[
  {
    "path": ".gitignore",
    "content": ".settings\n.svn\nlocal.properties\nproguard.cfg\nproguard-project.txt\nbin/\ngen/\nlibs/\nobj/\npatches/\ntarget/\nsrc/test/resources/META-INF/config.properties\n\n*.Plo\n*.dylib\n*.la\n*.a\n*.lo\n.libs/\n.deps/\nautom4te.cache/\nMakefile.in\nMakefile\nconfig.status\n*.m4\nconfig_auto.h\nconfigure\nlibtool\ntesseract.pc\nstamp-h1\nbuild/\n.gradle/\n.idea/\n*.iml\njavadoc/\ntessdata/\n.externalNativeBuild\neyes-two/.cxx\ntess-two/.cxx\n"
  },
  {
    "path": ".gitmodules",
    "content": "[submodule \"leptonica\"]\n\tpath = leptonica\n\turl = https://github.com/alexcohn/leptonica\n[submodule \"tesseract\"]\n\tpath = tesseract\n\turl = https://github.com/alexcohn/tesseract\n"
  },
  {
    "path": "BUILDING.md",
    "content": "# Building\n\nThis project may be built manually as an alternative to including the pre-built\nAAR as an external dependency in your app project. To start the build, import\nthe root directory of this project into Android Studio as an existing Android\nStudio project, or follow the instructions below to build on the command line.\n\n## _Building with Android Studio_\n\nThe Gradle build uses the gradle-stable plugin and the Android NDK to\nbuild the Tesseract and Leptonica native C/C++ code through a call to\n`ndk-build` in `build.gradle`. In Android Studio, use \n\nBuild -> Rebuild Project\n\nto build or rebuild the project.\n\nNote: When building from Android Studio, you may need to set the path to your\nNDK installation in the Project Structure dialog (File->Project Structure).\n\n## _Building on the Command Line_\n\n_On Mac/Linux:_\n\nEdit your local.properties file to include the path to your NDK directory:\n\n    ndk.dir=/path/to/your/android-ndk\n\nRun the following commands:\n\n    export ANDROID_HOME=/path/to/your/android-sdk\n    git clone git://github.com/rmtheis/tess-two tess\n    cd tess\n    ./gradlew assemble\n\t\t\n_On Windows:_\n\nEdit your local.properties file to include the path to your NDK directory:\n\n    ndk.dir=C\\:\\\\path\\\\to\\\\your\\\\android-ndk\n\nRun the following commands:\n\n    set ANDROID_HOME=C:\\\\path\\\\to\\\\your\\\\android-sdk\n    git clone git://github.com/rmtheis/tess-two tess\n    cd tess\n    gradlew assemble\n\nOn all above platforms you can build a command-line static banary, e.g.\n\n    ndk-build -C tess-two-git/tess-two tesseract APP_ABI=arm64-v8a\n    \nIt can be deployed to `/data/local/tmp` of a compatible Android device and run from adb shell:  \n\n    adb shell time tesseract --tessdata-dir tessdata imagename outputbase\n    \nWith v.4.1 you can use new or old data files.\n\n# Importing\n\nAfter building, the code that is generated may be imported into your app\nproject in Android Studio as a module using\n\nFile -> New -> Import Module -> `tess-two` folder\n\nand then adding the dependency to your app module build.gradle:\n\n        dependencies {\n            implementation project(':tess-two')\n        }\n\n# Testing\n\n_On Mac/Linux:_\n\n    ./preparetests.sh\n    ./gradlew connectedAndroidTest\n\n_On Windows:_\n\n    preparetests.cmd\n    gradlew connectedAndroidTest\n\n# Removing\n\nIf you want to remove your app's dependency on the tess-two module, reverse\nthe import process by removing the module using the Project Structure dialog\n(File->Project Structure), manually deleting the tess-two subfolder from your\napp project folder, and removing the tess-two reference from your app module\nbuild.gradle."
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Change Log\n\n## [9.1.0](https://github.com/rmtheis/tess-two/tree/9.1.0) (2019-10-19)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/9.0.0...9.1.0)\n\n**Fixed bugs:**\n\n- WriteFile.writeBytes altering the source image endiannes and producing artefacts [\\#228](https://github.com/rmtheis/tess-two/issues/228)\n- Crashing reported on 64-bit devices [\\#197](https://github.com/rmtheis/tess-two/issues/197)\n- testPixaReplacePix crashes in native code [\\#159](https://github.com/rmtheis/tess-two/issues/159)\n- ReadFile.readBitmap alters image colors [\\#87](https://github.com/rmtheis/tess-two/issues/87)\n\n**Closed issues:**\n\n- read Jpeg and PNG produce wrong alpha in 32bpp pix [\\#264](https://github.com/rmtheis/tess-two/issues/264)\n- Native crush when 'vert'.tessdata is used [\\#263](https://github.com/rmtheis/tess-two/issues/263)\n- In versions higher than 5.4.1 TessBaseAPI.ProgressNotifier never called [\\#262](https://github.com/rmtheis/tess-two/issues/262)\n- Decoding is slow when multiple languages are used [\\#261](https://github.com/rmtheis/tess-two/issues/261)\n- Getting different results when using tesseract on mobile vs on PC using Python. [\\#260](https://github.com/rmtheis/tess-two/issues/260)\n-  Illegible words recognition in Persian lang   [\\#259](https://github.com/rmtheis/tess-two/issues/259)\n- Could not initialize Tesseract API with language=ces! [\\#258](https://github.com/rmtheis/tess-two/issues/258)\n- Can't lanch [\\#257](https://github.com/rmtheis/tess-two/issues/257)\n- Tess4 initialize crash [\\#255](https://github.com/rmtheis/tess-two/issues/255)\n- tess4 on android studio [\\#254](https://github.com/rmtheis/tess-two/issues/254)\n- How I can init the tesseract to work only with digits? [\\#253](https://github.com/rmtheis/tess-two/issues/253)\n- java.lang.NoSuchFieldError: no \"I\" field \"mNativeData\" in class \"Lcom/googlecode/tesseract/android/TessBaseAPI;\" or its superclasses [\\#252](https://github.com/rmtheis/tess-two/issues/252)\n- java.lang.NoSuchFieldError: no \"I\" field \"mNativeData\" in class \"Lcom/googlecode/tesseract/android/TessBaseAPI;\" or its superclasses [\\#251](https://github.com/rmtheis/tess-two/issues/251)\n- Arabic trained-data produce 20% accuracy  [\\#250](https://github.com/rmtheis/tess-two/issues/250)\n- import tess two error [\\#249](https://github.com/rmtheis/tess-two/issues/249)\n- error in Android 7.0 [\\#248](https://github.com/rmtheis/tess-two/issues/248)\n- How to build tess-two without JNI? [\\#247](https://github.com/rmtheis/tess-two/issues/247)\n- Initializing TessBaseAPI crashes app [\\#246](https://github.com/rmtheis/tess-two/issues/246)\n- OCR number [\\#245](https://github.com/rmtheis/tess-two/issues/245)\n- compile binary only [\\#244](https://github.com/rmtheis/tess-two/issues/244)\n- Skip tesseract's default image preprocessing \\(Otsu\\) [\\#243](https://github.com/rmtheis/tess-two/issues/243)\n- How to add OPTITypewriter-Special font [\\#242](https://github.com/rmtheis/tess-two/issues/242)\n- Special requirements for Hindi and Arabic OCR [\\#239](https://github.com/rmtheis/tess-two/issues/239)\n\n**Merged pull requests:**\n\n- fix Java tests for leptronica [\\#265](https://github.com/rmtheis/tess-two/pull/265) ([alexcohn](https://github.com/alexcohn))\n- Update to support latest Android Studio [\\#256](https://github.com/rmtheis/tess-two/pull/256) ([Robyer](https://github.com/Robyer))\n\n## [9.0.0](https://github.com/rmtheis/tess-two/tree/9.0.0) (2018-04-20)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/8.0.0...9.0.0)\n\n**Change:**\n\n- This version fixes and adds back in the 64-bit ABIs, and removes the deprecated armv5 and mips/mips64 ABIs.\n\n**Implemented enhancements:**\n\n- Improve developer support for Hindi/Arabic [\\#240](https://github.com/rmtheis/tess-two/issues/240)\n\n**Fixed bugs:**\n\n- Crashing reported on 64-bit devices [\\#197](https://github.com/rmtheis/tess-two/issues/197)\n\n**Merged pull requests:**\n\n- Updated repositories. Changed compile to implementation. [\\#233](https://github.com/rmtheis/tess-two/pull/233) ([mauriciotogneri](https://github.com/mauriciotogneri))\n- Updated version of SDK, build tools and support libraries [\\#231](https://github.com/rmtheis/tess-two/pull/231) ([mauriciotogneri](https://github.com/mauriciotogneri))\n\n## [8.0.0](https://github.com/rmtheis/tess-two/tree/8.0.0) (2017-08-13)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/7.0.0...8.0.0)\n\n**Change:**\n\n- This version removes the 64-bit ABIs from the default build in order to avoid crashes due to [\\#197](https://github.com/rmtheis/tess-two/issues/197)\n\n**Closed issues:**\n\n- Build failure with Android Studio 3 and NDK ver. 15.x [\\#215](https://github.com/rmtheis/tess-two/issues/215)\n\n**Merged pull requests:**\n\n- clone tag 3.04.00 from tessdata [\\#217](https://github.com/rmtheis/tess-two/pull/217) ([ivankolev](https://github.com/ivankolev))\n- See issue \\#215 [\\#216](https://github.com/rmtheis/tess-two/pull/216) ([ivankolev](https://github.com/ivankolev))\n\n## [7.0.0](https://github.com/rmtheis/tess-two/tree/7.0.0) (2017-06-12)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.3.0...7.0.0)\n\n**API-breaking change:**\n\n- ResultIterator getChoicesAndConfidence\\(\\) is now getSymbolChoicesAndConfidence\\(\\)\n\n**Fixed bugs:**\n\n- ResultIterator crashes with certain character combinations [\\#126](https://github.com/rmtheis/tess-two/issues/126)\n- ResultIterator returns single Character as Alternatives for Words [\\#119](https://github.com/rmtheis/tess-two/issues/119)\n- beginDocument\\(\\) returns false even when successful [\\#103](https://github.com/rmtheis/tess-two/issues/103)\n\n**Closed issues:**\n\n- Hardcoded path in TessBaseAPITest.java [\\#208](https://github.com/rmtheis/tess-two/issues/208)\n\n**Merged pull requests:**\n\n- Add missing PageSegMode constant [\\#209](https://github.com/rmtheis/tess-two/pull/209) ([Robyer](https://github.com/Robyer))\n- Fix return value of BeginDocument \\(fixes \\#103\\) [\\#207](https://github.com/rmtheis/tess-two/pull/207) ([Robyer](https://github.com/Robyer))\n- Improve ResultIterator [\\#206](https://github.com/rmtheis/tess-two/pull/206) ([Robyer](https://github.com/Robyer))\n- Update gradle plugin [\\#205](https://github.com/rmtheis/tess-two/pull/205) ([Robyer](https://github.com/Robyer))\n- Fix javadocs errors and warnings [\\#202](https://github.com/rmtheis/tess-two/pull/202) ([Robyer](https://github.com/Robyer))\n\n## [6.3.0](https://github.com/rmtheis/tess-two/tree/6.2.0) (2017-04-06)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.2.0...6.3.0)\n\n**Updates:**\n\n- Tesseract code updated to version 3.05.00\n\n[Tesseract change log](https://github.com/tesseract-ocr/tesseract/blob/cf0b378577e7ed0c75bfaf97cae7e35d7634cf4d/ChangeLog#L22)\n\n## [6.2.0](https://github.com/rmtheis/tess-two/tree/6.2.0) (2017-02-04)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.1.1...6.2.0)\n\n**Updates:**\n\n- Leptonica 1.74.1\n- Libpng 1.6.25\n\n**Fixed bugs:**\n\n- Stop\\(\\) does not work with GetUTF8Text\\(\\) [\\#185](https://github.com/rmtheis/tess-two/issues/185)\n- TessBaseAPI stop\\(\\) sometimes causes SIGSEGV [\\#97](https://github.com/rmtheis/tess-two/issues/97)\n\n**Merged pull requests:**\n\n- Issue 185 [\\#186](https://github.com/rmtheis/tess-two/pull/186) ([Xyresic](https://github.com/Xyresic))\n\n## [6.1.1](https://github.com/rmtheis/tess-two/tree/6.1.1) (2016-11-27)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.1.0...6.1.1)\n\n**Updates:**\n\n- Changed ProGuard settings\n \n## [6.1.0](https://github.com/rmtheis/tess-two/tree/6.1.0) (2016-11-22)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.0.4...6.1.0)\n\n**Updates:**\n\n- Tesseract code updated, version 3.05.00dev\n\n**Closed issues:**\n \n- Tests doesn't work on devices without sdcard [\\#171](https://github.com/rmtheis/tess-two/issues/171)\n- no field with name='mNativeData' signature='J' in class Lcom/googlecode/tesseract/android/TessBaseAPI; [\\#166](https://github.com/rmtheis/tess-two/issues/166)\n \n**Merged pull requests:**\n \n- Pass native pointer as parameter [\\#172](https://github.com/rmtheis/tess-two/pull/172) ([jereksel](https://github.com/jereksel))\n\n## [6.0.4](https://github.com/rmtheis/tess-two/tree/6.0.4) (2016-08-21)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.0.3...6.0.4)\n\n**Updates:**\n\n- Changed ProGuard settings\n\n**Closed issues:**\n\n- android studio2.1.2 not build [\\#168](https://github.com/rmtheis/tess-two/issues/168)\n- no field with name='mNativeData' signature='J' in class Lcom/googlecode/tesseract/android/TessBaseAPI; [\\#166](https://github.com/rmtheis/tess-two/issues/166)\n\n## [6.0.3](https://github.com/rmtheis/tess-two/tree/6.0.3) (2016-07-16)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.0.2...6.0.3)\n\n**Closed issues:**\n\n- UnsatisfiedLinkError; thrown while initializing Lcom/googlecode/tesseract/android/TessBaseAPI 'libjpgt.so' and 'liblept.so' w/ compile 'com.rmtheis:tess-two:6.0.0' [\\#150](https://github.com/rmtheis/tess-two/issues/150)\n\n## [6.0.2](https://github.com/rmtheis/tess-two/tree/6.0.2) (2016-06-20)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.0.1...6.0.2)\n\n**Closed issues:**\n\n- Building project error on Windows - javadoc failed [\\#148](https://github.com/rmtheis/tess-two/issues/148)\n\n**Merged pull requests:**\n\n- Refactor nativeMergeAndReplacePix. Addresses \\#132. [\\#157](https://github.com/rmtheis/tess-two/pull/157) ([megabytefisher](https://github.com/megabytefisher))\n- Fix memory leak in setImage\\(Bitmap bmp\\) [\\#154](https://github.com/rmtheis/tess-two/pull/154) ([megabytefisher](https://github.com/megabytefisher))\n\n## [6.0.1](https://github.com/rmtheis/tess-two/tree/6.0.1) (2016-06-09)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/6.0.0...6.0.1)\n\n**Bug fix:**\n\n - Fixed nativeGetPix for 64-bit devices\n\n## [6.0.0](https://github.com/rmtheis/tess-two/tree/6.0.0) (2016-05-16)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.4.1...6.0.0)\n\n**API-breaking changes:** \n\n- Progress values no longer available when using getUTF8Text. Use getHOCRText instead.\n- Android 2.2 (API level 8) no longer supported\n- Eyes-two project refactored. Code similar to what was removed is available from the [Google Mobile Vision API](https://developers.google.com/vision/).\n- Tess-two deprecated methods removed\n\n**Updates:**\n\n- Tesseract 3.05.00dev (tesseract-ocr/tesseract@add1ed1)\n- Leptonica 1.73\n- Libpng 1.6.20 (android/platform_external_libpng@2789184)\n\n**Implemented enhancements:**\n\n- GetUTF8Text\\(\\) monitor and multi-platform projects [\\#116](https://github.com/rmtheis/tess-two/issues/116)\n- Update eyes-two structure [\\#95](https://github.com/rmtheis/tess-two/issues/95)\n- Expand image I/O format support [\\#94](https://github.com/rmtheis/tess-two/issues/94)\n\n**Fixed bugs:**\n\n- NDK r11 clang build error: undefined reference to isnanf/\\_\\_isinff [\\#138](https://github.com/rmtheis/tess-two/issues/138)\n- init\\(\\) crashes when using OEM\\_TESSERACT\\_CUBE\\_COMBINED for Arabic [\\#12](https://github.com/rmtheis/tess-two/issues/12)\n\n\n## [5.4.1](https://github.com/rmtheis/tess-two/tree/5.4.1) (2016-01-17)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.4.0...5.4.1)\n\n**Updates:**\n\n- Added libjpeg 9b\n\n**Closed issues:**\n\n- Pdf renderer isn't working with jpg input images [\\#122](https://github.com/rmtheis/tess-two/issues/122)\n\n## [5.4.0](https://github.com/rmtheis/tess-two/tree/5.4.0) (2016-01-10)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.3.0...5.4.0)\n\n**Updates:**\n\n- Added Gradle build\n- Released on Bintray\n\n**Closed issues:**\n\n- Add Maven support [\\#53](https://github.com/rmtheis/tess-two/issues/53)\n\n**Merged pull requests:**\n\n- Gradle build [\\#99](https://github.com/rmtheis/tess-two/pull/99) ([Aaargh20318](https://github.com/Aaargh20318))\n\n\n## [5.3.0](https://github.com/rmtheis/tess-two/tree/5.3.0) (2015-10-30)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.2.0...5.3.0)\n\n**Implemented enhancements:**\n\n- Added TessPdfRenderer for PDF output [\\#46](https://github.com/rmtheis/tess-two/issues/46)\n- Added libpng 1.6.10 (android/platform_external_libpng@37f83eb)\n\n**Closed issues:**\n\n- java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol \"png\\_set\\_longjmp\\_fn\" referenced by \"liblept.so\"... [\\#106](https://github.com/rmtheis/tess-two/issues/106)\n- \"'libpng.so' not found\" message on some 4.x versions of Android [\\#105](https://github.com/rmtheis/tess-two/issues/105)\n- libpng fails to build on ARMv8 [\\#102](https://github.com/rmtheis/tess-two/issues/102)\n\n**Merged pull requests:**\n\n- fix 64-bit ARMv8 build [\\#124](https://github.com/rmtheis/tess-two/pull/124) ([panzerfahrer](https://github.com/panzerfahrer))\n- Bugfix for progress notifier [\\#115](https://github.com/rmtheis/tess-two/pull/115) ([FDIM](https://github.com/FDIM))\n\n## [5.2.0](https://github.com/rmtheis/tess-two/tree/5.2.0) (2015-07-21)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.1.0...5.2.0)\n\n**Updates:**\n\n- Added support for using multiple training data files/languages\n- Tesseract 3.04 (tesseract-ocr/tesseract@e8b6d6f)\n- Leptonica 1.72\n\n**Fixed bugs:**\n\n- Fix finalizers [\\#88](https://github.com/rmtheis/tess-two/issues/88)\n- WriteFile.writeImpliedFormat fails for jpegs [\\#86](https://github.com/rmtheis/tess-two/issues/86)\n- WriteFile don't work as expected [\\#25](https://github.com/rmtheis/tess-two/issues/25)\n\n**Closed issues:**\n\n- clang \"atomicity.h:49: error: undefined reference to '\\_\\_atomic\\_fetch\\_add\\_4''\" for armeabi [\\#81](https://github.com/rmtheis/tess-two/issues/81)\n- Android \\(ART\\) crash with error JNI DETECTED ERROR IN APPLICATION: jarray is an invalid stack indirect reference table or invalid reference [\\#78](https://github.com/rmtheis/tess-two/issues/78)\n\n## [5.1.0](https://github.com/rmtheis/tess-two/tree/5.1.0) (2015-03-16)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/5.0.0...5.1.0)\n\n **Updates:**\n \n - Added 64-bit ABI support\n - Tesseract 3.04 (tesseract-ocr/tesseract@239f350)\n\n**Added to Tesseract API:**\n \n - ProgressNotifier for getting OCR percent complete values\n - ChoiceIterator support for getting per-symbol alternatives\n - GetConnectedComponents\n  \n**Added to Leptonica API:**\n\n - Edge.pixSobelEdgeFilter\n - GrayQuant.pixThresholdToBinary\n - Pix.clipRectangle\n - Pix.pixFastTophat\n - Pix.pixTophat\n - Pix.rotateOrth\n - Pix.scaleWithoutSharpening\n\n## [5.0.0](https://github.com/rmtheis/tess-two/tree/5.0.0) (2014-08-13)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/4.0.0...5.0.0)\n\n**Updates:**\n\n- Tesseract 3.03\n- Leptonica 1.71\n\n## [4.0.0](https://github.com/rmtheis/tess-two/tree/4.0.0) (2014-02-17)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/3.0.0...4.0.0)\n\n**Updates:**\n\n- Tesseract 3.03\n- Leptonica 1.70\n\n**Merged pull requests:**\n\n- Add some useful functions [\\#40](https://github.com/rmtheis/tess-two/pull/40) ([ductranit](https://github.com/ductranit))\n\n## [3.0.0](https://github.com/rmtheis/tess-two/tree/3.0.0) (2013-01-22)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/2.0.0...3.0.0)\n\n**Updates:**\n\n- Tesseract 3.03\n- Leptonica 1.69\n\n## [2.0.0](https://github.com/rmtheis/tess-two/tree/2.0.0) (2012-05-31)\n[Full Changelog](https://github.com/rmtheis/tess-two/compare/1.0.0...2.0.0)\n\n**Updates:**\n\n- Eyes-free project added\n- Tesseract 3.02\n\n## [1.0.0](https://github.com/rmtheis/tess-two/tree/1.0.0) (2011-11-06)\n\n- Initial release, branched from tesseract-android-tools project\n- Tesseract 3.01\n- Leptonica 1.68\n\n\n\\* *This change log was generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*\n\n"
  },
  {
    "path": "COPYING",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "ISSUE_TEMPLATE.md",
    "content": "Summary:\n\n\n\nSteps to reproduce the issue:\n\n1. \n2. \n3.\n\nExpected result:\n\n\n\nActual result:\n\n\n\nTess-two version:\n\n\n\nAndroid version:\n\n\n\nPhone/device model:\n\n\n\nPhone/device architecture (armeabi, armeabi-v7a, x86, mips, arm64-v8a, x86_64, mips64):\n\n\n\nLink to training data used:\n\n\n\nLink to image used as input:\n\n\n\n\n"
  },
  {
    "path": "README.md",
    "content": "## NO LONGER MAINTAINED\n\nThis project won't be receiving further updates or maintenance.\n\nPlease consider trying one of the forks of this project such as \n[https://github.com/alexcohn/tess-two](https://github.com/alexcohn/tess-two).\n\n# tess-two\n\nA fork of Tesseract Tools for Android \n([tesseract-android-tools][tesseract-android-tools]) that adds some\nadditional functions. Tesseract Tools for Android is a set of Android APIs and\nbuild files for the [Tesseract OCR][tesseract-ocr] and [Leptonica][leptonica] \nimage processing libraries.\n\nThis project works with:\n\n - Tesseract 4.1 (submodule)\n - Leptonica 1.9 (submodule)\n - libjpeg 9b\n - libpng 1.6.25\n \nThe source code for these dependencies is included within the\n`tess-two/jni` folder. \n\nThe `tess-two` module contains tools for compiling the Tesseract and Leptonica\nlibraries for use on the Android platform. It provides a Java API for accessing \nnatively-compiled Tesseract and Leptonica APIs.\n\nThe `eyes-two` module contains additional image processing code copied from the\n[eyes-free project][eyes-free]. It includes native functions for text detection,\nblur detection, optical flow detection, and thresholding. Eyes-two is not needed\nfor using the Tesseract or Leptonica APIs.\n\nThe `tess-two-test` module contains instrumented unit tests for tess-two.\n\n## Pre-requisites\n\n* Android 2.3 or higher\n* A v4.1 or 3.02 [trained data file][tessdata] for a language. Data files must be \ncopied to the Android device in a subdirectory named `tessdata`.\n\n## Usage\n\nTo use tess-two from your app, edit your app module's `build.gradle` file to add \ntess-two as an external dependency:\n\n\tdependencies {\n\t    implementation 'com.rmtheis:tess-two:9.1.0'\n\t}\n\t\n[Javadoc][javadoc] is available.\n\n## Building\n\nIf you want to modify the tess-two code, or you want to use the eyes-two module,\nyou may build the project yourself locally. See [BUILDING.md](BUILDING.md).\n\n\n## Versions\n\nRelease points are tagged with [version numbers][semantic-versioning]. A change \nto the major version number indicates an API change making that version \nincompatible with previous versions.\n\nThe [change log](CHANGELOG.md) shows what's new in each version.\n\n## Support\n\n* Stack Overflow: https://stackoverflow.com/questions/tagged/tess-two\n* tesseract-ocr: https://groups.google.com/forum/#!forum/tesseract-ocr\n\n## License\n\n    Copyright 2011 Robert Theis\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n        http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n## See Also\n\nThe Google Mobile Vision API team has made available an OCR capability that is\nprovided to developers through the Google Play Services library: The\n[Mobile Vision API][mobile-vision-api] offers a simple API for OCR that\ncurrently works for Latin-based characters.\n\n[tesseract-android-tools]: https://github.com/alanv/tesseract-android-tools\n[Tesseract4Android]: https://github.com/adaptech-cz/Tesseract4Android\n[tesseract-ocr]: https://github.com/tesseract-ocr/tesseract\n[leptonica]: https://github.com/DanBloomberg/leptonica\n[eyes-free]: https://github.com/rmtheis/eyes-free\n[tessdata]: https://github.com/tesseract-ocr/tessdata/tree/3.04.00\n[javadoc]: https://rmtheis.github.io/tess-two/javadoc/index.html\n[semantic-versioning]: http://semver.org\n[stackoverflow]: https://stackoverflow.com/\n[mobile-vision-api]: https://developers.google.com/vision/"
  },
  {
    "path": "build.gradle",
    "content": "// Top-level build file where you can add configuration options common to all sub-projects/modules.\n\nbuildscript {\n    repositories {\n        google()\n        jcenter()\n    }\n    dependencies {\n        classpath 'com.android.tools.build:gradle:4.1.1'\n        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2'\n        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'\n    }\n}\n\nallprojects {\n\n    group = 'com.rmtheis'\n    version = '9.1.0'\n\n    repositories {\n        google()\n        jcenter()\n    }\n}\n"
  },
  {
    "path": "eyes-two/.classpath",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"con\" path=\"com.android.ide.eclipse.adt.ANDROID_FRAMEWORK\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.LIBRARIES\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.DEPENDENCIES\"/>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"src\" path=\"gen\"/>\n\t<classpathentry kind=\"output\" path=\"bin/classes\"/>\n</classpath>\n"
  },
  {
    "path": "eyes-two/.project",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>eyes-two</name>\n\t<comment></comment>\n\t<projects>\n\t</projects>\n\t<buildSpec>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ApkBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t</buildSpec>\n\t<natures>\n\t\t<nature>com.android.ide.eclipse.adt.AndroidNature</nature>\n\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n\t</natures>\n</projectDescription>\n"
  },
  {
    "path": "eyes-two/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Copyright (C) 2009 Google Inc.\n\n     Licensed under the Apache License, Version 2.0 (the \"License\");\n     you may not use this file except in compliance with the License.\n     You may obtain a copy of the License at\n\n          http://www.apache.org/licenses/LICENSE-2.0\n\n     Unless required by applicable law or agreed to in writing, software\n     distributed under the License is distributed on an \"AS IS\" BASIS,\n     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n     See the License for the specific language governing permissions and\n     limitations under the License.\n-->\n\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.googlecode.eyesfree.ocr\"\n    android:versionCode=\"1\"\n    android:versionName=\"1.0\" >\n\n    <uses-sdk\n        android:minSdkVersion=\"16\"\n        android:targetSdkVersion=\"22\" />\n\n</manifest>\n"
  },
  {
    "path": "eyes-two/COPYING",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "eyes-two/build.gradle",
    "content": "apply plugin: 'com.android.library'\n\nandroid {\n    compileSdkVersion 30\n\n    defaultConfig {\n        minSdkVersion 16\n        targetSdkVersion 30\n        versionCode 1\n        versionName '1.0'\n\n        testInstrumentationRunner \"androidx.test.runner.AndroidJUnitRunner\"\n\n        externalNativeBuild {\n            ndkBuild {\n                arguments \"TESSERACT_BUILD_PATH=${project(':tess-two').getBuildDir().path}\"\n            }\n        }\n    }\n\n    externalNativeBuild {\n        ndkBuild {\n            path \"src/main/jni/Android.mk\"\n        }\n    }\n\n    lintOptions {\n        abortOnError false\n    }\n}\n\ndependencies {\n    implementation project(':tess-two')\n\n    androidTestImplementation 'androidx.test:runner:1.3.0'\n}\n"
  },
  {
    "path": "eyes-two/build.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project name=\"eyes-two\" default=\"help\">\n\n    <!-- The local.properties file is created and updated by the 'android' tool.\n         It contains the path to the SDK. It should *NOT* be checked into\n         Version Control Systems. -->\n    <property file=\"local.properties\" />\n\n    <!-- The ant.properties file can be created by you. It is only edited by the\n         'android' tool to add properties to it.\n         This is the place to change some Ant specific build properties.\n         Here are some properties you may want to change/update:\n\n         source.dir\n             The name of the source directory. Default is 'src'.\n         out.dir\n             The name of the output directory. Default is 'bin'.\n\n         For other overridable properties, look at the beginning of the rules\n         files in the SDK, at tools/ant/build.xml\n\n         Properties related to the SDK location or the project target should\n         be updated using the 'android' tool with the 'update' action.\n\n         This file is an integral part of the build system for your\n         application and should be checked into Version Control Systems.\n\n         -->\n    <property file=\"ant.properties\" />\n\n    <!-- The project.properties file is created and updated by the 'android'\n         tool, as well as ADT.\n\n         This contains project specific properties such as project target, and library\n         dependencies. Lower level build properties are stored in ant.properties\n         (or in .classpath for Eclipse projects).\n\n         This file is an integral part of the build system for your\n         application and should be checked into Version Control Systems. -->\n    <loadproperties srcFile=\"project.properties\" />\n\n    <!-- quick check on sdk.dir -->\n    <fail\n            message=\"sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var\"\n            unless=\"sdk.dir\"\n    />\n\n\n<!-- extension targets. Uncomment the ones where you want to do custom work\n     in between standard targets -->\n<!--\n    <target name=\"-pre-build\">\n    </target>\n    <target name=\"-pre-compile\">\n    </target>\n\n    /* This is typically used for code obfuscation.\n       Compiled code location: ${out.classes.absolute.dir}\n       If this is not done in place, override ${out.dex.input.absolute.dir} */\n    <target name=\"-post-compile\">\n    </target>\n-->\n\n    <!-- Import the actual build file.\n\n         To customize existing targets, there are two options:\n         - Customize only one target:\n             - copy/paste the target into this file, *before* the\n               <import> task.\n             - customize it to your needs.\n         - Customize the whole content of build.xml\n             - copy/paste the content of the rules files (minus the top node)\n               into this file, replacing the <import> task.\n             - customize to your needs.\n\n         ***********************\n         ****** IMPORTANT ******\n         ***********************\n         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,\n         in order to avoid having your file be overridden by tools such as \"android update project\"\n    -->\n    <!-- version-tag: 1 -->\n    <import file=\"${sdk.dir}/tools/ant/build.xml\" />\n\n</project>\n"
  },
  {
    "path": "eyes-two/project.properties",
    "content": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# This file must be checked in Version Control Systems.\n#\n# To customize properties used by the Ant build system use,\n# \"ant.properties\", and override values to adapt the script to your\n# project structure.\n\n# Indicates whether an apk should be generated for each density.\nsplit.density=false\n# Project target.\ntarget=android-16\nandroid.library=true\nandroid.library.reference.1=../tess-two\n"
  },
  {
    "path": "eyes-two/src/androidTest/java/OpticalFlowTest.java",
    "content": "import android.util.Log;\n\nimport junit.framework.TestCase;\n\nimport androidx.test.filters.SmallTest;\n\nimport com.googlecode.eyesfree.opticflow.OpticalFlow;\n\npublic class OpticalFlowTest extends TestCase {\n    private static final String TAG = OpticalFlowTest.class.getSimpleName();\n\n    @SmallTest\n    public void testInit() {\n        OpticalFlow of = new OpticalFlow();\n        of.initialize(360, 240, 2);\n        assertTrue(of != null);\n    }\n}\n"
  },
  {
    "path": "eyes-two/src/main/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!-- Copyright (C) 2009 Google Inc.\n\n     Licensed under the Apache License, Version 2.0 (the \"License\");\n     you may not use this file except in compliance with the License.\n     You may obtain a copy of the License at\n\n          http://www.apache.org/licenses/LICENSE-2.0\n\n     Unless required by applicable law or agreed to in writing, software\n     distributed under the License is distributed on an \"AS IS\" BASIS,\n     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n     See the License for the specific language governing permissions and\n     limitations under the License.\n-->\n\n<manifest package=\"com.googlecode.eyesfree.ocr\">\n\n</manifest>\n"
  },
  {
    "path": "eyes-two/src/main/java/com/googlecode/eyesfree/opticflow/ImageBlur.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.eyesfree.opticflow;\n\n/**\n * Wrapper for native image blur detection code. Modified by Alan Viverette from\n * Xiaotao Duan's original source.\n *\n * @author Xiaotao Duan\n * @author alanv@google.com (Alan Viverette)\n */\npublic class ImageBlur {\n    static {\n        System.loadLibrary(\"imageutils\");\n    }\n\n    /**\n     * Tests if a given image is blurred or not.\n     *\n     * @param input An array of input pixels in YUV420SP format.\n     * @param width The width of the input image.\n     * @param height The height of the input image.\n     * @return true when input image is blurred.\n     */\n    public static native boolean isBlurred(byte[] input, int width, int height);\n\n    /**\n     * Computes signature of a given image.\n     *\n     * @param input An array of input pixels in YUV420SP format.\n     * @param width The width of the input image.\n     * @param height The height of the input image.\n     * @param signatureBuffer A buffer for output signature. If it's null or not\n     *            in the right size, this buffer will be ignored and not used.\n     *            This is used to avoid GC.\n     * @return Signature of input image. If signatureBuffer is valid,\n     *         signatureBuffer will be returned. Otherwise a new array will be\n     *         returned and can be used as signature buffer in next function\n     *         call.\n     */\n    public static native int[] computeSignature(\n            byte[] input, int width, int height, int[] signatureBuffer);\n\n    /**\n     * Computes how similar of two given images represented by their signatures.\n     *\n     * @return An integer from 0 to 100 is returned indicating how much\n     *         percentage of signature2 is different from signature1.\n     */\n    public static native int diffSignature(int[] signature1, int[] signature2);\n}\n"
  },
  {
    "path": "eyes-two/src/main/java/com/googlecode/eyesfree/opticflow/OpticalFlow.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.eyesfree.opticflow;\n\nimport android.graphics.PointF;\n\n/**\n * Interface to native optical flow library.\n *\n * Modified by Alan Viverette from Andrew Harp's original source.\n *\n * @author Andrew Harp\n * @author alanv@google.com (Alan Viverette)\n */\npublic class OpticalFlow {\n    static {\n        System.loadLibrary(\"opticalflow\");\n    }\n\n    @Override\n    protected void finalize() {\n        resetNative();\n    }\n\n    public void initialize(int width, int height, int downsampleFactor) {\n        initNative(width, height, downsampleFactor);\n    }\n\n    public void setImage(byte[] data, long timestamp) {\n        addFrameNative(data, timestamp);\n    }\n\n    public void computeOpticalFlow() {\n        computeFeaturesNative(true);\n        computeFlowNative();\n        printInfoNative();\n    }\n\n    public float[] getFeatures(boolean onlyReturnCorrespondingFeatures) {\n        return getFeaturesNative(onlyReturnCorrespondingFeatures);\n    }\n\n    public PointF getAccumulatedDelta(\n            long timestamp, float positionX, float positionY, float radius) {\n        float[] delta = new float[2];\n\n        getAccumulatedDeltaNative(timestamp, positionX, positionY, radius, delta);\n\n        return new PointF(delta[0], delta[1]);\n    }\n\n    public void addInterestRegion(int numX, int numY, int left, int top, int right, int bottom) {\n        addInterestRegionNative(numX, numY, left, top, right, bottom);\n    }\n\n    /*********************** NATIVE METHODS *************************************/\n\n    private native void initNative(int width, int height, int downsampleFactor);\n\n    private native void addFrameNative(byte[] data, long timeStamp);\n\n    private native void computeFeaturesNative(boolean cachedOk);\n\n    private native void computeFlowNative();\n\n    private native void printInfoNative();\n\n    private native void getAccumulatedDeltaNative(\n            long timestamp, float positionX, float positionY, float radius, float[] delta);\n\n    private native void addInterestRegionNative(\n            int numX, int numY, float left, float top, float right, float bottom);\n\n    private native float[] getFeaturesNative(boolean onlyReturnCorrespondingFeatures);\n\n    private native void resetNative();\n}\n"
  },
  {
    "path": "eyes-two/src/main/java/com/googlecode/eyesfree/textdetect/HydrogenTextDetector.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.eyesfree.textdetect;\n\nimport android.os.Environment;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.Pixa;\n\n/**\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"unused\")\npublic class HydrogenTextDetector {\n    private final long mNative;\n\n    static {\n        System.loadLibrary(\"lept\");\n        System.loadLibrary(\"hydrogen\");\n    }\n\n    private Parameters mParams;\n\n    public HydrogenTextDetector() {\n        mNative = nativeConstructor();\n\n        mParams = new Parameters();\n        setParameters(mParams);\n    }\n\n    public void setSize(int width, int height) {\n        // TODO(alanv): Set up native buffers\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        try {\n            nativeDestructor(mNative);\n        } finally {\n            super.finalize();\n        }\n    }\n\n    public void setParameters(Parameters params) {\n        mParams = params;\n\n        nativeSetParameters(mNative, mParams);\n    }\n\n    public Parameters getParameters() {\n        return mParams;\n    }\n\n    public Pixa getTextAreas() {\n        long nativePixa = nativeGetTextAreas(mNative);\n\n        if (nativePixa == 0) {\n            return null;\n        }\n\n        int width = nativeGetSourceWidth(mNative);\n        int height = nativeGetSourceHeight(mNative);\n\n        return new Pixa(nativePixa, width, height);\n    }\n\n    public float getSkewAngle() {\n        return nativeGetSkewAngle(mNative);\n    }\n\n    public float[] getTextConfs() {\n        return nativeGetTextConfs(mNative);\n    }\n\n    public Pix getSourceImage() {\n        long nativePix = nativeGetSourceImage(mNative);\n\n        if (nativePix == 0) {\n            return null;\n        }\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Sets the text detection source image to be a clone of the supplied source\n     * image. The supplied image may be recycled after calling this method.\n     *\n     * @param pixs The source image on which to perform text detection.\n     */\n    public void setSourceImage(Pix pixs) {\n        nativeSetSourceImage(mNative, pixs.getNativePix());\n    }\n\n    public void detectText() {\n        nativeDetectText(mNative);\n    }\n\n    public void clear() {\n        nativeClear(mNative);\n    }\n\n    // ******************\n    // * PUBLIC CLASSES *\n    // ******************\n\n    public class Parameters {\n        public boolean debug;\n\n        public String out_dir;\n\n        // Edge-based thresholding\n        public int edge_tile_x;\n\n        public int edge_tile_y;\n\n        public int edge_thresh;\n\n        public int edge_avg_thresh;\n\n        // Skew angle correction\n        public boolean skew_enabled;\n\n        public float skew_min_angle;\n\n        public float skew_sweep_range;\n\n        public float skew_sweep_delta;\n\n        public int skew_sweep_reduction;\n\n        public int skew_search_reduction;\n\n        public float skew_search_min_delta;\n\n        // Singleton filter\n        public float single_min_aspect;\n\n        public float single_max_aspect;\n\n        public int single_min_area;\n\n        public float single_min_density;\n\n        // Quick pair filter\n        public float pair_h_ratio;\n\n        public float pair_d_ratio;\n\n        public float pair_h_dist_ratio;\n\n        public float pair_v_dist_ratio;\n\n        public float pair_h_shared;\n\n        // Cluster pair filter\n        public int cluster_width_spacing;\n\n        public float cluster_shared_edge;\n\n        public float cluster_h_ratio;\n\n        // Finalized cluster filter\n        public int cluster_min_blobs;\n\n        public float cluster_min_aspect;\n\n        public float cluster_min_fdr;\n\n        public int cluster_min_edge;\n\n        public int cluster_min_edge_avg;\n\n        public Parameters() {\n            debug = false;\n            out_dir = Environment.getExternalStorageDirectory().toString();\n\n            // Edge-based thresholding\n            edge_tile_x = 32;\n            edge_tile_y = 64;\n            edge_thresh = 64;\n            edge_avg_thresh = 4;\n\n            // Skew angle correction\n            skew_enabled = true;\n            skew_min_angle = 1.0f;\n            skew_sweep_range = 30.0f;\n            skew_sweep_delta = 5.0f;\n            skew_sweep_reduction = 8;\n            skew_search_reduction = 4;\n            skew_search_min_delta = 0.01f;\n\n            // Singleton filter\n            single_min_aspect = 0.1f;\n            single_max_aspect = 4.0f;\n            single_min_area = 4;\n            single_min_density = 0.2f;\n\n            // Quick pair filter\n            pair_h_ratio = 1.0f;\n            pair_d_ratio = 1.5f;\n            pair_h_dist_ratio = 2.0f;\n            pair_v_dist_ratio = 0.25f;\n            pair_h_shared = 0.25f;\n\n            // Cluster pair filter\n            cluster_width_spacing = 2;\n            cluster_shared_edge = 0.5f;\n            cluster_h_ratio = 1.0f;\n\n            // Finalized cluster filter\n            cluster_min_blobs = 5;\n            cluster_min_aspect = 2;\n            cluster_min_fdr = 2.5f;\n            cluster_min_edge = 32;\n            cluster_min_edge_avg = 1;\n        }\n    }\n\n    // ******************\n    // * NATIVE METHODS *\n    // ******************\n\n    private static native long nativeConstructor();\n\n    private static native void nativeDestructor(long nativePtr);\n\n    private static native void nativeSetParameters(long nativePtr, Parameters params);\n\n    private static native long nativeGetTextAreas(long nativePtr);\n\n    private static native float nativeGetSkewAngle(long nativePtr);\n\n    private static native int nativeGetSourceWidth(long nativePtr);\n\n    private static native int nativeGetSourceHeight(long nativePtr);\n\n    private static native float[] nativeGetTextConfs(long nativePtr);\n\n    private static native long nativeGetSourceImage(long nativePtr);\n\n    private static native void nativeSetSourceImage(long nativePtr, long nativePix);\n\n    private static native void nativeDetectText(long nativePtr);\n\n    private static native void nativeClear(long nativePtr);\n}\n"
  },
  {
    "path": "eyes-two/src/main/java/com/googlecode/eyesfree/textdetect/Thresholder.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.eyesfree.textdetect;\n\nimport com.googlecode.leptonica.android.Pix;\n\n/**\n * @author alanv@google.com (Alan Viverette)\n */\npublic class Thresholder {\n    static {\n        System.loadLibrary(\"lept\");\n        System.loadLibrary(\"hydrogen\");\n    }\n\n    /* Threshold under which pixels will be pulled low */\n    public final static int SOBEL_THRESH = 64;\n\n    public static Pix sobelEdgeThreshold(Pix pixs) {\n        return sobelEdgeThreshold(pixs, SOBEL_THRESH);\n    }\n\n    public static Pix sobelEdgeThreshold(Pix pixs, int thresh) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (thresh >= 255 || thresh < 0)\n            throw new IllegalArgumentException(\"Threshold must be in the range 0 <= thresh < 255\");\n\n        long nativePix = nativeSobelEdgeThreshold(pixs.getNativePix(), thresh);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to run Sobel edge threshold on Pix\");\n\n        return new Pix(nativePix);\n    }\n\n    /* Desired tile X dimension; actual size may vary */\n    public static final int EDGE_TILE_X = 32;\n\n    /* Desired tile Y dimension; actual size may vary */\n    public static final int EDGE_TILE_Y = 64;\n\n    /* Threshold for maximum edge, typically 32 */\n    public static final int EDGE_THRESH = 32;\n\n    /* Threshold for average edge, typically 1 */\n    public static final int EDGE_AVERAGE = 1;\n\n    /**\n     * Returns a version of the image thresholded using Fisher's discriminant.\n     *\n     * @return a thresholded image or <code>null</code> on error\n     */\n\n    public static Pix edgeAdaptiveThreshold(Pix pixs) {\n        return edgeAdaptiveThreshold(pixs, EDGE_TILE_X, EDGE_TILE_Y, EDGE_THRESH, EDGE_AVERAGE);\n    }\n\n    public static Pix edgeAdaptiveThreshold(\n            Pix pixs, int tileX, int tileY, int threshold, int average) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (tileX < 8)\n            throw new IllegalArgumentException(\"Tile width must be at least 8 pixels\");\n        if (tileY < 8)\n            throw new IllegalArgumentException(\"Tile height must be at least 8 pixels\");\n\n        long nativePix = nativeEdgeAdaptiveThreshold(\n                pixs.getNativePix(), tileX, tileY, threshold, average);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to run Fisher adaptive threshold on Pix\");\n\n        return new Pix(nativePix);\n    }\n\n    /* Desired tile X dimension; actual size may vary */\n    public static final int FDR_TILE_X = 48;\n\n    /* Desired tile Y dimension; actual size may vary */\n    public static final int FDR_TILE_Y = 48;\n\n    /* Fraction of the max Otsu score, typically 0.01 */\n    public static final float FDR_SCORE_FRACT = 0.0f;\n\n    /* Threshold for Fisher's Discriminant Rate, typically 3.5 */\n    public static final float FDR_THRESH = 2.5f;\n\n    /**\n     * Returns a version of the image thresholded using Fisher's discriminant.\n     *\n     * @return a thresholded image or <code>null</code> on error\n     */\n    public static Pix fisherAdaptiveThreshold(Pix pixs) {\n        return fisherAdaptiveThreshold(pixs, 30, 20);\n    }\n\n    public static Pix fisherAdaptiveThreshold(Pix pixs, int numTilesX, int numTilesY) {\n        int tileX = pixs.getWidth() / numTilesX;\n        int tileY = pixs.getHeight() / numTilesY;\n\n        return fisherAdaptiveThreshold(pixs, tileX, tileY, FDR_SCORE_FRACT, FDR_THRESH);\n    }\n\n    public static Pix fisherAdaptiveThreshold(\n            Pix pixs, int tileX, int tileY, float scoreFract, float thresh) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (tileX < 8)\n            throw new IllegalArgumentException(\"Tile width must be at least 8 pixels\");\n        if (tileY < 8)\n            throw new IllegalArgumentException(\"Tile height must be at least 8 pixels\");\n\n        long nativePix = nativeFisherAdaptiveThreshold(\n                pixs.getNativePix(), tileX, tileY, scoreFract, thresh);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to run Fisher adaptive threshold on Pix\");\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeFisherAdaptiveThreshold(\n            long nativePix, int tileX, int tileY, float scoreFract, float thresh);\n\n    private static native long nativeEdgeAdaptiveThreshold(\n            long nativePix, int tileX, int tileY, int threshold, int average);\n\n    private static native long nativeSobelEdgeThreshold(long nativePix, int threshold);\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/Android.mk",
    "content": "out_path := $(realpath $(NDK_OUT))\nout_path := $(out_path:$(realpath $(out_path)/../../../..)%=%)\nTESSERACT_TOOLS_PATH := $(TESSERACT_BUILD_PATH)/$(out_path)/local\n\nPREBUILT_PATH := $(TESSERACT_TOOLS_PATH)/$(TARGET_ARCH_ABI)\nROOT_PATH := $(TESSERACT_BUILD_PATH)/../..\n\ninclude $(call all-subdir-makefiles)\n"
  },
  {
    "path": "eyes-two/src/main/jni/Application.mk",
    "content": "APP_ABI := armeabi-v7a x86 arm64-v8a x86_64\nAPP_OPTIM := release\nNDK_TOOLCHAIN_VERSION := clang\n"
  },
  {
    "path": "eyes-two/src/main/jni/common/Android.mk",
    "content": "LOCAL_PATH:= $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_SRC_FILES := time_log.cpp\n\nLOCAL_CFLAGS := -Wall \\\n                -DHAVE_MALLOC_H \\\n                -DHAVE_PTHREAD \\\n                -finline-functions \\\n                -frename-registers \\\n                -ffast-math \\\n                -s \\\n                -fomit-frame-pointer\n\nifeq ($(LOG_TIME),true)\n  LOCAL_CFLAGS += -DLOG_TIME\nendif\n\nLOCAL_MODULE := common\n\ninclude $(BUILD_STATIC_LIBRARY)\n"
  },
  {
    "path": "eyes-two/src/main/jni/common/time_log.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Andrew Harp\n\n#include \"types.h\"\n#include \"time_log.h\"\n\n#ifdef LOG_TIME\n// Storage for logging functionality.\nint32 num_time_logs = 0;\nLogEntry time_logs[NUM_LOGS];\n\nint32 num_avg_entries = 0;\nAverageEntry avg_entries[NUM_LOGS];\n\nfloat32 running_total = 0.0f;\n#endif\n"
  },
  {
    "path": "eyes-two/src/main/jni/common/time_log.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n//\n// Utility functions for performance profiling.\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_TIME_LOG_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_TIME_LOG_H_\n\n#include <time.h>\n\n#include \"utils.h\"\n#include \"types.h\"\n\n#ifdef LOG_TIME\n\ninline static long currentThreadTimeNanos() {\n  struct timespec tm;\n  clock_gettime(CLOCK_THREAD_CPUTIME_ID, &tm);\n  return tm.tv_sec * 1000000000LL + tm.tv_nsec;\n}\n\n// Blend constant for running average.\n#define ALPHA 0.98f\n#define NUM_LOGS 100\n\nstruct LogEntry {\n  const char* id;\n  clock_t time_stamp;\n};\n\nstruct AverageEntry {\n  const char* id;\n  float32 average_duration;\n};\n\n// Storage for keeping track of this frame's values.\nextern int32 num_time_logs;\nextern LogEntry time_logs[NUM_LOGS];\n\n// Storage for keeping track of average values (each entry may not be printed\n// out each frame).\nextern AverageEntry avg_entries[NUM_LOGS];\nextern int32 num_avg_entries;\nextern float32 running_total;\n\n// Call this at the start of a logging phase.\ninline static void resetTimeLog() {\n  num_time_logs = 0;\n}\n\n\n// Log a message to be printed out when printTimeLog is called, along with the\n// amount of time in ms that has passed since the last call to this function.\ninline static void timeLog(const char* str) {\n  if (num_time_logs >= NUM_LOGS) {\n    LOGE(\"Out of log entries!\");\n    return;\n  }\n\n  time_logs[num_time_logs].id = str;\n  time_logs[num_time_logs].time_stamp = currentThreadTimeNanos();\n  ++num_time_logs;\n}\n\n\ninline static float32 blend(float32 old_val, float32 new_val) {\n  return ALPHA * old_val + (1.0f - ALPHA) * new_val;\n}\n\n\ninline static float32 updateAverage(const char* str, const float32 new_val) {\n  for (int32 entry_num = 0; entry_num < num_avg_entries; ++entry_num) {\n    AverageEntry* const entry = avg_entries + entry_num;\n    if (str == entry->id) {\n      entry->average_duration = blend(entry->average_duration, new_val);\n      return entry->average_duration;\n    }\n  }\n\n  if (num_avg_entries >= NUM_LOGS) {\n    LOGE(\"Too many log entries!\");\n  }\n\n  // If it wasn't there already, add it.\n  avg_entries[num_avg_entries].id = str;\n  avg_entries[num_avg_entries].average_duration = new_val;\n  ++num_avg_entries;\n\n  return new_val;\n}\n\n\n// Prints out all the timeLog statements in chronological order with the\n// interval that passed between subsequent statements.  The total time between\n// the first and last statements is printed last.\ninline static void printTimeLog() {\n  LogEntry* last_time = time_logs;\n\n  for (int i = 0; i < num_time_logs; ++i) {\n    LogEntry* this_time = time_logs + i;\n\n    const float32 curr_time =\n        (this_time->time_stamp - last_time->time_stamp) / 1000000.0f;\n\n    const float32 avg_time = updateAverage(this_time->id, curr_time);\n    LOGD(\"%32s:    %6.2fms    %6.2fms\", this_time->id, curr_time, avg_time);\n    last_time = this_time;\n  }\n\n  float32 total_time =\n      (last_time->time_stamp - time_logs->time_stamp) / 1000000.0f;\n\n  running_total = blend(running_total, total_time);\n\n  LOGD(\"TOTAL TIME:                          %6.2fms    %6.2fms\\n\",\n       total_time, running_total);\n}\n#else\ninline static void resetTimeLog() {}\ninline static void timeLog(const char* str) {}\ninline static void printTimeLog() {}\n#endif\n\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_TIME_LOG_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/common/types.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n//\n// This file exists to make the optical flow library more portable to different\n// platforms.\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_NATIVE_TYPES_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_NATIVE_TYPES_H_\n\n//typedef unsigned char bool;\n\ntypedef unsigned char uint8;\ntypedef unsigned short uint16;\ntypedef unsigned int uint32;\n\ntypedef signed char int8;\ntypedef short int16;\ntypedef signed int int32;\ntypedef float float32;\n\n#endif // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_NATIVE_TYPES_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/common/utils.h",
    "content": "// Copyright 2009 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_UTILS_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_UTILS_H_\n\n#include <android/log.h>\n#include <stdlib.h>\n\n#ifdef HAVE_ARMEABI_V7A\n#include <cpu-features.h>\n#include <arm_neon.h>\n#endif\n\n#include <math.h>\n#include \"types.h\"\n\n#define SAFE_DELETE(pointer) {\\\n  if ((pointer) != NULL) {\\\n    LOGV(\"Safe deleting pointer: %s\", #pointer);\\\n    delete (pointer);\\\n    (pointer) = NULL;\\\n  } else {\\\n    LOGV(\"Pointer already null: %s\", #pointer);\\\n  }\\\n}\n\n#ifdef VERBOSE_LOGGING\n#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)\n#else\n#define LOGV(...) {}\n#endif\n\n#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)\n#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\n#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)\n#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\n#define LOG_TAG \"goggles\"\n\n#ifdef SANITY_CHECKS\n#define CHECK(condition, ...) {\\\n  if (!(condition)) {\\\n    LOGE(\"CHECK FAILED: (%s) @ %s:%u\\n\", #condition, __FILE__, __LINE__);\\\n    LOGE(__VA_ARGS__);\\\n  }\\\n}\n#else\n#define CHECK(...) {}\n#endif\n\n\n#ifdef HAVE_ARMEABI_V7A\n// Runtime check for NEON support.  Only call on devices that support at least\n// armeabi-v7a.\ninline bool supportsNeon() {\n  return (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;\n}\n#endif\n\n#ifndef max\n#define max(a, b) (((a) > (b)) ? (a) : (b))\n#endif\n#ifndef min\n#define min(a, b) (((a) > (b)) ? (b) : (a))\n#endif\n\ntemplate<typename T>\ninline static T square(const T a) {\n  return a * a;\n}\n\ntemplate<typename T>\ninline static T clip(const T a, const T floor, const T ceil) {\n  return min(ceil, max(a, floor));\n}\n\ntemplate<typename T>\ninline static int32 floor(const T a) {\n  return static_cast<int32>(a);\n}\n\ntemplate<typename T>\ninline static int32 ceil(const T a) {\n  return floor(a) + 1;\n}\n\ntemplate<typename T>\ninline static bool inRange(const T a, const T min, const T max) {\n  return (a >= min) && (a <= max);\n}\n\ntemplate<typename T>\ninline static int32 round(const float a) {\n  return (a - (float) floor(a) > 0.5f) ? ceil(a) : floor(a);\n}\n\ntemplate<typename T>\ninline static void swap(T* const a, T* const b) {\n  // Cache out the VALUE of what's at a.\n  T tmp = *a;\n  *a = *b;\n\n  *b = tmp;\n}\n\n#endif // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_COMMON_UTILS_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/Android.mk",
    "content": "ifneq ($(TARGET_SIMULATOR),true)\n\nLOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_MODULE := libhydrogen\n\nLOCAL_SRC_FILES += \\\n  src/clusterer.cpp \\\n  src/hydrogentextdetector.cpp \\\n  src/thresholder.cpp \\\n  src/utilities.cpp \\\n  src/validator.cpp\n\nLOCAL_SRC_FILES += \\\n  jni/hydrogentextdetector.cpp \\\n  jni/thresholder.cpp \\\n  jni/jni.cpp\n\nLOCAL_C_INCLUDES += \\\n  $(LOCAL_PATH)/src \\\n  $(ROOT_PATH)/tess-two/jni/com_googlecode_leptonica_android \\\n  $(ROOT_PATH)/leptonica/src\n\nLOCAL_LDLIBS += \\\n  -llog\n\nLOCAL_MODULE_TAGS := optional\n\nLOCAL_PRELINK_MODULE := false\n\nLOCAL_DISABLE_FORMAT_STRING_CHECKS := true\n\nTARGET_PREBUILT_SHARED_LIBRARIES += \\\n  $(PREBUILT_PATH)/liblept.so\n\ninclude $(BUILD_SHARED_LIBRARY)\n\nendif #TARGET_SIMULATOR\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/jni/common.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef TEXTDETECT_JNI_COMMON_H\n#define TEXTDETECT_JNI_COMMON_H\n\n#include <jni.h>\n#include <android/log.h>\n#include <assert.h>\n#include <cstdlib>\n\n#define LOG_TAG \"TextDetect(native)\"\n#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)\n#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)\n#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\n#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)\n#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\n#define LOG_ASSERT(_cond, ...) if (!_cond) __android_log_assert(\"conditional\", LOG_TAG, __VA_ARGS__)\n\n#endif  /* TEXTDETECT_JNI_COMMON_H */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/jni/hydrogentextdetector.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n#include \"hydrogentextdetector.h\"\n\n#define DEBUG_MODE false\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njlong Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeConstructor(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = new HydrogenTextDetector();\n\n  return (jlong) ptr;\n}\n\nvoid Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeDestructor(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  delete ptr;\n}\n\nbool getBoolField(JNIEnv *env, jclass &clazz, jobject &obj, const char *field) {\n  jfieldID fieldID = env->GetFieldID(clazz, field, \"Z\");\n\n  return (env->GetBooleanField(obj, fieldID) == JNI_TRUE);\n}\n\nint getIntField(JNIEnv *env, jclass &clazz, jobject &obj, const char *field) {\n  jfieldID fieldID = env->GetFieldID(clazz, field, \"I\");\n\n  return (int) env->GetIntField(obj, fieldID);\n}\n\nfloat getFloatField(JNIEnv *env, jclass &clazz, jobject &obj, const char *field) {\n  jfieldID fieldID = env->GetFieldID(clazz, field, \"F\");\n\n  return (float) env->GetFloatField(obj, fieldID);\n}\n\nvoid getStringField(JNIEnv *env, jclass &clazz, jobject &obj, const char *field,\n                    char *dst) {\n  jfieldID fieldID = env->GetFieldID(clazz, field, \"Ljava/lang/String;\");\n  jstring str = (jstring) env->GetObjectField(obj, fieldID);\n\n  if (str != NULL) {\n    jsize len = L_MIN(env->GetStringLength(str), 254);\n\n    env->GetStringUTFRegion(str, 0, len, dst);\n\n    dst[len + 1] = 0;\n  } else {\n    dst[0] = 0;\n  }\n}\n\nvoid Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeSetParameters(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr,\n    jobject params) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n  HydrogenTextDetector::TextDetectorParameters *myParams = ptr->GetMutableParameters();\n\n  jclass paramClass = env->GetObjectClass(params);\n\n  getStringField(env, paramClass, params, \"out_dir\", myParams->out_dir);\n\n  myParams->debug = getBoolField(env, paramClass, params, \"debug\");\n  myParams->edge_tile_x = getIntField(env, paramClass, params, \"edge_tile_x\");\n  myParams->edge_tile_y = getIntField(env, paramClass, params, \"edge_tile_y\");\n  myParams->edge_thresh = getIntField(env, paramClass, params, \"edge_thresh\");\n  myParams->edge_avg_thresh = getIntField(env, paramClass, params, \"edge_avg_thresh\");\n\n  myParams->skew_enabled = getBoolField(env, paramClass, params, \"skew_enabled\");\n  myParams->skew_min_angle = getFloatField(env, paramClass, params, \"skew_min_angle\");\n  myParams->skew_sweep_range = getFloatField(env, paramClass, params, \"skew_sweep_range\");\n  myParams->skew_sweep_delta = getFloatField(env, paramClass, params, \"skew_sweep_delta\");\n  myParams->skew_sweep_reduction = getIntField(env, paramClass, params, \"skew_sweep_reduction\");\n  myParams->skew_search_reduction = getIntField(env, paramClass, params, \"skew_search_reduction\");\n  myParams->skew_search_min_delta = getFloatField(env, paramClass, params, \"skew_search_min_delta\");\n\n  myParams->single_min_aspect = getFloatField(env, paramClass, params, \"single_min_aspect\");\n  myParams->single_max_aspect = getFloatField(env, paramClass, params, \"single_max_aspect\");\n  myParams->single_min_area = getIntField(env, paramClass, params, \"single_min_area\");\n  myParams->single_min_density = getFloatField(env, paramClass, params, \"single_min_density\");\n\n  myParams->pair_h_ratio = getFloatField(env, paramClass, params, \"pair_h_ratio\");\n  myParams->pair_d_ratio = getFloatField(env, paramClass, params, \"pair_d_ratio\");\n  myParams->pair_h_dist_ratio = getFloatField(env, paramClass, params, \"pair_h_dist_ratio\");\n  myParams->pair_v_dist_ratio = getFloatField(env, paramClass, params, \"pair_v_dist_ratio\");\n  myParams->pair_h_shared = getFloatField(env, paramClass, params, \"pair_h_shared\");\n\n  myParams->cluster_width_spacing = getIntField(env, paramClass, params, \"cluster_width_spacing\");\n  myParams->cluster_shared_edge = getFloatField(env, paramClass, params, \"cluster_shared_edge\");\n  myParams->cluster_h_ratio = getFloatField(env, paramClass, params, \"cluster_h_ratio\");\n\n  myParams->cluster_min_blobs = getIntField(env, paramClass, params, \"cluster_min_blobs\");\n  myParams->cluster_min_aspect = getFloatField(env, paramClass, params, \"cluster_min_aspect\");\n  myParams->cluster_min_fdr = getFloatField(env, paramClass, params, \"cluster_min_fdr\");\n  myParams->cluster_min_edge = getIntField(env, paramClass, params, \"cluster_min_edge\");\n  myParams->cluster_min_edge_avg = getIntField(env, paramClass, params, \"cluster_min_edge_avg\");\n}\n\njlong Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetTextAreas(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  PIXA *textAreas = ptr->GetTextAreas();\n\n  return (jlong) textAreas;\n}\n\njfloat Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetSkewAngle(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  l_float32 skew_angle = ptr->GetSkewAngle();\n\n  return (jfloat) skew_angle;\n}\n\njint Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetSourceWidth(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n  PIX *pix = ptr->GetSourceImage();\n  jint h = pixGetWidth(pix);\n\n  pixDestroy(&pix);\n\n  return (jint) h;\n}\n\njint Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetSourceHeight(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  //LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n  PIX *pix = ptr->GetSourceImage();\n  jint w = pixGetHeight(pix);\n\n  pixDestroy(&pix);\n\n  return (jint) w;\n}\n\njfloatArray Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetTextConfs(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n  NUMA *confs = ptr->GetTextConfs();\n  l_int32 count = numaGetCount(confs);\n  jfloatArray ret = env->NewFloatArray(count);\n  l_float32 nval;\n  jfloat jval;\n\n  if (ret != NULL) {\n    for (int i = 0; i < count; i++) {\n      numaGetFValue(confs, i, &nval);\n      jval = (jfloat) nval;\n      env->SetFloatArrayRegion(ret, i, 1, &jval);\n    }\n  }\n\n  numaDestroy(&confs);\n\n  return ret;\n}\n\njlong Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeGetSourceImage(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  return (jlong) ptr->GetSourceImage();\n}\n\nvoid Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeSetSourceImage(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr,\n    jlong nativePix) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n  PIX *pix = (PIX *) nativePix;\n\n  ptr->SetSourceImage(pix);\n}\n\nvoid Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeDetectText(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  ptr->DetectText();\n}\n\nvoid Java_com_googlecode_eyesfree_textdetect_HydrogenTextDetector_nativeClear(\n    JNIEnv *env,\n    jclass clazz,\n    jlong nativePtr) {\n  if (DEBUG_MODE) LOGV(__FUNCTION__);\n\n  HydrogenTextDetector *ptr = (HydrogenTextDetector *) nativePtr;\n\n  ptr->Clear();\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n\n#undef DEBUG_MODE\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/jni/jni.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\njint JNI_OnLoad(JavaVM* vm, void* reserved) {\n  JNIEnv *env;\n\n  if (vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK) {\n      LOGE(\"ERROR: GetEnv failed\\n\");\n      return -1;\n  }\n  assert(env != NULL);\n\n  return JNI_VERSION_1_6;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/jni/thresholder.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n#include \"thresholder.h\"\n#include \"utilities.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njlong Java_com_googlecode_eyesfree_textdetect_Thresholder_nativeSobelEdgeThreshold(JNIEnv *env,\n                                                                                   jclass clazz,\n                                                                                   jlong nativePix,\n                                                                                   jlong threshold) {\n  LOGV(__FUNCTION__);\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixThreshedSobelEdgeFilter(pixs, (l_int32) threshold);\n\n  return (jlong) pixd;\n}\n\njlong Java_com_googlecode_eyesfree_textdetect_Thresholder_nativeEdgeAdaptiveThreshold(JNIEnv *env,\n                                                                                      jclass clazz,\n                                                                                      jlong nativePix,\n                                                                                      jint tileX,\n                                                                                      jint tileY,\n                                                                                      jint threshold,\n                                                                                      jint average) {\n  LOGV(__FUNCTION__);\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd;\n\n  if (pixEdgeAdaptiveThreshold(pixs, &pixd, (l_int32) tileX, (l_int32) tileY, (l_int32) threshold,\n                               (l_int32) average)) {\n    return (jlong) 0;\n  }\n\n  return (jlong) pixd;\n}\n\njlong Java_com_googlecode_eyesfree_textdetect_Thresholder_nativeFisherAdaptiveThreshold(JNIEnv *env,\n                                                                                        jclass clazz,\n                                                                                        jlong nativePix,\n                                                                                        jint tileX,\n                                                                                        jint tileY,\n                                                                                        jfloat scoreFract,\n                                                                                        jfloat thresh) {\n  LOGV(__FUNCTION__);\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd;\n\n  if (pixFisherAdaptiveThreshold(pixs, &pixd, (l_int32) tileX, (l_int32) tileY,\n                                 (l_float32) scoreFract, (l_float32) thresh)) {\n    return (jlong) 0;\n  }\n\n  return (jlong) pixd;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/clusterer.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <malloc.h>\n#include \"leptonica.h\"\n#include \"clusterer.h\"\n#include \"validator.h\"\n\n/* Type of connected components: 4 is up/down/left/right. 8 includes diagonals */\n#define CONN_COMP 8\n\nl_int32 ConnCompValidPixa(PIX *pix8, PIX *pix, PIXA **ppixa, NUMA **pconfs,\n                          HydrogenTextDetector::TextDetectorParameters &params) {\n  l_int32 h, iszero;\n  l_int32 x, y, xstart, ystart;\n  l_float32 singleton_conf;\n  PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixt5;\n  PIXA *pixa, *pixasort;\n  NUMA *confs, *confsort;\n  BOX *box;\n  BOXA *boxa;\n  L_STACK *lstack, *auxstack;\n\n  PROCNAME(\"pixConnCompValidPixa\");\n\n  if (!ppixa)\n    return ERROR_INT(\"&pixa not defined\", procName, 1);\n  if (!pconfs)\n    return ERROR_INT(\"&confs not defined\", procName, 1);\n  *ppixa = NULL;\n  *pconfs = NULL;\n  if (!pix || pixGetDepth(pix) != 1)\n    return ERROR_INT(\"pixs undefined or not 1 bpp\", procName, 1);\n\n  pixa = pixaCreate(0);\n  confs = numaCreate(0);\n\n  pixZero(pix, &iszero);\n  if (iszero) {\n    *ppixa = pixa;\n    return 0;\n  }\n\n  if ((pixt1 = pixCopy(NULL, pix)) == NULL)\n    return ERROR_INT(\"pixt1 not made\", procName, 1);\n  if ((pixt2 = pixCopy(NULL, pix)) == NULL)\n    return ERROR_INT(\"pixt2 not made\", procName, 1);\n\n  h = pixGetHeight(pix);\n  if ((lstack = lstackCreate(h)) == NULL)\n    return ERROR_INT(\"lstack not made\", procName, 1);\n  if ((auxstack = lstackCreate(0)) == NULL)\n    return ERROR_INT(\"auxstack not made\", procName, 1);\n  lstack->auxstack = auxstack;\n  if ((boxa = boxaCreate(0)) == NULL)\n    return ERROR_INT(\"boxa not made\", procName, 1);\n\n  xstart = 0;\n  ystart = 0;\n  while (1) {\n    if (!nextOnPixelInRaster(pixt1, xstart, ystart, &x, &y))\n      break;\n\n    if ((box = pixSeedfillBB(pixt1, lstack, x, y, CONN_COMP)) == NULL)\n      return ERROR_INT(\"box not made\", procName, 1);\n\n    /* Save the c.c. and remove from pixt2 as well */\n    pixt3 = pixClipRectangle(pixt1, box, NULL);\n    pixt4 = pixClipRectangle(pixt2, box, NULL);\n    pixt5 = pixClipRectangle(pix8, box, NULL);\n    pixXor(pixt3, pixt3, pixt4);\n    pixRasterop(pixt2, box->x, box->y, box->w, box->h, PIX_SRC ^ PIX_DST, pixt3, 0, 0);\n    pixDestroy(&pixt4);\n\n    if (ValidateSingleton(pixt3, box, pixt5, &singleton_conf, params)) {\n      boxaAddBox(boxa, box, L_INSERT);\n      pixaAddPix(pixa, pixt3, L_INSERT);\n      numaAddNumber(confs, singleton_conf);\n    } else {\n      boxDestroy(&box);\n      pixDestroy(&pixt3);\n    }\n\n    pixDestroy(&pixt5);\n\n    xstart = x;\n    ystart = y;\n  }\n\n  /* Remove old boxa of pixa and replace with a clone copy */\n  boxaDestroy(&pixa->boxa);\n  pixa->boxa = boxaCopy(boxa, L_CLONE);\n\n  /* Sort pixa, then destroy old pixa */\n  NUMA *naindex;\n  if ((pixasort = pixaSort(pixa, L_SORT_BY_X, L_SORT_INCREASING, &naindex, L_CLONE)) == NULL)\n    return ERROR_INT(\"pixasort not made\", procName, 1);\n  confsort = numaSortByIndex(confs, naindex);\n\n  /* Cleanup, freeing the fillsegs on each stack */\n  lstackDestroy(&lstack, TRUE);\n  pixDestroy(&pixt1);\n  pixDestroy(&pixt2);\n  boxaDestroy(&boxa);\n  pixaDestroy(&pixa);\n\n  *ppixa = pixasort;\n  *pconfs = confsort;\n\n  return 0;\n}\n\nl_int32 MergePix(PIXA *pixad, l_int32 d_idx, PIXA *pixas, l_int32 s_idx) {\n  l_int32 op;\n  l_int32 x, y, w, h;\n  l_int32 dx, dy, dw, dh;\n  PIX *pixd, *pixs, *pixmerge;\n  BOX *boxd, *boxs, *boxmerge;\n\n  PROCNAME(\"pixMergePix\");\n\n  if (!pixad)\n    return ERROR_INT(\"pixad not defined\", procName, 1);\n  if (!pixas)\n    return ERROR_INT(\"pixas not defined\", procName, 1);\n\n  boxd = pixaGetBox(pixad, d_idx, L_CLONE);\n  boxs = pixaGetBox(pixas, s_idx, L_CLONE);\n  boxmerge = boxBoundingRegion(boxd, boxs);\n\n  boxGetGeometry(boxmerge, &x, &y, &w, &h);\n  pixmerge = pixCreate(w, h, 1);\n\n  op = PIX_SRC | PIX_DST;\n\n  pixs = pixaGetPix(pixas, s_idx, L_CLONE);\n\n  if (!pixs)\n    return ERROR_INT(\"s_idx not valid\", procName, 1);\n\n  boxGetGeometry(boxs, &dx, &dy, &dw, &dh);\n  pixRasterop(pixmerge, dx - x, dy - y, dw, dh, op, pixs, 0, 0);\n  pixDestroy(&pixs);\n  boxDestroy(&boxs);\n\n  pixd = pixaGetPix(pixad, d_idx, L_CLONE);\n\n  if (!pixd)\n    return ERROR_INT(\"d_idx not valid\", procName, 1);\n\n  boxGetGeometry(boxd, &dx, &dy, &dw, &dh);\n  pixRasterop(pixmerge, dx - x, dy - y, dw, dh, op, pixd, 0, 0);\n  pixDestroy(&pixd);\n  boxDestroy(&boxd);\n\n  pixaReplacePix(pixad, d_idx, pixmerge, boxmerge);\n\n  return 0;\n}\n\nl_int32 MergePairFragments(PIX *pix8, PIXA *clusters, PIXA *pixa, l_uint8 *remove) {\n  l_uint8 setj;\n  l_int32 i, j, real_j, contains, n, count, num_clusters, initj;\n  l_int32 xi, yi, wi, hi;\n  l_int32 xj, yj, wj, hj;\n  BOX *boxi, *boxj;\n  PIXA *pixasort;\n  NUMA *numa;\n\n  PROCNAME(\"pixMergePairFragments\");\n\n  if (!pixa)\n    return ERROR_INT(\"pixa not defined\", procName, -1);\n  if (!remove)\n    return ERROR_INT(\"remove not defined\", procName, -1);\n\n  n = pixaGetCount(pixa);\n  num_clusters = pixaGetCount(clusters);\n\n  if (!n) {\n    L_INFO(\"pixa contained 0 pix\", procName);\n    return 0;\n  }\n  if (!num_clusters) {\n    L_INFO(\"clusters contained 0 pix\", procName);\n    return 0;\n  }\n  if ((pixasort = pixaSort(pixa, L_SORT_BY_Y, L_SORT_INCREASING, &numa, L_CLONE)) == NULL)\n    return ERROR_INT(\"failed to sort pixa\", procName, -1);\n\n  count = 0;\n  initj = 0;\n  setj = 0;\n\n  for (i = 0; i < num_clusters; i++) {\n    pixaGetBoxGeometry(clusters, i, &xi, &yi, &wi, &hi);\n    boxi = pixaGetBox(clusters, i, L_CLONE);\n\n    setj = 0;\n\n    for (j = initj; j < n; j++) {\n      numaGetIValue(numa, j, &real_j);\n\n      // Only consider removed pix\n      if (!remove[real_j])\n        continue;\n\n      pixaGetBoxGeometry(pixasort, j, &xj, &yj, &wj, &hj);\n\n      // If the top of this pix is above the top of the cluster, skip\n      if (yj < yi)\n        continue;\n\n      if (!setj) {\n        initj = j;\n        setj = 1;\n      }\n\n      // If the bottom of this pix is below the bottom of the cluster, stop\n      if (yj > yi + hi)\n        break;\n\n      boxj = pixaGetBox(pixasort, j, L_CLONE);\n\n      boxIntersects(boxi, boxj, &contains);\n\n      if (contains) {\n        MergePix(clusters, i, pixasort, j);\n        //remove[real_j] = 0; // TODO eliminates duplicates\n        count++;\n      }\n\n      boxDestroy(&boxj);\n    }\n\n    boxDestroy(&boxi);\n  }\n\n  pixaDestroy(&pixasort);\n  numaDestroy(&numa);\n\n  return count;\n}\n\nl_int32 RemoveInvalidPairs(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove,\n                           HydrogenTextDetector::TextDetectorParameters &params) {\n  l_int32 i, j, n, count;\n  l_float32 pair_conf;\n  l_uint8 *has_partner;\n  BOX *b1, *b2;\n\n  PROCNAME(\"pixRemoveInvalidPairs\");\n\n  if (!pixa)\n    return ERROR_INT(\"pixa not defined\", procName, -1);\n  if (!remove)\n    return ERROR_INT(\"remove not defined\", procName, -1);\n\n  n = pixaGetCount(pixa);\n\n  if (!n) {\n    L_INFO(\"pixa contained 0 pix\", procName);\n    return 0;\n  }\n\n  has_partner = (l_uint8 *) calloc(n, sizeof(l_uint8));\n  count = 0;\n\n  for (i = 0; i < n; i++) {\n    if (remove[i])\n      continue;\n\n    b1 = pixaGetBox(pixa, i, L_CLONE);\n\n    /* Search right for a partner for i */\n    for (j = i + 1; j < n; j++) {\n      if (remove[j])\n        continue;\n\n      b2 = pixaGetBox(pixa, j, L_CLONE);\n\n      /* Check whether this is a valid pair */\n      if (!ValidatePair(b1, b2, &pair_conf, params)) {\n        boxDestroy(&b2);\n        continue;\n      }\n\n      // We don't need to adjust confidence values here, since we'll\n      // generate cluster pairs and use those later.\n\n      boxDestroy(&b2);\n\n      has_partner[i] = 1;\n      has_partner[j] = 1;\n      break;\n    }\n\n    boxDestroy(&b1);\n  }\n\n  for (i = 0; i < n; i++) {\n    if (!has_partner[i]) {\n      remove[i] = 1;\n\n      count++;\n    }\n  }\n\n  free(has_partner);\n\n  return count;\n}\n\n// Clustering pass\n\nl_int32 GenerateClusterPartners(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove, l_int32 **pleft,\n                                l_int32 **pright, HydrogenTextDetector::TextDetectorParameters &params) {\n  l_int32 n, i, j;\n  l_int32 xi, yi, wi, hi, maxd;\n  l_int32 xj, yj, wj, hj;\n  l_int32 dx, dy, d, mind, minj;\n  l_int32 *left, *right;\n  l_float32 clusterpair_conf, minconf;\n  BOX *b1, *b2;\n  bool too_far;\n\n  PROCNAME(\"GenerateClusterPartners\");\n\n  if (!pixa)\n    return ERROR_INT(\"pixa not defined\", procName, -1);\n  if (!pright)\n    return ERROR_INT(\"&right not defined\", procName, -1);\n  if (!pleft)\n    return ERROR_INT(\"&left not defined\", procName, -1);\n\n  n = pixaGetCount(pixa);\n\n  if (!n) {\n    L_INFO(\"pixa contained 0 pix\", procName);\n    return 0;\n  }\n\n  /* If n == 0, remove may be NULL. Since we have already checked for that,\n   * any NULL arrays signal an error condition.\n   */\n  if (!remove)\n    return ERROR_INT(\"remove not defined\", procName, -1);\n\n  left = (l_int32 *) malloc(n * sizeof(l_int32));\n  right = (l_int32 *) malloc(n * sizeof(l_int32));\n\n  /* Initialize left and right arrays */\n  for (i = 0; i < n; i++) {\n    left[i] = -2;\n    right[i] = -2;\n  }\n\n  /* For each component, check all possible neighbors to find the most likely\n   * right neighbor. If that right neighbor already has a left neighbor, insert\n   * the component to the right of the existing neighbor and the left of the\n   * right neighbor.\n   */\n  for (i = 0; i < n; i++) {\n    if (remove[i])\n      continue;\n\n    pixaGetBoxGeometry(pixa, i, &xi, &yi, &wi, &hi);\n    b1 = pixaGetBox(pixa, i, L_CLONE);\n    mind = -1;\n    minj = -1;\n    maxd = L_MAX(wi, hi);\n    minconf = 0.0;\n\n    /* Search for closest right neighbor */\n    for (j = i + 1; j < n; j++) {\n      if (remove[j])\n        continue;\n\n      pixaGetBoxGeometry(pixa, j, &xj, &yj, &wj, &hj);\n      b2 = pixaGetBox(pixa, j, L_CLONE);\n\n      if (!ValidateClusterPair(b1, b2, &too_far, &clusterpair_conf, params)) {\n        if (too_far)\n          break;\n        else\n          continue;\n      }\n\n      /* calculate spacing between i and j */\n      dx = xj - (xi + wi);\n      dy = (yj + hj) - (yi + hi);\n      d = dx * dx + dy * dy;\n\n      /* If we haven't found a neighbor OR we're the closest neighbor, update\n       * i's record for most likely neighbor.\n       */\n      if (mind < 0 || d < mind) {\n        mind = d;\n        minj = j;\n        minconf = clusterpair_conf;\n      }\n    }\n\n    /* If we found a valid neighbor, go ahead and use it. */\n    if (mind >= 0) {\n      j = left[minj];\n\n      /* If minj already had a left neighbor, replace it with i */\n      // TODO(alanv): Insertion fudges the partner confidence value\n      if (j >= 0) {\n        left[i] = j;\n        right[j] = i;\n      }\n\n      left[minj] = i;\n      right[i] = minj;\n\n      // Adjust confidence to reflect partner confidence\n      l_float32 conf;\n      numaGetFValue(confs, i, &conf);\n      conf *= minconf;\n      numaReplaceNumber(confs, i, conf);\n    }\n  }\n\n  *pleft = left;\n  *pright = right;\n\n  return 0;\n}\n\nl_int32 MergeClusterPartners(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove, l_int32 *left, l_int32 *right,\n                             PIXA **ppixad, NUMA **pclusterconfs, HydrogenTextDetector::TextDetectorParameters &params) {\n  l_int32 n, count, i, j, temp;\n  l_uint32 x, y, w, h;\n  l_int32 xi, yi, wi, hi;\n  l_int32 xj, yj, wj, hj;\n  PIXA *pixad, *pixa_cluster;\n  NUMA *confd, *numa_cluster;\n  PIX *pix, *pixd, *pix_cluster;\n  BOX *box, *boxd;\n\n  PROCNAME(\"ClusterValidComponents\");\n\n  if (!ppixad)\n    return ERROR_INT(\"&pixad not defined\", procName, -1);\n  if (!pclusterconfs)\n    return ERROR_INT(\"&clusterconfs not defined\", procName, -1);\n\n  n = pixaGetCount(pixa);\n\n  pixad = pixaCreate(0);\n  confd = numaCreate(0);\n  *ppixad = pixad;\n  *pclusterconfs = confd;\n\n  if (!n) {\n    L_INFO(\"pixa contained 0 pix\", procName);\n    return 0;\n  }\n\n  /* If n == 0, then left, right, and remove may be NULL. Since we have\n   * already checked for that, any NULL arrays signal an error condition.\n   */\n  if (!left)\n    return ERROR_INT(\"left not defined\", procName, -1);\n  if (!right)\n    return ERROR_INT(\"right not defined\", procName, -1);\n  if (!remove)\n    return ERROR_INT(\"remove not defined\", procName, -1);\n\n  count = 0;\n\n  /* Starting from the first component, generate a cluster by traveling\n   * left and right as far as possible. Ignore components that have no\n   * neighbors.\n   */\n  for (i = 0; i < n; i++) {\n    if (remove[i])\n      continue;\n    if (left[i] < -1 && right[i] < -1)\n      remove[i] = 1;\n    if (left[i] < 0 && right[i] < 0)\n      continue;\n\n    pixa_cluster = pixaCreate(1);\n    numa_cluster = numaCreate(1);\n\n    /* We don't need to destroy this pix and box since pixa_cluster\n     * takes ownership with L_INSERT.\n     */\n    pix = pixaGetPix(pixa, i, L_CLONE);\n    box = pixaGetBox(pixa, i, L_CLONE);\n    pixaAddPix(pixa_cluster, pix, L_INSERT);\n    pixaAddBox(pixa_cluster, box, L_INSERT);\n    numaAddNumber(numa_cluster, i);\n\n    boxGetGeometry(box, &xi, &yi, &wi, &hi);\n    x = xi;\n    y = yi;\n    w = xi + wi;\n    h = yi + hi;\n\n    /* Move along left neighbors */\n    j = left[i];\n    left[i] = -1;\n    while (j >= 0) {\n      pix = pixaGetPix(pixa, j, L_CLONE);\n      box = pixaGetBox(pixa, j, L_CLONE);\n      pixaAddPix(pixa_cluster, pix, L_INSERT);\n      pixaAddBox(pixa_cluster, box, L_INSERT);\n      numaAddNumber(numa_cluster, j);\n\n      boxGetGeometry(box, &xj, &yj, &wj, &hj);\n      x = L_MIN(x, (l_uint32) xj);\n      y = L_MIN(y, (l_uint32) yj);\n      w = L_MAX(w, (l_uint32) (xj + wj));\n      h = L_MAX(h, (l_uint32) (yj + hj));\n\n      right[j] = -1;\n      temp = left[j];\n      left[j] = -1;\n      j = temp;\n    }\n\n    /* Move along right neighbors */\n    j = right[i];\n    right[i] = -1;\n    while (j >= 0) {\n      pix = pixaGetPix(pixa, j, L_CLONE);\n      box = pixaGetBox(pixa, j, L_CLONE);\n      pixaAddPix(pixa_cluster, pix, L_INSERT);\n      pixaAddBox(pixa_cluster, box, L_INSERT);\n      numaAddNumber(numa_cluster, j);\n\n      boxGetGeometry(box, &xj, &yj, &wj, &hj);\n      x = L_MIN(x, (l_uint32) xj);\n      y = L_MIN(y, (l_uint32) yj);\n      w = L_MAX(w, (l_uint32) xj + wj);\n      h = L_MAX(h, (l_uint32) (yj + hj));\n\n      left[j] = -1;\n      temp = right[j];\n      right[j] = -1;\n      j = temp;\n    }\n\n    w = w - x;\n    h = h - y;\n\n    boxd = boxCreate(x, y, w, h);\n    pix_cluster = pixClipRectangle(pix8, boxd, NULL);\n\n    l_float32 temp_conf;\n    l_float32 cluster_conf;\n\n    /* If pixa seems valid, collapse its components to a single pix */\n    if (ValidateCluster(pix_cluster, pixa_cluster, boxd, &cluster_conf, params)) {\n      l_int32 num_comps = pixaGetCount(pixa_cluster);\n      l_float32 avg_conf = 0.0;\n\n      pixd = pixCreate(w, h, 1);\n\n      for (int i = 0; i < num_comps; i++) {\n        pix = pixaGetPix(pixa_cluster, i, L_CLONE);\n        pixaGetBoxGeometry(pixa_cluster, i, &xj, &yj, &wj, &hj);\n        pixRasterop(pixd, xj - x, yj - y, wj, hj, PIX_PAINT, pix, 0, 0);\n        pixDestroy(&pix);\n\n        numaGetFValue(confs, i, &temp_conf);\n        avg_conf += temp_conf;\n      }\n\n      // Adjust average confidence to reflect overall cluster confidence\n      avg_conf /= num_comps;\n      avg_conf *= cluster_conf;\n\n      pixaAddPix(pixad, pixd, L_INSERT);\n      pixaAddBox(pixad, boxd, L_INSERT);\n      numaAddNumber(confd, avg_conf);\n\n      count++;\n    } else {\n      l_int32 num_nums = numaGetCount(numa_cluster);\n\n      // Otherwise, mark its components as removed\n      for (int i = 0; i < num_nums; i++) {\n        if (!numaGetIValue(numa_cluster, i, &temp)) {\n          remove[temp] = 1;\n        }\n      }\n\n      boxDestroy(&boxd);\n    }\n\n    pixDestroy(&pix_cluster);\n    pixaDestroy(&pixa_cluster);\n    numaDestroy(&numa_cluster);\n  }\n\n  free(left);\n  free(right);\n\n  PIXA *pixasort;\n  NUMA *confsort;\n\n  /* Sort pixa, then destroy old pixa */\n  NUMA *naindex;\n  if ((pixasort = pixaSort(pixad, L_SORT_BY_Y, L_SORT_INCREASING, &naindex, L_CLONE)) == NULL)\n    return ERROR_INT(\"pixasort not made\", procName, 1);\n  confsort = numaSortByIndex(confd, naindex);\n\n  *ppixad = pixasort;\n  *pclusterconfs = confsort;\n\n  pixaDestroy(&pixad);\n  numaDestroy(&confd);\n\n  return count;\n}\n\nl_int32 ClusterValidComponents(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove, PIXA **ppixad,\n                               NUMA **pclusterconfs, HydrogenTextDetector::TextDetectorParameters &params) {\n  l_int32 *left, *right;\n  PIXA *pixad;\n  NUMA *clusterconfs;\n\n  if (GenerateClusterPartners(pix8, pixa, confs, remove, &left, &right, params))\n    return -1;\n\n  int count = MergeClusterPartners(pix8, pixa, confs, remove, left, right, &pixad, &clusterconfs, params);\n\n  *ppixad = pixad;\n  *pclusterconfs = clusterconfs;\n\n  return count;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/clusterer.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef HYDROGEN_CLUSTERER_H_\n#define HYDROGEN_CLUSTERER_H_\n\n#include \"leptonica.h\"\n#include \"hydrogentextdetector.h\"\n\nl_int32 ConnCompValidPixa(PIX *pix8, PIX *pix, PIXA **ppixa, NUMA **pconfs,\n                          HydrogenTextDetector::TextDetectorParameters &params);\n\nl_int32 MergePix(PIXA *pixad, l_int32 i, PIXA *pixas, l_int32 j);\n\nl_int32 RemoveInvalidPairs(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove,\n                           HydrogenTextDetector::TextDetectorParameters &params);\n\nl_int32 ClusterValidComponents(PIX *pix8, PIXA *pixa, NUMA *confs, l_uint8 *remove, PIXA **ppixad, NUMA **pconfs,\n                               HydrogenTextDetector::TextDetectorParameters &params);\n\nl_int32 MergePairFragments(PIX *pix8, PIXA *clusters, PIXA *pixa, l_uint8 *remove);\n\n#endif /* HYDROGEN_CLUSTERER_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/hydrogentextdetector.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <ctime>\n#include <cstring>\n#include <cstdlib>\n\n#include \"leptonica.h\"\n#include \"hydrogentextdetector.h\"\n#include \"clusterer.h\"\n#include \"thresholder.h\"\n#include \"utilities.h\"\n\nHydrogenTextDetector::HydrogenTextDetector() {\n  pixs_ = NULL;\n  text_areas_ = NULL;\n  text_confs_ = NULL;\n}\n\nHydrogenTextDetector::~HydrogenTextDetector() {\n  Clear();\n}\n\nPIXA *HydrogenTextDetector::ExtractTextRegions(PIX *pix8, PIX *edges, NUMA **pconfs) {\n  l_int32 result;\n\n  if (parameters_.debug) fprintf(stderr, \"ExtractTextRegions()\\n\");\n\n  // TODO(alanv): More error checking for invalid arguments\n  if (!pconfs) {\n    return NULL;\n  }\n\n  clock_t timer = clock();\n  NUMA *connconfs;\n  PIXA *conncomp;\n\n  if (parameters_.debug) fprintf(stderr, \"ConnCompValidPixa()\\n\");\n  result = ConnCompValidPixa(pix8, edges, &conncomp, &connconfs, parameters_);\n\n  if (parameters_.debug) fprintf(stderr, \"Found %d connected components\\n\", result);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0' && result > 0) {\n    PIX *temp = pixaDisplayHeatmap(conncomp, pix8->w, pix8->h, connconfs);\n    char filename[255];\n    sprintf(filename, \"%s/%d_validsingles.jpg\", parameters_.out_dir, (int) timer);\n    pixWriteImpliedFormat(filename, temp, 85, 0);\n  }\n\n  l_int32 count = pixaGetCount(conncomp);\n  l_uint8 *remove = (l_uint8 *) calloc(count, sizeof(l_uint8));\n\n  if (parameters_.debug) fprintf(stderr, \"RemoveInvalidPairs()\\n\");\n  result = RemoveInvalidPairs(pix8, conncomp, connconfs, remove, parameters_);\n\n  if (parameters_.debug) fprintf(stderr, \"Removed %d invalid pairs\\n\", result);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0' && result > 0) {\n    PIX *temp = pixaDisplayRandomCmapFiltered(conncomp, pix8->w, pix8->h, remove);\n    char filename[255];\n    sprintf(filename, \"%s/%d_validpairs.jpg\", parameters_.out_dir, (int) timer);\n    pixWriteImpliedFormat(filename, temp, 85, 0);\n  }\n\n  NUMA *clusterconfs;\n  PIXA *clusters;\n  if (parameters_.debug) fprintf(stderr, \"ClusterValidComponents()\\n\");\n  result = ClusterValidComponents(pix8, conncomp, connconfs, remove, &clusters, &clusterconfs, parameters_);\n\n  if (parameters_.debug) fprintf(stderr, \"Created %d clusters\\n\", result);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0' && result > 0) {\n    PIX *temp = pixaDisplayHeatmap(clusters, pix8->w, pix8->h, clusterconfs);\n    char filename[255];\n    sprintf(filename, \"%s/%d_validclusters.jpg\", parameters_.out_dir, (int) timer);\n    pixWriteImpliedFormat(filename, temp, 85, 0);\n  }\n\n  // Merge unused components that are contained inside the detected text areas.\n  // This typically catches punctuation and dots over i's and j's.\n  if (parameters_.debug) fprintf(stderr, \"MergePairFragments()\\n\");\n  result = MergePairFragments(pix8, clusters, conncomp, remove);\n\n  *pconfs = clusterconfs;\n\n  pixaDestroy(&conncomp);\n  free(remove);\n\n  return clusters;\n}\n\nPIX *HydrogenTextDetector::DetectAndFixSkew(PIX *pixs) {\n  l_float32 angle, conf;\n\n  skew_angle_ = 0.0;\n\n  if (!parameters_.skew_enabled) {\n    if (parameters_.debug) fprintf(stderr, \"Bypassed skew (skew detection is disabled)\\n\");\n\n    return pixClone(pixs);\n  }\n\n  if (pixFindSkewSweepAndSearch(pixs, &angle, &conf, parameters_.skew_sweep_reduction,\n                                parameters_.skew_search_reduction, parameters_.skew_sweep_range,\n                                parameters_.skew_sweep_delta, parameters_.skew_search_min_delta)) {\n    if (parameters_.debug) fprintf(stderr, \"Bypassed skew (failed sweep and search)\\n\");\n\n    return pixClone(pixs);\n  }\n\n  if (conf <= 0 || L_ABS(angle) < parameters_.skew_min_angle) {\n    if (parameters_.debug) fprintf(stderr, \"Bypassed skew (low confidence or small angle)\\n\");\n\n    return pixClone(pixs);\n  }\n\n  if (parameters_.debug) fprintf(stderr, \"Found %f degree skew with confidence %f\\n\", angle, conf);\n\n  // The detected angle is the one required to align the text,\n  // which is the opposite of the angle of the text itself.\n  skew_angle_ = -angle;\n\n  l_float32 deg2rad = 3.1415926535 / 180.0;\n  l_float32 radians = angle * deg2rad;\n\n  PIX *pixd = pixRotate(pixs, radians, L_ROTATE_SAMPLING, L_BRING_IN_WHITE, 0, 0);\n\n  return pixd;\n}\n\nvoid HydrogenTextDetector::SetSourceImage(PIX *pixs) {\n  pixs_ = pixClone(pixs);\n}\n\nvoid HydrogenTextDetector::DetectText() {\n  if (parameters_.debug) fprintf(stderr, \"DetectText()\\n\");\n\n  clock_t timer = clock();\n\n  PIX *pix8 = pixConvertTo8(pixs_, false);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0') {\n    char filename[255];\n    sprintf(filename, \"%s/%d_input.jpg\", parameters_.out_dir, (int) timer);\n    pixWriteImpliedFormat(filename, pix8, 85, 0);\n  }\n\n  PIX *edges;\n  pixEdgeAdaptiveThreshold(pix8, &edges, parameters_.edge_tile_x, parameters_.edge_tile_y,\n                           parameters_.edge_thresh, parameters_.edge_avg_thresh);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0') {\n    char filename[255];\n    sprintf(filename, \"%s/%d_edges.jpg\", parameters_.out_dir, (int) timer);\n    PIX *edges8 = pixConvertTo8(edges, false);\n    pixWriteImpliedFormat(filename, edges8, 85, 0);\n    pixDestroy(&edges8);\n  }\n\n  PIX *deskew = DetectAndFixSkew(edges);\n  pixDestroy(&edges);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0') {\n    char filename[255];\n    sprintf(filename, \"%s/%d_deskew.jpg\", parameters_.out_dir, (int) timer);\n\n    PIX *deskew8 = pixConvertTo8(deskew, false);\n    pixWriteImpliedFormat(filename, deskew8, 85, 0);\n    pixDestroy(&deskew8);\n  }\n\n  NUMA *confs;\n  PIXA *clusters = ExtractTextRegions(pix8, deskew, &confs);\n\n  if (parameters_.debug) fprintf(stderr, \"Inverting image...\\n\");\n  pixInvert(deskew, deskew);\n\n  NUMA *invconfs;\n  PIXA *invclusters = ExtractTextRegions(pix8, deskew, &invconfs);\n  pixDestroy(&deskew);\n  pixDestroy(&pix8);\n\n  pixaJoin(clusters, invclusters, 0, 0);\n  pixaDestroy(&invclusters);\n\n  numaJoin(confs, invconfs);\n  numaDestroy(&invconfs);\n\n  text_areas_ = pixaCopy(clusters, L_CLONE);\n  pixaDestroy(&clusters);\n\n  text_confs_ = numaClone(confs);\n  numaDestroy(&confs);\n\n  if (parameters_.debug && parameters_.out_dir[0] != '\\0') {\n    PIX *temp = pixaDisplayHeatmap(text_areas_, pixs_->w, pixs_->h, text_confs_);\n    char filename[255];\n    sprintf(filename, \"%s/heatmap.jpg\", parameters_.out_dir);\n    pixWriteImpliedFormat(filename, temp, 85, 0);\n  }\n}\n\nvoid HydrogenTextDetector::Clear() {\n  if (text_confs_) {\n    numaDestroy(&text_confs_);\n  }\n\n  if (text_areas_) {\n    pixaDestroy(&text_areas_);\n  }\n\n  if (pixs_) {\n    pixDestroy(&pixs_);\n  }\n}\n\nPIXA *HydrogenTextDetector::GetTextAreas() {\n  return pixaCopy(text_areas_, L_CLONE);\n}\n\nl_float32 HydrogenTextDetector::GetSkewAngle() {\n  return skew_angle_;\n}\n\nNUMA *HydrogenTextDetector::GetTextConfs() {\n  return numaClone(text_confs_);\n}\n\nPIX *HydrogenTextDetector::GetSourceImage() {\n  return pixClone(pixs_);\n}\n\nHydrogenTextDetector::TextDetectorParameters *HydrogenTextDetector::GetMutableParameters() {\n  return &parameters_;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/hydrogentextdetector.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef HYDROGEN_HYDROGENTEXTDETECTOR_H_\n#define HYDROGEN_HYDROGENTEXTDETECTOR_H_\n\n#include \"leptonica.h\"\n\nclass HydrogenTextDetector {\npublic:\n  HydrogenTextDetector();\n\n  ~HydrogenTextDetector();\n\n  struct TextDetectorParameters {\n    bool debug;\n    char out_dir[255];\n\n    // Edge-based thresholding\n    l_int32 edge_tile_x;\n    l_int32 edge_tile_y;\n    l_int32 edge_thresh;\n    l_int32 edge_avg_thresh;\n\n    // Skew angle correction\n    bool skew_enabled;\n    l_float32 skew_min_angle;\n    l_float32 skew_sweep_range;\n    l_float32 skew_sweep_delta;\n    l_int32 skew_sweep_reduction;\n    l_int32 skew_search_reduction;\n    l_float32 skew_search_min_delta;\n\n    // Singleton filter\n    l_float32 single_min_aspect;\n    l_float32 single_max_aspect;\n    l_int32 single_min_area;\n    l_float32 single_min_density;\n\n    // Quick pair filter\n    l_float32 pair_h_ratio;\n    l_float32 pair_d_ratio;\n    l_float32 pair_h_dist_ratio;\n    l_float32 pair_v_dist_ratio;\n    l_float32 pair_h_shared;\n\n    // Cluster pair filter\n    l_int32 cluster_width_spacing;\n    l_float32 cluster_shared_edge;\n    l_float32 cluster_h_ratio;\n\n    // Finalized cluster filter\n    l_int32 cluster_min_blobs;\n    l_float32 cluster_min_aspect;\n    l_float32 cluster_min_fdr;\n    l_int32 cluster_min_edge;\n    l_int32 cluster_min_edge_avg;\n\n    TextDetectorParameters()\n        : debug(false),\n          edge_tile_x(32),\n          edge_tile_y(64),\n          edge_thresh(64),\n          edge_avg_thresh(4),\n          skew_enabled(true),\n          skew_min_angle(1.0),\n          skew_sweep_range(30.0),\n          skew_sweep_delta(5.0),\n          skew_sweep_reduction(8),\n          skew_search_reduction(4),\n          skew_search_min_delta(0.01),\n          single_min_aspect(0.1),\n          single_max_aspect(4.0),\n          single_min_area(4),\n          single_min_density(0.2),\n          pair_h_ratio(1.0),\n          pair_d_ratio(1.5),\n          pair_h_dist_ratio(2.0),\n          pair_v_dist_ratio(0.25),\n          pair_h_shared(0.25),\n          cluster_width_spacing(2),\n          cluster_shared_edge(0.5),\n          cluster_h_ratio(1.0),\n          cluster_min_blobs(5),\n          cluster_min_aspect(2),\n          cluster_min_fdr(2.5),\n          cluster_min_edge(32),\n          cluster_min_edge_avg(1)\n          {\n    }\n  };\n\n  // Function to set the original source image\n  void SetSourceImage(PIX *);\n\n  // Main text detection function\n  void DetectText();\n\n  // Clear recognition results between calls\n  void Clear();\n\n  // Function to return text area clippings of the original image\n  PIXA *GetImageAreas();\n\n  // Function to return binarized text areas\n  PIXA *GetTextAreas();\n\n  // Function to return text area confidences\n  NUMA *GetTextConfs();\n\n  // Function to return detected skew angle\n  l_float32 GetSkewAngle();\n\n  // Function to return the original source image\n  PIX *GetSourceImage();\n\n  TextDetectorParameters *GetMutableParameters();\n\nprivate:\n  TextDetectorParameters parameters_;\n\n  // Source image\n  PIX *pixs_;\n  // Detected text areas\n  PIXA *text_areas_;\n  // Confidences of detected text areas\n  NUMA *text_confs_;\n  // Detected skew angle\n  l_float32 skew_angle_;\n\n  // Function to extract text areas from a PIX\n  PIXA *ExtractTextRegions(PIX *pix8, PIX *edges, NUMA **pconfs);\n\n  // Function to detect and fix text skew\n  PIX *DetectAndFixSkew(PIX *pixs);\n};\n\n#endif /* HYDROGEN_HYDROGENTEXTDETECTOR_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/leptonica.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef  HYDROGEN_LEPTONICA_H_\n#define  HYDROGEN_LEPTONICA_H_\n\n#include \"allheaders.h\"\n\n#endif  /* HYDROGEN_LEPTONICA_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/thresholder.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <math.h>\n\n#include \"leptonica.h\"\n#include \"thresholder.h\"\n\n/*!\n *  pixFisherAdaptiveThreshold()\n *\n *      Input:  pixs (8 bpp)\n *              &pixd (<required return> thresholded input for pixs)\n *              sx, sy (desired tile dimensions; actual size may vary)\n *              scorefract (fraction of the max Otsu score; typ. 0.1)\n *              fdrthresh (threshold for Fisher's Discriminant Rate; typ. 5.0)\n *      Return: 0 if OK, 1 on error\n */\nl_int32 pixFisherAdaptiveThreshold(PIX *pixs, PIX **ppixd, l_int32 tile_x, l_int32 tile_y,\n                                l_float32 score_fract, l_float32 thresh) {\n  l_float32 fdr;\n  l_int32 w, h, d, nx, ny, x, y, t;\n  PIX *pixb, *pixd, *pixt;\n  PIXTILING *pt;\n\n  PROCNAME(\"pixFisherAdaptiveThreshold\");\n\n  if (!pixs)\n    return ERROR_INT(\"pixs not defined\", procName, 1);\n  if (!ppixd)\n    return ERROR_INT(\"&ppixd not defined\", procName, 1);\n  pixGetDimensions(pixs, &w, &h, &d);\n  if (d != 8)\n    return ERROR_INT(\"pixs not 8 bpp\", procName, 1);\n  if (tile_x < 8 || tile_y < 8)\n    return ERROR_INT(\"sx and sy must be >= 8\", procName, 1);\n\n  /* Compute FDR & threshold for individual tiles */\n  nx = L_MAX(1, w / tile_x);\n  ny = L_MAX(1, h / tile_y);\n  pt = pixTilingCreate(pixs, nx, ny, 0, 0, 0, 0);\n  pixd = pixCreate(w, h, 1);\n  for (y = 0; y < ny; y++) {\n    for (x = 0; x < nx; x++) {\n      pixt = pixTilingGetTile(pt, y, x);\n      pixGetFisherThresh(pixt, score_fract, &fdr, &t);\n\n      if (fdr > thresh) {\n        pixb = pixThresholdToBinary(pixt, t);\n        pixTilingPaintTile(pixd, y, x, pixb, pt);\n        pixDestroy(&pixb);\n      }\n\n      pixDestroy(&pixt);\n    }\n  }\n\n  pixTilingDestroy(&pt);\n\n  *ppixd = pixd;\n\n  return 0;\n}\n\n/*!\n *  pixGetFisherThresh()\n *\n *      Input:  pixs (any depth; cmapped ok)\n *              scorefract (fraction of the max score, used to determine\n *                          the range over which the histogram min is searched)\n *              &xfdr (<optional return> Fisher's Discriminate Rate value)\n *              &xthresh (<optional return> Otsu threshold value)\n *      Return: 0 if OK, 1 on error\n */\nl_int32 pixGetFisherThresh(PIX *pixs, l_float32 scorefract, l_float32 *pfdr, l_int32 *pthresh) {\n  l_float32 mean1, mean2, sum, sum1, sum2, fract;\n  l_float32 var, between, within, fdr;\n  l_int32 thresh;\n  NUMA *na;\n\n  PROCNAME(\"pixGetFisherThresh\");\n\n  if (!pixs)\n    return ERROR_INT(\"pixs not defined\", procName, 1);\n  if (!pfdr && !pthresh)\n    return ERROR_INT(\"neither &pfdr nor &pthresh defined\", procName, 1);\n\n  na = pixGetGrayHistogram(pixs, 1);\n\n  /* Compute Otsu threshold for histogram */\n  numaSplitDistribution(na, scorefract, &thresh, &mean1, &mean2, &sum1, &sum2, NULL);\n\n  /* Compute Fisher's Discriminant Rate if needed */\n  if (pfdr) {\n    numaGetHistogramStats(na, 0.0, 1.0, NULL, NULL, NULL, &var);\n    numaGetSum(na, &sum);\n\n    /* Between-class variance = sum of weighted squared distances\n     between-class and overall means */\n    fract = sum1 / sum;\n    between = (fract * (1 - fract)) * (mean1 - mean2) * (mean1 - mean2);\n\n    /* Within-class variance = difference between total variance\n     and between-class variance */\n    within = var - between;\n\n    /* FDR = between-class variance over within-class variance */\n    if (within <= 1) {\n      fdr = between;\n    } else {\n      fdr = between / within;\n    }\n\n    *pfdr = fdr;\n  }\n\n  if (pthresh)\n    *pthresh = thresh;\n\n  numaDestroy(&na);\n\n  return 0;\n}\n\nPIX *pixThreshedSobelEdgeFilter(PIX *pixs, l_int32 threshold) {\n  l_uint8 bval, bidx;\n  l_int32 w, h, d, i, j, wplt, wpld, gx, gy, vald;\n  l_int32 val1, val2, val3, val4, val5, val6, val7, val8, val9;\n  l_uint32 *datat, *linet, *datad, *lined;\n  PIX *pixd;\n\n  PROCNAME(\"pixThreshedSobelEdgeFilter\");\n\n  if (!pixs)\n    return (PIX *) ERROR_PTR(\"pixs not defined\", procName, NULL);\n  pixGetDimensions(pixs, &w, &h, &d);\n  if (d != 8)\n    return (PIX *) ERROR_PTR(\"pixs not 8 bpp\", procName, NULL);\n\n  /* Compute filter output at each location. */\n  pixd = pixCreateNoInit(w, h, 1);\n  datat = pixGetData(pixs);\n  wplt = pixGetWpl(pixs);\n  datad = pixGetData(pixd);\n  wpld = pixGetWpl(pixd);\n  val1 = val2 = val3 = val4 = val5 = 0;\n  val6 = val7 = val8 = val9 = 0;\n  bval = bidx = 0;\n  for (i = 0; i < h - 1; i++) {\n    linet = datat + i * wplt;\n    lined = datad + i * wpld;\n    for (j = 0; j < w - 1; j++) {\n      if (j == 0) { /* start a new row */\n        val1 = GET_DATA_BYTE(linet, j);\n        val2 = GET_DATA_BYTE(linet + wplt, j);\n        val3 = GET_DATA_BYTE(linet + (wplt << 1), j);\n        val4 = GET_DATA_BYTE(linet, j + 1);\n        val5 = GET_DATA_BYTE(linet + wplt, j + 1);\n        val6 = GET_DATA_BYTE(linet + (wplt << 1), j + 1);\n        val7 = GET_DATA_BYTE(linet, j + 2);\n        val8 = GET_DATA_BYTE(linet + wplt, j + 2);\n        val9 = GET_DATA_BYTE(linet + (wplt << 1), j + 2);\n        bval = 0;\n        bidx = 0x80;\n      } else { /* shift right by 1 pixel; update incrementally */\n        val1 = val4;\n        val2 = val5;\n        val3 = val6;\n        val4 = val7;\n        val5 = val8;\n        val6 = val9;\n        val7 = GET_DATA_BYTE(linet, j + 2);\n        val8 = GET_DATA_BYTE(linet + wplt, j + 2);\n        val9 = GET_DATA_BYTE(linet + (wplt << 1), j + 2);\n      }\n\n      bval <<= 1;\n      bidx >>= 1;\n\n      gx = val1 + (val2 << 1) + val3 - val7 - (val8 << 1) - val9;\n      gy = val1 + (val4 << 1) + val7 - val3 - (val6 << 1) - val9;\n      vald = L_MIN(255, L_ABS(gx) + L_ABS(gy));\n\n      /* Flip high bit if value exceeds threshold */\n      if (vald >= threshold) {\n        bval |= 1;\n      }\n\n      if (bidx == 0) {\n        SET_DATA_BYTE(lined, j / 8, bval);\n\n        bval = 0;\n        bidx = 0x80;\n      }\n    }\n  }\n\n  return pixd;\n}\n\nl_uint8 pixGradientEnergy(PIX *pixs, PIX *mask, l_float32 *penergy) {\n  l_int32 w, h, d;\n  l_uint8 val1, val2;\n  l_uint32 mask1, mask2;\n  l_int32 wpls, wplm;\n  l_uint32 *datas, *lines;\n  l_uint32 *datam, *linem;\n  l_int32 total, count;\n\n  PROCNAME(\"pixGradientEnergy\");\n\n  if (!pixs)\n    return ERROR_INT(\"pixs not defined\", procName, -1);\n  pixGetDimensions(pixs, &w, &h, &d);\n  if (d != 8)\n    return ERROR_INT(\"pixs not 8 bpp\", procName, -1);\n\n  /* Compute filter output at each location. */\n  datas = pixGetData(pixs);\n  wpls = pixGetWpl(pixs);\n  datam = pixGetData(mask);\n  wplm = pixGetWpl(mask);\n  total = 0;\n  count = 1;\n  mask1 = mask2 = 0;\n  val1 = val2 = 0;\n  for (int y = 0; y < h; y++) {\n    lines = datas + y * wpls;\n    linem = datam + y * wplm;\n    for (int x = 0; x < w - 1; x++) {\n      if (x == 0) { /* start a new row */\n        mask1 = GET_DATA_BIT(linem, x);\n        mask2 = GET_DATA_BIT(linem, x + 1);\n        val1 = GET_DATA_BYTE(lines, x);\n        val2 = GET_DATA_BYTE(lines, x + 1);\n      } else { /* shift right by 1 pixel; update incrementally */\n        val1 = val2;\n        val2 = GET_DATA_BYTE(lines, x + 1);\n        mask1 = mask2;\n        mask2 = GET_DATA_BIT(linem, x + 1);\n      }\n\n      /* If we're on an edge, add the gradient value and increment */\n      if (mask1 != mask2) {\n        total += L_ABS(val1 - val2);\n        count += 1;\n      }\n    }\n  }\n\n  *penergy = total / (l_float32) count;\n\n  return 0;\n}\n\nl_uint8 pixEdgeMax(PIX *pixs, l_int32 *pmax, l_int32 *pavg) {\n  l_int32 w, h, d, wplt, vald;\n  l_uint8 val1, val2, val3, val4, val5;\n  l_uint32 *datat, *linet;\n  l_int32 max, total;\n\n  PROCNAME(\"pixEdgeMax\");\n\n  if (!pixs)\n    return ERROR_INT(\"pixs not defined\", procName, -1);\n  pixGetDimensions(pixs, &w, &h, &d);\n  if (d != 8)\n    return ERROR_INT(\"pixs not 8 bpp\", procName, -1);\n\n  /* Compute filter output at each location. */\n  datat = pixGetData(pixs);\n  wplt = pixGetWpl(pixs);\n  max = 0;\n  total = 0;\n  val1 = val2 = val3 = val4 = val5 = 0;\n  for (int y = 0; y < h; y++) {\n    linet = datat + y * wplt;\n    for (int x = 0; x < w - 5; x++) {\n      if (x == 0) { /* start a new row */\n        val1 = GET_DATA_BYTE(linet, x);\n        val2 = GET_DATA_BYTE(linet, x + 1);\n        val3 = GET_DATA_BYTE(linet, x + 2);\n        val4 = GET_DATA_BYTE(linet, x + 3);\n        val5 = GET_DATA_BYTE(linet, x + 4);\n      } else { /* shift right by 1 pixel; update incrementally */\n        val1 = val2;\n        val2 = val3;\n        val3 = val4;\n        val4 = val5;\n        val5 = GET_DATA_BYTE(linet, x + 4);\n      }\n\n      //maxd = L_MAX(val5, L_MAX(val4, L_MAX(val3, L_MAX(val2, val1))));\n      //mind = L_MIN(val5, L_MIN(val4, L_MIN(val3, L_MIN(val2, val1))));\n      vald = L_ABS(val1 - val5); //maxd - mind;\n\n      if (vald > max) {\n        max = vald;\n      }\n\n      total += vald;\n    }\n  }\n\n  *pmax = max;\n  *pavg = total / (w * h);\n\n  return 0;\n}\n\n/*!\n *  pixEdgeAdaptiveThreshold()\n *\n *      Input:  pixs (8 bpp)\n *              &pixd (<required return> thresholded input for pixs)\n *              tile_x, tile_y (desired tile dimensions; actual size may vary)\n *              thresh\n *              avg_thresh\n *      Return: 0 if OK, 1 on error\n */\nl_uint8 pixEdgeAdaptiveThreshold(PIX *pixs, PIX **ppixd, l_int32 tile_x, l_int32 tile_y,\n                                  l_int32 thresh, l_int32 avg_thresh) {\n  l_int32 w, h, d, nx, ny, x, y, t, max, avg;\n  PIX *pixb, *pixd, *pixt;\n  PIXTILING *pt;\n\n  PROCNAME(\"pixEdgeAdaptiveThreshold\");\n\n  if (!pixs)\n    return ERROR_INT(\"pixs not defined\", procName, 1);\n  if (!ppixd)\n    return ERROR_INT(\"&ppixd not defined\", procName, 1);\n  pixGetDimensions(pixs, &w, &h, &d);\n  if (d != 8)\n    return ERROR_INT(\"pixs not 8 bpp\", procName, 1);\n  if (tile_x < 8 || tile_y < 8)\n    return ERROR_INT(\"sx and sy must be >= 8\", procName, 1);\n\n  /* Compute FDR & threshold for individual tiles */\n  nx = L_MAX(1, w / tile_x);\n  ny = L_MAX(1, h / tile_y);\n  pt = pixTilingCreate(pixs, nx, ny, 0, 0, 0, 0);\n  pixd = pixCreate(w, h, 1);\n  for (y = 0; y < ny; y++) {\n    for (x = 0; x < nx; x++) {\n      pixt = pixTilingGetTile(pt, y, x);\n      pixEdgeMax(pixt, &max, &avg);\n\n      if (max > thresh && avg > avg_thresh) {\n        pixSplitDistributionFgBg(pixt, 0.0, 1, &t, NULL, NULL, 0);\n        pixb = pixThresholdToBinary(pixt, t);\n        pixTilingPaintTile(pixd, y, x, pixb, pt);\n        pixDestroy(&pixb);\n      }\n\n      pixDestroy(&pixt);\n    }\n  }\n\n  pixTilingDestroy(&pt);\n\n  *ppixd = pixd;\n\n  return 0;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/thresholder.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef HYDROGEN_THRESHOLDER_H_\n#define HYDROGEN_THRESHOLDER_H_\n\n#include \"leptonica.h\"\n\nl_int32 pixGetFisherThresh(PIX *pixs, l_float32 scorefract, l_float32 *pfdr, l_int32 *pthresh);\n\nl_int32 pixFisherAdaptiveThreshold(PIX *pixs, PIX **ppixd, l_int32 tile_x, l_int32 tile_y,\n                                l_float32 score_fract, l_float32 thresh);\n\nPIX *pixThreshedSobelEdgeFilter(PIX *pixs, l_int32 threshold);\n\nl_uint8 pixGradientEnergy(PIX *pixs, PIX *mask, l_float32 *pdensity);\n\nl_uint8 pixEdgeMax(PIX *pixs, l_int32 *pmax, l_int32 *pavg);\n\nl_uint8 pixEdgeAdaptiveThreshold(PIX *pixs, PIX **ppixd, l_int32 tile_x, l_int32 tile_y,\n                                 l_int32 thresh, l_int32 avg_thresh);\n\n#endif /* HYDROGEN_THRESHOLDER_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/utilities.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/* smart sharpen\n * PIX *edgemask = pixThreshedSobelEdgeFilter(pix8, 16, 2, L_ALL_EDGES);\n * PIX *enhanced = pixUnsharpMasking(pix8, UNSHARP_HALFWIDTH, UNSHARP_FRACTION);\n * PIX *blended = pixBlendWithGrayMask(normalized, enhanced, edgemask, 0, 0);\n */\n\n#include \"leptonica.h\"\n#include \"utilities.h\"\n\nvoid numaJoin(NUMA *dst, NUMA *src) {\n  l_int32 count = numaGetCount(src);\n  l_float32 temp;\n\n  for (int i = 0; i < count; i++) {\n    numaGetFValue(src, i, &temp);\n    numaAddNumber(dst, temp);\n  }\n}\n\nPIX *pixaDisplayRandomCmapFiltered(PIXA *pixa, l_int32 w, l_int32 h, l_uint8 *filter) {\n  l_int32 i, n, d, index, xb, yb, wb, hb;\n  BOXA *boxa;\n  PIX *pixs, *pixt, *pixd;\n  PIXCMAP *cmap;\n\n  PROCNAME(\"pixaDisplayRandomCmapFiltered\");\n\n  if (!pixa)\n    return (PIX *) ERROR_PTR(\"pixa not defined\", procName, NULL);\n  n = pixaGetCount(pixa);\n  if (n == 0)\n    return (PIX *) ERROR_PTR(\"no components\", procName, NULL);\n\n  /* Use the first pix in pixa to verify depth is 1 bpp  */\n  pixs = pixaGetPix(pixa, 0, L_CLONE);\n  d = pixGetDepth(pixs);\n  pixDestroy(&pixs);\n  if (d != 1)\n    return (PIX *) ERROR_PTR(\"components not 1 bpp\", procName, NULL);\n\n  /* If w and h not input, determine the minimum size required\n   * to contain the origin and all c.c. */\n  if (w == 0 || h == 0) {\n    boxa = pixaGetBoxa(pixa, L_CLONE);\n    boxaGetExtent(boxa, &w, &h, NULL);\n    boxaDestroy(&boxa);\n  }\n\n  /* Set up an 8 bpp dest pix, with a colormap with 254 random colors */\n  if ((pixd = pixCreate(w, h, 8)) == NULL)\n    return (PIX *) ERROR_PTR(\"pixd not made\", procName, NULL);\n  cmap = pixcmapCreateRandom(8, 1, 1);\n  pixSetColormap(pixd, cmap);\n\n  /* Color each component and blit it in */\n  for (i = 0; i < n; i++) {\n    if (filter[i])\n      continue;\n    index = 1 + (i % 254);\n    pixaGetBoxGeometry(pixa, i, &xb, &yb, &wb, &hb);\n    pixs = pixaGetPix(pixa, i, L_CLONE);\n    pixt = pixConvert1To8(NULL, pixs, 0, index);\n    pixRasterop(pixd, xb, yb, wb, hb, PIX_PAINT, pixt, 0, 0);\n    pixDestroy(&pixs);\n    pixDestroy(&pixt);\n  }\n\n  return pixd;\n}\n\n/*!\n *  pixcmapCreateHeatmap()\n *\n *      Input:  d (depth of pix for this colormap; 1, 2, 4 or 8)\n *      Return: cmap, or null on error\n *\n *  Notes:\n *      (1) Colormap shows 0 as black, 1-MAX as a range from violet to red.\n */\nPIXCMAP *\npixcmapCreateHeatmap(l_int32  d)\n{\nl_int32   nlevels, i, h, s, v;\nPIXCMAP  *cmap;\n\n    PROCNAME(\"pixcmapCreateHeatmap\");\n\n    if (d != 1 && d != 2 && d !=4 && d != 8)\n        return (PIXCMAP *)ERROR_PTR(\"d not in {1, 2, 4, 8}\", procName, NULL);\n    nlevels = 1 << d;\n\n    cmap = pixcmapCreate(d);\n\n    nlevels--;\n    pixcmapAddColor(cmap, 0, 0, 0);\n\n    for (i = nlevels; i > 0; i--) {\n        h = 170 * i / nlevels;\n        s = 255;\n        v = 255;\n        pixcmapAddColor(cmap, h, s, v);\n    }\n\n    pixcmapConvertHSVToRGB(cmap);\n\n    return cmap;\n}\n\nPIX *pixaDisplayHeatmap(PIXA *pixa, l_int32 w, l_int32 h, NUMA *confs) {\n  l_int32 i, n, d, val, xb, yb, wb, hb;\n  l_float32 maxconf, minconf, confrange, conf;\n  BOXA *boxa;\n  PIX *pixs, *pixt, *pixd;\n  PIXCMAP *cmap;\n\n  PROCNAME(\"pixaDisplayHeatmap\");\n\n  if (!pixa)\n    return (PIX *) ERROR_PTR(\"pixa not defined\", procName, NULL);\n  n = pixaGetCount(pixa);\n  if (n == 0)\n    return (PIX *) ERROR_PTR(\"no components\", procName, NULL);\n\n  /* Use the first pix in pixa to verify depth is 1 bpp  */\n  pixs = pixaGetPix(pixa, 0, L_CLONE);\n  d = pixGetDepth(pixs);\n  pixDestroy(&pixs);\n  if (d != 1)\n    return (PIX *) ERROR_PTR(\"components not 1 bpp\", procName, NULL);\n\n  /* If w and h not input, determine the minimum size required\n   * to contain the origin and all c.c. */\n  if (w == 0 || h == 0) {\n    boxa = pixaGetBoxa(pixa, L_CLONE);\n    boxaGetExtent(boxa, &w, &h, NULL);\n    boxaDestroy(&boxa);\n  }\n\n  /* Determine the confidence range */\n  numaGetMin(confs, &minconf, NULL);\n  numaGetMax(confs, &maxconf, NULL);\n  confrange = maxconf - minconf;\n\n  /* Set up an 8 bpp dest pix, with a colormap with 254 random colors */\n  if ((pixd = pixCreate(w, h, 8)) == NULL)\n    return (PIX *) ERROR_PTR(\"pixd not made\", procName, NULL);\n  cmap = pixcmapCreateHeatmap(8);\n  pixSetColormap(pixd, cmap);\n\n  /* Color each component and blit it in */\n  for (i = 0; i < n; i++) {\n    numaGetFValue(confs, i, &conf);\n    val = (l_int32) ((conf - minconf) / confrange * 254) + 1;\n    pixaGetBoxGeometry(pixa, i, &xb, &yb, &wb, &hb);\n    pixs = pixaGetPix(pixa, i, L_CLONE);\n    pixt = pixConvert1To8(NULL, pixs, 0, val);\n    pixRasterop(pixd, xb, yb, wb, hb, PIX_PAINT, pixt, 0, 0);\n    pixDestroy(&pixs);\n    pixDestroy(&pixt);\n  }\n\n  return pixd;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/utilities.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef HYDROGEN_UTILITIES_H_\n#define HYDROGEN_UTILITIES_H_\n\n#include \"leptonica.h\"\n\nvoid numaJoin(NUMA *dst, NUMA *src);\n\nPIX *pixaDisplayRandomCmapFiltered(PIXA *pixa, l_int32 w, l_int32 h, l_uint8 *filter);\n\nPIX *pixaDisplayHeatmap(PIXA *pixa, l_int32 w, l_int32 h, NUMA *confs);\n\n#endif /* HYDROGEN_UTILITIES_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/validator.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <math.h>\n\n#include \"leptonica.h\"\n#include \"validator.h\"\n#include \"thresholder.h\"\n#include \"utilities.h\"\n#include \"hydrogentextdetector.h\"\n\nl_int32 BBoxHDist(BOX *b1, BOX *b2) {\n  return L_MAX(b1->x, b2->x) - L_MIN(b1->x + b1->w, b2->x + b2->w);\n}\n\nl_int32 BBoxVDist(BOX *b1, BOX *b2) {\n  return L_MAX(b1->y, b2->y) - L_MIN(b1->y + b1->h, b2->y + b2->h);\n}\n\nl_float32 RelativeDiff(l_int32 v1, l_int32 v2) {\n  return L_ABS(v1 - v2) / (L_MIN(v1, v2) + 1.0);\n}\n\n#define OLDPAIR_MIN_HPAIR_RATIO 0.5\n#define OLDPAIR_MIN_WPAIR_RATIO 0.1\n#define OLDPAIR_MAX_HDIST_RATIO 3.0\n#define OLDPAIR_MAX_VDIST_RATIO 0.5\n\n/**\n * Test whether b1 and b2 are close enough to be a character pair.\n */\nbool ValidatePairOld(BOX *b1, BOX *b2) {\n  l_int32 max_w = L_MAX(b1->w, b2->w);\n  l_int32 centerx1 = b1->x + b1->w / 2;\n  l_int32 centerx2 = b2->x + b2->w / 2;\n  l_int32 h_dist = L_ABS(centerx1 - centerx2);\n\n  /* Horizontal distance between centers is\n   * less than twice the wider character */\n  if (h_dist > max_w * OLDPAIR_MAX_HDIST_RATIO)\n    return false;\n\n  l_int32 max_h = L_MAX(b1->h, b2->h);\n  l_int32 centery1 = b1->y + b1->h / 2;\n  l_int32 centery2 = b2->y + b2->h / 2;\n  l_int32 v_dist = L_ABS(centery1 - centery2);\n\n  /* Vertical distance between centers is\n   less than 50% of the taller character */\n  if (v_dist > max_h * OLDPAIR_MAX_VDIST_RATIO)\n    return false;\n\n  l_int32 min_h = L_MIN(b1->h, b2->h);\n  l_float32 h_ratio = min_h / (max_h + 1.0);\n\n  /* Height ratio is between 0.5 and 2 */\n  if (h_ratio < OLDPAIR_MIN_HPAIR_RATIO)\n    return false;\n\n  l_int32 min_w = L_MIN(b1->w, b2->w);\n  l_float32 w_ratio = min_w / (max_w + 1.0);\n\n  /* Width ratio is between 0.1 and 10 */\n  if (w_ratio < OLDPAIR_MIN_WPAIR_RATIO)\n    return false;\n\n  return true;\n}\n\nl_float32 ComputeFDR(PIX *cc8) {\n  l_float32 fdr;\n\n  pixGetFisherThresh(cc8, 0.0, &fdr, NULL);\n\n  return fdr;\n}\n\nl_float32 ComputeGradientEnergy(PIX *cc8, PIX *cc) {\n  l_float32 energy;\n\n  pixGradientEnergy(cc8, cc, &energy);\n\n  return energy;\n}\n\nl_float32 ComputeCCDensity(PIX *pix) {\n  l_int32 area = pix->w * pix->h;\n  l_int32 pixel_count;\n\n  pixCountPixels(pix, &pixel_count, NULL);\n\n  return pixel_count / (l_float32) area;\n}\n\nl_float32 ComputeCCEdgeMax(PIX *pix8) {\n  l_int32 max;\n  l_int32 avg;\n\n  pixEdgeMax(pix8, &max, &avg);\n\n  return (l_float32) max;\n}\n\nl_float32 ComputeSingletonConfidence(PIX *pix, BOX *box, PIX *pix8) {\n  l_float32 aspect_ratio = box->w / (l_float32) box->h;\n  l_float32 density = ComputeCCDensity(pix);\n  l_float32 gradient = ComputeGradientEnergy(pix8, pix);\n  l_float32 edgemax = ComputeCCEdgeMax(pix8);\n\n  /* Compute features for confidence */\n  l_float32 features[6];\n  features[0] = 1.0;\n  features[1] = aspect_ratio;\n  features[2] = aspect_ratio * aspect_ratio;\n  features[3] = gradient;\n  features[4] = aspect_ratio / density;\n  features[5] = edgemax;\n\n  l_float32 beta[6];\n  beta[0] = -3.099;\n  beta[1] = 1.244;\n  beta[2] = -0.1142;\n  beta[3] = 39.86;\n  beta[4] = -0.4005;\n  beta[5] = 0;\n\n  l_float32 confidence = 0.0;\n  for (int i = 0; i < 6; i++) {\n    confidence += features[i] * beta[i];\n  }\n\n  return confidence;\n}\n\nbool ValidateSingleton(PIX *pix, BOX *box, PIX *pix8, l_float32 *pconf,\n                       HydrogenTextDetector::TextDetectorParameters &params) {\n  l_float32 aspect_ratio = box->w / (l_float32) box->h;\n  l_float32 density = ComputeCCDensity(pix);\n\n  *pconf = 0.0;\n\n  /* Aspect ratio */\n  if (aspect_ratio > params.single_max_aspect)\n    return false;\n\n  if (aspect_ratio < params.single_min_aspect)\n    return false;\n\n  /* Pixel density */\n  if (density < params.single_min_density)\n    return false;\n\n  l_int32 area = box->w * box->h;\n\n  /* Area */\n  if (area < params.single_min_area)\n    return false;\n\n  *pconf = 1.0; //ComputeSingletonConfidence(pix, box, pix8);\n\n  return true;\n}\n\n/**\n * Test whether b1 and b2 are close enough to be a character pair.\n */\nbool ValidatePair(BOX *b1, BOX *b2, l_float32 *pconf,\n                  HydrogenTextDetector::TextDetectorParameters &params) {\n  *pconf = 0.0;\n\n  l_int32 max_h = L_MAX(b1->h, b2->h);\n  l_int32 h_dist = BBoxHDist(b1, b2);\n  l_int32 v_dist = BBoxVDist(b1, b2);\n  l_float32 h_ratio = RelativeDiff(b1->h, b2->h);\n  l_int32 d1 = L_MAX(b1->h, b1->w);\n  l_int32 d2 = L_MAX(b2->h, b2->w);\n  l_float32 d_ratio = RelativeDiff(d1, d2);\n\n  /* Horizontal spacing less than 2x taller edge */\n  if (h_dist > params.pair_h_dist_ratio * max_h)\n    return false;\n\n  /* Must share at least 0.25x the larger vertical edge */\n  if (v_dist > 0 || L_ABS(v_dist) < max_h * params.pair_h_shared)\n    return false;\n\n  /* Heights must be at least 2x tolerance */\n  if (h_ratio > params.pair_h_ratio)\n    return false;\n\n  /* Maximum dimensions must be within 3x tolerance */\n  if (d_ratio > params.pair_d_ratio)\n    return false;\n\n  // TODO(alanv): Does this need to return a confidence value?\n  *pconf = 1.0;\n\n  return true;\n}\n\nl_float32 ComputePairNormalizedOverlapArea(BOX *b1, BOX *b2) {\n  BOX *overlap = boxOverlapRegion(b1, b2);\n\n  if (!overlap || overlap->w == 0.0 || overlap->h == 0.0) return 0.0;\n\n  l_float32 area0 = overlap->w * overlap->h;\n  l_float32 area1 = b1->w * b1->h;\n  l_float32 area2 = b2->w * b2->h;\n  l_float32 oarea = 2.0 * area0 / (area1 + area2);\n\n  return oarea;\n}\n\nl_float32 ComputePairNormalizedBaselineDistance(BOX *b1, BOX *b2) {\n  l_float32 dy = (b1->y + b1->h) - (b2->y  + b2->h);\n  l_float32 vdist = 2.0 * L_ABS(dy) / (b1->h + b2->h);\n\n  return vdist;\n}\n\nl_float32 ComputePairNormalizedToplineDistance(BOX *b1, BOX *b2) {\n  l_float32 dy = b1->y - b2->y;\n  l_float32 vdist = 2.0 * L_ABS(dy) / (b1->h + b2->h);\n\n  return vdist;\n}\n\nl_float32 ComputePairNormalizedHorizontalDistance(BOX *b1, BOX *b2) {\n  l_float32 dx = (b1->x - b2->x) + (b1->w - b2->w) / 2.0;\n  l_float32 hdist = 2.0 * L_ABS(dx) / (b1->w + b2->w);\n\n  return hdist;\n}\n\nl_float32 ComputePairAreaRatio(BOX *b1, BOX *b2) {\n  l_float32 area1 = b1->w * b1->h;\n  l_float32 area2 = b2->w * b2->h;\n  l_float32 ratio = L_MIN(area1, area2) / L_MAX(area1, area2);\n\n  return ratio;\n}\n\nl_float32 ComputePairWidthRatio(BOX *b1, BOX *b2) {\n  l_float32 ratio = L_MIN(b1->w, b2->w) / L_MAX(b1->w, b2->w);\n\n  return ratio;\n}\n\nl_float32 ComputePairHeightRatio(BOX *b1, BOX *b2) {\n  l_float32 ratio = L_MIN(b1->h, b2->h) / L_MAX(b1->h, b2->h);\n\n  return ratio;\n}\n\nl_float32 ComputePairContainmentCheck(BOX *b1, BOX *b2) {\n  l_int32 contains1, contains2;\n\n  boxContains(b1, b2, &contains1);\n  boxContains(b2, b1, &contains2);\n\n  l_float32 contains = (l_float32) (contains1 || contains2);\n\n  return contains;\n}\n\nl_float32 ComputePairConfidence(BOX *b1, BOX *b2) {\n  l_float32 features[9];\n  features[0] = 1.0;\n  features[1] = ComputePairNormalizedOverlapArea(b1, b2);\n  features[2] = ComputePairNormalizedBaselineDistance(b1, b2);\n  features[3] = ComputePairNormalizedToplineDistance(b1, b2);\n  features[4] = ComputePairNormalizedHorizontalDistance(b1, b2);\n  features[5] = ComputePairAreaRatio(b1, b2);\n  features[6] = ComputePairWidthRatio(b1, b2);\n  features[7] = ComputePairHeightRatio(b1, b2);\n  features[8] = ComputePairContainmentCheck(b1, b2);\n\n  l_float32 beta[9];\n  beta[0] = 3.987;\n  beta[1] = -9.681;\n  beta[2] = -5.804;\n  beta[3] = -4.857;\n  beta[4] = -2.906;\n  beta[5] = -1.813;\n  beta[6] = 3.481;\n  beta[7] = 3.983;\n  beta[8] = -39.24;\n\n  l_float32 confidence = 0.0;\n  for (int i = 0; i < 5; i++) {\n    confidence += features[i] * beta[i];\n  }\n\n  return confidence;\n}\n\n/**\n * Test whether b1 and b2 are close enough to be clustered. More relaxed constraints than ValidatePair().\n */\nbool ValidateClusterPair(BOX *b1, BOX *b2, bool *too_far, l_float32 *pconf,\n                         HydrogenTextDetector::TextDetectorParameters &params) {\n  *pconf = 0.0;\n\n  l_int32 max_d = L_MAX(b1->w, b1->h);\n  l_float32 h_ratio = RelativeDiff(b1->h, b2->h);\n\n  // If we're already too far out, quit\n  if (b2->x > b1->x + b1->w + params.cluster_width_spacing * max_d) {\n    *too_far = true;\n\n    return false;\n  }\n\n  *too_far = false;\n\n  // Must share at least 0.25x the larger vertical edge\n  //l_int32 v_dist = BBoxVDist(b1, b2);\n  //if (v_dist > 0 || L_ABS(v_dist) < L_MIN(min_h, max_h) * PAIR_H_SHARED)\n  //  return false;\n\n  // i and j must share at least half an edge\n  if (b2->y + b2->h * params.cluster_shared_edge < b1->y)\n    return false;\n  if (b1->y + b1->h * params.cluster_shared_edge < b2->y)\n    return false;\n\n  // Heights must be at least 2x tolerance\n  if (h_ratio > params.pair_h_ratio)\n    return false;\n\n  *pconf = 1.0; //ComputePairConfidence(b1, b2);\n\n  return true;\n}\n\n/**\n * Test whether a finalized cluster is valid.\n */\nbool ValidateCluster(PIX *pix8, PIXA *pixa, BOX *box, l_float32 *pconf,\n                     HydrogenTextDetector::TextDetectorParameters &params) {\n  *pconf = 0.0;\n\n  l_float32 aspect = box->w / (l_float32) box->h;\n  l_int32 count = pixaGetCount(pixa);\n  l_float32 fdr = ComputeFDR(pix8);\n\n  if (box->h < 15)\n    return false;\n\n  if (aspect < params.cluster_min_aspect)\n    return false;\n\n  if (count < params.cluster_min_blobs)\n    return false;\n\n  if (fdr < params.cluster_min_fdr)\n    return false;\n/*\n  l_int32 edge_max, edge_avg;\n  pixEdgeMax(pix8, &edge_max, &edge_avg);\n\n  if (edge_max < params.cluster_min_edge || edge_avg < params.cluster_min_edge_avg)\n    return false;\n*/\n  // TODO(alanv): Combine all of these into a confidence score, higher = better\n  *pconf = log(fdr); //log(fdr * edge_max * edge_avg);\n\n  return true;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/hydrogen/src/validator.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef HYDROGEN_VALIDATOR_H_\n#define HYDROGEN_VALIDATOR_H_\n\n#include \"leptonica.h\"\n#include \"hydrogentextdetector.h\"\n\nbool ValidatePairOld(BOX *b1, BOX *b2);\n\nbool ValidateSingleton(PIX *pix, BOX *box, PIX *pix8, l_float32 *pconf,\n                       HydrogenTextDetector::TextDetectorParameters &params);\n\nbool ValidatePair(BOX *b1, BOX *b2, l_float32 *pconf,\n                  HydrogenTextDetector::TextDetectorParameters &params);\n\nbool ValidateClusterPair(BOX *b1, BOX *b2, bool *too_far, l_float32 *pconf,\n                         HydrogenTextDetector::TextDetectorParameters &params);\n\nbool ValidateCluster(PIX *pix8, PIXA *pixa, BOX *box, l_float32 *pconf,\n                     HydrogenTextDetector::TextDetectorParameters &params);\n\n#endif /* HYDROGEN_VALIDATOR_H_ */\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/Android.mk",
    "content": "LOCAL_PATH:= $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_MODULE := imageutils$(LIB_SUFFIX)\nLOCAL_SRC_FILES := blur-jni.cpp \\\n\t\t               similar-jni.cpp \\\n                   blur.cpp \\\n\t\t               similar.cpp\n\nifeq ($(TARGET_ARCH_ABI),armeabi-v7a)\n  LOCAL_CFLAGS += -DHAVE_ARMEABI_V7A=1 -mfloat-abi=softfp -mfpu=neon\n  LOCAL_C_INCLUDES += $(NDK_ROOT)/sources/android/cpufeatures\n  LOCAL_STATIC_LIBRARIES += cpufeatures\nendif\n\nLOCAL_C_INCLUDES += $(LOCAL_PATH)/../common\n\nLOCAL_STATIC_LIBRARIES += common\n\ninclude $(BUILD_SHARED_LIBRARY)\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/blur-jni.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Xiaotao Duan\n\n#include <jni.h>\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"types.h\"\n#include \"time_log.h\"\n#include \"blur.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nJNIEXPORT jboolean JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_isBlurred(\n    JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height);\n\n#ifdef __cplusplus\n}\n#endif\n\nJNIEXPORT jboolean JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_isBlurred(\n    JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height) {\n  jboolean inputCopy = JNI_FALSE;\n  jbyte* const i = env->GetByteArrayElements(input, &inputCopy);\n\n  float blur = 0;\n  float extent = 0;\n\n  resetTimeLog();\n  int blurred = IsBlurred(reinterpret_cast<uint8*>(i),\n                          width, height, &blur, &extent);\n  timeLog(\"Finished image blur detection\");\n  printTimeLog();\n\n  env->ReleaseByteArrayElements(input, i, JNI_ABORT);\n\n  return blurred ? JNI_TRUE : JNI_FALSE;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/blur.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Xiaotao Duan\n//\n// This library contains image processing method to detect\n// image blurriness.\n//\n// This library is *not* thread safe because static memory is\n// used for performance.\n//\n// A method to detect whether a given image is blurred or not.\n// The algorithm is based on H. Tong, M. Li, H. Zhang, J. He,\n// and C. Zhang. \"Blur detection for digital images using wavelet\n// transform\".\n//\n// To achieve better performance on client side, the method\n// is running on four 128x128 portions which compose the 256x256\n// central area of the given image. On Nexus One, average time\n// to process a single image is ~5 milliseconds.\n\n#include <math.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include \"blur.h\"\n#include \"utils.h\"\n\nstatic const int kDecomposition = 3;\nstatic const int kThreshold = 35;\nstatic const float kMinZero = 0.05;\n\nstatic const int kMaximumWidth = 256;\nstatic const int kMaximumHeight = 256;\n\nstatic int32 _smatrix[kMaximumWidth * kMaximumHeight];\nstatic int32 _arow[kMaximumWidth > kMaximumHeight ?\n    kMaximumWidth : kMaximumHeight];\n\n// Does Haar Wavelet Transformation in place on a given row of a matrix.\n// The matrix is in size of matrix_height * matrix_width and represented\n// in a linear array. Parameter offset_row indicates transformation is\n// performed on which row. offset_column and num_columns indicate column\n// range of the given row.\ninline void Haar1DX(int* matrix, int matrix_height, int matrix_width,\n    int offset_row, int offset_column, int num_columns) {\n  int32* ptr_a = _arow;\n  int32* ptr_matrix = matrix + offset_row * matrix_width + offset_column;\n  int half_num_columns = num_columns / 2;\n\n  int32* a_tmp = ptr_a;\n  int32* matrix_tmp = ptr_matrix;\n  for (int j = 0; j < half_num_columns; ++j) {\n    *a_tmp++ = (matrix_tmp[0] + matrix_tmp[1]) / 2;\n    matrix_tmp += 2;\n  }\n\n  int32* average = ptr_a;\n  a_tmp = ptr_a + half_num_columns;\n  matrix_tmp = ptr_matrix;\n  for (int j = 0; j < half_num_columns; ++j) {\n    *a_tmp++ = *matrix_tmp - *average++;\n    matrix_tmp += 2;\n  }\n\n  memcpy(ptr_matrix, ptr_a, sizeof(int32) * num_columns);\n}\n\n// Does Haar Wavelet Transformation in place on a given column of a matrix.\ninline void Haar1DY(int* matrix, int matrix_height, int matrix_width,\n    int offset_column, int offset_row, int num_rows) {\n  int32* ptr_a = _arow;\n  int32* ptr_matrix = matrix + offset_row * matrix_width + offset_column;\n  int half_num_rows = num_rows / 2;\n  int two_line_width = matrix_width * 2;\n\n  int32* a_tmp = ptr_a;\n  int32* matrix_tmp = ptr_matrix;\n  for (int j = 0; j < half_num_rows; ++j) {\n    *a_tmp++ = (matrix_tmp[matrix_width] + matrix_tmp[0]) / 2;\n    matrix_tmp += two_line_width;\n  }\n\n  int32* average = ptr_a;\n  a_tmp = ptr_a + half_num_rows;\n  matrix_tmp = ptr_matrix;\n  for (int j = 0; j < num_rows; j += 2) {\n    *a_tmp++ = *matrix_tmp - *average++;\n    matrix_tmp += two_line_width;\n  }\n\n  for (int j = 0; j < num_rows; ++j) {\n    *ptr_matrix = *ptr_a++;\n    ptr_matrix += matrix_width;\n  }\n}\n\n// Does Haar Wavelet Transformation in place for a specified area of\n// a matrix. The matrix size is specified by matrix_width and matrix_height.\n// The area on which the transformation is performed is specified by\n// offset_column, num_columns, offset_row and num_rows.\nvoid Haar2D(int* matrix, int matrix_height, int matrix_width,\n    int offset_column, int num_columns, int offset_row, int num_rows) {\n  for (int i = offset_row; i < offset_row + num_rows; ++i) {\n    Haar1DX(matrix, matrix_height, matrix_width, i, offset_column, num_columns);\n  }\n\n  for (int i = offset_column; i < offset_column + num_columns; ++i){\n    Haar1DY(matrix, matrix_height, matrix_width, i, offset_row, num_rows);\n  }\n}\n\n// Reads in a given matrix, does first round HWT and outputs result\n// matrix into target array. This function is used for optimization by\n// avoiding a memory copy. The input matrix has height rows and width\n// columns. The transformation is performed on the given area specified\n// by offset_column, num_columns, offset_row, num_rows. After\n// transformation, the output matrix has num_columns columns and\n// num_rows rows.\nvoid HwtFirstRound(const uint8* const data, int height, int width,\n    int offset_column, int num_columns,\n    int offset_row, int num_rows, int32* matrix) {\n  int32* ptr_a = _arow;\n  const uint8* ptr_data = data + offset_row * width + offset_column;\n  int half_num_columns = num_columns / 2;\n  for (int i = 0; i < num_rows; ++i) {\n    int32* a_tmp = ptr_a;\n    const uint8* data_tmp = ptr_data;\n    for (int j = 0; j < half_num_columns; ++j) {\n      *a_tmp++ = (int32) ((data_tmp[0] + data_tmp[1]) / 2);\n      data_tmp += 2;\n    }\n\n    int32* average = ptr_a;\n    a_tmp = ptr_a + half_num_columns;\n    data_tmp = ptr_data;\n    for (int j = 0; j < half_num_columns; ++j) {\n      *a_tmp++ = *data_tmp - *average++;\n      data_tmp += 2;\n    }\n\n    int32* ptr_matrix = matrix + i * num_columns;\n    a_tmp = ptr_a;\n    for (int j = 0; j < num_columns; ++j) {\n      *ptr_matrix++ = *a_tmp++;\n    }\n\n    ptr_data += width;\n  }\n\n  // Column transformation does not involve input data.\n  for (int i = 0; i < num_columns; ++i) {\n    Haar1DY(matrix, num_rows, num_columns, i, 0, num_rows);\n  }\n}\n\n// Returns the weight of a given point in a certain scale of a matrix\n// after wavelet transformation.\n// The point is specified by k and l which are y and x coordinate\n// respectively. Parameter scale tells in which scale the weight is\n// computed, must be 1, 2 or 3 which stands respectively for 1/2, 1/4\n// and 1/8 of original size.\nint ComputeEdgePointWeight(int* matrix, int width, int height,\n    int k, int l, int scale) {\n  int r = k >> scale;\n  int c = l >> scale;\n  int window_row = height >> scale;\n  int window_column = width >> scale;\n\n  int v_top_right = square(matrix[r * width + c + window_column]);\n  int v_bot_left = square(matrix[(r + window_row) * width + c]);\n  int v_bot_right =\n      square(matrix[(r + window_row) * width + c + window_column]);\n\n  int v = sqrt(v_top_right + v_bot_left + v_bot_right);\n  return v;\n}\n\n// Computes point with maximum weight for a given local window for a\n// given scale.\n// Parameter scaled_width and scaled_height define scaled image size\n// of a certain decomposition level. The window size is defined by\n// window_size. Output value k and l store row (y coordinate) and\n// column (x coordinate) respectively of the point with maximum weight.\n// The maximum weight is returned.\nint ComputeLocalMaximum(int* matrix, int width, int height,\n    int scaled_width, int scaled_height,\n    int top, int left, int window_size, int* k, int* l) {\n  int max = -1;\n  *k = top;\n  *l = left;\n\n  for (int i = 0; i < window_size; ++i) {\n    for (int j = 0; j < window_size; ++j) {\n      int r = top + i;\n      int c = left + j;\n\n      int v_top_right = abs(matrix[r * width + c + scaled_width]);\n      int v_bot_left = abs(matrix[(r + scaled_height) * width + c]);\n      int v_bot_right =\n          abs(matrix[(r + scaled_height) * width + c + scaled_width]);\n      int v = v_top_right + v_bot_left + v_bot_right;\n\n      if (v > max) {\n        max = v;\n        *k = r;\n        *l = c;\n      }\n    }\n  }\n\n  int r = *k;\n  int c = *l;\n  int v_top_right = square(matrix[r * width + c + scaled_width]);\n  int v_bot_left = square(matrix[(r + scaled_height) * width + c]);\n  int v_bot_right =\n      square(matrix[(r + scaled_height) * width + c + scaled_width]);\n  int v = sqrt(v_top_right + v_bot_left + v_bot_right);\n\n  return v;\n}\n\n// Detects blurriness of a transformed matrix.\n// Blur confidence and extent will be returned through blur_conf\n// and blur_extent. 1 is returned while input matrix is blurred.\nint DetectBlur(int* matrix, int width, int height,\n    float* blur_conf, float* blur_extent) {\n  int nedge = 0;\n  int nda = 0;\n  int nrg = 0;\n  int nbrg = 0;\n\n  // For each scale\n  for (int current_scale = kDecomposition; current_scale > 0; --current_scale) {\n    int scaled_width = width >> current_scale;\n    int scaled_height = height >> current_scale;\n    int window_size = 16 >> current_scale;  // 2, 4, 8\n    // For each window\n    for (int r = 0; r + window_size < scaled_height; r += window_size) {\n      for (int c = 0; c + window_size < scaled_width; c += window_size) {\n        int k, l;\n        int emax = ComputeLocalMaximum(matrix, width, height,\n            scaled_width, scaled_height, r, c, window_size, &k, &l);\n        if (emax > kThreshold) {\n          int emax1, emax2, emax3;\n          switch (current_scale) {\n            case 1:\n              emax1 = emax;\n              emax2 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 2);\n              emax3 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 3);\n              break;\n            case 2:\n              emax1 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 1);\n              emax2 = emax;\n              emax3 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 3);\n              break;\n            case 3:\n              emax1 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 1);\n              emax2 = ComputeEdgePointWeight(matrix, width, height,\n                  k << current_scale, l << current_scale, 2);\n              emax3 = emax;\n              break;\n          }\n\n          nedge++;\n          if (emax1 > emax2 && emax2 > emax3) {\n            nda++;\n          }\n          if (emax1 < emax2 && emax2 < emax3) {\n            nrg++;\n            if (emax1 < kThreshold) {\n              nbrg++;\n            }\n          }\n          if (emax2 > emax1 && emax2 > emax3) {\n            nrg++;\n            if (emax1 < kThreshold) {\n              nbrg++;\n            }\n          }\n        }\n      }\n    }\n  }\n\n  // TODO(xiaotao): No edge point at all, blurred or not?\n  float per = nedge == 0 ? 0 : (float)nda / nedge;\n\n  *blur_conf = per;\n  *blur_extent = (float)nbrg / nrg;\n\n  return per < kMinZero;\n}\n\n// Detects blurriness of a given portion of a luminance matrix.\nint IsBlurredInner(const uint8* const luminance,\n    const int width, const int height,\n    const int left, const int top,\n    const int width_wanted, const int height_wanted,\n    float* const blur, float* const extent) {\n  int32* matrix = _smatrix;\n\n  HwtFirstRound(luminance, height, width,\n                left, width_wanted, top, height_wanted, matrix);\n  Haar2D(matrix, height_wanted, width_wanted,\n         0, width_wanted >> 1, 0, height_wanted >> 1);\n  Haar2D(matrix, height_wanted, width_wanted,\n         0, width_wanted >> 2, 0, height_wanted >> 2);\n\n  int blurred = DetectBlur(matrix, width_wanted, height_wanted, blur, extent);\n\n  return blurred;\n}\n\nint IsBlurred(const uint8* const luminance,\n    const int width, const int height, float* const blur, float* const extent) {\n\n  int desired_width = min(kMaximumWidth, width);\n  int desired_height = min(kMaximumHeight, height);\n  int left = (width - desired_width) >> 1;\n  int top = (height - desired_height) >> 1;\n\n  float conf1, extent1;\n  int blur1 = IsBlurredInner(luminance, width, height,\n      left, top, desired_width >> 1, desired_height >> 1, &conf1, &extent1);\n  float conf2, extent2;\n  int blur2 = IsBlurredInner(luminance, width, height,\n      left + (desired_width >> 1), top, desired_width >> 1, desired_height >> 1,\n      &conf2, &extent2);\n  float conf3, extent3;\n  int blur3 = IsBlurredInner(luminance, width, height,\n      left, top + (desired_height >> 1), desired_width >> 1,\n      desired_height >> 1, &conf3, &extent3);\n  float conf4, extent4;\n  int blur4 = IsBlurredInner(luminance, width, height,\n      left + (desired_width >> 1), top + (desired_height >> 1),\n      desired_width >> 1, desired_height >> 1, &conf4, &extent4);\n\n  *blur = (conf1 + conf2 + conf3 + conf4) / 4;\n  *extent = (extent1 + extent2 + extent3 + extent4) / 4;\n  return *blur < kMinZero;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/blur.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: xiaotao@google.com (Xiaotao Duan)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_BLUR_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_BLUR_H_\n\n#include \"types.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// Detects whether a given luminance matrix is blurred or not.\n// The input matrix size if width * height. 1 is returned when\n// input image is blurred along with blur confidence and extent\n// returned through output value blur and extent.\nint IsBlurred(const uint8* const luminance, const int width, const int height,\n              float* const blur, float* const extent);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_BLUR_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/similar-jni.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Xiaotao Duan\n\n#include <jni.h>\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"types.h\"\n#include \"time_log.h\"\n#include \"similar.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\nJNIEXPORT jintArray JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_computeSignature(\n    JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height,\n    jintArray signatureBuffer);\n\nJNIEXPORT jint JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_diffSignature(\n    JNIEnv* env, jclass clazz, jintArray signature1, jintArray signature2);\n#ifdef __cplusplus\n}\n#endif\n\nJNIEXPORT jintArray JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_computeSignature(\n    JNIEnv* env, jclass clazz, jbyteArray input, jint width, jint height,\n    jintArray signatureBuffer) {\n  jboolean inputCopy = JNI_FALSE;\n  jbyte* const i = env->GetByteArrayElements(input, &inputCopy);\n\n  int sig_len = 0;\n\n  resetTimeLog();\n  uint32_t* sig = ComputeSignature(reinterpret_cast<uint8*>(i),\n      width, height, &sig_len);\n  timeLog(\"Finished image signature computation\");\n  printTimeLog();\n\n  env->ReleaseByteArrayElements(input, i, JNI_ABORT);\n\n  jintArray ret = signatureBuffer;\n  if (ret == NULL || env->GetArrayLength(ret) != sig_len) {\n    ret = env->NewIntArray(sig_len);\n  }\n  jint* body = env->GetIntArrayElements(ret, 0);\n  for (int i = 0; i < sig_len; ++i) {\n    body[i] = sig[i];\n  }\n  env->ReleaseIntArrayElements(ret, body, 0);\n  return ret;\n}\n\nJNIEXPORT jint JNICALL\nJava_com_googlecode_eyesfree_opticflow_ImageBlur_diffSignature(\n    JNIEnv* env, jclass clazz, jintArray signature1, jintArray signature2) {\n  jint* sig1 = env->GetIntArrayElements(signature1, 0);\n  jint* sig2 = env->GetIntArrayElements(signature2, 0);\n\n  int size = env->GetArrayLength(signature1);\n\n  int diff = Diff(sig1, sig2, size);\n\n  env->ReleaseIntArrayElements(signature1, sig1, 0);\n  env->ReleaseIntArrayElements(signature2, sig2, 0);\n\n  return diff;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/similar.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Xiaotao Duan\n//\n// This library contains image processing method to estimate\n// similarity of two given images.\n//\n// This library is *not* thread safe because static memory is\n// used for performance.\n//\n// Two methods are provided to estimate the similarity of two\n// given images. ComputeSignature() is used to compute the\n// signature of a given image. Diff() takes two signatures\n// as input to compute how similar two given images are.\n// The algorithm is based on R. O. Stehling, M. A. Nascimento,\n// and A. X. Falc ̃ao. \"A Compact and Efficient Image Retrieval\n// Approach Based on Border/Interior Pixel Classification\".\n//\n// For performance consideration, 480x480 of central area of\n// a given image is used for signature computation.\n#include <string.h>\n\n#include \"similar.h\"\n#include \"utils.h\"\n\n// How many quantized colors using to compute signature.\n// For performance consideration, it's specified in format of\n// number of left shift bits rather than color numbers directly.\n// e.g. kShiftColors 4 means (1 << 4 == 16) colors are used.\nstatic const int kShiftColors = 4;\nstatic const int kDesiredWidthForSignature = 480;\nstatic const int kDesiredHeightForSignature = 480;\nstatic uint8 _colors[kDesiredHeightForSignature * kDesiredWidthForSignature];\n// The final signature contains both color information of\n// inner and outer pixels, and total pixel count at last.\nstatic uint32_t _signature[1 + (1 << kShiftColors) * 2];\n\nuint32_t* ComputeSignatureInner(const uint8* const luminance,\n    int width, int height,\n    int left, int top, int desired_width, int desired_height, int* size) {\n  int num_colors = 1 << kShiftColors;\n\n  memset(_signature, 0, sizeof(int32) * num_colors * 2);\n\n  // Build quantized color map for input image. For each possible lumiance\n  // value from 0 to 255, quantize it into more coarse value.\n#ifdef HAVE_ARMEABI_V7A\n  if (supportsNeon()) {\n    for (int i = 0; i < desired_height; ++i) {\n      uint8* ptr_colors = _colors + i * desired_width;\n      const uint8* ptr_lumi = luminance + (i + top) * width + left;\n      int itrs = desired_width / 8;\n      for (int j = 0; j < itrs; ++j) {\n        // Load 8 bytes from ptr_lumi into neon vector\n        uint8x8_t lumix8 = vld1_u8(ptr_lumi);\n        // Batch right shift every elements (8 - kShiftColors) bits\n        // in the vector\n        uint8x8_t colorx8 = vshr_n_u8(lumix8, 8 - kShiftColors);\n        // Store above result into our own memory starting from ptr_colors\n        vst1_u8(ptr_colors, colorx8);\n\n        ptr_lumi += 8;\n        ptr_colors += 8;\n      }\n    }\n  } else {\n#endif\n    int shift_bits = 8 - kShiftColors;  // equals to 256/num_colors\n    for (int i = 0; i < desired_height; ++i) {\n      uint8* ptr_colors = &_colors[i * desired_width];\n      const uint8* ptr_lumi = luminance + (i + top) * width + left;\n      for (int j = 0; j < desired_width; ++j) {\n        *ptr_colors++ = *ptr_lumi++ >> shift_bits;\n      }\n    }\n#ifdef HAVE_ARMEABI_V7A\n  }\n#endif\n\n  // Go through each pixel, decide it is a inner pixel (having same\n  // quantized color as its 4 neighbours) or an outer one (at least one of\n  // his 4 neighbours has different color), update signature respectively.\n  int h = desired_height - 1;\n  int w = desired_width - 1;\n  for (int i = 1; i < h; ++i) {\n    uint8* ptr_colors = _colors + i * desired_width;\n    for (int j = 1; j < w; ++j) {\n      int inner = 0;\n      uint8 y = ptr_colors[j];\n      uint8 yleft = ptr_colors[j - 1];\n      if (y == yleft) {\n        uint8 yright = ptr_colors[j + 1];\n        if (y == yright) {\n          uint8 yup = ptr_colors[j - desired_width];\n          if (y == yup) {\n            uint8 ydown = ptr_colors[j + desired_width];\n            if (y == ydown) {\n              inner = 1;\n            }\n          }\n        }\n      }\n      _signature[inner * num_colors + y] += 1;\n    }\n  }\n\n  *size = sizeof(_signature) / sizeof(uint32);\n  _signature[*size - 1] = (desired_height - 2) * (desired_width - 2);\n\n  return _signature;\n}\n\nuint32_t* ComputeSignature(const uint8* const luminance,\n    const int width, const int height, int* size) {\n  int desired_width = min(kDesiredWidthForSignature, width);\n  int desired_height = min(kDesiredHeightForSignature, height);\n  int left = (width - desired_width) >> 1;\n  int top = (height - desired_height) >> 1;\n\n  return ComputeSignatureInner(luminance, width, height,\n      left, top, desired_width, desired_height, size);\n}\n\nint Diff(const int32* const signature1, const int32* const signature2,\n    const int size) {\n  int total = signature1[size - 1];\n  int diff = 0;\n  for (int i = 0; i < size; ++i) {\n    diff += abs(signature1[i] - signature2[i]);\n  }\n  return diff * 50 / total;\n}\n"
  },
  {
    "path": "eyes-two/src/main/jni/imageutils/similar.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: xiaotao@google.com (Xiaotao Duan)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_SIMILAR_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_SIMILAR_H_\n\n#include \"types.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n// Computes signature of a given image. This signature can be used to\n// compute similarity of two different images. Signature is returned\n// and size is returned via output parameter size.\nuint32* ComputeSignature(const uint8* const luminance,\n                         const int width, const int height, int* size);\n\n// Returns how different two given images (represented by their signatures)\n// are. The input signatures must be in the same size. An integer from 0 to\n// 100 is returned to indicate difference percentage of signature2\n// comparing against signature1.\nint Diff(const int32* const signature1, const int32* const signature2,\n         const int size);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_IMAGEUTILS_SIMILAR_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/Android.mk",
    "content": "LOCAL_PATH:= $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_MODULE := libopticalflow\nLOCAL_MODULE_TAGS := optional\n\nLOCAL_CFLAGS := -Wall \\\n                -DHAVE_MALLOC_H \\\n                -DHAVE_PTHREAD \\\n                -finline-functions \\\n                -frename-registers \\\n                -ffast-math \\\n                -s \\\n                -fomit-frame-pointer\n\nLOCAL_SRC_FILES := optical_flow-jni.cpp \\\n                   optical_flow.cpp \\\n                   feature_detector.cpp\n\nLOCAL_C_INCLUDES += $(LOCAL_PATH)/../common\n\nifeq ($(LOG_TIME),true)\n  LOCAL_CFLAGS += -DLOG_TIME\nendif\n\nifeq ($(SANITY_CHECKS),true)\n  LOCAL_CFLAGS += -DSANITY_CHECKS\nendif\n\nifeq ($(VERBOSE_LOGGING),true)\n  LOCAL_CFLAGS += -DVERBOSE_LOGGING\nendif\n\nifeq ($(TARGET_ARCH_ABI),armeabi-v7a)\n    LOCAL_CFLAGS += -DHAVE_ARMEABI_V7A=1 -mfloat-abi=softfp -mfpu=neon\n    LOCAL_C_INCLUDES += $(NDK_ROOT)/sources/android/cpufeatures\n    LOCAL_STATIC_LIBRARIES += cpufeatures\nendif\n\nLOCAL_LDLIBS := -llog\n\nLOCAL_STATIC_LIBRARIES += common\n\ninclude $(BUILD_SHARED_LIBRARY)\n\n\ninclude $(NDK_ROOT)/sources/android/cpufeatures/Android.mk\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/feature_detector.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Andrew Harp\n//\n// Various feature detecting functions.\n\n#include <float.h>\n#include <string.h>\n\n#include \"utils.h\"\n#include \"time_log.h\"\n\n#include \"image.h\"\n#include \"feature_detector.h\"\n\n// Threshold for pixels to be considered different.\n#define FAST_DIFF_AMOUNT 10\n\n// How far from edge of frame to stop looking for FAST features.\n#define FAST_BORDER_BUFFER 20\n\n// Minimum enforced distance between detected features.\n// Default\n#define MIN_FEATURE_DIST_NORMAL 24\n\n// Regions selected as \"interesting\" (aka have annotations) can have denser\n// feature coverage.\n#define MIN_FEATURE_DIST_INTEREST 12\n\n// How many FAST qualifying pixels must be connected to a pixel for it to be\n// considered a candidate feature for Harris filtering.\n#define MIN_NUM_CONNECTED 8\n\n// Size of the window to integrate over for Harris filtering.\n// Compare to WINDOW_SIZE in optical_flow.h.\n#define HARRIS_WINDOW_SIZE 2\n\n// Arbitrary parameter for how picky Harris filter is, the higher the more\n// discriminating.\n#define SENSITIVITY 0.2f\n\nnamespace flow {\n\nvoid scoreFeatures(const Image<int32>& I_x, const Image<int32>& I_y,\n                   const int32 num_candidates,\n                   Point2D* const candidate_features) {\n  // Score all the features\n  for (int32 i = 0; i < num_candidates; ++i) {\n    Point2D* const feature = candidate_features + i;\n    feature->score = harrisFilter(I_x, I_y, feature->x, feature->y);\n  }\n}\n\n// Quicksorts detected features by score and then selects them such that\n// they are separated by a minimum distance.\nint32 sortAndSelect(const int32 num_candidates, const int32 max_features,\n                    const Image<bool>& interest_map,\n                    Point2D* const candidate_features,\n                    Point2D* const final_features,\n                    Image<uint8>* const best_feature_map) {\n  qsort(candidate_features, num_candidates);\n\n#ifdef SANITY_CHECKS\n  // Verify that the array got sorted.\n  float32 last_score = -FLT_MAX;\n  for (int32 i = 0; i < num_candidates; ++i) {\n    const float32 curr_score = (candidate_features + i)->score;\n\n    // Scores should be monotonically increasing.\n    CHECK(last_score <= curr_score,\n          \"Quicksort failure! %d: %.5f > %d: %.5f\",\n          i - 1, last_score, i, curr_score);\n\n    last_score = curr_score;\n  }\n#endif\n\n  best_feature_map->clear(false);\n\n  int32 num_features = 0;\n\n  for (int32 i = num_candidates - 1; i >= 0; --i) {\n    const Point2D& candidate = candidate_features[i];\n\n    // Since features are sorted, the first 0 or less value means we can stop\n    // looking.\n    if (candidate.score <= 0.0f) {\n      break;\n    }\n\n    // Lookup whether this feature is in an interest region.  If so, other\n    // features may appear closer to it than normal.\n    const int32 distance = interest_map.getPixel(candidate.x, candidate.y) ?\n        MIN_FEATURE_DIST_INTEREST : MIN_FEATURE_DIST_NORMAL;\n\n    if (markImage(candidate.x, candidate.y, distance, best_feature_map)) {\n      final_features[num_features] = candidate;\n      num_features++;\n\n      if (num_features >= max_features) {\n        break;\n      }\n    }\n  }\n\n  return num_features;\n}\n\n// Walks along the given circle checking for pixels above or below the center.\n// Returns a score, or 0 if the feature did not pass the criteria.\n//\n// Parameters:\n//  circle_perimeter: the circumference in pixels of the circle.\n//  threshold: the minimum number of contiguous pixels that must be above or\n//             below the center value.\n//  center_ptr: the location of the center pixel in memory\n//  offsets: the relative offsets from the center pixel of the edge pixels.\ninline int32 testCircle(const int32 circle_perimeter, const int32 threshold,\n                        const uint8* const center_ptr,\n                        const int32* offsets) {\n  // Get the actual value of the center pixel for easier reference later on.\n  const int32 center_value = static_cast<int32>(*center_ptr);\n\n  // Number of total pixels to check.  Have to wrap around some in case\n  // the contiguous section is split by the array edges.\n  const int32 num_total = circle_perimeter + threshold - 1;\n\n  int32 num_above = 0;\n  int32 above_diff = 0;\n\n  int32 num_below = 0;\n  int32 below_diff = 0;\n\n  // Used to tell when this is definitely not going to meet the threshold so we\n  // can early abort.\n  int32 minimum_by_now = threshold - num_total + 1;\n\n  // Go through every pixel along the perimeter of the circle, and then around\n  // again a little bit.\n  for (int32 i = 0; i < num_total; ++i) {\n    // This should be faster than mod.\n    const int32 perim_index = i < circle_perimeter ? i : i - circle_perimeter;\n\n    // This gets the value of the current pixel along the perimeter by using\n    // a precomputed offset.\n    const int32 curr_value =\n        static_cast<int32>(center_ptr[offsets[perim_index]]);\n\n    const int32 difference = curr_value - center_value;\n\n    if (difference > FAST_DIFF_AMOUNT) {\n      above_diff += difference;\n      ++num_above;\n\n      num_below = 0;\n      below_diff = 0;\n\n      if (num_above >= threshold) {\n        return above_diff;\n      }\n    } else if (difference < -FAST_DIFF_AMOUNT) {\n      below_diff += difference;\n      ++num_below;\n\n      num_above = 0;\n      above_diff = 0;\n\n      if (num_below >= threshold) {\n        return below_diff;\n      }\n    } else {\n      num_above = 0;\n      num_below = 0;\n      above_diff = 0;\n      below_diff = 0;\n    }\n\n    // See if there's any chance of making the threshold.\n    if (max(num_above, num_below) < minimum_by_now) {\n      // Didn't pass.\n      return 0;\n    }\n    ++minimum_by_now;\n  }\n\n  // Didn't pass.\n  return 0;\n}\n\n// Creates features in a regular grid, regardless of image contents.\nint32 seedFeatures(const Image<uint8>& frame,\n                   const int32 num_x, const int32 num_y,\n                   const float32 left, const float32 top,\n                   const float32 right, const float32 bottom,\n                   const int32 type, Point2D* const features) {\n  int32 num_features = 0;\n\n  const float32 step_x = ((right - left) / (num_x - 1));\n  const float32 step_y = ((bottom - top) / (num_y - 1));\n\n  for (int32 x = 0; x < num_x; ++x) {\n    for (int32 y = 0; y < num_y; ++y) {\n      const int32 x_pos = x * step_x + left;\n      const int32 y_pos = y * step_y + top;\n      if (inRange(x_pos, 0, frame.width_less_one_) &&\n          inRange(y_pos, 0, frame.height_less_one_)) {\n        Point2D* const feature = features + num_features;\n        feature->x = x_pos;\n        feature->y = y_pos;\n        feature->type = type;\n\n        ++num_features;\n      }\n    }\n  }\n\n  return num_features;\n}\n\n\n// Returns how likely a point in the image is to be a corner.\nfloat32 harrisFilter(const Image<int32>& I_x, const Image<int32>& I_y,\n                     const int32 x, const int32 y) {\n  // Image gradient matrix.\n  float32 G[] = { 0, 0, 0, 0 };\n  calculateG(HARRIS_WINDOW_SIZE, x, y, I_x, I_y, G);\n\n  const float32 g_sum = G[0] + G[1] + G[2] + G[3];\n\n  const float32 a = G[0] / g_sum;\n  const float32 b = G[1] / g_sum;\n  const float32 c = G[2] / g_sum;\n  const float32 d = G[3] / g_sum;\n\n  const float32 det = a * d - b * c;\n  const float32 trace = a + d;\n\n  const float32 inner = square(trace) - 4 * det;\n\n  if (inner >= 0.0f) {\n    const float32 square_root_inner = sqrtf(inner);\n    const float32 eig1 = (trace + square_root_inner) / 2.0f;\n    const float32 eig2 = (trace - square_root_inner) / 2.0f;\n    return eig1 * eig2 - SENSITIVITY * square(eig1 + eig2);\n  }\n\n  // Way negative.\n  return -100.0f;\n}\n\n// FAST feature detector.\nint32 findFastFeatures(const Image<uint8>& frame, const int32 max_num_features,\n                       Point2D* const features,\n                       Image<uint8>* const best_feature_map) {\n  /*\n   // Reference for a circle of diameter 7.\n   const int32 circle[] = {0, 0, 1, 1, 1, 0, 0,\n                           0, 1, 0, 0, 0, 1, 0,\n                           1, 0, 0, 0, 0, 0, 1,\n                           1, 0, 0, 0, 0, 0, 1,\n                           1, 0, 0, 0, 0, 0, 1,\n                           0, 1, 0, 0, 0, 1, 0,\n                           0, 0, 1, 1, 1, 0, 0};\n   const int32 circle_offset[] =\n       {2, 3, 4, 8, 12, 14, 20, 21, 27, 28, 34, 36, 40, 44, 45, 46};\n   */\n\n  // Quick test of compass directions.  Any length 16 circle with a break of up\n  // to 4 pixels will have at least 3 of these 4 pixels active.\n  static const int32 short_circle_perimeter = 4;\n  static const int32 short_threshold = 3;\n  static const int32 short_circle_x[] = { -3,  0, +3,  0 };\n  static const int32 short_circle_y[] = {  0, -3,  0, +3 };\n\n  // Precompute image offsets.\n  int32 short_offsets[short_circle_perimeter];\n  for (int i = 0; i < short_circle_perimeter; ++i) {\n    short_offsets[i] = short_circle_x[i] + short_circle_y[i] * frame.getWidth();\n  }\n\n  // Large circle values.\n  static const int32 full_circle_perimeter = 16;\n  static const int32 full_threshold = 12;\n  static const int32 full_circle_x[] =\n      { -1,  0, +1, +2, +3, +3, +3, +2, +1, +0, -1, -2, -3, -3, -3, -2 };\n  static const int32 full_circle_y[] =\n      { -3, -3, -3, -2, -1,  0, +1, +2, +3, +3, +3, +2, +1, +0, -1, -2 };\n\n  // Precompute image offsets.\n  int32 full_offsets[full_circle_perimeter];\n  for (int i = 0; i < full_circle_perimeter; ++i) {\n    full_offsets[i] = full_circle_x[i] + full_circle_y[i] * frame.getWidth();\n  }\n\n  const int frame_width = frame.getWidth();\n\n  const int end_y = frame.getHeight() - FAST_BORDER_BUFFER;\n  const int end_x = frame.getWidth() - FAST_BORDER_BUFFER;\n\n  best_feature_map->clear(0);\n\n  // Loop through once to find FAST feature clumps.\n  for (int32 img_y = FAST_BORDER_BUFFER; img_y < end_y; ++img_y) {\n    const uint8* curr_pixel_ptr =\n        frame.getPixelPtrConst(FAST_BORDER_BUFFER, img_y);\n\n    for (int32 img_x = FAST_BORDER_BUFFER; img_x < end_x; ++img_x) {\n      // Only insert it if it meets the quick minimum requirements test.\n      if (testCircle(short_circle_perimeter, short_threshold,\n                     curr_pixel_ptr, short_offsets) != 0) {\n\n        // Longer test for actual feature score..\n        const int32 fast_score = testCircle(full_circle_perimeter,\n                                            full_threshold,\n                                            curr_pixel_ptr,\n                                            full_offsets);\n\n        // Non-zero score means the feature was found.\n        if (fast_score != 0) {\n          uint8* const center_ptr = best_feature_map->getPixelPtr(img_x, img_y);\n\n          // Increase the feature count on this pixel and the pixels in all\n          // 4 cardinal directions.\n          *center_ptr += 5;\n          *(center_ptr - 1) += 1;\n          *(center_ptr + 1) += 1;\n          *(center_ptr - frame_width) += 1;\n          *(center_ptr + frame_width) += 1;\n        }\n      }\n\n      ++curr_pixel_ptr;\n    }  // x\n  }  // y\n\n  timeLog(\"Found FAST features\");\n\n  int32 num_features = 0;\n  // Loop through again and Harris filter pixels in the center of clumps.\n  // We can shrink the window by 1 pixel on every side.\n  for (int32 img_y = FAST_BORDER_BUFFER + 1; img_y < end_y - 1; ++img_y) {\n    const int32 start_x = FAST_BORDER_BUFFER + 1;\n\n    const uint8* curr_pixel_ptr =\n        best_feature_map->getPixelPtrConst(start_x, img_y);\n\n    for (int32 img_x = start_x; img_x < end_x - 1; ++img_x) {\n      if (*curr_pixel_ptr >= MIN_NUM_CONNECTED) {\n        Point2D* const feature = features + num_features;\n        feature->x = img_x;\n        feature->y = img_y;\n        feature->score = 0;\n        feature->type = FEATURE_FAST;\n\n        ++num_features;\n        if (num_features >= max_num_features) {\n          return num_features;\n        }\n      }\n\n      ++curr_pixel_ptr;\n    }  // x\n  }  // y\n\n  timeLog(\"Filtered FAST features\");\n  return num_features;\n}\n\n}  // namespace flow\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/feature_detector.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_FEATURE_DETECTOR_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_FEATURE_DETECTOR_H_\n\nnamespace flow {\n\n// Add features along a regular grid.\nint32 seedFeatures(const Image<uint8>& frame,\n                   const int32 num_x, const int32 num_y,\n                   const float32 left, const float32 top,\n                   const float32 right, const float32 bottom,\n                   const int32 type, Point2D* const features);\n\n// Compute the corneriness of a point in the image.\nfloat32 harrisFilter(const Image<int32>& I_x, const Image<int32>& I_y,\n                     const int32 x, const int32 y);\n\n// Scan the frame for potential features using the FAST feature detector.\nint32 findFastFeatures(const Image<uint8>& frame,\n                       const int32 max_num_features,\n                       Point2D* const features,\n                       Image<uint8>* const best_feature_map);\n\n// Score a bunch of candidate features.  Assigns the scores to the input\n// candidate_features array entries.\nvoid scoreFeatures(const Image<int32>& I_x, const Image<int32>& I_y,\n                   const int32 num_candidates,\n                   Point2D* const candidate_features);\n\n// Copy the best features (with local non-max suppression) from\n// candidate_features to final_features.\n// Returns the number of features copied.\nint32 sortAndSelect(const int32 num_candidates,\n                    const int32 max_features,\n                    const Image<bool>& interest_map,\n                    Point2D* const candidate_features,\n                    Point2D* const final_features,\n                    Image<uint8>* const best_feature_map);\n\n}  // namespace flow\n\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_FEATURE_DETECTOR_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/image.h",
    "content": "// Copyright 2009 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_IMAGE_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_IMAGE_H_\n\n#include \"optical_flow_utils.h\"\n\n// TODO(andrewharp): Make this a cast to uint32 if/when we go unsigned for\n// operations.\n#define ZERO 0\n\n#ifdef SANITY_CHECKS\n  #define CHECK_PIXEL(IMAGE, X, Y) {\\\n    CHECK((IMAGE)->validPixel((X), (Y)), \\\n          \"CHECK_PIXEL(%d,%d) in %dx%d image.\", \\\n          static_cast<int32>(X), static_cast<int32>(Y), \\\n          (IMAGE)->getWidth(), (IMAGE)->getHeight());\\\n  }\n\n  #define CHECK_PIXEL_INTERP(IMAGE, X, Y) {\\\n    CHECK((IMAGE)->validInterpPixel((X), (Y)), \\\n          \"CHECK_PIXEL_INTERP(%.2f, %.2f) in %dx%d image.\", \\\n          static_cast<float32>(X), static_cast<float32>(Y), \\\n          (IMAGE)->getWidth(), (IMAGE)->getHeight());\\\n  }\n#else\n  #define CHECK_PIXEL(image, x, y) {}\n  #define CHECK_PIXEL_INTERP(IMAGE, X, Y) {}\n#endif\n\nnamespace flow {\n\n// TODO(andrewharp): Make explicit which operations support negative numbers or\n// struct/class types in image data (possibly create fast multi-dim array class\n// for data where pixel arithmetic does not make sense).\n\n// Image class optimized for working on numeric arrays as grayscale image data.\n// Supports other data types as a 2D array class, so long as no pixel math\n// operations are called (convolution, downsampling, etc).\ntemplate <typename T>\nclass Image {\n public:\n  Image(const int32 width, const int32 height) :\n      width_(width),\n      height_(height),\n      width_less_one_(width_ - 1),\n      height_less_one_(height_ - 1),\n      num_pixels_(width_ * height_) {\n    allocate();\n  }\n\n  explicit Image(const Size& size) :\n      width_(size.width),\n      height_(size.height),\n      width_less_one_(width_ - 1),\n      height_less_one_(height_ - 1),\n      num_pixels_(width_ * height_) {\n    allocate();\n  }\n\n  // Constructor that creates an image from preallocated data.\n  // Note: The image takes ownership of the data.\n  Image(const int32 width, const int32 height, T* const image) :\n      width_(width),\n      height_(height),\n      width_less_one_(width_ - 1),\n      height_less_one_(height_ - 1),\n      num_pixels_(width_ * height_) {\n    image_data_ = image;\n    if (image_data_ == NULL) {\n      LOGE(\"Can't create image with NULL data!\");\n    }\n  }\n\n  ~Image() {\n    free(image_data_);\n  }\n\n  inline int32 getWidth() const { return width_; }\n  inline int32 getHeight() const { return height_; }\n\n  // Bilinearly sample a value between pixels.\n  // Values outside of the image are sampled from the nearest edge of the image.\n  inline float32 getPixelInterp(const float32 x, const float32 y) const {\n    // Do int32 conversion one time.\n    const int32 floored_x = (int32) x;\n    const int32 floored_y = (int32) y;\n\n    // Note: it might be the case that the *_[min|max] values are clipped, and\n    // these (the a b c d vals) aren't (for speed purposes), but that doesn't\n    // matter. We'll just be blending the pixel with itself in that case anyway.\n    const float32 b = x - floored_x;\n    const float32 a = 1.0f - b;\n\n    const float32 d = y - floored_y;\n    const float32 c = 1.0f - d;\n\n    CHECK(validInterpPixel(x, y),\n          \"x or y out of bounds! %.2f [0 - %d), %.2f [0 - %d)\",\n          x, width_less_one_, y, height_less_one_);\n\n    const T* const pix_ptr = getPixelPtrConst(floored_x, floored_y);\n\n// Experimental NEON acceleration... not to be turned on until it's faster.\n#if FALSE\n#ifdef HAVE_ARMEABI_V7A\n    if (supportsNeon()) {\n      // Output value:\n      // a * c * p1 +\n      // b * c * p2 +\n      // a * d * p3 +\n      // b * d * p4\n      const float32x2_t ab = {a, b};\n      const float32x4_t ab_c_ab_d = vcombine_f32(vmul_n_f32(ab, c),\n                                                 vmul_n_f32(ab, d));\n\n      const float32x4_t p1p2p3p4 = {pix_ptr[0], pix_ptr[1],\n                                    pix_ptr[width_], pix_ptr[width_ + 1]};\n\n      float32x4_t almost = vmulq_f32(ab_c_ab_d, p1p2p3p4);\n\n      // Butterfly-ish sum.\n      almost = vaddq_f32(vrev64q_f32(almost), almost);\n\n      return vgetq_lane_f32(almost, 0) + vgetq_lane_f32(almost, 1);\n    }\n#endif\n#endif\n\n    // Get the pixel values surrounding this point.\n    const T& p1 = pix_ptr[0];\n    const T& p2 = pix_ptr[1];\n    const T& p3 = pix_ptr[width_];\n    const T& p4 = pix_ptr[width_ + 1];\n\n    // Simple bilinear interpolation between four reference pixels.\n    // If x is the value requested:\n    //     a  b\n    //   -------\n    // c |p1 p2|\n    //   |  x  |\n    // d |p3 p4|\n    //   -------\n    return  c * ((a * p1) + (b * p2)) +\n            d * ((a * p3) + (b * p4));\n  }\n\n  // Returns true iff the pixel is in the image's boundaries.\n  inline bool validPixel(const int32 x, const int32 y) const {\n    return inRange(x, ZERO, width_less_one_) &&\n           inRange(y, ZERO, height_less_one_);\n  }\n\n  // Returns true iff the pixel is in the image's boundaries for interpolation\n  // purposes.\n  // TODO(andrewharp): check in interpolation follow-up change.\n  inline bool validInterpPixel(const float32 x, const float32 y) const {\n    // Exclusive of max because we can be more efficient if we don't handle\n    // interpolating on or past the last pixel.\n    return (x >= ZERO) && (x < width_less_one_) &&\n           (y >= ZERO) && (y < height_less_one_);\n  }\n\n  // Safe lookup with boundary enforcement.\n  inline T getPixelClipped(const int32 x, const int32 y) const {\n    return getPixel(clip(x, ZERO, width_less_one_),\n                    clip(y, ZERO, height_less_one_));\n  }\n\n  // Returns a const pointer to the pixel in question.\n  inline const T* getPixelPtrConst(const int32 x, const int32 y) const {\n    CHECK_PIXEL(this, x, y);\n    return image_data_ + y * width_ + x;\n  }\n\n  // Returns a pointer to the pixel in question.\n  inline T* getPixelPtr(const int32 x, const int32 y) const {\n    CHECK_PIXEL(this, x, y);\n    return image_data_ + y * width_ + x;\n  }\n\n  // Fast lookup without boundary enforcement.\n  inline const T getPixel(const int32 x, const int32 y) const {\n    CHECK_PIXEL(this, x, y);\n    return image_data_[y * width_ + x];\n  }\n\n  // Fast setting without boundary enforcement.\n  inline void setPixel(const int32 x, const int32 y, const T& val) {\n    CHECK_PIXEL(this, x, y);\n    image_data_[y * width_ + x] = val;\n  }\n\n  // Clears image to a single value.\n  inline void clear(const T& val) {\n    memset(image_data_, val, sizeof(*image_data_) * num_pixels_);\n  }\n\n\n#ifdef HAVE_ARMEABI_V7A\n  // This function does the bulk of the work.\n  inline void downsample32ColumnsNeon(const uint8* const original,\n                                      const int32 stride,\n                                      const int32 orig_x) {\n    // Divide input x offset by 4 to find output offset.\n    const int32 new_x = orig_x >> 2;\n\n    // Initial offset into top row.\n    const uint8* offset = original + orig_x;\n\n    // Sum along vertical columns.\n    // Process 32x4 input pixels and 8x1 output pixels per iteration.\n    for (int32 new_y = 0; new_y < height_; ++new_y) {\n      uint16x8_t accum1 = vdupq_n_u16(0);\n      uint16x8_t accum2 = vdupq_n_u16(0);\n\n      // Go top to bottom across the four rows of input pixels that make up\n      // this output row.\n      for (int32 row_num = 0; row_num < 4; ++row_num) {\n        // First 16 bytes.\n        {\n          // Load 32 bytes of data from current offset.\n          const uint8x16_t curr_data1 = vld1q_u8(offset);\n          // Pairwise add and accumulate into accum vectors (16 bit to account\n          // for values above 255).\n          accum1 = vpadalq_u8(accum1, curr_data1);\n        }\n\n        // Second 16 bytes.\n        {\n          // Load 32 bytes of data from current offset.\n          const uint8x16_t curr_data2 = vld1q_u8(offset + 16);\n          // Pairwise add and accumulate into accum vectors (16 bit to account\n          // for values above 255).\n          accum2 = vpadalq_u8(accum2, curr_data2);\n        }\n\n        // Move offset down one row.\n        offset += stride;\n      }\n\n      // Add and widen, then divide by 16 (number of input pixels per output\n      // pixel) and narrow data from 32 bits per pixel to 16 bpp.\n      const uint16x4_t tmp_pix1 = vqshrn_n_u32(vpaddlq_u16(accum1), 4);\n      const uint16x4_t tmp_pix2 = vqshrn_n_u32(vpaddlq_u16(accum2), 4);\n\n      // Combine 4x1 pixel strips into 8x1 pixel strip and narrow from\n      // 16 bits to 8 bits per pixel.\n      const uint8x8_t allpixels = vmovn_u16(vcombine_u16(tmp_pix1, tmp_pix2));\n\n      // This points to the leftmost pixel of our 8 horizontally arranged\n      // pixels in the destination data.\n      uint8* const ptr_dst = getPixelPtr(new_x, new_y);\n\n      // Copy all pixels from composite 8x1 vector into output strip.\n      vst1_u8(ptr_dst, allpixels);\n    }\n  }\n\n\n  // Hardware accelerated downsampling method for supported devices.\n  // Requires that image size be a multiple of 16 pixels in each dimension,\n  // and that downsampling be by a factor of 4.\n  void downsampleAveragedNeon(const uint8* const original,\n                              const int32 stride) {\n    // Hardcoded to only work on 4x downsampling.\n    const int32 orig_width = width_ * 4;\n\n    // We process 32 input pixels lengthwise at a time.\n    // The output per pass of this loop is an 8 wide by 1 tall pixel strip.\n    for (int32 orig_x = 0; orig_x < orig_width; orig_x += 32) {\n      // Push it to the left enough so that it never goes out of bounds.\n      // This will result in some extra computation on the last pass on\n      // devices whose frame widths are not multiples of 32.\n      downsample32ColumnsNeon(original, stride, min(orig_x, orig_width - 32));\n    }\n  }\n#endif\n\n\n  // Naive downsampler that reduces image size by factor by averaging pixels in\n  // blocks of size factor x factor.\n  void downsampleAveraged(const T* const original, const int32 stride,\n                          const int32 factor) {\n#ifdef HAVE_ARMEABI_V7A\n    if (supportsNeon() &&\n        factor == 4 &&\n        (height_ % 4) == 0) {\n      downsampleAveragedNeon(original, stride);\n      return;\n    }\n#endif\n\n    const int32 pixels_per_block = factor * factor;\n\n    // For every pixel in resulting image.\n    for (int32 y = 0; y < height_; ++y) {\n      const int32 orig_y = y * factor;\n      const int32 y_bound = orig_y + factor;\n\n      // Sum up the original pixels.\n      for (int32 x = 0; x < width_; ++x) {\n        const int32 orig_x = x * factor;\n        const int32 x_bound = orig_x + factor;\n\n        // Making this int32 because type U or T might overflow.\n        int32 pixel_sum = 0;\n\n        // Grab all the pixels that make up this pixel.\n        for (int32 curr_y = orig_y; curr_y < y_bound; ++curr_y) {\n          const T* p = original + curr_y * stride + orig_x;\n\n          for (int32 curr_x = orig_x; curr_x < x_bound; ++curr_x) {\n            pixel_sum += *p++;\n          }\n        }\n\n        setPixel(x, y, pixel_sum / pixels_per_block);\n      }\n    }\n  }\n\n  // Naive downsampler that reduces image size by factor by averaging pixels in\n  // blocks of size factor x factor.\n  void downsampleAveraged(const Image<T>& original, const int32 factor) {\n    downsampleAveraged(original.getPixelPtr(0, 0), original.getWidth(), factor);\n  }\n\n  // Relatively efficient downsampling of an image by a factor of two with a\n  // low-pass 3x3 smoothing operation thrown in.\n  void downsampleSmoothed3x3(const Image<T>& original) {\n    for (int32 y = 0; y < height_; ++y) {\n      const int32 orig_y = clip(2 * y, ZERO, original.height_less_one_);\n      const int32 min_y = clip(orig_y - 1, ZERO, original.height_less_one_);\n      const int32 max_y = clip(orig_y + 1, ZERO, original.height_less_one_);\n\n      for (int32 x = 0; x < width_; ++x) {\n        const int32 orig_x = clip(2 * x, ZERO, original.width_less_one_);\n        const int32 min_x = clip(orig_x - 1, ZERO, original.width_less_one_);\n        const int32 max_x = clip(orig_x + 1, ZERO, original.width_less_one_);\n\n        // Center.\n        int32 pixel_sum = original.getPixel(orig_x, orig_y) * 4;\n\n        // Sides.\n        pixel_sum += (original.getPixel(max_x, orig_y) +\n                      original.getPixel(min_x, orig_y) +\n                      original.getPixel(orig_x, max_y) +\n                      original.getPixel(orig_x, min_y)) * 2;\n\n        // Diagonals.\n        pixel_sum += (original.getPixel(max_x, max_y) +\n                      original.getPixel(min_x, max_y) +\n                      original.getPixel(max_x, min_y) +\n                      original.getPixel(min_x, min_y));\n\n        const int32 pixel_val = pixel_sum>>4;  // 16\n\n        //LOGV(\"Setting %d,%d to %d\", col, row, pixel_val);\n\n        setPixel(x, y, pixel_val);\n      }\n    }\n  }\n\n  // Relatively efficient downsampling of an image by a factor of two with a\n  // low-pass 5x5 smoothing operation thrown in.\n  void downsampleSmoothed5x5(const Image<T>& original) {\n    const int32 max_x = original.width_less_one_;\n    const int32 max_y = original.height_less_one_;\n\n    // The JY Bouget paper on Lucas-Kanade recommends a\n    // [1/16 1/4 3/8 1/4 1/16]^2 filter.\n    // This works out to a [1 4 6 4 1]^2 / 256 array, precomputed below.\n    static const int32 window_radius = 2;\n    static const int32 window_size = window_radius*2 + 1;\n    static const int32 window_weights[] = {1, 4, 6, 4,1,  // 16 +\n                                           4,16,24,16,4,  // 64 +\n                                           6,24,36,24,6,  // 96 +\n                                           4,16,24,16,4,  // 64 +\n                                           1, 4, 6, 4,1}; // 16 = 256\n\n    // We'll multiply and sum with the the whole numbers first, then divide by\n    // the total weight to normalize at the last moment.\n    for (int32 y = 0; y < height_; ++y) {\n      for (int32 x = 0; x < width_; ++x) {\n        int32 pixel_sum = 0;\n\n        const int32* w = window_weights;\n        const int32 start_x = clip((x<<1) - window_radius, ZERO, max_x);\n\n        // Clip the boundaries to the size of the image.\n        for (int32 window_y = 0; window_y < window_size; ++window_y) {\n          const int32 start_y =\n              clip((y<<1) - window_radius + window_y, ZERO, max_y);\n\n          const T* p = original.getPixelPtrConst(start_x, start_y);\n\n          for (int32 window_x = 0; window_x < window_size; ++window_x) {\n            pixel_sum +=  *p++ * *w++;\n          }\n        }\n\n        // Conversion to type T will happen here after shifting right 8 bits to\n        // divide by 256.\n        setPixel(x, y, pixel_sum >> 8);\n      }\n    }\n  }\n\n  // Optimized Scharr filter on a single pixel in the X direction.\n  // Scharr filters are like central-difference operators, but have more\n  // rotational symmetry in their response because they also consider the\n  // diagonal neighbors.\n  template <typename U>\n  inline T scharrPixelX(const Image<U>& original,\n                        const int32 center_x, const int32 center_y) const {\n    const int32 min_x = clip(center_x - 1, ZERO, original.width_less_one_);\n    const int32 max_x = clip(center_x + 1, ZERO, original.width_less_one_);\n    const int32 min_y = clip(center_y - 1, ZERO, original.height_less_one_);\n    const int32 max_y = clip(center_y + 1, ZERO, original.height_less_one_);\n\n    // Convolution loop unrolled for performance...\n    return (3 * (original.getPixel(max_x, min_y)\n                 + original.getPixel(max_x, max_y)\n                 - original.getPixel(min_x, min_y)\n                 - original.getPixel(min_x, min_y))\n            + 10 * (original.getPixel(max_x, center_y)\n                    - original.getPixel(min_x, center_y))) / 32;\n  }\n\n  // Optimized Scharr filter on a single pixel in the X direction.\n  // Scharr filters are like central-difference operators, but have more\n  // rotational symmetry in their response because they also consider the\n  // diagonal neighbors.\n  template <typename U>\n  inline T scharrPixelY(const Image<U>& original,\n                        const int32 center_x, const int32 center_y) const {\n    const int32 min_x = clip(center_x - 1, 0, original.width_less_one_);\n    const int32 max_x = clip(center_x + 1, 0, original.width_less_one_);\n    const int32 min_y = clip(center_y - 1, 0, original.height_less_one_);\n    const int32 max_y = clip(center_y + 1, 0, original.height_less_one_);\n\n    // Convolution loop unrolled for performance...\n    return (3 * (original.getPixel(min_x, max_y)\n                 + original.getPixel(max_x, max_y)\n                 - original.getPixel(min_x, min_y)\n                 - original.getPixel(max_x, min_y))\n            + 10 * (original.getPixel(center_x, max_y)\n                    - original.getPixel(center_x, min_y))) / 32;\n  }\n\n  // Convolve the image with a Scharr filter in the X direction.\n  // Much faster than an equivalent generic convolution.\n  template <typename U>\n  inline void scharrX(const Image<U>& original) {\n    for (int32 y = 0; y < height_; ++y) {\n      for (int32 x = 0; x < width_; ++x) {\n        setPixel(x, y, scharrPixelX(original, x, y));\n      }\n    }\n  }\n\n  // Convolve the image with a Scharr filter in the Y direction.\n  // Much faster than an equivalent generic convolution.\n  template <typename U>\n  inline void scharrY(const Image<U>& original) {\n    for (int32 y = 0; y < height_; ++y) {\n      for (int32 x = 0; x < width_; ++x) {\n        setPixel(x, y, scharrPixelY(original, x, y));\n      }\n    }\n  }\n\n  static inline T halfDiff(int32 first, int32 second) {\n    return (second - first) / 2;\n  }\n\n  template <typename U>\n  void derivativeX(const Image<U>& original) {\n    for (int32 y = 0; y < height_; ++y) {\n      T* const dest_row = getPixelPtr(0, y);\n      const U* const source_row = original.getPixelPtrConst(0, y);\n\n      // Compute first pixel.\n      dest_row[0] = halfDiff(source_row[0], source_row[1]);\n\n      // Last pixel.\n      dest_row[width_less_one_] = halfDiff(source_row[width_less_one_ - 1],\n                                           source_row[width_less_one_]);\n\n      // All the pixels in between.\n      const U* const source_prev_pixel = source_row - 1;\n      const U* const source_next_pixel = source_row + 1;\n      for (int32 x = 1; x < width_less_one_; ++x) {\n        dest_row[x] = halfDiff(source_prev_pixel[x], source_next_pixel[x]);\n      }\n    }\n  }\n\n  template <typename U>\n  void derivativeY(const Image<U>& original) {\n    for (int32 y = 0; y < height_; ++y) {\n      T* const dest_row = getPixelPtr(0, y);\n\n      const U* const source_prev_pixel =\n          original.getPixelPtrConst(0, max(0, y - 1));\n\n      const U* const source_next_pixel =\n          original.getPixelPtrConst(0, min(height_less_one_, y + 1));\n\n      for (int32 x = 0; x < width_; ++x) {\n        dest_row[x] = halfDiff(source_prev_pixel[x], source_next_pixel[x]);\n      }\n    }\n  }\n\n  // Generic function for convolving pixel with 3x3 filter.\n  // Filter pixels should be in row major order.\n  template <typename U>\n  inline T convolvePixel3x3(const Image<U>& original,\n                            const int32* const filter,\n                            const int32 center_x, const int32 center_y,\n                            const int32 total) const {\n    int32 sum = 0;\n    for (int32 filter_y = 0; filter_y < 3; ++filter_y) {\n      const int32 y = clip(center_y - 1 + filter_y, 0, original.getHeight());\n      for (int32 filter_x = 0; filter_x < 3; ++filter_x) {\n        const int32 x = clip(center_x - 1 + filter_x, 0, original.getWidth());\n        sum += original.getPixel(x, y) * filter[filter_y * 3 + filter_x];\n      }\n    }\n    return sum / total;\n  }\n\n  // Generic function for convolving an image with a 3x3 filter.\n  // TODO(andrewharp): Generalize this for any size filter.\n  template <typename U>\n  inline void convolve3x3(const Image<U>& original,\n                          const int32* const filter) {\n    int32 sum = 0;\n    for (int32 i = 0; i < 9; ++i) {\n      sum += abs(filter[i]);\n    }\n    for (int32 y = 0; y < height_; ++y) {\n      for (int32 x = 0; x < width_; ++x) {\n        setPixel(x, y, convolvePixel3x3(original, filter, x, y, sum));\n      }\n    }\n  }\n\n  // Load this image's data from a data array. The data at pixels is assumed to\n  // have dimensions equivalent to this image's dimensions * factor.\n  inline void fromArray(const T* const pixels, const int32 stride,\n                        const int32 factor) {\n    if (factor == 1) {\n      // If not subsampling, memcpy per line should be faster.\n      memcpy(this->image_data_, pixels, num_pixels_ * sizeof(T));\n      return;\n    }\n\n    downsampleAveraged(pixels, stride, factor);\n  }\n\n  // Copy the image back out to an appropriately sized data array.\n  inline void toArray(T* const pixels) const {\n    // If not subsampling, memcpy should be faster.\n    memcpy(pixels, this->image_data_, num_pixels_ * sizeof(T));\n  }\n\n private:\n  inline void allocate() {\n    image_data_ = (T*)malloc(num_pixels_ * sizeof(T));\n    if (image_data_ == NULL) {\n      LOGE(\"Couldn't allocate image data!\");\n    }\n  }\n\n  T* image_data_;\n  int32 width_;\n  int32 height_;\n\n public:\n  // Precompute these for efficiency's sake as they're used by a lot of\n  // clipping code and loop code.\n  // TODO(andrewharp): make these only accessible by other Images.\n  int32 width_less_one_;\n  int32 height_less_one_;\n  int32 num_pixels_;\n};\n\n\n// Create a pyramid of downsampled images. The first level of the pyramid is the\n// original image.\ninline void computeSmoothedPyramid(const Image<uint8>& frame,\n                                   const int32 num_levels,\n                                   Image<uint8>** const pyramid) {\n  // TODO(andrewharp): Find a const correct solution to this...\n  // Maybe make an pyramid class with the first level of this pyramid as a\n  // separate pointer?\n\n  // Cast away const, but we're not going to hurt it, honest!\n  pyramid[0] = const_cast<Image<uint8>*>(&frame);\n\n  for (int32 l = 1; l < num_levels; ++l) {\n    pyramid[l]->downsampleSmoothed3x3(*pyramid[l - 1]);\n  }\n}\n\n\n// Create a spatial derivative pyramid based on a downsampled pyramid.\ninline void computeSpatialPyramid(const Image<uint8>** const pyramid,\n                                  const int32 num_levels,\n                                  Image<int32>** pyramid_x,\n                                  Image<int32>** pyramid_y) {\n  for (int32 l = 0; l < num_levels; ++l) {\n    const Image<uint8>& frame = *pyramid[l];\n\n    // Fast convolutions to find spatial derivatives.\n    pyramid_x[l]->derivativeX(frame);\n    pyramid_y[l]->derivativeY(frame);\n  }\n}\n\n\n// Marks a circle of a given radius on the boolean image.\n// If the center spot is already marked, don't do anything and return false.\n// Otherwise, mark everything in range true and return true.\ntemplate <typename U>\ninline static bool markImage(const int32 x, const int32 y,\n                             const int32 radius,\n                             Image<U>* const img) {\n  if (img->getPixel(x, y)) {\n    // Already claimed, sorry.\n    return false;\n  }\n\n  const int32 squared_radius = square(radius);\n\n  for (int32 d_y = 0; d_y < radius; ++d_y) {\n    const int32 squared_y_dist = square(d_y);\n\n    const int32 min_y = y > d_y ? y - d_y : ZERO;\n    const int32 max_y = min(y + d_y, img->height_less_one_);\n\n    for (int32 d_x = 0; d_x < radius; ++d_x) {\n      if (squared_y_dist + square(d_x) <= squared_radius) {\n        const int32 min_x = x > d_x ? x - d_x : ZERO;\n        const int32 max_x = min(x + d_x, img->width_less_one_);\n\n        // Mark all four quadrants.\n        img->setPixel(max_x, max_y, true);\n        img->setPixel(max_x, min_y, true);\n        img->setPixel(min_x, max_y, true);\n        img->setPixel(min_x, min_y, true);\n      } else {\n        // Once we're too far out, we're not coming back in.\n        break;\n      }\n    }\n  }\n  return true;\n}\n\n\n// Puts the image gradient matrix about a pixel into the 2x2 float array G.\n// vals_x should be an array of the window x gradient values, whose indices\n// can be in any order but are parallel to the vals_y entries.\n// See http://robots.stanford.edu/cs223b04/algo_tracking.pdf for more details.\ninline void calculateG(const float32* const vals_x, const float32* const vals_y,\n                       const int32 num_vals, float* const G) {\n  // Defined here because we want to keep track of how many values were\n  // processed by NEON, so that we can finish off the remainder the normal\n  // way.\n  int32 i = 0;\n\n#ifdef HAVE_ARMEABI_V7A\n  if (supportsNeon()) {\n    const float32_t* const arm_vals_x = (const float32_t*) vals_x;\n    const float32_t* const arm_vals_y = (const float32_t*) vals_y;\n\n    // Running sums.\n    float32x4_t xx = vdupq_n_f32(0.0f);\n    float32x4_t xy = vdupq_n_f32(0.0f);\n    float32x4_t yy = vdupq_n_f32(0.0f);\n\n    // Maximum index we can load 4 consecutive values from.\n    // e.g. if there are 81 values, our last full pass can be from index 77:\n    // 81-4=>77 (77, 78, 79, 80)\n    const int32 max_i = num_vals - 4;\n\n    // Process values 4 at a time, accumulating the sums of\n    // the pixel-wise x*x, x*y, and y*y values.\n    for (; i <= max_i; i += 4) {\n      // Load xs\n      float32x4_t x = vld1q_f32(arm_vals_x + i);\n\n      // Multiply x*x and accumulate.\n      xx = vmlaq_f32(xx, x, x);\n\n      // Load ys\n      float32x4_t y = vld1q_f32(arm_vals_y + i);\n\n      // Multiply x*y and accumulate.\n      xy = vmlaq_f32(xy, x, y);\n\n      // Multiply y*y and accumulate.\n      yy = vmlaq_f32(yy, y, y);\n    }\n\n    static float32_t xx_vals[4];\n    static float32_t xy_vals[4];\n    static float32_t yy_vals[4];\n\n    vst1q_f32(xx_vals, xx);\n    vst1q_f32(xy_vals, xy);\n    vst1q_f32(yy_vals, yy);\n\n    // Accumulated values are store in sets of 4, we have to manually add\n    // the last bits together.\n    for (int32 j = 0; j < 4; ++j) {\n      G[0] += xx_vals[j];\n      G[1] += xy_vals[j];\n      G[3] += yy_vals[j];\n    }\n  }\n#endif\n  // Non-accelerated version, also finishes off last few values (< 4) from\n  // above.\n  for (; i < num_vals; ++i) {\n    G[0] += square(vals_x[i]);\n    G[1] += vals_x[i] * vals_y[i];\n    G[3] += square(vals_y[i]);\n  }\n\n  // The matrix is symmetric, so this is a given.\n  G[2] = G[1];\n}\n\n\n// Puts the image gradient matrix about a pixel into the 2x2 float array G.\n// Looks up interpolated pixels, then calls above method for implementation.\ninline void calculateG(const int window_size,\n                       const float32 center_x, const float center_y,\n                       const Image<int32>& I_x, const Image<int32>& I_y,\n                       float* const G) {\n  CHECK(I_x.validPixel(center_x, center_y), \"Problem in calculateG!\");\n\n  // Hardcoded to allow for a max window radius of 5 (9 pixels x 9 pixels).\n  static const int kMaxWindowRadius = 5;\n  CHECK(window_size <= kMaxWindowRadius,\n        \"Window %d > %d!\", window_size, kMaxWindowRadius);\n\n  // Diameter of window is 2 * radius + 1 for center pixel.\n  static const int kWindowBufferSize =\n      (kMaxWindowRadius * 2 + 1) * (kMaxWindowRadius * 2 + 1);\n\n  // Preallocate buffers statically for efficiency.\n  static float32 vals_x[kWindowBufferSize];\n  static float32 vals_y[kWindowBufferSize];\n\n  int32 num_vals = 0;\n\n  for (int32 win_x = -window_size; win_x <= window_size; ++win_x) {\n    for (int32 win_y = -window_size; win_y <= window_size; ++win_y) {\n      vals_x[num_vals] = I_x.getPixelInterp(center_x + win_x,\n                                            center_y + win_y);\n      vals_y[num_vals] = I_y.getPixelInterp(center_x + win_x,\n                                            center_y + win_y);\n      ++num_vals;\n    }\n  }\n  calculateG(vals_x, vals_y, num_vals, G);\n}\n\n}  // namespace flow\n\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_IMAGE_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/optical_flow-jni.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Andrew Harp\n\n#include <time.h>\n#include <stdlib.h>\n#include <string.h>\n#include <jni.h>\n#include \"types.h\"\n#include \"optical_flow_utils.h\"\n#include \"time_log.h\"\n#include \"image.h\"\n#include \"optical_flow.h\"\n\nnamespace flow {\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_initNative(\n      JNIEnv* env,\n      jobject thiz,\n      jint width,\n      jint height,\n      jint downsample_factor);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_addFrameNative(\n      JNIEnv* env,\n      jobject thiz,\n      jbyteArray photo_data,\n      jlong timestamp);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_computeFeaturesNative(\n      JNIEnv* env,\n      jobject thiz,\n      jboolean cached_ok);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_computeFlowNative(\n      JNIEnv* env,\n      jobject thiz);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_printInfoNative(\n      JNIEnv* env,\n      jobject thiz);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_addInterestRegionNative(\n      JNIEnv* env,\n      jobject thiz,\n      jint num_x, jint num_y,\n      jfloat left, jfloat top, jfloat right, jfloat bottom);\n\n  JNIEXPORT\n  jfloatArray\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_getFeaturesNative(\n      JNIEnv* env,\n      jobject thiz,\n      jboolean only_found_);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_getAccumulatedDeltaNative(\n      JNIEnv* env,\n      jobject thiz,\n      jlong timestamp,\n      jfloat position_x,\n      jfloat position_y,\n      jfloat radius,\n      jfloatArray delta);\n\n  JNIEXPORT\n  void\n  JNICALL\n  Java_com_googlecode_eyesfree_opticflow_OpticalFlow_resetNative(\n      JNIEnv* env,\n      jobject thiz);\n\n#ifdef __cplusplus\n}\n#endif\n\nOpticalFlow* optical_flow = NULL;\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_initNative(\n    JNIEnv* env,\n    jobject thiz,\n    jint width,\n    jint height,\n    jint downsample_factor) {\n  SAFE_DELETE(optical_flow);\n\n  LOGI(\"Initializing optical flow. %dx%d, %d\",\n       width, height, downsample_factor);\n  optical_flow = new OpticalFlow(width, height, downsample_factor);\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_addFrameNative(\n    JNIEnv* env,\n    jobject thiz,\n    jbyteArray photo_data,\n    jlong timestamp) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  resetTimeLog();\n  timeLog(\"Starting optical flow\");\n\n  // Copy image into currFrame.\n  jboolean iCopied = JNI_FALSE;\n  jbyte* pixels = env->GetByteArrayElements(photo_data, &iCopied);\n\n  timeLog(\"Got elements\");\n\n  // Add the frame to the optical flow object.\n  optical_flow->nextFrame(reinterpret_cast<uint8*>(pixels), timestamp);\n\n  env->ReleaseByteArrayElements(photo_data, pixels, JNI_ABORT);\n  timeLog(\"Released elements\");\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_computeFeaturesNative(\n    JNIEnv* env,\n    jobject thiz,\n    jboolean cached_ok) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  optical_flow->computeFeatures(cached_ok);\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_computeFlowNative(\n    JNIEnv* env,\n    jobject thiz) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  optical_flow->computeFlow();\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_printInfoNative(\n    JNIEnv* env,\n    jobject thiz) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  printTimeLog();\n  optical_flow->printInfo();\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_addInterestRegionNative(\n    JNIEnv* env,\n    jobject thiz,\n    jint num_x, jint num_y,\n    jfloat left, jfloat top, jfloat right, jfloat bottom) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  optical_flow->addInterestRegion(num_x, num_y, left, top, right, bottom);\n  timeLog(\"Added interest region.\");\n}\n\n\nJNIEXPORT\njfloatArray\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_getFeaturesNative(\n    JNIEnv* env,\n    jobject thiz,\n    jboolean only_found) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  jfloat feature_arr[MAX_FEATURES * FEATURE_STEP];\n\n  const int32 number_of_features =\n      optical_flow->getFeatures(only_found, feature_arr);\n\n  // Create and return the array that will be passed back to Java.\n  jfloatArray features = env->NewFloatArray(number_of_features * FEATURE_STEP);\n  if (features == NULL) {\n    LOGE(\"null array!\");\n    return NULL;\n  }\n  env->SetFloatArrayRegion(\n      features, 0, number_of_features * FEATURE_STEP, feature_arr);\n\n  return features;\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_getAccumulatedDeltaNative(\n    JNIEnv* env,\n    jobject thiz,\n    jlong timestamp,\n    jfloat position_x,\n    jfloat position_y,\n    jfloat radius,\n    jfloatArray delta) {\n  CHECK(optical_flow != NULL, \"Optical flow not initialized!\");\n\n  const Point2D query_position(position_x, position_y);\n  const Point2D query_delta =\n      optical_flow->getAccumulatedDelta(query_position, radius, timestamp);\n  const jfloat point_arr[] = { query_delta.x, query_delta.y };\n\n  env->SetFloatArrayRegion(delta, 0, 2, point_arr);\n}\n\n\nJNIEXPORT\nvoid\nJNICALL\nJava_com_googlecode_eyesfree_opticflow_OpticalFlow_resetNative(\n    JNIEnv* env, jobject thiz) {\n  LOGI(\"Cleaning up optical flow.\");\n  SAFE_DELETE(optical_flow);\n}\n\n}  // namespace flow\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/optical_flow.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// Author: Andrew Harp\n\n#include <string.h>\n\n#include \"utils.h\"\n#include \"time_log.h\"\n\n#include \"image.h\"\n\n#include \"math.h\"\n\n#include \"optical_flow.h\"\n#include \"feature_detector.h\"\n\nnamespace flow {\n\nOpticalFlow::OpticalFlow(const int32 frame_width,\n                         const int32 frame_height,\n                         const int32 downsample_factor) :\n    downsample_factor_(downsample_factor),\n    original_size_(frame_width, frame_height),\n    working_size_(frame_width / downsample_factor_,\n                  frame_height / downsample_factor_),\n    first_frame_index_(0),\n    num_frames_(0),\n    last_time_fresh_features_(0),\n    frame_added_(false),\n    features_computed_(false),\n    flow_computed_(false) {\n  for (int i = 0; i < NUM_FRAMES; ++i) {\n    frame_pairs_[i].init(0);\n  }\n\n  interest_map_ = new Image<bool>(working_size_);\n  feature_scratch_ = new Image<uint8>(working_size_);\n\n  frame1_ = new ImageData(working_size_);\n  frame2_ = new ImageData(working_size_);\n}\n\n\nOpticalFlow::~OpticalFlow() {\n  // Delete all image storage.\n  SAFE_DELETE(feature_scratch_);\n  SAFE_DELETE(interest_map_);\n\n  SAFE_DELETE(frame1_);\n  SAFE_DELETE(frame2_);\n}\n\n\nvoid OpticalFlow::nextFrame(const uint8* const new_frame,\n                            const clock_t timestamp) {\n  frame_added_ = false;\n  features_computed_ = false;\n  flow_computed_ = false;\n\n  // Move the current framechange index up.\n  ++num_frames_;\n\n  // If we've got too many, push up the start of the queue.\n  if (num_frames_ > NUM_FRAMES) {\n    first_frame_index_ = geNthIndexFromStart(1);\n    --num_frames_;\n  }\n\n  FramePair* const curr_change = frame_pairs_ + geNthIndexFromEnd(0);\n  curr_change->init(timestamp);\n\n  interest_map_->clear(false);\n\n  // Cache out data from last frame.\n  // Don't run on frame 0 (no point) or frame 1 (because the old frame will\n  // already be in frame1_).\n  if (num_frames_ > 2) {\n    swap(&frame1_, &frame2_);\n    timeLog(\"Copied data from last run\");\n  }\n\n  frame2_->init(new_frame, original_size_.width, timestamp, downsample_factor_);\n\n  // Special case for the first frame: make sure the image ends up in\n  // frame1_ so that feature detection can be done on it if desired.\n  // TODO(andrewharp): Make it so that feature detection is always done\n  // on the last frame added.\n  if (num_frames_ == 1) {\n    swap(&frame1_, &frame2_);\n  }\n\n  frame_added_ = true;\n}\n\n\nvoid OpticalFlow::computeFlow() {\n  CHECK(frame_added_ && features_computed_ && !flow_computed_,\n        \"Optical Flow function called out of order!\");\n\n  if (num_frames_ < 2) {\n    LOGV(\"Frame index was %d, skipping computation.\", num_frames_);\n    return;\n  }\n\n  FramePair* const curr_change = &frame_pairs_[geNthIndexFromEnd(0)];\n\n  findCorrespondences(curr_change);\n\n  flow_computed_ = true;\n}\n\n\nvoid OpticalFlow::findFeatures(const FramePair& prev_change,\n                               FramePair* const curr_change) {\n  int32 number_of_tmp_features = 0;\n\n  // Copy features from second frame of last pass to temp features of this\n  // pass.\n  number_of_tmp_features = copyFeatures(prev_change, tmp_features_);\n\n  const float32 buffer = 30.0f;\n  number_of_tmp_features += seedFeatures(*frame1_->image_,\n      FEATURE_GRID_WIDTH, FEATURE_GRID_HEIGHT,\n      buffer, buffer,\n      (float32) working_size_.width - buffer,\n      (float32) working_size_.height - buffer, FEATURE_DEFAULT,\n      tmp_features_ + number_of_tmp_features);\n  timeLog(\"Seeded features.\");\n\n  const int32 max_num_fast = MAX_TEMP_FEATURES - number_of_tmp_features;\n  number_of_tmp_features +=\n      findFastFeatures(*frame1_->image_, max_num_fast,\n                       tmp_features_ + number_of_tmp_features,\n                       feature_scratch_);\n\n  if (number_of_tmp_features >= MAX_TEMP_FEATURES) {\n    LOGW(\"Hit cap of %d for temporary features!\", number_of_tmp_features);\n  }\n\n  // Score them...\n  scoreFeatures(*frame1_->spatial_x_[0], *frame1_->spatial_y_[0],\n                number_of_tmp_features, tmp_features_);\n\n  timeLog(\"Scored features\");\n\n  // Now pare it down a bit.\n  curr_change->number_of_features_ = sortAndSelect(\n      number_of_tmp_features,\n      MAX_FEATURES,\n      *interest_map_,\n      tmp_features_,\n      curr_change->frame1_features_,\n      feature_scratch_);\n\n  timeLog(\"Sorted and selected features\");\n\n  LOGV(\"Picked %d (%d max) final features out of %d potential.\",\n       curr_change->number_of_features_, MAX_FEATURES, number_of_tmp_features);\n\n  last_time_fresh_features_ = curr_change->end_time;\n}\n\n\nint32 OpticalFlow::copyFeatures(const FramePair& prev_change,\n                                Point2D* const new_features) {\n  int32 number_of_features = 0;\n\n  // Caching values from last pass, just copy and compact.\n  for (int32 i = 0; i < prev_change.number_of_features_; ++i) {\n    if (prev_change.optical_flow_found_feature_[i]) {\n      new_features[number_of_features] =\n          prev_change.frame2_features_[i];\n\n      new_features[number_of_features].score =\n          prev_change.frame1_features_[i].score;\n\n      ++number_of_features;\n    }\n  }\n\n  timeLog(\"Copied features\");\n\n  return number_of_features;\n}\n\n\nvoid OpticalFlow::computeFeatures(const bool cached_ok) {\n  CHECK(frame_added_ && !features_computed_ && !flow_computed_,\n        \"Optical Flow function called out of order!\");\n\n  const FramePair& prev_change = frame_pairs_[geNthIndexFromEnd(1)];\n  FramePair* const curr_change = &frame_pairs_[geNthIndexFromEnd(0)];\n\n  const int32 num_found_features = prev_change.countFoundFeatures();\n  const clock_t ms_since_last_refresh =\n      (curr_change->end_time - last_time_fresh_features_);\n\n  if (cached_ok &&\n      num_found_features >= MIN_FEATURES &&\n      ms_since_last_refresh <= REGEN_FEATURES_MS) {\n    // Reuse the found features from the last frame if we can.\n    curr_change->number_of_features_ =\n        copyFeatures(prev_change, curr_change->frame1_features_);\n  } else {\n    // Only find new features to track if we've lost too many since the last\n    // time, or it's time to regenerate anyway.\n    LOGV(\"Not enough features (%d/%d), or it's been too long (%ld), \"\n         \"finding more.\",\n         num_found_features, MIN_FEATURES, ms_since_last_refresh);\n    findFeatures(prev_change, curr_change);\n  }\n\n  features_computed_ = true;\n}\n\n\nint32 OpticalFlow::getFeatures(const bool only_found,\n                               float32* const out_data) const {\n  CHECK(frame_added_ && features_computed_,\n        \"Optical Flow function called out of order!\");\n\n  int32 curr_feature = 0;\n  const FramePair& change = frame_pairs_[geNthIndexFromEnd(0)];\n\n  for (int32 i = 0; i < change.number_of_features_; ++i) {\n    if (!only_found || change.optical_flow_found_feature_[i]) {\n      const int base = curr_feature * FEATURE_STEP;\n      out_data[base + 0] = change.frame1_features_[i].x * downsample_factor_;\n      out_data[base + 1] = change.frame1_features_[i].y * downsample_factor_;\n      out_data[base + 2] = change.optical_flow_found_feature_[i];\n      out_data[base + 3] = change.frame2_features_[i].x * downsample_factor_;\n      out_data[base + 4] = change.frame2_features_[i].y * downsample_factor_;\n      out_data[base + 5] = change.frame1_features_[i].score;\n      out_data[base + 6] = change.frame1_features_[i].type;\n      ++curr_feature;\n    }\n  }\n\n  LOGV(\"Got %d features.\", curr_feature);\n\n  return curr_feature;\n}\n\n\n// Finds the correspondences for all the points in the current pair of frames.\n// Stores the results in the given FramePair.\nvoid OpticalFlow::findCorrespondences(FramePair* const frame_pair) const {\n  // Features aren't found until they're found.\n  memset(frame_pair->optical_flow_found_feature_, false,\n         sizeof(*frame_pair->optical_flow_found_feature_) * MAX_FEATURES);\n  timeLog(\"Cleared old found features\");\n\n  int32 num_features_found = 0;\n\n  // For every feature...\n  for (int32 i_feat = 0; i_feat < frame_pair->number_of_features_; ++i_feat) {\n    Point2D* feature1 = frame_pair->frame1_features_ + i_feat;\n    Point2D* feature2 = frame_pair->frame2_features_ + i_feat;\n\n    if (findFlowAtPoint(feature1->x, feature1->y,\n                        &feature2->x, &feature2->y)) {\n      frame_pair->optical_flow_found_feature_[i_feat] = true;\n      ++num_features_found;\n    }\n  }\n\n  timeLog(\"Found correspondences\");\n\n  LOGV(\"Found %d of %d feature correspondences\",\n       num_features_found, frame_pair->number_of_features_);\n}\n\n\n// An implementation of the Pyramidal Lucas-Kanade Optical Flow algorithm.\n// See http://robots.stanford.edu/cs223b04/algo_tracking.pdf for details.\nbool OpticalFlow::findFlowAtPoint(const float32 u_x, const float32 u_y,\n                                  float32* final_x, float32* final_y) const {\n  const float32 threshold_squared = square(THRESHOLD);\n\n  // Initial guess.\n  float32 g_x = 0.0f;\n  float32 g_y = 0.0f;\n\n  // For every level in the pyramid, update the coordinates of the best match.\n  for (int32 l = NUM_LEVELS - 1; l >= 0; --l) {\n    // Shrink factor from original.\n    const int32 shrink_factor = (1 << l);\n\n    // Images I (prev) and J (next).\n    const Image<uint8>& img_I = *frame1_->pyramid_[l];\n    const Image<uint8>& img_J = *frame2_->pyramid_[l];\n\n    // Computed gradients.\n    const Image<int32>& I_x = *frame1_->spatial_x_[l];\n    const Image<int32>& I_y = *frame1_->spatial_y_[l];\n\n    // Image position vector (p := u^l), scaled for this level.\n    const float32 p_x = u_x / static_cast<float32>(shrink_factor);\n    const float32 p_y = u_y / static_cast<float32>(shrink_factor);\n\n    // LOGV(\"Level %d: (%d, %d) / %d -> (%d, %d)\",\n    //      l, u_x, u_y, shrink_factor, p_x, p_y);\n\n    // Get values for frame 1.  They remain constant through the inner\n    // iteration loop.\n    float32 vals_I[ARRAY_SIZE];\n    float32 vals_I_x[ARRAY_SIZE];\n    float32 vals_I_y[ARRAY_SIZE];\n\n    int32 val_idx = 0;\n    for (int32 win_x = -WINDOW_SIZE; win_x <= WINDOW_SIZE; ++win_x) {\n      for (int32 win_y = -WINDOW_SIZE; win_y <= WINDOW_SIZE; ++win_y) {\n        const float32 x_pos = p_x + win_x;\n        const float32 y_pos = p_y + win_y;\n\n        if (!img_I.validInterpPixel(x_pos, y_pos)) {\n          return false;\n        }\n\n        vals_I[val_idx] = img_I.getPixelInterp(x_pos, y_pos);\n\n        vals_I_x[val_idx] = I_x.getPixelInterp(x_pos, y_pos);\n        vals_I_y[val_idx] = I_y.getPixelInterp(x_pos, y_pos);\n\n        ++val_idx;\n      }\n    }\n\n    // Compute the spatial gradient matrix about point p.\n    float32 G[] = { 0, 0, 0, 0 };\n    calculateG(vals_I_x, vals_I_y, ARRAY_SIZE, G);\n\n    // Find the inverse of G.\n    float32 G_inv[4];\n    if (!invert2x2(G, G_inv)) {\n      // If we can't invert, hope that the next level will have better luck.\n      continue;\n    }\n\n#ifdef NORMALIZE\n    const float32 mean_I = computeMean(vals_I, ARRAY_SIZE);\n    const float32 std_dev_I = computeStdDev(vals_I, ARRAY_SIZE, mean_I);\n#endif\n\n    // Iterate NUM_ITERATIONS times or until we converge.\n    for (int32 iteration = 0; iteration < NUM_ITERATIONS; ++iteration) {\n      // Get values for frame 2.\n      float32 vals_J[ARRAY_SIZE];\n      int32 val_idx = 0;\n      for (int32 win_x = -WINDOW_SIZE; win_x <= WINDOW_SIZE; ++win_x) {\n        for (int32 win_y = -WINDOW_SIZE; win_y <= WINDOW_SIZE; ++win_y) {\n          const float32 x_pos = p_x + win_x + g_x;\n          const float32 y_pos = p_y + win_y + g_y;\n\n          if (!img_I.validInterpPixel(x_pos, y_pos)) {\n            return false;\n          }\n\n          vals_J[val_idx] = img_J.getPixelInterp(x_pos, y_pos);\n\n          ++val_idx;\n        }\n      }\n\n#ifdef NORMALIZE\n      const float32 mean_J = computeMean(vals_J, ARRAY_SIZE);\n      const float32 std_dev_J = computeStdDev(vals_J, ARRAY_SIZE, mean_J);\n\n      const float32 std_dev_ratio = std_dev_I / std_dev_J;\n#endif\n\n      // Compute image mismatch vector.\n      float32 b_x = 0.0f;\n      float32 b_y = 0.0f;\n      val_idx = 0;\n      for (int32 win_x = -WINDOW_SIZE; win_x <= WINDOW_SIZE; ++win_x) {\n        for (int32 win_y = -WINDOW_SIZE; win_y <= WINDOW_SIZE; ++win_y) {\n          // Normalized Image difference.\n\n#ifdef NORMALIZE\n          const float32 dI = (vals_I[val_idx] - mean_I) -\n                             (vals_J[val_idx] - mean_J) * std_dev_ratio;\n#else\n          const float32 dI = vals_I[val_idx] - vals_J[val_idx];\n#endif\n\n          b_x += dI * vals_I_x[val_idx];\n          b_y += dI * vals_I_y[val_idx];\n\n          ++val_idx;\n        }\n      }\n\n      // Optical flow... solve n = G^-1 * b\n      const float32 n_x = (G_inv[0] * b_x) + (G_inv[1] * b_y);\n      const float32 n_y = (G_inv[2] * b_x) + (G_inv[3] * b_y);\n\n      // Update best guess with residual displacement from this level and\n      // iteration.\n      g_x += n_x;\n      g_y += n_y;\n\n      // LOGV(\"Iteration %d: delta (%.3f, %.3f)\", iteration, n_x, n_y);\n\n      // Abort early if we're already below the threshold.\n      if (square(n_x) + square(n_y) < threshold_squared) {\n        break;\n      }\n    }  // Iteration.\n\n    if (l > 0) {\n      // Every lower level of the pyramid is 2x as large dimensionally.\n      g_x = 2.0f * g_x;\n      g_y = 2.0f * g_y;\n    }\n  }  // Level.\n\n  // LOGV(\"Final displacement for feature %d was (%.2f, %.2f)\",\n  //      iFeat, g_x, g_y);\n\n  *final_x = u_x + g_x;\n  *final_y = u_y + g_y;\n\n  // Assign the best guess, if we're still in the image.\n  if (frame1_->pyramid_[0]->validInterpPixel(*final_x, *final_y)) {\n    return true;\n  } else {\n    return false;\n  }\n}\n\n\nvoid OpticalFlow::addInterestRegion(const int32 num_x, const int32 num_y,\n                                    float32 left, float32 top,\n                                    float32 right, float32 bottom) {\n  left = max(left / downsample_factor_, 0);\n  top = max(top / downsample_factor_, 0);\n  right = min(right / downsample_factor_, working_size_.width - 1);\n  bottom = min(bottom / downsample_factor_, working_size_.height - 1);\n\n  if (left > right || top > bottom) {\n    return;\n  }\n\n  // This is inclusive of the border pixels, hence the +1.\n  const int32 width = right - left + 1;\n\n  // Also inclusive, so it uses a LTE.\n  for (int32 y = top; y <= bottom; ++y) {\n    bool* row_start = interest_map_->getPixelPtr(left, y);\n    memset(row_start, true, width * sizeof(*row_start));\n  }\n}\n\n\nPoint2D OpticalFlow::getAccumulatedDelta(const Point2D& position,\n                                         const float32 radius,\n                                         const clock_t timestamp) const {\n  Point2D curr_pos(position);\n\n  // Scale down to downsampled size.\n  curr_pos.x /= downsample_factor_;\n  curr_pos.y /= downsample_factor_;\n\n  LOGV(\"Tracking accumulated delta from %.2f, %.2f\", curr_pos.x, curr_pos.y);\n\n  const float32 cutoff_dist = radius / downsample_factor_;\n\n  // Anything that ended before the requested timestamp is of no concern to us.\n  bool found_it = false;\n  int32 num_frames_back = -1;\n  for (int32 i = 0; i < num_frames_; ++i) {\n    const FramePair& frame_pair =\n        frame_pairs_[geNthIndexFromEnd(i)];\n\n    if (frame_pair.end_time <= timestamp) {\n      num_frames_back = i - 1;\n\n      if (num_frames_back > 0) {\n        LOGV(\"Went %d out of %d frames before finding frame. (index: %d)\",\n             num_frames_back, num_frames_, geNthIndexFromEnd(i));\n      }\n\n      found_it = true;\n      break;\n    }\n  }\n\n  if (!found_it) {\n    const FramePair& frame_pair = frame_pairs_[geNthIndexFromStart(0)];\n    const FramePair& latest_frame_pair = frame_pairs_[geNthIndexFromEnd(0)];\n\n    clock_t latest_time = latest_frame_pair.end_time;\n\n    LOGW(\"History did not go back far enough! %ld vs %ld\",\n         latest_time - frame_pair.end_time,\n         latest_time - timestamp);\n  }\n\n  // Loop over all the frames in the queue, tracking the accumulated delta\n  // of the point from frame to frame.  It's possible the point could\n  // go out of frame, but keep tracking as best we can, using points near\n  // the edge of the screen where it went out of bounds.\n  for (int32 i = num_frames_back; i >= 0; --i) {\n    const FramePair& frame_pair = frame_pairs_[geNthIndexFromEnd(i)];\n    CHECK(frame_pair.end_time >= timestamp, \"Frame timestamp was too early!\");\n\n    const Point2D delta = frame_pair.queryFlow(curr_pos, cutoff_dist);\n    curr_pos.x += delta.x;\n    curr_pos.y += delta.y;\n  }\n\n  // Scale back to original size.\n  curr_pos.x *= downsample_factor_;\n  curr_pos.y *= downsample_factor_;\n\n  // Return the delta only.\n  return curr_pos - position;\n}\n\n\nvoid FramePair::init(const clock_t end_time) {\n  this->end_time = end_time;\n  memset(optical_flow_found_feature_, false,\n         sizeof(*optical_flow_found_feature_) * MAX_FEATURES);\n  number_of_features_ = 0;\n}\n\n\nPoint2D FramePair::queryFlow(\n    const Point2D& initial, const float32 cutoff_dist) const {\n  float32 weights[MAX_FEATURES];\n  memset(weights, 0, sizeof(float32) * MAX_FEATURES);\n\n  // Compute the max score.\n  float32 max_score = 0.0f;\n  for (int32 i = 0; i < MAX_FEATURES; ++i) {\n    if (optical_flow_found_feature_[i]) {\n      max_score = max(max_score, frame1_features_[i].score);\n    }\n  }\n\n  const float32 cutoff_dist_squared = cutoff_dist * cutoff_dist;\n  for (int32 i = 0; i < MAX_FEATURES; ++i) {\n    if (optical_flow_found_feature_[i]) {\n      const float32 sq_x_dist = square(initial.x - frame1_features_[i].x);\n      const float32 sq_y_dist = square(initial.y - frame1_features_[i].y);\n\n      const float32 dist_squared = sq_x_dist + sq_y_dist;\n\n      // The weighting based off distance.  Anything within the cuttoff\n      // distance has a weight of 1, and everything outside of that is within\n      // the range [0, 1).\n      const float32 distance_score =\n          min(cutoff_dist_squared / dist_squared, 1.0f);\n\n      // The weighting based on score strength. 0.5f - 1.0f.\n      float32 intrinsic_score = 1.0f;\n      if (max_score > 0) {\n        intrinsic_score = (frame1_features_[i].score / max_score) / 2.0f;\n      }\n\n      // The final score will be in the range [0, 1].\n      weights[i] = distance_score * intrinsic_score;\n    }\n  }\n\n  return getWeightedDelta(weights);\n}\n\n\nPoint2D FramePair::getWeightedDelta(const float32* const weights) const {\n  float32 total_weight = 0.0f;\n  float32 weighted_sum_x = 0.0f;\n  float32 weighted_sum_y = 0.0f;\n\n  Point2D deltas[MAX_FEATURES];\n\n  // Compute weighted mean and deltas.\n  for (int32 i = 0; i < MAX_FEATURES; ++i) {\n    const float32 weight = weights[i];\n    if (weight > 0.0f) {\n      deltas[i] = frame2_features_[i] - frame1_features_[i];\n      weighted_sum_x += deltas[i].x * weight;\n      weighted_sum_y += deltas[i].y * weight;\n      total_weight += weight;\n    }\n  }\n  const float32 weighted_mean_x = weighted_sum_x / total_weight;\n  const float32 weighted_mean_y = weighted_sum_y / total_weight;\n\n  // Compute weighted squared standard deviation from weighted mean.\n  float32 weighted_dev_squared_sum = 0.0f;\n  for (int32 i = 0; i < MAX_FEATURES; ++i) {\n    const float32 weight = weights[i];\n\n    if (weight > 0.0f) {\n      const float32 devX = deltas[i].x - weighted_mean_x;\n      const float32 devY = deltas[i].y - weighted_mean_y;\n\n      const float32 squared_deviation = (devX * devX) + (devY * devY);\n      weighted_dev_squared_sum += squared_deviation * weight;\n    }\n  }\n  const float32 weighted_std_dev_squared =\n      weighted_dev_squared_sum / total_weight;\n\n  // Recompute weighted mean change without outliers.\n  float32 good_weight = 0.0f;\n  float32 good_sum_x = 0.0f;\n  float32 good_sum_y = 0.0f;\n\n  for (int32 i = 0; i < MAX_FEATURES; ++i) {\n    const float32 weight = weights[i];\n\n    if (weight > 0.0f) {\n      const float32 dev_x = deltas[i].x - weighted_mean_x;\n      const float32 dev_y = deltas[i].y - weighted_mean_y;\n\n      const float32 sqrd_deviation = (dev_x * dev_x) + (dev_y * dev_y);\n\n      // Throw out anything beyond NUM_DEVIATIONS.\n      if (sqrd_deviation <= NUM_DEVIATIONS * weighted_std_dev_squared) {\n        good_sum_x += deltas[i].x * weight;\n        good_sum_y += deltas[i].y * weight;\n        good_weight += weight;\n      }\n    }\n  }\n\n  if (good_weight > 0.0f) {\n    return Point2D(good_sum_x / good_weight, good_sum_y / good_weight);\n  } else {\n    return Point2D(0.0f, 0.0f);\n  }\n}\n\n}  // namespace flow\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/optical_flow.h",
    "content": "// Copyright 2009 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_H_\n\n#include \"types.h\"\n#include \"utils.h\"\n\n// Feature detection.\n#define MAX_TEMP_FEATURES 4096\n#define MAX_FEATURES 128\n\n// Number of floats each feature takes up when exporting to an array.\n#define FEATURE_STEP 7\n\n// Number of frame deltas to keep around in the circular queue.\n#define NUM_FRAMES 128\n\n// Redetect if we ever have less than this number of features.\n#define MIN_FEATURES 6\n\n// How long to wait between forcing complete feature regeneration.\n#define REGEN_FEATURES_MS 400\n\n// Number of iterations to do tracking on each feature at each pyramid level.\n#define NUM_ITERATIONS 3\n\n// Number of pyramid levels used for tracking.\n#define NUM_LEVELS 4\n\n// Window size to integrate over to find local image derivative.\n#define WINDOW_SIZE 3\n\n// Total area of integration windows.\n#define ARRAY_SIZE (2 * WINDOW_SIZE + 1) * (2 * WINDOW_SIZE + 1)\n\n// Error that's considered good enough to early abort tracking.\n#define THRESHOLD 0.03f\n\n// Maximum number of deviations a feature delta can be from the weighted\n// average before being thrown out for region-based queries.\n#define NUM_DEVIATIONS 2.0f\n\n// Resolution of feature grid to seed features with.\n#define FEATURE_GRID_WIDTH 4\n#define FEATURE_GRID_HEIGHT 3\n\n// Whether to normalize feature windows for intensity.\n#define NORMALIZE\n\nnamespace flow {\n\ntemplate <typename T>\nclass Image;\n\n// Class that encapsulates all bulky processed data for a frame.\nclass ImageData {\n public:\n  explicit ImageData(Size size) {\n    timestamp_ = 0;\n\n    image_ = new Image<uint8>(size);\n\n    for (int32 i = 0; i < NUM_LEVELS; ++i) {\n      pyramid_[i] = (i == 0) ? image_ : new Image<uint8>(size);\n\n      spatial_x_[i] = new Image<int32>(size);\n      spatial_y_[i] = new Image<int32>(size);\n\n      size.width /= 2;\n      size.height /= 2;\n    }\n  }\n\n  ~ImageData() {\n    // image_ will be deleted along with the rest of the pyramids.\n\n    for (int32 i = 0; i < NUM_LEVELS; ++i) {\n      SAFE_DELETE(pyramid_[i]);\n      SAFE_DELETE(spatial_x_[i]);\n      SAFE_DELETE(spatial_y_[i]);\n    }\n  }\n\n  void init(const uint8* const new_frame, const int32 stride,\n            const clock_t timestamp, const int32 downsample_factor_) {\n    timestamp_ = timestamp;\n\n    image_->fromArray(new_frame, stride, downsample_factor_);\n    timeLog(\"Downsampled image\");\n\n    // Create the smoothed pyramids.\n    computeSmoothedPyramid(*image_, NUM_LEVELS, pyramid_);\n    timeLog(\"Created smoothed pyramids\");\n\n    // Create the spatial derivatives for frame 1.\n    computeSpatialPyramid((const Image<uint8>**)pyramid_,\n                          NUM_LEVELS, spatial_x_, spatial_y_);\n    timeLog(\"Created spatial derivatives\");\n  }\n\n  clock_t timestamp_;\n  Image<uint8>* image_;\n  Image<uint8>* pyramid_[NUM_LEVELS];\n  Image<int32>* spatial_x_[NUM_LEVELS];\n  Image<int32>* spatial_y_[NUM_LEVELS];\n};\n\n// A class that records a timestamped frame features\n// translation delta for optical flow.\nclass FramePair {\n public:\n  // Cleans up the FramePair so that they can be reused.\n  void init(const clock_t end_time);\n\n  // Throws out outliers based on the input weighting.\n  Point2D getWeightedDelta(const float32* const weights) const;\n\n  // Weights points based on the query_point and cutoff_dist, then\n  // returns getWeightedDelta.  Essentially tells you where a point at the\n  // beginning of a frame ends up.\n  Point2D queryFlow(const Point2D& query_point,\n                    const float32 cutoff_dist) const;\n\n  // Just count up and return the number of features from the first frame that\n  // were found in the second frame.\n  inline int32 countFoundFeatures() const {\n    int32 num_found_features = 0;\n    for (int32 i = 0; i < number_of_features_; ++i) {\n      if (optical_flow_found_feature_[i]) {\n        ++num_found_features;\n      }\n    }\n    return num_found_features;\n  }\n\n  // The time at frame2.\n  clock_t end_time;\n\n  // This array will contain the features found in frame 1.\n  Point2D frame1_features_[MAX_FEATURES];\n\n  // Contain the locations of the points from frame 1 in frame 2.\n  Point2D frame2_features_[MAX_FEATURES];\n\n  // The number of features in frame 1.\n  int32 number_of_features_;\n\n  // Keeps track of which features were actually found from one frame\n  // another.\n  // The i-th element of this array will be non-zero if and only if the i-th\n  // feature of frame 1 was found in frame 2.\n  bool optical_flow_found_feature_[MAX_FEATURES];\n};\n\n// Class encapsulating all the data and logic necessary for performing optical\n// flow.  The general order of operations on a per frame basis is:\n//\n// // Notify optical flow that a new frame is available.\n// nextFrame(...);\n//\n// // Tell it any regions we want it to pay special attention to.\n// addInterestRegion(...);\n//\n// // Have it compute the flow.\n// computeFlow();\n//\n// // Look up the delta from a given point at a given time to the current time.\n// getAccumulatedDelta(...);\nclass OpticalFlow {\n public:\n  OpticalFlow(const int32 frame_width, const int32 frame_height,\n              const int32 downsample_factor);\n  ~OpticalFlow();\n\n  // Add a new frame to the optical flow.  Will update all the non-feature\n  // related member variables.\n  //\n  // new_frame should be a buffer of grayscale values, one byte per pixel,\n  // at the original frame_width and frame_height used to initialize the\n  // OpticalFlow object.  Downsampling will be handled internally.\n  //\n  // time_stamp should be a time in milliseconds that later calls to this and\n  // other methods will be relative to.\n  void nextFrame(const uint8* const new_frame, const clock_t timestamp);\n\n  // Find the features in the frame before the current frame.\n  // If only one frame exists, features will be found in that frame.\n  void computeFeatures(const bool cached_ok = false);\n\n  // Process the most recent two frames, and fill in the feature arrays.\n  void computeFlow();\n\n  // Copy the feature arrays after computeFlow is called.\n  // out_data should be at least MAX_FEATURES * FEATURE_STEP long.\n  // Currently, its format is [x1 y1 found x2 y2 score] repeated N times,\n  // where N is the number of features tracked.  N is returned as the result.\n  int32 getFeatures(const bool only_found, float32* const out_data) const;\n\n  // Tells you the overall flow for region of a given radius at a given time to\n  // the present.\n  Point2D getAccumulatedDelta(const Point2D& position,\n                              const float radius,\n                              const clock_t timestamp) const;\n\n  // Pay special attention to the area inside this box on the next\n  // optical flow pass.\n  void addInterestRegion(const int32 num_x, const int32 num_y,\n                         float32 left, float32 top,\n                         float32 right, float32 bottom);\n\n  // Finds the correspondences for all the points in the current pair of frames.\n  // Stores the results in the given FramePair.\n  void findCorrespondences(FramePair* const curr_change) const;\n\n  // An implementation of the Pyramidal Lucas-Kanade Optical Flow algorithm.\n  bool findFlowAtPoint(const float32 u_x, const float32 u_y,\n                       float32* final_x, float32* final_y) const;\n\n  void printInfo() const {\n#ifdef VERBOSE_LOGGING\n    const int32 first_frame_index = geNthIndexFromStart(0);\n    const FramePair& first_frame_pair = frame_pairs_[first_frame_index];\n\n    const int32 last_frame_index = geNthIndexFromEnd(0);\n    const FramePair& last_frame_pair = frame_pairs_[last_frame_index];\n\n    LOGV  (\"Queue size: %d, last/first: %4d %4d: %8ld - %8ld = %8ld\",\n         num_frames_, last_frame_index, first_frame_index,\n         last_frame_pair.end_time, first_frame_pair.end_time,\n         last_frame_pair.end_time - first_frame_pair.end_time);\n#endif\n  }\n\n private:\n  inline int32 geNthIndexFromStart(const int32 offset) const {\n    CHECK(offset >= 0 && offset < num_frames_,\n          \"Offset out of range!  %d out of %d.\", offset, num_frames_);\n    return (first_frame_index_ + offset) % NUM_FRAMES;\n  }\n\n  inline int32 geNthIndexFromEnd(const int32 offset) const {\n    return geNthIndexFromStart(num_frames_ - 1 - offset);\n  }\n\n  // Finds features in the previous frame and adds them to curr_change.\n  void findFeatures(const FramePair& prev_change,\n                    FramePair* const curr_change);\n\n  // Copies and compacts the found features in the second frame of prev_change\n  // into the array at new_features.\n  static int32 copyFeatures(const FramePair& prev_change,\n                            Point2D* const new_features);\n\n  const int32 downsample_factor_;\n\n  // Size of the original images.\n  const Size original_size_;\n\n  // Size of the internally allocated images (after original is downsampled).\n  const Size working_size_;\n\n  int32 first_frame_index_;\n  int32 num_frames_;\n\n  clock_t last_time_fresh_features_;\n\n  Point2D tmp_features_[MAX_TEMP_FEATURES];\n\n  FramePair frame_pairs_[NUM_FRAMES];\n\n  // Scratch memory for feature candidacy detection and non-max suppression.\n  Image<uint8>* feature_scratch_;\n\n  // Regions of the image to pay special attention to.\n  Image<bool>* interest_map_;\n\n  ImageData* frame1_;\n  ImageData* frame2_;\n\n  bool frame_added_;\n  bool features_computed_;\n  bool flow_computed_;\n};\n\n}  // namespace flow\n#endif  // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_H_\n"
  },
  {
    "path": "eyes-two/src/main/jni/opticalflow/optical_flow_utils.h",
    "content": "// Copyright 2010 Google Inc. All Rights Reserved.\n// Author: andrewharp@google.com (Andrew Harp)\n\n#ifndef JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_UTILS_H_\n#define JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_UTILS_H_\n\n#include \"utils.h\"\n#include <cmath>\n\nnamespace flow {\n\n// Arbitrary feature type ids for labeling the origin of tracked features.\n#define FEATURE_DEFAULT 0\n#define FEATURE_FAST 1\n#define FEATURE_INTEREST 2\n\n#define EPSILON 0.0000001f\n\nclass Size {\n public:\n  int32 width;\n  int32 height;\n\n  Size(const int32 width, const int32 height) : width(width), height(height) {}\n};\n\n// For keeping track of features.\nclass Point2D {\n public:\n  float32 x;\n  float32 y;\n  float32 score;\n  uint8 type;\n\n  Point2D() : x(0.0f), y(0.0f), score(0.0f), type(0) {}\n  Point2D(const float32 x, const float32 y) :\n    x(x), y(y), score(0.0f), type(0) {}\n\n  // The following operators all compare the computed score of the feature for\n  // sorting purposes.\n  // TODO(andrewharp): Use the qsort function in stdlib.\n  inline bool operator< (const Point2D& that) const {\n    return this->score < that.score;\n  }\n\n  inline bool operator<= (const Point2D& that) const {\n    return this->score <= that.score;\n  }\n\n  inline bool operator> (const Point2D& that) const {\n    return this->score > that.score;\n  }\n\n  inline Point2D operator- (const Point2D& that) const {\n    return Point2D(this->x - that.x, this->y - that.y);\n  }\n};\n\n// Returns the determinant of a 2x2 matrix.\ninline float findDeterminant2x2(const float32* const a) {\n  // Determinant: (ad - bc)\n  return a[0] * a[3] - a[1] * a[2];\n}\n\n// Finds the inverse of a 2x2 matrix.\n// Returns true upon success, false if the matrix is not invertible.\ninline bool invert2x2(const float32* const a, float32* const a_inv) {\n  const float det = findDeterminant2x2(a);\n  if (std::fabs(det) < EPSILON) {\n    return false;\n  }\n  const float32 inv_det = 1.0f / static_cast<float32>(det);\n\n  a_inv[0] = inv_det * a[3];  // d\n  a_inv[1] = inv_det * -a[1];  // -b\n  a_inv[2] = inv_det * -a[2];  // -c\n  a_inv[3] = inv_det * a[0];  // a\n\n  return true;\n}\n\n// TODO(andrewharp): Accelerate with NEON.\ninline float32 computeMean(const float32* const values,\n                           const int32 num_vals) {\n  // Get mean.\n  float32 sum = 0.0f;\n  for (int32 i = 0; i < num_vals; ++i) {\n    sum += values[i];\n  }\n  return sum / static_cast<float32>(num_vals);\n}\n\n// TODO(andrewharp): Accelerate with NEON.\ninline float32 computeStdDev(const float32* const values,\n                             const int32 num_vals,\n                             const float32 mean) {\n  // Get Std dev.\n  float32 squared_sum = 0.0f;\n  for (int32 i = 0; i < num_vals; ++i) {\n    squared_sum += square(values[i] - mean);\n  }\n  return sqrt(squared_sum / static_cast<float32>(num_vals));\n}\n\n// TODO(andrewharp): Accelerate with NEON.\ninline float32 computeWeightedMean(const float32* const values,\n                                   const float32* const weights,\n                                   const int32 num_vals) {\n  float32 sum = 0.0f;\n  float32 total_weight = 0.0f;\n  for (int32 i = 0; i < num_vals; ++i) {\n    sum += values[i] * weights[i];\n    total_weight += weights[i];\n  }\n  return sum / num_vals;\n}\n\n// Partitioning phase of quicksort.\ntemplate<typename T>\ninline int32 partition(T* const arr_start,\n                       const int32 num_elems, const T pivot) {\n  int32 i = 0;\n  int32 j = num_elems - 1;\n\n  // Put everything <= pivot on the left, and everything > pivot to the right.\n  while (true) {\n    while (arr_start[i] <= pivot && (i < j)) {\n      ++i;\n    }\n\n    while (arr_start[j] > pivot && (i < j)) {\n      --j;\n    }\n\n    // Termination condition.\n    if (i >= j) {\n      break;\n    }\n\n    swap(arr_start + i, arr_start + j);\n    ++i;\n    --j;\n  }\n\n  int32 part_size;\n  for (part_size = 0; part_size < num_elems; ++part_size) {\n    if (arr_start[part_size] > pivot) {\n      break;\n    }\n  }\n  return part_size;\n}\n\n// Just your basic quicksort implementation.\n// Sorts an array of size num_elems inplace by the score field of the elements.\ntemplate<typename T>\nvoid qsort(T* const arr_start, const int32 num_elems) {\n  // No point in sorting a list of size 1 or 0!\n  if (num_elems <= 1) {\n    return;\n  }\n\n  // Check to see if we're already sorted...\n  bool sorted = true;\n  T last_score = arr_start[0];\n  for (int32 i = 1; i < num_elems; ++i) {\n    const T curr_score = arr_start[i];\n    if (last_score > curr_score) {\n      sorted = false;\n      break;\n    }\n    last_score = curr_score;\n  }\n  if (sorted) {\n    return;\n  }\n\n  // Select partition element randomly.\n  const int32 sort_ind = rand() % num_elems;\n  const T pivot = arr_start[sort_ind];\n\n  const int32 first_part_size = partition(arr_start, num_elems, pivot);\n  const int32 second_part_size = num_elems - first_part_size;\n\n  qsort(arr_start, first_part_size);\n  qsort(arr_start + first_part_size, second_part_size);\n}\n\n}  // namespace flow\n\n#endif // JAVA_COM_GOOGLE_ANDROID_APPS_UNVEIL_JNI_OPTICALFLOW_OPTICAL_FLOW_UTILS_H_\n"
  },
  {
    "path": "gradle/wrapper/gradle-wrapper.properties",
    "content": "#Mon Dec 28 12:31:23 IST 2020\ndistributionBase=GRADLE_USER_HOME\ndistributionPath=wrapper/dists\nzipStoreBase=GRADLE_USER_HOME\nzipStorePath=wrapper/dists\ndistributionUrl=https\\://services.gradle.org/distributions/gradle-6.7.1-bin.zip\n"
  },
  {
    "path": "gradle.properties",
    "content": "## For more details on how to configure your build environment visit\n# http://www.gradle.org/docs/current/userguide/build_environment.html\n#\n# Specifies the JVM arguments used for the daemon process.\n# The setting is particularly useful for tweaking memory settings.\n# Default value: -Xmx1024m -XX:MaxPermSize=256m\n# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8\n#\n# When configured, Gradle will run in incubating parallel mode.\n# This option should only be used with decoupled projects. More details, visit\n# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects\n# org.gradle.parallel=true\n#Mon Dec 28 14:15:43 IST 2020\nandroid.enableJetifier=true\nandroid.useAndroidX=true\norg.gradle.jvmargs=-Xmx2048M\n"
  },
  {
    "path": "gradlew",
    "content": "#!/usr/bin/env bash\n\n##############################################################################\n##\n##  Gradle start up script for UN*X\n##\n##############################################################################\n\n# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nDEFAULT_JVM_OPTS=\"\"\n\nAPP_NAME=\"Gradle\"\nAPP_BASE_NAME=`basename \"$0\"`\n\n# Use the maximum available, or set MAX_FD != -1 to use that value.\nMAX_FD=\"maximum\"\n\nwarn ( ) {\n    echo \"$*\"\n}\n\ndie ( ) {\n    echo\n    echo \"$*\"\n    echo\n    exit 1\n}\n\n# OS specific support (must be 'true' or 'false').\ncygwin=false\nmsys=false\ndarwin=false\ncase \"`uname`\" in\n  CYGWIN* )\n    cygwin=true\n    ;;\n  Darwin* )\n    darwin=true\n    ;;\n  MINGW* )\n    msys=true\n    ;;\nesac\n\n# For Cygwin, ensure paths are in UNIX format before anything is touched.\nif $cygwin ; then\n    [ -n \"$JAVA_HOME\" ] && JAVA_HOME=`cygpath --unix \"$JAVA_HOME\"`\nfi\n\n# Attempt to set APP_HOME\n# Resolve links: $0 may be a link\nPRG=\"$0\"\n# Need this for relative symlinks.\nwhile [ -h \"$PRG\" ] ; do\n    ls=`ls -ld \"$PRG\"`\n    link=`expr \"$ls\" : '.*-> \\(.*\\)$'`\n    if expr \"$link\" : '/.*' > /dev/null; then\n        PRG=\"$link\"\n    else\n        PRG=`dirname \"$PRG\"`\"/$link\"\n    fi\ndone\nSAVED=\"`pwd`\"\ncd \"`dirname \\\"$PRG\\\"`/\" >&-\nAPP_HOME=\"`pwd -P`\"\ncd \"$SAVED\" >&-\n\nCLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar\n\n# Determine the Java command to use to start the JVM.\nif [ -n \"$JAVA_HOME\" ] ; then\n    if [ -x \"$JAVA_HOME/jre/sh/java\" ] ; then\n        # IBM's JDK on AIX uses strange locations for the executables\n        JAVACMD=\"$JAVA_HOME/jre/sh/java\"\n    else\n        JAVACMD=\"$JAVA_HOME/bin/java\"\n    fi\n    if [ ! -x \"$JAVACMD\" ] ; then\n        die \"ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\n    fi\nelse\n    JAVACMD=\"java\"\n    which java >/dev/null 2>&1 || die \"ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\n\nPlease set the JAVA_HOME variable in your environment to match the\nlocation of your Java installation.\"\nfi\n\n# Increase the maximum file descriptors if we can.\nif [ \"$cygwin\" = \"false\" -a \"$darwin\" = \"false\" ] ; then\n    MAX_FD_LIMIT=`ulimit -H -n`\n    if [ $? -eq 0 ] ; then\n        if [ \"$MAX_FD\" = \"maximum\" -o \"$MAX_FD\" = \"max\" ] ; then\n            MAX_FD=\"$MAX_FD_LIMIT\"\n        fi\n        ulimit -n $MAX_FD\n        if [ $? -ne 0 ] ; then\n            warn \"Could not set maximum file descriptor limit: $MAX_FD\"\n        fi\n    else\n        warn \"Could not query maximum file descriptor limit: $MAX_FD_LIMIT\"\n    fi\nfi\n\n# For Darwin, add options to specify how the application appears in the dock\nif $darwin; then\n    GRADLE_OPTS=\"$GRADLE_OPTS \\\"-Xdock:name=$APP_NAME\\\" \\\"-Xdock:icon=$APP_HOME/media/gradle.icns\\\"\"\nfi\n\n# For Cygwin, switch paths to Windows format before running java\nif $cygwin ; then\n    APP_HOME=`cygpath --path --mixed \"$APP_HOME\"`\n    CLASSPATH=`cygpath --path --mixed \"$CLASSPATH\"`\n\n    # We build the pattern for arguments to be converted via cygpath\n    ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`\n    SEP=\"\"\n    for dir in $ROOTDIRSRAW ; do\n        ROOTDIRS=\"$ROOTDIRS$SEP$dir\"\n        SEP=\"|\"\n    done\n    OURCYGPATTERN=\"(^($ROOTDIRS))\"\n    # Add a user-defined pattern to the cygpath arguments\n    if [ \"$GRADLE_CYGPATTERN\" != \"\" ] ; then\n        OURCYGPATTERN=\"$OURCYGPATTERN|($GRADLE_CYGPATTERN)\"\n    fi\n    # Now convert the arguments - kludge to limit ourselves to /bin/sh\n    i=0\n    for arg in \"$@\" ; do\n        CHECK=`echo \"$arg\"|egrep -c \"$OURCYGPATTERN\" -`\n        CHECK2=`echo \"$arg\"|egrep -c \"^-\"`                                 ### Determine if an option\n\n        if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then                    ### Added a condition\n            eval `echo args$i`=`cygpath --path --ignore --mixed \"$arg\"`\n        else\n            eval `echo args$i`=\"\\\"$arg\\\"\"\n        fi\n        i=$((i+1))\n    done\n    case $i in\n        (0) set -- ;;\n        (1) set -- \"$args0\" ;;\n        (2) set -- \"$args0\" \"$args1\" ;;\n        (3) set -- \"$args0\" \"$args1\" \"$args2\" ;;\n        (4) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" ;;\n        (5) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" ;;\n        (6) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" ;;\n        (7) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" ;;\n        (8) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" ;;\n        (9) set -- \"$args0\" \"$args1\" \"$args2\" \"$args3\" \"$args4\" \"$args5\" \"$args6\" \"$args7\" \"$args8\" ;;\n    esac\nfi\n\n# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules\nfunction splitJvmOpts() {\n    JVM_OPTS=(\"$@\")\n}\neval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS\nJVM_OPTS[${#JVM_OPTS[*]}]=\"-Dorg.gradle.appname=$APP_BASE_NAME\"\n\nexec \"$JAVACMD\" \"${JVM_OPTS[@]}\" -classpath \"$CLASSPATH\" org.gradle.wrapper.GradleWrapperMain \"$@\"\n"
  },
  {
    "path": "gradlew.bat",
    "content": "@if \"%DEBUG%\" == \"\" @echo off\n@rem ##########################################################################\n@rem\n@rem  Gradle startup script for Windows\n@rem\n@rem ##########################################################################\n\n@rem Set local scope for the variables with windows NT shell\nif \"%OS%\"==\"Windows_NT\" setlocal\n\n@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.\nset DEFAULT_JVM_OPTS=\n\nset DIRNAME=%~dp0\nif \"%DIRNAME%\" == \"\" set DIRNAME=.\nset APP_BASE_NAME=%~n0\nset APP_HOME=%DIRNAME%\n\n@rem Find java.exe\nif defined JAVA_HOME goto findJavaFromJavaHome\n\nset JAVA_EXE=java.exe\n%JAVA_EXE% -version >NUL 2>&1\nif \"%ERRORLEVEL%\" == \"0\" goto init\n\necho.\necho ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:findJavaFromJavaHome\nset JAVA_HOME=%JAVA_HOME:\"=%\nset JAVA_EXE=%JAVA_HOME%/bin/java.exe\n\nif exist \"%JAVA_EXE%\" goto init\n\necho.\necho ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%\necho.\necho Please set the JAVA_HOME variable in your environment to match the\necho location of your Java installation.\n\ngoto fail\n\n:init\n@rem Get command-line arguments, handling Windowz variants\n\nif not \"%OS%\" == \"Windows_NT\" goto win9xME_args\nif \"%@eval[2+2]\" == \"4\" goto 4NT_args\n\n:win9xME_args\n@rem Slurp the command line arguments.\nset CMD_LINE_ARGS=\nset _SKIP=2\n\n:win9xME_args_slurp\nif \"x%~1\" == \"x\" goto execute\n\nset CMD_LINE_ARGS=%*\ngoto execute\n\n:4NT_args\n@rem Get arguments from the 4NT Shell from JP Software\nset CMD_LINE_ARGS=%$\n\n:execute\n@rem Setup the command line\n\nset CLASSPATH=%APP_HOME%\\gradle\\wrapper\\gradle-wrapper.jar\n\n@rem Execute Gradle\n\"%JAVA_EXE%\" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% \"-Dorg.gradle.appname=%APP_BASE_NAME%\" -classpath \"%CLASSPATH%\" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%\n\n:end\n@rem End local scope for the variables with windows NT shell\nif \"%ERRORLEVEL%\"==\"0\" goto mainEnd\n\n:fail\nrem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of\nrem the _cmd.exe /c_ return code!\nif  not \"\" == \"%GRADLE_EXIT_CONSOLE%\" exit 1\nexit /b 1\n\n:mainEnd\nif \"%OS%\"==\"Windows_NT\" endlocal\n\n:omega\n"
  },
  {
    "path": "preparetests.cmd",
    "content": "for /f %%i in ('adb shell echo $EXTERNAL_STORAGE') do set DIR=%%i\n\ngit clone -b 3.04.00 https://github.com/tesseract-ocr/tessdata.git\n\nadb shell rm %DIR%/testAddPageToDocument.pdf\nadb shell rm %DIR%/testCreate.pdf\n\nadb uninstall com.googlecode.tesseract.android.test\n\nadb shell mkdir %DIR%/tessdata\n\nadb push -p tessdata/eng.cube.bigrams %DIR%/tessdata\nadb push -p tessdata/eng.cube.fold %DIR%/tessdata\nadb push -p tessdata/eng.cube.lm %DIR%/tessdata\nadb push -p tessdata/eng.cube.nn %DIR%/tessdata\nadb push -p tessdata/eng.cube.params %DIR%/tessdata\nadb push -p tessdata/eng.cube.size %DIR%/tessdata\nadb push -p tessdata/eng.cube.word-freq %DIR%/tessdata\nadb push -p tessdata/eng.tesseract_cube.nn %DIR%/tessdata\nadb push -p tessdata/eng.traineddata %DIR%/tessdata\nadb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf %DIR%/tessdata\n"
  },
  {
    "path": "preparetests.sh",
    "content": "#!/bin/sh\n\nDIR=\"`adb shell echo \\\\$EXTERNAL_STORAGE`\"\n\ngit clone -b 3.04.00 https://github.com/tesseract-ocr/tessdata.git\n\nadb shell rm $DIR/testAddPageToDocument.pdf\nadb shell rm $DIR/testCreate.pdf\n\nadb uninstall com.googlecode.tesseract.android.test\n\nadb shell mkdir $DIR/tessdata\n \nfor f in tessdata/eng.*; do\n    TRAINEDDATA_FILENAME=\"$DIR/tessdata/`basename $f`\"\n\n    if [ `adb shell \"if [ -f $TRAINEDDATA_FILENAME ]; then echo 1; fi\"` ]; then\n        echo \"$TRAINEDDATA_FILENAME already present on device\"\n        continue\n    fi \n    \n    echo \"Copying $f to device...\";\n    adb push -p $f $DIR/tessdata\ndone\n\nadb push -p tess-two/jni/com_googlecode_tesseract_android/src/tessdata/pdf.ttf $DIR/tessdata\n\n# adb shell am instrument -w com.googlecode.tesseract.android.test/android.test.InstrumentationTestRunner\n"
  },
  {
    "path": "settings.gradle",
    "content": "include ':eyes-two'\ninclude ':tess-two'\ninclude ':tess-two-test'\nrootProject.name = 'tess-two.project'\n"
  },
  {
    "path": "tess-two/.classpath",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry kind=\"con\" path=\"com.android.ide.eclipse.adt.ANDROID_FRAMEWORK\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.LIBRARIES\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.DEPENDENCIES\"/>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"src\" path=\"gen\"/>\n\t<classpathentry kind=\"output\" path=\"bin/classes\"/>\n</classpath>\n"
  },
  {
    "path": "tess-two/.gitignore",
    "content": "/obj\n/gen\n/libs\n/jni/com_googlecode_tesseract_android/src/config/**\n/jni/com_googlecode_tesseract_android/src/m4/**\n/jni/com_googlecode_tesseract_android/src/vs2008/**\n/jni/com_googlecode_tesseract_android/src/vs2010/**\n"
  },
  {
    "path": "tess-two/.project",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>tess-two</name>\n\t<comment></comment>\n\t<projects>\n\t</projects>\n\t<buildSpec>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ApkBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t</buildSpec>\n\t<natures>\n\t\t<nature>com.android.ide.eclipse.adt.AndroidNature</nature>\n\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n\t</natures>\n</projectDescription>\n"
  },
  {
    "path": "tess-two/AndroidManifest.xml",
    "content": "<!--\n Copyright (C) 2011 Google Inc.\n\n     Licensed under the Apache License, Version 2.0 (the \"License\");\n     you may not use this file except in compliance with the License.\n     You may obtain a copy of the License at\n\n          http://www.apache.org/licenses/LICENSE-2.0\n\n     Unless required by applicable law or agreed to in writing, software\n     distributed under the License is distributed on an \"AS IS\" BASIS,\n     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n     See the License for the specific language governing permissions and\n     limitations under the License.\n-->\n\n<manifest package=\"com.googlecode.tesseract.android\">\n\n</manifest>\n"
  },
  {
    "path": "tess-two/COPYING",
    "content": "\n                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"[]\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright [yyyy] [name of copyright owner]\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "tess-two/build.gradle",
    "content": "apply plugin: 'com.android.library'\napply plugin: 'com.github.dcendents.android-maven'\napply plugin: 'com.jfrog.bintray'\n\nProperties properties = new Properties()\nproperties.load(rootProject.file('local.properties').newDataInputStream())\n\nandroid {\n    compileSdkVersion 30\n\n    defaultConfig {\n        minSdkVersion 16\n        targetSdkVersion 30\n        versionCode 1\n        versionName '1.0'\n        consumerProguardFiles 'proguard-rules.pro'\n    }\n\n    sourceSets {\n        main {\n            manifest.srcFile 'AndroidManifest.xml'\n            java.srcDirs = ['src']\n            res.srcDirs = ['res']\n        }\n    }\n\n    externalNativeBuild {\n        ndkBuild {\n            path \"jni/Android.mk\"\n        }\n    }\n}\n\ndependencies {\n    implementation \"androidx.annotation:annotation:1.1.0\"\n}\n\n\n// Settings for uploading module AAR to Bintray for library distribution\n\ntask sourcesJar(type: Jar) {\n    from android.sourceSets.main.java.srcDirs\n    classifier = 'sources'\n}\n\ntask javadoc(type: Javadoc) {\n    failOnError = false\n    source = android.sourceSets.main.java.srcDirs\n    classpath += project.files(android.getBootClasspath().join(File.pathSeparator))\n    options {\n        links \"http://docs.oracle.com/javase/7/docs/api/\"\n        linksOffline \"http://d.android.com/reference\",\"${android.sdkDirectory}/docs/reference\"\n    }\n}\n\ntask javadocJar(type: Jar, dependsOn: javadoc) {\n    classifier = 'javadoc'\n    from javadoc.destinationDir\n}\n\nartifacts {\n    archives javadocJar\n    archives sourcesJar\n}\n\ninstall {\n    repositories.mavenInstaller {\n        pom.project {\n            name = 'tess-two'\n\n            packaging = 'aar'\n            groupId = 'com.rmtheis'\n            artifactId = 'tess-two'\n\n            developers {\n                developer {\n                    id = 'rmtheis'\n                    name = 'Robert Theis'\n                    email = 'robert.m.theis@gmail.com'\n                }\n            }\n            licenses {\n                license {\n                    name = 'The Apache Software License, Version 2.0'\n                    url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'\n                    distribution = 'repo'\n                }\n            }\n            scm {\n                url 'https://github.com/rmtheis/tess-two'\n            }\n        }\n    }\n}\n\nbintray {\n    user = properties.getProperty(\"bintray.user\")\n    key = properties.getProperty(\"bintray.apikey\")\n    configurations = ['archives']\n    pkg {\n        repo = 'maven'\n        name = 'tess-two'\n        userOrg = user\n        publish = true\n    }\n}\n"
  },
  {
    "path": "tess-two/build.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project name=\"tess-two\" default=\"help\">\n\n    <!-- The local.properties file is created and updated by the 'android' tool.\n         It contains the path to the SDK. It should *NOT* be checked into\n         Version Control Systems. -->\n    <property file=\"local.properties\" />\n\n    <!-- The ant.properties file can be created by you. It is only edited by the\n         'android' tool to add properties to it.\n         This is the place to change some Ant specific build properties.\n         Here are some properties you may want to change/update:\n\n         source.dir\n             The name of the source directory. Default is 'src'.\n         out.dir\n             The name of the output directory. Default is 'bin'.\n\n         For other overridable properties, look at the beginning of the rules\n         files in the SDK, at tools/ant/build.xml\n\n         Properties related to the SDK location or the project target should\n         be updated using the 'android' tool with the 'update' action.\n\n         This file is an integral part of the build system for your\n         application and should be checked into Version Control Systems.\n\n         -->\n    <property file=\"ant.properties\" />\n\n    <!-- The project.properties file is created and updated by the 'android'\n         tool, as well as ADT.\n\n         This contains project specific properties such as project target, and library\n         dependencies. Lower level build properties are stored in ant.properties\n         (or in .classpath for Eclipse projects).\n\n         This file is an integral part of the build system for your\n         application and should be checked into Version Control Systems. -->\n    <loadproperties srcFile=\"project.properties\" />\n\n    <!-- quick check on sdk.dir -->\n    <fail\n            message=\"sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var\"\n            unless=\"sdk.dir\"\n    />\n\n\n<!-- extension targets. Uncomment the ones where you want to do custom work\n     in between standard targets -->\n<!--\n    <target name=\"-pre-build\">\n    </target>\n    <target name=\"-pre-compile\">\n    </target>\n\n    /* This is typically used for code obfuscation.\n       Compiled code location: ${out.classes.absolute.dir}\n       If this is not done in place, override ${out.dex.input.absolute.dir} */\n    <target name=\"-post-compile\">\n    </target>\n-->\n\n    <!-- Import the actual build file.\n\n         To customize existing targets, there are two options:\n         - Customize only one target:\n             - copy/paste the target into this file, *before* the\n               <import> task.\n             - customize it to your needs.\n         - Customize the whole content of build.xml\n             - copy/paste the content of the rules files (minus the top node)\n               into this file, replacing the <import> task.\n             - customize to your needs.\n\n         ***********************\n         ****** IMPORTANT ******\n         ***********************\n         In all cases you must update the value of version-tag below to read 'custom' instead of an integer,\n         in order to avoid having your file be overridden by tools such as \"android update project\"\n    -->\n    <!-- version-tag: 1 -->\n    <import file=\"${sdk.dir}/tools/ant/build.xml\" />\n\n</project>\n"
  },
  {
    "path": "tess-two/jni/Android.mk",
    "content": "LOCAL_PATH := $(call my-dir)\nTESSERACT_PATH := $(LOCAL_PATH)/../../tesseract\nLEPTONICA_PATH := $(LOCAL_PATH)/../../leptonica\nLIBJPEG_PATH := $(LOCAL_PATH)/libjpeg\nLIBPNG_PATH := $(LOCAL_PATH)/libpng\n\n# Just build the Android.mk files in the subdirs\ninclude $(call all-subdir-makefiles)\n"
  },
  {
    "path": "tess-two/jni/Application.mk",
    "content": "APP_STL := c++_static\nAPP_ABI := armeabi-v7a x86 arm64-v8a x86_64\nAPP_OPTIM := release\nAPP_PLATFORM := android-16\nAPP_CPPFLAGS += -fexceptions -frtti\nNDK_TOOLCHAIN_VERSION := clang\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/Android.mk",
    "content": "LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := liblept\n\nLOCAL_SRC_FILES += \\\n  box.cpp \\\n  boxa.cpp \\\n  pix.cpp \\\n  pixa.cpp \\\n  utilities.cpp \\\n  readfile.cpp \\\n  writefile.cpp \\\n  jni.cpp\n\nLOCAL_EXPORT_CFLAGS := \\\n  -DHAVE_CONFIG_H\n\nLOCAL_EXPORT_C_INCLUDES := \\\n  $(LOCAL_PATH) \\\n  $(LEPTONICA_PATH)/src\n\nLOCAL_C_INCLUDES := \\\n  $(LOCAL_EXPORT_C_INCLUDES) \\\n  $(LIBJPEG_PATH) \\\n  $(LIBPNG_PATH)\n\nLOCAL_LDLIBS += \\\n  -ljnigraphics \\\n  -llog\n\nLOCAL_STATIC_LIBRARIES:= liblept_static\n\ninclude $(BUILD_SHARED_LIBRARY)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := liblept_static\nLOCAL_THIN_ARCHIVE := true\n\nLOCAL_EXPORT_CFLAGS := \\\n  -DHAVE_CONFIG_H\n\nLOCAL_CFLAGS := \\\n  $(LOCAL_EXPORT_CFLAGS) \\\n  -include $(LOCAL_PATH)/common.h\n\nLOCAL_EXPORT_C_INCLUDES := \\\n  $(LOCAL_PATH) \\\n  $(LEPTONICA_PATH)/src\n\nLOCAL_PATH := $(LEPTONICA_PATH)/src\n\nget-src-file-target-cflags += $(if $(filter bmpio.c,$1),-Wno-address-of-packed-member,)\n\n# leptonica (minus freetype)\n\nBLACKLIST_SRC_FILES := \\\n  %endiantest.c \\\n  %freetype.c \\\n  %xtractprotos.c\n\nLEPTONICA_SRC_FILES := \\\n  $(subst $(LOCAL_PATH)/,,$(wildcard $(LEPTONICA_PATH)/src/*.c))\n\nLOCAL_SRC_FILES := \\\n  $(filter-out $(BLACKLIST_SRC_FILES),$(LEPTONICA_SRC_FILES))\n\nLOCAL_C_INCLUDES += \\\n  $(LOCAL_EXPORT_C_INCLUDES) \\\n  $(LIBJPEG_PATH) \\\n  $(LIBPNG_PATH)\n\nLOCAL_STATIC_LIBRARIES:= libjpgt_static libpngt_static\ninclude $(BUILD_STATIC_LIBRARY)"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/box.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njlong Java_com_googlecode_leptonica_android_Box_nativeCreate(JNIEnv *env, jclass clazz, jint x,\n                                                             jint y, jint w, jint h) {\n  BOX *box = boxCreate((l_int32) x, (l_int32) y, (l_int32) w, (l_int32) h);\n\n  return (jlong) box;\n}\n\nvoid Java_com_googlecode_leptonica_android_Box_nativeDestroy(JNIEnv *env, jclass clazz,\n                                                             jlong nativeBox) {\n  BOX *box = (BOX *) nativeBox;\n\n  boxDestroy(&box);\n}\n\njint Java_com_googlecode_leptonica_android_Box_nativeGetX(JNIEnv *env, jclass clazz, jlong nativeBox) {\n  BOX *box = (BOX *) nativeBox;\n\n  return (jint) box->x;\n}\n\njint Java_com_googlecode_leptonica_android_Box_nativeGetY(JNIEnv *env, jclass clazz, jlong nativeBox) {\n  BOX *box = (BOX *) nativeBox;\n\n  return (jint) box->y;\n}\n\njint Java_com_googlecode_leptonica_android_Box_nativeGetWidth(JNIEnv *env, jclass clazz,\n                                                              jlong nativeBox) {\n  BOX *box = (BOX *) nativeBox;\n\n  return (jint) box->w;\n}\n\njint Java_com_googlecode_leptonica_android_Box_nativeGetHeight(JNIEnv *env, jclass clazz,\n                                                               jlong nativeBox) {\n  BOX *box = (BOX *) nativeBox;\n\n  return (jint) box->h;\n}\n\njboolean Java_com_googlecode_leptonica_android_Box_nativeGetGeometry(JNIEnv *env, jclass clazz,\n                                                                     jlong nativeBox,\n                                                                     jintArray dimensions) {\n  BOX *box = (BOX *) nativeBox;\n  jint *dimensionArray = env->GetIntArrayElements(dimensions, NULL);\n  l_int32 x, y, w, h;\n\n  if (boxGetGeometry(box, &x, &y, &w, &h)) {\n    return JNI_FALSE;\n  }\n\n  dimensionArray[0] = x;\n  dimensionArray[1] = y;\n  dimensionArray[2] = w;\n  dimensionArray[3] = h;\n\n  env->ReleaseIntArrayElements(dimensions, dimensionArray, 0);\n\n  return JNI_TRUE;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/boxa.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\nvoid Java_com_googlecode_leptonica_android_Boxa_nativeDestroy(JNIEnv *env, jclass clazz, jlong nativeBoxa) {\n  BOXA *boxa = (BOXA *) nativeBoxa;\n  boxaDestroy(&boxa);\n}\n\n\njboolean Java_com_googlecode_leptonica_android_Boxa_nativeGetGeometry(JNIEnv *env, jclass clazz,\n                                                                     jlong nativeBoxa,\n                                                                     jint index,\n                                                                     jintArray dimensions) {\n  BOXA *boxa = (BOXA *) nativeBoxa;\n  jint *dimensionArray = env->GetIntArrayElements(dimensions, NULL);\n  l_int32 x, y, w, h;\n\n  if (boxaGetBoxGeometry(boxa,index,  &x, &y, &w, &h)) {\n    return JNI_FALSE;\n  }\n\n  dimensionArray[0] = x;\n  dimensionArray[1] = y;\n  dimensionArray[2] = w;\n  dimensionArray[3] = h;\n\n  env->ReleaseIntArrayElements(dimensions, dimensionArray, 0);\n\n  return JNI_TRUE;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/common.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef LEPTONICA_JNI_COMMON_H\n#define LEPTONICA_JNI_COMMON_H\n\n#include <jni.h>\n#include <assert.h>\n#include \"allheaders.h\"\n#include <android/log.h>\n#include <asm/byteorder.h>\n\n#ifdef __BIG_ENDIAN\n  #define SK_A32_SHIFT 0\n  #define SK_R32_SHIFT 8\n  #define SK_G32_SHIFT 16\n  #define SK_B32_SHIFT 24\n#else\n  #define SK_A32_SHIFT 24\n  #define SK_R32_SHIFT 16\n  #define SK_G32_SHIFT 8\n  #define SK_B32_SHIFT 0\n#endif /* __BIG_ENDIAN */\n\n#define LOG_TAG \"Leptonica(native)\"\n#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)\n#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)\n#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\n#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)\n#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\n#define LOG_ASSERT(_cond, ...) if (!_cond) __android_log_assert(\"conditional\", LOG_TAG, __VA_ARGS__)\n\n#undef L_ERROR\n#undef L_WARNING\n#undef L_INFO\n\n#define L_ERROR(a,...) \\\n      IF_SEV(L_SEVERITY_ERROR, (void) LOGE(\"in %s: \" a, __VA_ARGS__), (void)0)\n#define L_WARNING(a,...) \\\n      IF_SEV(L_SEVERITY_WARNING, (void) LOGW(\"in %s: \" a, __VA_ARGS__), (void)0)\n#define L_INFO(a,...) \\\n      IF_SEV(L_SEVERITY_INFO, (void) LOGI(\"in %s: \" a, __VA_ARGS__), (void)0)\n\n#endif\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/endianness.h",
    "content": "/* for Android, this header is intentionally left blank */"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/jni.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\njint JNI_OnLoad(JavaVM* vm, void* reserved) {\n  JNIEnv *env;\n\n  if (vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK) {\n      LOGE(\"ERROR: GetEnv failed\\n\");\n      return -1;\n  }\n  assert(env != NULL);\n\n  return JNI_VERSION_1_6;\n}\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/pix.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n#include <string.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njlong Java_com_googlecode_leptonica_android_Pix_nativeCreatePix(JNIEnv *env, jclass clazz, jint w,\n                                                                jint h, jint d) {\n  PIX *pix = pixCreate((l_int32) w, (l_int32) h, (l_int32) d);\n\n  return (jlong) pix;\n}\n\njlong Java_com_googlecode_leptonica_android_Pix_nativeCreateFromData(JNIEnv *env, jclass clazz,\n                                                                     jbyteArray data, jint w,\n                                                                     jint h, jint d) {\n  PIX *pix = pixCreateNoInit((l_int32) w, (l_int32) h, (l_int32) d);\n\n  jbyte *data_buffer = env->GetByteArrayElements(data, NULL);\n  l_uint8 *byte_buffer = (l_uint8 *) data_buffer;\n\n  size_t size = 4 * pixGetWpl(pix) * pixGetHeight(pix);\n  memcpy(pixGetData(pix), byte_buffer, size);\n\n  env->ReleaseByteArrayElements(data, data_buffer, JNI_ABORT);\n\n  return (jlong) pix;\n}\n\njbyteArray Java_com_googlecode_leptonica_android_Pix_nativeGetData(JNIEnv *env, jclass clazz,\n                                                                   jlong nativePix, jbyteArray data) {\n  PIX *pix = (PIX *) nativePix;\n\n  size_t size = 4 * pixGetWpl(pix) * pixGetHeight(pix);\n\n  jbyteArray result = env->NewByteArray(size);\n  if (result == NULL) {\n    LOGE(\"Cannot allocate JNI Byte Array\");\n    return NULL;\n  }\n\n  env->SetByteArrayRegion(result, 0, size, (jbyte *)pixGetData(pix));\n  return result;\n}\n\njlong Java_com_googlecode_leptonica_android_Pix_nativeClone(JNIEnv *env, jclass clazz,\n                                                            jlong nativePix) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixClone(pixs);\n\n  return (jlong) pixd;\n}\n\njlong Java_com_googlecode_leptonica_android_Pix_nativeCopy(JNIEnv *env, jclass clazz, jlong nativePix) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixCopy(NULL, pixs);\n\n  return (jlong) pixd;\n}\n\njboolean Java_com_googlecode_leptonica_android_Pix_nativeInvert(JNIEnv *env, jclass clazz,\n                                                                jlong nativePix) {\n  PIX *pixs = (PIX *) nativePix;\n\n  if (pixInvert(pixs, pixs)) {\n    return JNI_FALSE;\n  }\n\n  return JNI_TRUE;\n}\n\nvoid Java_com_googlecode_leptonica_android_Pix_nativeDestroy(JNIEnv *env, jclass clazz,\n                                                             jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n\n  pixDestroy(&pix);\n}\n\njboolean Java_com_googlecode_leptonica_android_Pix_nativeGetDimensions(JNIEnv *env, jclass clazz,\n                                                                       jlong nativePix,\n                                                                       jintArray dimensions) {\n  PIX *pix = (PIX *) nativePix;\n  jint *dimensionArray = env->GetIntArrayElements(dimensions, NULL);\n  l_int32 w, h, d;\n\n  if (pixGetDimensions(pix, &w, &h, &d)) {\n    return JNI_FALSE;\n  }\n\n  dimensionArray[0] = w;\n  dimensionArray[1] = h;\n  dimensionArray[2] = d;\n\n  env->ReleaseIntArrayElements(dimensions, dimensionArray, 0);\n\n  return JNI_TRUE;\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetWidth(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n\n  return (jint) pixGetWidth(pix);\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetRefCount(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n\n  return (jint) pixGetRefcount(pix);\n}\njint Java_com_googlecode_leptonica_android_Pix_nativeGetHeight(JNIEnv *env, jclass clazz,\n                                                               jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n\n  return (jint) pixGetHeight(pix);\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetDepth(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n\n  return (jint) pixGetDepth(pix);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pix_nativeSetPixel(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix, jint xCoord,\n                                                              jint yCoord, jint argbColor) {\n  PIX *pix = (PIX *) nativePix;\n  l_int32 d = pixGetDepth(pix);\n  l_int32 x = (l_int32) xCoord;\n  l_int32 y = (l_int32) yCoord;\n\n  // These shift values are based on RGBA_8888\n  l_uint8 r = (argbColor >> SK_R32_SHIFT) & 0xFF;\n  l_uint8 g = (argbColor >> SK_G32_SHIFT) & 0xFF;\n  l_uint8 b = (argbColor >> SK_B32_SHIFT) & 0xFF;\n  l_uint8 a = (argbColor >> SK_A32_SHIFT) & 0xFF;\n  l_uint8 gray = ((r + g + b) / 3) & 0xFF;\n\n  l_uint32 color;\n\n  switch (d) {\n    case 1: // 1-bit binary\n      color = gray > 128 ? 1 : 0;\n      break;\n    case 2: // 2-bit grayscale\n      color = gray >> 6;\n      break;\n    case 4: // 4-bit grayscale\n      color = gray >> 4;\n      break;\n    case 8: // 8-bit grayscale\n      color = gray;\n      break;\n    case 24: // 24-bit RGB\n      SET_DATA_BYTE(&color, COLOR_RED, r);\n      SET_DATA_BYTE(&color, COLOR_GREEN, g);\n      SET_DATA_BYTE(&color, COLOR_BLUE, b);\n      break;\n    case 32: // 32-bit ARGB\n      SET_DATA_BYTE(&color, COLOR_RED, r);\n      SET_DATA_BYTE(&color, COLOR_GREEN, g);\n      SET_DATA_BYTE(&color, COLOR_BLUE, b);\n      SET_DATA_BYTE(&color, L_ALPHA_CHANNEL, a);\n      break;\n    default: // unsupported\n      LOGE(\"Not a supported color depth: %d\", d);\n      color = 0;\n      break;\n  }\n\n  pixSetPixel(pix, x, y, color);\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetPixel(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix, jint xCoord,\n                                                              jint yCoord) {\n  PIX *pix = (PIX *) nativePix;\n  l_int32 d = pixGetDepth(pix);\n  l_int32 x = (l_int32) xCoord;\n  l_int32 y = (l_int32) yCoord;\n  l_uint32 pixel;\n  l_uint32 color;\n  l_uint8 a, r, g, b;\n\n  pixGetPixel(pix, x, y, &pixel);\n\n  switch (d) {\n    case 1: // 1-bit binary\n      a = 0xFF;\n      r = g = b = (pixel == 0 ? 0x00 : 0xFF);\n      break;\n    case 2: // 2-bit grayscale\n      a = 0xFF;\n      r = g = b = (pixel << 6 | pixel << 4 | pixel);\n      break;\n    case 4: // 4-bit grayscale\n      a = 0xFF;\n      r = g = b = (pixel << 4 | pixel);\n      break;\n    case 8: // 8-bit grayscale\n      a = 0xFF;\n      r = g = b = pixel;\n      break;\n    case 24: // 24-bit RGB\n      a = 0xFF;\n      r = (pixel >> L_RED_SHIFT) & 0xFF;\n      g = (pixel >> L_GREEN_SHIFT) & 0xFF;\n      b = (pixel >> L_BLUE_SHIFT) & 0xFF;\n      break;\n    case 32: // 32-bit RGBA\n      r = (pixel >> L_RED_SHIFT) & 0xFF;\n      g = (pixel >> L_GREEN_SHIFT) & 0xFF;\n      b = (pixel >> L_BLUE_SHIFT) & 0xFF;\n      a = (pixel >> L_ALPHA_SHIFT) & 0xFF;\n      break;\n    default: // Not supported\n      LOGE(\"Not a supported color depth: %d\", d);\n      a = r = g = b = 0x00;\n      break;\n  }\n\n  color = a << SK_A32_SHIFT;\n  color |= r << SK_R32_SHIFT;\n  color |= g << SK_G32_SHIFT;\n  color |= b << SK_B32_SHIFT;\n\n  return (jint) color;\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetSpp(JNIEnv *env, jclass clazz,\n                                                            jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n  return pixGetSpp(pix);\n}\n\njint Java_com_googlecode_leptonica_android_Pix_nativeGetInputFormat(JNIEnv *env, jclass clazz,\n                                                                    jlong nativePix) {\n  PIX *pix = (PIX *) nativePix;\n  return pixGetInputFormat(pix);\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/pixa.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njlong Java_com_googlecode_leptonica_android_Pixa_nativeCreate(JNIEnv *env, jclass clazz, jint size) {\n  PIXA *pixa = pixaCreate((l_int32) size);\n\n  return (jlong) pixa;\n}\n\njlong Java_com_googlecode_leptonica_android_Pixa_nativeCopy(JNIEnv *env, jclass clazz,\n                                                            jlong nativePixa) {\n  PIXA *pixas = (PIXA *) nativePixa;\n  PIXA *pixad = pixaCopy(pixas, L_CLONE);\n\n  return (jlong) pixad;\n}\n\njlong Java_com_googlecode_leptonica_android_Pixa_nativeSort(JNIEnv *env, jclass clazz,\n                                                            jlong nativePixa, jint field, jint order) {\n  PIXA *pixas = (PIXA *) nativePixa;\n  PIXA *pixad = pixaSort(pixas, field, order, NULL, L_CLONE);\n\n  return (jlong) pixad;\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeDestroy(JNIEnv *env, jclass clazz,\n                                                              jlong nativePixa) {\n  PIXA *pixa = (PIXA *) nativePixa;\n\n  pixaDestroy(&pixa);\n}\n\njboolean Java_com_googlecode_leptonica_android_Pixa_nativeJoin(JNIEnv *env, jclass clazz,\n                                                               jlong nativePixa, jlong otherPixa) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  PIXA *pixas = (PIXA *) otherPixa;\n\n  if (pixaJoin(pixa, pixas, 0, 0)) {\n    return JNI_FALSE;\n  }\n\n  return JNI_TRUE;\n}\n\njint Java_com_googlecode_leptonica_android_Pixa_nativeGetCount(JNIEnv *env, jclass clazz,\n                                                               jlong nativePixa) {\n  PIXA *pixa = (PIXA *) nativePixa;\n\n  return (jint) pixaGetCount(pixa);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeAddPix(JNIEnv *env, jclass clazz,\n                                                             jlong nativePixa, jlong nativePix,\n                                                             jint mode) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  PIX *pix = (PIX *) nativePix;\n\n  pixaAddPix(pixa, pix, mode);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeAddBox(JNIEnv *env, jclass clazz,\n                                                             jlong nativePixa, jlong nativeBox,\n                                                             jint mode) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  BOX *box = (BOX *) nativeBox;\n\n  pixaAddBox(pixa, box, mode);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeAdd(JNIEnv *env, jclass clazz,\n                                                          jlong nativePixa, jlong nativePix,\n                                                          jlong nativeBox, jint mode) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  PIX *pix = (PIX *) nativePix;\n  BOX *box = (BOX *) nativeBox;\n\n  pixaAddPix(pixa, pix, mode);\n  pixaAddBox(pixa, box, mode);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeReplacePix(JNIEnv *env, jclass clazz,\n                                                                 jlong nativePixa, jint index,\n                                                                 jlong nativePix, jlong nativeBox) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  PIX *pix = (PIX *) nativePix;\n  BOX *box = (BOX *) nativeBox;\n\n  pixaReplacePix(pixa, index, pix, box);\n}\n\nvoid Java_com_googlecode_leptonica_android_Pixa_nativeMergeAndReplacePix(JNIEnv *env, jclass clazz,\n                                                                         jlong nativePixa,\n                                                                         jint indexA, jint indexB) {\n  PIXA *pixa = (PIXA *) nativePixa;\n\n  l_int32 op;\n  l_int32 depth;\n  l_int32 x, y, w, h;\n  l_int32 dx, dy, dw, dh;\n  PIX *pixA, *pixB, *pixd;\n  BOX *boxA, *boxB, *boxd;\n\n  pixA = pixaGetPix(pixa, indexA, L_CLONE);\n  pixB = pixaGetPix(pixa, indexB, L_CLONE);\n  boxA = pixaGetBox(pixa, indexA, L_CLONE);\n  boxB = pixaGetBox(pixa, indexB, L_CLONE);\n  boxd = boxBoundingRegion(boxA, boxB);\n\n  depth = pixGetDepth(pixA);\n  boxGetGeometry(boxd, &x, &y, &w, &h);\n  pixd = pixCreate(w, h, depth);\n\n  op = PIX_SRC | PIX_DST;\n\n  boxGetGeometry(boxA, &dx, &dy, &dw, &dh);\n  pixRasterop(pixd, dx - x, dy - y, dw, dh, op, pixA, 0, 0);\n  pixDestroy(&pixA);\n  boxDestroy(&boxA);\n\n  boxGetGeometry(boxB, &dx, &dy, &dw, &dh);\n  pixRasterop(pixd, dx - x, dy - y, dw, dh, op, pixB, 0, 0);\n  pixDestroy(&pixB);\n  boxDestroy(&boxB);\n\n  pixaReplacePix(pixa, indexA, pixd, boxd);\n  pixaRemovePix(pixa, indexB);\n}\n\njboolean Java_com_googlecode_leptonica_android_Pixa_nativeWriteToFileRandomCmap(JNIEnv *env,\n                                                                                jclass clazz,\n                                                                                jlong nativePixa,\n                                                                                jstring fileName,\n                                                                                jint width,\n                                                                                jint height) {\n  PIX *pixtemp;\n  PIXA *pixa = (PIXA *) nativePixa;\n\n  const char *c_fileName = env->GetStringUTFChars(fileName, NULL);\n  if (c_fileName == NULL) {\n    LOGE(\"could not extract fileName string!\");\n    return JNI_FALSE;\n  }\n\n  if (pixaGetCount(pixa) > 0) {\n    pixtemp = pixaDisplayRandomCmap(pixa, (l_int32) width, (l_int32) height);\n  } else {\n    pixtemp = pixCreate((l_int32) width, (l_int32) height, 1);\n  }\n\n  pixWrite(c_fileName, pixtemp, IFF_BMP);\n  pixDestroy(&pixtemp);\n\n  env->ReleaseStringUTFChars(fileName, c_fileName);\n\n  return JNI_TRUE;\n}\n\njlong Java_com_googlecode_leptonica_android_Pixa_nativeGetPix(JNIEnv *env, jclass clazz,\n                                                             jlong nativePixa, jint index) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  PIX *pix = pixaGetPix(pixa, (l_int32) index, L_CLONE);\n\n  return (jlong) pix;\n}\n\njlong Java_com_googlecode_leptonica_android_Pixa_nativeGetBox(JNIEnv *env, jclass clazz,\n                                                              jlong nativePixa, jint index) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  BOX *box = pixaGetBox(pixa, (l_int32) index, L_CLONE);\n\n  return (jlong) box;\n}\n\njboolean Java_com_googlecode_leptonica_android_Pixa_nativeGetBoxGeometry(JNIEnv *env, jclass clazz,\n                                                                         jlong nativePixa,\n                                                                         jint index,\n                                                                         jintArray dimensions) {\n  PIXA *pixa = (PIXA *) nativePixa;\n  jint *dimensionArray = env->GetIntArrayElements(dimensions, NULL);\n  l_int32 x, y, w, h;\n\n  if (pixaGetBoxGeometry(pixa, (l_int32) index, &x, &y, &w, &h)) {\n    return JNI_FALSE;\n  }\n\n  dimensionArray[0] = x;\n  dimensionArray[1] = y;\n  dimensionArray[2] = w;\n  dimensionArray[3] = h;\n\n  env->ReleaseIntArrayElements(dimensions, dimensionArray, 0);\n\n  return JNI_TRUE;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/readfile.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <allheaders.h>\n#include <android/bitmap.h>\n#include <android/log.h>\n#include <common.h>\n#include <environ.h>\n#include <jni.h>\n#include <pix.h>\n#include <string.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\n/************\n * ReadFile *\n ************/\n\njlong Java_com_googlecode_leptonica_android_ReadFile_nativeReadMem(JNIEnv *env, jclass clazz,\n                                                                   jbyteArray image, jint length) {\n    jbyte *image_buffer = env->GetByteArrayElements(image, NULL);\n    int buffer_length = env->GetArrayLength(image);\n\n    PIX *pix = pixReadMem((const l_uint8 *) image_buffer, buffer_length);\n\n    env->ReleaseByteArrayElements(image, image_buffer, JNI_ABORT);\n\n    return (jlong) pix;\n}\n\njlong Java_com_googlecode_leptonica_android_ReadFile_nativeReadBytes8(JNIEnv *env, jclass clazz,\n                                                                      jbyteArray data, jint w,\n                                                                      jint h) {\n    PIX *pix = pixCreateNoInit((l_int32) w, (l_int32) h, 8);\n    l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);\n    jbyte *data_buffer = env->GetByteArrayElements(data, NULL);\n    l_uint8 *byte_buffer = (l_uint8 *) data_buffer;\n\n    for (int i = 0; i < h; i++) {\n        memcpy(lineptrs[i], (byte_buffer + (i * w)), w);\n    }\n\n    env->ReleaseByteArrayElements(data, data_buffer, JNI_ABORT);\n    pixCleanupByteProcessing(pix, lineptrs);\n\n    l_int32 d;\n\n    pixGetDimensions(pix, &w, &h, &d);\n\n    LOGE(\"Created image width w=%d, h=%d, d=%d\", w, h, d);\n\n    return (jlong) pix;\n}\n\njboolean Java_com_googlecode_leptonica_android_ReadFile_nativeReplaceBytes8(JNIEnv *env,\n                                                                            jclass clazz,\n                                                                            jlong nativePix,\n                                                                            jbyteArray data,\n                                                                            jint srcw, jint srch) {\n    PIX *pix = (PIX *) nativePix;\n    l_int32 w, h, d;\n\n    pixGetDimensions(pix, &w, &h, &d);\n\n    if (d != 8 || (l_int32) srcw != w || (l_int32) srch != h) {\n        LOGE(\"Failed to replace bytes at w=%d, h=%d, d=%d with w=%d, h=%d\", w, h, d, srcw, srch);\n\n        return JNI_FALSE;\n    }\n\n    l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);\n    jbyte *data_buffer = env->GetByteArrayElements(data, NULL);\n    l_uint8 *byte_buffer = (l_uint8 *) data_buffer;\n\n    for (int i = 0; i < h; i++) {\n        memcpy(lineptrs[i], (byte_buffer + (i * w)), w);\n    }\n\n    env->ReleaseByteArrayElements(data, data_buffer, JNI_ABORT);\n    pixCleanupByteProcessing(pix, lineptrs);\n\n    return JNI_TRUE;\n}\n\njlong Java_com_googlecode_leptonica_android_ReadFile_nativeReadFiles(JNIEnv *env, jclass clazz,\n                                                                     jstring dirName, jstring prefix) {\n    PIXA *pixad = NULL;\n\n    const char *c_dirName = env->GetStringUTFChars(dirName, NULL);\n    if (c_dirName == NULL) {\n        LOGE(\"could not extract dirName string!\");\n        return JNI_FALSE;\n    }\n\n    const char *c_prefix = env->GetStringUTFChars(prefix, NULL);\n    if (c_prefix == NULL) {\n        LOGE(\"could not extract prefix string!\");\n        return JNI_FALSE;\n    }\n\n    pixad = pixaReadFiles(c_dirName, c_prefix);\n\n    env->ReleaseStringUTFChars(dirName, c_dirName);\n    env->ReleaseStringUTFChars(prefix, c_prefix);\n\n    return (jlong) pixad;\n}\n\njlong Java_com_googlecode_leptonica_android_ReadFile_nativeReadFile(JNIEnv *env, jclass clazz,\n                                                                    jstring fileName) {\n    PIX *pixd = NULL;\n\n    const char *c_fileName = env->GetStringUTFChars(fileName, NULL);\n    if (c_fileName == NULL) {\n        LOGE(\"could not extract fileName string!\");\n        return JNI_FALSE;\n    }\n\n    pixd = pixRead(c_fileName);\n\n    env->ReleaseStringUTFChars(fileName, c_fileName);\n\n    return (jlong) pixd;\n}\n\njlong Java_com_googlecode_leptonica_android_ReadFile_nativeReadBitmap(JNIEnv *env, jclass clazz,\n                                                                      jobject bitmap) {\n    LOGV(__FUNCTION__);\n\n    l_int32 w, h, d;\n    AndroidBitmapInfo info;\n    void* pixels;\n    int ret;\n\n    if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {\n        LOGE(\"AndroidBitmap_getInfo() failed ! error=%d\", ret);\n        return JNI_FALSE;\n    }\n\n    if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {\n        LOGE(\"Bitmap format is not RGBA_8888 !\");\n        return JNI_FALSE;\n    }\n\n    if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {\n        LOGE(\"AndroidBitmap_lockPixels() failed ! error=%d\", ret);\n        return JNI_FALSE;\n    }\n\n    PIX *pixd = pixCreate(info.width, info.height, 32);\n    l_uint8 *src = (l_uint8 *) pixels;\n    l_uint8 *dst = (l_uint8 *) pixGetData(pixd);\n    l_int32 srcBpl = (info.stride);\n    l_int32 dstBpl = pixGetWpl(pixd)*4;\n\n    for (int dy = 0; dy < info.height; dy++) {\n        memcpy(dst, src, 4 * info.width);\n        dst += dstBpl;\n        src += srcBpl;\n\n    }\n    pixEndianByteSwap(pixd);\n\n\n    AndroidBitmap_unlockPixels(env, bitmap);\n\n    return (jlong) pixd;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/utilities.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\n#include <string.h>\n#include <android/bitmap.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\n/***************\n * AdaptiveMap *\n ***************/\n\njlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativeBackgroundNormMorph(JNIEnv *env,\n                                                                                  jclass clazz,\n                                                                                  jlong nativePix,\n                                                                                  jint reduction,\n                                                                                  jint size,\n                                                                                  jint bgval) {\n  // Normalizes the background of each element in pixa.\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixBackgroundNormMorph(pixs, NULL, (l_int32) reduction, (l_int32) size,\n                                     (l_int32) bgval);\n\n  return jlong(pixd);\n}\n\njlong Java_com_googlecode_leptonica_android_AdaptiveMap_nativePixContrastNorm(JNIEnv *env,\n                                                                              jclass clazz,\n                                                                              jlong nativePix,\n                                                                              jint sizeX,\n                                                                              jint sizeY,\n                                                                              jint minDiff,\n                                                                              jint smoothX,\n                                                                              jint smoothY) {\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixContrastNorm(NULL, pixs, (l_int32) sizeX, (l_int32) sizeY,\n                                     (l_int32) minDiff, (l_int32) smoothX, (l_int32) smoothY);\n\n  return jlong(pixd);\n}\n\n/************\n * Binarize *\n ************/\n\njlong Java_com_googlecode_leptonica_android_Binarize_nativeOtsuAdaptiveThreshold(JNIEnv *env,\n                                                                                 jclass clazz,\n                                                                                 jlong nativePix,\n                                                                                 jint sizeX,\n                                                                                 jint sizeY,\n                                                                                 jint smoothX,\n                                                                                 jint smoothY,\n                                                                                 jfloat scoreFract) {\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd;\n\n  if (pixOtsuAdaptiveThreshold(pixs, (l_int32) sizeX, (l_int32) sizeY, (l_int32) smoothX,\n                               (l_int32) smoothY, (l_float32) scoreFract, NULL, &pixd)) {\n    return (jlong) 0;\n  }\n\n  return jlong(pixd);\n}\n\njlong Java_com_googlecode_leptonica_android_Binarize_nativeSauvolaBinarizeTiled(JNIEnv *env,\n                                                                                jclass clazz,\n                                                                                jlong nativePix,\n                                                                                jint whsize,\n                                                                                jfloat factor,\n                                                                                jint nx,\n                                                                                jint ny) {\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd;\n\n  if (pixSauvolaBinarizeTiled(pixs, (l_int32) whsize, (l_float32) factor, (l_int32) nx,\n                               (l_int32) ny, NULL, &pixd)) {\n    return (jlong) 0;\n  }\n\n  return jlong(pixd);\n}\n\n/********\n * Clip *\n ********/\n\njlong Java_com_googlecode_leptonica_android_Clip_nativeClipRectangle(JNIEnv *env, jclass clazz,\n                                                                     jlong nativePix, jlong nativeBox) {\n\n  PIX *pixs = (PIX *) nativePix;\n  BOX *box = (BOX *) nativeBox;\n  PIX *pixd;\n  pixd = pixClipRectangle(pixs,box,NULL);\n  return jlong(pixd);\n}\n\n/***********\n * Convert *\n ***********/\n\njlong Java_com_googlecode_leptonica_android_Convert_nativeConvertTo8(JNIEnv *env, jclass clazz,\n                                                                     jlong nativePix) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixConvertTo8(pixs, FALSE);\n\n  return jlong(pixd);\n}\n\n/********\n * Edge *\n ********/\n\njlong Java_com_googlecode_leptonica_android_Edge_nativePixSobelEdgeFilter(JNIEnv *env,\n                                                                          jclass clazz,\n                                                                          jlong nativePix,\n                                                                          jint orientFlag) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixSobelEdgeFilter(pixs, (l_int32) orientFlag);\n\n  return jlong(pixd);\n}\n\n/***********\n * Enhance *\n ***********/\n\njlong Java_com_googlecode_leptonica_android_Enhance_nativeUnsharpMasking(JNIEnv *env, jclass clazz,\n                                                                         jlong nativePix,\n                                                                         jint halfwidth,\n                                                                         jfloat fract) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixUnsharpMasking(pixs, (l_int32) halfwidth, (l_float32) fract);\n\n  return jlong(pixd);\n}\n\n/*************\n * GrayQuant *\n *************/\n\njlong Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary(JNIEnv *env, jclass clazz,\n                                                                                 jlong nativePix, jint thresh) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixThresholdToBinary(pixs, (l_int32) thresh);\n\n  return jlong(pixd);\n}\n\n/**********\n * JpegIO *\n **********/\n\njbyteArray Java_com_googlecode_leptonica_android_JpegIO_nativeCompressToJpeg(JNIEnv *env,\n                                                                             jclass clazz,\n                                                                             jlong nativePix,\n                                                                             jint quality,\n                                                                             jboolean progressive) {\n  PIX *pix = (PIX *) nativePix;\n\n  l_uint8 *data;\n  size_t size;\n\n  if (pixWriteMemJpeg(&data, &size, pix, (l_int32) quality, progressive == JNI_TRUE ? 1 : 0)) {\n    LOGE(\"Failed to write JPEG data\");\n\n    return NULL;\n  }\n\n  // TODO Can we just use the byte array directly?\n  jbyteArray array = env->NewByteArray(size);\n  env->SetByteArrayRegion(array, 0, size, (jbyte *) data);\n\n  free(data);\n\n  return array;\n}\n\n/************\n * MorphApp *\n ************/\n\njlong Java_com_googlecode_leptonica_android_MorphApp_nativePixTophat(JNIEnv *env, jclass clazz,\n                                                                     jlong nativePix, jint hsize,\n                                                                     jint vsize, jint type) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixTophat(pixs, (l_int32) hsize, (l_int32) vsize, (l_int32) type);\n\n  return jlong(pixd);\n}\n\njlong Java_com_googlecode_leptonica_android_MorphApp_nativePixFastTophat(JNIEnv *env, jclass clazz,\n                                                                         jlong nativePix, jint xsize,\n                                                                         jint ysize, jint type) {\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixFastTophat(pixs, (l_int32) xsize, (l_int32) ysize, (l_int32) type);\n\n  return jlong(pixd);\n}\n\n/*********\n * Scale *\n *********/\n\njlong Java_com_googlecode_leptonica_android_Scale_nativeScaleGeneral(JNIEnv *env, jclass clazz,\n                                                                     jlong nativePix, jfloat scaleX,\n                                                                     jfloat scaleY, jfloat sharpfract, jint sharpwidth) {\n  PIX *pixs = (Pix *) nativePix;\n  return (jlong) pixScaleGeneral(pixs, (l_float32) scaleX, (l_float32) scaleY,(l_float32) sharpfract, (l_int32) sharpwidth);\n}\n\njlong Java_com_googlecode_leptonica_android_Scale_nativeScale(JNIEnv *env, jclass clazz,\n                                                              jlong nativePix, jfloat scaleX,\n                                                              jfloat scaleY) {\n  PIX *pixs = (Pix *) nativePix;\n  PIX *pixd = pixScale(pixs, (l_float32) scaleX, (l_float32) scaleY);\n\n  return jlong(pixd);\n}\n\n/********\n * Skew *\n ********/\n\njfloat Java_com_googlecode_leptonica_android_Skew_nativeFindSkew(JNIEnv *env, jclass clazz,\n                                                                 jlong nativePix, jfloat sweepRange,\n                                                                 jfloat sweepDelta,\n                                                                 jint sweepReduction,\n                                                                 jint searchReduction,\n                                                                 jfloat searchMinDelta) {\n  PIX *pixs = (PIX *) nativePix;\n\n  l_float32 angle, conf;\n\n  if (!pixFindSkewSweepAndSearch(pixs, &angle, &conf, (l_int32) sweepReduction,\n                                 (l_int32) searchReduction, (l_float32) sweepRange,\n                                 (l_int32) sweepDelta, (l_float32) searchMinDelta)) {\n    if (conf <= 0) {\n      return (jfloat) 0;\n    }\n\n    return (jfloat) angle;\n  }\n\n  return (jfloat) 0;\n}\n\n/**********\n * Rotate *\n **********/\n\njlong Java_com_googlecode_leptonica_android_Rotate_nativeRotate(JNIEnv *env, jclass clazz,\n                                                                jlong nativePix, jfloat degrees,\n                                                                jboolean quality, jboolean resize) {\n  PIX *pixd;\n  PIX *pixs = (PIX *) nativePix;\n\n  l_float32 deg2rad = 3.1415926535 / 180.0;\n  l_float32 radians = degrees * deg2rad;\n  l_int32 w, h, bpp, type;\n\n  pixGetDimensions(pixs, &w, &h, &bpp);\n\n  if (bpp == 1 && quality == JNI_TRUE) {\n    pixd = pixRotateBinaryNice(pixs, radians, L_BRING_IN_WHITE);\n  } else {\n    type = quality == JNI_TRUE ? L_ROTATE_AREA_MAP : L_ROTATE_SAMPLING;\n    w = (resize == JNI_TRUE) ? w : 0;\n    h = (resize == JNI_TRUE) ? h : 0;\n    pixd = pixRotate(pixs, radians, type, L_BRING_IN_WHITE, w, h);\n  }\n\n  return jlong(pixd);\n}\n\njlong Java_com_googlecode_leptonica_android_Rotate_nativeRotateOrth(JNIEnv *env, jclass clazz,\n                                                                    jlong nativePix, jint quads) {\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd;\n  pixd = pixRotateOrth(pixs,(int)quads);\n  return jlong(pixd);\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_leptonica_android/writefile.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include \"common.h\"\n\n#include <string.h>\n#include <android/bitmap.h>\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\n/*************\n * WriteFile *\n *************/\n\njint Java_com_googlecode_leptonica_android_WriteFile_nativeWriteBytes8(JNIEnv *env, jclass clazz,\n                                                                       jlong nativePix,\n                                                                       jbyteArray data) {\n  l_int32 w, h, d;\n  PIX *pix = (PIX *) nativePix;\n  pixGetDimensions(pix, &w, &h, &d);\n\n  l_uint8 **lineptrs = pixSetupByteProcessing(pix, NULL, NULL);\n  jbyte *data_buffer = env->GetByteArrayElements(data, NULL);\n  l_uint8 *byte_buffer = (l_uint8 *) data_buffer;\n\n  for (int i = 0; i < h; i++) {\n    memcpy((byte_buffer + (i * w)), lineptrs[i], w);\n  }\n\n  env->ReleaseByteArrayElements(data, data_buffer, 0);\n  pixCleanupByteProcessing(pix, lineptrs);\n\n  return (jint)(w * h);\n}\n\njboolean Java_com_googlecode_leptonica_android_WriteFile_nativeWriteImpliedFormat(JNIEnv *env,\n                                                                                  jclass clazz,\n                                                                                  jlong nativePix,\n                                                                                  jstring fileName) {\n  PIX *pixs = (PIX *) nativePix;\n\n  const char *c_fileName = env->GetStringUTFChars(fileName, NULL);\n  if (c_fileName == NULL) {\n    LOGE(\"could not extract fileName string!\");\n    return JNI_FALSE;\n  }\n\n  jboolean result = JNI_TRUE;\n\n  if (pixWriteImpliedFormat(c_fileName, pixs, 85, JNI_FALSE)) {\n    LOGE(\"could not write pix data to %s\", c_fileName);\n    result = JNI_FALSE;\n  }\n\n  env->ReleaseStringUTFChars(fileName, c_fileName);\n\n  return result;\n}\n\njboolean Java_com_googlecode_leptonica_android_WriteFile_nativeWriteBitmap(JNIEnv *env,\n                                                                           jclass clazz,\n                                                                           jlong nativePix,\n                                                                           jobject bitmap) {\n  PIX *pixs = (PIX *) nativePix;\n\n  l_int32 w, h, d;\n  AndroidBitmapInfo info;\n  void* pixels;\n  int ret;\n\n  if ((ret = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {\n    LOGE(\"AndroidBitmap_getInfo() failed ! error=%d\", ret);\n    return JNI_FALSE;\n  }\n\n  if (info.format != ANDROID_BITMAP_FORMAT_RGBA_8888) {\n    LOGE(\"Bitmap format is not RGBA_8888 !\");\n    return JNI_FALSE;\n  }\n\n  pixGetDimensions(pixs, &w, &h, &d);\n\n  if (w != info.width || h != info.height) {\n    LOGE(\"Bitmap width and height do not match Pix dimensions!\");\n    return JNI_FALSE;\n  }\n\n  if ((ret = AndroidBitmap_lockPixels(env, bitmap, &pixels)) < 0) {\n    LOGE(\"AndroidBitmap_lockPixels() failed ! error=%d\", ret);\n    return JNI_FALSE;\n  }\n\n  pixEndianByteSwap(pixs);\n\n  l_uint8 *dst = (l_uint8 *) pixels;\n  l_uint8 *src = (l_uint8 *) pixGetData(pixs);\n  l_int32 dstBpl = info.stride;\n  l_int32 srcBpl = 4 * pixGetWpl(pixs);\n\n  LOGI(\"Writing 32bpp RGBA bitmap (w=%d, h=%d, stride=%d) from %dbpp Pix (wpl=%d)\", info.width,\n       info.height, info.stride, d, pixGetWpl(pixs));\n\n  for (int dy = 0; dy < info.height; dy++) {\n    l_uint8 *dstx = dst;\n    l_uint8 *srcx = src;\n\n    if (d == 32) {\n      memcpy(dst, src, 4 * info.width);\n    } else if (d == 8) {\n      for (int dw = 0; dw < info.width; dw++) {\n        dstx[0] = dstx[1] = dstx[2] = srcx[0];\n        dstx[3] = 0xFF;\n\n        dstx += 4;\n        srcx += 1;\n      }\n    } else if (d == 1) {\n      for (int dw = 0; dw < info.width; dw++) {\n        dstx[0] = dstx[1] = dstx[2] = (1 << (7 - (dw & 7)) & srcx[0]) ? 0x00 : 0xFF;\n        dstx[3] = 0xFF;\n\n        dstx += 4;\n        srcx += ((dw % 8) == 7) ? 1 : 0;\n      }\n    }\n\n    dst += dstBpl;\n    src += srcBpl;\n  }\n\n  AndroidBitmap_unlockPixels(env, bitmap);\n\n  return JNI_TRUE;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/Android.mk",
    "content": "LOCAL_PATH := $(call my-dir)\nTESSERACT_PATH := $(TESSERACT_PATH)/src\n\n### jni\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := libtess\n\nLOCAL_SRC_FILES += \\\n  pageiterator.cpp \\\n  resultiterator.cpp \\\n  tessbaseapi.cpp\n\nLOCAL_C_INCLUDES += \\\n  $(LOCAL_PATH)\n\nLOCAL_LDLIBS += \\\n  -ljnigraphics \\\n  -llog\n\nLOCAL_STATIC_LIBRARIES := libtess_static\nLOCAL_SHARED_LIBRARIES := liblept\n\ninclude $(BUILD_SHARED_LIBRARY)\n\n### core static\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := libtess_core_static\nLOCAL_THIN_ARCHIVE := true\n\nLOCAL_C_INCLUDES += $(LOCAL_PATH) # overriding some tesseract headers\n\nLOCAL_PATH := $(TESSERACT_PATH)\n\nTESSERACT_SRC_FILES := \\\n  $(wildcard $(TESSERACT_PATH)/arch/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/ccstruct/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/ccutil/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/classify/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/cube/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/cutil/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/dict/*.cpp) \\\n\nBLACKLIST_SRC_FILES := \\\n    ccutil/fileio.cpp \\\n    %sse.cpp \\\n    %avx2.cpp \\\n    %avx.cpp \\\n\nLOCAL_SRC_FILES := \\\n  $(filter-out $(BLACKLIST_SRC_FILES),$(subst $(LOCAL_PATH)/,,$(TESSERACT_SRC_FILES)))\n\nLOCAL_C_INCLUDES += \\\n  $(TESSERACT_PATH)/api \\\n  $(TESSERACT_PATH)/arch \\\n  $(TESSERACT_PATH)/ccmain \\\n  $(TESSERACT_PATH)/ccstruct \\\n  $(TESSERACT_PATH)/ccutil \\\n  $(TESSERACT_PATH)/classify \\\n  $(TESSERACT_PATH)/cutil \\\n  $(TESSERACT_PATH)/dict \\\n  $(TESSERACT_PATH)/lstm \\\n  $(TESSERACT_PATH)/textord \\\n  $(TESSERACT_PATH)/training \\\n  $(TESSERACT_PATH)/viewer \\\n  $(TESSERACT_PATH)/wordrec\n\nLOCAL_CFLAGS := \\\n  -DGRAPHICS_DISABLED \\\n  -DPACKAGE_VERSION=\\\"4.1.0\\\" \\\n  -DTESSERACT_MAJOR_VERSION=4 \\\n  -DTESSERACT_MINOR_VERSION=1 \\\n  -DTESSERACT_MICRO_VERSION=0 \\\n  -Wno-shift-negative-value\n\nLOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)\nLOCAL_EXPORT_CFLAGS := $(LOCAL_CFLAGS)\nLOCAL_STATIC_LIBRARIES += liblept_static # to inherit C_INCLUDE and CFLAGS\n\ninclude $(BUILD_STATIC_LIBRARY)\n\n### other static (split from _core to keep linker command line less than maximum)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := libtess_static\nLOCAL_THIN_ARCHIVE := true\n\n# tesseract (minus executable)\n\nBLACKLIST_SRC_FILES := \\\n  %api/tesseractmain.cpp \\\n  %viewer/svpaint.cpp\n\nTESSERACT_SRC_FILES := \\\n  $(wildcard $(TESSERACT_PATH)/api/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/ccmain/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/lstm/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/textord/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/viewer/*.cpp) \\\n  $(wildcard $(TESSERACT_PATH)/wordrec/*.cpp)\n\nLOCAL_PATH := $(TESSERACT_PATH)\n\nLOCAL_SRC_FILES := \\\n  $(filter-out $(BLACKLIST_SRC_FILES),$(subst $(LOCAL_PATH)/,,$(TESSERACT_SRC_FILES)))\n\nLOCAL_STATIC_LIBRARIES := libtess_core_static\nLOCAL_STATIC_LIBRARIES += liblept_static # to inherit C_INCLUDE\n\ninclude $(BUILD_STATIC_LIBRARY)\n\n### command line (statically linked to tesseract libs)\n\ninclude $(CLEAR_VARS)\nLOCAL_MODULE := tesseract\nTESSERACT_SRC_FILES := \\\n  $(TESSERACT_PATH)/api/tesseractmain.cpp\n\nLOCAL_PATH := $(TESSERACT_PATH)\n\nLOCAL_SRC_FILES := \\\n  $(subst $(LOCAL_PATH)/,,$(TESSERACT_SRC_FILES))\n\nLOCAL_STATIC_LIBRARIES := libtess_static liblept_static\nLOCAL_LDLIBS += \\\n  -llog\n\ninclude $(BUILD_EXECUTABLE)"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/common.h",
    "content": "/*\n * Copyright 2010, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#ifndef TESSERACT_JNI_COMMON_H\n#define TESSERACT_JNI_COMMON_H\n\n#include <jni.h>\n#include <android/log.h>\n#include <assert.h>\n\n#define LOG_TAG \"Tesseract(native)\"\n#define LOGV(...) __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)\n#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)\n#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)\n#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)\n#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)\n#define LOG_ASSERT(_cond, ...) if (!_cond) __android_log_assert(\"conditional\", LOG_TAG, __VA_ARGS__)\n\n#endif\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/debugpixa.h",
    "content": "#ifndef TESSERACT_CCSTRUCT_DEBUGPIXA_H_\n#define TESSERACT_CCSTRUCT_DEBUGPIXA_H_\n\n// dummy DebugPixa for Android\n\n#include \"allheaders.h\"\n\nnamespace tesseract {\n\n// Class to hold a Pixa collection of debug images with captions and save them\n// to a PDF file.\nclass DebugPixa {\n public:\n  DebugPixa() {\n  }\n  // If the filename_ has been set and there are any debug images, they are\n  // written to the set filename_.\n  ~DebugPixa() {\n  }\n\n  // Adds the given pix to the set of pages in the PDF file, with the given\n  // caption added to the top.\n  void AddPix(const Pix* pix, const char* caption) {\n  }\n\n  // Sets the destination filename and enables images to be written to a PDF\n  // on destruction.\n  void WritePDF(const char* filename) {\n  }\n};\n\n}  // namespace tesseract\n\n#endif  // TESSERACT_CCSTRUCT_DEBUGPIXA_H_\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/pageiterator.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <stdio.h>\n#include \"common.h\"\n#include \"pageiterator.h\"\n#include \"allheaders.h\"\n#include \"helpers.h\"\n#include \"pageres.h\"\n#include \"tesseractclass.h\"\n\nusing namespace tesseract;\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\nvoid Java_com_googlecode_tesseract_android_PageIterator_nativeBegin(JNIEnv *env, jclass clazz,\n    jlong nativePageIterator) {\n  ((PageIterator *) nativePageIterator)->Begin();\n}\n\njboolean Java_com_googlecode_tesseract_android_PageIterator_nativeNext(JNIEnv *env, jclass clazz,\n    jlong nativePageIterator, jint level) {\n  PageIterator *pageIterator = (PageIterator *) nativePageIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n\n  return pageIterator->Next(enumLevel) ? JNI_TRUE : JNI_FALSE;\n}\n\njintArray Java_com_googlecode_tesseract_android_PageIterator_nativeBoundingBox(JNIEnv *env, jclass clazz,\n    jlong nativePageIterator, jint level) {\n  int size = 4;\n  jintArray result = env->NewIntArray(size);\n\n  LOG_ASSERT((result != NULL), \"Could not create Java bounding box array!\");\n  \n  PageIterator *pageIterator = (PageIterator *) nativePageIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n  int x1, y1, x2, y2;\n  pageIterator->BoundingBox(enumLevel, &x1, &y1, &x2, &y2);\n  \n  // fill a temp structure to use to populate the java int array\n  jint fill[4];\n  fill[0] = x1;\n  fill[1] = y1;\n  fill[2] = x2;\n  fill[3] = y2;\n \n  env->SetIntArrayRegion(result, 0, size, fill);\n  return result;\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/resultiterator.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <stdio.h>\n#include \"common.h\"\n#include \"resultiterator.h\"\n#include \"allheaders.h\"\n#include \"pageres.h\"\n#include \"tesseractclass.h\"\n\nusing namespace tesseract;\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif  /* __cplusplus */\n\njstring Java_com_googlecode_tesseract_android_ResultIterator_nativeGetUTF8Text(JNIEnv *env,\n    jclass clazz, jlong nativeResultIterator, jint level) {\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n\n  char *text = resultIterator->GetUTF8Text(enumLevel);\n  jstring result = env->NewStringUTF(text);\n\n  free(text);\n\n  return result;\n}\n\njfloat Java_com_googlecode_tesseract_android_ResultIterator_nativeConfidence(JNIEnv *env,\n    jclass clazz, jlong nativeResultIterator, jint level) {\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n\n  return (jfloat) resultIterator->Confidence(enumLevel);\n}\n\njobjectArray Java_com_googlecode_tesseract_android_ResultIterator_nativeGetSymbolChoices(JNIEnv *env,\n    jclass clazz, jlong nativeResultIterator) {\n\n  // Get the actual result iterator (as C object)\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n\n  // Create a choice iterator to determine the number of alternatives\n  tesseract::ChoiceIterator ci(*resultIterator);\n  int numberOfAlternatives = 0;\n  do {\n    numberOfAlternatives++;\n  } while (ci.Next());\n\n  // Create a string array to hold the choices\n  jobjectArray ret = (jobjectArray) env->NewObjectArray(numberOfAlternatives, env->FindClass(\"java/lang/String\"), env->NewStringUTF(\"\"));\n\n  // Save each result to the output array\n  int i = 0;\n  tesseract::ChoiceIterator cb(*resultIterator);\n  do {\n    // Create the string output\n    const char *utfText = cb.GetUTF8Text();\n\n    // Add each string to the object array elements\n    char newString[strlen(utfText) + 7];\n    sprintf(newString, \"%s|%.2f\", utfText, cb.Confidence());\n    env->SetObjectArrayElement(ret, i, env->NewStringUTF(newString));\n\n    // Move to the next element in the list\n    i++;\n  } while(cb.Next());\n\n  // Return the string array\n  return ret;\n}\n\njboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtBeginningOf(JNIEnv *env,\n    jclass clazz, jlong nativeResultIterator, jint level) {\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n\n  return (jboolean) (resultIterator->IsAtBeginningOf(enumLevel) ? JNI_TRUE : JNI_FALSE);\n}\n\njboolean Java_com_googlecode_tesseract_android_ResultIterator_nativeIsAtFinalElement(JNIEnv *env,\n    jclass clazz, jlong nativeResultIterator, jint level, jint element) {\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n  PageIteratorLevel enumLevel = (PageIteratorLevel) level;\n  PageIteratorLevel enumElement = (PageIteratorLevel) element;\n\n  return (jboolean) (resultIterator->IsAtFinalElement(enumLevel, enumElement) ? JNI_TRUE : JNI_FALSE);\n}\n\nvoid Java_com_googlecode_tesseract_android_ResultIterator_nativeDelete(JNIEnv *env, jclass clazz,\n    jlong nativeResultIterator) {\n  ResultIterator *resultIterator = (ResultIterator *) nativeResultIterator;\n  if (resultIterator != 0) {\n    delete resultIterator;\n  }\n}\n\n#ifdef __cplusplus\n}\n#endif  /* __cplusplus */\n"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/tess_version.h",
    "content": "/* for Android, this header is intentionally left blank */"
  },
  {
    "path": "tess-two/jni/com_googlecode_tesseract_android/tessbaseapi.cpp",
    "content": "/*\n * Copyright 2011, Google Inc.\n * Copyright 2011, Robert Theis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *     http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n#include <stdio.h>\n#include <malloc.h>\n#include \"android/bitmap.h\"\n#include \"common.h\"\n#include \"baseapi.h\"\n#include \"ocrclass.h\"\n#include \"allheaders.h\"\n#include \"renderer.h\"\n\nstatic jmethodID method_onProgressValues;\n\nstruct native_data_t {\n  tesseract::TessBaseAPI api;\n  PIX *pix;\n  void *data;\n  bool debug;\n\n  Box* currentTextBox = NULL;\n  l_int32 lastProgress;\n  bool cancel_ocr;\n\n  JNIEnv *cachedEnv;\n  jobject* cachedObject;\n\n  bool isStateValid() {\n    if (cancel_ocr == false && cachedEnv != NULL && cachedObject != NULL) {\n      return true;\n    } else {\n      LOGI(\"state is cancelled\");\n      return false;\n    }\n  }\n\n  void setTextBoundaries(l_uint32 x, l_uint32 y, l_uint32 width, l_uint32 height) {\n    boxSetGeometry(currentTextBox, x, y, width, height);\n  }\n\n  void initStateVariables(JNIEnv* env, jobject *object) {\n    cancel_ocr = false;\n    cachedEnv = env;\n    cachedObject = object;\n    lastProgress = 0;\n  }\n\n  void resetStateVariables() {\n    cancel_ocr = false;\n    cachedEnv = NULL;\n    cachedObject = NULL;\n    lastProgress = 0;\n    boxSetGeometry(currentTextBox, 0, 0, 0, 0);\n  }\n\n  native_data_t() {\n    currentTextBox = boxCreate(0, 0, 0, 0);\n    lastProgress = 0;\n    pix = NULL;\n    data = NULL;\n    debug = false;\n    cachedEnv = NULL;\n    cachedObject = NULL;\n    cancel_ocr = false;\n  }\n\n  ~native_data_t() {\n\t  boxDestroy(&currentTextBox);\n  }\n};\n\n/**\n * Callback for Tesseract's monitor to cancel recognition.\n */\nbool cancelFunc(void* cancel_this, int words) {\n  native_data_t *nat = (native_data_t*)cancel_this;\n  return nat->cancel_ocr;\n}\n\n/**\n * Callback for Tesseract's monitor to update progress.\n */\nbool progressJavaCallback(ETEXT_DESC* monitor, int left, int right, int top, int bottom) {\n  native_data_t *nat = (native_data_t*)monitor->cancel_this;\n  l_int32 progress = monitor->progress;\n  if (nat->isStateValid() && nat->currentTextBox != NULL) {\n    if (progress > nat->lastProgress || left != 0 || right != 0 || top != 0 || bottom != 0) {\n      int x, y, width, height;\n      boxGetGeometry(nat->currentTextBox, &x, &y, &width, &height);\n      nat->cachedEnv->CallVoidMethod(*(nat->cachedObject), method_onProgressValues, progress,\n              (jint) left, (jint) right, (jint) top, (jint) bottom,\n              (jint) x, (jint) (x + width), (jint) (y + height), (jint) y);\n      nat->lastProgress = progress;\n    }\n  }\n  return true;\n}\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\njint JNI_OnLoad(JavaVM* vm, void* reserved) {\n  JNIEnv *env;\n\n  if (vm->GetEnv((void**) &env, JNI_VERSION_1_6) != JNI_OK) {\n    LOGE(\"Failed to get the environment using GetEnv()\");\n    return -1;\n  }\n\n  return JNI_VERSION_1_6;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClassInit(JNIEnv* env, \n                                                                       jclass clazz) {\n\n  method_onProgressValues = env->GetMethodID(clazz, \"onProgressValues\", \"(IIIIIIIII)V\");\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeConstruct(JNIEnv* env,\n                                                                       jobject object) {\n\n  native_data_t *nat = new native_data_t;\n\n  if (nat == NULL) {\n    LOGE(\"%s: out of memory!\", __FUNCTION__);\n    return 0;\n  }\n\n  return (jlong) nat;\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInit(JNIEnv *env,\n                                                                      jobject thiz,\n                                                                      jlong mNativeData,\n                                                                      jstring dir,\n                                                                      jstring lang) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  const char *c_dir = env->GetStringUTFChars(dir, NULL);\n  const char *c_lang = env->GetStringUTFChars(lang, NULL);\n\n  jboolean res = JNI_TRUE;\n\n  if (nat->api.Init(c_dir, c_lang)) {\n    LOGE(\"Could not initialize Tesseract API with language=%s!\", c_lang);\n    res = JNI_FALSE;\n  } else {\n    LOGI(\"Initialized Tesseract API with language=%s\", c_lang);\n  }\n\n  env->ReleaseStringUTFChars(dir, c_dir);\n  env->ReleaseStringUTFChars(lang, c_lang);\n\n  return res;\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeInitOem(JNIEnv *env, \n                                                                         jobject thiz,\n                                                                         jlong mNativeData,\n                                                                         jstring dir, \n                                                                         jstring lang, \n                                                                         jint mode) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  const char *c_dir = env->GetStringUTFChars(dir, NULL);\n  const char *c_lang = env->GetStringUTFChars(lang, NULL);\n\n  jboolean res = JNI_TRUE;\n\n  if (nat->api.Init(c_dir, c_lang, (tesseract::OcrEngineMode) mode)) {\n    LOGE(\"Could not initialize Tesseract API with language=%s!\", c_lang);\n    res = JNI_FALSE;\n  } else {\n    LOGI(\"Initialized Tesseract API with language=%s\", c_lang);\n  }\n\n  env->ReleaseStringUTFChars(dir, c_dir);\n  env->ReleaseStringUTFChars(lang, c_lang);\n\n  return res;\n}\n\njstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetInitLanguagesAsString(JNIEnv *env,\n                                                                                         jobject thiz,\n                                                                                         jlong mNativeData) {\n\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  const char *text = nat->api.GetInitLanguagesAsString();\n\n  jstring result = env->NewStringUTF(text);\n\n  return result;\n}\n\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImageBytes(JNIEnv *env,\n                                                                           jobject thiz,\n                                                                           jlong mNativeData,\n                                                                           jbyteArray data,\n                                                                           jint width,\n                                                                           jint height,\n                                                                           jint bpp,\n                                                                           jint bpl) {\n\n  jbyte *data_array = env->GetByteArrayElements(data, NULL);\n  int count = env->GetArrayLength(data);\n  unsigned char* imagedata = (unsigned char *) malloc(count * sizeof(unsigned char));\n\n  // This is painfully slow, but necessary because we don't know\n  // how many bits the JVM might be using to represent a byte\n  for (int i = 0; i < count; i++) {\n    imagedata[i] = (unsigned char) data_array[i];\n  }\n\n  env->ReleaseByteArrayElements(data, data_array, JNI_ABORT);\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  nat->api.SetImage(imagedata, (int) width, (int) height, (int) bpp, (int) bpl);\n\n  // Since Tesseract doesn't take ownership of the memory, we keep a pointer in the native\n  // code struct. We need to free that pointer when we release our instance of Tesseract or\n  // attempt to set a new image using one of the nativeSet* methods.\n  if (nat->data != NULL)\n    free(nat->data);\n  else if (nat->pix != NULL)\n    pixDestroy(&nat->pix);\n  nat->data = imagedata;\n  nat->pix = NULL;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetImagePix(JNIEnv *env,\n                                                                         jobject thiz,\n                                                                         jlong mNativeData,\n                                                                         jlong nativePix) {\n\n  PIX *pixs = (PIX *) nativePix;\n  PIX *pixd = pixClone(pixs);\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  if (pixd) {\n    l_int32 width = pixGetWidth(pixd);\n    l_int32 height = pixGetHeight(pixd);\n    nat->setTextBoundaries(0, 0, width, height);\n  }\n  nat->api.SetImage(pixd);\n\n  // Since Tesseract doesn't take ownership of the memory, we keep a pointer in the native\n  // code struct. We need to free that pointer when we release our instance of Tesseract or\n  // attempt to set a new image using one of the nativeSet* methods.\n  if (nat->data != NULL)\n    free(nat->data);\n  else if (nat->pix != NULL)\n    pixDestroy(&nat->pix);\n  nat->data = NULL;\n  nat->pix = pixd;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetRectangle(JNIEnv *env,\n                                                                          jobject thiz,\n                                                                          jlong mNativeData,\n                                                                          jint left,\n                                                                          jint top,\n                                                                          jint width,\n                                                                          jint height) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  nat->setTextBoundaries(left, top, width, height);\n\n  nat->api.SetRectangle(left, top, width, height);\n}\n\njstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetUTF8Text(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  nat->initStateVariables(env, &thiz);\n\n  char *text = nat->api.GetUTF8Text();\n\n  jstring result = env->NewStringUTF(text);\n\n  free(text);\n  nat->resetStateVariables();\n\n  return result;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeStop(JNIEnv *env, \n                                                                  jobject thiz,\n                                                                  jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  // Stop by setting a flag that's used by the monitor\n  nat->resetStateVariables();\n  nat->cancel_ocr = true;\n}\n\njint Java_com_googlecode_tesseract_android_TessBaseAPI_nativeMeanConfidence(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  return (jint) nat->api.MeanTextConf();\n}\n\njintArray Java_com_googlecode_tesseract_android_TessBaseAPI_nativeWordConfidences(JNIEnv *env,\n                                                                                  jobject thiz,\n                                                                                  jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  int *confs = nat->api.AllWordConfidences();\n\n  if (confs == NULL) {\n    LOGE(\"Could not get word-confidence values!\");\n    return NULL;\n  }\n\n  int len, *trav;\n  for (len = 0, trav = confs; *trav != -1; trav++, len++)\n    ;\n\n  LOG_ASSERT((confs != NULL), \"Confidence array has %d elements\", len);\n\n  jintArray ret = env->NewIntArray(len);\n\n  LOG_ASSERT((ret != NULL), \"Could not create Java confidence array!\");\n\n  env->SetIntArrayRegion(ret, 0, len, confs);\n\n  delete[] confs;\n\n  return ret;\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetVariable(JNIEnv *env,\n                                                                             jobject thiz,\n                                                                             jlong mNativeData,\n                                                                             jstring var,\n                                                                             jstring value) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  const char *c_var = env->GetStringUTFChars(var, NULL);\n  const char *c_value = env->GetStringUTFChars(value, NULL);\n\n  jboolean set = nat->api.SetVariable(c_var, c_value) ? JNI_TRUE : JNI_FALSE;\n\n  env->ReleaseStringUTFChars(var, c_var);\n  env->ReleaseStringUTFChars(value, c_value);\n\n  return set;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeClear(JNIEnv *env,\n                                                                   jobject thiz,\n                                                                   jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  nat->api.Clear();\n\n  // Call between pages or documents etc to free up memory and forget adaptive data.\n  nat->api.ClearAdaptiveClassifier();\n\n  // Since Tesseract doesn't take ownership of the memory, we keep a pointer in the native\n  // code struct. We need to free that pointer when we release our instance of Tesseract or\n  // attempt to set a new image using one of the nativeSet* methods.\n  if (nat->data != NULL)\n    free(nat->data);\n  else if (nat->pix != NULL)\n    pixDestroy(&nat->pix);\n  nat->data = NULL;\n  nat->pix = NULL;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEnd(JNIEnv *env,\n                                                                 jobject thiz,\n                                                                 jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  nat->api.End();\n\n  // Since Tesseract doesn't take ownership of the memory, we keep a pointer in the native\n  // code struct. We need to free that pointer when we release our instance of Tesseract or\n  // attempt to set a new image using one of the nativeSet* methods.\n  if (nat->data != NULL)\n    free(nat->data);\n  else if (nat->pix != NULL)\n    pixDestroy(&nat->pix);\n  nat->data = NULL;\n  nat->pix = NULL;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetDebug(JNIEnv *env,\n                                                                      jobject thiz,\n                                                                      jlong mNativeData,\n                                                                      jboolean debug) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  nat->debug = (debug == JNI_TRUE) ? TRUE : FALSE;\n}\n\njint Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetPageSegMode(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  return nat->api.GetPageSegMode();\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetPageSegMode(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData,\n                                                                            jint mode) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  nat->api.SetPageSegMode((tesseract::PageSegMode) mode);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetThresholdedImage(JNIEnv *env,\n                                                                                  jobject thiz,\n                                                                                  jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  PIX *pix = nat->api.GetThresholdedImage();\n\n  return (jlong) pix;\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetRegions(JNIEnv *env,\n                                                                         jobject thiz,\n                                                                         jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIXA *pixa = NULL;\n  BOXA *boxa;\n\n  boxa = nat->api.GetRegions(&pixa);\n\n  boxaDestroy(&boxa);\n\n  return reinterpret_cast<jlong>(pixa);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetTextlines(JNIEnv *env,\n                                                                           jobject thiz,\n                                                                           jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIXA *pixa = NULL;\n  BOXA *boxa;\n\n  boxa = nat->api.GetTextlines(&pixa, NULL);\n\n  boxaDestroy(&boxa);\n\n  return reinterpret_cast<jlong>(pixa);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetStrips(JNIEnv *env,\n                                                                        jobject thiz,\n                                                                        jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIXA *pixa = NULL;\n  BOXA *boxa;\n\n  boxa = nat->api.GetStrips(&pixa, NULL);\n\n  boxaDestroy(&boxa);\n\n  return reinterpret_cast<jlong>(pixa);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetWords(JNIEnv *env,\n                                                                       jobject thiz,\n                                                                       jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIXA *pixa = NULL;\n  BOXA *boxa;\n\n  boxa = nat->api.GetWords(&pixa);\n\n  boxaDestroy(&boxa);\n\n  return reinterpret_cast<jlong>(pixa);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetConnectedComponents(JNIEnv *env,\n                                                                                    jobject thiz,\n                                                                                    jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIXA *pixa = NULL;\n  BOXA *boxa;\n\n  boxa = nat->api.GetConnectedComponents(&pixa);\n  boxaDestroy(&boxa);\n\n  return reinterpret_cast<jlong>(pixa);\n}\n\njlong Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetResultIterator(JNIEnv *env,\n                                                                                jobject thiz,\n                                                                                jlong mNativeData) {\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  return (jlong) nat->api.GetIterator();\n}\n\njstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetHOCRText(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData,\n                                                                            jint page) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  nat->initStateVariables(env, &thiz);\n\n  ETEXT_DESC monitor;\n  monitor.progress_callback2 = progressJavaCallback;\n  monitor.cancel = cancelFunc;\n  monitor.cancel_this = nat;\n\n  char *text = nat->api.GetHOCRText(&monitor, page);\n\n  jstring result = env->NewStringUTF(text);\n\n  free(text);\n  nat->resetStateVariables();\n\n  return result;\n}\n\njstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetBoxText(JNIEnv *env,\n                                                                           jobject thiz,\n                                                                           jlong mNativeData,\n                                                                           jint page) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n\n  char *text = nat->api.GetBoxText(page);\n\n  jstring result = env->NewStringUTF(text);\n\n  free(text);\n\n  return result;\n}\n\njstring Java_com_googlecode_tesseract_android_TessBaseAPI_nativeGetVersion(JNIEnv *env,\n                                                                           jobject thiz,\n                                                                           jlong mNativeData) {\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  const char *text = nat->api.Version();\n  jstring result = env->NewStringUTF(text);\n  return result;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetInputName(JNIEnv *env,\n                                                                          jobject thiz,\n                                                                          jlong mNativeData,\n                                                                          jstring name) {\n  native_data_t *nat = (native_data_t*) mNativeData;\n  const char *c_name = env->GetStringUTFChars(name, NULL);\n  nat->api.SetInputName(c_name);\n  env->ReleaseStringUTFChars(name, c_name);\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeSetOutputName(JNIEnv *env,\n                                                                           jobject thiz,\n                                                                           jlong mNativeData,\n                                                                           jstring name) {\n  native_data_t *nat = (native_data_t*) mNativeData;\n  const char *c_name = env->GetStringUTFChars(name, NULL);\n  nat->api.SetOutputName(c_name);\n  env->ReleaseStringUTFChars(name, c_name);\n}\n\nvoid Java_com_googlecode_tesseract_android_TessBaseAPI_nativeReadConfigFile(JNIEnv *env,\n                                                                            jobject thiz,\n                                                                            jlong mNativeData,\n                                                                            jstring fileName) {\n  native_data_t *nat = (native_data_t*) mNativeData;\n  const char *c_file_name = env->GetStringUTFChars(fileName, NULL);\n  nat->api.ReadConfigFile(c_file_name);\n  env->ReleaseStringUTFChars(fileName, c_file_name);\n}\n\njlong Java_com_googlecode_tesseract_android_TessPdfRenderer_nativeCreate(JNIEnv *env,\n                                                                         jobject thiz,\n                                                                         jlong jTessBaseApi,\n                                                                         jstring outputPath) {\n  native_data_t *nat = (native_data_t*) jTessBaseApi;\n  const char *c_output_path = env->GetStringUTFChars(outputPath, NULL);\n\n  tesseract::TessPDFRenderer* result = new tesseract::TessPDFRenderer(c_output_path, nat->api.GetDatapath());\n\n  env->ReleaseStringUTFChars(outputPath, c_output_path);\n\n  return (jlong) result;\n}\n\nvoid Java_com_googlecode_tesseract_android_TessPdfRenderer_nativeRecycle(JNIEnv *env,\n                                                                         jobject thiz,\n                                                                         jlong jPointer) {\n  tesseract::TessPDFRenderer* renderer = (tesseract::TessPDFRenderer*) jPointer;\n  delete renderer;\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeBeginDocument(JNIEnv *env,\n                                                                               jobject thiz,\n                                                                               jlong jRenderer,\n                                                                               jstring title) {\n\n  const char *c_title = env->GetStringUTFChars(title, NULL);\n  tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer;\n\n  bool res = pdfRenderer->BeginDocument(c_title);\n\n  env->ReleaseStringUTFChars(title, c_title);\n\n  return (jboolean) (res ? JNI_TRUE : JNI_FALSE);\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeEndDocument(JNIEnv *env,\n                                                                             jobject thiz,\n                                                                             jlong jRenderer) {\n\n  tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer;\n  return pdfRenderer->EndDocument();\n}\n\njboolean Java_com_googlecode_tesseract_android_TessBaseAPI_nativeAddPageToDocument(JNIEnv *env,\n                                                                                   jobject thiz,\n                                                                                   jlong mNativeData,\n                                                                                   jlong jPix,\n                                                                                   jstring jPath,\n                                                                                   jlong jRenderer) {\n\n  tesseract::TessPDFRenderer* pdfRenderer = (tesseract::TessPDFRenderer*) jRenderer;\n\n  native_data_t *nat = (native_data_t*) mNativeData;\n  PIX* pix = (PIX*) jPix;\n  const char *inputImage = env->GetStringUTFChars(jPath, NULL);\n\n  nat->api.ProcessPage(pix, 0, inputImage, NULL, 0, pdfRenderer);\n\n  env->ReleaseStringUTFChars(jPath, inputImage);\n\n  return true;\n}\n\n#ifdef __cplusplus\n}\n#endif\n"
  },
  {
    "path": "tess-two/jni/libjpeg/Android.mk",
    "content": "LOCAL_PATH := $(call my-dir)\n\ninclude $(CLEAR_VARS)\n\nLOCAL_MODULE := libjpgt_static\n\nLOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)\n\nLOCAL_SRC_FILES := \\\n        jaricom.c \\\n        jcapimin.c \\\n        jcapistd.c \\\n        jcarith.c \\\n        jccoefct.c \\\n        jccolor.c \\\n        jcdctmgr.c \\\n        jchuff.c \\\n        jcinit.c \\\n        jcmainct.c \\\n        jcmarker.c \\\n        jcmaster.c \\\n        jcomapi.c \\\n        jcparam.c \\\n        jcprepct.c \\\n        jcsample.c \\\n        jctrans.c \\\n        jdapimin.c \\\n        jdapistd.c \\\n        jdarith.c \\\n        jdatadst.c \\\n        jdatasrc.c \\\n        jdcoefct.c \\\n        jdcolor.c \\\n        jddctmgr.c \\\n        jdhuff.c \\\n        jdinput.c \\\n        jdmainct.c \\\n        jdmarker.c \\\n        jdmaster.c \\\n        jdmerge.c \\\n        jdpostct.c \\\n        jdsample.c \\\n        jdtrans.c \\\n        jerror.c \\\n        jfdctflt.c \\\n        jfdctfst.c \\\n        jfdctint.c \\\n        jidctflt.c \\\n        jidctfst.c \\\n        jidctint.c \\\n        jquant1.c \\\n        jquant2.c \\\n        jutils.c \\\n        jmemmgr.c \\\n        jmemname.c\n\nLOCAL_CFLAGS := \\\n  -include stdlib.h \\\n  -Wno-deprecated-declarations \\\n  -Wno-pointer-sign \\\n  -Wno-implicit-function-declaration\n\ninclude $(BUILD_STATIC_LIBRARY)\n"
  },
  {
    "path": "tess-two/jni/libjpeg/Makefile.am",
    "content": "## Process this file with automake to produce Makefile.in\n#\n#  Automake Makefile for the JPEG library\n#\n#  This file is written by Bob Friesenhahn, Guido Vollbeding\n#\n\n# Sources to build library\nLIBSOURCES = jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c @MEMORYMGR@.c\n\n# System dependent sources\nSYSDEPSOURCES = jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n\n# Headers which are installed to support the library\nINSTINCLUDES  = jerror.h jmorecfg.h jpeglib.h\n\n# Headers which are not installed\nOTHERINCLUDES = cderror.h cdjpeg.h jdct.h jinclude.h jmemsys.h jpegint.h \\\n        jversion.h transupp.h\n\n# Manual pages (Automake uses 'MANS' for itself)\nDISTMANS= cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 wrjpgcom.1\n\n# Other documentation files\nDOCS= README install.txt usage.txt wizard.txt example.c libjpeg.txt \\\n        structure.txt coderules.txt filelist.txt change.log\n\n# Makefiles for various systems\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\n\n# Configuration files\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\n\n# Support scripts for configure\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\n\n# Miscellaneous support files\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\n\n# Test support files\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\n\n# libtool libraries to build\nlib_LTLIBRARIES = libjpeg.la\n\n# Library sources for libjpeg.la\nlibjpeg_la_SOURCES = $(LIBSOURCES)\n\n# LDFLAGS for libjpeg.la\nlibjpeg_la_LDFLAGS = -no-undefined \\\n        -version-info $(JPEG_LIB_VERSION)\n\nif HAVE_LD_VERSION_SCRIPT\n  libjpeg_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libjpeg.map\nendif\n\n# Executables to build\nbin_PROGRAMS = cjpeg djpeg jpegtran rdjpgcom wrjpgcom\n\n# Executable sources & libs\ncjpeg_SOURCES    = cjpeg.c rdppm.c rdgif.c rdtarga.c rdrle.c rdbmp.c \\\n        rdswitch.c cdjpeg.c\ncjpeg_LDADD      = libjpeg.la\ndjpeg_SOURCES    = djpeg.c wrppm.c wrgif.c wrtarga.c wrrle.c wrbmp.c \\\n        rdcolmap.c cdjpeg.c\ndjpeg_LDADD      = libjpeg.la\njpegtran_SOURCES = jpegtran.c rdswitch.c cdjpeg.c transupp.c\njpegtran_LDADD   = libjpeg.la\nrdjpgcom_SOURCES = rdjpgcom.c\nwrjpgcom_SOURCES = wrjpgcom.c\n\n# Manual pages to install\nman_MANS = $(DISTMANS)\n\n# Headers to install\ninclude_HEADERS = $(INSTINCLUDES)\n\n# Other distributed headers\nnoinst_HEADERS = $(OTHERINCLUDES)\n\n# Other distributed files\nEXTRA_DIST =  $(DOCS) $(DISTMANS) $(MKFILES) $(CONFIGFILES) $(SYSDEPSOURCES) \\\n        $(OTHERFILES) $(TESTFILES)\n\n# Files to be cleaned\nCLEANFILES = testout.ppm testout.bmp testout.jpg testoutp.ppm testoutp.jpg \\\n        testoutt.jpg\n\n# Install jconfig.h\ninstall-data-local:\n\t$(mkinstalldirs) $(DESTDIR)$(includedir)\n\t$(INSTALL_HEADER) jconfig.h $(DESTDIR)$(includedir)/jconfig.h\n\n# Uninstall jconfig.h\nuninstall-local:\n\trm -f $(DESTDIR)$(includedir)/jconfig.h\n\n# Run tests\ntest: check-local\ncheck-local:\n\trm -f testout*\n\t./djpeg -dct int -ppm -outfile testout.ppm  $(srcdir)/testorig.jpg\n\t./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  $(srcdir)/testorig.jpg\n\t./cjpeg -dct int -outfile testout.jpg  $(srcdir)/testimg.ppm\n\t./djpeg -dct int -ppm -outfile testoutp.ppm $(srcdir)/testprog.jpg\n\t./cjpeg -dct int -progressive -opt -outfile testoutp.jpg $(srcdir)/testimg.ppm\n\t./jpegtran -outfile testoutt.jpg $(srcdir)/testprog.jpg\n\tcmp $(srcdir)/testimg.ppm testout.ppm\n\tcmp $(srcdir)/testimg.bmp testout.bmp\n\tcmp $(srcdir)/testimg.jpg testout.jpg\n\tcmp $(srcdir)/testimg.ppm testoutp.ppm\n\tcmp $(srcdir)/testimgp.jpg testoutp.jpg\n\tcmp $(srcdir)/testorig.jpg testoutt.jpg\n"
  },
  {
    "path": "tess-two/jni/libjpeg/README",
    "content": "The Independent JPEG Group's JPEG software\n==========================================\n\nREADME for release 9b of 17-Jan-2016\n====================================\n\nThis distribution contains the ninth public release of the Independent JPEG\nGroup's free JPEG software.  You are welcome to redistribute this software and\nto use it for any purpose, subject to the conditions under LEGAL ISSUES, below.\n\nThis software is the work of Tom Lane, Guido Vollbeding, Philip Gladstone,\nBill Allombert, Jim Boucher, Lee Crocker, Bob Friesenhahn, Ben Jackson,\nJulian Minguillon, Luis Ortiz, George Phillips, Davide Rossi, Ge' Weijers,\nand other members of the Independent JPEG Group.\n\nIJG is not affiliated with the ISO/IEC JTC1/SC29/WG1 standards committee\n(previously known as JPEG, together with ITU-T SG16).\n\n\nDOCUMENTATION ROADMAP\n=====================\n\nThis file contains the following sections:\n\nOVERVIEW            General description of JPEG and the IJG software.\nLEGAL ISSUES        Copyright, lack of warranty, terms of distribution.\nREFERENCES          Where to learn more about JPEG.\nARCHIVE LOCATIONS   Where to find newer versions of this software.\nACKNOWLEDGMENTS     Special thanks.\nFILE FORMAT WARS    Software *not* to get.\nTO DO               Plans for future IJG releases.\n\nOther documentation files in the distribution are:\n\nUser documentation:\n  install.txt       How to configure and install the IJG software.\n  usage.txt         Usage instructions for cjpeg, djpeg, jpegtran,\n                    rdjpgcom, and wrjpgcom.\n  *.1               Unix-style man pages for programs (same info as usage.txt).\n  wizard.txt        Advanced usage instructions for JPEG wizards only.\n  change.log        Version-to-version change highlights.\nProgrammer and internal documentation:\n  libjpeg.txt       How to use the JPEG library in your own programs.\n  example.c         Sample code for calling the JPEG library.\n  structure.txt     Overview of the JPEG library's internal structure.\n  filelist.txt      Road map of IJG files.\n  coderules.txt     Coding style rules --- please read if you contribute code.\n\nPlease read at least the files install.txt and usage.txt.  Some information\ncan also be found in the JPEG FAQ (Frequently Asked Questions) article.  See\nARCHIVE LOCATIONS below to find out where to obtain the FAQ article.\n\nIf you want to understand how the JPEG code works, we suggest reading one or\nmore of the REFERENCES, then looking at the documentation files (in roughly\nthe order listed) before diving into the code.\n\n\nOVERVIEW\n========\n\nThis package contains C software to implement JPEG image encoding, decoding,\nand transcoding.  JPEG (pronounced \"jay-peg\") is a standardized compression\nmethod for full-color and grayscale images.\n\nThis software implements JPEG baseline, extended-sequential, and progressive\ncompression processes.  Provision is made for supporting all variants of these\nprocesses, although some uncommon parameter settings aren't implemented yet.\nWe have made no provision for supporting the hierarchical or lossless\nprocesses defined in the standard.\n\nWe provide a set of library routines for reading and writing JPEG image files,\nplus two sample applications \"cjpeg\" and \"djpeg\", which use the library to\nperform conversion between JPEG and some other popular image file formats.\nThe library is intended to be reused in other applications.\n\nIn order to support file conversion and viewing software, we have included\nconsiderable functionality beyond the bare JPEG coding/decoding capability;\nfor example, the color quantization modules are not strictly part of JPEG\ndecoding, but they are essential for output to colormapped file formats or\ncolormapped displays.  These extra functions can be compiled out of the\nlibrary if not required for a particular application.\n\nWe have also included \"jpegtran\", a utility for lossless transcoding between\ndifferent JPEG processes, and \"rdjpgcom\" and \"wrjpgcom\", two simple\napplications for inserting and extracting textual comments in JFIF files.\n\nThe emphasis in designing this software has been on achieving portability and\nflexibility, while also making it fast enough to be useful.  In particular,\nthe software is not intended to be read as a tutorial on JPEG.  (See the\nREFERENCES section for introductory material.)  Rather, it is intended to\nbe reliable, portable, industrial-strength code.  We do not claim to have\nachieved that goal in every aspect of the software, but we strive for it.\n\nWe welcome the use of this software as a component of commercial products.\nNo royalty is required, but we do ask for an acknowledgement in product\ndocumentation, as described under LEGAL ISSUES.\n\n\nLEGAL ISSUES\n============\n\nIn plain English:\n\n1. We don't promise that this software works.  (But if you find any bugs,\n   please let us know!)\n2. You can use this software for whatever you want.  You don't have to pay us.\n3. You may not pretend that you wrote this software.  If you use it in a\n   program, you must acknowledge somewhere in your documentation that\n   you've used the IJG code.\n\nIn legalese:\n\nThe authors make NO WARRANTY or representation, either express or implied,\nwith respect to this software, its quality, accuracy, merchantability, or\nfitness for a particular purpose.  This software is provided \"AS IS\", and you,\nits user, assume the entire risk as to its quality and accuracy.\n\nThis software is copyright (C) 1991-2016, Thomas G. Lane, Guido Vollbeding.\nAll Rights Reserved except as specified below.\n\nPermission is hereby granted to use, copy, modify, and distribute this\nsoftware (or portions thereof) for any purpose, without fee, subject to these\nconditions:\n(1) If any part of the source code for this software is distributed, then this\nREADME file must be included, with this copyright and no-warranty notice\nunaltered; and any additions, deletions, or changes to the original files\nmust be clearly indicated in accompanying documentation.\n(2) If only executable code is distributed, then the accompanying\ndocumentation must state that \"this software is based in part on the work of\nthe Independent JPEG Group\".\n(3) Permission for use of this software is granted only if the user accepts\nfull responsibility for any undesirable consequences; the authors accept\nNO LIABILITY for damages of any kind.\n\nThese conditions apply to any software derived from or based on the IJG code,\nnot just to the unmodified library.  If you use our work, you ought to\nacknowledge us.\n\nPermission is NOT granted for the use of any IJG author's name or company name\nin advertising or publicity relating to this software or products derived from\nit.  This software may be referred to only as \"the Independent JPEG Group's\nsoftware\".\n\nWe specifically permit and encourage the use of this software as the basis of\ncommercial products, provided that all warranty or liability claims are\nassumed by the product vendor.\n\n\nThe Unix configuration script \"configure\" was produced with GNU Autoconf.\nIt is copyright by the Free Software Foundation but is freely distributable.\nThe same holds for its supporting scripts (config.guess, config.sub,\nltmain.sh).  Another support script, install-sh, is copyright by X Consortium\nbut is also freely distributable.\n\nThe IJG distribution formerly included code to read and write GIF files.\nTo avoid entanglement with the Unisys LZW patent (now expired), GIF reading\nsupport has been removed altogether, and the GIF writer has been simplified\nto produce \"uncompressed GIFs\".  This technique does not use the LZW\nalgorithm; the resulting GIF files are larger than usual, but are readable\nby all standard GIF decoders.\n\n\nREFERENCES\n==========\n\nWe recommend reading one or more of these references before trying to\nunderstand the innards of the JPEG software.\n\nThe best short technical introduction to the JPEG compression algorithm is\n\tWallace, Gregory K.  \"The JPEG Still Picture Compression Standard\",\n\tCommunications of the ACM, April 1991 (vol. 34 no. 4), pp. 30-44.\n(Adjacent articles in that issue discuss MPEG motion picture compression,\napplications of JPEG, and related topics.)  If you don't have the CACM issue\nhandy, a PDF file containing a revised version of Wallace's article is\navailable at http://www.ijg.org/files/Wallace.JPEG.pdf.  The file (actually\na preprint for an article that appeared in IEEE Trans. Consumer Electronics)\nomits the sample images that appeared in CACM, but it includes corrections\nand some added material.  Note: the Wallace article is copyright ACM and IEEE,\nand it may not be used for commercial purposes.\n\nA somewhat less technical, more leisurely introduction to JPEG can be found in\n\"The Data Compression Book\" by Mark Nelson and Jean-loup Gailly, published by\nM&T Books (New York), 2nd ed. 1996, ISBN 1-55851-434-1.  This book provides\ngood explanations and example C code for a multitude of compression methods\nincluding JPEG.  It is an excellent source if you are comfortable reading C\ncode but don't know much about data compression in general.  The book's JPEG\nsample code is far from industrial-strength, but when you are ready to look\nat a full implementation, you've got one here...\n\nThe best currently available description of JPEG is the textbook \"JPEG Still\nImage Data Compression Standard\" by William B. Pennebaker and Joan L.\nMitchell, published by Van Nostrand Reinhold, 1993, ISBN 0-442-01272-1.\nPrice US$59.95, 638 pp.  The book includes the complete text of the ISO JPEG\nstandards (DIS 10918-1 and draft DIS 10918-2).\nAlthough this is by far the most detailed and comprehensive exposition of\nJPEG publicly available, we point out that it is still missing an explanation\nof the most essential properties and algorithms of the underlying DCT\ntechnology.\nIf you think that you know about DCT-based JPEG after reading this book,\nthen you are in delusion.  The real fundamentals and corresponding potential\nof DCT-based JPEG are not publicly known so far, and that is the reason for\nall the mistaken developments taking place in the image coding domain.\n\nThe original JPEG standard is divided into two parts, Part 1 being the actual\nspecification, while Part 2 covers compliance testing methods.  Part 1 is\ntitled \"Digital Compression and Coding of Continuous-tone Still Images,\nPart 1: Requirements and guidelines\" and has document numbers ISO/IEC IS\n10918-1, ITU-T T.81.  Part 2 is titled \"Digital Compression and Coding of\nContinuous-tone Still Images, Part 2: Compliance testing\" and has document\nnumbers ISO/IEC IS 10918-2, ITU-T T.83.\nIJG JPEG 8 introduced an implementation of the JPEG SmartScale extension\nwhich is specified in two documents:  A contributed document at ITU and ISO\nwith title \"ITU-T JPEG-Plus Proposal for Extending ITU-T T.81 for Advanced\nImage Coding\", April 2006, Geneva, Switzerland.  The latest version of this\ndocument is Revision 3.  And a contributed document ISO/IEC JTC1/SC29/WG1 N\n5799 with title \"Evolution of JPEG\", June/July 2011, Berlin, Germany.\nIJG JPEG 9 introduces a reversible color transform for improved lossless\ncompression which is described in a contributed document ISO/IEC JTC1/SC29/\nWG1 N 6080 with title \"JPEG 9 Lossless Coding\", June/July 2012, Paris,\nFrance.\n\nThe JPEG standard does not specify all details of an interchangeable file\nformat.  For the omitted details we follow the \"JFIF\" conventions, version 2.\nJFIF version 1 has been adopted as Recommendation ITU-T T.871 (05/2011) :\nInformation technology - Digital compression and coding of continuous-tone\nstill images: JPEG File Interchange Format (JFIF).  It is available as a\nfree download in PDF file format from http://www.itu.int/rec/T-REC-T.871.\nA PDF file of the older JFIF document is available at\nhttp://www.w3.org/Graphics/JPEG/jfif3.pdf.\n\nThe TIFF 6.0 file format specification can be obtained by FTP from\nftp://ftp.sgi.com/graphics/tiff/TIFF6.ps.gz.  The JPEG incorporation scheme\nfound in the TIFF 6.0 spec of 3-June-92 has a number of serious problems.\nIJG does not recommend use of the TIFF 6.0 design (TIFF Compression tag 6).\nInstead, we recommend the JPEG design proposed by TIFF Technical Note #2\n(Compression tag 7).  Copies of this Note can be obtained from\nhttp://www.ijg.org/files/.  It is expected that the next revision\nof the TIFF spec will replace the 6.0 JPEG design with the Note's design.\nAlthough IJG's own code does not support TIFF/JPEG, the free libtiff library\nuses our library to implement TIFF/JPEG per the Note.\n\n\nARCHIVE LOCATIONS\n=================\n\nThe \"official\" archive site for this software is www.ijg.org.\nThe most recent released version can always be found there in\ndirectory \"files\".  This particular version will be archived as\nhttp://www.ijg.org/files/jpegsrc.v9b.tar.gz, and in Windows-compatible\n\"zip\" archive format as http://www.ijg.org/files/jpegsr9b.zip.\n\nThe JPEG FAQ (Frequently Asked Questions) article is a source of some\ngeneral information about JPEG.\nIt is available on the World Wide Web at http://www.faqs.org/faqs/jpeg-faq/\nand other news.answers archive sites, including the official news.answers\narchive at rtfm.mit.edu: ftp://rtfm.mit.edu/pub/usenet/news.answers/jpeg-faq/.\nIf you don't have Web or FTP access, send e-mail to mail-server@rtfm.mit.edu\nwith body\n\tsend usenet/news.answers/jpeg-faq/part1\n\tsend usenet/news.answers/jpeg-faq/part2\n\n\nACKNOWLEDGMENTS\n===============\n\nThank to Juergen Bruder for providing me with a copy of the common DCT\nalgorithm article, only to find out that I had come to the same result\nin a more direct and comprehensible way with a more generative approach.\n\nThank to Istvan Sebestyen and Joan L. Mitchell for inviting me to the\nITU JPEG (Study Group 16) meeting in Geneva, Switzerland.\n\nThank to Thomas Wiegand and Gary Sullivan for inviting me to the\nJoint Video Team (MPEG & ITU) meeting in Geneva, Switzerland.\n\nThank to Thomas Richter and Daniel Lee for inviting me to the\nISO/IEC JTC1/SC29/WG1 (previously known as JPEG, together with ITU-T SG16)\nmeeting in Berlin, Germany.\n\nThank to John Korejwa and Massimo Ballerini for inviting me to\nfruitful consultations in Boston, MA and Milan, Italy.\n\nThank to Hendrik Elstner, Roland Fassauer, Simone Zuck, Guenther\nMaier-Gerber, Walter Stoeber, Fred Schmitz, and Norbert Braunagel\nfor corresponding business development.\n\nThank to Nico Zschach and Dirk Stelling of the technical support team\nat the Digital Images company in Halle for providing me with extra\nequipment for configuration tests.\n\nThank to Richard F. Lyon (then of Foveon Inc.) for fruitful\ncommunication about JPEG configuration in Sigma Photo Pro software.\n\nThank to Andrew Finkenstadt for hosting the ijg.org site.\n\nLast but not least special thank to Thomas G. Lane for the original\ndesign and development of this singular software package.\n\n\nFILE FORMAT WARS\n================\n\nThe ISO/IEC JTC1/SC29/WG1 standards committee (previously known as JPEG,\ntogether with ITU-T SG16) currently promotes different formats containing\nthe name \"JPEG\" which is misleading because these formats are incompatible\nwith original DCT-based JPEG and are based on faulty technologies.\nIJG therefore does not and will not support such momentary mistakes\n(see REFERENCES).\nThere exist also distributions under the name \"OpenJPEG\" promoting such\nkind of formats which is misleading because they don't support original\nJPEG images.\nWe have no sympathy for the promotion of inferior formats.  Indeed, one of\nthe original reasons for developing this free software was to help force\nconvergence on common, interoperable format standards for JPEG files.\nDon't use an incompatible file format!\n(In any case, our decoder will remain capable of reading existing JPEG\nimage files indefinitely.)\n\nThe ISO committee pretends to be \"responsible for the popular JPEG\" in their\npublic reports which is not true because they don't respond to actual\nrequirements for the maintenance of the original JPEG specification.\nFurthermore, the ISO committee pretends to \"ensure interoperability\" with\ntheir standards which is not true because their \"standards\" support only\napplication-specific and proprietary use cases and contain mathematically\nincorrect code.\n\nThere are currently different distributions in circulation containing the\nname \"libjpeg\" which is misleading because they don't have the features and\nare incompatible with formats supported by actual IJG libjpeg distributions.\nOne of those fakes is released by members of the ISO committee and just uses\nthe name of libjpeg for misdirection of people, similar to the abuse of the\nname JPEG as described above, while having nothing in common with actual IJG\nlibjpeg distributions and containing mathematically incorrect code.\nThe other one claims to be a \"derivative\" or \"fork\" of the original libjpeg,\nbut violates the license conditions as described under LEGAL ISSUES above\nand violates basic C programming properties.\nWe have no sympathy for the release of misleading, incorrect and illegal\ndistributions derived from obsolete code bases.\nDon't use an obsolete code base!\n\nAccording to the UCC (Uniform Commercial Code) law, IJG has the lawful and\nlegal right to foreclose on certain standardization bodies and other\ninstitutions or corporations that knowingly perform substantial and\nsystematic deceptive acts and practices, fraud, theft, and damaging of the\nvalue of the people of this planet without their knowing, willing and\nintentional consent.\nThe titles, ownership, and rights of these institutions and all their assets\nare now duly secured and held in trust for the free people of this planet.\nPeople of the planet, on every country, may have a financial interest in\nthe assets of these former principals, agents, and beneficiaries of the\nforeclosed institutions and corporations.\nIJG asserts what is: that each man, woman, and child has unalienable value\nand rights granted and deposited in them by the Creator and not any one of\nthe people is subordinate to any artificial principality, corporate fiction\nor the special interest of another without their appropriate knowing,\nwilling and intentional consent made by contract or accommodation agreement.\nIJG expresses that which already was.\nThe people have already determined and demanded that public administration\nentities, national governments, and their supporting judicial systems must\nbe fully transparent, accountable, and liable.\nIJG has secured the value for all concerned free people of the planet.\n\nA partial list of foreclosed institutions and corporations (\"Hall of Shame\")\nis currently prepared and will be published later.\n\n\nTO DO\n=====\n\nVersion 9 is the second release of a new generation JPEG standard\nto overcome the limitations of the original JPEG specification,\nand is the first true source reference JPEG codec.\nMore features are being prepared for coming releases...\n\nPlease send bug reports, offers of help, etc. to jpeg-info@jpegclub.org.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/ar-lib",
    "content": "#! /bin/sh\n# Wrapper for Microsoft lib.exe\n\nme=ar-lib\nscriptversion=2012-03-01.08; # UTC\n\n# Copyright (C) 2010-2014 Free Software Foundation, Inc.\n# Written by Peter Rosin <peda@lysator.liu.se>.\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2, or (at your option)\n# any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that program.\n\n# This file is maintained in Automake, please report\n# bugs to <bug-automake@gnu.org> or send patches to\n# <automake-patches@gnu.org>.\n\n\n# func_error message\nfunc_error ()\n{\n  echo \"$me: $1\" 1>&2\n  exit 1\n}\n\nfile_conv=\n\n# func_file_conv build_file\n# Convert a $build file to $host form and store it in $file\n# Currently only supports Windows hosts.\nfunc_file_conv ()\n{\n  file=$1\n  case $file in\n    / | /[!/]*) # absolute file, and not a UNC file\n      if test -z \"$file_conv\"; then\n\t# lazily determine how to convert abs files\n\tcase `uname -s` in\n\t  MINGW*)\n\t    file_conv=mingw\n\t    ;;\n\t  CYGWIN*)\n\t    file_conv=cygwin\n\t    ;;\n\t  *)\n\t    file_conv=wine\n\t    ;;\n\tesac\n      fi\n      case $file_conv in\n\tmingw)\n\t  file=`cmd //C echo \"$file \" | sed -e 's/\"\\(.*\\) \" *$/\\1/'`\n\t  ;;\n\tcygwin)\n\t  file=`cygpath -m \"$file\" || echo \"$file\"`\n\t  ;;\n\twine)\n\t  file=`winepath -w \"$file\" || echo \"$file\"`\n\t  ;;\n      esac\n      ;;\n  esac\n}\n\n# func_at_file at_file operation archive\n# Iterate over all members in AT_FILE performing OPERATION on ARCHIVE\n# for each of them.\n# When interpreting the content of the @FILE, do NOT use func_file_conv,\n# since the user would need to supply preconverted file names to\n# binutils ar, at least for MinGW.\nfunc_at_file ()\n{\n  operation=$2\n  archive=$3\n  at_file_contents=`cat \"$1\"`\n  eval set x \"$at_file_contents\"\n  shift\n\n  for member\n  do\n    $AR -NOLOGO $operation:\"$member\" \"$archive\" || exit $?\n  done\n}\n\ncase $1 in\n  '')\n     func_error \"no command.  Try '$0 --help' for more information.\"\n     ;;\n  -h | --h*)\n    cat <<EOF\nUsage: $me [--help] [--version] PROGRAM ACTION ARCHIVE [MEMBER...]\n\nMembers may be specified in a file named with @FILE.\nEOF\n    exit $?\n    ;;\n  -v | --v*)\n    echo \"$me, version $scriptversion\"\n    exit $?\n    ;;\nesac\n\nif test $# -lt 3; then\n  func_error \"you must specify a program, an action and an archive\"\nfi\n\nAR=$1\nshift\nwhile :\ndo\n  if test $# -lt 2; then\n    func_error \"you must specify a program, an action and an archive\"\n  fi\n  case $1 in\n    -lib | -LIB \\\n    | -ltcg | -LTCG \\\n    | -machine* | -MACHINE* \\\n    | -subsystem* | -SUBSYSTEM* \\\n    | -verbose | -VERBOSE \\\n    | -wx* | -WX* )\n      AR=\"$AR $1\"\n      shift\n      ;;\n    *)\n      action=$1\n      shift\n      break\n      ;;\n  esac\ndone\norig_archive=$1\nshift\nfunc_file_conv \"$orig_archive\"\narchive=$file\n\n# strip leading dash in $action\naction=${action#-}\n\ndelete=\nextract=\nlist=\nquick=\nreplace=\nindex=\ncreate=\n\nwhile test -n \"$action\"\ndo\n  case $action in\n    d*) delete=yes  ;;\n    x*) extract=yes ;;\n    t*) list=yes    ;;\n    q*) quick=yes   ;;\n    r*) replace=yes ;;\n    s*) index=yes   ;;\n    S*)             ;; # the index is always updated implicitly\n    c*) create=yes  ;;\n    u*)             ;; # TODO: don't ignore the update modifier\n    v*)             ;; # TODO: don't ignore the verbose modifier\n    *)\n      func_error \"unknown action specified\"\n      ;;\n  esac\n  action=${action#?}\ndone\n\ncase $delete$extract$list$quick$replace,$index in\n  yes,* | ,yes)\n    ;;\n  yesyes*)\n    func_error \"more than one action specified\"\n    ;;\n  *)\n    func_error \"no action specified\"\n    ;;\nesac\n\nif test -n \"$delete\"; then\n  if test ! -f \"$orig_archive\"; then\n    func_error \"archive not found\"\n  fi\n  for member\n  do\n    case $1 in\n      @*)\n        func_at_file \"${1#@}\" -REMOVE \"$archive\"\n        ;;\n      *)\n        func_file_conv \"$1\"\n        $AR -NOLOGO -REMOVE:\"$file\" \"$archive\" || exit $?\n        ;;\n    esac\n  done\n\nelif test -n \"$extract\"; then\n  if test ! -f \"$orig_archive\"; then\n    func_error \"archive not found\"\n  fi\n  if test $# -gt 0; then\n    for member\n    do\n      case $1 in\n        @*)\n          func_at_file \"${1#@}\" -EXTRACT \"$archive\"\n          ;;\n        *)\n          func_file_conv \"$1\"\n          $AR -NOLOGO -EXTRACT:\"$file\" \"$archive\" || exit $?\n          ;;\n      esac\n    done\n  else\n    $AR -NOLOGO -LIST \"$archive\" | sed -e 's/\\\\/\\\\\\\\/g' | while read member\n    do\n      $AR -NOLOGO -EXTRACT:\"$member\" \"$archive\" || exit $?\n    done\n  fi\n\nelif test -n \"$quick$replace\"; then\n  if test ! -f \"$orig_archive\"; then\n    if test -z \"$create\"; then\n      echo \"$me: creating $orig_archive\"\n    fi\n    orig_archive=\n  else\n    orig_archive=$archive\n  fi\n\n  for member\n  do\n    case $1 in\n    @*)\n      func_file_conv \"${1#@}\"\n      set x \"$@\" \"@$file\"\n      ;;\n    *)\n      func_file_conv \"$1\"\n      set x \"$@\" \"$file\"\n      ;;\n    esac\n    shift\n    shift\n  done\n\n  if test -n \"$orig_archive\"; then\n    $AR -NOLOGO -OUT:\"$archive\" \"$orig_archive\" \"$@\" || exit $?\n  else\n    $AR -NOLOGO -OUT:\"$archive\" \"$@\" || exit $?\n  fi\n\nelif test -n \"$list\"; then\n  if test ! -f \"$orig_archive\"; then\n    func_error \"archive not found\"\n  fi\n  $AR -NOLOGO -LIST \"$archive\" || exit $?\nfi\n"
  },
  {
    "path": "tess-two/jni/libjpeg/cderror.h",
    "content": "/*\n * cderror.h\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 2009 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file defines the error and message codes for the cjpeg/djpeg\n * applications.  These strings are not needed as part of the JPEG library\n * proper.\n * Edit this file to add new codes, or to translate the message strings to\n * some other language.\n */\n\n/*\n * To define the enum list of message codes, include this file without\n * defining macro JMESSAGE.  To create a message string table, include it\n * again with a suitable JMESSAGE definition (see jerror.c for an example).\n */\n#ifndef JMESSAGE\n#ifndef CDERROR_H\n#define CDERROR_H\n/* First time through, define the enum list */\n#define JMAKE_ENUM_LIST\n#else\n/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */\n#define JMESSAGE(code,string)\n#endif /* CDERROR_H */\n#endif /* JMESSAGE */\n\n#ifdef JMAKE_ENUM_LIST\n\ntypedef enum {\n\n#define JMESSAGE(code,string)\tcode ,\n\n#endif /* JMAKE_ENUM_LIST */\n\nJMESSAGE(JMSG_FIRSTADDONCODE=1000, NULL) /* Must be first entry! */\n\n#ifdef BMP_SUPPORTED\nJMESSAGE(JERR_BMP_BADCMAP, \"Unsupported BMP colormap format\")\nJMESSAGE(JERR_BMP_BADDEPTH, \"Only 8- and 24-bit BMP files are supported\")\nJMESSAGE(JERR_BMP_BADHEADER, \"Invalid BMP file: bad header length\")\nJMESSAGE(JERR_BMP_BADPLANES, \"Invalid BMP file: biPlanes not equal to 1\")\nJMESSAGE(JERR_BMP_COLORSPACE, \"BMP output must be grayscale or RGB\")\nJMESSAGE(JERR_BMP_COMPRESSED, \"Sorry, compressed BMPs not yet supported\")\nJMESSAGE(JERR_BMP_EMPTY, \"Empty BMP image\")\nJMESSAGE(JERR_BMP_NOT, \"Not a BMP file - does not start with BM\")\nJMESSAGE(JTRC_BMP, \"%ux%u 24-bit BMP image\")\nJMESSAGE(JTRC_BMP_MAPPED, \"%ux%u 8-bit colormapped BMP image\")\nJMESSAGE(JTRC_BMP_OS2, \"%ux%u 24-bit OS2 BMP image\")\nJMESSAGE(JTRC_BMP_OS2_MAPPED, \"%ux%u 8-bit colormapped OS2 BMP image\")\n#endif /* BMP_SUPPORTED */\n\n#ifdef GIF_SUPPORTED\nJMESSAGE(JERR_GIF_BUG, \"GIF output got confused\")\nJMESSAGE(JERR_GIF_CODESIZE, \"Bogus GIF codesize %d\")\nJMESSAGE(JERR_GIF_COLORSPACE, \"GIF output must be grayscale or RGB\")\nJMESSAGE(JERR_GIF_IMAGENOTFOUND, \"Too few images in GIF file\")\nJMESSAGE(JERR_GIF_NOT, \"Not a GIF file\")\nJMESSAGE(JTRC_GIF, \"%ux%ux%d GIF image\")\nJMESSAGE(JTRC_GIF_BADVERSION,\n\t \"Warning: unexpected GIF version number '%c%c%c'\")\nJMESSAGE(JTRC_GIF_EXTENSION, \"Ignoring GIF extension block of type 0x%02x\")\nJMESSAGE(JTRC_GIF_NONSQUARE, \"Caution: nonsquare pixels in input\")\nJMESSAGE(JWRN_GIF_BADDATA, \"Corrupt data in GIF file\")\nJMESSAGE(JWRN_GIF_CHAR, \"Bogus char 0x%02x in GIF file, ignoring\")\nJMESSAGE(JWRN_GIF_ENDCODE, \"Premature end of GIF image\")\nJMESSAGE(JWRN_GIF_NOMOREDATA, \"Ran out of GIF bits\")\n#endif /* GIF_SUPPORTED */\n\n#ifdef PPM_SUPPORTED\nJMESSAGE(JERR_PPM_COLORSPACE, \"PPM output must be grayscale or RGB\")\nJMESSAGE(JERR_PPM_NONNUMERIC, \"Nonnumeric data in PPM file\")\nJMESSAGE(JERR_PPM_NOT, \"Not a PPM/PGM file\")\nJMESSAGE(JTRC_PGM, \"%ux%u PGM image\")\nJMESSAGE(JTRC_PGM_TEXT, \"%ux%u text PGM image\")\nJMESSAGE(JTRC_PPM, \"%ux%u PPM image\")\nJMESSAGE(JTRC_PPM_TEXT, \"%ux%u text PPM image\")\n#endif /* PPM_SUPPORTED */\n\n#ifdef RLE_SUPPORTED\nJMESSAGE(JERR_RLE_BADERROR, \"Bogus error code from RLE library\")\nJMESSAGE(JERR_RLE_COLORSPACE, \"RLE output must be grayscale or RGB\")\nJMESSAGE(JERR_RLE_DIMENSIONS, \"Image dimensions (%ux%u) too large for RLE\")\nJMESSAGE(JERR_RLE_EMPTY, \"Empty RLE file\")\nJMESSAGE(JERR_RLE_EOF, \"Premature EOF in RLE header\")\nJMESSAGE(JERR_RLE_MEM, \"Insufficient memory for RLE header\")\nJMESSAGE(JERR_RLE_NOT, \"Not an RLE file\")\nJMESSAGE(JERR_RLE_TOOMANYCHANNELS, \"Cannot handle %d output channels for RLE\")\nJMESSAGE(JERR_RLE_UNSUPPORTED, \"Cannot handle this RLE setup\")\nJMESSAGE(JTRC_RLE, \"%ux%u full-color RLE file\")\nJMESSAGE(JTRC_RLE_FULLMAP, \"%ux%u full-color RLE file with map of length %d\")\nJMESSAGE(JTRC_RLE_GRAY, \"%ux%u grayscale RLE file\")\nJMESSAGE(JTRC_RLE_MAPGRAY, \"%ux%u grayscale RLE file with map of length %d\")\nJMESSAGE(JTRC_RLE_MAPPED, \"%ux%u colormapped RLE file with map of length %d\")\n#endif /* RLE_SUPPORTED */\n\n#ifdef TARGA_SUPPORTED\nJMESSAGE(JERR_TGA_BADCMAP, \"Unsupported Targa colormap format\")\nJMESSAGE(JERR_TGA_BADPARMS, \"Invalid or unsupported Targa file\")\nJMESSAGE(JERR_TGA_COLORSPACE, \"Targa output must be grayscale or RGB\")\nJMESSAGE(JTRC_TGA, \"%ux%u RGB Targa image\")\nJMESSAGE(JTRC_TGA_GRAY, \"%ux%u grayscale Targa image\")\nJMESSAGE(JTRC_TGA_MAPPED, \"%ux%u colormapped Targa image\")\n#else\nJMESSAGE(JERR_TGA_NOTCOMP, \"Targa support was not compiled\")\n#endif /* TARGA_SUPPORTED */\n\nJMESSAGE(JERR_BAD_CMAP_FILE,\n\t \"Color map file is invalid or of unsupported format\")\nJMESSAGE(JERR_TOO_MANY_COLORS,\n\t \"Output file format cannot handle %d colormap entries\")\nJMESSAGE(JERR_UNGETC_FAILED, \"ungetc failed\")\n#ifdef TARGA_SUPPORTED\nJMESSAGE(JERR_UNKNOWN_FORMAT,\n\t \"Unrecognized input file format --- perhaps you need -targa\")\n#else\nJMESSAGE(JERR_UNKNOWN_FORMAT, \"Unrecognized input file format\")\n#endif\nJMESSAGE(JERR_UNSUPPORTED_FORMAT, \"Unsupported output file format\")\n\n#ifdef JMAKE_ENUM_LIST\n\n  JMSG_LASTADDONCODE\n} ADDON_MESSAGE_CODE;\n\n#undef JMAKE_ENUM_LIST\n#endif /* JMAKE_ENUM_LIST */\n\n/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */\n#undef JMESSAGE\n"
  },
  {
    "path": "tess-two/jni/libjpeg/cdjpeg.c",
    "content": "/*\n * cdjpeg.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains common support routines used by the IJG application\n * programs (cjpeg, djpeg, jpegtran).\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n#include <ctype.h>\t\t/* to declare isupper(), tolower() */\n#ifdef NEED_SIGNAL_CATCHER\n#include <signal.h>\t\t/* to declare signal() */\n#endif\n#ifdef USE_SETMODE\n#include <fcntl.h>\t\t/* to declare setmode()'s parameter macros */\n/* If you have setmode() but not <io.h>, just delete this line: */\n#include <io.h>\t\t\t/* to declare setmode() */\n#endif\n\n\n/*\n * Signal catcher to ensure that temporary files are removed before aborting.\n * NB: for Amiga Manx C this is actually a global routine named _abort();\n * we put \"#define signal_catcher _abort\" in jconfig.h.  Talk about bogus...\n */\n\n#ifdef NEED_SIGNAL_CATCHER\n\nstatic j_common_ptr sig_cinfo;\n\nvoid\t\t\t\t/* must be global for Manx C */\nsignal_catcher (int signum)\n{\n  if (sig_cinfo != NULL) {\n    if (sig_cinfo->err != NULL) /* turn off trace output */\n      sig_cinfo->err->trace_level = 0;\n    jpeg_destroy(sig_cinfo);\t/* clean up memory allocation & temp files */\n  }\n  exit(EXIT_FAILURE);\n}\n\n\nGLOBAL(void)\nenable_signal_catcher (j_common_ptr cinfo)\n{\n  sig_cinfo = cinfo;\n#ifdef SIGINT\t\t\t/* not all systems have SIGINT */\n  signal(SIGINT, signal_catcher);\n#endif\n#ifdef SIGTERM\t\t\t/* not all systems have SIGTERM */\n  signal(SIGTERM, signal_catcher);\n#endif\n}\n\n#endif\n\n\n/*\n * Optional progress monitor: display a percent-done figure on stderr.\n */\n\n#ifdef PROGRESS_REPORT\n\nMETHODDEF(void)\nprogress_monitor (j_common_ptr cinfo)\n{\n  cd_progress_ptr prog = (cd_progress_ptr) cinfo->progress;\n  int total_passes = prog->pub.total_passes + prog->total_extra_passes;\n  int percent_done = (int) (prog->pub.pass_counter*100L/prog->pub.pass_limit);\n\n  if (percent_done != prog->percent_done) {\n    prog->percent_done = percent_done;\n    if (total_passes > 1) {\n      fprintf(stderr, \"\\rPass %d/%d: %3d%% \",\n\t      prog->pub.completed_passes + prog->completed_extra_passes + 1,\n\t      total_passes, percent_done);\n    } else {\n      fprintf(stderr, \"\\r %3d%% \", percent_done);\n    }\n    fflush(stderr);\n  }\n}\n\n\nGLOBAL(void)\nstart_progress_monitor (j_common_ptr cinfo, cd_progress_ptr progress)\n{\n  /* Enable progress display, unless trace output is on */\n  if (cinfo->err->trace_level == 0) {\n    progress->pub.progress_monitor = progress_monitor;\n    progress->completed_extra_passes = 0;\n    progress->total_extra_passes = 0;\n    progress->percent_done = -1;\n    cinfo->progress = &progress->pub;\n  }\n}\n\n\nGLOBAL(void)\nend_progress_monitor (j_common_ptr cinfo)\n{\n  /* Clear away progress display */\n  if (cinfo->err->trace_level == 0) {\n    fprintf(stderr, \"\\r                \\r\");\n    fflush(stderr);\n  }\n}\n\n#endif\n\n\n/*\n * Case-insensitive matching of possibly-abbreviated keyword switches.\n * keyword is the constant keyword (must be lower case already),\n * minchars is length of minimum legal abbreviation.\n */\n\nGLOBAL(boolean)\nkeymatch (char * arg, const char * keyword, int minchars)\n{\n  register int ca, ck;\n  register int nmatched = 0;\n\n  while ((ca = *arg++) != '\\0') {\n    if ((ck = *keyword++) == '\\0')\n      return FALSE;\t\t/* arg longer than keyword, no good */\n    if (isupper(ca))\t\t/* force arg to lcase (assume ck is already) */\n      ca = tolower(ca);\n    if (ca != ck)\n      return FALSE;\t\t/* no good */\n    nmatched++;\t\t\t/* count matched characters */\n  }\n  /* reached end of argument; fail if it's too short for unique abbrev */\n  if (nmatched < minchars)\n    return FALSE;\n  return TRUE;\t\t\t/* A-OK */\n}\n\n\n/*\n * Routines to establish binary I/O mode for stdin and stdout.\n * Non-Unix systems often require some hacking to get out of text mode.\n */\n\nGLOBAL(FILE *)\nread_stdin (void)\n{\n  FILE * input_file = stdin;\n\n#ifdef USE_SETMODE\t\t/* need to hack file mode? */\n  setmode(fileno(stdin), O_BINARY);\n#endif\n#ifdef USE_FDOPEN\t\t/* need to re-open in binary mode? */\n  if ((input_file = fdopen(fileno(stdin), READ_BINARY)) == NULL) {\n    fprintf(stderr, \"Cannot reopen stdin\\n\");\n    exit(EXIT_FAILURE);\n  }\n#endif\n  return input_file;\n}\n\n\nGLOBAL(FILE *)\nwrite_stdout (void)\n{\n  FILE * output_file = stdout;\n\n#ifdef USE_SETMODE\t\t/* need to hack file mode? */\n  setmode(fileno(stdout), O_BINARY);\n#endif\n#ifdef USE_FDOPEN\t\t/* need to re-open in binary mode? */\n  if ((output_file = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {\n    fprintf(stderr, \"Cannot reopen stdout\\n\");\n    exit(EXIT_FAILURE);\n  }\n#endif\n  return output_file;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/cdjpeg.h",
    "content": "/*\n * cdjpeg.h\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains common declarations for the sample applications\n * cjpeg and djpeg.  It is NOT used by the core JPEG library.\n */\n\n#define JPEG_CJPEG_DJPEG\t/* define proper options in jconfig.h */\n#define JPEG_INTERNAL_OPTIONS\t/* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jerror.h\"\t\t/* get library error codes too */\n#include \"cderror.h\"\t\t/* get application-specific error codes */\n\n\n/*\n * Object interface for cjpeg's source file decoding modules\n */\n\ntypedef struct cjpeg_source_struct * cjpeg_source_ptr;\n\nstruct cjpeg_source_struct {\n  JMETHOD(void, start_input, (j_compress_ptr cinfo,\n\t\t\t      cjpeg_source_ptr sinfo));\n  JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,\n\t\t\t\t       cjpeg_source_ptr sinfo));\n  JMETHOD(void, finish_input, (j_compress_ptr cinfo,\n\t\t\t       cjpeg_source_ptr sinfo));\n\n  FILE *input_file;\n\n  JSAMPARRAY buffer;\n  JDIMENSION buffer_height;\n};\n\n\n/*\n * Object interface for djpeg's output file encoding modules\n */\n\ntypedef struct djpeg_dest_struct * djpeg_dest_ptr;\n\nstruct djpeg_dest_struct {\n  /* start_output is called after jpeg_start_decompress finishes.\n   * The color map will be ready at this time, if one is needed.\n   */\n  JMETHOD(void, start_output, (j_decompress_ptr cinfo,\n\t\t\t       djpeg_dest_ptr dinfo));\n  /* Emit the specified number of pixel rows from the buffer. */\n  JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,\n\t\t\t\t djpeg_dest_ptr dinfo,\n\t\t\t\t JDIMENSION rows_supplied));\n  /* Finish up at the end of the image. */\n  JMETHOD(void, finish_output, (j_decompress_ptr cinfo,\n\t\t\t\tdjpeg_dest_ptr dinfo));\n\n  /* Target file spec; filled in by djpeg.c after object is created. */\n  FILE * output_file;\n\n  /* Output pixel-row buffer.  Created by module init or start_output.\n   * Width is cinfo->output_width * cinfo->output_components;\n   * height is buffer_height.\n   */\n  JSAMPARRAY buffer;\n  JDIMENSION buffer_height;\n};\n\n\n/*\n * cjpeg/djpeg may need to perform extra passes to convert to or from\n * the source/destination file format.  The JPEG library does not know\n * about these passes, but we'd like them to be counted by the progress\n * monitor.  We use an expanded progress monitor object to hold the\n * additional pass count.\n */\n\nstruct cdjpeg_progress_mgr {\n  struct jpeg_progress_mgr pub;\t/* fields known to JPEG library */\n  int completed_extra_passes;\t/* extra passes completed */\n  int total_extra_passes;\t/* total extra */\n  /* last printed percentage stored here to avoid multiple printouts */\n  int percent_done;\n};\n\ntypedef struct cdjpeg_progress_mgr * cd_progress_ptr;\n\n\n/* Short forms of external names for systems with brain-damaged linkers. */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jinit_read_bmp\t\tjIRdBMP\n#define jinit_write_bmp\t\tjIWrBMP\n#define jinit_read_gif\t\tjIRdGIF\n#define jinit_write_gif\t\tjIWrGIF\n#define jinit_read_ppm\t\tjIRdPPM\n#define jinit_write_ppm\t\tjIWrPPM\n#define jinit_read_rle\t\tjIRdRLE\n#define jinit_write_rle\t\tjIWrRLE\n#define jinit_read_targa\tjIRdTarga\n#define jinit_write_targa\tjIWrTarga\n#define read_quant_tables\tRdQTables\n#define read_scan_script\tRdScnScript\n#define set_quality_ratings     SetQRates\n#define set_quant_slots\t\tSetQSlots\n#define set_sample_factors\tSetSFacts\n#define read_color_map\t\tRdCMap\n#define enable_signal_catcher\tEnSigCatcher\n#define start_progress_monitor\tStProgMon\n#define end_progress_monitor\tEnProgMon\n#define read_stdin\t\tRdStdin\n#define write_stdout\t\tWrStdout\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n/* Module selection routines for I/O modules. */\n\nEXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));\nEXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t    boolean is_os2));\nEXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));\nEXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo));\nEXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));\nEXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));\nEXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));\nEXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));\nEXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));\nEXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));\n\n/* cjpeg support routines (in rdswitch.c) */\n\nEXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,\n\t\t\t\t       boolean force_baseline));\nEXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));\nEXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg,\n\t\t\t\t\t boolean force_baseline));\nEXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));\nEXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));\n\n/* djpeg support routines (in rdcolmap.c) */\n\nEXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));\n\n/* common support routines (in cdjpeg.c) */\n\nEXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));\nEXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,\n\t\t\t\t\t cd_progress_ptr progress));\nEXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));\nEXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));\nEXTERN(FILE *) read_stdin JPP((void));\nEXTERN(FILE *) write_stdout JPP((void));\n\n/* miscellaneous useful macros */\n\n#ifdef DONT_USE_B_MODE\t\t/* define mode parameters for fopen() */\n#define READ_BINARY\t\"r\"\n#define WRITE_BINARY\t\"w\"\n#else\n#ifdef VMS\t\t\t/* VMS is very nonstandard */\n#define READ_BINARY\t\"rb\", \"ctx=stm\"\n#define WRITE_BINARY\t\"wb\", \"ctx=stm\"\n#else\t\t\t\t/* standard ANSI-compliant case */\n#define READ_BINARY\t\"rb\"\n#define WRITE_BINARY\t\"wb\"\n#endif\n#endif\n\n#ifndef EXIT_FAILURE\t\t/* define exit() codes if not provided */\n#define EXIT_FAILURE  1\n#endif\n#ifndef EXIT_SUCCESS\n#ifdef VMS\n#define EXIT_SUCCESS  1\t\t/* VMS is very nonstandard */\n#else\n#define EXIT_SUCCESS  0\n#endif\n#endif\n#ifndef EXIT_WARNING\n#ifdef VMS\n#define EXIT_WARNING  1\t\t/* VMS is very nonstandard */\n#else\n#define EXIT_WARNING  2\n#endif\n#endif\n"
  },
  {
    "path": "tess-two/jni/libjpeg/change.log",
    "content": "CHANGE LOG for Independent JPEG Group's JPEG software\n\n\nVersion 9b  17-Jan-2016\n-----------------------\n\nImprovements and optimizations in DCT and color calculations.\nNormalize range limit array composition and access pattern.\nThank to Sia Furler and Maddie Ziegler for inspiration.\n\nUse merged upsample with scaled DCT sizes larger than 8.\nThank to Taylor Hatala for inspiration.\n\nCheck for excessive comment lengths in argument parsing in wrjpgcom.c.\nThank to Julian Cohen for hint.\n\nAdd makefile.b32 for use with Borland C++ 32-bit (bcc32).\nThank to Joe Slater for contribution.\n\nDocument 'f' specifier for jpegtran -crop specification.\nThank to Michele Martone for suggestion.\n\nUse defined value from header instead of hardwired number in rdswitch.c.\nThank to Robert Sprowson for hint.\n\n\nVersion 9a  19-Jan-2014\n-----------------------\n\nAdd support for wide gamut color spaces (JFIF version 2).\nImprove clarity and accuracy in color conversion modules.\nNote: Requires rebuild of test images.\n\nExtend the bit depth support to all values from 8 to 12\n(BITS_IN_JSAMPLE configuration option in jmorecfg.h).\njpegtran now supports N bits sample data precision with all N from 8 to 12\nin a single instance.  Thank to Roland Fassauer for inspiration.\n\nTry to resolve issues with new boolean type definition.\nThank also to v4hn for suggestion.\n\nEnable option to use default Huffman tables for lossless compression\n(for hardware solution), and in this case improve lossless RGB compression\nwith reversible color transform.  Thank to Benny Alexandar for hint.\n\nExtend the entropy decoding structure, so that extraneous bytes between\ncompressed scan data and following marker can be reported correctly.\nThank to Nigel Tao for hint.\n\nAdd jpegtran -wipe option and extension for -crop.\nThank to Andrew Senior, David Clunie, and Josef Schmid for suggestion.\n\n\nVersion 9  13-Jan-2013\n----------------------\n\nAdd cjpeg -rgb1 option to create an RGB JPEG file, and insert\na simple reversible color transform into the processing which\nsignificantly improves the compression.\nThe recommended command for lossless coding of RGB images is now\ncjpeg -rgb1 -block 1 -arithmetic.\nAs said, this option improves the compression significantly, but\nthe files are not compatible with JPEG decoders prior to IJG v9\ndue to the included color transform.\nThe used color transform and marker signaling is compatible with\nother JPEG standards (e.g., JPEG-LS part 2).\n\nRemove the automatic de-ANSI-fication support (Automake 1.12).\nThank also to Nitin A Kamble for suggestion.\n\nAdd remark for jpeg_mem_dest() in jdatadst.c.\nThank to Elie-Gregoire Khoury for the hint.\n\nSupport files with invalid component identifiers (created\nby Adobe PDF).  Thank to Robin Watts for the suggestion.\n\nAdapt full buffer case in jcmainct.c for use with scaled DCT.\nThank to Sergii Biloshytskyi for the suggestion.\n\nAdd type identifier for declaration of noreturn functions.\nThank to Brett L. Moore for the suggestion.\n\nCorrect argument type in format string, avoid compiler warnings.\nThank to Vincent Torri for hint.\n\nAdd missing #include directives in configuration checks, avoid\nconfiguration errors.  Thank to John Spencer for the hint.\n\n\nVersion 8d  15-Jan-2012\n-----------------------\n\nAdd cjpeg -rgb option to create RGB JPEG files.\nUsing this switch suppresses the conversion from RGB\ncolorspace input to the default YCbCr JPEG colorspace.\nThis feature allows true lossless JPEG coding of RGB color images.\nThe recommended command for this purpose is currently\ncjpeg -rgb -block 1 -arithmetic.\nSmartScale capable decoder (introduced with IJG JPEG 8) required.\nThank to Michael Koch for the initial suggestion.\n\nAdd option to disable the region adjustment in the transupp crop code.\nThank to Jeffrey Friedl for the suggestion.\n\nThank to Richard Jones and Edd Dawson for various minor corrections.\n\nThank to Akim Demaille for configure.ac cleanup.\n\n\nVersion 8c  16-Jan-2011\n-----------------------\n\nAdd option to compression library and cjpeg (-block N) to use\ndifferent DCT block size.\nAll N from 1 to 16 are possible.  Default is 8 (baseline format).\nLarger values produce higher compression,\nsmaller values produce higher quality.\nSmartScale capable decoder (introduced with IJG JPEG 8) required.\n\n\nVersion 8b  16-May-2010\n-----------------------\n\nRepair problem in new memory source manager with corrupt JPEG data.\nThank to Ted Campbell and Samuel Chun for the report.\n\nRepair problem in Makefile.am test target.\nThank to anonymous user for the report.\n\nSupport MinGW installation with automatic configure.\nThank to Volker Grabsch for the suggestion.\n\n\nVersion 8a  28-Feb-2010\n-----------------------\n\nWriting tables-only datastreams via jpeg_write_tables works again.\n\nSupport 32-bit BMPs (RGB image with Alpha channel) for read in cjpeg.\nThank to Brett Blackham for the suggestion.\n\nImprove accuracy in floating point IDCT calculation.\nThank to Robert Hooke for the hint.\n\n\nVersion 8  10-Jan-2010\n----------------------\n\njpegtran now supports the same -scale option as djpeg for \"lossless\" resize.\nAn implementation of the JPEG SmartScale extension is required for this\nfeature.  A (draft) specification of the JPEG SmartScale extension is\navailable as a contributed document at ITU and ISO.  Revision 2 or later\nof the document is required (latest document version is Revision 3).\nThe SmartScale extension will enable more features beside lossless resize\nin future implementations, as described in the document (new compression\noptions).\n\nAdd sanity check in BMP reader module to avoid cjpeg crash for empty input\nimage (thank to Isaev Ildar of ISP RAS, Moscow, RU for reporting this error).\n\nAdd data source and destination managers for read from and write to\nmemory buffers.  New API functions jpeg_mem_src and jpeg_mem_dest.\nThank to Roberto Boni from Italy for the suggestion.\n\n\nVersion 7  27-Jun-2009\n----------------------\n\nNew scaled DCTs implemented.\ndjpeg now supports scalings N/8 with all N from 1 to 16.\ncjpeg now supports scalings 8/N with all N from 1 to 16.\nScaled DCTs with size larger than 8 are now also used for resolving the\ncommon 2x2 chroma subsampling case without additional spatial resampling.\nSeparate spatial resampling for those kind of files is now only necessary\nfor N>8 scaling cases.\nFurthermore, separate scaled DCT functions are provided for direct resolving\nof the common asymmetric subsampling cases (2x1 and 1x2) without additional\nspatial resampling.\n\ncjpeg -quality option has been extended for support of separate quality\nsettings for luminance and chrominance (or in general, for every provided\nquantization table slot).\nNew API function jpeg_default_qtables() and q_scale_factor array in library.\n\nAdded -nosmooth option to cjpeg, complementary to djpeg.\nNew variable \"do_fancy_downsampling\" in library, complement to fancy\nupsampling.  Fancy upsampling now uses direct DCT scaling with sizes\nlarger than 8.  The old method is not reversible and has been removed.\n\nSupport arithmetic entropy encoding and decoding.\nAdded files jaricom.c, jcarith.c, jdarith.c.\n\nStraighten the file structure:\nRemoved files jidctred.c, jcphuff.c, jchuff.h, jdphuff.c, jdhuff.h.\n\njpegtran has a new \"lossless\" cropping feature.\n\nImplement -perfect option in jpegtran, new API function\njtransform_perfect_transform() in transupp. (DP 204_perfect.dpatch)\n\nBetter error messages for jpegtran fopen failure.\n(DP 203_jpegtran_errmsg.dpatch)\n\nFix byte order issue with 16bit PPM/PGM files in rdppm.c/wrppm.c:\naccording to Netpbm, the de facto standard implementation of the PNM formats,\nthe most significant byte is first. (DP 203_rdppm.dpatch)\n\nAdd -raw option to rdjpgcom not to mangle the output.\n(DP 205_rdjpgcom_raw.dpatch)\n\nMake rdjpgcom locale aware. (DP 201_rdjpgcom_locale.dpatch)\n\nAdd extern \"C\" to jpeglib.h.\nThis avoids the need to put extern \"C\" { ... } around #include \"jpeglib.h\"\nin your C++ application.  Defining the symbol DONT_USE_EXTERN_C in the\nconfiguration prevents this. (DP 202_jpeglib.h_c++.dpatch)\n\n\nVersion 6b  27-Mar-1998\n-----------------------\n\njpegtran has new features for lossless image transformations (rotation\nand flipping) as well as \"lossless\" reduction to grayscale.\n\njpegtran now copies comments by default; it has a -copy switch to enable\ncopying all APPn blocks as well, or to suppress comments.  (Formerly it\nalways suppressed comments and APPn blocks.)  jpegtran now also preserves\nJFIF version and resolution information.\n\nNew decompressor library feature: COM and APPn markers found in the input\nfile can be saved in memory for later use by the application.  (Before,\nyou had to code this up yourself with a custom marker processor.)\n\nThere is an unused field \"void * client_data\" now in compress and decompress\nparameter structs; this may be useful in some applications.\n\nJFIF version number information is now saved by the decoder and accepted by\nthe encoder.  jpegtran uses this to copy the source file's version number,\nto ensure \"jpegtran -copy all\" won't create bogus files that contain JFXX\nextensions but claim to be version 1.01.  Applications that generate their\nown JFXX extension markers also (finally) have a supported way to cause the\nencoder to emit JFIF version number 1.02.\n\ndjpeg's trace mode reports JFIF 1.02 thumbnail images as such, rather\nthan as unknown APP0 markers.\n\nIn -verbose mode, djpeg and rdjpgcom will try to print the contents of\nAPP12 markers as text.  Some digital cameras store useful text information\nin APP12 markers.\n\nHandling of truncated data streams is more robust: blocks beyond the one in\nwhich the error occurs will be output as uniform gray, or left unchanged\nif decoding a progressive JPEG.  The appearance no longer depends on the\nHuffman tables being used.\n\nHuffman tables are checked for validity much more carefully than before.\n\nTo avoid the Unisys LZW patent, djpeg's GIF output capability has been\nchanged to produce \"uncompressed GIFs\", and cjpeg's GIF input capability\nhas been removed altogether.  We're not happy about it either, but there\nseems to be no good alternative.\n\nThe configure script now supports building libjpeg as a shared library\non many flavors of Unix (all the ones that GNU libtool knows how to\nbuild shared libraries for).  Use \"./configure --enable-shared\" to\ntry this out.\n\nNew jconfig file and makefiles for Microsoft Visual C++ and Developer Studio.\nAlso, a jconfig file and a build script for Metrowerks CodeWarrior\non Apple Macintosh.  makefile.dj has been updated for DJGPP v2, and there\nare miscellaneous other minor improvements in the makefiles.\n\njmemmac.c now knows how to create temporary files following Mac System 7\nconventions.\n\ndjpeg's -map switch is now able to read raw-format PPM files reliably.\n\ncjpeg -progressive -restart no longer generates any unnecessary DRI markers.\n\nMultiple calls to jpeg_simple_progression for a single JPEG object\nno longer leak memory.\n\n\nVersion 6a  7-Feb-96\n--------------------\n\nLibrary initialization sequence modified to detect version mismatches\nand struct field packing mismatches between library and calling application.\nThis change requires applications to be recompiled, but does not require\nany application source code change.\n\nAll routine declarations changed to the style \"GLOBAL(type) name ...\",\nthat is, GLOBAL, LOCAL, METHODDEF, EXTERN are now macros taking the\nroutine's return type as an argument.  This makes it possible to add\nMicrosoft-style linkage keywords to all the routines by changing just\nthese macros.  Note that any application code that was using these macros\nwill have to be changed.\n\nDCT coefficient quantization tables are now stored in normal array order\nrather than zigzag order.  Application code that calls jpeg_add_quant_table,\nor otherwise manipulates quantization tables directly, will need to be\nchanged.  If you need to make such code work with either older or newer\nversions of the library, a test like \"#if JPEG_LIB_VERSION >= 61\" is\nrecommended.\n\ndjpeg's trace capability now dumps DQT tables in natural order, not zigzag\norder.  This allows the trace output to be made into a \"-qtables\" file\nmore easily.\n\nNew system-dependent memory manager module for use on Apple Macintosh.\n\nFix bug in cjpeg's -smooth option: last one or two scanlines would be\nduplicates of the prior line unless the image height mod 16 was 1 or 2.\n\nRepair minor problems in VMS, BCC, MC6 makefiles.\n\nNew configure script based on latest GNU Autoconf.\n\nCorrect the list of include files needed by MetroWerks C for ccommand().\n\nNumerous small documentation updates.\n\n\nVersion 6  2-Aug-95\n-------------------\n\nProgressive JPEG support: library can read and write full progressive JPEG\nfiles.  A \"buffered image\" mode supports incremental decoding for on-the-fly\ndisplay of progressive images.  Simply recompiling an existing IJG-v5-based\ndecoder with v6 should allow it to read progressive files, though of course\nwithout any special progressive display.\n\nNew \"jpegtran\" application performs lossless transcoding between different\nJPEG formats; primarily, it can be used to convert baseline to progressive\nJPEG and vice versa.  In support of jpegtran, the library now allows lossless\nreading and writing of JPEG files as DCT coefficient arrays.  This ability\nmay be of use in other applications.\n\nNotes for programmers:\n* We changed jpeg_start_decompress() to be able to suspend; this makes all\ndecoding modes available to suspending-input applications.  However,\nexisting applications that use suspending input will need to be changed\nto check the return value from jpeg_start_decompress().  You don't need to\ndo anything if you don't use a suspending data source.\n* We changed the interface to the virtual array routines: access_virt_array\nroutines now take a count of the number of rows to access this time.  The\nlast parameter to request_virt_array routines is now interpreted as the\nmaximum number of rows that may be accessed at once, but not necessarily\nthe height of every access.\n\n\nVersion 5b  15-Mar-95\n---------------------\n\nCorrect bugs with grayscale images having v_samp_factor > 1.\n\njpeg_write_raw_data() now supports output suspension.\n\nCorrect bugs in \"configure\" script for case of compiling in\na directory other than the one containing the source files.\n\nRepair bug in jquant1.c: sometimes didn't use as many colors as it could.\n\nBorland C makefile and jconfig file work under either MS-DOS or OS/2.\n\nMiscellaneous improvements to documentation.\n\n\nVersion 5a  7-Dec-94\n--------------------\n\nChanged color conversion roundoff behavior so that grayscale values are\nrepresented exactly.  (This causes test image files to change.)\n\nMake ordered dither use 16x16 instead of 4x4 pattern for a small quality\nimprovement.\n\nNew configure script based on latest GNU Autoconf.\nFix configure script to handle CFLAGS correctly.\nRename *.auto files to *.cfg, so that configure script still works if\nfile names have been truncated for DOS.\n\nFix bug in rdbmp.c: didn't allow for extra data between header and image.\n\nModify rdppm.c/wrppm.c to handle 2-byte raw PPM/PGM formats for 12-bit data.\n\nFix several bugs in rdrle.c.\n\nNEED_SHORT_EXTERNAL_NAMES option was broken.\n\nRevise jerror.h/jerror.c for more flexibility in message table.\n\nRepair oversight in jmemname.c NO_MKTEMP case: file could be there\nbut unreadable.\n\n\nVersion 5  24-Sep-94\n--------------------\n\nVersion 5 represents a nearly complete redesign and rewrite of the IJG\nsoftware.  Major user-visible changes include:\n  * Automatic configuration simplifies installation for most Unix systems.\n  * A range of speed vs. image quality tradeoffs are supported.\n    This includes resizing of an image during decompression: scaling down\n    by a factor of 1/2, 1/4, or 1/8 is handled very efficiently.\n  * New programs rdjpgcom and wrjpgcom allow insertion and extraction\n    of text comments in a JPEG file.\n\nThe application programmer's interface to the library has changed completely.\nNotable improvements include:\n  * We have eliminated the use of callback routines for handling the\n    uncompressed image data.  The application now sees the library as a\n    set of routines that it calls to read or write image data on a\n    scanline-by-scanline basis.\n  * The application image data is represented in a conventional interleaved-\n    pixel format, rather than as a separate array for each color channel.\n    This can save a copying step in many programs.\n  * The handling of compressed data has been cleaned up: the application can\n    supply routines to source or sink the compressed data.  It is possible to\n    suspend processing on source/sink buffer overrun, although this is not\n    supported in all operating modes.\n  * All static state has been eliminated from the library, so that multiple\n    instances of compression or decompression can be active concurrently.\n  * JPEG abbreviated datastream formats are supported, ie, quantization and\n    Huffman tables can be stored separately from the image data.\n  * And not only that, but the documentation of the library has improved\n    considerably!\n\n\nThe last widely used release before the version 5 rewrite was version 4A of\n18-Feb-93.  Change logs before that point have been discarded, since they\nare not of much interest after the rewrite.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/cjpeg.1",
    "content": ".TH CJPEG 1 \"26 July 2015\"\n.SH NAME\ncjpeg \\- compress an image file to a JPEG file\n.SH SYNOPSIS\n.B cjpeg\n[\n.I options\n]\n[\n.I filename\n]\n.LP\n.SH DESCRIPTION\n.LP\n.B cjpeg\ncompresses the named image file, or the standard input if no file is\nnamed, and produces a JPEG/JFIF file on the standard output.\nThe currently supported input file formats are: PPM (PBMPLUS color\nformat), PGM (PBMPLUS grayscale format), BMP, Targa, and RLE (Utah Raster\nToolkit format).  (RLE is supported only if the URT library is available.)\n.SH OPTIONS\nAll switch names may be abbreviated; for example,\n.B \\-grayscale\nmay be written\n.B \\-gray\nor\n.BR \\-gr .\nMost of the \"basic\" switches can be abbreviated to as little as one letter.\nUpper and lower case are equivalent (thus\n.B \\-BMP\nis the same as\n.BR \\-bmp ).\nBritish spellings are also accepted (e.g.,\n.BR \\-greyscale ),\nthough for brevity these are not mentioned below.\n.PP\nThe basic switches are:\n.TP\n.BI \\-quality \" N[,...]\"\nScale quantization tables to adjust image quality.  Quality is 0 (worst) to\n100 (best); default is 75.  (See below for more info.)\n.TP\n.B \\-grayscale\nCreate monochrome JPEG file from color input.  Be sure to use this switch when\ncompressing a grayscale BMP file, because\n.B cjpeg\nisn't bright enough to notice whether a BMP file uses only shades of gray.\nBy saying\n.BR \\-grayscale ,\nyou'll get a smaller JPEG file that takes less time to process.\n.TP\n.B \\-rgb\nCreate RGB JPEG file.\nUsing this switch suppresses the conversion from RGB\ncolorspace input to the default YCbCr JPEG colorspace.\nYou can use this switch in combination with the\n.BI \\-block \" N\"\nswitch (see below) for lossless JPEG coding.\nSee also the\n.B \\-rgb1\nswitch below.\n.TP\n.B \\-optimize\nPerform optimization of entropy encoding parameters.  Without this, default\nencoding parameters are used.\n.B \\-optimize\nusually makes the JPEG file a little smaller, but\n.B cjpeg\nruns somewhat slower and needs much more memory.  Image quality and speed of\ndecompression are unaffected by\n.BR \\-optimize .\n.TP\n.B \\-progressive\nCreate progressive JPEG file (see below).\n.TP\n.BI \\-scale \" M/N\"\nScale the output image by a factor M/N.  Currently supported scale factors are\nM/N with all N from 1 to 16, where M is the destination DCT size, which is 8\nby default (see\n.BI \\-block \" N\"\nswitch below).\n.TP\n.B \\-targa\nInput file is Targa format.  Targa files that contain an \"identification\"\nfield will not be automatically recognized by\n.BR cjpeg ;\nfor such files you must specify\n.B \\-targa\nto make\n.B cjpeg\ntreat the input as Targa format.\nFor most Targa files, you won't need this switch.\n.PP\nThe\n.B \\-quality\nswitch lets you trade off compressed file size against quality of the\nreconstructed image: the higher the quality setting, the larger the JPEG file,\nand the closer the output image will be to the original input.  Normally you\nwant to use the lowest quality setting (smallest file) that decompresses into\nsomething visually indistinguishable from the original image.  For this\npurpose the quality setting should be between 50 and 95; the default of 75 is\noften about right.  If you see defects at\n.B \\-quality\n75, then go up 5 or 10 counts at a time until you are happy with the output\nimage.  (The optimal setting will vary from one image to another.)\n.PP\n.B \\-quality\n100 will generate a quantization table of all 1's, minimizing loss in the\nquantization step (but there is still information loss in subsampling, as well\nas roundoff error).  This setting is mainly of interest for experimental\npurposes.  Quality values above about 95 are\n.B not\nrecommended for normal use; the compressed file size goes up dramatically for\nhardly any gain in output image quality.\n.PP\nIn the other direction, quality values below 50 will produce very small files\nof low image quality.  Settings around 5 to 10 might be useful in preparing an\nindex of a large image library, for example.  Try\n.B \\-quality\n2 (or so) for some amusing Cubist effects.  (Note: quality\nvalues below about 25 generate 2-byte quantization tables, which are\nconsidered optional in the JPEG standard.\n.B cjpeg\nemits a warning message when you give such a quality value, because some\nother JPEG programs may be unable to decode the resulting file.  Use\n.B \\-baseline\nif you need to ensure compatibility at low quality values.)\n.PP\nThe\n.B \\-quality\noption has been extended in IJG version 7 for support of separate quality\nsettings for luminance and chrominance (or in general, for every provided\nquantization table slot).  This feature is useful for high-quality\napplications which cannot accept the damage of color data by coarse\nsubsampling settings.  You can now easily reduce the color data amount more\nsmoothly with finer control without separate subsampling.  The resulting file\nis fully compliant with standard JPEG decoders.\nNote that the\n.B \\-quality\nratings refer to the quantization table slots, and that the last value is\nreplicated if there are more q-table slots than parameters.  The default\nq-table slots are 0 for luminance and 1 for chrominance with default tables as\ngiven in the JPEG standard.  This is compatible with the old behaviour in case\nthat only one parameter is given, which is then used for both luminance and\nchrominance (slots 0 and 1).  More or custom quantization tables can be set\nwith\n.B \\-qtables\nand assigned to components with\n.B \\-qslots\nparameter (see the \"wizard\" switches below).\n.B Caution:\nYou must explicitly add\n.BI \\-sample \" 1x1\"\nfor efficient separate color\nquality selection, since the default value used by library is 2x2!\n.PP\nThe\n.B \\-progressive\nswitch creates a \"progressive JPEG\" file.  In this type of JPEG file, the data\nis stored in multiple scans of increasing quality.  If the file is being\ntransmitted over a slow communications link, the decoder can use the first\nscan to display a low-quality image very quickly, and can then improve the\ndisplay with each subsequent scan.  The final image is exactly equivalent to a\nstandard JPEG file of the same quality setting, and the total file size is\nabout the same --- often a little smaller.\n.PP\nSwitches for advanced users:\n.TP\n.B \\-arithmetic\nUse arithmetic coding.\n.B Caution:\narithmetic coded JPEG is not yet widely implemented, so many decoders will\nbe unable to view an arithmetic coded JPEG file at all.\n.TP\n.BI \\-block \" N\"\nSet DCT block size.  All N from 1 to 16 are possible.\nDefault is 8 (baseline format).\nLarger values produce higher compression,\nsmaller values produce higher quality\n(exact DCT stage possible with 1 or 2; with the default quality of 75 and\ndefault Luminance qtable the DCT+Quantization stage is lossless for N=1).\n.B Caution:\nAn implementation of the JPEG SmartScale extension is required for this\nfeature.  SmartScale enabled JPEG is not yet widely implemented, so many\ndecoders will be unable to view a SmartScale extended JPEG file at all.\n.TP\n.B \\-rgb1\nCreate RGB JPEG file with reversible color transform.\nWorks like the\n.B \\-rgb\nswitch (see above) and inserts a simple reversible color transform\ninto the processing which significantly improves the compression.\nUse this switch in combination with the\n.BI \\-block \" N\"\nswitch (see above) for lossless JPEG coding.\n.B Caution:\nA decoder with inverse color transform support is required for\nthis feature.  Reversible color transform support is not yet\nwidely implemented, so many decoders will be unable to view\na reversible color transformed JPEG file at all.\n.TP\n.B \\-bgycc\nCreate big gamut YCC JPEG file.\nIn this type of encoding the color difference components are quantized\nfurther by a factor of 2 compared to the normal Cb/Cr values, thus creating\nspace to allow larger color values with higher saturation than the normal\ngamut limits to be encoded.  In order to compensate for the loss of color\nfidelity compared to a normal YCC encoded file, the color quantization\ntables can be adjusted accordingly.  For example,\n.B cjpeg \\-bgycc \\-quality\n80,90 will give similar results as\n.B cjpeg \\-quality\n80.\n.B Caution:\nFor correct decompression a decoder with big gamut YCC support (JFIF\nversion 2) is required.  An old decoder may or may not display a big\ngamut YCC encoded JPEG file, depending on JFIF version check and\ncorresponding warning/error configuration.  In case of a granted\ndecompression the old decoder will display the image with half\nsaturated colors.\n.TP\n.B \\-dct int\nUse integer DCT method (default).\n.TP\n.B \\-dct fast\nUse fast integer DCT (less accurate).\n.TP\n.B \\-dct float\nUse floating-point DCT method.\nThe float method is very slightly more accurate than the int method, but is\nmuch slower unless your machine has very fast floating-point hardware.  Also\nnote that results of the floating-point method may vary slightly across\nmachines, while the integer methods should give the same results everywhere.\nThe fast integer method is much less accurate than the other two.\n.TP\n.B \\-nosmooth\nDon't use high-quality downsampling.\n.TP\n.BI \\-restart \" N\"\nEmit a JPEG restart marker every N MCU rows, or every N MCU blocks if \"B\" is\nattached to the number.\n.B \\-restart 0\n(the default) means no restart markers.\n.TP\n.BI \\-smooth \" N\"\nSmooth the input image to eliminate dithering noise.  N, ranging from 1 to\n100, indicates the strength of smoothing.  0 (the default) means no smoothing.\n.TP\n.BI \\-maxmemory \" N\"\nSet limit for amount of memory to use in processing large images.  Value is\nin thousands of bytes, or millions of bytes if \"M\" is attached to the\nnumber.  For example,\n.B \\-max 4m\nselects 4000000 bytes.  If more space is needed, temporary files will be used.\n.TP\n.BI \\-outfile \" name\"\nSend output image to the named file, not to standard output.\n.TP\n.B \\-verbose\nEnable debug printout.  More\n.BR \\-v 's\ngive more output.  Also, version information is printed at startup.\n.TP\n.B \\-debug\nSame as\n.BR \\-verbose .\n.PP\nThe\n.B \\-restart\noption inserts extra markers that allow a JPEG decoder to resynchronize after\na transmission error.  Without restart markers, any damage to a compressed\nfile will usually ruin the image from the point of the error to the end of the\nimage; with restart markers, the damage is usually confined to the portion of\nthe image up to the next restart marker.  Of course, the restart markers\noccupy extra space.  We recommend\n.B \\-restart 1\nfor images that will be transmitted across unreliable networks such as Usenet.\n.PP\nThe\n.B \\-smooth\noption filters the input to eliminate fine-scale noise.  This is often useful\nwhen converting dithered images to JPEG: a moderate smoothing factor of 10 to\n50 gets rid of dithering patterns in the input file, resulting in a smaller\nJPEG file and a better-looking image.  Too large a smoothing factor will\nvisibly blur the image, however.\n.PP\nSwitches for wizards:\n.TP\n.B \\-baseline\nForce baseline-compatible quantization tables to be generated.  This clamps\nquantization values to 8 bits even at low quality settings.  (This switch is\npoorly named, since it does not ensure that the output is actually baseline\nJPEG.  For example, you can use\n.B \\-baseline\nand\n.B \\-progressive\ntogether.)\n.TP\n.BI \\-qtables \" file\"\nUse the quantization tables given in the specified text file.\n.TP\n.BI \\-qslots \" N[,...]\"\nSelect which quantization table to use for each color component.\n.TP\n.BI \\-sample \" HxV[,...]\"\nSet JPEG sampling factors for each color component.\n.TP\n.BI \\-scans \" file\"\nUse the scan script given in the specified text file.\n.PP\nThe \"wizard\" switches are intended for experimentation with JPEG.  If you\ndon't know what you are doing, \\fBdon't use them\\fR.  These switches are\ndocumented further in the file wizard.txt.\n.SH EXAMPLES\n.LP\nThis example compresses the PPM file foo.ppm with a quality factor of\n60 and saves the output as foo.jpg:\n.IP\n.B cjpeg \\-quality\n.I 60 foo.ppm\n.B >\n.I foo.jpg\n.SH HINTS\nColor GIF files are not the ideal input for JPEG; JPEG is really intended for\ncompressing full-color (24-bit) images.  In particular, don't try to convert\ncartoons, line drawings, and other images that have only a few distinct\ncolors.  GIF works great on these, JPEG does not.  If you want to convert a\nGIF to JPEG, you should experiment with\n.BR cjpeg 's\n.B \\-quality\nand\n.B \\-smooth\noptions to get a satisfactory conversion.\n.B \\-smooth 10\nor so is often helpful.\n.PP\nAvoid running an image through a series of JPEG compression/decompression\ncycles.  Image quality loss will accumulate; after ten or so cycles the image\nmay be noticeably worse than it was after one cycle.  It's best to use a\nlossless format while manipulating an image, then convert to JPEG format when\nyou are ready to file the image away.\n.PP\nThe\n.B \\-optimize\noption to\n.B cjpeg\nis worth using when you are making a \"final\" version for posting or archiving.\nIt's also a win when you are using low quality settings to make very small\nJPEG files; the percentage improvement is often a lot more than it is on\nlarger files.  (At present,\n.B \\-optimize\nmode is always selected when generating progressive JPEG files.)\n.SH ENVIRONMENT\n.TP\n.B JPEGMEM\nIf this environment variable is set, its value is the default memory limit.\nThe value is specified as described for the\n.B \\-maxmemory\nswitch.\n.B JPEGMEM\noverrides the default value specified when the program was compiled, and\nitself is overridden by an explicit\n.BR \\-maxmemory .\n.SH SEE ALSO\n.BR djpeg (1),\n.BR jpegtran (1),\n.BR rdjpgcom (1),\n.BR wrjpgcom (1)\n.br\n.BR ppm (5),\n.BR pgm (5)\n.br\nWallace, Gregory K.  \"The JPEG Still Picture Compression Standard\",\nCommunications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.\n.SH AUTHOR\nIndependent JPEG Group\n.SH BUGS\nGIF input files are no longer supported, to avoid the Unisys LZW patent\n(now expired).\n(Conversion of GIF files to JPEG is usually a bad idea anyway.)\n.PP\nNot all variants of BMP and Targa file formats are supported.\n.PP\nThe\n.B \\-targa\nswitch is not a bug, it's a feature.  (It would be a bug if the Targa format\ndesigners had not been clueless.)\n"
  },
  {
    "path": "tess-two/jni/libjpeg/cjpeg.c",
    "content": "/*\n * cjpeg.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a command-line user interface for the JPEG compressor.\n * It should work on any system with Unix- or MS-DOS-style command lines.\n *\n * Two different command line styles are permitted, depending on the\n * compile-time switch TWO_FILE_COMMANDLINE:\n *\tcjpeg [options]  inputfile outputfile\n *\tcjpeg [options]  [inputfile]\n * In the second style, output is always to standard output, which you'd\n * normally redirect to a file or pipe to some other program.  Input is\n * either from a named file or from standard input (typically redirected).\n * The second style is convenient on Unix but is unhelpful on systems that\n * don't support pipes.  Also, you MUST use the first style if your system\n * doesn't do binary I/O to stdin/stdout.\n * To simplify script writing, the \"-outfile\" switch is provided.  The syntax\n *\tcjpeg [options]  -outfile outputfile  inputfile\n * works regardless of which command line style is used.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n#include \"jversion.h\"\t\t/* for version message */\n\n#ifdef USE_CCOMMAND\t\t/* command-line reader for Macintosh */\n#ifdef __MWERKS__\n#include <SIOUX.h>              /* Metrowerks needs this */\n#include <console.h>\t\t/* ... and this */\n#endif\n#ifdef THINK_C\n#include <console.h>\t\t/* Think declares it here */\n#endif\n#endif\n\n\n/* Create the add-on message string table. */\n\n#define JMESSAGE(code,string)\tstring ,\n\nstatic const char * const cdjpeg_message_table[] = {\n#include \"cderror.h\"\n  NULL\n};\n\n\n/*\n * This routine determines what format the input file is,\n * and selects the appropriate input-reading module.\n *\n * To determine which family of input formats the file belongs to,\n * we may look only at the first byte of the file, since C does not\n * guarantee that more than one character can be pushed back with ungetc.\n * Looking at additional bytes would require one of these approaches:\n *     1) assume we can fseek() the input file (fails for piped input);\n *     2) assume we can push back more than one character (works in\n *        some C implementations, but unportable);\n *     3) provide our own buffering (breaks input readers that want to use\n *        stdio directly, such as the RLE library);\n * or  4) don't put back the data, and modify the input_init methods to assume\n *        they start reading after the start of file (also breaks RLE library).\n * #1 is attractive for MS-DOS but is untenable on Unix.\n *\n * The most portable solution for file types that can't be identified by their\n * first byte is to make the user tell us what they are.  This is also the\n * only approach for \"raw\" file types that contain only arbitrary values.\n * We presently apply this method for Targa files.  Most of the time Targa\n * files start with 0x00, so we recognize that case.  Potentially, however,\n * a Targa file could start with any byte value (byte 0 is the length of the\n * seldom-used ID field), so we provide a switch to force Targa input mode.\n */\n\nstatic boolean is_targa;\t/* records user -targa switch */\n\n\nLOCAL(cjpeg_source_ptr)\nselect_file_type (j_compress_ptr cinfo, FILE * infile)\n{\n  int c;\n\n  if (is_targa) {\n#ifdef TARGA_SUPPORTED\n    return jinit_read_targa(cinfo);\n#else\n    ERREXIT(cinfo, JERR_TGA_NOTCOMP);\n#endif\n  }\n\n  if ((c = getc(infile)) == EOF)\n    ERREXIT(cinfo, JERR_INPUT_EMPTY);\n  if (ungetc(c, infile) == EOF)\n    ERREXIT(cinfo, JERR_UNGETC_FAILED);\n\n  switch (c) {\n#ifdef BMP_SUPPORTED\n  case 'B':\n    return jinit_read_bmp(cinfo);\n#endif\n#ifdef GIF_SUPPORTED\n  case 'G':\n    return jinit_read_gif(cinfo);\n#endif\n#ifdef PPM_SUPPORTED\n  case 'P':\n    return jinit_read_ppm(cinfo);\n#endif\n#ifdef RLE_SUPPORTED\n  case 'R':\n    return jinit_read_rle(cinfo);\n#endif\n#ifdef TARGA_SUPPORTED\n  case 0x00:\n    return jinit_read_targa(cinfo);\n#endif\n  default:\n    ERREXIT(cinfo, JERR_UNKNOWN_FORMAT);\n    break;\n  }\n\n  return NULL;\t\t\t/* suppress compiler warnings */\n}\n\n\n/*\n * Argument-parsing code.\n * The switch parser is designed to be useful with DOS-style command line\n * syntax, ie, intermixed switches and file names, where only the switches\n * to the left of a given file name affect processing of that file.\n * The main program in this file doesn't actually use this capability...\n */\n\n\nstatic const char * progname;\t/* program name for error messages */\nstatic char * outfilename;\t/* for -outfile switch */\n\n\nLOCAL(void)\nusage (void)\n/* complain about bad command line */\n{\n  fprintf(stderr, \"usage: %s [switches] \", progname);\n#ifdef TWO_FILE_COMMANDLINE\n  fprintf(stderr, \"inputfile outputfile\\n\");\n#else\n  fprintf(stderr, \"[inputfile]\\n\");\n#endif\n\n  fprintf(stderr, \"Switches (names may be abbreviated):\\n\");\n  fprintf(stderr, \"  -quality N[,...]   Compression quality (0..100; 5-95 is useful range)\\n\");\n  fprintf(stderr, \"  -grayscale     Create monochrome JPEG file\\n\");\n  fprintf(stderr, \"  -rgb           Create RGB JPEG file\\n\");\n#ifdef ENTROPY_OPT_SUPPORTED\n  fprintf(stderr, \"  -optimize      Optimize Huffman table (smaller file, but slow compression)\\n\");\n#endif\n#ifdef C_PROGRESSIVE_SUPPORTED\n  fprintf(stderr, \"  -progressive   Create progressive JPEG file\\n\");\n#endif\n#ifdef DCT_SCALING_SUPPORTED\n  fprintf(stderr, \"  -scale M/N     Scale image by fraction M/N, eg, 1/2\\n\");\n#endif\n#ifdef TARGA_SUPPORTED\n  fprintf(stderr, \"  -targa         Input file is Targa format (usually not needed)\\n\");\n#endif\n  fprintf(stderr, \"Switches for advanced users:\\n\");\n#ifdef C_ARITH_CODING_SUPPORTED\n  fprintf(stderr, \"  -arithmetic    Use arithmetic coding\\n\");\n#endif\n#ifdef DCT_SCALING_SUPPORTED\n  fprintf(stderr, \"  -block N       DCT block size (1..16; default is 8)\\n\");\n#endif\n#if JPEG_LIB_VERSION_MAJOR >= 9\n  fprintf(stderr, \"  -rgb1          Create RGB JPEG file with reversible color transform\\n\");\n  fprintf(stderr, \"  -bgycc         Create big gamut YCC JPEG file\\n\");\n#endif\n#ifdef DCT_ISLOW_SUPPORTED\n  fprintf(stderr, \"  -dct int       Use integer DCT method%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_ISLOW ? \" (default)\" : \"\"));\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n  fprintf(stderr, \"  -dct fast      Use fast integer DCT (less accurate)%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_IFAST ? \" (default)\" : \"\"));\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n  fprintf(stderr, \"  -dct float     Use floating-point DCT method%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_FLOAT ? \" (default)\" : \"\"));\n#endif\n  fprintf(stderr, \"  -nosmooth      Don't use high-quality downsampling\\n\");\n  fprintf(stderr, \"  -restart N     Set restart interval in rows, or in blocks with B\\n\");\n#ifdef INPUT_SMOOTHING_SUPPORTED\n  fprintf(stderr, \"  -smooth N      Smooth dithered input (N=1..100 is strength)\\n\");\n#endif\n  fprintf(stderr, \"  -maxmemory N   Maximum memory to use (in kbytes)\\n\");\n  fprintf(stderr, \"  -outfile name  Specify name for output file\\n\");\n  fprintf(stderr, \"  -verbose  or  -debug   Emit debug output\\n\");\n  fprintf(stderr, \"Switches for wizards:\\n\");\n  fprintf(stderr, \"  -baseline      Force baseline quantization tables\\n\");\n  fprintf(stderr, \"  -qtables file  Use quantization tables given in file\\n\");\n  fprintf(stderr, \"  -qslots N[,...]    Set component quantization tables\\n\");\n  fprintf(stderr, \"  -sample HxV[,...]  Set component sampling factors\\n\");\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n  fprintf(stderr, \"  -scans file    Create multi-scan JPEG per script file\\n\");\n#endif\n  exit(EXIT_FAILURE);\n}\n\n\nLOCAL(int)\nparse_switches (j_compress_ptr cinfo, int argc, char **argv,\n\t\tint last_file_arg_seen, boolean for_real)\n/* Parse optional switches.\n * Returns argv[] index of first file-name argument (== argc if none).\n * Any file names with indexes <= last_file_arg_seen are ignored;\n * they have presumably been processed in a previous iteration.\n * (Pass 0 for last_file_arg_seen on the first or only iteration.)\n * for_real is FALSE on the first (dummy) pass; we may skip any expensive\n * processing.\n */\n{\n  int argn;\n  char * arg;\n  boolean force_baseline;\n  boolean simple_progressive;\n  char * qualityarg = NULL;\t/* saves -quality parm if any */\n  char * qtablefile = NULL;\t/* saves -qtables filename if any */\n  char * qslotsarg = NULL;\t/* saves -qslots parm if any */\n  char * samplearg = NULL;\t/* saves -sample parm if any */\n  char * scansarg = NULL;\t/* saves -scans parm if any */\n\n  /* Set up default JPEG parameters. */\n\n  force_baseline = FALSE;\t/* by default, allow 16-bit quantizers */\n  simple_progressive = FALSE;\n  is_targa = FALSE;\n  outfilename = NULL;\n  cinfo->err->trace_level = 0;\n\n  /* Scan command line options, adjust parameters */\n\n  for (argn = 1; argn < argc; argn++) {\n    arg = argv[argn];\n    if (*arg != '-') {\n      /* Not a switch, must be a file name argument */\n      if (argn <= last_file_arg_seen) {\n\toutfilename = NULL;\t/* -outfile applies to just one input file */\n\tcontinue;\t\t/* ignore this name if previously processed */\n      }\n      break;\t\t\t/* else done parsing switches */\n    }\n    arg++;\t\t\t/* advance past switch marker character */\n\n    if (keymatch(arg, \"arithmetic\", 1)) {\n      /* Use arithmetic coding. */\n#ifdef C_ARITH_CODING_SUPPORTED\n      cinfo->arith_code = TRUE;\n#else\n      fprintf(stderr, \"%s: sorry, arithmetic coding not supported\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"baseline\", 2)) {\n      /* Force baseline-compatible output (8-bit quantizer values). */\n      force_baseline = TRUE;\n\n    } else if (keymatch(arg, \"block\", 2)) {\n      /* Set DCT block size. */\n#if defined DCT_SCALING_SUPPORTED && JPEG_LIB_VERSION_MAJOR >= 8 && \\\n      (JPEG_LIB_VERSION_MAJOR > 8 || JPEG_LIB_VERSION_MINOR >= 3)\n      int val;\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%d\", &val) != 1)\n\tusage();\n      if (val < 1 || val > 16)\n\tusage();\n      cinfo->block_size = val;\n#else\n      fprintf(stderr, \"%s: sorry, block size setting not supported\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"dct\", 2)) {\n      /* Select DCT algorithm. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"int\", 1)) {\n\tcinfo->dct_method = JDCT_ISLOW;\n      } else if (keymatch(argv[argn], \"fast\", 2)) {\n\tcinfo->dct_method = JDCT_IFAST;\n      } else if (keymatch(argv[argn], \"float\", 2)) {\n\tcinfo->dct_method = JDCT_FLOAT;\n      } else\n\tusage();\n\n    } else if (keymatch(arg, \"debug\", 1) || keymatch(arg, \"verbose\", 1)) {\n      /* Enable debug printouts. */\n      /* On first -d, print version identification */\n      static boolean printed_version = FALSE;\n\n      if (! printed_version) {\n\tfprintf(stderr, \"Independent JPEG Group's CJPEG, version %s\\n%s\\n\",\n\t\tJVERSION, JCOPYRIGHT);\n\tprinted_version = TRUE;\n      }\n      cinfo->err->trace_level++;\n\n    } else if (keymatch(arg, \"grayscale\", 2) || keymatch(arg, \"greyscale\",2)) {\n      /* Force a monochrome JPEG file to be generated. */\n      jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);\n\n    } else if (keymatch(arg, \"rgb\", 3) || keymatch(arg, \"rgb1\", 4)) {\n      /* Force an RGB JPEG file to be generated. */\n#if JPEG_LIB_VERSION_MAJOR >= 9\n      /* Note: Entropy table assignment in jpeg_set_colorspace depends\n       * on color_transform.\n       */\n      cinfo->color_transform = arg[3] ? JCT_SUBTRACT_GREEN : JCT_NONE;\n#endif\n      jpeg_set_colorspace(cinfo, JCS_RGB);\n\n    } else if (keymatch(arg, \"bgycc\", 5)) {\n      /* Force a big gamut YCC JPEG file to be generated. */\n#if JPEG_LIB_VERSION_MAJOR >= 9 && \\\n      (JPEG_LIB_VERSION_MAJOR > 9 || JPEG_LIB_VERSION_MINOR >= 1)\n      jpeg_set_colorspace(cinfo, JCS_BG_YCC);\n#else\n      fprintf(stderr, \"%s: sorry, BG_YCC colorspace not supported\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"maxmemory\", 3)) {\n      /* Maximum memory in Kb (or Mb with 'm'). */\n      long lval;\n      char ch = 'x';\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%ld%c\", &lval, &ch) < 1)\n\tusage();\n      if (ch == 'm' || ch == 'M')\n\tlval *= 1000L;\n      cinfo->mem->max_memory_to_use = lval * 1000L;\n\n    } else if (keymatch(arg, \"nosmooth\", 3)) {\n      /* Suppress fancy downsampling. */\n      cinfo->do_fancy_downsampling = FALSE;\n\n    } else if (keymatch(arg, \"optimize\", 1) || keymatch(arg, \"optimise\", 1)) {\n      /* Enable entropy parm optimization. */\n#ifdef ENTROPY_OPT_SUPPORTED\n      cinfo->optimize_coding = TRUE;\n#else\n      fprintf(stderr, \"%s: sorry, entropy optimization was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"outfile\", 4)) {\n      /* Set output file name. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      outfilename = argv[argn];\t/* save it away for later use */\n\n    } else if (keymatch(arg, \"progressive\", 1)) {\n      /* Select simple progressive mode. */\n#ifdef C_PROGRESSIVE_SUPPORTED\n      simple_progressive = TRUE;\n      /* We must postpone execution until num_components is known. */\n#else\n      fprintf(stderr, \"%s: sorry, progressive output was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"quality\", 1)) {\n      /* Quality ratings (quantization table scaling factors). */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      qualityarg = argv[argn];\n\n    } else if (keymatch(arg, \"qslots\", 2)) {\n      /* Quantization table slot numbers. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      qslotsarg = argv[argn];\n      /* Must delay setting qslots until after we have processed any\n       * colorspace-determining switches, since jpeg_set_colorspace sets\n       * default quant table numbers.\n       */\n\n    } else if (keymatch(arg, \"qtables\", 2)) {\n      /* Quantization tables fetched from file. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      qtablefile = argv[argn];\n      /* We postpone actually reading the file in case -quality comes later. */\n\n    } else if (keymatch(arg, \"restart\", 1)) {\n      /* Restart interval in MCU rows (or in MCUs with 'b'). */\n      long lval;\n      char ch = 'x';\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%ld%c\", &lval, &ch) < 1)\n\tusage();\n      if (lval < 0 || lval > 65535L)\n\tusage();\n      if (ch == 'b' || ch == 'B') {\n\tcinfo->restart_interval = (unsigned int) lval;\n\tcinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */\n      } else {\n\tcinfo->restart_in_rows = (int) lval;\n\t/* restart_interval will be computed during startup */\n      }\n\n    } else if (keymatch(arg, \"sample\", 2)) {\n      /* Set sampling factors. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      samplearg = argv[argn];\n      /* Must delay setting sample factors until after we have processed any\n       * colorspace-determining switches, since jpeg_set_colorspace sets\n       * default sampling factors.\n       */\n\n    } else if (keymatch(arg, \"scale\", 4)) {\n      /* Scale the image by a fraction M/N. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%u/%u\",\n\t\t &cinfo->scale_num, &cinfo->scale_denom) != 2)\n\tusage();\n\n    } else if (keymatch(arg, \"scans\", 4)) {\n      /* Set scan script. */\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      scansarg = argv[argn];\n      /* We must postpone reading the file in case -progressive appears. */\n#else\n      fprintf(stderr, \"%s: sorry, multi-scan output was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"smooth\", 2)) {\n      /* Set input smoothing factor. */\n      int val;\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%d\", &val) != 1)\n\tusage();\n      if (val < 0 || val > 100)\n\tusage();\n      cinfo->smoothing_factor = val;\n\n    } else if (keymatch(arg, \"targa\", 1)) {\n      /* Input file is Targa format. */\n      is_targa = TRUE;\n\n    } else {\n      usage();\t\t\t/* bogus switch */\n    }\n  }\n\n  /* Post-switch-scanning cleanup */\n\n  if (for_real) {\n\n    /* Set quantization tables for selected quality. */\n    /* Some or all may be overridden if -qtables is present. */\n    if (qualityarg != NULL)\t/* process -quality if it was present */\n      if (! set_quality_ratings(cinfo, qualityarg, force_baseline))\n\tusage();\n\n    if (qtablefile != NULL)\t/* process -qtables if it was present */\n      if (! read_quant_tables(cinfo, qtablefile, force_baseline))\n\tusage();\n\n    if (qslotsarg != NULL)\t/* process -qslots if it was present */\n      if (! set_quant_slots(cinfo, qslotsarg))\n\tusage();\n\n    if (samplearg != NULL)\t/* process -sample if it was present */\n      if (! set_sample_factors(cinfo, samplearg))\n\tusage();\n\n#ifdef C_PROGRESSIVE_SUPPORTED\n    if (simple_progressive)\t/* process -progressive; -scans can override */\n      jpeg_simple_progression(cinfo);\n#endif\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n    if (scansarg != NULL)\t/* process -scans if it was present */\n      if (! read_scan_script(cinfo, scansarg))\n\tusage();\n#endif\n  }\n\n  return argn;\t\t\t/* return index of next arg (file name) */\n}\n\n\n/*\n * The main program.\n */\n\nint\nmain (int argc, char **argv)\n{\n  struct jpeg_compress_struct cinfo;\n  struct jpeg_error_mgr jerr;\n#ifdef PROGRESS_REPORT\n  struct cdjpeg_progress_mgr progress;\n#endif\n  int file_index;\n  cjpeg_source_ptr src_mgr;\n  FILE * input_file;\n  FILE * output_file;\n  JDIMENSION num_scanlines;\n\n  /* On Mac, fetch a command line. */\n#ifdef USE_CCOMMAND\n  argc = ccommand(&argv);\n#endif\n\n  progname = argv[0];\n  if (progname == NULL || progname[0] == 0)\n    progname = \"cjpeg\";\t\t/* in case C library doesn't provide it */\n\n  /* Initialize the JPEG compression object with default error handling. */\n  cinfo.err = jpeg_std_error(&jerr);\n  jpeg_create_compress(&cinfo);\n  /* Add some application-specific error messages (from cderror.h) */\n  jerr.addon_message_table = cdjpeg_message_table;\n  jerr.first_addon_message = JMSG_FIRSTADDONCODE;\n  jerr.last_addon_message = JMSG_LASTADDONCODE;\n\n  /* Now safe to enable signal catcher. */\n#ifdef NEED_SIGNAL_CATCHER\n  enable_signal_catcher((j_common_ptr) &cinfo);\n#endif\n\n  /* Initialize JPEG parameters.\n   * Much of this may be overridden later.\n   * In particular, we don't yet know the input file's color space,\n   * but we need to provide some value for jpeg_set_defaults() to work.\n   */\n\n  cinfo.in_color_space = JCS_RGB; /* arbitrary guess */\n  jpeg_set_defaults(&cinfo);\n\n  /* Scan command line to find file names.\n   * It is convenient to use just one switch-parsing routine, but the switch\n   * values read here are ignored; we will rescan the switches after opening\n   * the input file.\n   */\n\n  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);\n\n#ifdef TWO_FILE_COMMANDLINE\n  /* Must have either -outfile switch or explicit output file name */\n  if (outfilename == NULL) {\n    if (file_index != argc-2) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n    outfilename = argv[file_index+1];\n  } else {\n    if (file_index != argc-1) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n  }\n#else\n  /* Unix style: expect zero or one file name */\n  if (file_index < argc-1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Open the input file. */\n  if (file_index < argc) {\n    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[file_index]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n    input_file = read_stdin();\n  }\n\n  /* Open the output file. */\n  if (outfilename != NULL) {\n    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, outfilename);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default output file is stdout */\n    output_file = write_stdout();\n  }\n\n#ifdef PROGRESS_REPORT\n  start_progress_monitor((j_common_ptr) &cinfo, &progress);\n#endif\n\n  /* Figure out the input file format, and set up to read it. */\n  src_mgr = select_file_type(&cinfo, input_file);\n  src_mgr->input_file = input_file;\n\n  /* Read the input file header to obtain file size & colorspace. */\n  (*src_mgr->start_input) (&cinfo, src_mgr);\n\n  /* Now that we know input colorspace, fix colorspace-dependent defaults */\n  jpeg_default_colorspace(&cinfo);\n\n  /* Adjust default compression parameters by re-parsing the options */\n  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);\n\n  /* Specify data destination for compression */\n  jpeg_stdio_dest(&cinfo, output_file);\n\n  /* Start compressor */\n  jpeg_start_compress(&cinfo, TRUE);\n\n  /* Process data */\n  while (cinfo.next_scanline < cinfo.image_height) {\n    num_scanlines = (*src_mgr->get_pixel_rows) (&cinfo, src_mgr);\n    (void) jpeg_write_scanlines(&cinfo, src_mgr->buffer, num_scanlines);\n  }\n\n  /* Finish compression and release memory */\n  (*src_mgr->finish_input) (&cinfo, src_mgr);\n  jpeg_finish_compress(&cinfo);\n  jpeg_destroy_compress(&cinfo);\n\n  /* Close files, if we opened them */\n  if (input_file != stdin)\n    fclose(input_file);\n  if (output_file != stdout)\n    fclose(output_file);\n\n#ifdef PROGRESS_REPORT\n  end_progress_monitor((j_common_ptr) &cinfo);\n#endif\n\n  /* All done. */\n  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);\n  return 0;\t\t\t/* suppress no-return-value warnings */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/ckconfig.c",
    "content": "/*\n * ckconfig.c\n *\n * Copyright (C) 1991-1994, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n */\n\n/*\n * This program is intended to help you determine how to configure the JPEG\n * software for installation on a particular system.  The idea is to try to\n * compile and execute this program.  If your compiler fails to compile the\n * program, make changes as indicated in the comments below.  Once you can\n * compile the program, run it, and it will produce a \"jconfig.h\" file for\n * your system.\n *\n * As a general rule, each time you try to compile this program,\n * pay attention only to the *first* error message you get from the compiler.\n * Many C compilers will issue lots of spurious error messages once they\n * have gotten confused.  Go to the line indicated in the first error message,\n * and read the comments preceding that line to see what to change.\n *\n * Almost all of the edits you may need to make to this program consist of\n * changing a line that reads \"#define SOME_SYMBOL\" to \"#undef SOME_SYMBOL\",\n * or vice versa.  This is called defining or undefining that symbol.\n */\n\n\n/* First we must see if your system has the include files we need.\n * We start out with the assumption that your system has all the ANSI-standard\n * include files.  If you get any error trying to include one of these files,\n * undefine the corresponding HAVE_xxx symbol.\n */\n\n#define HAVE_STDDEF_H\t\t/* replace 'define' by 'undef' if error here */\n#ifdef HAVE_STDDEF_H\t\t/* next line will be skipped if you undef... */\n#include <stddef.h>\n#endif\n\n#define HAVE_STDLIB_H\t\t/* same thing for stdlib.h */\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n\n#include <stdio.h>\t\t/* If you ain't got this, you ain't got C. */\n\n/* We have to see if your string functions are defined by\n * strings.h (old BSD convention) or string.h (everybody else).\n * We try the non-BSD convention first; define NEED_BSD_STRINGS\n * if the compiler says it can't find string.h.\n */\n\n#undef NEED_BSD_STRINGS\n\n#ifdef NEED_BSD_STRINGS\n#include <strings.h>\n#else\n#include <string.h>\n#endif\n\n/* On some systems (especially older Unix machines), type size_t is\n * defined only in the include file <sys/types.h>.  If you get a failure\n * on the size_t test below, try defining NEED_SYS_TYPES_H.\n */\n\n#undef NEED_SYS_TYPES_H\t\t/* start by assuming we don't need it */\n#ifdef NEED_SYS_TYPES_H\n#include <sys/types.h>\n#endif\n\n\n/* Usually type size_t is defined in one of the include files we've included\n * above.  If not, you'll get an error on the \"typedef size_t my_size_t;\" line.\n * In that case, first try defining NEED_SYS_TYPES_H just above.\n * If that doesn't work, you'll have to search through your system library\n * to figure out which include file defines \"size_t\".  Look for a line that\n * says \"typedef something-or-other size_t;\".  Then, change the line below\n * that says \"#include <someincludefile.h>\" to instead include the file\n * you found size_t in, and define NEED_SPECIAL_INCLUDE.  If you can't find\n * type size_t anywhere, try replacing \"#include <someincludefile.h>\" with\n * \"typedef unsigned int size_t;\".\n */\n\n#undef NEED_SPECIAL_INCLUDE\t/* assume we DON'T need it, for starters */\n\n#ifdef NEED_SPECIAL_INCLUDE\n#include <someincludefile.h>\n#endif\n\ntypedef size_t my_size_t;\t/* The payoff: do we have size_t now? */\n\n\n/* The next question is whether your compiler supports ANSI-style function\n * prototypes.  You need to know this in order to choose between using\n * makefile.ansi and using makefile.unix.\n * The #define line below is set to assume you have ANSI function prototypes.\n * If you get an error in this group of lines, undefine HAVE_PROTOTYPES.\n */\n\n#define HAVE_PROTOTYPES\n\n#ifdef HAVE_PROTOTYPES\nint testfunction (int arg1, int * arg2); /* check prototypes */\n\nstruct methods_struct {\t\t/* check method-pointer declarations */\n  int (*error_exit) (char *msgtext);\n  int (*trace_message) (char *msgtext);\n  int (*another_method) (void);\n};\n\nint testfunction (int arg1, int * arg2) /* check definitions */\n{\n  return arg2[arg1];\n}\n\nint test2function (void)\t/* check void arg list */\n{\n  return 0;\n}\n#endif\n\n\n/* Now we want to find out if your compiler knows what \"unsigned char\" means.\n * If you get an error on the \"unsigned char un_char;\" line,\n * then undefine HAVE_UNSIGNED_CHAR.\n */\n\n#define HAVE_UNSIGNED_CHAR\n\n#ifdef HAVE_UNSIGNED_CHAR\nunsigned char un_char;\n#endif\n\n\n/* Now we want to find out if your compiler knows what \"unsigned short\" means.\n * If you get an error on the \"unsigned short un_short;\" line,\n * then undefine HAVE_UNSIGNED_SHORT.\n */\n\n#define HAVE_UNSIGNED_SHORT\n\n#ifdef HAVE_UNSIGNED_SHORT\nunsigned short un_short;\n#endif\n\n\n/* Now we want to find out if your compiler understands type \"void\".\n * If you get an error anywhere in here, undefine HAVE_VOID.\n */\n\n#define HAVE_VOID\n\n#ifdef HAVE_VOID\n/* Caution: a C++ compiler will insist on complete prototypes */\ntypedef void * void_ptr;\t/* check void * */\n#ifdef HAVE_PROTOTYPES\t\t/* check ptr to function returning void */\ntypedef void (*void_func) (int a, int b);\n#else\ntypedef void (*void_func) ();\n#endif\n\n#ifdef HAVE_PROTOTYPES\t\t/* check void function result */\nvoid test3function (void_ptr arg1, void_func arg2)\n#else\nvoid test3function (arg1, arg2)\n     void_ptr arg1;\n     void_func arg2;\n#endif\n{\n  char * locptr = (char *) arg1; /* check casting to and from void * */\n  arg1 = (void *) locptr;\n  (*arg2) (1, 2);\t\t/* check call of fcn returning void */\n}\n#endif\n\n\n/* Now we want to find out if your compiler knows what \"const\" means.\n * If you get an error here, undefine HAVE_CONST.\n */\n\n#define HAVE_CONST\n\n#ifdef HAVE_CONST\nstatic const int carray[3] = {1, 2, 3};\n\n#ifdef HAVE_PROTOTYPES\nint test4function (const int arg1)\n#else\nint test4function (arg1)\n     const int arg1;\n#endif\n{\n  return carray[arg1];\n}\n#endif\n\n\n/* If you get an error or warning about this structure definition,\n * define INCOMPLETE_TYPES_BROKEN.\n */\n\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifndef INCOMPLETE_TYPES_BROKEN\ntypedef struct undefined_structure * undef_struct_ptr;\n#endif\n\n\n/* If you get an error about duplicate names,\n * define NEED_SHORT_EXTERNAL_NAMES.\n */\n\n#undef NEED_SHORT_EXTERNAL_NAMES\n\n#ifndef NEED_SHORT_EXTERNAL_NAMES\n\nint possibly_duplicate_function ()\n{\n  return 0;\n}\n\nint possibly_dupli_function ()\n{\n  return 1;\n}\n\n#endif\n\n\n\n/************************************************************************\n *  OK, that's it.  You should not have to change anything beyond this\n *  point in order to compile and execute this program.  (You might get\n *  some warnings, but you can ignore them.)\n *  When you run the program, it will make a couple more tests that it\n *  can do automatically, and then it will create jconfig.h and print out\n *  any additional suggestions it has.\n ************************************************************************\n */\n\n\n#ifdef HAVE_PROTOTYPES\nint is_char_signed (int arg)\n#else\nint is_char_signed (arg)\n     int arg;\n#endif\n{\n  if (arg == 189) {\t\t/* expected result for unsigned char */\n    return 0;\t\t\t/* type char is unsigned */\n  }\n  else if (arg != -67) {\t/* expected result for signed char */\n    printf(\"Hmm, it seems 'char' is not eight bits wide on your machine.\\n\");\n    printf(\"I fear the JPEG software will not work at all.\\n\\n\");\n  }\n  return 1;\t\t\t/* assume char is signed otherwise */\n}\n\n\n#ifdef HAVE_PROTOTYPES\nint is_shifting_signed (long arg)\n#else\nint is_shifting_signed (arg)\n     long arg;\n#endif\n/* See whether right-shift on a long is signed or not. */\n{\n  long res = arg >> 4;\n\n  if (res == -0x7F7E80CL) {\t/* expected result for signed shift */\n    return 1;\t\t\t/* right shift is signed */\n  }\n  /* see if unsigned-shift hack will fix it. */\n  /* we can't just test exact value since it depends on width of long... */\n  res |= (~0L) << (32-4);\n  if (res == -0x7F7E80CL) {\t/* expected result now? */\n    return 0;\t\t\t/* right shift is unsigned */\n  }\n  printf(\"Right shift isn't acting as I expect it to.\\n\");\n  printf(\"I fear the JPEG software will not work at all.\\n\\n\");\n  return 0;\t\t\t/* try it with unsigned anyway */\n}\n\n\n#ifdef HAVE_PROTOTYPES\nint main (int argc, char ** argv)\n#else\nint main (argc, argv)\n     int argc;\n     char ** argv;\n#endif\n{\n  char signed_char_check = (char) (-67);\n  FILE *outfile;\n\n  /* Attempt to write jconfig.h */\n  if ((outfile = fopen(\"jconfig.h\", \"w\")) == NULL) {\n    printf(\"Failed to write jconfig.h\\n\");\n    return 1;\n  }\n\n  /* Write out all the info */\n  fprintf(outfile, \"/* jconfig.h --- generated by ckconfig.c */\\n\");\n  fprintf(outfile, \"/* see jconfig.txt for explanations */\\n\\n\");\n#ifdef HAVE_PROTOTYPES\n  fprintf(outfile, \"#define HAVE_PROTOTYPES\\n\");\n#else\n  fprintf(outfile, \"#undef HAVE_PROTOTYPES\\n\");\n#endif\n#ifdef HAVE_UNSIGNED_CHAR\n  fprintf(outfile, \"#define HAVE_UNSIGNED_CHAR\\n\");\n#else\n  fprintf(outfile, \"#undef HAVE_UNSIGNED_CHAR\\n\");\n#endif\n#ifdef HAVE_UNSIGNED_SHORT\n  fprintf(outfile, \"#define HAVE_UNSIGNED_SHORT\\n\");\n#else\n  fprintf(outfile, \"#undef HAVE_UNSIGNED_SHORT\\n\");\n#endif\n#ifdef HAVE_VOID\n  fprintf(outfile, \"/* #define void char */\\n\");\n#else\n  fprintf(outfile, \"#define void char\\n\");\n#endif\n#ifdef HAVE_CONST\n  fprintf(outfile, \"/* #define const */\\n\");\n#else\n  fprintf(outfile, \"#define const\\n\");\n#endif\n  if (is_char_signed((int) signed_char_check))\n    fprintf(outfile, \"#undef CHAR_IS_UNSIGNED\\n\");\n  else\n    fprintf(outfile, \"#define CHAR_IS_UNSIGNED\\n\");\n#ifdef HAVE_STDDEF_H\n  fprintf(outfile, \"#define HAVE_STDDEF_H\\n\");\n#else\n  fprintf(outfile, \"#undef HAVE_STDDEF_H\\n\");\n#endif\n#ifdef HAVE_STDLIB_H\n  fprintf(outfile, \"#define HAVE_STDLIB_H\\n\");\n#else\n  fprintf(outfile, \"#undef HAVE_STDLIB_H\\n\");\n#endif\n#ifdef NEED_BSD_STRINGS\n  fprintf(outfile, \"#define NEED_BSD_STRINGS\\n\");\n#else\n  fprintf(outfile, \"#undef NEED_BSD_STRINGS\\n\");\n#endif\n#ifdef NEED_SYS_TYPES_H\n  fprintf(outfile, \"#define NEED_SYS_TYPES_H\\n\");\n#else\n  fprintf(outfile, \"#undef NEED_SYS_TYPES_H\\n\");\n#endif\n  fprintf(outfile, \"#undef NEED_FAR_POINTERS\\n\");\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n  fprintf(outfile, \"#define NEED_SHORT_EXTERNAL_NAMES\\n\");\n#else\n  fprintf(outfile, \"#undef NEED_SHORT_EXTERNAL_NAMES\\n\");\n#endif\n#ifdef INCOMPLETE_TYPES_BROKEN\n  fprintf(outfile, \"#define INCOMPLETE_TYPES_BROKEN\\n\");\n#else\n  fprintf(outfile, \"#undef INCOMPLETE_TYPES_BROKEN\\n\");\n#endif\n  fprintf(outfile, \"\\n#ifdef JPEG_INTERNALS\\n\\n\");\n  if (is_shifting_signed(-0x7F7E80B1L))\n    fprintf(outfile, \"#undef RIGHT_SHIFT_IS_UNSIGNED\\n\");\n  else\n    fprintf(outfile, \"#define RIGHT_SHIFT_IS_UNSIGNED\\n\");\n  fprintf(outfile, \"\\n#endif /* JPEG_INTERNALS */\\n\");\n  fprintf(outfile, \"\\n#ifdef JPEG_CJPEG_DJPEG\\n\\n\");\n  fprintf(outfile, \"#define BMP_SUPPORTED\t\t/* BMP image file format */\\n\");\n  fprintf(outfile, \"#define GIF_SUPPORTED\t\t/* GIF image file format */\\n\");\n  fprintf(outfile, \"#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\\n\");\n  fprintf(outfile, \"#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\\n\");\n  fprintf(outfile, \"#define TARGA_SUPPORTED\t\t/* Targa image file format */\\n\\n\");\n  fprintf(outfile, \"#undef TWO_FILE_COMMANDLINE\t/* You may need this on non-Unix systems */\\n\");\n  fprintf(outfile, \"#undef NEED_SIGNAL_CATCHER\t/* Define this if you use jmemname.c */\\n\");\n  fprintf(outfile, \"#undef DONT_USE_B_MODE\\n\");\n  fprintf(outfile, \"/* #define PROGRESS_REPORT */\t/* optional */\\n\");\n  fprintf(outfile, \"\\n#endif /* JPEG_CJPEG_DJPEG */\\n\");\n\n  /* Close the jconfig.h file */\n  fclose(outfile);\n\n  /* User report */\n  printf(\"Configuration check for Independent JPEG Group's software done.\\n\");\n  printf(\"\\nI have written the jconfig.h file for you.\\n\\n\");\n#ifdef HAVE_PROTOTYPES\n  printf(\"You should use makefile.ansi as the starting point for your Makefile.\\n\");\n#else\n  printf(\"You should use makefile.unix as the starting point for your Makefile.\\n\");\n#endif\n\n#ifdef NEED_SPECIAL_INCLUDE\n  printf(\"\\nYou'll need to change jconfig.h to include the system include file\\n\");\n  printf(\"that you found type size_t in, or add a direct definition of type\\n\");\n  printf(\"size_t if that's what you used.  Just add it to the end.\\n\");\n#endif\n\n  return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/coderules.txt",
    "content": "IJG JPEG LIBRARY:  CODING RULES\n\nCopyright (C) 1991-1996, Thomas G. Lane.\nThis file is part of the Independent JPEG Group's software.\nFor conditions of distribution and use, see the accompanying README file.\n\n\nSince numerous people will be contributing code and bug fixes, it's important\nto establish a common coding style.  The goal of using similar coding styles\nis much more important than the details of just what that style is.\n\nIn general we follow the recommendations of \"Recommended C Style and Coding\nStandards\" revision 6.1 (Cannon et al. as modified by Spencer, Keppel and\nBrader).  This document is available in the IJG FTP archive (see\njpeg/doc/cstyle.ms.tbl.Z, or cstyle.txt.Z for those without nroff/tbl).\n\nBlock comments should be laid out thusly:\n\n/*\n *  Block comments in this style.\n */\n\nWe indent statements in K&R style, e.g.,\n\tif (test) {\n\t  then-part;\n\t} else {\n\t  else-part;\n\t}\nwith two spaces per indentation level.  (This indentation convention is\nhandled automatically by GNU Emacs and many other text editors.)\n\nMulti-word names should be written in lower case with underscores, e.g.,\nmulti_word_name (not multiWordName).  Preprocessor symbols and enum constants\nare similar but upper case (MULTI_WORD_NAME).  Names should be unique within\nthe first fifteen characters.  (On some older systems, global names must be\nunique within six characters.  We accommodate this without cluttering the\nsource code by using macros to substitute shorter names.)\n\nWe use function prototypes everywhere; we rely on automatic source code\ntransformation to feed prototype-less C compilers.  Transformation is done\nby the simple and portable tool 'ansi2knr.c' (courtesy of Ghostscript).\nansi2knr is not very bright, so it imposes a format requirement on function\ndeclarations: the function name MUST BEGIN IN COLUMN 1.  Thus all functions\nshould be written in the following style:\n\nLOCAL(int *)\nfunction_name (int a, char *b)\n{\n    code...\n}\n\nNote that each function definition must begin with GLOBAL(type), LOCAL(type),\nor METHODDEF(type).  These macros expand to \"static type\" or just \"type\" as\nappropriate.  They provide a readable indication of the routine's usage and\ncan readily be changed for special needs.  (For instance, special linkage\nkeywords can be inserted for use in Windows DLLs.)\n\nansi2knr does not transform method declarations (function pointers in\nstructs).  We handle these with a macro JMETHOD, defined as\n\t#ifdef HAVE_PROTOTYPES\n\t#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist\n\t#else\n\t#define JMETHOD(type,methodname,arglist)  type (*methodname) ()\n\t#endif\nwhich is used like this:\n\tstruct function_pointers {\n\t  JMETHOD(void, init_entropy_encoder, (int somearg, jparms *jp));\n\t  JMETHOD(void, term_entropy_encoder, (void));\n\t};\nNote the set of parentheses surrounding the parameter list.\n\nA similar solution is used for forward and external function declarations\n(see the EXTERN and JPP macros).\n\nIf the code is to work on non-ANSI compilers, we cannot rely on a prototype\ndeclaration to coerce actual parameters into the right types.  Therefore, use\nexplicit casts on actual parameters whenever the actual parameter type is not\nidentical to the formal parameter.  Beware of implicit conversions to \"int\".\n\nIt seems there are some non-ANSI compilers in which the sizeof() operator\nis defined to return int, yet size_t is defined as long.  Needless to say,\nthis is brain-damaged.  Always use the SIZEOF() macro in place of sizeof(),\nso that the result is guaranteed to be of type size_t.\n\n\nThe JPEG library is intended to be used within larger programs.  Furthermore,\nwe want it to be reentrant so that it can be used by applications that process\nmultiple images concurrently.  The following rules support these requirements:\n\n1. Avoid direct use of file I/O, \"malloc\", error report printouts, etc;\npass these through the common routines provided.\n\n2. Minimize global namespace pollution.  Functions should be declared static\nwherever possible.  (Note that our method-based calling conventions help this\na lot: in many modules only the initialization function will ever need to be\ncalled directly, so only that function need be externally visible.)  All\nglobal function names should begin with \"jpeg_\", and should have an\nabbreviated name (unique in the first six characters) substituted by macro\nwhen NEED_SHORT_EXTERNAL_NAMES is set.\n\n3. Don't use global variables; anything that must be used in another module\nshould be in the common data structures.\n\n4. Don't use static variables except for read-only constant tables.  Variables\nthat should be private to a module can be placed into private structures (see\nthe system architecture document, structure.txt).\n\n5. Source file names should begin with \"j\" for files that are part of the\nlibrary proper; source files that are not part of the library, such as cjpeg.c\nand djpeg.c, do not begin with \"j\".  Keep source file names to eight\ncharacters (plus \".c\" or \".h\", etc) to make life easy for MS-DOSers.  Keep\ncompression and decompression code in separate source files --- some\napplications may want only one half of the library.\n\nNote: these rules (particularly #4) are not followed religiously in the\nmodules that are used in cjpeg/djpeg but are not part of the JPEG library\nproper.  Those modules are not really intended to be used in other\napplications.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/compile",
    "content": "#! /bin/sh\n# Wrapper for compilers which do not understand '-c -o'.\n\nscriptversion=2012-10-14.11; # UTC\n\n# Copyright (C) 1999-2014 Free Software Foundation, Inc.\n# Written by Tom Tromey <tromey@cygnus.com>.\n#\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2, or (at your option)\n# any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that program.\n\n# This file is maintained in Automake, please report\n# bugs to <bug-automake@gnu.org> or send patches to\n# <automake-patches@gnu.org>.\n\nnl='\n'\n\n# We need space, tab and new line, in precisely that order.  Quoting is\n# there to prevent tools from complaining about whitespace usage.\nIFS=\" \"\"\t$nl\"\n\nfile_conv=\n\n# func_file_conv build_file lazy\n# Convert a $build file to $host form and store it in $file\n# Currently only supports Windows hosts. If the determined conversion\n# type is listed in (the comma separated) LAZY, no conversion will\n# take place.\nfunc_file_conv ()\n{\n  file=$1\n  case $file in\n    / | /[!/]*) # absolute file, and not a UNC file\n      if test -z \"$file_conv\"; then\n\t# lazily determine how to convert abs files\n\tcase `uname -s` in\n\t  MINGW*)\n\t    file_conv=mingw\n\t    ;;\n\t  CYGWIN*)\n\t    file_conv=cygwin\n\t    ;;\n\t  *)\n\t    file_conv=wine\n\t    ;;\n\tesac\n      fi\n      case $file_conv/,$2, in\n\t*,$file_conv,*)\n\t  ;;\n\tmingw/*)\n\t  file=`cmd //C echo \"$file \" | sed -e 's/\"\\(.*\\) \" *$/\\1/'`\n\t  ;;\n\tcygwin/*)\n\t  file=`cygpath -m \"$file\" || echo \"$file\"`\n\t  ;;\n\twine/*)\n\t  file=`winepath -w \"$file\" || echo \"$file\"`\n\t  ;;\n      esac\n      ;;\n  esac\n}\n\n# func_cl_dashL linkdir\n# Make cl look for libraries in LINKDIR\nfunc_cl_dashL ()\n{\n  func_file_conv \"$1\"\n  if test -z \"$lib_path\"; then\n    lib_path=$file\n  else\n    lib_path=\"$lib_path;$file\"\n  fi\n  linker_opts=\"$linker_opts -LIBPATH:$file\"\n}\n\n# func_cl_dashl library\n# Do a library search-path lookup for cl\nfunc_cl_dashl ()\n{\n  lib=$1\n  found=no\n  save_IFS=$IFS\n  IFS=';'\n  for dir in $lib_path $LIB\n  do\n    IFS=$save_IFS\n    if $shared && test -f \"$dir/$lib.dll.lib\"; then\n      found=yes\n      lib=$dir/$lib.dll.lib\n      break\n    fi\n    if test -f \"$dir/$lib.lib\"; then\n      found=yes\n      lib=$dir/$lib.lib\n      break\n    fi\n    if test -f \"$dir/lib$lib.a\"; then\n      found=yes\n      lib=$dir/lib$lib.a\n      break\n    fi\n  done\n  IFS=$save_IFS\n\n  if test \"$found\" != yes; then\n    lib=$lib.lib\n  fi\n}\n\n# func_cl_wrapper cl arg...\n# Adjust compile command to suit cl\nfunc_cl_wrapper ()\n{\n  # Assume a capable shell\n  lib_path=\n  shared=:\n  linker_opts=\n  for arg\n  do\n    if test -n \"$eat\"; then\n      eat=\n    else\n      case $1 in\n\t-o)\n\t  # configure might choose to run compile as 'compile cc -o foo foo.c'.\n\t  eat=1\n\t  case $2 in\n\t    *.o | *.[oO][bB][jJ])\n\t      func_file_conv \"$2\"\n\t      set x \"$@\" -Fo\"$file\"\n\t      shift\n\t      ;;\n\t    *)\n\t      func_file_conv \"$2\"\n\t      set x \"$@\" -Fe\"$file\"\n\t      shift\n\t      ;;\n\t  esac\n\t  ;;\n\t-I)\n\t  eat=1\n\t  func_file_conv \"$2\" mingw\n\t  set x \"$@\" -I\"$file\"\n\t  shift\n\t  ;;\n\t-I*)\n\t  func_file_conv \"${1#-I}\" mingw\n\t  set x \"$@\" -I\"$file\"\n\t  shift\n\t  ;;\n\t-l)\n\t  eat=1\n\t  func_cl_dashl \"$2\"\n\t  set x \"$@\" \"$lib\"\n\t  shift\n\t  ;;\n\t-l*)\n\t  func_cl_dashl \"${1#-l}\"\n\t  set x \"$@\" \"$lib\"\n\t  shift\n\t  ;;\n\t-L)\n\t  eat=1\n\t  func_cl_dashL \"$2\"\n\t  ;;\n\t-L*)\n\t  func_cl_dashL \"${1#-L}\"\n\t  ;;\n\t-static)\n\t  shared=false\n\t  ;;\n\t-Wl,*)\n\t  arg=${1#-Wl,}\n\t  save_ifs=\"$IFS\"; IFS=','\n\t  for flag in $arg; do\n\t    IFS=\"$save_ifs\"\n\t    linker_opts=\"$linker_opts $flag\"\n\t  done\n\t  IFS=\"$save_ifs\"\n\t  ;;\n\t-Xlinker)\n\t  eat=1\n\t  linker_opts=\"$linker_opts $2\"\n\t  ;;\n\t-*)\n\t  set x \"$@\" \"$1\"\n\t  shift\n\t  ;;\n\t*.cc | *.CC | *.cxx | *.CXX | *.[cC]++)\n\t  func_file_conv \"$1\"\n\t  set x \"$@\" -Tp\"$file\"\n\t  shift\n\t  ;;\n\t*.c | *.cpp | *.CPP | *.lib | *.LIB | *.Lib | *.OBJ | *.obj | *.[oO])\n\t  func_file_conv \"$1\" mingw\n\t  set x \"$@\" \"$file\"\n\t  shift\n\t  ;;\n\t*)\n\t  set x \"$@\" \"$1\"\n\t  shift\n\t  ;;\n      esac\n    fi\n    shift\n  done\n  if test -n \"$linker_opts\"; then\n    linker_opts=\"-link$linker_opts\"\n  fi\n  exec \"$@\" $linker_opts\n  exit 1\n}\n\neat=\n\ncase $1 in\n  '')\n     echo \"$0: No command.  Try '$0 --help' for more information.\" 1>&2\n     exit 1;\n     ;;\n  -h | --h*)\n    cat <<\\EOF\nUsage: compile [--help] [--version] PROGRAM [ARGS]\n\nWrapper for compilers which do not understand '-c -o'.\nRemove '-o dest.o' from ARGS, run PROGRAM with the remaining\narguments, and rename the output as expected.\n\nIf you are trying to build a whole package this is not the\nright script to run: please start by reading the file 'INSTALL'.\n\nReport bugs to <bug-automake@gnu.org>.\nEOF\n    exit $?\n    ;;\n  -v | --v*)\n    echo \"compile $scriptversion\"\n    exit $?\n    ;;\n  cl | *[/\\\\]cl | cl.exe | *[/\\\\]cl.exe )\n    func_cl_wrapper \"$@\"      # Doesn't return...\n    ;;\nesac\n\nofile=\ncfile=\n\nfor arg\ndo\n  if test -n \"$eat\"; then\n    eat=\n  else\n    case $1 in\n      -o)\n\t# configure might choose to run compile as 'compile cc -o foo foo.c'.\n\t# So we strip '-o arg' only if arg is an object.\n\teat=1\n\tcase $2 in\n\t  *.o | *.obj)\n\t    ofile=$2\n\t    ;;\n\t  *)\n\t    set x \"$@\" -o \"$2\"\n\t    shift\n\t    ;;\n\tesac\n\t;;\n      *.c)\n\tcfile=$1\n\tset x \"$@\" \"$1\"\n\tshift\n\t;;\n      *)\n\tset x \"$@\" \"$1\"\n\tshift\n\t;;\n    esac\n  fi\n  shift\ndone\n\nif test -z \"$ofile\" || test -z \"$cfile\"; then\n  # If no '-o' option was seen then we might have been invoked from a\n  # pattern rule where we don't need one.  That is ok -- this is a\n  # normal compilation that the losing compiler can handle.  If no\n  # '.c' file was seen then we are probably linking.  That is also\n  # ok.\n  exec \"$@\"\nfi\n\n# Name of file we expect compiler to create.\ncofile=`echo \"$cfile\" | sed 's|^.*[\\\\/]||; s|^[a-zA-Z]:||; s/\\.c$/.o/'`\n\n# Create the lock directory.\n# Note: use '[/\\\\:.-]' here to ensure that we don't use the same name\n# that we are using for the .o file.  Also, base the name on the expected\n# object file name, since that is what matters with a parallel build.\nlockdir=`echo \"$cofile\" | sed -e 's|[/\\\\:.-]|_|g'`.d\nwhile true; do\n  if mkdir \"$lockdir\" >/dev/null 2>&1; then\n    break\n  fi\n  sleep 1\ndone\n# FIXME: race condition here if user kills between mkdir and trap.\ntrap \"rmdir '$lockdir'; exit 1\" 1 2 15\n\n# Run the compile.\n\"$@\"\nret=$?\n\nif test -f \"$cofile\"; then\n  test \"$cofile\" = \"$ofile\" || mv \"$cofile\" \"$ofile\"\nelif test -f \"${cofile}bj\"; then\n  test \"${cofile}bj\" = \"$ofile\" || mv \"${cofile}bj\" \"$ofile\"\nfi\n\nrmdir \"$lockdir\"\nexit $ret\n\n# Local Variables:\n# mode: shell-script\n# sh-indentation: 2\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"scriptversion=\"\n# time-stamp-format: \"%:y-%02m-%02d.%02H\"\n# time-stamp-time-zone: \"UTC\"\n# time-stamp-end: \"; # UTC\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/config.guess",
    "content": "#! /bin/sh\n# Attempt to guess a canonical system name.\n#   Copyright 1992-2014 Free Software Foundation, Inc.\n\ntimestamp='2014-11-04'\n\n# This file is free software; you can redistribute it and/or modify it\n# under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful, but\n# WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n# General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, see <http://www.gnu.org/licenses/>.\n#\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that\n# program.  This Exception is an additional permission under section 7\n# of the GNU General Public License, version 3 (\"GPLv3\").\n#\n# Originally written by Per Bothner; maintained since 2000 by Ben Elliston.\n#\n# You can get the latest version of this script from:\n# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD\n#\n# Please send patches to <config-patches@gnu.org>.\n\n\nme=`echo \"$0\" | sed -e 's,.*/,,'`\n\nusage=\"\\\nUsage: $0 [OPTION]\n\nOutput the configuration name of the system \\`$me' is run on.\n\nOperation modes:\n  -h, --help         print this help, then exit\n  -t, --time-stamp   print date of last modification, then exit\n  -v, --version      print version number, then exit\n\nReport bugs and patches to <config-patches@gnu.org>.\"\n\nversion=\"\\\nGNU config.guess ($timestamp)\n\nOriginally written by Per Bothner.\nCopyright 1992-2014 Free Software Foundation, Inc.\n\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\"\n\nhelp=\"\nTry \\`$me --help' for more information.\"\n\n# Parse command line\nwhile test $# -gt 0 ; do\n  case $1 in\n    --time-stamp | --time* | -t )\n       echo \"$timestamp\" ; exit ;;\n    --version | -v )\n       echo \"$version\" ; exit ;;\n    --help | --h* | -h )\n       echo \"$usage\"; exit ;;\n    -- )     # Stop option processing\n       shift; break ;;\n    - )\t# Use stdin as input.\n       break ;;\n    -* )\n       echo \"$me: invalid option $1$help\" >&2\n       exit 1 ;;\n    * )\n       break ;;\n  esac\ndone\n\nif test $# != 0; then\n  echo \"$me: too many arguments$help\" >&2\n  exit 1\nfi\n\ntrap 'exit 1' 1 2 15\n\n# CC_FOR_BUILD -- compiler used by this script. Note that the use of a\n# compiler to aid in system detection is discouraged as it requires\n# temporary files to be created and, as you can see below, it is a\n# headache to deal with in a portable fashion.\n\n# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still\n# use `HOST_CC' if defined, but it is deprecated.\n\n# Portable tmp directory creation inspired by the Autoconf team.\n\nset_cc_for_build='\ntrap \"exitcode=\\$?; (rm -f \\$tmpfiles 2>/dev/null; rmdir \\$tmp 2>/dev/null) && exit \\$exitcode\" 0 ;\ntrap \"rm -f \\$tmpfiles 2>/dev/null; rmdir \\$tmp 2>/dev/null; exit 1\" 1 2 13 15 ;\n: ${TMPDIR=/tmp} ;\n { tmp=`(umask 077 && mktemp -d \"$TMPDIR/cgXXXXXX\") 2>/dev/null` && test -n \"$tmp\" && test -d \"$tmp\" ; } ||\n { test -n \"$RANDOM\" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||\n { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo \"Warning: creating insecure temp directory\" >&2 ; } ||\n { echo \"$me: cannot create a temporary directory in $TMPDIR\" >&2 ; exit 1 ; } ;\ndummy=$tmp/dummy ;\ntmpfiles=\"$dummy.c $dummy.o $dummy.rel $dummy\" ;\ncase $CC_FOR_BUILD,$HOST_CC,$CC in\n ,,)    echo \"int x;\" > $dummy.c ;\n\tfor c in cc gcc c89 c99 ; do\n\t  if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then\n\t     CC_FOR_BUILD=\"$c\"; break ;\n\t  fi ;\n\tdone ;\n\tif test x\"$CC_FOR_BUILD\" = x ; then\n\t  CC_FOR_BUILD=no_compiler_found ;\n\tfi\n\t;;\n ,,*)   CC_FOR_BUILD=$CC ;;\n ,*,*)  CC_FOR_BUILD=$HOST_CC ;;\nesac ; set_cc_for_build= ;'\n\n# This is needed to find uname on a Pyramid OSx when run in the BSD universe.\n# (ghazi@noc.rutgers.edu 1994-08-24)\nif (test -f /.attbin/uname) >/dev/null 2>&1 ; then\n\tPATH=$PATH:/.attbin ; export PATH\nfi\n\nUNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown\nUNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown\nUNAME_SYSTEM=`(uname -s) 2>/dev/null`  || UNAME_SYSTEM=unknown\nUNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown\n\ncase \"${UNAME_SYSTEM}\" in\nLinux|GNU|GNU/*)\n\t# If the system lacks a compiler, then just pick glibc.\n\t# We could probably try harder.\n\tLIBC=gnu\n\n\teval $set_cc_for_build\n\tcat <<-EOF > $dummy.c\n\t#include <features.h>\n\t#if defined(__UCLIBC__)\n\tLIBC=uclibc\n\t#elif defined(__dietlibc__)\n\tLIBC=dietlibc\n\t#else\n\tLIBC=gnu\n\t#endif\n\tEOF\n\teval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`\n\t;;\nesac\n\n# Note: order is significant - the case branches are not exclusive.\n\ncase \"${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}\" in\n    *:NetBSD:*:*)\n\t# NetBSD (nbsd) targets should (where applicable) match one or\n\t# more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,\n\t# *-*-netbsdecoff* and *-*-netbsd*.  For targets that recently\n\t# switched to ELF, *-*-netbsd* would select the old\n\t# object file format.  This provides both forward\n\t# compatibility and a consistent mechanism for selecting the\n\t# object file format.\n\t#\n\t# Note: NetBSD doesn't particularly care about the vendor\n\t# portion of the name.  We always set it to \"unknown\".\n\tsysctl=\"sysctl -n hw.machine_arch\"\n\tUNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \\\n\t    /usr/sbin/$sysctl 2>/dev/null || echo unknown)`\n\tcase \"${UNAME_MACHINE_ARCH}\" in\n\t    armeb) machine=armeb-unknown ;;\n\t    arm*) machine=arm-unknown ;;\n\t    sh3el) machine=shl-unknown ;;\n\t    sh3eb) machine=sh-unknown ;;\n\t    sh5el) machine=sh5le-unknown ;;\n\t    *) machine=${UNAME_MACHINE_ARCH}-unknown ;;\n\tesac\n\t# The Operating System including object format, if it has switched\n\t# to ELF recently, or will in the future.\n\tcase \"${UNAME_MACHINE_ARCH}\" in\n\t    arm*|i386|m68k|ns32k|sh3*|sparc|vax)\n\t\teval $set_cc_for_build\n\t\tif echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \\\n\t\t\t| grep -q __ELF__\n\t\tthen\n\t\t    # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).\n\t\t    # Return netbsd for either.  FIX?\n\t\t    os=netbsd\n\t\telse\n\t\t    os=netbsdelf\n\t\tfi\n\t\t;;\n\t    *)\n\t\tos=netbsd\n\t\t;;\n\tesac\n\t# The OS release\n\t# Debian GNU/NetBSD machines have a different userland, and\n\t# thus, need a distinct triplet. However, they do not need\n\t# kernel version information, so it can be replaced with a\n\t# suitable tag, in the style of linux-gnu.\n\tcase \"${UNAME_VERSION}\" in\n\t    Debian*)\n\t\trelease='-gnu'\n\t\t;;\n\t    *)\n\t\trelease=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\\./'`\n\t\t;;\n\tesac\n\t# Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:\n\t# contains redundant information, the shorter form:\n\t# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.\n\techo \"${machine}-${os}${release}\"\n\texit ;;\n    *:Bitrig:*:*)\n\tUNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`\n\techo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}\n\texit ;;\n    *:OpenBSD:*:*)\n\tUNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`\n\techo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}\n\texit ;;\n    *:ekkoBSD:*:*)\n\techo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}\n\texit ;;\n    *:SolidBSD:*:*)\n\techo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}\n\texit ;;\n    macppc:MirBSD:*:*)\n\techo powerpc-unknown-mirbsd${UNAME_RELEASE}\n\texit ;;\n    *:MirBSD:*:*)\n\techo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}\n\texit ;;\n    alpha:OSF1:*:*)\n\tcase $UNAME_RELEASE in\n\t*4.0)\n\t\tUNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`\n\t\t;;\n\t*5.*)\n\t\tUNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`\n\t\t;;\n\tesac\n\t# According to Compaq, /usr/sbin/psrinfo has been available on\n\t# OSF/1 and Tru64 systems produced since 1995.  I hope that\n\t# covers most systems running today.  This code pipes the CPU\n\t# types through head -n 1, so we only detect the type of CPU 0.\n\tALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^  The alpha \\(.*\\) processor.*$/\\1/p' | head -n 1`\n\tcase \"$ALPHA_CPU_TYPE\" in\n\t    \"EV4 (21064)\")\n\t\tUNAME_MACHINE=\"alpha\" ;;\n\t    \"EV4.5 (21064)\")\n\t\tUNAME_MACHINE=\"alpha\" ;;\n\t    \"LCA4 (21066/21068)\")\n\t\tUNAME_MACHINE=\"alpha\" ;;\n\t    \"EV5 (21164)\")\n\t\tUNAME_MACHINE=\"alphaev5\" ;;\n\t    \"EV5.6 (21164A)\")\n\t\tUNAME_MACHINE=\"alphaev56\" ;;\n\t    \"EV5.6 (21164PC)\")\n\t\tUNAME_MACHINE=\"alphapca56\" ;;\n\t    \"EV5.7 (21164PC)\")\n\t\tUNAME_MACHINE=\"alphapca57\" ;;\n\t    \"EV6 (21264)\")\n\t\tUNAME_MACHINE=\"alphaev6\" ;;\n\t    \"EV6.7 (21264A)\")\n\t\tUNAME_MACHINE=\"alphaev67\" ;;\n\t    \"EV6.8CB (21264C)\")\n\t\tUNAME_MACHINE=\"alphaev68\" ;;\n\t    \"EV6.8AL (21264B)\")\n\t\tUNAME_MACHINE=\"alphaev68\" ;;\n\t    \"EV6.8CX (21264D)\")\n\t\tUNAME_MACHINE=\"alphaev68\" ;;\n\t    \"EV6.9A (21264/EV69A)\")\n\t\tUNAME_MACHINE=\"alphaev69\" ;;\n\t    \"EV7 (21364)\")\n\t\tUNAME_MACHINE=\"alphaev7\" ;;\n\t    \"EV7.9 (21364A)\")\n\t\tUNAME_MACHINE=\"alphaev79\" ;;\n\tesac\n\t# A Pn.n version is a patched version.\n\t# A Vn.n version is a released version.\n\t# A Tn.n version is a released field test version.\n\t# A Xn.n version is an unreleased experimental baselevel.\n\t# 1.2 uses \"1.2\" for uname -r.\n\techo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`\n\t# Reset EXIT trap before exiting to avoid spurious non-zero exit code.\n\texitcode=$?\n\ttrap '' 0\n\texit $exitcode ;;\n    Alpha\\ *:Windows_NT*:*)\n\t# How do we know it's Interix rather than the generic POSIX subsystem?\n\t# Should we change UNAME_MACHINE based on the output of uname instead\n\t# of the specific Alpha model?\n\techo alpha-pc-interix\n\texit ;;\n    21064:Windows_NT:50:3)\n\techo alpha-dec-winnt3.5\n\texit ;;\n    Amiga*:UNIX_System_V:4.0:*)\n\techo m68k-unknown-sysv4\n\texit ;;\n    *:[Aa]miga[Oo][Ss]:*:*)\n\techo ${UNAME_MACHINE}-unknown-amigaos\n\texit ;;\n    *:[Mm]orph[Oo][Ss]:*:*)\n\techo ${UNAME_MACHINE}-unknown-morphos\n\texit ;;\n    *:OS/390:*:*)\n\techo i370-ibm-openedition\n\texit ;;\n    *:z/VM:*:*)\n\techo s390-ibm-zvmoe\n\texit ;;\n    *:OS400:*:*)\n\techo powerpc-ibm-os400\n\texit ;;\n    arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)\n\techo arm-acorn-riscix${UNAME_RELEASE}\n\texit ;;\n    arm*:riscos:*:*|arm*:RISCOS:*:*)\n\techo arm-unknown-riscos\n\texit ;;\n    SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)\n\techo hppa1.1-hitachi-hiuxmpp\n\texit ;;\n    Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)\n\t# akee@wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.\n\tif test \"`(/bin/universe) 2>/dev/null`\" = att ; then\n\t\techo pyramid-pyramid-sysv3\n\telse\n\t\techo pyramid-pyramid-bsd\n\tfi\n\texit ;;\n    NILE*:*:*:dcosx)\n\techo pyramid-pyramid-svr4\n\texit ;;\n    DRS?6000:unix:4.0:6*)\n\techo sparc-icl-nx6\n\texit ;;\n    DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)\n\tcase `/usr/bin/uname -p` in\n\t    sparc) echo sparc-icl-nx7; exit ;;\n\tesac ;;\n    s390x:SunOS:*:*)\n\techo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    sun4H:SunOS:5.*:*)\n\techo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)\n\techo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)\n\techo i386-pc-auroraux${UNAME_RELEASE}\n\texit ;;\n    i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)\n\teval $set_cc_for_build\n\tSUN_ARCH=\"i386\"\n\t# If there is a compiler, see if it is configured for 64-bit objects.\n\t# Note that the Sun cc does not turn __LP64__ into 1 like gcc does.\n\t# This test works for both compilers.\n\tif [ \"$CC_FOR_BUILD\" != 'no_compiler_found' ]; then\n\t    if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \\\n\t\t(CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \\\n\t\tgrep IS_64BIT_ARCH >/dev/null\n\t    then\n\t\tSUN_ARCH=\"x86_64\"\n\t    fi\n\tfi\n\techo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    sun4*:SunOS:6*:*)\n\t# According to config.sub, this is the proper way to canonicalize\n\t# SunOS6.  Hard to guess exactly what SunOS6 will be like, but\n\t# it's likely to be more like Solaris than SunOS4.\n\techo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    sun4*:SunOS:*:*)\n\tcase \"`/usr/bin/arch -k`\" in\n\t    Series*|S4*)\n\t\tUNAME_RELEASE=`uname -v`\n\t\t;;\n\tesac\n\t# Japanese Language versions have a version number like `4.1.3-JL'.\n\techo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`\n\texit ;;\n    sun3*:SunOS:*:*)\n\techo m68k-sun-sunos${UNAME_RELEASE}\n\texit ;;\n    sun*:*:4.2BSD:*)\n\tUNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`\n\ttest \"x${UNAME_RELEASE}\" = \"x\" && UNAME_RELEASE=3\n\tcase \"`/bin/arch`\" in\n\t    sun3)\n\t\techo m68k-sun-sunos${UNAME_RELEASE}\n\t\t;;\n\t    sun4)\n\t\techo sparc-sun-sunos${UNAME_RELEASE}\n\t\t;;\n\tesac\n\texit ;;\n    aushp:SunOS:*:*)\n\techo sparc-auspex-sunos${UNAME_RELEASE}\n\texit ;;\n    # The situation for MiNT is a little confusing.  The machine name\n    # can be virtually everything (everything which is not\n    # \"atarist\" or \"atariste\" at least should have a processor\n    # > m68000).  The system name ranges from \"MiNT\" over \"FreeMiNT\"\n    # to the lowercase version \"mint\" (or \"freemint\").  Finally\n    # the system name \"TOS\" denotes a system which is actually not\n    # MiNT.  But MiNT is downward compatible to TOS, so this should\n    # be no problem.\n    atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)\n\techo m68k-atari-mint${UNAME_RELEASE}\n\texit ;;\n    atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)\n\techo m68k-atari-mint${UNAME_RELEASE}\n\texit ;;\n    *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)\n\techo m68k-atari-mint${UNAME_RELEASE}\n\texit ;;\n    milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)\n\techo m68k-milan-mint${UNAME_RELEASE}\n\texit ;;\n    hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)\n\techo m68k-hades-mint${UNAME_RELEASE}\n\texit ;;\n    *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)\n\techo m68k-unknown-mint${UNAME_RELEASE}\n\texit ;;\n    m68k:machten:*:*)\n\techo m68k-apple-machten${UNAME_RELEASE}\n\texit ;;\n    powerpc:machten:*:*)\n\techo powerpc-apple-machten${UNAME_RELEASE}\n\texit ;;\n    RISC*:Mach:*:*)\n\techo mips-dec-mach_bsd4.3\n\texit ;;\n    RISC*:ULTRIX:*:*)\n\techo mips-dec-ultrix${UNAME_RELEASE}\n\texit ;;\n    VAX*:ULTRIX*:*:*)\n\techo vax-dec-ultrix${UNAME_RELEASE}\n\texit ;;\n    2020:CLIX:*:* | 2430:CLIX:*:*)\n\techo clipper-intergraph-clix${UNAME_RELEASE}\n\texit ;;\n    mips:*:*:UMIPS | mips:*:*:RISCos)\n\teval $set_cc_for_build\n\tsed 's/^\t//' << EOF >$dummy.c\n#ifdef __cplusplus\n#include <stdio.h>  /* for printf() prototype */\n\tint main (int argc, char *argv[]) {\n#else\n\tint main (argc, argv) int argc; char *argv[]; {\n#endif\n\t#if defined (host_mips) && defined (MIPSEB)\n\t#if defined (SYSTYPE_SYSV)\n\t  printf (\"mips-mips-riscos%ssysv\\n\", argv[1]); exit (0);\n\t#endif\n\t#if defined (SYSTYPE_SVR4)\n\t  printf (\"mips-mips-riscos%ssvr4\\n\", argv[1]); exit (0);\n\t#endif\n\t#if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)\n\t  printf (\"mips-mips-riscos%sbsd\\n\", argv[1]); exit (0);\n\t#endif\n\t#endif\n\t  exit (-1);\n\t}\nEOF\n\t$CC_FOR_BUILD -o $dummy $dummy.c &&\n\t  dummyarg=`echo \"${UNAME_RELEASE}\" | sed -n 's/\\([0-9]*\\).*/\\1/p'` &&\n\t  SYSTEM_NAME=`$dummy $dummyarg` &&\n\t    { echo \"$SYSTEM_NAME\"; exit; }\n\techo mips-mips-riscos${UNAME_RELEASE}\n\texit ;;\n    Motorola:PowerMAX_OS:*:*)\n\techo powerpc-motorola-powermax\n\texit ;;\n    Motorola:*:4.3:PL8-*)\n\techo powerpc-harris-powermax\n\texit ;;\n    Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)\n\techo powerpc-harris-powermax\n\texit ;;\n    Night_Hawk:Power_UNIX:*:*)\n\techo powerpc-harris-powerunix\n\texit ;;\n    m88k:CX/UX:7*:*)\n\techo m88k-harris-cxux7\n\texit ;;\n    m88k:*:4*:R4*)\n\techo m88k-motorola-sysv4\n\texit ;;\n    m88k:*:3*:R3*)\n\techo m88k-motorola-sysv3\n\texit ;;\n    AViiON:dgux:*:*)\n\t# DG/UX returns AViiON for all architectures\n\tUNAME_PROCESSOR=`/usr/bin/uname -p`\n\tif [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]\n\tthen\n\t    if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \\\n\t       [ ${TARGET_BINARY_INTERFACE}x = x ]\n\t    then\n\t\techo m88k-dg-dgux${UNAME_RELEASE}\n\t    else\n\t\techo m88k-dg-dguxbcs${UNAME_RELEASE}\n\t    fi\n\telse\n\t    echo i586-dg-dgux${UNAME_RELEASE}\n\tfi\n\texit ;;\n    M88*:DolphinOS:*:*)\t# DolphinOS (SVR3)\n\techo m88k-dolphin-sysv3\n\texit ;;\n    M88*:*:R3*:*)\n\t# Delta 88k system running SVR3\n\techo m88k-motorola-sysv3\n\texit ;;\n    XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)\n\techo m88k-tektronix-sysv3\n\texit ;;\n    Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)\n\techo m68k-tektronix-bsd\n\texit ;;\n    *:IRIX*:*:*)\n\techo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`\n\texit ;;\n    ????????:AIX?:[12].1:2)   # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.\n\techo romp-ibm-aix     # uname -m gives an 8 hex-code CPU id\n\texit ;;               # Note that: echo \"'`uname -s`'\" gives 'AIX '\n    i*86:AIX:*:*)\n\techo i386-ibm-aix\n\texit ;;\n    ia64:AIX:*:*)\n\tif [ -x /usr/bin/oslevel ] ; then\n\t\tIBM_REV=`/usr/bin/oslevel`\n\telse\n\t\tIBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}\n\tfi\n\techo ${UNAME_MACHINE}-ibm-aix${IBM_REV}\n\texit ;;\n    *:AIX:2:3)\n\tif grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then\n\t\teval $set_cc_for_build\n\t\tsed 's/^\t\t//' << EOF >$dummy.c\n\t\t#include <sys/systemcfg.h>\n\n\t\tmain()\n\t\t\t{\n\t\t\tif (!__power_pc())\n\t\t\t\texit(1);\n\t\t\tputs(\"powerpc-ibm-aix3.2.5\");\n\t\t\texit(0);\n\t\t\t}\nEOF\n\t\tif $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`\n\t\tthen\n\t\t\techo \"$SYSTEM_NAME\"\n\t\telse\n\t\t\techo rs6000-ibm-aix3.2.5\n\t\tfi\n\telif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then\n\t\techo rs6000-ibm-aix3.2.4\n\telse\n\t\techo rs6000-ibm-aix3.2\n\tfi\n\texit ;;\n    *:AIX:*:[4567])\n\tIBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`\n\tif /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then\n\t\tIBM_ARCH=rs6000\n\telse\n\t\tIBM_ARCH=powerpc\n\tfi\n\tif [ -x /usr/bin/lslpp ] ; then\n\t\tIBM_REV=`/usr/bin/lslpp -Lqc bos.rte.libc |\n\t\t\t   awk -F: '{ print $3 }' | sed s/[0-9]*$/0/`\n\telse\n\t\tIBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}\n\tfi\n\techo ${IBM_ARCH}-ibm-aix${IBM_REV}\n\texit ;;\n    *:AIX:*:*)\n\techo rs6000-ibm-aix\n\texit ;;\n    ibmrt:4.4BSD:*|romp-ibm:BSD:*)\n\techo romp-ibm-bsd4.4\n\texit ;;\n    ibmrt:*BSD:*|romp-ibm:BSD:*)            # covers RT/PC BSD and\n\techo romp-ibm-bsd${UNAME_RELEASE}   # 4.3 with uname added to\n\texit ;;                             # report: romp-ibm BSD 4.3\n    *:BOSX:*:*)\n\techo rs6000-bull-bosx\n\texit ;;\n    DPX/2?00:B.O.S.:*:*)\n\techo m68k-bull-sysv3\n\texit ;;\n    9000/[34]??:4.3bsd:1.*:*)\n\techo m68k-hp-bsd\n\texit ;;\n    hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)\n\techo m68k-hp-bsd4.4\n\texit ;;\n    9000/[34678]??:HP-UX:*:*)\n\tHPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`\n\tcase \"${UNAME_MACHINE}\" in\n\t    9000/31? )            HP_ARCH=m68000 ;;\n\t    9000/[34]?? )         HP_ARCH=m68k ;;\n\t    9000/[678][0-9][0-9])\n\t\tif [ -x /usr/bin/getconf ]; then\n\t\t    sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`\n\t\t    sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`\n\t\t    case \"${sc_cpu_version}\" in\n\t\t      523) HP_ARCH=\"hppa1.0\" ;; # CPU_PA_RISC1_0\n\t\t      528) HP_ARCH=\"hppa1.1\" ;; # CPU_PA_RISC1_1\n\t\t      532)                      # CPU_PA_RISC2_0\n\t\t\tcase \"${sc_kernel_bits}\" in\n\t\t\t  32) HP_ARCH=\"hppa2.0n\" ;;\n\t\t\t  64) HP_ARCH=\"hppa2.0w\" ;;\n\t\t\t  '') HP_ARCH=\"hppa2.0\" ;;   # HP-UX 10.20\n\t\t\tesac ;;\n\t\t    esac\n\t\tfi\n\t\tif [ \"${HP_ARCH}\" = \"\" ]; then\n\t\t    eval $set_cc_for_build\n\t\t    sed 's/^\t\t//' << EOF >$dummy.c\n\n\t\t#define _HPUX_SOURCE\n\t\t#include <stdlib.h>\n\t\t#include <unistd.h>\n\n\t\tint main ()\n\t\t{\n\t\t#if defined(_SC_KERNEL_BITS)\n\t\t    long bits = sysconf(_SC_KERNEL_BITS);\n\t\t#endif\n\t\t    long cpu  = sysconf (_SC_CPU_VERSION);\n\n\t\t    switch (cpu)\n\t\t\t{\n\t\t\tcase CPU_PA_RISC1_0: puts (\"hppa1.0\"); break;\n\t\t\tcase CPU_PA_RISC1_1: puts (\"hppa1.1\"); break;\n\t\t\tcase CPU_PA_RISC2_0:\n\t\t#if defined(_SC_KERNEL_BITS)\n\t\t\t    switch (bits)\n\t\t\t\t{\n\t\t\t\tcase 64: puts (\"hppa2.0w\"); break;\n\t\t\t\tcase 32: puts (\"hppa2.0n\"); break;\n\t\t\t\tdefault: puts (\"hppa2.0\"); break;\n\t\t\t\t} break;\n\t\t#else  /* !defined(_SC_KERNEL_BITS) */\n\t\t\t    puts (\"hppa2.0\"); break;\n\t\t#endif\n\t\t\tdefault: puts (\"hppa1.0\"); break;\n\t\t\t}\n\t\t    exit (0);\n\t\t}\nEOF\n\t\t    (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`\n\t\t    test -z \"$HP_ARCH\" && HP_ARCH=hppa\n\t\tfi ;;\n\tesac\n\tif [ ${HP_ARCH} = \"hppa2.0w\" ]\n\tthen\n\t    eval $set_cc_for_build\n\n\t    # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating\n\t    # 32-bit code.  hppa64-hp-hpux* has the same kernel and a compiler\n\t    # generating 64-bit code.  GNU and HP use different nomenclature:\n\t    #\n\t    # $ CC_FOR_BUILD=cc ./config.guess\n\t    # => hppa2.0w-hp-hpux11.23\n\t    # $ CC_FOR_BUILD=\"cc +DA2.0w\" ./config.guess\n\t    # => hppa64-hp-hpux11.23\n\n\t    if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |\n\t\tgrep -q __LP64__\n\t    then\n\t\tHP_ARCH=\"hppa2.0w\"\n\t    else\n\t\tHP_ARCH=\"hppa64\"\n\t    fi\n\tfi\n\techo ${HP_ARCH}-hp-hpux${HPUX_REV}\n\texit ;;\n    ia64:HP-UX:*:*)\n\tHPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`\n\techo ia64-hp-hpux${HPUX_REV}\n\texit ;;\n    3050*:HI-UX:*:*)\n\teval $set_cc_for_build\n\tsed 's/^\t//' << EOF >$dummy.c\n\t#include <unistd.h>\n\tint\n\tmain ()\n\t{\n\t  long cpu = sysconf (_SC_CPU_VERSION);\n\t  /* The order matters, because CPU_IS_HP_MC68K erroneously returns\n\t     true for CPU_PA_RISC1_0.  CPU_IS_PA_RISC returns correct\n\t     results, however.  */\n\t  if (CPU_IS_PA_RISC (cpu))\n\t    {\n\t      switch (cpu)\n\t\t{\n\t\t  case CPU_PA_RISC1_0: puts (\"hppa1.0-hitachi-hiuxwe2\"); break;\n\t\t  case CPU_PA_RISC1_1: puts (\"hppa1.1-hitachi-hiuxwe2\"); break;\n\t\t  case CPU_PA_RISC2_0: puts (\"hppa2.0-hitachi-hiuxwe2\"); break;\n\t\t  default: puts (\"hppa-hitachi-hiuxwe2\"); break;\n\t\t}\n\t    }\n\t  else if (CPU_IS_HP_MC68K (cpu))\n\t    puts (\"m68k-hitachi-hiuxwe2\");\n\t  else puts (\"unknown-hitachi-hiuxwe2\");\n\t  exit (0);\n\t}\nEOF\n\t$CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&\n\t\t{ echo \"$SYSTEM_NAME\"; exit; }\n\techo unknown-hitachi-hiuxwe2\n\texit ;;\n    9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )\n\techo hppa1.1-hp-bsd\n\texit ;;\n    9000/8??:4.3bsd:*:*)\n\techo hppa1.0-hp-bsd\n\texit ;;\n    *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)\n\techo hppa1.0-hp-mpeix\n\texit ;;\n    hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )\n\techo hppa1.1-hp-osf\n\texit ;;\n    hp8??:OSF1:*:*)\n\techo hppa1.0-hp-osf\n\texit ;;\n    i*86:OSF1:*:*)\n\tif [ -x /usr/sbin/sysversion ] ; then\n\t    echo ${UNAME_MACHINE}-unknown-osf1mk\n\telse\n\t    echo ${UNAME_MACHINE}-unknown-osf1\n\tfi\n\texit ;;\n    parisc*:Lites*:*:*)\n\techo hppa1.1-hp-lites\n\texit ;;\n    C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)\n\techo c1-convex-bsd\n\texit ;;\n    C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)\n\tif getsysinfo -f scalar_acc\n\tthen echo c32-convex-bsd\n\telse echo c2-convex-bsd\n\tfi\n\texit ;;\n    C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)\n\techo c34-convex-bsd\n\texit ;;\n    C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)\n\techo c38-convex-bsd\n\texit ;;\n    C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)\n\techo c4-convex-bsd\n\texit ;;\n    CRAY*Y-MP:*:*:*)\n\techo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    CRAY*[A-Z]90:*:*:*)\n\techo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \\\n\t| sed -e 's/CRAY.*\\([A-Z]90\\)/\\1/' \\\n\t      -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \\\n\t      -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    CRAY*TS:*:*:*)\n\techo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    CRAY*T3E:*:*:*)\n\techo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    CRAY*SV1:*:*:*)\n\techo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    *:UNICOS/mp:*:*)\n\techo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\\.[^.]*$/.X/'\n\texit ;;\n    F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)\n\tFUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`\n\tFUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\\///'`\n\tFUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`\n\techo \"${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}\"\n\texit ;;\n    5000:UNIX_System_V:4.*:*)\n\tFUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\\///'`\n\tFUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`\n\techo \"sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}\"\n\texit ;;\n    i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\\ Embedded/OS:*:*)\n\techo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}\n\texit ;;\n    sparc*:BSD/OS:*:*)\n\techo sparc-unknown-bsdi${UNAME_RELEASE}\n\texit ;;\n    *:BSD/OS:*:*)\n\techo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}\n\texit ;;\n    *:FreeBSD:*:*)\n\tUNAME_PROCESSOR=`/usr/bin/uname -p`\n\tcase ${UNAME_PROCESSOR} in\n\t    amd64)\n\t\techo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;\n\t    *)\n\t\techo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;\n\tesac\n\texit ;;\n    i*:CYGWIN*:*)\n\techo ${UNAME_MACHINE}-pc-cygwin\n\texit ;;\n    *:MINGW64*:*)\n\techo ${UNAME_MACHINE}-pc-mingw64\n\texit ;;\n    *:MINGW*:*)\n\techo ${UNAME_MACHINE}-pc-mingw32\n\texit ;;\n    *:MSYS*:*)\n\techo ${UNAME_MACHINE}-pc-msys\n\texit ;;\n    i*:windows32*:*)\n\t# uname -m includes \"-pc\" on this system.\n\techo ${UNAME_MACHINE}-mingw32\n\texit ;;\n    i*:PW*:*)\n\techo ${UNAME_MACHINE}-pc-pw32\n\texit ;;\n    *:Interix*:*)\n\tcase ${UNAME_MACHINE} in\n\t    x86)\n\t\techo i586-pc-interix${UNAME_RELEASE}\n\t\texit ;;\n\t    authenticamd | genuineintel | EM64T)\n\t\techo x86_64-unknown-interix${UNAME_RELEASE}\n\t\texit ;;\n\t    IA64)\n\t\techo ia64-unknown-interix${UNAME_RELEASE}\n\t\texit ;;\n\tesac ;;\n    [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)\n\techo i${UNAME_MACHINE}-pc-mks\n\texit ;;\n    8664:Windows_NT:*)\n\techo x86_64-pc-mks\n\texit ;;\n    i*:Windows_NT*:* | Pentium*:Windows_NT*:*)\n\t# How do we know it's Interix rather than the generic POSIX subsystem?\n\t# It also conflicts with pre-2.0 versions of AT&T UWIN. Should we\n\t# UNAME_MACHINE based on the output of uname instead of i386?\n\techo i586-pc-interix\n\texit ;;\n    i*:UWIN*:*)\n\techo ${UNAME_MACHINE}-pc-uwin\n\texit ;;\n    amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)\n\techo x86_64-unknown-cygwin\n\texit ;;\n    p*:CYGWIN*:*)\n\techo powerpcle-unknown-cygwin\n\texit ;;\n    prep*:SunOS:5.*:*)\n\techo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`\n\texit ;;\n    *:GNU:*:*)\n\t# the GNU system\n\techo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`\n\texit ;;\n    *:GNU/*:*:*)\n\t# other systems with GNU libc and userland\n\techo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}\n\texit ;;\n    i*86:Minix:*:*)\n\techo ${UNAME_MACHINE}-pc-minix\n\texit ;;\n    aarch64:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    aarch64_be:Linux:*:*)\n\tUNAME_MACHINE=aarch64_be\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    alpha:Linux:*:*)\n\tcase `sed -n '/^cpu model/s/^.*: \\(.*\\)/\\1/p' < /proc/cpuinfo` in\n\t  EV5)   UNAME_MACHINE=alphaev5 ;;\n\t  EV56)  UNAME_MACHINE=alphaev56 ;;\n\t  PCA56) UNAME_MACHINE=alphapca56 ;;\n\t  PCA57) UNAME_MACHINE=alphapca56 ;;\n\t  EV6)   UNAME_MACHINE=alphaev6 ;;\n\t  EV67)  UNAME_MACHINE=alphaev67 ;;\n\t  EV68*) UNAME_MACHINE=alphaev68 ;;\n\tesac\n\tobjdump --private-headers /bin/sh | grep -q ld.so.1\n\tif test \"$?\" = 0 ; then LIBC=\"gnulibc1\" ; fi\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    arc:Linux:*:* | arceb:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    arm*:Linux:*:*)\n\teval $set_cc_for_build\n\tif echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \\\n\t    | grep -q __ARM_EABI__\n\tthen\n\t    echo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\telse\n\t    if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \\\n\t\t| grep -q __ARM_PCS_VFP\n\t    then\n\t\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi\n\t    else\n\t\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf\n\t    fi\n\tfi\n\texit ;;\n    avr32*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    cris:Linux:*:*)\n\techo ${UNAME_MACHINE}-axis-linux-${LIBC}\n\texit ;;\n    crisv32:Linux:*:*)\n\techo ${UNAME_MACHINE}-axis-linux-${LIBC}\n\texit ;;\n    frv:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    hexagon:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    i*86:Linux:*:*)\n\techo ${UNAME_MACHINE}-pc-linux-${LIBC}\n\texit ;;\n    ia64:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    m32r*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    m68*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    mips:Linux:*:* | mips64:Linux:*:*)\n\teval $set_cc_for_build\n\tsed 's/^\t//' << EOF >$dummy.c\n\t#undef CPU\n\t#undef ${UNAME_MACHINE}\n\t#undef ${UNAME_MACHINE}el\n\t#if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)\n\tCPU=${UNAME_MACHINE}el\n\t#else\n\t#if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)\n\tCPU=${UNAME_MACHINE}\n\t#else\n\tCPU=\n\t#endif\n\t#endif\nEOF\n\teval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`\n\ttest x\"${CPU}\" != x && { echo \"${CPU}-unknown-linux-${LIBC}\"; exit; }\n\t;;\n    openrisc*:Linux:*:*)\n\techo or1k-unknown-linux-${LIBC}\n\texit ;;\n    or32:Linux:*:* | or1k*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    padre:Linux:*:*)\n\techo sparc-unknown-linux-${LIBC}\n\texit ;;\n    parisc64:Linux:*:* | hppa64:Linux:*:*)\n\techo hppa64-unknown-linux-${LIBC}\n\texit ;;\n    parisc:Linux:*:* | hppa:Linux:*:*)\n\t# Look for CPU level\n\tcase `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in\n\t  PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;\n\t  PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;\n\t  *)    echo hppa-unknown-linux-${LIBC} ;;\n\tesac\n\texit ;;\n    ppc64:Linux:*:*)\n\techo powerpc64-unknown-linux-${LIBC}\n\texit ;;\n    ppc:Linux:*:*)\n\techo powerpc-unknown-linux-${LIBC}\n\texit ;;\n    ppc64le:Linux:*:*)\n\techo powerpc64le-unknown-linux-${LIBC}\n\texit ;;\n    ppcle:Linux:*:*)\n\techo powerpcle-unknown-linux-${LIBC}\n\texit ;;\n    s390:Linux:*:* | s390x:Linux:*:*)\n\techo ${UNAME_MACHINE}-ibm-linux-${LIBC}\n\texit ;;\n    sh64*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    sh*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    sparc:Linux:*:* | sparc64:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    tile*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    vax:Linux:*:*)\n\techo ${UNAME_MACHINE}-dec-linux-${LIBC}\n\texit ;;\n    x86_64:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    xtensa*:Linux:*:*)\n\techo ${UNAME_MACHINE}-unknown-linux-${LIBC}\n\texit ;;\n    i*86:DYNIX/ptx:4*:*)\n\t# ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.\n\t# earlier versions are messed up and put the nodename in both\n\t# sysname and nodename.\n\techo i386-sequent-sysv4\n\texit ;;\n    i*86:UNIX_SV:4.2MP:2.*)\n\t# Unixware is an offshoot of SVR4, but it has its own version\n\t# number series starting with 2...\n\t# I am not positive that other SVR4 systems won't match this,\n\t# I just have to hope.  -- rms.\n\t# Use sysv4.2uw... so that sysv4* matches it.\n\techo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}\n\texit ;;\n    i*86:OS/2:*:*)\n\t# If we were able to find `uname', then EMX Unix compatibility\n\t# is probably installed.\n\techo ${UNAME_MACHINE}-pc-os2-emx\n\texit ;;\n    i*86:XTS-300:*:STOP)\n\techo ${UNAME_MACHINE}-unknown-stop\n\texit ;;\n    i*86:atheos:*:*)\n\techo ${UNAME_MACHINE}-unknown-atheos\n\texit ;;\n    i*86:syllable:*:*)\n\techo ${UNAME_MACHINE}-pc-syllable\n\texit ;;\n    i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)\n\techo i386-unknown-lynxos${UNAME_RELEASE}\n\texit ;;\n    i*86:*DOS:*:*)\n\techo ${UNAME_MACHINE}-pc-msdosdjgpp\n\texit ;;\n    i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)\n\tUNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\\/MP$//'`\n\tif grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then\n\t\techo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}\n\telse\n\t\techo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}\n\tfi\n\texit ;;\n    i*86:*:5:[678]*)\n\t# UnixWare 7.x, OpenUNIX and OpenServer 6.\n\tcase `/bin/uname -X | grep \"^Machine\"` in\n\t    *486*)\t     UNAME_MACHINE=i486 ;;\n\t    *Pentium)\t     UNAME_MACHINE=i586 ;;\n\t    *Pent*|*Celeron) UNAME_MACHINE=i686 ;;\n\tesac\n\techo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}\n\texit ;;\n    i*86:*:3.2:*)\n\tif test -f /usr/options/cb.name; then\n\t\tUNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`\n\t\techo ${UNAME_MACHINE}-pc-isc$UNAME_REL\n\telif /bin/uname -X 2>/dev/null >/dev/null ; then\n\t\tUNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`\n\t\t(/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486\n\t\t(/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \\\n\t\t\t&& UNAME_MACHINE=i586\n\t\t(/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \\\n\t\t\t&& UNAME_MACHINE=i686\n\t\t(/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \\\n\t\t\t&& UNAME_MACHINE=i686\n\t\techo ${UNAME_MACHINE}-pc-sco$UNAME_REL\n\telse\n\t\techo ${UNAME_MACHINE}-pc-sysv32\n\tfi\n\texit ;;\n    pc:*:*:*)\n\t# Left here for compatibility:\n\t# uname -m prints for DJGPP always 'pc', but it prints nothing about\n\t# the processor, so we play safe by assuming i586.\n\t# Note: whatever this is, it MUST be the same as what config.sub\n\t# prints for the \"djgpp\" host, or else GDB configury will decide that\n\t# this is a cross-build.\n\techo i586-pc-msdosdjgpp\n\texit ;;\n    Intel:Mach:3*:*)\n\techo i386-pc-mach3\n\texit ;;\n    paragon:*:*:*)\n\techo i860-intel-osf1\n\texit ;;\n    i860:*:4.*:*) # i860-SVR4\n\tif grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then\n\t  echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4\n\telse # Add other i860-SVR4 vendors below as they are discovered.\n\t  echo i860-unknown-sysv${UNAME_RELEASE}  # Unknown i860-SVR4\n\tfi\n\texit ;;\n    mini*:CTIX:SYS*5:*)\n\t# \"miniframe\"\n\techo m68010-convergent-sysv\n\texit ;;\n    mc68k:UNIX:SYSTEM5:3.51m)\n\techo m68k-convergent-sysv\n\texit ;;\n    M680?0:D-NIX:5.3:*)\n\techo m68k-diab-dnix\n\texit ;;\n    M68*:*:R3V[5678]*:*)\n\ttest -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;\n    3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)\n\tOS_REL=''\n\ttest -r /etc/.relid \\\n\t&& OS_REL=.`sed -n 's/[^ ]* [^ ]* \\([0-9][0-9]\\).*/\\1/p' < /etc/.relid`\n\t/bin/uname -p 2>/dev/null | grep 86 >/dev/null \\\n\t  && { echo i486-ncr-sysv4.3${OS_REL}; exit; }\n\t/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \\\n\t  && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;\n    3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)\n\t/bin/uname -p 2>/dev/null | grep 86 >/dev/null \\\n\t  && { echo i486-ncr-sysv4; exit; } ;;\n    NCR*:*:4.2:* | MPRAS*:*:4.2:*)\n\tOS_REL='.3'\n\ttest -r /etc/.relid \\\n\t    && OS_REL=.`sed -n 's/[^ ]* [^ ]* \\([0-9][0-9]\\).*/\\1/p' < /etc/.relid`\n\t/bin/uname -p 2>/dev/null | grep 86 >/dev/null \\\n\t    && { echo i486-ncr-sysv4.3${OS_REL}; exit; }\n\t/bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \\\n\t    && { echo i586-ncr-sysv4.3${OS_REL}; exit; }\n\t/bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \\\n\t    && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;\n    m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)\n\techo m68k-unknown-lynxos${UNAME_RELEASE}\n\texit ;;\n    mc68030:UNIX_System_V:4.*:*)\n\techo m68k-atari-sysv4\n\texit ;;\n    TSUNAMI:LynxOS:2.*:*)\n\techo sparc-unknown-lynxos${UNAME_RELEASE}\n\texit ;;\n    rs6000:LynxOS:2.*:*)\n\techo rs6000-unknown-lynxos${UNAME_RELEASE}\n\texit ;;\n    PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)\n\techo powerpc-unknown-lynxos${UNAME_RELEASE}\n\texit ;;\n    SM[BE]S:UNIX_SV:*:*)\n\techo mips-dde-sysv${UNAME_RELEASE}\n\texit ;;\n    RM*:ReliantUNIX-*:*:*)\n\techo mips-sni-sysv4\n\texit ;;\n    RM*:SINIX-*:*:*)\n\techo mips-sni-sysv4\n\texit ;;\n    *:SINIX-*:*:*)\n\tif uname -p 2>/dev/null >/dev/null ; then\n\t\tUNAME_MACHINE=`(uname -p) 2>/dev/null`\n\t\techo ${UNAME_MACHINE}-sni-sysv4\n\telse\n\t\techo ns32k-sni-sysv\n\tfi\n\texit ;;\n    PENTIUM:*:4.0*:*)\t# Unisys `ClearPath HMP IX 4000' SVR4/MP effort\n\t\t\t# says <Richard.M.Bartel@ccMail.Census.GOV>\n\techo i586-unisys-sysv4\n\texit ;;\n    *:UNIX_System_V:4*:FTX*)\n\t# From Gerald Hewes <hewes@openmarket.com>.\n\t# How about differentiating between stratus architectures? -djm\n\techo hppa1.1-stratus-sysv4\n\texit ;;\n    *:*:*:FTX*)\n\t# From seanf@swdc.stratus.com.\n\techo i860-stratus-sysv4\n\texit ;;\n    i*86:VOS:*:*)\n\t# From Paul.Green@stratus.com.\n\techo ${UNAME_MACHINE}-stratus-vos\n\texit ;;\n    *:VOS:*:*)\n\t# From Paul.Green@stratus.com.\n\techo hppa1.1-stratus-vos\n\texit ;;\n    mc68*:A/UX:*:*)\n\techo m68k-apple-aux${UNAME_RELEASE}\n\texit ;;\n    news*:NEWS-OS:6*:*)\n\techo mips-sony-newsos6\n\texit ;;\n    R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)\n\tif [ -d /usr/nec ]; then\n\t\techo mips-nec-sysv${UNAME_RELEASE}\n\telse\n\t\techo mips-unknown-sysv${UNAME_RELEASE}\n\tfi\n\texit ;;\n    BeBox:BeOS:*:*)\t# BeOS running on hardware made by Be, PPC only.\n\techo powerpc-be-beos\n\texit ;;\n    BeMac:BeOS:*:*)\t# BeOS running on Mac or Mac clone, PPC only.\n\techo powerpc-apple-beos\n\texit ;;\n    BePC:BeOS:*:*)\t# BeOS running on Intel PC compatible.\n\techo i586-pc-beos\n\texit ;;\n    BePC:Haiku:*:*)\t# Haiku running on Intel PC compatible.\n\techo i586-pc-haiku\n\texit ;;\n    x86_64:Haiku:*:*)\n\techo x86_64-unknown-haiku\n\texit ;;\n    SX-4:SUPER-UX:*:*)\n\techo sx4-nec-superux${UNAME_RELEASE}\n\texit ;;\n    SX-5:SUPER-UX:*:*)\n\techo sx5-nec-superux${UNAME_RELEASE}\n\texit ;;\n    SX-6:SUPER-UX:*:*)\n\techo sx6-nec-superux${UNAME_RELEASE}\n\texit ;;\n    SX-7:SUPER-UX:*:*)\n\techo sx7-nec-superux${UNAME_RELEASE}\n\texit ;;\n    SX-8:SUPER-UX:*:*)\n\techo sx8-nec-superux${UNAME_RELEASE}\n\texit ;;\n    SX-8R:SUPER-UX:*:*)\n\techo sx8r-nec-superux${UNAME_RELEASE}\n\texit ;;\n    Power*:Rhapsody:*:*)\n\techo powerpc-apple-rhapsody${UNAME_RELEASE}\n\texit ;;\n    *:Rhapsody:*:*)\n\techo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}\n\texit ;;\n    *:Darwin:*:*)\n\tUNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown\n\teval $set_cc_for_build\n\tif test \"$UNAME_PROCESSOR\" = unknown ; then\n\t    UNAME_PROCESSOR=powerpc\n\tfi\n\tif test `echo \"$UNAME_RELEASE\" | sed -e 's/\\..*//'` -le 10 ; then\n\t    if [ \"$CC_FOR_BUILD\" != 'no_compiler_found' ]; then\n\t\tif (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \\\n\t\t    (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \\\n\t\t    grep IS_64BIT_ARCH >/dev/null\n\t\tthen\n\t\t    case $UNAME_PROCESSOR in\n\t\t\ti386) UNAME_PROCESSOR=x86_64 ;;\n\t\t\tpowerpc) UNAME_PROCESSOR=powerpc64 ;;\n\t\t    esac\n\t\tfi\n\t    fi\n\telif test \"$UNAME_PROCESSOR\" = i386 ; then\n\t    # Avoid executing cc on OS X 10.9, as it ships with a stub\n\t    # that puts up a graphical alert prompting to install\n\t    # developer tools.  Any system running Mac OS X 10.7 or\n\t    # later (Darwin 11 and later) is required to have a 64-bit\n\t    # processor. This is not true of the ARM version of Darwin\n\t    # that Apple uses in portable devices.\n\t    UNAME_PROCESSOR=x86_64\n\tfi\n\techo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}\n\texit ;;\n    *:procnto*:*:* | *:QNX:[0123456789]*:*)\n\tUNAME_PROCESSOR=`uname -p`\n\tif test \"$UNAME_PROCESSOR\" = \"x86\"; then\n\t\tUNAME_PROCESSOR=i386\n\t\tUNAME_MACHINE=pc\n\tfi\n\techo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}\n\texit ;;\n    *:QNX:*:4*)\n\techo i386-pc-qnx\n\texit ;;\n    NEO-?:NONSTOP_KERNEL:*:*)\n\techo neo-tandem-nsk${UNAME_RELEASE}\n\texit ;;\n    NSE-*:NONSTOP_KERNEL:*:*)\n\techo nse-tandem-nsk${UNAME_RELEASE}\n\texit ;;\n    NSR-?:NONSTOP_KERNEL:*:*)\n\techo nsr-tandem-nsk${UNAME_RELEASE}\n\texit ;;\n    *:NonStop-UX:*:*)\n\techo mips-compaq-nonstopux\n\texit ;;\n    BS2000:POSIX*:*:*)\n\techo bs2000-siemens-sysv\n\texit ;;\n    DS/*:UNIX_System_V:*:*)\n\techo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}\n\texit ;;\n    *:Plan9:*:*)\n\t# \"uname -m\" is not consistent, so use $cputype instead. 386\n\t# is converted to i386 for consistency with other x86\n\t# operating systems.\n\tif test \"$cputype\" = \"386\"; then\n\t    UNAME_MACHINE=i386\n\telse\n\t    UNAME_MACHINE=\"$cputype\"\n\tfi\n\techo ${UNAME_MACHINE}-unknown-plan9\n\texit ;;\n    *:TOPS-10:*:*)\n\techo pdp10-unknown-tops10\n\texit ;;\n    *:TENEX:*:*)\n\techo pdp10-unknown-tenex\n\texit ;;\n    KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)\n\techo pdp10-dec-tops20\n\texit ;;\n    XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)\n\techo pdp10-xkl-tops20\n\texit ;;\n    *:TOPS-20:*:*)\n\techo pdp10-unknown-tops20\n\texit ;;\n    *:ITS:*:*)\n\techo pdp10-unknown-its\n\texit ;;\n    SEI:*:*:SEIUX)\n\techo mips-sei-seiux${UNAME_RELEASE}\n\texit ;;\n    *:DragonFly:*:*)\n\techo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`\n\texit ;;\n    *:*VMS:*:*)\n\tUNAME_MACHINE=`(uname -p) 2>/dev/null`\n\tcase \"${UNAME_MACHINE}\" in\n\t    A*) echo alpha-dec-vms ; exit ;;\n\t    I*) echo ia64-dec-vms ; exit ;;\n\t    V*) echo vax-dec-vms ; exit ;;\n\tesac ;;\n    *:XENIX:*:SysV)\n\techo i386-pc-xenix\n\texit ;;\n    i*86:skyos:*:*)\n\techo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'\n\texit ;;\n    i*86:rdos:*:*)\n\techo ${UNAME_MACHINE}-pc-rdos\n\texit ;;\n    i*86:AROS:*:*)\n\techo ${UNAME_MACHINE}-pc-aros\n\texit ;;\n    x86_64:VMkernel:*:*)\n\techo ${UNAME_MACHINE}-unknown-esx\n\texit ;;\nesac\n\ncat >&2 <<EOF\n$0: unable to guess system type\n\nThis script, last modified $timestamp, has failed to recognize\nthe operating system you are using. It is advised that you\ndownload the most up to date version of the config scripts from\n\n  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD\nand\n  http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD\n\nIf the version you run ($0) is already up to date, please\nsend the following data and any information you think might be\npertinent to <config-patches@gnu.org> in order to provide the needed\ninformation to handle your system.\n\nconfig.guess timestamp = $timestamp\n\nuname -m = `(uname -m) 2>/dev/null || echo unknown`\nuname -r = `(uname -r) 2>/dev/null || echo unknown`\nuname -s = `(uname -s) 2>/dev/null || echo unknown`\nuname -v = `(uname -v) 2>/dev/null || echo unknown`\n\n/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`\n/bin/uname -X     = `(/bin/uname -X) 2>/dev/null`\n\nhostinfo               = `(hostinfo) 2>/dev/null`\n/bin/universe          = `(/bin/universe) 2>/dev/null`\n/usr/bin/arch -k       = `(/usr/bin/arch -k) 2>/dev/null`\n/bin/arch              = `(/bin/arch) 2>/dev/null`\n/usr/bin/oslevel       = `(/usr/bin/oslevel) 2>/dev/null`\n/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`\n\nUNAME_MACHINE = ${UNAME_MACHINE}\nUNAME_RELEASE = ${UNAME_RELEASE}\nUNAME_SYSTEM  = ${UNAME_SYSTEM}\nUNAME_VERSION = ${UNAME_VERSION}\nEOF\n\nexit 1\n\n# Local variables:\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"timestamp='\"\n# time-stamp-format: \"%:y-%02m-%02d\"\n# time-stamp-end: \"'\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/config.sub",
    "content": "#! /bin/sh\n# Configuration validation subroutine script.\n#   Copyright 1992-2014 Free Software Foundation, Inc.\n\ntimestamp='2014-12-03'\n\n# This file is free software; you can redistribute it and/or modify it\n# under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful, but\n# WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n# General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program; if not, see <http://www.gnu.org/licenses/>.\n#\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that\n# program.  This Exception is an additional permission under section 7\n# of the GNU General Public License, version 3 (\"GPLv3\").\n\n\n# Please send patches to <config-patches@gnu.org>.\n#\n# Configuration subroutine to validate and canonicalize a configuration type.\n# Supply the specified configuration type as an argument.\n# If it is invalid, we print an error message on stderr and exit with code 1.\n# Otherwise, we print the canonical config type on stdout and succeed.\n\n# You can get the latest version of this script from:\n# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD\n\n# This file is supposed to be the same for all GNU packages\n# and recognize all the CPU types, system types and aliases\n# that are meaningful with *any* GNU software.\n# Each package is responsible for reporting which valid configurations\n# it does not support.  The user should be able to distinguish\n# a failure to support a valid configuration from a meaningless\n# configuration.\n\n# The goal of this file is to map all the various variations of a given\n# machine specification into a single specification in the form:\n#\tCPU_TYPE-MANUFACTURER-OPERATING_SYSTEM\n# or in some cases, the newer four-part form:\n#\tCPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM\n# It is wrong to echo any other type of specification.\n\nme=`echo \"$0\" | sed -e 's,.*/,,'`\n\nusage=\"\\\nUsage: $0 [OPTION] CPU-MFR-OPSYS\n       $0 [OPTION] ALIAS\n\nCanonicalize a configuration name.\n\nOperation modes:\n  -h, --help         print this help, then exit\n  -t, --time-stamp   print date of last modification, then exit\n  -v, --version      print version number, then exit\n\nReport bugs and patches to <config-patches@gnu.org>.\"\n\nversion=\"\\\nGNU config.sub ($timestamp)\n\nCopyright 1992-2014 Free Software Foundation, Inc.\n\nThis is free software; see the source for copying conditions.  There is NO\nwarranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\"\n\nhelp=\"\nTry \\`$me --help' for more information.\"\n\n# Parse command line\nwhile test $# -gt 0 ; do\n  case $1 in\n    --time-stamp | --time* | -t )\n       echo \"$timestamp\" ; exit ;;\n    --version | -v )\n       echo \"$version\" ; exit ;;\n    --help | --h* | -h )\n       echo \"$usage\"; exit ;;\n    -- )     # Stop option processing\n       shift; break ;;\n    - )\t# Use stdin as input.\n       break ;;\n    -* )\n       echo \"$me: invalid option $1$help\"\n       exit 1 ;;\n\n    *local*)\n       # First pass through any local machine types.\n       echo $1\n       exit ;;\n\n    * )\n       break ;;\n  esac\ndone\n\ncase $# in\n 0) echo \"$me: missing argument$help\" >&2\n    exit 1;;\n 1) ;;\n *) echo \"$me: too many arguments$help\" >&2\n    exit 1;;\nesac\n\n# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).\n# Here we must recognize all the valid KERNEL-OS combinations.\nmaybe_os=`echo $1 | sed 's/^\\(.*\\)-\\([^-]*-[^-]*\\)$/\\2/'`\ncase $maybe_os in\n  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \\\n  linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \\\n  knetbsd*-gnu* | netbsd*-gnu* | \\\n  kopensolaris*-gnu* | \\\n  storm-chaos* | os2-emx* | rtmk-nova*)\n    os=-$maybe_os\n    basic_machine=`echo $1 | sed 's/^\\(.*\\)-\\([^-]*-[^-]*\\)$/\\1/'`\n    ;;\n  android-linux)\n    os=-linux-android\n    basic_machine=`echo $1 | sed 's/^\\(.*\\)-\\([^-]*-[^-]*\\)$/\\1/'`-unknown\n    ;;\n  *)\n    basic_machine=`echo $1 | sed 's/-[^-]*$//'`\n    if [ $basic_machine != $1 ]\n    then os=`echo $1 | sed 's/.*-/-/'`\n    else os=; fi\n    ;;\nesac\n\n### Let's recognize common machines as not being operating systems so\n### that things like config.sub decstation-3100 work.  We also\n### recognize some manufacturers as not being operating systems, so we\n### can provide default operating systems below.\ncase $os in\n\t-sun*os*)\n\t\t# Prevent following clause from handling this invalid input.\n\t\t;;\n\t-dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \\\n\t-att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \\\n\t-unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \\\n\t-convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\\\n\t-c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \\\n\t-harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \\\n\t-apple | -axis | -knuth | -cray | -microblaze*)\n\t\tos=\n\t\tbasic_machine=$1\n\t\t;;\n\t-bluegene*)\n\t\tos=-cnk\n\t\t;;\n\t-sim | -cisco | -oki | -wec | -winbond)\n\t\tos=\n\t\tbasic_machine=$1\n\t\t;;\n\t-scout)\n\t\t;;\n\t-wrs)\n\t\tos=-vxworks\n\t\tbasic_machine=$1\n\t\t;;\n\t-chorusos*)\n\t\tos=-chorusos\n\t\tbasic_machine=$1\n\t\t;;\n\t-chorusrdb)\n\t\tos=-chorusrdb\n\t\tbasic_machine=$1\n\t\t;;\n\t-hiux*)\n\t\tos=-hiuxwe2\n\t\t;;\n\t-sco6)\n\t\tos=-sco5v6\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco5)\n\t\tos=-sco3.2v5\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco4)\n\t\tos=-sco3.2v4\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco3.2.[4-9]*)\n\t\tos=`echo $os | sed -e 's/sco3.2./sco3.2v/'`\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco3.2v[4-9]*)\n\t\t# Don't forget version if it is 3.2v4 or newer.\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco5v6*)\n\t\t# Don't forget version if it is 3.2v4 or newer.\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-sco*)\n\t\tos=-sco3.2v2\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-udk*)\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-isc)\n\t\tos=-isc2.2\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-clix*)\n\t\tbasic_machine=clipper-intergraph\n\t\t;;\n\t-isc*)\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`\n\t\t;;\n\t-lynx*178)\n\t\tos=-lynxos178\n\t\t;;\n\t-lynx*5)\n\t\tos=-lynxos5\n\t\t;;\n\t-lynx*)\n\t\tos=-lynxos\n\t\t;;\n\t-ptx*)\n\t\tbasic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`\n\t\t;;\n\t-windowsnt*)\n\t\tos=`echo $os | sed -e 's/windowsnt/winnt/'`\n\t\t;;\n\t-psos*)\n\t\tos=-psos\n\t\t;;\n\t-mint | -mint[0-9]*)\n\t\tbasic_machine=m68k-atari\n\t\tos=-mint\n\t\t;;\nesac\n\n# Decode aliases for certain CPU-COMPANY combinations.\ncase $basic_machine in\n\t# Recognize the basic CPU types without company name.\n\t# Some are omitted here because they have special meanings below.\n\t1750a | 580 \\\n\t| a29k \\\n\t| aarch64 | aarch64_be \\\n\t| alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \\\n\t| alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \\\n\t| am33_2.0 \\\n\t| arc | arceb \\\n\t| arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \\\n\t| avr | avr32 \\\n\t| be32 | be64 \\\n\t| bfin \\\n\t| c4x | c8051 | clipper \\\n\t| d10v | d30v | dlx | dsp16xx \\\n\t| epiphany \\\n\t| fido | fr30 | frv \\\n\t| h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \\\n\t| hexagon \\\n\t| i370 | i860 | i960 | ia64 \\\n\t| ip2k | iq2000 \\\n\t| k1om \\\n\t| le32 | le64 \\\n\t| lm32 \\\n\t| m32c | m32r | m32rle | m68000 | m68k | m88k \\\n\t| maxq | mb | microblaze | microblazeel | mcore | mep | metag \\\n\t| mips | mipsbe | mipseb | mipsel | mipsle \\\n\t| mips16 \\\n\t| mips64 | mips64el \\\n\t| mips64octeon | mips64octeonel \\\n\t| mips64orion | mips64orionel \\\n\t| mips64r5900 | mips64r5900el \\\n\t| mips64vr | mips64vrel \\\n\t| mips64vr4100 | mips64vr4100el \\\n\t| mips64vr4300 | mips64vr4300el \\\n\t| mips64vr5000 | mips64vr5000el \\\n\t| mips64vr5900 | mips64vr5900el \\\n\t| mipsisa32 | mipsisa32el \\\n\t| mipsisa32r2 | mipsisa32r2el \\\n\t| mipsisa32r6 | mipsisa32r6el \\\n\t| mipsisa64 | mipsisa64el \\\n\t| mipsisa64r2 | mipsisa64r2el \\\n\t| mipsisa64r6 | mipsisa64r6el \\\n\t| mipsisa64sb1 | mipsisa64sb1el \\\n\t| mipsisa64sr71k | mipsisa64sr71kel \\\n\t| mipsr5900 | mipsr5900el \\\n\t| mipstx39 | mipstx39el \\\n\t| mn10200 | mn10300 \\\n\t| moxie \\\n\t| mt \\\n\t| msp430 \\\n\t| nds32 | nds32le | nds32be \\\n\t| nios | nios2 | nios2eb | nios2el \\\n\t| ns16k | ns32k \\\n\t| open8 | or1k | or1knd | or32 \\\n\t| pdp10 | pdp11 | pj | pjl \\\n\t| powerpc | powerpc64 | powerpc64le | powerpcle \\\n\t| pyramid \\\n\t| riscv32 | riscv64 \\\n\t| rl78 | rx \\\n\t| score \\\n\t| sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \\\n\t| sh64 | sh64le \\\n\t| sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \\\n\t| sparcv8 | sparcv9 | sparcv9b | sparcv9v \\\n\t| spu \\\n\t| tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \\\n\t| ubicom32 \\\n\t| v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \\\n\t| visium \\\n\t| we32k \\\n\t| x86 | xc16x | xstormy16 | xtensa \\\n\t| z8k | z80)\n\t\tbasic_machine=$basic_machine-unknown\n\t\t;;\n\tc54x)\n\t\tbasic_machine=tic54x-unknown\n\t\t;;\n\tc55x)\n\t\tbasic_machine=tic55x-unknown\n\t\t;;\n\tc6x)\n\t\tbasic_machine=tic6x-unknown\n\t\t;;\n\tleon|leon[3-9])\n\t\tbasic_machine=sparc-$basic_machine\n\t\t;;\n\tm6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)\n\t\tbasic_machine=$basic_machine-unknown\n\t\tos=-none\n\t\t;;\n\tm88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)\n\t\t;;\n\tms1)\n\t\tbasic_machine=mt-unknown\n\t\t;;\n\n\tstrongarm | thumb | xscale)\n\t\tbasic_machine=arm-unknown\n\t\t;;\n\txgate)\n\t\tbasic_machine=$basic_machine-unknown\n\t\tos=-none\n\t\t;;\n\txscaleeb)\n\t\tbasic_machine=armeb-unknown\n\t\t;;\n\n\txscaleel)\n\t\tbasic_machine=armel-unknown\n\t\t;;\n\n\t# We use `pc' rather than `unknown'\n\t# because (1) that's what they normally are, and\n\t# (2) the word \"unknown\" tends to confuse beginning users.\n\ti*86 | x86_64)\n\t  basic_machine=$basic_machine-pc\n\t  ;;\n\t# Object if more than one company name word.\n\t*-*-*)\n\t\techo Invalid configuration \\`$1\\': machine \\`$basic_machine\\' not recognized 1>&2\n\t\texit 1\n\t\t;;\n\t# Recognize the basic CPU types with company name.\n\t580-* \\\n\t| a29k-* \\\n\t| aarch64-* | aarch64_be-* \\\n\t| alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \\\n\t| alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \\\n\t| alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \\\n\t| arm-*  | armbe-* | armle-* | armeb-* | armv*-* \\\n\t| avr-* | avr32-* \\\n\t| be32-* | be64-* \\\n\t| bfin-* | bs2000-* \\\n\t| c[123]* | c30-* | [cjt]90-* | c4x-* \\\n\t| c8051-* | clipper-* | craynv-* | cydra-* \\\n\t| d10v-* | d30v-* | dlx-* \\\n\t| elxsi-* \\\n\t| f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \\\n\t| h8300-* | h8500-* \\\n\t| hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \\\n\t| hexagon-* \\\n\t| i*86-* | i860-* | i960-* | ia64-* \\\n\t| ip2k-* | iq2000-* \\\n\t| k1om-* \\\n\t| le32-* | le64-* \\\n\t| lm32-* \\\n\t| m32c-* | m32r-* | m32rle-* \\\n\t| m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \\\n\t| m88110-* | m88k-* | maxq-* | mcore-* | metag-* \\\n\t| microblaze-* | microblazeel-* \\\n\t| mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \\\n\t| mips16-* \\\n\t| mips64-* | mips64el-* \\\n\t| mips64octeon-* | mips64octeonel-* \\\n\t| mips64orion-* | mips64orionel-* \\\n\t| mips64r5900-* | mips64r5900el-* \\\n\t| mips64vr-* | mips64vrel-* \\\n\t| mips64vr4100-* | mips64vr4100el-* \\\n\t| mips64vr4300-* | mips64vr4300el-* \\\n\t| mips64vr5000-* | mips64vr5000el-* \\\n\t| mips64vr5900-* | mips64vr5900el-* \\\n\t| mipsisa32-* | mipsisa32el-* \\\n\t| mipsisa32r2-* | mipsisa32r2el-* \\\n\t| mipsisa32r6-* | mipsisa32r6el-* \\\n\t| mipsisa64-* | mipsisa64el-* \\\n\t| mipsisa64r2-* | mipsisa64r2el-* \\\n\t| mipsisa64r6-* | mipsisa64r6el-* \\\n\t| mipsisa64sb1-* | mipsisa64sb1el-* \\\n\t| mipsisa64sr71k-* | mipsisa64sr71kel-* \\\n\t| mipsr5900-* | mipsr5900el-* \\\n\t| mipstx39-* | mipstx39el-* \\\n\t| mmix-* \\\n\t| mt-* \\\n\t| msp430-* \\\n\t| nds32-* | nds32le-* | nds32be-* \\\n\t| nios-* | nios2-* | nios2eb-* | nios2el-* \\\n\t| none-* | np1-* | ns16k-* | ns32k-* \\\n\t| open8-* \\\n\t| or1k*-* \\\n\t| orion-* \\\n\t| pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \\\n\t| powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \\\n\t| pyramid-* \\\n\t| rl78-* | romp-* | rs6000-* | rx-* \\\n\t| sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \\\n\t| shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \\\n\t| sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \\\n\t| sparclite-* \\\n\t| sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \\\n\t| tahoe-* \\\n\t| tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \\\n\t| tile*-* \\\n\t| tron-* \\\n\t| ubicom32-* \\\n\t| v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \\\n\t| vax-* \\\n\t| visium-* \\\n\t| we32k-* \\\n\t| x86-* | x86_64-* | xc16x-* | xps100-* \\\n\t| xstormy16-* | xtensa*-* \\\n\t| ymp-* \\\n\t| z8k-* | z80-*)\n\t\t;;\n\t# Recognize the basic CPU types without company name, with glob match.\n\txtensa*)\n\t\tbasic_machine=$basic_machine-unknown\n\t\t;;\n\t# Recognize the various machine names and aliases which stand\n\t# for a CPU type and a company and sometimes even an OS.\n\t386bsd)\n\t\tbasic_machine=i386-unknown\n\t\tos=-bsd\n\t\t;;\n\t3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)\n\t\tbasic_machine=m68000-att\n\t\t;;\n\t3b*)\n\t\tbasic_machine=we32k-att\n\t\t;;\n\ta29khif)\n\t\tbasic_machine=a29k-amd\n\t\tos=-udi\n\t\t;;\n\tabacus)\n\t\tbasic_machine=abacus-unknown\n\t\t;;\n\tadobe68k)\n\t\tbasic_machine=m68010-adobe\n\t\tos=-scout\n\t\t;;\n\talliant | fx80)\n\t\tbasic_machine=fx80-alliant\n\t\t;;\n\taltos | altos3068)\n\t\tbasic_machine=m68k-altos\n\t\t;;\n\tam29k)\n\t\tbasic_machine=a29k-none\n\t\tos=-bsd\n\t\t;;\n\tamd64)\n\t\tbasic_machine=x86_64-pc\n\t\t;;\n\tamd64-*)\n\t\tbasic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tamdahl)\n\t\tbasic_machine=580-amdahl\n\t\tos=-sysv\n\t\t;;\n\tamiga | amiga-*)\n\t\tbasic_machine=m68k-unknown\n\t\t;;\n\tamigaos | amigados)\n\t\tbasic_machine=m68k-unknown\n\t\tos=-amigaos\n\t\t;;\n\tamigaunix | amix)\n\t\tbasic_machine=m68k-unknown\n\t\tos=-sysv4\n\t\t;;\n\tapollo68)\n\t\tbasic_machine=m68k-apollo\n\t\tos=-sysv\n\t\t;;\n\tapollo68bsd)\n\t\tbasic_machine=m68k-apollo\n\t\tos=-bsd\n\t\t;;\n\taros)\n\t\tbasic_machine=i386-pc\n\t\tos=-aros\n\t\t;;\n\taux)\n\t\tbasic_machine=m68k-apple\n\t\tos=-aux\n\t\t;;\n\tbalance)\n\t\tbasic_machine=ns32k-sequent\n\t\tos=-dynix\n\t\t;;\n\tblackfin)\n\t\tbasic_machine=bfin-unknown\n\t\tos=-linux\n\t\t;;\n\tblackfin-*)\n\t\tbasic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\tos=-linux\n\t\t;;\n\tbluegene*)\n\t\tbasic_machine=powerpc-ibm\n\t\tos=-cnk\n\t\t;;\n\tc54x-*)\n\t\tbasic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tc55x-*)\n\t\tbasic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tc6x-*)\n\t\tbasic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tc90)\n\t\tbasic_machine=c90-cray\n\t\tos=-unicos\n\t\t;;\n\tcegcc)\n\t\tbasic_machine=arm-unknown\n\t\tos=-cegcc\n\t\t;;\n\tconvex-c1)\n\t\tbasic_machine=c1-convex\n\t\tos=-bsd\n\t\t;;\n\tconvex-c2)\n\t\tbasic_machine=c2-convex\n\t\tos=-bsd\n\t\t;;\n\tconvex-c32)\n\t\tbasic_machine=c32-convex\n\t\tos=-bsd\n\t\t;;\n\tconvex-c34)\n\t\tbasic_machine=c34-convex\n\t\tos=-bsd\n\t\t;;\n\tconvex-c38)\n\t\tbasic_machine=c38-convex\n\t\tos=-bsd\n\t\t;;\n\tcray | j90)\n\t\tbasic_machine=j90-cray\n\t\tos=-unicos\n\t\t;;\n\tcraynv)\n\t\tbasic_machine=craynv-cray\n\t\tos=-unicosmp\n\t\t;;\n\tcr16 | cr16-*)\n\t\tbasic_machine=cr16-unknown\n\t\tos=-elf\n\t\t;;\n\tcrds | unos)\n\t\tbasic_machine=m68k-crds\n\t\t;;\n\tcrisv32 | crisv32-* | etraxfs*)\n\t\tbasic_machine=crisv32-axis\n\t\t;;\n\tcris | cris-* | etrax*)\n\t\tbasic_machine=cris-axis\n\t\t;;\n\tcrx)\n\t\tbasic_machine=crx-unknown\n\t\tos=-elf\n\t\t;;\n\tda30 | da30-*)\n\t\tbasic_machine=m68k-da30\n\t\t;;\n\tdecstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)\n\t\tbasic_machine=mips-dec\n\t\t;;\n\tdecsystem10* | dec10*)\n\t\tbasic_machine=pdp10-dec\n\t\tos=-tops10\n\t\t;;\n\tdecsystem20* | dec20*)\n\t\tbasic_machine=pdp10-dec\n\t\tos=-tops20\n\t\t;;\n\tdelta | 3300 | motorola-3300 | motorola-delta \\\n\t      | 3300-motorola | delta-motorola)\n\t\tbasic_machine=m68k-motorola\n\t\t;;\n\tdelta88)\n\t\tbasic_machine=m88k-motorola\n\t\tos=-sysv3\n\t\t;;\n\tdicos)\n\t\tbasic_machine=i686-pc\n\t\tos=-dicos\n\t\t;;\n\tdjgpp)\n\t\tbasic_machine=i586-pc\n\t\tos=-msdosdjgpp\n\t\t;;\n\tdpx20 | dpx20-*)\n\t\tbasic_machine=rs6000-bull\n\t\tos=-bosx\n\t\t;;\n\tdpx2* | dpx2*-bull)\n\t\tbasic_machine=m68k-bull\n\t\tos=-sysv3\n\t\t;;\n\tebmon29k)\n\t\tbasic_machine=a29k-amd\n\t\tos=-ebmon\n\t\t;;\n\telxsi)\n\t\tbasic_machine=elxsi-elxsi\n\t\tos=-bsd\n\t\t;;\n\tencore | umax | mmax)\n\t\tbasic_machine=ns32k-encore\n\t\t;;\n\tes1800 | OSE68k | ose68k | ose | OSE)\n\t\tbasic_machine=m68k-ericsson\n\t\tos=-ose\n\t\t;;\n\tfx2800)\n\t\tbasic_machine=i860-alliant\n\t\t;;\n\tgenix)\n\t\tbasic_machine=ns32k-ns\n\t\t;;\n\tgmicro)\n\t\tbasic_machine=tron-gmicro\n\t\tos=-sysv\n\t\t;;\n\tgo32)\n\t\tbasic_machine=i386-pc\n\t\tos=-go32\n\t\t;;\n\th3050r* | hiux*)\n\t\tbasic_machine=hppa1.1-hitachi\n\t\tos=-hiuxwe2\n\t\t;;\n\th8300hms)\n\t\tbasic_machine=h8300-hitachi\n\t\tos=-hms\n\t\t;;\n\th8300xray)\n\t\tbasic_machine=h8300-hitachi\n\t\tos=-xray\n\t\t;;\n\th8500hms)\n\t\tbasic_machine=h8500-hitachi\n\t\tos=-hms\n\t\t;;\n\tharris)\n\t\tbasic_machine=m88k-harris\n\t\tos=-sysv3\n\t\t;;\n\thp300-*)\n\t\tbasic_machine=m68k-hp\n\t\t;;\n\thp300bsd)\n\t\tbasic_machine=m68k-hp\n\t\tos=-bsd\n\t\t;;\n\thp300hpux)\n\t\tbasic_machine=m68k-hp\n\t\tos=-hpux\n\t\t;;\n\thp3k9[0-9][0-9] | hp9[0-9][0-9])\n\t\tbasic_machine=hppa1.0-hp\n\t\t;;\n\thp9k2[0-9][0-9] | hp9k31[0-9])\n\t\tbasic_machine=m68000-hp\n\t\t;;\n\thp9k3[2-9][0-9])\n\t\tbasic_machine=m68k-hp\n\t\t;;\n\thp9k6[0-9][0-9] | hp6[0-9][0-9])\n\t\tbasic_machine=hppa1.0-hp\n\t\t;;\n\thp9k7[0-79][0-9] | hp7[0-79][0-9])\n\t\tbasic_machine=hppa1.1-hp\n\t\t;;\n\thp9k78[0-9] | hp78[0-9])\n\t\t# FIXME: really hppa2.0-hp\n\t\tbasic_machine=hppa1.1-hp\n\t\t;;\n\thp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)\n\t\t# FIXME: really hppa2.0-hp\n\t\tbasic_machine=hppa1.1-hp\n\t\t;;\n\thp9k8[0-9][13679] | hp8[0-9][13679])\n\t\tbasic_machine=hppa1.1-hp\n\t\t;;\n\thp9k8[0-9][0-9] | hp8[0-9][0-9])\n\t\tbasic_machine=hppa1.0-hp\n\t\t;;\n\thppa-next)\n\t\tos=-nextstep3\n\t\t;;\n\thppaosf)\n\t\tbasic_machine=hppa1.1-hp\n\t\tos=-osf\n\t\t;;\n\thppro)\n\t\tbasic_machine=hppa1.1-hp\n\t\tos=-proelf\n\t\t;;\n\ti370-ibm* | ibm*)\n\t\tbasic_machine=i370-ibm\n\t\t;;\n\ti*86v32)\n\t\tbasic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`\n\t\tos=-sysv32\n\t\t;;\n\ti*86v4*)\n\t\tbasic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`\n\t\tos=-sysv4\n\t\t;;\n\ti*86v)\n\t\tbasic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`\n\t\tos=-sysv\n\t\t;;\n\ti*86sol2)\n\t\tbasic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`\n\t\tos=-solaris2\n\t\t;;\n\ti386mach)\n\t\tbasic_machine=i386-mach\n\t\tos=-mach\n\t\t;;\n\ti386-vsta | vsta)\n\t\tbasic_machine=i386-unknown\n\t\tos=-vsta\n\t\t;;\n\tiris | iris4d)\n\t\tbasic_machine=mips-sgi\n\t\tcase $os in\n\t\t    -irix*)\n\t\t\t;;\n\t\t    *)\n\t\t\tos=-irix4\n\t\t\t;;\n\t\tesac\n\t\t;;\n\tisi68 | isi)\n\t\tbasic_machine=m68k-isi\n\t\tos=-sysv\n\t\t;;\n\tleon-*|leon[3-9]-*)\n\t\tbasic_machine=sparc-`echo $basic_machine | sed 's/-.*//'`\n\t\t;;\n\tm68knommu)\n\t\tbasic_machine=m68k-unknown\n\t\tos=-linux\n\t\t;;\n\tm68knommu-*)\n\t\tbasic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\tos=-linux\n\t\t;;\n\tm88k-omron*)\n\t\tbasic_machine=m88k-omron\n\t\t;;\n\tmagnum | m3230)\n\t\tbasic_machine=mips-mips\n\t\tos=-sysv\n\t\t;;\n\tmerlin)\n\t\tbasic_machine=ns32k-utek\n\t\tos=-sysv\n\t\t;;\n\tmicroblaze*)\n\t\tbasic_machine=microblaze-xilinx\n\t\t;;\n\tmingw64)\n\t\tbasic_machine=x86_64-pc\n\t\tos=-mingw64\n\t\t;;\n\tmingw32)\n\t\tbasic_machine=i686-pc\n\t\tos=-mingw32\n\t\t;;\n\tmingw32ce)\n\t\tbasic_machine=arm-unknown\n\t\tos=-mingw32ce\n\t\t;;\n\tminiframe)\n\t\tbasic_machine=m68000-convergent\n\t\t;;\n\t*mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)\n\t\tbasic_machine=m68k-atari\n\t\tos=-mint\n\t\t;;\n\tmips3*-*)\n\t\tbasic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`\n\t\t;;\n\tmips3*)\n\t\tbasic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown\n\t\t;;\n\tmonitor)\n\t\tbasic_machine=m68k-rom68k\n\t\tos=-coff\n\t\t;;\n\tmorphos)\n\t\tbasic_machine=powerpc-unknown\n\t\tos=-morphos\n\t\t;;\n\tmoxiebox)\n\t\tbasic_machine=moxie-unknown\n\t\tos=-moxiebox\n\t\t;;\n\tmsdos)\n\t\tbasic_machine=i386-pc\n\t\tos=-msdos\n\t\t;;\n\tms1-*)\n\t\tbasic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`\n\t\t;;\n\tmsys)\n\t\tbasic_machine=i686-pc\n\t\tos=-msys\n\t\t;;\n\tmvs)\n\t\tbasic_machine=i370-ibm\n\t\tos=-mvs\n\t\t;;\n\tnacl)\n\t\tbasic_machine=le32-unknown\n\t\tos=-nacl\n\t\t;;\n\tncr3000)\n\t\tbasic_machine=i486-ncr\n\t\tos=-sysv4\n\t\t;;\n\tnetbsd386)\n\t\tbasic_machine=i386-unknown\n\t\tos=-netbsd\n\t\t;;\n\tnetwinder)\n\t\tbasic_machine=armv4l-rebel\n\t\tos=-linux\n\t\t;;\n\tnews | news700 | news800 | news900)\n\t\tbasic_machine=m68k-sony\n\t\tos=-newsos\n\t\t;;\n\tnews1000)\n\t\tbasic_machine=m68030-sony\n\t\tos=-newsos\n\t\t;;\n\tnews-3600 | risc-news)\n\t\tbasic_machine=mips-sony\n\t\tos=-newsos\n\t\t;;\n\tnecv70)\n\t\tbasic_machine=v70-nec\n\t\tos=-sysv\n\t\t;;\n\tnext | m*-next )\n\t\tbasic_machine=m68k-next\n\t\tcase $os in\n\t\t    -nextstep* )\n\t\t\t;;\n\t\t    -ns2*)\n\t\t      os=-nextstep2\n\t\t\t;;\n\t\t    *)\n\t\t      os=-nextstep3\n\t\t\t;;\n\t\tesac\n\t\t;;\n\tnh3000)\n\t\tbasic_machine=m68k-harris\n\t\tos=-cxux\n\t\t;;\n\tnh[45]000)\n\t\tbasic_machine=m88k-harris\n\t\tos=-cxux\n\t\t;;\n\tnindy960)\n\t\tbasic_machine=i960-intel\n\t\tos=-nindy\n\t\t;;\n\tmon960)\n\t\tbasic_machine=i960-intel\n\t\tos=-mon960\n\t\t;;\n\tnonstopux)\n\t\tbasic_machine=mips-compaq\n\t\tos=-nonstopux\n\t\t;;\n\tnp1)\n\t\tbasic_machine=np1-gould\n\t\t;;\n\tneo-tandem)\n\t\tbasic_machine=neo-tandem\n\t\t;;\n\tnse-tandem)\n\t\tbasic_machine=nse-tandem\n\t\t;;\n\tnsr-tandem)\n\t\tbasic_machine=nsr-tandem\n\t\t;;\n\top50n-* | op60c-*)\n\t\tbasic_machine=hppa1.1-oki\n\t\tos=-proelf\n\t\t;;\n\topenrisc | openrisc-*)\n\t\tbasic_machine=or32-unknown\n\t\t;;\n\tos400)\n\t\tbasic_machine=powerpc-ibm\n\t\tos=-os400\n\t\t;;\n\tOSE68000 | ose68000)\n\t\tbasic_machine=m68000-ericsson\n\t\tos=-ose\n\t\t;;\n\tos68k)\n\t\tbasic_machine=m68k-none\n\t\tos=-os68k\n\t\t;;\n\tpa-hitachi)\n\t\tbasic_machine=hppa1.1-hitachi\n\t\tos=-hiuxwe2\n\t\t;;\n\tparagon)\n\t\tbasic_machine=i860-intel\n\t\tos=-osf\n\t\t;;\n\tparisc)\n\t\tbasic_machine=hppa-unknown\n\t\tos=-linux\n\t\t;;\n\tparisc-*)\n\t\tbasic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\tos=-linux\n\t\t;;\n\tpbd)\n\t\tbasic_machine=sparc-tti\n\t\t;;\n\tpbb)\n\t\tbasic_machine=m68k-tti\n\t\t;;\n\tpc532 | pc532-*)\n\t\tbasic_machine=ns32k-pc532\n\t\t;;\n\tpc98)\n\t\tbasic_machine=i386-pc\n\t\t;;\n\tpc98-*)\n\t\tbasic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tpentium | p5 | k5 | k6 | nexgen | viac3)\n\t\tbasic_machine=i586-pc\n\t\t;;\n\tpentiumpro | p6 | 6x86 | athlon | athlon_*)\n\t\tbasic_machine=i686-pc\n\t\t;;\n\tpentiumii | pentium2 | pentiumiii | pentium3)\n\t\tbasic_machine=i686-pc\n\t\t;;\n\tpentium4)\n\t\tbasic_machine=i786-pc\n\t\t;;\n\tpentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)\n\t\tbasic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tpentiumpro-* | p6-* | 6x86-* | athlon-*)\n\t\tbasic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tpentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)\n\t\tbasic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tpentium4-*)\n\t\tbasic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tpn)\n\t\tbasic_machine=pn-gould\n\t\t;;\n\tpower)\tbasic_machine=power-ibm\n\t\t;;\n\tppc | ppcbe)\tbasic_machine=powerpc-unknown\n\t\t;;\n\tppc-* | ppcbe-*)\n\t\tbasic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tppcle | powerpclittle | ppc-le | powerpc-little)\n\t\tbasic_machine=powerpcle-unknown\n\t\t;;\n\tppcle-* | powerpclittle-*)\n\t\tbasic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tppc64)\tbasic_machine=powerpc64-unknown\n\t\t;;\n\tppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tppc64le | powerpc64little | ppc64-le | powerpc64-little)\n\t\tbasic_machine=powerpc64le-unknown\n\t\t;;\n\tppc64le-* | powerpc64little-*)\n\t\tbasic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tps2)\n\t\tbasic_machine=i386-ibm\n\t\t;;\n\tpw32)\n\t\tbasic_machine=i586-unknown\n\t\tos=-pw32\n\t\t;;\n\trdos | rdos64)\n\t\tbasic_machine=x86_64-pc\n\t\tos=-rdos\n\t\t;;\n\trdos32)\n\t\tbasic_machine=i386-pc\n\t\tos=-rdos\n\t\t;;\n\trom68k)\n\t\tbasic_machine=m68k-rom68k\n\t\tos=-coff\n\t\t;;\n\trm[46]00)\n\t\tbasic_machine=mips-siemens\n\t\t;;\n\trtpc | rtpc-*)\n\t\tbasic_machine=romp-ibm\n\t\t;;\n\ts390 | s390-*)\n\t\tbasic_machine=s390-ibm\n\t\t;;\n\ts390x | s390x-*)\n\t\tbasic_machine=s390x-ibm\n\t\t;;\n\tsa29200)\n\t\tbasic_machine=a29k-amd\n\t\tos=-udi\n\t\t;;\n\tsb1)\n\t\tbasic_machine=mipsisa64sb1-unknown\n\t\t;;\n\tsb1el)\n\t\tbasic_machine=mipsisa64sb1el-unknown\n\t\t;;\n\tsde)\n\t\tbasic_machine=mipsisa32-sde\n\t\tos=-elf\n\t\t;;\n\tsei)\n\t\tbasic_machine=mips-sei\n\t\tos=-seiux\n\t\t;;\n\tsequent)\n\t\tbasic_machine=i386-sequent\n\t\t;;\n\tsh)\n\t\tbasic_machine=sh-hitachi\n\t\tos=-hms\n\t\t;;\n\tsh5el)\n\t\tbasic_machine=sh5le-unknown\n\t\t;;\n\tsh64)\n\t\tbasic_machine=sh64-unknown\n\t\t;;\n\tsparclite-wrs | simso-wrs)\n\t\tbasic_machine=sparclite-wrs\n\t\tos=-vxworks\n\t\t;;\n\tsps7)\n\t\tbasic_machine=m68k-bull\n\t\tos=-sysv2\n\t\t;;\n\tspur)\n\t\tbasic_machine=spur-unknown\n\t\t;;\n\tst2000)\n\t\tbasic_machine=m68k-tandem\n\t\t;;\n\tstratus)\n\t\tbasic_machine=i860-stratus\n\t\tos=-sysv4\n\t\t;;\n\tstrongarm-* | thumb-*)\n\t\tbasic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`\n\t\t;;\n\tsun2)\n\t\tbasic_machine=m68000-sun\n\t\t;;\n\tsun2os3)\n\t\tbasic_machine=m68000-sun\n\t\tos=-sunos3\n\t\t;;\n\tsun2os4)\n\t\tbasic_machine=m68000-sun\n\t\tos=-sunos4\n\t\t;;\n\tsun3os3)\n\t\tbasic_machine=m68k-sun\n\t\tos=-sunos3\n\t\t;;\n\tsun3os4)\n\t\tbasic_machine=m68k-sun\n\t\tos=-sunos4\n\t\t;;\n\tsun4os3)\n\t\tbasic_machine=sparc-sun\n\t\tos=-sunos3\n\t\t;;\n\tsun4os4)\n\t\tbasic_machine=sparc-sun\n\t\tos=-sunos4\n\t\t;;\n\tsun4sol2)\n\t\tbasic_machine=sparc-sun\n\t\tos=-solaris2\n\t\t;;\n\tsun3 | sun3-*)\n\t\tbasic_machine=m68k-sun\n\t\t;;\n\tsun4)\n\t\tbasic_machine=sparc-sun\n\t\t;;\n\tsun386 | sun386i | roadrunner)\n\t\tbasic_machine=i386-sun\n\t\t;;\n\tsv1)\n\t\tbasic_machine=sv1-cray\n\t\tos=-unicos\n\t\t;;\n\tsymmetry)\n\t\tbasic_machine=i386-sequent\n\t\tos=-dynix\n\t\t;;\n\tt3e)\n\t\tbasic_machine=alphaev5-cray\n\t\tos=-unicos\n\t\t;;\n\tt90)\n\t\tbasic_machine=t90-cray\n\t\tos=-unicos\n\t\t;;\n\ttile*)\n\t\tbasic_machine=$basic_machine-unknown\n\t\tos=-linux-gnu\n\t\t;;\n\ttx39)\n\t\tbasic_machine=mipstx39-unknown\n\t\t;;\n\ttx39el)\n\t\tbasic_machine=mipstx39el-unknown\n\t\t;;\n\ttoad1)\n\t\tbasic_machine=pdp10-xkl\n\t\tos=-tops20\n\t\t;;\n\ttower | tower-32)\n\t\tbasic_machine=m68k-ncr\n\t\t;;\n\ttpf)\n\t\tbasic_machine=s390x-ibm\n\t\tos=-tpf\n\t\t;;\n\tudi29k)\n\t\tbasic_machine=a29k-amd\n\t\tos=-udi\n\t\t;;\n\tultra3)\n\t\tbasic_machine=a29k-nyu\n\t\tos=-sym1\n\t\t;;\n\tv810 | necv810)\n\t\tbasic_machine=v810-nec\n\t\tos=-none\n\t\t;;\n\tvaxv)\n\t\tbasic_machine=vax-dec\n\t\tos=-sysv\n\t\t;;\n\tvms)\n\t\tbasic_machine=vax-dec\n\t\tos=-vms\n\t\t;;\n\tvpp*|vx|vx-*)\n\t\tbasic_machine=f301-fujitsu\n\t\t;;\n\tvxworks960)\n\t\tbasic_machine=i960-wrs\n\t\tos=-vxworks\n\t\t;;\n\tvxworks68)\n\t\tbasic_machine=m68k-wrs\n\t\tos=-vxworks\n\t\t;;\n\tvxworks29k)\n\t\tbasic_machine=a29k-wrs\n\t\tos=-vxworks\n\t\t;;\n\tw65*)\n\t\tbasic_machine=w65-wdc\n\t\tos=-none\n\t\t;;\n\tw89k-*)\n\t\tbasic_machine=hppa1.1-winbond\n\t\tos=-proelf\n\t\t;;\n\txbox)\n\t\tbasic_machine=i686-pc\n\t\tos=-mingw32\n\t\t;;\n\txps | xps100)\n\t\tbasic_machine=xps100-honeywell\n\t\t;;\n\txscale-* | xscalee[bl]-*)\n\t\tbasic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`\n\t\t;;\n\tymp)\n\t\tbasic_machine=ymp-cray\n\t\tos=-unicos\n\t\t;;\n\tz8k-*-coff)\n\t\tbasic_machine=z8k-unknown\n\t\tos=-sim\n\t\t;;\n\tz80-*-coff)\n\t\tbasic_machine=z80-unknown\n\t\tos=-sim\n\t\t;;\n\tnone)\n\t\tbasic_machine=none-none\n\t\tos=-none\n\t\t;;\n\n# Here we handle the default manufacturer of certain CPU types.  It is in\n# some cases the only manufacturer, in others, it is the most popular.\n\tw89k)\n\t\tbasic_machine=hppa1.1-winbond\n\t\t;;\n\top50n)\n\t\tbasic_machine=hppa1.1-oki\n\t\t;;\n\top60c)\n\t\tbasic_machine=hppa1.1-oki\n\t\t;;\n\tromp)\n\t\tbasic_machine=romp-ibm\n\t\t;;\n\tmmix)\n\t\tbasic_machine=mmix-knuth\n\t\t;;\n\trs6000)\n\t\tbasic_machine=rs6000-ibm\n\t\t;;\n\tvax)\n\t\tbasic_machine=vax-dec\n\t\t;;\n\tpdp10)\n\t\t# there are many clones, so DEC is not a safe bet\n\t\tbasic_machine=pdp10-unknown\n\t\t;;\n\tpdp11)\n\t\tbasic_machine=pdp11-dec\n\t\t;;\n\twe32k)\n\t\tbasic_machine=we32k-att\n\t\t;;\n\tsh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)\n\t\tbasic_machine=sh-unknown\n\t\t;;\n\tsparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)\n\t\tbasic_machine=sparc-sun\n\t\t;;\n\tcydra)\n\t\tbasic_machine=cydra-cydrome\n\t\t;;\n\torion)\n\t\tbasic_machine=orion-highlevel\n\t\t;;\n\torion105)\n\t\tbasic_machine=clipper-highlevel\n\t\t;;\n\tmac | mpw | mac-mpw)\n\t\tbasic_machine=m68k-apple\n\t\t;;\n\tpmac | pmac-mpw)\n\t\tbasic_machine=powerpc-apple\n\t\t;;\n\t*-unknown)\n\t\t# Make sure to match an already-canonicalized machine name.\n\t\t;;\n\t*)\n\t\techo Invalid configuration \\`$1\\': machine \\`$basic_machine\\' not recognized 1>&2\n\t\texit 1\n\t\t;;\nesac\n\n# Here we canonicalize certain aliases for manufacturers.\ncase $basic_machine in\n\t*-digital*)\n\t\tbasic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`\n\t\t;;\n\t*-commodore*)\n\t\tbasic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`\n\t\t;;\n\t*)\n\t\t;;\nesac\n\n# Decode manufacturer-specific aliases for certain operating systems.\n\nif [ x\"$os\" != x\"\" ]\nthen\ncase $os in\n\t# First match some system type aliases\n\t# that might get confused with valid system types.\n\t# -solaris* is a basic system type, with this one exception.\n\t-auroraux)\n\t\tos=-auroraux\n\t\t;;\n\t-solaris1 | -solaris1.*)\n\t\tos=`echo $os | sed -e 's|solaris1|sunos4|'`\n\t\t;;\n\t-solaris)\n\t\tos=-solaris2\n\t\t;;\n\t-svr4*)\n\t\tos=-sysv4\n\t\t;;\n\t-unixware*)\n\t\tos=-sysv4.2uw\n\t\t;;\n\t-gnu/linux*)\n\t\tos=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`\n\t\t;;\n\t# First accept the basic system types.\n\t# The portable systems comes first.\n\t# Each alternative MUST END IN A *, to match a version number.\n\t# -sysv* is not here because it comes later, after sysvr4.\n\t-gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \\\n\t      | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\\\n\t      | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \\\n\t      | -sym* | -kopensolaris* | -plan9* \\\n\t      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \\\n\t      | -aos* | -aros* \\\n\t      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \\\n\t      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \\\n\t      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \\\n\t      | -bitrig* | -openbsd* | -solidbsd* \\\n\t      | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \\\n\t      | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \\\n\t      | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \\\n\t      | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \\\n\t      | -chorusos* | -chorusrdb* | -cegcc* \\\n\t      | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \\\n\t      | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \\\n\t      | -linux-newlib* | -linux-musl* | -linux-uclibc* \\\n\t      | -uxpv* | -beos* | -mpeix* | -udk* | -moxiebox* \\\n\t      | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \\\n\t      | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \\\n\t      | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \\\n\t      | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \\\n\t      | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \\\n\t      | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \\\n\t      | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es* | -tirtos*)\n\t# Remember, each alternative MUST END IN *, to match a version number.\n\t\t;;\n\t-qnx*)\n\t\tcase $basic_machine in\n\t\t    x86-* | i*86-*)\n\t\t\t;;\n\t\t    *)\n\t\t\tos=-nto$os\n\t\t\t;;\n\t\tesac\n\t\t;;\n\t-nto-qnx*)\n\t\t;;\n\t-nto*)\n\t\tos=`echo $os | sed -e 's|nto|nto-qnx|'`\n\t\t;;\n\t-sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \\\n\t      | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \\\n\t      | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)\n\t\t;;\n\t-mac*)\n\t\tos=`echo $os | sed -e 's|mac|macos|'`\n\t\t;;\n\t-linux-dietlibc)\n\t\tos=-linux-dietlibc\n\t\t;;\n\t-linux*)\n\t\tos=`echo $os | sed -e 's|linux|linux-gnu|'`\n\t\t;;\n\t-sunos5*)\n\t\tos=`echo $os | sed -e 's|sunos5|solaris2|'`\n\t\t;;\n\t-sunos6*)\n\t\tos=`echo $os | sed -e 's|sunos6|solaris3|'`\n\t\t;;\n\t-opened*)\n\t\tos=-openedition\n\t\t;;\n\t-os400*)\n\t\tos=-os400\n\t\t;;\n\t-wince*)\n\t\tos=-wince\n\t\t;;\n\t-osfrose*)\n\t\tos=-osfrose\n\t\t;;\n\t-osf*)\n\t\tos=-osf\n\t\t;;\n\t-utek*)\n\t\tos=-bsd\n\t\t;;\n\t-dynix*)\n\t\tos=-bsd\n\t\t;;\n\t-acis*)\n\t\tos=-aos\n\t\t;;\n\t-atheos*)\n\t\tos=-atheos\n\t\t;;\n\t-syllable*)\n\t\tos=-syllable\n\t\t;;\n\t-386bsd)\n\t\tos=-bsd\n\t\t;;\n\t-ctix* | -uts*)\n\t\tos=-sysv\n\t\t;;\n\t-nova*)\n\t\tos=-rtmk-nova\n\t\t;;\n\t-ns2 )\n\t\tos=-nextstep2\n\t\t;;\n\t-nsk*)\n\t\tos=-nsk\n\t\t;;\n\t# Preserve the version number of sinix5.\n\t-sinix5.*)\n\t\tos=`echo $os | sed -e 's|sinix|sysv|'`\n\t\t;;\n\t-sinix*)\n\t\tos=-sysv4\n\t\t;;\n\t-tpf*)\n\t\tos=-tpf\n\t\t;;\n\t-triton*)\n\t\tos=-sysv3\n\t\t;;\n\t-oss*)\n\t\tos=-sysv3\n\t\t;;\n\t-svr4)\n\t\tos=-sysv4\n\t\t;;\n\t-svr3)\n\t\tos=-sysv3\n\t\t;;\n\t-sysvr4)\n\t\tos=-sysv4\n\t\t;;\n\t# This must come after -sysvr4.\n\t-sysv*)\n\t\t;;\n\t-ose*)\n\t\tos=-ose\n\t\t;;\n\t-es1800*)\n\t\tos=-ose\n\t\t;;\n\t-xenix)\n\t\tos=-xenix\n\t\t;;\n\t-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)\n\t\tos=-mint\n\t\t;;\n\t-aros*)\n\t\tos=-aros\n\t\t;;\n\t-zvmoe)\n\t\tos=-zvmoe\n\t\t;;\n\t-dicos*)\n\t\tos=-dicos\n\t\t;;\n\t-nacl*)\n\t\t;;\n\t-none)\n\t\t;;\n\t*)\n\t\t# Get rid of the `-' at the beginning of $os.\n\t\tos=`echo $os | sed 's/[^-]*-//'`\n\t\techo Invalid configuration \\`$1\\': system \\`$os\\' not recognized 1>&2\n\t\texit 1\n\t\t;;\nesac\nelse\n\n# Here we handle the default operating systems that come with various machines.\n# The value should be what the vendor currently ships out the door with their\n# machine or put another way, the most popular os provided with the machine.\n\n# Note that if you're going to try to match \"-MANUFACTURER\" here (say,\n# \"-sun\"), then you have to tell the case statement up towards the top\n# that MANUFACTURER isn't an operating system.  Otherwise, code above\n# will signal an error saying that MANUFACTURER isn't an operating\n# system, and we'll never get to this point.\n\ncase $basic_machine in\n\tscore-*)\n\t\tos=-elf\n\t\t;;\n\tspu-*)\n\t\tos=-elf\n\t\t;;\n\t*-acorn)\n\t\tos=-riscix1.2\n\t\t;;\n\tarm*-rebel)\n\t\tos=-linux\n\t\t;;\n\tarm*-semi)\n\t\tos=-aout\n\t\t;;\n\tc4x-* | tic4x-*)\n\t\tos=-coff\n\t\t;;\n\tc8051-*)\n\t\tos=-elf\n\t\t;;\n\thexagon-*)\n\t\tos=-elf\n\t\t;;\n\ttic54x-*)\n\t\tos=-coff\n\t\t;;\n\ttic55x-*)\n\t\tos=-coff\n\t\t;;\n\ttic6x-*)\n\t\tos=-coff\n\t\t;;\n\t# This must come before the *-dec entry.\n\tpdp10-*)\n\t\tos=-tops20\n\t\t;;\n\tpdp11-*)\n\t\tos=-none\n\t\t;;\n\t*-dec | vax-*)\n\t\tos=-ultrix4.2\n\t\t;;\n\tm68*-apollo)\n\t\tos=-domain\n\t\t;;\n\ti386-sun)\n\t\tos=-sunos4.0.2\n\t\t;;\n\tm68000-sun)\n\t\tos=-sunos3\n\t\t;;\n\tm68*-cisco)\n\t\tos=-aout\n\t\t;;\n\tmep-*)\n\t\tos=-elf\n\t\t;;\n\tmips*-cisco)\n\t\tos=-elf\n\t\t;;\n\tmips*-*)\n\t\tos=-elf\n\t\t;;\n\tor32-*)\n\t\tos=-coff\n\t\t;;\n\t*-tti)\t# must be before sparc entry or we get the wrong os.\n\t\tos=-sysv3\n\t\t;;\n\tsparc-* | *-sun)\n\t\tos=-sunos4.1.1\n\t\t;;\n\t*-be)\n\t\tos=-beos\n\t\t;;\n\t*-haiku)\n\t\tos=-haiku\n\t\t;;\n\t*-ibm)\n\t\tos=-aix\n\t\t;;\n\t*-knuth)\n\t\tos=-mmixware\n\t\t;;\n\t*-wec)\n\t\tos=-proelf\n\t\t;;\n\t*-winbond)\n\t\tos=-proelf\n\t\t;;\n\t*-oki)\n\t\tos=-proelf\n\t\t;;\n\t*-hp)\n\t\tos=-hpux\n\t\t;;\n\t*-hitachi)\n\t\tos=-hiux\n\t\t;;\n\ti860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)\n\t\tos=-sysv\n\t\t;;\n\t*-cbm)\n\t\tos=-amigaos\n\t\t;;\n\t*-dg)\n\t\tos=-dgux\n\t\t;;\n\t*-dolphin)\n\t\tos=-sysv3\n\t\t;;\n\tm68k-ccur)\n\t\tos=-rtu\n\t\t;;\n\tm88k-omron*)\n\t\tos=-luna\n\t\t;;\n\t*-next )\n\t\tos=-nextstep\n\t\t;;\n\t*-sequent)\n\t\tos=-ptx\n\t\t;;\n\t*-crds)\n\t\tos=-unos\n\t\t;;\n\t*-ns)\n\t\tos=-genix\n\t\t;;\n\ti370-*)\n\t\tos=-mvs\n\t\t;;\n\t*-next)\n\t\tos=-nextstep3\n\t\t;;\n\t*-gould)\n\t\tos=-sysv\n\t\t;;\n\t*-highlevel)\n\t\tos=-bsd\n\t\t;;\n\t*-encore)\n\t\tos=-bsd\n\t\t;;\n\t*-sgi)\n\t\tos=-irix\n\t\t;;\n\t*-siemens)\n\t\tos=-sysv4\n\t\t;;\n\t*-masscomp)\n\t\tos=-rtu\n\t\t;;\n\tf30[01]-fujitsu | f700-fujitsu)\n\t\tos=-uxpv\n\t\t;;\n\t*-rom68k)\n\t\tos=-coff\n\t\t;;\n\t*-*bug)\n\t\tos=-coff\n\t\t;;\n\t*-apple)\n\t\tos=-macos\n\t\t;;\n\t*-atari*)\n\t\tos=-mint\n\t\t;;\n\t*)\n\t\tos=-none\n\t\t;;\nesac\nfi\n\n# Here we handle the case where we know the os, and the CPU type, but not the\n# manufacturer.  We pick the logical manufacturer.\nvendor=unknown\ncase $basic_machine in\n\t*-unknown)\n\t\tcase $os in\n\t\t\t-riscix*)\n\t\t\t\tvendor=acorn\n\t\t\t\t;;\n\t\t\t-sunos*)\n\t\t\t\tvendor=sun\n\t\t\t\t;;\n\t\t\t-cnk*|-aix*)\n\t\t\t\tvendor=ibm\n\t\t\t\t;;\n\t\t\t-beos*)\n\t\t\t\tvendor=be\n\t\t\t\t;;\n\t\t\t-hpux*)\n\t\t\t\tvendor=hp\n\t\t\t\t;;\n\t\t\t-mpeix*)\n\t\t\t\tvendor=hp\n\t\t\t\t;;\n\t\t\t-hiux*)\n\t\t\t\tvendor=hitachi\n\t\t\t\t;;\n\t\t\t-unos*)\n\t\t\t\tvendor=crds\n\t\t\t\t;;\n\t\t\t-dgux*)\n\t\t\t\tvendor=dg\n\t\t\t\t;;\n\t\t\t-luna*)\n\t\t\t\tvendor=omron\n\t\t\t\t;;\n\t\t\t-genix*)\n\t\t\t\tvendor=ns\n\t\t\t\t;;\n\t\t\t-mvs* | -opened*)\n\t\t\t\tvendor=ibm\n\t\t\t\t;;\n\t\t\t-os400*)\n\t\t\t\tvendor=ibm\n\t\t\t\t;;\n\t\t\t-ptx*)\n\t\t\t\tvendor=sequent\n\t\t\t\t;;\n\t\t\t-tpf*)\n\t\t\t\tvendor=ibm\n\t\t\t\t;;\n\t\t\t-vxsim* | -vxworks* | -windiss*)\n\t\t\t\tvendor=wrs\n\t\t\t\t;;\n\t\t\t-aux*)\n\t\t\t\tvendor=apple\n\t\t\t\t;;\n\t\t\t-hms*)\n\t\t\t\tvendor=hitachi\n\t\t\t\t;;\n\t\t\t-mpw* | -macos*)\n\t\t\t\tvendor=apple\n\t\t\t\t;;\n\t\t\t-*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)\n\t\t\t\tvendor=atari\n\t\t\t\t;;\n\t\t\t-vos*)\n\t\t\t\tvendor=stratus\n\t\t\t\t;;\n\t\tesac\n\t\tbasic_machine=`echo $basic_machine | sed \"s/unknown/$vendor/\"`\n\t\t;;\nesac\n\necho $basic_machine$os\nexit\n\n# Local variables:\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"timestamp='\"\n# time-stamp-format: \"%:y-%02m-%02d\"\n# time-stamp-end: \"'\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/configure.ac",
    "content": "# IJG auto-configuration source file.\n# Process this file with autoconf to produce a configure script.\n\n#\n# Configure script for IJG libjpeg\n#\n\nAC_INIT([libjpeg], [9.2.0])\n\n# Directory where autotools helper scripts lives.\nAC_CONFIG_AUX_DIR([.])\n\n# Generate configuration headers.\nAC_CONFIG_HEADERS([jconfig.h:jconfig.cfg])\n\n# Hack: disable autoheader so that it doesn't overwrite our cfg template.\nAUTOHEADER=\"echo autoheader ignored\"\n\n# Check system type\nAC_CANONICAL_TARGET\n\n# Initialize Automake\n# Don't require all the GNU mandated files\nAM_INIT_AUTOMAKE([-Wall -Werror no-dist foreign])\n\n# Make --enable-silent-rules the default.\n# To get verbose build output you may configure\n# with --disable-silent-rules or use \"make V=1\".\nAM_SILENT_RULES([yes])\n\n# Add configure option --enable-maintainer-mode which enables\n# dependency checking and generation useful to package maintainers.\n# This is made an option to avoid confusing end users.\nAM_MAINTAINER_MODE\n\n# Check for programs\nAC_PROG_CC\nAC_PROG_CC_STDC\nAC_PROG_CPP\nAC_PROG_INSTALL\nAC_PROG_MAKE_SET\nAC_PROG_LN_S\nAM_PROG_AR\n\n# Check if LD supports linker scripts,\n# and define automake conditional HAVE_LD_VERSION_SCRIPT if so.\nAC_ARG_ENABLE([ld-version-script],\n  AS_HELP_STRING([--enable-ld-version-script],\n    [enable linker version script (default is enabled when possible)]),\n    [have_ld_version_script=$enableval], [])\nif test -z \"$have_ld_version_script\"; then\n  AC_MSG_CHECKING([if LD -Wl,--version-script works])\n  save_LDFLAGS=\"$LDFLAGS\"\n  LDFLAGS=\"$LDFLAGS -Wl,--version-script=conftest.map\"\n  cat > conftest.map <<EOF\nVERS_1 {\n        global: sym;\n};\n\nVERS_2 {\n        global: sym;\n} VERS_1;\nEOF\n  AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])],\n                 [have_ld_version_script=yes], [have_ld_version_script=no])\n  rm -f conftest.map\n  LDFLAGS=\"$save_LDFLAGS\"\n  AC_MSG_RESULT($have_ld_version_script)\nfi\nAM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test \"$have_ld_version_script\" = \"yes\")\n\n# See if compiler supports prototypes.\nAC_MSG_CHECKING([for function prototypes])\nAC_CACHE_VAL([ijg_cv_have_prototypes],\n[AC_COMPILE_IFELSE([AC_LANG_SOURCE([[\nint testfunction (int arg1, int * arg2); /* check prototypes */\nstruct methods_struct {\t\t/* check method-pointer declarations */\n  int (*error_exit) (char *msgtext);\n  int (*trace_message) (char *msgtext);\n  int (*another_method) (void);\n};\nint testfunction (int arg1, int * arg2) /* check definitions */\n{ return arg2[arg1]; }\nint test2function (void)\t/* check void arg list */\n{ return 0; }\n]])],\n          [ijg_cv_have_prototypes=yes],\n          [ijg_cv_have_prototypes=no])])\nAC_MSG_RESULT([$ijg_cv_have_prototypes])\nif test $ijg_cv_have_prototypes = yes; then\n  AC_DEFINE([HAVE_PROTOTYPES],[1],[Compiler supports function prototypes.])\nelse\n  AC_MSG_WARN([Your compiler does not seem to know about function prototypes.\n    Perhaps it needs a special switch to enable ANSI C mode.\n    If so, we recommend running configure like this:\n       ./configure  CC='cc -switch'\n    where -switch is the proper switch.])\nfi\n\n# Check header files\nAC_CHECK_HEADERS([stddef.h stdlib.h locale.h])\nAC_CHECK_HEADER([string.h], [],\n [AC_DEFINE([NEED_BSD_STRINGS], [1],\n            [Compiler has <strings.h> rather than standard <string.h>.])])\n\n# See whether type size_t is defined in any ANSI-standard places;\n# if not, perhaps it is defined in <sys/types.h>.\nAC_MSG_CHECKING([for size_t])\nAC_TRY_COMPILE([\n#ifdef HAVE_STDDEF_H\n#include <stddef.h>\n#endif\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n#include <stdio.h>\n#ifdef NEED_BSD_STRINGS\n#include <strings.h>\n#else\n#include <string.h>\n#endif\ntypedef size_t my_size_t;\n],\n      [ my_size_t foovar; ],\n      [ijg_size_t_ok=yes],\n      [ijg_size_t_ok=\"not ANSI, perhaps it is in sys/types.h\"])\nAC_MSG_RESULT([$ijg_size_t_ok])\nif test \"$ijg_size_t_ok\" != yes; then\n  AC_CHECK_HEADER([sys/types.h],\n     [AC_DEFINE([NEED_SYS_TYPES_H], [1],\n                [Need to include <sys/types.h> in order to obtain size_t.])\n      AC_EGREP_CPP([size_t], [#include <sys/types.h>],\n                   [ijg_size_t_ok=\"size_t is in sys/types.h\"],\n                   [ijg_size_t_ok=no])],\n     [ijg_size_t_ok=no])\n  AC_MSG_RESULT([$ijg_size_t_ok])\n  if test \"$ijg_size_t_ok\" = no; then\n    AC_MSG_WARN([Type size_t is not defined in any of the usual places.\n      Try putting '\"typedef unsigned int size_t;\"' in jconfig.h.])\n  fi\nfi\n\n# Check compiler characteristics\nAC_MSG_CHECKING([for type unsigned char])\nAC_TRY_COMPILE([], [ unsigned char un_char; ],\n [AC_MSG_RESULT(yes)\n  AC_DEFINE([HAVE_UNSIGNED_CHAR], [1],\n            [Compiler supports 'unsigned char'.])],\n [AC_MSG_RESULT(no)])\n\nAC_MSG_CHECKING([for type unsigned short])\nAC_TRY_COMPILE([], [ unsigned short un_short; ],\n  [AC_MSG_RESULT(yes)\n   AC_DEFINE([HAVE_UNSIGNED_SHORT], [1],\n             [Compiler supports 'unsigned short'.])],\n  [AC_MSG_RESULT(no)])\n\nAC_MSG_CHECKING([for type void])\nAC_TRY_COMPILE([\n/* Caution: a C++ compiler will insist on valid prototypes */\ntypedef void * void_ptr;\t/* check void * */\n#ifdef HAVE_PROTOTYPES\t\t/* check ptr to function returning void */\ntypedef void (*void_func) (int a, int b);\n#else\ntypedef void (*void_func) ();\n#endif\n\n#ifdef HAVE_PROTOTYPES\t\t/* check void function result */\nvoid test3function (void_ptr arg1, void_func arg2)\n#else\nvoid test3function (arg1, arg2)\n     void_ptr arg1;\n     void_func arg2;\n#endif\n{\n  char * locptr = (char *) arg1; /* check casting to and from void * */\n  arg1 = (void *) locptr;\n  (*arg2) (1, 2);\t\t/* check call of fcn returning void */\n}\n], [ ],\n        [AC_MSG_RESULT(yes)],\n        [AC_MSG_RESULT(no)\n         AC_DEFINE([void], [char],\n                   [Define 'void' as 'char' for archaic compilers\n                    that don't understand it.])])\nAC_C_CONST\n\n# Check for non-broken inline under various spellings\nAC_MSG_CHECKING([for inline])\nijg_cv_inline=\"\"\nAC_TRY_COMPILE([], [} __inline__ int foo() { return 0; }\nint bar() { return foo();], ijg_cv_inline=\"__inline__\",\n[AC_TRY_COMPILE(, [} __inline int foo() { return 0; }\nint bar() { return foo();], ijg_cv_inline=\"__inline\",\n[AC_TRY_COMPILE(, [} inline int foo() { return 0; }\nint bar() { return foo();], ijg_cv_inline=\"inline\")])])\nAC_MSG_RESULT($ijg_cv_inline)\nAC_DEFINE_UNQUOTED([INLINE], [$ijg_cv_inline],\n                   [How to obtain function inlining.])\n\n# We cannot check for bogus warnings, but at least we can check for errors\nAC_MSG_CHECKING([for broken incomplete types])\nAC_TRY_COMPILE([ typedef struct undefined_structure * undef_struct_ptr; ],\n               [],\n               [AC_MSG_RESULT(ok)],\n               [AC_MSG_RESULT(broken)\n                AC_DEFINE([INCOMPLETE_TYPES_BROKEN], [1],\n                          [Compiler does not support pointers to unspecified\n                           structures.])])\n\n# Test whether global names are unique to at least 15 chars\nAC_MSG_CHECKING([for short external names])\nAC_TRY_LINK([\nint possibly_duplicate_function () { return 0; }\nint possibly_dupli_function () { return 1; }\n], [],\n            [AC_MSG_RESULT(ok)],\n            [AC_MSG_RESULT(short)\n             AC_DEFINE([NEED_SHORT_EXTERNAL_NAMES], [1],\n                       [Linker requires that global names be unique in\n                        first 15 characters.])])\n\n# Run-time checks\nAC_MSG_CHECKING([to see if char is signed])\nAC_TRY_RUN([\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n#include <stdio.h>\n#ifdef HAVE_PROTOTYPES\nint is_char_signed (int arg)\n#else\nint is_char_signed (arg)\n     int arg;\n#endif\n{\n  if (arg == 189) {\t\t/* expected result for unsigned char */\n    return 0;\t\t\t/* type char is unsigned */\n  }\n  else if (arg != -67) {\t/* expected result for signed char */\n    printf(\"Hmm, it seems 'char' is not eight bits wide on your machine.\\n\");\n    printf(\"I fear the JPEG software will not work at all.\\n\\n\");\n  }\n  return 1;\t\t\t/* assume char is signed otherwise */\n}\nchar signed_char_check = (char) (-67);\nint main() {\n  exit(is_char_signed((int) signed_char_check));\n}], [AC_MSG_RESULT(no)\n     AC_DEFINE([CHAR_IS_UNSIGNED], [1],\n               [Characters are unsigned])],\n               [AC_MSG_RESULT(yes)],\n[AC_MSG_WARN([Assuming that char is signed on target machine.\n    If it is unsigned, this will be a little bit inefficient.])\n])\n\nAC_MSG_CHECKING([to see if right shift is signed])\nAC_TRY_RUN([\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n#include <stdio.h>\n#ifdef HAVE_PROTOTYPES\nint is_shifting_signed (long arg)\n#else\nint is_shifting_signed (arg)\n     long arg;\n#endif\n/* See whether right-shift on a long is signed or not. */\n{\n  long res = arg >> 4;\n\n  if (res == -0x7F7E80CL) {\t/* expected result for signed shift */\n    return 1;\t\t\t/* right shift is signed */\n  }\n  /* see if unsigned-shift hack will fix it. */\n  /* we can't just test exact value since it depends on width of long... */\n  res |= (~0L) << (32-4);\n  if (res == -0x7F7E80CL) {\t/* expected result now? */\n    return 0;\t\t\t/* right shift is unsigned */\n  }\n  printf(\"Right shift isn't acting as I expect it to.\\n\");\n  printf(\"I fear the JPEG software will not work at all.\\n\\n\");\n  return 0;\t\t\t/* try it with unsigned anyway */\n}\nint main() {\n  exit(is_shifting_signed(-0x7F7E80B1L));\n}],\n      [AC_MSG_RESULT(no)\n       AC_DEFINE([RIGHT_SHIFT_IS_UNSIGNED], [1],\n                 [Broken compiler shifts signed values as an unsigned shift.])],\n       [AC_MSG_RESULT(yes)],\n       [AC_MSG_RESULT(Assuming that right shift is signed on target machine.)])\n\nAC_MSG_CHECKING([to see if fopen accepts b spec])\nAC_TRY_RUN([\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n#include <stdio.h>\nint main() {\n  if (fopen(\"conftestdata\", \"wb\") != NULL)\n    exit(0);\n  exit(1);\n}],\n          [AC_MSG_RESULT(yes)],\n          [AC_MSG_RESULT(no)\n           AC_DEFINE([DONT_USE_B_MODE], [1],\n                     [Don't open files in binary mode.])],\n          [AC_MSG_RESULT(Assuming that it does.)])\n\n# Configure libtool\nAC_LIBTOOL_WIN32_DLL\nAC_PROG_LIBTOOL\n\n# Select memory manager depending on user input.\n# If no \"-enable-maxmem\", use jmemnobs\nMEMORYMGR='jmemnobs'\nMAXMEM=\"no\"\nAC_ARG_ENABLE([maxmem],\n[  --enable-maxmem[=N]     enable use of temp files, set max mem usage to N MB],\n[MAXMEM=\"$enableval\"])\ndnl [# support --with-maxmem for backwards compatibility with IJG V5.]\ndnl AC_ARG_WITH(maxmem, , MAXMEM=\"$withval\")\nif test \"x$MAXMEM\" = xyes; then\n  MAXMEM=1\nfi\nif test \"x$MAXMEM\" != xno; then\n  if test -n \"`echo $MAXMEM | sed 's/[[0-9]]//g'`\"; then\n    AC_MSG_ERROR(non-numeric argument to --enable-maxmem)\n  fi\n  DEFAULTMAXMEM=`expr $MAXMEM \\* 1048576`\n  AC_DEFINE_UNQUOTED([DEFAULT_MAX_MEM], [${DEFAULTMAXMEM}],\n                     [Maximum data space library will allocate.])\n  AC_MSG_CHECKING([for 'tmpfile()'])\n  AC_TRY_LINK([#include <stdio.h>], [ FILE * tfile = tmpfile(); ],\n    [AC_MSG_RESULT(yes)\n    MEMORYMGR='jmemansi'],\n    [AC_MSG_RESULT(no)\n    dnl if tmpfile is not present, must use jmemname.\n    MEMORYMGR='jmemname'\n\n    # Test for the need to remove temporary files using a signal handler\n    # (for cjpeg/djpeg)\n    AC_DEFINE([NEED_SIGNAL_CATCHER], [1],\n              [Need signal handler to clean up temporary files.])\n    AC_MSG_CHECKING([for 'mktemp()'])\n    AC_TRY_LINK([], [ char fname[80]; mktemp(fname); ],\n                [AC_MSG_RESULT(yes)],\n                [AC_MSG_RESULT(no)\n                 AC_DEFINE([NO_MKTEMP], [1],\n                           [The mktemp() function is not available.])])])\nfi\nAC_SUBST([MEMORYMGR])\n\n# Extract the library version IDs from jpeglib.h.\nAC_MSG_CHECKING([libjpeg version number])\n[major=`sed -ne 's/^#define JPEG_LIB_VERSION_MAJOR *\\([0-9][0-9]*\\).*$/\\1/p' $srcdir/jpeglib.h`\nminor=`sed -ne 's/^#define JPEG_LIB_VERSION_MINOR *\\([0-9][0-9]*\\).*$/\\1/p' $srcdir/jpeglib.h`]\nAC_SUBST([JPEG_LIB_VERSION],\n         [`expr $major + $minor`:0:$minor])\nAC_MSG_RESULT([$JPEG_LIB_VERSION])\n\nAC_CONFIG_FILES([Makefile])\nAC_OUTPUT\n"
  },
  {
    "path": "tess-two/jni/libjpeg/depcomp",
    "content": "#! /bin/sh\n# depcomp - compile a program generating dependencies as side-effects\n\nscriptversion=2013-05-30.07; # UTC\n\n# Copyright (C) 1999-2014 Free Software Foundation, Inc.\n\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2, or (at your option)\n# any later version.\n\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that program.\n\n# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>.\n\ncase $1 in\n  '')\n    echo \"$0: No command.  Try '$0 --help' for more information.\" 1>&2\n    exit 1;\n    ;;\n  -h | --h*)\n    cat <<\\EOF\nUsage: depcomp [--help] [--version] PROGRAM [ARGS]\n\nRun PROGRAMS ARGS to compile a file, generating dependencies\nas side-effects.\n\nEnvironment variables:\n  depmode     Dependency tracking mode.\n  source      Source file read by 'PROGRAMS ARGS'.\n  object      Object file output by 'PROGRAMS ARGS'.\n  DEPDIR      directory where to store dependencies.\n  depfile     Dependency file to output.\n  tmpdepfile  Temporary file to use when outputting dependencies.\n  libtool     Whether libtool is used (yes/no).\n\nReport bugs to <bug-automake@gnu.org>.\nEOF\n    exit $?\n    ;;\n  -v | --v*)\n    echo \"depcomp $scriptversion\"\n    exit $?\n    ;;\nesac\n\n# Get the directory component of the given path, and save it in the\n# global variables '$dir'.  Note that this directory component will\n# be either empty or ending with a '/' character.  This is deliberate.\nset_dir_from ()\n{\n  case $1 in\n    */*) dir=`echo \"$1\" | sed -e 's|/[^/]*$|/|'`;;\n      *) dir=;;\n  esac\n}\n\n# Get the suffix-stripped basename of the given path, and save it the\n# global variable '$base'.\nset_base_from ()\n{\n  base=`echo \"$1\" | sed -e 's|^.*/||' -e 's/\\.[^.]*$//'`\n}\n\n# If no dependency file was actually created by the compiler invocation,\n# we still have to create a dummy depfile, to avoid errors with the\n# Makefile \"include basename.Plo\" scheme.\nmake_dummy_depfile ()\n{\n  echo \"#dummy\" > \"$depfile\"\n}\n\n# Factor out some common post-processing of the generated depfile.\n# Requires the auxiliary global variable '$tmpdepfile' to be set.\naix_post_process_depfile ()\n{\n  # If the compiler actually managed to produce a dependency file,\n  # post-process it.\n  if test -f \"$tmpdepfile\"; then\n    # Each line is of the form 'foo.o: dependency.h'.\n    # Do two passes, one to just change these to\n    #   $object: dependency.h\n    # and one to simply output\n    #   dependency.h:\n    # which is needed to avoid the deleted-header problem.\n    { sed -e \"s,^.*\\.[$lower]*:,$object:,\" < \"$tmpdepfile\"\n      sed -e \"s,^.*\\.[$lower]*:[$tab ]*,,\" -e 's,$,:,' < \"$tmpdepfile\"\n    } > \"$depfile\"\n    rm -f \"$tmpdepfile\"\n  else\n    make_dummy_depfile\n  fi\n}\n\n# A tabulation character.\ntab='\t'\n# A newline character.\nnl='\n'\n# Character ranges might be problematic outside the C locale.\n# These definitions help.\nupper=ABCDEFGHIJKLMNOPQRSTUVWXYZ\nlower=abcdefghijklmnopqrstuvwxyz\ndigits=0123456789\nalpha=${upper}${lower}\n\nif test -z \"$depmode\" || test -z \"$source\" || test -z \"$object\"; then\n  echo \"depcomp: Variables source, object and depmode must be set\" 1>&2\n  exit 1\nfi\n\n# Dependencies for sub/bar.o or sub/bar.obj go into sub/.deps/bar.Po.\ndepfile=${depfile-`echo \"$object\" |\n  sed 's|[^\\\\/]*$|'${DEPDIR-.deps}'/&|;s|\\.\\([^.]*\\)$|.P\\1|;s|Pobj$|Po|'`}\ntmpdepfile=${tmpdepfile-`echo \"$depfile\" | sed 's/\\.\\([^.]*\\)$/.T\\1/'`}\n\nrm -f \"$tmpdepfile\"\n\n# Avoid interferences from the environment.\ngccflag= dashmflag=\n\n# Some modes work just like other modes, but use different flags.  We\n# parameterize here, but still list the modes in the big case below,\n# to make depend.m4 easier to write.  Note that we *cannot* use a case\n# here, because this file can only contain one case statement.\nif test \"$depmode\" = hp; then\n  # HP compiler uses -M and no extra arg.\n  gccflag=-M\n  depmode=gcc\nfi\n\nif test \"$depmode\" = dashXmstdout; then\n  # This is just like dashmstdout with a different argument.\n  dashmflag=-xM\n  depmode=dashmstdout\nfi\n\ncygpath_u=\"cygpath -u -f -\"\nif test \"$depmode\" = msvcmsys; then\n  # This is just like msvisualcpp but w/o cygpath translation.\n  # Just convert the backslash-escaped backslashes to single forward\n  # slashes to satisfy depend.m4\n  cygpath_u='sed s,\\\\\\\\,/,g'\n  depmode=msvisualcpp\nfi\n\nif test \"$depmode\" = msvc7msys; then\n  # This is just like msvc7 but w/o cygpath translation.\n  # Just convert the backslash-escaped backslashes to single forward\n  # slashes to satisfy depend.m4\n  cygpath_u='sed s,\\\\\\\\,/,g'\n  depmode=msvc7\nfi\n\nif test \"$depmode\" = xlc; then\n  # IBM C/C++ Compilers xlc/xlC can output gcc-like dependency information.\n  gccflag=-qmakedep=gcc,-MF\n  depmode=gcc\nfi\n\ncase \"$depmode\" in\ngcc3)\n## gcc 3 implements dependency tracking that does exactly what\n## we want.  Yay!  Note: for some reason libtool 1.4 doesn't like\n## it if -MD -MP comes after the -MF stuff.  Hmm.\n## Unfortunately, FreeBSD c89 acceptance of flags depends upon\n## the command line argument order; so add the flags where they\n## appear in depend2.am.  Note that the slowdown incurred here\n## affects only configure: in makefiles, %FASTDEP% shortcuts this.\n  for arg\n  do\n    case $arg in\n    -c) set fnord \"$@\" -MT \"$object\" -MD -MP -MF \"$tmpdepfile\" \"$arg\" ;;\n    *)  set fnord \"$@\" \"$arg\" ;;\n    esac\n    shift # fnord\n    shift # $arg\n  done\n  \"$@\"\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  mv \"$tmpdepfile\" \"$depfile\"\n  ;;\n\ngcc)\n## Note that this doesn't just cater to obsosete pre-3.x GCC compilers.\n## but also to in-use compilers like IMB xlc/xlC and the HP C compiler.\n## (see the conditional assignment to $gccflag above).\n## There are various ways to get dependency output from gcc.  Here's\n## why we pick this rather obscure method:\n## - Don't want to use -MD because we'd like the dependencies to end\n##   up in a subdir.  Having to rename by hand is ugly.\n##   (We might end up doing this anyway to support other compilers.)\n## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like\n##   -MM, not -M (despite what the docs say).  Also, it might not be\n##   supported by the other compilers which use the 'gcc' depmode.\n## - Using -M directly means running the compiler twice (even worse\n##   than renaming).\n  if test -z \"$gccflag\"; then\n    gccflag=-MD,\n  fi\n  \"$@\" -Wp,\"$gccflag$tmpdepfile\"\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  rm -f \"$depfile\"\n  echo \"$object : \\\\\" > \"$depfile\"\n  # The second -e expression handles DOS-style file names with drive\n  # letters.\n  sed -e 's/^[^:]*: / /' \\\n      -e 's/^['$alpha']:\\/[^:]*: / /' < \"$tmpdepfile\" >> \"$depfile\"\n## This next piece of magic avoids the \"deleted header file\" problem.\n## The problem is that when a header file which appears in a .P file\n## is deleted, the dependency causes make to die (because there is\n## typically no way to rebuild the header).  We avoid this by adding\n## dummy dependencies for each header file.  Too bad gcc doesn't do\n## this for us directly.\n## Some versions of gcc put a space before the ':'.  On the theory\n## that the space means something, we add a space to the output as\n## well.  hp depmode also adds that space, but also prefixes the VPATH\n## to the object.  Take care to not repeat it in the output.\n## Some versions of the HPUX 10.20 sed can't process this invocation\n## correctly.  Breaking it into two sed invocations is a workaround.\n  tr ' ' \"$nl\" < \"$tmpdepfile\" \\\n    | sed -e 's/^\\\\$//' -e '/^$/d' -e \"s|.*$object$||\" -e '/:$/d' \\\n    | sed -e 's/$/ :/' >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\nhp)\n  # This case exists only to let depend.m4 do its work.  It works by\n  # looking at the text of this script.  This case will never be run,\n  # since it is checked for above.\n  exit 1\n  ;;\n\nsgi)\n  if test \"$libtool\" = yes; then\n    \"$@\" \"-Wp,-MDupdate,$tmpdepfile\"\n  else\n    \"$@\" -MDupdate \"$tmpdepfile\"\n  fi\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  rm -f \"$depfile\"\n\n  if test -f \"$tmpdepfile\"; then  # yes, the sourcefile depend on other files\n    echo \"$object : \\\\\" > \"$depfile\"\n    # Clip off the initial element (the dependent).  Don't try to be\n    # clever and replace this with sed code, as IRIX sed won't handle\n    # lines with more than a fixed number of characters (4096 in\n    # IRIX 6.2 sed, 8192 in IRIX 6.5).  We also remove comment lines;\n    # the IRIX cc adds comments like '#:fec' to the end of the\n    # dependency line.\n    tr ' ' \"$nl\" < \"$tmpdepfile\" \\\n      | sed -e 's/^.*\\.o://' -e 's/#.*$//' -e '/^$/ d' \\\n      | tr \"$nl\" ' ' >> \"$depfile\"\n    echo >> \"$depfile\"\n    # The second pass generates a dummy entry for each header file.\n    tr ' ' \"$nl\" < \"$tmpdepfile\" \\\n      | sed -e 's/^.*\\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \\\n      >> \"$depfile\"\n  else\n    make_dummy_depfile\n  fi\n  rm -f \"$tmpdepfile\"\n  ;;\n\nxlc)\n  # This case exists only to let depend.m4 do its work.  It works by\n  # looking at the text of this script.  This case will never be run,\n  # since it is checked for above.\n  exit 1\n  ;;\n\naix)\n  # The C for AIX Compiler uses -M and outputs the dependencies\n  # in a .u file.  In older versions, this file always lives in the\n  # current directory.  Also, the AIX compiler puts '$object:' at the\n  # start of each line; $object doesn't have directory information.\n  # Version 6 uses the directory in both cases.\n  set_dir_from \"$object\"\n  set_base_from \"$object\"\n  if test \"$libtool\" = yes; then\n    tmpdepfile1=$dir$base.u\n    tmpdepfile2=$base.u\n    tmpdepfile3=$dir.libs/$base.u\n    \"$@\" -Wc,-M\n  else\n    tmpdepfile1=$dir$base.u\n    tmpdepfile2=$dir$base.u\n    tmpdepfile3=$dir$base.u\n    \"$@\" -M\n  fi\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile1\" \"$tmpdepfile2\" \"$tmpdepfile3\"\n    exit $stat\n  fi\n\n  for tmpdepfile in \"$tmpdepfile1\" \"$tmpdepfile2\" \"$tmpdepfile3\"\n  do\n    test -f \"$tmpdepfile\" && break\n  done\n  aix_post_process_depfile\n  ;;\n\ntcc)\n  # tcc (Tiny C Compiler) understand '-MD -MF file' since version 0.9.26\n  # FIXME: That version still under development at the moment of writing.\n  #        Make that this statement remains true also for stable, released\n  #        versions.\n  # It will wrap lines (doesn't matter whether long or short) with a\n  # trailing '\\', as in:\n  #\n  #   foo.o : \\\n  #    foo.c \\\n  #    foo.h \\\n  #\n  # It will put a trailing '\\' even on the last line, and will use leading\n  # spaces rather than leading tabs (at least since its commit 0394caf7\n  # \"Emit spaces for -MD\").\n  \"$@\" -MD -MF \"$tmpdepfile\"\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  rm -f \"$depfile\"\n  # Each non-empty line is of the form 'foo.o : \\' or ' dep.h \\'.\n  # We have to change lines of the first kind to '$object: \\'.\n  sed -e \"s|.*:|$object :|\" < \"$tmpdepfile\" > \"$depfile\"\n  # And for each line of the second kind, we have to emit a 'dep.h:'\n  # dummy dependency, to avoid the deleted-header problem.\n  sed -n -e 's|^  *\\(.*\\) *\\\\$|\\1:|p' < \"$tmpdepfile\" >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\n## The order of this option in the case statement is important, since the\n## shell code in configure will try each of these formats in the order\n## listed in this file.  A plain '-MD' option would be understood by many\n## compilers, so we must ensure this comes after the gcc and icc options.\npgcc)\n  # Portland's C compiler understands '-MD'.\n  # Will always output deps to 'file.d' where file is the root name of the\n  # source file under compilation, even if file resides in a subdirectory.\n  # The object file name does not affect the name of the '.d' file.\n  # pgcc 10.2 will output\n  #    foo.o: sub/foo.c sub/foo.h\n  # and will wrap long lines using '\\' :\n  #    foo.o: sub/foo.c ... \\\n  #     sub/foo.h ... \\\n  #     ...\n  set_dir_from \"$object\"\n  # Use the source, not the object, to determine the base name, since\n  # that's sadly what pgcc will do too.\n  set_base_from \"$source\"\n  tmpdepfile=$base.d\n\n  # For projects that build the same source file twice into different object\n  # files, the pgcc approach of using the *source* file root name can cause\n  # problems in parallel builds.  Use a locking strategy to avoid stomping on\n  # the same $tmpdepfile.\n  lockdir=$base.d-lock\n  trap \"\n    echo '$0: caught signal, cleaning up...' >&2\n    rmdir '$lockdir'\n    exit 1\n  \" 1 2 13 15\n  numtries=100\n  i=$numtries\n  while test $i -gt 0; do\n    # mkdir is a portable test-and-set.\n    if mkdir \"$lockdir\" 2>/dev/null; then\n      # This process acquired the lock.\n      \"$@\" -MD\n      stat=$?\n      # Release the lock.\n      rmdir \"$lockdir\"\n      break\n    else\n      # If the lock is being held by a different process, wait\n      # until the winning process is done or we timeout.\n      while test -d \"$lockdir\" && test $i -gt 0; do\n        sleep 1\n        i=`expr $i - 1`\n      done\n    fi\n    i=`expr $i - 1`\n  done\n  trap - 1 2 13 15\n  if test $i -le 0; then\n    echo \"$0: failed to acquire lock after $numtries attempts\" >&2\n    echo \"$0: check lockdir '$lockdir'\" >&2\n    exit 1\n  fi\n\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  rm -f \"$depfile\"\n  # Each line is of the form `foo.o: dependent.h',\n  # or `foo.o: dep1.h dep2.h \\', or ` dep3.h dep4.h \\'.\n  # Do two passes, one to just change these to\n  # `$object: dependent.h' and one to simply `dependent.h:'.\n  sed \"s,^[^:]*:,$object :,\" < \"$tmpdepfile\" > \"$depfile\"\n  # Some versions of the HPUX 10.20 sed can't process this invocation\n  # correctly.  Breaking it into two sed invocations is a workaround.\n  sed 's,^[^:]*: \\(.*\\)$,\\1,;s/^\\\\$//;/^$/d;/:$/d' < \"$tmpdepfile\" \\\n    | sed -e 's/$/ :/' >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\nhp2)\n  # The \"hp\" stanza above does not work with aCC (C++) and HP's ia64\n  # compilers, which have integrated preprocessors.  The correct option\n  # to use with these is +Maked; it writes dependencies to a file named\n  # 'foo.d', which lands next to the object file, wherever that\n  # happens to be.\n  # Much of this is similar to the tru64 case; see comments there.\n  set_dir_from  \"$object\"\n  set_base_from \"$object\"\n  if test \"$libtool\" = yes; then\n    tmpdepfile1=$dir$base.d\n    tmpdepfile2=$dir.libs/$base.d\n    \"$@\" -Wc,+Maked\n  else\n    tmpdepfile1=$dir$base.d\n    tmpdepfile2=$dir$base.d\n    \"$@\" +Maked\n  fi\n  stat=$?\n  if test $stat -ne 0; then\n     rm -f \"$tmpdepfile1\" \"$tmpdepfile2\"\n     exit $stat\n  fi\n\n  for tmpdepfile in \"$tmpdepfile1\" \"$tmpdepfile2\"\n  do\n    test -f \"$tmpdepfile\" && break\n  done\n  if test -f \"$tmpdepfile\"; then\n    sed -e \"s,^.*\\.[$lower]*:,$object:,\" \"$tmpdepfile\" > \"$depfile\"\n    # Add 'dependent.h:' lines.\n    sed -ne '2,${\n               s/^ *//\n               s/ \\\\*$//\n               s/$/:/\n               p\n             }' \"$tmpdepfile\" >> \"$depfile\"\n  else\n    make_dummy_depfile\n  fi\n  rm -f \"$tmpdepfile\" \"$tmpdepfile2\"\n  ;;\n\ntru64)\n  # The Tru64 compiler uses -MD to generate dependencies as a side\n  # effect.  'cc -MD -o foo.o ...' puts the dependencies into 'foo.o.d'.\n  # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put\n  # dependencies in 'foo.d' instead, so we check for that too.\n  # Subdirectories are respected.\n  set_dir_from  \"$object\"\n  set_base_from \"$object\"\n\n  if test \"$libtool\" = yes; then\n    # Libtool generates 2 separate objects for the 2 libraries.  These\n    # two compilations output dependencies in $dir.libs/$base.o.d and\n    # in $dir$base.o.d.  We have to check for both files, because\n    # one of the two compilations can be disabled.  We should prefer\n    # $dir$base.o.d over $dir.libs/$base.o.d because the latter is\n    # automatically cleaned when .libs/ is deleted, while ignoring\n    # the former would cause a distcleancheck panic.\n    tmpdepfile1=$dir$base.o.d          # libtool 1.5\n    tmpdepfile2=$dir.libs/$base.o.d    # Likewise.\n    tmpdepfile3=$dir.libs/$base.d      # Compaq CCC V6.2-504\n    \"$@\" -Wc,-MD\n  else\n    tmpdepfile1=$dir$base.d\n    tmpdepfile2=$dir$base.d\n    tmpdepfile3=$dir$base.d\n    \"$@\" -MD\n  fi\n\n  stat=$?\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile1\" \"$tmpdepfile2\" \"$tmpdepfile3\"\n    exit $stat\n  fi\n\n  for tmpdepfile in \"$tmpdepfile1\" \"$tmpdepfile2\" \"$tmpdepfile3\"\n  do\n    test -f \"$tmpdepfile\" && break\n  done\n  # Same post-processing that is required for AIX mode.\n  aix_post_process_depfile\n  ;;\n\nmsvc7)\n  if test \"$libtool\" = yes; then\n    showIncludes=-Wc,-showIncludes\n  else\n    showIncludes=-showIncludes\n  fi\n  \"$@\" $showIncludes > \"$tmpdepfile\"\n  stat=$?\n  grep -v '^Note: including file: ' \"$tmpdepfile\"\n  if test $stat -ne 0; then\n    rm -f \"$tmpdepfile\"\n    exit $stat\n  fi\n  rm -f \"$depfile\"\n  echo \"$object : \\\\\" > \"$depfile\"\n  # The first sed program below extracts the file names and escapes\n  # backslashes for cygpath.  The second sed program outputs the file\n  # name when reading, but also accumulates all include files in the\n  # hold buffer in order to output them again at the end.  This only\n  # works with sed implementations that can handle large buffers.\n  sed < \"$tmpdepfile\" -n '\n/^Note: including file:  *\\(.*\\)/ {\n  s//\\1/\n  s/\\\\/\\\\\\\\/g\n  p\n}' | $cygpath_u | sort -u | sed -n '\ns/ /\\\\ /g\ns/\\(.*\\)/'\"$tab\"'\\1 \\\\/p\ns/.\\(.*\\) \\\\/\\1:/\nH\n$ {\n  s/.*/'\"$tab\"'/\n  G\n  p\n}' >> \"$depfile\"\n  echo >> \"$depfile\" # make sure the fragment doesn't end with a backslash\n  rm -f \"$tmpdepfile\"\n  ;;\n\nmsvc7msys)\n  # This case exists only to let depend.m4 do its work.  It works by\n  # looking at the text of this script.  This case will never be run,\n  # since it is checked for above.\n  exit 1\n  ;;\n\n#nosideeffect)\n  # This comment above is used by automake to tell side-effect\n  # dependency tracking mechanisms from slower ones.\n\ndashmstdout)\n  # Important note: in order to support this mode, a compiler *must*\n  # always write the preprocessed file to stdout, regardless of -o.\n  \"$@\" || exit $?\n\n  # Remove the call to Libtool.\n  if test \"$libtool\" = yes; then\n    while test \"X$1\" != 'X--mode=compile'; do\n      shift\n    done\n    shift\n  fi\n\n  # Remove '-o $object'.\n  IFS=\" \"\n  for arg\n  do\n    case $arg in\n    -o)\n      shift\n      ;;\n    $object)\n      shift\n      ;;\n    *)\n      set fnord \"$@\" \"$arg\"\n      shift # fnord\n      shift # $arg\n      ;;\n    esac\n  done\n\n  test -z \"$dashmflag\" && dashmflag=-M\n  # Require at least two characters before searching for ':'\n  # in the target name.  This is to cope with DOS-style filenames:\n  # a dependency such as 'c:/foo/bar' could be seen as target 'c' otherwise.\n  \"$@\" $dashmflag |\n    sed \"s|^[$tab ]*[^:$tab ][^:][^:]*:[$tab ]*|$object: |\" > \"$tmpdepfile\"\n  rm -f \"$depfile\"\n  cat < \"$tmpdepfile\" > \"$depfile\"\n  # Some versions of the HPUX 10.20 sed can't process this sed invocation\n  # correctly.  Breaking it into two sed invocations is a workaround.\n  tr ' ' \"$nl\" < \"$tmpdepfile\" \\\n    | sed -e 's/^\\\\$//' -e '/^$/d' -e '/:$/d' \\\n    | sed -e 's/$/ :/' >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\ndashXmstdout)\n  # This case only exists to satisfy depend.m4.  It is never actually\n  # run, as this mode is specially recognized in the preamble.\n  exit 1\n  ;;\n\nmakedepend)\n  \"$@\" || exit $?\n  # Remove any Libtool call\n  if test \"$libtool\" = yes; then\n    while test \"X$1\" != 'X--mode=compile'; do\n      shift\n    done\n    shift\n  fi\n  # X makedepend\n  shift\n  cleared=no eat=no\n  for arg\n  do\n    case $cleared in\n    no)\n      set \"\"; shift\n      cleared=yes ;;\n    esac\n    if test $eat = yes; then\n      eat=no\n      continue\n    fi\n    case \"$arg\" in\n    -D*|-I*)\n      set fnord \"$@\" \"$arg\"; shift ;;\n    # Strip any option that makedepend may not understand.  Remove\n    # the object too, otherwise makedepend will parse it as a source file.\n    -arch)\n      eat=yes ;;\n    -*|$object)\n      ;;\n    *)\n      set fnord \"$@\" \"$arg\"; shift ;;\n    esac\n  done\n  obj_suffix=`echo \"$object\" | sed 's/^.*\\././'`\n  touch \"$tmpdepfile\"\n  ${MAKEDEPEND-makedepend} -o\"$obj_suffix\" -f\"$tmpdepfile\" \"$@\"\n  rm -f \"$depfile\"\n  # makedepend may prepend the VPATH from the source file name to the object.\n  # No need to regex-escape $object, excess matching of '.' is harmless.\n  sed \"s|^.*\\($object *:\\)|\\1|\" \"$tmpdepfile\" > \"$depfile\"\n  # Some versions of the HPUX 10.20 sed can't process the last invocation\n  # correctly.  Breaking it into two sed invocations is a workaround.\n  sed '1,2d' \"$tmpdepfile\" \\\n    | tr ' ' \"$nl\" \\\n    | sed -e 's/^\\\\$//' -e '/^$/d' -e '/:$/d' \\\n    | sed -e 's/$/ :/' >> \"$depfile\"\n  rm -f \"$tmpdepfile\" \"$tmpdepfile\".bak\n  ;;\n\ncpp)\n  # Important note: in order to support this mode, a compiler *must*\n  # always write the preprocessed file to stdout.\n  \"$@\" || exit $?\n\n  # Remove the call to Libtool.\n  if test \"$libtool\" = yes; then\n    while test \"X$1\" != 'X--mode=compile'; do\n      shift\n    done\n    shift\n  fi\n\n  # Remove '-o $object'.\n  IFS=\" \"\n  for arg\n  do\n    case $arg in\n    -o)\n      shift\n      ;;\n    $object)\n      shift\n      ;;\n    *)\n      set fnord \"$@\" \"$arg\"\n      shift # fnord\n      shift # $arg\n      ;;\n    esac\n  done\n\n  \"$@\" -E \\\n    | sed -n -e '/^# [0-9][0-9]* \"\\([^\"]*\\)\".*/ s:: \\1 \\\\:p' \\\n             -e '/^#line [0-9][0-9]* \"\\([^\"]*\\)\".*/ s:: \\1 \\\\:p' \\\n    | sed '$ s: \\\\$::' > \"$tmpdepfile\"\n  rm -f \"$depfile\"\n  echo \"$object : \\\\\" > \"$depfile\"\n  cat < \"$tmpdepfile\" >> \"$depfile\"\n  sed < \"$tmpdepfile\" '/^$/d;s/^ //;s/ \\\\$//;s/$/ :/' >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\nmsvisualcpp)\n  # Important note: in order to support this mode, a compiler *must*\n  # always write the preprocessed file to stdout.\n  \"$@\" || exit $?\n\n  # Remove the call to Libtool.\n  if test \"$libtool\" = yes; then\n    while test \"X$1\" != 'X--mode=compile'; do\n      shift\n    done\n    shift\n  fi\n\n  IFS=\" \"\n  for arg\n  do\n    case \"$arg\" in\n    -o)\n      shift\n      ;;\n    $object)\n      shift\n      ;;\n    \"-Gm\"|\"/Gm\"|\"-Gi\"|\"/Gi\"|\"-ZI\"|\"/ZI\")\n        set fnord \"$@\"\n        shift\n        shift\n        ;;\n    *)\n        set fnord \"$@\" \"$arg\"\n        shift\n        shift\n        ;;\n    esac\n  done\n  \"$@\" -E 2>/dev/null |\n  sed -n '/^#line [0-9][0-9]* \"\\([^\"]*\\)\"/ s::\\1:p' | $cygpath_u | sort -u > \"$tmpdepfile\"\n  rm -f \"$depfile\"\n  echo \"$object : \\\\\" > \"$depfile\"\n  sed < \"$tmpdepfile\" -n -e 's% %\\\\ %g' -e '/^\\(.*\\)$/ s::'\"$tab\"'\\1 \\\\:p' >> \"$depfile\"\n  echo \"$tab\" >> \"$depfile\"\n  sed < \"$tmpdepfile\" -n -e 's% %\\\\ %g' -e '/^\\(.*\\)$/ s::\\1\\::p' >> \"$depfile\"\n  rm -f \"$tmpdepfile\"\n  ;;\n\nmsvcmsys)\n  # This case exists only to let depend.m4 do its work.  It works by\n  # looking at the text of this script.  This case will never be run,\n  # since it is checked for above.\n  exit 1\n  ;;\n\nnone)\n  exec \"$@\"\n  ;;\n\n*)\n  echo \"Unknown depmode $depmode\" 1>&2\n  exit 1\n  ;;\nesac\n\nexit 0\n\n# Local Variables:\n# mode: shell-script\n# sh-indentation: 2\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"scriptversion=\"\n# time-stamp-format: \"%:y-%02m-%02d.%02H\"\n# time-stamp-time-zone: \"UTC\"\n# time-stamp-end: \"; # UTC\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/djpeg.1",
    "content": ".TH DJPEG 1 \"26 July 2015\"\n.SH NAME\ndjpeg \\- decompress a JPEG file to an image file\n.SH SYNOPSIS\n.B djpeg\n[\n.I options\n]\n[\n.I filename\n]\n.LP\n.SH DESCRIPTION\n.LP\n.B djpeg\ndecompresses the named JPEG file, or the standard input if no file is named,\nand produces an image file on the standard output.  PBMPLUS (PPM/PGM), BMP,\nGIF, Targa, or RLE (Utah Raster Toolkit) output format can be selected.\n(RLE is supported only if the URT library is available.)\n.SH OPTIONS\nAll switch names may be abbreviated; for example,\n.B \\-grayscale\nmay be written\n.B \\-gray\nor\n.BR \\-gr .\nMost of the \"basic\" switches can be abbreviated to as little as one letter.\nUpper and lower case are equivalent (thus\n.B \\-BMP\nis the same as\n.BR \\-bmp ).\nBritish spellings are also accepted (e.g.,\n.BR \\-greyscale ),\nthough for brevity these are not mentioned below.\n.PP\nThe basic switches are:\n.TP\n.BI \\-colors \" N\"\nReduce image to at most N colors.  This reduces the number of colors used in\nthe output image, so that it can be displayed on a colormapped display or\nstored in a colormapped file format.  For example, if you have an 8-bit\ndisplay, you'd need to reduce to 256 or fewer colors.\n.TP\n.BI \\-quantize \" N\"\nSame as\n.BR \\-colors .\n.B \\-colors\nis the recommended name,\n.B \\-quantize\nis provided only for backwards compatibility.\n.TP\n.B \\-fast\nSelect recommended processing options for fast, low quality output.  (The\ndefault options are chosen for highest quality output.)  Currently, this is\nequivalent to \\fB\\-dct fast \\-nosmooth \\-onepass \\-dither ordered\\fR.\n.TP\n.B \\-grayscale\nForce grayscale output even if JPEG file is color.\nUseful for viewing on monochrome displays; also,\n.B djpeg\nruns noticeably faster in this mode.\n.TP\n.B \\-rgb\nForce RGB output even if JPEG file is grayscale.\nThis is provided to support applications that don't\nwant to cope with grayscale as a separate case.\n.TP\n.BI \\-scale \" M/N\"\nScale the output image by a factor M/N.  Currently supported scale factors are\nM/N with all M from 1 to 16, where N is the source DCT size, which is 8 for\nbaseline JPEG.  If the /N part is omitted, then M specifies the DCT scaled\nsize to be applied on the given input.  For baseline JPEG this is equivalent\nto M/8 scaling, since the source DCT size for baseline JPEG is 8.\nScaling is handy if the image is larger than your screen; also,\n.B djpeg\nruns much faster when scaling down the output.\n.TP\n.B \\-bmp\nSelect BMP output format (Windows flavor).  8-bit colormapped format is\nemitted if\n.B \\-colors\nor\n.B \\-grayscale\nis specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color\nformat is emitted.\n.TP\n.B \\-gif\nSelect GIF output format.  Since GIF does not support more than 256 colors,\n.B \\-colors 256\nis assumed (unless you specify a smaller number of colors).\n.TP\n.B \\-os2\nSelect BMP output format (OS/2 1.x flavor).  8-bit colormapped format is\nemitted if\n.B \\-colors\nor\n.B \\-grayscale\nis specified, or if the JPEG file is grayscale; otherwise, 24-bit full-color\nformat is emitted.\n.TP\n.B \\-pnm\nSelect PBMPLUS (PPM/PGM) output format (this is the default format).\nPGM is emitted if the JPEG file is grayscale or if\n.B \\-grayscale\nis specified; otherwise PPM is emitted.\n.TP\n.B \\-rle\nSelect RLE output format.  (Requires URT library.)\n.TP\n.B \\-targa\nSelect Targa output format.  Grayscale format is emitted if the JPEG file is\ngrayscale or if\n.B \\-grayscale\nis specified; otherwise, colormapped format is emitted if\n.B \\-colors\nis specified; otherwise, 24-bit full-color format is emitted.\n.PP\nSwitches for advanced users:\n.TP\n.B \\-dct int\nUse integer DCT method (default).\n.TP\n.B \\-dct fast\nUse fast integer DCT (less accurate).\n.TP\n.B \\-dct float\nUse floating-point DCT method.\nThe float method is very slightly more accurate than the int method, but is\nmuch slower unless your machine has very fast floating-point hardware.  Also\nnote that results of the floating-point method may vary slightly across\nmachines, while the integer methods should give the same results everywhere.\nThe fast integer method is much less accurate than the other two.\n.TP\n.B \\-dither fs\nUse Floyd-Steinberg dithering in color quantization.\n.TP\n.B \\-dither ordered\nUse ordered dithering in color quantization.\n.TP\n.B \\-dither none\nDo not use dithering in color quantization.\nBy default, Floyd-Steinberg dithering is applied when quantizing colors; this\nis slow but usually produces the best results.  Ordered dither is a compromise\nbetween speed and quality; no dithering is fast but usually looks awful.  Note\nthat these switches have no effect unless color quantization is being done.\nOrdered dither is only available in\n.B \\-onepass\nmode.\n.TP\n.BI \\-map \" file\"\nQuantize to the colors used in the specified image file.  This is useful for\nproducing multiple files with identical color maps, or for forcing a\npredefined set of colors to be used.  The\n.I file\nmust be a GIF or PPM file. This option overrides\n.B \\-colors\nand\n.BR \\-onepass .\n.TP\n.B \\-nosmooth\nDon't use high-quality upsampling.\n.TP\n.B \\-onepass\nUse one-pass instead of two-pass color quantization.  The one-pass method is\nfaster and needs less memory, but it produces a lower-quality image.\n.B \\-onepass\nis ignored unless you also say\n.B \\-colors\n.IR N .\nAlso, the one-pass method is always used for grayscale output (the two-pass\nmethod is no improvement then).\n.TP\n.BI \\-maxmemory \" N\"\nSet limit for amount of memory to use in processing large images.  Value is\nin thousands of bytes, or millions of bytes if \"M\" is attached to the\nnumber.  For example,\n.B \\-max 4m\nselects 4000000 bytes.  If more space is needed, temporary files will be used.\n.TP\n.BI \\-outfile \" name\"\nSend output image to the named file, not to standard output.\n.TP\n.B \\-verbose\nEnable debug printout.  More\n.BR \\-v 's\ngive more output.  Also, version information is printed at startup.\n.TP\n.B \\-debug\nSame as\n.BR \\-verbose .\n.SH EXAMPLES\n.LP\nThis example decompresses the JPEG file foo.jpg, quantizes it to\n256 colors, and saves the output in 8-bit BMP format in foo.bmp:\n.IP\n.B djpeg \\-colors 256 \\-bmp\n.I foo.jpg\n.B >\n.I foo.bmp\n.SH HINTS\nTo get a quick preview of an image, use the\n.B \\-grayscale\nand/or\n.B \\-scale\nswitches.\n.B \\-grayscale \\-scale 1/8\nis the fastest case.\n.PP\nSeveral options are available that trade off image quality to gain speed.\n.B \\-fast\nturns on the recommended settings.\n.PP\n.B \\-dct fast\nand/or\n.B \\-nosmooth\ngain speed at a small sacrifice in quality.\nWhen producing a color-quantized image,\n.B \\-onepass \\-dither ordered\nis fast but much lower quality than the default behavior.\n.B \\-dither none\nmay give acceptable results in two-pass mode, but is seldom tolerable in\none-pass mode.\n.PP\nIf you are fortunate enough to have very fast floating point hardware,\n\\fB\\-dct float\\fR may be even faster than \\fB\\-dct fast\\fR.  But on most\nmachines \\fB\\-dct float\\fR is slower than \\fB\\-dct int\\fR; in this case it is\nnot worth using, because its theoretical accuracy advantage is too small to be\nsignificant in practice.\n.SH ENVIRONMENT\n.TP\n.B JPEGMEM\nIf this environment variable is set, its value is the default memory limit.\nThe value is specified as described for the\n.B \\-maxmemory\nswitch.\n.B JPEGMEM\noverrides the default value specified when the program was compiled, and\nitself is overridden by an explicit\n.BR \\-maxmemory .\n.SH SEE ALSO\n.BR cjpeg (1),\n.BR jpegtran (1),\n.BR rdjpgcom (1),\n.BR wrjpgcom (1)\n.br\n.BR ppm (5),\n.BR pgm (5)\n.br\nWallace, Gregory K.  \"The JPEG Still Picture Compression Standard\",\nCommunications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.\n.SH AUTHOR\nIndependent JPEG Group\n.SH BUGS\nTo avoid the Unisys LZW patent (now expired),\n.B djpeg\nproduces uncompressed GIF files.  These are larger than they should be, but\nare readable by standard GIF decoders.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/djpeg.c",
    "content": "/*\n * djpeg.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2009-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a command-line user interface for the JPEG decompressor.\n * It should work on any system with Unix- or MS-DOS-style command lines.\n *\n * Two different command line styles are permitted, depending on the\n * compile-time switch TWO_FILE_COMMANDLINE:\n *\tdjpeg [options]  inputfile outputfile\n *\tdjpeg [options]  [inputfile]\n * In the second style, output is always to standard output, which you'd\n * normally redirect to a file or pipe to some other program.  Input is\n * either from a named file or from standard input (typically redirected).\n * The second style is convenient on Unix but is unhelpful on systems that\n * don't support pipes.  Also, you MUST use the first style if your system\n * doesn't do binary I/O to stdin/stdout.\n * To simplify script writing, the \"-outfile\" switch is provided.  The syntax\n *\tdjpeg [options]  -outfile outputfile  inputfile\n * works regardless of which command line style is used.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n#include \"jversion.h\"\t\t/* for version message */\n\n#include <ctype.h>\t\t/* to declare isprint() */\n\n#ifdef USE_CCOMMAND\t\t/* command-line reader for Macintosh */\n#ifdef __MWERKS__\n#include <SIOUX.h>              /* Metrowerks needs this */\n#include <console.h>\t\t/* ... and this */\n#endif\n#ifdef THINK_C\n#include <console.h>\t\t/* Think declares it here */\n#endif\n#endif\n\n\n/* Create the add-on message string table. */\n\n#define JMESSAGE(code,string)\tstring ,\n\nstatic const char * const cdjpeg_message_table[] = {\n#include \"cderror.h\"\n  NULL\n};\n\n\n/*\n * This list defines the known output image formats\n * (not all of which need be supported by a given version).\n * You can change the default output format by defining DEFAULT_FMT;\n * indeed, you had better do so if you undefine PPM_SUPPORTED.\n */\n\ntypedef enum {\n\tFMT_BMP,\t\t/* BMP format (Windows flavor) */\n\tFMT_GIF,\t\t/* GIF format */\n\tFMT_OS2,\t\t/* BMP format (OS/2 flavor) */\n\tFMT_PPM,\t\t/* PPM/PGM (PBMPLUS formats) */\n\tFMT_RLE,\t\t/* RLE format */\n\tFMT_TARGA,\t\t/* Targa format */\n\tFMT_TIFF\t\t/* TIFF format */\n} IMAGE_FORMATS;\n\n#ifndef DEFAULT_FMT\t\t/* so can override from CFLAGS in Makefile */\n#define DEFAULT_FMT\tFMT_PPM\n#endif\n\nstatic IMAGE_FORMATS requested_fmt;\n\n\n/*\n * Argument-parsing code.\n * The switch parser is designed to be useful with DOS-style command line\n * syntax, ie, intermixed switches and file names, where only the switches\n * to the left of a given file name affect processing of that file.\n * The main program in this file doesn't actually use this capability...\n */\n\n\nstatic const char * progname;\t/* program name for error messages */\nstatic char * outfilename;\t/* for -outfile switch */\n\n\nLOCAL(void)\nusage (void)\n/* complain about bad command line */\n{\n  fprintf(stderr, \"usage: %s [switches] \", progname);\n#ifdef TWO_FILE_COMMANDLINE\n  fprintf(stderr, \"inputfile outputfile\\n\");\n#else\n  fprintf(stderr, \"[inputfile]\\n\");\n#endif\n\n  fprintf(stderr, \"Switches (names may be abbreviated):\\n\");\n  fprintf(stderr, \"  -colors N      Reduce image to no more than N colors\\n\");\n  fprintf(stderr, \"  -fast          Fast, low-quality processing\\n\");\n  fprintf(stderr, \"  -grayscale     Force grayscale output\\n\");\n  fprintf(stderr, \"  -rgb           Force RGB output\\n\");\n#ifdef IDCT_SCALING_SUPPORTED\n  fprintf(stderr, \"  -scale M/N     Scale output image by fraction M/N, eg, 1/8\\n\");\n#endif\n#ifdef BMP_SUPPORTED\n  fprintf(stderr, \"  -bmp           Select BMP output format (Windows style)%s\\n\",\n\t  (DEFAULT_FMT == FMT_BMP ? \" (default)\" : \"\"));\n#endif\n#ifdef GIF_SUPPORTED\n  fprintf(stderr, \"  -gif           Select GIF output format%s\\n\",\n\t  (DEFAULT_FMT == FMT_GIF ? \" (default)\" : \"\"));\n#endif\n#ifdef BMP_SUPPORTED\n  fprintf(stderr, \"  -os2           Select BMP output format (OS/2 style)%s\\n\",\n\t  (DEFAULT_FMT == FMT_OS2 ? \" (default)\" : \"\"));\n#endif\n#ifdef PPM_SUPPORTED\n  fprintf(stderr, \"  -pnm           Select PBMPLUS (PPM/PGM) output format%s\\n\",\n\t  (DEFAULT_FMT == FMT_PPM ? \" (default)\" : \"\"));\n#endif\n#ifdef RLE_SUPPORTED\n  fprintf(stderr, \"  -rle           Select Utah RLE output format%s\\n\",\n\t  (DEFAULT_FMT == FMT_RLE ? \" (default)\" : \"\"));\n#endif\n#ifdef TARGA_SUPPORTED\n  fprintf(stderr, \"  -targa         Select Targa output format%s\\n\",\n\t  (DEFAULT_FMT == FMT_TARGA ? \" (default)\" : \"\"));\n#endif\n  fprintf(stderr, \"Switches for advanced users:\\n\");\n#ifdef DCT_ISLOW_SUPPORTED\n  fprintf(stderr, \"  -dct int       Use integer DCT method%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_ISLOW ? \" (default)\" : \"\"));\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n  fprintf(stderr, \"  -dct fast      Use fast integer DCT (less accurate)%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_IFAST ? \" (default)\" : \"\"));\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n  fprintf(stderr, \"  -dct float     Use floating-point DCT method%s\\n\",\n\t  (JDCT_DEFAULT == JDCT_FLOAT ? \" (default)\" : \"\"));\n#endif\n  fprintf(stderr, \"  -dither fs     Use F-S dithering (default)\\n\");\n  fprintf(stderr, \"  -dither none   Don't use dithering in quantization\\n\");\n  fprintf(stderr, \"  -dither ordered  Use ordered dither (medium speed, quality)\\n\");\n#ifdef QUANT_2PASS_SUPPORTED\n  fprintf(stderr, \"  -map FILE      Map to colors used in named image file\\n\");\n#endif\n  fprintf(stderr, \"  -nosmooth      Don't use high-quality upsampling\\n\");\n#ifdef QUANT_1PASS_SUPPORTED\n  fprintf(stderr, \"  -onepass       Use 1-pass quantization (fast, low quality)\\n\");\n#endif\n  fprintf(stderr, \"  -maxmemory N   Maximum memory to use (in kbytes)\\n\");\n  fprintf(stderr, \"  -outfile name  Specify name for output file\\n\");\n  fprintf(stderr, \"  -verbose  or  -debug   Emit debug output\\n\");\n  exit(EXIT_FAILURE);\n}\n\n\nLOCAL(int)\nparse_switches (j_decompress_ptr cinfo, int argc, char **argv,\n\t\tint last_file_arg_seen, boolean for_real)\n/* Parse optional switches.\n * Returns argv[] index of first file-name argument (== argc if none).\n * Any file names with indexes <= last_file_arg_seen are ignored;\n * they have presumably been processed in a previous iteration.\n * (Pass 0 for last_file_arg_seen on the first or only iteration.)\n * for_real is FALSE on the first (dummy) pass; we may skip any expensive\n * processing.\n */\n{\n  int argn;\n  char * arg;\n\n  /* Set up default JPEG parameters. */\n  requested_fmt = DEFAULT_FMT;\t/* set default output file format */\n  outfilename = NULL;\n  cinfo->err->trace_level = 0;\n\n  /* Scan command line options, adjust parameters */\n\n  for (argn = 1; argn < argc; argn++) {\n    arg = argv[argn];\n    if (*arg != '-') {\n      /* Not a switch, must be a file name argument */\n      if (argn <= last_file_arg_seen) {\n\toutfilename = NULL;\t/* -outfile applies to just one input file */\n\tcontinue;\t\t/* ignore this name if previously processed */\n      }\n      break;\t\t\t/* else done parsing switches */\n    }\n    arg++;\t\t\t/* advance past switch marker character */\n\n    if (keymatch(arg, \"bmp\", 1)) {\n      /* BMP output format. */\n      requested_fmt = FMT_BMP;\n\n    } else if (keymatch(arg, \"colors\", 1) || keymatch(arg, \"colours\", 1) ||\n\t       keymatch(arg, \"quantize\", 1) || keymatch(arg, \"quantise\", 1)) {\n      /* Do color quantization. */\n      int val;\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%d\", &val) != 1)\n\tusage();\n      cinfo->desired_number_of_colors = val;\n      cinfo->quantize_colors = TRUE;\n\n    } else if (keymatch(arg, \"dct\", 2)) {\n      /* Select IDCT algorithm. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"int\", 1)) {\n\tcinfo->dct_method = JDCT_ISLOW;\n      } else if (keymatch(argv[argn], \"fast\", 2)) {\n\tcinfo->dct_method = JDCT_IFAST;\n      } else if (keymatch(argv[argn], \"float\", 2)) {\n\tcinfo->dct_method = JDCT_FLOAT;\n      } else\n\tusage();\n\n    } else if (keymatch(arg, \"dither\", 2)) {\n      /* Select dithering algorithm. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"fs\", 2)) {\n\tcinfo->dither_mode = JDITHER_FS;\n      } else if (keymatch(argv[argn], \"none\", 2)) {\n\tcinfo->dither_mode = JDITHER_NONE;\n      } else if (keymatch(argv[argn], \"ordered\", 2)) {\n\tcinfo->dither_mode = JDITHER_ORDERED;\n      } else\n\tusage();\n\n    } else if (keymatch(arg, \"debug\", 1) || keymatch(arg, \"verbose\", 1)) {\n      /* Enable debug printouts. */\n      /* On first -d, print version identification */\n      static boolean printed_version = FALSE;\n\n      if (! printed_version) {\n\tfprintf(stderr, \"Independent JPEG Group's DJPEG, version %s\\n%s\\n\",\n\t\tJVERSION, JCOPYRIGHT);\n\tprinted_version = TRUE;\n      }\n      cinfo->err->trace_level++;\n\n    } else if (keymatch(arg, \"fast\", 1)) {\n      /* Select recommended processing options for quick-and-dirty output. */\n      cinfo->two_pass_quantize = FALSE;\n      cinfo->dither_mode = JDITHER_ORDERED;\n      if (! cinfo->quantize_colors) /* don't override an earlier -colors */\n\tcinfo->desired_number_of_colors = 216;\n      cinfo->dct_method = JDCT_FASTEST;\n      cinfo->do_fancy_upsampling = FALSE;\n\n    } else if (keymatch(arg, \"gif\", 1)) {\n      /* GIF output format. */\n      requested_fmt = FMT_GIF;\n\n    } else if (keymatch(arg, \"grayscale\", 2) || keymatch(arg, \"greyscale\",2)) {\n      /* Force monochrome output. */\n      cinfo->out_color_space = JCS_GRAYSCALE;\n\n    } else if (keymatch(arg, \"rgb\", 3)) {\n      /* Force RGB output. */\n      cinfo->out_color_space = JCS_RGB;\n\n    } else if (keymatch(arg, \"map\", 3)) {\n      /* Quantize to a color map taken from an input file. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (for_real) {\t\t/* too expensive to do twice! */\n#ifdef QUANT_2PASS_SUPPORTED\t/* otherwise can't quantize to supplied map */\n\tFILE * mapfile;\n\n\tif ((mapfile = fopen(argv[argn], READ_BINARY)) == NULL) {\n\t  fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n\t  exit(EXIT_FAILURE);\n\t}\n\tread_color_map(cinfo, mapfile);\n\tfclose(mapfile);\n\tcinfo->quantize_colors = TRUE;\n#else\n\tERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n      }\n\n    } else if (keymatch(arg, \"maxmemory\", 3)) {\n      /* Maximum memory in Kb (or Mb with 'm'). */\n      long lval;\n      char ch = 'x';\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%ld%c\", &lval, &ch) < 1)\n\tusage();\n      if (ch == 'm' || ch == 'M')\n\tlval *= 1000L;\n      cinfo->mem->max_memory_to_use = lval * 1000L;\n\n    } else if (keymatch(arg, \"nosmooth\", 3)) {\n      /* Suppress fancy upsampling. */\n      cinfo->do_fancy_upsampling = FALSE;\n\n    } else if (keymatch(arg, \"onepass\", 3)) {\n      /* Use fast one-pass quantization. */\n      cinfo->two_pass_quantize = FALSE;\n\n    } else if (keymatch(arg, \"os2\", 3)) {\n      /* BMP output format (OS/2 flavor). */\n      requested_fmt = FMT_OS2;\n\n    } else if (keymatch(arg, \"outfile\", 4)) {\n      /* Set output file name. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      outfilename = argv[argn];\t/* save it away for later use */\n\n    } else if (keymatch(arg, \"pnm\", 1) || keymatch(arg, \"ppm\", 1)) {\n      /* PPM/PGM output format. */\n      requested_fmt = FMT_PPM;\n\n    } else if (keymatch(arg, \"rle\", 1)) {\n      /* RLE output format. */\n      requested_fmt = FMT_RLE;\n\n    } else if (keymatch(arg, \"scale\", 1)) {\n      /* Scale the output image by a fraction M/N. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%u/%u\",\n\t\t &cinfo->scale_num, &cinfo->scale_denom) < 1)\n\tusage();\n\n    } else if (keymatch(arg, \"targa\", 1)) {\n      /* Targa output format. */\n      requested_fmt = FMT_TARGA;\n\n    } else {\n      usage();\t\t\t/* bogus switch */\n    }\n  }\n\n  return argn;\t\t\t/* return index of next arg (file name) */\n}\n\n\n/*\n * Marker processor for COM and interesting APPn markers.\n * This replaces the library's built-in processor, which just skips the marker.\n * We want to print out the marker as text, to the extent possible.\n * Note this code relies on a non-suspending data source.\n */\n\nLOCAL(unsigned int)\njpeg_getc (j_decompress_ptr cinfo)\n/* Read next byte */\n{\n  struct jpeg_source_mgr * datasrc = cinfo->src;\n\n  if (datasrc->bytes_in_buffer == 0) {\n    if (! (*datasrc->fill_input_buffer) (cinfo))\n      ERREXIT(cinfo, JERR_CANT_SUSPEND);\n  }\n  datasrc->bytes_in_buffer--;\n  return GETJOCTET(*datasrc->next_input_byte++);\n}\n\n\nMETHODDEF(boolean)\nprint_text_marker (j_decompress_ptr cinfo)\n{\n  boolean traceit = (cinfo->err->trace_level >= 1);\n  INT32 length;\n  unsigned int ch;\n  unsigned int lastch = 0;\n\n  length = jpeg_getc(cinfo) << 8;\n  length += jpeg_getc(cinfo);\n  length -= 2;\t\t\t/* discount the length word itself */\n\n  if (traceit) {\n    if (cinfo->unread_marker == JPEG_COM)\n      fprintf(stderr, \"Comment, length %ld:\\n\", (long) length);\n    else\t\t\t/* assume it is an APPn otherwise */\n      fprintf(stderr, \"APP%d, length %ld:\\n\",\n\t      cinfo->unread_marker - JPEG_APP0, (long) length);\n  }\n\n  while (--length >= 0) {\n    ch = jpeg_getc(cinfo);\n    if (traceit) {\n      /* Emit the character in a readable form.\n       * Nonprintables are converted to \\nnn form,\n       * while \\ is converted to \\\\.\n       * Newlines in CR, CR/LF, or LF form will be printed as one newline.\n       */\n      if (ch == '\\r') {\n\tfprintf(stderr, \"\\n\");\n      } else if (ch == '\\n') {\n\tif (lastch != '\\r')\n\t  fprintf(stderr, \"\\n\");\n      } else if (ch == '\\\\') {\n\tfprintf(stderr, \"\\\\\\\\\");\n      } else if (isprint(ch)) {\n\tputc(ch, stderr);\n      } else {\n\tfprintf(stderr, \"\\\\%03o\", ch);\n      }\n      lastch = ch;\n    }\n  }\n\n  if (traceit)\n    fprintf(stderr, \"\\n\");\n\n  return TRUE;\n}\n\n\n/*\n * The main program.\n */\n\nint\nmain (int argc, char **argv)\n{\n  struct jpeg_decompress_struct cinfo;\n  struct jpeg_error_mgr jerr;\n#ifdef PROGRESS_REPORT\n  struct cdjpeg_progress_mgr progress;\n#endif\n  int file_index;\n  djpeg_dest_ptr dest_mgr = NULL;\n  FILE * input_file;\n  FILE * output_file;\n  JDIMENSION num_scanlines;\n\n  /* On Mac, fetch a command line. */\n#ifdef USE_CCOMMAND\n  argc = ccommand(&argv);\n#endif\n\n  progname = argv[0];\n  if (progname == NULL || progname[0] == 0)\n    progname = \"djpeg\";\t\t/* in case C library doesn't provide it */\n\n  /* Initialize the JPEG decompression object with default error handling. */\n  cinfo.err = jpeg_std_error(&jerr);\n  jpeg_create_decompress(&cinfo);\n  /* Add some application-specific error messages (from cderror.h) */\n  jerr.addon_message_table = cdjpeg_message_table;\n  jerr.first_addon_message = JMSG_FIRSTADDONCODE;\n  jerr.last_addon_message = JMSG_LASTADDONCODE;\n\n  /* Insert custom marker processor for COM and APP12.\n   * APP12 is used by some digital camera makers for textual info,\n   * so we provide the ability to display it as text.\n   * If you like, additional APPn marker types can be selected for display,\n   * but don't try to override APP0 or APP14 this way (see libjpeg.doc).\n   */\n  jpeg_set_marker_processor(&cinfo, JPEG_COM, print_text_marker);\n  jpeg_set_marker_processor(&cinfo, JPEG_APP0+12, print_text_marker);\n\n  /* Now safe to enable signal catcher. */\n#ifdef NEED_SIGNAL_CATCHER\n  enable_signal_catcher((j_common_ptr) &cinfo);\n#endif\n\n  /* Scan command line to find file names. */\n  /* It is convenient to use just one switch-parsing routine, but the switch\n   * values read here are ignored; we will rescan the switches after opening\n   * the input file.\n   * (Exception: tracing level set here controls verbosity for COM markers\n   * found during jpeg_read_header...)\n   */\n\n  file_index = parse_switches(&cinfo, argc, argv, 0, FALSE);\n\n#ifdef TWO_FILE_COMMANDLINE\n  /* Must have either -outfile switch or explicit output file name */\n  if (outfilename == NULL) {\n    if (file_index != argc-2) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n    outfilename = argv[file_index+1];\n  } else {\n    if (file_index != argc-1) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n  }\n#else\n  /* Unix style: expect zero or one file name */\n  if (file_index < argc-1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Open the input file. */\n  if (file_index < argc) {\n    if ((input_file = fopen(argv[file_index], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[file_index]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n    input_file = read_stdin();\n  }\n\n  /* Open the output file. */\n  if (outfilename != NULL) {\n    if ((output_file = fopen(outfilename, WRITE_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, outfilename);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default output file is stdout */\n    output_file = write_stdout();\n  }\n\n#ifdef PROGRESS_REPORT\n  start_progress_monitor((j_common_ptr) &cinfo, &progress);\n#endif\n\n  /* Specify data source for decompression */\n  jpeg_stdio_src(&cinfo, input_file);\n\n  /* Read file header, set default decompression parameters */\n  (void) jpeg_read_header(&cinfo, TRUE);\n\n  /* Adjust default decompression parameters by re-parsing the options */\n  file_index = parse_switches(&cinfo, argc, argv, 0, TRUE);\n\n  /* Initialize the output module now to let it override any crucial\n   * option settings (for instance, GIF wants to force color quantization).\n   */\n  switch (requested_fmt) {\n#ifdef BMP_SUPPORTED\n  case FMT_BMP:\n    dest_mgr = jinit_write_bmp(&cinfo, FALSE);\n    break;\n  case FMT_OS2:\n    dest_mgr = jinit_write_bmp(&cinfo, TRUE);\n    break;\n#endif\n#ifdef GIF_SUPPORTED\n  case FMT_GIF:\n    dest_mgr = jinit_write_gif(&cinfo);\n    break;\n#endif\n#ifdef PPM_SUPPORTED\n  case FMT_PPM:\n    dest_mgr = jinit_write_ppm(&cinfo);\n    break;\n#endif\n#ifdef RLE_SUPPORTED\n  case FMT_RLE:\n    dest_mgr = jinit_write_rle(&cinfo);\n    break;\n#endif\n#ifdef TARGA_SUPPORTED\n  case FMT_TARGA:\n    dest_mgr = jinit_write_targa(&cinfo);\n    break;\n#endif\n  default:\n    ERREXIT(&cinfo, JERR_UNSUPPORTED_FORMAT);\n    break;\n  }\n  dest_mgr->output_file = output_file;\n\n  /* Start decompressor */\n  (void) jpeg_start_decompress(&cinfo);\n\n  /* Write output file header */\n  (*dest_mgr->start_output) (&cinfo, dest_mgr);\n\n  /* Process data */\n  while (cinfo.output_scanline < cinfo.output_height) {\n    num_scanlines = jpeg_read_scanlines(&cinfo, dest_mgr->buffer,\n\t\t\t\t\tdest_mgr->buffer_height);\n    (*dest_mgr->put_pixel_rows) (&cinfo, dest_mgr, num_scanlines);\n  }\n\n#ifdef PROGRESS_REPORT\n  /* Hack: count final pass as done in case finish_output does an extra pass.\n   * The library won't have updated completed_passes.\n   */\n  progress.pub.completed_passes = progress.pub.total_passes;\n#endif\n\n  /* Finish decompression and release memory.\n   * I must do it in this order because output module has allocated memory\n   * of lifespan JPOOL_IMAGE; it needs to finish before releasing memory.\n   */\n  (*dest_mgr->finish_output) (&cinfo, dest_mgr);\n  (void) jpeg_finish_decompress(&cinfo);\n  jpeg_destroy_decompress(&cinfo);\n\n  /* Close files, if we opened them */\n  if (input_file != stdin)\n    fclose(input_file);\n  if (output_file != stdout)\n    fclose(output_file);\n\n#ifdef PROGRESS_REPORT\n  end_progress_monitor((j_common_ptr) &cinfo);\n#endif\n\n  /* All done. */\n  exit(jerr.num_warnings ? EXIT_WARNING : EXIT_SUCCESS);\n  return 0;\t\t\t/* suppress no-return-value warnings */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/example.c",
    "content": "/*\n * example.c\n *\n * This file illustrates how to use the IJG code as a subroutine library\n * to read or write JPEG image files.  You should look at this code in\n * conjunction with the documentation file libjpeg.txt.\n *\n * This code will not do anything useful as-is, but it may be helpful as a\n * skeleton for constructing routines that call the JPEG library.  \n *\n * We present these routines in the same coding style used in the JPEG code\n * (ANSI function definitions, etc); but you are of course free to code your\n * routines in a different style if you prefer.\n */\n\n#include <stdio.h>\n\n/*\n * Include file for users of JPEG library.\n * You will need to have included system headers that define at least\n * the typedefs FILE and size_t before you can include jpeglib.h.\n * (stdio.h is sufficient on ANSI-conforming systems.)\n * You may also wish to include \"jerror.h\".\n */\n\n#include \"jpeglib.h\"\n\n/*\n * <setjmp.h> is used for the optional error recovery mechanism shown in\n * the second part of the example.\n */\n\n#include <setjmp.h>\n\n\n\n/******************** JPEG COMPRESSION SAMPLE INTERFACE *******************/\n\n/* This half of the example shows how to feed data into the JPEG compressor.\n * We present a minimal version that does not worry about refinements such\n * as error recovery (the JPEG code will just exit() if it gets an error).\n */\n\n\n/*\n * IMAGE DATA FORMATS:\n *\n * The standard input image format is a rectangular array of pixels, with\n * each pixel having the same number of \"component\" values (color channels).\n * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).\n * If you are working with color data, then the color values for each pixel\n * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit\n * RGB color.\n *\n * For this example, we'll assume that this data structure matches the way\n * our application has stored the image in memory, so we can just pass a\n * pointer to our image buffer.  In particular, let's say that the image is\n * RGB color and is described by:\n */\n\nextern JSAMPLE * image_buffer;\t/* Points to large array of R,G,B-order data */\nextern int image_height;\t/* Number of rows in image */\nextern int image_width;\t\t/* Number of columns in image */\n\n\n/*\n * Sample routine for JPEG compression.  We assume that the target file name\n * and a compression quality factor are passed in.\n */\n\nGLOBAL(void)\nwrite_JPEG_file (char * filename, int quality)\n{\n  /* This struct contains the JPEG compression parameters and pointers to\n   * working space (which is allocated as needed by the JPEG library).\n   * It is possible to have several such structures, representing multiple\n   * compression/decompression processes, in existence at once.  We refer\n   * to any one struct (and its associated working data) as a \"JPEG object\".\n   */\n  struct jpeg_compress_struct cinfo;\n  /* This struct represents a JPEG error handler.  It is declared separately\n   * because applications often want to supply a specialized error handler\n   * (see the second half of this file for an example).  But here we just\n   * take the easy way out and use the standard error handler, which will\n   * print a message on stderr and call exit() if compression fails.\n   * Note that this struct must live as long as the main JPEG parameter\n   * struct, to avoid dangling-pointer problems.\n   */\n  struct jpeg_error_mgr jerr;\n  /* More stuff */\n  FILE * outfile;\t\t/* target file */\n  JSAMPROW row_pointer[1];\t/* pointer to JSAMPLE row[s] */\n  int row_stride;\t\t/* physical row width in image buffer */\n\n  /* Step 1: allocate and initialize JPEG compression object */\n\n  /* We have to set up the error handler first, in case the initialization\n   * step fails.  (Unlikely, but it could happen if you are out of memory.)\n   * This routine fills in the contents of struct jerr, and returns jerr's\n   * address which we place into the link field in cinfo.\n   */\n  cinfo.err = jpeg_std_error(&jerr);\n  /* Now we can initialize the JPEG compression object. */\n  jpeg_create_compress(&cinfo);\n\n  /* Step 2: specify data destination (eg, a file) */\n  /* Note: steps 2 and 3 can be done in either order. */\n\n  /* Here we use the library-supplied code to send compressed data to a\n   * stdio stream.  You can also write your own code to do something else.\n   * VERY IMPORTANT: use \"b\" option to fopen() if you are on a machine that\n   * requires it in order to write binary files.\n   */\n  if ((outfile = fopen(filename, \"wb\")) == NULL) {\n    fprintf(stderr, \"can't open %s\\n\", filename);\n    exit(1);\n  }\n  jpeg_stdio_dest(&cinfo, outfile);\n\n  /* Step 3: set parameters for compression */\n\n  /* First we supply a description of the input image.\n   * Four fields of the cinfo struct must be filled in:\n   */\n  cinfo.image_width = image_width; \t/* image width and height, in pixels */\n  cinfo.image_height = image_height;\n  cinfo.input_components = 3;\t\t/* # of color components per pixel */\n  cinfo.in_color_space = JCS_RGB; \t/* colorspace of input image */\n  /* Now use the library's routine to set default compression parameters.\n   * (You must set at least cinfo.in_color_space before calling this,\n   * since the defaults depend on the source color space.)\n   */\n  jpeg_set_defaults(&cinfo);\n  /* Now you can set any non-default parameters you wish to.\n   * Here we just illustrate the use of quality (quantization table) scaling:\n   */\n  jpeg_set_quality(&cinfo, quality, TRUE /* limit to baseline-JPEG values */);\n\n  /* Step 4: Start compressor */\n\n  /* TRUE ensures that we will write a complete interchange-JPEG file.\n   * Pass TRUE unless you are very sure of what you're doing.\n   */\n  jpeg_start_compress(&cinfo, TRUE);\n\n  /* Step 5: while (scan lines remain to be written) */\n  /*           jpeg_write_scanlines(...); */\n\n  /* Here we use the library's state variable cinfo.next_scanline as the\n   * loop counter, so that we don't have to keep track ourselves.\n   * To keep things simple, we pass one scanline per call; you can pass\n   * more if you wish, though.\n   */\n  row_stride = image_width * 3;\t/* JSAMPLEs per row in image_buffer */\n\n  while (cinfo.next_scanline < cinfo.image_height) {\n    /* jpeg_write_scanlines expects an array of pointers to scanlines.\n     * Here the array is only one element long, but you could pass\n     * more than one scanline at a time if that's more convenient.\n     */\n    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];\n    (void) jpeg_write_scanlines(&cinfo, row_pointer, 1);\n  }\n\n  /* Step 6: Finish compression */\n\n  jpeg_finish_compress(&cinfo);\n  /* After finish_compress, we can close the output file. */\n  fclose(outfile);\n\n  /* Step 7: release JPEG compression object */\n\n  /* This is an important step since it will release a good deal of memory. */\n  jpeg_destroy_compress(&cinfo);\n\n  /* And we're done! */\n}\n\n\n/*\n * SOME FINE POINTS:\n *\n * In the above loop, we ignored the return value of jpeg_write_scanlines,\n * which is the number of scanlines actually written.  We could get away\n * with this because we were only relying on the value of cinfo.next_scanline,\n * which will be incremented correctly.  If you maintain additional loop\n * variables then you should be careful to increment them properly.\n * Actually, for output to a stdio stream you needn't worry, because\n * then jpeg_write_scanlines will write all the lines passed (or else exit\n * with a fatal error).  Partial writes can only occur if you use a data\n * destination module that can demand suspension of the compressor.\n * (If you don't know what that's for, you don't need it.)\n *\n * If the compressor requires full-image buffers (for entropy-coding\n * optimization or a multi-scan JPEG file), it will create temporary\n * files for anything that doesn't fit within the maximum-memory setting.\n * (Note that temp files are NOT needed if you use the default parameters.)\n * On some systems you may need to set up a signal handler to ensure that\n * temporary files are deleted if the program is interrupted.  See libjpeg.txt.\n *\n * Scanlines MUST be supplied in top-to-bottom order if you want your JPEG\n * files to be compatible with everyone else's.  If you cannot readily read\n * your data in that order, you'll need an intermediate array to hold the\n * image.  See rdtarga.c or rdbmp.c for examples of handling bottom-to-top\n * source data using the JPEG code's internal virtual-array mechanisms.\n */\n\n\n\n/******************** JPEG DECOMPRESSION SAMPLE INTERFACE *******************/\n\n/* This half of the example shows how to read data from the JPEG decompressor.\n * It's a bit more refined than the above, in that we show:\n *   (a) how to modify the JPEG library's standard error-reporting behavior;\n *   (b) how to allocate workspace using the library's memory manager.\n *\n * Just to make this example a little different from the first one, we'll\n * assume that we do not intend to put the whole image into an in-memory\n * buffer, but to send it line-by-line someplace else.  We need a one-\n * scanline-high JSAMPLE array as a work buffer, and we will let the JPEG\n * memory manager allocate it for us.  This approach is actually quite useful\n * because we don't need to remember to deallocate the buffer separately: it\n * will go away automatically when the JPEG object is cleaned up.\n */\n\n\n/*\n * ERROR HANDLING:\n *\n * The JPEG library's standard error handler (jerror.c) is divided into\n * several \"methods\" which you can override individually.  This lets you\n * adjust the behavior without duplicating a lot of code, which you might\n * have to update with each future release.\n *\n * Our example here shows how to override the \"error_exit\" method so that\n * control is returned to the library's caller when a fatal error occurs,\n * rather than calling exit() as the standard error_exit method does.\n *\n * We use C's setjmp/longjmp facility to return control.  This means that the\n * routine which calls the JPEG library must first execute a setjmp() call to\n * establish the return point.  We want the replacement error_exit to do a\n * longjmp().  But we need to make the setjmp buffer accessible to the\n * error_exit routine.  To do this, we make a private extension of the\n * standard JPEG error handler object.  (If we were using C++, we'd say we\n * were making a subclass of the regular error handler.)\n *\n * Here's the extended error handler struct:\n */\n\nstruct my_error_mgr {\n  struct jpeg_error_mgr pub;\t/* \"public\" fields */\n\n  jmp_buf setjmp_buffer;\t/* for return to caller */\n};\n\ntypedef struct my_error_mgr * my_error_ptr;\n\n/*\n * Here's the routine that will replace the standard error_exit method:\n */\n\nMETHODDEF(void)\nmy_error_exit (j_common_ptr cinfo)\n{\n  /* cinfo->err really points to a my_error_mgr struct, so coerce pointer */\n  my_error_ptr myerr = (my_error_ptr) cinfo->err;\n\n  /* Always display the message. */\n  /* We could postpone this until after returning, if we chose. */\n  (*cinfo->err->output_message) (cinfo);\n\n  /* Return control to the setjmp point */\n  longjmp(myerr->setjmp_buffer, 1);\n}\n\n\n/*\n * Sample routine for JPEG decompression.  We assume that the source file name\n * is passed in.  We want to return 1 on success, 0 on error.\n */\n\n\nGLOBAL(int)\nread_JPEG_file (char * filename)\n{\n  /* This struct contains the JPEG decompression parameters and pointers to\n   * working space (which is allocated as needed by the JPEG library).\n   */\n  struct jpeg_decompress_struct cinfo;\n  /* We use our private extension JPEG error handler.\n   * Note that this struct must live as long as the main JPEG parameter\n   * struct, to avoid dangling-pointer problems.\n   */\n  struct my_error_mgr jerr;\n  /* More stuff */\n  FILE * infile;\t\t/* source file */\n  JSAMPARRAY buffer;\t\t/* Output row buffer */\n  int row_stride;\t\t/* physical row width in output buffer */\n\n  /* In this example we want to open the input file before doing anything else,\n   * so that the setjmp() error recovery below can assume the file is open.\n   * VERY IMPORTANT: use \"b\" option to fopen() if you are on a machine that\n   * requires it in order to read binary files.\n   */\n\n  if ((infile = fopen(filename, \"rb\")) == NULL) {\n    fprintf(stderr, \"can't open %s\\n\", filename);\n    return 0;\n  }\n\n  /* Step 1: allocate and initialize JPEG decompression object */\n\n  /* We set up the normal JPEG error routines, then override error_exit. */\n  cinfo.err = jpeg_std_error(&jerr.pub);\n  jerr.pub.error_exit = my_error_exit;\n  /* Establish the setjmp return context for my_error_exit to use. */\n  if (setjmp(jerr.setjmp_buffer)) {\n    /* If we get here, the JPEG code has signaled an error.\n     * We need to clean up the JPEG object, close the input file, and return.\n     */\n    jpeg_destroy_decompress(&cinfo);\n    fclose(infile);\n    return 0;\n  }\n  /* Now we can initialize the JPEG decompression object. */\n  jpeg_create_decompress(&cinfo);\n\n  /* Step 2: specify data source (eg, a file) */\n\n  jpeg_stdio_src(&cinfo, infile);\n\n  /* Step 3: read file parameters with jpeg_read_header() */\n\n  (void) jpeg_read_header(&cinfo, TRUE);\n  /* We can ignore the return value from jpeg_read_header since\n   *   (a) suspension is not possible with the stdio data source, and\n   *   (b) we passed TRUE to reject a tables-only JPEG file as an error.\n   * See libjpeg.txt for more info.\n   */\n\n  /* Step 4: set parameters for decompression */\n\n  /* In this example, we don't need to change any of the defaults set by\n   * jpeg_read_header(), so we do nothing here.\n   */\n\n  /* Step 5: Start decompressor */\n\n  (void) jpeg_start_decompress(&cinfo);\n  /* We can ignore the return value since suspension is not possible\n   * with the stdio data source.\n   */\n\n  /* We may need to do some setup of our own at this point before reading\n   * the data.  After jpeg_start_decompress() we have the correct scaled\n   * output image dimensions available, as well as the output colormap\n   * if we asked for color quantization.\n   * In this example, we need to make an output work buffer of the right size.\n   */ \n  /* JSAMPLEs per row in output buffer */\n  row_stride = cinfo.output_width * cinfo.output_components;\n  /* Make a one-row-high sample array that will go away when done with image */\n  buffer = (*cinfo.mem->alloc_sarray)\n\t\t((j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1);\n\n  /* Step 6: while (scan lines remain to be read) */\n  /*           jpeg_read_scanlines(...); */\n\n  /* Here we use the library's state variable cinfo.output_scanline as the\n   * loop counter, so that we don't have to keep track ourselves.\n   */\n  while (cinfo.output_scanline < cinfo.output_height) {\n    /* jpeg_read_scanlines expects an array of pointers to scanlines.\n     * Here the array is only one element long, but you could ask for\n     * more than one scanline at a time if that's more convenient.\n     */\n    (void) jpeg_read_scanlines(&cinfo, buffer, 1);\n    /* Assume put_scanline_someplace wants a pointer and sample count. */\n    put_scanline_someplace(buffer[0], row_stride);\n  }\n\n  /* Step 7: Finish decompression */\n\n  (void) jpeg_finish_decompress(&cinfo);\n  /* We can ignore the return value since suspension is not possible\n   * with the stdio data source.\n   */\n\n  /* Step 8: Release JPEG decompression object */\n\n  /* This is an important step since it will release a good deal of memory. */\n  jpeg_destroy_decompress(&cinfo);\n\n  /* After finish_decompress, we can close the input file.\n   * Here we postpone it until after no more JPEG errors are possible,\n   * so as to simplify the setjmp error logic above.  (Actually, I don't\n   * think that jpeg_destroy can do an error exit, but why assume anything...)\n   */\n  fclose(infile);\n\n  /* At this point you may want to check to see whether any corrupt-data\n   * warnings occurred (test whether jerr.pub.num_warnings is nonzero).\n   */\n\n  /* And we're done! */\n  return 1;\n}\n\n\n/*\n * SOME FINE POINTS:\n *\n * In the above code, we ignored the return value of jpeg_read_scanlines,\n * which is the number of scanlines actually read.  We could get away with\n * this because we asked for only one line at a time and we weren't using\n * a suspending data source.  See libjpeg.txt for more info.\n *\n * We cheated a bit by calling alloc_sarray() after jpeg_start_decompress();\n * we should have done it beforehand to ensure that the space would be\n * counted against the JPEG max_memory setting.  In some systems the above\n * code would risk an out-of-memory error.  However, in general we don't\n * know the output image dimensions before jpeg_start_decompress(), unless we\n * call jpeg_calc_output_dimensions().  See libjpeg.txt for more about this.\n *\n * Scanlines are returned in the same order as they appear in the JPEG file,\n * which is standardly top-to-bottom.  If you must emit data bottom-to-top,\n * you can use one of the virtual arrays provided by the JPEG memory manager\n * to invert the data.  See wrbmp.c for an example.\n *\n * As with compression, some operating modes may require temporary files.\n * On some systems you may need to set up a signal handler to ensure that\n * temporary files are deleted if the program is interrupted.  See libjpeg.txt.\n */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/filelist.txt",
    "content": "IJG JPEG LIBRARY:  FILE LIST\n\nCopyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.\nThis file is part of the Independent JPEG Group's software.\nFor conditions of distribution and use, see the accompanying README file.\n\n\nHere is a road map to the files in the IJG JPEG distribution.  The\ndistribution includes the JPEG library proper, plus two application\nprograms (\"cjpeg\" and \"djpeg\") which use the library to convert JPEG\nfiles to and from some other popular image formats.  A third application\n\"jpegtran\" uses the library to do lossless conversion between different\nvariants of JPEG.  There are also two stand-alone applications,\n\"rdjpgcom\" and \"wrjpgcom\".\n\n\nTHE JPEG LIBRARY\n================\n\nInclude files:\n\njpeglib.h\tJPEG library's exported data and function declarations.\njconfig.h\tConfiguration declarations.  Note: this file is not present\n\t\tin the distribution; it is generated during installation.\njmorecfg.h\tAdditional configuration declarations; need not be changed\n\t\tfor a standard installation.\njerror.h\tDeclares JPEG library's error and trace message codes.\njinclude.h\tCentral include file used by all IJG .c files to reference\n\t\tsystem include files.\njpegint.h\tJPEG library's internal data structures.\njdct.h\t\tPrivate declarations for forward & reverse DCT subsystems.\njmemsys.h\tPrivate declarations for memory management subsystem.\njversion.h\tVersion information.\n\nApplications using the library should include jpeglib.h (which in turn\nincludes jconfig.h and jmorecfg.h).  Optionally, jerror.h may be included\nif the application needs to reference individual JPEG error codes.  The\nother include files are intended for internal use and would not normally\nbe included by an application program.  (cjpeg/djpeg/etc do use jinclude.h,\nsince its function is to improve portability of the whole IJG distribution.\nMost other applications will directly include the system include files they\nwant, and hence won't need jinclude.h.)\n\n\nC source code files:\n\nThese files contain most of the functions intended to be called directly by\nan application program:\n\njcapimin.c\tApplication program interface: core routines for compression.\njcapistd.c\tApplication program interface: standard compression.\njdapimin.c\tApplication program interface: core routines for decompression.\njdapistd.c\tApplication program interface: standard decompression.\njcomapi.c\tApplication program interface routines common to compression\n\t\tand decompression.\njcparam.c\tCompression parameter setting helper routines.\njctrans.c\tAPI and library routines for transcoding compression.\njdtrans.c\tAPI and library routines for transcoding decompression.\n\nCompression side of the library:\n\njcinit.c\tInitialization: determines which other modules to use.\njcmaster.c\tMaster control: setup and inter-pass sequencing logic.\njcmainct.c\tMain buffer controller (preprocessor => JPEG compressor).\njcprepct.c\tPreprocessor buffer controller.\njccoefct.c\tBuffer controller for DCT coefficient buffer.\njccolor.c\tColor space conversion.\njcsample.c\tDownsampling.\njcdctmgr.c\tDCT manager (DCT implementation selection & control).\njfdctint.c\tForward DCT using slow-but-accurate integer method.\njfdctfst.c\tForward DCT using faster, less accurate integer method.\njfdctflt.c\tForward DCT using floating-point arithmetic.\njchuff.c\tHuffman entropy coding.\njcarith.c\tArithmetic entropy coding.\njcmarker.c\tJPEG marker writing.\njdatadst.c\tData destination managers for memory and stdio output.\n\nDecompression side of the library:\n\njdmaster.c\tMaster control: determines which other modules to use.\njdinput.c\tInput controller: controls input processing modules.\njdmainct.c\tMain buffer controller (JPEG decompressor => postprocessor).\njdcoefct.c\tBuffer controller for DCT coefficient buffer.\njdpostct.c\tPostprocessor buffer controller.\njdmarker.c\tJPEG marker reading.\njdhuff.c\tHuffman entropy decoding.\njdarith.c\tArithmetic entropy decoding.\njddctmgr.c\tIDCT manager (IDCT implementation selection & control).\njidctint.c\tInverse DCT using slow-but-accurate integer method.\njidctfst.c\tInverse DCT using faster, less accurate integer method.\njidctflt.c\tInverse DCT using floating-point arithmetic.\njdsample.c\tUpsampling.\njdcolor.c\tColor space conversion.\njdmerge.c\tMerged upsampling/color conversion (faster, lower quality).\njquant1.c\tOne-pass color quantization using a fixed-spacing colormap.\njquant2.c\tTwo-pass color quantization using a custom-generated colormap.\n\t\tAlso handles one-pass quantization to an externally given map.\njdatasrc.c\tData source managers for memory and stdio input.\n\nSupport files for both compression and decompression:\n\njaricom.c\tTables for common use in arithmetic entropy encoding and\n\t\tdecoding routines.\njerror.c\tStandard error handling routines (application replaceable).\njmemmgr.c\tSystem-independent (more or less) memory management code.\njutils.c\tMiscellaneous utility routines.\n\njmemmgr.c relies on a system-dependent memory management module.  The IJG\ndistribution includes the following implementations of the system-dependent\nmodule:\n\njmemnobs.c\t\"No backing store\": assumes adequate virtual memory exists.\njmemansi.c\tMakes temporary files with ANSI-standard routine tmpfile().\njmemname.c\tMakes temporary files with program-generated file names.\njmemdos.c\tCustom implementation for MS-DOS (16-bit environment only):\n\t\tcan use extended and expanded memory as well as temp files.\njmemmac.c\tCustom implementation for Apple Macintosh.\n\nExactly one of the system-dependent modules should be configured into an\ninstalled JPEG library (see install.txt for hints about which one to use).\nOn unusual systems you may find it worthwhile to make a special\nsystem-dependent memory manager.\n\n\nNon-C source code files:\n\njmemdosa.asm\t80x86 assembly code support for jmemdos.c; used only in\n\t\tMS-DOS-specific configurations of the JPEG library.\n\n\nCJPEG/DJPEG/JPEGTRAN\n====================\n\nInclude files:\n\ncdjpeg.h\tDeclarations shared by cjpeg/djpeg/jpegtran modules.\ncderror.h\tAdditional error and trace message codes for cjpeg et al.\ntransupp.h\tDeclarations for jpegtran support routines in transupp.c.\n\nC source code files:\n\ncjpeg.c\t\tMain program for cjpeg.\ndjpeg.c\t\tMain program for djpeg.\njpegtran.c\tMain program for jpegtran.\ncdjpeg.c\tUtility routines used by all three programs.\nrdcolmap.c\tCode to read a colormap file for djpeg's \"-map\" switch.\nrdswitch.c\tCode to process some of cjpeg's more complex switches.\n\t\tAlso used by jpegtran.\ntransupp.c\tSupport code for jpegtran: lossless image manipulations.\n\nImage file reader modules for cjpeg:\n\nrdbmp.c\t\tBMP file input.\nrdgif.c\t\tGIF file input (now just a stub).\nrdppm.c\t\tPPM/PGM file input.\nrdrle.c\t\tUtah RLE file input.\nrdtarga.c\tTarga file input.\n\nImage file writer modules for djpeg:\n\nwrbmp.c\t\tBMP file output.\nwrgif.c\t\tGIF file output (a mere shadow of its former self).\nwrppm.c\t\tPPM/PGM file output.\nwrrle.c\t\tUtah RLE file output.\nwrtarga.c\tTarga file output.\n\n\nRDJPGCOM/WRJPGCOM\n=================\n\nC source code files:\n\nrdjpgcom.c\tStand-alone rdjpgcom application.\nwrjpgcom.c\tStand-alone wrjpgcom application.\n\nThese programs do not depend on the IJG library.  They do use\njconfig.h and jinclude.h, only to improve portability.\n\n\nADDITIONAL FILES\n================\n\nDocumentation (see README for a guide to the documentation files):\n\nREADME\t\tMaster documentation file.\n*.txt\t\tOther documentation files.\n*.1\t\tDocumentation in Unix man page format.\nchange.log\tVersion-to-version change highlights.\nexample.c\tSample code for calling JPEG library.\n\nConfiguration/installation files and programs (see install.txt for more info):\n\nconfigure\tUnix shell script to perform automatic configuration.\nconfigure.ac\tSource file for use with Autoconf to generate configure.\nltmain.sh\tSupport scripts for configure (from GNU libtool).\nconfig.guess\nconfig.sub\ndepcomp\nmissing\nar-lib\ncompile\ninstall-sh\tInstall shell script for those Unix systems lacking one.\nMakefile.in\tMakefile input for configure.\nMakefile.am\tSource file for use with Automake to generate Makefile.in.\nckconfig.c\tProgram to generate jconfig.h on non-Unix systems.\njconfig.txt\tTemplate for making jconfig.h by hand.\nmak*.*\t\tSample makefiles for particular systems.\njconfig.*\tSample jconfig.h for particular systems.\nlibjpeg.map\tScript to generate shared library with versioned symbols.\naclocal.m4\tM4 macro definitions for use with Autoconf.\n\nTest files (see install.txt for test procedure):\n\ntest*.*\t\tSource and comparison files for confidence test.\n\t\tThese are binary image files, NOT text files.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/install-sh",
    "content": "#!/bin/sh\n# install - install a program, script, or datafile\n\nscriptversion=2013-12-25.23; # UTC\n\n# This originates from X11R5 (mit/util/scripts/install.sh), which was\n# later released in X11R6 (xc/config/util/install.sh) with the\n# following copyright and license.\n#\n# Copyright (C) 1994 X Consortium\n#\n# Permission is hereby granted, free of charge, to any person obtaining a copy\n# of this software and associated documentation files (the \"Software\"), to\n# deal in the Software without restriction, including without limitation the\n# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or\n# sell copies of the Software, and to permit persons to whom the Software is\n# furnished to do so, subject to the following conditions:\n#\n# The above copyright notice and this permission notice shall be included in\n# all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE\n# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\n# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC-\n# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n#\n# Except as contained in this notice, the name of the X Consortium shall not\n# be used in advertising or otherwise to promote the sale, use or other deal-\n# ings in this Software without prior written authorization from the X Consor-\n# tium.\n#\n#\n# FSF changes to this file are in the public domain.\n#\n# Calling this script install-sh is preferred over install.sh, to prevent\n# 'make' implicit rules from creating a file called install from it\n# when there is no Makefile.\n#\n# This script is compatible with the BSD install script, but was written\n# from scratch.\n\ntab='\t'\nnl='\n'\nIFS=\" $tab$nl\"\n\n# Set DOITPROG to \"echo\" to test this script.\n\ndoit=${DOITPROG-}\ndoit_exec=${doit:-exec}\n\n# Put in absolute file names if you don't have them in your path;\n# or use environment vars.\n\nchgrpprog=${CHGRPPROG-chgrp}\nchmodprog=${CHMODPROG-chmod}\nchownprog=${CHOWNPROG-chown}\ncmpprog=${CMPPROG-cmp}\ncpprog=${CPPROG-cp}\nmkdirprog=${MKDIRPROG-mkdir}\nmvprog=${MVPROG-mv}\nrmprog=${RMPROG-rm}\nstripprog=${STRIPPROG-strip}\n\nposix_mkdir=\n\n# Desired mode of installed file.\nmode=0755\n\nchgrpcmd=\nchmodcmd=$chmodprog\nchowncmd=\nmvcmd=$mvprog\nrmcmd=\"$rmprog -f\"\nstripcmd=\n\nsrc=\ndst=\ndir_arg=\ndst_arg=\n\ncopy_on_change=false\nis_target_a_directory=possibly\n\nusage=\"\\\nUsage: $0 [OPTION]... [-T] SRCFILE DSTFILE\n   or: $0 [OPTION]... SRCFILES... DIRECTORY\n   or: $0 [OPTION]... -t DIRECTORY SRCFILES...\n   or: $0 [OPTION]... -d DIRECTORIES...\n\nIn the 1st form, copy SRCFILE to DSTFILE.\nIn the 2nd and 3rd, copy all SRCFILES to DIRECTORY.\nIn the 4th, create DIRECTORIES.\n\nOptions:\n     --help     display this help and exit.\n     --version  display version info and exit.\n\n  -c            (ignored)\n  -C            install only if different (preserve the last data modification time)\n  -d            create directories instead of installing files.\n  -g GROUP      $chgrpprog installed files to GROUP.\n  -m MODE       $chmodprog installed files to MODE.\n  -o USER       $chownprog installed files to USER.\n  -s            $stripprog installed files.\n  -t DIRECTORY  install into DIRECTORY.\n  -T            report an error if DSTFILE is a directory.\n\nEnvironment variables override the default commands:\n  CHGRPPROG CHMODPROG CHOWNPROG CMPPROG CPPROG MKDIRPROG MVPROG\n  RMPROG STRIPPROG\n\"\n\nwhile test $# -ne 0; do\n  case $1 in\n    -c) ;;\n\n    -C) copy_on_change=true;;\n\n    -d) dir_arg=true;;\n\n    -g) chgrpcmd=\"$chgrpprog $2\"\n        shift;;\n\n    --help) echo \"$usage\"; exit $?;;\n\n    -m) mode=$2\n        case $mode in\n          *' '* | *\"$tab\"* | *\"$nl\"* | *'*'* | *'?'* | *'['*)\n            echo \"$0: invalid mode: $mode\" >&2\n            exit 1;;\n        esac\n        shift;;\n\n    -o) chowncmd=\"$chownprog $2\"\n        shift;;\n\n    -s) stripcmd=$stripprog;;\n\n    -t)\n        is_target_a_directory=always\n        dst_arg=$2\n        # Protect names problematic for 'test' and other utilities.\n        case $dst_arg in\n          -* | [=\\(\\)!]) dst_arg=./$dst_arg;;\n        esac\n        shift;;\n\n    -T) is_target_a_directory=never;;\n\n    --version) echo \"$0 $scriptversion\"; exit $?;;\n\n    --) shift\n        break;;\n\n    -*) echo \"$0: invalid option: $1\" >&2\n        exit 1;;\n\n    *)  break;;\n  esac\n  shift\ndone\n\n# We allow the use of options -d and -T together, by making -d\n# take the precedence; this is for compatibility with GNU install.\n\nif test -n \"$dir_arg\"; then\n  if test -n \"$dst_arg\"; then\n    echo \"$0: target directory not allowed when installing a directory.\" >&2\n    exit 1\n  fi\nfi\n\nif test $# -ne 0 && test -z \"$dir_arg$dst_arg\"; then\n  # When -d is used, all remaining arguments are directories to create.\n  # When -t is used, the destination is already specified.\n  # Otherwise, the last argument is the destination.  Remove it from $@.\n  for arg\n  do\n    if test -n \"$dst_arg\"; then\n      # $@ is not empty: it contains at least $arg.\n      set fnord \"$@\" \"$dst_arg\"\n      shift # fnord\n    fi\n    shift # arg\n    dst_arg=$arg\n    # Protect names problematic for 'test' and other utilities.\n    case $dst_arg in\n      -* | [=\\(\\)!]) dst_arg=./$dst_arg;;\n    esac\n  done\nfi\n\nif test $# -eq 0; then\n  if test -z \"$dir_arg\"; then\n    echo \"$0: no input file specified.\" >&2\n    exit 1\n  fi\n  # It's OK to call 'install-sh -d' without argument.\n  # This can happen when creating conditional directories.\n  exit 0\nfi\n\nif test -z \"$dir_arg\"; then\n  if test $# -gt 1 || test \"$is_target_a_directory\" = always; then\n    if test ! -d \"$dst_arg\"; then\n      echo \"$0: $dst_arg: Is not a directory.\" >&2\n      exit 1\n    fi\n  fi\nfi\n\nif test -z \"$dir_arg\"; then\n  do_exit='(exit $ret); exit $ret'\n  trap \"ret=129; $do_exit\" 1\n  trap \"ret=130; $do_exit\" 2\n  trap \"ret=141; $do_exit\" 13\n  trap \"ret=143; $do_exit\" 15\n\n  # Set umask so as not to create temps with too-generous modes.\n  # However, 'strip' requires both read and write access to temps.\n  case $mode in\n    # Optimize common cases.\n    *644) cp_umask=133;;\n    *755) cp_umask=22;;\n\n    *[0-7])\n      if test -z \"$stripcmd\"; then\n        u_plus_rw=\n      else\n        u_plus_rw='% 200'\n      fi\n      cp_umask=`expr '(' 777 - $mode % 1000 ')' $u_plus_rw`;;\n    *)\n      if test -z \"$stripcmd\"; then\n        u_plus_rw=\n      else\n        u_plus_rw=,u+rw\n      fi\n      cp_umask=$mode$u_plus_rw;;\n  esac\nfi\n\nfor src\ndo\n  # Protect names problematic for 'test' and other utilities.\n  case $src in\n    -* | [=\\(\\)!]) src=./$src;;\n  esac\n\n  if test -n \"$dir_arg\"; then\n    dst=$src\n    dstdir=$dst\n    test -d \"$dstdir\"\n    dstdir_status=$?\n  else\n\n    # Waiting for this to be detected by the \"$cpprog $src $dsttmp\" command\n    # might cause directories to be created, which would be especially bad\n    # if $src (and thus $dsttmp) contains '*'.\n    if test ! -f \"$src\" && test ! -d \"$src\"; then\n      echo \"$0: $src does not exist.\" >&2\n      exit 1\n    fi\n\n    if test -z \"$dst_arg\"; then\n      echo \"$0: no destination specified.\" >&2\n      exit 1\n    fi\n    dst=$dst_arg\n\n    # If destination is a directory, append the input filename; won't work\n    # if double slashes aren't ignored.\n    if test -d \"$dst\"; then\n      if test \"$is_target_a_directory\" = never; then\n        echo \"$0: $dst_arg: Is a directory\" >&2\n        exit 1\n      fi\n      dstdir=$dst\n      dst=$dstdir/`basename \"$src\"`\n      dstdir_status=0\n    else\n      dstdir=`dirname \"$dst\"`\n      test -d \"$dstdir\"\n      dstdir_status=$?\n    fi\n  fi\n\n  obsolete_mkdir_used=false\n\n  if test $dstdir_status != 0; then\n    case $posix_mkdir in\n      '')\n        # Create intermediate dirs using mode 755 as modified by the umask.\n        # This is like FreeBSD 'install' as of 1997-10-28.\n        umask=`umask`\n        case $stripcmd.$umask in\n          # Optimize common cases.\n          *[2367][2367]) mkdir_umask=$umask;;\n          .*0[02][02] | .[02][02] | .[02]) mkdir_umask=22;;\n\n          *[0-7])\n            mkdir_umask=`expr $umask + 22 \\\n              - $umask % 100 % 40 + $umask % 20 \\\n              - $umask % 10 % 4 + $umask % 2\n            `;;\n          *) mkdir_umask=$umask,go-w;;\n        esac\n\n        # With -d, create the new directory with the user-specified mode.\n        # Otherwise, rely on $mkdir_umask.\n        if test -n \"$dir_arg\"; then\n          mkdir_mode=-m$mode\n        else\n          mkdir_mode=\n        fi\n\n        posix_mkdir=false\n        case $umask in\n          *[123567][0-7][0-7])\n            # POSIX mkdir -p sets u+wx bits regardless of umask, which\n            # is incompatible with FreeBSD 'install' when (umask & 300) != 0.\n            ;;\n          *)\n            tmpdir=${TMPDIR-/tmp}/ins$RANDOM-$$\n            trap 'ret=$?; rmdir \"$tmpdir/d\" \"$tmpdir\" 2>/dev/null; exit $ret' 0\n\n            if (umask $mkdir_umask &&\n                exec $mkdirprog $mkdir_mode -p -- \"$tmpdir/d\") >/dev/null 2>&1\n            then\n              if test -z \"$dir_arg\" || {\n                   # Check for POSIX incompatibilities with -m.\n                   # HP-UX 11.23 and IRIX 6.5 mkdir -m -p sets group- or\n                   # other-writable bit of parent directory when it shouldn't.\n                   # FreeBSD 6.1 mkdir -m -p sets mode of existing directory.\n                   ls_ld_tmpdir=`ls -ld \"$tmpdir\"`\n                   case $ls_ld_tmpdir in\n                     d????-?r-*) different_mode=700;;\n                     d????-?--*) different_mode=755;;\n                     *) false;;\n                   esac &&\n                   $mkdirprog -m$different_mode -p -- \"$tmpdir\" && {\n                     ls_ld_tmpdir_1=`ls -ld \"$tmpdir\"`\n                     test \"$ls_ld_tmpdir\" = \"$ls_ld_tmpdir_1\"\n                   }\n                 }\n              then posix_mkdir=:\n              fi\n              rmdir \"$tmpdir/d\" \"$tmpdir\"\n            else\n              # Remove any dirs left behind by ancient mkdir implementations.\n              rmdir ./$mkdir_mode ./-p ./-- 2>/dev/null\n            fi\n            trap '' 0;;\n        esac;;\n    esac\n\n    if\n      $posix_mkdir && (\n        umask $mkdir_umask &&\n        $doit_exec $mkdirprog $mkdir_mode -p -- \"$dstdir\"\n      )\n    then :\n    else\n\n      # The umask is ridiculous, or mkdir does not conform to POSIX,\n      # or it failed possibly due to a race condition.  Create the\n      # directory the slow way, step by step, checking for races as we go.\n\n      case $dstdir in\n        /*) prefix='/';;\n        [-=\\(\\)!]*) prefix='./';;\n        *)  prefix='';;\n      esac\n\n      oIFS=$IFS\n      IFS=/\n      set -f\n      set fnord $dstdir\n      shift\n      set +f\n      IFS=$oIFS\n\n      prefixes=\n\n      for d\n      do\n        test X\"$d\" = X && continue\n\n        prefix=$prefix$d\n        if test -d \"$prefix\"; then\n          prefixes=\n        else\n          if $posix_mkdir; then\n            (umask=$mkdir_umask &&\n             $doit_exec $mkdirprog $mkdir_mode -p -- \"$dstdir\") && break\n            # Don't fail if two instances are running concurrently.\n            test -d \"$prefix\" || exit 1\n          else\n            case $prefix in\n              *\\'*) qprefix=`echo \"$prefix\" | sed \"s/'/'\\\\\\\\\\\\\\\\''/g\"`;;\n              *) qprefix=$prefix;;\n            esac\n            prefixes=\"$prefixes '$qprefix'\"\n          fi\n        fi\n        prefix=$prefix/\n      done\n\n      if test -n \"$prefixes\"; then\n        # Don't fail if two instances are running concurrently.\n        (umask $mkdir_umask &&\n         eval \"\\$doit_exec \\$mkdirprog $prefixes\") ||\n          test -d \"$dstdir\" || exit 1\n        obsolete_mkdir_used=true\n      fi\n    fi\n  fi\n\n  if test -n \"$dir_arg\"; then\n    { test -z \"$chowncmd\" || $doit $chowncmd \"$dst\"; } &&\n    { test -z \"$chgrpcmd\" || $doit $chgrpcmd \"$dst\"; } &&\n    { test \"$obsolete_mkdir_used$chowncmd$chgrpcmd\" = false ||\n      test -z \"$chmodcmd\" || $doit $chmodcmd $mode \"$dst\"; } || exit 1\n  else\n\n    # Make a couple of temp file names in the proper directory.\n    dsttmp=$dstdir/_inst.$$_\n    rmtmp=$dstdir/_rm.$$_\n\n    # Trap to clean up those temp files at exit.\n    trap 'ret=$?; rm -f \"$dsttmp\" \"$rmtmp\" && exit $ret' 0\n\n    # Copy the file name to the temp name.\n    (umask $cp_umask && $doit_exec $cpprog \"$src\" \"$dsttmp\") &&\n\n    # and set any options; do chmod last to preserve setuid bits.\n    #\n    # If any of these fail, we abort the whole thing.  If we want to\n    # ignore errors from any of these, just make sure not to ignore\n    # errors from the above \"$doit $cpprog $src $dsttmp\" command.\n    #\n    { test -z \"$chowncmd\" || $doit $chowncmd \"$dsttmp\"; } &&\n    { test -z \"$chgrpcmd\" || $doit $chgrpcmd \"$dsttmp\"; } &&\n    { test -z \"$stripcmd\" || $doit $stripcmd \"$dsttmp\"; } &&\n    { test -z \"$chmodcmd\" || $doit $chmodcmd $mode \"$dsttmp\"; } &&\n\n    # If -C, don't bother to copy if it wouldn't change the file.\n    if $copy_on_change &&\n       old=`LC_ALL=C ls -dlL \"$dst\"     2>/dev/null` &&\n       new=`LC_ALL=C ls -dlL \"$dsttmp\"  2>/dev/null` &&\n       set -f &&\n       set X $old && old=:$2:$4:$5:$6 &&\n       set X $new && new=:$2:$4:$5:$6 &&\n       set +f &&\n       test \"$old\" = \"$new\" &&\n       $cmpprog \"$dst\" \"$dsttmp\" >/dev/null 2>&1\n    then\n      rm -f \"$dsttmp\"\n    else\n      # Rename the file to the real destination.\n      $doit $mvcmd -f \"$dsttmp\" \"$dst\" 2>/dev/null ||\n\n      # The rename failed, perhaps because mv can't rename something else\n      # to itself, or perhaps because mv is so ancient that it does not\n      # support -f.\n      {\n        # Now remove or move aside any old file at destination location.\n        # We try this two ways since rm can't unlink itself on some\n        # systems and the destination file might be busy for other\n        # reasons.  In this case, the final cleanup might fail but the new\n        # file should still install successfully.\n        {\n          test ! -f \"$dst\" ||\n          $doit $rmcmd -f \"$dst\" 2>/dev/null ||\n          { $doit $mvcmd -f \"$dst\" \"$rmtmp\" 2>/dev/null &&\n            { $doit $rmcmd -f \"$rmtmp\" 2>/dev/null; :; }\n          } ||\n          { echo \"$0: cannot unlink or rename $dst\" >&2\n            (exit 1); exit 1\n          }\n        } &&\n\n        # Now rename the file to the real destination.\n        $doit $mvcmd \"$dsttmp\" \"$dst\"\n      }\n    fi || exit 1\n\n    trap '' 0\n  fi\ndone\n\n# Local variables:\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"scriptversion=\"\n# time-stamp-format: \"%:y-%02m-%02d.%02H\"\n# time-stamp-time-zone: \"UTC\"\n# time-stamp-end: \"; # UTC\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/install.txt",
    "content": "INSTALLATION INSTRUCTIONS for the Independent JPEG Group's JPEG software\n\nCopyright (C) 1991-2015, Thomas G. Lane, Guido Vollbeding.\nThis file is part of the Independent JPEG Group's software.\nFor conditions of distribution and use, see the accompanying README file.\n\n\nThis file explains how to configure and install the IJG software.  We have\ntried to make this software extremely portable and flexible, so that it can be\nadapted to almost any environment.  The downside of this decision is that the\ninstallation process is complicated.  We have provided shortcuts to simplify\nthe task on common systems.  But in any case, you will need at least a little\nfamiliarity with C programming and program build procedures for your system.\n\nIf you are only using this software as part of a larger program, the larger\nprogram's installation procedure may take care of configuring the IJG code.\nFor example, Ghostscript's installation script will configure the IJG code.\nYou don't need to read this file if you just want to compile Ghostscript.\n\nIf you are on a Unix machine, you may not need to read this file at all.\nTry doing\n\t./configure\n\tmake\n\tmake test\nIf that doesn't complain, do\n\tmake install\n(better do \"make -n install\" first to see if the makefile will put the files\nwhere you want them).  Read further if you run into snags or want to customize\nthe code for your system.\n\n\nTABLE OF CONTENTS\n-----------------\n\nBefore you start\nConfiguring the software:\n\tusing the automatic \"configure\" script\n\tusing one of the supplied jconfig and makefile files\n\tby hand\nBuilding the software\nTesting the software\nInstalling the software\nOptional stuff\nOptimization\nHints for specific systems\n\n\nBEFORE YOU START\n================\n\nBefore installing the software you must unpack the distributed source code.\nSince you are reading this file, you have probably already succeeded in this\ntask.  However, there is a potential for error if you needed to convert the\nfiles to the local standard text file format (for example, if you are on\nMS-DOS you may have converted LF end-of-line to CR/LF).  You must apply\nsuch conversion to all the files EXCEPT those whose names begin with \"test\".\nThe test files contain binary data; if you change them in any way then the\nself-test will give bad results.\n\nPlease check the last section of this file to see if there are hints for the\nspecific machine or compiler you are using.\n\n\nCONFIGURING THE SOFTWARE\n========================\n\nTo configure the IJG code for your system, you need to create two files:\n  * jconfig.h: contains values for system-dependent #define symbols.\n  * Makefile: controls the compilation process.\n(On a non-Unix machine, you may create \"project files\" or some other\nsubstitute for a Makefile.  jconfig.h is needed in any environment.)\n\nWe provide three different ways to generate these files:\n  * On a Unix system, you can just run the \"configure\" script.\n  * We provide sample jconfig files and makefiles for popular machines;\n    if your machine matches one of the samples, just copy the right sample\n    files to jconfig.h and Makefile.\n  * If all else fails, read the instructions below and make your own files.\n\n\nConfiguring the software using the automatic \"configure\" script\n---------------------------------------------------------------\n\nIf you are on a Unix machine, you can just type\n\t./configure\nand let the configure script construct appropriate configuration files.\nIf you're using \"csh\" on an old version of System V, you might need to type\n\tsh configure\ninstead to prevent csh from trying to execute configure itself.\nExpect configure to run for a few minutes, particularly on slower machines;\nit works by compiling a series of test programs.\n\nConfigure was created with GNU Autoconf and it follows the usual conventions\nfor GNU configure scripts.  It makes a few assumptions that you may want to\noverride.  You can do this by providing optional switches to configure:\n\n* Configure will build both static and shared libraries, if possible.\nIf you want to build libjpeg only as a static library, say\n\t./configure --disable-shared\nIf you want to build libjpeg only as a shared library, say\n\t./configure --disable-static\nConfigure uses GNU libtool to take care of system-dependent shared library\nbuilding methods.\n\n* Configure will use gcc (GNU C compiler) if it's available, otherwise cc.\nTo force a particular compiler to be selected, use the CC option, for example\n\t./configure CC='cc'\nThe same method can be used to include any unusual compiler switches.\nFor example, on HP-UX you probably want to say\n\t./configure CC='cc -Aa'\nto get HP's compiler to run in ANSI mode.\n\n* The default CFLAGS setting is \"-g\" for non-gcc compilers, \"-g -O2\" for gcc.\nYou can override this by saying, for example,\n\t./configure CFLAGS='-O2'\nif you want to compile without debugging support.\n\n* Configure will set up the makefile so that \"make install\" will install files\ninto /usr/local/bin, /usr/local/man, etc.  You can specify an installation\nprefix other than \"/usr/local\" by giving configure the option \"--prefix=PATH\".\n\n* If you don't have a lot of swap space, you may need to enable the IJG\nsoftware's internal virtual memory mechanism.  To do this, give the option\n\"--enable-maxmem=N\" where N is the default maxmemory limit in megabytes.\nThis is discussed in more detail under \"Selecting a memory manager\", below.\nYou probably don't need to worry about this on reasonably-sized Unix machines,\nunless you plan to process very large images.\n\nConfigure has some other features that are useful if you are cross-compiling\nor working in a network of multiple machine types; but if you need those\nfeatures, you probably already know how to use them.\n\n\nConfiguring the software using one of the supplied jconfig and makefile files\n-----------------------------------------------------------------------------\n\nIf you have one of these systems, you can just use the provided configuration\nfiles:\n\nMakefile\tjconfig file\tSystem and/or compiler\n\nmakefile.manx\tjconfig.manx\tAmiga, Manx Aztec C\nmakefile.sas\tjconfig.sas\tAmiga, SAS C\nmakeproj.mac\tjconfig.mac\tApple Macintosh, Metrowerks CodeWarrior\nmak*jpeg.st\tjconfig.st\tAtari ST/STE/TT, Pure C or Turbo C\nmakefile.bcc\tjconfig.bcc\tMS-DOS or OS/2, Borland C\nmakefile.dj\tjconfig.dj\tMS-DOS, DJGPP (Delorie's port of GNU C)\nmakefile.mc6\tjconfig.mc6\tMS-DOS, Microsoft C (16-bit only)\nmakefile.wat\tjconfig.wat\tMS-DOS, OS/2, or Windows NT, Watcom C\nmakefile.vc\tjconfig.vc\tWindows NT/9x, MS Visual C++\nmake*.vc6\tjconfig.vc\tWindows NT/9x, MS Visual C++ 6\nmake*.v10\tjconfig.vc\tWindows NT/9x, MS Visual C++ 2010 (v10)\nmakefile.b32\tjconfig.vc\tWindows NT/9x, Borland C++ 32-bit (bcc32)\nmakefile.mms\tjconfig.vms\tDigital VMS, with MMS software\nmakefile.vms\tjconfig.vms\tDigital VMS, without MMS software\n\nCopy the proper jconfig file to jconfig.h and the makefile to Makefile (or\nwhatever your system uses as the standard makefile name).  For more info see\nthe appropriate system-specific hints section near the end of this file.\n\n\nConfiguring the software by hand\n--------------------------------\n\nFirst, generate a jconfig.h file.  If you are moderately familiar with C,\nthe comments in jconfig.txt should be enough information to do this; just\ncopy jconfig.txt to jconfig.h and edit it appropriately.  Otherwise, you may\nprefer to use the ckconfig.c program.  You will need to compile and execute\nckconfig.c by hand --- we hope you know at least enough to do that.\nckconfig.c may not compile the first try (in fact, the whole idea is for it\nto fail if anything is going to).  If you get compile errors, fix them by\nediting ckconfig.c according to the directions given in ckconfig.c.  Once\nyou get it to run, it will write a suitable jconfig.h file, and will also\nprint out some advice about which makefile to use.\n\nYou may also want to look at the canned jconfig files, if there is one for a\nsystem similar to yours.\n\nSecond, select a makefile and copy it to Makefile (or whatever your system\nuses as the standard makefile name).  The most generic makefiles we provide\nare\n\tmakefile.ansi:\tif your C compiler supports function prototypes\n\tmakefile.unix:\tif not.\n(You have function prototypes if ckconfig.c put \"#define HAVE_PROTOTYPES\"\nin jconfig.h.)  You may want to start from one of the other makefiles if\nthere is one for a system similar to yours.\n\nLook over the selected Makefile and adjust options as needed.  In particular\nyou may want to change the CC and CFLAGS definitions.  For instance, if you\nare using GCC, set CC=gcc.  If you had to use any compiler switches to get\nckconfig.c to work, make sure the same switches are in CFLAGS.\n\nIf you are on a system that doesn't use makefiles, you'll need to set up\nproject files (or whatever you do use) to compile all the source files and\nlink them into executable files cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom.\nSee the file lists in any of the makefiles to find out which files go into\neach program.  Note that the provided makefiles all make a \"library\" file\nlibjpeg first, but you don't have to do that if you don't want to; the file\nlists identify which source files are actually needed for compression,\ndecompression, or both.  As a last resort, you can make a batch script that\njust compiles everything and links it all together; makefile.vms is an example\nof this (it's for VMS systems that have no make-like utility).\n\nHere are comments about some specific configuration decisions you'll\nneed to make:\n\nCommand line style\n------------------\n\nThese programs can use a Unix-like command line style which supports\nredirection and piping, like this:\n\tcjpeg inputfile >outputfile\n\tcjpeg <inputfile >outputfile\n\tsource program | cjpeg >outputfile\nThe simpler \"two file\" command line style is just\n\tcjpeg inputfile outputfile\nYou may prefer the two-file style, particularly if you don't have pipes.\n\nYou MUST use two-file style on any system that doesn't cope well with binary\ndata fed through stdin/stdout; this is true for some MS-DOS compilers, for\nexample.  If you're not on a Unix system, it's safest to assume you need\ntwo-file style.  (But if your compiler provides either the Posix-standard\nfdopen() library routine or a Microsoft-compatible setmode() routine, you\ncan safely use the Unix command line style, by defining USE_FDOPEN or\nUSE_SETMODE respectively.)\n\nTo use the two-file style, make jconfig.h say \"#define TWO_FILE_COMMANDLINE\".\n\nSelecting a memory manager\n--------------------------\n\nThe IJG code is capable of working on images that are too big to fit in main\nmemory; data is swapped out to temporary files as necessary.  However, the\ncode to do this is rather system-dependent.  We provide five different\nmemory managers:\n\n* jmemansi.c\tThis version uses the ANSI-standard library routine tmpfile(),\n\t\twhich not all non-ANSI systems have.  On some systems\n\t\ttmpfile() may put the temporary file in a non-optimal\n\t\tlocation; if you don't like what it does, use jmemname.c.\n\n* jmemname.c\tThis version creates named temporary files.  For anything\n\t\texcept a Unix machine, you'll need to configure the\n\t\tselect_file_name() routine appropriately; see the comments\n\t\tnear the head of jmemname.c.  If you use this version, define\n\t\tNEED_SIGNAL_CATCHER in jconfig.h to make sure the temp files\n\t\tare removed if the program is aborted.\n\n* jmemnobs.c\t(That stands for No Backing Store :-).)  This will compile on\n\t\talmost any system, but it assumes you have enough main memory\n\t\tor virtual memory to hold the biggest images you work with.\n\n* jmemdos.c\tThis should be used with most 16-bit MS-DOS compilers.\n\t\tSee the system-specific notes about MS-DOS for more info.\n\t\tIMPORTANT: if you use this, define USE_MSDOS_MEMMGR in\n\t\tjconfig.h, and include the assembly file jmemdosa.asm in the\n\t\tprograms.  The supplied makefiles and jconfig files for\n\t\t16-bit MS-DOS compilers already do both.\n\n* jmemmac.c\tCustom version for Apple Macintosh; see the system-specific\n\t\tnotes for Macintosh for more info.\n\nTo use a particular memory manager, change the SYSDEPMEM variable in your\nmakefile to equal the corresponding object file name (for example, jmemansi.o\nor jmemansi.obj for jmemansi.c).\n\nIf you have plenty of (real or virtual) main memory, just use jmemnobs.c.\n\"Plenty\" means about ten bytes for every pixel in the largest images\nyou plan to process, so a lot of systems don't meet this criterion.\nIf yours doesn't, try jmemansi.c first.  If that doesn't compile, you'll have\nto use jmemname.c; be sure to adjust select_file_name() for local conditions.\nYou may also need to change unlink() to remove() in close_backing_store().\n\nExcept with jmemnobs.c or jmemmac.c, you need to adjust the DEFAULT_MAX_MEM\nsetting to a reasonable value for your system (either by adding a #define for\nDEFAULT_MAX_MEM to jconfig.h, or by adding a -D switch to the Makefile).\nThis value limits the amount of data space the program will attempt to\nallocate.  Code and static data space isn't counted, so the actual memory\nneeds for cjpeg or djpeg are typically 100 to 150Kb more than the max-memory\nsetting.  Larger max-memory settings reduce the amount of I/O needed to\nprocess a large image, but too large a value can result in \"insufficient\nmemory\" failures.  On most Unix machines (and other systems with virtual\nmemory), just set DEFAULT_MAX_MEM to several million and forget it.  At the\nother end of the spectrum, for MS-DOS machines you probably can't go much\nabove 300K to 400K.  (On MS-DOS the value refers to conventional memory only.\nExtended/expanded memory is handled separately by jmemdos.c.)\n\n\nBUILDING THE SOFTWARE\n=====================\n\nNow you should be able to compile the software.  Just say \"make\" (or\nwhatever's necessary to start the compilation).  Have a cup of coffee.\n\nHere are some things that could go wrong:\n\nIf your compiler complains about undefined structures, you should be able to\nshut it up by putting \"#define INCOMPLETE_TYPES_BROKEN\" in jconfig.h.\n\nIf you have trouble with missing system include files or inclusion of the\nwrong ones, read jinclude.h.  This shouldn't happen if you used configure\nor ckconfig.c to set up jconfig.h.\n\nThere are a fair number of routines that do not use all of their parameters;\nsome compilers will issue warnings about this, which you can ignore.  There\nare also a few configuration checks that may give \"unreachable code\" warnings.\nAny other warning deserves investigation.\n\nIf you don't have a getenv() library routine, define NO_GETENV.\n\nAlso see the system-specific hints, below.\n\n\nTESTING THE SOFTWARE\n====================\n\nAs a quick test of functionality we've included a small sample image in\nseveral forms:\n\ttestorig.jpg\tStarting point for the djpeg tests.\n\ttestimg.ppm\tThe output of djpeg testorig.jpg\n\ttestimg.bmp\tThe output of djpeg -bmp -colors 256 testorig.jpg\n\ttestimg.jpg\tThe output of cjpeg testimg.ppm\n\ttestprog.jpg\tProgressive-mode equivalent of testorig.jpg.\n\ttestimgp.jpg\tThe output of cjpeg -progressive -optimize testimg.ppm\n(The first- and second-generation .jpg files aren't identical since the\ndefault compression parameters are lossy.)  If you can generate duplicates\nof the testimg* files then you probably have working programs.\n\nWith most of the makefiles, \"make test\" will perform the necessary\ncomparisons.\n\nIf you're using a makefile that doesn't provide the test option, run djpeg\nand cjpeg by hand and compare the output files to testimg* with whatever\nbinary file comparison tool you have.  The files should be bit-for-bit\nidentical.\n\nIf the programs complain \"MAX_ALLOC_CHUNK is wrong, please fix\", then you\nneed to reduce MAX_ALLOC_CHUNK to a value that fits in type size_t.\nTry adding \"#define MAX_ALLOC_CHUNK 65520L\" to jconfig.h.  A less likely\nconfiguration error is \"ALIGN_TYPE is wrong, please fix\": defining ALIGN_TYPE\nas long should take care of that one.\n\nIf the cjpeg test run fails with \"Missing Huffman code table entry\", it's a\ngood bet that you needed to define RIGHT_SHIFT_IS_UNSIGNED.  Go back to the\nconfiguration step and run ckconfig.c.  (This is a good plan for any other\ntest failure, too.)\n\nIf you are using Unix (one-file) command line style on a non-Unix system,\nit's a good idea to check that binary I/O through stdin/stdout actually\nworks.  You should get the same results from \"djpeg <testorig.jpg >out.ppm\"\nas from \"djpeg -outfile out.ppm testorig.jpg\".  Note that the makefiles all\nuse the latter style and therefore do not exercise stdin/stdout!  If this\ncheck fails, try recompiling with USE_SETMODE or USE_FDOPEN defined.\nIf it still doesn't work, better use two-file style.\n\nIf you chose a memory manager other than jmemnobs.c, you should test that\ntemporary-file usage works.  Try \"djpeg -bmp -colors 256 -max 0 testorig.jpg\"\nand make sure its output matches testimg.bmp.  If you have any really large\nimages handy, try compressing them with -optimize and/or decompressing with\n-colors 256 to make sure your DEFAULT_MAX_MEM setting is not too large.\n\nNOTE: this is far from an exhaustive test of the JPEG software; some modules,\nsuch as 1-pass color quantization, are not exercised at all.  It's just a\nquick test to give you some confidence that you haven't missed something\nmajor.\n\n\nINSTALLING THE SOFTWARE\n=======================\n\nOnce you're done with the above steps, you can install the software by\ncopying the executable files (cjpeg, djpeg, jpegtran, rdjpgcom, and wrjpgcom)\nto wherever you normally install programs.  On Unix systems, you'll also want\nto put the man pages (cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1)\nin the man-page directory.  The pre-fab makefiles don't support this step\nsince there's such a wide variety of installation procedures on different\nsystems.\n\nIf you generated a Makefile with the \"configure\" script, you can just say\n\tmake install\nto install the programs and their man pages into the standard places.\n(You'll probably need to be root to do this.)  We recommend first saying\n\tmake -n install\nto see where configure thought the files should go.  You may need to edit\nthe Makefile, particularly if your system's conventions for man page\nfilenames don't match what configure expects.\n\nIf you want to install the IJG library itself, for use in compiling other\nprograms besides ours, then you need to put the four include files\n\tjpeglib.h jerror.h jconfig.h jmorecfg.h\ninto your include-file directory, and put the library file libjpeg.a\n(extension may vary depending on system) wherever library files go.\nIf you generated a Makefile with \"configure\", it will do what it thinks\nis the right thing if you say\n\tmake install-lib\n\n\nOPTIONAL STUFF\n==============\n\nProgress monitor:\n\nIf you like, you can #define PROGRESS_REPORT (in jconfig.h) to enable display\nof percent-done progress reports.  The routine provided in cdjpeg.c merely\nprints percentages to stderr, but you can customize it to do something\nfancier.\n\nUtah RLE file format support:\n\nWe distribute the software with support for RLE image files (Utah Raster\nToolkit format) disabled, because the RLE support won't compile without the\nUtah library.  If you have URT version 3.1 or later, you can enable RLE\nsupport as follows:\n\t1.  #define RLE_SUPPORTED in jconfig.h.\n\t2.  Add a -I option to CFLAGS in the Makefile for the directory\n\t    containing the URT .h files (typically the \"include\"\n\t    subdirectory of the URT distribution).\n\t3.  Add -L... -lrle to LDLIBS in the Makefile, where ... specifies\n\t    the directory containing the URT \"librle.a\" file (typically the\n\t    \"lib\" subdirectory of the URT distribution).\n\nSupport for 9-bit to 12-bit deep pixel data:\n\nThe IJG code currently allows 8, 9, 10, 11, or 12 bits sample data precision.\n(For color, this means 8 to 12 bits per channel, of course.)  If you need to\nwork with deeper than 8-bit data, you can compile the IJG code for 9-bit to\n12-bit operation.\nTo do so:\n  1. In jmorecfg.h, define BITS_IN_JSAMPLE as 9, 10, 11, or 12 rather than 8.\n  2. In jconfig.h, undefine BMP_SUPPORTED, RLE_SUPPORTED, and TARGA_SUPPORTED,\n     because the code for those formats doesn't handle deeper than 8-bit data\n     and won't even compile.  (The PPM code does work, as explained below.\n     The GIF code works too; it scales 8-bit GIF data to and from 12-bit\n     depth automatically.)\n  3. Compile.  Don't expect \"make test\" to pass, since the supplied test\n     files are for 8-bit data.\n\nCurrently, 9-bit to 12-bit support does not work on 16-bit-int machines.\n\nRun-time selection and conversion of data precision are currently not\nsupported and may be added later.\nException:  The transcoding part (jpegtran) supports all settings in a\nsingle instance, since it operates on the level of DCT coefficients and\nnot sample values.\n\nThe PPM reader (rdppm.c) can read deeper than 8-bit data from either\ntext-format or binary-format PPM and PGM files.  Binary-format PPM/PGM files\nwhich have a maxval greater than 255 are assumed to use 2 bytes per sample,\nMSB first (big-endian order).  As of early 1995, 2-byte binary format is not\nofficially supported by the PBMPLUS library, but it is expected that a\nfuture release of PBMPLUS will support it.  Note that the PPM reader will\nread files of any maxval regardless of the BITS_IN_JSAMPLE setting; incoming\ndata is automatically rescaled to maxval=MAXJSAMPLE as appropriate for the\ncjpeg bit depth.\n\nThe PPM writer (wrppm.c) will normally write 2-byte binary PPM or PGM\nformat, maxval=MAXJSAMPLE, when compiled with BITS_IN_JSAMPLE>8.  Since this\nformat is not yet widely supported, you can disable it by compiling wrppm.c\nwith PPM_NORAWWORD defined; then the data is scaled down to 8 bits to make a\nstandard 1-byte/sample PPM or PGM file.  (Yes, this means still another copy\nof djpeg to keep around.  But hopefully you won't need it for very long.\nPoskanzer's supposed to get that new PBMPLUS release out Real Soon Now.)\n\nOf course, if you are working with 9-bit to 12-bit data, you probably have\nit stored in some other, nonstandard format.  In that case you'll probably\nwant to write your own I/O modules to read and write your format.\n\nNote:\nThe standard Huffman tables are only valid for 8-bit data precision.  If\nyou selected more than 8-bit data precision, cjpeg uses arithmetic coding\nby default.  The Huffman encoder normally uses entropy optimization to\ncompute usable tables for higher precision.  Otherwise, you'll have to\nsupply different default Huffman tables.\n\nRemoving code:\n\nIf you need to make a smaller version of the JPEG software, some optional\nfunctions can be removed at compile time.  See the xxx_SUPPORTED #defines in\njconfig.h and jmorecfg.h.  If at all possible, we recommend that you leave in\ndecoder support for all valid JPEG files, to ensure that you can read anyone's\noutput.  Taking out support for image file formats that you don't use is the\nmost painless way to make the programs smaller.  Another possibility is to\nremove some of the DCT methods: in particular, the \"IFAST\" method may not be\nenough faster than the others to be worth keeping on your machine.  (If you\ndo remove ISLOW or IFAST, be sure to redefine JDCT_DEFAULT or JDCT_FASTEST\nto a supported method, by adding a #define in jconfig.h.)\n\n\nOPTIMIZATION\n============\n\nUnless you own a Cray, you'll probably be interested in making the JPEG\nsoftware go as fast as possible.  This section covers some machine-dependent\noptimizations you may want to try.  We suggest that before trying any of\nthis, you first get the basic installation to pass the self-test step.\nRepeat the self-test after any optimization to make sure that you haven't\nbroken anything.\n\nThe integer DCT routines perform a lot of multiplications.  These\nmultiplications must yield 32-bit results, but none of their input values\nare more than 16 bits wide.  On many machines, notably the 680x0 and 80x86\nCPUs, a 16x16=>32 bit multiply instruction is faster than a full 32x32=>32\nbit multiply.  Unfortunately there is no portable way to specify such a\nmultiplication in C, but some compilers can generate one when you use the\nright combination of casts.  See the MULTIPLYxxx macro definitions in\njdct.h.  If your compiler makes \"int\" be 32 bits and \"short\" be 16 bits,\ndefining SHORTxSHORT_32 is fairly likely to work.  When experimenting with\nalternate definitions, be sure to test not only whether the code still works\n(use the self-test), but also whether it is actually faster --- on some\ncompilers, alternate definitions may compute the right answer, yet be slower\nthan the default.  Timing cjpeg on a large PGM (grayscale) input file is the\nbest way to check this, as the DCT will be the largest fraction of the runtime\nin that mode.  (Note: some of the distributed compiler-specific jconfig files\nalready contain #define switches to select appropriate MULTIPLYxxx\ndefinitions.)\n\nIf your machine has sufficiently fast floating point hardware, you may find\nthat the float DCT method is faster than the integer DCT methods, even\nafter tweaking the integer multiply macros.  In that case you may want to\nmake the float DCT be the default method.  (The only objection to this is\nthat float DCT results may vary slightly across machines.)  To do that, add\n\"#define JDCT_DEFAULT JDCT_FLOAT\" to jconfig.h.  Even if you don't change\nthe default, you should redefine JDCT_FASTEST, which is the method selected\nby djpeg's -fast switch.  Don't forget to update the documentation files\n(usage.txt and/or cjpeg.1, djpeg.1) to agree with what you've done.\n\nIf access to \"short\" arrays is slow on your machine, it may be a win to\ndefine type JCOEF as int rather than short.  This will cost a good deal of\nmemory though, particularly in some multi-pass modes, so don't do it unless\nyou have memory to burn and short is REALLY slow.\n\nIf your compiler can compile function calls in-line, make sure the INLINE\nmacro in jmorecfg.h is defined as the keyword that marks a function\ninline-able.  Some compilers have a switch that tells the compiler to inline\nany function it thinks is profitable (e.g., -finline-functions for gcc).\nEnabling such a switch is likely to make the compiled code bigger but faster.\n\nIn general, it's worth trying the maximum optimization level of your compiler,\nand experimenting with any optional optimizations such as loop unrolling.\n(Unfortunately, far too many compilers have optimizer bugs ... be prepared to\nback off if the code fails self-test.)  If you do any experimentation along\nthese lines, please report the optimal settings to jpeg-info@jpegclub.org so\nwe can mention them in future releases.  Be sure to specify your machine and\ncompiler version.\n\n\nHINTS FOR SPECIFIC SYSTEMS\n==========================\n\nWe welcome reports on changes needed for systems not mentioned here.  Submit\n'em to jpeg-info@jpegclub.org.  Also, if configure or ckconfig.c is wrong\nabout how to configure the JPEG software for your system, please let us know.\n\n\nAcorn RISC OS:\n\n(Thanks to Simon Middleton for these hints on compiling with Desktop C.)\nAfter renaming the files according to Acorn conventions, take a copy of\nmakefile.ansi, change all occurrences of 'libjpeg.a' to 'libjpeg.o' and\nchange these definitions as indicated:\n\nCFLAGS= -throwback -IC: -Wn\nLDLIBS=C:o.Stubs\nSYSDEPMEM=jmemansi.o\nLN=Link\nAR=LibFile -c -o\n\nAlso add a new line '.c.o:; $(cc) $< $(cflags) -c -o $@'.  Remove the\nlines '$(RM) libjpeg.o' and '$(AR2) libjpeg.o' and the 'jconfig.h'\ndependency section.\n\nCopy jconfig.txt to jconfig.h.  Edit jconfig.h to define TWO_FILE_COMMANDLINE\nand CHAR_IS_UNSIGNED.\n\nRun the makefile using !AMU not !Make.  If you want to use the 'clean' and\n'test' makefile entries then you will have to fiddle with the syntax a bit\nand rename the test files.\n\n\nAmiga:\n\nSAS C 6.50 reportedly is too buggy to compile the IJG code properly.\nA patch to update to 6.51 is available from SAS or AmiNet FTP sites.\n\nThe supplied config files are set up to use jmemname.c as the memory\nmanager, with temporary files being created on the device named by\n\"JPEGTMP:\".\n\n\nAtari ST/STE/TT:\n\nCopy the project files makcjpeg.st, makdjpeg.st, maktjpeg.st, and makljpeg.st\nto cjpeg.prj, djpeg.prj, jpegtran.prj, and libjpeg.prj respectively.  The\nproject files should work as-is with Pure C.  For Turbo C, change library\nfilenames \"pc...\" to \"tc...\" in each project file.  Note that libjpeg.prj\nselects jmemansi.c as the recommended memory manager.  You'll probably want to\nadjust the DEFAULT_MAX_MEM setting --- you want it to be a couple hundred K\nless than your normal free memory.  Put \"#define DEFAULT_MAX_MEM nnnn\" into\njconfig.h to do this.\n\nTo use the 68881/68882 coprocessor for the floating point DCT, add the\ncompiler option \"-8\" to the project files and replace pcfltlib.lib with\npc881lib.lib in cjpeg.prj and djpeg.prj.  Or if you don't have a\ncoprocessor, you may prefer to remove the float DCT code by undefining\nDCT_FLOAT_SUPPORTED in jmorecfg.h (since without a coprocessor, the float\ncode will be too slow to be useful).  In that case, you can delete\npcfltlib.lib from the project files.\n\nNote that you must make libjpeg.lib before making cjpeg.ttp, djpeg.ttp,\nor jpegtran.ttp.  You'll have to perform the self-test by hand.\n\nWe haven't bothered to include project files for rdjpgcom and wrjpgcom.\nThose source files should just be compiled by themselves; they don't\ndepend on the JPEG library.  You can use the default.prj project file\nof the Pure C distribution to make the programs.\n\nThere is a bug in some older versions of the Turbo C library which causes the\nspace used by temporary files created with \"tmpfile()\" not to be freed after\nan abnormal program exit.  If you check your disk afterwards, you will find\ncluster chains that are allocated but not used by a file.  This should not\nhappen in cjpeg/djpeg/jpegtran, since we enable a signal catcher to explicitly\nclose temp files before exiting.  But if you use the JPEG library with your\nown code, be sure to supply a signal catcher, or else use a different\nsystem-dependent memory manager.\n\n\nCray:\n\nShould you be so fortunate as to be running JPEG on a Cray YMP, there is a\ncompiler bug in old versions of Cray's Standard C (prior to 3.1).  If you\nstill have an old compiler, you'll need to insert a line reading\n\"#pragma novector\" just before the loop\t\n    for (i = 1; i <= (int) htbl->bits[l]; i++)\n      huffsize[p++] = (char) l;\nin fix_huff_tbl (in V5beta1, line 204 of jchuff.c and line 176 of jdhuff.c).\n[This bug may or may not still occur with the current IJG code, but it's\nprobably a dead issue anyway...]\n\n\nHP-UX:\n\nIf you have HP-UX 7.05 or later with the \"software development\" C compiler,\nyou should run the compiler in ANSI mode.  If using the configure script,\nsay\n\t./configure CC='cc -Aa'\n(or -Ae if you prefer).  If configuring by hand, use makefile.ansi and add\n\"-Aa\" to the CFLAGS line in the makefile.\n\nIf you have a pre-7.05 system, or if you are using the non-ANSI C compiler\ndelivered with a minimum HP-UX system, then you must use makefile.unix\n(and do NOT add -Aa); or just run configure without the CC option.\n\nOn HP 9000 series 800 machines, the HP C compiler is buggy in revisions prior\nto A.08.07.  If you get complaints about \"not a typedef name\", you'll have to\nuse makefile.unix, or run configure without the CC option.\n\n\nMacintosh, generic comments:\n\nThe supplied user-interface files (cjpeg.c, djpeg.c, etc) are set up to\nprovide a Unix-style command line interface.  You can use this interface on\nthe Mac by means of the ccommand() library routine provided by Metrowerks\nCodeWarrior or Think C.  This is only appropriate for testing the library,\nhowever; to make a user-friendly equivalent of cjpeg/djpeg you'd really want\nto develop a Mac-style user interface.  There isn't a complete example\navailable at the moment, but there are some helpful starting points:\n1. Sam Bushell's free \"To JPEG\" applet provides drag-and-drop conversion to\nJPEG under System 7 and later.  This only illustrates how to use the\ncompression half of the library, but it does a very nice job of that part.\nThe CodeWarrior source code is available from http://www.pobox.com/~jsam.\n2. Jim Brunner prepared a Mac-style user interface for both compression and\ndecompression.  Unfortunately, it hasn't been updated since IJG v4, and\nthe library's API has changed considerably since then.  Still it may be of\nsome help, particularly as a guide to compiling the IJG code under Think C.\nJim's code is available from the Info-Mac archives, at sumex-aim.stanford.edu\nor mirrors thereof; see file /info-mac/dev/src/jpeg-convert-c.hqx.\n\njmemmac.c is the recommended memory manager back end for Macintosh.  It uses\nNewPtr/DisposePtr instead of malloc/free, and has a Mac-specific\nimplementation of jpeg_mem_available().  It also creates temporary files that\nfollow Mac conventions.  (That part of the code relies on System-7-or-later OS\nfunctions.  See the comments in jmemmac.c if you need to run it on System 6.)\nNOTE that USE_MAC_MEMMGR must be defined in jconfig.h to use jmemmac.c.\n\nYou can also use jmemnobs.c, if you don't care about handling images larger\nthan available memory.  If you use any memory manager back end other than\njmemmac.c, we recommend replacing \"malloc\" and \"free\" by \"NewPtr\" and\n\"DisposePtr\", because Mac C libraries often have peculiar implementations of\nmalloc/free.  (For instance, free() may not return the freed space to the\nMac Memory Manager.  This is undesirable for the IJG code because jmemmgr.c\nalready clumps space requests.)\n\n\nMacintosh, Metrowerks CodeWarrior:\n\nThe Unix-command-line-style interface can be used by defining USE_CCOMMAND.\nYou'll also need to define TWO_FILE_COMMANDLINE to avoid stdin/stdout.\nThis means that when using the cjpeg/djpeg programs, you'll have to type the\ninput and output file names in the \"Arguments\" text-edit box, rather than\nusing the file radio buttons.  (Perhaps USE_FDOPEN or USE_SETMODE would\neliminate the problem, but I haven't heard from anyone who's tried it.)\n\nOn 680x0 Macs, Metrowerks defines type \"double\" as a 10-byte IEEE extended\nfloat.  jmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power\nof 2.  Add \"#define ALIGN_TYPE long\" to jconfig.h to eliminate the complaint.\n\nThe supplied configuration file jconfig.mac can be used for your jconfig.h;\nit includes all the recommended symbol definitions.  If you have AppleScript\ninstalled, you can run the supplied script makeproj.mac to create CodeWarrior\nproject files for the library and the testbed applications, then build the\nlibrary and applications.  (Thanks to Dan Sears and Don Agro for this nifty\nhack, which saves us from trying to maintain CodeWarrior project files as part\nof the IJG distribution...)\n\n\nMacintosh, Think C:\n\nThe documentation in Jim Brunner's \"JPEG Convert\" source code (see above)\nincludes detailed build instructions for Think C; it's probably somewhat\nout of date for the current release, but may be helpful.\n\nIf you want to build the minimal command line version, proceed as follows.\nYou'll have to prepare project files for the programs; we don't include any\nin the distribution since they are not text files.  Use the file lists in\nany of the supplied makefiles as a guide.  Also add the ANSI and Unix C\nlibraries in a separate segment.  You may need to divide the JPEG files into\nmore than one segment; we recommend dividing compression and decompression\nmodules.  Define USE_CCOMMAND in jconfig.h so that the ccommand() routine is\ncalled.  You must also define TWO_FILE_COMMANDLINE because stdin/stdout\ndon't handle binary data correctly.\n\nOn 680x0 Macs, Think C defines type \"double\" as a 12-byte IEEE extended float.\njmemmgr.c won't like this: it wants sizeof(ALIGN_TYPE) to be a power of 2.\nAdd \"#define ALIGN_TYPE long\" to jconfig.h to eliminate the complaint.\n\njconfig.mac should work as a jconfig.h configuration file for Think C,\nbut the makeproj.mac AppleScript script is specific to CodeWarrior.  Sorry.\n\n\nMIPS R3000:\n\nMIPS's cc version 1.31 has a rather nasty optimization bug.  Don't use -O\nif you have that compiler version.  (Use \"cc -V\" to check the version.)\nNote that the R3000 chip is found in workstations from DEC and others.\n\n\nMS-DOS, generic comments for 16-bit compilers:\n\nThe IJG code is designed to work well in 80x86 \"small\" or \"medium\" memory\nmodels (i.e., data pointers are 16 bits unless explicitly declared \"far\";\ncode pointers can be either size).  You may be able to use small model to\ncompile cjpeg or djpeg by itself, but you will probably have to use medium\nmodel for any larger application.  This won't make much difference in\nperformance.  You *will* take a noticeable performance hit if you use a\nlarge-data memory model, and you should avoid \"huge\" model if at all\npossible.  Be sure that NEED_FAR_POINTERS is defined in jconfig.h if you use\na small-data memory model; be sure it is NOT defined if you use a large-data\nmodel.  (The supplied makefiles and jconfig files for Borland and Microsoft C\ncompile in medium model and define NEED_FAR_POINTERS.)\n\nThe DOS-specific memory manager, jmemdos.c, should be used if possible.\nIt needs some assembly-code routines which are in jmemdosa.asm; make sure\nyour makefile assembles that file and includes it in the library.  If you\ndon't have a suitable assembler, you can get pre-assembled object files for\njmemdosa by FTP from ftp.uu.net:/graphics/jpeg/jdosaobj.zip.  (DOS-oriented\ndistributions of the IJG source code often include these object files.)\n\nWhen using jmemdos.c, jconfig.h must define USE_MSDOS_MEMMGR and must set\nMAX_ALLOC_CHUNK to less than 64K (65520L is a typical value).  If your\nC library's far-heap malloc() can't allocate blocks that large, reduce\nMAX_ALLOC_CHUNK to whatever it can handle.\n\nIf you can't use jmemdos.c for some reason --- for example, because you\ndon't have an assembler to assemble jmemdosa.asm --- you'll have to fall\nback to jmemansi.c or jmemname.c.  You'll probably still need to set\nMAX_ALLOC_CHUNK in jconfig.h, because most DOS C libraries won't malloc()\nmore than 64K at a time.  IMPORTANT: if you use jmemansi.c or jmemname.c,\nyou will have to compile in a large-data memory model in order to get the\nright stdio library.  Too bad.\n\nwrjpgcom needs to be compiled in large model, because it malloc()s a 64KB\nwork area to hold the comment text.  If your C library's malloc can't\nhandle that, reduce MAX_COM_LENGTH as necessary in wrjpgcom.c.\n\nMost MS-DOS compilers treat stdin/stdout as text files, so you must use\ntwo-file command line style.  But if your compiler has either fdopen() or\nsetmode(), you can use one-file style if you like.  To do this, define\nUSE_SETMODE or USE_FDOPEN so that stdin/stdout will be set to binary mode.\n(USE_SETMODE seems to work with more DOS compilers than USE_FDOPEN.)  You\nshould test that I/O through stdin/stdout produces the same results as I/O\nto explicitly named files... the \"make test\" procedures in the supplied\nmakefiles do NOT use stdin/stdout.\n\n\nMS-DOS, generic comments for 32-bit compilers:\n\nNone of the above comments about memory models apply if you are using a\n32-bit flat-memory-space environment, such as DJGPP or Watcom C.  (And you\nshould use one if you have it, as performance will be much better than\n8086-compatible code!)  For flat-memory-space compilers, do NOT define\nNEED_FAR_POINTERS, and do NOT use jmemdos.c.  Use jmemnobs.c if the\nenvironment supplies adequate virtual memory, otherwise use jmemansi.c or\njmemname.c.\n\nYou'll still need to be careful about binary I/O through stdin/stdout.\nSee the last paragraph of the previous section.\n\n\nMS-DOS, Borland C:\n\nBe sure to convert all the source files to DOS text format (CR/LF newlines).\nAlthough Borland C will often work OK with unmodified Unix (LF newlines)\nsource files, sometimes it will give bogus compile errors.\n\"Illegal character '#'\" is the most common such error.  (This is true with\nBorland C 3.1, but perhaps is fixed in newer releases.)\n\nIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.\njconfig.bcc already includes #define USE_SETMODE to make this work.\n(fdopen does not work correctly.)\n\n\nMS-DOS, Microsoft C:\n\nmakefile.mc6 works with Microsoft C, DOS Visual C++, etc.  It should only\nbe used if you want to build a 16-bit (small or medium memory model) program.\n\nIf you want one-file command line style, just undefine TWO_FILE_COMMANDLINE.\njconfig.mc6 already includes #define USE_SETMODE to make this work.\n(fdopen does not work correctly.)\n\nNote that this makefile assumes that the working copy of itself is called\n\"makefile\".  If you want to call it something else, say \"makefile.mak\",\nbe sure to adjust the dependency line that reads \"$(RFILE) : makefile\".\nOtherwise the make will fail because it doesn't know how to create \"makefile\".\nWorse, some releases of Microsoft's make utilities give an incorrect error\nmessage in this situation.\n\nOld versions of MS C fail with an \"out of macro expansion space\" error\nbecause they can't cope with the macro TRACEMS8 (defined in jerror.h).\nIf this happens to you, the easiest solution is to change TRACEMS8 to\nexpand to nothing.  You'll lose the ability to dump out JPEG coefficient\ntables with djpeg -debug -debug, but at least you can compile.\n\nOriginal MS C 6.0 is very buggy; it compiles incorrect code unless you turn\noff optimization entirely (remove -O from CFLAGS).  6.00A is better, but it\nstill generates bad code if you enable loop optimizations (-Ol or -Ox).\n\nMS C 8.0 crashes when compiling jquant1.c with optimization switch /Oo ...\nwhich is on by default.  To work around this bug, compile that one file\nwith /Oo-.\n\n\nMicrosoft Windows (all versions), generic comments:\n\nSome Windows system include files define typedef boolean as \"unsigned char\".\nThe IJG code also defines typedef boolean, but we make it an \"enum\" by default.\nThis doesn't affect the IJG programs because we don't import those Windows\ninclude files.  But if you use the JPEG library in your own program, and some\nof your program's files import one definition of boolean while some import the\nother, you can get all sorts of mysterious problems.  A good preventive step\nis to make the IJG library use \"unsigned char\" for boolean.  To do that,\nadd something like this to your jconfig.h file:\n\t/* Define \"boolean\" as unsigned char, not enum, per Windows custom */\n\t#ifndef __RPCNDR_H__\t/* don't conflict if rpcndr.h already read */\n\ttypedef unsigned char boolean;\n\t#endif\n\t#ifndef FALSE\t\t/* in case these macros already exist */\n\t#define FALSE\t0\t/* values of boolean */\n\t#endif\n\t#ifndef TRUE\n\t#define TRUE\t1\n\t#endif\n\t#define HAVE_BOOLEAN\t/* prevent jmorecfg.h from redefining it */\n(This is already in jconfig.vc, by the way.)\n\nwindef.h contains the declarations\n\t#define far\n\t#define FAR far\nSince jmorecfg.h tries to define FAR as empty, you may get a compiler\nwarning if you include both jpeglib.h and windef.h (which windows.h\nincludes).  To suppress the warning, you can put \"#ifndef FAR\"/\"#endif\"\naround the line \"#define FAR\" in jmorecfg.h.\n(Something like this is already in jmorecfg.h, by the way.)\n\nWhen using the library in a Windows application, you will almost certainly\nwant to modify or replace the error handler module jerror.c, since our\ndefault error handler does a couple of inappropriate things:\n  1. it tries to write error and warning messages on stderr;\n  2. in event of a fatal error, it exits by calling exit().\n\nA simple stopgap solution for problem 1 is to replace the line\n\tfprintf(stderr, \"%s\\n\", buffer);\n(in output_message in jerror.c) with\n\tMessageBox(GetActiveWindow(),buffer,\"JPEG Error\",MB_OK|MB_ICONERROR);\nIt's highly recommended that you at least do that much, since otherwise\nerror messages will disappear into nowhere.  (Beginning with IJG v6b, this\ncode is already present in jerror.c; just define USE_WINDOWS_MESSAGEBOX in\njconfig.h to enable it.)\n\nThe proper solution for problem 2 is to return control to your calling\napplication after a library error.  This can be done with the setjmp/longjmp\ntechnique discussed in libjpeg.txt and illustrated in example.c.  (NOTE:\nsome older Windows C compilers provide versions of setjmp/longjmp that\ndon't actually work under Windows.  You may need to use the Windows system\nfunctions Catch and Throw instead.)\n\nThe recommended memory manager under Windows is jmemnobs.c; in other words,\nlet Windows do any virtual memory management needed.  You should NOT use\njmemdos.c nor jmemdosa.asm under Windows.\n\nFor Windows 3.1, we recommend compiling in medium or large memory model;\nfor newer Windows versions, use a 32-bit flat memory model.  (See the MS-DOS\nsections above for more info about memory models.)  In the 16-bit memory\nmodels only, you'll need to put\n\t#define MAX_ALLOC_CHUNK 65520L\t/* Maximum request to malloc() */\ninto jconfig.h to limit allocation chunks to 64Kb.  (Without that, you'd\nhave to use huge memory model, which slows things down unnecessarily.)\njmemnobs.c works without modification in large or flat memory models, but to\nuse medium model, you need to modify its jpeg_get_large and jpeg_free_large\nroutines to allocate far memory.  In any case, you might like to replace\nits calls to malloc and free with direct calls on Windows memory allocation\nfunctions.\n\nYou may also want to modify jdatasrc.c and jdatadst.c to use Windows file\noperations rather than fread/fwrite.  This is only necessary if your C\ncompiler doesn't provide a competent implementation of C stdio functions.\n\nYou might want to tweak the RGB_xxx macros in jmorecfg.h so that the library\nwill accept or deliver color pixels in BGR sample order, not RGB; BGR order\nis usually more convenient under Windows.  Note that this change will break\nthe sample applications cjpeg/djpeg, but the library itself works fine.\n\n\nMany people want to convert the IJG library into a DLL.  This is reasonably\nstraightforward, but watch out for the following:\n\n  1. Don't try to compile as a DLL in small or medium memory model; use\nlarge model, or even better, 32-bit flat model.  Many places in the IJG code\nassume the address of a local variable is an ordinary (not FAR) pointer;\nthat isn't true in a medium-model DLL.\n\n  2. Microsoft C cannot pass file pointers between applications and DLLs.\n(See Microsoft Knowledge Base, PSS ID Number Q50336.)  So jdatasrc.c and\njdatadst.c don't work if you open a file in your application and then pass\nthe pointer to the DLL.  One workaround is to make jdatasrc.c/jdatadst.c\npart of your main application rather than part of the DLL.\n\n  3. You'll probably need to modify the macros GLOBAL() and EXTERN() to\nattach suitable linkage keywords to the exported routine names.  Similarly,\nyou'll want to modify METHODDEF() and JMETHOD() to ensure function pointers\nare declared in a way that lets application routines be called back through\nthe function pointers.  These macros are in jmorecfg.h.  Typical definitions\nfor a 16-bit DLL are:\n\t#define GLOBAL(type)\t\ttype _far _pascal _loadds _export\n\t#define EXTERN(type)\t\textern type _far _pascal _loadds\n\t#define METHODDEF(type)\t\tstatic type _far _pascal\n\t#define JMETHOD(type,methodname,arglist)  \\\n\t\ttype (_far _pascal *methodname) arglist\nFor a 32-bit DLL you may want something like\n\t#define GLOBAL(type)\t\t__declspec(dllexport) type\n\t#define EXTERN(type)\t\textern __declspec(dllexport) type\nAlthough not all the GLOBAL routines are actually intended to be called by\nthe application, the performance cost of making them all DLL entry points is\nnegligible.\n\nThe unmodified IJG library presents a very C-specific application interface,\nso the resulting DLL is only usable from C or C++ applications.  There has\nbeen some talk of writing wrapper code that would present a simpler interface\nusable from other languages, such as Visual Basic.  This is on our to-do list\nbut hasn't been very high priority --- any volunteers out there?\n\n\nMicrosoft Windows, Borland C:\n\nThe provided jconfig.bcc should work OK in a 32-bit Windows environment,\nbut you'll need to tweak it in a 16-bit environment (you'd need to define\nNEED_FAR_POINTERS and MAX_ALLOC_CHUNK).  Beware that makefile.bcc will need\nalteration if you want to use it for Windows --- in particular, you should\nuse jmemnobs.c not jmemdos.c under Windows.\n\nBorland C++ 4.5 fails with an internal compiler error when trying to compile\njdmerge.c in 32-bit mode.  If enough people complain, perhaps Borland will fix\nit.  In the meantime, the simplest known workaround is to add a redundant\ndefinition of the variable range_limit in h2v1_merged_upsample(), at the head\nof the block that handles odd image width (about line 268 in v6 jdmerge.c):\n  /* If image width is odd, do the last output column separately */\n  if (cinfo->output_width & 1) {\n    register JSAMPLE * range_limit = cinfo->sample_range_limit; /* ADD THIS */\n    cb = GETJSAMPLE(*inptr1);\nPretty bizarre, especially since the very similar routine h2v2_merged_upsample\ndoesn't trigger the bug.\nRecent reports suggest that this bug does not occur with \"bcc32a\" (the\nPentium-optimized version of the compiler).\n\nAnother report from a user of Borland C 4.5 was that incorrect code (leading\nto a color shift in processed images) was produced if any of the following\noptimization switch combinations were used: \n\t-Ot -Og\n\t-Ot -Op\n\t-Ot -Om\nSo try backing off on optimization if you see such a problem.  (Are there\nseveral different releases all numbered \"4.5\"??)\n\n\nMicrosoft Windows, Microsoft Visual C++:\n\njconfig.vc should work OK with any Microsoft compiler for a 32-bit memory\nmodel.  makefile.vc is intended for command-line use.  (If you are using\nthe Developer Studio environment, you may prefer the DevStudio project\nfiles; see below.)\n\nIJG JPEG 7 adds extern \"C\" to jpeglib.h.  This avoids the need to put\nextern \"C\" { ... } around #include \"jpeglib.h\" in your C++ application.\nYou can also force VC++ to treat the library as C++ code by renaming\nall the *.c files to *.cpp (and adjusting the makefile to match).\nIn this case you also need to define the symbol DONT_USE_EXTERN_C in\nthe configuration to prevent jpeglib.h from using extern \"C\".\n\n\nMicrosoft Windows, Microsoft Visual C++ 6 Developer Studio:\n\nWe include makefiles that should work as project files in DevStudio 6.0 or\nlater.  There is a library makefile that builds the IJG library as a static\nWin32 library, and application makefiles that build the sample applications\nas Win32 console applications.  (Even if you only want the library, we\nrecommend building the applications so that you can run the self-test.)\n\nTo use:\n1. Open the command prompt, change to the main directory and execute the\n   command line\n\tNMAKE /f makefile.vc  setup-vc6\n   This will move jconfig.vc to jconfig.h and makefiles to project files.\n   (Note that the renaming is critical!)\n2. Open the workspace file jpeg.dsw, build the library project.\n   (If you are using DevStudio more recent than 6.0, you'll probably\n   get a message saying that the project files are being updated.)\n3. Open the workspace file apps.dsw, build the application projects.\n4. To perform the self-test, execute the command line\n\tNMAKE /f makefile.vc  test-build\n5. Move the application .exe files from `app`\\Release to an\n   appropriate location on your path.\n\n\nMicrosoft Windows, Microsoft Visual C++ 2010 Developer Studio (v10):\n\nWe include makefiles that should work as project files in Visual Studio\n2010 or later.  There is a library makefile that builds the IJG library\nas a static Win32 library, and application makefiles that build the sample\napplications as Win32 console applications.  (Even if you only want the\nlibrary, we recommend building the applications so that you can run the\nself-test.)\n\nTo use:\n1. Open the command prompt, change to the main directory and execute the\n   command line\n\tNMAKE /f makefile.vc  setup-v10\n   This will move jconfig.vc to jconfig.h and makefiles to project files.\n   (Note that the renaming is critical!)\n2. Open the solution file jpeg.sln, build the library project.\n   (If you are using Visual Studio more recent than 2010 (v10), you'll\n   probably get a message saying that the project files are being updated.)\n3. Open the solution file apps.sln, build the application projects.\n4. To perform the self-test, execute the command line\n\tNMAKE /f makefile.vc  test-build\n5. Move the application .exe files from `app`\\Release to an\n   appropriate location on your path.\n\nNote:\nThere seems to be an optimization bug in the compiler which causes the\nself-test to fail with the color quantization option.\nWe have disabled optimization for the file jquant2.c in the library\nproject file which causes the self-test to pass properly.\n\n\nOS/2, Borland C++:\n\nWatch out for optimization bugs in older Borland compilers; you may need\nto back off the optimization switch settings.  See the comments in\nmakefile.bcc.\n\n\nSGI:\n\nOn some SGI systems, you may need to set \"AR2= ar -ts\" in the Makefile.\nIf you are using configure, you can do this by saying\n\t./configure RANLIB='ar -ts'\nThis change is not needed on all SGIs.  Use it only if the make fails at the\nstage of linking the completed programs.\n\nOn the MIPS R4000 architecture (Indy, etc.), the compiler option \"-mips2\"\nreportedly speeds up the float DCT method substantially, enough to make it\nfaster than the default int method (but still slower than the fast int\nmethod).  If you use -mips2, you may want to alter the default DCT method to\nbe float.  To do this, put \"#define JDCT_DEFAULT JDCT_FLOAT\" in jconfig.h.\n\n\nVMS:\n\nOn an Alpha/VMS system with MMS, be sure to use the \"/Marco=Alpha=1\"\nqualifier with MMS when building the JPEG package.\n\nVAX/VMS v5.5-1 may have problems with the test step of the build procedure\nreporting differences when it compares the original and test images.  If the\nerror points to the last block of the files, it is most likely bogus and may\nbe safely ignored.  It seems to be because the files are Stream_LF and\nBackup/Compare has difficulty with the (presumably) null padded files.\nThis problem was not observed on VAX/VMS v6.1 or AXP/VMS v6.1.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jaricom.c",
    "content": "/*\n * jaricom.c\n *\n * Developed 1997-2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains probability estimation tables for common use in\n * arithmetic entropy encoding and decoding routines.\n *\n * This data represents Table D.3 in the JPEG spec (D.2 in the draft),\n * ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81, and Table 24\n * in the JBIG spec, ISO/IEC IS 11544 and CCITT Recommendation ITU-T T.82.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n/* The following #define specifies the packing of the four components\n * into the compact INT32 representation.\n * Note that this formula must match the actual arithmetic encoder\n * and decoder implementation.  The implementation has to be changed\n * if this formula is changed.\n * The current organization is leaned on Markus Kuhn's JBIG\n * implementation (jbig_tab.c).\n */\n\n#define V(i,a,b,c,d) (((INT32)a << 16) | ((INT32)c << 8) | ((INT32)d << 7) | b)\n\nconst INT32 jpeg_aritab[113+1] = {\n/*\n * Index, Qe_Value, Next_Index_LPS, Next_Index_MPS, Switch_MPS\n */\n  V(   0, 0x5a1d,   1,   1, 1 ),\n  V(   1, 0x2586,  14,   2, 0 ),\n  V(   2, 0x1114,  16,   3, 0 ),\n  V(   3, 0x080b,  18,   4, 0 ),\n  V(   4, 0x03d8,  20,   5, 0 ),\n  V(   5, 0x01da,  23,   6, 0 ),\n  V(   6, 0x00e5,  25,   7, 0 ),\n  V(   7, 0x006f,  28,   8, 0 ),\n  V(   8, 0x0036,  30,   9, 0 ),\n  V(   9, 0x001a,  33,  10, 0 ),\n  V(  10, 0x000d,  35,  11, 0 ),\n  V(  11, 0x0006,   9,  12, 0 ),\n  V(  12, 0x0003,  10,  13, 0 ),\n  V(  13, 0x0001,  12,  13, 0 ),\n  V(  14, 0x5a7f,  15,  15, 1 ),\n  V(  15, 0x3f25,  36,  16, 0 ),\n  V(  16, 0x2cf2,  38,  17, 0 ),\n  V(  17, 0x207c,  39,  18, 0 ),\n  V(  18, 0x17b9,  40,  19, 0 ),\n  V(  19, 0x1182,  42,  20, 0 ),\n  V(  20, 0x0cef,  43,  21, 0 ),\n  V(  21, 0x09a1,  45,  22, 0 ),\n  V(  22, 0x072f,  46,  23, 0 ),\n  V(  23, 0x055c,  48,  24, 0 ),\n  V(  24, 0x0406,  49,  25, 0 ),\n  V(  25, 0x0303,  51,  26, 0 ),\n  V(  26, 0x0240,  52,  27, 0 ),\n  V(  27, 0x01b1,  54,  28, 0 ),\n  V(  28, 0x0144,  56,  29, 0 ),\n  V(  29, 0x00f5,  57,  30, 0 ),\n  V(  30, 0x00b7,  59,  31, 0 ),\n  V(  31, 0x008a,  60,  32, 0 ),\n  V(  32, 0x0068,  62,  33, 0 ),\n  V(  33, 0x004e,  63,  34, 0 ),\n  V(  34, 0x003b,  32,  35, 0 ),\n  V(  35, 0x002c,  33,   9, 0 ),\n  V(  36, 0x5ae1,  37,  37, 1 ),\n  V(  37, 0x484c,  64,  38, 0 ),\n  V(  38, 0x3a0d,  65,  39, 0 ),\n  V(  39, 0x2ef1,  67,  40, 0 ),\n  V(  40, 0x261f,  68,  41, 0 ),\n  V(  41, 0x1f33,  69,  42, 0 ),\n  V(  42, 0x19a8,  70,  43, 0 ),\n  V(  43, 0x1518,  72,  44, 0 ),\n  V(  44, 0x1177,  73,  45, 0 ),\n  V(  45, 0x0e74,  74,  46, 0 ),\n  V(  46, 0x0bfb,  75,  47, 0 ),\n  V(  47, 0x09f8,  77,  48, 0 ),\n  V(  48, 0x0861,  78,  49, 0 ),\n  V(  49, 0x0706,  79,  50, 0 ),\n  V(  50, 0x05cd,  48,  51, 0 ),\n  V(  51, 0x04de,  50,  52, 0 ),\n  V(  52, 0x040f,  50,  53, 0 ),\n  V(  53, 0x0363,  51,  54, 0 ),\n  V(  54, 0x02d4,  52,  55, 0 ),\n  V(  55, 0x025c,  53,  56, 0 ),\n  V(  56, 0x01f8,  54,  57, 0 ),\n  V(  57, 0x01a4,  55,  58, 0 ),\n  V(  58, 0x0160,  56,  59, 0 ),\n  V(  59, 0x0125,  57,  60, 0 ),\n  V(  60, 0x00f6,  58,  61, 0 ),\n  V(  61, 0x00cb,  59,  62, 0 ),\n  V(  62, 0x00ab,  61,  63, 0 ),\n  V(  63, 0x008f,  61,  32, 0 ),\n  V(  64, 0x5b12,  65,  65, 1 ),\n  V(  65, 0x4d04,  80,  66, 0 ),\n  V(  66, 0x412c,  81,  67, 0 ),\n  V(  67, 0x37d8,  82,  68, 0 ),\n  V(  68, 0x2fe8,  83,  69, 0 ),\n  V(  69, 0x293c,  84,  70, 0 ),\n  V(  70, 0x2379,  86,  71, 0 ),\n  V(  71, 0x1edf,  87,  72, 0 ),\n  V(  72, 0x1aa9,  87,  73, 0 ),\n  V(  73, 0x174e,  72,  74, 0 ),\n  V(  74, 0x1424,  72,  75, 0 ),\n  V(  75, 0x119c,  74,  76, 0 ),\n  V(  76, 0x0f6b,  74,  77, 0 ),\n  V(  77, 0x0d51,  75,  78, 0 ),\n  V(  78, 0x0bb6,  77,  79, 0 ),\n  V(  79, 0x0a40,  77,  48, 0 ),\n  V(  80, 0x5832,  80,  81, 1 ),\n  V(  81, 0x4d1c,  88,  82, 0 ),\n  V(  82, 0x438e,  89,  83, 0 ),\n  V(  83, 0x3bdd,  90,  84, 0 ),\n  V(  84, 0x34ee,  91,  85, 0 ),\n  V(  85, 0x2eae,  92,  86, 0 ),\n  V(  86, 0x299a,  93,  87, 0 ),\n  V(  87, 0x2516,  86,  71, 0 ),\n  V(  88, 0x5570,  88,  89, 1 ),\n  V(  89, 0x4ca9,  95,  90, 0 ),\n  V(  90, 0x44d9,  96,  91, 0 ),\n  V(  91, 0x3e22,  97,  92, 0 ),\n  V(  92, 0x3824,  99,  93, 0 ),\n  V(  93, 0x32b4,  99,  94, 0 ),\n  V(  94, 0x2e17,  93,  86, 0 ),\n  V(  95, 0x56a8,  95,  96, 1 ),\n  V(  96, 0x4f46, 101,  97, 0 ),\n  V(  97, 0x47e5, 102,  98, 0 ),\n  V(  98, 0x41cf, 103,  99, 0 ),\n  V(  99, 0x3c3d, 104, 100, 0 ),\n  V( 100, 0x375e,  99,  93, 0 ),\n  V( 101, 0x5231, 105, 102, 0 ),\n  V( 102, 0x4c0f, 106, 103, 0 ),\n  V( 103, 0x4639, 107, 104, 0 ),\n  V( 104, 0x415e, 103,  99, 0 ),\n  V( 105, 0x5627, 105, 106, 1 ),\n  V( 106, 0x50e7, 108, 107, 0 ),\n  V( 107, 0x4b85, 109, 103, 0 ),\n  V( 108, 0x5597, 110, 109, 0 ),\n  V( 109, 0x504f, 111, 107, 0 ),\n  V( 110, 0x5a10, 110, 111, 1 ),\n  V( 111, 0x5522, 112, 109, 0 ),\n  V( 112, 0x59eb, 112, 111, 1 ),\n/*\n * This last entry is used for fixed probability estimate of 0.5\n * as suggested in Section 10.3 Table 5 of ITU-T Rec. T.851.\n */\n  V( 113, 0x5a1d, 113, 113, 0 )\n};\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcapimin.c",
    "content": "/*\n * jcapimin.c\n *\n * Copyright (C) 1994-1998, Thomas G. Lane.\n * Modified 2003-2010 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains application interface code for the compression half\n * of the JPEG library.  These are the \"minimum\" API routines that may be\n * needed in either the normal full-compression case or the transcoding-only\n * case.\n *\n * Most of the routines intended to be called directly by an application\n * are in this file or in jcapistd.c.  But also see jcparam.c for\n * parameter-setup helper routines, jcomapi.c for routines shared by\n * compression and decompression, and jctrans.c for the transcoding case.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Initialization of a JPEG compression object.\n * The error manager must already be set up (in case memory manager fails).\n */\n\nGLOBAL(void)\njpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)\n{\n  int i;\n\n  /* Guard against version mismatches between library and caller. */\n  cinfo->mem = NULL;\t\t/* so jpeg_destroy knows mem mgr not called */\n  if (version != JPEG_LIB_VERSION)\n    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);\n  if (structsize != SIZEOF(struct jpeg_compress_struct))\n    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, \n\t     (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);\n\n  /* For debugging purposes, we zero the whole master structure.\n   * But the application has already set the err pointer, and may have set\n   * client_data, so we have to save and restore those fields.\n   * Note: if application hasn't set client_data, tools like Purify may\n   * complain here.\n   */\n  {\n    struct jpeg_error_mgr * err = cinfo->err;\n    void * client_data = cinfo->client_data; /* ignore Purify complaint here */\n    MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));\n    cinfo->err = err;\n    cinfo->client_data = client_data;\n  }\n  cinfo->is_decompressor = FALSE;\n\n  /* Initialize a memory manager instance for this object */\n  jinit_memory_mgr((j_common_ptr) cinfo);\n\n  /* Zero out pointers to permanent structures. */\n  cinfo->progress = NULL;\n  cinfo->dest = NULL;\n\n  cinfo->comp_info = NULL;\n\n  for (i = 0; i < NUM_QUANT_TBLS; i++) {\n    cinfo->quant_tbl_ptrs[i] = NULL;\n    cinfo->q_scale_factor[i] = 100;\n  }\n\n  for (i = 0; i < NUM_HUFF_TBLS; i++) {\n    cinfo->dc_huff_tbl_ptrs[i] = NULL;\n    cinfo->ac_huff_tbl_ptrs[i] = NULL;\n  }\n\n  /* Must do it here for emit_dqt in case jpeg_write_tables is used */\n  cinfo->block_size = DCTSIZE;\n  cinfo->natural_order = jpeg_natural_order;\n  cinfo->lim_Se = DCTSIZE2-1;\n\n  cinfo->script_space = NULL;\n\n  cinfo->input_gamma = 1.0;\t/* in case application forgets */\n\n  /* OK, I'm ready */\n  cinfo->global_state = CSTATE_START;\n}\n\n\n/*\n * Destruction of a JPEG compression object\n */\n\nGLOBAL(void)\njpeg_destroy_compress (j_compress_ptr cinfo)\n{\n  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */\n}\n\n\n/*\n * Abort processing of a JPEG compression operation,\n * but don't destroy the object itself.\n */\n\nGLOBAL(void)\njpeg_abort_compress (j_compress_ptr cinfo)\n{\n  jpeg_abort((j_common_ptr) cinfo); /* use common routine */\n}\n\n\n/*\n * Forcibly suppress or un-suppress all quantization and Huffman tables.\n * Marks all currently defined tables as already written (if suppress)\n * or not written (if !suppress).  This will control whether they get emitted\n * by a subsequent jpeg_start_compress call.\n *\n * This routine is exported for use by applications that want to produce\n * abbreviated JPEG datastreams.  It logically belongs in jcparam.c, but\n * since it is called by jpeg_start_compress, we put it here --- otherwise\n * jcparam.o would be linked whether the application used it or not.\n */\n\nGLOBAL(void)\njpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)\n{\n  int i;\n  JQUANT_TBL * qtbl;\n  JHUFF_TBL * htbl;\n\n  for (i = 0; i < NUM_QUANT_TBLS; i++) {\n    if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)\n      qtbl->sent_table = suppress;\n  }\n\n  for (i = 0; i < NUM_HUFF_TBLS; i++) {\n    if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)\n      htbl->sent_table = suppress;\n    if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)\n      htbl->sent_table = suppress;\n  }\n}\n\n\n/*\n * Finish JPEG compression.\n *\n * If a multipass operating mode was selected, this may do a great deal of\n * work including most of the actual output.\n */\n\nGLOBAL(void)\njpeg_finish_compress (j_compress_ptr cinfo)\n{\n  JDIMENSION iMCU_row;\n\n  if (cinfo->global_state == CSTATE_SCANNING ||\n      cinfo->global_state == CSTATE_RAW_OK) {\n    /* Terminate first pass */\n    if (cinfo->next_scanline < cinfo->image_height)\n      ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);\n    (*cinfo->master->finish_pass) (cinfo);\n  } else if (cinfo->global_state != CSTATE_WRCOEFS)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  /* Perform any remaining passes */\n  while (! cinfo->master->is_last_pass) {\n    (*cinfo->master->prepare_for_pass) (cinfo);\n    for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {\n      if (cinfo->progress != NULL) {\n\tcinfo->progress->pass_counter = (long) iMCU_row;\n\tcinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;\n\t(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n      }\n      /* We bypass the main controller and invoke coef controller directly;\n       * all work is being done from the coefficient buffer.\n       */\n      if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))\n\tERREXIT(cinfo, JERR_CANT_SUSPEND);\n    }\n    (*cinfo->master->finish_pass) (cinfo);\n  }\n  /* Write EOI, do final cleanup */\n  (*cinfo->marker->write_file_trailer) (cinfo);\n  (*cinfo->dest->term_destination) (cinfo);\n  /* We can use jpeg_abort to release memory and reset global_state */\n  jpeg_abort((j_common_ptr) cinfo);\n}\n\n\n/*\n * Write a special marker.\n * This is only recommended for writing COM or APPn markers.\n * Must be called after jpeg_start_compress() and before\n * first call to jpeg_write_scanlines() or jpeg_write_raw_data().\n */\n\nGLOBAL(void)\njpeg_write_marker (j_compress_ptr cinfo, int marker,\n\t\t   const JOCTET *dataptr, unsigned int datalen)\n{\n  JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));\n\n  if (cinfo->next_scanline != 0 ||\n      (cinfo->global_state != CSTATE_SCANNING &&\n       cinfo->global_state != CSTATE_RAW_OK &&\n       cinfo->global_state != CSTATE_WRCOEFS))\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);\n  write_marker_byte = cinfo->marker->write_marker_byte;\t/* copy for speed */\n  while (datalen--) {\n    (*write_marker_byte) (cinfo, *dataptr);\n    dataptr++;\n  }\n}\n\n/* Same, but piecemeal. */\n\nGLOBAL(void)\njpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)\n{\n  if (cinfo->next_scanline != 0 ||\n      (cinfo->global_state != CSTATE_SCANNING &&\n       cinfo->global_state != CSTATE_RAW_OK &&\n       cinfo->global_state != CSTATE_WRCOEFS))\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);\n}\n\nGLOBAL(void)\njpeg_write_m_byte (j_compress_ptr cinfo, int val)\n{\n  (*cinfo->marker->write_marker_byte) (cinfo, val);\n}\n\n\n/*\n * Alternate compression function: just write an abbreviated table file.\n * Before calling this, all parameters and a data destination must be set up.\n *\n * To produce a pair of files containing abbreviated tables and abbreviated\n * image data, one would proceed as follows:\n *\n *\t\tinitialize JPEG object\n *\t\tset JPEG parameters\n *\t\tset destination to table file\n *\t\tjpeg_write_tables(cinfo);\n *\t\tset destination to image file\n *\t\tjpeg_start_compress(cinfo, FALSE);\n *\t\twrite data...\n *\t\tjpeg_finish_compress(cinfo);\n *\n * jpeg_write_tables has the side effect of marking all tables written\n * (same as jpeg_suppress_tables(..., TRUE)).  Thus a subsequent start_compress\n * will not re-emit the tables unless it is passed write_all_tables=TRUE.\n */\n\nGLOBAL(void)\njpeg_write_tables (j_compress_ptr cinfo)\n{\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  /* (Re)initialize error mgr and destination modules */\n  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);\n  (*cinfo->dest->init_destination) (cinfo);\n  /* Initialize the marker writer ... bit of a crock to do it here. */\n  jinit_marker_writer(cinfo);\n  /* Write them tables! */\n  (*cinfo->marker->write_tables_only) (cinfo);\n  /* And clean up. */\n  (*cinfo->dest->term_destination) (cinfo);\n  /*\n   * In library releases up through v6a, we called jpeg_abort() here to free\n   * any working memory allocated by the destination manager and marker\n   * writer.  Some applications had a problem with that: they allocated space\n   * of their own from the library memory manager, and didn't want it to go\n   * away during write_tables.  So now we do nothing.  This will cause a\n   * memory leak if an app calls write_tables repeatedly without doing a full\n   * compression cycle or otherwise resetting the JPEG object.  However, that\n   * seems less bad than unexpectedly freeing memory in the normal case.\n   * An app that prefers the old behavior can call jpeg_abort for itself after\n   * each call to jpeg_write_tables().\n   */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcapistd.c",
    "content": "/*\n * jcapistd.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains application interface code for the compression half\n * of the JPEG library.  These are the \"standard\" API routines that are\n * used in the normal full-compression case.  They are not used by a\n * transcoding-only application.  Note that if an application links in\n * jpeg_start_compress, it will end up linking in the entire compressor.\n * We thus must separate this file from jcapimin.c to avoid linking the\n * whole compression library into a transcoder.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Compression initialization.\n * Before calling this, all parameters and a data destination must be set up.\n *\n * We require a write_all_tables parameter as a failsafe check when writing\n * multiple datastreams from the same compression object.  Since prior runs\n * will have left all the tables marked sent_table=TRUE, a subsequent run\n * would emit an abbreviated stream (no tables) by default.  This may be what\n * is wanted, but for safety's sake it should not be the default behavior:\n * programmers should have to make a deliberate choice to emit abbreviated\n * images.  Therefore the documentation and examples should encourage people\n * to pass write_all_tables=TRUE; then it will take active thought to do the\n * wrong thing.\n */\n\nGLOBAL(void)\njpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)\n{\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  if (write_all_tables)\n    jpeg_suppress_tables(cinfo, FALSE);\t/* mark all tables to be written */\n\n  /* (Re)initialize error mgr and destination modules */\n  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);\n  (*cinfo->dest->init_destination) (cinfo);\n  /* Perform master selection of active modules */\n  jinit_compress_master(cinfo);\n  /* Set up for the first pass */\n  (*cinfo->master->prepare_for_pass) (cinfo);\n  /* Ready for application to drive first pass through jpeg_write_scanlines\n   * or jpeg_write_raw_data.\n   */\n  cinfo->next_scanline = 0;\n  cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);\n}\n\n\n/*\n * Write some scanlines of data to the JPEG compressor.\n *\n * The return value will be the number of lines actually written.\n * This should be less than the supplied num_lines only in case that\n * the data destination module has requested suspension of the compressor,\n * or if more than image_height scanlines are passed in.\n *\n * Note: we warn about excess calls to jpeg_write_scanlines() since\n * this likely signals an application programmer error.  However,\n * excess scanlines passed in the last valid call are *silently* ignored,\n * so that the application need not adjust num_lines for end-of-image\n * when using a multiple-scanline buffer.\n */\n\nGLOBAL(JDIMENSION)\njpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,\n\t\t      JDIMENSION num_lines)\n{\n  JDIMENSION row_ctr, rows_left;\n\n  if (cinfo->global_state != CSTATE_SCANNING)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  if (cinfo->next_scanline >= cinfo->image_height)\n    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\n\n  /* Call progress monitor hook if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->pass_counter = (long) cinfo->next_scanline;\n    cinfo->progress->pass_limit = (long) cinfo->image_height;\n    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n  }\n\n  /* Give master control module another chance if this is first call to\n   * jpeg_write_scanlines.  This lets output of the frame/scan headers be\n   * delayed so that application can write COM, etc, markers between\n   * jpeg_start_compress and jpeg_write_scanlines.\n   */\n  if (cinfo->master->call_pass_startup)\n    (*cinfo->master->pass_startup) (cinfo);\n\n  /* Ignore any extra scanlines at bottom of image. */\n  rows_left = cinfo->image_height - cinfo->next_scanline;\n  if (num_lines > rows_left)\n    num_lines = rows_left;\n\n  row_ctr = 0;\n  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);\n  cinfo->next_scanline += row_ctr;\n  return row_ctr;\n}\n\n\n/*\n * Alternate entry point to write raw data.\n * Processes exactly one iMCU row per call, unless suspended.\n */\n\nGLOBAL(JDIMENSION)\njpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,\n\t\t     JDIMENSION num_lines)\n{\n  JDIMENSION lines_per_iMCU_row;\n\n  if (cinfo->global_state != CSTATE_RAW_OK)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  if (cinfo->next_scanline >= cinfo->image_height) {\n    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\n    return 0;\n  }\n\n  /* Call progress monitor hook if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->pass_counter = (long) cinfo->next_scanline;\n    cinfo->progress->pass_limit = (long) cinfo->image_height;\n    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n  }\n\n  /* Give master control module another chance if this is first call to\n   * jpeg_write_raw_data.  This lets output of the frame/scan headers be\n   * delayed so that application can write COM, etc, markers between\n   * jpeg_start_compress and jpeg_write_raw_data.\n   */\n  if (cinfo->master->call_pass_startup)\n    (*cinfo->master->pass_startup) (cinfo);\n\n  /* Verify that at least one iMCU row has been passed. */\n  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;\n  if (num_lines < lines_per_iMCU_row)\n    ERREXIT(cinfo, JERR_BUFFER_SIZE);\n\n  /* Directly compress the row. */\n  if (! (*cinfo->coef->compress_data) (cinfo, data)) {\n    /* If compressor did not consume the whole row, suspend processing. */\n    return 0;\n  }\n\n  /* OK, we processed one iMCU row. */\n  cinfo->next_scanline += lines_per_iMCU_row;\n  return lines_per_iMCU_row;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcarith.c",
    "content": "/*\n * jcarith.c\n *\n * Developed 1997-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains portable arithmetic entropy encoding routines for JPEG\n * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).\n *\n * Both sequential and progressive modes are supported in this single module.\n *\n * Suspension is not currently supported in this module.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Expanded entropy encoder object for arithmetic encoding. */\n\ntypedef struct {\n  struct jpeg_entropy_encoder pub; /* public fields */\n\n  INT32 c; /* C register, base of coding interval, layout as in sec. D.1.3 */\n  INT32 a;               /* A register, normalized size of coding interval */\n  INT32 sc;        /* counter for stacked 0xFF values which might overflow */\n  INT32 zc;          /* counter for pending 0x00 output values which might *\n                          * be discarded at the end (\"Pacman\" termination) */\n  int ct;  /* bit shift counter, determines when next byte will be written */\n  int buffer;                /* buffer for most recent output byte != 0xFF */\n\n  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */\n  int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */\n\n  unsigned int restarts_to_go;\t/* MCUs left in this restart interval */\n  int next_restart_num;\t\t/* next restart number to write (0-7) */\n\n  /* Pointers to statistics areas (these workspaces have image lifespan) */\n  unsigned char * dc_stats[NUM_ARITH_TBLS];\n  unsigned char * ac_stats[NUM_ARITH_TBLS];\n\n  /* Statistics bin for coding with fixed probability 0.5 */\n  unsigned char fixed_bin[4];\n} arith_entropy_encoder;\n\ntypedef arith_entropy_encoder * arith_entropy_ptr;\n\n/* The following two definitions specify the allocation chunk size\n * for the statistics area.\n * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least\n * 49 statistics bins for DC, and 245 statistics bins for AC coding.\n *\n * We use a compact representation with 1 byte per statistics bin,\n * thus the numbers directly represent byte sizes.\n * This 1 byte per statistics bin contains the meaning of the MPS\n * (more probable symbol) in the highest bit (mask 0x80), and the\n * index into the probability estimation state machine table\n * in the lower bits (mask 0x7F).\n */\n\n#define DC_STAT_BINS 64\n#define AC_STAT_BINS 256\n\n/* NOTE: Uncomment the following #define if you want to use the\n * given formula for calculating the AC conditioning parameter Kx\n * for spectral selection progressive coding in section G.1.3.2\n * of the spec (Kx = Kmin + SRL (8 + Se - Kmin) 4).\n * Although the spec and P&M authors claim that this \"has proven\n * to give good results for 8 bit precision samples\", I'm not\n * convinced yet that this is really beneficial.\n * Early tests gave only very marginal compression enhancements\n * (a few - around 5 or so - bytes even for very large files),\n * which would turn out rather negative if we'd suppress the\n * DAC (Define Arithmetic Conditioning) marker segments for\n * the default parameters in the future.\n * Note that currently the marker writing module emits 12-byte\n * DAC segments for a full-component scan in a color image.\n * This is not worth worrying about IMHO. However, since the\n * spec defines the default values to be used if the tables\n * are omitted (unlike Huffman tables, which are required\n * anyway), one might optimize this behaviour in the future,\n * and then it would be disadvantageous to use custom tables if\n * they don't provide sufficient gain to exceed the DAC size.\n *\n * On the other hand, I'd consider it as a reasonable result\n * that the conditioning has no significant influence on the\n * compression performance. This means that the basic\n * statistical model is already rather stable.\n *\n * Thus, at the moment, we use the default conditioning values\n * anyway, and do not use the custom formula.\n *\n#define CALCULATE_SPECTRAL_CONDITIONING\n */\n\n/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.\n * We assume that int right shift is unsigned if INT32 right shift is,\n * which should be safe.\n */\n\n#ifdef RIGHT_SHIFT_IS_UNSIGNED\n#define ISHIFT_TEMPS\tint ishift_temp;\n#define IRIGHT_SHIFT(x,shft)  \\\n\t((ishift_temp = (x)) < 0 ? \\\n\t (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \\\n\t (ishift_temp >> (shft)))\n#else\n#define ISHIFT_TEMPS\n#define IRIGHT_SHIFT(x,shft)\t((x) >> (shft))\n#endif\n\n\nLOCAL(void)\nemit_byte (int val, j_compress_ptr cinfo)\n/* Write next output byte; we do not support suspension in this module. */\n{\n  struct jpeg_destination_mgr * dest = cinfo->dest;\n\n  *dest->next_output_byte++ = (JOCTET) val;\n  if (--dest->free_in_buffer == 0)\n    if (! (*dest->empty_output_buffer) (cinfo))\n      ERREXIT(cinfo, JERR_CANT_SUSPEND);\n}\n\n\n/*\n * Finish up at the end of an arithmetic-compressed scan.\n */\n\nMETHODDEF(void)\nfinish_pass (j_compress_ptr cinfo)\n{\n  arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;\n  INT32 temp;\n\n  /* Section D.1.8: Termination of encoding */\n\n  /* Find the e->c in the coding interval with the largest\n   * number of trailing zero bits */\n  if ((temp = (e->a - 1 + e->c) & 0xFFFF0000L) < e->c)\n    e->c = temp + 0x8000L;\n  else\n    e->c = temp;\n  /* Send remaining bytes to output */\n  e->c <<= e->ct;\n  if (e->c & 0xF8000000L) {\n    /* One final overflow has to be handled */\n    if (e->buffer >= 0) {\n      if (e->zc)\n\tdo emit_byte(0x00, cinfo);\n\twhile (--e->zc);\n      emit_byte(e->buffer + 1, cinfo);\n      if (e->buffer + 1 == 0xFF)\n\temit_byte(0x00, cinfo);\n    }\n    e->zc += e->sc;  /* carry-over converts stacked 0xFF bytes to 0x00 */\n    e->sc = 0;\n  } else {\n    if (e->buffer == 0)\n      ++e->zc;\n    else if (e->buffer >= 0) {\n      if (e->zc)\n\tdo emit_byte(0x00, cinfo);\n\twhile (--e->zc);\n      emit_byte(e->buffer, cinfo);\n    }\n    if (e->sc) {\n      if (e->zc)\n\tdo emit_byte(0x00, cinfo);\n\twhile (--e->zc);\n      do {\n\temit_byte(0xFF, cinfo);\n\temit_byte(0x00, cinfo);\n      } while (--e->sc);\n    }\n  }\n  /* Output final bytes only if they are not 0x00 */\n  if (e->c & 0x7FFF800L) {\n    if (e->zc)  /* output final pending zero bytes */\n      do emit_byte(0x00, cinfo);\n      while (--e->zc);\n    emit_byte((e->c >> 19) & 0xFF, cinfo);\n    if (((e->c >> 19) & 0xFF) == 0xFF)\n      emit_byte(0x00, cinfo);\n    if (e->c & 0x7F800L) {\n      emit_byte((e->c >> 11) & 0xFF, cinfo);\n      if (((e->c >> 11) & 0xFF) == 0xFF)\n\temit_byte(0x00, cinfo);\n    }\n  }\n}\n\n\n/*\n * The core arithmetic encoding routine (common in JPEG and JBIG).\n * This needs to go as fast as possible.\n * Machine-dependent optimization facilities\n * are not utilized in this portable implementation.\n * However, this code should be fairly efficient and\n * may be a good base for further optimizations anyway.\n *\n * Parameter 'val' to be encoded may be 0 or 1 (binary decision).\n *\n * Note: I've added full \"Pacman\" termination support to the\n * byte output routines, which is equivalent to the optional\n * Discard_final_zeros procedure (Figure D.15) in the spec.\n * Thus, we always produce the shortest possible output\n * stream compliant to the spec (no trailing zero bytes,\n * except for FF stuffing).\n *\n * I've also introduced a new scheme for accessing\n * the probability estimation state machine table,\n * derived from Markus Kuhn's JBIG implementation.\n */\n\nLOCAL(void)\narith_encode (j_compress_ptr cinfo, unsigned char *st, int val) \n{\n  register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;\n  register unsigned char nl, nm;\n  register INT32 qe, temp;\n  register int sv;\n\n  /* Fetch values from our compact representation of Table D.3(D.2):\n   * Qe values and probability estimation state machine\n   */\n  sv = *st;\n  qe = jpeg_aritab[sv & 0x7F];\t/* => Qe_Value */\n  nl = qe & 0xFF; qe >>= 8;\t/* Next_Index_LPS + Switch_MPS */\n  nm = qe & 0xFF; qe >>= 8;\t/* Next_Index_MPS */\n\n  /* Encode & estimation procedures per sections D.1.4 & D.1.5 */\n  e->a -= qe;\n  if (val != (sv >> 7)) {\n    /* Encode the less probable symbol */\n    if (e->a >= qe) {\n      /* If the interval size (qe) for the less probable symbol (LPS)\n       * is larger than the interval size for the MPS, then exchange\n       * the two symbols for coding efficiency, otherwise code the LPS\n       * as usual: */\n      e->c += e->a;\n      e->a = qe;\n    }\n    *st = (sv & 0x80) ^ nl;\t/* Estimate_after_LPS */\n  } else {\n    /* Encode the more probable symbol */\n    if (e->a >= 0x8000L)\n      return;  /* A >= 0x8000 -> ready, no renormalization required */\n    if (e->a < qe) {\n      /* If the interval size (qe) for the less probable symbol (LPS)\n       * is larger than the interval size for the MPS, then exchange\n       * the two symbols for coding efficiency: */\n      e->c += e->a;\n      e->a = qe;\n    }\n    *st = (sv & 0x80) ^ nm;\t/* Estimate_after_MPS */\n  }\n\n  /* Renormalization & data output per section D.1.6 */\n  do {\n    e->a <<= 1;\n    e->c <<= 1;\n    if (--e->ct == 0) {\n      /* Another byte is ready for output */\n      temp = e->c >> 19;\n      if (temp > 0xFF) {\n\t/* Handle overflow over all stacked 0xFF bytes */\n\tif (e->buffer >= 0) {\n\t  if (e->zc)\n\t    do emit_byte(0x00, cinfo);\n\t    while (--e->zc);\n\t  emit_byte(e->buffer + 1, cinfo);\n\t  if (e->buffer + 1 == 0xFF)\n\t    emit_byte(0x00, cinfo);\n\t}\n\te->zc += e->sc;  /* carry-over converts stacked 0xFF bytes to 0x00 */\n\te->sc = 0;\n\t/* Note: The 3 spacer bits in the C register guarantee\n\t * that the new buffer byte can't be 0xFF here\n\t * (see page 160 in the P&M JPEG book). */\n\te->buffer = temp & 0xFF;  /* new output byte, might overflow later */\n      } else if (temp == 0xFF) {\n\t++e->sc;  /* stack 0xFF byte (which might overflow later) */\n      } else {\n\t/* Output all stacked 0xFF bytes, they will not overflow any more */\n\tif (e->buffer == 0)\n\t  ++e->zc;\n\telse if (e->buffer >= 0) {\n\t  if (e->zc)\n\t    do emit_byte(0x00, cinfo);\n\t    while (--e->zc);\n\t  emit_byte(e->buffer, cinfo);\n\t}\n\tif (e->sc) {\n\t  if (e->zc)\n\t    do emit_byte(0x00, cinfo);\n\t    while (--e->zc);\n\t  do {\n\t    emit_byte(0xFF, cinfo);\n\t    emit_byte(0x00, cinfo);\n\t  } while (--e->sc);\n\t}\n\te->buffer = temp & 0xFF;  /* new output byte (can still overflow) */\n      }\n      e->c &= 0x7FFFFL;\n      e->ct += 8;\n    }\n  } while (e->a < 0x8000L);\n}\n\n\n/*\n * Emit a restart marker & resynchronize predictions.\n */\n\nLOCAL(void)\nemit_restart (j_compress_ptr cinfo, int restart_num)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  int ci;\n  jpeg_component_info * compptr;\n\n  finish_pass(cinfo);\n\n  emit_byte(0xFF, cinfo);\n  emit_byte(JPEG_RST0 + restart_num, cinfo);\n\n  /* Re-initialize statistics areas */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    /* DC needs no table for refinement scan */\n    if (cinfo->Ss == 0 && cinfo->Ah == 0) {\n      MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);\n      /* Reset DC predictions to 0 */\n      entropy->last_dc_val[ci] = 0;\n      entropy->dc_context[ci] = 0;\n    }\n    /* AC needs no table when not present */\n    if (cinfo->Se) {\n      MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);\n    }\n  }\n\n  /* Reset arithmetic encoding variables */\n  entropy->c = 0;\n  entropy->a = 0x10000L;\n  entropy->sc = 0;\n  entropy->zc = 0;\n  entropy->ct = 11;\n  entropy->buffer = -1;  /* empty */\n}\n\n\n/*\n * MCU encoding for DC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\nencode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  unsigned char *st;\n  int blkn, ci, tbl;\n  int v, v2, m;\n  ISHIFT_TEMPS\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      emit_restart(cinfo, entropy->next_restart_num);\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    ci = cinfo->MCU_membership[blkn];\n    tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;\n\n    /* Compute the DC value after the required point transform by Al.\n     * This is simply an arithmetic right shift.\n     */\n    m = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);\n\n    /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */\n\n    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */\n    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];\n\n    /* Figure F.4: Encode_DC_DIFF */\n    if ((v = m - entropy->last_dc_val[ci]) == 0) {\n      arith_encode(cinfo, st, 0);\n      entropy->dc_context[ci] = 0;\t/* zero diff category */\n    } else {\n      entropy->last_dc_val[ci] = m;\n      arith_encode(cinfo, st, 1);\n      /* Figure F.6: Encoding nonzero value v */\n      /* Figure F.7: Encoding the sign of v */\n      if (v > 0) {\n\tarith_encode(cinfo, st + 1, 0);\t/* Table F.4: SS = S0 + 1 */\n\tst += 2;\t\t\t/* Table F.4: SP = S0 + 2 */\n\tentropy->dc_context[ci] = 4;\t/* small positive diff category */\n      } else {\n\tv = -v;\n\tarith_encode(cinfo, st + 1, 1);\t/* Table F.4: SS = S0 + 1 */\n\tst += 3;\t\t\t/* Table F.4: SN = S0 + 3 */\n\tentropy->dc_context[ci] = 8;\t/* small negative diff category */\n      }\n      /* Figure F.8: Encoding the magnitude category of v */\n      m = 0;\n      if (v -= 1) {\n\tarith_encode(cinfo, st, 1);\n\tm = 1;\n\tv2 = v;\n\tst = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */\n\twhile (v2 >>= 1) {\n\t  arith_encode(cinfo, st, 1);\n\t  m <<= 1;\n\t  st += 1;\n\t}\n      }\n      arith_encode(cinfo, st, 0);\n      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */\n      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))\n\tentropy->dc_context[ci] = 0;\t/* zero diff category */\n      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))\n\tentropy->dc_context[ci] += 8;\t/* large diff category */\n      /* Figure F.9: Encoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tarith_encode(cinfo, st, (m & v) ? 1 : 0);\n    }\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for AC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\nencode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  JBLOCKROW block;\n  unsigned char *st;\n  int tbl, k, ke;\n  int v, v2, m;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      emit_restart(cinfo, entropy->next_restart_num);\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  natural_order = cinfo->natural_order;\n\n  /* Encode the MCU data block */\n  block = MCU_data[0];\n  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;\n\n  /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */\n\n  /* Establish EOB (end-of-block) index */\n  ke = cinfo->Se;\n  do {\n    /* We must apply the point transform by Al.  For AC coefficients this\n     * is an integer division with rounding towards 0.  To do this portably\n     * in C, we shift after obtaining the absolute value.\n     */\n    if ((v = (*block)[natural_order[ke]]) >= 0) {\n      if (v >>= cinfo->Al) break;\n    } else {\n      v = -v;\n      if (v >>= cinfo->Al) break;\n    }\n  } while (--ke);\n\n  /* Figure F.5: Encode_AC_Coefficients */\n  for (k = cinfo->Ss - 1; k < ke;) {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    arith_encode(cinfo, st, 0);\t\t/* EOB decision */\n    for (;;) {\n      if ((v = (*block)[natural_order[++k]]) >= 0) {\n\tif (v >>= cinfo->Al) {\n\t  arith_encode(cinfo, st + 1, 1);\n\t  arith_encode(cinfo, entropy->fixed_bin, 0);\n\t  break;\n\t}\n      } else {\n\tv = -v;\n\tif (v >>= cinfo->Al) {\n\t  arith_encode(cinfo, st + 1, 1);\n\t  arith_encode(cinfo, entropy->fixed_bin, 1);\n\t  break;\n\t}\n      }\n      arith_encode(cinfo, st + 1, 0);\n      st += 3;\n    }\n    st += 2;\n    /* Figure F.8: Encoding the magnitude category of v */\n    m = 0;\n    if (v -= 1) {\n      arith_encode(cinfo, st, 1);\n      m = 1;\n      v2 = v;\n      if (v2 >>= 1) {\n\tarith_encode(cinfo, st, 1);\n\tm <<= 1;\n\tst = entropy->ac_stats[tbl] +\n\t     (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);\n\twhile (v2 >>= 1) {\n\t  arith_encode(cinfo, st, 1);\n\t  m <<= 1;\n\t  st += 1;\n\t}\n      }\n    }\n    arith_encode(cinfo, st, 0);\n    /* Figure F.9: Encoding the magnitude bit pattern of v */\n    st += 14;\n    while (m >>= 1)\n      arith_encode(cinfo, st, (m & v) ? 1 : 0);\n  }\n  /* Encode EOB decision only if k < cinfo->Se */\n  if (k < cinfo->Se) {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    arith_encode(cinfo, st, 1);\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for DC successive approximation refinement scan.\n * Note: we assume such scans can be multi-component,\n * although the spec is not very clear on the point.\n */\n\nMETHODDEF(boolean)\nencode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  unsigned char *st;\n  int Al, blkn;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      emit_restart(cinfo, entropy->next_restart_num);\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  st = entropy->fixed_bin;\t/* use fixed probability estimation */\n  Al = cinfo->Al;\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    /* We simply emit the Al'th bit of the DC coefficient value. */\n    arith_encode(cinfo, st, (MCU_data[blkn][0][0] >> Al) & 1);\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for AC successive approximation refinement scan.\n */\n\nMETHODDEF(boolean)\nencode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  JBLOCKROW block;\n  unsigned char *st;\n  int tbl, k, ke, kex;\n  int v;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      emit_restart(cinfo, entropy->next_restart_num);\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  natural_order = cinfo->natural_order;\n\n  /* Encode the MCU data block */\n  block = MCU_data[0];\n  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;\n\n  /* Section G.1.3.3: Encoding of AC coefficients */\n\n  /* Establish EOB (end-of-block) index */\n  ke = cinfo->Se;\n  do {\n    /* We must apply the point transform by Al.  For AC coefficients this\n     * is an integer division with rounding towards 0.  To do this portably\n     * in C, we shift after obtaining the absolute value.\n     */\n    if ((v = (*block)[natural_order[ke]]) >= 0) {\n      if (v >>= cinfo->Al) break;\n    } else {\n      v = -v;\n      if (v >>= cinfo->Al) break;\n    }\n  } while (--ke);\n\n  /* Establish EOBx (previous stage end-of-block) index */\n  for (kex = ke; kex > 0; kex--)\n    if ((v = (*block)[natural_order[kex]]) >= 0) {\n      if (v >>= cinfo->Ah) break;\n    } else {\n      v = -v;\n      if (v >>= cinfo->Ah) break;\n    }\n\n  /* Figure G.10: Encode_AC_Coefficients_SA */\n  for (k = cinfo->Ss - 1; k < ke;) {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    if (k >= kex)\n      arith_encode(cinfo, st, 0);\t/* EOB decision */\n    for (;;) {\n      if ((v = (*block)[natural_order[++k]]) >= 0) {\n\tif (v >>= cinfo->Al) {\n\t  if (v >> 1)\t\t\t/* previously nonzero coef */\n\t    arith_encode(cinfo, st + 2, (v & 1));\n\t  else {\t\t\t/* newly nonzero coef */\n\t    arith_encode(cinfo, st + 1, 1);\n\t    arith_encode(cinfo, entropy->fixed_bin, 0);\n\t  }\n\t  break;\n\t}\n      } else {\n\tv = -v;\n\tif (v >>= cinfo->Al) {\n\t  if (v >> 1)\t\t\t/* previously nonzero coef */\n\t    arith_encode(cinfo, st + 2, (v & 1));\n\t  else {\t\t\t/* newly nonzero coef */\n\t    arith_encode(cinfo, st + 1, 1);\n\t    arith_encode(cinfo, entropy->fixed_bin, 1);\n\t  }\n\t  break;\n\t}\n      }\n      arith_encode(cinfo, st + 1, 0);\n      st += 3;\n    }\n  }\n  /* Encode EOB decision only if k < cinfo->Se */\n  if (k < cinfo->Se) {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    arith_encode(cinfo, st, 1);\n  }\n\n  return TRUE;\n}\n\n\n/*\n * Encode and output one MCU's worth of arithmetic-compressed coefficients.\n */\n\nMETHODDEF(boolean)\nencode_mcu (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  JBLOCKROW block;\n  unsigned char *st;\n  int tbl, k, ke;\n  int v, v2, m;\n  int blkn, ci;\n  jpeg_component_info * compptr;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      emit_restart(cinfo, entropy->next_restart_num);\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  natural_order = cinfo->natural_order;\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    block = MCU_data[blkn];\n    ci = cinfo->MCU_membership[blkn];\n    compptr = cinfo->cur_comp_info[ci];\n\n    /* Sections F.1.4.1 & F.1.4.4.1: Encoding of DC coefficients */\n\n    tbl = compptr->dc_tbl_no;\n\n    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */\n    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];\n\n    /* Figure F.4: Encode_DC_DIFF */\n    if ((v = (*block)[0] - entropy->last_dc_val[ci]) == 0) {\n      arith_encode(cinfo, st, 0);\n      entropy->dc_context[ci] = 0;\t/* zero diff category */\n    } else {\n      entropy->last_dc_val[ci] = (*block)[0];\n      arith_encode(cinfo, st, 1);\n      /* Figure F.6: Encoding nonzero value v */\n      /* Figure F.7: Encoding the sign of v */\n      if (v > 0) {\n\tarith_encode(cinfo, st + 1, 0);\t/* Table F.4: SS = S0 + 1 */\n\tst += 2;\t\t\t/* Table F.4: SP = S0 + 2 */\n\tentropy->dc_context[ci] = 4;\t/* small positive diff category */\n      } else {\n\tv = -v;\n\tarith_encode(cinfo, st + 1, 1);\t/* Table F.4: SS = S0 + 1 */\n\tst += 3;\t\t\t/* Table F.4: SN = S0 + 3 */\n\tentropy->dc_context[ci] = 8;\t/* small negative diff category */\n      }\n      /* Figure F.8: Encoding the magnitude category of v */\n      m = 0;\n      if (v -= 1) {\n\tarith_encode(cinfo, st, 1);\n\tm = 1;\n\tv2 = v;\n\tst = entropy->dc_stats[tbl] + 20; /* Table F.4: X1 = 20 */\n\twhile (v2 >>= 1) {\n\t  arith_encode(cinfo, st, 1);\n\t  m <<= 1;\n\t  st += 1;\n\t}\n      }\n      arith_encode(cinfo, st, 0);\n      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */\n      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))\n\tentropy->dc_context[ci] = 0;\t/* zero diff category */\n      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))\n\tentropy->dc_context[ci] += 8;\t/* large diff category */\n      /* Figure F.9: Encoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tarith_encode(cinfo, st, (m & v) ? 1 : 0);\n    }\n\n    /* Sections F.1.4.2 & F.1.4.4.2: Encoding of AC coefficients */\n\n    if ((ke = cinfo->lim_Se) == 0) continue;\n    tbl = compptr->ac_tbl_no;\n\n    /* Establish EOB (end-of-block) index */\n    do {\n      if ((*block)[natural_order[ke]]) break;\n    } while (--ke);\n\n    /* Figure F.5: Encode_AC_Coefficients */\n    for (k = 0; k < ke;) {\n      st = entropy->ac_stats[tbl] + 3 * k;\n      arith_encode(cinfo, st, 0);\t/* EOB decision */\n      while ((v = (*block)[natural_order[++k]]) == 0) {\n\tarith_encode(cinfo, st + 1, 0);\n\tst += 3;\n      }\n      arith_encode(cinfo, st + 1, 1);\n      /* Figure F.6: Encoding nonzero value v */\n      /* Figure F.7: Encoding the sign of v */\n      if (v > 0) {\n\tarith_encode(cinfo, entropy->fixed_bin, 0);\n      } else {\n\tv = -v;\n\tarith_encode(cinfo, entropy->fixed_bin, 1);\n      }\n      st += 2;\n      /* Figure F.8: Encoding the magnitude category of v */\n      m = 0;\n      if (v -= 1) {\n\tarith_encode(cinfo, st, 1);\n\tm = 1;\n\tv2 = v;\n\tif (v2 >>= 1) {\n\t  arith_encode(cinfo, st, 1);\n\t  m <<= 1;\n\t  st = entropy->ac_stats[tbl] +\n\t       (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);\n\t  while (v2 >>= 1) {\n\t    arith_encode(cinfo, st, 1);\n\t    m <<= 1;\n\t    st += 1;\n\t  }\n\t}\n      }\n      arith_encode(cinfo, st, 0);\n      /* Figure F.9: Encoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tarith_encode(cinfo, st, (m & v) ? 1 : 0);\n    }\n    /* Encode EOB decision only if k < cinfo->lim_Se */\n    if (k < cinfo->lim_Se) {\n      st = entropy->ac_stats[tbl] + 3 * k;\n      arith_encode(cinfo, st, 1);\n    }\n  }\n\n  return TRUE;\n}\n\n\n/*\n * Initialize for an arithmetic-compressed scan.\n */\n\nMETHODDEF(void)\nstart_pass (j_compress_ptr cinfo, boolean gather_statistics)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  int ci, tbl;\n  jpeg_component_info * compptr;\n\n  if (gather_statistics)\n    /* Make sure to avoid that in the master control logic!\n     * We are fully adaptive here and need no extra\n     * statistics gathering pass!\n     */\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n\n  /* We assume jcmaster.c already validated the progressive scan parameters. */\n\n  /* Select execution routines */\n  if (cinfo->progressive_mode) {\n    if (cinfo->Ah == 0) {\n      if (cinfo->Ss == 0)\n\tentropy->pub.encode_mcu = encode_mcu_DC_first;\n      else\n\tentropy->pub.encode_mcu = encode_mcu_AC_first;\n    } else {\n      if (cinfo->Ss == 0)\n\tentropy->pub.encode_mcu = encode_mcu_DC_refine;\n      else\n\tentropy->pub.encode_mcu = encode_mcu_AC_refine;\n    }\n  } else\n    entropy->pub.encode_mcu = encode_mcu;\n\n  /* Allocate & initialize requested statistics areas */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    /* DC needs no table for refinement scan */\n    if (cinfo->Ss == 0 && cinfo->Ah == 0) {\n      tbl = compptr->dc_tbl_no;\n      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)\n\tERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);\n      if (entropy->dc_stats[tbl] == NULL)\n\tentropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)\n\t  ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);\n      MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);\n      /* Initialize DC predictions to 0 */\n      entropy->last_dc_val[ci] = 0;\n      entropy->dc_context[ci] = 0;\n    }\n    /* AC needs no table when not present */\n    if (cinfo->Se) {\n      tbl = compptr->ac_tbl_no;\n      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)\n\tERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);\n      if (entropy->ac_stats[tbl] == NULL)\n\tentropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)\n\t  ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);\n      MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);\n#ifdef CALCULATE_SPECTRAL_CONDITIONING\n      if (cinfo->progressive_mode)\n\t/* Section G.1.3.2: Set appropriate arithmetic conditioning value Kx */\n\tcinfo->arith_ac_K[tbl] = cinfo->Ss + ((8 + cinfo->Se - cinfo->Ss) >> 4);\n#endif\n    }\n  }\n\n  /* Initialize arithmetic encoding variables */\n  entropy->c = 0;\n  entropy->a = 0x10000L;\n  entropy->sc = 0;\n  entropy->zc = 0;\n  entropy->ct = 11;\n  entropy->buffer = -1;  /* empty */\n\n  /* Initialize restart stuff */\n  entropy->restarts_to_go = cinfo->restart_interval;\n  entropy->next_restart_num = 0;\n}\n\n\n/*\n * Module initialization routine for arithmetic entropy encoding.\n */\n\nGLOBAL(void)\njinit_arith_encoder (j_compress_ptr cinfo)\n{\n  arith_entropy_ptr entropy;\n  int i;\n\n  entropy = (arith_entropy_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(arith_entropy_encoder));\n  cinfo->entropy = &entropy->pub;\n  entropy->pub.start_pass = start_pass;\n  entropy->pub.finish_pass = finish_pass;\n\n  /* Mark tables unallocated */\n  for (i = 0; i < NUM_ARITH_TBLS; i++) {\n    entropy->dc_stats[i] = NULL;\n    entropy->ac_stats[i] = NULL;\n  }\n\n  /* Initialize index for fixed probability estimation */\n  entropy->fixed_bin[0] = 113;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jccoefct.c",
    "content": "/*\n * jccoefct.c\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 2003-2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the coefficient buffer controller for compression.\n * This controller is the top level of the JPEG compressor proper.\n * The coefficient buffer lies between forward-DCT and entropy encoding steps.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* We use a full-image coefficient buffer when doing Huffman optimization,\n * and also for writing multiple-scan JPEG files.  In all cases, the DCT\n * step is run during the first pass, and subsequent passes need only read\n * the buffered coefficients.\n */\n#ifdef ENTROPY_OPT_SUPPORTED\n#define FULL_COEF_BUFFER_SUPPORTED\n#else\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n#define FULL_COEF_BUFFER_SUPPORTED\n#endif\n#endif\n\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_c_coef_controller pub; /* public fields */\n\n  JDIMENSION iMCU_row_num;\t/* iMCU row # within image */\n  JDIMENSION mcu_ctr;\t\t/* counts MCUs processed in current row */\n  int MCU_vert_offset;\t\t/* counts MCU rows within iMCU row */\n  int MCU_rows_per_iMCU_row;\t/* number of such rows needed */\n\n  /* For single-pass compression, it's sufficient to buffer just one MCU\n   * (although this may prove a bit slow in practice).  We allocate a\n   * workspace of C_MAX_BLOCKS_IN_MCU coefficient blocks, and reuse it for each\n   * MCU constructed and sent.  (On 80x86, the workspace is FAR even though\n   * it's not really very big; this is to keep the module interfaces unchanged\n   * when a large coefficient buffer is necessary.)\n   * In multi-pass modes, this array points to the current MCU's blocks\n   * within the virtual arrays.\n   */\n  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];\n\n  /* In multi-pass modes, we need a virtual block array for each component. */\n  jvirt_barray_ptr whole_image[MAX_COMPONENTS];\n} my_coef_controller;\n\ntypedef my_coef_controller * my_coef_ptr;\n\n\n/* Forward declarations */\nMETHODDEF(boolean) compress_data\n    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));\n#ifdef FULL_COEF_BUFFER_SUPPORTED\nMETHODDEF(boolean) compress_first_pass\n    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));\nMETHODDEF(boolean) compress_output\n    JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));\n#endif\n\n\nLOCAL(void)\nstart_iMCU_row (j_compress_ptr cinfo)\n/* Reset within-iMCU-row counters for a new row */\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  /* In an interleaved scan, an MCU row is the same as an iMCU row.\n   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.\n   * But at the bottom of the image, process only what's left.\n   */\n  if (cinfo->comps_in_scan > 1) {\n    coef->MCU_rows_per_iMCU_row = 1;\n  } else {\n    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;\n    else\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;\n  }\n\n  coef->mcu_ctr = 0;\n  coef->MCU_vert_offset = 0;\n}\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  coef->iMCU_row_num = 0;\n  start_iMCU_row(cinfo);\n\n  switch (pass_mode) {\n  case JBUF_PASS_THRU:\n    if (coef->whole_image[0] != NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    coef->pub.compress_data = compress_data;\n    break;\n#ifdef FULL_COEF_BUFFER_SUPPORTED\n  case JBUF_SAVE_AND_PASS:\n    if (coef->whole_image[0] == NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    coef->pub.compress_data = compress_first_pass;\n    break;\n  case JBUF_CRANK_DEST:\n    if (coef->whole_image[0] == NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    coef->pub.compress_data = compress_output;\n    break;\n#endif\n  default:\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    break;\n  }\n}\n\n\n/*\n * Process some data in the single-pass case.\n * We process the equivalent of one fully interleaved MCU row (\"iMCU\" row)\n * per call, ie, v_samp_factor block rows for each component in the image.\n * Returns TRUE if the iMCU row is completed, FALSE if suspended.\n *\n * NB: input_buf contains a plane for each component in image,\n * which we index according to the component's SOF position.\n */\n\nMETHODDEF(boolean)\ncompress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION MCU_col_num;\t/* index of current MCU within row */\n  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  int blkn, bi, ci, yindex, yoffset, blockcnt;\n  JDIMENSION ypos, xpos;\n  jpeg_component_info *compptr;\n  forward_DCT_ptr forward_DCT;\n\n  /* Loop to write as much as one whole iMCU row */\n  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\n       yoffset++) {\n    for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;\n\t MCU_col_num++) {\n      /* Determine where data comes from in input_buf and do the DCT thing.\n       * Each call on forward_DCT processes a horizontal row of DCT blocks\n       * as wide as an MCU; we rely on having allocated the MCU_buffer[] blocks\n       * sequentially.  Dummy blocks at the right or bottom edge are filled in\n       * specially.  The data in them does not matter for image reconstruction,\n       * so we fill them with values that will encode to the smallest amount of\n       * data, viz: all zeroes in the AC entries, DC entries equal to previous\n       * block's DC value.  (Thanks to Thomas Kinsman for this idea.)\n       */\n      blkn = 0;\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n\tcompptr = cinfo->cur_comp_info[ci];\n\tforward_DCT = cinfo->fdct->forward_DCT[compptr->component_index];\n\tblockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width\n\t\t\t\t\t\t: compptr->last_col_width;\n\txpos = MCU_col_num * compptr->MCU_sample_width;\n\typos = yoffset * compptr->DCT_v_scaled_size;\n\t/* ypos == (yoffset+yindex) * DCTSIZE */\n\tfor (yindex = 0; yindex < compptr->MCU_height; yindex++) {\n\t  if (coef->iMCU_row_num < last_iMCU_row ||\n\t      yoffset+yindex < compptr->last_row_height) {\n\t    (*forward_DCT) (cinfo, compptr,\n\t\t\t    input_buf[compptr->component_index],\n\t\t\t    coef->MCU_buffer[blkn],\n\t\t\t    ypos, xpos, (JDIMENSION) blockcnt);\n\t    if (blockcnt < compptr->MCU_width) {\n\t      /* Create some dummy blocks at the right edge of the image. */\n\t      FMEMZERO((void FAR *) coef->MCU_buffer[blkn + blockcnt],\n\t\t       (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));\n\t      for (bi = blockcnt; bi < compptr->MCU_width; bi++) {\n\t\tcoef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];\n\t      }\n\t    }\n\t  } else {\n\t    /* Create a row of dummy blocks at the bottom of the image. */\n\t    FMEMZERO((void FAR *) coef->MCU_buffer[blkn],\n\t\t     compptr->MCU_width * SIZEOF(JBLOCK));\n\t    for (bi = 0; bi < compptr->MCU_width; bi++) {\n\t      coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];\n\t    }\n\t  }\n\t  blkn += compptr->MCU_width;\n\t  ypos += compptr->DCT_v_scaled_size;\n\t}\n      }\n      /* Try to write the MCU.  In event of a suspension failure, we will\n       * re-DCT the MCU on restart (a bit inefficient, could be fixed...)\n       */\n      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {\n\t/* Suspension forced; update state counters and exit */\n\tcoef->MCU_vert_offset = yoffset;\n\tcoef->mcu_ctr = MCU_col_num;\n\treturn FALSE;\n      }\n    }\n    /* Completed an MCU row, but perhaps not an iMCU row */\n    coef->mcu_ctr = 0;\n  }\n  /* Completed the iMCU row, advance counters for next one */\n  coef->iMCU_row_num++;\n  start_iMCU_row(cinfo);\n  return TRUE;\n}\n\n\n#ifdef FULL_COEF_BUFFER_SUPPORTED\n\n/*\n * Process some data in the first pass of a multi-pass case.\n * We process the equivalent of one fully interleaved MCU row (\"iMCU\" row)\n * per call, ie, v_samp_factor block rows for each component in the image.\n * This amount of data is read from the source buffer, DCT'd and quantized,\n * and saved into the virtual arrays.  We also generate suitable dummy blocks\n * as needed at the right and lower edges.  (The dummy blocks are constructed\n * in the virtual arrays, which have been padded appropriately.)  This makes\n * it possible for subsequent passes not to worry about real vs. dummy blocks.\n *\n * We must also emit the data to the entropy encoder.  This is conveniently\n * done by calling compress_output() after we've loaded the current strip\n * of the virtual arrays.\n *\n * NB: input_buf contains a plane for each component in image.  All\n * components are DCT'd and loaded into the virtual arrays in this pass.\n * However, it may be that only a subset of the components are emitted to\n * the entropy encoder during this first pass; be careful about looking\n * at the scan-dependent variables (MCU dimensions, etc).\n */\n\nMETHODDEF(boolean)\ncompress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  JDIMENSION blocks_across, MCUs_across, MCUindex;\n  int bi, ci, h_samp_factor, block_row, block_rows, ndummy;\n  JCOEF lastDC;\n  jpeg_component_info *compptr;\n  JBLOCKARRAY buffer;\n  JBLOCKROW thisblockrow, lastblockrow;\n  forward_DCT_ptr forward_DCT;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Align the virtual buffer for this component. */\n    buffer = (*cinfo->mem->access_virt_barray)\n      ((j_common_ptr) cinfo, coef->whole_image[ci],\n       coef->iMCU_row_num * compptr->v_samp_factor,\n       (JDIMENSION) compptr->v_samp_factor, TRUE);\n    /* Count non-dummy DCT block rows in this iMCU row. */\n    if (coef->iMCU_row_num < last_iMCU_row)\n      block_rows = compptr->v_samp_factor;\n    else {\n      /* NB: can't use last_row_height here, since may not be set! */\n      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\n      if (block_rows == 0) block_rows = compptr->v_samp_factor;\n    }\n    blocks_across = compptr->width_in_blocks;\n    h_samp_factor = compptr->h_samp_factor;\n    /* Count number of dummy blocks to be added at the right margin. */\n    ndummy = (int) (blocks_across % h_samp_factor);\n    if (ndummy > 0)\n      ndummy = h_samp_factor - ndummy;\n    forward_DCT = cinfo->fdct->forward_DCT[ci];\n    /* Perform DCT for all non-dummy blocks in this iMCU row.  Each call\n     * on forward_DCT processes a complete horizontal row of DCT blocks.\n     */\n    for (block_row = 0; block_row < block_rows; block_row++) {\n      thisblockrow = buffer[block_row];\n      (*forward_DCT) (cinfo, compptr, input_buf[ci], thisblockrow,\n\t\t      (JDIMENSION) (block_row * compptr->DCT_v_scaled_size),\n\t\t      (JDIMENSION) 0, blocks_across);\n      if (ndummy > 0) {\n\t/* Create dummy blocks at the right edge of the image. */\n\tthisblockrow += blocks_across; /* => first dummy block */\n\tFMEMZERO((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));\n\tlastDC = thisblockrow[-1][0];\n\tfor (bi = 0; bi < ndummy; bi++) {\n\t  thisblockrow[bi][0] = lastDC;\n\t}\n      }\n    }\n    /* If at end of image, create dummy block rows as needed.\n     * The tricky part here is that within each MCU, we want the DC values\n     * of the dummy blocks to match the last real block's DC value.\n     * This squeezes a few more bytes out of the resulting file...\n     */\n    if (coef->iMCU_row_num == last_iMCU_row) {\n      blocks_across += ndummy;\t/* include lower right corner */\n      MCUs_across = blocks_across / h_samp_factor;\n      for (block_row = block_rows; block_row < compptr->v_samp_factor;\n\t   block_row++) {\n\tthisblockrow = buffer[block_row];\n\tlastblockrow = buffer[block_row-1];\n\tFMEMZERO((void FAR *) thisblockrow,\n\t\t (size_t) (blocks_across * SIZEOF(JBLOCK)));\n\tfor (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {\n\t  lastDC = lastblockrow[h_samp_factor-1][0];\n\t  for (bi = 0; bi < h_samp_factor; bi++) {\n\t    thisblockrow[bi][0] = lastDC;\n\t  }\n\t  thisblockrow += h_samp_factor; /* advance to next MCU in row */\n\t  lastblockrow += h_samp_factor;\n\t}\n      }\n    }\n  }\n  /* NB: compress_output will increment iMCU_row_num if successful.\n   * A suspension return will result in redoing all the work above next time.\n   */\n\n  /* Emit data to the entropy encoder, sharing code with subsequent passes */\n  return compress_output(cinfo, input_buf);\n}\n\n\n/*\n * Process some data in subsequent passes of a multi-pass case.\n * We process the equivalent of one fully interleaved MCU row (\"iMCU\" row)\n * per call, ie, v_samp_factor block rows for each component in the scan.\n * The data is obtained from the virtual arrays and fed to the entropy coder.\n * Returns TRUE if the iMCU row is completed, FALSE if suspended.\n *\n * NB: input_buf is ignored; it is likely to be a NULL pointer.\n */\n\nMETHODDEF(boolean)\ncompress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION MCU_col_num;\t/* index of current MCU within row */\n  int blkn, ci, xindex, yindex, yoffset;\n  JDIMENSION start_col;\n  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];\n  JBLOCKROW buffer_ptr;\n  jpeg_component_info *compptr;\n\n  /* Align the virtual buffers for the components used in this scan.\n   * NB: during first pass, this is safe only because the buffers will\n   * already be aligned properly, so jmemmgr.c won't need to do any I/O.\n   */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    buffer[ci] = (*cinfo->mem->access_virt_barray)\n      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],\n       coef->iMCU_row_num * compptr->v_samp_factor,\n       (JDIMENSION) compptr->v_samp_factor, FALSE);\n  }\n\n  /* Loop to process one whole iMCU row */\n  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\n       yoffset++) {\n    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;\n\t MCU_col_num++) {\n      /* Construct list of pointers to DCT blocks belonging to this MCU */\n      blkn = 0;\t\t\t/* index of current DCT block within MCU */\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n\tcompptr = cinfo->cur_comp_info[ci];\n\tstart_col = MCU_col_num * compptr->MCU_width;\n\tfor (yindex = 0; yindex < compptr->MCU_height; yindex++) {\n\t  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;\n\t  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {\n\t    coef->MCU_buffer[blkn++] = buffer_ptr++;\n\t  }\n\t}\n      }\n      /* Try to write the MCU. */\n      if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {\n\t/* Suspension forced; update state counters and exit */\n\tcoef->MCU_vert_offset = yoffset;\n\tcoef->mcu_ctr = MCU_col_num;\n\treturn FALSE;\n      }\n    }\n    /* Completed an MCU row, but perhaps not an iMCU row */\n    coef->mcu_ctr = 0;\n  }\n  /* Completed the iMCU row, advance counters for next one */\n  coef->iMCU_row_num++;\n  start_iMCU_row(cinfo);\n  return TRUE;\n}\n\n#endif /* FULL_COEF_BUFFER_SUPPORTED */\n\n\n/*\n * Initialize coefficient buffer controller.\n */\n\nGLOBAL(void)\njinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)\n{\n  my_coef_ptr coef;\n\n  coef = (my_coef_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_coef_controller));\n  cinfo->coef = (struct jpeg_c_coef_controller *) coef;\n  coef->pub.start_pass = start_pass_coef;\n\n  /* Create the coefficient buffer. */\n  if (need_full_buffer) {\n#ifdef FULL_COEF_BUFFER_SUPPORTED\n    /* Allocate a full-image virtual array for each component, */\n    /* padded to a multiple of samp_factor DCT blocks in each direction. */\n    int ci;\n    jpeg_component_info *compptr;\n\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n\t (JDIMENSION) jround_up((long) compptr->width_in_blocks,\n\t\t\t\t(long) compptr->h_samp_factor),\n\t (JDIMENSION) jround_up((long) compptr->height_in_blocks,\n\t\t\t\t(long) compptr->v_samp_factor),\n\t (JDIMENSION) compptr->v_samp_factor);\n    }\n#else\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n#endif\n  } else {\n    /* We only need a single-MCU buffer. */\n    JBLOCKROW buffer;\n    int i;\n\n    buffer = (JBLOCKROW)\n      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));\n    for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {\n      coef->MCU_buffer[i] = buffer + i;\n    }\n    coef->whole_image[0] = NULL; /* flag for no virtual arrays */\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jccolor.c",
    "content": "/*\n * jccolor.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2011-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains input colorspace conversion routines.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_color_converter pub; /* public fields */\n\n  /* Private state for RGB->YCC conversion */\n  INT32 * rgb_ycc_tab;\t\t/* => table for RGB to YCbCr conversion */\n} my_color_converter;\n\ntypedef my_color_converter * my_cconvert_ptr;\n\n\n/**************** RGB -> YCbCr conversion: most common case **************/\n\n/*\n * YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),\n * previously known as Recommendation CCIR 601-1, except that Cb and Cr\n * are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.\n * sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.\n * sYCC (standard luma-chroma-chroma color space with extended gamut)\n * is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.\n * bg-sRGB and bg-sYCC (big gamut standard color spaces)\n * are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.\n * Note that the derived conversion coefficients given in some of these\n * documents are imprecise.  The general conversion equations are\n *\tY  = Kr * R + (1 - Kr - Kb) * G + Kb * B\n *\tCb = 0.5 * (B - Y) / (1 - Kb)\n *\tCr = 0.5 * (R - Y) / (1 - Kr)\n * With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993\n * from the 1953 FCC NTSC primaries and CIE Illuminant C),\n * the conversion equations to be implemented are therefore\n *\tY  =  0.299 * R + 0.587 * G + 0.114 * B\n *\tCb = -0.168735892 * R - 0.331264108 * G + 0.5 * B + CENTERJSAMPLE\n *\tCr =  0.5 * R - 0.418687589 * G - 0.081312411 * B + CENTERJSAMPLE\n * Note: older versions of the IJG code used a zero offset of MAXJSAMPLE/2,\n * rather than CENTERJSAMPLE, for Cb and Cr.  This gave equal positive and\n * negative swings for Cb/Cr, but meant that grayscale values (Cb=Cr=0)\n * were not represented exactly.  Now we sacrifice exact representation of\n * maximum red and maximum blue in order to get exact grayscales.\n *\n * To avoid floating-point arithmetic, we represent the fractional constants\n * as integers scaled up by 2^16 (about 4 digits precision); we have to divide\n * the products by 2^16, with appropriate rounding, to get the correct answer.\n *\n * For even more speed, we avoid doing any multiplications in the inner loop\n * by precalculating the constants times R,G,B for all possible values.\n * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);\n * for 9-bit to 12-bit samples it is still acceptable.  It's not very\n * reasonable for 16-bit samples, but if you want lossless storage you\n * shouldn't be changing colorspace anyway.\n * The CENTERJSAMPLE offsets and the rounding fudge-factor of 0.5 are included\n * in the tables to save adding them separately in the inner loop.\n */\n\n#define SCALEBITS\t16\t/* speediest right-shift on some machines */\n#define CBCR_OFFSET\t((INT32) CENTERJSAMPLE << SCALEBITS)\n#define ONE_HALF\t((INT32) 1 << (SCALEBITS-1))\n#define FIX(x)\t\t((INT32) ((x) * (1L<<SCALEBITS) + 0.5))\n\n/* We allocate one big table and divide it up into eight parts, instead of\n * doing eight alloc_small requests.  This lets us use a single table base\n * address, which can be held in a register in the inner loops on many\n * machines (more than can hold all eight addresses, anyway).\n */\n\n#define R_Y_OFF\t\t0\t\t\t/* offset to R => Y section */\n#define G_Y_OFF\t\t(1*(MAXJSAMPLE+1))\t/* offset to G => Y section */\n#define B_Y_OFF\t\t(2*(MAXJSAMPLE+1))\t/* etc. */\n#define R_CB_OFF\t(3*(MAXJSAMPLE+1))\n#define G_CB_OFF\t(4*(MAXJSAMPLE+1))\n#define B_CB_OFF\t(5*(MAXJSAMPLE+1))\n#define R_CR_OFF\tB_CB_OFF\t\t/* B=>Cb, R=>Cr are the same */\n#define G_CR_OFF\t(6*(MAXJSAMPLE+1))\n#define B_CR_OFF\t(7*(MAXJSAMPLE+1))\n#define TABLE_SIZE\t(8*(MAXJSAMPLE+1))\n\n\n/*\n * Initialize for RGB->YCC colorspace conversion.\n */\n\nMETHODDEF(void)\nrgb_ycc_start (j_compress_ptr cinfo)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  INT32 * rgb_ycc_tab;\n  INT32 i;\n\n  /* Allocate and fill in the conversion tables. */\n  cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(TABLE_SIZE * SIZEOF(INT32)));\n\n  for (i = 0; i <= MAXJSAMPLE; i++) {\n    rgb_ycc_tab[i+R_Y_OFF] = FIX(0.299) * i;\n    rgb_ycc_tab[i+G_Y_OFF] = FIX(0.587) * i;\n    rgb_ycc_tab[i+B_Y_OFF] = FIX(0.114) * i   + ONE_HALF;\n    rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.168735892)) * i;\n    rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.331264108)) * i;\n    /* We use a rounding fudge-factor of 0.5-epsilon for Cb and Cr.\n     * This ensures that the maximum output will round to MAXJSAMPLE\n     * not MAXJSAMPLE+1, and thus that we don't have to range-limit.\n     */\n    rgb_ycc_tab[i+B_CB_OFF] = FIX(0.5) * i    + CBCR_OFFSET + ONE_HALF-1;\n/*  B=>Cb and R=>Cr tables are the same\n    rgb_ycc_tab[i+R_CR_OFF] = FIX(0.5) * i    + CBCR_OFFSET + ONE_HALF-1;\n*/\n    rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.418687589)) * i;\n    rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.081312411)) * i;\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n *\n * Note that we change from the application's interleaved-pixel format\n * to our internal noninterleaved, one-plane-per-component format.\n * The input buffer is therefore three times as wide as the output buffer.\n *\n * A starting row offset is provided only for the output buffer.  The caller\n * can easily adjust the passed input_buf value to accommodate any row\n * offset required on that side.\n */\n\nMETHODDEF(void)\nrgb_ycc_convert (j_compress_ptr cinfo,\n\t\t JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t JDIMENSION output_row, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register INT32 * ctab = cconvert->rgb_ycc_tab;\n  register int r, g, b;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr0, outptr1, outptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr0 = output_buf[0][output_row];\n    outptr1 = output_buf[1][output_row];\n    outptr2 = output_buf[2][output_row];\n    output_row++;\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr[RGB_RED]);\n      g = GETJSAMPLE(inptr[RGB_GREEN]);\n      b = GETJSAMPLE(inptr[RGB_BLUE]);\n      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations\n       * must be too; we do not need an explicit range-limiting operation.\n       * Hence the value being shifted is never negative, and we don't\n       * need the general RIGHT_SHIFT macro.\n       */\n      /* Y */\n      outptr0[col] = (JSAMPLE)\n\t\t((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])\n\t\t >> SCALEBITS);\n      /* Cb */\n      outptr1[col] = (JSAMPLE)\n\t\t((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])\n\t\t >> SCALEBITS);\n      /* Cr */\n      outptr2[col] = (JSAMPLE)\n\t\t((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])\n\t\t >> SCALEBITS);\n      inptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/**************** Cases other than RGB -> YCbCr **************/\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * This version handles RGB->grayscale conversion, which is the same\n * as the RGB->Y portion of RGB->YCbCr.\n * We assume rgb_ycc_start has been called (we only use the Y tables).\n */\n\nMETHODDEF(void)\nrgb_gray_convert (j_compress_ptr cinfo,\n\t\t  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t  JDIMENSION output_row, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register INT32 * ctab = cconvert->rgb_ycc_tab;\n  register int r, g, b;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr = output_buf[0][output_row++];\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr[RGB_RED]);\n      g = GETJSAMPLE(inptr[RGB_GREEN]);\n      b = GETJSAMPLE(inptr[RGB_BLUE]);\n      /* Y */\n      outptr[col] = (JSAMPLE)\n\t\t((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])\n\t\t >> SCALEBITS);\n      inptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * This version handles Adobe-style CMYK->YCCK conversion,\n * where we convert R=1-C, G=1-M, and B=1-Y to YCbCr using the same\n * conversion as above, while passing K (black) unchanged.\n * We assume rgb_ycc_start has been called.\n */\n\nMETHODDEF(void)\ncmyk_ycck_convert (j_compress_ptr cinfo,\n\t\t   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t   JDIMENSION output_row, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register INT32 * ctab = cconvert->rgb_ycc_tab;\n  register int r, g, b;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr0, outptr1, outptr2, outptr3;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr0 = output_buf[0][output_row];\n    outptr1 = output_buf[1][output_row];\n    outptr2 = output_buf[2][output_row];\n    outptr3 = output_buf[3][output_row];\n    output_row++;\n    for (col = 0; col < num_cols; col++) {\n      r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);\n      g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);\n      b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);\n      /* K passes through as-is */\n      outptr3[col] = inptr[3];\t/* don't need GETJSAMPLE here */\n      /* If the inputs are 0..MAXJSAMPLE, the outputs of these equations\n       * must be too; we do not need an explicit range-limiting operation.\n       * Hence the value being shifted is never negative, and we don't\n       * need the general RIGHT_SHIFT macro.\n       */\n      /* Y */\n      outptr0[col] = (JSAMPLE)\n\t\t((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])\n\t\t >> SCALEBITS);\n      /* Cb */\n      outptr1[col] = (JSAMPLE)\n\t\t((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])\n\t\t >> SCALEBITS);\n      /* Cr */\n      outptr2[col] = (JSAMPLE)\n\t\t((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])\n\t\t >> SCALEBITS);\n      inptr += 4;\n    }\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * [R,G,B] to [R-G,G,B-G] conversion with modulo calculation\n * (forward reversible color transform).\n * This can be seen as an adaption of the general RGB->YCbCr\n * conversion equation with Kr = Kb = 0, while replacing the\n * normalization by modulo calculation.\n */\n\nMETHODDEF(void)\nrgb_rgb1_convert (j_compress_ptr cinfo,\n\t\t  JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t  JDIMENSION output_row, int num_rows)\n{\n  register int r, g, b;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr0, outptr1, outptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr0 = output_buf[0][output_row];\n    outptr1 = output_buf[1][output_row];\n    outptr2 = output_buf[2][output_row];\n    output_row++;\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr[RGB_RED]);\n      g = GETJSAMPLE(inptr[RGB_GREEN]);\n      b = GETJSAMPLE(inptr[RGB_BLUE]);\n      /* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD\n       * (modulo) operator is equivalent to the bitmask operator AND.\n       */\n      outptr0[col] = (JSAMPLE) ((r - g + CENTERJSAMPLE) & MAXJSAMPLE);\n      outptr1[col] = (JSAMPLE) g;\n      outptr2[col] = (JSAMPLE) ((b - g + CENTERJSAMPLE) & MAXJSAMPLE);\n      inptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * This version handles grayscale output with no conversion.\n * The source can be either plain grayscale or YCC (since Y == gray).\n */\n\nMETHODDEF(void)\ngrayscale_convert (j_compress_ptr cinfo,\n\t\t   JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t   JDIMENSION output_row, int num_rows)\n{\n  int instride = cinfo->input_components;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr = output_buf[0][output_row++];\n    for (col = 0; col < num_cols; col++) {\n      outptr[col] = inptr[0];\t/* don't need GETJSAMPLE() here */\n      inptr += instride;\n    }\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * No colorspace conversion, but change from interleaved\n * to separate-planes representation.\n */\n\nMETHODDEF(void)\nrgb_convert (j_compress_ptr cinfo,\n\t     JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t     JDIMENSION output_row, int num_rows)\n{\n  register JSAMPROW inptr;\n  register JSAMPROW outptr0, outptr1, outptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    inptr = *input_buf++;\n    outptr0 = output_buf[0][output_row];\n    outptr1 = output_buf[1][output_row];\n    outptr2 = output_buf[2][output_row];\n    output_row++;\n    for (col = 0; col < num_cols; col++) {\n      /* We can dispense with GETJSAMPLE() here */\n      outptr0[col] = inptr[RGB_RED];\n      outptr1[col] = inptr[RGB_GREEN];\n      outptr2[col] = inptr[RGB_BLUE];\n      inptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * Convert some rows of samples to the JPEG colorspace.\n * This version handles multi-component colorspaces without conversion.\n * We assume input_components == num_components.\n */\n\nMETHODDEF(void)\nnull_convert (j_compress_ptr cinfo,\n\t      JSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t      JDIMENSION output_row, int num_rows)\n{\n  int ci;\n  register int nc = cinfo->num_components;\n  register JSAMPROW inptr;\n  register JSAMPROW outptr;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->image_width;\n\n  while (--num_rows >= 0) {\n    /* It seems fastest to make a separate pass for each component. */\n    for (ci = 0; ci < nc; ci++) {\n      inptr = input_buf[0] + ci;\n      outptr = output_buf[ci][output_row];\n      for (col = 0; col < num_cols; col++) {\n\t*outptr++ = *inptr;\t/* don't need GETJSAMPLE() here */\n\tinptr += nc;\n      }\n    }\n    input_buf++;\n    output_row++;\n  }\n}\n\n\n/*\n * Empty method for start_pass.\n */\n\nMETHODDEF(void)\nnull_method (j_compress_ptr cinfo)\n{\n  /* no work needed */\n}\n\n\n/*\n * Module initialization routine for input colorspace conversion.\n */\n\nGLOBAL(void)\njinit_color_converter (j_compress_ptr cinfo)\n{\n  my_cconvert_ptr cconvert;\n\n  cconvert = (my_cconvert_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_color_converter));\n  cinfo->cconvert = &cconvert->pub;\n  /* set start_pass to null method until we find out differently */\n  cconvert->pub.start_pass = null_method;\n\n  /* Make sure input_components agrees with in_color_space */\n  switch (cinfo->in_color_space) {\n  case JCS_GRAYSCALE:\n    if (cinfo->input_components != 1)\n      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n    break;\n\n  case JCS_RGB:\n  case JCS_BG_RGB:\n    if (cinfo->input_components != RGB_PIXELSIZE)\n      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n    break;\n\n  case JCS_YCbCr:\n  case JCS_BG_YCC:\n    if (cinfo->input_components != 3)\n      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n    break;\n\n  case JCS_CMYK:\n  case JCS_YCCK:\n    if (cinfo->input_components != 4)\n      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n    break;\n\n  default:\t\t\t/* JCS_UNKNOWN can be anything */\n    if (cinfo->input_components < 1)\n      ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n    break;\n  }\n\n  /* Support color transform only for RGB colorspaces */\n  if (cinfo->color_transform &&\n      cinfo->jpeg_color_space != JCS_RGB &&\n      cinfo->jpeg_color_space != JCS_BG_RGB)\n    ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n\n  /* Check num_components, set conversion method based on requested space */\n  switch (cinfo->jpeg_color_space) {\n  case JCS_GRAYSCALE:\n    if (cinfo->num_components != 1)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    switch (cinfo->in_color_space) {\n    case JCS_GRAYSCALE:\n    case JCS_YCbCr:\n    case JCS_BG_YCC:\n      cconvert->pub.color_convert = grayscale_convert;\n      break;\n    case JCS_RGB:\n      cconvert->pub.start_pass = rgb_ycc_start;\n      cconvert->pub.color_convert = rgb_gray_convert;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  case JCS_RGB:\n  case JCS_BG_RGB:\n    if (cinfo->num_components != 3)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    if (cinfo->in_color_space == cinfo->jpeg_color_space) {\n      switch (cinfo->color_transform) {\n      case JCT_NONE:\n\tcconvert->pub.color_convert = rgb_convert;\n\tbreak;\n      case JCT_SUBTRACT_GREEN:\n\tcconvert->pub.color_convert = rgb_rgb1_convert;\n\tbreak;\n      default:\n\tERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n      }\n    } else\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    break;\n\n  case JCS_YCbCr:\n    if (cinfo->num_components != 3)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    switch (cinfo->in_color_space) {\n    case JCS_RGB:\n      cconvert->pub.start_pass = rgb_ycc_start;\n      cconvert->pub.color_convert = rgb_ycc_convert;\n      break;\n    case JCS_YCbCr:\n      cconvert->pub.color_convert = null_convert;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  case JCS_BG_YCC:\n    if (cinfo->num_components != 3)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    switch (cinfo->in_color_space) {\n    case JCS_RGB:\n      /* For conversion from normal RGB input to BG_YCC representation,\n       * the Cb/Cr values are first computed as usual, and then\n       * quantized further after DCT processing by a factor of\n       * 2 in reference to the nominal quantization factor.\n       */\n      /* need quantization scale by factor of 2 after DCT */\n      cinfo->comp_info[1].component_needed = TRUE;\n      cinfo->comp_info[2].component_needed = TRUE;\n      /* compute normal YCC first */\n      cconvert->pub.start_pass = rgb_ycc_start;\n      cconvert->pub.color_convert = rgb_ycc_convert;\n      break;\n    case JCS_YCbCr:\n      /* need quantization scale by factor of 2 after DCT */\n      cinfo->comp_info[1].component_needed = TRUE;\n      cinfo->comp_info[2].component_needed = TRUE;\n      /*FALLTHROUGH*/\n    case JCS_BG_YCC:\n      /* Pass through for BG_YCC input */\n      cconvert->pub.color_convert = null_convert;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  case JCS_CMYK:\n    if (cinfo->num_components != 4)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    if (cinfo->in_color_space == JCS_CMYK)\n      cconvert->pub.color_convert = null_convert;\n    else\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    break;\n\n  case JCS_YCCK:\n    if (cinfo->num_components != 4)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    switch (cinfo->in_color_space) {\n    case JCS_CMYK:\n      cconvert->pub.start_pass = rgb_ycc_start;\n      cconvert->pub.color_convert = cmyk_ycck_convert;\n      break;\n    case JCS_YCCK:\n      cconvert->pub.color_convert = null_convert;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  default:\t\t\t/* allow null conversion of JCS_UNKNOWN */\n    if (cinfo->jpeg_color_space != cinfo->in_color_space ||\n\tcinfo->num_components != cinfo->input_components)\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    cconvert->pub.color_convert = null_convert;\n    break;\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcdctmgr.c",
    "content": "/*\n * jcdctmgr.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the forward-DCT management logic.\n * This code selects a particular DCT implementation to be used,\n * and it performs related housekeeping chores including coefficient\n * quantization.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n\n/* Private subobject for this module */\n\ntypedef struct {\n  struct jpeg_forward_dct pub;\t/* public fields */\n\n  /* Pointer to the DCT routine actually in use */\n  forward_DCT_method_ptr do_dct[MAX_COMPONENTS];\n\n#ifdef DCT_FLOAT_SUPPORTED\n  /* Same as above for the floating-point case. */\n  float_DCT_method_ptr do_float_dct[MAX_COMPONENTS];\n#endif\n} my_fdct_controller;\n\ntypedef my_fdct_controller * my_fdct_ptr;\n\n\n/* The allocated post-DCT divisor tables -- big enough for any\n * supported variant and not identical to the quant table entries,\n * because of scaling (especially for an unnormalized DCT) --\n * are pointed to by dct_table in the per-component comp_info\n * structures.  Each table is given in normal array order.\n */\n\ntypedef union {\n  DCTELEM int_array[DCTSIZE2];\n#ifdef DCT_FLOAT_SUPPORTED\n  FAST_FLOAT float_array[DCTSIZE2];\n#endif\n} divisor_table;\n\n\n/* The current scaled-DCT routines require ISLOW-style divisor tables,\n * so be sure to compile that code if either ISLOW or SCALING is requested.\n */\n#ifdef DCT_ISLOW_SUPPORTED\n#define PROVIDE_ISLOW_TABLES\n#else\n#ifdef DCT_SCALING_SUPPORTED\n#define PROVIDE_ISLOW_TABLES\n#endif\n#endif\n\n\n/*\n * Perform forward DCT on one or more blocks of a component.\n *\n * The input samples are taken from the sample_data[] array starting at\n * position start_row/start_col, and moving to the right for any additional\n * blocks. The quantized coefficients are returned in coef_blocks[].\n */\n\nMETHODDEF(void)\nforward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t     JSAMPARRAY sample_data, JBLOCKROW coef_blocks,\n\t     JDIMENSION start_row, JDIMENSION start_col,\n\t     JDIMENSION num_blocks)\n/* This version is used for integer DCT implementations. */\n{\n  /* This routine is heavily used, so it's worth coding it tightly. */\n  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;\n  forward_DCT_method_ptr do_dct = fdct->do_dct[compptr->component_index];\n  DCTELEM * divisors = (DCTELEM *) compptr->dct_table;\n  DCTELEM workspace[DCTSIZE2];\t/* work area for FDCT subroutine */\n  JDIMENSION bi;\n\n  sample_data += start_row;\t/* fold in the vertical offset once */\n\n  for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {\n    /* Perform the DCT */\n    (*do_dct) (workspace, sample_data, start_col);\n\n    /* Quantize/descale the coefficients, and store into coef_blocks[] */\n    { register DCTELEM temp, qval;\n      register int i;\n      register JCOEFPTR output_ptr = coef_blocks[bi];\n\n      for (i = 0; i < DCTSIZE2; i++) {\n\tqval = divisors[i];\n\ttemp = workspace[i];\n\t/* Divide the coefficient value by qval, ensuring proper rounding.\n\t * Since C does not specify the direction of rounding for negative\n\t * quotients, we have to force the dividend positive for portability.\n\t *\n\t * In most files, at least half of the output values will be zero\n\t * (at default quantization settings, more like three-quarters...)\n\t * so we should ensure that this case is fast.  On many machines,\n\t * a comparison is enough cheaper than a divide to make a special test\n\t * a win.  Since both inputs will be nonnegative, we need only test\n\t * for a < b to discover whether a/b is 0.\n\t * If your machine's division is fast enough, define FAST_DIVIDE.\n\t */\n#ifdef FAST_DIVIDE\n#define DIVIDE_BY(a,b)\ta /= b\n#else\n#define DIVIDE_BY(a,b)\tif (a >= b) a /= b; else a = 0\n#endif\n\tif (temp < 0) {\n\t  temp = -temp;\n\t  temp += qval>>1;\t/* for rounding */\n\t  DIVIDE_BY(temp, qval);\n\t  temp = -temp;\n\t} else {\n\t  temp += qval>>1;\t/* for rounding */\n\t  DIVIDE_BY(temp, qval);\n\t}\n\toutput_ptr[i] = (JCOEF) temp;\n      }\n    }\n  }\n}\n\n\n#ifdef DCT_FLOAT_SUPPORTED\n\nMETHODDEF(void)\nforward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,\n\t\t   JDIMENSION start_row, JDIMENSION start_col,\n\t\t   JDIMENSION num_blocks)\n/* This version is used for floating-point DCT implementations. */\n{\n  /* This routine is heavily used, so it's worth coding it tightly. */\n  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;\n  float_DCT_method_ptr do_dct = fdct->do_float_dct[compptr->component_index];\n  FAST_FLOAT * divisors = (FAST_FLOAT *) compptr->dct_table;\n  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */\n  JDIMENSION bi;\n\n  sample_data += start_row;\t/* fold in the vertical offset once */\n\n  for (bi = 0; bi < num_blocks; bi++, start_col += compptr->DCT_h_scaled_size) {\n    /* Perform the DCT */\n    (*do_dct) (workspace, sample_data, start_col);\n\n    /* Quantize/descale the coefficients, and store into coef_blocks[] */\n    { register FAST_FLOAT temp;\n      register int i;\n      register JCOEFPTR output_ptr = coef_blocks[bi];\n\n      for (i = 0; i < DCTSIZE2; i++) {\n\t/* Apply the quantization and scaling factor */\n\ttemp = workspace[i] * divisors[i];\n\t/* Round to nearest integer.\n\t * Since C does not specify the direction of rounding for negative\n\t * quotients, we have to force the dividend positive for portability.\n\t * The maximum coefficient size is +-16K (for 12-bit data), so this\n\t * code should work for either 16-bit or 32-bit ints.\n\t */\n\toutput_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);\n      }\n    }\n  }\n}\n\n#endif /* DCT_FLOAT_SUPPORTED */\n\n\n/*\n * Initialize for a processing pass.\n * Verify that all referenced Q-tables are present, and set up\n * the divisor table for each one.\n * In the current implementation, DCT of all components is done during\n * the first pass, even if only some components will be output in the\n * first scan.  Hence all components should be examined here.\n */\n\nMETHODDEF(void)\nstart_pass_fdctmgr (j_compress_ptr cinfo)\n{\n  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;\n  int ci, qtblno, i;\n  jpeg_component_info *compptr;\n  int method = 0;\n  JQUANT_TBL * qtbl;\n  DCTELEM * dtbl;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Select the proper DCT routine for this component's scaling */\n    switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {\n#ifdef DCT_SCALING_SUPPORTED\n    case ((1 << 8) + 1):\n      fdct->do_dct[ci] = jpeg_fdct_1x1;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((2 << 8) + 2):\n      fdct->do_dct[ci] = jpeg_fdct_2x2;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((3 << 8) + 3):\n      fdct->do_dct[ci] = jpeg_fdct_3x3;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((4 << 8) + 4):\n      fdct->do_dct[ci] = jpeg_fdct_4x4;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((5 << 8) + 5):\n      fdct->do_dct[ci] = jpeg_fdct_5x5;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((6 << 8) + 6):\n      fdct->do_dct[ci] = jpeg_fdct_6x6;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((7 << 8) + 7):\n      fdct->do_dct[ci] = jpeg_fdct_7x7;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((9 << 8) + 9):\n      fdct->do_dct[ci] = jpeg_fdct_9x9;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((10 << 8) + 10):\n      fdct->do_dct[ci] = jpeg_fdct_10x10;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((11 << 8) + 11):\n      fdct->do_dct[ci] = jpeg_fdct_11x11;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((12 << 8) + 12):\n      fdct->do_dct[ci] = jpeg_fdct_12x12;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((13 << 8) + 13):\n      fdct->do_dct[ci] = jpeg_fdct_13x13;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((14 << 8) + 14):\n      fdct->do_dct[ci] = jpeg_fdct_14x14;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((15 << 8) + 15):\n      fdct->do_dct[ci] = jpeg_fdct_15x15;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((16 << 8) + 16):\n      fdct->do_dct[ci] = jpeg_fdct_16x16;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((16 << 8) + 8):\n      fdct->do_dct[ci] = jpeg_fdct_16x8;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((14 << 8) + 7):\n      fdct->do_dct[ci] = jpeg_fdct_14x7;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((12 << 8) + 6):\n      fdct->do_dct[ci] = jpeg_fdct_12x6;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((10 << 8) + 5):\n      fdct->do_dct[ci] = jpeg_fdct_10x5;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((8 << 8) + 4):\n      fdct->do_dct[ci] = jpeg_fdct_8x4;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((6 << 8) + 3):\n      fdct->do_dct[ci] = jpeg_fdct_6x3;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((4 << 8) + 2):\n      fdct->do_dct[ci] = jpeg_fdct_4x2;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((2 << 8) + 1):\n      fdct->do_dct[ci] = jpeg_fdct_2x1;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((8 << 8) + 16):\n      fdct->do_dct[ci] = jpeg_fdct_8x16;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((7 << 8) + 14):\n      fdct->do_dct[ci] = jpeg_fdct_7x14;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((6 << 8) + 12):\n      fdct->do_dct[ci] = jpeg_fdct_6x12;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((5 << 8) + 10):\n      fdct->do_dct[ci] = jpeg_fdct_5x10;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((4 << 8) + 8):\n      fdct->do_dct[ci] = jpeg_fdct_4x8;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((3 << 8) + 6):\n      fdct->do_dct[ci] = jpeg_fdct_3x6;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((2 << 8) + 4):\n      fdct->do_dct[ci] = jpeg_fdct_2x4;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n    case ((1 << 8) + 2):\n      fdct->do_dct[ci] = jpeg_fdct_1x2;\n      method = JDCT_ISLOW;\t/* jfdctint uses islow-style table */\n      break;\n#endif\n    case ((DCTSIZE << 8) + DCTSIZE):\n      switch (cinfo->dct_method) {\n#ifdef DCT_ISLOW_SUPPORTED\n      case JDCT_ISLOW:\n\tfdct->do_dct[ci] = jpeg_fdct_islow;\n\tmethod = JDCT_ISLOW;\n\tbreak;\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n      case JDCT_IFAST:\n\tfdct->do_dct[ci] = jpeg_fdct_ifast;\n\tmethod = JDCT_IFAST;\n\tbreak;\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n      case JDCT_FLOAT:\n\tfdct->do_float_dct[ci] = jpeg_fdct_float;\n\tmethod = JDCT_FLOAT;\n\tbreak;\n#endif\n      default:\n\tERREXIT(cinfo, JERR_NOT_COMPILED);\n\tbreak;\n      }\n      break;\n    default:\n      ERREXIT2(cinfo, JERR_BAD_DCTSIZE,\n\t       compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);\n      break;\n    }\n    qtblno = compptr->quant_tbl_no;\n    /* Make sure specified quantization table is present */\n    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||\n\tcinfo->quant_tbl_ptrs[qtblno] == NULL)\n      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);\n    qtbl = cinfo->quant_tbl_ptrs[qtblno];\n    /* Create divisor table from quant table */\n    switch (method) {\n#ifdef PROVIDE_ISLOW_TABLES\n    case JDCT_ISLOW:\n      /* For LL&M IDCT method, divisors are equal to raw quantization\n       * coefficients multiplied by 8 (to counteract scaling).\n       */\n      dtbl = (DCTELEM *) compptr->dct_table;\n      for (i = 0; i < DCTSIZE2; i++) {\n\tdtbl[i] =\n\t  ((DCTELEM) qtbl->quantval[i]) << (compptr->component_needed ? 4 : 3);\n      }\n      fdct->pub.forward_DCT[ci] = forward_DCT;\n      break;\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n    case JDCT_IFAST:\n      {\n\t/* For AA&N IDCT method, divisors are equal to quantization\n\t * coefficients scaled by scalefactor[row]*scalefactor[col], where\n\t *   scalefactor[0] = 1\n\t *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7\n\t * We apply a further scale factor of 8.\n\t */\n#define CONST_BITS 14\n\tstatic const INT16 aanscales[DCTSIZE2] = {\n\t  /* precomputed values scaled up by 14 bits */\n\t  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,\n\t  22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,\n\t  21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,\n\t  19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,\n\t  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,\n\t  12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,\n\t   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,\n\t   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247\n\t};\n\tSHIFT_TEMPS\n\n\tdtbl = (DCTELEM *) compptr->dct_table;\n\tfor (i = 0; i < DCTSIZE2; i++) {\n\t  dtbl[i] = (DCTELEM)\n\t    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],\n\t\t\t\t  (INT32) aanscales[i]),\n\t\t    compptr->component_needed ? CONST_BITS-4 : CONST_BITS-3);\n\t}\n      }\n      fdct->pub.forward_DCT[ci] = forward_DCT;\n      break;\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n    case JDCT_FLOAT:\n      {\n\t/* For float AA&N IDCT method, divisors are equal to quantization\n\t * coefficients scaled by scalefactor[row]*scalefactor[col], where\n\t *   scalefactor[0] = 1\n\t *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7\n\t * We apply a further scale factor of 8.\n\t * What's actually stored is 1/divisor so that the inner loop can\n\t * use a multiplication rather than a division.\n\t */\n\tFAST_FLOAT * fdtbl = (FAST_FLOAT *) compptr->dct_table;\n\tint row, col;\n\tstatic const double aanscalefactor[DCTSIZE] = {\n\t  1.0, 1.387039845, 1.306562965, 1.175875602,\n\t  1.0, 0.785694958, 0.541196100, 0.275899379\n\t};\n\n\ti = 0;\n\tfor (row = 0; row < DCTSIZE; row++) {\n\t  for (col = 0; col < DCTSIZE; col++) {\n\t    fdtbl[i] = (FAST_FLOAT)\n\t      (1.0 / ((double) qtbl->quantval[i] *\n\t\t      aanscalefactor[row] * aanscalefactor[col] *\n\t\t      (compptr->component_needed ? 16.0 : 8.0)));\n\t    i++;\n\t  }\n\t}\n      }\n      fdct->pub.forward_DCT[ci] = forward_DCT_float;\n      break;\n#endif\n    default:\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n      break;\n    }\n  }\n}\n\n\n/*\n * Initialize FDCT manager.\n */\n\nGLOBAL(void)\njinit_forward_dct (j_compress_ptr cinfo)\n{\n  my_fdct_ptr fdct;\n  int ci;\n  jpeg_component_info *compptr;\n\n  fdct = (my_fdct_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_fdct_controller));\n  cinfo->fdct = &fdct->pub;\n  fdct->pub.start_pass = start_pass_fdctmgr;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Allocate a divisor table for each component */\n    compptr->dct_table =\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(divisor_table));\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jchuff.c",
    "content": "/*\n * jchuff.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2006-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains Huffman entropy encoding routines.\n * Both sequential and progressive modes are supported in this single module.\n *\n * Much of the complexity here has to do with supporting output suspension.\n * If the data destination module demands suspension, we want to be able to\n * back up to the start of the current MCU.  To do this, we copy state\n * variables into local working storage, and update them back to the\n * permanent JPEG objects only upon successful completion of an MCU.\n *\n * We do not support output suspension for the progressive JPEG mode, since\n * the library currently does not allow multiple-scan files to be written\n * with output suspension.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* The legal range of a DCT coefficient is\n *  -1024 .. +1023  for 8-bit data;\n * -16384 .. +16383 for 12-bit data.\n * Hence the magnitude should always fit in 10 or 14 bits respectively.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define MAX_COEF_BITS 10\n#else\n#define MAX_COEF_BITS 14\n#endif\n\n/* Derived data constructed for each Huffman table */\n\ntypedef struct {\n  unsigned int ehufco[256];\t/* code for each symbol */\n  char ehufsi[256];\t\t/* length of code for each symbol */\n  /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */\n} c_derived_tbl;\n\n\n/* Expanded entropy encoder object for Huffman encoding.\n *\n * The savable_state subrecord contains fields that change within an MCU,\n * but must not be updated permanently until we complete the MCU.\n */\n\ntypedef struct {\n  INT32 put_buffer;\t\t/* current bit-accumulation buffer */\n  int put_bits;\t\t\t/* # of bits now in it */\n  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */\n} savable_state;\n\n/* This macro is to work around compilers with missing or broken\n * structure assignment.  You'll need to fix this code if you have\n * such a compiler and you change MAX_COMPS_IN_SCAN.\n */\n\n#ifndef NO_STRUCT_ASSIGN\n#define ASSIGN_STATE(dest,src)  ((dest) = (src))\n#else\n#if MAX_COMPS_IN_SCAN == 4\n#define ASSIGN_STATE(dest,src)  \\\n\t((dest).put_buffer = (src).put_buffer, \\\n\t (dest).put_bits = (src).put_bits, \\\n\t (dest).last_dc_val[0] = (src).last_dc_val[0], \\\n\t (dest).last_dc_val[1] = (src).last_dc_val[1], \\\n\t (dest).last_dc_val[2] = (src).last_dc_val[2], \\\n\t (dest).last_dc_val[3] = (src).last_dc_val[3])\n#endif\n#endif\n\n\ntypedef struct {\n  struct jpeg_entropy_encoder pub; /* public fields */\n\n  savable_state saved;\t\t/* Bit buffer & DC state at start of MCU */\n\n  /* These fields are NOT loaded into local working state. */\n  unsigned int restarts_to_go;\t/* MCUs left in this restart interval */\n  int next_restart_num;\t\t/* next restart number to write (0-7) */\n\n  /* Pointers to derived tables (these workspaces have image lifespan) */\n  c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];\n  c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];\n\n  /* Statistics tables for optimization */\n  long * dc_count_ptrs[NUM_HUFF_TBLS];\n  long * ac_count_ptrs[NUM_HUFF_TBLS];\n\n  /* Following fields used only in progressive mode */\n\n  /* Mode flag: TRUE for optimization, FALSE for actual data output */\n  boolean gather_statistics;\n\n  /* next_output_byte/free_in_buffer are local copies of cinfo->dest fields.\n   */\n  JOCTET * next_output_byte;\t/* => next byte to write in buffer */\n  size_t free_in_buffer;\t/* # of byte spaces remaining in buffer */\n  j_compress_ptr cinfo;\t\t/* link to cinfo (needed for dump_buffer) */\n\n  /* Coding status for AC components */\n  int ac_tbl_no;\t\t/* the table number of the single component */\n  unsigned int EOBRUN;\t\t/* run length of EOBs */\n  unsigned int BE;\t\t/* # of buffered correction bits before MCU */\n  char * bit_buffer;\t\t/* buffer for correction bits (1 per char) */\n  /* packing correction bits tightly would save some space but cost time... */\n} huff_entropy_encoder;\n\ntypedef huff_entropy_encoder * huff_entropy_ptr;\n\n/* Working state while writing an MCU (sequential mode).\n * This struct contains all the fields that are needed by subroutines.\n */\n\ntypedef struct {\n  JOCTET * next_output_byte;\t/* => next byte to write in buffer */\n  size_t free_in_buffer;\t/* # of byte spaces remaining in buffer */\n  savable_state cur;\t\t/* Current bit buffer & DC state */\n  j_compress_ptr cinfo;\t\t/* dump_buffer needs access to this */\n} working_state;\n\n/* MAX_CORR_BITS is the number of bits the AC refinement correction-bit\n * buffer can hold.  Larger sizes may slightly improve compression, but\n * 1000 is already well into the realm of overkill.\n * The minimum safe size is 64 bits.\n */\n\n#define MAX_CORR_BITS  1000\t/* Max # of correction bits I can buffer */\n\n/* IRIGHT_SHIFT is like RIGHT_SHIFT, but works on int rather than INT32.\n * We assume that int right shift is unsigned if INT32 right shift is,\n * which should be safe.\n */\n\n#ifdef RIGHT_SHIFT_IS_UNSIGNED\n#define ISHIFT_TEMPS\tint ishift_temp;\n#define IRIGHT_SHIFT(x,shft)  \\\n\t((ishift_temp = (x)) < 0 ? \\\n\t (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \\\n\t (ishift_temp >> (shft)))\n#else\n#define ISHIFT_TEMPS\n#define IRIGHT_SHIFT(x,shft)\t((x) >> (shft))\n#endif\n\n\n/*\n * Compute the derived values for a Huffman table.\n * This routine also performs some validation checks on the table.\n */\n\nLOCAL(void)\njpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,\n\t\t\t c_derived_tbl ** pdtbl)\n{\n  JHUFF_TBL *htbl;\n  c_derived_tbl *dtbl;\n  int p, i, l, lastp, si, maxsymbol;\n  char huffsize[257];\n  unsigned int huffcode[257];\n  unsigned int code;\n\n  /* Note that huffsize[] and huffcode[] are filled in code-length order,\n   * paralleling the order of the symbols themselves in htbl->huffval[].\n   */\n\n  /* Find the input Huffman table */\n  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)\n    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);\n  htbl =\n    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];\n  if (htbl == NULL)\n    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);\n\n  /* Allocate a workspace if we haven't already done so. */\n  if (*pdtbl == NULL)\n    *pdtbl = (c_derived_tbl *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(c_derived_tbl));\n  dtbl = *pdtbl;\n  \n  /* Figure C.1: make table of Huffman code length for each symbol */\n\n  p = 0;\n  for (l = 1; l <= 16; l++) {\n    i = (int) htbl->bits[l];\n    if (i < 0 || p + i > 256)\t/* protect against table overrun */\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    while (i--)\n      huffsize[p++] = (char) l;\n  }\n  huffsize[p] = 0;\n  lastp = p;\n  \n  /* Figure C.2: generate the codes themselves */\n  /* We also validate that the counts represent a legal Huffman code tree. */\n\n  code = 0;\n  si = huffsize[0];\n  p = 0;\n  while (huffsize[p]) {\n    while (((int) huffsize[p]) == si) {\n      huffcode[p++] = code;\n      code++;\n    }\n    /* code is now 1 more than the last code used for codelength si; but\n     * it must still fit in si bits, since no code is allowed to be all ones.\n     */\n    if (((INT32) code) >= (((INT32) 1) << si))\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    code <<= 1;\n    si++;\n  }\n  \n  /* Figure C.3: generate encoding tables */\n  /* These are code and size indexed by symbol value */\n\n  /* Set all codeless symbols to have code length 0;\n   * this lets us detect duplicate VAL entries here, and later\n   * allows emit_bits to detect any attempt to emit such symbols.\n   */\n  MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));\n\n  /* This is also a convenient place to check for out-of-range\n   * and duplicated VAL entries.  We allow 0..255 for AC symbols\n   * but only 0..15 for DC.  (We could constrain them further\n   * based on data depth and mode, but this seems enough.)\n   */\n  maxsymbol = isDC ? 15 : 255;\n\n  for (p = 0; p < lastp; p++) {\n    i = htbl->huffval[p];\n    if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    dtbl->ehufco[i] = huffcode[p];\n    dtbl->ehufsi[i] = huffsize[p];\n  }\n}\n\n\n/* Outputting bytes to the file.\n * NB: these must be called only when actually outputting,\n * that is, entropy->gather_statistics == FALSE.\n */\n\n/* Emit a byte, taking 'action' if must suspend. */\n#define emit_byte_s(state,val,action)  \\\n\t{ *(state)->next_output_byte++ = (JOCTET) (val);  \\\n\t  if (--(state)->free_in_buffer == 0)  \\\n\t    if (! dump_buffer_s(state))  \\\n\t      { action; } }\n\n/* Emit a byte */\n#define emit_byte_e(entropy,val)  \\\n\t{ *(entropy)->next_output_byte++ = (JOCTET) (val);  \\\n\t  if (--(entropy)->free_in_buffer == 0)  \\\n\t    dump_buffer_e(entropy); }\n\n\nLOCAL(boolean)\ndump_buffer_s (working_state * state)\n/* Empty the output buffer; return TRUE if successful, FALSE if must suspend */\n{\n  struct jpeg_destination_mgr * dest = state->cinfo->dest;\n\n  if (! (*dest->empty_output_buffer) (state->cinfo))\n    return FALSE;\n  /* After a successful buffer dump, must reset buffer pointers */\n  state->next_output_byte = dest->next_output_byte;\n  state->free_in_buffer = dest->free_in_buffer;\n  return TRUE;\n}\n\n\nLOCAL(void)\ndump_buffer_e (huff_entropy_ptr entropy)\n/* Empty the output buffer; we do not support suspension in this case. */\n{\n  struct jpeg_destination_mgr * dest = entropy->cinfo->dest;\n\n  if (! (*dest->empty_output_buffer) (entropy->cinfo))\n    ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);\n  /* After a successful buffer dump, must reset buffer pointers */\n  entropy->next_output_byte = dest->next_output_byte;\n  entropy->free_in_buffer = dest->free_in_buffer;\n}\n\n\n/* Outputting bits to the file */\n\n/* Only the right 24 bits of put_buffer are used; the valid bits are\n * left-justified in this part.  At most 16 bits can be passed to emit_bits\n * in one call, and we never retain more than 7 bits in put_buffer\n * between calls, so 24 bits are sufficient.\n */\n\nINLINE\nLOCAL(boolean)\nemit_bits_s (working_state * state, unsigned int code, int size)\n/* Emit some bits; return TRUE if successful, FALSE if must suspend */\n{\n  /* This routine is heavily used, so it's worth coding tightly. */\n  register INT32 put_buffer;\n  register int put_bits;\n\n  /* if size is 0, caller used an invalid Huffman table entry */\n  if (size == 0)\n    ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);\n\n  /* mask off any extra bits in code */\n  put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);\n\n  /* new number of bits in buffer */\n  put_bits = size + state->cur.put_bits;\n\n  put_buffer <<= 24 - put_bits; /* align incoming bits */\n\n  /* and merge with old buffer contents */\n  put_buffer |= state->cur.put_buffer;\n\n  while (put_bits >= 8) {\n    int c = (int) ((put_buffer >> 16) & 0xFF);\n\n    emit_byte_s(state, c, return FALSE);\n    if (c == 0xFF) {\t\t/* need to stuff a zero byte? */\n      emit_byte_s(state, 0, return FALSE);\n    }\n    put_buffer <<= 8;\n    put_bits -= 8;\n  }\n\n  state->cur.put_buffer = put_buffer; /* update state variables */\n  state->cur.put_bits = put_bits;\n\n  return TRUE;\n}\n\n\nINLINE\nLOCAL(void)\nemit_bits_e (huff_entropy_ptr entropy, unsigned int code, int size)\n/* Emit some bits, unless we are in gather mode */\n{\n  /* This routine is heavily used, so it's worth coding tightly. */\n  register INT32 put_buffer;\n  register int put_bits;\n\n  /* if size is 0, caller used an invalid Huffman table entry */\n  if (size == 0)\n    ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);\n\n  if (entropy->gather_statistics)\n    return;\t\t\t/* do nothing if we're only getting stats */\n\n  /* mask off any extra bits in code */\n  put_buffer = ((INT32) code) & ((((INT32) 1) << size) - 1);\n\n  /* new number of bits in buffer */\n  put_bits = size + entropy->saved.put_bits;\n\n  put_buffer <<= 24 - put_bits; /* align incoming bits */\n\n  /* and merge with old buffer contents */\n  put_buffer |= entropy->saved.put_buffer;\n\n  while (put_bits >= 8) {\n    int c = (int) ((put_buffer >> 16) & 0xFF);\n\n    emit_byte_e(entropy, c);\n    if (c == 0xFF) {\t\t/* need to stuff a zero byte? */\n      emit_byte_e(entropy, 0);\n    }\n    put_buffer <<= 8;\n    put_bits -= 8;\n  }\n\n  entropy->saved.put_buffer = put_buffer; /* update variables */\n  entropy->saved.put_bits = put_bits;\n}\n\n\nLOCAL(boolean)\nflush_bits_s (working_state * state)\n{\n  if (! emit_bits_s(state, 0x7F, 7)) /* fill any partial byte with ones */\n    return FALSE;\n  state->cur.put_buffer = 0;\t     /* and reset bit-buffer to empty */\n  state->cur.put_bits = 0;\n  return TRUE;\n}\n\n\nLOCAL(void)\nflush_bits_e (huff_entropy_ptr entropy)\n{\n  emit_bits_e(entropy, 0x7F, 7); /* fill any partial byte with ones */\n  entropy->saved.put_buffer = 0; /* and reset bit-buffer to empty */\n  entropy->saved.put_bits = 0;\n}\n\n\n/*\n * Emit (or just count) a Huffman symbol.\n */\n\nINLINE\nLOCAL(void)\nemit_dc_symbol (huff_entropy_ptr entropy, int tbl_no, int symbol)\n{\n  if (entropy->gather_statistics)\n    entropy->dc_count_ptrs[tbl_no][symbol]++;\n  else {\n    c_derived_tbl * tbl = entropy->dc_derived_tbls[tbl_no];\n    emit_bits_e(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);\n  }\n}\n\n\nINLINE\nLOCAL(void)\nemit_ac_symbol (huff_entropy_ptr entropy, int tbl_no, int symbol)\n{\n  if (entropy->gather_statistics)\n    entropy->ac_count_ptrs[tbl_no][symbol]++;\n  else {\n    c_derived_tbl * tbl = entropy->ac_derived_tbls[tbl_no];\n    emit_bits_e(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);\n  }\n}\n\n\n/*\n * Emit bits from a correction bit buffer.\n */\n\nLOCAL(void)\nemit_buffered_bits (huff_entropy_ptr entropy, char * bufstart,\n\t\t    unsigned int nbits)\n{\n  if (entropy->gather_statistics)\n    return;\t\t\t/* no real work */\n\n  while (nbits > 0) {\n    emit_bits_e(entropy, (unsigned int) (*bufstart), 1);\n    bufstart++;\n    nbits--;\n  }\n}\n\n\n/*\n * Emit any pending EOBRUN symbol.\n */\n\nLOCAL(void)\nemit_eobrun (huff_entropy_ptr entropy)\n{\n  register int temp, nbits;\n\n  if (entropy->EOBRUN > 0) {\t/* if there is any pending EOBRUN */\n    temp = entropy->EOBRUN;\n    nbits = 0;\n    while ((temp >>= 1))\n      nbits++;\n    /* safety check: shouldn't happen given limited correction-bit buffer */\n    if (nbits > 14)\n      ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);\n\n    emit_ac_symbol(entropy, entropy->ac_tbl_no, nbits << 4);\n    if (nbits)\n      emit_bits_e(entropy, entropy->EOBRUN, nbits);\n\n    entropy->EOBRUN = 0;\n\n    /* Emit any buffered correction bits */\n    emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);\n    entropy->BE = 0;\n  }\n}\n\n\n/*\n * Emit a restart marker & resynchronize predictions.\n */\n\nLOCAL(boolean)\nemit_restart_s (working_state * state, int restart_num)\n{\n  int ci;\n\n  if (! flush_bits_s(state))\n    return FALSE;\n\n  emit_byte_s(state, 0xFF, return FALSE);\n  emit_byte_s(state, JPEG_RST0 + restart_num, return FALSE);\n\n  /* Re-initialize DC predictions to 0 */\n  for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)\n    state->cur.last_dc_val[ci] = 0;\n\n  /* The restart counter is not updated until we successfully write the MCU. */\n\n  return TRUE;\n}\n\n\nLOCAL(void)\nemit_restart_e (huff_entropy_ptr entropy, int restart_num)\n{\n  int ci;\n\n  emit_eobrun(entropy);\n\n  if (! entropy->gather_statistics) {\n    flush_bits_e(entropy);\n    emit_byte_e(entropy, 0xFF);\n    emit_byte_e(entropy, JPEG_RST0 + restart_num);\n  }\n\n  if (entropy->cinfo->Ss == 0) {\n    /* Re-initialize DC predictions to 0 */\n    for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)\n      entropy->saved.last_dc_val[ci] = 0;\n  } else {\n    /* Re-initialize all AC-related fields to 0 */\n    entropy->EOBRUN = 0;\n    entropy->BE = 0;\n  }\n}\n\n\n/*\n * MCU encoding for DC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\nencode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  register int temp, temp2;\n  register int nbits;\n  int blkn, ci, tbl;\n  ISHIFT_TEMPS\n\n  entropy->next_output_byte = cinfo->dest->next_output_byte;\n  entropy->free_in_buffer = cinfo->dest->free_in_buffer;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval)\n    if (entropy->restarts_to_go == 0)\n      emit_restart_e(entropy, entropy->next_restart_num);\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    ci = cinfo->MCU_membership[blkn];\n    tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;\n\n    /* Compute the DC value after the required point transform by Al.\n     * This is simply an arithmetic right shift.\n     */\n    temp = IRIGHT_SHIFT((int) (MCU_data[blkn][0][0]), cinfo->Al);\n\n    /* DC differences are figured on the point-transformed values. */\n    temp2 = temp - entropy->saved.last_dc_val[ci];\n    entropy->saved.last_dc_val[ci] = temp;\n\n    /* Encode the DC coefficient difference per section G.1.2.1 */\n    temp = temp2;\n    if (temp < 0) {\n      temp = -temp;\t\t/* temp is abs value of input */\n      /* For a negative input, want temp2 = bitwise complement of abs(input) */\n      /* This code assumes we are on a two's complement machine */\n      temp2--;\n    }\n\n    /* Find the number of bits needed for the magnitude of the coefficient */\n    nbits = 0;\n    while (temp) {\n      nbits++;\n      temp >>= 1;\n    }\n    /* Check for out-of-range coefficient values.\n     * Since we're encoding a difference, the range limit is twice as much.\n     */\n    if (nbits > MAX_COEF_BITS+1)\n      ERREXIT(cinfo, JERR_BAD_DCT_COEF);\n\n    /* Count/emit the Huffman-coded symbol for the number of bits */\n    emit_dc_symbol(entropy, tbl, nbits);\n\n    /* Emit that number of bits of the value, if positive, */\n    /* or the complement of its magnitude, if negative. */\n    if (nbits)\t\t\t/* emit_bits rejects calls with size 0 */\n      emit_bits_e(entropy, (unsigned int) temp2, nbits);\n  }\n\n  cinfo->dest->next_output_byte = entropy->next_output_byte;\n  cinfo->dest->free_in_buffer = entropy->free_in_buffer;\n\n  /* Update restart-interval state too */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for AC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\nencode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  JBLOCKROW block;\n  register int temp, temp2;\n  register int nbits;\n  register int r, k;\n  int Se, Al;\n\n  entropy->next_output_byte = cinfo->dest->next_output_byte;\n  entropy->free_in_buffer = cinfo->dest->free_in_buffer;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval)\n    if (entropy->restarts_to_go == 0)\n      emit_restart_e(entropy, entropy->next_restart_num);\n\n  Se = cinfo->Se;\n  Al = cinfo->Al;\n  natural_order = cinfo->natural_order;\n\n  /* Encode the MCU data block */\n  block = MCU_data[0];\n\n  /* Encode the AC coefficients per section G.1.2.2, fig. G.3 */\n  \n  r = 0;\t\t\t/* r = run length of zeros */\n   \n  for (k = cinfo->Ss; k <= Se; k++) {\n    if ((temp = (*block)[natural_order[k]]) == 0) {\n      r++;\n      continue;\n    }\n    /* We must apply the point transform by Al.  For AC coefficients this\n     * is an integer division with rounding towards 0.  To do this portably\n     * in C, we shift after obtaining the absolute value; so the code is\n     * interwoven with finding the abs value (temp) and output bits (temp2).\n     */\n    if (temp < 0) {\n      temp = -temp;\t\t/* temp is abs value of input */\n      temp >>= Al;\t\t/* apply the point transform */\n      /* For a negative coef, want temp2 = bitwise complement of abs(coef) */\n      temp2 = ~temp;\n    } else {\n      temp >>= Al;\t\t/* apply the point transform */\n      temp2 = temp;\n    }\n    /* Watch out for case that nonzero coef is zero after point transform */\n    if (temp == 0) {\n      r++;\n      continue;\n    }\n\n    /* Emit any pending EOBRUN */\n    if (entropy->EOBRUN > 0)\n      emit_eobrun(entropy);\n    /* if run length > 15, must emit special run-length-16 codes (0xF0) */\n    while (r > 15) {\n      emit_ac_symbol(entropy, entropy->ac_tbl_no, 0xF0);\n      r -= 16;\n    }\n\n    /* Find the number of bits needed for the magnitude of the coefficient */\n    nbits = 1;\t\t\t/* there must be at least one 1 bit */\n    while ((temp >>= 1))\n      nbits++;\n    /* Check for out-of-range coefficient values */\n    if (nbits > MAX_COEF_BITS)\n      ERREXIT(cinfo, JERR_BAD_DCT_COEF);\n\n    /* Count/emit Huffman symbol for run length / number of bits */\n    emit_ac_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);\n\n    /* Emit that number of bits of the value, if positive, */\n    /* or the complement of its magnitude, if negative. */\n    emit_bits_e(entropy, (unsigned int) temp2, nbits);\n\n    r = 0;\t\t\t/* reset zero run length */\n  }\n\n  if (r > 0) {\t\t\t/* If there are trailing zeroes, */\n    entropy->EOBRUN++;\t\t/* count an EOB */\n    if (entropy->EOBRUN == 0x7FFF)\n      emit_eobrun(entropy);\t/* force it out to avoid overflow */\n  }\n\n  cinfo->dest->next_output_byte = entropy->next_output_byte;\n  cinfo->dest->free_in_buffer = entropy->free_in_buffer;\n\n  /* Update restart-interval state too */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for DC successive approximation refinement scan.\n * Note: we assume such scans can be multi-component,\n * although the spec is not very clear on the point.\n */\n\nMETHODDEF(boolean)\nencode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int Al, blkn;\n\n  entropy->next_output_byte = cinfo->dest->next_output_byte;\n  entropy->free_in_buffer = cinfo->dest->free_in_buffer;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval)\n    if (entropy->restarts_to_go == 0)\n      emit_restart_e(entropy, entropy->next_restart_num);\n\n  Al = cinfo->Al;\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    /* We simply emit the Al'th bit of the DC coefficient value. */\n    emit_bits_e(entropy, (unsigned int) (MCU_data[blkn][0][0] >> Al), 1);\n  }\n\n  cinfo->dest->next_output_byte = entropy->next_output_byte;\n  cinfo->dest->free_in_buffer = entropy->free_in_buffer;\n\n  /* Update restart-interval state too */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU encoding for AC successive approximation refinement scan.\n */\n\nMETHODDEF(boolean)\nencode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  JBLOCKROW block;\n  register int temp;\n  register int r, k;\n  int Se, Al;\n  int EOB;\n  char *BR_buffer;\n  unsigned int BR;\n  int absvalues[DCTSIZE2];\n\n  entropy->next_output_byte = cinfo->dest->next_output_byte;\n  entropy->free_in_buffer = cinfo->dest->free_in_buffer;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval)\n    if (entropy->restarts_to_go == 0)\n      emit_restart_e(entropy, entropy->next_restart_num);\n\n  Se = cinfo->Se;\n  Al = cinfo->Al;\n  natural_order = cinfo->natural_order;\n\n  /* Encode the MCU data block */\n  block = MCU_data[0];\n\n  /* It is convenient to make a pre-pass to determine the transformed\n   * coefficients' absolute values and the EOB position.\n   */\n  EOB = 0;\n  for (k = cinfo->Ss; k <= Se; k++) {\n    temp = (*block)[natural_order[k]];\n    /* We must apply the point transform by Al.  For AC coefficients this\n     * is an integer division with rounding towards 0.  To do this portably\n     * in C, we shift after obtaining the absolute value.\n     */\n    if (temp < 0)\n      temp = -temp;\t\t/* temp is abs value of input */\n    temp >>= Al;\t\t/* apply the point transform */\n    absvalues[k] = temp;\t/* save abs value for main pass */\n    if (temp == 1)\n      EOB = k;\t\t\t/* EOB = index of last newly-nonzero coef */\n  }\n\n  /* Encode the AC coefficients per section G.1.2.3, fig. G.7 */\n  \n  r = 0;\t\t\t/* r = run length of zeros */\n  BR = 0;\t\t\t/* BR = count of buffered bits added now */\n  BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */\n\n  for (k = cinfo->Ss; k <= Se; k++) {\n    if ((temp = absvalues[k]) == 0) {\n      r++;\n      continue;\n    }\n\n    /* Emit any required ZRLs, but not if they can be folded into EOB */\n    while (r > 15 && k <= EOB) {\n      /* emit any pending EOBRUN and the BE correction bits */\n      emit_eobrun(entropy);\n      /* Emit ZRL */\n      emit_ac_symbol(entropy, entropy->ac_tbl_no, 0xF0);\n      r -= 16;\n      /* Emit buffered correction bits that must be associated with ZRL */\n      emit_buffered_bits(entropy, BR_buffer, BR);\n      BR_buffer = entropy->bit_buffer; /* BE bits are gone now */\n      BR = 0;\n    }\n\n    /* If the coef was previously nonzero, it only needs a correction bit.\n     * NOTE: a straight translation of the spec's figure G.7 would suggest\n     * that we also need to test r > 15.  But if r > 15, we can only get here\n     * if k > EOB, which implies that this coefficient is not 1.\n     */\n    if (temp > 1) {\n      /* The correction bit is the next bit of the absolute value. */\n      BR_buffer[BR++] = (char) (temp & 1);\n      continue;\n    }\n\n    /* Emit any pending EOBRUN and the BE correction bits */\n    emit_eobrun(entropy);\n\n    /* Count/emit Huffman symbol for run length / number of bits */\n    emit_ac_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);\n\n    /* Emit output bit for newly-nonzero coef */\n    temp = ((*block)[natural_order[k]] < 0) ? 0 : 1;\n    emit_bits_e(entropy, (unsigned int) temp, 1);\n\n    /* Emit buffered correction bits that must be associated with this code */\n    emit_buffered_bits(entropy, BR_buffer, BR);\n    BR_buffer = entropy->bit_buffer; /* BE bits are gone now */\n    BR = 0;\n    r = 0;\t\t\t/* reset zero run length */\n  }\n\n  if (r > 0 || BR > 0) {\t/* If there are trailing zeroes, */\n    entropy->EOBRUN++;\t\t/* count an EOB */\n    entropy->BE += BR;\t\t/* concat my correction bits to older ones */\n    /* We force out the EOB if we risk either:\n     * 1. overflow of the EOB counter;\n     * 2. overflow of the correction bit buffer during the next MCU.\n     */\n    if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))\n      emit_eobrun(entropy);\n  }\n\n  cinfo->dest->next_output_byte = entropy->next_output_byte;\n  cinfo->dest->free_in_buffer = entropy->free_in_buffer;\n\n  /* Update restart-interval state too */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  return TRUE;\n}\n\n\n/* Encode a single block's worth of coefficients */\n\nLOCAL(boolean)\nencode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,\n\t\t  c_derived_tbl *dctbl, c_derived_tbl *actbl)\n{\n  register int temp, temp2;\n  register int nbits;\n  register int r, k;\n  int Se = state->cinfo->lim_Se;\n  const int * natural_order = state->cinfo->natural_order;\n\n  /* Encode the DC coefficient difference per section F.1.2.1 */\n\n  temp = temp2 = block[0] - last_dc_val;\n\n  if (temp < 0) {\n    temp = -temp;\t\t/* temp is abs value of input */\n    /* For a negative input, want temp2 = bitwise complement of abs(input) */\n    /* This code assumes we are on a two's complement machine */\n    temp2--;\n  }\n\n  /* Find the number of bits needed for the magnitude of the coefficient */\n  nbits = 0;\n  while (temp) {\n    nbits++;\n    temp >>= 1;\n  }\n  /* Check for out-of-range coefficient values.\n   * Since we're encoding a difference, the range limit is twice as much.\n   */\n  if (nbits > MAX_COEF_BITS+1)\n    ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);\n\n  /* Emit the Huffman-coded symbol for the number of bits */\n  if (! emit_bits_s(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))\n    return FALSE;\n\n  /* Emit that number of bits of the value, if positive, */\n  /* or the complement of its magnitude, if negative. */\n  if (nbits)\t\t\t/* emit_bits rejects calls with size 0 */\n    if (! emit_bits_s(state, (unsigned int) temp2, nbits))\n      return FALSE;\n\n  /* Encode the AC coefficients per section F.1.2.2 */\n\n  r = 0;\t\t\t/* r = run length of zeros */\n\n  for (k = 1; k <= Se; k++) {\n    if ((temp2 = block[natural_order[k]]) == 0) {\n      r++;\n    } else {\n      /* if run length > 15, must emit special run-length-16 codes (0xF0) */\n      while (r > 15) {\n\tif (! emit_bits_s(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))\n\t  return FALSE;\n\tr -= 16;\n      }\n\n      temp = temp2;\n      if (temp < 0) {\n\ttemp = -temp;\t\t/* temp is abs value of input */\n\t/* This code assumes we are on a two's complement machine */\n\ttemp2--;\n      }\n\n      /* Find the number of bits needed for the magnitude of the coefficient */\n      nbits = 1;\t\t/* there must be at least one 1 bit */\n      while ((temp >>= 1))\n\tnbits++;\n      /* Check for out-of-range coefficient values */\n      if (nbits > MAX_COEF_BITS)\n\tERREXIT(state->cinfo, JERR_BAD_DCT_COEF);\n\n      /* Emit Huffman symbol for run length / number of bits */\n      temp = (r << 4) + nbits;\n      if (! emit_bits_s(state, actbl->ehufco[temp], actbl->ehufsi[temp]))\n\treturn FALSE;\n\n      /* Emit that number of bits of the value, if positive, */\n      /* or the complement of its magnitude, if negative. */\n      if (! emit_bits_s(state, (unsigned int) temp2, nbits))\n\treturn FALSE;\n\n      r = 0;\n    }\n  }\n\n  /* If the last coef(s) were zero, emit an end-of-block code */\n  if (r > 0)\n    if (! emit_bits_s(state, actbl->ehufco[0], actbl->ehufsi[0]))\n      return FALSE;\n\n  return TRUE;\n}\n\n\n/*\n * Encode and output one MCU's worth of Huffman-compressed coefficients.\n */\n\nMETHODDEF(boolean)\nencode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  working_state state;\n  int blkn, ci;\n  jpeg_component_info * compptr;\n\n  /* Load up working state */\n  state.next_output_byte = cinfo->dest->next_output_byte;\n  state.free_in_buffer = cinfo->dest->free_in_buffer;\n  ASSIGN_STATE(state.cur, entropy->saved);\n  state.cinfo = cinfo;\n\n  /* Emit restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! emit_restart_s(&state, entropy->next_restart_num))\n\treturn FALSE;\n  }\n\n  /* Encode the MCU data blocks */\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    ci = cinfo->MCU_membership[blkn];\n    compptr = cinfo->cur_comp_info[ci];\n    if (! encode_one_block(&state,\n\t\t\t   MCU_data[blkn][0], state.cur.last_dc_val[ci],\n\t\t\t   entropy->dc_derived_tbls[compptr->dc_tbl_no],\n\t\t\t   entropy->ac_derived_tbls[compptr->ac_tbl_no]))\n      return FALSE;\n    /* Update last_dc_val */\n    state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];\n  }\n\n  /* Completed MCU, so update state */\n  cinfo->dest->next_output_byte = state.next_output_byte;\n  cinfo->dest->free_in_buffer = state.free_in_buffer;\n  ASSIGN_STATE(entropy->saved, state.cur);\n\n  /* Update restart-interval state too */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      entropy->restarts_to_go = cinfo->restart_interval;\n      entropy->next_restart_num++;\n      entropy->next_restart_num &= 7;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  return TRUE;\n}\n\n\n/*\n * Finish up at the end of a Huffman-compressed scan.\n */\n\nMETHODDEF(void)\nfinish_pass_huff (j_compress_ptr cinfo)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  working_state state;\n\n  if (cinfo->progressive_mode) {\n    entropy->next_output_byte = cinfo->dest->next_output_byte;\n    entropy->free_in_buffer = cinfo->dest->free_in_buffer;\n\n    /* Flush out any buffered data */\n    emit_eobrun(entropy);\n    flush_bits_e(entropy);\n\n    cinfo->dest->next_output_byte = entropy->next_output_byte;\n    cinfo->dest->free_in_buffer = entropy->free_in_buffer;\n  } else {\n    /* Load up working state ... flush_bits needs it */\n    state.next_output_byte = cinfo->dest->next_output_byte;\n    state.free_in_buffer = cinfo->dest->free_in_buffer;\n    ASSIGN_STATE(state.cur, entropy->saved);\n    state.cinfo = cinfo;\n\n    /* Flush out the last data */\n    if (! flush_bits_s(&state))\n      ERREXIT(cinfo, JERR_CANT_SUSPEND);\n\n    /* Update state */\n    cinfo->dest->next_output_byte = state.next_output_byte;\n    cinfo->dest->free_in_buffer = state.free_in_buffer;\n    ASSIGN_STATE(entropy->saved, state.cur);\n  }\n}\n\n\n/*\n * Huffman coding optimization.\n *\n * We first scan the supplied data and count the number of uses of each symbol\n * that is to be Huffman-coded. (This process MUST agree with the code above.)\n * Then we build a Huffman coding tree for the observed counts.\n * Symbols which are not needed at all for the particular image are not\n * assigned any code, which saves space in the DHT marker as well as in\n * the compressed data.\n */\n\n\n/* Process a single block's worth of coefficients */\n\nLOCAL(void)\nhtest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,\n\t\t long dc_counts[], long ac_counts[])\n{\n  register int temp;\n  register int nbits;\n  register int r, k;\n  int Se = cinfo->lim_Se;\n  const int * natural_order = cinfo->natural_order;\n\n  /* Encode the DC coefficient difference per section F.1.2.1 */\n\n  temp = block[0] - last_dc_val;\n  if (temp < 0)\n    temp = -temp;\n\n  /* Find the number of bits needed for the magnitude of the coefficient */\n  nbits = 0;\n  while (temp) {\n    nbits++;\n    temp >>= 1;\n  }\n  /* Check for out-of-range coefficient values.\n   * Since we're encoding a difference, the range limit is twice as much.\n   */\n  if (nbits > MAX_COEF_BITS+1)\n    ERREXIT(cinfo, JERR_BAD_DCT_COEF);\n\n  /* Count the Huffman symbol for the number of bits */\n  dc_counts[nbits]++;\n\n  /* Encode the AC coefficients per section F.1.2.2 */\n\n  r = 0;\t\t\t/* r = run length of zeros */\n\n  for (k = 1; k <= Se; k++) {\n    if ((temp = block[natural_order[k]]) == 0) {\n      r++;\n    } else {\n      /* if run length > 15, must emit special run-length-16 codes (0xF0) */\n      while (r > 15) {\n\tac_counts[0xF0]++;\n\tr -= 16;\n      }\n\n      /* Find the number of bits needed for the magnitude of the coefficient */\n      if (temp < 0)\n\ttemp = -temp;\n\n      /* Find the number of bits needed for the magnitude of the coefficient */\n      nbits = 1;\t\t/* there must be at least one 1 bit */\n      while ((temp >>= 1))\n\tnbits++;\n      /* Check for out-of-range coefficient values */\n      if (nbits > MAX_COEF_BITS)\n\tERREXIT(cinfo, JERR_BAD_DCT_COEF);\n\n      /* Count Huffman symbol for run length / number of bits */\n      ac_counts[(r << 4) + nbits]++;\n\n      r = 0;\n    }\n  }\n\n  /* If the last coef(s) were zero, emit an end-of-block code */\n  if (r > 0)\n    ac_counts[0]++;\n}\n\n\n/*\n * Trial-encode one MCU's worth of Huffman-compressed coefficients.\n * No data is actually output, so no suspension return is possible.\n */\n\nMETHODDEF(boolean)\nencode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int blkn, ci;\n  jpeg_component_info * compptr;\n\n  /* Take care of restart intervals if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0) {\n      /* Re-initialize DC predictions to 0 */\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++)\n\tentropy->saved.last_dc_val[ci] = 0;\n      /* Update restart state */\n      entropy->restarts_to_go = cinfo->restart_interval;\n    }\n    entropy->restarts_to_go--;\n  }\n\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    ci = cinfo->MCU_membership[blkn];\n    compptr = cinfo->cur_comp_info[ci];\n    htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],\n\t\t    entropy->dc_count_ptrs[compptr->dc_tbl_no],\n\t\t    entropy->ac_count_ptrs[compptr->ac_tbl_no]);\n    entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];\n  }\n\n  return TRUE;\n}\n\n\n/*\n * Generate the best Huffman code table for the given counts, fill htbl.\n *\n * The JPEG standard requires that no symbol be assigned a codeword of all\n * one bits (so that padding bits added at the end of a compressed segment\n * can't look like a valid code).  Because of the canonical ordering of\n * codewords, this just means that there must be an unused slot in the\n * longest codeword length category.  Section K.2 of the JPEG spec suggests\n * reserving such a slot by pretending that symbol 256 is a valid symbol\n * with count 1.  In theory that's not optimal; giving it count zero but\n * including it in the symbol set anyway should give a better Huffman code.\n * But the theoretically better code actually seems to come out worse in\n * practice, because it produces more all-ones bytes (which incur stuffed\n * zero bytes in the final file).  In any case the difference is tiny.\n *\n * The JPEG standard requires Huffman codes to be no more than 16 bits long.\n * If some symbols have a very small but nonzero probability, the Huffman tree\n * must be adjusted to meet the code length restriction.  We currently use\n * the adjustment method suggested in JPEG section K.2.  This method is *not*\n * optimal; it may not choose the best possible limited-length code.  But\n * typically only very-low-frequency symbols will be given less-than-optimal\n * lengths, so the code is almost optimal.  Experimental comparisons against\n * an optimal limited-length-code algorithm indicate that the difference is\n * microscopic --- usually less than a hundredth of a percent of total size.\n * So the extra complexity of an optimal algorithm doesn't seem worthwhile.\n */\n\nLOCAL(void)\njpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])\n{\n#define MAX_CLEN 32\t\t/* assumed maximum initial code length */\n  UINT8 bits[MAX_CLEN+1];\t/* bits[k] = # of symbols with code length k */\n  int codesize[257];\t\t/* codesize[k] = code length of symbol k */\n  int others[257];\t\t/* next symbol in current branch of tree */\n  int c1, c2;\n  int p, i, j;\n  long v;\n\n  /* This algorithm is explained in section K.2 of the JPEG standard */\n\n  MEMZERO(bits, SIZEOF(bits));\n  MEMZERO(codesize, SIZEOF(codesize));\n  for (i = 0; i < 257; i++)\n    others[i] = -1;\t\t/* init links to empty */\n  \n  freq[256] = 1;\t\t/* make sure 256 has a nonzero count */\n  /* Including the pseudo-symbol 256 in the Huffman procedure guarantees\n   * that no real symbol is given code-value of all ones, because 256\n   * will be placed last in the largest codeword category.\n   */\n\n  /* Huffman's basic algorithm to assign optimal code lengths to symbols */\n\n  for (;;) {\n    /* Find the smallest nonzero frequency, set c1 = its symbol */\n    /* In case of ties, take the larger symbol number */\n    c1 = -1;\n    v = 1000000000L;\n    for (i = 0; i <= 256; i++) {\n      if (freq[i] && freq[i] <= v) {\n\tv = freq[i];\n\tc1 = i;\n      }\n    }\n\n    /* Find the next smallest nonzero frequency, set c2 = its symbol */\n    /* In case of ties, take the larger symbol number */\n    c2 = -1;\n    v = 1000000000L;\n    for (i = 0; i <= 256; i++) {\n      if (freq[i] && freq[i] <= v && i != c1) {\n\tv = freq[i];\n\tc2 = i;\n      }\n    }\n\n    /* Done if we've merged everything into one frequency */\n    if (c2 < 0)\n      break;\n    \n    /* Else merge the two counts/trees */\n    freq[c1] += freq[c2];\n    freq[c2] = 0;\n\n    /* Increment the codesize of everything in c1's tree branch */\n    codesize[c1]++;\n    while (others[c1] >= 0) {\n      c1 = others[c1];\n      codesize[c1]++;\n    }\n    \n    others[c1] = c2;\t\t/* chain c2 onto c1's tree branch */\n    \n    /* Increment the codesize of everything in c2's tree branch */\n    codesize[c2]++;\n    while (others[c2] >= 0) {\n      c2 = others[c2];\n      codesize[c2]++;\n    }\n  }\n\n  /* Now count the number of symbols of each code length */\n  for (i = 0; i <= 256; i++) {\n    if (codesize[i]) {\n      /* The JPEG standard seems to think that this can't happen, */\n      /* but I'm paranoid... */\n      if (codesize[i] > MAX_CLEN)\n\tERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);\n\n      bits[codesize[i]]++;\n    }\n  }\n\n  /* JPEG doesn't allow symbols with code lengths over 16 bits, so if the pure\n   * Huffman procedure assigned any such lengths, we must adjust the coding.\n   * Here is what the JPEG spec says about how this next bit works:\n   * Since symbols are paired for the longest Huffman code, the symbols are\n   * removed from this length category two at a time.  The prefix for the pair\n   * (which is one bit shorter) is allocated to one of the pair; then,\n   * skipping the BITS entry for that prefix length, a code word from the next\n   * shortest nonzero BITS entry is converted into a prefix for two code words\n   * one bit longer.\n   */\n  \n  for (i = MAX_CLEN; i > 16; i--) {\n    while (bits[i] > 0) {\n      j = i - 2;\t\t/* find length of new prefix to be used */\n      while (bits[j] == 0)\n\tj--;\n      \n      bits[i] -= 2;\t\t/* remove two symbols */\n      bits[i-1]++;\t\t/* one goes in this length */\n      bits[j+1] += 2;\t\t/* two new symbols in this length */\n      bits[j]--;\t\t/* symbol of this length is now a prefix */\n    }\n  }\n\n  /* Remove the count for the pseudo-symbol 256 from the largest codelength */\n  while (bits[i] == 0)\t\t/* find largest codelength still in use */\n    i--;\n  bits[i]--;\n  \n  /* Return final symbol counts (only for lengths 0..16) */\n  MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));\n  \n  /* Return a list of the symbols sorted by code length */\n  /* It's not real clear to me why we don't need to consider the codelength\n   * changes made above, but the JPEG spec seems to think this works.\n   */\n  p = 0;\n  for (i = 1; i <= MAX_CLEN; i++) {\n    for (j = 0; j <= 255; j++) {\n      if (codesize[j] == i) {\n\thtbl->huffval[p] = (UINT8) j;\n\tp++;\n      }\n    }\n  }\n\n  /* Set sent_table FALSE so updated table will be written to JPEG file. */\n  htbl->sent_table = FALSE;\n}\n\n\n/*\n * Finish up a statistics-gathering pass and create the new Huffman tables.\n */\n\nMETHODDEF(void)\nfinish_pass_gather (j_compress_ptr cinfo)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int ci, tbl;\n  jpeg_component_info * compptr;\n  JHUFF_TBL **htblptr;\n  boolean did_dc[NUM_HUFF_TBLS];\n  boolean did_ac[NUM_HUFF_TBLS];\n\n  /* It's important not to apply jpeg_gen_optimal_table more than once\n   * per table, because it clobbers the input frequency counts!\n   */\n  if (cinfo->progressive_mode)\n    /* Flush out buffered data (all we care about is counting the EOB symbol) */\n    emit_eobrun(entropy);\n\n  MEMZERO(did_dc, SIZEOF(did_dc));\n  MEMZERO(did_ac, SIZEOF(did_ac));\n\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    /* DC needs no table for refinement scan */\n    if (cinfo->Ss == 0 && cinfo->Ah == 0) {\n      tbl = compptr->dc_tbl_no;\n      if (! did_dc[tbl]) {\n\thtblptr = & cinfo->dc_huff_tbl_ptrs[tbl];\n\tif (*htblptr == NULL)\n\t  *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);\n\tjpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[tbl]);\n\tdid_dc[tbl] = TRUE;\n      }\n    }\n    /* AC needs no table when not present */\n    if (cinfo->Se) {\n      tbl = compptr->ac_tbl_no;\n      if (! did_ac[tbl]) {\n\thtblptr = & cinfo->ac_huff_tbl_ptrs[tbl];\n\tif (*htblptr == NULL)\n\t  *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);\n\tjpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[tbl]);\n\tdid_ac[tbl] = TRUE;\n      }\n    }\n  }\n}\n\n\n/*\n * Initialize for a Huffman-compressed scan.\n * If gather_statistics is TRUE, we do not output anything during the scan,\n * just count the Huffman symbols used and generate Huffman code tables.\n */\n\nMETHODDEF(void)\nstart_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int ci, tbl;\n  jpeg_component_info * compptr;\n\n  if (gather_statistics)\n    entropy->pub.finish_pass = finish_pass_gather;\n  else\n    entropy->pub.finish_pass = finish_pass_huff;\n\n  if (cinfo->progressive_mode) {\n    entropy->cinfo = cinfo;\n    entropy->gather_statistics = gather_statistics;\n\n    /* We assume jcmaster.c already validated the scan parameters. */\n\n    /* Select execution routine */\n    if (cinfo->Ah == 0) {\n      if (cinfo->Ss == 0)\n\tentropy->pub.encode_mcu = encode_mcu_DC_first;\n      else\n\tentropy->pub.encode_mcu = encode_mcu_AC_first;\n    } else {\n      if (cinfo->Ss == 0)\n\tentropy->pub.encode_mcu = encode_mcu_DC_refine;\n      else {\n\tentropy->pub.encode_mcu = encode_mcu_AC_refine;\n\t/* AC refinement needs a correction bit buffer */\n\tif (entropy->bit_buffer == NULL)\n\t  entropy->bit_buffer = (char *)\n\t    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t\tMAX_CORR_BITS * SIZEOF(char));\n      }\n    }\n\n    /* Initialize AC stuff */\n    entropy->ac_tbl_no = cinfo->cur_comp_info[0]->ac_tbl_no;\n    entropy->EOBRUN = 0;\n    entropy->BE = 0;\n  } else {\n    if (gather_statistics)\n      entropy->pub.encode_mcu = encode_mcu_gather;\n    else\n      entropy->pub.encode_mcu = encode_mcu_huff;\n  }\n\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    /* DC needs no table for refinement scan */\n    if (cinfo->Ss == 0 && cinfo->Ah == 0) {\n      tbl = compptr->dc_tbl_no;\n      if (gather_statistics) {\n\t/* Check for invalid table index */\n\t/* (make_c_derived_tbl does this in the other path) */\n\tif (tbl < 0 || tbl >= NUM_HUFF_TBLS)\n\t  ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);\n\t/* Allocate and zero the statistics tables */\n\t/* Note that jpeg_gen_optimal_table expects 257 entries in each table! */\n\tif (entropy->dc_count_ptrs[tbl] == NULL)\n\t  entropy->dc_count_ptrs[tbl] = (long *)\n\t    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t\t257 * SIZEOF(long));\n\tMEMZERO(entropy->dc_count_ptrs[tbl], 257 * SIZEOF(long));\n      } else {\n\t/* Compute derived values for Huffman tables */\n\t/* We may do this more than once for a table, but it's not expensive */\n\tjpeg_make_c_derived_tbl(cinfo, TRUE, tbl,\n\t\t\t\t& entropy->dc_derived_tbls[tbl]);\n      }\n      /* Initialize DC predictions to 0 */\n      entropy->saved.last_dc_val[ci] = 0;\n    }\n    /* AC needs no table when not present */\n    if (cinfo->Se) {\n      tbl = compptr->ac_tbl_no;\n      if (gather_statistics) {\n\tif (tbl < 0 || tbl >= NUM_HUFF_TBLS)\n\t  ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);\n\tif (entropy->ac_count_ptrs[tbl] == NULL)\n\t  entropy->ac_count_ptrs[tbl] = (long *)\n\t    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t\t257 * SIZEOF(long));\n\tMEMZERO(entropy->ac_count_ptrs[tbl], 257 * SIZEOF(long));\n      } else {\n\tjpeg_make_c_derived_tbl(cinfo, FALSE, tbl,\n\t\t\t\t& entropy->ac_derived_tbls[tbl]);\n      }\n    }\n  }\n\n  /* Initialize bit buffer to empty */\n  entropy->saved.put_buffer = 0;\n  entropy->saved.put_bits = 0;\n\n  /* Initialize restart stuff */\n  entropy->restarts_to_go = cinfo->restart_interval;\n  entropy->next_restart_num = 0;\n}\n\n\n/*\n * Module initialization routine for Huffman entropy encoding.\n */\n\nGLOBAL(void)\njinit_huff_encoder (j_compress_ptr cinfo)\n{\n  huff_entropy_ptr entropy;\n  int i;\n\n  entropy = (huff_entropy_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(huff_entropy_encoder));\n  cinfo->entropy = &entropy->pub;\n  entropy->pub.start_pass = start_pass_huff;\n\n  /* Mark tables unallocated */\n  for (i = 0; i < NUM_HUFF_TBLS; i++) {\n    entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;\n    entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;\n  }\n\n  if (cinfo->progressive_mode)\n    entropy->bit_buffer = NULL;\t/* needed only in AC refinement scan */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcinit.c",
    "content": "/*\n * jcinit.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains initialization logic for the JPEG compressor.\n * This routine is in charge of selecting the modules to be executed and\n * making an initialization call to each one.\n *\n * Logically, this code belongs in jcmaster.c.  It's split out because\n * linking this routine implies linking the entire compression library.\n * For a transcoding-only application, we want to be able to use jcmaster.c\n * without linking in the whole library.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Master selection of compression modules.\n * This is done once at the start of processing an image.  We determine\n * which modules will be used and give them appropriate initialization calls.\n */\n\nGLOBAL(void)\njinit_compress_master (j_compress_ptr cinfo)\n{\n  long samplesperrow;\n  JDIMENSION jd_samplesperrow;\n\n  /* For now, precision must match compiled-in value... */\n  if (cinfo->data_precision != BITS_IN_JSAMPLE)\n    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);\n\n  /* Sanity check on image dimensions */\n  if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||\n      cinfo->input_components <= 0)\n    ERREXIT(cinfo, JERR_EMPTY_IMAGE);\n\n  /* Width of an input scanline must be representable as JDIMENSION. */\n  samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;\n  jd_samplesperrow = (JDIMENSION) samplesperrow;\n  if ((long) jd_samplesperrow != samplesperrow)\n    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);\n\n  /* Initialize master control (includes parameter checking/processing) */\n  jinit_c_master_control(cinfo, FALSE /* full compression */);\n\n  /* Preprocessing */\n  if (! cinfo->raw_data_in) {\n    jinit_color_converter(cinfo);\n    jinit_downsampler(cinfo);\n    jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);\n  }\n  /* Forward DCT */\n  jinit_forward_dct(cinfo);\n  /* Entropy encoding: either Huffman or arithmetic coding. */\n  if (cinfo->arith_code)\n    jinit_arith_encoder(cinfo);\n  else {\n    jinit_huff_encoder(cinfo);\n  }\n\n  /* Need a full-image coefficient buffer in any multi-pass mode. */\n  jinit_c_coef_controller(cinfo,\n\t\t(boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));\n  jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);\n\n  jinit_marker_writer(cinfo);\n\n  /* We can now tell the memory manager to allocate virtual arrays. */\n  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);\n\n  /* Write the datastream header (SOI) immediately.\n   * Frame and scan headers are postponed till later.\n   * This lets application insert special markers after the SOI.\n   */\n  (*cinfo->marker->write_file_header) (cinfo);\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcmainct.c",
    "content": "/*\n * jcmainct.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2003-2012 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the main buffer controller for compression.\n * The main buffer lies between the pre-processor and the JPEG\n * compressor proper; it holds downsampled data in the JPEG colorspace.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Note: currently, there is no operating mode in which a full-image buffer\n * is needed at this step.  If there were, that mode could not be used with\n * \"raw data\" input, since this module is bypassed in that case.  However,\n * we've left the code here for possible use in special applications.\n */\n#undef FULL_MAIN_BUFFER_SUPPORTED\n\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_c_main_controller pub; /* public fields */\n\n  JDIMENSION cur_iMCU_row;\t/* number of current iMCU row */\n  JDIMENSION rowgroup_ctr;\t/* counts row groups received in iMCU row */\n  boolean suspended;\t\t/* remember if we suspended output */\n  J_BUF_MODE pass_mode;\t\t/* current operating mode */\n\n  /* If using just a strip buffer, this points to the entire set of buffers\n   * (we allocate one for each component).  In the full-image case, this\n   * points to the currently accessible strips of the virtual arrays.\n   */\n  JSAMPARRAY buffer[MAX_COMPONENTS];\n\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n  /* If using full-image storage, this array holds pointers to virtual-array\n   * control blocks for each component.  Unused if not full-image storage.\n   */\n  jvirt_sarray_ptr whole_image[MAX_COMPONENTS];\n#endif\n} my_main_controller;\n\ntypedef my_main_controller * my_main_ptr;\n\n\n/* Forward declarations */\nMETHODDEF(void) process_data_simple_main\n\tJPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,\n\t     JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\nMETHODDEF(void) process_data_buffer_main\n\tJPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,\n\t     JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));\n#endif\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n\n  /* Do nothing in raw-data mode. */\n  if (cinfo->raw_data_in)\n    return;\n\n  mainp->cur_iMCU_row = 0;\t/* initialize counters */\n  mainp->rowgroup_ctr = 0;\n  mainp->suspended = FALSE;\n  mainp->pass_mode = pass_mode;\t/* save mode for use by process_data */\n\n  switch (pass_mode) {\n  case JBUF_PASS_THRU:\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n    if (mainp->whole_image[0] != NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n#endif\n    mainp->pub.process_data = process_data_simple_main;\n    break;\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n  case JBUF_SAVE_SOURCE:\n  case JBUF_CRANK_DEST:\n  case JBUF_SAVE_AND_PASS:\n    if (mainp->whole_image[0] == NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    mainp->pub.process_data = process_data_buffer_main;\n    break;\n#endif\n  default:\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    break;\n  }\n}\n\n\n/*\n * Process some data.\n * This routine handles the simple pass-through mode,\n * where we have only a strip buffer.\n */\n\nMETHODDEF(void)\nprocess_data_simple_main (j_compress_ptr cinfo,\n\t\t\t  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,\n\t\t\t  JDIMENSION in_rows_avail)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n\n  while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {\n    /* Read input data if we haven't filled the main buffer yet */\n    if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)\n      (*cinfo->prep->pre_process_data) (cinfo,\n\t\t\t\t\tinput_buf, in_row_ctr, in_rows_avail,\n\t\t\t\t\tmainp->buffer, &mainp->rowgroup_ctr,\n\t\t\t\t\t(JDIMENSION) cinfo->min_DCT_v_scaled_size);\n\n    /* If we don't have a full iMCU row buffered, return to application for\n     * more data.  Note that preprocessor will always pad to fill the iMCU row\n     * at the bottom of the image.\n     */\n    if (mainp->rowgroup_ctr != (JDIMENSION) cinfo->min_DCT_v_scaled_size)\n      return;\n\n    /* Send the completed row to the compressor */\n    if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {\n      /* If compressor did not consume the whole row, then we must need to\n       * suspend processing and return to the application.  In this situation\n       * we pretend we didn't yet consume the last input row; otherwise, if\n       * it happened to be the last row of the image, the application would\n       * think we were done.\n       */\n      if (! mainp->suspended) {\n\t(*in_row_ctr)--;\n\tmainp->suspended = TRUE;\n      }\n      return;\n    }\n    /* We did finish the row.  Undo our little suspension hack if a previous\n     * call suspended; then mark the main buffer empty.\n     */\n    if (mainp->suspended) {\n      (*in_row_ctr)++;\n      mainp->suspended = FALSE;\n    }\n    mainp->rowgroup_ctr = 0;\n    mainp->cur_iMCU_row++;\n  }\n}\n\n\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n\n/*\n * Process some data.\n * This routine handles all of the modes that use a full-size buffer.\n */\n\nMETHODDEF(void)\nprocess_data_buffer_main (j_compress_ptr cinfo,\n\t\t\t  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,\n\t\t\t  JDIMENSION in_rows_avail)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  int ci;\n  jpeg_component_info *compptr;\n  boolean writing = (mainp->pass_mode != JBUF_CRANK_DEST);\n\n  while (mainp->cur_iMCU_row < cinfo->total_iMCU_rows) {\n    /* Realign the virtual buffers if at the start of an iMCU row. */\n    if (mainp->rowgroup_ctr == 0) {\n      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t   ci++, compptr++) {\n\tmainp->buffer[ci] = (*cinfo->mem->access_virt_sarray)\n\t  ((j_common_ptr) cinfo, mainp->whole_image[ci], mainp->cur_iMCU_row *\n\t   ((JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size)),\n\t   (JDIMENSION) (compptr->v_samp_factor * cinfo->min_DCT_v_scaled_size),\n\t   writing);\n      }\n      /* In a read pass, pretend we just read some source data. */\n      if (! writing) {\n\t*in_row_ctr += (JDIMENSION)\n\t  (cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size);\n\tmainp->rowgroup_ctr = (JDIMENSION) cinfo->min_DCT_v_scaled_size;\n      }\n    }\n\n    /* If a write pass, read input data until the current iMCU row is full. */\n    /* Note: preprocessor will pad if necessary to fill the last iMCU row. */\n    if (writing) {\n      (*cinfo->prep->pre_process_data) (cinfo,\n\t\t\t\t\tinput_buf, in_row_ctr, in_rows_avail,\n\t\t\t\t\tmainp->buffer, &mainp->rowgroup_ctr,\n\t\t\t\t\t(JDIMENSION) cinfo->min_DCT_v_scaled_size);\n      /* Return to application if we need more data to fill the iMCU row. */\n      if (mainp->rowgroup_ctr < (JDIMENSION) cinfo->min_DCT_v_scaled_size)\n\treturn;\n    }\n\n    /* Emit data, unless this is a sink-only pass. */\n    if (mainp->pass_mode != JBUF_SAVE_SOURCE) {\n      if (! (*cinfo->coef->compress_data) (cinfo, mainp->buffer)) {\n\t/* If compressor did not consume the whole row, then we must need to\n\t * suspend processing and return to the application.  In this situation\n\t * we pretend we didn't yet consume the last input row; otherwise, if\n\t * it happened to be the last row of the image, the application would\n\t * think we were done.\n\t */\n\tif (! mainp->suspended) {\n\t  (*in_row_ctr)--;\n\t  mainp->suspended = TRUE;\n\t}\n\treturn;\n      }\n      /* We did finish the row.  Undo our little suspension hack if a previous\n       * call suspended; then mark the main buffer empty.\n       */\n      if (mainp->suspended) {\n\t(*in_row_ctr)++;\n\tmainp->suspended = FALSE;\n      }\n    }\n\n    /* If get here, we are done with this iMCU row.  Mark buffer empty. */\n    mainp->rowgroup_ctr = 0;\n    mainp->cur_iMCU_row++;\n  }\n}\n\n#endif /* FULL_MAIN_BUFFER_SUPPORTED */\n\n\n/*\n * Initialize main buffer controller.\n */\n\nGLOBAL(void)\njinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)\n{\n  my_main_ptr mainp;\n  int ci;\n  jpeg_component_info *compptr;\n\n  mainp = (my_main_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_main_controller));\n  cinfo->main = &mainp->pub;\n  mainp->pub.start_pass = start_pass_main;\n\n  /* We don't need to create a buffer in raw-data mode. */\n  if (cinfo->raw_data_in)\n    return;\n\n  /* Create the buffer.  It holds downsampled data, so each component\n   * may be of a different size.\n   */\n  if (need_full_buffer) {\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n    /* Allocate a full-image virtual array for each component */\n    /* Note we pad the bottom to a multiple of the iMCU height */\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      mainp->whole_image[ci] = (*cinfo->mem->request_virt_sarray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n\t compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),\n\t ((JDIMENSION) jround_up((long) compptr->height_in_blocks,\n\t\t\t\t (long) compptr->v_samp_factor)) *\n\t ((JDIMENSION) cinfo->min_DCT_v_scaled_size),\n\t (JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));\n    }\n#else\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n#endif\n  } else {\n#ifdef FULL_MAIN_BUFFER_SUPPORTED\n    mainp->whole_image[0] = NULL; /* flag for no virtual arrays */\n#endif\n    /* Allocate a strip buffer for each component */\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),\n\t (JDIMENSION) (compptr->v_samp_factor * compptr->DCT_v_scaled_size));\n    }\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcmarker.c",
    "content": "/*\n * jcmarker.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write JPEG datastream markers.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\ntypedef enum {\t\t\t/* JPEG marker codes */\n  M_SOF0  = 0xc0,\n  M_SOF1  = 0xc1,\n  M_SOF2  = 0xc2,\n  M_SOF3  = 0xc3,\n\n  M_SOF5  = 0xc5,\n  M_SOF6  = 0xc6,\n  M_SOF7  = 0xc7,\n\n  M_JPG   = 0xc8,\n  M_SOF9  = 0xc9,\n  M_SOF10 = 0xca,\n  M_SOF11 = 0xcb,\n\n  M_SOF13 = 0xcd,\n  M_SOF14 = 0xce,\n  M_SOF15 = 0xcf,\n\n  M_DHT   = 0xc4,\n\n  M_DAC   = 0xcc,\n\n  M_RST0  = 0xd0,\n  M_RST1  = 0xd1,\n  M_RST2  = 0xd2,\n  M_RST3  = 0xd3,\n  M_RST4  = 0xd4,\n  M_RST5  = 0xd5,\n  M_RST6  = 0xd6,\n  M_RST7  = 0xd7,\n\n  M_SOI   = 0xd8,\n  M_EOI   = 0xd9,\n  M_SOS   = 0xda,\n  M_DQT   = 0xdb,\n  M_DNL   = 0xdc,\n  M_DRI   = 0xdd,\n  M_DHP   = 0xde,\n  M_EXP   = 0xdf,\n\n  M_APP0  = 0xe0,\n  M_APP1  = 0xe1,\n  M_APP2  = 0xe2,\n  M_APP3  = 0xe3,\n  M_APP4  = 0xe4,\n  M_APP5  = 0xe5,\n  M_APP6  = 0xe6,\n  M_APP7  = 0xe7,\n  M_APP8  = 0xe8,\n  M_APP9  = 0xe9,\n  M_APP10 = 0xea,\n  M_APP11 = 0xeb,\n  M_APP12 = 0xec,\n  M_APP13 = 0xed,\n  M_APP14 = 0xee,\n  M_APP15 = 0xef,\n\n  M_JPG0  = 0xf0,\n  M_JPG8  = 0xf8,\n  M_JPG13 = 0xfd,\n  M_COM   = 0xfe,\n\n  M_TEM   = 0x01,\n\n  M_ERROR = 0x100\n} JPEG_MARKER;\n\n\n/* Private state */\n\ntypedef struct {\n  struct jpeg_marker_writer pub; /* public fields */\n\n  unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */\n} my_marker_writer;\n\ntypedef my_marker_writer * my_marker_ptr;\n\n\n/*\n * Basic output routines.\n *\n * Note that we do not support suspension while writing a marker.\n * Therefore, an application using suspension must ensure that there is\n * enough buffer space for the initial markers (typ. 600-700 bytes) before\n * calling jpeg_start_compress, and enough space to write the trailing EOI\n * (a few bytes) before calling jpeg_finish_compress.  Multipass compression\n * modes are not supported at all with suspension, so those two are the only\n * points where markers will be written.\n */\n\nLOCAL(void)\nemit_byte (j_compress_ptr cinfo, int val)\n/* Emit a byte */\n{\n  struct jpeg_destination_mgr * dest = cinfo->dest;\n\n  *(dest->next_output_byte)++ = (JOCTET) val;\n  if (--dest->free_in_buffer == 0) {\n    if (! (*dest->empty_output_buffer) (cinfo))\n      ERREXIT(cinfo, JERR_CANT_SUSPEND);\n  }\n}\n\n\nLOCAL(void)\nemit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)\n/* Emit a marker code */\n{\n  emit_byte(cinfo, 0xFF);\n  emit_byte(cinfo, (int) mark);\n}\n\n\nLOCAL(void)\nemit_2bytes (j_compress_ptr cinfo, int value)\n/* Emit a 2-byte integer; these are always MSB first in JPEG files */\n{\n  emit_byte(cinfo, (value >> 8) & 0xFF);\n  emit_byte(cinfo, value & 0xFF);\n}\n\n\n/*\n * Routines to write specific marker types.\n */\n\nLOCAL(int)\nemit_dqt (j_compress_ptr cinfo, int index)\n/* Emit a DQT marker */\n/* Returns the precision used (0 = 8bits, 1 = 16bits) for baseline checking */\n{\n  JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];\n  int prec;\n  int i;\n\n  if (qtbl == NULL)\n    ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);\n\n  prec = 0;\n  for (i = 0; i <= cinfo->lim_Se; i++) {\n    if (qtbl->quantval[cinfo->natural_order[i]] > 255)\n      prec = 1;\n  }\n\n  if (! qtbl->sent_table) {\n    emit_marker(cinfo, M_DQT);\n\n    emit_2bytes(cinfo,\n      prec ? cinfo->lim_Se * 2 + 2 + 1 + 2 : cinfo->lim_Se + 1 + 1 + 2);\n\n    emit_byte(cinfo, index + (prec<<4));\n\n    for (i = 0; i <= cinfo->lim_Se; i++) {\n      /* The table entries must be emitted in zigzag order. */\n      unsigned int qval = qtbl->quantval[cinfo->natural_order[i]];\n      if (prec)\n\temit_byte(cinfo, (int) (qval >> 8));\n      emit_byte(cinfo, (int) (qval & 0xFF));\n    }\n\n    qtbl->sent_table = TRUE;\n  }\n\n  return prec;\n}\n\n\nLOCAL(void)\nemit_dht (j_compress_ptr cinfo, int index, boolean is_ac)\n/* Emit a DHT marker */\n{\n  JHUFF_TBL * htbl;\n  int length, i;\n  \n  if (is_ac) {\n    htbl = cinfo->ac_huff_tbl_ptrs[index];\n    index += 0x10;\t\t/* output index has AC bit set */\n  } else {\n    htbl = cinfo->dc_huff_tbl_ptrs[index];\n  }\n\n  if (htbl == NULL)\n    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);\n  \n  if (! htbl->sent_table) {\n    emit_marker(cinfo, M_DHT);\n    \n    length = 0;\n    for (i = 1; i <= 16; i++)\n      length += htbl->bits[i];\n    \n    emit_2bytes(cinfo, length + 2 + 1 + 16);\n    emit_byte(cinfo, index);\n    \n    for (i = 1; i <= 16; i++)\n      emit_byte(cinfo, htbl->bits[i]);\n    \n    for (i = 0; i < length; i++)\n      emit_byte(cinfo, htbl->huffval[i]);\n    \n    htbl->sent_table = TRUE;\n  }\n}\n\n\nLOCAL(void)\nemit_dac (j_compress_ptr cinfo)\n/* Emit a DAC marker */\n/* Since the useful info is so small, we want to emit all the tables in */\n/* one DAC marker.  Therefore this routine does its own scan of the table. */\n{\n#ifdef C_ARITH_CODING_SUPPORTED\n  char dc_in_use[NUM_ARITH_TBLS];\n  char ac_in_use[NUM_ARITH_TBLS];\n  int length, i;\n  jpeg_component_info *compptr;\n\n  for (i = 0; i < NUM_ARITH_TBLS; i++)\n    dc_in_use[i] = ac_in_use[i] = 0;\n\n  for (i = 0; i < cinfo->comps_in_scan; i++) {\n    compptr = cinfo->cur_comp_info[i];\n    /* DC needs no table for refinement scan */\n    if (cinfo->Ss == 0 && cinfo->Ah == 0)\n      dc_in_use[compptr->dc_tbl_no] = 1;\n    /* AC needs no table when not present */\n    if (cinfo->Se)\n      ac_in_use[compptr->ac_tbl_no] = 1;\n  }\n\n  length = 0;\n  for (i = 0; i < NUM_ARITH_TBLS; i++)\n    length += dc_in_use[i] + ac_in_use[i];\n\n  if (length) {\n    emit_marker(cinfo, M_DAC);\n\n    emit_2bytes(cinfo, length*2 + 2);\n\n    for (i = 0; i < NUM_ARITH_TBLS; i++) {\n      if (dc_in_use[i]) {\n\temit_byte(cinfo, i);\n\temit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));\n      }\n      if (ac_in_use[i]) {\n\temit_byte(cinfo, i + 0x10);\n\temit_byte(cinfo, cinfo->arith_ac_K[i]);\n      }\n    }\n  }\n#endif /* C_ARITH_CODING_SUPPORTED */\n}\n\n\nLOCAL(void)\nemit_dri (j_compress_ptr cinfo)\n/* Emit a DRI marker */\n{\n  emit_marker(cinfo, M_DRI);\n  \n  emit_2bytes(cinfo, 4);\t/* fixed length */\n\n  emit_2bytes(cinfo, (int) cinfo->restart_interval);\n}\n\n\nLOCAL(void)\nemit_lse_ict (j_compress_ptr cinfo)\n/* Emit an LSE inverse color transform specification marker */\n{\n  /* Support only 1 transform */\n  if (cinfo->color_transform != JCT_SUBTRACT_GREEN ||\n      cinfo->num_components < 3)\n    ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n\n  emit_marker(cinfo, M_JPG8);\n  \n  emit_2bytes(cinfo, 24);\t/* fixed length */\n\n  emit_byte(cinfo, 0x0D);\t/* ID inverse transform specification */\n  emit_2bytes(cinfo, MAXJSAMPLE);\t/* MAXTRANS */\n  emit_byte(cinfo, 3);\t\t/* Nt=3 */\n  emit_byte(cinfo, cinfo->comp_info[1].component_id);\n  emit_byte(cinfo, cinfo->comp_info[0].component_id);\n  emit_byte(cinfo, cinfo->comp_info[2].component_id);\n  emit_byte(cinfo, 0x80);\t/* F1: CENTER1=1, NORM1=0 */\n  emit_2bytes(cinfo, 0);\t/* A(1,1)=0 */\n  emit_2bytes(cinfo, 0);\t/* A(1,2)=0 */\n  emit_byte(cinfo, 0);\t\t/* F2: CENTER2=0, NORM2=0 */\n  emit_2bytes(cinfo, 1);\t/* A(2,1)=1 */\n  emit_2bytes(cinfo, 0);\t/* A(2,2)=0 */\n  emit_byte(cinfo, 0);\t\t/* F3: CENTER3=0, NORM3=0 */\n  emit_2bytes(cinfo, 1);\t/* A(3,1)=1 */\n  emit_2bytes(cinfo, 0);\t/* A(3,2)=0 */\n}\n\n\nLOCAL(void)\nemit_sof (j_compress_ptr cinfo, JPEG_MARKER code)\n/* Emit a SOF marker */\n{\n  int ci;\n  jpeg_component_info *compptr;\n  \n  emit_marker(cinfo, code);\n  \n  emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */\n\n  /* Make sure image isn't bigger than SOF field can handle */\n  if ((long) cinfo->jpeg_height > 65535L ||\n      (long) cinfo->jpeg_width > 65535L)\n    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);\n\n  emit_byte(cinfo, cinfo->data_precision);\n  emit_2bytes(cinfo, (int) cinfo->jpeg_height);\n  emit_2bytes(cinfo, (int) cinfo->jpeg_width);\n\n  emit_byte(cinfo, cinfo->num_components);\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    emit_byte(cinfo, compptr->component_id);\n    emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);\n    emit_byte(cinfo, compptr->quant_tbl_no);\n  }\n}\n\n\nLOCAL(void)\nemit_sos (j_compress_ptr cinfo)\n/* Emit a SOS marker */\n{\n  int i, td, ta;\n  jpeg_component_info *compptr;\n  \n  emit_marker(cinfo, M_SOS);\n  \n  emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */\n  \n  emit_byte(cinfo, cinfo->comps_in_scan);\n  \n  for (i = 0; i < cinfo->comps_in_scan; i++) {\n    compptr = cinfo->cur_comp_info[i];\n    emit_byte(cinfo, compptr->component_id);\n\n    /* We emit 0 for unused field(s); this is recommended by the P&M text\n     * but does not seem to be specified in the standard.\n     */\n\n    /* DC needs no table for refinement scan */\n    td = cinfo->Ss == 0 && cinfo->Ah == 0 ? compptr->dc_tbl_no : 0;\n    /* AC needs no table when not present */\n    ta = cinfo->Se ? compptr->ac_tbl_no : 0;\n\n    emit_byte(cinfo, (td << 4) + ta);\n  }\n\n  emit_byte(cinfo, cinfo->Ss);\n  emit_byte(cinfo, cinfo->Se);\n  emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);\n}\n\n\nLOCAL(void)\nemit_pseudo_sos (j_compress_ptr cinfo)\n/* Emit a pseudo SOS marker */\n{\n  emit_marker(cinfo, M_SOS);\n  \n  emit_2bytes(cinfo, 2 + 1 + 3); /* length */\n  \n  emit_byte(cinfo, 0); /* Ns */\n\n  emit_byte(cinfo, 0); /* Ss */\n  emit_byte(cinfo, cinfo->block_size * cinfo->block_size - 1); /* Se */\n  emit_byte(cinfo, 0); /* Ah/Al */\n}\n\n\nLOCAL(void)\nemit_jfif_app0 (j_compress_ptr cinfo)\n/* Emit a JFIF-compliant APP0 marker */\n{\n  /*\n   * Length of APP0 block\t(2 bytes)\n   * Block ID\t\t\t(4 bytes - ASCII \"JFIF\")\n   * Zero byte\t\t\t(1 byte to terminate the ID string)\n   * Version Major, Minor\t(2 bytes - major first)\n   * Units\t\t\t(1 byte - 0x00 = none, 0x01 = inch, 0x02 = cm)\n   * Xdpu\t\t\t(2 bytes - dots per unit horizontal)\n   * Ydpu\t\t\t(2 bytes - dots per unit vertical)\n   * Thumbnail X size\t\t(1 byte)\n   * Thumbnail Y size\t\t(1 byte)\n   */\n  \n  emit_marker(cinfo, M_APP0);\n  \n  emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */\n\n  emit_byte(cinfo, 0x4A);\t/* Identifier: ASCII \"JFIF\" */\n  emit_byte(cinfo, 0x46);\n  emit_byte(cinfo, 0x49);\n  emit_byte(cinfo, 0x46);\n  emit_byte(cinfo, 0);\n  emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */\n  emit_byte(cinfo, cinfo->JFIF_minor_version);\n  emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */\n  emit_2bytes(cinfo, (int) cinfo->X_density);\n  emit_2bytes(cinfo, (int) cinfo->Y_density);\n  emit_byte(cinfo, 0);\t\t/* No thumbnail image */\n  emit_byte(cinfo, 0);\n}\n\n\nLOCAL(void)\nemit_adobe_app14 (j_compress_ptr cinfo)\n/* Emit an Adobe APP14 marker */\n{\n  /*\n   * Length of APP14 block\t(2 bytes)\n   * Block ID\t\t\t(5 bytes - ASCII \"Adobe\")\n   * Version Number\t\t(2 bytes - currently 100)\n   * Flags0\t\t\t(2 bytes - currently 0)\n   * Flags1\t\t\t(2 bytes - currently 0)\n   * Color transform\t\t(1 byte)\n   *\n   * Although Adobe TN 5116 mentions Version = 101, all the Adobe files\n   * now in circulation seem to use Version = 100, so that's what we write.\n   *\n   * We write the color transform byte as 1 if the JPEG color space is\n   * YCbCr, 2 if it's YCCK, 0 otherwise.  Adobe's definition has to do with\n   * whether the encoder performed a transformation, which is pretty useless.\n   */\n  \n  emit_marker(cinfo, M_APP14);\n  \n  emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */\n\n  emit_byte(cinfo, 0x41);\t/* Identifier: ASCII \"Adobe\" */\n  emit_byte(cinfo, 0x64);\n  emit_byte(cinfo, 0x6F);\n  emit_byte(cinfo, 0x62);\n  emit_byte(cinfo, 0x65);\n  emit_2bytes(cinfo, 100);\t/* Version */\n  emit_2bytes(cinfo, 0);\t/* Flags0 */\n  emit_2bytes(cinfo, 0);\t/* Flags1 */\n  switch (cinfo->jpeg_color_space) {\n  case JCS_YCbCr:\n    emit_byte(cinfo, 1);\t/* Color transform = 1 */\n    break;\n  case JCS_YCCK:\n    emit_byte(cinfo, 2);\t/* Color transform = 2 */\n    break;\n  default:\n    emit_byte(cinfo, 0);\t/* Color transform = 0 */\n    break;\n  }\n}\n\n\n/*\n * These routines allow writing an arbitrary marker with parameters.\n * The only intended use is to emit COM or APPn markers after calling\n * write_file_header and before calling write_frame_header.\n * Other uses are not guaranteed to produce desirable results.\n * Counting the parameter bytes properly is the caller's responsibility.\n */\n\nMETHODDEF(void)\nwrite_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)\n/* Emit an arbitrary marker header */\n{\n  if (datalen > (unsigned int) 65533)\t\t/* safety check */\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  emit_marker(cinfo, (JPEG_MARKER) marker);\n\n  emit_2bytes(cinfo, (int) (datalen + 2));\t/* total length */\n}\n\nMETHODDEF(void)\nwrite_marker_byte (j_compress_ptr cinfo, int val)\n/* Emit one byte of marker parameters following write_marker_header */\n{\n  emit_byte(cinfo, val);\n}\n\n\n/*\n * Write datastream header.\n * This consists of an SOI and optional APPn markers.\n * We recommend use of the JFIF marker, but not the Adobe marker,\n * when using YCbCr or grayscale data.  The JFIF marker is also used\n * for other standard JPEG colorspaces.  The Adobe marker is helpful\n * to distinguish RGB, CMYK, and YCCK colorspaces.\n * Note that an application can write additional header markers after\n * jpeg_start_compress returns.\n */\n\nMETHODDEF(void)\nwrite_file_header (j_compress_ptr cinfo)\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n\n  emit_marker(cinfo, M_SOI);\t/* first the SOI */\n\n  /* SOI is defined to reset restart interval to 0 */\n  marker->last_restart_interval = 0;\n\n  if (cinfo->write_JFIF_header)\t/* next an optional JFIF APP0 */\n    emit_jfif_app0(cinfo);\n  if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */\n    emit_adobe_app14(cinfo);\n}\n\n\n/*\n * Write frame header.\n * This consists of DQT and SOFn markers,\n * a conditional LSE marker and a conditional pseudo SOS marker.\n * Note that we do not emit the SOF until we have emitted the DQT(s).\n * This avoids compatibility problems with incorrect implementations that\n * try to error-check the quant table numbers as soon as they see the SOF.\n */\n\nMETHODDEF(void)\nwrite_frame_header (j_compress_ptr cinfo)\n{\n  int ci, prec;\n  boolean is_baseline;\n  jpeg_component_info *compptr;\n  \n  /* Emit DQT for each quantization table.\n   * Note that emit_dqt() suppresses any duplicate tables.\n   */\n  prec = 0;\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    prec += emit_dqt(cinfo, compptr->quant_tbl_no);\n  }\n  /* now prec is nonzero iff there are any 16-bit quant tables. */\n\n  /* Check for a non-baseline specification.\n   * Note we assume that Huffman table numbers won't be changed later.\n   */\n  if (cinfo->arith_code || cinfo->progressive_mode ||\n      cinfo->data_precision != 8 || cinfo->block_size != DCTSIZE) {\n    is_baseline = FALSE;\n  } else {\n    is_baseline = TRUE;\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)\n\tis_baseline = FALSE;\n    }\n    if (prec && is_baseline) {\n      is_baseline = FALSE;\n      /* If it's baseline except for quantizer size, warn the user */\n      TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);\n    }\n  }\n\n  /* Emit the proper SOF marker */\n  if (cinfo->arith_code) {\n    if (cinfo->progressive_mode)\n      emit_sof(cinfo, M_SOF10); /* SOF code for progressive arithmetic */\n    else\n      emit_sof(cinfo, M_SOF9);  /* SOF code for sequential arithmetic */\n  } else {\n    if (cinfo->progressive_mode)\n      emit_sof(cinfo, M_SOF2);\t/* SOF code for progressive Huffman */\n    else if (is_baseline)\n      emit_sof(cinfo, M_SOF0);\t/* SOF code for baseline implementation */\n    else\n      emit_sof(cinfo, M_SOF1);\t/* SOF code for non-baseline Huffman file */\n  }\n\n  /* Check to emit LSE inverse color transform specification marker */\n  if (cinfo->color_transform)\n    emit_lse_ict(cinfo);\n\n  /* Check to emit pseudo SOS marker */\n  if (cinfo->progressive_mode && cinfo->block_size != DCTSIZE)\n    emit_pseudo_sos(cinfo);\n}\n\n\n/*\n * Write scan header.\n * This consists of DHT or DAC markers, optional DRI, and SOS.\n * Compressed data will be written following the SOS.\n */\n\nMETHODDEF(void)\nwrite_scan_header (j_compress_ptr cinfo)\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n  int i;\n  jpeg_component_info *compptr;\n\n  if (cinfo->arith_code) {\n    /* Emit arith conditioning info.  We may have some duplication\n     * if the file has multiple scans, but it's so small it's hardly\n     * worth worrying about.\n     */\n    emit_dac(cinfo);\n  } else {\n    /* Emit Huffman tables.\n     * Note that emit_dht() suppresses any duplicate tables.\n     */\n    for (i = 0; i < cinfo->comps_in_scan; i++) {\n      compptr = cinfo->cur_comp_info[i];\n      /* DC needs no table for refinement scan */\n      if (cinfo->Ss == 0 && cinfo->Ah == 0)\n\temit_dht(cinfo, compptr->dc_tbl_no, FALSE);\n      /* AC needs no table when not present */\n      if (cinfo->Se)\n\temit_dht(cinfo, compptr->ac_tbl_no, TRUE);\n    }\n  }\n\n  /* Emit DRI if required --- note that DRI value could change for each scan.\n   * We avoid wasting space with unnecessary DRIs, however.\n   */\n  if (cinfo->restart_interval != marker->last_restart_interval) {\n    emit_dri(cinfo);\n    marker->last_restart_interval = cinfo->restart_interval;\n  }\n\n  emit_sos(cinfo);\n}\n\n\n/*\n * Write datastream trailer.\n */\n\nMETHODDEF(void)\nwrite_file_trailer (j_compress_ptr cinfo)\n{\n  emit_marker(cinfo, M_EOI);\n}\n\n\n/*\n * Write an abbreviated table-specification datastream.\n * This consists of SOI, DQT and DHT tables, and EOI.\n * Any table that is defined and not marked sent_table = TRUE will be\n * emitted.  Note that all tables will be marked sent_table = TRUE at exit.\n */\n\nMETHODDEF(void)\nwrite_tables_only (j_compress_ptr cinfo)\n{\n  int i;\n\n  emit_marker(cinfo, M_SOI);\n\n  for (i = 0; i < NUM_QUANT_TBLS; i++) {\n    if (cinfo->quant_tbl_ptrs[i] != NULL)\n      (void) emit_dqt(cinfo, i);\n  }\n\n  if (! cinfo->arith_code) {\n    for (i = 0; i < NUM_HUFF_TBLS; i++) {\n      if (cinfo->dc_huff_tbl_ptrs[i] != NULL)\n\temit_dht(cinfo, i, FALSE);\n      if (cinfo->ac_huff_tbl_ptrs[i] != NULL)\n\temit_dht(cinfo, i, TRUE);\n    }\n  }\n\n  emit_marker(cinfo, M_EOI);\n}\n\n\n/*\n * Initialize the marker writer module.\n */\n\nGLOBAL(void)\njinit_marker_writer (j_compress_ptr cinfo)\n{\n  my_marker_ptr marker;\n\n  /* Create the subobject */\n  marker = (my_marker_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_marker_writer));\n  cinfo->marker = &marker->pub;\n  /* Initialize method pointers */\n  marker->pub.write_file_header = write_file_header;\n  marker->pub.write_frame_header = write_frame_header;\n  marker->pub.write_scan_header = write_scan_header;\n  marker->pub.write_file_trailer = write_file_trailer;\n  marker->pub.write_tables_only = write_tables_only;\n  marker->pub.write_marker_header = write_marker_header;\n  marker->pub.write_marker_byte = write_marker_byte;\n  /* Initialize private state */\n  marker->last_restart_interval = 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcmaster.c",
    "content": "/*\n * jcmaster.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains master control logic for the JPEG compressor.\n * These routines are concerned with parameter validation, initial setup,\n * and inter-pass control (determining the number of passes and the work \n * to be done in each pass).\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private state */\n\ntypedef enum {\n\tmain_pass,\t\t/* input data, also do first output step */\n\thuff_opt_pass,\t\t/* Huffman code optimization pass */\n\toutput_pass\t\t/* data output pass */\n} c_pass_type;\n\ntypedef struct {\n  struct jpeg_comp_master pub;\t/* public fields */\n\n  c_pass_type pass_type;\t/* the type of the current pass */\n\n  int pass_number;\t\t/* # of passes completed */\n  int total_passes;\t\t/* total # of passes needed */\n\n  int scan_number;\t\t/* current index in scan_info[] */\n} my_comp_master;\n\ntypedef my_comp_master * my_master_ptr;\n\n\n/*\n * Support routines that do various essential calculations.\n */\n\n/*\n * Compute JPEG image dimensions and related values.\n * NOTE: this is exported for possible use by application.\n * Hence it mustn't do anything that can't be done twice.\n */\n\nGLOBAL(void)\njpeg_calc_jpeg_dimensions (j_compress_ptr cinfo)\n/* Do computations that are needed before master selection phase */\n{\n#ifdef DCT_SCALING_SUPPORTED\n\n  /* Sanity check on input image dimensions to prevent overflow in\n   * following calculation.\n   * We do check jpeg_width and jpeg_height in initial_setup below,\n   * but image_width and image_height can come from arbitrary data,\n   * and we need some space for multiplication by block_size.\n   */\n  if (((long) cinfo->image_width >> 24) || ((long) cinfo->image_height >> 24))\n    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);\n\n  /* Compute actual JPEG image dimensions and DCT scaling choices. */\n  if (cinfo->scale_num >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/1 scaling */\n    cinfo->jpeg_width = cinfo->image_width * cinfo->block_size;\n    cinfo->jpeg_height = cinfo->image_height * cinfo->block_size;\n    cinfo->min_DCT_h_scaled_size = 1;\n    cinfo->min_DCT_v_scaled_size = 1;\n  } else if (cinfo->scale_num * 2 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/2 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 2L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 2L);\n    cinfo->min_DCT_h_scaled_size = 2;\n    cinfo->min_DCT_v_scaled_size = 2;\n  } else if (cinfo->scale_num * 3 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/3 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 3L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 3L);\n    cinfo->min_DCT_h_scaled_size = 3;\n    cinfo->min_DCT_v_scaled_size = 3;\n  } else if (cinfo->scale_num * 4 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/4 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 4L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 4L);\n    cinfo->min_DCT_h_scaled_size = 4;\n    cinfo->min_DCT_v_scaled_size = 4;\n  } else if (cinfo->scale_num * 5 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/5 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 5L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 5L);\n    cinfo->min_DCT_h_scaled_size = 5;\n    cinfo->min_DCT_v_scaled_size = 5;\n  } else if (cinfo->scale_num * 6 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/6 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 6L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 6L);\n    cinfo->min_DCT_h_scaled_size = 6;\n    cinfo->min_DCT_v_scaled_size = 6;\n  } else if (cinfo->scale_num * 7 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/7 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 7L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 7L);\n    cinfo->min_DCT_h_scaled_size = 7;\n    cinfo->min_DCT_v_scaled_size = 7;\n  } else if (cinfo->scale_num * 8 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/8 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 8L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 8L);\n    cinfo->min_DCT_h_scaled_size = 8;\n    cinfo->min_DCT_v_scaled_size = 8;\n  } else if (cinfo->scale_num * 9 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/9 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 9L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 9L);\n    cinfo->min_DCT_h_scaled_size = 9;\n    cinfo->min_DCT_v_scaled_size = 9;\n  } else if (cinfo->scale_num * 10 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/10 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 10L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 10L);\n    cinfo->min_DCT_h_scaled_size = 10;\n    cinfo->min_DCT_v_scaled_size = 10;\n  } else if (cinfo->scale_num * 11 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/11 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 11L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 11L);\n    cinfo->min_DCT_h_scaled_size = 11;\n    cinfo->min_DCT_v_scaled_size = 11;\n  } else if (cinfo->scale_num * 12 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/12 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 12L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 12L);\n    cinfo->min_DCT_h_scaled_size = 12;\n    cinfo->min_DCT_v_scaled_size = 12;\n  } else if (cinfo->scale_num * 13 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/13 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 13L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 13L);\n    cinfo->min_DCT_h_scaled_size = 13;\n    cinfo->min_DCT_v_scaled_size = 13;\n  } else if (cinfo->scale_num * 14 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/14 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 14L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 14L);\n    cinfo->min_DCT_h_scaled_size = 14;\n    cinfo->min_DCT_v_scaled_size = 14;\n  } else if (cinfo->scale_num * 15 >= cinfo->scale_denom * cinfo->block_size) {\n    /* Provide block_size/15 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 15L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 15L);\n    cinfo->min_DCT_h_scaled_size = 15;\n    cinfo->min_DCT_v_scaled_size = 15;\n  } else {\n    /* Provide block_size/16 scaling */\n    cinfo->jpeg_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * cinfo->block_size, 16L);\n    cinfo->jpeg_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * cinfo->block_size, 16L);\n    cinfo->min_DCT_h_scaled_size = 16;\n    cinfo->min_DCT_v_scaled_size = 16;\n  }\n\n#else /* !DCT_SCALING_SUPPORTED */\n\n  /* Hardwire it to \"no scaling\" */\n  cinfo->jpeg_width = cinfo->image_width;\n  cinfo->jpeg_height = cinfo->image_height;\n  cinfo->min_DCT_h_scaled_size = DCTSIZE;\n  cinfo->min_DCT_v_scaled_size = DCTSIZE;\n\n#endif /* DCT_SCALING_SUPPORTED */\n}\n\n\nLOCAL(void)\njpeg_calc_trans_dimensions (j_compress_ptr cinfo)\n{\n  if (cinfo->min_DCT_h_scaled_size != cinfo->min_DCT_v_scaled_size)\n    ERREXIT2(cinfo, JERR_BAD_DCTSIZE,\n\t     cinfo->min_DCT_h_scaled_size, cinfo->min_DCT_v_scaled_size);\n\n  cinfo->block_size = cinfo->min_DCT_h_scaled_size;\n}\n\n\nLOCAL(void)\ninitial_setup (j_compress_ptr cinfo, boolean transcode_only)\n/* Do computations that are needed before master selection phase */\n{\n  int ci, ssize;\n  jpeg_component_info *compptr;\n\n  if (transcode_only)\n    jpeg_calc_trans_dimensions(cinfo);\n  else\n    jpeg_calc_jpeg_dimensions(cinfo);\n\n  /* Sanity check on block_size */\n  if (cinfo->block_size < 1 || cinfo->block_size > 16)\n    ERREXIT2(cinfo, JERR_BAD_DCTSIZE, cinfo->block_size, cinfo->block_size);\n\n  /* Derive natural_order from block_size */\n  switch (cinfo->block_size) {\n  case 2: cinfo->natural_order = jpeg_natural_order2; break;\n  case 3: cinfo->natural_order = jpeg_natural_order3; break;\n  case 4: cinfo->natural_order = jpeg_natural_order4; break;\n  case 5: cinfo->natural_order = jpeg_natural_order5; break;\n  case 6: cinfo->natural_order = jpeg_natural_order6; break;\n  case 7: cinfo->natural_order = jpeg_natural_order7; break;\n  default: cinfo->natural_order = jpeg_natural_order; break;\n  }\n\n  /* Derive lim_Se from block_size */\n  cinfo->lim_Se = cinfo->block_size < DCTSIZE ?\n    cinfo->block_size * cinfo->block_size - 1 : DCTSIZE2-1;\n\n  /* Sanity check on image dimensions */\n  if (cinfo->jpeg_height <= 0 || cinfo->jpeg_width <= 0 ||\n      cinfo->num_components <= 0)\n    ERREXIT(cinfo, JERR_EMPTY_IMAGE);\n\n  /* Make sure image isn't bigger than I can handle */\n  if ((long) cinfo->jpeg_height > (long) JPEG_MAX_DIMENSION ||\n      (long) cinfo->jpeg_width > (long) JPEG_MAX_DIMENSION)\n    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);\n\n  /* Only 8 to 12 bits data precision are supported for DCT based JPEG */\n  if (cinfo->data_precision < 8 || cinfo->data_precision > 12)\n    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);\n\n  /* Check that number of components won't exceed internal array sizes */\n  if (cinfo->num_components > MAX_COMPONENTS)\n    ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,\n\t     MAX_COMPONENTS);\n\n  /* Compute maximum sampling factors; check factor validity */\n  cinfo->max_h_samp_factor = 1;\n  cinfo->max_v_samp_factor = 1;\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||\n\tcompptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)\n      ERREXIT(cinfo, JERR_BAD_SAMPLING);\n    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,\n\t\t\t\t   compptr->h_samp_factor);\n    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,\n\t\t\t\t   compptr->v_samp_factor);\n  }\n\n  /* Compute dimensions of components */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Fill in the correct component_index value; don't rely on application */\n    compptr->component_index = ci;\n    /* In selecting the actual DCT scaling for each component, we try to\n     * scale down the chroma components via DCT scaling rather than downsampling.\n     * This saves time if the downsampler gets to use 1:1 scaling.\n     * Note this code adapts subsampling ratios which are powers of 2.\n     */\n    ssize = 1;\n#ifdef DCT_SCALING_SUPPORTED\n    while (cinfo->min_DCT_h_scaled_size * ssize <=\n\t   (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&\n\t   (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {\n      ssize = ssize * 2;\n    }\n#endif\n    compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;\n    ssize = 1;\n#ifdef DCT_SCALING_SUPPORTED\n    while (cinfo->min_DCT_v_scaled_size * ssize <=\n\t   (cinfo->do_fancy_downsampling ? DCTSIZE : DCTSIZE / 2) &&\n\t   (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {\n      ssize = ssize * 2;\n    }\n#endif\n    compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;\n\n    /* We don't support DCT ratios larger than 2. */\n    if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)\n\tcompptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;\n    else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)\n\tcompptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;\n\n    /* Size in DCT blocks */\n    compptr->width_in_blocks = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_width * (long) compptr->h_samp_factor,\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    compptr->height_in_blocks = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_height * (long) compptr->v_samp_factor,\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n    /* Size in samples */\n    compptr->downsampled_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_width *\n\t\t    (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    compptr->downsampled_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_height *\n\t\t    (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n    /* Don't need quantization scale after DCT,\n     * until color conversion says otherwise.\n     */\n    compptr->component_needed = FALSE;\n  }\n\n  /* Compute number of fully interleaved MCU rows (number of times that\n   * main controller will call coefficient controller).\n   */\n  cinfo->total_iMCU_rows = (JDIMENSION)\n    jdiv_round_up((long) cinfo->jpeg_height,\n\t\t  (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n}\n\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n\nLOCAL(void)\nvalidate_script (j_compress_ptr cinfo)\n/* Verify that the scan script in cinfo->scan_info[] is valid; also\n * determine whether it uses progressive JPEG, and set cinfo->progressive_mode.\n */\n{\n  const jpeg_scan_info * scanptr;\n  int scanno, ncomps, ci, coefi, thisi;\n  int Ss, Se, Ah, Al;\n  boolean component_sent[MAX_COMPONENTS];\n#ifdef C_PROGRESSIVE_SUPPORTED\n  int * last_bitpos_ptr;\n  int last_bitpos[MAX_COMPONENTS][DCTSIZE2];\n  /* -1 until that coefficient has been seen; then last Al for it */\n#endif\n\n  if (cinfo->num_scans <= 0)\n    ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);\n\n  /* For sequential JPEG, all scans must have Ss=0, Se=DCTSIZE2-1;\n   * for progressive JPEG, no scan can have this.\n   */\n  scanptr = cinfo->scan_info;\n  if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {\n#ifdef C_PROGRESSIVE_SUPPORTED\n    cinfo->progressive_mode = TRUE;\n    last_bitpos_ptr = & last_bitpos[0][0];\n    for (ci = 0; ci < cinfo->num_components; ci++) \n      for (coefi = 0; coefi < DCTSIZE2; coefi++)\n\t*last_bitpos_ptr++ = -1;\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n  } else {\n    cinfo->progressive_mode = FALSE;\n    for (ci = 0; ci < cinfo->num_components; ci++) \n      component_sent[ci] = FALSE;\n  }\n\n  for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {\n    /* Validate component indexes */\n    ncomps = scanptr->comps_in_scan;\n    if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)\n      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);\n    for (ci = 0; ci < ncomps; ci++) {\n      thisi = scanptr->component_index[ci];\n      if (thisi < 0 || thisi >= cinfo->num_components)\n\tERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);\n      /* Components must appear in SOF order within each scan */\n      if (ci > 0 && thisi <= scanptr->component_index[ci-1])\n\tERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);\n    }\n    /* Validate progression parameters */\n    Ss = scanptr->Ss;\n    Se = scanptr->Se;\n    Ah = scanptr->Ah;\n    Al = scanptr->Al;\n    if (cinfo->progressive_mode) {\n#ifdef C_PROGRESSIVE_SUPPORTED\n      /* The JPEG spec simply gives the ranges 0..13 for Ah and Al, but that\n       * seems wrong: the upper bound ought to depend on data precision.\n       * Perhaps they really meant 0..N+1 for N-bit precision.\n       * Here we allow 0..10 for 8-bit data; Al larger than 10 results in\n       * out-of-range reconstructed DC values during the first DC scan,\n       * which might cause problems for some decoders.\n       */\n#if BITS_IN_JSAMPLE == 8\n#define MAX_AH_AL 10\n#else\n#define MAX_AH_AL 13\n#endif\n      if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||\n\t  Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)\n\tERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n      if (Ss == 0) {\n\tif (Se != 0)\t\t/* DC and AC together not OK */\n\t  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n      } else {\n\tif (ncomps != 1)\t/* AC scans must be for only one component */\n\t  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n      }\n      for (ci = 0; ci < ncomps; ci++) {\n\tlast_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];\n\tif (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */\n\t  ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n\tfor (coefi = Ss; coefi <= Se; coefi++) {\n\t  if (last_bitpos_ptr[coefi] < 0) {\n\t    /* first scan of this coefficient */\n\t    if (Ah != 0)\n\t      ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n\t  } else {\n\t    /* not first scan */\n\t    if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)\n\t      ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n\t  }\n\t  last_bitpos_ptr[coefi] = Al;\n\t}\n      }\n#endif\n    } else {\n      /* For sequential JPEG, all progression parameters must be these: */\n      if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)\n\tERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);\n      /* Make sure components are not sent twice */\n      for (ci = 0; ci < ncomps; ci++) {\n\tthisi = scanptr->component_index[ci];\n\tif (component_sent[thisi])\n\t  ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);\n\tcomponent_sent[thisi] = TRUE;\n      }\n    }\n  }\n\n  /* Now verify that everything got sent. */\n  if (cinfo->progressive_mode) {\n#ifdef C_PROGRESSIVE_SUPPORTED\n    /* For progressive mode, we only check that at least some DC data\n     * got sent for each component; the spec does not require that all bits\n     * of all coefficients be transmitted.  Would it be wiser to enforce\n     * transmission of all coefficient bits??\n     */\n    for (ci = 0; ci < cinfo->num_components; ci++) {\n      if (last_bitpos[ci][0] < 0)\n\tERREXIT(cinfo, JERR_MISSING_DATA);\n    }\n#endif\n  } else {\n    for (ci = 0; ci < cinfo->num_components; ci++) {\n      if (! component_sent[ci])\n\tERREXIT(cinfo, JERR_MISSING_DATA);\n    }\n  }\n}\n\n\nLOCAL(void)\nreduce_script (j_compress_ptr cinfo)\n/* Adapt scan script for use with reduced block size;\n * assume that script has been validated before.\n */\n{\n  jpeg_scan_info * scanptr;\n  int idxout, idxin;\n\n  /* Circumvent const declaration for this function */\n  scanptr = (jpeg_scan_info *) cinfo->scan_info;\n  idxout = 0;\n\n  for (idxin = 0; idxin < cinfo->num_scans; idxin++) {\n    /* After skipping, idxout becomes smaller than idxin */\n    if (idxin != idxout)\n      /* Copy rest of data;\n       * note we stay in given chunk of allocated memory.\n       */\n      scanptr[idxout] = scanptr[idxin];\n    if (scanptr[idxout].Ss > cinfo->lim_Se)\n      /* Entire scan out of range - skip this entry */\n      continue;\n    if (scanptr[idxout].Se > cinfo->lim_Se)\n      /* Limit scan to end of block */\n      scanptr[idxout].Se = cinfo->lim_Se;\n    idxout++;\n  }\n\n  cinfo->num_scans = idxout;\n}\n\n#endif /* C_MULTISCAN_FILES_SUPPORTED */\n\n\nLOCAL(void)\nselect_scan_parameters (j_compress_ptr cinfo)\n/* Set up the scan parameters for the current scan */\n{\n  int ci;\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n  if (cinfo->scan_info != NULL) {\n    /* Prepare for current scan --- the script is already validated */\n    my_master_ptr master = (my_master_ptr) cinfo->master;\n    const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;\n\n    cinfo->comps_in_scan = scanptr->comps_in_scan;\n    for (ci = 0; ci < scanptr->comps_in_scan; ci++) {\n      cinfo->cur_comp_info[ci] =\n\t&cinfo->comp_info[scanptr->component_index[ci]];\n    }\n    if (cinfo->progressive_mode) {\n      cinfo->Ss = scanptr->Ss;\n      cinfo->Se = scanptr->Se;\n      cinfo->Ah = scanptr->Ah;\n      cinfo->Al = scanptr->Al;\n      return;\n    }\n  }\n  else\n#endif\n  {\n    /* Prepare for single sequential-JPEG scan containing all components */\n    if (cinfo->num_components > MAX_COMPS_IN_SCAN)\n      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,\n\t       MAX_COMPS_IN_SCAN);\n    cinfo->comps_in_scan = cinfo->num_components;\n    for (ci = 0; ci < cinfo->num_components; ci++) {\n      cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];\n    }\n  }\n  cinfo->Ss = 0;\n  cinfo->Se = cinfo->block_size * cinfo->block_size - 1;\n  cinfo->Ah = 0;\n  cinfo->Al = 0;\n}\n\n\nLOCAL(void)\nper_scan_setup (j_compress_ptr cinfo)\n/* Do computations that are needed before processing a JPEG scan */\n/* cinfo->comps_in_scan and cinfo->cur_comp_info[] are already set */\n{\n  int ci, mcublks, tmp;\n  jpeg_component_info *compptr;\n  \n  if (cinfo->comps_in_scan == 1) {\n    \n    /* Noninterleaved (single-component) scan */\n    compptr = cinfo->cur_comp_info[0];\n    \n    /* Overall image size in MCUs */\n    cinfo->MCUs_per_row = compptr->width_in_blocks;\n    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;\n    \n    /* For noninterleaved scan, always one block per MCU */\n    compptr->MCU_width = 1;\n    compptr->MCU_height = 1;\n    compptr->MCU_blocks = 1;\n    compptr->MCU_sample_width = compptr->DCT_h_scaled_size;\n    compptr->last_col_width = 1;\n    /* For noninterleaved scans, it is convenient to define last_row_height\n     * as the number of block rows present in the last iMCU row.\n     */\n    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\n    if (tmp == 0) tmp = compptr->v_samp_factor;\n    compptr->last_row_height = tmp;\n    \n    /* Prepare array describing MCU composition */\n    cinfo->blocks_in_MCU = 1;\n    cinfo->MCU_membership[0] = 0;\n    \n  } else {\n    \n    /* Interleaved (multi-component) scan */\n    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)\n      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,\n\t       MAX_COMPS_IN_SCAN);\n    \n    /* Overall image size in MCUs */\n    cinfo->MCUs_per_row = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_width,\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    cinfo->MCU_rows_in_scan = (JDIMENSION)\n      jdiv_round_up((long) cinfo->jpeg_height,\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n    \n    cinfo->blocks_in_MCU = 0;\n    \n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      compptr = cinfo->cur_comp_info[ci];\n      /* Sampling factors give # of blocks of component in each MCU */\n      compptr->MCU_width = compptr->h_samp_factor;\n      compptr->MCU_height = compptr->v_samp_factor;\n      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;\n      compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;\n      /* Figure number of non-dummy blocks in last MCU column & row */\n      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);\n      if (tmp == 0) tmp = compptr->MCU_width;\n      compptr->last_col_width = tmp;\n      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);\n      if (tmp == 0) tmp = compptr->MCU_height;\n      compptr->last_row_height = tmp;\n      /* Prepare array describing MCU composition */\n      mcublks = compptr->MCU_blocks;\n      if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)\n\tERREXIT(cinfo, JERR_BAD_MCU_SIZE);\n      while (mcublks-- > 0) {\n\tcinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;\n      }\n    }\n    \n  }\n\n  /* Convert restart specified in rows to actual MCU count. */\n  /* Note that count must fit in 16 bits, so we provide limiting. */\n  if (cinfo->restart_in_rows > 0) {\n    long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;\n    cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);\n  }\n}\n\n\n/*\n * Per-pass setup.\n * This is called at the beginning of each pass.  We determine which modules\n * will be active during this pass and give them appropriate start_pass calls.\n * We also set is_last_pass to indicate whether any more passes will be\n * required.\n */\n\nMETHODDEF(void)\nprepare_for_pass (j_compress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n\n  switch (master->pass_type) {\n  case main_pass:\n    /* Initial pass: will collect input data, and do either Huffman\n     * optimization or data output for the first scan.\n     */\n    select_scan_parameters(cinfo);\n    per_scan_setup(cinfo);\n    if (! cinfo->raw_data_in) {\n      (*cinfo->cconvert->start_pass) (cinfo);\n      (*cinfo->downsample->start_pass) (cinfo);\n      (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);\n    }\n    (*cinfo->fdct->start_pass) (cinfo);\n    (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);\n    (*cinfo->coef->start_pass) (cinfo,\n\t\t\t\t(master->total_passes > 1 ?\n\t\t\t\t JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));\n    (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);\n    if (cinfo->optimize_coding) {\n      /* No immediate data output; postpone writing frame/scan headers */\n      master->pub.call_pass_startup = FALSE;\n    } else {\n      /* Will write frame/scan headers at first jpeg_write_scanlines call */\n      master->pub.call_pass_startup = TRUE;\n    }\n    break;\n#ifdef ENTROPY_OPT_SUPPORTED\n  case huff_opt_pass:\n    /* Do Huffman optimization for a scan after the first one. */\n    select_scan_parameters(cinfo);\n    per_scan_setup(cinfo);\n    if (cinfo->Ss != 0 || cinfo->Ah == 0) {\n      (*cinfo->entropy->start_pass) (cinfo, TRUE);\n      (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);\n      master->pub.call_pass_startup = FALSE;\n      break;\n    }\n    /* Special case: Huffman DC refinement scans need no Huffman table\n     * and therefore we can skip the optimization pass for them.\n     */\n    master->pass_type = output_pass;\n    master->pass_number++;\n    /*FALLTHROUGH*/\n#endif\n  case output_pass:\n    /* Do a data-output pass. */\n    /* We need not repeat per-scan setup if prior optimization pass did it. */\n    if (! cinfo->optimize_coding) {\n      select_scan_parameters(cinfo);\n      per_scan_setup(cinfo);\n    }\n    (*cinfo->entropy->start_pass) (cinfo, FALSE);\n    (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);\n    /* We emit frame/scan headers now */\n    if (master->scan_number == 0)\n      (*cinfo->marker->write_frame_header) (cinfo);\n    (*cinfo->marker->write_scan_header) (cinfo);\n    master->pub.call_pass_startup = FALSE;\n    break;\n  default:\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n  }\n\n  master->pub.is_last_pass = (master->pass_number == master->total_passes-1);\n\n  /* Set up progress monitor's pass info if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->completed_passes = master->pass_number;\n    cinfo->progress->total_passes = master->total_passes;\n  }\n}\n\n\n/*\n * Special start-of-pass hook.\n * This is called by jpeg_write_scanlines if call_pass_startup is TRUE.\n * In single-pass processing, we need this hook because we don't want to\n * write frame/scan headers during jpeg_start_compress; we want to let the\n * application write COM markers etc. between jpeg_start_compress and the\n * jpeg_write_scanlines loop.\n * In multi-pass processing, this routine is not used.\n */\n\nMETHODDEF(void)\npass_startup (j_compress_ptr cinfo)\n{\n  cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */\n\n  (*cinfo->marker->write_frame_header) (cinfo);\n  (*cinfo->marker->write_scan_header) (cinfo);\n}\n\n\n/*\n * Finish up at end of pass.\n */\n\nMETHODDEF(void)\nfinish_pass_master (j_compress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n\n  /* The entropy coder always needs an end-of-pass call,\n   * either to analyze statistics or to flush its output buffer.\n   */\n  (*cinfo->entropy->finish_pass) (cinfo);\n\n  /* Update state for next pass */\n  switch (master->pass_type) {\n  case main_pass:\n    /* next pass is either output of scan 0 (after optimization)\n     * or output of scan 1 (if no optimization).\n     */\n    master->pass_type = output_pass;\n    if (! cinfo->optimize_coding)\n      master->scan_number++;\n    break;\n  case huff_opt_pass:\n    /* next pass is always output of current scan */\n    master->pass_type = output_pass;\n    break;\n  case output_pass:\n    /* next pass is either optimization or output of next scan */\n    if (cinfo->optimize_coding)\n      master->pass_type = huff_opt_pass;\n    master->scan_number++;\n    break;\n  }\n\n  master->pass_number++;\n}\n\n\n/*\n * Initialize master compression control.\n */\n\nGLOBAL(void)\njinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)\n{\n  my_master_ptr master;\n\n  master = (my_master_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(my_comp_master));\n  cinfo->master = &master->pub;\n  master->pub.prepare_for_pass = prepare_for_pass;\n  master->pub.pass_startup = pass_startup;\n  master->pub.finish_pass = finish_pass_master;\n  master->pub.is_last_pass = FALSE;\n\n  /* Validate parameters, determine derived values */\n  initial_setup(cinfo, transcode_only);\n\n  if (cinfo->scan_info != NULL) {\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n    validate_script(cinfo);\n    if (cinfo->block_size < DCTSIZE)\n      reduce_script(cinfo);\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n  } else {\n    cinfo->progressive_mode = FALSE;\n    cinfo->num_scans = 1;\n  }\n\n  if (cinfo->optimize_coding)\n    cinfo->arith_code = FALSE; /* disable arithmetic coding */\n  else if (! cinfo->arith_code &&\n\t   (cinfo->progressive_mode ||\n\t    (cinfo->block_size > 1 && cinfo->block_size < DCTSIZE)))\n    /* TEMPORARY HACK ??? */\n    /* assume default tables no good for progressive or reduced AC mode */\n    cinfo->optimize_coding = TRUE; /* force Huffman optimization */\n\n  /* Initialize my private state */\n  if (transcode_only) {\n    /* no main pass in transcoding */\n    if (cinfo->optimize_coding)\n      master->pass_type = huff_opt_pass;\n    else\n      master->pass_type = output_pass;\n  } else {\n    /* for normal compression, first pass is always this type: */\n    master->pass_type = main_pass;\n  }\n  master->scan_number = 0;\n  master->pass_number = 0;\n  if (cinfo->optimize_coding)\n    master->total_passes = cinfo->num_scans * 2;\n  else\n    master->total_passes = cinfo->num_scans;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcomapi.c",
    "content": "/*\n * jcomapi.c\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains application interface routines that are used for both\n * compression and decompression.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Abort processing of a JPEG compression or decompression operation,\n * but don't destroy the object itself.\n *\n * For this, we merely clean up all the nonpermanent memory pools.\n * Note that temp files (virtual arrays) are not allowed to belong to\n * the permanent pool, so we will be able to close all temp files here.\n * Closing a data source or destination, if necessary, is the application's\n * responsibility.\n */\n\nGLOBAL(void)\njpeg_abort (j_common_ptr cinfo)\n{\n  int pool;\n\n  /* Do nothing if called on a not-initialized or destroyed JPEG object. */\n  if (cinfo->mem == NULL)\n    return;\n\n  /* Releasing pools in reverse order might help avoid fragmentation\n   * with some (brain-damaged) malloc libraries.\n   */\n  for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {\n    (*cinfo->mem->free_pool) (cinfo, pool);\n  }\n\n  /* Reset overall state for possible reuse of object */\n  if (cinfo->is_decompressor) {\n    cinfo->global_state = DSTATE_START;\n    /* Try to keep application from accessing now-deleted marker list.\n     * A bit kludgy to do it here, but this is the most central place.\n     */\n    ((j_decompress_ptr) cinfo)->marker_list = NULL;\n  } else {\n    cinfo->global_state = CSTATE_START;\n  }\n}\n\n\n/*\n * Destruction of a JPEG object.\n *\n * Everything gets deallocated except the master jpeg_compress_struct itself\n * and the error manager struct.  Both of these are supplied by the application\n * and must be freed, if necessary, by the application.  (Often they are on\n * the stack and so don't need to be freed anyway.)\n * Closing a data source or destination, if necessary, is the application's\n * responsibility.\n */\n\nGLOBAL(void)\njpeg_destroy (j_common_ptr cinfo)\n{\n  /* We need only tell the memory manager to release everything. */\n  /* NB: mem pointer is NULL if memory mgr failed to initialize. */\n  if (cinfo->mem != NULL)\n    (*cinfo->mem->self_destruct) (cinfo);\n  cinfo->mem = NULL;\t\t/* be safe if jpeg_destroy is called twice */\n  cinfo->global_state = 0;\t/* mark it destroyed */\n}\n\n\n/*\n * Convenience routines for allocating quantization and Huffman tables.\n * (Would jutils.c be a more reasonable place to put these?)\n */\n\nGLOBAL(JQUANT_TBL *)\njpeg_alloc_quant_table (j_common_ptr cinfo)\n{\n  JQUANT_TBL *tbl;\n\n  tbl = (JQUANT_TBL *)\n    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));\n  tbl->sent_table = FALSE;\t/* make sure this is false in any new table */\n  return tbl;\n}\n\n\nGLOBAL(JHUFF_TBL *)\njpeg_alloc_huff_table (j_common_ptr cinfo)\n{\n  JHUFF_TBL *tbl;\n\n  tbl = (JHUFF_TBL *)\n    (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));\n  tbl->sent_table = FALSE;\t/* make sure this is false in any new table */\n  return tbl;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.bcc",
    "content": "/* jconfig.bcc --- jconfig.h for Borland C (Turbo C) on MS-DOS or OS/2. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#ifdef __MSDOS__\n#define NEED_FAR_POINTERS\t/* for small or medium memory model */\n#endif\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\t/* this assumes you have -w-stu in CFLAGS */\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#ifdef __MSDOS__\n#define USE_MSDOS_MEMMGR\t/* Define this if you use jmemdos.c */\n#define MAX_ALLOC_CHUNK 65520L\t/* Maximum request to malloc() */\n#define USE_FMEM\t\t/* Borland has _fmemcpy() and _fmemset() */\n#endif\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\n#define USE_SETMODE\t\t/* Borland has setmode() */\n#ifdef __MSDOS__\n#define NEED_SIGNAL_CATCHER\t/* Define this if you use jmemdos.c */\n#endif\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.cfg",
    "content": "/* jconfig.cfg --- source file edited by configure script */\n/* see jconfig.txt for explanations */\n\n#undef HAVE_PROTOTYPES\n#undef HAVE_UNSIGNED_CHAR\n#undef HAVE_UNSIGNED_SHORT\n#undef void\n#undef const\n#undef CHAR_IS_UNSIGNED\n#undef HAVE_STDDEF_H\n#undef HAVE_STDLIB_H\n#undef HAVE_LOCALE_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n/* Define this if you get warnings about undefined structures. */\n#undef INCOMPLETE_TYPES_BROKEN\n\n/* Define \"boolean\" as unsigned char, not enum, on Windows systems. */\n#ifdef _WIN32\n#ifndef __RPCNDR_H__\t\t/* don't conflict if rpcndr.h already read */\ntypedef unsigned char boolean;\n#endif\n#ifndef FALSE\t\t\t/* in case these macros already exist */\n#define FALSE\t0\t\t/* values of boolean */\n#endif\n#ifndef TRUE\n#define TRUE\t1\n#endif\n#define HAVE_BOOLEAN\t\t/* prevent jmorecfg.h from redefining it */\n#endif\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n#undef INLINE\n/* These are for configuring the JPEG memory manager. */\n#undef DEFAULT_MAX_MEM\n#undef NO_MKTEMP\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#undef TWO_FILE_COMMANDLINE\n#undef NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n\n/* Define this if you want percent-done progress reports from cjpeg/djpeg. */\n#undef PROGRESS_REPORT\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.dj",
    "content": "/* jconfig.dj --- jconfig.h for DJGPP (Delorie's GNU C port) on MS-DOS. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\t/* DJGPP uses flat 32-bit addressing */\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#undef TWO_FILE_COMMANDLINE\t/* optional */\n#define USE_SETMODE\t\t/* Needed to make one-file style work in DJGPP */\n#undef NEED_SIGNAL_CATCHER\t/* Define this if you use jmemname.c */\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.h",
    "content": ""
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.mac",
    "content": "/* jconfig.mac --- jconfig.h for CodeWarrior on Apple Macintosh */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#define USE_MAC_MEMMGR\t\t/* Define this if you use jmemmac.c */\n\n#define ALIGN_TYPE long\t\t/* Needed for 680x0 Macs */\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define USE_CCOMMAND\t\t/* Command line reader for Macintosh */\n#define TWO_FILE_COMMANDLINE\t/* Binary I/O thru stdin/stdout doesn't work */\n\n#undef NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.manx",
    "content": "/* jconfig.manx --- jconfig.h for Amiga systems using Manx Aztec C ver 5.x. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#define TEMP_DIRECTORY \"JPEGTMP:\"\t/* recommended setting for Amiga */\n\n#define SHORTxSHORT_32\t\t/* produces better DCT code with Aztec C */\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\n#define NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#define signal_catcher _abort\t/* hack for Aztec C naming requirements */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.mc6",
    "content": "/* jconfig.mc6 --- jconfig.h for Microsoft C on MS-DOS, version 6.00A & up. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#define NEED_FAR_POINTERS\t/* for small or medium memory model */\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#define USE_MSDOS_MEMMGR\t/* Define this if you use jmemdos.c */\n\n#define MAX_ALLOC_CHUNK 65520L\t/* Maximum request to malloc() */\n\n#define USE_FMEM\t\t/* Microsoft has _fmemcpy() and _fmemset() */\n\n#define NEED_FHEAPMIN\t\t/* far heap management routines are broken */\n\n#define SHORTxLCONST_32\t\t/* enable compiler-specific DCT optimization */\n/* Note: the above define is known to improve the code with Microsoft C 6.00A.\n * I do not know whether it is good for later compiler versions.\n * Please report any info on this point to jpeg-info@jpegclub.org.\n */\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\n#define USE_SETMODE\t\t/* Microsoft has setmode() */\n#define NEED_SIGNAL_CATCHER\t/* Define this if you use jmemdos.c */\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.sas",
    "content": "/* jconfig.sas --- jconfig.h for Amiga systems using SAS C 6.0 and up. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#define TEMP_DIRECTORY \"JPEGTMP:\"\t/* recommended setting for Amiga */\n\n#define NO_MKTEMP\t\t/* SAS C doesn't have mktemp() */\n\n#define SHORTxSHORT_32\t\t/* produces better DCT code with SAS C */\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\n#define NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.st",
    "content": "/* jconfig.st --- jconfig.h for Atari ST/STE/TT using Pure C or Turbo C. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n#define INCOMPLETE_TYPES_BROKEN\t/* suppress undefined-structure warnings */\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#define ALIGN_TYPE  long\t/* apparently double is a weird size? */\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\t/* optional -- undef if you like Unix style */\n/* Note: if you undef TWO_FILE_COMMANDLINE, you may need to define\n * USE_SETMODE.  Some Atari compilers require it, some do not.\n */\n#define NEED_SIGNAL_CATCHER\t/* needed if you use jmemname.c */\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.txt",
    "content": "/*\n * jconfig.txt\n *\n * Copyright (C) 1991-1994, Thomas G. Lane.\n * Modified 2009-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file documents the configuration options that are required to\n * customize the JPEG software for a particular system.\n *\n * The actual configuration options for a particular installation are stored\n * in jconfig.h.  On many machines, jconfig.h can be generated automatically\n * or copied from one of the \"canned\" jconfig files that we supply.  But if\n * you need to generate a jconfig.h file by hand, this file tells you how.\n *\n * DO NOT EDIT THIS FILE --- IT WON'T ACCOMPLISH ANYTHING.\n * EDIT A COPY NAMED JCONFIG.H.\n */\n\n\n/*\n * These symbols indicate the properties of your machine or compiler.\n * #define the symbol if yes, #undef it if no.\n */\n\n/* Does your compiler support function prototypes?\n * (If not, you also need to use ansi2knr, see install.txt)\n */\n#define HAVE_PROTOTYPES\n\n/* Does your compiler support the declaration \"unsigned char\" ?\n * How about \"unsigned short\" ?\n */\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n\n/* Define \"void\" as \"char\" if your compiler doesn't know about type void.\n * NOTE: be sure to define void such that \"void *\" represents the most general\n * pointer type, e.g., that returned by malloc().\n */\n/* #define void char */\n\n/* Define \"const\" as empty if your compiler doesn't know the \"const\" keyword.\n */\n/* #define const */\n\n/* Define this if an ordinary \"char\" type is unsigned.\n * If you're not sure, leaving it undefined will work at some cost in speed.\n * If you defined HAVE_UNSIGNED_CHAR then the speed difference is minimal.\n */\n#undef CHAR_IS_UNSIGNED\n\n/* Define this if your system has an ANSI-conforming <stddef.h> file.\n */\n#define HAVE_STDDEF_H\n\n/* Define this if your system has an ANSI-conforming <stdlib.h> file.\n */\n#define HAVE_STDLIB_H\n\n/* Define this if your system does not have an ANSI/SysV <string.h>,\n * but does have a BSD-style <strings.h>.\n */\n#undef NEED_BSD_STRINGS\n\n/* Define this if your system does not provide typedef size_t in any of the\n * ANSI-standard places (stddef.h, stdlib.h, or stdio.h), but places it in\n * <sys/types.h> instead.\n */\n#undef NEED_SYS_TYPES_H\n\n/* For 80x86 machines, you need to define NEED_FAR_POINTERS,\n * unless you are using a large-data memory model or 80386 flat-memory mode.\n * On less brain-damaged CPUs this symbol must not be defined.\n * (Defining this symbol causes large data structures to be referenced through\n * \"far\" pointers and to be allocated with a special version of malloc.)\n */\n#undef NEED_FAR_POINTERS\n\n/* Define this if your linker needs global names to be unique in less\n * than the first 15 characters.\n */\n#undef NEED_SHORT_EXTERNAL_NAMES\n\n/* Although a real ANSI C compiler can deal perfectly well with pointers to\n * unspecified structures (see \"incomplete types\" in the spec), a few pre-ANSI\n * and pseudo-ANSI compilers get confused.  To keep one of these bozos happy,\n * define INCOMPLETE_TYPES_BROKEN.  This is not recommended unless you\n * actually get \"missing structure definition\" warnings or errors while\n * compiling the JPEG code.\n */\n#undef INCOMPLETE_TYPES_BROKEN\n\n/* Define \"boolean\" as unsigned char, not enum, on Windows systems.\n */\n#ifdef _WIN32\n#ifndef __RPCNDR_H__\t\t/* don't conflict if rpcndr.h already read */\ntypedef unsigned char boolean;\n#endif\n#ifndef FALSE\t\t\t/* in case these macros already exist */\n#define FALSE\t0\t\t/* values of boolean */\n#endif\n#ifndef TRUE\n#define TRUE\t1\n#endif\n#define HAVE_BOOLEAN\t\t/* prevent jmorecfg.h from redefining it */\n#endif\n\n\n/*\n * The following options affect code selection within the JPEG library,\n * but they don't need to be visible to applications using the library.\n * To minimize application namespace pollution, the symbols won't be\n * defined unless JPEG_INTERNALS has been defined.\n */\n\n#ifdef JPEG_INTERNALS\n\n/* Define this if your compiler implements \">>\" on signed values as a logical\n * (unsigned) shift; leave it undefined if \">>\" is a signed (arithmetic) shift,\n * which is the normal and rational definition.\n */\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n\n#endif /* JPEG_INTERNALS */\n\n\n/*\n * The remaining options do not affect the JPEG library proper,\n * but only the sample applications cjpeg/djpeg (see cjpeg.c, djpeg.c).\n * Other applications can ignore these.\n */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n/* These defines indicate which image (non-JPEG) file formats are allowed. */\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n/* Define this if you want to name both input and output files on the command\n * line, rather than using stdout and optionally stdin.  You MUST do this if\n * your system can't cope with binary I/O to stdin/stdout.  See comments at\n * head of cjpeg.c or djpeg.c.\n */\n#undef TWO_FILE_COMMANDLINE\n\n/* Define this if your system needs explicit cleanup of temporary files.\n * This is crucial under MS-DOS, where the temporary \"files\" may be areas\n * of extended memory; on most other systems it's not as important.\n */\n#undef NEED_SIGNAL_CATCHER\n\n/* By default, we open image files with fopen(...,\"rb\") or fopen(...,\"wb\").\n * This is necessary on systems that distinguish text files from binary files,\n * and is harmless on most systems that don't.  If you have one of the rare\n * systems that complains about the \"b\" spec, define this symbol.\n */\n#undef DONT_USE_B_MODE\n\n/* Define this if you want percent-done progress reports from cjpeg/djpeg.\n */\n#undef PROGRESS_REPORT\n\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.vc",
    "content": "/* jconfig.vc --- jconfig.h for Microsoft Visual C++ on Windows 9x or NT. */\n/* This file also works for Borland C++ 32-bit (bcc32) on Windows 9x or NT. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\t/* we presume a 32-bit flat memory model */\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n/* Define \"boolean\" as unsigned char, not enum, per Windows custom */\n#ifndef __RPCNDR_H__\t\t/* don't conflict if rpcndr.h already read */\ntypedef unsigned char boolean;\n#endif\n#ifndef FALSE\t\t\t/* in case these macros already exist */\n#define FALSE\t0\t\t/* values of boolean */\n#endif\n#ifndef TRUE\n#define TRUE\t1\n#endif\n#define HAVE_BOOLEAN\t\t/* prevent jmorecfg.h from redefining it */\n\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\t/* optional */\n#define USE_SETMODE\t\t/* Microsoft has setmode() */\n#undef NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.vms",
    "content": "/* jconfig.vms --- jconfig.h for use on Digital VMS. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#undef CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#define TWO_FILE_COMMANDLINE\t/* Needed on VMS */\n#undef NEED_SIGNAL_CATCHER\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jconfig.wat",
    "content": "/* jconfig.wat --- jconfig.h for Watcom C/C++ on MS-DOS or OS/2. */\n/* see jconfig.txt for explanations */\n\n#define HAVE_PROTOTYPES\n#define HAVE_UNSIGNED_CHAR\n#define HAVE_UNSIGNED_SHORT\n/* #define void char */\n/* #define const */\n#define CHAR_IS_UNSIGNED\n#define HAVE_STDDEF_H\n#define HAVE_STDLIB_H\n#undef NEED_BSD_STRINGS\n#undef NEED_SYS_TYPES_H\n#undef NEED_FAR_POINTERS\t/* Watcom uses flat 32-bit addressing */\n#undef NEED_SHORT_EXTERNAL_NAMES\n#undef INCOMPLETE_TYPES_BROKEN\n\n#ifdef JPEG_INTERNALS\n\n#undef RIGHT_SHIFT_IS_UNSIGNED\n\n#endif /* JPEG_INTERNALS */\n\n#ifdef JPEG_CJPEG_DJPEG\n\n#define BMP_SUPPORTED\t\t/* BMP image file format */\n#define GIF_SUPPORTED\t\t/* GIF image file format */\n#define PPM_SUPPORTED\t\t/* PBMPLUS PPM/PGM image file format */\n#undef RLE_SUPPORTED\t\t/* Utah RLE image file format */\n#define TARGA_SUPPORTED\t\t/* Targa image file format */\n\n#undef TWO_FILE_COMMANDLINE\t/* optional */\n#define USE_SETMODE\t\t/* Needed to make one-file style work in Watcom */\n#undef NEED_SIGNAL_CATCHER\t/* Define this if you use jmemname.c */\n#undef DONT_USE_B_MODE\n#undef PROGRESS_REPORT\t\t/* optional */\n\n#endif /* JPEG_CJPEG_DJPEG */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcparam.c",
    "content": "/*\n * jcparam.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2003-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains optional default-setting code for the JPEG compressor.\n * Applications do not have to use this file, but those that don't use it\n * must know a lot more about the innards of the JPEG code.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Quantization table setup routines\n */\n\nGLOBAL(void)\njpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,\n\t\t      const unsigned int *basic_table,\n\t\t      int scale_factor, boolean force_baseline)\n/* Define a quantization table equal to the basic_table times\n * a scale factor (given as a percentage).\n * If force_baseline is TRUE, the computed quantization table entries\n * are limited to 1..255 for JPEG baseline compatibility.\n */\n{\n  JQUANT_TBL ** qtblptr;\n  int i;\n  long temp;\n\n  /* Safety check to ensure start_compress not called yet. */\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)\n    ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);\n\n  qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];\n\n  if (*qtblptr == NULL)\n    *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);\n\n  for (i = 0; i < DCTSIZE2; i++) {\n    temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;\n    /* limit the values to the valid range */\n    if (temp <= 0L) temp = 1L;\n    if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */\n    if (force_baseline && temp > 255L)\n      temp = 255L;\t\t/* limit to baseline range if requested */\n    (*qtblptr)->quantval[i] = (UINT16) temp;\n  }\n\n  /* Initialize sent_table FALSE so table will be written to JPEG file. */\n  (*qtblptr)->sent_table = FALSE;\n}\n\n\n/* These are the sample quantization tables given in JPEG spec section K.1.\n * The spec says that the values given produce \"good\" quality, and\n * when divided by 2, \"very good\" quality.\n */\nstatic const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {\n  16,  11,  10,  16,  24,  40,  51,  61,\n  12,  12,  14,  19,  26,  58,  60,  55,\n  14,  13,  16,  24,  40,  57,  69,  56,\n  14,  17,  22,  29,  51,  87,  80,  62,\n  18,  22,  37,  56,  68, 109, 103,  77,\n  24,  35,  55,  64,  81, 104, 113,  92,\n  49,  64,  78,  87, 103, 121, 120, 101,\n  72,  92,  95,  98, 112, 100, 103,  99\n};\nstatic const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {\n  17,  18,  24,  47,  99,  99,  99,  99,\n  18,  21,  26,  66,  99,  99,  99,  99,\n  24,  26,  56,  99,  99,  99,  99,  99,\n  47,  66,  99,  99,  99,  99,  99,  99,\n  99,  99,  99,  99,  99,  99,  99,  99,\n  99,  99,  99,  99,  99,  99,  99,  99,\n  99,  99,  99,  99,  99,  99,  99,  99,\n  99,  99,  99,  99,  99,  99,  99,  99\n};\n\n\nGLOBAL(void)\njpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)\n/* Set or change the 'quality' (quantization) setting, using default tables\n * and straight percentage-scaling quality scales.\n * This entry point allows different scalings for luminance and chrominance.\n */\n{\n  /* Set up two quantization tables using the specified scaling */\n  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,\n\t\t       cinfo->q_scale_factor[0], force_baseline);\n  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,\n\t\t       cinfo->q_scale_factor[1], force_baseline);\n}\n\n\nGLOBAL(void)\njpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,\n\t\t\t boolean force_baseline)\n/* Set or change the 'quality' (quantization) setting, using default tables\n * and a straight percentage-scaling quality scale.  In most cases it's better\n * to use jpeg_set_quality (below); this entry point is provided for\n * applications that insist on a linear percentage scaling.\n */\n{\n  /* Set up two quantization tables using the specified scaling */\n  jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,\n\t\t       scale_factor, force_baseline);\n  jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,\n\t\t       scale_factor, force_baseline);\n}\n\n\nGLOBAL(int)\njpeg_quality_scaling (int quality)\n/* Convert a user-specified quality rating to a percentage scaling factor\n * for an underlying quantization table, using our recommended scaling curve.\n * The input 'quality' factor should be 0 (terrible) to 100 (very good).\n */\n{\n  /* Safety limit on quality factor.  Convert 0 to 1 to avoid zero divide. */\n  if (quality <= 0) quality = 1;\n  if (quality > 100) quality = 100;\n\n  /* The basic table is used as-is (scaling 100) for a quality of 50.\n   * Qualities 50..100 are converted to scaling percentage 200 - 2*Q;\n   * note that at Q=100 the scaling is 0, which will cause jpeg_add_quant_table\n   * to make all the table entries 1 (hence, minimum quantization loss).\n   * Qualities 1..50 are converted to scaling percentage 5000/Q.\n   */\n  if (quality < 50)\n    quality = 5000 / quality;\n  else\n    quality = 200 - quality*2;\n\n  return quality;\n}\n\n\nGLOBAL(void)\njpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)\n/* Set or change the 'quality' (quantization) setting, using default tables.\n * This is the standard quality-adjusting entry point for typical user\n * interfaces; only those who want detailed control over quantization tables\n * would use the preceding routines directly.\n */\n{\n  /* Convert user 0-100 rating to percentage scaling */\n  quality = jpeg_quality_scaling(quality);\n\n  /* Set up standard quality tables */\n  jpeg_set_linear_quality(cinfo, quality, force_baseline);\n}\n\n\n/*\n * Huffman table setup routines\n */\n\nLOCAL(void)\nadd_huff_table (j_compress_ptr cinfo,\n\t\tJHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)\n/* Define a Huffman table */\n{\n  int nsymbols, len;\n\n  if (*htblptr == NULL)\n    *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);\n\n  /* Copy the number-of-symbols-of-each-code-length counts */\n  MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));\n\n  /* Validate the counts.  We do this here mainly so we can copy the right\n   * number of symbols from the val[] array, without risking marching off\n   * the end of memory.  jchuff.c will do a more thorough test later.\n   */\n  nsymbols = 0;\n  for (len = 1; len <= 16; len++)\n    nsymbols += bits[len];\n  if (nsymbols < 1 || nsymbols > 256)\n    ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n\n  MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));\n\n  /* Initialize sent_table FALSE so table will be written to JPEG file. */\n  (*htblptr)->sent_table = FALSE;\n}\n\n\nLOCAL(void)\nstd_huff_tables (j_compress_ptr cinfo)\n/* Set up the standard Huffman tables (cf. JPEG standard section K.3) */\n/* IMPORTANT: these are only valid for 8-bit data precision! */\n{\n  static const UINT8 bits_dc_luminance[17] =\n    { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };\n  static const UINT8 val_dc_luminance[] =\n    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };\n  \n  static const UINT8 bits_dc_chrominance[17] =\n    { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };\n  static const UINT8 val_dc_chrominance[] =\n    { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };\n  \n  static const UINT8 bits_ac_luminance[17] =\n    { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };\n  static const UINT8 val_ac_luminance[] =\n    { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,\n      0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,\n      0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,\n      0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,\n      0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,\n      0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,\n      0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,\n      0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,\n      0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,\n      0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,\n      0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,\n      0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,\n      0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,\n      0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n      0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,\n      0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,\n      0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,\n      0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,\n      0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,\n      0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,\n      0xf9, 0xfa };\n  \n  static const UINT8 bits_ac_chrominance[17] =\n    { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };\n  static const UINT8 val_ac_chrominance[] =\n    { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,\n      0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,\n      0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,\n      0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,\n      0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,\n      0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,\n      0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,\n      0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,\n      0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,\n      0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,\n      0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,\n      0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n      0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,\n      0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,\n      0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,\n      0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,\n      0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,\n      0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,\n      0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,\n      0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,\n      0xf9, 0xfa };\n  \n  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],\n\t\t bits_dc_luminance, val_dc_luminance);\n  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],\n\t\t bits_ac_luminance, val_ac_luminance);\n  add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],\n\t\t bits_dc_chrominance, val_dc_chrominance);\n  add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],\n\t\t bits_ac_chrominance, val_ac_chrominance);\n}\n\n\n/*\n * Default parameter setup for compression.\n *\n * Applications that don't choose to use this routine must do their\n * own setup of all these parameters.  Alternately, you can call this\n * to establish defaults and then alter parameters selectively.  This\n * is the recommended approach since, if we add any new parameters,\n * your code will still work (they'll be set to reasonable defaults).\n */\n\nGLOBAL(void)\njpeg_set_defaults (j_compress_ptr cinfo)\n{\n  int i;\n\n  /* Safety check to ensure start_compress not called yet. */\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  /* Allocate comp_info array large enough for maximum component count.\n   * Array is made permanent in case application wants to compress\n   * multiple images at same param settings.\n   */\n  if (cinfo->comp_info == NULL)\n    cinfo->comp_info = (jpeg_component_info *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  MAX_COMPONENTS * SIZEOF(jpeg_component_info));\n\n  /* Initialize everything not dependent on the color space */\n\n  cinfo->scale_num = 1;\t\t/* 1:1 scaling */\n  cinfo->scale_denom = 1;\n  cinfo->data_precision = BITS_IN_JSAMPLE;\n  /* Set up two quantization tables using default quality of 75 */\n  jpeg_set_quality(cinfo, 75, TRUE);\n  /* Set up two Huffman tables */\n  std_huff_tables(cinfo);\n\n  /* Initialize default arithmetic coding conditioning */\n  for (i = 0; i < NUM_ARITH_TBLS; i++) {\n    cinfo->arith_dc_L[i] = 0;\n    cinfo->arith_dc_U[i] = 1;\n    cinfo->arith_ac_K[i] = 5;\n  }\n\n  /* Default is no multiple-scan output */\n  cinfo->scan_info = NULL;\n  cinfo->num_scans = 0;\n\n  /* Expect normal source image, not raw downsampled data */\n  cinfo->raw_data_in = FALSE;\n\n  /* The standard Huffman tables are only valid for 8-bit data precision.\n   * If the precision is higher, use arithmetic coding.\n   * (Alternatively, using Huffman coding would be possible with forcing\n   * optimization on so that usable tables will be computed, or by\n   * supplying default tables that are valid for the desired precision.)\n   * Otherwise, use Huffman coding by default.\n   */\n  cinfo->arith_code = cinfo->data_precision > 8 ? TRUE : FALSE;\n\n  /* By default, don't do extra passes to optimize entropy coding */\n  cinfo->optimize_coding = FALSE;\n\n  /* By default, use the simpler non-cosited sampling alignment */\n  cinfo->CCIR601_sampling = FALSE;\n\n  /* By default, apply fancy downsampling */\n  cinfo->do_fancy_downsampling = TRUE;\n\n  /* No input smoothing */\n  cinfo->smoothing_factor = 0;\n\n  /* DCT algorithm preference */\n  cinfo->dct_method = JDCT_DEFAULT;\n\n  /* No restart markers */\n  cinfo->restart_interval = 0;\n  cinfo->restart_in_rows = 0;\n\n  /* Fill in default JFIF marker parameters.  Note that whether the marker\n   * will actually be written is determined by jpeg_set_colorspace.\n   *\n   * By default, the library emits JFIF version code 1.01.\n   * An application that wants to emit JFIF 1.02 extension markers should set\n   * JFIF_minor_version to 2.  We could probably get away with just defaulting\n   * to 1.02, but there may still be some decoders in use that will complain\n   * about that; saying 1.01 should minimize compatibility problems.\n   *\n   * For wide gamut colorspaces (BG_RGB and BG_YCC), the major version will be\n   * overridden by jpeg_set_colorspace and set to 2.\n   */\n  cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */\n  cinfo->JFIF_minor_version = 1;\n  cinfo->density_unit = 0;\t/* Pixel size is unknown by default */\n  cinfo->X_density = 1;\t\t/* Pixel aspect ratio is square by default */\n  cinfo->Y_density = 1;\n\n  /* No color transform */\n  cinfo->color_transform = JCT_NONE;\n\n  /* Choose JPEG colorspace based on input space, set defaults accordingly */\n\n  jpeg_default_colorspace(cinfo);\n}\n\n\n/*\n * Select an appropriate JPEG colorspace for in_color_space.\n */\n\nGLOBAL(void)\njpeg_default_colorspace (j_compress_ptr cinfo)\n{\n  switch (cinfo->in_color_space) {\n  case JCS_UNKNOWN:\n    jpeg_set_colorspace(cinfo, JCS_UNKNOWN);\n    break;\n  case JCS_GRAYSCALE:\n    jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);\n    break;\n  case JCS_RGB:\n    jpeg_set_colorspace(cinfo, JCS_YCbCr);\n    break;\n  case JCS_YCbCr:\n    jpeg_set_colorspace(cinfo, JCS_YCbCr);\n    break;\n  case JCS_CMYK:\n    jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */\n    break;\n  case JCS_YCCK:\n    jpeg_set_colorspace(cinfo, JCS_YCCK);\n    break;\n  case JCS_BG_RGB:\n    /* No translation for now -- conversion to BG_YCC not yet supportet */\n    jpeg_set_colorspace(cinfo, JCS_BG_RGB);\n    break;\n  case JCS_BG_YCC:\n    jpeg_set_colorspace(cinfo, JCS_BG_YCC);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);\n  }\n}\n\n\n/*\n * Set the JPEG colorspace, and choose colorspace-dependent default values.\n */\n\nGLOBAL(void)\njpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)\n{\n  jpeg_component_info * compptr;\n  int ci;\n\n#define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl)  \\\n  (compptr = &cinfo->comp_info[index], \\\n   compptr->component_id = (id), \\\n   compptr->h_samp_factor = (hsamp), \\\n   compptr->v_samp_factor = (vsamp), \\\n   compptr->quant_tbl_no = (quant), \\\n   compptr->dc_tbl_no = (dctbl), \\\n   compptr->ac_tbl_no = (actbl) )\n\n  /* Safety check to ensure start_compress not called yet. */\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  /* For all colorspaces, we use Q and Huff tables 0 for luminance components,\n   * tables 1 for chrominance components.\n   */\n\n  cinfo->jpeg_color_space = colorspace;\n\n  cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */\n  cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */\n\n  switch (colorspace) {\n  case JCS_UNKNOWN:\n    cinfo->num_components = cinfo->input_components;\n    if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)\n      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,\n\t       MAX_COMPONENTS);\n    for (ci = 0; ci < cinfo->num_components; ci++) {\n      SET_COMP(ci, ci, 1,1, 0, 0,0);\n    }\n    break;\n  case JCS_GRAYSCALE:\n    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */\n    cinfo->num_components = 1;\n    /* JFIF specifies component ID 1 */\n    SET_COMP(0, 0x01, 1,1, 0, 0,0);\n    break;\n  case JCS_RGB:\n    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */\n    cinfo->num_components = 3;\n    SET_COMP(0, 0x52 /* 'R' */, 1,1, 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);\n    SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);\n    SET_COMP(2, 0x42 /* 'B' */, 1,1, 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);\n    break;\n  case JCS_YCbCr:\n    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */\n    cinfo->num_components = 3;\n    /* JFIF specifies component IDs 1,2,3 */\n    /* We default to 2x2 subsamples of chrominance */\n    SET_COMP(0, 0x01, 2,2, 0, 0,0);\n    SET_COMP(1, 0x02, 1,1, 1, 1,1);\n    SET_COMP(2, 0x03, 1,1, 1, 1,1);\n    break;\n  case JCS_CMYK:\n    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */\n    cinfo->num_components = 4;\n    SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);\n    SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);\n    SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);\n    SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);\n    break;\n  case JCS_YCCK:\n    cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */\n    cinfo->num_components = 4;\n    SET_COMP(0, 0x01, 2,2, 0, 0,0);\n    SET_COMP(1, 0x02, 1,1, 1, 1,1);\n    SET_COMP(2, 0x03, 1,1, 1, 1,1);\n    SET_COMP(3, 0x04, 2,2, 0, 0,0);\n    break;\n  case JCS_BG_RGB:\n    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */\n    cinfo->JFIF_major_version = 2;   /* Set JFIF major version = 2 */\n    cinfo->num_components = 3;\n    /* Add offset 0x20 to the normal R/G/B component IDs */\n    SET_COMP(0, 0x72 /* 'r' */, 1,1, 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);\n    SET_COMP(1, 0x67 /* 'g' */, 1,1, 0, 0,0);\n    SET_COMP(2, 0x62 /* 'b' */, 1,1, 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0,\n\t\tcinfo->color_transform == JCT_SUBTRACT_GREEN ? 1 : 0);\n    break;\n  case JCS_BG_YCC:\n    cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */\n    cinfo->JFIF_major_version = 2;   /* Set JFIF major version = 2 */\n    cinfo->num_components = 3;\n    /* Add offset 0x20 to the normal Cb/Cr component IDs */\n    /* We default to 2x2 subsamples of chrominance */\n    SET_COMP(0, 0x01, 2,2, 0, 0,0);\n    SET_COMP(1, 0x22, 1,1, 1, 1,1);\n    SET_COMP(2, 0x23, 1,1, 1, 1,1);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n  }\n}\n\n\n#ifdef C_PROGRESSIVE_SUPPORTED\n\nLOCAL(jpeg_scan_info *)\nfill_a_scan (jpeg_scan_info * scanptr, int ci,\n\t     int Ss, int Se, int Ah, int Al)\n/* Support routine: generate one scan for specified component */\n{\n  scanptr->comps_in_scan = 1;\n  scanptr->component_index[0] = ci;\n  scanptr->Ss = Ss;\n  scanptr->Se = Se;\n  scanptr->Ah = Ah;\n  scanptr->Al = Al;\n  scanptr++;\n  return scanptr;\n}\n\nLOCAL(jpeg_scan_info *)\nfill_scans (jpeg_scan_info * scanptr, int ncomps,\n\t    int Ss, int Se, int Ah, int Al)\n/* Support routine: generate one scan for each component */\n{\n  int ci;\n\n  for (ci = 0; ci < ncomps; ci++) {\n    scanptr->comps_in_scan = 1;\n    scanptr->component_index[0] = ci;\n    scanptr->Ss = Ss;\n    scanptr->Se = Se;\n    scanptr->Ah = Ah;\n    scanptr->Al = Al;\n    scanptr++;\n  }\n  return scanptr;\n}\n\nLOCAL(jpeg_scan_info *)\nfill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)\n/* Support routine: generate interleaved DC scan if possible, else N scans */\n{\n  int ci;\n\n  if (ncomps <= MAX_COMPS_IN_SCAN) {\n    /* Single interleaved DC scan */\n    scanptr->comps_in_scan = ncomps;\n    for (ci = 0; ci < ncomps; ci++)\n      scanptr->component_index[ci] = ci;\n    scanptr->Ss = scanptr->Se = 0;\n    scanptr->Ah = Ah;\n    scanptr->Al = Al;\n    scanptr++;\n  } else {\n    /* Noninterleaved DC scan for each component */\n    scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);\n  }\n  return scanptr;\n}\n\n\n/*\n * Create a recommended progressive-JPEG script.\n * cinfo->num_components and cinfo->jpeg_color_space must be correct.\n */\n\nGLOBAL(void)\njpeg_simple_progression (j_compress_ptr cinfo)\n{\n  int ncomps = cinfo->num_components;\n  int nscans;\n  jpeg_scan_info * scanptr;\n\n  /* Safety check to ensure start_compress not called yet. */\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  /* Figure space needed for script.  Calculation must match code below! */\n  if (ncomps == 3 &&\n      (cinfo->jpeg_color_space == JCS_YCbCr ||\n       cinfo->jpeg_color_space == JCS_BG_YCC)) {\n    /* Custom script for YCC color images. */\n    nscans = 10;\n  } else {\n    /* All-purpose script for other color spaces. */\n    if (ncomps > MAX_COMPS_IN_SCAN)\n      nscans = 6 * ncomps;\t/* 2 DC + 4 AC scans per component */\n    else\n      nscans = 2 + 4 * ncomps;\t/* 2 DC scans; 4 AC scans per component */\n  }\n\n  /* Allocate space for script.\n   * We need to put it in the permanent pool in case the application performs\n   * multiple compressions without changing the settings.  To avoid a memory\n   * leak if jpeg_simple_progression is called repeatedly for the same JPEG\n   * object, we try to re-use previously allocated space, and we allocate\n   * enough space to handle YCC even if initially asked for grayscale.\n   */\n  if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {\n    cinfo->script_space_size = MAX(nscans, 10);\n    cinfo->script_space = (jpeg_scan_info *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\tcinfo->script_space_size * SIZEOF(jpeg_scan_info));\n  }\n  scanptr = cinfo->script_space;\n  cinfo->scan_info = scanptr;\n  cinfo->num_scans = nscans;\n\n  if (ncomps == 3 &&\n      (cinfo->jpeg_color_space == JCS_YCbCr ||\n       cinfo->jpeg_color_space == JCS_BG_YCC)) {\n    /* Custom script for YCC color images. */\n    /* Initial DC scan */\n    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);\n    /* Initial AC scan: get some luma data out in a hurry */\n    scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);\n    /* Chroma data is too small to be worth expending many scans on */\n    scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);\n    scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);\n    /* Complete spectral selection for luma AC */\n    scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);\n    /* Refine next bit of luma AC */\n    scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);\n    /* Finish DC successive approximation */\n    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);\n    /* Finish AC successive approximation */\n    scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);\n    scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);\n    /* Luma bottom bit comes last since it's usually largest scan */\n    scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);\n  } else {\n    /* All-purpose script for other color spaces. */\n    /* Successive approximation first pass */\n    scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);\n    scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);\n    scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);\n    /* Successive approximation second pass */\n    scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);\n    /* Successive approximation final pass */\n    scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);\n    scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);\n  }\n}\n\n#endif /* C_PROGRESSIVE_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcprepct.c",
    "content": "/*\n * jcprepct.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the compression preprocessing controller.\n * This controller manages the color conversion, downsampling,\n * and edge expansion steps.\n *\n * Most of the complexity here is associated with buffering input rows\n * as required by the downsampler.  See the comments at the head of\n * jcsample.c for the downsampler's needs.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* At present, jcsample.c can request context rows only for smoothing.\n * In the future, we might also need context rows for CCIR601 sampling\n * or other more-complex downsampling procedures.  The code to support\n * context rows should be compiled only if needed.\n */\n#ifdef INPUT_SMOOTHING_SUPPORTED\n#define CONTEXT_ROWS_SUPPORTED\n#endif\n\n\n/*\n * For the simple (no-context-row) case, we just need to buffer one\n * row group's worth of pixels for the downsampling step.  At the bottom of\n * the image, we pad to a full row group by replicating the last pixel row.\n * The downsampler's last output row is then replicated if needed to pad\n * out to a full iMCU row.\n *\n * When providing context rows, we must buffer three row groups' worth of\n * pixels.  Three row groups are physically allocated, but the row pointer\n * arrays are made five row groups high, with the extra pointers above and\n * below \"wrapping around\" to point to the last and first real row groups.\n * This allows the downsampler to access the proper context rows.\n * At the top and bottom of the image, we create dummy context rows by\n * copying the first or last real pixel row.  This copying could be avoided\n * by pointer hacking as is done in jdmainct.c, but it doesn't seem worth the\n * trouble on the compression side.\n */\n\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_c_prep_controller pub; /* public fields */\n\n  /* Downsampling input buffer.  This buffer holds color-converted data\n   * until we have enough to do a downsample step.\n   */\n  JSAMPARRAY color_buf[MAX_COMPONENTS];\n\n  JDIMENSION rows_to_go;\t/* counts rows remaining in source image */\n  int next_buf_row;\t\t/* index of next row to store in color_buf */\n\n#ifdef CONTEXT_ROWS_SUPPORTED\t/* only needed for context case */\n  int this_row_group;\t\t/* starting row index of group to process */\n  int next_buf_stop;\t\t/* downsample when we reach this index */\n#endif\n} my_prep_controller;\n\ntypedef my_prep_controller * my_prep_ptr;\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;\n\n  if (pass_mode != JBUF_PASS_THRU)\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n\n  /* Initialize total-height counter for detecting bottom of image */\n  prep->rows_to_go = cinfo->image_height;\n  /* Mark the conversion buffer empty */\n  prep->next_buf_row = 0;\n#ifdef CONTEXT_ROWS_SUPPORTED\n  /* Preset additional state variables for context mode.\n   * These aren't used in non-context mode, so we needn't test which mode.\n   */\n  prep->this_row_group = 0;\n  /* Set next_buf_stop to stop after two row groups have been read in. */\n  prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;\n#endif\n}\n\n\n/*\n * Expand an image vertically from height input_rows to height output_rows,\n * by duplicating the bottom row.\n */\n\nLOCAL(void)\nexpand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,\n\t\t    int input_rows, int output_rows)\n{\n  register int row;\n\n  for (row = input_rows; row < output_rows; row++) {\n    jcopy_sample_rows(image_data, input_rows-1, image_data, row,\n\t\t      1, num_cols);\n  }\n}\n\n\n/*\n * Process some data in the simple no-context case.\n *\n * Preprocessor output data is counted in \"row groups\".  A row group\n * is defined to be v_samp_factor sample rows of each component.\n * Downsampling will produce this much data from each max_v_samp_factor\n * input rows.\n */\n\nMETHODDEF(void)\npre_process_data (j_compress_ptr cinfo,\n\t\t  JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,\n\t\t  JDIMENSION in_rows_avail,\n\t\t  JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,\n\t\t  JDIMENSION out_row_groups_avail)\n{\n  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;\n  int numrows, ci;\n  JDIMENSION inrows;\n  jpeg_component_info * compptr;\n\n  while (*in_row_ctr < in_rows_avail &&\n\t *out_row_group_ctr < out_row_groups_avail) {\n    /* Do color conversion to fill the conversion buffer. */\n    inrows = in_rows_avail - *in_row_ctr;\n    numrows = cinfo->max_v_samp_factor - prep->next_buf_row;\n    numrows = (int) MIN((JDIMENSION) numrows, inrows);\n    (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,\n\t\t\t\t       prep->color_buf,\n\t\t\t\t       (JDIMENSION) prep->next_buf_row,\n\t\t\t\t       numrows);\n    *in_row_ctr += numrows;\n    prep->next_buf_row += numrows;\n    prep->rows_to_go -= numrows;\n    /* If at bottom of image, pad to fill the conversion buffer. */\n    if (prep->rows_to_go == 0 &&\n\tprep->next_buf_row < cinfo->max_v_samp_factor) {\n      for (ci = 0; ci < cinfo->num_components; ci++) {\n\texpand_bottom_edge(prep->color_buf[ci], cinfo->image_width,\n\t\t\t   prep->next_buf_row, cinfo->max_v_samp_factor);\n      }\n      prep->next_buf_row = cinfo->max_v_samp_factor;\n    }\n    /* If we've filled the conversion buffer, empty it. */\n    if (prep->next_buf_row == cinfo->max_v_samp_factor) {\n      (*cinfo->downsample->downsample) (cinfo,\n\t\t\t\t\tprep->color_buf, (JDIMENSION) 0,\n\t\t\t\t\toutput_buf, *out_row_group_ctr);\n      prep->next_buf_row = 0;\n      (*out_row_group_ctr)++;\n    }\n    /* If at bottom of image, pad the output to a full iMCU height.\n     * Note we assume the caller is providing a one-iMCU-height output buffer!\n     */\n    if (prep->rows_to_go == 0 &&\n\t*out_row_group_ctr < out_row_groups_avail) {\n      for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t   ci++, compptr++) {\n\tnumrows = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n\t\t  cinfo->min_DCT_v_scaled_size;\n\texpand_bottom_edge(output_buf[ci],\n\t\t\t   compptr->width_in_blocks * compptr->DCT_h_scaled_size,\n\t\t\t   (int) (*out_row_group_ctr * numrows),\n\t\t\t   (int) (out_row_groups_avail * numrows));\n      }\n      *out_row_group_ctr = out_row_groups_avail;\n      break;\t\t\t/* can exit outer loop without test */\n    }\n  }\n}\n\n\n#ifdef CONTEXT_ROWS_SUPPORTED\n\n/*\n * Process some data in the context case.\n */\n\nMETHODDEF(void)\npre_process_context (j_compress_ptr cinfo,\n\t\t     JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,\n\t\t     JDIMENSION in_rows_avail,\n\t\t     JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,\n\t\t     JDIMENSION out_row_groups_avail)\n{\n  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;\n  int numrows, ci;\n  int buf_height = cinfo->max_v_samp_factor * 3;\n  JDIMENSION inrows;\n\n  while (*out_row_group_ctr < out_row_groups_avail) {\n    if (*in_row_ctr < in_rows_avail) {\n      /* Do color conversion to fill the conversion buffer. */\n      inrows = in_rows_avail - *in_row_ctr;\n      numrows = prep->next_buf_stop - prep->next_buf_row;\n      numrows = (int) MIN((JDIMENSION) numrows, inrows);\n      (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,\n\t\t\t\t\t prep->color_buf,\n\t\t\t\t\t (JDIMENSION) prep->next_buf_row,\n\t\t\t\t\t numrows);\n      /* Pad at top of image, if first time through */\n      if (prep->rows_to_go == cinfo->image_height) {\n\tfor (ci = 0; ci < cinfo->num_components; ci++) {\n\t  int row;\n\t  for (row = 1; row <= cinfo->max_v_samp_factor; row++) {\n\t    jcopy_sample_rows(prep->color_buf[ci], 0,\n\t\t\t      prep->color_buf[ci], -row,\n\t\t\t      1, cinfo->image_width);\n\t  }\n\t}\n      }\n      *in_row_ctr += numrows;\n      prep->next_buf_row += numrows;\n      prep->rows_to_go -= numrows;\n    } else {\n      /* Return for more data, unless we are at the bottom of the image. */\n      if (prep->rows_to_go != 0)\n\tbreak;\n      /* When at bottom of image, pad to fill the conversion buffer. */\n      if (prep->next_buf_row < prep->next_buf_stop) {\n\tfor (ci = 0; ci < cinfo->num_components; ci++) {\n\t  expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,\n\t\t\t     prep->next_buf_row, prep->next_buf_stop);\n\t}\n\tprep->next_buf_row = prep->next_buf_stop;\n      }\n    }\n    /* If we've gotten enough data, downsample a row group. */\n    if (prep->next_buf_row == prep->next_buf_stop) {\n      (*cinfo->downsample->downsample) (cinfo,\n\t\t\t\t\tprep->color_buf,\n\t\t\t\t\t(JDIMENSION) prep->this_row_group,\n\t\t\t\t\toutput_buf, *out_row_group_ctr);\n      (*out_row_group_ctr)++;\n      /* Advance pointers with wraparound as necessary. */\n      prep->this_row_group += cinfo->max_v_samp_factor;\n      if (prep->this_row_group >= buf_height)\n\tprep->this_row_group = 0;\n      if (prep->next_buf_row >= buf_height)\n\tprep->next_buf_row = 0;\n      prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;\n    }\n  }\n}\n\n\n/*\n * Create the wrapped-around downsampling input buffer needed for context mode.\n */\n\nLOCAL(void)\ncreate_context_buffer (j_compress_ptr cinfo)\n{\n  my_prep_ptr prep = (my_prep_ptr) cinfo->prep;\n  int rgroup_height = cinfo->max_v_samp_factor;\n  int ci, i;\n  jpeg_component_info * compptr;\n  JSAMPARRAY true_buffer, fake_buffer;\n\n  /* Grab enough space for fake row pointers for all the components;\n   * we need five row groups' worth of pointers for each component.\n   */\n  fake_buffer = (JSAMPARRAY)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(cinfo->num_components * 5 * rgroup_height) *\n\t\t\t\tSIZEOF(JSAMPROW));\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Allocate the actual buffer space (3 row groups) for this component.\n     * We make the buffer wide enough to allow the downsampler to edge-expand\n     * horizontally within the buffer, if it so chooses.\n     */\n    true_buffer = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) (((long) compptr->width_in_blocks *\n\t\t      cinfo->min_DCT_h_scaled_size *\n\t\t      cinfo->max_h_samp_factor) / compptr->h_samp_factor),\n       (JDIMENSION) (3 * rgroup_height));\n    /* Copy true buffer row pointers into the middle of the fake row array */\n    MEMCOPY(fake_buffer + rgroup_height, true_buffer,\n\t    3 * rgroup_height * SIZEOF(JSAMPROW));\n    /* Fill in the above and below wraparound pointers */\n    for (i = 0; i < rgroup_height; i++) {\n      fake_buffer[i] = true_buffer[2 * rgroup_height + i];\n      fake_buffer[4 * rgroup_height + i] = true_buffer[i];\n    }\n    prep->color_buf[ci] = fake_buffer + rgroup_height;\n    fake_buffer += 5 * rgroup_height; /* point to space for next component */\n  }\n}\n\n#endif /* CONTEXT_ROWS_SUPPORTED */\n\n\n/*\n * Initialize preprocessing controller.\n */\n\nGLOBAL(void)\njinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)\n{\n  my_prep_ptr prep;\n  int ci;\n  jpeg_component_info * compptr;\n\n  if (need_full_buffer)\t\t/* safety check */\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n\n  prep = (my_prep_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_prep_controller));\n  cinfo->prep = (struct jpeg_c_prep_controller *) prep;\n  prep->pub.start_pass = start_pass_prep;\n\n  /* Allocate the color conversion buffer.\n   * We make the buffer wide enough to allow the downsampler to edge-expand\n   * horizontally within the buffer, if it so chooses.\n   */\n  if (cinfo->downsample->need_context_rows) {\n    /* Set up to provide context rows */\n#ifdef CONTEXT_ROWS_SUPPORTED\n    prep->pub.pre_process_data = pre_process_context;\n    create_context_buffer(cinfo);\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n  } else {\n    /* No context, just make it tall enough for one row group */\n    prep->pub.pre_process_data = pre_process_data;\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t (JDIMENSION) (((long) compptr->width_in_blocks *\n\t\t\tcinfo->min_DCT_h_scaled_size *\n\t\t\tcinfo->max_h_samp_factor) / compptr->h_samp_factor),\n\t (JDIMENSION) cinfo->max_v_samp_factor);\n    }\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jcsample.c",
    "content": "/*\n * jcsample.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains downsampling routines.\n *\n * Downsampling input data is counted in \"row groups\".  A row group\n * is defined to be max_v_samp_factor pixel rows of each component,\n * from which the downsampler produces v_samp_factor sample rows.\n * A single row group is processed in each call to the downsampler module.\n *\n * The downsampler is responsible for edge-expansion of its output data\n * to fill an integral number of DCT blocks horizontally.  The source buffer\n * may be modified if it is helpful for this purpose (the source buffer is\n * allocated wide enough to correspond to the desired output width).\n * The caller (the prep controller) is responsible for vertical padding.\n *\n * The downsampler may request \"context rows\" by setting need_context_rows\n * during startup.  In this case, the input arrays will contain at least\n * one row group's worth of pixels above and below the passed-in data;\n * the caller will create dummy rows at image top and bottom by replicating\n * the first or last real pixel row.\n *\n * An excellent reference for image resampling is\n *   Digital Image Warping, George Wolberg, 1990.\n *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.\n *\n * The downsampling algorithm used here is a simple average of the source\n * pixels covered by the output pixel.  The hi-falutin sampling literature\n * refers to this as a \"box filter\".  In general the characteristics of a box\n * filter are not very good, but for the specific cases we normally use (1:1\n * and 2:1 ratios) the box is equivalent to a \"triangle filter\" which is not\n * nearly so bad.  If you intend to use other sampling ratios, you'd be well\n * advised to improve this code.\n *\n * A simple input-smoothing capability is provided.  This is mainly intended\n * for cleaning up color-dithered GIF input files (if you find it inadequate,\n * we suggest using an external filtering program such as pnmconvol).  When\n * enabled, each input pixel P is replaced by a weighted sum of itself and its\n * eight neighbors.  P's weight is 1-8*SF and each neighbor's weight is SF,\n * where SF = (smoothing_factor / 1024).\n * Currently, smoothing is only supported for 2h2v sampling factors.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Pointer to routine to downsample a single component */\ntypedef JMETHOD(void, downsample1_ptr,\n\t\t(j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JSAMPARRAY input_data, JSAMPARRAY output_data));\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_downsampler pub;\t/* public fields */\n\n  /* Downsampling method pointers, one per component */\n  downsample1_ptr methods[MAX_COMPONENTS];\n\n  /* Height of an output row group for each component. */\n  int rowgroup_height[MAX_COMPONENTS];\n\n  /* These arrays save pixel expansion factors so that int_downsample need not\n   * recompute them each time.  They are unused for other downsampling methods.\n   */\n  UINT8 h_expand[MAX_COMPONENTS];\n  UINT8 v_expand[MAX_COMPONENTS];\n} my_downsampler;\n\ntypedef my_downsampler * my_downsample_ptr;\n\n\n/*\n * Initialize for a downsampling pass.\n */\n\nMETHODDEF(void)\nstart_pass_downsample (j_compress_ptr cinfo)\n{\n  /* no work for now */\n}\n\n\n/*\n * Expand a component horizontally from width input_cols to width output_cols,\n * by duplicating the rightmost samples.\n */\n\nLOCAL(void)\nexpand_right_edge (JSAMPARRAY image_data, int num_rows,\n\t\t   JDIMENSION input_cols, JDIMENSION output_cols)\n{\n  register JSAMPROW ptr;\n  register JSAMPLE pixval;\n  register int count;\n  int row;\n  int numcols = (int) (output_cols - input_cols);\n\n  if (numcols > 0) {\n    for (row = 0; row < num_rows; row++) {\n      ptr = image_data[row] + input_cols;\n      pixval = ptr[-1];\t\t/* don't need GETJSAMPLE() here */\n      for (count = numcols; count > 0; count--)\n\t*ptr++ = pixval;\n    }\n  }\n}\n\n\n/*\n * Do downsampling for a whole row group (all components).\n *\n * In this version we simply downsample each component independently.\n */\n\nMETHODDEF(void)\nsep_downsample (j_compress_ptr cinfo,\n\t\tJSAMPIMAGE input_buf, JDIMENSION in_row_index,\n\t\tJSAMPIMAGE output_buf, JDIMENSION out_row_group_index)\n{\n  my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;\n  int ci;\n  jpeg_component_info * compptr;\n  JSAMPARRAY in_ptr, out_ptr;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    in_ptr = input_buf[ci] + in_row_index;\n    out_ptr = output_buf[ci] +\n\t      (out_row_group_index * downsample->rowgroup_height[ci]);\n    (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);\n  }\n}\n\n\n/*\n * Downsample pixel values of a single component.\n * One row group is processed per call.\n * This version handles arbitrary integral sampling ratios, without smoothing.\n * Note that this version is not actually used for customary sampling ratios.\n */\n\nMETHODDEF(void)\nint_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;\n  int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;\n  JDIMENSION outcol, outcol_h;\t/* outcol_h == outcol*h_expand */\n  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;\n  JSAMPROW inptr, outptr;\n  INT32 outvalue;\n\n  h_expand = downsample->h_expand[compptr->component_index];\n  v_expand = downsample->v_expand[compptr->component_index];\n  numpix = h_expand * v_expand;\n  numpix2 = numpix/2;\n\n  /* Expand input data enough to let all the output samples be generated\n   * by the standard loop.  Special-casing padded output would be more\n   * efficient.\n   */\n  expand_right_edge(input_data, cinfo->max_v_samp_factor,\n\t\t    cinfo->image_width, output_cols * h_expand);\n\n  inrow = outrow = 0;\n  while (inrow < cinfo->max_v_samp_factor) {\n    outptr = output_data[outrow];\n    for (outcol = 0, outcol_h = 0; outcol < output_cols;\n\t outcol++, outcol_h += h_expand) {\n      outvalue = 0;\n      for (v = 0; v < v_expand; v++) {\n\tinptr = input_data[inrow+v] + outcol_h;\n\tfor (h = 0; h < h_expand; h++) {\n\t  outvalue += (INT32) GETJSAMPLE(*inptr++);\n\t}\n      }\n      *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);\n    }\n    inrow += v_expand;\n    outrow++;\n  }\n}\n\n\n/*\n * Downsample pixel values of a single component.\n * This version handles the special case of a full-size component,\n * without smoothing.\n */\n\nMETHODDEF(void)\nfullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t     JSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  /* Copy the data */\n  jcopy_sample_rows(input_data, 0, output_data, 0,\n\t\t    cinfo->max_v_samp_factor, cinfo->image_width);\n  /* Edge-expand */\n  expand_right_edge(output_data, cinfo->max_v_samp_factor, cinfo->image_width,\n\t\t    compptr->width_in_blocks * compptr->DCT_h_scaled_size);\n}\n\n\n/*\n * Downsample pixel values of a single component.\n * This version handles the common case of 2:1 horizontal and 1:1 vertical,\n * without smoothing.\n *\n * A note about the \"bias\" calculations: when rounding fractional values to\n * integer, we do not want to always round 0.5 up to the next integer.\n * If we did that, we'd introduce a noticeable bias towards larger values.\n * Instead, this code is arranged so that 0.5 will be rounded up or down at\n * alternate pixel locations (a simple ordered dither pattern).\n */\n\nMETHODDEF(void)\nh2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  int inrow;\n  JDIMENSION outcol;\n  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;\n  register JSAMPROW inptr, outptr;\n  register int bias;\n\n  /* Expand input data enough to let all the output samples be generated\n   * by the standard loop.  Special-casing padded output would be more\n   * efficient.\n   */\n  expand_right_edge(input_data, cinfo->max_v_samp_factor,\n\t\t    cinfo->image_width, output_cols * 2);\n\n  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {\n    outptr = output_data[inrow];\n    inptr = input_data[inrow];\n    bias = 0;\t\t\t/* bias = 0,1,0,1,... for successive samples */\n    for (outcol = 0; outcol < output_cols; outcol++) {\n      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])\n\t\t\t      + bias) >> 1);\n      bias ^= 1;\t\t/* 0=>1, 1=>0 */\n      inptr += 2;\n    }\n  }\n}\n\n\n/*\n * Downsample pixel values of a single component.\n * This version handles the standard case of 2:1 horizontal and 2:1 vertical,\n * without smoothing.\n */\n\nMETHODDEF(void)\nh2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  int inrow, outrow;\n  JDIMENSION outcol;\n  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;\n  register JSAMPROW inptr0, inptr1, outptr;\n  register int bias;\n\n  /* Expand input data enough to let all the output samples be generated\n   * by the standard loop.  Special-casing padded output would be more\n   * efficient.\n   */\n  expand_right_edge(input_data, cinfo->max_v_samp_factor,\n\t\t    cinfo->image_width, output_cols * 2);\n\n  inrow = outrow = 0;\n  while (inrow < cinfo->max_v_samp_factor) {\n    outptr = output_data[outrow];\n    inptr0 = input_data[inrow];\n    inptr1 = input_data[inrow+1];\n    bias = 1;\t\t\t/* bias = 1,2,1,2,... for successive samples */\n    for (outcol = 0; outcol < output_cols; outcol++) {\n      *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +\n\t\t\t      GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])\n\t\t\t      + bias) >> 2);\n      bias ^= 3;\t\t/* 1=>2, 2=>1 */\n      inptr0 += 2; inptr1 += 2;\n    }\n    inrow += 2;\n    outrow++;\n  }\n}\n\n\n#ifdef INPUT_SMOOTHING_SUPPORTED\n\n/*\n * Downsample pixel values of a single component.\n * This version handles the standard case of 2:1 horizontal and 2:1 vertical,\n * with smoothing.  One row of context is required.\n */\n\nMETHODDEF(void)\nh2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t\tJSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  int inrow, outrow;\n  JDIMENSION colctr;\n  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;\n  register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;\n  INT32 membersum, neighsum, memberscale, neighscale;\n\n  /* Expand input data enough to let all the output samples be generated\n   * by the standard loop.  Special-casing padded output would be more\n   * efficient.\n   */\n  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,\n\t\t    cinfo->image_width, output_cols * 2);\n\n  /* We don't bother to form the individual \"smoothed\" input pixel values;\n   * we can directly compute the output which is the average of the four\n   * smoothed values.  Each of the four member pixels contributes a fraction\n   * (1-8*SF) to its own smoothed image and a fraction SF to each of the three\n   * other smoothed pixels, therefore a total fraction (1-5*SF)/4 to the final\n   * output.  The four corner-adjacent neighbor pixels contribute a fraction\n   * SF to just one smoothed pixel, or SF/4 to the final output; while the\n   * eight edge-adjacent neighbors contribute SF to each of two smoothed\n   * pixels, or SF/2 overall.  In order to use integer arithmetic, these\n   * factors are scaled by 2^16 = 65536.\n   * Also recall that SF = smoothing_factor / 1024.\n   */\n\n  memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */\n  neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */\n\n  inrow = outrow = 0;\n  while (inrow < cinfo->max_v_samp_factor) {\n    outptr = output_data[outrow];\n    inptr0 = input_data[inrow];\n    inptr1 = input_data[inrow+1];\n    above_ptr = input_data[inrow-1];\n    below_ptr = input_data[inrow+2];\n\n    /* Special case for first column: pretend column -1 is same as column 0 */\n    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +\n\t\tGETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);\n    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +\n\t       GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +\n\t       GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +\n\t       GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);\n    neighsum += neighsum;\n    neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +\n\t\tGETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);\n    membersum = membersum * memberscale + neighsum * neighscale;\n    *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);\n    inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;\n\n    for (colctr = output_cols - 2; colctr > 0; colctr--) {\n      /* sum of pixels directly mapped to this output element */\n      membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +\n\t\t  GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);\n      /* sum of edge-neighbor pixels */\n      neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +\n\t\t GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +\n\t\t GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +\n\t\t GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);\n      /* The edge-neighbors count twice as much as corner-neighbors */\n      neighsum += neighsum;\n      /* Add in the corner-neighbors */\n      neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +\n\t\t  GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);\n      /* form final output scaled up by 2^16 */\n      membersum = membersum * memberscale + neighsum * neighscale;\n      /* round, descale and output it */\n      *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);\n      inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;\n    }\n\n    /* Special case for last column */\n    membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +\n\t\tGETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);\n    neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +\n\t       GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +\n\t       GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +\n\t       GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);\n    neighsum += neighsum;\n    neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +\n\t\tGETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);\n    membersum = membersum * memberscale + neighsum * neighscale;\n    *outptr = (JSAMPLE) ((membersum + 32768) >> 16);\n\n    inrow += 2;\n    outrow++;\n  }\n}\n\n\n/*\n * Downsample pixel values of a single component.\n * This version handles the special case of a full-size component,\n * with smoothing.  One row of context is required.\n */\n\nMETHODDEF(void)\nfullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,\n\t\t\t    JSAMPARRAY input_data, JSAMPARRAY output_data)\n{\n  int inrow;\n  JDIMENSION colctr;\n  JDIMENSION output_cols = compptr->width_in_blocks * compptr->DCT_h_scaled_size;\n  register JSAMPROW inptr, above_ptr, below_ptr, outptr;\n  INT32 membersum, neighsum, memberscale, neighscale;\n  int colsum, lastcolsum, nextcolsum;\n\n  /* Expand input data enough to let all the output samples be generated\n   * by the standard loop.  Special-casing padded output would be more\n   * efficient.\n   */\n  expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,\n\t\t    cinfo->image_width, output_cols);\n\n  /* Each of the eight neighbor pixels contributes a fraction SF to the\n   * smoothed pixel, while the main pixel contributes (1-8*SF).  In order\n   * to use integer arithmetic, these factors are multiplied by 2^16 = 65536.\n   * Also recall that SF = smoothing_factor / 1024.\n   */\n\n  memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */\n  neighscale = cinfo->smoothing_factor * 64; /* scaled SF */\n\n  for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {\n    outptr = output_data[inrow];\n    inptr = input_data[inrow];\n    above_ptr = input_data[inrow-1];\n    below_ptr = input_data[inrow+1];\n\n    /* Special case for first column */\n    colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +\n\t     GETJSAMPLE(*inptr);\n    membersum = GETJSAMPLE(*inptr++);\n    nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +\n\t\t GETJSAMPLE(*inptr);\n    neighsum = colsum + (colsum - membersum) + nextcolsum;\n    membersum = membersum * memberscale + neighsum * neighscale;\n    *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);\n    lastcolsum = colsum; colsum = nextcolsum;\n\n    for (colctr = output_cols - 2; colctr > 0; colctr--) {\n      membersum = GETJSAMPLE(*inptr++);\n      above_ptr++; below_ptr++;\n      nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +\n\t\t   GETJSAMPLE(*inptr);\n      neighsum = lastcolsum + (colsum - membersum) + nextcolsum;\n      membersum = membersum * memberscale + neighsum * neighscale;\n      *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);\n      lastcolsum = colsum; colsum = nextcolsum;\n    }\n\n    /* Special case for last column */\n    membersum = GETJSAMPLE(*inptr);\n    neighsum = lastcolsum + (colsum - membersum) + colsum;\n    membersum = membersum * memberscale + neighsum * neighscale;\n    *outptr = (JSAMPLE) ((membersum + 32768) >> 16);\n\n  }\n}\n\n#endif /* INPUT_SMOOTHING_SUPPORTED */\n\n\n/*\n * Module initialization routine for downsampling.\n * Note that we must select a routine for each component.\n */\n\nGLOBAL(void)\njinit_downsampler (j_compress_ptr cinfo)\n{\n  my_downsample_ptr downsample;\n  int ci;\n  jpeg_component_info * compptr;\n  boolean smoothok = TRUE;\n  int h_in_group, v_in_group, h_out_group, v_out_group;\n\n  downsample = (my_downsample_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_downsampler));\n  cinfo->downsample = (struct jpeg_downsampler *) downsample;\n  downsample->pub.start_pass = start_pass_downsample;\n  downsample->pub.downsample = sep_downsample;\n  downsample->pub.need_context_rows = FALSE;\n\n  if (cinfo->CCIR601_sampling)\n    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);\n\n  /* Verify we can handle the sampling factors, and set up method pointers */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Compute size of an \"output group\" for DCT scaling.  This many samples\n     * are to be converted from max_h_samp_factor * max_v_samp_factor pixels.\n     */\n    h_out_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /\n\t\t  cinfo->min_DCT_h_scaled_size;\n    v_out_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n\t\t  cinfo->min_DCT_v_scaled_size;\n    h_in_group = cinfo->max_h_samp_factor;\n    v_in_group = cinfo->max_v_samp_factor;\n    downsample->rowgroup_height[ci] = v_out_group; /* save for use later */\n    if (h_in_group == h_out_group && v_in_group == v_out_group) {\n#ifdef INPUT_SMOOTHING_SUPPORTED\n      if (cinfo->smoothing_factor) {\n\tdownsample->methods[ci] = fullsize_smooth_downsample;\n\tdownsample->pub.need_context_rows = TRUE;\n      } else\n#endif\n\tdownsample->methods[ci] = fullsize_downsample;\n    } else if (h_in_group == h_out_group * 2 &&\n\t       v_in_group == v_out_group) {\n      smoothok = FALSE;\n      downsample->methods[ci] = h2v1_downsample;\n    } else if (h_in_group == h_out_group * 2 &&\n\t       v_in_group == v_out_group * 2) {\n#ifdef INPUT_SMOOTHING_SUPPORTED\n      if (cinfo->smoothing_factor) {\n\tdownsample->methods[ci] = h2v2_smooth_downsample;\n\tdownsample->pub.need_context_rows = TRUE;\n      } else\n#endif\n\tdownsample->methods[ci] = h2v2_downsample;\n    } else if ((h_in_group % h_out_group) == 0 &&\n\t       (v_in_group % v_out_group) == 0) {\n      smoothok = FALSE;\n      downsample->methods[ci] = int_downsample;\n      downsample->h_expand[ci] = (UINT8) (h_in_group / h_out_group);\n      downsample->v_expand[ci] = (UINT8) (v_in_group / v_out_group);\n    } else\n      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);\n  }\n\n#ifdef INPUT_SMOOTHING_SUPPORTED\n  if (cinfo->smoothing_factor && !smoothok)\n    TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);\n#endif\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jctrans.c",
    "content": "/*\n * jctrans.c\n *\n * Copyright (C) 1995-1998, Thomas G. Lane.\n * Modified 2000-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains library routines for transcoding compression,\n * that is, writing raw DCT coefficient arrays to an output JPEG file.\n * The routines in jcapimin.c will also be needed by a transcoder.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Forward declarations */\nLOCAL(void) transencode_master_selection\n\tJPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));\nLOCAL(void) transencode_coef_controller\n\tJPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));\n\n\n/*\n * Compression initialization for writing raw-coefficient data.\n * Before calling this, all parameters and a data destination must be set up.\n * Call jpeg_finish_compress() to actually write the data.\n *\n * The number of passed virtual arrays must match cinfo->num_components.\n * Note that the virtual arrays need not be filled or even realized at\n * the time write_coefficients is called; indeed, if the virtual arrays\n * were requested from this compression object's memory manager, they\n * typically will be realized during this routine and filled afterwards.\n */\n\nGLOBAL(void)\njpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)\n{\n  if (cinfo->global_state != CSTATE_START)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  /* Mark all tables to be written */\n  jpeg_suppress_tables(cinfo, FALSE);\n  /* (Re)initialize error mgr and destination modules */\n  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);\n  (*cinfo->dest->init_destination) (cinfo);\n  /* Perform master selection of active modules */\n  transencode_master_selection(cinfo, coef_arrays);\n  /* Wait for jpeg_finish_compress() call */\n  cinfo->next_scanline = 0;\t/* so jpeg_write_marker works */\n  cinfo->global_state = CSTATE_WRCOEFS;\n}\n\n\n/*\n * Initialize the compression object with default parameters,\n * then copy from the source object all parameters needed for lossless\n * transcoding.  Parameters that can be varied without loss (such as\n * scan script and Huffman optimization) are left in their default states.\n */\n\nGLOBAL(void)\njpeg_copy_critical_parameters (j_decompress_ptr srcinfo,\n\t\t\t       j_compress_ptr dstinfo)\n{\n  JQUANT_TBL ** qtblptr;\n  jpeg_component_info *incomp, *outcomp;\n  JQUANT_TBL *c_quant, *slot_quant;\n  int tblno, ci, coefi;\n\n  /* Safety check to ensure start_compress not called yet. */\n  if (dstinfo->global_state != CSTATE_START)\n    ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);\n  /* Copy fundamental image dimensions */\n  dstinfo->image_width = srcinfo->image_width;\n  dstinfo->image_height = srcinfo->image_height;\n  dstinfo->input_components = srcinfo->num_components;\n  dstinfo->in_color_space = srcinfo->jpeg_color_space;\n  dstinfo->jpeg_width = srcinfo->output_width;\n  dstinfo->jpeg_height = srcinfo->output_height;\n  dstinfo->min_DCT_h_scaled_size = srcinfo->min_DCT_h_scaled_size;\n  dstinfo->min_DCT_v_scaled_size = srcinfo->min_DCT_v_scaled_size;\n  /* Initialize all parameters to default values */\n  jpeg_set_defaults(dstinfo);\n  /* jpeg_set_defaults may choose wrong colorspace, eg YCbCr if input is RGB.\n   * Fix it to get the right header markers for the image colorspace.\n   * Note: Entropy table assignment in jpeg_set_colorspace depends\n   * on color_transform.\n   */\n  dstinfo->color_transform = srcinfo->color_transform;\n  jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);\n  dstinfo->data_precision = srcinfo->data_precision;\n  dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;\n  /* Copy the source's quantization tables. */\n  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {\n    if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {\n      qtblptr = & dstinfo->quant_tbl_ptrs[tblno];\n      if (*qtblptr == NULL)\n\t*qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);\n      MEMCOPY((*qtblptr)->quantval,\n\t      srcinfo->quant_tbl_ptrs[tblno]->quantval,\n\t      SIZEOF((*qtblptr)->quantval));\n      (*qtblptr)->sent_table = FALSE;\n    }\n  }\n  /* Copy the source's per-component info.\n   * Note we assume jpeg_set_defaults has allocated the dest comp_info array.\n   */\n  dstinfo->num_components = srcinfo->num_components;\n  if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)\n    ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,\n\t     MAX_COMPONENTS);\n  for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;\n       ci < dstinfo->num_components; ci++, incomp++, outcomp++) {\n    outcomp->component_id = incomp->component_id;\n    outcomp->h_samp_factor = incomp->h_samp_factor;\n    outcomp->v_samp_factor = incomp->v_samp_factor;\n    outcomp->quant_tbl_no = incomp->quant_tbl_no;\n    /* Make sure saved quantization table for component matches the qtable\n     * slot.  If not, the input file re-used this qtable slot.\n     * IJG encoder currently cannot duplicate this.\n     */\n    tblno = outcomp->quant_tbl_no;\n    if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||\n\tsrcinfo->quant_tbl_ptrs[tblno] == NULL)\n      ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);\n    slot_quant = srcinfo->quant_tbl_ptrs[tblno];\n    c_quant = incomp->quant_table;\n    if (c_quant != NULL) {\n      for (coefi = 0; coefi < DCTSIZE2; coefi++) {\n\tif (c_quant->quantval[coefi] != slot_quant->quantval[coefi])\n\t  ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);\n      }\n    }\n    /* Note: we do not copy the source's entropy table assignments;\n     * instead we rely on jpeg_set_colorspace to have made a suitable choice.\n     */\n  }\n  /* Also copy JFIF version and resolution information, if available.\n   * Strictly speaking this isn't \"critical\" info, but it's nearly\n   * always appropriate to copy it if available.  In particular,\n   * if the application chooses to copy JFIF 1.02 extension markers from\n   * the source file, we need to copy the version to make sure we don't\n   * emit a file that has 1.02 extensions but a claimed version of 1.01.\n   */\n  if (srcinfo->saw_JFIF_marker) {\n    if (srcinfo->JFIF_major_version == 1 ||\n\tsrcinfo->JFIF_major_version == 2) {\n      dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;\n      dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;\n    }\n    dstinfo->density_unit = srcinfo->density_unit;\n    dstinfo->X_density = srcinfo->X_density;\n    dstinfo->Y_density = srcinfo->Y_density;\n  }\n}\n\n\n/*\n * Master selection of compression modules for transcoding.\n * This substitutes for jcinit.c's initialization of the full compressor.\n */\n\nLOCAL(void)\ntransencode_master_selection (j_compress_ptr cinfo,\n\t\t\t      jvirt_barray_ptr * coef_arrays)\n{\n  /* Initialize master control (includes parameter checking/processing) */\n  jinit_c_master_control(cinfo, TRUE /* transcode only */);\n\n  /* Entropy encoding: either Huffman or arithmetic coding. */\n  if (cinfo->arith_code)\n    jinit_arith_encoder(cinfo);\n  else {\n    jinit_huff_encoder(cinfo);\n  }\n\n  /* We need a special coefficient buffer controller. */\n  transencode_coef_controller(cinfo, coef_arrays);\n\n  jinit_marker_writer(cinfo);\n\n  /* We can now tell the memory manager to allocate virtual arrays. */\n  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);\n\n  /* Write the datastream header (SOI, JFIF) immediately.\n   * Frame and scan headers are postponed till later.\n   * This lets application insert special markers after the SOI.\n   */\n  (*cinfo->marker->write_file_header) (cinfo);\n}\n\n\n/*\n * The rest of this file is a special implementation of the coefficient\n * buffer controller.  This is similar to jccoefct.c, but it handles only\n * output from presupplied virtual arrays.  Furthermore, we generate any\n * dummy padding blocks on-the-fly rather than expecting them to be present\n * in the arrays.\n */\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_c_coef_controller pub; /* public fields */\n\n  JDIMENSION iMCU_row_num;\t/* iMCU row # within image */\n  JDIMENSION mcu_ctr;\t\t/* counts MCUs processed in current row */\n  int MCU_vert_offset;\t\t/* counts MCU rows within iMCU row */\n  int MCU_rows_per_iMCU_row;\t/* number of such rows needed */\n\n  /* Virtual block array for each component. */\n  jvirt_barray_ptr * whole_image;\n\n  /* Workspace for constructing dummy blocks at right/bottom edges. */\n  JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];\n} my_coef_controller;\n\ntypedef my_coef_controller * my_coef_ptr;\n\n\nLOCAL(void)\nstart_iMCU_row (j_compress_ptr cinfo)\n/* Reset within-iMCU-row counters for a new row */\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  /* In an interleaved scan, an MCU row is the same as an iMCU row.\n   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.\n   * But at the bottom of the image, process only what's left.\n   */\n  if (cinfo->comps_in_scan > 1) {\n    coef->MCU_rows_per_iMCU_row = 1;\n  } else {\n    if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;\n    else\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;\n  }\n\n  coef->mcu_ctr = 0;\n  coef->MCU_vert_offset = 0;\n}\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  if (pass_mode != JBUF_CRANK_DEST)\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n\n  coef->iMCU_row_num = 0;\n  start_iMCU_row(cinfo);\n}\n\n\n/*\n * Process some data.\n * We process the equivalent of one fully interleaved MCU row (\"iMCU\" row)\n * per call, ie, v_samp_factor block rows for each component in the scan.\n * The data is obtained from the virtual arrays and fed to the entropy coder.\n * Returns TRUE if the iMCU row is completed, FALSE if suspended.\n *\n * NB: input_buf is ignored; it is likely to be a NULL pointer.\n */\n\nMETHODDEF(boolean)\ncompress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION MCU_col_num;\t/* index of current MCU within row */\n  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  int blkn, ci, xindex, yindex, yoffset, blockcnt;\n  JDIMENSION start_col;\n  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];\n  JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];\n  JBLOCKROW buffer_ptr;\n  jpeg_component_info *compptr;\n\n  /* Align the virtual buffers for the components used in this scan. */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    buffer[ci] = (*cinfo->mem->access_virt_barray)\n      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],\n       coef->iMCU_row_num * compptr->v_samp_factor,\n       (JDIMENSION) compptr->v_samp_factor, FALSE);\n  }\n\n  /* Loop to process one whole iMCU row */\n  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\n       yoffset++) {\n    for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;\n\t MCU_col_num++) {\n      /* Construct list of pointers to DCT blocks belonging to this MCU */\n      blkn = 0;\t\t\t/* index of current DCT block within MCU */\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n\tcompptr = cinfo->cur_comp_info[ci];\n\tstart_col = MCU_col_num * compptr->MCU_width;\n\tblockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width\n\t\t\t\t\t\t: compptr->last_col_width;\n\tfor (yindex = 0; yindex < compptr->MCU_height; yindex++) {\n\t  if (coef->iMCU_row_num < last_iMCU_row ||\n\t      yindex+yoffset < compptr->last_row_height) {\n\t    /* Fill in pointers to real blocks in this row */\n\t    buffer_ptr = buffer[ci][yindex+yoffset] + start_col;\n\t    for (xindex = 0; xindex < blockcnt; xindex++)\n\t      MCU_buffer[blkn++] = buffer_ptr++;\n\t  } else {\n\t    /* At bottom of image, need a whole row of dummy blocks */\n\t    xindex = 0;\n\t  }\n\t  /* Fill in any dummy blocks needed in this row.\n\t   * Dummy blocks are filled in the same way as in jccoefct.c:\n\t   * all zeroes in the AC entries, DC entries equal to previous\n\t   * block's DC value.  The init routine has already zeroed the\n\t   * AC entries, so we need only set the DC entries correctly.\n\t   */\n\t  for (; xindex < compptr->MCU_width; xindex++) {\n\t    MCU_buffer[blkn] = coef->dummy_buffer[blkn];\n\t    MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];\n\t    blkn++;\n\t  }\n\t}\n      }\n      /* Try to write the MCU. */\n      if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {\n\t/* Suspension forced; update state counters and exit */\n\tcoef->MCU_vert_offset = yoffset;\n\tcoef->mcu_ctr = MCU_col_num;\n\treturn FALSE;\n      }\n    }\n    /* Completed an MCU row, but perhaps not an iMCU row */\n    coef->mcu_ctr = 0;\n  }\n  /* Completed the iMCU row, advance counters for next one */\n  coef->iMCU_row_num++;\n  start_iMCU_row(cinfo);\n  return TRUE;\n}\n\n\n/*\n * Initialize coefficient buffer controller.\n *\n * Each passed coefficient array must be the right size for that\n * coefficient: width_in_blocks wide and height_in_blocks high,\n * with unitheight at least v_samp_factor.\n */\n\nLOCAL(void)\ntransencode_coef_controller (j_compress_ptr cinfo,\n\t\t\t     jvirt_barray_ptr * coef_arrays)\n{\n  my_coef_ptr coef;\n  JBLOCKROW buffer;\n  int i;\n\n  coef = (my_coef_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_coef_controller));\n  cinfo->coef = &coef->pub;\n  coef->pub.start_pass = start_pass_coef;\n  coef->pub.compress_data = compress_output;\n\n  /* Save pointer to virtual arrays */\n  coef->whole_image = coef_arrays;\n\n  /* Allocate and pre-zero space for dummy DCT blocks. */\n  buffer = (JBLOCKROW)\n    (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tC_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));\n  FMEMZERO((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));\n  for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {\n    coef->dummy_buffer[i] = buffer + i;\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdapimin.c",
    "content": "/*\n * jdapimin.c\n *\n * Copyright (C) 1994-1998, Thomas G. Lane.\n * Modified 2009-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains application interface code for the decompression half\n * of the JPEG library.  These are the \"minimum\" API routines that may be\n * needed in either the normal full-decompression case or the\n * transcoding-only case.\n *\n * Most of the routines intended to be called directly by an application\n * are in this file or in jdapistd.c.  But also see jcomapi.c for routines\n * shared by compression and decompression, and jdtrans.c for the transcoding\n * case.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * Initialization of a JPEG decompression object.\n * The error manager must already be set up (in case memory manager fails).\n */\n\nGLOBAL(void)\njpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)\n{\n  int i;\n\n  /* Guard against version mismatches between library and caller. */\n  cinfo->mem = NULL;\t\t/* so jpeg_destroy knows mem mgr not called */\n  if (version != JPEG_LIB_VERSION)\n    ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);\n  if (structsize != SIZEOF(struct jpeg_decompress_struct))\n    ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE, \n\t     (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);\n\n  /* For debugging purposes, we zero the whole master structure.\n   * But the application has already set the err pointer, and may have set\n   * client_data, so we have to save and restore those fields.\n   * Note: if application hasn't set client_data, tools like Purify may\n   * complain here.\n   */\n  {\n    struct jpeg_error_mgr * err = cinfo->err;\n    void * client_data = cinfo->client_data; /* ignore Purify complaint here */\n    MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));\n    cinfo->err = err;\n    cinfo->client_data = client_data;\n  }\n  cinfo->is_decompressor = TRUE;\n\n  /* Initialize a memory manager instance for this object */\n  jinit_memory_mgr((j_common_ptr) cinfo);\n\n  /* Zero out pointers to permanent structures. */\n  cinfo->progress = NULL;\n  cinfo->src = NULL;\n\n  for (i = 0; i < NUM_QUANT_TBLS; i++)\n    cinfo->quant_tbl_ptrs[i] = NULL;\n\n  for (i = 0; i < NUM_HUFF_TBLS; i++) {\n    cinfo->dc_huff_tbl_ptrs[i] = NULL;\n    cinfo->ac_huff_tbl_ptrs[i] = NULL;\n  }\n\n  /* Initialize marker processor so application can override methods\n   * for COM, APPn markers before calling jpeg_read_header.\n   */\n  cinfo->marker_list = NULL;\n  jinit_marker_reader(cinfo);\n\n  /* And initialize the overall input controller. */\n  jinit_input_controller(cinfo);\n\n  /* OK, I'm ready */\n  cinfo->global_state = DSTATE_START;\n}\n\n\n/*\n * Destruction of a JPEG decompression object\n */\n\nGLOBAL(void)\njpeg_destroy_decompress (j_decompress_ptr cinfo)\n{\n  jpeg_destroy((j_common_ptr) cinfo); /* use common routine */\n}\n\n\n/*\n * Abort processing of a JPEG decompression operation,\n * but don't destroy the object itself.\n */\n\nGLOBAL(void)\njpeg_abort_decompress (j_decompress_ptr cinfo)\n{\n  jpeg_abort((j_common_ptr) cinfo); /* use common routine */\n}\n\n\n/*\n * Set default decompression parameters.\n */\n\nLOCAL(void)\ndefault_decompress_parms (j_decompress_ptr cinfo)\n{\n  int cid0, cid1, cid2;\n\n  /* Guess the input colorspace, and set output colorspace accordingly. */\n  /* Note application may override our guesses. */\n  switch (cinfo->num_components) {\n  case 1:\n    cinfo->jpeg_color_space = JCS_GRAYSCALE;\n    cinfo->out_color_space = JCS_GRAYSCALE;\n    break;\n    \n  case 3:\n    cid0 = cinfo->comp_info[0].component_id;\n    cid1 = cinfo->comp_info[1].component_id;\n    cid2 = cinfo->comp_info[2].component_id;\n\n    /* First try to guess from the component IDs */\n    if      (cid0 == 0x01 && cid1 == 0x02 && cid2 == 0x03)\n      cinfo->jpeg_color_space = JCS_YCbCr;\n    else if (cid0 == 0x01 && cid1 == 0x22 && cid2 == 0x23)\n      cinfo->jpeg_color_space = JCS_BG_YCC;\n    else if (cid0 == 0x52 && cid1 == 0x47 && cid2 == 0x42)\n      cinfo->jpeg_color_space = JCS_RGB;\t/* ASCII 'R', 'G', 'B' */\n    else if (cid0 == 0x72 && cid1 == 0x67 && cid2 == 0x62)\n      cinfo->jpeg_color_space = JCS_BG_RGB;\t/* ASCII 'r', 'g', 'b' */\n    else if (cinfo->saw_JFIF_marker)\n      cinfo->jpeg_color_space = JCS_YCbCr;\t/* assume it's YCbCr */\n    else if (cinfo->saw_Adobe_marker) {\n      switch (cinfo->Adobe_transform) {\n      case 0:\n\tcinfo->jpeg_color_space = JCS_RGB;\n\tbreak;\n      case 1:\n\tcinfo->jpeg_color_space = JCS_YCbCr;\n\tbreak;\n      default:\n\tWARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);\n\tcinfo->jpeg_color_space = JCS_YCbCr;\t/* assume it's YCbCr */\n\tbreak;\n      }\n    } else {\n      TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);\n      cinfo->jpeg_color_space = JCS_YCbCr;\t/* assume it's YCbCr */\n    }\n    /* Always guess RGB is proper output colorspace. */\n    cinfo->out_color_space = JCS_RGB;\n    break;\n    \n  case 4:\n    if (cinfo->saw_Adobe_marker) {\n      switch (cinfo->Adobe_transform) {\n      case 0:\n\tcinfo->jpeg_color_space = JCS_CMYK;\n\tbreak;\n      case 2:\n\tcinfo->jpeg_color_space = JCS_YCCK;\n\tbreak;\n      default:\n\tWARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);\n\tcinfo->jpeg_color_space = JCS_YCCK;\t/* assume it's YCCK */\n\tbreak;\n      }\n    } else {\n      /* No special markers, assume straight CMYK. */\n      cinfo->jpeg_color_space = JCS_CMYK;\n    }\n    cinfo->out_color_space = JCS_CMYK;\n    break;\n    \n  default:\n    cinfo->jpeg_color_space = JCS_UNKNOWN;\n    cinfo->out_color_space = JCS_UNKNOWN;\n    break;\n  }\n\n  /* Set defaults for other decompression parameters. */\n  cinfo->scale_num = cinfo->block_size;\t\t/* 1:1 scaling */\n  cinfo->scale_denom = cinfo->block_size;\n  cinfo->output_gamma = 1.0;\n  cinfo->buffered_image = FALSE;\n  cinfo->raw_data_out = FALSE;\n  cinfo->dct_method = JDCT_DEFAULT;\n  cinfo->do_fancy_upsampling = TRUE;\n  cinfo->do_block_smoothing = TRUE;\n  cinfo->quantize_colors = FALSE;\n  /* We set these in case application only sets quantize_colors. */\n  cinfo->dither_mode = JDITHER_FS;\n#ifdef QUANT_2PASS_SUPPORTED\n  cinfo->two_pass_quantize = TRUE;\n#else\n  cinfo->two_pass_quantize = FALSE;\n#endif\n  cinfo->desired_number_of_colors = 256;\n  cinfo->colormap = NULL;\n  /* Initialize for no mode change in buffered-image mode. */\n  cinfo->enable_1pass_quant = FALSE;\n  cinfo->enable_external_quant = FALSE;\n  cinfo->enable_2pass_quant = FALSE;\n}\n\n\n/*\n * Decompression startup: read start of JPEG datastream to see what's there.\n * Need only initialize JPEG object and supply a data source before calling.\n *\n * This routine will read as far as the first SOS marker (ie, actual start of\n * compressed data), and will save all tables and parameters in the JPEG\n * object.  It will also initialize the decompression parameters to default\n * values, and finally return JPEG_HEADER_OK.  On return, the application may\n * adjust the decompression parameters and then call jpeg_start_decompress.\n * (Or, if the application only wanted to determine the image parameters,\n * the data need not be decompressed.  In that case, call jpeg_abort or\n * jpeg_destroy to release any temporary space.)\n * If an abbreviated (tables only) datastream is presented, the routine will\n * return JPEG_HEADER_TABLES_ONLY upon reaching EOI.  The application may then\n * re-use the JPEG object to read the abbreviated image datastream(s).\n * It is unnecessary (but OK) to call jpeg_abort in this case.\n * The JPEG_SUSPENDED return code only occurs if the data source module\n * requests suspension of the decompressor.  In this case the application\n * should load more source data and then re-call jpeg_read_header to resume\n * processing.\n * If a non-suspending data source is used and require_image is TRUE, then the\n * return code need not be inspected since only JPEG_HEADER_OK is possible.\n *\n * This routine is now just a front end to jpeg_consume_input, with some\n * extra error checking.\n */\n\nGLOBAL(int)\njpeg_read_header (j_decompress_ptr cinfo, boolean require_image)\n{\n  int retcode;\n\n  if (cinfo->global_state != DSTATE_START &&\n      cinfo->global_state != DSTATE_INHEADER)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  retcode = jpeg_consume_input(cinfo);\n\n  switch (retcode) {\n  case JPEG_REACHED_SOS:\n    retcode = JPEG_HEADER_OK;\n    break;\n  case JPEG_REACHED_EOI:\n    if (require_image)\t\t/* Complain if application wanted an image */\n      ERREXIT(cinfo, JERR_NO_IMAGE);\n    /* Reset to start state; it would be safer to require the application to\n     * call jpeg_abort, but we can't change it now for compatibility reasons.\n     * A side effect is to free any temporary memory (there shouldn't be any).\n     */\n    jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */\n    retcode = JPEG_HEADER_TABLES_ONLY;\n    break;\n  case JPEG_SUSPENDED:\n    /* no work */\n    break;\n  }\n\n  return retcode;\n}\n\n\n/*\n * Consume data in advance of what the decompressor requires.\n * This can be called at any time once the decompressor object has\n * been created and a data source has been set up.\n *\n * This routine is essentially a state machine that handles a couple\n * of critical state-transition actions, namely initial setup and\n * transition from header scanning to ready-for-start_decompress.\n * All the actual input is done via the input controller's consume_input\n * method.\n */\n\nGLOBAL(int)\njpeg_consume_input (j_decompress_ptr cinfo)\n{\n  int retcode = JPEG_SUSPENDED;\n\n  /* NB: every possible DSTATE value should be listed in this switch */\n  switch (cinfo->global_state) {\n  case DSTATE_START:\n    /* Start-of-datastream actions: reset appropriate modules */\n    (*cinfo->inputctl->reset_input_controller) (cinfo);\n    /* Initialize application's data source module */\n    (*cinfo->src->init_source) (cinfo);\n    cinfo->global_state = DSTATE_INHEADER;\n    /*FALLTHROUGH*/\n  case DSTATE_INHEADER:\n    retcode = (*cinfo->inputctl->consume_input) (cinfo);\n    if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */\n      /* Set up default parameters based on header data */\n      default_decompress_parms(cinfo);\n      /* Set global state: ready for start_decompress */\n      cinfo->global_state = DSTATE_READY;\n    }\n    break;\n  case DSTATE_READY:\n    /* Can't advance past first SOS until start_decompress is called */\n    retcode = JPEG_REACHED_SOS;\n    break;\n  case DSTATE_PRELOAD:\n  case DSTATE_PRESCAN:\n  case DSTATE_SCANNING:\n  case DSTATE_RAW_OK:\n  case DSTATE_BUFIMAGE:\n  case DSTATE_BUFPOST:\n  case DSTATE_STOPPING:\n    retcode = (*cinfo->inputctl->consume_input) (cinfo);\n    break;\n  default:\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  }\n  return retcode;\n}\n\n\n/*\n * Have we finished reading the input file?\n */\n\nGLOBAL(boolean)\njpeg_input_complete (j_decompress_ptr cinfo)\n{\n  /* Check for valid jpeg object */\n  if (cinfo->global_state < DSTATE_START ||\n      cinfo->global_state > DSTATE_STOPPING)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  return cinfo->inputctl->eoi_reached;\n}\n\n\n/*\n * Is there more than one scan?\n */\n\nGLOBAL(boolean)\njpeg_has_multiple_scans (j_decompress_ptr cinfo)\n{\n  /* Only valid after jpeg_read_header completes */\n  if (cinfo->global_state < DSTATE_READY ||\n      cinfo->global_state > DSTATE_STOPPING)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  return cinfo->inputctl->has_multiple_scans;\n}\n\n\n/*\n * Finish JPEG decompression.\n *\n * This will normally just verify the file trailer and release temp storage.\n *\n * Returns FALSE if suspended.  The return value need be inspected only if\n * a suspending data source is used.\n */\n\nGLOBAL(boolean)\njpeg_finish_decompress (j_decompress_ptr cinfo)\n{\n  if ((cinfo->global_state == DSTATE_SCANNING ||\n       cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {\n    /* Terminate final pass of non-buffered mode */\n    if (cinfo->output_scanline < cinfo->output_height)\n      ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);\n    (*cinfo->master->finish_output_pass) (cinfo);\n    cinfo->global_state = DSTATE_STOPPING;\n  } else if (cinfo->global_state == DSTATE_BUFIMAGE) {\n    /* Finishing after a buffered-image operation */\n    cinfo->global_state = DSTATE_STOPPING;\n  } else if (cinfo->global_state != DSTATE_STOPPING) {\n    /* STOPPING = repeat call after a suspension, anything else is error */\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  }\n  /* Read until EOI */\n  while (! cinfo->inputctl->eoi_reached) {\n    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)\n      return FALSE;\t\t/* Suspend, come back later */\n  }\n  /* Do final cleanup */\n  (*cinfo->src->term_source) (cinfo);\n  /* We can use jpeg_abort to release memory and reset global_state */\n  jpeg_abort((j_common_ptr) cinfo);\n  return TRUE;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdapistd.c",
    "content": "/*\n * jdapistd.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2002-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains application interface code for the decompression half\n * of the JPEG library.  These are the \"standard\" API routines that are\n * used in the normal full-decompression case.  They are not used by a\n * transcoding-only application.  Note that if an application links in\n * jpeg_start_decompress, it will end up linking in the entire decompressor.\n * We thus must separate this file from jdapimin.c to avoid linking the\n * whole decompression library into a transcoder.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Forward declarations */\nLOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));\n\n\n/*\n * Decompression initialization.\n * jpeg_read_header must be completed before calling this.\n *\n * If a multipass operating mode was selected, this will do all but the\n * last pass, and thus may take a great deal of time.\n *\n * Returns FALSE if suspended.  The return value need be inspected only if\n * a suspending data source is used.\n */\n\nGLOBAL(boolean)\njpeg_start_decompress (j_decompress_ptr cinfo)\n{\n  if (cinfo->global_state == DSTATE_READY) {\n    /* First call: initialize master control, select active modules */\n    jinit_master_decompress(cinfo);\n    if (cinfo->buffered_image) {\n      /* No more work here; expecting jpeg_start_output next */\n      cinfo->global_state = DSTATE_BUFIMAGE;\n      return TRUE;\n    }\n    cinfo->global_state = DSTATE_PRELOAD;\n  }\n  if (cinfo->global_state == DSTATE_PRELOAD) {\n    /* If file has multiple scans, absorb them all into the coef buffer */\n    if (cinfo->inputctl->has_multiple_scans) {\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n      for (;;) {\n\tint retcode;\n\t/* Call progress monitor hook if present */\n\tif (cinfo->progress != NULL)\n\t  (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n\t/* Absorb some more input */\n\tretcode = (*cinfo->inputctl->consume_input) (cinfo);\n\tif (retcode == JPEG_SUSPENDED)\n\t  return FALSE;\n\tif (retcode == JPEG_REACHED_EOI)\n\t  break;\n\t/* Advance progress counter if appropriate */\n\tif (cinfo->progress != NULL &&\n\t    (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {\n\t  if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {\n\t    /* jdmaster underestimated number of scans; ratchet up one scan */\n\t    cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;\n\t  }\n\t}\n      }\n#else\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif /* D_MULTISCAN_FILES_SUPPORTED */\n    }\n    cinfo->output_scan_number = cinfo->input_scan_number;\n  } else if (cinfo->global_state != DSTATE_PRESCAN)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  /* Perform any dummy output passes, and set up for the final pass */\n  return output_pass_setup(cinfo);\n}\n\n\n/*\n * Set up for an output pass, and perform any dummy pass(es) needed.\n * Common subroutine for jpeg_start_decompress and jpeg_start_output.\n * Entry: global_state = DSTATE_PRESCAN only if previously suspended.\n * Exit: If done, returns TRUE and sets global_state for proper output mode.\n *       If suspended, returns FALSE and sets global_state = DSTATE_PRESCAN.\n */\n\nLOCAL(boolean)\noutput_pass_setup (j_decompress_ptr cinfo)\n{\n  if (cinfo->global_state != DSTATE_PRESCAN) {\n    /* First call: do pass setup */\n    (*cinfo->master->prepare_for_output_pass) (cinfo);\n    cinfo->output_scanline = 0;\n    cinfo->global_state = DSTATE_PRESCAN;\n  }\n  /* Loop over any required dummy passes */\n  while (cinfo->master->is_dummy_pass) {\n#ifdef QUANT_2PASS_SUPPORTED\n    /* Crank through the dummy pass */\n    while (cinfo->output_scanline < cinfo->output_height) {\n      JDIMENSION last_scanline;\n      /* Call progress monitor hook if present */\n      if (cinfo->progress != NULL) {\n\tcinfo->progress->pass_counter = (long) cinfo->output_scanline;\n\tcinfo->progress->pass_limit = (long) cinfo->output_height;\n\t(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n      }\n      /* Process some data */\n      last_scanline = cinfo->output_scanline;\n      (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,\n\t\t\t\t    &cinfo->output_scanline, (JDIMENSION) 0);\n      if (cinfo->output_scanline == last_scanline)\n\treturn FALSE;\t\t/* No progress made, must suspend */\n    }\n    /* Finish up dummy pass, and set up for another one */\n    (*cinfo->master->finish_output_pass) (cinfo);\n    (*cinfo->master->prepare_for_output_pass) (cinfo);\n    cinfo->output_scanline = 0;\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif /* QUANT_2PASS_SUPPORTED */\n  }\n  /* Ready for application to drive output pass through\n   * jpeg_read_scanlines or jpeg_read_raw_data.\n   */\n  cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;\n  return TRUE;\n}\n\n\n/*\n * Read some scanlines of data from the JPEG decompressor.\n *\n * The return value will be the number of lines actually read.\n * This may be less than the number requested in several cases,\n * including bottom of image, data source suspension, and operating\n * modes that emit multiple scanlines at a time.\n *\n * Note: we warn about excess calls to jpeg_read_scanlines() since\n * this likely signals an application programmer error.  However,\n * an oversize buffer (max_lines > scanlines remaining) is not an error.\n */\n\nGLOBAL(JDIMENSION)\njpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,\n\t\t     JDIMENSION max_lines)\n{\n  JDIMENSION row_ctr;\n\n  if (cinfo->global_state != DSTATE_SCANNING)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  if (cinfo->output_scanline >= cinfo->output_height) {\n    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\n    return 0;\n  }\n\n  /* Call progress monitor hook if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->pass_counter = (long) cinfo->output_scanline;\n    cinfo->progress->pass_limit = (long) cinfo->output_height;\n    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n  }\n\n  /* Process some data */\n  row_ctr = 0;\n  (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);\n  cinfo->output_scanline += row_ctr;\n  return row_ctr;\n}\n\n\n/*\n * Alternate entry point to read raw data.\n * Processes exactly one iMCU row per call, unless suspended.\n */\n\nGLOBAL(JDIMENSION)\njpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,\n\t\t    JDIMENSION max_lines)\n{\n  JDIMENSION lines_per_iMCU_row;\n\n  if (cinfo->global_state != DSTATE_RAW_OK)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  if (cinfo->output_scanline >= cinfo->output_height) {\n    WARNMS(cinfo, JWRN_TOO_MUCH_DATA);\n    return 0;\n  }\n\n  /* Call progress monitor hook if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->pass_counter = (long) cinfo->output_scanline;\n    cinfo->progress->pass_limit = (long) cinfo->output_height;\n    (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n  }\n\n  /* Verify that at least one iMCU row can be returned. */\n  lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_v_scaled_size;\n  if (max_lines < lines_per_iMCU_row)\n    ERREXIT(cinfo, JERR_BUFFER_SIZE);\n\n  /* Decompress directly into user's buffer. */\n  if (! (*cinfo->coef->decompress_data) (cinfo, data))\n    return 0;\t\t\t/* suspension forced, can do nothing more */\n\n  /* OK, we processed one iMCU row. */\n  cinfo->output_scanline += lines_per_iMCU_row;\n  return lines_per_iMCU_row;\n}\n\n\n/* Additional entry points for buffered-image mode. */\n\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n\n/*\n * Initialize for an output pass in buffered-image mode.\n */\n\nGLOBAL(boolean)\njpeg_start_output (j_decompress_ptr cinfo, int scan_number)\n{\n  if (cinfo->global_state != DSTATE_BUFIMAGE &&\n      cinfo->global_state != DSTATE_PRESCAN)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  /* Limit scan number to valid range */\n  if (scan_number <= 0)\n    scan_number = 1;\n  if (cinfo->inputctl->eoi_reached &&\n      scan_number > cinfo->input_scan_number)\n    scan_number = cinfo->input_scan_number;\n  cinfo->output_scan_number = scan_number;\n  /* Perform any dummy output passes, and set up for the real pass */\n  return output_pass_setup(cinfo);\n}\n\n\n/*\n * Finish up after an output pass in buffered-image mode.\n *\n * Returns FALSE if suspended.  The return value need be inspected only if\n * a suspending data source is used.\n */\n\nGLOBAL(boolean)\njpeg_finish_output (j_decompress_ptr cinfo)\n{\n  if ((cinfo->global_state == DSTATE_SCANNING ||\n       cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {\n    /* Terminate this pass. */\n    /* We do not require the whole pass to have been completed. */\n    (*cinfo->master->finish_output_pass) (cinfo);\n    cinfo->global_state = DSTATE_BUFPOST;\n  } else if (cinfo->global_state != DSTATE_BUFPOST) {\n    /* BUFPOST = repeat call after a suspension, anything else is error */\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  }\n  /* Read markers looking for SOS or EOI */\n  while (cinfo->input_scan_number <= cinfo->output_scan_number &&\n\t ! cinfo->inputctl->eoi_reached) {\n    if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)\n      return FALSE;\t\t/* Suspend, come back later */\n  }\n  cinfo->global_state = DSTATE_BUFIMAGE;\n  return TRUE;\n}\n\n#endif /* D_MULTISCAN_FILES_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdarith.c",
    "content": "/*\n * jdarith.c\n *\n * Developed 1997-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains portable arithmetic entropy decoding routines for JPEG\n * (implementing the ISO/IEC IS 10918-1 and CCITT Recommendation ITU-T T.81).\n *\n * Both sequential and progressive modes are supported in this single module.\n *\n * Suspension is not currently supported in this module.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Expanded entropy decoder object for arithmetic decoding. */\n\ntypedef struct {\n  struct jpeg_entropy_decoder pub; /* public fields */\n\n  INT32 c;       /* C register, base of coding interval + input bit buffer */\n  INT32 a;               /* A register, normalized size of coding interval */\n  int ct;     /* bit shift counter, # of bits left in bit buffer part of C */\n                                                         /* init: ct = -16 */\n                                                         /* run: ct = 0..7 */\n                                                         /* error: ct = -1 */\n  int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */\n  int dc_context[MAX_COMPS_IN_SCAN]; /* context index for DC conditioning */\n\n  unsigned int restarts_to_go;\t/* MCUs left in this restart interval */\n\n  /* Pointers to statistics areas (these workspaces have image lifespan) */\n  unsigned char * dc_stats[NUM_ARITH_TBLS];\n  unsigned char * ac_stats[NUM_ARITH_TBLS];\n\n  /* Statistics bin for coding with fixed probability 0.5 */\n  unsigned char fixed_bin[4];\n} arith_entropy_decoder;\n\ntypedef arith_entropy_decoder * arith_entropy_ptr;\n\n/* The following two definitions specify the allocation chunk size\n * for the statistics area.\n * According to sections F.1.4.4.1.3 and F.1.4.4.2, we need at least\n * 49 statistics bins for DC, and 245 statistics bins for AC coding.\n *\n * We use a compact representation with 1 byte per statistics bin,\n * thus the numbers directly represent byte sizes.\n * This 1 byte per statistics bin contains the meaning of the MPS\n * (more probable symbol) in the highest bit (mask 0x80), and the\n * index into the probability estimation state machine table\n * in the lower bits (mask 0x7F).\n */\n\n#define DC_STAT_BINS 64\n#define AC_STAT_BINS 256\n\n\nLOCAL(int)\nget_byte (j_decompress_ptr cinfo)\n/* Read next input byte; we do not support suspension in this module. */\n{\n  struct jpeg_source_mgr * src = cinfo->src;\n\n  if (src->bytes_in_buffer == 0)\n    if (! (*src->fill_input_buffer) (cinfo))\n      ERREXIT(cinfo, JERR_CANT_SUSPEND);\n  src->bytes_in_buffer--;\n  return GETJOCTET(*src->next_input_byte++);\n}\n\n\n/*\n * The core arithmetic decoding routine (common in JPEG and JBIG).\n * This needs to go as fast as possible.\n * Machine-dependent optimization facilities\n * are not utilized in this portable implementation.\n * However, this code should be fairly efficient and\n * may be a good base for further optimizations anyway.\n *\n * Return value is 0 or 1 (binary decision).\n *\n * Note: I've changed the handling of the code base & bit\n * buffer register C compared to other implementations\n * based on the standards layout & procedures.\n * While it also contains both the actual base of the\n * coding interval (16 bits) and the next-bits buffer,\n * the cut-point between these two parts is floating\n * (instead of fixed) with the bit shift counter CT.\n * Thus, we also need only one (variable instead of\n * fixed size) shift for the LPS/MPS decision, and\n * we can do away with any renormalization update\n * of C (except for new data insertion, of course).\n *\n * I've also introduced a new scheme for accessing\n * the probability estimation state machine table,\n * derived from Markus Kuhn's JBIG implementation.\n */\n\nLOCAL(int)\narith_decode (j_decompress_ptr cinfo, unsigned char *st)\n{\n  register arith_entropy_ptr e = (arith_entropy_ptr) cinfo->entropy;\n  register unsigned char nl, nm;\n  register INT32 qe, temp;\n  register int sv, data;\n\n  /* Renormalization & data input per section D.2.6 */\n  while (e->a < 0x8000L) {\n    if (--e->ct < 0) {\n      /* Need to fetch next data byte */\n      if (cinfo->unread_marker)\n\tdata = 0;\t\t/* stuff zero data */\n      else {\n\tdata = get_byte(cinfo);\t/* read next input byte */\n\tif (data == 0xFF) {\t/* zero stuff or marker code */\n\t  do data = get_byte(cinfo);\n\t  while (data == 0xFF);\t/* swallow extra 0xFF bytes */\n\t  if (data == 0)\n\t    data = 0xFF;\t/* discard stuffed zero byte */\n\t  else {\n\t    /* Note: Different from the Huffman decoder, hitting\n\t     * a marker while processing the compressed data\n\t     * segment is legal in arithmetic coding.\n\t     * The convention is to supply zero data\n\t     * then until decoding is complete.\n\t     */\n\t    cinfo->unread_marker = data;\n\t    data = 0;\n\t  }\n\t}\n      }\n      e->c = (e->c << 8) | data; /* insert data into C register */\n      if ((e->ct += 8) < 0)\t /* update bit shift counter */\n\t/* Need more initial bytes */\n\tif (++e->ct == 0)\n\t  /* Got 2 initial bytes -> re-init A and exit loop */\n\t  e->a = 0x8000L; /* => e->a = 0x10000L after loop exit */\n    }\n    e->a <<= 1;\n  }\n\n  /* Fetch values from our compact representation of Table D.3(D.2):\n   * Qe values and probability estimation state machine\n   */\n  sv = *st;\n  qe = jpeg_aritab[sv & 0x7F];\t/* => Qe_Value */\n  nl = qe & 0xFF; qe >>= 8;\t/* Next_Index_LPS + Switch_MPS */\n  nm = qe & 0xFF; qe >>= 8;\t/* Next_Index_MPS */\n\n  /* Decode & estimation procedures per sections D.2.4 & D.2.5 */\n  temp = e->a - qe;\n  e->a = temp;\n  temp <<= e->ct;\n  if (e->c >= temp) {\n    e->c -= temp;\n    /* Conditional LPS (less probable symbol) exchange */\n    if (e->a < qe) {\n      e->a = qe;\n      *st = (sv & 0x80) ^ nm;\t/* Estimate_after_MPS */\n    } else {\n      e->a = qe;\n      *st = (sv & 0x80) ^ nl;\t/* Estimate_after_LPS */\n      sv ^= 0x80;\t\t/* Exchange LPS/MPS */\n    }\n  } else if (e->a < 0x8000L) {\n    /* Conditional MPS (more probable symbol) exchange */\n    if (e->a < qe) {\n      *st = (sv & 0x80) ^ nl;\t/* Estimate_after_LPS */\n      sv ^= 0x80;\t\t/* Exchange LPS/MPS */\n    } else {\n      *st = (sv & 0x80) ^ nm;\t/* Estimate_after_MPS */\n    }\n  }\n\n  return sv >> 7;\n}\n\n\n/*\n * Check for a restart marker & resynchronize decoder.\n */\n\nLOCAL(void)\nprocess_restart (j_decompress_ptr cinfo)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  int ci;\n  jpeg_component_info * compptr;\n\n  /* Advance past the RSTn marker */\n  if (! (*cinfo->marker->read_restart_marker) (cinfo))\n    ERREXIT(cinfo, JERR_CANT_SUSPEND);\n\n  /* Re-initialize statistics areas */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {\n      MEMZERO(entropy->dc_stats[compptr->dc_tbl_no], DC_STAT_BINS);\n      /* Reset DC predictions to 0 */\n      entropy->last_dc_val[ci] = 0;\n      entropy->dc_context[ci] = 0;\n    }\n    if ((! cinfo->progressive_mode && cinfo->lim_Se) ||\n\t(cinfo->progressive_mode && cinfo->Ss)) {\n      MEMZERO(entropy->ac_stats[compptr->ac_tbl_no], AC_STAT_BINS);\n    }\n  }\n\n  /* Reset arithmetic decoding variables */\n  entropy->c = 0;\n  entropy->a = 0;\n  entropy->ct = -16;\t/* force reading 2 initial bytes to fill C */\n\n  /* Reset restart counter */\n  entropy->restarts_to_go = cinfo->restart_interval;\n}\n\n\n/*\n * Arithmetic MCU decoding.\n * Each of these routines decodes and returns one MCU's worth of\n * arithmetic-compressed coefficients.\n * The coefficients are reordered from zigzag order into natural array order,\n * but are not dequantized.\n *\n * The i'th block of the MCU is stored into the block pointed to by\n * MCU_data[i].  WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.\n */\n\n/*\n * MCU decoding for DC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\ndecode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  JBLOCKROW block;\n  unsigned char *st;\n  int blkn, ci, tbl, sign;\n  int v, m;\n\n  /* Process restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      process_restart(cinfo);\n    entropy->restarts_to_go--;\n  }\n\n  if (entropy->ct == -1) return TRUE;\t/* if error do nothing */\n\n  /* Outer loop handles each block in the MCU */\n\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    block = MCU_data[blkn];\n    ci = cinfo->MCU_membership[blkn];\n    tbl = cinfo->cur_comp_info[ci]->dc_tbl_no;\n\n    /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */\n\n    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */\n    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];\n\n    /* Figure F.19: Decode_DC_DIFF */\n    if (arith_decode(cinfo, st) == 0)\n      entropy->dc_context[ci] = 0;\n    else {\n      /* Figure F.21: Decoding nonzero value v */\n      /* Figure F.22: Decoding the sign of v */\n      sign = arith_decode(cinfo, st + 1);\n      st += 2; st += sign;\n      /* Figure F.23: Decoding the magnitude category of v */\n      if ((m = arith_decode(cinfo, st)) != 0) {\n\tst = entropy->dc_stats[tbl] + 20;\t/* Table F.4: X1 = 20 */\n\twhile (arith_decode(cinfo, st)) {\n\t  if ((m <<= 1) == 0x8000) {\n\t    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\t    entropy->ct = -1;\t\t\t/* magnitude overflow */\n\t    return TRUE;\n\t  }\n\t  st += 1;\n\t}\n      }\n      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */\n      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))\n\tentropy->dc_context[ci] = 0;\t\t   /* zero diff category */\n      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))\n\tentropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */\n      else\n\tentropy->dc_context[ci] = 4 + (sign * 4);  /* small diff category */\n      v = m;\n      /* Figure F.24: Decoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tif (arith_decode(cinfo, st)) v |= m;\n      v += 1; if (sign) v = -v;\n      entropy->last_dc_val[ci] += v;\n    }\n\n    /* Scale and output the DC coefficient (assumes jpeg_natural_order[0]=0) */\n    (*block)[0] = (JCOEF) (entropy->last_dc_val[ci] << cinfo->Al);\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for AC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\ndecode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  JBLOCKROW block;\n  unsigned char *st;\n  int tbl, sign, k;\n  int v, m;\n  const int * natural_order;\n\n  /* Process restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      process_restart(cinfo);\n    entropy->restarts_to_go--;\n  }\n\n  if (entropy->ct == -1) return TRUE;\t/* if error do nothing */\n\n  natural_order = cinfo->natural_order;\n\n  /* There is always only one block per MCU */\n  block = MCU_data[0];\n  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;\n\n  /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */\n\n  /* Figure F.20: Decode_AC_coefficients */\n  k = cinfo->Ss - 1;\n  do {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    if (arith_decode(cinfo, st)) break;\t\t/* EOB flag */\n    for (;;) {\n      k++;\n      if (arith_decode(cinfo, st + 1)) break;\n      st += 3;\n      if (k >= cinfo->Se) {\n\tWARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\tentropy->ct = -1;\t\t\t/* spectral overflow */\n\treturn TRUE;\n      }\n    }\n    /* Figure F.21: Decoding nonzero value v */\n    /* Figure F.22: Decoding the sign of v */\n    sign = arith_decode(cinfo, entropy->fixed_bin);\n    st += 2;\n    /* Figure F.23: Decoding the magnitude category of v */\n    if ((m = arith_decode(cinfo, st)) != 0) {\n      if (arith_decode(cinfo, st)) {\n\tm <<= 1;\n\tst = entropy->ac_stats[tbl] +\n\t     (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);\n\twhile (arith_decode(cinfo, st)) {\n\t  if ((m <<= 1) == 0x8000) {\n\t    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\t    entropy->ct = -1;\t\t\t/* magnitude overflow */\n\t    return TRUE;\n\t  }\n\t  st += 1;\n\t}\n      }\n    }\n    v = m;\n    /* Figure F.24: Decoding the magnitude bit pattern of v */\n    st += 14;\n    while (m >>= 1)\n      if (arith_decode(cinfo, st)) v |= m;\n    v += 1; if (sign) v = -v;\n    /* Scale and output coefficient in natural (dezigzagged) order */\n    (*block)[natural_order[k]] = (JCOEF) (v << cinfo->Al);\n  } while (k < cinfo->Se);\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for DC successive approximation refinement scan.\n * Note: we assume such scans can be multi-component,\n * although the spec is not very clear on the point.\n */\n\nMETHODDEF(boolean)\ndecode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  unsigned char *st;\n  int p1, blkn;\n\n  /* Process restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      process_restart(cinfo);\n    entropy->restarts_to_go--;\n  }\n\n  st = entropy->fixed_bin;\t/* use fixed probability estimation */\n  p1 = 1 << cinfo->Al;\t\t/* 1 in the bit position being coded */\n\n  /* Outer loop handles each block in the MCU */\n\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    /* Encoded data is simply the next bit of the two's-complement DC value */\n    if (arith_decode(cinfo, st))\n      MCU_data[blkn][0][0] |= p1;\n  }\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for AC successive approximation refinement scan.\n */\n\nMETHODDEF(boolean)\ndecode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  JBLOCKROW block;\n  JCOEFPTR thiscoef;\n  unsigned char *st;\n  int tbl, k, kex;\n  int p1, m1;\n  const int * natural_order;\n\n  /* Process restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      process_restart(cinfo);\n    entropy->restarts_to_go--;\n  }\n\n  if (entropy->ct == -1) return TRUE;\t/* if error do nothing */\n\n  natural_order = cinfo->natural_order;\n\n  /* There is always only one block per MCU */\n  block = MCU_data[0];\n  tbl = cinfo->cur_comp_info[0]->ac_tbl_no;\n\n  p1 = 1 << cinfo->Al;\t\t/* 1 in the bit position being coded */\n  m1 = (-1) << cinfo->Al;\t/* -1 in the bit position being coded */\n\n  /* Establish EOBx (previous stage end-of-block) index */\n  kex = cinfo->Se;\n  do {\n    if ((*block)[natural_order[kex]]) break;\n  } while (--kex);\n\n  k = cinfo->Ss - 1;\n  do {\n    st = entropy->ac_stats[tbl] + 3 * k;\n    if (k >= kex)\n      if (arith_decode(cinfo, st)) break;\t/* EOB flag */\n    for (;;) {\n      thiscoef = *block + natural_order[++k];\n      if (*thiscoef) {\t\t\t\t/* previously nonzero coef */\n\tif (arith_decode(cinfo, st + 2)) {\n\t  if (*thiscoef < 0)\n\t    *thiscoef += m1;\n\t  else\n\t    *thiscoef += p1;\n\t}\n\tbreak;\n      }\n      if (arith_decode(cinfo, st + 1)) {\t/* newly nonzero coef */\n\tif (arith_decode(cinfo, entropy->fixed_bin))\n\t  *thiscoef = m1;\n\telse\n\t  *thiscoef = p1;\n\tbreak;\n      }\n      st += 3;\n      if (k >= cinfo->Se) {\n\tWARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\tentropy->ct = -1;\t\t\t/* spectral overflow */\n\treturn TRUE;\n      }\n    }\n  } while (k < cinfo->Se);\n\n  return TRUE;\n}\n\n\n/*\n * Decode one MCU's worth of arithmetic-compressed coefficients.\n */\n\nMETHODDEF(boolean)\ndecode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  jpeg_component_info * compptr;\n  JBLOCKROW block;\n  unsigned char *st;\n  int blkn, ci, tbl, sign, k;\n  int v, m;\n  const int * natural_order;\n\n  /* Process restart marker if needed */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      process_restart(cinfo);\n    entropy->restarts_to_go--;\n  }\n\n  if (entropy->ct == -1) return TRUE;\t/* if error do nothing */\n\n  natural_order = cinfo->natural_order;\n\n  /* Outer loop handles each block in the MCU */\n\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    block = MCU_data[blkn];\n    ci = cinfo->MCU_membership[blkn];\n    compptr = cinfo->cur_comp_info[ci];\n\n    /* Sections F.2.4.1 & F.1.4.4.1: Decoding of DC coefficients */\n\n    tbl = compptr->dc_tbl_no;\n\n    /* Table F.4: Point to statistics bin S0 for DC coefficient coding */\n    st = entropy->dc_stats[tbl] + entropy->dc_context[ci];\n\n    /* Figure F.19: Decode_DC_DIFF */\n    if (arith_decode(cinfo, st) == 0)\n      entropy->dc_context[ci] = 0;\n    else {\n      /* Figure F.21: Decoding nonzero value v */\n      /* Figure F.22: Decoding the sign of v */\n      sign = arith_decode(cinfo, st + 1);\n      st += 2; st += sign;\n      /* Figure F.23: Decoding the magnitude category of v */\n      if ((m = arith_decode(cinfo, st)) != 0) {\n\tst = entropy->dc_stats[tbl] + 20;\t/* Table F.4: X1 = 20 */\n\twhile (arith_decode(cinfo, st)) {\n\t  if ((m <<= 1) == 0x8000) {\n\t    WARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\t    entropy->ct = -1;\t\t\t/* magnitude overflow */\n\t    return TRUE;\n\t  }\n\t  st += 1;\n\t}\n      }\n      /* Section F.1.4.4.1.2: Establish dc_context conditioning category */\n      if (m < (int) ((1L << cinfo->arith_dc_L[tbl]) >> 1))\n\tentropy->dc_context[ci] = 0;\t\t   /* zero diff category */\n      else if (m > (int) ((1L << cinfo->arith_dc_U[tbl]) >> 1))\n\tentropy->dc_context[ci] = 12 + (sign * 4); /* large diff category */\n      else\n\tentropy->dc_context[ci] = 4 + (sign * 4);  /* small diff category */\n      v = m;\n      /* Figure F.24: Decoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tif (arith_decode(cinfo, st)) v |= m;\n      v += 1; if (sign) v = -v;\n      entropy->last_dc_val[ci] += v;\n    }\n\n    (*block)[0] = (JCOEF) entropy->last_dc_val[ci];\n\n    /* Sections F.2.4.2 & F.1.4.4.2: Decoding of AC coefficients */\n\n    if (cinfo->lim_Se == 0) continue;\n    tbl = compptr->ac_tbl_no;\n    k = 0;\n\n    /* Figure F.20: Decode_AC_coefficients */\n    do {\n      st = entropy->ac_stats[tbl] + 3 * k;\n      if (arith_decode(cinfo, st)) break;\t/* EOB flag */\n      for (;;) {\n\tk++;\n\tif (arith_decode(cinfo, st + 1)) break;\n\tst += 3;\n\tif (k >= cinfo->lim_Se) {\n\t  WARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\t  entropy->ct = -1;\t\t\t/* spectral overflow */\n\t  return TRUE;\n\t}\n      }\n      /* Figure F.21: Decoding nonzero value v */\n      /* Figure F.22: Decoding the sign of v */\n      sign = arith_decode(cinfo, entropy->fixed_bin);\n      st += 2;\n      /* Figure F.23: Decoding the magnitude category of v */\n      if ((m = arith_decode(cinfo, st)) != 0) {\n\tif (arith_decode(cinfo, st)) {\n\t  m <<= 1;\n\t  st = entropy->ac_stats[tbl] +\n\t       (k <= cinfo->arith_ac_K[tbl] ? 189 : 217);\n\t  while (arith_decode(cinfo, st)) {\n\t    if ((m <<= 1) == 0x8000) {\n\t      WARNMS(cinfo, JWRN_ARITH_BAD_CODE);\n\t      entropy->ct = -1;\t\t\t/* magnitude overflow */\n\t      return TRUE;\n\t    }\n\t    st += 1;\n\t  }\n\t}\n      }\n      v = m;\n      /* Figure F.24: Decoding the magnitude bit pattern of v */\n      st += 14;\n      while (m >>= 1)\n\tif (arith_decode(cinfo, st)) v |= m;\n      v += 1; if (sign) v = -v;\n      (*block)[natural_order[k]] = (JCOEF) v;\n    } while (k < cinfo->lim_Se);\n  }\n\n  return TRUE;\n}\n\n\n/*\n * Initialize for an arithmetic-compressed scan.\n */\n\nMETHODDEF(void)\nstart_pass (j_decompress_ptr cinfo)\n{\n  arith_entropy_ptr entropy = (arith_entropy_ptr) cinfo->entropy;\n  int ci, tbl;\n  jpeg_component_info * compptr;\n\n  if (cinfo->progressive_mode) {\n    /* Validate progressive scan parameters */\n    if (cinfo->Ss == 0) {\n      if (cinfo->Se != 0)\n\tgoto bad;\n    } else {\n      /* need not check Ss/Se < 0 since they came from unsigned bytes */\n      if (cinfo->Se < cinfo->Ss || cinfo->Se > cinfo->lim_Se)\n\tgoto bad;\n      /* AC scans may have only one component */\n      if (cinfo->comps_in_scan != 1)\n\tgoto bad;\n    }\n    if (cinfo->Ah != 0) {\n      /* Successive approximation refinement scan: must have Al = Ah-1. */\n      if (cinfo->Ah-1 != cinfo->Al)\n\tgoto bad;\n    }\n    if (cinfo->Al > 13) {\t/* need not check for < 0 */\n      bad:\n      ERREXIT4(cinfo, JERR_BAD_PROGRESSION,\n\t       cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);\n    }\n    /* Update progression status, and verify that scan order is legal.\n     * Note that inter-scan inconsistencies are treated as warnings\n     * not fatal errors ... not clear if this is right way to behave.\n     */\n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;\n      int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];\n      if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */\n\tWARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);\n      for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {\n\tint expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];\n\tif (cinfo->Ah != expected)\n\t  WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);\n\tcoef_bit_ptr[coefi] = cinfo->Al;\n      }\n    }\n    /* Select MCU decoding routine */\n    if (cinfo->Ah == 0) {\n      if (cinfo->Ss == 0)\n\tentropy->pub.decode_mcu = decode_mcu_DC_first;\n      else\n\tentropy->pub.decode_mcu = decode_mcu_AC_first;\n    } else {\n      if (cinfo->Ss == 0)\n\tentropy->pub.decode_mcu = decode_mcu_DC_refine;\n      else\n\tentropy->pub.decode_mcu = decode_mcu_AC_refine;\n    }\n  } else {\n    /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.\n     * This ought to be an error condition, but we make it a warning.\n     */\n    if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||\n\t(cinfo->Se < DCTSIZE2 && cinfo->Se != cinfo->lim_Se))\n      WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);\n    /* Select MCU decoding routine */\n    entropy->pub.decode_mcu = decode_mcu;\n  }\n\n  /* Allocate & initialize requested statistics areas */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    if (! cinfo->progressive_mode || (cinfo->Ss == 0 && cinfo->Ah == 0)) {\n      tbl = compptr->dc_tbl_no;\n      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)\n\tERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);\n      if (entropy->dc_stats[tbl] == NULL)\n\tentropy->dc_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)\n\t  ((j_common_ptr) cinfo, JPOOL_IMAGE, DC_STAT_BINS);\n      MEMZERO(entropy->dc_stats[tbl], DC_STAT_BINS);\n      /* Initialize DC predictions to 0 */\n      entropy->last_dc_val[ci] = 0;\n      entropy->dc_context[ci] = 0;\n    }\n    if ((! cinfo->progressive_mode && cinfo->lim_Se) ||\n\t(cinfo->progressive_mode && cinfo->Ss)) {\n      tbl = compptr->ac_tbl_no;\n      if (tbl < 0 || tbl >= NUM_ARITH_TBLS)\n\tERREXIT1(cinfo, JERR_NO_ARITH_TABLE, tbl);\n      if (entropy->ac_stats[tbl] == NULL)\n\tentropy->ac_stats[tbl] = (unsigned char *) (*cinfo->mem->alloc_small)\n\t  ((j_common_ptr) cinfo, JPOOL_IMAGE, AC_STAT_BINS);\n      MEMZERO(entropy->ac_stats[tbl], AC_STAT_BINS);\n    }\n  }\n\n  /* Initialize arithmetic decoding variables */\n  entropy->c = 0;\n  entropy->a = 0;\n  entropy->ct = -16;\t/* force reading 2 initial bytes to fill C */\n\n  /* Initialize restart counter */\n  entropy->restarts_to_go = cinfo->restart_interval;\n}\n\n\n/*\n * Finish up at the end of an arithmetic-compressed scan.\n */\n\nMETHODDEF(void)\nfinish_pass (j_decompress_ptr cinfo)\n{\n  /* no work necessary here */\n}\n\n\n/*\n * Module initialization routine for arithmetic entropy decoding.\n */\n\nGLOBAL(void)\njinit_arith_decoder (j_decompress_ptr cinfo)\n{\n  arith_entropy_ptr entropy;\n  int i;\n\n  entropy = (arith_entropy_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(arith_entropy_decoder));\n  cinfo->entropy = &entropy->pub;\n  entropy->pub.start_pass = start_pass;\n  entropy->pub.finish_pass = finish_pass;\n\n  /* Mark tables unallocated */\n  for (i = 0; i < NUM_ARITH_TBLS; i++) {\n    entropy->dc_stats[i] = NULL;\n    entropy->ac_stats[i] = NULL;\n  }\n\n  /* Initialize index for fixed probability estimation */\n  entropy->fixed_bin[0] = 113;\n\n  if (cinfo->progressive_mode) {\n    /* Create progression status table */\n    int *coef_bit_ptr, ci;\n    cinfo->coef_bits = (int (*)[DCTSIZE2])\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  cinfo->num_components*DCTSIZE2*SIZEOF(int));\n    coef_bit_ptr = & cinfo->coef_bits[0][0];\n    for (ci = 0; ci < cinfo->num_components; ci++) \n      for (i = 0; i < DCTSIZE2; i++)\n\t*coef_bit_ptr++ = -1;\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdatadst.c",
    "content": "/*\n * jdatadst.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2009-2012 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains compression data destination routines for the case of\n * emitting JPEG data to memory or to a file (or any stdio stream).\n * While these routines are sufficient for most applications,\n * some will want to use a different destination manager.\n * IMPORTANT: we assume that fwrite() will correctly transcribe an array of\n * JOCTETs into 8-bit-wide elements on external storage.  If char is wider\n * than 8 bits on your machine, you may need to do some tweaking.\n */\n\n/* this is not a core library module, so it doesn't define JPEG_INTERNALS */\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jerror.h\"\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare malloc(),free() */\nextern void * malloc JPP((size_t size));\nextern void free JPP((void *ptr));\n#endif\n\n\n/* Expanded data destination object for stdio output */\n\ntypedef struct {\n  struct jpeg_destination_mgr pub; /* public fields */\n\n  FILE * outfile;\t\t/* target stream */\n  JOCTET * buffer;\t\t/* start of buffer */\n} my_destination_mgr;\n\ntypedef my_destination_mgr * my_dest_ptr;\n\n#define OUTPUT_BUF_SIZE  4096\t/* choose an efficiently fwrite'able size */\n\n\n/* Expanded data destination object for memory output */\n\ntypedef struct {\n  struct jpeg_destination_mgr pub; /* public fields */\n\n  unsigned char ** outbuffer;\t/* target buffer */\n  unsigned long * outsize;\n  unsigned char * newbuffer;\t/* newly allocated buffer */\n  JOCTET * buffer;\t\t/* start of buffer */\n  size_t bufsize;\n} my_mem_destination_mgr;\n\ntypedef my_mem_destination_mgr * my_mem_dest_ptr;\n\n\n/*\n * Initialize destination --- called by jpeg_start_compress\n * before any data is actually written.\n */\n\nMETHODDEF(void)\ninit_destination (j_compress_ptr cinfo)\n{\n  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;\n\n  /* Allocate the output buffer --- it will be released when done with image */\n  dest->buffer = (JOCTET *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  OUTPUT_BUF_SIZE * SIZEOF(JOCTET));\n\n  dest->pub.next_output_byte = dest->buffer;\n  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;\n}\n\nMETHODDEF(void)\ninit_mem_destination (j_compress_ptr cinfo)\n{\n  /* no work necessary here */\n}\n\n\n/*\n * Empty the output buffer --- called whenever buffer fills up.\n *\n * In typical applications, this should write the entire output buffer\n * (ignoring the current state of next_output_byte & free_in_buffer),\n * reset the pointer & count to the start of the buffer, and return TRUE\n * indicating that the buffer has been dumped.\n *\n * In applications that need to be able to suspend compression due to output\n * overrun, a FALSE return indicates that the buffer cannot be emptied now.\n * In this situation, the compressor will return to its caller (possibly with\n * an indication that it has not accepted all the supplied scanlines).  The\n * application should resume compression after it has made more room in the\n * output buffer.  Note that there are substantial restrictions on the use of\n * suspension --- see the documentation.\n *\n * When suspending, the compressor will back up to a convenient restart point\n * (typically the start of the current MCU). next_output_byte & free_in_buffer\n * indicate where the restart point will be if the current call returns FALSE.\n * Data beyond this point will be regenerated after resumption, so do not\n * write it out when emptying the buffer externally.\n */\n\nMETHODDEF(boolean)\nempty_output_buffer (j_compress_ptr cinfo)\n{\n  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;\n\n  if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=\n      (size_t) OUTPUT_BUF_SIZE)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n\n  dest->pub.next_output_byte = dest->buffer;\n  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;\n\n  return TRUE;\n}\n\nMETHODDEF(boolean)\nempty_mem_output_buffer (j_compress_ptr cinfo)\n{\n  size_t nextsize;\n  JOCTET * nextbuffer;\n  my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;\n\n  /* Try to allocate new buffer with double size */\n  nextsize = dest->bufsize * 2;\n  nextbuffer = (JOCTET *) malloc(nextsize);\n\n  if (nextbuffer == NULL)\n    ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);\n\n  MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);\n\n  if (dest->newbuffer != NULL)\n    free(dest->newbuffer);\n\n  dest->newbuffer = nextbuffer;\n\n  dest->pub.next_output_byte = nextbuffer + dest->bufsize;\n  dest->pub.free_in_buffer = dest->bufsize;\n\n  dest->buffer = nextbuffer;\n  dest->bufsize = nextsize;\n\n  return TRUE;\n}\n\n\n/*\n * Terminate destination --- called by jpeg_finish_compress\n * after all data has been written.  Usually needs to flush buffer.\n *\n * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding\n * application must deal with any cleanup that should happen even\n * for error exit.\n */\n\nMETHODDEF(void)\nterm_destination (j_compress_ptr cinfo)\n{\n  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;\n  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;\n\n  /* Write any data remaining in the buffer */\n  if (datacount > 0) {\n    if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)\n      ERREXIT(cinfo, JERR_FILE_WRITE);\n  }\n  fflush(dest->outfile);\n  /* Make sure we wrote the output file OK */\n  if (ferror(dest->outfile))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\nMETHODDEF(void)\nterm_mem_destination (j_compress_ptr cinfo)\n{\n  my_mem_dest_ptr dest = (my_mem_dest_ptr) cinfo->dest;\n\n  *dest->outbuffer = dest->buffer;\n  *dest->outsize = dest->bufsize - dest->pub.free_in_buffer;\n}\n\n\n/*\n * Prepare for output to a stdio stream.\n * The caller must have already opened the stream, and is responsible\n * for closing it after finishing compression.\n */\n\nGLOBAL(void)\njpeg_stdio_dest (j_compress_ptr cinfo, FILE * outfile)\n{\n  my_dest_ptr dest;\n\n  /* The destination object is made permanent so that multiple JPEG images\n   * can be written to the same file without re-executing jpeg_stdio_dest.\n   * This makes it dangerous to use this manager and a different destination\n   * manager serially with the same JPEG object, because their private object\n   * sizes may be different.  Caveat programmer.\n   */\n  if (cinfo->dest == NULL) {\t/* first time for this JPEG object? */\n    cinfo->dest = (struct jpeg_destination_mgr *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  SIZEOF(my_destination_mgr));\n  }\n\n  dest = (my_dest_ptr) cinfo->dest;\n  dest->pub.init_destination = init_destination;\n  dest->pub.empty_output_buffer = empty_output_buffer;\n  dest->pub.term_destination = term_destination;\n  dest->outfile = outfile;\n}\n\n\n/*\n * Prepare for output to a memory buffer.\n * The caller may supply an own initial buffer with appropriate size.\n * Otherwise, or when the actual data output exceeds the given size,\n * the library adapts the buffer size as necessary.\n * The standard library functions malloc/free are used for allocating\n * larger memory, so the buffer is available to the application after\n * finishing compression, and then the application is responsible for\n * freeing the requested memory.\n * Note:  An initial buffer supplied by the caller is expected to be\n * managed by the application.  The library does not free such buffer\n * when allocating a larger buffer.\n */\n\nGLOBAL(void)\njpeg_mem_dest (j_compress_ptr cinfo,\n\t       unsigned char ** outbuffer, unsigned long * outsize)\n{\n  my_mem_dest_ptr dest;\n\n  if (outbuffer == NULL || outsize == NULL)\t/* sanity check */\n    ERREXIT(cinfo, JERR_BUFFER_SIZE);\n\n  /* The destination object is made permanent so that multiple JPEG images\n   * can be written to the same buffer without re-executing jpeg_mem_dest.\n   */\n  if (cinfo->dest == NULL) {\t/* first time for this JPEG object? */\n    cinfo->dest = (struct jpeg_destination_mgr *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  SIZEOF(my_mem_destination_mgr));\n  }\n\n  dest = (my_mem_dest_ptr) cinfo->dest;\n  dest->pub.init_destination = init_mem_destination;\n  dest->pub.empty_output_buffer = empty_mem_output_buffer;\n  dest->pub.term_destination = term_mem_destination;\n  dest->outbuffer = outbuffer;\n  dest->outsize = outsize;\n  dest->newbuffer = NULL;\n\n  if (*outbuffer == NULL || *outsize == 0) {\n    /* Allocate initial buffer */\n    dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);\n    if (dest->newbuffer == NULL)\n      ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);\n    *outsize = OUTPUT_BUF_SIZE;\n  }\n\n  dest->pub.next_output_byte = dest->buffer = *outbuffer;\n  dest->pub.free_in_buffer = dest->bufsize = *outsize;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdatasrc.c",
    "content": "/*\n * jdatasrc.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2009-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains decompression data source routines for the case of\n * reading JPEG data from memory or from a file (or any stdio stream).\n * While these routines are sufficient for most applications,\n * some will want to use a different source manager.\n * IMPORTANT: we assume that fread() will correctly transcribe an array of\n * JOCTETs from 8-bit-wide elements on external storage.  If char is wider\n * than 8 bits on your machine, you may need to do some tweaking.\n */\n\n/* this is not a core library module, so it doesn't define JPEG_INTERNALS */\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jerror.h\"\n\n\n/* Expanded data source object for stdio input */\n\ntypedef struct {\n  struct jpeg_source_mgr pub;\t/* public fields */\n\n  FILE * infile;\t\t/* source stream */\n  JOCTET * buffer;\t\t/* start of buffer */\n  boolean start_of_file;\t/* have we gotten any data yet? */\n} my_source_mgr;\n\ntypedef my_source_mgr * my_src_ptr;\n\n#define INPUT_BUF_SIZE  4096\t/* choose an efficiently fread'able size */\n\n\n/*\n * Initialize source --- called by jpeg_read_header\n * before any data is actually read.\n */\n\nMETHODDEF(void)\ninit_source (j_decompress_ptr cinfo)\n{\n  my_src_ptr src = (my_src_ptr) cinfo->src;\n\n  /* We reset the empty-input-file flag for each image,\n   * but we don't clear the input buffer.\n   * This is correct behavior for reading a series of images from one source.\n   */\n  src->start_of_file = TRUE;\n}\n\nMETHODDEF(void)\ninit_mem_source (j_decompress_ptr cinfo)\n{\n  /* no work necessary here */\n}\n\n\n/*\n * Fill the input buffer --- called whenever buffer is emptied.\n *\n * In typical applications, this should read fresh data into the buffer\n * (ignoring the current state of next_input_byte & bytes_in_buffer),\n * reset the pointer & count to the start of the buffer, and return TRUE\n * indicating that the buffer has been reloaded.  It is not necessary to\n * fill the buffer entirely, only to obtain at least one more byte.\n *\n * There is no such thing as an EOF return.  If the end of the file has been\n * reached, the routine has a choice of ERREXIT() or inserting fake data into\n * the buffer.  In most cases, generating a warning message and inserting a\n * fake EOI marker is the best course of action --- this will allow the\n * decompressor to output however much of the image is there.  However,\n * the resulting error message is misleading if the real problem is an empty\n * input file, so we handle that case specially.\n *\n * In applications that need to be able to suspend compression due to input\n * not being available yet, a FALSE return indicates that no more data can be\n * obtained right now, but more may be forthcoming later.  In this situation,\n * the decompressor will return to its caller (with an indication of the\n * number of scanlines it has read, if any).  The application should resume\n * decompression after it has loaded more data into the input buffer.  Note\n * that there are substantial restrictions on the use of suspension --- see\n * the documentation.\n *\n * When suspending, the decompressor will back up to a convenient restart point\n * (typically the start of the current MCU). next_input_byte & bytes_in_buffer\n * indicate where the restart point will be if the current call returns FALSE.\n * Data beyond this point must be rescanned after resumption, so move it to\n * the front of the buffer rather than discarding it.\n */\n\nMETHODDEF(boolean)\nfill_input_buffer (j_decompress_ptr cinfo)\n{\n  my_src_ptr src = (my_src_ptr) cinfo->src;\n  size_t nbytes;\n\n  nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);\n\n  if (nbytes <= 0) {\n    if (src->start_of_file)\t/* Treat empty input file as fatal error */\n      ERREXIT(cinfo, JERR_INPUT_EMPTY);\n    WARNMS(cinfo, JWRN_JPEG_EOF);\n    /* Insert a fake EOI marker */\n    src->buffer[0] = (JOCTET) 0xFF;\n    src->buffer[1] = (JOCTET) JPEG_EOI;\n    nbytes = 2;\n  }\n\n  src->pub.next_input_byte = src->buffer;\n  src->pub.bytes_in_buffer = nbytes;\n  src->start_of_file = FALSE;\n\n  return TRUE;\n}\n\nMETHODDEF(boolean)\nfill_mem_input_buffer (j_decompress_ptr cinfo)\n{\n  static const JOCTET mybuffer[4] = {\n    (JOCTET) 0xFF, (JOCTET) JPEG_EOI, 0, 0\n  };\n\n  /* The whole JPEG data is expected to reside in the supplied memory\n   * buffer, so any request for more data beyond the given buffer size\n   * is treated as an error.\n   */\n  WARNMS(cinfo, JWRN_JPEG_EOF);\n\n  /* Insert a fake EOI marker */\n\n  cinfo->src->next_input_byte = mybuffer;\n  cinfo->src->bytes_in_buffer = 2;\n\n  return TRUE;\n}\n\n\n/*\n * Skip data --- used to skip over a potentially large amount of\n * uninteresting data (such as an APPn marker).\n *\n * Writers of suspendable-input applications must note that skip_input_data\n * is not granted the right to give a suspension return.  If the skip extends\n * beyond the data currently in the buffer, the buffer can be marked empty so\n * that the next read will cause a fill_input_buffer call that can suspend.\n * Arranging for additional bytes to be discarded before reloading the input\n * buffer is the application writer's problem.\n */\n\nMETHODDEF(void)\nskip_input_data (j_decompress_ptr cinfo, long num_bytes)\n{\n  struct jpeg_source_mgr * src = cinfo->src;\n\n  /* Just a dumb implementation for now.  Could use fseek() except\n   * it doesn't work on pipes.  Not clear that being smart is worth\n   * any trouble anyway --- large skips are infrequent.\n   */\n  if (num_bytes > 0) {\n    while (num_bytes > (long) src->bytes_in_buffer) {\n      num_bytes -= (long) src->bytes_in_buffer;\n      (void) (*src->fill_input_buffer) (cinfo);\n      /* note we assume that fill_input_buffer will never return FALSE,\n       * so suspension need not be handled.\n       */\n    }\n    src->next_input_byte += (size_t) num_bytes;\n    src->bytes_in_buffer -= (size_t) num_bytes;\n  }\n}\n\n\n/*\n * An additional method that can be provided by data source modules is the\n * resync_to_restart method for error recovery in the presence of RST markers.\n * For the moment, this source module just uses the default resync method\n * provided by the JPEG library.  That method assumes that no backtracking\n * is possible.\n */\n\n\n/*\n * Terminate source --- called by jpeg_finish_decompress\n * after all data has been read.  Often a no-op.\n *\n * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding\n * application must deal with any cleanup that should happen even\n * for error exit.\n */\n\nMETHODDEF(void)\nterm_source (j_decompress_ptr cinfo)\n{\n  /* no work necessary here */\n}\n\n\n/*\n * Prepare for input from a stdio stream.\n * The caller must have already opened the stream, and is responsible\n * for closing it after finishing decompression.\n */\n\nGLOBAL(void)\njpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)\n{\n  my_src_ptr src;\n\n  /* The source object and input buffer are made permanent so that a series\n   * of JPEG images can be read from the same file by calling jpeg_stdio_src\n   * only before the first one.  (If we discarded the buffer at the end of\n   * one image, we'd likely lose the start of the next one.)\n   * This makes it unsafe to use this manager and a different source\n   * manager serially with the same JPEG object.  Caveat programmer.\n   */\n  if (cinfo->src == NULL) {\t/* first time for this JPEG object? */\n    cinfo->src = (struct jpeg_source_mgr *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  SIZEOF(my_source_mgr));\n    src = (my_src_ptr) cinfo->src;\n    src->buffer = (JOCTET *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  INPUT_BUF_SIZE * SIZEOF(JOCTET));\n  }\n\n  src = (my_src_ptr) cinfo->src;\n  src->pub.init_source = init_source;\n  src->pub.fill_input_buffer = fill_input_buffer;\n  src->pub.skip_input_data = skip_input_data;\n  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */\n  src->pub.term_source = term_source;\n  src->infile = infile;\n  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */\n  src->pub.next_input_byte = NULL; /* until buffer loaded */\n}\n\n\n/*\n * Prepare for input from a supplied memory buffer.\n * The buffer must contain the whole JPEG data.\n */\n\nGLOBAL(void)\njpeg_mem_src (j_decompress_ptr cinfo,\n\t      const unsigned char * inbuffer, unsigned long insize)\n{\n  struct jpeg_source_mgr * src;\n\n  if (inbuffer == NULL || insize == 0)\t/* Treat empty input as fatal error */\n    ERREXIT(cinfo, JERR_INPUT_EMPTY);\n\n  /* The source object is made permanent so that a series of JPEG images\n   * can be read from the same buffer by calling jpeg_mem_src only before\n   * the first one.\n   */\n  if (cinfo->src == NULL) {\t/* first time for this JPEG object? */\n    cinfo->src = (struct jpeg_source_mgr *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\t  SIZEOF(struct jpeg_source_mgr));\n  }\n\n  src = cinfo->src;\n  src->init_source = init_mem_source;\n  src->fill_input_buffer = fill_mem_input_buffer;\n  src->skip_input_data = skip_input_data;\n  src->resync_to_restart = jpeg_resync_to_restart; /* use default method */\n  src->term_source = term_source;\n  src->bytes_in_buffer = (size_t) insize;\n  src->next_input_byte = (const JOCTET *) inbuffer;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdcoefct.c",
    "content": "/*\n * jdcoefct.c\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 2002-2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the coefficient buffer controller for decompression.\n * This controller is the top level of the JPEG decompressor proper.\n * The coefficient buffer lies between entropy decoding and inverse-DCT steps.\n *\n * In buffered-image mode, this controller is the interface between\n * input-oriented processing and output-oriented processing.\n * Also, the input side (only) is used when reading a file for transcoding.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n/* Block smoothing is only applicable for progressive JPEG, so: */\n#ifndef D_PROGRESSIVE_SUPPORTED\n#undef BLOCK_SMOOTHING_SUPPORTED\n#endif\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_d_coef_controller pub; /* public fields */\n\n  /* These variables keep track of the current location of the input side. */\n  /* cinfo->input_iMCU_row is also used for this. */\n  JDIMENSION MCU_ctr;\t\t/* counts MCUs processed in current row */\n  int MCU_vert_offset;\t\t/* counts MCU rows within iMCU row */\n  int MCU_rows_per_iMCU_row;\t/* number of such rows needed */\n\n  /* The output side's location is represented by cinfo->output_iMCU_row. */\n\n  /* In single-pass modes, it's sufficient to buffer just one MCU.\n   * We allocate a workspace of D_MAX_BLOCKS_IN_MCU coefficient blocks,\n   * and let the entropy decoder write into that workspace each time.\n   * (On 80x86, the workspace is FAR even though it's not really very big;\n   * this is to keep the module interfaces unchanged when a large coefficient\n   * buffer is necessary.)\n   * In multi-pass modes, this array points to the current MCU's blocks\n   * within the virtual arrays; it is used only by the input side.\n   */\n  JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];\n\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n  /* In multi-pass modes, we need a virtual block array for each component. */\n  jvirt_barray_ptr whole_image[MAX_COMPONENTS];\n#endif\n\n#ifdef BLOCK_SMOOTHING_SUPPORTED\n  /* When doing block smoothing, we latch coefficient Al values here */\n  int * coef_bits_latch;\n#define SAVED_COEFS  6\t\t/* we save coef_bits[0..5] */\n#endif\n} my_coef_controller;\n\ntypedef my_coef_controller * my_coef_ptr;\n\n/* Forward declarations */\nMETHODDEF(int) decompress_onepass\n\tJPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\n#ifdef D_MULTISCAN_FILES_SUPPORTED\nMETHODDEF(int) decompress_data\n\tJPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\n#endif\n#ifdef BLOCK_SMOOTHING_SUPPORTED\nLOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));\nMETHODDEF(int) decompress_smooth_data\n\tJPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));\n#endif\n\n\nLOCAL(void)\nstart_iMCU_row (j_decompress_ptr cinfo)\n/* Reset within-iMCU-row counters for a new row (input side) */\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  /* In an interleaved scan, an MCU row is the same as an iMCU row.\n   * In a noninterleaved scan, an iMCU row has v_samp_factor MCU rows.\n   * But at the bottom of the image, process only what's left.\n   */\n  if (cinfo->comps_in_scan > 1) {\n    coef->MCU_rows_per_iMCU_row = 1;\n  } else {\n    if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;\n    else\n      coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;\n  }\n\n  coef->MCU_ctr = 0;\n  coef->MCU_vert_offset = 0;\n}\n\n\n/*\n * Initialize for an input processing pass.\n */\n\nMETHODDEF(void)\nstart_input_pass (j_decompress_ptr cinfo)\n{\n  cinfo->input_iMCU_row = 0;\n  start_iMCU_row(cinfo);\n}\n\n\n/*\n * Initialize for an output processing pass.\n */\n\nMETHODDEF(void)\nstart_output_pass (j_decompress_ptr cinfo)\n{\n#ifdef BLOCK_SMOOTHING_SUPPORTED\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n\n  /* If multipass, check to see whether to use block smoothing on this pass */\n  if (coef->pub.coef_arrays != NULL) {\n    if (cinfo->do_block_smoothing && smoothing_ok(cinfo))\n      coef->pub.decompress_data = decompress_smooth_data;\n    else\n      coef->pub.decompress_data = decompress_data;\n  }\n#endif\n  cinfo->output_iMCU_row = 0;\n}\n\n\n/*\n * Decompress and return some data in the single-pass case.\n * Always attempts to emit one fully interleaved MCU row (\"iMCU\" row).\n * Input and output must run in lockstep since we have only a one-MCU buffer.\n * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\n *\n * NB: output_buf contains a plane for each component in image,\n * which we index according to the component's SOF position.\n */\n\nMETHODDEF(int)\ndecompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION MCU_col_num;\t/* index of current MCU within row */\n  JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  int blkn, ci, xindex, yindex, yoffset, useful_width;\n  JSAMPARRAY output_ptr;\n  JDIMENSION start_col, output_col;\n  jpeg_component_info *compptr;\n  inverse_DCT_method_ptr inverse_DCT;\n\n  /* Loop to process as much as one whole iMCU row */\n  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\n       yoffset++) {\n    for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;\n\t MCU_col_num++) {\n      /* Try to fetch an MCU.  Entropy decoder expects buffer to be zeroed. */\n      if (cinfo->lim_Se)\t/* can bypass in DC only case */\n\tFMEMZERO((void FAR *) coef->MCU_buffer[0],\n\t\t (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));\n      if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {\n\t/* Suspension forced; update state counters and exit */\n\tcoef->MCU_vert_offset = yoffset;\n\tcoef->MCU_ctr = MCU_col_num;\n\treturn JPEG_SUSPENDED;\n      }\n      /* Determine where data should go in output_buf and do the IDCT thing.\n       * We skip dummy blocks at the right and bottom edges (but blkn gets\n       * incremented past them!).  Note the inner loop relies on having\n       * allocated the MCU_buffer[] blocks sequentially.\n       */\n      blkn = 0;\t\t\t/* index of current DCT block within MCU */\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n\tcompptr = cinfo->cur_comp_info[ci];\n\t/* Don't bother to IDCT an uninteresting component. */\n\tif (! compptr->component_needed) {\n\t  blkn += compptr->MCU_blocks;\n\t  continue;\n\t}\n\tinverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];\n\tuseful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width\n\t\t\t\t\t\t    : compptr->last_col_width;\n\toutput_ptr = output_buf[compptr->component_index] +\n\t  yoffset * compptr->DCT_v_scaled_size;\n\tstart_col = MCU_col_num * compptr->MCU_sample_width;\n\tfor (yindex = 0; yindex < compptr->MCU_height; yindex++) {\n\t  if (cinfo->input_iMCU_row < last_iMCU_row ||\n\t      yoffset+yindex < compptr->last_row_height) {\n\t    output_col = start_col;\n\t    for (xindex = 0; xindex < useful_width; xindex++) {\n\t      (*inverse_DCT) (cinfo, compptr,\n\t\t\t      (JCOEFPTR) coef->MCU_buffer[blkn+xindex],\n\t\t\t      output_ptr, output_col);\n\t      output_col += compptr->DCT_h_scaled_size;\n\t    }\n\t  }\n\t  blkn += compptr->MCU_width;\n\t  output_ptr += compptr->DCT_v_scaled_size;\n\t}\n      }\n    }\n    /* Completed an MCU row, but perhaps not an iMCU row */\n    coef->MCU_ctr = 0;\n  }\n  /* Completed the iMCU row, advance counters for next one */\n  cinfo->output_iMCU_row++;\n  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {\n    start_iMCU_row(cinfo);\n    return JPEG_ROW_COMPLETED;\n  }\n  /* Completed the scan */\n  (*cinfo->inputctl->finish_input_pass) (cinfo);\n  return JPEG_SCAN_COMPLETED;\n}\n\n\n/*\n * Dummy consume-input routine for single-pass operation.\n */\n\nMETHODDEF(int)\ndummy_consume_data (j_decompress_ptr cinfo)\n{\n  return JPEG_SUSPENDED;\t/* Always indicate nothing was done */\n}\n\n\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n\n/*\n * Consume input data and store it in the full-image coefficient buffer.\n * We read as much as one fully interleaved MCU row (\"iMCU\" row) per call,\n * ie, v_samp_factor block rows for each component in the scan.\n * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\n */\n\nMETHODDEF(int)\nconsume_data (j_decompress_ptr cinfo)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION MCU_col_num;\t/* index of current MCU within row */\n  int blkn, ci, xindex, yindex, yoffset;\n  JDIMENSION start_col;\n  JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];\n  JBLOCKROW buffer_ptr;\n  jpeg_component_info *compptr;\n\n  /* Align the virtual buffers for the components used in this scan. */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    buffer[ci] = (*cinfo->mem->access_virt_barray)\n      ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],\n       cinfo->input_iMCU_row * compptr->v_samp_factor,\n       (JDIMENSION) compptr->v_samp_factor, TRUE);\n    /* Note: entropy decoder expects buffer to be zeroed,\n     * but this is handled automatically by the memory manager\n     * because we requested a pre-zeroed array.\n     */\n  }\n\n  /* Loop to process one whole iMCU row */\n  for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;\n       yoffset++) {\n    for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;\n\t MCU_col_num++) {\n      /* Construct list of pointers to DCT blocks belonging to this MCU */\n      blkn = 0;\t\t\t/* index of current DCT block within MCU */\n      for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n\tcompptr = cinfo->cur_comp_info[ci];\n\tstart_col = MCU_col_num * compptr->MCU_width;\n\tfor (yindex = 0; yindex < compptr->MCU_height; yindex++) {\n\t  buffer_ptr = buffer[ci][yindex+yoffset] + start_col;\n\t  for (xindex = 0; xindex < compptr->MCU_width; xindex++) {\n\t    coef->MCU_buffer[blkn++] = buffer_ptr++;\n\t  }\n\t}\n      }\n      /* Try to fetch the MCU. */\n      if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {\n\t/* Suspension forced; update state counters and exit */\n\tcoef->MCU_vert_offset = yoffset;\n\tcoef->MCU_ctr = MCU_col_num;\n\treturn JPEG_SUSPENDED;\n      }\n    }\n    /* Completed an MCU row, but perhaps not an iMCU row */\n    coef->MCU_ctr = 0;\n  }\n  /* Completed the iMCU row, advance counters for next one */\n  if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {\n    start_iMCU_row(cinfo);\n    return JPEG_ROW_COMPLETED;\n  }\n  /* Completed the scan */\n  (*cinfo->inputctl->finish_input_pass) (cinfo);\n  return JPEG_SCAN_COMPLETED;\n}\n\n\n/*\n * Decompress and return some data in the multi-pass case.\n * Always attempts to emit one fully interleaved MCU row (\"iMCU\" row).\n * Return value is JPEG_ROW_COMPLETED, JPEG_SCAN_COMPLETED, or JPEG_SUSPENDED.\n *\n * NB: output_buf contains a plane for each component in image.\n */\n\nMETHODDEF(int)\ndecompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  JDIMENSION block_num;\n  int ci, block_row, block_rows;\n  JBLOCKARRAY buffer;\n  JBLOCKROW buffer_ptr;\n  JSAMPARRAY output_ptr;\n  JDIMENSION output_col;\n  jpeg_component_info *compptr;\n  inverse_DCT_method_ptr inverse_DCT;\n\n  /* Force some input to be done if we are getting ahead of the input. */\n  while (cinfo->input_scan_number < cinfo->output_scan_number ||\n\t (cinfo->input_scan_number == cinfo->output_scan_number &&\n\t  cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {\n    if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)\n      return JPEG_SUSPENDED;\n  }\n\n  /* OK, output from the virtual arrays. */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Don't bother to IDCT an uninteresting component. */\n    if (! compptr->component_needed)\n      continue;\n    /* Align the virtual buffer for this component. */\n    buffer = (*cinfo->mem->access_virt_barray)\n      ((j_common_ptr) cinfo, coef->whole_image[ci],\n       cinfo->output_iMCU_row * compptr->v_samp_factor,\n       (JDIMENSION) compptr->v_samp_factor, FALSE);\n    /* Count non-dummy DCT block rows in this iMCU row. */\n    if (cinfo->output_iMCU_row < last_iMCU_row)\n      block_rows = compptr->v_samp_factor;\n    else {\n      /* NB: can't use last_row_height here; it is input-side-dependent! */\n      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\n      if (block_rows == 0) block_rows = compptr->v_samp_factor;\n    }\n    inverse_DCT = cinfo->idct->inverse_DCT[ci];\n    output_ptr = output_buf[ci];\n    /* Loop over all DCT blocks to be processed. */\n    for (block_row = 0; block_row < block_rows; block_row++) {\n      buffer_ptr = buffer[block_row];\n      output_col = 0;\n      for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {\n\t(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,\n\t\t\toutput_ptr, output_col);\n\tbuffer_ptr++;\n\toutput_col += compptr->DCT_h_scaled_size;\n      }\n      output_ptr += compptr->DCT_v_scaled_size;\n    }\n  }\n\n  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)\n    return JPEG_ROW_COMPLETED;\n  return JPEG_SCAN_COMPLETED;\n}\n\n#endif /* D_MULTISCAN_FILES_SUPPORTED */\n\n\n#ifdef BLOCK_SMOOTHING_SUPPORTED\n\n/*\n * This code applies interblock smoothing as described by section K.8\n * of the JPEG standard: the first 5 AC coefficients are estimated from\n * the DC values of a DCT block and its 8 neighboring blocks.\n * We apply smoothing only for progressive JPEG decoding, and only if\n * the coefficients it can estimate are not yet known to full precision.\n */\n\n/* Natural-order array positions of the first 5 zigzag-order coefficients */\n#define Q01_POS  1\n#define Q10_POS  8\n#define Q20_POS  16\n#define Q11_POS  9\n#define Q02_POS  2\n\n/*\n * Determine whether block smoothing is applicable and safe.\n * We also latch the current states of the coef_bits[] entries for the\n * AC coefficients; otherwise, if the input side of the decompressor\n * advances into a new scan, we might think the coefficients are known\n * more accurately than they really are.\n */\n\nLOCAL(boolean)\nsmoothing_ok (j_decompress_ptr cinfo)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  boolean smoothing_useful = FALSE;\n  int ci, coefi;\n  jpeg_component_info *compptr;\n  JQUANT_TBL * qtable;\n  int * coef_bits;\n  int * coef_bits_latch;\n\n  if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)\n    return FALSE;\n\n  /* Allocate latch area if not already done */\n  if (coef->coef_bits_latch == NULL)\n    coef->coef_bits_latch = (int *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  cinfo->num_components *\n\t\t\t\t  (SAVED_COEFS * SIZEOF(int)));\n  coef_bits_latch = coef->coef_bits_latch;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* All components' quantization values must already be latched. */\n    if ((qtable = compptr->quant_table) == NULL)\n      return FALSE;\n    /* Verify DC & first 5 AC quantizers are nonzero to avoid zero-divide. */\n    if (qtable->quantval[0] == 0 ||\n\tqtable->quantval[Q01_POS] == 0 ||\n\tqtable->quantval[Q10_POS] == 0 ||\n\tqtable->quantval[Q20_POS] == 0 ||\n\tqtable->quantval[Q11_POS] == 0 ||\n\tqtable->quantval[Q02_POS] == 0)\n      return FALSE;\n    /* DC values must be at least partly known for all components. */\n    coef_bits = cinfo->coef_bits[ci];\n    if (coef_bits[0] < 0)\n      return FALSE;\n    /* Block smoothing is helpful if some AC coefficients remain inaccurate. */\n    for (coefi = 1; coefi <= 5; coefi++) {\n      coef_bits_latch[coefi] = coef_bits[coefi];\n      if (coef_bits[coefi] != 0)\n\tsmoothing_useful = TRUE;\n    }\n    coef_bits_latch += SAVED_COEFS;\n  }\n\n  return smoothing_useful;\n}\n\n\n/*\n * Variant of decompress_data for use when doing block smoothing.\n */\n\nMETHODDEF(int)\ndecompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)\n{\n  my_coef_ptr coef = (my_coef_ptr) cinfo->coef;\n  JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;\n  JDIMENSION block_num, last_block_column;\n  int ci, block_row, block_rows, access_rows;\n  JBLOCKARRAY buffer;\n  JBLOCKROW buffer_ptr, prev_block_row, next_block_row;\n  JSAMPARRAY output_ptr;\n  JDIMENSION output_col;\n  jpeg_component_info *compptr;\n  inverse_DCT_method_ptr inverse_DCT;\n  boolean first_row, last_row;\n  JBLOCK workspace;\n  int *coef_bits;\n  JQUANT_TBL *quanttbl;\n  INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;\n  int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;\n  int Al, pred;\n\n  /* Force some input to be done if we are getting ahead of the input. */\n  while (cinfo->input_scan_number <= cinfo->output_scan_number &&\n\t ! cinfo->inputctl->eoi_reached) {\n    if (cinfo->input_scan_number == cinfo->output_scan_number) {\n      /* If input is working on current scan, we ordinarily want it to\n       * have completed the current row.  But if input scan is DC,\n       * we want it to keep one row ahead so that next block row's DC\n       * values are up to date.\n       */\n      JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;\n      if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)\n\tbreak;\n    }\n    if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)\n      return JPEG_SUSPENDED;\n  }\n\n  /* OK, output from the virtual arrays. */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Don't bother to IDCT an uninteresting component. */\n    if (! compptr->component_needed)\n      continue;\n    /* Count non-dummy DCT block rows in this iMCU row. */\n    if (cinfo->output_iMCU_row < last_iMCU_row) {\n      block_rows = compptr->v_samp_factor;\n      access_rows = block_rows * 2; /* this and next iMCU row */\n      last_row = FALSE;\n    } else {\n      /* NB: can't use last_row_height here; it is input-side-dependent! */\n      block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\n      if (block_rows == 0) block_rows = compptr->v_samp_factor;\n      access_rows = block_rows; /* this iMCU row only */\n      last_row = TRUE;\n    }\n    /* Align the virtual buffer for this component. */\n    if (cinfo->output_iMCU_row > 0) {\n      access_rows += compptr->v_samp_factor; /* prior iMCU row too */\n      buffer = (*cinfo->mem->access_virt_barray)\n\t((j_common_ptr) cinfo, coef->whole_image[ci],\n\t (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,\n\t (JDIMENSION) access_rows, FALSE);\n      buffer += compptr->v_samp_factor;\t/* point to current iMCU row */\n      first_row = FALSE;\n    } else {\n      buffer = (*cinfo->mem->access_virt_barray)\n\t((j_common_ptr) cinfo, coef->whole_image[ci],\n\t (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);\n      first_row = TRUE;\n    }\n    /* Fetch component-dependent info */\n    coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);\n    quanttbl = compptr->quant_table;\n    Q00 = quanttbl->quantval[0];\n    Q01 = quanttbl->quantval[Q01_POS];\n    Q10 = quanttbl->quantval[Q10_POS];\n    Q20 = quanttbl->quantval[Q20_POS];\n    Q11 = quanttbl->quantval[Q11_POS];\n    Q02 = quanttbl->quantval[Q02_POS];\n    inverse_DCT = cinfo->idct->inverse_DCT[ci];\n    output_ptr = output_buf[ci];\n    /* Loop over all DCT blocks to be processed. */\n    for (block_row = 0; block_row < block_rows; block_row++) {\n      buffer_ptr = buffer[block_row];\n      if (first_row && block_row == 0)\n\tprev_block_row = buffer_ptr;\n      else\n\tprev_block_row = buffer[block_row-1];\n      if (last_row && block_row == block_rows-1)\n\tnext_block_row = buffer_ptr;\n      else\n\tnext_block_row = buffer[block_row+1];\n      /* We fetch the surrounding DC values using a sliding-register approach.\n       * Initialize all nine here so as to do the right thing on narrow pics.\n       */\n      DC1 = DC2 = DC3 = (int) prev_block_row[0][0];\n      DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];\n      DC7 = DC8 = DC9 = (int) next_block_row[0][0];\n      output_col = 0;\n      last_block_column = compptr->width_in_blocks - 1;\n      for (block_num = 0; block_num <= last_block_column; block_num++) {\n\t/* Fetch current DCT block into workspace so we can modify it. */\n\tjcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);\n\t/* Update DC values */\n\tif (block_num < last_block_column) {\n\t  DC3 = (int) prev_block_row[1][0];\n\t  DC6 = (int) buffer_ptr[1][0];\n\t  DC9 = (int) next_block_row[1][0];\n\t}\n\t/* Compute coefficient estimates per K.8.\n\t * An estimate is applied only if coefficient is still zero,\n\t * and is not known to be fully accurate.\n\t */\n\t/* AC01 */\n\tif ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {\n\t  num = 36 * Q00 * (DC4 - DC6);\n\t  if (num >= 0) {\n\t    pred = (int) (((Q01<<7) + num) / (Q01<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t  } else {\n\t    pred = (int) (((Q01<<7) - num) / (Q01<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t    pred = -pred;\n\t  }\n\t  workspace[1] = (JCOEF) pred;\n\t}\n\t/* AC10 */\n\tif ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {\n\t  num = 36 * Q00 * (DC2 - DC8);\n\t  if (num >= 0) {\n\t    pred = (int) (((Q10<<7) + num) / (Q10<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t  } else {\n\t    pred = (int) (((Q10<<7) - num) / (Q10<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t    pred = -pred;\n\t  }\n\t  workspace[8] = (JCOEF) pred;\n\t}\n\t/* AC20 */\n\tif ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {\n\t  num = 9 * Q00 * (DC2 + DC8 - 2*DC5);\n\t  if (num >= 0) {\n\t    pred = (int) (((Q20<<7) + num) / (Q20<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t  } else {\n\t    pred = (int) (((Q20<<7) - num) / (Q20<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t    pred = -pred;\n\t  }\n\t  workspace[16] = (JCOEF) pred;\n\t}\n\t/* AC11 */\n\tif ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {\n\t  num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);\n\t  if (num >= 0) {\n\t    pred = (int) (((Q11<<7) + num) / (Q11<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t  } else {\n\t    pred = (int) (((Q11<<7) - num) / (Q11<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t    pred = -pred;\n\t  }\n\t  workspace[9] = (JCOEF) pred;\n\t}\n\t/* AC02 */\n\tif ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {\n\t  num = 9 * Q00 * (DC4 + DC6 - 2*DC5);\n\t  if (num >= 0) {\n\t    pred = (int) (((Q02<<7) + num) / (Q02<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t  } else {\n\t    pred = (int) (((Q02<<7) - num) / (Q02<<8));\n\t    if (Al > 0 && pred >= (1<<Al))\n\t      pred = (1<<Al)-1;\n\t    pred = -pred;\n\t  }\n\t  workspace[2] = (JCOEF) pred;\n\t}\n\t/* OK, do the IDCT */\n\t(*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,\n\t\t\toutput_ptr, output_col);\n\t/* Advance for next column */\n\tDC1 = DC2; DC2 = DC3;\n\tDC4 = DC5; DC5 = DC6;\n\tDC7 = DC8; DC8 = DC9;\n\tbuffer_ptr++, prev_block_row++, next_block_row++;\n\toutput_col += compptr->DCT_h_scaled_size;\n      }\n      output_ptr += compptr->DCT_v_scaled_size;\n    }\n  }\n\n  if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)\n    return JPEG_ROW_COMPLETED;\n  return JPEG_SCAN_COMPLETED;\n}\n\n#endif /* BLOCK_SMOOTHING_SUPPORTED */\n\n\n/*\n * Initialize coefficient buffer controller.\n */\n\nGLOBAL(void)\njinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)\n{\n  my_coef_ptr coef;\n\n  coef = (my_coef_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_coef_controller));\n  cinfo->coef = (struct jpeg_d_coef_controller *) coef;\n  coef->pub.start_input_pass = start_input_pass;\n  coef->pub.start_output_pass = start_output_pass;\n#ifdef BLOCK_SMOOTHING_SUPPORTED\n  coef->coef_bits_latch = NULL;\n#endif\n\n  /* Create the coefficient buffer. */\n  if (need_full_buffer) {\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n    /* Allocate a full-image virtual array for each component, */\n    /* padded to a multiple of samp_factor DCT blocks in each direction. */\n    /* Note we ask for a pre-zeroed array. */\n    int ci, access_rows;\n    jpeg_component_info *compptr;\n\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      access_rows = compptr->v_samp_factor;\n#ifdef BLOCK_SMOOTHING_SUPPORTED\n      /* If block smoothing could be used, need a bigger window */\n      if (cinfo->progressive_mode)\n\taccess_rows *= 3;\n#endif\n      coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,\n\t (JDIMENSION) jround_up((long) compptr->width_in_blocks,\n\t\t\t\t(long) compptr->h_samp_factor),\n\t (JDIMENSION) jround_up((long) compptr->height_in_blocks,\n\t\t\t\t(long) compptr->v_samp_factor),\n\t (JDIMENSION) access_rows);\n    }\n    coef->pub.consume_data = consume_data;\n    coef->pub.decompress_data = decompress_data;\n    coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n  } else {\n    /* We only need a single-MCU buffer. */\n    JBLOCKROW buffer;\n    int i;\n\n    buffer = (JBLOCKROW)\n      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));\n    for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {\n      coef->MCU_buffer[i] = buffer + i;\n    }\n    if (cinfo->lim_Se == 0)\t/* DC only case: want to bypass later */\n      FMEMZERO((void FAR *) buffer,\n\t       (size_t) (D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK)));\n    coef->pub.consume_data = dummy_consume_data;\n    coef->pub.decompress_data = decompress_onepass;\n    coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdcolor.c",
    "content": "/*\n * jdcolor.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2011-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains output colorspace conversion routines.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_color_deconverter pub; /* public fields */\n\n  /* Private state for YCbCr->RGB and BG_YCC->RGB conversion */\n  int * Cr_r_tab;\t\t/* => table for Cr to R conversion */\n  int * Cb_b_tab;\t\t/* => table for Cb to B conversion */\n  INT32 * Cr_g_tab;\t\t/* => table for Cr to G conversion */\n  INT32 * Cb_g_tab;\t\t/* => table for Cb to G conversion */\n\n  /* Private state for RGB->Y conversion */\n  INT32 * rgb_y_tab;\t\t/* => table for RGB to Y conversion */\n} my_color_deconverter;\n\ntypedef my_color_deconverter * my_cconvert_ptr;\n\n\n/***************  YCbCr -> RGB conversion: most common case **************/\n/*************** BG_YCC -> RGB conversion: less common case **************/\n/***************    RGB -> Y   conversion: less common case **************/\n\n/*\n * YCbCr is defined per Recommendation ITU-R BT.601-7 (03/2011),\n * previously known as Recommendation CCIR 601-1, except that Cb and Cr\n * are normalized to the range 0..MAXJSAMPLE rather than -0.5 .. 0.5.\n * sRGB (standard RGB color space) is defined per IEC 61966-2-1:1999.\n * sYCC (standard luma-chroma-chroma color space with extended gamut)\n * is defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex F.\n * bg-sRGB and bg-sYCC (big gamut standard color spaces)\n * are defined per IEC 61966-2-1:1999 Amendment A1:2003 Annex G.\n * Note that the derived conversion coefficients given in some of these\n * documents are imprecise.  The general conversion equations are\n *\n *\tR = Y + K * (1 - Kr) * Cr\n *\tG = Y - K * (Kb * (1 - Kb) * Cb + Kr * (1 - Kr) * Cr) / (1 - Kr - Kb)\n *\tB = Y + K * (1 - Kb) * Cb\n *\n *\tY = Kr * R + (1 - Kr - Kb) * G + Kb * B\n *\n * With Kr = 0.299 and Kb = 0.114 (derived according to SMPTE RP 177-1993\n * from the 1953 FCC NTSC primaries and CIE Illuminant C), K = 2 for sYCC,\n * the conversion equations to be implemented are therefore\n *\n *\tR = Y + 1.402 * Cr\n *\tG = Y - 0.344136286 * Cb - 0.714136286 * Cr\n *\tB = Y + 1.772 * Cb\n *\n *\tY = 0.299 * R + 0.587 * G + 0.114 * B\n *\n * where Cb and Cr represent the incoming values less CENTERJSAMPLE.\n * For bg-sYCC, with K = 4, the equations are\n *\n *\tR = Y + 2.804 * Cr\n *\tG = Y - 0.688272572 * Cb - 1.428272572 * Cr\n *\tB = Y + 3.544 * Cb\n *\n * To avoid floating-point arithmetic, we represent the fractional constants\n * as integers scaled up by 2^16 (about 4 digits precision); we have to divide\n * the products by 2^16, with appropriate rounding, to get the correct answer.\n * Notice that Y, being an integral input, does not contribute any fraction\n * so it need not participate in the rounding.\n *\n * For even more speed, we avoid doing any multiplications in the inner loop\n * by precalculating the constants times Cb and Cr for all possible values.\n * For 8-bit JSAMPLEs this is very reasonable (only 256 entries per table);\n * for 9-bit to 12-bit samples it is still acceptable.  It's not very\n * reasonable for 16-bit samples, but if you want lossless storage you\n * shouldn't be changing colorspace anyway.\n * The Cr=>R and Cb=>B values can be rounded to integers in advance; the\n * values for the G calculation are left scaled up, since we must add them\n * together before rounding.\n */\n\n#define SCALEBITS\t16\t/* speediest right-shift on some machines */\n#define ONE_HALF\t((INT32) 1 << (SCALEBITS-1))\n#define FIX(x)\t\t((INT32) ((x) * (1L<<SCALEBITS) + 0.5))\n\n/* We allocate one big table for RGB->Y conversion and divide it up into\n * three parts, instead of doing three alloc_small requests.  This lets us\n * use a single table base address, which can be held in a register in the\n * inner loops on many machines (more than can hold all three addresses,\n * anyway).\n */\n\n#define R_Y_OFF\t\t0\t\t\t/* offset to R => Y section */\n#define G_Y_OFF\t\t(1*(MAXJSAMPLE+1))\t/* offset to G => Y section */\n#define B_Y_OFF\t\t(2*(MAXJSAMPLE+1))\t/* etc. */\n#define TABLE_SIZE\t(3*(MAXJSAMPLE+1))\n\n\n/*\n * Initialize tables for YCbCr->RGB and BG_YCC->RGB colorspace conversion.\n */\n\nLOCAL(void)\nbuild_ycc_rgb_table (j_decompress_ptr cinfo)\n/* Normal case, sYCC */\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  int i;\n  INT32 x;\n  SHIFT_TEMPS\n\n  cconvert->Cr_r_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  cconvert->Cb_b_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  cconvert->Cr_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n  cconvert->Cb_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n\n  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {\n    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */\n    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */\n    /* Cr=>R value is nearest int to 1.402 * x */\n    cconvert->Cr_r_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);\n    /* Cb=>B value is nearest int to 1.772 * x */\n    cconvert->Cb_b_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);\n    /* Cr=>G value is scaled-up -0.714136286 * x */\n    cconvert->Cr_g_tab[i] = (- FIX(0.714136286)) * x;\n    /* Cb=>G value is scaled-up -0.344136286 * x */\n    /* We also add in ONE_HALF so that need not do it in inner loop */\n    cconvert->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;\n  }\n}\n\n\nLOCAL(void)\nbuild_bg_ycc_rgb_table (j_decompress_ptr cinfo)\n/* Wide gamut case, bg-sYCC */\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  int i;\n  INT32 x;\n  SHIFT_TEMPS\n\n  cconvert->Cr_r_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  cconvert->Cb_b_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  cconvert->Cr_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n  cconvert->Cb_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n\n  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {\n    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */\n    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */\n    /* Cr=>R value is nearest int to 2.804 * x */\n    cconvert->Cr_r_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(2.804) * x + ONE_HALF, SCALEBITS);\n    /* Cb=>B value is nearest int to 3.544 * x */\n    cconvert->Cb_b_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(3.544) * x + ONE_HALF, SCALEBITS);\n    /* Cr=>G value is scaled-up -1.428272572 * x */\n    cconvert->Cr_g_tab[i] = (- FIX(1.428272572)) * x;\n    /* Cb=>G value is scaled-up -0.688272572 * x */\n    /* We also add in ONE_HALF so that need not do it in inner loop */\n    cconvert->Cb_g_tab[i] = (- FIX(0.688272572)) * x + ONE_HALF;\n  }\n}\n\n\n/*\n * Convert some rows of samples to the output colorspace.\n *\n * Note that we change from noninterleaved, one-plane-per-component format\n * to interleaved-pixel format.  The output buffer is therefore three times\n * as wide as the input buffer.\n * A starting row offset is provided only for the input buffer.  The caller\n * can easily adjust the passed output_buf value to accommodate any row\n * offset required on that side.\n */\n\nMETHODDEF(void)\nycc_rgb_convert (j_decompress_ptr cinfo,\n\t\t JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t JSAMPARRAY output_buf, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register int y, cb, cr;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n  /* copy these pointers into registers if possible */\n  register JSAMPLE * range_limit = cinfo->sample_range_limit;\n  register int * Crrtab = cconvert->Cr_r_tab;\n  register int * Cbbtab = cconvert->Cb_b_tab;\n  register INT32 * Crgtab = cconvert->Cr_g_tab;\n  register INT32 * Cbgtab = cconvert->Cb_g_tab;\n  SHIFT_TEMPS\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      y  = GETJSAMPLE(inptr0[col]);\n      cb = GETJSAMPLE(inptr1[col]);\n      cr = GETJSAMPLE(inptr2[col]);\n      /* Range-limiting is essential due to noise introduced by DCT losses,\n       * for extended gamut (sYCC) and wide gamut (bg-sYCC) encodings.\n       */\n      outptr[RGB_RED]   = range_limit[y + Crrtab[cr]];\n      outptr[RGB_GREEN] = range_limit[y +\n\t\t\t      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],\n\t\t\t\t\t\t SCALEBITS))];\n      outptr[RGB_BLUE]  = range_limit[y + Cbbtab[cb]];\n      outptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/**************** Cases other than YCC -> RGB ****************/\n\n\n/*\n * Initialize for RGB->grayscale colorspace conversion.\n */\n\nLOCAL(void)\nbuild_rgb_y_table (j_decompress_ptr cinfo)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  INT32 * rgb_y_tab;\n  INT32 i;\n\n  /* Allocate and fill in the conversion tables. */\n  cconvert->rgb_y_tab = rgb_y_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(TABLE_SIZE * SIZEOF(INT32)));\n\n  for (i = 0; i <= MAXJSAMPLE; i++) {\n    rgb_y_tab[i+R_Y_OFF] = FIX(0.299) * i;\n    rgb_y_tab[i+G_Y_OFF] = FIX(0.587) * i;\n    rgb_y_tab[i+B_Y_OFF] = FIX(0.114) * i + ONE_HALF;\n  }\n}\n\n\n/*\n * Convert RGB to grayscale.\n */\n\nMETHODDEF(void)\nrgb_gray_convert (j_decompress_ptr cinfo,\n\t\t  JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t  JSAMPARRAY output_buf, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register INT32 * ctab = cconvert->rgb_y_tab;\n  register int r, g, b;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr0[col]);\n      g = GETJSAMPLE(inptr1[col]);\n      b = GETJSAMPLE(inptr2[col]);\n      /* Y */\n      outptr[col] = (JSAMPLE)\n\t\t((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])\n\t\t >> SCALEBITS);\n    }\n  }\n}\n\n\n/*\n * [R-G,G,B-G] to [R,G,B] conversion with modulo calculation\n * (inverse color transform).\n * This can be seen as an adaption of the general YCbCr->RGB\n * conversion equation with Kr = Kb = 0, while replacing the\n * normalization by modulo calculation.\n */\n\nMETHODDEF(void)\nrgb1_rgb_convert (j_decompress_ptr cinfo,\n\t\t  JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t  JSAMPARRAY output_buf, int num_rows)\n{\n  register int r, g, b;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr0[col]);\n      g = GETJSAMPLE(inptr1[col]);\n      b = GETJSAMPLE(inptr2[col]);\n      /* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD\n       * (modulo) operator is equivalent to the bitmask operator AND.\n       */\n      outptr[RGB_RED]   = (JSAMPLE) ((r + g - CENTERJSAMPLE) & MAXJSAMPLE);\n      outptr[RGB_GREEN] = (JSAMPLE) g;\n      outptr[RGB_BLUE]  = (JSAMPLE) ((b + g - CENTERJSAMPLE) & MAXJSAMPLE);\n      outptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * [R-G,G,B-G] to grayscale conversion with modulo calculation\n * (inverse color transform).\n */\n\nMETHODDEF(void)\nrgb1_gray_convert (j_decompress_ptr cinfo,\n\t\t   JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t   JSAMPARRAY output_buf, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register INT32 * ctab = cconvert->rgb_y_tab;\n  register int r, g, b;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      r = GETJSAMPLE(inptr0[col]);\n      g = GETJSAMPLE(inptr1[col]);\n      b = GETJSAMPLE(inptr2[col]);\n      /* Assume that MAXJSAMPLE+1 is a power of 2, so that the MOD\n       * (modulo) operator is equivalent to the bitmask operator AND.\n       */\n      r = (r + g - CENTERJSAMPLE) & MAXJSAMPLE;\n      b = (b + g - CENTERJSAMPLE) & MAXJSAMPLE;\n      /* Y */\n      outptr[col] = (JSAMPLE)\n\t\t((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])\n\t\t >> SCALEBITS);\n    }\n  }\n}\n\n\n/*\n * No colorspace change, but conversion from separate-planes\n * to interleaved representation.\n */\n\nMETHODDEF(void)\nrgb_convert (j_decompress_ptr cinfo,\n\t     JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t     JSAMPARRAY output_buf, int num_rows)\n{\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      /* We can dispense with GETJSAMPLE() here */\n      outptr[RGB_RED]   = inptr0[col];\n      outptr[RGB_GREEN] = inptr1[col];\n      outptr[RGB_BLUE]  = inptr2[col];\n      outptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * Color conversion for no colorspace change: just copy the data,\n * converting from separate-planes to interleaved representation.\n */\n\nMETHODDEF(void)\nnull_convert (j_decompress_ptr cinfo,\n\t      JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t      JSAMPARRAY output_buf, int num_rows)\n{\n  int ci;\n  register int nc = cinfo->num_components;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    for (ci = 0; ci < nc; ci++) {\n      inptr = input_buf[ci][input_row];\n      outptr = output_buf[0] + ci;\n      for (col = 0; col < num_cols; col++) {\n\t*outptr = *inptr++;\t/* needn't bother with GETJSAMPLE() here */\n\toutptr += nc;\n      }\n    }\n    input_row++;\n    output_buf++;\n  }\n}\n\n\n/*\n * Color conversion for grayscale: just copy the data.\n * This also works for YCC -> grayscale conversion, in which\n * we just copy the Y (luminance) component and ignore chrominance.\n */\n\nMETHODDEF(void)\ngrayscale_convert (j_decompress_ptr cinfo,\n\t\t   JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t   JSAMPARRAY output_buf, int num_rows)\n{\n  jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,\n\t\t    num_rows, cinfo->output_width);\n}\n\n\n/*\n * Convert grayscale to RGB: just duplicate the graylevel three times.\n * This is provided to support applications that don't want to cope\n * with grayscale as a separate case.\n */\n\nMETHODDEF(void)\ngray_rgb_convert (j_decompress_ptr cinfo,\n\t\t  JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t  JSAMPARRAY output_buf, int num_rows)\n{\n  register JSAMPROW outptr;\n  register JSAMPROW inptr;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n\n  while (--num_rows >= 0) {\n    inptr = input_buf[0][input_row++];\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      /* We can dispense with GETJSAMPLE() here */\n      outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];\n      outptr += RGB_PIXELSIZE;\n    }\n  }\n}\n\n\n/*\n * Adobe-style YCCK->CMYK conversion.\n * We convert YCbCr to R=1-C, G=1-M, and B=1-Y using the same\n * conversion as above, while passing K (black) unchanged.\n * We assume build_ycc_rgb_table has been called.\n */\n\nMETHODDEF(void)\nycck_cmyk_convert (j_decompress_ptr cinfo,\n\t\t   JSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t   JSAMPARRAY output_buf, int num_rows)\n{\n  my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;\n  register int y, cb, cr;\n  register JSAMPROW outptr;\n  register JSAMPROW inptr0, inptr1, inptr2, inptr3;\n  register JDIMENSION col;\n  JDIMENSION num_cols = cinfo->output_width;\n  /* copy these pointers into registers if possible */\n  register JSAMPLE * range_limit = cinfo->sample_range_limit;\n  register int * Crrtab = cconvert->Cr_r_tab;\n  register int * Cbbtab = cconvert->Cb_b_tab;\n  register INT32 * Crgtab = cconvert->Cr_g_tab;\n  register INT32 * Cbgtab = cconvert->Cb_g_tab;\n  SHIFT_TEMPS\n\n  while (--num_rows >= 0) {\n    inptr0 = input_buf[0][input_row];\n    inptr1 = input_buf[1][input_row];\n    inptr2 = input_buf[2][input_row];\n    inptr3 = input_buf[3][input_row];\n    input_row++;\n    outptr = *output_buf++;\n    for (col = 0; col < num_cols; col++) {\n      y  = GETJSAMPLE(inptr0[col]);\n      cb = GETJSAMPLE(inptr1[col]);\n      cr = GETJSAMPLE(inptr2[col]);\n      /* Range-limiting is essential due to noise introduced by DCT losses,\n       * and for extended gamut encodings (sYCC).\n       */\n      outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])];\t/* red */\n      outptr[1] = range_limit[MAXJSAMPLE - (y +\t\t\t/* green */\n\t\t\t      ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],\n\t\t\t\t\t\t SCALEBITS)))];\n      outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])];\t/* blue */\n      /* K passes through unchanged */\n      outptr[3] = inptr3[col];\t/* don't need GETJSAMPLE here */\n      outptr += 4;\n    }\n  }\n}\n\n\n/*\n * Empty method for start_pass.\n */\n\nMETHODDEF(void)\nstart_pass_dcolor (j_decompress_ptr cinfo)\n{\n  /* no work needed */\n}\n\n\n/*\n * Module initialization routine for output colorspace conversion.\n */\n\nGLOBAL(void)\njinit_color_deconverter (j_decompress_ptr cinfo)\n{\n  my_cconvert_ptr cconvert;\n  int ci;\n\n  cconvert = (my_cconvert_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_color_deconverter));\n  cinfo->cconvert = &cconvert->pub;\n  cconvert->pub.start_pass = start_pass_dcolor;\n\n  /* Make sure num_components agrees with jpeg_color_space */\n  switch (cinfo->jpeg_color_space) {\n  case JCS_GRAYSCALE:\n    if (cinfo->num_components != 1)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    break;\n\n  case JCS_RGB:\n  case JCS_YCbCr:\n  case JCS_BG_RGB:\n  case JCS_BG_YCC:\n    if (cinfo->num_components != 3)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    break;\n\n  case JCS_CMYK:\n  case JCS_YCCK:\n    if (cinfo->num_components != 4)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    break;\n\n  default:\t\t\t/* JCS_UNKNOWN can be anything */\n    if (cinfo->num_components < 1)\n      ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);\n    break;\n  }\n\n  /* Support color transform only for RGB colorspaces */\n  if (cinfo->color_transform &&\n      cinfo->jpeg_color_space != JCS_RGB &&\n      cinfo->jpeg_color_space != JCS_BG_RGB)\n    ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n\n  /* Set out_color_components and conversion method based on requested space.\n   * Also clear the component_needed flags for any unused components,\n   * so that earlier pipeline stages can avoid useless computation.\n   */\n\n  switch (cinfo->out_color_space) {\n  case JCS_GRAYSCALE:\n    cinfo->out_color_components = 1;\n    switch (cinfo->jpeg_color_space) {\n    case JCS_GRAYSCALE:\n    case JCS_YCbCr:\n    case JCS_BG_YCC:\n      cconvert->pub.color_convert = grayscale_convert;\n      /* For color->grayscale conversion, only the Y (0) component is needed */\n      for (ci = 1; ci < cinfo->num_components; ci++)\n\tcinfo->comp_info[ci].component_needed = FALSE;\n      break;\n    case JCS_RGB:\n      switch (cinfo->color_transform) {\n      case JCT_NONE:\n\tcconvert->pub.color_convert = rgb_gray_convert;\n\tbreak;\n      case JCT_SUBTRACT_GREEN:\n\tcconvert->pub.color_convert = rgb1_gray_convert;\n\tbreak;\n      default:\n\tERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n      }\n      build_rgb_y_table(cinfo);\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  case JCS_RGB:\n    cinfo->out_color_components = RGB_PIXELSIZE;\n    switch (cinfo->jpeg_color_space) {\n    case JCS_GRAYSCALE:\n      cconvert->pub.color_convert = gray_rgb_convert;\n      break;\n    case JCS_YCbCr:\n      cconvert->pub.color_convert = ycc_rgb_convert;\n      build_ycc_rgb_table(cinfo);\n      break;\n    case JCS_BG_YCC:\n      cconvert->pub.color_convert = ycc_rgb_convert;\n      build_bg_ycc_rgb_table(cinfo);\n      break;\n    case JCS_RGB:\n      switch (cinfo->color_transform) {\n      case JCT_NONE:\n\tcconvert->pub.color_convert = rgb_convert;\n\tbreak;\n      case JCT_SUBTRACT_GREEN:\n\tcconvert->pub.color_convert = rgb1_rgb_convert;\n\tbreak;\n      default:\n\tERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n      }\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  case JCS_BG_RGB:\n    cinfo->out_color_components = RGB_PIXELSIZE;\n    if (cinfo->jpeg_color_space == JCS_BG_RGB) {\n      switch (cinfo->color_transform) {\n      case JCT_NONE:\n\tcconvert->pub.color_convert = rgb_convert;\n\tbreak;\n      case JCT_SUBTRACT_GREEN:\n\tcconvert->pub.color_convert = rgb1_rgb_convert;\n\tbreak;\n      default:\n\tERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n      }\n    } else\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    break;\n\n  case JCS_CMYK:\n    cinfo->out_color_components = 4;\n    switch (cinfo->jpeg_color_space) {\n    case JCS_YCCK:\n      cconvert->pub.color_convert = ycck_cmyk_convert;\n      build_ycc_rgb_table(cinfo);\n      break;\n    case JCS_CMYK:\n      cconvert->pub.color_convert = null_convert;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    }\n    break;\n\n  default:\n    /* Permit null conversion to same output space */\n    if (cinfo->out_color_space == cinfo->jpeg_color_space) {\n      cinfo->out_color_components = cinfo->num_components;\n      cconvert->pub.color_convert = null_convert;\n    } else\t\t\t/* unsupported non-null conversion */\n      ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n    break;\n  }\n\n  if (cinfo->quantize_colors)\n    cinfo->output_components = 1; /* single colormapped output component */\n  else\n    cinfo->output_components = cinfo->out_color_components;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdct.h",
    "content": "/*\n * jdct.h\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2002-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This include file contains common declarations for the forward and\n * inverse DCT modules.  These declarations are private to the DCT managers\n * (jcdctmgr.c, jddctmgr.c) and the individual DCT algorithms.\n * The individual DCT algorithms are kept in separate files to ease \n * machine-dependent tuning (e.g., assembly coding).\n */\n\n\n/*\n * A forward DCT routine is given a pointer to an input sample array and\n * a pointer to a work area of type DCTELEM[]; the DCT is to be performed\n * in-place in that buffer.  Type DCTELEM is int for 8-bit samples, INT32\n * for 12-bit samples.  (NOTE: Floating-point DCT implementations use an\n * array of type FAST_FLOAT, instead.)\n * The input data is to be fetched from the sample array starting at a\n * specified column.  (Any row offset needed will be applied to the array\n * pointer before it is passed to the FDCT code.)\n * Note that the number of samples fetched by the FDCT routine is\n * DCT_h_scaled_size * DCT_v_scaled_size.\n * The DCT outputs are returned scaled up by a factor of 8; they therefore\n * have a range of +-8K for 8-bit data, +-128K for 12-bit data.  This\n * convention improves accuracy in integer implementations and saves some\n * work in floating-point ones.\n * Quantization of the output coefficients is done by jcdctmgr.c.\n */\n\n#if BITS_IN_JSAMPLE == 8\ntypedef int DCTELEM;\t\t/* 16 or 32 bits is fine */\n#else\ntypedef INT32 DCTELEM;\t\t/* must have 32 bits */\n#endif\n\ntypedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data,\n\t\t\t\t\t       JSAMPARRAY sample_data,\n\t\t\t\t\t       JDIMENSION start_col));\ntypedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data,\n\t\t\t\t\t     JSAMPARRAY sample_data,\n\t\t\t\t\t     JDIMENSION start_col));\n\n\n/*\n * An inverse DCT routine is given a pointer to the input JBLOCK and a pointer\n * to an output sample array.  The routine must dequantize the input data as\n * well as perform the IDCT; for dequantization, it uses the multiplier table\n * pointed to by compptr->dct_table.  The output data is to be placed into the\n * sample array starting at a specified column.  (Any row offset needed will\n * be applied to the array pointer before it is passed to the IDCT code.)\n * Note that the number of samples emitted by the IDCT routine is\n * DCT_h_scaled_size * DCT_v_scaled_size.\n */\n\n/* typedef inverse_DCT_method_ptr is declared in jpegint.h */\n\n/*\n * Each IDCT routine has its own ideas about the best dct_table element type.\n */\n\ntypedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */\n#if BITS_IN_JSAMPLE == 8\ntypedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */\n#define IFAST_SCALE_BITS  2\t/* fractional bits in scale factors */\n#else\ntypedef INT32 IFAST_MULT_TYPE;\t/* need 32 bits for scaled quantizers */\n#define IFAST_SCALE_BITS  13\t/* fractional bits in scale factors */\n#endif\ntypedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */\n\n\n/*\n * Each IDCT routine is responsible for range-limiting its results and\n * converting them to unsigned form (0..MAXJSAMPLE).  The raw outputs could\n * be quite far out of range if the input data is corrupt, so a bulletproof\n * range-limiting step is required.  We use a mask-and-table-lookup method\n * to do the combined operations quickly, assuming that MAXJSAMPLE+1\n * is a power of 2.  See the comments with prepare_range_limit_table\n * (in jdmaster.c) for more info.\n */\n\n#define RANGE_MASK  (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */\n#define RANGE_CENTER  (MAXJSAMPLE * 2 + 2)\n#define RANGE_SUBSET  (RANGE_CENTER - CENTERJSAMPLE)\n\n#define IDCT_range_limit(cinfo)  ((cinfo)->sample_range_limit - RANGE_SUBSET)\n\n\n/* Short forms of external names for systems with brain-damaged linkers. */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jpeg_fdct_islow\t\tjFDislow\n#define jpeg_fdct_ifast\t\tjFDifast\n#define jpeg_fdct_float\t\tjFDfloat\n#define jpeg_fdct_7x7\t\tjFD7x7\n#define jpeg_fdct_6x6\t\tjFD6x6\n#define jpeg_fdct_5x5\t\tjFD5x5\n#define jpeg_fdct_4x4\t\tjFD4x4\n#define jpeg_fdct_3x3\t\tjFD3x3\n#define jpeg_fdct_2x2\t\tjFD2x2\n#define jpeg_fdct_1x1\t\tjFD1x1\n#define jpeg_fdct_9x9\t\tjFD9x9\n#define jpeg_fdct_10x10\t\tjFD10x10\n#define jpeg_fdct_11x11\t\tjFD11x11\n#define jpeg_fdct_12x12\t\tjFD12x12\n#define jpeg_fdct_13x13\t\tjFD13x13\n#define jpeg_fdct_14x14\t\tjFD14x14\n#define jpeg_fdct_15x15\t\tjFD15x15\n#define jpeg_fdct_16x16\t\tjFD16x16\n#define jpeg_fdct_16x8\t\tjFD16x8\n#define jpeg_fdct_14x7\t\tjFD14x7\n#define jpeg_fdct_12x6\t\tjFD12x6\n#define jpeg_fdct_10x5\t\tjFD10x5\n#define jpeg_fdct_8x4\t\tjFD8x4\n#define jpeg_fdct_6x3\t\tjFD6x3\n#define jpeg_fdct_4x2\t\tjFD4x2\n#define jpeg_fdct_2x1\t\tjFD2x1\n#define jpeg_fdct_8x16\t\tjFD8x16\n#define jpeg_fdct_7x14\t\tjFD7x14\n#define jpeg_fdct_6x12\t\tjFD6x12\n#define jpeg_fdct_5x10\t\tjFD5x10\n#define jpeg_fdct_4x8\t\tjFD4x8\n#define jpeg_fdct_3x6\t\tjFD3x6\n#define jpeg_fdct_2x4\t\tjFD2x4\n#define jpeg_fdct_1x2\t\tjFD1x2\n#define jpeg_idct_islow\t\tjRDislow\n#define jpeg_idct_ifast\t\tjRDifast\n#define jpeg_idct_float\t\tjRDfloat\n#define jpeg_idct_7x7\t\tjRD7x7\n#define jpeg_idct_6x6\t\tjRD6x6\n#define jpeg_idct_5x5\t\tjRD5x5\n#define jpeg_idct_4x4\t\tjRD4x4\n#define jpeg_idct_3x3\t\tjRD3x3\n#define jpeg_idct_2x2\t\tjRD2x2\n#define jpeg_idct_1x1\t\tjRD1x1\n#define jpeg_idct_9x9\t\tjRD9x9\n#define jpeg_idct_10x10\t\tjRD10x10\n#define jpeg_idct_11x11\t\tjRD11x11\n#define jpeg_idct_12x12\t\tjRD12x12\n#define jpeg_idct_13x13\t\tjRD13x13\n#define jpeg_idct_14x14\t\tjRD14x14\n#define jpeg_idct_15x15\t\tjRD15x15\n#define jpeg_idct_16x16\t\tjRD16x16\n#define jpeg_idct_16x8\t\tjRD16x8\n#define jpeg_idct_14x7\t\tjRD14x7\n#define jpeg_idct_12x6\t\tjRD12x6\n#define jpeg_idct_10x5\t\tjRD10x5\n#define jpeg_idct_8x4\t\tjRD8x4\n#define jpeg_idct_6x3\t\tjRD6x3\n#define jpeg_idct_4x2\t\tjRD4x2\n#define jpeg_idct_2x1\t\tjRD2x1\n#define jpeg_idct_8x16\t\tjRD8x16\n#define jpeg_idct_7x14\t\tjRD7x14\n#define jpeg_idct_6x12\t\tjRD6x12\n#define jpeg_idct_5x10\t\tjRD5x10\n#define jpeg_idct_4x8\t\tjRD4x8\n#define jpeg_idct_3x6\t\tjRD3x8\n#define jpeg_idct_2x4\t\tjRD2x4\n#define jpeg_idct_1x2\t\tjRD1x2\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n/* Extern declarations for the forward and inverse DCT routines. */\n\nEXTERN(void) jpeg_fdct_islow\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_ifast\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_float\n    JPP((FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_7x7\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_6x6\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_5x5\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_4x4\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_3x3\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_2x2\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_1x1\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_9x9\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_10x10\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_11x11\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_12x12\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_13x13\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_14x14\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_15x15\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_16x16\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_16x8\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_14x7\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_12x6\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_10x5\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_8x4\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_6x3\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_4x2\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_2x1\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_8x16\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_7x14\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_6x12\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_5x10\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_4x8\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_3x6\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_2x4\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\nEXTERN(void) jpeg_fdct_1x2\n    JPP((DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col));\n\nEXTERN(void) jpeg_idct_islow\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_ifast\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_float\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_7x7\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_6x6\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_5x5\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_4x4\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_3x3\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_2x2\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_1x1\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_9x9\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_10x10\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_11x11\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_12x12\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_13x13\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_14x14\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_15x15\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_16x16\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_16x8\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_14x7\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_12x6\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_10x5\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_8x4\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_6x3\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_4x2\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_2x1\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_8x16\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_7x14\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_6x12\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_5x10\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_4x8\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_3x6\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_2x4\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\nEXTERN(void) jpeg_idct_1x2\n    JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));\n\n\n/*\n * Macros for handling fixed-point arithmetic; these are used by many\n * but not all of the DCT/IDCT modules.\n *\n * All values are expected to be of type INT32.\n * Fractional constants are scaled left by CONST_BITS bits.\n * CONST_BITS is defined within each module using these macros,\n * and may differ from one module to the next.\n */\n\n#define ONE\t((INT32) 1)\n#define CONST_SCALE (ONE << CONST_BITS)\n\n/* Convert a positive real constant to an integer scaled by CONST_SCALE.\n * Caution: some C compilers fail to reduce \"FIX(constant)\" at compile time,\n * thus causing a lot of useless floating-point operations at run time.\n */\n\n#define FIX(x)\t((INT32) ((x) * CONST_SCALE + 0.5))\n\n/* Descale and correctly round an INT32 value that's scaled by N bits.\n * We assume RIGHT_SHIFT rounds towards minus infinity, so adding\n * the fudge factor is correct for either sign of X.\n */\n\n#define DESCALE(x,n)  RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)\n\n/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.\n * This macro is used only when the two inputs will actually be no more than\n * 16 bits wide, so that a 16x16->32 bit multiply can be used instead of a\n * full 32x32 multiply.  This provides a useful speedup on many machines.\n * Unfortunately there is no way to specify a 16x16->32 multiply portably\n * in C, but some C compilers will do the right thing if you provide the\n * correct combination of casts.\n */\n\n#ifdef SHORTxSHORT_32\t\t/* may work if 'int' is 32 bits */\n#define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT16) (const)))\n#endif\n#ifdef SHORTxLCONST_32\t\t/* known to work with Microsoft C 6.0 */\n#define MULTIPLY16C16(var,const)  (((INT16) (var)) * ((INT32) (const)))\n#endif\n\n#ifndef MULTIPLY16C16\t\t/* default definition */\n#define MULTIPLY16C16(var,const)  ((var) * (const))\n#endif\n\n/* Same except both inputs are variables. */\n\n#ifdef SHORTxSHORT_32\t\t/* may work if 'int' is 32 bits */\n#define MULTIPLY16V16(var1,var2)  (((INT16) (var1)) * ((INT16) (var2)))\n#endif\n\n#ifndef MULTIPLY16V16\t\t/* default definition */\n#define MULTIPLY16V16(var1,var2)  ((var1) * (var2))\n#endif\n\n/* Like RIGHT_SHIFT, but applies to a DCTELEM.\n * We assume that int right shift is unsigned if INT32 right shift is.\n */\n\n#ifdef RIGHT_SHIFT_IS_UNSIGNED\n#define ISHIFT_TEMPS\tDCTELEM ishift_temp;\n#if BITS_IN_JSAMPLE == 8\n#define DCTELEMBITS  16\t\t/* DCTELEM may be 16 or 32 bits */\n#else\n#define DCTELEMBITS  32\t\t/* DCTELEM must be 32 bits */\n#endif\n#define IRIGHT_SHIFT(x,shft)  \\\n    ((ishift_temp = (x)) < 0 ? \\\n     (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \\\n     (ishift_temp >> (shft)))\n#else\n#define ISHIFT_TEMPS\n#define IRIGHT_SHIFT(x,shft)\t((x) >> (shft))\n#endif\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jddctmgr.c",
    "content": "/*\n * jddctmgr.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2002-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the inverse-DCT management logic.\n * This code selects a particular IDCT implementation to be used,\n * and it performs related housekeeping chores.  No code in this file\n * is executed per IDCT step, only during output pass setup.\n *\n * Note that the IDCT routines are responsible for performing coefficient\n * dequantization as well as the IDCT proper.  This module sets up the\n * dequantization multiplier table needed by the IDCT routine.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n\n/*\n * The decompressor input side (jdinput.c) saves away the appropriate\n * quantization table for each component at the start of the first scan\n * involving that component.  (This is necessary in order to correctly\n * decode files that reuse Q-table slots.)\n * When we are ready to make an output pass, the saved Q-table is converted\n * to a multiplier table that will actually be used by the IDCT routine.\n * The multiplier table contents are IDCT-method-dependent.  To support\n * application changes in IDCT method between scans, we can remake the\n * multiplier tables if necessary.\n * In buffered-image mode, the first output pass may occur before any data\n * has been seen for some components, and thus before their Q-tables have\n * been saved away.  To handle this case, multiplier tables are preset\n * to zeroes; the result of the IDCT will be a neutral gray level.\n */\n\n\n/* Private subobject for this module */\n\ntypedef struct {\n  struct jpeg_inverse_dct pub;\t/* public fields */\n\n  /* This array contains the IDCT method code that each multiplier table\n   * is currently set up for, or -1 if it's not yet set up.\n   * The actual multiplier tables are pointed to by dct_table in the\n   * per-component comp_info structures.\n   */\n  int cur_method[MAX_COMPONENTS];\n} my_idct_controller;\n\ntypedef my_idct_controller * my_idct_ptr;\n\n\n/* Allocated multiplier tables: big enough for any supported variant */\n\ntypedef union {\n  ISLOW_MULT_TYPE islow_array[DCTSIZE2];\n#ifdef DCT_IFAST_SUPPORTED\n  IFAST_MULT_TYPE ifast_array[DCTSIZE2];\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n  FLOAT_MULT_TYPE float_array[DCTSIZE2];\n#endif\n} multiplier_table;\n\n\n/* The current scaled-IDCT routines require ISLOW-style multiplier tables,\n * so be sure to compile that code if either ISLOW or SCALING is requested.\n */\n#ifdef DCT_ISLOW_SUPPORTED\n#define PROVIDE_ISLOW_TABLES\n#else\n#ifdef IDCT_SCALING_SUPPORTED\n#define PROVIDE_ISLOW_TABLES\n#endif\n#endif\n\n\n/*\n * Prepare for an output pass.\n * Here we select the proper IDCT routine for each component and build\n * a matching multiplier table.\n */\n\nMETHODDEF(void)\nstart_pass (j_decompress_ptr cinfo)\n{\n  my_idct_ptr idct = (my_idct_ptr) cinfo->idct;\n  int ci, i;\n  jpeg_component_info *compptr;\n  int method = 0;\n  inverse_DCT_method_ptr method_ptr = NULL;\n  JQUANT_TBL * qtbl;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Select the proper IDCT routine for this component's scaling */\n    switch ((compptr->DCT_h_scaled_size << 8) + compptr->DCT_v_scaled_size) {\n#ifdef IDCT_SCALING_SUPPORTED\n    case ((1 << 8) + 1):\n      method_ptr = jpeg_idct_1x1;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((2 << 8) + 2):\n      method_ptr = jpeg_idct_2x2;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((3 << 8) + 3):\n      method_ptr = jpeg_idct_3x3;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((4 << 8) + 4):\n      method_ptr = jpeg_idct_4x4;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((5 << 8) + 5):\n      method_ptr = jpeg_idct_5x5;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((6 << 8) + 6):\n      method_ptr = jpeg_idct_6x6;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((7 << 8) + 7):\n      method_ptr = jpeg_idct_7x7;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((9 << 8) + 9):\n      method_ptr = jpeg_idct_9x9;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((10 << 8) + 10):\n      method_ptr = jpeg_idct_10x10;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((11 << 8) + 11):\n      method_ptr = jpeg_idct_11x11;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((12 << 8) + 12):\n      method_ptr = jpeg_idct_12x12;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((13 << 8) + 13):\n      method_ptr = jpeg_idct_13x13;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((14 << 8) + 14):\n      method_ptr = jpeg_idct_14x14;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((15 << 8) + 15):\n      method_ptr = jpeg_idct_15x15;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((16 << 8) + 16):\n      method_ptr = jpeg_idct_16x16;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((16 << 8) + 8):\n      method_ptr = jpeg_idct_16x8;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((14 << 8) + 7):\n      method_ptr = jpeg_idct_14x7;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((12 << 8) + 6):\n      method_ptr = jpeg_idct_12x6;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((10 << 8) + 5):\n      method_ptr = jpeg_idct_10x5;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((8 << 8) + 4):\n      method_ptr = jpeg_idct_8x4;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((6 << 8) + 3):\n      method_ptr = jpeg_idct_6x3;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((4 << 8) + 2):\n      method_ptr = jpeg_idct_4x2;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((2 << 8) + 1):\n      method_ptr = jpeg_idct_2x1;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((8 << 8) + 16):\n      method_ptr = jpeg_idct_8x16;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((7 << 8) + 14):\n      method_ptr = jpeg_idct_7x14;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((6 << 8) + 12):\n      method_ptr = jpeg_idct_6x12;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((5 << 8) + 10):\n      method_ptr = jpeg_idct_5x10;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((4 << 8) + 8):\n      method_ptr = jpeg_idct_4x8;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((3 << 8) + 6):\n      method_ptr = jpeg_idct_3x6;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((2 << 8) + 4):\n      method_ptr = jpeg_idct_2x4;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n    case ((1 << 8) + 2):\n      method_ptr = jpeg_idct_1x2;\n      method = JDCT_ISLOW;\t/* jidctint uses islow-style table */\n      break;\n#endif\n    case ((DCTSIZE << 8) + DCTSIZE):\n      switch (cinfo->dct_method) {\n#ifdef DCT_ISLOW_SUPPORTED\n      case JDCT_ISLOW:\n\tmethod_ptr = jpeg_idct_islow;\n\tmethod = JDCT_ISLOW;\n\tbreak;\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n      case JDCT_IFAST:\n\tmethod_ptr = jpeg_idct_ifast;\n\tmethod = JDCT_IFAST;\n\tbreak;\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n      case JDCT_FLOAT:\n\tmethod_ptr = jpeg_idct_float;\n\tmethod = JDCT_FLOAT;\n\tbreak;\n#endif\n      default:\n\tERREXIT(cinfo, JERR_NOT_COMPILED);\n\tbreak;\n      }\n      break;\n    default:\n      ERREXIT2(cinfo, JERR_BAD_DCTSIZE,\n\t       compptr->DCT_h_scaled_size, compptr->DCT_v_scaled_size);\n      break;\n    }\n    idct->pub.inverse_DCT[ci] = method_ptr;\n    /* Create multiplier table from quant table.\n     * However, we can skip this if the component is uninteresting\n     * or if we already built the table.  Also, if no quant table\n     * has yet been saved for the component, we leave the\n     * multiplier table all-zero; we'll be reading zeroes from the\n     * coefficient controller's buffer anyway.\n     */\n    if (! compptr->component_needed || idct->cur_method[ci] == method)\n      continue;\n    qtbl = compptr->quant_table;\n    if (qtbl == NULL)\t\t/* happens if no data yet for component */\n      continue;\n    idct->cur_method[ci] = method;\n    switch (method) {\n#ifdef PROVIDE_ISLOW_TABLES\n    case JDCT_ISLOW:\n      {\n\t/* For LL&M IDCT method, multipliers are equal to raw quantization\n\t * coefficients, but are stored as ints to ensure access efficiency.\n\t */\n\tISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;\n\tfor (i = 0; i < DCTSIZE2; i++) {\n\t  ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];\n\t}\n      }\n      break;\n#endif\n#ifdef DCT_IFAST_SUPPORTED\n    case JDCT_IFAST:\n      {\n\t/* For AA&N IDCT method, multipliers are equal to quantization\n\t * coefficients scaled by scalefactor[row]*scalefactor[col], where\n\t *   scalefactor[0] = 1\n\t *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7\n\t * For integer operation, the multiplier table is to be scaled by\n\t * IFAST_SCALE_BITS.\n\t */\n\tIFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;\n#define CONST_BITS 14\n\tstatic const INT16 aanscales[DCTSIZE2] = {\n\t  /* precomputed values scaled up by 14 bits */\n\t  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,\n\t  22725, 31521, 29692, 26722, 22725, 17855, 12299,  6270,\n\t  21407, 29692, 27969, 25172, 21407, 16819, 11585,  5906,\n\t  19266, 26722, 25172, 22654, 19266, 15137, 10426,  5315,\n\t  16384, 22725, 21407, 19266, 16384, 12873,  8867,  4520,\n\t  12873, 17855, 16819, 15137, 12873, 10114,  6967,  3552,\n\t   8867, 12299, 11585, 10426,  8867,  6967,  4799,  2446,\n\t   4520,  6270,  5906,  5315,  4520,  3552,  2446,  1247\n\t};\n\tSHIFT_TEMPS\n\n\tfor (i = 0; i < DCTSIZE2; i++) {\n\t  ifmtbl[i] = (IFAST_MULT_TYPE)\n\t    DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],\n\t\t\t\t  (INT32) aanscales[i]),\n\t\t    CONST_BITS-IFAST_SCALE_BITS);\n\t}\n      }\n      break;\n#endif\n#ifdef DCT_FLOAT_SUPPORTED\n    case JDCT_FLOAT:\n      {\n\t/* For float AA&N IDCT method, multipliers are equal to quantization\n\t * coefficients scaled by scalefactor[row]*scalefactor[col], where\n\t *   scalefactor[0] = 1\n\t *   scalefactor[k] = cos(k*PI/16) * sqrt(2)    for k=1..7\n\t * We apply a further scale factor of 1/8.\n\t */\n\tFLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;\n\tint row, col;\n\tstatic const double aanscalefactor[DCTSIZE] = {\n\t  1.0, 1.387039845, 1.306562965, 1.175875602,\n\t  1.0, 0.785694958, 0.541196100, 0.275899379\n\t};\n\n\ti = 0;\n\tfor (row = 0; row < DCTSIZE; row++) {\n\t  for (col = 0; col < DCTSIZE; col++) {\n\t    fmtbl[i] = (FLOAT_MULT_TYPE)\n\t      ((double) qtbl->quantval[i] *\n\t       aanscalefactor[row] * aanscalefactor[col] * 0.125);\n\t    i++;\n\t  }\n\t}\n      }\n      break;\n#endif\n    default:\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n      break;\n    }\n  }\n}\n\n\n/*\n * Initialize IDCT manager.\n */\n\nGLOBAL(void)\njinit_inverse_dct (j_decompress_ptr cinfo)\n{\n  my_idct_ptr idct;\n  int ci;\n  jpeg_component_info *compptr;\n\n  idct = (my_idct_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_idct_controller));\n  cinfo->idct = &idct->pub;\n  idct->pub.start_pass = start_pass;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Allocate and pre-zero a multiplier table for each component */\n    compptr->dct_table =\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(multiplier_table));\n    MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));\n    /* Mark multiplier table not yet set up for any method */\n    idct->cur_method[ci] = -1;\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdhuff.c",
    "content": "/*\n * jdhuff.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2006-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains Huffman entropy decoding routines.\n * Both sequential and progressive modes are supported in this single module.\n *\n * Much of the complexity here has to do with supporting input suspension.\n * If the data source module demands suspension, we want to be able to back\n * up to the start of the current MCU.  To do this, we copy state variables\n * into local working storage, and update them back to the permanent\n * storage only upon successful completion of an MCU.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Derived data constructed for each Huffman table */\n\n#define HUFF_LOOKAHEAD\t8\t/* # of bits of lookahead */\n\ntypedef struct {\n  /* Basic tables: (element [0] of each array is unused) */\n  INT32 maxcode[18];\t\t/* largest code of length k (-1 if none) */\n  /* (maxcode[17] is a sentinel to ensure jpeg_huff_decode terminates) */\n  INT32 valoffset[17];\t\t/* huffval[] offset for codes of length k */\n  /* valoffset[k] = huffval[] index of 1st symbol of code length k, less\n   * the smallest code of length k; so given a code of length k, the\n   * corresponding symbol is huffval[code + valoffset[k]]\n   */\n\n  /* Link to public Huffman table (needed only in jpeg_huff_decode) */\n  JHUFF_TBL *pub;\n\n  /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of\n   * the input data stream.  If the next Huffman code is no more\n   * than HUFF_LOOKAHEAD bits long, we can obtain its length and\n   * the corresponding symbol directly from these tables.\n   */\n  int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */\n  UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */\n} d_derived_tbl;\n\n\n/*\n * Fetching the next N bits from the input stream is a time-critical operation\n * for the Huffman decoders.  We implement it with a combination of inline\n * macros and out-of-line subroutines.  Note that N (the number of bits\n * demanded at one time) never exceeds 15 for JPEG use.\n *\n * We read source bytes into get_buffer and dole out bits as needed.\n * If get_buffer already contains enough bits, they are fetched in-line\n * by the macros CHECK_BIT_BUFFER and GET_BITS.  When there aren't enough\n * bits, jpeg_fill_bit_buffer is called; it will attempt to fill get_buffer\n * as full as possible (not just to the number of bits needed; this\n * prefetching reduces the overhead cost of calling jpeg_fill_bit_buffer).\n * Note that jpeg_fill_bit_buffer may return FALSE to indicate suspension.\n * On TRUE return, jpeg_fill_bit_buffer guarantees that get_buffer contains\n * at least the requested number of bits --- dummy zeroes are inserted if\n * necessary.\n */\n\ntypedef INT32 bit_buf_type;\t/* type of bit-extraction buffer */\n#define BIT_BUF_SIZE  32\t/* size of buffer in bits */\n\n/* If long is > 32 bits on your machine, and shifting/masking longs is\n * reasonably fast, making bit_buf_type be long and setting BIT_BUF_SIZE\n * appropriately should be a win.  Unfortunately we can't define the size\n * with something like  #define BIT_BUF_SIZE (sizeof(bit_buf_type)*8)\n * because not all machines measure sizeof in 8-bit bytes.\n */\n\ntypedef struct {\t\t/* Bitreading state saved across MCUs */\n  bit_buf_type get_buffer;\t/* current bit-extraction buffer */\n  int bits_left;\t\t/* # of unused bits in it */\n} bitread_perm_state;\n\ntypedef struct {\t\t/* Bitreading working state within an MCU */\n  /* Current data source location */\n  /* We need a copy, rather than munging the original, in case of suspension */\n  const JOCTET * next_input_byte; /* => next byte to read from source */\n  size_t bytes_in_buffer;\t/* # of bytes remaining in source buffer */\n  /* Bit input buffer --- note these values are kept in register variables,\n   * not in this struct, inside the inner loops.\n   */\n  bit_buf_type get_buffer;\t/* current bit-extraction buffer */\n  int bits_left;\t\t/* # of unused bits in it */\n  /* Pointer needed by jpeg_fill_bit_buffer. */\n  j_decompress_ptr cinfo;\t/* back link to decompress master record */\n} bitread_working_state;\n\n/* Macros to declare and load/save bitread local variables. */\n#define BITREAD_STATE_VARS  \\\n\tregister bit_buf_type get_buffer;  \\\n\tregister int bits_left;  \\\n\tbitread_working_state br_state\n\n#define BITREAD_LOAD_STATE(cinfop,permstate)  \\\n\tbr_state.cinfo = cinfop; \\\n\tbr_state.next_input_byte = cinfop->src->next_input_byte; \\\n\tbr_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \\\n\tget_buffer = permstate.get_buffer; \\\n\tbits_left = permstate.bits_left;\n\n#define BITREAD_SAVE_STATE(cinfop,permstate)  \\\n\tcinfop->src->next_input_byte = br_state.next_input_byte; \\\n\tcinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \\\n\tpermstate.get_buffer = get_buffer; \\\n\tpermstate.bits_left = bits_left\n\n/*\n * These macros provide the in-line portion of bit fetching.\n * Use CHECK_BIT_BUFFER to ensure there are N bits in get_buffer\n * before using GET_BITS, PEEK_BITS, or DROP_BITS.\n * The variables get_buffer and bits_left are assumed to be locals,\n * but the state struct might not be (jpeg_huff_decode needs this).\n *\tCHECK_BIT_BUFFER(state,n,action);\n *\t\tEnsure there are N bits in get_buffer; if suspend, take action.\n *      val = GET_BITS(n);\n *\t\tFetch next N bits.\n *      val = PEEK_BITS(n);\n *\t\tFetch next N bits without removing them from the buffer.\n *\tDROP_BITS(n);\n *\t\tDiscard next N bits.\n * The value N should be a simple variable, not an expression, because it\n * is evaluated multiple times.\n */\n\n#define CHECK_BIT_BUFFER(state,nbits,action) \\\n\t{ if (bits_left < (nbits)) {  \\\n\t    if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits))  \\\n\t      { action; }  \\\n\t    get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }\n\n#define GET_BITS(nbits) \\\n\t(((int) (get_buffer >> (bits_left -= (nbits)))) & BIT_MASK(nbits))\n\n#define PEEK_BITS(nbits) \\\n\t(((int) (get_buffer >> (bits_left -  (nbits)))) & BIT_MASK(nbits))\n\n#define DROP_BITS(nbits) \\\n\t(bits_left -= (nbits))\n\n\n/*\n * Code for extracting next Huffman-coded symbol from input bit stream.\n * Again, this is time-critical and we make the main paths be macros.\n *\n * We use a lookahead table to process codes of up to HUFF_LOOKAHEAD bits\n * without looping.  Usually, more than 95% of the Huffman codes will be 8\n * or fewer bits long.  The few overlength codes are handled with a loop,\n * which need not be inline code.\n *\n * Notes about the HUFF_DECODE macro:\n * 1. Near the end of the data segment, we may fail to get enough bits\n *    for a lookahead.  In that case, we do it the hard way.\n * 2. If the lookahead table contains no entry, the next code must be\n *    more than HUFF_LOOKAHEAD bits long.\n * 3. jpeg_huff_decode returns -1 if forced to suspend.\n */\n\n#define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \\\n{ register int nb, look; \\\n  if (bits_left < HUFF_LOOKAHEAD) { \\\n    if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \\\n    get_buffer = state.get_buffer; bits_left = state.bits_left; \\\n    if (bits_left < HUFF_LOOKAHEAD) { \\\n      nb = 1; goto slowlabel; \\\n    } \\\n  } \\\n  look = PEEK_BITS(HUFF_LOOKAHEAD); \\\n  if ((nb = htbl->look_nbits[look]) != 0) { \\\n    DROP_BITS(nb); \\\n    result = htbl->look_sym[look]; \\\n  } else { \\\n    nb = HUFF_LOOKAHEAD+1; \\\nslowlabel: \\\n    if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \\\n\t{ failaction; } \\\n    get_buffer = state.get_buffer; bits_left = state.bits_left; \\\n  } \\\n}\n\n\n/*\n * Expanded entropy decoder object for Huffman decoding.\n *\n * The savable_state subrecord contains fields that change within an MCU,\n * but must not be updated permanently until we complete the MCU.\n */\n\ntypedef struct {\n  unsigned int EOBRUN;\t\t\t/* remaining EOBs in EOBRUN */\n  int last_dc_val[MAX_COMPS_IN_SCAN];\t/* last DC coef for each component */\n} savable_state;\n\n/* This macro is to work around compilers with missing or broken\n * structure assignment.  You'll need to fix this code if you have\n * such a compiler and you change MAX_COMPS_IN_SCAN.\n */\n\n#ifndef NO_STRUCT_ASSIGN\n#define ASSIGN_STATE(dest,src)  ((dest) = (src))\n#else\n#if MAX_COMPS_IN_SCAN == 4\n#define ASSIGN_STATE(dest,src)  \\\n\t((dest).EOBRUN = (src).EOBRUN, \\\n\t (dest).last_dc_val[0] = (src).last_dc_val[0], \\\n\t (dest).last_dc_val[1] = (src).last_dc_val[1], \\\n\t (dest).last_dc_val[2] = (src).last_dc_val[2], \\\n\t (dest).last_dc_val[3] = (src).last_dc_val[3])\n#endif\n#endif\n\n\ntypedef struct {\n  struct jpeg_entropy_decoder pub; /* public fields */\n\n  /* These fields are loaded into local variables at start of each MCU.\n   * In case of suspension, we exit WITHOUT updating them.\n   */\n  bitread_perm_state bitstate;\t/* Bit buffer at start of MCU */\n  savable_state saved;\t\t/* Other state at start of MCU */\n\n  /* These fields are NOT loaded into local working state. */\n  boolean insufficient_data;\t/* set TRUE after emitting warning */\n  unsigned int restarts_to_go;\t/* MCUs left in this restart interval */\n\n  /* Following two fields used only in progressive mode */\n\n  /* Pointers to derived tables (these workspaces have image lifespan) */\n  d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];\n\n  d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */\n\n  /* Following fields used only in sequential mode */\n\n  /* Pointers to derived tables (these workspaces have image lifespan) */\n  d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];\n  d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];\n\n  /* Precalculated info set up by start_pass for use in decode_mcu: */\n\n  /* Pointers to derived tables to be used for each block within an MCU */\n  d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];\n  d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];\n  /* Whether we care about the DC and AC coefficient values for each block */\n  int coef_limit[D_MAX_BLOCKS_IN_MCU];\n} huff_entropy_decoder;\n\ntypedef huff_entropy_decoder * huff_entropy_ptr;\n\n\nstatic const int jpeg_zigzag_order[8][8] = {\n  {  0,  1,  5,  6, 14, 15, 27, 28 },\n  {  2,  4,  7, 13, 16, 26, 29, 42 },\n  {  3,  8, 12, 17, 25, 30, 41, 43 },\n  {  9, 11, 18, 24, 31, 40, 44, 53 },\n  { 10, 19, 23, 32, 39, 45, 52, 54 },\n  { 20, 22, 33, 38, 46, 51, 55, 60 },\n  { 21, 34, 37, 47, 50, 56, 59, 61 },\n  { 35, 36, 48, 49, 57, 58, 62, 63 }\n};\n\nstatic const int jpeg_zigzag_order7[7][7] = {\n  {  0,  1,  5,  6, 14, 15, 27 },\n  {  2,  4,  7, 13, 16, 26, 28 },\n  {  3,  8, 12, 17, 25, 29, 38 },\n  {  9, 11, 18, 24, 30, 37, 39 },\n  { 10, 19, 23, 31, 36, 40, 45 },\n  { 20, 22, 32, 35, 41, 44, 46 },\n  { 21, 33, 34, 42, 43, 47, 48 }\n};\n\nstatic const int jpeg_zigzag_order6[6][6] = {\n  {  0,  1,  5,  6, 14, 15 },\n  {  2,  4,  7, 13, 16, 25 },\n  {  3,  8, 12, 17, 24, 26 },\n  {  9, 11, 18, 23, 27, 32 },\n  { 10, 19, 22, 28, 31, 33 },\n  { 20, 21, 29, 30, 34, 35 }\n};\n\nstatic const int jpeg_zigzag_order5[5][5] = {\n  {  0,  1,  5,  6, 14 },\n  {  2,  4,  7, 13, 15 },\n  {  3,  8, 12, 16, 21 },\n  {  9, 11, 17, 20, 22 },\n  { 10, 18, 19, 23, 24 }\n};\n\nstatic const int jpeg_zigzag_order4[4][4] = {\n  { 0,  1,  5,  6 },\n  { 2,  4,  7, 12 },\n  { 3,  8, 11, 13 },\n  { 9, 10, 14, 15 }\n};\n\nstatic const int jpeg_zigzag_order3[3][3] = {\n  { 0, 1, 5 },\n  { 2, 4, 6 },\n  { 3, 7, 8 }\n};\n\nstatic const int jpeg_zigzag_order2[2][2] = {\n  { 0, 1 },\n  { 2, 3 }\n};\n\n\n/*\n * Compute the derived values for a Huffman table.\n * This routine also performs some validation checks on the table.\n */\n\nLOCAL(void)\njpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,\n\t\t\t d_derived_tbl ** pdtbl)\n{\n  JHUFF_TBL *htbl;\n  d_derived_tbl *dtbl;\n  int p, i, l, si, numsymbols;\n  int lookbits, ctr;\n  char huffsize[257];\n  unsigned int huffcode[257];\n  unsigned int code;\n\n  /* Note that huffsize[] and huffcode[] are filled in code-length order,\n   * paralleling the order of the symbols themselves in htbl->huffval[].\n   */\n\n  /* Find the input Huffman table */\n  if (tblno < 0 || tblno >= NUM_HUFF_TBLS)\n    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);\n  htbl =\n    isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];\n  if (htbl == NULL)\n    ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);\n\n  /* Allocate a workspace if we haven't already done so. */\n  if (*pdtbl == NULL)\n    *pdtbl = (d_derived_tbl *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(d_derived_tbl));\n  dtbl = *pdtbl;\n  dtbl->pub = htbl;\t\t/* fill in back link */\n  \n  /* Figure C.1: make table of Huffman code length for each symbol */\n\n  p = 0;\n  for (l = 1; l <= 16; l++) {\n    i = (int) htbl->bits[l];\n    if (i < 0 || p + i > 256)\t/* protect against table overrun */\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    while (i--)\n      huffsize[p++] = (char) l;\n  }\n  huffsize[p] = 0;\n  numsymbols = p;\n  \n  /* Figure C.2: generate the codes themselves */\n  /* We also validate that the counts represent a legal Huffman code tree. */\n  \n  code = 0;\n  si = huffsize[0];\n  p = 0;\n  while (huffsize[p]) {\n    while (((int) huffsize[p]) == si) {\n      huffcode[p++] = code;\n      code++;\n    }\n    /* code is now 1 more than the last code used for codelength si; but\n     * it must still fit in si bits, since no code is allowed to be all ones.\n     */\n    if (((INT32) code) >= (((INT32) 1) << si))\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    code <<= 1;\n    si++;\n  }\n\n  /* Figure F.15: generate decoding tables for bit-sequential decoding */\n\n  p = 0;\n  for (l = 1; l <= 16; l++) {\n    if (htbl->bits[l]) {\n      /* valoffset[l] = huffval[] index of 1st symbol of code length l,\n       * minus the minimum code of length l\n       */\n      dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];\n      p += htbl->bits[l];\n      dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */\n    } else {\n      dtbl->maxcode[l] = -1;\t/* -1 if no codes of this length */\n    }\n  }\n  dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */\n\n  /* Compute lookahead tables to speed up decoding.\n   * First we set all the table entries to 0, indicating \"too long\";\n   * then we iterate through the Huffman codes that are short enough and\n   * fill in all the entries that correspond to bit sequences starting\n   * with that code.\n   */\n\n  MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));\n\n  p = 0;\n  for (l = 1; l <= HUFF_LOOKAHEAD; l++) {\n    for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {\n      /* l = current code's length, p = its index in huffcode[] & huffval[]. */\n      /* Generate left-justified code followed by all possible bit sequences */\n      lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);\n      for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {\n\tdtbl->look_nbits[lookbits] = l;\n\tdtbl->look_sym[lookbits] = htbl->huffval[p];\n\tlookbits++;\n      }\n    }\n  }\n\n  /* Validate symbols as being reasonable.\n   * For AC tables, we make no check, but accept all byte values 0..255.\n   * For DC tables, we require the symbols to be in range 0..15.\n   * (Tighter bounds could be applied depending on the data depth and mode,\n   * but this is sufficient to ensure safe decoding.)\n   */\n  if (isDC) {\n    for (i = 0; i < numsymbols; i++) {\n      int sym = htbl->huffval[i];\n      if (sym < 0 || sym > 15)\n\tERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n    }\n  }\n}\n\n\n/*\n * Out-of-line code for bit fetching.\n * Note: current values of get_buffer and bits_left are passed as parameters,\n * but are returned in the corresponding fields of the state struct.\n *\n * On most machines MIN_GET_BITS should be 25 to allow the full 32-bit width\n * of get_buffer to be used.  (On machines with wider words, an even larger\n * buffer could be used.)  However, on some machines 32-bit shifts are\n * quite slow and take time proportional to the number of places shifted.\n * (This is true with most PC compilers, for instance.)  In this case it may\n * be a win to set MIN_GET_BITS to the minimum value of 15.  This reduces the\n * average shift distance at the cost of more calls to jpeg_fill_bit_buffer.\n */\n\n#ifdef SLOW_SHIFT_32\n#define MIN_GET_BITS  15\t/* minimum allowable value */\n#else\n#define MIN_GET_BITS  (BIT_BUF_SIZE-7)\n#endif\n\n\nLOCAL(boolean)\njpeg_fill_bit_buffer (bitread_working_state * state,\n\t\t      register bit_buf_type get_buffer, register int bits_left,\n\t\t      int nbits)\n/* Load up the bit buffer to a depth of at least nbits */\n{\n  /* Copy heavily used state fields into locals (hopefully registers) */\n  register const JOCTET * next_input_byte = state->next_input_byte;\n  register size_t bytes_in_buffer = state->bytes_in_buffer;\n  j_decompress_ptr cinfo = state->cinfo;\n\n  /* Attempt to load at least MIN_GET_BITS bits into get_buffer. */\n  /* (It is assumed that no request will be for more than that many bits.) */\n  /* We fail to do so only if we hit a marker or are forced to suspend. */\n\n  if (cinfo->unread_marker == 0) {\t/* cannot advance past a marker */\n    while (bits_left < MIN_GET_BITS) {\n      register int c;\n\n      /* Attempt to read a byte */\n      if (bytes_in_buffer == 0) {\n\tif (! (*cinfo->src->fill_input_buffer) (cinfo))\n\t  return FALSE;\n\tnext_input_byte = cinfo->src->next_input_byte;\n\tbytes_in_buffer = cinfo->src->bytes_in_buffer;\n      }\n      bytes_in_buffer--;\n      c = GETJOCTET(*next_input_byte++);\n\n      /* If it's 0xFF, check and discard stuffed zero byte */\n      if (c == 0xFF) {\n\t/* Loop here to discard any padding FF's on terminating marker,\n\t * so that we can save a valid unread_marker value.  NOTE: we will\n\t * accept multiple FF's followed by a 0 as meaning a single FF data\n\t * byte.  This data pattern is not valid according to the standard.\n\t */\n\tdo {\n\t  if (bytes_in_buffer == 0) {\n\t    if (! (*cinfo->src->fill_input_buffer) (cinfo))\n\t      return FALSE;\n\t    next_input_byte = cinfo->src->next_input_byte;\n\t    bytes_in_buffer = cinfo->src->bytes_in_buffer;\n\t  }\n\t  bytes_in_buffer--;\n\t  c = GETJOCTET(*next_input_byte++);\n\t} while (c == 0xFF);\n\n\tif (c == 0) {\n\t  /* Found FF/00, which represents an FF data byte */\n\t  c = 0xFF;\n\t} else {\n\t  /* Oops, it's actually a marker indicating end of compressed data.\n\t   * Save the marker code for later use.\n\t   * Fine point: it might appear that we should save the marker into\n\t   * bitread working state, not straight into permanent state.  But\n\t   * once we have hit a marker, we cannot need to suspend within the\n\t   * current MCU, because we will read no more bytes from the data\n\t   * source.  So it is OK to update permanent state right away.\n\t   */\n\t  cinfo->unread_marker = c;\n\t  /* See if we need to insert some fake zero bits. */\n\t  goto no_more_bytes;\n\t}\n      }\n\n      /* OK, load c into get_buffer */\n      get_buffer = (get_buffer << 8) | c;\n      bits_left += 8;\n    } /* end while */\n  } else {\n  no_more_bytes:\n    /* We get here if we've read the marker that terminates the compressed\n     * data segment.  There should be enough bits in the buffer register\n     * to satisfy the request; if so, no problem.\n     */\n    if (nbits > bits_left) {\n      /* Uh-oh.  Report corrupted data to user and stuff zeroes into\n       * the data stream, so that we can produce some kind of image.\n       * We use a nonvolatile flag to ensure that only one warning message\n       * appears per data segment.\n       */\n      if (! ((huff_entropy_ptr) cinfo->entropy)->insufficient_data) {\n\tWARNMS(cinfo, JWRN_HIT_MARKER);\n\t((huff_entropy_ptr) cinfo->entropy)->insufficient_data = TRUE;\n      }\n      /* Fill the buffer with zero bits */\n      get_buffer <<= MIN_GET_BITS - bits_left;\n      bits_left = MIN_GET_BITS;\n    }\n  }\n\n  /* Unload the local registers */\n  state->next_input_byte = next_input_byte;\n  state->bytes_in_buffer = bytes_in_buffer;\n  state->get_buffer = get_buffer;\n  state->bits_left = bits_left;\n\n  return TRUE;\n}\n\n\n/*\n * Figure F.12: extend sign bit.\n * On some machines, a shift and sub will be faster than a table lookup.\n */\n\n#ifdef AVOID_TABLES\n\n#define BIT_MASK(nbits)   ((1<<(nbits))-1)\n#define HUFF_EXTEND(x,s)  ((x) < (1<<((s)-1)) ? (x) - ((1<<(s))-1) : (x))\n\n#else\n\n#define BIT_MASK(nbits)   bmask[nbits]\n#define HUFF_EXTEND(x,s)  ((x) <= bmask[(s) - 1] ? (x) - bmask[s] : (x))\n\nstatic const int bmask[16] =\t/* bmask[n] is mask for n rightmost bits */\n  { 0, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,\n    0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF };\n\n#endif /* AVOID_TABLES */\n\n\n/*\n * Out-of-line code for Huffman code decoding.\n */\n\nLOCAL(int)\njpeg_huff_decode (bitread_working_state * state,\n\t\t  register bit_buf_type get_buffer, register int bits_left,\n\t\t  d_derived_tbl * htbl, int min_bits)\n{\n  register int l = min_bits;\n  register INT32 code;\n\n  /* HUFF_DECODE has determined that the code is at least min_bits */\n  /* bits long, so fetch that many bits in one swoop. */\n\n  CHECK_BIT_BUFFER(*state, l, return -1);\n  code = GET_BITS(l);\n\n  /* Collect the rest of the Huffman code one bit at a time. */\n  /* This is per Figure F.16 in the JPEG spec. */\n\n  while (code > htbl->maxcode[l]) {\n    code <<= 1;\n    CHECK_BIT_BUFFER(*state, 1, return -1);\n    code |= GET_BITS(1);\n    l++;\n  }\n\n  /* Unload the local registers */\n  state->get_buffer = get_buffer;\n  state->bits_left = bits_left;\n\n  /* With garbage input we may reach the sentinel value l = 17. */\n\n  if (l > 16) {\n    WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);\n    return 0;\t\t\t/* fake a zero as the safest result */\n  }\n\n  return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];\n}\n\n\n/*\n * Finish up at the end of a Huffman-compressed scan.\n */\n\nMETHODDEF(void)\nfinish_pass_huff (j_decompress_ptr cinfo)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n\n  /* Throw away any unused bits remaining in bit buffer; */\n  /* include any full bytes in next_marker's count of discarded bytes */\n  cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;\n  entropy->bitstate.bits_left = 0;\n}\n\n\n/*\n * Check for a restart marker & resynchronize decoder.\n * Returns FALSE if must suspend.\n */\n\nLOCAL(boolean)\nprocess_restart (j_decompress_ptr cinfo)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int ci;\n\n  finish_pass_huff(cinfo);\n\n  /* Advance past the RSTn marker */\n  if (! (*cinfo->marker->read_restart_marker) (cinfo))\n    return FALSE;\n\n  /* Re-initialize DC predictions to 0 */\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++)\n    entropy->saved.last_dc_val[ci] = 0;\n  /* Re-init EOB run count, too */\n  entropy->saved.EOBRUN = 0;\n\n  /* Reset restart counter */\n  entropy->restarts_to_go = cinfo->restart_interval;\n\n  /* Reset out-of-data flag, unless read_restart_marker left us smack up\n   * against a marker.  In that case we will end up treating the next data\n   * segment as empty, and we can avoid producing bogus output pixels by\n   * leaving the flag set.\n   */\n  if (cinfo->unread_marker == 0)\n    entropy->insufficient_data = FALSE;\n\n  return TRUE;\n}\n\n\n/*\n * Huffman MCU decoding.\n * Each of these routines decodes and returns one MCU's worth of\n * Huffman-compressed coefficients. \n * The coefficients are reordered from zigzag order into natural array order,\n * but are not dequantized.\n *\n * The i'th block of the MCU is stored into the block pointed to by\n * MCU_data[i].  WE ASSUME THIS AREA IS INITIALLY ZEROED BY THE CALLER.\n * (Wholesale zeroing is usually a little faster than retail...)\n *\n * We return FALSE if data source requested suspension.  In that case no\n * changes have been made to permanent state.  (Exception: some output\n * coefficients may already have been assigned.  This is harmless for\n * spectral selection, since we'll just re-assign them on the next call.\n * Successive approximation AC refinement has to be more careful, however.)\n */\n\n/*\n * MCU decoding for DC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\ndecode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{   \n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int Al = cinfo->Al;\n  register int s, r;\n  int blkn, ci;\n  JBLOCKROW block;\n  BITREAD_STATE_VARS;\n  savable_state state;\n  d_derived_tbl * tbl;\n  jpeg_component_info * compptr;\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* If we've run out of data, just leave the MCU set to zeroes.\n   * This way, we return uniform gray for the remainder of the segment.\n   */\n  if (! entropy->insufficient_data) {\n\n    /* Load up working state */\n    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(state, entropy->saved);\n\n    /* Outer loop handles each block in the MCU */\n\n    for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n      block = MCU_data[blkn];\n      ci = cinfo->MCU_membership[blkn];\n      compptr = cinfo->cur_comp_info[ci];\n      tbl = entropy->derived_tbls[compptr->dc_tbl_no];\n\n      /* Decode a single block's worth of coefficients */\n\n      /* Section F.2.2.1: decode the DC coefficient difference */\n      HUFF_DECODE(s, br_state, tbl, return FALSE, label1);\n      if (s) {\n\tCHECK_BIT_BUFFER(br_state, s, return FALSE);\n\tr = GET_BITS(s);\n\ts = HUFF_EXTEND(r, s);\n      }\n\n      /* Convert DC difference to actual value, update last_dc_val */\n      s += state.last_dc_val[ci];\n      state.last_dc_val[ci] = s;\n      /* Scale and output the coefficient (assumes jpeg_natural_order[0]=0) */\n      (*block)[0] = (JCOEF) (s << Al);\n    }\n\n    /* Completed MCU, so update state */\n    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(entropy->saved, state);\n  }\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for AC initial scan (either spectral selection,\n * or first pass of successive approximation).\n */\n\nMETHODDEF(boolean)\ndecode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{   \n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  register int s, k, r;\n  unsigned int EOBRUN;\n  int Se, Al;\n  const int * natural_order;\n  JBLOCKROW block;\n  BITREAD_STATE_VARS;\n  d_derived_tbl * tbl;\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* If we've run out of data, just leave the MCU set to zeroes.\n   * This way, we return uniform gray for the remainder of the segment.\n   */\n  if (! entropy->insufficient_data) {\n\n    Se = cinfo->Se;\n    Al = cinfo->Al;\n    natural_order = cinfo->natural_order;\n\n    /* Load up working state.\n     * We can avoid loading/saving bitread state if in an EOB run.\n     */\n    EOBRUN = entropy->saved.EOBRUN;\t/* only part of saved state we need */\n\n    /* There is always only one block per MCU */\n\n    if (EOBRUN)\t\t\t/* if it's a band of zeroes... */\n      EOBRUN--;\t\t\t/* ...process it now (we do nothing) */\n    else {\n      BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n      block = MCU_data[0];\n      tbl = entropy->ac_derived_tbl;\n\n      for (k = cinfo->Ss; k <= Se; k++) {\n\tHUFF_DECODE(s, br_state, tbl, return FALSE, label2);\n\tr = s >> 4;\n\ts &= 15;\n\tif (s) {\n\t  k += r;\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  r = GET_BITS(s);\n\t  s = HUFF_EXTEND(r, s);\n\t  /* Scale and output coefficient in natural (dezigzagged) order */\n\t  (*block)[natural_order[k]] = (JCOEF) (s << Al);\n\t} else {\n\t  if (r != 15) {\t/* EOBr, run length is 2^r + appended bits */\n\t    if (r) {\t\t/* EOBr, r > 0 */\n\t      EOBRUN = 1 << r;\n\t      CHECK_BIT_BUFFER(br_state, r, return FALSE);\n\t      r = GET_BITS(r);\n\t      EOBRUN += r;\n\t      EOBRUN--;\t\t/* this band is processed at this moment */\n\t    }\n\t    break;\t\t/* force end-of-band */\n\t  }\n\t  k += 15;\t\t/* ZRL: skip 15 zeroes in band */\n\t}\n      }\n\n      BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n    }\n\n    /* Completed MCU, so update state */\n    entropy->saved.EOBRUN = EOBRUN;\t/* only part of saved state we need */\n  }\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for DC successive approximation refinement scan.\n * Note: we assume such scans can be multi-component,\n * although the spec is not very clear on the point.\n */\n\nMETHODDEF(boolean)\ndecode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{   \n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int p1, blkn;\n  BITREAD_STATE_VARS;\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* Not worth the cycles to check insufficient_data here,\n   * since we will not change the data anyway if we read zeroes.\n   */\n\n  /* Load up working state */\n  BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n\n  p1 = 1 << cinfo->Al;\t\t/* 1 in the bit position being coded */\n\n  /* Outer loop handles each block in the MCU */\n\n  for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n    /* Encoded data is simply the next bit of the two's-complement DC value */\n    CHECK_BIT_BUFFER(br_state, 1, return FALSE);\n    if (GET_BITS(1))\n      MCU_data[blkn][0][0] |= p1;\n    /* Note: since we use |=, repeating the assignment later is safe */\n  }\n\n  /* Completed MCU, so update state */\n  BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n}\n\n\n/*\n * MCU decoding for AC successive approximation refinement scan.\n */\n\nMETHODDEF(boolean)\ndecode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{   \n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  register int s, k, r;\n  unsigned int EOBRUN;\n  int Se, p1, m1;\n  const int * natural_order;\n  JBLOCKROW block;\n  JCOEFPTR thiscoef;\n  BITREAD_STATE_VARS;\n  d_derived_tbl * tbl;\n  int num_newnz;\n  int newnz_pos[DCTSIZE2];\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* If we've run out of data, don't modify the MCU.\n   */\n  if (! entropy->insufficient_data) {\n\n    Se = cinfo->Se;\n    p1 = 1 << cinfo->Al;\t/* 1 in the bit position being coded */\n    m1 = (-1) << cinfo->Al;\t/* -1 in the bit position being coded */\n    natural_order = cinfo->natural_order;\n\n    /* Load up working state */\n    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n    EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */\n\n    /* There is always only one block per MCU */\n    block = MCU_data[0];\n    tbl = entropy->ac_derived_tbl;\n\n    /* If we are forced to suspend, we must undo the assignments to any newly\n     * nonzero coefficients in the block, because otherwise we'd get confused\n     * next time about which coefficients were already nonzero.\n     * But we need not undo addition of bits to already-nonzero coefficients;\n     * instead, we can test the current bit to see if we already did it.\n     */\n    num_newnz = 0;\n\n    /* initialize coefficient loop counter to start of band */\n    k = cinfo->Ss;\n\n    if (EOBRUN == 0) {\n      do {\n\tHUFF_DECODE(s, br_state, tbl, goto undoit, label3);\n\tr = s >> 4;\n\ts &= 15;\n\tif (s) {\n\t  if (s != 1)\t\t/* size of new coef should always be 1 */\n\t    WARNMS(cinfo, JWRN_HUFF_BAD_CODE);\n\t  CHECK_BIT_BUFFER(br_state, 1, goto undoit);\n\t  if (GET_BITS(1))\n\t    s = p1;\t\t/* newly nonzero coef is positive */\n\t  else\n\t    s = m1;\t\t/* newly nonzero coef is negative */\n\t} else {\n\t  if (r != 15) {\n\t    EOBRUN = 1 << r;\t/* EOBr, run length is 2^r + appended bits */\n\t    if (r) {\n\t      CHECK_BIT_BUFFER(br_state, r, goto undoit);\n\t      r = GET_BITS(r);\n\t      EOBRUN += r;\n\t    }\n\t    break;\t\t/* rest of block is handled by EOB logic */\n\t  }\n\t  /* note s = 0 for processing ZRL */\n\t}\n\t/* Advance over already-nonzero coefs and r still-zero coefs,\n\t * appending correction bits to the nonzeroes.  A correction bit is 1\n\t * if the absolute value of the coefficient must be increased.\n\t */\n\tdo {\n\t  thiscoef = *block + natural_order[k];\n\t  if (*thiscoef) {\n\t    CHECK_BIT_BUFFER(br_state, 1, goto undoit);\n\t    if (GET_BITS(1)) {\n\t      if ((*thiscoef & p1) == 0) { /* do nothing if already set it */\n\t\tif (*thiscoef >= 0)\n\t\t  *thiscoef += p1;\n\t\telse\n\t\t  *thiscoef += m1;\n\t      }\n\t    }\n\t  } else {\n\t    if (--r < 0)\n\t      break;\t\t/* reached target zero coefficient */\n\t  }\n\t  k++;\n\t} while (k <= Se);\n\tif (s) {\n\t  int pos = natural_order[k];\n\t  /* Output newly nonzero coefficient */\n\t  (*block)[pos] = (JCOEF) s;\n\t  /* Remember its position in case we have to suspend */\n\t  newnz_pos[num_newnz++] = pos;\n\t}\n\tk++;\n      } while (k <= Se);\n    }\n\n    if (EOBRUN) {\n      /* Scan any remaining coefficient positions after the end-of-band\n       * (the last newly nonzero coefficient, if any).  Append a correction\n       * bit to each already-nonzero coefficient.  A correction bit is 1\n       * if the absolute value of the coefficient must be increased.\n       */\n      do {\n\tthiscoef = *block + natural_order[k];\n\tif (*thiscoef) {\n\t  CHECK_BIT_BUFFER(br_state, 1, goto undoit);\n\t  if (GET_BITS(1)) {\n\t    if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */\n\t      if (*thiscoef >= 0)\n\t\t*thiscoef += p1;\n\t      else\n\t\t*thiscoef += m1;\n\t    }\n\t  }\n\t}\n\tk++;\n      } while (k <= Se);\n      /* Count one block completed in EOB run */\n      EOBRUN--;\n    }\n\n    /* Completed MCU, so update state */\n    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n    entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */\n  }\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n\nundoit:\n  /* Re-zero any output coefficients that we made newly nonzero */\n  while (num_newnz)\n    (*block)[newnz_pos[--num_newnz]] = 0;\n\n  return FALSE;\n}\n\n\n/*\n * Decode one MCU's worth of Huffman-compressed coefficients,\n * partial blocks.\n */\n\nMETHODDEF(boolean)\ndecode_mcu_sub (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  const int * natural_order;\n  int Se, blkn;\n  BITREAD_STATE_VARS;\n  savable_state state;\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* If we've run out of data, just leave the MCU set to zeroes.\n   * This way, we return uniform gray for the remainder of the segment.\n   */\n  if (! entropy->insufficient_data) {\n\n    natural_order = cinfo->natural_order;\n    Se = cinfo->lim_Se;\n\n    /* Load up working state */\n    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(state, entropy->saved);\n\n    /* Outer loop handles each block in the MCU */\n\n    for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n      JBLOCKROW block = MCU_data[blkn];\n      d_derived_tbl * htbl;\n      register int s, k, r;\n      int coef_limit, ci;\n\n      /* Decode a single block's worth of coefficients */\n\n      /* Section F.2.2.1: decode the DC coefficient difference */\n      htbl = entropy->dc_cur_tbls[blkn];\n      HUFF_DECODE(s, br_state, htbl, return FALSE, label1);\n\n      htbl = entropy->ac_cur_tbls[blkn];\n      k = 1;\n      coef_limit = entropy->coef_limit[blkn];\n      if (coef_limit) {\n\t/* Convert DC difference to actual value, update last_dc_val */\n\tif (s) {\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  r = GET_BITS(s);\n\t  s = HUFF_EXTEND(r, s);\n\t}\n\tci = cinfo->MCU_membership[blkn];\n\ts += state.last_dc_val[ci];\n\tstate.last_dc_val[ci] = s;\n\t/* Output the DC coefficient */\n\t(*block)[0] = (JCOEF) s;\n\n\t/* Section F.2.2.2: decode the AC coefficients */\n\t/* Since zeroes are skipped, output area must be cleared beforehand */\n\tfor (; k < coef_limit; k++) {\n\t  HUFF_DECODE(s, br_state, htbl, return FALSE, label2);\n\n\t  r = s >> 4;\n\t  s &= 15;\n\n\t  if (s) {\n\t    k += r;\n\t    CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t    r = GET_BITS(s);\n\t    s = HUFF_EXTEND(r, s);\n\t    /* Output coefficient in natural (dezigzagged) order.\n\t     * Note: the extra entries in natural_order[] will save us\n\t     * if k > Se, which could happen if the data is corrupted.\n\t     */\n\t    (*block)[natural_order[k]] = (JCOEF) s;\n\t  } else {\n\t    if (r != 15)\n\t      goto EndOfBlock;\n\t    k += 15;\n\t  }\n\t}\n      } else {\n\tif (s) {\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  DROP_BITS(s);\n\t}\n      }\n\n      /* Section F.2.2.2: decode the AC coefficients */\n      /* In this path we just discard the values */\n      for (; k <= Se; k++) {\n\tHUFF_DECODE(s, br_state, htbl, return FALSE, label3);\n\n\tr = s >> 4;\n\ts &= 15;\n\n\tif (s) {\n\t  k += r;\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  DROP_BITS(s);\n\t} else {\n\t  if (r != 15)\n\t    break;\n\t  k += 15;\n\t}\n      }\n\n      EndOfBlock: ;\n    }\n\n    /* Completed MCU, so update state */\n    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(entropy->saved, state);\n  }\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n}\n\n\n/*\n * Decode one MCU's worth of Huffman-compressed coefficients,\n * full-size blocks.\n */\n\nMETHODDEF(boolean)\ndecode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int blkn;\n  BITREAD_STATE_VARS;\n  savable_state state;\n\n  /* Process restart marker if needed; may have to suspend */\n  if (cinfo->restart_interval) {\n    if (entropy->restarts_to_go == 0)\n      if (! process_restart(cinfo))\n\treturn FALSE;\n  }\n\n  /* If we've run out of data, just leave the MCU set to zeroes.\n   * This way, we return uniform gray for the remainder of the segment.\n   */\n  if (! entropy->insufficient_data) {\n\n    /* Load up working state */\n    BITREAD_LOAD_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(state, entropy->saved);\n\n    /* Outer loop handles each block in the MCU */\n\n    for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n      JBLOCKROW block = MCU_data[blkn];\n      d_derived_tbl * htbl;\n      register int s, k, r;\n      int coef_limit, ci;\n\n      /* Decode a single block's worth of coefficients */\n\n      /* Section F.2.2.1: decode the DC coefficient difference */\n      htbl = entropy->dc_cur_tbls[blkn];\n      HUFF_DECODE(s, br_state, htbl, return FALSE, label1);\n\n      htbl = entropy->ac_cur_tbls[blkn];\n      k = 1;\n      coef_limit = entropy->coef_limit[blkn];\n      if (coef_limit) {\n\t/* Convert DC difference to actual value, update last_dc_val */\n\tif (s) {\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  r = GET_BITS(s);\n\t  s = HUFF_EXTEND(r, s);\n\t}\n\tci = cinfo->MCU_membership[blkn];\n\ts += state.last_dc_val[ci];\n\tstate.last_dc_val[ci] = s;\n\t/* Output the DC coefficient */\n\t(*block)[0] = (JCOEF) s;\n\n\t/* Section F.2.2.2: decode the AC coefficients */\n\t/* Since zeroes are skipped, output area must be cleared beforehand */\n\tfor (; k < coef_limit; k++) {\n\t  HUFF_DECODE(s, br_state, htbl, return FALSE, label2);\n\n\t  r = s >> 4;\n\t  s &= 15;\n\n\t  if (s) {\n\t    k += r;\n\t    CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t    r = GET_BITS(s);\n\t    s = HUFF_EXTEND(r, s);\n\t    /* Output coefficient in natural (dezigzagged) order.\n\t     * Note: the extra entries in jpeg_natural_order[] will save us\n\t     * if k >= DCTSIZE2, which could happen if the data is corrupted.\n\t     */\n\t    (*block)[jpeg_natural_order[k]] = (JCOEF) s;\n\t  } else {\n\t    if (r != 15)\n\t      goto EndOfBlock;\n\t    k += 15;\n\t  }\n\t}\n      } else {\n\tif (s) {\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  DROP_BITS(s);\n\t}\n      }\n\n      /* Section F.2.2.2: decode the AC coefficients */\n      /* In this path we just discard the values */\n      for (; k < DCTSIZE2; k++) {\n\tHUFF_DECODE(s, br_state, htbl, return FALSE, label3);\n\n\tr = s >> 4;\n\ts &= 15;\n\n\tif (s) {\n\t  k += r;\n\t  CHECK_BIT_BUFFER(br_state, s, return FALSE);\n\t  DROP_BITS(s);\n\t} else {\n\t  if (r != 15)\n\t    break;\n\t  k += 15;\n\t}\n      }\n\n      EndOfBlock: ;\n    }\n\n    /* Completed MCU, so update state */\n    BITREAD_SAVE_STATE(cinfo,entropy->bitstate);\n    ASSIGN_STATE(entropy->saved, state);\n  }\n\n  /* Account for restart interval (no-op if not using restarts) */\n  entropy->restarts_to_go--;\n\n  return TRUE;\n}\n\n\n/*\n * Initialize for a Huffman-compressed scan.\n */\n\nMETHODDEF(void)\nstart_pass_huff_decoder (j_decompress_ptr cinfo)\n{\n  huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;\n  int ci, blkn, tbl, i;\n  jpeg_component_info * compptr;\n\n  if (cinfo->progressive_mode) {\n    /* Validate progressive scan parameters */\n    if (cinfo->Ss == 0) {\n      if (cinfo->Se != 0)\n\tgoto bad;\n    } else {\n      /* need not check Ss/Se < 0 since they came from unsigned bytes */\n      if (cinfo->Se < cinfo->Ss || cinfo->Se > cinfo->lim_Se)\n\tgoto bad;\n      /* AC scans may have only one component */\n      if (cinfo->comps_in_scan != 1)\n\tgoto bad;\n    }\n    if (cinfo->Ah != 0) {\n      /* Successive approximation refinement scan: must have Al = Ah-1. */\n      if (cinfo->Ah-1 != cinfo->Al)\n\tgoto bad;\n    }\n    if (cinfo->Al > 13) {\t/* need not check for < 0 */\n      /* Arguably the maximum Al value should be less than 13 for 8-bit precision,\n       * but the spec doesn't say so, and we try to be liberal about what we\n       * accept.  Note: large Al values could result in out-of-range DC\n       * coefficients during early scans, leading to bizarre displays due to\n       * overflows in the IDCT math.  But we won't crash.\n       */\n      bad:\n      ERREXIT4(cinfo, JERR_BAD_PROGRESSION,\n\t       cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);\n    }\n    /* Update progression status, and verify that scan order is legal.\n     * Note that inter-scan inconsistencies are treated as warnings\n     * not fatal errors ... not clear if this is right way to behave.\n     */\n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      int coefi, cindex = cinfo->cur_comp_info[ci]->component_index;\n      int *coef_bit_ptr = & cinfo->coef_bits[cindex][0];\n      if (cinfo->Ss && coef_bit_ptr[0] < 0) /* AC without prior DC scan */\n\tWARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);\n      for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {\n\tint expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];\n\tif (cinfo->Ah != expected)\n\t  WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);\n\tcoef_bit_ptr[coefi] = cinfo->Al;\n      }\n    }\n\n    /* Select MCU decoding routine */\n    if (cinfo->Ah == 0) {\n      if (cinfo->Ss == 0)\n\tentropy->pub.decode_mcu = decode_mcu_DC_first;\n      else\n\tentropy->pub.decode_mcu = decode_mcu_AC_first;\n    } else {\n      if (cinfo->Ss == 0)\n\tentropy->pub.decode_mcu = decode_mcu_DC_refine;\n      else\n\tentropy->pub.decode_mcu = decode_mcu_AC_refine;\n    }\n\n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      compptr = cinfo->cur_comp_info[ci];\n      /* Make sure requested tables are present, and compute derived tables.\n       * We may build same derived table more than once, but it's not expensive.\n       */\n      if (cinfo->Ss == 0) {\n\tif (cinfo->Ah == 0) {\t/* DC refinement needs no table */\n\t  tbl = compptr->dc_tbl_no;\n\t  jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,\n\t\t\t\t  & entropy->derived_tbls[tbl]);\n\t}\n      } else {\n\ttbl = compptr->ac_tbl_no;\n\tjpeg_make_d_derived_tbl(cinfo, FALSE, tbl,\n\t\t\t\t& entropy->derived_tbls[tbl]);\n\t/* remember the single active table */\n\tentropy->ac_derived_tbl = entropy->derived_tbls[tbl];\n      }\n      /* Initialize DC predictions to 0 */\n      entropy->saved.last_dc_val[ci] = 0;\n    }\n\n    /* Initialize private state variables */\n    entropy->saved.EOBRUN = 0;\n  } else {\n    /* Check that the scan parameters Ss, Se, Ah/Al are OK for sequential JPEG.\n     * This ought to be an error condition, but we make it a warning because\n     * there are some baseline files out there with all zeroes in these bytes.\n     */\n    if (cinfo->Ss != 0 || cinfo->Ah != 0 || cinfo->Al != 0 ||\n\t((cinfo->is_baseline || cinfo->Se < DCTSIZE2) &&\n\tcinfo->Se != cinfo->lim_Se))\n      WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);\n\n    /* Select MCU decoding routine */\n    /* We retain the hard-coded case for full-size blocks.\n     * This is not necessary, but it appears that this version is slightly\n     * more performant in the given implementation.\n     * With an improved implementation we would prefer a single optimized\n     * function.\n     */\n    if (cinfo->lim_Se != DCTSIZE2-1)\n      entropy->pub.decode_mcu = decode_mcu_sub;\n    else\n      entropy->pub.decode_mcu = decode_mcu;\n\n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      compptr = cinfo->cur_comp_info[ci];\n      /* Compute derived values for Huffman tables */\n      /* We may do this more than once for a table, but it's not expensive */\n      tbl = compptr->dc_tbl_no;\n      jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,\n\t\t\t      & entropy->dc_derived_tbls[tbl]);\n      if (cinfo->lim_Se) {\t/* AC needs no table when not present */\n\ttbl = compptr->ac_tbl_no;\n\tjpeg_make_d_derived_tbl(cinfo, FALSE, tbl,\n\t\t\t\t& entropy->ac_derived_tbls[tbl]);\n      }\n      /* Initialize DC predictions to 0 */\n      entropy->saved.last_dc_val[ci] = 0;\n    }\n\n    /* Precalculate decoding info for each block in an MCU of this scan */\n    for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {\n      ci = cinfo->MCU_membership[blkn];\n      compptr = cinfo->cur_comp_info[ci];\n      /* Precalculate which table to use for each block */\n      entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];\n      entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];\n      /* Decide whether we really care about the coefficient values */\n      if (compptr->component_needed) {\n\tci = compptr->DCT_v_scaled_size;\n\ti = compptr->DCT_h_scaled_size;\n\tswitch (cinfo->lim_Se) {\n\tcase (1*1-1):\n\t  entropy->coef_limit[blkn] = 1;\n\t  break;\n\tcase (2*2-1):\n\t  if (ci <= 0 || ci > 2) ci = 2;\n\t  if (i <= 0 || i > 2) i = 2;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order2[ci - 1][i - 1];\n\t  break;\n\tcase (3*3-1):\n\t  if (ci <= 0 || ci > 3) ci = 3;\n\t  if (i <= 0 || i > 3) i = 3;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order3[ci - 1][i - 1];\n\t  break;\n\tcase (4*4-1):\n\t  if (ci <= 0 || ci > 4) ci = 4;\n\t  if (i <= 0 || i > 4) i = 4;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order4[ci - 1][i - 1];\n\t  break;\n\tcase (5*5-1):\n\t  if (ci <= 0 || ci > 5) ci = 5;\n\t  if (i <= 0 || i > 5) i = 5;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order5[ci - 1][i - 1];\n\t  break;\n\tcase (6*6-1):\n\t  if (ci <= 0 || ci > 6) ci = 6;\n\t  if (i <= 0 || i > 6) i = 6;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order6[ci - 1][i - 1];\n\t  break;\n\tcase (7*7-1):\n\t  if (ci <= 0 || ci > 7) ci = 7;\n\t  if (i <= 0 || i > 7) i = 7;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order7[ci - 1][i - 1];\n\t  break;\n\tdefault:\n\t  if (ci <= 0 || ci > 8) ci = 8;\n\t  if (i <= 0 || i > 8) i = 8;\n\t  entropy->coef_limit[blkn] = 1 + jpeg_zigzag_order[ci - 1][i - 1];\n\t  break;\n\t}\n      } else {\n\tentropy->coef_limit[blkn] = 0;\n      }\n    }\n  }\n\n  /* Initialize bitread state variables */\n  entropy->bitstate.bits_left = 0;\n  entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */\n  entropy->insufficient_data = FALSE;\n\n  /* Initialize restart counter */\n  entropy->restarts_to_go = cinfo->restart_interval;\n}\n\n\n/*\n * Module initialization routine for Huffman entropy decoding.\n */\n\nGLOBAL(void)\njinit_huff_decoder (j_decompress_ptr cinfo)\n{\n  huff_entropy_ptr entropy;\n  int i;\n\n  entropy = (huff_entropy_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(huff_entropy_decoder));\n  cinfo->entropy = &entropy->pub;\n  entropy->pub.start_pass = start_pass_huff_decoder;\n  entropy->pub.finish_pass = finish_pass_huff;\n\n  if (cinfo->progressive_mode) {\n    /* Create progression status table */\n    int *coef_bit_ptr, ci;\n    cinfo->coef_bits = (int (*)[DCTSIZE2])\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  cinfo->num_components*DCTSIZE2*SIZEOF(int));\n    coef_bit_ptr = & cinfo->coef_bits[0][0];\n    for (ci = 0; ci < cinfo->num_components; ci++)\n      for (i = 0; i < DCTSIZE2; i++)\n\t*coef_bit_ptr++ = -1;\n\n    /* Mark derived tables unallocated */\n    for (i = 0; i < NUM_HUFF_TBLS; i++) {\n      entropy->derived_tbls[i] = NULL;\n    }\n  } else {\n    /* Mark tables unallocated */\n    for (i = 0; i < NUM_HUFF_TBLS; i++) {\n      entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;\n    }\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdinput.c",
    "content": "/*\n * jdinput.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2002-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains input control logic for the JPEG decompressor.\n * These routines are concerned with controlling the decompressor's input\n * processing (marker reading and coefficient decoding).  The actual input\n * reading is done in jdmarker.c, jdhuff.c, and jdarith.c.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private state */\n\ntypedef struct {\n  struct jpeg_input_controller pub; /* public fields */\n\n  int inheaders;\t\t/* Nonzero until first SOS is reached */\n} my_input_controller;\n\ntypedef my_input_controller * my_inputctl_ptr;\n\n\n/* Forward declarations */\nMETHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));\n\n\n/*\n * Routines to calculate various quantities related to the size of the image.\n */\n\n\n/*\n * Compute output image dimensions and related values.\n * NOTE: this is exported for possible use by application.\n * Hence it mustn't do anything that can't be done twice.\n */\n\nGLOBAL(void)\njpeg_core_output_dimensions (j_decompress_ptr cinfo)\n/* Do computations that are needed before master selection phase.\n * This function is used for transcoding and full decompression.\n */\n{\n#ifdef IDCT_SCALING_SUPPORTED\n  int ci;\n  jpeg_component_info *compptr;\n\n  /* Compute actual output image dimensions and DCT scaling choices. */\n  if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom) {\n    /* Provide 1/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 1;\n    cinfo->min_DCT_v_scaled_size = 1;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 2) {\n    /* Provide 2/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 2L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 2L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 2;\n    cinfo->min_DCT_v_scaled_size = 2;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 3) {\n    /* Provide 3/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 3L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 3L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 3;\n    cinfo->min_DCT_v_scaled_size = 3;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 4) {\n    /* Provide 4/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 4L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 4L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 4;\n    cinfo->min_DCT_v_scaled_size = 4;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 5) {\n    /* Provide 5/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 5L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 5L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 5;\n    cinfo->min_DCT_v_scaled_size = 5;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 6) {\n    /* Provide 6/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 6L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 6L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 6;\n    cinfo->min_DCT_v_scaled_size = 6;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 7) {\n    /* Provide 7/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 7L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 7L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 7;\n    cinfo->min_DCT_v_scaled_size = 7;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 8) {\n    /* Provide 8/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 8L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 8L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 8;\n    cinfo->min_DCT_v_scaled_size = 8;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 9) {\n    /* Provide 9/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 9L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 9L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 9;\n    cinfo->min_DCT_v_scaled_size = 9;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 10) {\n    /* Provide 10/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 10L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 10L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 10;\n    cinfo->min_DCT_v_scaled_size = 10;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 11) {\n    /* Provide 11/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 11L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 11L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 11;\n    cinfo->min_DCT_v_scaled_size = 11;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 12) {\n    /* Provide 12/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 12L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 12L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 12;\n    cinfo->min_DCT_v_scaled_size = 12;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 13) {\n    /* Provide 13/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 13L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 13L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 13;\n    cinfo->min_DCT_v_scaled_size = 13;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 14) {\n    /* Provide 14/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 14L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 14L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 14;\n    cinfo->min_DCT_v_scaled_size = 14;\n  } else if (cinfo->scale_num * cinfo->block_size <= cinfo->scale_denom * 15) {\n    /* Provide 15/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 15L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 15L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 15;\n    cinfo->min_DCT_v_scaled_size = 15;\n  } else {\n    /* Provide 16/block_size scaling */\n    cinfo->output_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * 16L, (long) cinfo->block_size);\n    cinfo->output_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * 16L, (long) cinfo->block_size);\n    cinfo->min_DCT_h_scaled_size = 16;\n    cinfo->min_DCT_v_scaled_size = 16;\n  }\n\n  /* Recompute dimensions of components */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size;\n    compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size;\n  }\n\n#else /* !IDCT_SCALING_SUPPORTED */\n\n  /* Hardwire it to \"no scaling\" */\n  cinfo->output_width = cinfo->image_width;\n  cinfo->output_height = cinfo->image_height;\n  /* initial_setup has already initialized DCT_scaled_size,\n   * and has computed unscaled downsampled_width and downsampled_height.\n   */\n\n#endif /* IDCT_SCALING_SUPPORTED */\n}\n\n\nLOCAL(void)\ninitial_setup (j_decompress_ptr cinfo)\n/* Called once, when first SOS marker is reached */\n{\n  int ci;\n  jpeg_component_info *compptr;\n\n  /* Make sure image isn't bigger than I can handle */\n  if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||\n      (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)\n    ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);\n\n  /* Only 8 to 12 bits data precision are supported for DCT based JPEG */\n  if (cinfo->data_precision < 8 || cinfo->data_precision > 12)\n    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);\n\n  /* Check that number of components won't exceed internal array sizes */\n  if (cinfo->num_components > MAX_COMPONENTS)\n    ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,\n\t     MAX_COMPONENTS);\n\n  /* Compute maximum sampling factors; check factor validity */\n  cinfo->max_h_samp_factor = 1;\n  cinfo->max_v_samp_factor = 1;\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||\n\tcompptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)\n      ERREXIT(cinfo, JERR_BAD_SAMPLING);\n    cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,\n\t\t\t\t   compptr->h_samp_factor);\n    cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,\n\t\t\t\t   compptr->v_samp_factor);\n  }\n\n  /* Derive block_size, natural_order, and lim_Se */\n  if (cinfo->is_baseline || (cinfo->progressive_mode &&\n      cinfo->comps_in_scan)) { /* no pseudo SOS marker */\n    cinfo->block_size = DCTSIZE;\n    cinfo->natural_order = jpeg_natural_order;\n    cinfo->lim_Se = DCTSIZE2-1;\n  } else\n    switch (cinfo->Se) {\n    case (1*1-1):\n      cinfo->block_size = 1;\n      cinfo->natural_order = jpeg_natural_order; /* not needed */\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (2*2-1):\n      cinfo->block_size = 2;\n      cinfo->natural_order = jpeg_natural_order2;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (3*3-1):\n      cinfo->block_size = 3;\n      cinfo->natural_order = jpeg_natural_order3;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (4*4-1):\n      cinfo->block_size = 4;\n      cinfo->natural_order = jpeg_natural_order4;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (5*5-1):\n      cinfo->block_size = 5;\n      cinfo->natural_order = jpeg_natural_order5;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (6*6-1):\n      cinfo->block_size = 6;\n      cinfo->natural_order = jpeg_natural_order6;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (7*7-1):\n      cinfo->block_size = 7;\n      cinfo->natural_order = jpeg_natural_order7;\n      cinfo->lim_Se = cinfo->Se;\n      break;\n    case (8*8-1):\n      cinfo->block_size = 8;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (9*9-1):\n      cinfo->block_size = 9;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (10*10-1):\n      cinfo->block_size = 10;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (11*11-1):\n      cinfo->block_size = 11;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (12*12-1):\n      cinfo->block_size = 12;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (13*13-1):\n      cinfo->block_size = 13;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (14*14-1):\n      cinfo->block_size = 14;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (15*15-1):\n      cinfo->block_size = 15;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    case (16*16-1):\n      cinfo->block_size = 16;\n      cinfo->natural_order = jpeg_natural_order;\n      cinfo->lim_Se = DCTSIZE2-1;\n      break;\n    default:\n      ERREXIT4(cinfo, JERR_BAD_PROGRESSION,\n\t       cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);\n      break;\n    }\n\n  /* We initialize DCT_scaled_size and min_DCT_scaled_size to block_size.\n   * In the full decompressor,\n   * this will be overridden by jpeg_calc_output_dimensions in jdmaster.c;\n   * but in the transcoder,\n   * jpeg_calc_output_dimensions is not used, so we must do it here.\n   */\n  cinfo->min_DCT_h_scaled_size = cinfo->block_size;\n  cinfo->min_DCT_v_scaled_size = cinfo->block_size;\n\n  /* Compute dimensions of components */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    compptr->DCT_h_scaled_size = cinfo->block_size;\n    compptr->DCT_v_scaled_size = cinfo->block_size;\n    /* Size in DCT blocks */\n    compptr->width_in_blocks = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    compptr->height_in_blocks = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n    /* downsampled_width and downsampled_height will also be overridden by\n     * jdmaster.c if we are doing full decompression.  The transcoder library\n     * doesn't use these values, but the calling application might.\n     */\n    /* Size in samples */\n    compptr->downsampled_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,\n\t\t    (long) cinfo->max_h_samp_factor);\n    compptr->downsampled_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,\n\t\t    (long) cinfo->max_v_samp_factor);\n    /* Mark component needed, until color conversion says otherwise */\n    compptr->component_needed = TRUE;\n    /* Mark no quantization table yet saved for component */\n    compptr->quant_table = NULL;\n  }\n\n  /* Compute number of fully interleaved MCU rows. */\n  cinfo->total_iMCU_rows = (JDIMENSION)\n    jdiv_round_up((long) cinfo->image_height,\n\t          (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n\n  /* Decide whether file contains multiple scans */\n  if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)\n    cinfo->inputctl->has_multiple_scans = TRUE;\n  else\n    cinfo->inputctl->has_multiple_scans = FALSE;\n}\n\n\nLOCAL(void)\nper_scan_setup (j_decompress_ptr cinfo)\n/* Do computations that are needed before processing a JPEG scan */\n/* cinfo->comps_in_scan and cinfo->cur_comp_info[] were set from SOS marker */\n{\n  int ci, mcublks, tmp;\n  jpeg_component_info *compptr;\n  \n  if (cinfo->comps_in_scan == 1) {\n    \n    /* Noninterleaved (single-component) scan */\n    compptr = cinfo->cur_comp_info[0];\n    \n    /* Overall image size in MCUs */\n    cinfo->MCUs_per_row = compptr->width_in_blocks;\n    cinfo->MCU_rows_in_scan = compptr->height_in_blocks;\n    \n    /* For noninterleaved scan, always one block per MCU */\n    compptr->MCU_width = 1;\n    compptr->MCU_height = 1;\n    compptr->MCU_blocks = 1;\n    compptr->MCU_sample_width = compptr->DCT_h_scaled_size;\n    compptr->last_col_width = 1;\n    /* For noninterleaved scans, it is convenient to define last_row_height\n     * as the number of block rows present in the last iMCU row.\n     */\n    tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);\n    if (tmp == 0) tmp = compptr->v_samp_factor;\n    compptr->last_row_height = tmp;\n    \n    /* Prepare array describing MCU composition */\n    cinfo->blocks_in_MCU = 1;\n    cinfo->MCU_membership[0] = 0;\n    \n  } else {\n    \n    /* Interleaved (multi-component) scan */\n    if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)\n      ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,\n\t       MAX_COMPS_IN_SCAN);\n    \n    /* Overall image size in MCUs */\n    cinfo->MCUs_per_row = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width,\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    cinfo->MCU_rows_in_scan = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height,\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n    \n    cinfo->blocks_in_MCU = 0;\n    \n    for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n      compptr = cinfo->cur_comp_info[ci];\n      /* Sampling factors give # of blocks of component in each MCU */\n      compptr->MCU_width = compptr->h_samp_factor;\n      compptr->MCU_height = compptr->v_samp_factor;\n      compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;\n      compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_h_scaled_size;\n      /* Figure number of non-dummy blocks in last MCU column & row */\n      tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);\n      if (tmp == 0) tmp = compptr->MCU_width;\n      compptr->last_col_width = tmp;\n      tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);\n      if (tmp == 0) tmp = compptr->MCU_height;\n      compptr->last_row_height = tmp;\n      /* Prepare array describing MCU composition */\n      mcublks = compptr->MCU_blocks;\n      if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)\n\tERREXIT(cinfo, JERR_BAD_MCU_SIZE);\n      while (mcublks-- > 0) {\n\tcinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;\n      }\n    }\n    \n  }\n}\n\n\n/*\n * Save away a copy of the Q-table referenced by each component present\n * in the current scan, unless already saved during a prior scan.\n *\n * In a multiple-scan JPEG file, the encoder could assign different components\n * the same Q-table slot number, but change table definitions between scans\n * so that each component uses a different Q-table.  (The IJG encoder is not\n * currently capable of doing this, but other encoders might.)  Since we want\n * to be able to dequantize all the components at the end of the file, this\n * means that we have to save away the table actually used for each component.\n * We do this by copying the table at the start of the first scan containing\n * the component.\n * The JPEG spec prohibits the encoder from changing the contents of a Q-table\n * slot between scans of a component using that slot.  If the encoder does so\n * anyway, this decoder will simply use the Q-table values that were current\n * at the start of the first scan for the component.\n *\n * The decompressor output side looks only at the saved quant tables,\n * not at the current Q-table slots.\n */\n\nLOCAL(void)\nlatch_quant_tables (j_decompress_ptr cinfo)\n{\n  int ci, qtblno;\n  jpeg_component_info *compptr;\n  JQUANT_TBL * qtbl;\n\n  for (ci = 0; ci < cinfo->comps_in_scan; ci++) {\n    compptr = cinfo->cur_comp_info[ci];\n    /* No work if we already saved Q-table for this component */\n    if (compptr->quant_table != NULL)\n      continue;\n    /* Make sure specified quantization table is present */\n    qtblno = compptr->quant_tbl_no;\n    if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||\n\tcinfo->quant_tbl_ptrs[qtblno] == NULL)\n      ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);\n    /* OK, save away the quantization table */\n    qtbl = (JQUANT_TBL *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(JQUANT_TBL));\n    MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));\n    compptr->quant_table = qtbl;\n  }\n}\n\n\n/*\n * Initialize the input modules to read a scan of compressed data.\n * The first call to this is done by jdmaster.c after initializing\n * the entire decompressor (during jpeg_start_decompress).\n * Subsequent calls come from consume_markers, below.\n */\n\nMETHODDEF(void)\nstart_input_pass (j_decompress_ptr cinfo)\n{\n  per_scan_setup(cinfo);\n  latch_quant_tables(cinfo);\n  (*cinfo->entropy->start_pass) (cinfo);\n  (*cinfo->coef->start_input_pass) (cinfo);\n  cinfo->inputctl->consume_input = cinfo->coef->consume_data;\n}\n\n\n/*\n * Finish up after inputting a compressed-data scan.\n * This is called by the coefficient controller after it's read all\n * the expected data of the scan.\n */\n\nMETHODDEF(void)\nfinish_input_pass (j_decompress_ptr cinfo)\n{\n  (*cinfo->entropy->finish_pass) (cinfo);\n  cinfo->inputctl->consume_input = consume_markers;\n}\n\n\n/*\n * Read JPEG markers before, between, or after compressed-data scans.\n * Change state as necessary when a new scan is reached.\n * Return value is JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.\n *\n * The consume_input method pointer points either here or to the\n * coefficient controller's consume_data routine, depending on whether\n * we are reading a compressed data segment or inter-segment markers.\n *\n * Note: This function should NOT return a pseudo SOS marker (with zero\n * component number) to the caller.  A pseudo marker received by\n * read_markers is processed and then skipped for other markers.\n */\n\nMETHODDEF(int)\nconsume_markers (j_decompress_ptr cinfo)\n{\n  my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;\n  int val;\n\n  if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */\n    return JPEG_REACHED_EOI;\n\n  for (;;) {\t\t\t/* Loop to pass pseudo SOS marker */\n    val = (*cinfo->marker->read_markers) (cinfo);\n\n    switch (val) {\n    case JPEG_REACHED_SOS:\t/* Found SOS */\n      if (inputctl->inheaders) { /* 1st SOS */\n\tif (inputctl->inheaders == 1)\n\t  initial_setup(cinfo);\n\tif (cinfo->comps_in_scan == 0) { /* pseudo SOS marker */\n\t  inputctl->inheaders = 2;\n\t  break;\n\t}\n\tinputctl->inheaders = 0;\n\t/* Note: start_input_pass must be called by jdmaster.c\n\t * before any more input can be consumed.  jdapimin.c is\n\t * responsible for enforcing this sequencing.\n\t */\n      } else {\t\t\t/* 2nd or later SOS marker */\n\tif (! inputctl->pub.has_multiple_scans)\n\t  ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */\n\tif (cinfo->comps_in_scan == 0) /* unexpected pseudo SOS marker */\n\t  break;\n\tstart_input_pass(cinfo);\n      }\n      return val;\n    case JPEG_REACHED_EOI:\t/* Found EOI */\n      inputctl->pub.eoi_reached = TRUE;\n      if (inputctl->inheaders) { /* Tables-only datastream, apparently */\n\tif (cinfo->marker->saw_SOF)\n\t  ERREXIT(cinfo, JERR_SOF_NO_SOS);\n      } else {\n\t/* Prevent infinite loop in coef ctlr's decompress_data routine\n\t * if user set output_scan_number larger than number of scans.\n\t */\n\tif (cinfo->output_scan_number > cinfo->input_scan_number)\n\t  cinfo->output_scan_number = cinfo->input_scan_number;\n      }\n      return val;\n    case JPEG_SUSPENDED:\n      return val;\n    default:\n      return val;\n    }\n  }\n}\n\n\n/*\n * Reset state to begin a fresh datastream.\n */\n\nMETHODDEF(void)\nreset_input_controller (j_decompress_ptr cinfo)\n{\n  my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;\n\n  inputctl->pub.consume_input = consume_markers;\n  inputctl->pub.has_multiple_scans = FALSE; /* \"unknown\" would be better */\n  inputctl->pub.eoi_reached = FALSE;\n  inputctl->inheaders = 1;\n  /* Reset other modules */\n  (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);\n  (*cinfo->marker->reset_marker_reader) (cinfo);\n  /* Reset progression state -- would be cleaner if entropy decoder did this */\n  cinfo->coef_bits = NULL;\n}\n\n\n/*\n * Initialize the input controller module.\n * This is called only once, when the decompression object is created.\n */\n\nGLOBAL(void)\njinit_input_controller (j_decompress_ptr cinfo)\n{\n  my_inputctl_ptr inputctl;\n\n  /* Create subobject in permanent pool */\n  inputctl = (my_inputctl_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\tSIZEOF(my_input_controller));\n  cinfo->inputctl = &inputctl->pub;\n  /* Initialize method pointers */\n  inputctl->pub.consume_input = consume_markers;\n  inputctl->pub.reset_input_controller = reset_input_controller;\n  inputctl->pub.start_input_pass = start_input_pass;\n  inputctl->pub.finish_input_pass = finish_input_pass;\n  /* Initialize state: can't use reset_input_controller since we don't\n   * want to try to reset other modules yet.\n   */\n  inputctl->pub.has_multiple_scans = FALSE; /* \"unknown\" would be better */\n  inputctl->pub.eoi_reached = FALSE;\n  inputctl->inheaders = 1;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdmainct.c",
    "content": "/*\n * jdmainct.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2002-2012 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the main buffer controller for decompression.\n * The main buffer lies between the JPEG decompressor proper and the\n * post-processor; it holds downsampled data in the JPEG colorspace.\n *\n * Note that this code is bypassed in raw-data mode, since the application\n * supplies the equivalent of the main buffer in that case.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * In the current system design, the main buffer need never be a full-image\n * buffer; any full-height buffers will be found inside the coefficient or\n * postprocessing controllers.  Nonetheless, the main controller is not\n * trivial.  Its responsibility is to provide context rows for upsampling/\n * rescaling, and doing this in an efficient fashion is a bit tricky.\n *\n * Postprocessor input data is counted in \"row groups\".  A row group\n * is defined to be (v_samp_factor * DCT_scaled_size / min_DCT_scaled_size)\n * sample rows of each component.  (We require DCT_scaled_size values to be\n * chosen such that these numbers are integers.  In practice DCT_scaled_size\n * values will likely be powers of two, so we actually have the stronger\n * condition that DCT_scaled_size / min_DCT_scaled_size is an integer.)\n * Upsampling will typically produce max_v_samp_factor pixel rows from each\n * row group (times any additional scale factor that the upsampler is\n * applying).\n *\n * The coefficient controller will deliver data to us one iMCU row at a time;\n * each iMCU row contains v_samp_factor * DCT_scaled_size sample rows, or\n * exactly min_DCT_scaled_size row groups.  (This amount of data corresponds\n * to one row of MCUs when the image is fully interleaved.)  Note that the\n * number of sample rows varies across components, but the number of row\n * groups does not.  Some garbage sample rows may be included in the last iMCU\n * row at the bottom of the image.\n *\n * Depending on the vertical scaling algorithm used, the upsampler may need\n * access to the sample row(s) above and below its current input row group.\n * The upsampler is required to set need_context_rows TRUE at global selection\n * time if so.  When need_context_rows is FALSE, this controller can simply\n * obtain one iMCU row at a time from the coefficient controller and dole it\n * out as row groups to the postprocessor.\n *\n * When need_context_rows is TRUE, this controller guarantees that the buffer\n * passed to postprocessing contains at least one row group's worth of samples\n * above and below the row group(s) being processed.  Note that the context\n * rows \"above\" the first passed row group appear at negative row offsets in\n * the passed buffer.  At the top and bottom of the image, the required\n * context rows are manufactured by duplicating the first or last real sample\n * row; this avoids having special cases in the upsampling inner loops.\n *\n * The amount of context is fixed at one row group just because that's a\n * convenient number for this controller to work with.  The existing\n * upsamplers really only need one sample row of context.  An upsampler\n * supporting arbitrary output rescaling might wish for more than one row\n * group of context when shrinking the image; tough, we don't handle that.\n * (This is justified by the assumption that downsizing will be handled mostly\n * by adjusting the DCT_scaled_size values, so that the actual scale factor at\n * the upsample step needn't be much less than one.)\n *\n * To provide the desired context, we have to retain the last two row groups\n * of one iMCU row while reading in the next iMCU row.  (The last row group\n * can't be processed until we have another row group for its below-context,\n * and so we have to save the next-to-last group too for its above-context.)\n * We could do this most simply by copying data around in our buffer, but\n * that'd be very slow.  We can avoid copying any data by creating a rather\n * strange pointer structure.  Here's how it works.  We allocate a workspace\n * consisting of M+2 row groups (where M = min_DCT_scaled_size is the number\n * of row groups per iMCU row).  We create two sets of redundant pointers to\n * the workspace.  Labeling the physical row groups 0 to M+1, the synthesized\n * pointer lists look like this:\n *                   M+1                          M-1\n * master pointer --> 0         master pointer --> 0\n *                    1                            1\n *                   ...                          ...\n *                   M-3                          M-3\n *                   M-2                           M\n *                   M-1                          M+1\n *                    M                           M-2\n *                   M+1                          M-1\n *                    0                            0\n * We read alternate iMCU rows using each master pointer; thus the last two\n * row groups of the previous iMCU row remain un-overwritten in the workspace.\n * The pointer lists are set up so that the required context rows appear to\n * be adjacent to the proper places when we pass the pointer lists to the\n * upsampler.\n *\n * The above pictures describe the normal state of the pointer lists.\n * At top and bottom of the image, we diddle the pointer lists to duplicate\n * the first or last sample row as necessary (this is cheaper than copying\n * sample rows around).\n *\n * This scheme breaks down if M < 2, ie, min_DCT_scaled_size is 1.  In that\n * situation each iMCU row provides only one row group so the buffering logic\n * must be different (eg, we must read two iMCU rows before we can emit the\n * first row group).  For now, we simply do not support providing context\n * rows when min_DCT_scaled_size is 1.  That combination seems unlikely to\n * be worth providing --- if someone wants a 1/8th-size preview, they probably\n * want it quick and dirty, so a context-free upsampler is sufficient.\n */\n\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_d_main_controller pub; /* public fields */\n\n  /* Pointer to allocated workspace (M or M+2 row groups). */\n  JSAMPARRAY buffer[MAX_COMPONENTS];\n\n  boolean buffer_full;\t\t/* Have we gotten an iMCU row from decoder? */\n  JDIMENSION rowgroup_ctr;\t/* counts row groups output to postprocessor */\n\n  /* Remaining fields are only used in the context case. */\n\n  /* These are the master pointers to the funny-order pointer lists. */\n  JSAMPIMAGE xbuffer[2];\t/* pointers to weird pointer lists */\n\n  int whichptr;\t\t\t/* indicates which pointer set is now in use */\n  int context_state;\t\t/* process_data state machine status */\n  JDIMENSION rowgroups_avail;\t/* row groups available to postprocessor */\n  JDIMENSION iMCU_row_ctr;\t/* counts iMCU rows to detect image top/bot */\n} my_main_controller;\n\ntypedef my_main_controller * my_main_ptr;\n\n/* context_state values: */\n#define CTX_PREPARE_FOR_IMCU\t0\t/* need to prepare for MCU row */\n#define CTX_PROCESS_IMCU\t1\t/* feeding iMCU to postprocessor */\n#define CTX_POSTPONED_ROW\t2\t/* feeding postponed row group */\n\n\n/* Forward declarations */\nMETHODDEF(void) process_data_simple_main\n\tJPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,\n\t     JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));\nMETHODDEF(void) process_data_context_main\n\tJPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,\n\t     JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));\n#ifdef QUANT_2PASS_SUPPORTED\nMETHODDEF(void) process_data_crank_post\n\tJPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,\n\t     JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));\n#endif\n\n\nLOCAL(void)\nalloc_funny_pointers (j_decompress_ptr cinfo)\n/* Allocate space for the funny pointer lists.\n * This is done only once, not once per pass.\n */\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  int ci, rgroup;\n  int M = cinfo->min_DCT_v_scaled_size;\n  jpeg_component_info *compptr;\n  JSAMPARRAY xbuf;\n\n  /* Get top-level space for component array pointers.\n   * We alloc both arrays with one call to save a few cycles.\n   */\n  mainp->xbuffer[0] = (JSAMPIMAGE)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tcinfo->num_components * 2 * SIZEOF(JSAMPARRAY));\n  mainp->xbuffer[1] = mainp->xbuffer[0] + cinfo->num_components;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n      cinfo->min_DCT_v_scaled_size; /* height of a row group of component */\n    /* Get space for pointer lists --- M+4 row groups in each list.\n     * We alloc both pointer lists with one call to save a few cycles.\n     */\n    xbuf = (JSAMPARRAY)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));\n    xbuf += rgroup;\t\t/* want one row group at negative offsets */\n    mainp->xbuffer[0][ci] = xbuf;\n    xbuf += rgroup * (M + 4);\n    mainp->xbuffer[1][ci] = xbuf;\n  }\n}\n\n\nLOCAL(void)\nmake_funny_pointers (j_decompress_ptr cinfo)\n/* Create the funny pointer lists discussed in the comments above.\n * The actual workspace is already allocated (in main->buffer),\n * and the space for the pointer lists is allocated too.\n * This routine just fills in the curiously ordered lists.\n * This will be repeated at the beginning of each pass.\n */\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  int ci, i, rgroup;\n  int M = cinfo->min_DCT_v_scaled_size;\n  jpeg_component_info *compptr;\n  JSAMPARRAY buf, xbuf0, xbuf1;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n      cinfo->min_DCT_v_scaled_size; /* height of a row group of component */\n    xbuf0 = mainp->xbuffer[0][ci];\n    xbuf1 = mainp->xbuffer[1][ci];\n    /* First copy the workspace pointers as-is */\n    buf = mainp->buffer[ci];\n    for (i = 0; i < rgroup * (M + 2); i++) {\n      xbuf0[i] = xbuf1[i] = buf[i];\n    }\n    /* In the second list, put the last four row groups in swapped order */\n    for (i = 0; i < rgroup * 2; i++) {\n      xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];\n      xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];\n    }\n    /* The wraparound pointers at top and bottom will be filled later\n     * (see set_wraparound_pointers, below).  Initially we want the \"above\"\n     * pointers to duplicate the first actual data line.  This only needs\n     * to happen in xbuffer[0].\n     */\n    for (i = 0; i < rgroup; i++) {\n      xbuf0[i - rgroup] = xbuf0[0];\n    }\n  }\n}\n\n\nLOCAL(void)\nset_wraparound_pointers (j_decompress_ptr cinfo)\n/* Set up the \"wraparound\" pointers at top and bottom of the pointer lists.\n * This changes the pointer list state from top-of-image to the normal state.\n */\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  int ci, i, rgroup;\n  int M = cinfo->min_DCT_v_scaled_size;\n  jpeg_component_info *compptr;\n  JSAMPARRAY xbuf0, xbuf1;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n      cinfo->min_DCT_v_scaled_size; /* height of a row group of component */\n    xbuf0 = mainp->xbuffer[0][ci];\n    xbuf1 = mainp->xbuffer[1][ci];\n    for (i = 0; i < rgroup; i++) {\n      xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];\n      xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];\n      xbuf0[rgroup*(M+2) + i] = xbuf0[i];\n      xbuf1[rgroup*(M+2) + i] = xbuf1[i];\n    }\n  }\n}\n\n\nLOCAL(void)\nset_bottom_pointers (j_decompress_ptr cinfo)\n/* Change the pointer lists to duplicate the last sample row at the bottom\n * of the image.  whichptr indicates which xbuffer holds the final iMCU row.\n * Also sets rowgroups_avail to indicate number of nondummy row groups in row.\n */\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  int ci, i, rgroup, iMCUheight, rows_left;\n  jpeg_component_info *compptr;\n  JSAMPARRAY xbuf;\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Count sample rows in one iMCU row and in one row group */\n    iMCUheight = compptr->v_samp_factor * compptr->DCT_v_scaled_size;\n    rgroup = iMCUheight / cinfo->min_DCT_v_scaled_size;\n    /* Count nondummy sample rows remaining for this component */\n    rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);\n    if (rows_left == 0) rows_left = iMCUheight;\n    /* Count nondummy row groups.  Should get same answer for each component,\n     * so we need only do it once.\n     */\n    if (ci == 0) {\n      mainp->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);\n    }\n    /* Duplicate the last real sample row rgroup*2 times; this pads out the\n     * last partial rowgroup and ensures at least one full rowgroup of context.\n     */\n    xbuf = mainp->xbuffer[mainp->whichptr][ci];\n    for (i = 0; i < rgroup * 2; i++) {\n      xbuf[rows_left + i] = xbuf[rows_left-1];\n    }\n  }\n}\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_main (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n\n  switch (pass_mode) {\n  case JBUF_PASS_THRU:\n    if (cinfo->upsample->need_context_rows) {\n      mainp->pub.process_data = process_data_context_main;\n      make_funny_pointers(cinfo); /* Create the xbuffer[] lists */\n      mainp->whichptr = 0;\t/* Read first iMCU row into xbuffer[0] */\n      mainp->context_state = CTX_PREPARE_FOR_IMCU;\n      mainp->iMCU_row_ctr = 0;\n    } else {\n      /* Simple case with no context needed */\n      mainp->pub.process_data = process_data_simple_main;\n    }\n    mainp->buffer_full = FALSE;\t/* Mark buffer empty */\n    mainp->rowgroup_ctr = 0;\n    break;\n#ifdef QUANT_2PASS_SUPPORTED\n  case JBUF_CRANK_DEST:\n    /* For last pass of 2-pass quantization, just crank the postprocessor */\n    mainp->pub.process_data = process_data_crank_post;\n    break;\n#endif\n  default:\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    break;\n  }\n}\n\n\n/*\n * Process some data.\n * This handles the simple case where no context is required.\n */\n\nMETHODDEF(void)\nprocess_data_simple_main (j_decompress_ptr cinfo,\n\t\t\t  JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t\t  JDIMENSION out_rows_avail)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n  JDIMENSION rowgroups_avail;\n\n  /* Read input data if we haven't filled the main buffer yet */\n  if (! mainp->buffer_full) {\n    if (! (*cinfo->coef->decompress_data) (cinfo, mainp->buffer))\n      return;\t\t\t/* suspension forced, can do nothing more */\n    mainp->buffer_full = TRUE;\t/* OK, we have an iMCU row to work with */\n  }\n\n  /* There are always min_DCT_scaled_size row groups in an iMCU row. */\n  rowgroups_avail = (JDIMENSION) cinfo->min_DCT_v_scaled_size;\n  /* Note: at the bottom of the image, we may pass extra garbage row groups\n   * to the postprocessor.  The postprocessor has to check for bottom\n   * of image anyway (at row resolution), so no point in us doing it too.\n   */\n\n  /* Feed the postprocessor */\n  (*cinfo->post->post_process_data) (cinfo, mainp->buffer,\n\t\t\t\t     &mainp->rowgroup_ctr, rowgroups_avail,\n\t\t\t\t     output_buf, out_row_ctr, out_rows_avail);\n\n  /* Has postprocessor consumed all the data yet? If so, mark buffer empty */\n  if (mainp->rowgroup_ctr >= rowgroups_avail) {\n    mainp->buffer_full = FALSE;\n    mainp->rowgroup_ctr = 0;\n  }\n}\n\n\n/*\n * Process some data.\n * This handles the case where context rows must be provided.\n */\n\nMETHODDEF(void)\nprocess_data_context_main (j_decompress_ptr cinfo,\n\t\t\t   JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t\t   JDIMENSION out_rows_avail)\n{\n  my_main_ptr mainp = (my_main_ptr) cinfo->main;\n\n  /* Read input data if we haven't filled the main buffer yet */\n  if (! mainp->buffer_full) {\n    if (! (*cinfo->coef->decompress_data) (cinfo,\n\t\t\t\t\t   mainp->xbuffer[mainp->whichptr]))\n      return;\t\t\t/* suspension forced, can do nothing more */\n    mainp->buffer_full = TRUE;\t/* OK, we have an iMCU row to work with */\n    mainp->iMCU_row_ctr++;\t/* count rows received */\n  }\n\n  /* Postprocessor typically will not swallow all the input data it is handed\n   * in one call (due to filling the output buffer first).  Must be prepared\n   * to exit and restart.  This switch lets us keep track of how far we got.\n   * Note that each case falls through to the next on successful completion.\n   */\n  switch (mainp->context_state) {\n  case CTX_POSTPONED_ROW:\n    /* Call postprocessor using previously set pointers for postponed row */\n    (*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],\n\t\t\t&mainp->rowgroup_ctr, mainp->rowgroups_avail,\n\t\t\toutput_buf, out_row_ctr, out_rows_avail);\n    if (mainp->rowgroup_ctr < mainp->rowgroups_avail)\n      return;\t\t\t/* Need to suspend */\n    mainp->context_state = CTX_PREPARE_FOR_IMCU;\n    if (*out_row_ctr >= out_rows_avail)\n      return;\t\t\t/* Postprocessor exactly filled output buf */\n    /*FALLTHROUGH*/\n  case CTX_PREPARE_FOR_IMCU:\n    /* Prepare to process first M-1 row groups of this iMCU row */\n    mainp->rowgroup_ctr = 0;\n    mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size - 1);\n    /* Check for bottom of image: if so, tweak pointers to \"duplicate\"\n     * the last sample row, and adjust rowgroups_avail to ignore padding rows.\n     */\n    if (mainp->iMCU_row_ctr == cinfo->total_iMCU_rows)\n      set_bottom_pointers(cinfo);\n    mainp->context_state = CTX_PROCESS_IMCU;\n    /*FALLTHROUGH*/\n  case CTX_PROCESS_IMCU:\n    /* Call postprocessor using previously set pointers */\n    (*cinfo->post->post_process_data) (cinfo, mainp->xbuffer[mainp->whichptr],\n\t\t\t&mainp->rowgroup_ctr, mainp->rowgroups_avail,\n\t\t\toutput_buf, out_row_ctr, out_rows_avail);\n    if (mainp->rowgroup_ctr < mainp->rowgroups_avail)\n      return;\t\t\t/* Need to suspend */\n    /* After the first iMCU, change wraparound pointers to normal state */\n    if (mainp->iMCU_row_ctr == 1)\n      set_wraparound_pointers(cinfo);\n    /* Prepare to load new iMCU row using other xbuffer list */\n    mainp->whichptr ^= 1;\t/* 0=>1 or 1=>0 */\n    mainp->buffer_full = FALSE;\n    /* Still need to process last row group of this iMCU row, */\n    /* which is saved at index M+1 of the other xbuffer */\n    mainp->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 1);\n    mainp->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_v_scaled_size + 2);\n    mainp->context_state = CTX_POSTPONED_ROW;\n  }\n}\n\n\n/*\n * Process some data.\n * Final pass of two-pass quantization: just call the postprocessor.\n * Source data will be the postprocessor controller's internal buffer.\n */\n\n#ifdef QUANT_2PASS_SUPPORTED\n\nMETHODDEF(void)\nprocess_data_crank_post (j_decompress_ptr cinfo,\n\t\t\t JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t\t JDIMENSION out_rows_avail)\n{\n  (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,\n\t\t\t\t     (JDIMENSION *) NULL, (JDIMENSION) 0,\n\t\t\t\t     output_buf, out_row_ctr, out_rows_avail);\n}\n\n#endif /* QUANT_2PASS_SUPPORTED */\n\n\n/*\n * Initialize main buffer controller.\n */\n\nGLOBAL(void)\njinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)\n{\n  my_main_ptr mainp;\n  int ci, rgroup, ngroups;\n  jpeg_component_info *compptr;\n\n  mainp = (my_main_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_main_controller));\n  cinfo->main = &mainp->pub;\n  mainp->pub.start_pass = start_pass_main;\n\n  if (need_full_buffer)\t\t/* shouldn't happen */\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n\n  /* Allocate the workspace.\n   * ngroups is the number of row groups we need.\n   */\n  if (cinfo->upsample->need_context_rows) {\n    if (cinfo->min_DCT_v_scaled_size < 2) /* unsupported, see comments above */\n      ERREXIT(cinfo, JERR_NOTIMPL);\n    alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */\n    ngroups = cinfo->min_DCT_v_scaled_size + 2;\n  } else {\n    ngroups = cinfo->min_DCT_v_scaled_size;\n  }\n\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    rgroup = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n      cinfo->min_DCT_v_scaled_size; /* height of a row group of component */\n    mainp->buffer[ci] = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       compptr->width_in_blocks * ((JDIMENSION) compptr->DCT_h_scaled_size),\n       (JDIMENSION) (rgroup * ngroups));\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdmarker.c",
    "content": "/*\n * jdmarker.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2009-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to decode JPEG datastream markers.\n * Most of the complexity arises from our desire to support input\n * suspension: if not all of the data for a marker is available,\n * we must exit back to the application.  On resumption, we reprocess\n * the marker.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\ntypedef enum {\t\t\t/* JPEG marker codes */\n  M_SOF0  = 0xc0,\n  M_SOF1  = 0xc1,\n  M_SOF2  = 0xc2,\n  M_SOF3  = 0xc3,\n\n  M_SOF5  = 0xc5,\n  M_SOF6  = 0xc6,\n  M_SOF7  = 0xc7,\n\n  M_JPG   = 0xc8,\n  M_SOF9  = 0xc9,\n  M_SOF10 = 0xca,\n  M_SOF11 = 0xcb,\n\n  M_SOF13 = 0xcd,\n  M_SOF14 = 0xce,\n  M_SOF15 = 0xcf,\n\n  M_DHT   = 0xc4,\n\n  M_DAC   = 0xcc,\n\n  M_RST0  = 0xd0,\n  M_RST1  = 0xd1,\n  M_RST2  = 0xd2,\n  M_RST3  = 0xd3,\n  M_RST4  = 0xd4,\n  M_RST5  = 0xd5,\n  M_RST6  = 0xd6,\n  M_RST7  = 0xd7,\n\n  M_SOI   = 0xd8,\n  M_EOI   = 0xd9,\n  M_SOS   = 0xda,\n  M_DQT   = 0xdb,\n  M_DNL   = 0xdc,\n  M_DRI   = 0xdd,\n  M_DHP   = 0xde,\n  M_EXP   = 0xdf,\n\n  M_APP0  = 0xe0,\n  M_APP1  = 0xe1,\n  M_APP2  = 0xe2,\n  M_APP3  = 0xe3,\n  M_APP4  = 0xe4,\n  M_APP5  = 0xe5,\n  M_APP6  = 0xe6,\n  M_APP7  = 0xe7,\n  M_APP8  = 0xe8,\n  M_APP9  = 0xe9,\n  M_APP10 = 0xea,\n  M_APP11 = 0xeb,\n  M_APP12 = 0xec,\n  M_APP13 = 0xed,\n  M_APP14 = 0xee,\n  M_APP15 = 0xef,\n\n  M_JPG0  = 0xf0,\n  M_JPG8  = 0xf8,\n  M_JPG13 = 0xfd,\n  M_COM   = 0xfe,\n\n  M_TEM   = 0x01,\n\n  M_ERROR = 0x100\n} JPEG_MARKER;\n\n\n/* Private state */\n\ntypedef struct {\n  struct jpeg_marker_reader pub; /* public fields */\n\n  /* Application-overridable marker processing methods */\n  jpeg_marker_parser_method process_COM;\n  jpeg_marker_parser_method process_APPn[16];\n\n  /* Limit on marker data length to save for each marker type */\n  unsigned int length_limit_COM;\n  unsigned int length_limit_APPn[16];\n\n  /* Status of COM/APPn marker saving */\n  jpeg_saved_marker_ptr cur_marker;\t/* NULL if not processing a marker */\n  unsigned int bytes_read;\t\t/* data bytes read so far in marker */\n  /* Note: cur_marker is not linked into marker_list until it's all read. */\n} my_marker_reader;\n\ntypedef my_marker_reader * my_marker_ptr;\n\n\n/*\n * Macros for fetching data from the data source module.\n *\n * At all times, cinfo->src->next_input_byte and ->bytes_in_buffer reflect\n * the current restart point; we update them only when we have reached a\n * suitable place to restart if a suspension occurs.\n */\n\n/* Declare and initialize local copies of input pointer/count */\n#define INPUT_VARS(cinfo)  \\\n\tstruct jpeg_source_mgr * datasrc = (cinfo)->src;  \\\n\tconst JOCTET * next_input_byte = datasrc->next_input_byte;  \\\n\tsize_t bytes_in_buffer = datasrc->bytes_in_buffer\n\n/* Unload the local copies --- do this only at a restart boundary */\n#define INPUT_SYNC(cinfo)  \\\n\t( datasrc->next_input_byte = next_input_byte,  \\\n\t  datasrc->bytes_in_buffer = bytes_in_buffer )\n\n/* Reload the local copies --- used only in MAKE_BYTE_AVAIL */\n#define INPUT_RELOAD(cinfo)  \\\n\t( next_input_byte = datasrc->next_input_byte,  \\\n\t  bytes_in_buffer = datasrc->bytes_in_buffer )\n\n/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available.\n * Note we do *not* do INPUT_SYNC before calling fill_input_buffer,\n * but we must reload the local copies after a successful fill.\n */\n#define MAKE_BYTE_AVAIL(cinfo,action)  \\\n\tif (bytes_in_buffer == 0) {  \\\n\t  if (! (*datasrc->fill_input_buffer) (cinfo))  \\\n\t    { action; }  \\\n\t  INPUT_RELOAD(cinfo);  \\\n\t}\n\n/* Read a byte into variable V.\n * If must suspend, take the specified action (typically \"return FALSE\").\n */\n#define INPUT_BYTE(cinfo,V,action)  \\\n\tMAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \\\n\t\t  bytes_in_buffer--; \\\n\t\t  V = GETJOCTET(*next_input_byte++); )\n\n/* As above, but read two bytes interpreted as an unsigned 16-bit integer.\n * V should be declared unsigned int or perhaps INT32.\n */\n#define INPUT_2BYTES(cinfo,V,action)  \\\n\tMAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \\\n\t\t  bytes_in_buffer--; \\\n\t\t  V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \\\n\t\t  MAKE_BYTE_AVAIL(cinfo,action); \\\n\t\t  bytes_in_buffer--; \\\n\t\t  V += GETJOCTET(*next_input_byte++); )\n\n\n/*\n * Routines to process JPEG markers.\n *\n * Entry condition: JPEG marker itself has been read and its code saved\n *   in cinfo->unread_marker; input restart point is just after the marker.\n *\n * Exit: if return TRUE, have read and processed any parameters, and have\n *   updated the restart point to point after the parameters.\n *   If return FALSE, was forced to suspend before reaching end of\n *   marker parameters; restart point has not been moved.  Same routine\n *   will be called again after application supplies more input data.\n *\n * This approach to suspension assumes that all of a marker's parameters\n * can fit into a single input bufferload.  This should hold for \"normal\"\n * markers.  Some COM/APPn markers might have large parameter segments\n * that might not fit.  If we are simply dropping such a marker, we use\n * skip_input_data to get past it, and thereby put the problem on the\n * source manager's shoulders.  If we are saving the marker's contents\n * into memory, we use a slightly different convention: when forced to\n * suspend, the marker processor updates the restart point to the end of\n * what it's consumed (ie, the end of the buffer) before returning FALSE.\n * On resumption, cinfo->unread_marker still contains the marker code,\n * but the data source will point to the next chunk of marker data.\n * The marker processor must retain internal state to deal with this.\n *\n * Note that we don't bother to avoid duplicate trace messages if a\n * suspension occurs within marker parameters.  Other side effects\n * require more care.\n */\n\n\nLOCAL(boolean)\nget_soi (j_decompress_ptr cinfo)\n/* Process an SOI marker */\n{\n  int i;\n  \n  TRACEMS(cinfo, 1, JTRC_SOI);\n\n  if (cinfo->marker->saw_SOI)\n    ERREXIT(cinfo, JERR_SOI_DUPLICATE);\n\n  /* Reset all parameters that are defined to be reset by SOI */\n\n  for (i = 0; i < NUM_ARITH_TBLS; i++) {\n    cinfo->arith_dc_L[i] = 0;\n    cinfo->arith_dc_U[i] = 1;\n    cinfo->arith_ac_K[i] = 5;\n  }\n  cinfo->restart_interval = 0;\n\n  /* Set initial assumptions for colorspace etc */\n\n  cinfo->jpeg_color_space = JCS_UNKNOWN;\n  cinfo->color_transform = JCT_NONE;\n  cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */\n\n  cinfo->saw_JFIF_marker = FALSE;\n  cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */\n  cinfo->JFIF_minor_version = 1;\n  cinfo->density_unit = 0;\n  cinfo->X_density = 1;\n  cinfo->Y_density = 1;\n  cinfo->saw_Adobe_marker = FALSE;\n  cinfo->Adobe_transform = 0;\n\n  cinfo->marker->saw_SOI = TRUE;\n\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nget_sof (j_decompress_ptr cinfo, boolean is_baseline, boolean is_prog,\n\t boolean is_arith)\n/* Process a SOFn marker */\n{\n  INT32 length;\n  int c, ci, i;\n  jpeg_component_info * compptr;\n  INPUT_VARS(cinfo);\n\n  cinfo->is_baseline = is_baseline;\n  cinfo->progressive_mode = is_prog;\n  cinfo->arith_code = is_arith;\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n\n  INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);\n  INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);\n  INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);\n  INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);\n\n  length -= 8;\n\n  TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,\n\t   (int) cinfo->image_width, (int) cinfo->image_height,\n\t   cinfo->num_components);\n\n  if (cinfo->marker->saw_SOF)\n    ERREXIT(cinfo, JERR_SOF_DUPLICATE);\n\n  /* We don't support files in which the image height is initially specified */\n  /* as 0 and is later redefined by DNL.  As long as we have to check that,  */\n  /* might as well have a general sanity check. */\n  if (cinfo->image_height <= 0 || cinfo->image_width <= 0 ||\n      cinfo->num_components <= 0)\n    ERREXIT(cinfo, JERR_EMPTY_IMAGE);\n\n  if (length != (cinfo->num_components * 3))\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  if (cinfo->comp_info == NULL)\t/* do only once, even if suspend */\n    cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)\n\t\t\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t cinfo->num_components * SIZEOF(jpeg_component_info));\n\n  for (ci = 0; ci < cinfo->num_components; ci++) {\n    INPUT_BYTE(cinfo, c, return FALSE);\n    /* Check to see whether component id has already been seen   */\n    /* (in violation of the spec, but unfortunately seen in some */\n    /* files).  If so, create \"fake\" component id equal to the   */\n    /* max id seen so far + 1. */\n    for (i = 0, compptr = cinfo->comp_info; i < ci; i++, compptr++) {\n      if (c == compptr->component_id) {\n\tcompptr = cinfo->comp_info;\n\tc = compptr->component_id;\n\tcompptr++;\n\tfor (i = 1; i < ci; i++, compptr++) {\n\t  if (compptr->component_id > c) c = compptr->component_id;\n\t}\n\tc++;\n\tbreak;\n      }\n    }\n    compptr->component_id = c;\n    compptr->component_index = ci;\n    INPUT_BYTE(cinfo, c, return FALSE);\n    compptr->h_samp_factor = (c >> 4) & 15;\n    compptr->v_samp_factor = (c     ) & 15;\n    INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);\n\n    TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,\n\t     compptr->component_id, compptr->h_samp_factor,\n\t     compptr->v_samp_factor, compptr->quant_tbl_no);\n  }\n\n  cinfo->marker->saw_SOF = TRUE;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nget_sos (j_decompress_ptr cinfo)\n/* Process a SOS marker */\n{\n  INT32 length;\n  int c, ci, i, n;\n  jpeg_component_info * compptr;\n  INPUT_VARS(cinfo);\n\n  if (! cinfo->marker->saw_SOF)\n    ERREXITS(cinfo, JERR_SOF_BEFORE, \"SOS\");\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n\n  INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */\n\n  TRACEMS1(cinfo, 1, JTRC_SOS, n);\n\n  if (length != (n * 2 + 6) || n > MAX_COMPS_IN_SCAN ||\n      (n == 0 && !cinfo->progressive_mode))\n      /* pseudo SOS marker only allowed in progressive mode */\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  cinfo->comps_in_scan = n;\n\n  /* Collect the component-spec parameters */\n\n  for (i = 0; i < n; i++) {\n    INPUT_BYTE(cinfo, c, return FALSE);\n\n    /* Detect the case where component id's are not unique, and, if so, */\n    /* create a fake component id using the same logic as in get_sof.   */\n    /* Note:  This also ensures that all of the SOF components are      */\n    /* referenced in the single scan case, which prevents access to     */\n    /* uninitialized memory in later decoding stages. */\n    for (ci = 0; ci < i; ci++) {\n      if (c == cinfo->cur_comp_info[ci]->component_id) {\n\tc = cinfo->cur_comp_info[0]->component_id;\n\tfor (ci = 1; ci < i; ci++) {\n\t  compptr = cinfo->cur_comp_info[ci];\n\t  if (compptr->component_id > c) c = compptr->component_id;\n\t}\n\tc++;\n\tbreak;\n      }\n    }\n\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      if (c == compptr->component_id)\n\tgoto id_found;\n    }\n\n    ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, c);\n\n  id_found:\n\n    cinfo->cur_comp_info[i] = compptr;\n    INPUT_BYTE(cinfo, c, return FALSE);\n    compptr->dc_tbl_no = (c >> 4) & 15;\n    compptr->ac_tbl_no = (c     ) & 15;\n\n    TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, compptr->component_id,\n\t     compptr->dc_tbl_no, compptr->ac_tbl_no);\n  }\n\n  /* Collect the additional scan parameters Ss, Se, Ah/Al. */\n  INPUT_BYTE(cinfo, c, return FALSE);\n  cinfo->Ss = c;\n  INPUT_BYTE(cinfo, c, return FALSE);\n  cinfo->Se = c;\n  INPUT_BYTE(cinfo, c, return FALSE);\n  cinfo->Ah = (c >> 4) & 15;\n  cinfo->Al = (c     ) & 15;\n\n  TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,\n\t   cinfo->Ah, cinfo->Al);\n\n  /* Prepare to scan data & restart markers */\n  cinfo->marker->next_restart_num = 0;\n\n  /* Count another (non-pseudo) SOS marker */\n  if (n) cinfo->input_scan_number++;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\n#ifdef D_ARITH_CODING_SUPPORTED\n\nLOCAL(boolean)\nget_dac (j_decompress_ptr cinfo)\n/* Process a DAC marker */\n{\n  INT32 length;\n  int index, val;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  length -= 2;\n  \n  while (length > 0) {\n    INPUT_BYTE(cinfo, index, return FALSE);\n    INPUT_BYTE(cinfo, val, return FALSE);\n\n    length -= 2;\n\n    TRACEMS2(cinfo, 1, JTRC_DAC, index, val);\n\n    if (index < 0 || index >= (2*NUM_ARITH_TBLS))\n      ERREXIT1(cinfo, JERR_DAC_INDEX, index);\n\n    if (index >= NUM_ARITH_TBLS) { /* define AC table */\n      cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;\n    } else {\t\t\t/* define DC table */\n      cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);\n      cinfo->arith_dc_U[index] = (UINT8) (val >> 4);\n      if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])\n\tERREXIT1(cinfo, JERR_DAC_VALUE, val);\n    }\n  }\n\n  if (length != 0)\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n#else /* ! D_ARITH_CODING_SUPPORTED */\n\n#define get_dac(cinfo)  skip_variable(cinfo)\n\n#endif /* D_ARITH_CODING_SUPPORTED */\n\n\nLOCAL(boolean)\nget_dht (j_decompress_ptr cinfo)\n/* Process a DHT marker */\n{\n  INT32 length;\n  UINT8 bits[17];\n  UINT8 huffval[256];\n  int i, index, count;\n  JHUFF_TBL **htblptr;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  length -= 2;\n  \n  while (length > 16) {\n    INPUT_BYTE(cinfo, index, return FALSE);\n\n    TRACEMS1(cinfo, 1, JTRC_DHT, index);\n      \n    bits[0] = 0;\n    count = 0;\n    for (i = 1; i <= 16; i++) {\n      INPUT_BYTE(cinfo, bits[i], return FALSE);\n      count += bits[i];\n    }\n\n    length -= 1 + 16;\n\n    TRACEMS8(cinfo, 2, JTRC_HUFFBITS,\n\t     bits[1], bits[2], bits[3], bits[4],\n\t     bits[5], bits[6], bits[7], bits[8]);\n    TRACEMS8(cinfo, 2, JTRC_HUFFBITS,\n\t     bits[9], bits[10], bits[11], bits[12],\n\t     bits[13], bits[14], bits[15], bits[16]);\n\n    /* Here we just do minimal validation of the counts to avoid walking\n     * off the end of our table space.  jdhuff.c will check more carefully.\n     */\n    if (count > 256 || ((INT32) count) > length)\n      ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);\n\n    MEMZERO(huffval, SIZEOF(huffval)); /* pre-zero array for later copy */\n\n    for (i = 0; i < count; i++)\n      INPUT_BYTE(cinfo, huffval[i], return FALSE);\n\n    length -= count;\n\n    if (index & 0x10) {\t\t/* AC table definition */\n      index -= 0x10;\n      htblptr = &cinfo->ac_huff_tbl_ptrs[index];\n    } else {\t\t\t/* DC table definition */\n      htblptr = &cinfo->dc_huff_tbl_ptrs[index];\n    }\n\n    if (index < 0 || index >= NUM_HUFF_TBLS)\n      ERREXIT1(cinfo, JERR_DHT_INDEX, index);\n\n    if (*htblptr == NULL)\n      *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);\n  \n    MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));\n    MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));\n  }\n\n  if (length != 0)\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nget_dqt (j_decompress_ptr cinfo)\n/* Process a DQT marker */\n{\n  INT32 length, count, i;\n  int n, prec;\n  unsigned int tmp;\n  JQUANT_TBL *quant_ptr;\n  const int *natural_order;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  length -= 2;\n\n  while (length > 0) {\n    length--;\n    INPUT_BYTE(cinfo, n, return FALSE);\n    prec = n >> 4;\n    n &= 0x0F;\n\n    TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);\n\n    if (n >= NUM_QUANT_TBLS)\n      ERREXIT1(cinfo, JERR_DQT_INDEX, n);\n      \n    if (cinfo->quant_tbl_ptrs[n] == NULL)\n      cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);\n    quant_ptr = cinfo->quant_tbl_ptrs[n];\n\n    if (prec) {\n      if (length < DCTSIZE2 * 2) {\n\t/* Initialize full table for safety. */\n\tfor (i = 0; i < DCTSIZE2; i++) {\n\t  quant_ptr->quantval[i] = 1;\n\t}\n\tcount = length >> 1;\n      } else\n\tcount = DCTSIZE2;\n    } else {\n      if (length < DCTSIZE2) {\n\t/* Initialize full table for safety. */\n\tfor (i = 0; i < DCTSIZE2; i++) {\n\t  quant_ptr->quantval[i] = 1;\n\t}\n\tcount = length;\n      } else\n\tcount = DCTSIZE2;\n    }\n\n    switch (count) {\n    case (2*2): natural_order = jpeg_natural_order2; break;\n    case (3*3): natural_order = jpeg_natural_order3; break;\n    case (4*4): natural_order = jpeg_natural_order4; break;\n    case (5*5): natural_order = jpeg_natural_order5; break;\n    case (6*6): natural_order = jpeg_natural_order6; break;\n    case (7*7): natural_order = jpeg_natural_order7; break;\n    default:    natural_order = jpeg_natural_order;  break;\n    }\n\n    for (i = 0; i < count; i++) {\n      if (prec)\n\tINPUT_2BYTES(cinfo, tmp, return FALSE);\n      else\n\tINPUT_BYTE(cinfo, tmp, return FALSE);\n      /* We convert the zigzag-order table to natural array order. */\n      quant_ptr->quantval[natural_order[i]] = (UINT16) tmp;\n    }\n\n    if (cinfo->err->trace_level >= 2) {\n      for (i = 0; i < DCTSIZE2; i += 8) {\n\tTRACEMS8(cinfo, 2, JTRC_QUANTVALS,\n\t\t quant_ptr->quantval[i],   quant_ptr->quantval[i+1],\n\t\t quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],\n\t\t quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],\n\t\t quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);\n      }\n    }\n\n    length -= count;\n    if (prec) length -= count;\n  }\n\n  if (length != 0)\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nget_dri (j_decompress_ptr cinfo)\n/* Process a DRI marker */\n{\n  INT32 length;\n  unsigned int tmp;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  \n  if (length != 4)\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n\n  TRACEMS1(cinfo, 1, JTRC_DRI, tmp);\n\n  cinfo->restart_interval = tmp;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nget_lse (j_decompress_ptr cinfo)\n/* Process an LSE marker */\n{\n  INT32 length;\n  unsigned int tmp;\n  int cid;\n  INPUT_VARS(cinfo);\n\n  if (! cinfo->marker->saw_SOF)\n    ERREXITS(cinfo, JERR_SOF_BEFORE, \"LSE\");\n\n  if (cinfo->num_components < 3) goto bad;\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n\n  if (length != 24)\n    ERREXIT(cinfo, JERR_BAD_LENGTH);\n\n  INPUT_BYTE(cinfo, tmp, return FALSE);\n  if (tmp != 0x0D)\t/* ID inverse transform specification */\n    ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != MAXJSAMPLE) goto bad;\t\t/* MAXTRANS */\n  INPUT_BYTE(cinfo, tmp, return FALSE);\n  if (tmp != 3) goto bad;\t\t\t/* Nt=3 */\n  INPUT_BYTE(cinfo, cid, return FALSE);\n  if (cid != cinfo->comp_info[1].component_id) goto bad;\n  INPUT_BYTE(cinfo, cid, return FALSE);\n  if (cid != cinfo->comp_info[0].component_id) goto bad;\n  INPUT_BYTE(cinfo, cid, return FALSE);\n  if (cid != cinfo->comp_info[2].component_id) goto bad;\n  INPUT_BYTE(cinfo, tmp, return FALSE);\n  if (tmp != 0x80) goto bad;\t\t/* F1: CENTER1=1, NORM1=0 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 0) goto bad;\t\t\t/* A(1,1)=0 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 0) goto bad;\t\t\t/* A(1,2)=0 */\n  INPUT_BYTE(cinfo, tmp, return FALSE);\n  if (tmp != 0) goto bad;\t\t/* F2: CENTER2=0, NORM2=0 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 1) goto bad;\t\t\t/* A(2,1)=1 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 0) goto bad;\t\t\t/* A(2,2)=0 */\n  INPUT_BYTE(cinfo, tmp, return FALSE);\n  if (tmp != 0) goto bad;\t\t/* F3: CENTER3=0, NORM3=0 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 1) goto bad;\t\t\t/* A(3,1)=1 */\n  INPUT_2BYTES(cinfo, tmp, return FALSE);\n  if (tmp != 0) {\t\t\t\t/* A(3,2)=0 */\n    bad:\n    ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);\n  }\n\n  /* OK, valid transform that we can handle. */\n  cinfo->color_transform = JCT_SUBTRACT_GREEN;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\n/*\n * Routines for processing APPn and COM markers.\n * These are either saved in memory or discarded, per application request.\n * APP0 and APP14 are specially checked to see if they are\n * JFIF and Adobe markers, respectively.\n */\n\n#define APP0_DATA_LEN\t14\t/* Length of interesting data in APP0 */\n#define APP14_DATA_LEN\t12\t/* Length of interesting data in APP14 */\n#define APPN_DATA_LEN\t14\t/* Must be the largest of the above!! */\n\n\nLOCAL(void)\nexamine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,\n\t      unsigned int datalen, INT32 remaining)\n/* Examine first few bytes from an APP0.\n * Take appropriate action if it is a JFIF marker.\n * datalen is # of bytes at data[], remaining is length of rest of marker data.\n */\n{\n  INT32 totallen = (INT32) datalen + remaining;\n\n  if (datalen >= APP0_DATA_LEN &&\n      GETJOCTET(data[0]) == 0x4A &&\n      GETJOCTET(data[1]) == 0x46 &&\n      GETJOCTET(data[2]) == 0x49 &&\n      GETJOCTET(data[3]) == 0x46 &&\n      GETJOCTET(data[4]) == 0) {\n    /* Found JFIF APP0 marker: save info */\n    cinfo->saw_JFIF_marker = TRUE;\n    cinfo->JFIF_major_version = GETJOCTET(data[5]);\n    cinfo->JFIF_minor_version = GETJOCTET(data[6]);\n    cinfo->density_unit = GETJOCTET(data[7]);\n    cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);\n    cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);\n    /* Check version.\n     * Major version must be 1 or 2, anything else signals an incompatible\n     * change.\n     * (We used to treat this as an error, but now it's a nonfatal warning,\n     * because some bozo at Hijaak couldn't read the spec.)\n     * Minor version should be 0..2, but process anyway if newer.\n     */\n    if (cinfo->JFIF_major_version != 1 && cinfo->JFIF_major_version != 2)\n      WARNMS2(cinfo, JWRN_JFIF_MAJOR,\n\t      cinfo->JFIF_major_version, cinfo->JFIF_minor_version);\n    /* Generate trace messages */\n    TRACEMS5(cinfo, 1, JTRC_JFIF,\n\t     cinfo->JFIF_major_version, cinfo->JFIF_minor_version,\n\t     cinfo->X_density, cinfo->Y_density, cinfo->density_unit);\n    /* Validate thumbnail dimensions and issue appropriate messages */\n    if (GETJOCTET(data[12]) | GETJOCTET(data[13]))\n      TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,\n\t       GETJOCTET(data[12]), GETJOCTET(data[13]));\n    totallen -= APP0_DATA_LEN;\n    if (totallen !=\n\t((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))\n      TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);\n  } else if (datalen >= 6 &&\n      GETJOCTET(data[0]) == 0x4A &&\n      GETJOCTET(data[1]) == 0x46 &&\n      GETJOCTET(data[2]) == 0x58 &&\n      GETJOCTET(data[3]) == 0x58 &&\n      GETJOCTET(data[4]) == 0) {\n    /* Found JFIF \"JFXX\" extension APP0 marker */\n    /* The library doesn't actually do anything with these,\n     * but we try to produce a helpful trace message.\n     */\n    switch (GETJOCTET(data[5])) {\n    case 0x10:\n      TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);\n      break;\n    case 0x11:\n      TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);\n      break;\n    case 0x13:\n      TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);\n      break;\n    default:\n      TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,\n\t       GETJOCTET(data[5]), (int) totallen);\n      break;\n    }\n  } else {\n    /* Start of APP0 does not match \"JFIF\" or \"JFXX\", or too short */\n    TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);\n  }\n}\n\n\nLOCAL(void)\nexamine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,\n\t       unsigned int datalen, INT32 remaining)\n/* Examine first few bytes from an APP14.\n * Take appropriate action if it is an Adobe marker.\n * datalen is # of bytes at data[], remaining is length of rest of marker data.\n */\n{\n  unsigned int version, flags0, flags1, transform;\n\n  if (datalen >= APP14_DATA_LEN &&\n      GETJOCTET(data[0]) == 0x41 &&\n      GETJOCTET(data[1]) == 0x64 &&\n      GETJOCTET(data[2]) == 0x6F &&\n      GETJOCTET(data[3]) == 0x62 &&\n      GETJOCTET(data[4]) == 0x65) {\n    /* Found Adobe APP14 marker */\n    version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);\n    flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);\n    flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);\n    transform = GETJOCTET(data[11]);\n    TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);\n    cinfo->saw_Adobe_marker = TRUE;\n    cinfo->Adobe_transform = (UINT8) transform;\n  } else {\n    /* Start of APP14 does not match \"Adobe\", or too short */\n    TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));\n  }\n}\n\n\nMETHODDEF(boolean)\nget_interesting_appn (j_decompress_ptr cinfo)\n/* Process an APP0 or APP14 marker without saving it */\n{\n  INT32 length;\n  JOCTET b[APPN_DATA_LEN];\n  unsigned int i, numtoread;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  length -= 2;\n\n  /* get the interesting part of the marker data */\n  if (length >= APPN_DATA_LEN)\n    numtoread = APPN_DATA_LEN;\n  else if (length > 0)\n    numtoread = (unsigned int) length;\n  else\n    numtoread = 0;\n  for (i = 0; i < numtoread; i++)\n    INPUT_BYTE(cinfo, b[i], return FALSE);\n  length -= numtoread;\n\n  /* process it */\n  switch (cinfo->unread_marker) {\n  case M_APP0:\n    examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);\n    break;\n  case M_APP14:\n    examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);\n    break;\n  default:\n    /* can't get here unless jpeg_save_markers chooses wrong processor */\n    ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);\n    break;\n  }\n\n  /* skip any remaining data -- could be lots */\n  INPUT_SYNC(cinfo);\n  if (length > 0)\n    (*cinfo->src->skip_input_data) (cinfo, (long) length);\n\n  return TRUE;\n}\n\n\n#ifdef SAVE_MARKERS_SUPPORTED\n\nMETHODDEF(boolean)\nsave_marker (j_decompress_ptr cinfo)\n/* Save an APPn or COM marker into the marker list */\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n  jpeg_saved_marker_ptr cur_marker = marker->cur_marker;\n  unsigned int bytes_read, data_length;\n  JOCTET FAR * data;\n  INT32 length = 0;\n  INPUT_VARS(cinfo);\n\n  if (cur_marker == NULL) {\n    /* begin reading a marker */\n    INPUT_2BYTES(cinfo, length, return FALSE);\n    length -= 2;\n    if (length >= 0) {\t\t/* watch out for bogus length word */\n      /* figure out how much we want to save */\n      unsigned int limit;\n      if (cinfo->unread_marker == (int) M_COM)\n\tlimit = marker->length_limit_COM;\n      else\n\tlimit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];\n      if ((unsigned int) length < limit)\n\tlimit = (unsigned int) length;\n      /* allocate and initialize the marker item */\n      cur_marker = (jpeg_saved_marker_ptr)\n\t(*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t    SIZEOF(struct jpeg_marker_struct) + limit);\n      cur_marker->next = NULL;\n      cur_marker->marker = (UINT8) cinfo->unread_marker;\n      cur_marker->original_length = (unsigned int) length;\n      cur_marker->data_length = limit;\n      /* data area is just beyond the jpeg_marker_struct */\n      data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);\n      marker->cur_marker = cur_marker;\n      marker->bytes_read = 0;\n      bytes_read = 0;\n      data_length = limit;\n    } else {\n      /* deal with bogus length word */\n      bytes_read = data_length = 0;\n      data = NULL;\n    }\n  } else {\n    /* resume reading a marker */\n    bytes_read = marker->bytes_read;\n    data_length = cur_marker->data_length;\n    data = cur_marker->data + bytes_read;\n  }\n\n  while (bytes_read < data_length) {\n    INPUT_SYNC(cinfo);\t\t/* move the restart point to here */\n    marker->bytes_read = bytes_read;\n    /* If there's not at least one byte in buffer, suspend */\n    MAKE_BYTE_AVAIL(cinfo, return FALSE);\n    /* Copy bytes with reasonable rapidity */\n    while (bytes_read < data_length && bytes_in_buffer > 0) {\n      *data++ = *next_input_byte++;\n      bytes_in_buffer--;\n      bytes_read++;\n    }\n  }\n\n  /* Done reading what we want to read */\n  if (cur_marker != NULL) {\t/* will be NULL if bogus length word */\n    /* Add new marker to end of list */\n    if (cinfo->marker_list == NULL) {\n      cinfo->marker_list = cur_marker;\n    } else {\n      jpeg_saved_marker_ptr prev = cinfo->marker_list;\n      while (prev->next != NULL)\n\tprev = prev->next;\n      prev->next = cur_marker;\n    }\n    /* Reset pointer & calc remaining data length */\n    data = cur_marker->data;\n    length = cur_marker->original_length - data_length;\n  }\n  /* Reset to initial state for next marker */\n  marker->cur_marker = NULL;\n\n  /* Process the marker if interesting; else just make a generic trace msg */\n  switch (cinfo->unread_marker) {\n  case M_APP0:\n    examine_app0(cinfo, data, data_length, length);\n    break;\n  case M_APP14:\n    examine_app14(cinfo, data, data_length, length);\n    break;\n  default:\n    TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,\n\t     (int) (data_length + length));\n    break;\n  }\n\n  /* skip any remaining data -- could be lots */\n  INPUT_SYNC(cinfo);\t\t/* do before skip_input_data */\n  if (length > 0)\n    (*cinfo->src->skip_input_data) (cinfo, (long) length);\n\n  return TRUE;\n}\n\n#endif /* SAVE_MARKERS_SUPPORTED */\n\n\nMETHODDEF(boolean)\nskip_variable (j_decompress_ptr cinfo)\n/* Skip over an unknown or uninteresting variable-length marker */\n{\n  INT32 length;\n  INPUT_VARS(cinfo);\n\n  INPUT_2BYTES(cinfo, length, return FALSE);\n  length -= 2;\n  \n  TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);\n\n  INPUT_SYNC(cinfo);\t\t/* do before skip_input_data */\n  if (length > 0)\n    (*cinfo->src->skip_input_data) (cinfo, (long) length);\n\n  return TRUE;\n}\n\n\n/*\n * Find the next JPEG marker, save it in cinfo->unread_marker.\n * Returns FALSE if had to suspend before reaching a marker;\n * in that case cinfo->unread_marker is unchanged.\n *\n * Note that the result might not be a valid marker code,\n * but it will never be 0 or FF.\n */\n\nLOCAL(boolean)\nnext_marker (j_decompress_ptr cinfo)\n{\n  int c;\n  INPUT_VARS(cinfo);\n\n  for (;;) {\n    INPUT_BYTE(cinfo, c, return FALSE);\n    /* Skip any non-FF bytes.\n     * This may look a bit inefficient, but it will not occur in a valid file.\n     * We sync after each discarded byte so that a suspending data source\n     * can discard the byte from its buffer.\n     */\n    while (c != 0xFF) {\n      cinfo->marker->discarded_bytes++;\n      INPUT_SYNC(cinfo);\n      INPUT_BYTE(cinfo, c, return FALSE);\n    }\n    /* This loop swallows any duplicate FF bytes.  Extra FFs are legal as\n     * pad bytes, so don't count them in discarded_bytes.  We assume there\n     * will not be so many consecutive FF bytes as to overflow a suspending\n     * data source's input buffer.\n     */\n    do {\n      INPUT_BYTE(cinfo, c, return FALSE);\n    } while (c == 0xFF);\n    if (c != 0)\n      break;\t\t\t/* found a valid marker, exit loop */\n    /* Reach here if we found a stuffed-zero data sequence (FF/00).\n     * Discard it and loop back to try again.\n     */\n    cinfo->marker->discarded_bytes += 2;\n    INPUT_SYNC(cinfo);\n  }\n\n  if (cinfo->marker->discarded_bytes != 0) {\n    WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);\n    cinfo->marker->discarded_bytes = 0;\n  }\n\n  cinfo->unread_marker = c;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\nLOCAL(boolean)\nfirst_marker (j_decompress_ptr cinfo)\n/* Like next_marker, but used to obtain the initial SOI marker. */\n/* For this marker, we do not allow preceding garbage or fill; otherwise,\n * we might well scan an entire input file before realizing it ain't JPEG.\n * If an application wants to process non-JFIF files, it must seek to the\n * SOI before calling the JPEG library.\n */\n{\n  int c, c2;\n  INPUT_VARS(cinfo);\n\n  INPUT_BYTE(cinfo, c, return FALSE);\n  INPUT_BYTE(cinfo, c2, return FALSE);\n  if (c != 0xFF || c2 != (int) M_SOI)\n    ERREXIT2(cinfo, JERR_NO_SOI, c, c2);\n\n  cinfo->unread_marker = c2;\n\n  INPUT_SYNC(cinfo);\n  return TRUE;\n}\n\n\n/*\n * Read markers until SOS or EOI.\n *\n * Returns same codes as are defined for jpeg_consume_input:\n * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.\n *\n * Note: This function may return a pseudo SOS marker (with zero\n * component number) for treat by input controller's consume_input.\n * consume_input itself should filter out (skip) the pseudo marker\n * after processing for the caller.\n */\n\nMETHODDEF(int)\nread_markers (j_decompress_ptr cinfo)\n{\n  /* Outer loop repeats once for each marker. */\n  for (;;) {\n    /* Collect the marker proper, unless we already did. */\n    /* NB: first_marker() enforces the requirement that SOI appear first. */\n    if (cinfo->unread_marker == 0) {\n      if (! cinfo->marker->saw_SOI) {\n\tif (! first_marker(cinfo))\n\t  return JPEG_SUSPENDED;\n      } else {\n\tif (! next_marker(cinfo))\n\t  return JPEG_SUSPENDED;\n      }\n    }\n    /* At this point cinfo->unread_marker contains the marker code and the\n     * input point is just past the marker proper, but before any parameters.\n     * A suspension will cause us to return with this state still true.\n     */\n    switch (cinfo->unread_marker) {\n    case M_SOI:\n      if (! get_soi(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_SOF0:\t\t/* Baseline */\n      if (! get_sof(cinfo, TRUE, FALSE, FALSE))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_SOF1:\t\t/* Extended sequential, Huffman */\n      if (! get_sof(cinfo, FALSE, FALSE, FALSE))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_SOF2:\t\t/* Progressive, Huffman */\n      if (! get_sof(cinfo, FALSE, TRUE, FALSE))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_SOF9:\t\t/* Extended sequential, arithmetic */\n      if (! get_sof(cinfo, FALSE, FALSE, TRUE))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_SOF10:\t\t/* Progressive, arithmetic */\n      if (! get_sof(cinfo, FALSE, TRUE, TRUE))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    /* Currently unsupported SOFn types */\n    case M_SOF3:\t\t/* Lossless, Huffman */\n    case M_SOF5:\t\t/* Differential sequential, Huffman */\n    case M_SOF6:\t\t/* Differential progressive, Huffman */\n    case M_SOF7:\t\t/* Differential lossless, Huffman */\n    case M_JPG:\t\t\t/* Reserved for JPEG extensions */\n    case M_SOF11:\t\t/* Lossless, arithmetic */\n    case M_SOF13:\t\t/* Differential sequential, arithmetic */\n    case M_SOF14:\t\t/* Differential progressive, arithmetic */\n    case M_SOF15:\t\t/* Differential lossless, arithmetic */\n      ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);\n      break;\n\n    case M_SOS:\n      if (! get_sos(cinfo))\n\treturn JPEG_SUSPENDED;\n      cinfo->unread_marker = 0;\t/* processed the marker */\n      return JPEG_REACHED_SOS;\n\n    case M_EOI:\n      TRACEMS(cinfo, 1, JTRC_EOI);\n      cinfo->unread_marker = 0;\t/* processed the marker */\n      return JPEG_REACHED_EOI;\n\n    case M_DAC:\n      if (! get_dac(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_DHT:\n      if (! get_dht(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_DQT:\n      if (! get_dqt(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_DRI:\n      if (! get_dri(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_JPG8:\n      if (! get_lse(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_APP0:\n    case M_APP1:\n    case M_APP2:\n    case M_APP3:\n    case M_APP4:\n    case M_APP5:\n    case M_APP6:\n    case M_APP7:\n    case M_APP8:\n    case M_APP9:\n    case M_APP10:\n    case M_APP11:\n    case M_APP12:\n    case M_APP13:\n    case M_APP14:\n    case M_APP15:\n      if (! (*((my_marker_ptr) cinfo->marker)->process_APPn[\n\t\tcinfo->unread_marker - (int) M_APP0]) (cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_COM:\n      if (! (*((my_marker_ptr) cinfo->marker)->process_COM) (cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    case M_RST0:\t\t/* these are all parameterless */\n    case M_RST1:\n    case M_RST2:\n    case M_RST3:\n    case M_RST4:\n    case M_RST5:\n    case M_RST6:\n    case M_RST7:\n    case M_TEM:\n      TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);\n      break;\n\n    case M_DNL:\t\t\t/* Ignore DNL ... perhaps the wrong thing */\n      if (! skip_variable(cinfo))\n\treturn JPEG_SUSPENDED;\n      break;\n\n    default:\t\t\t/* must be DHP, EXP, JPGn, or RESn */\n      /* For now, we treat the reserved markers as fatal errors since they are\n       * likely to be used to signal incompatible JPEG Part 3 extensions.\n       * Once the JPEG 3 version-number marker is well defined, this code\n       * ought to change!\n       */\n      ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);\n      break;\n    }\n    /* Successfully processed marker, so reset state variable */\n    cinfo->unread_marker = 0;\n  } /* end loop */\n}\n\n\n/*\n * Read a restart marker, which is expected to appear next in the datastream;\n * if the marker is not there, take appropriate recovery action.\n * Returns FALSE if suspension is required.\n *\n * This is called by the entropy decoder after it has read an appropriate\n * number of MCUs.  cinfo->unread_marker may be nonzero if the entropy decoder\n * has already read a marker from the data source.  Under normal conditions\n * cinfo->unread_marker will be reset to 0 before returning; if not reset,\n * it holds a marker which the decoder will be unable to read past.\n */\n\nMETHODDEF(boolean)\nread_restart_marker (j_decompress_ptr cinfo)\n{\n  /* Obtain a marker unless we already did. */\n  /* Note that next_marker will complain if it skips any data. */\n  if (cinfo->unread_marker == 0) {\n    if (! next_marker(cinfo))\n      return FALSE;\n  }\n\n  if (cinfo->unread_marker ==\n      ((int) M_RST0 + cinfo->marker->next_restart_num)) {\n    /* Normal case --- swallow the marker and let entropy decoder continue */\n    TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);\n    cinfo->unread_marker = 0;\n  } else {\n    /* Uh-oh, the restart markers have been messed up. */\n    /* Let the data source manager determine how to resync. */\n    if (! (*cinfo->src->resync_to_restart) (cinfo,\n\t\t\t\t\t    cinfo->marker->next_restart_num))\n      return FALSE;\n  }\n\n  /* Update next-restart state */\n  cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;\n\n  return TRUE;\n}\n\n\n/*\n * This is the default resync_to_restart method for data source managers\n * to use if they don't have any better approach.  Some data source managers\n * may be able to back up, or may have additional knowledge about the data\n * which permits a more intelligent recovery strategy; such managers would\n * presumably supply their own resync method.\n *\n * read_restart_marker calls resync_to_restart if it finds a marker other than\n * the restart marker it was expecting.  (This code is *not* used unless\n * a nonzero restart interval has been declared.)  cinfo->unread_marker is\n * the marker code actually found (might be anything, except 0 or FF).\n * The desired restart marker number (0..7) is passed as a parameter.\n * This routine is supposed to apply whatever error recovery strategy seems\n * appropriate in order to position the input stream to the next data segment.\n * Note that cinfo->unread_marker is treated as a marker appearing before\n * the current data-source input point; usually it should be reset to zero\n * before returning.\n * Returns FALSE if suspension is required.\n *\n * This implementation is substantially constrained by wanting to treat the\n * input as a data stream; this means we can't back up.  Therefore, we have\n * only the following actions to work with:\n *   1. Simply discard the marker and let the entropy decoder resume at next\n *      byte of file.\n *   2. Read forward until we find another marker, discarding intervening\n *      data.  (In theory we could look ahead within the current bufferload,\n *      without having to discard data if we don't find the desired marker.\n *      This idea is not implemented here, in part because it makes behavior\n *      dependent on buffer size and chance buffer-boundary positions.)\n *   3. Leave the marker unread (by failing to zero cinfo->unread_marker).\n *      This will cause the entropy decoder to process an empty data segment,\n *      inserting dummy zeroes, and then we will reprocess the marker.\n *\n * #2 is appropriate if we think the desired marker lies ahead, while #3 is\n * appropriate if the found marker is a future restart marker (indicating\n * that we have missed the desired restart marker, probably because it got\n * corrupted).\n * We apply #2 or #3 if the found marker is a restart marker no more than\n * two counts behind or ahead of the expected one.  We also apply #2 if the\n * found marker is not a legal JPEG marker code (it's certainly bogus data).\n * If the found marker is a restart marker more than 2 counts away, we do #1\n * (too much risk that the marker is erroneous; with luck we will be able to\n * resync at some future point).\n * For any valid non-restart JPEG marker, we apply #3.  This keeps us from\n * overrunning the end of a scan.  An implementation limited to single-scan\n * files might find it better to apply #2 for markers other than EOI, since\n * any other marker would have to be bogus data in that case.\n */\n\nGLOBAL(boolean)\njpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)\n{\n  int marker = cinfo->unread_marker;\n  int action = 1;\n  \n  /* Always put up a warning. */\n  WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);\n  \n  /* Outer loop handles repeated decision after scanning forward. */\n  for (;;) {\n    if (marker < (int) M_SOF0)\n      action = 2;\t\t/* invalid marker */\n    else if (marker < (int) M_RST0 || marker > (int) M_RST7)\n      action = 3;\t\t/* valid non-restart marker */\n    else {\n      if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||\n\t  marker == ((int) M_RST0 + ((desired+2) & 7)))\n\taction = 3;\t\t/* one of the next two expected restarts */\n      else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||\n\t       marker == ((int) M_RST0 + ((desired-2) & 7)))\n\taction = 2;\t\t/* a prior restart, so advance */\n      else\n\taction = 1;\t\t/* desired restart or too far away */\n    }\n    TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);\n    switch (action) {\n    case 1:\n      /* Discard marker and let entropy decoder resume processing. */\n      cinfo->unread_marker = 0;\n      return TRUE;\n    case 2:\n      /* Scan to the next marker, and repeat the decision loop. */\n      if (! next_marker(cinfo))\n\treturn FALSE;\n      marker = cinfo->unread_marker;\n      break;\n    case 3:\n      /* Return without advancing past this marker. */\n      /* Entropy decoder will be forced to process an empty segment. */\n      return TRUE;\n    }\n  } /* end loop */\n}\n\n\n/*\n * Reset marker processing state to begin a fresh datastream.\n */\n\nMETHODDEF(void)\nreset_marker_reader (j_decompress_ptr cinfo)\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n\n  cinfo->comp_info = NULL;\t\t/* until allocated by get_sof */\n  cinfo->input_scan_number = 0;\t\t/* no SOS seen yet */\n  cinfo->unread_marker = 0;\t\t/* no pending marker */\n  marker->pub.saw_SOI = FALSE;\t\t/* set internal state too */\n  marker->pub.saw_SOF = FALSE;\n  marker->pub.discarded_bytes = 0;\n  marker->cur_marker = NULL;\n}\n\n\n/*\n * Initialize the marker reader module.\n * This is called only once, when the decompression object is created.\n */\n\nGLOBAL(void)\njinit_marker_reader (j_decompress_ptr cinfo)\n{\n  my_marker_ptr marker;\n  int i;\n\n  /* Create subobject in permanent pool */\n  marker = (my_marker_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,\n\t\t\t\tSIZEOF(my_marker_reader));\n  cinfo->marker = &marker->pub;\n  /* Initialize public method pointers */\n  marker->pub.reset_marker_reader = reset_marker_reader;\n  marker->pub.read_markers = read_markers;\n  marker->pub.read_restart_marker = read_restart_marker;\n  /* Initialize COM/APPn processing.\n   * By default, we examine and then discard APP0 and APP14,\n   * but simply discard COM and all other APPn.\n   */\n  marker->process_COM = skip_variable;\n  marker->length_limit_COM = 0;\n  for (i = 0; i < 16; i++) {\n    marker->process_APPn[i] = skip_variable;\n    marker->length_limit_APPn[i] = 0;\n  }\n  marker->process_APPn[0] = get_interesting_appn;\n  marker->process_APPn[14] = get_interesting_appn;\n  /* Reset marker processing state */\n  reset_marker_reader(cinfo);\n}\n\n\n/*\n * Control saving of COM and APPn markers into marker_list.\n */\n\n#ifdef SAVE_MARKERS_SUPPORTED\n\nGLOBAL(void)\njpeg_save_markers (j_decompress_ptr cinfo, int marker_code,\n\t\t   unsigned int length_limit)\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n  long maxlength;\n  jpeg_marker_parser_method processor;\n\n  /* Length limit mustn't be larger than what we can allocate\n   * (should only be a concern in a 16-bit environment).\n   */\n  maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);\n  if (((long) length_limit) > maxlength)\n    length_limit = (unsigned int) maxlength;\n\n  /* Choose processor routine to use.\n   * APP0/APP14 have special requirements.\n   */\n  if (length_limit) {\n    processor = save_marker;\n    /* If saving APP0/APP14, save at least enough for our internal use. */\n    if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)\n      length_limit = APP0_DATA_LEN;\n    else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)\n      length_limit = APP14_DATA_LEN;\n  } else {\n    processor = skip_variable;\n    /* If discarding APP0/APP14, use our regular on-the-fly processor. */\n    if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)\n      processor = get_interesting_appn;\n  }\n\n  if (marker_code == (int) M_COM) {\n    marker->process_COM = processor;\n    marker->length_limit_COM = length_limit;\n  } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {\n    marker->process_APPn[marker_code - (int) M_APP0] = processor;\n    marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;\n  } else\n    ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);\n}\n\n#endif /* SAVE_MARKERS_SUPPORTED */\n\n\n/*\n * Install a special processing method for COM or APPn markers.\n */\n\nGLOBAL(void)\njpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,\n\t\t\t   jpeg_marker_parser_method routine)\n{\n  my_marker_ptr marker = (my_marker_ptr) cinfo->marker;\n\n  if (marker_code == (int) M_COM)\n    marker->process_COM = routine;\n  else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)\n    marker->process_APPn[marker_code - (int) M_APP0] = routine;\n  else\n    ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdmaster.c",
    "content": "/*\n * jdmaster.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2002-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains master control logic for the JPEG decompressor.\n * These routines are concerned with selecting the modules to be executed\n * and with determining the number of passes and the work to be done in each\n * pass.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private state */\n\ntypedef struct {\n  struct jpeg_decomp_master pub; /* public fields */\n\n  int pass_number;\t\t/* # of passes completed */\n\n  boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */\n\n  /* Saved references to initialized quantizer modules,\n   * in case we need to switch modes.\n   */\n  struct jpeg_color_quantizer * quantizer_1pass;\n  struct jpeg_color_quantizer * quantizer_2pass;\n} my_decomp_master;\n\ntypedef my_decomp_master * my_master_ptr;\n\n\n/*\n * Determine whether merged upsample/color conversion should be used.\n * CRUCIAL: this must match the actual capabilities of jdmerge.c!\n */\n\nLOCAL(boolean)\nuse_merged_upsample (j_decompress_ptr cinfo)\n{\n#ifdef UPSAMPLE_MERGING_SUPPORTED\n  /* Merging is the equivalent of plain box-filter upsampling. */\n  /* The following condition is only needed if fancy shall select\n   * a different upsampling method.  In our current implementation\n   * fancy only affects the DCT scaling, thus we can use fancy\n   * upsampling and merged upsample simultaneously, in particular\n   * with scaled DCT sizes larger than the default DCTSIZE.\n   */\n#if 0\n  if (cinfo->do_fancy_upsampling)\n    return FALSE;\n#endif\n  if (cinfo->CCIR601_sampling)\n    return FALSE;\n  /* jdmerge.c only supports YCC=>RGB color conversion */\n  if ((cinfo->jpeg_color_space != JCS_YCbCr &&\n       cinfo->jpeg_color_space != JCS_BG_YCC) ||\n      cinfo->num_components != 3 ||\n      cinfo->out_color_space != JCS_RGB ||\n      cinfo->out_color_components != RGB_PIXELSIZE ||\n      cinfo->color_transform)\n    return FALSE;\n  /* and it only handles 2h1v or 2h2v sampling ratios */\n  if (cinfo->comp_info[0].h_samp_factor != 2 ||\n      cinfo->comp_info[1].h_samp_factor != 1 ||\n      cinfo->comp_info[2].h_samp_factor != 1 ||\n      cinfo->comp_info[0].v_samp_factor >  2 ||\n      cinfo->comp_info[1].v_samp_factor != 1 ||\n      cinfo->comp_info[2].v_samp_factor != 1)\n    return FALSE;\n  /* furthermore, it doesn't work if we've scaled the IDCTs differently */\n  if (cinfo->comp_info[0].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||\n      cinfo->comp_info[1].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||\n      cinfo->comp_info[2].DCT_h_scaled_size != cinfo->min_DCT_h_scaled_size ||\n      cinfo->comp_info[0].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||\n      cinfo->comp_info[1].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size ||\n      cinfo->comp_info[2].DCT_v_scaled_size != cinfo->min_DCT_v_scaled_size)\n    return FALSE;\n  /* ??? also need to test for upsample-time rescaling, when & if supported */\n  return TRUE;\t\t\t/* by golly, it'll work... */\n#else\n  return FALSE;\n#endif\n}\n\n\n/*\n * Compute output image dimensions and related values.\n * NOTE: this is exported for possible use by application.\n * Hence it mustn't do anything that can't be done twice.\n * Also note that it may be called before the master module is initialized!\n */\n\nGLOBAL(void)\njpeg_calc_output_dimensions (j_decompress_ptr cinfo)\n/* Do computations that are needed before master selection phase.\n * This function is used for full decompression.\n */\n{\n#ifdef IDCT_SCALING_SUPPORTED\n  int ci;\n  jpeg_component_info *compptr;\n#endif\n\n  /* Prevent application from calling me at wrong times */\n  if (cinfo->global_state != DSTATE_READY)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  /* Compute core output image dimensions and DCT scaling choices. */\n  jpeg_core_output_dimensions(cinfo);\n\n#ifdef IDCT_SCALING_SUPPORTED\n\n  /* In selecting the actual DCT scaling for each component, we try to\n   * scale up the chroma components via IDCT scaling rather than upsampling.\n   * This saves time if the upsampler gets to use 1:1 scaling.\n   * Note this code adapts subsampling ratios which are powers of 2.\n   */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    int ssize = 1;\n    while (cinfo->min_DCT_h_scaled_size * ssize <=\n\t   (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&\n\t   (cinfo->max_h_samp_factor % (compptr->h_samp_factor * ssize * 2)) == 0) {\n      ssize = ssize * 2;\n    }\n    compptr->DCT_h_scaled_size = cinfo->min_DCT_h_scaled_size * ssize;\n    ssize = 1;\n    while (cinfo->min_DCT_v_scaled_size * ssize <=\n\t   (cinfo->do_fancy_upsampling ? DCTSIZE : DCTSIZE / 2) &&\n\t   (cinfo->max_v_samp_factor % (compptr->v_samp_factor * ssize * 2)) == 0) {\n      ssize = ssize * 2;\n    }\n    compptr->DCT_v_scaled_size = cinfo->min_DCT_v_scaled_size * ssize;\n\n    /* We don't support IDCT ratios larger than 2. */\n    if (compptr->DCT_h_scaled_size > compptr->DCT_v_scaled_size * 2)\n\tcompptr->DCT_h_scaled_size = compptr->DCT_v_scaled_size * 2;\n    else if (compptr->DCT_v_scaled_size > compptr->DCT_h_scaled_size * 2)\n\tcompptr->DCT_v_scaled_size = compptr->DCT_h_scaled_size * 2;\n  }\n\n  /* Recompute downsampled dimensions of components;\n   * application needs to know these if using raw downsampled data.\n   */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Size in samples, after IDCT scaling */\n    compptr->downsampled_width = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_width *\n\t\t    (long) (compptr->h_samp_factor * compptr->DCT_h_scaled_size),\n\t\t    (long) (cinfo->max_h_samp_factor * cinfo->block_size));\n    compptr->downsampled_height = (JDIMENSION)\n      jdiv_round_up((long) cinfo->image_height *\n\t\t    (long) (compptr->v_samp_factor * compptr->DCT_v_scaled_size),\n\t\t    (long) (cinfo->max_v_samp_factor * cinfo->block_size));\n  }\n\n#endif /* IDCT_SCALING_SUPPORTED */\n\n  /* Report number of components in selected colorspace. */\n  /* Probably this should be in the color conversion module... */\n  switch (cinfo->out_color_space) {\n  case JCS_GRAYSCALE:\n    cinfo->out_color_components = 1;\n    break;\n  case JCS_RGB:\n  case JCS_BG_RGB:\n    cinfo->out_color_components = RGB_PIXELSIZE;\n    break;\n  case JCS_YCbCr:\n  case JCS_BG_YCC:\n    cinfo->out_color_components = 3;\n    break;\n  case JCS_CMYK:\n  case JCS_YCCK:\n    cinfo->out_color_components = 4;\n    break;\n  default:\t\t\t/* else must be same colorspace as in file */\n    cinfo->out_color_components = cinfo->num_components;\n    break;\n  }\n  cinfo->output_components = (cinfo->quantize_colors ? 1 :\n\t\t\t      cinfo->out_color_components);\n\n  /* See if upsampler will want to emit more than one row at a time */\n  if (use_merged_upsample(cinfo))\n    cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;\n  else\n    cinfo->rec_outbuf_height = 1;\n}\n\n\n/*\n * Several decompression processes need to range-limit values to the range\n * 0..MAXJSAMPLE; the input value may fall somewhat outside this range\n * due to noise introduced by quantization, roundoff error, etc.  These\n * processes are inner loops and need to be as fast as possible.  On most\n * machines, particularly CPUs with pipelines or instruction prefetch,\n * a (subscript-check-less) C table lookup\n *\t\tx = sample_range_limit[x];\n * is faster than explicit tests\n *\t\tif (x < 0)  x = 0;\n *\t\telse if (x > MAXJSAMPLE)  x = MAXJSAMPLE;\n * These processes all use a common table prepared by the routine below.\n *\n * For most steps we can mathematically guarantee that the initial value\n * of x is within 2*(MAXJSAMPLE+1) of the legal range, so a table running\n * from -2*(MAXJSAMPLE+1) to 3*MAXJSAMPLE+2 is sufficient.  But for the\n * initial limiting step (just after the IDCT), a wildly out-of-range value\n * is possible if the input data is corrupt.  To avoid any chance of indexing\n * off the end of memory and getting a bad-pointer trap, we perform the\n * post-IDCT limiting thus:\n *\t\tx = (sample_range_limit - SUBSET)[(x + CENTER) & MASK];\n * where MASK is 2 bits wider than legal sample data, ie 10 bits for 8-bit\n * samples.  Under normal circumstances this is more than enough range and\n * a correct output will be generated; with bogus input data the mask will\n * cause wraparound, and we will safely generate a bogus-but-in-range output.\n * For the post-IDCT step, we want to convert the data from signed to unsigned\n * representation by adding CENTERJSAMPLE at the same time that we limit it.\n * This is accomplished with SUBSET = CENTER - CENTERJSAMPLE.\n *\n * Note that the table is allocated in near data space on PCs; it's small\n * enough and used often enough to justify this.\n */\n\nLOCAL(void)\nprepare_range_limit_table (j_decompress_ptr cinfo)\n/* Allocate and fill in the sample_range_limit table */\n{\n  JSAMPLE * table;\n  int i;\n\n  table = (JSAMPLE *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t5 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));\n  /* First segment of range limit table: limit[x] = 0 for x < 0 */\n  MEMZERO(table, 2 * (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));\n  table += 2 * (MAXJSAMPLE+1);\t/* allow negative subscripts of table */\n  cinfo->sample_range_limit = table;\n  /* Main part of range limit table: limit[x] = x */\n  for (i = 0; i <= MAXJSAMPLE; i++)\n    table[i] = (JSAMPLE) i;\n  /* End of range limit table: limit[x] = MAXJSAMPLE for x > MAXJSAMPLE */\n  for (; i < 3 * (MAXJSAMPLE+1); i++)\n    table[i] = MAXJSAMPLE;\n}\n\n\n/*\n * Master selection of decompression modules.\n * This is done once at jpeg_start_decompress time.  We determine\n * which modules will be used and give them appropriate initialization calls.\n * We also initialize the decompressor input side to begin consuming data.\n *\n * Since jpeg_read_header has finished, we know what is in the SOF\n * and (first) SOS markers.  We also have all the application parameter\n * settings.\n */\n\nLOCAL(void)\nmaster_selection (j_decompress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n  boolean use_c_buffer;\n  long samplesperrow;\n  JDIMENSION jd_samplesperrow;\n\n  /* For now, precision must match compiled-in value... */\n  if (cinfo->data_precision != BITS_IN_JSAMPLE)\n    ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);\n\n  /* Initialize dimensions and other stuff */\n  jpeg_calc_output_dimensions(cinfo);\n  prepare_range_limit_table(cinfo);\n\n  /* Sanity check on image dimensions */\n  if (cinfo->output_height <= 0 || cinfo->output_width <= 0 ||\n      cinfo->out_color_components <= 0)\n    ERREXIT(cinfo, JERR_EMPTY_IMAGE);\n\n  /* Width of an output scanline must be representable as JDIMENSION. */\n  samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;\n  jd_samplesperrow = (JDIMENSION) samplesperrow;\n  if ((long) jd_samplesperrow != samplesperrow)\n    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);\n\n  /* Initialize my private state */\n  master->pass_number = 0;\n  master->using_merged_upsample = use_merged_upsample(cinfo);\n\n  /* Color quantizer selection */\n  master->quantizer_1pass = NULL;\n  master->quantizer_2pass = NULL;\n  /* No mode changes if not using buffered-image mode. */\n  if (! cinfo->quantize_colors || ! cinfo->buffered_image) {\n    cinfo->enable_1pass_quant = FALSE;\n    cinfo->enable_external_quant = FALSE;\n    cinfo->enable_2pass_quant = FALSE;\n  }\n  if (cinfo->quantize_colors) {\n    if (cinfo->raw_data_out)\n      ERREXIT(cinfo, JERR_NOTIMPL);\n    /* 2-pass quantizer only works in 3-component color space. */\n    if (cinfo->out_color_components != 3) {\n      cinfo->enable_1pass_quant = TRUE;\n      cinfo->enable_external_quant = FALSE;\n      cinfo->enable_2pass_quant = FALSE;\n      cinfo->colormap = NULL;\n    } else if (cinfo->colormap != NULL) {\n      cinfo->enable_external_quant = TRUE;\n    } else if (cinfo->two_pass_quantize) {\n      cinfo->enable_2pass_quant = TRUE;\n    } else {\n      cinfo->enable_1pass_quant = TRUE;\n    }\n\n    if (cinfo->enable_1pass_quant) {\n#ifdef QUANT_1PASS_SUPPORTED\n      jinit_1pass_quantizer(cinfo);\n      master->quantizer_1pass = cinfo->cquantize;\n#else\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n    }\n\n    /* We use the 2-pass code to map to external colormaps. */\n    if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {\n#ifdef QUANT_2PASS_SUPPORTED\n      jinit_2pass_quantizer(cinfo);\n      master->quantizer_2pass = cinfo->cquantize;\n#else\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n    }\n    /* If both quantizers are initialized, the 2-pass one is left active;\n     * this is necessary for starting with quantization to an external map.\n     */\n  }\n\n  /* Post-processing: in particular, color conversion first */\n  if (! cinfo->raw_data_out) {\n    if (master->using_merged_upsample) {\n#ifdef UPSAMPLE_MERGING_SUPPORTED\n      jinit_merged_upsampler(cinfo); /* does color conversion too */\n#else\n      ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif\n    } else {\n      jinit_color_deconverter(cinfo);\n      jinit_upsampler(cinfo);\n    }\n    jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);\n  }\n  /* Inverse DCT */\n  jinit_inverse_dct(cinfo);\n  /* Entropy decoding: either Huffman or arithmetic coding. */\n  if (cinfo->arith_code)\n    jinit_arith_decoder(cinfo);\n  else {\n    jinit_huff_decoder(cinfo);\n  }\n\n  /* Initialize principal buffer controllers. */\n  use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;\n  jinit_d_coef_controller(cinfo, use_c_buffer);\n\n  if (! cinfo->raw_data_out)\n    jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);\n\n  /* We can now tell the memory manager to allocate virtual arrays. */\n  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);\n\n  /* Initialize input side of decompressor to consume first scan. */\n  (*cinfo->inputctl->start_input_pass) (cinfo);\n\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n  /* If jpeg_start_decompress will read the whole file, initialize\n   * progress monitoring appropriately.  The input step is counted\n   * as one pass.\n   */\n  if (cinfo->progress != NULL && ! cinfo->buffered_image &&\n      cinfo->inputctl->has_multiple_scans) {\n    int nscans;\n    /* Estimate number of scans to set pass_limit. */\n    if (cinfo->progressive_mode) {\n      /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */\n      nscans = 2 + 3 * cinfo->num_components;\n    } else {\n      /* For a nonprogressive multiscan file, estimate 1 scan per component. */\n      nscans = cinfo->num_components;\n    }\n    cinfo->progress->pass_counter = 0L;\n    cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;\n    cinfo->progress->completed_passes = 0;\n    cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);\n    /* Count the input pass as done */\n    master->pass_number++;\n  }\n#endif /* D_MULTISCAN_FILES_SUPPORTED */\n}\n\n\n/*\n * Per-pass setup.\n * This is called at the beginning of each output pass.  We determine which\n * modules will be active during this pass and give them appropriate\n * start_pass calls.  We also set is_dummy_pass to indicate whether this\n * is a \"real\" output pass or a dummy pass for color quantization.\n * (In the latter case, jdapistd.c will crank the pass to completion.)\n */\n\nMETHODDEF(void)\nprepare_for_output_pass (j_decompress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n\n  if (master->pub.is_dummy_pass) {\n#ifdef QUANT_2PASS_SUPPORTED\n    /* Final pass of 2-pass quantization */\n    master->pub.is_dummy_pass = FALSE;\n    (*cinfo->cquantize->start_pass) (cinfo, FALSE);\n    (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);\n    (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);\n#else\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n#endif /* QUANT_2PASS_SUPPORTED */\n  } else {\n    if (cinfo->quantize_colors && cinfo->colormap == NULL) {\n      /* Select new quantization method */\n      if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {\n\tcinfo->cquantize = master->quantizer_2pass;\n\tmaster->pub.is_dummy_pass = TRUE;\n      } else if (cinfo->enable_1pass_quant) {\n\tcinfo->cquantize = master->quantizer_1pass;\n      } else {\n\tERREXIT(cinfo, JERR_MODE_CHANGE);\n      }\n    }\n    (*cinfo->idct->start_pass) (cinfo);\n    (*cinfo->coef->start_output_pass) (cinfo);\n    if (! cinfo->raw_data_out) {\n      if (! master->using_merged_upsample)\n\t(*cinfo->cconvert->start_pass) (cinfo);\n      (*cinfo->upsample->start_pass) (cinfo);\n      if (cinfo->quantize_colors)\n\t(*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);\n      (*cinfo->post->start_pass) (cinfo,\n\t    (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));\n      (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);\n    }\n  }\n\n  /* Set up progress monitor's pass info if present */\n  if (cinfo->progress != NULL) {\n    cinfo->progress->completed_passes = master->pass_number;\n    cinfo->progress->total_passes = master->pass_number +\n\t\t\t\t    (master->pub.is_dummy_pass ? 2 : 1);\n    /* In buffered-image mode, we assume one more output pass if EOI not\n     * yet reached, but no more passes if EOI has been reached.\n     */\n    if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {\n      cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);\n    }\n  }\n}\n\n\n/*\n * Finish up at end of an output pass.\n */\n\nMETHODDEF(void)\nfinish_output_pass (j_decompress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n\n  if (cinfo->quantize_colors)\n    (*cinfo->cquantize->finish_pass) (cinfo);\n  master->pass_number++;\n}\n\n\n#ifdef D_MULTISCAN_FILES_SUPPORTED\n\n/*\n * Switch to a new external colormap between output passes.\n */\n\nGLOBAL(void)\njpeg_new_colormap (j_decompress_ptr cinfo)\n{\n  my_master_ptr master = (my_master_ptr) cinfo->master;\n\n  /* Prevent application from calling me at wrong times */\n  if (cinfo->global_state != DSTATE_BUFIMAGE)\n    ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n\n  if (cinfo->quantize_colors && cinfo->enable_external_quant &&\n      cinfo->colormap != NULL) {\n    /* Select 2-pass quantizer for external colormap use */\n    cinfo->cquantize = master->quantizer_2pass;\n    /* Notify quantizer of colormap change */\n    (*cinfo->cquantize->new_color_map) (cinfo);\n    master->pub.is_dummy_pass = FALSE; /* just in case */\n  } else\n    ERREXIT(cinfo, JERR_MODE_CHANGE);\n}\n\n#endif /* D_MULTISCAN_FILES_SUPPORTED */\n\n\n/*\n * Initialize master decompression control and select active modules.\n * This is performed at the start of jpeg_start_decompress.\n */\n\nGLOBAL(void)\njinit_master_decompress (j_decompress_ptr cinfo)\n{\n  my_master_ptr master;\n\n  master = (my_master_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(my_decomp_master));\n  cinfo->master = &master->pub;\n  master->pub.prepare_for_output_pass = prepare_for_output_pass;\n  master->pub.finish_output_pass = finish_output_pass;\n\n  master->pub.is_dummy_pass = FALSE;\n\n  master_selection(cinfo);\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdmerge.c",
    "content": "/*\n * jdmerge.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2013-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains code for merged upsampling/color conversion.\n *\n * This file combines functions from jdsample.c and jdcolor.c;\n * read those files first to understand what's going on.\n *\n * When the chroma components are to be upsampled by simple replication\n * (ie, box filtering), we can save some work in color conversion by\n * calculating all the output pixels corresponding to a pair of chroma\n * samples at one time.  In the conversion equations\n *\tR = Y           + K1 * Cr\n *\tG = Y + K2 * Cb + K3 * Cr\n *\tB = Y + K4 * Cb\n * only the Y term varies among the group of pixels corresponding to a pair\n * of chroma samples, so the rest of the terms can be calculated just once.\n * At typical sampling ratios, this eliminates half or three-quarters of the\n * multiplications needed for color conversion.\n *\n * This file currently provides implementations for the following cases:\n *\tYCC => RGB color conversion only (YCbCr or BG_YCC).\n *\tSampling ratios of 2h1v or 2h2v.\n *\tNo scaling needed at upsample time.\n *\tCorner-aligned (non-CCIR601) sampling alignment.\n * Other special cases could be added, but in most applications these are\n * the only common cases.  (For uncommon cases we fall back on the more\n * general code in jdsample.c and jdcolor.c.)\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n#ifdef UPSAMPLE_MERGING_SUPPORTED\n\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_upsampler pub;\t/* public fields */\n\n  /* Pointer to routine to do actual upsampling/conversion of one row group */\n  JMETHOD(void, upmethod, (j_decompress_ptr cinfo,\n\t\t\t   JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,\n\t\t\t   JSAMPARRAY output_buf));\n\n  /* Private state for YCC->RGB conversion */\n  int * Cr_r_tab;\t\t/* => table for Cr to R conversion */\n  int * Cb_b_tab;\t\t/* => table for Cb to B conversion */\n  INT32 * Cr_g_tab;\t\t/* => table for Cr to G conversion */\n  INT32 * Cb_g_tab;\t\t/* => table for Cb to G conversion */\n\n  /* For 2:1 vertical sampling, we produce two output rows at a time.\n   * We need a \"spare\" row buffer to hold the second output row if the\n   * application provides just a one-row buffer; we also use the spare\n   * to discard the dummy last row if the image height is odd.\n   */\n  JSAMPROW spare_row;\n  boolean spare_full;\t\t/* T if spare buffer is occupied */\n\n  JDIMENSION out_row_width;\t/* samples per output row */\n  JDIMENSION rows_to_go;\t/* counts rows remaining in image */\n} my_upsampler;\n\ntypedef my_upsampler * my_upsample_ptr;\n\n#define SCALEBITS\t16\t/* speediest right-shift on some machines */\n#define ONE_HALF\t((INT32) 1 << (SCALEBITS-1))\n#define FIX(x)\t\t((INT32) ((x) * (1L<<SCALEBITS) + 0.5))\n\n\n/*\n * Initialize tables for YCbCr->RGB and BG_YCC->RGB colorspace conversion.\n * This is taken directly from jdcolor.c; see that file for more info.\n */\n\nLOCAL(void)\nbuild_ycc_rgb_table (j_decompress_ptr cinfo)\n/* Normal case, sYCC */\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  int i;\n  INT32 x;\n  SHIFT_TEMPS\n\n  upsample->Cr_r_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  upsample->Cb_b_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  upsample->Cr_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n  upsample->Cb_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n\n  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {\n    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */\n    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */\n    /* Cr=>R value is nearest int to 1.402 * x */\n    upsample->Cr_r_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(1.402) * x + ONE_HALF, SCALEBITS);\n    /* Cb=>B value is nearest int to 1.772 * x */\n    upsample->Cb_b_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(1.772) * x + ONE_HALF, SCALEBITS);\n    /* Cr=>G value is scaled-up -0.714136286 * x */\n    upsample->Cr_g_tab[i] = (- FIX(0.714136286)) * x;\n    /* Cb=>G value is scaled-up -0.344136286 * x */\n    /* We also add in ONE_HALF so that need not do it in inner loop */\n    upsample->Cb_g_tab[i] = (- FIX(0.344136286)) * x + ONE_HALF;\n  }\n}\n\n\nLOCAL(void)\nbuild_bg_ycc_rgb_table (j_decompress_ptr cinfo)\n/* Wide gamut case, bg-sYCC */\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  int i;\n  INT32 x;\n  SHIFT_TEMPS\n\n  upsample->Cr_r_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  upsample->Cb_b_tab = (int *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(int));\n  upsample->Cr_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n  upsample->Cb_g_tab = (INT32 *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(MAXJSAMPLE+1) * SIZEOF(INT32));\n\n  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {\n    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */\n    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */\n    /* Cr=>R value is nearest int to 2.804 * x */\n    upsample->Cr_r_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(2.804) * x + ONE_HALF, SCALEBITS);\n    /* Cb=>B value is nearest int to 3.544 * x */\n    upsample->Cb_b_tab[i] = (int)\n\t\t    RIGHT_SHIFT(FIX(3.544) * x + ONE_HALF, SCALEBITS);\n    /* Cr=>G value is scaled-up -1.428272572 * x */\n    upsample->Cr_g_tab[i] = (- FIX(1.428272572)) * x;\n    /* Cb=>G value is scaled-up -0.688272572 * x */\n    /* We also add in ONE_HALF so that need not do it in inner loop */\n    upsample->Cb_g_tab[i] = (- FIX(0.688272572)) * x + ONE_HALF;\n  }\n}\n\n\n/*\n * Initialize for an upsampling pass.\n */\n\nMETHODDEF(void)\nstart_pass_merged_upsample (j_decompress_ptr cinfo)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n\n  /* Mark the spare buffer empty */\n  upsample->spare_full = FALSE;\n  /* Initialize total-height counter for detecting bottom of image */\n  upsample->rows_to_go = cinfo->output_height;\n}\n\n\n/*\n * Control routine to do upsampling (and color conversion).\n *\n * The control routine just handles the row buffering considerations.\n */\n\nMETHODDEF(void)\nmerged_2v_upsample (j_decompress_ptr cinfo,\n\t\t    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t\t    JDIMENSION in_row_groups_avail,\n\t\t    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t    JDIMENSION out_rows_avail)\n/* 2:1 vertical sampling case: may need a spare row. */\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  JSAMPROW work_ptrs[2];\n  JDIMENSION num_rows;\t\t/* number of rows returned to caller */\n\n  if (upsample->spare_full) {\n    /* If we have a spare row saved from a previous cycle, just return it. */\n    jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,\n\t\t      1, upsample->out_row_width);\n    num_rows = 1;\n    upsample->spare_full = FALSE;\n  } else {\n    /* Figure number of rows to return to caller. */\n    num_rows = 2;\n    /* Not more than the distance to the end of the image. */\n    if (num_rows > upsample->rows_to_go)\n      num_rows = upsample->rows_to_go;\n    /* And not more than what the client can accept: */\n    out_rows_avail -= *out_row_ctr;\n    if (num_rows > out_rows_avail)\n      num_rows = out_rows_avail;\n    /* Create output pointer array for upsampler. */\n    work_ptrs[0] = output_buf[*out_row_ctr];\n    if (num_rows > 1) {\n      work_ptrs[1] = output_buf[*out_row_ctr + 1];\n    } else {\n      work_ptrs[1] = upsample->spare_row;\n      upsample->spare_full = TRUE;\n    }\n    /* Now do the upsampling. */\n    (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);\n  }\n\n  /* Adjust counts */\n  *out_row_ctr += num_rows;\n  upsample->rows_to_go -= num_rows;\n  /* When the buffer is emptied, declare this input row group consumed */\n  if (! upsample->spare_full)\n    (*in_row_group_ctr)++;\n}\n\n\nMETHODDEF(void)\nmerged_1v_upsample (j_decompress_ptr cinfo,\n\t\t    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t\t    JDIMENSION in_row_groups_avail,\n\t\t    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t    JDIMENSION out_rows_avail)\n/* 1:1 vertical sampling case: much easier, never need a spare row. */\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n\n  /* Just do the upsampling. */\n  (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,\n\t\t\t output_buf + *out_row_ctr);\n  /* Adjust counts */\n  (*out_row_ctr)++;\n  (*in_row_group_ctr)++;\n}\n\n\n/*\n * These are the routines invoked by the control routines to do\n * the actual upsampling/conversion.  One row group is processed per call.\n *\n * Note: since we may be writing directly into application-supplied buffers,\n * we have to be honest about the output width; we can't assume the buffer\n * has been rounded up to an even width.\n */\n\n\n/*\n * Upsample and color convert for the case of 2:1 horizontal and 1:1 vertical.\n */\n\nMETHODDEF(void)\nh2v1_merged_upsample (j_decompress_ptr cinfo,\n\t\t      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,\n\t\t      JSAMPARRAY output_buf)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  register int y, cred, cgreen, cblue;\n  int cb, cr;\n  register JSAMPROW outptr;\n  JSAMPROW inptr0, inptr1, inptr2;\n  JDIMENSION col;\n  /* copy these pointers into registers if possible */\n  register JSAMPLE * range_limit = cinfo->sample_range_limit;\n  int * Crrtab = upsample->Cr_r_tab;\n  int * Cbbtab = upsample->Cb_b_tab;\n  INT32 * Crgtab = upsample->Cr_g_tab;\n  INT32 * Cbgtab = upsample->Cb_g_tab;\n  SHIFT_TEMPS\n\n  inptr0 = input_buf[0][in_row_group_ctr];\n  inptr1 = input_buf[1][in_row_group_ctr];\n  inptr2 = input_buf[2][in_row_group_ctr];\n  outptr = output_buf[0];\n  /* Loop for each pair of output pixels */\n  for (col = cinfo->output_width >> 1; col > 0; col--) {\n    /* Do the chroma part of the calculation */\n    cb = GETJSAMPLE(*inptr1++);\n    cr = GETJSAMPLE(*inptr2++);\n    cred   = Crrtab[cr];\n    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);\n    cblue  = Cbbtab[cb];\n    /* Fetch 2 Y values and emit 2 pixels */\n    y  = GETJSAMPLE(*inptr0++);\n    outptr[RGB_RED]   = range_limit[y + cred];\n    outptr[RGB_GREEN] = range_limit[y + cgreen];\n    outptr[RGB_BLUE]  = range_limit[y + cblue];\n    outptr += RGB_PIXELSIZE;\n    y  = GETJSAMPLE(*inptr0++);\n    outptr[RGB_RED]   = range_limit[y + cred];\n    outptr[RGB_GREEN] = range_limit[y + cgreen];\n    outptr[RGB_BLUE]  = range_limit[y + cblue];\n    outptr += RGB_PIXELSIZE;\n  }\n  /* If image width is odd, do the last output column separately */\n  if (cinfo->output_width & 1) {\n    cb = GETJSAMPLE(*inptr1);\n    cr = GETJSAMPLE(*inptr2);\n    cred   = Crrtab[cr];\n    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);\n    cblue  = Cbbtab[cb];\n    y  = GETJSAMPLE(*inptr0);\n    outptr[RGB_RED]   = range_limit[y + cred];\n    outptr[RGB_GREEN] = range_limit[y + cgreen];\n    outptr[RGB_BLUE]  = range_limit[y + cblue];\n  }\n}\n\n\n/*\n * Upsample and color convert for the case of 2:1 horizontal and 2:1 vertical.\n */\n\nMETHODDEF(void)\nh2v2_merged_upsample (j_decompress_ptr cinfo,\n\t\t      JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,\n\t\t      JSAMPARRAY output_buf)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  register int y, cred, cgreen, cblue;\n  int cb, cr;\n  register JSAMPROW outptr0, outptr1;\n  JSAMPROW inptr00, inptr01, inptr1, inptr2;\n  JDIMENSION col;\n  /* copy these pointers into registers if possible */\n  register JSAMPLE * range_limit = cinfo->sample_range_limit;\n  int * Crrtab = upsample->Cr_r_tab;\n  int * Cbbtab = upsample->Cb_b_tab;\n  INT32 * Crgtab = upsample->Cr_g_tab;\n  INT32 * Cbgtab = upsample->Cb_g_tab;\n  SHIFT_TEMPS\n\n  inptr00 = input_buf[0][in_row_group_ctr*2];\n  inptr01 = input_buf[0][in_row_group_ctr*2 + 1];\n  inptr1 = input_buf[1][in_row_group_ctr];\n  inptr2 = input_buf[2][in_row_group_ctr];\n  outptr0 = output_buf[0];\n  outptr1 = output_buf[1];\n  /* Loop for each group of output pixels */\n  for (col = cinfo->output_width >> 1; col > 0; col--) {\n    /* Do the chroma part of the calculation */\n    cb = GETJSAMPLE(*inptr1++);\n    cr = GETJSAMPLE(*inptr2++);\n    cred   = Crrtab[cr];\n    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);\n    cblue  = Cbbtab[cb];\n    /* Fetch 4 Y values and emit 4 pixels */\n    y  = GETJSAMPLE(*inptr00++);\n    outptr0[RGB_RED]   = range_limit[y + cred];\n    outptr0[RGB_GREEN] = range_limit[y + cgreen];\n    outptr0[RGB_BLUE]  = range_limit[y + cblue];\n    outptr0 += RGB_PIXELSIZE;\n    y  = GETJSAMPLE(*inptr00++);\n    outptr0[RGB_RED]   = range_limit[y + cred];\n    outptr0[RGB_GREEN] = range_limit[y + cgreen];\n    outptr0[RGB_BLUE]  = range_limit[y + cblue];\n    outptr0 += RGB_PIXELSIZE;\n    y  = GETJSAMPLE(*inptr01++);\n    outptr1[RGB_RED]   = range_limit[y + cred];\n    outptr1[RGB_GREEN] = range_limit[y + cgreen];\n    outptr1[RGB_BLUE]  = range_limit[y + cblue];\n    outptr1 += RGB_PIXELSIZE;\n    y  = GETJSAMPLE(*inptr01++);\n    outptr1[RGB_RED]   = range_limit[y + cred];\n    outptr1[RGB_GREEN] = range_limit[y + cgreen];\n    outptr1[RGB_BLUE]  = range_limit[y + cblue];\n    outptr1 += RGB_PIXELSIZE;\n  }\n  /* If image width is odd, do the last output column separately */\n  if (cinfo->output_width & 1) {\n    cb = GETJSAMPLE(*inptr1);\n    cr = GETJSAMPLE(*inptr2);\n    cred   = Crrtab[cr];\n    cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);\n    cblue  = Cbbtab[cb];\n    y  = GETJSAMPLE(*inptr00);\n    outptr0[RGB_RED]   = range_limit[y + cred];\n    outptr0[RGB_GREEN] = range_limit[y + cgreen];\n    outptr0[RGB_BLUE]  = range_limit[y + cblue];\n    y  = GETJSAMPLE(*inptr01);\n    outptr1[RGB_RED]   = range_limit[y + cred];\n    outptr1[RGB_GREEN] = range_limit[y + cgreen];\n    outptr1[RGB_BLUE]  = range_limit[y + cblue];\n  }\n}\n\n\n/*\n * Module initialization routine for merged upsampling/color conversion.\n *\n * NB: this is called under the conditions determined by use_merged_upsample()\n * in jdmaster.c.  That routine MUST correspond to the actual capabilities\n * of this module; no safety checks are made here.\n */\n\nGLOBAL(void)\njinit_merged_upsampler (j_decompress_ptr cinfo)\n{\n  my_upsample_ptr upsample;\n\n  upsample = (my_upsample_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_upsampler));\n  cinfo->upsample = &upsample->pub;\n  upsample->pub.start_pass = start_pass_merged_upsample;\n  upsample->pub.need_context_rows = FALSE;\n\n  upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;\n\n  if (cinfo->max_v_samp_factor == 2) {\n    upsample->pub.upsample = merged_2v_upsample;\n    upsample->upmethod = h2v2_merged_upsample;\n    /* Allocate a spare row buffer */\n    upsample->spare_row = (JSAMPROW)\n      (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t(size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));\n  } else {\n    upsample->pub.upsample = merged_1v_upsample;\n    upsample->upmethod = h2v1_merged_upsample;\n    /* No spare row needed */\n    upsample->spare_row = NULL;\n  }\n\n  if (cinfo->jpeg_color_space == JCS_BG_YCC)\n    build_bg_ycc_rgb_table(cinfo);\n  else\n    build_ycc_rgb_table(cinfo);\n}\n\n#endif /* UPSAMPLE_MERGING_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdpostct.c",
    "content": "/*\n * jdpostct.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the decompression postprocessing controller.\n * This controller manages the upsampling, color conversion, and color\n * quantization/reduction steps; specifically, it controls the buffering\n * between upsample/color conversion and color quantization/reduction.\n *\n * If no color quantization/reduction is required, then this module has no\n * work to do, and it just hands off to the upsample/color conversion code.\n * An integrated upsample/convert/quantize process would replace this module\n * entirely.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Private buffer controller object */\n\ntypedef struct {\n  struct jpeg_d_post_controller pub; /* public fields */\n\n  /* Color quantization source buffer: this holds output data from\n   * the upsample/color conversion step to be passed to the quantizer.\n   * For two-pass color quantization, we need a full-image buffer;\n   * for one-pass operation, a strip buffer is sufficient.\n   */\n  jvirt_sarray_ptr whole_image;\t/* virtual array, or NULL if one-pass */\n  JSAMPARRAY buffer;\t\t/* strip buffer, or current strip of virtual */\n  JDIMENSION strip_height;\t/* buffer size in rows */\n  /* for two-pass mode only: */\n  JDIMENSION starting_row;\t/* row # of first row in current strip */\n  JDIMENSION next_row;\t\t/* index of next row to fill/empty in strip */\n} my_post_controller;\n\ntypedef my_post_controller * my_post_ptr;\n\n\n/* Forward declarations */\nMETHODDEF(void) post_process_1pass\n\tJPP((j_decompress_ptr cinfo,\n\t     JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t     JDIMENSION in_row_groups_avail,\n\t     JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t     JDIMENSION out_rows_avail));\n#ifdef QUANT_2PASS_SUPPORTED\nMETHODDEF(void) post_process_prepass\n\tJPP((j_decompress_ptr cinfo,\n\t     JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t     JDIMENSION in_row_groups_avail,\n\t     JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t     JDIMENSION out_rows_avail));\nMETHODDEF(void) post_process_2pass\n\tJPP((j_decompress_ptr cinfo,\n\t     JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t     JDIMENSION in_row_groups_avail,\n\t     JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t     JDIMENSION out_rows_avail));\n#endif\n\n\n/*\n * Initialize for a processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)\n{\n  my_post_ptr post = (my_post_ptr) cinfo->post;\n\n  switch (pass_mode) {\n  case JBUF_PASS_THRU:\n    if (cinfo->quantize_colors) {\n      /* Single-pass processing with color quantization. */\n      post->pub.post_process_data = post_process_1pass;\n      /* We could be doing buffered-image output before starting a 2-pass\n       * color quantization; in that case, jinit_d_post_controller did not\n       * allocate a strip buffer.  Use the virtual-array buffer as workspace.\n       */\n      if (post->buffer == NULL) {\n\tpost->buffer = (*cinfo->mem->access_virt_sarray)\n\t  ((j_common_ptr) cinfo, post->whole_image,\n\t   (JDIMENSION) 0, post->strip_height, TRUE);\n      }\n    } else {\n      /* For single-pass processing without color quantization,\n       * I have no work to do; just call the upsampler directly.\n       */\n      post->pub.post_process_data = cinfo->upsample->upsample;\n    }\n    break;\n#ifdef QUANT_2PASS_SUPPORTED\n  case JBUF_SAVE_AND_PASS:\n    /* First pass of 2-pass quantization */\n    if (post->whole_image == NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    post->pub.post_process_data = post_process_prepass;\n    break;\n  case JBUF_CRANK_DEST:\n    /* Second pass of 2-pass quantization */\n    if (post->whole_image == NULL)\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    post->pub.post_process_data = post_process_2pass;\n    break;\n#endif /* QUANT_2PASS_SUPPORTED */\n  default:\n    ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n    break;\n  }\n  post->starting_row = post->next_row = 0;\n}\n\n\n/*\n * Process some data in the one-pass (strip buffer) case.\n * This is used for color precision reduction as well as one-pass quantization.\n */\n\nMETHODDEF(void)\npost_process_1pass (j_decompress_ptr cinfo,\n\t\t    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t\t    JDIMENSION in_row_groups_avail,\n\t\t    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t    JDIMENSION out_rows_avail)\n{\n  my_post_ptr post = (my_post_ptr) cinfo->post;\n  JDIMENSION num_rows, max_rows;\n\n  /* Fill the buffer, but not more than what we can dump out in one go. */\n  /* Note we rely on the upsampler to detect bottom of image. */\n  max_rows = out_rows_avail - *out_row_ctr;\n  if (max_rows > post->strip_height)\n    max_rows = post->strip_height;\n  num_rows = 0;\n  (*cinfo->upsample->upsample) (cinfo,\n\t\tinput_buf, in_row_group_ctr, in_row_groups_avail,\n\t\tpost->buffer, &num_rows, max_rows);\n  /* Quantize and emit data. */\n  (*cinfo->cquantize->color_quantize) (cinfo,\n\t\tpost->buffer, output_buf + *out_row_ctr, (int) num_rows);\n  *out_row_ctr += num_rows;\n}\n\n\n#ifdef QUANT_2PASS_SUPPORTED\n\n/*\n * Process some data in the first pass of 2-pass quantization.\n */\n\nMETHODDEF(void)\npost_process_prepass (j_decompress_ptr cinfo,\n\t\t      JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t\t      JDIMENSION in_row_groups_avail,\n\t\t      JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t      JDIMENSION out_rows_avail)\n{\n  my_post_ptr post = (my_post_ptr) cinfo->post;\n  JDIMENSION old_next_row, num_rows;\n\n  /* Reposition virtual buffer if at start of strip. */\n  if (post->next_row == 0) {\n    post->buffer = (*cinfo->mem->access_virt_sarray)\n\t((j_common_ptr) cinfo, post->whole_image,\n\t post->starting_row, post->strip_height, TRUE);\n  }\n\n  /* Upsample some data (up to a strip height's worth). */\n  old_next_row = post->next_row;\n  (*cinfo->upsample->upsample) (cinfo,\n\t\tinput_buf, in_row_group_ctr, in_row_groups_avail,\n\t\tpost->buffer, &post->next_row, post->strip_height);\n\n  /* Allow quantizer to scan new data.  No data is emitted, */\n  /* but we advance out_row_ctr so outer loop can tell when we're done. */\n  if (post->next_row > old_next_row) {\n    num_rows = post->next_row - old_next_row;\n    (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,\n\t\t\t\t\t (JSAMPARRAY) NULL, (int) num_rows);\n    *out_row_ctr += num_rows;\n  }\n\n  /* Advance if we filled the strip. */\n  if (post->next_row >= post->strip_height) {\n    post->starting_row += post->strip_height;\n    post->next_row = 0;\n  }\n}\n\n\n/*\n * Process some data in the second pass of 2-pass quantization.\n */\n\nMETHODDEF(void)\npost_process_2pass (j_decompress_ptr cinfo,\n\t\t    JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t\t    JDIMENSION in_row_groups_avail,\n\t\t    JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t    JDIMENSION out_rows_avail)\n{\n  my_post_ptr post = (my_post_ptr) cinfo->post;\n  JDIMENSION num_rows, max_rows;\n\n  /* Reposition virtual buffer if at start of strip. */\n  if (post->next_row == 0) {\n    post->buffer = (*cinfo->mem->access_virt_sarray)\n\t((j_common_ptr) cinfo, post->whole_image,\n\t post->starting_row, post->strip_height, FALSE);\n  }\n\n  /* Determine number of rows to emit. */\n  num_rows = post->strip_height - post->next_row; /* available in strip */\n  max_rows = out_rows_avail - *out_row_ctr; /* available in output area */\n  if (num_rows > max_rows)\n    num_rows = max_rows;\n  /* We have to check bottom of image here, can't depend on upsampler. */\n  max_rows = cinfo->output_height - post->starting_row;\n  if (num_rows > max_rows)\n    num_rows = max_rows;\n\n  /* Quantize and emit data. */\n  (*cinfo->cquantize->color_quantize) (cinfo,\n\t\tpost->buffer + post->next_row, output_buf + *out_row_ctr,\n\t\t(int) num_rows);\n  *out_row_ctr += num_rows;\n\n  /* Advance if we filled the strip. */\n  post->next_row += num_rows;\n  if (post->next_row >= post->strip_height) {\n    post->starting_row += post->strip_height;\n    post->next_row = 0;\n  }\n}\n\n#endif /* QUANT_2PASS_SUPPORTED */\n\n\n/*\n * Initialize postprocessing controller.\n */\n\nGLOBAL(void)\njinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)\n{\n  my_post_ptr post;\n\n  post = (my_post_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_post_controller));\n  cinfo->post = (struct jpeg_d_post_controller *) post;\n  post->pub.start_pass = start_pass_dpost;\n  post->whole_image = NULL;\t/* flag for no virtual arrays */\n  post->buffer = NULL;\t\t/* flag for no strip buffer */\n\n  /* Create the quantization buffer, if needed */\n  if (cinfo->quantize_colors) {\n    /* The buffer strip height is max_v_samp_factor, which is typically\n     * an efficient number of rows for upsampling to return.\n     * (In the presence of output rescaling, we might want to be smarter?)\n     */\n    post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;\n    if (need_full_buffer) {\n      /* Two-pass color quantization: need full-image storage. */\n      /* We round up the number of rows to a multiple of the strip height. */\n#ifdef QUANT_2PASS_SUPPORTED\n      post->whole_image = (*cinfo->mem->request_virt_sarray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n\t cinfo->output_width * cinfo->out_color_components,\n\t (JDIMENSION) jround_up((long) cinfo->output_height,\n\t\t\t\t(long) post->strip_height),\n\t post->strip_height);\n#else\n      ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);\n#endif /* QUANT_2PASS_SUPPORTED */\n    } else {\n      /* One-pass color quantization: just make a strip buffer. */\n      post->buffer = (*cinfo->mem->alloc_sarray)\n\t((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t cinfo->output_width * cinfo->out_color_components,\n\t post->strip_height);\n    }\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdsample.c",
    "content": "/*\n * jdsample.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2002-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains upsampling routines.\n *\n * Upsampling input data is counted in \"row groups\".  A row group\n * is defined to be (v_samp_factor * DCT_v_scaled_size / min_DCT_v_scaled_size)\n * sample rows of each component.  Upsampling will normally produce\n * max_v_samp_factor pixel rows from each row group (but this could vary\n * if the upsampler is applying a scale factor of its own).\n *\n * An excellent reference for image resampling is\n *   Digital Image Warping, George Wolberg, 1990.\n *   Pub. by IEEE Computer Society Press, Los Alamitos, CA. ISBN 0-8186-8944-7.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Pointer to routine to upsample a single component */\ntypedef JMETHOD(void, upsample1_ptr,\n\t\t(j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_upsampler pub;\t/* public fields */\n\n  /* Color conversion buffer.  When using separate upsampling and color\n   * conversion steps, this buffer holds one upsampled row group until it\n   * has been color converted and output.\n   * Note: we do not allocate any storage for component(s) which are full-size,\n   * ie do not need rescaling.  The corresponding entry of color_buf[] is\n   * simply set to point to the input data array, thereby avoiding copying.\n   */\n  JSAMPARRAY color_buf[MAX_COMPONENTS];\n\n  /* Per-component upsampling method pointers */\n  upsample1_ptr methods[MAX_COMPONENTS];\n\n  int next_row_out;\t\t/* counts rows emitted from color_buf */\n  JDIMENSION rows_to_go;\t/* counts rows remaining in image */\n\n  /* Height of an input row group for each component. */\n  int rowgroup_height[MAX_COMPONENTS];\n\n  /* These arrays save pixel expansion factors so that int_expand need not\n   * recompute them each time.  They are unused for other upsampling methods.\n   */\n  UINT8 h_expand[MAX_COMPONENTS];\n  UINT8 v_expand[MAX_COMPONENTS];\n} my_upsampler;\n\ntypedef my_upsampler * my_upsample_ptr;\n\n\n/*\n * Initialize for an upsampling pass.\n */\n\nMETHODDEF(void)\nstart_pass_upsample (j_decompress_ptr cinfo)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n\n  /* Mark the conversion buffer empty */\n  upsample->next_row_out = cinfo->max_v_samp_factor;\n  /* Initialize total-height counter for detecting bottom of image */\n  upsample->rows_to_go = cinfo->output_height;\n}\n\n\n/*\n * Control routine to do upsampling (and color conversion).\n *\n * In this version we upsample each component independently.\n * We upsample one row group into the conversion buffer, then apply\n * color conversion a row at a time.\n */\n\nMETHODDEF(void)\nsep_upsample (j_decompress_ptr cinfo,\n\t      JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,\n\t      JDIMENSION in_row_groups_avail,\n\t      JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t      JDIMENSION out_rows_avail)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  int ci;\n  jpeg_component_info * compptr;\n  JDIMENSION num_rows;\n\n  /* Fill the conversion buffer, if it's empty */\n  if (upsample->next_row_out >= cinfo->max_v_samp_factor) {\n    for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n\t ci++, compptr++) {\n      /* Invoke per-component upsample method.  Notice we pass a POINTER\n       * to color_buf[ci], so that fullsize_upsample can change it.\n       */\n      (*upsample->methods[ci]) (cinfo, compptr,\n\tinput_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),\n\tupsample->color_buf + ci);\n    }\n    upsample->next_row_out = 0;\n  }\n\n  /* Color-convert and emit rows */\n\n  /* How many we have in the buffer: */\n  num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);\n  /* Not more than the distance to the end of the image.  Need this test\n   * in case the image height is not a multiple of max_v_samp_factor:\n   */\n  if (num_rows > upsample->rows_to_go) \n    num_rows = upsample->rows_to_go;\n  /* And not more than what the client can accept: */\n  out_rows_avail -= *out_row_ctr;\n  if (num_rows > out_rows_avail)\n    num_rows = out_rows_avail;\n\n  (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,\n\t\t\t\t     (JDIMENSION) upsample->next_row_out,\n\t\t\t\t     output_buf + *out_row_ctr,\n\t\t\t\t     (int) num_rows);\n\n  /* Adjust counts */\n  *out_row_ctr += num_rows;\n  upsample->rows_to_go -= num_rows;\n  upsample->next_row_out += num_rows;\n  /* When the buffer is emptied, declare this input row group consumed */\n  if (upsample->next_row_out >= cinfo->max_v_samp_factor)\n    (*in_row_group_ctr)++;\n}\n\n\n/*\n * These are the routines invoked by sep_upsample to upsample pixel values\n * of a single component.  One row group is processed per call.\n */\n\n\n/*\n * For full-size components, we just make color_buf[ci] point at the\n * input buffer, and thus avoid copying any data.  Note that this is\n * safe only because sep_upsample doesn't declare the input row group\n * \"consumed\" until we are done color converting and emitting it.\n */\n\nMETHODDEF(void)\nfullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t   JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)\n{\n  *output_data_ptr = input_data;\n}\n\n\n/*\n * This is a no-op version used for \"uninteresting\" components.\n * These components will not be referenced by color conversion.\n */\n\nMETHODDEF(void)\nnoop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)\n{\n  *output_data_ptr = NULL;\t/* safety check */\n}\n\n\n/*\n * This version handles any integral sampling ratios.\n * This is not used for typical JPEG files, so it need not be fast.\n * Nor, for that matter, is it particularly accurate: the algorithm is\n * simple replication of the input pixel onto the corresponding output\n * pixels.  The hi-falutin sampling literature refers to this as a\n * \"box filter\".  A box filter tends to introduce visible artifacts,\n * so if you are actually going to use 3:1 or 4:1 sampling ratios\n * you would be well advised to improve this code.\n */\n\nMETHODDEF(void)\nint_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t      JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)\n{\n  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;\n  JSAMPARRAY output_data = *output_data_ptr;\n  register JSAMPROW inptr, outptr;\n  register JSAMPLE invalue;\n  register int h;\n  JSAMPROW outend;\n  int h_expand, v_expand;\n  int inrow, outrow;\n\n  h_expand = upsample->h_expand[compptr->component_index];\n  v_expand = upsample->v_expand[compptr->component_index];\n\n  inrow = outrow = 0;\n  while (outrow < cinfo->max_v_samp_factor) {\n    /* Generate one output row with proper horizontal expansion */\n    inptr = input_data[inrow];\n    outptr = output_data[outrow];\n    outend = outptr + cinfo->output_width;\n    while (outptr < outend) {\n      invalue = *inptr++;\t/* don't need GETJSAMPLE() here */\n      for (h = h_expand; h > 0; h--) {\n\t*outptr++ = invalue;\n      }\n    }\n    /* Generate any additional output rows by duplicating the first one */\n    if (v_expand > 1) {\n      jcopy_sample_rows(output_data, outrow, output_data, outrow+1,\n\t\t\tv_expand-1, cinfo->output_width);\n    }\n    inrow++;\n    outrow += v_expand;\n  }\n}\n\n\n/*\n * Fast processing for the common case of 2:1 horizontal and 1:1 vertical.\n * It's still a box filter.\n */\n\nMETHODDEF(void)\nh2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)\n{\n  JSAMPARRAY output_data = *output_data_ptr;\n  register JSAMPROW inptr, outptr;\n  register JSAMPLE invalue;\n  JSAMPROW outend;\n  int outrow;\n\n  for (outrow = 0; outrow < cinfo->max_v_samp_factor; outrow++) {\n    inptr = input_data[outrow];\n    outptr = output_data[outrow];\n    outend = outptr + cinfo->output_width;\n    while (outptr < outend) {\n      invalue = *inptr++;\t/* don't need GETJSAMPLE() here */\n      *outptr++ = invalue;\n      *outptr++ = invalue;\n    }\n  }\n}\n\n\n/*\n * Fast processing for the common case of 2:1 horizontal and 2:1 vertical.\n * It's still a box filter.\n */\n\nMETHODDEF(void)\nh2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)\n{\n  JSAMPARRAY output_data = *output_data_ptr;\n  register JSAMPROW inptr, outptr;\n  register JSAMPLE invalue;\n  JSAMPROW outend;\n  int inrow, outrow;\n\n  inrow = outrow = 0;\n  while (outrow < cinfo->max_v_samp_factor) {\n    inptr = input_data[inrow];\n    outptr = output_data[outrow];\n    outend = outptr + cinfo->output_width;\n    while (outptr < outend) {\n      invalue = *inptr++;\t/* don't need GETJSAMPLE() here */\n      *outptr++ = invalue;\n      *outptr++ = invalue;\n    }\n    jcopy_sample_rows(output_data, outrow, output_data, outrow+1,\n\t\t      1, cinfo->output_width);\n    inrow++;\n    outrow += 2;\n  }\n}\n\n\n/*\n * Module initialization routine for upsampling.\n */\n\nGLOBAL(void)\njinit_upsampler (j_decompress_ptr cinfo)\n{\n  my_upsample_ptr upsample;\n  int ci;\n  jpeg_component_info * compptr;\n  int h_in_group, v_in_group, h_out_group, v_out_group;\n\n  upsample = (my_upsample_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_upsampler));\n  cinfo->upsample = &upsample->pub;\n  upsample->pub.start_pass = start_pass_upsample;\n  upsample->pub.upsample = sep_upsample;\n  upsample->pub.need_context_rows = FALSE; /* until we find out differently */\n\n  if (cinfo->CCIR601_sampling)\t/* this isn't supported */\n    ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);\n\n  /* Verify we can handle the sampling factors, select per-component methods,\n   * and create storage as needed.\n   */\n  for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;\n       ci++, compptr++) {\n    /* Compute size of an \"input group\" after IDCT scaling.  This many samples\n     * are to be converted to max_h_samp_factor * max_v_samp_factor pixels.\n     */\n    h_in_group = (compptr->h_samp_factor * compptr->DCT_h_scaled_size) /\n\t\t cinfo->min_DCT_h_scaled_size;\n    v_in_group = (compptr->v_samp_factor * compptr->DCT_v_scaled_size) /\n\t\t cinfo->min_DCT_v_scaled_size;\n    h_out_group = cinfo->max_h_samp_factor;\n    v_out_group = cinfo->max_v_samp_factor;\n    upsample->rowgroup_height[ci] = v_in_group; /* save for use later */\n    if (! compptr->component_needed) {\n      /* Don't bother to upsample an uninteresting component. */\n      upsample->methods[ci] = noop_upsample;\n      continue;\t\t/* don't need to allocate buffer */\n    }\n    if (h_in_group == h_out_group && v_in_group == v_out_group) {\n      /* Fullsize components can be processed without any work. */\n      upsample->methods[ci] = fullsize_upsample;\n      continue;\t\t/* don't need to allocate buffer */\n    }\n    if (h_in_group * 2 == h_out_group && v_in_group == v_out_group) {\n      /* Special case for 2h1v upsampling */\n      upsample->methods[ci] = h2v1_upsample;\n    } else if (h_in_group * 2 == h_out_group &&\n\t       v_in_group * 2 == v_out_group) {\n      /* Special case for 2h2v upsampling */\n      upsample->methods[ci] = h2v2_upsample;\n    } else if ((h_out_group % h_in_group) == 0 &&\n\t       (v_out_group % v_in_group) == 0) {\n      /* Generic integral-factors upsampling method */\n      upsample->methods[ci] = int_upsample;\n      upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);\n      upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);\n    } else\n      ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);\n    upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) jround_up((long) cinfo->output_width,\n\t\t\t      (long) cinfo->max_h_samp_factor),\n       (JDIMENSION) cinfo->max_v_samp_factor);\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jdtrans.c",
    "content": "/*\n * jdtrans.c\n *\n * Copyright (C) 1995-1997, Thomas G. Lane.\n * Modified 2000-2009 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains library routines for transcoding decompression,\n * that is, reading raw DCT coefficient arrays from an input JPEG file.\n * The routines in jdapimin.c will also be needed by a transcoder.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/* Forward declarations */\nLOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));\n\n\n/*\n * Read the coefficient arrays from a JPEG file.\n * jpeg_read_header must be completed before calling this.\n *\n * The entire image is read into a set of virtual coefficient-block arrays,\n * one per component.  The return value is a pointer to the array of\n * virtual-array descriptors.  These can be manipulated directly via the\n * JPEG memory manager, or handed off to jpeg_write_coefficients().\n * To release the memory occupied by the virtual arrays, call\n * jpeg_finish_decompress() when done with the data.\n *\n * An alternative usage is to simply obtain access to the coefficient arrays\n * during a buffered-image-mode decompression operation.  This is allowed\n * after any jpeg_finish_output() call.  The arrays can be accessed until\n * jpeg_finish_decompress() is called.  (Note that any call to the library\n * may reposition the arrays, so don't rely on access_virt_barray() results\n * to stay valid across library calls.)\n *\n * Returns NULL if suspended.  This case need be checked only if\n * a suspending data source is used.\n */\n\nGLOBAL(jvirt_barray_ptr *)\njpeg_read_coefficients (j_decompress_ptr cinfo)\n{\n  if (cinfo->global_state == DSTATE_READY) {\n    /* First call: initialize active modules */\n    transdecode_master_selection(cinfo);\n    cinfo->global_state = DSTATE_RDCOEFS;\n  }\n  if (cinfo->global_state == DSTATE_RDCOEFS) {\n    /* Absorb whole file into the coef buffer */\n    for (;;) {\n      int retcode;\n      /* Call progress monitor hook if present */\n      if (cinfo->progress != NULL)\n\t(*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);\n      /* Absorb some more input */\n      retcode = (*cinfo->inputctl->consume_input) (cinfo);\n      if (retcode == JPEG_SUSPENDED)\n\treturn NULL;\n      if (retcode == JPEG_REACHED_EOI)\n\tbreak;\n      /* Advance progress counter if appropriate */\n      if (cinfo->progress != NULL &&\n\t  (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {\n\tif (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {\n\t  /* startup underestimated number of scans; ratchet up one scan */\n\t  cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;\n\t}\n      }\n    }\n    /* Set state so that jpeg_finish_decompress does the right thing */\n    cinfo->global_state = DSTATE_STOPPING;\n  }\n  /* At this point we should be in state DSTATE_STOPPING if being used\n   * standalone, or in state DSTATE_BUFIMAGE if being invoked to get access\n   * to the coefficients during a full buffered-image-mode decompression.\n   */\n  if ((cinfo->global_state == DSTATE_STOPPING ||\n       cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {\n    return cinfo->coef->coef_arrays;\n  }\n  /* Oops, improper usage */\n  ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);\n  return NULL;\t\t\t/* keep compiler happy */\n}\n\n\n/*\n * Master selection of decompression modules for transcoding.\n * This substitutes for jdmaster.c's initialization of the full decompressor.\n */\n\nLOCAL(void)\ntransdecode_master_selection (j_decompress_ptr cinfo)\n{\n  /* This is effectively a buffered-image operation. */\n  cinfo->buffered_image = TRUE;\n\n  /* Compute output image dimensions and related values. */\n  jpeg_core_output_dimensions(cinfo);\n\n  /* Entropy decoding: either Huffman or arithmetic coding. */\n  if (cinfo->arith_code)\n    jinit_arith_decoder(cinfo);\n  else {\n    jinit_huff_decoder(cinfo);\n  }\n\n  /* Always get a full-image coefficient buffer. */\n  jinit_d_coef_controller(cinfo, TRUE);\n\n  /* We can now tell the memory manager to allocate virtual arrays. */\n  (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);\n\n  /* Initialize input side of decompressor to consume first scan. */\n  (*cinfo->inputctl->start_input_pass) (cinfo);\n\n  /* Initialize progress monitoring. */\n  if (cinfo->progress != NULL) {\n    int nscans;\n    /* Estimate number of scans to set pass_limit. */\n    if (cinfo->progressive_mode) {\n      /* Arbitrarily estimate 2 interleaved DC scans + 3 AC scans/component. */\n      nscans = 2 + 3 * cinfo->num_components;\n    } else if (cinfo->inputctl->has_multiple_scans) {\n      /* For a nonprogressive multiscan file, estimate 1 scan per component. */\n      nscans = cinfo->num_components;\n    } else {\n      nscans = 1;\n    }\n    cinfo->progress->pass_counter = 0L;\n    cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;\n    cinfo->progress->completed_passes = 0;\n    cinfo->progress->total_passes = 1;\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jerror.c",
    "content": "/*\n * jerror.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2012-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains simple error-reporting and trace-message routines.\n * These are suitable for Unix-like systems and others where writing to\n * stderr is the right thing to do.  Many applications will want to replace\n * some or all of these routines.\n *\n * If you define USE_WINDOWS_MESSAGEBOX in jconfig.h or in the makefile,\n * you get a Windows-specific hack to display error messages in a dialog box.\n * It ain't much, but it beats dropping error messages into the bit bucket,\n * which is what happens to output to stderr under most Windows C compilers.\n *\n * These routines are used by both the compression and decompression code.\n */\n\n#ifdef USE_WINDOWS_MESSAGEBOX\n#include <windows.h>\n#endif\n\n/* this is not a core library module, so it doesn't define JPEG_INTERNALS */\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jversion.h\"\n#include \"jerror.h\"\n\n#ifndef EXIT_FAILURE\t\t/* define exit() codes if not provided */\n#define EXIT_FAILURE  1\n#endif\n\n\n/*\n * Create the message string table.\n * We do this from the master message list in jerror.h by re-reading\n * jerror.h with a suitable definition for macro JMESSAGE.\n * The message table is made an external symbol just in case any applications\n * want to refer to it directly.\n */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jpeg_std_message_table\tjMsgTable\n#endif\n\n#define JMESSAGE(code,string)\tstring ,\n\nconst char * const jpeg_std_message_table[] = {\n#include \"jerror.h\"\n  NULL\n};\n\n\n/*\n * Error exit handler: must not return to caller.\n *\n * Applications may override this if they want to get control back after\n * an error.  Typically one would longjmp somewhere instead of exiting.\n * The setjmp buffer can be made a private field within an expanded error\n * handler object.  Note that the info needed to generate an error message\n * is stored in the error object, so you can generate the message now or\n * later, at your convenience.\n * You should make sure that the JPEG object is cleaned up (with jpeg_abort\n * or jpeg_destroy) at some point.\n */\n\nMETHODDEF(noreturn_t)\nerror_exit (j_common_ptr cinfo)\n{\n  /* Always display the message */\n  (*cinfo->err->output_message) (cinfo);\n\n  /* Let the memory manager delete any temp files before we die */\n  jpeg_destroy(cinfo);\n\n  exit(EXIT_FAILURE);\n}\n\n\n/*\n * Actual output of an error or trace message.\n * Applications may override this method to send JPEG messages somewhere\n * other than stderr.\n *\n * On Windows, printing to stderr is generally completely useless,\n * so we provide optional code to produce an error-dialog popup.\n * Most Windows applications will still prefer to override this routine,\n * but if they don't, it'll do something at least marginally useful.\n *\n * NOTE: to use the library in an environment that doesn't support the\n * C stdio library, you may have to delete the call to fprintf() entirely,\n * not just not use this routine.\n */\n\nMETHODDEF(void)\noutput_message (j_common_ptr cinfo)\n{\n  char buffer[JMSG_LENGTH_MAX];\n\n  /* Create the message */\n  (*cinfo->err->format_message) (cinfo, buffer);\n\n#ifdef USE_WINDOWS_MESSAGEBOX\n  /* Display it in a message dialog box */\n  MessageBox(GetActiveWindow(), buffer, \"JPEG Library Error\",\n\t     MB_OK | MB_ICONERROR);\n#else\n  /* Send it to stderr, adding a newline */\n  fprintf(stderr, \"%s\\n\", buffer);\n#endif\n}\n\n\n/*\n * Decide whether to emit a trace or warning message.\n * msg_level is one of:\n *   -1: recoverable corrupt-data warning, may want to abort.\n *    0: important advisory messages (always display to user).\n *    1: first level of tracing detail.\n *    2,3,...: successively more detailed tracing messages.\n * An application might override this method if it wanted to abort on warnings\n * or change the policy about which messages to display.\n */\n\nMETHODDEF(void)\nemit_message (j_common_ptr cinfo, int msg_level)\n{\n  struct jpeg_error_mgr * err = cinfo->err;\n\n  if (msg_level < 0) {\n    /* It's a warning message.  Since corrupt files may generate many warnings,\n     * the policy implemented here is to show only the first warning,\n     * unless trace_level >= 3.\n     */\n    if (err->num_warnings == 0 || err->trace_level >= 3)\n      (*err->output_message) (cinfo);\n    /* Always count warnings in num_warnings. */\n    err->num_warnings++;\n  } else {\n    /* It's a trace message.  Show it if trace_level >= msg_level. */\n    if (err->trace_level >= msg_level)\n      (*err->output_message) (cinfo);\n  }\n}\n\n\n/*\n * Format a message string for the most recent JPEG error or message.\n * The message is stored into buffer, which should be at least JMSG_LENGTH_MAX\n * characters.  Note that no '\\n' character is added to the string.\n * Few applications should need to override this method.\n */\n\nMETHODDEF(void)\nformat_message (j_common_ptr cinfo, char * buffer)\n{\n  struct jpeg_error_mgr * err = cinfo->err;\n  int msg_code = err->msg_code;\n  const char * msgtext = NULL;\n  const char * msgptr;\n  char ch;\n  boolean isstring;\n\n  /* Look up message string in proper table */\n  if (msg_code > 0 && msg_code <= err->last_jpeg_message) {\n    msgtext = err->jpeg_message_table[msg_code];\n  } else if (err->addon_message_table != NULL &&\n\t     msg_code >= err->first_addon_message &&\n\t     msg_code <= err->last_addon_message) {\n    msgtext = err->addon_message_table[msg_code - err->first_addon_message];\n  }\n\n  /* Defend against bogus message number */\n  if (msgtext == NULL) {\n    err->msg_parm.i[0] = msg_code;\n    msgtext = err->jpeg_message_table[0];\n  }\n\n  /* Check for string parameter, as indicated by %s in the message text */\n  isstring = FALSE;\n  msgptr = msgtext;\n  while ((ch = *msgptr++) != '\\0') {\n    if (ch == '%') {\n      if (*msgptr == 's') isstring = TRUE;\n      break;\n    }\n  }\n\n  /* Format the message into the passed buffer */\n  if (isstring)\n    sprintf(buffer, msgtext, err->msg_parm.s);\n  else\n    sprintf(buffer, msgtext,\n\t    err->msg_parm.i[0], err->msg_parm.i[1],\n\t    err->msg_parm.i[2], err->msg_parm.i[3],\n\t    err->msg_parm.i[4], err->msg_parm.i[5],\n\t    err->msg_parm.i[6], err->msg_parm.i[7]);\n}\n\n\n/*\n * Reset error state variables at start of a new image.\n * This is called during compression startup to reset trace/error\n * processing to default state, without losing any application-specific\n * method pointers.  An application might possibly want to override\n * this method if it has additional error processing state.\n */\n\nMETHODDEF(void)\nreset_error_mgr (j_common_ptr cinfo)\n{\n  cinfo->err->num_warnings = 0;\n  /* trace_level is not reset since it is an application-supplied parameter */\n  cinfo->err->msg_code = 0;\t/* may be useful as a flag for \"no error\" */\n}\n\n\n/*\n * Fill in the standard error-handling methods in a jpeg_error_mgr object.\n * Typical call is:\n *\tstruct jpeg_compress_struct cinfo;\n *\tstruct jpeg_error_mgr err;\n *\n *\tcinfo.err = jpeg_std_error(&err);\n * after which the application may override some of the methods.\n */\n\nGLOBAL(struct jpeg_error_mgr *)\njpeg_std_error (struct jpeg_error_mgr * err)\n{\n  err->error_exit = error_exit;\n  err->emit_message = emit_message;\n  err->output_message = output_message;\n  err->format_message = format_message;\n  err->reset_error_mgr = reset_error_mgr;\n\n  err->trace_level = 0;\t\t/* default = no tracing */\n  err->num_warnings = 0;\t/* no warnings emitted yet */\n  err->msg_code = 0;\t\t/* may be useful as a flag for \"no error\" */\n\n  /* Initialize message table pointers */\n  err->jpeg_message_table = jpeg_std_message_table;\n  err->last_jpeg_message = (int) JMSG_LASTMSGCODE - 1;\n\n  err->addon_message_table = NULL;\n  err->first_addon_message = 0;\t/* for safety */\n  err->last_addon_message = 0;\n\n  return err;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jerror.h",
    "content": "/*\n * jerror.h\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 1997-2012 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file defines the error and message codes for the JPEG library.\n * Edit this file to add new codes, or to translate the message strings to\n * some other language.\n * A set of error-reporting macros are defined too.  Some applications using\n * the JPEG library may wish to include this file to get the error codes\n * and/or the macros.\n */\n\n/*\n * To define the enum list of message codes, include this file without\n * defining macro JMESSAGE.  To create a message string table, include it\n * again with a suitable JMESSAGE definition (see jerror.c for an example).\n */\n#ifndef JMESSAGE\n#ifndef JERROR_H\n/* First time through, define the enum list */\n#define JMAKE_ENUM_LIST\n#else\n/* Repeated inclusions of this file are no-ops unless JMESSAGE is defined */\n#define JMESSAGE(code,string)\n#endif /* JERROR_H */\n#endif /* JMESSAGE */\n\n#ifdef JMAKE_ENUM_LIST\n\ntypedef enum {\n\n#define JMESSAGE(code,string)\tcode ,\n\n#endif /* JMAKE_ENUM_LIST */\n\nJMESSAGE(JMSG_NOMESSAGE, \"Bogus message code %d\") /* Must be first entry! */\n\n/* For maintenance convenience, list is alphabetical by message code name */\nJMESSAGE(JERR_BAD_ALIGN_TYPE, \"ALIGN_TYPE is wrong, please fix\")\nJMESSAGE(JERR_BAD_ALLOC_CHUNK, \"MAX_ALLOC_CHUNK is wrong, please fix\")\nJMESSAGE(JERR_BAD_BUFFER_MODE, \"Bogus buffer control mode\")\nJMESSAGE(JERR_BAD_COMPONENT_ID, \"Invalid component ID %d in SOS\")\nJMESSAGE(JERR_BAD_CROP_SPEC, \"Invalid crop request\")\nJMESSAGE(JERR_BAD_DCT_COEF, \"DCT coefficient out of range\")\nJMESSAGE(JERR_BAD_DCTSIZE, \"DCT scaled block size %dx%d not supported\")\nJMESSAGE(JERR_BAD_DROP_SAMPLING,\n\t \"Component index %d: mismatching sampling ratio %d:%d, %d:%d, %c\")\nJMESSAGE(JERR_BAD_HUFF_TABLE, \"Bogus Huffman table definition\")\nJMESSAGE(JERR_BAD_IN_COLORSPACE, \"Bogus input colorspace\")\nJMESSAGE(JERR_BAD_J_COLORSPACE, \"Bogus JPEG colorspace\")\nJMESSAGE(JERR_BAD_LENGTH, \"Bogus marker length\")\nJMESSAGE(JERR_BAD_LIB_VERSION,\n\t \"Wrong JPEG library version: library is %d, caller expects %d\")\nJMESSAGE(JERR_BAD_MCU_SIZE, \"Sampling factors too large for interleaved scan\")\nJMESSAGE(JERR_BAD_POOL_ID, \"Invalid memory pool code %d\")\nJMESSAGE(JERR_BAD_PRECISION, \"Unsupported JPEG data precision %d\")\nJMESSAGE(JERR_BAD_PROGRESSION,\n\t \"Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d\")\nJMESSAGE(JERR_BAD_PROG_SCRIPT,\n\t \"Invalid progressive parameters at scan script entry %d\")\nJMESSAGE(JERR_BAD_SAMPLING, \"Bogus sampling factors\")\nJMESSAGE(JERR_BAD_SCAN_SCRIPT, \"Invalid scan script at entry %d\")\nJMESSAGE(JERR_BAD_STATE, \"Improper call to JPEG library in state %d\")\nJMESSAGE(JERR_BAD_STRUCT_SIZE,\n\t \"JPEG parameter struct mismatch: library thinks size is %u, caller expects %u\")\nJMESSAGE(JERR_BAD_VIRTUAL_ACCESS, \"Bogus virtual array access\")\nJMESSAGE(JERR_BUFFER_SIZE, \"Buffer passed to JPEG library is too small\")\nJMESSAGE(JERR_CANT_SUSPEND, \"Suspension not allowed here\")\nJMESSAGE(JERR_CCIR601_NOTIMPL, \"CCIR601 sampling not implemented yet\")\nJMESSAGE(JERR_COMPONENT_COUNT, \"Too many color components: %d, max %d\")\nJMESSAGE(JERR_CONVERSION_NOTIMPL, \"Unsupported color conversion request\")\nJMESSAGE(JERR_DAC_INDEX, \"Bogus DAC index %d\")\nJMESSAGE(JERR_DAC_VALUE, \"Bogus DAC value 0x%x\")\nJMESSAGE(JERR_DHT_INDEX, \"Bogus DHT index %d\")\nJMESSAGE(JERR_DQT_INDEX, \"Bogus DQT index %d\")\nJMESSAGE(JERR_EMPTY_IMAGE, \"Empty JPEG image (DNL not supported)\")\nJMESSAGE(JERR_EMS_READ, \"Read from EMS failed\")\nJMESSAGE(JERR_EMS_WRITE, \"Write to EMS failed\")\nJMESSAGE(JERR_EOI_EXPECTED, \"Didn't expect more than one scan\")\nJMESSAGE(JERR_FILE_READ, \"Input file read error\")\nJMESSAGE(JERR_FILE_WRITE, \"Output file write error --- out of disk space?\")\nJMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, \"Fractional sampling not implemented yet\")\nJMESSAGE(JERR_HUFF_CLEN_OVERFLOW, \"Huffman code size table overflow\")\nJMESSAGE(JERR_HUFF_MISSING_CODE, \"Missing Huffman code table entry\")\nJMESSAGE(JERR_IMAGE_TOO_BIG, \"Maximum supported image dimension is %u pixels\")\nJMESSAGE(JERR_INPUT_EMPTY, \"Empty input file\")\nJMESSAGE(JERR_INPUT_EOF, \"Premature end of input file\")\nJMESSAGE(JERR_MISMATCHED_QUANT_TABLE,\n\t \"Cannot transcode due to multiple use of quantization table %d\")\nJMESSAGE(JERR_MISSING_DATA, \"Scan script does not transmit all data\")\nJMESSAGE(JERR_MODE_CHANGE, \"Invalid color quantization mode change\")\nJMESSAGE(JERR_NOTIMPL, \"Not implemented yet\")\nJMESSAGE(JERR_NOT_COMPILED, \"Requested feature was omitted at compile time\")\nJMESSAGE(JERR_NO_ARITH_TABLE, \"Arithmetic table 0x%02x was not defined\")\nJMESSAGE(JERR_NO_BACKING_STORE, \"Backing store not supported\")\nJMESSAGE(JERR_NO_HUFF_TABLE, \"Huffman table 0x%02x was not defined\")\nJMESSAGE(JERR_NO_IMAGE, \"JPEG datastream contains no image\")\nJMESSAGE(JERR_NO_QUANT_TABLE, \"Quantization table 0x%02x was not defined\")\nJMESSAGE(JERR_NO_SOI, \"Not a JPEG file: starts with 0x%02x 0x%02x\")\nJMESSAGE(JERR_OUT_OF_MEMORY, \"Insufficient memory (case %d)\")\nJMESSAGE(JERR_QUANT_COMPONENTS,\n\t \"Cannot quantize more than %d color components\")\nJMESSAGE(JERR_QUANT_FEW_COLORS, \"Cannot quantize to fewer than %d colors\")\nJMESSAGE(JERR_QUANT_MANY_COLORS, \"Cannot quantize to more than %d colors\")\nJMESSAGE(JERR_SOF_BEFORE, \"Invalid JPEG file structure: %s before SOF\")\nJMESSAGE(JERR_SOF_DUPLICATE, \"Invalid JPEG file structure: two SOF markers\")\nJMESSAGE(JERR_SOF_NO_SOS, \"Invalid JPEG file structure: missing SOS marker\")\nJMESSAGE(JERR_SOF_UNSUPPORTED, \"Unsupported JPEG process: SOF type 0x%02x\")\nJMESSAGE(JERR_SOI_DUPLICATE, \"Invalid JPEG file structure: two SOI markers\")\nJMESSAGE(JERR_TFILE_CREATE, \"Failed to create temporary file %s\")\nJMESSAGE(JERR_TFILE_READ, \"Read failed on temporary file\")\nJMESSAGE(JERR_TFILE_SEEK, \"Seek failed on temporary file\")\nJMESSAGE(JERR_TFILE_WRITE,\n\t \"Write failed on temporary file --- out of disk space?\")\nJMESSAGE(JERR_TOO_LITTLE_DATA, \"Application transferred too few scanlines\")\nJMESSAGE(JERR_UNKNOWN_MARKER, \"Unsupported marker type 0x%02x\")\nJMESSAGE(JERR_VIRTUAL_BUG, \"Virtual array controller messed up\")\nJMESSAGE(JERR_WIDTH_OVERFLOW, \"Image too wide for this implementation\")\nJMESSAGE(JERR_XMS_READ, \"Read from XMS failed\")\nJMESSAGE(JERR_XMS_WRITE, \"Write to XMS failed\")\nJMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)\nJMESSAGE(JMSG_VERSION, JVERSION)\nJMESSAGE(JTRC_16BIT_TABLES,\n\t \"Caution: quantization tables are too coarse for baseline JPEG\")\nJMESSAGE(JTRC_ADOBE,\n\t \"Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d\")\nJMESSAGE(JTRC_APP0, \"Unknown APP0 marker (not JFIF), length %u\")\nJMESSAGE(JTRC_APP14, \"Unknown APP14 marker (not Adobe), length %u\")\nJMESSAGE(JTRC_DAC, \"Define Arithmetic Table 0x%02x: 0x%02x\")\nJMESSAGE(JTRC_DHT, \"Define Huffman Table 0x%02x\")\nJMESSAGE(JTRC_DQT, \"Define Quantization Table %d  precision %d\")\nJMESSAGE(JTRC_DRI, \"Define Restart Interval %u\")\nJMESSAGE(JTRC_EMS_CLOSE, \"Freed EMS handle %u\")\nJMESSAGE(JTRC_EMS_OPEN, \"Obtained EMS handle %u\")\nJMESSAGE(JTRC_EOI, \"End Of Image\")\nJMESSAGE(JTRC_HUFFBITS, \"        %3d %3d %3d %3d %3d %3d %3d %3d\")\nJMESSAGE(JTRC_JFIF, \"JFIF APP0 marker: version %d.%02d, density %dx%d  %d\")\nJMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,\n\t \"Warning: thumbnail image size does not match data length %u\")\nJMESSAGE(JTRC_JFIF_EXTENSION,\n\t \"JFIF extension marker: type 0x%02x, length %u\")\nJMESSAGE(JTRC_JFIF_THUMBNAIL, \"    with %d x %d thumbnail image\")\nJMESSAGE(JTRC_MISC_MARKER, \"Miscellaneous marker 0x%02x, length %u\")\nJMESSAGE(JTRC_PARMLESS_MARKER, \"Unexpected marker 0x%02x\")\nJMESSAGE(JTRC_QUANTVALS, \"        %4u %4u %4u %4u %4u %4u %4u %4u\")\nJMESSAGE(JTRC_QUANT_3_NCOLORS, \"Quantizing to %d = %d*%d*%d colors\")\nJMESSAGE(JTRC_QUANT_NCOLORS, \"Quantizing to %d colors\")\nJMESSAGE(JTRC_QUANT_SELECTED, \"Selected %d colors for quantization\")\nJMESSAGE(JTRC_RECOVERY_ACTION, \"At marker 0x%02x, recovery action %d\")\nJMESSAGE(JTRC_RST, \"RST%d\")\nJMESSAGE(JTRC_SMOOTH_NOTIMPL,\n\t \"Smoothing not supported with nonstandard sampling ratios\")\nJMESSAGE(JTRC_SOF, \"Start Of Frame 0x%02x: width=%u, height=%u, components=%d\")\nJMESSAGE(JTRC_SOF_COMPONENT, \"    Component %d: %dhx%dv q=%d\")\nJMESSAGE(JTRC_SOI, \"Start of Image\")\nJMESSAGE(JTRC_SOS, \"Start Of Scan: %d components\")\nJMESSAGE(JTRC_SOS_COMPONENT, \"    Component %d: dc=%d ac=%d\")\nJMESSAGE(JTRC_SOS_PARAMS, \"  Ss=%d, Se=%d, Ah=%d, Al=%d\")\nJMESSAGE(JTRC_TFILE_CLOSE, \"Closed temporary file %s\")\nJMESSAGE(JTRC_TFILE_OPEN, \"Opened temporary file %s\")\nJMESSAGE(JTRC_THUMB_JPEG,\n\t \"JFIF extension marker: JPEG-compressed thumbnail image, length %u\")\nJMESSAGE(JTRC_THUMB_PALETTE,\n\t \"JFIF extension marker: palette thumbnail image, length %u\")\nJMESSAGE(JTRC_THUMB_RGB,\n\t \"JFIF extension marker: RGB thumbnail image, length %u\")\nJMESSAGE(JTRC_UNKNOWN_IDS,\n\t \"Unrecognized component IDs %d %d %d, assuming YCbCr\")\nJMESSAGE(JTRC_XMS_CLOSE, \"Freed XMS handle %u\")\nJMESSAGE(JTRC_XMS_OPEN, \"Obtained XMS handle %u\")\nJMESSAGE(JWRN_ADOBE_XFORM, \"Unknown Adobe color transform code %d\")\nJMESSAGE(JWRN_ARITH_BAD_CODE, \"Corrupt JPEG data: bad arithmetic code\")\nJMESSAGE(JWRN_BOGUS_PROGRESSION,\n\t \"Inconsistent progression sequence for component %d coefficient %d\")\nJMESSAGE(JWRN_EXTRANEOUS_DATA,\n\t \"Corrupt JPEG data: %u extraneous bytes before marker 0x%02x\")\nJMESSAGE(JWRN_HIT_MARKER, \"Corrupt JPEG data: premature end of data segment\")\nJMESSAGE(JWRN_HUFF_BAD_CODE, \"Corrupt JPEG data: bad Huffman code\")\nJMESSAGE(JWRN_JFIF_MAJOR, \"Warning: unknown JFIF revision number %d.%02d\")\nJMESSAGE(JWRN_JPEG_EOF, \"Premature end of JPEG file\")\nJMESSAGE(JWRN_MUST_RESYNC,\n\t \"Corrupt JPEG data: found marker 0x%02x instead of RST%d\")\nJMESSAGE(JWRN_NOT_SEQUENTIAL, \"Invalid SOS parameters for sequential JPEG\")\nJMESSAGE(JWRN_TOO_MUCH_DATA, \"Application transferred too many scanlines\")\n\n#ifdef JMAKE_ENUM_LIST\n\n  JMSG_LASTMSGCODE\n} J_MESSAGE_CODE;\n\n#undef JMAKE_ENUM_LIST\n#endif /* JMAKE_ENUM_LIST */\n\n/* Zap JMESSAGE macro so that future re-inclusions do nothing by default */\n#undef JMESSAGE\n\n\n#ifndef JERROR_H\n#define JERROR_H\n\n/* Macros to simplify using the error and trace message stuff */\n/* The first parameter is either type of cinfo pointer */\n\n/* Fatal errors (print message and exit) */\n#define ERREXIT(cinfo,code)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXIT1(cinfo,code,p1)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXIT2(cinfo,code,p1,p2)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXIT3(cinfo,code,p1,p2,p3)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (cinfo)->err->msg_parm.i[2] = (p3), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXIT4(cinfo,code,p1,p2,p3,p4)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (cinfo)->err->msg_parm.i[2] = (p3), \\\n   (cinfo)->err->msg_parm.i[3] = (p4), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXIT6(cinfo,code,p1,p2,p3,p4,p5,p6)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (cinfo)->err->msg_parm.i[2] = (p3), \\\n   (cinfo)->err->msg_parm.i[3] = (p4), \\\n   (cinfo)->err->msg_parm.i[4] = (p5), \\\n   (cinfo)->err->msg_parm.i[5] = (p6), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n#define ERREXITS(cinfo,code,str)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \\\n   (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))\n\n#define MAKESTMT(stuff)\t\tdo { stuff } while (0)\n\n/* Nonfatal errors (we can keep going, but the data is probably corrupt) */\n#define WARNMS(cinfo,code)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))\n#define WARNMS1(cinfo,code,p1)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))\n#define WARNMS2(cinfo,code,p1,p2)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))\n\n/* Informational/debugging messages */\n#define TRACEMS(cinfo,lvl,code)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))\n#define TRACEMS1(cinfo,lvl,code,p1)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))\n#define TRACEMS2(cinfo,lvl,code,p1,p2)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   (cinfo)->err->msg_parm.i[0] = (p1), \\\n   (cinfo)->err->msg_parm.i[1] = (p2), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))\n#define TRACEMS3(cinfo,lvl,code,p1,p2,p3)  \\\n  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \\\n\t   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \\\n\t   (cinfo)->err->msg_code = (code); \\\n\t   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )\n#define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4)  \\\n  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \\\n\t   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \\\n\t   (cinfo)->err->msg_code = (code); \\\n\t   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )\n#define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5)  \\\n  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \\\n\t   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \\\n\t   _mp[4] = (p5); \\\n\t   (cinfo)->err->msg_code = (code); \\\n\t   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )\n#define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8)  \\\n  MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \\\n\t   _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \\\n\t   _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \\\n\t   (cinfo)->err->msg_code = (code); \\\n\t   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )\n#define TRACEMSS(cinfo,lvl,code,str)  \\\n  ((cinfo)->err->msg_code = (code), \\\n   strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \\\n   (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))\n\n#endif /* JERROR_H */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jfdctflt.c",
    "content": "/*\n * jfdctflt.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2003-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a floating-point implementation of the\n * forward DCT (Discrete Cosine Transform).\n *\n * This implementation should be more accurate than either of the integer\n * DCT implementations.  However, it may not give the same results on all\n * machines because of differences in roundoff behavior.  Speed will depend\n * on the hardware's floating point capacity.\n *\n * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT\n * on each column.  Direct algorithms are also available, but they are\n * much more complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on Arai, Agui, and Nakajima's algorithm for\n * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in\n * Japanese, but the algorithm is described in the Pennebaker & Mitchell\n * JPEG textbook (see REFERENCES section in file README).  The following code\n * is based directly on figure 4-8 in P&M.\n * While an 8-point DCT cannot be done in less than 11 multiplies, it is\n * possible to arrange the computation so that many of the multiplies are\n * simple scalings of the final outputs.  These multiplies can then be\n * folded into the multiplications or divisions by the JPEG quantization\n * table entries.  The AA&N method leaves only 5 multiplies and 29 adds\n * to be done in the DCT itself.\n * The primary disadvantage of this method is that with a fixed-point\n * implementation, accuracy is lost due to imprecise representation of the\n * scaled quantization values.  However, that problem does not arise if\n * we use floating point arithmetic.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_FLOAT_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */\n#endif\n\n\n/*\n * Perform the forward DCT on one block of samples.\n *\n * cK represents cos(K*pi/16).\n */\n\nGLOBAL(void)\njpeg_fdct_float (FAST_FLOAT * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  FAST_FLOAT tmp10, tmp11, tmp12, tmp13;\n  FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;\n  FAST_FLOAT *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n\n  /* Pass 1: process rows. */\n\n  dataptr = data;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Load data into workspace */\n    tmp0 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]));\n    tmp7 = (FAST_FLOAT) (GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]));\n    tmp1 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]));\n    tmp6 = (FAST_FLOAT) (GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]));\n    tmp2 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]));\n    tmp5 = (FAST_FLOAT) (GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]));\n    tmp3 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]));\n    tmp4 = (FAST_FLOAT) (GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]));\n\n    /* Even part */\n\n    tmp10 = tmp0 + tmp3;\t/* phase 2 */\n    tmp13 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp12 = tmp1 - tmp2;\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */\n    dataptr[4] = tmp10 - tmp11;\n\n    z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */\n    dataptr[2] = tmp13 + z1;\t/* phase 5 */\n    dataptr[6] = tmp13 - z1;\n\n    /* Odd part */\n\n    tmp10 = tmp4 + tmp5;\t/* phase 2 */\n    tmp11 = tmp5 + tmp6;\n    tmp12 = tmp6 + tmp7;\n\n    /* The rotator is modified from fig 4-8 to avoid extra negations. */\n    z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */\n    z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */\n    z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */\n    z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */\n\n    z11 = tmp7 + z3;\t\t/* phase 5 */\n    z13 = tmp7 - z3;\n\n    dataptr[5] = z13 + z2;\t/* phase 6 */\n    dataptr[3] = z13 - z2;\n    dataptr[1] = z11 + z4;\n    dataptr[7] = z11 - z4;\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns. */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];\n    tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];\n    tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];\n    tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];\n\n    /* Even part */\n\n    tmp10 = tmp0 + tmp3;\t/* phase 2 */\n    tmp13 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp12 = tmp1 - tmp2;\n\n    dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */\n    dataptr[DCTSIZE*4] = tmp10 - tmp11;\n\n    z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */\n    dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */\n    dataptr[DCTSIZE*6] = tmp13 - z1;\n\n    /* Odd part */\n\n    tmp10 = tmp4 + tmp5;\t/* phase 2 */\n    tmp11 = tmp5 + tmp6;\n    tmp12 = tmp6 + tmp7;\n\n    /* The rotator is modified from fig 4-8 to avoid extra negations. */\n    z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */\n    z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */\n    z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */\n    z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */\n\n    z11 = tmp7 + z3;\t\t/* phase 5 */\n    z13 = tmp7 - z3;\n\n    dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */\n    dataptr[DCTSIZE*3] = z13 - z2;\n    dataptr[DCTSIZE*1] = z11 + z4;\n    dataptr[DCTSIZE*7] = z11 - z4;\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n#endif /* DCT_FLOAT_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jfdctfst.c",
    "content": "/*\n * jfdctfst.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2003-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a fast, not so accurate integer implementation of the\n * forward DCT (Discrete Cosine Transform).\n *\n * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT\n * on each column.  Direct algorithms are also available, but they are\n * much more complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on Arai, Agui, and Nakajima's algorithm for\n * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in\n * Japanese, but the algorithm is described in the Pennebaker & Mitchell\n * JPEG textbook (see REFERENCES section in file README).  The following code\n * is based directly on figure 4-8 in P&M.\n * While an 8-point DCT cannot be done in less than 11 multiplies, it is\n * possible to arrange the computation so that many of the multiplies are\n * simple scalings of the final outputs.  These multiplies can then be\n * folded into the multiplications or divisions by the JPEG quantization\n * table entries.  The AA&N method leaves only 5 multiplies and 29 adds\n * to be done in the DCT itself.\n * The primary disadvantage of this method is that with fixed-point math,\n * accuracy is lost due to imprecise representation of the scaled\n * quantization values.  The smaller the quantization table entry, the less\n * precise the scaled value, so this implementation does worse with high-\n * quality-setting files than with low-quality ones.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_IFAST_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */\n#endif\n\n\n/* Scaling decisions are generally the same as in the LL&M algorithm;\n * see jfdctint.c for more details.  However, we choose to descale\n * (right shift) multiplication products as soon as they are formed,\n * rather than carrying additional fractional bits into subsequent additions.\n * This compromises accuracy slightly, but it lets us save a few shifts.\n * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)\n * everywhere except in the multiplications proper; this saves a good deal\n * of work on 16-bit-int machines.\n *\n * Again to save a few shifts, the intermediate results between pass 1 and\n * pass 2 are not upscaled, but are represented only to integral precision.\n *\n * A final compromise is to represent the multiplicative constants to only\n * 8 fractional bits, rather than 13.  This saves some shifting work on some\n * machines, and may also reduce the cost of multiplication (since there\n * are fewer one-bits in the constants).\n */\n\n#define CONST_BITS  8\n\n\n/* Some C compilers fail to reduce \"FIX(constant)\" at compile time, thus\n * causing a lot of useless floating-point operations at run time.\n * To get around this we use the following pre-calculated constants.\n * If you change CONST_BITS you may want to add appropriate values.\n * (With a reasonable C compiler, you can just rely on the FIX() macro...)\n */\n\n#if CONST_BITS == 8\n#define FIX_0_382683433  ((INT32)   98)\t\t/* FIX(0.382683433) */\n#define FIX_0_541196100  ((INT32)  139)\t\t/* FIX(0.541196100) */\n#define FIX_0_707106781  ((INT32)  181)\t\t/* FIX(0.707106781) */\n#define FIX_1_306562965  ((INT32)  334)\t\t/* FIX(1.306562965) */\n#else\n#define FIX_0_382683433  FIX(0.382683433)\n#define FIX_0_541196100  FIX(0.541196100)\n#define FIX_0_707106781  FIX(0.707106781)\n#define FIX_1_306562965  FIX(1.306562965)\n#endif\n\n\n/* We can gain a little more speed, with a further compromise in accuracy,\n * by omitting the addition in a descaling shift.  This yields an incorrectly\n * rounded result half the time...\n */\n\n#ifndef USE_ACCURATE_ROUNDING\n#undef DESCALE\n#define DESCALE(x,n)  RIGHT_SHIFT(x, n)\n#endif\n\n\n/* Multiply a DCTELEM variable by an INT32 constant, and immediately\n * descale to yield a DCTELEM result.\n */\n\n#define MULTIPLY(var,const)  ((DCTELEM) DESCALE((var) * (const), CONST_BITS))\n\n\n/*\n * Perform the forward DCT on one block of samples.\n *\n * cK represents cos(K*pi/16).\n */\n\nGLOBAL(void)\njpeg_fdct_ifast (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  DCTELEM tmp10, tmp11, tmp12, tmp13;\n  DCTELEM z1, z2, z3, z4, z5, z11, z13;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows. */\n\n  dataptr = data;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Load data into workspace */\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);\n    tmp7 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);\n    tmp6 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);\n    tmp5 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);\n    tmp4 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);\n\n    /* Even part */\n\n    tmp10 = tmp0 + tmp3;\t/* phase 2 */\n    tmp13 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp12 = tmp1 - tmp2;\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = tmp10 + tmp11 - 8 * CENTERJSAMPLE; /* phase 3 */\n    dataptr[4] = tmp10 - tmp11;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */\n    dataptr[2] = tmp13 + z1;\t/* phase 5 */\n    dataptr[6] = tmp13 - z1;\n\n    /* Odd part */\n\n    tmp10 = tmp4 + tmp5;\t/* phase 2 */\n    tmp11 = tmp5 + tmp6;\n    tmp12 = tmp6 + tmp7;\n\n    /* The rotator is modified from fig 4-8 to avoid extra negations. */\n    z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */\n    z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */\n    z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */\n    z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */\n\n    z11 = tmp7 + z3;\t\t/* phase 5 */\n    z13 = tmp7 - z3;\n\n    dataptr[5] = z13 + z2;\t/* phase 6 */\n    dataptr[3] = z13 - z2;\n    dataptr[1] = z11 + z4;\n    dataptr[7] = z11 - z4;\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns. */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];\n    tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];\n    tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];\n    tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];\n\n    /* Even part */\n\n    tmp10 = tmp0 + tmp3;\t/* phase 2 */\n    tmp13 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp12 = tmp1 - tmp2;\n\n    dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */\n    dataptr[DCTSIZE*4] = tmp10 - tmp11;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */\n    dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */\n    dataptr[DCTSIZE*6] = tmp13 - z1;\n\n    /* Odd part */\n\n    tmp10 = tmp4 + tmp5;\t/* phase 2 */\n    tmp11 = tmp5 + tmp6;\n    tmp12 = tmp6 + tmp7;\n\n    /* The rotator is modified from fig 4-8 to avoid extra negations. */\n    z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */\n    z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */\n    z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */\n    z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */\n\n    z11 = tmp7 + z3;\t\t/* phase 5 */\n    z13 = tmp7 - z3;\n\n    dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */\n    dataptr[DCTSIZE*3] = z13 - z2;\n    dataptr[DCTSIZE*1] = z11 + z4;\n    dataptr[DCTSIZE*7] = z11 - z4;\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n#endif /* DCT_IFAST_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jfdctint.c",
    "content": "/*\n * jfdctint.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modification developed 2003-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a slow-but-accurate integer implementation of the\n * forward DCT (Discrete Cosine Transform).\n *\n * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT\n * on each column.  Direct algorithms are also available, but they are\n * much more complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on an algorithm described in\n *   C. Loeffler, A. Ligtenberg and G. Moschytz, \"Practical Fast 1-D DCT\n *   Algorithms with 11 Multiplications\", Proc. Int'l. Conf. on Acoustics,\n *   Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.\n * The primary algorithm described there uses 11 multiplies and 29 adds.\n * We use their alternate method with 12 multiplies and 32 adds.\n * The advantage of this method is that no data path contains more than one\n * multiplication; this allows a very simple and accurate implementation in\n * scaled fixed-point arithmetic, with a minimal number of shifts.\n *\n * We also provide FDCT routines with various input sample block sizes for\n * direct resolution reduction or enlargement and for direct resolving the\n * common 2x1 and 1x2 subsampling cases without additional resampling: NxN\n * (N=1...16), 2NxN, and Nx2N (N=1...8) pixels for one 8x8 output DCT block.\n *\n * For N<8 we fill the remaining block coefficients with zero.\n * For N>8 we apply a partial N-point FDCT on the input samples, computing\n * just the lower 8 frequency coefficients and discarding the rest.\n *\n * We must scale the output coefficients of the N-point FDCT appropriately\n * to the standard 8-point FDCT level by 8/N per 1-D pass.  This scaling\n * is folded into the constant multipliers (pass 2) and/or final/initial\n * shifting.\n *\n * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases\n * since there would be too many additional constants to pre-calculate.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_ISLOW_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */\n#endif\n\n\n/*\n * The poop on this scaling stuff is as follows:\n *\n * Each 1-D DCT step produces outputs which are a factor of sqrt(N)\n * larger than the true DCT outputs.  The final outputs are therefore\n * a factor of N larger than desired; since N=8 this can be cured by\n * a simple right shift at the end of the algorithm.  The advantage of\n * this arrangement is that we save two multiplications per 1-D DCT,\n * because the y0 and y4 outputs need not be divided by sqrt(N).\n * In the IJG code, this factor of 8 is removed by the quantization step\n * (in jcdctmgr.c), NOT in this module.\n *\n * We have to do addition and subtraction of the integer inputs, which\n * is no problem, and multiplication by fractional constants, which is\n * a problem to do in integer arithmetic.  We multiply all the constants\n * by CONST_SCALE and convert them to integer constants (thus retaining\n * CONST_BITS bits of precision in the constants).  After doing a\n * multiplication we have to divide the product by CONST_SCALE, with proper\n * rounding, to produce the correct output.  This division can be done\n * cheaply as a right shift of CONST_BITS bits.  We postpone shifting\n * as long as possible so that partial sums can be added together with\n * full fractional precision.\n *\n * The outputs of the first pass are scaled up by PASS1_BITS bits so that\n * they are represented to better-than-integral precision.  These outputs\n * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word\n * with the recommended scaling.  (For 12-bit sample data, the intermediate\n * array is INT32 anyway.)\n *\n * To avoid overflow of the 32-bit intermediate results in pass 2, we must\n * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26.  Error analysis\n * shows that the values given below are the most effective.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define CONST_BITS  13\n#define PASS1_BITS  2\n#else\n#define CONST_BITS  13\n#define PASS1_BITS  1\t\t/* lose a little precision to avoid overflow */\n#endif\n\n/* Some C compilers fail to reduce \"FIX(constant)\" at compile time, thus\n * causing a lot of useless floating-point operations at run time.\n * To get around this we use the following pre-calculated constants.\n * If you change CONST_BITS you may want to add appropriate values.\n * (With a reasonable C compiler, you can just rely on the FIX() macro...)\n */\n\n#if CONST_BITS == 13\n#define FIX_0_298631336  ((INT32)  2446)\t/* FIX(0.298631336) */\n#define FIX_0_390180644  ((INT32)  3196)\t/* FIX(0.390180644) */\n#define FIX_0_541196100  ((INT32)  4433)\t/* FIX(0.541196100) */\n#define FIX_0_765366865  ((INT32)  6270)\t/* FIX(0.765366865) */\n#define FIX_0_899976223  ((INT32)  7373)\t/* FIX(0.899976223) */\n#define FIX_1_175875602  ((INT32)  9633)\t/* FIX(1.175875602) */\n#define FIX_1_501321110  ((INT32)  12299)\t/* FIX(1.501321110) */\n#define FIX_1_847759065  ((INT32)  15137)\t/* FIX(1.847759065) */\n#define FIX_1_961570560  ((INT32)  16069)\t/* FIX(1.961570560) */\n#define FIX_2_053119869  ((INT32)  16819)\t/* FIX(2.053119869) */\n#define FIX_2_562915447  ((INT32)  20995)\t/* FIX(2.562915447) */\n#define FIX_3_072711026  ((INT32)  25172)\t/* FIX(3.072711026) */\n#else\n#define FIX_0_298631336  FIX(0.298631336)\n#define FIX_0_390180644  FIX(0.390180644)\n#define FIX_0_541196100  FIX(0.541196100)\n#define FIX_0_765366865  FIX(0.765366865)\n#define FIX_0_899976223  FIX(0.899976223)\n#define FIX_1_175875602  FIX(1.175875602)\n#define FIX_1_501321110  FIX(1.501321110)\n#define FIX_1_847759065  FIX(1.847759065)\n#define FIX_1_961570560  FIX(1.961570560)\n#define FIX_2_053119869  FIX(2.053119869)\n#define FIX_2_562915447  FIX(2.562915447)\n#define FIX_3_072711026  FIX(3.072711026)\n#endif\n\n\n/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.\n * For 8-bit samples with the recommended scaling, all the variable\n * and constant values involved are no more than 16 bits wide, so a\n * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.\n * For 12-bit samples, a full 32-bit multiplication will be needed.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define MULTIPLY(var,const)  MULTIPLY16C16(var,const)\n#else\n#define MULTIPLY(var,const)  ((var) * (const))\n#endif\n\n\n/*\n * Perform the forward DCT on one block of samples.\n */\n\nGLOBAL(void)\njpeg_fdct_islow (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);\n\n    tmp10 = tmp0 + tmp3;\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    dataptr[2] = (DCTELEM)\n      RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS-PASS1_BITS);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);       /*  c3 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);          /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);          /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);       /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);              /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);              /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);       /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);              /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);              /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];\n\n    /* Add fudge factor here for final descale. */\n    tmp10 = tmp0 + tmp3 + (ONE << (PASS1_BITS-1));\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp10 + tmp11, PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM) RIGHT_SHIFT(tmp10 - tmp11, PASS1_BITS);\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);       /*  c3 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);          /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);          /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);       /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);              /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);              /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);       /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);              /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);              /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n#ifdef DCT_SCALING_SUPPORTED\n\n\n/*\n * Perform the forward DCT on a 7x7 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_7x7 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12;\n  INT32 z1, z2, z3;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * cK represents sqrt(2) * cos(K*pi/14).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 7; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[6]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[5]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);\n    tmp3 = GETJSAMPLE(elemptr[3]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);\n\n    z1 = tmp0 + tmp2;\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);\n    tmp3 += tmp3;\n    z1 -= tmp3;\n    z1 -= tmp3;\n    z1 = MULTIPLY(z1, FIX(0.353553391));                /* (c2+c6-c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002));       /* (c2+c4-c6)/2 */\n    z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123));       /* c6 */\n    dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);\n    z1 -= z2;\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734));       /* c4 */\n    dataptr[4] = (DCTELEM)\n      DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347));   /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339));   /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */\n    tmp1 += tmp2;\n    tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268));   /* c5 */\n    tmp0 += tmp3;\n    tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693));   /* c3+c1-c5 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/7)**2 = 64/49, which we fold\n   * into the constant multipliers:\n   * cK now represents sqrt(2) * cos(K*pi/14) * 64/49.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 7; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];\n    tmp3 = dataptr[DCTSIZE*3];\n\n    tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];\n    tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];\n\n    z1 = tmp0 + tmp2;\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp3 += tmp3;\n    z1 -= tmp3;\n    z1 -= tmp3;\n    z1 = MULTIPLY(z1, FIX(0.461784020));                /* (c2+c6-c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084));       /* (c2+c4-c6)/2 */\n    z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446));       /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS);\n    z1 -= z2;\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509));       /* c4 */\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677));   /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464));   /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */\n    tmp1 += tmp2;\n    tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310));   /* c5 */\n    tmp0 += tmp3;\n    tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355));   /* c3+c1-c5 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 6x6 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_6x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2;\n  INT32 tmp10, tmp11, tmp12;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 6; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);\n    tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(1.224744871)),                 /* c2 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)),     /* c5 */\n\t\t    CONST_BITS-PASS1_BITS);\n\n    dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));\n    dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);\n    dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/6)**2 = 16/9, which we fold\n   * into the constant multipliers:\n   * cK now represents sqrt(2) * cos(K*pi/12) * 16/9.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 6; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];\n    tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)),         /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(2.177324216)),                 /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829));             /* c5 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)),    /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 5x5 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_5x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2;\n  INT32 tmp10, tmp11;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * cK represents sqrt(2) * cos(K*pi/10).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 5; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);\n    tmp2 = GETJSAMPLE(elemptr[2]);\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << (PASS1_BITS+1));\n    tmp11 = MULTIPLY(tmp11, FIX(0.790569415));          /* (c2+c4)/2 */\n    tmp10 -= tmp2 << 2;\n    tmp10 = MULTIPLY(tmp10, FIX(0.353553391));          /* (c2-c4)/2 */\n    dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS-1);\n    dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS-1);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876));    /* c3 */\n\n    dataptr[1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */\n\t      CONST_BITS-PASS1_BITS-1);\n    dataptr[3] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */\n\t      CONST_BITS-PASS1_BITS-1);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/5)**2 = 64/25, which we partially\n   * fold into the constant multipliers (other part was done in pass 1):\n   * cK now represents sqrt(2) * cos(K*pi/10) * 32/25.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 5; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];\n    tmp2 = dataptr[DCTSIZE*2];\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)),        /* 32/25 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp11 = MULTIPLY(tmp11, FIX(1.011928851));          /* (c2+c4)/2 */\n    tmp10 -= tmp2 << 2;\n    tmp10 = MULTIPLY(tmp10, FIX(0.452548340));          /* (c2-c4)/2 */\n    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961));    /* c3 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 4x4 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_4x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1;\n  INT32 tmp10, tmp11;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We must also scale the output by (8/4)**2 = 2**2, which we add here.\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+2));\n    dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+2));\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-3);\n\n    dataptr[1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS-PASS1_BITS-2);\n    dataptr[3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS-PASS1_BITS-2);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    /* Even part */\n\n    /* Add fudge factor here for final descale. */\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3] + (ONE << (PASS1_BITS-1));\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];\n\n    tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 3x3 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_3x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We scale the results further by 2**2 as part of output adaption\n   * scaling for different DCT size.\n   * cK represents sqrt(2) * cos(K*pi/6).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 3; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[2]);\n    tmp1 = GETJSAMPLE(elemptr[1]);\n\n    tmp2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[2]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 - 3 * CENTERJSAMPLE) << (PASS1_BITS+2));\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(0.707106781)), /* c2 */\n\t      CONST_BITS-PASS1_BITS-2);\n\n    /* Odd part */\n\n    dataptr[1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2, FIX(1.224744871)),               /* c1 */\n\t      CONST_BITS-PASS1_BITS-2);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/3)**2 = 64/9, which we partially\n   * fold into the constant multipliers (other part was done in pass 1):\n   * cK now represents sqrt(2) * cos(K*pi/6) * 16/9.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 3; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*2];\n    tmp1 = dataptr[DCTSIZE*1];\n\n    tmp2 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*2];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 + tmp1, FIX(1.777777778)),        /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(1.257078722)), /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2, FIX(2.177324216)),               /* c1 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 2x2 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_2x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  DCTELEM tmp0, tmp1, tmp2, tmp3;\n  JSAMPROW elemptr;\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   */\n\n  /* Row 0 */\n  elemptr = sample_data[0] + start_col;\n\n  tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[1]);\n  tmp1 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[1]);\n\n  /* Row 1 */\n  elemptr = sample_data[1] + start_col;\n\n  tmp2 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[1]);\n  tmp3 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[1]);\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/2)**2 = 2**4.\n   */\n\n  /* Column 0 */\n  /* Apply unsigned->signed conversion. */\n  data[DCTSIZE*0] = (tmp0 + tmp2 - 4 * CENTERJSAMPLE) << 4;\n  data[DCTSIZE*1] = (tmp0 - tmp2) << 4;\n\n  /* Column 1 */\n  data[DCTSIZE*0+1] = (tmp1 + tmp3) << 4;\n  data[DCTSIZE*1+1] = (tmp1 - tmp3) << 4;\n}\n\n\n/*\n * Perform the forward DCT on a 1x1 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_1x1 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  DCTELEM dcval;\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  dcval = GETJSAMPLE(sample_data[0][start_col]);\n\n  /* We leave the result scaled up by an overall factor of 8. */\n  /* We must also scale the output by (8/1)**2 = 2**6. */\n  /* Apply unsigned->signed conversion. */\n  data[0] = (dcval - CENTERJSAMPLE) << 6;\n}\n\n\n/*\n * Perform the forward DCT on a 9x9 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_9x9 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1, z2;\n  DCTELEM workspace[8];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * we scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * cK represents sqrt(2) * cos(K*pi/18).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[8]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[7]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[6]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[5]);\n    tmp4 = GETJSAMPLE(elemptr[4]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[8]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[7]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[6]);\n    tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[5]);\n\n    z1 = tmp0 + tmp2 + tmp3;\n    z2 = tmp1 + tmp4;\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) ((z1 + z2 - 9 * CENTERJSAMPLE) << 1);\n    dataptr[6] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 - z2 - z2, FIX(0.707106781)),  /* c6 */\n\t      CONST_BITS-1);\n    z1 = MULTIPLY(tmp0 - tmp2, FIX(1.328926049));        /* c2 */\n    z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(0.707106781)); /* c6 */\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.083350441))    /* c4 */\n\t      + z1 + z2, CONST_BITS-1);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.245575608))    /* c8 */\n\t      + z1 - z2, CONST_BITS-1);\n\n    /* Odd part */\n\n    dataptr[3] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.224744871)), /* c3 */\n\t      CONST_BITS-1);\n\n    tmp11 = MULTIPLY(tmp11, FIX(1.224744871));        /* c3 */\n    tmp0 = MULTIPLY(tmp10 + tmp12, FIX(0.909038955)); /* c5 */\n    tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.483689525)); /* c7 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS-1);\n\n    tmp2 = MULTIPLY(tmp12 - tmp13, FIX(1.392728481)); /* c1 */\n\n    dataptr[5] = (DCTELEM) DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS-1);\n    dataptr[7] = (DCTELEM) DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS-1);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 9)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/9)**2 = 64/81, which we partially\n   * fold into the constant multipliers and final/initial shifting:\n   * cK now represents sqrt(2) * cos(K*pi/18) * 128/81.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*0];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*7];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*6];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*5];\n    tmp4 = dataptr[DCTSIZE*4];\n\n    tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*0];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*7];\n    tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*6];\n    tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*5];\n\n    z1 = tmp0 + tmp2 + tmp3;\n    z2 = tmp1 + tmp4;\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 + z2, FIX(1.580246914)),       /* 128/81 */\n\t      CONST_BITS+2);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 - z2 - z2, FIX(1.117403309)),  /* c6 */\n\t      CONST_BITS+2);\n    z1 = MULTIPLY(tmp0 - tmp2, FIX(2.100031287));        /* c2 */\n    z2 = MULTIPLY(tmp1 - tmp4 - tmp4, FIX(1.117403309)); /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2 - tmp3, FIX(1.711961190))    /* c4 */\n\t      + z1 + z2, CONST_BITS+2);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp3 - tmp0, FIX(0.388070096))    /* c8 */\n\t      + z1 - z2, CONST_BITS+2);\n\n    /* Odd part */\n\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12 - tmp13, FIX(1.935399303)), /* c3 */\n\t      CONST_BITS+2);\n\n    tmp11 = MULTIPLY(tmp11, FIX(1.935399303));        /* c3 */\n    tmp0 = MULTIPLY(tmp10 + tmp12, FIX(1.436506004)); /* c5 */\n    tmp1 = MULTIPLY(tmp10 + tmp13, FIX(0.764348879)); /* c7 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp11 + tmp0 + tmp1, CONST_BITS+2);\n\n    tmp2 = MULTIPLY(tmp12 - tmp13, FIX(2.200854883)); /* c1 */\n\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp0 - tmp11 - tmp2, CONST_BITS+2);\n    dataptr[DCTSIZE*7] = (DCTELEM)\n      DESCALE(tmp1 - tmp11 + tmp2, CONST_BITS+2);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 10x10 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_10x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  DCTELEM workspace[8*2];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * we scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * cK represents sqrt(2) * cos(K*pi/20).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);\n    tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);\n\n    tmp10 = tmp0 + tmp4;\n    tmp13 = tmp0 - tmp4;\n    tmp11 = tmp1 + tmp3;\n    tmp14 = tmp1 - tmp3;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << 1);\n    tmp12 += tmp12;\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */\n\t      MULTIPLY(tmp11 - tmp12, FIX(0.437016024)),  /* c8 */\n\t      CONST_BITS-1);\n    tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876));    /* c6 */\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)),  /* c2-c6 */\n\t      CONST_BITS-1);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)),  /* c2+c6 */\n\t      CONST_BITS-1);\n\n    /* Odd part */\n\n    tmp10 = tmp0 + tmp4;\n    tmp11 = tmp1 - tmp3;\n    dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << 1);\n    tmp2 <<= CONST_BITS;\n    dataptr[1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) +          /* c1 */\n\t      MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 +   /* c3 */\n\t      MULTIPLY(tmp3, FIX(0.642039522)) +          /* c7 */\n\t      MULTIPLY(tmp4, FIX(0.221231742)),           /* c9 */\n\t      CONST_BITS-1);\n    tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) -     /* (c3+c7)/2 */\n\t    MULTIPLY(tmp1 + tmp3, FIX(0.587785252));      /* (c1-c9)/2 */\n    tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) +   /* (c3-c7)/2 */\n\t    (tmp11 << (CONST_BITS - 1)) - tmp2;\n    dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-1);\n    dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-1);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 10)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/10)**2 = 16/25, which we partially\n   * fold into the constant multipliers and final/initial shifting:\n   * cK now represents sqrt(2) * cos(K*pi/20) * 32/25.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];\n    tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];\n    tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];\n\n    tmp10 = tmp0 + tmp4;\n    tmp13 = tmp0 - tmp4;\n    tmp11 = tmp1 + tmp3;\n    tmp14 = tmp1 - tmp3;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];\n    tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];\n    tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */\n\t      CONST_BITS+2);\n    tmp12 += tmp12;\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */\n\t      MULTIPLY(tmp11 - tmp12, FIX(0.559380511)),  /* c8 */\n\t      CONST_BITS+2);\n    tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961));    /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)),  /* c2-c6 */\n\t      CONST_BITS+2);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)),  /* c2+c6 */\n\t      CONST_BITS+2);\n\n    /* Odd part */\n\n    tmp10 = tmp0 + tmp4;\n    tmp11 = tmp1 - tmp3;\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)),  /* 32/25 */\n\t      CONST_BITS+2);\n    tmp2 = MULTIPLY(tmp2, FIX(1.28));                     /* 32/25 */\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) +          /* c1 */\n\t      MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 +   /* c3 */\n\t      MULTIPLY(tmp3, FIX(0.821810588)) +          /* c7 */\n\t      MULTIPLY(tmp4, FIX(0.283176630)),           /* c9 */\n\t      CONST_BITS+2);\n    tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) -     /* (c3+c7)/2 */\n\t    MULTIPLY(tmp1 + tmp3, FIX(0.752365123));      /* (c1-c9)/2 */\n    tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) +   /* (c3-c7)/2 */\n\t    MULTIPLY(tmp11, FIX(0.64)) - tmp2;            /* 16/25 */\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+2);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+2);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on an 11x11 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_11x11 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 z1, z2, z3;\n  DCTELEM workspace[8*3];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * we scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * cK represents sqrt(2) * cos(K*pi/22).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[10]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[9]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[8]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[7]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[6]);\n    tmp5 = GETJSAMPLE(elemptr[5]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[10]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[9]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[8]);\n    tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[7]);\n    tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[6]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 - 11 * CENTERJSAMPLE) << 1);\n    tmp5 += tmp5;\n    tmp0 -= tmp5;\n    tmp1 -= tmp5;\n    tmp2 -= tmp5;\n    tmp3 -= tmp5;\n    tmp4 -= tmp5;\n    z1 = MULTIPLY(tmp0 + tmp3, FIX(1.356927976)) +       /* c2 */\n\t MULTIPLY(tmp2 + tmp4, FIX(0.201263574));        /* c10 */\n    z2 = MULTIPLY(tmp1 - tmp3, FIX(0.926112931));        /* c6 */\n    z3 = MULTIPLY(tmp0 - tmp1, FIX(1.189712156));        /* c4 */\n    dataptr[2] = (DCTELEM)\n      DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.018300590)) /* c2+c8-c6 */\n\t      - MULTIPLY(tmp4, FIX(1.390975730)),        /* c4+c10 */\n\t      CONST_BITS-1);\n    dataptr[4] = (DCTELEM)\n      DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.062335650)) /* c4-c6-c10 */\n\t      - MULTIPLY(tmp2, FIX(1.356927976))         /* c2 */\n\t      + MULTIPLY(tmp4, FIX(0.587485545)),        /* c8 */\n\t      CONST_BITS-1);\n    dataptr[6] = (DCTELEM)\n      DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.620527200)) /* c2+c4-c6 */\n\t      - MULTIPLY(tmp2, FIX(0.788749120)),        /* c8+c10 */\n\t      CONST_BITS-1);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.286413905));    /* c3 */\n    tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.068791298));    /* c5 */\n    tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.764581576));    /* c7 */\n    tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.719967871)) /* c7+c5+c3-c1 */\n\t   + MULTIPLY(tmp14, FIX(0.398430003));          /* c9 */\n    tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.764581576));  /* -c7 */\n    tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.399818907));  /* -c1 */\n    tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.276416582)) /* c9+c7+c1-c3 */\n\t    - MULTIPLY(tmp14, FIX(1.068791298));         /* c5 */\n    tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.398430003));   /* c9 */\n    tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(1.989053629)) /* c9+c5+c3-c7 */\n\t    + MULTIPLY(tmp14, FIX(1.399818907));         /* c1 */\n    tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.305598626)) /* c1+c5-c9-c7 */\n\t    - MULTIPLY(tmp14, FIX(1.286413905));         /* c3 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-1);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-1);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-1);\n    dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-1);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 11)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/11)**2 = 64/121, which we partially\n   * fold into the constant multipliers and final/initial shifting:\n   * cK now represents sqrt(2) * cos(K*pi/22) * 128/121.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*2];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*1];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*0];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*7];\n    tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*6];\n    tmp5 = dataptr[DCTSIZE*5];\n\n    tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*2];\n    tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*1];\n    tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*0];\n    tmp13 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*7];\n    tmp14 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*6];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5,\n\t\t       FIX(1.057851240)),                /* 128/121 */\n\t      CONST_BITS+2);\n    tmp5 += tmp5;\n    tmp0 -= tmp5;\n    tmp1 -= tmp5;\n    tmp2 -= tmp5;\n    tmp3 -= tmp5;\n    tmp4 -= tmp5;\n    z1 = MULTIPLY(tmp0 + tmp3, FIX(1.435427942)) +       /* c2 */\n\t MULTIPLY(tmp2 + tmp4, FIX(0.212906922));        /* c10 */\n    z2 = MULTIPLY(tmp1 - tmp3, FIX(0.979689713));        /* c6 */\n    z3 = MULTIPLY(tmp0 - tmp1, FIX(1.258538479));        /* c4 */\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(z1 + z2 - MULTIPLY(tmp3, FIX(1.077210542)) /* c2+c8-c6 */\n\t      - MULTIPLY(tmp4, FIX(1.471445400)),        /* c4+c10 */\n\t      CONST_BITS+2);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(z2 + z3 + MULTIPLY(tmp1, FIX(0.065941844)) /* c4-c6-c10 */\n\t      - MULTIPLY(tmp2, FIX(1.435427942))         /* c2 */\n\t      + MULTIPLY(tmp4, FIX(0.621472312)),        /* c8 */\n\t      CONST_BITS+2);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(z1 + z3 - MULTIPLY(tmp0, FIX(1.714276708)) /* c2+c4-c6 */\n\t      - MULTIPLY(tmp2, FIX(0.834379234)),        /* c8+c10 */\n\t      CONST_BITS+2);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.360834544));    /* c3 */\n    tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.130622199));    /* c5 */\n    tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.808813568));    /* c7 */\n    tmp0 = tmp1 + tmp2 + tmp3 - MULTIPLY(tmp10, FIX(1.819470145)) /* c7+c5+c3-c1 */\n\t   + MULTIPLY(tmp14, FIX(0.421479672));          /* c9 */\n    tmp4 = MULTIPLY(tmp11 + tmp12, - FIX(0.808813568));  /* -c7 */\n    tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.480800167));  /* -c1 */\n    tmp1 += tmp4 + tmp5 + MULTIPLY(tmp11, FIX(1.350258864)) /* c9+c7+c1-c3 */\n\t    - MULTIPLY(tmp14, FIX(1.130622199));         /* c5 */\n    tmp10 = MULTIPLY(tmp12 + tmp13, FIX(0.421479672));   /* c9 */\n    tmp2 += tmp4 + tmp10 - MULTIPLY(tmp12, FIX(2.104122847)) /* c9+c5+c3-c7 */\n\t    + MULTIPLY(tmp14, FIX(1.480800167));         /* c1 */\n    tmp3 += tmp5 + tmp10 + MULTIPLY(tmp13, FIX(1.381129125)) /* c1+c5-c9-c7 */\n\t    - MULTIPLY(tmp14, FIX(1.360834544));         /* c3 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 12x12 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_12x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  DCTELEM workspace[8*4];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   * cK represents sqrt(2) * cos(K*pi/24).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);\n\n    tmp10 = tmp0 + tmp5;\n    tmp13 = tmp0 - tmp5;\n    tmp11 = tmp1 + tmp4;\n    tmp14 = tmp1 - tmp4;\n    tmp12 = tmp2 + tmp3;\n    tmp15 = tmp2 - tmp3;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) (tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE);\n    dataptr[6] = (DCTELEM) (tmp13 - tmp14 - tmp15);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */\n\t      CONST_BITS);\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */\n\t      CONST_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100);    /* c9 */\n    tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865);   /* c3-c9 */\n    tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065);   /* c3+c9 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054));   /* c5 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669));   /* c7 */\n    tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */\n\t    + MULTIPLY(tmp5, FIX(0.184591911));        /* c11 */\n    tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */\n    tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */\n\t    + MULTIPLY(tmp5, FIX(0.860918669));        /* c7 */\n    tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */\n\t    - MULTIPLY(tmp5, FIX(1.121971054));        /* c5 */\n    tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */\n\t    - MULTIPLY(tmp2 + tmp5, FIX_0_541196100);  /* c9 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 12)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/12)**2 = 4/9, which we partially\n   * fold into the constant multipliers and final shifting:\n   * cK now represents sqrt(2) * cos(K*pi/24) * 8/9.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];\n    tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];\n    tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];\n\n    tmp10 = tmp0 + tmp5;\n    tmp13 = tmp0 - tmp5;\n    tmp11 = tmp1 + tmp4;\n    tmp14 = tmp1 - tmp4;\n    tmp12 = tmp2 + tmp3;\n    tmp15 = tmp2 - tmp3;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];\n    tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];\n    tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */\n\t      CONST_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */\n\t      CONST_BITS+1);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)),         /* c4 */\n\t      CONST_BITS+1);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) +        /* 8/9 */\n\t      MULTIPLY(tmp13 + tmp15, FIX(1.214244803)),         /* c2 */\n\t      CONST_BITS+1);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200));   /* c9 */\n    tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102));  /* c3-c9 */\n    tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502));  /* c3+c9 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603));   /* c5 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039));   /* c7 */\n    tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */\n\t    + MULTIPLY(tmp5, FIX(0.164081699));        /* c11 */\n    tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */\n    tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */\n\t    + MULTIPLY(tmp5, FIX(0.765261039));        /* c7 */\n    tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */\n\t    - MULTIPLY(tmp5, FIX(0.997307603));        /* c5 */\n    tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */\n\t    - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+1);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 13x13 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_13x13 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  INT32 z1, z2;\n  DCTELEM workspace[8*5];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   * cK represents sqrt(2) * cos(K*pi/26).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[12]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[11]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[10]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[9]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[8]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[7]);\n    tmp6 = GETJSAMPLE(elemptr[6]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[12]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[11]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[10]);\n    tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[9]);\n    tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[8]);\n    tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[7]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      (tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6 - 13 * CENTERJSAMPLE);\n    tmp6 += tmp6;\n    tmp0 -= tmp6;\n    tmp1 -= tmp6;\n    tmp2 -= tmp6;\n    tmp3 -= tmp6;\n    tmp4 -= tmp6;\n    tmp5 -= tmp6;\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.373119086)) +   /* c2 */\n\t      MULTIPLY(tmp1, FIX(1.058554052)) +   /* c6 */\n\t      MULTIPLY(tmp2, FIX(0.501487041)) -   /* c10 */\n\t      MULTIPLY(tmp3, FIX(0.170464608)) -   /* c12 */\n\t      MULTIPLY(tmp4, FIX(0.803364869)) -   /* c8 */\n\t      MULTIPLY(tmp5, FIX(1.252223920)),    /* c4 */\n\t      CONST_BITS);\n    z1 = MULTIPLY(tmp0 - tmp2, FIX(1.155388986)) - /* (c4+c6)/2 */\n\t MULTIPLY(tmp3 - tmp4, FIX(0.435816023)) - /* (c2-c10)/2 */\n\t MULTIPLY(tmp1 - tmp5, FIX(0.316450131));  /* (c8-c12)/2 */\n    z2 = MULTIPLY(tmp0 + tmp2, FIX(0.096834934)) - /* (c4-c6)/2 */\n\t MULTIPLY(tmp3 + tmp4, FIX(0.937303064)) + /* (c2+c10)/2 */\n\t MULTIPLY(tmp1 + tmp5, FIX(0.486914739));  /* (c8+c12)/2 */\n\n    dataptr[4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS);\n    dataptr[6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.322312651));   /* c3 */\n    tmp2 = MULTIPLY(tmp10 + tmp12, FIX(1.163874945));   /* c5 */\n    tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.937797057)) +  /* c7 */\n\t   MULTIPLY(tmp14 + tmp15, FIX(0.338443458));   /* c11 */\n    tmp0 = tmp1 + tmp2 + tmp3 -\n\t   MULTIPLY(tmp10, FIX(2.020082300)) +          /* c3+c5+c7-c1 */\n\t   MULTIPLY(tmp14, FIX(0.318774355));           /* c9-c11 */\n    tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.937797057)) -  /* c7 */\n\t   MULTIPLY(tmp11 + tmp12, FIX(0.338443458));   /* c11 */\n    tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(1.163874945)); /* -c5 */\n    tmp1 += tmp4 + tmp5 +\n\t    MULTIPLY(tmp11, FIX(0.837223564)) -         /* c5+c9+c11-c3 */\n\t    MULTIPLY(tmp14, FIX(2.341699410));          /* c1+c7 */\n    tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.657217813)); /* -c9 */\n    tmp2 += tmp4 + tmp6 -\n\t    MULTIPLY(tmp12, FIX(1.572116027)) +         /* c1+c5-c9-c11 */\n\t    MULTIPLY(tmp15, FIX(2.260109708));          /* c3+c7 */\n    tmp3 += tmp5 + tmp6 +\n\t    MULTIPLY(tmp13, FIX(2.205608352)) -         /* c3+c5+c9-c7 */\n\t    MULTIPLY(tmp15, FIX(1.742345811));          /* c1+c11 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 13)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/13)**2 = 64/169, which we partially\n   * fold into the constant multipliers and final shifting:\n   * cK now represents sqrt(2) * cos(K*pi/26) * 128/169.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*4];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*3];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*2];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*1];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*0];\n    tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*7];\n    tmp6 = dataptr[DCTSIZE*6];\n\n    tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*4];\n    tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*3];\n    tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*2];\n    tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*1];\n    tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*0];\n    tmp15 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*7];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 + tmp1 + tmp2 + tmp3 + tmp4 + tmp5 + tmp6,\n\t\t       FIX(0.757396450)),          /* 128/169 */\n\t      CONST_BITS+1);\n    tmp6 += tmp6;\n    tmp0 -= tmp6;\n    tmp1 -= tmp6;\n    tmp2 -= tmp6;\n    tmp3 -= tmp6;\n    tmp4 -= tmp6;\n    tmp5 -= tmp6;\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.039995521)) +   /* c2 */\n\t      MULTIPLY(tmp1, FIX(0.801745081)) +   /* c6 */\n\t      MULTIPLY(tmp2, FIX(0.379824504)) -   /* c10 */\n\t      MULTIPLY(tmp3, FIX(0.129109289)) -   /* c12 */\n\t      MULTIPLY(tmp4, FIX(0.608465700)) -   /* c8 */\n\t      MULTIPLY(tmp5, FIX(0.948429952)),    /* c4 */\n\t      CONST_BITS+1);\n    z1 = MULTIPLY(tmp0 - tmp2, FIX(0.875087516)) - /* (c4+c6)/2 */\n\t MULTIPLY(tmp3 - tmp4, FIX(0.330085509)) - /* (c2-c10)/2 */\n\t MULTIPLY(tmp1 - tmp5, FIX(0.239678205));  /* (c8-c12)/2 */\n    z2 = MULTIPLY(tmp0 + tmp2, FIX(0.073342435)) - /* (c4-c6)/2 */\n\t MULTIPLY(tmp3 + tmp4, FIX(0.709910013)) + /* (c2+c10)/2 */\n\t MULTIPLY(tmp1 + tmp5, FIX(0.368787494));  /* (c8+c12)/2 */\n\n    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 - z2, CONST_BITS+1);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.001514908));   /* c3 */\n    tmp2 = MULTIPLY(tmp10 + tmp12, FIX(0.881514751));   /* c5 */\n    tmp3 = MULTIPLY(tmp10 + tmp13, FIX(0.710284161)) +  /* c7 */\n\t   MULTIPLY(tmp14 + tmp15, FIX(0.256335874));   /* c11 */\n    tmp0 = tmp1 + tmp2 + tmp3 -\n\t   MULTIPLY(tmp10, FIX(1.530003162)) +          /* c3+c5+c7-c1 */\n\t   MULTIPLY(tmp14, FIX(0.241438564));           /* c9-c11 */\n    tmp4 = MULTIPLY(tmp14 - tmp15, FIX(0.710284161)) -  /* c7 */\n\t   MULTIPLY(tmp11 + tmp12, FIX(0.256335874));   /* c11 */\n    tmp5 = MULTIPLY(tmp11 + tmp13, - FIX(0.881514751)); /* -c5 */\n    tmp1 += tmp4 + tmp5 +\n\t    MULTIPLY(tmp11, FIX(0.634110155)) -         /* c5+c9+c11-c3 */\n\t    MULTIPLY(tmp14, FIX(1.773594819));          /* c1+c7 */\n    tmp6 = MULTIPLY(tmp12 + tmp13, - FIX(0.497774438)); /* -c9 */\n    tmp2 += tmp4 + tmp6 -\n\t    MULTIPLY(tmp12, FIX(1.190715098)) +         /* c1+c5-c9-c11 */\n\t    MULTIPLY(tmp15, FIX(1.711799069));          /* c3+c7 */\n    tmp3 += tmp5 + tmp6 +\n\t    MULTIPLY(tmp13, FIX(1.670519935)) -         /* c3+c5+c9-c7 */\n\t    MULTIPLY(tmp15, FIX(1.319646532));          /* c1+c11 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+1);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 14x14 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_14x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  DCTELEM workspace[8*6];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   * cK represents sqrt(2) * cos(K*pi/28).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);\n    tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);\n    tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);\n\n    tmp10 = tmp0 + tmp6;\n    tmp14 = tmp0 - tmp6;\n    tmp11 = tmp1 + tmp5;\n    tmp15 = tmp1 - tmp5;\n    tmp12 = tmp2 + tmp4;\n    tmp16 = tmp2 - tmp4;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);\n    tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      (tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE);\n    tmp13 += tmp13;\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */\n\t      MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */\n\t      MULTIPLY(tmp12 - tmp13, FIX(0.881747734)),  /* c8 */\n\t      CONST_BITS);\n\n    tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686));    /* c6 */\n\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590))   /* c2-c6 */\n\t      + MULTIPLY(tmp16, FIX(0.613604268)),        /* c10 */\n\t      CONST_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954))   /* c6+c10 */\n\t      - MULTIPLY(tmp16, FIX(1.378756276)),        /* c2 */\n\t      CONST_BITS);\n\n    /* Odd part */\n\n    tmp10 = tmp1 + tmp2;\n    tmp11 = tmp5 - tmp4;\n    dataptr[7] = (DCTELEM) (tmp0 - tmp10 + tmp3 - tmp11 - tmp6);\n    tmp3 <<= CONST_BITS;\n    tmp10 = MULTIPLY(tmp10, - FIX(0.158341681));          /* -c13 */\n    tmp11 = MULTIPLY(tmp11, FIX(1.405321284));            /* c1 */\n    tmp10 += tmp11 - tmp3;\n    tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) +     /* c5 */\n\t    MULTIPLY(tmp4 + tmp6, FIX(0.752406978));      /* c9 */\n    dataptr[5] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */\n\t      + MULTIPLY(tmp4, FIX(1.119999435)),         /* c1+c11-c9 */\n\t      CONST_BITS);\n    tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) +     /* c3 */\n\t    MULTIPLY(tmp5 - tmp6, FIX(0.467085129));      /* c11 */\n    dataptr[3] = (DCTELEM)\n      DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */\n\t      - MULTIPLY(tmp5, FIX(3.069855259)),         /* c1+c5+c11 */\n\t      CONST_BITS);\n    dataptr[1] = (DCTELEM)\n      DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -\n\t      MULTIPLY(tmp0 + tmp6, FIX(1.126980169)),    /* c3+c5-c1 */\n\t      CONST_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 14)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/14)**2 = 16/49, which we partially\n   * fold into the constant multipliers and final shifting:\n   * cK now represents sqrt(2) * cos(K*pi/28) * 32/49.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];\n    tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];\n    tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];\n    tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];\n\n    tmp10 = tmp0 + tmp6;\n    tmp14 = tmp0 - tmp6;\n    tmp11 = tmp1 + tmp5;\n    tmp15 = tmp1 - tmp5;\n    tmp12 = tmp2 + tmp4;\n    tmp16 = tmp2 - tmp4;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];\n    tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];\n    tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];\n    tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,\n\t\t       FIX(0.653061224)),                 /* 32/49 */\n\t      CONST_BITS+1);\n    tmp13 += tmp13;\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */\n\t      MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */\n\t      MULTIPLY(tmp12 - tmp13, FIX(0.575835255)),  /* c8 */\n\t      CONST_BITS+1);\n\n    tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570));    /* c6 */\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691))   /* c2-c6 */\n\t      + MULTIPLY(tmp16, FIX(0.400721155)),        /* c10 */\n\t      CONST_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725))   /* c6+c10 */\n\t      - MULTIPLY(tmp16, FIX(0.900412262)),        /* c2 */\n\t      CONST_BITS+1);\n\n    /* Odd part */\n\n    tmp10 = tmp1 + tmp2;\n    tmp11 = tmp5 - tmp4;\n    dataptr[DCTSIZE*7] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,\n\t\t       FIX(0.653061224)),                 /* 32/49 */\n\t      CONST_BITS+1);\n    tmp3  = MULTIPLY(tmp3 , FIX(0.653061224));            /* 32/49 */\n    tmp10 = MULTIPLY(tmp10, - FIX(0.103406812));          /* -c13 */\n    tmp11 = MULTIPLY(tmp11, FIX(0.917760839));            /* c1 */\n    tmp10 += tmp11 - tmp3;\n    tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) +     /* c5 */\n\t    MULTIPLY(tmp4 + tmp6, FIX(0.491367823));      /* c9 */\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */\n\t      + MULTIPLY(tmp4, FIX(0.731428202)),         /* c1+c11-c9 */\n\t      CONST_BITS+1);\n    tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) +     /* c3 */\n\t    MULTIPLY(tmp5 - tmp6, FIX(0.305035186));      /* c11 */\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */\n\t      - MULTIPLY(tmp5, FIX(2.004803435)),         /* c1+c5+c11 */\n\t      CONST_BITS+1);\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp11 + tmp12 + tmp3\n\t      - MULTIPLY(tmp0, FIX(0.735987049))          /* c3+c5-c1 */\n\t      - MULTIPLY(tmp6, FIX(0.082925825)),         /* c9-c11-c13 */\n\t      CONST_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 15x15 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_15x15 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 z1, z2, z3;\n  DCTELEM workspace[8*7];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   * cK represents sqrt(2) * cos(K*pi/30).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[14]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[13]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[12]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[11]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[10]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[9]);\n    tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[8]);\n    tmp7 = GETJSAMPLE(elemptr[7]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[14]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[13]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[12]);\n    tmp13 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[11]);\n    tmp14 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[10]);\n    tmp15 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[9]);\n    tmp16 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[8]);\n\n    z1 = tmp0 + tmp4 + tmp5;\n    z2 = tmp1 + tmp3 + tmp6;\n    z3 = tmp2 + tmp7;\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) (z1 + z2 + z3 - 15 * CENTERJSAMPLE);\n    z3 += z3;\n    dataptr[6] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 - z3, FIX(1.144122806)) - /* c6 */\n\t      MULTIPLY(z2 - z3, FIX(0.437016024)),  /* c12 */\n\t      CONST_BITS);\n    tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;\n    z1 = MULTIPLY(tmp3 - tmp2, FIX(1.531135173)) -  /* c2+c14 */\n         MULTIPLY(tmp6 - tmp2, FIX(2.238241955));   /* c4+c8 */\n    z2 = MULTIPLY(tmp5 - tmp2, FIX(0.798468008)) -  /* c8-c14 */\n\t MULTIPLY(tmp0 - tmp2, FIX(0.091361227));   /* c2-c4 */\n    z3 = MULTIPLY(tmp0 - tmp3, FIX(1.383309603)) +  /* c2 */\n\t MULTIPLY(tmp6 - tmp5, FIX(0.946293579)) +  /* c8 */\n\t MULTIPLY(tmp1 - tmp4, FIX(0.790569415));   /* (c6+c12)/2 */\n\n    dataptr[2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS);\n    dataptr[4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS);\n\n    /* Odd part */\n\n    tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,\n\t\t    FIX(1.224744871));                         /* c5 */\n    tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.344997024)) + /* c3 */\n\t   MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.831253876));  /* c9 */\n    tmp12 = MULTIPLY(tmp12, FIX(1.224744871));                 /* c5 */\n    tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.406466353)) +         /* c1 */\n\t   MULTIPLY(tmp11 + tmp14, FIX(1.344997024)) +         /* c3 */\n\t   MULTIPLY(tmp13 + tmp15, FIX(0.575212477));          /* c11 */\n    tmp0 = MULTIPLY(tmp13, FIX(0.475753014)) -                 /* c7-c11 */\n\t   MULTIPLY(tmp14, FIX(0.513743148)) +                 /* c3-c9 */\n\t   MULTIPLY(tmp16, FIX(1.700497885)) + tmp4 + tmp12;   /* c1+c13 */\n    tmp3 = MULTIPLY(tmp10, - FIX(0.355500862)) -               /* -(c1-c7) */\n\t   MULTIPLY(tmp11, FIX(2.176250899)) -                 /* c3+c9 */\n\t   MULTIPLY(tmp15, FIX(0.869244010)) + tmp4 - tmp12;   /* c11+c13 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 15)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/15)**2 = 64/225, which we partially\n   * fold into the constant multipliers and final shifting:\n   * cK now represents sqrt(2) * cos(K*pi/30) * 256/225.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*6];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*5];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*4];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*3];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*2];\n    tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*1];\n    tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*0];\n    tmp7 = dataptr[DCTSIZE*7];\n\n    tmp10 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*6];\n    tmp11 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*5];\n    tmp12 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*4];\n    tmp13 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*3];\n    tmp14 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*2];\n    tmp15 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*1];\n    tmp16 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*0];\n\n    z1 = tmp0 + tmp4 + tmp5;\n    z2 = tmp1 + tmp3 + tmp6;\n    z3 = tmp2 + tmp7;\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 + z2 + z3, FIX(1.137777778)), /* 256/225 */\n\t      CONST_BITS+2);\n    z3 += z3;\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 - z3, FIX(1.301757503)) - /* c6 */\n\t      MULTIPLY(z2 - z3, FIX(0.497227121)),  /* c12 */\n\t      CONST_BITS+2);\n    tmp2 += ((tmp1 + tmp4) >> 1) - tmp7 - tmp7;\n    z1 = MULTIPLY(tmp3 - tmp2, FIX(1.742091575)) -  /* c2+c14 */\n         MULTIPLY(tmp6 - tmp2, FIX(2.546621957));   /* c4+c8 */\n    z2 = MULTIPLY(tmp5 - tmp2, FIX(0.908479156)) -  /* c8-c14 */\n\t MULTIPLY(tmp0 - tmp2, FIX(0.103948774));   /* c2-c4 */\n    z3 = MULTIPLY(tmp0 - tmp3, FIX(1.573898926)) +  /* c2 */\n\t MULTIPLY(tmp6 - tmp5, FIX(1.076671805)) +  /* c8 */\n\t MULTIPLY(tmp1 - tmp4, FIX(0.899492312));   /* (c6+c12)/2 */\n\n    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z3, CONST_BITS+2);\n    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(z2 + z3, CONST_BITS+2);\n\n    /* Odd part */\n\n    tmp2 = MULTIPLY(tmp10 - tmp12 - tmp13 + tmp15 + tmp16,\n\t\t    FIX(1.393487498));                         /* c5 */\n    tmp1 = MULTIPLY(tmp10 - tmp14 - tmp15, FIX(1.530307725)) + /* c3 */\n\t   MULTIPLY(tmp11 - tmp13 - tmp16, FIX(0.945782187));  /* c9 */\n    tmp12 = MULTIPLY(tmp12, FIX(1.393487498));                 /* c5 */\n    tmp4 = MULTIPLY(tmp10 - tmp16, FIX(1.600246161)) +         /* c1 */\n\t   MULTIPLY(tmp11 + tmp14, FIX(1.530307725)) +         /* c3 */\n\t   MULTIPLY(tmp13 + tmp15, FIX(0.654463974));          /* c11 */\n    tmp0 = MULTIPLY(tmp13, FIX(0.541301207)) -                 /* c7-c11 */\n\t   MULTIPLY(tmp14, FIX(0.584525538)) +                 /* c3-c9 */\n\t   MULTIPLY(tmp16, FIX(1.934788705)) + tmp4 + tmp12;   /* c1+c13 */\n    tmp3 = MULTIPLY(tmp10, - FIX(0.404480980)) -               /* -(c1-c7) */\n\t   MULTIPLY(tmp11, FIX(2.476089912)) -                 /* c3+c9 */\n\t   MULTIPLY(tmp15, FIX(0.989006518)) + tmp4 - tmp12;   /* c11+c13 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+2);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+2);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+2);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+2);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 16x16 sample block.\n */\n\nGLOBAL(void)\njpeg_fdct_16x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;\n  DCTELEM workspace[DCTSIZE2];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);\n    tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);\n    tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);\n\n    tmp10 = tmp0 + tmp7;\n    tmp14 = tmp0 - tmp7;\n    tmp11 = tmp1 + tmp6;\n    tmp15 = tmp1 - tmp6;\n    tmp12 = tmp2 + tmp5;\n    tmp16 = tmp2 - tmp5;\n    tmp13 = tmp3 + tmp4;\n    tmp17 = tmp3 - tmp4;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);\n    tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);\n    tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */\n\t      MULTIPLY(tmp11 - tmp12, FIX_0_541196100),   /* c12[16] = c6[8] */\n\t      CONST_BITS-PASS1_BITS);\n\n    tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) +   /* c14[16] = c7[8] */\n\t    MULTIPLY(tmp14 - tmp16, FIX(1.387039845));    /* c2[16] = c1[8] */\n\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982))   /* c6+c14 */\n\t      + MULTIPLY(tmp16, FIX(2.172734804)),        /* c2+c10 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243))   /* c2-c6 */\n\t      - MULTIPLY(tmp17, FIX(1.061594338)),        /* c10+c14 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) +         /* c3 */\n\t    MULTIPLY(tmp6 - tmp7, FIX(0.410524528));          /* c13 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) +         /* c5 */\n\t    MULTIPLY(tmp5 + tmp7, FIX(0.666655658));          /* c11 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) +         /* c7 */\n\t    MULTIPLY(tmp4 - tmp7, FIX(0.897167586));          /* c9 */\n    tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) +         /* c15 */\n\t    MULTIPLY(tmp6 - tmp5, FIX(1.407403738));          /* c1 */\n    tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) +       /* -c11 */\n\t    MULTIPLY(tmp4 + tmp6, - FIX(1.247225013));        /* -c5 */\n    tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) +       /* -c3 */\n\t    MULTIPLY(tmp5 - tmp4, FIX(0.410524528));          /* c13 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(tmp0, FIX(2.286341144)) +                /* c7+c5+c3-c1 */\n\t    MULTIPLY(tmp7, FIX(0.779653625));                 /* c15+c13-c11+c9 */\n    tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */\n\t     - MULTIPLY(tmp6, FIX(1.663905119));              /* c7+c13+c1-c5 */\n    tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */\n\t     + MULTIPLY(tmp5, FIX(1.227391138));              /* c9-c11+c1-c13 */\n    tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */\n\t     + MULTIPLY(tmp4, FIX(2.167985692));              /* c1+c13+c5-c9 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == DCTSIZE * 2)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/16)**2 = 1/2**2.\n   * cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];\n    tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];\n    tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];\n    tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];\n\n    tmp10 = tmp0 + tmp7;\n    tmp14 = tmp0 - tmp7;\n    tmp11 = tmp1 + tmp6;\n    tmp15 = tmp1 - tmp6;\n    tmp12 = tmp2 + tmp5;\n    tmp16 = tmp2 - tmp5;\n    tmp13 = tmp3 + tmp4;\n    tmp17 = tmp3 - tmp4;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];\n    tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];\n    tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];\n    tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+2);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */\n\t      MULTIPLY(tmp11 - tmp12, FIX_0_541196100),   /* c12[16] = c6[8] */\n\t      CONST_BITS+PASS1_BITS+2);\n\n    tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) +   /* c14[16] = c7[8] */\n\t    MULTIPLY(tmp14 - tmp16, FIX(1.387039845));    /* c2[16] = c1[8] */\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982))   /* c6+c14 */\n\t      + MULTIPLY(tmp16, FIX(2.172734804)),        /* c2+10 */\n\t      CONST_BITS+PASS1_BITS+2);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243))   /* c2-c6 */\n\t      - MULTIPLY(tmp17, FIX(1.061594338)),        /* c10+c14 */\n\t      CONST_BITS+PASS1_BITS+2);\n\n    /* Odd part */\n\n    tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) +         /* c3 */\n\t    MULTIPLY(tmp6 - tmp7, FIX(0.410524528));          /* c13 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) +         /* c5 */\n\t    MULTIPLY(tmp5 + tmp7, FIX(0.666655658));          /* c11 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) +         /* c7 */\n\t    MULTIPLY(tmp4 - tmp7, FIX(0.897167586));          /* c9 */\n    tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) +         /* c15 */\n\t    MULTIPLY(tmp6 - tmp5, FIX(1.407403738));          /* c1 */\n    tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) +       /* -c11 */\n\t    MULTIPLY(tmp4 + tmp6, - FIX(1.247225013));        /* -c5 */\n    tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) +       /* -c3 */\n\t    MULTIPLY(tmp5 - tmp4, FIX(0.410524528));          /* c13 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(tmp0, FIX(2.286341144)) +                /* c7+c5+c3-c1 */\n\t    MULTIPLY(tmp7, FIX(0.779653625));                 /* c15+c13-c11+c9 */\n    tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */\n\t     - MULTIPLY(tmp6, FIX(1.663905119));              /* c7+c13+c1-c5 */\n    tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */\n\t     + MULTIPLY(tmp5, FIX(1.227391138));              /* c9-c11+c1-c13 */\n    tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */\n\t     + MULTIPLY(tmp4, FIX(2.167985692));              /* c1+c13+c5-c9 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+2);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+2);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+2);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+2);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 16x8 sample block.\n *\n * 16-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_16x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;\n  INT32 z1;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[15]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[14]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[13]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[12]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[11]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[10]);\n    tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[9]);\n    tmp7 = GETJSAMPLE(elemptr[7]) + GETJSAMPLE(elemptr[8]);\n\n    tmp10 = tmp0 + tmp7;\n    tmp14 = tmp0 - tmp7;\n    tmp11 = tmp1 + tmp6;\n    tmp15 = tmp1 - tmp6;\n    tmp12 = tmp2 + tmp5;\n    tmp16 = tmp2 - tmp5;\n    tmp13 = tmp3 + tmp4;\n    tmp17 = tmp3 - tmp4;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[15]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[14]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[13]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[12]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[11]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[10]);\n    tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[9]);\n    tmp7 = GETJSAMPLE(elemptr[7]) - GETJSAMPLE(elemptr[8]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 + tmp13 - 16 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */\n\t      MULTIPLY(tmp11 - tmp12, FIX_0_541196100),   /* c12[16] = c6[8] */\n\t      CONST_BITS-PASS1_BITS);\n\n    tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) +   /* c14[16] = c7[8] */\n\t    MULTIPLY(tmp14 - tmp16, FIX(1.387039845));    /* c2[16] = c1[8] */\n\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982))   /* c6+c14 */\n\t      + MULTIPLY(tmp16, FIX(2.172734804)),        /* c2+c10 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243))   /* c2-c6 */\n\t      - MULTIPLY(tmp17, FIX(1.061594338)),        /* c10+c14 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) +         /* c3 */\n\t    MULTIPLY(tmp6 - tmp7, FIX(0.410524528));          /* c13 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) +         /* c5 */\n\t    MULTIPLY(tmp5 + tmp7, FIX(0.666655658));          /* c11 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) +         /* c7 */\n\t    MULTIPLY(tmp4 - tmp7, FIX(0.897167586));          /* c9 */\n    tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) +         /* c15 */\n\t    MULTIPLY(tmp6 - tmp5, FIX(1.407403738));          /* c1 */\n    tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) +       /* -c11 */\n\t    MULTIPLY(tmp4 + tmp6, - FIX(1.247225013));        /* -c5 */\n    tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) +       /* -c3 */\n\t    MULTIPLY(tmp5 - tmp4, FIX(0.410524528));          /* c13 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(tmp0, FIX(2.286341144)) +                /* c7+c5+c3-c1 */\n\t    MULTIPLY(tmp7, FIX(0.779653625));                 /* c15+c13-c11+c9 */\n    tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */\n\t     - MULTIPLY(tmp6, FIX(1.663905119));              /* c7+c13+c1-c5 */\n    tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */\n\t     + MULTIPLY(tmp5, FIX(1.227391138));              /* c9-c11+c1-c13 */\n    tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */\n\t     + MULTIPLY(tmp4, FIX(2.167985692));              /* c1+c13+c5-c9 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by 8/16 = 1/2.\n   * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];\n\n    tmp10 = tmp0 + tmp3;\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS+1);\n    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS+1);\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);   /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t      CONST_BITS+PASS1_BITS+1);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);   /*  c3 */\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);      /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);      /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);   /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);          /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);          /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);   /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);          /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);          /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp3, CONST_BITS+PASS1_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 14x7 sample block.\n *\n * 14-point FDCT in pass 1 (rows), 7-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_14x7 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 z1, z2, z3;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Zero bottom row of output coefficient block. */\n  MEMZERO(&data[DCTSIZE*7], SIZEOF(DCTELEM) * DCTSIZE);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 7; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[13]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[12]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[11]);\n    tmp13 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[10]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[9]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[8]);\n    tmp6 = GETJSAMPLE(elemptr[6]) + GETJSAMPLE(elemptr[7]);\n\n    tmp10 = tmp0 + tmp6;\n    tmp14 = tmp0 - tmp6;\n    tmp11 = tmp1 + tmp5;\n    tmp15 = tmp1 - tmp5;\n    tmp12 = tmp2 + tmp4;\n    tmp16 = tmp2 - tmp4;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[13]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[12]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[11]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[10]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[9]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[8]);\n    tmp6 = GETJSAMPLE(elemptr[6]) - GETJSAMPLE(elemptr[7]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 + tmp13 - 14 * CENTERJSAMPLE) << PASS1_BITS);\n    tmp13 += tmp13;\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.274162392)) + /* c4 */\n\t      MULTIPLY(tmp11 - tmp13, FIX(0.314692123)) - /* c12 */\n\t      MULTIPLY(tmp12 - tmp13, FIX(0.881747734)),  /* c8 */\n\t      CONST_BITS-PASS1_BITS);\n\n    tmp10 = MULTIPLY(tmp14 + tmp15, FIX(1.105676686));    /* c6 */\n\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.273079590))   /* c2-c6 */\n\t      + MULTIPLY(tmp16, FIX(0.613604268)),        /* c10 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.719280954))   /* c6+c10 */\n\t      - MULTIPLY(tmp16, FIX(1.378756276)),        /* c2 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = tmp1 + tmp2;\n    tmp11 = tmp5 - tmp4;\n    dataptr[7] = (DCTELEM) ((tmp0 - tmp10 + tmp3 - tmp11 - tmp6) << PASS1_BITS);\n    tmp3 <<= CONST_BITS;\n    tmp10 = MULTIPLY(tmp10, - FIX(0.158341681));          /* -c13 */\n    tmp11 = MULTIPLY(tmp11, FIX(1.405321284));            /* c1 */\n    tmp10 += tmp11 - tmp3;\n    tmp11 = MULTIPLY(tmp0 + tmp2, FIX(1.197448846)) +     /* c5 */\n\t    MULTIPLY(tmp4 + tmp6, FIX(0.752406978));      /* c9 */\n    dataptr[5] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(2.373959773)) /* c3+c5-c13 */\n\t      + MULTIPLY(tmp4, FIX(1.119999435)),         /* c1+c11-c9 */\n\t      CONST_BITS-PASS1_BITS);\n    tmp12 = MULTIPLY(tmp0 + tmp1, FIX(1.334852607)) +     /* c3 */\n\t    MULTIPLY(tmp5 - tmp6, FIX(0.467085129));      /* c11 */\n    dataptr[3] = (DCTELEM)\n      DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.424103948)) /* c3-c9-c13 */\n\t      - MULTIPLY(tmp5, FIX(3.069855259)),         /* c1+c5+c11 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[1] = (DCTELEM)\n      DESCALE(tmp11 + tmp12 + tmp3 + tmp6 -\n\t      MULTIPLY(tmp0 + tmp6, FIX(1.126980169)),    /* c3+c5-c1 */\n\t      CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/14)*(8/7) = 32/49, which we\n   * partially fold into the constant multipliers and final shifting:\n   * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14) * 64/49.\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*6];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*5];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*4];\n    tmp3 = dataptr[DCTSIZE*3];\n\n    tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*6];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*5];\n    tmp12 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*4];\n\n    z1 = tmp0 + tmp2;\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(z1 + tmp1 + tmp3, FIX(1.306122449)), /* 64/49 */\n\t      CONST_BITS+PASS1_BITS+1);\n    tmp3 += tmp3;\n    z1 -= tmp3;\n    z1 -= tmp3;\n    z1 = MULTIPLY(z1, FIX(0.461784020));                /* (c2+c6-c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp2, FIX(1.202428084));       /* (c2+c4-c6)/2 */\n    z3 = MULTIPLY(tmp1 - tmp2, FIX(0.411026446));       /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS+PASS1_BITS+1);\n    z1 -= z2;\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(1.151670509));       /* c4 */\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.923568041)), /* c2+c6-c4 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS+PASS1_BITS+1);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(1.221765677));   /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.222383464));   /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.800824523)); /* -c1 */\n    tmp1 += tmp2;\n    tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.801442310));   /* c5 */\n    tmp0 += tmp3;\n    tmp2 += tmp3 + MULTIPLY(tmp12, FIX(2.443531355));   /* c3+c1-c5 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp0, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp1, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp2, CONST_BITS+PASS1_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 12x6 sample block.\n *\n * 12-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_12x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Zero 2 bottom rows of output coefficient block. */\n  MEMZERO(&data[DCTSIZE*6], SIZEOF(DCTELEM) * DCTSIZE * 2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 6; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[11]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[10]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[9]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[8]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[7]);\n    tmp5 = GETJSAMPLE(elemptr[5]) + GETJSAMPLE(elemptr[6]);\n\n    tmp10 = tmp0 + tmp5;\n    tmp13 = tmp0 - tmp5;\n    tmp11 = tmp1 + tmp4;\n    tmp14 = tmp1 - tmp4;\n    tmp12 = tmp2 + tmp3;\n    tmp15 = tmp2 - tmp3;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[11]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[10]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[9]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[8]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[7]);\n    tmp5 = GETJSAMPLE(elemptr[5]) - GETJSAMPLE(elemptr[6]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 - 12 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[6] = (DCTELEM) ((tmp13 - tmp14 - tmp15) << PASS1_BITS);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.224744871)), /* c4 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp14 - tmp15 + MULTIPLY(tmp13 + tmp15, FIX(1.366025404)), /* c2 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp1 + tmp4, FIX_0_541196100);    /* c9 */\n    tmp14 = tmp10 + MULTIPLY(tmp1, FIX_0_765366865);   /* c3-c9 */\n    tmp15 = tmp10 - MULTIPLY(tmp4, FIX_1_847759065);   /* c3+c9 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.121971054));   /* c5 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.860918669));   /* c7 */\n    tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.580774953)) /* c5+c7-c1 */\n\t    + MULTIPLY(tmp5, FIX(0.184591911));        /* c11 */\n    tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.184591911)); /* -c11 */\n    tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.339493912)) /* c1+c5-c11 */\n\t    + MULTIPLY(tmp5, FIX(0.860918669));        /* c7 */\n    tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.725788011)) /* c1+c11-c7 */\n\t    - MULTIPLY(tmp5, FIX(1.121971054));        /* c5 */\n    tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.306562965)) /* c3 */\n\t    - MULTIPLY(tmp2 + tmp5, FIX_0_541196100);  /* c9 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp10, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp11, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp12, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp13, CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/12)*(8/6) = 8/9, which we\n   * partially fold into the constant multipliers and final shifting:\n   * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];\n    tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)),         /* 16/9 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(2.177324216)),                 /* c2 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */\n\t      CONST_BITS+PASS1_BITS+1);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829));             /* c5 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)),    /* 16/9 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 10x5 sample block.\n *\n * 10-point FDCT in pass 1 (rows), 5-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_10x5 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Zero 3 bottom rows of output coefficient block. */\n  MEMZERO(&data[DCTSIZE*5], SIZEOF(DCTELEM) * DCTSIZE * 3);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 5; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[9]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[8]);\n    tmp12 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[7]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[6]);\n    tmp4 = GETJSAMPLE(elemptr[4]) + GETJSAMPLE(elemptr[5]);\n\n    tmp10 = tmp0 + tmp4;\n    tmp13 = tmp0 - tmp4;\n    tmp11 = tmp1 + tmp3;\n    tmp14 = tmp1 - tmp3;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[9]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[8]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[7]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[6]);\n    tmp4 = GETJSAMPLE(elemptr[4]) - GETJSAMPLE(elemptr[5]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 + tmp12 - 10 * CENTERJSAMPLE) << PASS1_BITS);\n    tmp12 += tmp12;\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.144122806)) - /* c4 */\n\t      MULTIPLY(tmp11 - tmp12, FIX(0.437016024)),  /* c8 */\n\t      CONST_BITS-PASS1_BITS);\n    tmp10 = MULTIPLY(tmp13 + tmp14, FIX(0.831253876));    /* c6 */\n    dataptr[2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.513743148)),  /* c2-c6 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.176250899)),  /* c2+c6 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = tmp0 + tmp4;\n    tmp11 = tmp1 - tmp3;\n    dataptr[5] = (DCTELEM) ((tmp10 - tmp11 - tmp2) << PASS1_BITS);\n    tmp2 <<= CONST_BITS;\n    dataptr[1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.396802247)) +          /* c1 */\n\t      MULTIPLY(tmp1, FIX(1.260073511)) + tmp2 +   /* c3 */\n\t      MULTIPLY(tmp3, FIX(0.642039522)) +          /* c7 */\n\t      MULTIPLY(tmp4, FIX(0.221231742)),           /* c9 */\n\t      CONST_BITS-PASS1_BITS);\n    tmp12 = MULTIPLY(tmp0 - tmp4, FIX(0.951056516)) -     /* (c3+c7)/2 */\n\t    MULTIPLY(tmp1 + tmp3, FIX(0.587785252));      /* (c1-c9)/2 */\n    tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.309016994)) +   /* (c3-c7)/2 */\n\t    (tmp11 << (CONST_BITS - 1)) - tmp2;\n    dataptr[3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS-PASS1_BITS);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/10)*(8/5) = 32/25, which we\n   * fold into the constant multipliers:\n   * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10) * 32/25.\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*4];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*3];\n    tmp2 = dataptr[DCTSIZE*2];\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*4];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*3];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp2, FIX(1.28)),        /* 32/25 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp11 = MULTIPLY(tmp11, FIX(1.011928851));          /* (c2+c4)/2 */\n    tmp10 -= tmp2 << 2;\n    tmp10 = MULTIPLY(tmp10, FIX(0.452548340));          /* (c2-c4)/2 */\n    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp1, FIX(1.064004961));    /* c3 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.657591230)), /* c1-c3 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.785601151)), /* c1+c3 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on an 8x4 sample block.\n *\n * 8-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_8x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Zero 4 bottom rows of output coefficient block. */\n  MEMZERO(&data[DCTSIZE*4], SIZEOF(DCTELEM) * DCTSIZE * 4);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We must also scale the output by 8/4 = 2, which we add here.\n   * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);\n\n    tmp10 = tmp0 + tmp3;\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << (PASS1_BITS+1));\n    dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << (PASS1_BITS+1));\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-2);\n\n    dataptr[2] = (DCTELEM)\n      RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS-PASS1_BITS-1);\n    dataptr[6] = (DCTELEM)\n      RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS-PASS1_BITS-1);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);       /*  c3 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-2);\n\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);          /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);          /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);       /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);              /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);              /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);       /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);              /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);              /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS-PASS1_BITS-1);\n    dataptr[3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS-PASS1_BITS-1);\n    dataptr[5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS-1);\n    dataptr[7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS-PASS1_BITS-1);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * 4-point FDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    /* Add fudge factor here for final descale. */\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3] + (ONE << (PASS1_BITS-1));\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];\n\n    tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 6x3 sample block.\n *\n * 6-point FDCT in pass 1 (rows), 3-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_6x3 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2;\n  INT32 tmp10, tmp11, tmp12;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 3; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);\n    tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << (PASS1_BITS+1));\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(1.224744871)),                 /* c2 */\n\t      CONST_BITS-PASS1_BITS-1);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */\n\t      CONST_BITS-PASS1_BITS-1);\n\n    /* Odd part */\n\n    tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)),     /* c5 */\n\t\t    CONST_BITS-PASS1_BITS-1);\n\n    dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << (PASS1_BITS+1)));\n    dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << (PASS1_BITS+1));\n    dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << (PASS1_BITS+1)));\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially\n   * fold into the constant multipliers (other part was done in pass 1):\n   * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6) * 16/9.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 6; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*2];\n    tmp1 = dataptr[DCTSIZE*1];\n\n    tmp2 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*2];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 + tmp1, FIX(1.777777778)),        /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(1.257078722)), /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2, FIX(2.177324216)),               /* c1 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 4x2 sample block.\n *\n * 4-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_4x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1;\n  INT32 tmp10, tmp11;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We must also scale the output by (8/4)*(8/2) = 2**3, which we add here.\n   * 4-point FDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 2; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+3));\n    dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+3));\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-4);\n\n    dataptr[1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS-PASS1_BITS-3);\n    dataptr[3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS-PASS1_BITS-3);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    /* Even part */\n\n    /* Add fudge factor here for final descale. */\n    tmp0 = dataptr[DCTSIZE*0] + (ONE << (PASS1_BITS-1));\n    tmp1 = dataptr[DCTSIZE*1];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp0 + tmp1, PASS1_BITS);\n\n    /* Odd part */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0 - tmp1, PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 2x1 sample block.\n *\n * 2-point FDCT in pass 1 (rows), 1-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_2x1 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  DCTELEM tmp0, tmp1;\n  JSAMPROW elemptr;\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  elemptr = sample_data[0] + start_col;\n\n  tmp0 = GETJSAMPLE(elemptr[0]);\n  tmp1 = GETJSAMPLE(elemptr[1]);\n\n  /* We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/2)*(8/1) = 2**5.\n   */\n\n  /* Even part */\n\n  /* Apply unsigned->signed conversion. */\n  data[0] = (tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5;\n\n  /* Odd part */\n\n  data[1] = (tmp0 - tmp1) << 5;\n}\n\n\n/*\n * Perform the forward DCT on an 8x16 sample block.\n *\n * 8-point FDCT in pass 1 (rows), 16-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_8x16 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16, tmp17;\n  INT32 z1;\n  DCTELEM workspace[DCTSIZE2];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) + GETJSAMPLE(elemptr[4]);\n\n    tmp10 = tmp0 + tmp3;\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[7]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[6]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[5]);\n    tmp3 = GETJSAMPLE(elemptr[3]) - GETJSAMPLE(elemptr[4]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) ((tmp10 + tmp11 - 8 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);   /* c6 */\n    dataptr[2] = (DCTELEM)\n      DESCALE(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM)\n      DESCALE(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);   /*  c3 */\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);      /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);      /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);   /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);          /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);          /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);   /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);          /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);          /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);\n    dataptr[7] = (DCTELEM) DESCALE(tmp3, CONST_BITS-PASS1_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == DCTSIZE * 2)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by 8/16 = 1/2.\n   * 16-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*3];\n    tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*2];\n    tmp6 = dataptr[DCTSIZE*6] + wsptr[DCTSIZE*1];\n    tmp7 = dataptr[DCTSIZE*7] + wsptr[DCTSIZE*0];\n\n    tmp10 = tmp0 + tmp7;\n    tmp14 = tmp0 - tmp7;\n    tmp11 = tmp1 + tmp6;\n    tmp15 = tmp1 - tmp6;\n    tmp12 = tmp2 + tmp5;\n    tmp16 = tmp2 - tmp5;\n    tmp13 = tmp3 + tmp4;\n    tmp17 = tmp3 - tmp4;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*4];\n    tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*3];\n    tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*2];\n    tmp6 = dataptr[DCTSIZE*6] - wsptr[DCTSIZE*1];\n    tmp7 = dataptr[DCTSIZE*7] - wsptr[DCTSIZE*0];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 + tmp12 + tmp13, PASS1_BITS+1);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(1.306562965)) + /* c4[16] = c2[8] */\n\t      MULTIPLY(tmp11 - tmp12, FIX_0_541196100),   /* c12[16] = c6[8] */\n\t      CONST_BITS+PASS1_BITS+1);\n\n    tmp10 = MULTIPLY(tmp17 - tmp15, FIX(0.275899379)) +   /* c14[16] = c7[8] */\n\t    MULTIPLY(tmp14 - tmp16, FIX(1.387039845));    /* c2[16] = c1[8] */\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp15, FIX(1.451774982))   /* c6+c14 */\n\t      + MULTIPLY(tmp16, FIX(2.172734804)),        /* c2+c10 */\n\t      CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(0.211164243))   /* c2-c6 */\n\t      - MULTIPLY(tmp17, FIX(1.061594338)),        /* c10+c14 */\n\t      CONST_BITS+PASS1_BITS+1);\n\n    /* Odd part */\n\n    tmp11 = MULTIPLY(tmp0 + tmp1, FIX(1.353318001)) +         /* c3 */\n\t    MULTIPLY(tmp6 - tmp7, FIX(0.410524528));          /* c13 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(1.247225013)) +         /* c5 */\n\t    MULTIPLY(tmp5 + tmp7, FIX(0.666655658));          /* c11 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(1.093201867)) +         /* c7 */\n\t    MULTIPLY(tmp4 - tmp7, FIX(0.897167586));          /* c9 */\n    tmp14 = MULTIPLY(tmp1 + tmp2, FIX(0.138617169)) +         /* c15 */\n\t    MULTIPLY(tmp6 - tmp5, FIX(1.407403738));          /* c1 */\n    tmp15 = MULTIPLY(tmp1 + tmp3, - FIX(0.666655658)) +       /* -c11 */\n\t    MULTIPLY(tmp4 + tmp6, - FIX(1.247225013));        /* -c5 */\n    tmp16 = MULTIPLY(tmp2 + tmp3, - FIX(1.353318001)) +       /* -c3 */\n\t    MULTIPLY(tmp5 - tmp4, FIX(0.410524528));          /* c13 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(tmp0, FIX(2.286341144)) +                /* c7+c5+c3-c1 */\n\t    MULTIPLY(tmp7, FIX(0.779653625));                 /* c15+c13-c11+c9 */\n    tmp11 += tmp14 + tmp15 + MULTIPLY(tmp1, FIX(0.071888074)) /* c9-c3-c15+c11 */\n\t     - MULTIPLY(tmp6, FIX(1.663905119));              /* c7+c13+c1-c5 */\n    tmp12 += tmp14 + tmp16 - MULTIPLY(tmp2, FIX(1.125726048)) /* c7+c5+c15-c3 */\n\t     + MULTIPLY(tmp5, FIX(1.227391138));              /* c9-c11+c1-c13 */\n    tmp13 += tmp15 + tmp16 + MULTIPLY(tmp3, FIX(1.065388962)) /* c15+c3+c11-c7 */\n\t     + MULTIPLY(tmp4, FIX(2.167985692));              /* c1+c13+c5-c9 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS+1);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS+1);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 7x14 sample block.\n *\n * 7-point FDCT in pass 1 (rows), 14-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_7x14 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 z1, z2, z3;\n  DCTELEM workspace[8*6];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 7-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/14).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[6]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[5]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[4]);\n    tmp3 = GETJSAMPLE(elemptr[3]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[6]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[5]);\n    tmp12 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[4]);\n\n    z1 = tmp0 + tmp2;\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((z1 + tmp1 + tmp3 - 7 * CENTERJSAMPLE) << PASS1_BITS);\n    tmp3 += tmp3;\n    z1 -= tmp3;\n    z1 -= tmp3;\n    z1 = MULTIPLY(z1, FIX(0.353553391));                /* (c2+c6-c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp2, FIX(0.920609002));       /* (c2+c4-c6)/2 */\n    z3 = MULTIPLY(tmp1 - tmp2, FIX(0.314692123));       /* c6 */\n    dataptr[2] = (DCTELEM) DESCALE(z1 + z2 + z3, CONST_BITS-PASS1_BITS);\n    z1 -= z2;\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(0.881747734));       /* c4 */\n    dataptr[4] = (DCTELEM)\n      DESCALE(z2 + z3 - MULTIPLY(tmp1 - tmp3, FIX(0.707106781)), /* c2+c6-c4 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[6] = (DCTELEM) DESCALE(z1 + z2, CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp1 = MULTIPLY(tmp10 + tmp11, FIX(0.935414347));   /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(tmp10 - tmp11, FIX(0.170262339));   /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(tmp11 + tmp12, - FIX(1.378756276)); /* -c1 */\n    tmp1 += tmp2;\n    tmp3 = MULTIPLY(tmp10 + tmp12, FIX(0.613604268));   /* c5 */\n    tmp0 += tmp3;\n    tmp2 += tmp3 + MULTIPLY(tmp12, FIX(1.870828693));   /* c3+c1-c5 */\n\n    dataptr[1] = (DCTELEM) DESCALE(tmp0, CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM) DESCALE(tmp1, CONST_BITS-PASS1_BITS);\n    dataptr[5] = (DCTELEM) DESCALE(tmp2, CONST_BITS-PASS1_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 14)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/7)*(8/14) = 32/49, which we\n   * fold into the constant multipliers:\n   * 14-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/28) * 32/49.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 7; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*3];\n    tmp13 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*2];\n    tmp4 = dataptr[DCTSIZE*4] + wsptr[DCTSIZE*1];\n    tmp5 = dataptr[DCTSIZE*5] + wsptr[DCTSIZE*0];\n    tmp6 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7];\n\n    tmp10 = tmp0 + tmp6;\n    tmp14 = tmp0 - tmp6;\n    tmp11 = tmp1 + tmp5;\n    tmp15 = tmp1 - tmp5;\n    tmp12 = tmp2 + tmp4;\n    tmp16 = tmp2 - tmp4;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*3];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*2];\n    tmp4 = dataptr[DCTSIZE*4] - wsptr[DCTSIZE*1];\n    tmp5 = dataptr[DCTSIZE*5] - wsptr[DCTSIZE*0];\n    tmp6 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12 + tmp13,\n\t\t       FIX(0.653061224)),                 /* 32/49 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp13 += tmp13;\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp13, FIX(0.832106052)) + /* c4 */\n\t      MULTIPLY(tmp11 - tmp13, FIX(0.205513223)) - /* c12 */\n\t      MULTIPLY(tmp12 - tmp13, FIX(0.575835255)),  /* c8 */\n\t      CONST_BITS+PASS1_BITS);\n\n    tmp10 = MULTIPLY(tmp14 + tmp15, FIX(0.722074570));    /* c6 */\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp14, FIX(0.178337691))   /* c2-c6 */\n\t      + MULTIPLY(tmp16, FIX(0.400721155)),        /* c10 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp15, FIX(1.122795725))   /* c6+c10 */\n\t      - MULTIPLY(tmp16, FIX(0.900412262)),        /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = tmp1 + tmp2;\n    tmp11 = tmp5 - tmp4;\n    dataptr[DCTSIZE*7] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp10 + tmp3 - tmp11 - tmp6,\n\t\t       FIX(0.653061224)),                 /* 32/49 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp3  = MULTIPLY(tmp3 , FIX(0.653061224));            /* 32/49 */\n    tmp10 = MULTIPLY(tmp10, - FIX(0.103406812));          /* -c13 */\n    tmp11 = MULTIPLY(tmp11, FIX(0.917760839));            /* c1 */\n    tmp10 += tmp11 - tmp3;\n    tmp11 = MULTIPLY(tmp0 + tmp2, FIX(0.782007410)) +     /* c5 */\n\t    MULTIPLY(tmp4 + tmp6, FIX(0.491367823));      /* c9 */\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp10 + tmp11 - MULTIPLY(tmp2, FIX(1.550341076)) /* c3+c5-c13 */\n\t      + MULTIPLY(tmp4, FIX(0.731428202)),         /* c1+c11-c9 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp12 = MULTIPLY(tmp0 + tmp1, FIX(0.871740478)) +     /* c3 */\n\t    MULTIPLY(tmp5 - tmp6, FIX(0.305035186));      /* c11 */\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(tmp10 + tmp12 - MULTIPLY(tmp1, FIX(0.276965844)) /* c3-c9-c13 */\n\t      - MULTIPLY(tmp5, FIX(2.004803435)),         /* c1+c5+c11 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp11 + tmp12 + tmp3\n\t      - MULTIPLY(tmp0, FIX(0.735987049))          /* c3+c5-c1 */\n\t      - MULTIPLY(tmp6, FIX(0.082925825)),         /* c9-c11-c13 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 6x12 sample block.\n *\n * 6-point FDCT in pass 1 (rows), 12-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_6x12 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  DCTELEM workspace[8*4];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[5]);\n    tmp11 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) + GETJSAMPLE(elemptr[3]);\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[5]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[4]);\n    tmp2 = GETJSAMPLE(elemptr[2]) - GETJSAMPLE(elemptr[3]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp11 - 6 * CENTERJSAMPLE) << PASS1_BITS);\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(1.224744871)),                 /* c2 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(0.707106781)), /* c4 */\n\t      CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = DESCALE(MULTIPLY(tmp0 + tmp2, FIX(0.366025404)),     /* c5 */\n\t\t    CONST_BITS-PASS1_BITS);\n\n    dataptr[1] = (DCTELEM) (tmp10 + ((tmp0 + tmp1) << PASS1_BITS));\n    dataptr[3] = (DCTELEM) ((tmp0 - tmp1 - tmp2) << PASS1_BITS);\n    dataptr[5] = (DCTELEM) (tmp10 + ((tmp2 - tmp1) << PASS1_BITS));\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 12)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/6)*(8/12) = 8/9, which we\n   * fold into the constant multipliers:\n   * 12-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/24) * 8/9.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*3];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*2];\n    tmp2 = dataptr[DCTSIZE*2] + wsptr[DCTSIZE*1];\n    tmp3 = dataptr[DCTSIZE*3] + wsptr[DCTSIZE*0];\n    tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*7];\n    tmp5 = dataptr[DCTSIZE*5] + dataptr[DCTSIZE*6];\n\n    tmp10 = tmp0 + tmp5;\n    tmp13 = tmp0 - tmp5;\n    tmp11 = tmp1 + tmp4;\n    tmp14 = tmp1 - tmp4;\n    tmp12 = tmp2 + tmp3;\n    tmp15 = tmp2 - tmp3;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*3];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*2];\n    tmp2 = dataptr[DCTSIZE*2] - wsptr[DCTSIZE*1];\n    tmp3 = dataptr[DCTSIZE*3] - wsptr[DCTSIZE*0];\n    tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*7];\n    tmp5 = dataptr[DCTSIZE*5] - dataptr[DCTSIZE*6];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(0.888888889)), /* 8/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp13 - tmp14 - tmp15, FIX(0.888888889)), /* 8/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.088662108)),         /* c4 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp14 - tmp15, FIX(0.888888889)) +        /* 8/9 */\n\t      MULTIPLY(tmp13 + tmp15, FIX(1.214244803)),         /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp1 + tmp4, FIX(0.481063200));   /* c9 */\n    tmp14 = tmp10 + MULTIPLY(tmp1, FIX(0.680326102));  /* c3-c9 */\n    tmp15 = tmp10 - MULTIPLY(tmp4, FIX(1.642452502));  /* c3+c9 */\n    tmp12 = MULTIPLY(tmp0 + tmp2, FIX(0.997307603));   /* c5 */\n    tmp13 = MULTIPLY(tmp0 + tmp3, FIX(0.765261039));   /* c7 */\n    tmp10 = tmp12 + tmp13 + tmp14 - MULTIPLY(tmp0, FIX(0.516244403)) /* c5+c7-c1 */\n\t    + MULTIPLY(tmp5, FIX(0.164081699));        /* c11 */\n    tmp11 = MULTIPLY(tmp2 + tmp3, - FIX(0.164081699)); /* -c11 */\n    tmp12 += tmp11 - tmp15 - MULTIPLY(tmp2, FIX(2.079550144)) /* c1+c5-c11 */\n\t    + MULTIPLY(tmp5, FIX(0.765261039));        /* c7 */\n    tmp13 += tmp11 - tmp14 + MULTIPLY(tmp3, FIX(0.645144899)) /* c1+c11-c7 */\n\t    - MULTIPLY(tmp5, FIX(0.997307603));        /* c5 */\n    tmp11 = tmp15 + MULTIPLY(tmp0 - tmp3, FIX(1.161389302)) /* c3 */\n\t    - MULTIPLY(tmp2 + tmp5, FIX(0.481063200)); /* c9 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp11, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp12, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp13, CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 5x10 sample block.\n *\n * 5-point FDCT in pass 1 (rows), 10-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_5x10 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp4;\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  DCTELEM workspace[8*2];\n  DCTELEM *dataptr;\n  DCTELEM *wsptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 5-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/10).\n   */\n\n  dataptr = data;\n  ctr = 0;\n  for (;;) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[4]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[3]);\n    tmp2 = GETJSAMPLE(elemptr[2]);\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n\n    tmp0 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[4]);\n    tmp1 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[3]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp10 + tmp2 - 5 * CENTERJSAMPLE) << PASS1_BITS);\n    tmp11 = MULTIPLY(tmp11, FIX(0.790569415));          /* (c2+c4)/2 */\n    tmp10 -= tmp2 << 2;\n    tmp10 = MULTIPLY(tmp10, FIX(0.353553391));          /* (c2-c4)/2 */\n    dataptr[2] = (DCTELEM) DESCALE(tmp11 + tmp10, CONST_BITS-PASS1_BITS);\n    dataptr[4] = (DCTELEM) DESCALE(tmp11 - tmp10, CONST_BITS-PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp1, FIX(0.831253876));    /* c3 */\n\n    dataptr[1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0, FIX(0.513743148)), /* c1-c3 */\n\t      CONST_BITS-PASS1_BITS);\n    dataptr[3] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp1, FIX(2.176250899)), /* c1+c3 */\n\t      CONST_BITS-PASS1_BITS);\n\n    ctr++;\n\n    if (ctr != DCTSIZE) {\n      if (ctr == 10)\n\tbreak;\t\t\t/* Done. */\n      dataptr += DCTSIZE;\t/* advance pointer to next row */\n    } else\n      dataptr = workspace;\t/* switch pointer to extended workspace */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/5)*(8/10) = 32/25, which we\n   * fold into the constant multipliers:\n   * 10-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/20) * 32/25.\n   */\n\n  dataptr = data;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 5; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + wsptr[DCTSIZE*1];\n    tmp1 = dataptr[DCTSIZE*1] + wsptr[DCTSIZE*0];\n    tmp12 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*7];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*6];\n    tmp4 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5];\n\n    tmp10 = tmp0 + tmp4;\n    tmp13 = tmp0 - tmp4;\n    tmp11 = tmp1 + tmp3;\n    tmp14 = tmp1 - tmp3;\n\n    tmp0 = dataptr[DCTSIZE*0] - wsptr[DCTSIZE*1];\n    tmp1 = dataptr[DCTSIZE*1] - wsptr[DCTSIZE*0];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*7];\n    tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*6];\n    tmp4 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11 + tmp12, FIX(1.28)), /* 32/25 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp12 += tmp12;\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp12, FIX(1.464477191)) - /* c4 */\n\t      MULTIPLY(tmp11 - tmp12, FIX(0.559380511)),  /* c8 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp10 = MULTIPLY(tmp13 + tmp14, FIX(1.064004961));    /* c6 */\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp13, FIX(0.657591230)),  /* c2-c6 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      DESCALE(tmp10 - MULTIPLY(tmp14, FIX(2.785601151)),  /* c2+c6 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = tmp0 + tmp4;\n    tmp11 = tmp1 - tmp3;\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp2, FIX(1.28)),  /* 32/25 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp2 = MULTIPLY(tmp2, FIX(1.28));                     /* 32/25 */\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0, FIX(1.787906876)) +          /* c1 */\n\t      MULTIPLY(tmp1, FIX(1.612894094)) + tmp2 +   /* c3 */\n\t      MULTIPLY(tmp3, FIX(0.821810588)) +          /* c7 */\n\t      MULTIPLY(tmp4, FIX(0.283176630)),           /* c9 */\n\t      CONST_BITS+PASS1_BITS);\n    tmp12 = MULTIPLY(tmp0 - tmp4, FIX(1.217352341)) -     /* (c3+c7)/2 */\n\t    MULTIPLY(tmp1 + tmp3, FIX(0.752365123));      /* (c1-c9)/2 */\n    tmp13 = MULTIPLY(tmp10 + tmp11, FIX(0.395541753)) +   /* (c3-c7)/2 */\n\t    MULTIPLY(tmp11, FIX(0.64)) - tmp2;            /* 16/25 */\n    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp12 + tmp13, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp12 - tmp13, CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n    wsptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 4x8 sample block.\n *\n * 4-point FDCT in pass 1 (rows), 8-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_4x8 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We must also scale the output by 8/4 = 2, which we add here.\n   * 4-point FDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[3]);\n    tmp1 = GETJSAMPLE(elemptr[1]) + GETJSAMPLE(elemptr[2]);\n\n    tmp10 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[3]);\n    tmp11 = GETJSAMPLE(elemptr[1]) - GETJSAMPLE(elemptr[2]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 - 4 * CENTERJSAMPLE) << (PASS1_BITS+1));\n    dataptr[2] = (DCTELEM) ((tmp0 - tmp1) << (PASS1_BITS+1));\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-2);\n\n    dataptr[1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS-PASS1_BITS-1);\n    dataptr[3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS-PASS1_BITS-1);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * 8-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    /* Even part per LL&M figure 1 --- note that published figure is faulty;\n     * rotator \"c1\" should be \"c6\".\n     */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];\n\n    /* Add fudge factor here for final descale. */\n    tmp10 = tmp0 + tmp3 + (ONE << (PASS1_BITS-1));\n    tmp12 = tmp0 - tmp3;\n    tmp11 = tmp1 + tmp2;\n    tmp13 = tmp1 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];\n    tmp3 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) RIGHT_SHIFT(tmp10 + tmp11, PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM) RIGHT_SHIFT(tmp10 - tmp11, PASS1_BITS);\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      RIGHT_SHIFT(z1 + MULTIPLY(tmp12, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*6] = (DCTELEM)\n      RIGHT_SHIFT(z1 - MULTIPLY(tmp13, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS+PASS1_BITS);\n\n    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).\n     * i0..i3 in the paper are tmp0..tmp3 here.\n     */\n\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(tmp12 + tmp13, FIX_1_175875602);       /*  c3 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS+PASS1_BITS-1);\n\n    tmp12 = MULTIPLY(tmp12, - FIX_0_390180644);          /* -c3+c5 */\n    tmp13 = MULTIPLY(tmp13, - FIX_1_961570560);          /* -c3-c5 */\n    tmp12 += z1;\n    tmp13 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223);       /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_1_501321110);              /*  c1+c3-c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_0_298631336);              /* -c1+c3+c5-c7 */\n    tmp0 += z1 + tmp12;\n    tmp3 += z1 + tmp13;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447);       /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_3_072711026);              /*  c1+c3+c5-c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_2_053119869);              /*  c1+c3-c5+c7 */\n    tmp1 += z1 + tmp13;\n    tmp2 += z1 + tmp12;\n\n    dataptr[DCTSIZE*1] = (DCTELEM) RIGHT_SHIFT(tmp0, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM) RIGHT_SHIFT(tmp1, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM) RIGHT_SHIFT(tmp2, CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*7] = (DCTELEM) RIGHT_SHIFT(tmp3, CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 3x6 sample block.\n *\n * 3-point FDCT in pass 1 (rows), 6-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_3x6 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1, tmp2;\n  INT32 tmp10, tmp11, tmp12;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * We scale the results further by 2 as part of output adaption\n   * scaling for different DCT size.\n   * 3-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/6).\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 6; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]) + GETJSAMPLE(elemptr[2]);\n    tmp1 = GETJSAMPLE(elemptr[1]);\n\n    tmp2 = GETJSAMPLE(elemptr[0]) - GETJSAMPLE(elemptr[2]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM)\n      ((tmp0 + tmp1 - 3 * CENTERJSAMPLE) << (PASS1_BITS+1));\n    dataptr[2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp1, FIX(0.707106781)), /* c2 */\n\t      CONST_BITS-PASS1_BITS-1);\n\n    /* Odd part */\n\n    dataptr[1] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp2, FIX(1.224744871)),               /* c1 */\n\t      CONST_BITS-PASS1_BITS-1);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We remove the PASS1_BITS scaling, but leave the results scaled up\n   * by an overall factor of 8.\n   * We must also scale the output by (8/6)*(8/3) = 32/9, which we partially\n   * fold into the constant multipliers (other part was done in pass 1):\n   * 6-point FDCT kernel, cK represents sqrt(2) * cos(K*pi/12) * 16/9.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 3; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*5];\n    tmp11 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3];\n\n    tmp10 = tmp0 + tmp2;\n    tmp12 = tmp0 - tmp2;\n\n    tmp0 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*5];\n    tmp1 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*4];\n    tmp2 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3];\n\n    dataptr[DCTSIZE*0] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 + tmp11, FIX(1.777777778)),         /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*2] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp12, FIX(2.177324216)),                 /* c2 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*4] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp10 - tmp11 - tmp11, FIX(1.257078722)), /* c4 */\n\t      CONST_BITS+PASS1_BITS);\n\n    /* Odd part */\n\n    tmp10 = MULTIPLY(tmp0 + tmp2, FIX(0.650711829));             /* c5 */\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp0 + tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      DESCALE(MULTIPLY(tmp0 - tmp1 - tmp2, FIX(1.777777778)),    /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n    dataptr[DCTSIZE*5] = (DCTELEM)\n      DESCALE(tmp10 + MULTIPLY(tmp2 - tmp1, FIX(1.777777778)),   /* 16/9 */\n\t      CONST_BITS+PASS1_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 2x4 sample block.\n *\n * 2-point FDCT in pass 1 (rows), 4-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_2x4 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  INT32 tmp0, tmp1;\n  INT32 tmp10, tmp11;\n  DCTELEM *dataptr;\n  JSAMPROW elemptr;\n  int ctr;\n  SHIFT_TEMPS\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: process rows.\n   * Note results are scaled up by sqrt(8) compared to a true DCT.\n   * We must also scale the output by (8/2)*(8/4) = 2**3, which we add here.\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 4; ctr++) {\n    elemptr = sample_data[ctr] + start_col;\n\n    /* Even part */\n\n    tmp0 = GETJSAMPLE(elemptr[0]);\n    tmp1 = GETJSAMPLE(elemptr[1]);\n\n    /* Apply unsigned->signed conversion. */\n    dataptr[0] = (DCTELEM) ((tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 3);\n\n    /* Odd part */\n\n    dataptr[1] = (DCTELEM) ((tmp0 - tmp1) << 3);\n\n    dataptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * 4-point FDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point FDCT].\n   */\n\n  dataptr = data;\n  for (ctr = 0; ctr < 2; ctr++) {\n    /* Even part */\n\n    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*3];\n    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*2];\n\n    tmp10 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*3];\n    tmp11 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*2];\n\n    dataptr[DCTSIZE*0] = (DCTELEM) (tmp0 + tmp1);\n    dataptr[DCTSIZE*2] = (DCTELEM) (tmp0 - tmp1);\n\n    /* Odd part */\n\n    tmp0 = MULTIPLY(tmp10 + tmp11, FIX_0_541196100);       /* c6 */\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-1);\n\n    dataptr[DCTSIZE*1] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 + MULTIPLY(tmp10, FIX_0_765366865), /* c2-c6 */\n\t\t  CONST_BITS);\n    dataptr[DCTSIZE*3] = (DCTELEM)\n      RIGHT_SHIFT(tmp0 - MULTIPLY(tmp11, FIX_1_847759065), /* c2+c6 */\n\t\t  CONST_BITS);\n\n    dataptr++;\t\t\t/* advance pointer to next column */\n  }\n}\n\n\n/*\n * Perform the forward DCT on a 1x2 sample block.\n *\n * 1-point FDCT in pass 1 (rows), 2-point in pass 2 (columns).\n */\n\nGLOBAL(void)\njpeg_fdct_1x2 (DCTELEM * data, JSAMPARRAY sample_data, JDIMENSION start_col)\n{\n  DCTELEM tmp0, tmp1;\n\n  /* Pre-zero output coefficient block. */\n  MEMZERO(data, SIZEOF(DCTELEM) * DCTSIZE2);\n\n  /* Pass 1: empty. */\n\n  /* Pass 2: process columns.\n   * We leave the results scaled up by an overall factor of 8.\n   * We must also scale the output by (8/1)*(8/2) = 2**5.\n   */\n\n  /* Even part */\n\n  tmp0 = GETJSAMPLE(sample_data[0][start_col]);\n  tmp1 = GETJSAMPLE(sample_data[1][start_col]);\n\n  /* Apply unsigned->signed conversion. */\n  data[DCTSIZE*0] = (tmp0 + tmp1 - 2 * CENTERJSAMPLE) << 5;\n\n  /* Odd part */\n\n  data[DCTSIZE*1] = (tmp0 - tmp1) << 5;\n}\n\n#endif /* DCT_SCALING_SUPPORTED */\n#endif /* DCT_ISLOW_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jidctflt.c",
    "content": "/*\n * jidctflt.c\n *\n * Copyright (C) 1994-1998, Thomas G. Lane.\n * Modified 2010-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a floating-point implementation of the\n * inverse DCT (Discrete Cosine Transform).  In the IJG code, this routine\n * must also perform dequantization of the input coefficients.\n *\n * This implementation should be more accurate than either of the integer\n * IDCT implementations.  However, it may not give the same results on all\n * machines because of differences in roundoff behavior.  Speed will depend\n * on the hardware's floating point capacity.\n *\n * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT\n * on each row (or vice versa, but it's more convenient to emit a row at\n * a time).  Direct algorithms are also available, but they are much more\n * complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on Arai, Agui, and Nakajima's algorithm for\n * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in\n * Japanese, but the algorithm is described in the Pennebaker & Mitchell\n * JPEG textbook (see REFERENCES section in file README).  The following code\n * is based directly on figure 4-8 in P&M.\n * While an 8-point DCT cannot be done in less than 11 multiplies, it is\n * possible to arrange the computation so that many of the multiplies are\n * simple scalings of the final outputs.  These multiplies can then be\n * folded into the multiplications or divisions by the JPEG quantization\n * table entries.  The AA&N method leaves only 5 multiplies and 29 adds\n * to be done in the DCT itself.\n * The primary disadvantage of this method is that with a fixed-point\n * implementation, accuracy is lost due to imprecise representation of the\n * scaled quantization values.  However, that problem does not arise if\n * we use floating point arithmetic.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_FLOAT_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */\n#endif\n\n\n/* Dequantize a coefficient by multiplying it by the multiplier-table\n * entry; produce a float result.\n */\n\n#define DEQUANTIZE(coef,quantval)  (((FAST_FLOAT) (coef)) * (quantval))\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients.\n *\n * cK represents cos(K*pi/16).\n */\n\nGLOBAL(void)\njpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  FAST_FLOAT tmp10, tmp11, tmp12, tmp13;\n  FAST_FLOAT z5, z10, z11, z12, z13;\n  JCOEFPTR inptr;\n  FLOAT_MULT_TYPE * quantptr;\n  FAST_FLOAT * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = DCTSIZE; ctr > 0; ctr--) {\n    /* Due to quantization, we will usually find that many of the input\n     * coefficients are zero, especially the AC terms.  We can exploit this\n     * by short-circuiting the IDCT calculation for any column in which all\n     * the AC terms are zero.  In that case each output is equal to the\n     * DC coefficient (with scale factor as needed).\n     * With typical images and quantization tables, half or more of the\n     * column DCT calculations can be simplified this way.\n     */\n\n    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&\n\tinptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&\n\tinptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&\n\tinptr[DCTSIZE*7] == 0) {\n      /* AC terms all zero */\n      FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n\n      wsptr[DCTSIZE*0] = dcval;\n      wsptr[DCTSIZE*1] = dcval;\n      wsptr[DCTSIZE*2] = dcval;\n      wsptr[DCTSIZE*3] = dcval;\n      wsptr[DCTSIZE*4] = dcval;\n      wsptr[DCTSIZE*5] = dcval;\n      wsptr[DCTSIZE*6] = dcval;\n      wsptr[DCTSIZE*7] = dcval;\n\n      inptr++;\t\t\t/* advance pointers to next column */\n      quantptr++;\n      wsptr++;\n      continue;\n    }\n\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp10 = tmp0 + tmp2;\t/* phase 3 */\n    tmp11 = tmp0 - tmp2;\n\n    tmp13 = tmp1 + tmp3;\t/* phases 5-3 */\n    tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */\n\n    tmp0 = tmp10 + tmp13;\t/* phase 2 */\n    tmp3 = tmp10 - tmp13;\n    tmp1 = tmp11 + tmp12;\n    tmp2 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    z13 = tmp6 + tmp5;\t\t/* phase 6 */\n    z10 = tmp6 - tmp5;\n    z11 = tmp4 + tmp7;\n    z12 = tmp4 - tmp7;\n\n    tmp7 = z11 + z13;\t\t/* phase 5 */\n    tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */\n\n    z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */\n    tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */\n    tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */\n\n    tmp6 = tmp12 - tmp7;\t/* phase 2 */\n    tmp5 = tmp11 - tmp6;\n    tmp4 = tmp10 - tmp5;\n\n    wsptr[DCTSIZE*0] = tmp0 + tmp7;\n    wsptr[DCTSIZE*7] = tmp0 - tmp7;\n    wsptr[DCTSIZE*1] = tmp1 + tmp6;\n    wsptr[DCTSIZE*6] = tmp1 - tmp6;\n    wsptr[DCTSIZE*2] = tmp2 + tmp5;\n    wsptr[DCTSIZE*5] = tmp2 - tmp5;\n    wsptr[DCTSIZE*3] = tmp3 + tmp4;\n    wsptr[DCTSIZE*4] = tmp3 - tmp4;\n\n    inptr++;\t\t\t/* advance pointers to next column */\n    quantptr++;\n    wsptr++;\n  }\n\n  /* Pass 2: process rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n    /* Rows of zeroes can be exploited in the same way as we did with columns.\n     * However, the column calculation has created many nonzero AC terms, so\n     * the simplification applies less often (typically 5% to 10% of the time).\n     * And testing floats for zero is relatively expensive, so we don't bother.\n     */\n\n    /* Even part */\n\n    /* Prepare range-limit and float->int conversion */\n    z5 = wsptr[0] + (((FAST_FLOAT) RANGE_CENTER) + ((FAST_FLOAT) 0.5));\n    tmp10 = z5 + wsptr[4];\n    tmp11 = z5 - wsptr[4];\n\n    tmp13 = wsptr[2] + wsptr[6];\n    tmp12 = (wsptr[2] - wsptr[6]) *\n\t      ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */\n\n    tmp0 = tmp10 + tmp13;\n    tmp3 = tmp10 - tmp13;\n    tmp1 = tmp11 + tmp12;\n    tmp2 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z13 = wsptr[5] + wsptr[3];\n    z10 = wsptr[5] - wsptr[3];\n    z11 = wsptr[1] + wsptr[7];\n    z12 = wsptr[1] - wsptr[7];\n\n    tmp7 = z11 + z13;\t\t/* phase 5 */\n    tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */\n\n    z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */\n    tmp10 = z5 - z12 * ((FAST_FLOAT) 1.082392200); /* 2*(c2-c6) */\n    tmp12 = z5 - z10 * ((FAST_FLOAT) 2.613125930); /* 2*(c2+c6) */\n\n    tmp6 = tmp12 - tmp7;\t/* phase 2 */\n    tmp5 = tmp11 - tmp6;\n    tmp4 = tmp10 - tmp5;\n\n    /* Final output stage: float->int conversion and range-limit */\n\n    outptr[0] = range_limit[(int) (tmp0 + tmp7) & RANGE_MASK];\n    outptr[7] = range_limit[(int) (tmp0 - tmp7) & RANGE_MASK];\n    outptr[1] = range_limit[(int) (tmp1 + tmp6) & RANGE_MASK];\n    outptr[6] = range_limit[(int) (tmp1 - tmp6) & RANGE_MASK];\n    outptr[2] = range_limit[(int) (tmp2 + tmp5) & RANGE_MASK];\n    outptr[5] = range_limit[(int) (tmp2 - tmp5) & RANGE_MASK];\n    outptr[3] = range_limit[(int) (tmp3 + tmp4) & RANGE_MASK];\n    outptr[4] = range_limit[(int) (tmp3 - tmp4) & RANGE_MASK];\n\n    wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n}\n\n#endif /* DCT_FLOAT_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jidctfst.c",
    "content": "/*\n * jidctfst.c\n *\n * Copyright (C) 1994-1998, Thomas G. Lane.\n * Modified 2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a fast, not so accurate integer implementation of the\n * inverse DCT (Discrete Cosine Transform).  In the IJG code, this routine\n * must also perform dequantization of the input coefficients.\n *\n * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT\n * on each row (or vice versa, but it's more convenient to emit a row at\n * a time).  Direct algorithms are also available, but they are much more\n * complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on Arai, Agui, and Nakajima's algorithm for\n * scaled DCT.  Their original paper (Trans. IEICE E-71(11):1095) is in\n * Japanese, but the algorithm is described in the Pennebaker & Mitchell\n * JPEG textbook (see REFERENCES section in file README).  The following code\n * is based directly on figure 4-8 in P&M.\n * While an 8-point DCT cannot be done in less than 11 multiplies, it is\n * possible to arrange the computation so that many of the multiplies are\n * simple scalings of the final outputs.  These multiplies can then be\n * folded into the multiplications or divisions by the JPEG quantization\n * table entries.  The AA&N method leaves only 5 multiplies and 29 adds\n * to be done in the DCT itself.\n * The primary disadvantage of this method is that with fixed-point math,\n * accuracy is lost due to imprecise representation of the scaled\n * quantization values.  The smaller the quantization table entry, the less\n * precise the scaled value, so this implementation does worse with high-\n * quality-setting files than with low-quality ones.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_IFAST_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */\n#endif\n\n\n/* Scaling decisions are generally the same as in the LL&M algorithm;\n * see jidctint.c for more details.  However, we choose to descale\n * (right shift) multiplication products as soon as they are formed,\n * rather than carrying additional fractional bits into subsequent additions.\n * This compromises accuracy slightly, but it lets us save a few shifts.\n * More importantly, 16-bit arithmetic is then adequate (for 8-bit samples)\n * everywhere except in the multiplications proper; this saves a good deal\n * of work on 16-bit-int machines.\n *\n * The dequantized coefficients are not integers because the AA&N scaling\n * factors have been incorporated.  We represent them scaled up by PASS1_BITS,\n * so that the first and second IDCT rounds have the same input scaling.\n * For 8-bit JSAMPLEs, we choose IFAST_SCALE_BITS = PASS1_BITS so as to\n * avoid a descaling shift; this compromises accuracy rather drastically\n * for small quantization table entries, but it saves a lot of shifts.\n * For 12-bit JSAMPLEs, there's no hope of using 16x16 multiplies anyway,\n * so we use a much larger scaling factor to preserve accuracy.\n *\n * A final compromise is to represent the multiplicative constants to only\n * 8 fractional bits, rather than 13.  This saves some shifting work on some\n * machines, and may also reduce the cost of multiplication (since there\n * are fewer one-bits in the constants).\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define CONST_BITS  8\n#define PASS1_BITS  2\n#else\n#define CONST_BITS  8\n#define PASS1_BITS  1\t\t/* lose a little precision to avoid overflow */\n#endif\n\n/* Some C compilers fail to reduce \"FIX(constant)\" at compile time, thus\n * causing a lot of useless floating-point operations at run time.\n * To get around this we use the following pre-calculated constants.\n * If you change CONST_BITS you may want to add appropriate values.\n * (With a reasonable C compiler, you can just rely on the FIX() macro...)\n */\n\n#if CONST_BITS == 8\n#define FIX_1_082392200  ((INT32)  277)\t\t/* FIX(1.082392200) */\n#define FIX_1_414213562  ((INT32)  362)\t\t/* FIX(1.414213562) */\n#define FIX_1_847759065  ((INT32)  473)\t\t/* FIX(1.847759065) */\n#define FIX_2_613125930  ((INT32)  669)\t\t/* FIX(2.613125930) */\n#else\n#define FIX_1_082392200  FIX(1.082392200)\n#define FIX_1_414213562  FIX(1.414213562)\n#define FIX_1_847759065  FIX(1.847759065)\n#define FIX_2_613125930  FIX(2.613125930)\n#endif\n\n\n/* We can gain a little more speed, with a further compromise in accuracy,\n * by omitting the addition in a descaling shift.  This yields an incorrectly\n * rounded result half the time...\n */\n\n#ifndef USE_ACCURATE_ROUNDING\n#undef DESCALE\n#define DESCALE(x,n)  RIGHT_SHIFT(x, n)\n#endif\n\n\n/* Multiply a DCTELEM variable by an INT32 constant, and immediately\n * descale to yield a DCTELEM result.\n */\n\n#define MULTIPLY(var,const)  ((DCTELEM) DESCALE((var) * (const), CONST_BITS))\n\n\n/* Dequantize a coefficient by multiplying it by the multiplier-table\n * entry; produce a DCTELEM result.  For 8-bit data a 16x16->16\n * multiplication will do.  For 12-bit data, the multiplier table is\n * declared INT32, so a 32-bit multiply will be used.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define DEQUANTIZE(coef,quantval)  (((IFAST_MULT_TYPE) (coef)) * (quantval))\n#else\n#define DEQUANTIZE(coef,quantval)  \\\n\tDESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)\n#endif\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients.\n *\n * cK represents cos(K*pi/16).\n */\n\nGLOBAL(void)\njpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;\n  DCTELEM tmp10, tmp11, tmp12, tmp13;\n  DCTELEM z5, z10, z11, z12, z13;\n  JCOEFPTR inptr;\n  IFAST_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[DCTSIZE2];\t/* buffers data between passes */\n  SHIFT_TEMPS\t\t\t/* for DESCALE */\n  ISHIFT_TEMPS\t\t\t/* for IRIGHT_SHIFT */\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = DCTSIZE; ctr > 0; ctr--) {\n    /* Due to quantization, we will usually find that many of the input\n     * coefficients are zero, especially the AC terms.  We can exploit this\n     * by short-circuiting the IDCT calculation for any column in which all\n     * the AC terms are zero.  In that case each output is equal to the\n     * DC coefficient (with scale factor as needed).\n     * With typical images and quantization tables, half or more of the\n     * column DCT calculations can be simplified this way.\n     */\n    \n    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&\n\tinptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&\n\tinptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&\n\tinptr[DCTSIZE*7] == 0) {\n      /* AC terms all zero */\n      int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n\n      wsptr[DCTSIZE*0] = dcval;\n      wsptr[DCTSIZE*1] = dcval;\n      wsptr[DCTSIZE*2] = dcval;\n      wsptr[DCTSIZE*3] = dcval;\n      wsptr[DCTSIZE*4] = dcval;\n      wsptr[DCTSIZE*5] = dcval;\n      wsptr[DCTSIZE*6] = dcval;\n      wsptr[DCTSIZE*7] = dcval;\n      \n      inptr++;\t\t\t/* advance pointers to next column */\n      quantptr++;\n      wsptr++;\n      continue;\n    }\n    \n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp10 = tmp0 + tmp2;\t/* phase 3 */\n    tmp11 = tmp0 - tmp2;\n\n    tmp13 = tmp1 + tmp3;\t/* phases 5-3 */\n    tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */\n\n    tmp0 = tmp10 + tmp13;\t/* phase 2 */\n    tmp3 = tmp10 - tmp13;\n    tmp1 = tmp11 + tmp12;\n    tmp2 = tmp11 - tmp12;\n    \n    /* Odd part */\n\n    tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    z13 = tmp6 + tmp5;\t\t/* phase 6 */\n    z10 = tmp6 - tmp5;\n    z11 = tmp4 + tmp7;\n    z12 = tmp4 - tmp7;\n\n    tmp7 = z11 + z13;\t\t/* phase 5 */\n    tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */\n\n    z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */\n    tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */\n    tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */\n\n    tmp6 = tmp12 - tmp7;\t/* phase 2 */\n    tmp5 = tmp11 - tmp6;\n    tmp4 = tmp10 - tmp5;\n\n    wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);\n    wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);\n    wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);\n    wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);\n    wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);\n    wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);\n    wsptr[DCTSIZE*3] = (int) (tmp3 + tmp4);\n    wsptr[DCTSIZE*4] = (int) (tmp3 - tmp4);\n\n    inptr++;\t\t\t/* advance pointers to next column */\n    quantptr++;\n    wsptr++;\n  }\n  \n  /* Pass 2: process rows from work array, store into output array.\n   * Note that we must descale the results by a factor of 8 == 2**3,\n   * and also undo the PASS1_BITS scaling.\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z5 = (DCTELEM) wsptr[0] +\n\t   ((((DCTELEM) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (1 << (PASS1_BITS+2)));\n\n    /* Rows of zeroes can be exploited in the same way as we did with columns.\n     * However, the column calculation has created many nonzero AC terms, so\n     * the simplification applies less often (typically 5% to 10% of the time).\n     * On machines with very fast multiplication, it's possible that the\n     * test takes more time than it's worth.  In that case this section\n     * may be commented out.\n     */\n    \n#ifndef NO_ZERO_ROW_TEST\n    if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&\n\twsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {\n      /* AC terms all zero */\n      JSAMPLE dcval = range_limit[(int) IRIGHT_SHIFT(z5, PASS1_BITS+3)\n\t\t\t\t  & RANGE_MASK];\n      \n      outptr[0] = dcval;\n      outptr[1] = dcval;\n      outptr[2] = dcval;\n      outptr[3] = dcval;\n      outptr[4] = dcval;\n      outptr[5] = dcval;\n      outptr[6] = dcval;\n      outptr[7] = dcval;\n\n      wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n      continue;\n    }\n#endif\n    \n    /* Even part */\n\n    tmp10 = z5 + (DCTELEM) wsptr[4];\n    tmp11 = z5 - (DCTELEM) wsptr[4];\n\n    tmp13 = (DCTELEM) wsptr[2] + (DCTELEM) wsptr[6];\n    tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6],\n\t\t     FIX_1_414213562) - tmp13; /* 2*c4 */\n\n    tmp0 = tmp10 + tmp13;\n    tmp3 = tmp10 - tmp13;\n    tmp1 = tmp11 + tmp12;\n    tmp2 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];\n    z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];\n    z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];\n    z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];\n\n    tmp7 = z11 + z13;\t\t/* phase 5 */\n    tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */\n\n    z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */\n    tmp10 = z5 - MULTIPLY(z12, FIX_1_082392200); /* 2*(c2-c6) */\n    tmp12 = z5 - MULTIPLY(z10, FIX_2_613125930); /* 2*(c2+c6) */\n\n    tmp6 = tmp12 - tmp7;\t/* phase 2 */\n    tmp5 = tmp11 - tmp6;\n    tmp4 = tmp10 - tmp5;\n\n    /* Final output stage: scale down by a factor of 8 and range-limit */\n\n    outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp7, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp7, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp1 + tmp6, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) IRIGHT_SHIFT(tmp1 - tmp6, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) IRIGHT_SHIFT(tmp2 + tmp5, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) IRIGHT_SHIFT(tmp2 - tmp5, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) IRIGHT_SHIFT(tmp3 + tmp4, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) IRIGHT_SHIFT(tmp3 - tmp4, PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n}\n\n#endif /* DCT_IFAST_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jidctint.c",
    "content": "/*\n * jidctint.c\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modification developed 2002-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a slow-but-accurate integer implementation of the\n * inverse DCT (Discrete Cosine Transform).  In the IJG code, this routine\n * must also perform dequantization of the input coefficients.\n *\n * A 2-D IDCT can be done by 1-D IDCT on each column followed by 1-D IDCT\n * on each row (or vice versa, but it's more convenient to emit a row at\n * a time).  Direct algorithms are also available, but they are much more\n * complex and seem not to be any faster when reduced to code.\n *\n * This implementation is based on an algorithm described in\n *   C. Loeffler, A. Ligtenberg and G. Moschytz, \"Practical Fast 1-D DCT\n *   Algorithms with 11 Multiplications\", Proc. Int'l. Conf. on Acoustics,\n *   Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991.\n * The primary algorithm described there uses 11 multiplies and 29 adds.\n * We use their alternate method with 12 multiplies and 32 adds.\n * The advantage of this method is that no data path contains more than one\n * multiplication; this allows a very simple and accurate implementation in\n * scaled fixed-point arithmetic, with a minimal number of shifts.\n *\n * We also provide IDCT routines with various output sample block sizes for\n * direct resolution reduction or enlargement and for direct resolving the\n * common 2x1 and 1x2 subsampling cases without additional resampling: NxN\n * (N=1...16), 2NxN, and Nx2N (N=1...8) pixels for one 8x8 input DCT block.\n *\n * For N<8 we simply take the corresponding low-frequency coefficients of\n * the 8x8 input DCT block and apply an NxN point IDCT on the sub-block\n * to yield the downscaled outputs.\n * This can be seen as direct low-pass downsampling from the DCT domain\n * point of view rather than the usual spatial domain point of view,\n * yielding significant computational savings and results at least\n * as good as common bilinear (averaging) spatial downsampling.\n *\n * For N>8 we apply a partial NxN IDCT on the 8 input coefficients as\n * lower frequencies and higher frequencies assumed to be zero.\n * It turns out that the computational effort is similar to the 8x8 IDCT\n * regarding the output size.\n * Furthermore, the scaling and descaling is the same for all IDCT sizes.\n *\n * CAUTION: We rely on the FIX() macro except for the N=1,2,4,8 cases\n * since there would be too many additional constants to pre-calculate.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jdct.h\"\t\t/* Private declarations for DCT subsystem */\n\n#ifdef DCT_ISLOW_SUPPORTED\n\n\n/*\n * This module is specialized to the case DCTSIZE = 8.\n */\n\n#if DCTSIZE != 8\n  Sorry, this code only copes with 8x8 DCT blocks. /* deliberate syntax err */\n#endif\n\n\n/*\n * The poop on this scaling stuff is as follows:\n *\n * Each 1-D IDCT step produces outputs which are a factor of sqrt(N)\n * larger than the true IDCT outputs.  The final outputs are therefore\n * a factor of N larger than desired; since N=8 this can be cured by\n * a simple right shift at the end of the algorithm.  The advantage of\n * this arrangement is that we save two multiplications per 1-D IDCT,\n * because the y0 and y4 inputs need not be divided by sqrt(N).\n *\n * We have to do addition and subtraction of the integer inputs, which\n * is no problem, and multiplication by fractional constants, which is\n * a problem to do in integer arithmetic.  We multiply all the constants\n * by CONST_SCALE and convert them to integer constants (thus retaining\n * CONST_BITS bits of precision in the constants).  After doing a\n * multiplication we have to divide the product by CONST_SCALE, with proper\n * rounding, to produce the correct output.  This division can be done\n * cheaply as a right shift of CONST_BITS bits.  We postpone shifting\n * as long as possible so that partial sums can be added together with\n * full fractional precision.\n *\n * The outputs of the first pass are scaled up by PASS1_BITS bits so that\n * they are represented to better-than-integral precision.  These outputs\n * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word\n * with the recommended scaling.  (To scale up 12-bit sample data further, an\n * intermediate INT32 array would be needed.)\n *\n * To avoid overflow of the 32-bit intermediate results in pass 2, we must\n * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26.  Error analysis\n * shows that the values given below are the most effective.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define CONST_BITS  13\n#define PASS1_BITS  2\n#else\n#define CONST_BITS  13\n#define PASS1_BITS  1\t\t/* lose a little precision to avoid overflow */\n#endif\n\n/* Some C compilers fail to reduce \"FIX(constant)\" at compile time, thus\n * causing a lot of useless floating-point operations at run time.\n * To get around this we use the following pre-calculated constants.\n * If you change CONST_BITS you may want to add appropriate values.\n * (With a reasonable C compiler, you can just rely on the FIX() macro...)\n */\n\n#if CONST_BITS == 13\n#define FIX_0_298631336  ((INT32)  2446)\t/* FIX(0.298631336) */\n#define FIX_0_390180644  ((INT32)  3196)\t/* FIX(0.390180644) */\n#define FIX_0_541196100  ((INT32)  4433)\t/* FIX(0.541196100) */\n#define FIX_0_765366865  ((INT32)  6270)\t/* FIX(0.765366865) */\n#define FIX_0_899976223  ((INT32)  7373)\t/* FIX(0.899976223) */\n#define FIX_1_175875602  ((INT32)  9633)\t/* FIX(1.175875602) */\n#define FIX_1_501321110  ((INT32)  12299)\t/* FIX(1.501321110) */\n#define FIX_1_847759065  ((INT32)  15137)\t/* FIX(1.847759065) */\n#define FIX_1_961570560  ((INT32)  16069)\t/* FIX(1.961570560) */\n#define FIX_2_053119869  ((INT32)  16819)\t/* FIX(2.053119869) */\n#define FIX_2_562915447  ((INT32)  20995)\t/* FIX(2.562915447) */\n#define FIX_3_072711026  ((INT32)  25172)\t/* FIX(3.072711026) */\n#else\n#define FIX_0_298631336  FIX(0.298631336)\n#define FIX_0_390180644  FIX(0.390180644)\n#define FIX_0_541196100  FIX(0.541196100)\n#define FIX_0_765366865  FIX(0.765366865)\n#define FIX_0_899976223  FIX(0.899976223)\n#define FIX_1_175875602  FIX(1.175875602)\n#define FIX_1_501321110  FIX(1.501321110)\n#define FIX_1_847759065  FIX(1.847759065)\n#define FIX_1_961570560  FIX(1.961570560)\n#define FIX_2_053119869  FIX(2.053119869)\n#define FIX_2_562915447  FIX(2.562915447)\n#define FIX_3_072711026  FIX(3.072711026)\n#endif\n\n\n/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result.\n * For 8-bit samples with the recommended scaling, all the variable\n * and constant values involved are no more than 16 bits wide, so a\n * 16x16->32 bit multiply can be used instead of a full 32x32 multiply.\n * For 12-bit samples, a full 32-bit multiplication will be needed.\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define MULTIPLY(var,const)  MULTIPLY16C16(var,const)\n#else\n#define MULTIPLY(var,const)  ((var) * (const))\n#endif\n\n\n/* Dequantize a coefficient by multiplying it by the multiplier-table\n * entry; produce an int result.  In this module, both inputs and result\n * are 16 bits or less, so either int or short multiply will work.\n */\n\n#define DEQUANTIZE(coef,quantval)  (((ISLOW_MULT_TYPE) (coef)) * (quantval))\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients.\n *\n * cK represents sqrt(2) * cos(K*pi/16).\n */\n\nGLOBAL(void)\njpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[DCTSIZE2];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * Note results are scaled up by sqrt(8) compared to a true IDCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = DCTSIZE; ctr > 0; ctr--) {\n    /* Due to quantization, we will usually find that many of the input\n     * coefficients are zero, especially the AC terms.  We can exploit this\n     * by short-circuiting the IDCT calculation for any column in which all\n     * the AC terms are zero.  In that case each output is equal to the\n     * DC coefficient (with scale factor as needed).\n     * With typical images and quantization tables, half or more of the\n     * column DCT calculations can be simplified this way.\n     */\n\n    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&\n\tinptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&\n\tinptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&\n\tinptr[DCTSIZE*7] == 0) {\n      /* AC terms all zero */\n      int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;\n\n      wsptr[DCTSIZE*0] = dcval;\n      wsptr[DCTSIZE*1] = dcval;\n      wsptr[DCTSIZE*2] = dcval;\n      wsptr[DCTSIZE*3] = dcval;\n      wsptr[DCTSIZE*4] = dcval;\n      wsptr[DCTSIZE*5] = dcval;\n      wsptr[DCTSIZE*6] = dcval;\n      wsptr[DCTSIZE*7] = dcval;\n\n      inptr++;\t\t\t/* advance pointers to next column */\n      quantptr++;\n      wsptr++;\n      continue;\n    }\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z2 <<= CONST_BITS;\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z2 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    tmp0 = z2 + z3;\n    tmp1 = z2 - z3;\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);\n\n    inptr++;\t\t\t/* advance pointers to next column */\n    quantptr++;\n    wsptr++;\n  }\n\n  /* Pass 2: process rows from work array, store into output array.\n   * Note that we must descale the results by a factor of 8 == 2**3,\n   * and also undo the PASS1_BITS scaling.\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < DCTSIZE; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z2 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n\n    /* Rows of zeroes can be exploited in the same way as we did with columns.\n     * However, the column calculation has created many nonzero AC terms, so\n     * the simplification applies less often (typically 5% to 10% of the time).\n     * On machines with very fast multiplication, it's possible that the\n     * test takes more time than it's worth.  In that case this section\n     * may be commented out.\n     */\n\n#ifndef NO_ZERO_ROW_TEST\n    if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&\n\twsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {\n      /* AC terms all zero */\n      JSAMPLE dcval = range_limit[(int) RIGHT_SHIFT(z2, PASS1_BITS+3)\n\t\t\t\t  & RANGE_MASK];\n\n      outptr[0] = dcval;\n      outptr[1] = dcval;\n      outptr[2] = dcval;\n      outptr[3] = dcval;\n      outptr[4] = dcval;\n      outptr[5] = dcval;\n      outptr[6] = dcval;\n      outptr[7] = dcval;\n\n      wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n      continue;\n    }\n#endif\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    z3 = (INT32) wsptr[4];\n\n    tmp0 = (z2 + z3) << CONST_BITS;\n    tmp1 = (z2 - z3) << CONST_BITS;\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[6];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = (INT32) wsptr[7];\n    tmp1 = (INT32) wsptr[5];\n    tmp2 = (INT32) wsptr[3];\n    tmp3 = (INT32) wsptr[1];\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n}\n\n#ifdef IDCT_SCALING_SUPPORTED\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 7x7 output block.\n *\n * Optimized algorithm with 12 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/14).\n */\n\nGLOBAL(void)\njpeg_idct_7x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12, tmp13;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[7*7];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp13 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp13 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp13 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734));     /* c4 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123));     /* c6 */\n    tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */\n    tmp0 = z1 + z3;\n    z2 -= tmp0;\n    tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */\n    tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536));  /* c2-c4-c6 */\n    tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249));  /* c2+c4+c6 */\n    tmp13 += MULTIPLY(z2, FIX(1.414213562));         /* c0 */\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n\n    tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347));      /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339));      /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276));    /* -c1 */\n    tmp1 += tmp2;\n    z2 = MULTIPLY(z1 + z3, FIX(0.613604268));        /* c5 */\n    tmp0 += z2;\n    tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693));     /* c3+c1-c5 */\n\n    /* Final output stage */\n\n    wsptr[7*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[7*6] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[7*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[7*5] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[7*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[7*4] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[7*3] = (int) RIGHT_SHIFT(tmp13, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 7 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 7; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp13 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp13 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[4];\n    z3 = (INT32) wsptr[6];\n\n    tmp10 = MULTIPLY(z2 - z3, FIX(0.881747734));     /* c4 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.314692123));     /* c6 */\n    tmp11 = tmp10 + tmp12 + tmp13 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */\n    tmp0 = z1 + z3;\n    z2 -= tmp0;\n    tmp0 = MULTIPLY(tmp0, FIX(1.274162392)) + tmp13; /* c2 */\n    tmp10 += tmp0 - MULTIPLY(z3, FIX(0.077722536));  /* c2-c4-c6 */\n    tmp12 += tmp0 - MULTIPLY(z1, FIX(2.470602249));  /* c2+c4+c6 */\n    tmp13 += MULTIPLY(z2, FIX(1.414213562));         /* c0 */\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n\n    tmp1 = MULTIPLY(z1 + z2, FIX(0.935414347));      /* (c3+c1-c5)/2 */\n    tmp2 = MULTIPLY(z1 - z2, FIX(0.170262339));      /* (c3+c5-c1)/2 */\n    tmp0 = tmp1 - tmp2;\n    tmp1 += tmp2;\n    tmp2 = MULTIPLY(z2 + z3, - FIX(1.378756276));    /* -c1 */\n    tmp1 += tmp2;\n    z2 = MULTIPLY(z1 + z3, FIX(0.613604268));        /* c5 */\n    tmp0 += z2;\n    tmp2 += z2 + MULTIPLY(z3, FIX(1.870828693));     /* c3+c1-c5 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 7;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 6x6 output block.\n *\n * Optimized algorithm with 3 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/12).\n */\n\nGLOBAL(void)\njpeg_idct_6x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[6*6];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp10 = MULTIPLY(tmp2, FIX(0.707106781));   /* c4 */\n    tmp1 = tmp0 + tmp10;\n    tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS-PASS1_BITS);\n    tmp10 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp0 = MULTIPLY(tmp10, FIX(1.224744871));   /* c2 */\n    tmp10 = tmp1 + tmp0;\n    tmp12 = tmp1 - tmp0;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);\n    tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);\n    tmp1 = (z1 - z2 - z3) << PASS1_BITS;\n\n    /* Final output stage */\n\n    wsptr[6*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[6*5] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[6*1] = (int) (tmp11 + tmp1);\n    wsptr[6*4] = (int) (tmp11 - tmp1);\n    wsptr[6*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[6*3] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 6 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n    tmp2 = (INT32) wsptr[4];\n    tmp10 = MULTIPLY(tmp2, FIX(0.707106781));   /* c4 */\n    tmp1 = tmp0 + tmp10;\n    tmp11 = tmp0 - tmp10 - tmp10;\n    tmp10 = (INT32) wsptr[2];\n    tmp0 = MULTIPLY(tmp10, FIX(1.224744871));   /* c2 */\n    tmp10 = tmp1 + tmp0;\n    tmp12 = tmp1 - tmp0;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);\n    tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);\n    tmp1 = (z1 - z2 - z3) << CONST_BITS;\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 6;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 5x5 output block.\n *\n * Optimized algorithm with 5 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/10).\n */\n\nGLOBAL(void)\njpeg_idct_5x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp10, tmp11, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[5*5];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp12 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */\n    z3 = tmp12 + z2;\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z1;\n    tmp12 -= z2 << 2;\n\n    /* Odd part */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));     /* c3 */\n    tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148));   /* c1-c3 */\n    tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899));   /* c1+c3 */\n\n    /* Final output stage */\n\n    wsptr[5*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[5*4] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[5*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[5*3] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[5*2] = (int) RIGHT_SHIFT(tmp12, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 5 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 5; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp12 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp12 <<= CONST_BITS;\n    tmp0 = (INT32) wsptr[2];\n    tmp1 = (INT32) wsptr[4];\n    z1 = MULTIPLY(tmp0 + tmp1, FIX(0.790569415)); /* (c2+c4)/2 */\n    z2 = MULTIPLY(tmp0 - tmp1, FIX(0.353553391)); /* (c2-c4)/2 */\n    z3 = tmp12 + z2;\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z1;\n    tmp12 -= z2 << 2;\n\n    /* Odd part */\n\n    z2 = (INT32) wsptr[1];\n    z3 = (INT32) wsptr[3];\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));     /* c3 */\n    tmp0 = z1 + MULTIPLY(z2, FIX(0.513743148));   /* c1-c3 */\n    tmp1 = z1 - MULTIPLY(z3, FIX(2.176250899));   /* c1+c3 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 5;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 4x4 output block.\n *\n * Optimized algorithm with 3 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].\n */\n\nGLOBAL(void)\njpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp2, tmp10, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[4*4];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 4; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    \n    tmp10 = (tmp0 + tmp2) << PASS1_BITS;\n    tmp12 = (tmp0 - tmp2) << PASS1_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);               /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp0 = RIGHT_SHIFT(z1 + MULTIPLY(z2, FIX_0_765366865), /* c2-c6 */\n\t\t       CONST_BITS-PASS1_BITS);\n    tmp2 = RIGHT_SHIFT(z1 - MULTIPLY(z3, FIX_1_847759065), /* c2+c6 */\n\t\t       CONST_BITS-PASS1_BITS);\n\n    /* Final output stage */\n\n    wsptr[4*0] = (int) (tmp10 + tmp0);\n    wsptr[4*3] = (int) (tmp10 - tmp0);\n    wsptr[4*1] = (int) (tmp12 + tmp2);\n    wsptr[4*2] = (int) (tmp12 - tmp2);\n  }\n\n  /* Pass 2: process 4 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 4; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp2 = (INT32) wsptr[2];\n\n    tmp10 = (tmp0 + tmp2) << CONST_BITS;\n    tmp12 = (tmp0 - tmp2) << CONST_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = (INT32) wsptr[1];\n    z3 = (INT32) wsptr[3];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);   /* c6 */\n    tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */\n    tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 4;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 3x3 output block.\n *\n * Optimized algorithm with 2 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/6).\n */\n\nGLOBAL(void)\njpeg_idct_3x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp2, tmp10, tmp12;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[3*3];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */\n    tmp10 = tmp0 + tmp12;\n    tmp2 = tmp0 - tmp12 - tmp12;\n\n    /* Odd part */\n\n    tmp12 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */\n\n    /* Final output stage */\n\n    wsptr[3*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[3*2] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[3*1] = (int) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 3 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 3; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n    tmp2 = (INT32) wsptr[2];\n    tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */\n    tmp10 = tmp0 + tmp12;\n    tmp2 = tmp0 - tmp12 - tmp12;\n\n    /* Odd part */\n\n    tmp12 = (INT32) wsptr[1];\n    tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 3;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 2x2 output block.\n *\n * Multiplication-less algorithm.\n */\n\nGLOBAL(void)\njpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5;\n  ISLOW_MULT_TYPE * quantptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  ISHIFT_TEMPS\n\n  /* Pass 1: process columns from input. */\n\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n\n  /* Column 0 */\n  tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]);\n  tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]);\n  /* Add range center and fudge factor for final descale and range-limit. */\n  tmp4 += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);\n\n  tmp0 = tmp4 + tmp5;\n  tmp2 = tmp4 - tmp5;\n\n  /* Column 1 */\n  tmp4 = DEQUANTIZE(coef_block[DCTSIZE*0+1], quantptr[DCTSIZE*0+1]);\n  tmp5 = DEQUANTIZE(coef_block[DCTSIZE*1+1], quantptr[DCTSIZE*1+1]);\n\n  tmp1 = tmp4 + tmp5;\n  tmp3 = tmp4 - tmp5;\n\n  /* Pass 2: process 2 rows, store into output array. */\n\n  /* Row 0 */\n  outptr = output_buf[0] + output_col;\n\n  outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];\n  outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];\n\n  /* Row 1 */\n  outptr = output_buf[1] + output_col;\n\n  outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp2 + tmp3, 3) & RANGE_MASK];\n  outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp2 - tmp3, 3) & RANGE_MASK];\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 1x1 output block.\n *\n * We hardly need an inverse DCT routine for this: just take the\n * average pixel value, which is one-eighth of the DC coefficient.\n */\n\nGLOBAL(void)\njpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  DCTELEM dcval;\n  ISLOW_MULT_TYPE * quantptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  ISHIFT_TEMPS\n\n  /* 1x1 is trivial: just take the DC coefficient divided by 8. */\n\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n\n  dcval = DEQUANTIZE(coef_block[0], quantptr[0]);\n  /* Add range center and fudge factor for descale and range-limit. */\n  dcval += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);\n\n  output_buf[0][output_col] =\n    range_limit[(int) IRIGHT_SHIFT(dcval, 3) & RANGE_MASK];\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 9x9 output block.\n *\n * Optimized algorithm with 10 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/18).\n */\n\nGLOBAL(void)\njpeg_idct_9x9 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*9];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp3 = MULTIPLY(z3, FIX(0.707106781));      /* c6 */\n    tmp1 = tmp0 + tmp3;\n    tmp2 = tmp0 - tmp3 - tmp3;\n\n    tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */\n    tmp11 = tmp2 + tmp0;\n    tmp14 = tmp2 - tmp0 - tmp0;\n\n    tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */\n    tmp2 = MULTIPLY(z1, FIX(1.083350441));      /* c4 */\n    tmp3 = MULTIPLY(z2, FIX(0.245575608));      /* c8 */\n\n    tmp10 = tmp1 + tmp0 - tmp3;\n    tmp12 = tmp1 - tmp0 + tmp2;\n    tmp13 = tmp1 - tmp2 + tmp3;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    z2 = MULTIPLY(z2, - FIX(1.224744871));           /* -c3 */\n\n    tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955));      /* c5 */\n    tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525));      /* c7 */\n    tmp0 = tmp2 + tmp3 - z2;\n    tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481));      /* c1 */\n    tmp2 += z2 - tmp1;\n    tmp3 += z2 + tmp1;\n    tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[8*8] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[8*1] = (int) RIGHT_SHIFT(tmp11 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[8*7] = (int) RIGHT_SHIFT(tmp11 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[8*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[8*6] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[8*3] = (int) RIGHT_SHIFT(tmp13 + tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[8*5] = (int) RIGHT_SHIFT(tmp13 - tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[8*4] = (int) RIGHT_SHIFT(tmp14, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 9 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 9; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[4];\n    z3 = (INT32) wsptr[6];\n\n    tmp3 = MULTIPLY(z3, FIX(0.707106781));      /* c6 */\n    tmp1 = tmp0 + tmp3;\n    tmp2 = tmp0 - tmp3 - tmp3;\n\n    tmp0 = MULTIPLY(z1 - z2, FIX(0.707106781)); /* c6 */\n    tmp11 = tmp2 + tmp0;\n    tmp14 = tmp2 - tmp0 - tmp0;\n\n    tmp0 = MULTIPLY(z1 + z2, FIX(1.328926049)); /* c2 */\n    tmp2 = MULTIPLY(z1, FIX(1.083350441));      /* c4 */\n    tmp3 = MULTIPLY(z2, FIX(0.245575608));      /* c8 */\n\n    tmp10 = tmp1 + tmp0 - tmp3;\n    tmp12 = tmp1 - tmp0 + tmp2;\n    tmp13 = tmp1 - tmp2 + tmp3;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    z2 = MULTIPLY(z2, - FIX(1.224744871));           /* -c3 */\n\n    tmp2 = MULTIPLY(z1 + z3, FIX(0.909038955));      /* c5 */\n    tmp3 = MULTIPLY(z1 + z4, FIX(0.483689525));      /* c7 */\n    tmp0 = tmp2 + tmp3 - z2;\n    tmp1 = MULTIPLY(z3 - z4, FIX(1.392728481));      /* c1 */\n    tmp2 += z2 - tmp1;\n    tmp3 += z2 + tmp1;\n    tmp1 = MULTIPLY(z1 - z3 - z4, FIX(1.224744871)); /* c3 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 10x10 output block.\n *\n * Optimized algorithm with 12 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/20).\n */\n\nGLOBAL(void)\njpeg_idct_10x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24;\n  INT32 z1, z2, z3, z4, z5;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*10];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z3 += ONE << (CONST_BITS-PASS1_BITS-1);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z1 = MULTIPLY(z4, FIX(1.144122806));         /* c4 */\n    z2 = MULTIPLY(z4, FIX(0.437016024));         /* c8 */\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z2;\n\n    tmp22 = RIGHT_SHIFT(z3 - ((z1 - z2) << 1),   /* c0 = (c4-c8)*2 */\n\t\t\tCONST_BITS-PASS1_BITS);\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));    /* c6 */\n    tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */\n    tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */\n\n    tmp20 = tmp10 + tmp12;\n    tmp24 = tmp10 - tmp12;\n    tmp21 = tmp11 + tmp13;\n    tmp23 = tmp11 - tmp13;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = z2 + z4;\n    tmp13 = z2 - z4;\n\n    tmp12 = MULTIPLY(tmp13, FIX(0.309016994));        /* (c3-c7)/2 */\n    z5 = z3 << CONST_BITS;\n\n    z2 = MULTIPLY(tmp11, FIX(0.951056516));           /* (c3+c7)/2 */\n    z4 = z5 + tmp12;\n\n    tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */\n    tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.587785252));           /* (c1-c9)/2 */\n    z4 = z5 - tmp12 - (tmp13 << (CONST_BITS - 1));\n\n    tmp12 = (z1 - tmp13 - z3) << PASS1_BITS;\n\n    tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */\n    tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*9] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*8] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2] = (int) (tmp22 + tmp12);\n    wsptr[8*7] = (int) (tmp22 - tmp12);\n    wsptr[8*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*6] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 10 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 10; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z3 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 <<= CONST_BITS;\n    z4 = (INT32) wsptr[4];\n    z1 = MULTIPLY(z4, FIX(1.144122806));         /* c4 */\n    z2 = MULTIPLY(z4, FIX(0.437016024));         /* c8 */\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z2;\n\n    tmp22 = z3 - ((z1 - z2) << 1);               /* c0 = (c4-c8)*2 */\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[6];\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));    /* c6 */\n    tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */\n    tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */\n\n    tmp20 = tmp10 + tmp12;\n    tmp24 = tmp10 - tmp12;\n    tmp21 = tmp11 + tmp13;\n    tmp23 = tmp11 - tmp13;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z3 <<= CONST_BITS;\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = z2 + z4;\n    tmp13 = z2 - z4;\n\n    tmp12 = MULTIPLY(tmp13, FIX(0.309016994));        /* (c3-c7)/2 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.951056516));           /* (c3+c7)/2 */\n    z4 = z3 + tmp12;\n\n    tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */\n    tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.587785252));           /* (c1-c9)/2 */\n    z4 = z3 - tmp12 - (tmp13 << (CONST_BITS - 1));\n\n    tmp12 = ((z1 - tmp13) << CONST_BITS) - z3;\n\n    tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */\n    tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 11x11 output block.\n *\n * Optimized algorithm with 24 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/22).\n */\n\nGLOBAL(void)\njpeg_idct_11x11 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*11];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp10 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp10 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132));     /* c2+c4 */\n    tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045));     /* c2-c6 */\n    z4 = z1 + z3;\n    tmp24 = MULTIPLY(z4, - FIX(1.155664402));        /* -(c2-c10) */\n    z4 -= z2;\n    tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976));  /* c2 */\n    tmp21 = tmp20 + tmp23 + tmp25 -\n\t    MULTIPLY(z2, FIX(1.821790775));          /* c2+c4+c10-c6 */\n    tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */\n    tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */\n    tmp24 += tmp25;\n    tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120));  /* c8+c10 */\n    tmp24 += MULTIPLY(z2, FIX(1.944413522)) -        /* c2+c8 */\n\t     MULTIPLY(z1, FIX(1.390975730));         /* c4+c10 */\n    tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562));  /* c0 */\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = z1 + z2;\n    tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */\n    tmp11 = MULTIPLY(tmp11, FIX(0.887983902));           /* c3-c9 */\n    tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295));         /* c5-c9 */\n    tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(z1, FIX(0.923107866));              /* c7+c5+c3-c1-2*c9 */\n    z1    = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */\n    tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588));        /* c1+c7+3*c9-c3 */\n    tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623));        /* c3+c5-c7-c9 */\n    z1    = MULTIPLY(z2 + z4, - FIX(1.798248910));       /* -(c1+c9) */\n    tmp11 += z1;\n    tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632));        /* c1+c5+c9-c7 */\n    tmp14 += MULTIPLY(z2, - FIX(1.467221301)) +          /* -(c5+c9) */\n\t     MULTIPLY(z3, FIX(1.001388905)) -            /* c1-c9 */\n\t     MULTIPLY(z4, FIX(1.684843907));             /* c3+c9 */\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 11 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 11; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp10 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp10 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[4];\n    z3 = (INT32) wsptr[6];\n\n    tmp20 = MULTIPLY(z2 - z3, FIX(2.546640132));     /* c2+c4 */\n    tmp23 = MULTIPLY(z2 - z1, FIX(0.430815045));     /* c2-c6 */\n    z4 = z1 + z3;\n    tmp24 = MULTIPLY(z4, - FIX(1.155664402));        /* -(c2-c10) */\n    z4 -= z2;\n    tmp25 = tmp10 + MULTIPLY(z4, FIX(1.356927976));  /* c2 */\n    tmp21 = tmp20 + tmp23 + tmp25 -\n\t    MULTIPLY(z2, FIX(1.821790775));          /* c2+c4+c10-c6 */\n    tmp20 += tmp25 + MULTIPLY(z3, FIX(2.115825087)); /* c4+c6 */\n    tmp23 += tmp25 - MULTIPLY(z1, FIX(1.513598477)); /* c6+c8 */\n    tmp24 += tmp25;\n    tmp22 = tmp24 - MULTIPLY(z3, FIX(0.788749120));  /* c8+c10 */\n    tmp24 += MULTIPLY(z2, FIX(1.944413522)) -        /* c2+c8 */\n\t     MULTIPLY(z1, FIX(1.390975730));         /* c4+c10 */\n    tmp25 = tmp10 - MULTIPLY(z4, FIX(1.414213562));  /* c0 */\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = z1 + z2;\n    tmp14 = MULTIPLY(tmp11 + z3 + z4, FIX(0.398430003)); /* c9 */\n    tmp11 = MULTIPLY(tmp11, FIX(0.887983902));           /* c3-c9 */\n    tmp12 = MULTIPLY(z1 + z3, FIX(0.670361295));         /* c5-c9 */\n    tmp13 = tmp14 + MULTIPLY(z1 + z4, FIX(0.366151574)); /* c7-c9 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(z1, FIX(0.923107866));              /* c7+c5+c3-c1-2*c9 */\n    z1    = tmp14 - MULTIPLY(z2 + z3, FIX(1.163011579)); /* c7+c9 */\n    tmp11 += z1 + MULTIPLY(z2, FIX(2.073276588));        /* c1+c7+3*c9-c3 */\n    tmp12 += z1 - MULTIPLY(z3, FIX(1.192193623));        /* c3+c5-c7-c9 */\n    z1    = MULTIPLY(z2 + z4, - FIX(1.798248910));       /* -(c1+c9) */\n    tmp11 += z1;\n    tmp13 += z1 + MULTIPLY(z4, FIX(2.102458632));        /* c1+c5+c9-c7 */\n    tmp14 += MULTIPLY(z2, - FIX(1.467221301)) +          /* -(c5+c9) */\n\t     MULTIPLY(z3, FIX(1.001388905)) -            /* c1-c9 */\n\t     MULTIPLY(z4, FIX(1.684843907));             /* c3+c9 */\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 12x12 output block.\n *\n * Optimized algorithm with 15 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/24).\n */\n\nGLOBAL(void)\njpeg_idct_12x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*12];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z3 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */\n    z1 <<= CONST_BITS;\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n    z2 <<= CONST_BITS;\n\n    tmp12 = z1 - z2;\n\n    tmp21 = z3 + tmp12;\n    tmp24 = z3 - tmp12;\n\n    tmp12 = z4 + z2;\n\n    tmp20 = tmp10 + tmp12;\n    tmp25 = tmp10 - tmp12;\n\n    tmp12 = z4 - z1 - z2;\n\n    tmp22 = tmp11 + tmp12;\n    tmp23 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = MULTIPLY(z2, FIX(1.306562965));                  /* c3 */\n    tmp14 = MULTIPLY(z2, - FIX_0_541196100);                 /* -c9 */\n\n    tmp10 = z1 + z3;\n    tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669));          /* c7 */\n    tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384));       /* c5-c7 */\n    tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716));  /* c1-c5 */\n    tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580));           /* -(c7+c11) */\n    tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */\n    tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */\n    tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) -        /* c7-c11 */\n\t     MULTIPLY(z4, FIX(1.982889723));                 /* c5+c7 */\n\n    z1 -= z4;\n    z2 -= z3;\n    z3 = MULTIPLY(z1 + z2, FIX_0_541196100);                 /* c9 */\n    tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865);              /* c3-c9 */\n    tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065);              /* c3+c9 */\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 12 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 12; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z3 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 <<= CONST_BITS;\n\n    z4 = (INT32) wsptr[4];\n    z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    z1 = (INT32) wsptr[2];\n    z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */\n    z1 <<= CONST_BITS;\n    z2 = (INT32) wsptr[6];\n    z2 <<= CONST_BITS;\n\n    tmp12 = z1 - z2;\n\n    tmp21 = z3 + tmp12;\n    tmp24 = z3 - tmp12;\n\n    tmp12 = z4 + z2;\n\n    tmp20 = tmp10 + tmp12;\n    tmp25 = tmp10 - tmp12;\n\n    tmp12 = z4 - z1 - z2;\n\n    tmp22 = tmp11 + tmp12;\n    tmp23 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = MULTIPLY(z2, FIX(1.306562965));                  /* c3 */\n    tmp14 = MULTIPLY(z2, - FIX_0_541196100);                 /* -c9 */\n\n    tmp10 = z1 + z3;\n    tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669));          /* c7 */\n    tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384));       /* c5-c7 */\n    tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716));  /* c1-c5 */\n    tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580));           /* -(c7+c11) */\n    tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */\n    tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */\n    tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) -        /* c7-c11 */\n\t     MULTIPLY(z4, FIX(1.982889723));                 /* c5+c7 */\n\n    z1 -= z4;\n    z2 -= z3;\n    z3 = MULTIPLY(z1 + z2, FIX_0_541196100);                 /* c9 */\n    tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865);              /* c3-c9 */\n    tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065);              /* c3+c9 */\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 13x13 output block.\n *\n * Optimized algorithm with 29 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/26).\n */\n\nGLOBAL(void)\njpeg_idct_13x13 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*13];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z1 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    tmp12 = MULTIPLY(tmp10, FIX(1.155388986));                /* (c4+c6)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1;           /* (c4-c6)/2 */\n\n    tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13;   /* c2 */\n    tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13;   /* c10 */\n\n    tmp12 = MULTIPLY(tmp10, FIX(0.316450131));                /* (c8-c12)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1;           /* (c8+c12)/2 */\n\n    tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13;   /* c6 */\n    tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */\n\n    tmp12 = MULTIPLY(tmp10, FIX(0.435816023));                /* (c2-c10)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1;           /* (c2+c10)/2 */\n\n    tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */\n    tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */\n\n    tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1;      /* c0 */\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651));     /* c3 */\n    tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945));     /* c5 */\n    tmp15 = z1 + z4;\n    tmp13 = MULTIPLY(tmp15, FIX(0.937797057));       /* c7 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(z1, FIX(2.020082300));          /* c7+c5+c3-c1 */\n    tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458));   /* -c11 */\n    tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */\n    tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */\n    tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945));   /* -c5 */\n    tmp11 += tmp14;\n    tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */\n    tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813));   /* -c9 */\n    tmp12 += tmp14;\n    tmp13 += tmp14;\n    tmp15 = MULTIPLY(tmp15, FIX(0.338443458));       /* c11 */\n    tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */\n\t    MULTIPLY(z2, FIX(0.466105296));          /* c1-c7 */\n    z1    = MULTIPLY(z3 - z2, FIX(0.937797057));     /* c7 */\n    tmp14 += z1;\n    tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) -   /* c3-c7 */\n\t     MULTIPLY(z4, FIX(1.742345811));         /* c1+c11 */\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*12] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp26, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 13 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 13; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z1 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z1 <<= CONST_BITS;\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[4];\n    z4 = (INT32) wsptr[6];\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    tmp12 = MULTIPLY(tmp10, FIX(1.155388986));                /* (c4+c6)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.096834934)) + z1;           /* (c4-c6)/2 */\n\n    tmp20 = MULTIPLY(z2, FIX(1.373119086)) + tmp12 + tmp13;   /* c2 */\n    tmp22 = MULTIPLY(z2, FIX(0.501487041)) - tmp12 + tmp13;   /* c10 */\n\n    tmp12 = MULTIPLY(tmp10, FIX(0.316450131));                /* (c8-c12)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.486914739)) + z1;           /* (c8+c12)/2 */\n\n    tmp21 = MULTIPLY(z2, FIX(1.058554052)) - tmp12 + tmp13;   /* c6 */\n    tmp25 = MULTIPLY(z2, - FIX(1.252223920)) + tmp12 + tmp13; /* c4 */\n\n    tmp12 = MULTIPLY(tmp10, FIX(0.435816023));                /* (c2-c10)/2 */\n    tmp13 = MULTIPLY(tmp11, FIX(0.937303064)) - z1;           /* (c2+c10)/2 */\n\n    tmp23 = MULTIPLY(z2, - FIX(0.170464608)) - tmp12 - tmp13; /* c12 */\n    tmp24 = MULTIPLY(z2, - FIX(0.803364869)) + tmp12 - tmp13; /* c8 */\n\n    tmp26 = MULTIPLY(tmp11 - z2, FIX(1.414213562)) + z1;      /* c0 */\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.322312651));     /* c3 */\n    tmp12 = MULTIPLY(z1 + z3, FIX(1.163874945));     /* c5 */\n    tmp15 = z1 + z4;\n    tmp13 = MULTIPLY(tmp15, FIX(0.937797057));       /* c7 */\n    tmp10 = tmp11 + tmp12 + tmp13 -\n\t    MULTIPLY(z1, FIX(2.020082300));          /* c7+c5+c3-c1 */\n    tmp14 = MULTIPLY(z2 + z3, - FIX(0.338443458));   /* -c11 */\n    tmp11 += tmp14 + MULTIPLY(z2, FIX(0.837223564)); /* c5+c9+c11-c3 */\n    tmp12 += tmp14 - MULTIPLY(z3, FIX(1.572116027)); /* c1+c5-c9-c11 */\n    tmp14 = MULTIPLY(z2 + z4, - FIX(1.163874945));   /* -c5 */\n    tmp11 += tmp14;\n    tmp13 += tmp14 + MULTIPLY(z4, FIX(2.205608352)); /* c3+c5+c9-c7 */\n    tmp14 = MULTIPLY(z3 + z4, - FIX(0.657217813));   /* -c9 */\n    tmp12 += tmp14;\n    tmp13 += tmp14;\n    tmp15 = MULTIPLY(tmp15, FIX(0.338443458));       /* c11 */\n    tmp14 = tmp15 + MULTIPLY(z1, FIX(0.318774355)) - /* c9-c11 */\n\t    MULTIPLY(z2, FIX(0.466105296));          /* c1-c7 */\n    z1    = MULTIPLY(z3 - z2, FIX(0.937797057));     /* c7 */\n    tmp14 += z1;\n    tmp15 += z1 + MULTIPLY(z3, FIX(0.384515595)) -   /* c3-c7 */\n\t     MULTIPLY(z4, FIX(1.742345811));         /* c1+c11 */\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 14x14 output block.\n *\n * Optimized algorithm with 20 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/28).\n */\n\nGLOBAL(void)\njpeg_idct_14x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*14];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z1 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z2 = MULTIPLY(z4, FIX(1.274162392));         /* c4 */\n    z3 = MULTIPLY(z4, FIX(0.314692123));         /* c12 */\n    z4 = MULTIPLY(z4, FIX(0.881747734));         /* c8 */\n\n    tmp10 = z1 + z2;\n    tmp11 = z1 + z3;\n    tmp12 = z1 - z4;\n\n    tmp23 = RIGHT_SHIFT(z1 - ((z2 + z3 - z4) << 1), /* c0 = (c4+c12-c8)*2 */\n\t\t\tCONST_BITS-PASS1_BITS);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z3 = MULTIPLY(z1 + z2, FIX(1.105676686));    /* c6 */\n\n    tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */\n    tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */\n    tmp15 = MULTIPLY(z1, FIX(0.613604268)) -     /* c10 */\n\t    MULTIPLY(z2, FIX(1.378756276));      /* c2 */\n\n    tmp20 = tmp10 + tmp13;\n    tmp26 = tmp10 - tmp13;\n    tmp21 = tmp11 + tmp14;\n    tmp25 = tmp11 - tmp14;\n    tmp22 = tmp12 + tmp15;\n    tmp24 = tmp12 - tmp15;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n    tmp13 = z4 << CONST_BITS;\n\n    tmp14 = z1 + z3;\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607));           /* c3 */\n    tmp12 = MULTIPLY(tmp14, FIX(1.197448846));             /* c5 */\n    tmp10 = tmp11 + tmp12 + tmp13 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */\n    tmp14 = MULTIPLY(tmp14, FIX(0.752406978));             /* c9 */\n    tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426));        /* c9+c11-c13 */\n    z1    -= z2;\n    tmp15 = MULTIPLY(z1, FIX(0.467085129)) - tmp13;        /* c11 */\n    tmp16 += tmp15;\n    z1    += z4;\n    z4    = MULTIPLY(z2 + z3, - FIX(0.158341681)) - tmp13; /* -c13 */\n    tmp11 += z4 - MULTIPLY(z2, FIX(0.424103948));          /* c3-c9-c13 */\n    tmp12 += z4 - MULTIPLY(z3, FIX(2.373959773));          /* c3+c5-c13 */\n    z4    = MULTIPLY(z3 - z2, FIX(1.405321284));           /* c1 */\n    tmp14 += z4 + tmp13 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */\n    tmp15 += z4 + MULTIPLY(z2, FIX(0.674957567));          /* c1+c11-c5 */\n\n    tmp13 = (z1 - z3) << PASS1_BITS;\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*13] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*12] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) (tmp23 + tmp13);\n    wsptr[8*10] = (int) (tmp23 - tmp13);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 14 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 14; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z1 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z1 <<= CONST_BITS;\n    z4 = (INT32) wsptr[4];\n    z2 = MULTIPLY(z4, FIX(1.274162392));         /* c4 */\n    z3 = MULTIPLY(z4, FIX(0.314692123));         /* c12 */\n    z4 = MULTIPLY(z4, FIX(0.881747734));         /* c8 */\n\n    tmp10 = z1 + z2;\n    tmp11 = z1 + z3;\n    tmp12 = z1 - z4;\n\n    tmp23 = z1 - ((z2 + z3 - z4) << 1);          /* c0 = (c4+c12-c8)*2 */\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[6];\n\n    z3 = MULTIPLY(z1 + z2, FIX(1.105676686));    /* c6 */\n\n    tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */\n    tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */\n    tmp15 = MULTIPLY(z1, FIX(0.613604268)) -     /* c10 */\n\t    MULTIPLY(z2, FIX(1.378756276));      /* c2 */\n\n    tmp20 = tmp10 + tmp13;\n    tmp26 = tmp10 - tmp13;\n    tmp21 = tmp11 + tmp14;\n    tmp25 = tmp11 - tmp14;\n    tmp22 = tmp12 + tmp15;\n    tmp24 = tmp12 - tmp15;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n    z4 <<= CONST_BITS;\n\n    tmp14 = z1 + z3;\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607));           /* c3 */\n    tmp12 = MULTIPLY(tmp14, FIX(1.197448846));             /* c5 */\n    tmp10 = tmp11 + tmp12 + z4 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */\n    tmp14 = MULTIPLY(tmp14, FIX(0.752406978));             /* c9 */\n    tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426));        /* c9+c11-c13 */\n    z1    -= z2;\n    tmp15 = MULTIPLY(z1, FIX(0.467085129)) - z4;           /* c11 */\n    tmp16 += tmp15;\n    tmp13 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - z4;    /* -c13 */\n    tmp11 += tmp13 - MULTIPLY(z2, FIX(0.424103948));       /* c3-c9-c13 */\n    tmp12 += tmp13 - MULTIPLY(z3, FIX(2.373959773));       /* c3+c5-c13 */\n    tmp13 = MULTIPLY(z3 - z2, FIX(1.405321284));           /* c1 */\n    tmp14 += tmp13 + z4 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */\n    tmp15 += tmp13 + MULTIPLY(z2, FIX(0.674957567));       /* c1+c11-c5 */\n\n    tmp13 = ((z1 - z3) << CONST_BITS) + z4;\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 15x15 output block.\n *\n * Optimized algorithm with 22 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/30).\n */\n\nGLOBAL(void)\njpeg_idct_15x15 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*15];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z1 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */\n    tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */\n\n    tmp12 = z1 - tmp10;\n    tmp13 = z1 + tmp11;\n    z1 -= (tmp11 - tmp10) << 1;             /* c0 = (c6-c12)*2 */\n\n    z4 = z2 - z3;\n    z3 += z2;\n    tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */\n    z2 = MULTIPLY(z2, FIX(1.439773946));    /* c4+c14 */\n\n    tmp20 = tmp13 + tmp10 + tmp11;\n    tmp23 = tmp12 - tmp10 + tmp11 + z2;\n\n    tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */\n\n    tmp25 = tmp13 - tmp10 - tmp11;\n    tmp26 = tmp12 + tmp10 - tmp11 - z2;\n\n    tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */\n\n    tmp21 = tmp12 + tmp10 + tmp11;\n    tmp24 = tmp13 - tmp10 + tmp11;\n    tmp11 += tmp11;\n    tmp22 = z1 + tmp11;                     /* c10 = c6-c12 */\n    tmp27 = z1 - tmp11 - tmp11;             /* c0 = (c6-c12)*2 */\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z3 = MULTIPLY(z4, FIX(1.224744871));                    /* c5 */\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp13 = z2 - z4;\n    tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876));         /* c9 */\n    tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148));         /* c3-c9 */\n    tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899));      /* c3+c9 */\n\n    tmp13 = MULTIPLY(z2, - FIX(0.831253876));               /* -c9 */\n    tmp15 = MULTIPLY(z2, - FIX(1.344997024));               /* -c3 */\n    z2 = z1 - z4;\n    tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353));            /* c1 */\n\n    tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */\n    tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */\n    tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3;            /* c5 */\n    z2 = MULTIPLY(z1 + z4, FIX(0.575212477));               /* c11 */\n    tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3;      /* c7-c11 */\n    tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3;      /* c11+c13 */\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*14] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*13] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*12] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp27, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 15 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 15; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z1 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z1 <<= CONST_BITS;\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[4];\n    z4 = (INT32) wsptr[6];\n\n    tmp10 = MULTIPLY(z4, FIX(0.437016024)); /* c12 */\n    tmp11 = MULTIPLY(z4, FIX(1.144122806)); /* c6 */\n\n    tmp12 = z1 - tmp10;\n    tmp13 = z1 + tmp11;\n    z1 -= (tmp11 - tmp10) << 1;             /* c0 = (c6-c12)*2 */\n\n    z4 = z2 - z3;\n    z3 += z2;\n    tmp10 = MULTIPLY(z3, FIX(1.337628990)); /* (c2+c4)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.045680613)); /* (c2-c4)/2 */\n    z2 = MULTIPLY(z2, FIX(1.439773946));    /* c4+c14 */\n\n    tmp20 = tmp13 + tmp10 + tmp11;\n    tmp23 = tmp12 - tmp10 + tmp11 + z2;\n\n    tmp10 = MULTIPLY(z3, FIX(0.547059574)); /* (c8+c14)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.399234004)); /* (c8-c14)/2 */\n\n    tmp25 = tmp13 - tmp10 - tmp11;\n    tmp26 = tmp12 + tmp10 - tmp11 - z2;\n\n    tmp10 = MULTIPLY(z3, FIX(0.790569415)); /* (c6+c12)/2 */\n    tmp11 = MULTIPLY(z4, FIX(0.353553391)); /* (c6-c12)/2 */\n\n    tmp21 = tmp12 + tmp10 + tmp11;\n    tmp24 = tmp13 - tmp10 + tmp11;\n    tmp11 += tmp11;\n    tmp22 = z1 + tmp11;                     /* c10 = c6-c12 */\n    tmp27 = z1 - tmp11 - tmp11;             /* c0 = (c6-c12)*2 */\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z4 = (INT32) wsptr[5];\n    z3 = MULTIPLY(z4, FIX(1.224744871));                    /* c5 */\n    z4 = (INT32) wsptr[7];\n\n    tmp13 = z2 - z4;\n    tmp15 = MULTIPLY(z1 + tmp13, FIX(0.831253876));         /* c9 */\n    tmp11 = tmp15 + MULTIPLY(z1, FIX(0.513743148));         /* c3-c9 */\n    tmp14 = tmp15 - MULTIPLY(tmp13, FIX(2.176250899));      /* c3+c9 */\n\n    tmp13 = MULTIPLY(z2, - FIX(0.831253876));               /* -c9 */\n    tmp15 = MULTIPLY(z2, - FIX(1.344997024));               /* -c3 */\n    z2 = z1 - z4;\n    tmp12 = z3 + MULTIPLY(z2, FIX(1.406466353));            /* c1 */\n\n    tmp10 = tmp12 + MULTIPLY(z4, FIX(2.457431844)) - tmp15; /* c1+c7 */\n    tmp16 = tmp12 - MULTIPLY(z1, FIX(1.112434820)) + tmp13; /* c1-c13 */\n    tmp12 = MULTIPLY(z2, FIX(1.224744871)) - z3;            /* c5 */\n    z2 = MULTIPLY(z1 + z4, FIX(0.575212477));               /* c11 */\n    tmp13 += z2 + MULTIPLY(z1, FIX(0.475753014)) - z3;      /* c7-c11 */\n    tmp15 += z2 - MULTIPLY(z4, FIX(0.869244010)) + z3;      /* c11+c13 */\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp27,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 16x16 output block.\n *\n * Optimized algorithm with 28 multiplications in the 1-D kernel.\n * cK represents sqrt(2) * cos(K*pi/32).\n */\n\nGLOBAL(void)\njpeg_idct_16x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*16];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += 1 << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp1 = MULTIPLY(z1, FIX(1.306562965));      /* c4[16] = c2[8] */\n    tmp2 = MULTIPLY(z1, FIX_0_541196100);       /* c12[16] = c6[8] */\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n    z3 = z1 - z2;\n    z4 = MULTIPLY(z3, FIX(0.275899379));        /* c14[16] = c7[8] */\n    z3 = MULTIPLY(z3, FIX(1.387039845));        /* c2[16] = c1[8] */\n\n    tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447);  /* (c6+c2)[16] = (c3+c1)[8] */\n    tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223);  /* (c6-c14)[16] = (c3-c7)[8] */\n    tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */\n    tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */\n\n    tmp20 = tmp10 + tmp0;\n    tmp27 = tmp10 - tmp0;\n    tmp21 = tmp12 + tmp1;\n    tmp26 = tmp12 - tmp1;\n    tmp22 = tmp13 + tmp2;\n    tmp25 = tmp13 - tmp2;\n    tmp23 = tmp11 + tmp3;\n    tmp24 = tmp11 - tmp3;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = z1 + z3;\n\n    tmp1  = MULTIPLY(z1 + z2, FIX(1.353318001));   /* c3 */\n    tmp2  = MULTIPLY(tmp11,   FIX(1.247225013));   /* c5 */\n    tmp3  = MULTIPLY(z1 + z4, FIX(1.093201867));   /* c7 */\n    tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586));   /* c9 */\n    tmp11 = MULTIPLY(tmp11,   FIX(0.666655658));   /* c11 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528));   /* c13 */\n    tmp0  = tmp1 + tmp2 + tmp3 -\n\t    MULTIPLY(z1, FIX(2.286341144));        /* c7+c5+c3-c1 */\n    tmp13 = tmp10 + tmp11 + tmp12 -\n\t    MULTIPLY(z1, FIX(1.835730603));        /* c9+c11+c13-c15 */\n    z1    = MULTIPLY(z2 + z3, FIX(0.138617169));   /* c15 */\n    tmp1  += z1 + MULTIPLY(z2, FIX(0.071888074));  /* c9+c11-c3-c15 */\n    tmp2  += z1 - MULTIPLY(z3, FIX(1.125726048));  /* c5+c7+c15-c3 */\n    z1    = MULTIPLY(z3 - z2, FIX(1.407403738));   /* c1 */\n    tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282));  /* c1+c11-c9-c13 */\n    tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411));  /* c1+c5+c13-c7 */\n    z2    += z4;\n    z1    = MULTIPLY(z2, - FIX(0.666655658));      /* -c11 */\n    tmp1  += z1;\n    tmp3  += z1 + MULTIPLY(z4, FIX(1.065388962));  /* c3+c11+c15-c7 */\n    z2    = MULTIPLY(z2, - FIX(1.247225013));      /* -c5 */\n    tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809));  /* c1+c5+c9-c13 */\n    tmp12 += z2;\n    z2    = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */\n    tmp2  += z2;\n    tmp3  += z2;\n    z2    = MULTIPLY(z4 - z3, FIX(0.410524528));   /* c13 */\n    tmp10 += z2;\n    tmp11 += z2;\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp0,  CONST_BITS-PASS1_BITS);\n    wsptr[8*15] = (int) RIGHT_SHIFT(tmp20 - tmp0,  CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp1,  CONST_BITS-PASS1_BITS);\n    wsptr[8*14] = (int) RIGHT_SHIFT(tmp21 - tmp1,  CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp2,  CONST_BITS-PASS1_BITS);\n    wsptr[8*13] = (int) RIGHT_SHIFT(tmp22 - tmp2,  CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp3,  CONST_BITS-PASS1_BITS);\n    wsptr[8*12] = (int) RIGHT_SHIFT(tmp23 - tmp3,  CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp24 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp25 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp26 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp26 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 16 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 16; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[4];\n    tmp1 = MULTIPLY(z1, FIX(1.306562965));      /* c4[16] = c2[8] */\n    tmp2 = MULTIPLY(z1, FIX_0_541196100);       /* c12[16] = c6[8] */\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[6];\n    z3 = z1 - z2;\n    z4 = MULTIPLY(z3, FIX(0.275899379));        /* c14[16] = c7[8] */\n    z3 = MULTIPLY(z3, FIX(1.387039845));        /* c2[16] = c1[8] */\n\n    tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447);  /* (c6+c2)[16] = (c3+c1)[8] */\n    tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223);  /* (c6-c14)[16] = (c3-c7)[8] */\n    tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */\n    tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */\n\n    tmp20 = tmp10 + tmp0;\n    tmp27 = tmp10 - tmp0;\n    tmp21 = tmp12 + tmp1;\n    tmp26 = tmp12 - tmp1;\n    tmp22 = tmp13 + tmp2;\n    tmp25 = tmp13 - tmp2;\n    tmp23 = tmp11 + tmp3;\n    tmp24 = tmp11 - tmp3;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = z1 + z3;\n\n    tmp1  = MULTIPLY(z1 + z2, FIX(1.353318001));   /* c3 */\n    tmp2  = MULTIPLY(tmp11,   FIX(1.247225013));   /* c5 */\n    tmp3  = MULTIPLY(z1 + z4, FIX(1.093201867));   /* c7 */\n    tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586));   /* c9 */\n    tmp11 = MULTIPLY(tmp11,   FIX(0.666655658));   /* c11 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528));   /* c13 */\n    tmp0  = tmp1 + tmp2 + tmp3 -\n\t    MULTIPLY(z1, FIX(2.286341144));        /* c7+c5+c3-c1 */\n    tmp13 = tmp10 + tmp11 + tmp12 -\n\t    MULTIPLY(z1, FIX(1.835730603));        /* c9+c11+c13-c15 */\n    z1    = MULTIPLY(z2 + z3, FIX(0.138617169));   /* c15 */\n    tmp1  += z1 + MULTIPLY(z2, FIX(0.071888074));  /* c9+c11-c3-c15 */\n    tmp2  += z1 - MULTIPLY(z3, FIX(1.125726048));  /* c5+c7+c15-c3 */\n    z1    = MULTIPLY(z3 - z2, FIX(1.407403738));   /* c1 */\n    tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282));  /* c1+c11-c9-c13 */\n    tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411));  /* c1+c5+c13-c7 */\n    z2    += z4;\n    z1    = MULTIPLY(z2, - FIX(0.666655658));      /* -c11 */\n    tmp1  += z1;\n    tmp3  += z1 + MULTIPLY(z4, FIX(1.065388962));  /* c3+c11+c15-c7 */\n    z2    = MULTIPLY(z2, - FIX(1.247225013));      /* -c5 */\n    tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809));  /* c1+c5+c9-c13 */\n    tmp12 += z2;\n    z2    = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */\n    tmp2  += z2;\n    tmp3  += z2;\n    z2    = MULTIPLY(z4 - z3, FIX(0.410524528));   /* c13 */\n    tmp10 += z2;\n    tmp11 += z2;\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp0,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[15] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp0,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp1,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp1,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp2,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp2,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp3,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp3,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp27 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp27 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 16x8 output block.\n *\n * 8-point IDCT in pass 1 (columns), 16-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_16x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*8];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * Note results are scaled up by sqrt(8) compared to a true IDCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = DCTSIZE; ctr > 0; ctr--) {\n    /* Due to quantization, we will usually find that many of the input\n     * coefficients are zero, especially the AC terms.  We can exploit this\n     * by short-circuiting the IDCT calculation for any column in which all\n     * the AC terms are zero.  In that case each output is equal to the\n     * DC coefficient (with scale factor as needed).\n     * With typical images and quantization tables, half or more of the\n     * column DCT calculations can be simplified this way.\n     */\n\n    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&\n\tinptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&\n\tinptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&\n\tinptr[DCTSIZE*7] == 0) {\n      /* AC terms all zero */\n      int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;\n\n      wsptr[DCTSIZE*0] = dcval;\n      wsptr[DCTSIZE*1] = dcval;\n      wsptr[DCTSIZE*2] = dcval;\n      wsptr[DCTSIZE*3] = dcval;\n      wsptr[DCTSIZE*4] = dcval;\n      wsptr[DCTSIZE*5] = dcval;\n      wsptr[DCTSIZE*6] = dcval;\n      wsptr[DCTSIZE*7] = dcval;\n\n      inptr++;\t\t\t/* advance pointers to next column */\n      quantptr++;\n      wsptr++;\n      continue;\n    }\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z2 <<= CONST_BITS;\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z2 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    tmp0 = z2 + z3;\n    tmp1 = z2 - z3;\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    wsptr[DCTSIZE*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[DCTSIZE*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);\n\n    inptr++;\t\t\t/* advance pointers to next column */\n    quantptr++;\n    wsptr++;\n  }\n\n  /* Pass 2: process 8 rows from work array, store into output array.\n   * 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[4];\n    tmp1 = MULTIPLY(z1, FIX(1.306562965));      /* c4[16] = c2[8] */\n    tmp2 = MULTIPLY(z1, FIX_0_541196100);       /* c12[16] = c6[8] */\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[6];\n    z3 = z1 - z2;\n    z4 = MULTIPLY(z3, FIX(0.275899379));        /* c14[16] = c7[8] */\n    z3 = MULTIPLY(z3, FIX(1.387039845));        /* c2[16] = c1[8] */\n\n    tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447);  /* (c6+c2)[16] = (c3+c1)[8] */\n    tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223);  /* (c6-c14)[16] = (c3-c7)[8] */\n    tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */\n    tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */\n\n    tmp20 = tmp10 + tmp0;\n    tmp27 = tmp10 - tmp0;\n    tmp21 = tmp12 + tmp1;\n    tmp26 = tmp12 - tmp1;\n    tmp22 = tmp13 + tmp2;\n    tmp25 = tmp13 - tmp2;\n    tmp23 = tmp11 + tmp3;\n    tmp24 = tmp11 - tmp3;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = z1 + z3;\n\n    tmp1  = MULTIPLY(z1 + z2, FIX(1.353318001));   /* c3 */\n    tmp2  = MULTIPLY(tmp11,   FIX(1.247225013));   /* c5 */\n    tmp3  = MULTIPLY(z1 + z4, FIX(1.093201867));   /* c7 */\n    tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586));   /* c9 */\n    tmp11 = MULTIPLY(tmp11,   FIX(0.666655658));   /* c11 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528));   /* c13 */\n    tmp0  = tmp1 + tmp2 + tmp3 -\n\t    MULTIPLY(z1, FIX(2.286341144));        /* c7+c5+c3-c1 */\n    tmp13 = tmp10 + tmp11 + tmp12 -\n\t    MULTIPLY(z1, FIX(1.835730603));        /* c9+c11+c13-c15 */\n    z1    = MULTIPLY(z2 + z3, FIX(0.138617169));   /* c15 */\n    tmp1  += z1 + MULTIPLY(z2, FIX(0.071888074));  /* c9+c11-c3-c15 */\n    tmp2  += z1 - MULTIPLY(z3, FIX(1.125726048));  /* c5+c7+c15-c3 */\n    z1    = MULTIPLY(z3 - z2, FIX(1.407403738));   /* c1 */\n    tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282));  /* c1+c11-c9-c13 */\n    tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411));  /* c1+c5+c13-c7 */\n    z2    += z4;\n    z1    = MULTIPLY(z2, - FIX(0.666655658));      /* -c11 */\n    tmp1  += z1;\n    tmp3  += z1 + MULTIPLY(z4, FIX(1.065388962));  /* c3+c11+c15-c7 */\n    z2    = MULTIPLY(z2, - FIX(1.247225013));      /* -c5 */\n    tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809));  /* c1+c5+c9-c13 */\n    tmp12 += z2;\n    z2    = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */\n    tmp2  += z2;\n    tmp3  += z2;\n    z2    = MULTIPLY(z4 - z3, FIX(0.410524528));   /* c13 */\n    tmp10 += z2;\n    tmp11 += z2;\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp0,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[15] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp0,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp1,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[14] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp1,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp2,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp2,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp3,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp3,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp27 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp27 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 14x7 output block.\n *\n * 7-point IDCT in pass 1 (columns), 14-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_14x7 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*7];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp23 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp23 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp23 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    tmp20 = MULTIPLY(z2 - z3, FIX(0.881747734));       /* c4 */\n    tmp22 = MULTIPLY(z1 - z2, FIX(0.314692123));       /* c6 */\n    tmp21 = tmp20 + tmp22 + tmp23 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */\n    tmp10 = z1 + z3;\n    z2 -= tmp10;\n    tmp10 = MULTIPLY(tmp10, FIX(1.274162392)) + tmp23; /* c2 */\n    tmp20 += tmp10 - MULTIPLY(z3, FIX(0.077722536));   /* c2-c4-c6 */\n    tmp22 += tmp10 - MULTIPLY(z1, FIX(2.470602249));   /* c2+c4+c6 */\n    tmp23 += MULTIPLY(z2, FIX(1.414213562));           /* c0 */\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n\n    tmp11 = MULTIPLY(z1 + z2, FIX(0.935414347));       /* (c3+c1-c5)/2 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.170262339));       /* (c3+c5-c1)/2 */\n    tmp10 = tmp11 - tmp12;\n    tmp11 += tmp12;\n    tmp12 = MULTIPLY(z2 + z3, - FIX(1.378756276));     /* -c1 */\n    tmp11 += tmp12;\n    z2 = MULTIPLY(z1 + z3, FIX(0.613604268));          /* c5 */\n    tmp10 += z2;\n    tmp12 += z2 + MULTIPLY(z3, FIX(1.870828693));      /* c3+c1-c5 */\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*6] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*5] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*4] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3] = (int) RIGHT_SHIFT(tmp23, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 7 rows from work array, store into output array.\n   * 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 7; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z1 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z1 <<= CONST_BITS;\n    z4 = (INT32) wsptr[4];\n    z2 = MULTIPLY(z4, FIX(1.274162392));         /* c4 */\n    z3 = MULTIPLY(z4, FIX(0.314692123));         /* c12 */\n    z4 = MULTIPLY(z4, FIX(0.881747734));         /* c8 */\n\n    tmp10 = z1 + z2;\n    tmp11 = z1 + z3;\n    tmp12 = z1 - z4;\n\n    tmp23 = z1 - ((z2 + z3 - z4) << 1);          /* c0 = (c4+c12-c8)*2 */\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[6];\n\n    z3 = MULTIPLY(z1 + z2, FIX(1.105676686));    /* c6 */\n\n    tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */\n    tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */\n    tmp15 = MULTIPLY(z1, FIX(0.613604268)) -     /* c10 */\n\t    MULTIPLY(z2, FIX(1.378756276));      /* c2 */\n\n    tmp20 = tmp10 + tmp13;\n    tmp26 = tmp10 - tmp13;\n    tmp21 = tmp11 + tmp14;\n    tmp25 = tmp11 - tmp14;\n    tmp22 = tmp12 + tmp15;\n    tmp24 = tmp12 - tmp15;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n    z4 <<= CONST_BITS;\n\n    tmp14 = z1 + z3;\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607));           /* c3 */\n    tmp12 = MULTIPLY(tmp14, FIX(1.197448846));             /* c5 */\n    tmp10 = tmp11 + tmp12 + z4 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */\n    tmp14 = MULTIPLY(tmp14, FIX(0.752406978));             /* c9 */\n    tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426));        /* c9+c11-c13 */\n    z1    -= z2;\n    tmp15 = MULTIPLY(z1, FIX(0.467085129)) - z4;           /* c11 */\n    tmp16 += tmp15;\n    tmp13 = MULTIPLY(z2 + z3, - FIX(0.158341681)) - z4;    /* -c13 */\n    tmp11 += tmp13 - MULTIPLY(z2, FIX(0.424103948));       /* c3-c9-c13 */\n    tmp12 += tmp13 - MULTIPLY(z3, FIX(2.373959773));       /* c3+c5-c13 */\n    tmp13 = MULTIPLY(z3 - z2, FIX(1.405321284));           /* c1 */\n    tmp14 += tmp13 + z4 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */\n    tmp15 += tmp13 + MULTIPLY(z2, FIX(0.674957567));       /* c1+c11-c5 */\n\n    tmp13 = ((z1 - z3) << CONST_BITS) + z4;\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[13] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[12] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp26 + tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp26 - tmp16,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 12x6 output block.\n *\n * 6-point IDCT in pass 1 (columns), 12-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_12x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*6];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp10 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp10 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp12 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp20 = MULTIPLY(tmp12, FIX(0.707106781));   /* c4 */\n    tmp11 = tmp10 + tmp20;\n    tmp21 = RIGHT_SHIFT(tmp10 - tmp20 - tmp20, CONST_BITS-PASS1_BITS);\n    tmp20 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp10 = MULTIPLY(tmp20, FIX(1.224744871));   /* c2 */\n    tmp20 = tmp11 + tmp10;\n    tmp22 = tmp11 - tmp10;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp11 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp10 = tmp11 + ((z1 + z2) << CONST_BITS);\n    tmp12 = tmp11 + ((z3 - z2) << CONST_BITS);\n    tmp11 = (z1 - z2 - z3) << PASS1_BITS;\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*5] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*1] = (int) (tmp21 + tmp11);\n    wsptr[8*4] = (int) (tmp21 - tmp11);\n    wsptr[8*2] = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*3] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 6 rows from work array, store into output array.\n   * 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z3 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 <<= CONST_BITS;\n\n    z4 = (INT32) wsptr[4];\n    z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    z1 = (INT32) wsptr[2];\n    z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */\n    z1 <<= CONST_BITS;\n    z2 = (INT32) wsptr[6];\n    z2 <<= CONST_BITS;\n\n    tmp12 = z1 - z2;\n\n    tmp21 = z3 + tmp12;\n    tmp24 = z3 - tmp12;\n\n    tmp12 = z4 + z2;\n\n    tmp20 = tmp10 + tmp12;\n    tmp25 = tmp10 - tmp12;\n\n    tmp12 = z4 - z1 - z2;\n\n    tmp22 = tmp11 + tmp12;\n    tmp23 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = MULTIPLY(z2, FIX(1.306562965));                  /* c3 */\n    tmp14 = MULTIPLY(z2, - FIX_0_541196100);                 /* -c9 */\n\n    tmp10 = z1 + z3;\n    tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669));          /* c7 */\n    tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384));       /* c5-c7 */\n    tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716));  /* c1-c5 */\n    tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580));           /* -(c7+c11) */\n    tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */\n    tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */\n    tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) -        /* c7-c11 */\n\t     MULTIPLY(z4, FIX(1.982889723));                 /* c5+c7 */\n\n    z1 -= z4;\n    z2 -= z3;\n    z3 = MULTIPLY(z1 + z2, FIX_0_541196100);                 /* c9 */\n    tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865);              /* c3-c9 */\n    tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065);              /* c3+c9 */\n\n    /* Final output stage */\n\n    outptr[0]  = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[11] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[1]  = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[10] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[2]  = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[9]  = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[3]  = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[8]  = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[4]  = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[7]  = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[5]  = range_limit[(int) RIGHT_SHIFT(tmp25 + tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n    outptr[6]  = range_limit[(int) RIGHT_SHIFT(tmp25 - tmp15,\n\t\t\t\t\t       CONST_BITS+PASS1_BITS+3)\n\t\t\t     & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 10x5 output block.\n *\n * 5-point IDCT in pass 1 (columns), 10-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_10x5 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*5];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp12 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp12 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp12 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp13 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp14 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z1 = MULTIPLY(tmp13 + tmp14, FIX(0.790569415)); /* (c2+c4)/2 */\n    z2 = MULTIPLY(tmp13 - tmp14, FIX(0.353553391)); /* (c2-c4)/2 */\n    z3 = tmp12 + z2;\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z1;\n    tmp12 -= z2 << 2;\n\n    /* Odd part */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));       /* c3 */\n    tmp13 = z1 + MULTIPLY(z2, FIX(0.513743148));    /* c1-c3 */\n    tmp14 = z1 - MULTIPLY(z3, FIX(2.176250899));    /* c1+c3 */\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) RIGHT_SHIFT(tmp10 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*4] = (int) RIGHT_SHIFT(tmp10 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*1] = (int) RIGHT_SHIFT(tmp11 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*3] = (int) RIGHT_SHIFT(tmp11 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[8*2] = (int) RIGHT_SHIFT(tmp12, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 5 rows from work array, store into output array.\n   * 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 5; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z3 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 <<= CONST_BITS;\n    z4 = (INT32) wsptr[4];\n    z1 = MULTIPLY(z4, FIX(1.144122806));         /* c4 */\n    z2 = MULTIPLY(z4, FIX(0.437016024));         /* c8 */\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z2;\n\n    tmp22 = z3 - ((z1 - z2) << 1);               /* c0 = (c4-c8)*2 */\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[6];\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));    /* c6 */\n    tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */\n    tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */\n\n    tmp20 = tmp10 + tmp12;\n    tmp24 = tmp10 - tmp12;\n    tmp21 = tmp11 + tmp13;\n    tmp23 = tmp11 - tmp13;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    z3 <<= CONST_BITS;\n    z4 = (INT32) wsptr[7];\n\n    tmp11 = z2 + z4;\n    tmp13 = z2 - z4;\n\n    tmp12 = MULTIPLY(tmp13, FIX(0.309016994));        /* (c3-c7)/2 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.951056516));           /* (c3+c7)/2 */\n    z4 = z3 + tmp12;\n\n    tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */\n    tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.587785252));           /* (c1-c9)/2 */\n    z4 = z3 - tmp12 - (tmp13 << (CONST_BITS - 1));\n\n    tmp12 = ((z1 - tmp13) << CONST_BITS) - z3;\n\n    tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */\n    tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[9] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[8] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23 + tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp23 - tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp24 + tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp24 - tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 8;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 8x4 output block.\n *\n * 4-point IDCT in pass 1 (columns), 8-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_8x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*4];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 4-point IDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n\n    tmp10 = (tmp0 + tmp2) << PASS1_BITS;\n    tmp12 = (tmp0 - tmp2) << PASS1_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);               /* c6 */\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp0 = RIGHT_SHIFT(z1 + MULTIPLY(z2, FIX_0_765366865), /* c2-c6 */\n\t\t       CONST_BITS-PASS1_BITS);\n    tmp2 = RIGHT_SHIFT(z1 - MULTIPLY(z3, FIX_1_847759065), /* c2+c6 */\n\t\t       CONST_BITS-PASS1_BITS);\n\n    /* Final output stage */\n\n    wsptr[8*0] = (int) (tmp10 + tmp0);\n    wsptr[8*3] = (int) (tmp10 - tmp0);\n    wsptr[8*1] = (int) (tmp12 + tmp2);\n    wsptr[8*2] = (int) (tmp12 - tmp2);\n  }\n\n  /* Pass 2: process rows from work array, store into output array.\n   * Note that we must descale the results by a factor of 8 == 2**3,\n   * and also undo the PASS1_BITS scaling.\n   * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 4; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z2 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 = (INT32) wsptr[4];\n\n    tmp0 = (z2 + z3) << CONST_BITS;\n    tmp1 = (z2 - z3) << CONST_BITS;\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[6];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = (INT32) wsptr[7];\n    tmp1 = (INT32) wsptr[5];\n    tmp2 = (INT32) wsptr[3];\n    tmp3 = (INT32) wsptr[1];\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 6x3 output block.\n *\n * 3-point IDCT in pass 1 (columns), 6-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_6x3 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[6*3];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */\n    tmp10 = tmp0 + tmp12;\n    tmp2 = tmp0 - tmp12 - tmp12;\n\n    /* Odd part */\n\n    tmp12 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */\n\n    /* Final output stage */\n\n    wsptr[6*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[6*2] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[6*1] = (int) RIGHT_SHIFT(tmp2, CONST_BITS-PASS1_BITS);\n  }\n  \n  /* Pass 2: process 3 rows from work array, store into output array.\n   * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 3; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n    tmp2 = (INT32) wsptr[4];\n    tmp10 = MULTIPLY(tmp2, FIX(0.707106781));   /* c4 */\n    tmp1 = tmp0 + tmp10;\n    tmp11 = tmp0 - tmp10 - tmp10;\n    tmp10 = (INT32) wsptr[2];\n    tmp0 = MULTIPLY(tmp10, FIX(1.224744871));   /* c2 */\n    tmp10 = tmp1 + tmp0;\n    tmp12 = tmp1 - tmp0;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);\n    tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);\n    tmp1 = (z1 - z2 - z3) << CONST_BITS;\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 6;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 4x2 output block.\n *\n * 2-point IDCT in pass 1 (columns), 4-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_4x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp2, tmp10, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  INT32 * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  INT32 workspace[4*2];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array. */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 4; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp10 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n\n    /* Odd part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n\n    /* Final output stage */\n\n    wsptr[4*0] = tmp10 + tmp0;\n    wsptr[4*1] = tmp10 - tmp0;\n  }\n\n  /* Pass 2: process 2 rows from work array, store into output array.\n   * 4-point IDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 2; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = wsptr[0] + ((((INT32) RANGE_CENTER) << 3) + (ONE << 2));\n    tmp2 = wsptr[2];\n\n    tmp10 = (tmp0 + tmp2) << CONST_BITS;\n    tmp12 = (tmp0 - tmp2) << CONST_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = wsptr[1];\n    z3 = wsptr[3];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);   /* c6 */\n    tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */\n    tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 4;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 2x1 output block.\n *\n * 1-point IDCT in pass 1 (columns), 2-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_2x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  DCTELEM tmp0, tmp1;\n  ISLOW_MULT_TYPE * quantptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  ISHIFT_TEMPS\n\n  /* Pass 1: empty. */\n\n  /* Pass 2: process 1 row from input, store into output array. */\n\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  outptr = output_buf[0] + output_col;\n\n  /* Even part */\n\n  tmp0 = DEQUANTIZE(coef_block[0], quantptr[0]);\n  /* Add range center and fudge factor for final descale and range-limit. */\n  tmp0 += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);\n\n  /* Odd part */\n\n  tmp1 = DEQUANTIZE(coef_block[1], quantptr[1]);\n\n  /* Final output stage */\n\n  outptr[0] = range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];\n  outptr[1] = range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 8x16 output block.\n *\n * 16-point IDCT in pass 1 (columns), 8-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_8x16 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3, tmp10, tmp11, tmp12, tmp13;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26, tmp27;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[8*16];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 16-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/32).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp1 = MULTIPLY(z1, FIX(1.306562965));      /* c4[16] = c2[8] */\n    tmp2 = MULTIPLY(z1, FIX_0_541196100);       /* c12[16] = c6[8] */\n\n    tmp10 = tmp0 + tmp1;\n    tmp11 = tmp0 - tmp1;\n    tmp12 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n    z3 = z1 - z2;\n    z4 = MULTIPLY(z3, FIX(0.275899379));        /* c14[16] = c7[8] */\n    z3 = MULTIPLY(z3, FIX(1.387039845));        /* c2[16] = c1[8] */\n\n    tmp0 = z3 + MULTIPLY(z2, FIX_2_562915447);  /* (c6+c2)[16] = (c3+c1)[8] */\n    tmp1 = z4 + MULTIPLY(z1, FIX_0_899976223);  /* (c6-c14)[16] = (c3-c7)[8] */\n    tmp2 = z3 - MULTIPLY(z1, FIX(0.601344887)); /* (c2-c10)[16] = (c1-c5)[8] */\n    tmp3 = z4 - MULTIPLY(z2, FIX(0.509795579)); /* (c10-c14)[16] = (c5-c7)[8] */\n\n    tmp20 = tmp10 + tmp0;\n    tmp27 = tmp10 - tmp0;\n    tmp21 = tmp12 + tmp1;\n    tmp26 = tmp12 - tmp1;\n    tmp22 = tmp13 + tmp2;\n    tmp25 = tmp13 - tmp2;\n    tmp23 = tmp11 + tmp3;\n    tmp24 = tmp11 - tmp3;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = z1 + z3;\n\n    tmp1  = MULTIPLY(z1 + z2, FIX(1.353318001));   /* c3 */\n    tmp2  = MULTIPLY(tmp11,   FIX(1.247225013));   /* c5 */\n    tmp3  = MULTIPLY(z1 + z4, FIX(1.093201867));   /* c7 */\n    tmp10 = MULTIPLY(z1 - z4, FIX(0.897167586));   /* c9 */\n    tmp11 = MULTIPLY(tmp11,   FIX(0.666655658));   /* c11 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.410524528));   /* c13 */\n    tmp0  = tmp1 + tmp2 + tmp3 -\n\t    MULTIPLY(z1, FIX(2.286341144));        /* c7+c5+c3-c1 */\n    tmp13 = tmp10 + tmp11 + tmp12 -\n\t    MULTIPLY(z1, FIX(1.835730603));        /* c9+c11+c13-c15 */\n    z1    = MULTIPLY(z2 + z3, FIX(0.138617169));   /* c15 */\n    tmp1  += z1 + MULTIPLY(z2, FIX(0.071888074));  /* c9+c11-c3-c15 */\n    tmp2  += z1 - MULTIPLY(z3, FIX(1.125726048));  /* c5+c7+c15-c3 */\n    z1    = MULTIPLY(z3 - z2, FIX(1.407403738));   /* c1 */\n    tmp11 += z1 - MULTIPLY(z3, FIX(0.766367282));  /* c1+c11-c9-c13 */\n    tmp12 += z1 + MULTIPLY(z2, FIX(1.971951411));  /* c1+c5+c13-c7 */\n    z2    += z4;\n    z1    = MULTIPLY(z2, - FIX(0.666655658));      /* -c11 */\n    tmp1  += z1;\n    tmp3  += z1 + MULTIPLY(z4, FIX(1.065388962));  /* c3+c11+c15-c7 */\n    z2    = MULTIPLY(z2, - FIX(1.247225013));      /* -c5 */\n    tmp10 += z2 + MULTIPLY(z4, FIX(3.141271809));  /* c1+c5+c9-c13 */\n    tmp12 += z2;\n    z2    = MULTIPLY(z3 + z4, - FIX(1.353318001)); /* -c3 */\n    tmp2  += z2;\n    tmp3  += z2;\n    z2    = MULTIPLY(z4 - z3, FIX(0.410524528));   /* c13 */\n    tmp10 += z2;\n    tmp11 += z2;\n\n    /* Final output stage */\n\n    wsptr[8*0]  = (int) RIGHT_SHIFT(tmp20 + tmp0,  CONST_BITS-PASS1_BITS);\n    wsptr[8*15] = (int) RIGHT_SHIFT(tmp20 - tmp0,  CONST_BITS-PASS1_BITS);\n    wsptr[8*1]  = (int) RIGHT_SHIFT(tmp21 + tmp1,  CONST_BITS-PASS1_BITS);\n    wsptr[8*14] = (int) RIGHT_SHIFT(tmp21 - tmp1,  CONST_BITS-PASS1_BITS);\n    wsptr[8*2]  = (int) RIGHT_SHIFT(tmp22 + tmp2,  CONST_BITS-PASS1_BITS);\n    wsptr[8*13] = (int) RIGHT_SHIFT(tmp22 - tmp2,  CONST_BITS-PASS1_BITS);\n    wsptr[8*3]  = (int) RIGHT_SHIFT(tmp23 + tmp3,  CONST_BITS-PASS1_BITS);\n    wsptr[8*12] = (int) RIGHT_SHIFT(tmp23 - tmp3,  CONST_BITS-PASS1_BITS);\n    wsptr[8*4]  = (int) RIGHT_SHIFT(tmp24 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*11] = (int) RIGHT_SHIFT(tmp24 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[8*5]  = (int) RIGHT_SHIFT(tmp25 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*10] = (int) RIGHT_SHIFT(tmp25 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[8*6]  = (int) RIGHT_SHIFT(tmp26 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*9]  = (int) RIGHT_SHIFT(tmp26 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[8*7]  = (int) RIGHT_SHIFT(tmp27 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[8*8]  = (int) RIGHT_SHIFT(tmp27 - tmp13, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process rows from work array, store into output array.\n   * Note that we must descale the results by a factor of 8 == 2**3,\n   * and also undo the PASS1_BITS scaling.\n   * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 16; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    z2 = (INT32) wsptr[0] +\n\t   ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t    (ONE << (PASS1_BITS+2)));\n    z3 = (INT32) wsptr[4];\n\n    tmp0 = (z2 + z3) << CONST_BITS;\n    tmp1 = (z2 - z3) << CONST_BITS;\n\n    z2 = (INT32) wsptr[2];\n    z3 = (INT32) wsptr[6];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = (INT32) wsptr[7];\n    tmp1 = (INT32) wsptr[5];\n    tmp2 = (INT32) wsptr[3];\n    tmp3 = (INT32) wsptr[1];\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[7] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp3,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp1,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp13 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp13 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += DCTSIZE;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 7x14 output block.\n *\n * 14-point IDCT in pass 1 (columns), 7-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_7x14 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15, tmp16;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25, tmp26;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[7*14];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 14-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/28).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 7; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z1 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z1 += ONE << (CONST_BITS-PASS1_BITS-1);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z2 = MULTIPLY(z4, FIX(1.274162392));         /* c4 */\n    z3 = MULTIPLY(z4, FIX(0.314692123));         /* c12 */\n    z4 = MULTIPLY(z4, FIX(0.881747734));         /* c8 */\n\n    tmp10 = z1 + z2;\n    tmp11 = z1 + z3;\n    tmp12 = z1 - z4;\n\n    tmp23 = RIGHT_SHIFT(z1 - ((z2 + z3 - z4) << 1), /* c0 = (c4+c12-c8)*2 */\n\t\t\tCONST_BITS-PASS1_BITS);\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z3 = MULTIPLY(z1 + z2, FIX(1.105676686));    /* c6 */\n\n    tmp13 = z3 + MULTIPLY(z1, FIX(0.273079590)); /* c2-c6 */\n    tmp14 = z3 - MULTIPLY(z2, FIX(1.719280954)); /* c6+c10 */\n    tmp15 = MULTIPLY(z1, FIX(0.613604268)) -     /* c10 */\n\t    MULTIPLY(z2, FIX(1.378756276));      /* c2 */\n\n    tmp20 = tmp10 + tmp13;\n    tmp26 = tmp10 - tmp13;\n    tmp21 = tmp11 + tmp14;\n    tmp25 = tmp11 - tmp14;\n    tmp22 = tmp12 + tmp15;\n    tmp24 = tmp12 - tmp15;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n    tmp13 = z4 << CONST_BITS;\n\n    tmp14 = z1 + z3;\n    tmp11 = MULTIPLY(z1 + z2, FIX(1.334852607));           /* c3 */\n    tmp12 = MULTIPLY(tmp14, FIX(1.197448846));             /* c5 */\n    tmp10 = tmp11 + tmp12 + tmp13 - MULTIPLY(z1, FIX(1.126980169)); /* c3+c5-c1 */\n    tmp14 = MULTIPLY(tmp14, FIX(0.752406978));             /* c9 */\n    tmp16 = tmp14 - MULTIPLY(z1, FIX(1.061150426));        /* c9+c11-c13 */\n    z1    -= z2;\n    tmp15 = MULTIPLY(z1, FIX(0.467085129)) - tmp13;        /* c11 */\n    tmp16 += tmp15;\n    z1    += z4;\n    z4    = MULTIPLY(z2 + z3, - FIX(0.158341681)) - tmp13; /* -c13 */\n    tmp11 += z4 - MULTIPLY(z2, FIX(0.424103948));          /* c3-c9-c13 */\n    tmp12 += z4 - MULTIPLY(z3, FIX(2.373959773));          /* c3+c5-c13 */\n    z4    = MULTIPLY(z3 - z2, FIX(1.405321284));           /* c1 */\n    tmp14 += z4 + tmp13 - MULTIPLY(z3, FIX(1.6906431334)); /* c1+c9-c11 */\n    tmp15 += z4 + MULTIPLY(z2, FIX(0.674957567));          /* c1+c11-c5 */\n\n    tmp13 = (z1 - z3) << PASS1_BITS;\n\n    /* Final output stage */\n\n    wsptr[7*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[7*13] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[7*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[7*12] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[7*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[7*11] = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[7*3]  = (int) (tmp23 + tmp13);\n    wsptr[7*10] = (int) (tmp23 - tmp13);\n    wsptr[7*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[7*9]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[7*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[7*8]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[7*6]  = (int) RIGHT_SHIFT(tmp26 + tmp16, CONST_BITS-PASS1_BITS);\n    wsptr[7*7]  = (int) RIGHT_SHIFT(tmp26 - tmp16, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 14 rows from work array, store into output array.\n   * 7-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/14).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 14; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp23 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp23 <<= CONST_BITS;\n\n    z1 = (INT32) wsptr[2];\n    z2 = (INT32) wsptr[4];\n    z3 = (INT32) wsptr[6];\n\n    tmp20 = MULTIPLY(z2 - z3, FIX(0.881747734));       /* c4 */\n    tmp22 = MULTIPLY(z1 - z2, FIX(0.314692123));       /* c6 */\n    tmp21 = tmp20 + tmp22 + tmp23 - MULTIPLY(z2, FIX(1.841218003)); /* c2+c4-c6 */\n    tmp10 = z1 + z3;\n    z2 -= tmp10;\n    tmp10 = MULTIPLY(tmp10, FIX(1.274162392)) + tmp23; /* c2 */\n    tmp20 += tmp10 - MULTIPLY(z3, FIX(0.077722536));   /* c2-c4-c6 */\n    tmp22 += tmp10 - MULTIPLY(z1, FIX(2.470602249));   /* c2+c4+c6 */\n    tmp23 += MULTIPLY(z2, FIX(1.414213562));           /* c0 */\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n\n    tmp11 = MULTIPLY(z1 + z2, FIX(0.935414347));       /* (c3+c1-c5)/2 */\n    tmp12 = MULTIPLY(z1 - z2, FIX(0.170262339));       /* (c3+c5-c1)/2 */\n    tmp10 = tmp11 - tmp12;\n    tmp11 += tmp12;\n    tmp12 = MULTIPLY(z2 + z3, - FIX(1.378756276));     /* -c1 */\n    tmp11 += tmp12;\n    z2 = MULTIPLY(z1 + z3, FIX(0.613604268));          /* c5 */\n    tmp10 += z2;\n    tmp12 += z2 + MULTIPLY(z3, FIX(1.870828693));      /* c3+c1-c5 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[6] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp23,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 7;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 6x12 output block.\n *\n * 12-point IDCT in pass 1 (columns), 6-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_6x12 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14, tmp15;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24, tmp25;\n  INT32 z1, z2, z3, z4;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[6*12];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 12-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/24).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z3 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z4 = MULTIPLY(z4, FIX(1.224744871)); /* c4 */\n\n    tmp10 = z3 + z4;\n    tmp11 = z3 - z4;\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z4 = MULTIPLY(z1, FIX(1.366025404)); /* c2 */\n    z1 <<= CONST_BITS;\n    z2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n    z2 <<= CONST_BITS;\n\n    tmp12 = z1 - z2;\n\n    tmp21 = z3 + tmp12;\n    tmp24 = z3 - tmp12;\n\n    tmp12 = z4 + z2;\n\n    tmp20 = tmp10 + tmp12;\n    tmp25 = tmp10 - tmp12;\n\n    tmp12 = z4 - z1 - z2;\n\n    tmp22 = tmp11 + tmp12;\n    tmp23 = tmp11 - tmp12;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = MULTIPLY(z2, FIX(1.306562965));                  /* c3 */\n    tmp14 = MULTIPLY(z2, - FIX_0_541196100);                 /* -c9 */\n\n    tmp10 = z1 + z3;\n    tmp15 = MULTIPLY(tmp10 + z4, FIX(0.860918669));          /* c7 */\n    tmp12 = tmp15 + MULTIPLY(tmp10, FIX(0.261052384));       /* c5-c7 */\n    tmp10 = tmp12 + tmp11 + MULTIPLY(z1, FIX(0.280143716));  /* c1-c5 */\n    tmp13 = MULTIPLY(z3 + z4, - FIX(1.045510580));           /* -(c7+c11) */\n    tmp12 += tmp13 + tmp14 - MULTIPLY(z3, FIX(1.478575242)); /* c1+c5-c7-c11 */\n    tmp13 += tmp15 - tmp11 + MULTIPLY(z4, FIX(1.586706681)); /* c1+c11 */\n    tmp15 += tmp14 - MULTIPLY(z1, FIX(0.676326758)) -        /* c7-c11 */\n\t     MULTIPLY(z4, FIX(1.982889723));                 /* c5+c7 */\n\n    z1 -= z4;\n    z2 -= z3;\n    z3 = MULTIPLY(z1 + z2, FIX_0_541196100);                 /* c9 */\n    tmp11 = z3 + MULTIPLY(z1, FIX_0_765366865);              /* c3-c9 */\n    tmp14 = z3 - MULTIPLY(z2, FIX_1_847759065);              /* c3+c9 */\n\n    /* Final output stage */\n\n    wsptr[6*0]  = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[6*11] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[6*1]  = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[6*10] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[6*2]  = (int) RIGHT_SHIFT(tmp22 + tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[6*9]  = (int) RIGHT_SHIFT(tmp22 - tmp12, CONST_BITS-PASS1_BITS);\n    wsptr[6*3]  = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[6*8]  = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[6*4]  = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[6*7]  = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[6*5]  = (int) RIGHT_SHIFT(tmp25 + tmp15, CONST_BITS-PASS1_BITS);\n    wsptr[6*6]  = (int) RIGHT_SHIFT(tmp25 - tmp15, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 12 rows from work array, store into output array.\n   * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 12; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp10 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp10 <<= CONST_BITS;\n    tmp12 = (INT32) wsptr[4];\n    tmp20 = MULTIPLY(tmp12, FIX(0.707106781));   /* c4 */\n    tmp11 = tmp10 + tmp20;\n    tmp21 = tmp10 - tmp20 - tmp20;\n    tmp20 = (INT32) wsptr[2];\n    tmp10 = MULTIPLY(tmp20, FIX(1.224744871));   /* c2 */\n    tmp20 = tmp11 + tmp10;\n    tmp22 = tmp11 - tmp10;\n\n    /* Odd part */\n\n    z1 = (INT32) wsptr[1];\n    z2 = (INT32) wsptr[3];\n    z3 = (INT32) wsptr[5];\n    tmp11 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp10 = tmp11 + ((z1 + z2) << CONST_BITS);\n    tmp12 = tmp11 + ((z3 - z2) << CONST_BITS);\n    tmp11 = (z1 - z2 - z3) << CONST_BITS;\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp20 + tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[5] = range_limit[(int) RIGHT_SHIFT(tmp20 - tmp10,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp21 + tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp21 - tmp11,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp22 + tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp22 - tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 6;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 5x10 output block.\n *\n * 10-point IDCT in pass 1 (columns), 5-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_5x10 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\tJCOEFPTR coef_block,\n\t\tJSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp10, tmp11, tmp12, tmp13, tmp14;\n  INT32 tmp20, tmp21, tmp22, tmp23, tmp24;\n  INT32 z1, z2, z3, z4, z5;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[5*10];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 10-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/20).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 5; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    z3 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z3 += ONE << (CONST_BITS-PASS1_BITS-1);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z1 = MULTIPLY(z4, FIX(1.144122806));         /* c4 */\n    z2 = MULTIPLY(z4, FIX(0.437016024));         /* c8 */\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z2;\n\n    tmp22 = RIGHT_SHIFT(z3 - ((z1 - z2) << 1),   /* c0 = (c4-c8)*2 */\n\t\t\tCONST_BITS-PASS1_BITS);\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));    /* c6 */\n    tmp12 = z1 + MULTIPLY(z2, FIX(0.513743148)); /* c2-c6 */\n    tmp13 = z1 - MULTIPLY(z3, FIX(2.176250899)); /* c2+c6 */\n\n    tmp20 = tmp10 + tmp12;\n    tmp24 = tmp10 - tmp12;\n    tmp21 = tmp11 + tmp13;\n    tmp23 = tmp11 - tmp13;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    z4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n\n    tmp11 = z2 + z4;\n    tmp13 = z2 - z4;\n\n    tmp12 = MULTIPLY(tmp13, FIX(0.309016994));        /* (c3-c7)/2 */\n    z5 = z3 << CONST_BITS;\n\n    z2 = MULTIPLY(tmp11, FIX(0.951056516));           /* (c3+c7)/2 */\n    z4 = z5 + tmp12;\n\n    tmp10 = MULTIPLY(z1, FIX(1.396802247)) + z2 + z4; /* c1 */\n    tmp14 = MULTIPLY(z1, FIX(0.221231742)) - z2 + z4; /* c9 */\n\n    z2 = MULTIPLY(tmp11, FIX(0.587785252));           /* (c1-c9)/2 */\n    z4 = z5 - tmp12 - (tmp13 << (CONST_BITS - 1));\n\n    tmp12 = (z1 - tmp13 - z3) << PASS1_BITS;\n\n    tmp11 = MULTIPLY(z1, FIX(1.260073511)) - z2 - z4; /* c3 */\n    tmp13 = MULTIPLY(z1, FIX(0.642039522)) - z2 + z4; /* c7 */\n\n    /* Final output stage */\n\n    wsptr[5*0] = (int) RIGHT_SHIFT(tmp20 + tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[5*9] = (int) RIGHT_SHIFT(tmp20 - tmp10, CONST_BITS-PASS1_BITS);\n    wsptr[5*1] = (int) RIGHT_SHIFT(tmp21 + tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[5*8] = (int) RIGHT_SHIFT(tmp21 - tmp11, CONST_BITS-PASS1_BITS);\n    wsptr[5*2] = (int) (tmp22 + tmp12);\n    wsptr[5*7] = (int) (tmp22 - tmp12);\n    wsptr[5*3] = (int) RIGHT_SHIFT(tmp23 + tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[5*6] = (int) RIGHT_SHIFT(tmp23 - tmp13, CONST_BITS-PASS1_BITS);\n    wsptr[5*4] = (int) RIGHT_SHIFT(tmp24 + tmp14, CONST_BITS-PASS1_BITS);\n    wsptr[5*5] = (int) RIGHT_SHIFT(tmp24 - tmp14, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 10 rows from work array, store into output array.\n   * 5-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/10).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 10; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp12 = (INT32) wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t       (ONE << (PASS1_BITS+2)));\n    tmp12 <<= CONST_BITS;\n    tmp13 = (INT32) wsptr[2];\n    tmp14 = (INT32) wsptr[4];\n    z1 = MULTIPLY(tmp13 + tmp14, FIX(0.790569415)); /* (c2+c4)/2 */\n    z2 = MULTIPLY(tmp13 - tmp14, FIX(0.353553391)); /* (c2-c4)/2 */\n    z3 = tmp12 + z2;\n    tmp10 = z3 + z1;\n    tmp11 = z3 - z1;\n    tmp12 -= z2 << 2;\n\n    /* Odd part */\n\n    z2 = (INT32) wsptr[1];\n    z3 = (INT32) wsptr[3];\n\n    z1 = MULTIPLY(z2 + z3, FIX(0.831253876));       /* c3 */\n    tmp13 = z1 + MULTIPLY(z2, FIX(0.513743148));    /* c1-c3 */\n    tmp14 = z1 - MULTIPLY(z3, FIX(2.176250899));    /* c1+c3 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[4] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp13,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp11 + tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp11 - tmp14,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 5;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 4x8 output block.\n *\n * 8-point IDCT in pass 1 (columns), 4-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_4x8 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp3;\n  INT32 tmp10, tmp11, tmp12, tmp13;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[4*8];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * Note results are scaled up by sqrt(8) compared to a true IDCT;\n   * furthermore, we scale the results by 2**PASS1_BITS.\n   * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 4; ctr > 0; ctr--) {\n    /* Due to quantization, we will usually find that many of the input\n     * coefficients are zero, especially the AC terms.  We can exploit this\n     * by short-circuiting the IDCT calculation for any column in which all\n     * the AC terms are zero.  In that case each output is equal to the\n     * DC coefficient (with scale factor as needed).\n     * With typical images and quantization tables, half or more of the\n     * column DCT calculations can be simplified this way.\n     */\n\n    if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&\n\tinptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&\n\tinptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&\n\tinptr[DCTSIZE*7] == 0) {\n      /* AC terms all zero */\n      int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;\n\n      wsptr[4*0] = dcval;\n      wsptr[4*1] = dcval;\n      wsptr[4*2] = dcval;\n      wsptr[4*3] = dcval;\n      wsptr[4*4] = dcval;\n      wsptr[4*5] = dcval;\n      wsptr[4*6] = dcval;\n      wsptr[4*7] = dcval;\n\n      inptr++;\t\t\t/* advance pointers to next column */\n      quantptr++;\n      wsptr++;\n      continue;\n    }\n\n    /* Even part: reverse the even part of the forward DCT.\n     * The rotator is c(-6).\n     */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);       /* c6 */\n    tmp2 = z1 + MULTIPLY(z2, FIX_0_765366865);     /* c2-c6 */\n    tmp3 = z1 - MULTIPLY(z3, FIX_1_847759065);     /* c2+c6 */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    z2 <<= CONST_BITS;\n    z3 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    z2 += ONE << (CONST_BITS-PASS1_BITS-1);\n\n    tmp0 = z2 + z3;\n    tmp1 = z2 - z3;\n\n    tmp10 = tmp0 + tmp2;\n    tmp13 = tmp0 - tmp2;\n    tmp11 = tmp1 + tmp3;\n    tmp12 = tmp1 - tmp3;\n\n    /* Odd part per figure 8; the matrix is unitary and hence its\n     * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.\n     */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);\n    tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n\n    z2 = tmp0 + tmp2;\n    z3 = tmp1 + tmp3;\n\n    z1 = MULTIPLY(z2 + z3, FIX_1_175875602);       /*  c3 */\n    z2 = MULTIPLY(z2, - FIX_1_961570560);          /* -c3-c5 */\n    z3 = MULTIPLY(z3, - FIX_0_390180644);          /* -c3+c5 */\n    z2 += z1;\n    z3 += z1;\n\n    z1 = MULTIPLY(tmp0 + tmp3, - FIX_0_899976223); /* -c3+c7 */\n    tmp0 = MULTIPLY(tmp0, FIX_0_298631336);        /* -c1+c3+c5-c7 */\n    tmp3 = MULTIPLY(tmp3, FIX_1_501321110);        /*  c1+c3-c5-c7 */\n    tmp0 += z1 + z2;\n    tmp3 += z1 + z3;\n\n    z1 = MULTIPLY(tmp1 + tmp2, - FIX_2_562915447); /* -c1-c3 */\n    tmp1 = MULTIPLY(tmp1, FIX_2_053119869);        /*  c1+c3-c5+c7 */\n    tmp2 = MULTIPLY(tmp2, FIX_3_072711026);        /*  c1+c3+c5-c7 */\n    tmp1 += z1 + z3;\n    tmp2 += z1 + z2;\n\n    /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */\n\n    wsptr[4*0] = (int) RIGHT_SHIFT(tmp10 + tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[4*7] = (int) RIGHT_SHIFT(tmp10 - tmp3, CONST_BITS-PASS1_BITS);\n    wsptr[4*1] = (int) RIGHT_SHIFT(tmp11 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[4*6] = (int) RIGHT_SHIFT(tmp11 - tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[4*2] = (int) RIGHT_SHIFT(tmp12 + tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[4*5] = (int) RIGHT_SHIFT(tmp12 - tmp1, CONST_BITS-PASS1_BITS);\n    wsptr[4*3] = (int) RIGHT_SHIFT(tmp13 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[4*4] = (int) RIGHT_SHIFT(tmp13 - tmp0, CONST_BITS-PASS1_BITS);\n\n    inptr++;\t\t\t/* advance pointers to next column */\n    quantptr++;\n    wsptr++;\n  }\n\n  /* Pass 2: process 8 rows from work array, store into output array.\n   * 4-point IDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 8; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp2 = (INT32) wsptr[2];\n\n    tmp10 = (tmp0 + tmp2) << CONST_BITS;\n    tmp12 = (tmp0 - tmp2) << CONST_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = (INT32) wsptr[1];\n    z3 = (INT32) wsptr[3];\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);   /* c6 */\n    tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */\n    tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[3] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp12 + tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp12 - tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 4;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a reduced-size 3x6 output block.\n *\n * 6-point IDCT in pass 1 (columns), 3-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_3x6 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp1, tmp2, tmp10, tmp11, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  int * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  int workspace[3*6];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 6-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/12).\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 3; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp0 <<= CONST_BITS;\n    /* Add fudge factor here for final descale. */\n    tmp0 += ONE << (CONST_BITS-PASS1_BITS-1);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);\n    tmp10 = MULTIPLY(tmp2, FIX(0.707106781));   /* c4 */\n    tmp1 = tmp0 + tmp10;\n    tmp11 = RIGHT_SHIFT(tmp0 - tmp10 - tmp10, CONST_BITS-PASS1_BITS);\n    tmp10 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n    tmp0 = MULTIPLY(tmp10, FIX(1.224744871));   /* c2 */\n    tmp10 = tmp1 + tmp0;\n    tmp12 = tmp1 - tmp0;\n\n    /* Odd part */\n\n    z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);\n    tmp1 = MULTIPLY(z1 + z3, FIX(0.366025404)); /* c5 */\n    tmp0 = tmp1 + ((z1 + z2) << CONST_BITS);\n    tmp2 = tmp1 + ((z3 - z2) << CONST_BITS);\n    tmp1 = (z1 - z2 - z3) << PASS1_BITS;\n\n    /* Final output stage */\n\n    wsptr[3*0] = (int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[3*5] = (int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS-PASS1_BITS);\n    wsptr[3*1] = (int) (tmp11 + tmp1);\n    wsptr[3*4] = (int) (tmp11 - tmp1);\n    wsptr[3*2] = (int) RIGHT_SHIFT(tmp12 + tmp2, CONST_BITS-PASS1_BITS);\n    wsptr[3*3] = (int) RIGHT_SHIFT(tmp12 - tmp2, CONST_BITS-PASS1_BITS);\n  }\n\n  /* Pass 2: process 6 rows from work array, store into output array.\n   * 3-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/6).\n   */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 6; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp0 = (INT32) wsptr[0] +\n\t     ((((INT32) RANGE_CENTER) << (PASS1_BITS+3)) +\n\t      (ONE << (PASS1_BITS+2)));\n    tmp0 <<= CONST_BITS;\n    tmp2 = (INT32) wsptr[2];\n    tmp12 = MULTIPLY(tmp2, FIX(0.707106781)); /* c2 */\n    tmp10 = tmp0 + tmp12;\n    tmp2 = tmp0 - tmp12 - tmp12;\n\n    /* Odd part */\n\n    tmp12 = (INT32) wsptr[1];\n    tmp0 = MULTIPLY(tmp12, FIX(1.224744871)); /* c1 */\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[2] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp2,\n\t\t\t\t\t      CONST_BITS+PASS1_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 3;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 2x4 output block.\n *\n * 4-point IDCT in pass 1 (columns), 2-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_2x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  INT32 tmp0, tmp2, tmp10, tmp12;\n  INT32 z1, z2, z3;\n  JCOEFPTR inptr;\n  ISLOW_MULT_TYPE * quantptr;\n  INT32 * wsptr;\n  JSAMPROW outptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  int ctr;\n  INT32 workspace[2*4];\t/* buffers data between passes */\n  SHIFT_TEMPS\n\n  /* Pass 1: process columns from input, store into work array.\n   * 4-point IDCT kernel,\n   * cK represents sqrt(2) * cos(K*pi/16) [refers to 8-point IDCT].\n   */\n\n  inptr = coef_block;\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n  wsptr = workspace;\n  for (ctr = 0; ctr < 2; ctr++, inptr++, quantptr++, wsptr++) {\n    /* Even part */\n\n    tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);\n    tmp2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);\n\n    tmp10 = (tmp0 + tmp2) << CONST_BITS;\n    tmp12 = (tmp0 - tmp2) << CONST_BITS;\n\n    /* Odd part */\n    /* Same rotation as in the even part of the 8x8 LL&M IDCT */\n\n    z2 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);\n    z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);\n\n    z1 = MULTIPLY(z2 + z3, FIX_0_541196100);   /* c6 */\n    tmp0 = z1 + MULTIPLY(z2, FIX_0_765366865); /* c2-c6 */\n    tmp2 = z1 - MULTIPLY(z3, FIX_1_847759065); /* c2+c6 */\n\n    /* Final output stage */\n\n    wsptr[2*0] = tmp10 + tmp0;\n    wsptr[2*3] = tmp10 - tmp0;\n    wsptr[2*1] = tmp12 + tmp2;\n    wsptr[2*2] = tmp12 - tmp2;\n  }\n\n  /* Pass 2: process 4 rows from work array, store into output array. */\n\n  wsptr = workspace;\n  for (ctr = 0; ctr < 4; ctr++) {\n    outptr = output_buf[ctr] + output_col;\n\n    /* Even part */\n\n    /* Add range center and fudge factor for final descale and range-limit. */\n    tmp10 = wsptr[0] +\n\t      ((((INT32) RANGE_CENTER) << (CONST_BITS+3)) +\n\t       (ONE << (CONST_BITS+2)));\n\n    /* Odd part */\n\n    tmp0 = wsptr[1];\n\n    /* Final output stage */\n\n    outptr[0] = range_limit[(int) RIGHT_SHIFT(tmp10 + tmp0, CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n    outptr[1] = range_limit[(int) RIGHT_SHIFT(tmp10 - tmp0, CONST_BITS+3)\n\t\t\t    & RANGE_MASK];\n\n    wsptr += 2;\t\t/* advance pointer to next row */\n  }\n}\n\n\n/*\n * Perform dequantization and inverse DCT on one block of coefficients,\n * producing a 1x2 output block.\n *\n * 2-point IDCT in pass 1 (columns), 1-point in pass 2 (rows).\n */\n\nGLOBAL(void)\njpeg_idct_1x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t       JCOEFPTR coef_block,\n\t       JSAMPARRAY output_buf, JDIMENSION output_col)\n{\n  DCTELEM tmp0, tmp1;\n  ISLOW_MULT_TYPE * quantptr;\n  JSAMPLE *range_limit = IDCT_range_limit(cinfo);\n  ISHIFT_TEMPS\n\n  /* Process 1 column from input, store into output array. */\n\n  quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;\n\n  /* Even part */\n\n  tmp0 = DEQUANTIZE(coef_block[DCTSIZE*0], quantptr[DCTSIZE*0]);\n  /* Add range center and fudge factor for final descale and range-limit. */\n  tmp0 += (((DCTELEM) RANGE_CENTER) << 3) + (1 << 2);\n\n  /* Odd part */\n\n  tmp1 = DEQUANTIZE(coef_block[DCTSIZE*1], quantptr[DCTSIZE*1]);\n\n  /* Final output stage */\n\n  output_buf[0][output_col] =\n    range_limit[(int) IRIGHT_SHIFT(tmp0 + tmp1, 3) & RANGE_MASK];\n  output_buf[1][output_col] =\n    range_limit[(int) IRIGHT_SHIFT(tmp0 - tmp1, 3) & RANGE_MASK];\n}\n\n#endif /* IDCT_SCALING_SUPPORTED */\n#endif /* DCT_ISLOW_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jinclude.h",
    "content": "/*\n * jinclude.h\n *\n * Copyright (C) 1991-1994, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file exists to provide a single place to fix any problems with\n * including the wrong system include files.  (Common problems are taken\n * care of by the standard jconfig symbols, but on really weird systems\n * you may have to edit this file.)\n *\n * NOTE: this file is NOT intended to be included by applications using the\n * JPEG library.  Most applications need only include jpeglib.h.\n */\n\n\n/* Include auto-config file to find out which system include files we need. */\n\n#include \"jconfig.h\"\t\t/* auto configuration options */\n#define JCONFIG_INCLUDED\t/* so that jpeglib.h doesn't do it again */\n\n/*\n * We need the NULL macro and size_t typedef.\n * On an ANSI-conforming system it is sufficient to include <stddef.h>.\n * Otherwise, we get them from <stdlib.h> or <stdio.h>; we may have to\n * pull in <sys/types.h> as well.\n * Note that the core JPEG library does not require <stdio.h>;\n * only the default error handler and data source/destination modules do.\n * But we must pull it in because of the references to FILE in jpeglib.h.\n * You can remove those references if you want to compile without <stdio.h>.\n */\n\n#ifdef HAVE_STDDEF_H\n#include <stddef.h>\n#endif\n\n#ifdef HAVE_STDLIB_H\n#include <stdlib.h>\n#endif\n\n#ifdef NEED_SYS_TYPES_H\n#include <sys/types.h>\n#endif\n\n#include <stdio.h>\n\n/*\n * We need memory copying and zeroing functions, plus strncpy().\n * ANSI and System V implementations declare these in <string.h>.\n * BSD doesn't have the mem() functions, but it does have bcopy()/bzero().\n * Some systems may declare memset and memcpy in <memory.h>.\n *\n * NOTE: we assume the size parameters to these functions are of type size_t.\n * Change the casts in these macros if not!\n */\n\n#ifdef NEED_BSD_STRINGS\n\n#include <strings.h>\n#define MEMZERO(target,size)\tbzero((void *)(target), (size_t)(size))\n#define MEMCOPY(dest,src,size)\tbcopy((const void *)(src), (void *)(dest), (size_t)(size))\n\n#else /* not BSD, assume ANSI/SysV string lib */\n\n#include <string.h>\n#define MEMZERO(target,size)\tmemset((void *)(target), 0, (size_t)(size))\n#define MEMCOPY(dest,src,size)\tmemcpy((void *)(dest), (const void *)(src), (size_t)(size))\n\n#endif\n\n/*\n * In ANSI C, and indeed any rational implementation, size_t is also the\n * type returned by sizeof().  However, it seems there are some irrational\n * implementations out there, in which sizeof() returns an int even though\n * size_t is defined as long or unsigned long.  To ensure consistent results\n * we always use this SIZEOF() macro in place of using sizeof() directly.\n */\n\n#define SIZEOF(object)\t((size_t) sizeof(object))\n\n/*\n * The modules that use fread() and fwrite() always invoke them through\n * these macros.  On some systems you may need to twiddle the argument casts.\n * CAUTION: argument order is different from underlying functions!\n */\n\n#define JFREAD(file,buf,sizeofbuf)  \\\n  ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))\n#define JFWRITE(file,buf,sizeofbuf)  \\\n  ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemansi.c",
    "content": "/*\n * jmemansi.c\n *\n * Copyright (C) 1992-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file provides a simple generic implementation of the system-\n * dependent portion of the JPEG memory manager.  This implementation\n * assumes that you have the ANSI-standard library routine tmpfile().\n * Also, the problem of determining the amount of memory available\n * is shoved onto the user.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"\t\t/* import the system-dependent declarations */\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare malloc(),free() */\nextern void * malloc JPP((size_t size));\nextern void free JPP((void *ptr));\n#endif\n\n#ifndef SEEK_SET\t\t/* pre-ANSI systems may not define this; */\n#define SEEK_SET  0\t\t/* if not, assume 0 is correct */\n#endif\n\n\n/*\n * Memory allocation and freeing are controlled by the regular library\n * routines malloc() and free().\n */\n\nGLOBAL(void *)\njpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * \"Large\" objects are treated the same as \"small\" ones.\n * NB: although we include FAR keywords in the routine declarations,\n * this file won't actually work in 80x86 small/medium model; at least,\n * you probably won't be able to process useful-size images in only 64KB.\n */\n\nGLOBAL(void FAR *)\njpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void FAR *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * This routine computes the total memory space available for allocation.\n * It's impossible to do this in a portable way; our current solution is\n * to make the user tell us (with a default value set at compile time).\n * If you can actually get the available space, it's a good idea to subtract\n * a slop factor of 5% or so.\n */\n\n#ifndef DEFAULT_MAX_MEM\t\t/* so can override from makefile */\n#define DEFAULT_MAX_MEM\t\t1000000L /* default: one megabyte */\n#endif\n\nGLOBAL(long)\njpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,\n\t\t    long max_bytes_needed, long already_allocated)\n{\n  return cinfo->mem->max_memory_to_use - already_allocated;\n}\n\n\n/*\n * Backing store (temporary file) management.\n * Backing store objects are only used when the value returned by\n * jpeg_mem_available is less than the total space needed.  You can dispense\n * with these routines if you have plenty of virtual memory; see jmemnobs.c.\n */\n\n\nMETHODDEF(void)\nread_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t    void FAR * buffer_address,\n\t\t    long file_offset, long byte_count)\n{\n  if (fseek(info->temp_file, file_offset, SEEK_SET))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  if (JFREAD(info->temp_file, buffer_address, byte_count)\n      != (size_t) byte_count)\n    ERREXIT(cinfo, JERR_TFILE_READ);\n}\n\n\nMETHODDEF(void)\nwrite_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t     void FAR * buffer_address,\n\t\t     long file_offset, long byte_count)\n{\n  if (fseek(info->temp_file, file_offset, SEEK_SET))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  if (JFWRITE(info->temp_file, buffer_address, byte_count)\n      != (size_t) byte_count)\n    ERREXIT(cinfo, JERR_TFILE_WRITE);\n}\n\n\nMETHODDEF(void)\nclose_backing_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  fclose(info->temp_file);\n  /* Since this implementation uses tmpfile() to create the file,\n   * no explicit file deletion is needed.\n   */\n}\n\n\n/*\n * Initial opening of a backing-store object.\n *\n * This version uses tmpfile(), which constructs a suitable file name\n * behind the scenes.  We don't have to use info->temp_name[] at all;\n * indeed, we can't even find out the actual name of the temp file.\n */\n\nGLOBAL(void)\njpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t\t long total_bytes_needed)\n{\n  if ((info->temp_file = tmpfile()) == NULL)\n    ERREXITS(cinfo, JERR_TFILE_CREATE, \"\");\n  info->read_backing_store = read_backing_store;\n  info->write_backing_store = write_backing_store;\n  info->close_backing_store = close_backing_store;\n}\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.\n */\n\nGLOBAL(long)\njpeg_mem_init (j_common_ptr cinfo)\n{\n  return DEFAULT_MAX_MEM;\t/* default for max_memory_to_use */\n}\n\nGLOBAL(void)\njpeg_mem_term (j_common_ptr cinfo)\n{\n  /* no work */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemdos.c",
    "content": "/*\n * jmemdos.c\n *\n * Copyright (C) 1992-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file provides an MS-DOS-compatible implementation of the system-\n * dependent portion of the JPEG memory manager.  Temporary data can be\n * stored in extended or expanded memory as well as in regular DOS files.\n *\n * If you use this file, you must be sure that NEED_FAR_POINTERS is defined\n * if you compile in a small-data memory model; it should NOT be defined if\n * you use a large-data memory model.  This file is not recommended if you\n * are using a flat-memory-space 386 environment such as DJGCC or Watcom C.\n * Also, this code will NOT work if struct fields are aligned on greater than\n * 2-byte boundaries.\n *\n * Based on code contributed by Ge' Weijers.\n */\n\n/*\n * If you have both extended and expanded memory, you may want to change the\n * order in which they are tried in jopen_backing_store.  On a 286 machine\n * expanded memory is usually faster, since extended memory access involves\n * an expensive protected-mode-and-back switch.  On 386 and better, extended\n * memory is usually faster.  As distributed, the code tries extended memory\n * first (what? not everyone has a 386? :-).\n *\n * You can disable use of extended/expanded memory entirely by altering these\n * definitions or overriding them from the Makefile (eg, -DEMS_SUPPORTED=0).\n */\n\n#ifndef XMS_SUPPORTED\n#define XMS_SUPPORTED  1\n#endif\n#ifndef EMS_SUPPORTED\n#define EMS_SUPPORTED  1\n#endif\n\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"\t\t/* import the system-dependent declarations */\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare these */\nextern void * malloc JPP((size_t size));\nextern void free JPP((void *ptr));\nextern char * getenv JPP((const char * name));\n#endif\n\n#ifdef NEED_FAR_POINTERS\n\n#ifdef __TURBOC__\n/* These definitions work for Borland C (Turbo C) */\n#include <alloc.h>\t\t/* need farmalloc(), farfree() */\n#define far_malloc(x)\tfarmalloc(x)\n#define far_free(x)\tfarfree(x)\n#else\n/* These definitions work for Microsoft C and compatible compilers */\n#include <malloc.h>\t\t/* need _fmalloc(), _ffree() */\n#define far_malloc(x)\t_fmalloc(x)\n#define far_free(x)\t_ffree(x)\n#endif\n\n#else /* not NEED_FAR_POINTERS */\n\n#define far_malloc(x)\tmalloc(x)\n#define far_free(x)\tfree(x)\n\n#endif /* NEED_FAR_POINTERS */\n\n#ifdef DONT_USE_B_MODE\t\t/* define mode parameters for fopen() */\n#define READ_BINARY\t\"r\"\n#else\n#define READ_BINARY\t\"rb\"\n#endif\n\n#ifndef USE_MSDOS_MEMMGR\t/* make sure user got configuration right */\n  You forgot to define USE_MSDOS_MEMMGR in jconfig.h. /* deliberate syntax error */\n#endif\n\n#if MAX_ALLOC_CHUNK >= 65535L\t/* make sure jconfig.h got this right */\n  MAX_ALLOC_CHUNK should be less than 64K. /* deliberate syntax error */\n#endif\n\n\n/*\n * Declarations for assembly-language support routines (see jmemdosa.asm).\n *\n * The functions are declared \"far\" as are all their pointer arguments;\n * this ensures the assembly source code will work regardless of the\n * compiler memory model.  We assume \"short\" is 16 bits, \"long\" is 32.\n */\n\ntypedef void far * XMSDRIVER;\t/* actually a pointer to code */\ntypedef struct {\t\t/* registers for calling XMS driver */\n\tunsigned short ax, dx, bx;\n\tvoid far * ds_si;\n      } XMScontext;\ntypedef struct {\t\t/* registers for calling EMS driver */\n\tunsigned short ax, dx, bx;\n\tvoid far * ds_si;\n      } EMScontext;\n\nextern short far jdos_open JPP((short far * handle, char far * filename));\nextern short far jdos_close JPP((short handle));\nextern short far jdos_seek JPP((short handle, long offset));\nextern short far jdos_read JPP((short handle, void far * buffer,\n\t\t\t\tunsigned short count));\nextern short far jdos_write JPP((short handle, void far * buffer,\n\t\t\t\t unsigned short count));\nextern void far jxms_getdriver JPP((XMSDRIVER far *));\nextern void far jxms_calldriver JPP((XMSDRIVER, XMScontext far *));\nextern short far jems_available JPP((void));\nextern void far jems_calldriver JPP((EMScontext far *));\n\n\n/*\n * Selection of a file name for a temporary file.\n * This is highly system-dependent, and you may want to customize it.\n */\n\nstatic int next_file_num;\t/* to distinguish among several temp files */\n\nLOCAL(void)\nselect_file_name (char * fname)\n{\n  const char * env;\n  char * ptr;\n  FILE * tfile;\n\n  /* Keep generating file names till we find one that's not in use */\n  for (;;) {\n    /* Get temp directory name from environment TMP or TEMP variable;\n     * if none, use \".\"\n     */\n    if ((env = (const char *) getenv(\"TMP\")) == NULL)\n      if ((env = (const char *) getenv(\"TEMP\")) == NULL)\n\tenv = \".\";\n    if (*env == '\\0')\t\t/* null string means \".\" */\n      env = \".\";\n    ptr = fname;\t\t/* copy name to fname */\n    while (*env != '\\0')\n      *ptr++ = *env++;\n    if (ptr[-1] != '\\\\' && ptr[-1] != '/')\n      *ptr++ = '\\\\';\t\t/* append backslash if not in env variable */\n    /* Append a suitable file name */\n    next_file_num++;\t\t/* advance counter */\n    sprintf(ptr, \"JPG%03d.TMP\", next_file_num);\n    /* Probe to see if file name is already in use */\n    if ((tfile = fopen(fname, READ_BINARY)) == NULL)\n      break;\n    fclose(tfile);\t\t/* oops, it's there; close tfile & try again */\n  }\n}\n\n\n/*\n * Near-memory allocation and freeing are controlled by the regular library\n * routines malloc() and free().\n */\n\nGLOBAL(void *)\njpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * \"Large\" objects are allocated in far memory, if possible\n */\n\nGLOBAL(void FAR *)\njpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void FAR *) far_malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)\n{\n  far_free(object);\n}\n\n\n/*\n * This routine computes the total memory space available for allocation.\n * It's impossible to do this in a portable way; our current solution is\n * to make the user tell us (with a default value set at compile time).\n * If you can actually get the available space, it's a good idea to subtract\n * a slop factor of 5% or so.\n */\n\n#ifndef DEFAULT_MAX_MEM\t\t/* so can override from makefile */\n#define DEFAULT_MAX_MEM\t\t300000L /* for total usage about 450K */\n#endif\n\nGLOBAL(long)\njpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,\n\t\t    long max_bytes_needed, long already_allocated)\n{\n  return cinfo->mem->max_memory_to_use - already_allocated;\n}\n\n\n/*\n * Backing store (temporary file) management.\n * Backing store objects are only used when the value returned by\n * jpeg_mem_available is less than the total space needed.  You can dispense\n * with these routines if you have plenty of virtual memory; see jmemnobs.c.\n */\n\n/*\n * For MS-DOS we support three types of backing storage:\n *   1. Conventional DOS files.  We access these by direct DOS calls rather\n *      than via the stdio package.  This provides a bit better performance,\n *      but the real reason is that the buffers to be read or written are FAR.\n *      The stdio library for small-data memory models can't cope with that.\n *   2. Extended memory, accessed per the XMS V2.0 specification.\n *   3. Expanded memory, accessed per the LIM/EMS 4.0 specification.\n * You'll need copies of those specs to make sense of the related code.\n * The specs are available by Internet FTP from the SIMTEL archives \n * (oak.oakland.edu and its various mirror sites).  See files\n * pub/msdos/microsoft/xms20.arc and pub/msdos/info/limems41.zip.\n */\n\n\n/*\n * Access methods for a DOS file.\n */\n\n\nMETHODDEF(void)\nread_file_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t void FAR * buffer_address,\n\t\t long file_offset, long byte_count)\n{\n  if (jdos_seek(info->handle.file_handle, file_offset))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */\n  if (byte_count > 65535L)\t/* safety check */\n    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);\n  if (jdos_read(info->handle.file_handle, buffer_address,\n\t\t(unsigned short) byte_count))\n    ERREXIT(cinfo, JERR_TFILE_READ);\n}\n\n\nMETHODDEF(void)\nwrite_file_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t  void FAR * buffer_address,\n\t\t  long file_offset, long byte_count)\n{\n  if (jdos_seek(info->handle.file_handle, file_offset))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  /* Since MAX_ALLOC_CHUNK is less than 64K, byte_count will be too. */\n  if (byte_count > 65535L)\t/* safety check */\n    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);\n  if (jdos_write(info->handle.file_handle, buffer_address,\n\t\t (unsigned short) byte_count))\n    ERREXIT(cinfo, JERR_TFILE_WRITE);\n}\n\n\nMETHODDEF(void)\nclose_file_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  jdos_close(info->handle.file_handle);\t/* close the file */\n  remove(info->temp_name);\t/* delete the file */\n/* If your system doesn't have remove(), try unlink() instead.\n * remove() is the ANSI-standard name for this function, but\n * unlink() was more common in pre-ANSI systems.\n */\n  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);\n}\n\n\nLOCAL(boolean)\nopen_file_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t long total_bytes_needed)\n{\n  short handle;\n\n  select_file_name(info->temp_name);\n  if (jdos_open((short far *) & handle, (char far *) info->temp_name)) {\n    /* might as well exit since jpeg_open_backing_store will fail anyway */\n    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);\n    return FALSE;\n  }\n  info->handle.file_handle = handle;\n  info->read_backing_store = read_file_store;\n  info->write_backing_store = write_file_store;\n  info->close_backing_store = close_file_store;\n  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);\n  return TRUE;\t\t\t/* succeeded */\n}\n\n\n/*\n * Access methods for extended memory.\n */\n\n#if XMS_SUPPORTED\n\nstatic XMSDRIVER xms_driver;\t/* saved address of XMS driver */\n\ntypedef union {\t\t\t/* either long offset or real-mode pointer */\n\tlong offset;\n\tvoid far * ptr;\n      } XMSPTR;\n\ntypedef struct {\t\t/* XMS move specification structure */\n\tlong length;\n\tXMSH src_handle;\n\tXMSPTR src;\n\tXMSH dst_handle;\n\tXMSPTR dst;\n      } XMSspec;\n\n#define ODD(X)\t(((X) & 1L) != 0)\n\n\nMETHODDEF(void)\nread_xms_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\tvoid FAR * buffer_address,\n\t\tlong file_offset, long byte_count)\n{\n  XMScontext ctx;\n  XMSspec spec;\n  char endbuffer[2];\n\n  /* The XMS driver can't cope with an odd length, so handle the last byte\n   * specially if byte_count is odd.  We don't expect this to be common.\n   */\n\n  spec.length = byte_count & (~ 1L);\n  spec.src_handle = info->handle.xms_handle;\n  spec.src.offset = file_offset;\n  spec.dst_handle = 0;\n  spec.dst.ptr = buffer_address;\n  \n  ctx.ds_si = (void far *) & spec;\n  ctx.ax = 0x0b00;\t\t/* EMB move */\n  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);\n  if (ctx.ax != 1)\n    ERREXIT(cinfo, JERR_XMS_READ);\n\n  if (ODD(byte_count)) {\n    read_xms_store(cinfo, info, (void FAR *) endbuffer,\n\t\t   file_offset + byte_count - 1L, 2L);\n    ((char FAR *) buffer_address)[byte_count - 1L] = endbuffer[0];\n  }\n}\n\n\nMETHODDEF(void)\nwrite_xms_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t void FAR * buffer_address,\n\t\t long file_offset, long byte_count)\n{\n  XMScontext ctx;\n  XMSspec spec;\n  char endbuffer[2];\n\n  /* The XMS driver can't cope with an odd length, so handle the last byte\n   * specially if byte_count is odd.  We don't expect this to be common.\n   */\n\n  spec.length = byte_count & (~ 1L);\n  spec.src_handle = 0;\n  spec.src.ptr = buffer_address;\n  spec.dst_handle = info->handle.xms_handle;\n  spec.dst.offset = file_offset;\n\n  ctx.ds_si = (void far *) & spec;\n  ctx.ax = 0x0b00;\t\t/* EMB move */\n  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);\n  if (ctx.ax != 1)\n    ERREXIT(cinfo, JERR_XMS_WRITE);\n\n  if (ODD(byte_count)) {\n    read_xms_store(cinfo, info, (void FAR *) endbuffer,\n\t\t   file_offset + byte_count - 1L, 2L);\n    endbuffer[0] = ((char FAR *) buffer_address)[byte_count - 1L];\n    write_xms_store(cinfo, info, (void FAR *) endbuffer,\n\t\t    file_offset + byte_count - 1L, 2L);\n  }\n}\n\n\nMETHODDEF(void)\nclose_xms_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  XMScontext ctx;\n\n  ctx.dx = info->handle.xms_handle;\n  ctx.ax = 0x0a00;\n  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);\n  TRACEMS1(cinfo, 1, JTRC_XMS_CLOSE, info->handle.xms_handle);\n  /* we ignore any error return from the driver */\n}\n\n\nLOCAL(boolean)\nopen_xms_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\tlong total_bytes_needed)\n{\n  XMScontext ctx;\n\n  /* Get address of XMS driver */\n  jxms_getdriver((XMSDRIVER far *) & xms_driver);\n  if (xms_driver == NULL)\n    return FALSE;\t\t/* no driver to be had */\n\n  /* Get version number, must be >= 2.00 */\n  ctx.ax = 0x0000;\n  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);\n  if (ctx.ax < (unsigned short) 0x0200)\n    return FALSE;\n\n  /* Try to get space (expressed in kilobytes) */\n  ctx.dx = (unsigned short) ((total_bytes_needed + 1023L) >> 10);\n  ctx.ax = 0x0900;\n  jxms_calldriver(xms_driver, (XMScontext far *) & ctx);\n  if (ctx.ax != 1)\n    return FALSE;\n\n  /* Succeeded, save the handle and away we go */\n  info->handle.xms_handle = ctx.dx;\n  info->read_backing_store = read_xms_store;\n  info->write_backing_store = write_xms_store;\n  info->close_backing_store = close_xms_store;\n  TRACEMS1(cinfo, 1, JTRC_XMS_OPEN, ctx.dx);\n  return TRUE;\t\t\t/* succeeded */\n}\n\n#endif /* XMS_SUPPORTED */\n\n\n/*\n * Access methods for expanded memory.\n */\n\n#if EMS_SUPPORTED\n\n/* The EMS move specification structure requires word and long fields aligned\n * at odd byte boundaries.  Some compilers will align struct fields at even\n * byte boundaries.  While it's usually possible to force byte alignment,\n * that causes an overall performance penalty and may pose problems in merging\n * JPEG into a larger application.  Instead we accept some rather dirty code\n * here.  Note this code would fail if the hardware did not allow odd-byte\n * word & long accesses, but all 80x86 CPUs do.\n */\n\ntypedef void far * EMSPTR;\n\ntypedef union {\t\t\t/* EMS move specification structure */\n\tlong length;\t\t/* It's easy to access first 4 bytes */\n\tchar bytes[18];\t\t/* Misaligned fields in here! */\n      } EMSspec;\n\n/* Macros for accessing misaligned fields */\n#define FIELD_AT(spec,offset,type)  (*((type *) &(spec.bytes[offset])))\n#define SRC_TYPE(spec)\t\tFIELD_AT(spec,4,char)\n#define SRC_HANDLE(spec)\tFIELD_AT(spec,5,EMSH)\n#define SRC_OFFSET(spec)\tFIELD_AT(spec,7,unsigned short)\n#define SRC_PAGE(spec)\t\tFIELD_AT(spec,9,unsigned short)\n#define SRC_PTR(spec)\t\tFIELD_AT(spec,7,EMSPTR)\n#define DST_TYPE(spec)\t\tFIELD_AT(spec,11,char)\n#define DST_HANDLE(spec)\tFIELD_AT(spec,12,EMSH)\n#define DST_OFFSET(spec)\tFIELD_AT(spec,14,unsigned short)\n#define DST_PAGE(spec)\t\tFIELD_AT(spec,16,unsigned short)\n#define DST_PTR(spec)\t\tFIELD_AT(spec,14,EMSPTR)\n\n#define EMSPAGESIZE\t16384L\t/* gospel, see the EMS specs */\n\n#define HIBYTE(W)  (((W) >> 8) & 0xFF)\n#define LOBYTE(W)  ((W) & 0xFF)\n\n\nMETHODDEF(void)\nread_ems_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\tvoid FAR * buffer_address,\n\t\tlong file_offset, long byte_count)\n{\n  EMScontext ctx;\n  EMSspec spec;\n\n  spec.length = byte_count;\n  SRC_TYPE(spec) = 1;\n  SRC_HANDLE(spec) = info->handle.ems_handle;\n  SRC_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);\n  SRC_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);\n  DST_TYPE(spec) = 0;\n  DST_HANDLE(spec) = 0;\n  DST_PTR(spec)    = buffer_address;\n  \n  ctx.ds_si = (void far *) & spec;\n  ctx.ax = 0x5700;\t\t/* move memory region */\n  jems_calldriver((EMScontext far *) & ctx);\n  if (HIBYTE(ctx.ax) != 0)\n    ERREXIT(cinfo, JERR_EMS_READ);\n}\n\n\nMETHODDEF(void)\nwrite_ems_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t void FAR * buffer_address,\n\t\t long file_offset, long byte_count)\n{\n  EMScontext ctx;\n  EMSspec spec;\n\n  spec.length = byte_count;\n  SRC_TYPE(spec) = 0;\n  SRC_HANDLE(spec) = 0;\n  SRC_PTR(spec)    = buffer_address;\n  DST_TYPE(spec) = 1;\n  DST_HANDLE(spec) = info->handle.ems_handle;\n  DST_PAGE(spec)   = (unsigned short) (file_offset / EMSPAGESIZE);\n  DST_OFFSET(spec) = (unsigned short) (file_offset % EMSPAGESIZE);\n  \n  ctx.ds_si = (void far *) & spec;\n  ctx.ax = 0x5700;\t\t/* move memory region */\n  jems_calldriver((EMScontext far *) & ctx);\n  if (HIBYTE(ctx.ax) != 0)\n    ERREXIT(cinfo, JERR_EMS_WRITE);\n}\n\n\nMETHODDEF(void)\nclose_ems_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  EMScontext ctx;\n\n  ctx.ax = 0x4500;\n  ctx.dx = info->handle.ems_handle;\n  jems_calldriver((EMScontext far *) & ctx);\n  TRACEMS1(cinfo, 1, JTRC_EMS_CLOSE, info->handle.ems_handle);\n  /* we ignore any error return from the driver */\n}\n\n\nLOCAL(boolean)\nopen_ems_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\tlong total_bytes_needed)\n{\n  EMScontext ctx;\n\n  /* Is EMS driver there? */\n  if (! jems_available())\n    return FALSE;\n\n  /* Get status, make sure EMS is OK */\n  ctx.ax = 0x4000;\n  jems_calldriver((EMScontext far *) & ctx);\n  if (HIBYTE(ctx.ax) != 0)\n    return FALSE;\n\n  /* Get version, must be >= 4.0 */\n  ctx.ax = 0x4600;\n  jems_calldriver((EMScontext far *) & ctx);\n  if (HIBYTE(ctx.ax) != 0 || LOBYTE(ctx.ax) < 0x40)\n    return FALSE;\n\n  /* Try to allocate requested space */\n  ctx.ax = 0x4300;\n  ctx.bx = (unsigned short) ((total_bytes_needed + EMSPAGESIZE-1L) / EMSPAGESIZE);\n  jems_calldriver((EMScontext far *) & ctx);\n  if (HIBYTE(ctx.ax) != 0)\n    return FALSE;\n\n  /* Succeeded, save the handle and away we go */\n  info->handle.ems_handle = ctx.dx;\n  info->read_backing_store = read_ems_store;\n  info->write_backing_store = write_ems_store;\n  info->close_backing_store = close_ems_store;\n  TRACEMS1(cinfo, 1, JTRC_EMS_OPEN, ctx.dx);\n  return TRUE;\t\t\t/* succeeded */\n}\n\n#endif /* EMS_SUPPORTED */\n\n\n/*\n * Initial opening of a backing-store object.\n */\n\nGLOBAL(void)\njpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t\t long total_bytes_needed)\n{\n  /* Try extended memory, then expanded memory, then regular file. */\n#if XMS_SUPPORTED\n  if (open_xms_store(cinfo, info, total_bytes_needed))\n    return;\n#endif\n#if EMS_SUPPORTED\n  if (open_ems_store(cinfo, info, total_bytes_needed))\n    return;\n#endif\n  if (open_file_store(cinfo, info, total_bytes_needed))\n    return;\n  ERREXITS(cinfo, JERR_TFILE_CREATE, \"\");\n}\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.\n */\n\nGLOBAL(long)\njpeg_mem_init (j_common_ptr cinfo)\n{\n  next_file_num = 0;\t\t/* initialize temp file name generator */\n  return DEFAULT_MAX_MEM;\t/* default for max_memory_to_use */\n}\n\nGLOBAL(void)\njpeg_mem_term (j_common_ptr cinfo)\n{\n  /* Microsoft C, at least in v6.00A, will not successfully reclaim freed\n   * blocks of size > 32Kbytes unless we give it a kick in the rear, like so:\n   */\n#ifdef NEED_FHEAPMIN\n  _fheapmin();\n#endif\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemdosa.asm",
    "content": ";\n; jmemdosa.asm\n;\n; Copyright (C) 1992, Thomas G. Lane.\n; This file is part of the Independent JPEG Group's software.\n; For conditions of distribution and use, see the accompanying README file.\n;\n; This file contains low-level interface routines to support the MS-DOS\n; backing store manager (jmemdos.c).  Routines are provided to access disk\n; files through direct DOS calls, and to access XMS and EMS drivers.\n;\n; This file should assemble with Microsoft's MASM or any compatible\n; assembler (including Borland's Turbo Assembler).  If you haven't got\n; a compatible assembler, better fall back to jmemansi.c or jmemname.c.\n;\n; To minimize dependence on the C compiler's register usage conventions,\n; we save and restore all 8086 registers, even though most compilers only\n; require SI,DI,DS to be preserved.  Also, we use only 16-bit-wide return\n; values, which everybody returns in AX.\n;\n; Based on code contributed by Ge' Weijers.\n;\n\nJMEMDOSA_TXT\tsegment byte public 'CODE'\n\n\t\tassume\tcs:JMEMDOSA_TXT\n\n\t\tpublic\t_jdos_open\n\t\tpublic\t_jdos_close\n\t\tpublic\t_jdos_seek\n\t\tpublic\t_jdos_read\n\t\tpublic\t_jdos_write\n\t\tpublic\t_jxms_getdriver\n\t\tpublic\t_jxms_calldriver\n\t\tpublic\t_jems_available\n\t\tpublic\t_jems_calldriver\n\n;\n; short far jdos_open (short far * handle, char far * filename)\n;\n; Create and open a temporary file\n;\n_jdos_open\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tcx,0\t\t\t; normal file attributes\n\t\tlds\tdx,dword ptr [bp+10]\t; get filename pointer\n\t\tmov\tah,3ch\t\t\t; create file\n\t\tint\t21h\n\t\tjc\topen_err\t\t; if failed, return error code\n\t\tlds\tbx,dword ptr [bp+6]\t; get handle pointer\n\t\tmov\tword ptr [bx],ax\t; save the handle\n\t\txor\tax,ax\t\t\t; return zero for OK\nopen_err:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jdos_open\tendp\n\n\n;\n; short far jdos_close (short handle)\n;\n; Close the file handle\n;\n_jdos_close\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tbx,word ptr [bp+6]\t; file handle\n\t\tmov\tah,3eh\t\t\t; close file\n\t\tint\t21h\n\t\tjc\tclose_err\t\t; if failed, return error code\n\t\txor\tax,ax\t\t\t; return zero for OK\nclose_err:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jdos_close\tendp\n\n\n;\n; short far jdos_seek (short handle, long offset)\n;\n; Set file position\n;\n_jdos_seek\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tbx,word ptr [bp+6]\t; file handle\n\t\tmov\tdx,word ptr [bp+8]\t; LS offset\n\t\tmov\tcx,word ptr [bp+10]\t; MS offset\n\t\tmov\tax,4200h\t\t; absolute seek\n\t\tint\t21h\n\t\tjc\tseek_err\t\t; if failed, return error code\n\t\txor\tax,ax\t\t\t; return zero for OK\nseek_err:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jdos_seek\tendp\n\n\n;\n; short far jdos_read (short handle, void far * buffer, unsigned short count)\n;\n; Read from file\n;\n_jdos_read\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tbx,word ptr [bp+6]\t; file handle\n\t\tlds\tdx,dword ptr [bp+8]\t; buffer address\n\t\tmov\tcx,word ptr [bp+12]\t; number of bytes\n\t\tmov\tah,3fh\t\t\t; read file\n\t\tint\t21h\n\t\tjc\tread_err\t\t; if failed, return error code\n\t\tcmp\tax,word ptr [bp+12]\t; make sure all bytes were read\n\t\tje\tread_ok\n\t\tmov\tax,1\t\t\t; else return 1 for not OK\n\t\tjmp\tshort read_err\nread_ok:\txor\tax,ax\t\t\t; return zero for OK\nread_err:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jdos_read\tendp\n\n\n;\n; short far jdos_write (short handle, void far * buffer, unsigned short count)\n;\n; Write to file\n;\n_jdos_write\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tbx,word ptr [bp+6]\t; file handle\n\t\tlds\tdx,dword ptr [bp+8]\t; buffer address\n\t\tmov\tcx,word ptr [bp+12]\t; number of bytes\n\t\tmov\tah,40h\t\t\t; write file\n\t\tint\t21h\n\t\tjc\twrite_err\t\t; if failed, return error code\n\t\tcmp\tax,word ptr [bp+12]\t; make sure all bytes written\n\t\tje\twrite_ok\n\t\tmov\tax,1\t\t\t; else return 1 for not OK\n\t\tjmp\tshort write_err\nwrite_ok:\txor\tax,ax\t\t\t; return zero for OK\nwrite_err:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jdos_write\tendp\n\n\n;\n; void far jxms_getdriver (XMSDRIVER far *)\n;\n; Get the address of the XMS driver, or NULL if not available\n;\n_jxms_getdriver\tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov \tax,4300h\t\t; call multiplex interrupt with\n\t\tint\t2fh\t\t\t; a magic cookie, hex 4300\n\t\tcmp \tal,80h\t\t\t; AL should contain hex 80\n\t\tje\txmsavail\n\t\txor \tdx,dx\t\t\t; no XMS driver available\n\t\txor \tax,ax\t\t\t; return a nil pointer\n\t\tjmp\tshort xmsavail_done\nxmsavail:\tmov \tax,4310h\t\t; fetch driver address with\n\t\tint\t2fh\t\t\t; another magic cookie\n\t\tmov \tdx,es\t\t\t; copy address to dx:ax\n\t\tmov \tax,bx\nxmsavail_done:\tles \tbx,dword ptr [bp+6]\t; get pointer to return value\n\t\tmov\tword ptr es:[bx],ax\n\t\tmov\tword ptr es:[bx+2],dx\n\t\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop\tbp\n\t\tret\n_jxms_getdriver\tendp\n\n\n;\n; void far jxms_calldriver (XMSDRIVER, XMScontext far *)\n;\n; The XMScontext structure contains values for the AX,DX,BX,SI,DS registers.\n; These are loaded, the XMS call is performed, and the new values of the\n; AX,DX,BX registers are written back to the context structure.\n;\n_jxms_calldriver \tproc\tfar\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tles \tbx,dword ptr [bp+10]\t; get XMScontext pointer\n\t\tmov \tax,word ptr es:[bx]\t; load registers\n\t\tmov \tdx,word ptr es:[bx+2]\n\t\tmov \tsi,word ptr es:[bx+6]\n\t\tmov \tds,word ptr es:[bx+8]\n\t\tmov \tbx,word ptr es:[bx+4]\n\t\tcall\tdword ptr [bp+6]\t; call the driver\n\t\tmov\tcx,bx\t\t\t; save returned BX for a sec\n\t\tles \tbx,dword ptr [bp+10]\t; get XMScontext pointer\n\t\tmov \tword ptr es:[bx],ax\t; put back ax,dx,bx\n\t\tmov \tword ptr es:[bx+2],dx\n\t\tmov \tword ptr es:[bx+4],cx\n\t\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jxms_calldriver \tendp\n\n\n;\n; short far jems_available (void)\n;\n; Have we got an EMS driver? (this comes straight from the EMS 4.0 specs)\n;\n_jems_available\tproc\tfar\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tmov\tax,3567h\t\t; get interrupt vector 67h\n\t\tint\t21h\n\t\tpush\tcs\n\t\tpop\tds\n\t\tmov\tdi,000ah\t\t; check offs 10 in returned seg\n\t\tlea\tsi,ASCII_device_name\t; against literal string\n\t\tmov\tcx,8\n\t\tcld\n\t\trepe cmpsb\n\t\tjne\tno_ems\n\t\tmov\tax,1\t\t\t; match, it's there\n\t\tjmp\tshort avail_done\nno_ems:\t\txor\tax,ax\t\t\t; it's not there\navail_done:\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tret\n\nASCII_device_name\tdb\t\"EMMXXXX0\"\n\n_jems_available\tendp\n\n\n;\n; void far jems_calldriver (EMScontext far *)\n;\n; The EMScontext structure contains values for the AX,DX,BX,SI,DS registers.\n; These are loaded, the EMS trap is performed, and the new values of the\n; AX,DX,BX registers are written back to the context structure.\n;\n_jems_calldriver\tproc far\n\t\tpush\tbp\t\t\t; linkage\n\t\tmov \tbp,sp\n\t\tpush\tsi\t\t\t; save all registers for safety\n\t\tpush\tdi\n\t\tpush\tbx\n\t\tpush\tcx\n\t\tpush\tdx\n\t\tpush\tes\n\t\tpush\tds\n\t\tles \tbx,dword ptr [bp+6]\t; get EMScontext pointer\n\t\tmov \tax,word ptr es:[bx]\t; load registers\n\t\tmov \tdx,word ptr es:[bx+2]\n\t\tmov \tsi,word ptr es:[bx+6]\n\t\tmov \tds,word ptr es:[bx+8]\n\t\tmov \tbx,word ptr es:[bx+4]\n\t\tint\t67h\t\t\t; call the EMS driver\n\t\tmov\tcx,bx\t\t\t; save returned BX for a sec\n\t\tles \tbx,dword ptr [bp+6]\t; get EMScontext pointer\n\t\tmov \tword ptr es:[bx],ax\t; put back ax,dx,bx\n\t\tmov \tword ptr es:[bx+2],dx\n\t\tmov \tword ptr es:[bx+4],cx\n\t\tpop\tds\t\t\t; restore registers and exit\n\t\tpop\tes\n\t\tpop\tdx\n\t\tpop\tcx\n\t\tpop\tbx\n\t\tpop\tdi\n\t\tpop\tsi\n\t\tpop \tbp\n\t\tret\n_jems_calldriver\tendp\n\nJMEMDOSA_TXT\tends\n\n\t\tend\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemmac.c",
    "content": "/*\n * jmemmac.c\n *\n * Copyright (C) 1992-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * jmemmac.c provides an Apple Macintosh implementation of the system-\n * dependent portion of the JPEG memory manager.\n *\n * If you use jmemmac.c, then you must define USE_MAC_MEMMGR in the\n * JPEG_INTERNALS part of jconfig.h.\n *\n * jmemmac.c uses the Macintosh toolbox routines NewPtr and DisposePtr\n * instead of malloc and free.  It accurately determines the amount of\n * memory available by using CompactMem.  Notice that if left to its\n * own devices, this code can chew up all available space in the\n * application's zone, with the exception of the rather small \"slop\"\n * factor computed in jpeg_mem_available().  The application can ensure\n * that more space is left over by reducing max_memory_to_use.\n *\n * Large images are swapped to disk using temporary files and System 7.0+'s\n * temporary folder functionality.\n *\n * Note that jmemmac.c depends on two features of MacOS that were first\n * introduced in System 7: FindFolder and the FSSpec-based calls.\n * If your application uses jmemmac.c and is run under System 6 or earlier,\n * and the jpeg library decides it needs a temporary file, it will abort,\n * printing error messages about requiring System 7.  (If no temporary files\n * are created, it will run fine.)\n *\n * If you want to use jmemmac.c in an application that might be used with\n * System 6 or earlier, then you should remove dependencies on FindFolder\n * and the FSSpec calls.  You will need to replace FindFolder with some\n * other mechanism for finding a place to put temporary files, and you\n * should replace the FSSpec calls with their HFS equivalents:\n *\n *     FSpDelete     ->  HDelete\n *     FSpGetFInfo   ->  HGetFInfo\n *     FSpCreate     ->  HCreate\n *     FSpOpenDF     ->  HOpen      *** Note: not HOpenDF ***\n *     FSMakeFSSpec  ->  (fill in spec by hand.)\n *\n * (Use HOpen instead of HOpenDF.  HOpen is just a glue-interface to PBHOpen,\n * which is on all HFS macs.  HOpenDF is a System 7 addition which avoids the\n * ages-old problem of names starting with a period.)\n *\n * Contributed by Sam Bushell (jsam@iagu.on.net) and\n * Dan Gildor (gyld@in-touch.com).\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"    /* import the system-dependent declarations */\n\n#ifndef USE_MAC_MEMMGR\t/* make sure user got configuration right */\n  You forgot to define USE_MAC_MEMMGR in jconfig.h. /* deliberate syntax error */\n#endif\n\n#include <Memory.h>     /* we use the MacOS memory manager */\n#include <Files.h>      /* we use the MacOS File stuff */\n#include <Folders.h>    /* we use the MacOS HFS stuff */\n#include <Script.h>     /* for smSystemScript */\n#include <Gestalt.h>    /* we use Gestalt to test for specific functionality */\n\n#ifndef TEMP_FILE_NAME\t\t/* can override from jconfig.h or Makefile */\n#define TEMP_FILE_NAME  \"JPG%03d.TMP\"\n#endif\n\nstatic int next_file_num;\t/* to distinguish among several temp files */\n\n\n/*\n * Memory allocation and freeing are controlled by the MacOS library\n * routines NewPtr() and DisposePtr(), which allocate fixed-address\n * storage.  Unfortunately, the IJG library isn't smart enough to cope\n * with relocatable storage.\n */\n\nGLOBAL(void *)\njpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void *) NewPtr(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)\n{\n  DisposePtr((Ptr) object);\n}\n\n\n/*\n * \"Large\" objects are treated the same as \"small\" ones.\n * NB: we include FAR keywords in the routine declarations simply for\n * consistency with the rest of the IJG code; FAR should expand to empty\n * on rational architectures like the Mac.\n */\n\nGLOBAL(void FAR *)\njpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void FAR *) NewPtr(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)\n{\n  DisposePtr((Ptr) object);\n}\n\n\n/*\n * This routine computes the total memory space available for allocation.\n */\n\nGLOBAL(long)\njpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,\n\t\t    long max_bytes_needed, long already_allocated)\n{\n  long limit = cinfo->mem->max_memory_to_use - already_allocated;\n  long slop, mem;\n\n  /* Don't ask for more than what application has told us we may use */\n  if (max_bytes_needed > limit && limit > 0)\n    max_bytes_needed = limit;\n  /* Find whether there's a big enough free block in the heap.\n   * CompactMem tries to create a contiguous block of the requested size,\n   * and then returns the size of the largest free block (which could be\n   * much more or much less than we asked for).\n   * We add some slop to ensure we don't use up all available memory.\n   */\n  slop = max_bytes_needed / 16 + 32768L;\n  mem = CompactMem(max_bytes_needed + slop) - slop;\n  if (mem < 0)\n    mem = 0;\t\t\t/* sigh, couldn't even get the slop */\n  /* Don't take more than the application says we can have */\n  if (mem > limit && limit > 0)\n    mem = limit;\n  return mem;\n}\n\n\n/*\n * Backing store (temporary file) management.\n * Backing store objects are only used when the value returned by\n * jpeg_mem_available is less than the total space needed.  You can dispense\n * with these routines if you have plenty of virtual memory; see jmemnobs.c.\n */\n\n\nMETHODDEF(void)\nread_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t    void FAR * buffer_address,\n\t\t    long file_offset, long byte_count)\n{\n  long bytes = byte_count;\n  long retVal;\n\n  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n\n  retVal = FSRead ( info->temp_file, &bytes,\n\t\t    (unsigned char *) buffer_address );\n  if ( retVal != noErr || bytes != byte_count )\n    ERREXIT(cinfo, JERR_TFILE_READ);\n}\n\n\nMETHODDEF(void)\nwrite_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t     void FAR * buffer_address,\n\t\t     long file_offset, long byte_count)\n{\n  long bytes = byte_count;\n  long retVal;\n\n  if ( SetFPos ( info->temp_file, fsFromStart, file_offset ) != noErr )\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n\n  retVal = FSWrite ( info->temp_file, &bytes,\n\t\t     (unsigned char *) buffer_address );\n  if ( retVal != noErr || bytes != byte_count )\n    ERREXIT(cinfo, JERR_TFILE_WRITE);\n}\n\n\nMETHODDEF(void)\nclose_backing_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  FSClose ( info->temp_file );\n  FSpDelete ( &(info->tempSpec) );\n}\n\n\n/*\n * Initial opening of a backing-store object.\n *\n * This version uses FindFolder to find the Temporary Items folder,\n * and puts the temporary file in there.\n */\n\nGLOBAL(void)\njpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t\t long total_bytes_needed)\n{\n  short         tmpRef, vRefNum;\n  long          dirID;\n  FInfo         finderInfo;\n  FSSpec        theSpec;\n  Str255        fName;\n  OSErr         osErr;\n  long          gestaltResponse = 0;\n\n  /* Check that FSSpec calls are available. */\n  osErr = Gestalt( gestaltFSAttr, &gestaltResponse );\n  if ( ( osErr != noErr )\n       || !( gestaltResponse & (1<<gestaltHasFSSpecCalls) ) )\n    ERREXITS(cinfo, JERR_TFILE_CREATE, \"- System 7.0 or later required\");\n  /* TO DO: add a proper error message to jerror.h. */\n\n  /* Check that FindFolder is available. */\n  osErr = Gestalt( gestaltFindFolderAttr, &gestaltResponse );\n  if ( ( osErr != noErr )\n       || !( gestaltResponse & (1<<gestaltFindFolderPresent) ) )\n    ERREXITS(cinfo, JERR_TFILE_CREATE, \"- System 7.0 or later required.\");\n  /* TO DO: add a proper error message to jerror.h. */\n\n  osErr = FindFolder ( kOnSystemDisk, kTemporaryFolderType, kCreateFolder,\n                       &vRefNum, &dirID );\n  if ( osErr != noErr )\n    ERREXITS(cinfo, JERR_TFILE_CREATE, \"- temporary items folder unavailable\");\n  /* TO DO: Try putting the temp files somewhere else. */\n\n  /* Keep generating file names till we find one that's not in use */\n  for (;;) {\n    next_file_num++;\t\t/* advance counter */\n\n    sprintf(info->temp_name, TEMP_FILE_NAME, next_file_num);\n    strcpy ( (Ptr)fName+1, info->temp_name );\n    *fName = strlen (info->temp_name);\n    osErr = FSMakeFSSpec ( vRefNum, dirID, fName, &theSpec );\n\n    if ( (osErr = FSpGetFInfo ( &theSpec, &finderInfo ) ) != noErr )\n      break;\n  }\n\n  osErr = FSpCreate ( &theSpec, '????', '????', smSystemScript );\n  if ( osErr != noErr )\n    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);\n\n  osErr = FSpOpenDF ( &theSpec, fsRdWrPerm, &(info->temp_file) );\n  if ( osErr != noErr )\n    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);\n\n  info->tempSpec = theSpec;\n\n  info->read_backing_store = read_backing_store;\n  info->write_backing_store = write_backing_store;\n  info->close_backing_store = close_backing_store;\n  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);\n}\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.\n */\n\nGLOBAL(long)\njpeg_mem_init (j_common_ptr cinfo)\n{\n  next_file_num = 0;\n\n  /* max_memory_to_use will be initialized to FreeMem()'s result;\n   * the calling application might later reduce it, for example\n   * to leave room to invoke multiple JPEG objects.\n   * Note that FreeMem returns the total number of free bytes;\n   * it may not be possible to allocate a single block of this size.\n   */\n  return FreeMem();\n}\n\nGLOBAL(void)\njpeg_mem_term (j_common_ptr cinfo)\n{\n  /* no work */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemmgr.c",
    "content": "/*\n * jmemmgr.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2011-2012 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains the JPEG system-independent memory management\n * routines.  This code is usable across a wide variety of machines; most\n * of the system dependencies have been isolated in a separate file.\n * The major functions provided here are:\n *   * pool-based allocation and freeing of memory;\n *   * policy decisions about how to divide available memory among the\n *     virtual arrays;\n *   * control logic for swapping virtual arrays between main memory and\n *     backing storage.\n * The separate system-dependent file provides the actual backing-storage\n * access code, and it contains the policy decision about how much total\n * main memory to use.\n * This file is system-dependent in the sense that some of its functions\n * are unnecessary in some systems.  For example, if there is enough virtual\n * memory so that backing storage will never be used, much of the virtual\n * array control logic could be removed.  (Of course, if you have that much\n * memory then you shouldn't care about a little bit of unused code...)\n */\n\n#define JPEG_INTERNALS\n#define AM_MEMORY_MANAGER\t/* we define jvirt_Xarray_control structs */\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"\t\t/* import the system-dependent declarations */\n\n#ifndef NO_GETENV\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare getenv() */\nextern char * getenv JPP((const char * name));\n#endif\n#endif\n\n\n/*\n * Some important notes:\n *   The allocation routines provided here must never return NULL.\n *   They should exit to error_exit if unsuccessful.\n *\n *   It's not a good idea to try to merge the sarray and barray routines,\n *   even though they are textually almost the same, because samples are\n *   usually stored as bytes while coefficients are shorts or ints.  Thus,\n *   in machines where byte pointers have a different representation from\n *   word pointers, the resulting machine code could not be the same.\n */\n\n\n/*\n * Many machines require storage alignment: longs must start on 4-byte\n * boundaries, doubles on 8-byte boundaries, etc.  On such machines, malloc()\n * always returns pointers that are multiples of the worst-case alignment\n * requirement, and we had better do so too.\n * There isn't any really portable way to determine the worst-case alignment\n * requirement.  This module assumes that the alignment requirement is\n * multiples of sizeof(ALIGN_TYPE).\n * By default, we define ALIGN_TYPE as double.  This is necessary on some\n * workstations (where doubles really do need 8-byte alignment) and will work\n * fine on nearly everything.  If your machine has lesser alignment needs,\n * you can save a few bytes by making ALIGN_TYPE smaller.\n * The only place I know of where this will NOT work is certain Macintosh\n * 680x0 compilers that define double as a 10-byte IEEE extended float.\n * Doing 10-byte alignment is counterproductive because longwords won't be\n * aligned well.  Put \"#define ALIGN_TYPE long\" in jconfig.h if you have\n * such a compiler.\n */\n\n#ifndef ALIGN_TYPE\t\t/* so can override from jconfig.h */\n#define ALIGN_TYPE  double\n#endif\n\n\n/*\n * We allocate objects from \"pools\", where each pool is gotten with a single\n * request to jpeg_get_small() or jpeg_get_large().  There is no per-object\n * overhead within a pool, except for alignment padding.  Each pool has a\n * header with a link to the next pool of the same class.\n * Small and large pool headers are identical except that the latter's\n * link pointer must be FAR on 80x86 machines.\n * Notice that the \"real\" header fields are union'ed with a dummy ALIGN_TYPE\n * field.  This forces the compiler to make SIZEOF(small_pool_hdr) a multiple\n * of the alignment requirement of ALIGN_TYPE.\n */\n\ntypedef union small_pool_struct * small_pool_ptr;\n\ntypedef union small_pool_struct {\n  struct {\n    small_pool_ptr next;\t/* next in list of pools */\n    size_t bytes_used;\t\t/* how many bytes already used within pool */\n    size_t bytes_left;\t\t/* bytes still available in this pool */\n  } hdr;\n  ALIGN_TYPE dummy;\t\t/* included in union to ensure alignment */\n} small_pool_hdr;\n\ntypedef union large_pool_struct FAR * large_pool_ptr;\n\ntypedef union large_pool_struct {\n  struct {\n    large_pool_ptr next;\t/* next in list of pools */\n    size_t bytes_used;\t\t/* how many bytes already used within pool */\n    size_t bytes_left;\t\t/* bytes still available in this pool */\n  } hdr;\n  ALIGN_TYPE dummy;\t\t/* included in union to ensure alignment */\n} large_pool_hdr;\n\n\n/*\n * Here is the full definition of a memory manager object.\n */\n\ntypedef struct {\n  struct jpeg_memory_mgr pub;\t/* public fields */\n\n  /* Each pool identifier (lifetime class) names a linked list of pools. */\n  small_pool_ptr small_list[JPOOL_NUMPOOLS];\n  large_pool_ptr large_list[JPOOL_NUMPOOLS];\n\n  /* Since we only have one lifetime class of virtual arrays, only one\n   * linked list is necessary (for each datatype).  Note that the virtual\n   * array control blocks being linked together are actually stored somewhere\n   * in the small-pool list.\n   */\n  jvirt_sarray_ptr virt_sarray_list;\n  jvirt_barray_ptr virt_barray_list;\n\n  /* This counts total space obtained from jpeg_get_small/large */\n  long total_space_allocated;\n\n  /* alloc_sarray and alloc_barray set this value for use by virtual\n   * array routines.\n   */\n  JDIMENSION last_rowsperchunk;\t/* from most recent alloc_sarray/barray */\n} my_memory_mgr;\n\ntypedef my_memory_mgr * my_mem_ptr;\n\n\n/*\n * The control blocks for virtual arrays.\n * Note that these blocks are allocated in the \"small\" pool area.\n * System-dependent info for the associated backing store (if any) is hidden\n * inside the backing_store_info struct.\n */\n\nstruct jvirt_sarray_control {\n  JSAMPARRAY mem_buffer;\t/* => the in-memory buffer */\n  JDIMENSION rows_in_array;\t/* total virtual array height */\n  JDIMENSION samplesperrow;\t/* width of array (and of memory buffer) */\n  JDIMENSION maxaccess;\t\t/* max rows accessed by access_virt_sarray */\n  JDIMENSION rows_in_mem;\t/* height of memory buffer */\n  JDIMENSION rowsperchunk;\t/* allocation chunk size in mem_buffer */\n  JDIMENSION cur_start_row;\t/* first logical row # in the buffer */\n  JDIMENSION first_undef_row;\t/* row # of first uninitialized row */\n  boolean pre_zero;\t\t/* pre-zero mode requested? */\n  boolean dirty;\t\t/* do current buffer contents need written? */\n  boolean b_s_open;\t\t/* is backing-store data valid? */\n  jvirt_sarray_ptr next;\t/* link to next virtual sarray control block */\n  backing_store_info b_s_info;\t/* System-dependent control info */\n};\n\nstruct jvirt_barray_control {\n  JBLOCKARRAY mem_buffer;\t/* => the in-memory buffer */\n  JDIMENSION rows_in_array;\t/* total virtual array height */\n  JDIMENSION blocksperrow;\t/* width of array (and of memory buffer) */\n  JDIMENSION maxaccess;\t\t/* max rows accessed by access_virt_barray */\n  JDIMENSION rows_in_mem;\t/* height of memory buffer */\n  JDIMENSION rowsperchunk;\t/* allocation chunk size in mem_buffer */\n  JDIMENSION cur_start_row;\t/* first logical row # in the buffer */\n  JDIMENSION first_undef_row;\t/* row # of first uninitialized row */\n  boolean pre_zero;\t\t/* pre-zero mode requested? */\n  boolean dirty;\t\t/* do current buffer contents need written? */\n  boolean b_s_open;\t\t/* is backing-store data valid? */\n  jvirt_barray_ptr next;\t/* link to next virtual barray control block */\n  backing_store_info b_s_info;\t/* System-dependent control info */\n};\n\n\n#ifdef MEM_STATS\t\t/* optional extra stuff for statistics */\n\nLOCAL(void)\nprint_mem_stats (j_common_ptr cinfo, int pool_id)\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  small_pool_ptr shdr_ptr;\n  large_pool_ptr lhdr_ptr;\n\n  /* Since this is only a debugging stub, we can cheat a little by using\n   * fprintf directly rather than going through the trace message code.\n   * This is helpful because message parm array can't handle longs.\n   */\n  fprintf(stderr, \"Freeing pool %d, total space = %ld\\n\",\n\t  pool_id, mem->total_space_allocated);\n\n  for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;\n       lhdr_ptr = lhdr_ptr->hdr.next) {\n    fprintf(stderr, \"  Large chunk used %ld\\n\",\n\t    (long) lhdr_ptr->hdr.bytes_used);\n  }\n\n  for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;\n       shdr_ptr = shdr_ptr->hdr.next) {\n    fprintf(stderr, \"  Small chunk used %ld free %ld\\n\",\n\t    (long) shdr_ptr->hdr.bytes_used,\n\t    (long) shdr_ptr->hdr.bytes_left);\n  }\n}\n\n#endif /* MEM_STATS */\n\n\nLOCAL(noreturn_t)\nout_of_memory (j_common_ptr cinfo, int which)\n/* Report an out-of-memory error and stop execution */\n/* If we compiled MEM_STATS support, report alloc requests before dying */\n{\n#ifdef MEM_STATS\n  cinfo->err->trace_level = 2;\t/* force self_destruct to report stats */\n#endif\n  ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);\n}\n\n\n/*\n * Allocation of \"small\" objects.\n *\n * For these, we use pooled storage.  When a new pool must be created,\n * we try to get enough space for the current request plus a \"slop\" factor,\n * where the slop will be the amount of leftover space in the new pool.\n * The speed vs. space tradeoff is largely determined by the slop values.\n * A different slop value is provided for each pool class (lifetime),\n * and we also distinguish the first pool of a class from later ones.\n * NOTE: the values given work fairly well on both 16- and 32-bit-int\n * machines, but may be too small if longs are 64 bits or more.\n */\n\nstatic const size_t first_pool_slop[JPOOL_NUMPOOLS] = \n{\n\t1600,\t\t\t/* first PERMANENT pool */\n\t16000\t\t\t/* first IMAGE pool */\n};\n\nstatic const size_t extra_pool_slop[JPOOL_NUMPOOLS] = \n{\n\t0,\t\t\t/* additional PERMANENT pools */\n\t5000\t\t\t/* additional IMAGE pools */\n};\n\n#define MIN_SLOP  50\t\t/* greater than 0 to avoid futile looping */\n\n\nMETHODDEF(void *)\nalloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)\n/* Allocate a \"small\" object */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  small_pool_ptr hdr_ptr, prev_hdr_ptr;\n  char * data_ptr;\n  size_t odd_bytes, min_request, slop;\n\n  /* Check for unsatisfiable request (do now to ensure no overflow below) */\n  if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))\n    out_of_memory(cinfo, 1);\t/* request exceeds malloc's ability */\n\n  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */\n  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);\n  if (odd_bytes > 0)\n    sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;\n\n  /* See if space is available in any existing pool */\n  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)\n    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);\t/* safety check */\n  prev_hdr_ptr = NULL;\n  hdr_ptr = mem->small_list[pool_id];\n  while (hdr_ptr != NULL) {\n    if (hdr_ptr->hdr.bytes_left >= sizeofobject)\n      break;\t\t\t/* found pool with enough space */\n    prev_hdr_ptr = hdr_ptr;\n    hdr_ptr = hdr_ptr->hdr.next;\n  }\n\n  /* Time to make a new pool? */\n  if (hdr_ptr == NULL) {\n    /* min_request is what we need now, slop is what will be leftover */\n    min_request = sizeofobject + SIZEOF(small_pool_hdr);\n    if (prev_hdr_ptr == NULL)\t/* first pool in class? */\n      slop = first_pool_slop[pool_id];\n    else\n      slop = extra_pool_slop[pool_id];\n    /* Don't ask for more than MAX_ALLOC_CHUNK */\n    if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))\n      slop = (size_t) (MAX_ALLOC_CHUNK-min_request);\n    /* Try to get space, if fail reduce slop and try again */\n    for (;;) {\n      hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);\n      if (hdr_ptr != NULL)\n\tbreak;\n      slop /= 2;\n      if (slop < MIN_SLOP)\t/* give up when it gets real small */\n\tout_of_memory(cinfo, 2); /* jpeg_get_small failed */\n    }\n    mem->total_space_allocated += min_request + slop;\n    /* Success, initialize the new pool header and add to end of list */\n    hdr_ptr->hdr.next = NULL;\n    hdr_ptr->hdr.bytes_used = 0;\n    hdr_ptr->hdr.bytes_left = sizeofobject + slop;\n    if (prev_hdr_ptr == NULL)\t/* first pool in class? */\n      mem->small_list[pool_id] = hdr_ptr;\n    else\n      prev_hdr_ptr->hdr.next = hdr_ptr;\n  }\n\n  /* OK, allocate the object from the current pool */\n  data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */\n  data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */\n  hdr_ptr->hdr.bytes_used += sizeofobject;\n  hdr_ptr->hdr.bytes_left -= sizeofobject;\n\n  return (void *) data_ptr;\n}\n\n\n/*\n * Allocation of \"large\" objects.\n *\n * The external semantics of these are the same as \"small\" objects,\n * except that FAR pointers are used on 80x86.  However the pool\n * management heuristics are quite different.  We assume that each\n * request is large enough that it may as well be passed directly to\n * jpeg_get_large; the pool management just links everything together\n * so that we can free it all on demand.\n * Note: the major use of \"large\" objects is in JSAMPARRAY and JBLOCKARRAY\n * structures.  The routines that create these structures (see below)\n * deliberately bunch rows together to ensure a large request size.\n */\n\nMETHODDEF(void FAR *)\nalloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)\n/* Allocate a \"large\" object */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  large_pool_ptr hdr_ptr;\n  size_t odd_bytes;\n\n  /* Check for unsatisfiable request (do now to ensure no overflow below) */\n  if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))\n    out_of_memory(cinfo, 3);\t/* request exceeds malloc's ability */\n\n  /* Round up the requested size to a multiple of SIZEOF(ALIGN_TYPE) */\n  odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);\n  if (odd_bytes > 0)\n    sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;\n\n  /* Always make a new pool */\n  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)\n    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);\t/* safety check */\n\n  hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +\n\t\t\t\t\t    SIZEOF(large_pool_hdr));\n  if (hdr_ptr == NULL)\n    out_of_memory(cinfo, 4);\t/* jpeg_get_large failed */\n  mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);\n\n  /* Success, initialize the new pool header and add to list */\n  hdr_ptr->hdr.next = mem->large_list[pool_id];\n  /* We maintain space counts in each pool header for statistical purposes,\n   * even though they are not needed for allocation.\n   */\n  hdr_ptr->hdr.bytes_used = sizeofobject;\n  hdr_ptr->hdr.bytes_left = 0;\n  mem->large_list[pool_id] = hdr_ptr;\n\n  return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */\n}\n\n\n/*\n * Creation of 2-D sample arrays.\n * The pointers are in near heap, the samples themselves in FAR heap.\n *\n * To minimize allocation overhead and to allow I/O of large contiguous\n * blocks, we allocate the sample rows in groups of as many rows as possible\n * without exceeding MAX_ALLOC_CHUNK total bytes per allocation request.\n * NB: the virtual array control routines, later in this file, know about\n * this chunking of rows.  The rowsperchunk value is left in the mem manager\n * object so that it can be saved away if this sarray is the workspace for\n * a virtual array.\n */\n\nMETHODDEF(JSAMPARRAY)\nalloc_sarray (j_common_ptr cinfo, int pool_id,\n\t      JDIMENSION samplesperrow, JDIMENSION numrows)\n/* Allocate a 2-D sample array */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  JSAMPARRAY result;\n  JSAMPROW workspace;\n  JDIMENSION rowsperchunk, currow, i;\n  long ltemp;\n\n  /* Calculate max # of rows allowed in one allocation chunk */\n  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /\n\t  ((long) samplesperrow * SIZEOF(JSAMPLE));\n  if (ltemp <= 0)\n    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);\n  if (ltemp < (long) numrows)\n    rowsperchunk = (JDIMENSION) ltemp;\n  else\n    rowsperchunk = numrows;\n  mem->last_rowsperchunk = rowsperchunk;\n\n  /* Get space for row pointers (small object) */\n  result = (JSAMPARRAY) alloc_small(cinfo, pool_id,\n\t\t\t\t    (size_t) (numrows * SIZEOF(JSAMPROW)));\n\n  /* Get the rows themselves (large objects) */\n  currow = 0;\n  while (currow < numrows) {\n    rowsperchunk = MIN(rowsperchunk, numrows - currow);\n    workspace = (JSAMPROW) alloc_large(cinfo, pool_id,\n\t(size_t) ((size_t) rowsperchunk * (size_t) samplesperrow\n\t\t  * SIZEOF(JSAMPLE)));\n    for (i = rowsperchunk; i > 0; i--) {\n      result[currow++] = workspace;\n      workspace += samplesperrow;\n    }\n  }\n\n  return result;\n}\n\n\n/*\n * Creation of 2-D coefficient-block arrays.\n * This is essentially the same as the code for sample arrays, above.\n */\n\nMETHODDEF(JBLOCKARRAY)\nalloc_barray (j_common_ptr cinfo, int pool_id,\n\t      JDIMENSION blocksperrow, JDIMENSION numrows)\n/* Allocate a 2-D coefficient-block array */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  JBLOCKARRAY result;\n  JBLOCKROW workspace;\n  JDIMENSION rowsperchunk, currow, i;\n  long ltemp;\n\n  /* Calculate max # of rows allowed in one allocation chunk */\n  ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /\n\t  ((long) blocksperrow * SIZEOF(JBLOCK));\n  if (ltemp <= 0)\n    ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);\n  if (ltemp < (long) numrows)\n    rowsperchunk = (JDIMENSION) ltemp;\n  else\n    rowsperchunk = numrows;\n  mem->last_rowsperchunk = rowsperchunk;\n\n  /* Get space for row pointers (small object) */\n  result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,\n\t\t\t\t     (size_t) (numrows * SIZEOF(JBLOCKROW)));\n\n  /* Get the rows themselves (large objects) */\n  currow = 0;\n  while (currow < numrows) {\n    rowsperchunk = MIN(rowsperchunk, numrows - currow);\n    workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,\n\t(size_t) ((size_t) rowsperchunk * (size_t) blocksperrow\n\t\t  * SIZEOF(JBLOCK)));\n    for (i = rowsperchunk; i > 0; i--) {\n      result[currow++] = workspace;\n      workspace += blocksperrow;\n    }\n  }\n\n  return result;\n}\n\n\n/*\n * About virtual array management:\n *\n * The above \"normal\" array routines are only used to allocate strip buffers\n * (as wide as the image, but just a few rows high).  Full-image-sized buffers\n * are handled as \"virtual\" arrays.  The array is still accessed a strip at a\n * time, but the memory manager must save the whole array for repeated\n * accesses.  The intended implementation is that there is a strip buffer in\n * memory (as high as is possible given the desired memory limit), plus a\n * backing file that holds the rest of the array.\n *\n * The request_virt_array routines are told the total size of the image and\n * the maximum number of rows that will be accessed at once.  The in-memory\n * buffer must be at least as large as the maxaccess value.\n *\n * The request routines create control blocks but not the in-memory buffers.\n * That is postponed until realize_virt_arrays is called.  At that time the\n * total amount of space needed is known (approximately, anyway), so free\n * memory can be divided up fairly.\n *\n * The access_virt_array routines are responsible for making a specific strip\n * area accessible (after reading or writing the backing file, if necessary).\n * Note that the access routines are told whether the caller intends to modify\n * the accessed strip; during a read-only pass this saves having to rewrite\n * data to disk.  The access routines are also responsible for pre-zeroing\n * any newly accessed rows, if pre-zeroing was requested.\n *\n * In current usage, the access requests are usually for nonoverlapping\n * strips; that is, successive access start_row numbers differ by exactly\n * num_rows = maxaccess.  This means we can get good performance with simple\n * buffer dump/reload logic, by making the in-memory buffer be a multiple\n * of the access height; then there will never be accesses across bufferload\n * boundaries.  The code will still work with overlapping access requests,\n * but it doesn't handle bufferload overlaps very efficiently.\n */\n\n\nMETHODDEF(jvirt_sarray_ptr)\nrequest_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,\n\t\t     JDIMENSION samplesperrow, JDIMENSION numrows,\n\t\t     JDIMENSION maxaccess)\n/* Request a virtual 2-D sample array */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  jvirt_sarray_ptr result;\n\n  /* Only IMAGE-lifetime virtual arrays are currently supported */\n  if (pool_id != JPOOL_IMAGE)\n    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);\t/* safety check */\n\n  /* get control block */\n  result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,\n\t\t\t\t\t  SIZEOF(struct jvirt_sarray_control));\n\n  result->mem_buffer = NULL;\t/* marks array not yet realized */\n  result->rows_in_array = numrows;\n  result->samplesperrow = samplesperrow;\n  result->maxaccess = maxaccess;\n  result->pre_zero = pre_zero;\n  result->b_s_open = FALSE;\t/* no associated backing-store object */\n  result->next = mem->virt_sarray_list; /* add to list of virtual arrays */\n  mem->virt_sarray_list = result;\n\n  return result;\n}\n\n\nMETHODDEF(jvirt_barray_ptr)\nrequest_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,\n\t\t     JDIMENSION blocksperrow, JDIMENSION numrows,\n\t\t     JDIMENSION maxaccess)\n/* Request a virtual 2-D coefficient-block array */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  jvirt_barray_ptr result;\n\n  /* Only IMAGE-lifetime virtual arrays are currently supported */\n  if (pool_id != JPOOL_IMAGE)\n    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);\t/* safety check */\n\n  /* get control block */\n  result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,\n\t\t\t\t\t  SIZEOF(struct jvirt_barray_control));\n\n  result->mem_buffer = NULL;\t/* marks array not yet realized */\n  result->rows_in_array = numrows;\n  result->blocksperrow = blocksperrow;\n  result->maxaccess = maxaccess;\n  result->pre_zero = pre_zero;\n  result->b_s_open = FALSE;\t/* no associated backing-store object */\n  result->next = mem->virt_barray_list; /* add to list of virtual arrays */\n  mem->virt_barray_list = result;\n\n  return result;\n}\n\n\nMETHODDEF(void)\nrealize_virt_arrays (j_common_ptr cinfo)\n/* Allocate the in-memory buffers for any unrealized virtual arrays */\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  long space_per_minheight, maximum_space, avail_mem;\n  long minheights, max_minheights;\n  jvirt_sarray_ptr sptr;\n  jvirt_barray_ptr bptr;\n\n  /* Compute the minimum space needed (maxaccess rows in each buffer)\n   * and the maximum space needed (full image height in each buffer).\n   * These may be of use to the system-dependent jpeg_mem_available routine.\n   */\n  space_per_minheight = 0;\n  maximum_space = 0;\n  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {\n    if (sptr->mem_buffer == NULL) { /* if not realized yet */\n      space_per_minheight += (long) sptr->maxaccess *\n\t\t\t     (long) sptr->samplesperrow * SIZEOF(JSAMPLE);\n      maximum_space += (long) sptr->rows_in_array *\n\t\t       (long) sptr->samplesperrow * SIZEOF(JSAMPLE);\n    }\n  }\n  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {\n    if (bptr->mem_buffer == NULL) { /* if not realized yet */\n      space_per_minheight += (long) bptr->maxaccess *\n\t\t\t     (long) bptr->blocksperrow * SIZEOF(JBLOCK);\n      maximum_space += (long) bptr->rows_in_array *\n\t\t       (long) bptr->blocksperrow * SIZEOF(JBLOCK);\n    }\n  }\n\n  if (space_per_minheight <= 0)\n    return;\t\t\t/* no unrealized arrays, no work */\n\n  /* Determine amount of memory to actually use; this is system-dependent. */\n  avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,\n\t\t\t\t mem->total_space_allocated);\n\n  /* If the maximum space needed is available, make all the buffers full\n   * height; otherwise parcel it out with the same number of minheights\n   * in each buffer.\n   */\n  if (avail_mem >= maximum_space)\n    max_minheights = 1000000000L;\n  else {\n    max_minheights = avail_mem / space_per_minheight;\n    /* If there doesn't seem to be enough space, try to get the minimum\n     * anyway.  This allows a \"stub\" implementation of jpeg_mem_available().\n     */\n    if (max_minheights <= 0)\n      max_minheights = 1;\n  }\n\n  /* Allocate the in-memory buffers and initialize backing store as needed. */\n\n  for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {\n    if (sptr->mem_buffer == NULL) { /* if not realized yet */\n      minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;\n      if (minheights <= max_minheights) {\n\t/* This buffer fits in memory */\n\tsptr->rows_in_mem = sptr->rows_in_array;\n      } else {\n\t/* It doesn't fit in memory, create backing store. */\n\tsptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);\n\tjpeg_open_backing_store(cinfo, & sptr->b_s_info,\n\t\t\t\t(long) sptr->rows_in_array *\n\t\t\t\t(long) sptr->samplesperrow *\n\t\t\t\t(long) SIZEOF(JSAMPLE));\n\tsptr->b_s_open = TRUE;\n      }\n      sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,\n\t\t\t\t      sptr->samplesperrow, sptr->rows_in_mem);\n      sptr->rowsperchunk = mem->last_rowsperchunk;\n      sptr->cur_start_row = 0;\n      sptr->first_undef_row = 0;\n      sptr->dirty = FALSE;\n    }\n  }\n\n  for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {\n    if (bptr->mem_buffer == NULL) { /* if not realized yet */\n      minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;\n      if (minheights <= max_minheights) {\n\t/* This buffer fits in memory */\n\tbptr->rows_in_mem = bptr->rows_in_array;\n      } else {\n\t/* It doesn't fit in memory, create backing store. */\n\tbptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);\n\tjpeg_open_backing_store(cinfo, & bptr->b_s_info,\n\t\t\t\t(long) bptr->rows_in_array *\n\t\t\t\t(long) bptr->blocksperrow *\n\t\t\t\t(long) SIZEOF(JBLOCK));\n\tbptr->b_s_open = TRUE;\n      }\n      bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,\n\t\t\t\t      bptr->blocksperrow, bptr->rows_in_mem);\n      bptr->rowsperchunk = mem->last_rowsperchunk;\n      bptr->cur_start_row = 0;\n      bptr->first_undef_row = 0;\n      bptr->dirty = FALSE;\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)\n/* Do backing store read or write of a virtual sample array */\n{\n  long bytesperrow, file_offset, byte_count, rows, thisrow, i;\n\n  bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);\n  file_offset = ptr->cur_start_row * bytesperrow;\n  /* Loop to read or write each allocation chunk in mem_buffer */\n  for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {\n    /* One chunk, but check for short chunk at end of buffer */\n    rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);\n    /* Transfer no more than is currently defined */\n    thisrow = (long) ptr->cur_start_row + i;\n    rows = MIN(rows, (long) ptr->first_undef_row - thisrow);\n    /* Transfer no more than fits in file */\n    rows = MIN(rows, (long) ptr->rows_in_array - thisrow);\n    if (rows <= 0)\t\t/* this chunk might be past end of file! */\n      break;\n    byte_count = rows * bytesperrow;\n    if (writing)\n      (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,\n\t\t\t\t\t    (void FAR *) ptr->mem_buffer[i],\n\t\t\t\t\t    file_offset, byte_count);\n    else\n      (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,\n\t\t\t\t\t   (void FAR *) ptr->mem_buffer[i],\n\t\t\t\t\t   file_offset, byte_count);\n    file_offset += byte_count;\n  }\n}\n\n\nLOCAL(void)\ndo_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)\n/* Do backing store read or write of a virtual coefficient-block array */\n{\n  long bytesperrow, file_offset, byte_count, rows, thisrow, i;\n\n  bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);\n  file_offset = ptr->cur_start_row * bytesperrow;\n  /* Loop to read or write each allocation chunk in mem_buffer */\n  for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {\n    /* One chunk, but check for short chunk at end of buffer */\n    rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);\n    /* Transfer no more than is currently defined */\n    thisrow = (long) ptr->cur_start_row + i;\n    rows = MIN(rows, (long) ptr->first_undef_row - thisrow);\n    /* Transfer no more than fits in file */\n    rows = MIN(rows, (long) ptr->rows_in_array - thisrow);\n    if (rows <= 0)\t\t/* this chunk might be past end of file! */\n      break;\n    byte_count = rows * bytesperrow;\n    if (writing)\n      (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,\n\t\t\t\t\t    (void FAR *) ptr->mem_buffer[i],\n\t\t\t\t\t    file_offset, byte_count);\n    else\n      (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,\n\t\t\t\t\t   (void FAR *) ptr->mem_buffer[i],\n\t\t\t\t\t   file_offset, byte_count);\n    file_offset += byte_count;\n  }\n}\n\n\nMETHODDEF(JSAMPARRAY)\naccess_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,\n\t\t    JDIMENSION start_row, JDIMENSION num_rows,\n\t\t    boolean writable)\n/* Access the part of a virtual sample array starting at start_row */\n/* and extending for num_rows rows.  writable is true if  */\n/* caller intends to modify the accessed area. */\n{\n  JDIMENSION end_row = start_row + num_rows;\n  JDIMENSION undef_row;\n\n  /* debugging check */\n  if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||\n      ptr->mem_buffer == NULL)\n    ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n\n  /* Make the desired part of the virtual array accessible */\n  if (start_row < ptr->cur_start_row ||\n      end_row > ptr->cur_start_row+ptr->rows_in_mem) {\n    if (! ptr->b_s_open)\n      ERREXIT(cinfo, JERR_VIRTUAL_BUG);\n    /* Flush old buffer contents if necessary */\n    if (ptr->dirty) {\n      do_sarray_io(cinfo, ptr, TRUE);\n      ptr->dirty = FALSE;\n    }\n    /* Decide what part of virtual array to access.\n     * Algorithm: if target address > current window, assume forward scan,\n     * load starting at target address.  If target address < current window,\n     * assume backward scan, load so that target area is top of window.\n     * Note that when switching from forward write to forward read, will have\n     * start_row = 0, so the limiting case applies and we load from 0 anyway.\n     */\n    if (start_row > ptr->cur_start_row) {\n      ptr->cur_start_row = start_row;\n    } else {\n      /* use long arithmetic here to avoid overflow & unsigned problems */\n      long ltemp;\n\n      ltemp = (long) end_row - (long) ptr->rows_in_mem;\n      if (ltemp < 0)\n\tltemp = 0;\t\t/* don't fall off front end of file */\n      ptr->cur_start_row = (JDIMENSION) ltemp;\n    }\n    /* Read in the selected part of the array.\n     * During the initial write pass, we will do no actual read\n     * because the selected part is all undefined.\n     */\n    do_sarray_io(cinfo, ptr, FALSE);\n  }\n  /* Ensure the accessed part of the array is defined; prezero if needed.\n   * To improve locality of access, we only prezero the part of the array\n   * that the caller is about to access, not the entire in-memory array.\n   */\n  if (ptr->first_undef_row < end_row) {\n    if (ptr->first_undef_row < start_row) {\n      if (writable)\t\t/* writer skipped over a section of array */\n\tERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n      undef_row = start_row;\t/* but reader is allowed to read ahead */\n    } else {\n      undef_row = ptr->first_undef_row;\n    }\n    if (writable)\n      ptr->first_undef_row = end_row;\n    if (ptr->pre_zero) {\n      size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);\n      undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */\n      end_row -= ptr->cur_start_row;\n      while (undef_row < end_row) {\n\tFMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);\n\tundef_row++;\n      }\n    } else {\n      if (! writable)\t\t/* reader looking at undefined data */\n\tERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n    }\n  }\n  /* Flag the buffer dirty if caller will write in it */\n  if (writable)\n    ptr->dirty = TRUE;\n  /* Return address of proper part of the buffer */\n  return ptr->mem_buffer + (start_row - ptr->cur_start_row);\n}\n\n\nMETHODDEF(JBLOCKARRAY)\naccess_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,\n\t\t    JDIMENSION start_row, JDIMENSION num_rows,\n\t\t    boolean writable)\n/* Access the part of a virtual block array starting at start_row */\n/* and extending for num_rows rows.  writable is true if  */\n/* caller intends to modify the accessed area. */\n{\n  JDIMENSION end_row = start_row + num_rows;\n  JDIMENSION undef_row;\n\n  /* debugging check */\n  if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||\n      ptr->mem_buffer == NULL)\n    ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n\n  /* Make the desired part of the virtual array accessible */\n  if (start_row < ptr->cur_start_row ||\n      end_row > ptr->cur_start_row+ptr->rows_in_mem) {\n    if (! ptr->b_s_open)\n      ERREXIT(cinfo, JERR_VIRTUAL_BUG);\n    /* Flush old buffer contents if necessary */\n    if (ptr->dirty) {\n      do_barray_io(cinfo, ptr, TRUE);\n      ptr->dirty = FALSE;\n    }\n    /* Decide what part of virtual array to access.\n     * Algorithm: if target address > current window, assume forward scan,\n     * load starting at target address.  If target address < current window,\n     * assume backward scan, load so that target area is top of window.\n     * Note that when switching from forward write to forward read, will have\n     * start_row = 0, so the limiting case applies and we load from 0 anyway.\n     */\n    if (start_row > ptr->cur_start_row) {\n      ptr->cur_start_row = start_row;\n    } else {\n      /* use long arithmetic here to avoid overflow & unsigned problems */\n      long ltemp;\n\n      ltemp = (long) end_row - (long) ptr->rows_in_mem;\n      if (ltemp < 0)\n\tltemp = 0;\t\t/* don't fall off front end of file */\n      ptr->cur_start_row = (JDIMENSION) ltemp;\n    }\n    /* Read in the selected part of the array.\n     * During the initial write pass, we will do no actual read\n     * because the selected part is all undefined.\n     */\n    do_barray_io(cinfo, ptr, FALSE);\n  }\n  /* Ensure the accessed part of the array is defined; prezero if needed.\n   * To improve locality of access, we only prezero the part of the array\n   * that the caller is about to access, not the entire in-memory array.\n   */\n  if (ptr->first_undef_row < end_row) {\n    if (ptr->first_undef_row < start_row) {\n      if (writable)\t\t/* writer skipped over a section of array */\n\tERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n      undef_row = start_row;\t/* but reader is allowed to read ahead */\n    } else {\n      undef_row = ptr->first_undef_row;\n    }\n    if (writable)\n      ptr->first_undef_row = end_row;\n    if (ptr->pre_zero) {\n      size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);\n      undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */\n      end_row -= ptr->cur_start_row;\n      while (undef_row < end_row) {\n\tFMEMZERO((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);\n\tundef_row++;\n      }\n    } else {\n      if (! writable)\t\t/* reader looking at undefined data */\n\tERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);\n    }\n  }\n  /* Flag the buffer dirty if caller will write in it */\n  if (writable)\n    ptr->dirty = TRUE;\n  /* Return address of proper part of the buffer */\n  return ptr->mem_buffer + (start_row - ptr->cur_start_row);\n}\n\n\n/*\n * Release all objects belonging to a specified pool.\n */\n\nMETHODDEF(void)\nfree_pool (j_common_ptr cinfo, int pool_id)\n{\n  my_mem_ptr mem = (my_mem_ptr) cinfo->mem;\n  small_pool_ptr shdr_ptr;\n  large_pool_ptr lhdr_ptr;\n  size_t space_freed;\n\n  if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)\n    ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id);\t/* safety check */\n\n#ifdef MEM_STATS\n  if (cinfo->err->trace_level > 1)\n    print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */\n#endif\n\n  /* If freeing IMAGE pool, close any virtual arrays first */\n  if (pool_id == JPOOL_IMAGE) {\n    jvirt_sarray_ptr sptr;\n    jvirt_barray_ptr bptr;\n\n    for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {\n      if (sptr->b_s_open) {\t/* there may be no backing store */\n\tsptr->b_s_open = FALSE;\t/* prevent recursive close if error */\n\t(*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);\n      }\n    }\n    mem->virt_sarray_list = NULL;\n    for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {\n      if (bptr->b_s_open) {\t/* there may be no backing store */\n\tbptr->b_s_open = FALSE;\t/* prevent recursive close if error */\n\t(*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);\n      }\n    }\n    mem->virt_barray_list = NULL;\n  }\n\n  /* Release large objects */\n  lhdr_ptr = mem->large_list[pool_id];\n  mem->large_list[pool_id] = NULL;\n\n  while (lhdr_ptr != NULL) {\n    large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;\n    space_freed = lhdr_ptr->hdr.bytes_used +\n\t\t  lhdr_ptr->hdr.bytes_left +\n\t\t  SIZEOF(large_pool_hdr);\n    jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);\n    mem->total_space_allocated -= space_freed;\n    lhdr_ptr = next_lhdr_ptr;\n  }\n\n  /* Release small objects */\n  shdr_ptr = mem->small_list[pool_id];\n  mem->small_list[pool_id] = NULL;\n\n  while (shdr_ptr != NULL) {\n    small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;\n    space_freed = shdr_ptr->hdr.bytes_used +\n\t\t  shdr_ptr->hdr.bytes_left +\n\t\t  SIZEOF(small_pool_hdr);\n    jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);\n    mem->total_space_allocated -= space_freed;\n    shdr_ptr = next_shdr_ptr;\n  }\n}\n\n\n/*\n * Close up shop entirely.\n * Note that this cannot be called unless cinfo->mem is non-NULL.\n */\n\nMETHODDEF(void)\nself_destruct (j_common_ptr cinfo)\n{\n  int pool;\n\n  /* Close all backing store, release all memory.\n   * Releasing pools in reverse order might help avoid fragmentation\n   * with some (brain-damaged) malloc libraries.\n   */\n  for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {\n    free_pool(cinfo, pool);\n  }\n\n  /* Release the memory manager control block too. */\n  jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));\n  cinfo->mem = NULL;\t\t/* ensures I will be called only once */\n\n  jpeg_mem_term(cinfo);\t\t/* system-dependent cleanup */\n}\n\n\n/*\n * Memory manager initialization.\n * When this is called, only the error manager pointer is valid in cinfo!\n */\n\nGLOBAL(void)\njinit_memory_mgr (j_common_ptr cinfo)\n{\n  my_mem_ptr mem;\n  long max_to_use;\n  int pool;\n  size_t test_mac;\n\n  cinfo->mem = NULL;\t\t/* for safety if init fails */\n\n  /* Check for configuration errors.\n   * SIZEOF(ALIGN_TYPE) should be a power of 2; otherwise, it probably\n   * doesn't reflect any real hardware alignment requirement.\n   * The test is a little tricky: for X>0, X and X-1 have no one-bits\n   * in common if and only if X is a power of 2, ie has only one one-bit.\n   * Some compilers may give an \"unreachable code\" warning here; ignore it.\n   */\n  if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)\n    ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);\n  /* MAX_ALLOC_CHUNK must be representable as type size_t, and must be\n   * a multiple of SIZEOF(ALIGN_TYPE).\n   * Again, an \"unreachable code\" warning may be ignored here.\n   * But a \"constant too large\" warning means you need to fix MAX_ALLOC_CHUNK.\n   */\n  test_mac = (size_t) MAX_ALLOC_CHUNK;\n  if ((long) test_mac != MAX_ALLOC_CHUNK ||\n      (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)\n    ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);\n\n  max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */\n\n  /* Attempt to allocate memory manager's control block */\n  mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));\n\n  if (mem == NULL) {\n    jpeg_mem_term(cinfo);\t/* system-dependent cleanup */\n    ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);\n  }\n\n  /* OK, fill in the method pointers */\n  mem->pub.alloc_small = alloc_small;\n  mem->pub.alloc_large = alloc_large;\n  mem->pub.alloc_sarray = alloc_sarray;\n  mem->pub.alloc_barray = alloc_barray;\n  mem->pub.request_virt_sarray = request_virt_sarray;\n  mem->pub.request_virt_barray = request_virt_barray;\n  mem->pub.realize_virt_arrays = realize_virt_arrays;\n  mem->pub.access_virt_sarray = access_virt_sarray;\n  mem->pub.access_virt_barray = access_virt_barray;\n  mem->pub.free_pool = free_pool;\n  mem->pub.self_destruct = self_destruct;\n\n  /* Make MAX_ALLOC_CHUNK accessible to other modules */\n  mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;\n\n  /* Initialize working state */\n  mem->pub.max_memory_to_use = max_to_use;\n\n  for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {\n    mem->small_list[pool] = NULL;\n    mem->large_list[pool] = NULL;\n  }\n  mem->virt_sarray_list = NULL;\n  mem->virt_barray_list = NULL;\n\n  mem->total_space_allocated = SIZEOF(my_memory_mgr);\n\n  /* Declare ourselves open for business */\n  cinfo->mem = & mem->pub;\n\n  /* Check for an environment variable JPEGMEM; if found, override the\n   * default max_memory setting from jpeg_mem_init.  Note that the\n   * surrounding application may again override this value.\n   * If your system doesn't support getenv(), define NO_GETENV to disable\n   * this feature.\n   */\n#ifndef NO_GETENV\n  { char * memenv;\n\n    if ((memenv = getenv(\"JPEGMEM\")) != NULL) {\n      char ch = 'x';\n\n      if (sscanf(memenv, \"%ld%c\", &max_to_use, &ch) > 0) {\n\tif (ch == 'm' || ch == 'M')\n\t  max_to_use *= 1000L;\n\tmem->pub.max_memory_to_use = max_to_use * 1000L;\n      }\n    }\n  }\n#endif\n\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemname.c",
    "content": "/*\n * jmemname.c\n *\n * Copyright (C) 1992-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file provides a generic implementation of the system-dependent\n * portion of the JPEG memory manager.  This implementation assumes that\n * you must explicitly construct a name for each temp file.\n * Also, the problem of determining the amount of memory available\n * is shoved onto the user.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"\t\t/* import the system-dependent declarations */\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare malloc(),free() */\nextern void * malloc JPP((size_t size));\nextern void free JPP((void *ptr));\n#endif\n\n#ifndef SEEK_SET\t\t/* pre-ANSI systems may not define this; */\n#define SEEK_SET  0\t\t/* if not, assume 0 is correct */\n#endif\n\n#ifdef DONT_USE_B_MODE\t\t/* define mode parameters for fopen() */\n#define READ_BINARY\t\"r\"\n#define RW_BINARY\t\"w+\"\n#else\n#ifdef VMS\t\t\t/* VMS is very nonstandard */\n#define READ_BINARY\t\"rb\", \"ctx=stm\"\n#define RW_BINARY\t\"w+b\", \"ctx=stm\"\n#else\t\t\t\t/* standard ANSI-compliant case */\n#define READ_BINARY\t\"rb\"\n#define RW_BINARY\t\"w+b\"\n#endif\n#endif\n\n\n/*\n * Selection of a file name for a temporary file.\n * This is system-dependent!\n *\n * The code as given is suitable for most Unix systems, and it is easily\n * modified for most non-Unix systems.  Some notes:\n *  1.  The temp file is created in the directory named by TEMP_DIRECTORY.\n *      The default value is /usr/tmp, which is the conventional place for\n *      creating large temp files on Unix.  On other systems you'll probably\n *      want to change the file location.  You can do this by editing the\n *      #define, or (preferred) by defining TEMP_DIRECTORY in jconfig.h.\n *\n *  2.  If you need to change the file name as well as its location,\n *      you can override the TEMP_FILE_NAME macro.  (Note that this is\n *      actually a printf format string; it must contain %s and %d.)\n *      Few people should need to do this.\n *\n *  3.  mktemp() is used to ensure that multiple processes running\n *      simultaneously won't select the same file names.  If your system\n *      doesn't have mktemp(), define NO_MKTEMP to do it the hard way.\n *      (If you don't have <errno.h>, also define NO_ERRNO_H.)\n *\n *  4.  You probably want to define NEED_SIGNAL_CATCHER so that cjpeg.c/djpeg.c\n *      will cause the temp files to be removed if you stop the program early.\n */\n\n#ifndef TEMP_DIRECTORY\t\t/* can override from jconfig.h or Makefile */\n#define TEMP_DIRECTORY  \"/usr/tmp/\" /* recommended setting for Unix */\n#endif\n\nstatic int next_file_num;\t/* to distinguish among several temp files */\n\n#ifdef NO_MKTEMP\n\n#ifndef TEMP_FILE_NAME\t\t/* can override from jconfig.h or Makefile */\n#define TEMP_FILE_NAME  \"%sJPG%03d.TMP\"\n#endif\n\n#ifndef NO_ERRNO_H\n#include <errno.h>\t\t/* to define ENOENT */\n#endif\n\n/* ANSI C specifies that errno is a macro, but on older systems it's more\n * likely to be a plain int variable.  And not all versions of errno.h\n * bother to declare it, so we have to in order to be most portable.  Thus:\n */\n#ifndef errno\nextern int errno;\n#endif\n\n\nLOCAL(void)\nselect_file_name (char * fname)\n{\n  FILE * tfile;\n\n  /* Keep generating file names till we find one that's not in use */\n  for (;;) {\n    next_file_num++;\t\t/* advance counter */\n    sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);\n    if ((tfile = fopen(fname, READ_BINARY)) == NULL) {\n      /* fopen could have failed for a reason other than the file not\n       * being there; for example, file there but unreadable.\n       * If <errno.h> isn't available, then we cannot test the cause.\n       */\n#ifdef ENOENT\n      if (errno != ENOENT)\n\tcontinue;\n#endif\n      break;\n    }\n    fclose(tfile);\t\t/* oops, it's there; close tfile & try again */\n  }\n}\n\n#else /* ! NO_MKTEMP */\n\n/* Note that mktemp() requires the initial filename to end in six X's */\n#ifndef TEMP_FILE_NAME\t\t/* can override from jconfig.h or Makefile */\n#define TEMP_FILE_NAME  \"%sJPG%dXXXXXX\"\n#endif\n\nLOCAL(void)\nselect_file_name (char * fname)\n{\n  next_file_num++;\t\t/* advance counter */\n  sprintf(fname, TEMP_FILE_NAME, TEMP_DIRECTORY, next_file_num);\n  mktemp(fname);\t\t/* make sure file name is unique */\n  /* mktemp replaces the trailing XXXXXX with a unique string of characters */\n}\n\n#endif /* NO_MKTEMP */\n\n\n/*\n * Memory allocation and freeing are controlled by the regular library\n * routines malloc() and free().\n */\n\nGLOBAL(void *)\njpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * \"Large\" objects are treated the same as \"small\" ones.\n * NB: although we include FAR keywords in the routine declarations,\n * this file won't actually work in 80x86 small/medium model; at least,\n * you probably won't be able to process useful-size images in only 64KB.\n */\n\nGLOBAL(void FAR *)\njpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void FAR *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * This routine computes the total memory space available for allocation.\n * It's impossible to do this in a portable way; our current solution is\n * to make the user tell us (with a default value set at compile time).\n * If you can actually get the available space, it's a good idea to subtract\n * a slop factor of 5% or so.\n */\n\n#ifndef DEFAULT_MAX_MEM\t\t/* so can override from makefile */\n#define DEFAULT_MAX_MEM\t\t1000000L /* default: one megabyte */\n#endif\n\nGLOBAL(long)\njpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,\n\t\t    long max_bytes_needed, long already_allocated)\n{\n  return cinfo->mem->max_memory_to_use - already_allocated;\n}\n\n\n/*\n * Backing store (temporary file) management.\n * Backing store objects are only used when the value returned by\n * jpeg_mem_available is less than the total space needed.  You can dispense\n * with these routines if you have plenty of virtual memory; see jmemnobs.c.\n */\n\n\nMETHODDEF(void)\nread_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t    void FAR * buffer_address,\n\t\t    long file_offset, long byte_count)\n{\n  if (fseek(info->temp_file, file_offset, SEEK_SET))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  if (JFREAD(info->temp_file, buffer_address, byte_count)\n      != (size_t) byte_count)\n    ERREXIT(cinfo, JERR_TFILE_READ);\n}\n\n\nMETHODDEF(void)\nwrite_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t     void FAR * buffer_address,\n\t\t     long file_offset, long byte_count)\n{\n  if (fseek(info->temp_file, file_offset, SEEK_SET))\n    ERREXIT(cinfo, JERR_TFILE_SEEK);\n  if (JFWRITE(info->temp_file, buffer_address, byte_count)\n      != (size_t) byte_count)\n    ERREXIT(cinfo, JERR_TFILE_WRITE);\n}\n\n\nMETHODDEF(void)\nclose_backing_store (j_common_ptr cinfo, backing_store_ptr info)\n{\n  fclose(info->temp_file);\t/* close the file */\n  unlink(info->temp_name);\t/* delete the file */\n/* If your system doesn't have unlink(), use remove() instead.\n * remove() is the ANSI-standard name for this function, but if\n * your system was ANSI you'd be using jmemansi.c, right?\n */\n  TRACEMSS(cinfo, 1, JTRC_TFILE_CLOSE, info->temp_name);\n}\n\n\n/*\n * Initial opening of a backing-store object.\n */\n\nGLOBAL(void)\njpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t\t long total_bytes_needed)\n{\n  select_file_name(info->temp_name);\n  if ((info->temp_file = fopen(info->temp_name, RW_BINARY)) == NULL)\n    ERREXITS(cinfo, JERR_TFILE_CREATE, info->temp_name);\n  info->read_backing_store = read_backing_store;\n  info->write_backing_store = write_backing_store;\n  info->close_backing_store = close_backing_store;\n  TRACEMSS(cinfo, 1, JTRC_TFILE_OPEN, info->temp_name);\n}\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.\n */\n\nGLOBAL(long)\njpeg_mem_init (j_common_ptr cinfo)\n{\n  next_file_num = 0;\t\t/* initialize temp file name generator */\n  return DEFAULT_MAX_MEM;\t/* default for max_memory_to_use */\n}\n\nGLOBAL(void)\njpeg_mem_term (j_common_ptr cinfo)\n{\n  /* no work */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemnobs.c",
    "content": "/*\n * jmemnobs.c\n *\n * Copyright (C) 1992-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file provides a really simple implementation of the system-\n * dependent portion of the JPEG memory manager.  This implementation\n * assumes that no backing-store files are needed: all required space\n * can be obtained from malloc().\n * This is very portable in the sense that it'll compile on almost anything,\n * but you'd better have lots of main memory (or virtual memory) if you want\n * to process big images.\n * Note that the max_memory_to_use option is ignored by this implementation.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"jmemsys.h\"\t\t/* import the system-dependent declarations */\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare malloc(),free() */\nextern void * malloc JPP((size_t size));\nextern void free JPP((void *ptr));\n#endif\n\n\n/*\n * Memory allocation and freeing are controlled by the regular library\n * routines malloc() and free().\n */\n\nGLOBAL(void *)\njpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * \"Large\" objects are treated the same as \"small\" ones.\n * NB: although we include FAR keywords in the routine declarations,\n * this file won't actually work in 80x86 small/medium model; at least,\n * you probably won't be able to process useful-size images in only 64KB.\n */\n\nGLOBAL(void FAR *)\njpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)\n{\n  return (void FAR *) malloc(sizeofobject);\n}\n\nGLOBAL(void)\njpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)\n{\n  free(object);\n}\n\n\n/*\n * This routine computes the total memory space available for allocation.\n * Here we always say, \"we got all you want bud!\"\n */\n\nGLOBAL(long)\njpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,\n\t\t    long max_bytes_needed, long already_allocated)\n{\n  return max_bytes_needed;\n}\n\n\n/*\n * Backing store (temporary file) management.\n * Since jpeg_mem_available always promised the moon,\n * this should never be called and we can just error out.\n */\n\nGLOBAL(void)\njpeg_open_backing_store (j_common_ptr cinfo, backing_store_ptr info,\n\t\t\t long total_bytes_needed)\n{\n  ERREXIT(cinfo, JERR_NO_BACKING_STORE);\n}\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.  Here, there isn't any.\n */\n\nGLOBAL(long)\njpeg_mem_init (j_common_ptr cinfo)\n{\n  return 0;\t\t\t/* just set max_memory_to_use to 0 */\n}\n\nGLOBAL(void)\njpeg_mem_term (j_common_ptr cinfo)\n{\n  /* no work */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmemsys.h",
    "content": "/*\n * jmemsys.h\n *\n * Copyright (C) 1992-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This include file defines the interface between the system-independent\n * and system-dependent portions of the JPEG memory manager.  No other\n * modules need include it.  (The system-independent portion is jmemmgr.c;\n * there are several different versions of the system-dependent portion.)\n *\n * This file works as-is for the system-dependent memory managers supplied\n * in the IJG distribution.  You may need to modify it if you write a\n * custom memory manager.  If system-dependent changes are needed in\n * this file, the best method is to #ifdef them based on a configuration\n * symbol supplied in jconfig.h, as we have done with USE_MSDOS_MEMMGR\n * and USE_MAC_MEMMGR.\n */\n\n\n/* Short forms of external names for systems with brain-damaged linkers. */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jpeg_get_small\t\tjGetSmall\n#define jpeg_free_small\t\tjFreeSmall\n#define jpeg_get_large\t\tjGetLarge\n#define jpeg_free_large\t\tjFreeLarge\n#define jpeg_mem_available\tjMemAvail\n#define jpeg_open_backing_store\tjOpenBackStore\n#define jpeg_mem_init\t\tjMemInit\n#define jpeg_mem_term\t\tjMemTerm\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n\n/*\n * These two functions are used to allocate and release small chunks of\n * memory.  (Typically the total amount requested through jpeg_get_small is\n * no more than 20K or so; this will be requested in chunks of a few K each.)\n * Behavior should be the same as for the standard library functions malloc\n * and free; in particular, jpeg_get_small must return NULL on failure.\n * On most systems, these ARE malloc and free.  jpeg_free_small is passed the\n * size of the object being freed, just in case it's needed.\n * On an 80x86 machine using small-data memory model, these manage near heap.\n */\n\nEXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));\nEXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,\n\t\t\t\t  size_t sizeofobject));\n\n/*\n * These two functions are used to allocate and release large chunks of\n * memory (up to the total free space designated by jpeg_mem_available).\n * The interface is the same as above, except that on an 80x86 machine,\n * far pointers are used.  On most other machines these are identical to\n * the jpeg_get/free_small routines; but we keep them separate anyway,\n * in case a different allocation strategy is desirable for large chunks.\n */\n\nEXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,\n\t\t\t\t       size_t sizeofobject));\nEXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,\n\t\t\t\t  size_t sizeofobject));\n\n/*\n * The macro MAX_ALLOC_CHUNK designates the maximum number of bytes that may\n * be requested in a single call to jpeg_get_large (and jpeg_get_small for that\n * matter, but that case should never come into play).  This macro is needed\n * to model the 64Kb-segment-size limit of far addressing on 80x86 machines.\n * On those machines, we expect that jconfig.h will provide a proper value.\n * On machines with 32-bit flat address spaces, any large constant may be used.\n *\n * NB: jmemmgr.c expects that MAX_ALLOC_CHUNK will be representable as type\n * size_t and will be a multiple of sizeof(align_type).\n */\n\n#ifndef MAX_ALLOC_CHUNK\t\t/* may be overridden in jconfig.h */\n#define MAX_ALLOC_CHUNK  1000000000L\n#endif\n\n/*\n * This routine computes the total space still available for allocation by\n * jpeg_get_large.  If more space than this is needed, backing store will be\n * used.  NOTE: any memory already allocated must not be counted.\n *\n * There is a minimum space requirement, corresponding to the minimum\n * feasible buffer sizes; jmemmgr.c will request that much space even if\n * jpeg_mem_available returns zero.  The maximum space needed, enough to hold\n * all working storage in memory, is also passed in case it is useful.\n * Finally, the total space already allocated is passed.  If no better\n * method is available, cinfo->mem->max_memory_to_use - already_allocated\n * is often a suitable calculation.\n *\n * It is OK for jpeg_mem_available to underestimate the space available\n * (that'll just lead to more backing-store access than is really necessary).\n * However, an overestimate will lead to failure.  Hence it's wise to subtract\n * a slop factor from the true available space.  5% should be enough.\n *\n * On machines with lots of virtual memory, any large constant may be returned.\n * Conversely, zero may be returned to always use the minimum amount of memory.\n */\n\nEXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,\n\t\t\t\t     long min_bytes_needed,\n\t\t\t\t     long max_bytes_needed,\n\t\t\t\t     long already_allocated));\n\n\n/*\n * This structure holds whatever state is needed to access a single\n * backing-store object.  The read/write/close method pointers are called\n * by jmemmgr.c to manipulate the backing-store object; all other fields\n * are private to the system-dependent backing store routines.\n */\n\n#define TEMP_NAME_LENGTH   64\t/* max length of a temporary file's name */\n\n\n#ifdef USE_MSDOS_MEMMGR\t\t/* DOS-specific junk */\n\ntypedef unsigned short XMSH;\t/* type of extended-memory handles */\ntypedef unsigned short EMSH;\t/* type of expanded-memory handles */\n\ntypedef union {\n  short file_handle;\t\t/* DOS file handle if it's a temp file */\n  XMSH xms_handle;\t\t/* handle if it's a chunk of XMS */\n  EMSH ems_handle;\t\t/* handle if it's a chunk of EMS */\n} handle_union;\n\n#endif /* USE_MSDOS_MEMMGR */\n\n#ifdef USE_MAC_MEMMGR\t\t/* Mac-specific junk */\n#include <Files.h>\n#endif /* USE_MAC_MEMMGR */\n\n\ntypedef struct backing_store_struct * backing_store_ptr;\n\ntypedef struct backing_store_struct {\n  /* Methods for reading/writing/closing this backing-store object */\n  JMETHOD(void, read_backing_store, (j_common_ptr cinfo,\n\t\t\t\t     backing_store_ptr info,\n\t\t\t\t     void FAR * buffer_address,\n\t\t\t\t     long file_offset, long byte_count));\n  JMETHOD(void, write_backing_store, (j_common_ptr cinfo,\n\t\t\t\t      backing_store_ptr info,\n\t\t\t\t      void FAR * buffer_address,\n\t\t\t\t      long file_offset, long byte_count));\n  JMETHOD(void, close_backing_store, (j_common_ptr cinfo,\n\t\t\t\t      backing_store_ptr info));\n\n  /* Private fields for system-dependent backing-store management */\n#ifdef USE_MSDOS_MEMMGR\n  /* For the MS-DOS manager (jmemdos.c), we need: */\n  handle_union handle;\t\t/* reference to backing-store storage object */\n  char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */\n#else\n#ifdef USE_MAC_MEMMGR\n  /* For the Mac manager (jmemmac.c), we need: */\n  short temp_file;\t\t/* file reference number to temp file */\n  FSSpec tempSpec;\t\t/* the FSSpec for the temp file */\n  char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */\n#else\n  /* For a typical implementation with temp files, we need: */\n  FILE * temp_file;\t\t/* stdio reference to temp file */\n  char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */\n#endif\n#endif\n} backing_store_info;\n\n\n/*\n * Initial opening of a backing-store object.  This must fill in the\n * read/write/close pointers in the object.  The read/write routines\n * may take an error exit if the specified maximum file size is exceeded.\n * (If jpeg_mem_available always returns a large value, this routine can\n * just take an error exit.)\n */\n\nEXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,\n\t\t\t\t\t  backing_store_ptr info,\n\t\t\t\t\t  long total_bytes_needed));\n\n\n/*\n * These routines take care of any system-dependent initialization and\n * cleanup required.  jpeg_mem_init will be called before anything is\n * allocated (and, therefore, nothing in cinfo is of use except the error\n * manager pointer).  It should return a suitable default value for\n * max_memory_to_use; this may subsequently be overridden by the surrounding\n * application.  (Note that max_memory_to_use is only important if\n * jpeg_mem_available chooses to consult it ... no one else will.)\n * jpeg_mem_term may assume that all requested memory has been freed and that\n * all opened backing-store objects have been closed.\n */\n\nEXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));\nEXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jmorecfg.h",
    "content": "/*\n * jmorecfg.h\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 1997-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains additional configuration options that customize the\n * JPEG software for special applications or support machine-dependent\n * optimizations.  Most users will not need to touch this file.\n */\n\n\n/*\n * Define BITS_IN_JSAMPLE as either\n *   8   for 8-bit sample values (the usual setting)\n *   9   for 9-bit sample values\n *   10  for 10-bit sample values\n *   11  for 11-bit sample values\n *   12  for 12-bit sample values\n * Only 8, 9, 10, 11, and 12 bits sample data precision are supported for\n * full-feature DCT processing.  Further depths up to 16-bit may be added\n * later for the lossless modes of operation.\n * Run-time selection and conversion of data precision will be added later\n * and are currently not supported, sorry.\n * Exception:  The transcoding part (jpegtran) supports all settings in a\n * single instance, since it operates on the level of DCT coefficients and\n * not sample values.  The DCT coefficients are of the same type (16 bits)\n * in all cases (see below).\n */\n\n#define BITS_IN_JSAMPLE  8\t/* use 8, 9, 10, 11, or 12 */\n\n\n/*\n * Maximum number of components (color channels) allowed in JPEG image.\n * To meet the letter of the JPEG spec, set this to 255.  However, darn\n * few applications need more than 4 channels (maybe 5 for CMYK + alpha\n * mask).  We recommend 10 as a reasonable compromise; use 4 if you are\n * really short on memory.  (Each allowed component costs a hundred or so\n * bytes of storage, whether actually used in an image or not.)\n */\n\n#define MAX_COMPONENTS  10\t/* maximum number of image components */\n\n\n/*\n * Basic data types.\n * You may need to change these if you have a machine with unusual data\n * type sizes; for example, \"char\" not 8 bits, \"short\" not 16 bits,\n * or \"long\" not 32 bits.  We don't care whether \"int\" is 16 or 32 bits,\n * but it had better be at least 16.\n */\n\n/* Representation of a single sample (pixel element value).\n * We frequently allocate large arrays of these, so it's important to keep\n * them small.  But if you have memory to burn and access to char or short\n * arrays is very slow on your hardware, you might want to change these.\n */\n\n#if BITS_IN_JSAMPLE == 8\n/* JSAMPLE should be the smallest type that will hold the values 0..255.\n * You can use a signed char by having GETJSAMPLE mask it with 0xFF.\n */\n\n#ifdef HAVE_UNSIGNED_CHAR\n\ntypedef unsigned char JSAMPLE;\n#define GETJSAMPLE(value)  ((int) (value))\n\n#else /* not HAVE_UNSIGNED_CHAR */\n\ntypedef char JSAMPLE;\n#ifdef CHAR_IS_UNSIGNED\n#define GETJSAMPLE(value)  ((int) (value))\n#else\n#define GETJSAMPLE(value)  ((int) (value) & 0xFF)\n#endif /* CHAR_IS_UNSIGNED */\n\n#endif /* HAVE_UNSIGNED_CHAR */\n\n#define MAXJSAMPLE\t255\n#define CENTERJSAMPLE\t128\n\n#endif /* BITS_IN_JSAMPLE == 8 */\n\n\n#if BITS_IN_JSAMPLE == 9\n/* JSAMPLE should be the smallest type that will hold the values 0..511.\n * On nearly all machines \"short\" will do nicely.\n */\n\ntypedef short JSAMPLE;\n#define GETJSAMPLE(value)  ((int) (value))\n\n#define MAXJSAMPLE\t511\n#define CENTERJSAMPLE\t256\n\n#endif /* BITS_IN_JSAMPLE == 9 */\n\n\n#if BITS_IN_JSAMPLE == 10\n/* JSAMPLE should be the smallest type that will hold the values 0..1023.\n * On nearly all machines \"short\" will do nicely.\n */\n\ntypedef short JSAMPLE;\n#define GETJSAMPLE(value)  ((int) (value))\n\n#define MAXJSAMPLE\t1023\n#define CENTERJSAMPLE\t512\n\n#endif /* BITS_IN_JSAMPLE == 10 */\n\n\n#if BITS_IN_JSAMPLE == 11\n/* JSAMPLE should be the smallest type that will hold the values 0..2047.\n * On nearly all machines \"short\" will do nicely.\n */\n\ntypedef short JSAMPLE;\n#define GETJSAMPLE(value)  ((int) (value))\n\n#define MAXJSAMPLE\t2047\n#define CENTERJSAMPLE\t1024\n\n#endif /* BITS_IN_JSAMPLE == 11 */\n\n\n#if BITS_IN_JSAMPLE == 12\n/* JSAMPLE should be the smallest type that will hold the values 0..4095.\n * On nearly all machines \"short\" will do nicely.\n */\n\ntypedef short JSAMPLE;\n#define GETJSAMPLE(value)  ((int) (value))\n\n#define MAXJSAMPLE\t4095\n#define CENTERJSAMPLE\t2048\n\n#endif /* BITS_IN_JSAMPLE == 12 */\n\n\n/* Representation of a DCT frequency coefficient.\n * This should be a signed value of at least 16 bits; \"short\" is usually OK.\n * Again, we allocate large arrays of these, but you can change to int\n * if you have memory to burn and \"short\" is really slow.\n */\n\ntypedef short JCOEF;\n\n\n/* Compressed datastreams are represented as arrays of JOCTET.\n * These must be EXACTLY 8 bits wide, at least once they are written to\n * external storage.  Note that when using the stdio data source/destination\n * managers, this is also the data type passed to fread/fwrite.\n */\n\n#ifdef HAVE_UNSIGNED_CHAR\n\ntypedef unsigned char JOCTET;\n#define GETJOCTET(value)  (value)\n\n#else /* not HAVE_UNSIGNED_CHAR */\n\ntypedef char JOCTET;\n#ifdef CHAR_IS_UNSIGNED\n#define GETJOCTET(value)  (value)\n#else\n#define GETJOCTET(value)  ((value) & 0xFF)\n#endif /* CHAR_IS_UNSIGNED */\n\n#endif /* HAVE_UNSIGNED_CHAR */\n\n\n/* These typedefs are used for various table entries and so forth.\n * They must be at least as wide as specified; but making them too big\n * won't cost a huge amount of memory, so we don't provide special\n * extraction code like we did for JSAMPLE.  (In other words, these\n * typedefs live at a different point on the speed/space tradeoff curve.)\n */\n\n/* UINT8 must hold at least the values 0..255. */\n\n#ifdef HAVE_UNSIGNED_CHAR\ntypedef unsigned char UINT8;\n#else /* not HAVE_UNSIGNED_CHAR */\n#ifdef CHAR_IS_UNSIGNED\ntypedef char UINT8;\n#else /* not CHAR_IS_UNSIGNED */\ntypedef short UINT8;\n#endif /* CHAR_IS_UNSIGNED */\n#endif /* HAVE_UNSIGNED_CHAR */\n\n/* UINT16 must hold at least the values 0..65535. */\n\n#ifdef HAVE_UNSIGNED_SHORT\ntypedef unsigned short UINT16;\n#else /* not HAVE_UNSIGNED_SHORT */\ntypedef unsigned int UINT16;\n#endif /* HAVE_UNSIGNED_SHORT */\n\n/* INT16 must hold at least the values -32768..32767. */\n\n#ifndef XMD_H\t\t\t/* X11/xmd.h correctly defines INT16 */\ntypedef short INT16;\n#endif\n\n/* INT32 must hold at least signed 32-bit values. */\n\n#ifndef XMD_H\t\t\t/* X11/xmd.h correctly defines INT32 */\n#ifndef _BASETSD_H_\t\t/* Microsoft defines it in basetsd.h */\n#ifndef _BASETSD_H\t\t/* MinGW is slightly different */\n#ifndef QGLOBAL_H\t\t/* Qt defines it in qglobal.h */\ntypedef long INT32;\n#endif\n#endif\n#endif\n#endif\n\n/* Datatype used for image dimensions.  The JPEG standard only supports\n * images up to 64K*64K due to 16-bit fields in SOF markers.  Therefore\n * \"unsigned int\" is sufficient on all machines.  However, if you need to\n * handle larger images and you don't mind deviating from the spec, you\n * can change this datatype.\n */\n\ntypedef unsigned int JDIMENSION;\n\n#define JPEG_MAX_DIMENSION  65500L  /* a tad under 64K to prevent overflows */\n\n\n/* These macros are used in all function definitions and extern declarations.\n * You could modify them if you need to change function linkage conventions;\n * in particular, you'll need to do that to make the library a Windows DLL.\n * Another application is to make all functions global for use with debuggers\n * or code profilers that require it.\n */\n\n/* a function called through method pointers: */\n#define METHODDEF(type)\t\tstatic type\n/* a function used only in its module: */\n#define LOCAL(type)\t\tstatic type\n/* a function referenced thru EXTERNs: */\n#define GLOBAL(type)\t\ttype\n/* a reference to a GLOBAL function: */\n#define EXTERN(type)\t\textern type\n\n\n/* This macro is used to declare a \"method\", that is, a function pointer.\n * We want to supply prototype parameters if the compiler can cope.\n * Note that the arglist parameter must be parenthesized!\n * Again, you can customize this if you need special linkage keywords.\n */\n\n#ifdef HAVE_PROTOTYPES\n#define JMETHOD(type,methodname,arglist)  type (*methodname) arglist\n#else\n#define JMETHOD(type,methodname,arglist)  type (*methodname) ()\n#endif\n\n\n/* The noreturn type identifier is used to declare functions\n * which cannot return.\n * Compilers can thus create more optimized code and perform\n * better checks for warnings and errors.\n * Static analyzer tools can make improved inferences about\n * execution paths and are prevented from giving false alerts.\n *\n * Unfortunately, the proposed specifications of corresponding\n * extensions in the Dec 2011 ISO C standard revision (C11),\n * GCC, MSVC, etc. are not viable.\n * Thus we introduce a user defined type to declare noreturn\n * functions at least for clarity.  A proper compiler would\n * have a suitable noreturn type to match in place of void.\n */\n\n#ifndef HAVE_NORETURN_T\ntypedef void noreturn_t;\n#endif\n\n\n/* Here is the pseudo-keyword for declaring pointers that must be \"far\"\n * on 80x86 machines.  Most of the specialized coding for 80x86 is handled\n * by just saying \"FAR *\" where such a pointer is needed.  In a few places\n * explicit coding is needed; see uses of the NEED_FAR_POINTERS symbol.\n */\n\n#ifndef FAR\n#ifdef NEED_FAR_POINTERS\n#define FAR  far\n#else\n#define FAR\n#endif\n#endif\n\n\n/*\n * On a few systems, type boolean and/or its values FALSE, TRUE may appear\n * in standard header files.  Or you may have conflicts with application-\n * specific header files that you want to include together with these files.\n * Defining HAVE_BOOLEAN before including jpeglib.h should make it work.\n */\n\n#ifndef HAVE_BOOLEAN\n#if defined FALSE || defined TRUE || defined QGLOBAL_H\n/* Qt3 defines FALSE and TRUE as \"const\" variables in qglobal.h */\ntypedef int boolean;\n#ifndef FALSE\t\t\t/* in case these macros already exist */\n#define FALSE\t0\t\t/* values of boolean */\n#endif\n#ifndef TRUE\n#define TRUE\t1\n#endif\n#else\ntypedef enum { FALSE = 0, TRUE = 1 } boolean;\n#endif\n#endif\n\n\n/*\n * The remaining options affect code selection within the JPEG library,\n * but they don't need to be visible to most applications using the library.\n * To minimize application namespace pollution, the symbols won't be\n * defined unless JPEG_INTERNALS or JPEG_INTERNAL_OPTIONS has been defined.\n */\n\n#ifdef JPEG_INTERNALS\n#define JPEG_INTERNAL_OPTIONS\n#endif\n\n#ifdef JPEG_INTERNAL_OPTIONS\n\n\n/*\n * These defines indicate whether to include various optional functions.\n * Undefining some of these symbols will produce a smaller but less capable\n * library.  Note that you can leave certain source files out of the\n * compilation/linking process if you've #undef'd the corresponding symbols.\n * (You may HAVE to do that if your compiler doesn't like null source files.)\n */\n\n/* Capability options common to encoder and decoder: */\n\n#define DCT_ISLOW_SUPPORTED\t/* slow but accurate integer algorithm */\n#define DCT_IFAST_SUPPORTED\t/* faster, less accurate integer method */\n#define DCT_FLOAT_SUPPORTED\t/* floating-point: accurate, fast on fast HW */\n\n/* Encoder capability options: */\n\n#define C_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */\n#define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */\n#define C_PROGRESSIVE_SUPPORTED\t    /* Progressive JPEG? (Requires MULTISCAN)*/\n#define DCT_SCALING_SUPPORTED\t    /* Input rescaling via DCT? (Requires DCT_ISLOW)*/\n#define ENTROPY_OPT_SUPPORTED\t    /* Optimization of entropy coding parms? */\n/* Note: if you selected more than 8-bit data precision, it is dangerous to\n * turn off ENTROPY_OPT_SUPPORTED.  The standard Huffman tables are only\n * good for 8-bit precision, so arithmetic coding is recommended for higher\n * precision.  The Huffman encoder normally uses entropy optimization to\n * compute usable tables for higher precision.  Otherwise, you'll have to\n * supply different default Huffman tables.\n * The exact same statements apply for progressive JPEG: the default tables\n * don't work for progressive mode.  (This may get fixed, however.)\n */\n#define INPUT_SMOOTHING_SUPPORTED   /* Input image smoothing option? */\n\n/* Decoder capability options: */\n\n#define D_ARITH_CODING_SUPPORTED    /* Arithmetic coding back end? */\n#define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */\n#define D_PROGRESSIVE_SUPPORTED\t    /* Progressive JPEG? (Requires MULTISCAN)*/\n#define IDCT_SCALING_SUPPORTED\t    /* Output rescaling via IDCT? (Requires DCT_ISLOW)*/\n#define SAVE_MARKERS_SUPPORTED\t    /* jpeg_save_markers() needed? */\n#define BLOCK_SMOOTHING_SUPPORTED   /* Block smoothing? (Progressive only) */\n#undef  UPSAMPLE_SCALING_SUPPORTED  /* Output rescaling at upsample stage? */\n#define UPSAMPLE_MERGING_SUPPORTED  /* Fast path for sloppy upsampling? */\n#define QUANT_1PASS_SUPPORTED\t    /* 1-pass color quantization? */\n#define QUANT_2PASS_SUPPORTED\t    /* 2-pass color quantization? */\n\n/* more capability options later, no doubt */\n\n\n/*\n * Ordering of RGB data in scanlines passed to or from the application.\n * If your application wants to deal with data in the order B,G,R, just\n * change these macros.  You can also deal with formats such as R,G,B,X\n * (one extra byte per pixel) by changing RGB_PIXELSIZE.  Note that changing\n * the offsets will also change the order in which colormap data is organized.\n * RESTRICTIONS:\n * 1. The sample applications cjpeg,djpeg do NOT support modified RGB formats.\n * 2. The color quantizer modules will not behave desirably if RGB_PIXELSIZE\n *    is not 3 (they don't understand about dummy color components!).  So you\n *    can't use color quantization if you change that value.\n */\n\n#define RGB_RED\t\t0\t/* Offset of Red in an RGB scanline element */\n#define RGB_GREEN\t1\t/* Offset of Green */\n#define RGB_BLUE\t2\t/* Offset of Blue */\n#define RGB_PIXELSIZE\t3\t/* JSAMPLEs per RGB scanline element */\n\n\n/* Definitions for speed-related optimizations. */\n\n\n/* If your compiler supports inline functions, define INLINE\n * as the inline keyword; otherwise define it as empty.\n */\n\n#ifndef INLINE\n#ifdef __GNUC__\t\t\t/* for instance, GNU C knows about inline */\n#define INLINE __inline__\n#endif\n#ifndef INLINE\n#define INLINE\t\t\t/* default is to define it as empty */\n#endif\n#endif\n\n\n/* On some machines (notably 68000 series) \"int\" is 32 bits, but multiplying\n * two 16-bit shorts is faster than multiplying two ints.  Define MULTIPLIER\n * as short on such a machine.  MULTIPLIER must be at least 16 bits wide.\n */\n\n#ifndef MULTIPLIER\n#define MULTIPLIER  int\t\t/* type for fastest integer multiply */\n#endif\n\n\n/* FAST_FLOAT should be either float or double, whichever is done faster\n * by your compiler.  (Note that this type is only used in the floating point\n * DCT routines, so it only matters if you've defined DCT_FLOAT_SUPPORTED.)\n * Typically, float is faster in ANSI C compilers, while double is faster in\n * pre-ANSI compilers (because they insist on converting to double anyway).\n * The code below therefore chooses float if we have ANSI-style prototypes.\n */\n\n#ifndef FAST_FLOAT\n#ifdef HAVE_PROTOTYPES\n#define FAST_FLOAT  float\n#else\n#define FAST_FLOAT  double\n#endif\n#endif\n\n#endif /* JPEG_INTERNAL_OPTIONS */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jpegint.h",
    "content": "/*\n * jpegint.h\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 1997-2013 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file provides common declarations for the various JPEG modules.\n * These declarations are considered internal to the JPEG library; most\n * applications using the library shouldn't need to include this file.\n */\n\n\n/* Declarations for both compression & decompression */\n\ntypedef enum {\t\t\t/* Operating modes for buffer controllers */\n\tJBUF_PASS_THRU,\t\t/* Plain stripwise operation */\n\t/* Remaining modes require a full-image buffer to have been created */\n\tJBUF_SAVE_SOURCE,\t/* Run source subobject only, save output */\n\tJBUF_CRANK_DEST,\t/* Run dest subobject only, using saved data */\n\tJBUF_SAVE_AND_PASS\t/* Run both subobjects, save output */\n} J_BUF_MODE;\n\n/* Values of global_state field (jdapi.c has some dependencies on ordering!) */\n#define CSTATE_START\t100\t/* after create_compress */\n#define CSTATE_SCANNING\t101\t/* start_compress done, write_scanlines OK */\n#define CSTATE_RAW_OK\t102\t/* start_compress done, write_raw_data OK */\n#define CSTATE_WRCOEFS\t103\t/* jpeg_write_coefficients done */\n#define DSTATE_START\t200\t/* after create_decompress */\n#define DSTATE_INHEADER\t201\t/* reading header markers, no SOS yet */\n#define DSTATE_READY\t202\t/* found SOS, ready for start_decompress */\n#define DSTATE_PRELOAD\t203\t/* reading multiscan file in start_decompress*/\n#define DSTATE_PRESCAN\t204\t/* performing dummy pass for 2-pass quant */\n#define DSTATE_SCANNING\t205\t/* start_decompress done, read_scanlines OK */\n#define DSTATE_RAW_OK\t206\t/* start_decompress done, read_raw_data OK */\n#define DSTATE_BUFIMAGE\t207\t/* expecting jpeg_start_output */\n#define DSTATE_BUFPOST\t208\t/* looking for SOS/EOI in jpeg_finish_output */\n#define DSTATE_RDCOEFS\t209\t/* reading file in jpeg_read_coefficients */\n#define DSTATE_STOPPING\t210\t/* looking for EOI in jpeg_finish_decompress */\n\n\n/* Declarations for compression modules */\n\n/* Master control module */\nstruct jpeg_comp_master {\n  JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));\n  JMETHOD(void, pass_startup, (j_compress_ptr cinfo));\n  JMETHOD(void, finish_pass, (j_compress_ptr cinfo));\n\n  /* State variables made visible to other modules */\n  boolean call_pass_startup;\t/* True if pass_startup must be called */\n  boolean is_last_pass;\t\t/* True during last pass */\n};\n\n/* Main buffer control (downsampled-data buffer) */\nstruct jpeg_c_main_controller {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));\n  JMETHOD(void, process_data, (j_compress_ptr cinfo,\n\t\t\t       JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,\n\t\t\t       JDIMENSION in_rows_avail));\n};\n\n/* Compression preprocessing (downsampling input buffer control) */\nstruct jpeg_c_prep_controller {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));\n  JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,\n\t\t\t\t   JSAMPARRAY input_buf,\n\t\t\t\t   JDIMENSION *in_row_ctr,\n\t\t\t\t   JDIMENSION in_rows_avail,\n\t\t\t\t   JSAMPIMAGE output_buf,\n\t\t\t\t   JDIMENSION *out_row_group_ctr,\n\t\t\t\t   JDIMENSION out_row_groups_avail));\n};\n\n/* Coefficient buffer control */\nstruct jpeg_c_coef_controller {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));\n  JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,\n\t\t\t\t   JSAMPIMAGE input_buf));\n};\n\n/* Colorspace conversion */\nstruct jpeg_color_converter {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo));\n  JMETHOD(void, color_convert, (j_compress_ptr cinfo,\n\t\t\t\tJSAMPARRAY input_buf, JSAMPIMAGE output_buf,\n\t\t\t\tJDIMENSION output_row, int num_rows));\n};\n\n/* Downsampling */\nstruct jpeg_downsampler {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo));\n  JMETHOD(void, downsample, (j_compress_ptr cinfo,\n\t\t\t     JSAMPIMAGE input_buf, JDIMENSION in_row_index,\n\t\t\t     JSAMPIMAGE output_buf,\n\t\t\t     JDIMENSION out_row_group_index));\n\n  boolean need_context_rows;\t/* TRUE if need rows above & below */\n};\n\n/* Forward DCT (also controls coefficient quantization) */\ntypedef JMETHOD(void, forward_DCT_ptr,\n\t\t(j_compress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JSAMPARRAY sample_data, JBLOCKROW coef_blocks,\n\t\t JDIMENSION start_row, JDIMENSION start_col,\n\t\t JDIMENSION num_blocks));\n\nstruct jpeg_forward_dct {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo));\n  /* It is useful to allow each component to have a separate FDCT method. */\n  forward_DCT_ptr forward_DCT[MAX_COMPONENTS];\n};\n\n/* Entropy encoding */\nstruct jpeg_entropy_encoder {\n  JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));\n  JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));\n  JMETHOD(void, finish_pass, (j_compress_ptr cinfo));\n};\n\n/* Marker writing */\nstruct jpeg_marker_writer {\n  JMETHOD(void, write_file_header, (j_compress_ptr cinfo));\n  JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));\n  JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));\n  JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));\n  JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));\n  /* These routines are exported to allow insertion of extra markers */\n  /* Probably only COM and APPn markers should be written this way */\n  JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,\n\t\t\t\t      unsigned int datalen));\n  JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));\n};\n\n\n/* Declarations for decompression modules */\n\n/* Master control module */\nstruct jpeg_decomp_master {\n  JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));\n  JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));\n\n  /* State variables made visible to other modules */\n  boolean is_dummy_pass;\t/* True during 1st pass for 2-pass quant */\n};\n\n/* Input control module */\nstruct jpeg_input_controller {\n  JMETHOD(int, consume_input, (j_decompress_ptr cinfo));\n  JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));\n  JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));\n  JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));\n\n  /* State variables made visible to other modules */\n  boolean has_multiple_scans;\t/* True if file has multiple scans */\n  boolean eoi_reached;\t\t/* True when EOI has been consumed */\n};\n\n/* Main buffer control (downsampled-data buffer) */\nstruct jpeg_d_main_controller {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));\n  JMETHOD(void, process_data, (j_decompress_ptr cinfo,\n\t\t\t       JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,\n\t\t\t       JDIMENSION out_rows_avail));\n};\n\n/* Coefficient buffer control */\nstruct jpeg_d_coef_controller {\n  JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));\n  JMETHOD(int, consume_data, (j_decompress_ptr cinfo));\n  JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));\n  JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,\n\t\t\t\t JSAMPIMAGE output_buf));\n  /* Pointer to array of coefficient virtual arrays, or NULL if none */\n  jvirt_barray_ptr *coef_arrays;\n};\n\n/* Decompression postprocessing (color quantization buffer control) */\nstruct jpeg_d_post_controller {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));\n  JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,\n\t\t\t\t    JSAMPIMAGE input_buf,\n\t\t\t\t    JDIMENSION *in_row_group_ctr,\n\t\t\t\t    JDIMENSION in_row_groups_avail,\n\t\t\t\t    JSAMPARRAY output_buf,\n\t\t\t\t    JDIMENSION *out_row_ctr,\n\t\t\t\t    JDIMENSION out_rows_avail));\n};\n\n/* Marker reading & parsing */\nstruct jpeg_marker_reader {\n  JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));\n  /* Read markers until SOS or EOI.\n   * Returns same codes as are defined for jpeg_consume_input:\n   * JPEG_SUSPENDED, JPEG_REACHED_SOS, or JPEG_REACHED_EOI.\n   */\n  JMETHOD(int, read_markers, (j_decompress_ptr cinfo));\n  /* Read a restart marker --- exported for use by entropy decoder only */\n  jpeg_marker_parser_method read_restart_marker;\n\n  /* State of marker reader --- nominally internal, but applications\n   * supplying COM or APPn handlers might like to know the state.\n   */\n  boolean saw_SOI;\t\t/* found SOI? */\n  boolean saw_SOF;\t\t/* found SOF? */\n  int next_restart_num;\t\t/* next restart number expected (0-7) */\n  unsigned int discarded_bytes;\t/* # of bytes skipped looking for a marker */\n};\n\n/* Entropy decoding */\nstruct jpeg_entropy_decoder {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo));\n  JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo, JBLOCKROW *MCU_data));\n  JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));\n};\n\n/* Inverse DCT (also performs dequantization) */\ntypedef JMETHOD(void, inverse_DCT_method_ptr,\n\t\t(j_decompress_ptr cinfo, jpeg_component_info * compptr,\n\t\t JCOEFPTR coef_block,\n\t\t JSAMPARRAY output_buf, JDIMENSION output_col));\n\nstruct jpeg_inverse_dct {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo));\n  /* It is useful to allow each component to have a separate IDCT method. */\n  inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];\n};\n\n/* Upsampling (note that upsampler must also call color converter) */\nstruct jpeg_upsampler {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo));\n  JMETHOD(void, upsample, (j_decompress_ptr cinfo,\n\t\t\t   JSAMPIMAGE input_buf,\n\t\t\t   JDIMENSION *in_row_group_ctr,\n\t\t\t   JDIMENSION in_row_groups_avail,\n\t\t\t   JSAMPARRAY output_buf,\n\t\t\t   JDIMENSION *out_row_ctr,\n\t\t\t   JDIMENSION out_rows_avail));\n\n  boolean need_context_rows;\t/* TRUE if need rows above & below */\n};\n\n/* Colorspace conversion */\nstruct jpeg_color_deconverter {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo));\n  JMETHOD(void, color_convert, (j_decompress_ptr cinfo,\n\t\t\t\tJSAMPIMAGE input_buf, JDIMENSION input_row,\n\t\t\t\tJSAMPARRAY output_buf, int num_rows));\n};\n\n/* Color quantization or color precision reduction */\nstruct jpeg_color_quantizer {\n  JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));\n  JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,\n\t\t\t\t JSAMPARRAY input_buf, JSAMPARRAY output_buf,\n\t\t\t\t int num_rows));\n  JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));\n  JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));\n};\n\n\n/* Miscellaneous useful macros */\n\n#undef MAX\n#define MAX(a,b)\t((a) > (b) ? (a) : (b))\n#undef MIN\n#define MIN(a,b)\t((a) < (b) ? (a) : (b))\n\n\n/* We assume that right shift corresponds to signed division by 2 with\n * rounding towards minus infinity.  This is correct for typical \"arithmetic\n * shift\" instructions that shift in copies of the sign bit.  But some\n * C compilers implement >> with an unsigned shift.  For these machines you\n * must define RIGHT_SHIFT_IS_UNSIGNED.\n * RIGHT_SHIFT provides a proper signed right shift of an INT32 quantity.\n * It is only applied with constant shift counts.  SHIFT_TEMPS must be\n * included in the variables of any routine using RIGHT_SHIFT.\n */\n\n#ifdef RIGHT_SHIFT_IS_UNSIGNED\n#define SHIFT_TEMPS\tINT32 shift_temp;\n#define RIGHT_SHIFT(x,shft)  \\\n\t((shift_temp = (x)) < 0 ? \\\n\t (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \\\n\t (shift_temp >> (shft)))\n#else\n#define SHIFT_TEMPS\n#define RIGHT_SHIFT(x,shft)\t((x) >> (shft))\n#endif\n\n\n/* Short forms of external names for systems with brain-damaged linkers. */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jinit_compress_master\tjICompress\n#define jinit_c_master_control\tjICMaster\n#define jinit_c_main_controller\tjICMainC\n#define jinit_c_prep_controller\tjICPrepC\n#define jinit_c_coef_controller\tjICCoefC\n#define jinit_color_converter\tjICColor\n#define jinit_downsampler\tjIDownsampler\n#define jinit_forward_dct\tjIFDCT\n#define jinit_huff_encoder\tjIHEncoder\n#define jinit_arith_encoder\tjIAEncoder\n#define jinit_marker_writer\tjIMWriter\n#define jinit_master_decompress\tjIDMaster\n#define jinit_d_main_controller\tjIDMainC\n#define jinit_d_coef_controller\tjIDCoefC\n#define jinit_d_post_controller\tjIDPostC\n#define jinit_input_controller\tjIInCtlr\n#define jinit_marker_reader\tjIMReader\n#define jinit_huff_decoder\tjIHDecoder\n#define jinit_arith_decoder\tjIADecoder\n#define jinit_inverse_dct\tjIIDCT\n#define jinit_upsampler\t\tjIUpsampler\n#define jinit_color_deconverter\tjIDColor\n#define jinit_1pass_quantizer\tjI1Quant\n#define jinit_2pass_quantizer\tjI2Quant\n#define jinit_merged_upsampler\tjIMUpsampler\n#define jinit_memory_mgr\tjIMemMgr\n#define jdiv_round_up\t\tjDivRound\n#define jround_up\t\tjRound\n#define jzero_far\t\tjZeroFar\n#define jcopy_sample_rows\tjCopySamples\n#define jcopy_block_row\t\tjCopyBlocks\n#define jpeg_zigzag_order\tjZIGTable\n#define jpeg_natural_order\tjZAGTable\n#define jpeg_natural_order7\tjZAG7Table\n#define jpeg_natural_order6\tjZAG6Table\n#define jpeg_natural_order5\tjZAG5Table\n#define jpeg_natural_order4\tjZAG4Table\n#define jpeg_natural_order3\tjZAG3Table\n#define jpeg_natural_order2\tjZAG2Table\n#define jpeg_aritab\t\tjAriTab\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n\n/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays\n * and coefficient-block arrays.  This won't work on 80x86 because the arrays\n * are FAR and we're assuming a small-pointer memory model.  However, some\n * DOS compilers provide far-pointer versions of memcpy() and memset() even\n * in the small-model libraries.  These will be used if USE_FMEM is defined.\n * Otherwise, the routines in jutils.c do it the hard way.\n */\n\n#ifndef NEED_FAR_POINTERS\t/* normal case, same as regular macro */\n#define FMEMZERO(target,size)\tMEMZERO(target,size)\n#else\t\t\t\t/* 80x86 case */\n#ifdef USE_FMEM\n#define FMEMZERO(target,size)\t_fmemset((void FAR *)(target), 0, (size_t)(size))\n#else\nEXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));\n#define FMEMZERO(target,size)\tjzero_far(target, size)\n#endif\n#endif\n\n\n/* Compression module initialization routines */\nEXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,\n\t\t\t\t\t boolean transcode_only));\nEXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_arith_encoder JPP((j_compress_ptr cinfo));\nEXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));\n/* Decompression module initialization routines */\nEXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t  boolean need_full_buffer));\nEXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_arith_decoder JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));\nEXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));\n/* Memory manager initialization */\nEXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));\n\n/* Utility routines in jutils.c */\nEXTERN(long) jdiv_round_up JPP((long a, long b));\nEXTERN(long) jround_up JPP((long a, long b));\nEXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,\n\t\t\t\t    JSAMPARRAY output_array, int dest_row,\n\t\t\t\t    int num_rows, JDIMENSION num_cols));\nEXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,\n\t\t\t\t  JDIMENSION num_blocks));\n/* Constant tables in jutils.c */\n#if 0\t\t\t\t/* This table is not actually needed in v6a */\nextern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */\n#endif\nextern const int jpeg_natural_order[]; /* zigzag coef order to natural order */\nextern const int jpeg_natural_order7[]; /* zz to natural order for 7x7 block */\nextern const int jpeg_natural_order6[]; /* zz to natural order for 6x6 block */\nextern const int jpeg_natural_order5[]; /* zz to natural order for 5x5 block */\nextern const int jpeg_natural_order4[]; /* zz to natural order for 4x4 block */\nextern const int jpeg_natural_order3[]; /* zz to natural order for 3x3 block */\nextern const int jpeg_natural_order2[]; /* zz to natural order for 2x2 block */\n\n/* Arithmetic coding probability estimation tables in jaricom.c */\nextern const INT32 jpeg_aritab[];\n\n/* Suppress undefined-structure complaints if necessary. */\n\n#ifdef INCOMPLETE_TYPES_BROKEN\n#ifndef AM_MEMORY_MANAGER\t/* only jmemmgr.c defines these */\nstruct jvirt_sarray_control { long dummy; };\nstruct jvirt_barray_control { long dummy; };\n#endif\n#endif /* INCOMPLETE_TYPES_BROKEN */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jpeglib.h",
    "content": "/*\n * jpeglib.h\n *\n * Copyright (C) 1991-1998, Thomas G. Lane.\n * Modified 2002-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file defines the application interface for the JPEG library.\n * Most applications using the library need only include this file,\n * and perhaps jerror.h if they want to know the exact error codes.\n */\n\n#ifndef JPEGLIB_H\n#define JPEGLIB_H\n\n/*\n * First we include the configuration files that record how this\n * installation of the JPEG library is set up.  jconfig.h can be\n * generated automatically for many systems.  jmorecfg.h contains\n * manual configuration options that most people need not worry about.\n */\n\n#ifndef JCONFIG_INCLUDED\t/* in case jinclude.h already did */\n#include \"jconfig.h\"\t\t/* widely used configuration options */\n#endif\n#include \"jmorecfg.h\"\t\t/* seldom changed options */\n\n\n#ifdef __cplusplus\n#ifndef DONT_USE_EXTERN_C\nextern \"C\" {\n#endif\n#endif\n\n/* Version IDs for the JPEG library.\n * Might be useful for tests like \"#if JPEG_LIB_VERSION >= 90\".\n */\n\n#define JPEG_LIB_VERSION        90\t/* Compatibility version 9.0 */\n#define JPEG_LIB_VERSION_MAJOR  9\n#define JPEG_LIB_VERSION_MINOR  2\n\n\n/* Various constants determining the sizes of things.\n * All of these are specified by the JPEG standard,\n * so don't change them if you want to be compatible.\n */\n\n#define DCTSIZE\t\t    8\t/* The basic DCT block is 8x8 coefficients */\n#define DCTSIZE2\t    64\t/* DCTSIZE squared; # of elements in a block */\n#define NUM_QUANT_TBLS      4\t/* Quantization tables are numbered 0..3 */\n#define NUM_HUFF_TBLS       4\t/* Huffman tables are numbered 0..3 */\n#define NUM_ARITH_TBLS      16\t/* Arith-coding tables are numbered 0..15 */\n#define MAX_COMPS_IN_SCAN   4\t/* JPEG limit on # of components in one scan */\n#define MAX_SAMP_FACTOR     4\t/* JPEG limit on sampling factors */\n/* Unfortunately, some bozo at Adobe saw no reason to be bound by the standard;\n * the PostScript DCT filter can emit files with many more than 10 blocks/MCU.\n * If you happen to run across such a file, you can up D_MAX_BLOCKS_IN_MCU\n * to handle it.  We even let you do this from the jconfig.h file.  However,\n * we strongly discourage changing C_MAX_BLOCKS_IN_MCU; just because Adobe\n * sometimes emits noncompliant files doesn't mean you should too.\n */\n#define C_MAX_BLOCKS_IN_MCU   10 /* compressor's limit on blocks per MCU */\n#ifndef D_MAX_BLOCKS_IN_MCU\n#define D_MAX_BLOCKS_IN_MCU   10 /* decompressor's limit on blocks per MCU */\n#endif\n\n\n/* Data structures for images (arrays of samples and of DCT coefficients).\n * On 80x86 machines, the image arrays are too big for near pointers,\n * but the pointer arrays can fit in near memory.\n */\n\ntypedef JSAMPLE FAR *JSAMPROW;\t/* ptr to one image row of pixel samples. */\ntypedef JSAMPROW *JSAMPARRAY;\t/* ptr to some rows (a 2-D sample array) */\ntypedef JSAMPARRAY *JSAMPIMAGE;\t/* a 3-D sample array: top index is color */\n\ntypedef JCOEF JBLOCK[DCTSIZE2];\t/* one block of coefficients */\ntypedef JBLOCK FAR *JBLOCKROW;\t/* pointer to one row of coefficient blocks */\ntypedef JBLOCKROW *JBLOCKARRAY;\t\t/* a 2-D array of coefficient blocks */\ntypedef JBLOCKARRAY *JBLOCKIMAGE;\t/* a 3-D array of coefficient blocks */\n\ntypedef JCOEF FAR *JCOEFPTR;\t/* useful in a couple of places */\n\n\n/* Types for JPEG compression parameters and working tables. */\n\n\n/* DCT coefficient quantization tables. */\n\ntypedef struct {\n  /* This array gives the coefficient quantizers in natural array order\n   * (not the zigzag order in which they are stored in a JPEG DQT marker).\n   * CAUTION: IJG versions prior to v6a kept this array in zigzag order.\n   */\n  UINT16 quantval[DCTSIZE2];\t/* quantization step for each coefficient */\n  /* This field is used only during compression.  It's initialized FALSE when\n   * the table is created, and set TRUE when it's been output to the file.\n   * You could suppress output of a table by setting this to TRUE.\n   * (See jpeg_suppress_tables for an example.)\n   */\n  boolean sent_table;\t\t/* TRUE when table has been output */\n} JQUANT_TBL;\n\n\n/* Huffman coding tables. */\n\ntypedef struct {\n  /* These two fields directly represent the contents of a JPEG DHT marker */\n  UINT8 bits[17];\t\t/* bits[k] = # of symbols with codes of */\n\t\t\t\t/* length k bits; bits[0] is unused */\n  UINT8 huffval[256];\t\t/* The symbols, in order of incr code length */\n  /* This field is used only during compression.  It's initialized FALSE when\n   * the table is created, and set TRUE when it's been output to the file.\n   * You could suppress output of a table by setting this to TRUE.\n   * (See jpeg_suppress_tables for an example.)\n   */\n  boolean sent_table;\t\t/* TRUE when table has been output */\n} JHUFF_TBL;\n\n\n/* Basic info about one component (color channel). */\n\ntypedef struct {\n  /* These values are fixed over the whole image. */\n  /* For compression, they must be supplied by parameter setup; */\n  /* for decompression, they are read from the SOF marker. */\n  int component_id;\t\t/* identifier for this component (0..255) */\n  int component_index;\t\t/* its index in SOF or cinfo->comp_info[] */\n  int h_samp_factor;\t\t/* horizontal sampling factor (1..4) */\n  int v_samp_factor;\t\t/* vertical sampling factor (1..4) */\n  int quant_tbl_no;\t\t/* quantization table selector (0..3) */\n  /* These values may vary between scans. */\n  /* For compression, they must be supplied by parameter setup; */\n  /* for decompression, they are read from the SOS marker. */\n  /* The decompressor output side may not use these variables. */\n  int dc_tbl_no;\t\t/* DC entropy table selector (0..3) */\n  int ac_tbl_no;\t\t/* AC entropy table selector (0..3) */\n  \n  /* Remaining fields should be treated as private by applications. */\n  \n  /* These values are computed during compression or decompression startup: */\n  /* Component's size in DCT blocks.\n   * Any dummy blocks added to complete an MCU are not counted; therefore\n   * these values do not depend on whether a scan is interleaved or not.\n   */\n  JDIMENSION width_in_blocks;\n  JDIMENSION height_in_blocks;\n  /* Size of a DCT block in samples,\n   * reflecting any scaling we choose to apply during the DCT step.\n   * Values from 1 to 16 are supported.\n   * Note that different components may receive different DCT scalings.\n   */\n  int DCT_h_scaled_size;\n  int DCT_v_scaled_size;\n  /* The downsampled dimensions are the component's actual, unpadded number\n   * of samples at the main buffer (preprocessing/compression interface);\n   * DCT scaling is included, so\n   * downsampled_width =\n   *   ceil(image_width * Hi/Hmax * DCT_h_scaled_size/block_size)\n   * and similarly for height.\n   */\n  JDIMENSION downsampled_width;\t /* actual width in samples */\n  JDIMENSION downsampled_height; /* actual height in samples */\n  /* For decompression, in cases where some of the components will be\n   * ignored (eg grayscale output from YCbCr image), we can skip most\n   * computations for the unused components.\n   * For compression, some of the components will need further quantization\n   * scale by factor of 2 after DCT (eg BG_YCC output from normal RGB input).\n   * The field is first set TRUE for decompression, FALSE for compression\n   * in initial_setup, and then adapted in color conversion setup.\n   */\n  boolean component_needed;\n\n  /* These values are computed before starting a scan of the component. */\n  /* The decompressor output side may not use these variables. */\n  int MCU_width;\t\t/* number of blocks per MCU, horizontally */\n  int MCU_height;\t\t/* number of blocks per MCU, vertically */\n  int MCU_blocks;\t\t/* MCU_width * MCU_height */\n  int MCU_sample_width;\t/* MCU width in samples: MCU_width * DCT_h_scaled_size */\n  int last_col_width;\t\t/* # of non-dummy blocks across in last MCU */\n  int last_row_height;\t\t/* # of non-dummy blocks down in last MCU */\n\n  /* Saved quantization table for component; NULL if none yet saved.\n   * See jdinput.c comments about the need for this information.\n   * This field is currently used only for decompression.\n   */\n  JQUANT_TBL * quant_table;\n\n  /* Private per-component storage for DCT or IDCT subsystem. */\n  void * dct_table;\n} jpeg_component_info;\n\n\n/* The script for encoding a multiple-scan file is an array of these: */\n\ntypedef struct {\n  int comps_in_scan;\t\t/* number of components encoded in this scan */\n  int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */\n  int Ss, Se;\t\t\t/* progressive JPEG spectral selection parms */\n  int Ah, Al;\t\t\t/* progressive JPEG successive approx. parms */\n} jpeg_scan_info;\n\n/* The decompressor can save APPn and COM markers in a list of these: */\n\ntypedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;\n\nstruct jpeg_marker_struct {\n  jpeg_saved_marker_ptr next;\t/* next in list, or NULL */\n  UINT8 marker;\t\t\t/* marker code: JPEG_COM, or JPEG_APP0+n */\n  unsigned int original_length;\t/* # bytes of data in the file */\n  unsigned int data_length;\t/* # bytes of data saved at data[] */\n  JOCTET FAR * data;\t\t/* the data contained in the marker */\n  /* the marker length word is not counted in data_length or original_length */\n};\n\n/* Known color spaces. */\n\ntypedef enum {\n\tJCS_UNKNOWN,\t\t/* error/unspecified */\n\tJCS_GRAYSCALE,\t\t/* monochrome */\n\tJCS_RGB,\t\t/* red/green/blue, standard RGB (sRGB) */\n\tJCS_YCbCr,\t\t/* Y/Cb/Cr (also known as YUV), standard YCC */\n\tJCS_CMYK,\t\t/* C/M/Y/K */\n\tJCS_YCCK,\t\t/* Y/Cb/Cr/K */\n\tJCS_BG_RGB,\t\t/* big gamut red/green/blue, bg-sRGB */\n\tJCS_BG_YCC\t\t/* big gamut Y/Cb/Cr, bg-sYCC */\n} J_COLOR_SPACE;\n\n/* Supported color transforms. */\n\ntypedef enum {\n\tJCT_NONE           = 0,\n\tJCT_SUBTRACT_GREEN = 1\n} J_COLOR_TRANSFORM;\n\n/* DCT/IDCT algorithm options. */\n\ntypedef enum {\n\tJDCT_ISLOW,\t\t/* slow but accurate integer algorithm */\n\tJDCT_IFAST,\t\t/* faster, less accurate integer method */\n\tJDCT_FLOAT\t\t/* floating-point: accurate, fast on fast HW */\n} J_DCT_METHOD;\n\n#ifndef JDCT_DEFAULT\t\t/* may be overridden in jconfig.h */\n#define JDCT_DEFAULT  JDCT_ISLOW\n#endif\n#ifndef JDCT_FASTEST\t\t/* may be overridden in jconfig.h */\n#define JDCT_FASTEST  JDCT_IFAST\n#endif\n\n/* Dithering options for decompression. */\n\ntypedef enum {\n\tJDITHER_NONE,\t\t/* no dithering */\n\tJDITHER_ORDERED,\t/* simple ordered dither */\n\tJDITHER_FS\t\t/* Floyd-Steinberg error diffusion dither */\n} J_DITHER_MODE;\n\n\n/* Common fields between JPEG compression and decompression master structs. */\n\n#define jpeg_common_fields \\\n  struct jpeg_error_mgr * err;\t/* Error handler module */\\\n  struct jpeg_memory_mgr * mem;\t/* Memory manager module */\\\n  struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\\\n  void * client_data;\t\t/* Available for use by application */\\\n  boolean is_decompressor;\t/* So common code can tell which is which */\\\n  int global_state\t\t/* For checking call sequence validity */\n\n/* Routines that are to be used by both halves of the library are declared\n * to receive a pointer to this structure.  There are no actual instances of\n * jpeg_common_struct, only of jpeg_compress_struct and jpeg_decompress_struct.\n */\nstruct jpeg_common_struct {\n  jpeg_common_fields;\t\t/* Fields common to both master struct types */\n  /* Additional fields follow in an actual jpeg_compress_struct or\n   * jpeg_decompress_struct.  All three structs must agree on these\n   * initial fields!  (This would be a lot cleaner in C++.)\n   */\n};\n\ntypedef struct jpeg_common_struct * j_common_ptr;\ntypedef struct jpeg_compress_struct * j_compress_ptr;\ntypedef struct jpeg_decompress_struct * j_decompress_ptr;\n\n\n/* Master record for a compression instance */\n\nstruct jpeg_compress_struct {\n  jpeg_common_fields;\t\t/* Fields shared with jpeg_decompress_struct */\n\n  /* Destination for compressed data */\n  struct jpeg_destination_mgr * dest;\n\n  /* Description of source image --- these fields must be filled in by\n   * outer application before starting compression.  in_color_space must\n   * be correct before you can even call jpeg_set_defaults().\n   */\n\n  JDIMENSION image_width;\t/* input image width */\n  JDIMENSION image_height;\t/* input image height */\n  int input_components;\t\t/* # of color components in input image */\n  J_COLOR_SPACE in_color_space;\t/* colorspace of input image */\n\n  double input_gamma;\t\t/* image gamma of input image */\n\n  /* Compression parameters --- these fields must be set before calling\n   * jpeg_start_compress().  We recommend calling jpeg_set_defaults() to\n   * initialize everything to reasonable defaults, then changing anything\n   * the application specifically wants to change.  That way you won't get\n   * burnt when new parameters are added.  Also note that there are several\n   * helper routines to simplify changing parameters.\n   */\n\n  unsigned int scale_num, scale_denom; /* fraction by which to scale image */\n\n  JDIMENSION jpeg_width;\t/* scaled JPEG image width */\n  JDIMENSION jpeg_height;\t/* scaled JPEG image height */\n  /* Dimensions of actual JPEG image that will be written to file,\n   * derived from input dimensions by scaling factors above.\n   * These fields are computed by jpeg_start_compress().\n   * You can also use jpeg_calc_jpeg_dimensions() to determine these values\n   * in advance of calling jpeg_start_compress().\n   */\n\n  int data_precision;\t\t/* bits of precision in image data */\n\n  int num_components;\t\t/* # of color components in JPEG image */\n  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */\n\n  jpeg_component_info * comp_info;\n  /* comp_info[i] describes component that appears i'th in SOF */\n\n  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];\n  int q_scale_factor[NUM_QUANT_TBLS];\n  /* ptrs to coefficient quantization tables, or NULL if not defined,\n   * and corresponding scale factors (percentage, initialized 100).\n   */\n\n  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];\n  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];\n  /* ptrs to Huffman coding tables, or NULL if not defined */\n\n  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */\n  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */\n  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */\n\n  int num_scans;\t\t/* # of entries in scan_info array */\n  const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */\n  /* The default value of scan_info is NULL, which causes a single-scan\n   * sequential JPEG file to be emitted.  To create a multi-scan file,\n   * set num_scans and scan_info to point to an array of scan definitions.\n   */\n\n  boolean raw_data_in;\t\t/* TRUE=caller supplies downsampled data */\n  boolean arith_code;\t\t/* TRUE=arithmetic coding, FALSE=Huffman */\n  boolean optimize_coding;\t/* TRUE=optimize entropy encoding parms */\n  boolean CCIR601_sampling;\t/* TRUE=first samples are cosited */\n  boolean do_fancy_downsampling; /* TRUE=apply fancy downsampling */\n  int smoothing_factor;\t\t/* 1..100, or 0 for no input smoothing */\n  J_DCT_METHOD dct_method;\t/* DCT algorithm selector */\n\n  /* The restart interval can be specified in absolute MCUs by setting\n   * restart_interval, or in MCU rows by setting restart_in_rows\n   * (in which case the correct restart_interval will be figured\n   * for each scan).\n   */\n  unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */\n  int restart_in_rows;\t\t/* if > 0, MCU rows per restart interval */\n\n  /* Parameters controlling emission of special markers. */\n\n  boolean write_JFIF_header;\t/* should a JFIF marker be written? */\n  UINT8 JFIF_major_version;\t/* What to write for the JFIF version number */\n  UINT8 JFIF_minor_version;\n  /* These three values are not used by the JPEG code, merely copied */\n  /* into the JFIF APP0 marker.  density_unit can be 0 for unknown, */\n  /* 1 for dots/inch, or 2 for dots/cm.  Note that the pixel aspect */\n  /* ratio is defined by X_density/Y_density even when density_unit=0. */\n  UINT8 density_unit;\t\t/* JFIF code for pixel size units */\n  UINT16 X_density;\t\t/* Horizontal pixel density */\n  UINT16 Y_density;\t\t/* Vertical pixel density */\n  boolean write_Adobe_marker;\t/* should an Adobe marker be written? */\n\n  J_COLOR_TRANSFORM color_transform;\n  /* Color transform identifier, writes LSE marker if nonzero */\n\n  /* State variable: index of next scanline to be written to\n   * jpeg_write_scanlines().  Application may use this to control its\n   * processing loop, e.g., \"while (next_scanline < image_height)\".\n   */\n\n  JDIMENSION next_scanline;\t/* 0 .. image_height-1  */\n\n  /* Remaining fields are known throughout compressor, but generally\n   * should not be touched by a surrounding application.\n   */\n\n  /*\n   * These fields are computed during compression startup\n   */\n  boolean progressive_mode;\t/* TRUE if scan script uses progressive mode */\n  int max_h_samp_factor;\t/* largest h_samp_factor */\n  int max_v_samp_factor;\t/* largest v_samp_factor */\n\n  int min_DCT_h_scaled_size;\t/* smallest DCT_h_scaled_size of any component */\n  int min_DCT_v_scaled_size;\t/* smallest DCT_v_scaled_size of any component */\n\n  JDIMENSION total_iMCU_rows;\t/* # of iMCU rows to be input to coef ctlr */\n  /* The coefficient controller receives data in units of MCU rows as defined\n   * for fully interleaved scans (whether the JPEG file is interleaved or not).\n   * There are v_samp_factor * DCTSIZE sample rows of each component in an\n   * \"iMCU\" (interleaved MCU) row.\n   */\n  \n  /*\n   * These fields are valid during any one scan.\n   * They describe the components and MCUs actually appearing in the scan.\n   */\n  int comps_in_scan;\t\t/* # of JPEG components in this scan */\n  jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];\n  /* *cur_comp_info[i] describes component that appears i'th in SOS */\n  \n  JDIMENSION MCUs_per_row;\t/* # of MCUs across the image */\n  JDIMENSION MCU_rows_in_scan;\t/* # of MCU rows in the image */\n  \n  int blocks_in_MCU;\t\t/* # of DCT blocks per MCU */\n  int MCU_membership[C_MAX_BLOCKS_IN_MCU];\n  /* MCU_membership[i] is index in cur_comp_info of component owning */\n  /* i'th block in an MCU */\n\n  int Ss, Se, Ah, Al;\t\t/* progressive JPEG parameters for scan */\n\n  int block_size;\t\t/* the basic DCT block size: 1..16 */\n  const int * natural_order;\t/* natural-order position array */\n  int lim_Se;\t\t\t/* min( Se, DCTSIZE2-1 ) */\n\n  /*\n   * Links to compression subobjects (methods and private variables of modules)\n   */\n  struct jpeg_comp_master * master;\n  struct jpeg_c_main_controller * main;\n  struct jpeg_c_prep_controller * prep;\n  struct jpeg_c_coef_controller * coef;\n  struct jpeg_marker_writer * marker;\n  struct jpeg_color_converter * cconvert;\n  struct jpeg_downsampler * downsample;\n  struct jpeg_forward_dct * fdct;\n  struct jpeg_entropy_encoder * entropy;\n  jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */\n  int script_space_size;\n};\n\n\n/* Master record for a decompression instance */\n\nstruct jpeg_decompress_struct {\n  jpeg_common_fields;\t\t/* Fields shared with jpeg_compress_struct */\n\n  /* Source of compressed data */\n  struct jpeg_source_mgr * src;\n\n  /* Basic description of image --- filled in by jpeg_read_header(). */\n  /* Application may inspect these values to decide how to process image. */\n\n  JDIMENSION image_width;\t/* nominal image width (from SOF marker) */\n  JDIMENSION image_height;\t/* nominal image height */\n  int num_components;\t\t/* # of color components in JPEG image */\n  J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */\n\n  /* Decompression processing parameters --- these fields must be set before\n   * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes\n   * them to default values.\n   */\n\n  J_COLOR_SPACE out_color_space; /* colorspace for output */\n\n  unsigned int scale_num, scale_denom; /* fraction by which to scale image */\n\n  double output_gamma;\t\t/* image gamma wanted in output */\n\n  boolean buffered_image;\t/* TRUE=multiple output passes */\n  boolean raw_data_out;\t\t/* TRUE=downsampled data wanted */\n\n  J_DCT_METHOD dct_method;\t/* IDCT algorithm selector */\n  boolean do_fancy_upsampling;\t/* TRUE=apply fancy upsampling */\n  boolean do_block_smoothing;\t/* TRUE=apply interblock smoothing */\n\n  boolean quantize_colors;\t/* TRUE=colormapped output wanted */\n  /* the following are ignored if not quantize_colors: */\n  J_DITHER_MODE dither_mode;\t/* type of color dithering to use */\n  boolean two_pass_quantize;\t/* TRUE=use two-pass color quantization */\n  int desired_number_of_colors;\t/* max # colors to use in created colormap */\n  /* these are significant only in buffered-image mode: */\n  boolean enable_1pass_quant;\t/* enable future use of 1-pass quantizer */\n  boolean enable_external_quant;/* enable future use of external colormap */\n  boolean enable_2pass_quant;\t/* enable future use of 2-pass quantizer */\n\n  /* Description of actual output image that will be returned to application.\n   * These fields are computed by jpeg_start_decompress().\n   * You can also use jpeg_calc_output_dimensions() to determine these values\n   * in advance of calling jpeg_start_decompress().\n   */\n\n  JDIMENSION output_width;\t/* scaled image width */\n  JDIMENSION output_height;\t/* scaled image height */\n  int out_color_components;\t/* # of color components in out_color_space */\n  int output_components;\t/* # of color components returned */\n  /* output_components is 1 (a colormap index) when quantizing colors;\n   * otherwise it equals out_color_components.\n   */\n  int rec_outbuf_height;\t/* min recommended height of scanline buffer */\n  /* If the buffer passed to jpeg_read_scanlines() is less than this many rows\n   * high, space and time will be wasted due to unnecessary data copying.\n   * Usually rec_outbuf_height will be 1 or 2, at most 4.\n   */\n\n  /* When quantizing colors, the output colormap is described by these fields.\n   * The application can supply a colormap by setting colormap non-NULL before\n   * calling jpeg_start_decompress; otherwise a colormap is created during\n   * jpeg_start_decompress or jpeg_start_output.\n   * The map has out_color_components rows and actual_number_of_colors columns.\n   */\n  int actual_number_of_colors;\t/* number of entries in use */\n  JSAMPARRAY colormap;\t\t/* The color map as a 2-D pixel array */\n\n  /* State variables: these variables indicate the progress of decompression.\n   * The application may examine these but must not modify them.\n   */\n\n  /* Row index of next scanline to be read from jpeg_read_scanlines().\n   * Application may use this to control its processing loop, e.g.,\n   * \"while (output_scanline < output_height)\".\n   */\n  JDIMENSION output_scanline;\t/* 0 .. output_height-1  */\n\n  /* Current input scan number and number of iMCU rows completed in scan.\n   * These indicate the progress of the decompressor input side.\n   */\n  int input_scan_number;\t/* Number of SOS markers seen so far */\n  JDIMENSION input_iMCU_row;\t/* Number of iMCU rows completed */\n\n  /* The \"output scan number\" is the notional scan being displayed by the\n   * output side.  The decompressor will not allow output scan/row number\n   * to get ahead of input scan/row, but it can fall arbitrarily far behind.\n   */\n  int output_scan_number;\t/* Nominal scan number being displayed */\n  JDIMENSION output_iMCU_row;\t/* Number of iMCU rows read */\n\n  /* Current progression status.  coef_bits[c][i] indicates the precision\n   * with which component c's DCT coefficient i (in zigzag order) is known.\n   * It is -1 when no data has yet been received, otherwise it is the point\n   * transform (shift) value for the most recent scan of the coefficient\n   * (thus, 0 at completion of the progression).\n   * This pointer is NULL when reading a non-progressive file.\n   */\n  int (*coef_bits)[DCTSIZE2];\t/* -1 or current Al value for each coef */\n\n  /* Internal JPEG parameters --- the application usually need not look at\n   * these fields.  Note that the decompressor output side may not use\n   * any parameters that can change between scans.\n   */\n\n  /* Quantization and Huffman tables are carried forward across input\n   * datastreams when processing abbreviated JPEG datastreams.\n   */\n\n  JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];\n  /* ptrs to coefficient quantization tables, or NULL if not defined */\n\n  JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];\n  JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];\n  /* ptrs to Huffman coding tables, or NULL if not defined */\n\n  /* These parameters are never carried across datastreams, since they\n   * are given in SOF/SOS markers or defined to be reset by SOI.\n   */\n\n  int data_precision;\t\t/* bits of precision in image data */\n\n  jpeg_component_info * comp_info;\n  /* comp_info[i] describes component that appears i'th in SOF */\n\n  boolean is_baseline;\t\t/* TRUE if Baseline SOF0 encountered */\n  boolean progressive_mode;\t/* TRUE if SOFn specifies progressive mode */\n  boolean arith_code;\t\t/* TRUE=arithmetic coding, FALSE=Huffman */\n\n  UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */\n  UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */\n  UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */\n\n  unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */\n\n  /* These fields record data obtained from optional markers recognized by\n   * the JPEG library.\n   */\n  boolean saw_JFIF_marker;\t/* TRUE iff a JFIF APP0 marker was found */\n  /* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */\n  UINT8 JFIF_major_version;\t/* JFIF version number */\n  UINT8 JFIF_minor_version;\n  UINT8 density_unit;\t\t/* JFIF code for pixel size units */\n  UINT16 X_density;\t\t/* Horizontal pixel density */\n  UINT16 Y_density;\t\t/* Vertical pixel density */\n  boolean saw_Adobe_marker;\t/* TRUE iff an Adobe APP14 marker was found */\n  UINT8 Adobe_transform;\t/* Color transform code from Adobe marker */\n\n  J_COLOR_TRANSFORM color_transform;\n  /* Color transform identifier derived from LSE marker, otherwise zero */\n\n  boolean CCIR601_sampling;\t/* TRUE=first samples are cosited */\n\n  /* Aside from the specific data retained from APPn markers known to the\n   * library, the uninterpreted contents of any or all APPn and COM markers\n   * can be saved in a list for examination by the application.\n   */\n  jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */\n\n  /* Remaining fields are known throughout decompressor, but generally\n   * should not be touched by a surrounding application.\n   */\n\n  /*\n   * These fields are computed during decompression startup\n   */\n  int max_h_samp_factor;\t/* largest h_samp_factor */\n  int max_v_samp_factor;\t/* largest v_samp_factor */\n\n  int min_DCT_h_scaled_size;\t/* smallest DCT_h_scaled_size of any component */\n  int min_DCT_v_scaled_size;\t/* smallest DCT_v_scaled_size of any component */\n\n  JDIMENSION total_iMCU_rows;\t/* # of iMCU rows in image */\n  /* The coefficient controller's input and output progress is measured in\n   * units of \"iMCU\" (interleaved MCU) rows.  These are the same as MCU rows\n   * in fully interleaved JPEG scans, but are used whether the scan is\n   * interleaved or not.  We define an iMCU row as v_samp_factor DCT block\n   * rows of each component.  Therefore, the IDCT output contains\n   * v_samp_factor*DCT_v_scaled_size sample rows of a component per iMCU row.\n   */\n\n  JSAMPLE * sample_range_limit; /* table for fast range-limiting */\n\n  /*\n   * These fields are valid during any one scan.\n   * They describe the components and MCUs actually appearing in the scan.\n   * Note that the decompressor output side must not use these fields.\n   */\n  int comps_in_scan;\t\t/* # of JPEG components in this scan */\n  jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];\n  /* *cur_comp_info[i] describes component that appears i'th in SOS */\n\n  JDIMENSION MCUs_per_row;\t/* # of MCUs across the image */\n  JDIMENSION MCU_rows_in_scan;\t/* # of MCU rows in the image */\n\n  int blocks_in_MCU;\t\t/* # of DCT blocks per MCU */\n  int MCU_membership[D_MAX_BLOCKS_IN_MCU];\n  /* MCU_membership[i] is index in cur_comp_info of component owning */\n  /* i'th block in an MCU */\n\n  int Ss, Se, Ah, Al;\t\t/* progressive JPEG parameters for scan */\n\n  /* These fields are derived from Se of first SOS marker.\n   */\n  int block_size;\t\t/* the basic DCT block size: 1..16 */\n  const int * natural_order; /* natural-order position array for entropy decode */\n  int lim_Se;\t\t\t/* min( Se, DCTSIZE2-1 ) for entropy decode */\n\n  /* This field is shared between entropy decoder and marker parser.\n   * It is either zero or the code of a JPEG marker that has been\n   * read from the data source, but has not yet been processed.\n   */\n  int unread_marker;\n\n  /*\n   * Links to decompression subobjects (methods, private variables of modules)\n   */\n  struct jpeg_decomp_master * master;\n  struct jpeg_d_main_controller * main;\n  struct jpeg_d_coef_controller * coef;\n  struct jpeg_d_post_controller * post;\n  struct jpeg_input_controller * inputctl;\n  struct jpeg_marker_reader * marker;\n  struct jpeg_entropy_decoder * entropy;\n  struct jpeg_inverse_dct * idct;\n  struct jpeg_upsampler * upsample;\n  struct jpeg_color_deconverter * cconvert;\n  struct jpeg_color_quantizer * cquantize;\n};\n\n\n/* \"Object\" declarations for JPEG modules that may be supplied or called\n * directly by the surrounding application.\n * As with all objects in the JPEG library, these structs only define the\n * publicly visible methods and state variables of a module.  Additional\n * private fields may exist after the public ones.\n */\n\n\n/* Error handler object */\n\nstruct jpeg_error_mgr {\n  /* Error exit handler: does not return to caller */\n  JMETHOD(noreturn_t, error_exit, (j_common_ptr cinfo));\n  /* Conditionally emit a trace or warning message */\n  JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));\n  /* Routine that actually outputs a trace or error message */\n  JMETHOD(void, output_message, (j_common_ptr cinfo));\n  /* Format a message string for the most recent JPEG error or message */\n  JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));\n#define JMSG_LENGTH_MAX  200\t/* recommended size of format_message buffer */\n  /* Reset error state variables at start of a new image */\n  JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));\n  \n  /* The message ID code and any parameters are saved here.\n   * A message can have one string parameter or up to 8 int parameters.\n   */\n  int msg_code;\n#define JMSG_STR_PARM_MAX  80\n  union {\n    int i[8];\n    char s[JMSG_STR_PARM_MAX];\n  } msg_parm;\n  \n  /* Standard state variables for error facility */\n  \n  int trace_level;\t\t/* max msg_level that will be displayed */\n  \n  /* For recoverable corrupt-data errors, we emit a warning message,\n   * but keep going unless emit_message chooses to abort.  emit_message\n   * should count warnings in num_warnings.  The surrounding application\n   * can check for bad data by seeing if num_warnings is nonzero at the\n   * end of processing.\n   */\n  long num_warnings;\t\t/* number of corrupt-data warnings */\n\n  /* These fields point to the table(s) of error message strings.\n   * An application can change the table pointer to switch to a different\n   * message list (typically, to change the language in which errors are\n   * reported).  Some applications may wish to add additional error codes\n   * that will be handled by the JPEG library error mechanism; the second\n   * table pointer is used for this purpose.\n   *\n   * First table includes all errors generated by JPEG library itself.\n   * Error code 0 is reserved for a \"no such error string\" message.\n   */\n  const char * const * jpeg_message_table; /* Library errors */\n  int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */\n  /* Second table can be added by application (see cjpeg/djpeg for example).\n   * It contains strings numbered first_addon_message..last_addon_message.\n   */\n  const char * const * addon_message_table; /* Non-library errors */\n  int first_addon_message;\t/* code for first string in addon table */\n  int last_addon_message;\t/* code for last string in addon table */\n};\n\n\n/* Progress monitor object */\n\nstruct jpeg_progress_mgr {\n  JMETHOD(void, progress_monitor, (j_common_ptr cinfo));\n\n  long pass_counter;\t\t/* work units completed in this pass */\n  long pass_limit;\t\t/* total number of work units in this pass */\n  int completed_passes;\t\t/* passes completed so far */\n  int total_passes;\t\t/* total number of passes expected */\n};\n\n\n/* Data destination object for compression */\n\nstruct jpeg_destination_mgr {\n  JOCTET * next_output_byte;\t/* => next byte to write in buffer */\n  size_t free_in_buffer;\t/* # of byte spaces remaining in buffer */\n\n  JMETHOD(void, init_destination, (j_compress_ptr cinfo));\n  JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));\n  JMETHOD(void, term_destination, (j_compress_ptr cinfo));\n};\n\n\n/* Data source object for decompression */\n\nstruct jpeg_source_mgr {\n  const JOCTET * next_input_byte; /* => next byte to read from buffer */\n  size_t bytes_in_buffer;\t/* # of bytes remaining in buffer */\n\n  JMETHOD(void, init_source, (j_decompress_ptr cinfo));\n  JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));\n  JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));\n  JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));\n  JMETHOD(void, term_source, (j_decompress_ptr cinfo));\n};\n\n\n/* Memory manager object.\n * Allocates \"small\" objects (a few K total), \"large\" objects (tens of K),\n * and \"really big\" objects (virtual arrays with backing store if needed).\n * The memory manager does not allow individual objects to be freed; rather,\n * each created object is assigned to a pool, and whole pools can be freed\n * at once.  This is faster and more convenient than remembering exactly what\n * to free, especially where malloc()/free() are not too speedy.\n * NB: alloc routines never return NULL.  They exit to error_exit if not\n * successful.\n */\n\n#define JPOOL_PERMANENT\t0\t/* lasts until master record is destroyed */\n#define JPOOL_IMAGE\t1\t/* lasts until done with image/datastream */\n#define JPOOL_NUMPOOLS\t2\n\ntypedef struct jvirt_sarray_control * jvirt_sarray_ptr;\ntypedef struct jvirt_barray_control * jvirt_barray_ptr;\n\n\nstruct jpeg_memory_mgr {\n  /* Method pointers */\n  JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,\n\t\t\t\tsize_t sizeofobject));\n  JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,\n\t\t\t\t     size_t sizeofobject));\n  JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,\n\t\t\t\t     JDIMENSION samplesperrow,\n\t\t\t\t     JDIMENSION numrows));\n  JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,\n\t\t\t\t      JDIMENSION blocksperrow,\n\t\t\t\t      JDIMENSION numrows));\n  JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,\n\t\t\t\t\t\t  int pool_id,\n\t\t\t\t\t\t  boolean pre_zero,\n\t\t\t\t\t\t  JDIMENSION samplesperrow,\n\t\t\t\t\t\t  JDIMENSION numrows,\n\t\t\t\t\t\t  JDIMENSION maxaccess));\n  JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,\n\t\t\t\t\t\t  int pool_id,\n\t\t\t\t\t\t  boolean pre_zero,\n\t\t\t\t\t\t  JDIMENSION blocksperrow,\n\t\t\t\t\t\t  JDIMENSION numrows,\n\t\t\t\t\t\t  JDIMENSION maxaccess));\n  JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));\n  JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,\n\t\t\t\t\t   jvirt_sarray_ptr ptr,\n\t\t\t\t\t   JDIMENSION start_row,\n\t\t\t\t\t   JDIMENSION num_rows,\n\t\t\t\t\t   boolean writable));\n  JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,\n\t\t\t\t\t    jvirt_barray_ptr ptr,\n\t\t\t\t\t    JDIMENSION start_row,\n\t\t\t\t\t    JDIMENSION num_rows,\n\t\t\t\t\t    boolean writable));\n  JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));\n  JMETHOD(void, self_destruct, (j_common_ptr cinfo));\n\n  /* Limit on memory allocation for this JPEG object.  (Note that this is\n   * merely advisory, not a guaranteed maximum; it only affects the space\n   * used for virtual-array buffers.)  May be changed by outer application\n   * after creating the JPEG object.\n   */\n  long max_memory_to_use;\n\n  /* Maximum allocation request accepted by alloc_large. */\n  long max_alloc_chunk;\n};\n\n\n/* Routine signature for application-supplied marker processing methods.\n * Need not pass marker code since it is stored in cinfo->unread_marker.\n */\ntypedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));\n\n\n/* Declarations for routines called by application.\n * The JPP macro hides prototype parameters from compilers that can't cope.\n * Note JPP requires double parentheses.\n */\n\n#ifdef HAVE_PROTOTYPES\n#define JPP(arglist)\targlist\n#else\n#define JPP(arglist)\t()\n#endif\n\n\n/* Short forms of external names for systems with brain-damaged linkers.\n * We shorten external names to be unique in the first six letters, which\n * is good enough for all known systems.\n * (If your compiler itself needs names to be unique in less than 15 \n * characters, you are out of luck.  Get a better compiler.)\n */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jpeg_std_error\t\tjStdError\n#define jpeg_CreateCompress\tjCreaCompress\n#define jpeg_CreateDecompress\tjCreaDecompress\n#define jpeg_destroy_compress\tjDestCompress\n#define jpeg_destroy_decompress\tjDestDecompress\n#define jpeg_stdio_dest\t\tjStdDest\n#define jpeg_stdio_src\t\tjStdSrc\n#define jpeg_mem_dest\t\tjMemDest\n#define jpeg_mem_src\t\tjMemSrc\n#define jpeg_set_defaults\tjSetDefaults\n#define jpeg_set_colorspace\tjSetColorspace\n#define jpeg_default_colorspace\tjDefColorspace\n#define jpeg_set_quality\tjSetQuality\n#define jpeg_set_linear_quality\tjSetLQuality\n#define jpeg_default_qtables\tjDefQTables\n#define jpeg_add_quant_table\tjAddQuantTable\n#define jpeg_quality_scaling\tjQualityScaling\n#define jpeg_simple_progression\tjSimProgress\n#define jpeg_suppress_tables\tjSuppressTables\n#define jpeg_alloc_quant_table\tjAlcQTable\n#define jpeg_alloc_huff_table\tjAlcHTable\n#define jpeg_start_compress\tjStrtCompress\n#define jpeg_write_scanlines\tjWrtScanlines\n#define jpeg_finish_compress\tjFinCompress\n#define jpeg_calc_jpeg_dimensions\tjCjpegDimensions\n#define jpeg_write_raw_data\tjWrtRawData\n#define jpeg_write_marker\tjWrtMarker\n#define jpeg_write_m_header\tjWrtMHeader\n#define jpeg_write_m_byte\tjWrtMByte\n#define jpeg_write_tables\tjWrtTables\n#define jpeg_read_header\tjReadHeader\n#define jpeg_start_decompress\tjStrtDecompress\n#define jpeg_read_scanlines\tjReadScanlines\n#define jpeg_finish_decompress\tjFinDecompress\n#define jpeg_read_raw_data\tjReadRawData\n#define jpeg_has_multiple_scans\tjHasMultScn\n#define jpeg_start_output\tjStrtOutput\n#define jpeg_finish_output\tjFinOutput\n#define jpeg_input_complete\tjInComplete\n#define jpeg_new_colormap\tjNewCMap\n#define jpeg_consume_input\tjConsumeInput\n#define jpeg_core_output_dimensions\tjCoreDimensions\n#define jpeg_calc_output_dimensions\tjCalcDimensions\n#define jpeg_save_markers\tjSaveMarkers\n#define jpeg_set_marker_processor\tjSetMarker\n#define jpeg_read_coefficients\tjReadCoefs\n#define jpeg_write_coefficients\tjWrtCoefs\n#define jpeg_copy_critical_parameters\tjCopyCrit\n#define jpeg_abort_compress\tjAbrtCompress\n#define jpeg_abort_decompress\tjAbrtDecompress\n#define jpeg_abort\t\tjAbort\n#define jpeg_destroy\t\tjDestroy\n#define jpeg_resync_to_restart\tjResyncRestart\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n\n/* Default error-management setup */\nEXTERN(struct jpeg_error_mgr *) jpeg_std_error\n\tJPP((struct jpeg_error_mgr * err));\n\n/* Initialization of JPEG compression objects.\n * jpeg_create_compress() and jpeg_create_decompress() are the exported\n * names that applications should call.  These expand to calls on\n * jpeg_CreateCompress and jpeg_CreateDecompress with additional information\n * passed for version mismatch checking.\n * NB: you must set up the error-manager BEFORE calling jpeg_create_xxx.\n */\n#define jpeg_create_compress(cinfo) \\\n    jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \\\n\t\t\t(size_t) sizeof(struct jpeg_compress_struct))\n#define jpeg_create_decompress(cinfo) \\\n    jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \\\n\t\t\t  (size_t) sizeof(struct jpeg_decompress_struct))\nEXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,\n\t\t\t\t      int version, size_t structsize));\nEXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,\n\t\t\t\t\tint version, size_t structsize));\n/* Destruction of JPEG compression objects */\nEXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));\nEXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));\n\n/* Standard data source and destination managers: stdio streams. */\n/* Caller is responsible for opening the file before and closing after. */\nEXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));\nEXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));\n\n/* Data source and destination managers: memory buffers. */\nEXTERN(void) jpeg_mem_dest JPP((j_compress_ptr cinfo,\n\t\t\t       unsigned char ** outbuffer,\n\t\t\t       unsigned long * outsize));\nEXTERN(void) jpeg_mem_src JPP((j_decompress_ptr cinfo,\n\t\t\t      const unsigned char * inbuffer,\n\t\t\t      unsigned long insize));\n\n/* Default parameter setup for compression */\nEXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));\n/* Compression parameter setup aids */\nEXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,\n\t\t\t\t      J_COLOR_SPACE colorspace));\nEXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));\nEXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,\n\t\t\t\t   boolean force_baseline));\nEXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,\n\t\t\t\t\t  int scale_factor,\n\t\t\t\t\t  boolean force_baseline));\nEXTERN(void) jpeg_default_qtables JPP((j_compress_ptr cinfo,\n\t\t\t\t       boolean force_baseline));\nEXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,\n\t\t\t\t       const unsigned int *basic_table,\n\t\t\t\t       int scale_factor,\n\t\t\t\t       boolean force_baseline));\nEXTERN(int) jpeg_quality_scaling JPP((int quality));\nEXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));\nEXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,\n\t\t\t\t       boolean suppress));\nEXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));\nEXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));\n\n/* Main entry points for compression */\nEXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,\n\t\t\t\t      boolean write_all_tables));\nEXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,\n\t\t\t\t\t     JSAMPARRAY scanlines,\n\t\t\t\t\t     JDIMENSION num_lines));\nEXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));\n\n/* Precalculate JPEG dimensions for current compression parameters. */\nEXTERN(void) jpeg_calc_jpeg_dimensions JPP((j_compress_ptr cinfo));\n\n/* Replaces jpeg_write_scanlines when writing raw downsampled data. */\nEXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,\n\t\t\t\t\t    JSAMPIMAGE data,\n\t\t\t\t\t    JDIMENSION num_lines));\n\n/* Write a special marker.  See libjpeg.txt concerning safe usage. */\nEXTERN(void) jpeg_write_marker\n\tJPP((j_compress_ptr cinfo, int marker,\n\t     const JOCTET * dataptr, unsigned int datalen));\n/* Same, but piecemeal. */\nEXTERN(void) jpeg_write_m_header\n\tJPP((j_compress_ptr cinfo, int marker, unsigned int datalen));\nEXTERN(void) jpeg_write_m_byte\n\tJPP((j_compress_ptr cinfo, int val));\n\n/* Alternate compression function: just write an abbreviated table file */\nEXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));\n\n/* Decompression startup: read start of JPEG datastream to see what's there */\nEXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,\n\t\t\t\t  boolean require_image));\n/* Return value is one of: */\n#define JPEG_SUSPENDED\t\t0 /* Suspended due to lack of input data */\n#define JPEG_HEADER_OK\t\t1 /* Found valid image datastream */\n#define JPEG_HEADER_TABLES_ONLY\t2 /* Found valid table-specs-only datastream */\n/* If you pass require_image = TRUE (normal case), you need not check for\n * a TABLES_ONLY return code; an abbreviated file will cause an error exit.\n * JPEG_SUSPENDED is only possible if you use a data source module that can\n * give a suspension return (the stdio source module doesn't).\n */\n\n/* Main entry points for decompression */\nEXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));\nEXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t    JSAMPARRAY scanlines,\n\t\t\t\t\t    JDIMENSION max_lines));\nEXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));\n\n/* Replaces jpeg_read_scanlines when reading raw downsampled data. */\nEXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t   JSAMPIMAGE data,\n\t\t\t\t\t   JDIMENSION max_lines));\n\n/* Additional entry points for buffered-image mode. */\nEXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));\nEXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,\n\t\t\t\t       int scan_number));\nEXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));\nEXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));\nEXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));\nEXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));\n/* Return value is one of: */\n/* #define JPEG_SUSPENDED\t0    Suspended due to lack of input data */\n#define JPEG_REACHED_SOS\t1 /* Reached start of new scan */\n#define JPEG_REACHED_EOI\t2 /* Reached end of image */\n#define JPEG_ROW_COMPLETED\t3 /* Completed one iMCU row */\n#define JPEG_SCAN_COMPLETED\t4 /* Completed last iMCU row of a scan */\n\n/* Precalculate output dimensions for current decompression parameters. */\nEXTERN(void) jpeg_core_output_dimensions JPP((j_decompress_ptr cinfo));\nEXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));\n\n/* Control saving of COM and APPn markers into marker_list. */\nEXTERN(void) jpeg_save_markers\n\tJPP((j_decompress_ptr cinfo, int marker_code,\n\t     unsigned int length_limit));\n\n/* Install a special processing method for COM or APPn markers. */\nEXTERN(void) jpeg_set_marker_processor\n\tJPP((j_decompress_ptr cinfo, int marker_code,\n\t     jpeg_marker_parser_method routine));\n\n/* Read or write raw DCT coefficients --- useful for lossless transcoding. */\nEXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));\nEXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,\n\t\t\t\t\t  jvirt_barray_ptr * coef_arrays));\nEXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,\n\t\t\t\t\t\tj_compress_ptr dstinfo));\n\n/* If you choose to abort compression or decompression before completing\n * jpeg_finish_(de)compress, then you need to clean up to release memory,\n * temporary files, etc.  You can just call jpeg_destroy_(de)compress\n * if you're done with the JPEG object, but if you want to clean it up and\n * reuse it, call this:\n */\nEXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));\nEXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));\n\n/* Generic versions of jpeg_abort and jpeg_destroy that work on either\n * flavor of JPEG object.  These may be more convenient in some places.\n */\nEXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));\nEXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));\n\n/* Default restart-marker-resync procedure for use by data source modules */\nEXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,\n\t\t\t\t\t    int desired));\n\n\n/* These marker codes are exported since applications and data source modules\n * are likely to want to use them.\n */\n\n#define JPEG_RST0\t0xD0\t/* RST0 marker code */\n#define JPEG_EOI\t0xD9\t/* EOI marker code */\n#define JPEG_APP0\t0xE0\t/* APP0 marker code */\n#define JPEG_COM\t0xFE\t/* COM marker code */\n\n\n/* If we have a brain-damaged compiler that emits warnings (or worse, errors)\n * for structure definitions that are never filled in, keep it quiet by\n * supplying dummy definitions for the various substructures.\n */\n\n#ifdef INCOMPLETE_TYPES_BROKEN\n#ifndef JPEG_INTERNALS\t\t/* will be defined in jpegint.h */\nstruct jvirt_sarray_control { long dummy; };\nstruct jvirt_barray_control { long dummy; };\nstruct jpeg_comp_master { long dummy; };\nstruct jpeg_c_main_controller { long dummy; };\nstruct jpeg_c_prep_controller { long dummy; };\nstruct jpeg_c_coef_controller { long dummy; };\nstruct jpeg_marker_writer { long dummy; };\nstruct jpeg_color_converter { long dummy; };\nstruct jpeg_downsampler { long dummy; };\nstruct jpeg_forward_dct { long dummy; };\nstruct jpeg_entropy_encoder { long dummy; };\nstruct jpeg_decomp_master { long dummy; };\nstruct jpeg_d_main_controller { long dummy; };\nstruct jpeg_d_coef_controller { long dummy; };\nstruct jpeg_d_post_controller { long dummy; };\nstruct jpeg_input_controller { long dummy; };\nstruct jpeg_marker_reader { long dummy; };\nstruct jpeg_entropy_decoder { long dummy; };\nstruct jpeg_inverse_dct { long dummy; };\nstruct jpeg_upsampler { long dummy; };\nstruct jpeg_color_deconverter { long dummy; };\nstruct jpeg_color_quantizer { long dummy; };\n#endif /* JPEG_INTERNALS */\n#endif /* INCOMPLETE_TYPES_BROKEN */\n\n\n/*\n * The JPEG library modules define JPEG_INTERNALS before including this file.\n * The internal structure declarations are read only when that is true.\n * Applications using the library should not include jpegint.h, but may wish\n * to include jerror.h.\n */\n\n#ifdef JPEG_INTERNALS\n#include \"jpegint.h\"\t\t/* fetch private declarations */\n#include \"jerror.h\"\t\t/* fetch error codes too */\n#endif\n\n#ifdef __cplusplus\n#ifndef DONT_USE_EXTERN_C\n}\n#endif\n#endif\n\n#endif /* JPEGLIB_H */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jpegtran.1",
    "content": ".TH JPEGTRAN 1 \"20 September 2015\"\n.SH NAME\njpegtran \\- lossless transformation of JPEG files\n.SH SYNOPSIS\n.B jpegtran\n[\n.I options\n]\n[\n.I filename\n]\n.LP\n.SH DESCRIPTION\n.LP\n.B jpegtran\nperforms various useful transformations of JPEG files.\nIt can translate the coded representation from one variant of JPEG to another,\nfor example from baseline JPEG to progressive JPEG or vice versa.  It can also\nperform some rearrangements of the image data, for example turning an image\nfrom landscape to portrait format by rotation.\n.PP\nFor EXIF files and JPEG files containing Exif data, you may prefer to use\n.B exiftran\ninstead.\n.PP\n.B jpegtran\nworks by rearranging the compressed data (DCT coefficients), without\never fully decoding the image.  Therefore, its transformations are lossless:\nthere is no image degradation at all, which would not be true if you used\n.B djpeg\nfollowed by\n.B cjpeg\nto accomplish the same conversion.  But by the same token,\n.B jpegtran\ncannot perform lossy operations such as changing the image quality.  However,\nwhile the image data is losslessly transformed, metadata can be removed.  See\nthe\n.B \\-copy\noption for specifics.\n.PP\n.B jpegtran\nreads the named JPEG/JFIF file, or the standard input if no file is\nnamed, and produces a JPEG/JFIF file on the standard output.\n.SH OPTIONS\nAll switch names may be abbreviated; for example,\n.B \\-optimize\nmay be written\n.B \\-opt\nor\n.BR \\-o .\nUpper and lower case are equivalent.\nBritish spellings are also accepted (e.g.,\n.BR \\-optimise ),\nthough for brevity these are not mentioned below.\n.PP\nTo specify the coded JPEG representation used in the output file,\n.B jpegtran\naccepts a subset of the switches recognized by\n.BR cjpeg :\n.TP\n.B \\-optimize\nPerform optimization of entropy encoding parameters.\n.TP\n.B \\-progressive\nCreate progressive JPEG file.\n.TP\n.BI \\-restart \" N\"\nEmit a JPEG restart marker every N MCU rows, or every N MCU blocks if \"B\" is\nattached to the number.\n.TP\n.B \\-arithmetic\nUse arithmetic coding.\n.TP\n.BI \\-scans \" file\"\nUse the scan script given in the specified text file.\n.PP\nSee\n.BR cjpeg (1)\nfor more details about these switches.\nIf you specify none of these switches, you get a plain baseline-JPEG output\nfile.  The quality setting and so forth are determined by the input file.\n.PP\nThe image can be losslessly transformed by giving one of these switches:\n.TP\n.B \\-flip horizontal\nMirror image horizontally (left-right).\n.TP\n.B \\-flip vertical\nMirror image vertically (top-bottom).\n.TP\n.B \\-rotate 90\nRotate image 90 degrees clockwise.\n.TP\n.B \\-rotate 180\nRotate image 180 degrees.\n.TP\n.B \\-rotate 270\nRotate image 270 degrees clockwise (or 90 ccw).\n.TP\n.B \\-transpose\nTranspose image (across UL-to-LR axis).\n.TP\n.B \\-transverse\nTransverse transpose (across UR-to-LL axis).\n.IP\nThe transpose transformation has no restrictions regarding image dimensions.\nThe other transformations operate rather oddly if the image dimensions are not\na multiple of the iMCU size (usually 8 or 16 pixels), because they can only\ntransform complete blocks of DCT coefficient data in the desired way.\n.IP\n.BR jpegtran 's\ndefault behavior when transforming an odd-size image is designed\nto preserve exact reversibility and mathematical consistency of the\ntransformation set.  As stated, transpose is able to flip the entire image\narea.  Horizontal mirroring leaves any partial iMCU column at the right edge\nuntouched, but is able to flip all rows of the image.  Similarly, vertical\nmirroring leaves any partial iMCU row at the bottom edge untouched, but is\nable to flip all columns.  The other transforms can be built up as sequences\nof transpose and flip operations; for consistency, their actions on edge\npixels are defined to be the same as the end result of the corresponding\ntranspose-and-flip sequence.\n.IP\nFor practical use, you may prefer to discard any untransformable edge pixels\nrather than having a strange-looking strip along the right and/or bottom edges\nof a transformed image.  To do this, add the\n.B \\-trim\nswitch:\n.TP\n.B \\-trim\nDrop non-transformable edge blocks.\n.IP\nObviously, a transformation with\n.B \\-trim\nis not reversible, so strictly speaking\n.B jpegtran\nwith this switch is not lossless.  Also, the expected mathematical\nequivalences between the transformations no longer hold.  For example,\n.B \\-rot 270 -trim\ntrims only the bottom edge, but\n.B \\-rot 90 -trim\nfollowed by\n.B \\-rot 180 -trim\ntrims both edges.\n.IP\nIf you are only interested in perfect transformation, add the\n.B \\-perfect\nswitch:\n.TP\n.B \\-perfect\nFails with an error if the transformation is not perfect.\n.IP\nFor example you may want to do\n.IP\n.B (jpegtran \\-rot 90 -perfect\n.I foo.jpg\n.B || djpeg\n.I foo.jpg\n.B | pnmflip \\-r90 | cjpeg)\n.IP\nto do a perfect rotation if available or an approximated one if not.\n.PP\nWe also offer a lossless-crop option, which discards data outside a given\nimage region but losslessly preserves what is inside.  Like the rotate and\nflip transforms, lossless crop is restricted by the current JPEG format: the\nupper left corner of the selected region must fall on an iMCU boundary.  If\nthis does not hold for the given crop parameters, we silently move the upper\nleft corner up and/or left to make it so, simultaneously increasing the\nregion dimensions to keep the lower right crop corner unchanged.  (Thus, the\noutput image covers at least the requested region, but may cover more.)\nThe adjustment of the region dimensions may be optionally disabled by\nattaching an 'f' character (\"force\") to the width or height number.\n\nThe image can be losslessly cropped by giving the switch:\n.TP\n.B \\-crop WxH+X+Y\nCrop to a rectangular subarea of width W, height H starting at point X,Y.\n.PP\nA complementary lossless-wipe option is provided to discard (gray out) data\ninside a given image region while losslessly preserving what is outside:\n.TP\n.B \\-wipe WxH+X+Y\nWipe (gray out) a rectangular subarea of width W, height H starting at point\nX,Y.\n.PP\nOther not-strictly-lossless transformation switches are:\n.TP\n.B \\-grayscale\nForce grayscale output.\n.IP\nThis option discards the chrominance channels if the input image is YCbCr\n(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The\nluminance channel is preserved exactly, so this is a better method of reducing\nto grayscale than decompression, conversion, and recompression.  This switch\nis particularly handy for fixing a monochrome picture that was mistakenly\nencoded as a color JPEG.  (In such a case, the space savings from getting rid\nof the near-empty chroma channels won't be large; but the decoding time for\na grayscale JPEG is substantially less than that for a color JPEG.)\n.TP\n.BI \\-scale \" M/N\"\nScale the output image by a factor M/N.\n.IP\nCurrently supported scale factors are M/N with all M from 1 to 16, where N is\nthe source DCT size, which is 8 for baseline JPEG.  If the /N part is omitted,\nthen M specifies the DCT scaled size to be applied on the given input.  For\nbaseline JPEG this is equivalent to M/8 scaling, since the source DCT size\nfor baseline JPEG is 8.\n.B Caution:\nAn implementation of the JPEG SmartScale extension is required for this\nfeature.  SmartScale enabled JPEG is not yet widely implemented, so many\ndecoders will be unable to view a SmartScale extended JPEG file at all.\n.PP\n.B jpegtran\nalso recognizes these switches that control what to do with \"extra\" markers,\nsuch as comment blocks:\n.TP\n.B \\-copy none\nCopy no extra markers from source file.  This setting suppresses all\ncomments and other metadata in the source file.\n.TP\n.B \\-copy comments\nCopy only comment markers.  This setting copies comments from the source file,\nbut discards any other metadata.\n.TP\n.B \\-copy all\nCopy all extra markers.  This setting preserves metadata\nfound in the source file, such as JFIF thumbnails, Exif data, and Photoshop\nsettings.  In some files these extra markers can be sizable.  Note that this\noption will copy thumbnails as-is; they will not be transformed.\n.IP\nThe default behavior is\n.BR \"\\-copy comments\" .\n(Note: in IJG releases v6 and v6a,\n.B jpegtran\nalways did the equivalent of\n.BR \"\\-copy none\" .)\n.PP\nAdditional switches recognized by jpegtran are:\n.TP\n.BI \\-maxmemory \" N\"\nSet limit for amount of memory to use in processing large images.  Value is\nin thousands of bytes, or millions of bytes if \"M\" is attached to the\nnumber.  For example,\n.B \\-max 4m\nselects 4000000 bytes.  If more space is needed, temporary files will be used.\n.TP\n.BI \\-outfile \" name\"\nSend output image to the named file, not to standard output.\n.TP\n.B \\-verbose\nEnable debug printout.  More\n.BR \\-v 's\ngive more output.  Also, version information is printed at startup.\n.TP\n.B \\-debug\nSame as\n.BR \\-verbose .\n.SH EXAMPLES\n.LP\nThis example converts a baseline JPEG file to progressive form:\n.IP\n.B jpegtran \\-progressive\n.I foo.jpg\n.B >\n.I fooprog.jpg\n.PP\nThis example rotates an image 90 degrees clockwise, discarding any\nunrotatable edge pixels:\n.IP\n.B jpegtran \\-rot 90 -trim\n.I foo.jpg\n.B >\n.I foo90.jpg\n.SH ENVIRONMENT\n.TP\n.B JPEGMEM\nIf this environment variable is set, its value is the default memory limit.\nThe value is specified as described for the\n.B \\-maxmemory\nswitch.\n.B JPEGMEM\noverrides the default value specified when the program was compiled, and\nitself is overridden by an explicit\n.BR \\-maxmemory .\n.SH SEE ALSO\n.BR cjpeg (1),\n.BR djpeg (1),\n.BR rdjpgcom (1),\n.BR wrjpgcom (1)\n.br\nWallace, Gregory K.  \"The JPEG Still Picture Compression Standard\",\nCommunications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.\n.SH AUTHOR\nIndependent JPEG Group\n.SH BUGS\nThe transform options can't transform odd-size images perfectly.  Use\n.B \\-trim\nor\n.B \\-perfect\nif you don't like the results.\n.PP\nThe entire image is read into memory and then written out again, even in\ncases where this isn't really necessary.  Expect swapping on large images,\nespecially when using the more complex transform options.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jpegtran.c",
    "content": "/*\n * jpegtran.c\n *\n * Copyright (C) 1995-2013, Thomas G. Lane, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a command-line user interface for JPEG transcoding.\n * It is very similar to cjpeg.c, and partly to djpeg.c, but provides\n * lossless transcoding between different JPEG file formats.  It also\n * provides some lossless and sort-of-lossless transformations of JPEG data.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n#include \"transupp.h\"\t\t/* Support routines for jpegtran */\n#include \"jversion.h\"\t\t/* for version message */\n\n#ifdef USE_CCOMMAND\t\t/* command-line reader for Macintosh */\n#ifdef __MWERKS__\n#include <SIOUX.h>              /* Metrowerks needs this */\n#include <console.h>\t\t/* ... and this */\n#endif\n#ifdef THINK_C\n#include <console.h>\t\t/* Think declares it here */\n#endif\n#endif\n\n\n/*\n * Argument-parsing code.\n * The switch parser is designed to be useful with DOS-style command line\n * syntax, ie, intermixed switches and file names, where only the switches\n * to the left of a given file name affect processing of that file.\n * The main program in this file doesn't actually use this capability...\n */\n\n\nstatic const char * progname;\t/* program name for error messages */\nstatic char * outfilename;\t/* for -outfile switch */\nstatic char * scaleoption;\t/* -scale switch */\nstatic JCOPY_OPTION copyoption;\t/* -copy switch */\nstatic jpeg_transform_info transformoption; /* image transformation options */\n\n\nLOCAL(void)\nusage (void)\n/* complain about bad command line */\n{\n  fprintf(stderr, \"usage: %s [switches] \", progname);\n#ifdef TWO_FILE_COMMANDLINE\n  fprintf(stderr, \"inputfile outputfile\\n\");\n#else\n  fprintf(stderr, \"[inputfile]\\n\");\n#endif\n\n  fprintf(stderr, \"Switches (names may be abbreviated):\\n\");\n  fprintf(stderr, \"  -copy none     Copy no extra markers from source file\\n\");\n  fprintf(stderr, \"  -copy comments Copy only comment markers (default)\\n\");\n  fprintf(stderr, \"  -copy all      Copy all extra markers\\n\");\n#ifdef ENTROPY_OPT_SUPPORTED\n  fprintf(stderr, \"  -optimize      Optimize Huffman table (smaller file, but slow compression)\\n\");\n#endif\n#ifdef C_PROGRESSIVE_SUPPORTED\n  fprintf(stderr, \"  -progressive   Create progressive JPEG file\\n\");\n#endif\n  fprintf(stderr, \"Switches for modifying the image:\\n\");\n#if TRANSFORMS_SUPPORTED\n  fprintf(stderr, \"  -crop WxH+X+Y  Crop to a rectangular subarea\\n\");\n  fprintf(stderr, \"  -flip [horizontal|vertical]  Mirror image (left-right or top-bottom)\\n\");\n  fprintf(stderr, \"  -grayscale     Reduce to grayscale (omit color data)\\n\");\n  fprintf(stderr, \"  -perfect       Fail if there is non-transformable edge blocks\\n\");\n  fprintf(stderr, \"  -rotate [90|180|270]         Rotate image (degrees clockwise)\\n\");\n#endif\n  fprintf(stderr, \"  -scale M/N     Scale output image by fraction M/N, eg, 1/8\\n\");\n#if TRANSFORMS_SUPPORTED\n  fprintf(stderr, \"  -transpose     Transpose image\\n\");\n  fprintf(stderr, \"  -transverse    Transverse transpose image\\n\");\n  fprintf(stderr, \"  -trim          Drop non-transformable edge blocks\\n\");\n  fprintf(stderr, \"  -wipe WxH+X+Y  Wipe (gray out) a rectangular subarea\\n\");\n#endif\n  fprintf(stderr, \"Switches for advanced users:\\n\");\n#ifdef C_ARITH_CODING_SUPPORTED\n  fprintf(stderr, \"  -arithmetic    Use arithmetic coding\\n\");\n#endif\n  fprintf(stderr, \"  -restart N     Set restart interval in rows, or in blocks with B\\n\");\n  fprintf(stderr, \"  -maxmemory N   Maximum memory to use (in kbytes)\\n\");\n  fprintf(stderr, \"  -outfile name  Specify name for output file\\n\");\n  fprintf(stderr, \"  -verbose  or  -debug   Emit debug output\\n\");\n  fprintf(stderr, \"Switches for wizards:\\n\");\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n  fprintf(stderr, \"  -scans file    Create multi-scan JPEG per script file\\n\");\n#endif\n  exit(EXIT_FAILURE);\n}\n\n\nLOCAL(void)\nselect_transform (JXFORM_CODE transform)\n/* Silly little routine to detect multiple transform options,\n * which we can't handle.\n */\n{\n#if TRANSFORMS_SUPPORTED\n  if (transformoption.transform == JXFORM_NONE ||\n      transformoption.transform == transform) {\n    transformoption.transform = transform;\n  } else {\n    fprintf(stderr, \"%s: can only do one image transformation at a time\\n\",\n\t    progname);\n    usage();\n  }\n#else\n  fprintf(stderr, \"%s: sorry, image transformation was not compiled\\n\",\n\t  progname);\n  exit(EXIT_FAILURE);\n#endif\n}\n\n\nLOCAL(int)\nparse_switches (j_compress_ptr cinfo, int argc, char **argv,\n\t\tint last_file_arg_seen, boolean for_real)\n/* Parse optional switches.\n * Returns argv[] index of first file-name argument (== argc if none).\n * Any file names with indexes <= last_file_arg_seen are ignored;\n * they have presumably been processed in a previous iteration.\n * (Pass 0 for last_file_arg_seen on the first or only iteration.)\n * for_real is FALSE on the first (dummy) pass; we may skip any expensive\n * processing.\n */\n{\n  int argn;\n  char * arg;\n  boolean simple_progressive;\n  char * scansarg = NULL;\t/* saves -scans parm if any */\n\n  /* Set up default JPEG parameters. */\n  simple_progressive = FALSE;\n  outfilename = NULL;\n  scaleoption = NULL;\n  copyoption = JCOPYOPT_DEFAULT;\n  transformoption.transform = JXFORM_NONE;\n  transformoption.perfect = FALSE;\n  transformoption.trim = FALSE;\n  transformoption.force_grayscale = FALSE;\n  transformoption.crop = FALSE;\n  cinfo->err->trace_level = 0;\n\n  /* Scan command line options, adjust parameters */\n\n  for (argn = 1; argn < argc; argn++) {\n    arg = argv[argn];\n    if (*arg != '-') {\n      /* Not a switch, must be a file name argument */\n      if (argn <= last_file_arg_seen) {\n\toutfilename = NULL;\t/* -outfile applies to just one input file */\n\tcontinue;\t\t/* ignore this name if previously processed */\n      }\n      break;\t\t\t/* else done parsing switches */\n    }\n    arg++;\t\t\t/* advance past switch marker character */\n\n    if (keymatch(arg, \"arithmetic\", 1)) {\n      /* Use arithmetic coding. */\n#ifdef C_ARITH_CODING_SUPPORTED\n      cinfo->arith_code = TRUE;\n#else\n      fprintf(stderr, \"%s: sorry, arithmetic coding not supported\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"copy\", 2)) {\n      /* Select which extra markers to copy. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"none\", 1)) {\n\tcopyoption = JCOPYOPT_NONE;\n      } else if (keymatch(argv[argn], \"comments\", 1)) {\n\tcopyoption = JCOPYOPT_COMMENTS;\n      } else if (keymatch(argv[argn], \"all\", 1)) {\n\tcopyoption = JCOPYOPT_ALL;\n      } else\n\tusage();\n\n    } else if (keymatch(arg, \"crop\", 2)) {\n      /* Perform lossless cropping. */\n#if TRANSFORMS_SUPPORTED\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (transformoption.crop /* reject multiple crop/wipe requests */ ||\n\t  ! jtransform_parse_crop_spec(&transformoption, argv[argn])) {\n\tfprintf(stderr, \"%s: bogus -crop argument '%s'\\n\",\n\t\tprogname, argv[argn]);\n\texit(EXIT_FAILURE);\n      }\n#else\n      select_transform(JXFORM_NONE);\t/* force an error */\n#endif\n\n    } else if (keymatch(arg, \"debug\", 1) || keymatch(arg, \"verbose\", 1)) {\n      /* Enable debug printouts. */\n      /* On first -d, print version identification */\n      static boolean printed_version = FALSE;\n\n      if (! printed_version) {\n\tfprintf(stderr, \"Independent JPEG Group's JPEGTRAN, version %s\\n%s\\n\",\n\t\tJVERSION, JCOPYRIGHT);\n\tprinted_version = TRUE;\n      }\n      cinfo->err->trace_level++;\n\n    } else if (keymatch(arg, \"flip\", 1)) {\n      /* Mirror left-right or top-bottom. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"horizontal\", 1))\n\tselect_transform(JXFORM_FLIP_H);\n      else if (keymatch(argv[argn], \"vertical\", 1))\n\tselect_transform(JXFORM_FLIP_V);\n      else\n\tusage();\n\n    } else if (keymatch(arg, \"grayscale\", 1) || keymatch(arg, \"greyscale\",1)) {\n      /* Force to grayscale. */\n#if TRANSFORMS_SUPPORTED\n      transformoption.force_grayscale = TRUE;\n#else\n      select_transform(JXFORM_NONE);\t/* force an error */\n#endif\n\n    } else if (keymatch(arg, \"maxmemory\", 3)) {\n      /* Maximum memory in Kb (or Mb with 'm'). */\n      long lval;\n      char ch = 'x';\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%ld%c\", &lval, &ch) < 1)\n\tusage();\n      if (ch == 'm' || ch == 'M')\n\tlval *= 1000L;\n      cinfo->mem->max_memory_to_use = lval * 1000L;\n\n    } else if (keymatch(arg, \"optimize\", 1) || keymatch(arg, \"optimise\", 1)) {\n      /* Enable entropy parm optimization. */\n#ifdef ENTROPY_OPT_SUPPORTED\n      cinfo->optimize_coding = TRUE;\n#else\n      fprintf(stderr, \"%s: sorry, entropy optimization was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"outfile\", 4)) {\n      /* Set output file name. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      outfilename = argv[argn];\t/* save it away for later use */\n\n    } else if (keymatch(arg, \"perfect\", 2)) {\n      /* Fail if there is any partial edge MCUs that the transform can't\n       * handle. */\n      transformoption.perfect = TRUE;\n\n    } else if (keymatch(arg, \"progressive\", 2)) {\n      /* Select simple progressive mode. */\n#ifdef C_PROGRESSIVE_SUPPORTED\n      simple_progressive = TRUE;\n      /* We must postpone execution until num_components is known. */\n#else\n      fprintf(stderr, \"%s: sorry, progressive output was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"restart\", 1)) {\n      /* Restart interval in MCU rows (or in MCUs with 'b'). */\n      long lval;\n      char ch = 'x';\n\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (sscanf(argv[argn], \"%ld%c\", &lval, &ch) < 1)\n\tusage();\n      if (lval < 0 || lval > 65535L)\n\tusage();\n      if (ch == 'b' || ch == 'B') {\n\tcinfo->restart_interval = (unsigned int) lval;\n\tcinfo->restart_in_rows = 0; /* else prior '-restart n' overrides me */\n      } else {\n\tcinfo->restart_in_rows = (int) lval;\n\t/* restart_interval will be computed during startup */\n      }\n\n    } else if (keymatch(arg, \"rotate\", 2)) {\n      /* Rotate 90, 180, or 270 degrees (measured clockwise). */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (keymatch(argv[argn], \"90\", 2))\n\tselect_transform(JXFORM_ROT_90);\n      else if (keymatch(argv[argn], \"180\", 3))\n\tselect_transform(JXFORM_ROT_180);\n      else if (keymatch(argv[argn], \"270\", 3))\n\tselect_transform(JXFORM_ROT_270);\n      else\n\tusage();\n\n    } else if (keymatch(arg, \"scale\", 4)) {\n      /* Scale the output image by a fraction M/N. */\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      scaleoption = argv[argn];\n      /* We must postpone processing until decompression startup. */\n\n    } else if (keymatch(arg, \"scans\", 1)) {\n      /* Set scan script. */\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      scansarg = argv[argn];\n      /* We must postpone reading the file in case -progressive appears. */\n#else\n      fprintf(stderr, \"%s: sorry, multi-scan output was not compiled\\n\",\n\t      progname);\n      exit(EXIT_FAILURE);\n#endif\n\n    } else if (keymatch(arg, \"transpose\", 1)) {\n      /* Transpose (across UL-to-LR axis). */\n      select_transform(JXFORM_TRANSPOSE);\n\n    } else if (keymatch(arg, \"transverse\", 6)) {\n      /* Transverse transpose (across UR-to-LL axis). */\n      select_transform(JXFORM_TRANSVERSE);\n\n    } else if (keymatch(arg, \"trim\", 3)) {\n      /* Trim off any partial edge MCUs that the transform can't handle. */\n      transformoption.trim = TRUE;\n\n    } else if (keymatch(arg, \"wipe\", 1)) {\n#if TRANSFORMS_SUPPORTED\n      if (++argn >= argc)\t/* advance to next argument */\n\tusage();\n      if (transformoption.crop /* reject multiple crop/wipe requests */ ||\n\t  ! jtransform_parse_crop_spec(&transformoption, argv[argn])) {\n\tfprintf(stderr, \"%s: bogus -wipe argument '%s'\\n\",\n\t\tprogname, argv[argn]);\n\texit(EXIT_FAILURE);\n      }\n      select_transform(JXFORM_WIPE);\n#else\n      select_transform(JXFORM_NONE);\t/* force an error */\n#endif\n\n    } else {\n      usage();\t\t\t/* bogus switch */\n    }\n  }\n\n  /* Post-switch-scanning cleanup */\n\n  if (for_real) {\n\n#ifdef C_PROGRESSIVE_SUPPORTED\n    if (simple_progressive)\t/* process -progressive; -scans can override */\n      jpeg_simple_progression(cinfo);\n#endif\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n    if (scansarg != NULL)\t/* process -scans if it was present */\n      if (! read_scan_script(cinfo, scansarg))\n\tusage();\n#endif\n  }\n\n  return argn;\t\t\t/* return index of next arg (file name) */\n}\n\n\n/*\n * The main program.\n */\n\nint\nmain (int argc, char **argv)\n{\n  struct jpeg_decompress_struct srcinfo;\n  struct jpeg_compress_struct dstinfo;\n  struct jpeg_error_mgr jsrcerr, jdsterr;\n#ifdef PROGRESS_REPORT\n  struct cdjpeg_progress_mgr progress;\n#endif\n  jvirt_barray_ptr * src_coef_arrays;\n  jvirt_barray_ptr * dst_coef_arrays;\n  int file_index;\n  /* We assume all-in-memory processing and can therefore use only a\n   * single file pointer for sequential input and output operation. \n   */\n  FILE * fp;\n\n  /* On Mac, fetch a command line. */\n#ifdef USE_CCOMMAND\n  argc = ccommand(&argv);\n#endif\n\n  progname = argv[0];\n  if (progname == NULL || progname[0] == 0)\n    progname = \"jpegtran\";\t/* in case C library doesn't provide it */\n\n  /* Initialize the JPEG decompression object with default error handling. */\n  srcinfo.err = jpeg_std_error(&jsrcerr);\n  jpeg_create_decompress(&srcinfo);\n  /* Initialize the JPEG compression object with default error handling. */\n  dstinfo.err = jpeg_std_error(&jdsterr);\n  jpeg_create_compress(&dstinfo);\n\n  /* Now safe to enable signal catcher.\n   * Note: we assume only the decompression object will have virtual arrays.\n   */\n#ifdef NEED_SIGNAL_CATCHER\n  enable_signal_catcher((j_common_ptr) &srcinfo);\n#endif\n\n  /* Scan command line to find file names.\n   * It is convenient to use just one switch-parsing routine, but the switch\n   * values read here are mostly ignored; we will rescan the switches after\n   * opening the input file.  Also note that most of the switches affect the\n   * destination JPEG object, so we parse into that and then copy over what\n   * needs to affects the source too.\n   */\n\n  file_index = parse_switches(&dstinfo, argc, argv, 0, FALSE);\n  jsrcerr.trace_level = jdsterr.trace_level;\n  srcinfo.mem->max_memory_to_use = dstinfo.mem->max_memory_to_use;\n\n#ifdef TWO_FILE_COMMANDLINE\n  /* Must have either -outfile switch or explicit output file name */\n  if (outfilename == NULL) {\n    if (file_index != argc-2) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n    outfilename = argv[file_index+1];\n  } else {\n    if (file_index != argc-1) {\n      fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t      progname);\n      usage();\n    }\n  }\n#else\n  /* Unix style: expect zero or one file name */\n  if (file_index < argc-1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Open the input file. */\n  if (file_index < argc) {\n    if ((fp = fopen(argv[file_index], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s for reading\\n\", progname, argv[file_index]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n    fp = read_stdin();\n  }\n\n#ifdef PROGRESS_REPORT\n  start_progress_monitor((j_common_ptr) &dstinfo, &progress);\n#endif\n\n  /* Specify data source for decompression */\n  jpeg_stdio_src(&srcinfo, fp);\n\n  /* Enable saving of extra markers that we want to copy */\n  jcopy_markers_setup(&srcinfo, copyoption);\n\n  /* Read file header */\n  (void) jpeg_read_header(&srcinfo, TRUE);\n\n  /* Adjust default decompression parameters */\n  if (scaleoption != NULL)\n    if (sscanf(scaleoption, \"%u/%u\",\n\t&srcinfo.scale_num, &srcinfo.scale_denom) < 1)\n      usage();\n\n  /* Any space needed by a transform option must be requested before\n   * jpeg_read_coefficients so that memory allocation will be done right.\n   */\n#if TRANSFORMS_SUPPORTED\n  /* Fail right away if -perfect is given and transformation is not perfect.\n   */\n  if (!jtransform_request_workspace(&srcinfo, &transformoption)) {\n    fprintf(stderr, \"%s: transformation is not perfect\\n\", progname);\n    exit(EXIT_FAILURE);\n  }\n#endif\n\n  /* Read source file as DCT coefficients */\n  src_coef_arrays = jpeg_read_coefficients(&srcinfo);\n\n  /* Initialize destination compression parameters from source values */\n  jpeg_copy_critical_parameters(&srcinfo, &dstinfo);\n\n  /* Adjust destination parameters if required by transform options;\n   * also find out which set of coefficient arrays will hold the output.\n   */\n#if TRANSFORMS_SUPPORTED\n  dst_coef_arrays = jtransform_adjust_parameters(&srcinfo, &dstinfo,\n\t\t\t\t\t\t src_coef_arrays,\n\t\t\t\t\t\t &transformoption);\n#else\n  dst_coef_arrays = src_coef_arrays;\n#endif\n\n  /* Close input file, if we opened it.\n   * Note: we assume that jpeg_read_coefficients consumed all input\n   * until JPEG_REACHED_EOI, and that jpeg_finish_decompress will\n   * only consume more while (! cinfo->inputctl->eoi_reached).\n   * We cannot call jpeg_finish_decompress here since we still need the\n   * virtual arrays allocated from the source object for processing.\n   */\n  if (fp != stdin)\n    fclose(fp);\n\n  /* Open the output file. */\n  if (outfilename != NULL) {\n    if ((fp = fopen(outfilename, WRITE_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s for writing\\n\", progname, outfilename);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default output file is stdout */\n    fp = write_stdout();\n  }\n\n  /* Adjust default compression parameters by re-parsing the options */\n  file_index = parse_switches(&dstinfo, argc, argv, 0, TRUE);\n\n  /* Specify data destination for compression */\n  jpeg_stdio_dest(&dstinfo, fp);\n\n  /* Start compressor (note no image data is actually written here) */\n  jpeg_write_coefficients(&dstinfo, dst_coef_arrays);\n\n  /* Copy to the output file any extra markers that we want to preserve */\n  jcopy_markers_execute(&srcinfo, &dstinfo, copyoption);\n\n  /* Execute image transformation, if any */\n#if TRANSFORMS_SUPPORTED\n  jtransform_execute_transformation(&srcinfo, &dstinfo,\n\t\t\t\t    src_coef_arrays,\n\t\t\t\t    &transformoption);\n#endif\n\n  /* Finish compression and release memory */\n  jpeg_finish_compress(&dstinfo);\n  jpeg_destroy_compress(&dstinfo);\n  (void) jpeg_finish_decompress(&srcinfo);\n  jpeg_destroy_decompress(&srcinfo);\n\n  /* Close output file, if we opened it */\n  if (fp != stdout)\n    fclose(fp);\n\n#ifdef PROGRESS_REPORT\n  end_progress_monitor((j_common_ptr) &dstinfo);\n#endif\n\n  /* All done. */\n  exit(jsrcerr.num_warnings + jdsterr.num_warnings ?EXIT_WARNING:EXIT_SUCCESS);\n  return 0;\t\t\t/* suppress no-return-value warnings */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jquant1.c",
    "content": "/*\n * jquant1.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains 1-pass color quantization (color mapping) routines.\n * These routines provide mapping to a fixed color map using equally spaced\n * color values.  Optional Floyd-Steinberg or ordered dithering is available.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n#ifdef QUANT_1PASS_SUPPORTED\n\n\n/*\n * The main purpose of 1-pass quantization is to provide a fast, if not very\n * high quality, colormapped output capability.  A 2-pass quantizer usually\n * gives better visual quality; however, for quantized grayscale output this\n * quantizer is perfectly adequate.  Dithering is highly recommended with this\n * quantizer, though you can turn it off if you really want to.\n *\n * In 1-pass quantization the colormap must be chosen in advance of seeing the\n * image.  We use a map consisting of all combinations of Ncolors[i] color\n * values for the i'th component.  The Ncolors[] values are chosen so that\n * their product, the total number of colors, is no more than that requested.\n * (In most cases, the product will be somewhat less.)\n *\n * Since the colormap is orthogonal, the representative value for each color\n * component can be determined without considering the other components;\n * then these indexes can be combined into a colormap index by a standard\n * N-dimensional-array-subscript calculation.  Most of the arithmetic involved\n * can be precalculated and stored in the lookup table colorindex[].\n * colorindex[i][j] maps pixel value j in component i to the nearest\n * representative value (grid plane) for that component; this index is\n * multiplied by the array stride for component i, so that the\n * index of the colormap entry closest to a given pixel value is just\n *    sum( colorindex[component-number][pixel-component-value] )\n * Aside from being fast, this scheme allows for variable spacing between\n * representative values with no additional lookup cost.\n *\n * If gamma correction has been applied in color conversion, it might be wise\n * to adjust the color grid spacing so that the representative colors are\n * equidistant in linear space.  At this writing, gamma correction is not\n * implemented by jdcolor, so nothing is done here.\n */\n\n\n/* Declarations for ordered dithering.\n *\n * We use a standard 16x16 ordered dither array.  The basic concept of ordered\n * dithering is described in many references, for instance Dale Schumacher's\n * chapter II.2 of Graphics Gems II (James Arvo, ed. Academic Press, 1991).\n * In place of Schumacher's comparisons against a \"threshold\" value, we add a\n * \"dither\" value to the input pixel and then round the result to the nearest\n * output value.  The dither value is equivalent to (0.5 - threshold) times\n * the distance between output values.  For ordered dithering, we assume that\n * the output colors are equally spaced; if not, results will probably be\n * worse, since the dither may be too much or too little at a given point.\n *\n * The normal calculation would be to form pixel value + dither, range-limit\n * this to 0..MAXJSAMPLE, and then index into the colorindex table as usual.\n * We can skip the separate range-limiting step by extending the colorindex\n * table in both directions.\n */\n\n#define ODITHER_SIZE  16\t/* dimension of dither matrix */\n/* NB: if ODITHER_SIZE is not a power of 2, ODITHER_MASK uses will break */\n#define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE)\t/* # cells in matrix */\n#define ODITHER_MASK  (ODITHER_SIZE-1) /* mask for wrapping around counters */\n\ntypedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];\ntypedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];\n\nstatic const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {\n  /* Bayer's order-4 dither array.  Generated by the code given in\n   * Stephen Hawley's article \"Ordered Dithering\" in Graphics Gems I.\n   * The values in this array must range from 0 to ODITHER_CELLS-1.\n   */\n  {   0,192, 48,240, 12,204, 60,252,  3,195, 51,243, 15,207, 63,255 },\n  { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },\n  {  32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },\n  { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },\n  {   8,200, 56,248,  4,196, 52,244, 11,203, 59,251,  7,199, 55,247 },\n  { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },\n  {  40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },\n  { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },\n  {   2,194, 50,242, 14,206, 62,254,  1,193, 49,241, 13,205, 61,253 },\n  { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },\n  {  34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },\n  { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },\n  {  10,202, 58,250,  6,198, 54,246,  9,201, 57,249,  5,197, 53,245 },\n  { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },\n  {  42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },\n  { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }\n};\n\n\n/* Declarations for Floyd-Steinberg dithering.\n *\n * Errors are accumulated into the array fserrors[], at a resolution of\n * 1/16th of a pixel count.  The error at a given pixel is propagated\n * to its not-yet-processed neighbors using the standard F-S fractions,\n *\t\t...\t(here)\t7/16\n *\t\t3/16\t5/16\t1/16\n * We work left-to-right on even rows, right-to-left on odd rows.\n *\n * We can get away with a single array (holding one row's worth of errors)\n * by using it to store the current row's errors at pixel columns not yet\n * processed, but the next row's errors at columns already processed.  We\n * need only a few extra variables to hold the errors immediately around the\n * current column.  (If we are lucky, those variables are in registers, but\n * even if not, they're probably cheaper to access than array elements are.)\n *\n * The fserrors[] array is indexed [component#][position].\n * We provide (#columns + 2) entries per component; the extra entry at each\n * end saves us from special-casing the first and last pixels.\n *\n * Note: on a wide image, we might not have enough room in a PC's near data\n * segment to hold the error array; so it is allocated with alloc_large.\n */\n\n#if BITS_IN_JSAMPLE == 8\ntypedef INT16 FSERROR;\t\t/* 16 bits should be enough */\ntypedef int LOCFSERROR;\t\t/* use 'int' for calculation temps */\n#else\ntypedef INT32 FSERROR;\t\t/* may need more than 16 bits */\ntypedef INT32 LOCFSERROR;\t/* be sure calculation temps are big enough */\n#endif\n\ntypedef FSERROR FAR *FSERRPTR;\t/* pointer to error array (in FAR storage!) */\n\n\n/* Private subobject */\n\n#define MAX_Q_COMPS 4\t\t/* max components I can handle */\n\ntypedef struct {\n  struct jpeg_color_quantizer pub; /* public fields */\n\n  /* Initially allocated colormap is saved here */\n  JSAMPARRAY sv_colormap;\t/* The color map as a 2-D pixel array */\n  int sv_actual;\t\t/* number of entries in use */\n\n  JSAMPARRAY colorindex;\t/* Precomputed mapping for speed */\n  /* colorindex[i][j] = index of color closest to pixel value j in component i,\n   * premultiplied as described above.  Since colormap indexes must fit into\n   * JSAMPLEs, the entries of this array will too.\n   */\n  boolean is_padded;\t\t/* is the colorindex padded for odither? */\n\n  int Ncolors[MAX_Q_COMPS];\t/* # of values alloced to each component */\n\n  /* Variables for ordered dithering */\n  int row_index;\t\t/* cur row's vertical index in dither matrix */\n  ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */\n\n  /* Variables for Floyd-Steinberg dithering */\n  FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */\n  boolean on_odd_row;\t\t/* flag to remember which row we are on */\n} my_cquantizer;\n\ntypedef my_cquantizer * my_cquantize_ptr;\n\n\n/*\n * Policy-making subroutines for create_colormap and create_colorindex.\n * These routines determine the colormap to be used.  The rest of the module\n * only assumes that the colormap is orthogonal.\n *\n *  * select_ncolors decides how to divvy up the available colors\n *    among the components.\n *  * output_value defines the set of representative values for a component.\n *  * largest_input_value defines the mapping from input values to\n *    representative values for a component.\n * Note that the latter two routines may impose different policies for\n * different components, though this is not currently done.\n */\n\n\nLOCAL(int)\nselect_ncolors (j_decompress_ptr cinfo, int Ncolors[])\n/* Determine allocation of desired colors to components, */\n/* and fill in Ncolors[] array to indicate choice. */\n/* Return value is total number of colors (product of Ncolors[] values). */\n{\n  int nc = cinfo->out_color_components; /* number of color components */\n  int max_colors = cinfo->desired_number_of_colors;\n  int total_colors, iroot, i, j;\n  boolean changed;\n  long temp;\n  static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };\n\n  /* We can allocate at least the nc'th root of max_colors per component. */\n  /* Compute floor(nc'th root of max_colors). */\n  iroot = 1;\n  do {\n    iroot++;\n    temp = iroot;\t\t/* set temp = iroot ** nc */\n    for (i = 1; i < nc; i++)\n      temp *= iroot;\n  } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */\n  iroot--;\t\t\t/* now iroot = floor(root) */\n\n  /* Must have at least 2 color values per component */\n  if (iroot < 2)\n    ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);\n\n  /* Initialize to iroot color values for each component */\n  total_colors = 1;\n  for (i = 0; i < nc; i++) {\n    Ncolors[i] = iroot;\n    total_colors *= iroot;\n  }\n  /* We may be able to increment the count for one or more components without\n   * exceeding max_colors, though we know not all can be incremented.\n   * Sometimes, the first component can be incremented more than once!\n   * (Example: for 16 colors, we start at 2*2*2, go to 3*2*2, then 4*2*2.)\n   * In RGB colorspace, try to increment G first, then R, then B.\n   */\n  do {\n    changed = FALSE;\n    for (i = 0; i < nc; i++) {\n      j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);\n      /* calculate new total_colors if Ncolors[j] is incremented */\n      temp = total_colors / Ncolors[j];\n      temp *= Ncolors[j]+1;\t/* done in long arith to avoid oflo */\n      if (temp > (long) max_colors)\n\tbreak;\t\t\t/* won't fit, done with this pass */\n      Ncolors[j]++;\t\t/* OK, apply the increment */\n      total_colors = (int) temp;\n      changed = TRUE;\n    }\n  } while (changed);\n\n  return total_colors;\n}\n\n\nLOCAL(int)\noutput_value (j_decompress_ptr cinfo, int ci, int j, int maxj)\n/* Return j'th output value, where j will range from 0 to maxj */\n/* The output values must fall in 0..MAXJSAMPLE in increasing order */\n{\n  /* We always provide values 0 and MAXJSAMPLE for each component;\n   * any additional values are equally spaced between these limits.\n   * (Forcing the upper and lower values to the limits ensures that\n   * dithering can't produce a color outside the selected gamut.)\n   */\n  return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);\n}\n\n\nLOCAL(int)\nlargest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)\n/* Return largest input value that should map to j'th output value */\n/* Must have largest(j=0) >= 0, and largest(j=maxj) >= MAXJSAMPLE */\n{\n  /* Breakpoints are halfway between values returned by output_value */\n  return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));\n}\n\n\n/*\n * Create the colormap.\n */\n\nLOCAL(void)\ncreate_colormap (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  JSAMPARRAY colormap;\t\t/* Created colormap */\n  int total_colors;\t\t/* Number of distinct output colors */\n  int i,j,k, nci, blksize, blkdist, ptr, val;\n\n  /* Select number of colors for each component */\n  total_colors = select_ncolors(cinfo, cquantize->Ncolors);\n\n  /* Report selected color counts */\n  if (cinfo->out_color_components == 3)\n    TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,\n\t     total_colors, cquantize->Ncolors[0],\n\t     cquantize->Ncolors[1], cquantize->Ncolors[2]);\n  else\n    TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);\n\n  /* Allocate and fill in the colormap. */\n  /* The colors are ordered in the map in standard row-major order, */\n  /* i.e. rightmost (highest-indexed) color changes most rapidly. */\n\n  colormap = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE,\n     (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);\n\n  /* blksize is number of adjacent repeated entries for a component */\n  /* blkdist is distance between groups of identical entries for a component */\n  blkdist = total_colors;\n\n  for (i = 0; i < cinfo->out_color_components; i++) {\n    /* fill in colormap entries for i'th color component */\n    nci = cquantize->Ncolors[i]; /* # of distinct values for this color */\n    blksize = blkdist / nci;\n    for (j = 0; j < nci; j++) {\n      /* Compute j'th output value (out of nci) for component */\n      val = output_value(cinfo, i, j, nci-1);\n      /* Fill in all colormap entries that have this value of this component */\n      for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {\n\t/* fill in blksize entries beginning at ptr */\n\tfor (k = 0; k < blksize; k++)\n\t  colormap[i][ptr+k] = (JSAMPLE) val;\n      }\n    }\n    blkdist = blksize;\t\t/* blksize of this color is blkdist of next */\n  }\n\n  /* Save the colormap in private storage,\n   * where it will survive color quantization mode changes.\n   */\n  cquantize->sv_colormap = colormap;\n  cquantize->sv_actual = total_colors;\n}\n\n\n/*\n * Create the color index table.\n */\n\nLOCAL(void)\ncreate_colorindex (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  JSAMPROW indexptr;\n  int i,j,k, nci, blksize, val, pad;\n\n  /* For ordered dither, we pad the color index tables by MAXJSAMPLE in\n   * each direction (input index values can be -MAXJSAMPLE .. 2*MAXJSAMPLE).\n   * This is not necessary in the other dithering modes.  However, we\n   * flag whether it was done in case user changes dithering mode.\n   */\n  if (cinfo->dither_mode == JDITHER_ORDERED) {\n    pad = MAXJSAMPLE*2;\n    cquantize->is_padded = TRUE;\n  } else {\n    pad = 0;\n    cquantize->is_padded = FALSE;\n  }\n\n  cquantize->colorindex = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE,\n     (JDIMENSION) (MAXJSAMPLE+1 + pad),\n     (JDIMENSION) cinfo->out_color_components);\n\n  /* blksize is number of adjacent repeated entries for a component */\n  blksize = cquantize->sv_actual;\n\n  for (i = 0; i < cinfo->out_color_components; i++) {\n    /* fill in colorindex entries for i'th color component */\n    nci = cquantize->Ncolors[i]; /* # of distinct values for this color */\n    blksize = blksize / nci;\n\n    /* adjust colorindex pointers to provide padding at negative indexes. */\n    if (pad)\n      cquantize->colorindex[i] += MAXJSAMPLE;\n\n    /* in loop, val = index of current output value, */\n    /* and k = largest j that maps to current val */\n    indexptr = cquantize->colorindex[i];\n    val = 0;\n    k = largest_input_value(cinfo, i, 0, nci-1);\n    for (j = 0; j <= MAXJSAMPLE; j++) {\n      while (j > k)\t\t/* advance val if past boundary */\n\tk = largest_input_value(cinfo, i, ++val, nci-1);\n      /* premultiply so that no multiplication needed in main processing */\n      indexptr[j] = (JSAMPLE) (val * blksize);\n    }\n    /* Pad at both ends if necessary */\n    if (pad)\n      for (j = 1; j <= MAXJSAMPLE; j++) {\n\tindexptr[-j] = indexptr[0];\n\tindexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];\n      }\n  }\n}\n\n\n/*\n * Create an ordered-dither array for a component having ncolors\n * distinct output values.\n */\n\nLOCAL(ODITHER_MATRIX_PTR)\nmake_odither_array (j_decompress_ptr cinfo, int ncolors)\n{\n  ODITHER_MATRIX_PTR odither;\n  int j,k;\n  INT32 num,den;\n\n  odither = (ODITHER_MATRIX_PTR)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(ODITHER_MATRIX));\n  /* The inter-value distance for this color is MAXJSAMPLE/(ncolors-1).\n   * Hence the dither value for the matrix cell with fill order f\n   * (f=0..N-1) should be (N-1-2*f)/(2*N) * MAXJSAMPLE/(ncolors-1).\n   * On 16-bit-int machine, be careful to avoid overflow.\n   */\n  den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));\n  for (j = 0; j < ODITHER_SIZE; j++) {\n    for (k = 0; k < ODITHER_SIZE; k++) {\n      num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))\n\t    * MAXJSAMPLE;\n      /* Ensure round towards zero despite C's lack of consistency\n       * about rounding negative values in integer division...\n       */\n      odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);\n    }\n  }\n  return odither;\n}\n\n\n/*\n * Create the ordered-dither tables.\n * Components having the same number of representative colors may \n * share a dither table.\n */\n\nLOCAL(void)\ncreate_odither_tables (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  ODITHER_MATRIX_PTR odither;\n  int i, j, nci;\n\n  for (i = 0; i < cinfo->out_color_components; i++) {\n    nci = cquantize->Ncolors[i]; /* # of distinct values for this color */\n    odither = NULL;\t\t/* search for matching prior component */\n    for (j = 0; j < i; j++) {\n      if (nci == cquantize->Ncolors[j]) {\n\todither = cquantize->odither[j];\n\tbreak;\n      }\n    }\n    if (odither == NULL)\t/* need a new table? */\n      odither = make_odither_array(cinfo, nci);\n    cquantize->odither[i] = odither;\n  }\n}\n\n\n/*\n * Map some rows of pixels to the output colormapped representation.\n */\n\nMETHODDEF(void)\ncolor_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\tJSAMPARRAY output_buf, int num_rows)\n/* General case, no dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  JSAMPARRAY colorindex = cquantize->colorindex;\n  register int pixcode, ci;\n  register JSAMPROW ptrin, ptrout;\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n  register int nc = cinfo->out_color_components;\n\n  for (row = 0; row < num_rows; row++) {\n    ptrin = input_buf[row];\n    ptrout = output_buf[row];\n    for (col = width; col > 0; col--) {\n      pixcode = 0;\n      for (ci = 0; ci < nc; ci++) {\n\tpixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);\n      }\n      *ptrout++ = (JSAMPLE) pixcode;\n    }\n  }\n}\n\n\nMETHODDEF(void)\ncolor_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\t JSAMPARRAY output_buf, int num_rows)\n/* Fast path for out_color_components==3, no dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  register int pixcode;\n  register JSAMPROW ptrin, ptrout;\n  JSAMPROW colorindex0 = cquantize->colorindex[0];\n  JSAMPROW colorindex1 = cquantize->colorindex[1];\n  JSAMPROW colorindex2 = cquantize->colorindex[2];\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n\n  for (row = 0; row < num_rows; row++) {\n    ptrin = input_buf[row];\n    ptrout = output_buf[row];\n    for (col = width; col > 0; col--) {\n      pixcode  = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);\n      pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);\n      pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);\n      *ptrout++ = (JSAMPLE) pixcode;\n    }\n  }\n}\n\n\nMETHODDEF(void)\nquantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\t     JSAMPARRAY output_buf, int num_rows)\n/* General case, with ordered dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  register JSAMPROW input_ptr;\n  register JSAMPROW output_ptr;\n  JSAMPROW colorindex_ci;\n  int * dither;\t\t\t/* points to active row of dither matrix */\n  int row_index, col_index;\t/* current indexes into dither matrix */\n  int nc = cinfo->out_color_components;\n  int ci;\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n\n  for (row = 0; row < num_rows; row++) {\n    /* Initialize output values to 0 so can process components separately */\n    FMEMZERO((void FAR *) output_buf[row],\n\t     (size_t) (width * SIZEOF(JSAMPLE)));\n    row_index = cquantize->row_index;\n    for (ci = 0; ci < nc; ci++) {\n      input_ptr = input_buf[row] + ci;\n      output_ptr = output_buf[row];\n      colorindex_ci = cquantize->colorindex[ci];\n      dither = cquantize->odither[ci][row_index];\n      col_index = 0;\n\n      for (col = width; col > 0; col--) {\n\t/* Form pixel value + dither, range-limit to 0..MAXJSAMPLE,\n\t * select output value, accumulate into output code for this pixel.\n\t * Range-limiting need not be done explicitly, as we have extended\n\t * the colorindex table to produce the right answers for out-of-range\n\t * inputs.  The maximum dither is +- MAXJSAMPLE; this sets the\n\t * required amount of padding.\n\t */\n\t*output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];\n\tinput_ptr += nc;\n\toutput_ptr++;\n\tcol_index = (col_index + 1) & ODITHER_MASK;\n      }\n    }\n    /* Advance row index for next row */\n    row_index = (row_index + 1) & ODITHER_MASK;\n    cquantize->row_index = row_index;\n  }\n}\n\n\nMETHODDEF(void)\nquantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\t      JSAMPARRAY output_buf, int num_rows)\n/* Fast path for out_color_components==3, with ordered dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  register int pixcode;\n  register JSAMPROW input_ptr;\n  register JSAMPROW output_ptr;\n  JSAMPROW colorindex0 = cquantize->colorindex[0];\n  JSAMPROW colorindex1 = cquantize->colorindex[1];\n  JSAMPROW colorindex2 = cquantize->colorindex[2];\n  int * dither0;\t\t/* points to active row of dither matrix */\n  int * dither1;\n  int * dither2;\n  int row_index, col_index;\t/* current indexes into dither matrix */\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n\n  for (row = 0; row < num_rows; row++) {\n    row_index = cquantize->row_index;\n    input_ptr = input_buf[row];\n    output_ptr = output_buf[row];\n    dither0 = cquantize->odither[0][row_index];\n    dither1 = cquantize->odither[1][row_index];\n    dither2 = cquantize->odither[2][row_index];\n    col_index = 0;\n\n    for (col = width; col > 0; col--) {\n      pixcode  = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +\n\t\t\t\t\tdither0[col_index]]);\n      pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +\n\t\t\t\t\tdither1[col_index]]);\n      pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +\n\t\t\t\t\tdither2[col_index]]);\n      *output_ptr++ = (JSAMPLE) pixcode;\n      col_index = (col_index + 1) & ODITHER_MASK;\n    }\n    row_index = (row_index + 1) & ODITHER_MASK;\n    cquantize->row_index = row_index;\n  }\n}\n\n\nMETHODDEF(void)\nquantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\t    JSAMPARRAY output_buf, int num_rows)\n/* General case, with Floyd-Steinberg dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  register LOCFSERROR cur;\t/* current error or pixel value */\n  LOCFSERROR belowerr;\t\t/* error for pixel below cur */\n  LOCFSERROR bpreverr;\t\t/* error for below/prev col */\n  LOCFSERROR bnexterr;\t\t/* error for below/next col */\n  LOCFSERROR delta;\n  register FSERRPTR errorptr;\t/* => fserrors[] at column before current */\n  register JSAMPROW input_ptr;\n  register JSAMPROW output_ptr;\n  JSAMPROW colorindex_ci;\n  JSAMPROW colormap_ci;\n  int pixcode;\n  int nc = cinfo->out_color_components;\n  int dir;\t\t\t/* 1 for left-to-right, -1 for right-to-left */\n  int dirnc;\t\t\t/* dir * nc */\n  int ci;\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n  JSAMPLE *range_limit = cinfo->sample_range_limit;\n  SHIFT_TEMPS\n\n  for (row = 0; row < num_rows; row++) {\n    /* Initialize output values to 0 so can process components separately */\n    FMEMZERO((void FAR *) output_buf[row],\n\t     (size_t) (width * SIZEOF(JSAMPLE)));\n    for (ci = 0; ci < nc; ci++) {\n      input_ptr = input_buf[row] + ci;\n      output_ptr = output_buf[row];\n      if (cquantize->on_odd_row) {\n\t/* work right to left in this row */\n\tinput_ptr += (width-1) * nc; /* so point to rightmost pixel */\n\toutput_ptr += width-1;\n\tdir = -1;\n\tdirnc = -nc;\n\terrorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */\n      } else {\n\t/* work left to right in this row */\n\tdir = 1;\n\tdirnc = nc;\n\terrorptr = cquantize->fserrors[ci]; /* => entry before first column */\n      }\n      colorindex_ci = cquantize->colorindex[ci];\n      colormap_ci = cquantize->sv_colormap[ci];\n      /* Preset error values: no error propagated to first pixel from left */\n      cur = 0;\n      /* and no error propagated to row below yet */\n      belowerr = bpreverr = 0;\n\n      for (col = width; col > 0; col--) {\n\t/* cur holds the error propagated from the previous pixel on the\n\t * current line.  Add the error propagated from the previous line\n\t * to form the complete error correction term for this pixel, and\n\t * round the error term (which is expressed * 16) to an integer.\n\t * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct\n\t * for either sign of the error value.\n\t * Note: errorptr points to *previous* column's array entry.\n\t */\n\tcur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);\n\t/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.\n\t * The maximum error is +- MAXJSAMPLE; this sets the required size\n\t * of the range_limit array.\n\t */\n\tcur += GETJSAMPLE(*input_ptr);\n\tcur = GETJSAMPLE(range_limit[cur]);\n\t/* Select output value, accumulate into output code for this pixel */\n\tpixcode = GETJSAMPLE(colorindex_ci[cur]);\n\t*output_ptr += (JSAMPLE) pixcode;\n\t/* Compute actual representation error at this pixel */\n\t/* Note: we can do this even though we don't have the final */\n\t/* pixel code, because the colormap is orthogonal. */\n\tcur -= GETJSAMPLE(colormap_ci[pixcode]);\n\t/* Compute error fractions to be propagated to adjacent pixels.\n\t * Add these into the running sums, and simultaneously shift the\n\t * next-line error sums left by 1 column.\n\t */\n\tbnexterr = cur;\n\tdelta = cur * 2;\n\tcur += delta;\t\t/* form error * 3 */\n\terrorptr[0] = (FSERROR) (bpreverr + cur);\n\tcur += delta;\t\t/* form error * 5 */\n\tbpreverr = belowerr + cur;\n\tbelowerr = bnexterr;\n\tcur += delta;\t\t/* form error * 7 */\n\t/* At this point cur contains the 7/16 error value to be propagated\n\t * to the next pixel on the current line, and all the errors for the\n\t * next line have been shifted over. We are therefore ready to move on.\n\t */\n\tinput_ptr += dirnc;\t/* advance input ptr to next column */\n\toutput_ptr += dir;\t/* advance output ptr to next column */\n\terrorptr += dir;\t/* advance errorptr to current column */\n      }\n      /* Post-loop cleanup: we must unload the final error value into the\n       * final fserrors[] entry.  Note we need not unload belowerr because\n       * it is for the dummy column before or after the actual array.\n       */\n      errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */\n    }\n    cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);\n  }\n}\n\n\n/*\n * Allocate workspace for Floyd-Steinberg errors.\n */\n\nLOCAL(void)\nalloc_fs_workspace (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  size_t arraysize;\n  int i;\n\n  arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));\n  for (i = 0; i < cinfo->out_color_components; i++) {\n    cquantize->fserrors[i] = (FSERRPTR)\n      (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);\n  }\n}\n\n\n/*\n * Initialize for one-pass color quantization.\n */\n\nMETHODDEF(void)\nstart_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  size_t arraysize;\n  int i;\n\n  /* Install my colormap. */\n  cinfo->colormap = cquantize->sv_colormap;\n  cinfo->actual_number_of_colors = cquantize->sv_actual;\n\n  /* Initialize for desired dithering mode. */\n  switch (cinfo->dither_mode) {\n  case JDITHER_NONE:\n    if (cinfo->out_color_components == 3)\n      cquantize->pub.color_quantize = color_quantize3;\n    else\n      cquantize->pub.color_quantize = color_quantize;\n    break;\n  case JDITHER_ORDERED:\n    if (cinfo->out_color_components == 3)\n      cquantize->pub.color_quantize = quantize3_ord_dither;\n    else\n      cquantize->pub.color_quantize = quantize_ord_dither;\n    cquantize->row_index = 0;\t/* initialize state for ordered dither */\n    /* If user changed to ordered dither from another mode,\n     * we must recreate the color index table with padding.\n     * This will cost extra space, but probably isn't very likely.\n     */\n    if (! cquantize->is_padded)\n      create_colorindex(cinfo);\n    /* Create ordered-dither tables if we didn't already. */\n    if (cquantize->odither[0] == NULL)\n      create_odither_tables(cinfo);\n    break;\n  case JDITHER_FS:\n    cquantize->pub.color_quantize = quantize_fs_dither;\n    cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */\n    /* Allocate Floyd-Steinberg workspace if didn't already. */\n    if (cquantize->fserrors[0] == NULL)\n      alloc_fs_workspace(cinfo);\n    /* Initialize the propagated errors to zero. */\n    arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));\n    for (i = 0; i < cinfo->out_color_components; i++)\n      FMEMZERO((void FAR *) cquantize->fserrors[i], arraysize);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_NOT_COMPILED);\n    break;\n  }\n}\n\n\n/*\n * Finish up at the end of the pass.\n */\n\nMETHODDEF(void)\nfinish_pass_1_quant (j_decompress_ptr cinfo)\n{\n  /* no work in 1-pass case */\n}\n\n\n/*\n * Switch to a new external colormap between output passes.\n * Shouldn't get to this module!\n */\n\nMETHODDEF(void)\nnew_color_map_1_quant (j_decompress_ptr cinfo)\n{\n  ERREXIT(cinfo, JERR_MODE_CHANGE);\n}\n\n\n/*\n * Module initialization routine for 1-pass color quantization.\n */\n\nGLOBAL(void)\njinit_1pass_quantizer (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize;\n\n  cquantize = (my_cquantize_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_cquantizer));\n  cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;\n  cquantize->pub.start_pass = start_pass_1_quant;\n  cquantize->pub.finish_pass = finish_pass_1_quant;\n  cquantize->pub.new_color_map = new_color_map_1_quant;\n  cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */\n  cquantize->odither[0] = NULL;\t/* Also flag odither arrays not allocated */\n\n  /* Make sure my internal arrays won't overflow */\n  if (cinfo->out_color_components > MAX_Q_COMPS)\n    ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);\n  /* Make sure colormap indexes can be represented by JSAMPLEs */\n  if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))\n    ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);\n\n  /* Create the colormap and color index table. */\n  create_colormap(cinfo);\n  create_colorindex(cinfo);\n\n  /* Allocate Floyd-Steinberg workspace now if requested.\n   * We do this now since it is FAR storage and may affect the memory\n   * manager's space calculations.  If the user changes to FS dither\n   * mode in a later pass, we will allocate the space then, and will\n   * possibly overrun the max_memory_to_use setting.\n   */\n  if (cinfo->dither_mode == JDITHER_FS)\n    alloc_fs_workspace(cinfo);\n}\n\n#endif /* QUANT_1PASS_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jquant2.c",
    "content": "/*\n * jquant2.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains 2-pass color quantization (color mapping) routines.\n * These routines provide selection of a custom color map for an image,\n * followed by mapping of the image to that color map, with optional\n * Floyd-Steinberg dithering.\n * It is also possible to use just the second pass to map to an arbitrary\n * externally-given color map.\n *\n * Note: ordered dithering is not supported, since there isn't any fast\n * way to compute intercolor distances; it's unclear that ordered dither's\n * fundamental assumptions even hold with an irregularly spaced color map.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n#ifdef QUANT_2PASS_SUPPORTED\n\n\n/*\n * This module implements the well-known Heckbert paradigm for color\n * quantization.  Most of the ideas used here can be traced back to\n * Heckbert's seminal paper\n *   Heckbert, Paul.  \"Color Image Quantization for Frame Buffer Display\",\n *   Proc. SIGGRAPH '82, Computer Graphics v.16 #3 (July 1982), pp 297-304.\n *\n * In the first pass over the image, we accumulate a histogram showing the\n * usage count of each possible color.  To keep the histogram to a reasonable\n * size, we reduce the precision of the input; typical practice is to retain\n * 5 or 6 bits per color, so that 8 or 4 different input values are counted\n * in the same histogram cell.\n *\n * Next, the color-selection step begins with a box representing the whole\n * color space, and repeatedly splits the \"largest\" remaining box until we\n * have as many boxes as desired colors.  Then the mean color in each\n * remaining box becomes one of the possible output colors.\n * \n * The second pass over the image maps each input pixel to the closest output\n * color (optionally after applying a Floyd-Steinberg dithering correction).\n * This mapping is logically trivial, but making it go fast enough requires\n * considerable care.\n *\n * Heckbert-style quantizers vary a good deal in their policies for choosing\n * the \"largest\" box and deciding where to cut it.  The particular policies\n * used here have proved out well in experimental comparisons, but better ones\n * may yet be found.\n *\n * In earlier versions of the IJG code, this module quantized in YCbCr color\n * space, processing the raw upsampled data without a color conversion step.\n * This allowed the color conversion math to be done only once per colormap\n * entry, not once per pixel.  However, that optimization precluded other\n * useful optimizations (such as merging color conversion with upsampling)\n * and it also interfered with desired capabilities such as quantizing to an\n * externally-supplied colormap.  We have therefore abandoned that approach.\n * The present code works in the post-conversion color space, typically RGB.\n *\n * To improve the visual quality of the results, we actually work in scaled\n * RGB space, giving G distances more weight than R, and R in turn more than\n * B.  To do everything in integer math, we must use integer scale factors.\n * The 2/3/1 scale factors used here correspond loosely to the relative\n * weights of the colors in the NTSC grayscale equation.\n * If you want to use this code to quantize a non-RGB color space, you'll\n * probably need to change these scale factors.\n */\n\n#define R_SCALE 2\t\t/* scale R distances by this much */\n#define G_SCALE 3\t\t/* scale G distances by this much */\n#define B_SCALE 1\t\t/* and B by this much */\n\n/* Relabel R/G/B as components 0/1/2, respecting the RGB ordering defined\n * in jmorecfg.h.  As the code stands, it will do the right thing for R,G,B\n * and B,G,R orders.  If you define some other weird order in jmorecfg.h,\n * you'll get compile errors until you extend this logic.  In that case\n * you'll probably want to tweak the histogram sizes too.\n */\n\n#if RGB_RED == 0\n#define C0_SCALE R_SCALE\n#endif\n#if RGB_BLUE == 0\n#define C0_SCALE B_SCALE\n#endif\n#if RGB_GREEN == 1\n#define C1_SCALE G_SCALE\n#endif\n#if RGB_RED == 2\n#define C2_SCALE R_SCALE\n#endif\n#if RGB_BLUE == 2\n#define C2_SCALE B_SCALE\n#endif\n\n\n/*\n * First we have the histogram data structure and routines for creating it.\n *\n * The number of bits of precision can be adjusted by changing these symbols.\n * We recommend keeping 6 bits for G and 5 each for R and B.\n * If you have plenty of memory and cycles, 6 bits all around gives marginally\n * better results; if you are short of memory, 5 bits all around will save\n * some space but degrade the results.\n * To maintain a fully accurate histogram, we'd need to allocate a \"long\"\n * (preferably unsigned long) for each cell.  In practice this is overkill;\n * we can get by with 16 bits per cell.  Few of the cell counts will overflow,\n * and clamping those that do overflow to the maximum value will give close-\n * enough results.  This reduces the recommended histogram size from 256Kb\n * to 128Kb, which is a useful savings on PC-class machines.\n * (In the second pass the histogram space is re-used for pixel mapping data;\n * in that capacity, each cell must be able to store zero to the number of\n * desired colors.  16 bits/cell is plenty for that too.)\n * Since the JPEG code is intended to run in small memory model on 80x86\n * machines, we can't just allocate the histogram in one chunk.  Instead\n * of a true 3-D array, we use a row of pointers to 2-D arrays.  Each\n * pointer corresponds to a C0 value (typically 2^5 = 32 pointers) and\n * each 2-D array has 2^6*2^5 = 2048 or 2^6*2^6 = 4096 entries.  Note that\n * on 80x86 machines, the pointer row is in near memory but the actual\n * arrays are in far memory (same arrangement as we use for image arrays).\n */\n\n#define MAXNUMCOLORS  (MAXJSAMPLE+1) /* maximum size of colormap */\n\n/* These will do the right thing for either R,G,B or B,G,R color order,\n * but you may not like the results for other color orders.\n */\n#define HIST_C0_BITS  5\t\t/* bits of precision in R/B histogram */\n#define HIST_C1_BITS  6\t\t/* bits of precision in G histogram */\n#define HIST_C2_BITS  5\t\t/* bits of precision in B/R histogram */\n\n/* Number of elements along histogram axes. */\n#define HIST_C0_ELEMS  (1<<HIST_C0_BITS)\n#define HIST_C1_ELEMS  (1<<HIST_C1_BITS)\n#define HIST_C2_ELEMS  (1<<HIST_C2_BITS)\n\n/* These are the amounts to shift an input value to get a histogram index. */\n#define C0_SHIFT  (BITS_IN_JSAMPLE-HIST_C0_BITS)\n#define C1_SHIFT  (BITS_IN_JSAMPLE-HIST_C1_BITS)\n#define C2_SHIFT  (BITS_IN_JSAMPLE-HIST_C2_BITS)\n\n\ntypedef UINT16 histcell;\t/* histogram cell; prefer an unsigned type */\n\ntypedef histcell FAR * histptr;\t/* for pointers to histogram cells */\n\ntypedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */\ntypedef hist1d FAR * hist2d;\t/* type for the 2nd-level pointers */\ntypedef hist2d * hist3d;\t/* type for top-level pointer */\n\n\n/* Declarations for Floyd-Steinberg dithering.\n *\n * Errors are accumulated into the array fserrors[], at a resolution of\n * 1/16th of a pixel count.  The error at a given pixel is propagated\n * to its not-yet-processed neighbors using the standard F-S fractions,\n *\t\t...\t(here)\t7/16\n *\t\t3/16\t5/16\t1/16\n * We work left-to-right on even rows, right-to-left on odd rows.\n *\n * We can get away with a single array (holding one row's worth of errors)\n * by using it to store the current row's errors at pixel columns not yet\n * processed, but the next row's errors at columns already processed.  We\n * need only a few extra variables to hold the errors immediately around the\n * current column.  (If we are lucky, those variables are in registers, but\n * even if not, they're probably cheaper to access than array elements are.)\n *\n * The fserrors[] array has (#columns + 2) entries; the extra entry at\n * each end saves us from special-casing the first and last pixels.\n * Each entry is three values long, one value for each color component.\n *\n * Note: on a wide image, we might not have enough room in a PC's near data\n * segment to hold the error array; so it is allocated with alloc_large.\n */\n\n#if BITS_IN_JSAMPLE == 8\ntypedef INT16 FSERROR;\t\t/* 16 bits should be enough */\ntypedef int LOCFSERROR;\t\t/* use 'int' for calculation temps */\n#else\ntypedef INT32 FSERROR;\t\t/* may need more than 16 bits */\ntypedef INT32 LOCFSERROR;\t/* be sure calculation temps are big enough */\n#endif\n\ntypedef FSERROR FAR *FSERRPTR;\t/* pointer to error array (in FAR storage!) */\n\n\n/* Private subobject */\n\ntypedef struct {\n  struct jpeg_color_quantizer pub; /* public fields */\n\n  /* Space for the eventually created colormap is stashed here */\n  JSAMPARRAY sv_colormap;\t/* colormap allocated at init time */\n  int desired;\t\t\t/* desired # of colors = size of colormap */\n\n  /* Variables for accumulating image statistics */\n  hist3d histogram;\t\t/* pointer to the histogram */\n\n  boolean needs_zeroed;\t\t/* TRUE if next pass must zero histogram */\n\n  /* Variables for Floyd-Steinberg dithering */\n  FSERRPTR fserrors;\t\t/* accumulated errors */\n  boolean on_odd_row;\t\t/* flag to remember which row we are on */\n  int * error_limiter;\t\t/* table for clamping the applied error */\n} my_cquantizer;\n\ntypedef my_cquantizer * my_cquantize_ptr;\n\n\n/*\n * Prescan some rows of pixels.\n * In this module the prescan simply updates the histogram, which has been\n * initialized to zeroes by start_pass.\n * An output_buf parameter is required by the method signature, but no data\n * is actually output (in fact the buffer controller is probably passing a\n * NULL pointer).\n */\n\nMETHODDEF(void)\nprescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,\n\t\t  JSAMPARRAY output_buf, int num_rows)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  register JSAMPROW ptr;\n  register histptr histp;\n  register hist3d histogram = cquantize->histogram;\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n\n  for (row = 0; row < num_rows; row++) {\n    ptr = input_buf[row];\n    for (col = width; col > 0; col--) {\n      /* get pixel value and index into the histogram */\n      histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]\n\t\t\t [GETJSAMPLE(ptr[1]) >> C1_SHIFT]\n\t\t\t [GETJSAMPLE(ptr[2]) >> C2_SHIFT];\n      /* increment, check for overflow and undo increment if so. */\n      if (++(*histp) <= 0)\n\t(*histp)--;\n      ptr += 3;\n    }\n  }\n}\n\n\n/*\n * Next we have the really interesting routines: selection of a colormap\n * given the completed histogram.\n * These routines work with a list of \"boxes\", each representing a rectangular\n * subset of the input color space (to histogram precision).\n */\n\ntypedef struct {\n  /* The bounds of the box (inclusive); expressed as histogram indexes */\n  int c0min, c0max;\n  int c1min, c1max;\n  int c2min, c2max;\n  /* The volume (actually 2-norm) of the box */\n  INT32 volume;\n  /* The number of nonzero histogram cells within this box */\n  long colorcount;\n} box;\n\ntypedef box * boxptr;\n\n\nLOCAL(boxptr)\nfind_biggest_color_pop (boxptr boxlist, int numboxes)\n/* Find the splittable box with the largest color population */\n/* Returns NULL if no splittable boxes remain */\n{\n  register boxptr boxp;\n  register int i;\n  register long maxc = 0;\n  boxptr which = NULL;\n  \n  for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {\n    if (boxp->colorcount > maxc && boxp->volume > 0) {\n      which = boxp;\n      maxc = boxp->colorcount;\n    }\n  }\n  return which;\n}\n\n\nLOCAL(boxptr)\nfind_biggest_volume (boxptr boxlist, int numboxes)\n/* Find the splittable box with the largest (scaled) volume */\n/* Returns NULL if no splittable boxes remain */\n{\n  register boxptr boxp;\n  register int i;\n  register INT32 maxv = 0;\n  boxptr which = NULL;\n  \n  for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {\n    if (boxp->volume > maxv) {\n      which = boxp;\n      maxv = boxp->volume;\n    }\n  }\n  return which;\n}\n\n\nLOCAL(void)\nupdate_box (j_decompress_ptr cinfo, boxptr boxp)\n/* Shrink the min/max bounds of a box to enclose only nonzero elements, */\n/* and recompute its volume and population */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  histptr histp;\n  int c0,c1,c2;\n  int c0min,c0max,c1min,c1max,c2min,c2max;\n  INT32 dist0,dist1,dist2;\n  long ccount;\n  \n  c0min = boxp->c0min;  c0max = boxp->c0max;\n  c1min = boxp->c1min;  c1max = boxp->c1max;\n  c2min = boxp->c2min;  c2max = boxp->c2max;\n  \n  if (c0max > c0min)\n    for (c0 = c0min; c0 <= c0max; c0++)\n      for (c1 = c1min; c1 <= c1max; c1++) {\n\thistp = & histogram[c0][c1][c2min];\n\tfor (c2 = c2min; c2 <= c2max; c2++)\n\t  if (*histp++ != 0) {\n\t    boxp->c0min = c0min = c0;\n\t    goto have_c0min;\n\t  }\n      }\n have_c0min:\n  if (c0max > c0min)\n    for (c0 = c0max; c0 >= c0min; c0--)\n      for (c1 = c1min; c1 <= c1max; c1++) {\n\thistp = & histogram[c0][c1][c2min];\n\tfor (c2 = c2min; c2 <= c2max; c2++)\n\t  if (*histp++ != 0) {\n\t    boxp->c0max = c0max = c0;\n\t    goto have_c0max;\n\t  }\n      }\n have_c0max:\n  if (c1max > c1min)\n    for (c1 = c1min; c1 <= c1max; c1++)\n      for (c0 = c0min; c0 <= c0max; c0++) {\n\thistp = & histogram[c0][c1][c2min];\n\tfor (c2 = c2min; c2 <= c2max; c2++)\n\t  if (*histp++ != 0) {\n\t    boxp->c1min = c1min = c1;\n\t    goto have_c1min;\n\t  }\n      }\n have_c1min:\n  if (c1max > c1min)\n    for (c1 = c1max; c1 >= c1min; c1--)\n      for (c0 = c0min; c0 <= c0max; c0++) {\n\thistp = & histogram[c0][c1][c2min];\n\tfor (c2 = c2min; c2 <= c2max; c2++)\n\t  if (*histp++ != 0) {\n\t    boxp->c1max = c1max = c1;\n\t    goto have_c1max;\n\t  }\n      }\n have_c1max:\n  if (c2max > c2min)\n    for (c2 = c2min; c2 <= c2max; c2++)\n      for (c0 = c0min; c0 <= c0max; c0++) {\n\thistp = & histogram[c0][c1min][c2];\n\tfor (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)\n\t  if (*histp != 0) {\n\t    boxp->c2min = c2min = c2;\n\t    goto have_c2min;\n\t  }\n      }\n have_c2min:\n  if (c2max > c2min)\n    for (c2 = c2max; c2 >= c2min; c2--)\n      for (c0 = c0min; c0 <= c0max; c0++) {\n\thistp = & histogram[c0][c1min][c2];\n\tfor (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)\n\t  if (*histp != 0) {\n\t    boxp->c2max = c2max = c2;\n\t    goto have_c2max;\n\t  }\n      }\n have_c2max:\n\n  /* Update box volume.\n   * We use 2-norm rather than real volume here; this biases the method\n   * against making long narrow boxes, and it has the side benefit that\n   * a box is splittable iff norm > 0.\n   * Since the differences are expressed in histogram-cell units,\n   * we have to shift back to JSAMPLE units to get consistent distances;\n   * after which, we scale according to the selected distance scale factors.\n   */\n  dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;\n  dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;\n  dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;\n  boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;\n  \n  /* Now scan remaining volume of box and compute population */\n  ccount = 0;\n  for (c0 = c0min; c0 <= c0max; c0++)\n    for (c1 = c1min; c1 <= c1max; c1++) {\n      histp = & histogram[c0][c1][c2min];\n      for (c2 = c2min; c2 <= c2max; c2++, histp++)\n\tif (*histp != 0) {\n\t  ccount++;\n\t}\n    }\n  boxp->colorcount = ccount;\n}\n\n\nLOCAL(int)\nmedian_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,\n\t    int desired_colors)\n/* Repeatedly select and split the largest box until we have enough boxes */\n{\n  int n,lb;\n  int c0,c1,c2,cmax;\n  register boxptr b1,b2;\n\n  while (numboxes < desired_colors) {\n    /* Select box to split.\n     * Current algorithm: by population for first half, then by volume.\n     */\n    if (numboxes*2 <= desired_colors) {\n      b1 = find_biggest_color_pop(boxlist, numboxes);\n    } else {\n      b1 = find_biggest_volume(boxlist, numboxes);\n    }\n    if (b1 == NULL)\t\t/* no splittable boxes left! */\n      break;\n    b2 = &boxlist[numboxes];\t/* where new box will go */\n    /* Copy the color bounds to the new box. */\n    b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;\n    b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;\n    /* Choose which axis to split the box on.\n     * Current algorithm: longest scaled axis.\n     * See notes in update_box about scaling distances.\n     */\n    c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;\n    c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;\n    c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;\n    /* We want to break any ties in favor of green, then red, blue last.\n     * This code does the right thing for R,G,B or B,G,R color orders only.\n     */\n#if RGB_RED == 0\n    cmax = c1; n = 1;\n    if (c0 > cmax) { cmax = c0; n = 0; }\n    if (c2 > cmax) { n = 2; }\n#else\n    cmax = c1; n = 1;\n    if (c2 > cmax) { cmax = c2; n = 2; }\n    if (c0 > cmax) { n = 0; }\n#endif\n    /* Choose split point along selected axis, and update box bounds.\n     * Current algorithm: split at halfway point.\n     * (Since the box has been shrunk to minimum volume,\n     * any split will produce two nonempty subboxes.)\n     * Note that lb value is max for lower box, so must be < old max.\n     */\n    switch (n) {\n    case 0:\n      lb = (b1->c0max + b1->c0min) / 2;\n      b1->c0max = lb;\n      b2->c0min = lb+1;\n      break;\n    case 1:\n      lb = (b1->c1max + b1->c1min) / 2;\n      b1->c1max = lb;\n      b2->c1min = lb+1;\n      break;\n    case 2:\n      lb = (b1->c2max + b1->c2min) / 2;\n      b1->c2max = lb;\n      b2->c2min = lb+1;\n      break;\n    }\n    /* Update stats for boxes */\n    update_box(cinfo, b1);\n    update_box(cinfo, b2);\n    numboxes++;\n  }\n  return numboxes;\n}\n\n\nLOCAL(void)\ncompute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)\n/* Compute representative color for a box, put it in colormap[icolor] */\n{\n  /* Current algorithm: mean weighted by pixels (not colors) */\n  /* Note it is important to get the rounding correct! */\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  histptr histp;\n  int c0,c1,c2;\n  int c0min,c0max,c1min,c1max,c2min,c2max;\n  long count;\n  long total = 0;\n  long c0total = 0;\n  long c1total = 0;\n  long c2total = 0;\n  \n  c0min = boxp->c0min;  c0max = boxp->c0max;\n  c1min = boxp->c1min;  c1max = boxp->c1max;\n  c2min = boxp->c2min;  c2max = boxp->c2max;\n  \n  for (c0 = c0min; c0 <= c0max; c0++)\n    for (c1 = c1min; c1 <= c1max; c1++) {\n      histp = & histogram[c0][c1][c2min];\n      for (c2 = c2min; c2 <= c2max; c2++) {\n\tif ((count = *histp++) != 0) {\n\t  total += count;\n\t  c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;\n\t  c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;\n\t  c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;\n\t}\n      }\n    }\n  \n  cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);\n  cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);\n  cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);\n}\n\n\nLOCAL(void)\nselect_colors (j_decompress_ptr cinfo, int desired_colors)\n/* Master routine for color selection */\n{\n  boxptr boxlist;\n  int numboxes;\n  int i;\n\n  /* Allocate workspace for box list */\n  boxlist = (boxptr) (*cinfo->mem->alloc_small)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));\n  /* Initialize one box containing whole space */\n  numboxes = 1;\n  boxlist[0].c0min = 0;\n  boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;\n  boxlist[0].c1min = 0;\n  boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;\n  boxlist[0].c2min = 0;\n  boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;\n  /* Shrink it to actually-used volume and set its statistics */\n  update_box(cinfo, & boxlist[0]);\n  /* Perform median-cut to produce final box list */\n  numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);\n  /* Compute the representative color for each box, fill colormap */\n  for (i = 0; i < numboxes; i++)\n    compute_color(cinfo, & boxlist[i], i);\n  cinfo->actual_number_of_colors = numboxes;\n  TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);\n}\n\n\n/*\n * These routines are concerned with the time-critical task of mapping input\n * colors to the nearest color in the selected colormap.\n *\n * We re-use the histogram space as an \"inverse color map\", essentially a\n * cache for the results of nearest-color searches.  All colors within a\n * histogram cell will be mapped to the same colormap entry, namely the one\n * closest to the cell's center.  This may not be quite the closest entry to\n * the actual input color, but it's almost as good.  A zero in the cache\n * indicates we haven't found the nearest color for that cell yet; the array\n * is cleared to zeroes before starting the mapping pass.  When we find the\n * nearest color for a cell, its colormap index plus one is recorded in the\n * cache for future use.  The pass2 scanning routines call fill_inverse_cmap\n * when they need to use an unfilled entry in the cache.\n *\n * Our method of efficiently finding nearest colors is based on the \"locally\n * sorted search\" idea described by Heckbert and on the incremental distance\n * calculation described by Spencer W. Thomas in chapter III.1 of Graphics\n * Gems II (James Arvo, ed.  Academic Press, 1991).  Thomas points out that\n * the distances from a given colormap entry to each cell of the histogram can\n * be computed quickly using an incremental method: the differences between\n * distances to adjacent cells themselves differ by a constant.  This allows a\n * fairly fast implementation of the \"brute force\" approach of computing the\n * distance from every colormap entry to every histogram cell.  Unfortunately,\n * it needs a work array to hold the best-distance-so-far for each histogram\n * cell (because the inner loop has to be over cells, not colormap entries).\n * The work array elements have to be INT32s, so the work array would need\n * 256Kb at our recommended precision.  This is not feasible in DOS machines.\n *\n * To get around these problems, we apply Thomas' method to compute the\n * nearest colors for only the cells within a small subbox of the histogram.\n * The work array need be only as big as the subbox, so the memory usage\n * problem is solved.  Furthermore, we need not fill subboxes that are never\n * referenced in pass2; many images use only part of the color gamut, so a\n * fair amount of work is saved.  An additional advantage of this\n * approach is that we can apply Heckbert's locality criterion to quickly\n * eliminate colormap entries that are far away from the subbox; typically\n * three-fourths of the colormap entries are rejected by Heckbert's criterion,\n * and we need not compute their distances to individual cells in the subbox.\n * The speed of this approach is heavily influenced by the subbox size: too\n * small means too much overhead, too big loses because Heckbert's criterion\n * can't eliminate as many colormap entries.  Empirically the best subbox\n * size seems to be about 1/512th of the histogram (1/8th in each direction).\n *\n * Thomas' article also describes a refined method which is asymptotically\n * faster than the brute-force method, but it is also far more complex and\n * cannot efficiently be applied to small subboxes.  It is therefore not\n * useful for programs intended to be portable to DOS machines.  On machines\n * with plenty of memory, filling the whole histogram in one shot with Thomas'\n * refined method might be faster than the present code --- but then again,\n * it might not be any faster, and it's certainly more complicated.\n */\n\n\n/* log2(histogram cells in update box) for each axis; this can be adjusted */\n#define BOX_C0_LOG  (HIST_C0_BITS-3)\n#define BOX_C1_LOG  (HIST_C1_BITS-3)\n#define BOX_C2_LOG  (HIST_C2_BITS-3)\n\n#define BOX_C0_ELEMS  (1<<BOX_C0_LOG) /* # of hist cells in update box */\n#define BOX_C1_ELEMS  (1<<BOX_C1_LOG)\n#define BOX_C2_ELEMS  (1<<BOX_C2_LOG)\n\n#define BOX_C0_SHIFT  (C0_SHIFT + BOX_C0_LOG)\n#define BOX_C1_SHIFT  (C1_SHIFT + BOX_C1_LOG)\n#define BOX_C2_SHIFT  (C2_SHIFT + BOX_C2_LOG)\n\n\n/*\n * The next three routines implement inverse colormap filling.  They could\n * all be folded into one big routine, but splitting them up this way saves\n * some stack space (the mindist[] and bestdist[] arrays need not coexist)\n * and may allow some compilers to produce better code by registerizing more\n * inner-loop variables.\n */\n\nLOCAL(int)\nfind_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,\n\t\t    JSAMPLE colorlist[])\n/* Locate the colormap entries close enough to an update box to be candidates\n * for the nearest entry to some cell(s) in the update box.  The update box\n * is specified by the center coordinates of its first cell.  The number of\n * candidate colormap entries is returned, and their colormap indexes are\n * placed in colorlist[].\n * This routine uses Heckbert's \"locally sorted search\" criterion to select\n * the colors that need further consideration.\n */\n{\n  int numcolors = cinfo->actual_number_of_colors;\n  int maxc0, maxc1, maxc2;\n  int centerc0, centerc1, centerc2;\n  int i, x, ncolors;\n  INT32 minmaxdist, min_dist, max_dist, tdist;\n  INT32 mindist[MAXNUMCOLORS];\t/* min distance to colormap entry i */\n\n  /* Compute true coordinates of update box's upper corner and center.\n   * Actually we compute the coordinates of the center of the upper-corner\n   * histogram cell, which are the upper bounds of the volume we care about.\n   * Note that since \">>\" rounds down, the \"center\" values may be closer to\n   * min than to max; hence comparisons to them must be \"<=\", not \"<\".\n   */\n  maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));\n  centerc0 = (minc0 + maxc0) >> 1;\n  maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));\n  centerc1 = (minc1 + maxc1) >> 1;\n  maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));\n  centerc2 = (minc2 + maxc2) >> 1;\n\n  /* For each color in colormap, find:\n   *  1. its minimum squared-distance to any point in the update box\n   *     (zero if color is within update box);\n   *  2. its maximum squared-distance to any point in the update box.\n   * Both of these can be found by considering only the corners of the box.\n   * We save the minimum distance for each color in mindist[];\n   * only the smallest maximum distance is of interest.\n   */\n  minmaxdist = 0x7FFFFFFFL;\n\n  for (i = 0; i < numcolors; i++) {\n    /* We compute the squared-c0-distance term, then add in the other two. */\n    x = GETJSAMPLE(cinfo->colormap[0][i]);\n    if (x < minc0) {\n      tdist = (x - minc0) * C0_SCALE;\n      min_dist = tdist*tdist;\n      tdist = (x - maxc0) * C0_SCALE;\n      max_dist = tdist*tdist;\n    } else if (x > maxc0) {\n      tdist = (x - maxc0) * C0_SCALE;\n      min_dist = tdist*tdist;\n      tdist = (x - minc0) * C0_SCALE;\n      max_dist = tdist*tdist;\n    } else {\n      /* within cell range so no contribution to min_dist */\n      min_dist = 0;\n      if (x <= centerc0) {\n\ttdist = (x - maxc0) * C0_SCALE;\n\tmax_dist = tdist*tdist;\n      } else {\n\ttdist = (x - minc0) * C0_SCALE;\n\tmax_dist = tdist*tdist;\n      }\n    }\n\n    x = GETJSAMPLE(cinfo->colormap[1][i]);\n    if (x < minc1) {\n      tdist = (x - minc1) * C1_SCALE;\n      min_dist += tdist*tdist;\n      tdist = (x - maxc1) * C1_SCALE;\n      max_dist += tdist*tdist;\n    } else if (x > maxc1) {\n      tdist = (x - maxc1) * C1_SCALE;\n      min_dist += tdist*tdist;\n      tdist = (x - minc1) * C1_SCALE;\n      max_dist += tdist*tdist;\n    } else {\n      /* within cell range so no contribution to min_dist */\n      if (x <= centerc1) {\n\ttdist = (x - maxc1) * C1_SCALE;\n\tmax_dist += tdist*tdist;\n      } else {\n\ttdist = (x - minc1) * C1_SCALE;\n\tmax_dist += tdist*tdist;\n      }\n    }\n\n    x = GETJSAMPLE(cinfo->colormap[2][i]);\n    if (x < minc2) {\n      tdist = (x - minc2) * C2_SCALE;\n      min_dist += tdist*tdist;\n      tdist = (x - maxc2) * C2_SCALE;\n      max_dist += tdist*tdist;\n    } else if (x > maxc2) {\n      tdist = (x - maxc2) * C2_SCALE;\n      min_dist += tdist*tdist;\n      tdist = (x - minc2) * C2_SCALE;\n      max_dist += tdist*tdist;\n    } else {\n      /* within cell range so no contribution to min_dist */\n      if (x <= centerc2) {\n\ttdist = (x - maxc2) * C2_SCALE;\n\tmax_dist += tdist*tdist;\n      } else {\n\ttdist = (x - minc2) * C2_SCALE;\n\tmax_dist += tdist*tdist;\n      }\n    }\n\n    mindist[i] = min_dist;\t/* save away the results */\n    if (max_dist < minmaxdist)\n      minmaxdist = max_dist;\n  }\n\n  /* Now we know that no cell in the update box is more than minmaxdist\n   * away from some colormap entry.  Therefore, only colors that are\n   * within minmaxdist of some part of the box need be considered.\n   */\n  ncolors = 0;\n  for (i = 0; i < numcolors; i++) {\n    if (mindist[i] <= minmaxdist)\n      colorlist[ncolors++] = (JSAMPLE) i;\n  }\n  return ncolors;\n}\n\n\nLOCAL(void)\nfind_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,\n\t\t  int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])\n/* Find the closest colormap entry for each cell in the update box,\n * given the list of candidate colors prepared by find_nearby_colors.\n * Return the indexes of the closest entries in the bestcolor[] array.\n * This routine uses Thomas' incremental distance calculation method to\n * find the distance from a colormap entry to successive cells in the box.\n */\n{\n  int ic0, ic1, ic2;\n  int i, icolor;\n  register INT32 * bptr;\t/* pointer into bestdist[] array */\n  JSAMPLE * cptr;\t\t/* pointer into bestcolor[] array */\n  INT32 dist0, dist1;\t\t/* initial distance values */\n  register INT32 dist2;\t\t/* current distance in inner loop */\n  INT32 xx0, xx1;\t\t/* distance increments */\n  register INT32 xx2;\n  INT32 inc0, inc1, inc2;\t/* initial values for increments */\n  /* This array holds the distance to the nearest-so-far color for each cell */\n  INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];\n\n  /* Initialize best-distance for each cell of the update box */\n  bptr = bestdist;\n  for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)\n    *bptr++ = 0x7FFFFFFFL;\n  \n  /* For each color selected by find_nearby_colors,\n   * compute its distance to the center of each cell in the box.\n   * If that's less than best-so-far, update best distance and color number.\n   */\n  \n  /* Nominal steps between cell centers (\"x\" in Thomas article) */\n#define STEP_C0  ((1 << C0_SHIFT) * C0_SCALE)\n#define STEP_C1  ((1 << C1_SHIFT) * C1_SCALE)\n#define STEP_C2  ((1 << C2_SHIFT) * C2_SCALE)\n  \n  for (i = 0; i < numcolors; i++) {\n    icolor = GETJSAMPLE(colorlist[i]);\n    /* Compute (square of) distance from minc0/c1/c2 to this color */\n    inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;\n    dist0 = inc0*inc0;\n    inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;\n    dist0 += inc1*inc1;\n    inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;\n    dist0 += inc2*inc2;\n    /* Form the initial difference increments */\n    inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;\n    inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;\n    inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;\n    /* Now loop over all cells in box, updating distance per Thomas method */\n    bptr = bestdist;\n    cptr = bestcolor;\n    xx0 = inc0;\n    for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {\n      dist1 = dist0;\n      xx1 = inc1;\n      for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {\n\tdist2 = dist1;\n\txx2 = inc2;\n\tfor (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {\n\t  if (dist2 < *bptr) {\n\t    *bptr = dist2;\n\t    *cptr = (JSAMPLE) icolor;\n\t  }\n\t  dist2 += xx2;\n\t  xx2 += 2 * STEP_C2 * STEP_C2;\n\t  bptr++;\n\t  cptr++;\n\t}\n\tdist1 += xx1;\n\txx1 += 2 * STEP_C1 * STEP_C1;\n      }\n      dist0 += xx0;\n      xx0 += 2 * STEP_C0 * STEP_C0;\n    }\n  }\n}\n\n\nLOCAL(void)\nfill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)\n/* Fill the inverse-colormap entries in the update box that contains */\n/* histogram cell c0/c1/c2.  (Only that one cell MUST be filled, but */\n/* we can fill as many others as we wish.) */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  int minc0, minc1, minc2;\t/* lower left corner of update box */\n  int ic0, ic1, ic2;\n  register JSAMPLE * cptr;\t/* pointer into bestcolor[] array */\n  register histptr cachep;\t/* pointer into main cache array */\n  /* This array lists the candidate colormap indexes. */\n  JSAMPLE colorlist[MAXNUMCOLORS];\n  int numcolors;\t\t/* number of candidate colors */\n  /* This array holds the actually closest colormap index for each cell. */\n  JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];\n\n  /* Convert cell coordinates to update box ID */\n  c0 >>= BOX_C0_LOG;\n  c1 >>= BOX_C1_LOG;\n  c2 >>= BOX_C2_LOG;\n\n  /* Compute true coordinates of update box's origin corner.\n   * Actually we compute the coordinates of the center of the corner\n   * histogram cell, which are the lower bounds of the volume we care about.\n   */\n  minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);\n  minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);\n  minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);\n  \n  /* Determine which colormap entries are close enough to be candidates\n   * for the nearest entry to some cell in the update box.\n   */\n  numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);\n\n  /* Determine the actually nearest colors. */\n  find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,\n\t\t   bestcolor);\n\n  /* Save the best color numbers (plus 1) in the main cache array */\n  c0 <<= BOX_C0_LOG;\t\t/* convert ID back to base cell indexes */\n  c1 <<= BOX_C1_LOG;\n  c2 <<= BOX_C2_LOG;\n  cptr = bestcolor;\n  for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {\n    for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {\n      cachep = & histogram[c0+ic0][c1+ic1][c2];\n      for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {\n\t*cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);\n      }\n    }\n  }\n}\n\n\n/*\n * Map some rows of pixels to the output colormapped representation.\n */\n\nMETHODDEF(void)\npass2_no_dither (j_decompress_ptr cinfo,\n\t\t JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)\n/* This version performs no dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  register JSAMPROW inptr, outptr;\n  register histptr cachep;\n  register int c0, c1, c2;\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n\n  for (row = 0; row < num_rows; row++) {\n    inptr = input_buf[row];\n    outptr = output_buf[row];\n    for (col = width; col > 0; col--) {\n      /* get pixel value and index into the cache */\n      c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;\n      c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;\n      c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;\n      cachep = & histogram[c0][c1][c2];\n      /* If we have not seen this color before, find nearest colormap entry */\n      /* and update the cache */\n      if (*cachep == 0)\n\tfill_inverse_cmap(cinfo, c0,c1,c2);\n      /* Now emit the colormap index for this cell */\n      *outptr++ = (JSAMPLE) (*cachep - 1);\n    }\n  }\n}\n\n\nMETHODDEF(void)\npass2_fs_dither (j_decompress_ptr cinfo,\n\t\t JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)\n/* This version performs Floyd-Steinberg dithering */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  register LOCFSERROR cur0, cur1, cur2;\t/* current error or pixel value */\n  LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */\n  LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */\n  register FSERRPTR errorptr;\t/* => fserrors[] at column before current */\n  JSAMPROW inptr;\t\t/* => current input pixel */\n  JSAMPROW outptr;\t\t/* => current output pixel */\n  histptr cachep;\n  int dir;\t\t\t/* +1 or -1 depending on direction */\n  int dir3;\t\t\t/* 3*dir, for advancing inptr & errorptr */\n  int row;\n  JDIMENSION col;\n  JDIMENSION width = cinfo->output_width;\n  JSAMPLE *range_limit = cinfo->sample_range_limit;\n  int *error_limit = cquantize->error_limiter;\n  JSAMPROW colormap0 = cinfo->colormap[0];\n  JSAMPROW colormap1 = cinfo->colormap[1];\n  JSAMPROW colormap2 = cinfo->colormap[2];\n  SHIFT_TEMPS\n\n  for (row = 0; row < num_rows; row++) {\n    inptr = input_buf[row];\n    outptr = output_buf[row];\n    if (cquantize->on_odd_row) {\n      /* work right to left in this row */\n      inptr += (width-1) * 3;\t/* so point to rightmost pixel */\n      outptr += width-1;\n      dir = -1;\n      dir3 = -3;\n      errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */\n      cquantize->on_odd_row = FALSE; /* flip for next time */\n    } else {\n      /* work left to right in this row */\n      dir = 1;\n      dir3 = 3;\n      errorptr = cquantize->fserrors; /* => entry before first real column */\n      cquantize->on_odd_row = TRUE; /* flip for next time */\n    }\n    /* Preset error values: no error propagated to first pixel from left */\n    cur0 = cur1 = cur2 = 0;\n    /* and no error propagated to row below yet */\n    belowerr0 = belowerr1 = belowerr2 = 0;\n    bpreverr0 = bpreverr1 = bpreverr2 = 0;\n\n    for (col = width; col > 0; col--) {\n      /* curN holds the error propagated from the previous pixel on the\n       * current line.  Add the error propagated from the previous line\n       * to form the complete error correction term for this pixel, and\n       * round the error term (which is expressed * 16) to an integer.\n       * RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct\n       * for either sign of the error value.\n       * Note: errorptr points to *previous* column's array entry.\n       */\n      cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);\n      cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);\n      cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);\n      /* Limit the error using transfer function set by init_error_limit.\n       * See comments with init_error_limit for rationale.\n       */\n      cur0 = error_limit[cur0];\n      cur1 = error_limit[cur1];\n      cur2 = error_limit[cur2];\n      /* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.\n       * The maximum error is +- MAXJSAMPLE (or less with error limiting);\n       * this sets the required size of the range_limit array.\n       */\n      cur0 += GETJSAMPLE(inptr[0]);\n      cur1 += GETJSAMPLE(inptr[1]);\n      cur2 += GETJSAMPLE(inptr[2]);\n      cur0 = GETJSAMPLE(range_limit[cur0]);\n      cur1 = GETJSAMPLE(range_limit[cur1]);\n      cur2 = GETJSAMPLE(range_limit[cur2]);\n      /* Index into the cache with adjusted pixel value */\n      cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];\n      /* If we have not seen this color before, find nearest colormap */\n      /* entry and update the cache */\n      if (*cachep == 0)\n\tfill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);\n      /* Now emit the colormap index for this cell */\n      { register int pixcode = *cachep - 1;\n\t*outptr = (JSAMPLE) pixcode;\n\t/* Compute representation error for this pixel */\n\tcur0 -= GETJSAMPLE(colormap0[pixcode]);\n\tcur1 -= GETJSAMPLE(colormap1[pixcode]);\n\tcur2 -= GETJSAMPLE(colormap2[pixcode]);\n      }\n      /* Compute error fractions to be propagated to adjacent pixels.\n       * Add these into the running sums, and simultaneously shift the\n       * next-line error sums left by 1 column.\n       */\n      { register LOCFSERROR bnexterr, delta;\n\n\tbnexterr = cur0;\t/* Process component 0 */\n\tdelta = cur0 * 2;\n\tcur0 += delta;\t\t/* form error * 3 */\n\terrorptr[0] = (FSERROR) (bpreverr0 + cur0);\n\tcur0 += delta;\t\t/* form error * 5 */\n\tbpreverr0 = belowerr0 + cur0;\n\tbelowerr0 = bnexterr;\n\tcur0 += delta;\t\t/* form error * 7 */\n\tbnexterr = cur1;\t/* Process component 1 */\n\tdelta = cur1 * 2;\n\tcur1 += delta;\t\t/* form error * 3 */\n\terrorptr[1] = (FSERROR) (bpreverr1 + cur1);\n\tcur1 += delta;\t\t/* form error * 5 */\n\tbpreverr1 = belowerr1 + cur1;\n\tbelowerr1 = bnexterr;\n\tcur1 += delta;\t\t/* form error * 7 */\n\tbnexterr = cur2;\t/* Process component 2 */\n\tdelta = cur2 * 2;\n\tcur2 += delta;\t\t/* form error * 3 */\n\terrorptr[2] = (FSERROR) (bpreverr2 + cur2);\n\tcur2 += delta;\t\t/* form error * 5 */\n\tbpreverr2 = belowerr2 + cur2;\n\tbelowerr2 = bnexterr;\n\tcur2 += delta;\t\t/* form error * 7 */\n      }\n      /* At this point curN contains the 7/16 error value to be propagated\n       * to the next pixel on the current line, and all the errors for the\n       * next line have been shifted over.  We are therefore ready to move on.\n       */\n      inptr += dir3;\t\t/* Advance pixel pointers to next column */\n      outptr += dir;\n      errorptr += dir3;\t\t/* advance errorptr to current column */\n    }\n    /* Post-loop cleanup: we must unload the final error values into the\n     * final fserrors[] entry.  Note we need not unload belowerrN because\n     * it is for the dummy column before or after the actual array.\n     */\n    errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */\n    errorptr[1] = (FSERROR) bpreverr1;\n    errorptr[2] = (FSERROR) bpreverr2;\n  }\n}\n\n\n/*\n * Initialize the error-limiting transfer function (lookup table).\n * The raw F-S error computation can potentially compute error values of up to\n * +- MAXJSAMPLE.  But we want the maximum correction applied to a pixel to be\n * much less, otherwise obviously wrong pixels will be created.  (Typical\n * effects include weird fringes at color-area boundaries, isolated bright\n * pixels in a dark area, etc.)  The standard advice for avoiding this problem\n * is to ensure that the \"corners\" of the color cube are allocated as output\n * colors; then repeated errors in the same direction cannot cause cascading\n * error buildup.  However, that only prevents the error from getting\n * completely out of hand; Aaron Giles reports that error limiting improves\n * the results even with corner colors allocated.\n * A simple clamping of the error values to about +- MAXJSAMPLE/8 works pretty\n * well, but the smoother transfer function used below is even better.  Thanks\n * to Aaron Giles for this idea.\n */\n\nLOCAL(void)\ninit_error_limit (j_decompress_ptr cinfo)\n/* Allocate and fill in the error_limiter table */\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  int * table;\n  int in, out;\n\n  table = (int *) (*cinfo->mem->alloc_small)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));\n  table += MAXJSAMPLE;\t\t/* so can index -MAXJSAMPLE .. +MAXJSAMPLE */\n  cquantize->error_limiter = table;\n\n#define STEPSIZE ((MAXJSAMPLE+1)/16)\n  /* Map errors 1:1 up to +- MAXJSAMPLE/16 */\n  out = 0;\n  for (in = 0; in < STEPSIZE; in++, out++) {\n    table[in] = out; table[-in] = -out;\n  }\n  /* Map errors 1:2 up to +- 3*MAXJSAMPLE/16 */\n  for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {\n    table[in] = out; table[-in] = -out;\n  }\n  /* Clamp the rest to final out value (which is (MAXJSAMPLE+1)/8) */\n  for (; in <= MAXJSAMPLE; in++) {\n    table[in] = out; table[-in] = -out;\n  }\n#undef STEPSIZE\n}\n\n\n/*\n * Finish up at the end of each pass.\n */\n\nMETHODDEF(void)\nfinish_pass1 (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n\n  /* Select the representative colors and fill in cinfo->colormap */\n  cinfo->colormap = cquantize->sv_colormap;\n  select_colors(cinfo, cquantize->desired);\n  /* Force next pass to zero the color index table */\n  cquantize->needs_zeroed = TRUE;\n}\n\n\nMETHODDEF(void)\nfinish_pass2 (j_decompress_ptr cinfo)\n{\n  /* no work */\n}\n\n\n/*\n * Initialize for each processing pass.\n */\n\nMETHODDEF(void)\nstart_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n  hist3d histogram = cquantize->histogram;\n  int i;\n\n  /* Only F-S dithering or no dithering is supported. */\n  /* If user asks for ordered dither, give him F-S. */\n  if (cinfo->dither_mode != JDITHER_NONE)\n    cinfo->dither_mode = JDITHER_FS;\n\n  if (is_pre_scan) {\n    /* Set up method pointers */\n    cquantize->pub.color_quantize = prescan_quantize;\n    cquantize->pub.finish_pass = finish_pass1;\n    cquantize->needs_zeroed = TRUE; /* Always zero histogram */\n  } else {\n    /* Set up method pointers */\n    if (cinfo->dither_mode == JDITHER_FS)\n      cquantize->pub.color_quantize = pass2_fs_dither;\n    else\n      cquantize->pub.color_quantize = pass2_no_dither;\n    cquantize->pub.finish_pass = finish_pass2;\n\n    /* Make sure color count is acceptable */\n    i = cinfo->actual_number_of_colors;\n    if (i < 1)\n      ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);\n    if (i > MAXNUMCOLORS)\n      ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);\n\n    if (cinfo->dither_mode == JDITHER_FS) {\n      size_t arraysize = (size_t) ((cinfo->output_width + 2) *\n\t\t\t\t   (3 * SIZEOF(FSERROR)));\n      /* Allocate Floyd-Steinberg workspace if we didn't already. */\n      if (cquantize->fserrors == NULL)\n\tcquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)\n\t  ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);\n      /* Initialize the propagated errors to zero. */\n      FMEMZERO((void FAR *) cquantize->fserrors, arraysize);\n      /* Make the error-limit table if we didn't already. */\n      if (cquantize->error_limiter == NULL)\n\tinit_error_limit(cinfo);\n      cquantize->on_odd_row = FALSE;\n    }\n\n  }\n  /* Zero the histogram or inverse color map, if necessary */\n  if (cquantize->needs_zeroed) {\n    for (i = 0; i < HIST_C0_ELEMS; i++) {\n      FMEMZERO((void FAR *) histogram[i],\n\t       HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));\n    }\n    cquantize->needs_zeroed = FALSE;\n  }\n}\n\n\n/*\n * Switch to a new external colormap between output passes.\n */\n\nMETHODDEF(void)\nnew_color_map_2_quant (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;\n\n  /* Reset the inverse color map */\n  cquantize->needs_zeroed = TRUE;\n}\n\n\n/*\n * Module initialization routine for 2-pass color quantization.\n */\n\nGLOBAL(void)\njinit_2pass_quantizer (j_decompress_ptr cinfo)\n{\n  my_cquantize_ptr cquantize;\n  int i;\n\n  cquantize = (my_cquantize_ptr)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\tSIZEOF(my_cquantizer));\n  cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;\n  cquantize->pub.start_pass = start_pass_2_quant;\n  cquantize->pub.new_color_map = new_color_map_2_quant;\n  cquantize->fserrors = NULL;\t/* flag optional arrays not allocated */\n  cquantize->error_limiter = NULL;\n\n  /* Make sure jdmaster didn't give me a case I can't handle */\n  if (cinfo->out_color_components != 3)\n    ERREXIT(cinfo, JERR_NOTIMPL);\n\n  /* Allocate the histogram/inverse colormap storage */\n  cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));\n  for (i = 0; i < HIST_C0_ELEMS; i++) {\n    cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));\n  }\n  cquantize->needs_zeroed = TRUE; /* histogram is garbage now */\n\n  /* Allocate storage for the completed colormap, if required.\n   * We do this now since it is FAR storage and may affect\n   * the memory manager's space calculations.\n   */\n  if (cinfo->enable_2pass_quant) {\n    /* Make sure color count is acceptable */\n    int desired = cinfo->desired_number_of_colors;\n    /* Lower bound on # of colors ... somewhat arbitrary as long as > 0 */\n    if (desired < 8)\n      ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);\n    /* Make sure colormap indexes can be represented by JSAMPLEs */\n    if (desired > MAXNUMCOLORS)\n      ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);\n    cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);\n    cquantize->desired = desired;\n  } else\n    cquantize->sv_colormap = NULL;\n\n  /* Only F-S dithering or no dithering is supported. */\n  /* If user asks for ordered dither, give him F-S. */\n  if (cinfo->dither_mode != JDITHER_NONE)\n    cinfo->dither_mode = JDITHER_FS;\n\n  /* Allocate Floyd-Steinberg workspace if necessary.\n   * This isn't really needed until pass 2, but again it is FAR storage.\n   * Although we will cope with a later change in dither_mode,\n   * we do not promise to honor max_memory_to_use if dither_mode changes.\n   */\n  if (cinfo->dither_mode == JDITHER_FS) {\n    cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));\n    /* Might as well create the error-limiting table too. */\n    init_error_limit(cinfo);\n  }\n}\n\n#endif /* QUANT_2PASS_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jutils.c",
    "content": "/*\n * jutils.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2009-2011 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains tables and miscellaneous utility routines needed\n * for both compression and decompression.\n * Note we prefix all global names with \"j\" to minimize conflicts with\n * a surrounding application.\n */\n\n#define JPEG_INTERNALS\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n\n\n/*\n * jpeg_zigzag_order[i] is the zigzag-order position of the i'th element\n * of a DCT block read in natural order (left to right, top to bottom).\n */\n\n#if 0\t\t\t\t/* This table is not actually needed in v6a */\n\nconst int jpeg_zigzag_order[DCTSIZE2] = {\n   0,  1,  5,  6, 14, 15, 27, 28,\n   2,  4,  7, 13, 16, 26, 29, 42,\n   3,  8, 12, 17, 25, 30, 41, 43,\n   9, 11, 18, 24, 31, 40, 44, 53,\n  10, 19, 23, 32, 39, 45, 52, 54,\n  20, 22, 33, 38, 46, 51, 55, 60,\n  21, 34, 37, 47, 50, 56, 59, 61,\n  35, 36, 48, 49, 57, 58, 62, 63\n};\n\n#endif\n\n/*\n * jpeg_natural_order[i] is the natural-order position of the i'th element\n * of zigzag order.\n *\n * When reading corrupted data, the Huffman decoders could attempt\n * to reference an entry beyond the end of this array (if the decoded\n * zero run length reaches past the end of the block).  To prevent\n * wild stores without adding an inner-loop test, we put some extra\n * \"63\"s after the real entries.  This will cause the extra coefficient\n * to be stored in location 63 of the block, not somewhere random.\n * The worst case would be a run-length of 15, which means we need 16\n * fake entries.\n */\n\nconst int jpeg_natural_order[DCTSIZE2+16] = {\n  0,  1,  8, 16,  9,  2,  3, 10,\n 17, 24, 32, 25, 18, 11,  4,  5,\n 12, 19, 26, 33, 40, 48, 41, 34,\n 27, 20, 13,  6,  7, 14, 21, 28,\n 35, 42, 49, 56, 57, 50, 43, 36,\n 29, 22, 15, 23, 30, 37, 44, 51,\n 58, 59, 52, 45, 38, 31, 39, 46,\n 53, 60, 61, 54, 47, 55, 62, 63,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order7[7*7+16] = {\n  0,  1,  8, 16,  9,  2,  3, 10,\n 17, 24, 32, 25, 18, 11,  4,  5,\n 12, 19, 26, 33, 40, 48, 41, 34,\n 27, 20, 13,  6, 14, 21, 28, 35,\n 42, 49, 50, 43, 36, 29, 22, 30,\n 37, 44, 51, 52, 45, 38, 46, 53,\n 54,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order6[6*6+16] = {\n  0,  1,  8, 16,  9,  2,  3, 10,\n 17, 24, 32, 25, 18, 11,  4,  5,\n 12, 19, 26, 33, 40, 41, 34, 27,\n 20, 13, 21, 28, 35, 42, 43, 36,\n 29, 37, 44, 45,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order5[5*5+16] = {\n  0,  1,  8, 16,  9,  2,  3, 10,\n 17, 24, 32, 25, 18, 11,  4, 12,\n 19, 26, 33, 34, 27, 20, 28, 35,\n 36,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order4[4*4+16] = {\n  0,  1,  8, 16,  9,  2,  3, 10,\n 17, 24, 25, 18, 11, 19, 26, 27,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order3[3*3+16] = {\n  0,  1,  8, 16,  9,  2, 10, 17,\n 18,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\nconst int jpeg_natural_order2[2*2+16] = {\n  0,  1,  8,  9,\n 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */\n 63, 63, 63, 63, 63, 63, 63, 63\n};\n\n\n/*\n * Arithmetic utilities\n */\n\nGLOBAL(long)\njdiv_round_up (long a, long b)\n/* Compute a/b rounded up to next integer, ie, ceil(a/b) */\n/* Assumes a >= 0, b > 0 */\n{\n  return (a + b - 1L) / b;\n}\n\n\nGLOBAL(long)\njround_up (long a, long b)\n/* Compute a rounded up to next multiple of b, ie, ceil(a/b)*b */\n/* Assumes a >= 0, b > 0 */\n{\n  a += b - 1L;\n  return a - (a % b);\n}\n\n\n/* On normal machines we can apply MEMCOPY() and MEMZERO() to sample arrays\n * and coefficient-block arrays.  This won't work on 80x86 because the arrays\n * are FAR and we're assuming a small-pointer memory model.  However, some\n * DOS compilers provide far-pointer versions of memcpy() and memset() even\n * in the small-model libraries.  These will be used if USE_FMEM is defined.\n * Otherwise, the routines below do it the hard way.  (The performance cost\n * is not all that great, because these routines aren't very heavily used.)\n */\n\n#ifndef NEED_FAR_POINTERS\t/* normal case, same as regular macro */\n#define FMEMCOPY(dest,src,size)\tMEMCOPY(dest,src,size)\n#else\t\t\t\t/* 80x86 case, define if we can */\n#ifdef USE_FMEM\n#define FMEMCOPY(dest,src,size)\t_fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))\n#else\n/* This function is for use by the FMEMZERO macro defined in jpegint.h.\n * Do not call this function directly, use the FMEMZERO macro instead.\n */\nGLOBAL(void)\njzero_far (void FAR * target, size_t bytestozero)\n/* Zero out a chunk of FAR memory. */\n/* This might be sample-array data, block-array data, or alloc_large data. */\n{\n  register char FAR * ptr = (char FAR *) target;\n  register size_t count;\n\n  for (count = bytestozero; count > 0; count--) {\n    *ptr++ = 0;\n  }\n}\n#endif\n#endif\n\n\nGLOBAL(void)\njcopy_sample_rows (JSAMPARRAY input_array, int source_row,\n\t\t   JSAMPARRAY output_array, int dest_row,\n\t\t   int num_rows, JDIMENSION num_cols)\n/* Copy some rows of samples from one place to another.\n * num_rows rows are copied from input_array[source_row++]\n * to output_array[dest_row++]; these areas may overlap for duplication.\n * The source and destination arrays must be at least as wide as num_cols.\n */\n{\n  register JSAMPROW inptr, outptr;\n#ifdef FMEMCOPY\n  register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));\n#else\n  register JDIMENSION count;\n#endif\n  register int row;\n\n  input_array += source_row;\n  output_array += dest_row;\n\n  for (row = num_rows; row > 0; row--) {\n    inptr = *input_array++;\n    outptr = *output_array++;\n#ifdef FMEMCOPY\n    FMEMCOPY(outptr, inptr, count);\n#else\n    for (count = num_cols; count > 0; count--)\n      *outptr++ = *inptr++;\t/* needn't bother with GETJSAMPLE() here */\n#endif\n  }\n}\n\n\nGLOBAL(void)\njcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,\n\t\t JDIMENSION num_blocks)\n/* Copy a row of coefficient blocks from one place to another. */\n{\n#ifdef FMEMCOPY\n  FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));\n#else\n  register JCOEFPTR inptr, outptr;\n  register long count;\n\n  inptr = (JCOEFPTR) input_row;\n  outptr = (JCOEFPTR) output_row;\n  for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {\n    *outptr++ = *inptr++;\n  }\n#endif\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/jversion.h",
    "content": "/*\n * jversion.h\n *\n * Copyright (C) 1991-2016, Thomas G. Lane, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains software version identification.\n */\n\n\n#define JVERSION\t\"9b  17-Jan-2016\"\n\n#define JCOPYRIGHT\t\"Copyright (C) 2016, Thomas G. Lane, Guido Vollbeding\"\n"
  },
  {
    "path": "tess-two/jni/libjpeg/libjpeg.txt",
    "content": "USING THE IJG JPEG LIBRARY\n\nCopyright (C) 1994-2013, Thomas G. Lane, Guido Vollbeding.\nThis file is part of the Independent JPEG Group's software.\nFor conditions of distribution and use, see the accompanying README file.\n\n\nThis file describes how to use the IJG JPEG library within an application\nprogram.  Read it if you want to write a program that uses the library.\n\nThe file example.c provides heavily commented skeleton code for calling the\nJPEG library.  Also see jpeglib.h (the include file to be used by application\nprograms) for full details about data structures and function parameter lists.\nThe library source code, of course, is the ultimate reference.\n\nNote that there have been *major* changes from the application interface\npresented by IJG version 4 and earlier versions.  The old design had several\ninherent limitations, and it had accumulated a lot of cruft as we added\nfeatures while trying to minimize application-interface changes.  We have\nsacrificed backward compatibility in the version 5 rewrite, but we think the\nimprovements justify this.\n\n\nTABLE OF CONTENTS\n-----------------\n\nOverview:\n\tFunctions provided by the library\n\tOutline of typical usage\nBasic library usage:\n\tData formats\n\tCompression details\n\tDecompression details\n\tMechanics of usage: include files, linking, etc\nAdvanced features:\n\tCompression parameter selection\n\tDecompression parameter selection\n\tSpecial color spaces\n\tError handling\n\tCompressed data handling (source and destination managers)\n\tI/O suspension\n\tProgressive JPEG support\n\tBuffered-image mode\n\tAbbreviated datastreams and multiple images\n\tSpecial markers\n\tRaw (downsampled) image data\n\tReally raw data: DCT coefficients\n\tProgress monitoring\n\tMemory management\n\tMemory usage\n\tLibrary compile-time options\n\tPortability considerations\n\tNotes for MS-DOS implementors\n\nYou should read at least the overview and basic usage sections before trying\nto program with the library.  The sections on advanced features can be read\nif and when you need them.\n\n\nOVERVIEW\n========\n\nFunctions provided by the library\n---------------------------------\n\nThe IJG JPEG library provides C code to read and write JPEG-compressed image\nfiles.  The surrounding application program receives or supplies image data a\nscanline at a time, using a straightforward uncompressed image format.  All\ndetails of color conversion and other preprocessing/postprocessing can be\nhandled by the library.\n\nThe library includes a substantial amount of code that is not covered by the\nJPEG standard but is necessary for typical applications of JPEG.  These\nfunctions preprocess the image before JPEG compression or postprocess it after\ndecompression.  They include colorspace conversion, downsampling/upsampling,\nand color quantization.  The application indirectly selects use of this code\nby specifying the format in which it wishes to supply or receive image data.\nFor example, if colormapped output is requested, then the decompression\nlibrary automatically invokes color quantization.\n\nA wide range of quality vs. speed tradeoffs are possible in JPEG processing,\nand even more so in decompression postprocessing.  The decompression library\nprovides multiple implementations that cover most of the useful tradeoffs,\nranging from very-high-quality down to fast-preview operation.  On the\ncompression side we have generally not provided low-quality choices, since\ncompression is normally less time-critical.  It should be understood that the\nlow-quality modes may not meet the JPEG standard's accuracy requirements;\nnonetheless, they are useful for viewers.\n\nA word about functions *not* provided by the library.  We handle a subset of\nthe ISO JPEG standard; most baseline, extended-sequential, and progressive\nJPEG processes are supported.  (Our subset includes all features now in common\nuse.)  Unsupported ISO options include:\n\t* Hierarchical storage\n\t* Lossless JPEG\n\t* DNL marker\n\t* Nonintegral subsampling ratios\nWe support 8-bit to 12-bit data precision, but this is a compile-time choice\nrather than a run-time choice; hence it is difficult to use different\nprecisions in a single application.\n\nBy itself, the library handles only interchange JPEG datastreams --- in\nparticular the widely used JFIF file format.  The library can be used by\nsurrounding code to process interchange or abbreviated JPEG datastreams that\nare embedded in more complex file formats.  (For example, this library is\nused by the free LIBTIFF library to support JPEG compression in TIFF.)\n\n\nOutline of typical usage\n------------------------\n\nThe rough outline of a JPEG compression operation is:\n\n\tAllocate and initialize a JPEG compression object\n\tSpecify the destination for the compressed data (eg, a file)\n\tSet parameters for compression, including image size & colorspace\n\tjpeg_start_compress(...);\n\twhile (scan lines remain to be written)\n\t\tjpeg_write_scanlines(...);\n\tjpeg_finish_compress(...);\n\tRelease the JPEG compression object\n\nA JPEG compression object holds parameters and working state for the JPEG\nlibrary.  We make creation/destruction of the object separate from starting\nor finishing compression of an image; the same object can be re-used for a\nseries of image compression operations.  This makes it easy to re-use the\nsame parameter settings for a sequence of images.  Re-use of a JPEG object\nalso has important implications for processing abbreviated JPEG datastreams,\nas discussed later.\n\nThe image data to be compressed is supplied to jpeg_write_scanlines() from\nin-memory buffers.  If the application is doing file-to-file compression,\nreading image data from the source file is the application's responsibility.\nThe library emits compressed data by calling a \"data destination manager\",\nwhich typically will write the data into a file; but the application can\nprovide its own destination manager to do something else.\n\nSimilarly, the rough outline of a JPEG decompression operation is:\n\n\tAllocate and initialize a JPEG decompression object\n\tSpecify the source of the compressed data (eg, a file)\n\tCall jpeg_read_header() to obtain image info\n\tSet parameters for decompression\n\tjpeg_start_decompress(...);\n\twhile (scan lines remain to be read)\n\t\tjpeg_read_scanlines(...);\n\tjpeg_finish_decompress(...);\n\tRelease the JPEG decompression object\n\nThis is comparable to the compression outline except that reading the\ndatastream header is a separate step.  This is helpful because information\nabout the image's size, colorspace, etc is available when the application\nselects decompression parameters.  For example, the application can choose an\noutput scaling ratio that will fit the image into the available screen size.\n\nThe decompression library obtains compressed data by calling a data source\nmanager, which typically will read the data from a file; but other behaviors\ncan be obtained with a custom source manager.  Decompressed data is delivered\ninto in-memory buffers passed to jpeg_read_scanlines().\n\nIt is possible to abort an incomplete compression or decompression operation\nby calling jpeg_abort(); or, if you do not need to retain the JPEG object,\nsimply release it by calling jpeg_destroy().\n\nJPEG compression and decompression objects are two separate struct types.\nHowever, they share some common fields, and certain routines such as\njpeg_destroy() can work on either type of object.\n\nThe JPEG library has no static variables: all state is in the compression\nor decompression object.  Therefore it is possible to process multiple\ncompression and decompression operations concurrently, using multiple JPEG\nobjects.\n\nBoth compression and decompression can be done in an incremental memory-to-\nmemory fashion, if suitable source/destination managers are used.  See the\nsection on \"I/O suspension\" for more details.\n\n\nBASIC LIBRARY USAGE\n===================\n\nData formats\n------------\n\nBefore diving into procedural details, it is helpful to understand the\nimage data format that the JPEG library expects or returns.\n\nThe standard input image format is a rectangular array of pixels, with each\npixel having the same number of \"component\" or \"sample\" values (color\nchannels).  You must specify how many components there are and the colorspace\ninterpretation of the components.  Most applications will use RGB data\n(three components per pixel) or grayscale data (one component per pixel).\nPLEASE NOTE THAT RGB DATA IS THREE SAMPLES PER PIXEL, GRAYSCALE ONLY ONE.\nA remarkable number of people manage to miss this, only to find that their\nprograms don't work with grayscale JPEG files.\n\nThere is no provision for colormapped input.  JPEG files are always full-color\nor full grayscale (or sometimes another colorspace such as CMYK).  You can\nfeed in a colormapped image by expanding it to full-color format.  However\nJPEG often doesn't work very well with source data that has been colormapped,\nbecause of dithering noise.  This is discussed in more detail in the JPEG FAQ\nand the other references mentioned in the README file.\n\nPixels are stored by scanlines, with each scanline running from left to\nright.  The component values for each pixel are adjacent in the row; for\nexample, R,G,B,R,G,B,R,G,B,... for 24-bit RGB color.  Each scanline is an\narray of data type JSAMPLE --- which is typically \"unsigned char\", unless\nyou've changed jmorecfg.h.  (You can also change the RGB pixel layout, say\nto B,G,R order, by modifying jmorecfg.h.  But see the restrictions listed in\nthat file before doing so.)\n\nA 2-D array of pixels is formed by making a list of pointers to the starts of\nscanlines; so the scanlines need not be physically adjacent in memory.  Even\nif you process just one scanline at a time, you must make a one-element\npointer array to conform to this structure.  Pointers to JSAMPLE rows are of\ntype JSAMPROW, and the pointer to the pointer array is of type JSAMPARRAY.\n\nThe library accepts or supplies one or more complete scanlines per call.\nIt is not possible to process part of a row at a time.  Scanlines are always\nprocessed top-to-bottom.  You can process an entire image in one call if you\nhave it all in memory, but usually it's simplest to process one scanline at\na time.\n\nFor best results, source data values should have the precision specified by\nBITS_IN_JSAMPLE (normally 8 bits).  For instance, if you choose to compress\ndata that's only 6 bits/channel, you should left-justify each value in a\nbyte before passing it to the compressor.  If you need to compress data\nthat has more than 8 bits/channel, compile with BITS_IN_JSAMPLE = 9 to 12.\n(See \"Library compile-time options\", later.)\n\n\nThe data format returned by the decompressor is the same in all details,\nexcept that colormapped output is supported.  (Again, a JPEG file is never\ncolormapped.  But you can ask the decompressor to perform on-the-fly color\nquantization to deliver colormapped output.)  If you request colormapped\noutput then the returned data array contains a single JSAMPLE per pixel;\nits value is an index into a color map.  The color map is represented as\na 2-D JSAMPARRAY in which each row holds the values of one color component,\nthat is, colormap[i][j] is the value of the i'th color component for pixel\nvalue (map index) j.  Note that since the colormap indexes are stored in\nJSAMPLEs, the maximum number of colors is limited by the size of JSAMPLE\n(ie, at most 256 colors for an 8-bit JPEG library).\n\n\nCompression details\n-------------------\n\nHere we revisit the JPEG compression outline given in the overview.\n\n1. Allocate and initialize a JPEG compression object.\n\nA JPEG compression object is a \"struct jpeg_compress_struct\".  (It also has\na bunch of subsidiary structures which are allocated via malloc(), but the\napplication doesn't control those directly.)  This struct can be just a local\nvariable in the calling routine, if a single routine is going to execute the\nwhole JPEG compression sequence.  Otherwise it can be static or allocated\nfrom malloc().\n\nYou will also need a structure representing a JPEG error handler.  The part\nof this that the library cares about is a \"struct jpeg_error_mgr\".  If you\nare providing your own error handler, you'll typically want to embed the\njpeg_error_mgr struct in a larger structure; this is discussed later under\n\"Error handling\".  For now we'll assume you are just using the default error\nhandler.  The default error handler will print JPEG error/warning messages\non stderr, and it will call exit() if a fatal error occurs.\n\nYou must initialize the error handler structure, store a pointer to it into\nthe JPEG object's \"err\" field, and then call jpeg_create_compress() to\ninitialize the rest of the JPEG object.\n\nTypical code for this step, if you are using the default error handler, is\n\n\tstruct jpeg_compress_struct cinfo;\n\tstruct jpeg_error_mgr jerr;\n\t...\n\tcinfo.err = jpeg_std_error(&jerr);\n\tjpeg_create_compress(&cinfo);\n\njpeg_create_compress allocates a small amount of memory, so it could fail\nif you are out of memory.  In that case it will exit via the error handler;\nthat's why the error handler must be initialized first.\n\n\n2. Specify the destination for the compressed data (eg, a file).\n\nAs previously mentioned, the JPEG library delivers compressed data to a\n\"data destination\" module.  The library includes one data destination\nmodule which knows how to write to a stdio stream.  You can use your own\ndestination module if you want to do something else, as discussed later.\n\nIf you use the standard destination module, you must open the target stdio\nstream beforehand.  Typical code for this step looks like:\n\n\tFILE * outfile;\n\t...\n\tif ((outfile = fopen(filename, \"wb\")) == NULL) {\n\t    fprintf(stderr, \"can't open %s\\n\", filename);\n\t    exit(1);\n\t}\n\tjpeg_stdio_dest(&cinfo, outfile);\n\nwhere the last line invokes the standard destination module.\n\nWARNING: it is critical that the binary compressed data be delivered to the\noutput file unchanged.  On non-Unix systems the stdio library may perform\nnewline translation or otherwise corrupt binary data.  To suppress this\nbehavior, you may need to use a \"b\" option to fopen (as shown above), or use\nsetmode() or another routine to put the stdio stream in binary mode.  See\ncjpeg.c and djpeg.c for code that has been found to work on many systems.\n\nYou can select the data destination after setting other parameters (step 3),\nif that's more convenient.  You may not change the destination between\ncalling jpeg_start_compress() and jpeg_finish_compress().\n\n\n3. Set parameters for compression, including image size & colorspace.\n\nYou must supply information about the source image by setting the following\nfields in the JPEG object (cinfo structure):\n\n\timage_width\t\tWidth of image, in pixels\n\timage_height\t\tHeight of image, in pixels\n\tinput_components\tNumber of color channels (samples per pixel)\n\tin_color_space\t\tColor space of source image\n\nThe image dimensions are, hopefully, obvious.  JPEG supports image dimensions\nof 1 to 64K pixels in either direction.  The input color space is typically\nRGB or grayscale, and input_components is 3 or 1 accordingly.  (See \"Special\ncolor spaces\", later, for more info.)  The in_color_space field must be\nassigned one of the J_COLOR_SPACE enum constants, typically JCS_RGB or\nJCS_GRAYSCALE.\n\nJPEG has a large number of compression parameters that determine how the\nimage is encoded.  Most applications don't need or want to know about all\nthese parameters.  You can set all the parameters to reasonable defaults by\ncalling jpeg_set_defaults(); then, if there are particular values you want\nto change, you can do so after that.  The \"Compression parameter selection\"\nsection tells about all the parameters.\n\nYou must set in_color_space correctly before calling jpeg_set_defaults(),\nbecause the defaults depend on the source image colorspace.  However the\nother three source image parameters need not be valid until you call\njpeg_start_compress().  There's no harm in calling jpeg_set_defaults() more\nthan once, if that happens to be convenient.\n\nTypical code for a 24-bit RGB source image is\n\n\tcinfo.image_width = Width; \t/* image width and height, in pixels */\n\tcinfo.image_height = Height;\n\tcinfo.input_components = 3;\t/* # of color components per pixel */\n\tcinfo.in_color_space = JCS_RGB; /* colorspace of input image */\n\n\tjpeg_set_defaults(&cinfo);\n\t/* Make optional parameter settings here */\n\n\n4. jpeg_start_compress(...);\n\nAfter you have established the data destination and set all the necessary\nsource image info and other parameters, call jpeg_start_compress() to begin\na compression cycle.  This will initialize internal state, allocate working\nstorage, and emit the first few bytes of the JPEG datastream header.\n\nTypical code:\n\n\tjpeg_start_compress(&cinfo, TRUE);\n\nThe \"TRUE\" parameter ensures that a complete JPEG interchange datastream\nwill be written.  This is appropriate in most cases.  If you think you might\nwant to use an abbreviated datastream, read the section on abbreviated\ndatastreams, below.\n\nOnce you have called jpeg_start_compress(), you may not alter any JPEG\nparameters or other fields of the JPEG object until you have completed\nthe compression cycle.\n\n\n5. while (scan lines remain to be written)\n\tjpeg_write_scanlines(...);\n\nNow write all the required image data by calling jpeg_write_scanlines()\none or more times.  You can pass one or more scanlines in each call, up\nto the total image height.  In most applications it is convenient to pass\njust one or a few scanlines at a time.  The expected format for the passed\ndata is discussed under \"Data formats\", above.\n\nImage data should be written in top-to-bottom scanline order.  The JPEG spec\ncontains some weasel wording about how top and bottom are application-defined\nterms (a curious interpretation of the English language...) but if you want\nyour files to be compatible with everyone else's, you WILL use top-to-bottom\norder.  If the source data must be read in bottom-to-top order, you can use\nthe JPEG library's virtual array mechanism to invert the data efficiently.\nExamples of this can be found in the sample application cjpeg.\n\nThe library maintains a count of the number of scanlines written so far\nin the next_scanline field of the JPEG object.  Usually you can just use\nthis variable as the loop counter, so that the loop test looks like\n\"while (cinfo.next_scanline < cinfo.image_height)\".\n\nCode for this step depends heavily on the way that you store the source data.\nexample.c shows the following code for the case of a full-size 2-D source\narray containing 3-byte RGB pixels:\n\n\tJSAMPROW row_pointer[1];\t/* pointer to a single row */\n\tint row_stride;\t\t\t/* physical row width in buffer */\n\n\trow_stride = image_width * 3;\t/* JSAMPLEs per row in image_buffer */\n\n\twhile (cinfo.next_scanline < cinfo.image_height) {\n\t    row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];\n\t    jpeg_write_scanlines(&cinfo, row_pointer, 1);\n\t}\n\njpeg_write_scanlines() returns the number of scanlines actually written.\nThis will normally be equal to the number passed in, so you can usually\nignore the return value.  It is different in just two cases:\n  * If you try to write more scanlines than the declared image height,\n    the additional scanlines are ignored.\n  * If you use a suspending data destination manager, output buffer overrun\n    will cause the compressor to return before accepting all the passed lines.\n    This feature is discussed under \"I/O suspension\", below.  The normal\n    stdio destination manager will NOT cause this to happen.\nIn any case, the return value is the same as the change in the value of\nnext_scanline.\n\n\n6. jpeg_finish_compress(...);\n\nAfter all the image data has been written, call jpeg_finish_compress() to\ncomplete the compression cycle.  This step is ESSENTIAL to ensure that the\nlast bufferload of data is written to the data destination.\njpeg_finish_compress() also releases working memory associated with the JPEG\nobject.\n\nTypical code:\n\n\tjpeg_finish_compress(&cinfo);\n\nIf using the stdio destination manager, don't forget to close the output\nstdio stream (if necessary) afterwards.\n\nIf you have requested a multi-pass operating mode, such as Huffman code\noptimization, jpeg_finish_compress() will perform the additional passes using\ndata buffered by the first pass.  In this case jpeg_finish_compress() may take\nquite a while to complete.  With the default compression parameters, this will\nnot happen.\n\nIt is an error to call jpeg_finish_compress() before writing the necessary\ntotal number of scanlines.  If you wish to abort compression, call\njpeg_abort() as discussed below.\n\nAfter completing a compression cycle, you may dispose of the JPEG object\nas discussed next, or you may use it to compress another image.  In that case\nreturn to step 2, 3, or 4 as appropriate.  If you do not change the\ndestination manager, the new datastream will be written to the same target.\nIf you do not change any JPEG parameters, the new datastream will be written\nwith the same parameters as before.  Note that you can change the input image\ndimensions freely between cycles, but if you change the input colorspace, you\nshould call jpeg_set_defaults() to adjust for the new colorspace; and then\nyou'll need to repeat all of step 3.\n\n\n7. Release the JPEG compression object.\n\nWhen you are done with a JPEG compression object, destroy it by calling\njpeg_destroy_compress().  This will free all subsidiary memory (regardless of\nthe previous state of the object).  Or you can call jpeg_destroy(), which\nworks for either compression or decompression objects --- this may be more\nconvenient if you are sharing code between compression and decompression\ncases.  (Actually, these routines are equivalent except for the declared type\nof the passed pointer.  To avoid gripes from ANSI C compilers, jpeg_destroy()\nshould be passed a j_common_ptr.)\n\nIf you allocated the jpeg_compress_struct structure from malloc(), freeing\nit is your responsibility --- jpeg_destroy() won't.  Ditto for the error\nhandler structure.\n\nTypical code:\n\n\tjpeg_destroy_compress(&cinfo);\n\n\n8. Aborting.\n\nIf you decide to abort a compression cycle before finishing, you can clean up\nin either of two ways:\n\n* If you don't need the JPEG object any more, just call\n  jpeg_destroy_compress() or jpeg_destroy() to release memory.  This is\n  legitimate at any point after calling jpeg_create_compress() --- in fact,\n  it's safe even if jpeg_create_compress() fails.\n\n* If you want to re-use the JPEG object, call jpeg_abort_compress(), or call\n  jpeg_abort() which works on both compression and decompression objects.\n  This will return the object to an idle state, releasing any working memory.\n  jpeg_abort() is allowed at any time after successful object creation.\n\nNote that cleaning up the data destination, if required, is your\nresponsibility; neither of these routines will call term_destination().\n(See \"Compressed data handling\", below, for more about that.)\n\njpeg_destroy() and jpeg_abort() are the only safe calls to make on a JPEG\nobject that has reported an error by calling error_exit (see \"Error handling\"\nfor more info).  The internal state of such an object is likely to be out of\nwhack.  Either of these two routines will return the object to a known state.\n\n\nDecompression details\n---------------------\n\nHere we revisit the JPEG decompression outline given in the overview.\n\n1. Allocate and initialize a JPEG decompression object.\n\nThis is just like initialization for compression, as discussed above,\nexcept that the object is a \"struct jpeg_decompress_struct\" and you\ncall jpeg_create_decompress().  Error handling is exactly the same.\n\nTypical code:\n\n\tstruct jpeg_decompress_struct cinfo;\n\tstruct jpeg_error_mgr jerr;\n\t...\n\tcinfo.err = jpeg_std_error(&jerr);\n\tjpeg_create_decompress(&cinfo);\n\n(Both here and in the IJG code, we usually use variable name \"cinfo\" for\nboth compression and decompression objects.)\n\n\n2. Specify the source of the compressed data (eg, a file).\n\nAs previously mentioned, the JPEG library reads compressed data from a \"data\nsource\" module.  The library includes one data source module which knows how\nto read from a stdio stream.  You can use your own source module if you want\nto do something else, as discussed later.\n\nIf you use the standard source module, you must open the source stdio stream\nbeforehand.  Typical code for this step looks like:\n\n\tFILE * infile;\n\t...\n\tif ((infile = fopen(filename, \"rb\")) == NULL) {\n\t    fprintf(stderr, \"can't open %s\\n\", filename);\n\t    exit(1);\n\t}\n\tjpeg_stdio_src(&cinfo, infile);\n\nwhere the last line invokes the standard source module.\n\nWARNING: it is critical that the binary compressed data be read unchanged.\nOn non-Unix systems the stdio library may perform newline translation or\notherwise corrupt binary data.  To suppress this behavior, you may need to use\na \"b\" option to fopen (as shown above), or use setmode() or another routine to\nput the stdio stream in binary mode.  See cjpeg.c and djpeg.c for code that\nhas been found to work on many systems.\n\nYou may not change the data source between calling jpeg_read_header() and\njpeg_finish_decompress().  If you wish to read a series of JPEG images from\na single source file, you should repeat the jpeg_read_header() to\njpeg_finish_decompress() sequence without reinitializing either the JPEG\nobject or the data source module; this prevents buffered input data from\nbeing discarded.\n\n\n3. Call jpeg_read_header() to obtain image info.\n\nTypical code for this step is just\n\n\tjpeg_read_header(&cinfo, TRUE);\n\nThis will read the source datastream header markers, up to the beginning\nof the compressed data proper.  On return, the image dimensions and other\ninfo have been stored in the JPEG object.  The application may wish to\nconsult this information before selecting decompression parameters.\n\nMore complex code is necessary if\n  * A suspending data source is used --- in that case jpeg_read_header()\n    may return before it has read all the header data.  See \"I/O suspension\",\n    below.  The normal stdio source manager will NOT cause this to happen.\n  * Abbreviated JPEG files are to be processed --- see the section on\n    abbreviated datastreams.  Standard applications that deal only in\n    interchange JPEG files need not be concerned with this case either.\n\nIt is permissible to stop at this point if you just wanted to find out the\nimage dimensions and other header info for a JPEG file.  In that case,\ncall jpeg_destroy() when you are done with the JPEG object, or call\njpeg_abort() to return it to an idle state before selecting a new data\nsource and reading another header.\n\n\n4. Set parameters for decompression.\n\njpeg_read_header() sets appropriate default decompression parameters based on\nthe properties of the image (in particular, its colorspace).  However, you\nmay well want to alter these defaults before beginning the decompression.\nFor example, the default is to produce full color output from a color file.\nIf you want colormapped output you must ask for it.  Other options allow the\nreturned image to be scaled and allow various speed/quality tradeoffs to be\nselected.  \"Decompression parameter selection\", below, gives details.\n\nIf the defaults are appropriate, nothing need be done at this step.\n\nNote that all default values are set by each call to jpeg_read_header().\nIf you reuse a decompression object, you cannot expect your parameter\nsettings to be preserved across cycles, as you can for compression.\nYou must set desired parameter values each time.\n\n\n5. jpeg_start_decompress(...);\n\nOnce the parameter values are satisfactory, call jpeg_start_decompress() to\nbegin decompression.  This will initialize internal state, allocate working\nmemory, and prepare for returning data.\n\nTypical code is just\n\n\tjpeg_start_decompress(&cinfo);\n\nIf you have requested a multi-pass operating mode, such as 2-pass color\nquantization, jpeg_start_decompress() will do everything needed before data\noutput can begin.  In this case jpeg_start_decompress() may take quite a while\nto complete.  With a single-scan (non progressive) JPEG file and default\ndecompression parameters, this will not happen; jpeg_start_decompress() will\nreturn quickly.\n\nAfter this call, the final output image dimensions, including any requested\nscaling, are available in the JPEG object; so is the selected colormap, if\ncolormapped output has been requested.  Useful fields include\n\n\toutput_width\t\timage width and height, as scaled\n\toutput_height\n\tout_color_components\t# of color components in out_color_space\n\toutput_components\t# of color components returned per pixel\n\tcolormap\t\tthe selected colormap, if any\n\tactual_number_of_colors\t\tnumber of entries in colormap\n\noutput_components is 1 (a colormap index) when quantizing colors; otherwise it\nequals out_color_components.  It is the number of JSAMPLE values that will be\nemitted per pixel in the output arrays.\n\nTypically you will need to allocate data buffers to hold the incoming image.\nYou will need output_width * output_components JSAMPLEs per scanline in your\noutput buffer, and a total of output_height scanlines will be returned.\n\nNote: if you are using the JPEG library's internal memory manager to allocate\ndata buffers (as djpeg does), then the manager's protocol requires that you\nrequest large buffers *before* calling jpeg_start_decompress().  This is a\nlittle tricky since the output_XXX fields are not normally valid then.  You\ncan make them valid by calling jpeg_calc_output_dimensions() after setting the\nrelevant parameters (scaling, output color space, and quantization flag).\n\n\n6. while (scan lines remain to be read)\n\tjpeg_read_scanlines(...);\n\nNow you can read the decompressed image data by calling jpeg_read_scanlines()\none or more times.  At each call, you pass in the maximum number of scanlines\nto be read (ie, the height of your working buffer); jpeg_read_scanlines()\nwill return up to that many lines.  The return value is the number of lines\nactually read.  The format of the returned data is discussed under \"Data\nformats\", above.  Don't forget that grayscale and color JPEGs will return\ndifferent data formats!\n\nImage data is returned in top-to-bottom scanline order.  If you must write\nout the image in bottom-to-top order, you can use the JPEG library's virtual\narray mechanism to invert the data efficiently.  Examples of this can be\nfound in the sample application djpeg.\n\nThe library maintains a count of the number of scanlines returned so far\nin the output_scanline field of the JPEG object.  Usually you can just use\nthis variable as the loop counter, so that the loop test looks like\n\"while (cinfo.output_scanline < cinfo.output_height)\".  (Note that the test\nshould NOT be against image_height, unless you never use scaling.  The\nimage_height field is the height of the original unscaled image.)\nThe return value always equals the change in the value of output_scanline.\n\nIf you don't use a suspending data source, it is safe to assume that\njpeg_read_scanlines() reads at least one scanline per call, until the\nbottom of the image has been reached.\n\nIf you use a buffer larger than one scanline, it is NOT safe to assume that\njpeg_read_scanlines() fills it.  (The current implementation returns only a\nfew scanlines per call, no matter how large a buffer you pass.)  So you must\nalways provide a loop that calls jpeg_read_scanlines() repeatedly until the\nwhole image has been read.\n\n\n7. jpeg_finish_decompress(...);\n\nAfter all the image data has been read, call jpeg_finish_decompress() to\ncomplete the decompression cycle.  This causes working memory associated\nwith the JPEG object to be released.\n\nTypical code:\n\n\tjpeg_finish_decompress(&cinfo);\n\nIf using the stdio source manager, don't forget to close the source stdio\nstream if necessary.\n\nIt is an error to call jpeg_finish_decompress() before reading the correct\ntotal number of scanlines.  If you wish to abort decompression, call\njpeg_abort() as discussed below.\n\nAfter completing a decompression cycle, you may dispose of the JPEG object as\ndiscussed next, or you may use it to decompress another image.  In that case\nreturn to step 2 or 3 as appropriate.  If you do not change the source\nmanager, the next image will be read from the same source.\n\n\n8. Release the JPEG decompression object.\n\nWhen you are done with a JPEG decompression object, destroy it by calling\njpeg_destroy_decompress() or jpeg_destroy().  The previous discussion of\ndestroying compression objects applies here too.\n\nTypical code:\n\n\tjpeg_destroy_decompress(&cinfo);\n\n\n9. Aborting.\n\nYou can abort a decompression cycle by calling jpeg_destroy_decompress() or\njpeg_destroy() if you don't need the JPEG object any more, or\njpeg_abort_decompress() or jpeg_abort() if you want to reuse the object.\nThe previous discussion of aborting compression cycles applies here too.\n\n\nMechanics of usage: include files, linking, etc\n-----------------------------------------------\n\nApplications using the JPEG library should include the header file jpeglib.h\nto obtain declarations of data types and routines.  Before including\njpeglib.h, include system headers that define at least the typedefs FILE and\nsize_t.  On ANSI-conforming systems, including <stdio.h> is sufficient; on\nolder Unix systems, you may need <sys/types.h> to define size_t.\n\nIf the application needs to refer to individual JPEG library error codes, also\ninclude jerror.h to define those symbols.\n\njpeglib.h indirectly includes the files jconfig.h and jmorecfg.h.  If you are\ninstalling the JPEG header files in a system directory, you will want to\ninstall all four files: jpeglib.h, jerror.h, jconfig.h, jmorecfg.h.\n\nThe most convenient way to include the JPEG code into your executable program\nis to prepare a library file (\"libjpeg.a\", or a corresponding name on non-Unix\nmachines) and reference it at your link step.  If you use only half of the\nlibrary (only compression or only decompression), only that much code will be\nincluded from the library, unless your linker is hopelessly brain-damaged.\nThe supplied makefiles build libjpeg.a automatically (see install.txt).\n\nWhile you can build the JPEG library as a shared library if the whim strikes\nyou, we don't really recommend it.  The trouble with shared libraries is that\nat some point you'll probably try to substitute a new version of the library\nwithout recompiling the calling applications.  That generally doesn't work\nbecause the parameter struct declarations usually change with each new\nversion.  In other words, the library's API is *not* guaranteed binary\ncompatible across versions; we only try to ensure source-code compatibility.\n(In hindsight, it might have been smarter to hide the parameter structs from\napplications and introduce a ton of access functions instead.  Too late now,\nhowever.)\n\nOn some systems your application may need to set up a signal handler to ensure\nthat temporary files are deleted if the program is interrupted.  This is most\ncritical if you are on MS-DOS and use the jmemdos.c memory manager back end;\nit will try to grab extended memory for temp files, and that space will NOT be\nfreed automatically.  See cjpeg.c or djpeg.c for an example signal handler.\n\nIt may be worth pointing out that the core JPEG library does not actually\nrequire the stdio library: only the default source/destination managers and\nerror handler need it.  You can use the library in a stdio-less environment\nif you replace those modules and use jmemnobs.c (or another memory manager of\nyour own devising).  More info about the minimum system library requirements\nmay be found in jinclude.h.\n\n\nADVANCED FEATURES\n=================\n\nCompression parameter selection\n-------------------------------\n\nThis section describes all the optional parameters you can set for JPEG\ncompression, as well as the \"helper\" routines provided to assist in this\ntask.  Proper setting of some parameters requires detailed understanding\nof the JPEG standard; if you don't know what a parameter is for, it's best\nnot to mess with it!  See REFERENCES in the README file for pointers to\nmore info about JPEG.\n\nIt's a good idea to call jpeg_set_defaults() first, even if you plan to set\nall the parameters; that way your code is more likely to work with future JPEG\nlibraries that have additional parameters.  For the same reason, we recommend\nyou use a helper routine where one is provided, in preference to twiddling\ncinfo fields directly.\n\nThe helper routines are:\n\njpeg_set_defaults (j_compress_ptr cinfo)\n\tThis routine sets all JPEG parameters to reasonable defaults, using\n\tonly the input image's color space (field in_color_space, which must\n\talready be set in cinfo).  Many applications will only need to use\n\tthis routine and perhaps jpeg_set_quality().\n\njpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)\n\tSets the JPEG file's colorspace (field jpeg_color_space) as specified,\n\tand sets other color-space-dependent parameters appropriately.  See\n\t\"Special color spaces\", below, before using this.  A large number of\n\tparameters, including all per-component parameters, are set by this\n\troutine; if you want to twiddle individual parameters you should call\n\tjpeg_set_colorspace() before rather than after.\n\njpeg_default_colorspace (j_compress_ptr cinfo)\n\tSelects an appropriate JPEG colorspace based on cinfo->in_color_space,\n\tand calls jpeg_set_colorspace().  This is actually a subroutine of\n\tjpeg_set_defaults().  It's broken out in case you want to change\n\tjust the colorspace-dependent JPEG parameters.\n\njpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)\n\tConstructs JPEG quantization tables appropriate for the indicated\n\tquality setting.  The quality value is expressed on the 0..100 scale\n\trecommended by IJG (cjpeg's \"-quality\" switch uses this routine).\n\tNote that the exact mapping from quality values to tables may change\n\tin future IJG releases as more is learned about DCT quantization.\n\tIf the force_baseline parameter is TRUE, then the quantization table\n\tentries are constrained to the range 1..255 for full JPEG baseline\n\tcompatibility.  In the current implementation, this only makes a\n\tdifference for quality settings below 25, and it effectively prevents\n\tvery small/low quality files from being generated.  The IJG decoder\n\tis capable of reading the non-baseline files generated at low quality\n\tsettings when force_baseline is FALSE, but other decoders may not be.\n\njpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,\n\t\t\t boolean force_baseline)\n\tSame as jpeg_set_quality() except that the generated tables are the\n\tsample tables given in the JPEC spec section K.1, multiplied by the\n\tspecified scale factor (which is expressed as a percentage; thus\n\tscale_factor = 100 reproduces the spec's tables).  Note that larger\n\tscale factors give lower quality.  This entry point is useful for\n\tconforming to the Adobe PostScript DCT conventions, but we do not\n\trecommend linear scaling as a user-visible quality scale otherwise.\n\tforce_baseline again constrains the computed table entries to 1..255.\n\nint jpeg_quality_scaling (int quality)\n\tConverts a value on the IJG-recommended quality scale to a linear\n\tscaling percentage.  Note that this routine may change or go away\n\tin future releases --- IJG may choose to adopt a scaling method that\n\tcan't be expressed as a simple scalar multiplier, in which case the\n\tpremise of this routine collapses.  Caveat user.\n\njpeg_default_qtables (j_compress_ptr cinfo, boolean force_baseline)\n\tSet default quantization tables with linear q_scale_factor[] values\n\t(see below).\n\njpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,\n\t\t      const unsigned int *basic_table,\n\t\t      int scale_factor, boolean force_baseline)\n\tAllows an arbitrary quantization table to be created.  which_tbl\n\tindicates which table slot to fill.  basic_table points to an array\n\tof 64 unsigned ints given in normal array order.  These values are\n\tmultiplied by scale_factor/100 and then clamped to the range 1..65535\n\t(or to 1..255 if force_baseline is TRUE).\n\tCAUTION: prior to library version 6a, jpeg_add_quant_table expected\n\tthe basic table to be given in JPEG zigzag order.  If you need to\n\twrite code that works with either older or newer versions of this\n\troutine, you must check the library version number.  Something like\n\t\"#if JPEG_LIB_VERSION >= 61\" is the right test.\n\njpeg_simple_progression (j_compress_ptr cinfo)\n\tGenerates a default scan script for writing a progressive-JPEG file.\n\tThis is the recommended method of creating a progressive file,\n\tunless you want to make a custom scan sequence.  You must ensure that\n\tthe JPEG color space is set correctly before calling this routine.\n\n\nCompression parameters (cinfo fields) include:\n\nboolean arith_code\n\tIf TRUE, use arithmetic coding.\n\tIf FALSE, use Huffman coding.\n\nint block_size\n\tSet DCT block size.  All N from 1 to 16 are possible.\n\tDefault is 8 (baseline format).\n\tLarger values produce higher compression,\n\tsmaller values produce higher quality.\n\tAn exact DCT stage is possible with 1 or 2.\n\tWith the default quality of 75 and default Luminance qtable\n\tthe DCT+Quantization stage is lossless for value 1.\n\tNote that values other than 8 require a SmartScale capable decoder,\n\tintroduced with IJG JPEG 8.  Setting the block_size parameter for\n\tcompression works with version 8c and later.\n\nJ_DCT_METHOD dct_method\n\tSelects the algorithm used for the DCT step.  Choices are:\n\t\tJDCT_ISLOW: slow but accurate integer algorithm\n\t\tJDCT_IFAST: faster, less accurate integer method\n\t\tJDCT_FLOAT: floating-point method\n\t\tJDCT_DEFAULT: default method (normally JDCT_ISLOW)\n\t\tJDCT_FASTEST: fastest method (normally JDCT_IFAST)\n\tThe FLOAT method is very slightly more accurate than the ISLOW method,\n\tbut may give different results on different machines due to varying\n\troundoff behavior.  The integer methods should give the same results\n\ton all machines.  On machines with sufficiently fast FP hardware, the\n\tfloating-point method may also be the fastest.  The IFAST method is\n\tconsiderably less accurate than the other two; its use is not\n\trecommended if high quality is a concern.  JDCT_DEFAULT and\n\tJDCT_FASTEST are macros configurable by each installation.\n\nunsigned int scale_num, scale_denom\n\tScale the image by the fraction scale_num/scale_denom.  Default is\n\t1/1, or no scaling.  Currently, the supported scaling ratios are\n\tM/N with all N from 1 to 16, where M is the destination DCT size,\n\twhich is 8 by default (see block_size parameter above).\n\t(The library design allows for arbitrary scaling ratios but this\n\tis not likely to be implemented any time soon.)\n\nJ_COLOR_SPACE jpeg_color_space\nint num_components\n\tThe JPEG color space and corresponding number of components; see\n\t\"Special color spaces\", below, for more info.  We recommend using\n\tjpeg_set_colorspace() if you want to change these.\n\nJ_COLOR_TRANSFORM color_transform\n\tInternal color transform identifier, writes LSE marker if nonzero\n\t(requires decoder with inverse color transform support, introduced\n\twith IJG JPEG 9).\n\tTwo values are currently possible: JCT_NONE and JCT_SUBTRACT_GREEN.\n\tSet this value for lossless RGB application *before* calling\n\tjpeg_set_colorspace(), because entropy table assignment in\n\tjpeg_set_colorspace() depends on color_transform.\n\nboolean optimize_coding\n\tTRUE causes the compressor to compute optimal Huffman coding tables\n\tfor the image.  This requires an extra pass over the data and\n\ttherefore costs a good deal of space and time.  The default is\n\tFALSE, which tells the compressor to use the supplied or default\n\tHuffman tables.  In most cases optimal tables save only a few percent\n\tof file size compared to the default tables.  Note that when this is\n\tTRUE, you need not supply Huffman tables at all, and any you do\n\tsupply will be overwritten.\n\nunsigned int restart_interval\nint restart_in_rows\n\tTo emit restart markers in the JPEG file, set one of these nonzero.\n\tSet restart_interval to specify the exact interval in MCU blocks.\n\tSet restart_in_rows to specify the interval in MCU rows.  (If\n\trestart_in_rows is not 0, then restart_interval is set after the\n\timage width in MCUs is computed.)  Defaults are zero (no restarts).\n\tOne restart marker per MCU row is often a good choice.\n\tNOTE: the overhead of restart markers is higher in grayscale JPEG\n\tfiles than in color files, and MUCH higher in progressive JPEGs.\n\tIf you use restarts, you may want to use larger intervals in those\n\tcases.\n\nconst jpeg_scan_info * scan_info\nint num_scans\n\tBy default, scan_info is NULL; this causes the compressor to write a\n\tsingle-scan sequential JPEG file.  If not NULL, scan_info points to\n\tan array of scan definition records of length num_scans.  The\n\tcompressor will then write a JPEG file having one scan for each scan\n\tdefinition record.  This is used to generate noninterleaved or\n\tprogressive JPEG files.  The library checks that the scan array\n\tdefines a valid JPEG scan sequence.  (jpeg_simple_progression creates\n\ta suitable scan definition array for progressive JPEG.)  This is\n\tdiscussed further under \"Progressive JPEG support\".\n\nboolean do_fancy_downsampling\n\tIf TRUE, use direct DCT scaling with DCT size > 8 for downsampling\n\tof chroma components.\n\tIf FALSE, use only DCT size <= 8 and simple separate downsampling.\n\tDefault is TRUE.\n\tFor better image stability in multiple generation compression cycles\n\tit is preferable that this value matches the corresponding\n\tdo_fancy_upsampling value in decompression.\n\nint smoothing_factor\n\tIf non-zero, the input image is smoothed; the value should be 1 for\n\tminimal smoothing to 100 for maximum smoothing.  Consult jcsample.c\n\tfor details of the smoothing algorithm.  The default is zero.\n\nboolean write_JFIF_header\n\tIf TRUE, a JFIF APP0 marker is emitted.  jpeg_set_defaults() and\n\tjpeg_set_colorspace() set this TRUE if a JFIF-legal JPEG color space\n\t(ie, YCbCr or grayscale) is selected, otherwise FALSE.\n\nUINT8 JFIF_major_version\nUINT8 JFIF_minor_version\n\tThe version number to be written into the JFIF marker.\n\tjpeg_set_defaults() initializes the version to 1.01 (major=minor=1).\n\tYou should set it to 1.02 (major=1, minor=2) if you plan to write\n\tany JFIF 1.02 extension markers.\n\nUINT8 density_unit\nUINT16 X_density\nUINT16 Y_density\n\tThe resolution information to be written into the JFIF marker;\n\tnot used otherwise.  density_unit may be 0 for unknown,\n\t1 for dots/inch, or 2 for dots/cm.  The default values are 0,1,1\n\tindicating square pixels of unknown size.\n\nboolean write_Adobe_marker\n\tIf TRUE, an Adobe APP14 marker is emitted.  jpeg_set_defaults() and\n\tjpeg_set_colorspace() set this TRUE if JPEG color space RGB, CMYK,\n\tor YCCK is selected, otherwise FALSE.  It is generally a bad idea\n\tto set both write_JFIF_header and write_Adobe_marker.  In fact,\n\tyou probably shouldn't change the default settings at all --- the\n\tdefault behavior ensures that the JPEG file's color space can be\n\trecognized by the decoder.\n\nJQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS]\n\tPointers to coefficient quantization tables, one per table slot,\n\tor NULL if no table is defined for a slot.  Usually these should\n\tbe set via one of the above helper routines; jpeg_add_quant_table()\n\tis general enough to define any quantization table.  The other\n\troutines will set up table slot 0 for luminance quality and table\n\tslot 1 for chrominance.\n\nint q_scale_factor[NUM_QUANT_TBLS]\n\tLinear quantization scaling factors (percentage, initialized 100)\n\tfor use with jpeg_default_qtables().\n\tSee rdswitch.c and cjpeg.c for an example of usage.\n\tNote that the q_scale_factor[] fields are the \"linear\" scales, so you\n\thave to convert from user-defined ratings via jpeg_quality_scaling().\n\tHere is an example code which corresponds to cjpeg -quality 90,70:\n\n\t\tjpeg_set_defaults(cinfo);\n\n\t\t/* Set luminance quality 90. */\n\t\tcinfo->q_scale_factor[0] = jpeg_quality_scaling(90);\n\t\t/* Set chrominance quality 70. */\n\t\tcinfo->q_scale_factor[1] = jpeg_quality_scaling(70);\n\n\t\tjpeg_default_qtables(cinfo, force_baseline);\n\n\tCAUTION: You must also set 1x1 subsampling for efficient separate\n\tcolor quality selection, since the default value used by library\n\tis 2x2:\n\n\t\tcinfo->comp_info[0].v_samp_factor = 1;\n\t\tcinfo->comp_info[0].h_samp_factor = 1;\n\nJHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS]\nJHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS]\n\tPointers to Huffman coding tables, one per table slot, or NULL if\n\tno table is defined for a slot.  Slots 0 and 1 are filled with the\n\tJPEG sample tables by jpeg_set_defaults().  If you need to allocate\n\tmore table structures, jpeg_alloc_huff_table() may be used.\n\tNote that optimal Huffman tables can be computed for an image\n\tby setting optimize_coding, as discussed above; there's seldom\n\tany need to mess with providing your own Huffman tables.\n\n\nThe actual dimensions of the JPEG image that will be written to the file are\ngiven by the following fields.  These are computed from the input image\ndimensions and the compression parameters by jpeg_start_compress().  You can\nalso call jpeg_calc_jpeg_dimensions() to obtain the values that will result\nfrom the current parameter settings.  This can be useful if you are trying\nto pick a scaling ratio that will get close to a desired target size.\n\nJDIMENSION jpeg_width\t\tActual dimensions of output image.\nJDIMENSION jpeg_height\n\n\nPer-component parameters are stored in the struct cinfo.comp_info[i] for\ncomponent number i.  Note that components here refer to components of the\nJPEG color space, *not* the source image color space.  A suitably large\ncomp_info[] array is allocated by jpeg_set_defaults(); if you choose not\nto use that routine, it's up to you to allocate the array.\n\nint component_id\n\tThe one-byte identifier code to be recorded in the JPEG file for\n\tthis component.  For the standard color spaces, we recommend you\n\tleave the default values alone.\n\nint h_samp_factor\nint v_samp_factor\n\tHorizontal and vertical sampling factors for the component; must\n\tbe 1..4 according to the JPEG standard.  Note that larger sampling\n\tfactors indicate a higher-resolution component; many people find\n\tthis behavior quite unintuitive.  The default values are 2,2 for\n\tluminance components and 1,1 for chrominance components, except\n\tfor grayscale where 1,1 is used.\n\nint quant_tbl_no\n\tQuantization table number for component.  The default value is\n\t0 for luminance components and 1 for chrominance components.\n\nint dc_tbl_no\nint ac_tbl_no\n\tDC and AC entropy coding table numbers.  The default values are\n\t0 for luminance components and 1 for chrominance components.\n\nint component_index\n\tMust equal the component's index in comp_info[].  (Beginning in\n\trelease v6, the compressor library will fill this in automatically;\n\tyou don't have to.)\n\n\nDecompression parameter selection\n---------------------------------\n\nDecompression parameter selection is somewhat simpler than compression\nparameter selection, since all of the JPEG internal parameters are\nrecorded in the source file and need not be supplied by the application.\n(Unless you are working with abbreviated files, in which case see\n\"Abbreviated datastreams\", below.)  Decompression parameters control\nthe postprocessing done on the image to deliver it in a format suitable\nfor the application's use.  Many of the parameters control speed/quality\ntradeoffs, in which faster decompression may be obtained at the price of\na poorer-quality image.  The defaults select the highest quality (slowest)\nprocessing.\n\nThe following fields in the JPEG object are set by jpeg_read_header() and\nmay be useful to the application in choosing decompression parameters:\n\nJDIMENSION image_width\t\t\tWidth and height of image\nJDIMENSION image_height\nint num_components\t\t\tNumber of color components\nJ_COLOR_SPACE jpeg_color_space\t\tColorspace of image\nboolean saw_JFIF_marker\t\t\tTRUE if a JFIF APP0 marker was seen\n  UINT8 JFIF_major_version\t\tVersion information from JFIF marker\n  UINT8 JFIF_minor_version\n  UINT8 density_unit\t\t\tResolution data from JFIF marker\n  UINT16 X_density\n  UINT16 Y_density\nboolean saw_Adobe_marker\t\tTRUE if an Adobe APP14 marker was seen\n  UINT8 Adobe_transform\t\t\tColor transform code from Adobe marker\n\nThe JPEG color space, unfortunately, is something of a guess since the JPEG\nstandard proper does not provide a way to record it.  In practice most files\nadhere to the JFIF or Adobe conventions, and the decoder will recognize these\ncorrectly.  See \"Special color spaces\", below, for more info.\n\n\nThe decompression parameters that determine the basic properties of the\nreturned image are:\n\nJ_COLOR_SPACE out_color_space\n\tOutput color space.  jpeg_read_header() sets an appropriate default\n\tbased on jpeg_color_space; typically it will be RGB or grayscale.\n\tThe application can change this field to request output in a different\n\tcolorspace.  For example, set it to JCS_GRAYSCALE to get grayscale\n\toutput from a color file.  (This is useful for previewing: grayscale\n\toutput is faster than full color since the color components need not\n\tbe processed.)  Note that not all possible color space transforms are\n\tcurrently implemented; you may need to extend jdcolor.c if you want an\n\tunusual conversion.\n\nunsigned int scale_num, scale_denom\n\tScale the image by the fraction scale_num/scale_denom.  Currently,\n\tthe supported scaling ratios are M/N with all M from 1 to 16, where\n\tN is the source DCT size, which is 8 for baseline JPEG.  (The library\n\tdesign allows for arbitrary scaling ratios but this is not likely\n\tto be implemented any time soon.)  The values are initialized by\n\tjpeg_read_header() with the source DCT size.  For baseline JPEG\n\tthis is 8/8.  If you change only the scale_num value while leaving\n\tthe other unchanged, then this specifies the DCT scaled size to be\n\tapplied on the given input.  For baseline JPEG this is equivalent\n\tto M/8 scaling, since the source DCT size for baseline JPEG is 8.\n\tSmaller scaling ratios permit significantly faster decoding since\n\tfewer pixels need be processed and a simpler IDCT method can be used.\n\nboolean quantize_colors\n\tIf set TRUE, colormapped output will be delivered.  Default is FALSE,\n\tmeaning that full-color output will be delivered.\n\nThe next three parameters are relevant only if quantize_colors is TRUE.\n\nint desired_number_of_colors\n\tMaximum number of colors to use in generating a library-supplied color\n\tmap (the actual number of colors is returned in a different field).\n\tDefault 256.  Ignored when the application supplies its own color map.\n\nboolean two_pass_quantize\n\tIf TRUE, an extra pass over the image is made to select a custom color\n\tmap for the image.  This usually looks a lot better than the one-size-\n\tfits-all colormap that is used otherwise.  Default is TRUE.  Ignored\n\twhen the application supplies its own color map.\n\nJ_DITHER_MODE dither_mode\n\tSelects color dithering method.  Supported values are:\n\t\tJDITHER_NONE\tno dithering: fast, very low quality\n\t\tJDITHER_ORDERED\tordered dither: moderate speed and quality\n\t\tJDITHER_FS\tFloyd-Steinberg dither: slow, high quality\n\tDefault is JDITHER_FS.  (At present, ordered dither is implemented\n\tonly in the single-pass, standard-colormap case.  If you ask for\n\tordered dither when two_pass_quantize is TRUE or when you supply\n\tan external color map, you'll get F-S dithering.)\n\nWhen quantize_colors is TRUE, the target color map is described by the next\ntwo fields.  colormap is set to NULL by jpeg_read_header().  The application\ncan supply a color map by setting colormap non-NULL and setting\nactual_number_of_colors to the map size.  Otherwise, jpeg_start_decompress()\nselects a suitable color map and sets these two fields itself.\n[Implementation restriction: at present, an externally supplied colormap is\nonly accepted for 3-component output color spaces.]\n\nJSAMPARRAY colormap\n\tThe color map, represented as a 2-D pixel array of out_color_components\n\trows and actual_number_of_colors columns.  Ignored if not quantizing.\n\tCAUTION: if the JPEG library creates its own colormap, the storage\n\tpointed to by this field is released by jpeg_finish_decompress().\n\tCopy the colormap somewhere else first, if you want to save it.\n\nint actual_number_of_colors\n\tThe number of colors in the color map.\n\nAdditional decompression parameters that the application may set include:\n\nJ_DCT_METHOD dct_method\n\tSelects the algorithm used for the DCT step.  Choices are the same\n\tas described above for compression.\n\nboolean do_fancy_upsampling\n\tIf TRUE, use direct DCT scaling with DCT size > 8 for upsampling\n\tof chroma components.\n\tIf FALSE, use only DCT size <= 8 and simple separate upsampling.\n\tDefault is TRUE.\n\tFor better image stability in multiple generation compression cycles\n\tit is preferable that this value matches the corresponding\n\tdo_fancy_downsampling value in compression.\n\nboolean do_block_smoothing\n\tIf TRUE, interblock smoothing is applied in early stages of decoding\n\tprogressive JPEG files; if FALSE, not.  Default is TRUE.  Early\n\tprogression stages look \"fuzzy\" with smoothing, \"blocky\" without.\n\tIn any case, block smoothing ceases to be applied after the first few\n\tAC coefficients are known to full accuracy, so it is relevant only\n\twhen using buffered-image mode for progressive images.\n\nboolean enable_1pass_quant\nboolean enable_external_quant\nboolean enable_2pass_quant\n\tThese are significant only in buffered-image mode, which is\n\tdescribed in its own section below.\n\n\nThe output image dimensions are given by the following fields.  These are\ncomputed from the source image dimensions and the decompression parameters\nby jpeg_start_decompress().  You can also call jpeg_calc_output_dimensions()\nto obtain the values that will result from the current parameter settings.\nThis can be useful if you are trying to pick a scaling ratio that will get\nclose to a desired target size.  It's also important if you are using the\nJPEG library's memory manager to allocate output buffer space, because you\nare supposed to request such buffers *before* jpeg_start_decompress().\n\nJDIMENSION output_width\t\tActual dimensions of output image.\nJDIMENSION output_height\nint out_color_components\tNumber of color components in out_color_space.\nint output_components\t\tNumber of color components returned.\nint rec_outbuf_height\t\tRecommended height of scanline buffer.\n\nWhen quantizing colors, output_components is 1, indicating a single color map\nindex per pixel.  Otherwise it equals out_color_components.  The output arrays\nare required to be output_width * output_components JSAMPLEs wide.\n\nrec_outbuf_height is the recommended minimum height (in scanlines) of the\nbuffer passed to jpeg_read_scanlines().  If the buffer is smaller, the\nlibrary will still work, but time will be wasted due to unnecessary data\ncopying.  In high-quality modes, rec_outbuf_height is always 1, but some\nfaster, lower-quality modes set it to larger values (typically 2 to 4).\nIf you are going to ask for a high-speed processing mode, you may as well\ngo to the trouble of honoring rec_outbuf_height so as to avoid data copying.\n(An output buffer larger than rec_outbuf_height lines is OK, but won't\nprovide any material speed improvement over that height.)\n\n\nSpecial color spaces\n--------------------\n\nThe JPEG standard itself is \"color blind\" and doesn't specify any particular\ncolor space.  It is customary to convert color data to a luminance/chrominance\ncolor space before compressing, since this permits greater compression.  The\nexisting JPEG file interchange format standards specify YCbCr or GRAYSCALE\ndata (JFIF version 1), GRAYSCALE, RGB, YCbCr, CMYK, or YCCK (Adobe), or BG_RGB\nor BG_YCC (big gamut color spaces, JFIF version 2).  For special applications\nsuch as multispectral images, other color spaces can be used,\nbut it must be understood that such files will be unportable.\n\nThe JPEG library can handle the most common colorspace conversions (namely\nRGB <=> YCbCr and CMYK <=> YCCK).  It can also deal with data of an unknown\ncolor space, passing it through without conversion.  If you deal extensively\nwith an unusual color space, you can easily extend the library to understand\nadditional color spaces and perform appropriate conversions.\n\nFor compression, the source data's color space is specified by field\nin_color_space.  This is transformed to the JPEG file's color space given\nby jpeg_color_space.  jpeg_set_defaults() chooses a reasonable JPEG color\nspace depending on in_color_space, but you can override this by calling\njpeg_set_colorspace().  Of course you must select a supported transformation.\njccolor.c currently supports the following transformations:\n\tRGB => YCbCr\n\tRGB => GRAYSCALE\n\tRGB => BG_YCC\n\tYCbCr => GRAYSCALE\n\tYCbCr => BG_YCC\n\tCMYK => YCCK\nplus the null transforms: GRAYSCALE => GRAYSCALE, RGB => RGB,\nBG_RGB => BG_RGB, YCbCr => YCbCr, BG_YCC => BG_YCC, CMYK => CMYK,\nYCCK => YCCK, and UNKNOWN => UNKNOWN.\n\nThe file interchange format standards (JFIF and Adobe) specify APPn markers\nthat indicate the color space of the JPEG file.  It is important to ensure\nthat these are written correctly, or omitted if the JPEG file's color space\nis not one of the ones supported by the interchange standards.\njpeg_set_colorspace() will set the compression parameters to include or omit\nthe APPn markers properly, so long as it is told the truth about the JPEG\ncolor space.  For example, if you are writing some random 3-component color\nspace without conversion, don't try to fake out the library by setting\nin_color_space and jpeg_color_space to JCS_YCbCr; use JCS_UNKNOWN.\nYou may want to write an APPn marker of your own devising to identify\nthe colorspace --- see \"Special markers\", below.\n\nWhen told that the color space is UNKNOWN, the library will default to using\nluminance-quality compression parameters for all color components.  You may\nwell want to change these parameters.  See the source code for\njpeg_set_colorspace(), in jcparam.c, for details.\n\nFor decompression, the JPEG file's color space is given in jpeg_color_space,\nand this is transformed to the output color space out_color_space.\njpeg_read_header's setting of jpeg_color_space can be relied on if the file\nconforms to JFIF or Adobe conventions, but otherwise it is no better than a\nguess.  If you know the JPEG file's color space for certain, you can override\njpeg_read_header's guess by setting jpeg_color_space.  jpeg_read_header also\nselects a default output color space based on (its guess of) jpeg_color_space;\nset out_color_space to override this.  Again, you must select a supported\ntransformation.  jdcolor.c currently supports\n\tYCbCr => RGB\n\tYCbCr => GRAYSCALE\n\tBG_YCC => RGB\n\tBG_YCC => GRAYSCALE\n\tRGB => GRAYSCALE\n\tGRAYSCALE => RGB\n\tYCCK => CMYK\nas well as the null transforms.  (Since GRAYSCALE=>RGB is provided, an\napplication can force grayscale JPEGs to look like color JPEGs if it only\nwants to handle one case.)\n\nThe two-pass color quantizer, jquant2.c, is specialized to handle RGB data\n(it weights distances appropriately for RGB colors).  You'll need to modify\nthe code if you want to use it for non-RGB output color spaces.  Note that\njquant2.c is used to map to an application-supplied colormap as well as for\nthe normal two-pass colormap selection process.\n\nCAUTION: it appears that Adobe Photoshop writes inverted data in CMYK JPEG\nfiles: 0 represents 100% ink coverage, rather than 0% ink as you'd expect.\nThis is arguably a bug in Photoshop, but if you need to work with Photoshop\nCMYK files, you will have to deal with it in your application.  We cannot\n\"fix\" this in the library by inverting the data during the CMYK<=>YCCK\ntransform, because that would break other applications, notably Ghostscript.\nPhotoshop versions prior to 3.0 write EPS files containing JPEG-encoded CMYK\ndata in the same inverted-YCCK representation used in bare JPEG files, but\nthe surrounding PostScript code performs an inversion using the PS image\noperator.  I am told that Photoshop 3.0 will write uninverted YCCK in\nEPS/JPEG files, and will omit the PS-level inversion.  (But the data\npolarity used in bare JPEG files will not change in 3.0.)  In either case,\nthe JPEG library must not invert the data itself, or else Ghostscript would\nread these EPS files incorrectly.\n\n\nError handling\n--------------\n\nWhen the default error handler is used, any error detected inside the JPEG\nroutines will cause a message to be printed on stderr, followed by exit().\nYou can supply your own error handling routines to override this behavior\nand to control the treatment of nonfatal warnings and trace/debug messages.\nThe file example.c illustrates the most common case, which is to have the\napplication regain control after an error rather than exiting.\n\nThe JPEG library never writes any message directly; it always goes through\nthe error handling routines.  Three classes of messages are recognized:\n  * Fatal errors: the library cannot continue.\n  * Warnings: the library can continue, but the data is corrupt, and a\n    damaged output image is likely to result.\n  * Trace/informational messages.  These come with a trace level indicating\n    the importance of the message; you can control the verbosity of the\n    program by adjusting the maximum trace level that will be displayed.\n\nYou may, if you wish, simply replace the entire JPEG error handling module\n(jerror.c) with your own code.  However, you can avoid code duplication by\nonly replacing some of the routines depending on the behavior you need.\nThis is accomplished by calling jpeg_std_error() as usual, but then overriding\nsome of the method pointers in the jpeg_error_mgr struct, as illustrated by\nexample.c.\n\nAll of the error handling routines will receive a pointer to the JPEG object\n(a j_common_ptr which points to either a jpeg_compress_struct or a\njpeg_decompress_struct; if you need to tell which, test the is_decompressor\nfield).  This struct includes a pointer to the error manager struct in its\n\"err\" field.  Frequently, custom error handler routines will need to access\nadditional data which is not known to the JPEG library or the standard error\nhandler.  The most convenient way to do this is to embed either the JPEG\nobject or the jpeg_error_mgr struct in a larger structure that contains\nadditional fields; then casting the passed pointer provides access to the\nadditional fields.  Again, see example.c for one way to do it.  (Beginning\nwith IJG version 6b, there is also a void pointer \"client_data\" in each\nJPEG object, which the application can also use to find related data.\nThe library does not touch client_data at all.)\n\nThe individual methods that you might wish to override are:\n\nerror_exit (j_common_ptr cinfo)\n\tReceives control for a fatal error.  Information sufficient to\n\tgenerate the error message has been stored in cinfo->err; call\n\toutput_message to display it.  Control must NOT return to the caller;\n\tgenerally this routine will exit() or longjmp() somewhere.\n\tTypically you would override this routine to get rid of the exit()\n\tdefault behavior.  Note that if you continue processing, you should\n\tclean up the JPEG object with jpeg_abort() or jpeg_destroy().\n\noutput_message (j_common_ptr cinfo)\n\tActual output of any JPEG message.  Override this to send messages\n\tsomewhere other than stderr.  Note that this method does not know\n\thow to generate a message, only where to send it.\n\nformat_message (j_common_ptr cinfo, char * buffer)\n\tConstructs a readable error message string based on the error info\n\tstored in cinfo->err.  This method is called by output_message.  Few\n\tapplications should need to override this method.  One possible\n\treason for doing so is to implement dynamic switching of error message\n\tlanguage.\n\nemit_message (j_common_ptr cinfo, int msg_level)\n\tDecide whether or not to emit a warning or trace message; if so,\n\tcalls output_message.  The main reason for overriding this method\n\twould be to abort on warnings.  msg_level is -1 for warnings,\n\t0 and up for trace messages.\n\nOnly error_exit() and emit_message() are called from the rest of the JPEG\nlibrary; the other two are internal to the error handler.\n\nThe actual message texts are stored in an array of strings which is pointed to\nby the field err->jpeg_message_table.  The messages are numbered from 0 to\nerr->last_jpeg_message, and it is these code numbers that are used in the\nJPEG library code.  You could replace the message texts (for instance, with\nmessages in French or German) by changing the message table pointer.  See\njerror.h for the default texts.  CAUTION: this table will almost certainly\nchange or grow from one library version to the next.\n\nIt may be useful for an application to add its own message texts that are\nhandled by the same mechanism.  The error handler supports a second \"add-on\"\nmessage table for this purpose.  To define an addon table, set the pointer\nerr->addon_message_table and the message numbers err->first_addon_message and\nerr->last_addon_message.  If you number the addon messages beginning at 1000\nor so, you won't have to worry about conflicts with the library's built-in\nmessages.  See the sample applications cjpeg/djpeg for an example of using\naddon messages (the addon messages are defined in cderror.h).\n\nActual invocation of the error handler is done via macros defined in jerror.h:\n\tERREXITn(...)\tfor fatal errors\n\tWARNMSn(...)\tfor corrupt-data warnings\n\tTRACEMSn(...)\tfor trace and informational messages.\nThese macros store the message code and any additional parameters into the\nerror handler struct, then invoke the error_exit() or emit_message() method.\nThe variants of each macro are for varying numbers of additional parameters.\nThe additional parameters are inserted into the generated message using\nstandard printf() format codes.\n\nSee jerror.h and jerror.c for further details.\n\n\nCompressed data handling (source and destination managers)\n----------------------------------------------------------\n\nThe JPEG compression library sends its compressed data to a \"destination\nmanager\" module.  The default destination manager just writes the data to a\nmemory buffer or to a stdio stream, but you can provide your own manager to\ndo something else.  Similarly, the decompression library calls a \"source\nmanager\" to obtain the compressed data; you can provide your own source\nmanager if you want the data to come from somewhere other than a memory\nbuffer or a stdio stream.\n\nIn both cases, compressed data is processed a bufferload at a time: the\ndestination or source manager provides a work buffer, and the library invokes\nthe manager only when the buffer is filled or emptied.  (You could define a\none-character buffer to force the manager to be invoked for each byte, but\nthat would be rather inefficient.)  The buffer's size and location are\ncontrolled by the manager, not by the library.  For example, the memory\nsource manager just makes the buffer pointer and length point to the original\ndata in memory.  In this case the buffer-reload procedure will be invoked\nonly if the decompressor ran off the end of the datastream, which would\nindicate an erroneous datastream.\n\nThe work buffer is defined as an array of datatype JOCTET, which is generally\n\"char\" or \"unsigned char\".  On a machine where char is not exactly 8 bits\nwide, you must define JOCTET as a wider data type and then modify the data\nsource and destination modules to transcribe the work arrays into 8-bit units\non external storage.\n\nA data destination manager struct contains a pointer and count defining the\nnext byte to write in the work buffer and the remaining free space:\n\n\tJOCTET * next_output_byte;  /* => next byte to write in buffer */\n\tsize_t free_in_buffer;      /* # of byte spaces remaining in buffer */\n\nThe library increments the pointer and decrements the count until the buffer\nis filled.  The manager's empty_output_buffer method must reset the pointer\nand count.  The manager is expected to remember the buffer's starting address\nand total size in private fields not visible to the library.\n\nA data destination manager provides three methods:\n\ninit_destination (j_compress_ptr cinfo)\n\tInitialize destination.  This is called by jpeg_start_compress()\n\tbefore any data is actually written.  It must initialize\n\tnext_output_byte and free_in_buffer.  free_in_buffer must be\n\tinitialized to a positive value.\n\nempty_output_buffer (j_compress_ptr cinfo)\n\tThis is called whenever the buffer has filled (free_in_buffer\n\treaches zero).  In typical applications, it should write out the\n\t*entire* buffer (use the saved start address and buffer length;\n\tignore the current state of next_output_byte and free_in_buffer).\n\tThen reset the pointer & count to the start of the buffer, and\n\treturn TRUE indicating that the buffer has been dumped.\n\tfree_in_buffer must be set to a positive value when TRUE is\n\treturned.  A FALSE return should only be used when I/O suspension is\n\tdesired (this operating mode is discussed in the next section).\n\nterm_destination (j_compress_ptr cinfo)\n\tTerminate destination --- called by jpeg_finish_compress() after all\n\tdata has been written.  In most applications, this must flush any\n\tdata remaining in the buffer.  Use either next_output_byte or\n\tfree_in_buffer to determine how much data is in the buffer.\n\nterm_destination() is NOT called by jpeg_abort() or jpeg_destroy().  If you\nwant the destination manager to be cleaned up during an abort, you must do it\nyourself.\n\nYou will also need code to create a jpeg_destination_mgr struct, fill in its\nmethod pointers, and insert a pointer to the struct into the \"dest\" field of\nthe JPEG compression object.  This can be done in-line in your setup code if\nyou like, but it's probably cleaner to provide a separate routine similar to\nthe jpeg_stdio_dest() or jpeg_mem_dest() routines of the supplied destination\nmanagers.\n\nDecompression source managers follow a parallel design, but with some\nadditional frammishes.  The source manager struct contains a pointer and count\ndefining the next byte to read from the work buffer and the number of bytes\nremaining:\n\n\tconst JOCTET * next_input_byte; /* => next byte to read from buffer */\n\tsize_t bytes_in_buffer;         /* # of bytes remaining in buffer */\n\nThe library increments the pointer and decrements the count until the buffer\nis emptied.  The manager's fill_input_buffer method must reset the pointer and\ncount.  In most applications, the manager must remember the buffer's starting\naddress and total size in private fields not visible to the library.\n\nA data source manager provides five methods:\n\ninit_source (j_decompress_ptr cinfo)\n\tInitialize source.  This is called by jpeg_read_header() before any\n\tdata is actually read.  Unlike init_destination(), it may leave\n\tbytes_in_buffer set to 0 (in which case a fill_input_buffer() call\n\twill occur immediately).\n\nfill_input_buffer (j_decompress_ptr cinfo)\n\tThis is called whenever bytes_in_buffer has reached zero and more\n\tdata is wanted.  In typical applications, it should read fresh data\n\tinto the buffer (ignoring the current state of next_input_byte and\n\tbytes_in_buffer), reset the pointer & count to the start of the\n\tbuffer, and return TRUE indicating that the buffer has been reloaded.\n\tIt is not necessary to fill the buffer entirely, only to obtain at\n\tleast one more byte.  bytes_in_buffer MUST be set to a positive value\n\tif TRUE is returned.  A FALSE return should only be used when I/O\n\tsuspension is desired (this mode is discussed in the next section).\n\nskip_input_data (j_decompress_ptr cinfo, long num_bytes)\n\tSkip num_bytes worth of data.  The buffer pointer and count should\n\tbe advanced over num_bytes input bytes, refilling the buffer as\n\tneeded.  This is used to skip over a potentially large amount of\n\tuninteresting data (such as an APPn marker).  In some applications\n\tit may be possible to optimize away the reading of the skipped data,\n\tbut it's not clear that being smart is worth much trouble; large\n\tskips are uncommon.  bytes_in_buffer may be zero on return.\n\tA zero or negative skip count should be treated as a no-op.\n\nresync_to_restart (j_decompress_ptr cinfo, int desired)\n\tThis routine is called only when the decompressor has failed to find\n\ta restart (RSTn) marker where one is expected.  Its mission is to\n\tfind a suitable point for resuming decompression.  For most\n\tapplications, we recommend that you just use the default resync\n\tprocedure, jpeg_resync_to_restart().  However, if you are able to back\n\tup in the input data stream, or if you have a-priori knowledge about\n\tthe likely location of restart markers, you may be able to do better.\n\tRead the read_restart_marker() and jpeg_resync_to_restart() routines\n\tin jdmarker.c if you think you'd like to implement your own resync\n\tprocedure.\n\nterm_source (j_decompress_ptr cinfo)\n\tTerminate source --- called by jpeg_finish_decompress() after all\n\tdata has been read.  Often a no-op.\n\nFor both fill_input_buffer() and skip_input_data(), there is no such thing\nas an EOF return.  If the end of the file has been reached, the routine has\na choice of exiting via ERREXIT() or inserting fake data into the buffer.\nIn most cases, generating a warning message and inserting a fake EOI marker\nis the best course of action --- this will allow the decompressor to output\nhowever much of the image is there.  In pathological cases, the decompressor\nmay swallow the EOI and again demand data ... just keep feeding it fake EOIs.\njdatasrc.c illustrates the recommended error recovery behavior.\n\nterm_source() is NOT called by jpeg_abort() or jpeg_destroy().  If you want\nthe source manager to be cleaned up during an abort, you must do it yourself.\n\nYou will also need code to create a jpeg_source_mgr struct, fill in its method\npointers, and insert a pointer to the struct into the \"src\" field of the JPEG\ndecompression object.  This can be done in-line in your setup code if you\nlike, but it's probably cleaner to provide a separate routine similar to the\njpeg_stdio_src() or jpeg_mem_src() routines of the supplied source managers.\n\nFor more information, consult the memory and stdio source and destination\nmanagers in jdatasrc.c and jdatadst.c.\n\n\nI/O suspension\n--------------\n\nSome applications need to use the JPEG library as an incremental memory-to-\nmemory filter: when the compressed data buffer is filled or emptied, they want\ncontrol to return to the outer loop, rather than expecting that the buffer can\nbe emptied or reloaded within the data source/destination manager subroutine.\nThe library supports this need by providing an \"I/O suspension\" mode, which we\ndescribe in this section.\n\nThe I/O suspension mode is not a panacea: nothing is guaranteed about the\nmaximum amount of time spent in any one call to the library, so it will not\neliminate response-time problems in single-threaded applications.  If you\nneed guaranteed response time, we suggest you \"bite the bullet\" and implement\na real multi-tasking capability.\n\nTo use I/O suspension, cooperation is needed between the calling application\nand the data source or destination manager; you will always need a custom\nsource/destination manager.  (Please read the previous section if you haven't\nalready.)  The basic idea is that the empty_output_buffer() or\nfill_input_buffer() routine is a no-op, merely returning FALSE to indicate\nthat it has done nothing.  Upon seeing this, the JPEG library suspends\noperation and returns to its caller.  The surrounding application is\nresponsible for emptying or refilling the work buffer before calling the\nJPEG library again.\n\nCompression suspension:\n\nFor compression suspension, use an empty_output_buffer() routine that returns\nFALSE; typically it will not do anything else.  This will cause the\ncompressor to return to the caller of jpeg_write_scanlines(), with the return\nvalue indicating that not all the supplied scanlines have been accepted.\nThe application must make more room in the output buffer, adjust the output\nbuffer pointer/count appropriately, and then call jpeg_write_scanlines()\nagain, pointing to the first unconsumed scanline.\n\nWhen forced to suspend, the compressor will backtrack to a convenient stopping\npoint (usually the start of the current MCU); it will regenerate some output\ndata when restarted.  Therefore, although empty_output_buffer() is only\ncalled when the buffer is filled, you should NOT write out the entire buffer\nafter a suspension.  Write only the data up to the current position of\nnext_output_byte/free_in_buffer.  The data beyond that point will be\nregenerated after resumption.\n\nBecause of the backtracking behavior, a good-size output buffer is essential\nfor efficiency; you don't want the compressor to suspend often.  (In fact, an\noverly small buffer could lead to infinite looping, if a single MCU required\nmore data than would fit in the buffer.)  We recommend a buffer of at least\nseveral Kbytes.  You may want to insert explicit code to ensure that you don't\ncall jpeg_write_scanlines() unless there is a reasonable amount of space in\nthe output buffer; in other words, flush the buffer before trying to compress\nmore data.\n\nThe compressor does not allow suspension while it is trying to write JPEG\nmarkers at the beginning and end of the file.  This means that:\n  * At the beginning of a compression operation, there must be enough free\n    space in the output buffer to hold the header markers (typically 600 or\n    so bytes).  The recommended buffer size is bigger than this anyway, so\n    this is not a problem as long as you start with an empty buffer.  However,\n    this restriction might catch you if you insert large special markers, such\n    as a JFIF thumbnail image, without flushing the buffer afterwards.\n  * When you call jpeg_finish_compress(), there must be enough space in the\n    output buffer to emit any buffered data and the final EOI marker.  In the\n    current implementation, half a dozen bytes should suffice for this, but\n    for safety's sake we recommend ensuring that at least 100 bytes are free\n    before calling jpeg_finish_compress().\n\nA more significant restriction is that jpeg_finish_compress() cannot suspend.\nThis means you cannot use suspension with multi-pass operating modes, namely\nHuffman code optimization and multiple-scan output.  Those modes write the\nwhole file during jpeg_finish_compress(), which will certainly result in\nbuffer overrun.  (Note that this restriction applies only to compression,\nnot decompression.  The decompressor supports input suspension in all of its\noperating modes.)\n\nDecompression suspension:\n\nFor decompression suspension, use a fill_input_buffer() routine that simply\nreturns FALSE (except perhaps during error recovery, as discussed below).\nThis will cause the decompressor to return to its caller with an indication\nthat suspension has occurred.  This can happen at four places:\n  * jpeg_read_header(): will return JPEG_SUSPENDED.\n  * jpeg_start_decompress(): will return FALSE, rather than its usual TRUE.\n  * jpeg_read_scanlines(): will return the number of scanlines already\n\tcompleted (possibly 0).\n  * jpeg_finish_decompress(): will return FALSE, rather than its usual TRUE.\nThe surrounding application must recognize these cases, load more data into\nthe input buffer, and repeat the call.  In the case of jpeg_read_scanlines(),\nincrement the passed pointers past any scanlines successfully read.\n\nJust as with compression, the decompressor will typically backtrack to a\nconvenient restart point before suspending.  When fill_input_buffer() is\ncalled, next_input_byte/bytes_in_buffer point to the current restart point,\nwhich is where the decompressor will backtrack to if FALSE is returned.\nThe data beyond that position must NOT be discarded if you suspend; it needs\nto be re-read upon resumption.  In most implementations, you'll need to shift\nthis data down to the start of your work buffer and then load more data after\nit.  Again, this behavior means that a several-Kbyte work buffer is essential\nfor decent performance; furthermore, you should load a reasonable amount of\nnew data before resuming decompression.  (If you loaded, say, only one new\nbyte each time around, you could waste a LOT of cycles.)\n\nThe skip_input_data() source manager routine requires special care in a\nsuspension scenario.  This routine is NOT granted the ability to suspend the\ndecompressor; it can decrement bytes_in_buffer to zero, but no more.  If the\nrequested skip distance exceeds the amount of data currently in the input\nbuffer, then skip_input_data() must set bytes_in_buffer to zero and record the\nadditional skip distance somewhere else.  The decompressor will immediately\ncall fill_input_buffer(), which should return FALSE, which will cause a\nsuspension return.  The surrounding application must then arrange to discard\nthe recorded number of bytes before it resumes loading the input buffer.\n(Yes, this design is rather baroque, but it avoids complexity in the far more\ncommon case where a non-suspending source manager is used.)\n\nIf the input data has been exhausted, we recommend that you emit a warning\nand insert dummy EOI markers just as a non-suspending data source manager\nwould do.  This can be handled either in the surrounding application logic or\nwithin fill_input_buffer(); the latter is probably more efficient.  If\nfill_input_buffer() knows that no more data is available, it can set the\npointer/count to point to a dummy EOI marker and then return TRUE just as\nthough it had read more data in a non-suspending situation.\n\nThe decompressor does not attempt to suspend within standard JPEG markers;\ninstead it will backtrack to the start of the marker and reprocess the whole\nmarker next time.  Hence the input buffer must be large enough to hold the\nlongest standard marker in the file.  Standard JPEG markers should normally\nnot exceed a few hundred bytes each (DHT tables are typically the longest).\nWe recommend at least a 2K buffer for performance reasons, which is much\nlarger than any correct marker is likely to be.  For robustness against\ndamaged marker length counts, you may wish to insert a test in your\napplication for the case that the input buffer is completely full and yet\nthe decoder has suspended without consuming any data --- otherwise, if this\nsituation did occur, it would lead to an endless loop.  (The library can't\nprovide this test since it has no idea whether \"the buffer is full\", or\neven whether there is a fixed-size input buffer.)\n\nThe input buffer would need to be 64K to allow for arbitrary COM or APPn\nmarkers, but these are handled specially: they are either saved into allocated\nmemory, or skipped over by calling skip_input_data().  In the former case,\nsuspension is handled correctly, and in the latter case, the problem of\nbuffer overrun is placed on skip_input_data's shoulders, as explained above.\nNote that if you provide your own marker handling routine for large markers,\nyou should consider how to deal with buffer overflow.\n\nMultiple-buffer management:\n\nIn some applications it is desirable to store the compressed data in a linked\nlist of buffer areas, so as to avoid data copying.  This can be handled by\nhaving empty_output_buffer() or fill_input_buffer() set the pointer and count\nto reference the next available buffer; FALSE is returned only if no more\nbuffers are available.  Although seemingly straightforward, there is a\npitfall in this approach: the backtrack that occurs when FALSE is returned\ncould back up into an earlier buffer.  For example, when fill_input_buffer()\nis called, the current pointer & count indicate the backtrack restart point.\nSince fill_input_buffer() will set the pointer and count to refer to a new\nbuffer, the restart position must be saved somewhere else.  Suppose a second\ncall to fill_input_buffer() occurs in the same library call, and no\nadditional input data is available, so fill_input_buffer must return FALSE.\nIf the JPEG library has not moved the pointer/count forward in the current\nbuffer, then *the correct restart point is the saved position in the prior\nbuffer*.  Prior buffers may be discarded only after the library establishes\na restart point within a later buffer.  Similar remarks apply for output into\na chain of buffers.\n\nThe library will never attempt to backtrack over a skip_input_data() call,\nso any skipped data can be permanently discarded.  You still have to deal\nwith the case of skipping not-yet-received data, however.\n\nIt's much simpler to use only a single buffer; when fill_input_buffer() is\ncalled, move any unconsumed data (beyond the current pointer/count) down to\nthe beginning of this buffer and then load new data into the remaining buffer\nspace.  This approach requires a little more data copying but is far easier\nto get right.\n\n\nProgressive JPEG support\n------------------------\n\nProgressive JPEG rearranges the stored data into a series of scans of\nincreasing quality.  In situations where a JPEG file is transmitted across a\nslow communications link, a decoder can generate a low-quality image very\nquickly from the first scan, then gradually improve the displayed quality as\nmore scans are received.  The final image after all scans are complete is\nidentical to that of a regular (sequential) JPEG file of the same quality\nsetting.  Progressive JPEG files are often slightly smaller than equivalent\nsequential JPEG files, but the possibility of incremental display is the main\nreason for using progressive JPEG.\n\nThe IJG encoder library generates progressive JPEG files when given a\nsuitable \"scan script\" defining how to divide the data into scans.\nCreation of progressive JPEG files is otherwise transparent to the encoder.\nProgressive JPEG files can also be read transparently by the decoder library.\nIf the decoding application simply uses the library as defined above, it\nwill receive a final decoded image without any indication that the file was\nprogressive.  Of course, this approach does not allow incremental display.\nTo perform incremental display, an application needs to use the decoder\nlibrary's \"buffered-image\" mode, in which it receives a decoded image\nmultiple times.\n\nEach displayed scan requires about as much work to decode as a full JPEG\nimage of the same size, so the decoder must be fairly fast in relation to the\ndata transmission rate in order to make incremental display useful.  However,\nit is possible to skip displaying the image and simply add the incoming bits\nto the decoder's coefficient buffer.  This is fast because only Huffman\ndecoding need be done, not IDCT, upsampling, colorspace conversion, etc.\nThe IJG decoder library allows the application to switch dynamically between\ndisplaying the image and simply absorbing the incoming bits.  A properly\ncoded application can automatically adapt the number of display passes to\nsuit the time available as the image is received.  Also, a final\nhigher-quality display cycle can be performed from the buffered data after\nthe end of the file is reached.\n\nProgressive compression:\n\nTo create a progressive JPEG file (or a multiple-scan sequential JPEG file),\nset the scan_info cinfo field to point to an array of scan descriptors, and\nperform compression as usual.  Instead of constructing your own scan list,\nyou can call the jpeg_simple_progression() helper routine to create a\nrecommended progression sequence; this method should be used by all\napplications that don't want to get involved in the nitty-gritty of\nprogressive scan sequence design.  (If you want to provide user control of\nscan sequences, you may wish to borrow the scan script reading code found\nin rdswitch.c, so that you can read scan script files just like cjpeg's.)\nWhen scan_info is not NULL, the compression library will store DCT'd data\ninto a buffer array as jpeg_write_scanlines() is called, and will emit all\nthe requested scans during jpeg_finish_compress().  This implies that\nmultiple-scan output cannot be created with a suspending data destination\nmanager, since jpeg_finish_compress() does not support suspension.  We\nshould also note that the compressor currently forces Huffman optimization\nmode when creating a progressive JPEG file, because the default Huffman\ntables are unsuitable for progressive files.\n\nProgressive decompression:\n\nWhen buffered-image mode is not used, the decoder library will read all of\na multi-scan file during jpeg_start_decompress(), so that it can provide a\nfinal decoded image.  (Here \"multi-scan\" means either progressive or\nmulti-scan sequential.)  This makes multi-scan files transparent to the\ndecoding application.  However, existing applications that used suspending\ninput with version 5 of the IJG library will need to be modified to check\nfor a suspension return from jpeg_start_decompress().\n\nTo perform incremental display, an application must use the library's\nbuffered-image mode.  This is described in the next section.\n\n\nBuffered-image mode\n-------------------\n\nIn buffered-image mode, the library stores the partially decoded image in a\ncoefficient buffer, from which it can be read out as many times as desired.\nThis mode is typically used for incremental display of progressive JPEG files,\nbut it can be used with any JPEG file.  Each scan of a progressive JPEG file\nadds more data (more detail) to the buffered image.  The application can\ndisplay in lockstep with the source file (one display pass per input scan),\nor it can allow input processing to outrun display processing.  By making\ninput and display processing run independently, it is possible for the\napplication to adapt progressive display to a wide range of data transmission\nrates.\n\nThe basic control flow for buffered-image decoding is\n\n\tjpeg_create_decompress()\n\tset data source\n\tjpeg_read_header()\n\tset overall decompression parameters\n\tcinfo.buffered_image = TRUE;\t/* select buffered-image mode */\n\tjpeg_start_decompress()\n\tfor (each output pass) {\n\t    adjust output decompression parameters if required\n\t    jpeg_start_output()\t\t/* start a new output pass */\n\t    for (all scanlines in image) {\n\t        jpeg_read_scanlines()\n\t        display scanlines\n\t    }\n\t    jpeg_finish_output()\t/* terminate output pass */\n\t}\n\tjpeg_finish_decompress()\n\tjpeg_destroy_decompress()\n\nThis differs from ordinary unbuffered decoding in that there is an additional\nlevel of looping.  The application can choose how many output passes to make\nand how to display each pass.\n\nThe simplest approach to displaying progressive images is to do one display\npass for each scan appearing in the input file.  In this case the outer loop\ncondition is typically\n\twhile (! jpeg_input_complete(&cinfo))\nand the start-output call should read\n\tjpeg_start_output(&cinfo, cinfo.input_scan_number);\nThe second parameter to jpeg_start_output() indicates which scan of the input\nfile is to be displayed; the scans are numbered starting at 1 for this\npurpose.  (You can use a loop counter starting at 1 if you like, but using\nthe library's input scan counter is easier.)  The library automatically reads\ndata as necessary to complete each requested scan, and jpeg_finish_output()\nadvances to the next scan or end-of-image marker (hence input_scan_number\nwill be incremented by the time control arrives back at jpeg_start_output()).\nWith this technique, data is read from the input file only as needed, and\ninput and output processing run in lockstep.\n\nAfter reading the final scan and reaching the end of the input file, the\nbuffered image remains available; it can be read additional times by\nrepeating the jpeg_start_output()/jpeg_read_scanlines()/jpeg_finish_output()\nsequence.  For example, a useful technique is to use fast one-pass color\nquantization for display passes made while the image is arriving, followed by\na final display pass using two-pass quantization for highest quality.  This\nis done by changing the library parameters before the final output pass.\nChanging parameters between passes is discussed in detail below.\n\nIn general the last scan of a progressive file cannot be recognized as such\nuntil after it is read, so a post-input display pass is the best approach if\nyou want special processing in the final pass.\n\nWhen done with the image, be sure to call jpeg_finish_decompress() to release\nthe buffered image (or just use jpeg_destroy_decompress()).\n\nIf input data arrives faster than it can be displayed, the application can\ncause the library to decode input data in advance of what's needed to produce\noutput.  This is done by calling the routine jpeg_consume_input().\nThe return value is one of the following:\n\tJPEG_REACHED_SOS:    reached an SOS marker (the start of a new scan)\n\tJPEG_REACHED_EOI:    reached the EOI marker (end of image)\n\tJPEG_ROW_COMPLETED:  completed reading one MCU row of compressed data\n\tJPEG_SCAN_COMPLETED: completed reading last MCU row of current scan\n\tJPEG_SUSPENDED:      suspended before completing any of the above\n(JPEG_SUSPENDED can occur only if a suspending data source is used.)  This\nroutine can be called at any time after initializing the JPEG object.  It\nreads some additional data and returns when one of the indicated significant\nevents occurs.  (If called after the EOI marker is reached, it will\nimmediately return JPEG_REACHED_EOI without attempting to read more data.)\n\nThe library's output processing will automatically call jpeg_consume_input()\nwhenever the output processing overtakes the input; thus, simple lockstep\ndisplay requires no direct calls to jpeg_consume_input().  But by adding\ncalls to jpeg_consume_input(), you can absorb data in advance of what is\nbeing displayed.  This has two benefits:\n  * You can limit buildup of unprocessed data in your input buffer.\n  * You can eliminate extra display passes by paying attention to the\n    state of the library's input processing.\n\nThe first of these benefits only requires interspersing calls to\njpeg_consume_input() with your display operations and any other processing\nyou may be doing.  To avoid wasting cycles due to backtracking, it's best to\ncall jpeg_consume_input() only after a hundred or so new bytes have arrived.\nThis is discussed further under \"I/O suspension\", above.  (Note: the JPEG\nlibrary currently is not thread-safe.  You must not call jpeg_consume_input()\nfrom one thread of control if a different library routine is working on the\nsame JPEG object in another thread.)\n\nWhen input arrives fast enough that more than one new scan is available\nbefore you start a new output pass, you may as well skip the output pass\ncorresponding to the completed scan.  This occurs for free if you pass\ncinfo.input_scan_number as the target scan number to jpeg_start_output().\nThe input_scan_number field is simply the index of the scan currently being\nconsumed by the input processor.  You can ensure that this is up-to-date by\nemptying the input buffer just before calling jpeg_start_output(): call\njpeg_consume_input() repeatedly until it returns JPEG_SUSPENDED or\nJPEG_REACHED_EOI.\n\nThe target scan number passed to jpeg_start_output() is saved in the\ncinfo.output_scan_number field.  The library's output processing calls\njpeg_consume_input() whenever the current input scan number and row within\nthat scan is less than or equal to the current output scan number and row.\nThus, input processing can \"get ahead\" of the output processing but is not\nallowed to \"fall behind\".  You can achieve several different effects by\nmanipulating this interlock rule.  For example, if you pass a target scan\nnumber greater than the current input scan number, the output processor will\nwait until that scan starts to arrive before producing any output.  (To avoid\nan infinite loop, the target scan number is automatically reset to the last\nscan number when the end of image is reached.  Thus, if you specify a large\ntarget scan number, the library will just absorb the entire input file and\nthen perform an output pass.  This is effectively the same as what\njpeg_start_decompress() does when you don't select buffered-image mode.)\nWhen you pass a target scan number equal to the current input scan number,\nthe image is displayed no faster than the current input scan arrives.  The\nfinal possibility is to pass a target scan number less than the current input\nscan number; this disables the input/output interlock and causes the output\nprocessor to simply display whatever it finds in the image buffer, without\nwaiting for input.  (However, the library will not accept a target scan\nnumber less than one, so you can't avoid waiting for the first scan.)\n\nWhen data is arriving faster than the output display processing can advance\nthrough the image, jpeg_consume_input() will store data into the buffered\nimage beyond the point at which the output processing is reading data out\nagain.  If the input arrives fast enough, it may \"wrap around\" the buffer to\nthe point where the input is more than one whole scan ahead of the output.\nIf the output processing simply proceeds through its display pass without\npaying attention to the input, the effect seen on-screen is that the lower\npart of the image is one or more scans better in quality than the upper part.\nThen, when the next output scan is started, you have a choice of what target\nscan number to use.  The recommended choice is to use the current input scan\nnumber at that time, which implies that you've skipped the output scans\ncorresponding to the input scans that were completed while you processed the\nprevious output scan.  In this way, the decoder automatically adapts its\nspeed to the arriving data, by skipping output scans as necessary to keep up\nwith the arriving data.\n\nWhen using this strategy, you'll want to be sure that you perform a final\noutput pass after receiving all the data; otherwise your last display may not\nbe full quality across the whole screen.  So the right outer loop logic is\nsomething like this:\n\tdo {\n\t    absorb any waiting input by calling jpeg_consume_input()\n\t    final_pass = jpeg_input_complete(&cinfo);\n\t    adjust output decompression parameters if required\n\t    jpeg_start_output(&cinfo, cinfo.input_scan_number);\n\t    ...\n\t    jpeg_finish_output()\n\t} while (! final_pass);\nrather than quitting as soon as jpeg_input_complete() returns TRUE.  This\narrangement makes it simple to use higher-quality decoding parameters\nfor the final pass.  But if you don't want to use special parameters for\nthe final pass, the right loop logic is like this:\n\tfor (;;) {\n\t    absorb any waiting input by calling jpeg_consume_input()\n\t    jpeg_start_output(&cinfo, cinfo.input_scan_number);\n\t    ...\n\t    jpeg_finish_output()\n\t    if (jpeg_input_complete(&cinfo) &&\n\t        cinfo.input_scan_number == cinfo.output_scan_number)\n\t      break;\n\t}\nIn this case you don't need to know in advance whether an output pass is to\nbe the last one, so it's not necessary to have reached EOF before starting\nthe final output pass; rather, what you want to test is whether the output\npass was performed in sync with the final input scan.  This form of the loop\nwill avoid an extra output pass whenever the decoder is able (or nearly able)\nto keep up with the incoming data.\n\nWhen the data transmission speed is high, you might begin a display pass,\nthen find that much or all of the file has arrived before you can complete\nthe pass.  (You can detect this by noting the JPEG_REACHED_EOI return code\nfrom jpeg_consume_input(), or equivalently by testing jpeg_input_complete().)\nIn this situation you may wish to abort the current display pass and start a\nnew one using the newly arrived information.  To do so, just call\njpeg_finish_output() and then start a new pass with jpeg_start_output().\n\nA variant strategy is to abort and restart display if more than one complete\nscan arrives during an output pass; this can be detected by noting\nJPEG_REACHED_SOS returns and/or examining cinfo.input_scan_number.  This\nidea should be employed with caution, however, since the display process\nmight never get to the bottom of the image before being aborted, resulting\nin the lower part of the screen being several passes worse than the upper.\nIn most cases it's probably best to abort an output pass only if the whole\nfile has arrived and you want to begin the final output pass immediately.\n\nWhen receiving data across a communication link, we recommend always using\nthe current input scan number for the output target scan number; if a\nhigher-quality final pass is to be done, it should be started (aborting any\nincomplete output pass) as soon as the end of file is received.  However,\nmany other strategies are possible.  For example, the application can examine\nthe parameters of the current input scan and decide whether to display it or\nnot.  If the scan contains only chroma data, one might choose not to use it\nas the target scan, expecting that the scan will be small and will arrive\nquickly.  To skip to the next scan, call jpeg_consume_input() until it\nreturns JPEG_REACHED_SOS or JPEG_REACHED_EOI.  Or just use the next higher\nnumber as the target scan for jpeg_start_output(); but that method doesn't\nlet you inspect the next scan's parameters before deciding to display it.\n\n\nIn buffered-image mode, jpeg_start_decompress() never performs input and\nthus never suspends.  An application that uses input suspension with\nbuffered-image mode must be prepared for suspension returns from these\nroutines:\n* jpeg_start_output() performs input only if you request 2-pass quantization\n  and the target scan isn't fully read yet.  (This is discussed below.)\n* jpeg_read_scanlines(), as always, returns the number of scanlines that it\n  was able to produce before suspending.\n* jpeg_finish_output() will read any markers following the target scan,\n  up to the end of the file or the SOS marker that begins another scan.\n  (But it reads no input if jpeg_consume_input() has already reached the\n  end of the file or a SOS marker beyond the target output scan.)\n* jpeg_finish_decompress() will read until the end of file, and thus can\n  suspend if the end hasn't already been reached (as can be tested by\n  calling jpeg_input_complete()).\njpeg_start_output(), jpeg_finish_output(), and jpeg_finish_decompress()\nall return TRUE if they completed their tasks, FALSE if they had to suspend.\nIn the event of a FALSE return, the application must load more input data\nand repeat the call.  Applications that use non-suspending data sources need\nnot check the return values of these three routines.\n\n\nIt is possible to change decoding parameters between output passes in the\nbuffered-image mode.  The decoder library currently supports only very\nlimited changes of parameters.  ONLY THE FOLLOWING parameter changes are\nallowed after jpeg_start_decompress() is called:\n* dct_method can be changed before each call to jpeg_start_output().\n  For example, one could use a fast DCT method for early scans, changing\n  to a higher quality method for the final scan.\n* dither_mode can be changed before each call to jpeg_start_output();\n  of course this has no impact if not using color quantization.  Typically\n  one would use ordered dither for initial passes, then switch to\n  Floyd-Steinberg dither for the final pass.  Caution: changing dither mode\n  can cause more memory to be allocated by the library.  Although the amount\n  of memory involved is not large (a scanline or so), it may cause the\n  initial max_memory_to_use specification to be exceeded, which in the worst\n  case would result in an out-of-memory failure.\n* do_block_smoothing can be changed before each call to jpeg_start_output().\n  This setting is relevant only when decoding a progressive JPEG image.\n  During the first DC-only scan, block smoothing provides a very \"fuzzy\" look\n  instead of the very \"blocky\" look seen without it; which is better seems a\n  matter of personal taste.  But block smoothing is nearly always a win\n  during later stages, especially when decoding a successive-approximation\n  image: smoothing helps to hide the slight blockiness that otherwise shows\n  up on smooth gradients until the lowest coefficient bits are sent.\n* Color quantization mode can be changed under the rules described below.\n  You *cannot* change between full-color and quantized output (because that\n  would alter the required I/O buffer sizes), but you can change which\n  quantization method is used.\n\nWhen generating color-quantized output, changing quantization method is a\nvery useful way of switching between high-speed and high-quality display.\nThe library allows you to change among its three quantization methods:\n1. Single-pass quantization to a fixed color cube.\n   Selected by cinfo.two_pass_quantize = FALSE and cinfo.colormap = NULL.\n2. Single-pass quantization to an application-supplied colormap.\n   Selected by setting cinfo.colormap to point to the colormap (the value of\n   two_pass_quantize is ignored); also set cinfo.actual_number_of_colors.\n3. Two-pass quantization to a colormap chosen specifically for the image.\n   Selected by cinfo.two_pass_quantize = TRUE and cinfo.colormap = NULL.\n   (This is the default setting selected by jpeg_read_header, but it is\n   probably NOT what you want for the first pass of progressive display!)\nThese methods offer successively better quality and lesser speed.  However,\nonly the first method is available for quantizing in non-RGB color spaces.\n\nIMPORTANT: because the different quantizer methods have very different\nworking-storage requirements, the library requires you to indicate which\none(s) you intend to use before you call jpeg_start_decompress().  (If we did\nnot require this, the max_memory_to_use setting would be a complete fiction.)\nYou do this by setting one or more of these three cinfo fields to TRUE:\n\tenable_1pass_quant\t\tFixed color cube colormap\n\tenable_external_quant\t\tExternally-supplied colormap\n\tenable_2pass_quant\t\tTwo-pass custom colormap\nAll three are initialized FALSE by jpeg_read_header().  But\njpeg_start_decompress() automatically sets TRUE the one selected by the\ncurrent two_pass_quantize and colormap settings, so you only need to set the\nenable flags for any other quantization methods you plan to change to later.\n\nAfter setting the enable flags correctly at jpeg_start_decompress() time, you\ncan change to any enabled quantization method by setting two_pass_quantize\nand colormap properly just before calling jpeg_start_output().  The following\nspecial rules apply:\n1. You must explicitly set cinfo.colormap to NULL when switching to 1-pass\n   or 2-pass mode from a different mode, or when you want the 2-pass\n   quantizer to be re-run to generate a new colormap.\n2. To switch to an external colormap, or to change to a different external\n   colormap than was used on the prior pass, you must call\n   jpeg_new_colormap() after setting cinfo.colormap.\nNOTE: if you want to use the same colormap as was used in the prior pass,\nyou should not do either of these things.  This will save some nontrivial\nswitchover costs.\n(These requirements exist because cinfo.colormap will always be non-NULL\nafter completing a prior output pass, since both the 1-pass and 2-pass\nquantizers set it to point to their output colormaps.  Thus you have to\ndo one of these two things to notify the library that something has changed.\nYup, it's a bit klugy, but it's necessary to do it this way for backwards\ncompatibility.)\n\nNote that in buffered-image mode, the library generates any requested colormap\nduring jpeg_start_output(), not during jpeg_start_decompress().\n\nWhen using two-pass quantization, jpeg_start_output() makes a pass over the\nbuffered image to determine the optimum color map; it therefore may take a\nsignificant amount of time, whereas ordinarily it does little work.  The\nprogress monitor hook is called during this pass, if defined.  It is also\nimportant to realize that if the specified target scan number is greater than\nor equal to the current input scan number, jpeg_start_output() will attempt\nto consume input as it makes this pass.  If you use a suspending data source,\nyou need to check for a FALSE return from jpeg_start_output() under these\nconditions.  The combination of 2-pass quantization and a not-yet-fully-read\ntarget scan is the only case in which jpeg_start_output() will consume input.\n\n\nApplication authors who support buffered-image mode may be tempted to use it\nfor all JPEG images, even single-scan ones.  This will work, but it is\ninefficient: there is no need to create an image-sized coefficient buffer for\nsingle-scan images.  Requesting buffered-image mode for such an image wastes\nmemory.  Worse, it can cost time on large images, since the buffered data has\nto be swapped out or written to a temporary file.  If you are concerned about\nmaximum performance on baseline JPEG files, you should use buffered-image\nmode only when the incoming file actually has multiple scans.  This can be\ntested by calling jpeg_has_multiple_scans(), which will return a correct\nresult at any time after jpeg_read_header() completes.\n\nIt is also worth noting that when you use jpeg_consume_input() to let input\nprocessing get ahead of output processing, the resulting pattern of access to\nthe coefficient buffer is quite nonsequential.  It's best to use the memory\nmanager jmemnobs.c if you can (ie, if you have enough real or virtual main\nmemory).  If not, at least make sure that max_memory_to_use is set as high as\npossible.  If the JPEG memory manager has to use a temporary file, you will\nprobably see a lot of disk traffic and poor performance.  (This could be\nimproved with additional work on the memory manager, but we haven't gotten\naround to it yet.)\n\nIn some applications it may be convenient to use jpeg_consume_input() for all\ninput processing, including reading the initial markers; that is, you may\nwish to call jpeg_consume_input() instead of jpeg_read_header() during\nstartup.  This works, but note that you must check for JPEG_REACHED_SOS and\nJPEG_REACHED_EOI return codes as the equivalent of jpeg_read_header's codes.\nOnce the first SOS marker has been reached, you must call\njpeg_start_decompress() before jpeg_consume_input() will consume more input;\nit'll just keep returning JPEG_REACHED_SOS until you do.  If you read a\ntables-only file this way, jpeg_consume_input() will return JPEG_REACHED_EOI\nwithout ever returning JPEG_REACHED_SOS; be sure to check for this case.\nIf this happens, the decompressor will not read any more input until you call\njpeg_abort() to reset it.  It is OK to call jpeg_consume_input() even when not\nusing buffered-image mode, but in that case it's basically a no-op after the\ninitial markers have been read: it will just return JPEG_SUSPENDED.\n\n\nAbbreviated datastreams and multiple images\n-------------------------------------------\n\nA JPEG compression or decompression object can be reused to process multiple\nimages.  This saves a small amount of time per image by eliminating the\n\"create\" and \"destroy\" operations, but that isn't the real purpose of the\nfeature.  Rather, reuse of an object provides support for abbreviated JPEG\ndatastreams.  Object reuse can also simplify processing a series of images in\na single input or output file.  This section explains these features.\n\nA JPEG file normally contains several hundred bytes worth of quantization\nand Huffman tables.  In a situation where many images will be stored or\ntransmitted with identical tables, this may represent an annoying overhead.\nThe JPEG standard therefore permits tables to be omitted.  The standard\ndefines three classes of JPEG datastreams:\n  * \"Interchange\" datastreams contain an image and all tables needed to decode\n     the image.  These are the usual kind of JPEG file.\n  * \"Abbreviated image\" datastreams contain an image, but are missing some or\n    all of the tables needed to decode that image.\n  * \"Abbreviated table specification\" (henceforth \"tables-only\") datastreams\n    contain only table specifications.\nTo decode an abbreviated image, it is necessary to load the missing table(s)\ninto the decoder beforehand.  This can be accomplished by reading a separate\ntables-only file.  A variant scheme uses a series of images in which the first\nimage is an interchange (complete) datastream, while subsequent ones are\nabbreviated and rely on the tables loaded by the first image.  It is assumed\nthat once the decoder has read a table, it will remember that table until a\nnew definition for the same table number is encountered.\n\nIt is the application designer's responsibility to figure out how to associate\nthe correct tables with an abbreviated image.  While abbreviated datastreams\ncan be useful in a closed environment, their use is strongly discouraged in\nany situation where data exchange with other applications might be needed.\nCaveat designer.\n\nThe JPEG library provides support for reading and writing any combination of\ntables-only datastreams and abbreviated images.  In both compression and\ndecompression objects, a quantization or Huffman table will be retained for\nthe lifetime of the object, unless it is overwritten by a new table definition.\n\n\nTo create abbreviated image datastreams, it is only necessary to tell the\ncompressor not to emit some or all of the tables it is using.  Each\nquantization and Huffman table struct contains a boolean field \"sent_table\",\nwhich normally is initialized to FALSE.  For each table used by the image, the\nheader-writing process emits the table and sets sent_table = TRUE unless it is\nalready TRUE.  (In normal usage, this prevents outputting the same table\ndefinition multiple times, as would otherwise occur because the chroma\ncomponents typically share tables.)  Thus, setting this field to TRUE before\ncalling jpeg_start_compress() will prevent the table from being written at\nall.\n\nIf you want to create a \"pure\" abbreviated image file containing no tables,\njust call \"jpeg_suppress_tables(&cinfo, TRUE)\" after constructing all the\ntables.  If you want to emit some but not all tables, you'll need to set the\nindividual sent_table fields directly.\n\nTo create an abbreviated image, you must also call jpeg_start_compress()\nwith a second parameter of FALSE, not TRUE.  Otherwise jpeg_start_compress()\nwill force all the sent_table fields to FALSE.  (This is a safety feature to\nprevent abbreviated images from being created accidentally.)\n\nTo create a tables-only file, perform the same parameter setup that you\nnormally would, but instead of calling jpeg_start_compress() and so on, call\njpeg_write_tables(&cinfo).  This will write an abbreviated datastream\ncontaining only SOI, DQT and/or DHT markers, and EOI.  All the quantization\nand Huffman tables that are currently defined in the compression object will\nbe emitted unless their sent_tables flag is already TRUE, and then all the\nsent_tables flags will be set TRUE.\n\nA sure-fire way to create matching tables-only and abbreviated image files\nis to proceed as follows:\n\n\tcreate JPEG compression object\n\tset JPEG parameters\n\tset destination to tables-only file\n\tjpeg_write_tables(&cinfo);\n\tset destination to image file\n\tjpeg_start_compress(&cinfo, FALSE);\n\twrite data...\n\tjpeg_finish_compress(&cinfo);\n\nSince the JPEG parameters are not altered between writing the table file and\nthe abbreviated image file, the same tables are sure to be used.  Of course,\nyou can repeat the jpeg_start_compress() ... jpeg_finish_compress() sequence\nmany times to produce many abbreviated image files matching the table file.\n\nYou cannot suppress output of the computed Huffman tables when Huffman\noptimization is selected.  (If you could, there'd be no way to decode the\nimage...)  Generally, you don't want to set optimize_coding = TRUE when\nyou are trying to produce abbreviated files.\n\nIn some cases you might want to compress an image using tables which are\nnot stored in the application, but are defined in an interchange or\ntables-only file readable by the application.  This can be done by setting up\na JPEG decompression object to read the specification file, then copying the\ntables into your compression object.  See jpeg_copy_critical_parameters()\nfor an example of copying quantization tables.\n\n\nTo read abbreviated image files, you simply need to load the proper tables\ninto the decompression object before trying to read the abbreviated image.\nIf the proper tables are stored in the application program, you can just\nallocate the table structs and fill in their contents directly.  For example,\nto load a fixed quantization table into table slot \"n\":\n\n    if (cinfo.quant_tbl_ptrs[n] == NULL)\n      cinfo.quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) &cinfo);\n    quant_ptr = cinfo.quant_tbl_ptrs[n];\t/* quant_ptr is JQUANT_TBL* */\n    for (i = 0; i < 64; i++) {\n      /* Qtable[] is desired quantization table, in natural array order */\n      quant_ptr->quantval[i] = Qtable[i];\n    }\n\nCode to load a fixed Huffman table is typically (for AC table \"n\"):\n\n    if (cinfo.ac_huff_tbl_ptrs[n] == NULL)\n      cinfo.ac_huff_tbl_ptrs[n] = jpeg_alloc_huff_table((j_common_ptr) &cinfo);\n    huff_ptr = cinfo.ac_huff_tbl_ptrs[n];\t/* huff_ptr is JHUFF_TBL* */\n    for (i = 1; i <= 16; i++) {\n      /* counts[i] is number of Huffman codes of length i bits, i=1..16 */\n      huff_ptr->bits[i] = counts[i];\n    }\n    for (i = 0; i < 256; i++) {\n      /* symbols[] is the list of Huffman symbols, in code-length order */\n      huff_ptr->huffval[i] = symbols[i];\n    }\n\n(Note that trying to set cinfo.quant_tbl_ptrs[n] to point directly at a\nconstant JQUANT_TBL object is not safe.  If the incoming file happened to\ncontain a quantization table definition, your master table would get\noverwritten!  Instead allocate a working table copy and copy the master table\ninto it, as illustrated above.  Ditto for Huffman tables, of course.)\n\nYou might want to read the tables from a tables-only file, rather than\nhard-wiring them into your application.  The jpeg_read_header() call is\nsufficient to read a tables-only file.  You must pass a second parameter of\nFALSE to indicate that you do not require an image to be present.  Thus, the\ntypical scenario is\n\n\tcreate JPEG decompression object\n\tset source to tables-only file\n\tjpeg_read_header(&cinfo, FALSE);\n\tset source to abbreviated image file\n\tjpeg_read_header(&cinfo, TRUE);\n\tset decompression parameters\n\tjpeg_start_decompress(&cinfo);\n\tread data...\n\tjpeg_finish_decompress(&cinfo);\n\nIn some cases, you may want to read a file without knowing whether it contains\nan image or just tables.  In that case, pass FALSE and check the return value\nfrom jpeg_read_header(): it will be JPEG_HEADER_OK if an image was found,\nJPEG_HEADER_TABLES_ONLY if only tables were found.  (A third return value,\nJPEG_SUSPENDED, is possible when using a suspending data source manager.)\nNote that jpeg_read_header() will not complain if you read an abbreviated\nimage for which you haven't loaded the missing tables; the missing-table check\noccurs later, in jpeg_start_decompress().\n\n\nIt is possible to read a series of images from a single source file by\nrepeating the jpeg_read_header() ... jpeg_finish_decompress() sequence,\nwithout releasing/recreating the JPEG object or the data source module.\n(If you did reinitialize, any partial bufferload left in the data source\nbuffer at the end of one image would be discarded, causing you to lose the\nstart of the next image.)  When you use this method, stored tables are\nautomatically carried forward, so some of the images can be abbreviated images\nthat depend on tables from earlier images.\n\nIf you intend to write a series of images into a single destination file,\nyou might want to make a specialized data destination module that doesn't\nflush the output buffer at term_destination() time.  This would speed things\nup by some trifling amount.  Of course, you'd need to remember to flush the\nbuffer after the last image.  You can make the later images be abbreviated\nones by passing FALSE to jpeg_start_compress().\n\n\nSpecial markers\n---------------\n\nSome applications may need to insert or extract special data in the JPEG\ndatastream.  The JPEG standard provides marker types \"COM\" (comment) and\n\"APP0\" through \"APP15\" (application) to hold application-specific data.\nUnfortunately, the use of these markers is not specified by the standard.\nCOM markers are fairly widely used to hold user-supplied text.  The JFIF file\nformat spec uses APP0 markers with specified initial strings to hold certain\ndata.  Adobe applications use APP14 markers beginning with the string \"Adobe\"\nfor miscellaneous data.  Other APPn markers are rarely seen, but might\ncontain almost anything.\n\nIf you wish to store user-supplied text, we recommend you use COM markers\nand place readable 7-bit ASCII text in them.  Newline conventions are not\nstandardized --- expect to find LF (Unix style), CR/LF (DOS style), or CR\n(Mac style).  A robust COM reader should be able to cope with random binary\ngarbage, including nulls, since some applications generate COM markers\ncontaining non-ASCII junk.  (But yours should not be one of them.)\n\nFor program-supplied data, use an APPn marker, and be sure to begin it with an\nidentifying string so that you can tell whether the marker is actually yours.\nIt's probably best to avoid using APP0 or APP14 for any private markers.\n(NOTE: the upcoming SPIFF standard will use APP8 markers; we recommend you\nnot use APP8 markers for any private purposes, either.)\n\nKeep in mind that at most 65533 bytes can be put into one marker, but you\ncan have as many markers as you like.\n\nBy default, the IJG compression library will write a JFIF APP0 marker if the\nselected JPEG colorspace is grayscale or YCbCr, or an Adobe APP14 marker if\nthe selected colorspace is RGB, CMYK, or YCCK.  You can disable this, but\nwe don't recommend it.  The decompression library will recognize JFIF and\nAdobe markers and will set the JPEG colorspace properly when one is found.\n\n\nYou can write special markers immediately following the datastream header by\ncalling jpeg_write_marker() after jpeg_start_compress() and before the first\ncall to jpeg_write_scanlines().  When you do this, the markers appear after\nthe SOI and the JFIF APP0 and Adobe APP14 markers (if written), but before\nall else.  Specify the marker type parameter as \"JPEG_COM\" for COM or\n\"JPEG_APP0 + n\" for APPn.  (Actually, jpeg_write_marker will let you write\nany marker type, but we don't recommend writing any other kinds of marker.)\nFor example, to write a user comment string pointed to by comment_text:\n\tjpeg_write_marker(cinfo, JPEG_COM, comment_text, strlen(comment_text));\n\nIf it's not convenient to store all the marker data in memory at once,\nyou can instead call jpeg_write_m_header() followed by multiple calls to\njpeg_write_m_byte().  If you do it this way, it's your responsibility to\ncall jpeg_write_m_byte() exactly the number of times given in the length\nparameter to jpeg_write_m_header().  (This method lets you empty the\noutput buffer partway through a marker, which might be important when\nusing a suspending data destination module.  In any case, if you are using\na suspending destination, you should flush its buffer after inserting\nany special markers.  See \"I/O suspension\".)\n\nOr, if you prefer to synthesize the marker byte sequence yourself,\nyou can just cram it straight into the data destination module.\n\nIf you are writing JFIF 1.02 extension markers (thumbnail images), don't\nforget to set cinfo.JFIF_minor_version = 2 so that the encoder will write the\ncorrect JFIF version number in the JFIF header marker.  The library's default\nis to write version 1.01, but that's wrong if you insert any 1.02 extension\nmarkers.  (We could probably get away with just defaulting to 1.02, but there\nused to be broken decoders that would complain about unknown minor version\nnumbers.  To reduce compatibility risks it's safest not to write 1.02 unless\nyou are actually using 1.02 extensions.)\n\n\nWhen reading, two methods of handling special markers are available:\n1. You can ask the library to save the contents of COM and/or APPn markers\ninto memory, and then examine them at your leisure afterwards.\n2. You can supply your own routine to process COM and/or APPn markers\non-the-fly as they are read.\nThe first method is simpler to use, especially if you are using a suspending\ndata source; writing a marker processor that copes with input suspension is\nnot easy (consider what happens if the marker is longer than your available\ninput buffer).  However, the second method conserves memory since the marker\ndata need not be kept around after it's been processed.\n\nFor either method, you'd normally set up marker handling after creating a\ndecompression object and before calling jpeg_read_header(), because the\nmarkers of interest will typically be near the head of the file and so will\nbe scanned by jpeg_read_header.  Once you've established a marker handling\nmethod, it will be used for the life of that decompression object\n(potentially many datastreams), unless you change it.  Marker handling is\ndetermined separately for COM markers and for each APPn marker code.\n\n\nTo save the contents of special markers in memory, call\n\tjpeg_save_markers(cinfo, marker_code, length_limit)\nwhere marker_code is the marker type to save, JPEG_COM or JPEG_APP0+n.\n(To arrange to save all the special marker types, you need to call this\nroutine 17 times, for COM and APP0-APP15.)  If the incoming marker is longer\nthan length_limit data bytes, only length_limit bytes will be saved; this\nparameter allows you to avoid chewing up memory when you only need to see the\nfirst few bytes of a potentially large marker.  If you want to save all the\ndata, set length_limit to 0xFFFF; that is enough since marker lengths are only\n16 bits.  As a special case, setting length_limit to 0 prevents that marker\ntype from being saved at all.  (That is the default behavior, in fact.)\n\nAfter jpeg_read_header() completes, you can examine the special markers by\nfollowing the cinfo->marker_list pointer chain.  All the special markers in\nthe file appear in this list, in order of their occurrence in the file (but\nomitting any markers of types you didn't ask for).  Both the original data\nlength and the saved data length are recorded for each list entry; the latter\nwill not exceed length_limit for the particular marker type.  Note that these\nlengths exclude the marker length word, whereas the stored representation\nwithin the JPEG file includes it.  (Hence the maximum data length is really\nonly 65533.)\n\nIt is possible that additional special markers appear in the file beyond the\nSOS marker at which jpeg_read_header stops; if so, the marker list will be\nextended during reading of the rest of the file.  This is not expected to be\ncommon, however.  If you are short on memory you may want to reset the length\nlimit to zero for all marker types after finishing jpeg_read_header, to\nensure that the max_memory_to_use setting cannot be exceeded due to addition\nof later markers.\n\nThe marker list remains stored until you call jpeg_finish_decompress or\njpeg_abort, at which point the memory is freed and the list is set to empty.\n(jpeg_destroy also releases the storage, of course.)\n\nNote that the library is internally interested in APP0 and APP14 markers;\nif you try to set a small nonzero length limit on these types, the library\nwill silently force the length up to the minimum it wants.  (But you can set\na zero length limit to prevent them from being saved at all.)  Also, in a\n16-bit environment, the maximum length limit may be constrained to less than\n65533 by malloc() limitations.  It is therefore best not to assume that the\neffective length limit is exactly what you set it to be.\n\n\nIf you want to supply your own marker-reading routine, you do it by calling\njpeg_set_marker_processor().  A marker processor routine must have the\nsignature\n\tboolean jpeg_marker_parser_method (j_decompress_ptr cinfo)\nAlthough the marker code is not explicitly passed, the routine can find it\nin cinfo->unread_marker.  At the time of call, the marker proper has been\nread from the data source module.  The processor routine is responsible for\nreading the marker length word and the remaining parameter bytes, if any.\nReturn TRUE to indicate success.  (FALSE should be returned only if you are\nusing a suspending data source and it tells you to suspend.  See the standard\nmarker processors in jdmarker.c for appropriate coding methods if you need to\nuse a suspending data source.)\n\nIf you override the default APP0 or APP14 processors, it is up to you to\nrecognize JFIF and Adobe markers if you want colorspace recognition to occur\nproperly.  We recommend copying and extending the default processors if you\nwant to do that.  (A better idea is to save these marker types for later\nexamination by calling jpeg_save_markers(); that method doesn't interfere\nwith the library's own processing of these markers.)\n\njpeg_set_marker_processor() and jpeg_save_markers() are mutually exclusive\n--- if you call one it overrides any previous call to the other, for the\nparticular marker type specified.\n\nA simple example of an external COM processor can be found in djpeg.c.\nAlso, see jpegtran.c for an example of using jpeg_save_markers.\n\n\nRaw (downsampled) image data\n----------------------------\n\nSome applications need to supply already-downsampled image data to the JPEG\ncompressor, or to receive raw downsampled data from the decompressor.  The\nlibrary supports this requirement by allowing the application to write or\nread raw data, bypassing the normal preprocessing or postprocessing steps.\nThe interface is different from the standard one and is somewhat harder to\nuse.  If your interest is merely in bypassing color conversion, we recommend\nthat you use the standard interface and simply set jpeg_color_space =\nin_color_space (or jpeg_color_space = out_color_space for decompression).\nThe mechanism described in this section is necessary only to supply or\nreceive downsampled image data, in which not all components have the same\ndimensions.\n\n\nTo compress raw data, you must supply the data in the colorspace to be used\nin the JPEG file (please read the earlier section on Special color spaces)\nand downsampled to the sampling factors specified in the JPEG parameters.\nYou must supply the data in the format used internally by the JPEG library,\nnamely a JSAMPIMAGE array.  This is an array of pointers to two-dimensional\narrays, each of type JSAMPARRAY.  Each 2-D array holds the values for one\ncolor component.  This structure is necessary since the components are of\ndifferent sizes.  If the image dimensions are not a multiple of the MCU size,\nyou must also pad the data correctly (usually, this is done by replicating\nthe last column and/or row).  The data must be padded to a multiple of a DCT\nblock in each component: that is, each downsampled row must contain a\nmultiple of block_size valid samples, and there must be a multiple of\nblock_size sample rows for each component.  (For applications such as\nconversion of digital TV images, the standard image size is usually a\nmultiple of the DCT block size, so that no padding need actually be done.)\n\nThe procedure for compression of raw data is basically the same as normal\ncompression, except that you call jpeg_write_raw_data() in place of\njpeg_write_scanlines().  Before calling jpeg_start_compress(), you must do\nthe following:\n  * Set cinfo->raw_data_in to TRUE.  (It is set FALSE by jpeg_set_defaults().)\n    This notifies the library that you will be supplying raw data.\n    Furthermore, set cinfo->do_fancy_downsampling to FALSE if you want to use\n    real downsampled data.  (It is set TRUE by jpeg_set_defaults().)\n  * Ensure jpeg_color_space is correct --- an explicit jpeg_set_colorspace()\n    call is a good idea.  Note that since color conversion is bypassed,\n    in_color_space is ignored, except that jpeg_set_defaults() uses it to\n    choose the default jpeg_color_space setting.\n  * Ensure the sampling factors, cinfo->comp_info[i].h_samp_factor and\n    cinfo->comp_info[i].v_samp_factor, are correct.  Since these indicate the\n    dimensions of the data you are supplying, it's wise to set them\n    explicitly, rather than assuming the library's defaults are what you want.\n\nTo pass raw data to the library, call jpeg_write_raw_data() in place of\njpeg_write_scanlines().  The two routines work similarly except that\njpeg_write_raw_data takes a JSAMPIMAGE data array rather than JSAMPARRAY.\nThe scanlines count passed to and returned from jpeg_write_raw_data is\nmeasured in terms of the component with the largest v_samp_factor.\n\njpeg_write_raw_data() processes one MCU row per call, which is to say\nv_samp_factor*block_size sample rows of each component.  The passed num_lines\nvalue must be at least max_v_samp_factor*block_size, and the return value\nwill be exactly that amount (or possibly some multiple of that amount, in\nfuture library versions).  This is true even on the last call at the bottom\nof the image; don't forget to pad your data as necessary.\n\nThe required dimensions of the supplied data can be computed for each\ncomponent as\n\tcinfo->comp_info[i].width_in_blocks*block_size  samples per row\n\tcinfo->comp_info[i].height_in_blocks*block_size rows in image\nafter jpeg_start_compress() has initialized those fields.  If the valid data\nis smaller than this, it must be padded appropriately.  For some sampling\nfactors and image sizes, additional dummy DCT blocks are inserted to make\nthe image a multiple of the MCU dimensions.  The library creates such dummy\nblocks itself; it does not read them from your supplied data.  Therefore you\nneed never pad by more than block_size samples.  An example may help here.\nAssume 2h2v downsampling of YCbCr data, that is\n\tcinfo->comp_info[0].h_samp_factor = 2\t\tfor Y\n\tcinfo->comp_info[0].v_samp_factor = 2\n\tcinfo->comp_info[1].h_samp_factor = 1\t\tfor Cb\n\tcinfo->comp_info[1].v_samp_factor = 1\n\tcinfo->comp_info[2].h_samp_factor = 1\t\tfor Cr\n\tcinfo->comp_info[2].v_samp_factor = 1\nand suppose that the nominal image dimensions (cinfo->image_width and\ncinfo->image_height) are 101x101 pixels.  Then jpeg_start_compress() will\ncompute downsampled_width = 101 and width_in_blocks = 13 for Y,\ndownsampled_width = 51 and width_in_blocks = 7 for Cb and Cr (and the same\nfor the height fields).  You must pad the Y data to at least 13*8 = 104\ncolumns and rows, the Cb/Cr data to at least 7*8 = 56 columns and rows.  The\nMCU height is max_v_samp_factor = 2 DCT rows so you must pass at least 16\nscanlines on each call to jpeg_write_raw_data(), which is to say 16 actual\nsample rows of Y and 8 each of Cb and Cr.  A total of 7 MCU rows are needed,\nso you must pass a total of 7*16 = 112 \"scanlines\".  The last DCT block row\nof Y data is dummy, so it doesn't matter what you pass for it in the data\narrays, but the scanlines count must total up to 112 so that all of the Cb\nand Cr data gets passed.\n\nOutput suspension is supported with raw-data compression: if the data\ndestination module suspends, jpeg_write_raw_data() will return 0.\nIn this case the same data rows must be passed again on the next call.\n\n\nDecompression with raw data output implies bypassing all postprocessing.\nYou must deal with the color space and sampling factors present in the\nincoming file.  If your application only handles, say, 2h1v YCbCr data,\nyou must check for and fail on other color spaces or other sampling factors.\nThe library will not convert to a different color space for you.\n\nTo obtain raw data output, set cinfo->raw_data_out = TRUE before\njpeg_start_decompress() (it is set FALSE by jpeg_read_header()).  Be sure to\nverify that the color space and sampling factors are ones you can handle.\nFurthermore, set cinfo->do_fancy_upsampling = FALSE if you want to get real\ndownsampled data (it is set TRUE by jpeg_read_header()).\nThen call jpeg_read_raw_data() in place of jpeg_read_scanlines().  The\ndecompression process is otherwise the same as usual.\n\njpeg_read_raw_data() returns one MCU row per call, and thus you must pass a\nbuffer of at least max_v_samp_factor*block_size scanlines (scanline counting\nis the same as for raw-data compression).  The buffer you pass must be large\nenough to hold the actual data plus padding to DCT-block boundaries.  As with\ncompression, any entirely dummy DCT blocks are not processed so you need not\nallocate space for them, but the total scanline count includes them.  The\nabove example of computing buffer dimensions for raw-data compression is\nequally valid for decompression.\n\nInput suspension is supported with raw-data decompression: if the data source\nmodule suspends, jpeg_read_raw_data() will return 0.  You can also use\nbuffered-image mode to read raw data in multiple passes.\n\n\nReally raw data: DCT coefficients\n---------------------------------\n\nIt is possible to read or write the contents of a JPEG file as raw DCT\ncoefficients.  This facility is mainly intended for use in lossless\ntranscoding between different JPEG file formats.  Other possible applications\ninclude lossless cropping of a JPEG image, lossless reassembly of a\nmulti-strip or multi-tile TIFF/JPEG file into a single JPEG datastream, etc.\n\nTo read the contents of a JPEG file as DCT coefficients, open the file and do\njpeg_read_header() as usual.  But instead of calling jpeg_start_decompress()\nand jpeg_read_scanlines(), call jpeg_read_coefficients().  This will read the\nentire image into a set of virtual coefficient-block arrays, one array per\ncomponent.  The return value is a pointer to an array of virtual-array\ndescriptors.  Each virtual array can be accessed directly using the JPEG\nmemory manager's access_virt_barray method (see Memory management, below,\nand also read structure.txt's discussion of virtual array handling).  Or,\nfor simple transcoding to a different JPEG file format, the array list can\njust be handed directly to jpeg_write_coefficients().\n\nEach block in the block arrays contains quantized coefficient values in\nnormal array order (not JPEG zigzag order).  The block arrays contain only\nDCT blocks containing real data; any entirely-dummy blocks added to fill out\ninterleaved MCUs at the right or bottom edges of the image are discarded\nduring reading and are not stored in the block arrays.  (The size of each\nblock array can be determined from the width_in_blocks and height_in_blocks\nfields of the component's comp_info entry.)  This is also the data format\nexpected by jpeg_write_coefficients().\n\nWhen you are done using the virtual arrays, call jpeg_finish_decompress()\nto release the array storage and return the decompression object to an idle\nstate; or just call jpeg_destroy() if you don't need to reuse the object.\n\nIf you use a suspending data source, jpeg_read_coefficients() will return\nNULL if it is forced to suspend; a non-NULL return value indicates successful\ncompletion.  You need not test for a NULL return value when using a\nnon-suspending data source.\n\nIt is also possible to call jpeg_read_coefficients() to obtain access to the\ndecoder's coefficient arrays during a normal decode cycle in buffered-image\nmode.  This frammish might be useful for progressively displaying an incoming\nimage and then re-encoding it without loss.  To do this, decode in buffered-\nimage mode as discussed previously, then call jpeg_read_coefficients() after\nthe last jpeg_finish_output() call.  The arrays will be available for your use\nuntil you call jpeg_finish_decompress().\n\n\nTo write the contents of a JPEG file as DCT coefficients, you must provide\nthe DCT coefficients stored in virtual block arrays.  You can either pass\nblock arrays read from an input JPEG file by jpeg_read_coefficients(), or\nallocate virtual arrays from the JPEG compression object and fill them\nyourself.  In either case, jpeg_write_coefficients() is substituted for\njpeg_start_compress() and jpeg_write_scanlines().  Thus the sequence is\n  * Create compression object\n  * Set all compression parameters as necessary\n  * Request virtual arrays if needed\n  * jpeg_write_coefficients()\n  * jpeg_finish_compress()\n  * Destroy or re-use compression object\njpeg_write_coefficients() is passed a pointer to an array of virtual block\narray descriptors; the number of arrays is equal to cinfo.num_components.\n\nThe virtual arrays need only have been requested, not realized, before\njpeg_write_coefficients() is called.  A side-effect of\njpeg_write_coefficients() is to realize any virtual arrays that have been\nrequested from the compression object's memory manager.  Thus, when obtaining\nthe virtual arrays from the compression object, you should fill the arrays\nafter calling jpeg_write_coefficients().  The data is actually written out\nwhen you call jpeg_finish_compress(); jpeg_write_coefficients() only writes\nthe file header.\n\nWhen writing raw DCT coefficients, it is crucial that the JPEG quantization\ntables and sampling factors match the way the data was encoded, or the\nresulting file will be invalid.  For transcoding from an existing JPEG file,\nwe recommend using jpeg_copy_critical_parameters().  This routine initializes\nall the compression parameters to default values (like jpeg_set_defaults()),\nthen copies the critical information from a source decompression object.\nThe decompression object should have just been used to read the entire\nJPEG input file --- that is, it should be awaiting jpeg_finish_decompress().\n\njpeg_write_coefficients() marks all tables stored in the compression object\nas needing to be written to the output file (thus, it acts like\njpeg_start_compress(cinfo, TRUE)).  This is for safety's sake, to avoid\nemitting abbreviated JPEG files by accident.  If you really want to emit an\nabbreviated JPEG file, call jpeg_suppress_tables(), or set the tables'\nindividual sent_table flags, between calling jpeg_write_coefficients() and\njpeg_finish_compress().\n\n\nProgress monitoring\n-------------------\n\nSome applications may need to regain control from the JPEG library every so\noften.  The typical use of this feature is to produce a percent-done bar or\nother progress display.  (For a simple example, see cjpeg.c or djpeg.c.)\nAlthough you do get control back frequently during the data-transferring pass\n(the jpeg_read_scanlines or jpeg_write_scanlines loop), any additional passes\nwill occur inside jpeg_finish_compress or jpeg_start_decompress; those\nroutines may take a long time to execute, and you don't get control back\nuntil they are done.\n\nYou can define a progress-monitor routine which will be called periodically\nby the library.  No guarantees are made about how often this call will occur,\nso we don't recommend you use it for mouse tracking or anything like that.\nAt present, a call will occur once per MCU row, scanline, or sample row\ngroup, whichever unit is convenient for the current processing mode; so the\nwider the image, the longer the time between calls.  During the data\ntransferring pass, only one call occurs per call of jpeg_read_scanlines or\njpeg_write_scanlines, so don't pass a large number of scanlines at once if\nyou want fine resolution in the progress count.  (If you really need to use\nthe callback mechanism for time-critical tasks like mouse tracking, you could\ninsert additional calls inside some of the library's inner loops.)\n\nTo establish a progress-monitor callback, create a struct jpeg_progress_mgr,\nfill in its progress_monitor field with a pointer to your callback routine,\nand set cinfo->progress to point to the struct.  The callback will be called\nwhenever cinfo->progress is non-NULL.  (This pointer is set to NULL by\njpeg_create_compress or jpeg_create_decompress; the library will not change\nit thereafter.  So if you allocate dynamic storage for the progress struct,\nmake sure it will live as long as the JPEG object does.  Allocating from the\nJPEG memory manager with lifetime JPOOL_PERMANENT will work nicely.)  You\ncan use the same callback routine for both compression and decompression.\n\nThe jpeg_progress_mgr struct contains four fields which are set by the library:\n\tlong pass_counter;\t/* work units completed in this pass */\n\tlong pass_limit;\t/* total number of work units in this pass */\n\tint completed_passes;\t/* passes completed so far */\n\tint total_passes;\t/* total number of passes expected */\nDuring any one pass, pass_counter increases from 0 up to (not including)\npass_limit; the step size is usually but not necessarily 1.  The pass_limit\nvalue may change from one pass to another.  The expected total number of\npasses is in total_passes, and the number of passes already completed is in\ncompleted_passes.  Thus the fraction of work completed may be estimated as\n\t\tcompleted_passes + (pass_counter/pass_limit)\n\t\t--------------------------------------------\n\t\t\t\ttotal_passes\nignoring the fact that the passes may not be equal amounts of work.\n\nWhen decompressing, pass_limit can even change within a pass, because it\ndepends on the number of scans in the JPEG file, which isn't always known in\nadvance.  The computed fraction-of-work-done may jump suddenly (if the library\ndiscovers it has overestimated the number of scans) or even decrease (in the\nopposite case).  It is not wise to put great faith in the work estimate.\n\nWhen using the decompressor's buffered-image mode, the progress monitor work\nestimate is likely to be completely unhelpful, because the library has no way\nto know how many output passes will be demanded of it.  Currently, the library\nsets total_passes based on the assumption that there will be one more output\npass if the input file end hasn't yet been read (jpeg_input_complete() isn't\nTRUE), but no more output passes if the file end has been reached when the\noutput pass is started.  This means that total_passes will rise as additional\noutput passes are requested.  If you have a way of determining the input file\nsize, estimating progress based on the fraction of the file that's been read\nwill probably be more useful than using the library's value.\n\n\nMemory management\n-----------------\n\nThis section covers some key facts about the JPEG library's built-in memory\nmanager.  For more info, please read structure.txt's section about the memory\nmanager, and consult the source code if necessary.\n\nAll memory and temporary file allocation within the library is done via the\nmemory manager.  If necessary, you can replace the \"back end\" of the memory\nmanager to control allocation yourself (for example, if you don't want the\nlibrary to use malloc() and free() for some reason).\n\nSome data is allocated \"permanently\" and will not be freed until the JPEG\nobject is destroyed.  Most data is allocated \"per image\" and is freed by\njpeg_finish_compress, jpeg_finish_decompress, or jpeg_abort.  You can call the\nmemory manager yourself to allocate structures that will automatically be\nfreed at these times.  Typical code for this is\n  ptr = (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, size);\nUse JPOOL_PERMANENT to get storage that lasts as long as the JPEG object.\nUse alloc_large instead of alloc_small for anything bigger than a few Kbytes.\nThere are also alloc_sarray and alloc_barray routines that automatically\nbuild 2-D sample or block arrays.\n\nThe library's minimum space requirements to process an image depend on the\nimage's width, but not on its height, because the library ordinarily works\nwith \"strip\" buffers that are as wide as the image but just a few rows high.\nSome operating modes (eg, two-pass color quantization) require full-image\nbuffers.  Such buffers are treated as \"virtual arrays\": only the current strip\nneed be in memory, and the rest can be swapped out to a temporary file.\n\nIf you use the simplest memory manager back end (jmemnobs.c), then no\ntemporary files are used; virtual arrays are simply malloc()'d.  Images bigger\nthan memory can be processed only if your system supports virtual memory.\nThe other memory manager back ends support temporary files of various flavors\nand thus work in machines without virtual memory.  They may also be useful on\nUnix machines if you need to process images that exceed available swap space.\n\nWhen using temporary files, the library will make the in-memory buffers for\nits virtual arrays just big enough to stay within a \"maximum memory\" setting.\nYour application can set this limit by setting cinfo->mem->max_memory_to_use\nafter creating the JPEG object.  (Of course, there is still a minimum size for\nthe buffers, so the max-memory setting is effective only if it is bigger than\nthe minimum space needed.)  If you allocate any large structures yourself, you\nmust allocate them before jpeg_start_compress() or jpeg_start_decompress() in\norder to have them counted against the max memory limit.  Also keep in mind\nthat space allocated with alloc_small() is ignored, on the assumption that\nit's too small to be worth worrying about; so a reasonable safety margin\nshould be left when setting max_memory_to_use.\n\nIf you use the jmemname.c or jmemdos.c memory manager back end, it is\nimportant to clean up the JPEG object properly to ensure that the temporary\nfiles get deleted.  (This is especially crucial with jmemdos.c, where the\n\"temporary files\" may be extended-memory segments; if they are not freed,\nDOS will require a reboot to recover the memory.)  Thus, with these memory\nmanagers, it's a good idea to provide a signal handler that will trap any\nearly exit from your program.  The handler should call either jpeg_abort()\nor jpeg_destroy() for any active JPEG objects.  A handler is not needed with\njmemnobs.c, and shouldn't be necessary with jmemansi.c or jmemmac.c either,\nsince the C library is supposed to take care of deleting files made with\ntmpfile().\n\n\nMemory usage\n------------\n\nWorking memory requirements while performing compression or decompression\ndepend on image dimensions, image characteristics (such as colorspace and\nJPEG process), and operating mode (application-selected options).\n\nAs of v6b, the decompressor requires:\n 1. About 24K in more-or-less-fixed-size data.  This varies a bit depending\n    on operating mode and image characteristics (particularly color vs.\n    grayscale), but it doesn't depend on image dimensions.\n 2. Strip buffers (of size proportional to the image width) for IDCT and\n    upsampling results.  The worst case for commonly used sampling factors\n    is about 34 bytes * width in pixels for a color image.  A grayscale image\n    only needs about 8 bytes per pixel column.\n 3. A full-image DCT coefficient buffer is needed to decode a multi-scan JPEG\n    file (including progressive JPEGs), or whenever you select buffered-image\n    mode.  This takes 2 bytes/coefficient.  At typical 2x2 sampling, that's\n    3 bytes per pixel for a color image.  Worst case (1x1 sampling) requires\n    6 bytes/pixel.  For grayscale, figure 2 bytes/pixel.\n 4. To perform 2-pass color quantization, the decompressor also needs a\n    128K color lookup table and a full-image pixel buffer (3 bytes/pixel).\nThis does not count any memory allocated by the application, such as a\nbuffer to hold the final output image.\n\nThe above figures are valid for 8-bit JPEG data precision and a machine with\n32-bit ints.  For 9-bit to 12-bit JPEG data, double the size of the strip\nbuffers and quantization pixel buffer.  The \"fixed-size\" data will be\nsomewhat smaller with 16-bit ints, larger with 64-bit ints.  Also, CMYK\nor other unusual color spaces will require different amounts of space.\n\nThe full-image coefficient and pixel buffers, if needed at all, do not\nhave to be fully RAM resident; you can have the library use temporary\nfiles instead when the total memory usage would exceed a limit you set.\n(But if your OS supports virtual memory, it's probably better to just use\njmemnobs and let the OS do the swapping.)\n\nThe compressor's memory requirements are similar, except that it has no need\nfor color quantization.  Also, it needs a full-image DCT coefficient buffer\nif Huffman-table optimization is asked for, even if progressive mode is not\nrequested.\n\nIf you need more detailed information about memory usage in a particular\nsituation, you can enable the MEM_STATS code in jmemmgr.c.\n\n\nLibrary compile-time options\n----------------------------\n\nA number of compile-time options are available by modifying jmorecfg.h.\n\nThe IJG code currently supports 8-bit to 12-bit sample data precision by\ndefining BITS_IN_JSAMPLE as 8, 9, 10, 11, or 12.\nNote that a value larger than 8 causes JSAMPLE to be larger than a char,\nso it affects the surrounding application's image data.\nThe sample applications cjpeg and djpeg can support deeper than 8-bit data\nonly for PPM and GIF file formats; you must disable the other file formats\nto compile a 9-bit to 12-bit cjpeg or djpeg.  (install.txt has more\ninformation about that.)\nRun-time selection and conversion of data precision are currently not\nsupported and may be added later.\nException:  The transcoding part (jpegtran) supports all settings in a\nsingle instance, since it operates on the level of DCT coefficients and\nnot sample values.\n(If you need to include an 8-bit library and a 9-bit to 12-bit library for\ncompression or decompression in a single application, you could probably do\nit by defining NEED_SHORT_EXTERNAL_NAMES for just one of the copies.  You'd\nhave to access the 8-bit and the 9-bit to 12-bit copies from separate\napplication source files.  This is untested ... if you try it, we'd like to\nhear whether it works!)\n\nNote that the standard Huffman tables are only valid for 8-bit data precision.\nIf you selected more than 8-bit data precision, cjpeg uses arithmetic coding\nby default.  The Huffman encoder normally uses entropy optimization to\ncompute usable tables for higher precision.  Otherwise, you'll have to\nsupply different default Huffman tables.  You may also want to supply your\nown DCT quantization tables; the existing quality-scaling code has been\ndeveloped for 8-bit use, and probably doesn't generate especially good tables\nfor 9-bit to 12-bit.\n\nThe maximum number of components (color channels) in the image is determined\nby MAX_COMPONENTS.  The JPEG standard allows up to 255 components, but we\nexpect that few applications will need more than four or so.\n\nOn machines with unusual data type sizes, you may be able to improve\nperformance or reduce memory space by tweaking the various typedefs in\njmorecfg.h.  In particular, on some RISC CPUs, access to arrays of \"short\"s\nis quite slow; consider trading memory for speed by making JCOEF, INT16, and\nUINT16 be \"int\" or \"unsigned int\".  UINT8 is also a candidate to become int.\nYou probably don't want to make JSAMPLE be int unless you have lots of memory\nto burn.\n\nYou can reduce the size of the library by compiling out various optional\nfunctions.  To do this, undefine xxx_SUPPORTED symbols as necessary.\n\nYou can also save a few K by not having text error messages in the library;\nthe standard error message table occupies about 5Kb.  This is particularly\nreasonable for embedded applications where there's no good way to display \na message anyway.  To do this, remove the creation of the message table\n(jpeg_std_message_table[]) from jerror.c, and alter format_message to do\nsomething reasonable without it.  You could output the numeric value of the\nmessage code number, for example.  If you do this, you can also save a couple\nmore K by modifying the TRACEMSn() macros in jerror.h to expand to nothing;\nyou don't need trace capability anyway, right?\n\n\nPortability considerations\n--------------------------\n\nThe JPEG library has been written to be extremely portable; the sample\napplications cjpeg and djpeg are slightly less so.  This section summarizes\nthe design goals in this area.  (If you encounter any bugs that cause the\nlibrary to be less portable than is claimed here, we'd appreciate hearing\nabout them.)\n\nThe code works fine on ANSI C, C++, and pre-ANSI C compilers, using any of\nthe popular system include file setups, and some not-so-popular ones too.\nSee install.txt for configuration procedures.\n\nThe code is not dependent on the exact sizes of the C data types.  As\ndistributed, we make the assumptions that\n\tchar\tis at least 8 bits wide\n\tshort\tis at least 16 bits wide\n\tint\tis at least 16 bits wide\n\tlong\tis at least 32 bits wide\n(These are the minimum requirements of the ANSI C standard.)  Wider types will\nwork fine, although memory may be used inefficiently if char is much larger\nthan 8 bits or short is much bigger than 16 bits.  The code should work\nequally well with 16- or 32-bit ints.\n\nIn a system where these assumptions are not met, you may be able to make the\ncode work by modifying the typedefs in jmorecfg.h.  However, you will probably\nhave difficulty if int is less than 16 bits wide, since references to plain\nint abound in the code.\n\nchar can be either signed or unsigned, although the code runs faster if an\nunsigned char type is available.  If char is wider than 8 bits, you will need\nto redefine JOCTET and/or provide custom data source/destination managers so\nthat JOCTET represents exactly 8 bits of data on external storage.\n\nThe JPEG library proper does not assume ASCII representation of characters.\nBut some of the image file I/O modules in cjpeg/djpeg do have ASCII\ndependencies in file-header manipulation; so does cjpeg's select_file_type()\nroutine.\n\nThe JPEG library does not rely heavily on the C library.  In particular, C\nstdio is used only by the data source/destination modules and the error\nhandler, all of which are application-replaceable.  (cjpeg/djpeg are more\nheavily dependent on stdio.)  malloc and free are called only from the memory\nmanager \"back end\" module, so you can use a different memory allocator by\nreplacing that one file.\n\nThe code generally assumes that C names must be unique in the first 15\ncharacters.  However, global function names can be made unique in the\nfirst 6 characters by defining NEED_SHORT_EXTERNAL_NAMES.\n\nMore info about porting the code may be gleaned by reading jconfig.txt,\njmorecfg.h, and jinclude.h.\n\n\nNotes for MS-DOS implementors\n-----------------------------\n\nThe IJG code is designed to work efficiently in 80x86 \"small\" or \"medium\"\nmemory models (i.e., data pointers are 16 bits unless explicitly declared\n\"far\"; code pointers can be either size).  You may be able to use small\nmodel to compile cjpeg or djpeg by itself, but you will probably have to use\nmedium model for any larger application.  This won't make much difference in\nperformance.  You *will* take a noticeable performance hit if you use a\nlarge-data memory model (perhaps 10%-25%), and you should avoid \"huge\" model\nif at all possible.\n\nThe JPEG library typically needs 2Kb-3Kb of stack space.  It will also\nmalloc about 20K-30K of near heap space while executing (and lots of far\nheap, but that doesn't count in this calculation).  This figure will vary\ndepending on selected operating mode, and to a lesser extent on image size.\nThere is also about 5Kb-6Kb of constant data which will be allocated in the\nnear data segment (about 4Kb of this is the error message table).\nThus you have perhaps 20K available for other modules' static data and near\nheap space before you need to go to a larger memory model.  The C library's\nstatic data will account for several K of this, but that still leaves a good\ndeal for your needs.  (If you are tight on space, you could reduce the sizes\nof the I/O buffers allocated by jdatasrc.c and jdatadst.c, say from 4K to\n1K.  Another possibility is to move the error message table to far memory;\nthis should be doable with only localized hacking on jerror.c.)\n\nAbout 2K of the near heap space is \"permanent\" memory that will not be\nreleased until you destroy the JPEG object.  This is only an issue if you\nsave a JPEG object between compression or decompression operations.\n\nFar data space may also be a tight resource when you are dealing with large\nimages.  The most memory-intensive case is decompression with two-pass color\nquantization, or single-pass quantization to an externally supplied color\nmap.  This requires a 128Kb color lookup table plus strip buffers amounting\nto about 40 bytes per column for typical sampling ratios (eg, about 25600\nbytes for a 640-pixel-wide image).  You may not be able to process wide\nimages if you have large data structures of your own.\n\nOf course, all of these concerns vanish if you use a 32-bit flat-memory-model\ncompiler, such as DJGPP or Watcom C.  We highly recommend flat model if you\ncan use it; the JPEG library is significantly faster in flat model.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/ltmain.sh",
    "content": "#! /bin/sh\n## DO NOT EDIT - This file generated from ./build-aux/ltmain.in\n##               by inline-source v2014-01-03.01\n\n# libtool (GNU libtool) 2.4.6\n# Provide generalized library-building support services.\n# Written by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996\n\n# Copyright (C) 1996-2015 Free Software Foundation, Inc.\n# This is free software; see the source for copying conditions.  There is NO\n# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n# GNU Libtool is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2 of the License, or\n# (at your option) any later version.\n#\n# As a special exception to the GNU General Public License,\n# if you distribute this file as part of a program or library that\n# is built using GNU Libtool, you may include this file under the\n# same distribution terms that you use for the rest of that program.\n#\n# GNU Libtool is distributed in the hope that it will be useful, but\n# WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n# General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n\nPROGRAM=libtool\nPACKAGE=libtool\nVERSION=2.4.6\npackage_revision=2.4.6\n\n\n## ------ ##\n## Usage. ##\n## ------ ##\n\n# Run './libtool --help' for help with using this script from the\n# command line.\n\n\n## ------------------------------- ##\n## User overridable command paths. ##\n## ------------------------------- ##\n\n# After configure completes, it has a better idea of some of the\n# shell tools we need than the defaults used by the functions shared\n# with bootstrap, so set those here where they can still be over-\n# ridden by the user, but otherwise take precedence.\n\n: ${AUTOCONF=\"autoconf\"}\n: ${AUTOMAKE=\"automake\"}\n\n\n## -------------------------- ##\n## Source external libraries. ##\n## -------------------------- ##\n\n# Much of our low-level functionality needs to be sourced from external\n# libraries, which are installed to $pkgauxdir.\n\n# Set a version string for this script.\nscriptversion=2015-01-20.17; # UTC\n\n# General shell script boiler plate, and helper functions.\n# Written by Gary V. Vaughan, 2004\n\n# Copyright (C) 2004-2015 Free Software Foundation, Inc.\n# This is free software; see the source for copying conditions.  There is NO\n# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 3 of the License, or\n# (at your option) any later version.\n\n# As a special exception to the GNU General Public License, if you distribute\n# this file as part of a program or library that is built using GNU Libtool,\n# you may include this file under the same distribution terms that you use\n# for the rest of that program.\n\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNES FOR A PARTICULAR PURPOSE. See the GNU\n# General Public License for more details.\n\n# You should have received a copy of the GNU General Public License\n# along with this program. If not, see <http://www.gnu.org/licenses/>.\n\n# Please report bugs or propose patches to gary@gnu.org.\n\n\n## ------ ##\n## Usage. ##\n## ------ ##\n\n# Evaluate this file near the top of your script to gain access to\n# the functions and variables defined here:\n#\n#   . `echo \"$0\" | ${SED-sed} 's|[^/]*$||'`/build-aux/funclib.sh\n#\n# If you need to override any of the default environment variable\n# settings, do that before evaluating this file.\n\n\n## -------------------- ##\n## Shell normalisation. ##\n## -------------------- ##\n\n# Some shells need a little help to be as Bourne compatible as possible.\n# Before doing anything else, make sure all that help has been provided!\n\nDUALCASE=1; export DUALCASE # for MKS sh\nif test -n \"${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then :\n  emulate sh\n  NULLCMD=:\n  # Pre-4.2 versions of Zsh do word splitting on ${1+\"$@\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '${1+\"$@\"}'='\"$@\"'\n  setopt NO_GLOB_SUBST\nelse\n  case `(set -o) 2>/dev/null` in *posix*) set -o posix ;; esac\nfi\n\n# NLS nuisances: We save the old values in case they are required later.\n_G_user_locale=\n_G_safe_locale=\nfor _G_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES\ndo\n  eval \"if test set = \\\"\\${$_G_var+set}\\\"; then\n          save_$_G_var=\\$$_G_var\n          $_G_var=C\n\t  export $_G_var\n\t  _G_user_locale=\\\"$_G_var=\\\\\\$save_\\$_G_var; \\$_G_user_locale\\\"\n\t  _G_safe_locale=\\\"$_G_var=C; \\$_G_safe_locale\\\"\n\tfi\"\ndone\n\n# CDPATH.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\n# Make sure IFS has a sensible default\nsp=' '\nnl='\n'\nIFS=\"$sp\t$nl\"\n\n# There are apparently some retarded systems that use ';' as a PATH separator!\nif test \"${PATH_SEPARATOR+set}\" != set; then\n  PATH_SEPARATOR=:\n  (PATH='/bin;/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 && {\n    (PATH='/bin:/bin'; FPATH=$PATH; sh -c :) >/dev/null 2>&1 ||\n      PATH_SEPARATOR=';'\n  }\nfi\n\n\n\n## ------------------------- ##\n## Locate command utilities. ##\n## ------------------------- ##\n\n\n# func_executable_p FILE\n# ----------------------\n# Check that FILE is an executable regular file.\nfunc_executable_p ()\n{\n    test -f \"$1\" && test -x \"$1\"\n}\n\n\n# func_path_progs PROGS_LIST CHECK_FUNC [PATH]\n# --------------------------------------------\n# Search for either a program that responds to --version with output\n# containing \"GNU\", or else returned by CHECK_FUNC otherwise, by\n# trying all the directories in PATH with each of the elements of\n# PROGS_LIST.\n#\n# CHECK_FUNC should accept the path to a candidate program, and\n# set $func_check_prog_result if it truncates its output less than\n# $_G_path_prog_max characters.\nfunc_path_progs ()\n{\n    _G_progs_list=$1\n    _G_check_func=$2\n    _G_PATH=${3-\"$PATH\"}\n\n    _G_path_prog_max=0\n    _G_path_prog_found=false\n    _G_save_IFS=$IFS; IFS=${PATH_SEPARATOR-:}\n    for _G_dir in $_G_PATH; do\n      IFS=$_G_save_IFS\n      test -z \"$_G_dir\" && _G_dir=.\n      for _G_prog_name in $_G_progs_list; do\n        for _exeext in '' .EXE; do\n          _G_path_prog=$_G_dir/$_G_prog_name$_exeext\n          func_executable_p \"$_G_path_prog\" || continue\n          case `\"$_G_path_prog\" --version 2>&1` in\n            *GNU*) func_path_progs_result=$_G_path_prog _G_path_prog_found=: ;;\n            *)     $_G_check_func $_G_path_prog\n\t\t   func_path_progs_result=$func_check_prog_result\n\t\t   ;;\n          esac\n          $_G_path_prog_found && break 3\n        done\n      done\n    done\n    IFS=$_G_save_IFS\n    test -z \"$func_path_progs_result\" && {\n      echo \"no acceptable sed could be found in \\$PATH\" >&2\n      exit 1\n    }\n}\n\n\n# We want to be able to use the functions in this file before configure\n# has figured out where the best binaries are kept, which means we have\n# to search for them ourselves - except when the results are already set\n# where we skip the searches.\n\n# Unless the user overrides by setting SED, search the path for either GNU\n# sed, or the sed that truncates its output the least.\ntest -z \"$SED\" && {\n  _G_sed_script=s/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/\n  for _G_i in 1 2 3 4 5 6 7; do\n    _G_sed_script=$_G_sed_script$nl$_G_sed_script\n  done\n  echo \"$_G_sed_script\" 2>/dev/null | sed 99q >conftest.sed\n  _G_sed_script=\n\n  func_check_prog_sed ()\n  {\n    _G_path_prog=$1\n\n    _G_count=0\n    printf 0123456789 >conftest.in\n    while :\n    do\n      cat conftest.in conftest.in >conftest.tmp\n      mv conftest.tmp conftest.in\n      cp conftest.in conftest.nl\n      echo '' >> conftest.nl\n      \"$_G_path_prog\" -f conftest.sed <conftest.nl >conftest.out 2>/dev/null || break\n      diff conftest.out conftest.nl >/dev/null 2>&1 || break\n      _G_count=`expr $_G_count + 1`\n      if test \"$_G_count\" -gt \"$_G_path_prog_max\"; then\n        # Best one so far, save it but keep looking for a better one\n        func_check_prog_result=$_G_path_prog\n        _G_path_prog_max=$_G_count\n      fi\n      # 10*(2^10) chars as input seems more than enough\n      test 10 -lt \"$_G_count\" && break\n    done\n    rm -f conftest.in conftest.tmp conftest.nl conftest.out\n  }\n\n  func_path_progs \"sed gsed\" func_check_prog_sed $PATH:/usr/xpg4/bin\n  rm -f conftest.sed\n  SED=$func_path_progs_result\n}\n\n\n# Unless the user overrides by setting GREP, search the path for either GNU\n# grep, or the grep that truncates its output the least.\ntest -z \"$GREP\" && {\n  func_check_prog_grep ()\n  {\n    _G_path_prog=$1\n\n    _G_count=0\n    _G_path_prog_max=0\n    printf 0123456789 >conftest.in\n    while :\n    do\n      cat conftest.in conftest.in >conftest.tmp\n      mv conftest.tmp conftest.in\n      cp conftest.in conftest.nl\n      echo 'GREP' >> conftest.nl\n      \"$_G_path_prog\" -e 'GREP$' -e '-(cannot match)-' <conftest.nl >conftest.out 2>/dev/null || break\n      diff conftest.out conftest.nl >/dev/null 2>&1 || break\n      _G_count=`expr $_G_count + 1`\n      if test \"$_G_count\" -gt \"$_G_path_prog_max\"; then\n        # Best one so far, save it but keep looking for a better one\n        func_check_prog_result=$_G_path_prog\n        _G_path_prog_max=$_G_count\n      fi\n      # 10*(2^10) chars as input seems more than enough\n      test 10 -lt \"$_G_count\" && break\n    done\n    rm -f conftest.in conftest.tmp conftest.nl conftest.out\n  }\n\n  func_path_progs \"grep ggrep\" func_check_prog_grep $PATH:/usr/xpg4/bin\n  GREP=$func_path_progs_result\n}\n\n\n## ------------------------------- ##\n## User overridable command paths. ##\n## ------------------------------- ##\n\n# All uppercase variable names are used for environment variables.  These\n# variables can be overridden by the user before calling a script that\n# uses them if a suitable command of that name is not already available\n# in the command search PATH.\n\n: ${CP=\"cp -f\"}\n: ${ECHO=\"printf %s\\n\"}\n: ${EGREP=\"$GREP -E\"}\n: ${FGREP=\"$GREP -F\"}\n: ${LN_S=\"ln -s\"}\n: ${MAKE=\"make\"}\n: ${MKDIR=\"mkdir\"}\n: ${MV=\"mv -f\"}\n: ${RM=\"rm -f\"}\n: ${SHELL=\"${CONFIG_SHELL-/bin/sh}\"}\n\n\n## -------------------- ##\n## Useful sed snippets. ##\n## -------------------- ##\n\nsed_dirname='s|/[^/]*$||'\nsed_basename='s|^.*/||'\n\n# Sed substitution that helps us do robust quoting.  It backslashifies\n# metacharacters that are still active within double-quoted strings.\nsed_quote_subst='s|\\([`\"$\\\\]\\)|\\\\\\1|g'\n\n# Same as above, but do not quote variable references.\nsed_double_quote_subst='s/\\([\"`\\\\]\\)/\\\\\\1/g'\n\n# Sed substitution that turns a string into a regex matching for the\n# string literally.\nsed_make_literal_regex='s|[].[^$\\\\*\\/]|\\\\&|g'\n\n# Sed substitution that converts a w32 file name or path\n# that contains forward slashes, into one that contains\n# (escaped) backslashes.  A very naive implementation.\nsed_naive_backslashify='s|\\\\\\\\*|\\\\|g;s|/|\\\\|g;s|\\\\|\\\\\\\\|g'\n\n# Re-'\\' parameter expansions in output of sed_double_quote_subst that\n# were '\\'-ed in input to the same.  If an odd number of '\\' preceded a\n# '$' in input to sed_double_quote_subst, that '$' was protected from\n# expansion.  Since each input '\\' is now two '\\'s, look for any number\n# of runs of four '\\'s followed by two '\\'s and then a '$'.  '\\' that '$'.\n_G_bs='\\\\'\n_G_bs2='\\\\\\\\'\n_G_bs4='\\\\\\\\\\\\\\\\'\n_G_dollar='\\$'\nsed_double_backslash=\"\\\n  s/$_G_bs4/&\\\\\n/g\n  s/^$_G_bs2$_G_dollar/$_G_bs&/\n  s/\\\\([^$_G_bs]\\\\)$_G_bs2$_G_dollar/\\\\1$_G_bs2$_G_bs$_G_dollar/g\n  s/\\n//g\"\n\n\n## ----------------- ##\n## Global variables. ##\n## ----------------- ##\n\n# Except for the global variables explicitly listed below, the following\n# functions in the '^func_' namespace, and the '^require_' namespace\n# variables initialised in the 'Resource management' section, sourcing\n# this file will not pollute your global namespace with anything\n# else. There's no portable way to scope variables in Bourne shell\n# though, so actually running these functions will sometimes place\n# results into a variable named after the function, and often use\n# temporary variables in the '^_G_' namespace. If you are careful to\n# avoid using those namespaces casually in your sourcing script, things\n# should continue to work as you expect. And, of course, you can freely\n# overwrite any of the functions or variables defined here before\n# calling anything to customize them.\n\nEXIT_SUCCESS=0\nEXIT_FAILURE=1\nEXIT_MISMATCH=63  # $? = 63 is used to indicate version mismatch to missing.\nEXIT_SKIP=77\t  # $? = 77 is used to indicate a skipped test to automake.\n\n# Allow overriding, eg assuming that you follow the convention of\n# putting '$debug_cmd' at the start of all your functions, you can get\n# bash to show function call trace with:\n#\n#    debug_cmd='eval echo \"${FUNCNAME[0]} $*\" >&2' bash your-script-name\ndebug_cmd=${debug_cmd-\":\"}\nexit_cmd=:\n\n# By convention, finish your script with:\n#\n#    exit $exit_status\n#\n# so that you can set exit_status to non-zero if you want to indicate\n# something went wrong during execution without actually bailing out at\n# the point of failure.\nexit_status=$EXIT_SUCCESS\n\n# Work around backward compatibility issue on IRIX 6.5. On IRIX 6.4+, sh\n# is ksh but when the shell is invoked as \"sh\" and the current value of\n# the _XPG environment variable is not equal to 1 (one), the special\n# positional parameter $0, within a function call, is the name of the\n# function.\nprogpath=$0\n\n# The name of this program.\nprogname=`$ECHO \"$progpath\" |$SED \"$sed_basename\"`\n\n# Make sure we have an absolute progpath for reexecution:\ncase $progpath in\n  [\\\\/]*|[A-Za-z]:\\\\*) ;;\n  *[\\\\/]*)\n     progdir=`$ECHO \"$progpath\" |$SED \"$sed_dirname\"`\n     progdir=`cd \"$progdir\" && pwd`\n     progpath=$progdir/$progname\n     ;;\n  *)\n     _G_IFS=$IFS\n     IFS=${PATH_SEPARATOR-:}\n     for progdir in $PATH; do\n       IFS=$_G_IFS\n       test -x \"$progdir/$progname\" && break\n     done\n     IFS=$_G_IFS\n     test -n \"$progdir\" || progdir=`pwd`\n     progpath=$progdir/$progname\n     ;;\nesac\n\n\n## ----------------- ##\n## Standard options. ##\n## ----------------- ##\n\n# The following options affect the operation of the functions defined\n# below, and should be set appropriately depending on run-time para-\n# meters passed on the command line.\n\nopt_dry_run=false\nopt_quiet=false\nopt_verbose=false\n\n# Categories 'all' and 'none' are always available.  Append any others\n# you will pass as the first argument to func_warning from your own\n# code.\nwarning_categories=\n\n# By default, display warnings according to 'opt_warning_types'.  Set\n# 'warning_func'  to ':' to elide all warnings, or func_fatal_error to\n# treat the next displayed warning as a fatal error.\nwarning_func=func_warn_and_continue\n\n# Set to 'all' to display all warnings, 'none' to suppress all\n# warnings, or a space delimited list of some subset of\n# 'warning_categories' to display only the listed warnings.\nopt_warning_types=all\n\n\n## -------------------- ##\n## Resource management. ##\n## -------------------- ##\n\n# This section contains definitions for functions that each ensure a\n# particular resource (a file, or a non-empty configuration variable for\n# example) is available, and if appropriate to extract default values\n# from pertinent package files. Call them using their associated\n# 'require_*' variable to ensure that they are executed, at most, once.\n#\n# It's entirely deliberate that calling these functions can set\n# variables that don't obey the namespace limitations obeyed by the rest\n# of this file, in order that that they be as useful as possible to\n# callers.\n\n\n# require_term_colors\n# -------------------\n# Allow display of bold text on terminals that support it.\nrequire_term_colors=func_require_term_colors\nfunc_require_term_colors ()\n{\n    $debug_cmd\n\n    test -t 1 && {\n      # COLORTERM and USE_ANSI_COLORS environment variables take\n      # precedence, because most terminfo databases neglect to describe\n      # whether color sequences are supported.\n      test -n \"${COLORTERM+set}\" && : ${USE_ANSI_COLORS=\"1\"}\n\n      if test 1 = \"$USE_ANSI_COLORS\"; then\n        # Standard ANSI escape sequences\n        tc_reset='\u001b[0m'\n        tc_bold='\u001b[1m';   tc_standout='\u001b[7m'\n        tc_red='\u001b[31m';   tc_green='\u001b[32m'\n        tc_blue='\u001b[34m';  tc_cyan='\u001b[36m'\n      else\n        # Otherwise trust the terminfo database after all.\n        test -n \"`tput sgr0 2>/dev/null`\" && {\n          tc_reset=`tput sgr0`\n          test -n \"`tput bold 2>/dev/null`\" && tc_bold=`tput bold`\n          tc_standout=$tc_bold\n          test -n \"`tput smso 2>/dev/null`\" && tc_standout=`tput smso`\n          test -n \"`tput setaf 1 2>/dev/null`\" && tc_red=`tput setaf 1`\n          test -n \"`tput setaf 2 2>/dev/null`\" && tc_green=`tput setaf 2`\n          test -n \"`tput setaf 4 2>/dev/null`\" && tc_blue=`tput setaf 4`\n          test -n \"`tput setaf 5 2>/dev/null`\" && tc_cyan=`tput setaf 5`\n        }\n      fi\n    }\n\n    require_term_colors=:\n}\n\n\n## ----------------- ##\n## Function library. ##\n## ----------------- ##\n\n# This section contains a variety of useful functions to call in your\n# scripts. Take note of the portable wrappers for features provided by\n# some modern shells, which will fall back to slower equivalents on\n# less featureful shells.\n\n\n# func_append VAR VALUE\n# ---------------------\n# Append VALUE onto the existing contents of VAR.\n\n  # We should try to minimise forks, especially on Windows where they are\n  # unreasonably slow, so skip the feature probes when bash or zsh are\n  # being used:\n  if test set = \"${BASH_VERSION+set}${ZSH_VERSION+set}\"; then\n    : ${_G_HAVE_ARITH_OP=\"yes\"}\n    : ${_G_HAVE_XSI_OPS=\"yes\"}\n    # The += operator was introduced in bash 3.1\n    case $BASH_VERSION in\n      [12].* | 3.0 | 3.0*) ;;\n      *)\n        : ${_G_HAVE_PLUSEQ_OP=\"yes\"}\n        ;;\n    esac\n  fi\n\n  # _G_HAVE_PLUSEQ_OP\n  # Can be empty, in which case the shell is probed, \"yes\" if += is\n  # useable or anything else if it does not work.\n  test -z \"$_G_HAVE_PLUSEQ_OP\" \\\n    && (eval 'x=a; x+=\" b\"; test \"a b\" = \"$x\"') 2>/dev/null \\\n    && _G_HAVE_PLUSEQ_OP=yes\n\nif test yes = \"$_G_HAVE_PLUSEQ_OP\"\nthen\n  # This is an XSI compatible shell, allowing a faster implementation...\n  eval 'func_append ()\n  {\n    $debug_cmd\n\n    eval \"$1+=\\$2\"\n  }'\nelse\n  # ...otherwise fall back to using expr, which is often a shell builtin.\n  func_append ()\n  {\n    $debug_cmd\n\n    eval \"$1=\\$$1\\$2\"\n  }\nfi\n\n\n# func_append_quoted VAR VALUE\n# ----------------------------\n# Quote VALUE and append to the end of shell variable VAR, separated\n# by a space.\nif test yes = \"$_G_HAVE_PLUSEQ_OP\"; then\n  eval 'func_append_quoted ()\n  {\n    $debug_cmd\n\n    func_quote_for_eval \"$2\"\n    eval \"$1+=\\\\ \\$func_quote_for_eval_result\"\n  }'\nelse\n  func_append_quoted ()\n  {\n    $debug_cmd\n\n    func_quote_for_eval \"$2\"\n    eval \"$1=\\$$1\\\\ \\$func_quote_for_eval_result\"\n  }\nfi\n\n\n# func_append_uniq VAR VALUE\n# --------------------------\n# Append unique VALUE onto the existing contents of VAR, assuming\n# entries are delimited by the first character of VALUE.  For example:\n#\n#   func_append_uniq options \" --another-option option-argument\"\n#\n# will only append to $options if \" --another-option option-argument \"\n# is not already present somewhere in $options already (note spaces at\n# each end implied by leading space in second argument).\nfunc_append_uniq ()\n{\n    $debug_cmd\n\n    eval _G_current_value='`$ECHO $'$1'`'\n    _G_delim=`expr \"$2\" : '\\(.\\)'`\n\n    case $_G_delim$_G_current_value$_G_delim in\n      *\"$2$_G_delim\"*) ;;\n      *) func_append \"$@\" ;;\n    esac\n}\n\n\n# func_arith TERM...\n# ------------------\n# Set func_arith_result to the result of evaluating TERMs.\n  test -z \"$_G_HAVE_ARITH_OP\" \\\n    && (eval 'test 2 = $(( 1 + 1 ))') 2>/dev/null \\\n    && _G_HAVE_ARITH_OP=yes\n\nif test yes = \"$_G_HAVE_ARITH_OP\"; then\n  eval 'func_arith ()\n  {\n    $debug_cmd\n\n    func_arith_result=$(( $* ))\n  }'\nelse\n  func_arith ()\n  {\n    $debug_cmd\n\n    func_arith_result=`expr \"$@\"`\n  }\nfi\n\n\n# func_basename FILE\n# ------------------\n# Set func_basename_result to FILE with everything up to and including\n# the last / stripped.\nif test yes = \"$_G_HAVE_XSI_OPS\"; then\n  # If this shell supports suffix pattern removal, then use it to avoid\n  # forking. Hide the definitions single quotes in case the shell chokes\n  # on unsupported syntax...\n  _b='func_basename_result=${1##*/}'\n  _d='case $1 in\n        */*) func_dirname_result=${1%/*}$2 ;;\n        *  ) func_dirname_result=$3        ;;\n      esac'\n\nelse\n  # ...otherwise fall back to using sed.\n  _b='func_basename_result=`$ECHO \"$1\" |$SED \"$sed_basename\"`'\n  _d='func_dirname_result=`$ECHO \"$1\"  |$SED \"$sed_dirname\"`\n      if test \"X$func_dirname_result\" = \"X$1\"; then\n        func_dirname_result=$3\n      else\n        func_append func_dirname_result \"$2\"\n      fi'\nfi\n\neval 'func_basename ()\n{\n    $debug_cmd\n\n    '\"$_b\"'\n}'\n\n\n# func_dirname FILE APPEND NONDIR_REPLACEMENT\n# -------------------------------------------\n# Compute the dirname of FILE.  If nonempty, add APPEND to the result,\n# otherwise set result to NONDIR_REPLACEMENT.\neval 'func_dirname ()\n{\n    $debug_cmd\n\n    '\"$_d\"'\n}'\n\n\n# func_dirname_and_basename FILE APPEND NONDIR_REPLACEMENT\n# --------------------------------------------------------\n# Perform func_basename and func_dirname in a single function\n# call:\n#   dirname:  Compute the dirname of FILE.  If nonempty,\n#             add APPEND to the result, otherwise set result\n#             to NONDIR_REPLACEMENT.\n#             value returned in \"$func_dirname_result\"\n#   basename: Compute filename of FILE.\n#             value retuned in \"$func_basename_result\"\n# For efficiency, we do not delegate to the functions above but instead\n# duplicate the functionality here.\neval 'func_dirname_and_basename ()\n{\n    $debug_cmd\n\n    '\"$_b\"'\n    '\"$_d\"'\n}'\n\n\n# func_echo ARG...\n# ----------------\n# Echo program name prefixed message.\nfunc_echo ()\n{\n    $debug_cmd\n\n    _G_message=$*\n\n    func_echo_IFS=$IFS\n    IFS=$nl\n    for _G_line in $_G_message; do\n      IFS=$func_echo_IFS\n      $ECHO \"$progname: $_G_line\"\n    done\n    IFS=$func_echo_IFS\n}\n\n\n# func_echo_all ARG...\n# --------------------\n# Invoke $ECHO with all args, space-separated.\nfunc_echo_all ()\n{\n    $ECHO \"$*\"\n}\n\n\n# func_echo_infix_1 INFIX ARG...\n# ------------------------------\n# Echo program name, followed by INFIX on the first line, with any\n# additional lines not showing INFIX.\nfunc_echo_infix_1 ()\n{\n    $debug_cmd\n\n    $require_term_colors\n\n    _G_infix=$1; shift\n    _G_indent=$_G_infix\n    _G_prefix=\"$progname: $_G_infix: \"\n    _G_message=$*\n\n    # Strip color escape sequences before counting printable length\n    for _G_tc in \"$tc_reset\" \"$tc_bold\" \"$tc_standout\" \"$tc_red\" \"$tc_green\" \"$tc_blue\" \"$tc_cyan\"\n    do\n      test -n \"$_G_tc\" && {\n        _G_esc_tc=`$ECHO \"$_G_tc\" | $SED \"$sed_make_literal_regex\"`\n        _G_indent=`$ECHO \"$_G_indent\" | $SED \"s|$_G_esc_tc||g\"`\n      }\n    done\n    _G_indent=\"$progname: \"`echo \"$_G_indent\" | $SED 's|.| |g'`\"  \" ## exclude from sc_prohibit_nested_quotes\n\n    func_echo_infix_1_IFS=$IFS\n    IFS=$nl\n    for _G_line in $_G_message; do\n      IFS=$func_echo_infix_1_IFS\n      $ECHO \"$_G_prefix$tc_bold$_G_line$tc_reset\" >&2\n      _G_prefix=$_G_indent\n    done\n    IFS=$func_echo_infix_1_IFS\n}\n\n\n# func_error ARG...\n# -----------------\n# Echo program name prefixed message to standard error.\nfunc_error ()\n{\n    $debug_cmd\n\n    $require_term_colors\n\n    func_echo_infix_1 \"  $tc_standout${tc_red}error$tc_reset\" \"$*\" >&2\n}\n\n\n# func_fatal_error ARG...\n# -----------------------\n# Echo program name prefixed message to standard error, and exit.\nfunc_fatal_error ()\n{\n    $debug_cmd\n\n    func_error \"$*\"\n    exit $EXIT_FAILURE\n}\n\n\n# func_grep EXPRESSION FILENAME\n# -----------------------------\n# Check whether EXPRESSION matches any line of FILENAME, without output.\nfunc_grep ()\n{\n    $debug_cmd\n\n    $GREP \"$1\" \"$2\" >/dev/null 2>&1\n}\n\n\n# func_len STRING\n# ---------------\n# Set func_len_result to the length of STRING. STRING may not\n# start with a hyphen.\n  test -z \"$_G_HAVE_XSI_OPS\" \\\n    && (eval 'x=a/b/c;\n      test 5aa/bb/cc = \"${#x}${x%%/*}${x%/*}${x#*/}${x##*/}\"') 2>/dev/null \\\n    && _G_HAVE_XSI_OPS=yes\n\nif test yes = \"$_G_HAVE_XSI_OPS\"; then\n  eval 'func_len ()\n  {\n    $debug_cmd\n\n    func_len_result=${#1}\n  }'\nelse\n  func_len ()\n  {\n    $debug_cmd\n\n    func_len_result=`expr \"$1\" : \".*\" 2>/dev/null || echo $max_cmd_len`\n  }\nfi\n\n\n# func_mkdir_p DIRECTORY-PATH\n# ---------------------------\n# Make sure the entire path to DIRECTORY-PATH is available.\nfunc_mkdir_p ()\n{\n    $debug_cmd\n\n    _G_directory_path=$1\n    _G_dir_list=\n\n    if test -n \"$_G_directory_path\" && test : != \"$opt_dry_run\"; then\n\n      # Protect directory names starting with '-'\n      case $_G_directory_path in\n        -*) _G_directory_path=./$_G_directory_path ;;\n      esac\n\n      # While some portion of DIR does not yet exist...\n      while test ! -d \"$_G_directory_path\"; do\n        # ...make a list in topmost first order.  Use a colon delimited\n\t# list incase some portion of path contains whitespace.\n        _G_dir_list=$_G_directory_path:$_G_dir_list\n\n        # If the last portion added has no slash in it, the list is done\n        case $_G_directory_path in */*) ;; *) break ;; esac\n\n        # ...otherwise throw away the child directory and loop\n        _G_directory_path=`$ECHO \"$_G_directory_path\" | $SED -e \"$sed_dirname\"`\n      done\n      _G_dir_list=`$ECHO \"$_G_dir_list\" | $SED 's|:*$||'`\n\n      func_mkdir_p_IFS=$IFS; IFS=:\n      for _G_dir in $_G_dir_list; do\n\tIFS=$func_mkdir_p_IFS\n        # mkdir can fail with a 'File exist' error if two processes\n        # try to create one of the directories concurrently.  Don't\n        # stop in that case!\n        $MKDIR \"$_G_dir\" 2>/dev/null || :\n      done\n      IFS=$func_mkdir_p_IFS\n\n      # Bail out if we (or some other process) failed to create a directory.\n      test -d \"$_G_directory_path\" || \\\n        func_fatal_error \"Failed to create '$1'\"\n    fi\n}\n\n\n# func_mktempdir [BASENAME]\n# -------------------------\n# Make a temporary directory that won't clash with other running\n# libtool processes, and avoids race conditions if possible.  If\n# given, BASENAME is the basename for that directory.\nfunc_mktempdir ()\n{\n    $debug_cmd\n\n    _G_template=${TMPDIR-/tmp}/${1-$progname}\n\n    if test : = \"$opt_dry_run\"; then\n      # Return a directory name, but don't create it in dry-run mode\n      _G_tmpdir=$_G_template-$$\n    else\n\n      # If mktemp works, use that first and foremost\n      _G_tmpdir=`mktemp -d \"$_G_template-XXXXXXXX\" 2>/dev/null`\n\n      if test ! -d \"$_G_tmpdir\"; then\n        # Failing that, at least try and use $RANDOM to avoid a race\n        _G_tmpdir=$_G_template-${RANDOM-0}$$\n\n        func_mktempdir_umask=`umask`\n        umask 0077\n        $MKDIR \"$_G_tmpdir\"\n        umask $func_mktempdir_umask\n      fi\n\n      # If we're not in dry-run mode, bomb out on failure\n      test -d \"$_G_tmpdir\" || \\\n        func_fatal_error \"cannot create temporary directory '$_G_tmpdir'\"\n    fi\n\n    $ECHO \"$_G_tmpdir\"\n}\n\n\n# func_normal_abspath PATH\n# ------------------------\n# Remove doubled-up and trailing slashes, \".\" path components,\n# and cancel out any \"..\" path components in PATH after making\n# it an absolute path.\nfunc_normal_abspath ()\n{\n    $debug_cmd\n\n    # These SED scripts presuppose an absolute path with a trailing slash.\n    _G_pathcar='s|^/\\([^/]*\\).*$|\\1|'\n    _G_pathcdr='s|^/[^/]*||'\n    _G_removedotparts=':dotsl\n\t\ts|/\\./|/|g\n\t\tt dotsl\n\t\ts|/\\.$|/|'\n    _G_collapseslashes='s|/\\{1,\\}|/|g'\n    _G_finalslash='s|/*$|/|'\n\n    # Start from root dir and reassemble the path.\n    func_normal_abspath_result=\n    func_normal_abspath_tpath=$1\n    func_normal_abspath_altnamespace=\n    case $func_normal_abspath_tpath in\n      \"\")\n        # Empty path, that just means $cwd.\n        func_stripname '' '/' \"`pwd`\"\n        func_normal_abspath_result=$func_stripname_result\n        return\n        ;;\n      # The next three entries are used to spot a run of precisely\n      # two leading slashes without using negated character classes;\n      # we take advantage of case's first-match behaviour.\n      ///*)\n        # Unusual form of absolute path, do nothing.\n        ;;\n      //*)\n        # Not necessarily an ordinary path; POSIX reserves leading '//'\n        # and for example Cygwin uses it to access remote file shares\n        # over CIFS/SMB, so we conserve a leading double slash if found.\n        func_normal_abspath_altnamespace=/\n        ;;\n      /*)\n        # Absolute path, do nothing.\n        ;;\n      *)\n        # Relative path, prepend $cwd.\n        func_normal_abspath_tpath=`pwd`/$func_normal_abspath_tpath\n        ;;\n    esac\n\n    # Cancel out all the simple stuff to save iterations.  We also want\n    # the path to end with a slash for ease of parsing, so make sure\n    # there is one (and only one) here.\n    func_normal_abspath_tpath=`$ECHO \"$func_normal_abspath_tpath\" | $SED \\\n          -e \"$_G_removedotparts\" -e \"$_G_collapseslashes\" -e \"$_G_finalslash\"`\n    while :; do\n      # Processed it all yet?\n      if test / = \"$func_normal_abspath_tpath\"; then\n        # If we ascended to the root using \"..\" the result may be empty now.\n        if test -z \"$func_normal_abspath_result\"; then\n          func_normal_abspath_result=/\n        fi\n        break\n      fi\n      func_normal_abspath_tcomponent=`$ECHO \"$func_normal_abspath_tpath\" | $SED \\\n          -e \"$_G_pathcar\"`\n      func_normal_abspath_tpath=`$ECHO \"$func_normal_abspath_tpath\" | $SED \\\n          -e \"$_G_pathcdr\"`\n      # Figure out what to do with it\n      case $func_normal_abspath_tcomponent in\n        \"\")\n          # Trailing empty path component, ignore it.\n          ;;\n        ..)\n          # Parent dir; strip last assembled component from result.\n          func_dirname \"$func_normal_abspath_result\"\n          func_normal_abspath_result=$func_dirname_result\n          ;;\n        *)\n          # Actual path component, append it.\n          func_append func_normal_abspath_result \"/$func_normal_abspath_tcomponent\"\n          ;;\n      esac\n    done\n    # Restore leading double-slash if one was found on entry.\n    func_normal_abspath_result=$func_normal_abspath_altnamespace$func_normal_abspath_result\n}\n\n\n# func_notquiet ARG...\n# --------------------\n# Echo program name prefixed message only when not in quiet mode.\nfunc_notquiet ()\n{\n    $debug_cmd\n\n    $opt_quiet || func_echo ${1+\"$@\"}\n\n    # A bug in bash halts the script if the last line of a function\n    # fails when set -e is in force, so we need another command to\n    # work around that:\n    :\n}\n\n\n# func_relative_path SRCDIR DSTDIR\n# --------------------------------\n# Set func_relative_path_result to the relative path from SRCDIR to DSTDIR.\nfunc_relative_path ()\n{\n    $debug_cmd\n\n    func_relative_path_result=\n    func_normal_abspath \"$1\"\n    func_relative_path_tlibdir=$func_normal_abspath_result\n    func_normal_abspath \"$2\"\n    func_relative_path_tbindir=$func_normal_abspath_result\n\n    # Ascend the tree starting from libdir\n    while :; do\n      # check if we have found a prefix of bindir\n      case $func_relative_path_tbindir in\n        $func_relative_path_tlibdir)\n          # found an exact match\n          func_relative_path_tcancelled=\n          break\n          ;;\n        $func_relative_path_tlibdir*)\n          # found a matching prefix\n          func_stripname \"$func_relative_path_tlibdir\" '' \"$func_relative_path_tbindir\"\n          func_relative_path_tcancelled=$func_stripname_result\n          if test -z \"$func_relative_path_result\"; then\n            func_relative_path_result=.\n          fi\n          break\n          ;;\n        *)\n          func_dirname $func_relative_path_tlibdir\n          func_relative_path_tlibdir=$func_dirname_result\n          if test -z \"$func_relative_path_tlibdir\"; then\n            # Have to descend all the way to the root!\n            func_relative_path_result=../$func_relative_path_result\n            func_relative_path_tcancelled=$func_relative_path_tbindir\n            break\n          fi\n          func_relative_path_result=../$func_relative_path_result\n          ;;\n      esac\n    done\n\n    # Now calculate path; take care to avoid doubling-up slashes.\n    func_stripname '' '/' \"$func_relative_path_result\"\n    func_relative_path_result=$func_stripname_result\n    func_stripname '/' '/' \"$func_relative_path_tcancelled\"\n    if test -n \"$func_stripname_result\"; then\n      func_append func_relative_path_result \"/$func_stripname_result\"\n    fi\n\n    # Normalisation. If bindir is libdir, return '.' else relative path.\n    if test -n \"$func_relative_path_result\"; then\n      func_stripname './' '' \"$func_relative_path_result\"\n      func_relative_path_result=$func_stripname_result\n    fi\n\n    test -n \"$func_relative_path_result\" || func_relative_path_result=.\n\n    :\n}\n\n\n# func_quote_for_eval ARG...\n# --------------------------\n# Aesthetically quote ARGs to be evaled later.\n# This function returns two values:\n#   i) func_quote_for_eval_result\n#      double-quoted, suitable for a subsequent eval\n#  ii) func_quote_for_eval_unquoted_result\n#      has all characters that are still active within double\n#      quotes backslashified.\nfunc_quote_for_eval ()\n{\n    $debug_cmd\n\n    func_quote_for_eval_unquoted_result=\n    func_quote_for_eval_result=\n    while test 0 -lt $#; do\n      case $1 in\n        *[\\\\\\`\\\"\\$]*)\n\t  _G_unquoted_arg=`printf '%s\\n' \"$1\" |$SED \"$sed_quote_subst\"` ;;\n        *)\n          _G_unquoted_arg=$1 ;;\n      esac\n      if test -n \"$func_quote_for_eval_unquoted_result\"; then\n\tfunc_append func_quote_for_eval_unquoted_result \" $_G_unquoted_arg\"\n      else\n        func_append func_quote_for_eval_unquoted_result \"$_G_unquoted_arg\"\n      fi\n\n      case $_G_unquoted_arg in\n        # Double-quote args containing shell metacharacters to delay\n        # word splitting, command substitution and variable expansion\n        # for a subsequent eval.\n        # Many Bourne shells cannot handle close brackets correctly\n        # in scan sets, so we specify it separately.\n        *[\\[\\~\\#\\^\\&\\*\\(\\)\\{\\}\\|\\;\\<\\>\\?\\'\\ \\\t]*|*]*|\"\")\n          _G_quoted_arg=\\\"$_G_unquoted_arg\\\"\n          ;;\n        *)\n          _G_quoted_arg=$_G_unquoted_arg\n\t  ;;\n      esac\n\n      if test -n \"$func_quote_for_eval_result\"; then\n\tfunc_append func_quote_for_eval_result \" $_G_quoted_arg\"\n      else\n        func_append func_quote_for_eval_result \"$_G_quoted_arg\"\n      fi\n      shift\n    done\n}\n\n\n# func_quote_for_expand ARG\n# -------------------------\n# Aesthetically quote ARG to be evaled later; same as above,\n# but do not quote variable references.\nfunc_quote_for_expand ()\n{\n    $debug_cmd\n\n    case $1 in\n      *[\\\\\\`\\\"]*)\n\t_G_arg=`$ECHO \"$1\" | $SED \\\n\t    -e \"$sed_double_quote_subst\" -e \"$sed_double_backslash\"` ;;\n      *)\n        _G_arg=$1 ;;\n    esac\n\n    case $_G_arg in\n      # Double-quote args containing shell metacharacters to delay\n      # word splitting and command substitution for a subsequent eval.\n      # Many Bourne shells cannot handle close brackets correctly\n      # in scan sets, so we specify it separately.\n      *[\\[\\~\\#\\^\\&\\*\\(\\)\\{\\}\\|\\;\\<\\>\\?\\'\\ \\\t]*|*]*|\"\")\n        _G_arg=\\\"$_G_arg\\\"\n        ;;\n    esac\n\n    func_quote_for_expand_result=$_G_arg\n}\n\n\n# func_stripname PREFIX SUFFIX NAME\n# ---------------------------------\n# strip PREFIX and SUFFIX from NAME, and store in func_stripname_result.\n# PREFIX and SUFFIX must not contain globbing or regex special\n# characters, hashes, percent signs, but SUFFIX may contain a leading\n# dot (in which case that matches only a dot).\nif test yes = \"$_G_HAVE_XSI_OPS\"; then\n  eval 'func_stripname ()\n  {\n    $debug_cmd\n\n    # pdksh 5.2.14 does not do ${X%$Y} correctly if both X and Y are\n    # positional parameters, so assign one to ordinary variable first.\n    func_stripname_result=$3\n    func_stripname_result=${func_stripname_result#\"$1\"}\n    func_stripname_result=${func_stripname_result%\"$2\"}\n  }'\nelse\n  func_stripname ()\n  {\n    $debug_cmd\n\n    case $2 in\n      .*) func_stripname_result=`$ECHO \"$3\" | $SED -e \"s%^$1%%\" -e \"s%\\\\\\\\$2\\$%%\"`;;\n      *)  func_stripname_result=`$ECHO \"$3\" | $SED -e \"s%^$1%%\" -e \"s%$2\\$%%\"`;;\n    esac\n  }\nfi\n\n\n# func_show_eval CMD [FAIL_EXP]\n# -----------------------------\n# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is\n# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP\n# is given, then evaluate it.\nfunc_show_eval ()\n{\n    $debug_cmd\n\n    _G_cmd=$1\n    _G_fail_exp=${2-':'}\n\n    func_quote_for_expand \"$_G_cmd\"\n    eval \"func_notquiet $func_quote_for_expand_result\"\n\n    $opt_dry_run || {\n      eval \"$_G_cmd\"\n      _G_status=$?\n      if test 0 -ne \"$_G_status\"; then\n\teval \"(exit $_G_status); $_G_fail_exp\"\n      fi\n    }\n}\n\n\n# func_show_eval_locale CMD [FAIL_EXP]\n# ------------------------------------\n# Unless opt_quiet is true, then output CMD.  Then, if opt_dryrun is\n# not true, evaluate CMD.  If the evaluation of CMD fails, and FAIL_EXP\n# is given, then evaluate it.  Use the saved locale for evaluation.\nfunc_show_eval_locale ()\n{\n    $debug_cmd\n\n    _G_cmd=$1\n    _G_fail_exp=${2-':'}\n\n    $opt_quiet || {\n      func_quote_for_expand \"$_G_cmd\"\n      eval \"func_echo $func_quote_for_expand_result\"\n    }\n\n    $opt_dry_run || {\n      eval \"$_G_user_locale\n\t    $_G_cmd\"\n      _G_status=$?\n      eval \"$_G_safe_locale\"\n      if test 0 -ne \"$_G_status\"; then\n\teval \"(exit $_G_status); $_G_fail_exp\"\n      fi\n    }\n}\n\n\n# func_tr_sh\n# ----------\n# Turn $1 into a string suitable for a shell variable name.\n# Result is stored in $func_tr_sh_result.  All characters\n# not in the set a-zA-Z0-9_ are replaced with '_'. Further,\n# if $1 begins with a digit, a '_' is prepended as well.\nfunc_tr_sh ()\n{\n    $debug_cmd\n\n    case $1 in\n    [0-9]* | *[!a-zA-Z0-9_]*)\n      func_tr_sh_result=`$ECHO \"$1\" | $SED -e 's/^\\([0-9]\\)/_\\1/' -e 's/[^a-zA-Z0-9_]/_/g'`\n      ;;\n    * )\n      func_tr_sh_result=$1\n      ;;\n    esac\n}\n\n\n# func_verbose ARG...\n# -------------------\n# Echo program name prefixed message in verbose mode only.\nfunc_verbose ()\n{\n    $debug_cmd\n\n    $opt_verbose && func_echo \"$*\"\n\n    :\n}\n\n\n# func_warn_and_continue ARG...\n# -----------------------------\n# Echo program name prefixed warning message to standard error.\nfunc_warn_and_continue ()\n{\n    $debug_cmd\n\n    $require_term_colors\n\n    func_echo_infix_1 \"${tc_red}warning$tc_reset\" \"$*\" >&2\n}\n\n\n# func_warning CATEGORY ARG...\n# ----------------------------\n# Echo program name prefixed warning message to standard error. Warning\n# messages can be filtered according to CATEGORY, where this function\n# elides messages where CATEGORY is not listed in the global variable\n# 'opt_warning_types'.\nfunc_warning ()\n{\n    $debug_cmd\n\n    # CATEGORY must be in the warning_categories list!\n    case \" $warning_categories \" in\n      *\" $1 \"*) ;;\n      *) func_internal_error \"invalid warning category '$1'\" ;;\n    esac\n\n    _G_category=$1\n    shift\n\n    case \" $opt_warning_types \" in\n      *\" $_G_category \"*) $warning_func ${1+\"$@\"} ;;\n    esac\n}\n\n\n# func_sort_ver VER1 VER2\n# -----------------------\n# 'sort -V' is not generally available.\n# Note this deviates from the version comparison in automake\n# in that it treats 1.5 < 1.5.0, and treats 1.4.4a < 1.4-p3a\n# but this should suffice as we won't be specifying old\n# version formats or redundant trailing .0 in bootstrap.conf.\n# If we did want full compatibility then we should probably\n# use m4_version_compare from autoconf.\nfunc_sort_ver ()\n{\n    $debug_cmd\n\n    printf '%s\\n%s\\n' \"$1\" \"$2\" \\\n      | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n -k 5,5n -k 6,6n -k 7,7n -k 8,8n -k 9,9n\n}\n\n# func_lt_ver PREV CURR\n# ---------------------\n# Return true if PREV and CURR are in the correct order according to\n# func_sort_ver, otherwise false.  Use it like this:\n#\n#  func_lt_ver \"$prev_ver\" \"$proposed_ver\" || func_fatal_error \"...\"\nfunc_lt_ver ()\n{\n    $debug_cmd\n\n    test \"x$1\" = x`func_sort_ver \"$1\" \"$2\" | $SED 1q`\n}\n\n\n# Local variables:\n# mode: shell-script\n# sh-indentation: 2\n# eval: (add-hook 'before-save-hook 'time-stamp)\n# time-stamp-pattern: \"10/scriptversion=%:y-%02m-%02d.%02H; # UTC\"\n# time-stamp-time-zone: \"UTC\"\n# End:\n#! /bin/sh\n\n# Set a version string for this script.\nscriptversion=2014-01-07.03; # UTC\n\n# A portable, pluggable option parser for Bourne shell.\n# Written by Gary V. Vaughan, 2010\n\n# Copyright (C) 2010-2015 Free Software Foundation, Inc.\n# This is free software; see the source for copying conditions.  There is NO\n# warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n# Please report bugs or propose patches to gary@gnu.org.\n\n\n## ------ ##\n## Usage. ##\n## ------ ##\n\n# This file is a library for parsing options in your shell scripts along\n# with assorted other useful supporting features that you can make use\n# of too.\n#\n# For the simplest scripts you might need only:\n#\n#   #!/bin/sh\n#   . relative/path/to/funclib.sh\n#   . relative/path/to/options-parser\n#   scriptversion=1.0\n#   func_options ${1+\"$@\"}\n#   eval set dummy \"$func_options_result\"; shift\n#   ...rest of your script...\n#\n# In order for the '--version' option to work, you will need to have a\n# suitably formatted comment like the one at the top of this file\n# starting with '# Written by ' and ending with '# warranty; '.\n#\n# For '-h' and '--help' to work, you will also need a one line\n# description of your script's purpose in a comment directly above the\n# '# Written by ' line, like the one at the top of this file.\n#\n# The default options also support '--debug', which will turn on shell\n# execution tracing (see the comment above debug_cmd below for another\n# use), and '--verbose' and the func_verbose function to allow your script\n# to display verbose messages only when your user has specified\n# '--verbose'.\n#\n# After sourcing this file, you can plug processing for additional\n# options by amending the variables from the 'Configuration' section\n# below, and following the instructions in the 'Option parsing'\n# section further down.\n\n## -------------- ##\n## Configuration. ##\n## -------------- ##\n\n# You should override these variables in your script after sourcing this\n# file so that they reflect the customisations you have added to the\n# option parser.\n\n# The usage line for option parsing errors and the start of '-h' and\n# '--help' output messages. You can embed shell variables for delayed\n# expansion at the time the message is displayed, but you will need to\n# quote other shell meta-characters carefully to prevent them being\n# expanded when the contents are evaled.\nusage='$progpath [OPTION]...'\n\n# Short help message in response to '-h' and '--help'.  Add to this or\n# override it after sourcing this library to reflect the full set of\n# options your script accepts.\nusage_message=\"\\\n       --debug        enable verbose shell tracing\n   -W, --warnings=CATEGORY\n                      report the warnings falling in CATEGORY [all]\n   -v, --verbose      verbosely report processing\n       --version      print version information and exit\n   -h, --help         print short or long help message and exit\n\"\n\n# Additional text appended to 'usage_message' in response to '--help'.\nlong_help_message=\"\nWarning categories include:\n       'all'          show all warnings\n       'none'         turn off all the warnings\n       'error'        warnings are treated as fatal errors\"\n\n# Help message printed before fatal option parsing errors.\nfatal_help=\"Try '\\$progname --help' for more information.\"\n\n\n\n## ------------------------- ##\n## Hook function management. ##\n## ------------------------- ##\n\n# This section contains functions for adding, removing, and running hooks\n# to the main code.  A hook is just a named list of of function, that can\n# be run in order later on.\n\n# func_hookable FUNC_NAME\n# -----------------------\n# Declare that FUNC_NAME will run hooks added with\n# 'func_add_hook FUNC_NAME ...'.\nfunc_hookable ()\n{\n    $debug_cmd\n\n    func_append hookable_fns \" $1\"\n}\n\n\n# func_add_hook FUNC_NAME HOOK_FUNC\n# ---------------------------------\n# Request that FUNC_NAME call HOOK_FUNC before it returns.  FUNC_NAME must\n# first have been declared \"hookable\" by a call to 'func_hookable'.\nfunc_add_hook ()\n{\n    $debug_cmd\n\n    case \" $hookable_fns \" in\n      *\" $1 \"*) ;;\n      *) func_fatal_error \"'$1' does not accept hook functions.\" ;;\n    esac\n\n    eval func_append ${1}_hooks '\" $2\"'\n}\n\n\n# func_remove_hook FUNC_NAME HOOK_FUNC\n# ------------------------------------\n# Remove HOOK_FUNC from the list of functions called by FUNC_NAME.\nfunc_remove_hook ()\n{\n    $debug_cmd\n\n    eval ${1}_hooks='`$ECHO \"\\$'$1'_hooks\" |$SED \"s| '$2'||\"`'\n}\n\n\n# func_run_hooks FUNC_NAME [ARG]...\n# ---------------------------------\n# Run all hook functions registered to FUNC_NAME.\n# It is assumed that the list of hook functions contains nothing more\n# than a whitespace-delimited list of legal shell function names, and\n# no effort is wasted trying to catch shell meta-characters or preserve\n# whitespace.\nfunc_run_hooks ()\n{\n    $debug_cmd\n\n    case \" $hookable_fns \" in\n      *\" $1 \"*) ;;\n      *) func_fatal_error \"'$1' does not support hook funcions.n\" ;;\n    esac\n\n    eval _G_hook_fns=\\$$1_hooks; shift\n\n    for _G_hook in $_G_hook_fns; do\n      eval $_G_hook '\"$@\"'\n\n      # store returned options list back into positional\n      # parameters for next 'cmd' execution.\n      eval _G_hook_result=\\$${_G_hook}_result\n      eval set dummy \"$_G_hook_result\"; shift\n    done\n\n    func_quote_for_eval ${1+\"$@\"}\n    func_run_hooks_result=$func_quote_for_eval_result\n}\n\n\n\n## --------------- ##\n## Option parsing. ##\n## --------------- ##\n\n# In order to add your own option parsing hooks, you must accept the\n# full positional parameter list in your hook function, remove any\n# options that you action, and then pass back the remaining unprocessed\n# options in '<hooked_function_name>_result', escaped suitably for\n# 'eval'.  Like this:\n#\n#    my_options_prep ()\n#    {\n#        $debug_cmd\n#\n#        # Extend the existing usage message.\n#        usage_message=$usage_message'\n#      -s, --silent       don'\\''t print informational messages\n#    '\n#\n#        func_quote_for_eval ${1+\"$@\"}\n#        my_options_prep_result=$func_quote_for_eval_result\n#    }\n#    func_add_hook func_options_prep my_options_prep\n#\n#\n#    my_silent_option ()\n#    {\n#        $debug_cmd\n#\n#        # Note that for efficiency, we parse as many options as we can\n#        # recognise in a loop before passing the remainder back to the\n#        # caller on the first unrecognised argument we encounter.\n#        while test $# -gt 0; do\n#          opt=$1; shift\n#          case $opt in\n#            --silent|-s) opt_silent=: ;;\n#            # Separate non-argument short options:\n#            -s*)         func_split_short_opt \"$_G_opt\"\n#                         set dummy \"$func_split_short_opt_name\" \\\n#                             \"-$func_split_short_opt_arg\" ${1+\"$@\"}\n#                         shift\n#                         ;;\n#            *)            set dummy \"$_G_opt\" \"$*\"; shift; break ;;\n#          esac\n#        done\n#\n#        func_quote_for_eval ${1+\"$@\"}\n#        my_silent_option_result=$func_quote_for_eval_result\n#    }\n#    func_add_hook func_parse_options my_silent_option\n#\n#\n#    my_option_validation ()\n#    {\n#        $debug_cmd\n#\n#        $opt_silent && $opt_verbose && func_fatal_help \"\\\n#    '--silent' and '--verbose' options are mutually exclusive.\"\n#\n#        func_quote_for_eval ${1+\"$@\"}\n#        my_option_validation_result=$func_quote_for_eval_result\n#    }\n#    func_add_hook func_validate_options my_option_validation\n#\n# You'll alse need to manually amend $usage_message to reflect the extra\n# options you parse.  It's preferable to append if you can, so that\n# multiple option parsing hooks can be added safely.\n\n\n# func_options [ARG]...\n# ---------------------\n# All the functions called inside func_options are hookable. See the\n# individual implementations for details.\nfunc_hookable func_options\nfunc_options ()\n{\n    $debug_cmd\n\n    func_options_prep ${1+\"$@\"}\n    eval func_parse_options \\\n        ${func_options_prep_result+\"$func_options_prep_result\"}\n    eval func_validate_options \\\n        ${func_parse_options_result+\"$func_parse_options_result\"}\n\n    eval func_run_hooks func_options \\\n        ${func_validate_options_result+\"$func_validate_options_result\"}\n\n    # save modified positional parameters for caller\n    func_options_result=$func_run_hooks_result\n}\n\n\n# func_options_prep [ARG]...\n# --------------------------\n# All initialisations required before starting the option parse loop.\n# Note that when calling hook functions, we pass through the list of\n# positional parameters.  If a hook function modifies that list, and\n# needs to propogate that back to rest of this script, then the complete\n# modified list must be put in 'func_run_hooks_result' before\n# returning.\nfunc_hookable func_options_prep\nfunc_options_prep ()\n{\n    $debug_cmd\n\n    # Option defaults:\n    opt_verbose=false\n    opt_warning_types=\n\n    func_run_hooks func_options_prep ${1+\"$@\"}\n\n    # save modified positional parameters for caller\n    func_options_prep_result=$func_run_hooks_result\n}\n\n\n# func_parse_options [ARG]...\n# ---------------------------\n# The main option parsing loop.\nfunc_hookable func_parse_options\nfunc_parse_options ()\n{\n    $debug_cmd\n\n    func_parse_options_result=\n\n    # this just eases exit handling\n    while test $# -gt 0; do\n      # Defer to hook functions for initial option parsing, so they\n      # get priority in the event of reusing an option name.\n      func_run_hooks func_parse_options ${1+\"$@\"}\n\n      # Adjust func_parse_options positional parameters to match\n      eval set dummy \"$func_run_hooks_result\"; shift\n\n      # Break out of the loop if we already parsed every option.\n      test $# -gt 0 || break\n\n      _G_opt=$1\n      shift\n      case $_G_opt in\n        --debug|-x)   debug_cmd='set -x'\n                      func_echo \"enabling shell trace mode\"\n                      $debug_cmd\n                      ;;\n\n        --no-warnings|--no-warning|--no-warn)\n                      set dummy --warnings none ${1+\"$@\"}\n                      shift\n\t\t      ;;\n\n        --warnings|--warning|-W)\n                      test $# = 0 && func_missing_arg $_G_opt && break\n                      case \" $warning_categories $1\" in\n                        *\" $1 \"*)\n                          # trailing space prevents matching last $1 above\n                          func_append_uniq opt_warning_types \" $1\"\n                          ;;\n                        *all)\n                          opt_warning_types=$warning_categories\n                          ;;\n                        *none)\n                          opt_warning_types=none\n                          warning_func=:\n                          ;;\n                        *error)\n                          opt_warning_types=$warning_categories\n                          warning_func=func_fatal_error\n                          ;;\n                        *)\n                          func_fatal_error \\\n                             \"unsupported warning category: '$1'\"\n                          ;;\n                      esac\n                      shift\n                      ;;\n\n        --verbose|-v) opt_verbose=: ;;\n        --version)    func_version ;;\n        -\\?|-h)       func_usage ;;\n        --help)       func_help ;;\n\n\t# Separate optargs to long options (plugins may need this):\n\t--*=*)        func_split_equals \"$_G_opt\"\n\t              set dummy \"$func_split_equals_lhs\" \\\n                          \"$func_split_equals_rhs\" ${1+\"$@\"}\n                      shift\n                      ;;\n\n       # Separate optargs to short options:\n        -W*)\n                      func_split_short_opt \"$_G_opt\"\n                      set dummy \"$func_split_short_opt_name\" \\\n                          \"$func_split_short_opt_arg\" ${1+\"$@\"}\n                      shift\n                      ;;\n\n        # Separate non-argument short options:\n        -\\?*|-h*|-v*|-x*)\n                      func_split_short_opt \"$_G_opt\"\n                      set dummy \"$func_split_short_opt_name\" \\\n                          \"-$func_split_short_opt_arg\" ${1+\"$@\"}\n                      shift\n                      ;;\n\n        --)           break ;;\n        -*)           func_fatal_help \"unrecognised option: '$_G_opt'\" ;;\n        *)            set dummy \"$_G_opt\" ${1+\"$@\"}; shift; break ;;\n      esac\n    done\n\n    # save modified positional parameters for caller\n    func_quote_for_eval ${1+\"$@\"}\n    func_parse_options_result=$func_quote_for_eval_result\n}\n\n\n# func_validate_options [ARG]...\n# ------------------------------\n# Perform any sanity checks on option settings and/or unconsumed\n# arguments.\nfunc_hookable func_validate_options\nfunc_validate_options ()\n{\n    $debug_cmd\n\n    # Display all warnings if -W was not given.\n    test -n \"$opt_warning_types\" || opt_warning_types=\" $warning_categories\"\n\n    func_run_hooks func_validate_options ${1+\"$@\"}\n\n    # Bail if the options were screwed!\n    $exit_cmd $EXIT_FAILURE\n\n    # save modified positional parameters for caller\n    func_validate_options_result=$func_run_hooks_result\n}\n\n\n\n## ----------------- ##\n## Helper functions. ##\n## ----------------- ##\n\n# This section contains the helper functions used by the rest of the\n# hookable option parser framework in ascii-betical order.\n\n\n# func_fatal_help ARG...\n# ----------------------\n# Echo program name prefixed message to standard error, followed by\n# a help hint, and exit.\nfunc_fatal_help ()\n{\n    $debug_cmd\n\n    eval \\$ECHO \\\"\"Usage: $usage\"\\\"\n    eval \\$ECHO \\\"\"$fatal_help\"\\\"\n    func_error ${1+\"$@\"}\n    exit $EXIT_FAILURE\n}\n\n\n# func_help\n# ---------\n# Echo long help message to standard output and exit.\nfunc_help ()\n{\n    $debug_cmd\n\n    func_usage_message\n    $ECHO \"$long_help_message\"\n    exit 0\n}\n\n\n# func_missing_arg ARGNAME\n# ------------------------\n# Echo program name prefixed message to standard error and set global\n# exit_cmd.\nfunc_missing_arg ()\n{\n    $debug_cmd\n\n    func_error \"Missing argument for '$1'.\"\n    exit_cmd=exit\n}\n\n\n# func_split_equals STRING\n# ------------------------\n# Set func_split_equals_lhs and func_split_equals_rhs shell variables after\n# splitting STRING at the '=' sign.\ntest -z \"$_G_HAVE_XSI_OPS\" \\\n    && (eval 'x=a/b/c;\n      test 5aa/bb/cc = \"${#x}${x%%/*}${x%/*}${x#*/}${x##*/}\"') 2>/dev/null \\\n    && _G_HAVE_XSI_OPS=yes\n\nif test yes = \"$_G_HAVE_XSI_OPS\"\nthen\n  # This is an XSI compatible shell, allowing a faster implementation...\n  eval 'func_split_equals ()\n  {\n      $debug_cmd\n\n      func_split_equals_lhs=${1%%=*}\n      func_split_equals_rhs=${1#*=}\n      test \"x$func_split_equals_lhs\" = \"x$1\" \\\n        && func_split_equals_rhs=\n  }'\nelse\n  # ...otherwise fall back to using expr, which is often a shell builtin.\n  func_split_equals ()\n  {\n      $debug_cmd\n\n      func_split_equals_lhs=`expr \"x$1\" : 'x\\([^=]*\\)'`\n      func_split_equals_rhs=\n      test \"x$func_split_equals_lhs\" = \"x$1\" \\\n        || func_split_equals_rhs=`expr \"x$1\" : 'x[^=]*=\\(.*\\)$'`\n  }\nfi #func_split_equals\n\n\n# func_split_short_opt SHORTOPT\n# -----------------------------\n# Set func_split_short_opt_name and func_split_short_opt_arg shell\n# variables after splitting SHORTOPT after the 2nd character.\nif test yes = \"$_G_HAVE_XSI_OPS\"\nthen\n  # This is an XSI compatible shell, allowing a faster implementation...\n  eval 'func_split_short_opt ()\n  {\n      $debug_cmd\n\n      func_split_short_opt_arg=${1#??}\n      func_split_short_opt_name=${1%\"$func_split_short_opt_arg\"}\n  }'\nelse\n  # ...otherwise fall back to using expr, which is often a shell builtin.\n  func_split_short_opt ()\n  {\n      $debug_cmd\n\n      func_split_short_opt_name=`expr \"x$1\" : 'x-\\(.\\)'`\n      func_split_short_opt_arg=`expr \"x$1\" : 'x-.\\(.*\\)$'`\n  }\nfi #func_split_short_opt\n\n\n# func_usage\n# ----------\n# Echo short help message to standard output and exit.\nfunc_usage ()\n{\n    $debug_cmd\n\n    func_usage_message\n    $ECHO \"Run '$progname --help |${PAGER-more}' for full usage\"\n    exit 0\n}\n\n\n# func_usage_message\n# ------------------\n# Echo short help message to standard output.\nfunc_usage_message ()\n{\n    $debug_cmd\n\n    eval \\$ECHO \\\"\"Usage: $usage\"\\\"\n    echo\n    $SED -n 's|^# ||\n        /^Written by/{\n          x;p;x\n        }\n\th\n\t/^Written by/q' < \"$progpath\"\n    echo\n    eval \\$ECHO \\\"\"$usage_message\"\\\"\n}\n\n\n# func_version\n# ------------\n# Echo version message to standard output and exit.\nfunc_version ()\n{\n    $debug_cmd\n\n    printf '%s\\n' \"$progname $scriptversion\"\n    $SED -n '\n        /(C)/!b go\n        :more\n        /\\./!{\n          N\n          s|\\n# | |\n          b more\n        }\n        :go\n        /^# Written by /,/# warranty; / {\n          s|^# ||\n          s|^# *$||\n          s|\\((C)\\)[ 0-9,-]*[ ,-]\\([1-9][0-9]* \\)|\\1 \\2|\n          p\n        }\n        /^# Written by / {\n          s|^# ||\n          p\n        }\n        /^warranty; /q' < \"$progpath\"\n\n    exit $?\n}\n\n\n# Local variables:\n# mode: shell-script\n# sh-indentation: 2\n# eval: (add-hook 'before-save-hook 'time-stamp)\n# time-stamp-pattern: \"10/scriptversion=%:y-%02m-%02d.%02H; # UTC\"\n# time-stamp-time-zone: \"UTC\"\n# End:\n\n# Set a version string.\nscriptversion='(GNU libtool) 2.4.6'\n\n\n# func_echo ARG...\n# ----------------\n# Libtool also displays the current mode in messages, so override\n# funclib.sh func_echo with this custom definition.\nfunc_echo ()\n{\n    $debug_cmd\n\n    _G_message=$*\n\n    func_echo_IFS=$IFS\n    IFS=$nl\n    for _G_line in $_G_message; do\n      IFS=$func_echo_IFS\n      $ECHO \"$progname${opt_mode+: $opt_mode}: $_G_line\"\n    done\n    IFS=$func_echo_IFS\n}\n\n\n# func_warning ARG...\n# -------------------\n# Libtool warnings are not categorized, so override funclib.sh\n# func_warning with this simpler definition.\nfunc_warning ()\n{\n    $debug_cmd\n\n    $warning_func ${1+\"$@\"}\n}\n\n\n## ---------------- ##\n## Options parsing. ##\n## ---------------- ##\n\n# Hook in the functions to make sure our own options are parsed during\n# the option parsing loop.\n\nusage='$progpath [OPTION]... [MODE-ARG]...'\n\n# Short help message in response to '-h'.\nusage_message=\"Options:\n       --config             show all configuration variables\n       --debug              enable verbose shell tracing\n   -n, --dry-run            display commands without modifying any files\n       --features           display basic configuration information and exit\n       --mode=MODE          use operation mode MODE\n       --no-warnings        equivalent to '-Wnone'\n       --preserve-dup-deps  don't remove duplicate dependency libraries\n       --quiet, --silent    don't print informational messages\n       --tag=TAG            use configuration variables from tag TAG\n   -v, --verbose            print more informational messages than default\n       --version            print version information\n   -W, --warnings=CATEGORY  report the warnings falling in CATEGORY [all]\n   -h, --help, --help-all   print short, long, or detailed help message\n\"\n\n# Additional text appended to 'usage_message' in response to '--help'.\nfunc_help ()\n{\n    $debug_cmd\n\n    func_usage_message\n    $ECHO \"$long_help_message\n\nMODE must be one of the following:\n\n       clean           remove files from the build directory\n       compile         compile a source file into a libtool object\n       execute         automatically set library path, then run a program\n       finish          complete the installation of libtool libraries\n       install         install libraries or executables\n       link            create a library or an executable\n       uninstall       remove libraries from an installed directory\n\nMODE-ARGS vary depending on the MODE.  When passed as first option,\n'--mode=MODE' may be abbreviated as 'MODE' or a unique abbreviation of that.\nTry '$progname --help --mode=MODE' for a more detailed description of MODE.\n\nWhen reporting a bug, please describe a test case to reproduce it and\ninclude the following information:\n\n       host-triplet:   $host\n       shell:          $SHELL\n       compiler:       $LTCC\n       compiler flags: $LTCFLAGS\n       linker:         $LD (gnu? $with_gnu_ld)\n       version:        $progname (GNU libtool) 2.4.6\n       automake:       `($AUTOMAKE --version) 2>/dev/null |$SED 1q`\n       autoconf:       `($AUTOCONF --version) 2>/dev/null |$SED 1q`\n\nReport bugs to <bug-libtool@gnu.org>.\nGNU libtool home page: <http://www.gnu.org/software/libtool/>.\nGeneral help using GNU software: <http://www.gnu.org/gethelp/>.\"\n    exit 0\n}\n\n\n# func_lo2o OBJECT-NAME\n# ---------------------\n# Transform OBJECT-NAME from a '.lo' suffix to the platform specific\n# object suffix.\n\nlo2o=s/\\\\.lo\\$/.$objext/\no2lo=s/\\\\.$objext\\$/.lo/\n\nif test yes = \"$_G_HAVE_XSI_OPS\"; then\n  eval 'func_lo2o ()\n  {\n    case $1 in\n      *.lo) func_lo2o_result=${1%.lo}.$objext ;;\n      *   ) func_lo2o_result=$1               ;;\n    esac\n  }'\n\n  # func_xform LIBOBJ-OR-SOURCE\n  # ---------------------------\n  # Transform LIBOBJ-OR-SOURCE from a '.o' or '.c' (or otherwise)\n  # suffix to a '.lo' libtool-object suffix.\n  eval 'func_xform ()\n  {\n    func_xform_result=${1%.*}.lo\n  }'\nelse\n  # ...otherwise fall back to using sed.\n  func_lo2o ()\n  {\n    func_lo2o_result=`$ECHO \"$1\" | $SED \"$lo2o\"`\n  }\n\n  func_xform ()\n  {\n    func_xform_result=`$ECHO \"$1\" | $SED 's|\\.[^.]*$|.lo|'`\n  }\nfi\n\n\n# func_fatal_configuration ARG...\n# -------------------------------\n# Echo program name prefixed message to standard error, followed by\n# a configuration failure hint, and exit.\nfunc_fatal_configuration ()\n{\n    func__fatal_error ${1+\"$@\"} \\\n      \"See the $PACKAGE documentation for more information.\" \\\n      \"Fatal configuration error.\"\n}\n\n\n# func_config\n# -----------\n# Display the configuration for all the tags in this script.\nfunc_config ()\n{\n    re_begincf='^# ### BEGIN LIBTOOL'\n    re_endcf='^# ### END LIBTOOL'\n\n    # Default configuration.\n    $SED \"1,/$re_begincf CONFIG/d;/$re_endcf CONFIG/,\\$d\" < \"$progpath\"\n\n    # Now print the configurations for the tags.\n    for tagname in $taglist; do\n      $SED -n \"/$re_begincf TAG CONFIG: $tagname\\$/,/$re_endcf TAG CONFIG: $tagname\\$/p\" < \"$progpath\"\n    done\n\n    exit $?\n}\n\n\n# func_features\n# -------------\n# Display the features supported by this script.\nfunc_features ()\n{\n    echo \"host: $host\"\n    if test yes = \"$build_libtool_libs\"; then\n      echo \"enable shared libraries\"\n    else\n      echo \"disable shared libraries\"\n    fi\n    if test yes = \"$build_old_libs\"; then\n      echo \"enable static libraries\"\n    else\n      echo \"disable static libraries\"\n    fi\n\n    exit $?\n}\n\n\n# func_enable_tag TAGNAME\n# -----------------------\n# Verify that TAGNAME is valid, and either flag an error and exit, or\n# enable the TAGNAME tag.  We also add TAGNAME to the global $taglist\n# variable here.\nfunc_enable_tag ()\n{\n    # Global variable:\n    tagname=$1\n\n    re_begincf=\"^# ### BEGIN LIBTOOL TAG CONFIG: $tagname\\$\"\n    re_endcf=\"^# ### END LIBTOOL TAG CONFIG: $tagname\\$\"\n    sed_extractcf=/$re_begincf/,/$re_endcf/p\n\n    # Validate tagname.\n    case $tagname in\n      *[!-_A-Za-z0-9,/]*)\n        func_fatal_error \"invalid tag name: $tagname\"\n        ;;\n    esac\n\n    # Don't test for the \"default\" C tag, as we know it's\n    # there but not specially marked.\n    case $tagname in\n        CC) ;;\n    *)\n        if $GREP \"$re_begincf\" \"$progpath\" >/dev/null 2>&1; then\n\t  taglist=\"$taglist $tagname\"\n\n\t  # Evaluate the configuration.  Be careful to quote the path\n\t  # and the sed script, to avoid splitting on whitespace, but\n\t  # also don't use non-portable quotes within backquotes within\n\t  # quotes we have to do it in 2 steps:\n\t  extractedcf=`$SED -n -e \"$sed_extractcf\" < \"$progpath\"`\n\t  eval \"$extractedcf\"\n        else\n\t  func_error \"ignoring unknown tag $tagname\"\n        fi\n        ;;\n    esac\n}\n\n\n# func_check_version_match\n# ------------------------\n# Ensure that we are using m4 macros, and libtool script from the same\n# release of libtool.\nfunc_check_version_match ()\n{\n    if test \"$package_revision\" != \"$macro_revision\"; then\n      if test \"$VERSION\" != \"$macro_version\"; then\n        if test -z \"$macro_version\"; then\n          cat >&2 <<_LT_EOF\n$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the\n$progname: definition of this LT_INIT comes from an older release.\n$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION\n$progname: and run autoconf again.\n_LT_EOF\n        else\n          cat >&2 <<_LT_EOF\n$progname: Version mismatch error.  This is $PACKAGE $VERSION, but the\n$progname: definition of this LT_INIT comes from $PACKAGE $macro_version.\n$progname: You should recreate aclocal.m4 with macros from $PACKAGE $VERSION\n$progname: and run autoconf again.\n_LT_EOF\n        fi\n      else\n        cat >&2 <<_LT_EOF\n$progname: Version mismatch error.  This is $PACKAGE $VERSION, revision $package_revision,\n$progname: but the definition of this LT_INIT comes from revision $macro_revision.\n$progname: You should recreate aclocal.m4 with macros from revision $package_revision\n$progname: of $PACKAGE $VERSION and run autoconf again.\n_LT_EOF\n      fi\n\n      exit $EXIT_MISMATCH\n    fi\n}\n\n\n# libtool_options_prep [ARG]...\n# -----------------------------\n# Preparation for options parsed by libtool.\nlibtool_options_prep ()\n{\n    $debug_mode\n\n    # Option defaults:\n    opt_config=false\n    opt_dlopen=\n    opt_dry_run=false\n    opt_help=false\n    opt_mode=\n    opt_preserve_dup_deps=false\n    opt_quiet=false\n\n    nonopt=\n    preserve_args=\n\n    # Shorthand for --mode=foo, only valid as the first argument\n    case $1 in\n    clean|clea|cle|cl)\n      shift; set dummy --mode clean ${1+\"$@\"}; shift\n      ;;\n    compile|compil|compi|comp|com|co|c)\n      shift; set dummy --mode compile ${1+\"$@\"}; shift\n      ;;\n    execute|execut|execu|exec|exe|ex|e)\n      shift; set dummy --mode execute ${1+\"$@\"}; shift\n      ;;\n    finish|finis|fini|fin|fi|f)\n      shift; set dummy --mode finish ${1+\"$@\"}; shift\n      ;;\n    install|instal|insta|inst|ins|in|i)\n      shift; set dummy --mode install ${1+\"$@\"}; shift\n      ;;\n    link|lin|li|l)\n      shift; set dummy --mode link ${1+\"$@\"}; shift\n      ;;\n    uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)\n      shift; set dummy --mode uninstall ${1+\"$@\"}; shift\n      ;;\n    esac\n\n    # Pass back the list of options.\n    func_quote_for_eval ${1+\"$@\"}\n    libtool_options_prep_result=$func_quote_for_eval_result\n}\nfunc_add_hook func_options_prep libtool_options_prep\n\n\n# libtool_parse_options [ARG]...\n# ---------------------------------\n# Provide handling for libtool specific options.\nlibtool_parse_options ()\n{\n    $debug_cmd\n\n    # Perform our own loop to consume as many options as possible in\n    # each iteration.\n    while test $# -gt 0; do\n      _G_opt=$1\n      shift\n      case $_G_opt in\n        --dry-run|--dryrun|-n)\n                        opt_dry_run=:\n                        ;;\n\n        --config)       func_config ;;\n\n        --dlopen|-dlopen)\n                        opt_dlopen=\"${opt_dlopen+$opt_dlopen\n}$1\"\n                        shift\n                        ;;\n\n        --preserve-dup-deps)\n                        opt_preserve_dup_deps=: ;;\n\n        --features)     func_features ;;\n\n        --finish)       set dummy --mode finish ${1+\"$@\"}; shift ;;\n\n        --help)         opt_help=: ;;\n\n        --help-all)     opt_help=': help-all' ;;\n\n        --mode)         test $# = 0 && func_missing_arg $_G_opt && break\n                        opt_mode=$1\n                        case $1 in\n                          # Valid mode arguments:\n                          clean|compile|execute|finish|install|link|relink|uninstall) ;;\n\n                          # Catch anything else as an error\n                          *) func_error \"invalid argument for $_G_opt\"\n                             exit_cmd=exit\n                             break\n                             ;;\n                        esac\n                        shift\n                        ;;\n\n        --no-silent|--no-quiet)\n                        opt_quiet=false\n                        func_append preserve_args \" $_G_opt\"\n                        ;;\n\n        --no-warnings|--no-warning|--no-warn)\n                        opt_warning=false\n                        func_append preserve_args \" $_G_opt\"\n                        ;;\n\n        --no-verbose)\n                        opt_verbose=false\n                        func_append preserve_args \" $_G_opt\"\n                        ;;\n\n        --silent|--quiet)\n                        opt_quiet=:\n                        opt_verbose=false\n                        func_append preserve_args \" $_G_opt\"\n                        ;;\n\n        --tag)          test $# = 0 && func_missing_arg $_G_opt && break\n                        opt_tag=$1\n                        func_append preserve_args \" $_G_opt $1\"\n                        func_enable_tag \"$1\"\n                        shift\n                        ;;\n\n        --verbose|-v)   opt_quiet=false\n                        opt_verbose=:\n                        func_append preserve_args \" $_G_opt\"\n                        ;;\n\n\t# An option not handled by this hook function:\n        *)\t\tset dummy \"$_G_opt\" ${1+\"$@\"};\tshift; break  ;;\n      esac\n    done\n\n\n    # save modified positional parameters for caller\n    func_quote_for_eval ${1+\"$@\"}\n    libtool_parse_options_result=$func_quote_for_eval_result\n}\nfunc_add_hook func_parse_options libtool_parse_options\n\n\n\n# libtool_validate_options [ARG]...\n# ---------------------------------\n# Perform any sanity checks on option settings and/or unconsumed\n# arguments.\nlibtool_validate_options ()\n{\n    # save first non-option argument\n    if test 0 -lt $#; then\n      nonopt=$1\n      shift\n    fi\n\n    # preserve --debug\n    test : = \"$debug_cmd\" || func_append preserve_args \" --debug\"\n\n    case $host in\n      # Solaris2 added to fix http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16452\n      # see also: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59788\n      *cygwin* | *mingw* | *pw32* | *cegcc* | *solaris2* | *os2*)\n        # don't eliminate duplications in $postdeps and $predeps\n        opt_duplicate_compiler_generated_deps=:\n        ;;\n      *)\n        opt_duplicate_compiler_generated_deps=$opt_preserve_dup_deps\n        ;;\n    esac\n\n    $opt_help || {\n      # Sanity checks first:\n      func_check_version_match\n\n      test yes != \"$build_libtool_libs\" \\\n        && test yes != \"$build_old_libs\" \\\n        && func_fatal_configuration \"not configured to build any kind of library\"\n\n      # Darwin sucks\n      eval std_shrext=\\\"$shrext_cmds\\\"\n\n      # Only execute mode is allowed to have -dlopen flags.\n      if test -n \"$opt_dlopen\" && test execute != \"$opt_mode\"; then\n        func_error \"unrecognized option '-dlopen'\"\n        $ECHO \"$help\" 1>&2\n        exit $EXIT_FAILURE\n      fi\n\n      # Change the help message to a mode-specific one.\n      generic_help=$help\n      help=\"Try '$progname --help --mode=$opt_mode' for more information.\"\n    }\n\n    # Pass back the unparsed argument list\n    func_quote_for_eval ${1+\"$@\"}\n    libtool_validate_options_result=$func_quote_for_eval_result\n}\nfunc_add_hook func_validate_options libtool_validate_options\n\n\n# Process options as early as possible so that --help and --version\n# can return quickly.\nfunc_options ${1+\"$@\"}\neval set dummy \"$func_options_result\"; shift\n\n\n\n## ----------- ##\n##    Main.    ##\n## ----------- ##\n\nmagic='%%%MAGIC variable%%%'\nmagic_exe='%%%MAGIC EXE variable%%%'\n\n# Global variables.\nextracted_archives=\nextracted_serial=0\n\n# If this variable is set in any of the actions, the command in it\n# will be execed at the end.  This prevents here-documents from being\n# left over by shells.\nexec_cmd=\n\n\n# A function that is used when there is no print builtin or printf.\nfunc_fallback_echo ()\n{\n  eval 'cat <<_LTECHO_EOF\n$1\n_LTECHO_EOF'\n}\n\n# func_generated_by_libtool\n# True iff stdin has been generated by Libtool. This function is only\n# a basic sanity check; it will hardly flush out determined imposters.\nfunc_generated_by_libtool_p ()\n{\n  $GREP \"^# Generated by .*$PACKAGE\" > /dev/null 2>&1\n}\n\n# func_lalib_p file\n# True iff FILE is a libtool '.la' library or '.lo' object file.\n# This function is only a basic sanity check; it will hardly flush out\n# determined imposters.\nfunc_lalib_p ()\n{\n    test -f \"$1\" &&\n      $SED -e 4q \"$1\" 2>/dev/null | func_generated_by_libtool_p\n}\n\n# func_lalib_unsafe_p file\n# True iff FILE is a libtool '.la' library or '.lo' object file.\n# This function implements the same check as func_lalib_p without\n# resorting to external programs.  To this end, it redirects stdin and\n# closes it afterwards, without saving the original file descriptor.\n# As a safety measure, use it only where a negative result would be\n# fatal anyway.  Works if 'file' does not exist.\nfunc_lalib_unsafe_p ()\n{\n    lalib_p=no\n    if test -f \"$1\" && test -r \"$1\" && exec 5<&0 <\"$1\"; then\n\tfor lalib_p_l in 1 2 3 4\n\tdo\n\t    read lalib_p_line\n\t    case $lalib_p_line in\n\t\t\\#\\ Generated\\ by\\ *$PACKAGE* ) lalib_p=yes; break;;\n\t    esac\n\tdone\n\texec 0<&5 5<&-\n    fi\n    test yes = \"$lalib_p\"\n}\n\n# func_ltwrapper_script_p file\n# True iff FILE is a libtool wrapper script\n# This function is only a basic sanity check; it will hardly flush out\n# determined imposters.\nfunc_ltwrapper_script_p ()\n{\n    test -f \"$1\" &&\n      $lt_truncate_bin < \"$1\" 2>/dev/null | func_generated_by_libtool_p\n}\n\n# func_ltwrapper_executable_p file\n# True iff FILE is a libtool wrapper executable\n# This function is only a basic sanity check; it will hardly flush out\n# determined imposters.\nfunc_ltwrapper_executable_p ()\n{\n    func_ltwrapper_exec_suffix=\n    case $1 in\n    *.exe) ;;\n    *) func_ltwrapper_exec_suffix=.exe ;;\n    esac\n    $GREP \"$magic_exe\" \"$1$func_ltwrapper_exec_suffix\" >/dev/null 2>&1\n}\n\n# func_ltwrapper_scriptname file\n# Assumes file is an ltwrapper_executable\n# uses $file to determine the appropriate filename for a\n# temporary ltwrapper_script.\nfunc_ltwrapper_scriptname ()\n{\n    func_dirname_and_basename \"$1\" \"\" \".\"\n    func_stripname '' '.exe' \"$func_basename_result\"\n    func_ltwrapper_scriptname_result=$func_dirname_result/$objdir/${func_stripname_result}_ltshwrapper\n}\n\n# func_ltwrapper_p file\n# True iff FILE is a libtool wrapper script or wrapper executable\n# This function is only a basic sanity check; it will hardly flush out\n# determined imposters.\nfunc_ltwrapper_p ()\n{\n    func_ltwrapper_script_p \"$1\" || func_ltwrapper_executable_p \"$1\"\n}\n\n\n# func_execute_cmds commands fail_cmd\n# Execute tilde-delimited COMMANDS.\n# If FAIL_CMD is given, eval that upon failure.\n# FAIL_CMD may read-access the current command in variable CMD!\nfunc_execute_cmds ()\n{\n    $debug_cmd\n\n    save_ifs=$IFS; IFS='~'\n    for cmd in $1; do\n      IFS=$sp$nl\n      eval cmd=\\\"$cmd\\\"\n      IFS=$save_ifs\n      func_show_eval \"$cmd\" \"${2-:}\"\n    done\n    IFS=$save_ifs\n}\n\n\n# func_source file\n# Source FILE, adding directory component if necessary.\n# Note that it is not necessary on cygwin/mingw to append a dot to\n# FILE even if both FILE and FILE.exe exist: automatic-append-.exe\n# behavior happens only for exec(3), not for open(2)!  Also, sourcing\n# 'FILE.' does not work on cygwin managed mounts.\nfunc_source ()\n{\n    $debug_cmd\n\n    case $1 in\n    */* | *\\\\*)\t. \"$1\" ;;\n    *)\t\t. \"./$1\" ;;\n    esac\n}\n\n\n# func_resolve_sysroot PATH\n# Replace a leading = in PATH with a sysroot.  Store the result into\n# func_resolve_sysroot_result\nfunc_resolve_sysroot ()\n{\n  func_resolve_sysroot_result=$1\n  case $func_resolve_sysroot_result in\n  =*)\n    func_stripname '=' '' \"$func_resolve_sysroot_result\"\n    func_resolve_sysroot_result=$lt_sysroot$func_stripname_result\n    ;;\n  esac\n}\n\n# func_replace_sysroot PATH\n# If PATH begins with the sysroot, replace it with = and\n# store the result into func_replace_sysroot_result.\nfunc_replace_sysroot ()\n{\n  case $lt_sysroot:$1 in\n  ?*:\"$lt_sysroot\"*)\n    func_stripname \"$lt_sysroot\" '' \"$1\"\n    func_replace_sysroot_result='='$func_stripname_result\n    ;;\n  *)\n    # Including no sysroot.\n    func_replace_sysroot_result=$1\n    ;;\n  esac\n}\n\n# func_infer_tag arg\n# Infer tagged configuration to use if any are available and\n# if one wasn't chosen via the \"--tag\" command line option.\n# Only attempt this if the compiler in the base compile\n# command doesn't match the default compiler.\n# arg is usually of the form 'gcc ...'\nfunc_infer_tag ()\n{\n    $debug_cmd\n\n    if test -n \"$available_tags\" && test -z \"$tagname\"; then\n      CC_quoted=\n      for arg in $CC; do\n\tfunc_append_quoted CC_quoted \"$arg\"\n      done\n      CC_expanded=`func_echo_all $CC`\n      CC_quoted_expanded=`func_echo_all $CC_quoted`\n      case $@ in\n      # Blanks in the command may have been stripped by the calling shell,\n      # but not from the CC environment variable when configure was run.\n      \" $CC \"* | \"$CC \"* | \" $CC_expanded \"* | \"$CC_expanded \"* | \\\n      \" $CC_quoted\"* | \"$CC_quoted \"* | \" $CC_quoted_expanded \"* | \"$CC_quoted_expanded \"*) ;;\n      # Blanks at the start of $base_compile will cause this to fail\n      # if we don't check for them as well.\n      *)\n\tfor z in $available_tags; do\n\t  if $GREP \"^# ### BEGIN LIBTOOL TAG CONFIG: $z$\" < \"$progpath\" > /dev/null; then\n\t    # Evaluate the configuration.\n\t    eval \"`$SED -n -e '/^# ### BEGIN LIBTOOL TAG CONFIG: '$z'$/,/^# ### END LIBTOOL TAG CONFIG: '$z'$/p' < $progpath`\"\n\t    CC_quoted=\n\t    for arg in $CC; do\n\t      # Double-quote args containing other shell metacharacters.\n\t      func_append_quoted CC_quoted \"$arg\"\n\t    done\n\t    CC_expanded=`func_echo_all $CC`\n\t    CC_quoted_expanded=`func_echo_all $CC_quoted`\n\t    case \"$@ \" in\n\t    \" $CC \"* | \"$CC \"* | \" $CC_expanded \"* | \"$CC_expanded \"* | \\\n\t    \" $CC_quoted\"* | \"$CC_quoted \"* | \" $CC_quoted_expanded \"* | \"$CC_quoted_expanded \"*)\n\t      # The compiler in the base compile command matches\n\t      # the one in the tagged configuration.\n\t      # Assume this is the tagged configuration we want.\n\t      tagname=$z\n\t      break\n\t      ;;\n\t    esac\n\t  fi\n\tdone\n\t# If $tagname still isn't set, then no tagged configuration\n\t# was found and let the user know that the \"--tag\" command\n\t# line option must be used.\n\tif test -z \"$tagname\"; then\n\t  func_echo \"unable to infer tagged configuration\"\n\t  func_fatal_error \"specify a tag with '--tag'\"\n#\telse\n#\t  func_verbose \"using $tagname tagged configuration\"\n\tfi\n\t;;\n      esac\n    fi\n}\n\n\n\n# func_write_libtool_object output_name pic_name nonpic_name\n# Create a libtool object file (analogous to a \".la\" file),\n# but don't create it if we're doing a dry run.\nfunc_write_libtool_object ()\n{\n    write_libobj=$1\n    if test yes = \"$build_libtool_libs\"; then\n      write_lobj=\\'$2\\'\n    else\n      write_lobj=none\n    fi\n\n    if test yes = \"$build_old_libs\"; then\n      write_oldobj=\\'$3\\'\n    else\n      write_oldobj=none\n    fi\n\n    $opt_dry_run || {\n      cat >${write_libobj}T <<EOF\n# $write_libobj - a libtool object file\n# Generated by $PROGRAM (GNU $PACKAGE) $VERSION\n#\n# Please DO NOT delete this file!\n# It is necessary for linking the library.\n\n# Name of the PIC object.\npic_object=$write_lobj\n\n# Name of the non-PIC object\nnon_pic_object=$write_oldobj\n\nEOF\n      $MV \"${write_libobj}T\" \"$write_libobj\"\n    }\n}\n\n\n##################################################\n# FILE NAME AND PATH CONVERSION HELPER FUNCTIONS #\n##################################################\n\n# func_convert_core_file_wine_to_w32 ARG\n# Helper function used by file name conversion functions when $build is *nix,\n# and $host is mingw, cygwin, or some other w32 environment. Relies on a\n# correctly configured wine environment available, with the winepath program\n# in $build's $PATH.\n#\n# ARG is the $build file name to be converted to w32 format.\n# Result is available in $func_convert_core_file_wine_to_w32_result, and will\n# be empty on error (or when ARG is empty)\nfunc_convert_core_file_wine_to_w32 ()\n{\n  $debug_cmd\n\n  func_convert_core_file_wine_to_w32_result=$1\n  if test -n \"$1\"; then\n    # Unfortunately, winepath does not exit with a non-zero error code, so we\n    # are forced to check the contents of stdout. On the other hand, if the\n    # command is not found, the shell will set an exit code of 127 and print\n    # *an error message* to stdout. So we must check for both error code of\n    # zero AND non-empty stdout, which explains the odd construction:\n    func_convert_core_file_wine_to_w32_tmp=`winepath -w \"$1\" 2>/dev/null`\n    if test \"$?\" -eq 0 && test -n \"$func_convert_core_file_wine_to_w32_tmp\"; then\n      func_convert_core_file_wine_to_w32_result=`$ECHO \"$func_convert_core_file_wine_to_w32_tmp\" |\n        $SED -e \"$sed_naive_backslashify\"`\n    else\n      func_convert_core_file_wine_to_w32_result=\n    fi\n  fi\n}\n# end: func_convert_core_file_wine_to_w32\n\n\n# func_convert_core_path_wine_to_w32 ARG\n# Helper function used by path conversion functions when $build is *nix, and\n# $host is mingw, cygwin, or some other w32 environment. Relies on a correctly\n# configured wine environment available, with the winepath program in $build's\n# $PATH. Assumes ARG has no leading or trailing path separator characters.\n#\n# ARG is path to be converted from $build format to win32.\n# Result is available in $func_convert_core_path_wine_to_w32_result.\n# Unconvertible file (directory) names in ARG are skipped; if no directory names\n# are convertible, then the result may be empty.\nfunc_convert_core_path_wine_to_w32 ()\n{\n  $debug_cmd\n\n  # unfortunately, winepath doesn't convert paths, only file names\n  func_convert_core_path_wine_to_w32_result=\n  if test -n \"$1\"; then\n    oldIFS=$IFS\n    IFS=:\n    for func_convert_core_path_wine_to_w32_f in $1; do\n      IFS=$oldIFS\n      func_convert_core_file_wine_to_w32 \"$func_convert_core_path_wine_to_w32_f\"\n      if test -n \"$func_convert_core_file_wine_to_w32_result\"; then\n        if test -z \"$func_convert_core_path_wine_to_w32_result\"; then\n          func_convert_core_path_wine_to_w32_result=$func_convert_core_file_wine_to_w32_result\n        else\n          func_append func_convert_core_path_wine_to_w32_result \";$func_convert_core_file_wine_to_w32_result\"\n        fi\n      fi\n    done\n    IFS=$oldIFS\n  fi\n}\n# end: func_convert_core_path_wine_to_w32\n\n\n# func_cygpath ARGS...\n# Wrapper around calling the cygpath program via LT_CYGPATH. This is used when\n# when (1) $build is *nix and Cygwin is hosted via a wine environment; or (2)\n# $build is MSYS and $host is Cygwin, or (3) $build is Cygwin. In case (1) or\n# (2), returns the Cygwin file name or path in func_cygpath_result (input\n# file name or path is assumed to be in w32 format, as previously converted\n# from $build's *nix or MSYS format). In case (3), returns the w32 file name\n# or path in func_cygpath_result (input file name or path is assumed to be in\n# Cygwin format). Returns an empty string on error.\n#\n# ARGS are passed to cygpath, with the last one being the file name or path to\n# be converted.\n#\n# Specify the absolute *nix (or w32) name to cygpath in the LT_CYGPATH\n# environment variable; do not put it in $PATH.\nfunc_cygpath ()\n{\n  $debug_cmd\n\n  if test -n \"$LT_CYGPATH\" && test -f \"$LT_CYGPATH\"; then\n    func_cygpath_result=`$LT_CYGPATH \"$@\" 2>/dev/null`\n    if test \"$?\" -ne 0; then\n      # on failure, ensure result is empty\n      func_cygpath_result=\n    fi\n  else\n    func_cygpath_result=\n    func_error \"LT_CYGPATH is empty or specifies non-existent file: '$LT_CYGPATH'\"\n  fi\n}\n#end: func_cygpath\n\n\n# func_convert_core_msys_to_w32 ARG\n# Convert file name or path ARG from MSYS format to w32 format.  Return\n# result in func_convert_core_msys_to_w32_result.\nfunc_convert_core_msys_to_w32 ()\n{\n  $debug_cmd\n\n  # awkward: cmd appends spaces to result\n  func_convert_core_msys_to_w32_result=`( cmd //c echo \"$1\" ) 2>/dev/null |\n    $SED -e 's/[ ]*$//' -e \"$sed_naive_backslashify\"`\n}\n#end: func_convert_core_msys_to_w32\n\n\n# func_convert_file_check ARG1 ARG2\n# Verify that ARG1 (a file name in $build format) was converted to $host\n# format in ARG2. Otherwise, emit an error message, but continue (resetting\n# func_to_host_file_result to ARG1).\nfunc_convert_file_check ()\n{\n  $debug_cmd\n\n  if test -z \"$2\" && test -n \"$1\"; then\n    func_error \"Could not determine host file name corresponding to\"\n    func_error \"  '$1'\"\n    func_error \"Continuing, but uninstalled executables may not work.\"\n    # Fallback:\n    func_to_host_file_result=$1\n  fi\n}\n# end func_convert_file_check\n\n\n# func_convert_path_check FROM_PATHSEP TO_PATHSEP FROM_PATH TO_PATH\n# Verify that FROM_PATH (a path in $build format) was converted to $host\n# format in TO_PATH. Otherwise, emit an error message, but continue, resetting\n# func_to_host_file_result to a simplistic fallback value (see below).\nfunc_convert_path_check ()\n{\n  $debug_cmd\n\n  if test -z \"$4\" && test -n \"$3\"; then\n    func_error \"Could not determine the host path corresponding to\"\n    func_error \"  '$3'\"\n    func_error \"Continuing, but uninstalled executables may not work.\"\n    # Fallback.  This is a deliberately simplistic \"conversion\" and\n    # should not be \"improved\".  See libtool.info.\n    if test \"x$1\" != \"x$2\"; then\n      lt_replace_pathsep_chars=\"s|$1|$2|g\"\n      func_to_host_path_result=`echo \"$3\" |\n        $SED -e \"$lt_replace_pathsep_chars\"`\n    else\n      func_to_host_path_result=$3\n    fi\n  fi\n}\n# end func_convert_path_check\n\n\n# func_convert_path_front_back_pathsep FRONTPAT BACKPAT REPL ORIG\n# Modifies func_to_host_path_result by prepending REPL if ORIG matches FRONTPAT\n# and appending REPL if ORIG matches BACKPAT.\nfunc_convert_path_front_back_pathsep ()\n{\n  $debug_cmd\n\n  case $4 in\n  $1 ) func_to_host_path_result=$3$func_to_host_path_result\n    ;;\n  esac\n  case $4 in\n  $2 ) func_append func_to_host_path_result \"$3\"\n    ;;\n  esac\n}\n# end func_convert_path_front_back_pathsep\n\n\n##################################################\n# $build to $host FILE NAME CONVERSION FUNCTIONS #\n##################################################\n# invoked via '$to_host_file_cmd ARG'\n#\n# In each case, ARG is the path to be converted from $build to $host format.\n# Result will be available in $func_to_host_file_result.\n\n\n# func_to_host_file ARG\n# Converts the file name ARG from $build format to $host format. Return result\n# in func_to_host_file_result.\nfunc_to_host_file ()\n{\n  $debug_cmd\n\n  $to_host_file_cmd \"$1\"\n}\n# end func_to_host_file\n\n\n# func_to_tool_file ARG LAZY\n# converts the file name ARG from $build format to toolchain format. Return\n# result in func_to_tool_file_result.  If the conversion in use is listed\n# in (the comma separated) LAZY, no conversion takes place.\nfunc_to_tool_file ()\n{\n  $debug_cmd\n\n  case ,$2, in\n    *,\"$to_tool_file_cmd\",*)\n      func_to_tool_file_result=$1\n      ;;\n    *)\n      $to_tool_file_cmd \"$1\"\n      func_to_tool_file_result=$func_to_host_file_result\n      ;;\n  esac\n}\n# end func_to_tool_file\n\n\n# func_convert_file_noop ARG\n# Copy ARG to func_to_host_file_result.\nfunc_convert_file_noop ()\n{\n  func_to_host_file_result=$1\n}\n# end func_convert_file_noop\n\n\n# func_convert_file_msys_to_w32 ARG\n# Convert file name ARG from (mingw) MSYS to (mingw) w32 format; automatic\n# conversion to w32 is not available inside the cwrapper.  Returns result in\n# func_to_host_file_result.\nfunc_convert_file_msys_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_file_result=$1\n  if test -n \"$1\"; then\n    func_convert_core_msys_to_w32 \"$1\"\n    func_to_host_file_result=$func_convert_core_msys_to_w32_result\n  fi\n  func_convert_file_check \"$1\" \"$func_to_host_file_result\"\n}\n# end func_convert_file_msys_to_w32\n\n\n# func_convert_file_cygwin_to_w32 ARG\n# Convert file name ARG from Cygwin to w32 format.  Returns result in\n# func_to_host_file_result.\nfunc_convert_file_cygwin_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_file_result=$1\n  if test -n \"$1\"; then\n    # because $build is cygwin, we call \"the\" cygpath in $PATH; no need to use\n    # LT_CYGPATH in this case.\n    func_to_host_file_result=`cygpath -m \"$1\"`\n  fi\n  func_convert_file_check \"$1\" \"$func_to_host_file_result\"\n}\n# end func_convert_file_cygwin_to_w32\n\n\n# func_convert_file_nix_to_w32 ARG\n# Convert file name ARG from *nix to w32 format.  Requires a wine environment\n# and a working winepath. Returns result in func_to_host_file_result.\nfunc_convert_file_nix_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_file_result=$1\n  if test -n \"$1\"; then\n    func_convert_core_file_wine_to_w32 \"$1\"\n    func_to_host_file_result=$func_convert_core_file_wine_to_w32_result\n  fi\n  func_convert_file_check \"$1\" \"$func_to_host_file_result\"\n}\n# end func_convert_file_nix_to_w32\n\n\n# func_convert_file_msys_to_cygwin ARG\n# Convert file name ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.\n# Returns result in func_to_host_file_result.\nfunc_convert_file_msys_to_cygwin ()\n{\n  $debug_cmd\n\n  func_to_host_file_result=$1\n  if test -n \"$1\"; then\n    func_convert_core_msys_to_w32 \"$1\"\n    func_cygpath -u \"$func_convert_core_msys_to_w32_result\"\n    func_to_host_file_result=$func_cygpath_result\n  fi\n  func_convert_file_check \"$1\" \"$func_to_host_file_result\"\n}\n# end func_convert_file_msys_to_cygwin\n\n\n# func_convert_file_nix_to_cygwin ARG\n# Convert file name ARG from *nix to Cygwin format.  Requires Cygwin installed\n# in a wine environment, working winepath, and LT_CYGPATH set.  Returns result\n# in func_to_host_file_result.\nfunc_convert_file_nix_to_cygwin ()\n{\n  $debug_cmd\n\n  func_to_host_file_result=$1\n  if test -n \"$1\"; then\n    # convert from *nix to w32, then use cygpath to convert from w32 to cygwin.\n    func_convert_core_file_wine_to_w32 \"$1\"\n    func_cygpath -u \"$func_convert_core_file_wine_to_w32_result\"\n    func_to_host_file_result=$func_cygpath_result\n  fi\n  func_convert_file_check \"$1\" \"$func_to_host_file_result\"\n}\n# end func_convert_file_nix_to_cygwin\n\n\n#############################################\n# $build to $host PATH CONVERSION FUNCTIONS #\n#############################################\n# invoked via '$to_host_path_cmd ARG'\n#\n# In each case, ARG is the path to be converted from $build to $host format.\n# The result will be available in $func_to_host_path_result.\n#\n# Path separators are also converted from $build format to $host format.  If\n# ARG begins or ends with a path separator character, it is preserved (but\n# converted to $host format) on output.\n#\n# All path conversion functions are named using the following convention:\n#   file name conversion function    : func_convert_file_X_to_Y ()\n#   path conversion function         : func_convert_path_X_to_Y ()\n# where, for any given $build/$host combination the 'X_to_Y' value is the\n# same.  If conversion functions are added for new $build/$host combinations,\n# the two new functions must follow this pattern, or func_init_to_host_path_cmd\n# will break.\n\n\n# func_init_to_host_path_cmd\n# Ensures that function \"pointer\" variable $to_host_path_cmd is set to the\n# appropriate value, based on the value of $to_host_file_cmd.\nto_host_path_cmd=\nfunc_init_to_host_path_cmd ()\n{\n  $debug_cmd\n\n  if test -z \"$to_host_path_cmd\"; then\n    func_stripname 'func_convert_file_' '' \"$to_host_file_cmd\"\n    to_host_path_cmd=func_convert_path_$func_stripname_result\n  fi\n}\n\n\n# func_to_host_path ARG\n# Converts the path ARG from $build format to $host format. Return result\n# in func_to_host_path_result.\nfunc_to_host_path ()\n{\n  $debug_cmd\n\n  func_init_to_host_path_cmd\n  $to_host_path_cmd \"$1\"\n}\n# end func_to_host_path\n\n\n# func_convert_path_noop ARG\n# Copy ARG to func_to_host_path_result.\nfunc_convert_path_noop ()\n{\n  func_to_host_path_result=$1\n}\n# end func_convert_path_noop\n\n\n# func_convert_path_msys_to_w32 ARG\n# Convert path ARG from (mingw) MSYS to (mingw) w32 format; automatic\n# conversion to w32 is not available inside the cwrapper.  Returns result in\n# func_to_host_path_result.\nfunc_convert_path_msys_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_path_result=$1\n  if test -n \"$1\"; then\n    # Remove leading and trailing path separator characters from ARG.  MSYS\n    # behavior is inconsistent here; cygpath turns them into '.;' and ';.';\n    # and winepath ignores them completely.\n    func_stripname : : \"$1\"\n    func_to_host_path_tmp1=$func_stripname_result\n    func_convert_core_msys_to_w32 \"$func_to_host_path_tmp1\"\n    func_to_host_path_result=$func_convert_core_msys_to_w32_result\n    func_convert_path_check : \";\" \\\n      \"$func_to_host_path_tmp1\" \"$func_to_host_path_result\"\n    func_convert_path_front_back_pathsep \":*\" \"*:\" \";\" \"$1\"\n  fi\n}\n# end func_convert_path_msys_to_w32\n\n\n# func_convert_path_cygwin_to_w32 ARG\n# Convert path ARG from Cygwin to w32 format.  Returns result in\n# func_to_host_file_result.\nfunc_convert_path_cygwin_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_path_result=$1\n  if test -n \"$1\"; then\n    # See func_convert_path_msys_to_w32:\n    func_stripname : : \"$1\"\n    func_to_host_path_tmp1=$func_stripname_result\n    func_to_host_path_result=`cygpath -m -p \"$func_to_host_path_tmp1\"`\n    func_convert_path_check : \";\" \\\n      \"$func_to_host_path_tmp1\" \"$func_to_host_path_result\"\n    func_convert_path_front_back_pathsep \":*\" \"*:\" \";\" \"$1\"\n  fi\n}\n# end func_convert_path_cygwin_to_w32\n\n\n# func_convert_path_nix_to_w32 ARG\n# Convert path ARG from *nix to w32 format.  Requires a wine environment and\n# a working winepath.  Returns result in func_to_host_file_result.\nfunc_convert_path_nix_to_w32 ()\n{\n  $debug_cmd\n\n  func_to_host_path_result=$1\n  if test -n \"$1\"; then\n    # See func_convert_path_msys_to_w32:\n    func_stripname : : \"$1\"\n    func_to_host_path_tmp1=$func_stripname_result\n    func_convert_core_path_wine_to_w32 \"$func_to_host_path_tmp1\"\n    func_to_host_path_result=$func_convert_core_path_wine_to_w32_result\n    func_convert_path_check : \";\" \\\n      \"$func_to_host_path_tmp1\" \"$func_to_host_path_result\"\n    func_convert_path_front_back_pathsep \":*\" \"*:\" \";\" \"$1\"\n  fi\n}\n# end func_convert_path_nix_to_w32\n\n\n# func_convert_path_msys_to_cygwin ARG\n# Convert path ARG from MSYS to Cygwin format.  Requires LT_CYGPATH set.\n# Returns result in func_to_host_file_result.\nfunc_convert_path_msys_to_cygwin ()\n{\n  $debug_cmd\n\n  func_to_host_path_result=$1\n  if test -n \"$1\"; then\n    # See func_convert_path_msys_to_w32:\n    func_stripname : : \"$1\"\n    func_to_host_path_tmp1=$func_stripname_result\n    func_convert_core_msys_to_w32 \"$func_to_host_path_tmp1\"\n    func_cygpath -u -p \"$func_convert_core_msys_to_w32_result\"\n    func_to_host_path_result=$func_cygpath_result\n    func_convert_path_check : : \\\n      \"$func_to_host_path_tmp1\" \"$func_to_host_path_result\"\n    func_convert_path_front_back_pathsep \":*\" \"*:\" : \"$1\"\n  fi\n}\n# end func_convert_path_msys_to_cygwin\n\n\n# func_convert_path_nix_to_cygwin ARG\n# Convert path ARG from *nix to Cygwin format.  Requires Cygwin installed in a\n# a wine environment, working winepath, and LT_CYGPATH set.  Returns result in\n# func_to_host_file_result.\nfunc_convert_path_nix_to_cygwin ()\n{\n  $debug_cmd\n\n  func_to_host_path_result=$1\n  if test -n \"$1\"; then\n    # Remove leading and trailing path separator characters from\n    # ARG. msys behavior is inconsistent here, cygpath turns them\n    # into '.;' and ';.', and winepath ignores them completely.\n    func_stripname : : \"$1\"\n    func_to_host_path_tmp1=$func_stripname_result\n    func_convert_core_path_wine_to_w32 \"$func_to_host_path_tmp1\"\n    func_cygpath -u -p \"$func_convert_core_path_wine_to_w32_result\"\n    func_to_host_path_result=$func_cygpath_result\n    func_convert_path_check : : \\\n      \"$func_to_host_path_tmp1\" \"$func_to_host_path_result\"\n    func_convert_path_front_back_pathsep \":*\" \"*:\" : \"$1\"\n  fi\n}\n# end func_convert_path_nix_to_cygwin\n\n\n# func_dll_def_p FILE\n# True iff FILE is a Windows DLL '.def' file.\n# Keep in sync with _LT_DLL_DEF_P in libtool.m4\nfunc_dll_def_p ()\n{\n  $debug_cmd\n\n  func_dll_def_p_tmp=`$SED -n \\\n    -e 's/^[\t ]*//' \\\n    -e '/^\\(;.*\\)*$/d' \\\n    -e 's/^\\(EXPORTS\\|LIBRARY\\)\\([\t ].*\\)*$/DEF/p' \\\n    -e q \\\n    \"$1\"`\n  test DEF = \"$func_dll_def_p_tmp\"\n}\n\n\n# func_mode_compile arg...\nfunc_mode_compile ()\n{\n    $debug_cmd\n\n    # Get the compilation command and the source file.\n    base_compile=\n    srcfile=$nonopt  #  always keep a non-empty value in \"srcfile\"\n    suppress_opt=yes\n    suppress_output=\n    arg_mode=normal\n    libobj=\n    later=\n    pie_flag=\n\n    for arg\n    do\n      case $arg_mode in\n      arg  )\n\t# do not \"continue\".  Instead, add this to base_compile\n\tlastarg=$arg\n\targ_mode=normal\n\t;;\n\n      target )\n\tlibobj=$arg\n\targ_mode=normal\n\tcontinue\n\t;;\n\n      normal )\n\t# Accept any command-line options.\n\tcase $arg in\n\t-o)\n\t  test -n \"$libobj\" && \\\n\t    func_fatal_error \"you cannot specify '-o' more than once\"\n\t  arg_mode=target\n\t  continue\n\t  ;;\n\n\t-pie | -fpie | -fPIE)\n          func_append pie_flag \" $arg\"\n\t  continue\n\t  ;;\n\n\t-shared | -static | -prefer-pic | -prefer-non-pic)\n\t  func_append later \" $arg\"\n\t  continue\n\t  ;;\n\n\t-no-suppress)\n\t  suppress_opt=no\n\t  continue\n\t  ;;\n\n\t-Xcompiler)\n\t  arg_mode=arg  #  the next one goes into the \"base_compile\" arg list\n\t  continue      #  The current \"srcfile\" will either be retained or\n\t  ;;            #  replaced later.  I would guess that would be a bug.\n\n\t-Wc,*)\n\t  func_stripname '-Wc,' '' \"$arg\"\n\t  args=$func_stripname_result\n\t  lastarg=\n\t  save_ifs=$IFS; IFS=,\n\t  for arg in $args; do\n\t    IFS=$save_ifs\n\t    func_append_quoted lastarg \"$arg\"\n\t  done\n\t  IFS=$save_ifs\n\t  func_stripname ' ' '' \"$lastarg\"\n\t  lastarg=$func_stripname_result\n\n\t  # Add the arguments to base_compile.\n\t  func_append base_compile \" $lastarg\"\n\t  continue\n\t  ;;\n\n\t*)\n\t  # Accept the current argument as the source file.\n\t  # The previous \"srcfile\" becomes the current argument.\n\t  #\n\t  lastarg=$srcfile\n\t  srcfile=$arg\n\t  ;;\n\tesac  #  case $arg\n\t;;\n      esac    #  case $arg_mode\n\n      # Aesthetically quote the previous argument.\n      func_append_quoted base_compile \"$lastarg\"\n    done # for arg\n\n    case $arg_mode in\n    arg)\n      func_fatal_error \"you must specify an argument for -Xcompile\"\n      ;;\n    target)\n      func_fatal_error \"you must specify a target with '-o'\"\n      ;;\n    *)\n      # Get the name of the library object.\n      test -z \"$libobj\" && {\n\tfunc_basename \"$srcfile\"\n\tlibobj=$func_basename_result\n      }\n      ;;\n    esac\n\n    # Recognize several different file suffixes.\n    # If the user specifies -o file.o, it is replaced with file.lo\n    case $libobj in\n    *.[cCFSifmso] | \\\n    *.ada | *.adb | *.ads | *.asm | \\\n    *.c++ | *.cc | *.ii | *.class | *.cpp | *.cxx | \\\n    *.[fF][09]? | *.for | *.java | *.go | *.obj | *.sx | *.cu | *.cup)\n      func_xform \"$libobj\"\n      libobj=$func_xform_result\n      ;;\n    esac\n\n    case $libobj in\n    *.lo) func_lo2o \"$libobj\"; obj=$func_lo2o_result ;;\n    *)\n      func_fatal_error \"cannot determine name of library object from '$libobj'\"\n      ;;\n    esac\n\n    func_infer_tag $base_compile\n\n    for arg in $later; do\n      case $arg in\n      -shared)\n\ttest yes = \"$build_libtool_libs\" \\\n\t  || func_fatal_configuration \"cannot build a shared library\"\n\tbuild_old_libs=no\n\tcontinue\n\t;;\n\n      -static)\n\tbuild_libtool_libs=no\n\tbuild_old_libs=yes\n\tcontinue\n\t;;\n\n      -prefer-pic)\n\tpic_mode=yes\n\tcontinue\n\t;;\n\n      -prefer-non-pic)\n\tpic_mode=no\n\tcontinue\n\t;;\n      esac\n    done\n\n    func_quote_for_eval \"$libobj\"\n    test \"X$libobj\" != \"X$func_quote_for_eval_result\" \\\n      && $ECHO \"X$libobj\" | $GREP '[]~#^*{};<>?\"'\"'\"'\t &()|`$[]' \\\n      && func_warning \"libobj name '$libobj' may not contain shell special characters.\"\n    func_dirname_and_basename \"$obj\" \"/\" \"\"\n    objname=$func_basename_result\n    xdir=$func_dirname_result\n    lobj=$xdir$objdir/$objname\n\n    test -z \"$base_compile\" && \\\n      func_fatal_help \"you must specify a compilation command\"\n\n    # Delete any leftover library objects.\n    if test yes = \"$build_old_libs\"; then\n      removelist=\"$obj $lobj $libobj ${libobj}T\"\n    else\n      removelist=\"$lobj $libobj ${libobj}T\"\n    fi\n\n    # On Cygwin there's no \"real\" PIC flag so we must build both object types\n    case $host_os in\n    cygwin* | mingw* | pw32* | os2* | cegcc*)\n      pic_mode=default\n      ;;\n    esac\n    if test no = \"$pic_mode\" && test pass_all != \"$deplibs_check_method\"; then\n      # non-PIC code in shared libraries is not supported\n      pic_mode=default\n    fi\n\n    # Calculate the filename of the output object if compiler does\n    # not support -o with -c\n    if test no = \"$compiler_c_o\"; then\n      output_obj=`$ECHO \"$srcfile\" | $SED 's%^.*/%%; s%\\.[^.]*$%%'`.$objext\n      lockfile=$output_obj.lock\n    else\n      output_obj=\n      need_locks=no\n      lockfile=\n    fi\n\n    # Lock this critical section if it is needed\n    # We use this script file to make the link, it avoids creating a new file\n    if test yes = \"$need_locks\"; then\n      until $opt_dry_run || ln \"$progpath\" \"$lockfile\" 2>/dev/null; do\n\tfunc_echo \"Waiting for $lockfile to be removed\"\n\tsleep 2\n      done\n    elif test warn = \"$need_locks\"; then\n      if test -f \"$lockfile\"; then\n\t$ECHO \"\\\n*** ERROR, $lockfile exists and contains:\n`cat $lockfile 2>/dev/null`\n\nThis indicates that another process is trying to use the same\ntemporary object file, and libtool could not work around it because\nyour compiler does not support '-c' and '-o' together.  If you\nrepeat this compilation, it may succeed, by chance, but you had better\navoid parallel builds (make -j) in this platform, or get a better\ncompiler.\"\n\n\t$opt_dry_run || $RM $removelist\n\texit $EXIT_FAILURE\n      fi\n      func_append removelist \" $output_obj\"\n      $ECHO \"$srcfile\" > \"$lockfile\"\n    fi\n\n    $opt_dry_run || $RM $removelist\n    func_append removelist \" $lockfile\"\n    trap '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE' 1 2 15\n\n    func_to_tool_file \"$srcfile\" func_convert_file_msys_to_w32\n    srcfile=$func_to_tool_file_result\n    func_quote_for_eval \"$srcfile\"\n    qsrcfile=$func_quote_for_eval_result\n\n    # Only build a PIC object if we are building libtool libraries.\n    if test yes = \"$build_libtool_libs\"; then\n      # Without this assignment, base_compile gets emptied.\n      fbsd_hideous_sh_bug=$base_compile\n\n      if test no != \"$pic_mode\"; then\n\tcommand=\"$base_compile $qsrcfile $pic_flag\"\n      else\n\t# Don't build PIC code\n\tcommand=\"$base_compile $qsrcfile\"\n      fi\n\n      func_mkdir_p \"$xdir$objdir\"\n\n      if test -z \"$output_obj\"; then\n\t# Place PIC objects in $objdir\n\tfunc_append command \" -o $lobj\"\n      fi\n\n      func_show_eval_locale \"$command\"\t\\\n          'test -n \"$output_obj\" && $RM $removelist; exit $EXIT_FAILURE'\n\n      if test warn = \"$need_locks\" &&\n\t test \"X`cat $lockfile 2>/dev/null`\" != \"X$srcfile\"; then\n\t$ECHO \"\\\n*** ERROR, $lockfile contains:\n`cat $lockfile 2>/dev/null`\n\nbut it should contain:\n$srcfile\n\nThis indicates that another process is trying to use the same\ntemporary object file, and libtool could not work around it because\nyour compiler does not support '-c' and '-o' together.  If you\nrepeat this compilation, it may succeed, by chance, but you had better\navoid parallel builds (make -j) in this platform, or get a better\ncompiler.\"\n\n\t$opt_dry_run || $RM $removelist\n\texit $EXIT_FAILURE\n      fi\n\n      # Just move the object if needed, then go on to compile the next one\n      if test -n \"$output_obj\" && test \"X$output_obj\" != \"X$lobj\"; then\n\tfunc_show_eval '$MV \"$output_obj\" \"$lobj\"' \\\n\t  'error=$?; $opt_dry_run || $RM $removelist; exit $error'\n      fi\n\n      # Allow error messages only from the first compilation.\n      if test yes = \"$suppress_opt\"; then\n\tsuppress_output=' >/dev/null 2>&1'\n      fi\n    fi\n\n    # Only build a position-dependent object if we build old libraries.\n    if test yes = \"$build_old_libs\"; then\n      if test yes != \"$pic_mode\"; then\n\t# Don't build PIC code\n\tcommand=\"$base_compile $qsrcfile$pie_flag\"\n      else\n\tcommand=\"$base_compile $qsrcfile $pic_flag\"\n      fi\n      if test yes = \"$compiler_c_o\"; then\n\tfunc_append command \" -o $obj\"\n      fi\n\n      # Suppress compiler output if we already did a PIC compilation.\n      func_append command \"$suppress_output\"\n      func_show_eval_locale \"$command\" \\\n        '$opt_dry_run || $RM $removelist; exit $EXIT_FAILURE'\n\n      if test warn = \"$need_locks\" &&\n\t test \"X`cat $lockfile 2>/dev/null`\" != \"X$srcfile\"; then\n\t$ECHO \"\\\n*** ERROR, $lockfile contains:\n`cat $lockfile 2>/dev/null`\n\nbut it should contain:\n$srcfile\n\nThis indicates that another process is trying to use the same\ntemporary object file, and libtool could not work around it because\nyour compiler does not support '-c' and '-o' together.  If you\nrepeat this compilation, it may succeed, by chance, but you had better\navoid parallel builds (make -j) in this platform, or get a better\ncompiler.\"\n\n\t$opt_dry_run || $RM $removelist\n\texit $EXIT_FAILURE\n      fi\n\n      # Just move the object if needed\n      if test -n \"$output_obj\" && test \"X$output_obj\" != \"X$obj\"; then\n\tfunc_show_eval '$MV \"$output_obj\" \"$obj\"' \\\n\t  'error=$?; $opt_dry_run || $RM $removelist; exit $error'\n      fi\n    fi\n\n    $opt_dry_run || {\n      func_write_libtool_object \"$libobj\" \"$objdir/$objname\" \"$objname\"\n\n      # Unlock the critical section if it was locked\n      if test no != \"$need_locks\"; then\n\tremovelist=$lockfile\n        $RM \"$lockfile\"\n      fi\n    }\n\n    exit $EXIT_SUCCESS\n}\n\n$opt_help || {\n  test compile = \"$opt_mode\" && func_mode_compile ${1+\"$@\"}\n}\n\nfunc_mode_help ()\n{\n    # We need to display help for each of the modes.\n    case $opt_mode in\n      \"\")\n        # Generic help is extracted from the usage comments\n        # at the start of this file.\n        func_help\n        ;;\n\n      clean)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=clean RM [RM-OPTION]... FILE...\n\nRemove files from the build directory.\n\nRM is the name of the program to use to delete files associated with each FILE\n(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed\nto RM.\n\nIf FILE is a libtool library, object or program, all the files associated\nwith it are deleted. Otherwise, only FILE itself is deleted using RM.\"\n        ;;\n\n      compile)\n      $ECHO \\\n\"Usage: $progname [OPTION]... --mode=compile COMPILE-COMMAND... SOURCEFILE\n\nCompile a source file into a libtool library object.\n\nThis mode accepts the following additional options:\n\n  -o OUTPUT-FILE    set the output file name to OUTPUT-FILE\n  -no-suppress      do not suppress compiler output for multiple passes\n  -prefer-pic       try to build PIC objects only\n  -prefer-non-pic   try to build non-PIC objects only\n  -shared           do not build a '.o' file suitable for static linking\n  -static           only build a '.o' file suitable for static linking\n  -Wc,FLAG          pass FLAG directly to the compiler\n\nCOMPILE-COMMAND is a command to be used in creating a 'standard' object file\nfrom the given SOURCEFILE.\n\nThe output file name is determined by removing the directory component from\nSOURCEFILE, then substituting the C source code suffix '.c' with the\nlibrary object suffix, '.lo'.\"\n        ;;\n\n      execute)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=execute COMMAND [ARGS]...\n\nAutomatically set library path, then run a program.\n\nThis mode accepts the following additional options:\n\n  -dlopen FILE      add the directory containing FILE to the library path\n\nThis mode sets the library path environment variable according to '-dlopen'\nflags.\n\nIf any of the ARGS are libtool executable wrappers, then they are translated\ninto their corresponding uninstalled binary, and any of their required library\ndirectories are added to the library path.\n\nThen, COMMAND is executed, with ARGS as arguments.\"\n        ;;\n\n      finish)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=finish [LIBDIR]...\n\nComplete the installation of libtool libraries.\n\nEach LIBDIR is a directory that contains libtool libraries.\n\nThe commands that this mode executes may require superuser privileges.  Use\nthe '--dry-run' option if you just want to see what would be executed.\"\n        ;;\n\n      install)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=install INSTALL-COMMAND...\n\nInstall executables or libraries.\n\nINSTALL-COMMAND is the installation command.  The first component should be\neither the 'install' or 'cp' program.\n\nThe following components of INSTALL-COMMAND are treated specially:\n\n  -inst-prefix-dir PREFIX-DIR  Use PREFIX-DIR as a staging area for installation\n\nThe rest of the components are interpreted as arguments to that command (only\nBSD-compatible install options are recognized).\"\n        ;;\n\n      link)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=link LINK-COMMAND...\n\nLink object files or libraries together to form another library, or to\ncreate an executable program.\n\nLINK-COMMAND is a command using the C compiler that you would use to create\na program from several object files.\n\nThe following components of LINK-COMMAND are treated specially:\n\n  -all-static       do not do any dynamic linking at all\n  -avoid-version    do not add a version suffix if possible\n  -bindir BINDIR    specify path to binaries directory (for systems where\n                    libraries must be found in the PATH setting at runtime)\n  -dlopen FILE      '-dlpreopen' FILE if it cannot be dlopened at runtime\n  -dlpreopen FILE   link in FILE and add its symbols to lt_preloaded_symbols\n  -export-dynamic   allow symbols from OUTPUT-FILE to be resolved with dlsym(3)\n  -export-symbols SYMFILE\n                    try to export only the symbols listed in SYMFILE\n  -export-symbols-regex REGEX\n                    try to export only the symbols matching REGEX\n  -LLIBDIR          search LIBDIR for required installed libraries\n  -lNAME            OUTPUT-FILE requires the installed library libNAME\n  -module           build a library that can dlopened\n  -no-fast-install  disable the fast-install mode\n  -no-install       link a not-installable executable\n  -no-undefined     declare that a library does not refer to external symbols\n  -o OUTPUT-FILE    create OUTPUT-FILE from the specified objects\n  -objectlist FILE  use a list of object files found in FILE to specify objects\n  -os2dllname NAME  force a short DLL name on OS/2 (no effect on other OSes)\n  -precious-files-regex REGEX\n                    don't remove output files matching REGEX\n  -release RELEASE  specify package release information\n  -rpath LIBDIR     the created library will eventually be installed in LIBDIR\n  -R[ ]LIBDIR       add LIBDIR to the runtime path of programs and libraries\n  -shared           only do dynamic linking of libtool libraries\n  -shrext SUFFIX    override the standard shared library file extension\n  -static           do not do any dynamic linking of uninstalled libtool libraries\n  -static-libtool-libs\n                    do not do any dynamic linking of libtool libraries\n  -version-info CURRENT[:REVISION[:AGE]]\n                    specify library version info [each variable defaults to 0]\n  -weak LIBNAME     declare that the target provides the LIBNAME interface\n  -Wc,FLAG\n  -Xcompiler FLAG   pass linker-specific FLAG directly to the compiler\n  -Wl,FLAG\n  -Xlinker FLAG     pass linker-specific FLAG directly to the linker\n  -XCClinker FLAG   pass link-specific FLAG to the compiler driver (CC)\n\nAll other options (arguments beginning with '-') are ignored.\n\nEvery other argument is treated as a filename.  Files ending in '.la' are\ntreated as uninstalled libtool libraries, other files are standard or library\nobject files.\n\nIf the OUTPUT-FILE ends in '.la', then a libtool library is created,\nonly library objects ('.lo' files) may be specified, and '-rpath' is\nrequired, except when creating a convenience library.\n\nIf OUTPUT-FILE ends in '.a' or '.lib', then a standard library is created\nusing 'ar' and 'ranlib', or on Windows using 'lib'.\n\nIf OUTPUT-FILE ends in '.lo' or '.$objext', then a reloadable object file\nis created, otherwise an executable program is created.\"\n        ;;\n\n      uninstall)\n        $ECHO \\\n\"Usage: $progname [OPTION]... --mode=uninstall RM [RM-OPTION]... FILE...\n\nRemove libraries from an installation directory.\n\nRM is the name of the program to use to delete files associated with each FILE\n(typically '/bin/rm').  RM-OPTIONS are options (such as '-f') to be passed\nto RM.\n\nIf FILE is a libtool library, all the files associated with it are deleted.\nOtherwise, only FILE itself is deleted using RM.\"\n        ;;\n\n      *)\n        func_fatal_help \"invalid operation mode '$opt_mode'\"\n        ;;\n    esac\n\n    echo\n    $ECHO \"Try '$progname --help' for more information about other modes.\"\n}\n\n# Now that we've collected a possible --mode arg, show help if necessary\nif $opt_help; then\n  if test : = \"$opt_help\"; then\n    func_mode_help\n  else\n    {\n      func_help noexit\n      for opt_mode in compile link execute install finish uninstall clean; do\n\tfunc_mode_help\n      done\n    } | $SED -n '1p; 2,$s/^Usage:/  or: /p'\n    {\n      func_help noexit\n      for opt_mode in compile link execute install finish uninstall clean; do\n\techo\n\tfunc_mode_help\n      done\n    } |\n    $SED '1d\n      /^When reporting/,/^Report/{\n\tH\n\td\n      }\n      $x\n      /information about other modes/d\n      /more detailed .*MODE/d\n      s/^Usage:.*--mode=\\([^ ]*\\) .*/Description of \\1 mode:/'\n  fi\n  exit $?\nfi\n\n\n# func_mode_execute arg...\nfunc_mode_execute ()\n{\n    $debug_cmd\n\n    # The first argument is the command name.\n    cmd=$nonopt\n    test -z \"$cmd\" && \\\n      func_fatal_help \"you must specify a COMMAND\"\n\n    # Handle -dlopen flags immediately.\n    for file in $opt_dlopen; do\n      test -f \"$file\" \\\n\t|| func_fatal_help \"'$file' is not a file\"\n\n      dir=\n      case $file in\n      *.la)\n\tfunc_resolve_sysroot \"$file\"\n\tfile=$func_resolve_sysroot_result\n\n\t# Check to see that this really is a libtool archive.\n\tfunc_lalib_unsafe_p \"$file\" \\\n\t  || func_fatal_help \"'$lib' is not a valid libtool archive\"\n\n\t# Read the libtool library.\n\tdlname=\n\tlibrary_names=\n\tfunc_source \"$file\"\n\n\t# Skip this library if it cannot be dlopened.\n\tif test -z \"$dlname\"; then\n\t  # Warn if it was a shared library.\n\t  test -n \"$library_names\" && \\\n\t    func_warning \"'$file' was not linked with '-export-dynamic'\"\n\t  continue\n\tfi\n\n\tfunc_dirname \"$file\" \"\" \".\"\n\tdir=$func_dirname_result\n\n\tif test -f \"$dir/$objdir/$dlname\"; then\n\t  func_append dir \"/$objdir\"\n\telse\n\t  if test ! -f \"$dir/$dlname\"; then\n\t    func_fatal_error \"cannot find '$dlname' in '$dir' or '$dir/$objdir'\"\n\t  fi\n\tfi\n\t;;\n\n      *.lo)\n\t# Just add the directory containing the .lo file.\n\tfunc_dirname \"$file\" \"\" \".\"\n\tdir=$func_dirname_result\n\t;;\n\n      *)\n\tfunc_warning \"'-dlopen' is ignored for non-libtool libraries and objects\"\n\tcontinue\n\t;;\n      esac\n\n      # Get the absolute pathname.\n      absdir=`cd \"$dir\" && pwd`\n      test -n \"$absdir\" && dir=$absdir\n\n      # Now add the directory to shlibpath_var.\n      if eval \"test -z \\\"\\$$shlibpath_var\\\"\"; then\n\teval \"$shlibpath_var=\\\"\\$dir\\\"\"\n      else\n\teval \"$shlibpath_var=\\\"\\$dir:\\$$shlibpath_var\\\"\"\n      fi\n    done\n\n    # This variable tells wrapper scripts just to set shlibpath_var\n    # rather than running their programs.\n    libtool_execute_magic=$magic\n\n    # Check if any of the arguments is a wrapper script.\n    args=\n    for file\n    do\n      case $file in\n      -* | *.la | *.lo ) ;;\n      *)\n\t# Do a test to see if this is really a libtool program.\n\tif func_ltwrapper_script_p \"$file\"; then\n\t  func_source \"$file\"\n\t  # Transform arg to wrapped name.\n\t  file=$progdir/$program\n\telif func_ltwrapper_executable_p \"$file\"; then\n\t  func_ltwrapper_scriptname \"$file\"\n\t  func_source \"$func_ltwrapper_scriptname_result\"\n\t  # Transform arg to wrapped name.\n\t  file=$progdir/$program\n\tfi\n\t;;\n      esac\n      # Quote arguments (to preserve shell metacharacters).\n      func_append_quoted args \"$file\"\n    done\n\n    if $opt_dry_run; then\n      # Display what would be done.\n      if test -n \"$shlibpath_var\"; then\n\teval \"\\$ECHO \\\"\\$shlibpath_var=\\$$shlibpath_var\\\"\"\n\techo \"export $shlibpath_var\"\n      fi\n      $ECHO \"$cmd$args\"\n      exit $EXIT_SUCCESS\n    else\n      if test -n \"$shlibpath_var\"; then\n\t# Export the shlibpath_var.\n\teval \"export $shlibpath_var\"\n      fi\n\n      # Restore saved environment variables\n      for lt_var in LANG LANGUAGE LC_ALL LC_CTYPE LC_COLLATE LC_MESSAGES\n      do\n\teval \"if test \\\"\\${save_$lt_var+set}\\\" = set; then\n                $lt_var=\\$save_$lt_var; export $lt_var\n\t      else\n\t\t$lt_unset $lt_var\n\t      fi\"\n      done\n\n      # Now prepare to actually exec the command.\n      exec_cmd=\\$cmd$args\n    fi\n}\n\ntest execute = \"$opt_mode\" && func_mode_execute ${1+\"$@\"}\n\n\n# func_mode_finish arg...\nfunc_mode_finish ()\n{\n    $debug_cmd\n\n    libs=\n    libdirs=\n    admincmds=\n\n    for opt in \"$nonopt\" ${1+\"$@\"}\n    do\n      if test -d \"$opt\"; then\n\tfunc_append libdirs \" $opt\"\n\n      elif test -f \"$opt\"; then\n\tif func_lalib_unsafe_p \"$opt\"; then\n\t  func_append libs \" $opt\"\n\telse\n\t  func_warning \"'$opt' is not a valid libtool archive\"\n\tfi\n\n      else\n\tfunc_fatal_error \"invalid argument '$opt'\"\n      fi\n    done\n\n    if test -n \"$libs\"; then\n      if test -n \"$lt_sysroot\"; then\n        sysroot_regex=`$ECHO \"$lt_sysroot\" | $SED \"$sed_make_literal_regex\"`\n        sysroot_cmd=\"s/\\([ ']\\)$sysroot_regex/\\1/g;\"\n      else\n        sysroot_cmd=\n      fi\n\n      # Remove sysroot references\n      if $opt_dry_run; then\n        for lib in $libs; do\n          echo \"removing references to $lt_sysroot and '=' prefixes from $lib\"\n        done\n      else\n        tmpdir=`func_mktempdir`\n        for lib in $libs; do\n\t  $SED -e \"$sysroot_cmd s/\\([ ']-[LR]\\)=/\\1/g; s/\\([ ']\\)=/\\1/g\" $lib \\\n\t    > $tmpdir/tmp-la\n\t  mv -f $tmpdir/tmp-la $lib\n\tdone\n        ${RM}r \"$tmpdir\"\n      fi\n    fi\n\n    if test -n \"$finish_cmds$finish_eval\" && test -n \"$libdirs\"; then\n      for libdir in $libdirs; do\n\tif test -n \"$finish_cmds\"; then\n\t  # Do each command in the finish commands.\n\t  func_execute_cmds \"$finish_cmds\" 'admincmds=\"$admincmds\n'\"$cmd\"'\"'\n\tfi\n\tif test -n \"$finish_eval\"; then\n\t  # Do the single finish_eval.\n\t  eval cmds=\\\"$finish_eval\\\"\n\t  $opt_dry_run || eval \"$cmds\" || func_append admincmds \"\n       $cmds\"\n\tfi\n      done\n    fi\n\n    # Exit here if they wanted silent mode.\n    $opt_quiet && exit $EXIT_SUCCESS\n\n    if test -n \"$finish_cmds$finish_eval\" && test -n \"$libdirs\"; then\n      echo \"----------------------------------------------------------------------\"\n      echo \"Libraries have been installed in:\"\n      for libdir in $libdirs; do\n\t$ECHO \"   $libdir\"\n      done\n      echo\n      echo \"If you ever happen to want to link against installed libraries\"\n      echo \"in a given directory, LIBDIR, you must either use libtool, and\"\n      echo \"specify the full pathname of the library, or use the '-LLIBDIR'\"\n      echo \"flag during linking and do at least one of the following:\"\n      if test -n \"$shlibpath_var\"; then\n\techo \"   - add LIBDIR to the '$shlibpath_var' environment variable\"\n\techo \"     during execution\"\n      fi\n      if test -n \"$runpath_var\"; then\n\techo \"   - add LIBDIR to the '$runpath_var' environment variable\"\n\techo \"     during linking\"\n      fi\n      if test -n \"$hardcode_libdir_flag_spec\"; then\n\tlibdir=LIBDIR\n\teval flag=\\\"$hardcode_libdir_flag_spec\\\"\n\n\t$ECHO \"   - use the '$flag' linker flag\"\n      fi\n      if test -n \"$admincmds\"; then\n\t$ECHO \"   - have your system administrator run these commands:$admincmds\"\n      fi\n      if test -f /etc/ld.so.conf; then\n\techo \"   - have your system administrator add LIBDIR to '/etc/ld.so.conf'\"\n      fi\n      echo\n\n      echo \"See any operating system documentation about shared libraries for\"\n      case $host in\n\tsolaris2.[6789]|solaris2.1[0-9])\n\t  echo \"more information, such as the ld(1), crle(1) and ld.so(8) manual\"\n\t  echo \"pages.\"\n\t  ;;\n\t*)\n\t  echo \"more information, such as the ld(1) and ld.so(8) manual pages.\"\n\t  ;;\n      esac\n      echo \"----------------------------------------------------------------------\"\n    fi\n    exit $EXIT_SUCCESS\n}\n\ntest finish = \"$opt_mode\" && func_mode_finish ${1+\"$@\"}\n\n\n# func_mode_install arg...\nfunc_mode_install ()\n{\n    $debug_cmd\n\n    # There may be an optional sh(1) argument at the beginning of\n    # install_prog (especially on Windows NT).\n    if test \"$SHELL\" = \"$nonopt\" || test /bin/sh = \"$nonopt\" ||\n       # Allow the use of GNU shtool's install command.\n       case $nonopt in *shtool*) :;; *) false;; esac\n    then\n      # Aesthetically quote it.\n      func_quote_for_eval \"$nonopt\"\n      install_prog=\"$func_quote_for_eval_result \"\n      arg=$1\n      shift\n    else\n      install_prog=\n      arg=$nonopt\n    fi\n\n    # The real first argument should be the name of the installation program.\n    # Aesthetically quote it.\n    func_quote_for_eval \"$arg\"\n    func_append install_prog \"$func_quote_for_eval_result\"\n    install_shared_prog=$install_prog\n    case \" $install_prog \" in\n      *[\\\\\\ /]cp\\ *) install_cp=: ;;\n      *) install_cp=false ;;\n    esac\n\n    # We need to accept at least all the BSD install flags.\n    dest=\n    files=\n    opts=\n    prev=\n    install_type=\n    isdir=false\n    stripme=\n    no_mode=:\n    for arg\n    do\n      arg2=\n      if test -n \"$dest\"; then\n\tfunc_append files \" $dest\"\n\tdest=$arg\n\tcontinue\n      fi\n\n      case $arg in\n      -d) isdir=: ;;\n      -f)\n\tif $install_cp; then :; else\n\t  prev=$arg\n\tfi\n\t;;\n      -g | -m | -o)\n\tprev=$arg\n\t;;\n      -s)\n\tstripme=\" -s\"\n\tcontinue\n\t;;\n      -*)\n\t;;\n      *)\n\t# If the previous option needed an argument, then skip it.\n\tif test -n \"$prev\"; then\n\t  if test X-m = \"X$prev\" && test -n \"$install_override_mode\"; then\n\t    arg2=$install_override_mode\n\t    no_mode=false\n\t  fi\n\t  prev=\n\telse\n\t  dest=$arg\n\t  continue\n\tfi\n\t;;\n      esac\n\n      # Aesthetically quote the argument.\n      func_quote_for_eval \"$arg\"\n      func_append install_prog \" $func_quote_for_eval_result\"\n      if test -n \"$arg2\"; then\n\tfunc_quote_for_eval \"$arg2\"\n      fi\n      func_append install_shared_prog \" $func_quote_for_eval_result\"\n    done\n\n    test -z \"$install_prog\" && \\\n      func_fatal_help \"you must specify an install program\"\n\n    test -n \"$prev\" && \\\n      func_fatal_help \"the '$prev' option requires an argument\"\n\n    if test -n \"$install_override_mode\" && $no_mode; then\n      if $install_cp; then :; else\n\tfunc_quote_for_eval \"$install_override_mode\"\n\tfunc_append install_shared_prog \" -m $func_quote_for_eval_result\"\n      fi\n    fi\n\n    if test -z \"$files\"; then\n      if test -z \"$dest\"; then\n\tfunc_fatal_help \"no file or destination specified\"\n      else\n\tfunc_fatal_help \"you must specify a destination\"\n      fi\n    fi\n\n    # Strip any trailing slash from the destination.\n    func_stripname '' '/' \"$dest\"\n    dest=$func_stripname_result\n\n    # Check to see that the destination is a directory.\n    test -d \"$dest\" && isdir=:\n    if $isdir; then\n      destdir=$dest\n      destname=\n    else\n      func_dirname_and_basename \"$dest\" \"\" \".\"\n      destdir=$func_dirname_result\n      destname=$func_basename_result\n\n      # Not a directory, so check to see that there is only one file specified.\n      set dummy $files; shift\n      test \"$#\" -gt 1 && \\\n\tfunc_fatal_help \"'$dest' is not a directory\"\n    fi\n    case $destdir in\n    [\\\\/]* | [A-Za-z]:[\\\\/]*) ;;\n    *)\n      for file in $files; do\n\tcase $file in\n\t*.lo) ;;\n\t*)\n\t  func_fatal_help \"'$destdir' must be an absolute directory name\"\n\t  ;;\n\tesac\n      done\n      ;;\n    esac\n\n    # This variable tells wrapper scripts just to set variables rather\n    # than running their programs.\n    libtool_install_magic=$magic\n\n    staticlibs=\n    future_libdirs=\n    current_libdirs=\n    for file in $files; do\n\n      # Do each installation.\n      case $file in\n      *.$libext)\n\t# Do the static libraries later.\n\tfunc_append staticlibs \" $file\"\n\t;;\n\n      *.la)\n\tfunc_resolve_sysroot \"$file\"\n\tfile=$func_resolve_sysroot_result\n\n\t# Check to see that this really is a libtool archive.\n\tfunc_lalib_unsafe_p \"$file\" \\\n\t  || func_fatal_help \"'$file' is not a valid libtool archive\"\n\n\tlibrary_names=\n\told_library=\n\trelink_command=\n\tfunc_source \"$file\"\n\n\t# Add the libdir to current_libdirs if it is the destination.\n\tif test \"X$destdir\" = \"X$libdir\"; then\n\t  case \"$current_libdirs \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append current_libdirs \" $libdir\" ;;\n\t  esac\n\telse\n\t  # Note the libdir as a future libdir.\n\t  case \"$future_libdirs \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append future_libdirs \" $libdir\" ;;\n\t  esac\n\tfi\n\n\tfunc_dirname \"$file\" \"/\" \"\"\n\tdir=$func_dirname_result\n\tfunc_append dir \"$objdir\"\n\n\tif test -n \"$relink_command\"; then\n\t  # Determine the prefix the user has applied to our future dir.\n\t  inst_prefix_dir=`$ECHO \"$destdir\" | $SED -e \"s%$libdir\\$%%\"`\n\n\t  # Don't allow the user to place us outside of our expected\n\t  # location b/c this prevents finding dependent libraries that\n\t  # are installed to the same prefix.\n\t  # At present, this check doesn't affect windows .dll's that\n\t  # are installed into $libdir/../bin (currently, that works fine)\n\t  # but it's something to keep an eye on.\n\t  test \"$inst_prefix_dir\" = \"$destdir\" && \\\n\t    func_fatal_error \"error: cannot install '$file' to a directory not ending in $libdir\"\n\n\t  if test -n \"$inst_prefix_dir\"; then\n\t    # Stick the inst_prefix_dir data into the link command.\n\t    relink_command=`$ECHO \"$relink_command\" | $SED \"s%@inst_prefix_dir@%-inst-prefix-dir $inst_prefix_dir%\"`\n\t  else\n\t    relink_command=`$ECHO \"$relink_command\" | $SED \"s%@inst_prefix_dir@%%\"`\n\t  fi\n\n\t  func_warning \"relinking '$file'\"\n\t  func_show_eval \"$relink_command\" \\\n\t    'func_fatal_error \"error: relink '\\''$file'\\'' with the above command before installing it\"'\n\tfi\n\n\t# See the names of the shared library.\n\tset dummy $library_names; shift\n\tif test -n \"$1\"; then\n\t  realname=$1\n\t  shift\n\n\t  srcname=$realname\n\t  test -n \"$relink_command\" && srcname=${realname}T\n\n\t  # Install the shared library and build the symlinks.\n\t  func_show_eval \"$install_shared_prog $dir/$srcname $destdir/$realname\" \\\n\t      'exit $?'\n\t  tstripme=$stripme\n\t  case $host_os in\n\t  cygwin* | mingw* | pw32* | cegcc*)\n\t    case $realname in\n\t    *.dll.a)\n\t      tstripme=\n\t      ;;\n\t    esac\n\t    ;;\n\t  os2*)\n\t    case $realname in\n\t    *_dll.a)\n\t      tstripme=\n\t      ;;\n\t    esac\n\t    ;;\n\t  esac\n\t  if test -n \"$tstripme\" && test -n \"$striplib\"; then\n\t    func_show_eval \"$striplib $destdir/$realname\" 'exit $?'\n\t  fi\n\n\t  if test \"$#\" -gt 0; then\n\t    # Delete the old symlinks, and create new ones.\n\t    # Try 'ln -sf' first, because the 'ln' binary might depend on\n\t    # the symlink we replace!  Solaris /bin/ln does not understand -f,\n\t    # so we also need to try rm && ln -s.\n\t    for linkname\n\t    do\n\t      test \"$linkname\" != \"$realname\" \\\n\t\t&& func_show_eval \"(cd $destdir && { $LN_S -f $realname $linkname || { $RM $linkname && $LN_S $realname $linkname; }; })\"\n\t    done\n\t  fi\n\n\t  # Do each command in the postinstall commands.\n\t  lib=$destdir/$realname\n\t  func_execute_cmds \"$postinstall_cmds\" 'exit $?'\n\tfi\n\n\t# Install the pseudo-library for information purposes.\n\tfunc_basename \"$file\"\n\tname=$func_basename_result\n\tinstname=$dir/${name}i\n\tfunc_show_eval \"$install_prog $instname $destdir/$name\" 'exit $?'\n\n\t# Maybe install the static library, too.\n\ttest -n \"$old_library\" && func_append staticlibs \" $dir/$old_library\"\n\t;;\n\n      *.lo)\n\t# Install (i.e. copy) a libtool object.\n\n\t# Figure out destination file name, if it wasn't already specified.\n\tif test -n \"$destname\"; then\n\t  destfile=$destdir/$destname\n\telse\n\t  func_basename \"$file\"\n\t  destfile=$func_basename_result\n\t  destfile=$destdir/$destfile\n\tfi\n\n\t# Deduce the name of the destination old-style object file.\n\tcase $destfile in\n\t*.lo)\n\t  func_lo2o \"$destfile\"\n\t  staticdest=$func_lo2o_result\n\t  ;;\n\t*.$objext)\n\t  staticdest=$destfile\n\t  destfile=\n\t  ;;\n\t*)\n\t  func_fatal_help \"cannot copy a libtool object to '$destfile'\"\n\t  ;;\n\tesac\n\n\t# Install the libtool object if requested.\n\ttest -n \"$destfile\" && \\\n\t  func_show_eval \"$install_prog $file $destfile\" 'exit $?'\n\n\t# Install the old object if enabled.\n\tif test yes = \"$build_old_libs\"; then\n\t  # Deduce the name of the old-style object file.\n\t  func_lo2o \"$file\"\n\t  staticobj=$func_lo2o_result\n\t  func_show_eval \"$install_prog \\$staticobj \\$staticdest\" 'exit $?'\n\tfi\n\texit $EXIT_SUCCESS\n\t;;\n\n      *)\n\t# Figure out destination file name, if it wasn't already specified.\n\tif test -n \"$destname\"; then\n\t  destfile=$destdir/$destname\n\telse\n\t  func_basename \"$file\"\n\t  destfile=$func_basename_result\n\t  destfile=$destdir/$destfile\n\tfi\n\n\t# If the file is missing, and there is a .exe on the end, strip it\n\t# because it is most likely a libtool script we actually want to\n\t# install\n\tstripped_ext=\n\tcase $file in\n\t  *.exe)\n\t    if test ! -f \"$file\"; then\n\t      func_stripname '' '.exe' \"$file\"\n\t      file=$func_stripname_result\n\t      stripped_ext=.exe\n\t    fi\n\t    ;;\n\tesac\n\n\t# Do a test to see if this is really a libtool program.\n\tcase $host in\n\t*cygwin* | *mingw*)\n\t    if func_ltwrapper_executable_p \"$file\"; then\n\t      func_ltwrapper_scriptname \"$file\"\n\t      wrapper=$func_ltwrapper_scriptname_result\n\t    else\n\t      func_stripname '' '.exe' \"$file\"\n\t      wrapper=$func_stripname_result\n\t    fi\n\t    ;;\n\t*)\n\t    wrapper=$file\n\t    ;;\n\tesac\n\tif func_ltwrapper_script_p \"$wrapper\"; then\n\t  notinst_deplibs=\n\t  relink_command=\n\n\t  func_source \"$wrapper\"\n\n\t  # Check the variables that should have been set.\n\t  test -z \"$generated_by_libtool_version\" && \\\n\t    func_fatal_error \"invalid libtool wrapper script '$wrapper'\"\n\n\t  finalize=:\n\t  for lib in $notinst_deplibs; do\n\t    # Check to see that each library is installed.\n\t    libdir=\n\t    if test -f \"$lib\"; then\n\t      func_source \"$lib\"\n\t    fi\n\t    libfile=$libdir/`$ECHO \"$lib\" | $SED 's%^.*/%%g'`\n\t    if test -n \"$libdir\" && test ! -f \"$libfile\"; then\n\t      func_warning \"'$lib' has not been installed in '$libdir'\"\n\t      finalize=false\n\t    fi\n\t  done\n\n\t  relink_command=\n\t  func_source \"$wrapper\"\n\n\t  outputname=\n\t  if test no = \"$fast_install\" && test -n \"$relink_command\"; then\n\t    $opt_dry_run || {\n\t      if $finalize; then\n\t        tmpdir=`func_mktempdir`\n\t\tfunc_basename \"$file$stripped_ext\"\n\t\tfile=$func_basename_result\n\t        outputname=$tmpdir/$file\n\t        # Replace the output file specification.\n\t        relink_command=`$ECHO \"$relink_command\" | $SED 's%@OUTPUT@%'\"$outputname\"'%g'`\n\n\t        $opt_quiet || {\n\t          func_quote_for_expand \"$relink_command\"\n\t\t  eval \"func_echo $func_quote_for_expand_result\"\n\t        }\n\t        if eval \"$relink_command\"; then :\n\t          else\n\t\t  func_error \"error: relink '$file' with the above command before installing it\"\n\t\t  $opt_dry_run || ${RM}r \"$tmpdir\"\n\t\t  continue\n\t        fi\n\t        file=$outputname\n\t      else\n\t        func_warning \"cannot relink '$file'\"\n\t      fi\n\t    }\n\t  else\n\t    # Install the binary that we compiled earlier.\n\t    file=`$ECHO \"$file$stripped_ext\" | $SED \"s%\\([^/]*\\)$%$objdir/\\1%\"`\n\t  fi\n\tfi\n\n\t# remove .exe since cygwin /usr/bin/install will append another\n\t# one anyway\n\tcase $install_prog,$host in\n\t*/usr/bin/install*,*cygwin*)\n\t  case $file:$destfile in\n\t  *.exe:*.exe)\n\t    # this is ok\n\t    ;;\n\t  *.exe:*)\n\t    destfile=$destfile.exe\n\t    ;;\n\t  *:*.exe)\n\t    func_stripname '' '.exe' \"$destfile\"\n\t    destfile=$func_stripname_result\n\t    ;;\n\t  esac\n\t  ;;\n\tesac\n\tfunc_show_eval \"$install_prog\\$stripme \\$file \\$destfile\" 'exit $?'\n\t$opt_dry_run || if test -n \"$outputname\"; then\n\t  ${RM}r \"$tmpdir\"\n\tfi\n\t;;\n      esac\n    done\n\n    for file in $staticlibs; do\n      func_basename \"$file\"\n      name=$func_basename_result\n\n      # Set up the ranlib parameters.\n      oldlib=$destdir/$name\n      func_to_tool_file \"$oldlib\" func_convert_file_msys_to_w32\n      tool_oldlib=$func_to_tool_file_result\n\n      func_show_eval \"$install_prog \\$file \\$oldlib\" 'exit $?'\n\n      if test -n \"$stripme\" && test -n \"$old_striplib\"; then\n\tfunc_show_eval \"$old_striplib $tool_oldlib\" 'exit $?'\n      fi\n\n      # Do each command in the postinstall commands.\n      func_execute_cmds \"$old_postinstall_cmds\" 'exit $?'\n    done\n\n    test -n \"$future_libdirs\" && \\\n      func_warning \"remember to run '$progname --finish$future_libdirs'\"\n\n    if test -n \"$current_libdirs\"; then\n      # Maybe just do a dry run.\n      $opt_dry_run && current_libdirs=\" -n$current_libdirs\"\n      exec_cmd='$SHELL \"$progpath\" $preserve_args --finish$current_libdirs'\n    else\n      exit $EXIT_SUCCESS\n    fi\n}\n\ntest install = \"$opt_mode\" && func_mode_install ${1+\"$@\"}\n\n\n# func_generate_dlsyms outputname originator pic_p\n# Extract symbols from dlprefiles and create ${outputname}S.o with\n# a dlpreopen symbol table.\nfunc_generate_dlsyms ()\n{\n    $debug_cmd\n\n    my_outputname=$1\n    my_originator=$2\n    my_pic_p=${3-false}\n    my_prefix=`$ECHO \"$my_originator\" | $SED 's%[^a-zA-Z0-9]%_%g'`\n    my_dlsyms=\n\n    if test -n \"$dlfiles$dlprefiles\" || test no != \"$dlself\"; then\n      if test -n \"$NM\" && test -n \"$global_symbol_pipe\"; then\n\tmy_dlsyms=${my_outputname}S.c\n      else\n\tfunc_error \"not configured to extract global symbols from dlpreopened files\"\n      fi\n    fi\n\n    if test -n \"$my_dlsyms\"; then\n      case $my_dlsyms in\n      \"\") ;;\n      *.c)\n\t# Discover the nlist of each of the dlfiles.\n\tnlist=$output_objdir/$my_outputname.nm\n\n\tfunc_show_eval \"$RM $nlist ${nlist}S ${nlist}T\"\n\n\t# Parse the name list into a source file.\n\tfunc_verbose \"creating $output_objdir/$my_dlsyms\"\n\n\t$opt_dry_run || $ECHO > \"$output_objdir/$my_dlsyms\" \"\\\n/* $my_dlsyms - symbol resolution table for '$my_outputname' dlsym emulation. */\n/* Generated by $PROGRAM (GNU $PACKAGE) $VERSION */\n\n#ifdef __cplusplus\nextern \\\"C\\\" {\n#endif\n\n#if defined __GNUC__ && (((__GNUC__ == 4) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ > 4))\n#pragma GCC diagnostic ignored \\\"-Wstrict-prototypes\\\"\n#endif\n\n/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests.  */\n#if defined _WIN32 || defined __CYGWIN__ || defined _WIN32_WCE\n/* DATA imports from DLLs on WIN32 can't be const, because runtime\n   relocations are performed -- see ld's documentation on pseudo-relocs.  */\n# define LT_DLSYM_CONST\n#elif defined __osf__\n/* This system does not cope well with relocations in const data.  */\n# define LT_DLSYM_CONST\n#else\n# define LT_DLSYM_CONST const\n#endif\n\n#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)\n\n/* External symbol declarations for the compiler. */\\\n\"\n\n\tif test yes = \"$dlself\"; then\n\t  func_verbose \"generating symbol list for '$output'\"\n\n\t  $opt_dry_run || echo ': @PROGRAM@ ' > \"$nlist\"\n\n\t  # Add our own program objects to the symbol list.\n\t  progfiles=`$ECHO \"$objs$old_deplibs\" | $SP2NL | $SED \"$lo2o\" | $NL2SP`\n\t  for progfile in $progfiles; do\n\t    func_to_tool_file \"$progfile\" func_convert_file_msys_to_w32\n\t    func_verbose \"extracting global C symbols from '$func_to_tool_file_result'\"\n\t    $opt_dry_run || eval \"$NM $func_to_tool_file_result | $global_symbol_pipe >> '$nlist'\"\n\t  done\n\n\t  if test -n \"$exclude_expsyms\"; then\n\t    $opt_dry_run || {\n\t      eval '$EGREP -v \" ($exclude_expsyms)$\" \"$nlist\" > \"$nlist\"T'\n\t      eval '$MV \"$nlist\"T \"$nlist\"'\n\t    }\n\t  fi\n\n\t  if test -n \"$export_symbols_regex\"; then\n\t    $opt_dry_run || {\n\t      eval '$EGREP -e \"$export_symbols_regex\" \"$nlist\" > \"$nlist\"T'\n\t      eval '$MV \"$nlist\"T \"$nlist\"'\n\t    }\n\t  fi\n\n\t  # Prepare the list of exported symbols\n\t  if test -z \"$export_symbols\"; then\n\t    export_symbols=$output_objdir/$outputname.exp\n\t    $opt_dry_run || {\n\t      $RM $export_symbols\n\t      eval \"$SED -n -e '/^: @PROGRAM@ $/d' -e 's/^.* \\(.*\\)$/\\1/p' \"'< \"$nlist\" > \"$export_symbols\"'\n\t      case $host in\n\t      *cygwin* | *mingw* | *cegcc* )\n                eval \"echo EXPORTS \"'> \"$output_objdir/$outputname.def\"'\n                eval 'cat \"$export_symbols\" >> \"$output_objdir/$outputname.def\"'\n\t        ;;\n\t      esac\n\t    }\n\t  else\n\t    $opt_dry_run || {\n\t      eval \"$SED -e 's/\\([].[*^$]\\)/\\\\\\\\\\1/g' -e 's/^/ /' -e 's/$/$/'\"' < \"$export_symbols\" > \"$output_objdir/$outputname.exp\"'\n\t      eval '$GREP -f \"$output_objdir/$outputname.exp\" < \"$nlist\" > \"$nlist\"T'\n\t      eval '$MV \"$nlist\"T \"$nlist\"'\n\t      case $host in\n\t        *cygwin* | *mingw* | *cegcc* )\n\t          eval \"echo EXPORTS \"'> \"$output_objdir/$outputname.def\"'\n\t          eval 'cat \"$nlist\" >> \"$output_objdir/$outputname.def\"'\n\t          ;;\n\t      esac\n\t    }\n\t  fi\n\tfi\n\n\tfor dlprefile in $dlprefiles; do\n\t  func_verbose \"extracting global C symbols from '$dlprefile'\"\n\t  func_basename \"$dlprefile\"\n\t  name=$func_basename_result\n          case $host in\n\t    *cygwin* | *mingw* | *cegcc* )\n\t      # if an import library, we need to obtain dlname\n\t      if func_win32_import_lib_p \"$dlprefile\"; then\n\t        func_tr_sh \"$dlprefile\"\n\t        eval \"curr_lafile=\\$libfile_$func_tr_sh_result\"\n\t        dlprefile_dlbasename=\n\t        if test -n \"$curr_lafile\" && func_lalib_p \"$curr_lafile\"; then\n\t          # Use subshell, to avoid clobbering current variable values\n\t          dlprefile_dlname=`source \"$curr_lafile\" && echo \"$dlname\"`\n\t          if test -n \"$dlprefile_dlname\"; then\n\t            func_basename \"$dlprefile_dlname\"\n\t            dlprefile_dlbasename=$func_basename_result\n\t          else\n\t            # no lafile. user explicitly requested -dlpreopen <import library>.\n\t            $sharedlib_from_linklib_cmd \"$dlprefile\"\n\t            dlprefile_dlbasename=$sharedlib_from_linklib_result\n\t          fi\n\t        fi\n\t        $opt_dry_run || {\n\t          if test -n \"$dlprefile_dlbasename\"; then\n\t            eval '$ECHO \": $dlprefile_dlbasename\" >> \"$nlist\"'\n\t          else\n\t            func_warning \"Could not compute DLL name from $name\"\n\t            eval '$ECHO \": $name \" >> \"$nlist\"'\n\t          fi\n\t          func_to_tool_file \"$dlprefile\" func_convert_file_msys_to_w32\n\t          eval \"$NM \\\"$func_to_tool_file_result\\\" 2>/dev/null | $global_symbol_pipe |\n\t            $SED -e '/I __imp/d' -e 's/I __nm_/D /;s/_nm__//' >> '$nlist'\"\n\t        }\n\t      else # not an import lib\n\t        $opt_dry_run || {\n\t          eval '$ECHO \": $name \" >> \"$nlist\"'\n\t          func_to_tool_file \"$dlprefile\" func_convert_file_msys_to_w32\n\t          eval \"$NM \\\"$func_to_tool_file_result\\\" 2>/dev/null | $global_symbol_pipe >> '$nlist'\"\n\t        }\n\t      fi\n\t    ;;\n\t    *)\n\t      $opt_dry_run || {\n\t        eval '$ECHO \": $name \" >> \"$nlist\"'\n\t        func_to_tool_file \"$dlprefile\" func_convert_file_msys_to_w32\n\t        eval \"$NM \\\"$func_to_tool_file_result\\\" 2>/dev/null | $global_symbol_pipe >> '$nlist'\"\n\t      }\n\t    ;;\n          esac\n\tdone\n\n\t$opt_dry_run || {\n\t  # Make sure we have at least an empty file.\n\t  test -f \"$nlist\" || : > \"$nlist\"\n\n\t  if test -n \"$exclude_expsyms\"; then\n\t    $EGREP -v \" ($exclude_expsyms)$\" \"$nlist\" > \"$nlist\"T\n\t    $MV \"$nlist\"T \"$nlist\"\n\t  fi\n\n\t  # Try sorting and uniquifying the output.\n\t  if $GREP -v \"^: \" < \"$nlist\" |\n\t      if sort -k 3 </dev/null >/dev/null 2>&1; then\n\t\tsort -k 3\n\t      else\n\t\tsort +2\n\t      fi |\n\t      uniq > \"$nlist\"S; then\n\t    :\n\t  else\n\t    $GREP -v \"^: \" < \"$nlist\" > \"$nlist\"S\n\t  fi\n\n\t  if test -f \"$nlist\"S; then\n\t    eval \"$global_symbol_to_cdecl\"' < \"$nlist\"S >> \"$output_objdir/$my_dlsyms\"'\n\t  else\n\t    echo '/* NONE */' >> \"$output_objdir/$my_dlsyms\"\n\t  fi\n\n\t  func_show_eval '$RM \"${nlist}I\"'\n\t  if test -n \"$global_symbol_to_import\"; then\n\t    eval \"$global_symbol_to_import\"' < \"$nlist\"S > \"$nlist\"I'\n\t  fi\n\n\t  echo >> \"$output_objdir/$my_dlsyms\" \"\\\n\n/* The mapping between symbol names and symbols.  */\ntypedef struct {\n  const char *name;\n  void *address;\n} lt_dlsymlist;\nextern LT_DLSYM_CONST lt_dlsymlist\nlt_${my_prefix}_LTX_preloaded_symbols[];\\\n\"\n\n\t  if test -s \"$nlist\"I; then\n\t    echo >> \"$output_objdir/$my_dlsyms\" \"\\\nstatic void lt_syminit(void)\n{\n  LT_DLSYM_CONST lt_dlsymlist *symbol = lt_${my_prefix}_LTX_preloaded_symbols;\n  for (; symbol->name; ++symbol)\n    {\"\n\t    $SED 's/.*/      if (STREQ (symbol->name, \\\"&\\\")) symbol->address = (void *) \\&&;/' < \"$nlist\"I >> \"$output_objdir/$my_dlsyms\"\n\t    echo >> \"$output_objdir/$my_dlsyms\" \"\\\n    }\n}\"\n\t  fi\n\t  echo >> \"$output_objdir/$my_dlsyms\" \"\\\nLT_DLSYM_CONST lt_dlsymlist\nlt_${my_prefix}_LTX_preloaded_symbols[] =\n{ {\\\"$my_originator\\\", (void *) 0},\"\n\n\t  if test -s \"$nlist\"I; then\n\t    echo >> \"$output_objdir/$my_dlsyms\" \"\\\n  {\\\"@INIT@\\\", (void *) &lt_syminit},\"\n\t  fi\n\n\t  case $need_lib_prefix in\n\t  no)\n\t    eval \"$global_symbol_to_c_name_address\" < \"$nlist\" >> \"$output_objdir/$my_dlsyms\"\n\t    ;;\n\t  *)\n\t    eval \"$global_symbol_to_c_name_address_lib_prefix\" < \"$nlist\" >> \"$output_objdir/$my_dlsyms\"\n\t    ;;\n\t  esac\n\t  echo >> \"$output_objdir/$my_dlsyms\" \"\\\n  {0, (void *) 0}\n};\n\n/* This works around a problem in FreeBSD linker */\n#ifdef FREEBSD_WORKAROUND\nstatic const void *lt_preloaded_setup() {\n  return lt_${my_prefix}_LTX_preloaded_symbols;\n}\n#endif\n\n#ifdef __cplusplus\n}\n#endif\\\n\"\n\t} # !$opt_dry_run\n\n\tpic_flag_for_symtable=\n\tcase \"$compile_command \" in\n\t*\" -static \"*) ;;\n\t*)\n\t  case $host in\n\t  # compiling the symbol table file with pic_flag works around\n\t  # a FreeBSD bug that causes programs to crash when -lm is\n\t  # linked before any other PIC object.  But we must not use\n\t  # pic_flag when linking with -static.  The problem exists in\n\t  # FreeBSD 2.2.6 and is fixed in FreeBSD 3.1.\n\t  *-*-freebsd2.*|*-*-freebsd3.0*|*-*-freebsdelf3.0*)\n\t    pic_flag_for_symtable=\" $pic_flag -DFREEBSD_WORKAROUND\" ;;\n\t  *-*-hpux*)\n\t    pic_flag_for_symtable=\" $pic_flag\"  ;;\n\t  *)\n\t    $my_pic_p && pic_flag_for_symtable=\" $pic_flag\"\n\t    ;;\n\t  esac\n\t  ;;\n\tesac\n\tsymtab_cflags=\n\tfor arg in $LTCFLAGS; do\n\t  case $arg in\n\t  -pie | -fpie | -fPIE) ;;\n\t  *) func_append symtab_cflags \" $arg\" ;;\n\t  esac\n\tdone\n\n\t# Now compile the dynamic symbol file.\n\tfunc_show_eval '(cd $output_objdir && $LTCC$symtab_cflags -c$no_builtin_flag$pic_flag_for_symtable \"$my_dlsyms\")' 'exit $?'\n\n\t# Clean up the generated files.\n\tfunc_show_eval '$RM \"$output_objdir/$my_dlsyms\" \"$nlist\" \"${nlist}S\" \"${nlist}T\" \"${nlist}I\"'\n\n\t# Transform the symbol file into the correct name.\n\tsymfileobj=$output_objdir/${my_outputname}S.$objext\n\tcase $host in\n\t*cygwin* | *mingw* | *cegcc* )\n\t  if test -f \"$output_objdir/$my_outputname.def\"; then\n\t    compile_command=`$ECHO \"$compile_command\" | $SED \"s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%\"`\n\t    finalize_command=`$ECHO \"$finalize_command\" | $SED \"s%@SYMFILE@%$output_objdir/$my_outputname.def $symfileobj%\"`\n\t  else\n\t    compile_command=`$ECHO \"$compile_command\" | $SED \"s%@SYMFILE@%$symfileobj%\"`\n\t    finalize_command=`$ECHO \"$finalize_command\" | $SED \"s%@SYMFILE@%$symfileobj%\"`\n\t  fi\n\t  ;;\n\t*)\n\t  compile_command=`$ECHO \"$compile_command\" | $SED \"s%@SYMFILE@%$symfileobj%\"`\n\t  finalize_command=`$ECHO \"$finalize_command\" | $SED \"s%@SYMFILE@%$symfileobj%\"`\n\t  ;;\n\tesac\n\t;;\n      *)\n\tfunc_fatal_error \"unknown suffix for '$my_dlsyms'\"\n\t;;\n      esac\n    else\n      # We keep going just in case the user didn't refer to\n      # lt_preloaded_symbols.  The linker will fail if global_symbol_pipe\n      # really was required.\n\n      # Nullify the symbol file.\n      compile_command=`$ECHO \"$compile_command\" | $SED \"s% @SYMFILE@%%\"`\n      finalize_command=`$ECHO \"$finalize_command\" | $SED \"s% @SYMFILE@%%\"`\n    fi\n}\n\n# func_cygming_gnu_implib_p ARG\n# This predicate returns with zero status (TRUE) if\n# ARG is a GNU/binutils-style import library. Returns\n# with nonzero status (FALSE) otherwise.\nfunc_cygming_gnu_implib_p ()\n{\n  $debug_cmd\n\n  func_to_tool_file \"$1\" func_convert_file_msys_to_w32\n  func_cygming_gnu_implib_tmp=`$NM \"$func_to_tool_file_result\" | eval \"$global_symbol_pipe\" | $EGREP ' (_head_[A-Za-z0-9_]+_[ad]l*|[A-Za-z0-9_]+_[ad]l*_iname)$'`\n  test -n \"$func_cygming_gnu_implib_tmp\"\n}\n\n# func_cygming_ms_implib_p ARG\n# This predicate returns with zero status (TRUE) if\n# ARG is an MS-style import library. Returns\n# with nonzero status (FALSE) otherwise.\nfunc_cygming_ms_implib_p ()\n{\n  $debug_cmd\n\n  func_to_tool_file \"$1\" func_convert_file_msys_to_w32\n  func_cygming_ms_implib_tmp=`$NM \"$func_to_tool_file_result\" | eval \"$global_symbol_pipe\" | $GREP '_NULL_IMPORT_DESCRIPTOR'`\n  test -n \"$func_cygming_ms_implib_tmp\"\n}\n\n# func_win32_libid arg\n# return the library type of file 'arg'\n#\n# Need a lot of goo to handle *both* DLLs and import libs\n# Has to be a shell function in order to 'eat' the argument\n# that is supplied when $file_magic_command is called.\n# Despite the name, also deal with 64 bit binaries.\nfunc_win32_libid ()\n{\n  $debug_cmd\n\n  win32_libid_type=unknown\n  win32_fileres=`file -L $1 2>/dev/null`\n  case $win32_fileres in\n  *ar\\ archive\\ import\\ library*) # definitely import\n    win32_libid_type=\"x86 archive import\"\n    ;;\n  *ar\\ archive*) # could be an import, or static\n    # Keep the egrep pattern in sync with the one in _LT_CHECK_MAGIC_METHOD.\n    if eval $OBJDUMP -f $1 | $SED -e '10q' 2>/dev/null |\n       $EGREP 'file format (pei*-i386(.*architecture: i386)?|pe-arm-wince|pe-x86-64)' >/dev/null; then\n      case $nm_interface in\n      \"MS dumpbin\")\n\tif func_cygming_ms_implib_p \"$1\" ||\n\t   func_cygming_gnu_implib_p \"$1\"\n\tthen\n\t  win32_nmres=import\n\telse\n\t  win32_nmres=\n\tfi\n\t;;\n      *)\n\tfunc_to_tool_file \"$1\" func_convert_file_msys_to_w32\n\twin32_nmres=`eval $NM -f posix -A \\\"$func_to_tool_file_result\\\" |\n\t  $SED -n -e '\n\t    1,100{\n\t\t/ I /{\n\t\t    s|.*|import|\n\t\t    p\n\t\t    q\n\t\t}\n\t    }'`\n\t;;\n      esac\n      case $win32_nmres in\n      import*)  win32_libid_type=\"x86 archive import\";;\n      *)        win32_libid_type=\"x86 archive static\";;\n      esac\n    fi\n    ;;\n  *DLL*)\n    win32_libid_type=\"x86 DLL\"\n    ;;\n  *executable*) # but shell scripts are \"executable\" too...\n    case $win32_fileres in\n    *MS\\ Windows\\ PE\\ Intel*)\n      win32_libid_type=\"x86 DLL\"\n      ;;\n    esac\n    ;;\n  esac\n  $ECHO \"$win32_libid_type\"\n}\n\n# func_cygming_dll_for_implib ARG\n#\n# Platform-specific function to extract the\n# name of the DLL associated with the specified\n# import library ARG.\n# Invoked by eval'ing the libtool variable\n#    $sharedlib_from_linklib_cmd\n# Result is available in the variable\n#    $sharedlib_from_linklib_result\nfunc_cygming_dll_for_implib ()\n{\n  $debug_cmd\n\n  sharedlib_from_linklib_result=`$DLLTOOL --identify-strict --identify \"$1\"`\n}\n\n# func_cygming_dll_for_implib_fallback_core SECTION_NAME LIBNAMEs\n#\n# The is the core of a fallback implementation of a\n# platform-specific function to extract the name of the\n# DLL associated with the specified import library LIBNAME.\n#\n# SECTION_NAME is either .idata$6 or .idata$7, depending\n# on the platform and compiler that created the implib.\n#\n# Echos the name of the DLL associated with the\n# specified import library.\nfunc_cygming_dll_for_implib_fallback_core ()\n{\n  $debug_cmd\n\n  match_literal=`$ECHO \"$1\" | $SED \"$sed_make_literal_regex\"`\n  $OBJDUMP -s --section \"$1\" \"$2\" 2>/dev/null |\n    $SED '/^Contents of section '\"$match_literal\"':/{\n      # Place marker at beginning of archive member dllname section\n      s/.*/====MARK====/\n      p\n      d\n    }\n    # These lines can sometimes be longer than 43 characters, but\n    # are always uninteresting\n    /:[\t ]*file format pe[i]\\{,1\\}-/d\n    /^In archive [^:]*:/d\n    # Ensure marker is printed\n    /^====MARK====/p\n    # Remove all lines with less than 43 characters\n    /^.\\{43\\}/!d\n    # From remaining lines, remove first 43 characters\n    s/^.\\{43\\}//' |\n    $SED -n '\n      # Join marker and all lines until next marker into a single line\n      /^====MARK====/ b para\n      H\n      $ b para\n      b\n      :para\n      x\n      s/\\n//g\n      # Remove the marker\n      s/^====MARK====//\n      # Remove trailing dots and whitespace\n      s/[\\. \\t]*$//\n      # Print\n      /./p' |\n    # we now have a list, one entry per line, of the stringified\n    # contents of the appropriate section of all members of the\n    # archive that possess that section. Heuristic: eliminate\n    # all those that have a first or second character that is\n    # a '.' (that is, objdump's representation of an unprintable\n    # character.) This should work for all archives with less than\n    # 0x302f exports -- but will fail for DLLs whose name actually\n    # begins with a literal '.' or a single character followed by\n    # a '.'.\n    #\n    # Of those that remain, print the first one.\n    $SED -e '/^\\./d;/^.\\./d;q'\n}\n\n# func_cygming_dll_for_implib_fallback ARG\n# Platform-specific function to extract the\n# name of the DLL associated with the specified\n# import library ARG.\n#\n# This fallback implementation is for use when $DLLTOOL\n# does not support the --identify-strict option.\n# Invoked by eval'ing the libtool variable\n#    $sharedlib_from_linklib_cmd\n# Result is available in the variable\n#    $sharedlib_from_linklib_result\nfunc_cygming_dll_for_implib_fallback ()\n{\n  $debug_cmd\n\n  if func_cygming_gnu_implib_p \"$1\"; then\n    # binutils import library\n    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$7' \"$1\"`\n  elif func_cygming_ms_implib_p \"$1\"; then\n    # ms-generated import library\n    sharedlib_from_linklib_result=`func_cygming_dll_for_implib_fallback_core '.idata$6' \"$1\"`\n  else\n    # unknown\n    sharedlib_from_linklib_result=\n  fi\n}\n\n\n# func_extract_an_archive dir oldlib\nfunc_extract_an_archive ()\n{\n    $debug_cmd\n\n    f_ex_an_ar_dir=$1; shift\n    f_ex_an_ar_oldlib=$1\n    if test yes = \"$lock_old_archive_extraction\"; then\n      lockfile=$f_ex_an_ar_oldlib.lock\n      until $opt_dry_run || ln \"$progpath\" \"$lockfile\" 2>/dev/null; do\n\tfunc_echo \"Waiting for $lockfile to be removed\"\n\tsleep 2\n      done\n    fi\n    func_show_eval \"(cd \\$f_ex_an_ar_dir && $AR x \\\"\\$f_ex_an_ar_oldlib\\\")\" \\\n\t\t   'stat=$?; rm -f \"$lockfile\"; exit $stat'\n    if test yes = \"$lock_old_archive_extraction\"; then\n      $opt_dry_run || rm -f \"$lockfile\"\n    fi\n    if ($AR t \"$f_ex_an_ar_oldlib\" | sort | sort -uc >/dev/null 2>&1); then\n     :\n    else\n      func_fatal_error \"object name conflicts in archive: $f_ex_an_ar_dir/$f_ex_an_ar_oldlib\"\n    fi\n}\n\n\n# func_extract_archives gentop oldlib ...\nfunc_extract_archives ()\n{\n    $debug_cmd\n\n    my_gentop=$1; shift\n    my_oldlibs=${1+\"$@\"}\n    my_oldobjs=\n    my_xlib=\n    my_xabs=\n    my_xdir=\n\n    for my_xlib in $my_oldlibs; do\n      # Extract the objects.\n      case $my_xlib in\n\t[\\\\/]* | [A-Za-z]:[\\\\/]*) my_xabs=$my_xlib ;;\n\t*) my_xabs=`pwd`\"/$my_xlib\" ;;\n      esac\n      func_basename \"$my_xlib\"\n      my_xlib=$func_basename_result\n      my_xlib_u=$my_xlib\n      while :; do\n        case \" $extracted_archives \" in\n\t*\" $my_xlib_u \"*)\n\t  func_arith $extracted_serial + 1\n\t  extracted_serial=$func_arith_result\n\t  my_xlib_u=lt$extracted_serial-$my_xlib ;;\n\t*) break ;;\n\tesac\n      done\n      extracted_archives=\"$extracted_archives $my_xlib_u\"\n      my_xdir=$my_gentop/$my_xlib_u\n\n      func_mkdir_p \"$my_xdir\"\n\n      case $host in\n      *-darwin*)\n\tfunc_verbose \"Extracting $my_xabs\"\n\t# Do not bother doing anything if just a dry run\n\t$opt_dry_run || {\n\t  darwin_orig_dir=`pwd`\n\t  cd $my_xdir || exit $?\n\t  darwin_archive=$my_xabs\n\t  darwin_curdir=`pwd`\n\t  func_basename \"$darwin_archive\"\n\t  darwin_base_archive=$func_basename_result\n\t  darwin_arches=`$LIPO -info \"$darwin_archive\" 2>/dev/null | $GREP Architectures 2>/dev/null || true`\n\t  if test -n \"$darwin_arches\"; then\n\t    darwin_arches=`$ECHO \"$darwin_arches\" | $SED -e 's/.*are://'`\n\t    darwin_arch=\n\t    func_verbose \"$darwin_base_archive has multiple architectures $darwin_arches\"\n\t    for darwin_arch in  $darwin_arches; do\n\t      func_mkdir_p \"unfat-$$/$darwin_base_archive-$darwin_arch\"\n\t      $LIPO -thin $darwin_arch -output \"unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive\" \"$darwin_archive\"\n\t      cd \"unfat-$$/$darwin_base_archive-$darwin_arch\"\n\t      func_extract_an_archive \"`pwd`\" \"$darwin_base_archive\"\n\t      cd \"$darwin_curdir\"\n\t      $RM \"unfat-$$/$darwin_base_archive-$darwin_arch/$darwin_base_archive\"\n\t    done # $darwin_arches\n            ## Okay now we've a bunch of thin objects, gotta fatten them up :)\n\t    darwin_filelist=`find unfat-$$ -type f -name \\*.o -print -o -name \\*.lo -print | $SED -e \"$sed_basename\" | sort -u`\n\t    darwin_file=\n\t    darwin_files=\n\t    for darwin_file in $darwin_filelist; do\n\t      darwin_files=`find unfat-$$ -name $darwin_file -print | sort | $NL2SP`\n\t      $LIPO -create -output \"$darwin_file\" $darwin_files\n\t    done # $darwin_filelist\n\t    $RM -rf unfat-$$\n\t    cd \"$darwin_orig_dir\"\n\t  else\n\t    cd $darwin_orig_dir\n\t    func_extract_an_archive \"$my_xdir\" \"$my_xabs\"\n\t  fi # $darwin_arches\n\t} # !$opt_dry_run\n\t;;\n      *)\n        func_extract_an_archive \"$my_xdir\" \"$my_xabs\"\n\t;;\n      esac\n      my_oldobjs=\"$my_oldobjs \"`find $my_xdir -name \\*.$objext -print -o -name \\*.lo -print | sort | $NL2SP`\n    done\n\n    func_extract_archives_result=$my_oldobjs\n}\n\n\n# func_emit_wrapper [arg=no]\n#\n# Emit a libtool wrapper script on stdout.\n# Don't directly open a file because we may want to\n# incorporate the script contents within a cygwin/mingw\n# wrapper executable.  Must ONLY be called from within\n# func_mode_link because it depends on a number of variables\n# set therein.\n#\n# ARG is the value that the WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\n# variable will take.  If 'yes', then the emitted script\n# will assume that the directory where it is stored is\n# the $objdir directory.  This is a cygwin/mingw-specific\n# behavior.\nfunc_emit_wrapper ()\n{\n\tfunc_emit_wrapper_arg1=${1-no}\n\n\t$ECHO \"\\\n#! $SHELL\n\n# $output - temporary wrapper script for $objdir/$outputname\n# Generated by $PROGRAM (GNU $PACKAGE) $VERSION\n#\n# The $output program cannot be directly executed until all the libtool\n# libraries that it depends on are installed.\n#\n# This wrapper script should never be moved out of the build directory.\n# If it is, it will not operate correctly.\n\n# Sed substitution that helps us do robust quoting.  It backslashifies\n# metacharacters that are still active within double-quoted strings.\nsed_quote_subst='$sed_quote_subst'\n\n# Be Bourne compatible\nif test -n \\\"\\${ZSH_VERSION+set}\\\" && (emulate sh) >/dev/null 2>&1; then\n  emulate sh\n  NULLCMD=:\n  # Zsh 3.x and 4.x performs word splitting on \\${1+\\\"\\$@\\\"}, which\n  # is contrary to our usage.  Disable this feature.\n  alias -g '\\${1+\\\"\\$@\\\"}'='\\\"\\$@\\\"'\n  setopt NO_GLOB_SUBST\nelse\n  case \\`(set -o) 2>/dev/null\\` in *posix*) set -o posix;; esac\nfi\nBIN_SH=xpg4; export BIN_SH # for Tru64\nDUALCASE=1; export DUALCASE # for MKS sh\n\n# The HP-UX ksh and POSIX shell print the target directory to stdout\n# if CDPATH is set.\n(unset CDPATH) >/dev/null 2>&1 && unset CDPATH\n\nrelink_command=\\\"$relink_command\\\"\n\n# This environment variable determines our operation mode.\nif test \\\"\\$libtool_install_magic\\\" = \\\"$magic\\\"; then\n  # install mode needs the following variables:\n  generated_by_libtool_version='$macro_version'\n  notinst_deplibs='$notinst_deplibs'\nelse\n  # When we are sourced in execute mode, \\$file and \\$ECHO are already set.\n  if test \\\"\\$libtool_execute_magic\\\" != \\\"$magic\\\"; then\n    file=\\\"\\$0\\\"\"\n\n    qECHO=`$ECHO \"$ECHO\" | $SED \"$sed_quote_subst\"`\n    $ECHO \"\\\n\n# A function that is used when there is no print builtin or printf.\nfunc_fallback_echo ()\n{\n  eval 'cat <<_LTECHO_EOF\n\\$1\n_LTECHO_EOF'\n}\n    ECHO=\\\"$qECHO\\\"\n  fi\n\n# Very basic option parsing. These options are (a) specific to\n# the libtool wrapper, (b) are identical between the wrapper\n# /script/ and the wrapper /executable/ that is used only on\n# windows platforms, and (c) all begin with the string \"--lt-\"\n# (application programs are unlikely to have options that match\n# this pattern).\n#\n# There are only two supported options: --lt-debug and\n# --lt-dump-script. There is, deliberately, no --lt-help.\n#\n# The first argument to this parsing function should be the\n# script's $0 value, followed by \"$@\".\nlt_option_debug=\nfunc_parse_lt_options ()\n{\n  lt_script_arg0=\\$0\n  shift\n  for lt_opt\n  do\n    case \\\"\\$lt_opt\\\" in\n    --lt-debug) lt_option_debug=1 ;;\n    --lt-dump-script)\n        lt_dump_D=\\`\\$ECHO \\\"X\\$lt_script_arg0\\\" | $SED -e 's/^X//' -e 's%/[^/]*$%%'\\`\n        test \\\"X\\$lt_dump_D\\\" = \\\"X\\$lt_script_arg0\\\" && lt_dump_D=.\n        lt_dump_F=\\`\\$ECHO \\\"X\\$lt_script_arg0\\\" | $SED -e 's/^X//' -e 's%^.*/%%'\\`\n        cat \\\"\\$lt_dump_D/\\$lt_dump_F\\\"\n        exit 0\n      ;;\n    --lt-*)\n        \\$ECHO \\\"Unrecognized --lt- option: '\\$lt_opt'\\\" 1>&2\n        exit 1\n      ;;\n    esac\n  done\n\n  # Print the debug banner immediately:\n  if test -n \\\"\\$lt_option_debug\\\"; then\n    echo \\\"$outputname:$output:\\$LINENO: libtool wrapper (GNU $PACKAGE) $VERSION\\\" 1>&2\n  fi\n}\n\n# Used when --lt-debug. Prints its arguments to stdout\n# (redirection is the responsibility of the caller)\nfunc_lt_dump_args ()\n{\n  lt_dump_args_N=1;\n  for lt_arg\n  do\n    \\$ECHO \\\"$outputname:$output:\\$LINENO: newargv[\\$lt_dump_args_N]: \\$lt_arg\\\"\n    lt_dump_args_N=\\`expr \\$lt_dump_args_N + 1\\`\n  done\n}\n\n# Core function for launching the target application\nfunc_exec_program_core ()\n{\n\"\n  case $host in\n  # Backslashes separate directories on plain windows\n  *-*-mingw | *-*-os2* | *-cegcc*)\n    $ECHO \"\\\n      if test -n \\\"\\$lt_option_debug\\\"; then\n        \\$ECHO \\\"$outputname:$output:\\$LINENO: newargv[0]: \\$progdir\\\\\\\\\\$program\\\" 1>&2\n        func_lt_dump_args \\${1+\\\"\\$@\\\"} 1>&2\n      fi\n      exec \\\"\\$progdir\\\\\\\\\\$program\\\" \\${1+\\\"\\$@\\\"}\n\"\n    ;;\n\n  *)\n    $ECHO \"\\\n      if test -n \\\"\\$lt_option_debug\\\"; then\n        \\$ECHO \\\"$outputname:$output:\\$LINENO: newargv[0]: \\$progdir/\\$program\\\" 1>&2\n        func_lt_dump_args \\${1+\\\"\\$@\\\"} 1>&2\n      fi\n      exec \\\"\\$progdir/\\$program\\\" \\${1+\\\"\\$@\\\"}\n\"\n    ;;\n  esac\n  $ECHO \"\\\n      \\$ECHO \\\"\\$0: cannot exec \\$program \\$*\\\" 1>&2\n      exit 1\n}\n\n# A function to encapsulate launching the target application\n# Strips options in the --lt-* namespace from \\$@ and\n# launches target application with the remaining arguments.\nfunc_exec_program ()\n{\n  case \\\" \\$* \\\" in\n  *\\\\ --lt-*)\n    for lt_wr_arg\n    do\n      case \\$lt_wr_arg in\n      --lt-*) ;;\n      *) set x \\\"\\$@\\\" \\\"\\$lt_wr_arg\\\"; shift;;\n      esac\n      shift\n    done ;;\n  esac\n  func_exec_program_core \\${1+\\\"\\$@\\\"}\n}\n\n  # Parse options\n  func_parse_lt_options \\\"\\$0\\\" \\${1+\\\"\\$@\\\"}\n\n  # Find the directory that this script lives in.\n  thisdir=\\`\\$ECHO \\\"\\$file\\\" | $SED 's%/[^/]*$%%'\\`\n  test \\\"x\\$thisdir\\\" = \\\"x\\$file\\\" && thisdir=.\n\n  # Follow symbolic links until we get to the real thisdir.\n  file=\\`ls -ld \\\"\\$file\\\" | $SED -n 's/.*-> //p'\\`\n  while test -n \\\"\\$file\\\"; do\n    destdir=\\`\\$ECHO \\\"\\$file\\\" | $SED 's%/[^/]*\\$%%'\\`\n\n    # If there was a directory component, then change thisdir.\n    if test \\\"x\\$destdir\\\" != \\\"x\\$file\\\"; then\n      case \\\"\\$destdir\\\" in\n      [\\\\\\\\/]* | [A-Za-z]:[\\\\\\\\/]*) thisdir=\\\"\\$destdir\\\" ;;\n      *) thisdir=\\\"\\$thisdir/\\$destdir\\\" ;;\n      esac\n    fi\n\n    file=\\`\\$ECHO \\\"\\$file\\\" | $SED 's%^.*/%%'\\`\n    file=\\`ls -ld \\\"\\$thisdir/\\$file\\\" | $SED -n 's/.*-> //p'\\`\n  done\n\n  # Usually 'no', except on cygwin/mingw when embedded into\n  # the cwrapper.\n  WRAPPER_SCRIPT_BELONGS_IN_OBJDIR=$func_emit_wrapper_arg1\n  if test \\\"\\$WRAPPER_SCRIPT_BELONGS_IN_OBJDIR\\\" = \\\"yes\\\"; then\n    # special case for '.'\n    if test \\\"\\$thisdir\\\" = \\\".\\\"; then\n      thisdir=\\`pwd\\`\n    fi\n    # remove .libs from thisdir\n    case \\\"\\$thisdir\\\" in\n    *[\\\\\\\\/]$objdir ) thisdir=\\`\\$ECHO \\\"\\$thisdir\\\" | $SED 's%[\\\\\\\\/][^\\\\\\\\/]*$%%'\\` ;;\n    $objdir )   thisdir=. ;;\n    esac\n  fi\n\n  # Try to get the absolute directory name.\n  absdir=\\`cd \\\"\\$thisdir\\\" && pwd\\`\n  test -n \\\"\\$absdir\\\" && thisdir=\\\"\\$absdir\\\"\n\"\n\n\tif test yes = \"$fast_install\"; then\n\t  $ECHO \"\\\n  program=lt-'$outputname'$exeext\n  progdir=\\\"\\$thisdir/$objdir\\\"\n\n  if test ! -f \\\"\\$progdir/\\$program\\\" ||\n     { file=\\`ls -1dt \\\"\\$progdir/\\$program\\\" \\\"\\$progdir/../\\$program\\\" 2>/dev/null | $SED 1q\\`; \\\\\n       test \\\"X\\$file\\\" != \\\"X\\$progdir/\\$program\\\"; }; then\n\n    file=\\\"\\$\\$-\\$program\\\"\n\n    if test ! -d \\\"\\$progdir\\\"; then\n      $MKDIR \\\"\\$progdir\\\"\n    else\n      $RM \\\"\\$progdir/\\$file\\\"\n    fi\"\n\n\t  $ECHO \"\\\n\n    # relink executable if necessary\n    if test -n \\\"\\$relink_command\\\"; then\n      if relink_command_output=\\`eval \\$relink_command 2>&1\\`; then :\n      else\n\t\\$ECHO \\\"\\$relink_command_output\\\" >&2\n\t$RM \\\"\\$progdir/\\$file\\\"\n\texit 1\n      fi\n    fi\n\n    $MV \\\"\\$progdir/\\$file\\\" \\\"\\$progdir/\\$program\\\" 2>/dev/null ||\n    { $RM \\\"\\$progdir/\\$program\\\";\n      $MV \\\"\\$progdir/\\$file\\\" \\\"\\$progdir/\\$program\\\"; }\n    $RM \\\"\\$progdir/\\$file\\\"\n  fi\"\n\telse\n\t  $ECHO \"\\\n  program='$outputname'\n  progdir=\\\"\\$thisdir/$objdir\\\"\n\"\n\tfi\n\n\t$ECHO \"\\\n\n  if test -f \\\"\\$progdir/\\$program\\\"; then\"\n\n\t# fixup the dll searchpath if we need to.\n\t#\n\t# Fix the DLL searchpath if we need to.  Do this before prepending\n\t# to shlibpath, because on Windows, both are PATH and uninstalled\n\t# libraries must come first.\n\tif test -n \"$dllsearchpath\"; then\n\t  $ECHO \"\\\n    # Add the dll search path components to the executable PATH\n    PATH=$dllsearchpath:\\$PATH\n\"\n\tfi\n\n\t# Export our shlibpath_var if we have one.\n\tif test yes = \"$shlibpath_overrides_runpath\" && test -n \"$shlibpath_var\" && test -n \"$temp_rpath\"; then\n\t  $ECHO \"\\\n    # Add our own library path to $shlibpath_var\n    $shlibpath_var=\\\"$temp_rpath\\$$shlibpath_var\\\"\n\n    # Some systems cannot cope with colon-terminated $shlibpath_var\n    # The second colon is a workaround for a bug in BeOS R4 sed\n    $shlibpath_var=\\`\\$ECHO \\\"\\$$shlibpath_var\\\" | $SED 's/::*\\$//'\\`\n\n    export $shlibpath_var\n\"\n\tfi\n\n\t$ECHO \"\\\n    if test \\\"\\$libtool_execute_magic\\\" != \\\"$magic\\\"; then\n      # Run the actual program with our arguments.\n      func_exec_program \\${1+\\\"\\$@\\\"}\n    fi\n  else\n    # The program doesn't exist.\n    \\$ECHO \\\"\\$0: error: '\\$progdir/\\$program' does not exist\\\" 1>&2\n    \\$ECHO \\\"This script is just a wrapper for \\$program.\\\" 1>&2\n    \\$ECHO \\\"See the $PACKAGE documentation for more information.\\\" 1>&2\n    exit 1\n  fi\nfi\\\n\"\n}\n\n\n# func_emit_cwrapperexe_src\n# emit the source code for a wrapper executable on stdout\n# Must ONLY be called from within func_mode_link because\n# it depends on a number of variable set therein.\nfunc_emit_cwrapperexe_src ()\n{\n\tcat <<EOF\n\n/* $cwrappersource - temporary wrapper executable for $objdir/$outputname\n   Generated by $PROGRAM (GNU $PACKAGE) $VERSION\n\n   The $output program cannot be directly executed until all the libtool\n   libraries that it depends on are installed.\n\n   This wrapper executable should never be moved out of the build directory.\n   If it is, it will not operate correctly.\n*/\nEOF\n\t    cat <<\"EOF\"\n#ifdef _MSC_VER\n# define _CRT_SECURE_NO_DEPRECATE 1\n#endif\n#include <stdio.h>\n#include <stdlib.h>\n#ifdef _MSC_VER\n# include <direct.h>\n# include <process.h>\n# include <io.h>\n#else\n# include <unistd.h>\n# include <stdint.h>\n# ifdef __CYGWIN__\n#  include <io.h>\n# endif\n#endif\n#include <malloc.h>\n#include <stdarg.h>\n#include <assert.h>\n#include <string.h>\n#include <ctype.h>\n#include <errno.h>\n#include <fcntl.h>\n#include <sys/stat.h>\n\n#define STREQ(s1, s2) (strcmp ((s1), (s2)) == 0)\n\n/* declarations of non-ANSI functions */\n#if defined __MINGW32__\n# ifdef __STRICT_ANSI__\nint _putenv (const char *);\n# endif\n#elif defined __CYGWIN__\n# ifdef __STRICT_ANSI__\nchar *realpath (const char *, char *);\nint putenv (char *);\nint setenv (const char *, const char *, int);\n# endif\n/* #elif defined other_platform || defined ... */\n#endif\n\n/* portability defines, excluding path handling macros */\n#if defined _MSC_VER\n# define setmode _setmode\n# define stat    _stat\n# define chmod   _chmod\n# define getcwd  _getcwd\n# define putenv  _putenv\n# define S_IXUSR _S_IEXEC\n#elif defined __MINGW32__\n# define setmode _setmode\n# define stat    _stat\n# define chmod   _chmod\n# define getcwd  _getcwd\n# define putenv  _putenv\n#elif defined __CYGWIN__\n# define HAVE_SETENV\n# define FOPEN_WB \"wb\"\n/* #elif defined other platforms ... */\n#endif\n\n#if defined PATH_MAX\n# define LT_PATHMAX PATH_MAX\n#elif defined MAXPATHLEN\n# define LT_PATHMAX MAXPATHLEN\n#else\n# define LT_PATHMAX 1024\n#endif\n\n#ifndef S_IXOTH\n# define S_IXOTH 0\n#endif\n#ifndef S_IXGRP\n# define S_IXGRP 0\n#endif\n\n/* path handling portability macros */\n#ifndef DIR_SEPARATOR\n# define DIR_SEPARATOR '/'\n# define PATH_SEPARATOR ':'\n#endif\n\n#if defined _WIN32 || defined __MSDOS__ || defined __DJGPP__ || \\\n  defined __OS2__\n# define HAVE_DOS_BASED_FILE_SYSTEM\n# define FOPEN_WB \"wb\"\n# ifndef DIR_SEPARATOR_2\n#  define DIR_SEPARATOR_2 '\\\\'\n# endif\n# ifndef PATH_SEPARATOR_2\n#  define PATH_SEPARATOR_2 ';'\n# endif\n#endif\n\n#ifndef DIR_SEPARATOR_2\n# define IS_DIR_SEPARATOR(ch) ((ch) == DIR_SEPARATOR)\n#else /* DIR_SEPARATOR_2 */\n# define IS_DIR_SEPARATOR(ch) \\\n\t(((ch) == DIR_SEPARATOR) || ((ch) == DIR_SEPARATOR_2))\n#endif /* DIR_SEPARATOR_2 */\n\n#ifndef PATH_SEPARATOR_2\n# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR)\n#else /* PATH_SEPARATOR_2 */\n# define IS_PATH_SEPARATOR(ch) ((ch) == PATH_SEPARATOR_2)\n#endif /* PATH_SEPARATOR_2 */\n\n#ifndef FOPEN_WB\n# define FOPEN_WB \"w\"\n#endif\n#ifndef _O_BINARY\n# define _O_BINARY 0\n#endif\n\n#define XMALLOC(type, num)      ((type *) xmalloc ((num) * sizeof(type)))\n#define XFREE(stale) do { \\\n  if (stale) { free (stale); stale = 0; } \\\n} while (0)\n\n#if defined LT_DEBUGWRAPPER\nstatic int lt_debug = 1;\n#else\nstatic int lt_debug = 0;\n#endif\n\nconst char *program_name = \"libtool-wrapper\"; /* in case xstrdup fails */\n\nvoid *xmalloc (size_t num);\nchar *xstrdup (const char *string);\nconst char *base_name (const char *name);\nchar *find_executable (const char *wrapper);\nchar *chase_symlinks (const char *pathspec);\nint make_executable (const char *path);\nint check_executable (const char *path);\nchar *strendzap (char *str, const char *pat);\nvoid lt_debugprintf (const char *file, int line, const char *fmt, ...);\nvoid lt_fatal (const char *file, int line, const char *message, ...);\nstatic const char *nonnull (const char *s);\nstatic const char *nonempty (const char *s);\nvoid lt_setenv (const char *name, const char *value);\nchar *lt_extend_str (const char *orig_value, const char *add, int to_end);\nvoid lt_update_exe_path (const char *name, const char *value);\nvoid lt_update_lib_path (const char *name, const char *value);\nchar **prepare_spawn (char **argv);\nvoid lt_dump_script (FILE *f);\nEOF\n\n\t    cat <<EOF\n#if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 5)\n# define externally_visible volatile\n#else\n# define externally_visible __attribute__((externally_visible)) volatile\n#endif\nexternally_visible const char * MAGIC_EXE = \"$magic_exe\";\nconst char * LIB_PATH_VARNAME = \"$shlibpath_var\";\nEOF\n\n\t    if test yes = \"$shlibpath_overrides_runpath\" && test -n \"$shlibpath_var\" && test -n \"$temp_rpath\"; then\n              func_to_host_path \"$temp_rpath\"\n\t      cat <<EOF\nconst char * LIB_PATH_VALUE   = \"$func_to_host_path_result\";\nEOF\n\t    else\n\t      cat <<\"EOF\"\nconst char * LIB_PATH_VALUE   = \"\";\nEOF\n\t    fi\n\n\t    if test -n \"$dllsearchpath\"; then\n              func_to_host_path \"$dllsearchpath:\"\n\t      cat <<EOF\nconst char * EXE_PATH_VARNAME = \"PATH\";\nconst char * EXE_PATH_VALUE   = \"$func_to_host_path_result\";\nEOF\n\t    else\n\t      cat <<\"EOF\"\nconst char * EXE_PATH_VARNAME = \"\";\nconst char * EXE_PATH_VALUE   = \"\";\nEOF\n\t    fi\n\n\t    if test yes = \"$fast_install\"; then\n\t      cat <<EOF\nconst char * TARGET_PROGRAM_NAME = \"lt-$outputname\"; /* hopefully, no .exe */\nEOF\n\t    else\n\t      cat <<EOF\nconst char * TARGET_PROGRAM_NAME = \"$outputname\"; /* hopefully, no .exe */\nEOF\n\t    fi\n\n\n\t    cat <<\"EOF\"\n\n#define LTWRAPPER_OPTION_PREFIX         \"--lt-\"\n\nstatic const char *ltwrapper_option_prefix = LTWRAPPER_OPTION_PREFIX;\nstatic const char *dumpscript_opt       = LTWRAPPER_OPTION_PREFIX \"dump-script\";\nstatic const char *debug_opt            = LTWRAPPER_OPTION_PREFIX \"debug\";\n\nint\nmain (int argc, char *argv[])\n{\n  char **newargz;\n  int  newargc;\n  char *tmp_pathspec;\n  char *actual_cwrapper_path;\n  char *actual_cwrapper_name;\n  char *target_name;\n  char *lt_argv_zero;\n  int rval = 127;\n\n  int i;\n\n  program_name = (char *) xstrdup (base_name (argv[0]));\n  newargz = XMALLOC (char *, (size_t) argc + 1);\n\n  /* very simple arg parsing; don't want to rely on getopt\n   * also, copy all non cwrapper options to newargz, except\n   * argz[0], which is handled differently\n   */\n  newargc=0;\n  for (i = 1; i < argc; i++)\n    {\n      if (STREQ (argv[i], dumpscript_opt))\n\t{\nEOF\n\t    case $host in\n\t      *mingw* | *cygwin* )\n\t\t# make stdout use \"unix\" line endings\n\t\techo \"          setmode(1,_O_BINARY);\"\n\t\t;;\n\t      esac\n\n\t    cat <<\"EOF\"\n\t  lt_dump_script (stdout);\n\t  return 0;\n\t}\n      if (STREQ (argv[i], debug_opt))\n\t{\n          lt_debug = 1;\n          continue;\n\t}\n      if (STREQ (argv[i], ltwrapper_option_prefix))\n        {\n          /* however, if there is an option in the LTWRAPPER_OPTION_PREFIX\n             namespace, but it is not one of the ones we know about and\n             have already dealt with, above (inluding dump-script), then\n             report an error. Otherwise, targets might begin to believe\n             they are allowed to use options in the LTWRAPPER_OPTION_PREFIX\n             namespace. The first time any user complains about this, we'll\n             need to make LTWRAPPER_OPTION_PREFIX a configure-time option\n             or a configure.ac-settable value.\n           */\n          lt_fatal (__FILE__, __LINE__,\n\t\t    \"unrecognized %s option: '%s'\",\n                    ltwrapper_option_prefix, argv[i]);\n        }\n      /* otherwise ... */\n      newargz[++newargc] = xstrdup (argv[i]);\n    }\n  newargz[++newargc] = NULL;\n\nEOF\n\t    cat <<EOF\n  /* The GNU banner must be the first non-error debug message */\n  lt_debugprintf (__FILE__, __LINE__, \"libtool wrapper (GNU $PACKAGE) $VERSION\\n\");\nEOF\n\t    cat <<\"EOF\"\n  lt_debugprintf (__FILE__, __LINE__, \"(main) argv[0]: %s\\n\", argv[0]);\n  lt_debugprintf (__FILE__, __LINE__, \"(main) program_name: %s\\n\", program_name);\n\n  tmp_pathspec = find_executable (argv[0]);\n  if (tmp_pathspec == NULL)\n    lt_fatal (__FILE__, __LINE__, \"couldn't find %s\", argv[0]);\n  lt_debugprintf (__FILE__, __LINE__,\n                  \"(main) found exe (before symlink chase) at: %s\\n\",\n\t\t  tmp_pathspec);\n\n  actual_cwrapper_path = chase_symlinks (tmp_pathspec);\n  lt_debugprintf (__FILE__, __LINE__,\n                  \"(main) found exe (after symlink chase) at: %s\\n\",\n\t\t  actual_cwrapper_path);\n  XFREE (tmp_pathspec);\n\n  actual_cwrapper_name = xstrdup (base_name (actual_cwrapper_path));\n  strendzap (actual_cwrapper_path, actual_cwrapper_name);\n\n  /* wrapper name transforms */\n  strendzap (actual_cwrapper_name, \".exe\");\n  tmp_pathspec = lt_extend_str (actual_cwrapper_name, \".exe\", 1);\n  XFREE (actual_cwrapper_name);\n  actual_cwrapper_name = tmp_pathspec;\n  tmp_pathspec = 0;\n\n  /* target_name transforms -- use actual target program name; might have lt- prefix */\n  target_name = xstrdup (base_name (TARGET_PROGRAM_NAME));\n  strendzap (target_name, \".exe\");\n  tmp_pathspec = lt_extend_str (target_name, \".exe\", 1);\n  XFREE (target_name);\n  target_name = tmp_pathspec;\n  tmp_pathspec = 0;\n\n  lt_debugprintf (__FILE__, __LINE__,\n\t\t  \"(main) libtool target name: %s\\n\",\n\t\t  target_name);\nEOF\n\n\t    cat <<EOF\n  newargz[0] =\n    XMALLOC (char, (strlen (actual_cwrapper_path) +\n\t\t    strlen (\"$objdir\") + 1 + strlen (actual_cwrapper_name) + 1));\n  strcpy (newargz[0], actual_cwrapper_path);\n  strcat (newargz[0], \"$objdir\");\n  strcat (newargz[0], \"/\");\nEOF\n\n\t    cat <<\"EOF\"\n  /* stop here, and copy so we don't have to do this twice */\n  tmp_pathspec = xstrdup (newargz[0]);\n\n  /* do NOT want the lt- prefix here, so use actual_cwrapper_name */\n  strcat (newargz[0], actual_cwrapper_name);\n\n  /* DO want the lt- prefix here if it exists, so use target_name */\n  lt_argv_zero = lt_extend_str (tmp_pathspec, target_name, 1);\n  XFREE (tmp_pathspec);\n  tmp_pathspec = NULL;\nEOF\n\n\t    case $host_os in\n\t      mingw*)\n\t    cat <<\"EOF\"\n  {\n    char* p;\n    while ((p = strchr (newargz[0], '\\\\')) != NULL)\n      {\n\t*p = '/';\n      }\n    while ((p = strchr (lt_argv_zero, '\\\\')) != NULL)\n      {\n\t*p = '/';\n      }\n  }\nEOF\n\t    ;;\n\t    esac\n\n\t    cat <<\"EOF\"\n  XFREE (target_name);\n  XFREE (actual_cwrapper_path);\n  XFREE (actual_cwrapper_name);\n\n  lt_setenv (\"BIN_SH\", \"xpg4\"); /* for Tru64 */\n  lt_setenv (\"DUALCASE\", \"1\");  /* for MSK sh */\n  /* Update the DLL searchpath.  EXE_PATH_VALUE ($dllsearchpath) must\n     be prepended before (that is, appear after) LIB_PATH_VALUE ($temp_rpath)\n     because on Windows, both *_VARNAMEs are PATH but uninstalled\n     libraries must come first. */\n  lt_update_exe_path (EXE_PATH_VARNAME, EXE_PATH_VALUE);\n  lt_update_lib_path (LIB_PATH_VARNAME, LIB_PATH_VALUE);\n\n  lt_debugprintf (__FILE__, __LINE__, \"(main) lt_argv_zero: %s\\n\",\n\t\t  nonnull (lt_argv_zero));\n  for (i = 0; i < newargc; i++)\n    {\n      lt_debugprintf (__FILE__, __LINE__, \"(main) newargz[%d]: %s\\n\",\n\t\t      i, nonnull (newargz[i]));\n    }\n\nEOF\n\n\t    case $host_os in\n\t      mingw*)\n\t\tcat <<\"EOF\"\n  /* execv doesn't actually work on mingw as expected on unix */\n  newargz = prepare_spawn (newargz);\n  rval = (int) _spawnv (_P_WAIT, lt_argv_zero, (const char * const *) newargz);\n  if (rval == -1)\n    {\n      /* failed to start process */\n      lt_debugprintf (__FILE__, __LINE__,\n\t\t      \"(main) failed to launch target \\\"%s\\\": %s\\n\",\n\t\t      lt_argv_zero, nonnull (strerror (errno)));\n      return 127;\n    }\n  return rval;\nEOF\n\t\t;;\n\t      *)\n\t\tcat <<\"EOF\"\n  execv (lt_argv_zero, newargz);\n  return rval; /* =127, but avoids unused variable warning */\nEOF\n\t\t;;\n\t    esac\n\n\t    cat <<\"EOF\"\n}\n\nvoid *\nxmalloc (size_t num)\n{\n  void *p = (void *) malloc (num);\n  if (!p)\n    lt_fatal (__FILE__, __LINE__, \"memory exhausted\");\n\n  return p;\n}\n\nchar *\nxstrdup (const char *string)\n{\n  return string ? strcpy ((char *) xmalloc (strlen (string) + 1),\n\t\t\t  string) : NULL;\n}\n\nconst char *\nbase_name (const char *name)\n{\n  const char *base;\n\n#if defined HAVE_DOS_BASED_FILE_SYSTEM\n  /* Skip over the disk name in MSDOS pathnames. */\n  if (isalpha ((unsigned char) name[0]) && name[1] == ':')\n    name += 2;\n#endif\n\n  for (base = name; *name; name++)\n    if (IS_DIR_SEPARATOR (*name))\n      base = name + 1;\n  return base;\n}\n\nint\ncheck_executable (const char *path)\n{\n  struct stat st;\n\n  lt_debugprintf (__FILE__, __LINE__, \"(check_executable): %s\\n\",\n                  nonempty (path));\n  if ((!path) || (!*path))\n    return 0;\n\n  if ((stat (path, &st) >= 0)\n      && (st.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)))\n    return 1;\n  else\n    return 0;\n}\n\nint\nmake_executable (const char *path)\n{\n  int rval = 0;\n  struct stat st;\n\n  lt_debugprintf (__FILE__, __LINE__, \"(make_executable): %s\\n\",\n                  nonempty (path));\n  if ((!path) || (!*path))\n    return 0;\n\n  if (stat (path, &st) >= 0)\n    {\n      rval = chmod (path, st.st_mode | S_IXOTH | S_IXGRP | S_IXUSR);\n    }\n  return rval;\n}\n\n/* Searches for the full path of the wrapper.  Returns\n   newly allocated full path name if found, NULL otherwise\n   Does not chase symlinks, even on platforms that support them.\n*/\nchar *\nfind_executable (const char *wrapper)\n{\n  int has_slash = 0;\n  const char *p;\n  const char *p_next;\n  /* static buffer for getcwd */\n  char tmp[LT_PATHMAX + 1];\n  size_t tmp_len;\n  char *concat_name;\n\n  lt_debugprintf (__FILE__, __LINE__, \"(find_executable): %s\\n\",\n                  nonempty (wrapper));\n\n  if ((wrapper == NULL) || (*wrapper == '\\0'))\n    return NULL;\n\n  /* Absolute path? */\n#if defined HAVE_DOS_BASED_FILE_SYSTEM\n  if (isalpha ((unsigned char) wrapper[0]) && wrapper[1] == ':')\n    {\n      concat_name = xstrdup (wrapper);\n      if (check_executable (concat_name))\n\treturn concat_name;\n      XFREE (concat_name);\n    }\n  else\n    {\n#endif\n      if (IS_DIR_SEPARATOR (wrapper[0]))\n\t{\n\t  concat_name = xstrdup (wrapper);\n\t  if (check_executable (concat_name))\n\t    return concat_name;\n\t  XFREE (concat_name);\n\t}\n#if defined HAVE_DOS_BASED_FILE_SYSTEM\n    }\n#endif\n\n  for (p = wrapper; *p; p++)\n    if (*p == '/')\n      {\n\thas_slash = 1;\n\tbreak;\n      }\n  if (!has_slash)\n    {\n      /* no slashes; search PATH */\n      const char *path = getenv (\"PATH\");\n      if (path != NULL)\n\t{\n\t  for (p = path; *p; p = p_next)\n\t    {\n\t      const char *q;\n\t      size_t p_len;\n\t      for (q = p; *q; q++)\n\t\tif (IS_PATH_SEPARATOR (*q))\n\t\t  break;\n\t      p_len = (size_t) (q - p);\n\t      p_next = (*q == '\\0' ? q : q + 1);\n\t      if (p_len == 0)\n\t\t{\n\t\t  /* empty path: current directory */\n\t\t  if (getcwd (tmp, LT_PATHMAX) == NULL)\n\t\t    lt_fatal (__FILE__, __LINE__, \"getcwd failed: %s\",\n                              nonnull (strerror (errno)));\n\t\t  tmp_len = strlen (tmp);\n\t\t  concat_name =\n\t\t    XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);\n\t\t  memcpy (concat_name, tmp, tmp_len);\n\t\t  concat_name[tmp_len] = '/';\n\t\t  strcpy (concat_name + tmp_len + 1, wrapper);\n\t\t}\n\t      else\n\t\t{\n\t\t  concat_name =\n\t\t    XMALLOC (char, p_len + 1 + strlen (wrapper) + 1);\n\t\t  memcpy (concat_name, p, p_len);\n\t\t  concat_name[p_len] = '/';\n\t\t  strcpy (concat_name + p_len + 1, wrapper);\n\t\t}\n\t      if (check_executable (concat_name))\n\t\treturn concat_name;\n\t      XFREE (concat_name);\n\t    }\n\t}\n      /* not found in PATH; assume curdir */\n    }\n  /* Relative path | not found in path: prepend cwd */\n  if (getcwd (tmp, LT_PATHMAX) == NULL)\n    lt_fatal (__FILE__, __LINE__, \"getcwd failed: %s\",\n              nonnull (strerror (errno)));\n  tmp_len = strlen (tmp);\n  concat_name = XMALLOC (char, tmp_len + 1 + strlen (wrapper) + 1);\n  memcpy (concat_name, tmp, tmp_len);\n  concat_name[tmp_len] = '/';\n  strcpy (concat_name + tmp_len + 1, wrapper);\n\n  if (check_executable (concat_name))\n    return concat_name;\n  XFREE (concat_name);\n  return NULL;\n}\n\nchar *\nchase_symlinks (const char *pathspec)\n{\n#ifndef S_ISLNK\n  return xstrdup (pathspec);\n#else\n  char buf[LT_PATHMAX];\n  struct stat s;\n  char *tmp_pathspec = xstrdup (pathspec);\n  char *p;\n  int has_symlinks = 0;\n  while (strlen (tmp_pathspec) && !has_symlinks)\n    {\n      lt_debugprintf (__FILE__, __LINE__,\n\t\t      \"checking path component for symlinks: %s\\n\",\n\t\t      tmp_pathspec);\n      if (lstat (tmp_pathspec, &s) == 0)\n\t{\n\t  if (S_ISLNK (s.st_mode) != 0)\n\t    {\n\t      has_symlinks = 1;\n\t      break;\n\t    }\n\n\t  /* search backwards for last DIR_SEPARATOR */\n\t  p = tmp_pathspec + strlen (tmp_pathspec) - 1;\n\t  while ((p > tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))\n\t    p--;\n\t  if ((p == tmp_pathspec) && (!IS_DIR_SEPARATOR (*p)))\n\t    {\n\t      /* no more DIR_SEPARATORS left */\n\t      break;\n\t    }\n\t  *p = '\\0';\n\t}\n      else\n\t{\n\t  lt_fatal (__FILE__, __LINE__,\n\t\t    \"error accessing file \\\"%s\\\": %s\",\n\t\t    tmp_pathspec, nonnull (strerror (errno)));\n\t}\n    }\n  XFREE (tmp_pathspec);\n\n  if (!has_symlinks)\n    {\n      return xstrdup (pathspec);\n    }\n\n  tmp_pathspec = realpath (pathspec, buf);\n  if (tmp_pathspec == 0)\n    {\n      lt_fatal (__FILE__, __LINE__,\n\t\t\"could not follow symlinks for %s\", pathspec);\n    }\n  return xstrdup (tmp_pathspec);\n#endif\n}\n\nchar *\nstrendzap (char *str, const char *pat)\n{\n  size_t len, patlen;\n\n  assert (str != NULL);\n  assert (pat != NULL);\n\n  len = strlen (str);\n  patlen = strlen (pat);\n\n  if (patlen <= len)\n    {\n      str += len - patlen;\n      if (STREQ (str, pat))\n\t*str = '\\0';\n    }\n  return str;\n}\n\nvoid\nlt_debugprintf (const char *file, int line, const char *fmt, ...)\n{\n  va_list args;\n  if (lt_debug)\n    {\n      (void) fprintf (stderr, \"%s:%s:%d: \", program_name, file, line);\n      va_start (args, fmt);\n      (void) vfprintf (stderr, fmt, args);\n      va_end (args);\n    }\n}\n\nstatic void\nlt_error_core (int exit_status, const char *file,\n\t       int line, const char *mode,\n\t       const char *message, va_list ap)\n{\n  fprintf (stderr, \"%s:%s:%d: %s: \", program_name, file, line, mode);\n  vfprintf (stderr, message, ap);\n  fprintf (stderr, \".\\n\");\n\n  if (exit_status >= 0)\n    exit (exit_status);\n}\n\nvoid\nlt_fatal (const char *file, int line, const char *message, ...)\n{\n  va_list ap;\n  va_start (ap, message);\n  lt_error_core (EXIT_FAILURE, file, line, \"FATAL\", message, ap);\n  va_end (ap);\n}\n\nstatic const char *\nnonnull (const char *s)\n{\n  return s ? s : \"(null)\";\n}\n\nstatic const char *\nnonempty (const char *s)\n{\n  return (s && !*s) ? \"(empty)\" : nonnull (s);\n}\n\nvoid\nlt_setenv (const char *name, const char *value)\n{\n  lt_debugprintf (__FILE__, __LINE__,\n\t\t  \"(lt_setenv) setting '%s' to '%s'\\n\",\n                  nonnull (name), nonnull (value));\n  {\n#ifdef HAVE_SETENV\n    /* always make a copy, for consistency with !HAVE_SETENV */\n    char *str = xstrdup (value);\n    setenv (name, str, 1);\n#else\n    size_t len = strlen (name) + 1 + strlen (value) + 1;\n    char *str = XMALLOC (char, len);\n    sprintf (str, \"%s=%s\", name, value);\n    if (putenv (str) != EXIT_SUCCESS)\n      {\n        XFREE (str);\n      }\n#endif\n  }\n}\n\nchar *\nlt_extend_str (const char *orig_value, const char *add, int to_end)\n{\n  char *new_value;\n  if (orig_value && *orig_value)\n    {\n      size_t orig_value_len = strlen (orig_value);\n      size_t add_len = strlen (add);\n      new_value = XMALLOC (char, add_len + orig_value_len + 1);\n      if (to_end)\n        {\n          strcpy (new_value, orig_value);\n          strcpy (new_value + orig_value_len, add);\n        }\n      else\n        {\n          strcpy (new_value, add);\n          strcpy (new_value + add_len, orig_value);\n        }\n    }\n  else\n    {\n      new_value = xstrdup (add);\n    }\n  return new_value;\n}\n\nvoid\nlt_update_exe_path (const char *name, const char *value)\n{\n  lt_debugprintf (__FILE__, __LINE__,\n\t\t  \"(lt_update_exe_path) modifying '%s' by prepending '%s'\\n\",\n                  nonnull (name), nonnull (value));\n\n  if (name && *name && value && *value)\n    {\n      char *new_value = lt_extend_str (getenv (name), value, 0);\n      /* some systems can't cope with a ':'-terminated path #' */\n      size_t len = strlen (new_value);\n      while ((len > 0) && IS_PATH_SEPARATOR (new_value[len-1]))\n        {\n          new_value[--len] = '\\0';\n        }\n      lt_setenv (name, new_value);\n      XFREE (new_value);\n    }\n}\n\nvoid\nlt_update_lib_path (const char *name, const char *value)\n{\n  lt_debugprintf (__FILE__, __LINE__,\n\t\t  \"(lt_update_lib_path) modifying '%s' by prepending '%s'\\n\",\n                  nonnull (name), nonnull (value));\n\n  if (name && *name && value && *value)\n    {\n      char *new_value = lt_extend_str (getenv (name), value, 0);\n      lt_setenv (name, new_value);\n      XFREE (new_value);\n    }\n}\n\nEOF\n\t    case $host_os in\n\t      mingw*)\n\t\tcat <<\"EOF\"\n\n/* Prepares an argument vector before calling spawn().\n   Note that spawn() does not by itself call the command interpreter\n     (getenv (\"COMSPEC\") != NULL ? getenv (\"COMSPEC\") :\n      ({ OSVERSIONINFO v; v.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);\n         GetVersionEx(&v);\n         v.dwPlatformId == VER_PLATFORM_WIN32_NT;\n      }) ? \"cmd.exe\" : \"command.com\").\n   Instead it simply concatenates the arguments, separated by ' ', and calls\n   CreateProcess().  We must quote the arguments since Win32 CreateProcess()\n   interprets characters like ' ', '\\t', '\\\\', '\"' (but not '<' and '>') in a\n   special way:\n   - Space and tab are interpreted as delimiters. They are not treated as\n     delimiters if they are surrounded by double quotes: \"...\".\n   - Unescaped double quotes are removed from the input. Their only effect is\n     that within double quotes, space and tab are treated like normal\n     characters.\n   - Backslashes not followed by double quotes are not special.\n   - But 2*n+1 backslashes followed by a double quote become\n     n backslashes followed by a double quote (n >= 0):\n       \\\" -> \"\n       \\\\\\\" -> \\\"\n       \\\\\\\\\\\" -> \\\\\"\n */\n#define SHELL_SPECIAL_CHARS \"\\\"\\\\ \\001\\002\\003\\004\\005\\006\\007\\010\\011\\012\\013\\014\\015\\016\\017\\020\\021\\022\\023\\024\\025\\026\\027\\030\\031\\032\\033\\034\\035\\036\\037\"\n#define SHELL_SPACE_CHARS \" \\001\\002\\003\\004\\005\\006\\007\\010\\011\\012\\013\\014\\015\\016\\017\\020\\021\\022\\023\\024\\025\\026\\027\\030\\031\\032\\033\\034\\035\\036\\037\"\nchar **\nprepare_spawn (char **argv)\n{\n  size_t argc;\n  char **new_argv;\n  size_t i;\n\n  /* Count number of arguments.  */\n  for (argc = 0; argv[argc] != NULL; argc++)\n    ;\n\n  /* Allocate new argument vector.  */\n  new_argv = XMALLOC (char *, argc + 1);\n\n  /* Put quoted arguments into the new argument vector.  */\n  for (i = 0; i < argc; i++)\n    {\n      const char *string = argv[i];\n\n      if (string[0] == '\\0')\n\tnew_argv[i] = xstrdup (\"\\\"\\\"\");\n      else if (strpbrk (string, SHELL_SPECIAL_CHARS) != NULL)\n\t{\n\t  int quote_around = (strpbrk (string, SHELL_SPACE_CHARS) != NULL);\n\t  size_t length;\n\t  unsigned int backslashes;\n\t  const char *s;\n\t  char *quoted_string;\n\t  char *p;\n\n\t  length = 0;\n\t  backslashes = 0;\n\t  if (quote_around)\n\t    length++;\n\t  for (s = string; *s != '\\0'; s++)\n\t    {\n\t      char c = *s;\n\t      if (c == '\"')\n\t\tlength += backslashes + 1;\n\t      length++;\n\t      if (c == '\\\\')\n\t\tbackslashes++;\n\t      else\n\t\tbackslashes = 0;\n\t    }\n\t  if (quote_around)\n\t    length += backslashes + 1;\n\n\t  quoted_string = XMALLOC (char, length + 1);\n\n\t  p = quoted_string;\n\t  backslashes = 0;\n\t  if (quote_around)\n\t    *p++ = '\"';\n\t  for (s = string; *s != '\\0'; s++)\n\t    {\n\t      char c = *s;\n\t      if (c == '\"')\n\t\t{\n\t\t  unsigned int j;\n\t\t  for (j = backslashes + 1; j > 0; j--)\n\t\t    *p++ = '\\\\';\n\t\t}\n\t      *p++ = c;\n\t      if (c == '\\\\')\n\t\tbackslashes++;\n\t      else\n\t\tbackslashes = 0;\n\t    }\n\t  if (quote_around)\n\t    {\n\t      unsigned int j;\n\t      for (j = backslashes; j > 0; j--)\n\t\t*p++ = '\\\\';\n\t      *p++ = '\"';\n\t    }\n\t  *p = '\\0';\n\n\t  new_argv[i] = quoted_string;\n\t}\n      else\n\tnew_argv[i] = (char *) string;\n    }\n  new_argv[argc] = NULL;\n\n  return new_argv;\n}\nEOF\n\t\t;;\n\t    esac\n\n            cat <<\"EOF\"\nvoid lt_dump_script (FILE* f)\n{\nEOF\n\t    func_emit_wrapper yes |\n\t      $SED -n -e '\ns/^\\(.\\{79\\}\\)\\(..*\\)/\\1\\\n\\2/\nh\ns/\\([\\\\\"]\\)/\\\\\\1/g\ns/$/\\\\n/\ns/\\([^\\n]*\\).*/  fputs (\"\\1\", f);/p\ng\nD'\n            cat <<\"EOF\"\n}\nEOF\n}\n# end: func_emit_cwrapperexe_src\n\n# func_win32_import_lib_p ARG\n# True if ARG is an import lib, as indicated by $file_magic_cmd\nfunc_win32_import_lib_p ()\n{\n    $debug_cmd\n\n    case `eval $file_magic_cmd \\\"\\$1\\\" 2>/dev/null | $SED -e 10q` in\n    *import*) : ;;\n    *) false ;;\n    esac\n}\n\n# func_suncc_cstd_abi\n# !!ONLY CALL THIS FOR SUN CC AFTER $compile_command IS FULLY EXPANDED!!\n# Several compiler flags select an ABI that is incompatible with the\n# Cstd library. Avoid specifying it if any are in CXXFLAGS.\nfunc_suncc_cstd_abi ()\n{\n    $debug_cmd\n\n    case \" $compile_command \" in\n    *\" -compat=g \"*|*\\ -std=c++[0-9][0-9]\\ *|*\" -library=stdcxx4 \"*|*\" -library=stlport4 \"*)\n      suncc_use_cstd_abi=no\n      ;;\n    *)\n      suncc_use_cstd_abi=yes\n      ;;\n    esac\n}\n\n# func_mode_link arg...\nfunc_mode_link ()\n{\n    $debug_cmd\n\n    case $host in\n    *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)\n      # It is impossible to link a dll without this setting, and\n      # we shouldn't force the makefile maintainer to figure out\n      # what system we are compiling for in order to pass an extra\n      # flag for every libtool invocation.\n      # allow_undefined=no\n\n      # FIXME: Unfortunately, there are problems with the above when trying\n      # to make a dll that has undefined symbols, in which case not\n      # even a static library is built.  For now, we need to specify\n      # -no-undefined on the libtool link line when we can be certain\n      # that all symbols are satisfied, otherwise we get a static library.\n      allow_undefined=yes\n      ;;\n    *)\n      allow_undefined=yes\n      ;;\n    esac\n    libtool_args=$nonopt\n    base_compile=\"$nonopt $@\"\n    compile_command=$nonopt\n    finalize_command=$nonopt\n\n    compile_rpath=\n    finalize_rpath=\n    compile_shlibpath=\n    finalize_shlibpath=\n    convenience=\n    old_convenience=\n    deplibs=\n    old_deplibs=\n    compiler_flags=\n    linker_flags=\n    dllsearchpath=\n    lib_search_path=`pwd`\n    inst_prefix_dir=\n    new_inherited_linker_flags=\n\n    avoid_version=no\n    bindir=\n    dlfiles=\n    dlprefiles=\n    dlself=no\n    export_dynamic=no\n    export_symbols=\n    export_symbols_regex=\n    generated=\n    libobjs=\n    ltlibs=\n    module=no\n    no_install=no\n    objs=\n    os2dllname=\n    non_pic_objects=\n    precious_files_regex=\n    prefer_static_libs=no\n    preload=false\n    prev=\n    prevarg=\n    release=\n    rpath=\n    xrpath=\n    perm_rpath=\n    temp_rpath=\n    thread_safe=no\n    vinfo=\n    vinfo_number=no\n    weak_libs=\n    single_module=$wl-single_module\n    func_infer_tag $base_compile\n\n    # We need to know -static, to get the right output filenames.\n    for arg\n    do\n      case $arg in\n      -shared)\n\ttest yes != \"$build_libtool_libs\" \\\n\t  && func_fatal_configuration \"cannot build a shared library\"\n\tbuild_old_libs=no\n\tbreak\n\t;;\n      -all-static | -static | -static-libtool-libs)\n\tcase $arg in\n\t-all-static)\n\t  if test yes = \"$build_libtool_libs\" && test -z \"$link_static_flag\"; then\n\t    func_warning \"complete static linking is impossible in this configuration\"\n\t  fi\n\t  if test -n \"$link_static_flag\"; then\n\t    dlopen_self=$dlopen_self_static\n\t  fi\n\t  prefer_static_libs=yes\n\t  ;;\n\t-static)\n\t  if test -z \"$pic_flag\" && test -n \"$link_static_flag\"; then\n\t    dlopen_self=$dlopen_self_static\n\t  fi\n\t  prefer_static_libs=built\n\t  ;;\n\t-static-libtool-libs)\n\t  if test -z \"$pic_flag\" && test -n \"$link_static_flag\"; then\n\t    dlopen_self=$dlopen_self_static\n\t  fi\n\t  prefer_static_libs=yes\n\t  ;;\n\tesac\n\tbuild_libtool_libs=no\n\tbuild_old_libs=yes\n\tbreak\n\t;;\n      esac\n    done\n\n    # See if our shared archives depend on static archives.\n    test -n \"$old_archive_from_new_cmds\" && build_old_libs=yes\n\n    # Go through the arguments, transforming them on the way.\n    while test \"$#\" -gt 0; do\n      arg=$1\n      shift\n      func_quote_for_eval \"$arg\"\n      qarg=$func_quote_for_eval_unquoted_result\n      func_append libtool_args \" $func_quote_for_eval_result\"\n\n      # If the previous option needs an argument, assign it.\n      if test -n \"$prev\"; then\n\tcase $prev in\n\toutput)\n\t  func_append compile_command \" @OUTPUT@\"\n\t  func_append finalize_command \" @OUTPUT@\"\n\t  ;;\n\tesac\n\n\tcase $prev in\n\tbindir)\n\t  bindir=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\tdlfiles|dlprefiles)\n\t  $preload || {\n\t    # Add the symbol object into the linking commands.\n\t    func_append compile_command \" @SYMFILE@\"\n\t    func_append finalize_command \" @SYMFILE@\"\n\t    preload=:\n\t  }\n\t  case $arg in\n\t  *.la | *.lo) ;;  # We handle these cases below.\n\t  force)\n\t    if test no = \"$dlself\"; then\n\t      dlself=needless\n\t      export_dynamic=yes\n\t    fi\n\t    prev=\n\t    continue\n\t    ;;\n\t  self)\n\t    if test dlprefiles = \"$prev\"; then\n\t      dlself=yes\n\t    elif test dlfiles = \"$prev\" && test yes != \"$dlopen_self\"; then\n\t      dlself=yes\n\t    else\n\t      dlself=needless\n\t      export_dynamic=yes\n\t    fi\n\t    prev=\n\t    continue\n\t    ;;\n\t  *)\n\t    if test dlfiles = \"$prev\"; then\n\t      func_append dlfiles \" $arg\"\n\t    else\n\t      func_append dlprefiles \" $arg\"\n\t    fi\n\t    prev=\n\t    continue\n\t    ;;\n\t  esac\n\t  ;;\n\texpsyms)\n\t  export_symbols=$arg\n\t  test -f \"$arg\" \\\n\t    || func_fatal_error \"symbol file '$arg' does not exist\"\n\t  prev=\n\t  continue\n\t  ;;\n\texpsyms_regex)\n\t  export_symbols_regex=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\tframework)\n\t  case $host in\n\t    *-*-darwin*)\n\t      case \"$deplibs \" in\n\t\t*\" $qarg.ltframework \"*) ;;\n\t\t*) func_append deplibs \" $qarg.ltframework\" # this is fixed later\n\t\t   ;;\n\t      esac\n\t      ;;\n\t  esac\n\t  prev=\n\t  continue\n\t  ;;\n\tinst_prefix)\n\t  inst_prefix_dir=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\tmllvm)\n\t  # Clang does not use LLVM to link, so we can simply discard any\n\t  # '-mllvm $arg' options when doing the link step.\n\t  prev=\n\t  continue\n\t  ;;\n\tobjectlist)\n\t  if test -f \"$arg\"; then\n\t    save_arg=$arg\n\t    moreargs=\n\t    for fil in `cat \"$save_arg\"`\n\t    do\n#\t      func_append moreargs \" $fil\"\n\t      arg=$fil\n\t      # A libtool-controlled object.\n\n\t      # Check to see that this really is a libtool object.\n\t      if func_lalib_unsafe_p \"$arg\"; then\n\t\tpic_object=\n\t\tnon_pic_object=\n\n\t\t# Read the .lo file\n\t\tfunc_source \"$arg\"\n\n\t\tif test -z \"$pic_object\" ||\n\t\t   test -z \"$non_pic_object\" ||\n\t\t   test none = \"$pic_object\" &&\n\t\t   test none = \"$non_pic_object\"; then\n\t\t  func_fatal_error \"cannot find name of object for '$arg'\"\n\t\tfi\n\n\t\t# Extract subdirectory from the argument.\n\t\tfunc_dirname \"$arg\" \"/\" \"\"\n\t\txdir=$func_dirname_result\n\n\t\tif test none != \"$pic_object\"; then\n\t\t  # Prepend the subdirectory the object is found in.\n\t\t  pic_object=$xdir$pic_object\n\n\t\t  if test dlfiles = \"$prev\"; then\n\t\t    if test yes = \"$build_libtool_libs\" && test yes = \"$dlopen_support\"; then\n\t\t      func_append dlfiles \" $pic_object\"\n\t\t      prev=\n\t\t      continue\n\t\t    else\n\t\t      # If libtool objects are unsupported, then we need to preload.\n\t\t      prev=dlprefiles\n\t\t    fi\n\t\t  fi\n\n\t\t  # CHECK ME:  I think I busted this.  -Ossama\n\t\t  if test dlprefiles = \"$prev\"; then\n\t\t    # Preload the old-style object.\n\t\t    func_append dlprefiles \" $pic_object\"\n\t\t    prev=\n\t\t  fi\n\n\t\t  # A PIC object.\n\t\t  func_append libobjs \" $pic_object\"\n\t\t  arg=$pic_object\n\t\tfi\n\n\t\t# Non-PIC object.\n\t\tif test none != \"$non_pic_object\"; then\n\t\t  # Prepend the subdirectory the object is found in.\n\t\t  non_pic_object=$xdir$non_pic_object\n\n\t\t  # A standard non-PIC object\n\t\t  func_append non_pic_objects \" $non_pic_object\"\n\t\t  if test -z \"$pic_object\" || test none = \"$pic_object\"; then\n\t\t    arg=$non_pic_object\n\t\t  fi\n\t\telse\n\t\t  # If the PIC object exists, use it instead.\n\t\t  # $xdir was prepended to $pic_object above.\n\t\t  non_pic_object=$pic_object\n\t\t  func_append non_pic_objects \" $non_pic_object\"\n\t\tfi\n\t      else\n\t\t# Only an error if not doing a dry-run.\n\t\tif $opt_dry_run; then\n\t\t  # Extract subdirectory from the argument.\n\t\t  func_dirname \"$arg\" \"/\" \"\"\n\t\t  xdir=$func_dirname_result\n\n\t\t  func_lo2o \"$arg\"\n\t\t  pic_object=$xdir$objdir/$func_lo2o_result\n\t\t  non_pic_object=$xdir$func_lo2o_result\n\t\t  func_append libobjs \" $pic_object\"\n\t\t  func_append non_pic_objects \" $non_pic_object\"\n\t        else\n\t\t  func_fatal_error \"'$arg' is not a valid libtool object\"\n\t\tfi\n\t      fi\n\t    done\n\t  else\n\t    func_fatal_error \"link input file '$arg' does not exist\"\n\t  fi\n\t  arg=$save_arg\n\t  prev=\n\t  continue\n\t  ;;\n\tos2dllname)\n\t  os2dllname=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\tprecious_regex)\n\t  precious_files_regex=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\trelease)\n\t  release=-$arg\n\t  prev=\n\t  continue\n\t  ;;\n\trpath | xrpath)\n\t  # We need an absolute path.\n\t  case $arg in\n\t  [\\\\/]* | [A-Za-z]:[\\\\/]*) ;;\n\t  *)\n\t    func_fatal_error \"only absolute run-paths are allowed\"\n\t    ;;\n\t  esac\n\t  if test rpath = \"$prev\"; then\n\t    case \"$rpath \" in\n\t    *\" $arg \"*) ;;\n\t    *) func_append rpath \" $arg\" ;;\n\t    esac\n\t  else\n\t    case \"$xrpath \" in\n\t    *\" $arg \"*) ;;\n\t    *) func_append xrpath \" $arg\" ;;\n\t    esac\n\t  fi\n\t  prev=\n\t  continue\n\t  ;;\n\tshrext)\n\t  shrext_cmds=$arg\n\t  prev=\n\t  continue\n\t  ;;\n\tweak)\n\t  func_append weak_libs \" $arg\"\n\t  prev=\n\t  continue\n\t  ;;\n\txcclinker)\n\t  func_append linker_flags \" $qarg\"\n\t  func_append compiler_flags \" $qarg\"\n\t  prev=\n\t  func_append compile_command \" $qarg\"\n\t  func_append finalize_command \" $qarg\"\n\t  continue\n\t  ;;\n\txcompiler)\n\t  func_append compiler_flags \" $qarg\"\n\t  prev=\n\t  func_append compile_command \" $qarg\"\n\t  func_append finalize_command \" $qarg\"\n\t  continue\n\t  ;;\n\txlinker)\n\t  func_append linker_flags \" $qarg\"\n\t  func_append compiler_flags \" $wl$qarg\"\n\t  prev=\n\t  func_append compile_command \" $wl$qarg\"\n\t  func_append finalize_command \" $wl$qarg\"\n\t  continue\n\t  ;;\n\t*)\n\t  eval \"$prev=\\\"\\$arg\\\"\"\n\t  prev=\n\t  continue\n\t  ;;\n\tesac\n      fi # test -n \"$prev\"\n\n      prevarg=$arg\n\n      case $arg in\n      -all-static)\n\tif test -n \"$link_static_flag\"; then\n\t  # See comment for -static flag below, for more details.\n\t  func_append compile_command \" $link_static_flag\"\n\t  func_append finalize_command \" $link_static_flag\"\n\tfi\n\tcontinue\n\t;;\n\n      -allow-undefined)\n\t# FIXME: remove this flag sometime in the future.\n\tfunc_fatal_error \"'-allow-undefined' must not be used because it is the default\"\n\t;;\n\n      -avoid-version)\n\tavoid_version=yes\n\tcontinue\n\t;;\n\n      -bindir)\n\tprev=bindir\n\tcontinue\n\t;;\n\n      -dlopen)\n\tprev=dlfiles\n\tcontinue\n\t;;\n\n      -dlpreopen)\n\tprev=dlprefiles\n\tcontinue\n\t;;\n\n      -export-dynamic)\n\texport_dynamic=yes\n\tcontinue\n\t;;\n\n      -export-symbols | -export-symbols-regex)\n\tif test -n \"$export_symbols\" || test -n \"$export_symbols_regex\"; then\n\t  func_fatal_error \"more than one -exported-symbols argument is not allowed\"\n\tfi\n\tif test X-export-symbols = \"X$arg\"; then\n\t  prev=expsyms\n\telse\n\t  prev=expsyms_regex\n\tfi\n\tcontinue\n\t;;\n\n      -framework)\n\tprev=framework\n\tcontinue\n\t;;\n\n      -inst-prefix-dir)\n\tprev=inst_prefix\n\tcontinue\n\t;;\n\n      # The native IRIX linker understands -LANG:*, -LIST:* and -LNO:*\n      # so, if we see these flags be careful not to treat them like -L\n      -L[A-Z][A-Z]*:*)\n\tcase $with_gcc/$host in\n\tno/*-*-irix* | /*-*-irix*)\n\t  func_append compile_command \" $arg\"\n\t  func_append finalize_command \" $arg\"\n\t  ;;\n\tesac\n\tcontinue\n\t;;\n\n      -L*)\n\tfunc_stripname \"-L\" '' \"$arg\"\n\tif test -z \"$func_stripname_result\"; then\n\t  if test \"$#\" -gt 0; then\n\t    func_fatal_error \"require no space between '-L' and '$1'\"\n\t  else\n\t    func_fatal_error \"need path for '-L' option\"\n\t  fi\n\tfi\n\tfunc_resolve_sysroot \"$func_stripname_result\"\n\tdir=$func_resolve_sysroot_result\n\t# We need an absolute path.\n\tcase $dir in\n\t[\\\\/]* | [A-Za-z]:[\\\\/]*) ;;\n\t*)\n\t  absdir=`cd \"$dir\" && pwd`\n\t  test -z \"$absdir\" && \\\n\t    func_fatal_error \"cannot determine absolute directory name of '$dir'\"\n\t  dir=$absdir\n\t  ;;\n\tesac\n\tcase \"$deplibs \" in\n\t*\" -L$dir \"* | *\" $arg \"*)\n\t  # Will only happen for absolute or sysroot arguments\n\t  ;;\n\t*)\n\t  # Preserve sysroot, but never include relative directories\n\t  case $dir in\n\t    [\\\\/]* | [A-Za-z]:[\\\\/]* | =*) func_append deplibs \" $arg\" ;;\n\t    *) func_append deplibs \" -L$dir\" ;;\n\t  esac\n\t  func_append lib_search_path \" $dir\"\n\t  ;;\n\tesac\n\tcase $host in\n\t*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)\n\t  testbindir=`$ECHO \"$dir\" | $SED 's*/lib$*/bin*'`\n\t  case :$dllsearchpath: in\n\t  *\":$dir:\"*) ;;\n\t  ::) dllsearchpath=$dir;;\n\t  *) func_append dllsearchpath \":$dir\";;\n\t  esac\n\t  case :$dllsearchpath: in\n\t  *\":$testbindir:\"*) ;;\n\t  ::) dllsearchpath=$testbindir;;\n\t  *) func_append dllsearchpath \":$testbindir\";;\n\t  esac\n\t  ;;\n\tesac\n\tcontinue\n\t;;\n\n      -l*)\n\tif test X-lc = \"X$arg\" || test X-lm = \"X$arg\"; then\n\t  case $host in\n\t  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-beos* | *-cegcc* | *-*-haiku*)\n\t    # These systems don't actually have a C or math library (as such)\n\t    continue\n\t    ;;\n\t  *-*-os2*)\n\t    # These systems don't actually have a C library (as such)\n\t    test X-lc = \"X$arg\" && continue\n\t    ;;\n\t  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)\n\t    # Do not include libc due to us having libc/libc_r.\n\t    test X-lc = \"X$arg\" && continue\n\t    ;;\n\t  *-*-rhapsody* | *-*-darwin1.[012])\n\t    # Rhapsody C and math libraries are in the System framework\n\t    func_append deplibs \" System.ltframework\"\n\t    continue\n\t    ;;\n\t  *-*-sco3.2v5* | *-*-sco5v6*)\n\t    # Causes problems with __ctype\n\t    test X-lc = \"X$arg\" && continue\n\t    ;;\n\t  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)\n\t    # Compiler inserts libc in the correct place for threads to work\n\t    test X-lc = \"X$arg\" && continue\n\t    ;;\n\t  esac\n\telif test X-lc_r = \"X$arg\"; then\n\t case $host in\n\t *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* | *-*-bitrig*)\n\t   # Do not include libc_r directly, use -pthread flag.\n\t   continue\n\t   ;;\n\t esac\n\tfi\n\tfunc_append deplibs \" $arg\"\n\tcontinue\n\t;;\n\n      -mllvm)\n\tprev=mllvm\n\tcontinue\n\t;;\n\n      -module)\n\tmodule=yes\n\tcontinue\n\t;;\n\n      # Tru64 UNIX uses -model [arg] to determine the layout of C++\n      # classes, name mangling, and exception handling.\n      # Darwin uses the -arch flag to determine output architecture.\n      -model|-arch|-isysroot|--sysroot)\n\tfunc_append compiler_flags \" $arg\"\n\tfunc_append compile_command \" $arg\"\n\tfunc_append finalize_command \" $arg\"\n\tprev=xcompiler\n\tcontinue\n\t;;\n\n      -mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \\\n      |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)\n\tfunc_append compiler_flags \" $arg\"\n\tfunc_append compile_command \" $arg\"\n\tfunc_append finalize_command \" $arg\"\n\tcase \"$new_inherited_linker_flags \" in\n\t    *\" $arg \"*) ;;\n\t    * ) func_append new_inherited_linker_flags \" $arg\" ;;\n\tesac\n\tcontinue\n\t;;\n\n      -multi_module)\n\tsingle_module=$wl-multi_module\n\tcontinue\n\t;;\n\n      -no-fast-install)\n\tfast_install=no\n\tcontinue\n\t;;\n\n      -no-install)\n\tcase $host in\n\t*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-darwin* | *-cegcc*)\n\t  # The PATH hackery in wrapper scripts is required on Windows\n\t  # and Darwin in order for the loader to find any dlls it needs.\n\t  func_warning \"'-no-install' is ignored for $host\"\n\t  func_warning \"assuming '-no-fast-install' instead\"\n\t  fast_install=no\n\t  ;;\n\t*) no_install=yes ;;\n\tesac\n\tcontinue\n\t;;\n\n      -no-undefined)\n\tallow_undefined=no\n\tcontinue\n\t;;\n\n      -objectlist)\n\tprev=objectlist\n\tcontinue\n\t;;\n\n      -os2dllname)\n\tprev=os2dllname\n\tcontinue\n\t;;\n\n      -o) prev=output ;;\n\n      -precious-files-regex)\n\tprev=precious_regex\n\tcontinue\n\t;;\n\n      -release)\n\tprev=release\n\tcontinue\n\t;;\n\n      -rpath)\n\tprev=rpath\n\tcontinue\n\t;;\n\n      -R)\n\tprev=xrpath\n\tcontinue\n\t;;\n\n      -R*)\n\tfunc_stripname '-R' '' \"$arg\"\n\tdir=$func_stripname_result\n\t# We need an absolute path.\n\tcase $dir in\n\t[\\\\/]* | [A-Za-z]:[\\\\/]*) ;;\n\t=*)\n\t  func_stripname '=' '' \"$dir\"\n\t  dir=$lt_sysroot$func_stripname_result\n\t  ;;\n\t*)\n\t  func_fatal_error \"only absolute run-paths are allowed\"\n\t  ;;\n\tesac\n\tcase \"$xrpath \" in\n\t*\" $dir \"*) ;;\n\t*) func_append xrpath \" $dir\" ;;\n\tesac\n\tcontinue\n\t;;\n\n      -shared)\n\t# The effects of -shared are defined in a previous loop.\n\tcontinue\n\t;;\n\n      -shrext)\n\tprev=shrext\n\tcontinue\n\t;;\n\n      -static | -static-libtool-libs)\n\t# The effects of -static are defined in a previous loop.\n\t# We used to do the same as -all-static on platforms that\n\t# didn't have a PIC flag, but the assumption that the effects\n\t# would be equivalent was wrong.  It would break on at least\n\t# Digital Unix and AIX.\n\tcontinue\n\t;;\n\n      -thread-safe)\n\tthread_safe=yes\n\tcontinue\n\t;;\n\n      -version-info)\n\tprev=vinfo\n\tcontinue\n\t;;\n\n      -version-number)\n\tprev=vinfo\n\tvinfo_number=yes\n\tcontinue\n\t;;\n\n      -weak)\n        prev=weak\n\tcontinue\n\t;;\n\n      -Wc,*)\n\tfunc_stripname '-Wc,' '' \"$arg\"\n\targs=$func_stripname_result\n\targ=\n\tsave_ifs=$IFS; IFS=,\n\tfor flag in $args; do\n\t  IFS=$save_ifs\n          func_quote_for_eval \"$flag\"\n\t  func_append arg \" $func_quote_for_eval_result\"\n\t  func_append compiler_flags \" $func_quote_for_eval_result\"\n\tdone\n\tIFS=$save_ifs\n\tfunc_stripname ' ' '' \"$arg\"\n\targ=$func_stripname_result\n\t;;\n\n      -Wl,*)\n\tfunc_stripname '-Wl,' '' \"$arg\"\n\targs=$func_stripname_result\n\targ=\n\tsave_ifs=$IFS; IFS=,\n\tfor flag in $args; do\n\t  IFS=$save_ifs\n          func_quote_for_eval \"$flag\"\n\t  func_append arg \" $wl$func_quote_for_eval_result\"\n\t  func_append compiler_flags \" $wl$func_quote_for_eval_result\"\n\t  func_append linker_flags \" $func_quote_for_eval_result\"\n\tdone\n\tIFS=$save_ifs\n\tfunc_stripname ' ' '' \"$arg\"\n\targ=$func_stripname_result\n\t;;\n\n      -Xcompiler)\n\tprev=xcompiler\n\tcontinue\n\t;;\n\n      -Xlinker)\n\tprev=xlinker\n\tcontinue\n\t;;\n\n      -XCClinker)\n\tprev=xcclinker\n\tcontinue\n\t;;\n\n      # -msg_* for osf cc\n      -msg_*)\n\tfunc_quote_for_eval \"$arg\"\n\targ=$func_quote_for_eval_result\n\t;;\n\n      # Flags to be passed through unchanged, with rationale:\n      # -64, -mips[0-9]      enable 64-bit mode for the SGI compiler\n      # -r[0-9][0-9]*        specify processor for the SGI compiler\n      # -xarch=*, -xtarget=* enable 64-bit mode for the Sun compiler\n      # +DA*, +DD*           enable 64-bit mode for the HP compiler\n      # -q*                  compiler args for the IBM compiler\n      # -m*, -t[45]*, -txscale* architecture-specific flags for GCC\n      # -F/path              path to uninstalled frameworks, gcc on darwin\n      # -p, -pg, --coverage, -fprofile-*  profiling flags for GCC\n      # -fstack-protector*   stack protector flags for GCC\n      # @file                GCC response files\n      # -tp=*                Portland pgcc target processor selection\n      # --sysroot=*          for sysroot support\n      # -O*, -g*, -flto*, -fwhopr*, -fuse-linker-plugin GCC link-time optimization\n      # -stdlib=*            select c++ std lib with clang\n      -64|-mips[0-9]|-r[0-9][0-9]*|-xarch=*|-xtarget=*|+DA*|+DD*|-q*|-m*| \\\n      -t[45]*|-txscale*|-p|-pg|--coverage|-fprofile-*|-F*|@*|-tp=*|--sysroot=*| \\\n      -O*|-g*|-flto*|-fwhopr*|-fuse-linker-plugin|-fstack-protector*|-stdlib=*)\n        func_quote_for_eval \"$arg\"\n\targ=$func_quote_for_eval_result\n        func_append compile_command \" $arg\"\n        func_append finalize_command \" $arg\"\n        func_append compiler_flags \" $arg\"\n        continue\n        ;;\n\n      -Z*)\n        if test os2 = \"`expr $host : '.*\\(os2\\)'`\"; then\n          # OS/2 uses -Zxxx to specify OS/2-specific options\n\t  compiler_flags=\"$compiler_flags $arg\"\n\t  func_append compile_command \" $arg\"\n\t  func_append finalize_command \" $arg\"\n\t  case $arg in\n\t  -Zlinker | -Zstack)\n\t    prev=xcompiler\n\t    ;;\n\t  esac\n\t  continue\n        else\n\t  # Otherwise treat like 'Some other compiler flag' below\n\t  func_quote_for_eval \"$arg\"\n\t  arg=$func_quote_for_eval_result\n        fi\n\t;;\n\n      # Some other compiler flag.\n      -* | +*)\n        func_quote_for_eval \"$arg\"\n\targ=$func_quote_for_eval_result\n\t;;\n\n      *.$objext)\n\t# A standard object.\n\tfunc_append objs \" $arg\"\n\t;;\n\n      *.lo)\n\t# A libtool-controlled object.\n\n\t# Check to see that this really is a libtool object.\n\tif func_lalib_unsafe_p \"$arg\"; then\n\t  pic_object=\n\t  non_pic_object=\n\n\t  # Read the .lo file\n\t  func_source \"$arg\"\n\n\t  if test -z \"$pic_object\" ||\n\t     test -z \"$non_pic_object\" ||\n\t     test none = \"$pic_object\" &&\n\t     test none = \"$non_pic_object\"; then\n\t    func_fatal_error \"cannot find name of object for '$arg'\"\n\t  fi\n\n\t  # Extract subdirectory from the argument.\n\t  func_dirname \"$arg\" \"/\" \"\"\n\t  xdir=$func_dirname_result\n\n\t  test none = \"$pic_object\" || {\n\t    # Prepend the subdirectory the object is found in.\n\t    pic_object=$xdir$pic_object\n\n\t    if test dlfiles = \"$prev\"; then\n\t      if test yes = \"$build_libtool_libs\" && test yes = \"$dlopen_support\"; then\n\t\tfunc_append dlfiles \" $pic_object\"\n\t\tprev=\n\t\tcontinue\n\t      else\n\t\t# If libtool objects are unsupported, then we need to preload.\n\t\tprev=dlprefiles\n\t      fi\n\t    fi\n\n\t    # CHECK ME:  I think I busted this.  -Ossama\n\t    if test dlprefiles = \"$prev\"; then\n\t      # Preload the old-style object.\n\t      func_append dlprefiles \" $pic_object\"\n\t      prev=\n\t    fi\n\n\t    # A PIC object.\n\t    func_append libobjs \" $pic_object\"\n\t    arg=$pic_object\n\t  }\n\n\t  # Non-PIC object.\n\t  if test none != \"$non_pic_object\"; then\n\t    # Prepend the subdirectory the object is found in.\n\t    non_pic_object=$xdir$non_pic_object\n\n\t    # A standard non-PIC object\n\t    func_append non_pic_objects \" $non_pic_object\"\n\t    if test -z \"$pic_object\" || test none = \"$pic_object\"; then\n\t      arg=$non_pic_object\n\t    fi\n\t  else\n\t    # If the PIC object exists, use it instead.\n\t    # $xdir was prepended to $pic_object above.\n\t    non_pic_object=$pic_object\n\t    func_append non_pic_objects \" $non_pic_object\"\n\t  fi\n\telse\n\t  # Only an error if not doing a dry-run.\n\t  if $opt_dry_run; then\n\t    # Extract subdirectory from the argument.\n\t    func_dirname \"$arg\" \"/\" \"\"\n\t    xdir=$func_dirname_result\n\n\t    func_lo2o \"$arg\"\n\t    pic_object=$xdir$objdir/$func_lo2o_result\n\t    non_pic_object=$xdir$func_lo2o_result\n\t    func_append libobjs \" $pic_object\"\n\t    func_append non_pic_objects \" $non_pic_object\"\n\t  else\n\t    func_fatal_error \"'$arg' is not a valid libtool object\"\n\t  fi\n\tfi\n\t;;\n\n      *.$libext)\n\t# An archive.\n\tfunc_append deplibs \" $arg\"\n\tfunc_append old_deplibs \" $arg\"\n\tcontinue\n\t;;\n\n      *.la)\n\t# A libtool-controlled library.\n\n\tfunc_resolve_sysroot \"$arg\"\n\tif test dlfiles = \"$prev\"; then\n\t  # This library was specified with -dlopen.\n\t  func_append dlfiles \" $func_resolve_sysroot_result\"\n\t  prev=\n\telif test dlprefiles = \"$prev\"; then\n\t  # The library was specified with -dlpreopen.\n\t  func_append dlprefiles \" $func_resolve_sysroot_result\"\n\t  prev=\n\telse\n\t  func_append deplibs \" $func_resolve_sysroot_result\"\n\tfi\n\tcontinue\n\t;;\n\n      # Some other compiler argument.\n      *)\n\t# Unknown arguments in both finalize_command and compile_command need\n\t# to be aesthetically quoted because they are evaled later.\n\tfunc_quote_for_eval \"$arg\"\n\targ=$func_quote_for_eval_result\n\t;;\n      esac # arg\n\n      # Now actually substitute the argument into the commands.\n      if test -n \"$arg\"; then\n\tfunc_append compile_command \" $arg\"\n\tfunc_append finalize_command \" $arg\"\n      fi\n    done # argument parsing loop\n\n    test -n \"$prev\" && \\\n      func_fatal_help \"the '$prevarg' option requires an argument\"\n\n    if test yes = \"$export_dynamic\" && test -n \"$export_dynamic_flag_spec\"; then\n      eval arg=\\\"$export_dynamic_flag_spec\\\"\n      func_append compile_command \" $arg\"\n      func_append finalize_command \" $arg\"\n    fi\n\n    oldlibs=\n    # calculate the name of the file, without its directory\n    func_basename \"$output\"\n    outputname=$func_basename_result\n    libobjs_save=$libobjs\n\n    if test -n \"$shlibpath_var\"; then\n      # get the directories listed in $shlibpath_var\n      eval shlib_search_path=\\`\\$ECHO \\\"\\$$shlibpath_var\\\" \\| \\$SED \\'s/:/ /g\\'\\`\n    else\n      shlib_search_path=\n    fi\n    eval sys_lib_search_path=\\\"$sys_lib_search_path_spec\\\"\n    eval sys_lib_dlsearch_path=\\\"$sys_lib_dlsearch_path_spec\\\"\n\n    # Definition is injected by LT_CONFIG during libtool generation.\n    func_munge_path_list sys_lib_dlsearch_path \"$LT_SYS_LIBRARY_PATH\"\n\n    func_dirname \"$output\" \"/\" \"\"\n    output_objdir=$func_dirname_result$objdir\n    func_to_tool_file \"$output_objdir/\"\n    tool_output_objdir=$func_to_tool_file_result\n    # Create the object directory.\n    func_mkdir_p \"$output_objdir\"\n\n    # Determine the type of output\n    case $output in\n    \"\")\n      func_fatal_help \"you must specify an output file\"\n      ;;\n    *.$libext) linkmode=oldlib ;;\n    *.lo | *.$objext) linkmode=obj ;;\n    *.la) linkmode=lib ;;\n    *) linkmode=prog ;; # Anything else should be a program.\n    esac\n\n    specialdeplibs=\n\n    libs=\n    # Find all interdependent deplibs by searching for libraries\n    # that are linked more than once (e.g. -la -lb -la)\n    for deplib in $deplibs; do\n      if $opt_preserve_dup_deps; then\n\tcase \"$libs \" in\n\t*\" $deplib \"*) func_append specialdeplibs \" $deplib\" ;;\n\tesac\n      fi\n      func_append libs \" $deplib\"\n    done\n\n    if test lib = \"$linkmode\"; then\n      libs=\"$predeps $libs $compiler_lib_search_path $postdeps\"\n\n      # Compute libraries that are listed more than once in $predeps\n      # $postdeps and mark them as special (i.e., whose duplicates are\n      # not to be eliminated).\n      pre_post_deps=\n      if $opt_duplicate_compiler_generated_deps; then\n\tfor pre_post_dep in $predeps $postdeps; do\n\t  case \"$pre_post_deps \" in\n\t  *\" $pre_post_dep \"*) func_append specialdeplibs \" $pre_post_deps\" ;;\n\t  esac\n\t  func_append pre_post_deps \" $pre_post_dep\"\n\tdone\n      fi\n      pre_post_deps=\n    fi\n\n    deplibs=\n    newdependency_libs=\n    newlib_search_path=\n    need_relink=no # whether we're linking any uninstalled libtool libraries\n    notinst_deplibs= # not-installed libtool libraries\n    notinst_path= # paths that contain not-installed libtool libraries\n\n    case $linkmode in\n    lib)\n\tpasses=\"conv dlpreopen link\"\n\tfor file in $dlfiles $dlprefiles; do\n\t  case $file in\n\t  *.la) ;;\n\t  *)\n\t    func_fatal_help \"libraries can '-dlopen' only libtool libraries: $file\"\n\t    ;;\n\t  esac\n\tdone\n\t;;\n    prog)\n\tcompile_deplibs=\n\tfinalize_deplibs=\n\talldeplibs=false\n\tnewdlfiles=\n\tnewdlprefiles=\n\tpasses=\"conv scan dlopen dlpreopen link\"\n\t;;\n    *)  passes=\"conv\"\n\t;;\n    esac\n\n    for pass in $passes; do\n      # The preopen pass in lib mode reverses $deplibs; put it back here\n      # so that -L comes before libs that need it for instance...\n      if test lib,link = \"$linkmode,$pass\"; then\n\t## FIXME: Find the place where the list is rebuilt in the wrong\n\t##        order, and fix it there properly\n        tmp_deplibs=\n\tfor deplib in $deplibs; do\n\t  tmp_deplibs=\"$deplib $tmp_deplibs\"\n\tdone\n\tdeplibs=$tmp_deplibs\n      fi\n\n      if test lib,link = \"$linkmode,$pass\" ||\n\t test prog,scan = \"$linkmode,$pass\"; then\n\tlibs=$deplibs\n\tdeplibs=\n      fi\n      if test prog = \"$linkmode\"; then\n\tcase $pass in\n\tdlopen) libs=$dlfiles ;;\n\tdlpreopen) libs=$dlprefiles ;;\n\tlink) libs=\"$deplibs %DEPLIBS% $dependency_libs\" ;;\n\tesac\n      fi\n      if test lib,dlpreopen = \"$linkmode,$pass\"; then\n\t# Collect and forward deplibs of preopened libtool libs\n\tfor lib in $dlprefiles; do\n\t  # Ignore non-libtool-libs\n\t  dependency_libs=\n\t  func_resolve_sysroot \"$lib\"\n\t  case $lib in\n\t  *.la)\tfunc_source \"$func_resolve_sysroot_result\" ;;\n\t  esac\n\n\t  # Collect preopened libtool deplibs, except any this library\n\t  # has declared as weak libs\n\t  for deplib in $dependency_libs; do\n\t    func_basename \"$deplib\"\n            deplib_base=$func_basename_result\n\t    case \" $weak_libs \" in\n\t    *\" $deplib_base \"*) ;;\n\t    *) func_append deplibs \" $deplib\" ;;\n\t    esac\n\t  done\n\tdone\n\tlibs=$dlprefiles\n      fi\n      if test dlopen = \"$pass\"; then\n\t# Collect dlpreopened libraries\n\tsave_deplibs=$deplibs\n\tdeplibs=\n      fi\n\n      for deplib in $libs; do\n\tlib=\n\tfound=false\n\tcase $deplib in\n\t-mt|-mthreads|-kthread|-Kthread|-pthread|-pthreads|--thread-safe \\\n        |-threads|-fopenmp|-openmp|-mp|-xopenmp|-omp|-qsmp=*)\n\t  if test prog,link = \"$linkmode,$pass\"; then\n\t    compile_deplibs=\"$deplib $compile_deplibs\"\n\t    finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t  else\n\t    func_append compiler_flags \" $deplib\"\n\t    if test lib = \"$linkmode\"; then\n\t\tcase \"$new_inherited_linker_flags \" in\n\t\t    *\" $deplib \"*) ;;\n\t\t    * ) func_append new_inherited_linker_flags \" $deplib\" ;;\n\t\tesac\n\t    fi\n\t  fi\n\t  continue\n\t  ;;\n\t-l*)\n\t  if test lib != \"$linkmode\" && test prog != \"$linkmode\"; then\n\t    func_warning \"'-l' is ignored for archives/objects\"\n\t    continue\n\t  fi\n\t  func_stripname '-l' '' \"$deplib\"\n\t  name=$func_stripname_result\n\t  if test lib = \"$linkmode\"; then\n\t    searchdirs=\"$newlib_search_path $lib_search_path $compiler_lib_search_dirs $sys_lib_search_path $shlib_search_path\"\n\t  else\n\t    searchdirs=\"$newlib_search_path $lib_search_path $sys_lib_search_path $shlib_search_path\"\n\t  fi\n\t  for searchdir in $searchdirs; do\n\t    for search_ext in .la $std_shrext .so .a; do\n\t      # Search the libtool library\n\t      lib=$searchdir/lib$name$search_ext\n\t      if test -f \"$lib\"; then\n\t\tif test .la = \"$search_ext\"; then\n\t\t  found=:\n\t\telse\n\t\t  found=false\n\t\tfi\n\t\tbreak 2\n\t      fi\n\t    done\n\t  done\n\t  if $found; then\n\t    # deplib is a libtool library\n\t    # If $allow_libtool_libs_with_static_runtimes && $deplib is a stdlib,\n\t    # We need to do some special things here, and not later.\n\t    if test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t      case \" $predeps $postdeps \" in\n\t      *\" $deplib \"*)\n\t\tif func_lalib_p \"$lib\"; then\n\t\t  library_names=\n\t\t  old_library=\n\t\t  func_source \"$lib\"\n\t\t  for l in $old_library $library_names; do\n\t\t    ll=$l\n\t\t  done\n\t\t  if test \"X$ll\" = \"X$old_library\"; then # only static version available\n\t\t    found=false\n\t\t    func_dirname \"$lib\" \"\" \".\"\n\t\t    ladir=$func_dirname_result\n\t\t    lib=$ladir/$old_library\n\t\t    if test prog,link = \"$linkmode,$pass\"; then\n\t\t      compile_deplibs=\"$deplib $compile_deplibs\"\n\t\t      finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t\t    else\n\t\t      deplibs=\"$deplib $deplibs\"\n\t\t      test lib = \"$linkmode\" && newdependency_libs=\"$deplib $newdependency_libs\"\n\t\t    fi\n\t\t    continue\n\t\t  fi\n\t\tfi\n\t\t;;\n\t      *) ;;\n\t      esac\n\t    fi\n\t  else\n\t    # deplib doesn't seem to be a libtool library\n\t    if test prog,link = \"$linkmode,$pass\"; then\n\t      compile_deplibs=\"$deplib $compile_deplibs\"\n\t      finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t    else\n\t      deplibs=\"$deplib $deplibs\"\n\t      test lib = \"$linkmode\" && newdependency_libs=\"$deplib $newdependency_libs\"\n\t    fi\n\t    continue\n\t  fi\n\t  ;; # -l\n\t*.ltframework)\n\t  if test prog,link = \"$linkmode,$pass\"; then\n\t    compile_deplibs=\"$deplib $compile_deplibs\"\n\t    finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t  else\n\t    deplibs=\"$deplib $deplibs\"\n\t    if test lib = \"$linkmode\"; then\n\t\tcase \"$new_inherited_linker_flags \" in\n\t\t    *\" $deplib \"*) ;;\n\t\t    * ) func_append new_inherited_linker_flags \" $deplib\" ;;\n\t\tesac\n\t    fi\n\t  fi\n\t  continue\n\t  ;;\n\t-L*)\n\t  case $linkmode in\n\t  lib)\n\t    deplibs=\"$deplib $deplibs\"\n\t    test conv = \"$pass\" && continue\n\t    newdependency_libs=\"$deplib $newdependency_libs\"\n\t    func_stripname '-L' '' \"$deplib\"\n\t    func_resolve_sysroot \"$func_stripname_result\"\n\t    func_append newlib_search_path \" $func_resolve_sysroot_result\"\n\t    ;;\n\t  prog)\n\t    if test conv = \"$pass\"; then\n\t      deplibs=\"$deplib $deplibs\"\n\t      continue\n\t    fi\n\t    if test scan = \"$pass\"; then\n\t      deplibs=\"$deplib $deplibs\"\n\t    else\n\t      compile_deplibs=\"$deplib $compile_deplibs\"\n\t      finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t    fi\n\t    func_stripname '-L' '' \"$deplib\"\n\t    func_resolve_sysroot \"$func_stripname_result\"\n\t    func_append newlib_search_path \" $func_resolve_sysroot_result\"\n\t    ;;\n\t  *)\n\t    func_warning \"'-L' is ignored for archives/objects\"\n\t    ;;\n\t  esac # linkmode\n\t  continue\n\t  ;; # -L\n\t-R*)\n\t  if test link = \"$pass\"; then\n\t    func_stripname '-R' '' \"$deplib\"\n\t    func_resolve_sysroot \"$func_stripname_result\"\n\t    dir=$func_resolve_sysroot_result\n\t    # Make sure the xrpath contains only unique directories.\n\t    case \"$xrpath \" in\n\t    *\" $dir \"*) ;;\n\t    *) func_append xrpath \" $dir\" ;;\n\t    esac\n\t  fi\n\t  deplibs=\"$deplib $deplibs\"\n\t  continue\n\t  ;;\n\t*.la)\n\t  func_resolve_sysroot \"$deplib\"\n\t  lib=$func_resolve_sysroot_result\n\t  ;;\n\t*.$libext)\n\t  if test conv = \"$pass\"; then\n\t    deplibs=\"$deplib $deplibs\"\n\t    continue\n\t  fi\n\t  case $linkmode in\n\t  lib)\n\t    # Linking convenience modules into shared libraries is allowed,\n\t    # but linking other static libraries is non-portable.\n\t    case \" $dlpreconveniencelibs \" in\n\t    *\" $deplib \"*) ;;\n\t    *)\n\t      valid_a_lib=false\n\t      case $deplibs_check_method in\n\t\tmatch_pattern*)\n\t\t  set dummy $deplibs_check_method; shift\n\t\t  match_pattern_regex=`expr \"$deplibs_check_method\" : \"$1 \\(.*\\)\"`\n\t\t  if eval \"\\$ECHO \\\"$deplib\\\"\" 2>/dev/null | $SED 10q \\\n\t\t    | $EGREP \"$match_pattern_regex\" > /dev/null; then\n\t\t    valid_a_lib=:\n\t\t  fi\n\t\t;;\n\t\tpass_all)\n\t\t  valid_a_lib=:\n\t\t;;\n\t      esac\n\t      if $valid_a_lib; then\n\t\techo\n\t\t$ECHO \"*** Warning: Linking the shared library $output against the\"\n\t\t$ECHO \"*** static library $deplib is not portable!\"\n\t\tdeplibs=\"$deplib $deplibs\"\n\t      else\n\t\techo\n\t\t$ECHO \"*** Warning: Trying to link with static lib archive $deplib.\"\n\t\techo \"*** I have the capability to make that library automatically link in when\"\n\t\techo \"*** you link to this library.  But I can only do this if you have a\"\n\t\techo \"*** shared version of the library, which you do not appear to have\"\n\t\techo \"*** because the file extensions .$libext of this argument makes me believe\"\n\t\techo \"*** that it is just a static archive that I should not use here.\"\n\t      fi\n\t      ;;\n\t    esac\n\t    continue\n\t    ;;\n\t  prog)\n\t    if test link != \"$pass\"; then\n\t      deplibs=\"$deplib $deplibs\"\n\t    else\n\t      compile_deplibs=\"$deplib $compile_deplibs\"\n\t      finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t    fi\n\t    continue\n\t    ;;\n\t  esac # linkmode\n\t  ;; # *.$libext\n\t*.lo | *.$objext)\n\t  if test conv = \"$pass\"; then\n\t    deplibs=\"$deplib $deplibs\"\n\t  elif test prog = \"$linkmode\"; then\n\t    if test dlpreopen = \"$pass\" || test yes != \"$dlopen_support\" || test no = \"$build_libtool_libs\"; then\n\t      # If there is no dlopen support or we're linking statically,\n\t      # we need to preload.\n\t      func_append newdlprefiles \" $deplib\"\n\t      compile_deplibs=\"$deplib $compile_deplibs\"\n\t      finalize_deplibs=\"$deplib $finalize_deplibs\"\n\t    else\n\t      func_append newdlfiles \" $deplib\"\n\t    fi\n\t  fi\n\t  continue\n\t  ;;\n\t%DEPLIBS%)\n\t  alldeplibs=:\n\t  continue\n\t  ;;\n\tesac # case $deplib\n\n\t$found || test -f \"$lib\" \\\n\t  || func_fatal_error \"cannot find the library '$lib' or unhandled argument '$deplib'\"\n\n\t# Check to see that this really is a libtool archive.\n\tfunc_lalib_unsafe_p \"$lib\" \\\n\t  || func_fatal_error \"'$lib' is not a valid libtool archive\"\n\n\tfunc_dirname \"$lib\" \"\" \".\"\n\tladir=$func_dirname_result\n\n\tdlname=\n\tdlopen=\n\tdlpreopen=\n\tlibdir=\n\tlibrary_names=\n\told_library=\n\tinherited_linker_flags=\n\t# If the library was installed with an old release of libtool,\n\t# it will not redefine variables installed, or shouldnotlink\n\tinstalled=yes\n\tshouldnotlink=no\n\tavoidtemprpath=\n\n\n\t# Read the .la file\n\tfunc_source \"$lib\"\n\n\t# Convert \"-framework foo\" to \"foo.ltframework\"\n\tif test -n \"$inherited_linker_flags\"; then\n\t  tmp_inherited_linker_flags=`$ECHO \"$inherited_linker_flags\" | $SED 's/-framework \\([^ $]*\\)/\\1.ltframework/g'`\n\t  for tmp_inherited_linker_flag in $tmp_inherited_linker_flags; do\n\t    case \" $new_inherited_linker_flags \" in\n\t      *\" $tmp_inherited_linker_flag \"*) ;;\n\t      *) func_append new_inherited_linker_flags \" $tmp_inherited_linker_flag\";;\n\t    esac\n\t  done\n\tfi\n\tdependency_libs=`$ECHO \" $dependency_libs\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\tif test lib,link = \"$linkmode,$pass\" ||\n\t   test prog,scan = \"$linkmode,$pass\" ||\n\t   { test prog != \"$linkmode\" && test lib != \"$linkmode\"; }; then\n\t  test -n \"$dlopen\" && func_append dlfiles \" $dlopen\"\n\t  test -n \"$dlpreopen\" && func_append dlprefiles \" $dlpreopen\"\n\tfi\n\n\tif test conv = \"$pass\"; then\n\t  # Only check for convenience libraries\n\t  deplibs=\"$lib $deplibs\"\n\t  if test -z \"$libdir\"; then\n\t    if test -z \"$old_library\"; then\n\t      func_fatal_error \"cannot find name of link library for '$lib'\"\n\t    fi\n\t    # It is a libtool convenience library, so add in its objects.\n\t    func_append convenience \" $ladir/$objdir/$old_library\"\n\t    func_append old_convenience \" $ladir/$objdir/$old_library\"\n\t  elif test prog != \"$linkmode\" && test lib != \"$linkmode\"; then\n\t    func_fatal_error \"'$lib' is not a convenience library\"\n\t  fi\n\t  tmp_libs=\n\t  for deplib in $dependency_libs; do\n\t    deplibs=\"$deplib $deplibs\"\n\t    if $opt_preserve_dup_deps; then\n\t      case \"$tmp_libs \" in\n\t      *\" $deplib \"*) func_append specialdeplibs \" $deplib\" ;;\n\t      esac\n\t    fi\n\t    func_append tmp_libs \" $deplib\"\n\t  done\n\t  continue\n\tfi # $pass = conv\n\n\n\t# Get the name of the library we link against.\n\tlinklib=\n\tif test -n \"$old_library\" &&\n\t   { test yes = \"$prefer_static_libs\" ||\n\t     test built,no = \"$prefer_static_libs,$installed\"; }; then\n\t  linklib=$old_library\n\telse\n\t  for l in $old_library $library_names; do\n\t    linklib=$l\n\t  done\n\tfi\n\tif test -z \"$linklib\"; then\n\t  func_fatal_error \"cannot find name of link library for '$lib'\"\n\tfi\n\n\t# This library was specified with -dlopen.\n\tif test dlopen = \"$pass\"; then\n\t  test -z \"$libdir\" \\\n\t    && func_fatal_error \"cannot -dlopen a convenience library: '$lib'\"\n\t  if test -z \"$dlname\" ||\n\t     test yes != \"$dlopen_support\" ||\n\t     test no = \"$build_libtool_libs\"\n\t  then\n\t    # If there is no dlname, no dlopen support or we're linking\n\t    # statically, we need to preload.  We also need to preload any\n\t    # dependent libraries so libltdl's deplib preloader doesn't\n\t    # bomb out in the load deplibs phase.\n\t    func_append dlprefiles \" $lib $dependency_libs\"\n\t  else\n\t    func_append newdlfiles \" $lib\"\n\t  fi\n\t  continue\n\tfi # $pass = dlopen\n\n\t# We need an absolute path.\n\tcase $ladir in\n\t[\\\\/]* | [A-Za-z]:[\\\\/]*) abs_ladir=$ladir ;;\n\t*)\n\t  abs_ladir=`cd \"$ladir\" && pwd`\n\t  if test -z \"$abs_ladir\"; then\n\t    func_warning \"cannot determine absolute directory name of '$ladir'\"\n\t    func_warning \"passing it literally to the linker, although it might fail\"\n\t    abs_ladir=$ladir\n\t  fi\n\t  ;;\n\tesac\n\tfunc_basename \"$lib\"\n\tlaname=$func_basename_result\n\n\t# Find the relevant object directory and library name.\n\tif test yes = \"$installed\"; then\n\t  if test ! -f \"$lt_sysroot$libdir/$linklib\" && test -f \"$abs_ladir/$linklib\"; then\n\t    func_warning \"library '$lib' was moved.\"\n\t    dir=$ladir\n\t    absdir=$abs_ladir\n\t    libdir=$abs_ladir\n\t  else\n\t    dir=$lt_sysroot$libdir\n\t    absdir=$lt_sysroot$libdir\n\t  fi\n\t  test yes = \"$hardcode_automatic\" && avoidtemprpath=yes\n\telse\n\t  if test ! -f \"$ladir/$objdir/$linklib\" && test -f \"$abs_ladir/$linklib\"; then\n\t    dir=$ladir\n\t    absdir=$abs_ladir\n\t    # Remove this search path later\n\t    func_append notinst_path \" $abs_ladir\"\n\t  else\n\t    dir=$ladir/$objdir\n\t    absdir=$abs_ladir/$objdir\n\t    # Remove this search path later\n\t    func_append notinst_path \" $abs_ladir\"\n\t  fi\n\tfi # $installed = yes\n\tfunc_stripname 'lib' '.la' \"$laname\"\n\tname=$func_stripname_result\n\n\t# This library was specified with -dlpreopen.\n\tif test dlpreopen = \"$pass\"; then\n\t  if test -z \"$libdir\" && test prog = \"$linkmode\"; then\n\t    func_fatal_error \"only libraries may -dlpreopen a convenience library: '$lib'\"\n\t  fi\n\t  case $host in\n\t    # special handling for platforms with PE-DLLs.\n\t    *cygwin* | *mingw* | *cegcc* )\n\t      # Linker will automatically link against shared library if both\n\t      # static and shared are present.  Therefore, ensure we extract\n\t      # symbols from the import library if a shared library is present\n\t      # (otherwise, the dlopen module name will be incorrect).  We do\n\t      # this by putting the import library name into $newdlprefiles.\n\t      # We recover the dlopen module name by 'saving' the la file\n\t      # name in a special purpose variable, and (later) extracting the\n\t      # dlname from the la file.\n\t      if test -n \"$dlname\"; then\n\t        func_tr_sh \"$dir/$linklib\"\n\t        eval \"libfile_$func_tr_sh_result=\\$abs_ladir/\\$laname\"\n\t        func_append newdlprefiles \" $dir/$linklib\"\n\t      else\n\t        func_append newdlprefiles \" $dir/$old_library\"\n\t        # Keep a list of preopened convenience libraries to check\n\t        # that they are being used correctly in the link pass.\n\t        test -z \"$libdir\" && \\\n\t          func_append dlpreconveniencelibs \" $dir/$old_library\"\n\t      fi\n\t    ;;\n\t    * )\n\t      # Prefer using a static library (so that no silly _DYNAMIC symbols\n\t      # are required to link).\n\t      if test -n \"$old_library\"; then\n\t        func_append newdlprefiles \" $dir/$old_library\"\n\t        # Keep a list of preopened convenience libraries to check\n\t        # that they are being used correctly in the link pass.\n\t        test -z \"$libdir\" && \\\n\t          func_append dlpreconveniencelibs \" $dir/$old_library\"\n\t      # Otherwise, use the dlname, so that lt_dlopen finds it.\n\t      elif test -n \"$dlname\"; then\n\t        func_append newdlprefiles \" $dir/$dlname\"\n\t      else\n\t        func_append newdlprefiles \" $dir/$linklib\"\n\t      fi\n\t    ;;\n\t  esac\n\tfi # $pass = dlpreopen\n\n\tif test -z \"$libdir\"; then\n\t  # Link the convenience library\n\t  if test lib = \"$linkmode\"; then\n\t    deplibs=\"$dir/$old_library $deplibs\"\n\t  elif test prog,link = \"$linkmode,$pass\"; then\n\t    compile_deplibs=\"$dir/$old_library $compile_deplibs\"\n\t    finalize_deplibs=\"$dir/$old_library $finalize_deplibs\"\n\t  else\n\t    deplibs=\"$lib $deplibs\" # used for prog,scan pass\n\t  fi\n\t  continue\n\tfi\n\n\n\tif test prog = \"$linkmode\" && test link != \"$pass\"; then\n\t  func_append newlib_search_path \" $ladir\"\n\t  deplibs=\"$lib $deplibs\"\n\n\t  linkalldeplibs=false\n\t  if test no != \"$link_all_deplibs\" || test -z \"$library_names\" ||\n\t     test no = \"$build_libtool_libs\"; then\n\t    linkalldeplibs=:\n\t  fi\n\n\t  tmp_libs=\n\t  for deplib in $dependency_libs; do\n\t    case $deplib in\n\t    -L*) func_stripname '-L' '' \"$deplib\"\n\t         func_resolve_sysroot \"$func_stripname_result\"\n\t         func_append newlib_search_path \" $func_resolve_sysroot_result\"\n\t\t ;;\n\t    esac\n\t    # Need to link against all dependency_libs?\n\t    if $linkalldeplibs; then\n\t      deplibs=\"$deplib $deplibs\"\n\t    else\n\t      # Need to hardcode shared library paths\n\t      # or/and link against static libraries\n\t      newdependency_libs=\"$deplib $newdependency_libs\"\n\t    fi\n\t    if $opt_preserve_dup_deps; then\n\t      case \"$tmp_libs \" in\n\t      *\" $deplib \"*) func_append specialdeplibs \" $deplib\" ;;\n\t      esac\n\t    fi\n\t    func_append tmp_libs \" $deplib\"\n\t  done # for deplib\n\t  continue\n\tfi # $linkmode = prog...\n\n\tif test prog,link = \"$linkmode,$pass\"; then\n\t  if test -n \"$library_names\" &&\n\t     { { test no = \"$prefer_static_libs\" ||\n\t         test built,yes = \"$prefer_static_libs,$installed\"; } ||\n\t       test -z \"$old_library\"; }; then\n\t    # We need to hardcode the library path\n\t    if test -n \"$shlibpath_var\" && test -z \"$avoidtemprpath\"; then\n\t      # Make sure the rpath contains only unique directories.\n\t      case $temp_rpath: in\n\t      *\"$absdir:\"*) ;;\n\t      *) func_append temp_rpath \"$absdir:\" ;;\n\t      esac\n\t    fi\n\n\t    # Hardcode the library path.\n\t    # Skip directories that are in the system default run-time\n\t    # search path.\n\t    case \" $sys_lib_dlsearch_path \" in\n\t    *\" $absdir \"*) ;;\n\t    *)\n\t      case \"$compile_rpath \" in\n\t      *\" $absdir \"*) ;;\n\t      *) func_append compile_rpath \" $absdir\" ;;\n\t      esac\n\t      ;;\n\t    esac\n\t    case \" $sys_lib_dlsearch_path \" in\n\t    *\" $libdir \"*) ;;\n\t    *)\n\t      case \"$finalize_rpath \" in\n\t      *\" $libdir \"*) ;;\n\t      *) func_append finalize_rpath \" $libdir\" ;;\n\t      esac\n\t      ;;\n\t    esac\n\t  fi # $linkmode,$pass = prog,link...\n\n\t  if $alldeplibs &&\n\t     { test pass_all = \"$deplibs_check_method\" ||\n\t       { test yes = \"$build_libtool_libs\" &&\n\t\t test -n \"$library_names\"; }; }; then\n\t    # We only need to search for static libraries\n\t    continue\n\t  fi\n\tfi\n\n\tlink_static=no # Whether the deplib will be linked statically\n\tuse_static_libs=$prefer_static_libs\n\tif test built = \"$use_static_libs\" && test yes = \"$installed\"; then\n\t  use_static_libs=no\n\tfi\n\tif test -n \"$library_names\" &&\n\t   { test no = \"$use_static_libs\" || test -z \"$old_library\"; }; then\n\t  case $host in\n\t  *cygwin* | *mingw* | *cegcc* | *os2*)\n\t      # No point in relinking DLLs because paths are not encoded\n\t      func_append notinst_deplibs \" $lib\"\n\t      need_relink=no\n\t    ;;\n\t  *)\n\t    if test no = \"$installed\"; then\n\t      func_append notinst_deplibs \" $lib\"\n\t      need_relink=yes\n\t    fi\n\t    ;;\n\t  esac\n\t  # This is a shared library\n\n\t  # Warn about portability, can't link against -module's on some\n\t  # systems (darwin).  Don't bleat about dlopened modules though!\n\t  dlopenmodule=\n\t  for dlpremoduletest in $dlprefiles; do\n\t    if test \"X$dlpremoduletest\" = \"X$lib\"; then\n\t      dlopenmodule=$dlpremoduletest\n\t      break\n\t    fi\n\t  done\n\t  if test -z \"$dlopenmodule\" && test yes = \"$shouldnotlink\" && test link = \"$pass\"; then\n\t    echo\n\t    if test prog = \"$linkmode\"; then\n\t      $ECHO \"*** Warning: Linking the executable $output against the loadable module\"\n\t    else\n\t      $ECHO \"*** Warning: Linking the shared library $output against the loadable module\"\n\t    fi\n\t    $ECHO \"*** $linklib is not portable!\"\n\t  fi\n\t  if test lib = \"$linkmode\" &&\n\t     test yes = \"$hardcode_into_libs\"; then\n\t    # Hardcode the library path.\n\t    # Skip directories that are in the system default run-time\n\t    # search path.\n\t    case \" $sys_lib_dlsearch_path \" in\n\t    *\" $absdir \"*) ;;\n\t    *)\n\t      case \"$compile_rpath \" in\n\t      *\" $absdir \"*) ;;\n\t      *) func_append compile_rpath \" $absdir\" ;;\n\t      esac\n\t      ;;\n\t    esac\n\t    case \" $sys_lib_dlsearch_path \" in\n\t    *\" $libdir \"*) ;;\n\t    *)\n\t      case \"$finalize_rpath \" in\n\t      *\" $libdir \"*) ;;\n\t      *) func_append finalize_rpath \" $libdir\" ;;\n\t      esac\n\t      ;;\n\t    esac\n\t  fi\n\n\t  if test -n \"$old_archive_from_expsyms_cmds\"; then\n\t    # figure out the soname\n\t    set dummy $library_names\n\t    shift\n\t    realname=$1\n\t    shift\n\t    libname=`eval \"\\\\$ECHO \\\"$libname_spec\\\"\"`\n\t    # use dlname if we got it. it's perfectly good, no?\n\t    if test -n \"$dlname\"; then\n\t      soname=$dlname\n\t    elif test -n \"$soname_spec\"; then\n\t      # bleh windows\n\t      case $host in\n\t      *cygwin* | mingw* | *cegcc* | *os2*)\n\t        func_arith $current - $age\n\t\tmajor=$func_arith_result\n\t\tversuffix=-$major\n\t\t;;\n\t      esac\n\t      eval soname=\\\"$soname_spec\\\"\n\t    else\n\t      soname=$realname\n\t    fi\n\n\t    # Make a new name for the extract_expsyms_cmds to use\n\t    soroot=$soname\n\t    func_basename \"$soroot\"\n\t    soname=$func_basename_result\n\t    func_stripname 'lib' '.dll' \"$soname\"\n\t    newlib=libimp-$func_stripname_result.a\n\n\t    # If the library has no export list, then create one now\n\t    if test -f \"$output_objdir/$soname-def\"; then :\n\t    else\n\t      func_verbose \"extracting exported symbol list from '$soname'\"\n\t      func_execute_cmds \"$extract_expsyms_cmds\" 'exit $?'\n\t    fi\n\n\t    # Create $newlib\n\t    if test -f \"$output_objdir/$newlib\"; then :; else\n\t      func_verbose \"generating import library for '$soname'\"\n\t      func_execute_cmds \"$old_archive_from_expsyms_cmds\" 'exit $?'\n\t    fi\n\t    # make sure the library variables are pointing to the new library\n\t    dir=$output_objdir\n\t    linklib=$newlib\n\t  fi # test -n \"$old_archive_from_expsyms_cmds\"\n\n\t  if test prog = \"$linkmode\" || test relink != \"$opt_mode\"; then\n\t    add_shlibpath=\n\t    add_dir=\n\t    add=\n\t    lib_linked=yes\n\t    case $hardcode_action in\n\t    immediate | unsupported)\n\t      if test no = \"$hardcode_direct\"; then\n\t\tadd=$dir/$linklib\n\t\tcase $host in\n\t\t  *-*-sco3.2v5.0.[024]*) add_dir=-L$dir ;;\n\t\t  *-*-sysv4*uw2*) add_dir=-L$dir ;;\n\t\t  *-*-sysv5OpenUNIX* | *-*-sysv5UnixWare7.[01].[10]* | \\\n\t\t    *-*-unixware7*) add_dir=-L$dir ;;\n\t\t  *-*-darwin* )\n\t\t    # if the lib is a (non-dlopened) module then we cannot\n\t\t    # link against it, someone is ignoring the earlier warnings\n\t\t    if /usr/bin/file -L $add 2> /dev/null |\n\t\t\t $GREP \": [^:]* bundle\" >/dev/null; then\n\t\t      if test \"X$dlopenmodule\" != \"X$lib\"; then\n\t\t\t$ECHO \"*** Warning: lib $linklib is a module, not a shared library\"\n\t\t\tif test -z \"$old_library\"; then\n\t\t\t  echo\n\t\t\t  echo \"*** And there doesn't seem to be a static archive available\"\n\t\t\t  echo \"*** The link will probably fail, sorry\"\n\t\t\telse\n\t\t\t  add=$dir/$old_library\n\t\t\tfi\n\t\t      elif test -n \"$old_library\"; then\n\t\t\tadd=$dir/$old_library\n\t\t      fi\n\t\t    fi\n\t\tesac\n\t      elif test no = \"$hardcode_minus_L\"; then\n\t\tcase $host in\n\t\t*-*-sunos*) add_shlibpath=$dir ;;\n\t\tesac\n\t\tadd_dir=-L$dir\n\t\tadd=-l$name\n\t      elif test no = \"$hardcode_shlibpath_var\"; then\n\t\tadd_shlibpath=$dir\n\t\tadd=-l$name\n\t      else\n\t\tlib_linked=no\n\t      fi\n\t      ;;\n\t    relink)\n\t      if test yes = \"$hardcode_direct\" &&\n\t         test no = \"$hardcode_direct_absolute\"; then\n\t\tadd=$dir/$linklib\n\t      elif test yes = \"$hardcode_minus_L\"; then\n\t\tadd_dir=-L$absdir\n\t\t# Try looking first in the location we're being installed to.\n\t\tif test -n \"$inst_prefix_dir\"; then\n\t\t  case $libdir in\n\t\t    [\\\\/]*)\n\t\t      func_append add_dir \" -L$inst_prefix_dir$libdir\"\n\t\t      ;;\n\t\t  esac\n\t\tfi\n\t\tadd=-l$name\n\t      elif test yes = \"$hardcode_shlibpath_var\"; then\n\t\tadd_shlibpath=$dir\n\t\tadd=-l$name\n\t      else\n\t\tlib_linked=no\n\t      fi\n\t      ;;\n\t    *) lib_linked=no ;;\n\t    esac\n\n\t    if test yes != \"$lib_linked\"; then\n\t      func_fatal_configuration \"unsupported hardcode properties\"\n\t    fi\n\n\t    if test -n \"$add_shlibpath\"; then\n\t      case :$compile_shlibpath: in\n\t      *\":$add_shlibpath:\"*) ;;\n\t      *) func_append compile_shlibpath \"$add_shlibpath:\" ;;\n\t      esac\n\t    fi\n\t    if test prog = \"$linkmode\"; then\n\t      test -n \"$add_dir\" && compile_deplibs=\"$add_dir $compile_deplibs\"\n\t      test -n \"$add\" && compile_deplibs=\"$add $compile_deplibs\"\n\t    else\n\t      test -n \"$add_dir\" && deplibs=\"$add_dir $deplibs\"\n\t      test -n \"$add\" && deplibs=\"$add $deplibs\"\n\t      if test yes != \"$hardcode_direct\" &&\n\t\t test yes != \"$hardcode_minus_L\" &&\n\t\t test yes = \"$hardcode_shlibpath_var\"; then\n\t\tcase :$finalize_shlibpath: in\n\t\t*\":$libdir:\"*) ;;\n\t\t*) func_append finalize_shlibpath \"$libdir:\" ;;\n\t\tesac\n\t      fi\n\t    fi\n\t  fi\n\n\t  if test prog = \"$linkmode\" || test relink = \"$opt_mode\"; then\n\t    add_shlibpath=\n\t    add_dir=\n\t    add=\n\t    # Finalize command for both is simple: just hardcode it.\n\t    if test yes = \"$hardcode_direct\" &&\n\t       test no = \"$hardcode_direct_absolute\"; then\n\t      add=$libdir/$linklib\n\t    elif test yes = \"$hardcode_minus_L\"; then\n\t      add_dir=-L$libdir\n\t      add=-l$name\n\t    elif test yes = \"$hardcode_shlibpath_var\"; then\n\t      case :$finalize_shlibpath: in\n\t      *\":$libdir:\"*) ;;\n\t      *) func_append finalize_shlibpath \"$libdir:\" ;;\n\t      esac\n\t      add=-l$name\n\t    elif test yes = \"$hardcode_automatic\"; then\n\t      if test -n \"$inst_prefix_dir\" &&\n\t\t test -f \"$inst_prefix_dir$libdir/$linklib\"; then\n\t\tadd=$inst_prefix_dir$libdir/$linklib\n\t      else\n\t\tadd=$libdir/$linklib\n\t      fi\n\t    else\n\t      # We cannot seem to hardcode it, guess we'll fake it.\n\t      add_dir=-L$libdir\n\t      # Try looking first in the location we're being installed to.\n\t      if test -n \"$inst_prefix_dir\"; then\n\t\tcase $libdir in\n\t\t  [\\\\/]*)\n\t\t    func_append add_dir \" -L$inst_prefix_dir$libdir\"\n\t\t    ;;\n\t\tesac\n\t      fi\n\t      add=-l$name\n\t    fi\n\n\t    if test prog = \"$linkmode\"; then\n\t      test -n \"$add_dir\" && finalize_deplibs=\"$add_dir $finalize_deplibs\"\n\t      test -n \"$add\" && finalize_deplibs=\"$add $finalize_deplibs\"\n\t    else\n\t      test -n \"$add_dir\" && deplibs=\"$add_dir $deplibs\"\n\t      test -n \"$add\" && deplibs=\"$add $deplibs\"\n\t    fi\n\t  fi\n\telif test prog = \"$linkmode\"; then\n\t  # Here we assume that one of hardcode_direct or hardcode_minus_L\n\t  # is not unsupported.  This is valid on all known static and\n\t  # shared platforms.\n\t  if test unsupported != \"$hardcode_direct\"; then\n\t    test -n \"$old_library\" && linklib=$old_library\n\t    compile_deplibs=\"$dir/$linklib $compile_deplibs\"\n\t    finalize_deplibs=\"$dir/$linklib $finalize_deplibs\"\n\t  else\n\t    compile_deplibs=\"-l$name -L$dir $compile_deplibs\"\n\t    finalize_deplibs=\"-l$name -L$dir $finalize_deplibs\"\n\t  fi\n\telif test yes = \"$build_libtool_libs\"; then\n\t  # Not a shared library\n\t  if test pass_all != \"$deplibs_check_method\"; then\n\t    # We're trying link a shared library against a static one\n\t    # but the system doesn't support it.\n\n\t    # Just print a warning and add the library to dependency_libs so\n\t    # that the program can be linked against the static library.\n\t    echo\n\t    $ECHO \"*** Warning: This system cannot link to static lib archive $lib.\"\n\t    echo \"*** I have the capability to make that library automatically link in when\"\n\t    echo \"*** you link to this library.  But I can only do this if you have a\"\n\t    echo \"*** shared version of the library, which you do not appear to have.\"\n\t    if test yes = \"$module\"; then\n\t      echo \"*** But as you try to build a module library, libtool will still create \"\n\t      echo \"*** a static module, that should work as long as the dlopening application\"\n\t      echo \"*** is linked with the -dlopen flag to resolve symbols at runtime.\"\n\t      if test -z \"$global_symbol_pipe\"; then\n\t\techo\n\t\techo \"*** However, this would only work if libtool was able to extract symbol\"\n\t\techo \"*** lists from a program, using 'nm' or equivalent, but libtool could\"\n\t\techo \"*** not find such a program.  So, this module is probably useless.\"\n\t\techo \"*** 'nm' from GNU binutils and a full rebuild may help.\"\n\t      fi\n\t      if test no = \"$build_old_libs\"; then\n\t\tbuild_libtool_libs=module\n\t\tbuild_old_libs=yes\n\t      else\n\t\tbuild_libtool_libs=no\n\t      fi\n\t    fi\n\t  else\n\t    deplibs=\"$dir/$old_library $deplibs\"\n\t    link_static=yes\n\t  fi\n\tfi # link shared/static library?\n\n\tif test lib = \"$linkmode\"; then\n\t  if test -n \"$dependency_libs\" &&\n\t     { test yes != \"$hardcode_into_libs\" ||\n\t       test yes = \"$build_old_libs\" ||\n\t       test yes = \"$link_static\"; }; then\n\t    # Extract -R from dependency_libs\n\t    temp_deplibs=\n\t    for libdir in $dependency_libs; do\n\t      case $libdir in\n\t      -R*) func_stripname '-R' '' \"$libdir\"\n\t           temp_xrpath=$func_stripname_result\n\t\t   case \" $xrpath \" in\n\t\t   *\" $temp_xrpath \"*) ;;\n\t\t   *) func_append xrpath \" $temp_xrpath\";;\n\t\t   esac;;\n\t      *) func_append temp_deplibs \" $libdir\";;\n\t      esac\n\t    done\n\t    dependency_libs=$temp_deplibs\n\t  fi\n\n\t  func_append newlib_search_path \" $absdir\"\n\t  # Link against this library\n\t  test no = \"$link_static\" && newdependency_libs=\"$abs_ladir/$laname $newdependency_libs\"\n\t  # ... and its dependency_libs\n\t  tmp_libs=\n\t  for deplib in $dependency_libs; do\n\t    newdependency_libs=\"$deplib $newdependency_libs\"\n\t    case $deplib in\n              -L*) func_stripname '-L' '' \"$deplib\"\n                   func_resolve_sysroot \"$func_stripname_result\";;\n              *) func_resolve_sysroot \"$deplib\" ;;\n            esac\n\t    if $opt_preserve_dup_deps; then\n\t      case \"$tmp_libs \" in\n\t      *\" $func_resolve_sysroot_result \"*)\n                func_append specialdeplibs \" $func_resolve_sysroot_result\" ;;\n\t      esac\n\t    fi\n\t    func_append tmp_libs \" $func_resolve_sysroot_result\"\n\t  done\n\n\t  if test no != \"$link_all_deplibs\"; then\n\t    # Add the search paths of all dependency libraries\n\t    for deplib in $dependency_libs; do\n\t      path=\n\t      case $deplib in\n\t      -L*) path=$deplib ;;\n\t      *.la)\n\t        func_resolve_sysroot \"$deplib\"\n\t        deplib=$func_resolve_sysroot_result\n\t        func_dirname \"$deplib\" \"\" \".\"\n\t\tdir=$func_dirname_result\n\t\t# We need an absolute path.\n\t\tcase $dir in\n\t\t[\\\\/]* | [A-Za-z]:[\\\\/]*) absdir=$dir ;;\n\t\t*)\n\t\t  absdir=`cd \"$dir\" && pwd`\n\t\t  if test -z \"$absdir\"; then\n\t\t    func_warning \"cannot determine absolute directory name of '$dir'\"\n\t\t    absdir=$dir\n\t\t  fi\n\t\t  ;;\n\t\tesac\n\t\tif $GREP \"^installed=no\" $deplib > /dev/null; then\n\t\tcase $host in\n\t\t*-*-darwin*)\n\t\t  depdepl=\n\t\t  eval deplibrary_names=`$SED -n -e 's/^library_names=\\(.*\\)$/\\1/p' $deplib`\n\t\t  if test -n \"$deplibrary_names\"; then\n\t\t    for tmp in $deplibrary_names; do\n\t\t      depdepl=$tmp\n\t\t    done\n\t\t    if test -f \"$absdir/$objdir/$depdepl\"; then\n\t\t      depdepl=$absdir/$objdir/$depdepl\n\t\t      darwin_install_name=`$OTOOL -L $depdepl | awk '{if (NR == 2) {print $1;exit}}'`\n                      if test -z \"$darwin_install_name\"; then\n                          darwin_install_name=`$OTOOL64 -L $depdepl  | awk '{if (NR == 2) {print $1;exit}}'`\n                      fi\n\t\t      func_append compiler_flags \" $wl-dylib_file $wl$darwin_install_name:$depdepl\"\n\t\t      func_append linker_flags \" -dylib_file $darwin_install_name:$depdepl\"\n\t\t      path=\n\t\t    fi\n\t\t  fi\n\t\t  ;;\n\t\t*)\n\t\t  path=-L$absdir/$objdir\n\t\t  ;;\n\t\tesac\n\t\telse\n\t\t  eval libdir=`$SED -n -e 's/^libdir=\\(.*\\)$/\\1/p' $deplib`\n\t\t  test -z \"$libdir\" && \\\n\t\t    func_fatal_error \"'$deplib' is not a valid libtool archive\"\n\t\t  test \"$absdir\" != \"$libdir\" && \\\n\t\t    func_warning \"'$deplib' seems to be moved\"\n\n\t\t  path=-L$absdir\n\t\tfi\n\t\t;;\n\t      esac\n\t      case \" $deplibs \" in\n\t      *\" $path \"*) ;;\n\t      *) deplibs=\"$path $deplibs\" ;;\n\t      esac\n\t    done\n\t  fi # link_all_deplibs != no\n\tfi # linkmode = lib\n      done # for deplib in $libs\n      if test link = \"$pass\"; then\n\tif test prog = \"$linkmode\"; then\n\t  compile_deplibs=\"$new_inherited_linker_flags $compile_deplibs\"\n\t  finalize_deplibs=\"$new_inherited_linker_flags $finalize_deplibs\"\n\telse\n\t  compiler_flags=\"$compiler_flags \"`$ECHO \" $new_inherited_linker_flags\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\tfi\n      fi\n      dependency_libs=$newdependency_libs\n      if test dlpreopen = \"$pass\"; then\n\t# Link the dlpreopened libraries before other libraries\n\tfor deplib in $save_deplibs; do\n\t  deplibs=\"$deplib $deplibs\"\n\tdone\n      fi\n      if test dlopen != \"$pass\"; then\n\ttest conv = \"$pass\" || {\n\t  # Make sure lib_search_path contains only unique directories.\n\t  lib_search_path=\n\t  for dir in $newlib_search_path; do\n\t    case \"$lib_search_path \" in\n\t    *\" $dir \"*) ;;\n\t    *) func_append lib_search_path \" $dir\" ;;\n\t    esac\n\t  done\n\t  newlib_search_path=\n\t}\n\n\tif test prog,link = \"$linkmode,$pass\"; then\n\t  vars=\"compile_deplibs finalize_deplibs\"\n\telse\n\t  vars=deplibs\n\tfi\n\tfor var in $vars dependency_libs; do\n\t  # Add libraries to $var in reverse order\n\t  eval tmp_libs=\\\"\\$$var\\\"\n\t  new_libs=\n\t  for deplib in $tmp_libs; do\n\t    # FIXME: Pedantically, this is the right thing to do, so\n\t    #        that some nasty dependency loop isn't accidentally\n\t    #        broken:\n\t    #new_libs=\"$deplib $new_libs\"\n\t    # Pragmatically, this seems to cause very few problems in\n\t    # practice:\n\t    case $deplib in\n\t    -L*) new_libs=\"$deplib $new_libs\" ;;\n\t    -R*) ;;\n\t    *)\n\t      # And here is the reason: when a library appears more\n\t      # than once as an explicit dependence of a library, or\n\t      # is implicitly linked in more than once by the\n\t      # compiler, it is considered special, and multiple\n\t      # occurrences thereof are not removed.  Compare this\n\t      # with having the same library being listed as a\n\t      # dependency of multiple other libraries: in this case,\n\t      # we know (pedantically, we assume) the library does not\n\t      # need to be listed more than once, so we keep only the\n\t      # last copy.  This is not always right, but it is rare\n\t      # enough that we require users that really mean to play\n\t      # such unportable linking tricks to link the library\n\t      # using -Wl,-lname, so that libtool does not consider it\n\t      # for duplicate removal.\n\t      case \" $specialdeplibs \" in\n\t      *\" $deplib \"*) new_libs=\"$deplib $new_libs\" ;;\n\t      *)\n\t\tcase \" $new_libs \" in\n\t\t*\" $deplib \"*) ;;\n\t\t*) new_libs=\"$deplib $new_libs\" ;;\n\t\tesac\n\t\t;;\n\t      esac\n\t      ;;\n\t    esac\n\t  done\n\t  tmp_libs=\n\t  for deplib in $new_libs; do\n\t    case $deplib in\n\t    -L*)\n\t      case \" $tmp_libs \" in\n\t      *\" $deplib \"*) ;;\n\t      *) func_append tmp_libs \" $deplib\" ;;\n\t      esac\n\t      ;;\n\t    *) func_append tmp_libs \" $deplib\" ;;\n\t    esac\n\t  done\n\t  eval $var=\\\"$tmp_libs\\\"\n\tdone # for var\n      fi\n\n      # Add Sun CC postdeps if required:\n      test CXX = \"$tagname\" && {\n        case $host_os in\n        linux*)\n          case `$CC -V 2>&1 | sed 5q` in\n          *Sun\\ C*) # Sun C++ 5.9\n            func_suncc_cstd_abi\n\n            if test no != \"$suncc_use_cstd_abi\"; then\n              func_append postdeps ' -library=Cstd -library=Crun'\n            fi\n            ;;\n          esac\n          ;;\n\n        solaris*)\n          func_cc_basename \"$CC\"\n          case $func_cc_basename_result in\n          CC* | sunCC*)\n            func_suncc_cstd_abi\n\n            if test no != \"$suncc_use_cstd_abi\"; then\n              func_append postdeps ' -library=Cstd -library=Crun'\n            fi\n            ;;\n          esac\n          ;;\n        esac\n      }\n\n      # Last step: remove runtime libs from dependency_libs\n      # (they stay in deplibs)\n      tmp_libs=\n      for i in $dependency_libs; do\n\tcase \" $predeps $postdeps $compiler_lib_search_path \" in\n\t*\" $i \"*)\n\t  i=\n\t  ;;\n\tesac\n\tif test -n \"$i\"; then\n\t  func_append tmp_libs \" $i\"\n\tfi\n      done\n      dependency_libs=$tmp_libs\n    done # for pass\n    if test prog = \"$linkmode\"; then\n      dlfiles=$newdlfiles\n    fi\n    if test prog = \"$linkmode\" || test lib = \"$linkmode\"; then\n      dlprefiles=$newdlprefiles\n    fi\n\n    case $linkmode in\n    oldlib)\n      if test -n \"$dlfiles$dlprefiles\" || test no != \"$dlself\"; then\n\tfunc_warning \"'-dlopen' is ignored for archives\"\n      fi\n\n      case \" $deplibs\" in\n      *\\ -l* | *\\ -L*)\n\tfunc_warning \"'-l' and '-L' are ignored for archives\" ;;\n      esac\n\n      test -n \"$rpath\" && \\\n\tfunc_warning \"'-rpath' is ignored for archives\"\n\n      test -n \"$xrpath\" && \\\n\tfunc_warning \"'-R' is ignored for archives\"\n\n      test -n \"$vinfo\" && \\\n\tfunc_warning \"'-version-info/-version-number' is ignored for archives\"\n\n      test -n \"$release\" && \\\n\tfunc_warning \"'-release' is ignored for archives\"\n\n      test -n \"$export_symbols$export_symbols_regex\" && \\\n\tfunc_warning \"'-export-symbols' is ignored for archives\"\n\n      # Now set the variables for building old libraries.\n      build_libtool_libs=no\n      oldlibs=$output\n      func_append objs \"$old_deplibs\"\n      ;;\n\n    lib)\n      # Make sure we only generate libraries of the form 'libNAME.la'.\n      case $outputname in\n      lib*)\n\tfunc_stripname 'lib' '.la' \"$outputname\"\n\tname=$func_stripname_result\n\teval shared_ext=\\\"$shrext_cmds\\\"\n\teval libname=\\\"$libname_spec\\\"\n\t;;\n      *)\n\ttest no = \"$module\" \\\n\t  && func_fatal_help \"libtool library '$output' must begin with 'lib'\"\n\n\tif test no != \"$need_lib_prefix\"; then\n\t  # Add the \"lib\" prefix for modules if required\n\t  func_stripname '' '.la' \"$outputname\"\n\t  name=$func_stripname_result\n\t  eval shared_ext=\\\"$shrext_cmds\\\"\n\t  eval libname=\\\"$libname_spec\\\"\n\telse\n\t  func_stripname '' '.la' \"$outputname\"\n\t  libname=$func_stripname_result\n\tfi\n\t;;\n      esac\n\n      if test -n \"$objs\"; then\n\tif test pass_all != \"$deplibs_check_method\"; then\n\t  func_fatal_error \"cannot build libtool library '$output' from non-libtool objects on this host:$objs\"\n\telse\n\t  echo\n\t  $ECHO \"*** Warning: Linking the shared library $output against the non-libtool\"\n\t  $ECHO \"*** objects $objs is not portable!\"\n\t  func_append libobjs \" $objs\"\n\tfi\n      fi\n\n      test no = \"$dlself\" \\\n\t|| func_warning \"'-dlopen self' is ignored for libtool libraries\"\n\n      set dummy $rpath\n      shift\n      test 1 -lt \"$#\" \\\n\t&& func_warning \"ignoring multiple '-rpath's for a libtool library\"\n\n      install_libdir=$1\n\n      oldlibs=\n      if test -z \"$rpath\"; then\n\tif test yes = \"$build_libtool_libs\"; then\n\t  # Building a libtool convenience library.\n\t  # Some compilers have problems with a '.al' extension so\n\t  # convenience libraries should have the same extension an\n\t  # archive normally would.\n\t  oldlibs=\"$output_objdir/$libname.$libext $oldlibs\"\n\t  build_libtool_libs=convenience\n\t  build_old_libs=yes\n\tfi\n\n\ttest -n \"$vinfo\" && \\\n\t  func_warning \"'-version-info/-version-number' is ignored for convenience libraries\"\n\n\ttest -n \"$release\" && \\\n\t  func_warning \"'-release' is ignored for convenience libraries\"\n      else\n\n\t# Parse the version information argument.\n\tsave_ifs=$IFS; IFS=:\n\tset dummy $vinfo 0 0 0\n\tshift\n\tIFS=$save_ifs\n\n\ttest -n \"$7\" && \\\n\t  func_fatal_help \"too many parameters to '-version-info'\"\n\n\t# convert absolute version numbers to libtool ages\n\t# this retains compatibility with .la files and attempts\n\t# to make the code below a bit more comprehensible\n\n\tcase $vinfo_number in\n\tyes)\n\t  number_major=$1\n\t  number_minor=$2\n\t  number_revision=$3\n\t  #\n\t  # There are really only two kinds -- those that\n\t  # use the current revision as the major version\n\t  # and those that subtract age and use age as\n\t  # a minor version.  But, then there is irix\n\t  # that has an extra 1 added just for fun\n\t  #\n\t  case $version_type in\n\t  # correct linux to gnu/linux during the next big refactor\n\t  darwin|freebsd-elf|linux|osf|windows|none)\n\t    func_arith $number_major + $number_minor\n\t    current=$func_arith_result\n\t    age=$number_minor\n\t    revision=$number_revision\n\t    ;;\n\t  freebsd-aout|qnx|sunos)\n\t    current=$number_major\n\t    revision=$number_minor\n\t    age=0\n\t    ;;\n\t  irix|nonstopux)\n\t    func_arith $number_major + $number_minor\n\t    current=$func_arith_result\n\t    age=$number_minor\n\t    revision=$number_minor\n\t    lt_irix_increment=no\n\t    ;;\n\t  esac\n\t  ;;\n\tno)\n\t  current=$1\n\t  revision=$2\n\t  age=$3\n\t  ;;\n\tesac\n\n\t# Check that each of the things are valid numbers.\n\tcase $current in\n\t0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;\n\t*)\n\t  func_error \"CURRENT '$current' must be a nonnegative integer\"\n\t  func_fatal_error \"'$vinfo' is not valid version information\"\n\t  ;;\n\tesac\n\n\tcase $revision in\n\t0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;\n\t*)\n\t  func_error \"REVISION '$revision' must be a nonnegative integer\"\n\t  func_fatal_error \"'$vinfo' is not valid version information\"\n\t  ;;\n\tesac\n\n\tcase $age in\n\t0|[1-9]|[1-9][0-9]|[1-9][0-9][0-9]|[1-9][0-9][0-9][0-9]|[1-9][0-9][0-9][0-9][0-9]) ;;\n\t*)\n\t  func_error \"AGE '$age' must be a nonnegative integer\"\n\t  func_fatal_error \"'$vinfo' is not valid version information\"\n\t  ;;\n\tesac\n\n\tif test \"$age\" -gt \"$current\"; then\n\t  func_error \"AGE '$age' is greater than the current interface number '$current'\"\n\t  func_fatal_error \"'$vinfo' is not valid version information\"\n\tfi\n\n\t# Calculate the version variables.\n\tmajor=\n\tversuffix=\n\tverstring=\n\tcase $version_type in\n\tnone) ;;\n\n\tdarwin)\n\t  # Like Linux, but with the current version available in\n\t  # verstring for coding it into the library header\n\t  func_arith $current - $age\n\t  major=.$func_arith_result\n\t  versuffix=$major.$age.$revision\n\t  # Darwin ld doesn't like 0 for these options...\n\t  func_arith $current + 1\n\t  minor_current=$func_arith_result\n\t  xlcverstring=\"$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision\"\n\t  verstring=\"-compatibility_version $minor_current -current_version $minor_current.$revision\"\n          # On Darwin other compilers\n          case $CC in\n              nagfor*)\n                  verstring=\"$wl-compatibility_version $wl$minor_current $wl-current_version $wl$minor_current.$revision\"\n                  ;;\n              *)\n                  verstring=\"-compatibility_version $minor_current -current_version $minor_current.$revision\"\n                  ;;\n          esac\n\t  ;;\n\n\tfreebsd-aout)\n\t  major=.$current\n\t  versuffix=.$current.$revision\n\t  ;;\n\n\tfreebsd-elf)\n\t  func_arith $current - $age\n\t  major=.$func_arith_result\n\t  versuffix=$major.$age.$revision\n\t  ;;\n\n\tirix | nonstopux)\n\t  if test no = \"$lt_irix_increment\"; then\n\t    func_arith $current - $age\n\t  else\n\t    func_arith $current - $age + 1\n\t  fi\n\t  major=$func_arith_result\n\n\t  case $version_type in\n\t    nonstopux) verstring_prefix=nonstopux ;;\n\t    *)         verstring_prefix=sgi ;;\n\t  esac\n\t  verstring=$verstring_prefix$major.$revision\n\n\t  # Add in all the interfaces that we are compatible with.\n\t  loop=$revision\n\t  while test 0 -ne \"$loop\"; do\n\t    func_arith $revision - $loop\n\t    iface=$func_arith_result\n\t    func_arith $loop - 1\n\t    loop=$func_arith_result\n\t    verstring=$verstring_prefix$major.$iface:$verstring\n\t  done\n\n\t  # Before this point, $major must not contain '.'.\n\t  major=.$major\n\t  versuffix=$major.$revision\n\t  ;;\n\n\tlinux) # correct to gnu/linux during the next big refactor\n\t  func_arith $current - $age\n\t  major=.$func_arith_result\n\t  versuffix=$major.$age.$revision\n\t  ;;\n\n\tosf)\n\t  func_arith $current - $age\n\t  major=.$func_arith_result\n\t  versuffix=.$current.$age.$revision\n\t  verstring=$current.$age.$revision\n\n\t  # Add in all the interfaces that we are compatible with.\n\t  loop=$age\n\t  while test 0 -ne \"$loop\"; do\n\t    func_arith $current - $loop\n\t    iface=$func_arith_result\n\t    func_arith $loop - 1\n\t    loop=$func_arith_result\n\t    verstring=$verstring:$iface.0\n\t  done\n\n\t  # Make executables depend on our current version.\n\t  func_append verstring \":$current.0\"\n\t  ;;\n\n\tqnx)\n\t  major=.$current\n\t  versuffix=.$current\n\t  ;;\n\n\tsco)\n\t  major=.$current\n\t  versuffix=.$current\n\t  ;;\n\n\tsunos)\n\t  major=.$current\n\t  versuffix=.$current.$revision\n\t  ;;\n\n\twindows)\n\t  # Use '-' rather than '.', since we only want one\n\t  # extension on DOS 8.3 file systems.\n\t  func_arith $current - $age\n\t  major=$func_arith_result\n\t  versuffix=-$major\n\t  ;;\n\n\t*)\n\t  func_fatal_configuration \"unknown library version type '$version_type'\"\n\t  ;;\n\tesac\n\n\t# Clear the version info if we defaulted, and they specified a release.\n\tif test -z \"$vinfo\" && test -n \"$release\"; then\n\t  major=\n\t  case $version_type in\n\t  darwin)\n\t    # we can't check for \"0.0\" in archive_cmds due to quoting\n\t    # problems, so we reset it completely\n\t    verstring=\n\t    ;;\n\t  *)\n\t    verstring=0.0\n\t    ;;\n\t  esac\n\t  if test no = \"$need_version\"; then\n\t    versuffix=\n\t  else\n\t    versuffix=.0.0\n\t  fi\n\tfi\n\n\t# Remove version info from name if versioning should be avoided\n\tif test yes,no = \"$avoid_version,$need_version\"; then\n\t  major=\n\t  versuffix=\n\t  verstring=\n\tfi\n\n\t# Check to see if the archive will have undefined symbols.\n\tif test yes = \"$allow_undefined\"; then\n\t  if test unsupported = \"$allow_undefined_flag\"; then\n\t    if test yes = \"$build_old_libs\"; then\n\t      func_warning \"undefined symbols not allowed in $host shared libraries; building static only\"\n\t      build_libtool_libs=no\n\t    else\n\t      func_fatal_error \"can't build $host shared library unless -no-undefined is specified\"\n\t    fi\n\t  fi\n\telse\n\t  # Don't allow undefined symbols.\n\t  allow_undefined_flag=$no_undefined_flag\n\tfi\n\n      fi\n\n      func_generate_dlsyms \"$libname\" \"$libname\" :\n      func_append libobjs \" $symfileobj\"\n      test \" \" = \"$libobjs\" && libobjs=\n\n      if test relink != \"$opt_mode\"; then\n\t# Remove our outputs, but don't remove object files since they\n\t# may have been created when compiling PIC objects.\n\tremovelist=\n\ttempremovelist=`$ECHO \"$output_objdir/*\"`\n\tfor p in $tempremovelist; do\n\t  case $p in\n\t    *.$objext | *.gcno)\n\t       ;;\n\t    $output_objdir/$outputname | $output_objdir/$libname.* | $output_objdir/$libname$release.*)\n\t       if test -n \"$precious_files_regex\"; then\n\t\t if $ECHO \"$p\" | $EGREP -e \"$precious_files_regex\" >/dev/null 2>&1\n\t\t then\n\t\t   continue\n\t\t fi\n\t       fi\n\t       func_append removelist \" $p\"\n\t       ;;\n\t    *) ;;\n\t  esac\n\tdone\n\ttest -n \"$removelist\" && \\\n\t  func_show_eval \"${RM}r \\$removelist\"\n      fi\n\n      # Now set the variables for building old libraries.\n      if test yes = \"$build_old_libs\" && test convenience != \"$build_libtool_libs\"; then\n\tfunc_append oldlibs \" $output_objdir/$libname.$libext\"\n\n\t# Transform .lo files to .o files.\n\toldobjs=\"$objs \"`$ECHO \"$libobjs\" | $SP2NL | $SED \"/\\.$libext$/d; $lo2o\" | $NL2SP`\n      fi\n\n      # Eliminate all temporary directories.\n      #for path in $notinst_path; do\n      #\tlib_search_path=`$ECHO \"$lib_search_path \" | $SED \"s% $path % %g\"`\n      #\tdeplibs=`$ECHO \"$deplibs \" | $SED \"s% -L$path % %g\"`\n      #\tdependency_libs=`$ECHO \"$dependency_libs \" | $SED \"s% -L$path % %g\"`\n      #done\n\n      if test -n \"$xrpath\"; then\n\t# If the user specified any rpath flags, then add them.\n\ttemp_xrpath=\n\tfor libdir in $xrpath; do\n\t  func_replace_sysroot \"$libdir\"\n\t  func_append temp_xrpath \" -R$func_replace_sysroot_result\"\n\t  case \"$finalize_rpath \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append finalize_rpath \" $libdir\" ;;\n\t  esac\n\tdone\n\tif test yes != \"$hardcode_into_libs\" || test yes = \"$build_old_libs\"; then\n\t  dependency_libs=\"$temp_xrpath $dependency_libs\"\n\tfi\n      fi\n\n      # Make sure dlfiles contains only unique files that won't be dlpreopened\n      old_dlfiles=$dlfiles\n      dlfiles=\n      for lib in $old_dlfiles; do\n\tcase \" $dlprefiles $dlfiles \" in\n\t*\" $lib \"*) ;;\n\t*) func_append dlfiles \" $lib\" ;;\n\tesac\n      done\n\n      # Make sure dlprefiles contains only unique files\n      old_dlprefiles=$dlprefiles\n      dlprefiles=\n      for lib in $old_dlprefiles; do\n\tcase \"$dlprefiles \" in\n\t*\" $lib \"*) ;;\n\t*) func_append dlprefiles \" $lib\" ;;\n\tesac\n      done\n\n      if test yes = \"$build_libtool_libs\"; then\n\tif test -n \"$rpath\"; then\n\t  case $host in\n\t  *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-*-beos* | *-cegcc* | *-*-haiku*)\n\t    # these systems don't actually have a c library (as such)!\n\t    ;;\n\t  *-*-rhapsody* | *-*-darwin1.[012])\n\t    # Rhapsody C library is in the System framework\n\t    func_append deplibs \" System.ltframework\"\n\t    ;;\n\t  *-*-netbsd*)\n\t    # Don't link with libc until the a.out ld.so is fixed.\n\t    ;;\n\t  *-*-openbsd* | *-*-freebsd* | *-*-dragonfly*)\n\t    # Do not include libc due to us having libc/libc_r.\n\t    ;;\n\t  *-*-sco3.2v5* | *-*-sco5v6*)\n\t    # Causes problems with __ctype\n\t    ;;\n\t  *-*-sysv4.2uw2* | *-*-sysv5* | *-*-unixware* | *-*-OpenUNIX*)\n\t    # Compiler inserts libc in the correct place for threads to work\n\t    ;;\n\t  *)\n\t    # Add libc to deplibs on all other systems if necessary.\n\t    if test yes = \"$build_libtool_need_lc\"; then\n\t      func_append deplibs \" -lc\"\n\t    fi\n\t    ;;\n\t  esac\n\tfi\n\n\t# Transform deplibs into only deplibs that can be linked in shared.\n\tname_save=$name\n\tlibname_save=$libname\n\trelease_save=$release\n\tversuffix_save=$versuffix\n\tmajor_save=$major\n\t# I'm not sure if I'm treating the release correctly.  I think\n\t# release should show up in the -l (ie -lgmp5) so we don't want to\n\t# add it in twice.  Is that correct?\n\trelease=\n\tversuffix=\n\tmajor=\n\tnewdeplibs=\n\tdroppeddeps=no\n\tcase $deplibs_check_method in\n\tpass_all)\n\t  # Don't check for shared/static.  Everything works.\n\t  # This might be a little naive.  We might want to check\n\t  # whether the library exists or not.  But this is on\n\t  # osf3 & osf4 and I'm not really sure... Just\n\t  # implementing what was already the behavior.\n\t  newdeplibs=$deplibs\n\t  ;;\n\ttest_compile)\n\t  # This code stresses the \"libraries are programs\" paradigm to its\n\t  # limits. Maybe even breaks it.  We compile a program, linking it\n\t  # against the deplibs as a proxy for the library.  Then we can check\n\t  # whether they linked in statically or dynamically with ldd.\n\t  $opt_dry_run || $RM conftest.c\n\t  cat > conftest.c <<EOF\n\t  int main() { return 0; }\nEOF\n\t  $opt_dry_run || $RM conftest\n\t  if $LTCC $LTCFLAGS -o conftest conftest.c $deplibs; then\n\t    ldd_output=`ldd conftest`\n\t    for i in $deplibs; do\n\t      case $i in\n\t      -l*)\n\t\tfunc_stripname -l '' \"$i\"\n\t\tname=$func_stripname_result\n\t\tif test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t\t  case \" $predeps $postdeps \" in\n\t\t  *\" $i \"*)\n\t\t    func_append newdeplibs \" $i\"\n\t\t    i=\n\t\t    ;;\n\t\t  esac\n\t\tfi\n\t\tif test -n \"$i\"; then\n\t\t  libname=`eval \"\\\\$ECHO \\\"$libname_spec\\\"\"`\n\t\t  deplib_matches=`eval \"\\\\$ECHO \\\"$library_names_spec\\\"\"`\n\t\t  set dummy $deplib_matches; shift\n\t\t  deplib_match=$1\n\t\t  if test `expr \"$ldd_output\" : \".*$deplib_match\"` -ne 0; then\n\t\t    func_append newdeplibs \" $i\"\n\t\t  else\n\t\t    droppeddeps=yes\n\t\t    echo\n\t\t    $ECHO \"*** Warning: dynamic linker does not accept needed library $i.\"\n\t\t    echo \"*** I have the capability to make that library automatically link in when\"\n\t\t    echo \"*** you link to this library.  But I can only do this if you have a\"\n\t\t    echo \"*** shared version of the library, which I believe you do not have\"\n\t\t    echo \"*** because a test_compile did reveal that the linker did not use it for\"\n\t\t    echo \"*** its dynamic dependency list that programs get resolved with at runtime.\"\n\t\t  fi\n\t\tfi\n\t\t;;\n\t      *)\n\t\tfunc_append newdeplibs \" $i\"\n\t\t;;\n\t      esac\n\t    done\n\t  else\n\t    # Error occurred in the first compile.  Let's try to salvage\n\t    # the situation: Compile a separate program for each library.\n\t    for i in $deplibs; do\n\t      case $i in\n\t      -l*)\n\t\tfunc_stripname -l '' \"$i\"\n\t\tname=$func_stripname_result\n\t\t$opt_dry_run || $RM conftest\n\t\tif $LTCC $LTCFLAGS -o conftest conftest.c $i; then\n\t\t  ldd_output=`ldd conftest`\n\t\t  if test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t\t    case \" $predeps $postdeps \" in\n\t\t    *\" $i \"*)\n\t\t      func_append newdeplibs \" $i\"\n\t\t      i=\n\t\t      ;;\n\t\t    esac\n\t\t  fi\n\t\t  if test -n \"$i\"; then\n\t\t    libname=`eval \"\\\\$ECHO \\\"$libname_spec\\\"\"`\n\t\t    deplib_matches=`eval \"\\\\$ECHO \\\"$library_names_spec\\\"\"`\n\t\t    set dummy $deplib_matches; shift\n\t\t    deplib_match=$1\n\t\t    if test `expr \"$ldd_output\" : \".*$deplib_match\"` -ne 0; then\n\t\t      func_append newdeplibs \" $i\"\n\t\t    else\n\t\t      droppeddeps=yes\n\t\t      echo\n\t\t      $ECHO \"*** Warning: dynamic linker does not accept needed library $i.\"\n\t\t      echo \"*** I have the capability to make that library automatically link in when\"\n\t\t      echo \"*** you link to this library.  But I can only do this if you have a\"\n\t\t      echo \"*** shared version of the library, which you do not appear to have\"\n\t\t      echo \"*** because a test_compile did reveal that the linker did not use this one\"\n\t\t      echo \"*** as a dynamic dependency that programs can get resolved with at runtime.\"\n\t\t    fi\n\t\t  fi\n\t\telse\n\t\t  droppeddeps=yes\n\t\t  echo\n\t\t  $ECHO \"*** Warning!  Library $i is needed by this library but I was not able to\"\n\t\t  echo \"*** make it link in!  You will probably need to install it or some\"\n\t\t  echo \"*** library that it depends on before this library will be fully\"\n\t\t  echo \"*** functional.  Installing it before continuing would be even better.\"\n\t\tfi\n\t\t;;\n\t      *)\n\t\tfunc_append newdeplibs \" $i\"\n\t\t;;\n\t      esac\n\t    done\n\t  fi\n\t  ;;\n\tfile_magic*)\n\t  set dummy $deplibs_check_method; shift\n\t  file_magic_regex=`expr \"$deplibs_check_method\" : \"$1 \\(.*\\)\"`\n\t  for a_deplib in $deplibs; do\n\t    case $a_deplib in\n\t    -l*)\n\t      func_stripname -l '' \"$a_deplib\"\n\t      name=$func_stripname_result\n\t      if test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t\tcase \" $predeps $postdeps \" in\n\t\t*\" $a_deplib \"*)\n\t\t  func_append newdeplibs \" $a_deplib\"\n\t\t  a_deplib=\n\t\t  ;;\n\t\tesac\n\t      fi\n\t      if test -n \"$a_deplib\"; then\n\t\tlibname=`eval \"\\\\$ECHO \\\"$libname_spec\\\"\"`\n\t\tif test -n \"$file_magic_glob\"; then\n\t\t  libnameglob=`func_echo_all \"$libname\" | $SED -e $file_magic_glob`\n\t\telse\n\t\t  libnameglob=$libname\n\t\tfi\n\t\ttest yes = \"$want_nocaseglob\" && nocaseglob=`shopt -p nocaseglob`\n\t\tfor i in $lib_search_path $sys_lib_search_path $shlib_search_path; do\n\t\t  if test yes = \"$want_nocaseglob\"; then\n\t\t    shopt -s nocaseglob\n\t\t    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`\n\t\t    $nocaseglob\n\t\t  else\n\t\t    potential_libs=`ls $i/$libnameglob[.-]* 2>/dev/null`\n\t\t  fi\n\t\t  for potent_lib in $potential_libs; do\n\t\t      # Follow soft links.\n\t\t      if ls -lLd \"$potent_lib\" 2>/dev/null |\n\t\t\t $GREP \" -> \" >/dev/null; then\n\t\t\tcontinue\n\t\t      fi\n\t\t      # The statement above tries to avoid entering an\n\t\t      # endless loop below, in case of cyclic links.\n\t\t      # We might still enter an endless loop, since a link\n\t\t      # loop can be closed while we follow links,\n\t\t      # but so what?\n\t\t      potlib=$potent_lib\n\t\t      while test -h \"$potlib\" 2>/dev/null; do\n\t\t\tpotliblink=`ls -ld $potlib | $SED 's/.* -> //'`\n\t\t\tcase $potliblink in\n\t\t\t[\\\\/]* | [A-Za-z]:[\\\\/]*) potlib=$potliblink;;\n\t\t\t*) potlib=`$ECHO \"$potlib\" | $SED 's|[^/]*$||'`\"$potliblink\";;\n\t\t\tesac\n\t\t      done\n\t\t      if eval $file_magic_cmd \\\"\\$potlib\\\" 2>/dev/null |\n\t\t\t $SED -e 10q |\n\t\t\t $EGREP \"$file_magic_regex\" > /dev/null; then\n\t\t\tfunc_append newdeplibs \" $a_deplib\"\n\t\t\ta_deplib=\n\t\t\tbreak 2\n\t\t      fi\n\t\t  done\n\t\tdone\n\t      fi\n\t      if test -n \"$a_deplib\"; then\n\t\tdroppeddeps=yes\n\t\techo\n\t\t$ECHO \"*** Warning: linker path does not have real file for library $a_deplib.\"\n\t\techo \"*** I have the capability to make that library automatically link in when\"\n\t\techo \"*** you link to this library.  But I can only do this if you have a\"\n\t\techo \"*** shared version of the library, which you do not appear to have\"\n\t\techo \"*** because I did check the linker path looking for a file starting\"\n\t\tif test -z \"$potlib\"; then\n\t\t  $ECHO \"*** with $libname but no candidates were found. (...for file magic test)\"\n\t\telse\n\t\t  $ECHO \"*** with $libname and none of the candidates passed a file format test\"\n\t\t  $ECHO \"*** using a file magic. Last file checked: $potlib\"\n\t\tfi\n\t      fi\n\t      ;;\n\t    *)\n\t      # Add a -L argument.\n\t      func_append newdeplibs \" $a_deplib\"\n\t      ;;\n\t    esac\n\t  done # Gone through all deplibs.\n\t  ;;\n\tmatch_pattern*)\n\t  set dummy $deplibs_check_method; shift\n\t  match_pattern_regex=`expr \"$deplibs_check_method\" : \"$1 \\(.*\\)\"`\n\t  for a_deplib in $deplibs; do\n\t    case $a_deplib in\n\t    -l*)\n\t      func_stripname -l '' \"$a_deplib\"\n\t      name=$func_stripname_result\n\t      if test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t\tcase \" $predeps $postdeps \" in\n\t\t*\" $a_deplib \"*)\n\t\t  func_append newdeplibs \" $a_deplib\"\n\t\t  a_deplib=\n\t\t  ;;\n\t\tesac\n\t      fi\n\t      if test -n \"$a_deplib\"; then\n\t\tlibname=`eval \"\\\\$ECHO \\\"$libname_spec\\\"\"`\n\t\tfor i in $lib_search_path $sys_lib_search_path $shlib_search_path; do\n\t\t  potential_libs=`ls $i/$libname[.-]* 2>/dev/null`\n\t\t  for potent_lib in $potential_libs; do\n\t\t    potlib=$potent_lib # see symlink-check above in file_magic test\n\t\t    if eval \"\\$ECHO \\\"$potent_lib\\\"\" 2>/dev/null | $SED 10q | \\\n\t\t       $EGREP \"$match_pattern_regex\" > /dev/null; then\n\t\t      func_append newdeplibs \" $a_deplib\"\n\t\t      a_deplib=\n\t\t      break 2\n\t\t    fi\n\t\t  done\n\t\tdone\n\t      fi\n\t      if test -n \"$a_deplib\"; then\n\t\tdroppeddeps=yes\n\t\techo\n\t\t$ECHO \"*** Warning: linker path does not have real file for library $a_deplib.\"\n\t\techo \"*** I have the capability to make that library automatically link in when\"\n\t\techo \"*** you link to this library.  But I can only do this if you have a\"\n\t\techo \"*** shared version of the library, which you do not appear to have\"\n\t\techo \"*** because I did check the linker path looking for a file starting\"\n\t\tif test -z \"$potlib\"; then\n\t\t  $ECHO \"*** with $libname but no candidates were found. (...for regex pattern test)\"\n\t\telse\n\t\t  $ECHO \"*** with $libname and none of the candidates passed a file format test\"\n\t\t  $ECHO \"*** using a regex pattern. Last file checked: $potlib\"\n\t\tfi\n\t      fi\n\t      ;;\n\t    *)\n\t      # Add a -L argument.\n\t      func_append newdeplibs \" $a_deplib\"\n\t      ;;\n\t    esac\n\t  done # Gone through all deplibs.\n\t  ;;\n\tnone | unknown | *)\n\t  newdeplibs=\n\t  tmp_deplibs=`$ECHO \" $deplibs\" | $SED 's/ -lc$//; s/ -[LR][^ ]*//g'`\n\t  if test yes = \"$allow_libtool_libs_with_static_runtimes\"; then\n\t    for i in $predeps $postdeps; do\n\t      # can't use Xsed below, because $i might contain '/'\n\t      tmp_deplibs=`$ECHO \" $tmp_deplibs\" | $SED \"s|$i||\"`\n\t    done\n\t  fi\n\t  case $tmp_deplibs in\n\t  *[!\\\t\\ ]*)\n\t    echo\n\t    if test none = \"$deplibs_check_method\"; then\n\t      echo \"*** Warning: inter-library dependencies are not supported in this platform.\"\n\t    else\n\t      echo \"*** Warning: inter-library dependencies are not known to be supported.\"\n\t    fi\n\t    echo \"*** All declared inter-library dependencies are being dropped.\"\n\t    droppeddeps=yes\n\t    ;;\n\t  esac\n\t  ;;\n\tesac\n\tversuffix=$versuffix_save\n\tmajor=$major_save\n\trelease=$release_save\n\tlibname=$libname_save\n\tname=$name_save\n\n\tcase $host in\n\t*-*-rhapsody* | *-*-darwin1.[012])\n\t  # On Rhapsody replace the C library with the System framework\n\t  newdeplibs=`$ECHO \" $newdeplibs\" | $SED 's/ -lc / System.ltframework /'`\n\t  ;;\n\tesac\n\n\tif test yes = \"$droppeddeps\"; then\n\t  if test yes = \"$module\"; then\n\t    echo\n\t    echo \"*** Warning: libtool could not satisfy all declared inter-library\"\n\t    $ECHO \"*** dependencies of module $libname.  Therefore, libtool will create\"\n\t    echo \"*** a static module, that should work as long as the dlopening\"\n\t    echo \"*** application is linked with the -dlopen flag.\"\n\t    if test -z \"$global_symbol_pipe\"; then\n\t      echo\n\t      echo \"*** However, this would only work if libtool was able to extract symbol\"\n\t      echo \"*** lists from a program, using 'nm' or equivalent, but libtool could\"\n\t      echo \"*** not find such a program.  So, this module is probably useless.\"\n\t      echo \"*** 'nm' from GNU binutils and a full rebuild may help.\"\n\t    fi\n\t    if test no = \"$build_old_libs\"; then\n\t      oldlibs=$output_objdir/$libname.$libext\n\t      build_libtool_libs=module\n\t      build_old_libs=yes\n\t    else\n\t      build_libtool_libs=no\n\t    fi\n\t  else\n\t    echo \"*** The inter-library dependencies that have been dropped here will be\"\n\t    echo \"*** automatically added whenever a program is linked with this library\"\n\t    echo \"*** or is declared to -dlopen it.\"\n\n\t    if test no = \"$allow_undefined\"; then\n\t      echo\n\t      echo \"*** Since this library must not contain undefined symbols,\"\n\t      echo \"*** because either the platform does not support them or\"\n\t      echo \"*** it was explicitly requested with -no-undefined,\"\n\t      echo \"*** libtool will only create a static version of it.\"\n\t      if test no = \"$build_old_libs\"; then\n\t\toldlibs=$output_objdir/$libname.$libext\n\t\tbuild_libtool_libs=module\n\t\tbuild_old_libs=yes\n\t      else\n\t\tbuild_libtool_libs=no\n\t      fi\n\t    fi\n\t  fi\n\tfi\n\t# Done checking deplibs!\n\tdeplibs=$newdeplibs\n      fi\n      # Time to change all our \"foo.ltframework\" stuff back to \"-framework foo\"\n      case $host in\n\t*-*-darwin*)\n\t  newdeplibs=`$ECHO \" $newdeplibs\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\t  new_inherited_linker_flags=`$ECHO \" $new_inherited_linker_flags\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\t  deplibs=`$ECHO \" $deplibs\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\t  ;;\n      esac\n\n      # move library search paths that coincide with paths to not yet\n      # installed libraries to the beginning of the library search list\n      new_libs=\n      for path in $notinst_path; do\n\tcase \" $new_libs \" in\n\t*\" -L$path/$objdir \"*) ;;\n\t*)\n\t  case \" $deplibs \" in\n\t  *\" -L$path/$objdir \"*)\n\t    func_append new_libs \" -L$path/$objdir\" ;;\n\t  esac\n\t  ;;\n\tesac\n      done\n      for deplib in $deplibs; do\n\tcase $deplib in\n\t-L*)\n\t  case \" $new_libs \" in\n\t  *\" $deplib \"*) ;;\n\t  *) func_append new_libs \" $deplib\" ;;\n\t  esac\n\t  ;;\n\t*) func_append new_libs \" $deplib\" ;;\n\tesac\n      done\n      deplibs=$new_libs\n\n      # All the library-specific variables (install_libdir is set above).\n      library_names=\n      old_library=\n      dlname=\n\n      # Test again, we may have decided not to build it any more\n      if test yes = \"$build_libtool_libs\"; then\n\t# Remove $wl instances when linking with ld.\n\t# FIXME: should test the right _cmds variable.\n\tcase $archive_cmds in\n\t  *\\$LD\\ *) wl= ;;\n        esac\n\tif test yes = \"$hardcode_into_libs\"; then\n\t  # Hardcode the library paths\n\t  hardcode_libdirs=\n\t  dep_rpath=\n\t  rpath=$finalize_rpath\n\t  test relink = \"$opt_mode\" || rpath=$compile_rpath$rpath\n\t  for libdir in $rpath; do\n\t    if test -n \"$hardcode_libdir_flag_spec\"; then\n\t      if test -n \"$hardcode_libdir_separator\"; then\n\t\tfunc_replace_sysroot \"$libdir\"\n\t\tlibdir=$func_replace_sysroot_result\n\t\tif test -z \"$hardcode_libdirs\"; then\n\t\t  hardcode_libdirs=$libdir\n\t\telse\n\t\t  # Just accumulate the unique libdirs.\n\t\t  case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in\n\t\t  *\"$hardcode_libdir_separator$libdir$hardcode_libdir_separator\"*)\n\t\t    ;;\n\t\t  *)\n\t\t    func_append hardcode_libdirs \"$hardcode_libdir_separator$libdir\"\n\t\t    ;;\n\t\t  esac\n\t\tfi\n\t      else\n\t\teval flag=\\\"$hardcode_libdir_flag_spec\\\"\n\t\tfunc_append dep_rpath \" $flag\"\n\t      fi\n\t    elif test -n \"$runpath_var\"; then\n\t      case \"$perm_rpath \" in\n\t      *\" $libdir \"*) ;;\n\t      *) func_append perm_rpath \" $libdir\" ;;\n\t      esac\n\t    fi\n\t  done\n\t  # Substitute the hardcoded libdirs into the rpath.\n\t  if test -n \"$hardcode_libdir_separator\" &&\n\t     test -n \"$hardcode_libdirs\"; then\n\t    libdir=$hardcode_libdirs\n\t    eval \"dep_rpath=\\\"$hardcode_libdir_flag_spec\\\"\"\n\t  fi\n\t  if test -n \"$runpath_var\" && test -n \"$perm_rpath\"; then\n\t    # We should set the runpath_var.\n\t    rpath=\n\t    for dir in $perm_rpath; do\n\t      func_append rpath \"$dir:\"\n\t    done\n\t    eval \"$runpath_var='$rpath\\$$runpath_var'; export $runpath_var\"\n\t  fi\n\t  test -n \"$dep_rpath\" && deplibs=\"$dep_rpath $deplibs\"\n\tfi\n\n\tshlibpath=$finalize_shlibpath\n\ttest relink = \"$opt_mode\" || shlibpath=$compile_shlibpath$shlibpath\n\tif test -n \"$shlibpath\"; then\n\t  eval \"$shlibpath_var='$shlibpath\\$$shlibpath_var'; export $shlibpath_var\"\n\tfi\n\n\t# Get the real and link names of the library.\n\teval shared_ext=\\\"$shrext_cmds\\\"\n\teval library_names=\\\"$library_names_spec\\\"\n\tset dummy $library_names\n\tshift\n\trealname=$1\n\tshift\n\n\tif test -n \"$soname_spec\"; then\n\t  eval soname=\\\"$soname_spec\\\"\n\telse\n\t  soname=$realname\n\tfi\n\tif test -z \"$dlname\"; then\n\t  dlname=$soname\n\tfi\n\n\tlib=$output_objdir/$realname\n\tlinknames=\n\tfor link\n\tdo\n\t  func_append linknames \" $link\"\n\tdone\n\n\t# Use standard objects if they are pic\n\ttest -z \"$pic_flag\" && libobjs=`$ECHO \"$libobjs\" | $SP2NL | $SED \"$lo2o\" | $NL2SP`\n\ttest \"X$libobjs\" = \"X \" && libobjs=\n\n\tdelfiles=\n\tif test -n \"$export_symbols\" && test -n \"$include_expsyms\"; then\n\t  $opt_dry_run || cp \"$export_symbols\" \"$output_objdir/$libname.uexp\"\n\t  export_symbols=$output_objdir/$libname.uexp\n\t  func_append delfiles \" $export_symbols\"\n\tfi\n\n\torig_export_symbols=\n\tcase $host_os in\n\tcygwin* | mingw* | cegcc*)\n\t  if test -n \"$export_symbols\" && test -z \"$export_symbols_regex\"; then\n\t    # exporting using user supplied symfile\n\t    func_dll_def_p \"$export_symbols\" || {\n\t      # and it's NOT already a .def file. Must figure out\n\t      # which of the given symbols are data symbols and tag\n\t      # them as such. So, trigger use of export_symbols_cmds.\n\t      # export_symbols gets reassigned inside the \"prepare\n\t      # the list of exported symbols\" if statement, so the\n\t      # include_expsyms logic still works.\n\t      orig_export_symbols=$export_symbols\n\t      export_symbols=\n\t      always_export_symbols=yes\n\t    }\n\t  fi\n\t  ;;\n\tesac\n\n\t# Prepare the list of exported symbols\n\tif test -z \"$export_symbols\"; then\n\t  if test yes = \"$always_export_symbols\" || test -n \"$export_symbols_regex\"; then\n\t    func_verbose \"generating symbol list for '$libname.la'\"\n\t    export_symbols=$output_objdir/$libname.exp\n\t    $opt_dry_run || $RM $export_symbols\n\t    cmds=$export_symbols_cmds\n\t    save_ifs=$IFS; IFS='~'\n\t    for cmd1 in $cmds; do\n\t      IFS=$save_ifs\n\t      # Take the normal branch if the nm_file_list_spec branch\n\t      # doesn't work or if tool conversion is not needed.\n\t      case $nm_file_list_spec~$to_tool_file_cmd in\n\t\t*~func_convert_file_noop | *~func_convert_file_msys_to_w32 | ~*)\n\t\t  try_normal_branch=yes\n\t\t  eval cmd=\\\"$cmd1\\\"\n\t\t  func_len \" $cmd\"\n\t\t  len=$func_len_result\n\t\t  ;;\n\t\t*)\n\t\t  try_normal_branch=no\n\t\t  ;;\n\t      esac\n\t      if test yes = \"$try_normal_branch\" \\\n\t\t && { test \"$len\" -lt \"$max_cmd_len\" \\\n\t\t      || test \"$max_cmd_len\" -le -1; }\n\t      then\n\t\tfunc_show_eval \"$cmd\" 'exit $?'\n\t\tskipped_export=false\n\t      elif test -n \"$nm_file_list_spec\"; then\n\t\tfunc_basename \"$output\"\n\t\toutput_la=$func_basename_result\n\t\tsave_libobjs=$libobjs\n\t\tsave_output=$output\n\t\toutput=$output_objdir/$output_la.nm\n\t\tfunc_to_tool_file \"$output\"\n\t\tlibobjs=$nm_file_list_spec$func_to_tool_file_result\n\t\tfunc_append delfiles \" $output\"\n\t\tfunc_verbose \"creating $NM input file list: $output\"\n\t\tfor obj in $save_libobjs; do\n\t\t  func_to_tool_file \"$obj\"\n\t\t  $ECHO \"$func_to_tool_file_result\"\n\t\tdone > \"$output\"\n\t\teval cmd=\\\"$cmd1\\\"\n\t\tfunc_show_eval \"$cmd\" 'exit $?'\n\t\toutput=$save_output\n\t\tlibobjs=$save_libobjs\n\t\tskipped_export=false\n\t      else\n\t\t# The command line is too long to execute in one step.\n\t\tfunc_verbose \"using reloadable object file for export list...\"\n\t\tskipped_export=:\n\t\t# Break out early, otherwise skipped_export may be\n\t\t# set to false by a later but shorter cmd.\n\t\tbreak\n\t      fi\n\t    done\n\t    IFS=$save_ifs\n\t    if test -n \"$export_symbols_regex\" && test : != \"$skipped_export\"; then\n\t      func_show_eval '$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"'\n\t      func_show_eval '$MV \"${export_symbols}T\" \"$export_symbols\"'\n\t    fi\n\t  fi\n\tfi\n\n\tif test -n \"$export_symbols\" && test -n \"$include_expsyms\"; then\n\t  tmp_export_symbols=$export_symbols\n\t  test -n \"$orig_export_symbols\" && tmp_export_symbols=$orig_export_symbols\n\t  $opt_dry_run || eval '$ECHO \"$include_expsyms\" | $SP2NL >> \"$tmp_export_symbols\"'\n\tfi\n\n\tif test : != \"$skipped_export\" && test -n \"$orig_export_symbols\"; then\n\t  # The given exports_symbols file has to be filtered, so filter it.\n\t  func_verbose \"filter symbol list for '$libname.la' to tag DATA exports\"\n\t  # FIXME: $output_objdir/$libname.filter potentially contains lots of\n\t  # 's' commands, which not all seds can handle. GNU sed should be fine\n\t  # though. Also, the filter scales superlinearly with the number of\n\t  # global variables. join(1) would be nice here, but unfortunately\n\t  # isn't a blessed tool.\n\t  $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\\(.*\\)\\([ \\,].*\\),s|^\\1$|\\1\\2|,' < $export_symbols > $output_objdir/$libname.filter\n\t  func_append delfiles \" $export_symbols $output_objdir/$libname.filter\"\n\t  export_symbols=$output_objdir/$libname.def\n\t  $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols\n\tfi\n\n\ttmp_deplibs=\n\tfor test_deplib in $deplibs; do\n\t  case \" $convenience \" in\n\t  *\" $test_deplib \"*) ;;\n\t  *)\n\t    func_append tmp_deplibs \" $test_deplib\"\n\t    ;;\n\t  esac\n\tdone\n\tdeplibs=$tmp_deplibs\n\n\tif test -n \"$convenience\"; then\n\t  if test -n \"$whole_archive_flag_spec\" &&\n\t    test yes = \"$compiler_needs_object\" &&\n\t    test -z \"$libobjs\"; then\n\t    # extract the archives, so we have objects to list.\n\t    # TODO: could optimize this to just extract one archive.\n\t    whole_archive_flag_spec=\n\t  fi\n\t  if test -n \"$whole_archive_flag_spec\"; then\n\t    save_libobjs=$libobjs\n\t    eval libobjs=\\\"\\$libobjs $whole_archive_flag_spec\\\"\n\t    test \"X$libobjs\" = \"X \" && libobjs=\n\t  else\n\t    gentop=$output_objdir/${outputname}x\n\t    func_append generated \" $gentop\"\n\n\t    func_extract_archives $gentop $convenience\n\t    func_append libobjs \" $func_extract_archives_result\"\n\t    test \"X$libobjs\" = \"X \" && libobjs=\n\t  fi\n\tfi\n\n\tif test yes = \"$thread_safe\" && test -n \"$thread_safe_flag_spec\"; then\n\t  eval flag=\\\"$thread_safe_flag_spec\\\"\n\t  func_append linker_flags \" $flag\"\n\tfi\n\n\t# Make a backup of the uninstalled library when relinking\n\tif test relink = \"$opt_mode\"; then\n\t  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}U && $MV $realname ${realname}U)' || exit $?\n\tfi\n\n\t# Do each of the archive commands.\n\tif test yes = \"$module\" && test -n \"$module_cmds\"; then\n\t  if test -n \"$export_symbols\" && test -n \"$module_expsym_cmds\"; then\n\t    eval test_cmds=\\\"$module_expsym_cmds\\\"\n\t    cmds=$module_expsym_cmds\n\t  else\n\t    eval test_cmds=\\\"$module_cmds\\\"\n\t    cmds=$module_cmds\n\t  fi\n\telse\n\t  if test -n \"$export_symbols\" && test -n \"$archive_expsym_cmds\"; then\n\t    eval test_cmds=\\\"$archive_expsym_cmds\\\"\n\t    cmds=$archive_expsym_cmds\n\t  else\n\t    eval test_cmds=\\\"$archive_cmds\\\"\n\t    cmds=$archive_cmds\n\t  fi\n\tfi\n\n\tif test : != \"$skipped_export\" &&\n\t   func_len \" $test_cmds\" &&\n\t   len=$func_len_result &&\n\t   test \"$len\" -lt \"$max_cmd_len\" || test \"$max_cmd_len\" -le -1; then\n\t  :\n\telse\n\t  # The command line is too long to link in one step, link piecewise\n\t  # or, if using GNU ld and skipped_export is not :, use a linker\n\t  # script.\n\n\t  # Save the value of $output and $libobjs because we want to\n\t  # use them later.  If we have whole_archive_flag_spec, we\n\t  # want to use save_libobjs as it was before\n\t  # whole_archive_flag_spec was expanded, because we can't\n\t  # assume the linker understands whole_archive_flag_spec.\n\t  # This may have to be revisited, in case too many\n\t  # convenience libraries get linked in and end up exceeding\n\t  # the spec.\n\t  if test -z \"$convenience\" || test -z \"$whole_archive_flag_spec\"; then\n\t    save_libobjs=$libobjs\n\t  fi\n\t  save_output=$output\n\t  func_basename \"$output\"\n\t  output_la=$func_basename_result\n\n\t  # Clear the reloadable object creation command queue and\n\t  # initialize k to one.\n\t  test_cmds=\n\t  concat_cmds=\n\t  objlist=\n\t  last_robj=\n\t  k=1\n\n\t  if test -n \"$save_libobjs\" && test : != \"$skipped_export\" && test yes = \"$with_gnu_ld\"; then\n\t    output=$output_objdir/$output_la.lnkscript\n\t    func_verbose \"creating GNU ld script: $output\"\n\t    echo 'INPUT (' > $output\n\t    for obj in $save_libobjs\n\t    do\n\t      func_to_tool_file \"$obj\"\n\t      $ECHO \"$func_to_tool_file_result\" >> $output\n\t    done\n\t    echo ')' >> $output\n\t    func_append delfiles \" $output\"\n\t    func_to_tool_file \"$output\"\n\t    output=$func_to_tool_file_result\n\t  elif test -n \"$save_libobjs\" && test : != \"$skipped_export\" && test -n \"$file_list_spec\"; then\n\t    output=$output_objdir/$output_la.lnk\n\t    func_verbose \"creating linker input file list: $output\"\n\t    : > $output\n\t    set x $save_libobjs\n\t    shift\n\t    firstobj=\n\t    if test yes = \"$compiler_needs_object\"; then\n\t      firstobj=\"$1 \"\n\t      shift\n\t    fi\n\t    for obj\n\t    do\n\t      func_to_tool_file \"$obj\"\n\t      $ECHO \"$func_to_tool_file_result\" >> $output\n\t    done\n\t    func_append delfiles \" $output\"\n\t    func_to_tool_file \"$output\"\n\t    output=$firstobj\\\"$file_list_spec$func_to_tool_file_result\\\"\n\t  else\n\t    if test -n \"$save_libobjs\"; then\n\t      func_verbose \"creating reloadable object files...\"\n\t      output=$output_objdir/$output_la-$k.$objext\n\t      eval test_cmds=\\\"$reload_cmds\\\"\n\t      func_len \" $test_cmds\"\n\t      len0=$func_len_result\n\t      len=$len0\n\n\t      # Loop over the list of objects to be linked.\n\t      for obj in $save_libobjs\n\t      do\n\t\tfunc_len \" $obj\"\n\t\tfunc_arith $len + $func_len_result\n\t\tlen=$func_arith_result\n\t\tif test -z \"$objlist\" ||\n\t\t   test \"$len\" -lt \"$max_cmd_len\"; then\n\t\t  func_append objlist \" $obj\"\n\t\telse\n\t\t  # The command $test_cmds is almost too long, add a\n\t\t  # command to the queue.\n\t\t  if test 1 -eq \"$k\"; then\n\t\t    # The first file doesn't have a previous command to add.\n\t\t    reload_objs=$objlist\n\t\t    eval concat_cmds=\\\"$reload_cmds\\\"\n\t\t  else\n\t\t    # All subsequent reloadable object files will link in\n\t\t    # the last one created.\n\t\t    reload_objs=\"$objlist $last_robj\"\n\t\t    eval concat_cmds=\\\"\\$concat_cmds~$reload_cmds~\\$RM $last_robj\\\"\n\t\t  fi\n\t\t  last_robj=$output_objdir/$output_la-$k.$objext\n\t\t  func_arith $k + 1\n\t\t  k=$func_arith_result\n\t\t  output=$output_objdir/$output_la-$k.$objext\n\t\t  objlist=\" $obj\"\n\t\t  func_len \" $last_robj\"\n\t\t  func_arith $len0 + $func_len_result\n\t\t  len=$func_arith_result\n\t\tfi\n\t      done\n\t      # Handle the remaining objects by creating one last\n\t      # reloadable object file.  All subsequent reloadable object\n\t      # files will link in the last one created.\n\t      test -z \"$concat_cmds\" || concat_cmds=$concat_cmds~\n\t      reload_objs=\"$objlist $last_robj\"\n\t      eval concat_cmds=\\\"\\$concat_cmds$reload_cmds\\\"\n\t      if test -n \"$last_robj\"; then\n\t        eval concat_cmds=\\\"\\$concat_cmds~\\$RM $last_robj\\\"\n\t      fi\n\t      func_append delfiles \" $output\"\n\n\t    else\n\t      output=\n\t    fi\n\n\t    ${skipped_export-false} && {\n\t      func_verbose \"generating symbol list for '$libname.la'\"\n\t      export_symbols=$output_objdir/$libname.exp\n\t      $opt_dry_run || $RM $export_symbols\n\t      libobjs=$output\n\t      # Append the command to create the export file.\n\t      test -z \"$concat_cmds\" || concat_cmds=$concat_cmds~\n\t      eval concat_cmds=\\\"\\$concat_cmds$export_symbols_cmds\\\"\n\t      if test -n \"$last_robj\"; then\n\t\teval concat_cmds=\\\"\\$concat_cmds~\\$RM $last_robj\\\"\n\t      fi\n\t    }\n\n\t    test -n \"$save_libobjs\" &&\n\t      func_verbose \"creating a temporary reloadable object file: $output\"\n\n\t    # Loop through the commands generated above and execute them.\n\t    save_ifs=$IFS; IFS='~'\n\t    for cmd in $concat_cmds; do\n\t      IFS=$save_ifs\n\t      $opt_quiet || {\n\t\t  func_quote_for_expand \"$cmd\"\n\t\t  eval \"func_echo $func_quote_for_expand_result\"\n\t      }\n\t      $opt_dry_run || eval \"$cmd\" || {\n\t\tlt_exit=$?\n\n\t\t# Restore the uninstalled library and exit\n\t\tif test relink = \"$opt_mode\"; then\n\t\t  ( cd \"$output_objdir\" && \\\n\t\t    $RM \"${realname}T\" && \\\n\t\t    $MV \"${realname}U\" \"$realname\" )\n\t\tfi\n\n\t\texit $lt_exit\n\t      }\n\t    done\n\t    IFS=$save_ifs\n\n\t    if test -n \"$export_symbols_regex\" && ${skipped_export-false}; then\n\t      func_show_eval '$EGREP -e \"$export_symbols_regex\" \"$export_symbols\" > \"${export_symbols}T\"'\n\t      func_show_eval '$MV \"${export_symbols}T\" \"$export_symbols\"'\n\t    fi\n\t  fi\n\n          ${skipped_export-false} && {\n\t    if test -n \"$export_symbols\" && test -n \"$include_expsyms\"; then\n\t      tmp_export_symbols=$export_symbols\n\t      test -n \"$orig_export_symbols\" && tmp_export_symbols=$orig_export_symbols\n\t      $opt_dry_run || eval '$ECHO \"$include_expsyms\" | $SP2NL >> \"$tmp_export_symbols\"'\n\t    fi\n\n\t    if test -n \"$orig_export_symbols\"; then\n\t      # The given exports_symbols file has to be filtered, so filter it.\n\t      func_verbose \"filter symbol list for '$libname.la' to tag DATA exports\"\n\t      # FIXME: $output_objdir/$libname.filter potentially contains lots of\n\t      # 's' commands, which not all seds can handle. GNU sed should be fine\n\t      # though. Also, the filter scales superlinearly with the number of\n\t      # global variables. join(1) would be nice here, but unfortunately\n\t      # isn't a blessed tool.\n\t      $opt_dry_run || $SED -e '/[ ,]DATA/!d;s,\\(.*\\)\\([ \\,].*\\),s|^\\1$|\\1\\2|,' < $export_symbols > $output_objdir/$libname.filter\n\t      func_append delfiles \" $export_symbols $output_objdir/$libname.filter\"\n\t      export_symbols=$output_objdir/$libname.def\n\t      $opt_dry_run || $SED -f $output_objdir/$libname.filter < $orig_export_symbols > $export_symbols\n\t    fi\n\t  }\n\n\t  libobjs=$output\n\t  # Restore the value of output.\n\t  output=$save_output\n\n\t  if test -n \"$convenience\" && test -n \"$whole_archive_flag_spec\"; then\n\t    eval libobjs=\\\"\\$libobjs $whole_archive_flag_spec\\\"\n\t    test \"X$libobjs\" = \"X \" && libobjs=\n\t  fi\n\t  # Expand the library linking commands again to reset the\n\t  # value of $libobjs for piecewise linking.\n\n\t  # Do each of the archive commands.\n\t  if test yes = \"$module\" && test -n \"$module_cmds\"; then\n\t    if test -n \"$export_symbols\" && test -n \"$module_expsym_cmds\"; then\n\t      cmds=$module_expsym_cmds\n\t    else\n\t      cmds=$module_cmds\n\t    fi\n\t  else\n\t    if test -n \"$export_symbols\" && test -n \"$archive_expsym_cmds\"; then\n\t      cmds=$archive_expsym_cmds\n\t    else\n\t      cmds=$archive_cmds\n\t    fi\n\t  fi\n\tfi\n\n\tif test -n \"$delfiles\"; then\n\t  # Append the command to remove temporary files to $cmds.\n\t  eval cmds=\\\"\\$cmds~\\$RM $delfiles\\\"\n\tfi\n\n\t# Add any objects from preloaded convenience libraries\n\tif test -n \"$dlprefiles\"; then\n\t  gentop=$output_objdir/${outputname}x\n\t  func_append generated \" $gentop\"\n\n\t  func_extract_archives $gentop $dlprefiles\n\t  func_append libobjs \" $func_extract_archives_result\"\n\t  test \"X$libobjs\" = \"X \" && libobjs=\n\tfi\n\n\tsave_ifs=$IFS; IFS='~'\n\tfor cmd in $cmds; do\n\t  IFS=$sp$nl\n\t  eval cmd=\\\"$cmd\\\"\n\t  IFS=$save_ifs\n\t  $opt_quiet || {\n\t    func_quote_for_expand \"$cmd\"\n\t    eval \"func_echo $func_quote_for_expand_result\"\n\t  }\n\t  $opt_dry_run || eval \"$cmd\" || {\n\t    lt_exit=$?\n\n\t    # Restore the uninstalled library and exit\n\t    if test relink = \"$opt_mode\"; then\n\t      ( cd \"$output_objdir\" && \\\n\t        $RM \"${realname}T\" && \\\n\t\t$MV \"${realname}U\" \"$realname\" )\n\t    fi\n\n\t    exit $lt_exit\n\t  }\n\tdone\n\tIFS=$save_ifs\n\n\t# Restore the uninstalled library and exit\n\tif test relink = \"$opt_mode\"; then\n\t  $opt_dry_run || eval '(cd $output_objdir && $RM ${realname}T && $MV $realname ${realname}T && $MV ${realname}U $realname)' || exit $?\n\n\t  if test -n \"$convenience\"; then\n\t    if test -z \"$whole_archive_flag_spec\"; then\n\t      func_show_eval '${RM}r \"$gentop\"'\n\t    fi\n\t  fi\n\n\t  exit $EXIT_SUCCESS\n\tfi\n\n\t# Create links to the real library.\n\tfor linkname in $linknames; do\n\t  if test \"$realname\" != \"$linkname\"; then\n\t    func_show_eval '(cd \"$output_objdir\" && $RM \"$linkname\" && $LN_S \"$realname\" \"$linkname\")' 'exit $?'\n\t  fi\n\tdone\n\n\t# If -module or -export-dynamic was specified, set the dlname.\n\tif test yes = \"$module\" || test yes = \"$export_dynamic\"; then\n\t  # On all known operating systems, these are identical.\n\t  dlname=$soname\n\tfi\n      fi\n      ;;\n\n    obj)\n      if test -n \"$dlfiles$dlprefiles\" || test no != \"$dlself\"; then\n\tfunc_warning \"'-dlopen' is ignored for objects\"\n      fi\n\n      case \" $deplibs\" in\n      *\\ -l* | *\\ -L*)\n\tfunc_warning \"'-l' and '-L' are ignored for objects\" ;;\n      esac\n\n      test -n \"$rpath\" && \\\n\tfunc_warning \"'-rpath' is ignored for objects\"\n\n      test -n \"$xrpath\" && \\\n\tfunc_warning \"'-R' is ignored for objects\"\n\n      test -n \"$vinfo\" && \\\n\tfunc_warning \"'-version-info' is ignored for objects\"\n\n      test -n \"$release\" && \\\n\tfunc_warning \"'-release' is ignored for objects\"\n\n      case $output in\n      *.lo)\n\ttest -n \"$objs$old_deplibs\" && \\\n\t  func_fatal_error \"cannot build library object '$output' from non-libtool objects\"\n\n\tlibobj=$output\n\tfunc_lo2o \"$libobj\"\n\tobj=$func_lo2o_result\n\t;;\n      *)\n\tlibobj=\n\tobj=$output\n\t;;\n      esac\n\n      # Delete the old objects.\n      $opt_dry_run || $RM $obj $libobj\n\n      # Objects from convenience libraries.  This assumes\n      # single-version convenience libraries.  Whenever we create\n      # different ones for PIC/non-PIC, this we'll have to duplicate\n      # the extraction.\n      reload_conv_objs=\n      gentop=\n      # if reload_cmds runs $LD directly, get rid of -Wl from\n      # whole_archive_flag_spec and hope we can get by with turning comma\n      # into space.\n      case $reload_cmds in\n        *\\$LD[\\ \\$]*) wl= ;;\n      esac\n      if test -n \"$convenience\"; then\n\tif test -n \"$whole_archive_flag_spec\"; then\n\t  eval tmp_whole_archive_flags=\\\"$whole_archive_flag_spec\\\"\n\t  test -n \"$wl\" || tmp_whole_archive_flags=`$ECHO \"$tmp_whole_archive_flags\" | $SED 's|,| |g'`\n\t  reload_conv_objs=$reload_objs\\ $tmp_whole_archive_flags\n\telse\n\t  gentop=$output_objdir/${obj}x\n\t  func_append generated \" $gentop\"\n\n\t  func_extract_archives $gentop $convenience\n\t  reload_conv_objs=\"$reload_objs $func_extract_archives_result\"\n\tfi\n      fi\n\n      # If we're not building shared, we need to use non_pic_objs\n      test yes = \"$build_libtool_libs\" || libobjs=$non_pic_objects\n\n      # Create the old-style object.\n      reload_objs=$objs$old_deplibs' '`$ECHO \"$libobjs\" | $SP2NL | $SED \"/\\.$libext$/d; /\\.lib$/d; $lo2o\" | $NL2SP`' '$reload_conv_objs\n\n      output=$obj\n      func_execute_cmds \"$reload_cmds\" 'exit $?'\n\n      # Exit if we aren't doing a library object file.\n      if test -z \"$libobj\"; then\n\tif test -n \"$gentop\"; then\n\t  func_show_eval '${RM}r \"$gentop\"'\n\tfi\n\n\texit $EXIT_SUCCESS\n      fi\n\n      test yes = \"$build_libtool_libs\" || {\n\tif test -n \"$gentop\"; then\n\t  func_show_eval '${RM}r \"$gentop\"'\n\tfi\n\n\t# Create an invalid libtool object if no PIC, so that we don't\n\t# accidentally link it into a program.\n\t# $show \"echo timestamp > $libobj\"\n\t# $opt_dry_run || eval \"echo timestamp > $libobj\" || exit $?\n\texit $EXIT_SUCCESS\n      }\n\n      if test -n \"$pic_flag\" || test default != \"$pic_mode\"; then\n\t# Only do commands if we really have different PIC objects.\n\treload_objs=\"$libobjs $reload_conv_objs\"\n\toutput=$libobj\n\tfunc_execute_cmds \"$reload_cmds\" 'exit $?'\n      fi\n\n      if test -n \"$gentop\"; then\n\tfunc_show_eval '${RM}r \"$gentop\"'\n      fi\n\n      exit $EXIT_SUCCESS\n      ;;\n\n    prog)\n      case $host in\n\t*cygwin*) func_stripname '' '.exe' \"$output\"\n\t          output=$func_stripname_result.exe;;\n      esac\n      test -n \"$vinfo\" && \\\n\tfunc_warning \"'-version-info' is ignored for programs\"\n\n      test -n \"$release\" && \\\n\tfunc_warning \"'-release' is ignored for programs\"\n\n      $preload \\\n\t&& test unknown,unknown,unknown = \"$dlopen_support,$dlopen_self,$dlopen_self_static\" \\\n\t&& func_warning \"'LT_INIT([dlopen])' not used. Assuming no dlopen support.\"\n\n      case $host in\n      *-*-rhapsody* | *-*-darwin1.[012])\n\t# On Rhapsody replace the C library is the System framework\n\tcompile_deplibs=`$ECHO \" $compile_deplibs\" | $SED 's/ -lc / System.ltframework /'`\n\tfinalize_deplibs=`$ECHO \" $finalize_deplibs\" | $SED 's/ -lc / System.ltframework /'`\n\t;;\n      esac\n\n      case $host in\n      *-*-darwin*)\n\t# Don't allow lazy linking, it breaks C++ global constructors\n\t# But is supposedly fixed on 10.4 or later (yay!).\n\tif test CXX = \"$tagname\"; then\n\t  case ${MACOSX_DEPLOYMENT_TARGET-10.0} in\n\t    10.[0123])\n\t      func_append compile_command \" $wl-bind_at_load\"\n\t      func_append finalize_command \" $wl-bind_at_load\"\n\t    ;;\n\t  esac\n\tfi\n\t# Time to change all our \"foo.ltframework\" stuff back to \"-framework foo\"\n\tcompile_deplibs=`$ECHO \" $compile_deplibs\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\tfinalize_deplibs=`$ECHO \" $finalize_deplibs\" | $SED 's% \\([^ $]*\\).ltframework% -framework \\1%g'`\n\t;;\n      esac\n\n\n      # move library search paths that coincide with paths to not yet\n      # installed libraries to the beginning of the library search list\n      new_libs=\n      for path in $notinst_path; do\n\tcase \" $new_libs \" in\n\t*\" -L$path/$objdir \"*) ;;\n\t*)\n\t  case \" $compile_deplibs \" in\n\t  *\" -L$path/$objdir \"*)\n\t    func_append new_libs \" -L$path/$objdir\" ;;\n\t  esac\n\t  ;;\n\tesac\n      done\n      for deplib in $compile_deplibs; do\n\tcase $deplib in\n\t-L*)\n\t  case \" $new_libs \" in\n\t  *\" $deplib \"*) ;;\n\t  *) func_append new_libs \" $deplib\" ;;\n\t  esac\n\t  ;;\n\t*) func_append new_libs \" $deplib\" ;;\n\tesac\n      done\n      compile_deplibs=$new_libs\n\n\n      func_append compile_command \" $compile_deplibs\"\n      func_append finalize_command \" $finalize_deplibs\"\n\n      if test -n \"$rpath$xrpath\"; then\n\t# If the user specified any rpath flags, then add them.\n\tfor libdir in $rpath $xrpath; do\n\t  # This is the magic to use -rpath.\n\t  case \"$finalize_rpath \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append finalize_rpath \" $libdir\" ;;\n\t  esac\n\tdone\n      fi\n\n      # Now hardcode the library paths\n      rpath=\n      hardcode_libdirs=\n      for libdir in $compile_rpath $finalize_rpath; do\n\tif test -n \"$hardcode_libdir_flag_spec\"; then\n\t  if test -n \"$hardcode_libdir_separator\"; then\n\t    if test -z \"$hardcode_libdirs\"; then\n\t      hardcode_libdirs=$libdir\n\t    else\n\t      # Just accumulate the unique libdirs.\n\t      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in\n\t      *\"$hardcode_libdir_separator$libdir$hardcode_libdir_separator\"*)\n\t\t;;\n\t      *)\n\t\tfunc_append hardcode_libdirs \"$hardcode_libdir_separator$libdir\"\n\t\t;;\n\t      esac\n\t    fi\n\t  else\n\t    eval flag=\\\"$hardcode_libdir_flag_spec\\\"\n\t    func_append rpath \" $flag\"\n\t  fi\n\telif test -n \"$runpath_var\"; then\n\t  case \"$perm_rpath \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append perm_rpath \" $libdir\" ;;\n\t  esac\n\tfi\n\tcase $host in\n\t*-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-os2* | *-cegcc*)\n\t  testbindir=`$ECHO \"$libdir\" | $SED -e 's*/lib$*/bin*'`\n\t  case :$dllsearchpath: in\n\t  *\":$libdir:\"*) ;;\n\t  ::) dllsearchpath=$libdir;;\n\t  *) func_append dllsearchpath \":$libdir\";;\n\t  esac\n\t  case :$dllsearchpath: in\n\t  *\":$testbindir:\"*) ;;\n\t  ::) dllsearchpath=$testbindir;;\n\t  *) func_append dllsearchpath \":$testbindir\";;\n\t  esac\n\t  ;;\n\tesac\n      done\n      # Substitute the hardcoded libdirs into the rpath.\n      if test -n \"$hardcode_libdir_separator\" &&\n\t test -n \"$hardcode_libdirs\"; then\n\tlibdir=$hardcode_libdirs\n\teval rpath=\\\" $hardcode_libdir_flag_spec\\\"\n      fi\n      compile_rpath=$rpath\n\n      rpath=\n      hardcode_libdirs=\n      for libdir in $finalize_rpath; do\n\tif test -n \"$hardcode_libdir_flag_spec\"; then\n\t  if test -n \"$hardcode_libdir_separator\"; then\n\t    if test -z \"$hardcode_libdirs\"; then\n\t      hardcode_libdirs=$libdir\n\t    else\n\t      # Just accumulate the unique libdirs.\n\t      case $hardcode_libdir_separator$hardcode_libdirs$hardcode_libdir_separator in\n\t      *\"$hardcode_libdir_separator$libdir$hardcode_libdir_separator\"*)\n\t\t;;\n\t      *)\n\t\tfunc_append hardcode_libdirs \"$hardcode_libdir_separator$libdir\"\n\t\t;;\n\t      esac\n\t    fi\n\t  else\n\t    eval flag=\\\"$hardcode_libdir_flag_spec\\\"\n\t    func_append rpath \" $flag\"\n\t  fi\n\telif test -n \"$runpath_var\"; then\n\t  case \"$finalize_perm_rpath \" in\n\t  *\" $libdir \"*) ;;\n\t  *) func_append finalize_perm_rpath \" $libdir\" ;;\n\t  esac\n\tfi\n      done\n      # Substitute the hardcoded libdirs into the rpath.\n      if test -n \"$hardcode_libdir_separator\" &&\n\t test -n \"$hardcode_libdirs\"; then\n\tlibdir=$hardcode_libdirs\n\teval rpath=\\\" $hardcode_libdir_flag_spec\\\"\n      fi\n      finalize_rpath=$rpath\n\n      if test -n \"$libobjs\" && test yes = \"$build_old_libs\"; then\n\t# Transform all the library objects into standard objects.\n\tcompile_command=`$ECHO \"$compile_command\" | $SP2NL | $SED \"$lo2o\" | $NL2SP`\n\tfinalize_command=`$ECHO \"$finalize_command\" | $SP2NL | $SED \"$lo2o\" | $NL2SP`\n      fi\n\n      func_generate_dlsyms \"$outputname\" \"@PROGRAM@\" false\n\n      # template prelinking step\n      if test -n \"$prelink_cmds\"; then\n\tfunc_execute_cmds \"$prelink_cmds\" 'exit $?'\n      fi\n\n      wrappers_required=:\n      case $host in\n      *cegcc* | *mingw32ce*)\n        # Disable wrappers for cegcc and mingw32ce hosts, we are cross compiling anyway.\n        wrappers_required=false\n        ;;\n      *cygwin* | *mingw* )\n        test yes = \"$build_libtool_libs\" || wrappers_required=false\n        ;;\n      *)\n        if test no = \"$need_relink\" || test yes != \"$build_libtool_libs\"; then\n          wrappers_required=false\n        fi\n        ;;\n      esac\n      $wrappers_required || {\n\t# Replace the output file specification.\n\tcompile_command=`$ECHO \"$compile_command\" | $SED 's%@OUTPUT@%'\"$output\"'%g'`\n\tlink_command=$compile_command$compile_rpath\n\n\t# We have no uninstalled library dependencies, so finalize right now.\n\texit_status=0\n\tfunc_show_eval \"$link_command\" 'exit_status=$?'\n\n\tif test -n \"$postlink_cmds\"; then\n\t  func_to_tool_file \"$output\"\n\t  postlink_cmds=`func_echo_all \"$postlink_cmds\" | $SED -e 's%@OUTPUT@%'\"$output\"'%g' -e 's%@TOOL_OUTPUT@%'\"$func_to_tool_file_result\"'%g'`\n\t  func_execute_cmds \"$postlink_cmds\" 'exit $?'\n\tfi\n\n\t# Delete the generated files.\n\tif test -f \"$output_objdir/${outputname}S.$objext\"; then\n\t  func_show_eval '$RM \"$output_objdir/${outputname}S.$objext\"'\n\tfi\n\n\texit $exit_status\n      }\n\n      if test -n \"$compile_shlibpath$finalize_shlibpath\"; then\n\tcompile_command=\"$shlibpath_var=\\\"$compile_shlibpath$finalize_shlibpath\\$$shlibpath_var\\\" $compile_command\"\n      fi\n      if test -n \"$finalize_shlibpath\"; then\n\tfinalize_command=\"$shlibpath_var=\\\"$finalize_shlibpath\\$$shlibpath_var\\\" $finalize_command\"\n      fi\n\n      compile_var=\n      finalize_var=\n      if test -n \"$runpath_var\"; then\n\tif test -n \"$perm_rpath\"; then\n\t  # We should set the runpath_var.\n\t  rpath=\n\t  for dir in $perm_rpath; do\n\t    func_append rpath \"$dir:\"\n\t  done\n\t  compile_var=\"$runpath_var=\\\"$rpath\\$$runpath_var\\\" \"\n\tfi\n\tif test -n \"$finalize_perm_rpath\"; then\n\t  # We should set the runpath_var.\n\t  rpath=\n\t  for dir in $finalize_perm_rpath; do\n\t    func_append rpath \"$dir:\"\n\t  done\n\t  finalize_var=\"$runpath_var=\\\"$rpath\\$$runpath_var\\\" \"\n\tfi\n      fi\n\n      if test yes = \"$no_install\"; then\n\t# We don't need to create a wrapper script.\n\tlink_command=$compile_var$compile_command$compile_rpath\n\t# Replace the output file specification.\n\tlink_command=`$ECHO \"$link_command\" | $SED 's%@OUTPUT@%'\"$output\"'%g'`\n\t# Delete the old output file.\n\t$opt_dry_run || $RM $output\n\t# Link the executable and exit\n\tfunc_show_eval \"$link_command\" 'exit $?'\n\n\tif test -n \"$postlink_cmds\"; then\n\t  func_to_tool_file \"$output\"\n\t  postlink_cmds=`func_echo_all \"$postlink_cmds\" | $SED -e 's%@OUTPUT@%'\"$output\"'%g' -e 's%@TOOL_OUTPUT@%'\"$func_to_tool_file_result\"'%g'`\n\t  func_execute_cmds \"$postlink_cmds\" 'exit $?'\n\tfi\n\n\texit $EXIT_SUCCESS\n      fi\n\n      case $hardcode_action,$fast_install in\n        relink,*)\n\t  # Fast installation is not supported\n\t  link_command=$compile_var$compile_command$compile_rpath\n\t  relink_command=$finalize_var$finalize_command$finalize_rpath\n\n\t  func_warning \"this platform does not like uninstalled shared libraries\"\n\t  func_warning \"'$output' will be relinked during installation\"\n\t  ;;\n        *,yes)\n\t  link_command=$finalize_var$compile_command$finalize_rpath\n\t  relink_command=`$ECHO \"$compile_var$compile_command$compile_rpath\" | $SED 's%@OUTPUT@%\\$progdir/\\$file%g'`\n          ;;\n\t*,no)\n\t  link_command=$compile_var$compile_command$compile_rpath\n\t  relink_command=$finalize_var$finalize_command$finalize_rpath\n          ;;\n\t*,needless)\n\t  link_command=$finalize_var$compile_command$finalize_rpath\n\t  relink_command=\n          ;;\n      esac\n\n      # Replace the output file specification.\n      link_command=`$ECHO \"$link_command\" | $SED 's%@OUTPUT@%'\"$output_objdir/$outputname\"'%g'`\n\n      # Delete the old output files.\n      $opt_dry_run || $RM $output $output_objdir/$outputname $output_objdir/lt-$outputname\n\n      func_show_eval \"$link_command\" 'exit $?'\n\n      if test -n \"$postlink_cmds\"; then\n\tfunc_to_tool_file \"$output_objdir/$outputname\"\n\tpostlink_cmds=`func_echo_all \"$postlink_cmds\" | $SED -e 's%@OUTPUT@%'\"$output_objdir/$outputname\"'%g' -e 's%@TOOL_OUTPUT@%'\"$func_to_tool_file_result\"'%g'`\n\tfunc_execute_cmds \"$postlink_cmds\" 'exit $?'\n      fi\n\n      # Now create the wrapper script.\n      func_verbose \"creating $output\"\n\n      # Quote the relink command for shipping.\n      if test -n \"$relink_command\"; then\n\t# Preserve any variables that may affect compiler behavior\n\tfor var in $variables_saved_for_relink; do\n\t  if eval test -z \\\"\\${$var+set}\\\"; then\n\t    relink_command=\"{ test -z \\\"\\${$var+set}\\\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command\"\n\t  elif eval var_value=\\$$var; test -z \"$var_value\"; then\n\t    relink_command=\"$var=; export $var; $relink_command\"\n\t  else\n\t    func_quote_for_eval \"$var_value\"\n\t    relink_command=\"$var=$func_quote_for_eval_result; export $var; $relink_command\"\n\t  fi\n\tdone\n\trelink_command=\"(cd `pwd`; $relink_command)\"\n\trelink_command=`$ECHO \"$relink_command\" | $SED \"$sed_quote_subst\"`\n      fi\n\n      # Only actually do things if not in dry run mode.\n      $opt_dry_run || {\n\t# win32 will think the script is a binary if it has\n\t# a .exe suffix, so we strip it off here.\n\tcase $output in\n\t  *.exe) func_stripname '' '.exe' \"$output\"\n\t         output=$func_stripname_result ;;\n\tesac\n\t# test for cygwin because mv fails w/o .exe extensions\n\tcase $host in\n\t  *cygwin*)\n\t    exeext=.exe\n\t    func_stripname '' '.exe' \"$outputname\"\n\t    outputname=$func_stripname_result ;;\n\t  *) exeext= ;;\n\tesac\n\tcase $host in\n\t  *cygwin* | *mingw* )\n\t    func_dirname_and_basename \"$output\" \"\" \".\"\n\t    output_name=$func_basename_result\n\t    output_path=$func_dirname_result\n\t    cwrappersource=$output_path/$objdir/lt-$output_name.c\n\t    cwrapper=$output_path/$output_name.exe\n\t    $RM $cwrappersource $cwrapper\n\t    trap \"$RM $cwrappersource $cwrapper; exit $EXIT_FAILURE\" 1 2 15\n\n\t    func_emit_cwrapperexe_src > $cwrappersource\n\n\t    # The wrapper executable is built using the $host compiler,\n\t    # because it contains $host paths and files. If cross-\n\t    # compiling, it, like the target executable, must be\n\t    # executed on the $host or under an emulation environment.\n\t    $opt_dry_run || {\n\t      $LTCC $LTCFLAGS -o $cwrapper $cwrappersource\n\t      $STRIP $cwrapper\n\t    }\n\n\t    # Now, create the wrapper script for func_source use:\n\t    func_ltwrapper_scriptname $cwrapper\n\t    $RM $func_ltwrapper_scriptname_result\n\t    trap \"$RM $func_ltwrapper_scriptname_result; exit $EXIT_FAILURE\" 1 2 15\n\t    $opt_dry_run || {\n\t      # note: this script will not be executed, so do not chmod.\n\t      if test \"x$build\" = \"x$host\"; then\n\t\t$cwrapper --lt-dump-script > $func_ltwrapper_scriptname_result\n\t      else\n\t\tfunc_emit_wrapper no > $func_ltwrapper_scriptname_result\n\t      fi\n\t    }\n\t  ;;\n\t  * )\n\t    $RM $output\n\t    trap \"$RM $output; exit $EXIT_FAILURE\" 1 2 15\n\n\t    func_emit_wrapper no > $output\n\t    chmod +x $output\n\t  ;;\n\tesac\n      }\n      exit $EXIT_SUCCESS\n      ;;\n    esac\n\n    # See if we need to build an old-fashioned archive.\n    for oldlib in $oldlibs; do\n\n      case $build_libtool_libs in\n        convenience)\n\t  oldobjs=\"$libobjs_save $symfileobj\"\n\t  addlibs=$convenience\n\t  build_libtool_libs=no\n\t  ;;\n\tmodule)\n\t  oldobjs=$libobjs_save\n\t  addlibs=$old_convenience\n\t  build_libtool_libs=no\n          ;;\n\t*)\n\t  oldobjs=\"$old_deplibs $non_pic_objects\"\n\t  $preload && test -f \"$symfileobj\" \\\n\t    && func_append oldobjs \" $symfileobj\"\n\t  addlibs=$old_convenience\n\t  ;;\n      esac\n\n      if test -n \"$addlibs\"; then\n\tgentop=$output_objdir/${outputname}x\n\tfunc_append generated \" $gentop\"\n\n\tfunc_extract_archives $gentop $addlibs\n\tfunc_append oldobjs \" $func_extract_archives_result\"\n      fi\n\n      # Do each command in the archive commands.\n      if test -n \"$old_archive_from_new_cmds\" && test yes = \"$build_libtool_libs\"; then\n\tcmds=$old_archive_from_new_cmds\n      else\n\n\t# Add any objects from preloaded convenience libraries\n\tif test -n \"$dlprefiles\"; then\n\t  gentop=$output_objdir/${outputname}x\n\t  func_append generated \" $gentop\"\n\n\t  func_extract_archives $gentop $dlprefiles\n\t  func_append oldobjs \" $func_extract_archives_result\"\n\tfi\n\n\t# POSIX demands no paths to be encoded in archives.  We have\n\t# to avoid creating archives with duplicate basenames if we\n\t# might have to extract them afterwards, e.g., when creating a\n\t# static archive out of a convenience library, or when linking\n\t# the entirety of a libtool archive into another (currently\n\t# not supported by libtool).\n\tif (for obj in $oldobjs\n\t    do\n\t      func_basename \"$obj\"\n\t      $ECHO \"$func_basename_result\"\n\t    done | sort | sort -uc >/dev/null 2>&1); then\n\t  :\n\telse\n\t  echo \"copying selected object files to avoid basename conflicts...\"\n\t  gentop=$output_objdir/${outputname}x\n\t  func_append generated \" $gentop\"\n\t  func_mkdir_p \"$gentop\"\n\t  save_oldobjs=$oldobjs\n\t  oldobjs=\n\t  counter=1\n\t  for obj in $save_oldobjs\n\t  do\n\t    func_basename \"$obj\"\n\t    objbase=$func_basename_result\n\t    case \" $oldobjs \" in\n\t    \" \") oldobjs=$obj ;;\n\t    *[\\ /]\"$objbase \"*)\n\t      while :; do\n\t\t# Make sure we don't pick an alternate name that also\n\t\t# overlaps.\n\t\tnewobj=lt$counter-$objbase\n\t\tfunc_arith $counter + 1\n\t\tcounter=$func_arith_result\n\t\tcase \" $oldobjs \" in\n\t\t*[\\ /]\"$newobj \"*) ;;\n\t\t*) if test ! -f \"$gentop/$newobj\"; then break; fi ;;\n\t\tesac\n\t      done\n\t      func_show_eval \"ln $obj $gentop/$newobj || cp $obj $gentop/$newobj\"\n\t      func_append oldobjs \" $gentop/$newobj\"\n\t      ;;\n\t    *) func_append oldobjs \" $obj\" ;;\n\t    esac\n\t  done\n\tfi\n\tfunc_to_tool_file \"$oldlib\" func_convert_file_msys_to_w32\n\ttool_oldlib=$func_to_tool_file_result\n\teval cmds=\\\"$old_archive_cmds\\\"\n\n\tfunc_len \" $cmds\"\n\tlen=$func_len_result\n\tif test \"$len\" -lt \"$max_cmd_len\" || test \"$max_cmd_len\" -le -1; then\n\t  cmds=$old_archive_cmds\n\telif test -n \"$archiver_list_spec\"; then\n\t  func_verbose \"using command file archive linking...\"\n\t  for obj in $oldobjs\n\t  do\n\t    func_to_tool_file \"$obj\"\n\t    $ECHO \"$func_to_tool_file_result\"\n\t  done > $output_objdir/$libname.libcmd\n\t  func_to_tool_file \"$output_objdir/$libname.libcmd\"\n\t  oldobjs=\" $archiver_list_spec$func_to_tool_file_result\"\n\t  cmds=$old_archive_cmds\n\telse\n\t  # the command line is too long to link in one step, link in parts\n\t  func_verbose \"using piecewise archive linking...\"\n\t  save_RANLIB=$RANLIB\n\t  RANLIB=:\n\t  objlist=\n\t  concat_cmds=\n\t  save_oldobjs=$oldobjs\n\t  oldobjs=\n\t  # Is there a better way of finding the last object in the list?\n\t  for obj in $save_oldobjs\n\t  do\n\t    last_oldobj=$obj\n\t  done\n\t  eval test_cmds=\\\"$old_archive_cmds\\\"\n\t  func_len \" $test_cmds\"\n\t  len0=$func_len_result\n\t  len=$len0\n\t  for obj in $save_oldobjs\n\t  do\n\t    func_len \" $obj\"\n\t    func_arith $len + $func_len_result\n\t    len=$func_arith_result\n\t    func_append objlist \" $obj\"\n\t    if test \"$len\" -lt \"$max_cmd_len\"; then\n\t      :\n\t    else\n\t      # the above command should be used before it gets too long\n\t      oldobjs=$objlist\n\t      if test \"$obj\" = \"$last_oldobj\"; then\n\t\tRANLIB=$save_RANLIB\n\t      fi\n\t      test -z \"$concat_cmds\" || concat_cmds=$concat_cmds~\n\t      eval concat_cmds=\\\"\\$concat_cmds$old_archive_cmds\\\"\n\t      objlist=\n\t      len=$len0\n\t    fi\n\t  done\n\t  RANLIB=$save_RANLIB\n\t  oldobjs=$objlist\n\t  if test -z \"$oldobjs\"; then\n\t    eval cmds=\\\"\\$concat_cmds\\\"\n\t  else\n\t    eval cmds=\\\"\\$concat_cmds~\\$old_archive_cmds\\\"\n\t  fi\n\tfi\n      fi\n      func_execute_cmds \"$cmds\" 'exit $?'\n    done\n\n    test -n \"$generated\" && \\\n      func_show_eval \"${RM}r$generated\"\n\n    # Now create the libtool archive.\n    case $output in\n    *.la)\n      old_library=\n      test yes = \"$build_old_libs\" && old_library=$libname.$libext\n      func_verbose \"creating $output\"\n\n      # Preserve any variables that may affect compiler behavior\n      for var in $variables_saved_for_relink; do\n\tif eval test -z \\\"\\${$var+set}\\\"; then\n\t  relink_command=\"{ test -z \\\"\\${$var+set}\\\" || $lt_unset $var || { $var=; export $var; }; }; $relink_command\"\n\telif eval var_value=\\$$var; test -z \"$var_value\"; then\n\t  relink_command=\"$var=; export $var; $relink_command\"\n\telse\n\t  func_quote_for_eval \"$var_value\"\n\t  relink_command=\"$var=$func_quote_for_eval_result; export $var; $relink_command\"\n\tfi\n      done\n      # Quote the link command for shipping.\n      relink_command=\"(cd `pwd`; $SHELL \\\"$progpath\\\" $preserve_args --mode=relink $libtool_args @inst_prefix_dir@)\"\n      relink_command=`$ECHO \"$relink_command\" | $SED \"$sed_quote_subst\"`\n      if test yes = \"$hardcode_automatic\"; then\n\trelink_command=\n      fi\n\n      # Only create the output if not a dry run.\n      $opt_dry_run || {\n\tfor installed in no yes; do\n\t  if test yes = \"$installed\"; then\n\t    if test -z \"$install_libdir\"; then\n\t      break\n\t    fi\n\t    output=$output_objdir/${outputname}i\n\t    # Replace all uninstalled libtool libraries with the installed ones\n\t    newdependency_libs=\n\t    for deplib in $dependency_libs; do\n\t      case $deplib in\n\t      *.la)\n\t\tfunc_basename \"$deplib\"\n\t\tname=$func_basename_result\n\t\tfunc_resolve_sysroot \"$deplib\"\n\t\teval libdir=`$SED -n -e 's/^libdir=\\(.*\\)$/\\1/p' $func_resolve_sysroot_result`\n\t\ttest -z \"$libdir\" && \\\n\t\t  func_fatal_error \"'$deplib' is not a valid libtool archive\"\n\t\tfunc_append newdependency_libs \" ${lt_sysroot:+=}$libdir/$name\"\n\t\t;;\n\t      -L*)\n\t\tfunc_stripname -L '' \"$deplib\"\n\t\tfunc_replace_sysroot \"$func_stripname_result\"\n\t\tfunc_append newdependency_libs \" -L$func_replace_sysroot_result\"\n\t\t;;\n\t      -R*)\n\t\tfunc_stripname -R '' \"$deplib\"\n\t\tfunc_replace_sysroot \"$func_stripname_result\"\n\t\tfunc_append newdependency_libs \" -R$func_replace_sysroot_result\"\n\t\t;;\n\t      *) func_append newdependency_libs \" $deplib\" ;;\n\t      esac\n\t    done\n\t    dependency_libs=$newdependency_libs\n\t    newdlfiles=\n\n\t    for lib in $dlfiles; do\n\t      case $lib in\n\t      *.la)\n\t        func_basename \"$lib\"\n\t\tname=$func_basename_result\n\t\teval libdir=`$SED -n -e 's/^libdir=\\(.*\\)$/\\1/p' $lib`\n\t\ttest -z \"$libdir\" && \\\n\t\t  func_fatal_error \"'$lib' is not a valid libtool archive\"\n\t\tfunc_append newdlfiles \" ${lt_sysroot:+=}$libdir/$name\"\n\t\t;;\n\t      *) func_append newdlfiles \" $lib\" ;;\n\t      esac\n\t    done\n\t    dlfiles=$newdlfiles\n\t    newdlprefiles=\n\t    for lib in $dlprefiles; do\n\t      case $lib in\n\t      *.la)\n\t\t# Only pass preopened files to the pseudo-archive (for\n\t\t# eventual linking with the app. that links it) if we\n\t\t# didn't already link the preopened objects directly into\n\t\t# the library:\n\t\tfunc_basename \"$lib\"\n\t\tname=$func_basename_result\n\t\teval libdir=`$SED -n -e 's/^libdir=\\(.*\\)$/\\1/p' $lib`\n\t\ttest -z \"$libdir\" && \\\n\t\t  func_fatal_error \"'$lib' is not a valid libtool archive\"\n\t\tfunc_append newdlprefiles \" ${lt_sysroot:+=}$libdir/$name\"\n\t\t;;\n\t      esac\n\t    done\n\t    dlprefiles=$newdlprefiles\n\t  else\n\t    newdlfiles=\n\t    for lib in $dlfiles; do\n\t      case $lib in\n\t\t[\\\\/]* | [A-Za-z]:[\\\\/]*) abs=$lib ;;\n\t\t*) abs=`pwd`\"/$lib\" ;;\n\t      esac\n\t      func_append newdlfiles \" $abs\"\n\t    done\n\t    dlfiles=$newdlfiles\n\t    newdlprefiles=\n\t    for lib in $dlprefiles; do\n\t      case $lib in\n\t\t[\\\\/]* | [A-Za-z]:[\\\\/]*) abs=$lib ;;\n\t\t*) abs=`pwd`\"/$lib\" ;;\n\t      esac\n\t      func_append newdlprefiles \" $abs\"\n\t    done\n\t    dlprefiles=$newdlprefiles\n\t  fi\n\t  $RM $output\n\t  # place dlname in correct position for cygwin\n\t  # In fact, it would be nice if we could use this code for all target\n\t  # systems that can't hard-code library paths into their executables\n\t  # and that have no shared library path variable independent of PATH,\n\t  # but it turns out we can't easily determine that from inspecting\n\t  # libtool variables, so we have to hard-code the OSs to which it\n\t  # applies here; at the moment, that means platforms that use the PE\n\t  # object format with DLL files.  See the long comment at the top of\n\t  # tests/bindir.at for full details.\n\t  tdlname=$dlname\n\t  case $host,$output,$installed,$module,$dlname in\n\t    *cygwin*,*lai,yes,no,*.dll | *mingw*,*lai,yes,no,*.dll | *cegcc*,*lai,yes,no,*.dll)\n\t      # If a -bindir argument was supplied, place the dll there.\n\t      if test -n \"$bindir\"; then\n\t\tfunc_relative_path \"$install_libdir\" \"$bindir\"\n\t\ttdlname=$func_relative_path_result/$dlname\n\t      else\n\t\t# Otherwise fall back on heuristic.\n\t\ttdlname=../bin/$dlname\n\t      fi\n\t      ;;\n\t  esac\n\t  $ECHO > $output \"\\\n# $outputname - a libtool library file\n# Generated by $PROGRAM (GNU $PACKAGE) $VERSION\n#\n# Please DO NOT delete this file!\n# It is necessary for linking the library.\n\n# The name that we can dlopen(3).\ndlname='$tdlname'\n\n# Names of this library.\nlibrary_names='$library_names'\n\n# The name of the static archive.\nold_library='$old_library'\n\n# Linker flags that cannot go in dependency_libs.\ninherited_linker_flags='$new_inherited_linker_flags'\n\n# Libraries that this one depends upon.\ndependency_libs='$dependency_libs'\n\n# Names of additional weak libraries provided by this library\nweak_library_names='$weak_libs'\n\n# Version information for $libname.\ncurrent=$current\nage=$age\nrevision=$revision\n\n# Is this an already installed library?\ninstalled=$installed\n\n# Should we warn about portability when linking against -modules?\nshouldnotlink=$module\n\n# Files to dlopen/dlpreopen\ndlopen='$dlfiles'\ndlpreopen='$dlprefiles'\n\n# Directory that this library needs to be installed in:\nlibdir='$install_libdir'\"\n\t  if test no,yes = \"$installed,$need_relink\"; then\n\t    $ECHO >> $output \"\\\nrelink_command=\\\"$relink_command\\\"\"\n\t  fi\n\tdone\n      }\n\n      # Do a symbolic link so that the libtool archive can be found in\n      # LD_LIBRARY_PATH before the program is installed.\n      func_show_eval '( cd \"$output_objdir\" && $RM \"$outputname\" && $LN_S \"../$outputname\" \"$outputname\" )' 'exit $?'\n      ;;\n    esac\n    exit $EXIT_SUCCESS\n}\n\nif test link = \"$opt_mode\" || test relink = \"$opt_mode\"; then\n  func_mode_link ${1+\"$@\"}\nfi\n\n\n# func_mode_uninstall arg...\nfunc_mode_uninstall ()\n{\n    $debug_cmd\n\n    RM=$nonopt\n    files=\n    rmforce=false\n    exit_status=0\n\n    # This variable tells wrapper scripts just to set variables rather\n    # than running their programs.\n    libtool_install_magic=$magic\n\n    for arg\n    do\n      case $arg in\n      -f) func_append RM \" $arg\"; rmforce=: ;;\n      -*) func_append RM \" $arg\" ;;\n      *) func_append files \" $arg\" ;;\n      esac\n    done\n\n    test -z \"$RM\" && \\\n      func_fatal_help \"you must specify an RM program\"\n\n    rmdirs=\n\n    for file in $files; do\n      func_dirname \"$file\" \"\" \".\"\n      dir=$func_dirname_result\n      if test . = \"$dir\"; then\n\todir=$objdir\n      else\n\todir=$dir/$objdir\n      fi\n      func_basename \"$file\"\n      name=$func_basename_result\n      test uninstall = \"$opt_mode\" && odir=$dir\n\n      # Remember odir for removal later, being careful to avoid duplicates\n      if test clean = \"$opt_mode\"; then\n\tcase \" $rmdirs \" in\n\t  *\" $odir \"*) ;;\n\t  *) func_append rmdirs \" $odir\" ;;\n\tesac\n      fi\n\n      # Don't error if the file doesn't exist and rm -f was used.\n      if { test -L \"$file\"; } >/dev/null 2>&1 ||\n\t { test -h \"$file\"; } >/dev/null 2>&1 ||\n\t test -f \"$file\"; then\n\t:\n      elif test -d \"$file\"; then\n\texit_status=1\n\tcontinue\n      elif $rmforce; then\n\tcontinue\n      fi\n\n      rmfiles=$file\n\n      case $name in\n      *.la)\n\t# Possibly a libtool archive, so verify it.\n\tif func_lalib_p \"$file\"; then\n\t  func_source $dir/$name\n\n\t  # Delete the libtool libraries and symlinks.\n\t  for n in $library_names; do\n\t    func_append rmfiles \" $odir/$n\"\n\t  done\n\t  test -n \"$old_library\" && func_append rmfiles \" $odir/$old_library\"\n\n\t  case $opt_mode in\n\t  clean)\n\t    case \" $library_names \" in\n\t    *\" $dlname \"*) ;;\n\t    *) test -n \"$dlname\" && func_append rmfiles \" $odir/$dlname\" ;;\n\t    esac\n\t    test -n \"$libdir\" && func_append rmfiles \" $odir/$name $odir/${name}i\"\n\t    ;;\n\t  uninstall)\n\t    if test -n \"$library_names\"; then\n\t      # Do each command in the postuninstall commands.\n\t      func_execute_cmds \"$postuninstall_cmds\" '$rmforce || exit_status=1'\n\t    fi\n\n\t    if test -n \"$old_library\"; then\n\t      # Do each command in the old_postuninstall commands.\n\t      func_execute_cmds \"$old_postuninstall_cmds\" '$rmforce || exit_status=1'\n\t    fi\n\t    # FIXME: should reinstall the best remaining shared library.\n\t    ;;\n\t  esac\n\tfi\n\t;;\n\n      *.lo)\n\t# Possibly a libtool object, so verify it.\n\tif func_lalib_p \"$file\"; then\n\n\t  # Read the .lo file\n\t  func_source $dir/$name\n\n\t  # Add PIC object to the list of files to remove.\n\t  if test -n \"$pic_object\" && test none != \"$pic_object\"; then\n\t    func_append rmfiles \" $dir/$pic_object\"\n\t  fi\n\n\t  # Add non-PIC object to the list of files to remove.\n\t  if test -n \"$non_pic_object\" && test none != \"$non_pic_object\"; then\n\t    func_append rmfiles \" $dir/$non_pic_object\"\n\t  fi\n\tfi\n\t;;\n\n      *)\n\tif test clean = \"$opt_mode\"; then\n\t  noexename=$name\n\t  case $file in\n\t  *.exe)\n\t    func_stripname '' '.exe' \"$file\"\n\t    file=$func_stripname_result\n\t    func_stripname '' '.exe' \"$name\"\n\t    noexename=$func_stripname_result\n\t    # $file with .exe has already been added to rmfiles,\n\t    # add $file without .exe\n\t    func_append rmfiles \" $file\"\n\t    ;;\n\t  esac\n\t  # Do a test to see if this is a libtool program.\n\t  if func_ltwrapper_p \"$file\"; then\n\t    if func_ltwrapper_executable_p \"$file\"; then\n\t      func_ltwrapper_scriptname \"$file\"\n\t      relink_command=\n\t      func_source $func_ltwrapper_scriptname_result\n\t      func_append rmfiles \" $func_ltwrapper_scriptname_result\"\n\t    else\n\t      relink_command=\n\t      func_source $dir/$noexename\n\t    fi\n\n\t    # note $name still contains .exe if it was in $file originally\n\t    # as does the version of $file that was added into $rmfiles\n\t    func_append rmfiles \" $odir/$name $odir/${name}S.$objext\"\n\t    if test yes = \"$fast_install\" && test -n \"$relink_command\"; then\n\t      func_append rmfiles \" $odir/lt-$name\"\n\t    fi\n\t    if test \"X$noexename\" != \"X$name\"; then\n\t      func_append rmfiles \" $odir/lt-$noexename.c\"\n\t    fi\n\t  fi\n\tfi\n\t;;\n      esac\n      func_show_eval \"$RM $rmfiles\" 'exit_status=1'\n    done\n\n    # Try to remove the $objdir's in the directories where we deleted files\n    for dir in $rmdirs; do\n      if test -d \"$dir\"; then\n\tfunc_show_eval \"rmdir $dir >/dev/null 2>&1\"\n      fi\n    done\n\n    exit $exit_status\n}\n\nif test uninstall = \"$opt_mode\" || test clean = \"$opt_mode\"; then\n  func_mode_uninstall ${1+\"$@\"}\nfi\n\ntest -z \"$opt_mode\" && {\n  help=$generic_help\n  func_fatal_help \"you must specify a MODE\"\n}\n\ntest -z \"$exec_cmd\" && \\\n  func_fatal_help \"invalid operation mode '$opt_mode'\"\n\nif test -n \"$exec_cmd\"; then\n  eval exec \"$exec_cmd\"\n  exit $EXIT_FAILURE\nfi\n\nexit $exit_status\n\n\n# The TAGs below are defined such that we never get into a situation\n# where we disable both kinds of libraries.  Given conflicting\n# choices, we go for a static library, that is the most portable,\n# since we can't tell whether shared libraries were disabled because\n# the user asked for that or because the platform doesn't support\n# them.  This is particularly important on AIX, because we don't\n# support having both static and shared libraries enabled at the same\n# time on that platform, so we default to a shared-only configuration.\n# If a disable-shared tag is given, we'll fallback to a static-only\n# configuration.  But we'll never go from static-only to shared-only.\n\n# ### BEGIN LIBTOOL TAG CONFIG: disable-shared\nbuild_libtool_libs=no\nbuild_old_libs=yes\n# ### END LIBTOOL TAG CONFIG: disable-shared\n\n# ### BEGIN LIBTOOL TAG CONFIG: disable-static\nbuild_old_libs=`case $build_libtool_libs in yes) echo no;; *) echo yes;; esac`\n# ### END LIBTOOL TAG CONFIG: disable-static\n\n# Local Variables:\n# mode:shell-script\n# sh-indentation:2\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makcjpeg.st",
    "content": "; Project file for Independent JPEG Group's software\n;\n; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.\n; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.\n;\n; To use this file, rename it to cjpeg.prj.\n; If you are using Turbo C, change filenames beginning with \"pc...\" to \"tc...\"\n; Read installation instructions before trying to make the program!\n;\n;\n;      * * * Output file * * *\ncjpeg.ttp\n;\n; * * * COMPILER OPTIONS * * *  \n.C[-P]        ; absolute calls\n.C[-M]        ; and no string merging, folks\n.C[-w-cln]    ; no \"constant is long\" warnings\n.C[-w-par]    ; no \"parameter xxxx unused\"\n.C[-w-rch]    ; no \"unreachable code\"\n.C[-wsig]     ; warn if significant digits may be lost\n=\n; * * * * List of modules * * * * \npcstart.o\ncjpeg.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)\ncdjpeg.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdswitch.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdppm.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdgif.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdtarga.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdbmp.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdrle.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nlibjpeg.lib        ; built by libjpeg.prj\npcfltlib.lib       ; floating point library\n; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED\npcstdlib.lib       ; standard library\npcextlib.lib       ; extended library\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makdjpeg.st",
    "content": "; Project file for Independent JPEG Group's software\n;\n; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.\n; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.\n;\n; To use this file, rename it to djpeg.prj.\n; If you are using Turbo C, change filenames beginning with \"pc...\" to \"tc...\"\n; Read installation instructions before trying to make the program!\n;\n;\n;      * * * Output file * * *\ndjpeg.ttp\n;\n; * * * COMPILER OPTIONS * * *  \n.C[-P]        ; absolute calls\n.C[-M]        ; and no string merging, folks\n.C[-w-cln]    ; no \"constant is long\" warnings\n.C[-w-par]    ; no \"parameter xxxx unused\"\n.C[-w-rch]    ; no \"unreachable code\"\n.C[-wsig]     ; warn if significant digits may be lost\n=\n; * * * * List of modules * * * * \npcstart.o\ndjpeg.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,jversion.h)\ncdjpeg.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdcolmap.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nwrppm.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nwrgif.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nwrtarga.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nwrbmp.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nwrrle.c\t\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nlibjpeg.lib        ; built by libjpeg.prj\npcfltlib.lib       ; floating point library\n; the float library can be omitted if you've turned off DCT_FLOAT_SUPPORTED\npcstdlib.lib       ; standard library\npcextlib.lib       ; extended library\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makeadsw.vc6",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN!\n\n###############################################################################\n\nProject: \"cjpeg\"=\".\\cjpeg.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nProject: \"djpeg\"=\".\\djpeg.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nProject: \"jpegtran\"=\".\\jpegtran.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nProject: \"rdjpgcom\"=\".\\rdjpgcom.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nProject: \"wrjpgcom\"=\".\\wrjpgcom.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makeasln.v10",
    "content": "\nMicrosoft Visual Studio Solution File, Format Version 11.00\n# Visual C++ Express 2010\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"cjpeg\", \"cjpeg.vcxproj\", \"{2E7FAAD9-2F58-4BDE-81F2-1D6D3FB8BF57}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"djpeg\", \"djpeg.vcxproj\", \"{11043137-B453-4DFA-9010-4D2B9DC1545C}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"jpegtran\", \"jpegtran.vcxproj\", \"{025BAC50-51B5-4FFE-BC47-3F920BB4047E}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"rdjpgcom\", \"rdjpgcom.vcxproj\", \"{C81513DB-78DC-46BC-BC98-82E745203976}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"wrjpgcom\", \"wrjpgcom.vcxproj\", \"{B57065D4-DDDA-4668-BAF5-2D49270C973C}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tRelease|Win32 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{2E7FAAD9-2F58-4BDE-81F2-1D6D3FB8BF57}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{2E7FAAD9-2F58-4BDE-81F2-1D6D3FB8BF57}.Release|Win32.Build.0 = Release|Win32\n\t\t{11043137-B453-4DFA-9010-4D2B9DC1545C}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{11043137-B453-4DFA-9010-4D2B9DC1545C}.Release|Win32.Build.0 = Release|Win32\n\t\t{025BAC50-51B5-4FFE-BC47-3F920BB4047E}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{025BAC50-51B5-4FFE-BC47-3F920BB4047E}.Release|Win32.Build.0 = Release|Win32\n\t\t{C81513DB-78DC-46BC-BC98-82E745203976}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{C81513DB-78DC-46BC-BC98-82E745203976}.Release|Win32.Build.0 = Release|Win32\n\t\t{B57065D4-DDDA-4668-BAF5-2D49270C973C}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{B57065D4-DDDA-4668-BAF5-2D49270C973C}.Release|Win32.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makecdep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von cjpeg.mak\n\n.\\cdjpeg.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\cjpeg.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\".\\jversion.h\"\\\n\t\n\n.\\rdbmp.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\rdgif.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\rdppm.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\rdrle.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\rdswitch.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\rdtarga.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makecdsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"cjpeg\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=cjpeg - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"cjpeg.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"cjpeg.mak\" CFG=\"cjpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"cjpeg - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\cjpeg\\Release\"\n# PROP BASE Intermediate_Dir \".\\cjpeg\\Release\"\n# PROP BASE Target_Dir \".\\cjpeg\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\cjpeg\\Release\"\n# PROP Intermediate_Dir \".\\cjpeg\\Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \".\\cjpeg\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /FD /c\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\n# ADD RSC /l 0x409 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# Begin Target\n\n# Name \"cjpeg - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\cdjpeg.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\cjpeg.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdbmp.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdgif.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdppm.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdrle.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdswitch.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdtarga.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\cderror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\cdjpeg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jerror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmorecfg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpeglib.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jversion.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makecfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"cdjpeg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jerror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jmorecfg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpeglib.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jversion.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"cjpeg.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdbmp.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdgif.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdppm.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdrle.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdswitch.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdtarga.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makecmak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on cjpeg.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=cjpeg - Win32\n!MESSAGE Keine Konfiguration angegeben. cjpeg - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"cjpeg - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"cjpeg.mak\" CFG=\"cjpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"cjpeg - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nCPP=cl.exe\nRSC=rc.exe\nOUTDIR=.\\cjpeg\\Release\nINTDIR=.\\cjpeg\\Release\n# Begin Custom Macros\nOutDir=.\\cjpeg\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\cjpeg.exe\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\cdjpeg.obj\"\n\t-@erase \"$(INTDIR)\\cjpeg.obj\"\n\t-@erase \"$(INTDIR)\\rdbmp.obj\"\n\t-@erase \"$(INTDIR)\\rdgif.obj\"\n\t-@erase \"$(INTDIR)\\rdppm.obj\"\n\t-@erase \"$(INTDIR)\\rdrle.obj\"\n\t-@erase \"$(INTDIR)\\rdswitch.obj\"\n\t-@erase \"$(INTDIR)\\rdtarga.obj\"\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(OUTDIR)\\cjpeg.exe\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\cjpeg.bsc\" \nBSC32_SBRS= \\\n\t\nLINK32=link.exe\nLINK32_FLAGS=Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:\"$(OUTDIR)\\cjpeg.pdb\" /machine:I386 /out:\"$(OUTDIR)\\cjpeg.exe\" \nLINK32_OBJS= \\\n\t\"$(INTDIR)\\cdjpeg.obj\" \\\n\t\"$(INTDIR)\\cjpeg.obj\" \\\n\t\"$(INTDIR)\\rdbmp.obj\" \\\n\t\"$(INTDIR)\\rdgif.obj\" \\\n\t\"$(INTDIR)\\rdppm.obj\" \\\n\t\"$(INTDIR)\\rdrle.obj\" \\\n\t\"$(INTDIR)\\rdswitch.obj\" \\\n\t\"$(INTDIR)\\rdtarga.obj\"\n\n\"$(OUTDIR)\\cjpeg.exe\" : \"$(OUTDIR)\" $(DEF_FILE) $(LINK32_OBJS)\n    $(LINK32) @<<\n  $(LINK32_FLAGS) $(LINK32_OBJS)\n<<\n\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /Fp\"$(INTDIR)\\cjpeg.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"cjpeg.dep\")\n!INCLUDE \"cjpeg.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"cjpeg.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"cjpeg - Win32\"\nSOURCE=.\\cdjpeg.c\n\n\"$(INTDIR)\\cdjpeg.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\cjpeg.c\n\n\"$(INTDIR)\\cjpeg.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdbmp.c\n\n\"$(INTDIR)\\rdbmp.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdgif.c\n\n\"$(INTDIR)\\rdgif.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdppm.c\n\n\"$(INTDIR)\\rdppm.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdrle.c\n\n\"$(INTDIR)\\rdrle.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdswitch.c\n\n\"$(INTDIR)\\rdswitch.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdtarga.c\n\n\"$(INTDIR)\\rdtarga.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makecvcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{2E7FAAD9-2F58-4BDE-81F2-1D6D3FB8BF57}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>cjpeg</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <OutDir>$(ProjectName)\\$(Configuration)\\</OutDir>\n    <IntDir>$(ProjectName)\\$(Configuration)\\</IntDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n      <DisableSpecificWarnings>4996</DisableSpecificWarnings>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>Release\\jpeg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\" />\n    <ClInclude Include=\"cdjpeg.h\" />\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jerror.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n    <ClInclude Include=\"jmorecfg.h\" />\n    <ClInclude Include=\"jpeglib.h\" />\n    <ClInclude Include=\"jversion.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\" />\n    <ClCompile Include=\"cjpeg.c\" />\n    <ClCompile Include=\"rdbmp.c\" />\n    <ClCompile Include=\"rdgif.c\" />\n    <ClCompile Include=\"rdppm.c\" />\n    <ClCompile Include=\"rdrle.c\" />\n    <ClCompile Include=\"rdswitch.c\" />\n    <ClCompile Include=\"rdtarga.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makeddep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von djpeg.mak\n\n.\\cdjpeg.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\djpeg.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\".\\jversion.h\"\\\n\t\n\n.\\rdcolmap.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\wrbmp.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\wrgif.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\wrppm.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\wrrle.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\wrtarga.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makeddsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"djpeg\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=djpeg - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"djpeg.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"djpeg.mak\" CFG=\"djpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"djpeg - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\djpeg\\Release\"\n# PROP BASE Intermediate_Dir \".\\djpeg\\Release\"\n# PROP BASE Target_Dir \".\\djpeg\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\djpeg\\Release\"\n# PROP Intermediate_Dir \".\\djpeg\\Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \".\\djpeg\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /FD /c\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\n# ADD RSC /l 0x409 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# Begin Target\n\n# Name \"djpeg - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\cdjpeg.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\djpeg.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdcolmap.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\wrbmp.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\wrgif.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\wrppm.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\wrrle.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\wrtarga.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\cderror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\cdjpeg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jerror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmorecfg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpeglib.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jversion.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makedfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"cdjpeg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jerror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jmorecfg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpeglib.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jversion.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"djpeg.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdcolmap.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"wrbmp.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"wrgif.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"wrppm.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"wrrle.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"wrtarga.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makedmak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on djpeg.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=djpeg - Win32\n!MESSAGE Keine Konfiguration angegeben. djpeg - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"djpeg - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"djpeg.mak\" CFG=\"djpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"djpeg - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nCPP=cl.exe\nRSC=rc.exe\nOUTDIR=.\\djpeg\\Release\nINTDIR=.\\djpeg\\Release\n# Begin Custom Macros\nOutDir=.\\djpeg\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\djpeg.exe\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\cdjpeg.obj\"\n\t-@erase \"$(INTDIR)\\djpeg.obj\"\n\t-@erase \"$(INTDIR)\\rdcolmap.obj\"\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(INTDIR)\\wrbmp.obj\"\n\t-@erase \"$(INTDIR)\\wrgif.obj\"\n\t-@erase \"$(INTDIR)\\wrppm.obj\"\n\t-@erase \"$(INTDIR)\\wrrle.obj\"\n\t-@erase \"$(INTDIR)\\wrtarga.obj\"\n\t-@erase \"$(OUTDIR)\\djpeg.exe\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\djpeg.bsc\" \nBSC32_SBRS= \\\n\t\nLINK32=link.exe\nLINK32_FLAGS=Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:\"$(OUTDIR)\\djpeg.pdb\" /machine:I386 /out:\"$(OUTDIR)\\djpeg.exe\" \nLINK32_OBJS= \\\n\t\"$(INTDIR)\\cdjpeg.obj\" \\\n\t\"$(INTDIR)\\djpeg.obj\" \\\n\t\"$(INTDIR)\\rdcolmap.obj\" \\\n\t\"$(INTDIR)\\wrbmp.obj\" \\\n\t\"$(INTDIR)\\wrgif.obj\" \\\n\t\"$(INTDIR)\\wrppm.obj\" \\\n\t\"$(INTDIR)\\wrrle.obj\" \\\n\t\"$(INTDIR)\\wrtarga.obj\"\n\n\"$(OUTDIR)\\djpeg.exe\" : \"$(OUTDIR)\" $(DEF_FILE) $(LINK32_OBJS)\n    $(LINK32) @<<\n  $(LINK32_FLAGS) $(LINK32_OBJS)\n<<\n\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /Fp\"$(INTDIR)\\djpeg.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"djpeg.dep\")\n!INCLUDE \"djpeg.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"djpeg.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"djpeg - Win32\"\nSOURCE=.\\cdjpeg.c\n\n\"$(INTDIR)\\cdjpeg.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\djpeg.c\n\n\"$(INTDIR)\\djpeg.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdcolmap.c\n\n\"$(INTDIR)\\rdcolmap.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\wrbmp.c\n\n\"$(INTDIR)\\wrbmp.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\wrgif.c\n\n\"$(INTDIR)\\wrgif.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\wrppm.c\n\n\"$(INTDIR)\\wrppm.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\wrrle.c\n\n\"$(INTDIR)\\wrrle.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\wrtarga.c\n\n\"$(INTDIR)\\wrtarga.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makedvcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{11043137-B453-4DFA-9010-4D2B9DC1545C}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>djpeg</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <OutDir>$(ProjectName)\\$(Configuration)\\</OutDir>\n    <IntDir>$(ProjectName)\\$(Configuration)\\</IntDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n      <DisableSpecificWarnings>4996</DisableSpecificWarnings>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>Release\\jpeg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\" />\n    <ClInclude Include=\"cdjpeg.h\" />\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jerror.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n    <ClInclude Include=\"jmorecfg.h\" />\n    <ClInclude Include=\"jpeglib.h\" />\n    <ClInclude Include=\"jversion.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\" />\n    <ClCompile Include=\"djpeg.c\" />\n    <ClCompile Include=\"rdcolmap.c\" />\n    <ClCompile Include=\"wrbmp.c\" />\n    <ClCompile Include=\"wrgif.c\" />\n    <ClCompile Include=\"wrppm.c\" />\n    <ClCompile Include=\"wrrle.c\" />\n    <ClCompile Include=\"wrtarga.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.ansi",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is suitable for Unix-like systems with ANSI-capable compilers.\n# If you have a non-ANSI compiler, makefile.unix is a better starting point.\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= cc\n\n# You may need to adjust these cc options:\nCFLAGS= -O\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time cc options:\nLDFLAGS= \n\n# To link any special libraries, add the necessary -l commands here.\nLDLIBS= \n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For Unix this is usually jmemnobs.o, but you may want\n# to use jmemansi.o or jmemname.o if you have limited swap space.\nSYSDEPMEM= jmemnobs.o\n\n# miscellaneous OS-dependent stuff\n# linker\nLN= $(CC)\n# file deletion command\nRM= rm -f\n# library (.a) file creation command\nAR= ar rc\n# second step in .a creation (use \"touch\" if not needed)\nAR2= ranlib\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o \\\n        jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o \\\n        jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o \\\n        jfdctflt.o jfdctint.o\n# decompression library object files\nDLIBOBJECTS= jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o \\\n        jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o \\\n        jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o \\\n        jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o\n# These objectfiles are included in libjpeg.a\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \\\n        cdjpeg.o\nDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \\\n        cdjpeg.o\nTROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o\n\n\nall: libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom\n\nlibjpeg.a: $(LIBOBJECTS)\n\t$(RM) libjpeg.a\n\t$(AR) libjpeg.a  $(LIBOBJECTS)\n\t$(AR2) libjpeg.a\n\ncjpeg: $(COBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)\n\ndjpeg: $(DOBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)\n\njpegtran: $(TROBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)\n\nrdjpgcom: rdjpgcom.o\n\t$(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)\n\nwrjpgcom: wrjpgcom.o\n\t$(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t$(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom\n\t$(RM) core testout*\n\ntest: cjpeg djpeg jpegtran\n\t$(RM) testout*\n\t./djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\t./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\t./cjpeg -dct int -outfile testout.jpg  testimg.ppm\n\t./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\t./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\t./jpegtran -outfile testoutt.jpg testprog.jpg\n\tcmp testimg.ppm testout.ppm\n\tcmp testimg.bmp testout.bmp\n\tcmp testimg.jpg testout.jpg\n\tcmp testimg.ppm testoutp.ppm\n\tcmp testimgp.jpg testoutp.jpg\n\tcmp testorig.jpg testoutt.jpg\n\n\njaricom.o: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.o: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.o: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.b32",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is suitable for Borland C on MS-DOS.\n# It works with Borland C++ 32-bit for DOS, revision 5.0 or later.\n# Thanks to Tom Wright and Ge' Weijers (original DOS) and\n# Joe Slater for adding 32-bit additions (needed for Borland\n# revision 5.5).\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= bcc32\n\n# You may need to adjust these cc options:\nCFLAGS= -O2 -w-par -w-stu -w-ccc -w-rch -w-aus\n# -w-par suppresses warnings about unused function parameters\n# -w-stu suppresses warnings about incomplete structures\n# -w-ccc suppresses warnings about compile-time-constant conditions\n# -w-rch suppresses warnings about unreachable code\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time cc options:\nLDFLAGS=\n# -lc case-significant link\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.\n# SYSDEPMEMLIB must list the same files with \"+\" signs for the librarian.\nSYSDEPMEM= jmemnobs.obj\nSYSDEPMEMLIB= +jmemnobs.obj\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \\\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \\\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj \\\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj \\\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj \\\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \\\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj \\\n        jdmerge.obj\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \\\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \\\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n\n\nall: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.lib: $(LIBOBJECTS)\n        - del libjpeg.lib\n        tlib libjpeg.lib /E /C @&&|\n+jcapimin.obj +jcapistd.obj +jcarith.obj +jctrans.obj +jcparam.obj &\n+jdatadst.obj +jcinit.obj +jcmaster.obj +jcmarker.obj +jcmainct.obj &\n+jcprepct.obj +jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj &\n+jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj +jfdctint.obj +jdapimin.obj &\n+jdapistd.obj +jdarith.obj +jdtrans.obj +jdatasrc.obj +jdmaster.obj &\n+jdinput.obj +jdmarker.obj +jdhuff.obj +jdmainct.obj +jdcoefct.obj &\n+jdpostct.obj +jddctmgr.obj +jidctfst.obj +jidctflt.obj +jidctint.obj &\n+jdsample.obj +jdcolor.obj +jquant1.obj +jquant2.obj +jdmerge.obj &\n+jaricom.obj +jcomapi.obj +jutils.obj +jerror.obj +jmemmgr.obj &\n$(SYSDEPMEMLIB)\n|\n\ncjpeg.exe: $(COBJECTS) libjpeg.lib\n        $(CC) $(LDFLAGS) -ecjpeg.exe $(COBJECTS) libjpeg.lib\n\ndjpeg.exe: $(DOBJECTS) libjpeg.lib\n        $(CC) $(LDFLAGS) -edjpeg.exe $(DOBJECTS) libjpeg.lib\n\njpegtran.exe: $(TROBJECTS) libjpeg.lib\n        $(CC) $(LDFLAGS) -ejpegtran.exe $(TROBJECTS) libjpeg.lib\n\nrdjpgcom.exe: rdjpgcom.c\n        $(CC) $(CFLAGS) rdjpgcom.c\n\nwrjpgcom.exe: wrjpgcom.c\n        $(CC) $(CFLAGS) wrjpgcom.c\n\n# This \"{}\" syntax allows Borland Make to \"batch\" source files.\n# In this way, each run of the compiler can build many modules.\n.c.obj:\n        $(CC) $(CFLAGS) -c{ $<}\n\njconfig.h: jconfig.txt\n        echo You must prepare a system-dependent jconfig.h file.\n        echo Please read the installation directions in install.txt.\n        exit 1\n\nclean:\n        - del *.obj\n        - del libjpeg.lib\n        - del cjpeg.exe\n        - del djpeg.exe\n        - del jpegtran.exe\n        - del rdjpgcom.exe\n        - del wrjpgcom.exe\n        - del testout*.*\n\ntest: cjpeg.exe djpeg.exe jpegtran.exe\n        - del testout*.*\n        djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n        djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n        cjpeg -dct int -outfile testout.jpg  testimg.ppm\n        djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n        cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n        jpegtran -outfile testoutt.jpg testprog.jpg\n        echo n > n.tmp\n        comp testimg.ppm testout.ppm < n.tmp\n        comp testimg.bmp testout.bmp < n.tmp\n        comp testimg.jpg testout.jpg < n.tmp\n        comp testimg.ppm testoutp.ppm < n.tmp\n        comp testimgp.jpg testoutp.jpg < n.tmp\n        comp testorig.jpg testoutt.jpg < n.tmp\n        del n.tmp\n\n\njaricom.obj: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\njmemdosa.obj: jmemdosa.asm\n        tasm /mx jmemdosa.asm\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.bcc",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is suitable for Borland C on MS-DOS or OS/2.\n# It works with Borland C++ for DOS, revision 3.0 or later,\n# and has been tested with Borland C++ for OS/2.\n# Watch out for optimization bugs in the OS/2 compilers --- see notes below!\n# Thanks to Tom Wright and Ge' Weijers (original DOS) and\n# Ken Porter (OS/2) for this file.\n\n# Read installation instructions before saying \"make\" !!\n\n# Are we under DOS or OS/2?\n!if !$d(DOS) && !$d(OS2)\n!if $d(__OS2__)\nOS2=1\n!else\nDOS=1\n!endif\n!endif\n\n# The name of your C compiler:\nCC= bcc\n\n# You may need to adjust these cc options:\n!if $d(DOS)\nCFLAGS= -O2 -mm -w-par -w-stu -w-ccc -w-rch\n!else\nCFLAGS= -O1 -w-par -w-stu -w-ccc -w-rch\n!endif\n# -O2 enables full code optimization (for pre-3.0 Borland C++, use -O -G -Z).\n# -O2 is buggy in Borland OS/2 C++ revision 2.0, so use -O1 there for now.\n# If you have Borland OS/2 C++ revision 1.0, use -O or no optimization at all.\n# -mm selects medium memory model (near data, far code pointers; DOS only!)\n# -w-par suppresses warnings about unused function parameters\n# -w-stu suppresses warnings about incomplete structures\n# -w-ccc suppresses warnings about compile-time-constant conditions\n# -w-rch suppresses warnings about unreachable code\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time cc options:\n!if $d(DOS)\nLDFLAGS= -mm\n# memory model option here must match CFLAGS!\n!else\nLDFLAGS=\n# -lai full-screen app\n# -lc case-significant link\n!endif\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.\n# For DOS, we recommend jmemdos.c and jmemdosa.asm.\n# For OS/2, we recommend jmemnobs.c (flat memory!)\n# SYSDEPMEMLIB must list the same files with \"+\" signs for the librarian.\n!if $d(DOS)\nSYSDEPMEM= jmemdos.obj jmemdosa.obj\nSYSDEPMEMLIB= +jmemdos.obj +jmemdosa.obj\n!else\nSYSDEPMEM= jmemnobs.obj\nSYSDEPMEMLIB= +jmemnobs.obj\n!endif\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \\\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \\\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj \\\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj \\\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj \\\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \\\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj \\\n        jdmerge.obj\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \\\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \\\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n\n\nall: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.lib: $(LIBOBJECTS)\n\t- del libjpeg.lib\n\ttlib libjpeg.lib /E /C @&&|\n+jcapimin.obj +jcapistd.obj +jcarith.obj +jctrans.obj +jcparam.obj &\n+jdatadst.obj +jcinit.obj +jcmaster.obj +jcmarker.obj +jcmainct.obj &\n+jcprepct.obj +jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj &\n+jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj +jfdctint.obj +jdapimin.obj &\n+jdapistd.obj +jdarith.obj +jdtrans.obj +jdatasrc.obj +jdmaster.obj &\n+jdinput.obj +jdmarker.obj +jdhuff.obj +jdmainct.obj +jdcoefct.obj &\n+jdpostct.obj +jddctmgr.obj +jidctfst.obj +jidctflt.obj +jidctint.obj &\n+jdsample.obj +jdcolor.obj +jquant1.obj +jquant2.obj +jdmerge.obj &\n+jaricom.obj +jcomapi.obj +jutils.obj +jerror.obj +jmemmgr.obj &\n$(SYSDEPMEMLIB)\n|\n\ncjpeg.exe: $(COBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) -ecjpeg.exe $(COBJECTS) libjpeg.lib\n\ndjpeg.exe: $(DOBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) -edjpeg.exe $(DOBJECTS) libjpeg.lib\n\njpegtran.exe: $(TROBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) -ejpegtran.exe $(TROBJECTS) libjpeg.lib\n\nrdjpgcom.exe: rdjpgcom.c\n!if $d(DOS)\n\t$(CC) -ms -O rdjpgcom.c\n!else\n\t$(CC) $(CFLAGS) rdjpgcom.c\n!endif\n\n# On DOS, wrjpgcom needs large model so it can malloc a 64K chunk\nwrjpgcom.exe: wrjpgcom.c\n!if $d(DOS)\n\t$(CC) -ml -O wrjpgcom.c\n!else\n\t$(CC) $(CFLAGS) wrjpgcom.c\n!endif\n\n# This \"{}\" syntax allows Borland Make to \"batch\" source files.\n# In this way, each run of the compiler can build many modules.\n.c.obj:\n\t$(CC) $(CFLAGS) -c{ $<}\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t- del *.obj\n\t- del libjpeg.lib\n\t- del cjpeg.exe\n\t- del djpeg.exe\n\t- del jpegtran.exe\n\t- del rdjpgcom.exe\n\t- del wrjpgcom.exe\n\t- del testout*.*\n\ntest: cjpeg.exe djpeg.exe jpegtran.exe\n\t- del testout*.*\n\tdjpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\tdjpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\tcjpeg -dct int -outfile testout.jpg  testimg.ppm\n\tdjpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tcjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tjpegtran -outfile testoutt.jpg testprog.jpg\n!if $d(DOS)\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n!else\n\techo n > n.tmp\n\tcomp testimg.ppm testout.ppm < n.tmp\n\tcomp testimg.bmp testout.bmp < n.tmp\n\tcomp testimg.jpg testout.jpg < n.tmp\n\tcomp testimg.ppm testoutp.ppm < n.tmp\n\tcomp testimgp.jpg testoutp.jpg < n.tmp\n\tcomp testorig.jpg testoutt.jpg < n.tmp\n\tdel n.tmp\n!endif\n\n\njaricom.obj: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\njmemdosa.obj: jmemdosa.asm\n\ttasm /mx jmemdosa.asm\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.dj",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for DJGPP (Delorie's GNU C port on MS-DOS), v2.0 or later.\n# Thanks to Frank J. Donahoe for this version.\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= gcc\n\n# You may need to adjust these cc options:\nCFLAGS= -O2 -Wall -I.\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time cc options:\nLDFLAGS= -s\n\n# To link any special libraries, add the necessary -l commands here.\nLDLIBS= \n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For DJGPP this is usually jmemnobs.o, but you could\n# use jmemname.o if you want to use named temp files instead of swap space.\nSYSDEPMEM= jmemnobs.o\n\n# miscellaneous OS-dependent stuff\n# linker\nLN= $(CC)\n# file deletion command\nRM= del\n# library (.a) file creation command\nAR= ar rc\n# second step in .a creation (use \"touch\" if not needed)\nAR2= ranlib\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o \\\n        jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o \\\n        jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o \\\n        jfdctflt.o jfdctint.o\n# decompression library object files\nDLIBOBJECTS= jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o \\\n        jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o \\\n        jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o \\\n        jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o\n# These objectfiles are included in libjpeg.a\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \\\n        cdjpeg.o\nDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \\\n        cdjpeg.o\nTROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o\n\n\nall: libjpeg.a cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.a: $(LIBOBJECTS)\n\t$(RM) libjpeg.a\n\t$(AR) libjpeg.a  $(LIBOBJECTS)\n\t$(AR2) libjpeg.a\n\ncjpeg.exe: $(COBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o cjpeg.exe $(COBJECTS) libjpeg.a $(LDLIBS)\n\ndjpeg.exe: $(DOBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o djpeg.exe $(DOBJECTS) libjpeg.a $(LDLIBS)\n\njpegtran.exe: $(TROBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o jpegtran.exe $(TROBJECTS) libjpeg.a $(LDLIBS)\n\nrdjpgcom.exe: rdjpgcom.o\n\t$(LN) $(LDFLAGS) -o rdjpgcom.exe rdjpgcom.o $(LDLIBS)\n\nwrjpgcom.exe: wrjpgcom.o\n\t$(LN) $(LDFLAGS) -o wrjpgcom.exe wrjpgcom.o $(LDLIBS)\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t$(RM) *.o\n\t$(RM) cjpeg.exe\n\t$(RM) djpeg.exe\n\t$(RM) jpegtran.exe\n\t$(RM) rdjpgcom.exe\n\t$(RM) wrjpgcom.exe\n\t$(RM) libjpeg.a\n\t$(RM) testout*.*\n\ntest: cjpeg.exe djpeg.exe jpegtran.exe\n\t$(RM) testout*.*\n\t./djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\t./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\t./cjpeg -dct int -outfile testout.jpg  testimg.ppm\n\t./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\t./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\t./jpegtran -outfile testoutt.jpg testprog.jpg\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n\n\njaricom.o: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.o: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.o: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.manx",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for Amiga systems using Manx Aztec C ver 5.x.\n# Thanks to D.J. James (djjames@cup.portal.com) for this version.\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= cc\n\n# You may need to adjust these cc options:\n# Uncomment for generic 68000 code (will work on any Amiga)\nARCHFLAGS= -sn\n\n# Uncomment for 68020/68030 code (faster, but won't run on 68000 CPU)\n#ARCHFLAGS= -c2\n\nCFLAGS= -MC -MD $(ARCHFLAGS) -spfam -r4\n\n# Link-time cc options:\nLDFLAGS= -g\n\n# To link any special libraries, add the necessary -l commands here.\nLDLIBS= -lml -lcl\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For Amiga we recommend jmemname.o.\nSYSDEPMEM= jmemname.o\n\n# miscellaneous OS-dependent stuff\n# linker\nLN= ln\n# file deletion command\nRM= delete quiet\n# library (.lib) file creation command\nAR= lb\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o \\\n        jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o \\\n        jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o \\\n        jfdctflt.o jfdctint.o\n# decompression library object files\nDLIBOBJECTS= jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o \\\n        jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o \\\n        jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o \\\n        jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \\\n        cdjpeg.o\nDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \\\n        cdjpeg.o\nTROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o\n\n\nall: libjpeg.lib cjpeg djpeg jpegtran rdjpgcom wrjpgcom\n\nlibjpeg.lib: $(LIBOBJECTS)\n\t-$(RM) libjpeg.lib\n\t$(AR) libjpeg.lib  $(LIBOBJECTS)\n\ncjpeg: $(COBJECTS) libjpeg.lib\n\t$(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.lib $(LDLIBS)\n\ndjpeg: $(DOBJECTS) libjpeg.lib\n\t$(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.lib $(LDLIBS)\n\njpegtran: $(TROBJECTS) libjpeg.lib\n\t$(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.lib $(LDLIBS)\n\nrdjpgcom: rdjpgcom.o\n\t$(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)\n\nwrjpgcom: wrjpgcom.o\n\t$(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t-$(RM) *.o cjpeg djpeg jpegtran libjpeg.lib rdjpgcom wrjpgcom\n\t-$(RM) core testout*.*\n\ntest: cjpeg djpeg jpegtran\n\t-$(RM) testout*.*\n\tdjpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\tdjpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\tcjpeg -dct int -outfile testout.jpg  testimg.ppm\n\tdjpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tcjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tjpegtran -outfile testoutt.jpg testprog.jpg\n\tcmp testimg.ppm testout.ppm\n\tcmp testimg.bmp testout.bmp\n\tcmp testimg.jpg testout.jpg\n\tcmp testimg.ppm testoutp.ppm\n\tcmp testimgp.jpg testoutp.jpg\n\tcmp testorig.jpg testoutt.jpg\n\n\njaricom.o: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.o: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.o: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.mc6",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for Microsoft C for MS-DOS, version 6.00A and up.\n# Use NMAKE, not Microsoft's brain-damaged MAKE.\n# Thanks to Alan Wright and Chris Turner of Olivetti Research Ltd.\n\n# Read installation instructions before saying \"nmake\" !!\n\n# You may need to adjust these compiler options:\nCFLAGS = -AM -Oecigt -Gs -W3\n# -AM medium memory model (or use -AS for small model, if you remove features)\n# -Oecigt -Gs  maximum safe optimisation (-Ol has bugs in MSC 6.00A)\n# -W3 warning level 3\n# You might also want to add -G2 if you have an 80286, etc.\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Jan-Herman Buining suggests the following switches for MS C 8.0 and a 486:\n# CFLAGS = /AM /f- /FPi87 /G3 /Gs /Gy /Ob1 /Oc /Oe /Og /Oi /Ol /On /Oo /Ot \\\n#          /OV4 /W3\n# except for jquant1.c, which must be compiled with /Oo- to avoid a compiler\n# crash.\n\n# Ingar Steinsland suggests the following switches when building\n# a 16-bit Windows DLL:\n# CFLAGS = -ALw -Gsw -Zpe -W3 -O2 -Zi -Zd\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For DOS, we recommend jmemdos.c and jmemdosa.asm.\n# (But not for Windows; see install.txt if you use this makefile for Windows.)\nSYSDEPMEM= jmemdos.obj jmemdosa.obj\n# SYSDEPMEMLIB must list the same files with \"+\" signs for the librarian.\nSYSDEPMEMLIB= +jmemdos.obj +jmemdosa.obj\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \\\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \\\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj \\\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj \\\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj \\\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \\\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj \\\n        jdmerge.obj\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \\\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \\\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n\n# need linker response file because file list > 128 chars\nRFILE = libjpeg.ans\n\n\nall: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.lib: $(LIBOBJECTS) $(RFILE)\n\tdel libjpeg.lib\n\tlib @$(RFILE)\n\n# linker response file for building libjpeg.lib\n$(RFILE) : makefile\n\tdel $(RFILE)\n\techo libjpeg.lib >$(RFILE)\n# silly want-to-create-it prompt:\n\techo y >>$(RFILE)\n\techo +jcapimin.obj +jcapistd.obj +jcarith.obj +jctrans.obj & >>$(RFILE)\n\techo +jcparam.obj +jdatadst.obj +jcinit.obj +jcmaster.obj & >>$(RFILE)\n\techo +jcmarker.obj +jcmainct.obj +jcprepct.obj & >>$(RFILE)\n\techo +jccoefct.obj +jccolor.obj +jcsample.obj +jchuff.obj & >>$(RFILE)\n\techo +jcdctmgr.obj +jfdctfst.obj +jfdctflt.obj & >>$(RFILE)\n\techo +jfdctint.obj +jdapimin.obj +jdapistd.obj & >>$(RFILE)\n\techo +jdarith.obj +jdtrans.obj +jdatasrc.obj +jdmaster.obj & >>$(RFILE)\n\techo +jdinput.obj +jdmarker.obj +jdhuff.obj +jdmainct.obj & >>$(RFILE)\n\techo +jdcoefct.obj +jdpostct.obj +jddctmgr.obj & >>$(RFILE)\n\techo +jidctfst.obj +jidctflt.obj +jidctint.obj & >>$(RFILE)\n\techo +jdsample.obj +jdcolor.obj +jquant1.obj & >>$(RFILE)\n\techo +jquant2.obj +jdmerge.obj +jaricom.obj +jcomapi.obj & >>$(RFILE)\n\techo +jutils.obj +jerror.obj +jmemmgr.obj & >>$(RFILE)\n\techo $(SYSDEPMEMLIB) ; >>$(RFILE)\n\ncjpeg.exe: $(COBJECTS) libjpeg.lib\n\techo $(COBJECTS) >cjpeg.lst\n\tlink /STACK:4096 /EXEPACK @cjpeg.lst, cjpeg.exe, , libjpeg.lib, ;\n\tdel cjpeg.lst\n\ndjpeg.exe: $(DOBJECTS) libjpeg.lib\n\techo $(DOBJECTS) >djpeg.lst\n\tlink /STACK:4096 /EXEPACK @djpeg.lst, djpeg.exe, , libjpeg.lib, ;\n\tdel djpeg.lst\n\njpegtran.exe: $(TROBJECTS) libjpeg.lib\n\tlink /STACK:4096 /EXEPACK $(TROBJECTS), jpegtran.exe, , libjpeg.lib, ;\n\nrdjpgcom.exe: rdjpgcom.c\n\t$(CC) -AS -O -W3 rdjpgcom.c\n\n# wrjpgcom needs large model so it can malloc a 64K chunk\nwrjpgcom.exe: wrjpgcom.c\n\t$(CC) -AL -O -W3 wrjpgcom.c\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\tdel *.obj\n\tdel libjpeg.lib\n\tdel cjpeg.exe\n\tdel djpeg.exe\n\tdel jpegtran.exe\n\tdel rdjpgcom.exe\n\tdel wrjpgcom.exe\n\tdel testout*.*\n\ntest: cjpeg.exe djpeg.exe jpegtran.exe\n\tdel testout*.*\n\tdjpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\tdjpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\tcjpeg -dct int -outfile testout.jpg  testimg.ppm\n\tdjpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tcjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tjpegtran -outfile testoutt.jpg testprog.jpg\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n\n\njaricom.obj: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\njmemdosa.obj : jmemdosa.asm\n\tmasm /mx $*;\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.mms",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for use with MMS on Digital VMS systems.\n# Thanks to Rick Dyson (dyson@iowasp.physics.uiowa.edu)\n# and Tim Bell (tbell@netcom.com) for their help.\n\n# Read installation instructions before saying \"MMS\" !!\n\n# You may need to adjust these cc options:\nCFLAGS= $(CFLAGS) /NoDebug /Optimize\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via /Define switches here.\n.ifdef ALPHA\nOPT=\n.else\nOPT= ,Sys$Disk:[]MAKVMS.OPT/Option\n.endif\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For Unix this is usually jmemnobs.o, but you may want\n# to use jmemansi.o or jmemname.o if you have limited swap space.\nSYSDEPMEM= jmemnobs.obj\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \\\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \\\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj \\\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj \\\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj \\\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \\\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj \\\n        jdmerge.obj\n# These objectfiles are included in libjpeg.olb\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \\\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \\\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n# objectfile lists with commas --- what a crock\nCOBJLIST= cjpeg.obj,rdppm.obj,rdgif.obj,rdtarga.obj,rdrle.obj,rdbmp.obj,\\\n          rdswitch.obj,cdjpeg.obj\nDOBJLIST= djpeg.obj,wrppm.obj,wrgif.obj,wrtarga.obj,wrrle.obj,wrbmp.obj,\\\n          rdcolmap.obj,cdjpeg.obj\nTROBJLIST= jpegtran.obj,rdswitch.obj,cdjpeg.obj,transupp.obj\nLIBOBJLIST= jaricom.obj,jcapimin.obj,jcapistd.obj,jcarith.obj,jctrans.obj,\\\n          jcparam.obj,jdatadst.obj,jcinit.obj,jcmaster.obj,jcmarker.obj,\\\n          jcmainct.obj,jcprepct.obj,jccoefct.obj,jccolor.obj,jcsample.obj,\\\n          jchuff.obj,jcdctmgr.obj,jfdctfst.obj,jfdctflt.obj,jfdctint.obj,\\\n          jdapimin.obj,jdapistd.obj,jdarith.obj,jdtrans.obj,jdatasrc.obj,\\\n          jdmaster.obj,jdinput.obj,jdmarker.obj,jdhuff.obj,jdmainct.obj,\\\n          jdcoefct.obj,jdpostct.obj,jddctmgr.obj,jidctfst.obj,jidctflt.obj,\\\n          jidctint.obj,jdsample.obj,jdcolor.obj,jquant1.obj,jquant2.obj,\\\n          jdmerge.obj,jcomapi.obj,jutils.obj,jerror.obj,jmemmgr.obj,$(SYSDEPMEM)\n\n\n.first\n\t@- Define /NoLog Sys Sys$Library\n\nALL : libjpeg.olb cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\t@ Continue\n\nlibjpeg.olb : $(LIBOBJECTS)\n\tLibrary /Create libjpeg.olb $(LIBOBJLIST)\n\ncjpeg.exe : $(COBJECTS) libjpeg.olb\n\t$(LINK) $(LFLAGS) /Executable = cjpeg.exe $(COBJLIST),libjpeg.olb/Library$(OPT)\n\ndjpeg.exe : $(DOBJECTS) libjpeg.olb\n\t$(LINK) $(LFLAGS) /Executable = djpeg.exe $(DOBJLIST),libjpeg.olb/Library$(OPT)\n\njpegtran.exe : $(TROBJECTS) libjpeg.olb\n\t$(LINK) $(LFLAGS) /Executable = jpegtran.exe $(TROBJLIST),libjpeg.olb/Library$(OPT)\n\nrdjpgcom.exe : rdjpgcom.obj\n\t$(LINK) $(LFLAGS) /Executable = rdjpgcom.exe rdjpgcom.obj$(OPT)\n\nwrjpgcom.exe : wrjpgcom.obj\n\t$(LINK) $(LFLAGS) /Executable = wrjpgcom.exe wrjpgcom.obj$(OPT)\n\njconfig.h : jconfig.vms\n\t@- Copy jconfig.vms jconfig.h\n\nclean :\n\t@- Set Protection = Owner:RWED *.*;-1\n\t@- Set Protection = Owner:RWED *.OBJ\n\t- Purge /NoLog /NoConfirm *.*\n\t- Delete /NoLog /NoConfirm *.OBJ;\n\ntest : cjpeg.exe djpeg.exe jpegtran.exe\n\tmcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg\n\tmcr sys$disk:[]djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg\n\tmcr sys$disk:[]cjpeg -dct int      -outfile testout.jpg testimg.ppm\n\tmcr sys$disk:[]djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tmcr sys$disk:[]cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tmcr sys$disk:[]jpegtran -outfile testoutt.jpg testprog.jpg\n\t- Backup /Compare/Log\t  testimg.ppm testout.ppm\n\t- Backup /Compare/Log\t  testimg.bmp testout.bmp\n\t- Backup /Compare/Log\t  testimg.jpg testout.jpg\n\t- Backup /Compare/Log\t  testimg.ppm testoutp.ppm\n\t- Backup /Compare/Log\t  testimgp.jpg testoutp.jpg\n\t- Backup /Compare/Log\t  testorig.jpg testoutt.jpg\n\n\njaricom.obj : jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj : jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj : jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj : jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj : jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj : jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj : jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj : jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj : jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj : jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj : jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj : jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj : jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj : jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj : jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj : jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj : jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj : jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj : jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj : jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj : jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj : jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj : jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj : jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj : jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj : jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj : jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj : jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj : jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj : jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj : jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj : jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj : jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj : jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj : jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj : jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj : jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj : jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj : jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj : jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj : jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj : jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj : jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj : jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj : jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj : jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj : jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj : jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj : jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj : jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj : cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj : djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj : jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj : rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj : wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj : cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj : rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj : rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj : transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj : rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj : wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj : rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj : wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj : rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj : wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj : rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj : wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj : rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj : wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.sas",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for Amiga systems using SAS C 6.0 and up.\n# Thanks to Ed Hanway, Mark Rinfret, and Jim Zepeda.\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= sc\n\n# You may need to adjust these cc options:\n# Uncomment the following lines for generic 680x0 version\nARCHFLAGS= cpu=any\nSUFFIX=\n\n# Uncomment the following lines for 68030-only version\n#ARCHFLAGS= cpu=68030\n#SUFFIX=.030\n\nCFLAGS= nostackcheck data=near parms=register optimize $(ARCHFLAGS) \\\n\tignore=104 ignore=304 ignore=306\n# ignore=104 disables warnings for mismatched const qualifiers\n# ignore=304 disables warnings for variables being optimized out\n# ignore=306 disables warnings for the inlining of functions\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via define switches here.\n\n# Link-time cc options:\nLDFLAGS= SC SD ND BATCH\n\n# To link any special libraries, add the necessary commands here.\nLDLIBS= LIB:scm.lib LIB:sc.lib\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For Amiga we recommend jmemname.o.\nSYSDEPMEM= jmemname.o\n\n# miscellaneous OS-dependent stuff\n# linker\nLN= slink\n# file deletion command\nRM= delete quiet\n# library (.lib) file creation command\nAR= oml\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o \\\n        jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o \\\n        jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o \\\n        jfdctflt.o jfdctint.o\n# decompression library object files\nDLIBOBJECTS= jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o \\\n        jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o \\\n        jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o \\\n        jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \\\n        cdjpeg.o\nDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \\\n        cdjpeg.o\nTROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o\n\n\nall: libjpeg.lib cjpeg$(SUFFIX) djpeg$(SUFFIX) jpegtran$(SUFFIX) rdjpgcom$(SUFFIX) wrjpgcom$(SUFFIX)\n\n# note: do several AR steps to avoid command line length limitations\n\nlibjpeg.lib: $(LIBOBJECTS)\n\t-$(RM) libjpeg.lib\n\t$(AR) libjpeg.lib r $(CLIBOBJECTS)\n\t$(AR) libjpeg.lib r $(DLIBOBJECTS)\n\t$(AR) libjpeg.lib r $(COMOBJECTS)\n\ncjpeg$(SUFFIX): $(COBJECTS) libjpeg.lib\n\t$(LN) <WITH <\n$(LDFLAGS)\nTO cjpeg$(SUFFIX)\nFROM LIB:c.o $(COBJECTS)\nLIB libjpeg.lib $(LDLIBS)\n<\n\ndjpeg$(SUFFIX): $(DOBJECTS) libjpeg.lib\n\t$(LN) <WITH <\n$(LDFLAGS)\nTO djpeg$(SUFFIX)\nFROM LIB:c.o $(DOBJECTS)\nLIB libjpeg.lib $(LDLIBS)\n<\n\njpegtran$(SUFFIX): $(TROBJECTS) libjpeg.lib\n\t$(LN) <WITH <\n$(LDFLAGS)\nTO jpegtran$(SUFFIX)\nFROM LIB:c.o $(TROBJECTS)\nLIB libjpeg.lib $(LDLIBS)\n<\n\nrdjpgcom$(SUFFIX): rdjpgcom.o\n\t$(LN) <WITH <\n$(LDFLAGS)\nTO rdjpgcom$(SUFFIX)\nFROM LIB:c.o rdjpgcom.o\nLIB $(LDLIBS)\n<\n\nwrjpgcom$(SUFFIX): wrjpgcom.o\n\t$(LN) <WITH <\n$(LDFLAGS)\nTO wrjpgcom$(SUFFIX)\nFROM LIB:c.o wrjpgcom.o\nLIB $(LDLIBS)\n<\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t-$(RM) *.o cjpeg djpeg jpegtran cjpeg.030 djpeg.030 jpegtran.030\n\t-$(RM) rdjpgcom wrjpgcom rdjpgcom.030 wrjpgcom.030\n\t-$(RM) libjpeg.lib core testout*.*\n\ntest: cjpeg djpeg jpegtran\n\t-$(RM) testout*.*\n\tdjpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\tdjpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\tcjpeg -dct int -outfile testout.jpg  testimg.ppm\n\tdjpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tcjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tjpegtran -outfile testoutt.jpg testprog.jpg\n\tcmp testimg.ppm testout.ppm\n\tcmp testimg.bmp testout.bmp\n\tcmp testimg.jpg testout.jpg\n\tcmp testimg.ppm testoutp.ppm\n\tcmp testimgp.jpg testoutp.jpg\n\tcmp testorig.jpg testoutt.jpg\n\n\njaricom.o: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.o: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.o: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.unix",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is suitable for Unix-like systems with non-ANSI compilers.\n# If you have an ANSI compiler, makefile.ansi is a better starting point.\n\n# Read installation instructions before saying \"make\" !!\n\n# The name of your C compiler:\nCC= cc\n\n# You may need to adjust these cc options:\nCFLAGS= -O\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n# However, any special defines for ansi2knr.c may be included here:\nANSI2KNRFLAGS= \n\n# Link-time cc options:\nLDFLAGS= \n\n# To link any special libraries, add the necessary -l commands here.\nLDLIBS= \n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For Unix this is usually jmemnobs.o, but you may want\n# to use jmemansi.o or jmemname.o if you have limited swap space.\nSYSDEPMEM= jmemnobs.o\n\n# miscellaneous OS-dependent stuff\n# linker\nLN= $(CC)\n# file deletion command\nRM= rm -f\n# file rename command\nMV= mv\n# library (.a) file creation command\nAR= ar rc\n# second step in .a creation (use \"touch\" if not needed)\nAR2= ranlib\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.o jcomapi.o jutils.o jerror.o jmemmgr.o $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.o jcapistd.o jcarith.o jctrans.o jcparam.o \\\n        jdatadst.o jcinit.o jcmaster.o jcmarker.o jcmainct.o jcprepct.o \\\n        jccoefct.o jccolor.o jcsample.o jchuff.o jcdctmgr.o jfdctfst.o \\\n        jfdctflt.o jfdctint.o\n# decompression library object files\nDLIBOBJECTS= jdapimin.o jdapistd.o jdarith.o jdtrans.o jdatasrc.o \\\n        jdmaster.o jdinput.o jdmarker.o jdhuff.o jdmainct.o \\\n        jdcoefct.o jdpostct.o jddctmgr.o jidctfst.o jidctflt.o \\\n        jidctint.o jdsample.o jdcolor.o jquant1.o jquant2.o jdmerge.o\n# These objectfiles are included in libjpeg.a\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.o rdppm.o rdgif.o rdtarga.o rdrle.o rdbmp.o rdswitch.o \\\n        cdjpeg.o\nDOBJECTS= djpeg.o wrppm.o wrgif.o wrtarga.o wrrle.o wrbmp.o rdcolmap.o \\\n        cdjpeg.o\nTROBJECTS= jpegtran.o rdswitch.o cdjpeg.o transupp.o\n\n\nall: ansi2knr libjpeg.a cjpeg djpeg jpegtran rdjpgcom wrjpgcom\n\n# This rule causes ansi2knr to be invoked.\n.c.o:\n\t./ansi2knr $*.c T$*.c\n\t$(CC) $(CFLAGS) -c T$*.c\n\t$(RM) T$*.c $*.o\n\t$(MV) T$*.o $*.o\n\nansi2knr: ansi2knr.c\n\t$(CC) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c\n\nlibjpeg.a: ansi2knr $(LIBOBJECTS)\n\t$(RM) libjpeg.a\n\t$(AR) libjpeg.a  $(LIBOBJECTS)\n\t$(AR2) libjpeg.a\n\ncjpeg: ansi2knr $(COBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o cjpeg $(COBJECTS) libjpeg.a $(LDLIBS)\n\ndjpeg: ansi2knr $(DOBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o djpeg $(DOBJECTS) libjpeg.a $(LDLIBS)\n\njpegtran: ansi2knr $(TROBJECTS) libjpeg.a\n\t$(LN) $(LDFLAGS) -o jpegtran $(TROBJECTS) libjpeg.a $(LDLIBS)\n\nrdjpgcom: rdjpgcom.o\n\t$(LN) $(LDFLAGS) -o rdjpgcom rdjpgcom.o $(LDLIBS)\n\nwrjpgcom: wrjpgcom.o\n\t$(LN) $(LDFLAGS) -o wrjpgcom wrjpgcom.o $(LDLIBS)\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean:\n\t$(RM) *.o cjpeg djpeg jpegtran libjpeg.a rdjpgcom wrjpgcom\n\t$(RM) ansi2knr core testout*\n\ntest: cjpeg djpeg jpegtran\n\t$(RM) testout*\n\t./djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\t./djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\t./cjpeg -dct int -outfile testout.jpg  testimg.ppm\n\t./djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\t./cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\t./jpegtran -outfile testoutt.jpg testprog.jpg\n\tcmp testimg.ppm testout.ppm\n\tcmp testimg.bmp testout.bmp\n\tcmp testimg.jpg testout.jpg\n\tcmp testimg.ppm testoutp.ppm\n\tcmp testimgp.jpg testoutp.jpg\n\tcmp testorig.jpg testoutt.jpg\n\n\njaricom.o: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.o: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.o: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.o: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.o: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.o: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.o: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.o: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.o: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.o: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.o: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.o: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.o: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.o: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.o: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.o: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.o: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.o: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.o: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.o: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.o: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.o: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.o: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.o: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.o: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.o: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.o: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.o: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.o: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.o: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.o: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.o: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.o: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.o: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.o: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.o: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.o: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.o: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.o: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.o: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.o: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.o: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.o: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.o: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.o: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.o: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.o: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.o: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.o: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.o: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.o: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.o: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.o: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.o: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.o: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.o: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.o: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.o: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.o: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.o: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.o: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.o: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.o: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.o: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.o: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.o: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.o: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.o: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.o: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.vc",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is for Microsoft Visual C++ on Windows NT (and 95?).\n# It builds the IJG library as a statically linkable library (.LIB),\n# and builds the sample applications as console-mode apps.\n# Thanks to Xingong Chang, Raymond Everly and others.\n\n# Read installation instructions before saying \"nmake\" !!\n# To build an optimized library without debug info, say \"nmake nodebug=1\".\n\n# Pull in standard variable definitions\n!include <win32.mak>\n\n# You may want to adjust these compiler options:\nCFLAGS= $(cflags) $(cdebug) $(cvars) -I.\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time options:\nLDFLAGS= $(ldebug) $(conlflags)\n\n# To link any special libraries, add the necessary commands here.\nLDLIBS= $(conlibs)\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  For NT we suggest jmemnobs.obj, which expects the OS to\n# provide adequate virtual memory.\nSYSDEPMEM= jmemnobs.obj\n\n# miscellaneous OS-dependent stuff\n# file deletion command\nRM= del\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c \\\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c \\\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c \\\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c \\\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c \\\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c \\\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c \\\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c \\\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c \\\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h \\\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 \\\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt \\\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 \\\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc \\\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 \\\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 \\\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 \\\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 \\\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 \\\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 \\\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac \\\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx \\\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat \\\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas \\\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp \\\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg \\\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) \\\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj \\\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj \\\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj \\\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj \\\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj \\\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj \\\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj \\\n        jdmerge.obj\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj \\\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj \\\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n\n# Template command for compiling .c to .obj\n.c.obj:\n\t$(cc) $(CFLAGS) $*.c\n\n\nall: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.lib: $(LIBOBJECTS)\n\t$(RM) libjpeg.lib\n\tlib -out:libjpeg.lib  $(LIBOBJECTS)\n\ncjpeg.exe: $(COBJECTS) libjpeg.lib\n\t$(link) $(LDFLAGS) -out:cjpeg.exe $(COBJECTS) libjpeg.lib $(LDLIBS)\n\ndjpeg.exe: $(DOBJECTS) libjpeg.lib\n\t$(link) $(LDFLAGS) -out:djpeg.exe $(DOBJECTS) libjpeg.lib $(LDLIBS)\n\njpegtran.exe: $(TROBJECTS) libjpeg.lib\n\t$(link) $(LDFLAGS) -out:jpegtran.exe $(TROBJECTS) libjpeg.lib $(LDLIBS)\n\nrdjpgcom.exe: rdjpgcom.obj\n\t$(link) $(LDFLAGS) -out:rdjpgcom.exe rdjpgcom.obj $(LDLIBS)\n\nwrjpgcom.exe: wrjpgcom.obj\n\t$(link) $(LDFLAGS) -out:wrjpgcom.exe wrjpgcom.obj $(LDLIBS)\n\n\nclean:\n\t$(RM) *.obj *.exe libjpeg.lib\n\t$(RM) testout*\n\nsetup-vc6:\n\tren jconfig.vc jconfig.h\n\tren makejdsw.vc6 jpeg.dsw\n\tren makeadsw.vc6 apps.dsw\n\tren makejmak.vc6 jpeg.mak\n\tren makejdep.vc6 jpeg.dep\n\tren makejdsp.vc6 jpeg.dsp\n\tren makecmak.vc6 cjpeg.mak\n\tren makecdep.vc6 cjpeg.dep\n\tren makecdsp.vc6 cjpeg.dsp\n\tren makedmak.vc6 djpeg.mak\n\tren makeddep.vc6 djpeg.dep\n\tren makeddsp.vc6 djpeg.dsp\n\tren maketmak.vc6 jpegtran.mak\n\tren maketdep.vc6 jpegtran.dep\n\tren maketdsp.vc6 jpegtran.dsp\n\tren makermak.vc6 rdjpgcom.mak\n\tren makerdep.vc6 rdjpgcom.dep\n\tren makerdsp.vc6 rdjpgcom.dsp\n\tren makewmak.vc6 wrjpgcom.mak\n\tren makewdep.vc6 wrjpgcom.dep\n\tren makewdsp.vc6 wrjpgcom.dsp\n\nsetup-v10:\n\tren jconfig.vc jconfig.h\n\tren makejsln.v10 jpeg.sln\n\tren makeasln.v10 apps.sln\n\tren makejvcx.v10 jpeg.vcxproj\n\tren makejfil.v10 jpeg.vcxproj.filters\n\tren makecvcx.v10 cjpeg.vcxproj\n\tren makecfil.v10 cjpeg.vcxproj.filters\n\tren makedvcx.v10 djpeg.vcxproj\n\tren makedfil.v10 djpeg.vcxproj.filters\n\tren maketvcx.v10 jpegtran.vcxproj\n\tren maketfil.v10 jpegtran.vcxproj.filters\n\tren makervcx.v10 rdjpgcom.vcxproj\n\tren makerfil.v10 rdjpgcom.vcxproj.filters\n\tren makewvcx.v10 wrjpgcom.vcxproj\n\tren makewfil.v10 wrjpgcom.vcxproj.filters\n\ntest:\n\tIF EXIST testout* $(RM) testout*\n\t.\\djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\t.\\djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\t.\\cjpeg -dct int -outfile testout.jpg  testimg.ppm\n\t.\\djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\t.\\cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\t.\\jpegtran -outfile testoutt.jpg testprog.jpg\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n\ntest-build:\n\tIF EXIST testout* $(RM) testout*\n\t.\\djpeg\\Release\\djpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\t.\\djpeg\\Release\\djpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\t.\\cjpeg\\Release\\cjpeg -dct int -outfile testout.jpg  testimg.ppm\n\t.\\djpeg\\Release\\djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\t.\\cjpeg\\Release\\cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\t.\\jpegtran\\Release\\jpegtran -outfile testoutt.jpg testprog.jpg\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n\n\njaricom.obj: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.vms",
    "content": "$! Makefile for Independent JPEG Group's software\n$!\n$! This is a command procedure for Digital VMS systems that do not have MMS.\n$! It builds the JPEG software by brute force, recompiling everything whether\n$! or not it is necessary.  It then runs the basic self-test.\n$! Thanks to Rick Dyson (dyson@iowasp.physics.uiowa.edu)\n$! and Tim Bell (tbell@netcom.com) for their help.\n$!\n$! Read installation instructions before running this!!\n$!\n$ If F$Mode () .eqs. \"INTERACTIVE\"\n$   Then\n$       VERIFY = F$Verify (0)\n$   Else\n$       VERIFY = F$Verify (1)\n$ EndIf\n$ On Control_Y Then GoTo End\n$ On Error     Then GoTo End\n$\n$ If F$GetSyi (\"HW_MODEL\") .gt. 1023 \n$   Then\n$       OPT = \"\"\n$   Else\n$       OPT = \",Sys$Disk:[]makvms.opt/Option\"\n$ EndIf\n$ \n$ DoCompile := CC /NoDebug /Optimize /NoList\n$!\n$ DoCompile jaricom.c\n$ DoCompile jcapimin.c\n$ DoCompile jcapistd.c\n$ DoCompile jcarith.c\n$ DoCompile jctrans.c\n$ DoCompile jcparam.c\n$ DoCompile jdatadst.c\n$ DoCompile jcinit.c\n$ DoCompile jcmaster.c\n$ DoCompile jcmarker.c\n$ DoCompile jcmainct.c\n$ DoCompile jcprepct.c\n$ DoCompile jccoefct.c\n$ DoCompile jccolor.c\n$ DoCompile jcsample.c\n$ DoCompile jchuff.c\n$ DoCompile jcdctmgr.c\n$ DoCompile jfdctfst.c\n$ DoCompile jfdctflt.c\n$ DoCompile jfdctint.c\n$ DoCompile jdapimin.c\n$ DoCompile jdapistd.c\n$ DoCompile jdarith.c\n$ DoCompile jdtrans.c\n$ DoCompile jdatasrc.c\n$ DoCompile jdmaster.c\n$ DoCompile jdinput.c\n$ DoCompile jdmarker.c\n$ DoCompile jdhuff.c\n$ DoCompile jdmainct.c\n$ DoCompile jdcoefct.c\n$ DoCompile jdpostct.c\n$ DoCompile jddctmgr.c\n$ DoCompile jidctfst.c\n$ DoCompile jidctflt.c\n$ DoCompile jidctint.c\n$ DoCompile jdsample.c\n$ DoCompile jdcolor.c\n$ DoCompile jquant1.c\n$ DoCompile jquant2.c\n$ DoCompile jdmerge.c\n$ DoCompile jcomapi.c\n$ DoCompile jutils.c\n$ DoCompile jerror.c\n$ DoCompile jmemmgr.c\n$ DoCompile jmemnobs.c\n$!\n$ Library /Create libjpeg.olb  jaricom.obj,jcapimin.obj,jcapistd.obj, -\n          jcarith.obj,jctrans.obj,jcparam.obj,jdatadst.obj,jcinit.obj, -\n          jcmaster.obj,jcmarker.obj,jcmainct.obj,jcprepct.obj,jccoefct.obj, -\n          jccolor.obj,jcsample.obj,jchuff.obj,jcdctmgr.obj,jfdctfst.obj, -\n          jfdctflt.obj,jfdctint.obj,jdapimin.obj,jdapistd.obj,jdarith.obj, -\n          jdtrans.obj,jdatasrc.obj,jdmaster.obj,jdinput.obj,jdmarker.obj, -\n          jdhuff.obj,jdmainct.obj,jdcoefct.obj,jdpostct.obj,jddctmgr.obj, -\n          jidctfst.obj,jidctflt.obj,jidctint.obj,jdsample.obj,jdcolor.obj, -\n          jquant1.obj,jquant2.obj,jdmerge.obj,jcomapi.obj,jutils.obj, -\n          jerror.obj,jmemmgr.obj,jmemnobs.obj\n$!\n$ DoCompile cjpeg.c\n$ DoCompile rdppm.c\n$ DoCompile rdgif.c\n$ DoCompile rdtarga.c\n$ DoCompile rdrle.c\n$ DoCompile rdbmp.c\n$ DoCompile rdswitch.c\n$ DoCompile cdjpeg.c\n$!\n$ Link /NoMap /Executable = cjpeg.exe  cjpeg.obj,rdppm.obj,rdgif.obj, -\n          rdtarga.obj,rdrle.obj,rdbmp.obj,rdswitch.obj,cdjpeg.obj,libjpeg.olb/Library'OPT'\n$!\n$ DoCompile djpeg.c\n$ DoCompile wrppm.c\n$ DoCompile wrgif.c\n$ DoCompile wrtarga.c\n$ DoCompile wrrle.c\n$ DoCompile wrbmp.c\n$ DoCompile rdcolmap.c\n$ DoCompile cdjpeg.c\n$!\n$ Link /NoMap /Executable = djpeg.exe  djpeg.obj,wrppm.obj,wrgif.obj, -\n          wrtarga.obj,wrrle.obj,wrbmp.obj,rdcolmap.obj,cdjpeg.obj,libjpeg.olb/Library'OPT'\n$!\n$ DoCompile jpegtran.c\n$ DoCompile rdswitch.c\n$ DoCompile cdjpeg.c\n$ DoCompile transupp.c\n$!\n$ Link /NoMap /Executable = jpegtran.exe  jpegtran.obj,rdswitch.obj, -\n          cdjpeg.obj,transupp.obj,libjpeg.olb/Library'OPT'\n$!\n$ DoCompile rdjpgcom.c\n$ Link /NoMap /Executable = rdjpgcom.exe  rdjpgcom.obj'OPT'\n$!\n$ DoCompile wrjpgcom.c\n$ Link /NoMap /Executable = wrjpgcom.exe  wrjpgcom.obj'OPT'\n$!\n$! Run the self-test\n$!\n$ mcr sys$disk:[]djpeg -dct int -ppm -outfile testout.ppm testorig.jpg\n$ mcr sys$disk:[]djpeg -dct int -bmp -colors 256 -outfile testout.bmp testorig.jpg\n$ mcr sys$disk:[]cjpeg -dct int      -outfile testout.jpg testimg.ppm\n$ mcr sys$disk:[]djpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n$ mcr sys$disk:[]cjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n$ mcr sys$disk:[]jpegtran -outfile testoutt.jpg testprog.jpg\n$ Backup /Compare/Log testimg.ppm testout.ppm\n$ Backup /Compare/Log testimg.bmp testout.bmp\n$ Backup /Compare/Log testimg.jpg testout.jpg\n$ Backup /Compare/Log testimg.ppm testoutp.ppm\n$ Backup /Compare/Log testimgp.jpg testoutp.jpg\n$ Backup /Compare/Log testorig.jpg testoutt.jpg\n$!\n$End:\n$   If Verify Then Set Verify\n$ Exit\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makefile.wat",
    "content": "# Makefile for Independent JPEG Group's software\n\n# This makefile is suitable for Watcom C/C++ 10.0 on MS-DOS (using\n# dos4g extender), OS/2, and Windows NT console mode.\n# Thanks to Janos Haide, jhaide@btrvtech.com.\n\n# Read installation instructions before saying \"wmake\" !!\n\n# Uncomment line for desired system\nSYSTEM=DOS\n#SYSTEM=OS2\n#SYSTEM=NT\n\n# The name of your C compiler:\nCC= wcl386\n\n# You may need to adjust these cc options:\nCFLAGS= -4r -ort -wx -zq -bt=$(SYSTEM)\n# Caution: avoid -ol or -ox; these generate bad code with 10.0 or 10.0a.\n# Generally, we recommend defining any configuration symbols in jconfig.h,\n# NOT via -D switches here.\n\n# Link-time cc options:\n!ifeq SYSTEM DOS\nLDFLAGS= -zq -l=dos4g\n!else ifeq SYSTEM OS2\nLDFLAGS= -zq -l=os2v2\n!else ifeq SYSTEM NT\nLDFLAGS= -zq -l=nt\n!endif\n\n# Put here the object file name for the correct system-dependent memory\n# manager file.  jmemnobs should work fine for dos4g or OS/2 environment.\nSYSDEPMEM= jmemnobs.obj\n\n# End of configurable options.\n\n\n# source files: JPEG library proper\nLIBSOURCES= jaricom.c jcapimin.c jcapistd.c jcarith.c jccoefct.c jccolor.c &\n        jcdctmgr.c jchuff.c jcinit.c jcmainct.c jcmarker.c jcmaster.c &\n        jcomapi.c jcparam.c jcprepct.c jcsample.c jctrans.c jdapimin.c &\n        jdapistd.c jdarith.c jdatadst.c jdatasrc.c jdcoefct.c jdcolor.c &\n        jddctmgr.c jdhuff.c jdinput.c jdmainct.c jdmarker.c jdmaster.c &\n        jdmerge.c jdpostct.c jdsample.c jdtrans.c jerror.c jfdctflt.c &\n        jfdctfst.c jfdctint.c jidctflt.c jidctfst.c jidctint.c jquant1.c &\n        jquant2.c jutils.c jmemmgr.c\n# memmgr back ends: compile only one of these into a working library\nSYSDEPSOURCES= jmemansi.c jmemname.c jmemnobs.c jmemdos.c jmemmac.c\n# source files: cjpeg/djpeg/jpegtran applications, also rdjpgcom/wrjpgcom\nAPPSOURCES= cjpeg.c djpeg.c jpegtran.c rdjpgcom.c wrjpgcom.c cdjpeg.c &\n        rdcolmap.c rdswitch.c transupp.c rdppm.c wrppm.c rdgif.c wrgif.c &\n        rdtarga.c wrtarga.c rdbmp.c wrbmp.c rdrle.c wrrle.c\nSOURCES= $(LIBSOURCES) $(SYSDEPSOURCES) $(APPSOURCES)\n# files included by source files\nINCLUDES= jdct.h jerror.h jinclude.h jmemsys.h jmorecfg.h jpegint.h &\n        jpeglib.h jversion.h cdjpeg.h cderror.h transupp.h\n# documentation, test, and support files\nDOCS= README install.txt usage.txt cjpeg.1 djpeg.1 jpegtran.1 rdjpgcom.1 &\n        wrjpgcom.1 wizard.txt example.c libjpeg.txt structure.txt &\n        coderules.txt filelist.txt change.log\nMKFILES= configure Makefile.in makefile.ansi makefile.unix makefile.b32 &\n        makefile.bcc makefile.mc6 makefile.dj makefile.wat makefile.vc &\n        makejdsw.vc6 makeadsw.vc6 makejdep.vc6 makejdsp.vc6 makejmak.vc6 &\n        makecdep.vc6 makecdsp.vc6 makecmak.vc6 makeddep.vc6 makeddsp.vc6 &\n        makedmak.vc6 maketdep.vc6 maketdsp.vc6 maketmak.vc6 makerdep.vc6 &\n        makerdsp.vc6 makermak.vc6 makewdep.vc6 makewdsp.vc6 makewmak.vc6 &\n        makejsln.v10 makeasln.v10 makejvcx.v10 makejfil.v10 makecvcx.v10 &\n        makecfil.v10 makedvcx.v10 makedfil.v10 maketvcx.v10 maketfil.v10 &\n        makervcx.v10 makerfil.v10 makewvcx.v10 makewfil.v10 makeproj.mac &\n        makcjpeg.st makdjpeg.st makljpeg.st maktjpeg.st makefile.manx &\n        makefile.sas makefile.mms makefile.vms makvms.opt\nCONFIGFILES= jconfig.cfg jconfig.bcc jconfig.mc6 jconfig.dj jconfig.wat &\n        jconfig.vc jconfig.mac jconfig.st jconfig.manx jconfig.sas &\n        jconfig.vms\nCONFIGUREFILES= config.guess config.sub install-sh ltmain.sh depcomp &\n        missing ar-lib\nOTHERFILES= jconfig.txt ckconfig.c jmemdosa.asm libjpeg.map\nTESTFILES= testorig.jpg testimg.ppm testimg.bmp testimg.jpg testprog.jpg &\n        testimgp.jpg\nDISTFILES= $(DOCS) $(MKFILES) $(CONFIGFILES) $(SOURCES) $(INCLUDES) &\n        $(CONFIGUREFILES) $(OTHERFILES) $(TESTFILES)\n# library object files common to compression and decompression\nCOMOBJECTS= jaricom.obj jcomapi.obj jutils.obj jerror.obj jmemmgr.obj $(SYSDEPMEM)\n# compression library object files\nCLIBOBJECTS= jcapimin.obj jcapistd.obj jcarith.obj jctrans.obj jcparam.obj &\n        jdatadst.obj jcinit.obj jcmaster.obj jcmarker.obj jcmainct.obj &\n        jcprepct.obj jccoefct.obj jccolor.obj jcsample.obj jchuff.obj &\n        jcdctmgr.obj jfdctfst.obj jfdctflt.obj jfdctint.obj\n# decompression library object files\nDLIBOBJECTS= jdapimin.obj jdapistd.obj jdarith.obj jdtrans.obj jdatasrc.obj &\n        jdmaster.obj jdinput.obj jdmarker.obj jdhuff.obj jdmainct.obj &\n        jdcoefct.obj jdpostct.obj jddctmgr.obj jidctfst.obj jidctflt.obj &\n        jidctint.obj jdsample.obj jdcolor.obj jquant1.obj jquant2.obj &\n        jdmerge.obj\n# These objectfiles are included in libjpeg.lib\nLIBOBJECTS= $(CLIBOBJECTS) $(DLIBOBJECTS) $(COMOBJECTS)\n# object files for sample applications (excluding library files)\nCOBJECTS= cjpeg.obj rdppm.obj rdgif.obj rdtarga.obj rdrle.obj rdbmp.obj &\n        rdswitch.obj cdjpeg.obj\nDOBJECTS= djpeg.obj wrppm.obj wrgif.obj wrtarga.obj wrrle.obj wrbmp.obj &\n        rdcolmap.obj cdjpeg.obj\nTROBJECTS= jpegtran.obj rdswitch.obj cdjpeg.obj transupp.obj\n\n\nall: libjpeg.lib cjpeg.exe djpeg.exe jpegtran.exe rdjpgcom.exe wrjpgcom.exe\n\nlibjpeg.lib: $(LIBOBJECTS)\n\t- del libjpeg.lib\n\t* wlib -n libjpeg.lib $(LIBOBJECTS)\n\ncjpeg.exe: $(COBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) $(COBJECTS) libjpeg.lib\n\ndjpeg.exe: $(DOBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) $(DOBJECTS) libjpeg.lib\n\njpegtran.exe: $(TROBJECTS) libjpeg.lib\n\t$(CC) $(LDFLAGS) $(TROBJECTS) libjpeg.lib\n\nrdjpgcom.exe: rdjpgcom.c\n\t$(CC) $(CFLAGS) $(LDFLAGS) rdjpgcom.c\n\nwrjpgcom.exe: wrjpgcom.c\n\t$(CC) $(CFLAGS) $(LDFLAGS) wrjpgcom.c\n\n.c.obj:\n\t$(CC) $(CFLAGS) -c $<\n\njconfig.h: jconfig.txt\n\techo You must prepare a system-dependent jconfig.h file.\n\techo Please read the installation directions in install.txt.\n\texit 1\n\nclean: .SYMBOLIC\n\t- del *.obj\n\t- del libjpeg.lib\n\t- del cjpeg.exe\n\t- del djpeg.exe\n\t- del jpegtran.exe\n\t- del rdjpgcom.exe\n\t- del wrjpgcom.exe\n\t- del testout*.*\n\ntest: cjpeg.exe djpeg.exe jpegtran.exe  .SYMBOLIC\n\t- del testout*.*\n\tdjpeg -dct int -ppm -outfile testout.ppm  testorig.jpg\n\tdjpeg -dct int -bmp -colors 256 -outfile testout.bmp  testorig.jpg\n\tcjpeg -dct int -outfile testout.jpg  testimg.ppm\n\tdjpeg -dct int -ppm -outfile testoutp.ppm testprog.jpg\n\tcjpeg -dct int -progressive -opt -outfile testoutp.jpg testimg.ppm\n\tjpegtran -outfile testoutt.jpg testprog.jpg\n!ifeq SYSTEM DOS\n\tfc /b testimg.ppm testout.ppm\n\tfc /b testimg.bmp testout.bmp\n\tfc /b testimg.jpg testout.jpg\n\tfc /b testimg.ppm testoutp.ppm\n\tfc /b testimgp.jpg testoutp.jpg\n\tfc /b testorig.jpg testoutt.jpg\n!else\n\techo n > n.tmp\n\tcomp testimg.ppm testout.ppm < n.tmp\n\tcomp testimg.bmp testout.bmp < n.tmp\n\tcomp testimg.jpg testout.jpg < n.tmp\n\tcomp testimg.ppm testoutp.ppm < n.tmp\n\tcomp testimgp.jpg testoutp.jpg < n.tmp\n\tcomp testorig.jpg testoutt.jpg < n.tmp\n\tdel n.tmp\n!endif\n\n\njaricom.obj: jaricom.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapimin.obj: jcapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcapistd.obj: jcapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcarith.obj: jcarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccoefct.obj: jccoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njccolor.obj: jccolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcdctmgr.obj: jcdctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njchuff.obj: jchuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcinit.obj: jcinit.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmainct.obj: jcmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmarker.obj: jcmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcmaster.obj: jcmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcomapi.obj: jcomapi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcparam.obj: jcparam.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcprepct.obj: jcprepct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njcsample.obj: jcsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njctrans.obj: jctrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapimin.obj: jdapimin.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdapistd.obj: jdapistd.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdarith.obj: jdarith.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdatadst.obj: jdatadst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdatasrc.obj: jdatasrc.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h\njdcoefct.obj: jdcoefct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdcolor.obj: jdcolor.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njddctmgr.obj: jddctmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njdhuff.obj: jdhuff.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdinput.obj: jdinput.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmainct.obj: jdmainct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmarker.obj: jdmarker.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmaster.obj: jdmaster.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdmerge.obj: jdmerge.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdpostct.obj: jdpostct.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdsample.obj: jdsample.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njdtrans.obj: jdtrans.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njerror.obj: jerror.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jversion.h jerror.h\njfdctflt.obj: jfdctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctfst.obj: jfdctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njfdctint.obj: jfdctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctflt.obj: jidctflt.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctfst.obj: jidctfst.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njidctint.obj: jidctint.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jdct.h\njquant1.obj: jquant1.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njquant2.obj: jquant2.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njutils.obj: jutils.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h\njmemmgr.obj: jmemmgr.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemansi.obj: jmemansi.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemname.obj: jmemname.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemnobs.obj: jmemnobs.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemdos.obj: jmemdos.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\njmemmac.obj: jmemmac.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h jmemsys.h\ncjpeg.obj: cjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\ndjpeg.obj: djpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h jversion.h\njpegtran.obj: jpegtran.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h transupp.h jversion.h\nrdjpgcom.obj: rdjpgcom.c jinclude.h jconfig.h\nwrjpgcom.obj: wrjpgcom.c jinclude.h jconfig.h\ncdjpeg.obj: cdjpeg.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdcolmap.obj: rdcolmap.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdswitch.obj: rdswitch.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\ntransupp.obj: transupp.c jinclude.h jconfig.h jpeglib.h jmorecfg.h jpegint.h jerror.h transupp.h\nrdppm.obj: rdppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrppm.obj: wrppm.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdgif.obj: rdgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrgif.obj: wrgif.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdtarga.obj: rdtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrtarga.obj: wrtarga.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdbmp.obj: rdbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrbmp.obj: wrbmp.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nrdrle.obj: rdrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\nwrrle.obj: wrrle.c cdjpeg.h jinclude.h jconfig.h jpeglib.h jmorecfg.h jerror.h cderror.h\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejdep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von jpeg.mak\n\n.\\jaricom.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcapimin.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcapistd.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcarith.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jccoefct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jccolor.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcdctmgr.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jchuff.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcinit.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcmainct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcmarker.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcmaster.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcomapi.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcparam.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcprepct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jcsample.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jctrans.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdapimin.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdapistd.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdarith.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdatadst.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdatasrc.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdcoefct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdcolor.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jddctmgr.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdhuff.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdinput.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdmainct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdmarker.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdmaster.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdmerge.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdpostct.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdsample.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jdtrans.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jerror.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\".\\jversion.h\"\\\n\t\n\n.\\jfdctflt.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jfdctfst.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jfdctint.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jidctflt.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jidctfst.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jidctint.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jdct.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jmemmgr.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmemsys.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jmemnobs.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmemsys.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jquant1.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jquant2.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jutils.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejdsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"jpeg\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Static Library\" 0x0104\n\nCFG=jpeg - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"jpeg.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"jpeg.mak\" CFG=\"jpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"jpeg - Win32\" (basierend auf  \"Win32 (x86) Static Library\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\Release\"\n# PROP BASE Intermediate_Dir \".\\Release\"\n# PROP BASE Target_Dir \"\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\Release\"\n# PROP Intermediate_Dir \".\\Release\"\n# PROP Target_Dir \"\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /YX /FD /c\n# ADD BASE RSC /l 0x407\n# ADD RSC /l 0x407\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLIB32=link.exe -lib\n# ADD BASE LIB32 /nologo\n# ADD LIB32 /nologo\n# Begin Target\n\n# Name \"jpeg - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\jaricom.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcapimin.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcapistd.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcarith.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jccoefct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jccolor.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcdctmgr.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jchuff.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcinit.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcmainct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcmarker.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcmaster.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcomapi.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcparam.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcprepct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jcsample.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jctrans.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdapimin.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdapistd.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdarith.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdatadst.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdatasrc.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdcoefct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdcolor.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jddctmgr.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdhuff.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdinput.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdmainct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdmarker.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdmaster.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdmerge.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdpostct.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdsample.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdtrans.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jerror.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jfdctflt.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jfdctfst.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jfdctint.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jidctflt.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jidctfst.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jidctint.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmemmgr.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmemnobs.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jquant1.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jquant2.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jutils.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jdct.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jerror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmemsys.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmorecfg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpegint.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpeglib.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jversion.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejdsw.vc6",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\n# WARNUNG: DIESE ARBEITSBEREICHSDATEI DARF NICHT BEARBEITET ODER GELSCHT WERDEN!\n\n###############################################################################\n\nProject: \"jpeg\"=\".\\jpeg.dsp\" - Package Owner=<4>\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<4>\n{{{\n}}}\n\n###############################################################################\n\nGlobal:\n\nPackage=<5>\n{{{\n}}}\n\nPackage=<3>\n{{{\n}}}\n\n###############################################################################\n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jdct.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jerror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jmemsys.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jmorecfg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpegint.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpeglib.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jversion.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"jaricom.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcapimin.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcapistd.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcarith.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jccoefct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jccolor.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcdctmgr.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jchuff.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcinit.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcmainct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcmarker.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcmaster.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcomapi.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcparam.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcprepct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jcsample.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jctrans.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdapimin.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdapistd.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdarith.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdatadst.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdatasrc.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdcoefct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdcolor.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jddctmgr.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdhuff.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdinput.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdmainct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdmarker.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdmaster.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdmerge.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdpostct.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdsample.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jdtrans.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jerror.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jfdctflt.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jfdctfst.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jfdctint.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jidctflt.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jidctfst.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jidctint.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jmemmgr.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jmemnobs.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jquant1.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jquant2.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jutils.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makejmak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on jpeg.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=jpeg - Win32\n!MESSAGE Keine Konfiguration angegeben. jpeg - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"jpeg - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"jpeg.mak\" CFG=\"jpeg - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"jpeg - Win32\" (basierend auf  \"Win32 (x86) Static Library\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nOUTDIR=.\\Release\nINTDIR=.\\Release\n# Begin Custom Macros\nOutDir=.\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\jpeg.lib\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\jaricom.obj\"\n\t-@erase \"$(INTDIR)\\jcapimin.obj\"\n\t-@erase \"$(INTDIR)\\jcapistd.obj\"\n\t-@erase \"$(INTDIR)\\jcarith.obj\"\n\t-@erase \"$(INTDIR)\\jccoefct.obj\"\n\t-@erase \"$(INTDIR)\\jccolor.obj\"\n\t-@erase \"$(INTDIR)\\jcdctmgr.obj\"\n\t-@erase \"$(INTDIR)\\jchuff.obj\"\n\t-@erase \"$(INTDIR)\\jcinit.obj\"\n\t-@erase \"$(INTDIR)\\jcmainct.obj\"\n\t-@erase \"$(INTDIR)\\jcmarker.obj\"\n\t-@erase \"$(INTDIR)\\jcmaster.obj\"\n\t-@erase \"$(INTDIR)\\jcomapi.obj\"\n\t-@erase \"$(INTDIR)\\jcparam.obj\"\n\t-@erase \"$(INTDIR)\\jcprepct.obj\"\n\t-@erase \"$(INTDIR)\\jcsample.obj\"\n\t-@erase \"$(INTDIR)\\jctrans.obj\"\n\t-@erase \"$(INTDIR)\\jdapimin.obj\"\n\t-@erase \"$(INTDIR)\\jdapistd.obj\"\n\t-@erase \"$(INTDIR)\\jdarith.obj\"\n\t-@erase \"$(INTDIR)\\jdatadst.obj\"\n\t-@erase \"$(INTDIR)\\jdatasrc.obj\"\n\t-@erase \"$(INTDIR)\\jdcoefct.obj\"\n\t-@erase \"$(INTDIR)\\jdcolor.obj\"\n\t-@erase \"$(INTDIR)\\jddctmgr.obj\"\n\t-@erase \"$(INTDIR)\\jdhuff.obj\"\n\t-@erase \"$(INTDIR)\\jdinput.obj\"\n\t-@erase \"$(INTDIR)\\jdmainct.obj\"\n\t-@erase \"$(INTDIR)\\jdmarker.obj\"\n\t-@erase \"$(INTDIR)\\jdmaster.obj\"\n\t-@erase \"$(INTDIR)\\jdmerge.obj\"\n\t-@erase \"$(INTDIR)\\jdpostct.obj\"\n\t-@erase \"$(INTDIR)\\jdsample.obj\"\n\t-@erase \"$(INTDIR)\\jdtrans.obj\"\n\t-@erase \"$(INTDIR)\\jerror.obj\"\n\t-@erase \"$(INTDIR)\\jfdctflt.obj\"\n\t-@erase \"$(INTDIR)\\jfdctfst.obj\"\n\t-@erase \"$(INTDIR)\\jfdctint.obj\"\n\t-@erase \"$(INTDIR)\\jidctflt.obj\"\n\t-@erase \"$(INTDIR)\\jidctfst.obj\"\n\t-@erase \"$(INTDIR)\\jidctint.obj\"\n\t-@erase \"$(INTDIR)\\jmemmgr.obj\"\n\t-@erase \"$(INTDIR)\\jmemnobs.obj\"\n\t-@erase \"$(INTDIR)\\jquant1.obj\"\n\t-@erase \"$(INTDIR)\\jquant2.obj\"\n\t-@erase \"$(INTDIR)\\jutils.obj\"\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(OUTDIR)\\jpeg.lib\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nCPP=cl.exe\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_WINDOWS\" /Fp\"$(INTDIR)\\jpeg.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\nRSC=rc.exe\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\jpeg.bsc\" \nBSC32_SBRS= \\\n\t\nLIB32=link.exe -lib\nLIB32_FLAGS=/nologo /out:\"$(OUTDIR)\\jpeg.lib\" \nLIB32_OBJS= \\\n\t\"$(INTDIR)\\jaricom.obj\" \\\n\t\"$(INTDIR)\\jcapimin.obj\" \\\n\t\"$(INTDIR)\\jcapistd.obj\" \\\n\t\"$(INTDIR)\\jcarith.obj\" \\\n\t\"$(INTDIR)\\jccoefct.obj\" \\\n\t\"$(INTDIR)\\jccolor.obj\" \\\n\t\"$(INTDIR)\\jcdctmgr.obj\" \\\n\t\"$(INTDIR)\\jchuff.obj\" \\\n\t\"$(INTDIR)\\jcinit.obj\" \\\n\t\"$(INTDIR)\\jcmainct.obj\" \\\n\t\"$(INTDIR)\\jcmarker.obj\" \\\n\t\"$(INTDIR)\\jcmaster.obj\" \\\n\t\"$(INTDIR)\\jcomapi.obj\" \\\n\t\"$(INTDIR)\\jcparam.obj\" \\\n\t\"$(INTDIR)\\jcprepct.obj\" \\\n\t\"$(INTDIR)\\jcsample.obj\" \\\n\t\"$(INTDIR)\\jctrans.obj\" \\\n\t\"$(INTDIR)\\jdapimin.obj\" \\\n\t\"$(INTDIR)\\jdapistd.obj\" \\\n\t\"$(INTDIR)\\jdarith.obj\" \\\n\t\"$(INTDIR)\\jdatadst.obj\" \\\n\t\"$(INTDIR)\\jdatasrc.obj\" \\\n\t\"$(INTDIR)\\jdcoefct.obj\" \\\n\t\"$(INTDIR)\\jdcolor.obj\" \\\n\t\"$(INTDIR)\\jddctmgr.obj\" \\\n\t\"$(INTDIR)\\jdhuff.obj\" \\\n\t\"$(INTDIR)\\jdinput.obj\" \\\n\t\"$(INTDIR)\\jdmainct.obj\" \\\n\t\"$(INTDIR)\\jdmarker.obj\" \\\n\t\"$(INTDIR)\\jdmaster.obj\" \\\n\t\"$(INTDIR)\\jdmerge.obj\" \\\n\t\"$(INTDIR)\\jdpostct.obj\" \\\n\t\"$(INTDIR)\\jdsample.obj\" \\\n\t\"$(INTDIR)\\jdtrans.obj\" \\\n\t\"$(INTDIR)\\jerror.obj\" \\\n\t\"$(INTDIR)\\jfdctflt.obj\" \\\n\t\"$(INTDIR)\\jfdctfst.obj\" \\\n\t\"$(INTDIR)\\jfdctint.obj\" \\\n\t\"$(INTDIR)\\jidctflt.obj\" \\\n\t\"$(INTDIR)\\jidctfst.obj\" \\\n\t\"$(INTDIR)\\jidctint.obj\" \\\n\t\"$(INTDIR)\\jmemmgr.obj\" \\\n\t\"$(INTDIR)\\jmemnobs.obj\" \\\n\t\"$(INTDIR)\\jquant1.obj\" \\\n\t\"$(INTDIR)\\jquant2.obj\" \\\n\t\"$(INTDIR)\\jutils.obj\"\n\n\"$(OUTDIR)\\jpeg.lib\" : \"$(OUTDIR)\" $(DEF_FILE) $(LIB32_OBJS)\n    $(LIB32) @<<\n  $(LIB32_FLAGS) $(DEF_FLAGS) $(LIB32_OBJS)\n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"jpeg.dep\")\n!INCLUDE \"jpeg.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"jpeg.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"jpeg - Win32\"\nSOURCE=.\\jaricom.c\n\n\"$(INTDIR)\\jaricom.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcapimin.c\n\n\"$(INTDIR)\\jcapimin.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcapistd.c\n\n\"$(INTDIR)\\jcapistd.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcarith.c\n\n\"$(INTDIR)\\jcarith.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jccoefct.c\n\n\"$(INTDIR)\\jccoefct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jccolor.c\n\n\"$(INTDIR)\\jccolor.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcdctmgr.c\n\n\"$(INTDIR)\\jcdctmgr.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jchuff.c\n\n\"$(INTDIR)\\jchuff.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcinit.c\n\n\"$(INTDIR)\\jcinit.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcmainct.c\n\n\"$(INTDIR)\\jcmainct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcmarker.c\n\n\"$(INTDIR)\\jcmarker.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcmaster.c\n\n\"$(INTDIR)\\jcmaster.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcomapi.c\n\n\"$(INTDIR)\\jcomapi.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcparam.c\n\n\"$(INTDIR)\\jcparam.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcprepct.c\n\n\"$(INTDIR)\\jcprepct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jcsample.c\n\n\"$(INTDIR)\\jcsample.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jctrans.c\n\n\"$(INTDIR)\\jctrans.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdapimin.c\n\n\"$(INTDIR)\\jdapimin.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdapistd.c\n\n\"$(INTDIR)\\jdapistd.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdarith.c\n\n\"$(INTDIR)\\jdarith.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdatadst.c\n\n\"$(INTDIR)\\jdatadst.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdatasrc.c\n\n\"$(INTDIR)\\jdatasrc.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdcoefct.c\n\n\"$(INTDIR)\\jdcoefct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdcolor.c\n\n\"$(INTDIR)\\jdcolor.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jddctmgr.c\n\n\"$(INTDIR)\\jddctmgr.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdhuff.c\n\n\"$(INTDIR)\\jdhuff.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdinput.c\n\n\"$(INTDIR)\\jdinput.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdmainct.c\n\n\"$(INTDIR)\\jdmainct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdmarker.c\n\n\"$(INTDIR)\\jdmarker.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdmaster.c\n\n\"$(INTDIR)\\jdmaster.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdmerge.c\n\n\"$(INTDIR)\\jdmerge.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdpostct.c\n\n\"$(INTDIR)\\jdpostct.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdsample.c\n\n\"$(INTDIR)\\jdsample.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jdtrans.c\n\n\"$(INTDIR)\\jdtrans.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jerror.c\n\n\"$(INTDIR)\\jerror.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jfdctflt.c\n\n\"$(INTDIR)\\jfdctflt.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jfdctfst.c\n\n\"$(INTDIR)\\jfdctfst.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jfdctint.c\n\n\"$(INTDIR)\\jfdctint.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jidctflt.c\n\n\"$(INTDIR)\\jidctflt.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jidctfst.c\n\n\"$(INTDIR)\\jidctfst.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jidctint.c\n\n\"$(INTDIR)\\jidctint.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jmemmgr.c\n\n\"$(INTDIR)\\jmemmgr.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jmemnobs.c\n\n\"$(INTDIR)\\jmemnobs.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jquant1.c\n\n\"$(INTDIR)\\jquant1.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jquant2.c\n\n\"$(INTDIR)\\jquant2.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jutils.c\n\n\"$(INTDIR)\\jutils.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejsln.v10",
    "content": "\nMicrosoft Visual Studio Solution File, Format Version 11.00\n# Visual C++ Express 2010\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"jpeg\", \"jpeg.vcxproj\", \"{019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}\"\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tRelease|Win32 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}.Release|Win32.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makejvcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jdct.h\" />\n    <ClInclude Include=\"jerror.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n    <ClInclude Include=\"jmemsys.h\" />\n    <ClInclude Include=\"jmorecfg.h\" />\n    <ClInclude Include=\"jpegint.h\" />\n    <ClInclude Include=\"jpeglib.h\" />\n    <ClInclude Include=\"jversion.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"jaricom.c\" />\n    <ClCompile Include=\"jcapimin.c\" />\n    <ClCompile Include=\"jcapistd.c\" />\n    <ClCompile Include=\"jcarith.c\" />\n    <ClCompile Include=\"jccoefct.c\" />\n    <ClCompile Include=\"jccolor.c\" />\n    <ClCompile Include=\"jcdctmgr.c\" />\n    <ClCompile Include=\"jchuff.c\" />\n    <ClCompile Include=\"jcinit.c\" />\n    <ClCompile Include=\"jcmainct.c\" />\n    <ClCompile Include=\"jcmarker.c\" />\n    <ClCompile Include=\"jcmaster.c\" />\n    <ClCompile Include=\"jcomapi.c\" />\n    <ClCompile Include=\"jcparam.c\" />\n    <ClCompile Include=\"jcprepct.c\" />\n    <ClCompile Include=\"jcsample.c\" />\n    <ClCompile Include=\"jctrans.c\" />\n    <ClCompile Include=\"jdapimin.c\" />\n    <ClCompile Include=\"jdapistd.c\" />\n    <ClCompile Include=\"jdarith.c\" />\n    <ClCompile Include=\"jdatadst.c\" />\n    <ClCompile Include=\"jdatasrc.c\" />\n    <ClCompile Include=\"jdcoefct.c\" />\n    <ClCompile Include=\"jdcolor.c\" />\n    <ClCompile Include=\"jddctmgr.c\" />\n    <ClCompile Include=\"jdhuff.c\" />\n    <ClCompile Include=\"jdinput.c\" />\n    <ClCompile Include=\"jdmainct.c\" />\n    <ClCompile Include=\"jdmarker.c\" />\n    <ClCompile Include=\"jdmaster.c\" />\n    <ClCompile Include=\"jdmerge.c\" />\n    <ClCompile Include=\"jdpostct.c\" />\n    <ClCompile Include=\"jdsample.c\" />\n    <ClCompile Include=\"jdtrans.c\" />\n    <ClCompile Include=\"jerror.c\" />\n    <ClCompile Include=\"jfdctflt.c\" />\n    <ClCompile Include=\"jfdctfst.c\" />\n    <ClCompile Include=\"jfdctint.c\" />\n    <ClCompile Include=\"jidctflt.c\" />\n    <ClCompile Include=\"jidctfst.c\" />\n    <ClCompile Include=\"jidctint.c\" />\n    <ClCompile Include=\"jmemmgr.c\" />\n    <ClCompile Include=\"jmemnobs.c\" />\n    <ClCompile Include=\"jquant1.c\" />\n    <ClCompile Include=\"jquant2.c\">\n      <Optimization Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">Disabled</Optimization>\n      <BufferSecurityCheck Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">false</BufferSecurityCheck>\n    </ClCompile>\n    <ClCompile Include=\"jutils.c\" />\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{019DBD2A-273D-4BA4-BF86-B5EFE2ED76B1}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>jpeg</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup />\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_LIB;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makeproj.mac",
    "content": "--\n-- makeproj.mac\n--\n-- This AppleScript builds Code Warrior PRO Release 2 project files for the\n-- libjpeg library as well as the test programs 'cjpeg', 'djpeg', 'jpegtran'.\n-- (We'd distribute real project files, except they're not text\n-- and would create maintenance headaches.)\n--\n-- The script then compiles and links the library and the test programs.\n-- NOTE: if you haven't already created a 'jconfig.h' file, the script\n-- automatically copies 'jconfig.mac' to 'jconfig.h'.\n--\n-- To use this script, you must have AppleScript 1.1 or later installed\n-- and a suitable AppleScript editor like Script Editor or Script Debugger\n-- (http://www.latenightsw.com). Open this file with your AppleScript\n-- editor and execute the \"run\" command to build the projects.\n--\n-- Thanks to Dan Sears and Don Agro for this script.\n-- Questions about this script can be addressed to dogpark@interlog.com\n--\n\non run\n\n\tchoose folder with prompt \">>> Select IJG source folder <<<\"\n\tset ijg_folder to result\n\n\tchoose folder with prompt \">>> Select MetroWerks folder <<<\"\n\tset cw_folder to result\n\n\t-- if jconfig.h doesn't already exist, copy jconfig.mac\n\n\ttell application \"Finder\"\n\t\tif not (exists file \"jconfig.h\" of ijg_folder) then\n\t\t\tduplicate {file \"jconfig.mac\" of folder ijg_folder}\n\t\t\tselect file \"jconfig.mac copy\" of folder ijg_folder\n\t\t\tset name of selection to \"jconfig.h\"\n\t\tend if\n\tend tell\n\n\ttell application \"CodeWarrior IDE 2.1\"\n\t  with timeout of 10000 seconds\n\n\t\t-- create libjpeg project\n\n\t\tactivate\n\t\tCreate Project (ijg_folder as string) & \"libjpeg.proj\"\n\t\tSet Preferences of panel \"Target Settings\" to {Target Name:\"libjpeg\"}\n\t\tSet Preferences of panel \"PPC Project\" to {File Name:\"libjpeg\"}\n\t\tSet Preferences of panel \"Target Settings\" to {Linker:\"MacOS PPC Linker\"}\n\t\tSet Preferences of panel \"PPC Project\" to {Project Type:library}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {ANSI Strict:true}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {Enums Always Ints:true}\n\t\tSet Preferences of panel \"PPC Codegen\" to {Struct Alignment:PowerPC}\n\t\tSet Preferences of panel \"PPC Linker\" to {Generate SYM File:false}\n\n\t\tAdd Files (ijg_folder as string) & \"jaricom.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcapimin.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcapistd.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcarith.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jctrans.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcparam.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdatadst.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcinit.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcmaster.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcmarker.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcmainct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcprepct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jccoefct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jccolor.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcsample.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jchuff.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcdctmgr.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jfdctfst.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jfdctflt.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jfdctint.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdapimin.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdapistd.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdarith.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdtrans.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdatasrc.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdmaster.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdinput.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdmarker.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdhuff.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdmainct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdcoefct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdpostct.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jddctmgr.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jidctfst.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jidctflt.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jidctint.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdsample.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdcolor.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jquant1.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jquant2.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jdmerge.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jcomapi.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jutils.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jerror.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jmemmgr.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"jmemmac.c\" To Segment 1\n\n\t\t-- compile and link the library\n\n\t\tMake Project\n\t\tClose Project\n\n\t\t-- create cjpeg project\n\n\t\tactivate\n\t\tCreate Project (ijg_folder as string) & \"cjpeg.proj\"\n\t\tSet Preferences of panel \"Target Settings\" to {Target Name:\"cjpeg\"}\n\t\tSet Preferences of panel \"PPC Project\" to {File Name:\"cjpeg\"}\n\t\tSet Preferences of panel \"Target Settings\" to {Linker:\"MacOS PPC Linker\"}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {ANSI Strict:true}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {Enums Always Ints:true}\n\t\tSet Preferences of panel \"PPC Codegen\" to {Struct Alignment:PowerPC}\n\t\tSet Preferences of panel \"PPC Linker\" to {Generate SYM File:false}\n\n\t\tAdd Files (ijg_folder as string) & \"cjpeg.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdppm.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdgif.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdtarga.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdrle.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdbmp.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdswitch.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"cdjpeg.c\" To Segment 1\n\n\t\tAdd Files (ijg_folder as string) & \"libjpeg\" To Segment 2\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib\" To Segment 3\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib\" To Segment 4\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib\" To Segment 4\n\n\t\t-- compile and link cjpeg\n\n\t\tMake Project\n\t\tClose Project\n\n\t\t-- create djpeg project\n\n\t\tactivate\n\t\tCreate Project (ijg_folder as string) & \"djpeg.proj\"\n\t\tSet Preferences of panel \"Target Settings\" to {Target Name:\"djpeg\"}\n\t\tSet Preferences of panel \"PPC Project\" to {File Name:\"djpeg\"}\n\t\tSet Preferences of panel \"Target Settings\" to {Linker:\"MacOS PPC Linker\"}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {ANSI Strict:true}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {Enums Always Ints:true}\n\t\tSet Preferences of panel \"PPC Codegen\" to {Struct Alignment:PowerPC}\n\t\tSet Preferences of panel \"PPC Linker\" to {Generate SYM File:false}\n\n\t\tAdd Files (ijg_folder as string) & \"djpeg.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"wrppm.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"wrgif.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"wrtarga.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"wrrle.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"wrbmp.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdcolmap.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"cdjpeg.c\" To Segment 1\n\n\t\tAdd Files (ijg_folder as string) & \"libjpeg\" To Segment 2\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib\" To Segment 3\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib\" To Segment 4\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib\" To Segment 4\n\n\t\t-- compile and link djpeg\n\n\t\tMake Project\n\t\tClose Project\n\n\t\t-- create jpegtran project\n\n\t\tactivate\n\t\tCreate Project (ijg_folder as string) & \"jpegtran.proj\"\n\t\tSet Preferences of panel \"Target Settings\" to {Target Name:\"jpegtran\"}\n\t\tSet Preferences of panel \"PPC Project\" to {File Name:\"jpegtran\"}\n\t\tSet Preferences of panel \"Target Settings\" to {Linker:\"MacOS PPC Linker\"}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {ANSI Strict:true}\n\t\tSet Preferences of panel \"C/C++ Compiler\" to {Enums Always Ints:true}\n\t\tSet Preferences of panel \"PPC Codegen\" to {Struct Alignment:PowerPC}\n\t\tSet Preferences of panel \"PPC Linker\" to {Generate SYM File:false}\n\n\t\tAdd Files (ijg_folder as string) & \"jpegtran.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"rdswitch.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"cdjpeg.c\" To Segment 1\n\t\tAdd Files (ijg_folder as string) & \"transupp.c\" To Segment 1\n\n\t\tAdd Files (ijg_folder as string) & \"libjpeg\" To Segment 2\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL C.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:Metrowerks Standard Library:MSL C:Bin:MSL SIOUX.PPC.Lib\" To Segment 3\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:Runtime:Runtime PPC:MSL RuntimePPC.Lib\" To Segment 3\n\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:InterfaceLib\" To Segment 4\n\t\tAdd Files (cw_folder as string) & \"Metrowerks CodeWarrior:MacOS Support:Libraries:MacOS Common:MathLib\" To Segment 4\n\n\t\t-- compile and link jpegtran\n\n\t\tMake Project\n\t\tClose Project\n\n\t\tquit\n\n\t  end timeout\n\tend tell\nend run\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makerdep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von rdjpgcom.mak\n\n.\\rdjpgcom.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jinclude.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makerdsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"rdjpgcom\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=rdjpgcom - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"rdjpgcom.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"rdjpgcom.mak\" CFG=\"rdjpgcom - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"rdjpgcom - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\rdjpgcom\\Release\"\n# PROP BASE Intermediate_Dir \".\\rdjpgcom\\Release\"\n# PROP BASE Target_Dir \".\\rdjpgcom\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\rdjpgcom\\Release\"\n# PROP Intermediate_Dir \".\\rdjpgcom\\Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \".\\rdjpgcom\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /FD /c\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\n# ADD RSC /l 0x409 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# Begin Target\n\n# Name \"rdjpgcom - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\rdjpgcom.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makerfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"rdjpgcom.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makermak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on rdjpgcom.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=rdjpgcom - Win32\n!MESSAGE Keine Konfiguration angegeben. rdjpgcom - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"rdjpgcom - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"rdjpgcom.mak\" CFG=\"rdjpgcom - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"rdjpgcom - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nCPP=cl.exe\nRSC=rc.exe\nOUTDIR=.\\rdjpgcom\\Release\nINTDIR=.\\rdjpgcom\\Release\n# Begin Custom Macros\nOutDir=.\\rdjpgcom\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\rdjpgcom.exe\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\rdjpgcom.obj\"\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(OUTDIR)\\rdjpgcom.exe\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\rdjpgcom.bsc\" \nBSC32_SBRS= \\\n\t\nLINK32=link.exe\nLINK32_FLAGS=Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:\"$(OUTDIR)\\rdjpgcom.pdb\" /machine:I386 /out:\"$(OUTDIR)\\rdjpgcom.exe\" \nLINK32_OBJS= \\\n\t\"$(INTDIR)\\rdjpgcom.obj\"\n\n\"$(OUTDIR)\\rdjpgcom.exe\" : \"$(OUTDIR)\" $(DEF_FILE) $(LINK32_OBJS)\n    $(LINK32) @<<\n  $(LINK32_FLAGS) $(LINK32_OBJS)\n<<\n\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /Fp\"$(INTDIR)\\rdjpgcom.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"rdjpgcom.dep\")\n!INCLUDE \"rdjpgcom.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"rdjpgcom.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"rdjpgcom - Win32\"\nSOURCE=.\\rdjpgcom.c\n\n\"$(INTDIR)\\rdjpgcom.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makervcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{C81513DB-78DC-46BC-BC98-82E745203976}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>rdjpgcom</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <OutDir>$(ProjectName)\\$(Configuration)\\</OutDir>\n    <IntDir>$(ProjectName)\\$(Configuration)\\</IntDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n      <DisableSpecificWarnings>4996</DisableSpecificWarnings>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"rdjpgcom.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/maketdep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von jpegtran.mak\n\n.\\cdjpeg.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\jpegtran.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\".\\jversion.h\"\\\n\t\".\\transupp.h\"\\\n\t\n\n.\\rdswitch.c : \\\n\t\".\\cderror.h\"\\\n\t\".\\cdjpeg.h\"\\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\n\n.\\transupp.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jerror.h\"\\\n\t\".\\jinclude.h\"\\\n\t\".\\jmorecfg.h\"\\\n\t\".\\jpegint.h\"\\\n\t\".\\jpeglib.h\"\\\n\t\".\\transupp.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/maketdsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"jpegtran\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=jpegtran - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"jpegtran.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"jpegtran.mak\" CFG=\"jpegtran - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"jpegtran - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\jpegtran\\Release\"\n# PROP BASE Intermediate_Dir \".\\jpegtran\\Release\"\n# PROP BASE Target_Dir \".\\jpegtran\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\jpegtran\\Release\"\n# PROP Intermediate_Dir \".\\jpegtran\\Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \".\\jpegtran\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /FD /c\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\n# ADD RSC /l 0x409 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# Begin Target\n\n# Name \"jpegtran - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\cdjpeg.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpegtran.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\rdswitch.c\n# End Source File\n# Begin Source File\n\nSOURCE=.\\transupp.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\cderror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\cdjpeg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jerror.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jmorecfg.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpegint.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jpeglib.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jversion.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\transupp.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/maketfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"cdjpeg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jerror.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jmorecfg.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpegint.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jpeglib.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jversion.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"transupp.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"jpegtran.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"rdswitch.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n    <ClCompile Include=\"transupp.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/maketmak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on jpegtran.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=jpegtran - Win32\n!MESSAGE Keine Konfiguration angegeben. jpegtran - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"jpegtran - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"jpegtran.mak\" CFG=\"jpegtran - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"jpegtran - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nCPP=cl.exe\nRSC=rc.exe\nOUTDIR=.\\jpegtran\\Release\nINTDIR=.\\jpegtran\\Release\n# Begin Custom Macros\nOutDir=.\\jpegtran\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\jpegtran.exe\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\cdjpeg.obj\"\n\t-@erase \"$(INTDIR)\\jpegtran.obj\"\n\t-@erase \"$(INTDIR)\\rdswitch.obj\"\n\t-@erase \"$(INTDIR)\\transupp.obj\"\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(OUTDIR)\\jpegtran.exe\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\jpegtran.bsc\" \nBSC32_SBRS= \\\n\t\nLINK32=link.exe\nLINK32_FLAGS=Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:\"$(OUTDIR)\\jpegtran.pdb\" /machine:I386 /out:\"$(OUTDIR)\\jpegtran.exe\" \nLINK32_OBJS= \\\n\t\"$(INTDIR)\\cdjpeg.obj\" \\\n\t\"$(INTDIR)\\jpegtran.obj\" \\\n\t\"$(INTDIR)\\rdswitch.obj\" \\\n\t\"$(INTDIR)\\transupp.obj\"\n\n\"$(OUTDIR)\\jpegtran.exe\" : \"$(OUTDIR)\" $(DEF_FILE) $(LINK32_OBJS)\n    $(LINK32) @<<\n  $(LINK32_FLAGS) $(LINK32_OBJS)\n<<\n\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /Fp\"$(INTDIR)\\jpegtran.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"jpegtran.dep\")\n!INCLUDE \"jpegtran.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"jpegtran.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"jpegtran - Win32\"\nSOURCE=.\\cdjpeg.c\n\n\"$(INTDIR)\\cdjpeg.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\jpegtran.c\n\n\"$(INTDIR)\\jpegtran.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\rdswitch.c\n\n\"$(INTDIR)\\rdswitch.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\nSOURCE=.\\transupp.c\n\n\"$(INTDIR)\\transupp.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/maketvcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{025BAC50-51B5-4FFE-BC47-3F920BB4047E}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>jpegtran</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <OutDir>$(ProjectName)\\$(Configuration)\\</OutDir>\n    <IntDir>$(ProjectName)\\$(Configuration)\\</IntDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n      <DisableSpecificWarnings>4996</DisableSpecificWarnings>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>Release\\jpeg.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"cderror.h\" />\n    <ClInclude Include=\"cdjpeg.h\" />\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jerror.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n    <ClInclude Include=\"jmorecfg.h\" />\n    <ClInclude Include=\"jpegint.h\" />\n    <ClInclude Include=\"jpeglib.h\" />\n    <ClInclude Include=\"jversion.h\" />\n    <ClInclude Include=\"transupp.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"cdjpeg.c\" />\n    <ClCompile Include=\"jpegtran.c\" />\n    <ClCompile Include=\"rdswitch.c\" />\n    <ClCompile Include=\"transupp.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makewdep.vc6",
    "content": "# Microsoft Developer Studio erstellte Abhngigkeitsdatei, einbezogen von wrjpgcom.mak\n\n.\\wrjpgcom.c : \\\n\t\".\\jconfig.h\"\\\n\t\".\\jinclude.h\"\\\n\t\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makewdsp.vc6",
    "content": "# Microsoft Developer Studio Project File - Name=\"wrjpgcom\" - Package Owner=<4>\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\n# ** NICHT BEARBEITEN **\n\n# TARGTYPE \"Win32 (x86) Console Application\" 0x0103\n\nCFG=wrjpgcom - Win32\n!MESSAGE Dies ist kein gltiges Makefile. Zum Erstellen dieses Projekts mit NMAKE\n!MESSAGE verwenden Sie den Befehl \"Makefile exportieren\" und fhren Sie den Befehl\n!MESSAGE \n!MESSAGE NMAKE /f \"wrjpgcom.mak\".\n!MESSAGE \n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"wrjpgcom.mak\" CFG=\"wrjpgcom - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"wrjpgcom - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n\n# Begin Project\n# PROP AllowPerConfigDependencies 0\n# PROP Scc_ProjName \"\"\n# PROP Scc_LocalPath \"\"\nCPP=cl.exe\nRSC=rc.exe\n# PROP BASE Use_MFC 0\n# PROP BASE Use_Debug_Libraries 0\n# PROP BASE Output_Dir \".\\wrjpgcom\\Release\"\n# PROP BASE Intermediate_Dir \".\\wrjpgcom\\Release\"\n# PROP BASE Target_Dir \".\\wrjpgcom\"\n# PROP Use_MFC 0\n# PROP Use_Debug_Libraries 0\n# PROP Output_Dir \".\\wrjpgcom\\Release\"\n# PROP Intermediate_Dir \".\\wrjpgcom\\Release\"\n# PROP Ignore_Export_Lib 0\n# PROP Target_Dir \".\\wrjpgcom\"\n# ADD BASE CPP /nologo /W3 /GX /O2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /c\n# ADD CPP /nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /YX /FD /c\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\n# ADD RSC /l 0x409 /d \"NDEBUG\"\nBSC32=bscmake.exe\n# ADD BASE BSC32 /nologo\n# ADD BSC32 /nologo\nLINK32=link.exe\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# ADD LINK32 Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386\n# Begin Target\n\n# Name \"wrjpgcom - Win32\"\n# Begin Group \"Quellcodedateien\"\n\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat;for;f90\"\n# Begin Source File\n\nSOURCE=.\\wrjpgcom.c\n# End Source File\n# End Group\n# Begin Group \"Header-Dateien\"\n\n# PROP Default_Filter \"h;hpp;hxx;hm;inl;fi;fd\"\n# Begin Source File\n\nSOURCE=.\\jconfig.h\n# End Source File\n# Begin Source File\n\nSOURCE=.\\jinclude.h\n# End Source File\n# End Group\n# Begin Group \"Ressourcendateien\"\n\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;cnt;rtf;gif;jpg;jpeg;jpe\"\n# End Group\n# End Target\n# End Project\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makewfil.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup>\n    <Filter Include=\"Source Files\">\n      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>\n      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>\n    </Filter>\n    <Filter Include=\"Header Files\">\n      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>\n      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>\n    </Filter>\n    <Filter Include=\"Resource Files\">\n      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>\n      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>\n    </Filter>\n  </ItemGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n    <ClInclude Include=\"jinclude.h\">\n      <Filter>Header Files</Filter>\n    </ClInclude>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"wrjpgcom.c\">\n      <Filter>Source Files</Filter>\n    </ClCompile>\n  </ItemGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makewmak.vc6",
    "content": "# Microsoft Developer Studio Generated NMAKE File, Based on wrjpgcom.dsp\n!IF \"$(CFG)\" == \"\"\nCFG=wrjpgcom - Win32\n!MESSAGE Keine Konfiguration angegeben. wrjpgcom - Win32 wird als Standard verwendet.\n!ENDIF \n\n!IF \"$(CFG)\" != \"wrjpgcom - Win32\"\n!MESSAGE Ungltige Konfiguration \"$(CFG)\" angegeben.\n!MESSAGE Sie knnen beim Ausfhren von NMAKE eine Konfiguration angeben\n!MESSAGE durch Definieren des Makros CFG in der Befehlszeile. Zum Beispiel:\n!MESSAGE \n!MESSAGE NMAKE /f \"wrjpgcom.mak\" CFG=\"wrjpgcom - Win32\"\n!MESSAGE \n!MESSAGE Fr die Konfiguration stehen zur Auswahl:\n!MESSAGE \n!MESSAGE \"wrjpgcom - Win32\" (basierend auf  \"Win32 (x86) Console Application\")\n!MESSAGE \n!ERROR Eine ungltige Konfiguration wurde angegeben.\n!ENDIF \n\n!IF \"$(OS)\" == \"Windows_NT\"\nNULL=\n!ELSE \nNULL=nul\n!ENDIF \n\nCPP=cl.exe\nRSC=rc.exe\nOUTDIR=.\\wrjpgcom\\Release\nINTDIR=.\\wrjpgcom\\Release\n# Begin Custom Macros\nOutDir=.\\wrjpgcom\\Release\n# End Custom Macros\n\nALL : \"$(OUTDIR)\\wrjpgcom.exe\"\n\n\nCLEAN :\n\t-@erase \"$(INTDIR)\\vc60.idb\"\n\t-@erase \"$(INTDIR)\\wrjpgcom.obj\"\n\t-@erase \"$(OUTDIR)\\wrjpgcom.exe\"\n\n\"$(OUTDIR)\" :\n    if not exist \"$(OUTDIR)/$(NULL)\" mkdir \"$(OUTDIR)\"\n\nBSC32=bscmake.exe\nBSC32_FLAGS=/nologo /o\"$(OUTDIR)\\wrjpgcom.bsc\" \nBSC32_SBRS= \\\n\t\nLINK32=link.exe\nLINK32_FLAGS=Release\\jpeg.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /incremental:no /pdb:\"$(OUTDIR)\\wrjpgcom.pdb\" /machine:I386 /out:\"$(OUTDIR)\\wrjpgcom.exe\" \nLINK32_OBJS= \\\n\t\"$(INTDIR)\\wrjpgcom.obj\"\n\n\"$(OUTDIR)\\wrjpgcom.exe\" : \"$(OUTDIR)\" $(DEF_FILE) $(LINK32_OBJS)\n    $(LINK32) @<<\n  $(LINK32_FLAGS) $(LINK32_OBJS)\n<<\n\nCPP_PROJ=/nologo /G6 /MT /W3 /GX /Ox /Oa /Ob2 /D \"WIN32\" /D \"NDEBUG\" /D \"_CONSOLE\" /Fp\"$(INTDIR)\\wrjpgcom.pch\" /YX /Fo\"$(INTDIR)\\\\\" /Fd\"$(INTDIR)\\\\\" /FD /c \n\n.c{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.obj::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.c{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cpp{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n.cxx{$(INTDIR)}.sbr::\n   $(CPP) @<<\n   $(CPP_PROJ) $< \n<<\n\n\n!IF \"$(NO_EXTERNAL_DEPS)\" != \"1\"\n!IF EXISTS(\"wrjpgcom.dep\")\n!INCLUDE \"wrjpgcom.dep\"\n!ELSE \n!MESSAGE Warning: cannot find \"wrjpgcom.dep\"\n!ENDIF \n!ENDIF \n\n\n!IF \"$(CFG)\" == \"wrjpgcom - Win32\"\nSOURCE=.\\wrjpgcom.c\n\n\"$(INTDIR)\\wrjpgcom.obj\" : $(SOURCE) \"$(INTDIR)\"\n\n\n\n!ENDIF \n\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makewvcx.v10",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{B57065D4-DDDA-4668-BAF5-2D49270C973C}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>wrjpgcom</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <OutDir>$(ProjectName)\\$(Configuration)\\</OutDir>\n    <IntDir>$(ProjectName)\\$(Configuration)\\</IntDir>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>Level3</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>false</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS</PreprocessorDefinitions>\n      <OmitFramePointers>true</OmitFramePointers>\n      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>\n      <DisableSpecificWarnings>4996</DisableSpecificWarnings>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClInclude Include=\"jconfig.h\" />\n    <ClInclude Include=\"jinclude.h\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"wrjpgcom.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>"
  },
  {
    "path": "tess-two/jni/libjpeg/makljpeg.st",
    "content": "; Project file for Independent JPEG Group's software\n;\n; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.\n; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.\n;\n; To use this file, rename it to libjpeg.prj.\n; Read installation instructions before trying to make the program!\n;\n;\n;      * * * Output file * * *\nlibjpeg.lib\n;\n; * * * COMPILER OPTIONS * * *  \n.C[-P]        ; absolute calls\n.C[-M]        ; and no string merging, folks\n.C[-w-cln]    ; no \"constant is long\" warnings\n.C[-w-par]    ; no \"parameter xxxx unused\"\n.C[-w-rch]    ; no \"unreachable code\"\n.C[-wsig]     ; warn if significant digits may be lost\n.L[-J]        ; link new Obj-format (so we get a library)\n=\n; * * * * List of modules * * * * \njaricom.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcapimin.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcapistd.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcarith.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njccoefct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njccolor.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcdctmgr.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njchuff.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcinit.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcmainct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcmarker.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcmaster.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcomapi.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcparam.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcprepct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njcsample.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njctrans.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdapimin.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdapistd.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdarith.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdatadst.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)\njdatasrc.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h)\njdcoefct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdcolor.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njddctmgr.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njdhuff.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdinput.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdmainct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdmarker.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdmaster.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdmerge.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdpostct.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdsample.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njdtrans.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njerror.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jversion.h,jerror.h)\njfdctflt.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njfdctfst.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njfdctint.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njidctflt.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njidctfst.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njidctint.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jdct.h)\njquant1.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njquant2.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njutils.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h)\njmemmgr.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)\njmemansi.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,jmemsys.h)\n"
  },
  {
    "path": "tess-two/jni/libjpeg/maktjpeg.st",
    "content": "; Project file for Independent JPEG Group's software\n;\n; This project file is for Atari ST/STE/TT systems using Pure C or Turbo C.\n; Thanks to Frank Moehle, B. Setzepfandt, and Guido Vollbeding.\n;\n; To use this file, rename it to jpegtran.prj.\n; If you are using Turbo C, change filenames beginning with \"pc...\" to \"tc...\"\n; Read installation instructions before trying to make the program!\n;\n;\n;      * * * Output file * * *\njpegtran.ttp\n;\n; * * * COMPILER OPTIONS * * *  \n.C[-P]        ; absolute calls\n.C[-M]        ; and no string merging, folks\n.C[-w-cln]    ; no \"constant is long\" warnings\n.C[-w-par]    ; no \"parameter xxxx unused\"\n.C[-w-rch]    ; no \"unreachable code\"\n.C[-wsig]     ; warn if significant digits may be lost\n=\n; * * * * List of modules * * * * \npcstart.o\njpegtran.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h,transupp.h,jversion.h)\ncdjpeg.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\nrdswitch.c\t(cdjpeg.h,jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jerror.h,cderror.h)\ntransupp.c\t(jinclude.h,jconfig.h,jpeglib.h,jmorecfg.h,jpegint.h,jerror.h,transupp.h)\nlibjpeg.lib        ; built by libjpeg.prj\npcstdlib.lib       ; standard library\npcextlib.lib       ; extended library\n"
  },
  {
    "path": "tess-two/jni/libjpeg/makvms.opt",
    "content": "! A pointer to the VAX/VMS C Run-Time Shareable Library.\n! This file is needed by makefile.mms and makefile.vms,\n! but only for the older VAX C compiler.  DEC C does not need it.\nSys$Library:VAXCRTL.EXE /Share\n"
  },
  {
    "path": "tess-two/jni/libjpeg/missing",
    "content": "#! /bin/sh\n# Common wrapper for a few potentially missing GNU programs.\n\nscriptversion=2013-10-28.13; # UTC\n\n# Copyright (C) 1996-2014 Free Software Foundation, Inc.\n# Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.\n\n# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; either version 2, or (at your option)\n# any later version.\n\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n\n# You should have received a copy of the GNU General Public License\n# along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\n# As a special exception to the GNU General Public License, if you\n# distribute this file as part of a program that contains a\n# configuration script generated by Autoconf, you may include it under\n# the same distribution terms that you use for the rest of that program.\n\nif test $# -eq 0; then\n  echo 1>&2 \"Try '$0 --help' for more information\"\n  exit 1\nfi\n\ncase $1 in\n\n  --is-lightweight)\n    # Used by our autoconf macros to check whether the available missing\n    # script is modern enough.\n    exit 0\n    ;;\n\n  --run)\n    # Back-compat with the calling convention used by older automake.\n    shift\n    ;;\n\n  -h|--h|--he|--hel|--help)\n    echo \"\\\n$0 [OPTION]... PROGRAM [ARGUMENT]...\n\nRun 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due\nto PROGRAM being missing or too old.\n\nOptions:\n  -h, --help      display this help and exit\n  -v, --version   output version information and exit\n\nSupported PROGRAM values:\n  aclocal   autoconf  autoheader   autom4te  automake  makeinfo\n  bison     yacc      flex         lex       help2man\n\nVersion suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and\n'g' are ignored when checking the name.\n\nSend bug reports to <bug-automake@gnu.org>.\"\n    exit $?\n    ;;\n\n  -v|--v|--ve|--ver|--vers|--versi|--versio|--version)\n    echo \"missing $scriptversion (GNU Automake)\"\n    exit $?\n    ;;\n\n  -*)\n    echo 1>&2 \"$0: unknown '$1' option\"\n    echo 1>&2 \"Try '$0 --help' for more information\"\n    exit 1\n    ;;\n\nesac\n\n# Run the given program, remember its exit status.\n\"$@\"; st=$?\n\n# If it succeeded, we are done.\ntest $st -eq 0 && exit 0\n\n# Also exit now if we it failed (or wasn't found), and '--version' was\n# passed; such an option is passed most likely to detect whether the\n# program is present and works.\ncase $2 in --version|--help) exit $st;; esac\n\n# Exit code 63 means version mismatch.  This often happens when the user\n# tries to use an ancient version of a tool on a file that requires a\n# minimum version.\nif test $st -eq 63; then\n  msg=\"probably too old\"\nelif test $st -eq 127; then\n  # Program was missing.\n  msg=\"missing on your system\"\nelse\n  # Program was found and executed, but failed.  Give up.\n  exit $st\nfi\n\nperl_URL=http://www.perl.org/\nflex_URL=http://flex.sourceforge.net/\ngnu_software_URL=http://www.gnu.org/software\n\nprogram_details ()\n{\n  case $1 in\n    aclocal|automake)\n      echo \"The '$1' program is part of the GNU Automake package:\"\n      echo \"<$gnu_software_URL/automake>\"\n      echo \"It also requires GNU Autoconf, GNU m4 and Perl in order to run:\"\n      echo \"<$gnu_software_URL/autoconf>\"\n      echo \"<$gnu_software_URL/m4/>\"\n      echo \"<$perl_URL>\"\n      ;;\n    autoconf|autom4te|autoheader)\n      echo \"The '$1' program is part of the GNU Autoconf package:\"\n      echo \"<$gnu_software_URL/autoconf/>\"\n      echo \"It also requires GNU m4 and Perl in order to run:\"\n      echo \"<$gnu_software_URL/m4/>\"\n      echo \"<$perl_URL>\"\n      ;;\n  esac\n}\n\ngive_advice ()\n{\n  # Normalize program name to check for.\n  normalized_program=`echo \"$1\" | sed '\n    s/^gnu-//; t\n    s/^gnu//; t\n    s/^g//; t'`\n\n  printf '%s\\n' \"'$1' is $msg.\"\n\n  configure_deps=\"'configure.ac' or m4 files included by 'configure.ac'\"\n  case $normalized_program in\n    autoconf*)\n      echo \"You should only need it if you modified 'configure.ac',\"\n      echo \"or m4 files included by it.\"\n      program_details 'autoconf'\n      ;;\n    autoheader*)\n      echo \"You should only need it if you modified 'acconfig.h' or\"\n      echo \"$configure_deps.\"\n      program_details 'autoheader'\n      ;;\n    automake*)\n      echo \"You should only need it if you modified 'Makefile.am' or\"\n      echo \"$configure_deps.\"\n      program_details 'automake'\n      ;;\n    aclocal*)\n      echo \"You should only need it if you modified 'acinclude.m4' or\"\n      echo \"$configure_deps.\"\n      program_details 'aclocal'\n      ;;\n   autom4te*)\n      echo \"You might have modified some maintainer files that require\"\n      echo \"the 'autom4te' program to be rebuilt.\"\n      program_details 'autom4te'\n      ;;\n    bison*|yacc*)\n      echo \"You should only need it if you modified a '.y' file.\"\n      echo \"You may want to install the GNU Bison package:\"\n      echo \"<$gnu_software_URL/bison/>\"\n      ;;\n    lex*|flex*)\n      echo \"You should only need it if you modified a '.l' file.\"\n      echo \"You may want to install the Fast Lexical Analyzer package:\"\n      echo \"<$flex_URL>\"\n      ;;\n    help2man*)\n      echo \"You should only need it if you modified a dependency\" \\\n           \"of a man page.\"\n      echo \"You may want to install the GNU Help2man package:\"\n      echo \"<$gnu_software_URL/help2man/>\"\n    ;;\n    makeinfo*)\n      echo \"You should only need it if you modified a '.texi' file, or\"\n      echo \"any other file indirectly affecting the aspect of the manual.\"\n      echo \"You might want to install the Texinfo package:\"\n      echo \"<$gnu_software_URL/texinfo/>\"\n      echo \"The spurious makeinfo call might also be the consequence of\"\n      echo \"using a buggy 'make' (AIX, DU, IRIX), in which case you might\"\n      echo \"want to install GNU make:\"\n      echo \"<$gnu_software_URL/make/>\"\n      ;;\n    *)\n      echo \"You might have modified some files without having the proper\"\n      echo \"tools for further handling them.  Check the 'README' file, it\"\n      echo \"often tells you about the needed prerequisites for installing\"\n      echo \"this package.  You may also peek at any GNU archive site, in\"\n      echo \"case some other package contains this missing '$1' program.\"\n      ;;\n  esac\n}\n\ngive_advice \"$1\" | sed -e '1s/^/WARNING: /' \\\n                       -e '2,$s/^/         /' >&2\n\n# Propagate the correct exit status (expected to be 127 for a program\n# not found, 63 for a program that failed due to version mismatch).\nexit $st\n\n# Local variables:\n# eval: (add-hook 'write-file-hooks 'time-stamp)\n# time-stamp-start: \"scriptversion=\"\n# time-stamp-format: \"%:y-%02m-%02d.%02H\"\n# time-stamp-time-zone: \"UTC\"\n# time-stamp-end: \"; # UTC\"\n# End:\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdbmp.c",
    "content": "/*\n * rdbmp.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * Modified 2009-2010 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to read input images in Microsoft \"BMP\"\n * format (MS Windows 3.x, OS/2 1.x, and OS/2 2.x flavors).\n * Currently, only 8-bit and 24-bit images are supported, not 1-bit or\n * 4-bit (feeding such low-depth images into JPEG would be silly anyway).\n * Also, we don't support RLE-compressed files.\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume input from\n * an ordinary stdio stream.  They further assume that reading begins\n * at the start of the file; start_input may need work if the\n * user interface has already read some data (e.g., to determine that\n * the file is indeed BMP format).\n *\n * This code contributed by James Arthur Boucher.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef BMP_SUPPORTED\n\n\n/* Macros to deal with unsigned chars as efficiently as compiler allows */\n\n#ifdef HAVE_UNSIGNED_CHAR\ntypedef unsigned char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else /* !HAVE_UNSIGNED_CHAR */\n#ifdef CHAR_IS_UNSIGNED\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x) & 0xFF)\n#endif\n#endif /* HAVE_UNSIGNED_CHAR */\n\n\n#define\tReadOK(file,buffer,len)\t(JFREAD(file,buffer,len) == ((size_t) (len)))\n\n\n/* Private version of data source object */\n\ntypedef struct _bmp_source_struct * bmp_source_ptr;\n\ntypedef struct _bmp_source_struct {\n  struct cjpeg_source_struct pub; /* public fields */\n\n  j_compress_ptr cinfo;\t\t/* back link saves passing separate parm */\n\n  JSAMPARRAY colormap;\t\t/* BMP colormap (converted to my format) */\n\n  jvirt_sarray_ptr whole_image;\t/* Needed to reverse row order */\n  JDIMENSION source_row;\t/* Current source row number */\n  JDIMENSION row_width;\t\t/* Physical width of scanlines in file */\n\n  int bits_per_pixel;\t\t/* remembers 8- or 24-bit format */\n} bmp_source_struct;\n\n\nLOCAL(int)\nread_byte (bmp_source_ptr sinfo)\n/* Read next byte from BMP file */\n{\n  register FILE *infile = sinfo->pub.input_file;\n  register int c;\n\n  if ((c = getc(infile)) == EOF)\n    ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);\n  return c;\n}\n\n\nLOCAL(void)\nread_colormap (bmp_source_ptr sinfo, int cmaplen, int mapentrysize)\n/* Read the colormap from a BMP file */\n{\n  int i;\n\n  switch (mapentrysize) {\n  case 3:\n    /* BGR format (occurs in OS/2 files) */\n    for (i = 0; i < cmaplen; i++) {\n      sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);\n      sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);\n      sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);\n    }\n    break;\n  case 4:\n    /* BGR0 format (occurs in MS Windows files) */\n    for (i = 0; i < cmaplen; i++) {\n      sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);\n      sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);\n      sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);\n      (void) read_byte(sinfo);\n    }\n    break;\n  default:\n    ERREXIT(sinfo->cinfo, JERR_BMP_BADCMAP);\n    break;\n  }\n}\n\n\n/*\n * Read one row of pixels.\n * The image has been read into the whole_image array, but is otherwise\n * unprocessed.  We must read it out in top-to-bottom row order, and if\n * it is an 8-bit image, we must expand colormapped pixels to 24bit format.\n */\n\nMETHODDEF(JDIMENSION)\nget_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 8-bit colormap indexes */\n{\n  bmp_source_ptr source = (bmp_source_ptr) sinfo;\n  register JSAMPARRAY colormap = source->colormap;\n  JSAMPARRAY image_ptr;\n  register int t;\n  register JSAMPROW inptr, outptr;\n  register JDIMENSION col;\n\n  /* Fetch next row from virtual array */\n  source->source_row--;\n  image_ptr = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->whole_image,\n     source->source_row, (JDIMENSION) 1, FALSE);\n\n  /* Expand the colormap indexes to real data */\n  inptr = image_ptr[0];\n  outptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    t = GETJSAMPLE(*inptr++);\n    *outptr++ = colormap[0][t];\t/* can omit GETJSAMPLE() safely */\n    *outptr++ = colormap[1][t];\n    *outptr++ = colormap[2][t];\n  }\n\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 24-bit pixels */\n{\n  bmp_source_ptr source = (bmp_source_ptr) sinfo;\n  JSAMPARRAY image_ptr;\n  register JSAMPROW inptr, outptr;\n  register JDIMENSION col;\n\n  /* Fetch next row from virtual array */\n  source->source_row--;\n  image_ptr = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->whole_image,\n     source->source_row, (JDIMENSION) 1, FALSE);\n\n  /* Transfer data.  Note source values are in BGR order\n   * (even though Microsoft's own documents say the opposite).\n   */\n  inptr = image_ptr[0];\n  outptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    outptr[2] = *inptr++;\t/* can omit GETJSAMPLE() safely */\n    outptr[1] = *inptr++;\n    outptr[0] = *inptr++;\n    outptr += 3;\n  }\n\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_32bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 32-bit pixels */\n{\n  bmp_source_ptr source = (bmp_source_ptr) sinfo;\n  JSAMPARRAY image_ptr;\n  register JSAMPROW inptr, outptr;\n  register JDIMENSION col;\n\n  /* Fetch next row from virtual array */\n  source->source_row--;\n  image_ptr = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->whole_image,\n     source->source_row, (JDIMENSION) 1, FALSE);\n  /* Transfer data.  Note source values are in BGR order\n   * (even though Microsoft's own documents say the opposite).\n   */\n  inptr = image_ptr[0];\n  outptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    outptr[2] = *inptr++;\t/* can omit GETJSAMPLE() safely */\n    outptr[1] = *inptr++;\n    outptr[0] = *inptr++;\n    inptr++;\t\t\t/* skip the 4th byte (Alpha channel) */\n    outptr += 3;\n  }\n\n  return 1;\n}\n\n\n/*\n * This method loads the image into whole_image during the first call on\n * get_pixel_rows.  The get_pixel_rows pointer is then adjusted to call\n * get_8bit_row, get_24bit_row, or get_32bit_row on subsequent calls.\n */\n\nMETHODDEF(JDIMENSION)\npreload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  bmp_source_ptr source = (bmp_source_ptr) sinfo;\n  register FILE *infile = source->pub.input_file;\n  register int c;\n  register JSAMPROW out_ptr;\n  JSAMPARRAY image_ptr;\n  JDIMENSION row, col;\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n\n  /* Read the data into a virtual array in input-file row order. */\n  for (row = 0; row < cinfo->image_height; row++) {\n    if (progress != NULL) {\n      progress->pub.pass_counter = (long) row;\n      progress->pub.pass_limit = (long) cinfo->image_height;\n      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n    }\n    image_ptr = (*cinfo->mem->access_virt_sarray)\n      ((j_common_ptr) cinfo, source->whole_image,\n       row, (JDIMENSION) 1, TRUE);\n    out_ptr = image_ptr[0];\n    for (col = source->row_width; col > 0; col--) {\n      /* inline copy of read_byte() for speed */\n      if ((c = getc(infile)) == EOF)\n\tERREXIT(cinfo, JERR_INPUT_EOF);\n      *out_ptr++ = (JSAMPLE) c;\n    }\n  }\n  if (progress != NULL)\n    progress->completed_extra_passes++;\n\n  /* Set up to read from the virtual array in top-to-bottom order */\n  switch (source->bits_per_pixel) {\n  case 8:\n    source->pub.get_pixel_rows = get_8bit_row;\n    break;\n  case 24:\n    source->pub.get_pixel_rows = get_24bit_row;\n    break;\n  case 32:\n    source->pub.get_pixel_rows = get_32bit_row;\n    break;\n  default:\n    ERREXIT(cinfo, JERR_BMP_BADDEPTH);\n  }\n  source->source_row = cinfo->image_height;\n\n  /* And read the first row */\n  return (*source->pub.get_pixel_rows) (cinfo, sinfo);\n}\n\n\n/*\n * Read the file header; return image size and component count.\n */\n\nMETHODDEF(void)\nstart_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  bmp_source_ptr source = (bmp_source_ptr) sinfo;\n  U_CHAR bmpfileheader[14];\n  U_CHAR bmpinfoheader[64];\n#define GET_2B(array,offset)  ((unsigned int) UCH(array[offset]) + \\\n\t\t\t       (((unsigned int) UCH(array[offset+1])) << 8))\n#define GET_4B(array,offset)  ((INT32) UCH(array[offset]) + \\\n\t\t\t       (((INT32) UCH(array[offset+1])) << 8) + \\\n\t\t\t       (((INT32) UCH(array[offset+2])) << 16) + \\\n\t\t\t       (((INT32) UCH(array[offset+3])) << 24))\n  INT32 bfOffBits;\n  INT32 headerSize;\n  INT32 biWidth;\n  INT32 biHeight;\n  unsigned int biPlanes;\n  INT32 biCompression;\n  INT32 biXPelsPerMeter,biYPelsPerMeter;\n  INT32 biClrUsed = 0;\n  int mapentrysize = 0;\t\t/* 0 indicates no colormap */\n  INT32 bPad;\n  JDIMENSION row_width;\n\n  /* Read and verify the bitmap file header */\n  if (! ReadOK(source->pub.input_file, bmpfileheader, 14))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  if (GET_2B(bmpfileheader,0) != 0x4D42) /* 'BM' */\n    ERREXIT(cinfo, JERR_BMP_NOT);\n  bfOffBits = (INT32) GET_4B(bmpfileheader,10);\n  /* We ignore the remaining fileheader fields */\n\n  /* The infoheader might be 12 bytes (OS/2 1.x), 40 bytes (Windows),\n   * or 64 bytes (OS/2 2.x).  Check the first 4 bytes to find out which.\n   */\n  if (! ReadOK(source->pub.input_file, bmpinfoheader, 4))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  headerSize = (INT32) GET_4B(bmpinfoheader,0);\n  if (headerSize < 12 || headerSize > 64)\n    ERREXIT(cinfo, JERR_BMP_BADHEADER);\n  if (! ReadOK(source->pub.input_file, bmpinfoheader+4, headerSize-4))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n\n  switch ((int) headerSize) {\n  case 12:\n    /* Decode OS/2 1.x header (Microsoft calls this a BITMAPCOREHEADER) */\n    biWidth = (INT32) GET_2B(bmpinfoheader,4);\n    biHeight = (INT32) GET_2B(bmpinfoheader,6);\n    biPlanes = GET_2B(bmpinfoheader,8);\n    source->bits_per_pixel = (int) GET_2B(bmpinfoheader,10);\n\n    switch (source->bits_per_pixel) {\n    case 8:\t\t\t/* colormapped image */\n      mapentrysize = 3;\t\t/* OS/2 uses RGBTRIPLE colormap */\n      TRACEMS2(cinfo, 1, JTRC_BMP_OS2_MAPPED, (int) biWidth, (int) biHeight);\n      break;\n    case 24:\t\t\t/* RGB image */\n      TRACEMS2(cinfo, 1, JTRC_BMP_OS2, (int) biWidth, (int) biHeight);\n      break;\n    default:\n      ERREXIT(cinfo, JERR_BMP_BADDEPTH);\n      break;\n    }\n    break;\n  case 40:\n  case 64:\n    /* Decode Windows 3.x header (Microsoft calls this a BITMAPINFOHEADER) */\n    /* or OS/2 2.x header, which has additional fields that we ignore */\n    biWidth = GET_4B(bmpinfoheader,4);\n    biHeight = GET_4B(bmpinfoheader,8);\n    biPlanes = GET_2B(bmpinfoheader,12);\n    source->bits_per_pixel = (int) GET_2B(bmpinfoheader,14);\n    biCompression = GET_4B(bmpinfoheader,16);\n    biXPelsPerMeter = GET_4B(bmpinfoheader,24);\n    biYPelsPerMeter = GET_4B(bmpinfoheader,28);\n    biClrUsed = GET_4B(bmpinfoheader,32);\n    /* biSizeImage, biClrImportant fields are ignored */\n\n    switch (source->bits_per_pixel) {\n    case 8:\t\t\t/* colormapped image */\n      mapentrysize = 4;\t\t/* Windows uses RGBQUAD colormap */\n      TRACEMS2(cinfo, 1, JTRC_BMP_MAPPED, (int) biWidth, (int) biHeight);\n      break;\n    case 24:\t\t\t/* RGB image */\n      TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);\n      break;\n    case 32:\t\t\t/* RGB image + Alpha channel */\n      TRACEMS2(cinfo, 1, JTRC_BMP, (int) biWidth, (int) biHeight);\n      break;\n    default:\n      ERREXIT(cinfo, JERR_BMP_BADDEPTH);\n      break;\n    }\n    if (biCompression != 0)\n      ERREXIT(cinfo, JERR_BMP_COMPRESSED);\n\n    if (biXPelsPerMeter > 0 && biYPelsPerMeter > 0) {\n      /* Set JFIF density parameters from the BMP data */\n      cinfo->X_density = (UINT16) (biXPelsPerMeter/100); /* 100 cm per meter */\n      cinfo->Y_density = (UINT16) (biYPelsPerMeter/100);\n      cinfo->density_unit = 2;\t/* dots/cm */\n    }\n    break;\n  default:\n    ERREXIT(cinfo, JERR_BMP_BADHEADER);\n    return;\n  }\n\n  if (biWidth <= 0 || biHeight <= 0)\n    ERREXIT(cinfo, JERR_BMP_EMPTY);\n  if (biPlanes != 1)\n    ERREXIT(cinfo, JERR_BMP_BADPLANES);\n\n  /* Compute distance to bitmap data --- will adjust for colormap below */\n  bPad = bfOffBits - (headerSize + 14);\n\n  /* Read the colormap, if any */\n  if (mapentrysize > 0) {\n    if (biClrUsed <= 0)\n      biClrUsed = 256;\t\t/* assume it's 256 */\n    else if (biClrUsed > 256)\n      ERREXIT(cinfo, JERR_BMP_BADCMAP);\n    /* Allocate space to store the colormap */\n    source->colormap = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) biClrUsed, (JDIMENSION) 3);\n    /* and read it from the file */\n    read_colormap(source, (int) biClrUsed, mapentrysize);\n    /* account for size of colormap */\n    bPad -= biClrUsed * mapentrysize;\n  }\n\n  /* Skip any remaining pad bytes */\n  if (bPad < 0)\t\t\t/* incorrect bfOffBits value? */\n    ERREXIT(cinfo, JERR_BMP_BADHEADER);\n  while (--bPad >= 0) {\n    (void) read_byte(source);\n  }\n\n  /* Compute row width in file, including padding to 4-byte boundary */\n  if (source->bits_per_pixel == 24)\n    row_width = (JDIMENSION) (biWidth * 3);\n  else if (source->bits_per_pixel == 32)\n    row_width = (JDIMENSION) (biWidth * 4);\n  else\n    row_width = (JDIMENSION) biWidth;\n  while ((row_width & 3) != 0) row_width++;\n  source->row_width = row_width;\n\n  /* Allocate space for inversion array, prepare for preload pass */\n  source->whole_image = (*cinfo->mem->request_virt_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n     row_width, (JDIMENSION) biHeight, (JDIMENSION) 1);\n  source->pub.get_pixel_rows = preload_image;\n  if (cinfo->progress != NULL) {\n    cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n    progress->total_extra_passes++; /* count file input as separate pass */\n  }\n\n  /* Allocate one-row buffer for returned data */\n  source->pub.buffer = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE,\n     (JDIMENSION) (biWidth * 3), (JDIMENSION) 1);\n  source->pub.buffer_height = 1;\n\n  cinfo->in_color_space = JCS_RGB;\n  cinfo->input_components = 3;\n  cinfo->data_precision = 8;\n  cinfo->image_width = (JDIMENSION) biWidth;\n  cinfo->image_height = (JDIMENSION) biHeight;\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_input_bmp (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  /* no work */\n}\n\n\n/*\n * The module selection routine for BMP format input.\n */\n\nGLOBAL(cjpeg_source_ptr)\njinit_read_bmp (j_compress_ptr cinfo)\n{\n  bmp_source_ptr source;\n\n  /* Create module interface object */\n  source = (bmp_source_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(bmp_source_struct));\n  source->cinfo = cinfo;\t/* make back link for subroutines */\n  /* Fill in method ptrs, except get_pixel_rows which start_input sets */\n  source->pub.start_input = start_input_bmp;\n  source->pub.finish_input = finish_input_bmp;\n\n  return (cjpeg_source_ptr) source;\n}\n\n#endif /* BMP_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdcolmap.c",
    "content": "/*\n * rdcolmap.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file implements djpeg's \"-map file\" switch.  It reads a source image\n * and constructs a colormap to be supplied to the JPEG decompressor.\n *\n * Currently, these file formats are supported for the map file:\n *   GIF: the contents of the GIF's global colormap are used.\n *   PPM (either text or raw flavor): the entire file is read and\n *      each unique pixel value is entered in the map.\n * Note that reading a large PPM file will be horrendously slow.\n * Typically, a PPM-format map file should contain just one pixel\n * of each desired color.  Such a file can be extracted from an\n * ordinary image PPM file with ppmtomap(1).\n *\n * Rescaling a PPM that has a maxval unequal to MAXJSAMPLE is not\n * currently implemented.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef QUANT_2PASS_SUPPORTED\t/* otherwise can't quantize to supplied map */\n\n/* Portions of this code are based on the PBMPLUS library, which is:\n**\n** Copyright (C) 1988 by Jef Poskanzer.\n**\n** Permission to use, copy, modify, and distribute this software and its\n** documentation for any purpose and without fee is hereby granted, provided\n** that the above copyright notice appear in all copies and that both that\n** copyright notice and this permission notice appear in supporting\n** documentation.  This software is provided \"as is\" without express or\n** implied warranty.\n*/\n\n\n/*\n * Add a (potentially) new color to the color map.\n */\n\nLOCAL(void)\nadd_map_entry (j_decompress_ptr cinfo, int R, int G, int B)\n{\n  JSAMPROW colormap0 = cinfo->colormap[0];\n  JSAMPROW colormap1 = cinfo->colormap[1];\n  JSAMPROW colormap2 = cinfo->colormap[2];\n  int ncolors = cinfo->actual_number_of_colors;\n  int index;\n\n  /* Check for duplicate color. */\n  for (index = 0; index < ncolors; index++) {\n    if (GETJSAMPLE(colormap0[index]) == R &&\n\tGETJSAMPLE(colormap1[index]) == G &&\n\tGETJSAMPLE(colormap2[index]) == B)\n      return;\t\t\t/* color is already in map */\n  }\n\n  /* Check for map overflow. */\n  if (ncolors >= (MAXJSAMPLE+1))\n    ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, (MAXJSAMPLE+1));\n\n  /* OK, add color to map. */\n  colormap0[ncolors] = (JSAMPLE) R;\n  colormap1[ncolors] = (JSAMPLE) G;\n  colormap2[ncolors] = (JSAMPLE) B;\n  cinfo->actual_number_of_colors++;\n}\n\n\n/*\n * Extract color map from a GIF file.\n */\n\nLOCAL(void)\nread_gif_map (j_decompress_ptr cinfo, FILE * infile)\n{\n  int header[13];\n  int i, colormaplen;\n  int R, G, B;\n\n  /* Initial 'G' has already been read by read_color_map */\n  /* Read the rest of the GIF header and logical screen descriptor */\n  for (i = 1; i < 13; i++) {\n    if ((header[i] = getc(infile)) == EOF)\n      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n  }\n\n  /* Verify GIF Header */\n  if (header[1] != 'I' || header[2] != 'F')\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n\n  /* There must be a global color map. */\n  if ((header[10] & 0x80) == 0)\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n\n  /* OK, fetch it. */\n  colormaplen = 2 << (header[10] & 0x07);\n\n  for (i = 0; i < colormaplen; i++) {\n    R = getc(infile);\n    G = getc(infile);\n    B = getc(infile);\n    if (R == EOF || G == EOF || B == EOF)\n      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n    add_map_entry(cinfo,\n\t\t  R << (BITS_IN_JSAMPLE-8),\n\t\t  G << (BITS_IN_JSAMPLE-8),\n\t\t  B << (BITS_IN_JSAMPLE-8));\n  }\n}\n\n\n/* Support routines for reading PPM */\n\n\nLOCAL(int)\npbm_getc (FILE * infile)\n/* Read next char, skipping over any comments */\n/* A comment/newline sequence is returned as a newline */\n{\n  register int ch;\n  \n  ch = getc(infile);\n  if (ch == '#') {\n    do {\n      ch = getc(infile);\n    } while (ch != '\\n' && ch != EOF);\n  }\n  return ch;\n}\n\n\nLOCAL(unsigned int)\nread_pbm_integer (j_decompress_ptr cinfo, FILE * infile)\n/* Read an unsigned decimal integer from the PPM file */\n/* Swallows one trailing character after the integer */\n/* Note that on a 16-bit-int machine, only values up to 64k can be read. */\n/* This should not be a problem in practice. */\n{\n  register int ch;\n  register unsigned int val;\n  \n  /* Skip any leading whitespace */\n  do {\n    ch = pbm_getc(infile);\n    if (ch == EOF)\n      ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n  } while (ch == ' ' || ch == '\\t' || ch == '\\n' || ch == '\\r');\n  \n  if (ch < '0' || ch > '9')\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n  \n  val = ch - '0';\n  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {\n    val *= 10;\n    val += ch - '0';\n  }\n  return val;\n}\n\n\n/*\n * Extract color map from a PPM file.\n */\n\nLOCAL(void)\nread_ppm_map (j_decompress_ptr cinfo, FILE * infile)\n{\n  int c;\n  unsigned int w, h, maxval, row, col;\n  int R, G, B;\n\n  /* Initial 'P' has already been read by read_color_map */\n  c = getc(infile);\t\t/* save format discriminator for a sec */\n\n  /* while we fetch the remaining header info */\n  w = read_pbm_integer(cinfo, infile);\n  h = read_pbm_integer(cinfo, infile);\n  maxval = read_pbm_integer(cinfo, infile);\n\n  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n\n  /* For now, we don't support rescaling from an unusual maxval. */\n  if (maxval != (unsigned int) MAXJSAMPLE)\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n\n  switch (c) {\n  case '3':\t\t\t/* it's a text-format PPM file */\n    for (row = 0; row < h; row++) {\n      for (col = 0; col < w; col++) {\n\tR = read_pbm_integer(cinfo, infile);\n\tG = read_pbm_integer(cinfo, infile);\n\tB = read_pbm_integer(cinfo, infile);\n\tadd_map_entry(cinfo, R, G, B);\n      }\n    }\n    break;\n\n  case '6':\t\t\t/* it's a raw-format PPM file */\n    for (row = 0; row < h; row++) {\n      for (col = 0; col < w; col++) {\n\tR = getc(infile);\n\tG = getc(infile);\n\tB = getc(infile);\n\tif (R == EOF || G == EOF || B == EOF)\n\t  ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n\tadd_map_entry(cinfo, R, G, B);\n      }\n    }\n    break;\n\n  default:\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n    break;\n  }\n}\n\n\n/*\n * Main entry point from djpeg.c.\n *  Input: opened input file (from file name argument on command line).\n *  Output: colormap and actual_number_of_colors fields are set in cinfo.\n */\n\nGLOBAL(void)\nread_color_map (j_decompress_ptr cinfo, FILE * infile)\n{\n  /* Allocate space for a color map of maximum supported size. */\n  cinfo->colormap = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE,\n     (JDIMENSION) (MAXJSAMPLE+1), (JDIMENSION) 3);\n  cinfo->actual_number_of_colors = 0; /* initialize map to empty */\n\n  /* Read first byte to determine file format */\n  switch (getc(infile)) {\n  case 'G':\n    read_gif_map(cinfo, infile);\n    break;\n  case 'P':\n    read_ppm_map(cinfo, infile);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_BAD_CMAP_FILE);\n    break;\n  }\n}\n\n#endif /* QUANT_2PASS_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdgif.c",
    "content": "/*\n * rdgif.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to read input images in GIF format.\n *\n *****************************************************************************\n * NOTE: to avoid entanglements with Unisys' patent on LZW compression,      *\n * the ability to read GIF files has been removed from the IJG distribution. *\n * Sorry about that.                                                         *\n *****************************************************************************\n *\n * We are required to state that\n *    \"The Graphics Interchange Format(c) is the Copyright property of\n *    CompuServe Incorporated. GIF(sm) is a Service Mark property of\n *    CompuServe Incorporated.\"\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef GIF_SUPPORTED\n\n/*\n * The module selection routine for GIF format input.\n */\n\nGLOBAL(cjpeg_source_ptr)\njinit_read_gif (j_compress_ptr cinfo)\n{\n  fprintf(stderr, \"GIF input is unsupported for legal reasons.  Sorry.\\n\");\n  exit(EXIT_FAILURE);\n  return NULL;\t\t\t/* keep compiler happy */\n}\n\n#endif /* GIF_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdjpgcom.1",
    "content": ".TH RDJPGCOM 1 \"13 September 2013\"\n.SH NAME\nrdjpgcom \\- display text comments from a JPEG file\n.SH SYNOPSIS\n.B rdjpgcom\n[\n.B \\-raw\n]\n[\n.B \\-verbose\n]\n[\n.I filename\n]\n.LP\n.SH DESCRIPTION\n.LP\n.B rdjpgcom\nreads the named JPEG/JFIF file, or the standard input if no file is named,\nand prints any text comments found in the file on the standard output.\n.PP\nThe JPEG standard allows \"comment\" (COM) blocks to occur within a JPEG file.\nAlthough the standard doesn't actually define what COM blocks are for, they\nare widely used to hold user-supplied text strings.  This lets you add\nannotations, titles, index terms, etc to your JPEG files, and later retrieve\nthem as text.  COM blocks do not interfere with the image stored in the JPEG\nfile.  The maximum size of a COM block is 64K, but you can have as many of\nthem as you like in one JPEG file.\n.SH OPTIONS\n.TP\n.B \\-raw\nNormally\n.B rdjpgcom\nescapes non-printable characters in comments, for security reasons.\nThis option avoids that.\n.PP\n.B \\-verbose\nCauses\n.B rdjpgcom\nto also display the JPEG image dimensions.\n.PP\nSwitch names may be abbreviated, and are not case sensitive.\n.SH HINTS\n.B rdjpgcom\ndoes not depend on the IJG JPEG library.  Its source code is intended as an\nillustration of the minimum amount of code required to parse a JPEG file\nheader correctly.\n.PP\nIn\n.B \\-verbose\nmode,\n.B rdjpgcom\nwill also attempt to print the contents of any \"APP12\" markers as text.\nSome digital cameras produce APP12 markers containing useful textual\ninformation.  If you like, you can modify the source code to print\nother APPn marker types as well.\n.SH SEE ALSO\n.BR cjpeg (1),\n.BR djpeg (1),\n.BR jpegtran (1),\n.BR wrjpgcom (1)\n.SH AUTHOR\nIndependent JPEG Group\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdjpgcom.c",
    "content": "/*\n * rdjpgcom.c\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 2009 by Bill Allombert, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a very simple stand-alone application that displays\n * the text in COM (comment) markers in a JFIF file.\n * This may be useful as an example of the minimum logic needed to parse\n * JPEG markers.\n */\n\n#define JPEG_CJPEG_DJPEG\t/* to get the command-line config symbols */\n#include \"jinclude.h\"\t\t/* get auto-config symbols, <stdio.h> */\n\n#ifdef HAVE_LOCALE_H\n#include <locale.h>\t\t/* Bill Allombert: use locale for isprint */\n#endif\n#include <ctype.h>\t\t/* to declare isupper(), tolower() */\n#ifdef USE_SETMODE\n#include <fcntl.h>\t\t/* to declare setmode()'s parameter macros */\n/* If you have setmode() but not <io.h>, just delete this line: */\n#include <io.h>\t\t\t/* to declare setmode() */\n#endif\n\n#ifdef USE_CCOMMAND\t\t/* command-line reader for Macintosh */\n#ifdef __MWERKS__\n#include <SIOUX.h>              /* Metrowerks needs this */\n#include <console.h>\t\t/* ... and this */\n#endif\n#ifdef THINK_C\n#include <console.h>\t\t/* Think declares it here */\n#endif\n#endif\n\n#ifdef DONT_USE_B_MODE\t\t/* define mode parameters for fopen() */\n#define READ_BINARY\t\"r\"\n#else\n#ifdef VMS\t\t\t/* VMS is very nonstandard */\n#define READ_BINARY\t\"rb\", \"ctx=stm\"\n#else\t\t\t\t/* standard ANSI-compliant case */\n#define READ_BINARY\t\"rb\"\n#endif\n#endif\n\n#ifndef EXIT_FAILURE\t\t/* define exit() codes if not provided */\n#define EXIT_FAILURE  1\n#endif\n#ifndef EXIT_SUCCESS\n#ifdef VMS\n#define EXIT_SUCCESS  1\t\t/* VMS is very nonstandard */\n#else\n#define EXIT_SUCCESS  0\n#endif\n#endif\n\n\n/*\n * These macros are used to read the input file.\n * To reuse this code in another application, you might need to change these.\n */\n\nstatic FILE * infile;\t\t/* input JPEG file */\n\n/* Return next input byte, or EOF if no more */\n#define NEXTBYTE()  getc(infile)\n\n\n/* Error exit handler */\n#define ERREXIT(msg)  (fprintf(stderr, \"%s\\n\", msg), exit(EXIT_FAILURE))\n\n\n/* Read one byte, testing for EOF */\nstatic int\nread_1_byte (void)\n{\n  int c;\n\n  c = NEXTBYTE();\n  if (c == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  return c;\n}\n\n/* Read 2 bytes, convert to unsigned int */\n/* All 2-byte quantities in JPEG markers are MSB first */\nstatic unsigned int\nread_2_bytes (void)\n{\n  int c1, c2;\n\n  c1 = NEXTBYTE();\n  if (c1 == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  c2 = NEXTBYTE();\n  if (c2 == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  return (((unsigned int) c1) << 8) + ((unsigned int) c2);\n}\n\n\n/*\n * JPEG markers consist of one or more 0xFF bytes, followed by a marker\n * code byte (which is not an FF).  Here are the marker codes of interest\n * in this program.  (See jdmarker.c for a more complete list.)\n */\n\n#define M_SOF0  0xC0\t\t/* Start Of Frame N */\n#define M_SOF1  0xC1\t\t/* N indicates which compression process */\n#define M_SOF2  0xC2\t\t/* Only SOF0-SOF2 are now in common use */\n#define M_SOF3  0xC3\n#define M_SOF5  0xC5\t\t/* NB: codes C4 and CC are NOT SOF markers */\n#define M_SOF6  0xC6\n#define M_SOF7  0xC7\n#define M_SOF9  0xC9\n#define M_SOF10 0xCA\n#define M_SOF11 0xCB\n#define M_SOF13 0xCD\n#define M_SOF14 0xCE\n#define M_SOF15 0xCF\n#define M_SOI   0xD8\t\t/* Start Of Image (beginning of datastream) */\n#define M_EOI   0xD9\t\t/* End Of Image (end of datastream) */\n#define M_SOS   0xDA\t\t/* Start Of Scan (begins compressed data) */\n#define M_APP0\t0xE0\t\t/* Application-specific marker, type N */\n#define M_APP12\t0xEC\t\t/* (we don't bother to list all 16 APPn's) */\n#define M_COM   0xFE\t\t/* COMment */\n\n\n/*\n * Find the next JPEG marker and return its marker code.\n * We expect at least one FF byte, possibly more if the compressor used FFs\n * to pad the file.\n * There could also be non-FF garbage between markers.  The treatment of such\n * garbage is unspecified; we choose to skip over it but emit a warning msg.\n * NB: this routine must not be used after seeing SOS marker, since it will\n * not deal correctly with FF/00 sequences in the compressed image data...\n */\n\nstatic int\nnext_marker (void)\n{\n  int c;\n  int discarded_bytes = 0;\n\n  /* Find 0xFF byte; count and skip any non-FFs. */\n  c = read_1_byte();\n  while (c != 0xFF) {\n    discarded_bytes++;\n    c = read_1_byte();\n  }\n  /* Get marker code byte, swallowing any duplicate FF bytes.  Extra FFs\n   * are legal as pad bytes, so don't count them in discarded_bytes.\n   */\n  do {\n    c = read_1_byte();\n  } while (c == 0xFF);\n\n  if (discarded_bytes != 0) {\n    fprintf(stderr, \"Warning: garbage data found in JPEG file\\n\");\n  }\n\n  return c;\n}\n\n\n/*\n * Read the initial marker, which should be SOI.\n * For a JFIF file, the first two bytes of the file should be literally\n * 0xFF M_SOI.  To be more general, we could use next_marker, but if the\n * input file weren't actually JPEG at all, next_marker might read the whole\n * file and then return a misleading error message...\n */\n\nstatic int\nfirst_marker (void)\n{\n  int c1, c2;\n\n  c1 = NEXTBYTE();\n  c2 = NEXTBYTE();\n  if (c1 != 0xFF || c2 != M_SOI)\n    ERREXIT(\"Not a JPEG file\");\n  return c2;\n}\n\n\n/*\n * Most types of marker are followed by a variable-length parameter segment.\n * This routine skips over the parameters for any marker we don't otherwise\n * want to process.\n * Note that we MUST skip the parameter segment explicitly in order not to\n * be fooled by 0xFF bytes that might appear within the parameter segment;\n * such bytes do NOT introduce new markers.\n */\n\nstatic void\nskip_variable (void)\n/* Skip over an unknown or uninteresting variable-length marker */\n{\n  unsigned int length;\n\n  /* Get the marker parameter length count */\n  length = read_2_bytes();\n  /* Length includes itself, so must be at least 2 */\n  if (length < 2)\n    ERREXIT(\"Erroneous JPEG marker length\");\n  length -= 2;\n  /* Skip over the remaining bytes */\n  while (length > 0) {\n    (void) read_1_byte();\n    length--;\n  }\n}\n\n\n/*\n * Process a COM marker.\n * We want to print out the marker contents as legible text;\n * we must guard against non-text junk and varying newline representations.\n */\n\nstatic void\nprocess_COM (int raw)\n{\n  unsigned int length;\n  int ch;\n  int lastch = 0;\n\n  /* Bill Allombert: set locale properly for isprint */\n#ifdef HAVE_LOCALE_H\n  setlocale(LC_CTYPE, \"\");\n#endif\n\n  /* Get the marker parameter length count */\n  length = read_2_bytes();\n  /* Length includes itself, so must be at least 2 */\n  if (length < 2)\n    ERREXIT(\"Erroneous JPEG marker length\");\n  length -= 2;\n\n  while (length > 0) {\n    ch = read_1_byte();\n    if (raw) {\n      putc(ch, stdout);\n    /* Emit the character in a readable form.\n     * Nonprintables are converted to \\nnn form,\n     * while \\ is converted to \\\\.\n     * Newlines in CR, CR/LF, or LF form will be printed as one newline.\n     */\n    } else if (ch == '\\r') {\n      printf(\"\\n\");\n    } else if (ch == '\\n') {\n      if (lastch != '\\r')\n\tprintf(\"\\n\");\n    } else if (ch == '\\\\') {\n      printf(\"\\\\\\\\\");\n    } else if (isprint(ch)) {\n      putc(ch, stdout);\n    } else {\n      printf(\"\\\\%03o\", ch);\n    }\n    lastch = ch;\n    length--;\n  }\n  printf(\"\\n\");\n\n  /* Bill Allombert: revert to C locale */\n#ifdef HAVE_LOCALE_H\n  setlocale(LC_CTYPE, \"C\");\n#endif\n}\n\n\n/*\n * Process a SOFn marker.\n * This code is only needed if you want to know the image dimensions...\n */\n\nstatic void\nprocess_SOFn (int marker)\n{\n  unsigned int length;\n  unsigned int image_height, image_width;\n  int data_precision, num_components;\n  const char * process;\n  int ci;\n\n  length = read_2_bytes();\t/* usual parameter length count */\n\n  data_precision = read_1_byte();\n  image_height = read_2_bytes();\n  image_width = read_2_bytes();\n  num_components = read_1_byte();\n\n  switch (marker) {\n  case M_SOF0:\tprocess = \"Baseline\";  break;\n  case M_SOF1:\tprocess = \"Extended sequential\";  break;\n  case M_SOF2:\tprocess = \"Progressive\";  break;\n  case M_SOF3:\tprocess = \"Lossless\";  break;\n  case M_SOF5:\tprocess = \"Differential sequential\";  break;\n  case M_SOF6:\tprocess = \"Differential progressive\";  break;\n  case M_SOF7:\tprocess = \"Differential lossless\";  break;\n  case M_SOF9:\tprocess = \"Extended sequential, arithmetic coding\";  break;\n  case M_SOF10:\tprocess = \"Progressive, arithmetic coding\";  break;\n  case M_SOF11:\tprocess = \"Lossless, arithmetic coding\";  break;\n  case M_SOF13:\tprocess = \"Differential sequential, arithmetic coding\";  break;\n  case M_SOF14:\tprocess = \"Differential progressive, arithmetic coding\"; break;\n  case M_SOF15:\tprocess = \"Differential lossless, arithmetic coding\";  break;\n  default:\tprocess = \"Unknown\";  break;\n  }\n\n  printf(\"JPEG image is %uw * %uh, %d color components, %d bits per sample\\n\",\n\t image_width, image_height, num_components, data_precision);\n  printf(\"JPEG process: %s\\n\", process);\n\n  if (length != (unsigned int) (8 + num_components * 3))\n    ERREXIT(\"Bogus SOF marker length\");\n\n  for (ci = 0; ci < num_components; ci++) {\n    (void) read_1_byte();\t/* Component ID code */\n    (void) read_1_byte();\t/* H, V sampling factors */\n    (void) read_1_byte();\t/* Quantization table number */\n  }\n}\n\n\n/*\n * Parse the marker stream until SOS or EOI is seen;\n * display any COM markers.\n * While the companion program wrjpgcom will always insert COM markers before\n * SOFn, other implementations might not, so we scan to SOS before stopping.\n * If we were only interested in the image dimensions, we would stop at SOFn.\n * (Conversely, if we only cared about COM markers, there would be no need\n * for special code to handle SOFn; we could treat it like other markers.)\n */\n\nstatic int\nscan_JPEG_header (int verbose, int raw)\n{\n  int marker;\n\n  /* Expect SOI at start of file */\n  if (first_marker() != M_SOI)\n    ERREXIT(\"Expected SOI marker first\");\n\n  /* Scan miscellaneous markers until we reach SOS. */\n  for (;;) {\n    marker = next_marker();\n    switch (marker) {\n      /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,\n       * treated as SOFn.  C4 in particular is actually DHT.\n       */\n    case M_SOF0:\t\t/* Baseline */\n    case M_SOF1:\t\t/* Extended sequential, Huffman */\n    case M_SOF2:\t\t/* Progressive, Huffman */\n    case M_SOF3:\t\t/* Lossless, Huffman */\n    case M_SOF5:\t\t/* Differential sequential, Huffman */\n    case M_SOF6:\t\t/* Differential progressive, Huffman */\n    case M_SOF7:\t\t/* Differential lossless, Huffman */\n    case M_SOF9:\t\t/* Extended sequential, arithmetic */\n    case M_SOF10:\t\t/* Progressive, arithmetic */\n    case M_SOF11:\t\t/* Lossless, arithmetic */\n    case M_SOF13:\t\t/* Differential sequential, arithmetic */\n    case M_SOF14:\t\t/* Differential progressive, arithmetic */\n    case M_SOF15:\t\t/* Differential lossless, arithmetic */\n      if (verbose)\n\tprocess_SOFn(marker);\n      else\n\tskip_variable();\n      break;\n\n    case M_SOS:\t\t\t/* stop before hitting compressed data */\n      return marker;\n\n    case M_EOI:\t\t\t/* in case it's a tables-only JPEG stream */\n      return marker;\n\n    case M_COM:\n      process_COM(raw);\n      break;\n\n    case M_APP12:\n      /* Some digital camera makers put useful textual information into\n       * APP12 markers, so we print those out too when in -verbose mode.\n       */\n      if (verbose) {\n\tprintf(\"APP12 contains:\\n\");\n\tprocess_COM(raw);\n      } else\n\tskip_variable();\n      break;\n\n    default:\t\t\t/* Anything else just gets skipped */\n      skip_variable();\t\t/* we assume it has a parameter count... */\n      break;\n    }\n  } /* end loop */\n}\n\n\n/* Command line parsing code */\n\nstatic const char * progname;\t/* program name for error messages */\n\n\nstatic void\nusage (void)\n/* complain about bad command line */\n{\n  fprintf(stderr, \"rdjpgcom displays any textual comments in a JPEG file.\\n\");\n\n  fprintf(stderr, \"Usage: %s [switches] [inputfile]\\n\", progname);\n\n  fprintf(stderr, \"Switches (names may be abbreviated):\\n\");\n  fprintf(stderr, \"  -raw        Display non-printable characters in comments (unsafe)\\n\");\n  fprintf(stderr, \"  -verbose    Also display dimensions of JPEG image\\n\");\n\n  exit(EXIT_FAILURE);\n}\n\n\nstatic int\nkeymatch (char * arg, const char * keyword, int minchars)\n/* Case-insensitive matching of (possibly abbreviated) keyword switches. */\n/* keyword is the constant keyword (must be lower case already), */\n/* minchars is length of minimum legal abbreviation. */\n{\n  register int ca, ck;\n  register int nmatched = 0;\n\n  while ((ca = *arg++) != '\\0') {\n    if ((ck = *keyword++) == '\\0')\n      return 0;\t\t\t/* arg longer than keyword, no good */\n    if (isupper(ca))\t\t/* force arg to lcase (assume ck is already) */\n      ca = tolower(ca);\n    if (ca != ck)\n      return 0;\t\t\t/* no good */\n    nmatched++;\t\t\t/* count matched characters */\n  }\n  /* reached end of argument; fail if it's too short for unique abbrev */\n  if (nmatched < minchars)\n    return 0;\n  return 1;\t\t\t/* A-OK */\n}\n\n\n/*\n * The main program.\n */\n\nint\nmain (int argc, char **argv)\n{\n  int argn;\n  char * arg;\n  int verbose = 0, raw = 0;\n\n  /* On Mac, fetch a command line. */\n#ifdef USE_CCOMMAND\n  argc = ccommand(&argv);\n#endif\n\n  progname = argv[0];\n  if (progname == NULL || progname[0] == 0)\n    progname = \"rdjpgcom\";\t/* in case C library doesn't provide it */\n\n  /* Parse switches, if any */\n  for (argn = 1; argn < argc; argn++) {\n    arg = argv[argn];\n    if (arg[0] != '-')\n      break;\t\t\t/* not switch, must be file name */\n    arg++;\t\t\t/* advance over '-' */\n    if (keymatch(arg, \"verbose\", 1)) {\n      verbose++;\n    } else if (keymatch(arg, \"raw\", 1)) {\n      raw = 1;\n    } else\n      usage();\n  }\n\n  /* Open the input file. */\n  /* Unix style: expect zero or one file name */\n  if (argn < argc-1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n  if (argn < argc) {\n    if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n#ifdef USE_SETMODE\t\t/* need to hack file mode? */\n    setmode(fileno(stdin), O_BINARY);\n#endif\n#ifdef USE_FDOPEN\t\t/* need to re-open in binary mode? */\n    if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open stdin\\n\", progname);\n      exit(EXIT_FAILURE);\n    }\n#else\n    infile = stdin;\n#endif\n  }\n\n  /* Scan the JPEG headers. */\n  (void) scan_JPEG_header(verbose, raw);\n\n  /* All done. */\n  exit(EXIT_SUCCESS);\n  return 0;\t\t\t/* suppress no-return-value warnings */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdppm.c",
    "content": "/*\n * rdppm.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2009 by Bill Allombert, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to read input images in PPM/PGM format.\n * The extended 2-byte-per-sample raw PPM/PGM formats are supported.\n * The PBMPLUS library is NOT required to compile this software\n * (but it is highly useful as a set of PPM image manipulation programs).\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume input from\n * an ordinary stdio stream.  They further assume that reading begins\n * at the start of the file; start_input may need work if the\n * user interface has already read some data (e.g., to determine that\n * the file is indeed PPM format).\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef PPM_SUPPORTED\n\n\n/* Portions of this code are based on the PBMPLUS library, which is:\n**\n** Copyright (C) 1988 by Jef Poskanzer.\n**\n** Permission to use, copy, modify, and distribute this software and its\n** documentation for any purpose and without fee is hereby granted, provided\n** that the above copyright notice appear in all copies and that both that\n** copyright notice and this permission notice appear in supporting\n** documentation.  This software is provided \"as is\" without express or\n** implied warranty.\n*/\n\n\n/* Macros to deal with unsigned chars as efficiently as compiler allows */\n\n#ifdef HAVE_UNSIGNED_CHAR\ntypedef unsigned char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else /* !HAVE_UNSIGNED_CHAR */\n#ifdef CHAR_IS_UNSIGNED\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x) & 0xFF)\n#endif\n#endif /* HAVE_UNSIGNED_CHAR */\n\n\n#define\tReadOK(file,buffer,len)\t(JFREAD(file,buffer,len) == ((size_t) (len)))\n\n\n/*\n * On most systems, reading individual bytes with getc() is drastically less\n * efficient than buffering a row at a time with fread().  On PCs, we must\n * allocate the buffer in near data space, because we are assuming small-data\n * memory model, wherein fread() can't reach far memory.  If you need to\n * process very wide images on a PC, you might have to compile in large-memory\n * model, or else replace fread() with a getc() loop --- which will be much\n * slower.\n */\n\n\n/* Private version of data source object */\n\ntypedef struct {\n  struct cjpeg_source_struct pub; /* public fields */\n\n  U_CHAR *iobuffer;\t\t/* non-FAR pointer to I/O buffer */\n  JSAMPROW pixrow;\t\t/* FAR pointer to same */\n  size_t buffer_width;\t\t/* width of I/O buffer */\n  JSAMPLE *rescale;\t\t/* => maxval-remapping array, or NULL */\n} ppm_source_struct;\n\ntypedef ppm_source_struct * ppm_source_ptr;\n\n\nLOCAL(int)\npbm_getc (FILE * infile)\n/* Read next char, skipping over any comments */\n/* A comment/newline sequence is returned as a newline */\n{\n  register int ch;\n\n  ch = getc(infile);\n  if (ch == '#') {\n    do {\n      ch = getc(infile);\n    } while (ch != '\\n' && ch != EOF);\n  }\n  return ch;\n}\n\n\nLOCAL(unsigned int)\nread_pbm_integer (j_compress_ptr cinfo, FILE * infile)\n/* Read an unsigned decimal integer from the PPM file */\n/* Swallows one trailing character after the integer */\n/* Note that on a 16-bit-int machine, only values up to 64k can be read. */\n/* This should not be a problem in practice. */\n{\n  register int ch;\n  register unsigned int val;\n\n  /* Skip any leading whitespace */\n  do {\n    ch = pbm_getc(infile);\n    if (ch == EOF)\n      ERREXIT(cinfo, JERR_INPUT_EOF);\n  } while (ch == ' ' || ch == '\\t' || ch == '\\n' || ch == '\\r');\n\n  if (ch < '0' || ch > '9')\n    ERREXIT(cinfo, JERR_PPM_NONNUMERIC);\n\n  val = ch - '0';\n  while ((ch = pbm_getc(infile)) >= '0' && ch <= '9') {\n    val *= 10;\n    val += ch - '0';\n  }\n  return val;\n}\n\n\n/*\n * Read one row of pixels.\n *\n * We provide several different versions depending on input file format.\n * In all cases, input is scaled to the size of JSAMPLE.\n *\n * A really fast path is provided for reading byte/sample raw files with\n * maxval = MAXJSAMPLE, which is the normal case for 8-bit data.\n */\n\n\nMETHODDEF(JDIMENSION)\nget_text_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading text-format PGM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  FILE * infile = source->pub.input_file;\n  register JSAMPROW ptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];\n  }\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_text_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading text-format PPM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  FILE * infile = source->pub.input_file;\n  register JSAMPROW ptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];\n    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];\n    *ptr++ = rescale[read_pbm_integer(cinfo, infile)];\n  }\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_scaled_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading raw-byte-format PGM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register U_CHAR * bufferptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  ptr = source->pub.buffer[0];\n  bufferptr = source->iobuffer;\n  for (col = cinfo->image_width; col > 0; col--) {\n    *ptr++ = rescale[UCH(*bufferptr++)];\n  }\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_scaled_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading raw-byte-format PPM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register U_CHAR * bufferptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  ptr = source->pub.buffer[0];\n  bufferptr = source->iobuffer;\n  for (col = cinfo->image_width; col > 0; col--) {\n    *ptr++ = rescale[UCH(*bufferptr++)];\n    *ptr++ = rescale[UCH(*bufferptr++)];\n    *ptr++ = rescale[UCH(*bufferptr++)];\n  }\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_raw_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading raw-byte-format files with maxval = MAXJSAMPLE.\n * In this case we just read right into the JSAMPLE buffer!\n * Note that same code works for PPM and PGM files.\n */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n\n  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_word_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading raw-word-format PGM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register U_CHAR * bufferptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  ptr = source->pub.buffer[0];\n  bufferptr = source->iobuffer;\n  for (col = cinfo->image_width; col > 0; col--) {\n    register int temp;\n    temp  = UCH(*bufferptr++) << 8;\n    temp |= UCH(*bufferptr++);\n    *ptr++ = rescale[temp];\n  }\n  return 1;\n}\n\n\nMETHODDEF(JDIMENSION)\nget_word_rgb_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading raw-word-format PPM files with any maxval */\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register U_CHAR * bufferptr;\n  register JSAMPLE *rescale = source->rescale;\n  JDIMENSION col;\n\n  if (! ReadOK(source->pub.input_file, source->iobuffer, source->buffer_width))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n  ptr = source->pub.buffer[0];\n  bufferptr = source->iobuffer;\n  for (col = cinfo->image_width; col > 0; col--) {\n    register int temp;\n    temp  = UCH(*bufferptr++) << 8;\n    temp |= UCH(*bufferptr++);\n    *ptr++ = rescale[temp];\n    temp  = UCH(*bufferptr++) << 8;\n    temp |= UCH(*bufferptr++);\n    *ptr++ = rescale[temp];\n    temp  = UCH(*bufferptr++) << 8;\n    temp |= UCH(*bufferptr++);\n    *ptr++ = rescale[temp];\n  }\n  return 1;\n}\n\n\n/*\n * Read the file header; return image size and component count.\n */\n\nMETHODDEF(void)\nstart_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  ppm_source_ptr source = (ppm_source_ptr) sinfo;\n  int c;\n  unsigned int w, h, maxval;\n  boolean need_iobuffer, use_raw_buffer, need_rescale;\n\n  if (getc(source->pub.input_file) != 'P')\n    ERREXIT(cinfo, JERR_PPM_NOT);\n\n  c = getc(source->pub.input_file); /* subformat discriminator character */\n\n  /* detect unsupported variants (ie, PBM) before trying to read header */\n  switch (c) {\n  case '2':\t\t\t/* it's a text-format PGM file */\n  case '3':\t\t\t/* it's a text-format PPM file */\n  case '5':\t\t\t/* it's a raw-format PGM file */\n  case '6':\t\t\t/* it's a raw-format PPM file */\n    break;\n  default:\n    ERREXIT(cinfo, JERR_PPM_NOT);\n    break;\n  }\n\n  /* fetch the remaining header info */\n  w = read_pbm_integer(cinfo, source->pub.input_file);\n  h = read_pbm_integer(cinfo, source->pub.input_file);\n  maxval = read_pbm_integer(cinfo, source->pub.input_file);\n\n  if (w <= 0 || h <= 0 || maxval <= 0) /* error check */\n    ERREXIT(cinfo, JERR_PPM_NOT);\n\n  cinfo->data_precision = BITS_IN_JSAMPLE; /* we always rescale data to this */\n  cinfo->image_width = (JDIMENSION) w;\n  cinfo->image_height = (JDIMENSION) h;\n\n  /* initialize flags to most common settings */\n  need_iobuffer = TRUE;\t\t/* do we need an I/O buffer? */\n  use_raw_buffer = FALSE;\t/* do we map input buffer onto I/O buffer? */\n  need_rescale = TRUE;\t\t/* do we need a rescale array? */\n\n  switch (c) {\n  case '2':\t\t\t/* it's a text-format PGM file */\n    cinfo->input_components = 1;\n    cinfo->in_color_space = JCS_GRAYSCALE;\n    TRACEMS2(cinfo, 1, JTRC_PGM_TEXT, w, h);\n    source->pub.get_pixel_rows = get_text_gray_row;\n    need_iobuffer = FALSE;\n    break;\n\n  case '3':\t\t\t/* it's a text-format PPM file */\n    cinfo->input_components = 3;\n    cinfo->in_color_space = JCS_RGB;\n    TRACEMS2(cinfo, 1, JTRC_PPM_TEXT, w, h);\n    source->pub.get_pixel_rows = get_text_rgb_row;\n    need_iobuffer = FALSE;\n    break;\n\n  case '5':\t\t\t/* it's a raw-format PGM file */\n    cinfo->input_components = 1;\n    cinfo->in_color_space = JCS_GRAYSCALE;\n    TRACEMS2(cinfo, 1, JTRC_PGM, w, h);\n    if (maxval > 255) {\n      source->pub.get_pixel_rows = get_word_gray_row;\n    } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {\n      source->pub.get_pixel_rows = get_raw_row;\n      use_raw_buffer = TRUE;\n      need_rescale = FALSE;\n    } else {\n      source->pub.get_pixel_rows = get_scaled_gray_row;\n    }\n    break;\n\n  case '6':\t\t\t/* it's a raw-format PPM file */\n    cinfo->input_components = 3;\n    cinfo->in_color_space = JCS_RGB;\n    TRACEMS2(cinfo, 1, JTRC_PPM, w, h);\n    if (maxval > 255) {\n      source->pub.get_pixel_rows = get_word_rgb_row;\n    } else if (maxval == MAXJSAMPLE && SIZEOF(JSAMPLE) == SIZEOF(U_CHAR)) {\n      source->pub.get_pixel_rows = get_raw_row;\n      use_raw_buffer = TRUE;\n      need_rescale = FALSE;\n    } else {\n      source->pub.get_pixel_rows = get_scaled_rgb_row;\n    }\n    break;\n  }\n\n  /* Allocate space for I/O buffer: 1 or 3 bytes or words/pixel. */\n  if (need_iobuffer) {\n    source->buffer_width = (size_t) w * cinfo->input_components *\n      ((maxval<=255) ? SIZEOF(U_CHAR) : (2*SIZEOF(U_CHAR)));\n    source->iobuffer = (U_CHAR *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  source->buffer_width);\n  }\n\n  /* Create compressor input buffer. */\n  if (use_raw_buffer) {\n    /* For unscaled raw-input case, we can just map it onto the I/O buffer. */\n    /* Synthesize a JSAMPARRAY pointer structure */\n    /* Cast here implies near->far pointer conversion on PCs */\n    source->pixrow = (JSAMPROW) source->iobuffer;\n    source->pub.buffer = & source->pixrow;\n    source->pub.buffer_height = 1;\n  } else {\n    /* Need to translate anyway, so make a separate sample buffer. */\n    source->pub.buffer = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) w * cinfo->input_components, (JDIMENSION) 1);\n    source->pub.buffer_height = 1;\n  }\n\n  /* Compute the rescaling array if required. */\n  if (need_rescale) {\n    INT32 val, half_maxval;\n\n    /* On 16-bit-int machines we have to be careful of maxval = 65535 */\n    source->rescale = (JSAMPLE *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  (size_t) (((long) maxval + 1L) * SIZEOF(JSAMPLE)));\n    half_maxval = maxval / 2;\n    for (val = 0; val <= (INT32) maxval; val++) {\n      /* The multiplication here must be done in 32 bits to avoid overflow */\n      source->rescale[val] = (JSAMPLE) ((val*MAXJSAMPLE + half_maxval)/maxval);\n    }\n  }\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_input_ppm (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  /* no work */\n}\n\n\n/*\n * The module selection routine for PPM format input.\n */\n\nGLOBAL(cjpeg_source_ptr)\njinit_read_ppm (j_compress_ptr cinfo)\n{\n  ppm_source_ptr source;\n\n  /* Create module interface object */\n  source = (ppm_source_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(ppm_source_struct));\n  /* Fill in method ptrs, except get_pixel_rows which start_input sets */\n  source->pub.start_input = start_input_ppm;\n  source->pub.finish_input = finish_input_ppm;\n\n  return (cjpeg_source_ptr) source;\n}\n\n#endif /* PPM_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdrle.c",
    "content": "/*\n * rdrle.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to read input images in Utah RLE format.\n * The Utah Raster Toolkit library is required (version 3.1 or later).\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume input from\n * an ordinary stdio stream.  They further assume that reading begins\n * at the start of the file; start_input may need work if the\n * user interface has already read some data (e.g., to determine that\n * the file is indeed RLE format).\n *\n * Based on code contributed by Mike Lijewski,\n * with updates from Robert Hutchinson.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef RLE_SUPPORTED\n\n/* rle.h is provided by the Utah Raster Toolkit. */\n\n#include <rle.h>\n\n/*\n * We assume that JSAMPLE has the same representation as rle_pixel,\n * to wit, \"unsigned char\".  Hence we can't cope with 12- or 16-bit samples.\n */\n\n#if BITS_IN_JSAMPLE != 8\n  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */\n#endif\n\n/*\n * We support the following types of RLE files:\n *   \n *   GRAYSCALE   - 8 bits, no colormap\n *   MAPPEDGRAY  - 8 bits, 1 channel colomap\n *   PSEUDOCOLOR - 8 bits, 3 channel colormap\n *   TRUECOLOR   - 24 bits, 3 channel colormap\n *   DIRECTCOLOR - 24 bits, no colormap\n *\n * For now, we ignore any alpha channel in the image.\n */\n\ntypedef enum\n  { GRAYSCALE, MAPPEDGRAY, PSEUDOCOLOR, TRUECOLOR, DIRECTCOLOR } rle_kind;\n\n\n/*\n * Since RLE stores scanlines bottom-to-top, we have to invert the image\n * to conform to JPEG's top-to-bottom order.  To do this, we read the\n * incoming image into a virtual array on the first get_pixel_rows call,\n * then fetch the required row from the virtual array on subsequent calls.\n */\n\ntypedef struct _rle_source_struct * rle_source_ptr;\n\ntypedef struct _rle_source_struct {\n  struct cjpeg_source_struct pub; /* public fields */\n\n  rle_kind visual;              /* actual type of input file */\n  jvirt_sarray_ptr image;       /* virtual array to hold the image */\n  JDIMENSION row;\t\t/* current row # in the virtual array */\n  rle_hdr header;               /* Input file information */\n  rle_pixel** rle_row;          /* holds a row returned by rle_getrow() */\n\n} rle_source_struct;\n\n\n/*\n * Read the file header; return image size and component count.\n */\n\nMETHODDEF(void)\nstart_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  rle_source_ptr source = (rle_source_ptr) sinfo;\n  JDIMENSION width, height;\n#ifdef PROGRESS_REPORT\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n#endif\n\n  /* Use RLE library routine to get the header info */\n  source->header = *rle_hdr_init(NULL);\n  source->header.rle_file = source->pub.input_file;\n  switch (rle_get_setup(&(source->header))) {\n  case RLE_SUCCESS:\n    /* A-OK */\n    break;\n  case RLE_NOT_RLE:\n    ERREXIT(cinfo, JERR_RLE_NOT);\n    break;\n  case RLE_NO_SPACE:\n    ERREXIT(cinfo, JERR_RLE_MEM);\n    break;\n  case RLE_EMPTY:\n    ERREXIT(cinfo, JERR_RLE_EMPTY);\n    break;\n  case RLE_EOF:\n    ERREXIT(cinfo, JERR_RLE_EOF);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_RLE_BADERROR);\n    break;\n  }\n\n  /* Figure out what we have, set private vars and return values accordingly */\n  \n  width  = source->header.xmax - source->header.xmin + 1;\n  height = source->header.ymax - source->header.ymin + 1;\n  source->header.xmin = 0;\t\t/* realign horizontally */\n  source->header.xmax = width-1;\n\n  cinfo->image_width      = width;\n  cinfo->image_height     = height;\n  cinfo->data_precision   = 8;  /* we can only handle 8 bit data */\n\n  if (source->header.ncolors == 1 && source->header.ncmap == 0) {\n    source->visual     = GRAYSCALE;\n    TRACEMS2(cinfo, 1, JTRC_RLE_GRAY, width, height);\n  } else if (source->header.ncolors == 1 && source->header.ncmap == 1) {\n    source->visual     = MAPPEDGRAY;\n    TRACEMS3(cinfo, 1, JTRC_RLE_MAPGRAY, width, height,\n             1 << source->header.cmaplen);\n  } else if (source->header.ncolors == 1 && source->header.ncmap == 3) {\n    source->visual     = PSEUDOCOLOR;\n    TRACEMS3(cinfo, 1, JTRC_RLE_MAPPED, width, height,\n\t     1 << source->header.cmaplen);\n  } else if (source->header.ncolors == 3 && source->header.ncmap == 3) {\n    source->visual     = TRUECOLOR;\n    TRACEMS3(cinfo, 1, JTRC_RLE_FULLMAP, width, height,\n\t     1 << source->header.cmaplen);\n  } else if (source->header.ncolors == 3 && source->header.ncmap == 0) {\n    source->visual     = DIRECTCOLOR;\n    TRACEMS2(cinfo, 1, JTRC_RLE, width, height);\n  } else\n    ERREXIT(cinfo, JERR_RLE_UNSUPPORTED);\n  \n  if (source->visual == GRAYSCALE || source->visual == MAPPEDGRAY) {\n    cinfo->in_color_space   = JCS_GRAYSCALE;\n    cinfo->input_components = 1;\n  } else {\n    cinfo->in_color_space   = JCS_RGB;\n    cinfo->input_components = 3;\n  }\n\n  /*\n   * A place to hold each scanline while it's converted.\n   * (GRAYSCALE scanlines don't need converting)\n   */\n  if (source->visual != GRAYSCALE) {\n    source->rle_row = (rle_pixel**) (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) width, (JDIMENSION) cinfo->input_components);\n  }\n\n  /* request a virtual array to hold the image */\n  source->image = (*cinfo->mem->request_virt_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n     (JDIMENSION) (width * source->header.ncolors),\n     (JDIMENSION) height, (JDIMENSION) 1);\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL) {\n    /* count file input as separate pass */\n    progress->total_extra_passes++;\n  }\n#endif\n\n  source->pub.buffer_height = 1;\n}\n\n\n/*\n * Read one row of pixels.\n * Called only after load_image has read the image into the virtual array.\n * Used for GRAYSCALE, MAPPEDGRAY, TRUECOLOR, and DIRECTCOLOR images.\n */\n\nMETHODDEF(JDIMENSION)\nget_rle_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  rle_source_ptr source = (rle_source_ptr) sinfo;\n\n  source->row--;\n  source->pub.buffer = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);\n\n  return 1;\n}\n\n/*\n * Read one row of pixels.\n * Called only after load_image has read the image into the virtual array.\n * Used for PSEUDOCOLOR images.\n */\n\nMETHODDEF(JDIMENSION)\nget_pseudocolor_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  rle_source_ptr source = (rle_source_ptr) sinfo;\n  JSAMPROW src_row, dest_row;\n  JDIMENSION col;\n  rle_map *colormap;\n  int val;\n\n  colormap = source->header.cmap;\n  dest_row = source->pub.buffer[0];\n  source->row--;\n  src_row = * (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->image, source->row, (JDIMENSION) 1, FALSE);\n\n  for (col = cinfo->image_width; col > 0; col--) {\n    val = GETJSAMPLE(*src_row++);\n    *dest_row++ = (JSAMPLE) (colormap[val      ] >> 8);\n    *dest_row++ = (JSAMPLE) (colormap[val + 256] >> 8);\n    *dest_row++ = (JSAMPLE) (colormap[val + 512] >> 8);\n  }\n\n  return 1;\n}\n\n\n/*\n * Load the image into a virtual array.  We have to do this because RLE\n * files start at the lower left while the JPEG standard has them starting\n * in the upper left.  This is called the first time we want to get a row\n * of input.  What we do is load the RLE data into the array and then call\n * the appropriate routine to read one row from the array.  Before returning,\n * we set source->pub.get_pixel_rows so that subsequent calls go straight to\n * the appropriate row-reading routine.\n */\n\nMETHODDEF(JDIMENSION)\nload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  rle_source_ptr source = (rle_source_ptr) sinfo;\n  JDIMENSION row, col;\n  JSAMPROW  scanline, red_ptr, green_ptr, blue_ptr;\n  rle_pixel **rle_row;\n  rle_map *colormap;\n  char channel;\n#ifdef PROGRESS_REPORT\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n#endif\n\n  colormap = source->header.cmap;\n  rle_row = source->rle_row;\n\n  /* Read the RLE data into our virtual array.\n   * We assume here that (a) rle_pixel is represented the same as JSAMPLE,\n   * and (b) we are not on a machine where FAR pointers differ from regular.\n   */\n  RLE_CLR_BIT(source->header, RLE_ALPHA); /* don't read the alpha channel */\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL) {\n    progress->pub.pass_limit = cinfo->image_height;\n    progress->pub.pass_counter = 0;\n    (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n  }\n#endif\n\n  switch (source->visual) {\n\n  case GRAYSCALE:\n  case PSEUDOCOLOR:\n    for (row = 0; row < cinfo->image_height; row++) {\n      rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)\n         ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);\n      rle_getrow(&source->header, rle_row);\n#ifdef PROGRESS_REPORT\n      if (progress != NULL) {\n        progress->pub.pass_counter++;\n        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n      }\n#endif\n    }\n    break;\n\n  case MAPPEDGRAY:\n  case TRUECOLOR:\n    for (row = 0; row < cinfo->image_height; row++) {\n      scanline = * (*cinfo->mem->access_virt_sarray)\n        ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);\n      rle_row = source->rle_row;\n      rle_getrow(&source->header, rle_row);\n\n      for (col = 0; col < cinfo->image_width; col++) {\n        for (channel = 0; channel < source->header.ncolors; channel++) {\n          *scanline++ = (JSAMPLE)\n            (colormap[GETJSAMPLE(rle_row[channel][col]) + 256 * channel] >> 8);\n        }\n      }\n\n#ifdef PROGRESS_REPORT\n      if (progress != NULL) {\n        progress->pub.pass_counter++;\n        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n      }\n#endif\n    }\n    break;\n\n  case DIRECTCOLOR:\n    for (row = 0; row < cinfo->image_height; row++) {\n      scanline = * (*cinfo->mem->access_virt_sarray)\n        ((j_common_ptr) cinfo, source->image, row, (JDIMENSION) 1, TRUE);\n      rle_getrow(&source->header, rle_row);\n\n      red_ptr   = rle_row[0];\n      green_ptr = rle_row[1];\n      blue_ptr  = rle_row[2];\n\n      for (col = cinfo->image_width; col > 0; col--) {\n        *scanline++ = *red_ptr++;\n        *scanline++ = *green_ptr++;\n        *scanline++ = *blue_ptr++;\n      }\n\n#ifdef PROGRESS_REPORT\n      if (progress != NULL) {\n        progress->pub.pass_counter++;\n        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n      }\n#endif\n    }\n  }\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL)\n    progress->completed_extra_passes++;\n#endif\n\n  /* Set up to call proper row-extraction routine in future */\n  if (source->visual == PSEUDOCOLOR) {\n    source->pub.buffer = source->rle_row;\n    source->pub.get_pixel_rows = get_pseudocolor_row;\n  } else {\n    source->pub.get_pixel_rows = get_rle_row;\n  }\n  source->row = cinfo->image_height;\n\n  /* And fetch the topmost (bottommost) row */\n  return (*source->pub.get_pixel_rows) (cinfo, sinfo);   \n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_input_rle (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  /* no work */\n}\n\n\n/*\n * The module selection routine for RLE format input.\n */\n\nGLOBAL(cjpeg_source_ptr)\njinit_read_rle (j_compress_ptr cinfo)\n{\n  rle_source_ptr source;\n\n  /* Create module interface object */\n  source = (rle_source_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n                                  SIZEOF(rle_source_struct));\n  /* Fill in method ptrs */\n  source->pub.start_input = start_input_rle;\n  source->pub.finish_input = finish_input_rle;\n  source->pub.get_pixel_rows = load_image;\n\n  return (cjpeg_source_ptr) source;\n}\n\n#endif /* RLE_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdswitch.c",
    "content": "/*\n * rdswitch.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2003-2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to process some of cjpeg's more complicated\n * command-line switches.  Switches processed here are:\n *\t-qtables file\t\tRead quantization tables from text file\n *\t-scans file\t\tRead scan script from text file\n *\t-quality N[,N,...]\tSet quality ratings\n *\t-qslots N[,N,...]\tSet component quantization table selectors\n *\t-sample HxV[,HxV,...]\tSet component sampling factors\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n#include <ctype.h>\t\t/* to declare isdigit(), isspace() */\n\n\nLOCAL(int)\ntext_getc (FILE * file)\n/* Read next char, skipping over any comments (# to end of line) */\n/* A comment/newline sequence is returned as a newline */\n{\n  register int ch;\n  \n  ch = getc(file);\n  if (ch == '#') {\n    do {\n      ch = getc(file);\n    } while (ch != '\\n' && ch != EOF);\n  }\n  return ch;\n}\n\n\nLOCAL(boolean)\nread_text_integer (FILE * file, long * result, int * termchar)\n/* Read an unsigned decimal integer from a file, store it in result */\n/* Reads one trailing character after the integer; returns it in termchar */\n{\n  register int ch;\n  register long val;\n  \n  /* Skip any leading whitespace, detect EOF */\n  do {\n    ch = text_getc(file);\n    if (ch == EOF) {\n      *termchar = ch;\n      return FALSE;\n    }\n  } while (isspace(ch));\n  \n  if (! isdigit(ch)) {\n    *termchar = ch;\n    return FALSE;\n  }\n\n  val = ch - '0';\n  while ((ch = text_getc(file)) != EOF) {\n    if (! isdigit(ch))\n      break;\n    val *= 10;\n    val += ch - '0';\n  }\n  *result = val;\n  *termchar = ch;\n  return TRUE;\n}\n\n\nGLOBAL(boolean)\nread_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline)\n/* Read a set of quantization tables from the specified file.\n * The file is plain ASCII text: decimal numbers with whitespace between.\n * Comments preceded by '#' may be included in the file.\n * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.\n * The tables are implicitly numbered 0,1,etc.\n * NOTE: does not affect the qslots mapping, which will default to selecting\n * table 0 for luminance (or primary) components, 1 for chrominance components.\n * You must use -qslots if you want a different component->table mapping.\n */\n{\n  FILE * fp;\n  int tblno, i, termchar;\n  long val;\n  unsigned int table[DCTSIZE2];\n\n  if ((fp = fopen(filename, \"r\")) == NULL) {\n    fprintf(stderr, \"Can't open table file %s\\n\", filename);\n    return FALSE;\n  }\n  tblno = 0;\n\n  while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */\n    if (tblno >= NUM_QUANT_TBLS) {\n      fprintf(stderr, \"Too many tables in file %s\\n\", filename);\n      fclose(fp);\n      return FALSE;\n    }\n    table[0] = (unsigned int) val;\n    for (i = 1; i < DCTSIZE2; i++) {\n      if (! read_text_integer(fp, &val, &termchar)) {\n\tfprintf(stderr, \"Invalid table data in file %s\\n\", filename);\n\tfclose(fp);\n\treturn FALSE;\n      }\n      table[i] = (unsigned int) val;\n    }\n    jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],\n\t\t\t force_baseline);\n    tblno++;\n  }\n\n  if (termchar != EOF) {\n    fprintf(stderr, \"Non-numeric data in file %s\\n\", filename);\n    fclose(fp);\n    return FALSE;\n  }\n\n  fclose(fp);\n  return TRUE;\n}\n\n\n#ifdef C_MULTISCAN_FILES_SUPPORTED\n\nLOCAL(boolean)\nread_scan_integer (FILE * file, long * result, int * termchar)\n/* Variant of read_text_integer that always looks for a non-space termchar;\n * this simplifies parsing of punctuation in scan scripts.\n */\n{\n  register int ch;\n\n  if (! read_text_integer(file, result, termchar))\n    return FALSE;\n  ch = *termchar;\n  while (ch != EOF && isspace(ch))\n    ch = text_getc(file);\n  if (isdigit(ch)) {\t\t/* oops, put it back */\n    if (ungetc(ch, file) == EOF)\n      return FALSE;\n    ch = ' ';\n  } else {\n    /* Any separators other than ';' and ':' are ignored;\n     * this allows user to insert commas, etc, if desired.\n     */\n    if (ch != EOF && ch != ';' && ch != ':')\n      ch = ' ';\n  }\n  *termchar = ch;\n  return TRUE;\n}\n\n\nGLOBAL(boolean)\nread_scan_script (j_compress_ptr cinfo, char * filename)\n/* Read a scan script from the specified text file.\n * Each entry in the file defines one scan to be emitted.\n * Entries are separated by semicolons ';'.\n * An entry contains one to four component indexes,\n * optionally followed by a colon ':' and four progressive-JPEG parameters.\n * The component indexes denote which component(s) are to be transmitted\n * in the current scan.  The first component has index 0.\n * Sequential JPEG is used if the progressive-JPEG parameters are omitted.\n * The file is free format text: any whitespace may appear between numbers\n * and the ':' and ';' punctuation marks.  Also, other punctuation (such\n * as commas or dashes) can be placed between numbers if desired.\n * Comments preceded by '#' may be included in the file.\n * Note: we do very little validity checking here;\n * jcmaster.c will validate the script parameters.\n */\n{\n  FILE * fp;\n  int scanno, ncomps, termchar;\n  long val;\n  jpeg_scan_info * scanptr;\n#define MAX_SCANS  100\t\t/* quite arbitrary limit */\n  jpeg_scan_info scans[MAX_SCANS];\n\n  if ((fp = fopen(filename, \"r\")) == NULL) {\n    fprintf(stderr, \"Can't open scan definition file %s\\n\", filename);\n    return FALSE;\n  }\n  scanptr = scans;\n  scanno = 0;\n\n  while (read_scan_integer(fp, &val, &termchar)) {\n    if (scanno >= MAX_SCANS) {\n      fprintf(stderr, \"Too many scans defined in file %s\\n\", filename);\n      fclose(fp);\n      return FALSE;\n    }\n    scanptr->component_index[0] = (int) val;\n    ncomps = 1;\n    while (termchar == ' ') {\n      if (ncomps >= MAX_COMPS_IN_SCAN) {\n\tfprintf(stderr, \"Too many components in one scan in file %s\\n\",\n\t\tfilename);\n\tfclose(fp);\n\treturn FALSE;\n      }\n      if (! read_scan_integer(fp, &val, &termchar))\n\tgoto bogus;\n      scanptr->component_index[ncomps] = (int) val;\n      ncomps++;\n    }\n    scanptr->comps_in_scan = ncomps;\n    if (termchar == ':') {\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')\n\tgoto bogus;\n      scanptr->Ss = (int) val;\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')\n\tgoto bogus;\n      scanptr->Se = (int) val;\n      if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ')\n\tgoto bogus;\n      scanptr->Ah = (int) val;\n      if (! read_scan_integer(fp, &val, &termchar))\n\tgoto bogus;\n      scanptr->Al = (int) val;\n    } else {\n      /* set non-progressive parameters */\n      scanptr->Ss = 0;\n      scanptr->Se = DCTSIZE2-1;\n      scanptr->Ah = 0;\n      scanptr->Al = 0;\n    }\n    if (termchar != ';' && termchar != EOF) {\nbogus:\n      fprintf(stderr, \"Invalid scan entry format in file %s\\n\", filename);\n      fclose(fp);\n      return FALSE;\n    }\n    scanptr++, scanno++;\n  }\n\n  if (termchar != EOF) {\n    fprintf(stderr, \"Non-numeric data in file %s\\n\", filename);\n    fclose(fp);\n    return FALSE;\n  }\n\n  if (scanno > 0) {\n    /* Stash completed scan list in cinfo structure.\n     * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data,\n     * but if you want to compress multiple images you'd want JPOOL_PERMANENT.\n     */\n    scanptr = (jpeg_scan_info *)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  scanno * SIZEOF(jpeg_scan_info));\n    MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info));\n    cinfo->scan_info = scanptr;\n    cinfo->num_scans = scanno;\n  }\n\n  fclose(fp);\n  return TRUE;\n}\n\n#endif /* C_MULTISCAN_FILES_SUPPORTED */\n\n\nGLOBAL(boolean)\nset_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline)\n/* Process a quality-ratings parameter string, of the form\n *     N[,N,...]\n * If there are more q-table slots than parameters, the last value is replicated.\n */\n{\n  int val = 75;\t\t\t/* default value */\n  int tblno;\n  char ch;\n\n  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {\n    if (*arg) {\n      ch = ',';\t\t\t/* if not set by sscanf, will be ',' */\n      if (sscanf(arg, \"%d%c\", &val, &ch) < 1)\n\treturn FALSE;\n      if (ch != ',')\t\t/* syntax check */\n\treturn FALSE;\n      /* Convert user 0-100 rating to percentage scaling */\n      cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);\n      while (*arg && *arg++ != ',') /* advance to next segment of arg string */\n\t;\n    } else {\n      /* reached end of parameter, set remaining factors to last value */\n      cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);\n    }\n  }\n  jpeg_default_qtables(cinfo, force_baseline);\n  return TRUE;\n}\n\n\nGLOBAL(boolean)\nset_quant_slots (j_compress_ptr cinfo, char *arg)\n/* Process a quantization-table-selectors parameter string, of the form\n *     N[,N,...]\n * If there are more components than parameters, the last value is replicated.\n */\n{\n  int val = 0;\t\t\t/* default table # */\n  int ci;\n  char ch;\n\n  for (ci = 0; ci < MAX_COMPONENTS; ci++) {\n    if (*arg) {\n      ch = ',';\t\t\t/* if not set by sscanf, will be ',' */\n      if (sscanf(arg, \"%d%c\", &val, &ch) < 1)\n\treturn FALSE;\n      if (ch != ',')\t\t/* syntax check */\n\treturn FALSE;\n      if (val < 0 || val >= NUM_QUANT_TBLS) {\n\tfprintf(stderr, \"JPEG quantization tables are numbered 0..%d\\n\",\n\t\tNUM_QUANT_TBLS-1);\n\treturn FALSE;\n      }\n      cinfo->comp_info[ci].quant_tbl_no = val;\n      while (*arg && *arg++ != ',') /* advance to next segment of arg string */\n\t;\n    } else {\n      /* reached end of parameter, set remaining components to last table */\n      cinfo->comp_info[ci].quant_tbl_no = val;\n    }\n  }\n  return TRUE;\n}\n\n\nGLOBAL(boolean)\nset_sample_factors (j_compress_ptr cinfo, char *arg)\n/* Process a sample-factors parameter string, of the form\n *     HxV[,HxV,...]\n * If there are more components than parameters, \"1x1\" is assumed for the rest.\n */\n{\n  int ci, val1, val2;\n  char ch1, ch2;\n\n  for (ci = 0; ci < MAX_COMPONENTS; ci++) {\n    if (*arg) {\n      ch2 = ',';\t\t/* if not set by sscanf, will be ',' */\n      if (sscanf(arg, \"%d%c%d%c\", &val1, &ch1, &val2, &ch2) < 3)\n\treturn FALSE;\n      if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */\n\treturn FALSE;\n      if (val1 <= 0 || val1 > MAX_SAMP_FACTOR ||\n\t  val2 <= 0 || val2 > MAX_SAMP_FACTOR) {\n\tfprintf(stderr, \"JPEG sampling factors must be 1..%d\\n\", MAX_SAMP_FACTOR);\n\treturn FALSE;\n      }\n      cinfo->comp_info[ci].h_samp_factor = val1;\n      cinfo->comp_info[ci].v_samp_factor = val2;\n      while (*arg && *arg++ != ',') /* advance to next segment of arg string */\n\t;\n    } else {\n      /* reached end of parameter, set remaining components to 1x1 sampling */\n      cinfo->comp_info[ci].h_samp_factor = 1;\n      cinfo->comp_info[ci].v_samp_factor = 1;\n    }\n  }\n  return TRUE;\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/rdtarga.c",
    "content": "/*\n * rdtarga.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to read input images in Targa format.\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume input from\n * an ordinary stdio stream.  They further assume that reading begins\n * at the start of the file; start_input may need work if the\n * user interface has already read some data (e.g., to determine that\n * the file is indeed Targa format).\n *\n * Based on code contributed by Lee Daniel Crocker.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef TARGA_SUPPORTED\n\n\n/* Macros to deal with unsigned chars as efficiently as compiler allows */\n\n#ifdef HAVE_UNSIGNED_CHAR\ntypedef unsigned char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else /* !HAVE_UNSIGNED_CHAR */\n#ifdef CHAR_IS_UNSIGNED\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x))\n#else\ntypedef char U_CHAR;\n#define UCH(x)\t((int) (x) & 0xFF)\n#endif\n#endif /* HAVE_UNSIGNED_CHAR */\n\n\n#define\tReadOK(file,buffer,len)\t(JFREAD(file,buffer,len) == ((size_t) (len)))\n\n\n/* Private version of data source object */\n\ntypedef struct _tga_source_struct * tga_source_ptr;\n\ntypedef struct _tga_source_struct {\n  struct cjpeg_source_struct pub; /* public fields */\n\n  j_compress_ptr cinfo;\t\t/* back link saves passing separate parm */\n\n  JSAMPARRAY colormap;\t\t/* Targa colormap (converted to my format) */\n\n  jvirt_sarray_ptr whole_image;\t/* Needed if funny input row order */\n  JDIMENSION current_row;\t/* Current logical row number to read */\n\n  /* Pointer to routine to extract next Targa pixel from input file */\n  JMETHOD(void, read_pixel, (tga_source_ptr sinfo));\n\n  /* Result of read_pixel is delivered here: */\n  U_CHAR tga_pixel[4];\n\n  int pixel_size;\t\t/* Bytes per Targa pixel (1 to 4) */\n\n  /* State info for reading RLE-coded pixels; both counts must be init to 0 */\n  int block_count;\t\t/* # of pixels remaining in RLE block */\n  int dup_pixel_count;\t\t/* # of times to duplicate previous pixel */\n\n  /* This saves the correct pixel-row-expansion method for preload_image */\n  JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,\n\t\t\t\t       cjpeg_source_ptr sinfo));\n} tga_source_struct;\n\n\n/* For expanding 5-bit pixel values to 8-bit with best rounding */\n\nstatic const UINT8 c5to8bits[32] = {\n    0,   8,  16,  25,  33,  41,  49,  58,\n   66,  74,  82,  90,  99, 107, 115, 123,\n  132, 140, 148, 156, 165, 173, 181, 189,\n  197, 206, 214, 222, 230, 239, 247, 255\n};\n\n\n\nLOCAL(int)\nread_byte (tga_source_ptr sinfo)\n/* Read next byte from Targa file */\n{\n  register FILE *infile = sinfo->pub.input_file;\n  register int c;\n\n  if ((c = getc(infile)) == EOF)\n    ERREXIT(sinfo->cinfo, JERR_INPUT_EOF);\n  return c;\n}\n\n\nLOCAL(void)\nread_colormap (tga_source_ptr sinfo, int cmaplen, int mapentrysize)\n/* Read the colormap from a Targa file */\n{\n  int i;\n\n  /* Presently only handles 24-bit BGR format */\n  if (mapentrysize != 24)\n    ERREXIT(sinfo->cinfo, JERR_TGA_BADCMAP);\n\n  for (i = 0; i < cmaplen; i++) {\n    sinfo->colormap[2][i] = (JSAMPLE) read_byte(sinfo);\n    sinfo->colormap[1][i] = (JSAMPLE) read_byte(sinfo);\n    sinfo->colormap[0][i] = (JSAMPLE) read_byte(sinfo);\n  }\n}\n\n\n/*\n * read_pixel methods: get a single pixel from Targa file into tga_pixel[]\n */\n\nMETHODDEF(void)\nread_non_rle_pixel (tga_source_ptr sinfo)\n/* Read one Targa pixel from the input file; no RLE expansion */\n{\n  register FILE *infile = sinfo->pub.input_file;\n  register int i;\n\n  for (i = 0; i < sinfo->pixel_size; i++) {\n    sinfo->tga_pixel[i] = (U_CHAR) getc(infile);\n  }\n}\n\n\nMETHODDEF(void)\nread_rle_pixel (tga_source_ptr sinfo)\n/* Read one Targa pixel from the input file, expanding RLE data as needed */\n{\n  register FILE *infile = sinfo->pub.input_file;\n  register int i;\n\n  /* Duplicate previously read pixel? */\n  if (sinfo->dup_pixel_count > 0) {\n    sinfo->dup_pixel_count--;\n    return;\n  }\n\n  /* Time to read RLE block header? */\n  if (--sinfo->block_count < 0) { /* decrement pixels remaining in block */\n    i = read_byte(sinfo);\n    if (i & 0x80) {\t\t/* Start of duplicate-pixel block? */\n      sinfo->dup_pixel_count = i & 0x7F; /* number of dups after this one */\n      sinfo->block_count = 0;\t/* then read new block header */\n    } else {\n      sinfo->block_count = i & 0x7F; /* number of pixels after this one */\n    }\n  }\n\n  /* Read next pixel */\n  for (i = 0; i < sinfo->pixel_size; i++) {\n    sinfo->tga_pixel[i] = (U_CHAR) getc(infile);\n  }\n}\n\n\n/*\n * Read one row of pixels.\n *\n * We provide several different versions depending on input file format.\n */\n\n\nMETHODDEF(JDIMENSION)\nget_8bit_gray_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 8-bit grayscale pixels */\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n  \n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */\n    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);\n  }\n  return 1;\n}\n\nMETHODDEF(JDIMENSION)\nget_8bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 8-bit colormap indexes */\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  register int t;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n  register JSAMPARRAY colormap = source->colormap;\n\n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */\n    t = UCH(source->tga_pixel[0]);\n    *ptr++ = colormap[0][t];\n    *ptr++ = colormap[1][t];\n    *ptr++ = colormap[2][t];\n  }\n  return 1;\n}\n\nMETHODDEF(JDIMENSION)\nget_16bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 16-bit pixels */\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  register int t;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n  \n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */\n    t = UCH(source->tga_pixel[0]);\n    t += UCH(source->tga_pixel[1]) << 8;\n    /* We expand 5 bit data to 8 bit sample width.\n     * The format of the 16-bit (LSB first) input word is\n     *     xRRRRRGGGGGBBBBB\n     */\n    ptr[2] = (JSAMPLE) c5to8bits[t & 0x1F];\n    t >>= 5;\n    ptr[1] = (JSAMPLE) c5to8bits[t & 0x1F];\n    t >>= 5;\n    ptr[0] = (JSAMPLE) c5to8bits[t & 0x1F];\n    ptr += 3;\n  }\n  return 1;\n}\n\nMETHODDEF(JDIMENSION)\nget_24bit_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n/* This version is for reading 24-bit pixels */\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n  \n  ptr = source->pub.buffer[0];\n  for (col = cinfo->image_width; col > 0; col--) {\n    (*source->read_pixel) (source); /* Load next pixel into tga_pixel */\n    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[2]); /* change BGR to RGB order */\n    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[1]);\n    *ptr++ = (JSAMPLE) UCH(source->tga_pixel[0]);\n  }\n  return 1;\n}\n\n/*\n * Targa also defines a 32-bit pixel format with order B,G,R,A.\n * We presently ignore the attribute byte, so the code for reading\n * these pixels is identical to the 24-bit routine above.\n * This works because the actual pixel length is only known to read_pixel.\n */\n\n#define get_32bit_row  get_24bit_row\n\n\n/*\n * This method is for re-reading the input data in standard top-down\n * row order.  The entire image has already been read into whole_image\n * with proper conversion of pixel format, but it's in a funny row order.\n */\n\nMETHODDEF(JDIMENSION)\nget_memory_row (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  JDIMENSION source_row;\n\n  /* Compute row of source that maps to current_row of normal order */\n  /* For now, assume image is bottom-up and not interlaced. */\n  /* NEEDS WORK to support interlaced images! */\n  source_row = cinfo->image_height - source->current_row - 1;\n\n  /* Fetch that row from virtual array */\n  source->pub.buffer = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, source->whole_image,\n     source_row, (JDIMENSION) 1, FALSE);\n\n  source->current_row++;\n  return 1;\n}\n\n\n/*\n * This method loads the image into whole_image during the first call on\n * get_pixel_rows.  The get_pixel_rows pointer is then adjusted to call\n * get_memory_row on subsequent calls.\n */\n\nMETHODDEF(JDIMENSION)\npreload_image (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  JDIMENSION row;\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n\n  /* Read the data into a virtual array in input-file row order. */\n  for (row = 0; row < cinfo->image_height; row++) {\n    if (progress != NULL) {\n      progress->pub.pass_counter = (long) row;\n      progress->pub.pass_limit = (long) cinfo->image_height;\n      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n    }\n    source->pub.buffer = (*cinfo->mem->access_virt_sarray)\n      ((j_common_ptr) cinfo, source->whole_image, row, (JDIMENSION) 1, TRUE);\n    (*source->get_pixel_rows) (cinfo, sinfo);\n  }\n  if (progress != NULL)\n    progress->completed_extra_passes++;\n\n  /* Set up to read from the virtual array in unscrambled order */\n  source->pub.get_pixel_rows = get_memory_row;\n  source->current_row = 0;\n  /* And read the first row */\n  return get_memory_row(cinfo, sinfo);\n}\n\n\n/*\n * Read the file header; return image size and component count.\n */\n\nMETHODDEF(void)\nstart_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  tga_source_ptr source = (tga_source_ptr) sinfo;\n  U_CHAR targaheader[18];\n  int idlen, cmaptype, subtype, flags, interlace_type, components;\n  unsigned int width, height, maplen;\n  boolean is_bottom_up;\n\n#define GET_2B(offset)\t((unsigned int) UCH(targaheader[offset]) + \\\n\t\t\t (((unsigned int) UCH(targaheader[offset+1])) << 8))\n\n  if (! ReadOK(source->pub.input_file, targaheader, 18))\n    ERREXIT(cinfo, JERR_INPUT_EOF);\n\n  /* Pretend \"15-bit\" pixels are 16-bit --- we ignore attribute bit anyway */\n  if (targaheader[16] == 15)\n    targaheader[16] = 16;\n\n  idlen = UCH(targaheader[0]);\n  cmaptype = UCH(targaheader[1]);\n  subtype = UCH(targaheader[2]);\n  maplen = GET_2B(5);\n  width = GET_2B(12);\n  height = GET_2B(14);\n  source->pixel_size = UCH(targaheader[16]) >> 3;\n  flags = UCH(targaheader[17]);\t/* Image Descriptor byte */\n\n  is_bottom_up = ((flags & 0x20) == 0);\t/* bit 5 set => top-down */\n  interlace_type = flags >> 6;\t/* bits 6/7 are interlace code */\n\n  if (cmaptype > 1 ||\t\t/* cmaptype must be 0 or 1 */\n      source->pixel_size < 1 || source->pixel_size > 4 ||\n      (UCH(targaheader[16]) & 7) != 0 || /* bits/pixel must be multiple of 8 */\n      interlace_type != 0)\t/* currently don't allow interlaced image */\n    ERREXIT(cinfo, JERR_TGA_BADPARMS);\n  \n  if (subtype > 8) {\n    /* It's an RLE-coded file */\n    source->read_pixel = read_rle_pixel;\n    source->block_count = source->dup_pixel_count = 0;\n    subtype -= 8;\n  } else {\n    /* Non-RLE file */\n    source->read_pixel = read_non_rle_pixel;\n  }\n\n  /* Now should have subtype 1, 2, or 3 */\n  components = 3;\t\t/* until proven different */\n  cinfo->in_color_space = JCS_RGB;\n\n  switch (subtype) {\n  case 1:\t\t\t/* Colormapped image */\n    if (source->pixel_size == 1 && cmaptype == 1)\n      source->get_pixel_rows = get_8bit_row;\n    else\n      ERREXIT(cinfo, JERR_TGA_BADPARMS);\n    TRACEMS2(cinfo, 1, JTRC_TGA_MAPPED, width, height);\n    break;\n  case 2:\t\t\t/* RGB image */\n    switch (source->pixel_size) {\n    case 2:\n      source->get_pixel_rows = get_16bit_row;\n      break;\n    case 3:\n      source->get_pixel_rows = get_24bit_row;\n      break;\n    case 4:\n      source->get_pixel_rows = get_32bit_row;\n      break;\n    default:\n      ERREXIT(cinfo, JERR_TGA_BADPARMS);\n      break;\n    }\n    TRACEMS2(cinfo, 1, JTRC_TGA, width, height);\n    break;\n  case 3:\t\t\t/* Grayscale image */\n    components = 1;\n    cinfo->in_color_space = JCS_GRAYSCALE;\n    if (source->pixel_size == 1)\n      source->get_pixel_rows = get_8bit_gray_row;\n    else\n      ERREXIT(cinfo, JERR_TGA_BADPARMS);\n    TRACEMS2(cinfo, 1, JTRC_TGA_GRAY, width, height);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_TGA_BADPARMS);\n    break;\n  }\n\n  if (is_bottom_up) {\n    /* Create a virtual array to buffer the upside-down image. */\n    source->whole_image = (*cinfo->mem->request_virt_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n       (JDIMENSION) width * components, (JDIMENSION) height, (JDIMENSION) 1);\n    if (cinfo->progress != NULL) {\n      cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n      progress->total_extra_passes++; /* count file input as separate pass */\n    }\n    /* source->pub.buffer will point to the virtual array. */\n    source->pub.buffer_height = 1; /* in case anyone looks at it */\n    source->pub.get_pixel_rows = preload_image;\n  } else {\n    /* Don't need a virtual array, but do need a one-row input buffer. */\n    source->whole_image = NULL;\n    source->pub.buffer = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       (JDIMENSION) width * components, (JDIMENSION) 1);\n    source->pub.buffer_height = 1;\n    source->pub.get_pixel_rows = source->get_pixel_rows;\n  }\n  \n  while (idlen--)\t\t/* Throw away ID field */\n    (void) read_byte(source);\n\n  if (maplen > 0) {\n    if (maplen > 256 || GET_2B(3) != 0)\n      ERREXIT(cinfo, JERR_TGA_BADCMAP);\n    /* Allocate space to store the colormap */\n    source->colormap = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE, (JDIMENSION) maplen, (JDIMENSION) 3);\n    /* and read it from the file */\n    read_colormap(source, (int) maplen, UCH(targaheader[7]));\n  } else {\n    if (cmaptype)\t\t/* but you promised a cmap! */\n      ERREXIT(cinfo, JERR_TGA_BADPARMS);\n    source->colormap = NULL;\n  }\n\n  cinfo->input_components = components;\n  cinfo->data_precision = 8;\n  cinfo->image_width = width;\n  cinfo->image_height = height;\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_input_tga (j_compress_ptr cinfo, cjpeg_source_ptr sinfo)\n{\n  /* no work */\n}\n\n\n/*\n * The module selection routine for Targa format input.\n */\n\nGLOBAL(cjpeg_source_ptr)\njinit_read_targa (j_compress_ptr cinfo)\n{\n  tga_source_ptr source;\n\n  /* Create module interface object */\n  source = (tga_source_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(tga_source_struct));\n  source->cinfo = cinfo;\t/* make back link for subroutines */\n  /* Fill in method ptrs, except get_pixel_rows which start_input sets */\n  source->pub.start_input = start_input_tga;\n  source->pub.finish_input = finish_input_tga;\n\n  return (cjpeg_source_ptr) source;\n}\n\n#endif /* TARGA_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/structure.txt",
    "content": "IJG JPEG LIBRARY:  SYSTEM ARCHITECTURE\n\nCopyright (C) 1991-2013, Thomas G. Lane, Guido Vollbeding.\nThis file is part of the Independent JPEG Group's software.\nFor conditions of distribution and use, see the accompanying README file.\n\n\nThis file provides an overview of the architecture of the IJG JPEG software;\nthat is, the functions of the various modules in the system and the interfaces\nbetween modules.  For more precise details about any data structure or calling\nconvention, see the include files and comments in the source code.\n\nWe assume that the reader is already somewhat familiar with the JPEG standard.\nThe README file includes references for learning about JPEG.  The file\nlibjpeg.txt describes the library from the viewpoint of an application\nprogrammer using the library; it's best to read that file before this one.\nAlso, the file coderules.txt describes the coding style conventions we use.\n\nIn this document, JPEG-specific terminology follows the JPEG standard:\n  A \"component\" means a color channel, e.g., Red or Luminance.\n  A \"sample\" is a single component value (i.e., one number in the image data).\n  A \"coefficient\" is a frequency coefficient (a DCT transform output number).\n  A \"block\" is an array of samples or coefficients.\n  An \"MCU\" (minimum coded unit) is an interleaved set of blocks of size\n\tdetermined by the sampling factors, or a single block in a\n\tnoninterleaved scan.\nWe do not use the terms \"pixel\" and \"sample\" interchangeably.  When we say\npixel, we mean an element of the full-size image, while a sample is an element\nof the downsampled image.  Thus the number of samples may vary across\ncomponents while the number of pixels does not.  (This terminology is not used\nrigorously throughout the code, but it is used in places where confusion would\notherwise result.)\n\n\n*** System features ***\n\nThe IJG distribution contains two parts:\n  * A subroutine library for JPEG compression and decompression.\n  * cjpeg/djpeg, two sample applications that use the library to transform\n    JFIF JPEG files to and from several other image formats.\ncjpeg/djpeg are of no great intellectual complexity: they merely add a simple\ncommand-line user interface and I/O routines for several uncompressed image\nformats.  This document concentrates on the library itself.\n\nWe desire the library to be capable of supporting all JPEG baseline, extended\nsequential, and progressive DCT processes.  The library does not support the\nhierarchical or lossless processes defined in the standard.\n\nWithin these limits, any set of compression parameters allowed by the JPEG\nspec should be readable for decompression.  (We can be more restrictive about\nwhat formats we can generate.)  Although the system design allows for all\nparameter values, some uncommon settings are not yet implemented and may\nnever be; nonintegral sampling ratios are the prime example.  Furthermore,\nwe treat 8-bit vs. 12-bit data precision as a compile-time switch, not a\nrun-time option, because most machines can store 8-bit pixels much more\ncompactly than 12-bit.\n\nBy itself, the library handles only interchange JPEG datastreams --- in\nparticular the widely used JFIF file format.  The library can be used by\nsurrounding code to process interchange or abbreviated JPEG datastreams that\nare embedded in more complex file formats.  (For example, libtiff uses this\nlibrary to implement JPEG compression within the TIFF file format.)\n\nThe library includes a substantial amount of code that is not covered by the\nJPEG standard but is necessary for typical applications of JPEG.  These\nfunctions preprocess the image before JPEG compression or postprocess it after\ndecompression.  They include colorspace conversion, downsampling/upsampling,\nand color quantization.  This code can be omitted if not needed.\n\nA wide range of quality vs. speed tradeoffs are possible in JPEG processing,\nand even more so in decompression postprocessing.  The decompression library\nprovides multiple implementations that cover most of the useful tradeoffs,\nranging from very-high-quality down to fast-preview operation.  On the\ncompression side we have generally not provided low-quality choices, since\ncompression is normally less time-critical.  It should be understood that the\nlow-quality modes may not meet the JPEG standard's accuracy requirements;\nnonetheless, they are useful for viewers.\n\n\n*** Portability issues ***\n\nPortability is an essential requirement for the library.  The key portability\nissues that show up at the level of system architecture are:\n\n1.  Memory usage.  We want the code to be able to run on PC-class machines\nwith limited memory.  Images should therefore be processed sequentially (in\nstrips), to avoid holding the whole image in memory at once.  Where a\nfull-image buffer is necessary, we should be able to use either virtual memory\nor temporary files.\n\n2.  Near/far pointer distinction.  To run efficiently on 80x86 machines, the\ncode should distinguish \"small\" objects (kept in near data space) from\n\"large\" ones (kept in far data space).  This is an annoying restriction, but\nfortunately it does not impact code quality for less brain-damaged machines,\nand the source code clutter turns out to be minimal with sufficient use of\npointer typedefs.\n\n3. Data precision.  We assume that \"char\" is at least 8 bits, \"short\" and\n\"int\" at least 16, \"long\" at least 32.  The code will work fine with larger\ndata sizes, although memory may be used inefficiently in some cases.  However,\nthe JPEG compressed datastream must ultimately appear on external storage as a\nsequence of 8-bit bytes if it is to conform to the standard.  This may pose a\nproblem on machines where char is wider than 8 bits.  The library represents\ncompressed data as an array of values of typedef JOCTET.  If no data type\nexactly 8 bits wide is available, custom data source and data destination\nmodules must be written to unpack and pack the chosen JOCTET datatype into\n8-bit external representation.\n\n\n*** System overview ***\n\nThe compressor and decompressor are each divided into two main sections:\nthe JPEG compressor or decompressor proper, and the preprocessing or\npostprocessing functions.  The interface between these two sections is the\nimage data that the official JPEG spec regards as its input or output: this\ndata is in the colorspace to be used for compression, and it is downsampled\nto the sampling factors to be used.  The preprocessing and postprocessing\nsteps are responsible for converting a normal image representation to or from\nthis form.  (Those few applications that want to deal with YCbCr downsampled\ndata can skip the preprocessing or postprocessing step.)\n\nLooking more closely, the compressor library contains the following main\nelements:\n\n  Preprocessing:\n    * Color space conversion (e.g., RGB to YCbCr).\n    * Edge expansion and downsampling.  Optionally, this step can do simple\n      smoothing --- this is often helpful for low-quality source data.\n  JPEG proper:\n    * MCU assembly, DCT, quantization.\n    * Entropy coding (sequential or progressive, Huffman or arithmetic).\n\nIn addition to these modules we need overall control, marker generation,\nand support code (memory management & error handling).  There is also a\nmodule responsible for physically writing the output data --- typically\nthis is just an interface to fwrite(), but some applications may need to\ndo something else with the data.\n\nThe decompressor library contains the following main elements:\n\n  JPEG proper:\n    * Entropy decoding (sequential or progressive, Huffman or arithmetic).\n    * Dequantization, inverse DCT, MCU disassembly.\n  Postprocessing:\n    * Upsampling.  Optionally, this step may be able to do more general\n      rescaling of the image.\n    * Color space conversion (e.g., YCbCr to RGB).  This step may also\n      provide gamma adjustment [ currently it does not ].\n    * Optional color quantization (e.g., reduction to 256 colors).\n    * Optional color precision reduction (e.g., 24-bit to 15-bit color).\n      [This feature is not currently implemented.]\n\nWe also need overall control, marker parsing, and a data source module.\nThe support code (memory management & error handling) can be shared with\nthe compression half of the library.\n\nThere may be several implementations of each of these elements, particularly\nin the decompressor, where a wide range of speed/quality tradeoffs is very\nuseful.  It must be understood that some of the best speedups involve\nmerging adjacent steps in the pipeline.  For example, upsampling, color space\nconversion, and color quantization might all be done at once when using a\nlow-quality ordered-dither technique.  The system architecture is designed to\nallow such merging where appropriate.\n\n\nNote: it is convenient to regard edge expansion (padding to block boundaries)\nas a preprocessing/postprocessing function, even though the JPEG spec includes\nit in compression/decompression.  We do this because downsampling/upsampling\ncan be simplified a little if they work on padded data: it's not necessary to\nhave special cases at the right and bottom edges.  Therefore the interface\nbuffer is always an integral number of blocks wide and high, and we expect\ncompression preprocessing to pad the source data properly.  Padding will occur\nonly to the next block (block_size-sample) boundary.  In an interleaved-scan\nsituation, additional dummy blocks may be used to fill out MCUs, but the MCU\nassembly and disassembly logic will create or discard these blocks internally.\n(This is advantageous for speed reasons, since we avoid DCTing the dummy\nblocks.  It also permits a small reduction in file size, because the\ncompressor can choose dummy block contents so as to minimize their size\nin compressed form.  Finally, it makes the interface buffer specification\nindependent of whether the file is actually interleaved or not.)\nApplications that wish to deal directly with the downsampled data must\nprovide similar buffering and padding for odd-sized images.\n\n\n*** Poor man's object-oriented programming ***\n\nIt should be clear by now that we have a lot of quasi-independent processing\nsteps, many of which have several possible behaviors.  To avoid cluttering the\ncode with lots of switch statements, we use a simple form of object-style\nprogramming to separate out the different possibilities.\n\nFor example, two different color quantization algorithms could be implemented\nas two separate modules that present the same external interface; at runtime,\nthe calling code will access the proper module indirectly through an \"object\".\n\nWe can get the limited features we need while staying within portable C.\nThe basic tool is a function pointer.  An \"object\" is just a struct\ncontaining one or more function pointer fields, each of which corresponds to\na method name in real object-oriented languages.  During initialization we\nfill in the function pointers with references to whichever module we have\ndetermined we need to use in this run.  Then invocation of the module is done\nby indirecting through a function pointer; on most machines this is no more\nexpensive than a switch statement, which would be the only other way of\nmaking the required run-time choice.  The really significant benefit, of\ncourse, is keeping the source code clean and well structured.\n\nWe can also arrange to have private storage that varies between different\nimplementations of the same kind of object.  We do this by making all the\nmodule-specific object structs be separately allocated entities, which will\nbe accessed via pointers in the master compression or decompression struct.\nThe \"public\" fields or methods for a given kind of object are specified by\na commonly known struct.  But a module's initialization code can allocate\na larger struct that contains the common struct as its first member, plus\nadditional private fields.  With appropriate pointer casting, the module's\ninternal functions can access these private fields.  (For a simple example,\nsee jdatadst.c, which implements the external interface specified by struct\njpeg_destination_mgr, but adds extra fields.)\n\n(Of course this would all be a lot easier if we were using C++, but we are\nnot yet prepared to assume that everyone has a C++ compiler.)\n\nAn important benefit of this scheme is that it is easy to provide multiple\nversions of any method, each tuned to a particular case.  While a lot of\nprecalculation might be done to select an optimal implementation of a method,\nthe cost per invocation is constant.  For example, the upsampling step might\nhave a \"generic\" method, plus one or more \"hardwired\" methods for the most\npopular sampling factors; the hardwired methods would be faster because they'd\nuse straight-line code instead of for-loops.  The cost to determine which\nmethod to use is paid only once, at startup, and the selection criteria are\nhidden from the callers of the method.\n\nThis plan differs a little bit from usual object-oriented structures, in that\nonly one instance of each object class will exist during execution.  The\nreason for having the class structure is that on different runs we may create\ndifferent instances (choose to execute different modules).  You can think of\nthe term \"method\" as denoting the common interface presented by a particular\nset of interchangeable functions, and \"object\" as denoting a group of related\nmethods, or the total shared interface behavior of a group of modules.\n\n\n*** Overall control structure ***\n\nWe previously mentioned the need for overall control logic in the compression\nand decompression libraries.  In IJG implementations prior to v5, overall\ncontrol was mostly provided by \"pipeline control\" modules, which proved to be\nlarge, unwieldy, and hard to understand.  To improve the situation, the\ncontrol logic has been subdivided into multiple modules.  The control modules\nconsist of:\n\n1. Master control for module selection and initialization.  This has two\nresponsibilities:\n\n   1A.  Startup initialization at the beginning of image processing.\n        The individual processing modules to be used in this run are selected\n        and given initialization calls.\n\n   1B.  Per-pass control.  This determines how many passes will be performed\n        and calls each active processing module to configure itself\n        appropriately at the beginning of each pass.  End-of-pass processing,\n\twhere necessary, is also invoked from the master control module.\n\n   Method selection is partially distributed, in that a particular processing\n   module may contain several possible implementations of a particular method,\n   which it will select among when given its initialization call.  The master\n   control code need only be concerned with decisions that affect more than\n   one module.\n \n2. Data buffering control.  A separate control module exists for each\n   inter-processing-step data buffer.  This module is responsible for\n   invoking the processing steps that write or read that data buffer.\n\nEach buffer controller sees the world as follows:\n\ninput data => processing step A => buffer => processing step B => output data\n                      |              |               |\n              ------------------ controller ------------------\n\nThe controller knows the dataflow requirements of steps A and B: how much data\nthey want to accept in one chunk and how much they output in one chunk.  Its\nfunction is to manage its buffer and call A and B at the proper times.\n\nA data buffer control module may itself be viewed as a processing step by a\nhigher-level control module; thus the control modules form a binary tree with\nelementary processing steps at the leaves of the tree.\n\nThe control modules are objects.  A considerable amount of flexibility can\nbe had by replacing implementations of a control module.  For example:\n* Merging of adjacent steps in the pipeline is done by replacing a control\n  module and its pair of processing-step modules with a single processing-\n  step module.  (Hence the possible merges are determined by the tree of\n  control modules.)\n* In some processing modes, a given interstep buffer need only be a \"strip\"\n  buffer large enough to accommodate the desired data chunk sizes.  In other\n  modes, a full-image buffer is needed and several passes are required.\n  The control module determines which kind of buffer is used and manipulates\n  virtual array buffers as needed.  One or both processing steps may be\n  unaware of the multi-pass behavior.\n\nIn theory, we might be able to make all of the data buffer controllers\ninterchangeable and provide just one set of implementations for all.  In\npractice, each one contains considerable special-case processing for its\nparticular job.  The buffer controller concept should be regarded as an\noverall system structuring principle, not as a complete description of the\ntask performed by any one controller.\n\n\n*** Compression object structure ***\n\nHere is a sketch of the logical structure of the JPEG compression library:\n\n                                                 |-- Colorspace conversion\n                  |-- Preprocessing controller --|\n                  |                              |-- Downsampling\nMain controller --|\n                  |                            |-- Forward DCT, quantize\n                  |-- Coefficient controller --|\n                                               |-- Entropy encoding\n\nThis sketch also describes the flow of control (subroutine calls) during\ntypical image data processing.  Each of the components shown in the diagram is\nan \"object\" which may have several different implementations available.  One\nor more source code files contain the actual implementation(s) of each object.\n\nThe objects shown above are:\n\n* Main controller: buffer controller for the subsampled-data buffer, which\n  holds the preprocessed input data.  This controller invokes preprocessing to\n  fill the subsampled-data buffer, and JPEG compression to empty it.  There is\n  usually no need for a full-image buffer here; a strip buffer is adequate.\n\n* Preprocessing controller: buffer controller for the downsampling input data\n  buffer, which lies between colorspace conversion and downsampling.  Note\n  that a unified conversion/downsampling module would probably replace this\n  controller entirely.\n\n* Colorspace conversion: converts application image data into the desired\n  JPEG color space; also changes the data from pixel-interleaved layout to\n  separate component planes.  Processes one pixel row at a time.\n\n* Downsampling: performs reduction of chroma components as required.\n  Optionally may perform pixel-level smoothing as well.  Processes a \"row\n  group\" at a time, where a row group is defined as Vmax pixel rows of each\n  component before downsampling, and Vk sample rows afterwards (remember Vk\n  differs across components).  Some downsampling or smoothing algorithms may\n  require context rows above and below the current row group; the\n  preprocessing controller is responsible for supplying these rows via proper\n  buffering.  The downsampler is responsible for edge expansion at the right\n  edge (i.e., extending each sample row to a multiple of block_size samples);\n  but the preprocessing controller is responsible for vertical edge expansion\n  (i.e., duplicating the bottom sample row as needed to make a multiple of\n  block_size rows).\n\n* Coefficient controller: buffer controller for the DCT-coefficient data.\n  This controller handles MCU assembly, including insertion of dummy DCT\n  blocks when needed at the right or bottom edge.  When performing\n  Huffman-code optimization or emitting a multiscan JPEG file, this\n  controller is responsible for buffering the full image.  The equivalent of\n  one fully interleaved MCU row of subsampled data is processed per call,\n  even when the JPEG file is noninterleaved.\n\n* Forward DCT and quantization: Perform DCT, quantize, and emit coefficients.\n  Works on one or more DCT blocks at a time.  (Note: the coefficients are now\n  emitted in normal array order, which the entropy encoder is expected to\n  convert to zigzag order as necessary.  Prior versions of the IJG code did\n  the conversion to zigzag order within the quantization step.)\n\n* Entropy encoding: Perform Huffman or arithmetic entropy coding and emit the\n  coded data to the data destination module.  Works on one MCU per call.\n  For progressive JPEG, the same DCT blocks are fed to the entropy coder\n  during each pass, and the coder must emit the appropriate subset of\n  coefficients.\n\nIn addition to the above objects, the compression library includes these\nobjects:\n\n* Master control: determines the number of passes required, controls overall\n  and per-pass initialization of the other modules.\n\n* Marker writing: generates JPEG markers (except for RSTn, which is emitted\n  by the entropy encoder when needed).\n\n* Data destination manager: writes the output JPEG datastream to its final\n  destination (e.g., a file).  The destination manager supplied with the\n  library knows how to write to a stdio stream or to a memory buffer;\n  for other behaviors, the surrounding application may provide its own\n  destination manager.\n\n* Memory manager: allocates and releases memory, controls virtual arrays\n  (with backing store management, where required).\n\n* Error handler: performs formatting and output of error and trace messages;\n  determines handling of nonfatal errors.  The surrounding application may\n  override some or all of this object's methods to change error handling.\n\n* Progress monitor: supports output of \"percent-done\" progress reports.\n  This object represents an optional callback to the surrounding application:\n  if wanted, it must be supplied by the application.\n\nThe error handler, destination manager, and progress monitor objects are\ndefined as separate objects in order to simplify application-specific\ncustomization of the JPEG library.  A surrounding application may override\nindividual methods or supply its own all-new implementation of one of these\nobjects.  The object interfaces for these objects are therefore treated as\npart of the application interface of the library, whereas the other objects\nare internal to the library.\n\nThe error handler and memory manager are shared by JPEG compression and\ndecompression; the progress monitor, if used, may be shared as well.\n\n\n*** Decompression object structure ***\n\nHere is a sketch of the logical structure of the JPEG decompression library:\n\n                                               |-- Entropy decoding\n                  |-- Coefficient controller --|\n                  |                            |-- Dequantize, Inverse DCT\nMain controller --|\n                  |                               |-- Upsampling\n                  |-- Postprocessing controller --|   |-- Colorspace conversion\n                                                  |-- Color quantization\n                                                  |-- Color precision reduction\n\nAs before, this diagram also represents typical control flow.  The objects\nshown are:\n\n* Main controller: buffer controller for the subsampled-data buffer, which\n  holds the output of JPEG decompression proper.  This controller's primary\n  task is to feed the postprocessing procedure.  Some upsampling algorithms\n  may require context rows above and below the current row group; when this\n  is true, the main controller is responsible for managing its buffer so as\n  to make context rows available.  In the current design, the main buffer is\n  always a strip buffer; a full-image buffer is never required.\n\n* Coefficient controller: buffer controller for the DCT-coefficient data.\n  This controller handles MCU disassembly, including deletion of any dummy\n  DCT blocks at the right or bottom edge.  When reading a multiscan JPEG\n  file, this controller is responsible for buffering the full image.\n  (Buffering DCT coefficients, rather than samples, is necessary to support\n  progressive JPEG.)  The equivalent of one fully interleaved MCU row of\n  subsampled data is processed per call, even when the source JPEG file is\n  noninterleaved.\n\n* Entropy decoding: Read coded data from the data source module and perform\n  Huffman or arithmetic entropy decoding.  Works on one MCU per call.\n  For progressive JPEG decoding, the coefficient controller supplies the prior\n  coefficients of each MCU (initially all zeroes), which the entropy decoder\n  modifies in each scan.\n\n* Dequantization and inverse DCT: like it says.  Note that the coefficients\n  buffered by the coefficient controller have NOT been dequantized; we\n  merge dequantization and inverse DCT into a single step for speed reasons.\n  When scaled-down output is asked for, simplified DCT algorithms may be used\n  that need fewer coefficients and emit fewer samples per DCT block, not the\n  full 8x8.  Works on one DCT block at a time.\n\n* Postprocessing controller: buffer controller for the color quantization\n  input buffer, when quantization is in use.  (Without quantization, this\n  controller just calls the upsampler.)  For two-pass quantization, this\n  controller is responsible for buffering the full-image data.\n\n* Upsampling: restores chroma components to full size.  (May support more\n  general output rescaling, too.  Note that if undersized DCT outputs have\n  been emitted by the DCT module, this module must adjust so that properly\n  sized outputs are created.)  Works on one row group at a time.  This module\n  also calls the color conversion module, so its top level is effectively a\n  buffer controller for the upsampling->color conversion buffer.  However, in\n  all but the highest-quality operating modes, upsampling and color\n  conversion are likely to be merged into a single step.\n\n* Colorspace conversion: convert from JPEG color space to output color space,\n  and change data layout from separate component planes to pixel-interleaved.\n  Works on one pixel row at a time.\n\n* Color quantization: reduce the data to colormapped form, using either an\n  externally specified colormap or an internally generated one.  This module\n  is not used for full-color output.  Works on one pixel row at a time; may\n  require two passes to generate a color map.  Note that the output will\n  always be a single component representing colormap indexes.  In the current\n  design, the output values are JSAMPLEs, so an 8-bit compilation cannot\n  quantize to more than 256 colors.  This is unlikely to be a problem in\n  practice.\n\n* Color reduction: this module handles color precision reduction, e.g.,\n  generating 15-bit color (5 bits/primary) from JPEG's 24-bit output.\n  Not quite clear yet how this should be handled... should we merge it with\n  colorspace conversion???\n\nNote that some high-speed operating modes might condense the entire\npostprocessing sequence to a single module (upsample, color convert, and\nquantize in one step).\n\nIn addition to the above objects, the decompression library includes these\nobjects:\n\n* Master control: determines the number of passes required, controls overall\n  and per-pass initialization of the other modules.  This is subdivided into\n  input and output control: jdinput.c controls only input-side processing,\n  while jdmaster.c handles overall initialization and output-side control.\n\n* Marker reading: decodes JPEG markers (except for RSTn).\n\n* Data source manager: supplies the input JPEG datastream.  The source\n  manager supplied with the library knows how to read from a stdio stream\n  or from a memory buffer;  for other behaviors, the surrounding application\n  may provide its own source manager.\n\n* Memory manager: same as for compression library.\n\n* Error handler: same as for compression library.\n\n* Progress monitor: same as for compression library.\n\nAs with compression, the data source manager, error handler, and progress\nmonitor are candidates for replacement by a surrounding application.\n\n\n*** Decompression input and output separation ***\n\nTo support efficient incremental display of progressive JPEG files, the\ndecompressor is divided into two sections that can run independently:\n\n1. Data input includes marker parsing, entropy decoding, and input into the\n   coefficient controller's DCT coefficient buffer.  Note that this\n   processing is relatively cheap and fast.\n\n2. Data output reads from the DCT coefficient buffer and performs the IDCT\n   and all postprocessing steps.\n\nFor a progressive JPEG file, the data input processing is allowed to get\narbitrarily far ahead of the data output processing.  (This occurs only\nif the application calls jpeg_consume_input(); otherwise input and output\nrun in lockstep, since the input section is called only when the output\nsection needs more data.)  In this way the application can avoid making\nextra display passes when data is arriving faster than the display pass\ncan run.  Furthermore, it is possible to abort an output pass without\nlosing anything, since the coefficient buffer is read-only as far as the\noutput section is concerned.  See libjpeg.txt for more detail.\n\nA full-image coefficient array is only created if the JPEG file has multiple\nscans (or if the application specifies buffered-image mode anyway).  When\nreading a single-scan file, the coefficient controller normally creates only\na one-MCU buffer, so input and output processing must run in lockstep in this\ncase.  jpeg_consume_input() is effectively a no-op in this situation.\n\nThe main impact of dividing the decompressor in this fashion is that we must\nbe very careful with shared variables in the cinfo data structure.  Each\nvariable that can change during the course of decompression must be\nclassified as belonging to data input or data output, and each section must\nlook only at its own variables.  For example, the data output section may not\ndepend on any of the variables that describe the current scan in the JPEG\nfile, because these may change as the data input section advances into a new\nscan.\n\nThe progress monitor is (somewhat arbitrarily) defined to treat input of the\nfile as one pass when buffered-image mode is not used, and to ignore data\ninput work completely when buffered-image mode is used.  Note that the\nlibrary has no reliable way to predict the number of passes when dealing\nwith a progressive JPEG file, nor can it predict the number of output passes\nin buffered-image mode.  So the work estimate is inherently bogus anyway.\n\nNo comparable division is currently made in the compression library, because\nthere isn't any real need for it.\n\n\n*** Data formats ***\n\nArrays of pixel sample values use the following data structure:\n\n    typedef something JSAMPLE;\t\ta pixel component value, 0..MAXJSAMPLE\n    typedef JSAMPLE *JSAMPROW;\t\tptr to a row of samples\n    typedef JSAMPROW *JSAMPARRAY;\tptr to a list of rows\n    typedef JSAMPARRAY *JSAMPIMAGE;\tptr to a list of color-component arrays\n\nThe basic element type JSAMPLE will typically be one of unsigned char,\n(signed) char, or short.  Short will be used if samples wider than 8 bits are\nto be supported (this is a compile-time option).  Otherwise, unsigned char is\nused if possible.  If the compiler only supports signed chars, then it is\nnecessary to mask off the value when reading.  Thus, all reads of JSAMPLE\nvalues must be coded as \"GETJSAMPLE(value)\", where the macro will be defined\nas \"((value) & 0xFF)\" on signed-char machines and \"((int) (value))\" elsewhere.\n\nWith these conventions, JSAMPLE values can be assumed to be >= 0.  This helps\nsimplify correct rounding during downsampling, etc.  The JPEG standard's\nspecification that sample values run from -128..127 is accommodated by\nsubtracting 128 from the sample value in the DCT step.  Similarly, during\ndecompression the output of the IDCT step will be immediately shifted back to\n0..255.  (NB: different values are required when 12-bit samples are in use.\nThe code is written in terms of MAXJSAMPLE and CENTERJSAMPLE, which will be\ndefined as 255 and 128 respectively in an 8-bit implementation, and as 4095\nand 2048 in a 12-bit implementation.)\n\nWe use a pointer per row, rather than a two-dimensional JSAMPLE array.  This\nchoice costs only a small amount of memory and has several benefits:\n* Code using the data structure doesn't need to know the allocated width of\n  the rows.  This simplifies edge expansion/compression, since we can work\n  in an array that's wider than the logical picture width.\n* Indexing doesn't require multiplication; this is a performance win on many\n  machines.\n* Arrays with more than 64K total elements can be supported even on machines\n  where malloc() cannot allocate chunks larger than 64K.\n* The rows forming a component array may be allocated at different times\n  without extra copying.  This trick allows some speedups in smoothing steps\n  that need access to the previous and next rows.\n\nNote that each color component is stored in a separate array; we don't use the\ntraditional layout in which the components of a pixel are stored together.\nThis simplifies coding of modules that work on each component independently,\nbecause they don't need to know how many components there are.  Furthermore,\nwe can read or write each component to a temporary file independently, which\nis helpful when dealing with noninterleaved JPEG files.\n\nIn general, a specific sample value is accessed by code such as\n\tGETJSAMPLE(image[colorcomponent][row][col])\nwhere col is measured from the image left edge, but row is measured from the\nfirst sample row currently in memory.  Either of the first two indexings can\nbe precomputed by copying the relevant pointer.\n\n\nSince most image-processing applications prefer to work on images in which\nthe components of a pixel are stored together, the data passed to or from the\nsurrounding application uses the traditional convention: a single pixel is\nrepresented by N consecutive JSAMPLE values, and an image row is an array of\n(# of color components)*(image width) JSAMPLEs.  One or more rows of data can\nbe represented by a pointer of type JSAMPARRAY in this scheme.  This scheme is\nconverted to component-wise storage inside the JPEG library.  (Applications\nthat want to skip JPEG preprocessing or postprocessing will have to contend\nwith component-wise storage.)\n\n\nArrays of DCT-coefficient values use the following data structure:\n\n    typedef short JCOEF;\t\ta 16-bit signed integer\n    typedef JCOEF JBLOCK[DCTSIZE2];\tan 8x8 block of coefficients\n    typedef JBLOCK *JBLOCKROW;\t\tptr to one horizontal row of 8x8 blocks\n    typedef JBLOCKROW *JBLOCKARRAY;\tptr to a list of such rows\n    typedef JBLOCKARRAY *JBLOCKIMAGE;\tptr to a list of color component arrays\n\nThe underlying type is at least a 16-bit signed integer; while \"short\" is big\nenough on all machines of interest, on some machines it is preferable to use\n\"int\" for speed reasons, despite the storage cost.  Coefficients are grouped\ninto 8x8 blocks (but we always use #defines DCTSIZE and DCTSIZE2 rather than\n\"8\" and \"64\").\n\nThe contents of a coefficient block may be in either \"natural\" or zigzagged\norder, and may be true values or divided by the quantization coefficients,\ndepending on where the block is in the processing pipeline.  In the current\nlibrary, coefficient blocks are kept in natural order everywhere; the entropy\ncodecs zigzag or dezigzag the data as it is written or read.  The blocks\ncontain quantized coefficients everywhere outside the DCT/IDCT subsystems.\n(This latter decision may need to be revisited to support variable\nquantization a la JPEG Part 3.)\n\nNotice that the allocation unit is now a row of 8x8 coefficient blocks,\ncorresponding to block_size rows of samples.  Otherwise the structure\nis much the same as for samples, and for the same reasons.\n\nOn machines where malloc() can't handle a request bigger than 64Kb, this data\nstructure limits us to rows of less than 512 JBLOCKs, or a picture width of\n4000+ pixels.  This seems an acceptable restriction.\n\n\nOn 80x86 machines, the bottom-level pointer types (JSAMPROW and JBLOCKROW)\nmust be declared as \"far\" pointers, but the upper levels can be \"near\"\n(implying that the pointer lists are allocated in the DS segment).\nWe use a #define symbol FAR, which expands to the \"far\" keyword when\ncompiling on 80x86 machines and to nothing elsewhere.\n\n\n*** Suspendable processing ***\n\nIn some applications it is desirable to use the JPEG library as an\nincremental, memory-to-memory filter.  In this situation the data source or\ndestination may be a limited-size buffer, and we can't rely on being able to\nempty or refill the buffer at arbitrary times.  Instead the application would\nlike to have control return from the library at buffer overflow/underrun, and\nthen resume compression or decompression at a later time.\n\nThis scenario is supported for simple cases.  (For anything more complex, we\nrecommend that the application \"bite the bullet\" and develop real multitasking\ncapability.)  The libjpeg.txt file goes into more detail about the usage and\nlimitations of this capability; here we address the implications for library\nstructure.\n\nThe essence of the problem is that the entropy codec (coder or decoder) must\nbe prepared to stop at arbitrary times.  In turn, the controllers that call\nthe entropy codec must be able to stop before having produced or consumed all\nthe data that they normally would handle in one call.  That part is reasonably\nstraightforward: we make the controller call interfaces include \"progress\ncounters\" which indicate the number of data chunks successfully processed, and\nwe require callers to test the counter rather than just assume all of the data\nwas processed.\n\nRather than trying to restart at an arbitrary point, the current Huffman\ncodecs are designed to restart at the beginning of the current MCU after a\nsuspension due to buffer overflow/underrun.  At the start of each call, the\ncodec's internal state is loaded from permanent storage (in the JPEG object\nstructures) into local variables.  On successful completion of the MCU, the\npermanent state is updated.  (This copying is not very expensive, and may even\nlead to *improved* performance if the local variables can be registerized.)\nIf a suspension occurs, the codec simply returns without updating the state,\nthus effectively reverting to the start of the MCU.  Note that this implies\nleaving some data unprocessed in the source/destination buffer (ie, the\ncompressed partial MCU).  The data source/destination module interfaces are\nspecified so as to make this possible.  This also implies that the data buffer\nmust be large enough to hold a worst-case compressed MCU; a couple thousand\nbytes should be enough.\n\nIn a successive-approximation AC refinement scan, the progressive Huffman\ndecoder has to be able to undo assignments of newly nonzero coefficients if it\nsuspends before the MCU is complete, since decoding requires distinguishing\npreviously-zero and previously-nonzero coefficients.  This is a bit tedious\nbut probably won't have much effect on performance.  Other variants of Huffman\ndecoding need not worry about this, since they will just store the same values\nagain if forced to repeat the MCU.\n\nThis approach would probably not work for an arithmetic codec, since its\nmodifiable state is quite large and couldn't be copied cheaply.  Instead it\nwould have to suspend and resume exactly at the point of the buffer end.\n\nThe JPEG marker reader is designed to cope with suspension at an arbitrary\npoint.  It does so by backing up to the start of the marker parameter segment,\nso the data buffer must be big enough to hold the largest marker of interest.\nAgain, a couple KB should be adequate.  (A special \"skip\" convention is used\nto bypass COM and APPn markers, so these can be larger than the buffer size\nwithout causing problems; otherwise a 64K buffer would be needed in the worst\ncase.)\n\nThe JPEG marker writer currently does *not* cope with suspension.\nWe feel that this is not necessary; it is much easier simply to require\nthe application to ensure there is enough buffer space before starting.  (An\nempty 2K buffer is more than sufficient for the header markers; and ensuring\nthere are a dozen or two bytes available before calling jpeg_finish_compress()\nwill suffice for the trailer.)  This would not work for writing multi-scan\nJPEG files, but we simply do not intend to support that capability with\nsuspension.\n\n\n*** Memory manager services ***\n\nThe JPEG library's memory manager controls allocation and deallocation of\nmemory, and it manages large \"virtual\" data arrays on machines where the\noperating system does not provide virtual memory.  Note that the same\nmemory manager serves both compression and decompression operations.\n\nIn all cases, allocated objects are tied to a particular compression or\ndecompression master record, and they will be released when that master\nrecord is destroyed.\n\nThe memory manager does not provide explicit deallocation of objects.\nInstead, objects are created in \"pools\" of free storage, and a whole pool\ncan be freed at once.  This approach helps prevent storage-leak bugs, and\nit speeds up operations whenever malloc/free are slow (as they often are).\nThe pools can be regarded as lifetime identifiers for objects.  Two\npools/lifetimes are defined:\n  * JPOOL_PERMANENT\tlasts until master record is destroyed\n  * JPOOL_IMAGE\t\tlasts until done with image (JPEG datastream)\nPermanent lifetime is used for parameters and tables that should be carried\nacross from one datastream to another; this includes all application-visible\nparameters.  Image lifetime is used for everything else.  (A third lifetime,\nJPOOL_PASS = one processing pass, was originally planned.  However it was\ndropped as not being worthwhile.  The actual usage patterns are such that the\npeak memory usage would be about the same anyway; and having per-pass storage\nsubstantially complicates the virtual memory allocation rules --- see below.)\n\nThe memory manager deals with three kinds of object:\n1. \"Small\" objects.  Typically these require no more than 10K-20K total.\n2. \"Large\" objects.  These may require tens to hundreds of K depending on\n   image size.  Semantically they behave the same as small objects, but we\n   distinguish them for two reasons:\n     * On MS-DOS machines, large objects are referenced by FAR pointers,\n       small objects by NEAR pointers.\n     * Pool allocation heuristics may differ for large and small objects.\n   Note that individual \"large\" objects cannot exceed the size allowed by\n   type size_t, which may be 64K or less on some machines.\n3. \"Virtual\" objects.  These are large 2-D arrays of JSAMPLEs or JBLOCKs\n   (typically large enough for the entire image being processed).  The\n   memory manager provides stripwise access to these arrays.  On machines\n   without virtual memory, the rest of the array may be swapped out to a\n   temporary file.\n\n(Note: JSAMPARRAY and JBLOCKARRAY data structures are a combination of large\nobjects for the data proper and small objects for the row pointers.  For\nconvenience and speed, the memory manager provides single routines to create\nthese structures.  Similarly, virtual arrays include a small control block\nand a JSAMPARRAY or JBLOCKARRAY working buffer, all created with one call.)\n\nIn the present implementation, virtual arrays are only permitted to have image\nlifespan.  (Permanent lifespan would not be reasonable, and pass lifespan is\nnot very useful since a virtual array's raison d'etre is to store data for\nmultiple passes through the image.)  We also expect that only \"small\" objects\nwill be given permanent lifespan, though this restriction is not required by\nthe memory manager.\n\nIn a non-virtual-memory machine, some performance benefit can be gained by\nmaking the in-memory buffers for virtual arrays be as large as possible.\n(For small images, the buffers might fit entirely in memory, so blind\nswapping would be very wasteful.)  The memory manager will adjust the height\nof the buffers to fit within a prespecified maximum memory usage.  In order\nto do this in a reasonably optimal fashion, the manager needs to allocate all\nof the virtual arrays at once.  Therefore, there isn't a one-step allocation\nroutine for virtual arrays; instead, there is a \"request\" routine that simply\nallocates the control block, and a \"realize\" routine (called just once) that\ndetermines space allocation and creates all of the actual buffers.  The\nrealize routine must allow for space occupied by non-virtual large objects.\n(We don't bother to factor in the space needed for small objects, on the\ngrounds that it isn't worth the trouble.)\n\nTo support all this, we establish the following protocol for doing business\nwith the memory manager:\n  1. Modules must request virtual arrays (which may have only image lifespan)\n     during the initial setup phase, i.e., in their jinit_xxx routines.\n  2. All \"large\" objects (including JSAMPARRAYs and JBLOCKARRAYs) must also be\n     allocated during initial setup.\n  3. realize_virt_arrays will be called at the completion of initial setup.\n     The above conventions ensure that sufficient information is available\n     for it to choose a good size for virtual array buffers.\nSmall objects of any lifespan may be allocated at any time.  We expect that\nthe total space used for small objects will be small enough to be negligible\nin the realize_virt_arrays computation.\n\nIn a virtual-memory machine, we simply pretend that the available space is\ninfinite, thus causing realize_virt_arrays to decide that it can allocate all\nthe virtual arrays as full-size in-memory buffers.  The overhead of the\nvirtual-array access protocol is very small when no swapping occurs.\n\nA virtual array can be specified to be \"pre-zeroed\"; when this flag is set,\nnever-yet-written sections of the array are set to zero before being made\navailable to the caller.  If this flag is not set, never-written sections\nof the array contain garbage.  (This feature exists primarily because the\nequivalent logic would otherwise be needed in jdcoefct.c for progressive\nJPEG mode; we may as well make it available for possible other uses.)\n\nThe first write pass on a virtual array is required to occur in top-to-bottom\norder; read passes, as well as any write passes after the first one, may\naccess the array in any order.  This restriction exists partly to simplify\nthe virtual array control logic, and partly because some file systems may not\nsupport seeking beyond the current end-of-file in a temporary file.  The main\nimplication of this restriction is that rearrangement of rows (such as\nconverting top-to-bottom data order to bottom-to-top) must be handled while\nreading data out of the virtual array, not while putting it in.\n\n\n*** Memory manager internal structure ***\n\nTo isolate system dependencies as much as possible, we have broken the\nmemory manager into two parts.  There is a reasonably system-independent\n\"front end\" (jmemmgr.c) and a \"back end\" that contains only the code\nlikely to change across systems.  All of the memory management methods\noutlined above are implemented by the front end.  The back end provides\nthe following routines for use by the front end (none of these routines\nare known to the rest of the JPEG code):\n\njpeg_mem_init, jpeg_mem_term\tsystem-dependent initialization/shutdown\n\njpeg_get_small, jpeg_free_small\tinterface to malloc and free library routines\n\t\t\t\t(or their equivalents)\n\njpeg_get_large, jpeg_free_large\tinterface to FAR malloc/free in MSDOS machines;\n\t\t\t\telse usually the same as\n\t\t\t\tjpeg_get_small/jpeg_free_small\n\njpeg_mem_available\t\testimate available memory\n\njpeg_open_backing_store\t\tcreate a backing-store object\n\nread_backing_store,\t\tmanipulate a backing-store object\nwrite_backing_store,\nclose_backing_store\n\nOn some systems there will be more than one type of backing-store object\n(specifically, in MS-DOS a backing store file might be an area of extended\nmemory as well as a disk file).  jpeg_open_backing_store is responsible for\nchoosing how to implement a given object.  The read/write/close routines\nare method pointers in the structure that describes a given object; this\nlets them be different for different object types.\n\nIt may be necessary to ensure that backing store objects are explicitly\nreleased upon abnormal program termination.  For example, MS-DOS won't free\nextended memory by itself.  To support this, we will expect the main program\nor surrounding application to arrange to call self_destruct (typically via\njpeg_destroy) upon abnormal termination.  This may require a SIGINT signal\nhandler or equivalent.  We don't want to have the back end module install its\nown signal handler, because that would pre-empt the surrounding application's\nability to control signal handling.\n\nThe IJG distribution includes several memory manager back end implementations.\nUsually the same back end should be suitable for all applications on a given\nsystem, but it is possible for an application to supply its own back end at\nneed.\n\n\n*** Implications of DNL marker ***\n\nSome JPEG files may use a DNL marker to postpone definition of the image\nheight (this would be useful for a fax-like scanner's output, for instance).\nIn these files the SOF marker claims the image height is 0, and you only\nfind out the true image height at the end of the first scan.\n\nWe could read these files as follows:\n1. Upon seeing zero image height, replace it by 65535 (the maximum allowed).\n2. When the DNL is found, update the image height in the global image\n   descriptor.\nThis implies that control modules must avoid making copies of the image\nheight, and must re-test for termination after each MCU row.  This would\nbe easy enough to do.\n\nIn cases where image-size data structures are allocated, this approach will\nresult in very inefficient use of virtual memory or much-larger-than-necessary\ntemporary files.  This seems acceptable for something that probably won't be a\nmainstream usage.  People might have to forgo use of memory-hogging options\n(such as two-pass color quantization or noninterleaved JPEG files) if they\nwant efficient conversion of such files.  (One could improve efficiency by\ndemanding a user-supplied upper bound for the height, less than 65536; in most\ncases it could be much less.)\n\nThe standard also permits the SOF marker to overestimate the image height,\nwith a DNL to give the true, smaller height at the end of the first scan.\nThis would solve the space problems if the overestimate wasn't too great.\nHowever, it implies that you don't even know whether DNL will be used.\n\nThis leads to a couple of very serious objections:\n1. Testing for a DNL marker must occur in the inner loop of the decompressor's\n   Huffman decoder; this implies a speed penalty whether the feature is used\n   or not.\n2. There is no way to hide the last-minute change in image height from an\n   application using the decoder.  Thus *every* application using the IJG\n   library would suffer a complexity penalty whether it cared about DNL or\n   not.\nWe currently do not support DNL because of these problems.\n\nA different approach is to insist that DNL-using files be preprocessed by a\nseparate program that reads ahead to the DNL, then goes back and fixes the SOF\nmarker.  This is a much simpler solution and is probably far more efficient.\nEven if one wants piped input, buffering the first scan of the JPEG file needs\na lot smaller temp file than is implied by the maximum-height method.  For\nthis approach we'd simply treat DNL as a no-op in the decompressor (at most,\ncheck that it matches the SOF image height).\n\nWe will not worry about making the compressor capable of outputting DNL.\nSomething similar to the first scheme above could be applied if anyone ever\nwants to make that work.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/testimg.ppm",
    "content": "P6\n227 149\n255\n0/-0/-10.21/51.51.62/72.83/83/83/:3-:3-:3-:3-:3-:2/91.91.80-80-91.91.:2/80-80-80-80-80-80-80-80-6.+6.+6.+5-*5-*4,)4,)4,)4,)4,)4,)4,)4,)4,)4,)4,).+$/,%/,%0-&1.'2/(30)30)63,63,74-85.85.96/:70:70A;/B<0D>2F@2IA4JB5KC6KD4MD5MD5MD3NB2OC3OC3PD4QE5T>1Y?2b@4nB5}E6G8G9E7F9F9E8F;F>F?G@G@CNCLCLDKDIBF>B<A;A9@9?;@>@?@?<=;@.@.@.?-?-@-?-?-@,A.A-B,A*A)@*A*?/?/?/>,>,<+<+<+?+?+=*=*=*>+?+@,?:>7=4?1B3D3D3D4?/@2E8H;H9mB2T8*D3#:659549547326216005//50-72/72/72/61-61-50,50,50,.0-.0-.0-//-//-0/-2.-3--5,-4+,4*+4(*7(+=.1E69L<?n@B|HJMNNOVZclns|}|pz`aTLuRCjSKcOG_MH\\TR`fdo|}{|jhgUXWERO>UPdUPdUPd0/-0/-10.10.40-51.62/72.83/83/83/:3-:3-:3-:3-:3-91.91.80-80-80-80-91.91.80-80-80-80-80-80-80-80-6.+6.+5-*5-*5-*4,)4,)4,)5-*5-*5-*5-*5-*5-*5-*5-*/,%0-&0-&1.'2/(30)41*41*63,63,74-74-85.96/:70:70@:.A;/C=1E?3H@3IA4JB5JC3LC4LC4KB3MA1MA1NB2OC3PD4P>0U?1^A3jC4xD6D4D5B3B3@2@4B7C:E<F=G>AKAICIDHDGBD@D>C;A9@9?<??@@@@<=8@.@.?-?-?-?,?-@-@,@-A-A+A*@+@*A*?/?/>.>.>,=+<+<+>->*>*=*=*>+?,@-@8>5>3?1A3D4D3C4A2B6E8I;G:kA3S9*D4$<66;55:4493382271161.61.72/72/72/61-61-50,50,50,.0-.0-.0-//-//-0/-2.-2.-3--5,-4*+4(*5)+<-0C47I:=h<;vDCJILJST`hk{r{|ylv[\\QHsQBkOFaOFaNI_RN_[Yfnot~ojk[]\\JVUCXQaXQaXQa/.,/.,0/-10.40-40-51.51.72.72.72.92,92,92,92,92,91.80-7/,7/,7/,7/,80-91.80-80-80-80-80-80-80-80-6.+5-*5-*5-*4,)4,)4,)4,)5-*5-*5-*5-*5-*5-*5-*5-*1.'1.'2/(30)30)41*41*52+63,63,63,74-85.96/96/:70?9-@:.B<0D>2G?4H@3H@3H@3I@1I@1I@1K?1K?/L@0MA1NB2MA1QA2YB2dC2qC3|C2A2@0<+:+;,>0@4C8F=G>?E@FBGCFDFCEAD?D;@:?:@=@@@A=@;>7@-@-@-?,?,?->,?,?-@-@,A+A,@*A*@)?/>.>.>.=+=+=+<+=,=,<+=)>*>*?+@,B7?5>3>2A4C5D5C4D6F9I=I=F;gA4P:,B6&=77=77<66:4493383072/72/62/62/62/52-52-41,41,41,,1-,1-.0-.0-//-//-0/-2.-5//4..5,-4*+4*+9-/>24C79_83l?:|E@IBNKZ^ftnw~zsdmUUNEtO?lMBbPEcQHcMH^NK\\[[estx|xzlghXZ[KVTEZT`ZT`ZT`.-+/.,/.,0/-10.40-40-40-51.61-61-61-81+81+81+81+50-50-4/,4/,4/,4/,50-50-61.61.61.61.61.61.61.61.3.+3.+3.+2-*2-*2-*1,)1,)4/,4/,4/,4/,4/,4/,4/,4/,30+30+30+41,41,52-52-52-52-52-63.74/850850961961>8,?9-@:.B<0E=2E=2F>1F>1G=1G>/F=.I=/I=/J>0L@0L@0JD4NE4TD4^D3hE2sB1~A/>-9'9'9)<-@3E8I<J>@CACCEDECDAC@C>A;@:?:>=@A?B=A7>5@,@,@,?->,>,?,>-?-?,@-@,@+@*@)@(>.>.>.=-=-=-<*<*=+=+<*<*=+=,>->-B6?5?2@2B4C6B5B5F:H>K@J@|F:aA4K;.?9+@86@86?75>64:5294183073062/62/62/32.32-21,21,21,-2.-2.-2./1./1.00.00.10.5106005//5,-4+,6,-:01>45W6-b<3qA7}D9H@RQ_iis|zu~my^gRQMDyM?rN@dPEgQFfLC^GBVNLZ^^fjnquzvx}vzvwzokoa`bUWYKTUG]V^]V^]V^.-+.-+.-+/.,0/-10.3/,40-3/,4/+4/+4/+4/+6/)6/)6/)4/,4/,3.+3.+3.+3.+4/,4/,50-50-50-50-50-50-50-50-3.+3.+2-*2-*2-*1,)1,)1,)4/,4/,4/,4/,4/,4/,4/,4/,41,41,41,41,41,52-52-52-52-52-63.63.74/850961961<5+=6,?8.@9/B:/C;0C;0C;.D:.D:.D:.G;-H<.I=/J>0K?1GH6KH7PG6XG5aF3jD1uB/|?,;):';(=,B2G7K<M>DBDCDBEBC@@@>>:>:=9<;>?>B>C:A5?0@-?,?,?,>+>+>-?-?,?-?,?+?*?+?*>)?.?.>->->-=,=,=,=,=,=,=,<,=->.>.B4A4@1@3B5C7A8@7B;G?KCJ@uE;Y>3C9-78*@86@86?75>64=53:5294173062/43/43/32.23.12-12,12,,2.-2.-2.-2./1./1.00.00.3205105104..2,,4+,7./901P5*Y9,e>/n@1tB7|KGYcg~pxxs{js]eTTOGLAyPAjPAhMAeJA`GBYHEXKKWMPU^bc`fbcha`f\\Z`TWZOUYKWYL`WZ`WZ`WZ,,,,,,---.-+/.,0/-10.3/,2.+2.+3.*3.*3.*3.*3.*3.*3.+3.+2-*1,)1,)2-*3.+3.+3.+3.+3.+3.+3.+3.+3.+3.+2-*2-*2-*2-*1,)1,)1,)0+(3.+3.+3.+3.+3.+3.+3.+3.+41,41,41,41,41,41,41,41,41,52-52-63.74/850850850;4*<5+=6,>7-@7.A8/A9.A9.C9/C9-C9-F:.G;/H<.J>0K?1FI8GH6MH5TG6[F3dC0lA.t?-{<*;);*=,A1F5J:M=E@FAFAE@C?@>==9<:<9;;=?=B=D8A2>,@,@,?+>->->,>,>.>-?,?,>,?+>*>)?)>->->->-=,=,=,<+=,<+<+<+<+=.>/?0C2A2@2A5B9C:@:@9@9H@NGNEoG=R@4?;039-A75A75@64>63<4194083/74/63.43.34/23.13.02-02-02--3/-3/-3/.3/.3/02/02/11/11/32032040/2.-1-,4..5//H4)M5)X8+a<,f>2nGBzYblu{|u|mubi[[SLLBQAnN?jI=cH>`HB^FCX@BO<?HBGJFLJJQJJQIIQFKQGOUISYMaXSaXSaXS++++++,,,---/.,/.,0/-0/-1-*1-*1-*2-)2-)2-)2-)2-)2-*2-*1,)1,)1,)1,)2-*2-*1,)1,)1,)1,)1,)1,)1,)1,)2-*2-*2-*1,)1,)1,)0+(0+(3.+3.+3.+3.+3.+3.+3.+3.+41,41,41,30+30+30+30+30+41,41,52-63.74/74/850850:3+;4,<5-=6.?6-?6-?6-?6-B8.B8.C9/E9-G;/H<0J>2K?3DG6EF6KE5PD4VC2^C2e@.m>,v=,|;):);*=.B2F7I:D<F>G>F>E>C?@><>9:9:;<@<B;D6A/=)@-@-@-?,?,>.=->->,?.?-?,>,>*?*>)>->->-=,=,=,<-<-<-<-<,<,=-=0=0>1D2C1A3B6C:A<B=B=EAPJXPZOqSIVI@BD97A6A83@72?61=60<4194083/63.43.43.34.13.13.02-.3-.3--3/-3/-3/.3/.3/.3/02/02/00.11/22021/0/-/.,2.-3/.?0)C1'K3'T8,Z<2dGCw]hs|szkqedVSJCN>kK<gG;cG=`FB]DBX?AP;?H:BE?HGDMHGQIGQHJRGNVKRZOaYNaYNaYN++++++,,,,,,---/.,0/-0/-/.,1-*1-*1-*2-)2-)2-)2-)1-,0,+0,+/+*/+*0,+0,+1-,/+*/+*/+*/+*/+*/+*/+*/+*1-,1-,1-,0,+0,+/+*/+*/+*1-,1-,1-,1-,1-,1-,1-,1-,3/,3/,3/,3/,3/,3/,3/,3/,40-40-51.62/62/73084184192,:3-;4,<5->5.>5.>5.>5,B8/B8/C9/E8/G:1I<3J=4K?3EC6FB6IC5NB4TA3\\@2b>0h=-q<.w9*}8)7*:,=/B2D5E9F;G<H=H>F@C?@@:9:9=;A;D:E4A-?(A-A-@.@.?.>-?->/>.@.?.?->+?*>)>+>->->-=,=.=-=-=-</<.<.<.<.=0>1?2D2C1B4B6C;C>C>D?PJ[Te\\f]s_TYUJFNC>KA@70@72>71=6094.83-63,63.43.34.34.13.13..3-.3-.3--3/-3/-3/.3/.3/.3/.3/02/.0-00.22022000.0/-0/-10.8,,;,)B1*K7.S<4^IHtbnzʂyrwikXVGDI<gG<fD<aC>^C@[ABV>DP>EMGQSKWUQ^WU`XS_UR^TT^SV`UaZHaZHaZH,-/,-/------------.-+.-+/.,/.,1-*0,)0,)0,)/+(0+'/+*/+*/+*/+*/+*/+*/+*0,+/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*0,+0,+1-,1-,2.-1-,1-,1-,1-,1-,1-,1-,1-,0,)1-*2.+3/,3/,3/,3/,3/,3/,3/,3/,3/,40-51.62/73081+92,:3-;4.=4/>5.>5.>5.?4.?5,@6-C6.D7.F90G:1H;2F?5H@5J@6N@5R>3W<1\\:0a7+k9.t8-|8+9,;/=0?1?2@3B5D8E:G=F>D?B>?=A?D?E>C8C1B.B,A.@-?,?,=-=->.?.<,=,=+>-=,=+=*>*<+<+<+<,<,<,;-;-=/</</=0?1@4A5B6F3E4F7H>F@C>DAKGXRf]qfth|rfik^S_SCSHQJBLE=D=5<8/95,74-63,33+43.34.23-13.02--2,,1+,1+-2.-2.-2.-2.-2.-2./1./1.02/02/11/11/11/11/11/11/5*2;/3A32C4/J;6]OOymyӐ݂tzjn_bYZPHmHBdA>]>>X?AVBHVLU^U`bbqnn}xv|pulyoguh_k_T`Ta[Eb\\Fc]G,-/,-/,-/,-/---------.-+/.,.-+.-+0,)/+(/+(/+(/+(.*).*).*).*)/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*/+*0,+0,+0,+1-,1-,1-,1-,1-,1-,1-,1-,1-,1-,0,)0,)1-*2.+3/,3/,2.+2.+2.+2.+2.+2.+3/,40-51.62/80-91.:2/;30=4/>50>50=4-?4.?4.?4.B5-C6.E80G:2H;3H>5J=5L=6O>6Q=4V;2Z90_7/h8.p7.y6-8-9.;1<1>1@3A5B5E8E:F<E=C=C?D@F@F>F8C2B/C-B0A/@.?-?->->.>.=,=.=-=,=+>-=,>,=+=+<,<,<,;-;-<-</=/=1=1>4@6A7B8H7F7G:I@HBFAJFTMdZre~op~|mlteYgZJZOPLAKI=EC7@>2=:1:7.44*11)23+23-12,/1,/1,.0+.0+.0-/1./1./1./1./1./1./1./1.02/11/11/11/11/11/11/11/5*:9-9<15?53H?:^VTxszΐׄxpykten__yXZsSUjRWjU]j\\gmguvrv}vypsfteXfW_YA`ZBb\\D,-/,-/,-/,-/,-/---------.-+.-+.-+-,*/+(.*'.*'.*'.*+.*+.*+.*+-)*-)*-)*-)*/+,/+,/+,/+,/+,/+,/+,/+,.*+.*+/+,/+,/+,0,-0,-0,-0,-0,-0,-1-.1-.1-.1-.1-.0,+0,+1-,2.-2.-2.-2.-1-,1-,1-,1-,1-,2.-3/.40/51080-91.:2/;30=31=31=4/=4/?40?4.?4.A4.C60D7/F91G:2H;5J;6K<7N=6P;6S:5V72[60c60k6.t5,}7/9/:0<0<1@3@4@3A3C6C8D:C<F>G@HBH?E:C3B0B.B/A.@->->->->-?0<-=-=,=.>-=,=+=+<*<,<,;+;+<-;,;-<0<0<2>3?4A8C:D;K<H;H>JDIFKGSM_Vrgqz{wrocqbVdWPQCMN@HI;DD8@@4::055+/0(01)01+/0*/0+./*./*//-//-//-//-//-//-//-//-//-//-00.00.00.00.00.00.00.00.6*>6+;8.6;63HE>_^Yyz|Î˄}{||yq~o|n}oy|{j{iXiW\\V<^X>`Z@-.0-.0-.0-.0-.0-.0......---.-+-,*-,*,+).*'.*'.*',*++)*+)*+)*+)**()*()*(),*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*+-+,-+,-+,-+,.,-.,-.,-.,-/-./-./-./+*0,+1-,1-,1-,1-,0,+0,+0,+0,+0,+0,+1-,2.-3/.40/91/:20;31<42=31=31=31=31>3/>3/>3/@3-A4.C60D71E82G83H94I:5L:6M:6N94Q83T50^72e60o6/x8/90:/;1=1?4?4?2@1A2C5D7D:F<G>IAH>F:C4B0B.A.A.?->,>,=.=.=.<,<.=.=-<.=-=-<,;);+;+;+;,;,;-:,;/<1<1>5@7C:E<F=M>I<H>ICLGPL\\Tj^oyzym{lam_UYHQUDKO@EI:@D6;=057,13(01)/0*/.).-).-).-+/.,0/-/.,/.,/.,/.,/.,/.,/.,/.,0/-0/-0/-0/-0/-0/-0/-0/-8*A6):3-1961HJ=bfX{y}~k|iUfSXT7ZV9^Z=+/2+/2-.0-.0-.0-.0-.0...------.-+-,*-,*,+),+),+),*+,*+,*++)*+)**()*()*(),*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*+,*++)*+)*+)*,*+-+,-+,.,-.,-/-./-./-./+*0,+0,+0,+0,+0,+/+*.*)/+*/+*/+*/+*0,+1-,3/.40/91/:20;31<42=32=32<20<20=20=2.=2.?1.@2/A4.B5/C60D63C84D95G96G96H94K84N51V72_60h70r7/}:1<1=2>2?7?5?5?3A3C5D6E8E;F=G>F=D8B5@0@/A-A-?,>+<,<,=-=/<.<-=-<.<-<,<,<,;+:*:*:*:+:+:,:.;0<1=4?6B9D;G@HALAH?HAKGOLWQf]whw|}tqlte\\eRV_LMVCEL<?F6<@27;-68-01)00(.-(/+(/+(/+*2,,3--1-,1-,1-,1-,1-,1-,1-,1-,0/-0/-0/-0/-0/-0/-0/-0/-9*?5)73*-66*GL6_iPxn{xgzdQcMTS5VU7XW9,03,03,03,03./1./1./1///..........-+.-+.-+-,*-,*-+,-+,-+,,*++)**()*()*()+)*+)*+)*+)*+)*+)*+)*+)*,*+,*++)*+)*+)**()*()*(),*+,*+,*+-+,.,-.,-/-./-./+*/+*0,+0,+/+*/+*.*)-)(0,+0,+/+*0,+1-,2.-3/.40/:12:12;23<42=32<21<21;1/=20<1/<1->0-?1.@2/A30A30?61@72@93A96A96B94E74G51O61W6/a6/j8/u9.</=0>0>7>5?5@4B4C4C4D4B5C8E:E;C7@4?1?2A,?-=,=,<+<+<.<.;-</<.;-;,<,;-<-:*:*9):):+9+:+9-<1<3?5A8C<F?JBJEJAG@HCNJVR_Yper{~~zuszjcqZ]iSR^JHT@BK:>E5:@29<134,22*1.)/+(/*'0**3*+4+,1++1++1++1++1++1++1++0,+1-,1-,1-,1-,1-,1-,1-,/.,;(;5(23+(56$CL-\\hDt`wƤШɯʰ˯ɪ{wrdx]MaHQQ5QQ5RR6,03,03,03,03./1./1./1./1/////////0/-/.,/.,.-+.-+/-..,-.,--+,,*++)*+)**()+)*+)*+)*+)*+)*+)*+)*+)*+)*+)*+)**()*()*())'()'(+)*+)*,*+-+,.,-.,-/-./-./+*/+*/+*/+*/+*.*)-)(,('0,+0,+0,+0,+1-,2.-40/40/:12;23;23<34=32<21<21;10<1/<1/<1/=/,>0->0-?1.@2/;60;62;83<94=:5=:5?82A60F5.O4-W5+b6+n8,x:-<,<.:6<5=5@4A4B3B2@0?1@4B7B9@6?5=2?2@-?->,<+;*;,;-;-;,<.;-<-;.;-;,;,9)9)9)9*9*9+~8,}9,=1=4@7B9E>HCKFMHIAGAJFSO\\Xh`{ny~w{nixacr[ZhQP]IIUACL;>D6<?467/44,30+0+(1)'1()3)*5+,2)*2)*2)*2)*2)*0**0**0**1++1++0,+0,+0,+0,+0,+0,+;&57(/4-%46\u001e?I$Ue8pTk}ɓҔҰҮѭ̥{{tqk_sWJ^CMM1LL0KK/,03,03,03,03./1./1./1./10000000000/-0/-0/-/.,/.,0.//-./-..,--+,,*++)*+)*+)*+)*+)*+)*+)*+)*+)*+)*+)*+)*+)**()*())'()'((&'*()+)*,*+,*+-+,.,-/-./-./+*/+*/+*/+*.*)-)(,(',('1-,1-,1-,1-,2.-3/.40/510;23;23<34<34=34<21;10;10<1/<1/;0.=/.=/,>0-?1.?1.96/:729839839:4:94;83>71A2+I2*S2)^4(j6)s8*|:*~;+84:5=4@3B3A1@/>-<-=0@4A7@7>4=4=3@-?,=+<*;*;,;,<-;.<.;-;,:-;-;,;,9)9)9(9*9*8*~8,}9,>2?5@7C<G?IDMGOIICHDMJUTa^ngs||yql{dgv__nWXeQP\\HIRAAG9=@579.66.41,1,)1)'2()3)*4*+2)*2)*2)*2)*2)*2)*2)*0**1++1++1++0,+0,+0,+0,+0,+:&27(+4.\"47\u001c=H\u001eRb1l~Jbr|~{ƅ΅ɢɟȞ×~~vumldZnRG[?IL/GJ-DG*/0*/0*/0*01+01+01+21,21,32-63.63.63.52-50,4/+4/+8.,7/,6.+5-+4,*2-*1++0,-0,-.,/--/-,1,+0*+/)*.()./(0/(//(//(//(//)-.)-.*+/+,-,*-,(.-).-)-.(./)./)--/--/---.../-.0/-2.+3.+2-)4,)5.(7.)8/(;0*;1(<2)<5+=4+>5.>5.>5.=4-<3.<1-=2.<1-<1/;0.=/.>0/>0/?11H-&C1';5)2:++=-(=.-;.45-?-+H()R%(X((Z.+Z8.[A2\\G6wC-{B.C1A3?1;0:/8+;->.B1D0D0B.?,<*6383:2<1@1B0|A/|A/C2A1>1=0;/:.9-9-v:/|@5u=0n9)s@/s@/t<+{@0{<-?4D9H?LANBQCRCHKTRd]ue{lwsz|yk{awhea]\\zV[sS]mR[cLVTEPH=J;6G53B,/=&,:#+:#-9#/8\".#/-#-,$-,&*+))+-(.1'/2'/4'06&14'14'13'32(32(30(3.)-0,-0,)//'=>0WZErx\\gspqrrs{{z{~}|zvroi{e[jWLZIKO@CG8>B3/0*01+01+01+12,12,21,32-43.63.74/74/63.61-50,50,7/,7/,6.+6.,5-+2-*1++0,+0,-/-./-0--/-,1+*/)*.()-/(//(//(//(//)-/)-.*+.*+/+*-,*.-).-)/.*./)./)./)..0....../-./.,/.,1-*3.+3.*5.(6/)8/(90);0*<2)=3*>5,>5,>5.>5.>5.=4-<3,=2.=2.<1-;0.;0.;0.=/.>0/?10F/'D0)A3*=4+96-85.83-<1-?-+D*)K)(P*'U.)[4-_:1c?3s@+xA-A0?2?4;3:1;19.<->.A0B1B/A/@/93:3;2=1?0@0@/?/A1>0=0;/;.:-:,:,w9.x<1s9-n9)r?.s>.q9*u:,}=1@5E:H?K@MBPCQCDJQRd]vfp}w~w}oxag\\`VZU}XWyXWpSPbJKVECI;@A998340-0,+/+,.)--(,*,+)+***,+),-(,/)-2(03(03(02(02(10)1/*1-*1,+3,+32-12./0,)--%9:,TWBox[iolnpppw{xwy||{xuqnh{eYjWL[HGK<@D5:>/12,12,12,12,23-23-43.43.54/74/85085085083/72.61-80-80-7/,6.,6.,3.+2,,1-,1-./-.0.1..0--/,+0+*/*).1'//(//(//)-/)-/)-.*+.*+0,+0,+/.*/.*/.*0/*/0*/0*/////////0./0/-1-,1-*2-)4/+70*90+:1*<1+=3*>4+?5,?6-?6-@7.@70?6/>5.=4->3/=2.<1-;0.;0.;0.;0.<1/=20C2*E0+H/+L,-N+/M*.J*/E+.A-,@.*@/(C/(M/'Y0*d1-j30i;+o;-w;0=4<4;594:4;2=2>2@1A2A3B5C6=2=1>1>0>/=.=.=.<.;.:-9,;,;+~=+z=*}=3z<1v:/u;-x@1x@1v<.v;-?3B6F=H?JAKANCPDDHQQc^ugnt~}{ak[eXaV`W`W]QtVMiPC[E=RA6F9/<2*5-&1+%.)$-(1&*1&*1&*1&*1&*1(-2).1+//*0-+0,+0+,0),1(-1&.1&.14.24.0.*'**\"66*PUAmv[~ik~hjnn~mqx|zwvtuwyy}}ywspmh{eYkUL[HEG:=?28:-23-23-34.34.34.45/54/54/650961961:72:72:51940940:2/91.91.80-7/-4/,4/,3/.3/.3/01/01/00.1..0--/,,.2).2).2).0*.0*,0*,0*,/+*1-,1-*0/+0/+10+10+10+10+11111100010.10.2.+2.+3.*91.92,;2+<3,>4+@6-@6-A7.A8/A8/B90A8/A81@70>5.?4.=2.=2.<1-;0.;0.<1/=20=20?5,E2.O-.W(0]#/\\\"0W#/L'.C/.:3-55);5)E1(U.'c+*l*+e;/j;1s=3}<6;8;9;7:6>9?9B9C9B9B9A9@7B/B/@.@.>-<,:+9+8*8*9*9)<)z=(w?(t@(=3{7,x8,z</v;-w=/{A5{?4B7D:G=I@I@LBNFPHOLYSf[sbg}mzv{|~zmmiiegdefgce]~_Zw[PhPI_J@Q?8D60:/-5**/(),%7$(7$(5%(4%(1&*1(+/+,.,-*+-(,-'--%-/%-/$./$./$./1(+1+-0+(.+$88,PUAiqYve{hyf{in}mykzmrsq}o}p}s~t~v}w|x}zzwuqnjg{bWkRK]GGE9?=1:8,45/45/45/560560560761761872:72;83<94<94=84<73<73<41<41;30;3083072/61.61.5106216213122011/00.//-.4+.4+.4+.4+.2,.2,,2,,2,,3/,3/,3/,10,21,21,32-32-22222032032032.51.61-61-;4.<5-=4-@6-A7.B8/E8/E8/C:1C:1E;2D:1C90B71@5/@5/>3/>3/=2.=2.=20=20>31>31>7/C41O/2Y*2_%3`#2Y%1N+1B3077-39+68*?5)N1)]-)e+)c;3h<3r=7z=:<<<=;;;:;9>8A:C;C<B<@9?8E/D/C.@-=,<,9+9+6)7)9);)~=)w?(sA(qB(6/|/'8/?4w5)s5*}A6}C7E9G<I>J?K@LDOGSJycL~hSoYu]}biu|~|~|}{yn}lylwkwmtjogl~dbqZ[hTSZHIK=B@4=6,8/&5+\":&(8%'6&'2&&0(&-)(++)).*'+*&,*&,*'+*'+,)*,**,**,-#$2*(50,85,BC5UZFfpWn}^tcqbtexiwkshsiwmzmxlwkvlyq{u{w|wxuzwwtqomhd{_WkPJ^CFB9>:195,560560671671782782872872983<94=:5>;6>;6?:6>95>95?74?74>63=52;62:5294194184184195484373243132021/6-.6-.6-.6-.6-.4..4/,4/,40-40-40-52-32-32-43.43.431431542540841850940:5/=60?6/@7.B8/C9/F90G:1H;2F<3F<3F<3F<3E;2C90B71A60@5/@51>50=4/=4/>42?53?53=82A64I35Q16V.6U-5R/5J22A62::08<.9;-?9)H6*P4)U3)]2+c4.k62t76}77897978}75{:6|=8{?7@9@:@;?;|E0}D0C0A/=.;-:-9,8+9+:+<+{>+x?+uA+tB+2,2,LEXQA8|90F;J>yH:zJ<{M@|NA~NBPEUJYN_uNgwRtzX{^|bis|z||x~tyqvponpp}pxmskk~bgu\\_iQWZGPM<H@3B6*>0%:,+7,*5+)1,(-,'+.').((/().(+-*,,*/+*3)*6',7&,9&,2)$<3,E>4JF:QR@]bLgqVizXm]j\\j]pbqeodoerhukrhqitlxrzvyvyvvtwturokjfc|^UlOJ^BHA9@91;4,671782782782893893983:94:94=:5>;6?<7?<7@;7@;7@;7B:7B:7A96@85=84=84<73<73<74<74<74;74:6395284173080.80.80.80.80.80.61.61.61-52-52-52-63.63.54/54/540540651952:72=84=82@93?80A8/C90D:0E;1H;2I=1I=1H>4H>4H>4G=4F<3D:1B8/A60B71@70@72?61?61@72@72A83=84@85B86D97E:8G96G96E:4C90B90B:/B:-D;,F:*H;*H;*].&b0)n3/x7398;;<<>;A>A<?6}=4~;3;5=8>:~C3B3A2?2=1<0;/;/;.|=.{=.|>/|>/|>/}>/}>/.*;8kf~yZTC<LAN@tJ:qM=pQ?qR@tSB{VD[J_OUOeUz~[y_raofrkxovz~~}yyvrrrrt|svpspligeby\\\\lQU_GMP;ED0A<)>3-<3,92*41(01).1(+1'+0)/0*2/*6,*:*+@'+D%+G$+H#+A7+LC4WP@[XE`bLgmQiwVj{Wl[gWfWj^nananbrfrkohniqnwsyvxuutssutspnlicb{[TmMH`@MD=E<5@707827828938938939:4:94:94;:5>;6?<7@=8@=8A<8A<8A<8A<8A<8A<8@;7?:6>95>95=84>95>95>95>95=84<73:51940:0.:0.:0.91.91.91.91.72.61-61-63.63.63.74/74/74/540651961;83<94?:4@;5B;3A8/B90C9/E;1H<0I=1J>2K=2K>5K>5J=4J=4F<3E;2C90B8/B92B92A81@72@72@93A:4A:4?74>95=<7>?7?@8@@6D@5J=4J70N5.Q6-Q6+O8*M:+I<)H=)l3(r6,~;3@:DAHDJGLHQJMDD;;28-7-91;4?7?7=6<5=5=4|>3y?3vA3uA3uA3y?3}=3:38373%$<;{zhcG@K@wI:mN<gR=dU>fW@jX@r\\E}aLeQj{O{{Uw\\l`^_R\\M[O^muxx΅~}xurruuus{sxrqlphiadtW]gLVX@LJ3GB.L40H3.D3,?2*:1(70&40'40'81):/+?-+C++H(+M%-O$-Q#-PE1[P:d^FgfJilOnuTm{Wl~VkZgVgVm]papbrdvhrlokmipmwtyxwwtustutsqokicb{[TmMGa>SJCKB;F=69:49:49:49:49:4:;5=<7=<7=<7?<7@=8@=8A>9C>:D?;D?;E@<E@<E@<D?;D?9C>8C>8D=7B;5B;5B;5B;5B;5B;5A:4A:4A83A83A83@72@72>71>71>71<71<71;60:5/85085074/74/761961961:72<71=82A:2B;1C:1E;1F<2J>2K?3L@2N@3N@3M@7M@7L?6K>5I<3F<2E;2E;2B90A81A81?80?80?82@93@93<5/LE?IB:E<5OB:K:2J3+\\>6Z5-`5.`4+^/'\\0%b8,g@1gB2I;G;I?LAF>>7=6D;NDQEVHYKPB@5:0=49;9:675496@:{@8o?3oC6lB4m?2u:27435-3(1EEbaEDWUyvVOF<WGlS=f\\CedFgfHgbEm_DyeLnVdKp]phW]8K(D&H+L<WG\\Xenr|zف}ֆ؉wwxxxyyxmm~itagY{YMtLBpE<r;>d02b22\\31L)'D'#I2,J70F5.E2,E0+H0.I-,I)*O+-V24VK/`W:f_BgdEkoLu}Xu]oWjWlXn]q`sbubudveqksmsoqosrwxzzyzxyqrmjjghdazZTnKIc@TKBSJAPG>9:49:49:49:4:;5;<6>=8?>9>=8@=8A>9A>9B?:D?;D?;D?;FA;E@:E@:E@:D?9D?9E>8E>8E>8E>6E>6D=5C<4D;4D;4C:3B92B92B92B92A81A81@91@93>71<71;60;60:5/85.74-74-96196/96/;60<8/>:1A:0C:1C;0E;1G=1J>0L@2M?2NA1NA1N@5N@5M?6J=4I<3H;2E;1E;2C:1B90A81@91@91@91?;2?;2C:3G81I0,V..j68u99{;;ECD?H@I?G>JANHPLMKE3C2B4B6>36-7+<0C5@.@.E3F6E5H9N@KRGN@F9=8:?<A:r@5k?2uK=NC@:,-(08FK\\JIMM>=>?_\\XQ@5UDvbJa]@Z_?ekIonOshJ{fKkP]V][SZ<N'E\u001eD\u001fH!K(N.N9RF[M^O]O]S`akclgnkpnrstvuww{zwzuxotircn^k\\i`nRaJWGQDKFIk79F\u001d\u001bS2-L0,F2+I6/J91I;2M>7SD=]P.dY9ga?ifCnrMz[zbt^r]o]o^q^ubwcwcwcrmwrzvyw~}z|qqljhc`yYTnKJdAWQEVPDUOC8938938939:4;<6<=7?>9@?:@?:B?:C@;C@;C@;D?;D?;D?;FA;FA;FA;E@:E@:G@:G@8F?7IB:HA9H?8G>5F=4E<3E<3D;2D:1D:1D:1C:1D;2D;4D;4C<4?80?80<71;60:5/:5/94.94.96/96/96/;7.<8/@9/A:0C;0E;1F<0I=/K?1M@0M@0NA1M@0N@5M?4L>3K=2I<3H;2E;1D:0C:1C:1A:0A:2?;2@<3@<3A=4SE<P40g35AGJWS`[f^cB>I?MAOBRJSRNSENE2B0@0?1:-7*8+=/E4>+7$:%>+@/B2C5/89BDLKRNRLLB>}:1u;/q9,s5*2-47<GEWLaFC41:921MKb]J?\\JzdLebCbfEpqOysS~iLiNrZW`NZ@Q3I-H-N*M&H-M,K.J2L1K.K.L1O=Z?[B]FaJcMfQhSkPhOiLgKiKjLoOsQuh_|ZtUkYldrR[r-0]''X1,T<2N@5?<-7:)<C1GP=[N,aW4e_=heBstRd~hwdxgsercrctcwfzgze~xzynmg~b^wYTmMKfCXUFXUFYVG7827828939:4;<6=>8@?:A@;BA<DA<DA<DA<DA<E@<E@<E@<GB<GB<GB<FA;FA;HA9HA9HA9LC:KB9JA8I@7H>4G=3F<2E;1D:0D:0E;1E;1D;2E<3E<3E<3@91?80?80<71;60:5/:5/:5/96/96-;7.;7.=9.@9/C;0D<1F<0F=.J>0L?/M@0M@0O?/O?/O>4O>4N=3K=2J<1G:1G:1D:0D;2D;2B;1B;1@<3A=4A>5A>5Q9/X+&:?P`OeOfPcGO20:/?.C3F=FG>H2BH6F5B3@3?1>1B4D6G5B/<);&<(:(5&3$7<8>7>6=<BJMTSZT@76+.%62HKNX@Q0E:4-(7464D@\\UWKXFtX@rgIysS|qQhJdKoY~kGVAP9J8I=N@Q:N5H@S:M4K3K0J-I-L1S1T1T3W3W6Z9\\;^<a@f=f<e<g<i?mBpEsLuNuRvPqRn`xdvWb|15h0/U3*L:,BA/:C.5G/5L2VH+_T6i`CokN||`rv}qzq|s|szozm}msxsqh|c]tWSlLLgDVWEWXFYZH671671782893:;5<=7?>9@?:BA<DA<DA<DA<DA<FA=FA=FA=FC<GB<GB<HC=HC=JC;JC;JC9LC:KB9KA7J@6H>4G=1H<0G;/E;/E;/E;/E;1E;1D<1D;2D;2@9/@91@91?82<71;60;60:5/;7.;7.;7.<8-?8.A;/C;0D</G=1I=/K?/M@0M@/P@0O?/O?/O>4N=3N=3J<1I;0G;/F90D:0D<1D;2B;1@<1A=2A>5B?6C@7_4-t42KSYiH_:Q2C#+/)9(;&=)@3A=:?0;D4B3?2>2?5C7G;J<>/?-=+:)9':*;-</EBCB=?6:7<AFLNRPD>LDTLTNKJ>C3>.<5+7.0+9482@9[PUDxO9~dIlPbF]FeTqdsj<I9D8A<DCHHKJLIMLSDM:I5H1G-F0J5P7V7X7X8Z:[<_>b?eAiBkBmAm@o@o@qAqBn=hEmJpGhMiZrbsYc@D]($M-\"PC2PR=CO76H.WH1eYCujT{gy~þþyvh{e\\sWTmONiHTYBUZCW\\E560560671782893:;5=<7>=8@?:B?:C@;DA<EB=FA=GB>GB>GD=GD=HC=ID>IE<KD<KD<MD;LC:KC8LB8KA5L@4K?3J>0I=/G>/G>/F<0F<0E;/E;1D<1C:1B90A:2@91@91?82<71;60;60;7.;7.;7,<8-?8.A;/D</F<0H?0J>0K?/M@0NA0P@0O?/O@-P>2N>1M<2L;1I;0H:/F90C9/C;0B<0B;1@<1A=2A?3B@4C@7t50FEY_Ub@Q5F0;*+1%9#;!: =&=.902-:,:-9-6,91A9E;E:?2@0<,6'6)=0D9G=9*@4D=A@<?7<05-.63H@TJNE=70..0273$</,\"7/2,6/g\\m^XC\\CW?R=\\LjafbUTAI>D<@?>C>JBRMZWPREL;G6F2D/B1G6L:T:T:T:W=\\?aBeDi<e>h?jAm@n?o>m=mFn:a>dInJlMmSoXnp_jILt:6\\6-O9+OD2SN:`PArdW|p̿m~k^u[VoQSlNU_DV`EWaF560560560560671893:94;:5=<7@=8A>9C@;DA<GB>HC?HC?GD=HE>ID>ID>JF=LE=MF<NE<ME:MC9MC7OC7NB6MA3MA3N@3JA2JA2I@1H>2G=1F<0D<1D<1C:1B;1A:2@91?82?82<71<71<8/<8-<8->7-@:.B:/D</F<0H?0K?/M@0NA0NA0P@0O@-O@-O=1O=1M=0L;1I;0G9.E9-C9/B:/A;/A:0?;0?=1@>2B@4@@4+)JKSV=B/6.3./0)1 9!=!=\u001f= =#;#6\"6-8/5.3,71@:B<@6B7A5</8+:0B:C=@;@(?+5))$ #\")'/-2((.)2*4*4*1*0+.+6#5&2$6,6.>7`UqeSWCN:XGe[a_PTBIDK@D@?B<B8B9IAPLKP@K9H7H5H3E7G=K9R9R7R7U7X9]<a=g@k@nBqDtCuCuCvBuFgAaEeJlJkUt^z\\vi~o~nw]aCAh6/hB7vTHwf_}vŽ˻tqexb[tWXqS\\iK\\iK[hJ560560560560560671872983<;6?<7@=8B?:DA<GB>HC?ID@HE>HE>ID>JE?JF=MF>MF<OF=NF;OE;ND8PD8PD6PD6QC6QC6OC5MD5KB3JA2H>2G=1E=2D<1C:1C:1A:2A:2@93?82<71<71<8-<8-<8-?8.@:.B:/D</F<0I@1K?/M@0NA0P@0PA.O@-O@-O=1O=1M=0L;1H:/G9.E9-C9/A9.@:.@9/?;0?=1@>2??3@@467]_Z[78,,/,,#0#8$B(G*G'F$F$C!? 81;29250:6B>D=>7<3<2</<1F<KDE>72:\u001d<$:*.($&\u001f'\u001d'\u001d%%(,)2*5*3(2'/&-%=(2\u001f>05)7/?7C9qdm]YFVEi\\lfSS@H?L<B:=<:@9>46,4.44BH8G2F3H5I7G<JBN>Y=X:W6W5Y5\\6_7e;k:m;o<r<r=t>t>vEbNkTqIf?\\Rqff^wbvkys{rvfeZVTN~ĻþĪyvi|f`w[\\uWbqRapQ`oP201312423653875984984983;:5<<4==5??5AA7CC9EE9EE9HH@HH>HH<HI9KJ6LK6MM5MM5LK7IG8EE;HGELIPKIWFCVA=TQF4NC1JA0KB1MD5LB6F>3B90E<5C:5@85?74@86?67>56:44F85E76B87@78>:;<:=<<>==????A@<DA:HB6JA2M@-P?+O?(CB0F?/K:2O62Q35Q28N5;F:<??=-=3)A1.J4/G-,?#5B&GP3`SJ<7)7':'9%;&@);$='?+?+:)6&4%2$8'8':(>,B0D2D0B/?,>*<*=-C4F7>03&6+8,:-=/=.</905//,--.,0,4,9)=)>(9%4\u001e4 9%8&6&@4QEIAMIUUVXJP9A4?9DCHCFAA?;=3=/?/@0Q@QCLCC=??@E>G8CGMENEQESAR=S>XCbGiBh<f;g=kDsIyK}MyNwRtTqQkQl[xdY?lMxX{Ypyca}sŹʻ|zt|qpzo~synv}k0./1/0320542653762873872:94;;3==5??5AA7CC9DD8EE9HH@HH>HH<JH9KJ6LK6MM5NM8KJ6KI<KJEQORWU`ZWhVTjQNiSI@ND;H?6F=6G>7H?8F=6C:5C<6A:4?74?74@85>95=84;63>3/=4/>42<74=98<;9=<:>=;@?;C@9G@6J@4L@0O@-P?+P>(=B,?A,E=0H92K63J46F35A57>=;8=69?5?A4C=-J9)^B4sRCK=;-2#6&:'8$9%?(;%=(@,@-=,9*6(5(;+:*9);+?.B/B/@.?.:(<+E6H9?18+7+5+7,:.;/=/;/8/4/0----+/+4)8(;'=&:'7\"8%=*;*5&;/G<G?JFPOPQGK;@:A?GDGDCB?>8;1;-<->.F5M?NEGC?@>B>F>HDJCLDPFTBS=S>XBaFhCi?i@lBpGvJzL|IxHtKpRs]z`{XwMqCkAlCjJg^ppugNIv̲Ų}/.,0/-10.21/43/540762761:94::2<<4>>4@@6BB8CC9DD8IF=IG;JH;KJ8MJ7NL7NL7OL9KI:NKBTSQ_^dihxmmlkihcYd[QZQGPJ@IH>FG>CC=A@:<A;;?:7<73<73=82>:1>:1=90:3-94.;60=82=:3>;4?<5?<3C?4F@4I?3L@2O?0P?-Q>-P>*3@&7?'<=+A;-B8/A62>42;31=85B:7H94O2.[+)o-.:=EJ9+2$1\"9'<)7$8$<&;&=)A-A/>.<-:-:.>0<.9+:+<+>->-=,?-9(>/L=H:6*2&;05*6+8,:.;/9.7/2,/-.+.+0)2'6&8$:#7$5#8'>-=.7)8.A7<5?8EAKIIJCC?A@CDCC?B;=4:.9*;*<+9)E8NEIE?@<AAIFPAG@ICOGTEU@U>X@_DfCiDmFpIwK{L|K{CvGwJtNtZ|aUvCdHkRv=\\H`z}~\\F;rճξ/.,/.,0/-10,21-32.54/650872991;;3==3??5AA7BB8CC9IE<JF;KG;OI9PK8QL8QL8OL;LJ=SPK^]bmlzzz~|urke^}YSoRMdMEZG@PB<HD?F@;?<87;62;7.<8-=9-<8,880991;;1><0?=1@<0?<-A;+F?/H?.K?/M@/O?/P?/Q>/P=.<@)=?*?>,?<-?;0=:3;:5:94<94D95N43[*-o&--83C7H7)7&9(?-?,9&9#;&:&<)>,@/>/<0=/=0@5=2:,8*9+:,:,:*;,;-B4E9?31'2(:13+4*7,8-8.7,3,1,0,.+.)0(1&4$6 8\u001f/\u001e0\u001f4$;,</9.<2C;6/70;5E@MILGC?;8A9@8>4</:+8*:+<-4&?3HBHEAB@DELLU?E?GBKHUHWBW?W@\\BbCfFmIsMyO|L{Jy@tL~Q}JrLoUwUuLjEcKf>Vet͑]=2aP@wlѥº10,10,0/+0/+10,21,43.54/77/880991;;1==3??5AA7BB8KD:LF:OG:QJ:RK9SL9RM:QK=OKBVTUfdowxÎƏ{wrlid_[~UPnNJaJGXEBM?=B;7696196-86*86)581692891;;/><-?<+C<)D<'I>*J?+L?,M@/M@0M?2M?4L>3M?4K?3F<2B90=909:25<44>57<5>:1H3.\\0/{48;D9E2A<+<+@.A/@-<'<'>*8%:'<+=.;/;.<0<1A6>3:/7,7,8+8+8+7+A5C88.1&3)7-6-2+3)5+6,5,4-2*/*/,.*/)0'1#4!6\u001f7\u001e/\u001e/\u001e2\"5)9-:0?6E=F>@9<5@9KDNGF<;1=1<0</;,9*:+=-?29-=4@:C?BDDHIOOV>C>EBJJTJYFXCYB]@_BdFjJsOxOzLyIxGwRQ}IqImStVtNiD^F]YkKFd2)jc͖ɿ˾Ⱦȿ84163.52-30+30+41,52-63,85.96/:70<90>;2@=4B?6B?6KC8ME:PF:SJ9TK:UL;SL<RL@QLHZW^kj|~Θڙޙޓ֋̆~xvmlfe]ZwVTiMKXDAH><=;:6;8396/267465672880<:-A<)D>(G?(I?&J?)IA,JA0IA4IA6HA9G@:R9<N8;I68A57:65384.93+;12?517+=3'X:0{D=GC>?46<*=+?-?->,>*?+@-8%9(:+:+9,9.:0;2>7;4818.8.9/8.6,7-C9?50&,#7/<44,1*1*2)3*3+2+/*.(.*-)/)2&3$5\"7 7\u001f5#3#2$2&5)7,;3?8YRRJHAD;F<J?G;?3;(;(;*:):(:+>0A3A6<5<6A?EEGIJMMQAD?ECIJTN[JZF\\F]A]BaEiJpNwOzMxKxR{R{OvOtVw]{SoD^UjQddt`cKLkeώ<94;8385052-41*41*52+63,74-85.96/;8/=:1?<3A>5B?6KA7MC7RF8UI9WK;WK;UL=SJASJK[Xcnlǚޞ졩홛敘ߔ֐̈zzrqfd|XWiPN\\IGRFCJDBG=?K==G;:?;:8<92A;-D=*F@*F@(GA)GB.ED2CC7BC=AC@>BAG9HH<JG?LGDODGN@JL;II:ID?KA<@2F=.bH9QBK<@2;-=+>,>,?+@,@-?-=*8'8)9*9,8-8.91;3;4:3818192:2706/<3>5912*3*;2<35,0(1)1*1+0+/)-(,(-).)0)2(5%6#7!8 8%8%5%4%4(6+7.7/NGXPZQRIH>E9B5?1<&<&<(;'9(;*>0@4D;?9@:FCIHHGIHJMCFADDIKSQZN]L]J`D^DaFfIlNuOxOxNyYzWvVuYx]{ZuQkI`WkUgN\\^kKZSaSaQ_jfɂ~窧@=6=:3:7074-52+52+52+63,74-74-96/;8/=:1?<3@=4A>5M@7OC7RF8WJ:XK:YL<WK=TICSJM^Xfpm͜磬Ꝡ㙛ؕΒĉyyji`]|XUpSOhPLcMJeKG^FBS@=H?;<?:4B<0A>-C@-CB.BC3AE7>E=<EB;EF9DF:D]@JcHTjR]oXdt\\fp]dj`ac`[W]LDgI>UEYFL7A+A+@,A-A-A-A.A/=+7&7(8)8+8-6-7/8/;2736161729494816/A:8/3*7/=5=58/6-0'0'0(/).)-)+(+(-)/)1)4)5'8&8$8#8$9%7$6&7)8,7+4*3+NGd\\`YOFB9<2:/?&>&=&;%9&9*;/>3C9A9E?KHLIGDFEJIFGCDDHMSRZR\\N^OaG^GbGdIiNrRvRyRy[u\\x`}_|UpMgPgYn[mbsL]SdM_RgI_E]d`tqښA>5@=4?<3=:1;8/96-74+63*52)52)63*74-:70=:3@=6B?8J@6OC7RF8VI9WJ9XK;ZL?[NHTIMXR`gd|}̗瞩꟡ܙҍurhe]ZXR~YP{YQxVOpOG_E?M?:@?;8@@6>>2@B5@F:>E=:C>9CB<GI?MP:YvKh[udunx|zq|`n]eX[XUWMM?A,:\";#<(>*?,@.@.?-=,;,6'5(6*7-7-8/91818495:685616183:3C<=670@7[Rlc]T@71'2)1*/)*&'%(&*(-)0*2)1%0#1\"5$:(=&=&=)<*;,9+8,6-@871GAc^XQB<@93.<#<$<&<&:(:)<.=2>4C;PJXTOJ@;@:KEFEFEJKPTQWNVKVL\\RdOfKeJfMnRsRvPt[wZuZu[w]xZsWnVictVg\\mYlDXBXMeIbnhhcˎ赲C?4B>3A=2?;0=90;7.:6-95,73*73*73*83-:5/=82@;5B=7I?5LB6QE7UH8VI8YI9YK>ZMEUKLXP_ebyzɔ䚧䘘،ɀ~uqieb^cVbU]TWOtNHdFCTBAIAAA;=8@C<DG@BD??A@BCGMNSWW_Vlgyw}q_wXkTaOUFD=49(:$<#8%7%8&:(8'9(7(5&3%4(7-;0<3=5;5;5>9<7<7=9A=C=B<A;@:A9@78/1'6+I>\\Q?46,+#)#,)./,-((0.4/7/6,4)2&3%5&='<'<(;(:(7)6(4(8/5-<6PJSOLHA?/,=%>&='<'9(8(9,:/>4B:OFWPQKD=B<KDIFIFMLSRTVPVNVOZVfUhSiRkRmSqStRsNoTv\\|^{[vUoQgReUfQbZhZjM^RcWiI\\ha\\W{٩EA5EA6C?4A=2?;0=9.<8-;7.84+84+73*83-:5/=82?:4A<6G>5JB7ND8RF6TG6WG7YI:YKBWKKXP[b^wsuޗ뙗Ղxtqml`i]dY^VVQyNKhEDV@@J76;?=>HBBKABN?BYFJmX_}fnt}}wpcRpE^I\\EP9<3,7(;%; <*<*;);*<,<-<-<.6*8.<1>5@8>7<3:273403/93A;E?A<<5<44,4*7-2', 6*H<I>@64--)+*+,+,*,))/+3,5.4+2(2'2':&;'<(;);*:,8+8,4+;4:5<7ONXYEE02=(<(<(:'9)8*7*7,>2A6JAUKRIH>E:H@IDHCLGSPSSPQMQNWXdZh[pZrUoQlPnRpFmOvZ}[{VqSkVk[mYhYh`m`k\\fenfmT[cY}NDlfØ߹IE9HD8FB6D@4B>2@<1?;0>:/:6-95,95,94.:5/<71>93@;5E>6HA7LD7QE5RE4UF3WG7WI<XMIXNW_Zppp֔횪엖䌋ق{zxlpfh__ZYWQQwGGc@?Q<6DF9BS>C_@EmDJOU]fjreklf]TyFg8U0H>PBM:<7/@.B*<!5$5$5$6&7(8);-</@6@5@6?6<5:16.4,/(-'.(3-:4;4814-5,+\")\u001f7,B4?04%.\u001fF7I<H?<9,,\"%&)/2-./-2.3,2*0(/'/)8*9+;-=->/?0@3@36*KBJE50FFZ\\HK?B=-;+:*:*:*9,9+8,<0>2F9OBPDH<C7D7F?F?JCPKROMLKMKPX`[haqauWoOgMgPkJuOySwRqSm[pcuixguaobmelgljjjhc_dVeH:_TͫLI:KH9JG8HD8FB6D@4B>3A=2=9.<8/;7.;60;60<71>93?:4B?8EA8JD8NE4PE1TE0VG4XH9ZMEVMR[Whkl~В噧铕⊌لӅ{umkdd_aX[QQsNHbUFY_CRlBLEOLVU][d]fJuNxPuLnFc?Y5J+?5EAMFK><>6H8J6B)>-=-<->/?2B4D7E:E9B7>5:26-5,3+2*1*4-6090807/6.5,/&5+6)2#1\"9)>-<+=-D7KAD?56)-)-.26755301,/,/,0-/-80:1:1<0<0=0?0>17+WL`X;6;:OQEHOT=2:/8,8,:-;.;-:.:-<.B3H9I:D6@2>0E<E<I@PIRMNKKKLOZ`^hfrhx]qOgMeQjPzQxQpSm\\qhxjwepfr_k_kkrsulhf\\l^ujXVI8kXJ{tQK=PJ<OI;MG9KE9IC7GA5G@6B;1A:2@91?82?82?82A:4B:7@?:EB;IE9MF6PE1RF0UF1WG7YLCUKLZTbii|ɓޗ먫횞蕙⑕ޒډ|rxnulphhj_x`xWjO_OZR\\R[OVHP:P=QAPCLCI?B9:45IJHH@A7693B8E8@1E6E6F7E8G8G:H<G;>3;18/4*3*4+4,5-9/<2=4<3905-5,6-.$;.<.1\".\u001d8$=);&:'9+:1=9@@;?27+1,.+,+)+(/.4488:;5564736/7-5*5(5&5'PEmcHA42CC>BUYB;=6706-9/<1=1=.9)<+@.B0B0?.=,<+C8D9H=PGSLOIOJOP_caiitm|duUjRgWoSxUtWp_poyy~msXaam`maos{숊ɂ|wjyhhpYMO:^WGqgݿSM=RL<QK=OI;MG9KE9JD8IB8E>4D=5B;3A:4@93A:4A96B:7@A;CC;IE:NG7QF2RF.UF/WH5XJ=RHFXR\\jh}ƒږ奦띤蛢晞⒚ۊ҅ʂymczWiP]KWGP?H9A;6<5B6H7J5G1D.@/UGG?;76488:;9866=.<.;.;,8+6*3)1&5*3*3(2)3*5,6.7/>3<2;18/7.6,4*3)3&3%4%6&=)>*9$2\u001c;(5%3'60;<=@7=27-1..--0.449:;=;>.4/3011/1*2(1%3$2#>/j_TL95@@:=RUJEB=935.8.;0<0=-<*?-@.?-;(;(<)=*>2>2D8LBPFNFMGNLbcbfhqo{hxYmUj[pXs\\tbqkt퉇yy_dhrl|cskw餟z\\pWFR<UVFtg^ܾUO?TN>RL<PJ<NH:LF:KE9JC9G@6F?7D=5B;5A:4A:4B:7C;8@A<DD<IG;MG7OG2RF.VG0WH3VH;RGCWRYjh~~Œؖ㡞뢪룫좪롩蘡䖡ᔟݓِѐǒmc{WjM\\BN;E6>4:B*D)H)N+O(L%H%D&WBF8;5>>BH>F5>08F8E7D7A3=08,3)0%0&1(2(3*5,5,4,4,C8=27-7-:/9/5+1'7*0\"0!9&9%5 9#E.:&:)7+3.//055;;BIMGJDD@@>>9:28.4'/(/*.-.0+2*5)7(0!/\u001feY]TA<ED;=NRPMFC:65/8.:/</<+>,A/B0=)8%9&;)>,8+8+>1G<K@IAICJG`a^bdllxixZkTiZo^tcugqqr݅锍ꋇruq{x`sXg֫TnSAS;PTCkaWݿXO@XO@WN?VM>TK<SJ;RI:QH9MD5LC4KB3I@1H?0H?0H?0H?0FC<GE9JG8NI6RJ5UJ4UJ4VK9XNDULMXTbii{~Ƒڗ妢ꧨ뫨ﲧ珣֢˴bnEP:G5B4>8>=@D@HB;D;BCG99B@D@/-HIHKAG;D8A:?<><;<9A=>9C=LCK@>27+;-9,8-7-3,0,/-1134A19)1 1\"8(;*6%2\u001e2\u001c4\u001d5\u001f4 3\"3%3(3).(2+6+8*8(7&7%6'3'2,3101+2*2+4-6+1*/+,.-4.8,7(5#.\u001a3 XHZL<2OG5/IFQRLKDB<8807,9+;+;):'9%:&<)=+=+=,9.;.=1?1?1@1@2A4k_qed[mirocbjituk|ivdm_hafgjnkqk|w}Yj[wZpaz]sMIZ6LR6snX˷YPAXO@XO@VM>UL=TK<SJ;RI:NE6MD5LC4KB3JA2JA2JA2JA2FC<GE9JG8OH6RJ5UJ4VK5VK9XNDUMKYUcii{}ԓߠퟧ梦榣誢瞧垞ҬºrUbCM;D7?6=8==?AADA:C8?@D;;C@A=41OPDF>D:B7?7;89:8;7F?<5<4G>LAC7;,9+7*7+7-4-2.3/5366?0<-6)4&6%6%4\"4\u001f:\":\":#;&<*;,8,5*3.5-7-8*6&4\"4!3\"2$1(/+.,,-,1-3.4*,,-0.2.3*5'7'9'@,*\u0017E5?1F>WPC?BAWVRRKJC>=59.9+8(;);(:';'>+?-@/>-9.;0=0=1?0?1B3C6i\\mdb[kfolbakluvpo|ir^fY^adqn|vyux~RdUrXnXn[tLN_;QZ;us\\úZQBYPAYPAWN?VM>UL=TK<TK<QH9PG8OF7MD5MD5MD5MD5MD5GD;JF;MG9PI7SK6VK5VK5VK9WMCVNL\\Vbkiy{͏ؙ䘙障蜤✢៙㞗䐝㖛ݠҮ¼rZqCQAJ>C<?;=<?=A>C>C;C7=?AA@D?=896WWBC=B:A7<586696;6HA:35+A5K>H:=/8)7)7+8,7.606387;;5)6*6*6*5(7):*?,5\u001f5\u001f6 7\"9)8+4(0&=;>8=5</9)8$7\"7#7%2&.&-'-*.-////*)/+4.5,3&5#9&>*B/1 TE<0A;C?JITSVVSSOMIEC;<28+6&7&7%7$:'<*>-=,=,:.;/<.=/=.?0B4E7\\Og]aYlgpoabfgkoP`^khqem`edgqqzwvsnuJ]MjUm񜡟PcVoEOd=Va?ww]\\PB\\PB[OAZN@YM?YM?XL>XL>UI;TH:SG9RF8RF8RF8RF8RF8JF=KG<OI;RK9TL7WL6WL6WL:VL@UMJ\\V`jh~yyĎДҔՕۖ㘛ꘞ욢훣뜥昢ߖؓՓՓג֐ց~reTzDa:K@HBCC?C?AA?C=F;F?F:>>@FCA<71>:[WAB?C=@:=8997=8A:E;9/2(</E7E6>/9(8)8+:,:/8083;7=:3+3,5,4-6-7.:.>/9(<)>->.=/=2>6>7?>?<?7=1:*9%;$<%<(8'2#1%2(4,2,0*3*5*7+7)7'8%<(>*<(=,^PF<3/.-?BUXvurojg^YPIA75(.\u001e8'9&8&:)=,=->,<-<.<.=/<-;->0B3E9MA`Wa[pltr`a]a^dFVYegpgodljpstxvssenCXEbRk뒘N\\Ql?Ri?ZhDy|_\\PB\\PB[OA[OAZN@YM?YM?YM?WK=VJ<UI;UI;TH:UI;UI;UI;LH=OI=QI<TK:WL8XM7YM7XM;UK?UKI\\U]hexut|~ĎƐ͒ԒܓᕚޕܒԌ̇ƃÁ}z|vqh[Kv>c7U8IAEFAIAIAFCAG;J8JDI>A@?JE?83,D<TPDCAC>@>?>=@<E;H<=27,5'9*=-=-<+<);*;,<-;/8/708395:764223142502+1)2'9-<0905/52<;DC5766615,5&6\"9#;#>'9&5$5'9,;0:/8-?1;-8'7&:'<)=';&>-:*>2B:.+::142673;7C>JEQISHTHUG?0>.<,<->.@.?/?.=0=.<.<.<,=.A3D6LAbZc]nlrr`c`e`gixozlt`h^fkqw{{|pq^h@W>]Oh懍XaXuE\\vIgwPfŻ㾺޺޼[OA[OA[OAZN@ZN@YM?YM?YM?XL>XL>WK=VJ<VJ<WK=WK=XL>PI?QI>SK>UL;XM9YM7YM7XM;WK=ULGYSWc_nmktt|~ȍώԏՍӐӋʂ{u|ovgpckn~eyZvMo?c2V0L6G@CGBLBMCIGCJ<N8NFHCCA>ID<45*I@LFCA>=:;;;?=E=H<I;7*7*8(9(9'9&:(;(;)=,<-;.8.6.6/5.24.1+0/237694521/,316342/3/55?=G,2.22/3,5(8';&>(9$8$8&:,?1A5B5A6I8B1<*:&<)?*<)9&;*6)0'B<1/>A.2'-3-4.71928.5*2&1#E5A2=.:+9):+:,:,</=.>/=.<+=,?/A4SGg^d_kinochjqoxp}t~mwcjdlqzw|sukpXfAY:[Kf}lojXoZx`rū٫ӦѥԩԮֱںZN>ZN>ZN>ZN>YM=YM=YM=YM=XL<XL<WK;WK;WK;XL<XL<YM=RJ?TJ@UL=XL<YN:ZN8ZN8ZM:YM?VKEXOP^Xbd_sifqpyy|~ĈˉΉ̈ȃ{~uxorjmegacacX^O\\H\\=V1K/D7B>@E@JBKCHGBL<N8PDDEDA=IB:/7,PFB<=8641051>8E;F9E68(:*:*:'8%:&:':&9&:);*9+7+5+3+4-)-)/,3.4071828587;8<9?9A9D6G6H5J)1,2024/7-9*<+=,7&9*</>2?4>4?6?6N<H7B1=,:':'9(9)3%9/@8D>0/-.38384-6.80:1;1;0:.:/L?F:?29*7)7*8*8*<->/?0=/<+<+<,>0KAc[c^kioshnrzveroyr{jslvvu}ioflRbA[6YFat{~zf{fhu˭շˮŨÒēș˝ˡΧҮٻǾ[N>ZM=ZM=ZM=ZM=ZM=YL<YL<ZM=YL<YL<XK;XK;YL<ZM=ZM=TJ@TJ>XL>YN<ZM:ZN8ZN8ZM:[O?WMDWMKZSZ^Xfb]sjfspvwxx|{~ǈʉɂ}~zzuvqvoslogldPHJEFFEO@L7D3@8><=A=E?GBDHAK=M:OBAGDA<H=;.</VK>583.,)&.*:3C9D6@0:(<)<):';(=(;'8%6\"7%8)7*5(3(3)3*03587<38,2&-'-)1,3'0%/'6+=(A\u001e:\u00152\".&0+10/1,4+5)6*6+90>5>7:4615061L?K<F7>/6(3%6)9-5*6-C<7421  89352(3)4)5)5+5*5+7+YNRFH;@4</;0=1=1:-</=0=.<,:*:*;-<2YQb]ppvyltrzr}yziqeop|t}nt`jNa@^3WA^nt~i}ghq̭ܽٻԴ̩ß~~ÏÑŗɟΪҵºνȷZM=ZM=ZM=ZM=ZM=ZM=ZM=ZM=XK;XK;XK;YL<YL<ZM=ZM=ZM=YMAYM?ZM=[N=[N;\\O<\\P:\\O<ZM=YMAWLHXNOXQX]Ub`Yka\\pifokspvq{u}ÊˊɈ~zrrulz^G9C7A:C@?=89:<BC<<=<>=@ABICMAN>NA<@9?6?3=/=0E8MD61;61.2.C<?36'?.6#:'<);'9%:&:':&:'9(7(3$.\"/%7.=57230.-)(%&#%\"'\"'$* )!,%7'<\u001f;\u00164\u00113)7\".\"+*---+(-)416254645512-.+,++<491:1TK\"\u001a+#F>.&/(<7E@:7/,.*41:7?3;.5)3&5*:.;08.bWZOD86,:/9-3)6,1%2&2&4'7':,<.=/:.C;\\Wppsvv~yq|{xu}s{r~q}lxisbmI\\=\\8[:Vek}~i|d}cju|vxqwo|rtwuy§̹־ʻZM<ZM<ZM<ZM<ZM<ZM<ZM<ZM<XK:XK:XK:YL;YL;ZM<ZM<ZM<ZL?ZL?ZM=]M=]N;^O<^O<\\O<]P?[OA[NFYNJZPQ\\SX_U^_Wbb\\xibngqjvpyƊŏÐ~tnquiY;.7)6)>1B6?6?8A==;:<:@<D?IAI@K?H>7=4<1</:,;+B5JAG@A=6341@9C8:+6%8%;(=*=*;(;(:(:&9(5&2%2%5*8.80912&0%.#,$+%+',+-,)-%+#.&5$9\u001b5\u00121\r0 .-92<*1(,.002*.9>6;3:06-2.314364/:572DADA/+2.\"\u001e41?<E@=83-2,6091<-9*5'4&8+;0<29/cYXN@83+:1;27.:14+4*4*5*6(6(7(6);0B9YTllqtw~|v|yv~uso}iweqanI]<\\9\\=Ydhysu`t\\w]ckppmp_l_f\\g^j_qeyi}lrtz}ƷǿҺŷ\\L<\\L<\\L<\\L<\\L<\\L<\\L<\\L<ZJ:ZJ:ZJ:[K;[K;\\L<\\L<\\L<\\L?\\L=\\L=]M=]N;^O<^O<^O<_RA^QA\\PD[NFZOK[PN]QS]ST_RlcXvh]jbsk}w}}ÙvotviU925-5)>/E5G7C8?9=<9>9A:E>GAH@E@B<4908-:*9(:*?3F<D>9665:7C=OEI<4%9&:'<)=+>,=*:)9)8'2#/#4*=3?6912+7&6&3#/\"-\"+%,&+(++(+'-(5%8\u001d5\u00152\u00133(5.;4?8C;D<E5>+61</9-8+5,3-1.1011.<964;9ljBA.-.,97?<A=<67.6+6+5*8&6%6%8);.<1<2;1aWTM<30(;3?6;3>6=8<7=4<2;/:.7*6);/@8TMgeorz~{{zxwsl}ftbn]kG^:Z9\\AZ_cgk^eOhOlRtX{\\}^x\\qX`yO_P`UeYm`ug{jmptvyyz~ǹ˸̴[K;[K;[K;[K;[K;[K;[K;[K;ZJ:ZJ:ZJ:[K;[K;\\L<\\L<\\L<]K=]K=]L<^M=^M;^O<^O<^O<`P@^Q@]P@\\NC\\NE[NF\\OI]PJ`NdcSmfX{g^ohzu|{yxucOyAF@@A=F;J;J;F9B:@?;A:D<G@HAFAA?<?6<19+;*:)9*?0D:<721:9A?D?TLVH;+9)6&8%;)=,=,9*8)3&2&3'9/>7>850-&:)8)5(2'/'.',(,*+*(,)1+7';\";\u001f=\"A8G(6/;P\\`lP\\<I9G)8)8,90:1701*(&#2-641/BArpTU==FF=:<9:5807-7*4&1#7#6\"8&;,</9.:/<4XQMG70/*<7A:;5=5<9=9?9?8?5<0;.9-9,<3OGc_no|~xyzxtl}dt_nXhE\\6V7ZC\\YZmRWxIXv@\\yCdzIl}PtVwXrXoWlZl^obuh{loqrqruvvvwz|z|ȷ˶[K;[K;[K;[K;[K;[K;[K;[K;ZJ:ZJ:ZJ:[K;[K;\\L<\\L<\\L<^K=^K<]L<^M=^M;_N<^O<^O<^O<^N>^N>^N?^N?_OB`PC`OEbM\\cPdcUodZlevr~wv~ЁwkXuFf=MDPJNJHG>G<G<D>BB>C>G@HCIDDB=?9A5=/:+;*:)9*<.?6FB<;ABAA:8JBXLL>@08(3#8(<-:*7)8+0%3)8/;4:3500++'4,4-2.314345586;/4.60=1C.F*G,L1T<H3?@M_llzWfCS>P3D2A3>5<89733*/$2*-(61XT\\ZXV@AHHB@<7706-8-9+7'3!:%9$;(=-;-6)8.>5NGEA501->9?:8171/011427392:/9.:.6*7-IB_Ynl}v}x~zxsj{dt_nUeF]6V7ZF_TRvaBJo<Us?[vCdzIn~QtVyZy_waygvhyl|oprpmrrttrrtw{xxüƪZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8[L9[L9\\M:\\M:\\M:^K<^K<^K<_L=^M;_N<^O<^O<]N;]N;^O<_P=_P=aP@bQAbQAeKTdN[aPc`Usgarpxv|rv݂̋rbsOb>R-H:QCTDK@AA>DAEBEFAF@EBFDEEAC:?4@3;-8(9(:)9(:-;3IE??;>682/A:ZPg[QCA34'6)9+8+6+8,0&5-;4:440/,-+-,4;3;3<2=1>0=0?0@1A2D5K5O0P-Q1X:d7BO\\an`nXfQbEX8J@S:G2;/23-9-=+>(9/2(JBkcLGPM<9;9LJ@<7/7-</<+:'9&>(;%=)?-9)4':1C=HAC?722.;7:62.2-)++,.-3/61:1<1>26)4)B:XRjh|}v}y{xqh{bt^oSeI`9X9[I_QNmZ:Em8ZvCa|InSvY|]bgll{m|o}p~onllqqrronptvtwï̾ŽӫZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8[L9[L9\\M:\\M:\\M:`J<`J<^K<_L=^M;_N<_N<^O<^O<_P;_P;aP<aP<aP<aP<bP<fLOdMUaO]_Vkgbsryx}tvΆ}owbjOX>H$H0Q;U<M<GAEEDBCCEBCADABDBC>A6>1?19+7':)=*=,>1>7=:79/3/03294NElaj[QC</:-:.7*6+8/4,7/93621/.,1/320E/E-D*B%@\"=\u001f:\u001f:'A+G/M0R+R)V1b=nHS`miuVeKZL]CU1DAR7C,3)(0$9&A&D'=.;,ZM\\SG>D>61;7UQF@918-:,9(:&;%B)<&<&=*8(3(=4MFGCEB96307341/+2-)/*/--0/4/7/;1>2:,4(;2NHb^yzz}}xn~dw^p[lN`Ha8W7YH]JGcS1Al6ZtDf~NuZcfjnsttr}p}nmlknpoolknpsrwƱοŷҤZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8ZK8[L9[L9\\M:\\M:\\M:`J<`J<^K<_L=^M=_N<_N<^O<`Q>aR=bQ=bQ=bR;bP:aO9`N8jNMgNRbQ[cWkjfuv}}y{˃{|qsgjTXAG#M.T7W9P>NEMEH?BBDAC@AA?C?B9?4=0?19+8(=,A.B1C7D=6457,002880+5-UKzn^RD7=0<06,6+90708271401/105387\u001f=\u001f>\u001e>\u001d>\u001c=\u001a=\u0019<\u001b=\u0018:\u001d@$I&N$Q%U0e=sgralXeR_Q`M]?R1B:J4?-0-(5'>&C%E\"7&9(WH<0A87/3/C@XSHA916*6&5$6\"9#B*<%:%<*7&3'A7SLIEGE:82.411-.)4.'-',)+*)-(1*5,9->13(7.HB\\Xwu~xl|`sZlXiHZE^4S3RCXE@\\L*?j4Uo?d|Lw\\hlptx{xt|mzi}ghhkmmlj}ilostx«ǶȻӞ]K7]K7]K7]K7]K7]K7]K7]K7^L8^L8^L8^L8^L8^L8^L8^L8\\J>]K?]M@\\L=ZM=ZO=\\Q?^SA_T@_R?^Q@aQAcRBdQCdNAcM@pKEjKIfOUgZknlv|}̃{~uml]fRN[DQ>LANCQ>K:G<F:B;?;;<:?7>4;/8+:$C0=,6(?5D=;56183716-7)9(=';\"7\u001e74PLXOD98(?.C3;-4+GD.14;4?+9@Q(9&+*-*-\u001f\"#$()((\u001d\u001f\u001f\"+1 )&1.<$5Yn+@`j^iYcT[PTHI@;:1A2F2D.;$5\u001f7#;)=+8183EC;9234544CAKFKED;:04+4*3+2*?19,.#'\u001e,\"7/C:G=PFE;801*/-01/3.4141201/00.1+4+8-=/2#?0>3`Wtqwe}[wXuSoJgDc7Y9]>[]kC=PI/F`;Xw<eKu[zcze|hlol~k~j}g}feee}p~onk~geegjpszĤŧz]K7]K7]K7]K7]K7]K7]K7]K7^L8^L8^L8^L8^L8^L8^L8^L8\\J<^L>^N?^N?[N>ZO=\\Q?^SA_TB]QA]P@_OB`NBbPFcOFcOFkLGjMOgS\\h_rnow~~̢wx|xuhjYZgN\\FRHUJVER?J;E9A:>::=:?7>4</;,>+?-9(:,A6<47/<7404-4*4(7&:&;%;\"52A;MDI>>/8(8);.<2JF/15<6A.<?P'8$'%(),+,*+'(((*,$'%(%,:D\u001a'4CAT#6lublZcW]OSBC;8>68,E4H6?,1\u001f)\u001a(\u0019)\u001b-':6TRHG5445<=WUGBGAB99/4+6,7/5.?5:15.3+4.83?9E=JBA86/1*0-1103.3141201/00.1+4+8->03$=.=2^Uvsue|[vWtQoIhAa8Z=_F`Q\\{?7NH.Ga>Yx=eKsYxawbzf|i}j|i|i|h{e{d}c}cd{l}n}l}i}e}cccfkpu|zdoqR]_]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8]L8^K<_N>aP@`P@]P?[O?[O?[RC[QE[QE\\OF\\OG_PKcQOfTRhTUiTQiVXi]kmisvz͉ٟ֗ʪ}烅~tve`kS\\GQFQHREQ@K=G6=7:99<7@7A4?0=-@-=+;*B4I?;20)926/5.7,7*7(7$:%<'3/4.A9OCH:6%3#@2>5HD134;6@4@ES3A),\"&#&03--''%%12(*7:+1)13?R^=KYiafV\\OTMREI:;74?96,?2C5>18-3),%' % 0*FC::,,44AB^]>:C;A9=39/=4@8@9A>=;>=A??>;9?=IDA;=45,2+2-3112/2040201/0/.0+4+8-?14%9*;0[Rzw~rcyZtTqMmFg=_:^BbQg?Fn<1OK2KcA[z?hLrZu^t_wc{gzgyfyfycxbyb{a|b}byj{j{h{e{az^|^`hnstwvypngVb`COM4@>^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^L6`N:aP<`Q>]P?ZN>YPAXPEXOH[RM_UTcWYeX_iYcl\\fm]hlbclemolrtx~τߊ狇ޝ٬ɳy{߁yvnrbgU\\LUFPBM>G;D5;7:97=7A6B4B1?.;,=/>0G:RGH?6.1)9181;0<0;-6%6&9'402-=4OCK=;,8*B67.>:/0164<8BNZKW>C38$&/1,,22+*0.::\u001a\u001c37-29BENYcLY?AADCF>C9=8988:58391:2A:NHVSNNAB82:5KGNLQRYZRQYX51>6C9@7?5A9C<A;<B7=8?>C:?58=?LJ93704+3,5.302101040201.0/.0+3+8-@26'6'9.WM}y{ocwXqNmFh?c8\\=`IdYh25d<0SQ8TgG`}EjPsYt\\u^wbyeyfwdvawav`x`z`{a|byhzg|fzbz_z]|]~_emrsustii_RaZDSL8G@^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;^M;_K2_M5aO9_P;\\O>ZN@XPEXQKYQO^X\\g`hnfsshysg{sg}tfnnzorrwv|y~׃刋쒍뛌ߞƞtkmqvj{illklfi]`QWEM;B5=596898>7A7C5C0A-8+@3;.;1RH]SNC;2907,9/>1=16*4'7(2-60=5E9F9C3A2?20&620/-1-47?OYZd[_OS.103--EE66,,-.>@2537ch=C*2-4();=AE7:378;89..43<9HESS`chndk[eB<E@^[igopjjKK=;4.>7E<C;?5<4937/0=,9+6-8*5+38<JK3/4.4+4+5.404/3//4/2/1-0..0+3+7-?29*3$8-NE}y}wl|atUmHg>b8_4\\@aMcWap/+\\A0XX>]lMbIlSt\\u_v_xcyexbu`u`u_v_w_z`{a|byd{f|dz`y^yZ{Z}\\_gmpst{nrffvi[k^RbU_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<_N<`L1aM2`N6^O:[N>YOE[RMZTT_Zahbprmzu{tyrzpyoovpyt}wz~Ճዋ唏㗊ҙ~yl[X>H?PIVRVURRJM=C387<9;;9=8A8C4B0@-9.A65+.$J?h\\eZVI=26)4):0;05,3)6+/+61;2:/?0F7C39+1&3-31-.*.17EJS[_d\\a9<9<+.JK89//55()(+YZ?B9=7: %))=>BE49,217/5(,37KNaehncl_k_m_nNIOJ]ZVTMMGH3231A<KDPHKAA8:3502+,;+:(7%4'4/:=CIL1.3,4,5,4-4-5/4//4/2.1-0../+3+7-=0;-1#7,D;yvyqhx`sTlCc7^3_3\\DcM^JMb6+TE0W[@^kMc~KkTt[w_x`{dzcv`s]s\\s\\t]v^w_{a|bybzb|b{_x[xYzY{Z~]eimsus|mvunmfwe_P=_P=_P=_P=_P=_P=_P=_P=^O<^O<^O<^O<^O<^O<^O<^O<cP2cO4aO7^O<[OA[RK^UV_Zakgvso}z~|}w{u{tpzs}w{~Ǆ͋ӓԘ͠«ǮŦlmJ?/A2@4A9GBMLHK?A;?:=;;=:A:A5?1=.;2?84,1'J>cWh[fYPB?25)7,:05,2+6.0,4/7/8.>1C4?04'4*1)2/..-.1468?COTY^FKRW47FJ8<BE7:.015IK8;8:#%<>89;>=A6<-4)219<DLS^eksis`lYhXhXkgaZVWT@?104441C@JDRKSLJA?7938171)8/>/>)7-:9CAHAB1/4-5,5,4-3,5/50.4.2.1-0../+3+7-:.>02$7,<3tqrj}bt]pRjBb6`5a8_KfN[z;6Y?.LH/TZ@]cIbzJjTr[v^yc{dxas\\pYpYqZqZt\\u]y_z`x_y^z^y\\xWvUwV{X~]dhlormxgrlk}ecu]_O?_O?_O?_O?_O?_O?_O?_O?^N>^N>^N>^N>^N>^N>^N>^N>eQ6cR8aP<]P@ZPG\\TR_Zab^otryx~~yxwvxwt}w}Ƃƅȸп¡ϼǲkS\\FG5=0H=VQVTNO?A=?<<<;=:=5;18.82<5:3>5PDYM]PgXdWM@:-8.913-2,50402-5-<3C7C4:-3%5*-&0+.,2144.,00EIY]W\\puDJHN=C[aou>C~mqQT>@02<>EI9>7==F6@-8>J\\hmwitdl]g^kap]nWh_YOKJG740.54/.95D?JDJA@86/5-7194$0/<1=*6/:>E>C443.5.6-5,3*3,4/5/.4.2.1-0...+2+6-9-@21$6,7/pokcx]pZnPiAd7a8d=bPiQW^2'RG3DH/PV<X\\C_vHiRq[v_zb|dx_rZnUnUnUoVrXt\\u]y_v[x[y[wXvUvSwTyVzX~_cd~f{fr_kV`uVZoPRgH\\L<^N>`P@`P@_O?_O?_O?aQAbRB_O?]M=]M=aQAcSCbRB`P@eS;aP<_O?^QH[QOZSZeapsqxxz|~}xyrsnoqwv{̋ȖäŲͭЩУѠѡ̚Ɣզg_FzgteG?QMbaIL>A799;997561949550B;=5I?XKPAeVdVYKG;:/6-6/5/3//-2,70=4<08)5(8*/$/(.)0-204051408<JNY]OS7?6>X`~~owgoipfj\\_Y[^`RYCK8B7A1>+9/>=IS_`kgpepbobp`o[lTOFA853110/.2186D=B:?7<4908183845=4;3;4<5;49331/3,6-7.5+3+2,1,2./503/2.1///,3,7.@49,7+/&<5XW~he|]rRhHeAe9b5`JlRd==K. >>&?I.IO5]]EWlAcxMqZxby`t\\rXqWlSmRnSoVrXt\\u]u]tVtWvXwWvUvUuTtS{[{\\z\\uZnUc}MXrCSj>AW1?U/<R,[K;^N>`P@`P@`P@_O?`P@aQAbRB`P@_O?`P@bRBcSCbRB`P@fVF_QD\\OF_TRcZ_f`nmkwvwy{}}x|qtlolnoqsu|}ىԘШƹƵϩףܞߞޝܞ٠ҜʖѼ~dċw}mVJ`YqnZZJL>@<>>@:;5634=:73?86.>3L@I;^Op`aSH<5)0&5-4-/)4395<7<38.5)5(5*6.4-1+0+0,2,4.5.9;>AIMW[\\d\\d]e`kR]MXQ[_gjqfl[`RU07+5+5-9&5\u001f/'67DP\\[dclemepdo[hP^FB<9646353202/62>9>7<2:1918295969;7:7:797957313,4,7-7.6,2+1*0,1.0503/2.1///,3,6.=2>28-2*82Z[w{a{^vWqOkFf=b:c=cLhJVw<8F5#7=#9C(DH/UP<Tf>`rJnXw_v]tZpVnTkOkPlQmRoVrZs[s[tVuWuWuUtTrQqPqQnPlNhLbFXu?Nh8F]/@W+@W-@W-AX.YL<[N>^QA^QA^QA^QA_RB`SCaTD`SC_RB`SCaTDaTD`SC^QAbUM^QK[QPcYakesqmvuy{y{y~w}nseibfjnrv}zᇃᖔߩټظۤϠĘkpp`RG]Umius^_HL@D@D=@7:36>;;6A:707.?3=/G8j\\j[\\MB62(4+6-1*44A>GC=62)1'2'0%3*1).)/)2,7/=4A7-,43CEVX^bYaS]P[FQHSNY\\fmvmtY_AG*2,41<1>*9&66EJXISOYW__fdkaiQ[BJ956375<8<9855160:3;290908183:6:8;9:999988884403+6,8-8,6,3)/)/,0.151302.1//0,3,6.9/D99/4.0,`bnu_zWsPmLlDf8_9_GfReDJi=4K@,7@%8@(ED/LE2N^9YkEg|Qr[tZqUmRkMiKhKiLkPmToUpXqZuWuWtUrTpRmMkKjLdGaE\\~AUt;Li3E_/AX*>U'B\\/E_2Ic6WJ:ZM=\\O?^QA]P@^QA_RBaTD`SC`SC`SCaTDaTD`SC_RB]P@YNR[PVbXcjcsqmvuxzz|w|symrbi]caglrv|ȋ攑褡淴޿ܨҧßvqsecWi`rmut[[KNCG?D;?8=:8;8D?C;:0;/7)2#J;bRk]SG9.3)5+4+33ML[XKF803*4+2(-&,%,%,'0)6-<0?20(4,:6CBFHEKGPLVQ]VbXd[ggpmuY_=C.2-4-4*4%2(6<KS_?IBIGMQV[`X]GM5<5173;8?>@?<;857292:1908071738687<9;9:7;8:8845.4+7,8-8,7*3)/)/)/+252312/1//0,3,6.8.G<903.-*fjyjr`{TqKkFj=c3[<^PhXeDBbE7WP=DH1@D-JH3JB/IW4Sc?btLmUpXoRkNiKgIgIhKjMkPmToWpYtVsUqSnQjLgIeHdG`D]AWy=Rq8Mi6Lf6Ne7Pe:Lf6Oi9Sm=UH8WJ:[N>\\O?]P@]P@_RBaTD_RB`SCaTDaTD`SC_RB_RB_RBTLY`Xgnf{tpxtxwxzy{syjq`g\\b`fkqv|~Ε䞞譭齼߳سѴůy}qwkskngoi扄~sredVYLNCE>A95:7B=E?<3=3B51%1\"I;YKN@=/8*6*3'34UUkh]XE>;3;2804-1,1+0)/'0$/$0#9,4'3):5CAEGBG@HDOOZVaVa^igoYaDI885526183;9CHSVa6?4;7;AFKOIM;@056195;8;9;9:77370;2;1;2:282736465<8;8;8:9;7956/4,8-9,9-7*3)0'/)0+453322010/1,3,6.7.D:7/1-21jprzhr]vPmCf<d7c6^Db[mW[uF>_L;_ZFQP;KI4PI6MB0DR1M[8[kFf|NmSmPlMhHfGgHgIiLjOlSnVoXtVqUnPjLfIcFaF_DZ@X|?St;Pn8Pj:Tk=XmB[pEUp=Vq>Wr?RE5UH8XK;ZM=[N>\\O?^QA`SC`SCaTDaTDaTD`SC`SCbUEdWG]Ulje|yu}yzywyvxswlqcj[c]ehpw}ǁІՙܡ௲廿Źxzuwvqulg~mfoib[a[smzu{|yrpccSTHHB=>:<6A;:1D:TJ>26):,=.?/A3C5?18*23LM_]XSD?;48170929292929/9.9+8))\u00163\"@2I>E>;:7;9@8AHTUaYb^g`iU[CI?:?;AAGJMRQYT]V^4:/5037:=A:?48/2619595411/20404.<4=4=3;293734333:898888987754/4+7-9,9-7*2(0&0(0*454332111/1,3,5.90<3700-AAnukucoSkIf;c1`3b<dMg]iIFeH:YN<\\WCXQ>RJ7QF4MB0AL.GU4Sc>`rHgMjMjKhGeFfGfHgJiNkRlUmVqSoQjNgKcH`E_F_G\\E[~DWxAVr?Uo?YpB]rG_tKYtAYtAXs@NB2QE5UI9WK;XL<ZN>\\P@^RBaUEbVFbVFaUE_SCaUEfZJj^Nkgup|x{ywxvwptjoah^f_gempx~͉؏ܙϠ֪۴ߺ߾̼ƻŴqqstpqogevhenj`Ye_[Tg`tn{v{wwshf[ZQKGB=6C=;4G=\\R;0<07+6(>.D3C2A1A08:>@DCC@=8917/7/:393:3;3>5A5E6G8.\u0017;%K8L==30+108>BJKVU`Ze]eYaLR?D4+8/<7@@DFEJBI?F5;26368<7914-2.44095640.,*/,2.2-=5=4>4<3:58565555757575656422.1*7.:-:+8*3(1&1(1*555342111/1,3,5.;24+;420UVpxcn[gKbEf7b+]1b@hKeRYd8/ZI7SN:UN;[P>VI8M@0MA1=H*CN.K[6Xj@ayGfHhIgFeDcBcEeHgLhOiRjTnPlNhLdJbH_F_H`H_H_H]~I]yH]wH`wKcxOdyP[vA[vAZu@MA1PD4SG7VJ:WK;YM=[O?]QAcWGdXHdXHbVFaUEcWGj^NpdTvqyuxvtsrrsulpbgZa^femltu}ƁЍڕ⚤ȟͦԬٰ۱ڲڵ۳ֲѮ˫Ī¦{|ydbgidhbY\\g[[xeauXRe]OHVOaYjcvp}zwuljZUPJD>MGB9F>WO,\"2'5'=0E6>-2!8%F4DF9;3262;6<7<6<6;4825.4+5+8+<.>/U;I/=';+=2;56537KRLVOYS]WaU\\LSCG5)8-816455584:288<6;9=<?6:,0)..44.94860.,*/-405.;4=4=4=4;49676563615052435310-/(7.9-:+8*4&1&1(2*655342211/1,3,5.=4/&>853cepy\\hR_HaGh:e*]/a@hE]AFQ-!UJ8PN9OH5\\O>YH8L<-NB2:D)?J*GU2Rd:]sBcEfGeDcBa@aCcFeJfMgPhRlPkOfLcIaG_H_H`I\\G]H]~I`|Ka{Ld{Of{Rg|S]xC^yD_zEAC8CE:IF=OH@RGAWI@]M>`O=aQ:aS9`T>_VGaZTfaeljwrowozt~wzurohfa`^^bahgqo|xυڏ㗐흖٣ڥܦݧݦۥڦ٥֣ҢС͞ɗymrvghlc_`e[ZlYUtUPULVKRGZNZP\\Smd|t~xyyyabPQEEYV611(5(7&6%8%9':+<.?18+=/?1;-5'4&:.?590907.7+7);)@+C,;3?7D<F>C;<42*,$>5G>QHXO[RYPPGE<<!<$:(4,--'0%2$6(@'@'B&B%B$B!A!A\u001e:\"<'>)<*6.648;;94:5<4;5:593736225445464717.6,6)9*:(:&9&8%8%7#7#414/4.3.4,5)6(8*:.7/96>BlyasRlGdIj5Y5];e=cPjLVT)\":1 9<)EF4RL>PH;BC39E15K4FG\u001fHJ#MQ,U\\:\\jGcuOf}QeNcHbBa>c@eDjIlNmQjIiFgFfFfHfIcIcGdJdIc~Gc~GdFfFe~Dc|BX}8[;^><?4?A6FC<JE?OF?TG>[K>^M;`O;`Q:^S?^WGa\\Vhcinlyrqtnvptppmgfaa]^\\\\edkjtr}{φَ蘒웗Ҝӝ֞ם֝՜ҝўќ͜ʛǙēwtmtkdkf]`e[YiZSoWMzVJVIUK\\RYRXRf_qjvowuufdTSYU2+/%7)7&7%8%9&:*;-=/8,9,:,:,9+9+8+8,;1908.8,8*:(;&;%4-80=5@8A9?7<4915->6H@OGQINFC;7/8\u001f9\"8)4,./*3(7(:+B*B)A&A$@ >\u001e=\u001c<\u001d8\u001f9$;);-9297;;;94:5;6;5:593736225365464717.5,6)9*:(:&9&9%8%7#7#4-3-4,4*4*5(6)7*</5,52TYes[pGbKh@d:`1[7aImJb8?O,&=7'3:(:=,C@1F@0@?-;C.:H1@C\u0018KP'\\b<eoLhvRezSd~QdLaFa@a>c@eDiHkMlPlIjGhGfFfHfIdJdHeKdIcHdHeGeGfEd}C\\<_?bB69.:<1??7E@:KB=OE<VH=[K<^O<\\O<\\TA_WLc^[helol}sqsmqkjgc`\\[ZZ\\]\\_hjnowxʁ҆؋ܐⓒΓΓЕДѓГϒΕ͓ǓĔz{rdpt_fiZ]c\\Vc\\ReYKqWHTFZQ_Y[YXWcblipkwq|ymh`Z4+2&8):':%9%9&:):+:,9-5)5'8*>/>/6(/\":.7-7,8,9+:)9&8#4*6,8.:0=3@6A7B8;1@6E;F<H>G=@68.6!7&7,3/03,5*9*<'='=%=#;!:\u001d8\u001c7\u001b7\u001d6\u001f6#8*;1<6=9;;:86:5;6;5:585736226475565616/5,5(9)9)9'8%8%7$7$7$4+4)4*5(6(7&7'8)=12+98lt]nPi=[Jl5\\=e4[<`Tq?Oa#(H1+79+-8'18&:;)B=*A<(@>)@B*?G\u0018Y`4s~Tfwbi~Ub|MaI`C`?a>c@hEjJkMlPnKkHhGgGgIhKfKfJeKeJcHeGfHfGeFcDbBeEhH06*58-;<4A>9G@:KB;RE<VJ<XL<YN<YRB^WOc_`igrompppmjg`^WWTUWY\\_adkoqt{|̂Ոيیڍۏ͎̏Ύ΍юЍύ΍ʎƎxxq[i}WbmWYa]T\\`Q\\^IhYF}SCULZYW[V\\bekkplys}v{u~{ka<29);(:'<&;%:&:'9)9*9.6*4'8)>.?.8(/!6)5)4(6)9+<+=*;(9/9/9/9/:0;1<2=3E;E;B8=3=3A7A7=34#6)5.31/5+6(7)<&9&;&;'<&<%<$:#:!7\"7%7-95>:?9:8786:5;6;59585655427376665726/5,5(8*8(9&8&7$7$6#6#6'7(8'9(9(:(:':+;/3.IKo{VjDa=_Ci/[7`=cLlOe0=G\u001f >3--3'+8'2=,=B.B@+C;$G=\"MA'R_*q}Mp|mjW_{J]~E_Ca@b?fCkHlLmQmSoLlIiHhHhJiLhMiMfLdJdGeHfHhIfEeDfFiIlL-3'17-7:3<;6B=9G?<MD=QG=SI=SK>UOCZUQa_dhgukklljgbaXVPPQQXY`cfjorux|Ѓֆ׉؊׌،̋ˊ͉ЉшъӉЌϋȍ}xvpScQ\\qUT`^RVcOTbH_]DvUBLBRRPWPY\\dejljwqvlph~v{~ka?28(;(='='=';':'8(8)8/7.8,9+;+;*:)7(9+7+8,7+7*8*<,>-=0<0<0;/:.8,7+5*@5@5=28.8.;1:06,.$0)2.23/8-9+;+>-?.?0@/@/A.?-?->)9)8*70:6=9=775386:5;6:79585655438485676746/6,5*9*9*9(9&9&8&7$7$9%:&<'=(=(=(>*=.8-;8^eaqPi;\\Ai6a/].WIjYq>NX'-?+,730*1)-9-5@/:B+<<\"B;\u001eVG(iV6vPlwo[aK^F`BcBeBjGoLpPoSoUoLlKiHgGiJiLiNhNfJeIdHfIgIhHgGfFgIiKlN*2%.4*470894<;7B=:HA;KD<NH<NH<OKBUTR_^ffewggfgba[YQQNORS[^eilosxx}փ؆ن׈ՉԇȆȅ˅΄Ѕԅԇҍӌˍ{vrnN\\NTqTPa_PWgMReI\\`EsXCOCTRSXPZYc`ghjqq{rrh}tsjxm\\Q:-5#<'>(>(=(;(;)9)8*3+6-:.:,:)9';)=,>.@2A4=17*4&8)<,:,:,;-;-;-9+6)5(6*;/>2>3?4>37,.#)%-*02290;/>/?0A0@1@2@0=/:-9,8*7/</;0:2:6;68554286:5:6:78777675449496976746/6-6*7+8)8)9'8'8%8%8%:$<%>&?'A(A*@,=.71IKgrOdHf7]Am/_1^1XOjWfh39@*,?994443524925>-2<#29\u0018EC\u001dl`8}RuΗȕ}vbeQ_F`Bc@gDoJrOrRqUpVoLlKhGfFhIiLiNiOgKfJeIfIhIjJiGgEhJkMnP(0#*2'/4-350664<87@<9C>8IE<HE<KHCQQQ[[eabvab~`a_]ZXTTTT\\]gipsty{~ہބ݃؃օ҆ӃǄȃ˂̓ӄՆ؈ՍՋʋ|uqlirOVNQpUNc`OYgMVfI]dEo]ETF[TXYSZYa\\daekn|rsjxoYP[QD85':):'<(='=*<*:*8*7+/'2)8,;,<*;(;(<);*C4K=G:</4&5';,9)9)9)9)8)8)7)7)7);.?2?3@4A5;/3'..12495>3>0>0@/?.</</907.5,2+2)/1;3<5;59475565758697:6:7877767465:5:7:8774726-6+8*8*9(9(9(8&8&8&:\";\">$?%A(@*>-;1:6U\\_oGc>b8c6g0c4\\CbMaBIL44:97<<>948>58<7379+3=\"8D\u001eS[,PoȈˎ̒Í}{ggQ^E^@c@iDoJsPsSqUoUnMkJgGeEgHhKiNiNfLdIdIgHiJjIiFhEiKlNoQ&.!(0%-2+130333756:97>;6GD=DD<GFAOOQZZd_`t^_{\\]|`^\\ZYX\\\\ggqrz|}܁ゅ䃆ㄅႄہՁ҃ЄȃɄ̃΅Ն׈؋؍ҌƋxsntjfgSPuRLjWIe`MafO\\gI`cFn`FxR?[MZSRRUZV\\X``itkofqhD;A91%4&C29%:&;'=);+:,8,7,,#/%6)<,@->*<'8$5#B2OAN@B47)7)>/;+:*8(6'6'6(8*8+;.;/9-5*7,;1<29/7:8=:A8B4A.>,;,:/;19385857483645496;9<69453386;986979899896967465:5:7:7985827/7+8+9+:*;*:*:*:(9(: : =$?%@(@+=.81<?[hQhHh7]<j,]7i;XYpLUX00?<5<E@99;B3:G08F21?9+<E(DW*at=_|̌ɋĉzygfPZ|@]?a>hCoJrOrRpTnToMkIgFeFfGhKiNiNfKeJdGeHgHhGhGfDjLmOpR(0!'/\"(-&+-*.0/333775:94==5?@8DE?JLKQQYVWiZ\\s]^|YW[Y^]eennwxڄ䊌솇䂂܀ԂӃҀāǃɄΆ҈Ջ֌ҊǊ~xwpxkeec^XpZMm[Mi\\Kf^Kd_IcaHfbGl`FlR;UA^OaYYXPTQ[XbkcYRD<707/;/</;+9(:(:(:)8)7,5,4,/'2)8,>/@/@-=*9'9)0\"VJJ?.#=1</8*;*:)9(8'6&6&5&4&7);.>2<07,7->4E;AF8?3:4?2>-;,:2=7@5;687899:98665==<<:<8977767575979899::9;9<9<8<6;5:7:9::9;5907,7+9):):):):);*;)9!>%;#5\u001c:$E3@60.^eVgHc;\\0X/[5c<j\\mEOo33G6.9C8:E==9:B+3P-4N00D7'CJ)Wo=}_v~ˌ~~nfRXvBY{?]>c?iDnImLlNkQjRjHfDcBcDfGhKgLdJgMhNgKfHeEfEjImJpSrUtW*0\")/#).'+-(-/.222553782;<4>@5BC;HJGOPTSUaXYm[[s\\Z^]dakjus}Їዋ퍌텄 ڀ~ҀσυƆȇˉ΋ьЍΎɊ{x{stknkd^e\\SbaLb`Ke^Kh]Ii\\Ij^Hk_Gm_EraG{]C[F[LWPQSPXS`WQKF>9505/908,8*8&8&8&8)7)5,3,2,1'4)9+=-A/@-=*9(9)<.QEH<4(:-:,5&=+=+;*;*:)8)7)6(7*8,7,3)1'1(7.=4BH7>07/:0;.;1<6?6<3632:8EBJFEA?<:9:89796858598988788999:9;9<8=7<5:596888:8:5917-8*:*:*;*;*<+<+<+9\"?);$5\u001f;'</:2<=]iOd@[6Y5[:`=f@gEJ>>];2@>/3A05?4E=:X;?T-0X51ZI7bjEu[p||}yr`YuESq?\\{B_>b>iCmFlKkMhMhQhFeDcBcDgHiLhNgMiOiMiKgGgGfGjImLnQoRrU-1\"-1#,/&,.).0-11/34/45-9;0<>1@B5EH?KMLQRWUTbXWi\\Yx^]fcpmzxύᐏ퐎釃~|}ȁ}ǅĈƊʌˌˌǌ|v{pujpod`i_Ue\\MXeK]bKa_Jh[HmZIp[Hq\\Go]EtcItZ?V=WDYMTSNTIU@<<984616/6.6+7(6&8&8&8'6)5,3,1,5(6(9)<+@-@-=+8(5'J=E:A5</6(;+7&:):):):*8)7)5(3'8-6,3*3*2+6/:3=6;?4:070:2<3>7@=C7;AANKZUZURLB>62727474748596;8::7788898;9<8<7<7<38475777:7:48/7,8+:+;+<+<+<+<+<+9$@*9$7$;+2%40OTZiH`8U6V>]FfHfEat?9e?6QA2@C04?.29)>5,O61K*#W:,j\\B_t{yv|m\\uKHa7Nh9[xB_}?c?hBlEjGhJgLeMeCdCcBeFhIjNkOjNkOkOiMhJgHiHlIpMsVtWvY25$13&02'01+12-23.34.46+9;-;>-?B1DF9IJBNNNRQWTR]XVd\\Zoda~nlzwČؑ唑쓏펋扅ڂ{}}Ë}{vzm~sfmoa`k^Vi[NgZJVdJZbJa_JjZJpYIsYJtZIs]FqY?tU9T;ZF\\PRNEG:A3/4151505.4+6)8)7$8$8&9'6)5*3,2,8+7)7(:*=->/;-8+3)TK;38.A64'<->-7&8'9(:)8)7)6(3'5*3)2)4,:3>7?9>847596;5;2:397=<@UVc`njidVQA<613/71717182859697::78898;9<8<8<8<8<48686787;7<49/8.9,;,;+<+<+<+;*;*:'@,8&9';-+\"54_gSdE];U<XG_OdP_KZcPAVI8JE2CF1AF0<?*<7#>1\u001eB2\u001bSE*okHfttqt}l\\K_:BV1Lc7Yq?_{@d@iAkDiFgIdJbLcBcBdCgHjMkOmQnRjPjNjLiJgGiGmKqMuYvZx\\78(78*66,56056156167/68+;>-=@+@C.DG4IK=NNFQPNSQTVUSYY[a_lkius}Ȍ֕㔐䐍ދӄƁ}|{~zxsznzrfjm_\\j[Tk[NjZKjYI^bK_aKe^Kk[KpZLtZKw\\Kz[G{WAS=U?XFSFF?76012-3/5/4.2*2'5(9(7$9$:$:'8)7*5,3,>-:)6%8';+=.;.6,80\\T=54+A53$:(@-9):*:+:,;-:-8-7-3*1)1+71;7>:;77477;<<?69156:BFNOxwqna[KC832.73?<939382727275767868798;8<8<8>7=7=69797:::=:=7;2;/9*;*<*<)=)<(<(<(:(=*9':*9-0)AAgrL^E[BYF[N^T]VWSQSU@LN9JG4JE1FD-AA'>C#@G%MU.^g<xTfmnrzudRcC?O2BS3Oa;Vl=b{Be@iCjEiFeFbH`IeBdCgFiJkNlPnRoSjPkOjMiKiIkInKrOuYvZw[?>,?=.==1==5=<7;<6;=2;=/?B-@D+CG,GI1KM8NOASPITQLYXDZ[M_^Zgepqo{yƏӏՍъǃ~zzw{uzw|y|~~y|tzrvkqrffm`Zl[QlZNl[KmZKmZIg^Mi]Mi]Mj]Mn]Ms^My^M[I`OWGN@I=@56.0)0*515/4/4-2)3'6&;(9$;$<$<':)9*7,5,A.;(6#5#:)=.;/6->7ZTHA90@36&4 >)7'7'7'7(7)7*7,8-<3:293<7>:=9854196<9::8:>@ORccqpheUP=82+5.;7<::9<3:2:4837365556869697;8<8>7=7=6<8:8;8:;:>:>7<2</9);*;);(<(;':&:&<):(<):*7*?8TXdpK\\H]I\\L[RXWV\\R^OAP9FN9NI5K>+>4\u001b67\u0015>O#Jh4gTt\\cdfltxpn}\\Q`C=J09F,BO3O_;Xi=czDgBkDkDhFeF`G`GfCiFjKlMlOkOmQlRmQmQmPlLkJmJrOuQy]y]x\\CB0DB3DB6EB9CC;CC;BB8AD3CG0EH-GJ-JM0OO7RQ?TREURI[\\:\\\\@\\]Kaa_ihvrq{z~È{ystpqmolrntqwrwrtoskxrilmb^l_Vj\\OlZLn[Lo\\Kq\\Kq\\KrZNq[Nn\\Nl_Ol`PqaQy_N[K_SOEA8:25-1(1(5*706/4-3*4(5(6%9#;\"<$>$>'<';*9,8,D/<(5!4!9(<.9/5-83NISMB9B5@.2\u001d?(;,9+8*6)7+9.;1;3D=A<?;>;=;;:8877939584;:JJ\\[dcca=9824.81B=E@=;42;3;3928484667777696;6;8<8>7=7=6<686989;9>9>6<1<.8););(;';&;%:'9&?-7%=,:)3'QKkm\\fN^I\\HWJUSS]RfQjP=S<CL7JB/L7$F5\u001bFH!Tq;cTxoof~YXcd|YXeGGT89E-8A,:C.?I0JX7Wh>g{FhClEkDiGcFaG^GiFlImNnOlOjNkOkQpTpSpRoPoNqNvRwUz^z^y]GD3HE6HF9HE<GG?GG?FF:FG5GI1HK.JM.LO0QQ7SR=VSDWSG[\\4Z\\7[[C\\\\Rcbhmkuszx~{||zwsomjkfgbhdlflhlhleuibij`^g]Th\\NjZJl[Io\\Ks^Ms^Ms\\LzWQvYQp\\Ql`PkbQpcR{aP\\OULD>613/5/5+7*8)6/4-3,4*6*7'7%7 <\">\">$?'>'<*:,9,E/='3\u001f3 8';.9/5./*?;YTI@D7I75\u001fD,F7D5A3?2?3B7F<G?B;>9;77464657799>7:473<:IHML=;(%-(5/@9C=A;=8>;?>:2:292849596999:7:6;7<8<8>7=6<7<595878:8<7<4<0:-8(:(;';&:':&:&9%?,4\">,:*1&\\Xy|T_TbI[DRGOSPbSlS{rSC[C?H3B7%O6\"_K0prJiǀyt{qu]oHy}JXy|O\\d5:D)3=$4>&<E2=D2:B+EP2Ve<g{HiDlEmEiGdGaG^GkHnKoPoPlOiMjNjPsWsVsUrSrQuRwU{YtXsWqUSJ;SJ;SJ;SJ;SJ;SJ;SJ;SJ;VM>WN?XO@YPAZQB\\SD]TE]TEcZKbYJbXNcXRg\\Zmacsfmwjs|n{~p}ss~p}wjtobli\\fcb]a`[a^W_\\U_[R^ZOa[ObZMe\\Kg\\Ji\\Ii]Gk\\El]Fm]Dm]D_gOkiTqZH{M@RIWLTIWHN:G2?*;(:.7223,17.7.7.8.8.7-6+6+7+7+7+7+8+8+8+8+=.=.8(2!2!;*>/:,6+6-:2B8I>G9;,1!OGIAE=E;H?G@C><:54678:9:7772:3>5KAE;=07)5&8)>.A2;/<2>5=8;97967687>7>7<8:9997:5:35.6/818497989:9:;>9;99<<A=C;B6@3;+=+>,<*;(:'9&8%F2>//%-(IKkolqWZOPTQVOYP[P]R^V`XMb!:O\u000e3J\u0006Of xIhrtpakN\\lEWdHS\\GHN@=C9;<,AB4=?2:=2<B6:C2AN4Rc?\\tBgHpKoIlGjIjKgJlUmToUlPkLkHlHmFpJoIpJrNsPvUyYzZ{jo^dSWN?WN?WN?WN?WN?WN?WN?WN?XO@YPAYPA[RC\\SD]TE^UF_VGd[JcZIcYMcYOf[Uj_]nbdpcjrentgpvirvirsfom`ggZacW[\\\\T\\YRYVOWTKXTIXTI\\VJ^VIb[Ic[Hf[Gh[Hi]Gj^Fm^Gm^G]eNmhTt]MRFVMVMQHQEH9C2>,:)9,7042226-7.8.8.7-8-7,7+7+7+7+8+8+8+8+9+>/=.9(2 3 :)=.;,:-4*3+;0E:PBRCQAE@@;<6;5>7=89633696879687797=9?:C9?2:,6'5&8)=-@1A4A4@7=8976756686<6<7:89879795:392:3:3;6:8:899999;:=<=?=@;?6<2;-;+<,=+<);(:&8&7%z;)8)5*;5QPce]aMMNLSOYP\\R^S^U_V^VSg*Sg(^r3zOlzn`jFau@Sf9IY5FP7?H59?358/;<,AB4=?2:=2;A5:C2@M3Rc?]uCgHqLpJmHkJkLhKmTnToSmQkLjHlHmHpJnJpLsOuTxXxXxZm\\bQYH]TE]TE]TE]TE]TE]TE]TE]TE[RC\\SD]TE^UF_VG`WHaXIaXIe]He]Jd[Jd[Le[Qf[Uh]Yh\\\\i]]j^`k_ak__i]]f[YbWU`USYVMWTKTQHRNCQMBSOCWQCXRB^WG^WEaYFc[Fg\\Hi^Hk`Jk`J^cOmhUy_PXN[TVQHEE>@7>3<-9*8+9.:/;17-7-7-8.8-7,8,7+7+7+7+8+8+8+9+9+@1>.9(2 3\u001f:&=,=.?07+2(3(<0F9M?QB87432052:7>;=<;<8<5:27245697<8=8;-9+6'4%5%8(<+=.D7C6B8=7966455675:6:69797795:3:3:3;4<6<6;8:999889:;<@>A=>7:17+7(;,=+=*<(;(9&8%7$u8%y6%9,E=ROVTOOHHLHSLZO^SbUaW_V]UgxB{UnzzYYp:?R$AS)AQ-?L0:C.6<.690581:;+@A3=?29<1;A59B1@M3Qb>_wEiJsNrLoJmLmNkNpVqUoSnPlKkIlHmIpJpJpLuSxXy[uWqU_NVEOx>aXIaXIaXIaXIaXIaXIaXIaXI_VG`WH`WHaXIbYJcZKd[Ld[Le]Ff^Gf^Ig_Lg^Of\\Pf\\Rf\\Sh]Wh]Wh^Uh^Ug]Se[QdZNdZN]YNZVKVRFRNBPL@PM>RO@UO?WQAYTA[VC^WDaZGd]Jf`JgaKadSleUt]O[Qb\\YXDD9:;8:6808-8):*@.C17*7*8+8+8+8*8*8)8)8)8)8)8)9)9)9)A2>.9'4 2\u001e8\"=)@.>/9+6*4*7+;.</>02614023488;<=?;?6<38/505477764307(6'6&7&7&9':):*A3A4A7?8:78576676:6:68768694:4;492:2:4;7:8989789<:@<B?A;;26+5'7(;*<)<)<(:&8$7#6%z@,v5#6'E;OHMILGPLPHVLZO_RbTaVaW`W~]ztsYN`8/A\u001b->\u001c3B%:F.=F3;A3:=2;<4<=79:*?@2<>19<1:@49B1?L2Pa=`xFjKtOsMqLoNoPmPpTqUpRoPmLlJnJoKqMrNtSyX|]w[mSdJ[LS|DNw?cZKcZKcZKcZKcZKcZKcZKcZKcZKcZKd[Ld[Le\\Mf]Nf]Nf]Nf_Eg`Fh`IiaLiaNi`Oh_Ng^OjaRi`Qi`Qh_Nh`Mh`Mh`KiaLb_P^[LYVGTQBPM>NK<NK:NK:PM<RO>TQ>VS@YVC\\YF^[H^]I`aSf^QmWJ[Rhcb`LM@C:<7974709+>)D+H-7)7)8*9+9+9*9*8)8)8)8)9)9)9)9)9)A2>.:(7\"5\u001e7 >&B-<*;*:,8-8.:.<0>25<3:2736464646155:39385:8:662/,(9(:(:(:(:(:(9&7&:+<-?3?7=8:68687566666748493:3;3:2;2=5=9=:><=;==A<B<A:<37-5(7(;);)<)=(;(9&8%7$6#}C/s4\"y4$G:RGNFNEWNULXL[N\\N^R`UaWbYd|j]kJDS42@&$2\u001b-:&0;*5=.9?3<?6=>6:;3::29:*>?1;=08;09?38A0>K1Pa=ayGkLuPtNrMqPqRoRrSrSrQpOmKmIpLrOtQvSxY{^z_qVdJY?]NVGQzBe\\Me\\Me\\Me\\Me\\Me\\Me\\Me\\Me\\Mf]Nf]Nf]Ng^Og^Oh_Ph_Pg`Fh`IiaJjbMjbMjbOjbOjbOjbOiaNh`Kh`Ih`IhaGibHjcGe`Mb]J^XHXRBSM=MJ9KH7IH6KJ8LK9LM;NO=PQ?QTASVESVEYYM]WKcQEzXNhaeaUUOR=C8>6762:.@+E*I*7(7(8)9*9*9*9*8)8)9)9)9)9)9)9):)@4=/<+:$7\u001f6\u001d<#B*C.@/;,7*2(4+:2@81<2<5=8>:>;>:=9<485:8<;>;<861--'<+=,>*>*=)<(:'8%6%7);.=3<5;7;8;77575758494;4;4=4>5?7A:A;A>A?????B:@8<38-5(5'8(<*;*<)<(:&9'7%6$5#y<)r3!}:*OAYLRGOEVJZN[M[M[O\\Q^T`Ya[s}Xy`r|ZU`B9F,/;'0;+1;03=44;35<4:?8?B9?A6<<277+89)>?1:</7:/8>27@/=J0O`<ayGkLuPuOsNqPrSpSrOrPqOoMnJpLsOuRyX{Z|]x]qWgO]EV@`PYISzCg^Og^Og^Og^Og^Og^Og^Og^Og^Og^Og^Oh_Ph_Ph_Ph_Pi`QjbOjbOjbOjbOiaNiaNiaNiaNiaLh`Kh`Ih`IhaGhaEhaEhaEf_Le^Kb[H\\WDWR?PM:LI6IH6GH6GH8GJ9GK:HL;IM>HO?HO?PPDVRGYOChREYMULRLXWGJ<B7954:1@-D*D$6'7(8):*:*:*:*:*9)9)9):):):):):)?3</=,<)9 6\u001b: B)C-A/=/6)/%/'6.=60;5>:A?CBCAC@A>?1256::<;;7734.3+>+>+>+?,>+>(<';'7$7'8+8.8.92<7?;85858494:4;4=4>4A7C9C<B;A=?<=;<9>3:/8+6(7'8):);(=)=*<):'9&7&6%~5$v4$x5%B2UEXKQCPDZLZM[N]O\\Q\\R\\U[V\\W`hCX_=JS4>G,6?*2=-4>35?74=88>:=B<CF?EG<CC7@>/;9*78(=>0:</7:/8>26?.=J0N_;`xFkLuPuOsNrQrSpSqMrNqMpLoKrNuRyX`~az]qUfL_G[E\\HbRYISzCh_Ph_Ph_Ph_Ph_Ph_Ph_Ph_Pg^Oh_Ph_Ph_Ph_Ph_Pi`Qi`QmcWlbVjaRi`Qh_Pg^Og^Mh_NiaNiaLiaLiaJh`IhaGhaGhaGh`Kg_Je_Ib[H\\WCUR?PM:ML:EF4DG6DH7BI9BI9BJ;BJ;BJ;JJ@QQERPAUN<bM:qF6I>YSQOCE8:55:3>/>)<$8'8'9(;*;*;*;*;*:):):):):):):):)=2:.<,>+9#5\u001a9\u001e@':$<)?0;18.7/<5A;;B>FBGCE@?;7501.0,51:5<6:29.9,9,>+>+?,@-@-A+>*=*<(:(7(5)4*80?8D>:5:5;4;4<4=4?4@5C9D:C;A9?:;685739-7*5'6':)<*:)9&=*=+=*<)~:'|7'{6&{6&y1#8*G8REPBK?SE_SXKZN\\R]T\\V[VYTXSV^7EM(6@\u001e8A&>G2<D53=2-7/1737>7@E>GJ?GI;BC1?>);;#78(=>09;.69.8>26?.<I/N_;`xFjKuPtNsNrQrSpSqJqLpLoKoLrOwV{\\edx^jP]EYC^HeOcUZLSzEi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qj_Yj_Yj`Wj`Wj`Vj`Vj`TjaRjaPjaPjbOjbOjbOjbMjbMjbMg_Jg_Jf^Ie_Ib]I\\WCSP=ML:HI7EH7AE6>E5>F7?G8=H8<G7HJ=HL>AE4HK6YS;_F0K9j]f`SSDE@@?==5=0>/3$5&6'7(7(8);,=.<-<-<-<-;,;,;,;,3,7.;-;)8\"7\u001f8\u001e:\"B-<+7)4*6/<7C?HCBGDHCC:661808.5+:/9.8.8-9,:+<+>-=*=*>+?,@-A.B-@-<*:(7(6)6+8-;1=4:4<6?6@7A7A6@4@5G=E;A6;26.3-1,1+;-:,:+:*:);)<+=+~:'|9(|9({:({:(z9'x6&w4$z, A4NCMAL>REVHRG\\R\\RUMTLZUXSWR`^R[0IQ(AK&BK,>H/7@-2=-4>34;3HPEX^RW[LLO<DF.AA'==!:;+>?1;=0:=29?34=,;H.Pa=bzHlMuPsMqLpOrSqTpJqKrLrNsPvU{\\bfx^iO_G]G`JfOhRdU[LTyEi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qj^^j_]j_]j_[j_Yj`Wj`Vj`Vj`TjaRjaRjaRjaRjaRjaRjaRj_Kh`Kg_Jg_Jd]J^YEUR?ON<IJ8EH7AE6>E5?E7>F7>F7=E6BF8>E5=F1DN5HK0PB'yS<ubdX_YUTFG>>@=>982:+<-=.<.;-:,9+9+:,:,:,:,:,:,:,:,?9A:A7=/6#2\u001d2\u001d3\u001d5#7(;0A8E?IDJFJGBCEDC@;59/>1A1?.@1@0>0?/?-?.A.B.;*;*<+=,?+?+?,>+@.=-:,9*8+8-:0:190;2>5A7C7D7D9E8B6A4=1:08-5.5,5.=,=,;,;+:*;*<,=,~;*|;)y:)y:)x9(w8'u6't5&1)C9NCK?J>PDTIRGSJWQUOUR\\XWTSO\\XT]0Zc8_j@[eBIT66C)4@*<G6MXGYbQ_fTW\\FJN5BE*?@!<=\u001d9:*=>0:</9<1:@45>-;H.Pa=c{IlMuPtNqLqPrSqTqKpLpJqMtQxW|_c{aoUcJ]FaJeNeNcLdU[LTyEi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`Qj^`j^`j^^j_]j_[j_Yj`Wj`Vj`Vj`Tj`Tj`Tj`Tj`Vj`Vj`VlaMk`LiaLiaNf_La\\I[VCTQ@ML:HI9DG6AE6AE6?E7>D6=C5=F57@-?H3EM5AA%QA']Eu`WHbZebRSEFFHBD799+:,:,:,:,8+6)6)8+7+7+7+7+8,8,7,3/5/5-3(0\"0\u001e1 4$A2C7G?KFLGJFFBC?CCDA@:;1=/C1F4G3E3E2C2B0B0B/{B.xD.8*9+:);*<+<+=,<*?.=-;+9*8+9-:/;/7.90;0>3?3@4@3A4:,:,9+7+7+7,8.91=-<,<+;,:+;+<+<,};+z;*z;,w9*v8)u7(t6's5&91F<MBJ?H<ODSHQINGSOSOVS]XYUZTf_wS~\\`lxPJX46D#=J.MZ@eqYeoW\\fMNW<DJ.?D&=@!:=\u001e89);<.8:-9<1;A56?.<I/Pa=c{ImNvQtNrMqPrSpSsMpLnLpOuV{\\}`|boUfM\\E\\EdMhQeN_GcUZLSxEi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`QjaRjaRjaRjaRjaRjaRjaRjaRk_ak__k__k`^k`\\kaXkaWkaWkaUkaUkaUkaWkaWkaWkaXkaXncQmbPjbOjbOhaNe^L_ZGYVERO>MK<GH8DF8CE7AE6@D5>B3;I27C-EJ3IG0K<%mN9dO`NA5SLc_^^RUJMDH>C;/9-7+7+9-:/;0;0>4>4>4>4?5?5?5?5?=B>D>F=G<I>N@PDSJOGLGIEFCC?A=@<FDC??7<1>.D2H3J6G4F3D3C1B0zA.wC.uB/8+9+9+:,:,;-;+;+:+:)8)8*9,<-=/>09/8.9/:.:.:,9+8*7)7*7(6*7+8-9/;0=.<-;,9*:+~9*}:*};-|:,z;,y;,w9,s8*q6(q7)q7)B8G=K?H<I<ODUJTLPLSPQORO\\X_Xh^znkfuVYh=CR)?O(P`<crQetS\\iKNY;CL/?E)>B'=A&;>#78(:;-79,9<1;A57@/<I/O`<ayGlMvQuOsNrQrSpSqMoKoMsRz]|az^u[bJ^G[D_HgMjPfL`FbTY~KRwDi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`QjaRjaRjaRjaRjaRjaRjaRjaRk`^k`^k`\\k`ZkaXkaWkaUkbSkbSkbSkbSkaUkaWkaWkaXkaXocSnbRmaQkbQkbQhaOd]M`ZJVSBRO>MK<IG8EF6DE5BC3@A19K1>H/JH1Q?+e>-ZL`S>64+@9XUigdeRUINKQJ@F<@6>4@6D:G=G>JAJAJBJBKCJCKDKDRTSTTPSMSLSLTNUNLHHFEBB@B@B@EBEBJHD@>7>2A2C1F3I6F3D3C3@0@1}?0y@/x@19.9.:.:.;/;-;-;-9*9*9+9,:+;-<.=/;/:/9-:.9,8*8*8*8)8)8(8)9*:,:-;-;-:,9+~9*}8)}7+|8+{9+z8*y9-x:-t9+q5*o5)q7+r:-G;H<I=I;K=RFWMWOQMTQRPVQ`YbWh[whivKZi>JY.AR&IZ0Wi?dvLj|TXjDL\\8?M,:D)<D,>C-=@-:=*89):;-68+8;0<B67@/;H.L]9^vDiJtOtNsNrQsTqTmJmLpPxY|_z`rXiQYC\\E`IeKgMgKfJdHcSY{IRtBi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`QkbSkbSkbSkbSkbSkbSkbSkbSla[lbYlbYlbXlcTlcRldQldQldQldQlcRlcTlbVlbXlbXlbYocSnbRmaQlcTlcTkbSg`Pd]M]WGYSCSM=MJ9KH7HE6DB3B@16J.>H-NC-b=-D:VPMJ++:9=;TPpnwvehY^]cVOOHG@C<D=G@GAGAHCIDIDIEJFJFKGKGGJGIGHGGHDHDGDEBBAAB@CBBBBB@A>A=JIB@<6>3@3A2B0D3A2@2>1=1<2<1=1}=1:3;3;1;1<1<1=/=/=/</=-;,;,9+9+8):/9.9/;/;.=.=/>.9)9*:*;+;,;+;,;+:,9+7)~6*{5){5)z6)z6+x6*x8,w9.s7,o5)o5)r:-u=0L>K>J<M=QCVHXMWNMIRQTR[We\\y_PcXFb]IBP,?M)?O(K\\2_qGk~QcyKVk@M_7@R,6E&7D*=F1=D4:=27:19:*:;-68+8;0<B67@/9F,IZ6Zr@eFrMsMrMrQsTqTlKoOsUx\\z_s[iQ`JXB^GdMgMfJeIgGhHaQXzHQsAi`Qi`Qi`Qi`Qi`Qi`Qi`Qi`QkbSkbSkbSkbSkbSkbSkbSkbSlbXlbVlcTlcRldQldOldMldMldMldMldOldQlcRlcTlbVlbXocUmaSkbSlcTmdUlcTi`Qf_Ob[K^WGWQARL<OI9LF6IC3F@02K+>G*SA+{E9NLEH5<19@E?@JIb`rpopbeZ^RJLDD=B;D=E>C<?9C=B=C>C?C?D@EAEA?D@DDFFHIHJIIIFHACADAEACAA@>>:=8EG=<73;4@4?1>0A1=/<0;1928193:4;4:4:4<3<3<3}=3}=3|<0{=0{=0{=.{<-z;,y:+z8*z8*:0:.:-:.:.;.<.=-9):):*;*;+;,<+}<*8,8,~6*}5)|4(z4(z4*y5*u3'v6,v8-r6+n4(n5*s:/v@4PBN?N=R@VFXIUJRINIRPSO\\VfZl\\LML7BL3@O.KZ9WgC`rJezOdzLVl=G]/AV+7I#0A!5C*=F5<D98=7796:;+;<.68+9<1=C77@/7D*FW3Um;a}BoJqKrMrQtUrUnNqQuWv\\sYjR`J[E^G`IbKeKfJhHfEeD`PWyGPr@i`Qi`Qi`Qi`Qi`Qi`Qi`Qi`QkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcRldQldOldMleKleIleIleKldMldOlcRlcTlbVlbVnbTmaSkbSkbSmdUlcTjaRh_Pd]M`YIZSCUN>QJ:MG7IC3GA13M*>G*[B.PGVV7?'3BN:C9>;:HG][gf[]ILJDF@C=C>GBGBB>=9C?B?C@DADBECECFD>C?DBEEGGGFFBC=AAD>C;A<>>>A?D@FA@C7830:4?4>1=/?2;.9.8061717384:5:3:3:3~;3|<3|<2{=2{=2u9.v;-w<.w<.x=-x=-y;,y;,{;1};/~8,7*6)5'6(5&7(8(:);)<+<,~=+{<*8,7+~6*|4(|4({2)y3)y5*t1(u5+v8-r6+n4)n5*t;0xB6TEQ@P>UBYHYISGNGSNRPPKVObUeZHFK4;K0IX;[jKgxVewQYnCSi;Me5I`28M\"-B\u001b*;\u001b2@):E7;B;8<;7;<<=-<=/79,9<1=C77@/6C)DU1Rj8_{@mHpJqLrQtUrUqQtVuYsYmSdN\\HZDdNaJ`HcIfJiIeDa>`PWyGPr@i`Qi`Qi`QjaRjaRkbSkbSkbSjaRjaRjaRjaRjaRjaRjaRjaRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTo\\Nq_QtdUrdWnbTj`Th`ShbTgaSebQa^K[VBVQ;TN6NH.GA'RD)N=#cI2iVzmng[WPQBE@E@GBFDGEIGIGIBEBEBDEEDBC;D:H;F7H9H:G?EBBD?F=EBDBDBDDEDEEDEDEDDAC@B?@>?=?=?=@>E??8:280:0>4@3?2A4|@5}?4<3:3837372<-<-<-;,;-:,:,:,9-9-9-~:/~:/~:/~:/~:/~80~80}90}90}90}90|90|90|90|90z:0y9/y9/x8.w9.w9.w8/w8/v7.t8.s7-r6,q5+p6+l2'q7,m4)l3(o6+m4)q8-H=ULTLQKPJNJNLNMPLSMUK\\NdOkaFTW8JX5N_;gT`zMWpFTkARg@O`<IX7DQ39C*5=&49%7:)=>0CA4B@4@<12:/2:/4:.5;-9=.<?.>A,>D*T^<bqHqTtVtUrSsSrQv^ggqYcK_G_G^F`HbJdLfNeMcK`H^F_OTvDKm;i`Qi`Qi`QjaRjaRkbSkbSkbSjaRjaRjaRjaRjaRjaRjaRjaRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTsaSr`RrbUqcVrfZpfZmeZjdXgdUkhYmjYlgThcOd^H[U=RL4PJ0F?%P@)kP;WGNBD=C?VTSRPQNOLMLKKHJHRTFG<<;:A@E?B9>4E9F9G=G>GDCEAE?GCDCDCDDEDEFDFDFDEAC@B?A>A=A=@=A>FAB<=6:090;/=0=0A4|@5}?4<3:3917172<-<-;,;,;-:,:,:,9-9-9-~:/~:/~:/~:/~:/}90}90}90}90}90}90|90|90|90z:0z:0y9/y9/x:/w9.w9.w8/w8/t8.s7-r6,r6,p6+p6+k1&q7,m4)l3(o6+l3(p7,~H<SKTJQJPJPLOMPNROOGSH[K{ePsiPhkLdrOgxT\\uKXoEPf?Ka:K_:K\\:GV7CP4<F-8@)6;'7:)<=/?@2@>2><03;03;05;/6<09=/<?.>A,>D*Q[9^mDmPpRrSqRsSsRxa|exakT`I]F]F\\E`IaJcLeNdMbK`I^G]MRtBIk9i`Qi`Qi`QjaRjaRkbSkbSkbSjaRjaRjaRjaRjaRjaRjaRjaRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTtbTo_Pm]Pm_ToeYog\\keYhbVfbVpl`{xi~{jzgzuapiVf`JPV<DF.A?(MB.S@/U8(^6*m=3p7.x71:3@9HBOHWP\\R[WROFEA?CBFCD@?:A9C:E>G@GCFFEFDGCDCDCDCDDEECECECDBE@D?C>C=C=B=B=F@E=C:>5:/8-9,<-A2~@3}?2=1:1918180<-;,;,;,:,:,:,:.9-9-9-~:/~:/~:/~:/~:/}90}90}90}90|90{8/{8/{8/{;1{;1z:0y;0x:/x:/x:/x:/t8.t8.s7-s7-r6,q5+o5*o5*k1&o6+m4)k2'n5*i3'm7+}G;QIPIQJQLRMRNTPUPVO[P^OtbNoiQnrWjwYfwWPf@K_:EY6BV3EV6GV7FU8ER8?I1<D-9>*7;*:<.<>0<=/:;-5<45<46<26<09=/<>0=@-=C)MV7Zi@h|KlNpOqRuStSzcw`nWcL\\E\\E\\EZC_HaJbKdMcLaJ_H]F[}KPr@Gi7i`Qi`Qi`QjaRjaRkbSkbSkbSjaRjaRjaRjaRjaRjaRjaRjaRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTtdWqaTm_Rk_SkaWlcZle[jf]jf]wuiy|rygZfNLV>AI2CF1ED0D?,I=-TD5M:+O8*R6*T7)X8+];/a?3eA5KASLUQNKEDABCCEF?>@=B>D@EAFDEDEDCDCDDDDDDDEDEBGCFBE?E>E>D=D=E=E=C<E?E>@8;/8,9+;.@2@1~?0=/;/:/9/90;,;,;-:,:,:,9+9-9-9-~:/~:/~:/~:/~:/~:/}90|90|90{8/{8/{8/y9/x8.{;1y;0y;0y;0x:/x:/v:/v:/s7-s7-s7-r6,p6+o5*o5*n4)j1&o6+l3(h2&k5)h2&l6*|F:OGPHQIRMSNUPWPYQ]RaUy_PiZGd_IciOZgKN]@EU8AQ4=M0<K.?M3CQ7FR:GS;BK6>G2:A/7>,9=,9=.8<-7;,6=66=66;46<29<1;=/<?,<A*JS4Ve>dxGjLpOsTwUwT{dr[eN\\EZC\\E\\EZC_H`IaJbKaJ`I^G]FY{INp>Ef7i`Qi`Qi`QjaRjaRkbSkbSkbSjaRjaRjaRjaRjaRjaRjaRjaRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTseXugZsg[mcYjaXle]snhzwp~wv~i`hSLSADK9AJ7>G4>G4BI7GN<FJ9CF5?@0=;,<:+<9*<9*U5(lD8PHPLHIEIDIAE>B?@AAC@EAEAEAEADFDFDFDDEDEDEDEAFBFAF>E=F=F=F=G>@9B;D=B9>3:-;.=/?0?/~?0=/<-:-:-:.;-;-:,:,:,9+9-9-9-~:/~:/~:/~:/}:1}:1}:1|90|90|90{8/y9/x8.x8.v8-y;0y;0x:/v:/v:/u9.u9.u9.s7/r6.q6.p5-o4,n3+m4+m4+j1(o6-j4*h2(j4*g1'k5+zF;MGNHPJSLUOWPZPZQ{YMv\\OkZJ]UBYXDY^HOYA>L3;G18D.5A+5A+8D.=I3AM7EN;BK8?H5<E29B/7@/7>.5<,4;+5;75<56;56;48;2:</;>-;@)GP1Ra:buGiKqPuVyWxUzcnW`IZ}C[~D^G^G]F`IaJbKbKaJ`I_H^GW{KLp@Bf6haQhaQhaQibRibRjcSjcSjcSibRibRibRibRibRibRibRibRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTmaUndXpf\\lcZkd\\rmg|ľtfcTPQAEI8=F38E18G45F35F44E36D58D6;E:?G<@H=<6(L</b@7EAOOW[OVBIDJDFDFEBEBE@D?C?DFDFDFDFDCDCDCECEAFAF@F=F<F<G=G==8@9B:C9A7>0=/=.>/?/>.=-<-;,;,;-:,:,:,:,9+9-9-~8,~:/~:/~:/~:/}:1}:1}:1}:1z:1z:1y90y90x8/v7.v7.v7.u9/u9/u9/s9.s9.s9.r8-r8-q6.q6.p5-o4,n3+m4+l3*l3*h2(l6,i3)f2'h4)e1&i5*xD9KEMFPJTLVOXNYO|\\Os\\Nk[L_XFUTBPS@JQ?@I64@,3<+2;*09(09(2;*5>-9B1<E4?H7=H7<G6:E48C25A-3?+1=)3973954954937:19;0;>-;@*CL/O^7_rDiMrSwXyWvUs\\fOZ}CX{A\\E]F]F^G`I`I`I`I`I_H^G]FVzLJn@Ae7haQhaQhaQibRibRjcSjcSjcSibRibRibRibRibRibRibRibRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcTiaVjbWkdZmf^upjҺzym__YIKL:>F19E1<K8;J79G68D68@57<57947836A3>>2J91`94HH\\__dVZOSMOLKJJHEFBDAA?DFDFDFCECEBBCBCBDCD@E?F?F<F<G=H=>8?:B9C:C8A4<-9)>->.>-=,=,<,;,<-:,:,:,9+9-9-~8,}9.~:/~:/~:/}:1}:1}:1}:1}:1y:1y:1x90x90w8/t8.s7-s7-s9.s9.r8-r8-q8-p7,p7,p7,p5-o6-n5,n5,m4+l3*i3)i3)g1'k7,h4)e1&h4)d0%f4)uC8JELHPJTLWNYOx[Mp]Nj^N]WGPQAKN=CJ:9B12:+08)36-17-06,/5+/5)17+2:-4<-9D4;F6=H7<I7:G56C/3@,1>*0640641622716929;0:<.:?)?H+KY5]pChLsTwYwWrQiT^IUx@WzB[~F[~F[~F]H_J_J_J_J^I^I]H]HUvKJk@@a6haQhaQhaQibRibRjcSjcSjcSibRibRibRibRibRibRibRibRkbSkbSkbSkbSkbSkbSkbSkbSlcTlcTlcTlcTlcTlcTlcTlcToh^ng_lh_tqjũsbaZGML7CH2AI4AH6BF7BD7C@9D<9C98C772?5;@9@93H/+c76QRgimm[\\YWUSQNKKGFBB@ACGDFDFBEBEADBBBBDCCBC?C>E>E>F<G=@;@9@9C9D:B5;-5&=-=.>-=,=,<,<*=+:,:,:.9-9-~8,}9.}9.~:/~:/}:1}:1}:1}:1}:1{;2w;1w;1v:0u9/t8.s9.r8-q7,r8-q8-p7,p7,n8,m7+m7+m7+o6-o6-n5,m4+j4*j4*i3)h4)f2'k7,h4)c1&e3(b0%e3(uC8JGNIQJTMXOzZMq[Mh\\LXUDHK:=D4=E69A208+/7*5=056157257247005.06,08-19,6A3:E5=J9>K9;J77F12A,0?*.42.420511605818:/:<.:?+<E*IW4[nAgMrUvZuWoPbMX{CSv>WzB[~FY|DY|D\\G_J_J^I^I^I]H]H]HSsJHh?>^5icSicSicSicSicSicSicSicSicSicSicSicSicSicSicSicSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUmdUmdUmdUmdUmdUmdUfc\\gd]vsnȷɴicbFGG-EG/DF0GD3IC5H;3F42G34M797@;;@:@;8G85cGFkjŔ譩ҋtn]XSNNNIKEICGFHHKCF:>>@FIDG:;@@@@A@B>C>B<B;B;A<@9?8A7B8@4;.8*>.>/?.>-=,<+=*=*9-9-9-~8,~8,|8-|8-|8-}9.|90|90|90z:1z:1z:1z:1x=5w<4v;3u:2t91r7/p7.p7.o6-m7-m7-m7-m7-l8-l8-l8-i2+m6/p92o81k4-g2*g2*h3+e0(i7.d2)^,#`0&_/%b2(p@6LJOKQJQJ}YMv_QfYIRO>CF5=F58C35@02=/3;04:04:077577566446135016/05..6+.9+2=/6C29H5:I68G42D./A+,20,2.-2..3-36/780:</:?+6>&DR1YkChRu[w_rWjN\\}HXyDTu@Tu@WxCZ{F[|GZ{F^JbNbN^J\\}H_K`L^JTrNFd@:X4icSicSicSicSicSicSicSicSicSicSicSicSicSicSicSicSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUmdUmdUmdUmdUmdUmdUed_onjͱcgkJMP1II/EC,HA/J>2L93M85Q99;;9BA?MHE\\RQyjg̳ǿ괪̃|c\\VTPSFM=DEEEEGHIKEG<><>@C>???@@A@B>B=A<A;@:@;?8A:C9A6;/9+=.>/>.>-=,<+=,<,9-9-9-~8,}9.|8-|8-|8-|90|90|90z:1z:1{;2{;2{;2v=4u<3t;2s:1r90p7.m7-m7-m7-l8-l8-l8-l8-j8-j8-j8-l5.n70n91n91l7/i4,g2*e3*c1(e3*_/%^.$b2(^.$`0&n?5IEQLWRWOrVKdRDQJ:>?/:A16A14A02>02<14<15;17:388677577557446116005./7,.8-1<.4A07E49H58G44E22D.062.40.3--2,14-45-8:-9=,7?'DQ3YkEhSv`wbpYfNZzHWwETtBTtBVvDYyGYyGYyG[{I_M_M\\|J[{I^~L^~L\\|JTmOF_A9R4icSicSicSicSicSicSicSicSicSicSicSicSicSicSicSicSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUmdUmdUmdUneVneVneVddby{xشĝj`hCRW7DG,EC.KD4MC9N?8L=8C:;SJKi`axv画ecACBINVVRLIDABAFEEFCDBD=?>>??@?A@A=B=A<?:@:A:D<D<B7<29.=0=0>/>.=-<+=,=,9-9-9-}9.}9.|8-|8-{8/}:1}:1{;2{;2{;2{;2{;2{;2t;2s:1p:0o9/n8.m7-k7,k7,l8-l8-j8-j8-j8-j8-i9-i9-n91m80m80m80m80i7.f4+c1(c3)a1']-#_0&c4*\\-#_0&sD:OKUPXQqSK^J?OC7?<-37(2:+/<+0<.2=/4<15;17:37:388688668557257227016/08-.8-0;-2?.6C27E48G48G48G46=53:2/4-,1*.1(13(57*6:)6>'DQ5[lHkZyfwflX^KWwEUuCRr@Rr@TtBVvDWwEWwEXxF[{I]}K[{I[{I]}K\\|JXxFPfOAW@3I2icSicSicSicSicSicSicSicSicSicSicSicSicSicSicSicSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUmdUneVneVneVneVofWgkl۲}cdnKLS4EI0HJ5KI:GE9D@7QEEk__莎bd>CPITMOJF@FBMJJI??>>>??>@?A?B?B?C?>8?:C=E?E>B9=5;2<1=0=1=0=-~<,=-=-~:/~:/~:/}9.}9.|8-{8/{8/~;2|<3|<3{;2{;2z;4z;4z;4p:0o9/o9/m9.l8-k7,j6+h6+i7,i7,h8,h8,h8,h8,h8,h8,o:4j81h6/i70j81j81e4-a0)e4-b1*].&a2*b3+Y*\"_3*zNE~]XvWRiNGWC:J<3@:.:;-8<.08)/:,1<.2=/5=25;169078079468368349338138119.19..9+/:,1<.2?.5B18E4:I6;J7;C87?428.-3)-0%/1&24'48)4<'ER8_pPrd}nwifXT}EUrBTqASp@Sp@TqAUrBVsCVsCWtD[xH]zJ\\yI^{K_|L\\yIVsCK\\J<M;.?-gdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUmdUneVneVofWofWpgXmruҭ|bX_@GL5DL7DK;AG9>D8f\\Z|z즤ifK=QDYN[QQHD=A<D@@=?>@?B>C?C?C?C?>9@<D@E@D<@9>5<4<3=2=1=0=/~<.=/</~:/~:/~:/}9.}9.{8/{8/{8/~;2|<3|<3{;2z;4y:3y:3y:3m80m80l7/l7/k6.h6-h6-h6-h8.h8.h8.h8.g8.g8.g8.g8.k92h6/f4-g5.i70h70e4-b1*b3+b3+_0(_0(]1(V*!b6-SJn[U`OHN?8A7.=6,;9-9;.7=12:-3;.4</6<06<07:167/56.49249238139/39/2:/19.19,.9+.9+/:,0;+2?.6C29F5;H7=E6:B35;-06(/3%/1$13&15&29'GS;dtWwm~rqg\\QIq?Qn>Qn>Qn>Qn>Qn>Qn>Sp@Sp@WtD[xH]zJ]zJ_|L_|LZwGQn>ESF6D7(6)gdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUneVneVofWpgXpgXpgXinrz׹ĥregOMP;EL:EM>EODGSG~zqƽߑ}fSK:UFWKF;@8KEC>C?B?C@C>D>D>C=@<C=E?D?A;=8;5<4<3=4=3=2=1~<0=1=/~:/~:/~:/}9.|90{8/{8/{8/|<3{;2{;2y:3y:3x92w81w81m80l7/j8/j8/i7.i7.g7-g7-g7-g7-f7-f7-f7-f7-f7-d8-i70h6/g5.f5.g6/h70g6/e6.a2*e6.^2)\\0'`4+a5,i=4|PGQJBE>6:6-85,99/8:/47,36+4:.5;/5;/69.69.68-57,46+19,19,19,19,19,19,19,19,08+.9+.9+/:*0;+3>.6A17B2<E4:C28?/5<,37)24'13%04%07%HT>gw]umvnf_RwKAh;Mj:Nk;Pm=Pm=Nk;Nk;Ol<Qn>VsCZwG]zJ^{K_|L_|LVsCLi9=H@/:2#.&gdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUneVneVofWpgXqhYqhYcjpmtzƯ}vn[ZWFOQCQWKYcZbmeq[WDSCQBMAJAG@E?E@E@E>D=C<C<C?D@EAC==9;5;5<6<5<6=5=4<3~<0=1<1~:/~:/~:/}9.|90{8/{8/y90{;2{;2z:1x92w81v70v70u6/k90j8/j8/j8/j8/h8.h8.h8.g7-f7-f7-f7-d8-d8-d8-d8-h6/h70i81i81h70i81j;3l=5g80k<4b6-a5,oC:xLCtI@uJA:=647036/7:18;247.14+25,58-58-57,46+46+46+46+46)/7(08)08)08)08)08)08+08+19,08+08+/7*08+19,3;.4</9B/:C0;B0:A19=.68*24&/3$29'IU?eu[mghbWyTInE>e9Jg9Li;Nk=Nk=Li;Li;Mj<Ol>UrDYvH[xJ]zL^{M\\yKQn@Eb47@;+4/!*%gdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSgdSkbSkbSkbSlcTlcTmdUmdUmdUmdUmdUneVofWpgXpgXqhYriZhowmt|ʹƯsce]P[YM_bYovo|Ȱ}gO=Q@RDC8IAH@F@F@E=D<C;C;D@E@E@A=;77493<6<5<6=5=4<3~;2<3=1~:/~:/~:/}9.|90{8/{8/y90z:1z:1y90w81v70u6/u6/t5.k90k90j8/j8/j8/i9/i9/h8.f7-f7-f7-d8-d8-d8-d8-d8-f5.i81l;4k:3j92j92m>6qB:n?7pD;g;2g;2SJaXTKpE<6=52913:27<5492/5+25,9<345-35*24)13(13(35(46)57*,7',7'-8(-8(-8(-8(-8(/7(19*08)08+/7*/7*/7*08+08+7@+9B-=D2=D2=A29;-35'/3$3:*JVBcr[f}a\\wVLnICgA=c:He7Kh:Nk=Nk=Kh:Jg9Li;Nk=TqCWtFZwI[xJ]zLZwINk=A^05;9*0.!'%heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVhdYkd\\kd\\md]meZmfVg`MjeOnlWnl]ff^eeeqqyֵymvW\\fK`lTq~lЪa\\D=MEKBC:A7D:H>JAI>G>J2K4L5K4H2F2E3E5D5C6@4>3;29/7/6-~:1~:1}90|8/{7.z7.y6-x5,w7-w7-x8.x8.v8-u7,s5*q3(h91h91h91g80h70g6/g6/g6/f5.h6/i70j81i70h6/f4-g2,k1-k4/n70m80k9.j:.i>.iB1dC2gJ8aJ8raOyn\\|jqOL;4:04:04:039/39/39/28.28.17-17-17-06,06,/5+/5+/5+/4./4./4./4./4./4./4./4.05//4./4..3-.3-/4./4.05/0;32=55A77C98D86B64@22?.3@.DQ=WeN\\jSSaHHV=DR8FT:Ic>Ke@Ke@Ke>Je<Je<Lg>OjAUpGYtK\\vO]wR]wTWpPHaC8Q3).2&+/$)-heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVhdYkd\\kd\\md]meZmfVjcPlgQmkVlj[gg_lll~~ЯvkrSYaI_kUto}uJ@K@J<K>J>D9=2?6D;H3J7M9J7G5C4D6F7C7C8A7>5<4:19181}:2}:2|91z:1y90x8/w7.v7.u6-v7.t8.t8.t8.r6,p4*o3)i81i81i81h70h70h70g6/g6/e3,e3,g5.h6/j81j81j81k92k60l71m80l:1k;/l>1j@0iD2hG6kP=gR?ufSvdsrML:4:039/39/39/28.28.28.17-17-17-17-06,06,/5+/5+/5+/4./4./4./4./4./4./4./4.05//4..3-.3-.3-.3-/4.05/-80/:21=34@66B66B66B45B16C1CP<P]IR`IIW>AO6BP7FT:Ic@Jd?Ke@Ke>Ic<Hc:Id;Je<SnEXrK\\vQ]wT[tTTmOC\\>3L/).2',0$)-heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVhdYkd\\kd\\md]meZmfVmhTmhRmkVjk[jkcvxwۿʫyuy^kpZt{iٞL=Q@K;>1G9XMTJ?6D6H9J=I=B7?5A7E=A9A9@:>8~>5<4<4;4x<2x<2w;1w;1v:0u9/t:/t:/s9.r9.r9.r9.q8-n8,l6*k5)j81j81j81j81i70i70i70h6/g5.g5.g5.g6/h70i81k:3k:3l;4k:3i:0j;1k?2lB4iD2fE2fI7lVAjYEviVl{mEF439/28.28.28.17-17-17-06,17-17-17-06,06,/5+/5+/5+/4./4./4./4./4./4./4./4./4./4..3--2,-2,.3-/4./4.*5-+6.-9//;12>24@46B47D38E3?L:ER>CQ:;I28F->L3ES:H`>Jb@LdBKc?Ia=G`9F_8G`9RkDXpL]uS^vVZqTPgK=T8,C)).2',0%*.heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVjcYkd\\kd\\md]meZmfVniUljSlkVlm]pqiؼǫ}ſınQ>P=XHL?D7G<>4D;H?F>?9;6=8A>?;@<@<}@;z?9y@9x?8v?8v=4v=4v=4u<3s=3r<2r<2q;1o;0o;0o;0l:/k9.j8-j8-i7,n72n72m61l71l71k60i70i70l:3j92h70g6/f7/f7/h91h91j?6f>4e=1f>2hC3iE5gF3cG2cJ6hV@k\\GskVnzor_9>*28.28.17-17-17-06,06,06,17-17-17-06,06,/5+/5+/5+.3-.3-.3-.3-.3-.3-.3-.3-.3-.3--2,-2,-2,-2,.3-.3-)4,)4,*6,+7-.:01=14@25A36C2:G5<I58E12@)2@)8F/?M4DX<G\\=K`ALa@K`?I_;H^:H^:SiEZoN`uV`tXZnSNbI9M4(;%',/%*-$),heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVjcYkd\\kd\\md]meZmfVlgSkiRnmXop`svmؿʱ½ÝcPK8L:O@M>=7A;D?C?<;989:====>>@?|A=xA<sB=rC=pC=s>6s>6s>6r=5p>5p>5p>5n>4n>4m=3l<2j;1j;1i:0i:0i:0p62p62p62o51m61m61k60i70l;4k:3h91e90e90e90e:1f;2dB6cA5cC4dD5fG5eH6cH3_I2^L6eV?jbKrmWnr[`L3;&28.28.17-17-17-06,06,06,17-17-17-06,06,/5+/5+/5+.3-.3-.3-.3-.3-.3-.3-.3--2,-2,,1+,1+,1+,1+-2,-2,,6.+5-*4,*4++5,.8-0:/2=/2=-5@06A05A-1=)1=)5A+9E/=O5AS9FY=I\\@J]?J]=K^>L_?TgG\\oQcvZbtZYkSK]G6G4$5\"&+.$),\"'*heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTheVjcYkd\\lc\\md]meZlfVlgSljSlnXorasvmθͺƶø̧lXZGVCM;A8B<D>D??>;;99:;<<>??=}@=wB<pC=mE=lF=q?8q?8q?8q?8p?8o>7o>7n?7o@8n?7m>6i=4h<3h<3h<3i=4r73q62q62p62o51m61l71j81h70g80e90e:1d<2f>4f@5gA6]C4aG8cL:dM;cM8`K6]K3]M4]Q9`Y?miPss[mt|eFO:2>(39/28.28.28.17-17-17-06,17-17-17-06,06,/5+/5+/5+-2,-2,-2,-2,-2,-2,-2,-2,-2,,1++0*+0*+0*+0*,1+-2,,6.,6.*4,*4+*4++5*-7,.9+-8*0;+4?/5@/4?.3>-3?+4@,7F/;J3@P6DT:GW<JZ?M]@O_BUeJ^nSdtZbqZXgRIXE4B1$2!&+.$),\"'*heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheTjdVjcYkd\\lc\\md]meZlfVljUllTkmWjn]lrhy}оλvaP:^HI>H=H>G@F@C@=:97<;=;>;A<wB:sD<nF<lH<q?8q?8q?8q?8p?8p?8p?8p?8qB:pA9n?7j>5i=4j>5j>5k?6s63r73q62p62n72l71j81i81d8/d90c;1d>3d@4cA5cA5bB5VG4^O<gVBhWCbS<^O8[O5\\R7]V<]Y>mmSsw^zjcmU2>(5C,4:039/39/39/28.28.28.17-17-17-17-06,06,/5+/5+/5+-2,-2,-2,-2,-2,-2,-2,-2,,1+,1++0**/)*/)+0*,1+,1++5-+5-*4,*4,+5,+5,,6+-7,,7)/:,2=/6A17B27B25@/4?.2?+5B.:G3>L5AO6ES:JX?M[BTbI]kTcqZ_lXUbPERA2>0#/#(..&,,$**heVheVheVheVheVheVheVheVheVheVheVheVheVheVheVheVjdTjdVjcYkd\\lc\\md]lfZlfVomXmmUimVgkZembr{x׭sYSAQ?N>O?OBJ@C:<4<7>8?6@7{B7tD6qE8nG8s>:s>:s>:q>:q>:q>:q>:p?:sB=rA<p?:m>8l=7l=7m>8n?9r73r73q73n72m82j81i81f:1f;2d>3d@4bB5`C5]A3\\@2[?1QI4[S>f^Gg_H`Y?ZS9ZS7\\W:ZV;WW;knSrx^u}eUaI%3\u001c7E.4:04:04:039/39/39/28.28.17-17-17-06,06,/5+/5+/5+-2,-2,-2,-2,-2,-2,-2,-2,,1++0*+0**/)*/)+0*+0*,1+)3+)3+*4,+5-+5,,6--7.-7,,6+.8-2=/6A39D69D67B46A1/<*2?-5B09F2<J3@N7FT=JXAR`I[iRanZ\\iWQ^MBN@/;/!-!+1/(.,&,*heVheVheVheVheVheVheVheVifWifWifWifWifWifWifWifWkeUkeWkdZle]md]ne^mg[mgWqoZkmUkoXkr`jrgozvecIO7T=YFQ?I:L?;0=0=0=/x=/t?/rC3sE5s<9s<9t=:s>:u@<u@<t?;q>:s@<r?;q@;q@;p?:o>9o>9o>9n72n72n93m;4l;4j;3g<3d<2c?3^>1dG9cG9T=-O8(M8'D/\u001eTR;PN7KI0MK2]Y>ieJeaDVU7XX<]`CosXzfcmT=I1,:#1?(5;15;14:04:04:039/39/39/39/39/39/28.17-17-17-06,16016005/05//4./4./4./4.,1+,1+,1+,1+,1+,1++0*+0*.5.-4--4-,3,-4--4-.5-.5-+2*-4,08-5=29A6=E:?G<AI>7B25@03>-1<+2>*9E/BN8IU?O[EVbN]hWYdTLWI<F;/90)3*)/-(.,'-+heVheVheVheVheVheVheVheVifWifWifWifWifWifWifWifWkeUkeWkdZmd]md]mf^mg[khWonYjlTjoXkr`jtiq|x߲uZ[AZBYCUAQ>F5F4D4D2}B0yB.s@-o?+v?:t=8u>9v?:t?9q<6r=7sA:q?8q?8q?8o>7o>7n=6n=6n=6l;4m<5m>6k?6j?6h@6eA5cA5dG9[A2^G7\\I8N=+F7$G8%A4!IM4GK2DG,BE*MM1[[?abC`aBYY=dgJsw\\sy_X`H8D,/;%6D-7=36<26<26<25;15;15;15;15;15;15;14:04:039/39/39/27127127116016016005/05/.3-.3--2,-2,,1+,1++0*+0**1**1*)0))0))0)*1*+2+,3,.5--4,.5-07/4;39@8?F>BIA:G69F56C13@.2?+5B.;I2?M6KXDR_KXeSVcRKWI<H<0<2*6,+1-*0,)/+heVheVheVheVheVheVheVheVifWifWifWifWifWifWifWifWkeUkeWlcZmd]md]mf^mg[khWmlWimTjoXktaiuiq}yjYAQ;[D]GR=F2w=)t=)t@+vC.xE2s>8p;5q<6vA;sA:p>7r@9xG@n=6n=6n=6m>6l=5l=5l=5l=5g?5h@6gA6gC7eC7cC6`C5^D5aL;UB1ZI7`S@RG3C;&E=(GA+>G,BH.@F*<@%?B%LO2_`AijKaaEnqTvz_gmSHP84<%4=(=F18>48>48>48>47=37=37=36<28>48>47=37=37=36<26<26<25:449349349338238238227105/05//4..3--2,,1++0*+0*(/((/((/((/((/()0)*1*+2+070.5.+2++2+.5.5<5<C<AHA?L;>K:<I78E34A-2?+3A*5C,DQ=KXDQ^LQ^MHTF<H<2>4-9/-3/-3/,2.gdUgdUheVheVheVheVifWifWifWifWifWifWifWifWifWifWleUldWlcZmd]md]mf^mg[khWmlWimThpXht`hthm|wڻּҽzyS<tJ2uH1wI2{M6~O;zK7o@.e8%{LBsD:qB8sD:qB8g;0d8-h<1j>3i?3i?3i?3f>2f>2f>2f>2aA4`C5`C5_C5^D5[D4ZE4VE3XI6OB/\\T?oiSc^HMK4IG0LJ3;E*?H->G*<B&<A#FI,VY:deFmmQxx\\tw\\[_F@D-6;%8@+<D/9?59?59?58>48>47=37=37=39?58>48>48>48>48>48>48>47<67<67<66;56;56;55:45:438238216005//4.-2,,1+,1++0,+0,*/+*/++0,,1--2.-2.051.3/+0,+0,-2.2738=9<A=?L;@M<@M;=J88E13@,1?(0>'<I5BO;HUCIVEDPB;G;2>4.:0.5..5.-4-gdUgdUgdUheVheVifWifWifWifWifWifWifWifWifWifWifWleUldWlcZmd]md]mf^mg[khWkmWjnUiqYgs_drejytܽչѷѾӾϴu`yVBlI5mH6rM;uP>mF7iB3gB2jE5nI9oJ:pK;oK;eA1eA1cB1cB1cB1cB1cB1bC1\\G6\\G6\\G6ZG6YH6WH5TG4RG3PH3MH2fdM~~fprZVX@IM4HL3;E*<F+?H+AG+AF(DG*MN/TU6xw[{z^nnTUU=AC-?A,>A.;>+9?59?59?58>48>47=37=37=38>48>48>48>48>48>48>48>49>89>89>88=78=78=77<67<66;55:449338227105//4./4.-2.-2.,1-+0,+0,,1--2.-2.,1-,1-,1-,1-.21043376598:H7=L9@O<@O:<K67F/4C,2A*6E.:I4@O<BP??M>8F91?2,9/.5.-4-,3,fcTfcTgdUheVheVifWjgXjgXifWifWifWifWifWifWifWifWleUldWlcZmd]md]mf^mg[khWkmWioUiqYgs_bpcgxrڻѵ˴˺ӿһurd|]I}^JrVAaE0W;&Y=(Z?*X=(`E0`E0_F0_F0`G1`G1^H1^H1[L9ZM:ZM:XM9XM9UM8RL6QL6NL5QQ9ikS|glrXSY?DM2>G,:G+<F+?H+DJ.EJ,DG*HI*ML.yx\\tsWfdKTR;LJ5KJ6FE3<=+:@69?59?59?58>48>48>48>47=37=38>48>48>48>49?59?5:?9:?9:?9:?99>89>89>88=78=78=77<66;55:4493382382/40.3/-2.,1-+0,+0,+0,+0,+/.,0/-10.21/32/32/32.210A.5F3;M7>P:=O7:L47I/6H.3E-6H0:L6<M::K95F6/?2*:--4,-4,,3+fcTfcTgdUheVheVifWjgXjgXifWifWifWifWifWifWifWifWleUldWlcZmd]md]mf^mg[jiWjlVhnThrYfs_aqdhysչ̳ŰĴ˴xt^GdP8aM5\\H0\\J2\\J2\\J2]K3\\L3]M4]M4]M4WO:WO:VP:VP:TO9QO8PN7NN6MO7PT;`fLfoTU^CEO4AK0:G+=J.?I.CL/HN2HM/FI,OP1YX:qmRjfKa]D[V@YT@TQ>MJ9EB1;A7;A7;A7;A7:@6:@6:@69?58>48>48>49?59?5:@6:@6:@6;@:;@:;@::?9:?99>89>89>8:?9:?99>89>88=78=77<67<6495273162/40-2.,1-+0,+/.,0/,0/-10.21.21.23-12,01):'/@-6H2;M5=O7<N4:L2:L25G-7I1:L6<M::K96G70@3+;..5--4,,3+fcTfcTgdUheVheVifWjgXjgXifWifWifWifWifWifWifWifWleUldWlcZmd]md]mf^kg[jiWikUhnThrYgt`brej{uҶȯſļtaP6RB(XH.XH.[M2[M2\\N3\\N3[P4[P4\\Q5\\Q5TO9TO9TO9QO8PN7NN6KM5IM4JN5LR8S\\AOY>?I.9F*?L0=J.AN2DN3HQ4LR6IN0JM0ZY;miLhdIc]C_YA_ZD`[GZUBQN=LI8=C9=C9=C9<B8<B8<B8;A7;A79?59?59?5:@6:@6;A7;A7;A7;@:;@:;@::?9:?99>89>89>8;@:;@:;@:;@::?9:?9:?9:?99>:8=95:6384162/40.3/.21.21.21-10-12,01,01-12-12$5\"*<&3E/9K3<N6;M3;M3;M38J09K3;M7<M:<M;7H81B2,<//6..5--4,ZgM[hN\\hP_iQakSckTfkWhkXfgUhgUheVheVjdVldWldYmeZjgVkhYkg[kg^kg^jf]hfZgeVfiVfkUenYbo^dqhsҿͼ̿·ƍnTO2UN1RL,SJ+WN/UO/UN1TO1SO2QP4QP4PP6QM2PO3QO6PP6MO7KO6HM6EM5HQ6FO4AJ-?F'@G&EK)GM)FL(ST2RS3MN.JK,TT8bbHccIZZB[YB\\ZC][B][B[Z>XW9UT6SR3KE/JD.FA-D?,A>/@>1??3>@5<=5;>59?59A67B48C57C57D3:B79A69A68@58@59A69A6:B7:B7:B79A6:B7;C8<D9=E:>F;7B:7C97A66A16?.4<-39-270.5./51-7/-9+-<%.B\u001f3J\u001e7O\u001f7Z 8Y$8W+:U2:R8;P==O?>O=:L6@R8EX:EZ;DY:>U93J0(>'.5-,3++2*ZgM[hN\\hP_iQakSckTglXhkXghVihVifWifWkeWmeXmeZnf[khWkhYkg[kg^jf]jf]hfZgeVgjWglVfoZerajwnz̹˾ǋlRM0TM0QK+SJ+WN/UO/UN1TO1SO2QP4QP4PP6QM2PO3PN5PP6MO7KO6HM6EM5HQ6EN3BK.AH)BI(GM+JP,KQ-NR/PT1VZ9^aBaaE[[?VV<UU=VV>VV>XV=YW>XW;XW9WV8VU7QK5OI3LG3ID1DA2B@3??3>@5<=5;>59?59A67B48C57C57D3:B79A69A68@58@59A69A6:B7:B7:B7:B7:B7;C8<D9=E:>F;<G?<H><F;;F6<E4:B39?38=67>76<83=51=/3B+9M*BY-Ia1Nq7Mn9Ji=Fa>AY?<Q>:L<:K9=O9DV<K^@LaBLaBF]A:Q7/E.-4,+2*)0(ZgM[hN\\hP`jRakSdlUglXilYijXkjXkhYkhYlfXmgYnf[og\\khWkhYkg[jf]jf]ie\\hfZhfWgjWejTdmXgtco|s˸öƉjPK.RK.QJ-SJ+VM.UO/UN1UP2TP3QP4QP4OO3QM2ON2PN5OO5MO7KO6IN7FN6HQ6FO4CL/EL-FM,KQ/OU1SY5QY0W_8jpLy]qvVY^@LO4MO7QQ9QQ9QQ9SQ8TR9UT8WV:ZV;XR<VP:RM9NI6HE6DB5AA5?A6<=5;>5:@69A67B47B47C57D3:B7:B79A69A69A69A6:B7:B7:B7:B7:B7:B7;C8<D9>F;>F;>IA>J@?I>>I9?H7>F7>D8=B;>E>;A=6@85A39H1BV3Pg;ZrB]F\\}HVuIMhEBZ@9N;5G74E3<N8EW=NaCRgHShILcG@W=4J3180/6.-4,YgM[hN\\hP^jRblTemVhmYjmZklZklZlj[liZnhZnhZog\\ph]liXkhYjfZjf]ie\\ie\\hfZhfWehUbgQajUerao|s~Ѿ˸ƳþķǺǊmPJ0SL0SL/UL-VM.UO/VO2UP2TP3QP4PO3NN2PL1NM1OM4NN4LN6KO6JO8HP8JS8GP5GP3KR3MT3PV4V\\8]c?fsGtUislnuTZaBRV;LN6NN6MM5NL5OM6TP7WS:YU<ZT>XR<TO;QL9KH9GE8CC7@B7=>6<?6:@69A67B47B46B46C2;C8:B79A69A69A69A6:B7;C8;C8:B7:B7;C8;C8=E:>F;?G<<G?<H>>H=>I9?H7>F7>D8=B;=D=;A=6@85A39H1DX5Ri=]uEY|BXyDRqEIdA<T:2G4.@0->,6H2@R8L_AQfGShIMdH@W=4J329107/-4,YgMZhN\\hP^jRblTemVgoZjo[lo\\lm[mk\\mj[nhZnhZoi]ph]liXkhYjfZie\\ie\\ie\\ig[igXfiVchRajUerao|s{ѿɶıþ˾Ÿ̌oRL2UN2TM0WN1VM.UO/WP3VQ3UQ4QP2ON2MM1PL1NM1NL3MM3LN6LP7KP9JR:LU:IR7JS6QX9SZ9U[9]c?gmIasxpr|Z\\bFLP7KM7LK6KI4NI5PK7TM:VP:WQ;VP:SN:QL9LI:IG:EE9CE:=>6<?6:@69A67B47B46B46C2;C8;C8:B79A69A6:B7;C8;C8;C8;C8;C8;C8<D9=E:>F;?G<<G?<H>=G<=H8>G6=E6=C7=B;:A:9?;5?75A39H1BV3Ne9Wo?Sv<St?NmAE`=8P6-B/*<,+<*1C-<N4H[=OdERgHLcG@W=3I2.5-+2*'.&"
  },
  {
    "path": "tess-two/jni/libjpeg/transupp.c",
    "content": "/*\n * transupp.c\n *\n * Copyright (C) 1997-2013, Thomas G. Lane, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains image transformation routines and other utility code\n * used by the jpegtran sample application.  These are NOT part of the core\n * JPEG library.  But we keep these routines separate from jpegtran.c to\n * ease the task of maintaining jpegtran-like programs that have other user\n * interfaces.\n */\n\n/* Although this file really shouldn't have access to the library internals,\n * it's helpful to let it call jround_up() and jcopy_block_row().\n */\n#define JPEG_INTERNALS\n\n#include \"jinclude.h\"\n#include \"jpeglib.h\"\n#include \"transupp.h\"\t\t/* My own external interface */\n#include <ctype.h>\t\t/* to declare isdigit() */\n\n\n#if TRANSFORMS_SUPPORTED\n\n/*\n * Lossless image transformation routines.  These routines work on DCT\n * coefficient arrays and thus do not require any lossy decompression\n * or recompression of the image.\n * Thanks to Guido Vollbeding for the initial design and code of this feature,\n * and to Ben Jackson for introducing the cropping feature.\n *\n * Horizontal flipping is done in-place, using a single top-to-bottom\n * pass through the virtual source array.  It will thus be much the\n * fastest option for images larger than main memory.\n *\n * The other routines require a set of destination virtual arrays, so they\n * need twice as much memory as jpegtran normally does.  The destination\n * arrays are always written in normal scan order (top to bottom) because\n * the virtual array manager expects this.  The source arrays will be scanned\n * in the corresponding order, which means multiple passes through the source\n * arrays for most of the transforms.  That could result in much thrashing\n * if the image is larger than main memory.\n *\n * If cropping or trimming is involved, the destination arrays may be smaller\n * than the source arrays.  Note it is not possible to do horizontal flip\n * in-place when a nonzero Y crop offset is specified, since we'd have to move\n * data from one block row to another but the virtual array manager doesn't\n * guarantee we can touch more than one row at a time.  So in that case,\n * we have to use a separate destination array.\n *\n * Some notes about the operating environment of the individual transform\n * routines:\n * 1. Both the source and destination virtual arrays are allocated from the\n *    source JPEG object, and therefore should be manipulated by calling the\n *    source's memory manager.\n * 2. The destination's component count should be used.  It may be smaller\n *    than the source's when forcing to grayscale.\n * 3. Likewise the destination's sampling factors should be used.  When\n *    forcing to grayscale the destination's sampling factors will be all 1,\n *    and we may as well take that as the effective iMCU size.\n * 4. When \"trim\" is in effect, the destination's dimensions will be the\n *    trimmed values but the source's will be untrimmed.\n * 5. When \"crop\" is in effect, the destination's dimensions will be the\n *    cropped values but the source's will be uncropped.  Each transform\n *    routine is responsible for picking up source data starting at the\n *    correct X and Y offset for the crop region.  (The X and Y offsets\n *    passed to the transform routines are measured in iMCU blocks of the\n *    destination.)\n * 6. All the routines assume that the source and destination buffers are\n *    padded out to a full iMCU boundary.  This is true, although for the\n *    source buffer it is an undocumented property of jdcoefct.c.\n */\n\n\nLOCAL(void)\ndo_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t jvirt_barray_ptr *src_coef_arrays,\n\t jvirt_barray_ptr *dst_coef_arrays)\n/* Crop.  This is only used when no rotate/flip is requested with the crop. */\n{\n  JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks;\n  int ci, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  jpeg_component_info *compptr;\n\n  /* We simply have to copy the right amount of data (the destination's\n   * image size) starting at the given X and Y offsets in the source.\n   */\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      src_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t dst_blk_y + y_crop_blocks,\n\t (JDIMENSION) compptr->v_samp_factor, FALSE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tjcopy_block_row(src_buffer[offset_y] + x_crop_blocks,\n\t\t\tdst_buffer[offset_y],\n\t\t\tcompptr->width_in_blocks);\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_crop_ext (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t     JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t     jvirt_barray_ptr *src_coef_arrays,\n\t     jvirt_barray_ptr *dst_coef_arrays)\n/* Crop.  This is only used when no rotate/flip is requested with the crop.\n * Extension: If the destination size is larger than the source, we fill in\n * the extra area with zero (neutral gray).  Note we also have to zero partial\n * iMCUs at the right and bottom edge of the source image area in this case.\n */\n{\n  JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height;\n  JDIMENSION dst_blk_y, x_crop_blocks, y_crop_blocks;\n  int ci, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  jpeg_component_info *compptr;\n\n  MCU_cols = srcinfo->output_width /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n  MCU_rows = srcinfo->output_height /\n    (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    comp_height = MCU_rows * compptr->v_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      if (dstinfo->jpeg_height > srcinfo->output_height) {\n\tif (dst_blk_y < y_crop_blocks ||\n\t    dst_blk_y >= comp_height + y_crop_blocks) {\n\t  for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\t    FMEMZERO(dst_buffer[offset_y],\n\t\t     compptr->width_in_blocks * SIZEOF(JBLOCK));\n\t  }\n\t  continue;\n\t}\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   dst_blk_y - y_crop_blocks,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      } else {\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   dst_blk_y + y_crop_blocks,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      }\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tif (dstinfo->jpeg_width > srcinfo->output_width) {\n\t  if (x_crop_blocks > 0) {\n\t    FMEMZERO(dst_buffer[offset_y],\n\t\t     x_crop_blocks * SIZEOF(JBLOCK));\n\t  }\n\t  jcopy_block_row(src_buffer[offset_y],\n\t\t\t  dst_buffer[offset_y] + x_crop_blocks,\n\t\t\t  comp_width);\n\t  if (compptr->width_in_blocks > comp_width + x_crop_blocks) {\n\t    FMEMZERO(dst_buffer[offset_y] +\n\t\t       comp_width + x_crop_blocks,\n\t\t     (compptr->width_in_blocks -\n\t\t       comp_width - x_crop_blocks) * SIZEOF(JBLOCK));\n\t  }\n\t} else {\n\t  jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,\n\t\t\t  dst_buffer[offset_y],\n\t\t\t  compptr->width_in_blocks);\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_wipe (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t jvirt_barray_ptr *src_coef_arrays,\n\t JDIMENSION drop_width, JDIMENSION drop_height)\n/* Wipe - drop content of specified area, fill with zero (neutral gray) */\n{\n  JDIMENSION comp_width, comp_height;\n  JDIMENSION blk_y, x_wipe_blocks, y_wipe_blocks;\n  int ci, offset_y;\n  JBLOCKARRAY buffer;\n  jpeg_component_info *compptr;\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = drop_width * compptr->h_samp_factor;\n    comp_height = drop_height * compptr->v_samp_factor;\n    x_wipe_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_wipe_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (blk_y = 0; blk_y < comp_height; blk_y += compptr->v_samp_factor) {\n      buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y + y_wipe_blocks,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tFMEMZERO(buffer[offset_y] + x_wipe_blocks,\n\t\t comp_width * SIZEOF(JBLOCK));\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_flip_h_no_crop (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t\t   JDIMENSION x_crop_offset,\n\t\t   jvirt_barray_ptr *src_coef_arrays)\n/* Horizontal flip; done in-place, so no separate dest array is required.\n * NB: this only works when y_crop_offset is zero.\n */\n{\n  JDIMENSION MCU_cols, comp_width, blk_x, blk_y, x_crop_blocks;\n  int ci, k, offset_y;\n  JBLOCKARRAY buffer;\n  JCOEFPTR ptr1, ptr2;\n  JCOEF temp1, temp2;\n  jpeg_component_info *compptr;\n\n  /* Horizontal mirroring of DCT blocks is accomplished by swapping\n   * pairs of blocks in-place.  Within a DCT block, we perform horizontal\n   * mirroring by changing the signs of odd-numbered columns.\n   * Partial iMCUs at the right edge are left untouched.\n   */\n  MCU_cols = srcinfo->output_width /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    for (blk_y = 0; blk_y < compptr->height_in_blocks;\n\t blk_y += compptr->v_samp_factor) {\n      buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\t/* Do the mirroring */\n\tfor (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {\n\t  ptr1 = buffer[offset_y][blk_x];\n\t  ptr2 = buffer[offset_y][comp_width - blk_x - 1];\n\t  /* this unrolled loop doesn't need to know which row it's on... */\n\t  for (k = 0; k < DCTSIZE2; k += 2) {\n\t    temp1 = *ptr1;\t/* swap even column */\n\t    temp2 = *ptr2;\n\t    *ptr1++ = temp2;\n\t    *ptr2++ = temp1;\n\t    temp1 = *ptr1;\t/* swap odd column with sign change */\n\t    temp2 = *ptr2;\n\t    *ptr1++ = -temp2;\n\t    *ptr2++ = -temp1;\n\t  }\n\t}\n\tif (x_crop_blocks > 0) {\n\t  /* Now left-justify the portion of the data to be kept.\n\t   * We can't use a single jcopy_block_row() call because that routine\n\t   * depends on memcpy(), whose behavior is unspecified for overlapping\n\t   * source and destination areas.  Sigh.\n\t   */\n\t  for (blk_x = 0; blk_x < compptr->width_in_blocks; blk_x++) {\n\t    jcopy_block_row(buffer[offset_y] + blk_x + x_crop_blocks,\n\t\t\t    buffer[offset_y] + blk_x,\n\t\t\t    (JDIMENSION) 1);\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t   JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t   jvirt_barray_ptr *src_coef_arrays,\n\t   jvirt_barray_ptr *dst_coef_arrays)\n/* Horizontal flip in general cropping case */\n{\n  JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, k, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JBLOCKROW src_row_ptr, dst_row_ptr;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  /* Here we must output into a separate array because we can't touch\n   * different rows of a single virtual array simultaneously.  Otherwise,\n   * this is essentially the same as the routine above.\n   */\n  MCU_cols = srcinfo->output_width /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      src_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t dst_blk_y + y_crop_blocks,\n\t (JDIMENSION) compptr->v_samp_factor, FALSE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tdst_row_ptr = dst_buffer[offset_y];\n\tsrc_row_ptr = src_buffer[offset_y];\n\tfor (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {\n\t  if (x_crop_blocks + dst_blk_x < comp_width) {\n\t    /* Do the mirrorable blocks */\n\t    dst_ptr = dst_row_ptr[dst_blk_x];\n\t    src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];\n\t    /* this unrolled loop doesn't need to know which row it's on... */\n\t    for (k = 0; k < DCTSIZE2; k += 2) {\n\t      *dst_ptr++ = *src_ptr++;\t /* copy even column */\n\t      *dst_ptr++ = - *src_ptr++; /* copy odd column with sign change */\n\t    }\n\t  } else {\n\t    /* Copy last partial block(s) verbatim */\n\t    jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,\n\t\t\t    dst_row_ptr + dst_blk_x,\n\t\t\t    (JDIMENSION) 1);\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t   JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t   jvirt_barray_ptr *src_coef_arrays,\n\t   jvirt_barray_ptr *dst_coef_arrays)\n/* Vertical flip */\n{\n  JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JBLOCKROW src_row_ptr, dst_row_ptr;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  /* We output into a separate array because we can't touch different\n   * rows of the source virtual array simultaneously.  Otherwise, this\n   * is a pretty straightforward analog of horizontal flip.\n   * Within a DCT block, vertical mirroring is done by changing the signs\n   * of odd-numbered rows.\n   * Partial iMCUs at the bottom edge are copied verbatim.\n   */\n  MCU_rows = srcinfo->output_height /\n    (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_height = MCU_rows * compptr->v_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      if (y_crop_blocks + dst_blk_y < comp_height) {\n\t/* Row is within the mirrorable area. */\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   comp_height - y_crop_blocks - dst_blk_y -\n\t   (JDIMENSION) compptr->v_samp_factor,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      } else {\n\t/* Bottom-edge blocks will be copied verbatim. */\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   dst_blk_y + y_crop_blocks,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      }\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tif (y_crop_blocks + dst_blk_y < comp_height) {\n\t  /* Row is within the mirrorable area. */\n\t  dst_row_ptr = dst_buffer[offset_y];\n\t  src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];\n\t  src_row_ptr += x_crop_blocks;\n\t  for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;\n\t       dst_blk_x++) {\n\t    dst_ptr = dst_row_ptr[dst_blk_x];\n\t    src_ptr = src_row_ptr[dst_blk_x];\n\t    for (i = 0; i < DCTSIZE; i += 2) {\n\t      /* copy even row */\n\t      for (j = 0; j < DCTSIZE; j++)\n\t\t*dst_ptr++ = *src_ptr++;\n\t      /* copy odd row with sign change */\n\t      for (j = 0; j < DCTSIZE; j++)\n\t\t*dst_ptr++ = - *src_ptr++;\n\t    }\n\t  }\n\t} else {\n\t  /* Just copy row verbatim. */\n\t  jcopy_block_row(src_buffer[offset_y] + x_crop_blocks,\n\t\t\t  dst_buffer[offset_y],\n\t\t\t  compptr->width_in_blocks);\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t      JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t      jvirt_barray_ptr *src_coef_arrays,\n\t      jvirt_barray_ptr *dst_coef_arrays)\n/* Transpose source into destination */\n{\n  JDIMENSION dst_blk_x, dst_blk_y, x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_x, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  /* Transposing pixels within a block just requires transposing the\n   * DCT coefficients.\n   * Partial iMCUs at the edges require no special treatment; we simply\n   * process all the available DCT blocks for every component.\n   */\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tfor (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;\n\t     dst_blk_x += compptr->h_samp_factor) {\n\t  src_buffer = (*srcinfo->mem->access_virt_barray)\n\t    ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t     dst_blk_x + x_crop_blocks,\n\t     (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {\n\t    dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];\n\t    src_ptr = src_buffer[offset_x][dst_blk_y + offset_y + y_crop_blocks];\n\t    for (i = 0; i < DCTSIZE; i++)\n\t      for (j = 0; j < DCTSIZE; j++)\n\t\tdst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t   JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t   jvirt_barray_ptr *src_coef_arrays,\n\t   jvirt_barray_ptr *dst_coef_arrays)\n/* 90 degree rotation is equivalent to\n *   1. Transposing the image;\n *   2. Horizontal mirroring.\n * These two steps are merged into a single processing routine.\n */\n{\n  JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_x, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  /* Because of the horizontal mirror step, we can't process partial iMCUs\n   * at the (output) right edge properly.  They just get transposed and\n   * not mirrored.\n   */\n  MCU_cols = srcinfo->output_height /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tfor (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;\n\t     dst_blk_x += compptr->h_samp_factor) {\n\t  if (x_crop_blocks + dst_blk_x < comp_width) {\n\t    /* Block is within the mirrorable area. */\n\t    src_buffer = (*srcinfo->mem->access_virt_barray)\n\t      ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t       comp_width - x_crop_blocks - dst_blk_x -\n\t       (JDIMENSION) compptr->h_samp_factor,\n\t       (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  } else {\n\t    /* Edge blocks are transposed but not mirrored. */\n\t    src_buffer = (*srcinfo->mem->access_virt_barray)\n\t      ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t       dst_blk_x + x_crop_blocks,\n\t       (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  }\n\t  for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {\n\t    dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];\n\t    if (x_crop_blocks + dst_blk_x < comp_width) {\n\t      /* Block is within the mirrorable area. */\n\t      src_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]\n\t\t[dst_blk_y + offset_y + y_crop_blocks];\n\t      for (i = 0; i < DCTSIZE; i++) {\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\ti++;\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t      }\n\t    } else {\n\t      /* Edge blocks are transposed but not mirrored. */\n\t      src_ptr = src_buffer[offset_x]\n\t\t[dst_blk_y + offset_y + y_crop_blocks];\n\t      for (i = 0; i < DCTSIZE; i++)\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t    }\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t    JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t    jvirt_barray_ptr *src_coef_arrays,\n\t    jvirt_barray_ptr *dst_coef_arrays)\n/* 270 degree rotation is equivalent to\n *   1. Horizontal mirroring;\n *   2. Transposing the image.\n * These two steps are merged into a single processing routine.\n */\n{\n  JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_x, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  /* Because of the horizontal mirror step, we can't process partial iMCUs\n   * at the (output) bottom edge properly.  They just get transposed and\n   * not mirrored.\n   */\n  MCU_rows = srcinfo->output_width /\n    (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_height = MCU_rows * compptr->v_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tfor (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;\n\t     dst_blk_x += compptr->h_samp_factor) {\n\t  src_buffer = (*srcinfo->mem->access_virt_barray)\n\t    ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t     dst_blk_x + x_crop_blocks,\n\t     (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {\n\t    dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];\n\t    if (y_crop_blocks + dst_blk_y < comp_height) {\n\t      /* Block is within the mirrorable area. */\n\t      src_ptr = src_buffer[offset_x]\n\t\t[comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];\n\t      for (i = 0; i < DCTSIZE; i++) {\n\t\tfor (j = 0; j < DCTSIZE; j++) {\n\t\t  dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\t  j++;\n\t\t  dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t\t}\n\t      }\n\t    } else {\n\t      /* Edge blocks are transposed but not mirrored. */\n\t      src_ptr = src_buffer[offset_x]\n\t\t[dst_blk_y + offset_y + y_crop_blocks];\n\t      for (i = 0; i < DCTSIZE; i++)\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t    }\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t    JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t    jvirt_barray_ptr *src_coef_arrays,\n\t    jvirt_barray_ptr *dst_coef_arrays)\n/* 180 degree rotation is equivalent to\n *   1. Vertical mirroring;\n *   2. Horizontal mirroring.\n * These two steps are merged into a single processing routine.\n */\n{\n  JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JBLOCKROW src_row_ptr, dst_row_ptr;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  MCU_cols = srcinfo->output_width /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n  MCU_rows = srcinfo->output_height /\n    (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    comp_height = MCU_rows * compptr->v_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      if (y_crop_blocks + dst_blk_y < comp_height) {\n\t/* Row is within the vertically mirrorable area. */\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   comp_height - y_crop_blocks - dst_blk_y -\n\t   (JDIMENSION) compptr->v_samp_factor,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      } else {\n\t/* Bottom-edge rows are only mirrored horizontally. */\n\tsrc_buffer = (*srcinfo->mem->access_virt_barray)\n\t  ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t   dst_blk_y + y_crop_blocks,\n\t   (JDIMENSION) compptr->v_samp_factor, FALSE);\n      }\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tdst_row_ptr = dst_buffer[offset_y];\n\tif (y_crop_blocks + dst_blk_y < comp_height) {\n\t  /* Row is within the mirrorable area. */\n\t  src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];\n\t  for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {\n\t    dst_ptr = dst_row_ptr[dst_blk_x];\n\t    if (x_crop_blocks + dst_blk_x < comp_width) {\n\t      /* Process the blocks that can be mirrored both ways. */\n\t      src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];\n\t      for (i = 0; i < DCTSIZE; i += 2) {\n\t\t/* For even row, negate every odd column. */\n\t\tfor (j = 0; j < DCTSIZE; j += 2) {\n\t\t  *dst_ptr++ = *src_ptr++;\n\t\t  *dst_ptr++ = - *src_ptr++;\n\t\t}\n\t\t/* For odd row, negate every even column. */\n\t\tfor (j = 0; j < DCTSIZE; j += 2) {\n\t\t  *dst_ptr++ = - *src_ptr++;\n\t\t  *dst_ptr++ = *src_ptr++;\n\t\t}\n\t      }\n\t    } else {\n\t      /* Any remaining right-edge blocks are only mirrored vertically. */\n\t      src_ptr = src_row_ptr[x_crop_blocks + dst_blk_x];\n\t      for (i = 0; i < DCTSIZE; i += 2) {\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  *dst_ptr++ = *src_ptr++;\n\t\tfor (j = 0; j < DCTSIZE; j++)\n\t\t  *dst_ptr++ = - *src_ptr++;\n\t      }\n\t    }\n\t  }\n\t} else {\n\t  /* Remaining rows are just mirrored horizontally. */\n\t  src_row_ptr = src_buffer[offset_y];\n\t  for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {\n\t    if (x_crop_blocks + dst_blk_x < comp_width) {\n\t      /* Process the blocks that can be mirrored. */\n\t      dst_ptr = dst_row_ptr[dst_blk_x];\n\t      src_ptr = src_row_ptr[comp_width - x_crop_blocks - dst_blk_x - 1];\n\t      for (i = 0; i < DCTSIZE2; i += 2) {\n\t\t*dst_ptr++ = *src_ptr++;\n\t\t*dst_ptr++ = - *src_ptr++;\n\t      }\n\t    } else {\n\t      /* Any remaining right-edge blocks are only copied. */\n\t      jcopy_block_row(src_row_ptr + dst_blk_x + x_crop_blocks,\n\t\t\t      dst_row_ptr + dst_blk_x,\n\t\t\t      (JDIMENSION) 1);\n\t    }\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\nLOCAL(void)\ndo_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t       JDIMENSION x_crop_offset, JDIMENSION y_crop_offset,\n\t       jvirt_barray_ptr *src_coef_arrays,\n\t       jvirt_barray_ptr *dst_coef_arrays)\n/* Transverse transpose is equivalent to\n *   1. 180 degree rotation;\n *   2. Transposition;\n * or\n *   1. Horizontal mirroring;\n *   2. Transposition;\n *   3. Horizontal mirroring.\n * These steps are merged into a single processing routine.\n */\n{\n  JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;\n  JDIMENSION x_crop_blocks, y_crop_blocks;\n  int ci, i, j, offset_x, offset_y;\n  JBLOCKARRAY src_buffer, dst_buffer;\n  JCOEFPTR src_ptr, dst_ptr;\n  jpeg_component_info *compptr;\n\n  MCU_cols = srcinfo->output_height /\n    (dstinfo->max_h_samp_factor * dstinfo->min_DCT_h_scaled_size);\n  MCU_rows = srcinfo->output_width /\n    (dstinfo->max_v_samp_factor * dstinfo->min_DCT_v_scaled_size);\n\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    comp_width = MCU_cols * compptr->h_samp_factor;\n    comp_height = MCU_rows * compptr->v_samp_factor;\n    x_crop_blocks = x_crop_offset * compptr->h_samp_factor;\n    y_crop_blocks = y_crop_offset * compptr->v_samp_factor;\n    for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;\n\t dst_blk_y += compptr->v_samp_factor) {\n      dst_buffer = (*srcinfo->mem->access_virt_barray)\n\t((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,\n\t (JDIMENSION) compptr->v_samp_factor, TRUE);\n      for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {\n\tfor (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;\n\t     dst_blk_x += compptr->h_samp_factor) {\n\t  if (x_crop_blocks + dst_blk_x < comp_width) {\n\t    /* Block is within the mirrorable area. */\n\t    src_buffer = (*srcinfo->mem->access_virt_barray)\n\t      ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t       comp_width - x_crop_blocks - dst_blk_x -\n\t       (JDIMENSION) compptr->h_samp_factor,\n\t       (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  } else {\n\t    src_buffer = (*srcinfo->mem->access_virt_barray)\n\t      ((j_common_ptr) srcinfo, src_coef_arrays[ci],\n\t       dst_blk_x + x_crop_blocks,\n\t       (JDIMENSION) compptr->h_samp_factor, FALSE);\n\t  }\n\t  for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {\n\t    dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];\n\t    if (y_crop_blocks + dst_blk_y < comp_height) {\n\t      if (x_crop_blocks + dst_blk_x < comp_width) {\n\t\t/* Block is within the mirrorable area. */\n\t\tsrc_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]\n\t\t  [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];\n\t\tfor (i = 0; i < DCTSIZE; i++) {\n\t\t  for (j = 0; j < DCTSIZE; j++) {\n\t\t    dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\t    j++;\n\t\t    dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t\t  }\n\t\t  i++;\n\t\t  for (j = 0; j < DCTSIZE; j++) {\n\t\t    dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t\t    j++;\n\t\t    dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\t  }\n\t\t}\n\t      } else {\n\t\t/* Right-edge blocks are mirrored in y only */\n\t\tsrc_ptr = src_buffer[offset_x]\n\t\t  [comp_height - y_crop_blocks - dst_blk_y - offset_y - 1];\n\t\tfor (i = 0; i < DCTSIZE; i++) {\n\t\t  for (j = 0; j < DCTSIZE; j++) {\n\t\t    dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\t    j++;\n\t\t    dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t\t  }\n\t\t}\n\t      }\n\t    } else {\n\t      if (x_crop_blocks + dst_blk_x < comp_width) {\n\t\t/* Bottom-edge blocks are mirrored in x only */\n\t\tsrc_ptr = src_buffer[compptr->h_samp_factor - offset_x - 1]\n\t\t  [dst_blk_y + offset_y + y_crop_blocks];\n\t\tfor (i = 0; i < DCTSIZE; i++) {\n\t\t  for (j = 0; j < DCTSIZE; j++)\n\t\t    dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t\t  i++;\n\t\t  for (j = 0; j < DCTSIZE; j++)\n\t\t    dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];\n\t\t}\n\t      } else {\n\t\t/* At lower right corner, just transpose, no mirroring */\n\t\tsrc_ptr = src_buffer[offset_x]\n\t\t  [dst_blk_y + offset_y + y_crop_blocks];\n\t\tfor (i = 0; i < DCTSIZE; i++)\n\t\t  for (j = 0; j < DCTSIZE; j++)\n\t\t    dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];\n\t      }\n\t    }\n\t  }\n\t}\n      }\n    }\n  }\n}\n\n\n/* Parse an unsigned integer: subroutine for jtransform_parse_crop_spec.\n * Returns TRUE if valid integer found, FALSE if not.\n * *strptr is advanced over the digit string, and *result is set to its value.\n */\n\nLOCAL(boolean)\njt_read_integer (const char ** strptr, JDIMENSION * result)\n{\n  const char * ptr = *strptr;\n  JDIMENSION val = 0;\n\n  for (; isdigit(*ptr); ptr++) {\n    val = val * 10 + (JDIMENSION) (*ptr - '0');\n  }\n  *result = val;\n  if (ptr == *strptr)\n    return FALSE;\t\t/* oops, no digits */\n  *strptr = ptr;\n  return TRUE;\n}\n\n\n/* Parse a crop specification (written in X11 geometry style).\n * The routine returns TRUE if the spec string is valid, FALSE if not.\n *\n * The crop spec string should have the format\n *\t<width>[f]x<height>[f]{+-}<xoffset>{+-}<yoffset>\n * where width, height, xoffset, and yoffset are unsigned integers.\n * Each of the elements can be omitted to indicate a default value.\n * (A weakness of this style is that it is not possible to omit xoffset\n * while specifying yoffset, since they look alike.)\n *\n * This code is loosely based on XParseGeometry from the X11 distribution.\n */\n\nGLOBAL(boolean)\njtransform_parse_crop_spec (jpeg_transform_info *info, const char *spec)\n{\n  info->crop = FALSE;\n  info->crop_width_set = JCROP_UNSET;\n  info->crop_height_set = JCROP_UNSET;\n  info->crop_xoffset_set = JCROP_UNSET;\n  info->crop_yoffset_set = JCROP_UNSET;\n\n  if (isdigit(*spec)) {\n    /* fetch width */\n    if (! jt_read_integer(&spec, &info->crop_width))\n      return FALSE;\n    if (*spec == 'f' || *spec == 'F') {\n      spec++;\n      info->crop_width_set = JCROP_FORCE;\n    } else\n      info->crop_width_set = JCROP_POS;\n  }\n  if (*spec == 'x' || *spec == 'X') {\n    /* fetch height */\n    spec++;\n    if (! jt_read_integer(&spec, &info->crop_height))\n      return FALSE;\n    if (*spec == 'f' || *spec == 'F') {\n      spec++;\n      info->crop_height_set = JCROP_FORCE;\n    } else\n      info->crop_height_set = JCROP_POS;\n  }\n  if (*spec == '+' || *spec == '-') {\n    /* fetch xoffset */\n    info->crop_xoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS;\n    spec++;\n    if (! jt_read_integer(&spec, &info->crop_xoffset))\n      return FALSE;\n  }\n  if (*spec == '+' || *spec == '-') {\n    /* fetch yoffset */\n    info->crop_yoffset_set = (*spec == '-') ? JCROP_NEG : JCROP_POS;\n    spec++;\n    if (! jt_read_integer(&spec, &info->crop_yoffset))\n      return FALSE;\n  }\n  /* We had better have gotten to the end of the string. */\n  if (*spec != '\\0')\n    return FALSE;\n  info->crop = TRUE;\n  return TRUE;\n}\n\n\n/* Trim off any partial iMCUs on the indicated destination edge */\n\nLOCAL(void)\ntrim_right_edge (jpeg_transform_info *info, JDIMENSION full_width)\n{\n  JDIMENSION MCU_cols;\n\n  MCU_cols = info->output_width / info->iMCU_sample_width;\n  if (MCU_cols > 0 && info->x_crop_offset + MCU_cols ==\n      full_width / info->iMCU_sample_width)\n    info->output_width = MCU_cols * info->iMCU_sample_width;\n}\n\nLOCAL(void)\ntrim_bottom_edge (jpeg_transform_info *info, JDIMENSION full_height)\n{\n  JDIMENSION MCU_rows;\n\n  MCU_rows = info->output_height / info->iMCU_sample_height;\n  if (MCU_rows > 0 && info->y_crop_offset + MCU_rows ==\n      full_height / info->iMCU_sample_height)\n    info->output_height = MCU_rows * info->iMCU_sample_height;\n}\n\n\n/* Request any required workspace.\n *\n * This routine figures out the size that the output image will be\n * (which implies that all the transform parameters must be set before\n * it is called).\n *\n * We allocate the workspace virtual arrays from the source decompression\n * object, so that all the arrays (both the original data and the workspace)\n * will be taken into account while making memory management decisions.\n * Hence, this routine must be called after jpeg_read_header (which reads\n * the image dimensions) and before jpeg_read_coefficients (which realizes\n * the source's virtual arrays).\n *\n * This function returns FALSE right away if -perfect is given\n * and transformation is not perfect.  Otherwise returns TRUE.\n */\n\nGLOBAL(boolean)\njtransform_request_workspace (j_decompress_ptr srcinfo,\n\t\t\t      jpeg_transform_info *info)\n{\n  jvirt_barray_ptr *coef_arrays;\n  boolean need_workspace, transpose_it;\n  jpeg_component_info *compptr;\n  JDIMENSION xoffset, yoffset;\n  JDIMENSION width_in_iMCUs, height_in_iMCUs;\n  JDIMENSION width_in_blocks, height_in_blocks;\n  int ci, h_samp_factor, v_samp_factor;\n\n  /* Determine number of components in output image */\n  if (info->force_grayscale &&\n      (srcinfo->jpeg_color_space == JCS_YCbCr ||\n       srcinfo->jpeg_color_space == JCS_BG_YCC) &&\n      srcinfo->num_components == 3)\n    /* We'll only process the first component */\n    info->num_components = 1;\n  else\n    /* Process all the components */\n    info->num_components = srcinfo->num_components;\n\n  /* Compute output image dimensions and related values. */\n  jpeg_core_output_dimensions(srcinfo);\n\n  /* Return right away if -perfect is given and transformation is not perfect.\n   */\n  if (info->perfect) {\n    if (info->num_components == 1) {\n      if (!jtransform_perfect_transform(srcinfo->output_width,\n\t  srcinfo->output_height,\n\t  srcinfo->min_DCT_h_scaled_size,\n\t  srcinfo->min_DCT_v_scaled_size,\n\t  info->transform))\n\treturn FALSE;\n    } else {\n      if (!jtransform_perfect_transform(srcinfo->output_width,\n\t  srcinfo->output_height,\n\t  srcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size,\n\t  srcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size,\n\t  info->transform))\n\treturn FALSE;\n    }\n  }\n\n  /* If there is only one output component, force the iMCU size to be 1;\n   * else use the source iMCU size.  (This allows us to do the right thing\n   * when reducing color to grayscale, and also provides a handy way of\n   * cleaning up \"funny\" grayscale images whose sampling factors are not 1x1.)\n   */\n  switch (info->transform) {\n  case JXFORM_TRANSPOSE:\n  case JXFORM_TRANSVERSE:\n  case JXFORM_ROT_90:\n  case JXFORM_ROT_270:\n    info->output_width = srcinfo->output_height;\n    info->output_height = srcinfo->output_width;\n    if (info->num_components == 1) {\n      info->iMCU_sample_width = srcinfo->min_DCT_v_scaled_size;\n      info->iMCU_sample_height = srcinfo->min_DCT_h_scaled_size;\n    } else {\n      info->iMCU_sample_width =\n\tsrcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size;\n      info->iMCU_sample_height =\n\tsrcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size;\n    }\n    break;\n  default:\n    info->output_width = srcinfo->output_width;\n    info->output_height = srcinfo->output_height;\n    if (info->num_components == 1) {\n      info->iMCU_sample_width = srcinfo->min_DCT_h_scaled_size;\n      info->iMCU_sample_height = srcinfo->min_DCT_v_scaled_size;\n    } else {\n      info->iMCU_sample_width =\n\tsrcinfo->max_h_samp_factor * srcinfo->min_DCT_h_scaled_size;\n      info->iMCU_sample_height =\n\tsrcinfo->max_v_samp_factor * srcinfo->min_DCT_v_scaled_size;\n    }\n    break;\n  }\n\n  /* If cropping has been requested, compute the crop area's position and\n   * dimensions, ensuring that its upper left corner falls at an iMCU boundary.\n   */\n  if (info->crop) {\n    /* Insert default values for unset crop parameters */\n    if (info->crop_xoffset_set == JCROP_UNSET)\n      info->crop_xoffset = 0;\t/* default to +0 */\n    if (info->crop_yoffset_set == JCROP_UNSET)\n      info->crop_yoffset = 0;\t/* default to +0 */\n    if (info->crop_width_set == JCROP_UNSET) {\n      if (info->crop_xoffset >= info->output_width)\n\tERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      info->crop_width = info->output_width - info->crop_xoffset;\n    } else {\n      /* Check for crop extension */\n      if (info->crop_width > info->output_width) {\n\t/* Crop extension does not work when transforming! */\n\tif (info->transform != JXFORM_NONE ||\n\t    info->crop_xoffset >= info->crop_width ||\n\t    info->crop_xoffset > info->crop_width - info->output_width)\n\t  ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      } else {\n\tif (info->crop_xoffset >= info->output_width ||\n\t    info->crop_width <= 0 ||\n\t    info->crop_xoffset > info->output_width - info->crop_width)\n\t  ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      }\n    }\n    if (info->crop_height_set == JCROP_UNSET) {\n      if (info->crop_yoffset >= info->output_height)\n\tERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      info->crop_height = info->output_height - info->crop_yoffset;\n    } else {\n      /* Check for crop extension */\n      if (info->crop_height > info->output_height) {\n\t/* Crop extension does not work when transforming! */\n\tif (info->transform != JXFORM_NONE ||\n\t    info->crop_yoffset >= info->crop_height ||\n\t    info->crop_yoffset > info->crop_height - info->output_height)\n\t  ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      } else {\n\tif (info->crop_yoffset >= info->output_height ||\n\t    info->crop_height <= 0 ||\n\t    info->crop_yoffset > info->output_height - info->crop_height)\n\t  ERREXIT(srcinfo, JERR_BAD_CROP_SPEC);\n      }\n    }\n    /* Convert negative crop offsets into regular offsets */\n    if (info->crop_xoffset_set != JCROP_NEG)\n      xoffset = info->crop_xoffset;\n    else if (info->crop_width > info->output_width) /* crop extension */\n      xoffset = info->crop_width - info->output_width - info->crop_xoffset;\n    else\n      xoffset = info->output_width - info->crop_width - info->crop_xoffset;\n    if (info->crop_yoffset_set != JCROP_NEG)\n      yoffset = info->crop_yoffset;\n    else if (info->crop_height > info->output_height) /* crop extension */\n      yoffset = info->crop_height - info->output_height - info->crop_yoffset;\n    else\n      yoffset = info->output_height - info->crop_height - info->crop_yoffset;\n    /* Now adjust so that upper left corner falls at an iMCU boundary */\n    if (info->transform == JXFORM_WIPE) {\n      /* Ensure the effective wipe region will cover the requested */\n      info->drop_width = (JDIMENSION) jdiv_round_up\n\t((long) (info->crop_width + (xoffset % info->iMCU_sample_width)),\n\t (long) info->iMCU_sample_width);\n      info->drop_height = (JDIMENSION) jdiv_round_up\n\t((long) (info->crop_height + (yoffset % info->iMCU_sample_height)),\n\t (long) info->iMCU_sample_height);\n    } else {\n      /* Ensure the effective crop region will cover the requested */\n      if (info->crop_width_set == JCROP_FORCE ||\n\t  info->crop_width > info->output_width)\n\tinfo->output_width = info->crop_width;\n      else\n\tinfo->output_width =\n\t  info->crop_width + (xoffset % info->iMCU_sample_width);\n      if (info->crop_height_set == JCROP_FORCE ||\n\t  info->crop_height > info->output_height)\n\tinfo->output_height = info->crop_height;\n      else\n\tinfo->output_height =\n\t  info->crop_height + (yoffset % info->iMCU_sample_height);\n    }\n    /* Save x/y offsets measured in iMCUs */\n    info->x_crop_offset = xoffset / info->iMCU_sample_width;\n    info->y_crop_offset = yoffset / info->iMCU_sample_height;\n  } else {\n    info->x_crop_offset = 0;\n    info->y_crop_offset = 0;\n  }\n\n  /* Figure out whether we need workspace arrays,\n   * and if so whether they are transposed relative to the source.\n   */\n  need_workspace = FALSE;\n  transpose_it = FALSE;\n  switch (info->transform) {\n  case JXFORM_NONE:\n    if (info->x_crop_offset != 0 || info->y_crop_offset != 0 ||\n\tinfo->output_width > srcinfo->output_width ||\n\tinfo->output_height > srcinfo->output_height)\n      need_workspace = TRUE;\n    /* No workspace needed if neither cropping nor transforming */\n    break;\n  case JXFORM_FLIP_H:\n    if (info->trim)\n      trim_right_edge(info, srcinfo->output_width);\n    if (info->y_crop_offset != 0)\n      need_workspace = TRUE;\n    /* do_flip_h_no_crop doesn't need a workspace array */\n    break;\n  case JXFORM_FLIP_V:\n    if (info->trim)\n      trim_bottom_edge(info, srcinfo->output_height);\n    /* Need workspace arrays having same dimensions as source image. */\n    need_workspace = TRUE;\n    break;\n  case JXFORM_TRANSPOSE:\n    /* transpose does NOT have to trim anything */\n    /* Need workspace arrays having transposed dimensions. */\n    need_workspace = TRUE;\n    transpose_it = TRUE;\n    break;\n  case JXFORM_TRANSVERSE:\n    if (info->trim) {\n      trim_right_edge(info, srcinfo->output_height);\n      trim_bottom_edge(info, srcinfo->output_width);\n    }\n    /* Need workspace arrays having transposed dimensions. */\n    need_workspace = TRUE;\n    transpose_it = TRUE;\n    break;\n  case JXFORM_ROT_90:\n    if (info->trim)\n      trim_right_edge(info, srcinfo->output_height);\n    /* Need workspace arrays having transposed dimensions. */\n    need_workspace = TRUE;\n    transpose_it = TRUE;\n    break;\n  case JXFORM_ROT_180:\n    if (info->trim) {\n      trim_right_edge(info, srcinfo->output_width);\n      trim_bottom_edge(info, srcinfo->output_height);\n    }\n    /* Need workspace arrays having same dimensions as source image. */\n    need_workspace = TRUE;\n    break;\n  case JXFORM_ROT_270:\n    if (info->trim)\n      trim_bottom_edge(info, srcinfo->output_width);\n    /* Need workspace arrays having transposed dimensions. */\n    need_workspace = TRUE;\n    transpose_it = TRUE;\n    break;\n  case JXFORM_WIPE:\n    break;\n  }\n\n  /* Allocate workspace if needed.\n   * Note that we allocate arrays padded out to the next iMCU boundary,\n   * so that transform routines need not worry about missing edge blocks.\n   */\n  if (need_workspace) {\n    coef_arrays = (jvirt_barray_ptr *)\n      (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,\n\tSIZEOF(jvirt_barray_ptr) * info->num_components);\n    width_in_iMCUs = (JDIMENSION)\n      jdiv_round_up((long) info->output_width,\n\t\t    (long) info->iMCU_sample_width);\n    height_in_iMCUs = (JDIMENSION)\n      jdiv_round_up((long) info->output_height,\n\t\t    (long) info->iMCU_sample_height);\n    for (ci = 0; ci < info->num_components; ci++) {\n      compptr = srcinfo->comp_info + ci;\n      if (info->num_components == 1) {\n\t/* we're going to force samp factors to 1x1 in this case */\n\th_samp_factor = v_samp_factor = 1;\n      } else if (transpose_it) {\n\th_samp_factor = compptr->v_samp_factor;\n\tv_samp_factor = compptr->h_samp_factor;\n      } else {\n\th_samp_factor = compptr->h_samp_factor;\n\tv_samp_factor = compptr->v_samp_factor;\n      }\n      width_in_blocks = width_in_iMCUs * h_samp_factor;\n      height_in_blocks = height_in_iMCUs * v_samp_factor;\n      coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)\n\t((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,\n\t width_in_blocks, height_in_blocks, (JDIMENSION) v_samp_factor);\n    }\n    info->workspace_coef_arrays = coef_arrays;\n  } else\n    info->workspace_coef_arrays = NULL;\n\n  return TRUE;\n}\n\n\n/* Transpose destination image parameters */\n\nLOCAL(void)\ntranspose_critical_parameters (j_compress_ptr dstinfo)\n{\n  int tblno, i, j, ci, itemp;\n  jpeg_component_info *compptr;\n  JQUANT_TBL *qtblptr;\n  JDIMENSION jtemp;\n  UINT16 qtemp;\n\n  /* Transpose image dimensions */\n  jtemp = dstinfo->image_width;\n  dstinfo->image_width = dstinfo->image_height;\n  dstinfo->image_height = jtemp;\n  itemp = dstinfo->min_DCT_h_scaled_size;\n  dstinfo->min_DCT_h_scaled_size = dstinfo->min_DCT_v_scaled_size;\n  dstinfo->min_DCT_v_scaled_size = itemp;\n\n  /* Transpose sampling factors */\n  for (ci = 0; ci < dstinfo->num_components; ci++) {\n    compptr = dstinfo->comp_info + ci;\n    itemp = compptr->h_samp_factor;\n    compptr->h_samp_factor = compptr->v_samp_factor;\n    compptr->v_samp_factor = itemp;\n  }\n\n  /* Transpose quantization tables */\n  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {\n    qtblptr = dstinfo->quant_tbl_ptrs[tblno];\n    if (qtblptr != NULL) {\n      for (i = 0; i < DCTSIZE; i++) {\n\tfor (j = 0; j < i; j++) {\n\t  qtemp = qtblptr->quantval[i*DCTSIZE+j];\n\t  qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];\n\t  qtblptr->quantval[j*DCTSIZE+i] = qtemp;\n\t}\n      }\n    }\n  }\n}\n\n\n/* Adjust Exif image parameters.\n *\n * We try to adjust the Tags ExifImageWidth and ExifImageHeight if possible.\n */\n\nLOCAL(void)\nadjust_exif_parameters (JOCTET FAR * data, unsigned int length,\n\t\t\tJDIMENSION new_width, JDIMENSION new_height)\n{\n  boolean is_motorola; /* Flag for byte order */\n  unsigned int number_of_tags, tagnum;\n  unsigned int firstoffset, offset;\n  JDIMENSION new_value;\n\n  if (length < 12) return; /* Length of an IFD entry */\n\n  /* Discover byte order */\n  if (GETJOCTET(data[0]) == 0x49 && GETJOCTET(data[1]) == 0x49)\n    is_motorola = FALSE;\n  else if (GETJOCTET(data[0]) == 0x4D && GETJOCTET(data[1]) == 0x4D)\n    is_motorola = TRUE;\n  else\n    return;\n\n  /* Check Tag Mark */\n  if (is_motorola) {\n    if (GETJOCTET(data[2]) != 0) return;\n    if (GETJOCTET(data[3]) != 0x2A) return;\n  } else {\n    if (GETJOCTET(data[3]) != 0) return;\n    if (GETJOCTET(data[2]) != 0x2A) return;\n  }\n\n  /* Get first IFD offset (offset to IFD0) */\n  if (is_motorola) {\n    if (GETJOCTET(data[4]) != 0) return;\n    if (GETJOCTET(data[5]) != 0) return;\n    firstoffset = GETJOCTET(data[6]);\n    firstoffset <<= 8;\n    firstoffset += GETJOCTET(data[7]);\n  } else {\n    if (GETJOCTET(data[7]) != 0) return;\n    if (GETJOCTET(data[6]) != 0) return;\n    firstoffset = GETJOCTET(data[5]);\n    firstoffset <<= 8;\n    firstoffset += GETJOCTET(data[4]);\n  }\n  if (firstoffset > length - 2) return; /* check end of data segment */\n\n  /* Get the number of directory entries contained in this IFD */\n  if (is_motorola) {\n    number_of_tags = GETJOCTET(data[firstoffset]);\n    number_of_tags <<= 8;\n    number_of_tags += GETJOCTET(data[firstoffset+1]);\n  } else {\n    number_of_tags = GETJOCTET(data[firstoffset+1]);\n    number_of_tags <<= 8;\n    number_of_tags += GETJOCTET(data[firstoffset]);\n  }\n  if (number_of_tags == 0) return;\n  firstoffset += 2;\n\n  /* Search for ExifSubIFD offset Tag in IFD0 */\n  for (;;) {\n    if (firstoffset > length - 12) return; /* check end of data segment */\n    /* Get Tag number */\n    if (is_motorola) {\n      tagnum = GETJOCTET(data[firstoffset]);\n      tagnum <<= 8;\n      tagnum += GETJOCTET(data[firstoffset+1]);\n    } else {\n      tagnum = GETJOCTET(data[firstoffset+1]);\n      tagnum <<= 8;\n      tagnum += GETJOCTET(data[firstoffset]);\n    }\n    if (tagnum == 0x8769) break; /* found ExifSubIFD offset Tag */\n    if (--number_of_tags == 0) return;\n    firstoffset += 12;\n  }\n\n  /* Get the ExifSubIFD offset */\n  if (is_motorola) {\n    if (GETJOCTET(data[firstoffset+8]) != 0) return;\n    if (GETJOCTET(data[firstoffset+9]) != 0) return;\n    offset = GETJOCTET(data[firstoffset+10]);\n    offset <<= 8;\n    offset += GETJOCTET(data[firstoffset+11]);\n  } else {\n    if (GETJOCTET(data[firstoffset+11]) != 0) return;\n    if (GETJOCTET(data[firstoffset+10]) != 0) return;\n    offset = GETJOCTET(data[firstoffset+9]);\n    offset <<= 8;\n    offset += GETJOCTET(data[firstoffset+8]);\n  }\n  if (offset > length - 2) return; /* check end of data segment */\n\n  /* Get the number of directory entries contained in this SubIFD */\n  if (is_motorola) {\n    number_of_tags = GETJOCTET(data[offset]);\n    number_of_tags <<= 8;\n    number_of_tags += GETJOCTET(data[offset+1]);\n  } else {\n    number_of_tags = GETJOCTET(data[offset+1]);\n    number_of_tags <<= 8;\n    number_of_tags += GETJOCTET(data[offset]);\n  }\n  if (number_of_tags < 2) return;\n  offset += 2;\n\n  /* Search for ExifImageWidth and ExifImageHeight Tags in this SubIFD */\n  do {\n    if (offset > length - 12) return; /* check end of data segment */\n    /* Get Tag number */\n    if (is_motorola) {\n      tagnum = GETJOCTET(data[offset]);\n      tagnum <<= 8;\n      tagnum += GETJOCTET(data[offset+1]);\n    } else {\n      tagnum = GETJOCTET(data[offset+1]);\n      tagnum <<= 8;\n      tagnum += GETJOCTET(data[offset]);\n    }\n    if (tagnum == 0xA002 || tagnum == 0xA003) {\n      if (tagnum == 0xA002)\n\tnew_value = new_width; /* ExifImageWidth Tag */\n      else\n\tnew_value = new_height; /* ExifImageHeight Tag */\n      if (is_motorola) {\n\tdata[offset+2] = 0; /* Format = unsigned long (4 octets) */\n\tdata[offset+3] = 4;\n\tdata[offset+4] = 0; /* Number Of Components = 1 */\n\tdata[offset+5] = 0;\n\tdata[offset+6] = 0;\n\tdata[offset+7] = 1;\n\tdata[offset+8] = 0;\n\tdata[offset+9] = 0;\n\tdata[offset+10] = (JOCTET)((new_value >> 8) & 0xFF);\n\tdata[offset+11] = (JOCTET)(new_value & 0xFF);\n      } else {\n\tdata[offset+2] = 4; /* Format = unsigned long (4 octets) */\n\tdata[offset+3] = 0;\n\tdata[offset+4] = 1; /* Number Of Components = 1 */\n\tdata[offset+5] = 0;\n\tdata[offset+6] = 0;\n\tdata[offset+7] = 0;\n\tdata[offset+8] = (JOCTET)(new_value & 0xFF);\n\tdata[offset+9] = (JOCTET)((new_value >> 8) & 0xFF);\n\tdata[offset+10] = 0;\n\tdata[offset+11] = 0;\n      }\n    }\n    offset += 12;\n  } while (--number_of_tags);\n}\n\n\n/* Adjust output image parameters as needed.\n *\n * This must be called after jpeg_copy_critical_parameters()\n * and before jpeg_write_coefficients().\n *\n * The return value is the set of virtual coefficient arrays to be written\n * (either the ones allocated by jtransform_request_workspace, or the\n * original source data arrays).  The caller will need to pass this value\n * to jpeg_write_coefficients().\n */\n\nGLOBAL(jvirt_barray_ptr *)\njtransform_adjust_parameters (j_decompress_ptr srcinfo,\n\t\t\t      j_compress_ptr dstinfo,\n\t\t\t      jvirt_barray_ptr *src_coef_arrays,\n\t\t\t      jpeg_transform_info *info)\n{\n  /* If force-to-grayscale is requested, adjust destination parameters */\n  if (info->force_grayscale) {\n    /* First, ensure we have YCC or grayscale data, and that the source's\n     * Y channel is full resolution.  (No reasonable person would make Y\n     * be less than full resolution, so actually coping with that case\n     * isn't worth extra code space.  But we check it to avoid crashing.)\n     */\n    if ((((dstinfo->jpeg_color_space == JCS_YCbCr ||\n\t   dstinfo->jpeg_color_space == JCS_BG_YCC) &&\n\t  dstinfo->num_components == 3) ||\n\t (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&\n\t  dstinfo->num_components == 1)) &&\n\tsrcinfo->comp_info[0].h_samp_factor == srcinfo->max_h_samp_factor &&\n\tsrcinfo->comp_info[0].v_samp_factor == srcinfo->max_v_samp_factor) {\n      /* We use jpeg_set_colorspace to make sure subsidiary settings get fixed\n       * properly.  Among other things, it sets the target h_samp_factor &\n       * v_samp_factor to 1, which typically won't match the source.\n       * We have to preserve the source's quantization table number, however.\n       */\n      int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;\n      jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);\n      dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;\n    } else {\n      /* Sorry, can't do it */\n      ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);\n    }\n  } else if (info->num_components == 1) {\n    /* For a single-component source, we force the destination sampling factors\n     * to 1x1, with or without force_grayscale.  This is useful because some\n     * decoders choke on grayscale images with other sampling factors.\n     */\n    dstinfo->comp_info[0].h_samp_factor = 1;\n    dstinfo->comp_info[0].v_samp_factor = 1;\n  }\n\n  /* Correct the destination's image dimensions as necessary\n   * for rotate/flip, resize, and crop operations.\n   */\n  dstinfo->jpeg_width = info->output_width;\n  dstinfo->jpeg_height = info->output_height;\n\n  /* Transpose destination image parameters */\n  switch (info->transform) {\n  case JXFORM_TRANSPOSE:\n  case JXFORM_TRANSVERSE:\n  case JXFORM_ROT_90:\n  case JXFORM_ROT_270:\n    transpose_critical_parameters(dstinfo);\n    break;\n  default:\n    break;\n  }\n\n  /* Adjust Exif properties */\n  if (srcinfo->marker_list != NULL &&\n      srcinfo->marker_list->marker == JPEG_APP0+1 &&\n      srcinfo->marker_list->data_length >= 6 &&\n      GETJOCTET(srcinfo->marker_list->data[0]) == 0x45 &&\n      GETJOCTET(srcinfo->marker_list->data[1]) == 0x78 &&\n      GETJOCTET(srcinfo->marker_list->data[2]) == 0x69 &&\n      GETJOCTET(srcinfo->marker_list->data[3]) == 0x66 &&\n      GETJOCTET(srcinfo->marker_list->data[4]) == 0 &&\n      GETJOCTET(srcinfo->marker_list->data[5]) == 0) {\n    /* Suppress output of JFIF marker */\n    dstinfo->write_JFIF_header = FALSE;\n    /* Adjust Exif image parameters */\n    if (dstinfo->jpeg_width != srcinfo->image_width ||\n\tdstinfo->jpeg_height != srcinfo->image_height)\n      /* Align data segment to start of TIFF structure for parsing */\n      adjust_exif_parameters(srcinfo->marker_list->data + 6,\n\tsrcinfo->marker_list->data_length - 6,\n\tdstinfo->jpeg_width, dstinfo->jpeg_height);\n  }\n\n  /* Return the appropriate output data set */\n  if (info->workspace_coef_arrays != NULL)\n    return info->workspace_coef_arrays;\n  return src_coef_arrays;\n}\n\n\n/* Execute the actual transformation, if any.\n *\n * This must be called *after* jpeg_write_coefficients, because it depends\n * on jpeg_write_coefficients to have computed subsidiary values such as\n * the per-component width and height fields in the destination object.\n *\n * Note that some transformations will modify the source data arrays!\n */\n\nGLOBAL(void)\njtransform_execute_transform (j_decompress_ptr srcinfo,\n\t\t\t      j_compress_ptr dstinfo,\n\t\t\t      jvirt_barray_ptr *src_coef_arrays,\n\t\t\t      jpeg_transform_info *info)\n{\n  jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;\n\n  /* Note: conditions tested here should match those in switch statement\n   * in jtransform_request_workspace()\n   */\n  switch (info->transform) {\n  case JXFORM_NONE:\n    if (info->output_width > srcinfo->output_width ||\n\tinfo->output_height > srcinfo->output_height)\n      do_crop_ext(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t\t  src_coef_arrays, dst_coef_arrays);\n    else if (info->x_crop_offset != 0 || info->y_crop_offset != 0)\n      do_crop(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t      src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_FLIP_H:\n    if (info->y_crop_offset != 0)\n      do_flip_h(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t\tsrc_coef_arrays, dst_coef_arrays);\n    else\n      do_flip_h_no_crop(srcinfo, dstinfo, info->x_crop_offset,\n\t\t\tsrc_coef_arrays);\n    break;\n  case JXFORM_FLIP_V:\n    do_flip_v(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t      src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_TRANSPOSE:\n    do_transpose(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t\t src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_TRANSVERSE:\n    do_transverse(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t\t  src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_ROT_90:\n    do_rot_90(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t      src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_ROT_180:\n    do_rot_180(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t       src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_ROT_270:\n    do_rot_270(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t       src_coef_arrays, dst_coef_arrays);\n    break;\n  case JXFORM_WIPE:\n    do_wipe(srcinfo, dstinfo, info->x_crop_offset, info->y_crop_offset,\n\t    src_coef_arrays, info->drop_width, info->drop_height);\n    break;\n  }\n}\n\n/* jtransform_perfect_transform\n *\n * Determine whether lossless transformation is perfectly\n * possible for a specified image and transformation.\n *\n * Inputs:\n *   image_width, image_height: source image dimensions.\n *   MCU_width, MCU_height: pixel dimensions of MCU.\n *   transform: transformation identifier.\n * Parameter sources from initialized jpeg_struct\n * (after reading source header):\n *   image_width = cinfo.image_width\n *   image_height = cinfo.image_height\n *   MCU_width = cinfo.max_h_samp_factor * cinfo.block_size\n *   MCU_height = cinfo.max_v_samp_factor * cinfo.block_size\n * Result:\n *   TRUE = perfect transformation possible\n *   FALSE = perfect transformation not possible\n *           (may use custom action then)\n */\n\nGLOBAL(boolean)\njtransform_perfect_transform(JDIMENSION image_width, JDIMENSION image_height,\n\t\t\t     int MCU_width, int MCU_height,\n\t\t\t     JXFORM_CODE transform)\n{\n  boolean result = TRUE; /* initialize TRUE */\n\n  switch (transform) {\n  case JXFORM_FLIP_H:\n  case JXFORM_ROT_270:\n    if (image_width % (JDIMENSION) MCU_width)\n      result = FALSE;\n    break;\n  case JXFORM_FLIP_V:\n  case JXFORM_ROT_90:\n    if (image_height % (JDIMENSION) MCU_height)\n      result = FALSE;\n    break;\n  case JXFORM_TRANSVERSE:\n  case JXFORM_ROT_180:\n    if (image_width % (JDIMENSION) MCU_width)\n      result = FALSE;\n    if (image_height % (JDIMENSION) MCU_height)\n      result = FALSE;\n    break;\n  default:\n    break;\n  }\n\n  return result;\n}\n\n#endif /* TRANSFORMS_SUPPORTED */\n\n\n/* Setup decompression object to save desired markers in memory.\n * This must be called before jpeg_read_header() to have the desired effect.\n */\n\nGLOBAL(void)\njcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)\n{\n#ifdef SAVE_MARKERS_SUPPORTED\n  int m;\n\n  /* Save comments except under NONE option */\n  if (option != JCOPYOPT_NONE) {\n    jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);\n  }\n  /* Save all types of APPn markers iff ALL option */\n  if (option == JCOPYOPT_ALL) {\n    for (m = 0; m < 16; m++)\n      jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);\n  }\n#endif /* SAVE_MARKERS_SUPPORTED */\n}\n\n/* Copy markers saved in the given source object to the destination object.\n * This should be called just after jpeg_start_compress() or\n * jpeg_write_coefficients().\n * Note that those routines will have written the SOI, and also the\n * JFIF APP0 or Adobe APP14 markers if selected.\n */\n\nGLOBAL(void)\njcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t\t       JCOPY_OPTION option)\n{\n  jpeg_saved_marker_ptr marker;\n\n  /* In the current implementation, we don't actually need to examine the\n   * option flag here; we just copy everything that got saved.\n   * But to avoid confusion, we do not output JFIF and Adobe APP14 markers\n   * if the encoder library already wrote one.\n   */\n  for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {\n    if (dstinfo->write_JFIF_header &&\n\tmarker->marker == JPEG_APP0 &&\n\tmarker->data_length >= 5 &&\n\tGETJOCTET(marker->data[0]) == 0x4A &&\n\tGETJOCTET(marker->data[1]) == 0x46 &&\n\tGETJOCTET(marker->data[2]) == 0x49 &&\n\tGETJOCTET(marker->data[3]) == 0x46 &&\n\tGETJOCTET(marker->data[4]) == 0)\n      continue;\t\t\t/* reject duplicate JFIF */\n    if (dstinfo->write_Adobe_marker &&\n\tmarker->marker == JPEG_APP0+14 &&\n\tmarker->data_length >= 5 &&\n\tGETJOCTET(marker->data[0]) == 0x41 &&\n\tGETJOCTET(marker->data[1]) == 0x64 &&\n\tGETJOCTET(marker->data[2]) == 0x6F &&\n\tGETJOCTET(marker->data[3]) == 0x62 &&\n\tGETJOCTET(marker->data[4]) == 0x65)\n      continue;\t\t\t/* reject duplicate Adobe */\n#ifdef NEED_FAR_POINTERS\n    /* We could use jpeg_write_marker if the data weren't FAR... */\n    {\n      unsigned int i;\n      jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);\n      for (i = 0; i < marker->data_length; i++)\n\tjpeg_write_m_byte(dstinfo, marker->data[i]);\n    }\n#else\n    jpeg_write_marker(dstinfo, marker->marker,\n\t\t      marker->data, marker->data_length);\n#endif\n  }\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/transupp.h",
    "content": "/*\n * transupp.h\n *\n * Copyright (C) 1997-2013, Thomas G. Lane, Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains declarations for image transformation routines and\n * other utility code used by the jpegtran sample application.  These are\n * NOT part of the core JPEG library.  But we keep these routines separate\n * from jpegtran.c to ease the task of maintaining jpegtran-like programs\n * that have other user interfaces.\n *\n * NOTE: all the routines declared here have very specific requirements\n * about when they are to be executed during the reading and writing of the\n * source and destination files.  See the comments in transupp.c, or see\n * jpegtran.c for an example of correct usage.\n */\n\n/* If you happen not to want the image transform support, disable it here */\n#ifndef TRANSFORMS_SUPPORTED\n#define TRANSFORMS_SUPPORTED 1\t\t/* 0 disables transform code */\n#endif\n\n/*\n * Although rotating and flipping data expressed as DCT coefficients is not\n * hard, there is an asymmetry in the JPEG format specification for images\n * whose dimensions aren't multiples of the iMCU size.  The right and bottom\n * image edges are padded out to the next iMCU boundary with junk data; but\n * no padding is possible at the top and left edges.  If we were to flip\n * the whole image including the pad data, then pad garbage would become\n * visible at the top and/or left, and real pixels would disappear into the\n * pad margins --- perhaps permanently, since encoders & decoders may not\n * bother to preserve DCT blocks that appear to be completely outside the\n * nominal image area.  So, we have to exclude any partial iMCUs from the\n * basic transformation.\n *\n * Transpose is the only transformation that can handle partial iMCUs at the\n * right and bottom edges completely cleanly.  flip_h can flip partial iMCUs\n * at the bottom, but leaves any partial iMCUs at the right edge untouched.\n * Similarly flip_v leaves any partial iMCUs at the bottom edge untouched.\n * The other transforms are defined as combinations of these basic transforms\n * and process edge blocks in a way that preserves the equivalence.\n *\n * The \"trim\" option causes untransformable partial iMCUs to be dropped;\n * this is not strictly lossless, but it usually gives the best-looking\n * result for odd-size images.  Note that when this option is active,\n * the expected mathematical equivalences between the transforms may not hold.\n * (For example, -rot 270 -trim trims only the bottom edge, but -rot 90 -trim\n * followed by -rot 180 -trim trims both edges.)\n *\n * We also offer a lossless-crop option, which discards data outside a given\n * image region but losslessly preserves what is inside.  Like the rotate and\n * flip transforms, lossless crop is restricted by the current JPEG format: the\n * upper left corner of the selected region must fall on an iMCU boundary.  If\n * this does not hold for the given crop parameters, we silently move the upper\n * left corner up and/or left to make it so, simultaneously increasing the\n * region dimensions to keep the lower right crop corner unchanged.  (Thus, the\n * output image covers at least the requested region, but may cover more.)\n * The adjustment of the region dimensions may be optionally disabled.\n *\n * A complementary lossless-wipe option is provided to discard (gray out) data\n * inside a given image region while losslessly preserving what is outside.\n *\n * We also provide a lossless-resize option, which is kind of a lossless-crop\n * operation in the DCT coefficient block domain - it discards higher-order\n * coefficients and losslessly preserves lower-order coefficients of a\n * sub-block.\n *\n * Rotate/flip transform, resize, and crop can be requested together in a\n * single invocation.  The crop is applied last --- that is, the crop region\n * is specified in terms of the destination image after transform/resize.\n *\n * We also offer a \"force to grayscale\" option, which simply discards the\n * chrominance channels of a YCbCr image.  This is lossless in the sense that\n * the luminance channel is preserved exactly.  It's not the same kind of\n * thing as the rotate/flip transformations, but it's convenient to handle it\n * as part of this package, mainly because the transformation routines have to\n * be aware of the option to know how many components to work on.\n */\n\n\n/* Short forms of external names for systems with brain-damaged linkers. */\n\n#ifdef NEED_SHORT_EXTERNAL_NAMES\n#define jtransform_parse_crop_spec\tjTrParCrop\n#define jtransform_request_workspace\tjTrRequest\n#define jtransform_adjust_parameters\tjTrAdjust\n#define jtransform_execute_transform\tjTrExec\n#define jtransform_perfect_transform\tjTrPerfect\n#define jcopy_markers_setup\t\tjCMrkSetup\n#define jcopy_markers_execute\t\tjCMrkExec\n#endif /* NEED_SHORT_EXTERNAL_NAMES */\n\n\n/*\n * Codes for supported types of image transformations.\n */\n\ntypedef enum {\n\tJXFORM_NONE,\t\t/* no transformation */\n\tJXFORM_FLIP_H,\t\t/* horizontal flip */\n\tJXFORM_FLIP_V,\t\t/* vertical flip */\n\tJXFORM_TRANSPOSE,\t/* transpose across UL-to-LR axis */\n\tJXFORM_TRANSVERSE,\t/* transpose across UR-to-LL axis */\n\tJXFORM_ROT_90,\t\t/* 90-degree clockwise rotation */\n\tJXFORM_ROT_180,\t\t/* 180-degree rotation */\n\tJXFORM_ROT_270,\t\t/* 270-degree clockwise (or 90 ccw) */\n\tJXFORM_WIPE\t\t/* wipe */\n} JXFORM_CODE;\n\n/*\n * Codes for crop parameters, which can individually be unspecified,\n * positive or negative for xoffset or yoffset,\n * positive or forced for width or height.\n */\n\ntypedef enum {\n        JCROP_UNSET,\n        JCROP_POS,\n        JCROP_NEG,\n        JCROP_FORCE\n} JCROP_CODE;\n\n/*\n * Transform parameters struct.\n * NB: application must not change any elements of this struct after\n * calling jtransform_request_workspace.\n */\n\ntypedef struct {\n  /* Options: set by caller */\n  JXFORM_CODE transform;\t/* image transform operator */\n  boolean perfect;\t\t/* if TRUE, fail if partial MCUs are requested */\n  boolean trim;\t\t\t/* if TRUE, trim partial MCUs as needed */\n  boolean force_grayscale;\t/* if TRUE, convert color image to grayscale */\n  boolean crop;\t\t\t/* if TRUE, crop or wipe source image */\n\n  /* Crop parameters: application need not set these unless crop is TRUE.\n   * These can be filled in by jtransform_parse_crop_spec().\n   */\n  JDIMENSION crop_width;\t/* Width of selected region */\n  JCROP_CODE crop_width_set;\t/* (forced disables adjustment) */\n  JDIMENSION crop_height;\t/* Height of selected region */\n  JCROP_CODE crop_height_set;\t/* (forced disables adjustment) */\n  JDIMENSION crop_xoffset;\t/* X offset of selected region */\n  JCROP_CODE crop_xoffset_set;\t/* (negative measures from right edge) */\n  JDIMENSION crop_yoffset;\t/* Y offset of selected region */\n  JCROP_CODE crop_yoffset_set;\t/* (negative measures from bottom edge) */\n\n  /* Internal workspace: caller should not touch these */\n  int num_components;\t\t/* # of components in workspace */\n  jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */\n  JDIMENSION output_width;\t/* cropped destination dimensions */\n  JDIMENSION output_height;\n  JDIMENSION x_crop_offset;\t/* destination crop offsets measured in iMCUs */\n  JDIMENSION y_crop_offset;\n  JDIMENSION drop_width;\t/* drop/wipe dimensions measured in iMCUs */\n  JDIMENSION drop_height;\n  int iMCU_sample_width;\t/* destination iMCU size */\n  int iMCU_sample_height;\n} jpeg_transform_info;\n\n\n#if TRANSFORMS_SUPPORTED\n\n/* Parse a crop specification (written in X11 geometry style) */\nEXTERN(boolean) jtransform_parse_crop_spec\n\tJPP((jpeg_transform_info *info, const char *spec));\n/* Request any required workspace */\nEXTERN(boolean) jtransform_request_workspace\n\tJPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));\n/* Adjust output image parameters */\nEXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters\n\tJPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t     jvirt_barray_ptr *src_coef_arrays,\n\t     jpeg_transform_info *info));\n/* Execute the actual transformation, if any */\nEXTERN(void) jtransform_execute_transform\n\tJPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t     jvirt_barray_ptr *src_coef_arrays,\n\t     jpeg_transform_info *info));\n/* Determine whether lossless transformation is perfectly\n * possible for a specified image and transformation.\n */\nEXTERN(boolean) jtransform_perfect_transform\n\tJPP((JDIMENSION image_width, JDIMENSION image_height,\n\t     int MCU_width, int MCU_height,\n\t     JXFORM_CODE transform));\n\n/* jtransform_execute_transform used to be called\n * jtransform_execute_transformation, but some compilers complain about\n * routine names that long.  This macro is here to avoid breaking any\n * old source code that uses the original name...\n */\n#define jtransform_execute_transformation\tjtransform_execute_transform\n\n#endif /* TRANSFORMS_SUPPORTED */\n\n\n/*\n * Support for copying optional markers from source to destination file.\n */\n\ntypedef enum {\n\tJCOPYOPT_NONE,\t\t/* copy no optional markers */\n\tJCOPYOPT_COMMENTS,\t/* copy only comment (COM) markers */\n\tJCOPYOPT_ALL\t\t/* copy all optional markers */\n} JCOPY_OPTION;\n\n#define JCOPYOPT_DEFAULT  JCOPYOPT_COMMENTS\t/* recommended default */\n\n/* Setup decompression object to save desired markers in memory */\nEXTERN(void) jcopy_markers_setup\n\tJPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));\n/* Copy markers saved in the given source object to the destination object */\nEXTERN(void) jcopy_markers_execute\n\tJPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,\n\t     JCOPY_OPTION option));\n"
  },
  {
    "path": "tess-two/jni/libjpeg/usage.txt",
    "content": "USAGE instructions for the Independent JPEG Group's JPEG software\n=================================================================\n\nThis file describes usage of the JPEG conversion programs cjpeg and djpeg,\nas well as the utility programs jpegtran, rdjpgcom and wrjpgcom.  (See\nthe other documentation files if you wish to use the JPEG library within\nyour own programs.)\n\nIf you are on a Unix machine you may prefer to read the Unix-style manual\npages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.\n\n\nINTRODUCTION\n\nThese programs implement JPEG image encoding, decoding, and transcoding.\nJPEG (pronounced \"jay-peg\") is a standardized compression method for\nfull-color and grayscale images.\n\n\nGENERAL USAGE\n\nWe provide two programs, cjpeg to compress an image file into JPEG format,\nand djpeg to decompress a JPEG file back into a conventional image format.\n\nOn Unix-like systems, you say:\n\tcjpeg [switches] [imagefile] >jpegfile\nor\n\tdjpeg [switches] [jpegfile]  >imagefile\nThe programs read the specified input file, or standard input if none is\nnamed.  They always write to standard output (with trace/error messages to\nstandard error).  These conventions are handy for piping images between\nprograms.\n\nOn most non-Unix systems, you say:\n\tcjpeg [switches] imagefile jpegfile\nor\n\tdjpeg [switches] jpegfile  imagefile\ni.e., both the input and output files are named on the command line.  This\nstyle is a little more foolproof, and it loses no functionality if you don't\nhave pipes.  (You can get this style on Unix too, if you prefer, by defining\nTWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)\n\nYou can also say:\n\tcjpeg [switches] -outfile jpegfile  imagefile\nor\n\tdjpeg [switches] -outfile imagefile  jpegfile\nThis syntax works on all systems, so it is useful for scripts.\n\nThe currently supported image file formats are: PPM (PBMPLUS color format),\nPGM (PBMPLUS grayscale format), BMP, Targa, and RLE (Utah Raster Toolkit\nformat).  (RLE is supported only if the URT library is available, which it\nisn't on most non-Unix systems.)  cjpeg recognizes the input image format\nautomatically, with the exception of some Targa-format files.  You have to\ntell djpeg which format to generate.\n\nJPEG files are in the standard JFIF file format.  There are other,\nless widely used JPEG-based file formats, but we don't support them.\n\nAll switch names may be abbreviated; for example, -grayscale may be written\n-gray or -gr.  Most of the \"basic\" switches can be abbreviated to as little as\none letter.  Upper and lower case are equivalent (-BMP is the same as -bmp).\nBritish spellings are also accepted (e.g., -greyscale), though for brevity\nthese are not mentioned below.\n\n\nCJPEG DETAILS\n\nThe basic command line switches for cjpeg are:\n\n\t-quality N[,...]  Scale quantization tables to adjust image quality.\n\t\t\tQuality is 0 (worst) to 100 (best); default is 75.\n\t\t\t(See below for more info.)\n\n\t-grayscale\tCreate monochrome JPEG file from color input.\n\t\t\tBe sure to use this switch when compressing a grayscale\n\t\t\tBMP file, because cjpeg isn't bright enough to notice\n\t\t\twhether a BMP file uses only shades of gray.  By\n\t\t\tsaying -grayscale, you'll get a smaller JPEG file that\n\t\t\ttakes less time to process.\n\n\t-rgb\t\tCreate RGB JPEG file.\n\t\t\tUsing this switch suppresses the conversion from RGB\n\t\t\tcolorspace input to the default YCbCr JPEG colorspace.\n\t\t\tYou can use this switch in combination with the\n\t\t\t-block N switch (see below) for lossless JPEG coding.\n\t\t\tSee also the -rgb1 switch below.\n\n\t-optimize\tPerform optimization of entropy encoding parameters.\n\t\t\tWithout this, default encoding parameters are used.\n\t\t\t-optimize usually makes the JPEG file a little smaller,\n\t\t\tbut cjpeg runs somewhat slower and needs much more\n\t\t\tmemory.  Image quality and speed of decompression are\n\t\t\tunaffected by -optimize.\n\n\t-progressive\tCreate progressive JPEG file (see below).\n\n\t-scale M/N\tScale the output image by a factor M/N.  Currently\n\t\t\tsupported scale factors are M/N with all N from 1 to\n\t\t\t16, where M is the destination DCT size, which is 8 by\n\t\t\tdefault (see -block N switch below).\n\n\t-targa\t\tInput file is Targa format.  Targa files that contain\n\t\t\tan \"identification\" field will not be automatically\n\t\t\trecognized by cjpeg; for such files you must specify\n\t\t\t-targa to make cjpeg treat the input as Targa format.\n\t\t\tFor most Targa files, you won't need this switch.\n\nThe -quality switch lets you trade off compressed file size against quality of\nthe reconstructed image: the higher the quality setting, the larger the JPEG\nfile, and the closer the output image will be to the original input.  Normally\nyou want to use the lowest quality setting (smallest file) that decompresses\ninto something visually indistinguishable from the original image.  For this\npurpose the quality setting should be between 50 and 95; the default of 75 is\noften about right.  If you see defects at -quality 75, then go up 5 or 10\ncounts at a time until you are happy with the output image.  (The optimal\nsetting will vary from one image to another.)\n\n-quality 100 will generate a quantization table of all 1's, minimizing loss\nin the quantization step (but there is still information loss in subsampling,\nas well as roundoff error).  This setting is mainly of interest for\nexperimental purposes.  Quality values above about 95 are NOT recommended for\nnormal use; the compressed file size goes up dramatically for hardly any gain\nin output image quality.\n\nIn the other direction, quality values below 50 will produce very small files\nof low image quality.  Settings around 5 to 10 might be useful in preparing an\nindex of a large image library, for example.  Try -quality 2 (or so) for some\namusing Cubist effects.  (Note: quality values below about 25 generate 2-byte\nquantization tables, which are considered optional in the JPEG standard.\ncjpeg emits a warning message when you give such a quality value, because some\nother JPEG programs may be unable to decode the resulting file.  Use -baseline\nif you need to ensure compatibility at low quality values.)\n\nThe -quality option has been extended in IJG version 7 for support of separate\nquality settings for luminance and chrominance (or in general, for every\nprovided quantization table slot).  This feature is useful for high-quality\napplications which cannot accept the damage of color data by coarse\nsubsampling settings.  You can now easily reduce the color data amount more\nsmoothly with finer control without separate subsampling.  The resulting file\nis fully compliant with standard JPEG decoders.\nNote that the -quality ratings refer to the quantization table slots, and that\nthe last value is replicated if there are more q-table slots than parameters.\nThe default q-table slots are 0 for luminance and 1 for chrominance with\ndefault tables as given in the JPEG standard.  This is compatible with the old\nbehaviour in case that only one parameter is given, which is then used for\nboth luminance and chrominance (slots 0 and 1).  More or custom quantization\ntables can be set with -qtables and assigned to components with -qslots\nparameter (see the \"wizard\" switches below).\nCAUTION: You must explicitly add -sample 1x1 for efficient separate color\nquality selection, since the default value used by library is 2x2!\n\nThe -progressive switch creates a \"progressive JPEG\" file.  In this type of\nJPEG file, the data is stored in multiple scans of increasing quality.  If the\nfile is being transmitted over a slow communications link, the decoder can use\nthe first scan to display a low-quality image very quickly, and can then\nimprove the display with each subsequent scan.  The final image is exactly\nequivalent to a standard JPEG file of the same quality setting, and the total\nfile size is about the same --- often a little smaller.\n\nSwitches for advanced users:\n\n\t-arithmetic\tUse arithmetic coding.\n\t\t\tCAUTION: arithmetic coded JPEG is not yet widely\n\t\t\timplemented, so many decoders will be unable to\n\t\t\tview an arithmetic coded JPEG file at all.\n\n\t-block N\tSet DCT block size.  All N from 1 to 16 are possible.\n\t\t\tDefault is 8 (baseline format).\n\t\t\tLarger values produce higher compression,\n\t\t\tsmaller values produce higher quality\n\t\t\t(exact DCT stage possible with 1 or 2; with the\n\t\t\tdefault quality of 75 and default Luminance qtable\n\t\t\tthe DCT+Quantization stage is lossless for N=1).\n\t\t\tCAUTION: An implementation of the JPEG SmartScale\n\t\t\textension is required for this feature.  SmartScale\n\t\t\tenabled JPEG is not yet widely implemented, so many\n\t\t\tdecoders will be unable to view a SmartScale extended\n\t\t\tJPEG file at all.\n\n\t-rgb1\t\tCreate RGB JPEG file with reversible color transform.\n\t\t\tWorks like the -rgb switch (see above) and inserts a\n\t\t\tsimple reversible color transform into the processing\n\t\t\twhich significantly improves the compression.\n\t\t\tUse this switch in combination with the -block N\n\t\t\tswitch (see above) for lossless JPEG coding.\n\t\t\tCAUTION: A decoder with inverse color transform\n\t\t\tsupport is required for this feature.  Reversible\n\t\t\tcolor transform support is not yet widely implemented,\n\t\t\tso many decoders will be unable to view a reversible\n\t\t\tcolor transformed JPEG file at all.\n\n\t-bgycc\t\tCreate big gamut YCC JPEG file.\n\t\t\tIn this type of encoding the color difference\n\t\t\tcomponents are quantized further by a factor of 2\n\t\t\tcompared to the normal Cb/Cr values, thus creating\n\t\t\tspace to allow larger color values with higher\n\t\t\tsaturation than the normal gamut limits to be encoded.\n\t\t\tIn order to compensate for the loss of color fidelity\n\t\t\tcompared to a normal YCC encoded file, the color\n\t\t\tquantization tables can be adjusted accordingly.\n\t\t\tFor example, cjpeg -bgycc -quality 80,90 will give\n\t\t\tsimilar results as cjpeg -quality 80.\n\t\t\tCAUTION: For correct decompression a decoder with big\n\t\t\tgamut YCC support (JFIF version 2) is required.\n\t\t\tAn old decoder may or may not display a big gamut YCC\n\t\t\tencoded JPEG file, depending on JFIF version check\n\t\t\tand corresponding warning/error configuration.\n\t\t\tIn case of a granted decompression the old decoder\n\t\t\twill display the image with half saturated colors.\n\n\t-dct int\tUse integer DCT method (default).\n\t-dct fast\tUse fast integer DCT (less accurate).\n\t-dct float\tUse floating-point DCT method.\n\t\t\tThe float method is very slightly more accurate than\n\t\t\tthe int method, but is much slower unless your machine\n\t\t\thas very fast floating-point hardware.  Also note that\n\t\t\tresults of the floating-point method may vary slightly\n\t\t\tacross machines, while the integer methods should give\n\t\t\tthe same results everywhere.  The fast integer method\n\t\t\tis much less accurate than the other two.\n\n\t-nosmooth\tDon't use high-quality downsampling.\n\n\t-restart N\tEmit a JPEG restart marker every N MCU rows, or every\n\t\t\tN MCU blocks if \"B\" is attached to the number.\n\t\t\t-restart 0 (the default) means no restart markers.\n\n\t-smooth N\tSmooth the input image to eliminate dithering noise.\n\t\t\tN, ranging from 1 to 100, indicates the strength of\n\t\t\tsmoothing.  0 (the default) means no smoothing.\n\n\t-maxmemory N\tSet limit for amount of memory to use in processing\n\t\t\tlarge images.  Value is in thousands of bytes, or\n\t\t\tmillions of bytes if \"M\" is attached to the number.\n\t\t\tFor example, -max 4m selects 4000000 bytes.  If more\n\t\t\tspace is needed, temporary files will be used.\n\n\t-verbose\tEnable debug printout.  More -v's give more printout.\n\tor  -debug\tAlso, version information is printed at startup.\n\nThe -restart option inserts extra markers that allow a JPEG decoder to\nresynchronize after a transmission error.  Without restart markers, any damage\nto a compressed file will usually ruin the image from the point of the error\nto the end of the image; with restart markers, the damage is usually confined\nto the portion of the image up to the next restart marker.  Of course, the\nrestart markers occupy extra space.  We recommend -restart 1 for images that\nwill be transmitted across unreliable networks such as Usenet.\n\nThe -smooth option filters the input to eliminate fine-scale noise.  This is\noften useful when converting dithered images to JPEG: a moderate smoothing\nfactor of 10 to 50 gets rid of dithering patterns in the input file, resulting\nin a smaller JPEG file and a better-looking image.  Too large a smoothing\nfactor will visibly blur the image, however.\n\nSwitches for wizards:\n\n\t-baseline\tForce baseline-compatible quantization tables to be\n\t\t\tgenerated.  This clamps quantization values to 8 bits\n\t\t\teven at low quality settings.  (This switch is poorly\n\t\t\tnamed, since it does not ensure that the output is\n\t\t\tactually baseline JPEG.  For example, you can use\n\t\t\t-baseline and -progressive together.)\n\n\t-qtables file\tUse the quantization tables given in the specified\n\t\t\ttext file.\n\n\t-qslots N[,...] Select which quantization table to use for each color\n\t\t\tcomponent.\n\n\t-sample HxV[,...]  Set JPEG sampling factors for each color component.\n\n\t-scans file\tUse the scan script given in the specified text file.\n\nThe \"wizard\" switches are intended for experimentation with JPEG.  If you\ndon't know what you are doing, DON'T USE THEM.  These switches are documented\nfurther in the file wizard.txt.\n\n\nDJPEG DETAILS\n\nThe basic command line switches for djpeg are:\n\n\t-colors N\tReduce image to at most N colors.  This reduces the\n\tor -quantize N\tnumber of colors used in the output image, so that it\n\t\t\tcan be displayed on a colormapped display or stored in\n\t\t\ta colormapped file format.  For example, if you have\n\t\t\tan 8-bit display, you'd need to reduce to 256 or fewer\n\t\t\tcolors.  (-colors is the recommended name, -quantize\n\t\t\tis provided only for backwards compatibility.)\n\n\t-fast\t\tSelect recommended processing options for fast, low\n\t\t\tquality output.  (The default options are chosen for\n\t\t\thighest quality output.)  Currently, this is equivalent\n\t\t\tto \"-dct fast -nosmooth -onepass -dither ordered\".\n\n\t-grayscale\tForce grayscale output even if JPEG file is color.\n\t\t\tUseful for viewing on monochrome displays; also,\n\t\t\tdjpeg runs noticeably faster in this mode.\n\n\t-rgb\t\tForce RGB output even if JPEG file is grayscale.\n\t\t\tThis is provided to support applications that don't\n\t\t\twant to cope with grayscale as a separate case.\n\n\t-scale M/N\tScale the output image by a factor M/N.  Currently\n\t\t\tsupported scale factors are M/N with all M from 1 to\n\t\t\t16, where N is the source DCT size, which is 8 for\n\t\t\tbaseline JPEG.  If the /N part is omitted, then M\n\t\t\tspecifies the DCT scaled size to be applied on the\n\t\t\tgiven input.  For baseline JPEG this is equivalent to\n\t\t\tM/8 scaling, since the source DCT size for baseline\n\t\t\tJPEG is 8.  Scaling is handy if the image is larger\n\t\t\tthan your screen; also, djpeg runs much faster when\n\t\t\tscaling down the output.\n\n\t-bmp\t\tSelect BMP output format (Windows flavor).  8-bit\n\t\t\tcolormapped format is emitted if -colors or -grayscale\n\t\t\tis specified, or if the JPEG file is grayscale;\n\t\t\totherwise, 24-bit full-color format is emitted.\n\n\t-gif\t\tSelect GIF output format.  Since GIF does not support\n\t\t\tmore than 256 colors, -colors 256 is assumed (unless\n\t\t\tyou specify a smaller number of colors).  If you\n\t\t\tspecify -fast, the default number of colors is 216.\n\n\t-os2\t\tSelect BMP output format (OS/2 1.x flavor).  8-bit\n\t\t\tcolormapped format is emitted if -colors or -grayscale\n\t\t\tis specified, or if the JPEG file is grayscale;\n\t\t\totherwise, 24-bit full-color format is emitted.\n\n\t-pnm\t\tSelect PBMPLUS (PPM/PGM) output format (this is the\n\t\t\tdefault format).  PGM is emitted if the JPEG file is\n\t\t\tgrayscale or if -grayscale is specified; otherwise\n\t\t\tPPM is emitted.\n\n\t-rle\t\tSelect RLE output format.  (Requires URT library.)\n\n\t-targa\t\tSelect Targa output format.  Grayscale format is\n\t\t\temitted if the JPEG file is grayscale or if\n\t\t\t-grayscale is specified; otherwise, colormapped format\n\t\t\tis emitted if -colors is specified; otherwise, 24-bit\n\t\t\tfull-color format is emitted.\n\nSwitches for advanced users:\n\n\t-dct int\tUse integer DCT method (default).\n\t-dct fast\tUse fast integer DCT (less accurate).\n\t-dct float\tUse floating-point DCT method.\n\t\t\tThe float method is very slightly more accurate than\n\t\t\tthe int method, but is much slower unless your machine\n\t\t\thas very fast floating-point hardware.  Also note that\n\t\t\tresults of the floating-point method may vary slightly\n\t\t\tacross machines, while the integer methods should give\n\t\t\tthe same results everywhere.  The fast integer method\n\t\t\tis much less accurate than the other two.\n\n\t-dither fs\tUse Floyd-Steinberg dithering in color quantization.\n\t-dither ordered\tUse ordered dithering in color quantization.\n\t-dither none\tDo not use dithering in color quantization.\n\t\t\tBy default, Floyd-Steinberg dithering is applied when\n\t\t\tquantizing colors; this is slow but usually produces\n\t\t\tthe best results.  Ordered dither is a compromise\n\t\t\tbetween speed and quality; no dithering is fast but\n\t\t\tusually looks awful.  Note that these switches have\n\t\t\tno effect unless color quantization is being done.\n\t\t\tOrdered dither is only available in -onepass mode.\n\n\t-map FILE\tQuantize to the colors used in the specified image\n\t\t\tfile.  This is useful for producing multiple files\n\t\t\twith identical color maps, or for forcing a predefined\n\t\t\tset of colors to be used.  The FILE must be a GIF\n\t\t\tor PPM file.  This option overrides -colors and\n\t\t\t-onepass.\n\n\t-nosmooth\tDon't use high-quality upsampling.\n\n\t-onepass\tUse one-pass instead of two-pass color quantization.\n\t\t\tThe one-pass method is faster and needs less memory,\n\t\t\tbut it produces a lower-quality image.  -onepass is\n\t\t\tignored unless you also say -colors N.  Also,\n\t\t\tthe one-pass method is always used for grayscale\n\t\t\toutput (the two-pass method is no improvement then).\n\n\t-maxmemory N\tSet limit for amount of memory to use in processing\n\t\t\tlarge images.  Value is in thousands of bytes, or\n\t\t\tmillions of bytes if \"M\" is attached to the number.\n\t\t\tFor example, -max 4m selects 4000000 bytes.  If more\n\t\t\tspace is needed, temporary files will be used.\n\n\t-verbose\tEnable debug printout.  More -v's give more printout.\n\tor  -debug\tAlso, version information is printed at startup.\n\n\nHINTS FOR CJPEG\n\nColor GIF files are not the ideal input for JPEG; JPEG is really intended for\ncompressing full-color (24-bit) images.  In particular, don't try to convert\ncartoons, line drawings, and other images that have only a few distinct\ncolors.  GIF works great on these, JPEG does not.  If you want to convert a\nGIF to JPEG, you should experiment with cjpeg's -quality and -smooth options\nto get a satisfactory conversion.  -smooth 10 or so is often helpful.\n\nAvoid running an image through a series of JPEG compression/decompression\ncycles.  Image quality loss will accumulate; after ten or so cycles the image\nmay be noticeably worse than it was after one cycle.  It's best to use a\nlossless format while manipulating an image, then convert to JPEG format when\nyou are ready to file the image away.\n\nThe -optimize option to cjpeg is worth using when you are making a \"final\"\nversion for posting or archiving.  It's also a win when you are using low\nquality settings to make very small JPEG files; the percentage improvement\nis often a lot more than it is on larger files.  (At present, -optimize\nmode is always selected when generating progressive JPEG files.)\n\nGIF input files are no longer supported, to avoid the Unisys LZW patent\n(now expired).\n(Conversion of GIF files to JPEG is usually a bad idea anyway.)\n\n\nHINTS FOR DJPEG\n\nTo get a quick preview of an image, use the -grayscale and/or -scale switches.\n\"-grayscale -scale 1/8\" is the fastest case.\n\nSeveral options are available that trade off image quality to gain speed.\n\"-fast\" turns on the recommended settings.\n\n\"-dct fast\" and/or \"-nosmooth\" gain speed at a small sacrifice in quality.\nWhen producing a color-quantized image, \"-onepass -dither ordered\" is fast but\nmuch lower quality than the default behavior.  \"-dither none\" may give\nacceptable results in two-pass mode, but is seldom tolerable in one-pass mode.\n\nIf you are fortunate enough to have very fast floating point hardware,\n\"-dct float\" may be even faster than \"-dct fast\".  But on most machines\n\"-dct float\" is slower than \"-dct int\"; in this case it is not worth using,\nbecause its theoretical accuracy advantage is too small to be significant\nin practice.\n\nTwo-pass color quantization requires a good deal of memory; on MS-DOS machines\nit may run out of memory even with -maxmemory 0.  In that case you can still\ndecompress, with some loss of image quality, by specifying -onepass for\none-pass quantization.\n\nTo avoid the Unisys LZW patent (now expired), djpeg produces uncompressed GIF\nfiles.  These are larger than they should be, but are readable by standard GIF\ndecoders.\n\n\nHINTS FOR BOTH PROGRAMS\n\nIf more space is needed than will fit in the available main memory (as\ndetermined by -maxmemory), temporary files will be used.  (MS-DOS versions\nwill try to get extended or expanded memory first.)  The temporary files are\noften rather large: in typical cases they occupy three bytes per pixel, for\nexample 3*800*600 = 1.44Mb for an 800x600 image.  If you don't have enough\nfree disk space, leave out -progressive and -optimize (for cjpeg) or specify\n-onepass (for djpeg).\n\nOn MS-DOS, the temporary files are created in the directory named by the TMP\nor TEMP environment variable, or in the current directory if neither of those\nexist.  Amiga implementations put the temp files in the directory named by\nJPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free\nspace.\n\nThe default memory usage limit (-maxmemory) is set when the software is\ncompiled.  If you get an \"insufficient memory\" error, try specifying a smaller\n-maxmemory value, even -maxmemory 0 to use the absolute minimum space.  You\nmay want to recompile with a smaller default value if this happens often.\n\nOn machines that have \"environment\" variables, you can define the environment\nvariable JPEGMEM to set the default memory limit.  The value is specified as\ndescribed for the -maxmemory switch.  JPEGMEM overrides the default value\nspecified when the program was compiled, and itself is overridden by an\nexplicit -maxmemory switch.\n\nOn MS-DOS machines, -maxmemory is the amount of main (conventional) memory to\nuse.  (Extended or expanded memory is also used if available.)  Most\nDOS-specific versions of this software do their own memory space estimation\nand do not need you to specify -maxmemory.\n\n\nJPEGTRAN\n\njpegtran performs various useful transformations of JPEG files.\nIt can translate the coded representation from one variant of JPEG to another,\nfor example from baseline JPEG to progressive JPEG or vice versa.  It can also\nperform some rearrangements of the image data, for example turning an image\nfrom landscape to portrait format by rotation.  For EXIF files and JPEG files\ncontaining Exif data, you may prefer to use exiftran instead.\n\njpegtran works by rearranging the compressed data (DCT coefficients), without\never fully decoding the image.  Therefore, its transformations are lossless:\nthere is no image degradation at all, which would not be true if you used\ndjpeg followed by cjpeg to accomplish the same conversion.  But by the same\ntoken, jpegtran cannot perform lossy operations such as changing the image\nquality.  However, while the image data is losslessly transformed, metadata\ncan be removed.  See the -copy option for specifics.\n\njpegtran uses a command line syntax similar to cjpeg or djpeg.\nOn Unix-like systems, you say:\n\tjpegtran [switches] [inputfile] >outputfile\nOn most non-Unix systems, you say:\n\tjpegtran [switches] inputfile outputfile\nwhere both the input and output files are JPEG files.\n\nTo specify the coded JPEG representation used in the output file,\njpegtran accepts a subset of the switches recognized by cjpeg:\n\t-optimize\tPerform optimization of entropy encoding parameters.\n\t-progressive\tCreate progressive JPEG file.\n\t-arithmetic\tUse arithmetic coding.\n\t-restart N\tEmit a JPEG restart marker every N MCU rows, or every\n\t\t\tN MCU blocks if \"B\" is attached to the number.\n\t-scans file\tUse the scan script given in the specified text file.\nSee the previous discussion of cjpeg for more details about these switches.\nIf you specify none of these switches, you get a plain baseline-JPEG output\nfile.  The quality setting and so forth are determined by the input file.\n\nThe image can be losslessly transformed by giving one of these switches:\n\t-flip horizontal\tMirror image horizontally (left-right).\n\t-flip vertical\t\tMirror image vertically (top-bottom).\n\t-rotate 90\t\tRotate image 90 degrees clockwise.\n\t-rotate 180\t\tRotate image 180 degrees.\n\t-rotate 270\t\tRotate image 270 degrees clockwise (or 90 ccw).\n\t-transpose\t\tTranspose image (across UL-to-LR axis).\n\t-transverse\t\tTransverse transpose (across UR-to-LL axis).\n\nThe transpose transformation has no restrictions regarding image dimensions.\nThe other transformations operate rather oddly if the image dimensions are not\na multiple of the iMCU size (usually 8 or 16 pixels), because they can only\ntransform complete blocks of DCT coefficient data in the desired way.\n\njpegtran's default behavior when transforming an odd-size image is designed\nto preserve exact reversibility and mathematical consistency of the\ntransformation set.  As stated, transpose is able to flip the entire image\narea.  Horizontal mirroring leaves any partial iMCU column at the right edge\nuntouched, but is able to flip all rows of the image.  Similarly, vertical\nmirroring leaves any partial iMCU row at the bottom edge untouched, but is\nable to flip all columns.  The other transforms can be built up as sequences\nof transpose and flip operations; for consistency, their actions on edge\npixels are defined to be the same as the end result of the corresponding\ntranspose-and-flip sequence.\n\nFor practical use, you may prefer to discard any untransformable edge pixels\nrather than having a strange-looking strip along the right and/or bottom edges\nof a transformed image.  To do this, add the -trim switch:\n\t-trim\t\tDrop non-transformable edge blocks.\nObviously, a transformation with -trim is not reversible, so strictly speaking\njpegtran with this switch is not lossless.  Also, the expected mathematical\nequivalences between the transformations no longer hold.  For example,\n\"-rot 270 -trim\" trims only the bottom edge, but \"-rot 90 -trim\" followed by\n\"-rot 180 -trim\" trims both edges.\n\nIf you are only interested in perfect transformation, add the -perfect switch:\n\t-perfect\tFails with an error if the transformation is not\n\t\t\tperfect.\nFor example you may want to do\n  jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg\nto do a perfect rotation if available or an approximated one if not.\n\nWe also offer a lossless-crop option, which discards data outside a given\nimage region but losslessly preserves what is inside.  Like the rotate and\nflip transforms, lossless crop is restricted by the current JPEG format: the\nupper left corner of the selected region must fall on an iMCU boundary.  If\nthis does not hold for the given crop parameters, we silently move the upper\nleft corner up and/or left to make it so, simultaneously increasing the\nregion dimensions to keep the lower right crop corner unchanged.  (Thus, the\noutput image covers at least the requested region, but may cover more.)\nThe adjustment of the region dimensions may be optionally disabled by\nattaching an 'f' character (\"force\") to the width or height number.\n\nThe image can be losslessly cropped by giving the switch:\n\t-crop WxH+X+Y\tCrop to a rectangular subarea of width W, height H\n\t\t\tstarting at point X,Y.\n\nA complementary lossless-wipe option is provided to discard (gray out) data\ninside a given image region while losslessly preserving what is outside:\n\t-wipe WxH+X+Y\tWipe (gray out) a rectangular subarea of\n\t\t\twidth W, height H starting at point X,Y.\n\nOther not-strictly-lossless transformation switches are:\n\n\t-grayscale\tForce grayscale output.\nThis option discards the chrominance channels if the input image is YCbCr\n(ie, a standard color JPEG), resulting in a grayscale JPEG file.  The\nluminance channel is preserved exactly, so this is a better method of reducing\nto grayscale than decompression, conversion, and recompression.  This switch\nis particularly handy for fixing a monochrome picture that was mistakenly\nencoded as a color JPEG.  (In such a case, the space savings from getting rid\nof the near-empty chroma channels won't be large; but the decoding time for\na grayscale JPEG is substantially less than that for a color JPEG.)\n\n\t-scale M/N\tScale the output image by a factor M/N.\nCurrently supported scale factors are M/N with all M from 1 to 16, where N is\nthe source DCT size, which is 8 for baseline JPEG.  If the /N part is omitted,\nthen M specifies the DCT scaled size to be applied on the given input.  For\nbaseline JPEG this is equivalent to M/8 scaling, since the source DCT size\nfor baseline JPEG is 8.  CAUTION: An implementation of the JPEG SmartScale\nextension is required for this feature.  SmartScale enabled JPEG is not yet\nwidely implemented, so many decoders will be unable to view a SmartScale\nextended JPEG file at all.\n\njpegtran also recognizes these switches that control what to do with \"extra\"\nmarkers, such as comment blocks:\n\t-copy none\tCopy no extra markers from source file.\n\t\t\tThis setting suppresses all comments\n\t\t\tand other metadata in the source file.\n\t-copy comments\tCopy only comment markers.\n\t\t\tThis setting copies comments from the source file,\n\t\t\tbut discards any other metadata.\n\t-copy all\tCopy all extra markers.  This setting preserves\n\t\t\tmetadata found in the source file, such as JFIF\n\t\t\tthumbnails, Exif data, and Photoshop settings.\n\t\t\tIn some files these extra markers can be sizable.\n\t\t\tNote that this option will copy thumbnails as-is;\n\t\t\tthey will not be transformed.\nThe default behavior is -copy comments.  (Note: in IJG releases v6 and v6a,\njpegtran always did the equivalent of -copy none.)\n\nAdditional switches recognized by jpegtran are:\n\t-outfile filename\n\t-maxmemory N\n\t-verbose\n\t-debug\nThese work the same as in cjpeg or djpeg.\n\n\nTHE COMMENT UTILITIES\n\nThe JPEG standard allows \"comment\" (COM) blocks to occur within a JPEG file.\nAlthough the standard doesn't actually define what COM blocks are for, they\nare widely used to hold user-supplied text strings.  This lets you add\nannotations, titles, index terms, etc to your JPEG files, and later retrieve\nthem as text.  COM blocks do not interfere with the image stored in the JPEG\nfile.  The maximum size of a COM block is 64K, but you can have as many of\nthem as you like in one JPEG file.\n\nWe provide two utility programs to display COM block contents and add COM\nblocks to a JPEG file.\n\nrdjpgcom searches a JPEG file and prints the contents of any COM blocks on\nstandard output.  The command line syntax is\n\trdjpgcom [-raw] [-verbose] [inputfilename]\nThe switch \"-raw\" (or just \"-r\") causes rdjpgcom to also output non-printable\ncharacters in comments, which are normally escaped for security reasons.\nThe switch \"-verbose\" (or just \"-v\") causes rdjpgcom to also display the JPEG\nimage dimensions.  If you omit the input file name from the command line,\nthe JPEG file is read from standard input.  (This may not work on some\noperating systems, if binary data can't be read from stdin.)\n\nwrjpgcom adds a COM block, containing text you provide, to a JPEG file.\nOrdinarily, the COM block is added after any existing COM blocks, but you\ncan delete the old COM blocks if you wish.  wrjpgcom produces a new JPEG\nfile; it does not modify the input file.  DO NOT try to overwrite the input\nfile by directing wrjpgcom's output back into it; on most systems this will\njust destroy your file.\n\nThe command line syntax for wrjpgcom is similar to cjpeg's.  On Unix-like\nsystems, it is\n\twrjpgcom [switches] [inputfilename]\nThe output file is written to standard output.  The input file comes from\nthe named file, or from standard input if no input file is named.\n\nOn most non-Unix systems, the syntax is\n\twrjpgcom [switches] inputfilename outputfilename\nwhere both input and output file names must be given explicitly.\n\nwrjpgcom understands three switches:\n\t-replace\t\t Delete any existing COM blocks from the file.\n\t-comment \"Comment text\"\t Supply new COM text on command line.\n\t-cfile name\t\t Read text for new COM block from named file.\n(Switch names can be abbreviated.)  If you have only one line of comment text\nto add, you can provide it on the command line with -comment.  The comment\ntext must be surrounded with quotes so that it is treated as a single\nargument.  Longer comments can be read from a text file.\n\nIf you give neither -comment nor -cfile, then wrjpgcom will read the comment\ntext from standard input.  (In this case an input image file name MUST be\nsupplied, so that the source JPEG file comes from somewhere else.)  You can\nenter multiple lines, up to 64KB worth.  Type an end-of-file indicator\n(usually control-D or control-Z) to terminate the comment text entry.\n\nwrjpgcom will not add a COM block if the provided comment string is empty.\nTherefore -replace -comment \"\" can be used to delete all COM blocks from a\nfile.\n\nThese utility programs do not depend on the IJG JPEG library.  In\nparticular, the source code for rdjpgcom is intended as an illustration of\nthe minimum amount of code required to parse a JPEG file header correctly.\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wizard.txt",
    "content": "Advanced usage instructions for the Independent JPEG Group's JPEG software\n==========================================================================\n\nThis file describes cjpeg's \"switches for wizards\".\n\nThe \"wizard\" switches are intended for experimentation with JPEG by persons\nwho are reasonably knowledgeable about the JPEG standard.  If you don't know\nwhat you are doing, DON'T USE THESE SWITCHES.  You'll likely produce files\nwith worse image quality and/or poorer compression than you'd get from the\ndefault settings.  Furthermore, these switches must be used with caution\nwhen making files intended for general use, because not all JPEG decoders\nwill support unusual JPEG parameter settings.\n\n\nQuantization Table Adjustment\n-----------------------------\n\nOrdinarily, cjpeg starts with a default set of tables (the same ones given\nas examples in the JPEG standard) and scales them up or down according to\nthe -quality setting.  The details of the scaling algorithm can be found in\njcparam.c.  At very low quality settings, some quantization table entries\ncan get scaled up to values exceeding 255.  Although 2-byte quantization\nvalues are supported by the IJG software, this feature is not in baseline\nJPEG and is not supported by all implementations.  If you need to ensure\nwide compatibility of low-quality files, you can constrain the scaled\nquantization values to no more than 255 by giving the -baseline switch.\nNote that use of -baseline will result in poorer quality for the same file\nsize, since more bits than necessary are expended on higher AC coefficients.\n\nYou can substitute a different set of quantization values by using the\n-qtables switch:\n\n\t-qtables file\tUse the quantization tables given in the named file.\n\nThe specified file should be a text file containing decimal quantization\nvalues.  The file should contain one to four tables, each of 64 elements.\nThe tables are implicitly numbered 0,1,etc. in order of appearance.  Table\nentries appear in normal array order (NOT in the zigzag order in which they\nwill be stored in the JPEG file).\n\nQuantization table files are free format, in that arbitrary whitespace can\nappear between numbers.  Also, comments can be included: a comment starts\nwith '#' and extends to the end of the line.  Here is an example file that\nduplicates the default quantization tables:\n\n\t# Quantization tables given in JPEG spec, section K.1\n\n\t# This is table 0 (the luminance table):\n\t  16  11  10  16  24  40  51  61\n\t  12  12  14  19  26  58  60  55\n\t  14  13  16  24  40  57  69  56\n\t  14  17  22  29  51  87  80  62\n\t  18  22  37  56  68 109 103  77\n\t  24  35  55  64  81 104 113  92\n\t  49  64  78  87 103 121 120 101\n\t  72  92  95  98 112 100 103  99\n\n\t# This is table 1 (the chrominance table):\n\t  17  18  24  47  99  99  99  99\n\t  18  21  26  66  99  99  99  99\n\t  24  26  56  99  99  99  99  99\n\t  47  66  99  99  99  99  99  99\n\t  99  99  99  99  99  99  99  99\n\t  99  99  99  99  99  99  99  99\n\t  99  99  99  99  99  99  99  99\n\t  99  99  99  99  99  99  99  99\n\nIf the -qtables switch is used without -quality, then the specified tables\nare used exactly as-is.  If both -qtables and -quality are used, then the\ntables taken from the file are scaled in the same fashion that the default\ntables would be scaled for that quality setting.  If -baseline appears, then\nthe quantization values are constrained to the range 1-255.\n\nBy default, cjpeg will use quantization table 0 for luminance components and\ntable 1 for chrominance components.  To override this choice, use the -qslots\nswitch:\n\n\t-qslots N[,...]\t\tSelect which quantization table to use for\n\t\t\t\teach color component.\n\nThe -qslots switch specifies a quantization table number for each color\ncomponent, in the order in which the components appear in the JPEG SOF marker.\nFor example, to create a separate table for each of Y,Cb,Cr, you could\nprovide a -qtables file that defines three quantization tables and say\n\"-qslots 0,1,2\".  If -qslots gives fewer table numbers than there are color\ncomponents, then the last table number is repeated as necessary.\n\n\nSampling Factor Adjustment\n--------------------------\n\nBy default, cjpeg uses 2:1 horizontal and vertical downsampling when\ncompressing YCbCr data, and no downsampling for all other color spaces.\nYou can override this default with the -sample switch:\n\n\t-sample HxV[,...]\tSet JPEG sampling factors for each color\n\t\t\t\tcomponent.\n\nThe -sample switch specifies the JPEG sampling factors for each color\ncomponent, in the order in which they appear in the JPEG SOF marker.\nIf you specify fewer HxV pairs than there are components, the remaining\ncomponents are set to 1x1 sampling.  For example, the default YCbCr setting\nis equivalent to \"-sample 2x2,1x1,1x1\", which can be abbreviated to\n\"-sample 2x2\".\n\nThere are still some JPEG decoders in existence that support only 2x1\nsampling (also called 4:2:2 sampling).  Compatibility with such decoders can\nbe achieved by specifying \"-sample 2x1\".  This is not recommended unless\nreally necessary, since it increases file size and encoding/decoding time\nwith very little quality gain.\n\n\nMultiple Scan / Progression Control\n-----------------------------------\n\nBy default, cjpeg emits a single-scan sequential JPEG file.  The\n-progressive switch generates a progressive JPEG file using a default series\nof progression parameters.  You can create multiple-scan sequential JPEG\nfiles or progressive JPEG files with custom progression parameters by using\nthe -scans switch:\n\n\t-scans file\tUse the scan sequence given in the named file.\n\nThe specified file should be a text file containing a \"scan script\".\nThe script specifies the contents and ordering of the scans to be emitted.\nEach entry in the script defines one scan.  A scan definition specifies\nthe components to be included in the scan, and for progressive JPEG it also\nspecifies the progression parameters Ss,Se,Ah,Al for the scan.  Scan\ndefinitions are separated by semicolons (';').  A semicolon after the last\nscan definition is optional.\n\nEach scan definition contains one to four component indexes, optionally\nfollowed by a colon (':') and the four progressive-JPEG parameters.  The\ncomponent indexes denote which color component(s) are to be transmitted in\nthe scan.  Components are numbered in the order in which they appear in the\nJPEG SOF marker, with the first component being numbered 0.  (Note that these\nindexes are not the \"component ID\" codes assigned to the components, just\npositional indexes.)\n\nThe progression parameters for each scan are:\n\tSs\tZigzag index of first coefficient included in scan\n\tSe\tZigzag index of last coefficient included in scan\n\tAh\tZero for first scan of a coefficient, else Al of prior scan\n\tAl\tSuccessive approximation low bit position for scan\nIf the progression parameters are omitted, the values 0,63,0,0 are used,\nproducing a sequential JPEG file.  cjpeg automatically determines whether\nthe script represents a progressive or sequential file, by observing whether\nSs and Se values other than 0 and 63 appear.  (The -progressive switch is\nnot needed to specify this; in fact, it is ignored when -scans appears.)\nThe scan script must meet the JPEG restrictions on progression sequences.\n(cjpeg checks that the spec's requirements are obeyed.)\n\nScan script files are free format, in that arbitrary whitespace can appear\nbetween numbers and around punctuation.  Also, comments can be included: a\ncomment starts with '#' and extends to the end of the line.  For additional\nlegibility, commas or dashes can be placed between values.  (Actually, any\nsingle punctuation character other than ':' or ';' can be inserted.)  For\nexample, the following two scan definitions are equivalent:\n\t0 1 2: 0 63 0 0;\n\t0,1,2 : 0-63, 0,0 ;\n\nHere is an example of a scan script that generates a partially interleaved\nsequential JPEG file:\n\n\t0;\t\t\t# Y only in first scan\n\t1 2;\t\t\t# Cb and Cr in second scan\n\nHere is an example of a progressive scan script using only spectral selection\n(no successive approximation):\n\n\t# Interleaved DC scan for Y,Cb,Cr:\n\t0,1,2: 0-0,   0, 0 ;\n\t# AC scans:\n\t0:     1-2,   0, 0 ;\t# First two Y AC coefficients\n\t0:     3-5,   0, 0 ;\t# Three more\n\t1:     1-63,  0, 0 ;\t# All AC coefficients for Cb\n\t2:     1-63,  0, 0 ;\t# All AC coefficients for Cr\n\t0:     6-9,   0, 0 ;\t# More Y coefficients\n\t0:     10-63, 0, 0 ;\t# Remaining Y coefficients\n\nHere is an example of a successive-approximation script.  This is equivalent\nto the default script used by \"cjpeg -progressive\" for YCbCr images:\n\n\t# Initial DC scan for Y,Cb,Cr (lowest bit not sent)\n\t0,1,2: 0-0,   0, 1 ;\n\t# First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits:\n\t0:     1-5,   0, 2 ;\n\t# Send all Cr,Cb AC coefficients, minus lowest bit:\n\t# (chroma data is usually too small to be worth subdividing further;\n\t#  but note we send Cr first since eye is least sensitive to Cb)\n\t2:     1-63,  0, 1 ;\n\t1:     1-63,  0, 1 ;\n\t# Send remaining Y AC coefficients, minus 2 lowest bits:\n\t0:     6-63,  0, 2 ;\n\t# Send next-to-lowest bit of all Y AC coefficients:\n\t0:     1-63,  2, 1 ;\n\t# At this point we've sent all but the lowest bit of all coefficients.\n\t# Send lowest bit of DC coefficients\n\t0,1,2: 0-0,   1, 0 ;\n\t# Send lowest bit of AC coefficients\n\t2:     1-63,  1, 0 ;\n\t1:     1-63,  1, 0 ;\n\t# Y AC lowest bit scan is last; it's usually the largest scan\n\t0:     1-63,  1, 0 ;\n\nIt may be worth pointing out that this script is tuned for quality settings\nof around 50 to 75.  For lower quality settings, you'd probably want to use\na script with fewer stages of successive approximation (otherwise the\ninitial scans will be really bad).  For higher quality settings, you might\nwant to use more stages of successive approximation (so that the initial\nscans are not too large).\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrbmp.c",
    "content": "/*\n * wrbmp.c\n *\n * Copyright (C) 1994-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write output images in Microsoft \"BMP\"\n * format (MS Windows 3.x and OS/2 1.x flavors).\n * Either 8-bit colormapped or 24-bit full-color format can be written.\n * No compression is supported.\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume output to\n * an ordinary stdio stream.\n *\n * This code contributed by James Arthur Boucher.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef BMP_SUPPORTED\n\n\n/*\n * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.\n * This is not yet implemented.\n */\n\n#if BITS_IN_JSAMPLE != 8\n  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */\n#endif\n\n/*\n * Since BMP stores scanlines bottom-to-top, we have to invert the image\n * from JPEG's top-to-bottom order.  To do this, we save the outgoing data\n * in a virtual array during put_pixel_row calls, then actually emit the\n * BMP file during finish_output.  The virtual array contains one JSAMPLE per\n * pixel if the output is grayscale or colormapped, three if it is full color.\n */\n\n/* Private version of data destination object */\n\ntypedef struct {\n  struct djpeg_dest_struct pub;\t/* public fields */\n\n  boolean is_os2;\t\t/* saves the OS2 format request flag */\n\n  jvirt_sarray_ptr whole_image;\t/* needed to reverse row order */\n  JDIMENSION data_width;\t/* JSAMPLEs per row */\n  JDIMENSION row_width;\t\t/* physical width of one row in the BMP file */\n  int pad_bytes;\t\t/* number of padding bytes needed per row */\n  JDIMENSION cur_output_row;\t/* next row# to write to virtual array */\n} bmp_dest_struct;\n\ntypedef bmp_dest_struct * bmp_dest_ptr;\n\n\n/* Forward declarations */\nLOCAL(void) write_colormap\n\tJPP((j_decompress_ptr cinfo, bmp_dest_ptr dest,\n\t     int map_colors, int map_entry_size));\n\n\n/*\n * Write some pixel data.\n * In this module rows_supplied will always be 1.\n */\n\nMETHODDEF(void)\nput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\tJDIMENSION rows_supplied)\n/* This version is for writing 24-bit pixels */\n{\n  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;\n  JSAMPARRAY image_ptr;\n  register JSAMPROW inptr, outptr;\n  register JDIMENSION col;\n  int pad;\n\n  /* Access next row in virtual array */\n  image_ptr = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, dest->whole_image,\n     dest->cur_output_row, (JDIMENSION) 1, TRUE);\n  dest->cur_output_row++;\n\n  /* Transfer data.  Note destination values must be in BGR order\n   * (even though Microsoft's own documents say the opposite).\n   */\n  inptr = dest->pub.buffer[0];\n  outptr = image_ptr[0];\n  for (col = cinfo->output_width; col > 0; col--) {\n    outptr[2] = *inptr++;\t/* can omit GETJSAMPLE() safely */\n    outptr[1] = *inptr++;\n    outptr[0] = *inptr++;\n    outptr += 3;\n  }\n\n  /* Zero out the pad bytes. */\n  pad = dest->pad_bytes;\n  while (--pad >= 0)\n    *outptr++ = 0;\n}\n\nMETHODDEF(void)\nput_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t       JDIMENSION rows_supplied)\n/* This version is for grayscale OR quantized color output */\n{\n  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;\n  JSAMPARRAY image_ptr;\n  register JSAMPROW inptr, outptr;\n  register JDIMENSION col;\n  int pad;\n\n  /* Access next row in virtual array */\n  image_ptr = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, dest->whole_image,\n     dest->cur_output_row, (JDIMENSION) 1, TRUE);\n  dest->cur_output_row++;\n\n  /* Transfer data. */\n  inptr = dest->pub.buffer[0];\n  outptr = image_ptr[0];\n  for (col = cinfo->output_width; col > 0; col--) {\n    *outptr++ = *inptr++;\t/* can omit GETJSAMPLE() safely */\n  }\n\n  /* Zero out the pad bytes. */\n  pad = dest->pad_bytes;\n  while (--pad >= 0)\n    *outptr++ = 0;\n}\n\n\n/*\n * Startup: normally writes the file header.\n * In this module we may as well postpone everything until finish_output.\n */\n\nMETHODDEF(void)\nstart_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  /* no work here */\n}\n\n\n/*\n * Finish up at the end of the file.\n *\n * Here is where we really output the BMP file.\n *\n * First, routines to write the Windows and OS/2 variants of the file header.\n */\n\nLOCAL(void)\nwrite_bmp_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)\n/* Write a Windows-style BMP file header, including colormap if needed */\n{\n  char bmpfileheader[14];\n  char bmpinfoheader[40];\n#define PUT_2B(array,offset,value)  \\\n\t(array[offset] = (char) ((value) & 0xFF), \\\n\t array[offset+1] = (char) (((value) >> 8) & 0xFF))\n#define PUT_4B(array,offset,value)  \\\n\t(array[offset] = (char) ((value) & 0xFF), \\\n\t array[offset+1] = (char) (((value) >> 8) & 0xFF), \\\n\t array[offset+2] = (char) (((value) >> 16) & 0xFF), \\\n\t array[offset+3] = (char) (((value) >> 24) & 0xFF))\n  INT32 headersize, bfSize;\n  int bits_per_pixel, cmap_entries;\n\n  /* Compute colormap size and total file size */\n  if (cinfo->out_color_space == JCS_RGB) {\n    if (cinfo->quantize_colors) {\n      /* Colormapped RGB */\n      bits_per_pixel = 8;\n      cmap_entries = 256;\n    } else {\n      /* Unquantized, full color RGB */\n      bits_per_pixel = 24;\n      cmap_entries = 0;\n    }\n  } else {\n    /* Grayscale output.  We need to fake a 256-entry colormap. */\n    bits_per_pixel = 8;\n    cmap_entries = 256;\n  }\n  /* File size */\n  headersize = 14 + 40 + cmap_entries * 4; /* Header and colormap */\n  bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;\n  \n  /* Set unused fields of header to 0 */\n  MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));\n  MEMZERO(bmpinfoheader, SIZEOF(bmpinfoheader));\n\n  /* Fill the file header */\n  bmpfileheader[0] = 0x42;\t/* first 2 bytes are ASCII 'B', 'M' */\n  bmpfileheader[1] = 0x4D;\n  PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */\n  /* we leave bfReserved1 & bfReserved2 = 0 */\n  PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */\n\n  /* Fill the info header (Microsoft calls this a BITMAPINFOHEADER) */\n  PUT_2B(bmpinfoheader, 0, 40);\t/* biSize */\n  PUT_4B(bmpinfoheader, 4, cinfo->output_width); /* biWidth */\n  PUT_4B(bmpinfoheader, 8, cinfo->output_height); /* biHeight */\n  PUT_2B(bmpinfoheader, 12, 1);\t/* biPlanes - must be 1 */\n  PUT_2B(bmpinfoheader, 14, bits_per_pixel); /* biBitCount */\n  /* we leave biCompression = 0, for none */\n  /* we leave biSizeImage = 0; this is correct for uncompressed data */\n  if (cinfo->density_unit == 2) { /* if have density in dots/cm, then */\n    PUT_4B(bmpinfoheader, 24, (INT32) (cinfo->X_density*100)); /* XPels/M */\n    PUT_4B(bmpinfoheader, 28, (INT32) (cinfo->Y_density*100)); /* XPels/M */\n  }\n  PUT_2B(bmpinfoheader, 32, cmap_entries); /* biClrUsed */\n  /* we leave biClrImportant = 0 */\n\n  if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n  if (JFWRITE(dest->pub.output_file, bmpinfoheader, 40) != (size_t) 40)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n\n  if (cmap_entries > 0)\n    write_colormap(cinfo, dest, cmap_entries, 4);\n}\n\n\nLOCAL(void)\nwrite_os2_header (j_decompress_ptr cinfo, bmp_dest_ptr dest)\n/* Write an OS2-style BMP file header, including colormap if needed */\n{\n  char bmpfileheader[14];\n  char bmpcoreheader[12];\n  INT32 headersize, bfSize;\n  int bits_per_pixel, cmap_entries;\n\n  /* Compute colormap size and total file size */\n  if (cinfo->out_color_space == JCS_RGB) {\n    if (cinfo->quantize_colors) {\n      /* Colormapped RGB */\n      bits_per_pixel = 8;\n      cmap_entries = 256;\n    } else {\n      /* Unquantized, full color RGB */\n      bits_per_pixel = 24;\n      cmap_entries = 0;\n    }\n  } else {\n    /* Grayscale output.  We need to fake a 256-entry colormap. */\n    bits_per_pixel = 8;\n    cmap_entries = 256;\n  }\n  /* File size */\n  headersize = 14 + 12 + cmap_entries * 3; /* Header and colormap */\n  bfSize = headersize + (INT32) dest->row_width * (INT32) cinfo->output_height;\n  \n  /* Set unused fields of header to 0 */\n  MEMZERO(bmpfileheader, SIZEOF(bmpfileheader));\n  MEMZERO(bmpcoreheader, SIZEOF(bmpcoreheader));\n\n  /* Fill the file header */\n  bmpfileheader[0] = 0x42;\t/* first 2 bytes are ASCII 'B', 'M' */\n  bmpfileheader[1] = 0x4D;\n  PUT_4B(bmpfileheader, 2, bfSize); /* bfSize */\n  /* we leave bfReserved1 & bfReserved2 = 0 */\n  PUT_4B(bmpfileheader, 10, headersize); /* bfOffBits */\n\n  /* Fill the info header (Microsoft calls this a BITMAPCOREHEADER) */\n  PUT_2B(bmpcoreheader, 0, 12);\t/* bcSize */\n  PUT_2B(bmpcoreheader, 4, cinfo->output_width); /* bcWidth */\n  PUT_2B(bmpcoreheader, 6, cinfo->output_height); /* bcHeight */\n  PUT_2B(bmpcoreheader, 8, 1);\t/* bcPlanes - must be 1 */\n  PUT_2B(bmpcoreheader, 10, bits_per_pixel); /* bcBitCount */\n\n  if (JFWRITE(dest->pub.output_file, bmpfileheader, 14) != (size_t) 14)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n  if (JFWRITE(dest->pub.output_file, bmpcoreheader, 12) != (size_t) 12)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n\n  if (cmap_entries > 0)\n    write_colormap(cinfo, dest, cmap_entries, 3);\n}\n\n\n/*\n * Write the colormap.\n * Windows uses BGR0 map entries; OS/2 uses BGR entries.\n */\n\nLOCAL(void)\nwrite_colormap (j_decompress_ptr cinfo, bmp_dest_ptr dest,\n\t\tint map_colors, int map_entry_size)\n{\n  JSAMPARRAY colormap = cinfo->colormap;\n  int num_colors = cinfo->actual_number_of_colors;\n  FILE * outfile = dest->pub.output_file;\n  int i;\n\n  if (colormap != NULL) {\n    if (cinfo->out_color_components == 3) {\n      /* Normal case with RGB colormap */\n      for (i = 0; i < num_colors; i++) {\n\tputc(GETJSAMPLE(colormap[2][i]), outfile);\n\tputc(GETJSAMPLE(colormap[1][i]), outfile);\n\tputc(GETJSAMPLE(colormap[0][i]), outfile);\n\tif (map_entry_size == 4)\n\t  putc(0, outfile);\n      }\n    } else {\n      /* Grayscale colormap (only happens with grayscale quantization) */\n      for (i = 0; i < num_colors; i++) {\n\tputc(GETJSAMPLE(colormap[0][i]), outfile);\n\tputc(GETJSAMPLE(colormap[0][i]), outfile);\n\tputc(GETJSAMPLE(colormap[0][i]), outfile);\n\tif (map_entry_size == 4)\n\t  putc(0, outfile);\n      }\n    }\n  } else {\n    /* If no colormap, must be grayscale data.  Generate a linear \"map\". */\n    for (i = 0; i < 256; i++) {\n      putc(i, outfile);\n      putc(i, outfile);\n      putc(i, outfile);\n      if (map_entry_size == 4)\n\tputc(0, outfile);\n    }\n  }\n  /* Pad colormap with zeros to ensure specified number of colormap entries */ \n  if (i > map_colors)\n    ERREXIT1(cinfo, JERR_TOO_MANY_COLORS, i);\n  for (; i < map_colors; i++) {\n    putc(0, outfile);\n    putc(0, outfile);\n    putc(0, outfile);\n    if (map_entry_size == 4)\n      putc(0, outfile);\n  }\n}\n\n\nMETHODDEF(void)\nfinish_output_bmp (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  bmp_dest_ptr dest = (bmp_dest_ptr) dinfo;\n  register FILE * outfile = dest->pub.output_file;\n  JSAMPARRAY image_ptr;\n  register JSAMPROW data_ptr;\n  JDIMENSION row;\n  register JDIMENSION col;\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n\n  /* Write the header and colormap */\n  if (dest->is_os2)\n    write_os2_header(cinfo, dest);\n  else\n    write_bmp_header(cinfo, dest);\n\n  /* Write the file body from our virtual array */\n  for (row = cinfo->output_height; row > 0; row--) {\n    if (progress != NULL) {\n      progress->pub.pass_counter = (long) (cinfo->output_height - row);\n      progress->pub.pass_limit = (long) cinfo->output_height;\n      (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n    }\n    image_ptr = (*cinfo->mem->access_virt_sarray)\n      ((j_common_ptr) cinfo, dest->whole_image, row-1, (JDIMENSION) 1, FALSE);\n    data_ptr = image_ptr[0];\n    for (col = dest->row_width; col > 0; col--) {\n      putc(GETJSAMPLE(*data_ptr), outfile);\n      data_ptr++;\n    }\n  }\n  if (progress != NULL)\n    progress->completed_extra_passes++;\n\n  /* Make sure we wrote the output file OK */\n  fflush(outfile);\n  if (ferror(outfile))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * The module selection routine for BMP format output.\n */\n\nGLOBAL(djpeg_dest_ptr)\njinit_write_bmp (j_decompress_ptr cinfo, boolean is_os2)\n{\n  bmp_dest_ptr dest;\n  JDIMENSION row_width;\n\n  /* Create module interface object, fill in method pointers */\n  dest = (bmp_dest_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(bmp_dest_struct));\n  dest->pub.start_output = start_output_bmp;\n  dest->pub.finish_output = finish_output_bmp;\n  dest->is_os2 = is_os2;\n\n  if (cinfo->out_color_space == JCS_GRAYSCALE) {\n    dest->pub.put_pixel_rows = put_gray_rows;\n  } else if (cinfo->out_color_space == JCS_RGB) {\n    if (cinfo->quantize_colors)\n      dest->pub.put_pixel_rows = put_gray_rows;\n    else\n      dest->pub.put_pixel_rows = put_pixel_rows;\n  } else {\n    ERREXIT(cinfo, JERR_BMP_COLORSPACE);\n  }\n\n  /* Calculate output image dimensions so we can allocate space */\n  jpeg_calc_output_dimensions(cinfo);\n\n  /* Determine width of rows in the BMP file (padded to 4-byte boundary). */\n  row_width = cinfo->output_width * cinfo->output_components;\n  dest->data_width = row_width;\n  while ((row_width & 3) != 0) row_width++;\n  dest->row_width = row_width;\n  dest->pad_bytes = (int) (row_width - dest->data_width);\n\n  /* Allocate space for inversion array, prepare for write pass */\n  dest->whole_image = (*cinfo->mem->request_virt_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n     row_width, cinfo->output_height, (JDIMENSION) 1);\n  dest->cur_output_row = 0;\n  if (cinfo->progress != NULL) {\n    cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n    progress->total_extra_passes++; /* count file input as separate pass */\n  }\n\n  /* Create decompressor output buffer. */\n  dest->pub.buffer = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, row_width, (JDIMENSION) 1);\n  dest->pub.buffer_height = 1;\n\n  return (djpeg_dest_ptr) dest;\n}\n\n#endif /* BMP_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrgif.c",
    "content": "/*\n * wrgif.c\n *\n * Copyright (C) 1991-1997, Thomas G. Lane.\n * Modified 2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write output images in GIF format.\n *\n **************************************************************************\n * NOTE: to avoid entanglements with Unisys' patent on LZW compression,   *\n * this code has been modified to output \"uncompressed GIF\" files.        *\n * There is no trace of the LZW algorithm in this file.                   *\n **************************************************************************\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume output to\n * an ordinary stdio stream.\n */\n\n/*\n * This code is loosely based on ppmtogif from the PBMPLUS distribution\n * of Feb. 1991.  That file contains the following copyright notice:\n *    Based on GIFENCODE by David Rowley <mgardi@watdscu.waterloo.edu>.\n *    Lempel-Ziv compression based on \"compress\" by Spencer W. Thomas et al.\n *    Copyright (C) 1989 by Jef Poskanzer.\n *    Permission to use, copy, modify, and distribute this software and its\n *    documentation for any purpose and without fee is hereby granted, provided\n *    that the above copyright notice appear in all copies and that both that\n *    copyright notice and this permission notice appear in supporting\n *    documentation.  This software is provided \"as is\" without express or\n *    implied warranty.\n *\n * We are also required to state that\n *    \"The Graphics Interchange Format(c) is the Copyright property of\n *    CompuServe Incorporated. GIF(sm) is a Service Mark property of\n *    CompuServe Incorporated.\"\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef GIF_SUPPORTED\n\n\n/* Private version of data destination object */\n\ntypedef struct {\n  struct djpeg_dest_struct pub;\t/* public fields */\n\n  j_decompress_ptr cinfo;\t/* back link saves passing separate parm */\n\n  /* State for packing variable-width codes into a bitstream */\n  int n_bits;\t\t\t/* current number of bits/code */\n  int maxcode;\t\t\t/* maximum code, given n_bits */\n  INT32 cur_accum;\t\t/* holds bits not yet output */\n  int cur_bits;\t\t\t/* # of bits in cur_accum */\n\n  /* State for GIF code assignment */\n  int ClearCode;\t\t/* clear code (doesn't change) */\n  int EOFCode;\t\t\t/* EOF code (ditto) */\n  int code_counter;\t\t/* counts output symbols */\n\n  /* GIF data packet construction buffer */\n  int bytesinpkt;\t\t/* # of bytes in current packet */\n  char packetbuf[256];\t\t/* workspace for accumulating packet */\n\n} gif_dest_struct;\n\ntypedef gif_dest_struct * gif_dest_ptr;\n\n/* Largest value that will fit in N bits */\n#define MAXCODE(n_bits)\t((1 << (n_bits)) - 1)\n\n\n/*\n * Routines to package finished data bytes into GIF data blocks.\n * A data block consists of a count byte (1..255) and that many data bytes.\n */\n\nLOCAL(void)\nflush_packet (gif_dest_ptr dinfo)\n/* flush any accumulated data */\n{\n  if (dinfo->bytesinpkt > 0) {\t/* never write zero-length packet */\n    dinfo->packetbuf[0] = (char) dinfo->bytesinpkt++;\n    if (JFWRITE(dinfo->pub.output_file, dinfo->packetbuf, dinfo->bytesinpkt)\n\t!= (size_t) dinfo->bytesinpkt)\n      ERREXIT(dinfo->cinfo, JERR_FILE_WRITE);\n    dinfo->bytesinpkt = 0;\n  }\n}\n\n\n/* Add a character to current packet; flush to disk if necessary */\n#define CHAR_OUT(dinfo,c)  \\\n\t{ (dinfo)->packetbuf[++(dinfo)->bytesinpkt] = (char) (c);  \\\n\t    if ((dinfo)->bytesinpkt >= 255)  \\\n\t      flush_packet(dinfo);  \\\n\t}\n\n\n/* Routine to convert variable-width codes into a byte stream */\n\nLOCAL(void)\noutput (gif_dest_ptr dinfo, int code)\n/* Emit a code of n_bits bits */\n/* Uses cur_accum and cur_bits to reblock into 8-bit bytes */\n{\n  dinfo->cur_accum |= ((INT32) code) << dinfo->cur_bits;\n  dinfo->cur_bits += dinfo->n_bits;\n\n  while (dinfo->cur_bits >= 8) {\n    CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);\n    dinfo->cur_accum >>= 8;\n    dinfo->cur_bits -= 8;\n  }\n}\n\n\n/* The pseudo-compression algorithm.\n *\n * In this module we simply output each pixel value as a separate symbol;\n * thus, no compression occurs.  In fact, there is expansion of one bit per\n * pixel, because we use a symbol width one bit wider than the pixel width.\n *\n * GIF ordinarily uses variable-width symbols, and the decoder will expect\n * to ratchet up the symbol width after a fixed number of symbols.\n * To simplify the logic and keep the expansion penalty down, we emit a\n * GIF Clear code to reset the decoder just before the width would ratchet up.\n * Thus, all the symbols in the output file will have the same bit width.\n * Note that emitting the Clear codes at the right times is a mere matter of\n * counting output symbols and is in no way dependent on the LZW patent.\n *\n * With a small basic pixel width (low color count), Clear codes will be\n * needed very frequently, causing the file to expand even more.  So this\n * simplistic approach wouldn't work too well on bilevel images, for example.\n * But for output of JPEG conversions the pixel width will usually be 8 bits\n * (129 to 256 colors), so the overhead added by Clear symbols is only about\n * one symbol in every 256.\n */\n\nLOCAL(void)\ncompress_init (gif_dest_ptr dinfo, int i_bits)\n/* Initialize pseudo-compressor */\n{\n  /* init all the state variables */\n  dinfo->n_bits = i_bits;\n  dinfo->maxcode = MAXCODE(dinfo->n_bits);\n  dinfo->ClearCode = (1 << (i_bits - 1));\n  dinfo->EOFCode = dinfo->ClearCode + 1;\n  dinfo->code_counter = dinfo->ClearCode + 2;\n  /* init output buffering vars */\n  dinfo->bytesinpkt = 0;\n  dinfo->cur_accum = 0;\n  dinfo->cur_bits = 0;\n  /* GIF specifies an initial Clear code */\n  output(dinfo, dinfo->ClearCode);\n}\n\n\nLOCAL(void)\ncompress_pixel (gif_dest_ptr dinfo, int c)\n/* Accept and \"compress\" one pixel value.\n * The given value must be less than n_bits wide.\n */\n{\n  /* Output the given pixel value as a symbol. */\n  output(dinfo, c);\n  /* Issue Clear codes often enough to keep the reader from ratcheting up\n   * its symbol size.\n   */\n  if (dinfo->code_counter < dinfo->maxcode) {\n    dinfo->code_counter++;\n  } else {\n    output(dinfo, dinfo->ClearCode);\n    dinfo->code_counter = dinfo->ClearCode + 2;\t/* reset the counter */\n  }\n}\n\n\nLOCAL(void)\ncompress_term (gif_dest_ptr dinfo)\n/* Clean up at end */\n{\n  /* Send an EOF code */\n  output(dinfo, dinfo->EOFCode);\n  /* Flush the bit-packing buffer */\n  if (dinfo->cur_bits > 0) {\n    CHAR_OUT(dinfo, dinfo->cur_accum & 0xFF);\n  }\n  /* Flush the packet buffer */\n  flush_packet(dinfo);\n}\n\n\n/* GIF header construction */\n\n\nLOCAL(void)\nput_word (gif_dest_ptr dinfo, unsigned int w)\n/* Emit a 16-bit word, LSB first */\n{\n  putc(w & 0xFF, dinfo->pub.output_file);\n  putc((w >> 8) & 0xFF, dinfo->pub.output_file);\n}\n\n\nLOCAL(void)\nput_3bytes (gif_dest_ptr dinfo, int val)\n/* Emit 3 copies of same byte value --- handy subr for colormap construction */\n{\n  putc(val, dinfo->pub.output_file);\n  putc(val, dinfo->pub.output_file);\n  putc(val, dinfo->pub.output_file);\n}\n\n\nLOCAL(void)\nemit_header (gif_dest_ptr dinfo, int num_colors, JSAMPARRAY colormap)\n/* Output the GIF file header, including color map */\n/* If colormap==NULL, synthesize a grayscale colormap */\n{\n  int BitsPerPixel, ColorMapSize, InitCodeSize, FlagByte;\n  int cshift = dinfo->cinfo->data_precision - 8;\n  int i;\n\n  if (num_colors > 256)\n    ERREXIT1(dinfo->cinfo, JERR_TOO_MANY_COLORS, num_colors);\n  /* Compute bits/pixel and related values */\n  BitsPerPixel = 1;\n  while (num_colors > (1 << BitsPerPixel))\n    BitsPerPixel++;\n  ColorMapSize = 1 << BitsPerPixel;\n  if (BitsPerPixel <= 1)\n    InitCodeSize = 2;\n  else\n    InitCodeSize = BitsPerPixel;\n  /*\n   * Write the GIF header.\n   * Note that we generate a plain GIF87 header for maximum compatibility.\n   */\n  putc('G', dinfo->pub.output_file);\n  putc('I', dinfo->pub.output_file);\n  putc('F', dinfo->pub.output_file);\n  putc('8', dinfo->pub.output_file);\n  putc('7', dinfo->pub.output_file);\n  putc('a', dinfo->pub.output_file);\n  /* Write the Logical Screen Descriptor */\n  put_word(dinfo, (unsigned int) dinfo->cinfo->output_width);\n  put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);\n  FlagByte = 0x80;\t\t/* Yes, there is a global color table */\n  FlagByte |= (BitsPerPixel-1) << 4; /* color resolution */\n  FlagByte |= (BitsPerPixel-1);\t/* size of global color table */\n  putc(FlagByte, dinfo->pub.output_file);\n  putc(0, dinfo->pub.output_file); /* Background color index */\n  putc(0, dinfo->pub.output_file); /* Reserved (aspect ratio in GIF89) */\n  /* Write the Global Color Map */\n  /* If the color map is more than 8 bits precision, */\n  /* we reduce it to 8 bits by shifting */\n  for (i=0; i < ColorMapSize; i++) {\n    if (i < num_colors) {\n      if (colormap != NULL) {\n\tif (dinfo->cinfo->out_color_space == JCS_RGB) {\n\t  /* Normal case: RGB color map */\n\t  putc(GETJSAMPLE(colormap[0][i]) >> cshift, dinfo->pub.output_file);\n\t  putc(GETJSAMPLE(colormap[1][i]) >> cshift, dinfo->pub.output_file);\n\t  putc(GETJSAMPLE(colormap[2][i]) >> cshift, dinfo->pub.output_file);\n\t} else {\n\t  /* Grayscale \"color map\": possible if quantizing grayscale image */\n\t  put_3bytes(dinfo, GETJSAMPLE(colormap[0][i]) >> cshift);\n\t}\n      } else {\n\t/* Create a grayscale map of num_colors values, range 0..255 */\n\tput_3bytes(dinfo, (i * 255 + (num_colors-1)/2) / (num_colors-1));\n      }\n    } else {\n      /* fill out the map to a power of 2 */\n      put_3bytes(dinfo, 0);\n    }\n  }\n  /* Write image separator and Image Descriptor */\n  putc(',', dinfo->pub.output_file); /* separator */\n  put_word(dinfo, 0);\t\t/* left/top offset */\n  put_word(dinfo, 0);\n  put_word(dinfo, (unsigned int) dinfo->cinfo->output_width); /* image size */\n  put_word(dinfo, (unsigned int) dinfo->cinfo->output_height);\n  /* flag byte: not interlaced, no local color map */\n  putc(0x00, dinfo->pub.output_file);\n  /* Write Initial Code Size byte */\n  putc(InitCodeSize, dinfo->pub.output_file);\n\n  /* Initialize for \"compression\" of image data */\n  compress_init(dinfo, InitCodeSize+1);\n}\n\n\n/*\n * Startup: write the file header.\n */\n\nMETHODDEF(void)\nstart_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  gif_dest_ptr dest = (gif_dest_ptr) dinfo;\n\n  if (cinfo->quantize_colors)\n    emit_header(dest, cinfo->actual_number_of_colors, cinfo->colormap);\n  else\n    emit_header(dest, 256, (JSAMPARRAY) NULL);\n}\n\n\n/*\n * Write some pixel data.\n * In this module rows_supplied will always be 1.\n */\n\nMETHODDEF(void)\nput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\tJDIMENSION rows_supplied)\n{\n  gif_dest_ptr dest = (gif_dest_ptr) dinfo;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n\n  ptr = dest->pub.buffer[0];\n  for (col = cinfo->output_width; col > 0; col--) {\n    compress_pixel(dest, GETJSAMPLE(*ptr++));\n  }\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_output_gif (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  gif_dest_ptr dest = (gif_dest_ptr) dinfo;\n\n  /* Flush \"compression\" mechanism */\n  compress_term(dest);\n  /* Write a zero-length data block to end the series */\n  putc(0, dest->pub.output_file);\n  /* Write the GIF terminator mark */\n  putc(';', dest->pub.output_file);\n  /* Make sure we wrote the output file OK */\n  fflush(dest->pub.output_file);\n  if (ferror(dest->pub.output_file))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * The module selection routine for GIF format output.\n */\n\nGLOBAL(djpeg_dest_ptr)\njinit_write_gif (j_decompress_ptr cinfo)\n{\n  gif_dest_ptr dest;\n\n  /* Create module interface object, fill in method pointers */\n  dest = (gif_dest_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(gif_dest_struct));\n  dest->cinfo = cinfo;\t\t/* make back link for subroutines */\n  dest->pub.start_output = start_output_gif;\n  dest->pub.put_pixel_rows = put_pixel_rows;\n  dest->pub.finish_output = finish_output_gif;\n\n  if (cinfo->out_color_space != JCS_GRAYSCALE &&\n      cinfo->out_color_space != JCS_RGB)\n    ERREXIT(cinfo, JERR_GIF_COLORSPACE);\n\n  /* Force quantization if color or if > 8 bits input */\n  if (cinfo->out_color_space != JCS_GRAYSCALE || cinfo->data_precision > 8) {\n    /* Force quantization to at most 256 colors */\n    cinfo->quantize_colors = TRUE;\n    if (cinfo->desired_number_of_colors > 256)\n      cinfo->desired_number_of_colors = 256;\n  }\n\n  /* Calculate output image dimensions so we can allocate space */\n  jpeg_calc_output_dimensions(cinfo);\n\n  if (cinfo->output_components != 1) /* safety check: just one component? */\n    ERREXIT(cinfo, JERR_GIF_BUG);\n\n  /* Create decompressor output buffer. */\n  dest->pub.buffer = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, cinfo->output_width, (JDIMENSION) 1);\n  dest->pub.buffer_height = 1;\n\n  return &dest->pub;\n}\n\n#endif /* GIF_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrjpgcom.1",
    "content": ".TH WRJPGCOM 1 \"15 June 1995\"\n.SH NAME\nwrjpgcom \\- insert text comments into a JPEG file\n.SH SYNOPSIS\n.B wrjpgcom\n[\n.B \\-replace\n]\n[\n.BI \\-comment \" text\"\n]\n[\n.BI \\-cfile \" name\"\n]\n[\n.I filename\n]\n.LP\n.SH DESCRIPTION\n.LP\n.B wrjpgcom\nreads the named JPEG/JFIF file, or the standard input if no file is named,\nand generates a new JPEG/JFIF file on standard output.  A comment block is\nadded to the file.\n.PP\nThe JPEG standard allows \"comment\" (COM) blocks to occur within a JPEG file.\nAlthough the standard doesn't actually define what COM blocks are for, they\nare widely used to hold user-supplied text strings.  This lets you add\nannotations, titles, index terms, etc to your JPEG files, and later retrieve\nthem as text.  COM blocks do not interfere with the image stored in the JPEG\nfile.  The maximum size of a COM block is 64K, but you can have as many of\nthem as you like in one JPEG file.\n.PP\n.B wrjpgcom\nadds a COM block, containing text you provide, to a JPEG file.\nOrdinarily, the COM block is added after any existing COM blocks; but you\ncan delete the old COM blocks if you wish.\n.SH OPTIONS\nSwitch names may be abbreviated, and are not case sensitive.\n.TP\n.B \\-replace\nDelete any existing COM blocks from the file.\n.TP\n.BI \\-comment \" text\"\nSupply text for new COM block on command line.\n.TP\n.BI \\-cfile \" name\"\nRead text for new COM block from named file.\n.PP\nIf you have only one line of comment text to add, you can provide it on the\ncommand line with\n.BR \\-comment .\nThe comment text must be surrounded with quotes so that it is treated as a\nsingle argument.  Longer comments can be read from a text file.\n.PP\nIf you give neither\n.B \\-comment\nnor\n.BR \\-cfile ,\nthen\n.B wrjpgcom\nwill read the comment text from standard input.  (In this case an input image\nfile name MUST be supplied, so that the source JPEG file comes from somewhere\nelse.)  You can enter multiple lines, up to 64KB worth.  Type an end-of-file\nindicator (usually control-D) to terminate the comment text entry.\n.PP\n.B wrjpgcom\nwill not add a COM block if the provided comment string is empty.  Therefore\n\\fB\\-replace \\-comment \"\"\\fR can be used to delete all COM blocks from a file.\n.SH EXAMPLES\n.LP\nAdd a short comment to in.jpg, producing out.jpg:\n.IP\n.B wrjpgcom \\-c\n\\fI\"View of my back yard\" in.jpg\n.B >\n.I out.jpg\n.PP\nAttach a long comment previously stored in comment.txt:\n.IP\n.B wrjpgcom\n.I in.jpg\n.B <\n.I comment.txt\n.B >\n.I out.jpg\n.PP\nor equivalently\n.IP\n.B wrjpgcom\n.B -cfile\n.I comment.txt\n.B <\n.I in.jpg\n.B >\n.I out.jpg\n.SH SEE ALSO\n.BR cjpeg (1),\n.BR djpeg (1),\n.BR jpegtran (1),\n.BR rdjpgcom (1)\n.SH AUTHOR\nIndependent JPEG Group\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrjpgcom.c",
    "content": "/*\n * wrjpgcom.c\n *\n * Copyright (C) 1994-1997, Thomas G. Lane.\n * Modified 2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains a very simple stand-alone application that inserts\n * user-supplied text as a COM (comment) marker in a JFIF file.\n * This may be useful as an example of the minimum logic needed to parse\n * JPEG markers.\n */\n\n#define JPEG_CJPEG_DJPEG\t/* to get the command-line config symbols */\n#include \"jinclude.h\"\t\t/* get auto-config symbols, <stdio.h> */\n\n#ifndef HAVE_STDLIB_H\t\t/* <stdlib.h> should declare malloc() */\nextern void * malloc ();\n#endif\n#include <ctype.h>\t\t/* to declare isupper(), tolower() */\n#ifdef USE_SETMODE\n#include <fcntl.h>\t\t/* to declare setmode()'s parameter macros */\n/* If you have setmode() but not <io.h>, just delete this line: */\n#include <io.h>\t\t\t/* to declare setmode() */\n#endif\n\n#ifdef USE_CCOMMAND\t\t/* command-line reader for Macintosh */\n#ifdef __MWERKS__\n#include <SIOUX.h>              /* Metrowerks needs this */\n#include <console.h>\t\t/* ... and this */\n#endif\n#ifdef THINK_C\n#include <console.h>\t\t/* Think declares it here */\n#endif\n#endif\n\n#ifdef DONT_USE_B_MODE\t\t/* define mode parameters for fopen() */\n#define READ_BINARY\t\"r\"\n#define WRITE_BINARY\t\"w\"\n#else\n#ifdef VMS\t\t\t/* VMS is very nonstandard */\n#define READ_BINARY\t\"rb\", \"ctx=stm\"\n#define WRITE_BINARY\t\"wb\", \"ctx=stm\"\n#else\t\t\t\t/* standard ANSI-compliant case */\n#define READ_BINARY\t\"rb\"\n#define WRITE_BINARY\t\"wb\"\n#endif\n#endif\n\n#ifndef EXIT_FAILURE\t\t/* define exit() codes if not provided */\n#define EXIT_FAILURE  1\n#endif\n#ifndef EXIT_SUCCESS\n#ifdef VMS\n#define EXIT_SUCCESS  1\t\t/* VMS is very nonstandard */\n#else\n#define EXIT_SUCCESS  0\n#endif\n#endif\n\n/* Reduce this value if your malloc() can't allocate blocks up to 64K.\n * On DOS, compiling in large model is usually a better solution.\n */\n\n#ifndef MAX_COM_LENGTH\n#define MAX_COM_LENGTH 65000L\t/* must be <= 65533 in any case */\n#endif\n\n\n/*\n * These macros are used to read the input file and write the output file.\n * To reuse this code in another application, you might need to change these.\n */\n\nstatic FILE * infile;\t\t/* input JPEG file */\n\n/* Return next input byte, or EOF if no more */\n#define NEXTBYTE()  getc(infile)\n\nstatic FILE * outfile;\t\t/* output JPEG file */\n\n/* Emit an output byte */\n#define PUTBYTE(x)  putc((x), outfile)\n\n\n/* Error exit handler */\n#define ERREXIT(msg)  (fprintf(stderr, \"%s\\n\", msg), exit(EXIT_FAILURE))\n\n\n/* Read one byte, testing for EOF */\nstatic int\nread_1_byte (void)\n{\n  int c;\n\n  c = NEXTBYTE();\n  if (c == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  return c;\n}\n\n/* Read 2 bytes, convert to unsigned int */\n/* All 2-byte quantities in JPEG markers are MSB first */\nstatic unsigned int\nread_2_bytes (void)\n{\n  int c1, c2;\n\n  c1 = NEXTBYTE();\n  if (c1 == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  c2 = NEXTBYTE();\n  if (c2 == EOF)\n    ERREXIT(\"Premature EOF in JPEG file\");\n  return (((unsigned int) c1) << 8) + ((unsigned int) c2);\n}\n\n\n/* Routines to write data to output file */\n\nstatic void\nwrite_1_byte (int c)\n{\n  PUTBYTE(c);\n}\n\nstatic void\nwrite_2_bytes (unsigned int val)\n{\n  PUTBYTE((val >> 8) & 0xFF);\n  PUTBYTE(val & 0xFF);\n}\n\nstatic void\nwrite_marker (int marker)\n{\n  PUTBYTE(0xFF);\n  PUTBYTE(marker);\n}\n\nstatic void\ncopy_rest_of_file (void)\n{\n  int c;\n\n  while ((c = NEXTBYTE()) != EOF)\n    PUTBYTE(c);\n}\n\n\n/*\n * JPEG markers consist of one or more 0xFF bytes, followed by a marker\n * code byte (which is not an FF).  Here are the marker codes of interest\n * in this program.  (See jdmarker.c for a more complete list.)\n */\n\n#define M_SOF0  0xC0\t\t/* Start Of Frame N */\n#define M_SOF1  0xC1\t\t/* N indicates which compression process */\n#define M_SOF2  0xC2\t\t/* Only SOF0-SOF2 are now in common use */\n#define M_SOF3  0xC3\n#define M_SOF5  0xC5\t\t/* NB: codes C4 and CC are NOT SOF markers */\n#define M_SOF6  0xC6\n#define M_SOF7  0xC7\n#define M_SOF9  0xC9\n#define M_SOF10 0xCA\n#define M_SOF11 0xCB\n#define M_SOF13 0xCD\n#define M_SOF14 0xCE\n#define M_SOF15 0xCF\n#define M_SOI   0xD8\t\t/* Start Of Image (beginning of datastream) */\n#define M_EOI   0xD9\t\t/* End Of Image (end of datastream) */\n#define M_SOS   0xDA\t\t/* Start Of Scan (begins compressed data) */\n#define M_COM   0xFE\t\t/* COMment */\n\n\n/*\n * Find the next JPEG marker and return its marker code.\n * We expect at least one FF byte, possibly more if the compressor used FFs\n * to pad the file.  (Padding FFs will NOT be replicated in the output file.)\n * There could also be non-FF garbage between markers.  The treatment of such\n * garbage is unspecified; we choose to skip over it but emit a warning msg.\n * NB: this routine must not be used after seeing SOS marker, since it will\n * not deal correctly with FF/00 sequences in the compressed image data...\n */\n\nstatic int\nnext_marker (void)\n{\n  int c;\n  int discarded_bytes = 0;\n\n  /* Find 0xFF byte; count and skip any non-FFs. */\n  c = read_1_byte();\n  while (c != 0xFF) {\n    discarded_bytes++;\n    c = read_1_byte();\n  }\n  /* Get marker code byte, swallowing any duplicate FF bytes.  Extra FFs\n   * are legal as pad bytes, so don't count them in discarded_bytes.\n   */\n  do {\n    c = read_1_byte();\n  } while (c == 0xFF);\n\n  if (discarded_bytes != 0) {\n    fprintf(stderr, \"Warning: garbage data found in JPEG file\\n\");\n  }\n\n  return c;\n}\n\n\n/*\n * Read the initial marker, which should be SOI.\n * For a JFIF file, the first two bytes of the file should be literally\n * 0xFF M_SOI.  To be more general, we could use next_marker, but if the\n * input file weren't actually JPEG at all, next_marker might read the whole\n * file and then return a misleading error message...\n */\n\nstatic int\nfirst_marker (void)\n{\n  int c1, c2;\n\n  c1 = NEXTBYTE();\n  c2 = NEXTBYTE();\n  if (c1 != 0xFF || c2 != M_SOI)\n    ERREXIT(\"Not a JPEG file\");\n  return c2;\n}\n\n\n/*\n * Most types of marker are followed by a variable-length parameter segment.\n * This routine skips over the parameters for any marker we don't otherwise\n * want to process.\n * Note that we MUST skip the parameter segment explicitly in order not to\n * be fooled by 0xFF bytes that might appear within the parameter segment;\n * such bytes do NOT introduce new markers.\n */\n\nstatic void\ncopy_variable (void)\n/* Copy an unknown or uninteresting variable-length marker */\n{\n  unsigned int length;\n\n  /* Get the marker parameter length count */\n  length = read_2_bytes();\n  write_2_bytes(length);\n  /* Length includes itself, so must be at least 2 */\n  if (length < 2)\n    ERREXIT(\"Erroneous JPEG marker length\");\n  length -= 2;\n  /* Skip over the remaining bytes */\n  while (length > 0) {\n    write_1_byte(read_1_byte());\n    length--;\n  }\n}\n\nstatic void\nskip_variable (void)\n/* Skip over an unknown or uninteresting variable-length marker */\n{\n  unsigned int length;\n\n  /* Get the marker parameter length count */\n  length = read_2_bytes();\n  /* Length includes itself, so must be at least 2 */\n  if (length < 2)\n    ERREXIT(\"Erroneous JPEG marker length\");\n  length -= 2;\n  /* Skip over the remaining bytes */\n  while (length > 0) {\n    (void) read_1_byte();\n    length--;\n  }\n}\n\n\n/*\n * Parse the marker stream until SOFn or EOI is seen;\n * copy data to output, but discard COM markers unless keep_COM is true.\n */\n\nstatic int\nscan_JPEG_header (int keep_COM)\n{\n  int marker;\n\n  /* Expect SOI at start of file */\n  if (first_marker() != M_SOI)\n    ERREXIT(\"Expected SOI marker first\");\n  write_marker(M_SOI);\n\n  /* Scan miscellaneous markers until we reach SOFn. */\n  for (;;) {\n    marker = next_marker();\n    switch (marker) {\n      /* Note that marker codes 0xC4, 0xC8, 0xCC are not, and must not be,\n       * treated as SOFn.  C4 in particular is actually DHT.\n       */\n    case M_SOF0:\t\t/* Baseline */\n    case M_SOF1:\t\t/* Extended sequential, Huffman */\n    case M_SOF2:\t\t/* Progressive, Huffman */\n    case M_SOF3:\t\t/* Lossless, Huffman */\n    case M_SOF5:\t\t/* Differential sequential, Huffman */\n    case M_SOF6:\t\t/* Differential progressive, Huffman */\n    case M_SOF7:\t\t/* Differential lossless, Huffman */\n    case M_SOF9:\t\t/* Extended sequential, arithmetic */\n    case M_SOF10:\t\t/* Progressive, arithmetic */\n    case M_SOF11:\t\t/* Lossless, arithmetic */\n    case M_SOF13:\t\t/* Differential sequential, arithmetic */\n    case M_SOF14:\t\t/* Differential progressive, arithmetic */\n    case M_SOF15:\t\t/* Differential lossless, arithmetic */\n      return marker;\n\n    case M_SOS:\t\t\t/* should not see compressed data before SOF */\n      ERREXIT(\"SOS without prior SOFn\");\n      break;\n\n    case M_EOI:\t\t\t/* in case it's a tables-only JPEG stream */\n      return marker;\n\n    case M_COM:\t\t\t/* Existing COM: conditionally discard */\n      if (keep_COM) {\n\twrite_marker(marker);\n\tcopy_variable();\n      } else {\n\tskip_variable();\n      }\n      break;\n\n    default:\t\t\t/* Anything else just gets copied */\n      write_marker(marker);\n      copy_variable();\t\t/* we assume it has a parameter count... */\n      break;\n    }\n  } /* end loop */\n}\n\n\n/* Command line parsing code */\n\nstatic const char * progname;\t/* program name for error messages */\n\n\nstatic void\nusage (void)\n/* complain about bad command line */\n{\n  fprintf(stderr, \"wrjpgcom inserts a textual comment in a JPEG file.\\n\");\n  fprintf(stderr, \"You can add to or replace any existing comment(s).\\n\");\n\n  fprintf(stderr, \"Usage: %s [switches] \", progname);\n#ifdef TWO_FILE_COMMANDLINE\n  fprintf(stderr, \"inputfile outputfile\\n\");\n#else\n  fprintf(stderr, \"[inputfile]\\n\");\n#endif\n\n  fprintf(stderr, \"Switches (names may be abbreviated):\\n\");\n  fprintf(stderr, \"  -replace         Delete any existing comments\\n\");\n  fprintf(stderr, \"  -comment \\\"text\\\"  Insert comment with given text\\n\");\n  fprintf(stderr, \"  -cfile name      Read comment from named file\\n\");\n  fprintf(stderr, \"Notice that you must put quotes around the comment text\\n\");\n  fprintf(stderr, \"when you use -comment.\\n\");\n  fprintf(stderr, \"If you do not give either -comment or -cfile on the command line,\\n\");\n  fprintf(stderr, \"then the comment text is read from standard input.\\n\");\n  fprintf(stderr, \"It can be multiple lines, up to %u characters total.\\n\",\n\t  (unsigned int) MAX_COM_LENGTH);\n#ifndef TWO_FILE_COMMANDLINE\n  fprintf(stderr, \"You must specify an input JPEG file name when supplying\\n\");\n  fprintf(stderr, \"comment text from standard input.\\n\");\n#endif\n\n  exit(EXIT_FAILURE);\n}\n\n\nstatic int\nkeymatch (char * arg, const char * keyword, int minchars)\n/* Case-insensitive matching of (possibly abbreviated) keyword switches. */\n/* keyword is the constant keyword (must be lower case already), */\n/* minchars is length of minimum legal abbreviation. */\n{\n  register int ca, ck;\n  register int nmatched = 0;\n\n  while ((ca = *arg++) != '\\0') {\n    if ((ck = *keyword++) == '\\0')\n      return 0;\t\t\t/* arg longer than keyword, no good */\n    if (isupper(ca))\t\t/* force arg to lcase (assume ck is already) */\n      ca = tolower(ca);\n    if (ca != ck)\n      return 0;\t\t\t/* no good */\n    nmatched++;\t\t\t/* count matched characters */\n  }\n  /* reached end of argument; fail if it's too short for unique abbrev */\n  if (nmatched < minchars)\n    return 0;\n  return 1;\t\t\t/* A-OK */\n}\n\n\n/*\n * The main program.\n */\n\nint\nmain (int argc, char **argv)\n{\n  int argn;\n  char * arg;\n  int keep_COM = 1;\n  char * comment_arg = NULL;\n  FILE * comment_file = NULL;\n  unsigned int comment_length = 0;\n  int marker;\n\n  /* On Mac, fetch a command line. */\n#ifdef USE_CCOMMAND\n  argc = ccommand(&argv);\n#endif\n\n  progname = argv[0];\n  if (progname == NULL || progname[0] == 0)\n    progname = \"wrjpgcom\";\t/* in case C library doesn't provide it */\n\n  /* Parse switches, if any */\n  for (argn = 1; argn < argc; argn++) {\n    arg = argv[argn];\n    if (arg[0] != '-')\n      break;\t\t\t/* not switch, must be file name */\n    arg++;\t\t\t/* advance over '-' */\n    if (keymatch(arg, \"replace\", 1)) {\n      keep_COM = 0;\n    } else if (keymatch(arg, \"cfile\", 2)) {\n      if (++argn >= argc) usage();\n      if ((comment_file = fopen(argv[argn], \"r\")) == NULL) {\n\tfprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n\texit(EXIT_FAILURE);\n      }\n    } else if (keymatch(arg, \"comment\", 1)) {\n      if (++argn >= argc) usage();\n      comment_arg = argv[argn];\n      /* If the comment text starts with '\"', then we are probably running\n       * under MS-DOG and must parse out the quoted string ourselves.  Sigh.\n       */\n      if (comment_arg[0] == '\"') {\n\tcomment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);\n\tif (comment_arg == NULL)\n\t  ERREXIT(\"Insufficient memory\");\n\tif (strlen(argv[argn]+1) >= (size_t) MAX_COM_LENGTH) {\n\t  fprintf(stderr, \"Comment text may not exceed %u bytes\\n\",\n\t\t  (unsigned int) MAX_COM_LENGTH);\n\t  exit(EXIT_FAILURE);\n\t}\n\tstrcpy(comment_arg, argv[argn]+1);\n\tfor (;;) {\n\t  comment_length = (unsigned int) strlen(comment_arg);\n\t  if (comment_length > 0 && comment_arg[comment_length-1] == '\"') {\n\t    comment_arg[comment_length-1] = '\\0'; /* zap terminating quote */\n\t    break;\n\t  }\n\t  if (++argn >= argc)\n\t    ERREXIT(\"Missing ending quote mark\");\n\t  if (strlen(comment_arg) + 1 + strlen(argv[argn]) >=\n\t      (size_t) MAX_COM_LENGTH) {\n\t    fprintf(stderr, \"Comment text may not exceed %u bytes\\n\",\n\t\t    (unsigned int) MAX_COM_LENGTH);\n\t    exit(EXIT_FAILURE);\n\t  }\n\t  strcat(comment_arg, \" \");\n\t  strcat(comment_arg, argv[argn]);\n\t}\n      } else if (strlen(comment_arg) >= (size_t) MAX_COM_LENGTH) {\n\tfprintf(stderr, \"Comment text may not exceed %u bytes\\n\",\n\t\t(unsigned int) MAX_COM_LENGTH);\n\texit(EXIT_FAILURE);\n      }\n      comment_length = (unsigned int) strlen(comment_arg);\n    } else\n      usage();\n  }\n\n  /* Cannot use both -comment and -cfile. */\n  if (comment_arg != NULL && comment_file != NULL)\n    usage();\n  /* If there is neither -comment nor -cfile, we will read the comment text\n   * from stdin; in this case there MUST be an input JPEG file name.\n   */\n  if (comment_arg == NULL && comment_file == NULL && argn >= argc)\n    usage();\n\n  /* Open the input file. */\n  if (argn < argc) {\n    if ((infile = fopen(argv[argn], READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn]);\n      exit(EXIT_FAILURE);\n    }\n  } else {\n    /* default input file is stdin */\n#ifdef USE_SETMODE\t\t/* need to hack file mode? */\n    setmode(fileno(stdin), O_BINARY);\n#endif\n#ifdef USE_FDOPEN\t\t/* need to re-open in binary mode? */\n    if ((infile = fdopen(fileno(stdin), READ_BINARY)) == NULL) {\n      fprintf(stderr, \"%s: can't open stdin\\n\", progname);\n      exit(EXIT_FAILURE);\n    }\n#else\n    infile = stdin;\n#endif\n  }\n\n  /* Open the output file. */\n#ifdef TWO_FILE_COMMANDLINE\n  /* Must have explicit output file name */\n  if (argn != argc-2) {\n    fprintf(stderr, \"%s: must name one input and one output file\\n\",\n\t    progname);\n    usage();\n  }\n  if ((outfile = fopen(argv[argn+1], WRITE_BINARY)) == NULL) {\n    fprintf(stderr, \"%s: can't open %s\\n\", progname, argv[argn+1]);\n    exit(EXIT_FAILURE);\n  }\n#else\n  /* Unix style: expect zero or one file name */\n  if (argn < argc-1) {\n    fprintf(stderr, \"%s: only one input file\\n\", progname);\n    usage();\n  }\n  /* default output file is stdout */\n#ifdef USE_SETMODE\t\t/* need to hack file mode? */\n  setmode(fileno(stdout), O_BINARY);\n#endif\n#ifdef USE_FDOPEN\t\t/* need to re-open in binary mode? */\n  if ((outfile = fdopen(fileno(stdout), WRITE_BINARY)) == NULL) {\n    fprintf(stderr, \"%s: can't open stdout\\n\", progname);\n    exit(EXIT_FAILURE);\n  }\n#else\n  outfile = stdout;\n#endif\n#endif /* TWO_FILE_COMMANDLINE */\n\n  /* Collect comment text from comment_file or stdin, if necessary */\n  if (comment_arg == NULL) {\n    FILE * src_file;\n    int c;\n\n    comment_arg = (char *) malloc((size_t) MAX_COM_LENGTH);\n    if (comment_arg == NULL)\n      ERREXIT(\"Insufficient memory\");\n    comment_length = 0;\n    src_file = (comment_file != NULL ? comment_file : stdin);\n    while ((c = getc(src_file)) != EOF) {\n      if (comment_length >= (unsigned int) MAX_COM_LENGTH) {\n\tfprintf(stderr, \"Comment text may not exceed %u bytes\\n\",\n\t\t(unsigned int) MAX_COM_LENGTH);\n\texit(EXIT_FAILURE);\n      }\n      comment_arg[comment_length++] = (char) c;\n    }\n    if (comment_file != NULL)\n      fclose(comment_file);\n  }\n\n  /* Copy JPEG headers until SOFn marker;\n   * we will insert the new comment marker just before SOFn.\n   * This (a) causes the new comment to appear after, rather than before,\n   * existing comments; and (b) ensures that comments come after any JFIF\n   * or JFXX markers, as required by the JFIF specification.\n   */\n  marker = scan_JPEG_header(keep_COM);\n  /* Insert the new COM marker, but only if nonempty text has been supplied */\n  if (comment_length > 0) {\n    write_marker(M_COM);\n    write_2_bytes(comment_length + 2);\n    while (comment_length > 0) {\n      write_1_byte(*comment_arg++);\n      comment_length--;\n    }\n  }\n  /* Duplicate the remainder of the source file.\n   * Note that any COM markers occuring after SOF will not be touched.\n   */\n  write_marker(marker);\n  copy_rest_of_file();\n\n  /* All done. */\n  exit(EXIT_SUCCESS);\n  return 0;\t\t\t/* suppress no-return-value warnings */\n}\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrppm.c",
    "content": "/*\n * wrppm.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2009 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write output images in PPM/PGM format.\n * The extended 2-byte-per-sample raw PPM/PGM formats are supported.\n * The PBMPLUS library is NOT required to compile this software\n * (but it is highly useful as a set of PPM image manipulation programs).\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume output to\n * an ordinary stdio stream.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef PPM_SUPPORTED\n\n\n/*\n * For 12-bit JPEG data, we either downscale the values to 8 bits\n * (to write standard byte-per-sample PPM/PGM files), or output\n * nonstandard word-per-sample PPM/PGM files.  Downscaling is done\n * if PPM_NORAWWORD is defined (this can be done in the Makefile\n * or in jconfig.h).\n * (When the core library supports data precision reduction, a cleaner\n * implementation will be to ask for that instead.)\n */\n\n#if BITS_IN_JSAMPLE == 8\n#define PUTPPMSAMPLE(ptr,v)  *ptr++ = (char) (v)\n#define BYTESPERSAMPLE 1\n#define PPM_MAXVAL 255\n#else\n#ifdef PPM_NORAWWORD\n#define PUTPPMSAMPLE(ptr,v)  *ptr++ = (char) ((v) >> (BITS_IN_JSAMPLE-8))\n#define BYTESPERSAMPLE 1\n#define PPM_MAXVAL 255\n#else\n/* The word-per-sample format always puts the MSB first. */\n#define PUTPPMSAMPLE(ptr,v)\t\t\t\\\n\t{ register int val_ = v;\t\t\\\n\t  *ptr++ = (char) ((val_ >> 8) & 0xFF);\t\\\n\t  *ptr++ = (char) (val_ & 0xFF);\t\\\n\t}\n#define BYTESPERSAMPLE 2\n#define PPM_MAXVAL ((1<<BITS_IN_JSAMPLE)-1)\n#endif\n#endif\n\n\n/*\n * When JSAMPLE is the same size as char, we can just fwrite() the\n * decompressed data to the PPM or PGM file.  On PCs, in order to make this\n * work the output buffer must be allocated in near data space, because we are\n * assuming small-data memory model wherein fwrite() can't reach far memory.\n * If you need to process very wide images on a PC, you might have to compile\n * in large-memory model, or else replace fwrite() with a putc() loop ---\n * which will be much slower.\n */\n\n\n/* Private version of data destination object */\n\ntypedef struct {\n  struct djpeg_dest_struct pub;\t/* public fields */\n\n  /* Usually these two pointers point to the same place: */\n  char *iobuffer;\t\t/* fwrite's I/O buffer */\n  JSAMPROW pixrow;\t\t/* decompressor output buffer */\n  size_t buffer_width;\t\t/* width of I/O buffer */\n  JDIMENSION samples_per_row;\t/* JSAMPLEs per output row */\n} ppm_dest_struct;\n\ntypedef ppm_dest_struct * ppm_dest_ptr;\n\n\n/*\n * Write some pixel data.\n * In this module rows_supplied will always be 1.\n *\n * put_pixel_rows handles the \"normal\" 8-bit case where the decompressor\n * output buffer is physically the same as the fwrite buffer.\n */\n\nMETHODDEF(void)\nput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\tJDIMENSION rows_supplied)\n{\n  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;\n\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\n/*\n * This code is used when we have to copy the data and apply a pixel\n * format translation.  Typically this only happens in 12-bit mode.\n */\n\nMETHODDEF(void)\ncopy_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\t JDIMENSION rows_supplied)\n{\n  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;\n  register char * bufferptr;\n  register JSAMPROW ptr;\n  register JDIMENSION col;\n\n  ptr = dest->pub.buffer[0];\n  bufferptr = dest->iobuffer;\n  for (col = dest->samples_per_row; col > 0; col--) {\n    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(*ptr++));\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\n/*\n * Write some pixel data when color quantization is in effect.\n * We have to demap the color index values to straight data.\n */\n\nMETHODDEF(void)\nput_demapped_rgb (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\t  JDIMENSION rows_supplied)\n{\n  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;\n  register char * bufferptr;\n  register int pixval;\n  register JSAMPROW ptr;\n  register JSAMPROW color_map0 = cinfo->colormap[0];\n  register JSAMPROW color_map1 = cinfo->colormap[1];\n  register JSAMPROW color_map2 = cinfo->colormap[2];\n  register JDIMENSION col;\n\n  ptr = dest->pub.buffer[0];\n  bufferptr = dest->iobuffer;\n  for (col = cinfo->output_width; col > 0; col--) {\n    pixval = GETJSAMPLE(*ptr++);\n    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map0[pixval]));\n    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map1[pixval]));\n    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map2[pixval]));\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\nMETHODDEF(void)\nput_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\t   JDIMENSION rows_supplied)\n{\n  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;\n  register char * bufferptr;\n  register JSAMPROW ptr;\n  register JSAMPROW color_map = cinfo->colormap[0];\n  register JDIMENSION col;\n\n  ptr = dest->pub.buffer[0];\n  bufferptr = dest->iobuffer;\n  for (col = cinfo->output_width; col > 0; col--) {\n    PUTPPMSAMPLE(bufferptr, GETJSAMPLE(color_map[GETJSAMPLE(*ptr++)]));\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\n/*\n * Startup: write the file header.\n */\n\nMETHODDEF(void)\nstart_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  ppm_dest_ptr dest = (ppm_dest_ptr) dinfo;\n\n  /* Emit file header */\n  switch (cinfo->out_color_space) {\n  case JCS_GRAYSCALE:\n    /* emit header for raw PGM format */\n    fprintf(dest->pub.output_file, \"P5\\n%ld %ld\\n%d\\n\",\n\t    (long) cinfo->output_width, (long) cinfo->output_height,\n\t    PPM_MAXVAL);\n    break;\n  case JCS_RGB:\n    /* emit header for raw PPM format */\n    fprintf(dest->pub.output_file, \"P6\\n%ld %ld\\n%d\\n\",\n\t    (long) cinfo->output_width, (long) cinfo->output_height,\n\t    PPM_MAXVAL);\n    break;\n  default:\n    ERREXIT(cinfo, JERR_PPM_COLORSPACE);\n  }\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_output_ppm (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  /* Make sure we wrote the output file OK */\n  fflush(dinfo->output_file);\n  if (ferror(dinfo->output_file))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * The module selection routine for PPM format output.\n */\n\nGLOBAL(djpeg_dest_ptr)\njinit_write_ppm (j_decompress_ptr cinfo)\n{\n  ppm_dest_ptr dest;\n\n  /* Create module interface object, fill in method pointers */\n  dest = (ppm_dest_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(ppm_dest_struct));\n  dest->pub.start_output = start_output_ppm;\n  dest->pub.finish_output = finish_output_ppm;\n\n  /* Calculate output image dimensions so we can allocate space */\n  jpeg_calc_output_dimensions(cinfo);\n\n  /* Create physical I/O buffer.  Note we make this near on a PC. */\n  dest->samples_per_row = cinfo->output_width * cinfo->out_color_components;\n  dest->buffer_width = dest->samples_per_row * (BYTESPERSAMPLE * SIZEOF(char));\n  dest->iobuffer = (char *) (*cinfo->mem->alloc_small)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width);\n\n  if (cinfo->quantize_colors || BITS_IN_JSAMPLE != 8 ||\n      SIZEOF(JSAMPLE) != SIZEOF(char)) {\n    /* When quantizing, we need an output buffer for colormap indexes\n     * that's separate from the physical I/O buffer.  We also need a\n     * separate buffer if pixel format translation must take place.\n     */\n    dest->pub.buffer = (*cinfo->mem->alloc_sarray)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE,\n       cinfo->output_width * cinfo->output_components, (JDIMENSION) 1);\n    dest->pub.buffer_height = 1;\n    if (! cinfo->quantize_colors)\n      dest->pub.put_pixel_rows = copy_pixel_rows;\n    else if (cinfo->out_color_space == JCS_GRAYSCALE)\n      dest->pub.put_pixel_rows = put_demapped_gray;\n    else\n      dest->pub.put_pixel_rows = put_demapped_rgb;\n  } else {\n    /* We will fwrite() directly from decompressor output buffer. */\n    /* Synthesize a JSAMPARRAY pointer structure */\n    /* Cast here implies near->far pointer conversion on PCs */\n    dest->pixrow = (JSAMPROW) dest->iobuffer;\n    dest->pub.buffer = & dest->pixrow;\n    dest->pub.buffer_height = 1;\n    dest->pub.put_pixel_rows = put_pixel_rows;\n  }\n\n  return (djpeg_dest_ptr) dest;\n}\n\n#endif /* PPM_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrrle.c",
    "content": "/*\n * wrrle.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write output images in RLE format.\n * The Utah Raster Toolkit library is required (version 3.1 or later).\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume output to\n * an ordinary stdio stream.\n *\n * Based on code contributed by Mike Lijewski,\n * with updates from Robert Hutchinson.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef RLE_SUPPORTED\n\n/* rle.h is provided by the Utah Raster Toolkit. */\n\n#include <rle.h>\n\n/*\n * We assume that JSAMPLE has the same representation as rle_pixel,\n * to wit, \"unsigned char\".  Hence we can't cope with 12- or 16-bit samples.\n */\n\n#if BITS_IN_JSAMPLE != 8\n  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */\n#endif\n\n\n/*\n * Since RLE stores scanlines bottom-to-top, we have to invert the image\n * from JPEG's top-to-bottom order.  To do this, we save the outgoing data\n * in a virtual array during put_pixel_row calls, then actually emit the\n * RLE file during finish_output.\n */\n\n\n/*\n * For now, if we emit an RLE color map then it is always 256 entries long,\n * though not all of the entries need be used.\n */\n\n#define CMAPBITS\t8\n#define CMAPLENGTH\t(1<<(CMAPBITS))\n\ntypedef struct {\n  struct djpeg_dest_struct pub; /* public fields */\n\n  jvirt_sarray_ptr image;\t/* virtual array to store the output image */\n  rle_map *colormap;\t \t/* RLE-style color map, or NULL if none */\n  rle_pixel **rle_row;\t\t/* To pass rows to rle_putrow() */\n\n} rle_dest_struct;\n\ntypedef rle_dest_struct * rle_dest_ptr;\n\n/* Forward declarations */\nMETHODDEF(void) rle_put_pixel_rows\n    JPP((j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t JDIMENSION rows_supplied));\n\n\n/*\n * Write the file header.\n *\n * In this module it's easier to wait till finish_output to write anything.\n */\n\nMETHODDEF(void)\nstart_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  rle_dest_ptr dest = (rle_dest_ptr) dinfo;\n  size_t cmapsize;\n  int i, ci;\n#ifdef PROGRESS_REPORT\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n#endif\n\n  /*\n   * Make sure the image can be stored in RLE format.\n   *\n   * - RLE stores image dimensions as *signed* 16 bit integers.  JPEG\n   *   uses unsigned, so we have to check the width.\n   *\n   * - Colorspace is expected to be grayscale or RGB.\n   *\n   * - The number of channels (components) is expected to be 1 (grayscale/\n   *   pseudocolor) or 3 (truecolor/directcolor).\n   *   (could be 2 or 4 if using an alpha channel, but we aren't)\n   */\n\n  if (cinfo->output_width > 32767 || cinfo->output_height > 32767)\n    ERREXIT2(cinfo, JERR_RLE_DIMENSIONS, cinfo->output_width, \n\t     cinfo->output_height);\n\n  if (cinfo->out_color_space != JCS_GRAYSCALE &&\n      cinfo->out_color_space != JCS_RGB)\n    ERREXIT(cinfo, JERR_RLE_COLORSPACE);\n\n  if (cinfo->output_components != 1 && cinfo->output_components != 3)\n    ERREXIT1(cinfo, JERR_RLE_TOOMANYCHANNELS, cinfo->num_components);\n\n  /* Convert colormap, if any, to RLE format. */\n\n  dest->colormap = NULL;\n\n  if (cinfo->quantize_colors) {\n    /* Allocate storage for RLE-style cmap, zero any extra entries */\n    cmapsize = cinfo->out_color_components * CMAPLENGTH * SIZEOF(rle_map);\n    dest->colormap = (rle_map *) (*cinfo->mem->alloc_small)\n      ((j_common_ptr) cinfo, JPOOL_IMAGE, cmapsize);\n    MEMZERO(dest->colormap, cmapsize);\n\n    /* Save away data in RLE format --- note 8-bit left shift! */\n    /* Shifting would need adjustment for JSAMPLEs wider than 8 bits. */\n    for (ci = 0; ci < cinfo->out_color_components; ci++) {\n      for (i = 0; i < cinfo->actual_number_of_colors; i++) {\n        dest->colormap[ci * CMAPLENGTH + i] =\n          GETJSAMPLE(cinfo->colormap[ci][i]) << 8;\n      }\n    }\n  }\n\n  /* Set the output buffer to the first row */\n  dest->pub.buffer = (*cinfo->mem->access_virt_sarray)\n    ((j_common_ptr) cinfo, dest->image, (JDIMENSION) 0, (JDIMENSION) 1, TRUE);\n  dest->pub.buffer_height = 1;\n\n  dest->pub.put_pixel_rows = rle_put_pixel_rows;\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL) {\n    progress->total_extra_passes++;  /* count file writing as separate pass */\n  }\n#endif\n}\n\n\n/*\n * Write some pixel data.\n *\n * This routine just saves the data away in a virtual array.\n */\n\nMETHODDEF(void)\nrle_put_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\t    JDIMENSION rows_supplied)\n{\n  rle_dest_ptr dest = (rle_dest_ptr) dinfo;\n\n  if (cinfo->output_scanline < cinfo->output_height) {\n    dest->pub.buffer = (*cinfo->mem->access_virt_sarray)\n      ((j_common_ptr) cinfo, dest->image,\n       cinfo->output_scanline, (JDIMENSION) 1, TRUE);\n  }\n}\n\n/*\n * Finish up at the end of the file.\n *\n * Here is where we really output the RLE file.\n */\n\nMETHODDEF(void)\nfinish_output_rle (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  rle_dest_ptr dest = (rle_dest_ptr) dinfo;\n  rle_hdr header;\t\t/* Output file information */\n  rle_pixel **rle_row, *red, *green, *blue;\n  JSAMPROW output_row;\n  char cmapcomment[80];\n  int row, col;\n  int ci;\n#ifdef PROGRESS_REPORT\n  cd_progress_ptr progress = (cd_progress_ptr) cinfo->progress;\n#endif\n\n  /* Initialize the header info */\n  header = *rle_hdr_init(NULL);\n  header.rle_file = dest->pub.output_file;\n  header.xmin     = 0;\n  header.xmax     = cinfo->output_width  - 1;\n  header.ymin     = 0;\n  header.ymax     = cinfo->output_height - 1;\n  header.alpha    = 0;\n  header.ncolors  = cinfo->output_components;\n  for (ci = 0; ci < cinfo->output_components; ci++) {\n    RLE_SET_BIT(header, ci);\n  }\n  if (cinfo->quantize_colors) {\n    header.ncmap   = cinfo->out_color_components;\n    header.cmaplen = CMAPBITS;\n    header.cmap    = dest->colormap;\n    /* Add a comment to the output image with the true colormap length. */\n    sprintf(cmapcomment, \"color_map_length=%d\", cinfo->actual_number_of_colors);\n    rle_putcom(cmapcomment, &header);\n  }\n\n  /* Emit the RLE header and color map (if any) */\n  rle_put_setup(&header);\n\n  /* Now output the RLE data from our virtual array.\n   * We assume here that (a) rle_pixel is represented the same as JSAMPLE,\n   * and (b) we are not on a machine where FAR pointers differ from regular.\n   */\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL) {\n    progress->pub.pass_limit = cinfo->output_height;\n    progress->pub.pass_counter = 0;\n    (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n  }\n#endif\n\n  if (cinfo->output_components == 1) {\n    for (row = cinfo->output_height-1; row >= 0; row--) {\n      rle_row = (rle_pixel **) (*cinfo->mem->access_virt_sarray)\n        ((j_common_ptr) cinfo, dest->image,\n\t (JDIMENSION) row, (JDIMENSION) 1, FALSE);\n      rle_putrow(rle_row, (int) cinfo->output_width, &header);\n#ifdef PROGRESS_REPORT\n      if (progress != NULL) {\n        progress->pub.pass_counter++;\n        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n      }\n#endif\n    }\n  } else {\n    for (row = cinfo->output_height-1; row >= 0; row--) {\n      rle_row = (rle_pixel **) dest->rle_row;\n      output_row = * (*cinfo->mem->access_virt_sarray)\n        ((j_common_ptr) cinfo, dest->image,\n\t (JDIMENSION) row, (JDIMENSION) 1, FALSE);\n      red = rle_row[0];\n      green = rle_row[1];\n      blue = rle_row[2];\n      for (col = cinfo->output_width; col > 0; col--) {\n        *red++ = GETJSAMPLE(*output_row++);\n        *green++ = GETJSAMPLE(*output_row++);\n        *blue++ = GETJSAMPLE(*output_row++);\n      }\n      rle_putrow(rle_row, (int) cinfo->output_width, &header);\n#ifdef PROGRESS_REPORT\n      if (progress != NULL) {\n        progress->pub.pass_counter++;\n        (*progress->pub.progress_monitor) ((j_common_ptr) cinfo);\n      }\n#endif\n    }\n  }\n\n#ifdef PROGRESS_REPORT\n  if (progress != NULL)\n    progress->completed_extra_passes++;\n#endif\n\n  /* Emit file trailer */\n  rle_puteof(&header);\n  fflush(dest->pub.output_file);\n  if (ferror(dest->pub.output_file))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * The module selection routine for RLE format output.\n */\n\nGLOBAL(djpeg_dest_ptr)\njinit_write_rle (j_decompress_ptr cinfo)\n{\n  rle_dest_ptr dest;\n\n  /* Create module interface object, fill in method pointers */\n  dest = (rle_dest_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n                                  SIZEOF(rle_dest_struct));\n  dest->pub.start_output = start_output_rle;\n  dest->pub.finish_output = finish_output_rle;\n\n  /* Calculate output image dimensions so we can allocate space */\n  jpeg_calc_output_dimensions(cinfo);\n\n  /* Allocate a work array for output to the RLE library. */\n  dest->rle_row = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE,\n     cinfo->output_width, (JDIMENSION) cinfo->output_components);\n\n  /* Allocate a virtual array to hold the image. */\n  dest->image = (*cinfo->mem->request_virt_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,\n     (JDIMENSION) (cinfo->output_width * cinfo->output_components),\n     cinfo->output_height, (JDIMENSION) 1);\n\n  return (djpeg_dest_ptr) dest;\n}\n\n#endif /* RLE_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libjpeg/wrtarga.c",
    "content": "/*\n * wrtarga.c\n *\n * Copyright (C) 1991-1996, Thomas G. Lane.\n * Modified 2015 by Guido Vollbeding.\n * This file is part of the Independent JPEG Group's software.\n * For conditions of distribution and use, see the accompanying README file.\n *\n * This file contains routines to write output images in Targa format.\n *\n * These routines may need modification for non-Unix environments or\n * specialized applications.  As they stand, they assume output to\n * an ordinary stdio stream.\n *\n * Based on code contributed by Lee Daniel Crocker.\n */\n\n#include \"cdjpeg.h\"\t\t/* Common decls for cjpeg/djpeg applications */\n\n#ifdef TARGA_SUPPORTED\n\n\n/*\n * To support 12-bit JPEG data, we'd have to scale output down to 8 bits.\n * This is not yet implemented.\n */\n\n#if BITS_IN_JSAMPLE != 8\n  Sorry, this code only copes with 8-bit JSAMPLEs. /* deliberate syntax err */\n#endif\n\n/*\n * The output buffer needs to be writable by fwrite().  On PCs, we must\n * allocate the buffer in near data space, because we are assuming small-data\n * memory model, wherein fwrite() can't reach far memory.  If you need to\n * process very wide images on a PC, you might have to compile in large-memory\n * model, or else replace fwrite() with a putc() loop --- which will be much\n * slower.\n */\n\n\n/* Private version of data destination object */\n\ntypedef struct {\n  struct djpeg_dest_struct pub;\t/* public fields */\n\n  char *iobuffer;\t\t/* physical I/O buffer */\n  JDIMENSION buffer_width;\t/* width of one row */\n} tga_dest_struct;\n\ntypedef tga_dest_struct * tga_dest_ptr;\n\n\nLOCAL(void)\nwrite_header (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo, int num_colors)\n/* Create and write a Targa header */\n{\n  char targaheader[18];\n\n  /* Set unused fields of header to 0 */\n  MEMZERO(targaheader, SIZEOF(targaheader));\n\n  if (num_colors > 0) {\n    targaheader[1] = 1;\t\t/* color map type 1 */\n    targaheader[5] = (char) (num_colors & 0xFF);\n    targaheader[6] = (char) (num_colors >> 8);\n    targaheader[7] = 24;\t/* 24 bits per cmap entry */\n  }\n\n  targaheader[12] = (char) (cinfo->output_width & 0xFF);\n  targaheader[13] = (char) (cinfo->output_width >> 8);\n  targaheader[14] = (char) (cinfo->output_height & 0xFF);\n  targaheader[15] = (char) (cinfo->output_height >> 8);\n  targaheader[17] = 0x20;\t/* Top-down, non-interlaced */\n\n  if (cinfo->out_color_space == JCS_GRAYSCALE) {\n    targaheader[2] = 3;\t\t/* image type = uncompressed grayscale */\n    targaheader[16] = 8;\t/* bits per pixel */\n  } else {\t\t\t/* must be RGB */\n    if (num_colors > 0) {\n      targaheader[2] = 1;\t/* image type = colormapped RGB */\n      targaheader[16] = 8;\n    } else {\n      targaheader[2] = 2;\t/* image type = uncompressed RGB */\n      targaheader[16] = 24;\n    }\n  }\n\n  if (JFWRITE(dinfo->output_file, targaheader, 18) != (size_t) 18)\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * Write some pixel data.\n * In this module rows_supplied will always be 1.\n */\n\nMETHODDEF(void)\nput_pixel_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\tJDIMENSION rows_supplied)\n/* used for unquantized full-color output */\n{\n  tga_dest_ptr dest = (tga_dest_ptr) dinfo;\n  register JSAMPROW inptr;\n  register char * outptr;\n  register JDIMENSION col;\n\n  inptr = dest->pub.buffer[0];\n  outptr = dest->iobuffer;\n  for (col = cinfo->output_width; col > 0; col--) {\n    outptr[0] = (char) GETJSAMPLE(inptr[2]); /* RGB to BGR order */\n    outptr[1] = (char) GETJSAMPLE(inptr[1]);\n    outptr[2] = (char) GETJSAMPLE(inptr[0]);\n    inptr += 3, outptr += 3;\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\nMETHODDEF(void)\nput_gray_rows (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t       JDIMENSION rows_supplied)\n/* used for grayscale OR quantized color output */\n{\n  tga_dest_ptr dest = (tga_dest_ptr) dinfo;\n  register JSAMPROW inptr;\n  register char * outptr;\n  register JDIMENSION col;\n\n  inptr = dest->pub.buffer[0];\n  outptr = dest->iobuffer;\n  for (col = cinfo->output_width; col > 0; col--) {\n    *outptr++ = (char) GETJSAMPLE(*inptr++);\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\n/*\n * Write some demapped pixel data when color quantization is in effect.\n * For Targa, this is only applied to grayscale data.\n */\n\nMETHODDEF(void)\nput_demapped_gray (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,\n\t\t   JDIMENSION rows_supplied)\n{\n  tga_dest_ptr dest = (tga_dest_ptr) dinfo;\n  register JSAMPROW inptr;\n  register char * outptr;\n  register JSAMPROW color_map0 = cinfo->colormap[0];\n  register JDIMENSION col;\n\n  inptr = dest->pub.buffer[0];\n  outptr = dest->iobuffer;\n  for (col = cinfo->output_width; col > 0; col--) {\n    *outptr++ = (char) GETJSAMPLE(color_map0[GETJSAMPLE(*inptr++)]);\n  }\n  (void) JFWRITE(dest->pub.output_file, dest->iobuffer, dest->buffer_width);\n}\n\n\n/*\n * Startup: write the file header.\n */\n\nMETHODDEF(void)\nstart_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  tga_dest_ptr dest = (tga_dest_ptr) dinfo;\n  int num_colors, i;\n  FILE *outfile;\n\n  if (cinfo->out_color_space == JCS_GRAYSCALE) {\n    /* Targa doesn't have a mapped grayscale format, so we will */\n    /* demap quantized gray output.  Never emit a colormap. */\n    write_header(cinfo, dinfo, 0);\n    if (cinfo->quantize_colors)\n      dest->pub.put_pixel_rows = put_demapped_gray;\n    else\n      dest->pub.put_pixel_rows = put_gray_rows;\n  } else if (cinfo->out_color_space == JCS_RGB) {\n    if (cinfo->quantize_colors) {\n      /* We only support 8-bit colormap indexes, so only 256 colors */\n      num_colors = cinfo->actual_number_of_colors;\n      if (num_colors > 256)\n\tERREXIT1(cinfo, JERR_TOO_MANY_COLORS, num_colors);\n      write_header(cinfo, dinfo, num_colors);\n      /* Write the colormap.  Note Targa uses BGR byte order */\n      outfile = dest->pub.output_file;\n      for (i = 0; i < num_colors; i++) {\n\tputc(GETJSAMPLE(cinfo->colormap[2][i]), outfile);\n\tputc(GETJSAMPLE(cinfo->colormap[1][i]), outfile);\n\tputc(GETJSAMPLE(cinfo->colormap[0][i]), outfile);\n      }\n      dest->pub.put_pixel_rows = put_gray_rows;\n    } else {\n      write_header(cinfo, dinfo, 0);\n      dest->pub.put_pixel_rows = put_pixel_rows;\n    }\n  } else {\n    ERREXIT(cinfo, JERR_TGA_COLORSPACE);\n  }\n}\n\n\n/*\n * Finish up at the end of the file.\n */\n\nMETHODDEF(void)\nfinish_output_tga (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo)\n{\n  /* Make sure we wrote the output file OK */\n  fflush(dinfo->output_file);\n  if (ferror(dinfo->output_file))\n    ERREXIT(cinfo, JERR_FILE_WRITE);\n}\n\n\n/*\n * The module selection routine for Targa format output.\n */\n\nGLOBAL(djpeg_dest_ptr)\njinit_write_targa (j_decompress_ptr cinfo)\n{\n  tga_dest_ptr dest;\n\n  /* Create module interface object, fill in method pointers */\n  dest = (tga_dest_ptr)\n      (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t  SIZEOF(tga_dest_struct));\n  dest->pub.start_output = start_output_tga;\n  dest->pub.finish_output = finish_output_tga;\n\n  /* Calculate output image dimensions so we can allocate space */\n  jpeg_calc_output_dimensions(cinfo);\n\n  /* Create I/O buffer.  Note we make this near on a PC. */\n  dest->buffer_width = cinfo->output_width * cinfo->output_components;\n  dest->iobuffer = (char *)\n    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,\n\t\t\t\t(size_t) (dest->buffer_width * SIZEOF(char)));\n\n  /* Create decompressor output buffer. */\n  dest->pub.buffer = (*cinfo->mem->alloc_sarray)\n    ((j_common_ptr) cinfo, JPOOL_IMAGE, dest->buffer_width, (JDIMENSION) 1);\n  dest->pub.buffer_height = 1;\n\n  return &dest->pub;\n}\n\n#endif /* TARGA_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libpng/ANNOUNCE",
    "content": "Libpng 1.6.25 - September 1, 2016\n\nThis is a public release of libpng, intended for use in production codes.\n\nFiles available for download:\n\nSource files with LF line endings (for Unix/Linux) and with a\n\"configure\" script\n\n   libpng-1.6.25.tar.xz (LZMA-compressed, recommended)\n   libpng-1.6.25.tar.gz\n\nSource files with CRLF line endings (for Windows), without the\n\"configure\" script\n\n   lpng1625.7z  (LZMA-compressed, recommended)\n   lpng1625.zip\n\nOther information:\n\n   libpng-1.6.25-README.txt\n   libpng-1.6.25-LICENSE.txt\n   libpng-1.6.25-*.asc (armored detached GPG signatures)\n\nChanges since the last public release (1.6.24):\n  Reject oversized iCCP profile immediately.\n  Cleaned up PNG_DEBUG compile of pngtest.c.\n  Conditionally compile png_inflate().\n  Don't install pngcp; it conflicts with pngcp in the pngtools package.\n  Minor editing of INSTALL, (whitespace, added copyright line)\n  Added MIPS support (Mandar Sahastrabuddhe <Mandar.Sahastrabuddhe@imgtec.com>).\n  Rebased contrib/intel/intel_sse.patch after the MIPS implementation.\n\n(subscription required; visit\nhttps://lists.sourceforge.net/lists/listinfo/png-mng-implement\nto subscribe)\nor to glennrp at users.sourceforge.net\n\nGlenn R-P\n"
  },
  {
    "path": "tess-two/jni/libpng/Android.bp",
    "content": "// We need to build this for both the device (as a shared library)\n// and the host (as a static library for tools to use).\n\ncc_defaults {\n    name: \"libpng-defaults\",\n    srcs: [\n        \"png.c\",\n        \"pngerror.c\",\n        \"pngget.c\",\n        \"pngmem.c\",\n        \"pngpread.c\",\n        \"pngread.c\",\n        \"pngrio.c\",\n        \"pngrtran.c\",\n        \"pngrutil.c\",\n        \"pngset.c\",\n        \"pngtrans.c\",\n        \"pngwio.c\",\n        \"pngwrite.c\",\n        \"pngwtran.c\",\n        \"pngwutil.c\",\n    ],\n    cflags: [\n        \"-std=gnu89\",\n        \"-Wno-unused-parameter\",\n    ],\n    arch: {\n        arm: {\n            srcs: [\n                \"arm/arm_init.c\",\n                \"arm/filter_neon.S\",\n                \"arm/filter_neon_intrinsics.c\",\n            ],\n        },\n        arm64: {\n            srcs: [\n                \"arm/arm_init.c\",\n                \"arm/filter_neon.S\",\n                \"arm/filter_neon_intrinsics.c\",\n            ],\n        },\n        x86: {\n            srcs: [\n                \"contrib/intel/intel_init.c\",\n                \"contrib/intel/filter_sse2_intrinsics.c\",\n            ],\n            // Disable optimizations because they crash on windows\n            // cflags: [\"-DPNG_INTEL_SSE_OPT=1\"],\n        },\n        x86_64: {\n            srcs: [\n                \"contrib/intel/intel_init.c\",\n                \"contrib/intel/filter_sse2_intrinsics.c\",\n            ],\n            // Disable optimizations because they crash on windows\n            // cflags: [\"-DPNG_INTEL_SSE_OPT=1\"],\n        },\n    },\n    target: {\n        android: {\n            shared_libs: [\"libz\"],\n        },\n        android_x86: {\n            cflags: [\"-DPNG_INTEL_SSE_OPT=1\"],\n        },\n        android_x86_64: {\n            cflags: [\"-DPNG_INTEL_SSE_OPT=1\"],\n        },\n        host: {\n            shared_libs: [\"libz-host\"],\n        },\n    },\n    export_include_dirs: [\".\"],\n    clang: true,\n}\n\n// For the host and device platform\n// =====================================================\n\ncc_library {\n    name: \"libpng\",\n    host_supported: true,\n    defaults: [\"libpng-defaults\"],\n    target: {\n        windows: {\n            enabled: true,\n        },\n    },\n}\n\n// For the device (static) for NDK\n// =====================================================\n\ncc_library_static {\n    name: \"libpng_ndk\",\n    defaults: [\"libpng-defaults\"],\n    cflags: [\"-ftrapv\"],\n\n    shared_libs: [\"libz\"],\n    sdk_version: \"14\",\n}\n\n// For testing\n// =====================================================\n\ncc_test {\n    clang: true,\n    host_supported: true,\n    gtest: false,\n    srcs: [\"pngtest.c\"],\n    name: \"pngtest\",\n    shared_libs: [\n        \"libpng\",\n    ],\n    target: {\n        android: {\n            shared_libs: [\"libz\"],\n        },\n        host: {\n            shared_libs: [\"libz-host\"],\n        },\n    },\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/Android.mk",
    "content": "LOCAL_PATH:= $(call my-dir)\n\ncommon_SRC_FILES := \\\n\tpng.c \\\n\tpngerror.c \\\n\tpngget.c \\\n\tpngmem.c \\\n\tpngpread.c \\\n\tpngread.c \\\n\tpngrio.c \\\n\tpngrtran.c \\\n\tpngrutil.c \\\n\tpngset.c \\\n\tpngtrans.c \\\n\tpngwio.c \\\n\tpngwrite.c \\\n\tpngwtran.c \\\n\tpngwutil.c \\\n\nifeq ($(ARCH_ARM_HAVE_NEON),true)\nmy_cflags_arm := -DPNG_ARM_NEON_OPT=2\nendif\n\nmy_cflags_arm64 := -DPNG_ARM_NEON_OPT=2\n\nmy_src_files_arm := \\\n\t\t\tarm/arm_init.c \\\n\t\t\tarm/filter_neon.S \\\n\t\t\tarm/filter_neon_intrinsics.c\n\n\ncommon_CFLAGS := -std=gnu89 #-fvisibility=hidden ## -fomit-frame-pointer\n\ninclude $(CLEAR_VARS)\nLOCAL_CLANG := true\nLOCAL_SRC_FILES := $(common_SRC_FILES)\nLOCAL_CFLAGS += $(common_CFLAGS) -ftrapv\nLOCAL_CFLAGS_arm := $(my_cflags_arm)\nLOCAL_ASFLAGS += $(common_ASFLAGS)\nLOCAL_SRC_FILES_arm := $(my_src_files_arm)\nLOCAL_CFLAGS_arm64 := $(my_cflags_arm64)\nLOCAL_SRC_FILES_arm64 := $(my_src_files_arm)\nLOCAL_SANITIZE := never\nLOCAL_EXPORT_C_INCLUDE_DIRS := $(LOCAL_PATH)\nLOCAL_EXPORT_LDLIBS := -lz\nLOCAL_MODULE:= libpngt_static\ninclude $(BUILD_STATIC_LIBRARY)"
  },
  {
    "path": "tess-two/jni/libpng/CHANGES",
    "content": "#if 0\nCHANGES - changes for libpng\n\nversion 0.1 [March 29, 1995]\n  initial work-in-progress release\n\nversion 0.2 [April 1, 1995]\n  added reader into png.h\n  fixed small problems in stub file\n\nversion 0.3 [April 8, 1995]\n  added pull reader\n  split up pngwrite.c to several files\n  added pnglib.txt\n  added example.c\n  cleaned up writer, adding a few new transformations\n  fixed some bugs in writer\n  interfaced with zlib 0.5\n  added K&R support\n  added check for 64 KB blocks for 16 bit machines\n\nversion 0.4 [April 26, 1995]\n  cleaned up code and commented code\n  simplified time handling into png_time\n  created png_color_16 and png_color_8 to handle color needs\n  cleaned up color type defines\n  fixed various bugs\n  made various names more consistent\n  interfaced with zlib 0.71\n  cleaned up zTXt reader and writer (using zlib's Reset functions)\n  split transformations into pngrtran.c and pngwtran.c\n\nversion 0.5 [April 30, 1995]\n  interfaced with zlib 0.8\n  fixed many reading and writing bugs\n  saved using 3 spaces instead of tabs\n\nversion 0.6 [May 1, 1995]\n  first beta release\n  added png_large_malloc() and png_large_free()\n  added png_size_t\n  cleaned up some compiler warnings\n  added png_start_read_image()\n\nversion 0.7 [June 24, 1995]\n  cleaned up lots of bugs\n  finished dithering and other stuff\n  added test program\n  changed name from pnglib to libpng\n\nversion 0.71 [June 26, 1995]\n  changed pngtest.png for zlib 0.93\n  fixed error in libpng.txt and example.c\n\nversion 0.8 [August 20, 1995]\n  cleaned up some bugs\n  added png_set_filler()\n  split up pngstub.c into pngmem.c, pngio.c, and pngerror.c\n  added #define's to remove unwanted code\n  moved png_info_init() to png.c\n  added old_size into png_realloc()\n  added functions to manually set filtering and compression info\n  changed compression parameters based on image type\n  optimized filter selection code\n  added version info\n  changed external functions passing floats to doubles (k&r problems?)\n  put all the configurable stuff in pngconf.h\n  enabled png_set_shift to work with paletted images on read\n  added png_read_update_info() - updates info structure with transformations\n\nVersion 0.81 [August, 1995]\n  incorporated Tim Wegner's medium model code (thanks, Tim)\n\nVersion 0.82 [September, 1995]\n  [unspecified changes]\n\nVersion 0.85 [December, 1995]\n  added more medium model code (almost everything's a far)\n  added i/o, error, and memory callback functions\n  fixed some bugs (16-bit, 4-bit interlaced, etc.)\n  added first run progressive reader (barely tested)\n\nVersion 0.86 [January, 1996]\n  fixed bugs\n  improved documentation\n\nVersion 0.87 [January, 1996]\n  fixed medium model bugs\n  fixed other bugs introduced in 0.85 and 0.86\n  added some minor documentation\n\nVersion 0.88 [January, 1996]\n  fixed progressive bugs\n  replaced tabs with spaces\n  cleaned up documentation\n  added callbacks for read/write and warning/error functions\n\nVersion 0.89 [June 5, 1996]\n  Added new initialization API to make libpng work better with shared libs\n    we now have png_create_read_struct(), png_create_write_struct(),\n    png_create_info_struct(), png_destroy_read_struct(), and\n    png_destroy_write_struct() instead of the separate calls to\n    malloc and png_read_init(), png_info_init(), and png_write_init()\n  Changed warning/error callback functions to fix bug - this means you\n    should use the new initialization API if you were using the old\n    png_set_message_fn() calls, and that the old API no longer exists\n    so that people are aware that they need to change their code\n  Changed filter selection API to allow selection of multiple filters\n    since it didn't work in previous versions of libpng anyways\n  Optimized filter selection code\n  Fixed png_set_background() to allow using an arbitrary RGB color for\n    paletted images\n  Fixed gamma and background correction for paletted images, so\n    png_correct_palette is not needed unless you are correcting an\n    external palette (you will need to #define PNG_CORRECT_PALETTE_SUPPORTED\n    in pngconf.h) - if nobody uses this, it may disappear in the future.\n  Fixed bug with Borland 64K memory allocation (Alexander Lehmann)\n  Fixed bug in interlace handling (Smarasderagd, I think)\n  Added more error checking for writing and image to reduce invalid files\n  Separated read and write functions so that they won't both be linked\n    into a binary when only reading or writing functionality is used\n  New pngtest image also has interlacing and zTXt\n  Updated documentation to reflect new API\n\nVersion 0.89c [June 17, 1996]\n  Bug fixes.\n\nVersion 0.90 [January, 1997]\n  Made CRC errors/warnings on critical and ancillary chunks configurable\n  libpng will use the zlib CRC routines by (compile-time) default\n  Changed DOS small/medium model memory support - needs zlib 1.04 (Tim Wegner)\n  Added external C++ wrapper statements to png.h (Gilles Dauphin)\n  Allow PNG file to be read when some or all of file signature has already\n    been read from the beginning of the stream.  ****This affects the size\n    of info_struct and invalidates all programs that use a shared libpng****\n  Fixed png_filler() declarations\n  Fixed? background color conversions\n  Fixed order of error function pointers to match documentation\n  Current chunk name is now available in png_struct to reduce the number\n    of nearly identical error messages (will simplify multi-lingual\n    support when available)\n  Try to get ready for unknown-chunk callback functions:\n    - previously read critical chunks are flagged, so the chunk handling\n      routines can determine if the chunk is in the right place\n    - all chunk handling routines have the same prototypes, so we will\n      be able to handle all chunks via a callback mechanism\n  Try to fix Linux \"setjmp\" buffer size problems\n  Removed png_large_malloc, png_large_free, and png_realloc functions.\n\nVersion 0.95 [March, 1997]\n  Fixed bug in pngwutil.c allocating \"up_row\" twice and \"avg_row\" never\n  Fixed bug in PNG file signature compares when start != 0\n  Changed parameter type of png_set_filler(...filler...) from png_byte\n    to png_uint_32\n  Added test for MACOS to ensure that both math.h and fp.h are not #included\n  Added macros for libpng to be compiled as a Windows DLL (Andreas Kupries)\n  Added \"packswap\" transformation, which changes the endianness of\n    packed-pixel bytes (Kevin Bracey)\n  Added \"strip_alpha\" transformation, which removes the alpha channel of\n    input images without using it (not necessarily a good idea)\n  Added \"swap_alpha\" transformation, which puts the alpha channel in front\n    of the color bytes instead of after\n  Removed all implicit variable tests which assume NULL == 0 (I think)\n  Changed several variables to \"png_size_t\" to show 16/32-bit limitations\n  Added new pCAL chunk read/write support\n  Added experimental filter selection weighting (Greg Roelofs)\n  Removed old png_set_rgbx() and png_set_xrgb() functions that have been\n    obsolete for about 2 years now (use png_set_filler() instead)\n  Added macros to read 16- and 32-bit ints directly from buffer, to be\n    used only on those systems that support it (namely PowerPC and 680x0)\n    With some testing, this may become the default for MACOS/PPC systems.\n  Only calculate CRC on data if we are going to use it\n  Added macros for zTXt compression type PNG_zTXt_COMPRESSION_???\n  Added macros for simple libpng debugging output selectable at compile time\n  Removed PNG_READ_END_MODE in progressive reader (Smarasderagd)\n  More description of info_struct in libpng.txt and png.h\n  More instructions in example.c\n  More chunk types tested in pngtest.c\n  Renamed pngrcb.c to pngset.c, and all png_read_<chunk> functions to be\n    png_set_<chunk>.  We now have corresponding png_get_<chunk>\n    functions in pngget.c to get information in info_ptr.  This isolates\n    the application from the internal organization of png_info_struct\n    (good for shared library implementations).\n\nVersion 0.96 [May, 1997]\n  Fixed serious bug with < 8bpp images introduced in 0.95\n  Fixed 256-color transparency bug (Greg Roelofs)\n  Fixed up documentation (Greg Roelofs, Laszlo Nyul)\n  Fixed \"error\" in pngconf.h for Linux setjmp() behavior\n  Fixed DOS medium model support (Tim Wegner)\n  Fixed png_check_keyword() for case with error in static string text\n  Added read of CRC after IEND chunk for embedded PNGs (Laszlo Nyul)\n  Added typecasts to quiet compiler errors\n  Added more debugging info\n\nVersion 0.97 [January, 1998]\n  Removed PNG_USE_OWN_CRC capability\n  Relocated png_set_crc_action from pngrutil.c to pngrtran.c\n  Fixed typecasts of \"new_key\", etc. (Andreas Dilger)\n  Added RFC 1152 [sic] date support\n  Fixed bug in gamma handling of 4-bit grayscale\n  Added 2-bit grayscale gamma handling (Glenn R-P)\n  Added more typecasts. 65536L becomes (png_uint_32)65536L, etc. (Glenn R-P)\n  Minor corrections in libpng.txt\n  Added simple sRGB support (Glenn R-P)\n  Easier conditional compiling, e.g.,\n    define PNG_READ/WRITE_NOT_FULLY_SUPPORTED;\n    all configurable options can be selected from command-line instead\n    of having to edit pngconf.h (Glenn R-P)\n  Fixed memory leak in pngwrite.c (free info_ptr->text) (Glenn R-P)\n  Added more conditions for png_do_background, to avoid changing\n    black pixels to background when a background is supplied and\n    no pixels are transparent\n  Repaired PNG_NO_STDIO behavior\n  Tested NODIV support and made it default behavior (Greg Roelofs)\n  Added \"-m\" option and PNGTEST_DEBUG_MEMORY to pngtest (John Bowler)\n  Regularized version numbering scheme and bumped shared-library major\n    version number to 2 to avoid problems with libpng 0.89 apps\n    (Greg Roelofs)\n\nVersion 0.98 [January, 1998]\n  Cleaned up some typos in libpng.txt and in code documentation\n  Fixed memory leaks in pCAL chunk processing (Glenn R-P and John Bowler)\n  Cosmetic change \"display_gamma\" to \"screen_gamma\" in pngrtran.c\n  Changed recommendation about file_gamma for PC images to .51 from .45,\n    in example.c and libpng.txt, added comments to distinguish between\n    screen_gamma, viewing_gamma, and display_gamma.\n  Changed all references to RFC1152 to read RFC1123 and changed the\n    PNG_TIME_RFC1152_SUPPORTED macro to PNG_TIME_RFC1123_SUPPORTED\n  Added png_invert_alpha capability (Glenn R-P -- suggestion by Jon Vincent)\n  Changed srgb_intent from png_byte to int to avoid compiler bugs\n\nVersion 0.99 [January 30, 1998]\n  Free info_ptr->text instead of end_info_ptr->text in pngread.c (John Bowler)\n  Fixed a longstanding \"packswap\" bug in pngtrans.c\n  Fixed some inconsistencies in pngconf.h that prevented compiling with\n    PNG_READ_GAMMA_SUPPORTED and PNG_READ_hIST_SUPPORTED undefined\n  Fixed some typos and made other minor rearrangement of libpng.txt (Andreas)\n  Changed recommendation about file_gamma for PC images to .50 from .51 in\n    example.c and libpng.txt, and changed file_gamma for sRGB images to .45\n  Added a number of functions to access information from the png structure\n    png_get_image_height(), etc. (Glenn R-P, suggestion by Brad Pettit)\n  Added TARGET_MACOS similar to zlib-1.0.8\n  Define PNG_ALWAYS_EXTERN when __MWERKS__ && WIN32 are defined\n  Added type casting to all png_malloc() function calls\n\nVersion 0.99a [January 31, 1998]\n  Added type casts and parentheses to all returns that return a value.(Tim W.)\n\nVersion 0.99b [February 4, 1998]\n  Added type cast png_uint_32 on malloc function calls where needed.\n  Changed type of num_hist from png_uint_32 to int (same as num_palette).\n  Added checks for rowbytes overflow, in case png_size_t is less than 32 bits.\n  Renamed makefile.elf to makefile.lnx.\n\nVersion 0.99c [February 7, 1998]\n  More type casting.  Removed erroneous overflow test in pngmem.c.\n  Added png_buffered_memcpy() and png_buffered_memset(), apply them to rowbytes.\n  Added UNIX manual pages libpng.3 (incorporating libpng.txt) and  png.5.\n\nVersion 0.99d [February 11, 1998]\n  Renamed \"far_to_near()\" \"png_far_to_near()\"\n  Revised libpng.3\n  Version 99c \"buffered\" operations didn't work as intended.  Replaced them\n    with png_memcpy_check() and png_memset_check().\n  Added many \"if (png_ptr == NULL) return\" to quell compiler warnings about\n    unused png_ptr, mostly in pngget.c and pngset.c.\n  Check for overlength tRNS chunk present when indexed-color PLTE is read.\n  Cleaned up spelling errors in libpng.3/libpng.txt\n  Corrected a problem with png_get_tRNS() which returned undefined trans array\n\nVersion 0.99e [February 28, 1998]\n  Corrected png_get_tRNS() again.\n  Add parentheses for easier reading of pngget.c, fixed \"||\" should be \"&&\".\n  Touched up example.c to make more of it compileable, although the entire\n    file still can't be compiled (Willem van Schaik)\n  Fixed a bug in png_do_shift() (Bryan Tsai)\n  Added a space in png.h prototype for png_write_chunk_start()\n  Replaced pngtest.png with one created with zlib 1.1.1\n  Changed pngtest to report PASS even when file size is different (Jean-loup G.)\n  Corrected some logic errors in png_do_invert_alpha() (Chris Patterson)\n\nVersion 0.99f [March 5, 1998]\n  Corrected a bug in pngpread() introduced in version 99c (Kevin Bracey)\n  Moved makefiles into a \"scripts\" directory, and added INSTALL instruction file\n  Added makefile.os2 and pngos2.def (A. Zabolotny) and makefile.s2x (W. Sebok)\n  Added pointers to \"note on libpng versions\" in makefile.lnx and README\n  Added row callback feature when reading and writing nonprogressive rows\n    and added a test of this feature in pngtest.c\n  Added user transform callbacks, with test of the feature in pngtest.c\n\nVersion 0.99g [March 6, 1998, morning]\n  Minor changes to pngtest.c to suppress compiler warnings.\n  Removed \"beta\" language from documentation.\n\nVersion 0.99h [March 6, 1998, evening]\n  Minor changes to previous minor changes to pngtest.c\n  Changed PNG_READ_NOT_FULLY_SUPPORTED to PNG_READ_TRANSFORMS_NOT_SUPPORTED\n    and added PNG_PROGRESSIVE_READ_NOT_SUPPORTED macro\n  Added user transform capability\n\nVersion 1.00 [March 7, 1998]\n  Changed several typedefs in pngrutil.c\n  Added makefile.wat (Pawel Mrochen), updated makefile.tc3 (Willem van Schaik)\n  Replaced \"while(1)\" with \"for(;;)\"\n  Added PNGARG() to prototypes in pngtest.c and removed some prototypes\n  Updated some of the makefiles (Tom Lane)\n  Changed some typedefs (s_start, etc.) in pngrutil.c\n  Fixed dimensions of \"short_months\" array in pngwrite.c\n  Replaced ansi2knr.c with the one from jpeg-v6\n\nVersion 1.0.0 [March 8, 1998]\n  Changed name from 1.00 to 1.0.0 (Adam Costello)\n  Added smakefile.ppc (with SCOPTIONS.ppc) for Amiga PPC (Andreas Kleinert)\n\nVersion 1.0.0a [March 9, 1998]\n  Fixed three bugs in pngrtran.c to make gamma+background handling consistent\n    (Greg Roelofs)\n  Changed format of the PNG_LIBPNG_VER integer to xyyzz instead of xyz\n    for major, minor, and bugfix releases.  This is 10001. (Adam Costello,\n    Tom Lane)\n  Make months range from 1-12 in png_convert_to_rfc1123\n\nVersion 1.0.0b [March 13, 1998]\n  Quieted compiler complaints about two empty \"for\" loops in pngrutil.c\n  Minor changes to makefile.s2x\n  Removed #ifdef/#endif around a png_free() in pngread.c\n\nVersion 1.0.1 [March 14, 1998]\n  Changed makefile.s2x to reduce security risk of using a relative pathname\n  Fixed some typos in the documentation (Greg).\n  Fixed a problem with value of \"channels\" returned by png_read_update_info()\n\nVersion 1.0.1a [April 21, 1998]\n  Optimized Paeth calculations by replacing abs() function calls with intrinsics\n  plus other loop optimizations. Improves avg decoding speed by about 20%.\n  Commented out i386istic \"align\" compiler flags in makefile.lnx.\n  Reduced the default warning level in some makefiles, to make them consistent.\n  Removed references to IJG and JPEG in the ansi2knr.c copyright statement.\n  Fixed a bug in png_do_strip_filler with XXRRGGBB => RRGGBB transformation.\n  Added grayscale and 16-bit capability to png_do_read_filler().\n  Fixed a bug in pngset.c, introduced in version 0.99c, that sets rowbytes\n    too large when writing an image with bit_depth < 8 (Bob Dellaca).\n  Corrected some bugs in the experimental weighted filtering heuristics.\n  Moved a misplaced pngrutil code block that truncates tRNS if it has more\n    than num_palette entries -- test was done before num_palette was defined.\n  Fixed a png_convert_to_rfc1123() bug that converts day 31 to 0 (Steve Eddins).\n  Changed compiler flags in makefile.wat for better optimization\n    (Pawel Mrochen).\n\nVersion 1.0.1b [May 2, 1998]\n  Relocated png_do_gray_to_rgb() within png_do_read_transformations() (Greg).\n  Relocated the png_composite macros from pngrtran.c to png.h (Greg).\n  Added makefile.sco (contributed by Mike Hopkirk).\n  Fixed two bugs (missing definitions of \"istop\") introduced in libpng-1.0.1a.\n  Fixed a bug in pngrtran.c that would set channels=5 under some circumstances.\n  More work on the Paeth-filtering, achieving imperceptible speedup\n    (A Kleinert).\n  More work on loop optimization which may help when compiled with C++\n    compilers.\n  Added warnings when people try to use transforms they've defined out.\n  Collapsed 4 \"i\" and \"c\" loops into single \"i\" loops in pngrtran and pngwtran.\n  Revised paragraph about png_set_expand() in libpng.txt and libpng.3 (Greg)\n\nVersion 1.0.1c [May 11, 1998]\n  Fixed a bug in pngrtran.c (introduced in libpng-1.0.1a) where the masks for\n    filler bytes should have been 0xff instead of 0xf.\n  Added max_pixel_depth=32 in pngrutil.c when using FILLER with palette images.\n  Moved PNG_WRITE_WEIGHTED_FILTER_SUPPORTED and PNG_WRITE_FLUSH_SUPPORTED\n    out of the PNG_WRITE_TRANSFORMS_NOT_SUPPORTED block of pngconf.h\n  Added \"PNG_NO_WRITE_TRANSFORMS\" etc., as alternatives for *_NOT_SUPPORTED,\n    for consistency, in pngconf.h\n  Added individual \"ifndef PNG_NO_[CAPABILITY]\" in pngconf.h to make it easier\n    to remove unwanted capabilities via the compile line\n  Made some corrections to grammar (which, it's) in documentation (Greg).\n  Corrected example.c, use of row_pointers in png_write_image().\n\nVersion 1.0.1d [May 24, 1998]\n  Corrected several statements that used side effects illegally in pngrutil.c\n    and pngtrans.c, that were introduced in version 1.0.1b\n  Revised png_read_rows() to avoid repeated if-testing for NULL (A Kleinert)\n  More corrections to example.c, use of row_pointers in png_write_image()\n    and png_read_rows().\n  Added pngdll.mak and pngdef.pas to scripts directory, contributed by\n    Bob Dellaca, to make a png32bd.dll with Borland C++ 4.5\n  Fixed error in example.c with png_set_text: num_text is 3, not 2 (Guido V.)\n  Changed several loops from count-down to count-up, for consistency.\n\nVersion 1.0.1e [June 6, 1998]\n  Revised libpng.txt and libpng.3 description of png_set_read|write_fn(), and\n    added warnings when people try to set png_read_fn and png_write_fn in\n    the same structure.\n  Added a test such that png_do_gamma will be done when num_trans==0\n    for truecolor images that have defined a background.  This corrects an\n    error that was introduced in libpng-0.90 that can cause gamma processing\n    to be skipped.\n  Added tests in png.h to include \"trans\" and \"trans_values\" in structures\n    when PNG_READ_BACKGROUND_SUPPORTED or PNG_READ_EXPAND_SUPPORTED is defined.\n  Add png_free(png_ptr->time_buffer) in png_destroy_read_struct()\n  Moved png_convert_to_rfc_1123() from pngwrite.c to png.c\n  Added capability for user-provided malloc_fn() and free_fn() functions,\n    and revised pngtest.c to demonstrate their use, replacing the\n    PNGTEST_DEBUG_MEM feature.\n  Added makefile.w32, for Microsoft C++ 4.0 and later (Tim Wegner).\n\nVersion 1.0.2 [June 14, 1998]\n  Fixed two bugs in makefile.bor .\n\nVersion 1.0.2a [December 30, 1998]\n  Replaced and extended code that was removed from png_set_filler() in 1.0.1a.\n  Fixed a bug in png_do_filler() that made it fail to write filler bytes in\n    the left-most pixel of each row (Kevin Bracey).\n  Changed \"static pngcharp tIME_string\" to \"static char tIME_string[30]\"\n    in pngtest.c (Duncan Simpson).\n  Fixed a bug in pngtest.c that caused pngtest to try to write a tIME chunk\n    even when no tIME chunk was present in the source file.\n  Fixed a problem in pngrutil.c: gray_to_rgb didn't always work with 16-bit.\n  Fixed a problem in png_read_push_finish_row(), which would not skip some\n    passes that it should skip, for images that are less than 3 pixels high.\n  Interchanged the order of calls to png_do_swap() and png_do_shift()\n    in pngwtran.c (John Cromer).\n  Added #ifdef PNG_DEBUG/#endif surrounding use of PNG_DEBUG in png.h .\n  Changed \"bad adaptive filter type\" from error to warning in pngrutil.c .\n  Fixed a documentation error about default filtering with 8-bit indexed-color.\n  Separated the PNG_NO_STDIO macro into PNG_NO_STDIO and PNG_NO_CONSOLE_IO\n    (L. Peter Deutsch).\n  Added png_set_rgb_to_gray() and png_get_rgb_to_gray_status() functions.\n  Added png_get_copyright() and png_get_header_version() functions.\n  Revised comments on png_set_progressive_read_fn() in libpng.txt and example.c\n  Added information about debugging in libpng.txt and libpng.3 .\n  Changed \"ln -sf\" to \"ln -s -f\" in makefile.s2x, makefile.lnx, and\n    makefile.sco.\n  Removed lines after Dynamic Dependencies\" in makefile.aco .\n  Revised makefile.dec to make a shared library (Jeremie Petit).\n  Removed trailing blanks from all files.\n\nVersion 1.0.2a [January 6, 1999]\n  Removed misplaced #endif and #ifdef PNG_NO_EXTERN near the end of png.h\n  Added \"if\" tests to silence complaints about unused png_ptr in png.h and png.c\n  Changed \"check_if_png\" function in example.c to return true (nonzero) if PNG.\n  Changed libpng.txt to demonstrate png_sig_cmp() instead of png_check_sig()\n    which is obsolete.\n\nVersion 1.0.3 [January 14, 1999]\n  Added makefile.hux, for Hewlett Packard HPUX 10.20 and 11.00 (Jim Rice)\n  Added a statement of Y2K compliance in png.h, libpng.3, and Y2KINFO.\n\nVersion 1.0.3a [August 12, 1999]\n  Added check for PNG_READ_INTERLACE_SUPPORTED in pngread.c; issue a warning\n    if an attempt is made to read an interlaced image when it's not supported.\n  Added check if png_ptr->trans is defined before freeing it in pngread.c\n  Modified the Y2K statement to include versions back to version 0.71\n  Fixed a bug in the check for valid IHDR bit_depth/color_types in pngrutil.c\n  Modified makefile.wat (added -zp8 flag, \".symbolic\", changed some comments)\n  Replaced leading blanks with tab characters in makefile.hux\n  Changed \"dworkin.wustl.edu\" to \"ccrc.wustl.edu\" in various documents.\n  Changed (float)red and (float)green to (double)red, (double)green\n    in png_set_rgb_to_gray() to avoid \"promotion\" problems in AIX.\n  Fixed a bug in pngconf.h that omitted <stdio.h> when PNG_DEBUG==0 (K Bracey).\n  Reformatted libpng.3 and libpngpf.3 with proper fonts (script by J. vanZandt).\n  Updated documentation to refer to the PNG-1.2 specification.\n  Removed ansi2knr.c and left pointers to the latest source for ansi2knr.c\n    in makefile.knr, INSTALL, and README (L. Peter Deutsch)\n  Fixed bugs in calculation of the length of rowbytes when adding alpha\n    channels to 16-bit images, in pngrtran.c (Chris Nokleberg)\n  Added function png_set_user_transform_info() to store user_transform_ptr,\n    user_depth, and user_channels into the png_struct, and a function\n    png_get_user_transform_ptr() to retrieve the pointer (Chris Nokleberg)\n  Added function png_set_empty_plte_permitted() to make libpng useable\n    in MNG applications.\n  Corrected the typedef for png_free_ptr in png.h (Jesse Jones).\n  Correct gamma with srgb is 45455 instead of 45000 in pngrutil.c, to be\n    consistent with PNG-1.2, and allow variance of 500 before complaining.\n  Added assembler code contributed by Intel in file pngvcrd.c and modified\n    makefile.w32 to use it (Nirav Chhatrapati, INTEL Corporation,\n    Gilles Vollant)\n  Changed \"ln -s -f\" to \"ln -f -s\" in the makefiles to make Solaris happy.\n  Added some aliases for png_set_expand() in pngrtran.c, namely\n    png_set_expand_PLTE(), png_set_expand_depth(), and png_set_expand_tRNS()\n    (Greg Roelofs, in \"PNG: The Definitive Guide\").\n  Added makefile.beo for BEOS on X86, contributed by Sander Stok.\n\nVersion 1.0.3b [August 26, 1999]\n  Replaced 2147483647L several places with PNG_MAX_UINT macro, defined in png.h\n  Changed leading blanks to tabs in all makefiles.\n  Define PNG_USE_PNGVCRD in makefile.w32, to get MMX assembler code.\n  Made alternate versions of  png_set_expand() in pngrtran.c, namely\n    png_set_gray_1_2_4_to_8, png_set_palette_to_rgb, and png_set_tRNS_to_alpha\n    (Greg Roelofs, in \"PNG: The Definitive Guide\").  Deleted the 1.0.3a aliases.\n  Relocated start of 'extern \"C\"' block in png.h so it doesn't include pngconf.h\n  Revised calculation of num_blocks in pngmem.c to avoid a potentially\n    negative shift distance, whose results are undefined in the C language.\n  Added a check in pngset.c to prevent writing multiple tIME chunks.\n  Added a check in pngwrite.c to detect invalid small window_bits sizes.\n\nVersion 1.0.3d [September 4, 1999]\n  Fixed type casting of igamma in pngrutil.c\n  Added new png_expand functions to scripts/pngdef.pas and pngos2.def\n  Added a demo read_user_transform_fn that examines the row filters in pngtest.c\n\nVersion 1.0.4 [September 24, 1999, not distributed publicly]\n  Define PNG_ALWAYS_EXTERN in pngconf.h if __STDC__ is defined\n  Delete #define PNG_INTERNAL and include \"png.h\" from pngasmrd.h\n  Made several minor corrections to pngtest.c\n  Renamed the makefiles with longer but more user friendly extensions.\n  Copied the PNG copyright and license to a separate LICENSE file.\n  Revised documentation, png.h, and example.c to remove reference to\n    \"viewing_gamma\" which no longer appears in the PNG specification.\n  Revised pngvcrd.c to use MMX code for interlacing only on the final pass.\n  Updated pngvcrd.c to use the faster C filter algorithms from libpng-1.0.1a\n  Split makefile.win32vc into two versions, makefile.vcawin32 (uses MMX\n    assembler code) and makefile.vcwin32 (doesn't).\n  Added a CPU timing report to pngtest.c (enabled by defining PNGTEST_TIMING)\n  Added a copy of pngnow.png to the distribution.\n\nVersion 1.0.4a [September 25, 1999]\n  Increase max_pixel_depth in pngrutil.c if a user transform needs it.\n  Changed several division operations to right-shifts in pngvcrd.c\n\nVersion 1.0.4b [September 30, 1999]\n  Added parentheses in line 3732 of pngvcrd.c\n  Added a comment in makefile.linux warning about buggy -O3 in pgcc 2.95.1\n\nVersion 1.0.4c [October 1, 1999]\n  Added a \"png_check_version\" function in png.c and pngtest.c that will generate\n    a helpful compiler error if an old png.h is found in the search path.\n  Changed type of png_user_transform_depth|channels from int to png_byte.\n  Added \"Libpng is OSI Certified Open Source Software\" statement to png.h\n\nVersion 1.0.4d [October 6, 1999]\n  Changed 0.45 to 0.45455 in png_set_sRGB()\n  Removed unused PLTE entries from pngnow.png\n  Re-enabled some parts of pngvcrd.c (png_combine_row) that work properly.\n\nVersion 1.0.4e [October 10, 1999]\n  Fixed sign error in pngvcrd.c (Greg Roelofs)\n  Replaced some instances of memcpy with simple assignments in pngvcrd (GR-P)\n\nVersion 1.0.4f [October 15, 1999]\n  Surrounded example.c code with #if 0 .. #endif to prevent people from\n    inadvertently trying to compile it.\n  Changed png_get_header_version() from a function to a macro in png.h\n  Added type casting mostly in pngrtran.c and pngwtran.c\n  Removed some pointless \"ptr = NULL\" in pngmem.c\n  Added a \"contrib\" directory containing the source code from Greg's book.\n\nVersion 1.0.5 [October 15, 1999]\n  Minor editing of the INSTALL and README files.\n\nVersion 1.0.5a [October 23, 1999]\n  Added contrib/pngsuite and contrib/pngminus (Willem van Schaik)\n  Fixed a typo in the png_set_sRGB() function call in example.c (Jan Nijtmans)\n  Further optimization and bugfix of pngvcrd.c\n  Revised pngset.c so that it does not allocate or free memory in the user's\n    text_ptr structure.  Instead, it makes its own copy.\n  Created separate write_end_info_struct in pngtest.c for a more severe test.\n  Added code in pngwrite.c to free info_ptr->text[i].key to stop a memory leak.\n\nVersion 1.0.5b [November 23, 1999]\n  Moved PNG_FLAG_HAVE_CHUNK_HEADER, PNG_FLAG_BACKGROUND_IS_GRAY and\n    PNG_FLAG_WROTE_tIME from flags to mode.\n  Added png_write_info_before_PLTE() function.\n  Fixed some typecasting in contrib/gregbook/*.c\n  Updated scripts/makevms.com and added makevms.com to contrib/gregbook\n    and contrib/pngminus (Martin Zinser)\n\nVersion 1.0.5c [November 26, 1999]\n  Moved png_get_header_version from png.h to png.c, to accommodate ansi2knr.\n  Removed all global arrays (according to PNG_NO_GLOBAL_ARRAYS macro), to\n    accommodate making DLL's: Moved usr_png_ver from global variable to function\n    png_get_header_ver() in png.c.  Moved png_sig to png_sig_bytes in png.c and\n    eliminated use of png_sig in pngwutil.c.  Moved the various png_CHNK arrays\n    into pngtypes.h.  Eliminated use of global png_pass arrays.  Declared the\n    png_CHNK and png_pass arrays to be \"const\".  Made the global arrays\n    available to applications (although none are used in libpng itself) when\n    PNG_NO_GLOBAL_ARRAYS is not defined or when PNG_GLOBAL_ARRAYS is defined.\n  Removed some extraneous \"-I\" from contrib/pngminus/makefile.std\n  Changed the PNG_sRGB_INTENT macros in png.h to be consistent with PNG-1.2.\n  Change PNG_SRGB_INTENT to PNG_sRGB_INTENT in libpng.txt and libpng.3\n\nVersion 1.0.5d [November 29, 1999]\n  Add type cast (png_const_charp) two places in png.c\n  Eliminated pngtypes.h; use macros instead to declare PNG_CHNK arrays.\n  Renamed \"PNG_GLOBAL_ARRAYS\" to \"PNG_USE_GLOBAL_ARRAYS\" and made available\n    to applications a macro \"PNG_USE_LOCAL_ARRAYS\".\n  comment out (with #ifdef) all the new declarations when\n    PNG_USE_GLOBAL_ARRAYS is defined.\n  Added PNG_EXPORT_VAR macro to accommodate making DLL's.\n\nVersion 1.0.5e [November 30, 1999]\n  Added iCCP, iTXt, and sPLT support; added \"lang\" member to the png_text\n    structure; refactored the inflate/deflate support to make adding new chunks\n    with trailing compressed parts easier in the future, and added new functions\n    png_free_iCCP, png_free_pCAL, png_free_sPLT, png_free_text, png_get_iCCP,\n    png_get_spalettes, png_set_iCCP, png_set_spalettes (Eric S. Raymond).\n  NOTE: Applications that write text chunks MUST define png_text->lang\n    before calling png_set_text(). It must be set to NULL if you want to\n    write tEXt or zTXt chunks.  If you want your application to be able to\n    run with older versions of libpng, use\n\n      #ifdef PNG_iTXt_SUPPORTED\n         png_text[i].lang = NULL;\n      #endif\n\n  Changed png_get_oFFs() and png_set_oFFs() to use signed rather than unsigned\n    offsets (Eric S. Raymond).\n  Combined PNG_READ_cHNK_SUPPORTED and PNG_WRITE_cHNK_SUPPORTED macros into\n    PNG_cHNK_SUPPORTED and combined the three types of PNG_text_SUPPORTED\n    macros, leaving the separate macros also available.\n  Removed comments on #endifs at the end of many short, non-nested #if-blocks.\n\nVersion 1.0.5f [December 6, 1999]\n  Changed makefile.solaris to issue a warning about potential problems when\n    the ucb \"ld\" is in the path ahead of the ccs \"ld\".\n  Removed \"- [date]\" from the \"synopsis\" line in libpng.3 and libpngpf.3.\n  Added sCAL chunk support (Eric S. Raymond).\n\nVersion 1.0.5g [December 7, 1999]\n  Fixed \"png_free_spallettes\" typo in png.h\n  Added code to handle new chunks in pngpread.c\n  Moved PNG_CHNK string macro definitions outside of PNG_NO_EXTERN block\n  Added \"translated_key\" to png_text structure and png_write_iTXt().\n  Added code in pngwrite.c to work around a newly discovered zlib bug.\n\nVersion 1.0.5h [December 10, 1999]\n  NOTE: regarding the note for version 1.0.5e, the following must also\n    be included in your code:\n        png_text[i].translated_key = NULL;\n  Unknown chunk handling is now supported.\n  Option to eliminate all floating point support was added.  Some new\n    fixed-point functions such as png_set_gAMA_fixed() were added.\n  Expanded tabs and removed trailing blanks in source files.\n\nVersion 1.0.5i [December 13, 1999]\n  Added some type casts to silence compiler warnings.\n  Renamed \"png_free_spalette\" to \"png_free_spalettes\" for consistency.\n  Removed leading blanks from a #define in pngvcrd.c\n  Added some parameters to the new png_set_keep_unknown_chunks() function.\n  Added a test for up->location != 0 in the first instance of writing\n    unknown chunks in pngwrite.c\n  Changed \"num\" to \"i\" in png_free_spalettes() and png_free_unknowns() to\n    prevent recursion.\n  Added png_free_hIST() function.\n  Various patches to fix bugs in the sCAL and integer cHRM processing,\n    and to add some convenience macros for use with sCAL.\n\nVersion 1.0.5j [December 21, 1999]\n  Changed \"unit\" parameter of png_write_sCAL from png_byte to int, to work\n    around buggy compilers.\n  Added new type \"png_fixed_point\" for integers that hold float*100000 values\n  Restored backward compatibility of tEXt/zTXt chunk processing:\n    Restored the first four members of png_text to the same order as v.1.0.5d.\n    Added members \"lang_key\" and \"itxt_length\" to png_text struct.  Set\n    text_length=0 when \"text\" contains iTXt data.  Use the \"compression\"\n    member to distinguish among tEXt/zTXt/iTXt types.  Added\n    PNG_ITXT_COMPRESSION_NONE (1) and PNG_ITXT_COMPRESSION_zTXt(2) macros.\n    The \"Note\" above, about backward incompatibility of libpng-1.0.5e, no\n    longer applies.\n  Fixed png_read|write_iTXt() to read|write parameters in the right order,\n    and to write the iTXt chunk after IDAT if it appears in the end_ptr.\n  Added pnggccrd.c, version of pngvcrd.c Intel assembler for gcc (Greg Roelofs)\n  Reversed the order of trying to write floating-point and fixed-point gAMA.\n\nVersion 1.0.5k [December 27, 1999]\n  Added many parentheses, e.g., \"if (a && b & c)\" becomes \"if (a && (b & c))\"\n  Added png_handle_as_unknown() function (Glenn)\n  Added png_free_chunk_list() function and chunk_list and num_chunk_list members\n    of png_ptr.\n  Eliminated erroneous warnings about multiple sPLT chunks and sPLT-after-PLTE.\n  Fixed a libpng-1.0.5h bug in pngrutil.c that was issuing erroneous warnings\n    about ignoring incorrect gAMA with sRGB (gAMA was in fact not ignored)\n  Added png_free_tRNS(); png_set_tRNS() now malloc's its own trans array (ESR).\n  Define png_get_int_32 when oFFs chunk is supported as well as when pCAL is.\n  Changed type of proflen from png_int_32 to png_uint_32 in png_get_iCCP().\n\nVersion 1.0.5l [January 1, 2000]\n  Added functions png_set_read_user_chunk_fn() and png_get_user_chunk_ptr()\n    for setting a callback function to handle unknown chunks and for\n    retrieving the associated user pointer (Glenn).\n\nVersion 1.0.5m [January 7, 2000]\n  Added high-level functions png_read_png(), png_write_png(), png_free_pixels().\n\nVersion 1.0.5n [January 9, 2000]\n  Added png_free_PLTE() function, and modified png_set_PLTE() to malloc its\n    own memory for info_ptr->palette.  This makes it safe for the calling\n    application to free its copy of the palette any time after it calls\n    png_set_PLTE().\n\nVersion 1.0.5o [January 20, 2000]\n  Cosmetic changes only (removed some trailing blanks and TABs)\n\nVersion 1.0.5p [January 31, 2000]\n  Renamed pngdll.mak to makefile.bd32\n  Cosmetic changes in pngtest.c\n\nVersion 1.0.5q [February 5, 2000]\n  Relocated the makefile.solaris warning about PATH problems.\n  Fixed pngvcrd.c bug by pushing/popping registers in mmxsupport (Bruce Oberg)\n  Revised makefile.gcmmx\n  Added PNG_SETJMP_SUPPORTED, PNG_SETJMP_NOT_SUPPORTED, and PNG_ABORT() macros\n\nVersion 1.0.5r [February 7, 2000]\n  Removed superfluous prototype for png_get_itxt from png.h\n  Fixed a bug in pngrtran.c that improperly expanded the background color.\n  Return *num_text=0 from png_get_text() when appropriate, and fix documentation\n    of png_get_text() in libpng.txt/libpng.3.\n\nVersion 1.0.5s [February 18, 2000]\n  Added \"png_jmp_env()\" macro to pngconf.h, to help people migrate to the\n    new error handler that's planned for the next libpng release, and changed\n    example.c, pngtest.c, and contrib programs to use this macro.\n  Revised some of the DLL-export macros in pngconf.h (Greg Roelofs)\n  Fixed a bug in png_read_png() that caused it to fail to expand some images\n    that it should have expanded.\n  Fixed some mistakes in the unused and undocumented INCH_CONVERSIONS functions\n    in pngget.c\n  Changed the allocation of palette, history, and trans arrays back to\n    the version 1.0.5 method (linking instead of copying) which restores\n    backward compatibility with version 1.0.5.  Added some remarks about\n    that in example.c.  Added \"free_me\" member to info_ptr and png_ptr\n    and added png_free_data() function.\n  Updated makefile.linux and makefile.gccmmx to make directories conditionally.\n  Made cosmetic changes to pngasmrd.h\n  Added png_set_rows() and png_get_rows(), for use with png_read|write_png().\n  Modified png_read_png() to allocate info_ptr->row_pointers only if it\n    hasn't already been allocated.\n\nVersion 1.0.5t [March 4, 2000]\n  Changed png_jmp_env() migration aiding macro to png_jmpbuf().\n  Fixed \"interlace\" typo (should be \"interlaced\") in contrib/gregbook/read2-x.c\n  Fixed bug with use of PNG_BEFORE_IHDR bit in png_ptr->mode, introduced when\n    PNG_FLAG_HAVE_CHUNK_HEADER was moved into png_ptr->mode in version 1.0.5b\n  Files in contrib/gregbook were revised to use png_jmpbuf() and to select\n    a 24-bit visual if one is available, and to allow abbreviated options.\n  Files in contrib/pngminus were revised to use the png_jmpbuf() macro.\n  Removed spaces in makefile.linux and makefile.gcmmx, introduced in 1.0.5s\n\nVersion 1.0.5u [March 5, 2000]\n  Simplified the code that detects old png.h in png.c and pngtest.c\n  Renamed png_spalette (_p, _pp) to png_sPLT_t (_tp, _tpp)\n  Increased precision of rgb_to_gray calculations from 8 to 15 bits and\n    added png_set_rgb_to_gray_fixed() function.\n  Added makefile.bc32 (32-bit Borland C++, C mode)\n\nVersion 1.0.5v [March 11, 2000]\n  Added some parentheses to the png_jmpbuf macro definition.\n  Updated references to the zlib home page, which has moved to freesoftware.com.\n  Corrected bugs in documentation regarding png_read_row() and png_write_row().\n  Updated documentation of png_rgb_to_gray calculations in libpng.3/libpng.txt.\n  Renamed makefile.borland,turboc3 back to makefile.bor,tc3 as in version 1.0.3,\n    revised borland makefiles; added makefile.ibmvac3 and makefile.gcc (Cosmin)\n\nVersion 1.0.6 [March 20, 2000]\n  Minor revisions of makefile.bor, libpng.txt, and gregbook/rpng2-win.c\n  Added makefile.sggcc (SGI IRIX with gcc)\n\nVersion 1.0.6d [April 7, 2000]\n  Changed sprintf() to strcpy() in png_write_sCAL_s() to work without STDIO\n  Added data_length parameter to png_decompress_chunk() function\n  Revised documentation to remove reference to abandoned png_free_chnk functions\n  Fixed an error in png_rgb_to_gray_fixed()\n  Revised example.c, usage of png_destroy_write_struct().\n  Renamed makefile.ibmvac3 to makefile.ibmc, added libpng.icc IBM project file\n  Added a check for info_ptr->free_me&PNG_FREE_TEXT when freeing text in png.c\n  Simplify png_sig_bytes() function to remove use of non-ISO-C strdup().\n\nVersion 1.0.6e [April 9, 2000]\n  Added png_data_freer() function.\n  In the code that checks for over-length tRNS chunks, added check of\n    info_ptr->num_trans as well as png_ptr->num_trans (Matthias Benckmann)\n  Minor revisions of libpng.txt/libpng.3.\n  Check for existing data and free it if the free_me flag is set, in png_set_*()\n    and png_handle_*().\n  Only define PNG_WEIGHTED_FILTERS_SUPPORTED when PNG_FLOATING_POINT_SUPPORTED\n    is defined.\n  Changed several instances of PNG_NO_CONSOLE_ID to PNG_NO_STDIO in pngrutil.c\n    and mentioned the purposes of the two macros in libpng.txt/libpng.3.\n\nVersion 1.0.6f [April 14, 2000]\n  Revised png_set_iCCP() and png_set_rows() to avoid prematurely freeing data.\n  Add checks in png_set_text() for NULL members of the input text structure.\n  Revised libpng.txt/libpng.3.\n  Removed superfluous prototype for png_set_iTXt from png.h\n  Removed \"else\" from pngread.c, after png_error(), and changed \"0\" to \"length\".\n  Changed several png_errors about malformed ancillary chunks to png_warnings.\n\nVersion 1.0.6g [April 24, 2000]\n  Added png_pass-* arrays to pnggccrd.c when PNG_USE_LOCAL_ARRAYS is defined.\n  Relocated paragraph about png_set_background() in libpng.3/libpng.txt\n    and other revisions (Matthias Benckmann)\n  Relocated info_ptr->free_me, png_ptr->free_me, and other info_ptr and\n    png_ptr members to restore binary compatibility with libpng-1.0.5\n    (breaks compatibility with libpng-1.0.6).\n\nVersion 1.0.6h [April 24, 2000]\n  Changed shared library so-number pattern from 2.x.y.z to xy.z (this builds\n    libpng.so.10 & libpng.so.10.6h instead of libpng.so.2 & libpng.so.2.1.0.6h)\n    This is a temporary change for test purposes.\n\nVersion 1.0.6i [May 2, 2000]\n  Rearranged some members at the end of png_info and png_struct, to put\n    unknown_chunks_num and free_me within the original size of the png_structs\n    and free_me, png_read_user_fn, and png_free_fn within the original png_info,\n    because some old applications allocate the structs directly instead of\n    using png_create_*().\n  Added documentation of user memory functions in libpng.txt/libpng.3\n  Modified png_read_png so that it will use user_allocated row_pointers\n    if present, unless free_me directs that it be freed, and added description\n    of the use of png_set_rows() and png_get_rows() in libpng.txt/libpng.3.\n  Added PNG_LEGACY_SUPPORTED macro, and #ifdef out all new (since version\n    1.00) members of png_struct and png_info, to regain binary compatibility\n    when you define this macro.  Capabilities lost in this event\n    are user transforms (new in version 1.0.0),the user transform pointer\n    (new in version 1.0.2), rgb_to_gray (new in 1.0.5), iCCP, sCAL, sPLT,\n    the high-level interface, and unknown chunks support (all new in 1.0.6).\n    This was necessary because of old applications that allocate the structs\n    directly as authors were instructed to do in libpng-0.88 and earlier,\n    instead of using png_create_*().\n  Added modes PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT which\n    can be used to detect codes that directly allocate the structs, and\n    code to check these modes in png_read_init() and png_write_init() and\n    generate a libpng error if the modes aren't set and PNG_LEGACY_SUPPORTED\n    was not defined.\n  Added makefile.intel and updated makefile.watcom (Pawel Mrochen)\n\nVersion 1.0.6j [May 3, 2000]\n  Overloaded png_read_init() and png_write_init() with macros that convert\n    calls to png_read_init_2() or png_write_init_2() that check the version\n    and structure sizes.\n\nVersion 1.0.7beta11 [May 7, 2000]\n  Removed the new PNG_CREATED_READ_STRUCT and PNG_CREATED_WRITE_STRUCT modes\n    which are no longer used.\n  Eliminated the three new members of png_text when PNG_LEGACY_SUPPORTED is\n    defined or when neither PNG_READ_iTXt_SUPPORTED nor PNG_WRITE_iTXT_SUPPORTED\n    is defined.\n  Made PNG_NO_READ|WRITE_iTXt the default setting, to avoid memory\n    overrun when old applications fill the info_ptr->text structure directly.\n  Added PNGAPI macro, and added it to the definitions of all exported functions.\n  Relocated version macro definitions ahead of the includes of zlib.h and\n    pngconf.h in png.h.\n\nVersion 1.0.7beta12 [May 12, 2000]\n  Revised pngset.c to avoid a problem with expanding the png_debug macro.\n  Deleted some extraneous defines from pngconf.h\n  Made PNG_NO_CONSOLE_IO the default condition when PNG_BUILD_DLL is defined.\n  Use MSC _RPTn debugging instead of fprintf if _MSC_VER is defined.\n  Added png_access_version_number() function.\n  Check for mask&PNG_FREE_CHNK (for TEXT, SCAL, PCAL) in png_free_data().\n  Expanded libpng.3/libpng.txt information about png_data_freer().\n\nVersion 1.0.7beta14 [May 17, 2000] (beta13 was not published)\n  Changed pnggccrd.c and pngvcrd.c to handle bad adaptive filter types as\n    warnings instead of errors, as pngrutil.c does.\n  Set the PNG_INFO_IDAT valid flag in png_set_rows() so png_write_png()\n    will actually write IDATs.\n  Made the default PNG_USE_LOCAL_ARRAYS depend on PNG_DLL instead of WIN32.\n  Make png_free_data() ignore its final parameter except when freeing data\n    that can have multiple instances (text, sPLT, unknowns).\n  Fixed a new bug in png_set_rows().\n  Removed info_ptr->valid tests from png_free_data(), as in version 1.0.5.\n  Added png_set_invalid() function.\n  Fixed incorrect illustrations of png_destroy_write_struct() in example.c.\n\nVersion 1.0.7beta15 [May 30, 2000]\n  Revised the deliberately erroneous Linux setjmp code in pngconf.h to produce\n    fewer error messages.\n  Rearranged checks for Z_OK to check the most likely path first in pngpread.c\n    and pngwutil.c.\n  Added checks in pngtest.c for png_create_*() returning NULL, and mentioned\n    in libpng.txt/libpng.3 the need for applications to check this.\n  Changed names of png_default_*() functions in pngtest to pngtest_*().\n  Changed return type of png_get_x|y_offset_*() from png_uint_32 to png_int_32.\n  Fixed some bugs in the unused PNG_INCH_CONVERSIONS functions in pngget.c\n  Set each pointer to NULL after freeing it in png_free_data().\n  Worked around a problem in pngconf.h; AIX's strings.h defines an \"index\"\n    macro that conflicts with libpng's png_color_16.index. (Dimitri\n    Papadapoulos)\n  Added \"msvc\" directory with MSVC++ project files (Simon-Pierre Cadieux).\n\nVersion 1.0.7beta16 [June 4, 2000]\n  Revised the workaround of AIX string.h \"index\" bug.\n  Added a check for overlength PLTE chunk in pngrutil.c.\n  Added PNG_NO_POINTER_INDEXING macro to use array-indexing instead of pointer\n    indexing in pngrutil.c and pngwutil.c to accommodate a buggy compiler.\n  Added a warning in png_decompress_chunk() when it runs out of data, e.g.\n    when it tries to read an erroneous PhotoShop iCCP chunk.\n  Added PNG_USE_DLL macro.\n  Revised the copyright/disclaimer/license notice.\n  Added contrib/msvctest directory\n\nVersion 1.0.7rc1 [June 9, 2000]\n  Corrected the definition of PNG_TRANSFORM_INVERT_ALPHA  (0x0400 not 0x0200)\n  Added contrib/visupng directory (Willem van Schaik)\n\nVersion 1.0.7beta18 [June 23, 2000]\n  Revised PNGAPI definition, and pngvcrd.c to work with __GCC__\n    and do not redefine PNGAPI if it is passed in via a compiler directive.\n  Revised visupng/PngFile.c to remove returns from within the Try block.\n  Removed leading underscores from \"_PNG_H\" and \"_PNG_SAVE_BSD_SOURCE\" macros.\n  Updated contrib/visupng/cexcept.h to version 1.0.0.\n  Fixed bugs in pngwrite.c and pngwutil.c that prevented writing iCCP chunks.\n\nVersion 1.0.7rc2 [June 28, 2000]\n  Updated license to include disclaimers required by UCITA.\n  Fixed \"DJBPP\" typo in pnggccrd.c introduced in beta18.\n\nVersion 1.0.7 [July 1, 2000]\n  Revised the definition of \"trans_values\" in libpng.3/libpng.txt\n\nVersion 1.0.8beta1 [July 8, 2000]\n  Added png_free(png_ptr, key) two places in pngpread.c to stop memory leaks.\n  Changed PNG_NO_STDIO to PNG_NO_CONSOLE_IO, several places in pngrutil.c and\n    pngwutil.c.\n  Changed PNG_EXPORT_VAR to use PNG_IMPEXP, in pngconf.h.\n  Removed unused \"#include <assert.h>\" from png.c\n  Added WindowsCE support.\n  Revised pnggccrd.c to work with gcc-2.95.2 and in the Cygwin environment.\n\nVersion 1.0.8beta2 [July 10, 2000]\n  Added project files to the wince directory and made further revisions\n    of pngtest.c, pngrio.c, and pngwio.c in support of WindowsCE.\n\nVersion 1.0.8beta3 [July 11, 2000]\n  Only set the PNG_FLAG_FREE_TRNS or PNG_FREE_TRNS flag in png_handle_tRNS()\n    for indexed-color input files to avoid potential double-freeing trans array\n    under some unusual conditions; problem was introduced in version 1.0.6f.\n  Further revisions to pngtest.c and files in the wince subdirectory.\n\nVersion 1.0.8beta4 [July 14, 2000]\n  Added the files pngbar.png and pngbar.jpg to the distribution.\n  Added makefile.cygwin, and cygwin support in pngconf.h\n  Added PNG_NO_ZALLOC_ZERO macro (makes png_zalloc skip zeroing memory)\n\nVersion 1.0.8rc1 [July 16, 2000]\n  Revised png_debug() macros and statements to eliminate compiler warnings.\n\nVersion 1.0.8 [July 24, 2000]\n  Added png_flush() in pngwrite.c, after png_write_IEND().\n  Updated makefile.hpux to build a shared library.\n\nVersion 1.0.9beta1 [November 10, 2000]\n  Fixed typo in scripts/makefile.hpux\n  Updated makevms.com in scripts and contrib/* and contrib/* (Martin Zinser)\n  Fixed seqence-point bug in contrib/pngminus/png2pnm (Martin Zinser)\n  Changed \"cdrom.com\" in documentation to \"libpng.org\"\n  Revised pnggccrd.c to get it all working, and updated makefile.gcmmx (Greg).\n  Changed type of \"params\" from voidp to png_voidp in png_read|write_png().\n  Make sure PNGAPI and PNG_IMPEXP are defined in pngconf.h.\n  Revised the 3 instances of WRITEFILE in pngtest.c.\n  Relocated \"msvc\" and \"wince\" project subdirectories into \"dll\" subdirectory.\n  Updated png.rc in dll/msvc project\n  Revised makefile.dec to define and use LIBPATH and INCPATH\n  Increased size of global png_libpng_ver[] array from 12 to 18 chars.\n  Made global png_libpng_ver[], png_sig[] and png_pass_*[] arrays const.\n  Removed duplicate png_crc_finish() from png_handle_bKGD() function.\n  Added a warning when application calls png_read_update_info() multiple times.\n  Revised makefile.cygwin\n  Fixed bugs in iCCP support in pngrutil.c and pngwutil.c.\n  Replaced png_set_empty_plte_permitted() with png_permit_mng_features().\n\nVersion 1.0.9beta2 [November 19, 2000]\n  Renamed the \"dll\" subdirectory \"projects\".\n  Added borland project files to \"projects\" subdirectory.\n  Set VS_FF_PRERELEASE and VS_FF_PATCHED flags in msvc/png.rc when appropriate.\n  Add error message in png_set_compression_buffer_size() when malloc fails.\n\nVersion 1.0.9beta3 [November 23, 2000]\n  Revised PNG_LIBPNG_BUILD_TYPE macro in png.h, used in the msvc project.\n  Removed the png_flush() in pngwrite.c that crashes some applications\n    that don't set png_output_flush_fn.\n  Added makefile.macosx and makefile.aix to scripts directory.\n\nVersion 1.0.9beta4 [December 1, 2000]\n  Change png_chunk_warning to png_warning in png_check_keyword().\n  Increased the first part of msg buffer from 16 to 18 in png_chunk_error().\n\nVersion 1.0.9beta5 [December 15, 2000]\n  Added support for filter method 64 (for PNG datastreams embedded in MNG).\n\nVersion 1.0.9beta6 [December 18, 2000]\n  Revised png_set_filter() to accept filter method 64 when appropriate.\n  Added new PNG_HAVE_PNG_SIGNATURE bit to png_ptr->mode and use it to\n    help prevent applications from using MNG features in PNG datastreams.\n  Added png_permit_mng_features() function.\n  Revised libpng.3/libpng.txt.  Changed \"filter type\" to \"filter method\".\n\nVersion 1.0.9rc1 [December 23, 2000]\n  Revised test for PNG_HAVE_PNG_SIGNATURE in pngrutil.c\n  Fixed error handling of unknown compression type in png_decompress_chunk().\n  In pngconf.h, define __cdecl when _MSC_VER is defined.\n\nVersion 1.0.9beta7 [December 28, 2000]\n  Changed PNG_TEXT_COMPRESSION_zTXt to PNG_COMPRESSION_TYPE_BASE several places.\n  Revised memory management in png_set_hIST and png_handle_hIST in a backward\n    compatible manner.  PLTE and tRNS were revised similarly.\n  Revised the iCCP chunk reader to ignore trailing garbage.\n\nVersion 1.0.9beta8 [January 12, 2001]\n  Moved pngasmrd.h into pngconf.h.\n  Improved handling of out-of-spec garbage iCCP chunks generated by PhotoShop.\n\nVersion 1.0.9beta9 [January 15, 2001]\n  Added png_set_invalid, png_permit_mng_features, and png_mmx_supported to\n    wince and msvc project module definition files.\n  Minor revision of makefile.cygwin.\n  Fixed bug with progressive reading of narrow interlaced images in pngpread.c\n\nVersion 1.0.9beta10 [January 16, 2001]\n  Do not typedef png_FILE_p in pngconf.h when PNG_NO_STDIO is defined.\n  Fixed \"png_mmx_supported\" typo in project definition files.\n\nVersion 1.0.9beta11 [January 19, 2001]\n  Updated makefile.sgi to make shared library.\n  Removed png_mmx_support() function and disabled PNG_MNG_FEATURES_SUPPORTED\n    by default, for the benefit of DLL forward compatibility.  These will\n    be re-enabled in version 1.2.0.\n\nVersion 1.0.9rc2 [January 22, 2001]\n  Revised cygwin support.\n\nVersion 1.0.9 [January 31, 2001]\n  Added check of cygwin's ALL_STATIC in pngconf.h\n  Added \"-nommx\" parameter to contrib/gregbook/rpng2-win and rpng2-x demos.\n\nVersion 1.0.10beta1 [March 14, 2001]\n  Revised makefile.dec, makefile.sgi, and makefile.sggcc; added makefile.hpgcc.\n  Reformatted libpng.3 to eliminate bad line breaks.\n  Added checks for _mmx_supported in the read_filter_row function of pnggccrd.c\n  Added prototype for png_mmx_support() near the top of pnggccrd.c\n  Moved some error checking from png_handle_IHDR to png_set_IHDR.\n  Added PNG_NO_READ_SUPPORTED and PNG_NO_WRITE_SUPPORTED macros.\n  Revised png_mmx_support() function in pnggccrd.c\n  Restored version 1.0.8 PNG_WRITE_EMPTY_PLTE_SUPPORTED behavior in pngwutil.c\n  Fixed memory leak in contrib/visupng/PngFile.c\n  Fixed bugs in png_combine_row() in pnggccrd.c and pngvcrd.c (C version)\n  Added warnings when retrieving or setting gamma=0.\n  Increased the first part of msg buffer from 16 to 18 in png_chunk_warning().\n\nVersion 1.0.10rc1 [March 23, 2001]\n  Changed all instances of memcpy, strcpy, and strlen to png_memcpy, png_strcpy,\n    and png_strlen.\n  Revised png_mmx_supported() function in pnggccrd.c to return proper value.\n  Fixed bug in progressive reading (pngpread.c) with small images (height < 8).\n\nVersion 1.0.10 [March 30, 2001]\n  Deleted extraneous space (introduced in 1.0.9) from line 42 of makefile.cygwin\n  Added beos project files (Chris Herborth)\n\nVersion 1.0.11beta1 [April 3, 2001]\n  Added type casts on several png_malloc() calls (Dimitri Papadapoulos).\n  Removed a no-longer needed AIX work-around from pngconf.h\n  Changed several \"//\" single-line comments to C-style in pnggccrd.c\n\nVersion 1.0.11beta2 [April 11, 2001]\n  Removed PNGAPI from several functions whose prototypes did not have PNGAPI.\n  Updated scripts/pngos2.def\n\nVersion 1.0.11beta3 [April 14, 2001]\n  Added checking the results of many instances of png_malloc() for NULL\n\nVersion 1.0.11beta4 [April 20, 2001]\n  Undid the changes from version 1.0.11beta3.  Added a check for NULL return\n    from user's malloc_fn().\n  Removed some useless type casts of the NULL pointer.\n  Added makefile.netbsd\n\nVersion 1.0.11 [April 27, 2001]\n  Revised makefile.netbsd\n\nVersion 1.0.12beta1 [May 14, 2001]\n  Test for Windows platform in pngconf.h when including malloc.h (Emmanuel Blot)\n  Updated makefile.cygwin and handling of Cygwin's ALL_STATIC in pngconf.h\n  Added some never-to-be-executed code in pnggccrd.c to quiet compiler warnings.\n  Eliminated the png_error about apps using png_read|write_init().  Instead,\n    libpng will reallocate the png_struct and info_struct if they are too small.\n    This retains future binary compatibility for old applications written for\n    libpng-0.88 and earlier.\n\nVersion 1.2.0beta1 [May 6, 2001]\n  Bumped DLLNUM to 2.\n  Re-enabled PNG_MNG_FEATURES_SUPPORTED and enabled PNG_ASSEMBLER_CODE_SUPPORTED\n    by default.\n  Added runtime selection of MMX features.\n  Added png_set_strip_error_numbers function and related macros.\n\nVersion 1.2.0beta2 [May 7, 2001]\n  Finished merging 1.2.0beta1 with version 1.0.11\n  Added a check for attempts to read or write PLTE in grayscale PNG datastreams.\n\nVersion 1.2.0beta3 [May 17, 2001]\n  Enabled user memory function by default.\n  Modified png_create_struct so it passes user mem_ptr to user memory allocator.\n  Increased png_mng_features flag from png_byte to png_uint_32.\n  Bumped shared-library (so-number) and dll-number to 3.\n\nVersion 1.2.0beta4 [June 23, 2001]\n  Check for missing profile length field in iCCP chunk and free chunk_data\n    in case of truncated iCCP chunk.\n  Bumped shared-library number to 3 in makefile.sgi and makefile.sggcc\n  Bumped dll-number from 2 to 3 in makefile.cygwin\n  Revised contrib/gregbook/rpng*-x.c to avoid a memory leak and to exit cleanly\n    if user attempts to run it on an 8-bit display.\n  Updated contrib/gregbook\n  Use png_malloc instead of png_zalloc to allocate palette in pngset.c\n  Updated makefile.ibmc\n  Added some typecasts to eliminate gcc 3.0 warnings.  Changed prototypes\n    of png_write_oFFS width and height from png_uint_32 to png_int_32.\n  Updated example.c\n  Revised prototypes for png_debug_malloc and png_debug_free in pngtest.c\n\nVersion 1.2.0beta5 [August 8, 2001]\n  Revised contrib/gregbook\n  Revised makefile.gcmmx\n  Revised pnggccrd.c to conditionally compile some thread-unsafe code only\n    when PNG_THREAD_UNSAFE_OK is defined.\n  Added tests to prevent pngwutil.c from writing a bKGD or tRNS chunk with\n    value exceeding 2^bit_depth-1\n  Revised makefile.sgi and makefile.sggcc\n  Replaced calls to fprintf(stderr,...) with png_warning() in pnggccrd.c\n  Removed restriction that do_invert_mono only operate on 1-bit opaque files\n\nVersion 1.2.0 [September 1, 2001]\n  Changed a png_warning() to png_debug() in pnggccrd.c\n  Fixed contrib/gregbook/rpng-x.c, rpng2-x.c to avoid crash with XFreeGC().\n\nVersion 1.2.1beta1 [October 19, 2001]\n  Revised makefile.std in contrib/pngminus\n  Include background_1 in png_struct regardless of gamma support.\n  Revised makefile.netbsd and makefile.macosx, added makefile.darwin.\n  Revised example.c to provide more details about using row_callback().\n\nVersion 1.2.1beta2 [October 25, 2001]\n  Added type cast to each NULL appearing in a function call, except for\n    WINCE functions.\n  Added makefile.so9.\n\nVersion 1.2.1beta3 [October 27, 2001]\n  Removed type casts from all NULLs.\n  Simplified png_create_struct_2().\n\nVersion 1.2.1beta4 [November 7, 2001]\n  Revised png_create_info_struct() and png_creat_struct_2().\n  Added error message if png_write_info() was omitted.\n  Type cast NULLs appearing in function calls when _NO_PROTO or\n    PNG_TYPECAST_NULL is defined.\n\nVersion 1.2.1rc1 [November 24, 2001]\n  Type cast NULLs appearing in function calls except when PNG_NO_TYPECAST_NULL\n    is defined.\n  Changed typecast of \"size\" argument to png_size_t in pngmem.c calls to\n    the user malloc_fn, to agree with the prototype in png.h\n  Added a pop/push operation to pnggccrd.c, to preserve Eflag (Maxim Sobolev)\n  Updated makefile.sgi to recognize LIBPATH and INCPATH.\n  Updated various makefiles so \"make clean\" does not remove previous major\n    version of the shared library.\n\nVersion 1.2.1rc2 [December 4, 2001]\n  Always allocate 256-entry internal palette, hist, and trans arrays, to\n    avoid out-of-bounds memory reference caused by invalid PNG datastreams.\n  Added a check for prefix_length > data_length in iCCP chunk handler.\n\nVersion 1.2.1 [December 7, 2001]\n  None.\n\nVersion 1.2.2beta1 [February 22, 2002]\n  Fixed a bug with reading the length of iCCP profiles (Larry Reeves).\n  Revised makefile.linux, makefile.gcmmx, and makefile.sgi to generate\n    libpng.a, libpng12.so (not libpng.so.3), and libpng12/png.h\n  Revised makefile.darwin to remove \"-undefined suppress\" option.\n  Added checks for gamma and chromaticity values over 21474.83, which exceed\n    the limit for PNG unsigned 32-bit integers when encoded.\n  Revised calls to png_create_read_struct() and png_create_write_struct()\n    for simpler debugging.\n  Revised png_zalloc() so zlib handles errors (uses PNG_FLAG_MALLOC_NULL_MEM_OK)\n\nVersion 1.2.2beta2 [February 23, 2002]\n  Check chunk_length and idat_size for invalid (over PNG_MAX_UINT) lengths.\n  Check for invalid image dimensions in png_get_IHDR.\n  Added missing \"fi;\" in the install target of the SGI makefiles.\n  Added install-static to all makefiles that make shared libraries.\n  Always do gamma compensation when image is partially transparent.\n\nVersion 1.2.2beta3 [March 7, 2002]\n  Compute background.gray and background_1.gray even when color_type is RGB\n    in case image gets reduced to gray later.\n  Modified shared-library makefiles to install pkgconfig/libpngNN.pc.\n  Export (with PNGAPI) png_zalloc, png_zfree, and png_handle_as_unknown\n  Removed unused png_write_destroy_info prototype from png.h\n  Eliminated incorrect use of width_mmx from pnggccrd.c in pixel_bytes == 8 case\n  Added install-shared target to all makefiles that make shared libraries.\n  Stopped a double free of palette, hist, and trans when not using free_me.\n  Added makefile.32sunu for Sun Ultra 32 and makefile.64sunu for Sun Ultra 64.\n\nVersion 1.2.2beta4 [March 8, 2002]\n  Compute background.gray and background_1.gray even when color_type is RGB\n    in case image gets reduced to gray later (Jason Summers).\n  Relocated a misplaced /bin/rm in the \"install-shared\" makefile targets\n  Added PNG_1_0_X macro which can be used to build a 1.0.x-compatible library.\n\nVersion 1.2.2beta5 [March 26, 2002]\n  Added missing PNGAPI to several function definitions.\n  Check for invalid bit_depth or color_type in png_get_IHDR(), and\n    check for missing PLTE or IHDR in png_push_read_chunk() (Matthias Clasen).\n  Revised iTXt support to accept NULL for lang and lang_key.\n  Compute gamma for color components of background even when color_type is gray.\n  Changed \"()\" to \"{}\" in scripts/libpng.pc.in.\n  Revised makefiles to put png.h and pngconf.h only in $prefix/include/libpngNN\n  Revised makefiles to make symlink to libpng.so.NN in addition to libpngNN.so\n\nVersion 1.2.2beta6 [March 31, 2002]\n\nVersion 1.0.13beta1 [March 31, 2002]\n  Prevent png_zalloc() from trying to memset memory that it failed to acquire.\n  Add typecasts of PNG_MAX_UINT in pngset_cHRM_fixed() (Matt Holgate).\n  Ensure that the right function (user or default) is used to free the\n    png_struct after an error in png_create_read_struct_2().\n\nVersion 1.2.2rc1 [April 7, 2002]\n\nVersion 1.0.13rc1 [April 7, 2002]\n  Save the ebx register in pnggccrd.c (Sami Farin)\n  Add \"mem_ptr = png_ptr->mem_ptr\" in png_destroy_write_struct() (Paul Gardner).\n  Updated makefiles to put headers in include/libpng and remove old include/*.h.\n\nVersion 1.2.2 [April 15, 2002]\n\nVersion 1.0.13 [April 15, 2002]\n  Revised description of png_set_filter() in libpng.3/libpng.txt.\n  Revised makefile.netbsd and added makefile.neNNbsd and makefile.freebsd\n\nVersion 1.0.13patch01 [April 17, 2002]\n\nVersion 1.2.2patch01 [April 17, 2002]\n  Changed ${PNGMAJ}.${PNGVER} bug to ${PNGVER} in makefile.sgi and\n    makefile.sggcc\n  Fixed VER -> PNGVER typo in makefile.macosx and added install-static to\n    install\n  Added install: target to makefile.32sunu and makefile.64sunu\n\nVersion 1.0.13patch03 [April 18, 2002]\n\nVersion 1.2.2patch03 [April 18, 2002]\n  Revised 15 makefiles to link libpng.a to libpngNN.a and the include libpng\n  subdirectory to libpngNN subdirectory without the full pathname.\n  Moved generation of libpng.pc from \"install\" to \"all\" in 15 makefiles.\n\nVersion 1.2.3rc1 [April 28, 2002]\n  Added install-man target to 15 makefiles (Dimitri Papadopolous-Orfanos).\n  Added $(DESTDIR) feature to 24 makefiles (Tim Mooney)\n  Fixed bug with $prefix, should be $(prefix) in makefile.hpux.\n  Updated cygwin-specific portion of pngconf.h and revised makefile.cygwin\n  Added a link from libpngNN.pc to libpng.pc in 15 makefiles.\n  Added links from include/libpngNN/*.h to include/*.h in 24 makefiles.\n  Revised makefile.darwin to make relative links without full pathname.\n  Added setjmp() at the end of png_create_*_struct_2() in case user forgets\n    to put one in their application.\n  Restored png_zalloc() and png_zfree() prototypes to version 1.2.1 and\n    removed them from module definition files.\n\nVersion 1.2.3rc2 [May 1, 2002]\n  Fixed bug in reporting number of channels in pngget.c and pngset.c,\n    that was introduced in version 1.2.2beta5.\n  Exported png_zalloc(), png_zfree(), png_default_read(), png_default_write(),\n    png_default_flush(), and png_push_fill_buffer() and included them in\n    module definition files.\n  Added \"libpng.pc\" dependency to the \"install-shared\" target in 15 makefiles.\n\nVersion 1.2.3rc3 [May 1, 2002]\n  Revised prototype for png_default_flush()\n  Remove old libpng.pc and libpngNN.pc before installing new ones.\n\nVersion 1.2.3rc4 [May 2, 2002]\n  Typos in *.def files (png_default_read|write -> png_default_read|write_data)\n  In makefiles, changed rm libpng.NN.pc to rm libpngNN.pc\n  Added libpng-config and libpngNN-config and modified makefiles to install\n    them.\n  Changed $(MANPATH) to $(DESTDIR)$(MANPATH) in makefiles\n  Added \"Win32 DLL VB\" configuration to projects/msvc/libpng.dsp\n\nVersion 1.2.3rc5 [May 11, 2002]\n  Changed \"error\" and \"message\" in prototypes to \"error_message\" and\n    \"warning_message\" to avoid namespace conflict.\n  Revised 15 makefiles to build libpng-config from libpng-config-*.in\n  Once more restored png_zalloc and png_zfree to regular nonexported form.\n  Restored png_default_read|write_data, png_default_flush, png_read_fill_buffer\n    to nonexported form, but with PNGAPI, and removed them from module def\n    files.\n\nVersion 1.2.3rc6 [May 14, 2002]\n  Removed \"PNGAPI\" from png_zalloc() and png_zfree() in png.c\n  Changed \"Gz\" to \"Gd\" in projects/msvc/libpng.dsp and zlib.dsp.\n  Removed leftover libpng-config \"sed\" script from four makefiles.\n  Revised libpng-config creating script in 16 makefiles.\n\nVersion 1.2.3 [May 22, 2002]\n  Revised libpng-config target in makefile.cygwin.\n  Removed description of png_set_mem_fn() from documentation.\n  Revised makefile.freebsd.\n  Minor cosmetic changes to 15 makefiles, e.g., $(DI) = $(DESTDIR)/$(INCDIR).\n  Revised projects/msvc/README.txt\n  Changed -lpng to -lpngNN in LDFLAGS in several makefiles.\n\nVersion 1.2.4beta1 [May 24, 2002]\n  Added libpng.pc and libpng-config to \"all:\" target in 16 makefiles.\n  Fixed bug in 16 makefiles: $(DESTDIR)/$(LIBPATH) to $(DESTDIR)$(LIBPATH)\n  Added missing \"\\\" before closing double quote in makefile.gcmmx.\n  Plugged various memory leaks; added png_malloc_warn() and png_set_text_2()\n    functions.\n\nVersion 1.2.4beta2 [June 25, 2002]\n  Plugged memory leak of png_ptr->current_text (Matt Holgate).\n  Check for buffer overflow before reading CRC in pngpread.c (Warwick Allison)\n  Added -soname to the loader flags in makefile.dec, makefile.sgi, and\n    makefile.sggcc.\n  Added \"test-installed\" target to makefile.linux, makefile.gcmmx,\n    makefile.sgi, and makefile.sggcc.\n\nVersion 1.2.4beta3 [June 28, 2002]\n  Plugged memory leak of row_buf in pngtest.c when there is a png_error().\n  Detect buffer overflow in pngpread.c when IDAT is corrupted with extra data.\n  Added \"test-installed\" target to makefile.32sunu, makefile.64sunu,\n    makefile.beos, makefile.darwin, makefile.dec, makefile.macosx,\n    makefile.solaris, makefile.hpux, makefile.hpgcc, and makefile.so9.\n\nVersion 1.2.4rc1 and 1.0.14rc1 [July 2, 2002]\n  Added \"test-installed\" target to makefile.cygwin and makefile.sco.\n  Revised pnggccrd.c to be able to back out version 1.0.x via PNG_1_0_X macro.\n\nVersion 1.2.4 and 1.0.14 [July 8, 2002]\n  Changed png_warning() to png_error() when width is too large to process.\n\nVersion 1.2.4patch01 [July 20, 2002]\n  Revised makefile.cygwin to use DLL number 12 instead of 13.\n\nVersion 1.2.5beta1 [August 6, 2002]\n  Added code to contrib/gregbook/readpng2.c to ignore unused chunks.\n  Replaced toucan.png in contrib/gregbook (it has been corrupt since 1.0.11)\n  Removed some stray *.o files from contrib/gregbook.\n  Changed png_error() to png_warning() about \"Too much data\" in pngpread.c\n    and about \"Extra compressed data\" in pngrutil.c.\n  Prevent png_ptr->pass from exceeding 7 in png_push_finish_row().\n  Updated makefile.hpgcc\n  Updated png.c and pnggccrd.c handling of return from png_mmx_support()\n\nVersion 1.2.5beta2 [August 15, 2002]\n  Only issue png_warning() about \"Too much data\" in pngpread.c when avail_in\n    is nonzero.\n  Updated makefiles to install a separate libpng.so.3 with its own rpath.\n\nVersion 1.2.5rc1 and 1.0.15rc1 [August 24, 2002]\n  Revised makefiles to not remove previous minor versions of shared libraries.\n\nVersion 1.2.5rc2 and 1.0.15rc2 [September 16, 2002]\n  Revised 13 makefiles to remove \"-lz\" and \"-L$(ZLIBLIB)\", etc., from shared\n    library loader directive.\n  Added missing \"$OBJSDLL\" line to makefile.gcmmx.\n  Added missing \"; fi\" to makefile.32sunu.\n\nVersion 1.2.5rc3 and 1.0.15rc3 [September 18, 2002]\n  Revised libpng-config script.\n\nVersion 1.2.5 and 1.0.15 [October 3, 2002]\n  Revised makefile.macosx, makefile.darwin, makefile.hpgcc, and makefile.hpux,\n    and makefile.aix.\n  Relocated two misplaced PNGAPI lines in pngtest.c\n\nVersion 1.2.6beta1 [October 22, 2002]\n  Commented out warning about uninitialized mmx_support in pnggccrd.c.\n  Changed \"IBMCPP__\" flag to \"__IBMCPP__\" in pngconf.h.\n  Relocated two more misplaced PNGAPI lines in pngtest.c\n  Fixed memory overrun bug in png_do_read_filler() with 16-bit datastreams,\n    introduced in version 1.0.2.\n  Revised makefile.macosx, makefile.dec, makefile.aix, and makefile.32sunu.\n\nVersion 1.2.6beta2 [November 1, 2002]\n  Added libpng-config \"--ldopts\" output.\n  Added \"AR=ar\" and \"ARFLAGS=rc\" and changed \"ar rc\" to \"$(AR) $(ARFLAGS)\"\n    in makefiles.\n\nVersion 1.2.6beta3 [July 18, 2004]\n  Reverted makefile changes from version 1.2.6beta2 and some of the changes\n    from version 1.2.6beta1; these will be postponed until version 1.2.7.\n    Version 1.2.6 is going to be a simple bugfix release.\n  Changed the one instance of \"ln -sf\" to \"ln -f -s\" in each Sun makefile.\n  Fixed potential overrun in pngerror.c by using strncpy instead of memcpy.\n  Added \"#!/bin/sh\" at the top of configure, for recognition of the\n    'x' flag under Cygwin (Cosmin).\n  Optimized vacuous tests that silence compiler warnings, in png.c (Cosmin).\n  Added support for PNG_USER_CONFIG, in pngconf.h (Cosmin).\n  Fixed the special memory handler for Borland C under DOS, in pngmem.c\n    (Cosmin).\n  Removed some spurious assignments in pngrutil.c (Cosmin).\n  Replaced 65536 with 65536L, and 0xffff with 0xffffL, to silence warnings\n    on 16-bit platforms (Cosmin).\n  Enclosed shift op expressions in parentheses, to silence warnings (Cosmin).\n  Used proper type png_fixed_point, to avoid problems on 16-bit platforms,\n    in png_handle_sRGB() (Cosmin).\n  Added compression_type to png_struct, and optimized the window size\n    inside the deflate stream (Cosmin).\n  Fixed definition of isnonalpha(), in pngerror.c and pngrutil.c (Cosmin).\n  Fixed handling of unknown chunks that come after IDAT (Cosmin).\n  Allowed png_error() and png_warning() to work even if png_ptr == NULL\n    (Cosmin).\n  Replaced row_info->rowbytes with row_bytes in png_write_find_filter()\n    (Cosmin).\n  Fixed definition of PNG_LIBPNG_VER_DLLNUM (Simon-Pierre).\n  Used PNG_LIBPNG_VER and PNG_LIBPNG_VER_STRING instead of the hardcoded\n    values in png.c (Simon-Pierre, Cosmin).\n  Initialized png_libpng_ver[] with PNG_LIBPNG_VER_STRING (Simon-Pierre).\n  Replaced PNG_LIBPNG_VER_MAJOR with PNG_LIBPNG_VER_DLLNUM in png.rc\n    (Simon-Pierre).\n  Moved the definition of PNG_HEADER_VERSION_STRING near the definitions\n    of the other PNG_LIBPNG_VER_... symbols in png.h (Cosmin).\n  Relocated #ifndef PNGAPI guards in pngconf.h (Simon-Pierre, Cosmin).\n  Updated scripts/makefile.vc(a)win32 (Cosmin).\n  Updated the MSVC project (Simon-Pierre, Cosmin).\n  Updated the Borland C++ Builder project (Cosmin).\n  Avoided access to asm_flags in pngvcrd.c, if PNG_1_0_X is defined (Cosmin).\n  Commented out warning about uninitialized mmx_support in pngvcrd.c (Cosmin).\n  Removed scripts/makefile.bd32 and scripts/pngdef.pas (Cosmin).\n  Added extra guard around inclusion of Turbo C memory headers, in pngconf.h\n    (Cosmin).\n  Renamed projects/msvc/ to projects/visualc6/, and projects/borland/ to\n    projects/cbuilder5/ (Cosmin).\n  Moved projects/visualc6/png32ms.def to scripts/pngw32.def,\n    and projects/visualc6/png.rc to scripts/pngw32.rc (Cosmin).\n  Added projects/visualc6/pngtest.dsp; removed contrib/msvctest/ (Cosmin).\n  Changed line endings to DOS style in cbuilder5 and visualc6 files, even\n    in the tar.* distributions (Cosmin).\n  Updated contrib/visupng/VisualPng.dsp (Cosmin).\n  Updated contrib/visupng/cexcept.h to version 2.0.0 (Cosmin).\n  Added a separate distribution with \"configure\" and supporting files (Junichi).\n\nVersion 1.2.6beta4 [July 28, 2004]\n  Added user ability to change png_size_t via a PNG_SIZE_T macro.\n  Added png_sizeof() and png_convert_size() functions.\n  Added PNG_SIZE_MAX (maximum value of a png_size_t variable.\n  Added check in png_malloc_default() for (size_t)size != (png_uint_32)size\n    which would indicate an overflow.\n  Changed sPLT failure action from png_error to png_warning and abandon chunk.\n  Changed sCAL and iCCP failures from png_error to png_warning and abandon.\n  Added png_get_uint_31(png_ptr, buf) function.\n  Added PNG_UINT_32_MAX macro.\n  Renamed PNG_MAX_UINT to PNG_UINT_31_MAX.\n  Made png_zalloc() issue a png_warning and return NULL on potential\n    overflow.\n  Turn on PNG_NO_ZALLOC_ZERO by default in version 1.2.x\n  Revised \"clobber list\" in pnggccrd.c so it will compile under gcc-3.4.\n  Revised Borland portion of png_malloc() to return NULL or issue\n    png_error() according to setting of PNG_FLAG_MALLOC_NULL_MEM_OK.\n  Added PNG_NO_SEQUENTIAL_READ_SUPPORTED macro to conditionally remove\n    sequential read support.\n  Added some \"#if PNG_WRITE_SUPPORTED\" blocks.\n  Added #ifdef to remove some redundancy in png_malloc_default().\n  Use png_malloc instead of png_zalloc to allocate the pallete.\n\nVersion 1.0.16rc1 and 1.2.6rc1 [August 4, 2004]\n  Fixed buffer overflow vulnerability (CVE-2004-0597) in png_handle_tRNS().\n  Fixed NULL dereference vulnerability (CVE-2004-0598) in png_handle_iCCP().\n  Fixed integer overflow vulnerability (CVE-2004-0599) in png_read_png().\n  Fixed some harmless bugs in png_handle_sBIT, etc, that would cause\n    duplicate chunk types to go undetected.\n  Fixed some timestamps in the -config version\n  Rearranged order of processing of color types in png_handle_tRNS().\n  Added ROWBYTES macro to calculate rowbytes without integer overflow.\n  Updated makefile.darwin and removed makefile.macosx from scripts directory.\n  Imposed default one million column, one-million row limits on the image\n    dimensions, and added png_set_user_limits() function to override them.\n  Revised use of PNG_SET_USER_LIMITS_SUPPORTED macro.\n  Fixed wrong cast of returns from png_get_user_width|height_max().\n  Changed some \"keep the compiler happy\" from empty statements to returns,\n  Revised libpng.txt to remove 1.2.x stuff from the 1.0.x distribution\n\nVersion 1.0.16rc2 and 1.2.6rc2 [August 7, 2004]\n  Revised makefile.darwin and makefile.solaris.  Removed makefile.macosx.\n  Revised pngtest's png_debug_malloc() to use png_malloc() instead of\n    png_malloc_default() which is not supposed to be exported.\n  Fixed off-by-one error in one of the conversions to PNG_ROWBYTES() in\n    pngpread.c.  Bug was introduced in 1.2.6rc1.\n  Fixed bug in RGB to RGBX transformation introduced in 1.2.6rc1.\n  Fixed old bug in RGB to Gray transformation.\n  Fixed problem with 64-bit compilers by casting arguments to abs()\n    to png_int_32.\n  Changed \"ln -sf\" to \"ln -f -s\" in three makefiles (solaris, sco, so9).\n  Changed \"HANDLE_CHUNK_*\" to \"PNG_HANDLE_CHUNK_*\" (Cosmin)\n  Added \"-@/bin/rm -f $(DL)/$(LIBNAME).so.$(PNGMAJ)\" to 15 *NIX makefiles.\n  Added code to update the row_info->colortype in png_do_read_filler() (MSB).\n\nVersion 1.0.16rc3 and 1.2.6rc3 [August 9, 2004]\n  Eliminated use of \"abs()\" in testing cHRM and gAMA values, to avoid\n    trouble with some 64-bit compilers.  Created PNG_OUT_OF_RANGE() macro.\n  Revised documentation of png_set_keep_unknown_chunks().\n  Check handle_as_unknown status in pngpread.c, as in pngread.c previously.\n  Moved  \"PNG_HANDLE_CHUNK_*\" macros out of PNG_INTERNAL section of png.h\n  Added \"rim\" definitions for CONST4 and CONST6 in pnggccrd.c\n\nVersion 1.0.16rc4 and 1.2.6rc4 [August 10, 2004]\n  Fixed mistake in pngtest.c introduced in 1.2.6rc2 (declaration of\n    \"pinfo\" was out of place).\n\nVersion 1.0.16rc5 and 1.2.6rc5 [August 10, 2004]\n  Moved  \"PNG_HANDLE_CHUNK_*\" macros out of PNG_ASSEMBLER_CODE_SUPPORTED\n    section of png.h where they were inadvertently placed in version rc3.\n\nVersion 1.2.6 and 1.0.16 [August 15, 2004]\n  Revised pngtest so memory allocation testing is only done when PNG_DEBUG==1.\n\nVersion 1.2.7beta1 [August 26, 2004]\n  Removed unused pngasmrd.h file.\n  Removed references to uu.net for archived files.  Added references to\n    PNG Spec (second edition) and the PNG ISO/IEC Standard.\n  Added \"test-dd\" target in 15 makefiles, to run pngtest in DESTDIR.\n  Fixed bug with \"optimized window size\" in the IDAT datastream, that\n    causes libpng to write PNG files with incorrect zlib header bytes.\n\nVersion 1.2.7beta2 [August 28, 2004]\n  Fixed bug with sCAL chunk and big-endian machines (David Munro).\n  Undid new code added in 1.2.6rc2 to update the color_type in\n    png_set_filler().\n  Added png_set_add_alpha() that updates color type.\n\nVersion 1.0.17rc1 and 1.2.7rc1 [September 4, 2004]\n  Revised png_set_strip_filler() to not remove alpha if color_type has alpha.\n\nVersion 1.2.7 and 1.0.17 [September 12, 2004]\n  Added makefile.hp64\n  Changed projects/msvc/png32ms.def to scripts/png32ms.def in makefile.cygwin\n\nVersion 1.2.8beta1 [November 1, 2004]\n  Fixed bug in png_text_compress() that would fail to complete a large block.\n  Fixed bug, introduced in libpng-1.2.7, that overruns a buffer during\n    strip alpha operation in png_do_strip_filler().\n  Added PNG_1_2_X definition in pngconf.h\n  Use #ifdef to comment out png_info_init in png.c and png_read_init in\n    pngread.c (as of 1.3.0)\n\nVersion 1.2.8beta2 [November 2, 2004]\n  Reduce color_type to a nonalpha type after strip alpha operation in\n    png_do_strip_filler().\n\nVersion 1.2.8beta3 [November 3, 2004]\n  Revised definitions of PNG_MAX_UINT_32, PNG_MAX_SIZE, and PNG_MAXSUM\n\nVersion 1.2.8beta4 [November 12, 2004]\n  Fixed (again) definition of PNG_LIBPNG_VER_DLLNUM in png.h (Cosmin).\n  Added PNG_LIBPNG_BUILD_PRIVATE in png.h (Cosmin).\n  Set png_ptr->zstream.data_type to Z_BINARY, to avoid unnecessary detection\n    of data type in deflate (Cosmin).\n  Deprecated but continue to support SPECIALBUILD and PRIVATEBUILD in favor of\n    PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.\n\nVersion 1.2.8beta5 [November 20, 2004]\n  Use png_ptr->flags instead of png_ptr->transformations to pass\n    PNG_STRIP_ALPHA info to png_do_strip_filler(), to preserve ABI\n    compatibility.\n  Revised handling of SPECIALBUILD, PRIVATEBUILD,\n    PNG_LIBPNG_BUILD_SPECIAL_STRING and PNG_LIBPNG_BUILD_PRIVATE_STRING.\n\nVersion 1.2.8rc1 [November 24, 2004]\n  Moved handling of BUILD macros from pngconf.h to png.h\n  Added definition of PNG_LIBPNG_BASE_TYPE in png.h, inadvertently\n    omitted from beta5.\n  Revised scripts/pngw32.rc\n  Despammed mailing addresses by masking \"@\" with \"at\".\n  Inadvertently installed a supposedly faster test version of pngrutil.c\n\nVersion 1.2.8rc2 [November 26, 2004]\n  Added two missing \"\\\" in png.h\n  Change tests in pngread.c and pngpread.c to\n    if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))\n       png_do_read_transformations(png_ptr);\n\nVersion 1.2.8rc3 [November 28, 2004]\n  Reverted pngrutil.c to version libpng-1.2.8beta5.\n  Added scripts/makefile.elf with supporting code in pngconf.h for symbol\n    versioning (John Bowler).\n\nVersion 1.2.8rc4 [November 29, 2004]\n  Added projects/visualc7 (Simon-pierre).\n\nVersion 1.2.8rc5 [November 29, 2004]\n  Fixed new typo in scripts/pngw32.rc\n\nVersion 1.2.8 [December 3, 2004]\n  Removed projects/visualc7, added projects/visualc71.\n\nVersion 1.2.9beta1 [February 21, 2006]\n  Initialized some structure members in pngwutil.c to avoid gcc-4.0.0 complaints\n  Revised man page and libpng.txt to make it clear that one should not call\n    png_read_end or png_write_end after png_read_png or png_write_png.\n  Updated references to png-mng-implement mailing list.\n  Fixed an incorrect typecast in pngrutil.c\n  Added PNG_NO_READ_SUPPORTED conditional for making a write-only library.\n  Added PNG_NO_WRITE_INTERLACING_SUPPORTED conditional.\n  Optimized alpha-inversion loops in pngwtran.c\n  Moved test for nonzero gamma outside of png_build_gamma_table() in pngrtran.c\n  Make sure num_trans is <= 256 before copying data in png_set_tRNS().\n  Make sure num_palette is <= 256 before copying data in png_set_PLTE().\n  Interchanged order of write_swap_alpha and write_invert_alpha transforms.\n  Added parentheses in the definition of PNG_LIBPNG_BUILD_TYPE (Cosmin).\n  Optimized zlib window flag (CINFO) in contrib/pngsuite/*.png (Cosmin).\n  Updated scripts/makefile.bc32 for Borland C++ 5.6 (Cosmin).\n  Exported png_get_uint_32, png_save_uint_32, png_get_uint_16, png_save_uint_16,\n    png_get_int_32, png_save_int_32, png_get_uint_31 (Cosmin).\n  Added type cast (png_byte) in png_write_sCAL() (Cosmin).\n  Fixed scripts/makefile.cygwin (Christian Biesinger, Cosmin).\n  Default iTXt support was inadvertently enabled.\n\nVersion 1.2.9beta2 [February 21, 2006]\n  Check for png_rgb_to_gray and png_gray_to_rgb read transformations before\n    checking for png_read_dither in pngrtran.c\n  Revised checking of chromaticity limits to accommodate extended RGB\n    colorspace (John Denker).\n  Changed line endings in some of the project files to CRLF, even in the\n    \"Unix\" tar distributions (Cosmin).\n  Made png_get_int_32 and png_save_int_32 always available (Cosmin).\n  Updated scripts/pngos2.def, scripts/pngw32.def and projects/wince/png32ce.def\n    with the newly exported functions.\n  Eliminated distributions without the \"configure\" script.\n  Updated INSTALL instructions.\n\nVersion 1.2.9beta3 [February 24, 2006]\n  Fixed CRCRLF line endings in contrib/visupng/VisualPng.dsp\n  Made libpng.pc respect EXEC_PREFIX (D. P. Kreil, J. Bowler)\n  Removed reference to pngasmrd.h from Makefile.am\n  Renamed CHANGES to ChangeLog.\n  Renamed LICENSE to COPYING.\n  Renamed ANNOUNCE to NEWS.\n  Created AUTHORS file.\n\nVersion 1.2.9beta4 [March 3, 2006]\n  Changed definition of PKGCONFIG from $prefix/lib to $libdir in configure.ac\n  Reverted to filenames LICENSE and ANNOUNCE; removed AUTHORS and COPYING.\n  Removed newline from the end of some error and warning messages.\n  Removed test for sqrt() from configure.ac and configure.\n  Made swap tables in pngtrans.c PNG_CONST (Carlo Bramix).\n  Disabled default iTXt support that was inadvertently enabled in\n    libpng-1.2.9beta1.\n  Added \"OS2\" to list of systems that don't need underscores, in pnggccrd.c\n  Removed libpng version and date from *.c files.\n\nVersion 1.2.9beta5 [March 4, 2006]\n  Removed trailing blanks from source files.\n  Put version and date of latest change in each source file, and changed\n    copyright year accordingly.\n  More cleanup of configure.ac, Makefile.am, and associated scripts.\n  Restored scripts/makefile.elf which was inadvertently deleted.\n\nVersion 1.2.9beta6 [March 6, 2006]\n  Fixed typo (RELEASE) in configuration files.\n\nVersion 1.2.9beta7 [March 7, 2006]\n  Removed libpng.vers and libpng.sym from libpng12_la_SOURCES in Makefile.am\n  Fixed inconsistent #ifdef's around png_sig_bytes() and png_set_sCAL_s()\n    in png.h.\n  Updated makefile.elf as suggested by debian.\n  Made cosmetic changes to some makefiles, adding LN_SF and other macros.\n  Made some makefiles accept \"exec_prefix\".\n\nVersion 1.2.9beta8 [March 9, 2006]\n  Fixed some \"#if defined (...\" which should be \"#if defined(...\"\n    Bug introduced in libpng-1.2.8.\n  Fixed inconsistency in definition of png_default_read_data()\n  Restored blank that was lost from makefile.sggcc \"clean\" target in beta7.\n  Revised calculation of \"current\" and \"major\" for irix in ltmain.sh\n  Changed \"mkdir\" to \"MKDIR_P\" in some makefiles.\n  Separated PNG_EXPAND and PNG_EXPAND_tRNS.\n  Added png_set_expand_gray_1_2_4_to_8() and deprecated\n    png_set_gray_1_2_4_to_8() which also expands tRNS to alpha.\n\nVersion 1.2.9beta9 [March 10, 2006]\n  Include \"config.h\" in pngconf.h when available.\n  Added some checks for NULL png_ptr or NULL info_ptr (timeless)\n\nVersion 1.2.9beta10 [March 20, 2006]\n  Removed extra CR from contrib/visualpng/VisualPng.dsw (Cosmin)\n  Made pnggccrd.c PIC-compliant (Christian Aichinger).\n  Added makefile.mingw (Wolfgang Glas).\n  Revised pngconf.h MMX checking.\n\nVersion 1.2.9beta11 [March 22, 2006]\n  Fixed out-of-order declaration in pngwrite.c that was introduced in beta9\n  Simplified some makefiles by using LIBSO, LIBSOMAJ, and LIBSOVER macros.\n\nVersion 1.2.9rc1 [March 31, 2006]\n  Defined PNG_USER_PRIVATEBUILD when including \"pngusr.h\" (Cosmin).\n  Removed nonsensical assertion check from pngtest.c (Cosmin).\n\nVersion 1.2.9 [April 14, 2006]\n  Revised makefile.beos and added \"none\" selector in ltmain.sh\n\nVersion 1.2.10beta1 [April 15, 2006]\n  Renamed \"config.h\" to \"png_conf.h\" and revised Makefile.am to add\n    -DPNG_BUILDING_LIBPNG to compile directive, and modified pngconf.h\n    to include png_conf.h only when PNG_BUILDING_LIBPNG is defined.\n\nVersion 1.2.10beta2 [April 15, 2006]\n  Manually updated Makefile.in and configure.  Changed png_conf.h.in\n    back to config.h.\n\nVersion 1.2.10beta3 [April 15, 2006]\n  Change png_conf.h back to config.h in pngconf.h.\n\nVersion 1.2.10beta4 [April 16, 2006]\n  Change PNG_BUILDING_LIBPNG to PNG_CONFIGURE_LIBPNG in config/Makefile*.\n\nVersion 1.2.10beta5 [April 16, 2006]\n  Added a configure check for compiling assembler code in pnggccrd.c\n\nVersion 1.2.10beta6 [April 17, 2006]\n  Revised the configure check for pnggccrd.c\n  Moved -DPNG_CONFIGURE_LIBPNG into @LIBPNG_DEFINES@\n  Added @LIBPNG_DEFINES@ to arguments when building libpng.sym\n\nVersion 1.2.10beta7 [April 18, 2006]\n  Change \"exec_prefix=$prefix\" to \"exec_prefix=$(prefix)\" in makefiles.\n\nVersion 1.2.10rc1 [April 19, 2006]\n  Ensure pngconf.h doesn't define both PNG_USE_PNGGCCRD and PNG_USE_PNGVCRD\n  Fixed \"LN_FS\" typo in makefile.sco and makefile.solaris.\n\nVersion 1.2.10rc2 [April 20, 2006]\n  Added a backslash between -DPNG_CONFIGURE_LIBPNG and -DPNG_NO_ASSEMBLER_CODE\n   in configure.ac and configure\n  Made the configure warning about versioned symbols less arrogant.\n\nVersion 1.2.10rc3 [April 21, 2006]\n  Added a note in libpng.txt that png_set_sig_bytes(8) can be used when\n    writing an embedded PNG without the 8-byte signature.\n  Revised makefiles and configure to avoid making links to libpng.so.*\n\nVersion 1.2.10 [April 23, 2006]\n  Reverted configure to \"rc2\" state.\n\nVersion 1.2.11beta1 [May 31, 2006]\n  scripts/libpng.pc.in contained \"configure\" style version info and would\n    not work with makefiles.\n  The shared-library makefiles were linking to libpng.so.0 instead of\n    libpng.so.3 compatibility as the library.\n\nVersion 1.2.11beta2 [June 2, 2006]\n  Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid\n    buffer overflow.\n  Fixed bug in example.c (png_set_palette_rgb -> png_set_palette_to_rgb)\n\nVersion 1.2.11beta3 [June 5, 2006]\n  Prepended \"#! /bin/sh\" to ltmail.sh and contrib/pngminus/*.sh (Cosmin).\n  Removed the accidental leftover Makefile.in~ (Cosmin).\n  Avoided potential buffer overflow and optimized buffer in\n    png_write_sCAL(), png_write_sCAL_s() (Cosmin).\n  Removed the include directories and libraries from CFLAGS and LDFLAGS\n    in scripts/makefile.gcc (Nelson A. de Oliveira, Cosmin).\n\nVersion 1.2.11beta4 [June 6, 2006]\n  Allow zero-length IDAT chunks after the entire zlib datastream, but not\n    after another intervening chunk type.\n\nVersion 1.0.19rc1, 1.2.11rc1 [June 13, 2006]\n  Deleted extraneous square brackets from [config.h] in configure.ac\n\nVersion 1.0.19rc2, 1.2.11rc2 [June 14, 2006]\n  Added prototypes for PNG_INCH_CONVERSIONS functions to png.h\n  Revised INSTALL and autogen.sh\n  Fixed typo in several makefiles (-W1 should be -Wl)\n  Added typedef for png_int_32 and png_uint_32 on 64-bit systems.\n\nVersion 1.0.19rc3, 1.2.11rc3 [June 15, 2006]\n  Removed the new typedefs for 64-bit systems (delay until version 1.4.0)\n  Added one zero element to png_gamma_shift[] array in pngrtran.c to avoid\n    reading out of bounds.\n\nVersion 1.0.19rc4, 1.2.11rc4 [June 15, 2006]\n  Really removed the new typedefs for 64-bit systems.\n\nVersion 1.0.19rc5, 1.2.11rc5 [June 22, 2006]\n  Removed png_sig_bytes entry from scripts/pngw32.def\n\nVersion 1.0.19, 1.2.11 [June 26, 2006]\n  None.\n\nVersion 1.0.20, 1.2.12 [June 27, 2006]\n  Really increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid\n    buffer overflow.\n\nVersion 1.2.13beta1 [October 2, 2006]\n  Removed AC_FUNC_MALLOC from configure.ac\n  Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h\n  Change \"logical\" to \"bitwise\" throughout documentation.\n  Detect and fix attempt to write wrong iCCP profile length (CVE-2006-7244)\n\nVersion 1.0.21, 1.2.13 [November 14, 2006]\n  Fix potential buffer overflow in sPLT chunk handler.\n  Fix Makefile.am to not try to link to noexistent files.\n  Check all exported functions for NULL png_ptr.\n\nVersion 1.2.14beta1 [November 17, 2006]\n  Relocated three misplaced tests for NULL png_ptr.\n  Built Makefile.in with automake-1.9.6 instead of 1.9.2.\n  Build configure with autoconf-2.60 instead of 2.59\n\nVersion 1.2.14beta2 [November 17, 2006]\n  Added some typecasts in png_zalloc().\n\nVersion 1.2.14rc1 [November 20, 2006]\n  Changed \"strtod\" to \"png_strtod\" in pngrutil.c\n\nVersion 1.0.22, 1.2.14    [November 27, 2006]\n  Added missing \"$(srcdir)\" in Makefile.am and Makefile.in\n\nVersion 1.2.15beta1 [December 3, 2006]\n  Generated configure with autoconf-2.61 instead of 2.60\n  Revised configure.ac to update libpng.pc and libpng-config.\n\nVersion 1.2.15beta2 [December 3, 2006]\n  Always export MMX asm functions, just stubs if not building pnggccrd.c\n\nVersion 1.2.15beta3 [December 4, 2006]\n  Add \"png_bytep\" typecast to profile while calculating length in pngwutil.c\n\nVersion 1.2.15beta4 [December 7, 2006]\n  Added scripts/CMakeLists.txt\n  Changed PNG_NO_ASSEMBLER_CODE to PNG_NO_MMX_CODE in scripts, like 1.4.0beta\n\nVersion 1.2.15beta5 [December 7, 2006]\n  Changed some instances of PNG_ASSEMBLER_* to PNG_MMX_* in pnggccrd.c\n  Revised scripts/CMakeLists.txt\n\nVersion 1.2.15beta6 [December 13, 2006]\n  Revised scripts/CMakeLists.txt and configure.ac\n\nVersion 1.2.15rc1 [December 18, 2006]\n  Revised scripts/CMakeLists.txt\n\nVersion 1.2.15rc2 [December 21, 2006]\n  Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.\n  Added scripts/makefile.nommx\n\nVersion 1.2.15rc3 [December 25, 2006]\n  Fixed shared library numbering error that was introduced in 1.2.15beta6.\n\nVersion 1.2.15rc4 [December 27, 2006]\n  Fixed handling of rgb_to_gray when png_ptr->color.gray isn't set.\n\nVersion 1.2.15rc5 [December 31, 2006]\n  Revised handling of rgb_to_gray.\n\nVersion 1.2.15 [January 5, 2007]\n  Added some (unsigned long) typecasts in pngtest.c to avoid printing errors.\n\nVersion 1.2.16beta1 [January 6, 2007]\n  Fix bugs in makefile.nommx\n\nVersion 1.2.16beta2 [January 16, 2007]\n  Revised scripts/CMakeLists.txt\n\nVersion 1.2.16 [January 31, 2007]\n  No changes.\n\nVersion 1.2.17beta1 [March 6, 2007]\n  Revised scripts/CMakeLists.txt to install both shared and static libraries.\n  Deleted a redundant line from pngset.c.\n\nVersion 1.2.17beta2 [April 26, 2007]\n  Relocated misplaced test for png_ptr == NULL in pngpread.c\n  Change \"==\" to \"&\" for testing PNG_RGB_TO_GRAY_ERR & PNG_RGB_TO_GRAY_WARN\n    flags.\n  Changed remaining instances of PNG_ASSEMBLER_* to PNG_MMX_*\n  Added pngerror() when write_IHDR fails in deflateInit2().\n  Added \"const\" to some array declarations.\n  Mention examples of libpng usage in the libpng*.txt and libpng.3 documents.\n\nVersion 1.2.17rc1 [May 4, 2007]\n  No changes.\n\nVersion 1.2.17rc2 [May 8, 2007]\n  Moved several PNG_HAVE_* macros out of PNG_INTERNAL because applications\n    calling set_unknown_chunk_location() need them.\n  Changed transformation flag from PNG_EXPAND_tRNS to PNG_EXPAND in\n    png_set_expand_gray_1_2_4_to_8().\n  Added png_ptr->unknown_chunk to hold working unknown chunk data, so it\n    can be free'ed in case of error.  Revised unknown chunk handling in\n    pngrutil.c and pngpread.c to use this structure.\n\nVersion 1.2.17rc3 [May 8, 2007]\n  Revised symbol-handling in configure script.\n\nVersion 1.2.17rc4 [May 10, 2007]\n  Revised unknown chunk handling to avoid storing unknown critical chunks.\n\nVersion 1.0.25 [May 15, 2007]\nVersion 1.2.17 [May 15, 2007]\n  Added \"png_ptr->num_trans=0\" before error return in png_handle_tRNS,\n    to eliminate a vulnerability (CVE-2007-2445, CERT VU#684664)\n\nVersion 1.0.26 [May 15, 2007]\nVersion 1.2.18 [May 15, 2007]\n  Reverted the libpng-1.2.17rc3 change to symbol-handling in configure script\n\nVersion 1.2.19beta1 [May 18, 2007]\n  Changed \"const static\" to \"static PNG_CONST\" everywhere, mostly undoing\n    change of libpng-1.2.17beta2.  Changed other \"const\" to \"PNG_CONST\"\n  Changed some handling of unused parameters, to avoid compiler warnings.\n    \"if (unused == NULL) return;\" becomes \"unused = unused\".\n\nVersion 1.2.19beta2 [May 18, 2007]\n  Only use the valid bits of tRNS value in png_do_expand() (Brian Cartier)\n\nVersion 1.2.19beta3 [May 19, 2007]\n  Add some \"png_byte\" typecasts in png_check_keyword() and write new_key\n  instead of key in zTXt chunk (Kevin Ryde).\n\nVersion 1.2.19beta4 [May 21, 2007]\n  Add png_snprintf() function and use it in place of sprint() for improved\n    defense against buffer overflows.\n\nVersion 1.2.19beta5 [May 21, 2007]\n  Fixed png_handle_tRNS() to only use the valid bits of tRNS value.\n  Changed handling of more unused parameters, to avoid compiler warnings.\n  Removed some PNG_CONST in pngwutil.c to avoid compiler warnings.\n\nVersion 1.2.19beta6 [May 22, 2007]\n  Added some #ifdef PNG_MMX_CODE_SUPPORTED where needed in pngvcrd.c\n  Added a special \"_MSC_VER\" case that defines png_snprintf to _snprintf\n\nVersion 1.2.19beta7 [May 22, 2007]\n  Squelched png_squelch_warnings() in pnggccrd.c and added\n    an #ifdef PNG_MMX_CODE_SUPPORTED block around the declarations that caused\n    the warnings that png_squelch_warnings was squelching.\n\nVersion 1.2.19beta8 [May 22, 2007]\n  Removed __MMX__ from test in pngconf.h.\n\nVersion 1.2.19beta9 [May 23, 2007]\n  Made png_squelch_warnings() available via PNG_SQUELCH_WARNINGS macro.\n  Revised png_squelch_warnings() so it might work.\n  Updated makefile.sgcc and makefile.solaris; added makefile.solaris-x86.\n\nVersion 1.2.19beta10 [May 24, 2007]\n  Resquelched png_squelch_warnings(), use \"__attribute__((used))\" instead.\n\nVersion 1.4.0beta1 [April 20, 2006]\n  Enabled iTXt support (changes png_struct, thus requires so-number change).\n  Cleaned up PNG_ASSEMBLER_CODE_SUPPORTED vs PNG_MMX_CODE_SUPPORTED\n  Eliminated PNG_1_0_X and PNG_1_2_X macros.\n  Removed deprecated functions png_read_init, png_write_init, png_info_init,\n    png_permit_empty_plte, png_set_gray_1_2_4_to_8, png_check_sig, and\n    removed the deprecated macro PNG_MAX_UINT.\n  Moved \"PNG_INTERNAL\" parts of png.h and pngconf.h into pngintrn.h\n  Removed many WIN32_WCE #ifdefs (Cosmin).\n  Reduced dependency on C-runtime library when on Windows (Simon-Pierre)\n  Replaced sprintf() with png_sprintf() (Simon-Pierre)\n\nVersion 1.4.0beta2 [April 20, 2006]\n  Revised makefiles and configure to avoid making links to libpng.so.*\n  Moved some leftover MMX-related defines from pngconf.h to pngintrn.h\n  Updated scripts/pngos2.def, pngw32.def, and projects/wince/png32ce.def\n\nVersion 1.4.0beta3 [May 10, 2006]\n  Updated scripts/pngw32.def to comment out MMX functions.\n  Added PNG_NO_GET_INT_32 and PNG_NO_SAVE_INT_32 macros.\n  Scripts/libpng.pc.in contained \"configure\" style version info and would\n    not work with makefiles.\n  Revised pngconf.h and added pngconf.h.in, so makefiles and configure can\n    pass defines to libpng and applications.\n\nVersion 1.4.0beta4 [May 11, 2006]\n  Revised configure.ac, Makefile.am, and many of the makefiles to write\n    their defines in pngconf.h.\n\nVersion 1.4.0beta5 [May 15, 2006]\n  Added a missing semicolon in Makefile.am and Makefile.in\n  Deleted extraneous square brackets from configure.ac\n\nVersion 1.4.0beta6 [June 2, 2006]\n  Increased sprintf buffer from 50 to 52 chars in pngrutil.c to avoid\n    buffer overflow.\n  Changed sonum from 0 to 1.\n  Removed unused prototype for png_check_sig() from png.h\n\nVersion 1.4.0beta7 [June 16, 2006]\n  Exported png_write_sig (Cosmin).\n  Optimized buffer in png_handle_cHRM() (Cosmin).\n  Set pHYs = 2835 x 2835 pixels per meter, and added\n    sCAL = 0.352778e-3 x 0.352778e-3 meters, in pngtest.png (Cosmin).\n  Added png_set_benign_errors(), png_benign_error(), png_chunk_benign_error().\n  Added typedef for png_int_32 and png_uint_32 on 64-bit systems.\n  Added \"(unsigned long)\" typecast on png_uint_32 variables in printf lists.\n\nVersion 1.4.0beta8 [June 22, 2006]\n  Added demonstration of user chunk support in pngtest.c, to support the\n    public sTER chunk and a private vpAg chunk.\n\nVersion 1.4.0beta9 [July 3, 2006]\n  Removed ordinals from scripts/pngw32.def and removed png_info_int and\n    png_set_gray_1_2_4_to_8 entries.\n  Inline call of png_get_uint_32() in png_get_uint_31().\n  Use png_get_uint_31() to get vpAg width and height in pngtest.c\n  Removed WINCE and Netware projects.\n  Removed standalone Y2KINFO file.\n\nVersion 1.4.0beta10 [July 12, 2006]\n  Eliminated automatic copy of pngconf.h to pngconf.h.in from configure and\n    some makefiles, because it was not working reliably.  Instead, distribute\n    pngconf.h.in along with pngconf.h and cause configure and some of the\n    makefiles to update pngconf.h from pngconf.h.in.\n  Added pngconf.h to DEPENDENCIES in Makefile.am\n\nVersion 1.4.0beta11 [August 19, 2006]\n  Removed AC_FUNC_MALLOC from configure.ac.\n  Added a warning when writing iCCP profile with mismatched profile length.\n  Patched pnggccrd.c to assemble on x86_64 platforms.\n  Moved chunk header reading into a separate function png_read_chunk_header()\n    in pngrutil.c.  The chunk header (len+sig) is now serialized in a single\n    operation (Cosmin).\n  Implemented support for I/O states. Added png_ptr member io_state, and\n    functions png_get_io_chunk_name() and png_get_io_state() in pngget.c\n    (Cosmin).\n  Added png_get_io_chunk_name and png_get_io_state to scripts/*.def (Cosmin).\n  Renamed scripts/pngw32.* to scripts/pngwin.* (Cosmin).\n  Removed the include directories and libraries from CFLAGS and LDFLAGS\n    in scripts/makefile.gcc (Cosmin).\n  Used png_save_uint_32() to set vpAg width and height in pngtest.c (Cosmin).\n  Cast to proper type when getting/setting vpAg units in pngtest.c (Cosmin).\n  Added pngintrn.h to the Visual C++ projects (Cosmin).\n  Removed scripts/list (Cosmin).\n  Updated copyright year in scripts/pngwin.def (Cosmin).\n  Removed PNG_TYPECAST_NULL and used standard NULL consistently (Cosmin).\n  Disallowed the user to redefine png_size_t, and enforced a consistent use\n    of png_size_t across libpng (Cosmin).\n  Changed the type of png_ptr->rowbytes, PNG_ROWBYTES() and friends\n    to png_size_t (Cosmin).\n  Removed png_convert_size() and replaced png_sizeof with sizeof (Cosmin).\n  Removed some unnecessary type casts (Cosmin).\n  Changed prototype of png_get_compression_buffer_size() and\n    png_set_compression_buffer_size() to work with png_size_t instead of\n    png_uint_32 (Cosmin).\n  Removed png_memcpy_check() and png_memset_check() (Cosmin).\n  Fixed a typo (png_byte --> png_bytep) in libpng.3 and libpng.txt (Cosmin).\n  Clarified that png_zalloc() does not clear the allocated memory,\n    and png_zalloc() and png_zfree() cannot be PNGAPI (Cosmin).\n  Renamed png_mem_size_t to png_alloc_size_t, fixed its definition in\n    pngconf.h, and used it in all memory allocation functions (Cosmin).\n  Renamed pngintrn.h to pngpriv.h, added a comment at the top of the file\n    mentioning that the symbols declared in that file are private, and\n    updated the scripts and the Visual C++ projects accordingly (Cosmin).\n  Removed circular references between pngconf.h and pngconf.h.in in\n    scripts/makefile.vc*win32 (Cosmin).\n  Removing trailing '.' from the warning and error messages (Cosmin).\n  Added pngdefs.h that is built by makefile or configure, instead of\n    pngconf.h.in (Glenn).\n  Detect and fix attempt to write wrong iCCP profile length.\n\nVersion 1.4.0beta12 [October 19, 2006]\n  Changed \"logical\" to \"bitwise\" in the documentation.\n  Work around Intel-Mac compiler bug by setting PNG_NO_MMX_CODE in pngconf.h\n  Add a typecast to stifle compiler warning in pngrutil.c\n\nVersion 1.4.0beta13 [November 10, 2006]\n  Fix potential buffer overflow in sPLT chunk handler.\n  Fix Makefile.am to not try to link to noexistent files.\n\nVersion 1.4.0beta14 [November 15, 2006]\n  Check all exported functions for NULL png_ptr.\n\nVersion 1.4.0beta15 [November 17, 2006]\n  Relocated two misplaced tests for NULL png_ptr.\n  Built Makefile.in with automake-1.9.6 instead of 1.9.2.\n  Build configure with autoconf-2.60 instead of 2.59\n  Add \"install: all\" in Makefile.am so \"configure; make install\" will work.\n\nVersion 1.4.0beta16 [November 17, 2006]\n  Added a typecast in png_zalloc().\n\nVersion 1.4.0beta17 [December 4, 2006]\n  Changed \"new_key[79] = '\\0';\" to \"(*new_key)[79] = '\\0';\" in pngwutil.c\n  Add \"png_bytep\" typecast to profile while calculating length in pngwutil.c\n\nVersion 1.4.0beta18 [December 7, 2006]\n  Added scripts/CMakeLists.txt\n\nVersion 1.4.0beta19 [May 16, 2007]\n  Revised scripts/CMakeLists.txt\n  Rebuilt configure and Makefile.in with newer tools.\n  Added conditional #undef jmpbuf in pngtest.c to undo #define in AIX headers.\n  Added scripts/makefile.nommx\n\nVersion 1.4.0beta20 [July 9, 2008]\n  Moved several PNG_HAVE_* macros from pngpriv.h to png.h because applications\n    calling set_unknown_chunk_location() need them.\n  Moved several macro definitions from pngpriv.h to pngconf.h\n  Merge with changes to the 1.2.X branch, as of 1.2.30beta04.\n  Deleted all use of the MMX assembler code and Intel-licensed optimizations.\n  Revised makefile.mingw\n\nVersion 1.4.0beta21 [July 21, 2008]\n  Moved local array \"chunkdata\" from pngrutil.c to the png_struct, so\n    it will be freed by png_read_destroy() in case of a read error (Kurt\n    Christensen).\n\nVersion 1.4.0beta22 [July 21, 2008]\n  Change \"purpose\" and \"buffer\" to png_ptr->chunkdata to avoid memory leaking.\n\nVersion 1.4.0beta23 [July 22, 2008]\n  Change \"chunkdata = NULL\" to \"png_ptr->chunkdata = NULL\" several places in\n    png_decompress_chunk().\n\nVersion 1.4.0beta24 [July 25, 2008]\n  Change all remaining \"chunkdata\" to \"png_ptr->chunkdata\" in\n    png_decompress_chunk(), and remove \"chunkdata\" from parameter list.\n  Put a call to png_check_chunk_name() in png_read_chunk_header().\n  Revised png_check_chunk_name() to reject a name with a lowercase 3rd byte.\n  Removed two calls to png_check_chunk_name() occurring later in the process.\n  Define PNG_NO_ERROR_NUMBERS by default in pngconf.h\n\nVersion 1.4.0beta25 [July 30, 2008]\n  Added a call to png_check_chunk_name() in pngpread.c\n  Reverted png_check_chunk_name() to accept a name with a lowercase 3rd byte.\n  Added png_push_have_buffer() function to pngpread.c\n  Eliminated PNG_BIG_ENDIAN_SUPPORTED and associated png_get_* macros.\n  Made inline expansion of png_get_*() optional with PNG_USE_READ_MACROS.\n  Eliminated all PNG_USELESS_TESTS and PNG_CORRECT_PALETTE_SUPPORTED code.\n  Synced contrib directory and configure files with libpng-1.2.30beta06.\n  Eliminated no-longer-used pngdefs.h (but it's still built in the makefiles)\n  Relocated a misplaced \"#endif /* PNG_NO_WRITE_FILTER */\" in pngwutil.c\n\nVersion 1.4.0beta26 [August 4, 2008]\n  Removed png_push_have_buffer() function in pngpread.c.  It increased the\n    compiled library size slightly.\n  Changed \"-Wall\" to \"-W -Wall\" in the CFLAGS in all makefiles (Cosmin Truta)\n  Declared png_ptr \"volatile\" in pngread.c and pngwrite.c to avoid warnings.\n  Updated contrib/visupng/cexcept.h to version 2.0.1\n  Added PNG_LITERAL_CHARACTER macros for #, [, and ].\n\nVersion 1.4.0beta27 [August 5, 2008]\n  Revised usage of PNG_LITERAL_SHARP in pngerror.c.\n  Moved newline character from individual png_debug messages into the\n    png_debug macros.\n  Allow user to #define their own png_debug, png_debug1, and png_debug2.\n\nVersion 1.4.0beta28 [August 5, 2008]\n  Revised usage of PNG_LITERAL_SHARP in pngerror.c.\n  Added PNG_STRING_NEWLINE macro\n\nVersion 1.4.0beta29 [August 9, 2008]\n  Revised usage of PNG_STRING_NEWLINE to work on non-ISO compilers.\n  Added PNG_STRING_COPYRIGHT macro.\n  Added non-ISO versions of png_debug macros.\n\nVersion 1.4.0beta30 [August 14, 2008]\n  Added premultiplied alpha feature (Volker Wiendl).\n\nVersion 1.4.0beta31 [August 18, 2008]\n  Moved png_set_premultiply_alpha from pngtrans.c to pngrtran.c\n  Removed extra crc check at the end of png_handle_cHRM().  Bug introduced\n    in libpng-1.4.0beta20.\n\nVersion 1.4.0beta32 [August 19, 2008]\n  Added PNG_WRITE_FLUSH_SUPPORTED block around new png_flush() call.\n  Revised PNG_NO_STDIO version of png_write_flush()\n\nVersion 1.4.0beta33 [August 20, 2008]\n  Added png_get|set_chunk_cache_max() to limit the total number of sPLT,\n    text, and unknown chunks that can be stored.\n\nVersion 1.4.0beta34 [September 6, 2008]\n  Shortened tIME_string to 29 bytes in pngtest.c\n  Fixed off-by-one error introduced in png_push_read_zTXt() function in\n    libpng-1.2.30beta04/pngpread.c (Harald van Dijk)\n\nVersion 1.4.0beta35 [October 6, 2008]\n  Changed \"trans_values\" to \"trans_color\".\n  Changed so-number from 0 to 14.  Some OS do not like 0.\n  Revised makefile.darwin to fix shared library numbering.\n  Change png_set_gray_1_2_4_to_8() to png_set_expand_gray_1_2_4_to_8()\n    in example.c (debian bug report)\n\nVersion 1.4.0beta36 [October 25, 2008]\n  Sync with tEXt vulnerability fix in libpng-1.2.33rc02.\n\nVersion 1.4.0beta37 [November 13, 2008]\n  Added png_check_cHRM in png.c and moved checking from pngget.c, pngrutil.c,\n    and pngwrite.c\n\nVersion 1.4.0beta38 [November 22, 2008]\n  Added check for zero-area RGB cHRM triangle in png_check_cHRM() and\n    png_check_cHRM_fixed().\n\nVersion 1.4.0beta39 [November 23, 2008]\n  Revised png_warning() to write its message on standard output by default\n    when warning_fn is NULL.\n\nVersion 1.4.0beta40 [November 24, 2008]\n  Eliminated png_check_cHRM().  Instead, always use png_check_cHRM_fixed().\n  In png_check_cHRM_fixed(), ensure white_y is > 0, and removed redundant\n    check for all-zero coordinates that is detected by the triangle check.\n\nVersion 1.4.0beta41 [November 26, 2008]\n  Fixed string vs pointer-to-string error in png_check_keyword().\n  Rearranged test expressions in png_check_cHRM_fixed() to avoid internal\n    overflows.\n  Added PNG_NO_CHECK_cHRM conditional.\n\nVersion 1.4.0beta42, 43 [December 1, 2008]\n  Merge png_debug with version 1.2.34beta04.\n\nVersion 1.4.0beta44 [December 6, 2008]\n  Removed redundant check for key==NULL before calling png_check_keyword()\n    to ensure that new_key gets initialized and removed extra warning\n    (Merge with version 1.2.34beta05 -- Arvan Pritchard).\n\nVersion 1.4.0beta45 [December 9, 2008]\n  In png_write_png(), respect the placement of the filler bytes in an earlier\n    call to png_set_filler() (Jim Barry).\n\nVersion 1.4.0beta46 [December 10, 2008]\n  Undid previous change and added PNG_TRANSFORM_STRIP_FILLER_BEFORE and\n    PNG_TRANSFORM_STRIP_FILLER_AFTER conditionals and deprecated\n    PNG_TRANSFORM_STRIP_FILLER (Jim Barry).\n\nVersion 1.4.0beta47 [December 15, 2008]\n  Support for dithering was disabled by default, because it has never\n    been well tested and doesn't work very well.  The code has not\n    been removed, however, and can be enabled by building libpng with\n    PNG_READ_DITHER_SUPPORTED defined.\n\nVersion 1.4.0beta48 [February 14, 2009]\n  Added new exported function png_calloc().\n  Combined several instances of png_malloc(); png_memset() into png_calloc().\n  Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24\n    but was never defined.\n\nVersion 1.4.0beta49 [February 28, 2009]\n  Added png_fileno() macro to pngconf.h, used in pngwio.c\n  Corrected order of #ifdef's in png_debug definition in png.h\n  Fixed bug introduced in libpng-1.4.0beta48 with the memset arguments\n    for pcal_params.\n  Fixed order of #ifdef directives in the png_debug defines in png.h\n    (bug introduced in libpng-1.2.34/1.4.0beta29).\n  Revised comments in png_set_read_fn() and png_set_write_fn().\n\nVersion 1.4.0beta50 [March 18, 2009]\n  Use png_calloc() instead of png_malloc() to allocate big_row_buf when\n    reading an interlaced file, to avoid a possible UMR.\n  Undid revision of PNG_NO_STDIO version of png_write_flush().  Users\n    having trouble with fflush() can build with PNG_NO_WRITE_FLUSH defined\n    or supply their own flush_fn() replacement.\n  Revised libpng*.txt and png.h documentation about use of png_write_flush()\n    and png_set_write_fn().\n  Removed fflush() from pngtest.c.\n  Added \"#define PNG_NO_WRITE_FLUSH\" to contrib/pngminim/encoder/pngusr.h\n\nVersion 1.4.0beta51 [March 21, 2009]\n  Removed new png_fileno() macro from pngconf.h .\n\nVersion 1.4.0beta52 [March 27, 2009]\n  Relocated png_do_chop() ahead of building gamma tables in pngrtran.c\n    This avoids building 16-bit gamma tables unnecessarily.\n  Removed fflush() from pngtest.c.\n  Added \"#define PNG_NO_WRITE_FLUSH\" to contrib/pngminim/encoder/pngusr.h\n  Added a section on differences between 1.0.x and 1.2.x to libpng.3/libpng.txt\n\nVersion 1.4.0beta53 [April 1, 2009]\n  Removed some remaining MMX macros from pngpriv.h\n  Fixed potential memory leak of \"new_name\" in png_write_iCCP() (Ralph Giles)\n\nVersion 1.4.0beta54 [April 13, 2009]\n  Added \"ifndef PNG_SKIP_SETJMP_CHECK\" block in pngconf.h to allow\n    application code writers to bypass the check for multiple inclusion\n    of setjmp.h when they know that it is safe to ignore the situation.\n  Eliminated internal use of setjmp() in pngread.c and pngwrite.c\n  Reordered ancillary chunks in pngtest.png to be the same as what\n    pngtest now produces, and made some cosmetic changes to pngtest output.\n  Eliminated deprecated png_read_init_3() and png_write_init_3() functions.\n\nVersion 1.4.0beta55 [April 15, 2009]\n  Simplified error handling in pngread.c and pngwrite.c by putting\n    the new png_read_cleanup() and png_write_cleanup() functions inline.\n\nVersion 1.4.0beta56 [April 25, 2009]\n  Renamed \"user_chunk_data\" to \"my_user_chunk_data\" in pngtest.c to suppress\n    \"shadowed declaration\" warning from gcc-4.3.3.\n  Renamed \"gamma\" to \"png_gamma\" in pngset.c to avoid \"shadowed declaration\"\n    warning about a global \"gamma\" variable in math.h on some platforms.\n\nVersion 1.4.0beta57 [May 2, 2009]\n  Removed prototype for png_freeptr() that was added in libpng-1.4.0beta24\n    but was never defined (again).\n  Rebuilt configure scripts with autoconf-2.63 instead of 2.62\n  Removed pngprefs.h and MMX from makefiles\n\nVersion 1.4.0beta58 [May 14, 2009]\n  Changed pngw32.def to pngwin.def in makefile.mingw (typo was introduced\n    in beta57).\n  Clarified usage of sig_bit versus sig_bit_p in example.c (Vincent Torri)\n\nVersion 1.4.0beta59 [May 15, 2009]\n  Reformated sources in libpng style (3-space intentation, comment format)\n  Fixed typo in libpng docs (PNG_FILTER_AVE should be PNG_FILTER_AVG)\n  Added sections about the git repository and our coding style to the\n    documentation\n  Relocated misplaced #endif in pngwrite.c, sCAL chunk handler.\n\nVersion 1.4.0beta60 [May 19, 2009]\n  Conditionally compile png_read_finish_row() which is not used by\n    progressive readers.\n  Added contrib/pngminim/preader to demonstrate building minimal progressive\n    decoder, based on contrib/gregbook with embedded libpng and zlib.\n\nVersion 1.4.0beta61 [May 20, 2009]\n  In contrib/pngminim/*, renamed \"makefile.std\" to \"makefile\", since there\n    is only one makefile in those directories, and revised the README files\n    accordingly.\n  More reformatting of comments, mostly to capitalize sentences.\n\nVersion 1.4.0beta62 [June 2, 2009]\n  Added \"#define PNG_NO_WRITE_SWAP\" to contrib/pngminim/encoder/pngusr.h\n    and \"define PNG_NO_READ_SWAP\" to decoder/pngusr.h and preader/pngusr.h\n  Reformatted several remaining \"else statement\" into two lines.\n  Added a section to the libpng documentation about using png_get_io_ptr()\n    in configure scripts to detect the presence of libpng.\n\nVersion 1.4.0beta63 [June 15, 2009]\n  Revised libpng*.txt and libpng.3 to mention calling png_set_IHDR()\n    multiple times and to specify the sample order in the tRNS chunk,\n    because the ISO PNG specification has a typo in the tRNS table.\n  Changed several PNG_UNKNOWN_CHUNK_SUPPORTED to\n    PNG_HANDLE_AS_UNKNOWN_SUPPORTED, to make the png_set_keep mechanism\n    available for ignoring known chunks even when not saving unknown chunks.\n  Adopted preference for consistent use of \"#ifdef\" and \"#ifndef\" versus\n    \"#if defined()\" and \"if !defined()\" where possible.\n\nVersion 1.4.0beta64 [June 24, 2009]\n  Eliminated PNG_LEGACY_SUPPORTED code.\n  Moved the various unknown chunk macro definitions outside of the\n    PNG_READ|WRITE_ANCILLARY_CHUNK_SUPPORTED blocks.\n\nVersion 1.4.0beta65 [June 26, 2009]\n  Added a reference to the libpng license in each file.\n\nVersion 1.4.0beta66 [June 27, 2009]\n  Refer to the libpng license instead of the libpng license in each file.\n\nVersion 1.4.0beta67 [July 6, 2009]\n  Relocated INVERT_ALPHA within png_read_png() and png_write_png().\n  Added high-level API transform PNG_TRANSFORM_GRAY_TO_RGB.\n  Added an \"xcode\" project to the projects directory (Alam Arias).\n\nVersion 1.4.0beta68 [July 19, 2009]\n  Avoid some tests in filter selection in pngwutil.c\n\nVersion 1.4.0beta69 [July 25, 2009]\n  Simplified the new filter-selection test.  This runs faster in the\n    common \"PNG_ALL_FILTERS\" and PNG_FILTER_NONE cases.\n  Removed extraneous declaration from the new call to png_read_gray_to_rgb()\n    (bug introduced in libpng-1.4.0beta67).\n  Fixed up xcode project (Alam Arias)\n  Added a prototype for png_64bit_product() in png.c\n\nVersion 1.4.0beta70 [July 27, 2009]\n  Avoid a possible NULL dereference in debug build, in png_set_text_2().\n    (bug introduced in libpng-0.95, discovered by Evan Rouault)\n\nVersion 1.4.0beta71 [July 29, 2009]\n  Rebuilt configure scripts with autoconf-2.64.\n\nVersion 1.4.0beta72 [August 1, 2009]\n  Replaced *.tar.lzma with *.tar.xz in distribution.  Get the xz codec\n    from <http://tukaani.org/xz>.\n\nVersion 1.4.0beta73 [August 1, 2009]\n  Reject attempt to write iCCP chunk with negative embedded profile length\n    (JD Chen) (CVE-2009-5063).\n\nVersion 1.4.0beta74 [August 8, 2009]\n  Changed png_ptr and info_ptr member \"trans\" to \"trans_alpha\".\n\nVersion 1.4.0beta75 [August 21, 2009]\n  Removed an extra png_debug() recently added to png_write_find_filter().\n  Fixed incorrect #ifdef in pngset.c regarding unknown chunk support.\n\nVersion 1.4.0beta76 [August 22, 2009]\n  Moved an incorrectly located test in png_read_row() in pngread.c\n\nVersion 1.4.0beta77 [August 27, 2009]\n  Removed lpXYZ.tar.bz2 (with CRLF), KNOWNBUG, libpng-x.y.z-KNOWNBUG.txt,\n    and the \"noconfig\" files from the distribution.\n  Moved CMakeLists.txt from scripts into the main libpng directory.\n  Various bugfixes and improvements to CMakeLists.txt (Philip Lowman)\n\nVersion 1.4.0beta78 [August 31, 2009]\n  Converted all PNG_NO_* tests to PNG_*_SUPPORTED everywhere except pngconf.h\n  Eliminated PNG_NO_FREE_ME and PNG_FREE_ME_SUPPORTED macros.\n  Use png_malloc plus a loop instead of png_calloc() to initialize\n    row_pointers in png_read_png().\n\nVersion 1.4.0beta79 [September 1, 2009]\n  Eliminated PNG_GLOBAL_ARRAYS and PNG_LOCAL_ARRAYS; always use local arrays.\n  Eliminated PNG_CALLOC_SUPPORTED macro and always provide png_calloc().\n\nVersion 1.4.0beta80 [September 17, 2009]\n  Removed scripts/libpng.icc\n  Changed typecast of filler from png_byte to png_uint_16 in png_set_filler().\n    (Dennis Gustafsson)\n  Fixed typo introduced in beta78 in pngtest.c (\"#if def \" should be \"#ifdef \")\n\nVersion 1.4.0beta81 [September 23, 2009]\n  Eliminated unused PNG_FLAG_FREE_* defines from pngpriv.h\n  Expanded TAB characters in pngrtran.c\n  Removed PNG_CONST from all \"PNG_CONST PNG_CHNK\" declarations to avoid\n    compiler complaints about doubly declaring things \"const\".\n  Changed all \"#if [!]defined(X)\" to \"if[n]def X\" where possible.\n  Eliminated unused png_ptr->row_buf_size\n\nVersion 1.4.0beta82 [September 25, 2009]\n  Moved redundant IHDR checking into new png_check_IHDR() in png.c\n    and report all errors found in the IHDR data.\n  Eliminated useless call to png_check_cHRM() from pngset.c\n\nVersion 1.4.0beta83 [September 25, 2009]\n  Revised png_check_IHDR() to eliminate bogus complaint about filter_type.\n\nVersion 1.4.0beta84 [September 30, 2009]\n  Fixed some inconsistent indentation in pngconf.h\n  Revised png_check_IHDR() to add a test for width variable less than 32-bit.\n\nVersion 1.4.0beta85 [October 1, 2009]\n  Revised png_check_IHDR() again, to check info_ptr members instead of\n    the contents of the returned parameters.\n\nVersion 1.4.0beta86 [October 9, 2009]\n  Updated the \"xcode\" project (Alam Arias).\n  Eliminated a shadowed declaration of \"pp\" in png_handle_sPLT().\n\nVersion 1.4.0rc01 [October 19, 2009]\n  Trivial cosmetic changes.\n\nVersion 1.4.0beta87 [October 30, 2009]\n  Moved version 1.4.0 back into beta.\n\nVersion 1.4.0beta88 [October 30, 2009]\n  Revised libpng*.txt section about differences between 1.2.x and 1.4.0\n    because most of the new features have now been ported back to 1.2.41\n\nVersion 1.4.0beta89 [November 1, 2009]\n  More bugfixes and improvements to CMakeLists.txt (Philip Lowman)\n  Removed a harmless extra png_set_invert_alpha() from pngwrite.c\n  Apply png_user_chunk_cache_max within png_decompress_chunk().\n  Merged libpng-1.2.41.txt with libpng-1.4.0.txt where appropriate.\n\nVersion 1.4.0beta90 [November 2, 2009]\n  Removed all remaining WIN32_WCE #ifdefs except those involving the\n    time.h \"tm\" structure\n\nVersion 1.4.0beta91 [November 3, 2009]\n  Updated scripts/pngw32.def and projects/wince/png32ce.def\n  Copied projects/wince/png32ce.def to the scripts directory.\n  Added scripts/makefile.wce\n  Patched ltmain.sh for wince support.\n  Added PNG_CONVERT_tIME_SUPPORTED macro.\n\nVersion 1.4.0beta92 [November 4, 2009]\n  Make inclusion of time.h in pngconf.h depend on PNG_CONVERT_tIME_SUPPORTED\n  Make #define PNG_CONVERT_tIME_SUPPORTED depend on PNG_WRITE_tIME_SUPPORTED\n  Revised libpng*.txt to describe differences from 1.2.40 to 1.4.0 (instead\n    of differences from 1.2.41 to 1.4.0)\n\nVersion 1.4.0beta93 [November 7, 2009]\n  Added PNG_DEPSTRUCT, PNG_DEPRECATED, PNG_USE_RESULT, PNG_NORETURN, and\n    PNG_ALLOCATED macros to detect deprecated direct access to the\n    png_struct or info_struct members and other deprecated usage in\n    applications (John Bowler).\n  Updated scripts/makefile* to add \"-DPNG_CONFIGURE_LIBPNG\" to CFLAGS,\n    to prevent warnings about direct access to png structs by libpng\n    functions while building libpng.  They need to be tested, especially\n    those using compilers other than gcc.\n  Updated projects/visualc6 and visualc71 with \"/d PNG_CONFIGURE_LIBPNG\".\n    They should work but still need to be updated to remove\n    references to pnggccrd.c or pngvcrd.c and ASM building.\n  Added README.txt to the beos, cbuilder5, netware, and xcode projects warning\n    that they need to be updated, to remove references to pnggccrd.c and\n    pngvcrd.c and to depend on pngpriv.h\n  Removed three direct references to read_info_ptr members in pngtest.c\n    that were detected by the new PNG_DEPSTRUCT macro.\n  Moved the png_debug macro definitions and the png_read_destroy(),\n    png_write_destroy() and png_far_to_near() prototypes from png.h\n    to pngpriv.h (John Bowler)\n  Moved the synopsis lines for png_read_destroy(), png_write_destroy()\n    png_debug(), png_debug1(), and png_debug2() from libpng.3 to libpngpf.3.\n\nVersion 1.4.0beta94 [November 9, 2009]\n  Removed the obsolete, unused pnggccrd.c and pngvcrd.c files.\n  Updated CMakeLists.txt to add \"-DPNG_CONFIGURE_LIBPNG\" to the definitions.\n  Removed dependency of pngtest.o on pngpriv.h in the makefiles.\n  Only #define PNG_DEPSTRUCT, etc. in pngconf.h if not already defined.\n\nVersion 1.4.0beta95 [November 10, 2009]\n  Changed png_check_sig() to !png_sig_cmp() in contrib programs.\n  Added -DPNG_CONFIGURE_LIBPNG to contrib/pngminm/*/makefile\n  Changed png_check_sig() to !png_sig_cmp() in contrib programs.\n  Corrected the png_get_IHDR() call in contrib/gregbook/readpng2.c\n  Changed pngminim/*/gather.sh to stop trying to remove pnggccrd.c and pngvcrd.c\n  Added dependency on pngpriv.h in contrib/pngminim/*/makefile\n\nVersion 1.4.0beta96 [November 12, 2009]\n  Renamed scripts/makefile.wce to scripts/makefile.cegcc\n  Revised Makefile.am to use libpng.sys while building libpng.so\n    so that only PNG_EXPORT functions are exported.\n  Removed the deprecated png_check_sig() function/macro.\n  Removed recently removed function names from scripts/*.def\n  Revised pngtest.png to put chunks in the same order written by pngtest\n    (evidently the same change made in libpng-1.0beta54 was lost).\n  Added PNG_PRIVATE macro definition in pngconf.h for possible future use.\n\nVersion 1.4.0beta97 [November 13, 2009]\n  Restored pngtest.png to the libpng-1.4.0beta7 version.\n  Removed projects/beos and netware.txt; no one seems to be supporting them.\n  Revised Makefile.in\n\nVersion 1.4.0beta98 [November 13, 2009]\n  Added the \"xcode\" project to zip distributions,\n  Fixed a typo in scripts/pngwin.def introduced in beta97.\n\nVersion 1.4.0beta99 [November 14, 2009]\n  Moved libpng-config.in and libpng.pc-configure.in out of the scripts\n    directory, to libpng-config.in and libpng-pc.in, respectively, and\n    modified Makefile.am and configure.ac accordingly.  Now \"configure\"\n    needs nothing from the \"scripts\" directory.\n  Avoid redefining PNG_CONST in pngconf.h\n\nVersion 1.4.0beta100 [November 14, 2009]\n  Removed ASM builds from projects/visualc6 and projects/visualc71\n  Removed scripts/makefile.nommx and makefile.vcawin32\n  Revised CMakeLists.txt to account for new location of libpng-config.in\n    and libpng-pc.in\n  Updated INSTALL to reflect removal and relocation of files.\n\nVersion 1.4.0beta101 [November 14, 2009]\n  Restored the binary files (*.jpg, *.png, some project files) that were\n    accidentally deleted from the zip and 7z distributions when the xcode\n    project was added.\n\nVersion 1.4.0beta102 [November 18, 2009]\n  Added libpng-config.in and libpng-pc.in to the zip and 7z distributions.\n  Fixed a typo in projects/visualc6/pngtest.dsp, introduced in beta100.\n  Moved descriptions of makefiles and other scripts out of INSTALL into\n    scripts/README.txt\n  Updated the copyright year in scripts/pngwin.rc from 2006 to 2009.\n\nVersion 1.4.0beta103 [November 21, 2009]\n  Removed obsolete comments about ASM from projects/visualc71/README_zlib.txt\n  Align row_buf on 16-byte boundary in memory.\n  Restored the PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED guard around the call\n    to png_flush() after png_write_IEND().  See 1.4.0beta32, 1.4.0beta50\n    changes above and 1.2.30, 1.2.30rc01 and rc03 in 1.2.41 CHANGES.  Someone\n    needs this feature.\n  Make the 'png_jmpbuf' macro expand to a call that records the correct\n    longjmp function as well as returning a pointer to the setjmp\n    jmp_buf buffer, and marked direct access to jmpbuf 'deprecated'.\n    (John Bowler)\n\nVersion 1.4.0beta104 [November 22, 2009]\n  Removed png_longjmp_ptr from scripts/*.def and libpng.3\n  Rebuilt configure scripts with autoconf-2.65\n\nVersion 1.4.0beta105 [November 25, 2009]\n  Use fast integer PNG_DIVIDE_BY_255() or PNG_DIVIDE_BY_65535()\n    to accomplish alpha premultiplication when\n    PNG_READ_COMPOSITE_NODIV_SUPPORTED is defined.\n  Changed \"/255\" to \"/255.0\" in background calculations to make it clear\n    that the 255 is used as a double.\n\nVersion 1.4.0beta106 [November 27, 2009]\n  Removed premultiplied alpha feature.\n\nVersion 1.4.0beta107 [December 4, 2009]\n  Updated README\n  Added \"#define PNG_NO_PEDANTIC_WARNINGS\" in the libpng source files.\n  Removed \"-DPNG_CONFIGURE_LIBPNG\" from the makefiles and projects.\n  Revised scripts/makefile.netbsd, makefile.openbsd, and makefile.sco\n    to put png.h and pngconf.h in $prefix/include, like the other scripts,\n    instead of in $prefix/include/libpng.  Also revised makefile.sco\n    to put them in $prefix/include/libpng15 instead of in\n    $prefix/include/libpng/libpng15.\n\nVersion 1.4.0beta108 [December 11, 2009]\n  Removed leftover \"-DPNG_CONFIGURE_LIBPNG\" from contrib/pngminim/*/makefile\n  Relocated png_do_chop() to its original position in pngrtran.c; the\n    change in version 1.2.41beta08 caused transparency to be handled wrong\n    in some 16-bit datastreams (Yusaku Sugai).\n\nVersion 1.4.0beta109 [December 13, 2009]\n  Added \"bit_depth\" parameter to the private png_build_gamma_table() function.\n  Pass bit_depth=8 to png_build_gamma_table() when bit_depth is 16 but the\n    PNG_16_TO_8 transform has been set, to avoid unnecessary build of 16-bit\n    tables.\n\nVersion 1.4.0rc02 [December 20, 2009]\n  Declared png_cleanup_needed \"volatile\" in pngread.c and pngwrite.c\n\nVersion 1.4.0rc03 [December 22, 2009]\n  Renamed libpng-pc.in back to libpng.pc.in and revised CMakeLists.txt\n    (revising the change in 1.4.0beta99)\n\nVersion 1.4.0rc04 [December 25, 2009]\n  Swapped PNG_UNKNOWN_CHUNKS_SUPPORTED and PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n    in pngset.c to be consistent with other changes in version 1.2.38.\n\nVersion 1.4.0rc05 [December 25, 2009]\n  Changed \"libpng-pc.in\" to \"libpng.pc.in\" in configure.ac, configure, and\n    Makefile.in to be consistent with changes in libpng-1.4.0rc03\n\nVersion 1.4.0rc06 [December 29, 2009]\n  Reverted the gamma_table changes from libpng-1.4.0beta109.\n  Fixed some indentation errors.\n\nVersion 1.4.0rc07 [January 1, 2010]\n  Revised libpng*.txt and libpng.3 about 1.2.x->1.4.x differences.\n  Use png_calloc() instead of png_malloc(); png_memset() in pngrutil.c\n  Update copyright year to 2010.\n\nVersion 1.4.0rc08 [January 2, 2010]\n  Avoid deprecated references to png_ptr-io_ptr and png_ptr->error_ptr\n    in pngtest.c\n\nVersion 1.4.0 [January 3, 2010]\n  No changes.\n\nVersion 1.4.1beta01 [January 8, 2010]\n  Updated CMakeLists.txt for consistent indentation and to avoid an\n    unclosed if-statement warning (Philip Lowman).\n  Revised Makefile.am and Makefile.in to remove references to Y2KINFO,\n    KNOWNBUG, and libpng.la (Robert Schwebel).\n  Revised the makefiles to install the same files and symbolic\n    links as configure, except for libpng.la and libpng14.la.\n  Make png_set|get_compression_buffer_size() available even when\n    PNG_WRITE_SUPPORTED is not enabled.\n  Revised Makefile.am and Makefile.in to simplify their maintenance.\n  Revised scripts/makefile.linux to install a link to libpng14.so.14.1\n\nVersion 1.4.1beta02 [January 9, 2010]\n  Revised the rest of the makefiles to install a link to libpng14.so.14.1\n\nVersion 1.4.1beta03 [January 10, 2010]\n  Removed png_set_premultiply_alpha() from scripts/*.def\n\nVersion 1.4.1rc01 [January 16, 2010]\n  No changes.\n\nVersion 1.4.1beta04 [January 23, 2010]\n  Revised png_decompress_chunk() to improve speed and memory usage when\n    decoding large chunks.\n  Added png_set|get_chunk_malloc_max() functions.\n\nVersion 1.4.1beta05 [January 26, 2010]\n  Relocated \"int k\" declaration in pngtest.c to minimize its scope.\n\nVersion 1.4.1beta06 [January 28, 2010]\n  Revised png_decompress_chunk() to use a two-pass method suggested by\n    John Bowler.\n\nVersion 1.4.1beta07 [February 6, 2010]\n  Folded some long lines in the source files.\n  Added defineable PNG_USER_CHUNK_CACHE_MAX, PNG_USER_CHUNK_MALLOC_MAX,\n    and a PNG_USER_LIMITS_SUPPORTED flag.\n  Eliminated use of png_ptr->irowbytes and reused the slot in png_ptr as\n    png_ptr->png_user_chunk_malloc_max.\n  Revised png_push_save_buffer() to do fewer but larger png_malloc() calls.\n\nVersion 1.4.1beta08 [February 6, 2010]\n  Minor cleanup and updating of dates and copyright year.\n\nVersion 1.5.0beta01 [February 7, 2010]\n  Moved declaration of png_struct into private pngstruct.h and png_info\n    into pnginfo.h\n\nVersion 1.4.1beta09 and 1.5.0beta02 [February 7, 2010]\n  Reverted to original png_push_save_buffer() code.\n\nVersion 1.4.1beta10 and 1.5.0beta03 [February 8, 2010]\n  Return allocated \"old_buffer\" in png_push_save_buffer() before\n    calling png_error(), to avoid a potential memory leak.\n  Updated configure script to use SO number 15.\n\nVersion 1.5.0beta04 [February 9, 2010]\n  Removed malformed \"incomplete struct declaration\" of png_info from png.h\n\nVersion 1.5.0beta05 [February 12, 2010]\n  Removed PNG_DEPSTRUCT markup in pngstruct.h and pnginfo.h, and undid the\n    linewrapping that it entailed.\n  Revised comments in pngstruct.h and pnginfo.h and added pointers to\n    the libpng license.\n  Changed PNG_INTERNAL to PNG_EXPOSE_INTERNAL_STRUCTURES\n  Removed the cbuilder5 project, which has not been updated to 1.4.0.\n\nVersion 1.4.1beta12 and 1.5.0beta06 [February 14, 2010]\n  Fixed type declaration of png_get_chunk_malloc_max() in pngget.c (Daisuke\n    Nishikawa)\n\nVersion 1.5.0beta07 [omitted]\n\nVersion 1.5.0beta08 [February 19, 2010]\n  Changed #ifdef PNG_NO_STDIO_SUPPORTED to #ifdef PNG_NO_CONSOLE_IO_SUPPORTED\n    wherever png_snprintf() is used to construct error and warning messages.\n  Noted in scripts/makefile.mingw that it expects to be run under MSYS.\n  Removed obsolete unused MMX-querying support from contrib/gregbook\n  Added exported png_longjmp() function.\n  Removed the AIX redefinition of jmpbuf in png.h\n  Added -D_ALLSOURCE in configure.ac, makefile.aix, and CMakeLists.txt\n    when building on AIX.\n\nVersion 1.5.0beta09 [February 19, 2010]\n  Removed -D_ALLSOURCE from configure.ac, makefile.aix, and CMakeLists.txt.\n  Changed the name of png_ptr->jmpbuf to png_ptr->png_jmpbuf in pngstruct.h\n\nVersion 1.5.0beta10 [February 25, 2010]\n  Removed unused gzio.c from contrib/pngminim gather and makefile scripts\n  Removed replacement error handlers from contrib/gregbook.  Because of\n    the new png_longjmp() function they are no longer needed.\n\nVersion 1.5.0beta11 [March 6, 2010]\n  Removed checking for already-included setjmp.h from pngconf.h\n  Fixed inconsistent indentations and made numerous cosmetic changes.\n  Revised the \"SEE ALSO\" style of libpng.3, libpngpf.3, and png.5\n\nVersion 1.5.0beta12 [March 9, 2010]\n  Moved \"#include png.h\" inside pngpriv.h and removed \"#include png.h\" from\n    the source files, along with \"#define PNG_EXPOSE_INTERNAL_STRUCTURES\"\n    and \"#define PNG_NO_PEDANTIC_WARNINGS\" (John Bowler).\n  Created new pngdebug.h and moved debug definitions there.\n\nVersion 1.5.0beta13 [March 10, 2010]\n  Protect pngstruct.h, pnginfo.h, and pngdebug.h from being included twice.\n  Revise the \"#ifdef\" blocks in png_inflate() so it will compile when neither\n    PNG_USER_CHUNK_MALLOC_MAX nor PNG_SET_CHUNK_MALLOC_LIMIT_SUPPORTED\n    is defined.\n  Removed unused png_measure_compressed_chunk() from pngpriv.h and libpngpf.3\n  Moved the 'config.h' support from pngconf.h to pngpriv.h\n  Removed PNGAPI from the png_longjmp_ptr typedef.\n  Eliminated dependence of pngtest.c on the private pngdebug.h file.\n  Make all png_debug macros into *unterminated* statements or\n    expressions (i.e. a trailing ';' must always be added) and correct\n    the format statements in various png_debug messages.\n\nVersion 1.5.0beta14 [March 14, 2010]\n  Removed direct access to png_ptr->io_ptr from the Windows code in pngtest.c\n  Revised Makefile.am to account for recent additions and replacements.\n  Corrected CE and OS/2 DEF files (scripts/png*def) for symbols removed and\n    added ordinal numbers to the Windows DEF file and corrected the duplicated\n    ordinal numbers on CE symbols that are commented out.\n  Added back in export symbols that can be present in the Windows build but\n    are disabled by default.\n  PNG_EXPORT changed to include an 'ordinal' field for DEF file generation.\n    PNG_CALLBACK added to make callback definitions uniform.  PNGAPI split\n    into PNGCAPI (base C form), PNGAPI (exports) and PNGCBAPI (callbacks),\n    and appropriate changes made to all files.  Cygwin builds re-hinged to\n    allow procedure call standard changes and to remove the need for the DEF\n    file (fixes build on Cygwin).\n  Enabled 'attribute' warnings that are relevant to library APIs and callbacks.\n  Changed rules for generation of the various symbol files and added a new\n    rule for a DEF file (which is also added to the distribution).\n  Updated the symbol file generation to stop it adding spurious spaces\n    to EOL (coming from preprocessor macro expansion).  Added a facility\n    to join tokens in the output and rewrite *.dfn to use this.\n  Eliminated scripts/*.def in favor of libpng.def; updated projects/visualc71\n    and removed scripts/makefile.cygwin.\n  Made PNG_BUILD_DLL safe: it can be set whenever a DLL is being built.\n  Removed the include of sys/types.h - apparently unnecessary now on the\n    platforms on which it happened (all but Mac OS and RISC OS).\n  Moved the Mac OS test into pngpriv.h (the only place it is used.)\n\nVersion 1.5.0beta15 [March 17, 2010]\n  Added symbols.chk target to Makefile.am to validate the symbols in png.h\n    against the new DEF file scripts/symbols.def.\n  Changed the default DEF file back to pngwin.def.\n  Removed makefile.mingw.\n  Eliminated PNG_NO_EXTERN and PNG_ALL_EXTERN\n\nVersion 1.5.0beta16 [April 1, 2010]\n  Make png_text_struct independent of PNG_iTXt_SUPPORTED, so that\n    fields are initialized in all configurations.  The READ/WRITE\n    macros (PNG_(READ|WRITE)_iTXt_SUPPORTED) still function as\n    before to disable code to actually read or write iTXt chunks\n    and iTXt_SUPPORTED can be used to detect presence of either\n    read or write support (but it is probably better to check for\n    the one actually required - read or write.)\n  Combined multiple png_warning() calls for a single error.\n  Restored the macro definition of png_check_sig().\n\nVersion 1.5.0beta17 [April 17, 2010]\n  Added some \"(long)\" typecasts to printf calls in png_handle_cHRM().\n  Documented the fact that png_set_dither() was disabled since libpng-1.4.0.\n  Reenabled png_set_dither() but renamed it to png_set_quantize() to reflect\n    more accurately what it actually does.  At the same time, renamed\n    the PNG_DITHER_[RED,GREEN_BLUE]_BITS macros to\n    PNG_QUANTIZE_[RED,GREEN,BLUE]_BITS.\n  Added some \"(long)\" typecasts to printf calls in png_handle_cHRM().\n  Freeze build-time only configuration in the build.\n    In all prior versions of libpng most configuration options\n    controlled by compiler #defines had to be repeated by the\n    application code that used libpng.  This patch changes this\n    so that compilation options that can only be changed at build\n    time are frozen in the build.  Options that are compiler\n    dependent (and those that are system dependent) are evaluated\n    each time - pngconf.h holds these.  Options that can be changed\n    per-file in the application are in png.h.  Frozen options are\n    in the new installed header file pnglibconf.h (John Bowler)\n  Removed the xcode project because it has not been updated to work\n    with libpng-1.5.0.\n  Removed the ability to include optional pngusr.h\n\nVersion 1.5.0beta18 [April 17, 2010]\n  Restored the ability to include optional pngusr.h\n  Moved replacements for png_error() and png_warning() from the\n    contrib/pngminim project to pngerror.c, for use when warnings or\n    errors are disabled via PNG_NO_WARN or PNG_NO_ERROR_TEXT, to avoid\n    storing unneeded error/warning text.\n  Updated contrib/pngminim project to work with the new pnglibconf.h\n  Added some PNG_NO_* defines to contrib/pngminim/*/pngusr.h to save space.\n\nVersion 1.5.0beta19 [April 24, 2010]\n  Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED.  This allows the functions\n    to read and write ints to be disabled independently of PNG_USE_READ_MACROS,\n    which allows libpng to be built with the functions even though the default\n    is to use the macros - this allows applications to choose at app build\n    time whether or not to use macros (previously impossible because the\n    functions weren't in the default build.)\n  Changed Windows calling convention back to __cdecl for API functions.\n    For Windows/x86 platforms only:\n      __stdcall is no longer needed for Visual Basic, so libpng-1.5.0 uses\n      __cdecl throughout (both API functions and callbacks) on Windows/x86\n      platforms.\n  Replaced visualc6 and visualc71 projects with new vstudio project\n  Relaxed the overly-restrictive permissions of some files.\n\nVersion 1.5.0beta20 [April 24, 2010]\n  Relaxed more overly-restrictive permissions of some files.\n\nVersion 1.5.0beta21 [April 27, 2010]\n  Removed some unwanted binary bytes and changed CRLF to NEWLINE in the new\n    vstudio project files, and some trivial editing of some files in the\n    scripts directory.\n  Set PNG_NO_READ_BGR, PNG_NO_IO_STATE, and PNG_NO_TIME_RFC1123 in\n    contrib/pngminim/decoder/pngusr.h to make a smaller decoder application.\n\nVersion 1.5.0beta22 [April 28, 2010]\n  Fixed dependencies of GET_INT_32 - it does not require READ_INT_FUNCTIONS\n    because it has a macro equivalent.\n  Improved the options.awk script; added an \"everything off\" option.\n  Revised contrib/pngminim to use the \"everything off\" option in pngusr.dfa.\n\nVersion 1.5.0beta23 [April 29, 2010]\n  Corrected PNG_REMOVED macro to take five arguments.\n    The macro was documented with two arguments (name,ordinal), however\n    the symbol checking .dfn files assumed five arguments.  The five\n    argument form seems more useful so it is changed to that.\n  Corrected PNG_UNKNOWN_CHUNKS_SUPPORTED to PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n    in gregbook/readpng2.c\n  Corrected protection of png_get_user_transform_ptr. The API declaration in\n    png.h is removed if both READ and WRITE USER_TRANSFORM are turned off\n    but was left defined in pngtrans.c\n  Added logunsupported=1 to cause pnglibconf.h to document disabled options.\n    This makes the installed pnglibconf.h more readable but causes no\n    other change.  The intention is that users of libpng will find it\n    easier to understand if an API they need is missing.\n  Include png_reset_zstream() in png.c only when PNG_READ_SUPPORTED is defined.\n  Removed dummy_inflate.c from contrib/pngminim/encoder\n  Removed contrib/pngminim/*/gather.sh; gathering is now done in the makefile.\n\nVersion 1.5.0beta24 [May 7, 2010]\n  Use bitwise \"&\" instead of arithmetic mod in pngrutil.c calculation of the\n    offset of the png_ptr->rowbuf pointer into png_ptr->big_row_buf.\n  Added more blank lines for readability.\n\nVersion 1.5.0beta25 [June 18, 2010]\n  In pngpread.c: png_push_have_row() add check for new_row > height\n  Removed the now-redundant check for out-of-bounds new_row from example.c\n\nVersion 1.5.0beta26 [June 18, 2010]\n  In pngpread.c: png_push_process_row() add check for too many rows.\n\nVersion 1.5.0beta27 [June 18, 2010]\n  Removed the check added in beta25 as it is now redundant.\n\nVersion 1.5.0beta28 [June 20, 2010]\n  Rewrote png_process_IDAT_data to consistently treat extra data as warnings\n    and handle end conditions more cleanly.\n  Removed the new (beta26) check in png_push_process_row().\n\nVersion 1.5.0beta29 [June 21, 2010]\n  Revised scripts/options.awk to work on Sunos (but still doesn't work)\n  Added comment to options.awk and contrib/pngminim/*/makefile to try nawk.\n\nVersion 1.5.0beta30 [June 22, 2010]\n  Stop memory leak when reading a malformed sCAL chunk.\n\nVersion 1.5.0beta31 [June 26, 2010]\n  Revised pngpread.c patch of beta28 to avoid an endless loop.\n  Removed some trailing blanks.\n\nVersion 1.5.0beta32 [June 26, 2010]\n  Removed leftover scripts/options.patch and scripts/options.rej\n\nVersion 1.5.0beta33 [July 6, 3010]\n  Made FIXED and FLOATING options consistent in the APIs they enable and\n    disable.  Corrected scripts/options.awk to handle both command line\n    options and options specified in the .dfa files.\n  Changed char *msg to PNG_CONST char *msg in pngrutil.c\n  Make png_set_sRGB_gAMA_and_cHRM set values using either the fixed or\n    floating point APIs, but not both.\n  Reversed patch to remove error handler when the jmp_buf is stored in the\n    main program structure, not the png_struct.\n    The error handler is needed because the default handler in libpng will\n    always use the jmp_buf in the library control structure; this is never\n    set.  The gregbook code is a useful example because, even though it\n    uses setjmp/longjmp, it shows how error handling can be implemented\n    using control mechanisms not directly supported by libpng.  The\n    technique will work correctly with mechanisms such as Microsoft\n    Structure Exceptions or C++ exceptions (compiler willing - note that gcc\n    does not by default support interworking of C and C++ error handling.)\n  Reverted changes to call png_longjmp in contrib/gregbook where it is not\n    appropriate.  If mainprog->jmpbuf is used by setjmp, then png_longjmp\n    cannot be used.\n  Changed \"extern PNG_EXPORT\" to \"PNG_EXPORT\" in png.h (Jan Nijtmans)\n  Changed \"extern\" to \"PNG_EXTERN\" in pngpriv.h (except for the 'extern \"C\" {')\n\nVersion 1.5.0beta34 [July 12, 2010]\n  Put #ifndef PNG_EXTERN, #endif around the define PNG_EXTERN in pngpriv.h\n\nVersion 1.5.0beta35 [July 24, 2010]\n  Removed some newly-added TAB characters.\n  Added -DNO_PNG_SNPRINTF to CFLAGS in scripts/makefile.dj2\n  Moved the definition of png_snprintf() outside of the enclosing\n    #ifdef blocks in pngconf.h\n\nVersion 1.5.0beta36 [July 29, 2010]\n  Patches by John Bowler:\n  Fixed point APIs are now supported throughout (no missing APIs).\n  Internal fixed point arithmetic support exists for all internal floating\n    point operations.\n  sCAL validates the floating point strings it is passed.\n  Safe, albeit rudimentary, Watcom support is provided by PNG_API_RULE==2\n  Two new APIs exist to get the number of passes without turning on the\n    PNG_INTERLACE transform and to get the number of rows in the current\n    pass.\n  A new test program, pngvalid.c, validates the gamma code.\n  Errors in the 16-bit gamma correction (overflows) have been corrected.\n  cHRM chunk testing is done consistently (previously the floating point\n    API bypassed it, because the test really didn't work on FP, now the test\n    is performed on the actual values to be stored in the PNG file so it\n    works in the FP case too.)\n  Most floating point APIs now simply call the fixed point APIs after\n    converting the values to the fixed point form used in the PNG file.\n  The standard headers no longer include zlib.h, which is currently only\n    required for pngstruct.h and can therefore be internal.\n  Revised png_get_int_32 to undo the PNG two's complement representation of\n    negative numbers.\n\nVersion 1.5.0beta37 [July 30, 2010]\n  Added a typecast in png_get_int_32() in png.h and pngrutil.h to avoid\n    a compiler warning.\n  Replaced oFFs 0,0 with oFFs -10,20 in pngtest.png\n\nVersion 1.5.0beta38 [July 31, 2010]\n  Implemented remaining \"_fixed\" functions.\n  Corrected a number of recently introduced warnings mostly resulting from\n    safe but uncast assignments to shorter integers.  Also added a zlib\n    VStudio release library project because the latest zlib Official Windows\n    build does not include such a thing.\n  Revised png_get_int_16() to be similar to png_get_int_32().\n  Restored projects/visualc71.\n\nVersion 1.5.0beta39 [August 2, 2010]\n  VisualC/GCC warning fixes, VisualC build fixes\n  The changes include support for function attributes in VC in addition to\n    those already present in GCC - necessary because without these some\n    warnings are unavoidable.  Fixes include signed/unsigned fixes in\n    pngvalid and checks with gcc -Wall -Wextra -Wunused.\n  VC requires function attributes on function definitions as well as\n    declarations, PNG_FUNCTION has been added to enable this and the\n    relevant function definitions changed.\n\nVersion 1.5.0beta40 [August 6, 2010]\n  Correct use of _WINDOWS_ in pngconf.h\n  Removed png_mem_ #defines; they are no longer used.\n  Added the sRGB chunk to pngtest.png\n\nVersion 1.5.0beta41 [August 11, 2010]\n  Added the cHRM chunk to pngtest.png\n  Don't try to use version-script with cygwin/mingw.\n  Revised contrib/gregbook to work under cygwin/mingw.\n\nVersion 1.5.0beta42 [August 18, 2010]\n  Add .dll.a to the list of extensions to be symlinked by Makefile.am (Yaakov)\n  Made all API functions that have const arguments and constant string\n    literal pointers declare them (John Bowler).\n\nVersion 1.5.0beta43 [August 20, 2010]\n  Removed spurious tabs, shorten long lines (no source change)\n    Also added scripts/chkfmt to validate the format of all the files that can\n    reasonably be validated (it is suggested to run \"make distclean\" before\n    checking, because some machine generated files have long lines.)\n  Reformatted the CHANGES file to be more consistent throughout.\n  Made changes to address various issues identified by GCC, mostly\n    signed/unsigned and shortening problems on assignment but also a few\n    difficult to optimize (for GCC) loops.\n  Fixed non-GCC fixed point builds.  In png.c a declaration was misplaced\n    in an earlier update.  Fixed to declare the auto variables at the head.\n  Use cexcept.h in pngvalid.c.\n\nVersion 1.5.0beta44 [August 24, 2010]\n  Updated CMakeLists.txt to use CMAKE_INSTALL_LIBDIR variable; useful for\n    installing libpng in /usr/lib64 (Funda Wang).\n  Revised CMakeLists.txt to put the man pages in share/man/man* not man/man*\n  Revised CMakeLists.txt to make symlinks instead of copies when installing.\n  Changed PNG_LIB_NAME from pngNN to libpngNN in CMakeLists.txt (Philip Lowman)\n  Implemented memory checks within pngvalid\n  Reformatted/rearranged pngvalid.c to assist use of progressive reader.\n  Check interlaced images in pngvalid\n  Clarified pngusr.h comments in pnglibconf.dfa\n  Simplified the pngvalid error-handling code now that cexcept.h is in place.\n  Implemented progressive reader in pngvalid.c for standard tests\n  Implemented progressive read in pngvalid.c gamma tests\n  Turn on progressive reader in pngvalid.c by default and tidy code.\n\nVersion 1.5.0beta45 [August 26, 2010]\n  Added an explicit make step to projects/vstudio for pnglibconf.h\n    Also corrected zlib.vcxproj into which Visual Studio had introduced\n    what it calls an \"authoring error\".  The change to make pnglibconf.h\n    simply copies the file; in the future it may actually generate the\n    file from scripts/pnglibconf.dfa as the other build systems do.\n  Changed pngvalid to work when floating point APIs are disabled\n  Renamed the prebuilt scripts/pnglibconf.h to scripts/pnglibconf.h.prebuilt\n  Supply default values for PNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX\n    in pngpriv.h in case the user neglected to define them in their pngusr.h\n\nVersion 1.5.0beta46 [August 28, 2010]\n  Added new private header files to libpng_sources in CMakeLists.txt\n  Added PNG_READ_16BIT, PNG_WRITE_16BIT, and PNG_16BIT options.\n  Added reference to scripts/pnglibconf.h.prebuilt in the visualc71 project.\n\nVersion 1.5.0beta47 [September 11, 2010]\n  Fixed a number of problems with 64-bit compilation reported by Visual\n    Studio 2010 (John Bowler).\n\nVersion 1.5.0beta48 [October 4, 2010]\n  Updated CMakeLists.txt (Philip Lowman).\n  Revised autogen.sh to recognize and use $AUTOCONF, $AUTOMAKE, $AUTOHEADER,\n    $AUTOPOINT, $ACLOCAL and $LIBTOOLIZE\n  Fixed problem with symbols creation in Makefile.am which was assuming that\n    all versions of ccp write to standard output by default (Martin Banky). The\n    bug was introduced in libpng-1.2.9beta5.\n  Removed unused mkinstalldirs.\n\nVersion 1.5.0beta49 [October 8, 2010]\n  Undid Makefile.am revision of 1.5.0beta48.\n\nVersion 1.5.0beta50 [October 14, 2010]\n  Revised Makefile.in to account for mkinstalldirs being removed.\n  Added some \"(unsigned long)\" typecasts in printf statements in pngvalid.c.\n  Suppressed a compiler warning in png_handle_sPLT().\n  Check for out-of-range text compression mode in png_set_text().\n\nVersion 1.5.0beta51 [October 15, 2010]\n  Changed embedded dates to \"(PENDING RELEASE) in beta releases (and future\n    rc releases) to minimize the difference between releases.\n\nVersion 1.5.0beta52 [October 16, 2010]\n  Restored some of the embedded dates (in png.h, png.c, documentation, etc.)\n\nVersion 1.5.0beta53 [October 18, 2010]\n  Updated INSTALL to mention using \"make maintainer-clean\" and to remove\n    obsolete statement about a custom ltmain.sh\n  Disabled \"color-tests\" by default in Makefile.am so it will work with\n    automake versions earlier than 1.11.1\n  Use document name \"libpng-manual.txt\" instead of \"libpng-<version>.txt\"\n    to simplify version differences.\n  Removed obsolete remarks about setjmp handling from INSTALL.\n  Revised and renamed the typedef in png.h and png.c that was designed\n    to catch library and header mismatch.\n\nVersion 1.5.0beta54 [November 10, 2010]\n  Require 48 bytes, not 64 bytes, for big_row_buf in overflow checks.\n  Used a consistent structure for the pngget.c functions.\n\nVersion 1.5.0beta55 [November 21, 2010]\n  Revised png_get_uint_32, png_get_int_32, png_get_uint_16 (Cosmin)\n  Moved reading of file signature into png_read_sig (Cosmin)\n  Fixed atomicity of chunk header serialization (Cosmin)\n  Added test for io_state in pngtest.c (Cosmin)\n  Added \"#!/bin/sh\" at the top of contrib/pngminim/*/gather.sh scripts.\n  Changes to remove gcc warnings (John Bowler)\n    Certain optional gcc warning flags resulted in warnings in libpng code.\n    With these changes only -Wconversion and -Wcast-qual cannot be turned on.\n    Changes are trivial rearrangements of code.  -Wconversion is not possible\n    for pngrutil.c (because of the widespread use of += et al on variables\n    smaller than (int) or (unsigned int)) and -Wcast-qual is not possible\n    with pngwio.c and pngwutil.c because the 'write' callback and zlib\n    compression both fail to declare their input buffers with 'const'.\n\nVersion 1.5.0beta56 [December 7, 2010]\n  Added the private PNG_UNUSED() macro definition in pngpriv.h.\n  Added some commentary about PNG_EXPORT in png.h and pngconf.h\n  Revised PNG_EXPORT() macro and added PNG_EXPORTA() macro, with the\n    objective of simplifying and improving the cosmetic appearance of png.h.\n  Fixed some incorrect \"=\" macro names in pnglibconf.dfa\n  Included documentation of changes in 1.5.0 from 1.4.x in libpng-manual.txt\n\nVersion 1.5.0beta57 [December 9, 2010]\n  Documented the pngvalid gamma error summary with additional comments and\n    print statements.\n  Improved missing symbol handling in checksym.awk; symbols missing in both\n    the old and new files can now be optionally ignored, treated as errors\n    or warnings.\n  Removed references to pngvcrd.c and pnggccrd.c from the vstudio project.\n  Updated \"libpng14\" to \"libpng15\" in the visualc71 project.\n  Enabled the strip16 tests in pngvalid.`\n  Don't display test results (except PASS/FAIL) when running \"make test\".\n    Instead put them in pngtest-log.txt\n  Added \"--with-zprefix=<string>\" to configure.ac\n  Updated the prebuilt configuration files to autoconf version 2.68\n\nVersion 1.5.0beta58 [December 19, 2010]\n  Fixed interlace image handling and add test cases (John Bowler)\n  Fixed the clean rule in Makefile.am to remove pngtest-log.txt\n  Made minor changes to work around warnings in gcc 3.4\n\nVersion 1.5.0rc01 [December 27, 2010]\n  No changes.\n\nVersion 1.5.0rc02 [December 27, 2010]\n  Eliminated references to the scripts/*.def files in project/visualc71.\n\nVersion 1.5.0rc03 [December 28, 2010]\n  Eliminated scripts/*.def and revised Makefile.am accordingly\n\nVersion 1.5.0rc04 [December 29, 2010]\n  Fixed bug in background transformation handling in pngrtran.c (it was\n    looking for the flag in png_ptr->transformations instead of in\n    png_ptr->flags) (David Raymond).\n\nVersion 1.5.0rc05 [December 31, 2010]\n  Fixed typo in a comment in CMakeLists.txt (libpng14 => libpng15) (Cosmin)\n\nVersion 1.5.0rc06 [January 4, 2011]\n  Changed the new configure option \"zprefix=string\" to \"zlib-prefix=string\"\n\nVersion 1.5.0rc07 [January 4, 2011]\n  Updated copyright year.\n\nVersion 1.5.0 [January 6, 2011]\n  No changes.\n\nversion 1.5.1beta01 [January 8, 2011]\n  Added description of png_set_crc_action() to the manual.\n  Added a note in the manual that the type of the iCCP profile was changed\n    from png_charpp to png_bytepp in png_get_iCCP().  This change happened\n    in version 1.5.0beta36 but is not noted in the CHANGES.  Similarly,\n    it was changed from png_charpp to png_const_bytepp in png_set_iCCP().\n  Ensure that png_rgb_to_gray ignores palette mapped images, if libpng\n    internally happens to call it with one, and fixed a failure to handle\n    palette mapped images correctly.  This fixes CVE-2690.\n\nVersion 1.5.1beta02 [January 14, 2011]\n  Fixed a bug in handling of interlaced images (bero at arklinux.org).\n  Updated CMakeLists.txt (Clifford Yapp)\n\nVersion 1.5.1beta03 [January 14, 2011]\n  Fixed typecasting of some png_debug() statements (Cosmin)\n\nVersion 1.5.1beta04 [January 16, 2011]\n  Updated documentation of png_set|get_tRNS() (Thomas Klausner).\n  Mentioned in the documentation that applications must #include \"zlib.h\"\n    if they need access to anything in zlib.h, and that a number of\n    macros such as png_memset() are no longer accessible by applications.\n  Corrected pngvalid gamma test \"sample\" function to access all of the color\n    samples of each pixel, instead of sampling the red channel three times.\n  Prefixed variable names index, div, exp, gamma with \"png_\" to avoid \"shadow\"\n    warnings, and (mistakenly) changed png_exp() to exp().\n\nVersion 1.5.1beta05 [January 16, 2011]\n  Changed variable names png_index, png_div, png_exp, and png_gamma to\n    char_index, divisor, exp_b10, and gamma_val, respectively, and\n    changed exp() back to png_exp().\n\nVersion 1.5.1beta06 [January 20, 2011]\n  Prevent png_push_crc_skip() from hanging while reading an unknown chunk\n    or an over-large compressed zTXt chunk with the progressive reader.\n  Eliminated more GCC \"shadow\" warnings.\n  Revised png_fixed() in png.c to avoid compiler warning about reaching the\n    end without returning anything.\n\nVersion 1.5.1beta07 [January 22, 2011]\n  In the manual, describe the png_get_IHDR() arguments in the correct order.\n  Added const_png_structp and const_png_infop types, and used them in\n    prototypes for most png_get_*() functions.\n\nVersion 1.5.1beta08 [January 23, 2011]\n  Added png_get_io_chunk_type() and deprecated png_get_io_chunk_name()\n  Added synopses for the IO_STATE functions and other missing synopses\n    to the manual. Removed the synopses from libpngpf.3 because they\n    were out of date and no longer useful.  Better information can be\n    obtained by reading the prototypes and comments in pngpriv.h\n  Attempted to fix cpp on Solaris with S. Studio 12 cc, fix build\n    Added a make macro DFNCPP that is a CPP that will accept the tokens in\n    a .dfn file and adds configure stuff to test for such a CPP.  ./configure\n    should fail if one is not available.\n  Corrected const_png_ in png.h to png_const_ to avoid polluting the namespace.\n  Added png_get_current_row_number and png_get_current_pass_number for the\n    benefit of the user transform callback.\n  Added png_process_data_pause and png_process_data_skip for the benefit of\n    progressive readers that need to stop data processing or want to optimize\n    skipping of unread data (e.g., if the reader marks a chunk to be skipped.)\n\nVersion 1.5.1beta09 [January 24, 2011]\n  Enhanced pngvalid, corrected an error in gray_to_rgb, corrected doc error.\n    pngvalid contains tests of transforms, which tests are currently disabled\n    because they are incompletely tested.  gray_to_rgb was failing to expand\n    the bit depth for smaller bit depth images; this seems to be a long\n    standing error and resulted, apparently, in invalid output\n    (CVE-2011-0408, CERT VU#643140).  The documentation did not accurately\n    describe what libpng really does when converting RGB to gray.\n\nVersion 1.5.1beta10 [January 27, 2010]\n  Fixed incorrect examples of callback prototypes in the manual, that were\n    introduced in libpng-1.0.0.\n  In addition the order of the png_get_uint macros with respect to the\n    relevant function definitions has been reversed.  This helps the\n    preprocessing of the symbol files be more robust.  Furthermore, the\n    symbol file preprocessing now uses -DPNG_NO_USE_READ_MACROS even when\n    the library may actually be built with PNG_USE_READ_MACROS; this stops\n    the read macros interfering with the symbol file format.\n  Made the manual, synopses, and function prototypes use the function\n    argument names file_gamma, int_file_gamma, and srgb_intent consistently.\n\nVersion 1.5.1beta11 [January 28, 2011]\n  Changed PNG_UNUSED from \"param=param;\" to \"{if(param){}}\".\n  Corrected local variable type in new API png_process_data_skip()\n    The type was self-evidently incorrect but only causes problems on 64-bit\n    architectures.\n  Added transform tests to pngvalid and simplified the arguments.\n\nVersion 1.5.1rc01 [January 29, 2011]\n  No changes.\n\nVersion 1.5.1rc02 [January 31, 2011]\n  Added a request in the manual that applications do not use \"png_\" or\n    \"PNG_\" to begin any of their own symbols.\n  Changed PNG_UNUSED to \"(void)param;\" and updated the commentary in pngpriv.h\n\nVersion 1.5.1 [February 3, 2011]\n  No changes.\n\nVersion 1.5.2beta01 [February 13, 2011]\n  More -Wshadow fixes for older gcc compilers.  Older gcc versions apparently\n    check formal parameters names in function declarations (as well as\n    definitions) to see if they match a name in the global namespace.\n  Revised PNG_EXPORTA macro to not use an empty parameter, to accommodate the\n    old VisualC++ preprocessor.\n  Turned on interlace handling in png_read_png().\n  Fixed gcc pendantic warnings.\n  Handle longjmp in Cygwin.\n  Fixed png_get_current_row_number() in the interlaced case.\n  Cleaned up ALPHA flags and transformations.\n  Implemented expansion to 16 bits.\n\nVersion 1.5.2beta02 [February 19, 2011]\n  Fixed mistake in the descriptions of user read_transform and write_transform\n    function prototypes in the manual.  The row_info struct is png_row_infop.\n  Reverted png_get_current_row_number() to previous (1.5.2beta01) behavior.\n  Corrected png_get_current_row_number documentation\n  Fixed the read/write row callback documentation.\n    This documents the current behavior, where the callback is called after\n    every row with information pertaining to the next row.\n\nVersion 1.5.2beta03 [March 3, 2011]\n  Fixed scripts/makefile.vcwin32\n  Updated contrib/pngsuite/README to add the word \"modify\".\n  Define PNG_ALLOCATED to blank when _MSC_VER<1300.\n\nVersion 1.5.2rc01 [March 19, 2011]\n  Define remaining attributes to blank when MSC_VER<1300.\n  ifdef out mask arrays in pngread.c when interlacing is not supported.\n\nVersion 1.5.2rc02 [March 22, 2011]\n  Added a hint to try CPP=/bin/cpp if \"cpp -E\" fails in scripts/pnglibconf.mak\n    and in contrib/pngminim/*/makefile, eg., on SunOS 5.10, and removed \"strip\"\n    from the makefiles.\n  Fixed a bug (present since libpng-1.0.7) that makes png_handle_sPLT() fail\n    to compile when PNG_NO_POINTER_INDEXING is defined (Chubanov Kirill)\n\nVersion 1.5.2rc03 [March 24, 2011]\n  Don't include standard header files in png.h while building the symbol table,\n    to avoid cpp failure on SunOS (introduced PNG_BUILDING_SYMBOL_TABLE macro).\n\nVersion 1.5.2 [March 31, 2011]\n  No changes.\n\nVersion 1.5.3beta01 [April 1, 2011]\n  Re-initialize the zlib compressor before compressing non-IDAT chunks.\n  Added API functions (png_set_text_compression_level() and four others) to\n    set parameters for zlib compression of non-IDAT chunks.\n\nVersion 1.5.3beta02 [April 3, 2011]\n  Updated scripts/symbols.def with new API functions.\n  Only compile the new zlib re-initializing code when text or iCCP is\n    supported, using PNG_WRITE_COMPRESSED_TEXT_SUPPORTED macro.\n  Improved the optimization of the zlib CMF byte (see libpng-1.2.6beta03).\n  Optimize the zlib CMF byte in non-IDAT compressed chunks\n\nVersion 1.5.3beta03 [April 16, 2011]\n  Fixed gcc -ansi -pedantic compile. A strict ANSI system does not have\n    snprintf, and the \"__STRICT_ANSI__\" detects that condition more reliably\n    than __STDC__ (John Bowler).\n  Removed the PNG_PTR_NORETURN attribute because it too dangerous. It tells\n    the compiler that a user supplied callback (the error handler) does not\n    return, yet there is no guarantee in practice that the application code\n    will correctly implement the error handler because the compiler only\n    issues a warning if there is a mistake (John Bowler).\n  Removed the no-longer-used PNG_DEPSTRUCT macro.\n  Updated the zlib version to 1.2.5 in the VStudio project.\n  Fixed 64-bit builds where png_uint_32 is smaller than png_size_t in\n    pngwutil.c (John Bowler).\n  Fixed bug with stripping the filler or alpha channel when writing, that\n    was introduced in libpng-1.5.2beta01 (bug report by Andrew Church).\n\nVersion 1.5.3beta04 [April 27, 2011]\n  Updated pngtest.png with the new zlib CMF optimization.\n  Cleaned up conditional compilation code and of background/gamma handling\n    Internal changes only except a new option to avoid compiling the\n    png_build_grayscale_palette API (which is not used at all internally.)\n    The main change is to move the transform tests (READ_TRANSFORMS,\n    WRITE_TRANSFORMS) up one level to the caller of the APIs.  This avoids\n    calls to spurious functions if all transforms are disabled and slightly\n    simplifies those functions.  Pngvalid modified to handle this.\n    A minor change is to stop the strip_16 and expand_16 interfaces from\n    disabling each other; this allows the future alpha premultiplication\n    code to use 16-bit intermediate values while still producing 8-bit output.\n    png_do_background and png_do_gamma have been simplified to take a single\n    pointer to the png_struct rather than pointers to every item required\n    from the png_struct. This makes no practical difference to the internal\n    code.\n  A serious bug in the pngvalid internal routine 'standard_display_init' has\n    been fixed - this failed to initialize the red channel and accidentally\n    initialized the alpha channel twice.\n  Changed png_struct jmp_buf member name from png_jmpbuf to tmp_jmpbuf to\n    avoid a possible clash with the png_jmpbuf macro on some platforms.\n\nVersion 1.5.3beta05 [May 6, 2011]\n  Added the \"_POSIX_SOURCE\" feature test macro to ensure libpng sees the\n    correct API. _POSIX_SOURCE is defined in pngpriv.h, pngtest.c and\n    pngvalid.c to ensure that POSIX conformant systems disable non-POSIX APIs.\n  Removed png_snprintf and added formatted warning messages.  This change adds\n    internal APIs to allow png_warning messages to have parameters without\n    requiring the host OS to implement snprintf.  As a side effect the\n    dependency of the tIME-supporting RFC1132 code on stdio is removed and\n    PNG_NO_WARNINGS does actually work now.\n  Pass \"\" instead of '\\0' to png_default_error() in png_err().  This mistake\n    was introduced in libpng-1.2.20beta01.  This fixes CVE-2011-2691.\n  Added PNG_WRITE_OPTIMIZE_CMF_SUPPORTED macro to make the zlib \"CMF\" byte\n    optimization configureable.\n  IDAT compression failed if preceded by a compressed text chunk (bug\n    introduced in libpng-1.5.3beta01-02).  This was because the attempt to\n    reset the zlib stream in png_write_IDAT happened after the first IDAT\n    chunk had been deflated - much too late.  In this change internal\n    functions were added to claim/release the z_stream and, hopefully, make\n    the code more robust.  Also deflateEnd checking is added - previously\n    libpng would ignore an error at the end of the stream.\n\nVersion 1.5.3beta06 [May 8, 2011]\n  Removed the -D_ALL_SOURCE from definitions for AIX in CMakeLists.txt\n  Implemented premultiplied alpha support: png_set_alpha_mode API\n\nVersion 1.5.3beta07 [May 11, 2011]\n  Added expand_16 support to the high level interface.\n  Added named value and 'flag' gamma support to png_set_gamma.  Made a minor\n    change from the previous (unreleased) ABI/API to hide the exact value used\n    for Macs - it's not a good idea to embed this in the ABI!\n  Moved macro definitions for PNG_HAVE_IHDR, PNG_HAVE_PLTE, and PNG_AFTER_IDAT\n    from pngpriv.h to png.h because they must be visible to applications\n    that call png_set_unknown_chunks().\n  Check for up->location !PNG_AFTER_IDAT when writing unknown chunks\n    before IDAT.\n\nVersion 1.5.3beta08 [May 16, 2011]\n  Improved \"pngvalid --speed\" to exclude more of pngvalid from the time.\n  Documented png_set_alpha_mode(), other changes in libpng.3/libpng-manual.txt\n  The cHRM chunk now sets the defaults for png_set_rgb_to_gray() (when negative\n    parameters are supplied by the caller), while in the absence of cHRM\n    sRGB/Rec 709 values are still used.  This introduced a divide-by-zero\n    bug in png_handle_cHRM().\n  The bKGD chunk no longer overwrites the background value set by\n    png_set_background(), allowing the latter to be used before the file\n    header is read. It never performed any useful function to override\n    the default anyway.\n  Added memory overwrite and palette image checks to pngvalid.c\n    Previously palette image code was poorly checked. Since the transformation\n    code has a special palette path in most cases this was a severe weakness.\n  Minor cleanup and some extra checking in pngrutil.c and pngrtran.c. When\n    expanding an indexed image, always expand to RGBA if transparency is\n    present.\n\nVersion 1.5.3beta09 [May 17, 2011]\n  Reversed earlier 1.5.3 change of transformation order; move png_expand_16\n    back where it was.  The change doesn't work because it requires 16-bit\n    gamma tables when the code only generates 8-bit ones.  This fails\n    silently; the libpng code just doesn't do any gamma correction.  Moving\n    the tests back leaves the old, inaccurate, 8-bit gamma calculations, but\n    these are clearly better than none!\n\nVersion 1.5.3beta10 [May 20, 2011]\n\n  png_set_background() and png_expand_16() did not work together correctly.\n    This problem is present in 1.5.2; if png_set_background is called with\n    need_expand false and the matching 16 bit color libpng erroneously just\n    treats it as an 8-bit color because of where png_do_expand_16 is in the\n    transform list.  This simple fix reduces the supplied colour to 8-bits,\n    so it gets smashed, but this is better than the current behavior.\n  Added tests for expand16, more fixes for palette image tests to pngvalid.\n    Corrects the code for palette image tests and disables attempts to\n    validate palette colors.\n\nVersion 1.5.3rc01 [June 3, 2011]\n  No changes.\n\nVersion 1.5.3rc02 [June 8, 2011]\n  Fixed uninitialized memory read in png_format_buffer() (Bug report by\n    Frank Busse, CVE-2011-2501, related to CVE-2004-0421).\n\nVersion 1.5.3beta11 [June 11, 2011]\n  Fixed png_handle_sCAL which is broken in 1.5. This fixes CVE 2011-2692.\n  Added sCAL to pngtest.png\n  Revised documentation about png_set_user_limits() to say that it also affects\n    png writing.\n  Revised handling of png_set_user_limits() so that it can increase the\n    limit beyond the PNG_USER_WIDTH|HEIGHT_MAX; previously it could only\n    reduce it.\n  Make the 16-to-8 scaling accurate. Dividing by 256 with no rounding is\n    wrong (high by one) 25% of the time. Dividing by 257 with rounding is\n    wrong in 128 out of 65536 cases. Getting the right answer all the time\n    without division is easy.\n  Added \"_SUPPORTED\" to the PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION macro.\n  Added projects/owatcom, an IDE project for OpenWatcom to replace\n    scripts/makefile.watcom.  This project works with OpenWatcom 1.9. The\n    IDE autogenerates appropriate makefiles (libpng.mk) for batch processing.\n    The project is configurable, unlike the Visual Studio project, so long\n    as the developer has an awk.\n  Changed png_set_gAMA to limit the gamma value range so that the inverse\n    of the stored value cannot overflow the fixed point representation,\n    and changed other things OpenWatcom warns about.\n  Revised pngvalid.c to test PNG_ALPHA_MODE_SUPPORTED correctly. This allows\n    pngvalid to build when ALPHA_MODE is not supported, which is required if\n    it is to build on libpng 1.4.\n  Removed string/memory macros that are no longer used and are not\n    necessarily fully supportable, particularly png_strncpy and png_snprintf.\n  Added log option to pngvalid.c and attempted to improve gamma messages.\n\nVersion 1.5.3 [omitted]\n  People found the presence of a beta release following an rc release\n    to be confusing; therefore we bump the version to libpng-1.5.4beta01\n    and there will be no libpng-1.5.3 release.\n\nVersion 1.5.4beta01 [June 14, 2011]\n  Made it possible to undefine PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\n    to get the same (inaccurate) output as libpng-1.5.2 and earlier.\n  Moved definitions of PNG_HAVE_IHDR, PNG_AFTER_IDAT, and PNG_HAVE_PLTE\n    outside of an unknown-chunk block in png.h because they are also\n    needed for other uses.\n\nVersion 1.5.4beta02 [June 14, 2011]\n  Fixed and clarified LEGACY 16-to-8 scaling code.\n  Added png_set_chop_16() API, to match inaccurate results from previous\n    libpng versions.\n  Removed the ACCURATE and LEGACY options (they are no longer useable)\n  Use the old scaling method for background if png_set_chop_16() was\n    called.\n  Made png_set_chop_16() API removeable by disabling PNG_CHOP_16_TO_8_SUPPORTED\n\nVersion 1.5.4beta03 [June 15, 2011]\n  Fixed a problem in png_do_expand_palette() exposed by optimization in\n    1.5.3beta06\n  Also removed a spurious and confusing \"trans\" member (\"trans\") from png_info.\n  The palette expand optimization prevented expansion to an intermediate RGBA\n    form if tRNS was present but alpha was marked to be stripped; this exposed\n    a check for tRNS in png_do_expand_palette() which is inconsistent with the\n    code elsewhere in libpng.\n  Correction to the expand_16 code; removed extra instance of\n    png_set_scale_16_to_8 from pngpriv.h\n\nVersion 1.5.4beta04 [June 16, 2011]\n  Added a missing \"#ifdef PNG_READ_BACKGROUND_SUPPORTED/#endif\" in pngrtran.c\n  Added PNG_TRANSFORM_CHOP_16 to the high-level read transforms.\n  Made PNG_READ_16_TO_8_ACCURATE_SCALE configurable again.  If this is\n    not enabled, png_set_strip_16() and png_do_scale_16_to_8() aren't built.\n  Revised contrib/visupng, gregbook, and pngminim to demonstrate chop_16_to_8\n\nVersion 1.5.4beta05 [June 16, 2011]\n  Renamed png_set_strip_16() to png_set_scale_16() and renamed\n    png_set_chop_16() to png_set_strip(16) in an attempt to minimize the\n    behavior changes between libpng14 and libpng15.\n\nVersion 1.5.4beta06 [June 18, 2011]\n  Fixed new bug that was causing both strip_16 and scale_16 to be applied.\n\nVersion 1.5.4beta07 [June 19, 2011]\n  Fixed pngvalid, simplified macros, added checking for 0 in sCAL.\n    The ACCURATE scale macro is no longer defined in 1.5 - call the\n    png_scale_16_to_8 API.  Made sure that PNG_READ_16_TO_8 is still defined\n    if the png_strip_16_to_8 API is present.  png_check_fp_number now\n    maintains some state so that positive, negative and zero values are\n    identified.  sCAL uses these to be strictly spec conformant.\n\nVersion 1.5.4beta08 [June 23, 2011]\n  Fixed pngvalid if ACCURATE_SCALE is defined.\n  Updated scripts/pnglibconf.h.prebuilt.\n\nVersion 1.5.4rc01 [June 30, 2011]\n  Define PNG_ALLOCATED to \"restrict\" only if MSC_VER >= 1400.\n\nVersion 1.5.4 [July 7, 2011]\n  No changes.\n\nVersion 1.5.5beta01 [July 13, 2011]\n  Fixed some typos and made other minor changes in the manual.\n  Updated contrib/pngminus/makefile.std (Samuli Souminen)\n\nVersion 1.5.5beta02 [July 14, 2011]\n  Revised Makefile.am and Makefile.in to look in the right directory for\n    pnglibconf.h.prebuilt\n\nVersion 1.5.5beta03 [July 27, 2011]\n  Enabled compilation with g++ compiler.  This compiler does not recognize\n    the file extension, so it always compiles with C++ rules.  Made minor\n    changes to pngrutil.c to cast results where C++ expects it but C does not.\n  Minor editing of libpng.3 and libpng-manual.txt.\n\nVersion 1.5.5beta04 [July 29, 2011]\n  Revised CMakeLists.txt (Clifford Yapp)\n  Updated commentary about the png_rgb_to_gray() default coefficients\n    in the manual and in pngrtran.c\n\nVersion 1.5.5beta05 [August 17, 2011]\n  Prevent unexpected API exports from non-libpng DLLs on Windows.  The \"_DLL\"\n    is removed from the test of whether a DLL is being built (this erroneously\n    caused the libpng APIs to be marked as DLL exports in static builds under\n    Microsoft Visual Studio).  Almost all of the libpng building configuration\n    is moved from pngconf.h to pngpriv.h, but PNG_DLL_EXPORT remains in\n    pngconf.h, though, so that it is colocated with the import definition (it\n    is no longer used anywhere in the installed headers).  The VStudio project\n    definitions have been cleaned up: \"_USRDLL\" has been removed from the\n    static library builds (this was incorrect), and PNG_USE_DLL has been added\n    to pngvalid to test the functionality (pngtest does not supply it,\n    deliberately).  The spurious \"_EXPORTS\" has been removed from the\n    libpng build (all these errors were a result of copy/paste between project\n    configurations.)\n  Added new types and internal functions for CIE RGB end point handling to\n    pngpriv.h (functions yet to be implemented).\n\nVersion 1.5.5beta06 [August 26, 2011]\n  Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set in CMakeLists.txt\n    (Clifford Yap)\n  Fixes to rgb_to_gray and cHRM XYZ APIs (John Bowler):\n    The rgb_to_gray code had errors when combined with gamma correction.\n    Some pixels were treated as true grey when they weren't and such pixels\n    and true grey ones were not gamma corrected (the original value of the\n    red component was used instead).  APIs to get and set cHRM using color\n    space end points have been added and the rgb_to_gray code that defaults\n    based on cHRM, and the divide-by-zero bug in png_handle_cHRM (CERT\n    VU#477046, CVE-2011-3328, introduced in 1.5.4) have been corrected.\n  A considerable number of tests has been added to pngvalid for the\n    rgb_to_gray transform.\n  Arithmetic errors in rgb_to_gray whereby the calculated gray value was\n    truncated to the bit depth rather than rounded have been fixed except in\n    the 8-bit non-gamma-corrected case (where consistency seems more important\n    than correctness.)  The code still has considerable inaccuracies in the\n    8-bit case because 8-bit linear arithmetic is used.\n\nVersion 1.5.5beta07 [September 7, 2011]\n  Added \"$(ARCH)\" option to makefile.darwin\n  Added SunOS support to configure.ac and Makefile.am\n  Changed png_chunk_benign_error() to png_warning() in png.c, in\n    png_XYZ_from_xy_checked().\n\nVersion 1.5.5beta08 [September 10, 2011]\n  Fixed 64-bit compilation errors (gcc). The errors fixed relate\n    to conditions where types that are 32 bits in the GCC 32-bit\n    world (uLong and png_size_t) become 64 bits in the 64-bit\n    world.  This produces potential truncation errors which the\n    compiler correctly flags.\n  Relocated new HAVE_SOLARIS_LD definition in configure.ac\n  Constant changes for 64-bit compatibility (removal of L suffixes). The\n    16-bit cases still use \"L\" as we don't have a 16-bit test system.\n\nVersion 1.5.5rc01 [September 15, 2011]\n  Removed \"L\" suffixes in pngpriv.h\n\nVersion 1.5.5 [September 22, 2011]\n  No changes.\n\nVersion 1.5.6beta01 [September 22, 2011]\n  Fixed some 64-bit type conversion warnings in pngrtran.c\n  Moved row_info from png_struct to a local variable.\n  The various interlace mask arrays have been made into arrays of\n    bytes and made PNG_CONST and static (previously some arrays were\n    marked PNG_CONST and some weren't).\n  Additional checks have been added to the transform code to validate the\n    pixel depths after the transforms on both read and write.\n  Removed some redundant code from pngwrite.c, in png_destroy_write_struct().\n  Changed chunk reading/writing code to use png_uint_32 instead of png_byte[4].\n    This removes the need to allocate temporary strings for chunk names on\n    the stack in the read/write code.  Unknown chunk handling still uses the\n    string form because this is exposed in the API.\n\nVersion 1.5.6beta02 [September 26, 2011]\n  Added a note in the manual the png_read_update_info() must be called only\n    once with a particular info_ptr.\n  Fixed a typo in the definition of the new PNG_STRING_FROM_CHUNK(s,c) macro.\n\nVersion 1.5.6beta03 [September 28, 2011]\n  Revised test-pngtest.sh to report FAIL when pngtest fails.\n  Added \"--strict\" option to pngtest, to report FAIL when the failure is\n    only because the resulting valid files are different.\n  Revised CMakeLists.txt to work with mingw and removed some material from\n    CMakeLists.txt that is no longer useful in libpng-1.5.\n\nVersion 1.5.6beta04 [October 5, 2011]\n  Fixed typo in Makefile.in and Makefile.am (\"-M Wl\" should be \"-M -Wl\").\"\n\nVersion 1.5.6beta05 [October 12, 2011]\n  Speed up png_combine_row() for interlaced images. This reduces the generality\n    of the code, allowing it to be optimized for Adam7 interlace.  The masks\n    passed to png_combine_row() are now generated internally, avoiding\n    some code duplication and localizing the interlace handling somewhat.\n  Align png_struct::row_buf - previously it was always unaligned, caused by\n    a bug in the code that attempted to align it; the code needs to subtract\n    one from the pointer to take account of the filter byte prepended to\n    each row.\n  Optimized png_combine_row() when rows are aligned. This gains a small\n    percentage for 16-bit and 32-bit pixels in the typical case where the\n    output row buffers are appropriately aligned. The optimization was not\n    previously possible because the png_struct buffer was always misaligned.\n  Fixed bug in png_write_chunk_header() debug print, introduced in 1.5.6beta01.\n\nVersion 1.5.6beta06 [October 17, 2011]\n  Removed two redundant tests for unitialized row.\n  Fixed a relatively harmless memory overwrite in compressed text writing\n    with a 1 byte zlib buffer.\n  Add ability to call png_read_update_info multiple times to pngvalid.c.\n  Fixes for multiple calls to png_read_update_info. These fixes attend to\n    most of the errors revealed in pngvalid, however doing the gamma work\n    twice results in inaccuracies that can't be easily fixed.  There is now\n    a warning in the code if this is going to happen.\n  Turned on multiple png_read_update_info in pngvalid transform tests.\n  Prevent libpng from overwriting unused bits at the end of the image when\n    it is not byte aligned, while reading. Prior to libpng-1.5.6 libpng would\n    overwrite the partial byte at the end of each row if the row width was not\n    an exact multiple of 8 bits and the image is not interlaced.\n\nVersion 1.5.6beta07 [October 21, 2011]\n  Made png_ptr->prev_row an aligned pointer into png_ptr->big_prev_row\n    (Mans Rullgard).\n\nVersion 1.5.6rc01 [October 26, 2011]\n  Changed misleading \"Missing PLTE before cHRM\" warning to \"Out of place cHRM\"\n\nVersion 1.5.6rc02 [October 27, 2011]\n  Added LSR() macro to defend against buggy compilers that evaluate non-taken\n    code branches and complain about out-of-range shifts.\n\nVersion 1.5.6rc03 [October 28, 2011]\n  Renamed the LSR() macro to PNG_LSR() and added PNG_LSL() macro.\n  Fixed compiler warnings with Intel and MSYS compilers. The logical shift\n    fix for Microsoft Visual C is required by other compilers, so this\n    enables that fix for all compilers when using compile-time constants.\n    Under MSYS 'byte' is a name declared in a system header file, so we\n    changed the name of a local variable to avoid the warnings that result.\n  Added #define PNG_ALIGN_TYPE PNG_ALIGN_NONE to contrib/pngminim/*/pngusr.h\n\nVersion 1.5.6 [November 3, 2011]\n  No changes.\n\nVersion 1.5.7beta01 [November 4, 2011]\n  Added support for ARM processor, when decoding all PNG up-filtered rows\n    and any other-filtered rows with 3 or 4 bytes per pixel (Mans Rullgard).\n  Fixed bug in pngvalid on early allocation failure; fixed type cast in\n    pngmem.c; pngvalid would attempt to call png_error() if the allocation\n    of a png_struct or png_info failed. This would probably have led to a\n    crash.  The pngmem.c implementation of png_malloc() included a cast\n    to png_size_t which would fail on large allocations on 16-bit systems.\n  Fix for the preprocessor of the Intel C compiler. The preprocessor\n    splits adjacent @ signs with a space; this changes the concatentation\n    token from @-@-@ to PNG_JOIN; that should work with all compiler\n    preprocessors.\n  Paeth filter speed improvements from work by Siarhei Siamashka. This\n    changes the 'Paeth' reconstruction function to improve the GCC code\n    generation on x86. The changes are only part of the suggested ones;\n    just the changes that definitely improve speed and remain simple.\n    The changes also slightly increase the clarity of the code.\n\nVersion 1.5.7beta02 [November 11, 2011]\n  Check compression_type parameter in png_get_iCCP and remove spurious\n    casts. The compression_type parameter is always assigned to, so must\n    be non-NULL. The cast of the profile length potentially truncated the\n    value unnecessarily on a 16-bit int system, so the cast of the (byte)\n    compression type to (int) is specified by ANSI-C anyway.\n  Fixed FP division by zero in pngvalid.c; the 'test_pixel' code left\n    the sBIT fields in the test pixel as 0, which resulted in a floating\n    point division by zero which was irrelevant but causes systems where\n    FP exceptions cause a crash. Added code to pngvalid to turn on FP\n    exceptions if the appropriate glibc support is there to ensure this is\n    tested in the future.\n  Updated scripts/pnglibconf.mak and scripts/makefile.std to handle the\n    new PNG_JOIN macro.\n  Added versioning to pnglibconf.h comments.\n  Simplified read/write API initial version; basic read/write tested on\n    a variety of images, limited documentation (in the header file.)\n  Installed more accurate linear to sRGB conversion tables. The slightly\n    modified tables reduce the number of 16-bit values that\n    convert to an off-by-one 8-bit value.  The \"makesRGB.c\" code that was used\n    to generate the tables is now in a contrib/sRGBtables sub-directory.\n\nVersion 1.5.7beta03 [November 17, 2011]\n  Removed PNG_CONST from the sRGB table declarations in pngpriv.h and png.c\n  Added run-time detection of NEON support.\n  Added contrib/libtests; includes simplified API test and timing test and\n    a color conversion utility for rapid checking of failed 'pngstest' results.\n  Multiple transform bug fixes plus a work-round for double gamma correction.\n    libpng does not support more than one transform that requires linear data\n    at once - if this is tried typically the results is double gamma\n    correction. Since the simplified APIs can need rgb to gray combined with\n    a compose operation it is necessary to do one of these outside the main\n    libpng transform code. This check-in also contains fixes to various bugs\n    in the simplified APIs themselves and to some bugs in compose and rgb to\n    gray (on palette) itself.\n  Fixes for C++ compilation using g++ When libpng source is compiled\n    using g++. The compiler imposes C++ rules on the C source; thus it\n    is desireable to make the source work with either C or C++ rules\n    without throwing away useful error information.  This change adds\n    png_voidcast to allow C semantic (void*) cases or the corresponding\n    C++ static_cast operation, as appropriate.\n  Added --noexecstack to assembler file compilation. GCC does not set\n    this on assembler compilation, even though it does on C compilation.\n    This creates security issues if assembler code is enabled; the\n    work-around is to set it by default in the flags for $(CCAS)\n  Work around compilers that don't support declaration of const data. Some\n    compilers fault 'extern const' data declarations (because the data is\n    not initialized); this turns on const-ness only for compilers where\n    this is known to work.\n\nVersion 1.5.7beta04 [November 17, 2011]\n  Since the gcc driver does not recognize the --noexecstack flag, we must\n    use the -Wa prefix to have it passed through to the assembler.\n    Also removed a duplicate setting of this flag.\n  Added files that were omitted from the libpng-1.5.7beta03 zip distribution.\n\nVersion 1.5.7beta05 [November 25, 2011]\n  Removed \"zTXt\" from warning in generic chunk decompression function.\n  Validate time settings passed to png_set_tIME() and png_convert_to_rfc1123()\n    (Frank Busse). Note: This prevented CVE-2015-7981 from affecting\n    libpng-1.5.7 and later.\n  Added MINGW support to CMakeLists.txt\n  Reject invalid compression flag or method when reading the iTXt chunk.\n  Backed out 'simplified' API changes. The API seems too complex and there\n    is a lack of consensus or enthusiasm for the proposals.  The API also\n    reveals significant bugs inside libpng (double gamma correction and the\n    known bug of being unable to retrieve a corrected palette). It seems\n    better to wait until the bugs, at least, are corrected.\n  Moved pngvalid.c into contrib/libtests\n  Rebuilt Makefile.in, configure, etc., with autoconf-2.68\n\nVersion 1.5.7rc01 [December 1, 2011]\n  Replaced an \"#if\" with \"#ifdef\" in pngrtran.c\n  Revised #if PNG_DO_BC block in png.c (use #ifdef and add #else)\n\nVersion 1.5.7rc02 [December 5, 2011]\n  Revised project files and contrib/pngvalid/pngvalid.c to account for\n    the relocation of pngvalid into contrib/libtests.\n  Revised pngconf.h to use \" __declspec(restrict)\" only when MSC_VER >= 1400,\n    as in libpng-1.5.4.\n  Put CRLF line endings in the owatcom project files.\n\nVersion 1.5.7rc03 [December 7, 2011]\n  Updated CMakeLists.txt to account for the relocation of pngvalid.c\n\nVersion 1.5.7 [December 15, 2011]\n  Minor fixes to pngvalid.c for gcc 4.6.2 compatibility to remove warnings\n    reported by earlier versions.\n  Fixed minor memset/sizeof errors in pngvalid.c.\n\nVersion 1.6.0beta01 [December 15, 2011]\n  Removed machine-generated configure files from the GIT repository (they will\n    continue to appear in the tarball distributions and in the libpng15 and\n    earlier GIT branches).\n  Restored the new 'simplified' API, which was started in libpng-1.5.7beta02\n    but later deleted from libpng-1.5.7beta05.\n  Added example programs for the new 'simplified' API.\n  Added ANSI-C (C90) headers and require them, and take advantage of the\n    change. Also fixed some of the projects/* and contrib/* files that needed\n    updates for libpng16 and the move of pngvalid.c.\n    With this change the required ANSI-C header files are assumed to exist: the\n    implementation must provide float.h, limits.h, stdarg.h and stddef.h and\n    libpng relies on limits.h and stddef.h existing and behaving as defined\n    (the other two required headers aren't used).  Non-ANSI systems that don't\n    have stddef.h or limits.h will have to provide an appropriate fake\n    containing the relevant types and #defines.\n  Dropped support for 16-bit platforms. The use of FAR/far has been eliminated\n    and the definition of png_alloc_size_t is now controlled by a flag so\n    that 'small size_t' systems can select it if necessary.  Libpng 1.6 may\n    not currently work on such systems -- it seems likely that it will\n    ask 'malloc' for more than 65535 bytes with any image that has a\n    sufficiently large row size (rather than simply failing to read such\n    images).\n  New tools directory containing tools used to generate libpng code.\n  Fixed race conditions in parallel make builds. With higher degrees of\n    parallelism during 'make' the use of the same temporary file names such\n    as 'dfn*' can result in a race where a temporary file from one arm of the\n    build is deleted or overwritten in another arm.  This changes the\n    temporary files for suffix rules to always use $* and ensures that the\n    non-suffix rules use unique file names.\n\nVersion 1.6.0beta02 [December 21, 2011]\n  Correct configure builds where build and source directories are separate.\n    The include path of 'config.h' was erroneously made relative in pngvalid.c\n    in libpng 1.5.7.\n\nVersion 1.6.0beta03 [December 22, 2011]\n  Start-up code size improvements, error handler flexibility. These changes\n    alter how the tricky allocation of the initial png_struct and png_info\n    structures are handled. png_info is now handled in pretty much the same\n    way as everything else, except that the allocations handle NULL return\n    silently.  png_struct is changed in a similar way on allocation and on\n    deallocation a 'safety' error handler is put in place (which should never\n    be required).  The error handler itself is changed to permit mismatches\n    in the application and libpng error buffer size; however, this means a\n    silent change to the API to return the jmp_buf if the size doesn't match\n    the size from the libpng compilation; libpng now allocates the memory and\n    this may fail.  Overall these changes result in slight code size\n    reductions; however, this is a reduction in code that is always executed\n    so is particularly valuable.  Overall on a 64-bit system the libpng DLL\n    decreases in code size by 1733 bytes.  pngerror.o increases in size by\n    about 465 bytes because of the new functionality.\n  Added png_convert_to_rfc1123_buffer() and deprecated png_convert_to_rfc1123()\n    to avoid including a spurious buffer in the png_struct.\n\nVersion 1.6.0beta04 [December 30, 2011]\n  Regenerated configure scripts with automake-1.11.2\n  Eliminated png_info_destroy(). It is now used only in png.c and only calls\n    one other internal function and memset().\n  Enabled png_get_sCAL_fixed() if floating point APIs are enabled. Previously\n    it was disabled whenever internal fixed point arithmetic was selected,\n    which meant it didn't exist even on systems where FP was available but not\n    preferred.\n  Added pngvalid.c compile time checks for const APIs.\n  Implemented 'restrict' for png_info and png_struct. Because of the way\n    libpng works both png_info and png_struct are always accessed via a\n    single pointer.  This means adding C99 'restrict' to the pointer gives\n    the compiler some opportunity to optimize the code.  This change allows\n    that.\n  Moved AC_MSG_CHECKING([if libraries can be versioned]) later to the proper\n    location in configure.ac (Gilles Espinasse).\n  Changed png_memcpy to C assignment where appropriate. Changed all those\n    uses of png_memcpy that were doing a simple assignment to assignments\n    (all those cases where the thing being copied is a non-array C L-value).\n  Added some error checking to png_set_*() routines.\n  Removed the reference to the non-exported function png_memcpy() from\n    example.c.\n  Fixed the Visual C 64-bit build - it requires jmp_buf to be aligned, but\n    it had become misaligned.\n  Revised contrib/pngminus/pnm2png.c to avoid warnings when png_uint_32\n    and unsigned long are of different sizes.\n\nVersion 1.6.0beta05 [January 15, 2012]\n  Updated manual with description of the simplified API (copied from png.h)\n  Fix bug in pngerror.c: some long warnings were being improperly truncated\n    (CVE-2011-3464, bug introduced in libpng-1.5.3beta05).\n\nVersion 1.6.0beta06 [January 24, 2012]\n  Added palette support to the simplified APIs. This commit\n    changes some of the macro definitions in png.h, app code\n    may need corresponding changes.\n  Increased the formatted warning buffer to 192 bytes.\n  Added color-map support to simplified API. This is an initial version for\n    review; the documentation has not yet been updated.\n  Fixed Min/GW uninstall to remove libpng.dll.a\n\nVersion 1.6.0beta07 [January 28, 2012]\n  Eliminated Intel icc/icl compiler warnings. The Intel (GCC derived)\n    compiler issues slightly different warnings from those issued by the\n    current vesions of GCC. This eliminates those warnings by\n    adding/removing casts and small code rewrites.\n  Updated configure.ac from autoupdate: added --enable-werror option.\n    Also some layout regularization and removal of introduced tab characters\n    (replaced with 3-character indentation).  Obsolete macros identified by\n    autoupdate have been removed; the replacements are all in 2.59 so\n    the pre-req hasn't been changed.  --enable-werror checks for support\n    for -Werror (or the given argument) in the compiler.  This mimics the\n    gcc configure option by allowing -Werror to be turned on safely; without\n    the option the tests written in configure itself fail compilation because\n    they cause compiler warnings.\n  Rewrote autogen.sh to run autoreconf instead of running tools one-by-one.\n  Conditionalize the install rules for MINGW and CYGWIN in CMakeLists.txt and\n    set CMAKE_LIBRARY_OUTPUT_DIRECTORY to \"lib\" on all platforms (C. Yapp).\n  Freeze libtool files in the 'scripts' directory. This version of autogen.sh\n    attempts to dissuade people from running it when it is not, or should not,\n    be necessary.  In fact, autogen.sh does not work when run in a libpng\n    directory extracted from a tar distribution anymore. You must run it in\n    a GIT clone instead.\n  Added two images to contrib/pngsuite (1-bit and 2-bit transparent grayscale),\n    and renamed three whose names were inconsistent with those in\n    pngsuite/README.txt.\n\nVersion 1.6.0beta08 [February 1, 2012]\n  Fixed Image::colormap misalignment in pngstest.c\n  Check libtool/libtoolize version number (2.4.2) in configure.ac\n  Divide test-pngstest.sh into separate pngstest runs for basic and\n    transparent images.\n  Moved automake options to AM_INIT_AUTOMAKE in configure.ac\n  Added color-tests, silent-rules (Not yet implemented in Makefile.am) and\n    version checking to configure.ac\n  Improved pngstest speed by not doing redundant tests and add const to\n    the background parameter of png_image_finish_read. The --background\n    option is now done automagically only when required, so that commandline\n    option no longer exists.\n  Cleaned up pngpriv.h to consistently declare all functions and data.\n    Also eliminated PNG_CONST_DATA, which is apparently not needed but we\n    can't be sure until it is gone.\n  Added symbol prefixing that allows all the libpng external symbols\n    to be prefixed (suggested by Reuben Hawkins).\n  Updated \"ftbb*.png\" list in the owatcom and vstudio projects.\n  Fixed 'prefix' builds on clean systems. The generation of pngprefix.h\n    should not require itself.\n  Updated INSTALL to explain that autogen.sh must be run in a GIT clone,\n    not in a libpng directory extracted from a tar distribution.\n\nVersion 1.6.0beta09 [February 1, 2012]\n  Reverted the prebuilt configure files to libpng-1.6.0beta05 condition.\n\nVersion 1.6.0beta10 [February 3, 2012]\n  Added Z_SOLO for zlib-1.2.6+ and correct pngstest tests\n  Updated list of test images in CMakeLists.txt\n  Updated the prebuilt configure files to current condition.\n  Revised INSTALL information about autogen.sh; it works in tar distributions.\n\nVersion 1.6.0beta11 [February 16, 2012]\n  Fix character count in pngstest command in projects/owatcom/pngstest.tgt\n  Revised test-pngstest.sh to report PASS/FAIL for each image.\n  Updated documentation about the simplified API.\n  Corrected estimate of error in libpng png_set_rgb_to_gray API.  The API is\n    extremely inaccurate for sRGB conversions because it uses an 8-bit\n    intermediate linear value and it does not use the sRGB transform, so it\n    suffers from the known instability in gamma transforms for values close\n    to 0 (see Poynton).  The net result is that the calculation has a maximum\n    error of 14.99/255; 0.5/255^(1/2.2).  pngstest now uses 15 for the\n    permitted 8-bit error. This may still not be enough because of arithmetic\n    error.\n  Removed some unused arrays (with #ifdef) from png_read_push_finish_row().\n  Fixed a memory overwrite bug in simplified read of RGB PNG with\n    non-linear gamma Also bugs in the error checking in pngread.c and changed\n    quite a lot of the checks in pngstest.c to be correct; either correctly\n    written or not over-optimistic.  The pngstest changes are insufficient to\n    allow all possible RGB transforms to be passed; pngstest cmppixel needs\n    to be rewritten to make it clearer which errors it allows and then changed\n    to permit known inaccuracies.\n  Removed tests for no-longer-used *_EMPTY_PLTE_SUPPORTED from pngstruct.h\n  Fixed fixed/float API export conditionals. 1) If FIXED_POINT or\n    FLOATING_POINT options were switched off, png.h ended up with lone ';'\n    characters.  This is not valid ANSI-C outside a function.  The ';'\n    characters have been moved inside the definition of PNG_FP_EXPORT and\n    PNG_FIXED_EXPORT. 2) If either option was switched off, the declaration\n    of the corresponding functions were completely omitted, even though some\n    of them are still used internally.  The result is still valid, but\n    produces warnings from gcc with some warning options (including -Wall). The\n    fix is to cause png.h to declare the functions with PNG_INTERNAL_FUNCTION\n    when png.h is included from pngpriv.h.\n  Check for invalid palette index while reading paletted PNG.  When one is\n    found, issue a warning and increase png_ptr->num_palette accordingly.\n    Apps are responsible for checking to see if that happened.\n\nVersion 1.6.0beta12 [February 18, 2012]\n  Do not increase num_palette on invalid_index.\n  Relocated check for invalid palette index to pngrtran.c, after unpacking\n    the sub-8-bit pixels.\n  Fixed CVE-2011-3026 buffer overrun bug.  This bug was introduced when\n    iCCP chunk support was added at libpng-1.0.6. Deal more correctly with the\n    test on iCCP chunk length. Also removed spurious casts that may hide\n    problems on 16-bit systems.\n\nVersion 1.6.0beta13 [February 24, 2012]\n  Eliminated redundant png_push_read_tEXt|zTXt|iTXt|unknown code from\n    pngpread.c and use the sequential png_handle_tEXt, etc., in pngrutil.c;\n    now that png_ptr->buffer is inaccessible to applications, the special\n    handling is no longer useful.\n  Added PNG_SAFE_LIMITS feature to pnglibconf.dfa, pngpriv.h, and new\n    pngusr.dfa to reset the user limits to safe ones if PNG_SAFE_LIMITS is\n    defined.  To enable, use \"CPPFLAGS=-DPNG_SAFE_LIMITS_SUPPORTED=1\" on the\n    configure command or put #define PNG_SAFE_LIMITS_SUPPORTED in\n    pnglibconf.h.prebuilt and pnglibconf.h.\n\nVersion 1.6.0beta14 [February 27, 2012]\n  Added information about the new limits in the manual.\n  Updated Makefile.in\n\nVersion 1.6.0beta15 [March 2, 2012]\n  Removed unused \"current_text\" members of png_struct and the png_free()\n    of png_ptr->current_text from pngread.c\n  Rewrote pngstest.c for substantial speed improvement.\n  Fixed transparent pixel and 16-bit rgb tests in pngstest and removed a\n    spurious check in pngwrite.c\n  Added PNG_IMAGE_FLAG_FAST for the benefit of applications that store\n    intermediate files, or intermediate in-memory data, while processing\n    image data with the simplified API.  The option makes the files larger\n    but faster to write and read.  pngstest now uses this by default; this\n    can be disabled with the --slow option.\n  Improved pngstest fine tuning of error numbers, new test file generator.\n    The generator generates images that test the full range of sample values,\n    allow the error numbers in pngstest to be tuned and checked.  makepng\n    also allows generation of images with extra chunks, although this is\n    still work-in-progress.\n  Added check for invalid palette index while reading.\n  Fixed some bugs in ICC profile writing. The code should now accept\n    all potentially valid ICC profiles and reject obviously invalid ones.\n    It now uses png_error() to do so rather than casually writing a PNG\n    without the necessary color data.\n  Removed whitespace from the end of lines in all source files and scripts.\n\nVersion 1.6.0beta16 [March 6, 2012]\n  Relocated palette-index checking function from pngrutil.c to pngtrans.c\n  Added palette-index checking while writing.\n  Changed png_inflate() and calling routines to avoid overflow problems.\n    This is an intermediate check-in that solves the immediate problems and\n    introduces one performance improvement (avoiding a copy via png_ptr->zbuf.)\n    Further changes will be made to make ICC profile handling more secure.\n  Fixed build warnings (MSVC, GCC, GCC v3). Cygwin GCC with default options\n    declares 'index' as a global, causing a warning if it is used as a local\n    variable.  GCC 64-bit warns about assigning a (size_t) (unsigned 64-bit)\n    to an (int) (signed 32-bit).  MSVC, however, warns about using the\n    unary '-' operator on an unsigned value (even though it is well defined\n    by ANSI-C to be ~x+1).  The padding calculation was changed to use a\n    different method.  Removed the tests on png_ptr->pass.\n  Added contrib/libtests/tarith.c to test internal arithmetic functions from\n    png.c. This is a libpng maintainer program used to validate changes to the\n    internal arithmetic functions.\n  Made read 'inflate' handling like write 'deflate' handling. The read\n    code now claims and releases png_ptr->zstream, like the write code.\n    The bug whereby the progressive reader failed to release the zstream\n    is now fixed, all initialization is delayed, and the code checks for\n    changed parameters on deflate rather than always calling\n    deflatedEnd/deflateInit.\n  Validate the zTXt strings in pngvalid.\n  Added code to validate the windowBits value passed to deflateInit2().\n    If the call to deflateInit2() is wrong a png_warning will be issued\n    (in fact this is harmless, but the PNG data produced may be sub-optimal).\n\nVersion 1.6.0beta17 [March 10, 2012]\n  Fixed PNG_LIBPNG_BUILD_BASE_TYPE definition. \n  Reject all iCCP chunks after the first, even if the first one is invalid.\n  Deflate/inflate was reworked to move common zlib calls into single\n    functions [rw]util.c.  A new shared keyword check routine was also added\n    and the 'zbuf' is no longer allocated on progressive read.  It is now\n    possible to call png_inflate() incrementally.  A warning is no longer\n    issued if the language tag or translated keyword in the iTXt chunk\n    has zero length.\n  If benign errors are disabled use maximum window on ancilliary inflate.\n    This works round a bug introduced in 1.5.4 where compressed ancillary\n    chunks could end up with a too-small windowBits value in the deflate\n    header.\n\nVersion 1.6.0beta18 [March 16, 2012]\n  Issue a png_benign_error() instead of png_warning() about bad palette index.\n  In pngtest, treat benign errors as errors if \"-strict\" is present.\n  Fixed an off-by-one error in the palette index checking function.\n  Fixed a compiler warning under Cygwin (Windows-7, 32-bit system)\n  Revised example.c to put text strings in a temporary character array\n    instead of directly assigning string constants to png_textp members.\n    This avoids compiler warnings when -Wwrite-strings is enabled.\n  Added output flushing to aid debugging under Visual Studio. Unfortunately\n    this is necessary because the VS2010 output window otherwise simply loses\n    the error messages on error (they weren't flushed to the window before\n    the process exited, apparently!)\n  Added configuration support for benign errors and changed the read\n    default. Also changed some warnings in the iCCP and sRGB handling\n    from to benign errors. Configuration now makes read benign\n    errors warnings and write benign errors to errors by default (thus\n    changing the behavior on read).  The simplified API always forces\n    read benign errors to warnings (regardless of the system default, unless\n    this is disabled in which case the simplified API can't be built.)\n\nVersion 1.6.0beta19 [March 18, 2012]\n  Work around for duplicate row start calls; added warning messages.\n    This turns on PNG_FLAG_DETECT_UNINITIALIZED to detect app code that\n    fails to call one of the 'start' routines (not enabled in libpng-1.5\n    because it is technically an API change, since it did normally work\n    before.)  It also makes duplicate calls to png_read_start_row (an\n    internal function called at the start of the image read) benign, as\n    they were before changes to use png_inflate_claim. Somehow webkit is\n    causing this to happen; this is probably a mis-feature in the zlib\n    changes so this commit is only a work-round.\n  Removed erroneous setting of DETECT_UNINITIALIZED and added more\n    checks. The code now does a png_error if an attempt is made to do the\n    row initialization twice; this is an application error and it has\n    serious consequences because the transform data in png_struct is\n    changed by each call.\n  Added application error reporting and added chunk names to read\n    benign errors; also added --strict to pngstest - not enabled\n    yet because a warning is produced.\n  Avoid the double gamma correction warning in the simplified API.\n    This allows the --strict option to pass in the pngstest checks\n\nVersion 1.6.0beta20 [March 29, 2012]\n  Changed chunk handler warnings into benign errors, incrementally load iCCP\n  Added checksum-icc.c to contrib/tools\n  Prevent PNG_EXPAND+PNG_SHIFT doing the shift twice.\n  Recognize known sRGB ICC profiles while reading; prefer writing the\n    iCCP profile over writing the sRGB chunk, controlled by the\n    PNG_sRGB_PROFILE_CHECKS option.\n  Revised png_set_text_2() to avoid potential memory corruption (fixes\n    CVE-2011-3048, also known as CVE-2012-3425).\n\nVersion 1.6.0beta21 [April 27, 2012]\n  Revised scripts/makefile.darwin: use system zlib; remove quotes around\n    architecture list; add missing ppc architecture; add architecture options\n    to shared library link; don't try to create a shared lib based on missing\n    RELEASE variable.\n  Enable png_set_check_for_invalid_index() for both read and write.\n  Removed #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED in pngpriv.h around\n    declaration of png_handle_unknown().\n  Added -lssp_nonshared in a comment in scripts/makefile.freebsd\n    and changed deprecated NOOBJ and NOPROFILE to NO_OBJ and NO_PROFILE.\n\nVersion 1.6.0beta22 [May 23, 2012]\n  Removed need for -Wno-cast-align with clang.  clang correctly warns on\n    alignment increasing pointer casts when -Wcast-align is passed. This\n    fixes the cases that clang warns about either by eliminating the\n    casts from png_bytep to png_uint_16p (pngread.c), or, for pngrutil.c\n    where the cast is previously verified or pngstest.c where it is OK, by\n    introducing new png_aligncast macros to do the cast in a way that clang\n    accepts.\n\nVersion 1.6.0beta23 [June 6, 2012]\n  Revised CMakeLists.txt to not attempt to make a symlink under mingw.\n  Made fixes for new optimization warnings from gcc 4.7.0. The compiler\n    performs an optimization which is safe; however it then warns about it.\n    Changing the type of 'palette_number' in pngvalid.c removes the warning.\n  Do not depend upon a GCC feature macro being available for use in generating\n    the linker mapfile symbol prefix.\n  Improved performance of new do_check_palette_indexes() function (only\n    update the value when it actually increases, move test for whether\n    the check is wanted out of the function.\n\nVersion 1.6.0beta24 [June 7, 2012]\n  Don't check palette indexes if num_palette is 0 (as it can be in MNG files).\n\nVersion 1.6.0beta25 [June 16, 2012]\n  Revised png_set_keep_unknown_chunks() so num_chunks < 0 means ignore all\n    unknown chunks and all known chunks except for IHDR, PLTE, tRNS, IDAT,\n    and IEND.  Previously it only meant ignore all unknown chunks, the\n    same as num_chunks == 0. Revised png_image_skip_unused_chunks() to\n    provide a list of chunks to be processed instead of a list of chunks to\n    ignore.  Revised contrib/gregbook/readpng2.c accordingly.\n\nVersion 1.6.0beta26 [July 10, 2012]\n  Removed scripts/makefile.cegcc from the *.zip and *.7z distributions; it\n    depends on configure, which is not included in those archives.\n  Moved scripts/chkfmt to contrib/tools.\n  Changed \"a+w\" to \"u+w\" in Makefile.in to fix CVE-2012-3386.\n\nVersion 1.6.0beta27 [August 11, 2012]\n  Do not compile PNG_DEPRECATED, PNG_ALLOC and PNG_PRIVATE when __GNUC__ < 3.\n  Do not use __restrict when GNUC is <= 3.1\n  Removed references to png_zalloc() and png_zfree() from the manual.\n  Fixed configurations where floating point is completely disabled.  Because\n    of the changes to support symbol prefixing PNG_INTERNAL_FUNCTION declares\n    floating point APIs during libpng builds even if they are completely\n    disabled. This requires the png floating point types (png_double*) to be\n    declared even though the functions are never actually defined.  This\n    change provides a dummy definition so that the declarations work, yet any\n    implementation will fail to compile because of an incomplete type.\n  Re-eliminated the use of strcpy() in pngtest.c.  An unncessary use of\n    strcpy() was accidentally re-introduced in libpng16; this change replaces\n    it with strncpy().\n  Eliminated use of png_sizeof(); use sizeof() instead.\n  Use a consistent style for (sizeof type) and (sizeof (array))\n  Cleanup of png_set_filler().  This function does very different things on\n    read and write.  In libpng 1.6 the two cases can be distinguished and\n    considerable code cleanup, and extra error checking, is possible.  This\n    makes calls on the write side that have no effect be ignored with a\n    png_app_error(), which can be disabled in the app using\n    png_set_benign_errors(), and removes the spurious use of usr_channels\n    on the read side.\n  Insist on autotools 1.12.1 for git builds because there are security issues\n    with 1.12 and insisting on anything less would allow 1.12 to be used.\n  Removed info_ptr->signature[8] from WRITE-only builds.\n  Add some conditions for compiling png_fixed().  This is a small function\n    but it requires \"-lm\" on some platforms.\n  Cause pngtest --strict to fail on any warning from libpng (not just errors)\n    and cause it not to fail at the comparison step if libpng lacks support\n    for writing chunks that it reads from the input (currently only implemented\n    for compressed text chunks).\n  Make all three \"make check\" test programs work without READ or WRITE support.\n    Now \"make check\" will succeed even if libpng is compiled with -DPNG_NO_READ\n    or -DPNG_NO_WRITE.  The tests performed are reduced, but the basic reading\n    and writing of a PNG file is always tested by one or more of the tests.\n  Consistently use strlen(), memset(), memcpy(), and memcmp() instead of the\n    png_strlen(), png_memset(), png_memcpy(), and png_memcmp() macros.\n  Removed the png_sizeof(), png_strlen(), png_memset(), png_memcpy(), and\n    png_memcmp() macros.\n  Work around gcc 3.x and Microsoft Visual Studio 2010 complaints. Both object\n    to the split initialization of num_chunks.\n\nVersion 1.6.0beta28 [August 29, 2012]\n  Unknown handling fixes and clean up. This adds more correct option\n    control of the unknown handling, corrects the pre-existing bug where\n    the per-chunk 'keep' setting is ignored and makes it possible to skip\n    IDAT chunks in the sequential reader (broken in earlier 1.6 versions).\n    There is a new test program, test-unknown.c, which is a work in progress\n    (not currently part of the test suite).  Comments in the header files now\n    explain how the unknown handling works.\n  Allow fine grain control of unknown chunk APIs. This change allows\n    png_set_keep_unknown_chunks() to be turned off if not required and causes\n    both read and write to behave appropriately (on read this is only possible\n    if the user callback is used to handle unknown chunks).  The change\n    also removes the support for storing unknown chunks in the info_struct\n    if the only unknown handling enabled is via the callback, allowing libpng\n    to be configured with callback reading and none of the unnecessary code.\n  Corrected fix for unknown handling in pngtest. This reinstates the\n    libpng handling of unknown chunks other than vpAg and sTER (including\n    unsafe-to-copy chunks which were dropped before) and eliminates the\n    repositioning of vpAg and sTER in pngtest.png by changing pngtest.png\n    (so the chunks are where libpng would put them).\n  Added \"tunknown\" test and corrected a logic error in png_handle_unknown()\n    when SAVE support is absent.  Moved the shell test scripts for\n    contrib/libtests from the libpng top directory to contrib/libtests.\n    png_handle_unknown() must always read or skip the chunk, if\n    SAVE_UNKNOWN_CHUNKS is turned off *and* the application does not set\n    a user callback an unknown chunk will not be read, leading to a read\n    error, which was revealed by the \"tunknown\" test.\n  Cleaned up and corrected ICC profile handling.\n    contrib/libtests/makepng: corrected 'rgb' and 'gray' cases.  profile_error\n    messages could be truncated; made a correct buffer size calculation and\n    adjusted pngerror.c appropriately. png_icc_check_* checking improved;\n    changed the functions to receive the correct color type of the PNG on read\n    or write and check that it matches the color space of the profile (despite\n    what the comments said before, there is danger in assuming the app will\n    cope correctly with an RGB profile on a grayscale image and, since it\n    violates the PNG spec, allowing it is certain to produce inconsistent\n    app behavior and might even cause app crashes.) Check that profiles\n    contain the tags needed to process the PNG (tags all required by the ICC\n    spec). Removed unused PNG_STATIC from pngpriv.h.\n\nVersion 1.6.0beta29 [September 4, 2012]\n  Fixed the simplified API example programs to add the *colormap parameter\n    to several of he API and improved the error message if the version field\n    is not set.\n  Added contrib/examples/* to the *.zip and *.7z distributions.\n  Updated simplified API synopses and description of the png_image structure\n    in the manual.\n  Made makepng and pngtest produce identical PNGs, add \"--relaxed\" option\n    to pngtest. The \"--relaxed\" option turns off the benign errors that are\n    enabled by default in pre-RC builds. makepng can now write ICC profiles\n    where the length has not been extended to a multiple of 4, and pngtest\n    now intercepts all libpng errors, allowing the previously-introduced\n    \"--strict test\" on no warnings to actually work.\n  Improved ICC profile handling including cHRM chunk generation and fixed\n    Cygwin+MSVC build errors. The ICC profile handling now includes more\n    checking.  Several errors that caused rejection of the profile are now\n    handled with a warning in such a way that the invalid profiles will be\n    read by default in release (but not pre-RC) builds but will not be\n    written by default.  The easy part of handling the cHRM chunk is written,\n    where the ICC profile contains the required data.  The more difficult\n    part plus guessing a gAMA value requires code to pass selected RGB values\n    through the profile.\n\nVersion 1.6.0beta30 [October 24, 2012]\n  Changed ICC profile matrix/vector types to not depend on array type rules.\n    By the ANSI-C standard the new types should be identical to the previous\n    versions, and all known versions of gcc tested with the previous versions\n    except for GCC-4.2.1 work with this version.  The change makes the ANSI-C\n    rule that const applied to an array of elements applies instead to the\n    elements in the array moot by explicitly applying const to the base\n    elements of the png_icc_matrix and png_icc_vector types. The accidental\n    (harmless) 'const' previously applied to the parameters of two of the\n    functions have also been removed.\n  Added a work around for GCC 4.2 optimization bug.\n  Marked the broken (bad white point) original HP sRGB profiles correctly and\n    correct comments.\n  Added -DZ_SOLO to contrib/pngminim/*/makefile to work with zlib-1.2.7\n  Use /MDd for vstudio debug builds. Also added pngunkown to the vstudio\n    builds, fixed build errors and corrected a minor exit code error in\n    pngvalid if the 'touch' file name is invalid.\n  Add updated WARNING file to projects/vstudio from libpng 1.5/vstudio\n  Fixed build when using #define PNG_NO_READ_GAMMA in png_do_compose() in\n    pngrtran.c (Domani Hannes).\n\nVersion 1.6.0beta31 [November 1, 2012]\n  Undid the erroneous change to vstudio/pngvalid build in libpng-1.6.0beta30.\n  Made pngvalid so that it will build outside the libpng source tree.\n  Made builds -DPNG_NO_READ_GAMMA compile (the unit tests still fail).\n  Made PNG_NO_READ_GAMMA switch off interfaces that depend on READ_GAMMA.\n    Prior to 1.6.0 switching off READ_GAMMA did unpredictable things to the\n    interfaces that use it (specifically, png_do_background in 1.4 would\n    simply display composite for grayscale images but do composition\n    with the incorrect arithmetic for color ones). In 1.6 the semantic\n    of -DPNG_NO_READ_GAMMA is changed to simply disable any interface that\n    depends on it; this obliges people who set it to consider whether they\n    really want it off if they happen to use any of the interfaces in\n    question (typically most users who disable it won't).\n  Fixed GUIDs in projects/vstudio. Some were duplicated or missing,\n    resulting in VS2010 having to update the files.\n  Removed non-working ICC profile support code that was mostly added to\n    libpng-1.6.0beta29 and beta30. There was too much code for too little\n    gain; implementing full ICC color correction may be desireable but is left\n    up to applications.\n\nVersion 1.6.0beta32 [November 25, 2012]\n  Fixed an intermittent SEGV in pngstest due to an uninitialized array element.\n  Added the ability for contrib/libtests/makepng.c to make a PNG with just one\n    color. This is useful for debugging pngstest color inaccuracy reports.\n  Fixed error checking in the simplified write API (Olaf van der Spek)\n  Made png_user_version_check() ok to use with libpng version 1.10.x and later.\n\nVersion 1.6.0beta33 [December 15, 2012]\n  Fixed typo in png.c (PNG_SET_CHUNK_MALLOC_MAX should be PNG_CHUNK_MALLOC_MAX)\n    that causes the MALLOC_MAX limit not to work (John Bowler)\n  Change png_warning() to png_app_error() in pngwrite.c and comment the\n    fall-through condition.\n  Change png_warning() to png_app_warning() in png_write_tRNS().\n  Rearranged the ARM-NEON optimizations: Isolated the machine specific code\n    to the hardware subdirectory and added comments to pngrutil.c so that\n    implementors of other optimizations know what to do.\n  Fixed cases of unquoted DESTDIR in Makefile.am\n  Rebuilt Makefile.in, etc., with autoconf-2.69 and automake-1.12.5.\n\nVersion 1.6.0beta34 [December 19, 2012]\n  Cleaned up whitespace in the synopsis portion of the manpage \"libpng.3\"\n  Disassembled the version number in scripts/options.awk (necessary for\n    building on SunOs).\n\nVersion 1.6.0beta35 [December 23, 2012]\n  Made default Zlib compression settings be configurable. This adds #defines to\n    pnglibconf.h to control the defaults.\n  Fixed Windows build issues, enabled ARM compilation. Various warnings issued\n    by earlier versions of GCC fixed for Cygwin and Min/GW (which both use old\n    GCCs.) ARM support is enabled by default in zlib.props (unsupported by\n    Microsoft) and ARM compilation is made possible by deleting the check for\n    x86. The test programs cannot be run because they are not signed.\n\nVersion 1.6.0beta36 [January 2, 2013]\n  Discontinued distributing libpng-1.x.x.tar.bz2.\n  Discontinued distributing libpng-1.7.0-1.6.0-diff.txt and similar.\n  Rebuilt configure with autoconf-2.69 (inadvertently not done in beta33)\n  Fixed 'make distcheck' on SUN OS - libpng.so was not being removed\n\nVersion 1.6.0beta37 [January 10, 2013]\n  Fixed conceivable but difficult to repro overflow. Also added two test\n    programs to generate and test a PNG which should have the problem.\n\nVersion 1.6.0beta39 [January 19, 2013]\n  Again corrected attempt at overflow detection in png_set_unknown_chunks()\n  (CVE-2013-7353).  Added overflow detection in png_set_sPLT() and\n  png_set_text_2() (CVE-2013-7354).\n\nVersion 1.6.0beta40 [January 20, 2013]\n  Use consistent handling of overflows in text, sPLT and unknown png_set_* APIs\n\nVersion 1.6.0rc01 [January 26, 2013]\n  No changes.\n\nVersion 1.6.0rc02 [February 4, 2013]\n  Added png_get_palette_max() function.\n\nVersion 1.6.0rc03 [February 5, 2013]\n  Fixed the png_get_palette_max API.\n\nVersion 1.6.0rc04 [February 7, 2013]\n  Turn serial tests back on (recently turned off by autotools upgrade).\n\nVersion 1.6.0rc05 [February 8, 2013]\n  Update manual about png_get_palette_max().\n\nVersion 1.6.0rc06 [February 9, 2013]\n  Fixed missing dependency in --prefix builds The intermediate\n    internal 'prefix.h' file can only be generated correctly after\n    pnglibconf.h, however the dependency was not in Makefile.am.  The\n    symptoms are unpredictable depending on the order make chooses to\n    build pngprefix.h and pnglibconf.h, often the error goes unnoticed\n    because there is a system pnglibconf.h to use instead.\n\nVersion 1.6.0rc07 [February 10, 2013]\n  Enclosed the new png_get_palette_max in #ifdef PNG_GET_PALETTE_MAX_SUPPORTED\n    block, and revised pnglibconf.h and pnglibconf.h.prebuilt accordingly.\n\nVersion 1.6.0rc08 [February 10, 2013]\n  Fix typo in png.h #ifdef\n\nVersion 1.6.0 [February 14, 2013]\n  No changes.\n\nVersion 1.6.1beta01 [February 16, 2013]\n  Made symbol prefixing work with the ARM neon optimizations. Also allow\n    pngpriv.h to be included for preprocessor definitions only, so it can\n    be used in non-C/C++ files. Back ported from libpng 1.7.\n  Made sRGB check numbers consistent.\n  Ported libpng 1.5 options.awk/dfn file handling to 1.6, fixed one bug.\n  Removed cc -E workround, corrected png_get_palette_max API Tested on\n    SUN OS cc 5.9, which demonstrates the tokenization problem previously\n    avoided by using /lib/cpp.  Since all .dfn output is now protected in\n    double quotes unless it is to be macro substituted the fix should\n    work everywhere.\n  Enabled parallel tests - back ported from libpng-1.7.\n  scripts/pnglibconf.dfa formatting improvements back ported from libpng17.\n  Fixed a race condition in the creation of the build 'scripts' directory\n    while building with a parallel make.\n  Use approved/supported Android method to check for NEON, use Linux/POSIX\n    1003.1 API to check /proc/self/auxv avoiding buffer allocation and other\n    library calls (ported from libpng15).\n\nVersion 1.6.1beta02 [February 19, 2013]\n  Use parentheses more consistently in \"#if defined(MACRO)\" tests.\n  Folded long lines.\n  Reenabled code to allow zero length PLTE chunks for MNG.\n\nVersion 1.6.1beta03 [February 22, 2013]\n  Fixed ALIGNED_MEMORY support.\n  Added a new configure option:\n    --enable-arm-neon=always will stop the run-time checks. New checks\n    within arm/arm_init.c will cause the code not to be compiled unless\n    __ARM_NEON__ is set. This should make it fail safe (if someone asks\n    for it on then the build will fail if it can't be done.)\n  Updated the INSTALL document.\n\nVersion 1.6.1beta04 [February 27, 2013]\n  Revised INSTALL to recommend using CPPFLAGS instead of INCLUDES.\n  Revised scripts/makefile.freebsd to respect ZLIBLIB and ZLIBINC.\n  Revised scripts/dfn.awk to work with the buggy MSYS awk that has trouble\n    with CRLF line endings.\n\nVersion 1.6.1beta05 [March 1, 2013]\n  Avoid a possible memory leak in contrib/gregbook/readpng.c\n\nVersion 1.6.1beta06 [March 4, 2013]\n  Better documentation of unknown handling API interactions.\n  Corrected Android builds and corrected libpng.vers with symbol\n    prefixing.  It also makes those tests compile and link on Android.\n  Added an API png_set_option() to set optimization options externally,\n    providing an alternative and general solution for the non-portable\n    run-time tests used by the ARM Neon code, using the PNG_ARM_NEON option.\n  The order of settings vs options in pnglibconf.h is reversed to allow\n    settings to depend on options and options can now set (or override) the\n    defaults for settings.\n\nVersion 1.6.1beta07 [March 7, 2013]\n  Corrected simplified API default gamma for color-mapped output, added\n    a flag to change default. In 1.6.0 when the simplified API was used\n    to produce color-mapped output from an input image with no gamma\n    information the gamma assumed for the input could be different from\n    that assumed for non-color-mapped output.  In particular 16-bit depth\n    input files were assumed to be sRGB encoded, whereas in the 'direct'\n    case they were assumed to have linear data.  This was an error.  The\n    fix makes the simplified API treat all input files the same way and\n    adds a new flag to the png_image::flags member to allow the\n    application/user to specify that 16-bit files contain sRGB data\n    rather than the default linear.\n  Fixed bugs in the pngpixel and makepng test programs.\n\nVersion 1.6.1beta08 [March 7, 2013]\n  Fixed CMakelists.txt to allow building a single variant of the library\n    (Claudio Bley):\n  Introduced a PNG_LIB_TARGETS variable that lists all activated library\n    targets.  It is an error if this variable ends up empty, ie. you have\n    to build at least one library variant.\n  Made the *_COPY targets only depend on library targets actually being build.\n  Use PNG_LIB_TARGETS to unify a code path.\n  Changed the CREATE_SYMLINK macro to expect the full path to a file as the\n    first argument. When symlinking the filename component of that path is\n    determined and used as the link target.\n  Use copy_if_different in the CREATE_SYMLINK macro.\n\nVersion 1.6.1beta09 [March 13, 2013]\n  Eliminated two warnings from the Intel C compiler. The warnings are\n    technically valid, although a reasonable treatment of division would\n    show it to be incorrect.\n\nVersion 1.6.1rc01 [March 21, 2013]\n  No changes.\n\nVersion 1.6.1 [March 28, 2013]\n  No changes.\n\nVersion 1.6.2beta01 [April 14, 2013]\n  Updated documentation of 1.5.x to 1.6.x changes in iCCP chunk handling.\n  Fixed incorrect warning of excess deflate data. End condition - the\n    warning would be produced if the end of the deflate stream wasn't read\n    in the last row.  The warning is harmless.\n  Corrected the test on user transform changes on read. It was in the\n    png_set of the transform function, but that doesn't matter unless the\n    transform function changes the rowbuf size, and that is only valid if\n    transform_info is called.\n  Corrected a misplaced closing bracket in contrib/libtests/pngvalid.c\n    (Flavio Medeiros).\n  Corrected length written to uncompressed iTXt chunks (Samuli Suominen).\n    Bug was introduced in libpng-1.6.0.\n\nVersion 1.6.2rc01 [April 18, 2013]\n  Added contrib/tools/fixitxt.c, to repair the erroneous iTXt chunk length\n    written by libpng-1.6.0 and 1.6.1.\n  Disallow storing sRGB information when the sRGB is not supported.\n\nVersion 1.6.2rc02 [April 18, 2013]\n  Merge pngtest.c with libpng-1.7.0\n\nVersion 1.6.2rc03 [April 22, 2013]\n  Trivial spelling cleanup.\n\nVersion 1.6.2rc04 and 1.6.2rc05 [omitted]\n\nVersion 1.6.2rc06 [April 24, 2013]\n  Reverted to version 1.6.2rc03.  Recent changes to arm/neon support\n    have been ported to libpng-1.7.0beta09 and will reappear in version\n    1.6.3beta01.\n\nVersion 1.6.2 [April 25, 2013]\n  No changes.\n\nVersion 1.6.3beta01 [April 25, 2013]\n  Revised stack marking in arm/filter_neon.S and configure.ac.\n  Ensure that NEON filter stuff is completely disabled when switched 'off'.\n    Previously the ARM NEON specific files were still built if the option\n    was switched 'off' as opposed to being explicitly disabled.\n\nVersion 1.6.3beta02 [April 26, 2013]\n  Test for 'arm*' not just 'arm' in the host_cpu configure variable.\n  Rebuilt the configure scripts.\n\nVersion 1.6.3beta03 [April 30, 2013]\n  Expanded manual paragraph about writing private chunks, particularly\n    the need to call png_set_keep_unknown_chunks() when writing them.\n  Avoid dereferencing NULL pointer possibly returned from\n    png_create_write_struct() (Andrew Church).\n\nVersion 1.6.3beta05 [May 9, 2013]\n  Calculate our own zlib windowBits when decoding rather than trusting the\n    CMF bytes in the PNG datastream.\n  Added an option to force maximum window size for inflating, which was\n    the behavior of libpng15 and earlier, via a new PNG_MAXIMUM_INFLATE_WINDOW\n    option for png_set_options().\n  Added png-fix-itxt and png-fix-too-far-back to the built programs and\n    removed warnings from the source code and timepng that are revealed as\n    a result.\n  Detect wrong libpng versions linked to png-fix-too-far-back, which currently\n    only works with libpng versions that can be made to reliably fail when\n    the deflate data contains an out-of-window reference.  This means only\n    1.6 and later.\n  Fixed gnu issues: g++ needs a static_cast, gcc 4.4.7 has a broken warning\n    message which it is easier to work round than ignore.\n  Updated contrib/pngminus/pnm2png.c (Paul Stewart):\n    Check for EOF\n    Ignore \"#\" delimited comments in input file to pnm2png.c.\n    Fixed whitespace handling\n    Added a call to png_set_packing()\n    Initialize dimension values so if sscanf fails at least we have known\n      invalid values.\n  Attempt to detect configuration issues with png-fix-too-far-back, which\n    requires both the correct libpng and the correct zlib to function\n    correctly.\n  Check ZLIB_VERNUM for mismatches, enclose #error in quotes\n  Added information in the documentation about problems with and fixes for\n    the bad CRC and bad iTXt chunk situations.\n\nVersion 1.6.3beta06 [May 12, 2013]\n  Allow contrib/pngminus/pnm2png.c to compile without WRITE_INVERT and\n    WRITE_PACK supported (writes error message that it can't read P1 or\n    P4 PBM files).\n  Improved png-fix-too-far-back usage message, added --suffix option.\n  Revised contrib/pngminim/*/makefile to generate pnglibconf.h with the\n    right zlib header files.\n  Separated CPPFLAGS and CFLAGS in contrib/pngminim/*/makefile\n\nVersion 1.6.3beta07 [June 8, 2013]\n  Removed a redundant test in png_set_IHDR().\n  Added set(CMAKE_CONFIGURATION_TYPES ...) to CMakeLists.txt (Andrew Hundt)\n  Deleted set(CMAKE_BUILD_TYPE) block from CMakeLists.txt\n  Enclose the prototypes for the simplified write API in\n    #ifdef PNG_STDIO_SUPPORTED/#endif\n  Make ARM NEON support work at compile time (not just configure time).\n    This moves the test on __ARM_NEON__ into pngconf.h to avoid issues when\n    using a compiler that compiles for multiple architectures at one time.\n  Removed PNG_FILTER_OPTIMIZATIONS and PNG_ARM_NEON_SUPPORTED from\n    pnglibconf.h, allowing more of the decisions to be made internally\n    (pngpriv.h) during the compile.  Without this, symbol prefixing is broken\n    under certain circumstances on ARM platforms.  Now only the API parts of\n    the optimizations ('check' vs 'api') are exposed in the public header files\n    except that the new setting PNG_ARM_NEON_OPT documents how libpng makes the\n    decision about whether or not to use the optimizations.\n  Protect symbol prefixing against CC/CPPFLAGS/CFLAGS useage.\n    Previous iOS/Xcode fixes for the ARM NEON optimizations moved the test\n    on __ARM_NEON__ from configure time to compile time.  This breaks symbol\n    prefixing because the definition of the special png_init_filter_functions\n    call was hidden at configure time if the relevant compiler arguments are\n    passed in CFLAGS as opposed to CC.  This change attempts to avoid all\n    the confusion that would result by declaring the init function even when\n    it is not used, so that it will always get prefixed.\n\nVersion 1.6.3beta08 [June 18, 2013]\n  Revised libpng.3 so that \"doclifter\" can process it.\n\nVersion 1.6.3beta09 [June 27, 2013]\n  Revised example.c to illustrate use of PNG_DEFAULT_sRGB and PNG_GAMMA_MAC_18\n    as parameters for png_set_gamma().  These have been available since\n    libpng-1.5.4.\n  Renamed contrib/tools/png-fix-too-far-back.c to pngfix.c and revised it\n    to check all compressed chunks known to libpng.\n\nVersion 1.6.3beta10 [July 5, 2013]\n  Updated documentation to show default behavior of benign errors correctly.\n  Only compile ARM code when PNG_READ_SUPPORTED is defined.\n  Fixed undefined behavior in contrib/tools/pngfix.c and added new strip\n    option. pngfix relied on undefined behavior and even a simple change from\n    gcc to g++ caused it to fail.  The new strip option 'unsafe' has been\n    implemented and is the default if --max is given.  Option names have\n    been clarified, with --strip=transform now stripping the bKGD chunk,\n    which was stripped previously with --strip=unused.\n  Added all documented chunk types to pngpriv.h\n  Unified pngfix.c source with libpng17.\n\nVersion 1.6.3rc01 [July 11, 2013]\n  No changes.\n\nVersion 1.6.3 [July 18, 2013]\n  Revised manual about changes in iTXt chunk handling made in libpng-1.6.0.\n  Added \"/* SAFE */\" comments in pngrutil.c and pngrtran.c where warnings\n    may be erroneously issued by code-checking applications.\n\nVersion 1.6.4beta01 [August 21, 2013]\n  Added information about png_set_options() to the manual.\n  Delay calling png_init_filter_functions() until a row with nonzero filter\n    is found.\n\nVersion 1.6.4beta02 [August 30, 2013]\n  Fixed inconsistent conditional compilation of png_chunk_unknown_handling()\n    prototype, definition, and usage.  Made it depend on\n    PNG_HANDLE_AS_UNKNOWN_SUPPORTED everywhere.\n\nVersion 1.6.4rc01 [September 5, 2013]\n  No changes.\n\nVersion 1.6.4 [September 12, 2013]\n  No changes.\n\nVersion 1.6.5 [September 14, 2013]\n  Removed two stray lines of code from arm/arm_init.c.\n\nVersion 1.6.6 [September 16, 2013]\n  Removed two stray lines of code from arm/arm_init.c, again.\n\nVersion 1.6.7beta01 [September 30, 2013]\n  Revised unknown chunk code to correct several bugs in the NO_SAVE_/NO_WRITE\n    combination\n  Allow HANDLE_AS_UNKNOWN to work when other options are configured off. Also\n    fixed the pngminim makefiles to work when $(MAKEFLAGS) contains stuff\n    which terminates the make options (as by default in recent versions of\n    Gentoo).\n  Avoid up-cast warnings in pngvalid.c. On ARM the alignment requirements of\n    png_modifier are greater than that of png_store and as a consequence\n    compilation of pngvalid.c results in a warning about increased alignment\n    requirements because of the bare cast to (png_modifier*). The code is safe,\n    because the pointer is known to point to a stack allocated png_modifier,\n    but this change avoids the warning.\n  Fixed default behavior of ARM_NEON_API. If the ARM NEON API option was\n    compiled without the CHECK option it defaulted to on, not off.\n  Check user callback behavior in pngunknown.c. Previous versions compiled\n    if SAVE_UNKNOWN was not available but did nothing since the callback\n    was never implemented.\n  Merged pngunknown.c with 1.7 version and back ported 1.7 improvements/fixes\n\nVersion 1.6.7beta02 [October 12, 2013]\n  Made changes for compatibility with automake 1.14:\n    1) Added the 'compile' program to the list of programs that must be cleaned\n       in autogen.sh\n    2) Added 'subdir-objects' which causes .c files in sub-directories to be\n       compiled such that the corresponding .o files are also in the\n       sub-directory.  This is because automake 1.14 warns that the\n       current behavior of compiling to the top level directory may be removed\n       in the future.\n    3) Updated dependencies on pnglibconf.h to match the new .o locations and\n       added all the files in contrib/libtests and contrib/tools that depend\n       on pnglibconf.h\n    4) Added 'BUILD_SOURCES = pnglibconf.h'; this is the automake recommended\n       way of handling the dependencies of sources that are machine generated;\n       unfortunately it only works if the user does 'make all' or 'make check',\n       so the dependencies (3) are still required.\n  Cleaned up (char*) casts of zlib messages. The latest version of the Intel C\n    compiler complains about casting a string literal as (char*), so copied the\n    treatment of z_const from the library code into pngfix.c\n  Simplified error message code in pngunknown. The simplification has the\n    useful side effect of avoiding a bogus warning generated by the latest\n    version of the Intel C compiler (it objects to\n    condition ? string-literal : string-literal).\n  Make autogen.sh work with automake 1.13 as well as 1.14. Do this by always\n    removing the 1.14 'compile' script but never checking for it.\n\nVersion 1.6.7beta03 [October 19, 2013]\n  Added ARMv8 support (James Yu <james.yu at linaro.org>).  Added file\n    arm/filter_neon_intrinsics.c; enable with -mfpu=neon.\n  Revised pngvalid to generate size images with as many filters as it can\n    manage, limited by the number of rows.\n  Cleaned up ARM NEON compilation handling. The tests are now in pngpriv.h\n    and detect the broken GCC compilers.\n\nVersion 1.6.7beta04 [October 26, 2013]\n  Allow clang derived from older GCC versions to use ARM intrinsics. This\n    causes all clang builds that use -mfpu=neon to use the intrinsics code,\n    not the assembler code.  This has only been tested on iOS 7. It may be\n    necessary to exclude some earlier clang versions but this seems unlikely.\n  Changed NEON implementation selection mechanism. This allows assembler\n    or intrinsics to be turned on at compile time during the build by defining\n    PNG_ARM_NEON_IMPLEMENTATION to the correct value (2 or 1).  This macro\n    is undefined by default and the build type is selected in pngpriv.h.\n\nVersion 1.6.7rc01 [November 2, 2013]\n  No changes.\n\nVersion 1.6.7rc02 [November 7, 2013]\n  Fixed #include in filter_neon_intrinsics.c and ctype macros. The ctype char\n    checking macros take an unsigned char argument, not a signed char.\n\nVersion 1.6.7 [November 14, 2013]\n  No changes.\n\nVersion 1.6.8beta01 [November 24, 2013]\n  Moved prototype for png_handle_unknown() in pngpriv.h outside of\n    the #ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED/#endif block.\n  Added \"-Wall\" to CFLAGS in contrib/pngminim/*/makefile\n  Conditionally compile some unused functions reported by -Wall in\n    pngminim.\n  Fixed 'minimal' builds. Various obviously useful minimal configurations\n    don't build because of missing contrib/libtests test programs and\n    overly complex dependencies in scripts/pnglibconf.dfa. This change\n    adds contrib/conftest/*.dfa files that can be used in automatic build\n    scripts to ensure that these configurations continue to build.\n  Enabled WRITE_INVERT and WRITE_PACK in contrib/pngminim/encoder.\n  Fixed pngvalid 'fail' function declaration on the Intel C Compiler.\n    This reverts to the previous 'static' implementation and works round\n    the 'unused static function' warning by using PNG_UNUSED().\n\nVersion 1.6.8beta02 [November 30, 2013]\n  Removed or marked PNG_UNUSED some harmless \"dead assignments\" reported\n    by clang scan-build.\n  Changed tabs to 3 spaces in png_debug macros and changed '\"%s\"m'\n    to '\"%s\" m' to improve portability among compilers.\n  Changed png_free_default() to free() in pngtest.c\n\nVersion 1.6.8rc01 [December 12, 2013]\n  Tidied up pngfix inits and fixed pngtest no-write builds.\n\nVersion 1.6.8rc02 [December 14, 2013]\n  Handle zero-length PLTE chunk or NULL palette with png_error()\n    instead of png_chunk_report(), which by default issues a warning\n    rather than an error, leading to later reading from a NULL pointer\n    (png_ptr->palette) in png_do_expand_palette(). This is CVE-2013-6954\n    and VU#650142.  Libpng-1.6.1 through 1.6.7 are vulnerable.\n    Libpng-1.6.0 and earlier do not have this bug.\n\nVersion 1.6.8 [December 19, 2013]\n  No changes.\n\nVersion 1.6.9beta01 [December 26, 2013]\n  Bookkeeping: Moved functions around (no changes). Moved transform\n    function definitions before the place where they are called so that\n    they can be made static. Move the intrapixel functions and the\n    grayscale palette builder out of the png?tran.c files. The latter\n    isn't a transform function and is no longer used internally, and the\n    former MNG specific functions are better placed in pngread/pngwrite.c\n  Made transform implementation functions static. This makes the internal\n    functions called by png_do_{read|write}_transformations static. On an\n    x86-64 DLL build (Gentoo Linux) this reduces the size of the text\n    segment of the DLL by 1208 bytes, about 0.6%. It also simplifies\n    maintenance by removing the declarations from pngpriv.h and allowing\n    easier changes to the internal interfaces.\n  Rebuilt configure scripts with automake-1.14.1 and autoconf-2.69\n    in the tar distributions.\n\nVersion 1.6.9beta02 [January 1, 2014]\n  Added checks for libpng 1.5 to pngvalid.c.  This supports the use of\n    this version of pngvalid in libpng 1.5\n  Merged with pngvalid.c from libpng-1.7 changes to create a single\n    pngvalid.c\n  Removed #error macro from contrib/tools/pngfix.c (Thomas Klausner).\n  Merged pngrio.c, pngtrans.c, pngwio.c, and pngerror.c with libpng-1.7.0\n  Merged libpng-1.7.0 changes to make no-interlace configurations work\n    with test programs.\n  Revised pngvalid.c to support libpng 1.5, which does not support the\n    PNG_MAXIMUM_INFLATE_WINDOW option, so #define it out when appropriate in\n    pngvalid.c\n  Allow unversioned links created on install to be disabled in configure.\n    In configure builds 'make install' changes/adds links like png.h\n    and libpng.a to point to the newly installed, versioned, files (e.g.\n    libpng17/png.h and libpng17.a). Three new configure options and some\n    rearrangement of Makefile.am allow creation of these links to be disabled.\n\nVersion 1.6.9beta03 [January 10, 2014]\n  Removed potentially misleading warning from png_check_IHDR().\n\nVersion 1.6.9beta04 [January 20, 2014]\n  Updated scripts/makefile.* to use CPPFLAGS (Cosmin).\n  Added clang attribute support (Cosmin).\n\nVersion 1.6.9rc01 [January 28, 2014]\n  No changes.\n\nVersion 1.6.9rc02 [January 30, 2014]\n  Quiet an uninitialized memory warning from VC2013 in png_get_png().\n\nVersion 1.6.9 [February 6, 2014]\n\nVersion 1.6.10beta01 [February 9, 2014]\n  Backported changes from libpng-1.7.0beta30 and beta31:\n  Fixed a large number of instances where PNGCBAPI was omitted from\n    function definitions.\n  Added pngimage test program for png_read_png() and png_write_png()\n    with two new test scripts.\n  Removed dependence on !PNG_READ_EXPAND_SUPPORTED for calling\n    png_set_packing() in png_read_png().\n  Fixed combination of ~alpha with shift. On read invert alpha, processing\n    occurred after shift processing, which causes the final values to be\n    outside the range that should be produced by the shift. Reversing the\n    order on read makes the two transforms work together correctly and mirrors\n    the order used on write.\n  Do not read invalid sBIT chunks. Previously libpng only checked sBIT\n    values on write, so a malicious PNG writer could therefore cause\n    the read code to return an invalid sBIT chunk, which might lead to\n    application errors or crashes.  Such chunks are now skipped (with\n    chunk_benign_error).\n  Make png_read_png() and png_write_png() prototypes in png.h depend\n    upon PNG_READ_SUPPORTED and PNG_WRITE_SUPPORTED.\n  Support builds with unsupported PNG_TRANSFORM_* values.  All of the\n    PNG_TRANSFORM_* values are always defined in png.h and, because they\n    are used for both read and write in some cases, it is not reliable\n    to #if out ones that are totally unsupported. This change adds error\n    detection in png_read_image() and png_write_image() to do a\n    png_app_error() if the app requests something that cannot be done\n    and it adds corresponding code to pngimage.c to handle such options\n    by not attempting to test them.\n\nVersion 1.6.10beta02 [February 23, 2014]\n  Moved redefines of png_error(), png_warning(), png_chunk_error(),\n    and png_chunk_warning() from pngpriv.h to png.h to make them visible\n    to libpng-calling applications.\n  Moved OS dependent code from arm/arm_init.c, to allow the included\n    implementation of the ARM NEON discovery function to be set at\n    build-time and provide sample implementations from the current code in the\n    contrib/arm-neon subdirectory. The __linux__ code has also been changed to\n    compile and link on Android by using /proc/cpuinfo, and the old linux code\n    is in contrib/arm-neon/linux-auxv.c.  The new code avoids POSIX and Linux\n    dependencies apart from opening /proc/cpuinfo and is C90 compliant.\n  Check for info_ptr == NULL early in png_read_end() so we don't need to\n    run all the png_handle_*() and depend on them to return if info_ptr == NULL.\n    This improves the performance of png_read_end(png_ptr, NULL) and makes\n    it more robust against future programming errors.\n  Check for __has_extension before using it in pngconf.h, to\n    support older Clang versions (Jeremy Sequoia).\n  Treat CRC error handling with png_set_crc_action(), instead of with\n    png_set_benign_errors(), which has been the case since libpng-1.6.0beta18.\n  Use a user warning handler in contrib/gregbook/readpng2.c instead of default,\n    so warnings will be put on stderr even if libpng has CONSOLE_IO disabled.\n  Added png_ptr->process_mode = PNG_READ_IDAT_MODE in png_push_read_chunk\n    after recognizing the IDAT chunk, which avoids an infinite loop while\n    reading a datastream whose first IDAT chunk is of zero-length.\n    This fixes CERT VU#684412 and CVE-2014-0333.\n  Don't recognize known sRGB profiles as sRGB if they have been hacked,\n    but don't reject them and don't issue a copyright violation warning.\n\nVersion 1.6.10beta03 [February 25, 2014]\n  Moved some documentation from png.h to libpng.3 and libpng-manual.txt\n  Minor editing of contrib/arm-neon/README and contrib/examples/*.c\n\nVersion 1.6.10rc01 [February 27, 2014]\n  Fixed typos in the manual and in scripts/pnglibconf.dfa (CFLAGS -> CPPFLAGS\n    and PNG_USR_CONFIG -> PNG_USER_CONFIG).\n\nVersion 1.6.10rc02 [February 28, 2014]\n  Removed unreachable return statement after png_chunk_error()\n    in pngrutil.c\n\nVersion 1.6.10rc03 [March 4, 2014]\n  Un-deprecated png_data_freer().\n\nVersion 1.6.10 [March 6, 2014]\n  No changes.\n\nVersion 1.6.11beta01 [March 17, 2014]\n  Use \"if (value != 0)\" instead of \"if (value)\" consistently.\n  Changed ZlibSrcDir from 1.2.5 to 1.2.8 in projects/vstudio.\n  Moved configuration information from the manual to the INSTALL file.\n\nVersion 1.6.11beta02 [April 6, 2014]\n  Removed #if/#else/#endif from inside two pow() calls in pngvalid.c because\n    they were handled improperly by Portland Group's PGI-14.1 - PGI-14.3\n    when using its \"__builtin_pow()\" function.\n  Silence 'unused parameter' build warnings (Cosmin Truta).\n  $(CP) is now used alongside $(RM_F).  Also, use 'copy' instead of 'cp'\n    where applicable, and applied other minor makefile changes (Cosmin).\n  Don't warn about invalid dimensions exceeding user limits (Cosmin).\n  Allow an easy replacement of the default pre-built configuration\n    header with a custom header, via the make PNGLIBCONF_H_PREBUILT\n    macro (Cosmin).\n\nVersion 1.6.11beta03 [April 6, 2014]\n  Fixed a typo in pngrutil.c, introduced in libpng-1.5.6, that interferes\n    with \"blocky\" expansion of sub-8-bit interlaced PNG files (Eric Huss).\n  Optionally use  __builtin_bswap16() in png_do_swap().\n\nVersion 1.6.11beta04 [April 19, 2014]\n  Made progressive reading of interlaced images consistent with the\n    behavior of the sequential reader and consistent with the manual, by\n    moving some code out of the PNG_READ_INTERLACING_SUPPORTED blocks. The\n    row_callback now receives the proper pass number and unexpanded rows, when\n    png_combine_row() isn't built or used, and png_set_interlace_handling()\n    is not called.\n  Allow PNG_sRGB_PROFILE_CHECKING = (-1) to mean no sRGB profile checking.\n\nVersion 1.6.11beta05 [April 26, 2014]\n  Do not reject ICC V2 profiles that lack padding (Kai-Uwe Behrmann).\n  Relocated closing bracket of the sRGB profile test loop to avoid getting\n    \"Not recognizing known sRGB profile that has been edited\" warning for\n    ICC V2 profiles that lack the MD5 signature in the profile header.\n\nVersion 1.6.11beta06 [May 19, 2014]\n  Added PNG_SKIP_sRGB_CHECK_PROFILE choice for png_set_option().\n\nVersion 1.6.11rc01 [May 27, 2014]\n  No changes.\n\nVersion 1.6.11rc02 [June 3, 2014]\n  Test ZLIB_VERNUM instead of PNG_ZLIB_VERNUM in contrib/tools/pngfix.c\n\nVersion 1.6.11 [June 5, 2014]\n  No changes.\n\nVersion 1.6.12rc01 [June 6, 2014]\n  Relocated new code from 1.6.11beta06 in png.c to a point after the\n    declarations (Max Stepin).\n\nVersion 1.6.12rc02 [June 7, 2014]\n  Changed file permissions of contrib/tools/intgamma.sh,\n    test-driver, and compile from 0644 to 0755 (Cosmin).\n\nVersion 1.6.12rc03 [June 8, 2014]\n  Ensure \"__has_attribute()\" macro exists before trying to use it with\n    old clang compilers (MacPorts Ticket #43939).\n\nVersion 1.6.12 [June 12, 2014]\n  No changes.\n\nVersion 1.6.13beta01 [July 4, 2014]\n  Quieted -Wsign-compare and -Wclobber compiler warnings in\n    contrib/pngminus/*.c\n  Added \"(void) png_ptr;\" where needed in contrib/gregbook to quiet\n    compiler complaints about unused pointers.\n  Split a long output string in contrib/gregbook/rpng2-x.c.\n  Added \"PNG_SET_OPTION\" requirement for sRGB chunk support to pnglibconf.dfa,\n    Needed for write-only support (John Bowler).\n  Changed \"if defined(__ARM_NEON__)\" to\n    \"if (defined(__ARM_NEON__) || defined(__ARM_NEON))\" (James Wu).\n  Fixed clang no-warning builds: png_digit was defined but never used.\n    \nVersion 1.6.13beta02 [July 21, 2014]\n  Fixed an incorrect separator (\"/\" should be \"\\\") in scripts/makefile.vcwin32\n    (bug report from Wolfgang S. Kechel).  Bug was introduced in libpng-1.6.11.\n    Also fixed makefile.bc32, makefile.bor, makefile.msc, makefile.intel, and\n    makefile.tc3 similarly.\n\nVersion 1.6.13beta03 [August 3, 2014]\n  Removed scripts/makefile.elf. It has not worked since libpng-1.5.0beta14\n    due to elimination of the PNG_FUNCTION_EXPORT and PNG_DATA_EXPORT\n    definitions from pngconf.h.\n  Ensure that CMakeLists.txt makes the target \"lib\" directory before making\n    symbolic link into it (SourceForge bug report #226 by Rolf Timmermans).\n\nVersion 1.6.13beta04 [August 8, 2014]\n  Added opinion that the ECCN (Export Control Classification Number) for\n    libpng is EAR99 to the README file.\n  Eliminated use of \"$<\" in makefile explicit rules, when copying\n    $PNGLIBCONF_H_PREBUILT.  This does not work on some versions of make;\n    bug introduced in libpng version 1.6.11.\n\nVersion 1.6.13rc01 [August 14, 2014]\n  Made \"ccopts\" agree with \"CFLAGS\" in scripts/makefile.hp* and makefile.*sunu\n\nVersion 1.6.13 [August 21, 2014]\n  No changes.\n\nVersion 1.6.14beta01 [September 14, 2014]\n  Guard usage of png_ptr->options with #ifdef PNG_SET_OPTION_SUPPORTED.\n  Do not build contrib/tools/pngfix.c when PNG_SETJMP_NOT_SUPPORTED,\n    to allow \"make\" to complete without setjmp support (bug report by\n    Claudio Fontana)\n  Add \"#include <setjmp.h>\" to contrib/tools/pngfix.c (John Bowler)\n\nVersion 1.6.14beta02 [September 18, 2014]\n  Use nanosleep() instead of usleep() in contrib/gregbook/rpng2-x.c\n    because usleep() is deprecated.\n  Define usleep() in contrib/gregbook/rpng2-x.c if not already defined\n    in unistd.h and nanosleep() is not available; fixes error introduced\n    in libpng-1.6.13.\n  Disable floating point exception handling in pngvalid.c when\n    PNG_FLOATING_ARITHMETIC is not supported (bug report by \"zootus\n    at users.sourceforge.net\").\n\nVersion 1.6.14beta03 [September 19, 2014]\n  Define FE_DIVBYZERO, FE_INVALID, and FE_OVERFLOW in pngvalid.c if not\n    already defined.  Revert floating point exception handling in pngvalid.c\n    to version 1.6.14beta01 behavior.\n\nVersion 1.6.14beta04 [September 27, 2014]\n  Fixed incorrect handling of the iTXt compression flag in pngrutil.c\n    (bug report by Shunsaku Hirata).  Bug was introduced in libpng-1.6.0.\n\nVersion 1.6.14beta05 [October 1, 2014]\n  Added \"option READ_iCCP enables READ_COMPRESSED_TEXT\" to pnglibconf.dfa\n\nVersion 1.6.14beta06 [October 5, 2014]\n  Removed unused \"text_len\" parameter from private function png_write_zTXt().\n  Conditionally compile some code in png_deflate_claim(), when\n    PNG_WARNINGS_SUPPORTED and PNG_ERROR_TEXT_SUPPORTED are disabled.\n  Replaced repeated code in pngpread.c with PNG_PUSH_SAVE_BUFFER_IF_FULL.\n  Added \"chunk iTXt enables TEXT\" and \"chunk zTXt enables TEXT\"\n    to pnglibconf.dfa.\n  Removed \"option READ_COMPRESSED_TEXT enables READ_TEXT\" from pnglibconf.dfa,\n    to make it possible to configure a libpng that supports iCCP but not TEXT.\n\nVersion 1.6.14beta07 [October 7, 2014]\n  Removed \"option WRITE_COMPRESSED_TEXT enables WRITE_TEXT\" from pnglibconf.dfa\n  Only mark text chunks as written after successfully writing them.\n\nVersion 1.6.14rc01 [October 15, 2014]\n  Fixed some typos in comments.\n\nVersion 1.6.14rc02 [October 17, 2014]\n  Changed png_convert_to_rfc_1123() to png_convert_to_rfc_1123_buffer()\n    in the manual, to reflect the change made in libpng-1.6.0.\n  Updated README file to explain that direct access to the png_struct\n    and info_struct members has not been permitted since libpng-1.5.0.\n\nVersion 1.6.14 [October 23, 2014]\n  No changes.\n\nVersion 1.6.15beta01 [October 29, 2014]\n  Changed \"if (!x)\" to \"if (x == 0)\" and \"if (x)\" to \"if (x != 0)\"\n  Simplified png_free_data().\n  Added missing \"ptr = NULL\" after some instances of png_free().\n\nVersion 1.6.15beta02 [November 1, 2014]\n  Changed remaining \"if (!x)\" to \"if (x == 0)\" and \"if (x)\" to \"if (x != 0)\"\n\nVersion 1.6.15beta03 [November 3, 2014]\n  Added PNG_USE_ARM_NEON configuration flag (Marcin Juszkiewicz).\n\nVersion 1.6.15beta04 [November 4, 2014]\n  Removed new PNG_USE_ARM_NEON configuration flag and made a one-line\n    revision to configure.ac to support ARM on aarch64 instead (John Bowler).\n\nVersion 1.6.15beta05 [November 5, 2014]\n  Use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING in\n    example.c, pngtest.c, and applications in the contrib directory.\n  Fixed an out-of-range read in png_user_version_check() (Bug report from\n    Qixue Xiao, CVE-2015-8540).\n  Simplified and future-proofed png_user_version_check().\n  Fixed GCC unsigned int->float warnings. Various versions of GCC\n    seem to generate warnings when an unsigned value is implicitly\n    converted to double. This is probably a GCC bug but this change\n    avoids the issue by explicitly converting to (int) where safe.\n  Free all allocated memory in pngimage. The file buffer cache was left\n    allocated at the end of the program, harmless but it causes memory\n    leak reports from clang.\n  Fixed array size calculations to avoid warnings. At various points\n    in the code the number of elements in an array is calculated using\n    sizeof.  This generates a compile time constant of type (size_t) which\n    is then typically assigned to an (unsigned int) or (int). Some versions\n    of GCC on 64-bit systems warn about the apparent narrowing, even though\n    the same compiler does apparently generate the correct, in-range,\n    numeric constant.  This adds appropriate, safe, casts to make the\n    warnings go away.\n\nVersion 1.6.15beta06 [November 6, 2014]\n  Reverted use png_get_libpng_ver(NULL) instead of PNG_LIBPNG_VER_STRING\n    in the manual, example.c, pngtest.c, and applications in the contrib\n    directory.  It was incorrect advice.\n\nVersion 1.6.15beta07 [November 7, 2014]\n  Removed #ifdef PNG_16BIT_SUPPORTED/#endif around png_product2(); it is\n    needed by png_reciprocal2().\n  Added #ifdef PNG_16BIT_SUPPORTED/#endif around png_log16bit() and\n    png_do_swap().\n  Changed all \"#endif /* PNG_FEATURE_SUPPORTED */\" to \"#endif /* FEATURE */\"\n\nVersion 1.6.15beta08 [November 8, 2014]\n  More housecleaning in *.h\n\nVersion 1.6.15rc01 [November 13, 2014]\n\nVersion 1.6.15rc02 [November 14, 2014]\n  The macros passed in the command line to Borland make were ignored if\n    similarly-named macros were already defined in makefiles. This behavior\n    is different from POSIX make and other make programs.  Surround the\n    macro definitions with ifndef guards (Cosmin).\n\nVersion 1.6.15rc03 [November 16, 2014]\n  Added \"-D_CRT_SECURE_NO_WARNINGS\" to CFLAGS in scripts/makefile.vcwin32.\n  Removed the obsolete $ARCH variable from scripts/makefile.darwin.\n\nVersion 1.6.15 [November 20, 2014]\n  No changes.\n\nVersion 1.6.16beta01 [December 14, 2014]\n  Added \".align 2\" to arm/filter_neon.S to support old GAS assemblers that\n    don't do alignment correctly.\n  Revised Makefile.am and scripts/symbols.dfn to work with MinGW/MSYS\n    (Bob Friesenhahn).\n\nVersion 1.6.16beta02 [December 15, 2014]\n  Revised Makefile.am and scripts/*.dfn again to work with MinGW/MSYS;\n    renamed scripts/*.dfn to scripts/*.c (John Bowler).\n\nVersion 1.6.16beta03 [December 21, 2014]\n  Quiet a \"comparison always true\" warning in pngstest.c (John Bowler).\n\nVersion 1.6.16rc01 [December 21, 2014]\n  Restored a test on width that was removed from png.c at libpng-1.6.9\n    (Bug report by Alex Eubanks, CVE-2015-0973).\n\nVersion 1.6.16rc02 [December 21, 2014]\n  Undid the update to pngrutil.c in 1.6.16rc01.\n\nVersion 1.6.16rc03 [December 21, 2014]\n  Fixed an overflow in png_combine_row() with very wide interlaced images\n    (Bug report and fix by John Bowler, CVE-2014-9495).\n\nVersion 1.6.16 [December 22, 2014]\n  No changes.\n\nVersion 1.6.17beta01 [January 29, 2015]\n  Removed duplicate PNG_SAFE_LIMITS_SUPPORTED handling from pngconf.h\n  Corrected the width limit calculation in png_check_IHDR().\n  Removed user limits from pngfix. Also pass NULL pointers to\n    png_read_row to skip the unnecessary row de-interlace stuff.\n  Added testing of png_set_packing() to pngvalid.c\n  Regenerated configure scripts in the *.tar distributions with libtool-2.4.4\n  Implement previously untested cases of libpng transforms in pngvalid.c\n  Fixed byte order in png_do_read_filler() with 16-bit input. Previously\n    the high and low bytes of the filler, from png_set_filler() or from\n    png_set_add_alpha(), were read in the wrong order.\n  Made the check for out-of-range values in png_set_tRNS() detect\n    values that are exactly 2^bit_depth, and work on 16-bit platforms.\n  Merged some parts of libpng-1.6.17beta01 and libpng-1.7.0beta47.\n  Added #ifndef __COVERITY__ where needed in png.c, pngrutil.c and\n    pngset.c to avoid warnings about dead code.\n  Added \"& 0xff\" to many instances of expressions that are typecast\n    to (png_byte), to avoid Coverity warnings.\n\nVersion 1.6.17beta02 [February 7, 2015]\n  Work around one more Coverity-scan dead-code warning.\n  Do not build png_product2() when it is unused.\n\nVersion 1.6.17beta03 [February 17, 2015]\n  Display user limits in the output from pngtest.\n  Eliminated the PNG_SAFE_LIMITS macro and restored the 1-million-column\n    and 1-million-row default limits in pnglibconf.dfa, that can be reset\n    by the user at build time or run time.  This provides a more robust\n    defense against DOS and as-yet undiscovered overflows.\n\nVersion 1.6.17beta04 [February 21, 2015]\n  Added PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED macro, on by default.\n  Allow user to call png_get_IHDR() with NULL arguments (Reuben Hawkins).\n  Rebuilt configure scripts with automake-1.15 and libtool-2.4.6\n\nVersion 1.6.17beta05 [February 25, 2015]\n  Restored compiling of png_reciprocal2 with PNG_NO_16BIT.\n\nVersion 1.6.17beta06 [February 27, 2015]\n  Moved png_set_filter() prototype into a PNG_WRITE_SUPPORTED block\n    of png.h.\n  Avoid runtime checks when converting integer to png_byte with\n    Visual Studio (Sergey Kosarevsky)\n\nVersion 1.6.17rc01 [March 4, 2015]\n  No changes.\n\nVersion 1.6.17rc02 [March 9, 2015]\n  Removed some comments that the configure script did not handle\n    properly from scripts/pnglibconf.dfa and pnglibconf.h.prebuilt.\n  Free the unknown_chunks structure even when it contains no data.\n\nVersion 1.6.17rc03 [March 12, 2015]\n  Updated CMakeLists.txt to add OSX framework, change YES/NO to ON/OFF\n    for consistency, and remove some useless tests (Alexey Petruchik).\n\nVersion 1.6.17rc04 [March 16, 2015]\n  Remove pnglibconf.h, pnglibconf.c, and pnglibconf.out instead of\n    pnglibconf.* in \"make clean\" (Cosmin).\n  Fix bug in calculation of maxbits, in png_write_sBIT, introduced\n    in libpng-1.6.17beta01 (John Bowler).\n\nVersion 1.6.17rc05 [March 21, 2015]\n  Define PNG_FILTER_* and PNG_FILTER_VALUE_* in png.h even when WRITE\n    is not supported (John Bowler).  This fixes an error introduced in\n    libpng-1.6.17beta06.\n  Reverted \"& 0xff\" additions of version 1.6.17beta01. Libpng passes\n    the Coverity scan without them.\n\nVersion 1.6.17rc06 [March 23, 2015]\n  Remove pnglibconf.dfn and pnglibconf.pre with \"make clean\".\n  Reformatted some \"&0xff\" instances to \"& 0xff\".\n  Fixed simplified 8-bit-linear to sRGB alpha. The calculated alpha\n    value was wrong.  It's not clear if this affected the final stored\n    value; in the obvious code path the upper and lower 8-bits of the\n    alpha value were identical and the alpha was truncated to 8-bits\n    rather than dividing by 257 (John Bowler).\n\nVersion 1.6.17 [March 26, 2015]\n  No changes.\n\nVersion 1.6.18beta01 [April 1, 2015]\n  Removed PNG_SET_CHUNK_[CACHE|MALLOC]_LIMIT_SUPPORTED macros.  They\n    have been combined with PNG_SET_USER_LIMITS_SUPPORTED (resolves\n    bug report by Andrew Church).\n  Fixed rgb_to_gray checks and added tRNS checks to pngvalid.c.  This\n    fixes some arithmetic errors that caused some tests to fail on\n    some 32-bit platforms (Bug reports by Peter Breitenlohner [i686]\n    and Petr Gajdos [i586]).\n\nVersion 1.6.18beta02 [April 26, 2015]\n  Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler\n    (Bug report by Viktor Szakats).\n\nVersion 1.6.18beta03 [May 6, 2015]\n  Replaced \"unexpected\" with an integer (0xabadca11) in pngset.c\n    where a long was expected, to avoid a compiler warning when PNG_DEBUG > 1.\n  Added contrib/examples/simpleover.c, to demonstrate how to handle\n    alpha compositing of multiple images, using the \"simplified API\"\n    and an example PNG generation tool, contrib/examples/genpng.c\n    (John Bowler).\n\nVersion 1.6.18beta04 [May 20, 2015]\n  PNG_RELEASE_BUILD replaces tests where the code depended on the build base\n    type and can be defined on the command line, allowing testing in beta\n    builds (John Bowler).\n  Avoid Coverity issue 80858 (REVERSE NULL) in pngtest.c PNG_DEBUG builds.\n  Avoid a harmless potential integer overflow in png_XYZ_from_xy() (Bug\n    report from Christopher Ferris).\n\nVersion 1.6.18beta05 [May 31, 2015]\n  Backport filter selection code from libpng-1.7.0beta51, to combine\n    sub_row, up_row, avg_row, and paeth_row into try_row and tst_row.\n  Changed png_voidcast(), etc., to voidcast(), etc., in contrib/tools/pngfix.c\n    to avoid confusion with the libpng private macros.\n  Fixed old cut&paste bug in the weighted filter selection code in\n    pngwutil.c, introduced in libpng-0.95, March 1997.\n\nVersion 1.6.18beta06 [June 1, 2015]\n  Removed WRITE_WEIGHTED_FILTERED code, to save a few kbytes of the\n    compiled library size. It never worked properly and as far as we can\n    tell, no one uses it. The png_set_filter_heuristics() and\n    png_set_filter_heuristics_fixed() APIs are retained but deprecated\n    and do nothing.\n\nVersion 1.6.18beta07 [June 6, 2015]\n  Removed non-working progressive reader 'skip' function. This\n    function has apparently never been used. It was implemented\n    to support back-door modification of png_struct in libpng-1.4.x\n    but (because it does nothing and cannot do anything) was apparently\n    never tested (John Bowler).\n  Fixed cexcept.h in which GCC 5 now reports that one of the auto\n    variables in the Try macro needs to be volatile to prevent value\n    being lost over the setjmp (John Bowler).\n  Fixed NO_WRITE_FILTER and -Wconversion build breaks (John Bowler).\n  Fix g++ build breaks (John Bowler).\n  Quieted some Coverity issues in pngfix.c, png-fix-itxt.c, pngvalid.c,\n    pngstest.c, and pngimage.c. Most seem harmless, but png-fix-itxt\n    would only work with iTXt chunks with length 255 or less.\n  Added #ifdef's to contrib/examples programs so people don't try\n    to compile them without the minimum required support enabled\n    (suggested by Flavio Medeiros).\n\nVersion 1.6.18beta08 [June 30, 2015]\n  Eliminated the final two Coverity defects (insecure temporary file\n    handling in contrib/libtests/pngstest.c; possible overflow of\n    unsigned char in contrib/tools/png-fix-itxt.c). To use the \"secure\"\n    file handling, define PNG_USE_MKSTEMP, otherwise \"tmpfile()\" will\n    be used.\n  Removed some unused WEIGHTED_FILTER macros from png.h and pngstruct.h\n\nVersion 1.6.18beta09 [July 5, 2015]\n  Removed some useless typecasts from contrib/tools/png-fix-itxt.c\n  Fixed a new signed-unsigned comparison in pngrtran.c (Max Stepin).\n  Replaced arbitrary use of 'extern' with #define PNG_LINKAGE_*.  To\n    preserve API compatibility, the new defines all default to \"extern\"\n    (requested by Jan Nijtmans).\n\nVersion 1.6.18rc01 [July 9, 2015]\n  Belatedly added Mans Rullgard and James Yu to the list of Contributing\n    Authors.\n\nVersion 1.6.18rc02 [July 12, 2015]\n  Restored unused FILTER_HEURISTIC macros removed at libpng-1.6.18beta08\n    to png.h to avoid compatibility warnings.\n\nVersion 1.6.18rc03 [July 15, 2015]\n  Minor changes to the man page\n\nVersion 1.6.18 [July 23, 2015]\n  No changes.\n\nVersion 1.6.19beta01 [July 30, 2015]\n  Updated obsolete information about the simplified API macros in the\n    manual pages (Bug report by Arc Riley).\n  Avoid potentially dereferencing NULL info_ptr in png_info_init_3().\n  Rearranged png.h to put the major sections in the same order as\n    in libpng17.\n  Eliminated unused PNG_COST_SHIFT, PNG_WEIGHT_SHIFT, PNG_COST_FACTOR, and\n    PNG_WEIGHT_FACTOR macros.\n  Suppressed some warnings from the Borland C++ 5.5.1/5.82 compiler\n    (Bug report by Viktor Szakats).  Several warnings remain and are\n    unavoidable, where we test for overflow.\n  Fixed potential leak of png_pixels in contrib/pngminus/pnm2png.c\n  Fixed uninitialized variable in contrib/gregbook/rpng2-x.c\n\nVersion 1.6.19beta02 [August 19, 2015]\n  Moved config.h.in~ from the \"libpng_autotools_files\" list to the\n    \"libpng_autotools_extra\" list in autogen.sh because it was causing a\n    false positive for missing files (bug report by Robert C. Seacord).\n  Removed unreachable \"break\" statements in png.c, pngread.c, and pngrtran.c\n    to suppress clang warnings (Bug report by Viktor Szakats).\n  Fixed some bad links in the man page.\n  Changed \"n bit\" to \"n-bit\" in comments.\n  Added signed/unsigned 16-bit safety net. This removes the dubious\n    0x8000 flag definitions on 16-bit systems. They aren't supported\n    yet the defs *probably* work, however it seems much safer to do this\n    and be advised if anyone, contrary to advice, is building libpng 1.6\n    on a 16-bit system. It also adds back various switch default clauses\n    for GCC; GCC errors out if they are not present (with an appropriately\n    high level of warnings).\n  Safely convert num_bytes to a png_byte in png_set_sig_bytes() (Robert\n    Seacord).\n  Fixed the recently reported 1's complement security issue by replacing\n    the value that is illegal in the PNG spec, in both signed and unsigned\n    values, with 0. Illegal unsigned values (anything greater than or equal\n    to  0x80000000) can still pass through, but since these are not illegal\n    in ANSI-C (unlike 0x80000000 in the signed case) the checking that\n    occurs later can catch them (John Bowler).\n\nVersion 1.6.19beta03 [September 26, 2015]\n  Fixed png_save_int_32 when int is not 2's complement (John Bowler).\n  Updated libpng16 with all the recent test changes from libpng17,\n    including changes to pngvalid.c to ensure that the original,\n    distributed, version of contrib/visupng/cexcept.h can be used\n    (John Bowler).\n  pngvalid contains the correction to the use of SAVE/STORE_\n    UNKNOWN_CHUNKS; a bug revealed by changes in libpng 1.7. More\n    tests contain the --strict option to detect warnings and the\n    pngvalid-standard test has been corrected so that it does not\n    turn on progressive-read. There is a separate test which does\n    that. (John Bowler)\n  Also made some signed/unsigned fixes.\n  Make pngstest error limits version specific. Splitting the machine\n    generated error structs out to a file allows the values to be updated\n    without changing pngstest.c itself. Since libpng 1.6 and 1.7 have\n    slightly different error limits this simplifies maintenance. The\n    makepngs.sh script has also been updated to more accurately reflect\n    current problems in libpng 1.7 (John Bowler).\n  Incorporated new test PNG files into make check.  tests/pngstest-*\n    are changed so that the new test files are divided into 8 groups by\n    gamma and alpha channel.  These tests have considerably better code\n    and pixel-value coverage than contrib/pngsuite; however,coverage is\n    still incomplete (John Bowler).\n  Removed the '--strict' in 1.6 because of the double-gamma-correction\n    warning, updated pngstest-errors.h for the errors detected with the\n    new contrib/testspngs PNG test files (John Bowler).\n\nVersion 1.6.19beta04 [October 15, 2015]\n  Worked around rgb-to-gray issues in libpng 1.6.  The previous\n    attempts to ignore the errors in the code aren't quite enough to\n    deal with the 'channel selection' encoding added to libpng 1.7; abort.\n    pngvalid.c is changed to drop this encoding in prior versions.\n  Fixed 'pow' macros in pngvalid.c. It is legal for 'pow' to be a\n    macro, therefore the argument list cannot contain preprocessing\n    directives.  Make sure pow is a function where this happens. This is\n    a minimal safe fix, the issue only arises in non-performance-critical\n    code (bug report by Curtis Leach, fix by John Bowler).\n  Added sPLT support to pngtest.c\n\nVersion 1.6.19rc01 [October 23, 2015]\n  No changes.\n\nVersion 1.6.19rc02 [October 31, 2015]\n  Prevent setting or writing over-length PLTE chunk (Cosmin Truta).\n  Silently truncate over-length PLTE chunk while reading.\n  Libpng incorrectly calculated the output rowbytes when the application\n    decreased either the number of channels or the bit depth (or both) in\n    a user transform.  This was safe; libpng overallocated buffer space\n   (potentially by quite a lot; up to 4 times the amount required) but,\n   from 1.5.4 on, resulted in a png_error (John Bowler).\n\nVersion 1.6.19rc03 [November 3, 2015]\n  Fixed some inconsequential cut-and-paste typos in png_set_cHRM_XYZ_fixed().\n  Clarified COPYRIGHT information to state explicitly that versions\n    are derived from previous versions.\n  Removed much of the long list of previous versions from png.h and\n    libpng.3.\n\nVersion 1.6.19rc04 [November 5, 2015]\n  Fixed new bug with CRC error after reading an over-length palette\n    (bug report by Cosmin Truta) (CVE-2015-8126).\n\nVersion 1.6.19 [November 12, 2015]\n  Cleaned up coding style in png_handle_PLTE().\n\nVersion 1.6.20beta01 [November 20, 2015]\n  Avoid potential pointer overflow/underflow in png_handle_sPLT() and\n    png_handle_pCAL() (Bug report by John Regehr).\n\nVersion 1.6.20beta02 [November 23, 2015]\n  Fixed incorrect implementation of png_set_PLTE() that uses png_ptr\n    not info_ptr, that left png_set_PLTE() open to the CVE-2015-8126\n    vulnerability.  Fixes CVE-2015-8472.\n\nVersion 1.6.20beta03 [November 24, 2015]\n  Backported tests from libpng-1.7.0beta69.\n\nVersion 1.6.20rc01 [November 26, 2015]\n  Fixed an error in handling of bad zlib CMINFO field in pngfix, found by\n    American Fuzzy Lop, reported by Brian Carpenter.  inflate() doesn't\n    immediately fault a bad CMINFO field; instead a 'too far back' error\n    happens later (at least some times).  pngfix failed to limit CMINFO to\n    the allowed values but then assumed that window_bits was in range,\n    triggering an assert. The bug is mostly harmless; the PNG file cannot\n    be fixed.\n\nVersion 1.6.20rc02 [November 29, 2015]\n  In libpng 1.6 zlib initialization was changed to use the window size\n    in the zlib stream, not a fixed value. This causes some invalid images,\n    where CINFO is too large, to display 'correctly' if the rest of the\n    data is valid.  This provides a workaround for zlib versions where the\n    error arises (ones that support the API change to use the window size\n    in the stream).\n\nVersion 1.6.20 [December 3, 2015]\n  No changes.\n\nVersion 1.6.21beta01 [December 11, 2015]\n  Fixed syntax \"$(command)\" in tests/pngstest that some shells other than\n    bash could not parse (Bug report by Nelson Beebe). Use `command` instead.\n\nVersion 1.6.21beta02 [December 14, 2015]\n  Moved png_check_keyword() from pngwutil.c to pngset.c\n  Removed LE/BE dependencies in pngvalid, to 'fix' the current problem\n    in the BigEndian tests by not testing it, making the BE code the same \n    as the LE version.\n  Fixes to pngvalid for various reduced build configurations (eliminate unused\n    statics) and a fix for the case in rgb_to_gray when the digitize option\n    reduces graylo to 0, producing a large error.\n\nVersion 1.6.21beta03 [December 18, 2015]\n  Widened the 'limit' check on the internally calculated error limits in\n    the 'DIGITIZE' case (the code used prior to 1.7 for rgb_to_gray error\n    checks) and changed the check to only operate in non-release builds\n    (base build type not RC or RELEASE.)\n  Fixed undefined behavior in pngvalid.c, undefined because\n    (png_byte) << shift is undefined if it changes the signed bit\n    (because png_byte is promoted to int). The libpng exported functions\n    png_get_uint_32 and png_get_uint_16 handle this. (Bug reported by\n    David Drysdale as a result of reports from UBSAN in clang 3.8).\n  This changes pngvalid to use BE random numbers; this used to produce\n    errors but these should not be fixed as a result of the previous changes.\n\nVersion 1.6.21rc01 [January 4, 2016]\n  In projects/vstudio, combined readme.txt and WARNING into README.txt\n\nVersion 1.6.21rc02 [January 7, 2016]\n  Relocated assert() in contrib/tools/pngfix.c, bug found by American\n    Fuzzy Lop, reported by Brian Carpenter.\n  Marked 'limit' UNUSED in transform_range_check().  This only affects\n    release builds.\n\nVersion 1.6.21 [January 15, 2016]\n  Worked around a false-positive Coverity issue in pngvalid.c.\n\nVersion 1.6.22beta01 [January 23, 2016]\n  Changed PNG_USE_MKSTEMP to __COVERITY__ to select alternate\n    \"tmpfile()\" implementation in contrib/libtests/pngstest.c\n  Fixed NO_STDIO build of pngunknown.c to skip calling png_init_io()\n    if there is no stdio.h support.\n  Added a png_image_write_to_memory() API and a number of assist macros\n    to allow an application that uses the simplified API write to bypass\n    stdio and write directly to memory.\n  Added some warnings (png.h) and some check code to detect *possible*\n    overflow in the ROW_STRIDE and simplified image SIZE macros.  This\n    disallows image width/height/format that *might* overflow.  This is\n    a quiet API change that limits in-memory image size (uncompressed) to\n    less than 4GByte and image row size (stride) to less than 2GByte.\n  Revised workaround for false-positive Coverity issue in pngvalid.c.\n\nVersion 1.6.22beta02 [February 8, 2016]\n  Only use exit(77) in configure builds.\n  Corrected error in PNG_IMAGE_PNG_SIZE_MAX. This new macro underreported\n    the palette size because it failed to take into account that the memory\n    palette has to be expanded to full RGB when it is written to PNG.\n  Updated CMakeLists.txt, added supporting scripts/gen*.cmake.in\n    and test.cmake.in (Roger Leigh).\n  Relaxed limit checks on gamma values in pngrtran.c. As suggested in\n    the comments gamma values outside the range currently permitted\n    by png_set_alpha_mode are useful for HDR data encoding.  These values\n    are already permitted by png_set_gamma so it is reasonable caution to\n    extend the png_set_alpha_mode range as HDR imaging systems are starting\n    to emerge.\n\nVersion 1.6.22beta03 [March 9, 2016]\n  Added a common-law trademark notice and export control information\n    to the LICENSE file, png.h, and the man page.\n  Restored \"& 0xff\" in png_save_uint_16() and png_save_uint_32() that\n    were accidentally removed from libpng-1.6.17. \n  Changed PNG_INFO_cHNK and PNG_FREE_cHNK from 0xnnnn to 0xnnnnU in png.h\n    (Robert C. Seacord).\n  Removed dubious \"#if INT_MAX\" test from png.h that was added to\n    libpng-1.6.19beta02 (John Bowler).\n  Add ${INCLUDES} in scripts/genout.cmake.in (Bug report by Nixon Kwok).\n  Updated LICENSE to say files in the contrib directory are not\n    necessarily under the libpng license, and that some makefiles have\n    other copyright owners.\n  Added INTEL-SSE2 support (Mike Klein and Matt Sarett, Google, Inc.).\n  Made contrib/libtests/timepng more robust.  The code no longer gives\n    up/fails on invalid PNG data, it just skips it (with error messages).\n    The code no longer fails on PNG files with data beyond IEND.  Options\n    exist to use png_read_png (reading the whole image, not by row) and, in\n    that case, to apply any of the supported transforms.  This makes for\n    more realistic testing; the decoded data actually gets used in a\n    meaningful fashion (John Bowler).\n  Fixed some misleading indentation (Krishnaraj Bhat).\n\nVersion 1.6.22beta04 [April 5, 2016]\n  Force GCC compilation to C89 if needed (Dagobert Michelsen).\n  SSE filter speed improvements for bpp=3:\n    memcpy-free implementations of load3() / store3().\n    call load3() only when needed at the end of a scanline.\n\nVersion 1.6.22beta05 [April 27, 2016]\n  Added PNG_FAST_FILTERS macro (defined as\n    PNG_FILTER_NONE|PNG_FILTER_SUB|PNG_FILTER_UP).\n  Various fixes for contrib/libtests/timepng.c\n  Moved INTEL-SSE code from pngpriv.h into contrib/intel/intel_sse.patch.\n  Fixed typo (missing underscore) in #define PNG_READ_16_TO_8_SUPPORTED\n    (Bug report by Y.Ohashik).\n\nVersion 1.6.22beta06 [May 5, 2016]\n  Rebased contrib/intel_sse.patch.\n  Quieted two Coverity issues in contrib/libtests/timepng.c.\n  Fixed issues with scripts/genout.cmake.in (David Capello, Nixon Kwok):\n    Added support to use multiple directories in ZLIBINCDIR variable,\n    Fixed CMAKE_C_FLAGS with multiple values when genout is compiled on MSVC,\n    Fixed pnglibconf.c compilation on OS X including the sysroot path.\n\nVersion 1.6.22rc01 [May 14, 2016]\n  No changes.\n\nVersion 1.6.22rc02 [May 16, 2016]\n  Removed contrib/timepng from default build; it does not build on platforms\n    that don't supply clock_gettime().\n\nVersion 1.6.22rc03 [May 17, 2016]\n  Restored contrib/timepng to default build but check for the presence\n    of clock_gettime() in configure.ac and Makefile.am.\n\nVersion 1.6.22 [May 26, 2016]\n  No changes.\n\nVersion 1.6.23beta01 [May 29, 2016]\n  Stop a potential memory leak in png_set_tRNS() (Bug report by Ted Ying).\n  Fixed the progressive reader to handle empty first IDAT chunk properly\n    (patch by Timothy Nikkel).  This bug was introduced in libpng-1.6.0 and\n    only affected the libpng16 branch.\n  Added tests in pngvalid.c to check zero-length IDAT chunks in various\n    positions.  Fixed the sequential reader to handle these more robustly\n    (John Bowler).\n\nVersion 1.6.23rc01 [June 2, 2016]\n  Corrected progressive read input buffer in pngvalid.c. The previous version\n    the code invariably passed just one byte at a time to libpng.  The intent\n    was to pass a random number of bytes in the range 0..511.\n  Moved sse2 prototype from pngpriv.h to contrib/intel/intel_sse.patch.\n  Added missing \")\" in pngerror.c (Matt Sarrett).\n\nVersion 1.6.23rc02 [June 4, 2016]\n  Fixed undefined behavior in png_push_save_buffer(). Do not call\n    memcpy() with a null source, even if count is zero (Leon Scroggins III).\n\nVersion 1.6.23 [June 9, 2016]\n  Fixed bad link to RFC2083 in png.5 (Nikola Forro).\n\nVersion 1.6.24beta01 [June 11, 2016]\n  Avoid potential overflow of the PNG_IMAGE_SIZE macro.  This macro\n    is not used within libpng, but is used in some of the examples.\n\nVersion 1.6.24beta02 [June 23, 2016]\n  Correct filter heuristic overflow handling. This was broken when the\n    write filter code was moved out-of-line; if there is a single filter and\n    the heuristic sum overflows the calculation of the filtered line is not\n    completed.  In versions prior to 1.6 the code was duplicated in-line\n    and the check not performed, so the filter operation completed; however,\n    in the multi-filter case where the sum is performed the 'none' filter would\n    be selected if all the sums overflowed, even if it wasn't in the filter\n    list.  The fix to the first problem is simply to provide PNG_SIZE_MAX as\n    the current lmins sum value; this means the sum can never exceed it and\n    overflows silently.  A reasonable compiler that does choose to inline\n    the code will simply eliminate the sum check.\n  The fix to the second problem is to use high precision arithmetic (this is\n    implemented in 1.7), however a simple safe fix here is to chose the lowest\n    numbered filter in the list from png_set_filter (this only works if the\n    first problem is also fixed) (John Bowler).\n  Use a more efficient absolute value calculation on SSE2 (Matthieu Darbois).\n  Fixed the case where PNG_IMAGE_BUFFER_SIZE can overflow in the application\n    as a result of the application using an increased 'row_stride'; previously\n    png_image_finish_read only checked for overflow on the base calculation of\n    components.  (I.e. it checked for overflow of a 32-bit number on the total\n    number of pixel components in the output format, not the possibly padded row\n    length and not the number of bytes, which for linear formats is twice the\n    number of components.)\n  MSVC does not like '-(unsigned)', so replaced it with 0U-(unsigned)\n  MSVC does not like (uInt) = -(unsigned) (i.e. as an initializer), unless\n    the conversion is explicitly invoked by a cast.\n  Put the SKIP definition in the correct place. It needs to come after the\n    png.h include (see all the other .c files in contrib/libtests) because it\n    depends on PNG_LIBPNG_VER.\n  Removed the three compile warning options from the individual project\n    files into the zlib.props globals.  It increases the warning level from 4\n    to All and adds a list of the warnings that need to be turned off.  This is\n    semi-documentary; the intent is to tell libpng users which warnings have\n    been examined and judged non-fixable at present.  The warning about\n    structure padding is fixable, but it would be a signficant change (moving\n    structure members around).\n\nVersion 1.6.24beta03 [July 4, 2016]\n  Optimized absolute value calculation in filter selection, similar to\n    code in the PAETH decoder in pngrutil.c. Build with PNG_USE_ABS to\n    use this.\n  Added pngcp to the build together with a pngcp.dfa configuration test.\n  Added high resolution timing to pngcp.\n  Added \"Common linking failures\" section to INSTALL.\n  Relocated misplaced #endif in png.c sRGB profile checking.\n  Fixed two Coverity issues in pngcp.c.\n\nVersion 1.6.24beta04 [July 8, 2016]\n  Avoid filter-selection heuristic sum calculations in cases where only one\n    filter is a candidate for selection. This trades off code size (added\n    private png_setup_*_row_only() functions) for speed.\n\nVersion 1.6.24beta05 [July 13, 2016]\n  Fixed some indentation to comply with our coding style.\n  Added contrib/tools/reindent.\n\nVersion 1.6.24beta06 [July 18, 2016]\n  Fixed more indentation to comply with our coding style.\n  Eliminated unnecessary tests of boolean png_isaligned() vs 0.\n\nVersion 1.6.24rc01 [July 25, 2016]\n  No changes.\n\nVersion 1.6.24rc02 [August 1, 2016]\n  Conditionally compile SSE2 headers in contrib/intel/intel_sse.patch\n  Conditionally compile png_decompress_chunk().\n\nVersion 1.6.24rc03 [August 2, 2016]\n  Conditionally compile ARM_NEON headers in pngpriv.h\n  Updated contrib/intel/intel_sse.patch\n\nVersion 1.6.24[August 4, 2016]\n  No changes.\n\nVersion 1.6.25beta01 [August 12, 2016]\n  Reject oversized iCCP profile immediately.\n  Cleaned up PNG_DEBUG compile of pngtest.c.\n  Conditionally compile png_inflate().\n\nVersion 1.6.25beta02 [August 18, 2016]\n  Don't install pngcp; it conflicts with pngcp in the pngtools package.\n  Minor editing of INSTALL, (whitespace, added copyright line)\n\nVersion 1.6.25rc01 [August 24, 2016]\n  No changes.\n\nVersion 1.6.25rc02 [August 29, 2016]\n  Added MIPS support (Mandar Sahastrabuddhe <Mandar.Sahastrabuddhe@imgtec.com>).\n  Only the UP filter is currently implemented.\n\nVersion 1.6.25rc03 [August 29, 2016]\n  Rebased contrib/intel/intel_sse.patch after the MIPS implementation.\n\nVersion 1.6.25rc04 [August 30, 2016]\n  Added MIPS support for SUB, AVG, and PAETH filters (Mandar Sahastrabuddhe).\n\nVersion 1.6.25rc05 [August 30, 2016]\n  Rebased contrib/intel/intel_sse.patch after the MIPS implementation update..\n\nVersion 1.6.25 [September 1, 2016]\n  No changes.\n\nSend comments/corrections/commendations to png-mng-implement at lists.sf.net\n(subscription required; visit\nhttps://lists.sourceforge.net/lists/listinfo/png-mng-implement\nto subscribe)\nor to glennrp at users.sourceforge.net\n\nGlenn R-P\n#endif\n"
  },
  {
    "path": "tess-two/jni/libpng/CMakeLists.txt",
    "content": "# CMakeLists.txt\n\n# Copyright (C) 2007,2009-2016 Glenn Randers-Pehrson\n# Written by Christian Ehrlicher, 2007\n# Revised by Roger Lowman, 2009-2010\n# Revised by Clifford Yapp, 2011-2012\n# Revised by Roger Leigh, 2016\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\ncmake_minimum_required(VERSION 2.8.3)\ncmake_policy(VERSION 2.8.3)\n\n# Set MacOSX @rpath usage globally.\nif (POLICY CMP0020)\n  cmake_policy(SET CMP0020 NEW)\nendif(POLICY CMP0020)\nif (POLICY CMP0042)\n  cmake_policy(SET CMP0042 NEW)\nendif(POLICY CMP0042)\n# Use new variable expansion policy.\nif (POLICY CMP0053)\n  cmake_policy(SET CMP0053 NEW)\nendif(POLICY CMP0053)\nif (POLICY CMP0054)\n  cmake_policy(SET CMP0054 NEW)\nendif(POLICY CMP0054)\n\nset(CMAKE_CONFIGURATION_TYPES \"Release;Debug;MinSizeRel;RelWithDebInfo\")\n\nproject(libpng C)\nenable_testing()\n\nset(PNGLIB_MAJOR 1)\nset(PNGLIB_MINOR 6)\nset(PNGLIB_RELEASE 25)\nset(PNGLIB_NAME libpng${PNGLIB_MAJOR}${PNGLIB_MINOR})\nset(PNGLIB_VERSION ${PNGLIB_MAJOR}.${PNGLIB_MINOR}.${PNGLIB_RELEASE})\n\n# needed packages\nfind_package(ZLIB REQUIRED)\ninclude_directories(${ZLIB_INCLUDE_DIR})\n\nif(NOT WIN32)\n  find_library(M_LIBRARY\n    NAMES m\n    PATHS /usr/lib /usr/local/lib\n  )\n  if(NOT M_LIBRARY)\n    message(STATUS \"math lib 'libm' not found; floating point support disabled\")\n  endif()\nelse()\n  # not needed on windows\n  set(M_LIBRARY \"\")\nendif()\n\n# COMMAND LINE OPTIONS\noption(PNG_SHARED \"Build shared lib\" ON)\noption(PNG_STATIC \"Build static lib\" ON)\noption(PNG_TESTS  \"Build libpng tests\" ON)\n\n# Many more configuration options could be added here\noption(PNG_FRAMEWORK \"Build OS X framework\" OFF)\noption(PNG_DEBUG     \"Build with debug output\" OFF)\noption(PNGARG        \"Disable ANSI-C prototypes\" OFF)\n\nset(PNG_PREFIX \"\" CACHE STRING \"Prefix to add to the API function names\")\nset(DFA_XTRA \"\" CACHE FILEPATH \"File containing extra configuration settings\")\n\n# SET LIBNAME\nset(PNG_LIB_NAME png${PNGLIB_MAJOR}${PNGLIB_MINOR})\n\n# to distinguish between debug and release lib\nset(CMAKE_DEBUG_POSTFIX \"d\")\n\ninclude(CheckCSourceCompiles)\noption(ld-version-script \"Enable linker version script\" ON)\nif(ld-version-script AND NOT APPLE)\n  # Check if LD supports linker scripts.\n  file(WRITE \"${CMAKE_CURRENT_BINARY_DIR}/conftest.map\" \"VERS_1 {\n        global: sym;\n        local: *;\n};\n\nVERS_2 {\n        global: sym2;\n                main;\n} VERS_1;\n\")\n  set(CMAKE_REQUIRED_FLAGS_SAVE ${CMAKE_REQUIRED_FLAGS})\n  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS} \"-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/conftest.map'\")\n  check_c_source_compiles(\"void sym(void) {}\nvoid sym2(void) {}\nint main(void) {return 0;}\n\" HAVE_LD_VERSION_SCRIPT)\n  if(NOT HAVE_LD_VERSION_SCRIPT)\n    set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE} \"-Wl,-M -Wl,${CMAKE_CURRENT_BINARY_DIR}/conftest.map\")\n  check_c_source_compiles(\"void sym(void) {}\nvoid sym2(void) {}\nint main(void) {return 0;}\n\" HAVE_SOLARIS_LD_VERSION_SCRIPT)\n  endif()\n  set(CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS_SAVE})\n  file(REMOVE \"${CMAKE_CURRENT_BINARY_DIR}/conftest.map\")\nendif()\n\n# Find symbol prefix.  Likely obsolete and unnecessary with recent\n# toolchains (it's not done in many other projects).\nfunction(symbol_prefix)\n  set(SYMBOL_PREFIX)\n\n  execute_process(COMMAND \"${CMAKE_C_COMPILER}\" \"-E\" \"-\"\n                  INPUT_FILE /dev/null\n                  OUTPUT_VARIABLE OUT\n                  RESULT_VARIABLE STATUS)\n\n  if(CPP_FAIL)\n    message(WARNING \"Failed to run the C preprocessor\")\n  endif()\n\n  string(REPLACE \"\\n\" \";\" OUT \"${OUT}\")\n  foreach(line ${OUT})\n    string(REGEX MATCH \"^PREFIX=\" found_match \"${line}\")\n    if(found_match)\n      STRING(REGEX REPLACE \"^PREFIX=(.*\\)\" \"\\\\1\" prefix \"${line}\")\n      string(REGEX MATCH \"__USER_LABEL_PREFIX__\" found_match \"${prefix}\")\n      if(found_match)\n        STRING(REGEX REPLACE \"(.*)__USER_LABEL_PREFIX__(.*)\" \"\\\\1\\\\2\" prefix \"${prefix}\")\n      endif()\n      set(SYMBOL_PREFIX \"${prefix}\")\n    endif()\n  endforeach()\n\n    message(STATUS \"Symbol prefix: ${SYMBOL_PREFIX}\")\n    set(SYMBOL_PREFIX \"${SYMBOL_PREFIX}\" PARENT_SCOPE)\nendfunction()\n\nif(UNIX)\n  symbol_prefix()\nendif()\n\nfind_program(AWK NAMES gawk awk)\n\ninclude_directories(${CMAKE_CURRENT_BINARY_DIR})\n\nif(NOT AWK)\n  # No awk available to generate sources; use pre-built pnglibconf.h\n  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt\n                 ${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h)\n  add_custom_target(genfiles) # Dummy\nelse()\n  include(CMakeParseArguments)\n  # Generate .chk from .out with awk\n  # generate_chk(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])\n  function(generate_chk)\n    set(options)\n    set(oneValueArgs INPUT OUTPUT)\n    set(multiValueArgs DEPENDS)\n    cmake_parse_arguments(_GC \"${options}\" \"${oneValueArgs}\" \"${multiValueArgs}\" ${ARGN})\n    if (NOT _GC_INPUT)\n      message(FATAL_ERROR \"Invalid arguments.  generate_out requires input.\")\n    endif()\n    if (NOT _GC_OUTPUT)\n      message(FATAL_ERROR \"Invalid arguments.  generate_out requires output.\")\n    endif()\n\n    add_custom_command(OUTPUT \"${_GC_OUTPUT}\"\n                       COMMAND \"${CMAKE_COMMAND}\"\n                               \"-DINPUT=${_GC_INPUT}\"\n                               \"-DOUTPUT=${_GC_OUTPUT}\"\n                               -P \"${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake\"\n                       DEPENDS \"${_GC_INPUT}\" ${_GC_DEPENDS}\n                       WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")\n  endfunction()\n\n  # Generate .out from .c with awk\n  # generate_out(INPUT inputfile OUTPUT outputfile [DEPENDS dep1 [dep2...]])\n  function(generate_out)\n    set(options)\n    set(oneValueArgs INPUT OUTPUT)\n    set(multiValueArgs DEPENDS)\n    cmake_parse_arguments(_GO \"${options}\" \"${oneValueArgs}\" \"${multiValueArgs}\" ${ARGN})\n    if (NOT _GO_INPUT)\n      message(FATAL_ERROR \"Invalid arguments.  generate_out requires input.\")\n    endif()\n    if (NOT _GO_OUTPUT)\n      message(FATAL_ERROR \"Invalid arguments.  generate_out requires output.\")\n    endif()\n\n    add_custom_command(OUTPUT \"${_GO_OUTPUT}\"\n                       COMMAND \"${CMAKE_COMMAND}\"\n                               \"-DINPUT=${_GO_INPUT}\"\n                               \"-DOUTPUT=${_GO_OUTPUT}\"\n                               -P \"${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake\"\n                       DEPENDS \"${_GO_INPUT}\" ${_GO_DEPENDS}\n                       WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")\n  endfunction()\n\n  # Generate specific source file with awk\n  # generate_source(OUTPUT outputfile [DEPENDS dep1 [dep2...]])\n  function(generate_source)\n    set(options)\n    set(oneValueArgs OUTPUT)\n    set(multiValueArgs DEPENDS)\n    cmake_parse_arguments(_GSO \"${options}\" \"${oneValueArgs}\" \"${multiValueArgs}\" ${ARGN})\n    if (NOT _GSO_OUTPUT)\n      message(FATAL_ERROR \"Invalid arguments.  generate_source requires output.\")\n    endif()\n\n    add_custom_command(OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/${_GSO_OUTPUT}\"\n                       COMMAND \"${CMAKE_COMMAND}\"\n                               \"-DOUTPUT=${_GSO_OUTPUT}\"\n                               -P \"${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake\"\n                       DEPENDS ${_GSO_DEPENDS}\n                       WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")\n  endfunction()\n\n  # Copy file\n  function(generate_copy source destination)\n    add_custom_command(OUTPUT \"${destination}\"\n                       COMMAND \"${CMAKE_COMMAND}\" -E remove \"${destination}\"\n                       COMMAND \"${CMAKE_COMMAND}\" -E copy \"${source}\"\n                                                          \"${destination}\"\n                       DEPENDS \"${source}\")\n  endfunction()\n\n  # Generate scripts/pnglibconf.h\n  generate_source(OUTPUT \"scripts/pnglibconf.c\"\n                  DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa\"\n                          \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk\"\n                          \"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h\")\n\n  # Generate pnglibconf.c\n  generate_source(OUTPUT \"pnglibconf.c\"\n                  DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.dfa\"\n                          \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/options.awk\"\n                          \"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h\")\n\n  if(PNG_PREFIX)\n    set(PNGLIBCONF_H_EXTRA_DEPENDS\n        \"${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out\"\n        \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/macro.lst\")\n    set(PNGPREFIX_H_EXTRA_DEPENDS\n        \"${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out\")\n  endif()\n\n  generate_out(INPUT \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out\")\n\n  # Generate pnglibconf.h\n  generate_source(OUTPUT \"pnglibconf.h\"\n                  DEPENDS \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out\"\n                          ${PNGLIBCONF_H_EXTRA_DEPENDS})\n\n  generate_out(INPUT \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/intprefix.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out\"\n               DEPENDS \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h\")\n\n  generate_out(INPUT \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/prefix.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out\"\n               DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/png.h\"\n                       \"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h\"\n                       \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out\")\n\n  # Generate pngprefix.h\n  generate_source(OUTPUT \"pngprefix.h\"\n                  DEPENDS ${PNGPREFIX_H_EXTRA_DEPENDS})\n\n  generate_out(INPUT \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/sym.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out\"\n               DEPENDS \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h\")\n\n  generate_out(INPUT \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out\"\n               DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/png.h\"\n                       \"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h\"\n                       \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/pnglibconf.h.prebuilt\")\n\n  generate_out(INPUT \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/vers.c\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out\"\n               DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/png.h\"\n                       \"${CMAKE_CURRENT_SOURCE_DIR}/pngconf.h\"\n                       \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h\")\n\n  generate_chk(INPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out\"\n               OUTPUT \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk\"\n               DEPENDS \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/checksym.awk\"\n                       \"${CMAKE_CURRENT_SOURCE_DIR}/scripts/symbols.def\")\n\n  add_custom_target(symbol-check DEPENDS\n                    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk\")\n\n  generate_copy(\"${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out\"\n                \"${CMAKE_CURRENT_BINARY_DIR}/libpng.sym\")\n  generate_copy(\"${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out\"\n                \"${CMAKE_CURRENT_BINARY_DIR}/libpng.vers\")\n\n  add_custom_target(genvers DEPENDS \"${CMAKE_CURRENT_BINARY_DIR}/libpng.vers\")\n  add_custom_target(gensym DEPENDS \"${CMAKE_CURRENT_BINARY_DIR}/libpng.sym\")\n\n  add_custom_target(\"genprebuilt\"\n                    COMMAND \"${CMAKE_COMMAND}\"\n                            \"-DOUTPUT=scripts/pnglibconf.h.prebuilt\"\n                            -P \"${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake\"\n                    WORKING_DIRECTORY \"${CMAKE_CURRENT_BINARY_DIR}\")\n\n  # A single target handles generation of all generated files.  If\n  # they are dependend upon separately by multiple targets, this\n  # confuses parallel make (it would require a separate top-level\n  # target for each file to track the dependencies properly).\n  add_custom_target(genfiles DEPENDS\n    \"${CMAKE_CURRENT_BINARY_DIR}/libpng.sym\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/libpng.vers\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.c\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.out\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/intprefix.out\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/pnglibconf.c\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/prefix.out\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/sym.out\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.chk\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/symbols.out\"\n    \"${CMAKE_CURRENT_BINARY_DIR}/scripts/vers.out\")\nendif(NOT AWK)\n\n# OUR SOURCES\nset(libpng_public_hdrs\n  png.h\n  pngconf.h\n  \"${CMAKE_CURRENT_BINARY_DIR}/pnglibconf.h\"\n)\nset(libpng_private_hdrs\n  pngpriv.h\n  pngdebug.h\n  pnginfo.h\n  pngstruct.h\n)\nif(AWK)\n  list(APPEND libpng_private_hdrs \"${CMAKE_CURRENT_BINARY_DIR}/pngprefix.h\")\nendif()\nset(libpng_sources\n  ${libpng_public_hdrs}\n  ${libpng_private_hdrs}\n  png.c\n  pngerror.c\n  pngget.c\n  pngmem.c\n  pngpread.c\n  pngread.c\n  pngrio.c\n  pngrtran.c\n  pngrutil.c\n  pngset.c\n  pngtrans.c\n  pngwio.c\n  pngwrite.c\n  pngwtran.c\n  pngwutil.c\n)\nset(pngtest_sources\n  pngtest.c\n)\nset(pngvalid_sources\n  contrib/libtests/pngvalid.c\n)\nset(pngstest_sources\n  contrib/libtests/pngstest.c\n)\nset(pngunknown_sources\n  contrib/libtests/pngunknown.c\n)\nset(pngimage_sources\n  contrib/libtests/pngimage.c\n)\nset(pngfix_sources\n  contrib/tools/pngfix.c\n)\nset(png_fix_itxt_sources\n  contrib/tools/png-fix-itxt.c\n)\n\nif(MSVC)\n  add_definitions(-D_CRT_SECURE_NO_DEPRECATE)\nendif(MSVC)\n\nif(PNG_DEBUG)\n  add_definitions(-DPNG_DEBUG)\nendif()\n\n# NOW BUILD OUR TARGET\ninclude_directories(${CMAKE_CURRENT_SOURCE_DIR} ${ZLIB_INCLUDE_DIR})\n\nunset(PNG_LIB_TARGETS)\n\nif(PNG_SHARED)\n  add_library(png SHARED ${libpng_sources})\n  set(PNG_LIB_TARGETS png)\n  set_target_properties(png PROPERTIES OUTPUT_NAME ${PNG_LIB_NAME})\n  add_dependencies(png genfiles)\n  if(MSVC)\n    # msvc does not append 'lib' - do it here to have consistent name\n    set_target_properties(png PROPERTIES PREFIX \"lib\")\n    set_target_properties(png PROPERTIES IMPORT_PREFIX \"lib\")\n  endif()\n  target_link_libraries(png ${ZLIB_LIBRARY} ${M_LIBRARY})\n\n  if(UNIX AND AWK)\n    if(HAVE_LD_VERSION_SCRIPT)\n      set_target_properties(png PROPERTIES LINK_FLAGS\n        \"-Wl,--version-script='${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'\")\n    elseif(HAVE_SOLARIS_LD_VERSION_SCRIPT)\n      set_target_properties(png PROPERTIES LINK_FLAGS\n        \"-Wl,-M -Wl,'${CMAKE_CURRENT_BINARY_DIR}/libpng.vers'\")\n    endif()\n  endif()\nendif()\n\nif(PNG_STATIC)\n  # does not work without changing name\n  set(PNG_LIB_NAME_STATIC png_static)\n  add_library(png_static STATIC ${libpng_sources})\n  add_dependencies(png_static genfiles)\n  # MSVC doesn't use a different file extension for shared vs. static\n  # libs.  We are able to change OUTPUT_NAME to remove the _static\n  # for all other platforms.\n  if(NOT MSVC)\n    set_target_properties(png_static PROPERTIES\n      OUTPUT_NAME \"${PNG_LIB_NAME}\"\n      CLEAN_DIRECT_OUTPUT 1)\n  else()\n    set_target_properties(png_static PROPERTIES\n      OUTPUT_NAME \"${PNG_LIB_NAME}_static\"\n      CLEAN_DIRECT_OUTPUT 1)\n  endif()\n  list(APPEND PNG_LIB_TARGETS png_static)\n  if(MSVC)\n    # msvc does not append 'lib' - do it here to have consistent name\n    set_target_properties(png_static PROPERTIES PREFIX \"lib\")\n  endif()\n  target_link_libraries(png_static ${ZLIB_LIBRARY} ${M_LIBRARY})\nendif()\n\nif(PNG_FRAMEWORK)\n  set(PNG_LIB_NAME_FRAMEWORK png_framework)\n  add_library(png_framework SHARED ${libpng_sources})\n  add_dependencies(png_framework genfiles)\n  list(APPEND PNG_LIB_TARGETS png_framework)\n  set_target_properties(png_framework PROPERTIES\n    FRAMEWORK TRUE\n    FRAMEWORK_VERSION ${PNGLIB_VERSION}\n    MACOSX_FRAMEWORK_SHORT_VERSION_STRING ${PNGLIB_MAJOR}.${PNGLIB_MINOR}\n    MACOSX_FRAMEWORK_BUNDLE_VERSION ${PNGLIB_VERSION}\n    MACOSX_FRAMEWORK_IDENTIFIER org.libpng.libpng\n    XCODE_ATTRIBUTE_INSTALL_PATH \"@rpath\"\n    PUBLIC_HEADER \"${libpng_public_hdrs}\"\n    OUTPUT_NAME png)\n  target_link_libraries(png_framework ${ZLIB_LIBRARY} ${M_LIBRARY})\nendif()\n\nif(NOT PNG_LIB_TARGETS)\n  message(SEND_ERROR\n    \"No library variant selected to build. \"\n    \"Please enable at least one of the following options: \"\n    \" PNG_STATIC, PNG_SHARED, PNG_FRAMEWORK\")\nendif()\n\nif(PNG_SHARED AND WIN32)\n  set_target_properties(png PROPERTIES DEFINE_SYMBOL PNG_BUILD_DLL)\nendif()\n\nfunction(png_add_test)\n  set(options)\n  set(oneValueArgs NAME COMMAND)\n  set(multiValueArgs OPTIONS FILES)\n  cmake_parse_arguments(_PAT \"${options}\" \"${oneValueArgs}\" \"${multiValueArgs}\" ${ARGN})\n\n  if (NOT _PAT_NAME)\n    message(FATAL_ERROR \"Invalid arguments.  png_add_test requires name.\")\n  endif()\n  if (NOT _PAT_COMMAND)\n    message(FATAL_ERROR \"Invalid arguments.  png_add_test requires command.\")\n  endif()\n\n  set(TEST_OPTIONS \"${_PAT_OPTIONS}\")\n  set(TEST_FILES \"${_PAT_FILES}\")\n\n  configure_file(\"${CMAKE_CURRENT_SOURCE_DIR}/scripts/test.cmake.in\"\n                 \"${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake\" @ONLY)\n  if(CMAKE_MAJOR_VERSION GREATER 2) # have generator expressions\n    add_test(NAME \"${_PAT_NAME}\"\n             COMMAND \"${CMAKE_COMMAND}\"\n             \"-DLIBPNG=$<TARGET_FILE:png>\"\n             \"-DTEST_COMMAND=$<TARGET_FILE:${_PAT_COMMAND}>\"\n             -P \"${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake\")\n  else() # old 2.x add_test; limited and won't work well on Windows\n    # Note LIBPNG is a dummy value as there are no generator expressions\n    add_test(\"${_PAT_NAME}\" \"${CMAKE_COMMAND}\"\n             \"-DLIBPNG=${CMAKE_CURRENT_BINARY_DIR}/libpng.so\"\n             \"-DTEST_COMMAND=./${_PAT_COMMAND}\"\n             -P \"${CMAKE_CURRENT_BINARY_DIR}/tests/${_PAT_NAME}.cmake\")\n  endif()\nendfunction()\n\nif(PNG_TESTS AND PNG_SHARED)\n  # Find test PNG files by globbing, but sort lists to ensure\n  # consistency between different filesystems.\n  file(GLOB PNGSUITE_PNGS \"${CMAKE_CURRENT_SOURCE_DIR}/contrib/pngsuite/*.png\")\n  list(SORT PNGSUITE_PNGS)\n  file(GLOB TEST_PNGS \"${CMAKE_CURRENT_SOURCE_DIR}/contrib/testpngs/*.png\")\n  list(SORT TEST_PNGS)\n\n  set(PNGTEST_PNG \"${CMAKE_CURRENT_SOURCE_DIR}/pngtest.png\")\n\n  add_executable(pngtest ${pngtest_sources})\n  target_link_libraries(pngtest png)\n\n  png_add_test(NAME pngtest COMMAND pngtest FILES \"${PNGTEST_PNG}\")\n\n  add_executable(pngvalid ${pngvalid_sources})\n  target_link_libraries(pngvalid png)\n\n  png_add_test(NAME pngvalid-gamma-16-to-8\n               COMMAND pngvalid OPTIONS --gamma-16-to-8)\n  png_add_test(NAME pngvalid-gamma-alpha-mode\n               COMMAND pngvalid OPTIONS --gamma-alpha-mode)\n  png_add_test(NAME pngvalid-gamma-background\n               COMMAND pngvalid OPTIONS --gamma-background)\n  png_add_test(NAME pngvalid-gamma-expand16-alpha-mode\n               COMMAND pngvalid OPTIONS --gamma-alpha-mode --expand16)\n  png_add_test(NAME pngvalid-gamma-expand16-background\n               COMMAND pngvalid OPTIONS --gamma-background --expand16)\n  png_add_test(NAME pngvalid-gamma-expand16-transform\n               COMMAND pngvalid OPTIONS --gamma-transform --expand16)\n  png_add_test(NAME pngvalid-gamma-sbit\n               COMMAND pngvalid OPTIONS --gamma-sbit)\n  png_add_test(NAME pngvalid-gamma-threshold\n               COMMAND pngvalid OPTIONS --gamma-threshold)\n  png_add_test(NAME pngvalid-gamma-transform\n               COMMAND pngvalid OPTIONS --gamma-transform)\n  png_add_test(NAME pngvalid-progressive-interlace-standard\n               COMMAND pngvalid OPTIONS --standard --progressive-read --interlace)\n  png_add_test(NAME pngvalid-progressive-size\n               COMMAND pngvalid OPTIONS --size --progressive-read)\n  png_add_test(NAME pngvalid-progressive-standard\n               COMMAND pngvalid OPTIONS --standard --progressive-read)\n  png_add_test(NAME pngvalid-standard\n               COMMAND pngvalid OPTIONS --standard)\n  png_add_test(NAME pngvalid-transform\n               COMMAND pngvalid OPTIONS --transform)\n\n  add_executable(pngstest ${pngstest_sources})\n  target_link_libraries(pngstest png)\n\n  foreach(gamma_type 1.8 linear none sRGB)\n    foreach(alpha_type none alpha)\n      set(PNGSTEST_FILES)\n      foreach(test_png ${TEST_PNGS})\n        string(REGEX MATCH \".*-linear[-.].*\" TEST_PNG_LINEAR \"${test_png}\")\n        string(REGEX MATCH \".*-sRGB[-.].*\" TEST_PNG_SRGB \"${test_png}\")\n        string(REGEX MATCH \".*-1.8[-.].*\" TEST_PNG_G18 \"${test_png}\")\n        string(REGEX MATCH \".*-alpha-.*\" TEST_PNG_ALPHA \"${test_png}\")\n\n        set(TEST_PNG_VALID TRUE)\n\n        if(TEST_PNG_ALPHA)\n          if (NOT \"${alpha_type}\" STREQUAL \"alpha\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        else()\n          if (\"${alpha_type}\" STREQUAL \"alpha\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        endif()\n\n        if(TEST_PNG_LINEAR)\n          if(NOT \"${gamma_type}\" STREQUAL \"linear\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        elseif(TEST_PNG_SRGB)\n          if(NOT \"${gamma_type}\" STREQUAL \"sRGB\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        elseif(TEST_PNG_G18)\n          if(NOT \"${gamma_type}\" STREQUAL \"1.8\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        else()\n          if(NOT \"${gamma_type}\" STREQUAL \"none\")\n            set(TEST_PNG_VALID FALSE)\n          endif()\n        endif()\n\n        if(TEST_PNG_VALID)\n          list(APPEND PNGSTEST_FILES \"${test_png}\")\n        endif()\n      endforeach()\n      # Should already be sorted, but sort anyway to be certain.\n      list(SORT PNGSTEST_FILES)\n      png_add_test(NAME pngstest-${gamma_type}-${alpha_type}\n                   COMMAND pngstest\n                   OPTIONS --tmpfile \"${gamma_type}-${alpha_type}-\" --log\n                   FILES ${PNGSTEST_FILES})\n    endforeach()\n  endforeach()\n\n  add_executable(pngunknown ${pngunknown_sources})\n  target_link_libraries(pngunknown png)\n\n  png_add_test(NAME pngunknown-discard COMMAND pngunknown OPTIONS --strict default=discard FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-IDAT COMMAND pngunknown OPTIONS --strict default=discard IDAT=save FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-if-safe COMMAND pngunknown OPTIONS --strict default=if-safe FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-sAPI COMMAND pngunknown OPTIONS --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-save COMMAND pngunknown OPTIONS --strict default=save FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-sTER COMMAND pngunknown OPTIONS --strict sTER=if-safe FILES \"${PNGTEST_PNG}\")\n  png_add_test(NAME pngunknown-vpAg COMMAND pngunknown OPTIONS --strict vpAg=if-safe FILES \"${PNGTEST_PNG}\")\n\n  add_executable(pngimage ${pngimage_sources})\n  target_link_libraries(pngimage png)\n\n  png_add_test(NAME pngimage-quick COMMAND pngimage OPTIONS --list-combos --log FILES ${PNGSUITE_PNGS})\n  png_add_test(NAME pngimage-full COMMAND pngimage OPTIONS --exhaustive --list-combos --log FILES ${PNGSUITE_PNGS})\nendif()\n\nif(PNG_SHARED)\n  add_executable(pngfix ${pngfix_sources})\n  target_link_libraries(pngfix png)\n  set(PNG_BIN_TARGETS pngfix)\n\n  add_executable(png-fix-itxt ${png_fix_itxt_sources})\n  target_link_libraries(png-fix-itxt ${ZLIB_LIBRARY} ${M_LIBRARY})\n  list(APPEND PNG_BIN_TARGETS png-fix-itxt)\nendif()\n\n# Ensure the CMAKE_LIBRARY_OUTPUT_DIRECTORY is set\nIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)\n  SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY \"lib\")\nENDIF(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)\n\n# Set a variable with CMake code which:\n# Creates a symlink from src to dest (if possible) or alternatively\n# copies if different.\nmacro(CREATE_SYMLINK SRC_FILE DEST_FILE)\n  FILE(REMOVE ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})\n  if(WIN32 AND NOT CYGWIN AND NOT MSYS)\n    ADD_CUSTOM_COMMAND(\n        OUTPUT ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}   ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}\n        COMMAND ${CMAKE_COMMAND} -E copy_if_different  \"${SRC_FILE}\" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE}\n        COMMAND ${CMAKE_COMMAND} -E copy_if_different  \"${SRC_FILE}\" ${CMAKE_CURRENT_BINARY_DIR}/${DEST_FILE}\n        DEPENDS ${PNG_LIB_TARGETS}\n        )\n    ADD_CUSTOM_TARGET(${DEST_FILE}_COPY ALL DEPENDS ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE})\n  else(WIN32 AND NOT CYGWIN AND NOT MSYS)\n    get_filename_component(LINK_TARGET \"${SRC_FILE}\" NAME)\n    execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_LIBRARY_OUTPUT_DIRECTORY})\n    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \"${LINK_TARGET}\" ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})\n    execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink \"${LINK_TARGET}\" ${DEST_FILE} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})\n  endif(WIN32 AND NOT CYGWIN AND NOT MSYS)\nendmacro()\n\n# Create source generation scripts.\nconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genchk.cmake.in\n               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genchk.cmake @ONLY)\nconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/genout.cmake.in\n               ${CMAKE_CURRENT_BINARY_DIR}/scripts/genout.cmake @ONLY)\nconfigure_file(${CMAKE_CURRENT_SOURCE_DIR}/scripts/gensrc.cmake.in\n               ${CMAKE_CURRENT_BINARY_DIR}/scripts/gensrc.cmake @ONLY)\n\n\n# libpng is a library so default to 'lib'\nif(NOT DEFINED CMAKE_INSTALL_LIBDIR)\n  set(CMAKE_INSTALL_LIBDIR lib)\nendif(NOT DEFINED CMAKE_INSTALL_LIBDIR)\n\n# CREATE PKGCONFIG FILES\n# we use the same files like ./configure, so we have to set its vars\n# Only do this on Windows for Cygwin - the files don't make much sense outside\n# a UNIX look alike\nif(NOT WIN32 OR CYGWIN OR MINGW)\n  set(prefix      ${CMAKE_INSTALL_PREFIX})\n  set(exec_prefix ${CMAKE_INSTALL_PREFIX})\n  set(libdir      ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})\n  set(includedir  ${CMAKE_INSTALL_PREFIX}/include)\n  set(LIBS        \"-lz -lm\")\n  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in\n    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)\n  CREATE_SYMLINK(${PNGLIB_NAME}.pc libpng.pc)\n\n  configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in\n    ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config @ONLY)\n  CREATE_SYMLINK(${PNGLIB_NAME}-config libpng-config)\nendif(NOT WIN32 OR CYGWIN OR MINGW)\n\n# SET UP LINKS\nif(PNG_SHARED)\n  set_target_properties(png PROPERTIES\n#   VERSION 16.${PNGLIB_RELEASE}.1.6.25\n    VERSION 16.${PNGLIB_RELEASE}.0\n    SOVERSION 16\n    CLEAN_DIRECT_OUTPUT 1)\nendif()\n\n# If CMake > 2.4.x, we set a variable used below to export\n# targets to an export file.\n# TODO: Use VERSION_GREATER after our cmake_minimum_required >= 2.6.2\nif(CMAKE_MAJOR_VERSION GREATER 1 AND CMAKE_MINOR_VERSION GREATER 4)\n  set(PNG_EXPORT_RULE EXPORT libpng)\nelseif(CMAKE_MAJOR_VERSION GREATER 2) # future proof\n  set(PNG_EXPORT_RULE EXPORT libpng)\nendif()\n\n# INSTALL\nif(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )\n  install(TARGETS ${PNG_LIB_TARGETS}\n      ${PNG_EXPORT_RULE}\n      RUNTIME DESTINATION bin\n      LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}\n      ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}\n      FRAMEWORK DESTINATION ${CMAKE_INSTALL_LIBDIR})\n\n  if(PNG_SHARED)\n    # Create a symlink for libpng.dll.a => libpng16.dll.a on Cygwin\n    if(CYGWIN OR MINGW)\n       get_target_property(BUILD_TARGET_LOCATION png LOCATION_${CMAKE_BUILD_TYPE})\n       CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_IMPORT_LIBRARY_SUFFIX})\n       install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_IMPORT_LIBRARY_SUFFIX}\n         DESTINATION ${CMAKE_INSTALL_LIBDIR})\n    endif(CYGWIN OR MINGW)\n\n    if(NOT WIN32)\n      get_target_property(BUILD_TARGET_LOCATION png LOCATION_${CMAKE_BUILD_TYPE})\n      CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_SHARED_LIBRARY_SUFFIX})\n      install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_SHARED_LIBRARY_SUFFIX}\n         DESTINATION ${CMAKE_INSTALL_LIBDIR})\n    endif(NOT WIN32)\n  endif(PNG_SHARED)\n\n  if(PNG_STATIC)\n    if(NOT WIN32 OR CYGWIN OR MINGW)\n      get_target_property(BUILD_TARGET_LOCATION png_static LOCATION_${CMAKE_BUILD_TYPE})\n      CREATE_SYMLINK(${BUILD_TARGET_LOCATION} libpng${CMAKE_STATIC_LIBRARY_SUFFIX})\n      install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng${CMAKE_STATIC_LIBRARY_SUFFIX}\n         DESTINATION ${CMAKE_INSTALL_LIBDIR})\n    endif(NOT WIN32 OR CYGWIN OR MINGW)\n endif()\nendif()\n\nif(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )\n  install(FILES ${libpng_public_hdrs}   DESTINATION include)\n  install(FILES ${libpng_public_hdrs}   DESTINATION include/${PNGLIB_NAME})\nendif()\nif(NOT SKIP_INSTALL_EXECUTABLES AND NOT SKIP_INSTALL_ALL )\n  if(NOT WIN32 OR CYGWIN OR MINGW)\n    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config DESTINATION bin)\n    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config\n            DESTINATION bin)\n  endif(NOT WIN32 OR CYGWIN OR MINGW)\nendif()\n\nif(NOT SKIP_INSTALL_PROGRAMS AND NOT SKIP_INSTALL_ALL )\n  install(TARGETS ${PNG_BIN_TARGETS}\n      RUNTIME DESTINATION bin)\nendif()\n\nif(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )\n  # Install man pages\n  if(NOT PNG_MAN_DIR)\n    set(PNG_MAN_DIR \"share/man\")\n  endif()\n  install(FILES libpng.3 libpngpf.3      DESTINATION ${PNG_MAN_DIR}/man3)\n  install(FILES png.5                    DESTINATION ${PNG_MAN_DIR}/man5)\n  # Install pkg-config files\n  if(NOT WIN32 OR CYGWIN OR MINGW)\n    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc\n            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)\n    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config\n            DESTINATION bin)\n    install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc\n            DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)\n    install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config\n            DESTINATION bin)\n  endif(NOT WIN32 OR CYGWIN OR MINGW)\nendif()\n\n# On versions of CMake that support it, create an export file CMake\n# users can include() to import our targets\nif(PNG_EXPORT_RULE AND NOT SKIP_INSTALL_EXPORT AND NOT SKIP_INSTALL_ALL )\n  install(EXPORT libpng DESTINATION lib/libpng FILE lib${PNG_LIB_NAME}.cmake)\nendif()\n\n# what's with libpng-manual.txt and all the extra files?\n\n# UNINSTALL\n# do we need this?\n\n# DIST\n# do we need this?\n\n# to create msvc import lib for mingw compiled shared lib\n# pexports libpng.dll > libpng.def\n# lib /def:libpng.def /machine:x86\n\n"
  },
  {
    "path": "tess-two/jni/libpng/CleanSpec.mk",
    "content": "# Copyright (C) 2007 The Android Open Source Project\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#      http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\n# If you don't need to do a full clean build but would like to touch\n# a file or delete some intermediate files, add a clean step to the end\n# of the list.  These steps will only be run once, if they haven't been\n# run before.\n#\n# E.g.:\n#     $(call add-clean-step, touch -c external/sqlite/sqlite3.h)\n#     $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)\n#\n# Always use \"touch -c\" and \"rm -f\" or \"rm -rf\" to gracefully deal with\n# files that are missing or have been moved.\n#\n# Use $(PRODUCT_OUT) to get to the \"out/target/product/blah/\" directory.\n# Use $(OUT_DIR) to refer to the \"out\" directory.\n#\n# If you need to re-do something that's already mentioned, just copy\n# the command and add it to the bottom of the list.  E.g., if a change\n# that you made last week required touching a file and a change you\n# made today requires touching the same file, just copy the old\n# touch step and add it to the end of the list.\n#\n# ************************************************\n# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST\n# ************************************************\n\n# For example:\n#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)\n#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)\n#$(call add-clean-step, find $(OUT_DIR) -type f -name \"IGTalkSession*\" -print0 | xargs -0 rm -f)\n#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)\n\n# ************************************************\n# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST\n# ************************************************\n"
  },
  {
    "path": "tess-two/jni/libpng/INSTALL",
    "content": "\n    Installing libpng\n\nContents\n\n       I. Simple installation\n      II. Rebuilding the configure scripts\n     III. Using scripts/makefile*\n      IV. Using cmake\n       V. Directory structure\n      VI. Building with project files\n     VII. Building with makefiles\n    VIII. Configuring libpng for 16-bit platforms\n      IX. Configuring for DOS\n       X. Configuring for Medium Model\n      XI. Prepending a prefix to exported symbols\n     XII. Configuring for compiler xxx:\n    XIII. Removing unwanted object code\n     XIV. Changes to the build and configuration of libpng in libpng-1.5.x\n      XV. Setjmp/longjmp issues\n     XVI. Common linking failures\n    XVII. Other sources of information about libpng\n\nI. Simple installation\n\nOn Unix/Linux and similar systems, you can simply type\n\n    ./configure [--prefix=/path]\n    make check\n    make install\n\nand ignore the rest of this document.  \"/path\" is the path to the directory\nwhere you want to install the libpng \"lib\", \"include\", and \"bin\"\nsubdirectories.\n\nIf you downloaded a GIT clone, you will need to run ./autogen.sh before\nrunning ./configure, to create \"configure\" and \"Makefile.in\" which are\nnot included in the GIT repository.\n\nNote that \"configure\" is only included in the \"*.tar\" distributions and not\nin the \"*.zip\" or \"*.7z\" distributions. If you downloaded one of those\ndistributions, see \"Building with project files\" or \"Building with makefiles\",\nbelow.\n\nII. Rebuilding the configure scripts\n\nIf configure does not work on your system, or if you have a need to\nchange configure.ac or Makefile.am, and you have a reasonably\nup-to-date set of tools, running ./autogen.sh in a git clone before\nrunning ./configure may fix the problem.  To be really sure that you\naren't using any of the included pre-built scripts, especially if you\nare building from a tar distribution instead of a git distribution,\ndo this:\n\n    ./configure --enable-maintainer-mode\n    make maintainer-clean\n    ./autogen.sh --maintainer --clean\n    ./autogen.sh --maintainer\n    ./configure [--prefix=/path] [other options]\n    make\n    make install\n    make check\n\nIII. Using scripts/makefile*\n\nInstead, you can use one of the custom-built makefiles in the\n\"scripts\" directory\n\n    cp scripts/pnglibconf.h.prebuilt pnglibconf.h\n    cp scripts/makefile.system makefile\n    make test\n    make install\n\nThe files that are presently available in the scripts directory\nare listed and described in scripts/README.txt.\n\nOr you can use one of the \"projects\" in the \"projects\" directory.\n\nBefore installing libpng, you must first install zlib, if it\nis not already on your system.  zlib can usually be found\nwherever you got libpng; otherwise go to http://zlib.net.  You can place\nzlib in the same directory as libpng or in another directory.\n\nIf your system already has a preinstalled zlib you will still need\nto have access to the zlib.h and zconf.h include files that\ncorrespond to the version of zlib that's installed.\n\nIf you wish to test with a particular zlib that is not first in the\nstandard library search path, put ZLIBLIB, ZLIBINC, CPPFLAGS, LDFLAGS,\nand LD_LIBRARY_PATH in your environment before running \"make test\"\nor \"make distcheck\":\n\n    ZLIBLIB=/path/to/lib export ZLIBLIB\n    ZLIBINC=/path/to/include export ZLIBINC\n    CPPFLAGS=\"-I$ZLIBINC\" export CPPFLAGS\n    LDFLAGS=\"-L$ZLIBLIB\" export LDFLAGS\n    LD_LIBRARY_PATH=\"$ZLIBLIB:$LD_LIBRARY_PATH\" export LD_LIBRARY_PATH\n\nIf you are using one of the makefile scripts, put ZLIBLIB and ZLIBINC\nin your environment and type\n\n    make ZLIBLIB=$ZLIBLIB ZLIBINC=$ZLIBINC test\n\nIV. Using cmake\n\nIf you want to use \"cmake\" (see www.cmake.org), type\n\n    cmake . -DCMAKE_INSTALL_PREFIX=/path\n    make\n    make install\n\nAs when using the simple configure method described above, \"/path\" points to\nthe installation directory where you want to put the libpng \"lib\", \"include\",\nand \"bin\" subdirectories.\n\nV. Directory structure\n\nYou can rename the directories that you downloaded (they\nmight be called \"libpng-x.y.z\" or \"libpngNN\" and \"zlib-1.2.8\"\nor \"zlib128\") so that you have directories called \"zlib\" and \"libpng\".\n\nYour directory structure should look like this:\n\n    .. (the parent directory)\n      libpng (this directory)\n          INSTALL (this file)\n          README\n          *.h, *.c  => libpng source files\n          CMakeLists.txt    =>  \"cmake\" script\n          configuration files:\n             configure.ac, configure, Makefile.am, Makefile.in,\n             autogen.sh, config.guess, ltmain.sh, missing, libpng.pc.in,\n             libpng-config.in, aclocal.m4, config.h.in, config.sub,\n             depcomp, install-sh, mkinstalldirs, test-pngtest.sh\n          contrib\n             arm-neon, conftest, examples, gregbook, libtests, pngminim,\n             pngminus, pngsuite, tools, visupng\n          projects\n             cbuilder5, owatcom, visualc71, vstudio, xcode\n          scripts\n             makefile.*\n             *.def (module definition files)\n             etc.\n          pngtest.png\n          etc.\n      zlib\n          README, *.h, *.c contrib, etc.\n\nIf the line endings in the files look funny, you may wish to get the other\ndistribution of libpng.  It is available in both tar.gz (UNIX style line\nendings) and zip (DOS style line endings) formats.\n\nVI. Building with project files\n\nIf you are building libpng with MSVC, you can enter the\nlibpng projects\\visualc71 or vstudio directory and follow the instructions\nin README.txt.\n\nOtherwise enter the zlib directory and follow the instructions in zlib/README,\nthen come back here and run \"configure\" or choose the appropriate\nmakefile.sys in the scripts directory.\n\nVII. Building with makefiles\n\nCopy the file (or files) that you need from the\nscripts directory into this directory, for example\n\nMSDOS example:\n\n    copy scripts\\makefile.msc makefile\n    copy scripts\\pnglibconf.h.prebuilt pnglibconf.h\n\nUNIX example:\n\n    cp scripts/makefile.std makefile\n    cp scripts/pnglibconf.h.prebuilt pnglibconf.h\n\nRead the makefile to see if you need to change any source or\ntarget directories to match your preferences.\n\nThen read pnglibconf.dfa to see if you want to make any configuration\nchanges.\n\nThen just run \"make\" which will create the libpng library in\nthis directory and \"make test\" which will run a quick test that reads\nthe \"pngtest.png\" file and writes a \"pngout.png\" file that should be\nidentical to it.  Look for \"9782 zero samples\" in the output of the\ntest.  For more confidence, you can run another test by typing\n\"pngtest pngnow.png\" and looking for \"289 zero samples\" in the output.\nAlso, you can run \"pngtest -m contrib/pngsuite/*.png\" and compare\nyour output with the result shown in contrib/pngsuite/README.\n\nMost of the makefiles will allow you to run \"make install\" to\nput the library in its final resting place (if you want to\ndo that, run \"make install\" in the zlib directory first if necessary).\nSome also allow you to run \"make test-installed\" after you have\nrun \"make install\".\n\nVIII. Configuring libpng for 16-bit platforms\n\nYou will want to look into zconf.h to tell zlib (and thus libpng) that\nit cannot allocate more than 64K at a time.  Even if you can, the memory\nwon't be accessible.  So limit zlib and libpng to 64K by defining MAXSEG_64K.\n\nIX. Configuring for DOS\n\nFor DOS users who only have access to the lower 640K, you will\nhave to limit zlib's memory usage via a png_set_compression_mem_level()\ncall.  See zlib.h or zconf.h in the zlib library for more information.\n\nX. Configuring for Medium Model\n\nLibpng's support for medium model has been tested on most of the popular\ncompilers.  Make sure MAXSEG_64K gets defined, USE_FAR_KEYWORD gets\ndefined, and FAR gets defined to far in pngconf.h, and you should be\nall set.  Everything in the library (except for zlib's structure) is\nexpecting far data.  You must use the typedefs with the p or pp on\nthe end for pointers (or at least look at them and be careful).  Make\nnote that the rows of data are defined as png_bytepp, which is\nan \"unsigned char far * far *\".\n\nXI. Prepending a prefix to exported symbols\n\nStarting with libpng-1.6.0, you can configure libpng (when using the\n\"configure\" script) to prefix all exported symbols by means of the\nconfiguration option \"--with-libpng-prefix=FOO_\", where FOO_ can be any\nstring beginning with a letter and containing only uppercase\nand lowercase letters, digits, and the underscore (i.e., a C language\nidentifier).  This creates a set of macros in pnglibconf.h, so this is\ntransparent to applications; their function calls get transformed by\nthe macros to use the modified names.\n\nXII. Configuring for compiler xxx:\n\nAll includes for libpng are in pngconf.h.  If you need to add, change\nor delete an include, this is the place to do it.\nThe includes that are not needed outside libpng are placed in pngpriv.h,\nwhich is only used by the routines inside libpng itself.\nThe files in libpng proper only include pngpriv.h and png.h, which\nin turn includes pngconf.h and, as of libpng-1.5.0, pnglibconf.h.\nAs of libpng-1.5.0, pngpriv.h also includes three other private header\nfiles, pngstruct.h, pnginfo.h, and pngdebug.h, which contain material\nthat previously appeared in the public headers.\n\nXIII. Removing unwanted object code\n\nThere are a bunch of #define's in pngconf.h that control what parts of\nlibpng are compiled.  All the defines end in _SUPPORTED.  If you are\nnever going to use a capability, you can change the #define to #undef\nbefore recompiling libpng and save yourself code and data space, or\nyou can turn off individual capabilities with defines that begin with\n\"PNG_NO_\".\n\nIn libpng-1.5.0 and later, the #define's are in pnglibconf.h instead.\n\nYou can also turn all of the transforms and ancillary chunk capabilities\noff en masse with compiler directives that define\nPNG_NO_READ[or WRITE]_TRANSFORMS, or PNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS,\nor all four, along with directives to turn on any of the capabilities that\nyou do want.  The PNG_NO_READ[or WRITE]_TRANSFORMS directives disable the\nextra transformations but still leave the library fully capable of reading\nand writing PNG files with all known public chunks. Use of the\nPNG_NO_READ[or WRITE]_ANCILLARY_CHUNKS directive produces a library\nthat is incapable of reading or writing ancillary chunks.  If you are\nnot using the progressive reading capability, you can turn that off\nwith PNG_NO_PROGRESSIVE_READ (don't confuse this with the INTERLACING\ncapability, which you'll still have).\n\nAll the reading and writing specific code are in separate files, so the\nlinker should only grab the files it needs.  However, if you want to\nmake sure, or if you are building a stand alone library, all the\nreading files start with \"pngr\" and all the writing files start with \"pngw\".\nThe files that don't match either (like png.c, pngtrans.c, etc.)\nare used for both reading and writing, and always need to be included.\nThe progressive reader is in pngpread.c\n\nIf you are creating or distributing a dynamically linked library (a .so\nor DLL file), you should not remove or disable any parts of the library,\nas this will cause applications linked with different versions of the\nlibrary to fail if they call functions not available in your library.\nThe size of the library itself should not be an issue, because only\nthose sections that are actually used will be loaded into memory.\n\nXIV. Changes to the build and configuration of libpng in libpng-1.5.x\n\nDetails of internal changes to the library code can be found in the CHANGES\nfile and in the GIT repository logs.  These will be of no concern to the vast\nmajority of library users or builders; however, the few who configure libpng\nto a non-default feature set may need to change how this is done.\n\nThere should be no need for library builders to alter build scripts if\nthese use the distributed build support - configure or the makefiles -\nhowever, users of the makefiles may care to update their build scripts\nto build pnglibconf.h where the corresponding makefile does not do so.\n\nBuilding libpng with a non-default configuration has changed completely.\nThe old method using pngusr.h should still work correctly even though the\nway pngusr.h is used in the build has been changed; however, library\nbuilders will probably want to examine the changes to take advantage of\nnew capabilities and to simplify their build system.\n\nA. Specific changes to library configuration capabilities\n\nThe exact mechanism used to control attributes of API functions has\nchanged.  A single set of operating system independent macro definitions\nis used and operating system specific directives are defined in\npnglibconf.h\n\nAs part of this the mechanism used to choose procedure call standards on\nthose systems that allow a choice has been changed.  At present this only\naffects certain Microsoft (DOS, Windows) and IBM (OS/2) operating systems\nrunning on Intel processors.  As before, PNGAPI is defined where required\nto control the exported API functions; however, two new macros, PNGCBAPI\nand PNGCAPI, are used instead for callback functions (PNGCBAPI) and\n(PNGCAPI) for functions that must match a C library prototype (currently\nonly png_longjmp_ptr, which must match the C longjmp function.)  The new\napproach is documented in pngconf.h\n\nDespite these changes, libpng 1.5.0 only supports the native C function\ncalling standard on those platforms tested so far (\"__cdecl\" on Microsoft\nWindows).  This is because the support requirements for alternative\ncalling conventions seem to no longer exist.  Developers who find it\nnecessary to set PNG_API_RULE to 1 should advise the mailing list\n(png-mng-implement) of this and library builders who use Openwatcom and\ntherefore set PNG_API_RULE to 2 should also contact the mailing list.\n\nB. Changes to the configuration mechanism\n\nPrior to libpng-1.5.0 library builders who needed to configure libpng\nhad either to modify the exported pngconf.h header file to add system\nspecific configuration or had to write feature selection macros into\npngusr.h and cause this to be included into pngconf.h by defining\nPNG_USER_CONFIG. The latter mechanism had the disadvantage that an\napplication built without PNG_USER_CONFIG defined would see the\nunmodified, default, libpng API and thus would probably fail to link.\n\nThese mechanisms still work in the configure build and in any makefile\nbuild that builds pnglibconf.h, although the feature selection macros\nhave changed somewhat as described above.  In 1.5.0, however, pngusr.h is\nprocessed only once, at the time the exported header file pnglibconf.h is\nbuilt.  pngconf.h no longer includes pngusr.h; therefore, pngusr.h is ignored\nafter the build of pnglibconf.h and it is never included in an application\nbuild.\n\nThe formerly used alternative of adding a list of feature macros to the\nCPPFLAGS setting in the build also still works; however, the macros will be\ncopied to pnglibconf.h and this may produce macro redefinition warnings\nwhen the individual C files are compiled.\n\nAll configuration now only works if pnglibconf.h is built from\nscripts/pnglibconf.dfa.  This requires the program awk.  Brian Kernighan\n(the original author of awk) maintains C source code of that awk and this\nand all known later implementations (often called by subtly different\nnames - nawk and gawk for example) are adequate to build pnglibconf.h.\nThe Sun Microsystems (now Oracle) program 'awk' is an earlier version\nand does not work; this may also apply to other systems that have a\nfunctioning awk called 'nawk'.\n\nConfiguration options are now documented in scripts/pnglibconf.dfa.  This\nfile also includes dependency information that ensures a configuration is\nconsistent; that is, if a feature is switched off, dependent features are\nalso switched off.  As a recommended alternative to using feature macros in\npngusr.h a system builder may also define equivalent options in pngusr.dfa\n(or, indeed, any file) and add that to the configuration by setting\nDFA_XTRA to the file name.  The makefiles in contrib/pngminim illustrate\nhow to do this, and also illustrate a case where pngusr.h is still required.\n\nAfter you have built libpng, the definitions that were recorded in\npnglibconf.h are available to your application (pnglibconf.h is included\nin png.h and gets installed alongside png.h and pngconf.h in your\n$PREFIX/include directory).  Do not edit pnglibconf.h after you have built\nlibpng, because than the settings would not accurately reflect the settings\nthat were used to build libpng.\n\nXV. Setjmp/longjmp issues\n\nLibpng uses setjmp()/longjmp() for error handling.  Unfortunately setjmp()\nis known to be not thread-safe on some platforms and we don't know of\nany platform where it is guaranteed to be thread-safe.  Therefore, if\nyour application is going to be using multiple threads, you should\nconfigure libpng with PNG_NO_SETJMP in your pngusr.dfa file, with\n-DPNG_NO_SETJMP on your compile line, or with\n\n    #undef PNG_SETJMP_SUPPORTED\n\nin your pnglibconf.h or pngusr.h.\n\nStarting with libpng-1.6.0, the library included a \"simplified API\".\nThis requires setjmp/longjmp, so you must either build the library\nwith PNG_SETJMP_SUPPORTED defined, or with PNG_SIMPLIFIED_READ_SUPPORTED\nand PNG_SIMPLIFIED_WRITE_SUPPORTED undefined.\n\nXVI. Common linking failures\n\nIf your application fails to find libpng or zlib entries while linking:\n\n  Be sure \"-lz\" appears after \"-lpng\" on your linking command.\n\n  Be sure you have built libpng, zlib, and your application for the\n  same platform (e.g., 32-bit or 64-bit).\n\n  If you are using the vstudio project, observe the WARNING in\n  project/vstudio/README.txt.\n\nXVII. Other sources of information about libpng:\n\nFurther information can be found in the README and libpng-manual.txt\nfiles, in the individual makefiles, in png.h, and the manual pages\nlibpng.3 and png.5.\n\nCopyright (c) 1998-2002,2006-2016 Glenn Randers-Pehrson\nThis document is released under the libpng license.\nFor conditions of distribution and use, see the disclaimer\nand license in png.h.\n"
  },
  {
    "path": "tess-two/jni/libpng/LICENSE",
    "content": "\nThis copy of the libpng notices is provided for your convenience.  In case of\nany discrepancy between this copy and the notices in the file png.h that is\nincluded in the libpng distribution, the latter shall prevail.\n\nCOPYRIGHT NOTICE, DISCLAIMER, and LICENSE:\n\nIf you modify libpng you may insert additional notices immediately following\nthis sentence.\n\nThis code is released under the libpng license.\n\nlibpng versions 1.0.7, July 1, 2000 through 1.6.25, September 1, 2016 are\nCopyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are\nderived from libpng-1.0.6, and are distributed according to the same\ndisclaimer and license as libpng-1.0.6 with the following individuals\nadded to the list of Contributing Authors:\n\n   Simon-Pierre Cadieux\n   Eric S. Raymond\n   Mans Rullgard\n   Cosmin Truta\n   Gilles Vollant\n   James Yu\n\nand with the following additions to the disclaimer:\n\n   There is no warranty against interference with your enjoyment of the\n   library or against infringement.  There is no warranty that our\n   efforts or the library will fulfill any of your particular purposes\n   or needs.  This library is provided with all faults, and the entire\n   risk of satisfactory quality, performance, accuracy, and effort is with\n   the user.\n\nSome files in the \"contrib\" directory and some configure-generated\nfiles that are distributed with libpng have other copyright owners and\nare released under other open source licenses.\n\nlibpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are\nCopyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from\nlibpng-0.96, and are distributed according to the same disclaimer and\nlicense as libpng-0.96, with the following individuals added to the list\nof Contributing Authors:\n\n   Tom Lane\n   Glenn Randers-Pehrson\n   Willem van Schaik\n\nlibpng versions 0.89, June 1996, through 0.96, May 1997, are\nCopyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,\nand are distributed according to the same disclaimer and license as\nlibpng-0.88, with the following individuals added to the list of\nContributing Authors:\n\n   John Bowler\n   Kevin Bracey\n   Sam Bushell\n   Magnus Holmgren\n   Greg Roelofs\n   Tom Tanner\n\nSome files in the \"scripts\" directory have other copyright owners\nbut are released under this license.\n\nlibpng versions 0.5, May 1995, through 0.88, January 1996, are\nCopyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nFor the purposes of this copyright and license, \"Contributing Authors\"\nis defined as the following set of individuals:\n\n   Andreas Dilger\n   Dave Martindale\n   Guy Eric Schalnat\n   Paul Schmidt\n   Tim Wegner\n\nThe PNG Reference Library is supplied \"AS IS\".  The Contributing Authors\nand Group 42, Inc. disclaim all warranties, expressed or implied,\nincluding, without limitation, the warranties of merchantability and of\nfitness for any purpose.  The Contributing Authors and Group 42, Inc.\nassume no liability for direct, indirect, incidental, special, exemplary,\nor consequential damages, which may result from the use of the PNG\nReference Library, even if advised of the possibility of such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute this\nsource code, or portions hereof, for any purpose, without fee, subject\nto the following restrictions:\n\n  1. The origin of this source code must not be misrepresented.\n\n  2. Altered versions must be plainly marked as such and must not\n     be misrepresented as being the original source.\n\n  3. This Copyright notice may not be removed or altered from any\n     source or altered source distribution.\n\nThe Contributing Authors and Group 42, Inc. specifically permit, without\nfee, and encourage the use of this source code as a component to\nsupporting the PNG file format in commercial products.  If you use this\nsource code in a product, acknowledgment is not required but would be\nappreciated.\n\nEND OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.\n\nTRADEMARK:\n\nThe name \"libpng\" has not been registered by the Copyright owner\nas a trademark in any jurisdiction.  However, because libpng has\nbeen distributed and maintained world-wide, continually since 1995,\nthe Copyright owner claims \"common-law trademark protection\" in any\njurisdiction where common-law trademark is recognized.\n\nOSI CERTIFICATION:\n\nLibpng is OSI Certified Open Source Software.  OSI Certified Open Source is\na certification mark of the Open Source Initiative. OSI has not addressed\nthe additional disclaimers inserted at version 1.0.7.\n\nEXPORT CONTROL:\n\nThe Copyright owner believes that the Export Control Classification\nNumber (ECCN) for libpng is EAR99, which means not subject to export\ncontrols or International Traffic in Arms Regulations (ITAR) because\nit is open source, publicly available software, that does not contain\nany encryption software.  See the EAR, paragraphs 734.3(b)(3) and\n734.7(b).\n\nGlenn Randers-Pehrson\nglennrp at users.sourceforge.net\nSeptember 1, 2016\n"
  },
  {
    "path": "tess-two/jni/libpng/MODULE_LICENSE_BSD_LIKE",
    "content": ""
  },
  {
    "path": "tess-two/jni/libpng/Makefile.am",
    "content": "# Makefile.am, the source file for Makefile.in (and hence Makefile), is\n#\n# Copyright (c) 2004-2016 Glenn Randers-Pehrson\n# Last changed in libpng 1.6.25 [September 1, 2016]\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\nPNGLIB_BASENAME= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@\n\nACLOCAL_AMFLAGS = -I scripts\n\n# test programs - run on make check, make distcheck\ncheck_PROGRAMS= pngtest pngunknown pngstest pngvalid pngimage pngcp\nif HAVE_CLOCK_GETTIME\ncheck_PROGRAMS += timepng\nendif\n\n# Utilities - installed\nbin_PROGRAMS= pngfix png-fix-itxt\n\n# This ensures that pnglibconf.h gets built at the start of 'make all' or\n# 'make check', but it does not add dependencies to the individual programs,\n# this is done below.\n#\n# IMPORTANT: always add the object modules of new programs to the list below\n# because otherwise the sequence 'configure; make new-program' will *sometimes*\n# result in the installed (system) pnglibconf.h being used and the result is\n# always wrong and always very confusing.\nBUILT_SOURCES = pnglibconf.h\n\npngtest_SOURCES = pngtest.c\npngtest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npngvalid_SOURCES = contrib/libtests/pngvalid.c\npngvalid_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npngstest_SOURCES = contrib/libtests/pngstest.c\npngstest_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npngunknown_SOURCES = contrib/libtests/pngunknown.c\npngunknown_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npngimage_SOURCES = contrib/libtests/pngimage.c\npngimage_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\ntimepng_SOURCES = contrib/libtests/timepng.c\ntimepng_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npngfix_SOURCES = contrib/tools/pngfix.c\npngfix_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\npng_fix_itxt_SOURCES = contrib/tools/png-fix-itxt.c\n\npngcp_SOURCES = contrib/tools/pngcp.c\npngcp_LDADD = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n\n# Generally these are single line shell scripts to run a test with a particular\n# set of parameters:\nTESTS =\\\n   tests/pngtest\\\n   tests/pngvalid-gamma-16-to-8 tests/pngvalid-gamma-alpha-mode\\\n   tests/pngvalid-gamma-background tests/pngvalid-gamma-expand16-alpha-mode\\\n   tests/pngvalid-gamma-expand16-background\\\n   tests/pngvalid-gamma-expand16-transform tests/pngvalid-gamma-sbit\\\n   tests/pngvalid-gamma-threshold tests/pngvalid-gamma-transform\\\n   tests/pngvalid-progressive-size\\\n   tests/pngvalid-progressive-interlace-standard\\\n   tests/pngvalid-transform\\\n   tests/pngvalid-progressive-standard tests/pngvalid-standard\\\n   tests/pngstest-1.8 tests/pngstest-1.8-alpha tests/pngstest-linear\\\n   tests/pngstest-linear-alpha tests/pngstest-none tests/pngstest-none-alpha\\\n   tests/pngstest-sRGB tests/pngstest-sRGB-alpha tests/pngunknown-IDAT\\\n   tests/pngunknown-discard tests/pngunknown-if-safe tests/pngunknown-sAPI\\\n   tests/pngunknown-sTER tests/pngunknown-save tests/pngunknown-vpAg\\\n   tests/pngimage-quick tests/pngimage-full\n\n# man pages\ndist_man_MANS= libpng.3 libpngpf.3 png.5\n\n# generate the -config scripts if required\nbinconfigs= libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config\nEXTRA_SCRIPTS= libpng-config libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config\nbin_SCRIPTS= @binconfigs@\n\n# rules to build libpng, only build the old library on request\nlib_LTLIBRARIES=libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.la\n# EXTRA_LTLIBRARIES= libpng.la\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = png.c pngerror.c\\\n\tpngget.c pngmem.c pngpread.c pngread.c pngrio.c pngrtran.c pngrutil.c\\\n\tpngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c pngwutil.c\\\n\tpng.h pngconf.h pngdebug.h pnginfo.h pngpriv.h pngstruct.h pngusr.dfa\n\nif PNG_ARM_NEON\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += arm/arm_init.c\\\n\tarm/filter_neon.S arm/filter_neon_intrinsics.c\nendif\n\nif PNG_MIPS_MSA\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c\\\n\tmips/filter_msa_intrinsics.c\nendif\n\nif PNG_INTEL_SSE\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\\\n    contrib/intel/filter_sse2_intrinsics.c\nendif\n\nnodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h\n\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \\\n\t-version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0\n\nif HAVE_LD_VERSION_SCRIPT\n#   Versioned symbols and restricted exports\nif HAVE_SOLARIS_LD\n  libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS += -Wl,-M -Wl,libpng.vers\nelse\n  libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS += -Wl,--version-script=libpng.vers\nendif\n\n  libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng.vers\nelse\n#   Only restricted exports when possible\n  libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS += -export-symbols libpng.sym\n  libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_DEPENDENCIES = libpng.sym\nendif\n\n#distribute headers in /usr/include/libpng/*\npkgincludedir= $(includedir)/$(PNGLIB_BASENAME)\npkginclude_HEADERS= png.h pngconf.h\nnodist_pkginclude_HEADERS= pnglibconf.h\n\n# pkg-config stuff, note that libpng.pc is always required in order\n# to get the correct library\npkgconfigdir = @pkgconfigdir@\npkgconfig_DATA = libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc\n\n# Extra source distribution files, '${srcdir}' is used below to stop build files\n# from those directories being included.  This only works if the configure is\n# not done in the source directory!\nEXTRA_DIST= \\\n\tANNOUNCE CHANGES INSTALL LICENSE README TODO \\\n\tpngtest.png pngbar.png pngnow.png pngbar.jpg autogen.sh \\\n\t${srcdir}/contrib ${srcdir}/projects ${srcdir}/scripts \\\n\t$(TESTS) $(XFAIL_TESTS) tests/pngstest \\\n\tCMakeLists.txt example.c libpng-manual.txt\n\nSCRIPT_CLEANFILES=scripts/*.out scripts/*.chk\n\nCLEANFILES= *.tf? pngout.png libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@.pc \\\n\tlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@-config libpng.vers libpng.sym \\\n\tcheck.new pnglibconf.h pngprefix.h symbols.new pngtest-log.txt \\\n\tpnglibconf.out pnglibconf.c pnglibconf.pre pnglibconf.dfn \\\n\t$(SCRIPT_CLEANFILES)\n\nMAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.guess config.h.in \\\nconfig.sub configure depcomp install-sh ltmain.sh missing\n\n# PNG_COPTS give extra options for the C compiler to be used on all compilation\n# steps (unless targe_CFLAGS is specified; that will take precedence over\n# AM_CFLAGS)\nPNG_COPTS = @PNG_COPTS@\nAM_CFLAGS = ${PNG_COPTS}\n\n# DFNCPP is normally just CPP - the C preprocessor - but on Solaris and maybe\n# other operating systems (NeXT?) the C preprocessor selected by configure\n# checks input tokens for validity - effectively it performs part of the ANSI-C\n# parsing - and therefore fails with the .df files.  configure.ac has special\n# checks for this and sets DFNCPP appropriately.\nDFNCPP = @DFNCPP@\n\nSUFFIXES = .chk .out\n\n$(PNGLIB_BASENAME).pc: libpng.pc\n\tcp libpng.pc $@\n\n$(PNGLIB_BASENAME)-config: libpng-config\n\tcp libpng-config $@\n\nscripts/sym.out scripts/vers.out: png.h pngconf.h pnglibconf.h\nscripts/prefix.out: png.h pngconf.h pnglibconf.out\nscripts/symbols.out: png.h pngconf.h $(srcdir)/scripts/pnglibconf.h.prebuilt\nscripts/intprefix.out: pnglibconf.h\n\nlibpng.sym: scripts/sym.out\n\trm -f $@\n\tcp $? $@\nlibpng.vers: scripts/vers.out\n\trm -f $@\n\tcp $? $@\n\nif DO_PNG_PREFIX\n# Rename functions in scripts/prefix.out with a PNG_PREFIX prefix.\n# Rename macros in scripts/macro.lst from PNG_PREFIXpng_ to PNG_ (the actual\n# implementation of the macro).\npnglibconf.h: pnglibconf.out scripts/prefix.out scripts/macro.lst\n\trm -f $@\n\t$(AWK) 's==0 && NR>1{print prev}\\\n\t   s==0{prev=$$0}\\\n\t   s==1{print \"#define\", $$1, \"@PNG_PREFIX@\" $$1}\\\n\t   s==2{print \"#define @PNG_PREFIX@png_\" $$1, \"PNG_\" $$1}\\\n\t   END{print prev}' s=0 pnglibconf.out s=1 scripts/prefix.out\\\n\t   s=2 ${srcdir}/scripts/macro.lst >pnglibconf.tf8\n\tmv pnglibconf.tf8 $@\n\npngprefix.h: scripts/intprefix.out\n\trm -f pngprefix.tf1\n\t$(AWK) '{print \"#define\", $$1, \"@PNG_PREFIX@\" $$1}' $? >pngprefix.tf1\n\tmv pngprefix.tf1 $@\nelse\npnglibconf.h: pnglibconf.out\n\trm -f $@\n\tcp $? $@\n\npngprefix.h: # is empty\n\t:>$@\nendif\n\n$(srcdir)/scripts/pnglibconf.h.prebuilt:\n\t@echo \"Attempting to build $@\" >&2\n\t@echo \"This is a machine generated file, but if you want to make\" >&2\n\t@echo \"a new one simply make 'scripts/pnglibconf.out', copy that\" >&2\n\t@echo \"AND set PNG_ZLIB_VERNUM to 0 (you MUST do this)\" >&2\n\t@exit 1\n\n# The following is necessary to ensure that the local pnglibconf.h is used, not\n# an installed one (this can happen immediately after on a clean system if\n# 'make test' is the first thing the user does.)  Only files which include\n# one of the png source files (typically png.h or pngpriv.h) need to be listed\n# here:\npngtest.o: pnglibconf.h\n\ncontrib/libtests/makepng.o: pnglibconf.h\ncontrib/libtests/pngstest.o: pnglibconf.h\ncontrib/libtests/pngunknown.o: pnglibconf.h\ncontrib/libtests/pngimage.o: pnglibconf.h\ncontrib/libtests/pngvalid.o: pnglibconf.h\ncontrib/libtests/readpng.o: pnglibconf.h\ncontrib/libtests/tarith.o: pnglibconf.h\ncontrib/libtests/timepng.o: pnglibconf.h\n\ncontrib/tools/makesRGB.o: pnglibconf.h\ncontrib/tools/pngfix.o: pnglibconf.h\ncontrib/tools/pngcp.o: pnglibconf.h\n\n# We must use -DPNG_NO_USE_READ_MACROS here even when the library may actually\n# be built with PNG_USE_READ_MACROS; this prevents the read macros from\n# interfering with the symbol file format.\nSYMBOL_CFLAGS = -DPNGLIB_LIBNAME='PNG@PNGLIB_MAJOR@@PNGLIB_MINOR@_0'\\\n\t\t-DPNGLIB_VERSION='@PNGLIB_VERSION@'\\\n\t\t-DSYMBOL_PREFIX='$(SYMBOL_PREFIX)'\\\n\t\t-DPNG_NO_USE_READ_MACROS -DPNG_BUILDING_SYMBOL_TABLE\n\nif DO_PNG_PREFIX\nSYMBOL_CFLAGS += -DPNG_PREFIX='@PNG_PREFIX@'\nendif\n\n.c.out:\n\trm -f $@ $*.tf[12]\n\ttest -d scripts || mkdir scripts || test -d scripts\n\t$(DFNCPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES)\\\n\t    $(CPPFLAGS) $(SYMBOL_CFLAGS) $< > $*.tf1\n\t$(AWK) -f \"${srcdir}/scripts/dfn.awk\" out=\"$*.tf2\" $*.tf1 1>&2\n\trm -f $*.tf1\n\tmv $*.tf2 $@\n\n# The .c file for pnglibconf.h is machine generated\npnglibconf.c: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_XTRA)\n\trm -f $@ $*.tf[45]\n\t$(AWK) -f ${srcdir}/scripts/options.awk out=$*.tf4 version=search\\\n\t    ${srcdir}/pngconf.h ${srcdir}/scripts/pnglibconf.dfa\\\n\t    ${srcdir}/pngusr.dfa $(DFA_XTRA) 1>&2\n\t$(AWK) -f ${srcdir}/scripts/options.awk out=$*.tf5 $*.tf4 1>&2\n\trm $*.tf4\n\tmv $*.tf5 $@\n\n# Symbol checks (.def and .out files should match)\nscripts/symbols.chk: scripts/checksym.awk scripts/symbols.def scripts/symbols.out\n\n.out.chk:\n\trm -f $@ $*.new\n\t$(AWK) -f ${srcdir}/scripts/checksym.awk ${srcdir}/scripts/${*F}.def\\\n\t    of=\"$*.new\" $< >&2\n\tmv $*.new $@\n\n# used on demand to regenerate the standard header, CPPFLAGS should\n# be empty - no non-standard defines\nscripts/pnglibconf.c: scripts/pnglibconf.dfa scripts/options.awk pngconf.h\n\trm -f $@ pnglibconf.tf[67]\n\ttest -z \"$(CPPFLAGS)\"\n\techo \"com @PNGLIB_VERSION@ STANDARD API DEFINITION\" |\\\n\t$(AWK) -f ${srcdir}/scripts/options.awk out=pnglibconf.tf6\\\n\t    logunsupported=1 version=search ${srcdir}/pngconf.h -\\\n\t    ${srcdir}/scripts/pnglibconf.dfa 1>&2\n\t$(AWK) -f ${srcdir}/scripts/options.awk out=pnglibconf.tf7\\\n\t    pnglibconf.tf6 1>&2\n\trm pnglibconf.tf6\n\tmv pnglibconf.tf7 $@\n\n$(libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_OBJECTS): png.h pngconf.h \\\n\tpnglibconf.h pngpriv.h pngdebug.h pnginfo.h pngstruct.h pngprefix.h\n\ntest: check-am\n\n# Extra checks\ncheck: scripts/symbols.chk\n\n# Don't distribute the generated script files\ndist-hook:\n\tcd '$(top_distdir)'; rm -f $(SCRIPT_CLEANFILES)\n\n# Make links between installed files with release-specific names and the generic\n# file names.  If this install rule is run the generic names will be deleted and\n# recreated - this has obvious issues for systems with multiple installations.\n\ninstall-header-links:\n\t@set -ex; cd '$(DESTDIR)$(includedir)'; for f in $(HEADERS); do \\\n\t   rm -f \"$$f\"; $(LN_S) \"$(PNGLIB_BASENAME)/$$f\" \"$$f\"; done\n\nuninstall-header-links:\n\tcd '$(DESTDIR)$(includedir)'; rm -f $(HEADERS)\n\ninstall-libpng-pc:\n\t@set -ex; cd '$(DESTDIR)$(pkgconfigdir)'; rm -f libpng.pc; \\\n\t   $(LN_S) '$(PNGLIB_BASENAME).pc' libpng.pc\n\nuninstall-libpng-pc:\n\trm -f '$(DESTDIR)$(pkgconfigdir)/libpng.pc'\n\n# EXT_LIST is a list of the possibly library directory extensions, this exists\n# because we can't find a good way of discovering the file extensions that are\n# actually installed on a given system, so instead we check for every extension\n# we have seen.\n\nEXT_LIST = a dll.a so so.@PNGLIB_MAJOR@@PNGLIB_MINOR@.@PNGLIB_RELEASE@ la sl dylib\n\ninstall-library-links:\n\t@set -x; cd '$(DESTDIR)$(libdir)';\\\n\tfor ext in $(EXT_LIST); do\\\n\t   rm -f \"libpng.$$ext\";\\\n           if test -f \"$(PNGLIB_BASENAME).$$ext\"; then\\\n              $(LN_S) \"$(PNGLIB_BASENAME).$$ext\" \"libpng.$$ext\" || exit 1;\\\n           fi;\\\n\tdone\n\nuninstall-library-links:\n\t@set -x; cd '$(DESTDIR)$(libdir)'; for ext in $(EXT_LIST); do\\\n\t   rm -f \"libpng.$$ext\"; done\n\ninstall-libpng-config:\n\t@set -ex; cd '$(DESTDIR)$(bindir)'; rm -f libpng-config; \\\n\t   $(LN_S) '$(PNGLIB_BASENAME)-config' libpng-config\n\nuninstall-libpng-config:\n\trm -f '$(DESTDIR)$(bindir)/libpng-config'\n\nif DO_INSTALL_LINKS\n# If --enable-unversioned-links is specified the header and lib file links\n# will be automatically made on a 'make install':\n\ninstall-data-hook: install-header-links\nuninstall-hook: uninstall-header-links\ninstall-exec-hook: install-library-links\nuninstall-hook: uninstall-library-links\nendif\n\nif DO_INSTALL_LIBPNG_PC\n# Likewise, --install-pc causes libpng.pc to be constructed:\n\ninstall-data-hook: install-libpng-pc\nuninstall-hook: uninstall-libpng-pc\nendif\n\nif DO_INSTALL_LIBPNG_CONFIG\n# And --install-config:\n\ninstall-exec-hook: install-libpng-config\nuninstall-hook: uninstall-libpng-config\nendif\n\n# The following addition ensures that 'make all' always builds the test programs\n# too.  It used to, but some change either in libpng or configure stopped this\n# working.\nall-am: $(check_PROGRAMS)\n"
  },
  {
    "path": "tess-two/jni/libpng/README",
    "content": "README for libpng version 1.6.25 - September 1, 2016 (shared library 16.0)\nSee the note about version numbers near the top of png.h\n\nSee INSTALL for instructions on how to install libpng.\n\nLibpng comes in several distribution formats.  Get libpng-*.tar.gz or\nlibpng-*.tar.xz or if you want UNIX-style line endings in the text files,\nor lpng*.7z or lpng*.zip if you want DOS-style line endings.\n\nVersion 0.89 was the first official release of libpng.  Don't let the\nfact that it's the first release fool you.  The libpng library has been in\nextensive use and testing since mid-1995.  By late 1997 it had\nfinally gotten to the stage where there hadn't been significant\nchanges to the API in some time, and people have a bad feeling about\nlibraries with versions < 1.0.  Version 1.0.0 was released in\nMarch 1998.\n\n****\nNote that some of the changes to the png_info structure render this\nversion of the library binary incompatible with libpng-0.89 or\nearlier versions if you are using a shared library.  The type of the\n\"filler\" parameter for png_set_filler() has changed from png_byte to\npng_uint_32, which will affect shared-library applications that use\nthis function.\n\nTo avoid problems with changes to the internals of png info_struct,\nnew APIs have been made available in 0.95 to avoid direct application\naccess to info_ptr.  These functions are the png_set_<chunk> and\npng_get_<chunk> functions.  These functions should be used when\naccessing/storing the info_struct data, rather than manipulating it\ndirectly, to avoid such problems in the future.\n\nIt is important to note that the APIs did not make current programs\nthat access the info struct directly incompatible with the new\nlibrary, through libpng-1.2.x.  In libpng-1.4.x, which was meant to\nbe a transitional release, members of the png_struct and the\ninfo_struct can still be accessed, but the compiler will issue a\nwarning about deprecated usage.  Since libpng-1.5.0, direct access\nto these structs is not allowed, and the definitions of the structs\nreside in private pngstruct.h and pnginfo.h header files that are not\naccessible to applications.  It is strongly suggested that new\nprograms use the new APIs (as shown in example.c and pngtest.c), and\nolder programs be converted to the new format, to facilitate upgrades\nin the future.\n****\n\nAdditions since 0.90 include the ability to compile libpng as a\nWindows DLL, and new APIs for accessing data in the info struct.\nExperimental functions include the ability to set weighting and cost\nfactors for row filter selection, direct reads of integers from buffers\non big-endian processors that support misaligned data access, faster\nmethods of doing alpha composition, and more accurate 16->8 bit color\nconversion.\n\nThe additions since 0.89 include the ability to read from a PNG stream\nwhich has had some (or all) of the signature bytes read by the calling\napplication.  This also allows the reading of embedded PNG streams that\ndo not have the PNG file signature.  As well, it is now possible to set\nthe library action on the detection of chunk CRC errors.  It is possible\nto set different actions based on whether the CRC error occurred in a\ncritical or an ancillary chunk.\n\nThe changes made to the library, and bugs fixed are based on discussions\non the PNG-implement mailing list and not on material submitted\nprivately to Guy, Andreas, or Glenn.  They will forward any good\nsuggestions to the list.\n\nFor a detailed description on using libpng, read libpng-manual.txt.  For\nexamples of libpng in a program, see example.c and pngtest.c.  For usage\ninformation and restrictions (what little they are) on libpng, see\npng.h.  For a description on using zlib (the compression library used by\nlibpng) and zlib's restrictions, see zlib.h\n\nI have included a general makefile, as well as several machine and\ncompiler specific ones, but you may have to modify one for your own needs.\n\nYou should use zlib 1.0.4 or later to run this, but it MAY work with\nversions as old as zlib 0.95.  Even so, there are bugs in older zlib\nversions which can cause the output of invalid compression streams for\nsome images.  You will definitely need zlib 1.0.4 or later if you are\ntaking advantage of the MS-DOS \"far\" structure allocation for the small\nand medium memory models.  You should also note that zlib is a\ncompression library that is useful for more things than just PNG files.\nYou can use zlib as a drop-in replacement for fread() and fwrite() if\nyou are so inclined.\n\nzlib should be available at the same place that libpng is, or at zlib.net.\n\nYou may also want a copy of the PNG specification.  It is available\nas an RFC, a W3C Recommendation, and an ISO/IEC Standard.  You can find\nthese at http://www.libpng.org/pub/png/documents/\n\nThis code is currently being archived at libpng.sf.net in the\n[DOWNLOAD] area, and at ftp://ftp.simplesystems.org.  If you can't find it\nin any of those places, e-mail me, and I'll help you find it.\n\nI am not a lawyer, but I believe that the Export Control Classification\nNumber (ECCN) for libpng is EAR99, which means not subject to export\ncontrols or International Traffic in Arms Regulations (ITAR) because it\nis open source, publicly available software, that does not contain any\nencryption software.  See the EAR, paragraphs 734.3(b)(3) and 734.7(b).\n\nIf you have any code changes, requests, problems, etc., please e-mail\nthem to me.  Also, I'd appreciate any make files or project files,\nand any modifications you needed to make to get libpng to compile,\nalong with a #define variable to tell what compiler/system you are on.\nIf you needed to add transformations to libpng, or wish libpng would\nprovide the image in a different way, drop me a note (and code, if\npossible), so I can consider supporting the transformation.\nFinally, if you get any warning messages when compiling libpng\n(note: not zlib), and they are easy to fix, I'd appreciate the\nfix.  Please mention \"libpng\" somewhere in the subject line.  Thanks.\n\nThis release was created and will be supported by myself (of course\nbased in a large way on Guy's and Andreas' earlier work), and the PNG\ndevelopment group.\n\nSend comments/corrections/commendations to png-mng-implement at\nlists.sourceforge.net (subscription required; visit\nhttps://lists.sourceforge.net/lists/listinfo/png-mng-implement\nto subscribe) or to glennrp at users.sourceforge.net\n\nYou can't reach Guy, the original libpng author, at the addresses\ngiven in previous versions of this document.  He and Andreas will\nread mail addressed to the png-implement list, however.\n\nPlease do not send general questions about PNG.  Send them to\npng-mng-misc at lists.sf.net (subscription required; visit\nhttps://lists.sourceforge.net/lists/listinfo/png-mng-misc to\nsubscribe).  If you have a question about something\nin the PNG specification that is related to using libpng, send it\nto me.  Send me any questions that start with \"I was using libpng,\nand ...\".  If in doubt, send questions to me.  I'll bounce them\nto others, if necessary.\n\nPlease do not send suggestions on how to change PNG.  We have\nbeen discussing PNG for twenty years now, and it is official and\nfinished.  If you have suggestions for libpng, however, I'll\ngladly listen.  Even if your suggestion is not used immediately,\nit may be used later.\n\nFiles in this distribution:\n\n      ANNOUNCE      =>  Announcement of this version, with recent changes\n      CHANGES       =>  Description of changes between libpng versions\n      KNOWNBUG      =>  List of known bugs and deficiencies\n      LICENSE       =>  License to use and redistribute libpng\n      README        =>  This file\n      TODO          =>  Things not implemented in the current library\n      Y2KINFO       =>  Statement of Y2K compliance\n      example.c     =>  Example code for using libpng functions\n      libpng.3      =>  manual page for libpng (includes libpng-manual.txt)\n      libpng-manual.txt  =>  Description of libpng and its functions\n      libpngpf.3    =>  manual page for libpng's private functions\n      png.5         =>  manual page for the PNG format\n      png.c         =>  Basic interface functions common to library\n      png.h         =>  Library function and interface declarations (public)\n      pngpriv.h     =>  Library function and interface declarations (private)\n      pngconf.h     =>  System specific library configuration (public)\n      pngstruct.h   =>  png_struct declaration (private)\n      pnginfo.h     =>  png_info struct declaration (private)\n      pngdebug.h    =>  debugging macros (private)\n      pngerror.c    =>  Error/warning message I/O functions\n      pngget.c      =>  Functions for retrieving info from struct\n      pngmem.c      =>  Memory handling functions\n      pngbar.png    =>  PNG logo, 88x31\n      pngnow.png    =>  PNG logo, 98x31\n      pngpread.c    =>  Progressive reading functions\n      pngread.c     =>  Read data/helper high-level functions\n      pngrio.c      =>  Lowest-level data read I/O functions\n      pngrtran.c    =>  Read data transformation functions\n      pngrutil.c    =>  Read data utility functions\n      pngset.c      =>  Functions for storing data into the info_struct\n      pngtest.c     =>  Library test program\n      pngtest.png   =>  Library test sample image\n      pngtrans.c    =>  Common data transformation functions\n      pngwio.c      =>  Lowest-level write I/O functions\n      pngwrite.c    =>  High-level write functions\n      pngwtran.c    =>  Write data transformations\n      pngwutil.c    =>  Write utility functions\n      arm           =>  Contains optimized code for the ARM platform\n      contrib       =>  Contributions\n       arm-neon         =>  Optimized code for ARM-NEON platform\n       examples         =>  Example programs\n       gregbook         =>  source code for PNG reading and writing, from\n                            Greg Roelofs' \"PNG: The Definitive Guide\",\n                            O'Reilly, 1999\n       intel            =>  Optimized code for INTEL-SSE2 platform\n       libtests         =>  Test programs\n       pngminim         =>  Minimal decoder, encoder, and progressive decoder\n                            programs demonstrating use of pngusr.dfa\n       pngminus         =>  Simple pnm2png and png2pnm programs\n       pngsuite         =>  Test images\n       testpngs\n       tools            =>  Various tools\n       visupng          =>  Contains a MSVC workspace for VisualPng\n      projects      =>  Contains project files and workspaces for\n                        building a DLL\n       owatcom          =>  Contains a WATCOM project for building libpng\n       visualc71        =>  Contains a Microsoft Visual C++ (MSVC)\n                            workspace for building libpng and zlib\n       vstudio          =>  Contains a Microsoft Visual C++ (MSVC)\n                            workspace for building libpng and zlib\n      scripts       =>  Directory containing scripts for building libpng:\n                            (see scripts/README.txt for the list of scripts)\n\nGood luck, and happy coding.\n\n-Glenn Randers-Pehrson (current maintainer, since 1998)\n Internet: glennrp at users.sourceforge.net\n\n-Andreas Eric Dilger (former maintainer, 1996-1997)\n Internet: adilger at enel.ucalgary.ca\n Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/\n\n-Guy Eric Schalnat (original author and former maintainer, 1995-1996)\n (formerly of Group 42, Inc)\n Internet: gschal at infinet.com\n"
  },
  {
    "path": "tess-two/jni/libpng/README.android",
    "content": "Any Android specific modifications to upstream libpng (1.6.25) should\nbe listed here:\n\n(1) Android has added the following files.\n    pngusr.h\n    Android.mk\n    CleanSpec.mk\n    MODULE_LICENSE_BSD_LIKE\n    README.version\n\n(2) pnglibconf.h\n    This is copied from scripts/pnglibconf.h.prebuilt.\n    Android has undefined PNG_WARNINGS_SUPPORTED.\n\n(3) Removed contrib/testpngs/\n    There is no reason to check in all of these files if we won't\n    be using them.\n\n(4) Applied the Intel SSE patch\n    Upstream places the patch for SSE support\n    in contrib/intel/intel_sse.patch.\n    The patch was applied using the following command:\n    'patch -i contrib/intel/intel_sse.patch -p1'\n"
  },
  {
    "path": "tess-two/jni/libpng/README.version",
    "content": "URL: https://sourceforge.net/projects/libpng/files/libpng16/1.6.25/libpng-1.6.25.tar.gz/download\nVersion: 1.6.25\nBugComponent: 87896\n"
  },
  {
    "path": "tess-two/jni/libpng/TODO",
    "content": "/*\nTODO - list of things to do for libpng:\n\nFinal bug fixes.\nBetter C++ wrapper/full C++ implementation?\nFix problem with C++ and EXTERN \"C\".\ncHRM transformation.\nRemove setjmp/longjmp usage in favor of returning error codes. As a start on\n  this, minimize the use of png_error(), replacing them with\n  png_warning(); return(0; or similar.\nPalette creation.\nAdd \"grayscale->palette\" transformation and \"palette->grayscale\" detection.\nImproved dithering.\nMulti-lingual error and warning message support.\nComplete sRGB transformation (presently it simply uses gamma=0.45455).\nMan pages for function calls.\nBetter documentation.\nBetter filter selection\n   (counting huffman bits/precompression?  filter inertia?  filter costs?).\nHistogram creation.\nText conversion between different code pages (Latin-1 -> Mac and DOS).\nAvoid building gamma tables whenever possible.\nUse greater precision when changing to linear gamma for compositing against\n  background and doing rgb-to-gray transformation.\nInvestigate pre-incremented loop counters and other loop constructions.\nAdd interpolated method of handling interlacing.\nSwitch to the simpler zlib (zlib/libpng) license if legally possible.\nExtend pngvalid.c to validate more of the libpng transformations.\n\n*/\n"
  },
  {
    "path": "tess-two/jni/libpng/arm/arm_init.c",
    "content": "\n/* arm_init.c - NEON optimised filter functions\n *\n * Copyright (c) 2014,2016 Glenn Randers-Pehrson\n * Written by Mans Rullgard, 2011.\n * Last changed in libpng 1.6.22 [May 26, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are\n * called.\n */\n#define _POSIX_SOURCE 1\n\n#include \"../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n#if PNG_ARM_NEON_OPT > 0\n#ifdef PNG_ARM_NEON_CHECK_SUPPORTED /* Do run-time checks */\n/* WARNING: it is strongly recommended that you do not build libpng with\n * run-time checks for CPU features if at all possible.  In the case of the ARM\n * NEON instructions there is no processor-specific way of detecting the\n * presence of the required support, therefore run-time detection is extremely\n * OS specific.\n *\n * You may set the macro PNG_ARM_NEON_FILE to the file name of file containing\n * a fragment of C source code which defines the png_have_neon function.  There\n * are a number of implementations in contrib/arm-neon, but the only one that\n * has partial support is contrib/arm-neon/linux.c - a generic Linux\n * implementation which reads /proc/cpufino.\n */\n#ifndef PNG_ARM_NEON_FILE\n#  ifdef __linux__\n#     define PNG_ARM_NEON_FILE \"contrib/arm-neon/linux.c\"\n#  endif\n#endif\n\n#ifdef PNG_ARM_NEON_FILE\n\n#include <signal.h> /* for sig_atomic_t */\nstatic int png_have_neon(png_structp png_ptr);\n#include PNG_ARM_NEON_FILE\n\n#else  /* PNG_ARM_NEON_FILE */\n#  error \"PNG_ARM_NEON_FILE undefined: no support for run-time ARM NEON checks\"\n#endif /* PNG_ARM_NEON_FILE */\n#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */\n\n#ifndef PNG_ALIGNED_MEMORY_SUPPORTED\n#  error \"ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED\"\n#endif\n\nvoid\npng_init_filter_functions_neon(png_structp pp, unsigned int bpp)\n{\n   /* The switch statement is compiled in for ARM_NEON_API, the call to\n    * png_have_neon is compiled in for ARM_NEON_CHECK.  If both are defined\n    * the check is only performed if the API has not set the NEON option on\n    * or off explicitly.  In this case the check controls what happens.\n    *\n    * If the CHECK is not compiled in and the option is UNSET the behavior prior\n    * to 1.6.7 was to use the NEON code - this was a bug caused by having the\n    * wrong order of the 'ON' and 'default' cases.  UNSET now defaults to OFF,\n    * as documented in png.h\n    */\n   png_debug(1, \"in png_init_filter_functions_neon\");\n#ifdef PNG_ARM_NEON_API_SUPPORTED\n   switch ((pp->options >> PNG_ARM_NEON) & 3)\n   {\n      case PNG_OPTION_UNSET:\n         /* Allow the run-time check to execute if it has been enabled -\n          * thus both API and CHECK can be turned on.  If it isn't supported\n          * this case will fall through to the 'default' below, which just\n          * returns.\n          */\n#endif /* PNG_ARM_NEON_API_SUPPORTED */\n#ifdef PNG_ARM_NEON_CHECK_SUPPORTED\n         {\n            static volatile sig_atomic_t no_neon = -1; /* not checked */\n\n            if (no_neon < 0)\n               no_neon = !png_have_neon(pp);\n\n            if (no_neon)\n               return;\n         }\n#ifdef PNG_ARM_NEON_API_SUPPORTED\n         break;\n#endif\n#endif /* PNG_ARM_NEON_CHECK_SUPPORTED */\n\n#ifdef PNG_ARM_NEON_API_SUPPORTED\n      default: /* OFF or INVALID */\n         return;\n\n      case PNG_OPTION_ON:\n         /* Option turned on */\n         break;\n   }\n#endif\n\n   /* IMPORTANT: any new external functions used here must be declared using\n    * PNG_INTERNAL_FUNCTION in ../pngpriv.h.  This is required so that the\n    * 'prefix' option to configure works:\n    *\n    *    ./configure --with-libpng-prefix=foobar_\n    *\n    * Verify you have got this right by running the above command, doing a build\n    * and examining pngprefix.h; it must contain a #define for every external\n    * function you add.  (Notice that this happens automatically for the\n    * initialization function.)\n    */\n   pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_neon;\n\n   if (bpp == 3)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_neon;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_neon;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n         png_read_filter_row_paeth3_neon;\n   }\n\n   else if (bpp == 4)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_neon;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_neon;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n          png_read_filter_row_paeth4_neon;\n   }\n}\n#endif /* PNG_ARM_NEON_OPT > 0 */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/arm/filter_neon.S",
    "content": "\n/* filter_neon.S - NEON optimised filter functions\n *\n * Copyright (c) 2014 Glenn Randers-Pehrson\n * Written by Mans Rullgard, 2011.\n * Last changed in libpng 1.6.16 [December 22, 2014]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* This is required to get the symbol renames, which are #defines, and the\n * definitions (or not) of PNG_ARM_NEON_OPT and PNG_ARM_NEON_IMPLEMENTATION.\n */\n#define PNG_VERSION_INFO_ONLY\n#include \"../pngpriv.h\"\n\n#if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,\"\",%progbits /* mark stack as non-executable */\n#endif\n\n#ifdef PNG_READ_SUPPORTED\n\n/* Assembler NEON support - only works for 32-bit ARM (i.e. it does not work for\n * ARM64).  The code in arm/filter_neon_intrinsics.c supports ARM64, however it\n * only works if -mfpu=neon is specified on the GCC command line.  See pngpriv.h\n * for the logic which sets PNG_USE_ARM_NEON_ASM:\n */\n#if PNG_ARM_NEON_IMPLEMENTATION == 2 /* hand-coded assembler */\n\n#if PNG_ARM_NEON_OPT > 0\n\n#ifdef __ELF__\n#   define ELF\n#else\n#   define ELF @\n#endif\n\n        .arch armv7-a\n        .fpu  neon\n\n.macro  func    name, export=0\n    .macro endfunc\nELF     .size   \\name, . - \\name\n        .endfunc\n        .purgem endfunc\n    .endm\n        .text\n\n        /* Explicitly specifying alignment here because some versions of\n         * GAS don't align code correctly.  This is harmless in correctly\n         * written versions of GAS.\n         */\n        .align 2\n\n    .if \\export\n        .global \\name\n    .endif\nELF     .type   \\name, STT_FUNC\n        .func   \\name\n\\name:\n.endm\n\nfunc    png_read_filter_row_sub4_neon, export=1\n        ldr             r3,  [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n1:\n        vld4.32         {d4[],d5[],d6[],d7[]},    [r1,:128]\n        vadd.u8         d0,  d3,  d4\n        vadd.u8         d1,  d0,  d5\n        vadd.u8         d2,  d1,  d6\n        vadd.u8         d3,  d2,  d7\n        vst4.32         {d0[0],d1[0],d2[0],d3[0]},[r1,:128]!\n        subs            r3,  r3,  #16\n        bgt             1b\n\n        bx              lr\nendfunc\n\nfunc    png_read_filter_row_sub3_neon, export=1\n        ldr             r3,  [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n        mov             r0,  r1\n        mov             r2,  #3\n        mov             r12, #12\n        vld1.8          {q11},    [r0], r12\n1:\n        vext.8          d5,  d22, d23, #3\n        vadd.u8         d0,  d3,  d22\n        vext.8          d6,  d22, d23, #6\n        vadd.u8         d1,  d0,  d5\n        vext.8          d7,  d23, d23, #1\n        vld1.8          {q11},    [r0], r12\n        vst1.32         {d0[0]},  [r1,:32], r2\n        vadd.u8         d2,  d1,  d6\n        vst1.32         {d1[0]},  [r1], r2\n        vadd.u8         d3,  d2,  d7\n        vst1.32         {d2[0]},  [r1], r2\n        vst1.32         {d3[0]},  [r1], r2\n        subs            r3,  r3,  #12\n        bgt             1b\n\n        bx              lr\nendfunc\n\nfunc    png_read_filter_row_up_neon, export=1\n        ldr             r3,  [r0, #4]           @ rowbytes\n1:\n        vld1.8          {q0}, [r1,:128]\n        vld1.8          {q1}, [r2,:128]!\n        vadd.u8         q0,  q0,  q1\n        vst1.8          {q0}, [r1,:128]!\n        subs            r3,  r3,  #16\n        bgt             1b\n\n        bx              lr\nendfunc\n\nfunc    png_read_filter_row_avg4_neon, export=1\n        ldr             r12, [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n1:\n        vld4.32         {d4[],d5[],d6[],d7[]},    [r1,:128]\n        vld4.32         {d16[],d17[],d18[],d19[]},[r2,:128]!\n        vhadd.u8        d0,  d3,  d16\n        vadd.u8         d0,  d0,  d4\n        vhadd.u8        d1,  d0,  d17\n        vadd.u8         d1,  d1,  d5\n        vhadd.u8        d2,  d1,  d18\n        vadd.u8         d2,  d2,  d6\n        vhadd.u8        d3,  d2,  d19\n        vadd.u8         d3,  d3,  d7\n        vst4.32         {d0[0],d1[0],d2[0],d3[0]},[r1,:128]!\n        subs            r12, r12, #16\n        bgt             1b\n\n        bx              lr\nendfunc\n\nfunc    png_read_filter_row_avg3_neon, export=1\n        push            {r4,lr}\n        ldr             r12, [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n        mov             r0,  r1\n        mov             r4,  #3\n        mov             lr,  #12\n        vld1.8          {q11},    [r0], lr\n1:\n        vld1.8          {q10},    [r2], lr\n        vext.8          d5,  d22, d23, #3\n        vhadd.u8        d0,  d3,  d20\n        vext.8          d17, d20, d21, #3\n        vadd.u8         d0,  d0,  d22\n        vext.8          d6,  d22, d23, #6\n        vhadd.u8        d1,  d0,  d17\n        vext.8          d18, d20, d21, #6\n        vadd.u8         d1,  d1,  d5\n        vext.8          d7,  d23, d23, #1\n        vld1.8          {q11},    [r0], lr\n        vst1.32         {d0[0]},  [r1,:32], r4\n        vhadd.u8        d2,  d1,  d18\n        vst1.32         {d1[0]},  [r1], r4\n        vext.8          d19, d21, d21, #1\n        vadd.u8         d2,  d2,  d6\n        vhadd.u8        d3,  d2,  d19\n        vst1.32         {d2[0]},  [r1], r4\n        vadd.u8         d3,  d3,  d7\n        vst1.32         {d3[0]},  [r1], r4\n        subs            r12, r12, #12\n        bgt             1b\n\n        pop             {r4,pc}\nendfunc\n\n.macro  paeth           rx,  ra,  rb,  rc\n        vaddl.u8        q12, \\ra, \\rb           @ a + b\n        vaddl.u8        q15, \\rc, \\rc           @ 2*c\n        vabdl.u8        q13, \\rb, \\rc           @ pa\n        vabdl.u8        q14, \\ra, \\rc           @ pb\n        vabd.u16        q15, q12, q15           @ pc\n        vcle.u16        q12, q13, q14           @ pa <= pb\n        vcle.u16        q13, q13, q15           @ pa <= pc\n        vcle.u16        q14, q14, q15           @ pb <= pc\n        vand            q12, q12, q13           @ pa <= pb && pa <= pc\n        vmovn.u16       d28, q14\n        vmovn.u16       \\rx, q12\n        vbsl            d28, \\rb, \\rc\n        vbsl            \\rx, \\ra, d28\n.endm\n\nfunc    png_read_filter_row_paeth4_neon, export=1\n        ldr             r12, [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n        vmov.i8         d20, #0\n1:\n        vld4.32         {d4[],d5[],d6[],d7[]},    [r1,:128]\n        vld4.32         {d16[],d17[],d18[],d19[]},[r2,:128]!\n        paeth           d0,  d3,  d16, d20\n        vadd.u8         d0,  d0,  d4\n        paeth           d1,  d0,  d17, d16\n        vadd.u8         d1,  d1,  d5\n        paeth           d2,  d1,  d18, d17\n        vadd.u8         d2,  d2,  d6\n        paeth           d3,  d2,  d19, d18\n        vmov            d20, d19\n        vadd.u8         d3,  d3,  d7\n        vst4.32         {d0[0],d1[0],d2[0],d3[0]},[r1,:128]!\n        subs            r12, r12, #16\n        bgt             1b\n\n        bx              lr\nendfunc\n\nfunc    png_read_filter_row_paeth3_neon, export=1\n        push            {r4,lr}\n        ldr             r12, [r0, #4]           @ rowbytes\n        vmov.i8         d3,  #0\n        vmov.i8         d4,  #0\n        mov             r0,  r1\n        mov             r4,  #3\n        mov             lr,  #12\n        vld1.8          {q11},    [r0], lr\n1:\n        vld1.8          {q10},    [r2], lr\n        paeth           d0,  d3,  d20, d4\n        vext.8          d5,  d22, d23, #3\n        vadd.u8         d0,  d0,  d22\n        vext.8          d17, d20, d21, #3\n        paeth           d1,  d0,  d17, d20\n        vst1.32         {d0[0]},  [r1,:32], r4\n        vext.8          d6,  d22, d23, #6\n        vadd.u8         d1,  d1,  d5\n        vext.8          d18, d20, d21, #6\n        paeth           d2,  d1,  d18, d17\n        vext.8          d7,  d23, d23, #1\n        vld1.8          {q11},    [r0], lr\n        vst1.32         {d1[0]},  [r1], r4\n        vadd.u8         d2,  d2,  d6\n        vext.8          d19, d21, d21, #1\n        paeth           d3,  d2,  d19, d18\n        vst1.32         {d2[0]},  [r1], r4\n        vmov            d4,  d19\n        vadd.u8         d3,  d3,  d7\n        vst1.32         {d3[0]},  [r1], r4\n        subs            r12, r12, #12\n        bgt             1b\n\n        pop             {r4,pc}\nendfunc\n#endif /* PNG_ARM_NEON_OPT > 0 */\n#endif /* PNG_ARM_NEON_IMPLEMENTATION == 2 (assembler) */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/arm/filter_neon_intrinsics.c",
    "content": "\n/* filter_neon_intrinsics.c - NEON optimised filter functions\n *\n * Copyright (c) 2014,2016 Glenn Randers-Pehrson\n * Written by James Yu <james.yu at linaro.org>, October 2013.\n * Based on filter_neon.S, written by Mans Rullgard, 2011.\n *\n * Last changed in libpng 1.6.22 [May 26, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n/* This code requires -mfpu=neon on the command line: */\n#if PNG_ARM_NEON_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */\n\n#include <arm_neon.h>\n\n/* libpng row pointers are not necessarily aligned to any particular boundary,\n * however this code will only work with appropriate alignment.  arm/arm_init.c\n * checks for this (and will not compile unless it is done). This code uses\n * variants of png_aligncast to avoid compiler warnings.\n */\n#define png_ptr(type,pointer) png_aligncast(type *,pointer)\n#define png_ptrc(type,pointer) png_aligncastconst(const type *,pointer)\n\n/* The following relies on a variable 'temp_pointer' being declared with type\n * 'type'.  This is written this way just to hide the GCC strict aliasing\n * warning; note that the code is safe because there never is an alias between\n * the input and output pointers.\n */\n#define png_ldr(type,pointer)\\\n   (temp_pointer = png_ptr(type,pointer), *temp_pointer)\n\n#if PNG_ARM_NEON_OPT > 0\n\nvoid\npng_read_filter_row_up_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n   png_const_bytep pp = prev_row;\n\n   png_debug(1, \"in png_read_filter_row_up_neon\");\n\n   for (; rp < rp_stop; rp += 16, pp += 16)\n   {\n      uint8x16_t qrp, qpp;\n\n      qrp = vld1q_u8(rp);\n      qpp = vld1q_u8(pp);\n      qrp = vaddq_u8(qrp, qpp);\n      vst1q_u8(rp, qrp);\n   }\n}\n\nvoid\npng_read_filter_row_sub3_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n\n   uint8x16_t vtmp = vld1q_u8(rp);\n   uint8x8x2_t *vrpt = png_ptr(uint8x8x2_t, &vtmp);\n   uint8x8x2_t vrp = *vrpt;\n\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   png_debug(1, \"in png_read_filter_row_sub3_neon\");\n\n   for (; rp < rp_stop;)\n   {\n      uint8x8_t vtmp1, vtmp2;\n      uint32x2_t *temp_pointer;\n\n      vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);\n      vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);\n      vtmp2 = vext_u8(vrp.val[0], vrp.val[1], 6);\n      vdest.val[1] = vadd_u8(vdest.val[0], vtmp1);\n\n      vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);\n      vdest.val[2] = vadd_u8(vdest.val[1], vtmp2);\n      vdest.val[3] = vadd_u8(vdest.val[2], vtmp1);\n\n      vtmp = vld1q_u8(rp + 12);\n      vrpt = png_ptr(uint8x8x2_t, &vtmp);\n      vrp = *vrpt;\n\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);\n      rp += 3;\n   }\n\n   PNG_UNUSED(prev_row)\n}\n\nvoid\npng_read_filter_row_sub4_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   png_debug(1, \"in png_read_filter_row_sub4_neon\");\n\n   for (; rp < rp_stop; rp += 16)\n   {\n      uint32x2x4_t vtmp = vld4_u32(png_ptr(uint32_t,rp));\n      uint8x8x4_t *vrpt = png_ptr(uint8x8x4_t,&vtmp);\n      uint8x8x4_t vrp = *vrpt;\n      uint32x2x4_t *temp_pointer;\n\n      vdest.val[0] = vadd_u8(vdest.val[3], vrp.val[0]);\n      vdest.val[1] = vadd_u8(vdest.val[0], vrp.val[1]);\n      vdest.val[2] = vadd_u8(vdest.val[1], vrp.val[2]);\n      vdest.val[3] = vadd_u8(vdest.val[2], vrp.val[3]);\n      vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);\n   }\n\n   PNG_UNUSED(prev_row)\n}\n\nvoid\npng_read_filter_row_avg3_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_const_bytep pp = prev_row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n\n   uint8x16_t vtmp;\n   uint8x8x2_t *vrpt;\n   uint8x8x2_t vrp;\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   vtmp = vld1q_u8(rp);\n   vrpt = png_ptr(uint8x8x2_t,&vtmp);\n   vrp = *vrpt;\n\n   png_debug(1, \"in png_read_filter_row_avg3_neon\");\n\n   for (; rp < rp_stop; pp += 12)\n   {\n      uint8x8_t vtmp1, vtmp2, vtmp3;\n\n      uint8x8x2_t *vppt;\n      uint8x8x2_t vpp;\n\n      uint32x2_t *temp_pointer;\n\n      vtmp = vld1q_u8(pp);\n      vppt = png_ptr(uint8x8x2_t,&vtmp);\n      vpp = *vppt;\n\n      vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);\n      vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);\n      vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);\n\n      vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);\n      vtmp3 = vext_u8(vrp.val[0], vrp.val[1], 6);\n      vdest.val[1] = vhadd_u8(vdest.val[0], vtmp2);\n      vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);\n\n      vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 6);\n      vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);\n\n      vtmp = vld1q_u8(rp + 12);\n      vrpt = png_ptr(uint8x8x2_t,&vtmp);\n      vrp = *vrpt;\n\n      vdest.val[2] = vhadd_u8(vdest.val[1], vtmp2);\n      vdest.val[2] = vadd_u8(vdest.val[2], vtmp3);\n\n      vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);\n\n      vdest.val[3] = vhadd_u8(vdest.val[2], vtmp2);\n      vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);\n\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);\n      rp += 3;\n   }\n}\n\nvoid\npng_read_filter_row_avg4_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n   png_const_bytep pp = prev_row;\n\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   png_debug(1, \"in png_read_filter_row_avg4_neon\");\n\n   for (; rp < rp_stop; rp += 16, pp += 16)\n   {\n      uint32x2x4_t vtmp;\n      uint8x8x4_t *vrpt, *vppt;\n      uint8x8x4_t vrp, vpp;\n      uint32x2x4_t *temp_pointer;\n\n      vtmp = vld4_u32(png_ptr(uint32_t,rp));\n      vrpt = png_ptr(uint8x8x4_t,&vtmp);\n      vrp = *vrpt;\n      vtmp = vld4_u32(png_ptrc(uint32_t,pp));\n      vppt = png_ptr(uint8x8x4_t,&vtmp);\n      vpp = *vppt;\n\n      vdest.val[0] = vhadd_u8(vdest.val[3], vpp.val[0]);\n      vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);\n      vdest.val[1] = vhadd_u8(vdest.val[0], vpp.val[1]);\n      vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);\n      vdest.val[2] = vhadd_u8(vdest.val[1], vpp.val[2]);\n      vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);\n      vdest.val[3] = vhadd_u8(vdest.val[2], vpp.val[3]);\n      vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);\n\n      vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);\n   }\n}\n\nstatic uint8x8_t\npaeth(uint8x8_t a, uint8x8_t b, uint8x8_t c)\n{\n   uint8x8_t d, e;\n   uint16x8_t p1, pa, pb, pc;\n\n   p1 = vaddl_u8(a, b); /* a + b */\n   pc = vaddl_u8(c, c); /* c * 2 */\n   pa = vabdl_u8(b, c); /* pa */\n   pb = vabdl_u8(a, c); /* pb */\n   pc = vabdq_u16(p1, pc); /* pc */\n\n   p1 = vcleq_u16(pa, pb); /* pa <= pb */\n   pa = vcleq_u16(pa, pc); /* pa <= pc */\n   pb = vcleq_u16(pb, pc); /* pb <= pc */\n\n   p1 = vandq_u16(p1, pa); /* pa <= pb && pa <= pc */\n\n   d = vmovn_u16(pb);\n   e = vmovn_u16(p1);\n\n   d = vbsl_u8(d, b, c);\n   e = vbsl_u8(e, a, d);\n\n   return e;\n}\n\nvoid\npng_read_filter_row_paeth3_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_const_bytep pp = prev_row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n\n   uint8x16_t vtmp;\n   uint8x8x2_t *vrpt;\n   uint8x8x2_t vrp;\n   uint8x8_t vlast = vdup_n_u8(0);\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   vtmp = vld1q_u8(rp);\n   vrpt = png_ptr(uint8x8x2_t,&vtmp);\n   vrp = *vrpt;\n\n   png_debug(1, \"in png_read_filter_row_paeth3_neon\");\n\n   for (; rp < rp_stop; pp += 12)\n   {\n      uint8x8x2_t *vppt;\n      uint8x8x2_t vpp;\n      uint8x8_t vtmp1, vtmp2, vtmp3;\n      uint32x2_t *temp_pointer;\n\n      vtmp = vld1q_u8(pp);\n      vppt = png_ptr(uint8x8x2_t,&vtmp);\n      vpp = *vppt;\n\n      vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);\n      vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);\n\n      vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 3);\n      vtmp2 = vext_u8(vpp.val[0], vpp.val[1], 3);\n      vdest.val[1] = paeth(vdest.val[0], vtmp2, vpp.val[0]);\n      vdest.val[1] = vadd_u8(vdest.val[1], vtmp1);\n\n      vtmp1 = vext_u8(vrp.val[0], vrp.val[1], 6);\n      vtmp3 = vext_u8(vpp.val[0], vpp.val[1], 6);\n      vdest.val[2] = paeth(vdest.val[1], vtmp3, vtmp2);\n      vdest.val[2] = vadd_u8(vdest.val[2], vtmp1);\n\n      vtmp1 = vext_u8(vrp.val[1], vrp.val[1], 1);\n      vtmp2 = vext_u8(vpp.val[1], vpp.val[1], 1);\n\n      vtmp = vld1q_u8(rp + 12);\n      vrpt = png_ptr(uint8x8x2_t,&vtmp);\n      vrp = *vrpt;\n\n      vdest.val[3] = paeth(vdest.val[2], vtmp2, vtmp3);\n      vdest.val[3] = vadd_u8(vdest.val[3], vtmp1);\n\n      vlast = vtmp2;\n\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[0]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[1]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[2]), 0);\n      rp += 3;\n      vst1_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2_t,&vdest.val[3]), 0);\n      rp += 3;\n   }\n}\n\nvoid\npng_read_filter_row_paeth4_neon(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev_row)\n{\n   png_bytep rp = row;\n   png_bytep rp_stop = row + row_info->rowbytes;\n   png_const_bytep pp = prev_row;\n\n   uint8x8_t vlast = vdup_n_u8(0);\n   uint8x8x4_t vdest;\n   vdest.val[3] = vdup_n_u8(0);\n\n   png_debug(1, \"in png_read_filter_row_paeth4_neon\");\n\n   for (; rp < rp_stop; rp += 16, pp += 16)\n   {\n      uint32x2x4_t vtmp;\n      uint8x8x4_t *vrpt, *vppt;\n      uint8x8x4_t vrp, vpp;\n      uint32x2x4_t *temp_pointer;\n\n      vtmp = vld4_u32(png_ptr(uint32_t,rp));\n      vrpt = png_ptr(uint8x8x4_t,&vtmp);\n      vrp = *vrpt;\n      vtmp = vld4_u32(png_ptrc(uint32_t,pp));\n      vppt = png_ptr(uint8x8x4_t,&vtmp);\n      vpp = *vppt;\n\n      vdest.val[0] = paeth(vdest.val[3], vpp.val[0], vlast);\n      vdest.val[0] = vadd_u8(vdest.val[0], vrp.val[0]);\n      vdest.val[1] = paeth(vdest.val[0], vpp.val[1], vpp.val[0]);\n      vdest.val[1] = vadd_u8(vdest.val[1], vrp.val[1]);\n      vdest.val[2] = paeth(vdest.val[1], vpp.val[2], vpp.val[1]);\n      vdest.val[2] = vadd_u8(vdest.val[2], vrp.val[2]);\n      vdest.val[3] = paeth(vdest.val[2], vpp.val[3], vpp.val[2]);\n      vdest.val[3] = vadd_u8(vdest.val[3], vrp.val[3]);\n\n      vlast = vpp.val[3];\n\n      vst4_lane_u32(png_ptr(uint32_t,rp), png_ldr(uint32x2x4_t,&vdest), 0);\n   }\n}\n\n#endif /* PNG_ARM_NEON_OPT > 0 */\n#endif /* PNG_ARM_NEON_IMPLEMENTATION == 1 (intrinsics) */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/autogen.sh",
    "content": "#! /bin/sh\n#\n# Run 'autoreconf' to build 'configure', 'Makefile.in' and other configure\n# control files.\n#\n# The first time this is run on a GIT checkout the only files that exist are\n# configure.ac and Makefile.am; all of the autotools support scripts are\n# missing.  They are instantiated with autoreconf --force --install.\n#\n# For regular (\"tarball\") distributions all the files should exist.  We do not\n# want them to be updated *under any circumstances*.  It should never be\n# necessary to run autogen.sh because ./configure --enable-maintainer-mode says\n# what to do if Makefile.am or configure.ac are changed.\n#\n# It is *probably* OK to update the files on a GIT checkout, because they have\n# come from the local tools, but leave that to the user who is assumed to know\n# whether it is ok or required.\n#\n# This script is intended to work without arguments, there are, however, hidden\n# arguments (a) for use while testing the script and (b) to fix up systems that\n# have been broken.  If (b) is required the script prompts for the correct\n# options.  For this reason the options are *NOT* documented in the help; this\n# is deliberate; UTSL.\n#\nclean=\nmaintainer=\nwhile test $# -gt 0\ndo\n   case \"$1\" in\n      --maintainer)\n         maintainer=1;;\n\n      --clean)\n         clean=1;;\n\n      *)\n         exec >&2\n         echo \"$0: usage: ./autogen.sh\"\n         if test -d .git\n         then\n            echo \"  ./autogen.sh generates the configure script and\"\n            echo \"  Makefile.in, or refreshes them after changes to Makefile.am\"\n            echo \"  or configure.ac.  You may prefer to just run autoreconf.\"\n         elif test -z \"$maintainer\"\n         then\n            echo \"  DO NOT RUN THIS SCRIPT.\"\n            echo \"  If you need to change Makefile.am or configure.ac then you\"\n            echo \"  also need to run ./configure --enable-maintainer-mode and\"\n            echo \"  use the appropriate autotools, *NOT* this script, to update\"\n            echo \"  everything, please check the documentation of autoreconf.\"\n            echo \"  WARNING: libpng is intentionally generated with a known,\"\n            echo \"  fixed, set of autotools.  It is known *NOT* to work with\"\n            echo \"  the collection of autotools distributed on highly reputable\"\n            echo \"  operating systems.\"\n            echo \"  Remember: autotools is GNU software, you are expected to\"\n            echo \"  pay for support.\"\n         else\n            echo \"  You have run autogen.sh with --maintainer enabled and you\"\n            echo \"  are not using a GIT distribution, then you have given an\"\n            echo \"  unrecognized argument.  This is not good. --maintainer\"\n            echo \"  switches off any assumptions that you might not know what\"\n            echo \"  you are doing.\"\n         fi\n         exit 1;;\n   esac\n\n   shift\ndone\n#\n# First check for a set of the autotools files; if absent then this is assumed\n# to be a GIT version and the local autotools must be used.  If present this\n# is a tarball distribution and the script should not be used.  If partially\n# present bad things are happening.\n#\n# The autotools generated files:\nlibpng_autotools_files=\"Makefile.in aclocal.m4 config.guess config.h.in\n   config.sub configure depcomp install-sh ltmain.sh missing\\\n   test-driver\"\n#\n# Files generated by versions of configue >2.68 or automake >1.13 (i.e. later\n# versions than those required by configure.ac):\nlibpng_autotools_extra=\"compile config.h.in~\"\n#\n# These are separate because 'maintainer-clean' does not remove them.\nlibpng_libtool_files=\"scripts/libtool.m4 scripts/ltoptions.m4\\\n   scripts/ltsugar.m4 scripts/ltversion.m4 scripts/lt~obsolete.m4\"\n\nlibpng_autotools_dirs=\"autom4te.cache\" # not required\n#\n# The configure generated files:\nlibpng_configure_files=\"Makefile config.h config.log config.status\\\n   libpng-config libpng.pc libtool stamp-h1\"\n\nlibpng_configure_dirs=\".deps\"\n#\n# We must remove the configure generated files as well as the autotools\n# generated files if autotools are regenerated because otherwise if configure\n# has been run without \"--enable-maintainer-mode\" make can do a partial update\n# of Makefile.  These functions do the two bits of cleaning.\nclean_autotools(){\n   rm -rf $libpng_autotools_files $libpng_libtool_files $libpng_autotools_dirs\n   rm -rf $libpng_autotools_extra\n}\n\nclean_configure(){\n   rm -rf $libpng_configure_files $libpng_configure_dirs\n}\n#\n# Clean: remove everything (this is to help with testing)\nif test -n \"$clean\"\nthen\n   clean_configure\n   if test -n \"$maintainer\"\n   then\n      clean_autotools\n   fi\n\n   exit 0\nfi\n#\n# Validate the distribution.\nlibpng_autotools_file_found=\nlibpng_autotools_file_missing=\nfor file in $libpng_autotools_files\ndo\n   if test -f  \"$file\"\n   then\n      libpng_autotools_file_found=1\n   else\n      libpng_autotools_file_missing=1\n   fi\ndone\n#\n# Presence of one of these does not *invalidate* missing, but absence\n# invalidates found.\nfor file in $libpng_libtool_files\ndo\n   if test ! -f \"$file\"\n   then\n      libpng_autotools_file_missing=1\n   fi\ndone\n#\n# The cache directory doesn't matter - it will be regenerated and does not exist\n# anyway in a tarball.\n#\n# Either everything is missing or everything is there, the --maintainer option\n# just changes this so that the mode is set to generate all the files.\nmode=\nif test -z \"$libpng_autotools_file_found\" -o -n \"$maintainer\"\nthen\n   mode=\"autoreconf\"\nelse\n   if test -n \"$libpng_autotools_file_missing\"\n   then\n      mode=\"broken\"\n   else\n      mode=\"configure\"\n   fi\nfi\n#\n# So:\ncase \"$mode\" in\n   autoreconf)\n      # Clean in case configure files exist\n      clean_configure\n      clean_autotools\n      # Everything must be initialized, so use --force\n      if autoreconf --warnings=all --force --install\n      then\n         missing=\n         for file in $libpng_autotools_files\n         do\n            test -f \"$file\" || missing=1\n         done\n         # ignore the cache directory\n         test -z \"$missing\" || {\n            exec >&2\n            echo \"autoreconf was run, but did not produce all the expected\"\n            echo \"files.  It is likely that your autotools installation is\"\n            echo \"not compatible with that expected by libpng.\"\n            exit 1\n         }\n      else\n         exec >&2\n         echo \"autoreconf failed: your version of autotools is incompatible\"\n         echo \"with this libpng version.  Please use a distributed archive\"\n         echo \"(which includes the autotools generated files) and run configure\"\n         echo \"instead.\"\n         exit 1\n      fi;;\n\n   configure)\n      if test -d .git\n      then\n         exec >&2\n         echo \"ERROR: running autoreconf on an initialized sytem\"\n         echo \"  This is not necessary; it is only necessary to remake the\"\n         echo \"  autotools generated files if Makefile.am or configure.ac\"\n         echo \"  change and make does the right thing with:\"\n         echo\n         echo \"     ./configure --enable-maintainer-mode.\"\n         echo\n         echo \"  You can run autoreconf yourself if you don't like maintainer\"\n         echo \"  mode and you can also just run autoreconf -f -i to initialize\"\n         echo \"  everything in the first place; this script is only for\"\n         echo \"  compatibility with prior releases.\"\n         exit 1\n      else\n         exec >&2\n         echo \"autogen.sh is intended only to generate 'configure' on systems\"\n         echo \"that do not have it.  You have a complete 'configure', if you\"\n         echo \"need to change Makefile.am or configure.ac you also need to\"\n         echo \"run configure with the --enable-maintainer-mode option.\"\n         exit 1\n      fi;;\n\n   broken)\n      exec >&2\n      echo \"Your system has a partial set of autotools generated files.\"\n      echo \"autogen.sh is unable to proceed.  The full set of files is\"\n      echo \"contained in the libpng 'tar' distribution archive and you do\"\n      echo \"not need to run autogen.sh if you use it.\"\n      exit 1;;\nesac\n"
  },
  {
    "path": "tess-two/jni/libpng/configure.ac",
    "content": "# configure.ac\n\n# Copyright (c) 2004-2016 Glenn Randers-Pehrson\n# Last changed in libpng 1.6.25 [September 1, 2016]\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\ndnl Process this file with autoconf to produce a configure script.\ndnl\ndnl Minor upgrades (compatible ABI): increment the package version\ndnl (third field in two places below) and set the PNGLIB_RELEASE\ndnl variable.\ndnl\ndnl Major upgrades (incompatible ABI): increment the package major\ndnl version (second field, or first if desired), set the minor\ndnl to 0, set PNGLIB_MAJOR below *and* follow the instructions in\ndnl Makefile.am to upgrade the package name.\n\ndnl This is here to prevent earlier autoconf from being used, it\ndnl should not be necessary to regenerate configure if the time\ndnl stamps are correct\nAC_PREREQ([2.68])\n\ndnl Version number stuff here:\n\nAC_INIT([libpng],[1.6.25],[png-mng-implement@lists.sourceforge.net])\nAC_CONFIG_MACRO_DIR([scripts])\n\n# libpng does not follow GNU file name conventions (hence 'foreign')\n# color-tests requires automake 1.11 or later\n# silent-rules requires automake 1.11 or later\n# dist-xz requires automake 1.11 or later\n# 1.12.2 fixes a security issue in 1.11.2 and 1.12.1\n# 1.13 is required for parallel tests\nAM_INIT_AUTOMAKE([1.13 foreign dist-xz color-tests silent-rules subdir-objects])\n# The following line causes --disable-maintainer-mode to be the default to\n# configure. This is necessary because libpng distributions cannot rely on the\n# time stamps of the autotools generated files being correct\nAM_MAINTAINER_MODE\n\ndnl configure.ac and Makefile.am expect automake 1.11.2 or a compatible later\ndnl version; aclocal.m4 will generate a failure if you use a prior version of\ndnl automake, so the following is not necessary (and is not defined anyway):\ndnl AM_PREREQ([1.11.2])\ndnl stop configure from automagically running automake\n\nPNGLIB_VERSION=1.6.25\nPNGLIB_MAJOR=1\nPNGLIB_MINOR=6\nPNGLIB_RELEASE=25\n\ndnl End of version number stuff\n\nAC_CONFIG_SRCDIR([pngget.c])\nAC_CONFIG_HEADERS([config.h])\n\n# Checks for programs.\nAC_LANG([C])\nAC_PROG_CC\nAM_PROG_AS\nLT_PATH_LD\nAC_PROG_CPP\nAC_PROG_AWK\nAC_PROG_INSTALL\nAC_PROG_LN_S\nAC_PROG_MAKE_SET\n\ndnl libtool/libtoolize; version 2.4.2 is the tested version. This or any\ndnl compatible later version may be used\nLT_INIT([win32-dll])\nLT_PREREQ([2.4.2])\n\n# Some awks crash when confronted with pnglibconf.dfa, do a test run now\n# to make sure this doesn't happen\nAC_MSG_CHECKING([that AWK works])\nif ${AWK} -f ${srcdir}/scripts/options.awk out=\"/dev/null\" version=search\\\n   ${srcdir}/pngconf.h ${srcdir}/scripts/pnglibconf.dfa\\\n   ${srcdir}/pngusr.dfa 1>&2\nthen\n   AC_MSG_RESULT([ok])\nelse\n   AC_MSG_FAILURE([failed], 1)\nfi\n\n# This is a remnant of the old cc -E validation, where it may have been\n# necessary to use a different preprocessor for .dfn files\nDFNCPP=\"$CPP\"\nAC_SUBST(DFNCPP)\n\n# -Werror cannot be passed to GCC in CFLAGS because configure will fail (it\n# checks the compiler with a program that generates a warning), add the\n# following option to deal with this\nAC_ARG_VAR(PNG_COPTS,\n   [additional flags for the C compiler, use this for options that would]\n   [cause configure itself to fail])\nAC_ARG_ENABLE(werror,\n   AS_HELP_STRING([[[--enable-werror[=OPT]]]],\n      [Pass -Werror or the given argument to the compiler if it is supported]),\n   [test \"$enable_werror\" = \"yes\" && enable_werror=\"-Werror\"\n    if test \"$enable_werror\" != \"no\"; then\n      sav_CFLAGS=\"$CFLAGS\"\n      CFLAGS=\"$enable_werror $CFLAGS\"\n      AC_MSG_CHECKING([if the compiler allows $enable_werror])\n      AC_COMPILE_IFELSE(\n         [AC_LANG_SOURCE([\n            [int main(int argc, char **argv){]\n            [return argv[argc-1][0];]\n            [}]])],\n         AC_MSG_RESULT(yes)\n         PNG_COPTS=\"$PNG_COPTS $enable_werror\",\n         AC_MSG_RESULT(no))\n      CFLAGS=\"$sav_CFLAGS\"\n    fi],)\n\n# For GCC 5 the default mode for C is -std=gnu11 instead of -std=gnu89\n# In pngpriv.h we request just the POSIX 1003.1 and C89 APIs by defining _POSIX_SOURCE to 1\n# This is incompatible with the new default mode, so we test for that and force the \n# \"-std=c89\" compiler option:\nAC_MSG_CHECKING([if we need to force back C standard to C89])\nAC_COMPILE_IFELSE(\n   [AC_LANG_PROGRAM([\n      [#define _POSIX_SOURCE 1]\n      [#include <stdio.h>]\n   ])],\n   AC_MSG_RESULT(no),[\n      if test \"x$GCC\" != \"xyes\"; then\n         AC_MSG_ERROR(\n            [Forcing back to C89 is required but the flags are only known for GCC])\n      fi\n   AC_MSG_RESULT(yes)\n   CFLAGS=\"$CFLAGS -std=c89\"\n])\n\n# Checks for header files.\nAC_HEADER_STDC\n\n# Checks for typedefs, structures, and compiler characteristics.\nAC_C_CONST\nAC_TYPE_SIZE_T\nAC_STRUCT_TM\nAC_C_RESTRICT\n\n# Checks for library functions.\nAC_FUNC_STRTOD\nAC_CHECK_FUNCS([memset], , AC_MSG_ERROR(memset not found in libc))\nAC_CHECK_FUNCS([pow], , AC_CHECK_LIB(m, pow, , AC_MSG_ERROR(cannot find pow)) )\n\n# Some later POSIX 1003.1 functions are required for test programs, failure here\n# is soft (the corresponding test program is not built).\nAC_CHECK_FUNC([clock_gettime],,[AC_MSG_WARN([not building timepng])])\nAM_CONDITIONAL([HAVE_CLOCK_GETTIME], [test \"$ac_cv_func_clock_gettime\" = \"yes\"])\n\nAC_ARG_WITH(zlib-prefix,\n   AS_HELP_STRING([[[--with-zlib-prefix]]],\n      [prefix that may have been used in installed zlib]),\n      [ZPREFIX=${withval}],\n      [ZPREFIX='z_'])\nAC_CHECK_LIB(z, zlibVersion, ,\n    AC_CHECK_LIB(z, ${ZPREFIX}zlibVersion, , AC_MSG_ERROR(zlib not installed)))\n\n# The following is for pngvalid, to ensure it catches FP errors even on\n# platforms that don't enable FP exceptions, the function appears in the math\n# library (typically), it's not an error if it is not found.\nAC_CHECK_LIB([m], [feenableexcept])\nAC_CHECK_FUNCS([feenableexcept])\n\nAC_MSG_CHECKING([if using Solaris linker])\nSLD=`$LD --version 2>&1 | grep Solaris`\nif test \"$SLD\"; then\n    have_solaris_ld=yes\n    AC_MSG_RESULT(yes)\nelse\n    have_solaris_ld=no\n    AC_MSG_RESULT(no)\nfi\nAM_CONDITIONAL(HAVE_SOLARIS_LD, test \"$have_solaris_ld\" = \"yes\")\n\nAC_MSG_CHECKING([if libraries can be versioned])\n# Special case for PE/COFF platforms: ld reports\n# support for version-script, but doesn't actually\n# DO anything with it.\ncase $host in\n*cygwin* | *mingw32* | *interix* )\n    have_ld_version_script=no\n    AC_MSG_RESULT(no)\n;;\n* )\n\nif test \"$have_solaris_ld\" = \"yes\"; then\n    GLD=`$LD --help < /dev/null 2>&1 | grep 'M mapfile'`\nelse\n    GLD=`$LD --help < /dev/null 2>/dev/null | grep version-script`\nfi\n\nif test \"$GLD\"; then\n    have_ld_version_script=yes\n    AC_MSG_RESULT(yes)\nelse\n    have_ld_version_script=no\n    AC_MSG_RESULT(no)\n    AC_MSG_WARN(*** You have not enabled versioned symbols.)\nfi\n;;\nesac\n\nAM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test \"$have_ld_version_script\" = \"yes\")\n\nif test \"$have_ld_version_script\" = \"yes\"; then\n    AC_MSG_CHECKING([for symbol prefix])\n    SYMBOL_PREFIX=`echo \"PREFIX=__USER_LABEL_PREFIX__\" \\\n                  | ${CPP-${CC-gcc} -E} - 2>&1 \\\n                  | ${EGREP-grep} \"^PREFIX=\" \\\n                  | ${SED-sed} -e \"s:^PREFIX=::\" -e \"s:__USER_LABEL_PREFIX__::\"`\n    AC_SUBST(SYMBOL_PREFIX)\n    AC_MSG_RESULT($SYMBOL_PREFIX)\nfi\n\n# Substitutions for .in files\nAC_SUBST(PNGLIB_VERSION)\nAC_SUBST(PNGLIB_MAJOR)\nAC_SUBST(PNGLIB_MINOR)\nAC_SUBST(PNGLIB_RELEASE)\n\n# Additional arguments (and substitutions)\n# Allow the pkg-config directory to be set\nAC_ARG_WITH(pkgconfigdir,\n   AS_HELP_STRING([[[--with-pkgconfigdir]]],\n      [Use the specified pkgconfig dir (default is libdir/pkgconfig)]),\n   [pkgconfigdir=${withval}],\n   [pkgconfigdir='${libdir}/pkgconfig'])\n\nAC_SUBST([pkgconfigdir])\nAC_MSG_NOTICE([[pkgconfig directory is ${pkgconfigdir}]])\n\n# Make the *-config binary config scripts optional\nAC_ARG_WITH(binconfigs,\n   AS_HELP_STRING([[[--with-binconfigs]]],\n      [Generate shell libpng-config scripts as well as pkg-config data]\n      [@<:@default=yes@:>@]),\n   [if test \"${withval}\" = no; then\n      binconfigs=\n      AC_MSG_NOTICE([[libpng-config scripts will not be built]])\n    else\n      binconfigs='${binconfigs}'\n    fi],\n   [binconfigs='${binconfigs}'])\nAC_SUBST([binconfigs])\n\n# Support for prefixes to the API function names; this will generate defines\n# at the start of the build to rename exported library functions\nAC_ARG_WITH(libpng-prefix,\n   AS_HELP_STRING([[[--with-libpng-prefix]]],\n      [prefix libpng exported function (API) names with the given value]),\n   [if test \"${withval:-no}\" != \"no\"; then\n      AC_SUBST([PNG_PREFIX], [${withval}])\n    fi])\nAM_CONDITIONAL([DO_PNG_PREFIX], [test \"${with_libpng_prefix:-no}\" != \"no\"])\n\n# Control over what links are made for installed files.  Versioned files are\n# always installed, when the following options are turned on corresponding\n# unversioned links are also created (normally as symbolic links):\nAC_ARG_ENABLE([unversioned-links],\n   AS_HELP_STRING([[[--enable-unversioned-links]]],\n      [Installed libpng header files are placed in a versioned subdirectory]\n      [and installed libpng library (including DLL) files are versioned.]\n      [If this option is enabled unversioned links will be created pointing to]\n      [the corresponding installed files.  If you use libpng.pc or]\n      [libpng-config for all builds you do not need these links, but if you]\n      [compile programs directly they will typically #include <png.h> and]\n      [link with -lpng; in that case you need the links.]\n      [The links can be installed manually using 'make install-header-links']\n      [and 'make install-library-links' and can be removed using the]\n      [corresponding uninstall- targets.  If you do enable this option every]\n      [libpng 'make install' will recreate the links to point to the just]\n      [installed version of libpng.  The default is to create the links;]\n      [use --disable-unversioned-links to change this]))\n\n# The AM_CONDITIONAL test is written so that the default is enabled;\n# --disable-unversioned-links must be given to turn the option off.\nAM_CONDITIONAL([DO_INSTALL_LINKS],[test \"$enable_unversioned_links\" != \"no\"])\n\nAC_ARG_ENABLE([unversioned-libpng-pc],\n   AS_HELP_STRING([[[--enable-unversioned-libpng-pc]]],\n      [Install the configuration file 'libpng.pc' as a link to the versioned]\n      [version.  This is done by default - use --disable-unversioned-libpng-pc]\n      [to change this.]))\nAM_CONDITIONAL([DO_INSTALL_LIBPNG_PC],\n   [test \"$enable_unversioned_libpng_pc\" != \"no\"])\n\nAC_ARG_ENABLE([unversioned-libpng-config],\n   AS_HELP_STRING([[[--enable-unversioned-libpng-config]]],\n      [Install the configuration file 'libpng-config' as a link to the]\n      [versioned version.  This is done by default - use]\n      [--disable-unversioned-libpng-config to change this.]))\nAM_CONDITIONAL([DO_INSTALL_LIBPNG_CONFIG],\n   [test \"$enable_unversioned_libpng_config\" != \"no\"])\n\n# HOST SPECIFIC OPTIONS\n# =====================\n#\n# ARM\n# ===\n#\n# ARM NEON (SIMD) support.\n\nAC_ARG_ENABLE([arm-neon],\n   AS_HELP_STRING([[[--enable-arm-neon]]],\n      [Enable ARM NEON optimizations: =no/off, check, api, yes/on:]\n      [no/off: disable the optimizations; check: use internal checking code]\n      [(deprecated and poorly supported); api: disable by default, enable by]\n      [a call to png_set_option; yes/on: turn on unconditionally.]\n      [If not specified: determined by the compiler.]),\n   [case \"$enableval\" in\n      no|off)\n         # disable the default enabling on __ARM_NEON__ systems:\n         AC_DEFINE([PNG_ARM_NEON], [], [ARM NEON support])\n         AC_DEFINE([PNG_ARM_NEON_OPT], [0],\n                   [Disable ARM Neon optimizations])\n         # Prevent inclusion of the assembler files below:\n         enable_arm_neon=no;;\n      check)\n         AC_DEFINE([PNG_ARM_NEON], [], [ARM NEON support])\n         AC_DEFINE([PNG_ARM_NEON_CHECK_SUPPORTED], [],\n                   [Check for ARM Neon support at run-time]);;\n      api)\n         AC_DEFINE([PNG_ARM_NEON], [], [ARM NEON support])\n         AC_DEFINE([PNG_ARM_NEON_API_SUPPORTED], [],\n                   [Turn on ARM Neon optimizations at run-time]);;\n      yes|on)\n         AC_DEFINE([PNG_ARM_NEON], [], [ARM NEON support])\n         AC_DEFINE([PNG_ARM_NEON_OPT], [2],\n                   [Enable ARM Neon optimizations])\n         AC_MSG_WARN([--enable-arm-neon: please specify 'check' or 'api', if]\n            [you want the optimizations unconditionally pass -mfpu=neon]\n            [to the compiler.]);;\n      *)\n         AC_MSG_ERROR([--enable-arm-neon=${enable_arm_neon}: invalid value])\n   esac])\n\n# Add ARM specific files to all builds where the host_cpu is arm ('arm*') or\n# where ARM optimizations were explicitly requested (this allows a fallback if a\n# future host CPU does not match 'arm*')\n\nAM_CONDITIONAL([PNG_ARM_NEON],\n   [test \"$enable_arm_neon\" != 'no' &&\n    case \"$host_cpu\" in\n      arm*|aarch64*) :;;\n      *)    test \"$enable_arm_neon\" != '';;\n    esac])\n\n# MIPS\n# ===\n#\n# MIPS MSA (SIMD) support.\n\nAC_ARG_ENABLE([mips-msa],\n   AS_HELP_STRING([[[--enable-mips-msa]]],\n      [Enable MIPS MSA optimizations: =no/off, check, api, yes/on:]\n      [no/off: disable the optimizations; check: use internal checking code]\n      [(deprecated and poorly supported); api: disable by default, enable by]\n      [a call to png_set_option; yes/on: turn on unconditionally.]\n      [If not specified: determined by the compiler.]),\n   [case \"$enableval\" in\n      no|off)\n         # disable the default enabling on __mips_msa systems:\n         AC_DEFINE([PNG_MIPS_MSA_OPT], [0],\n                   [Disable MIPS MSA optimizations])\n         # Prevent inclusion of the assembler files below:\n         enable_mips_msa=no;;\n      check)\n         AC_DEFINE([PNG_MIPS_MSA_CHECK_SUPPORTED], [],\n                   [Check for MIPS MSA support at run-time]);;\n      api)\n         AC_DEFINE([PNG_MIPS_MSA_API_SUPPORTED], [],\n                   [Turn on MIPS MSA optimizations at run-time]);;\n      yes|on)\n         AC_DEFINE([PNG_MIPS_MSA_OPT], [2],\n                   [Enable MIPS MSA optimizations])\n         AC_MSG_WARN([--enable-mips-msa: please specify 'check' or 'api', if]\n            [you want the optimizations unconditionally pass '-mmsa -mfp64']\n            [to the compiler.]);;\n      *)\n         AC_MSG_ERROR([--enable-mips-msa=${enable_mips_msa}: invalid value])\n   esac])\n\n# Add MIPS specific files to all builds where the host_cpu is mips ('mips*') or\n# where MIPS optimizations were explicitly requested (this allows a fallback if a\n# future host CPU does not match 'mips*')\n\nAM_CONDITIONAL([PNG_MIPS_MSA],\n   [test \"$enable_mips_msa\" != 'no' &&\n    case \"$host_cpu\" in\n      mipsel*|mips64el*) :;;\n    esac])\n\n# INTEL\n# =====\n#\n# INTEL SSE (SIMD) support.\n\nAC_ARG_ENABLE([intel-sse],\n   AS_HELP_STRING([[[--enable-intel-sse]]],\n      [Enable Intel SSE optimizations: =no/off, yes/on:]\n      [no/off: disable the optimizations;]\n      [yes/on: enable the optimizations.]\n      [If not specified: determined by the compiler.]),\n   [case \"$enableval\" in\n      no|off)\n         # disable the default enabling:\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [0],\n                   [Disable Intel SSE optimizations])\n         # Prevent inclusion of the assembler files below:\n         enable_intel_sse=no;;\n      yes|on)\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [1],\n                   [Enable Intel SSE optimizations]);;\n      *)\n         AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])\n   esac])\n\n# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')\n# or where Intel optimizations were explicitly requested (this allows a\n# fallback if a future host CPU does not match 'x86*')\nAM_CONDITIONAL([PNG_INTEL_SSE],\n   [test \"$enable_intel_sse\" != 'no' &&\n    case \"$host_cpu\" in\n      i?86|x86_64) :;;\n      *)    test \"$enable_intel_sse\" != '';;\n    esac])\n\nAC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])\n\n# Config files, substituting as above\nAC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in])\nAC_CONFIG_FILES([libpng-config:libpng-config.in],\n   [chmod +x libpng-config])\n\nAC_OUTPUT\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/README.txt",
    "content": "\nThis \"contrib\" directory contains contributions which are not necessarily under\nthe libpng license, although all are open source.  They are not part of\nlibpng proper and are not used for building the library, although some are used\nfor testing the library via \"make check\".\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/arm-neon/README",
    "content": "OPERATING SYSTEM SPECIFIC ARM NEON DETECTION\n--------------------------------------------\n\nDetection of the ability to execute ARM NEON on an ARM processor requires\noperating system support.  (The information is not available in user mode.)\n\nHOW TO USE THIS\n---------------\n\nThis directory contains C code fragments that can be included in arm/arm_init.c\nby setting the macro PNG_ARM_NEON_FILE to the file name in \"\" or <> at build\ntime.  This setting is not recorded in pnglibconf.h and can be changed simply by\nrebuilding arm/arm_init.o with the required macro definition.\n\nFor any of this code to be used the ARM NEON code must be enabled and run time\nchecks must be supported.  I.e.:\n\n#if PNG_ARM_NEON_OPT > 0\n#ifdef PNG_ARM_NEON_CHECK_SUPPORTED\n\nThis is done in a 'configure' build by passing configure the argument:\n\n   --enable-arm-neon=check\n\nApart from the basic Linux implementation in contrib/arm-neon/linux.c this code\nis unsupported.  That means that it is not even compiled on a regular basis and\nmay be broken in any given minor release.\n\nFILE FORMAT\n-----------\n\nEach file documents its testing status as of the last time it was tested (which\nmay have been a long time ago):\n\nSTATUS: one of:\n   SUPPORTED: This indicates that the file is included in the regularly\n         performed test builds and bugs are fixed when discovered.\n   COMPILED: This indicates that the code did compile at least once.  See the\n         more detailed description for the extent to which the result was\n         successful.\n   TESTED: This means the code was fully compiled into the libpng test programs\n         and these were run at least once.\n\nBUG REPORTS: an email address to which to send reports of problems\n\nThe file is a fragment of C code. It should not define any 'extern' symbols;\neverything should be static.  It must define the function:\n\nstatic int png_have_neon(png_structp png_ptr);\n\nThat function must return 1 if ARM NEON instructions are supported, 0 if not.\nIt must not execute png_error unless it detects a bug.  A png_error will prevent\nthe reading of the PNG and in the future, writing too.\n\nBUG REPORTS\n-----------\n\nIf you mail a bug report for any file that is not SUPPORTED there may only be\nlimited response.  Consider fixing it and sending a patch to fix the problem -\nthis is more likely to result in action.\n\nCONTRIBUTIONS\n-------------\n\nYou may send contributions of new implementations to\npng-mng-implement@sourceforge.net.  Please write code in strict C90 C where\npossible.  Obviously OS dependencies are to be expected.  If you submit code you\nmust have the authors permission and it must have a license that is acceptable\nto the current maintainer; in particular that license must permit modification\nand redistribution.\n\nPlease try to make the contribution a single file and give the file a clear and\nunambiguous name that identifies the target OS.  If multiple files really are\nrequired put them all in a sub-directory.\n\nYou must also be prepared to handle bug reports from users of the code, either\nby joining the png-mng-implement mailing list or by providing an email for the\n\"BUG REPORTS\" entry or both.  Please make sure that the header of the file\ncontains the STATUS and BUG REPORTS fields as above.\n\nPlease list the OS requirements as precisely as possible.  Ideally you should\nalso list the environment in which the code has been tested and certainly list\nany environments where you suspect it might not work.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/arm-neon/android-ndk.c",
    "content": "/* contrib/arm-neon/android-ndk.c\n *\n * Copyright (c) 2014 Glenn Randers-Pehrson\n * Written by John Bowler, 2014.\n * Last changed in libpng 1.6.10 [March 6, 2014]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * SEE contrib/arm-neon/README before reporting bugs\n *\n * STATUS: COMPILED, UNTESTED\n * BUG REPORTS: png-mng-implement@sourceforge.net\n *\n * png_have_neon implemented for the Android NDK, see:\n *\n * Documentation:\n *    http://www.kandroid.org/ndk/docs/CPU-ARM-NEON.html\n *    http://code.google.com/p/android/issues/detail?id=49065\n *\n * NOTE: this requires that libpng is built against the Android NDK and linked\n * with an implementation of the Android ARM 'cpu-features' library.  The code\n * has been compiled only, not linked: no version of the library has been found,\n * only the header files exist in the NDK.\n */\n#include <cpu-features.h>\n\nstatic int\npng_have_neon(png_structp png_ptr)\n{\n   /* This is a whole lot easier than the linux code, however it is probably\n    * implemented as below, therefore it is better to cache the result (these\n    * function calls may be slow!)\n    */\n   PNG_UNUSED(png_ptr)\n   return android_getCpuFamily() == ANDROID_CPU_FAMILY_ARM &&\n      (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) != 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/arm-neon/linux-auxv.c",
    "content": "/* contrib/arm-neon/linux-auxv.c\n *\n * Copyright (c) 2014 Glenn Randers-Pehrson\n * Written by Mans Rullgard, 2011.\n * Last changed in libpng 1.6.10 [March 6, 2014]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * SEE contrib/arm-neon/README before reporting bugs\n *\n * STATUS: COMPILED, TESTED\n * BUG REPORTS: png-mng-implement@sourceforge.net\n *\n * png_have_neon implemented for Linux versions which allow access to\n * /proc/self/auxv.  This is probably faster, cleaner and safer than the code to\n * read /proc/cpuinfo in contrib/arm-neon/linux, however it is yet another piece\n * of potentially untested code and has more complex dependencies than the code\n * to read cpuinfo.\n *\n * This generic __linux__ implementation requires reading /proc/self/auxv and\n * looking at each element for one that records NEON capabilities.\n */\n#include <unistd.h> /* for POSIX 1003.1 */\n#include <errno.h>  /* for EINTR */\n\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n#include <elf.h>\n#include <asm/hwcap.h>\n\n/* A read call may be interrupted, in which case it returns -1 and sets errno to\n * EINTR if nothing was done, otherwise (if something was done) a partial read\n * may result.\n */\nstatic size_t\nsafe_read(png_structp png_ptr, int fd, void *buffer_in, size_t nbytes)\n{\n   size_t ntotal = 0;\n   char *buffer = png_voidcast(char*, buffer_in);\n\n   while (nbytes > 0)\n   {\n      unsigned int nread;\n      int iread;\n\n      /* Passing nread > INT_MAX to read is implementation defined in POSIX\n       * 1003.1, therefore despite the unsigned argument portable code must\n       * limit the value to INT_MAX!\n       */\n      if (nbytes > INT_MAX)\n         nread = INT_MAX;\n\n      else\n         nread = (unsigned int)/*SAFE*/nbytes;\n\n      iread = read(fd, buffer, nread);\n\n      if (iread == -1)\n      {\n         /* This is the devil in the details, a read can terminate early with 0\n          * bytes read because of EINTR, yet it still returns -1 otherwise end\n          * of file cannot be distinguished.\n          */\n         if (errno != EINTR)\n         {\n            png_warning(png_ptr, \"/proc read failed\");\n            return 0; /* I.e., a permanent failure */\n         }\n      }\n\n      else if (iread < 0)\n      {\n         /* Not a valid 'read' result: */\n         png_warning(png_ptr, \"OS /proc read bug\");\n         return 0;\n      }\n\n      else if (iread > 0)\n      {\n         /* Continue reading until a permanent failure, or EOF */\n         buffer += iread;\n         nbytes -= (unsigned int)/*SAFE*/iread;\n         ntotal += (unsigned int)/*SAFE*/iread;\n      }\n\n      else\n         return ntotal;\n   }\n\n   return ntotal; /* nbytes == 0 */\n}\n\nstatic int\npng_have_neon(png_structp png_ptr)\n{\n   int fd = open(\"/proc/self/auxv\", O_RDONLY);\n   Elf32_auxv_t aux;\n\n   /* Failsafe: failure to open means no NEON */\n   if (fd == -1)\n   {\n      png_warning(png_ptr, \"/proc/self/auxv open failed\");\n      return 0;\n   }\n\n   while (safe_read(png_ptr, fd, &aux, sizeof aux) == sizeof aux)\n   {\n      if (aux.a_type == AT_HWCAP && (aux.a_un.a_val & HWCAP_NEON) != 0)\n      {\n         close(fd);\n         return 1;\n      }\n   }\n\n   close(fd);\n   return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/arm-neon/linux.c",
    "content": "/* contrib/arm-neon/linux.c\n *\n * Copyright (c) 2014 Glenn Randers-Pehrson\n * Written by John Bowler, 2014.\n * Last changed in libpng 1.6.16 [December 22, 2014]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * SEE contrib/arm-neon/README before reporting bugs\n *\n * STATUS: SUPPORTED\n * BUG REPORTS: png-mng-implement@sourceforge.net\n *\n * png_have_neon implemented for Linux by reading the widely available\n * pseudo-file /proc/cpuinfo.\n *\n * This code is strict ANSI-C and is probably moderately portable; it does\n * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.\n */\n#include <stdio.h>\n\nstatic int\npng_have_neon(png_structp png_ptr)\n{\n   FILE *f = fopen(\"/proc/cpuinfo\", \"rb\");\n\n   if (f != NULL)\n   {\n      /* This is a simple state machine which reads the input byte-by-byte until\n       * it gets a match on the 'neon' feature or reaches the end of the stream.\n       */\n      static const char ch_feature[] = { 70, 69, 65, 84, 85, 82, 69, 83 };\n      static const char ch_neon[] = { 78, 69, 79, 78 };\n\n      enum\n      {\n         StartLine, Feature, Colon, StartTag, Neon, HaveNeon, SkipTag, SkipLine\n      }  state;\n      int counter;\n\n      for (state=StartLine, counter=0;;)\n      {\n         int ch = fgetc(f);\n\n         if (ch == EOF)\n         {\n            /* EOF means error or end-of-file, return false; neon at EOF is\n             * assumed to be a mistake.\n             */\n            fclose(f);\n            return 0;\n         }\n\n         switch (state)\n         {\n            case StartLine:\n               /* Match spaces at the start of line */\n               if (ch <= 32) /* skip control characters and space */\n                  break;\n\n               counter=0;\n               state = Feature;\n               /* FALL THROUGH */\n\n            case Feature:\n               /* Match 'FEATURE', ASCII case insensitive. */\n               if ((ch & ~0x20) == ch_feature[counter])\n               {\n                  if (++counter == (sizeof ch_feature))\n                     state = Colon;\n                  break;\n               }\n\n               /* did not match 'feature' */\n               state = SkipLine;\n               /* FALL THROUGH */\n\n            case SkipLine:\n            skipLine:\n               /* Skip everything until we see linefeed or carriage return */\n               if (ch != 10 && ch != 13)\n                  break;\n\n               state = StartLine;\n               break;\n\n            case Colon:\n               /* Match any number of space or tab followed by ':' */\n               if (ch == 32 || ch == 9)\n                  break;\n\n               if (ch == 58) /* i.e. ':' */\n               {\n                  state = StartTag;\n                  break;\n               }\n\n               /* Either a bad line format or a 'feature' prefix followed by\n                * other characters.\n                */\n               state = SkipLine;\n               goto skipLine;\n\n            case StartTag:\n               /* Skip space characters before a tag */\n               if (ch == 32 || ch == 9)\n                  break;\n\n               state = Neon;\n               counter = 0;\n               /* FALL THROUGH */\n\n            case Neon:\n               /* Look for 'neon' tag */\n               if ((ch & ~0x20) == ch_neon[counter])\n               {\n                  if (++counter == (sizeof ch_neon))\n                     state = HaveNeon;\n                  break;\n               }\n\n               state = SkipTag;\n               /* FALL THROUGH */\n\n            case SkipTag:\n               /* Skip non-space characters */\n               if (ch == 10 || ch == 13)\n                  state = StartLine;\n\n               else if (ch == 32 || ch == 9)\n                  state = StartTag;\n               break;\n\n            case HaveNeon:\n               /* Have seen a 'neon' prefix, but there must be a space or new\n                * line character to terminate it.\n                */\n               if (ch == 10 || ch == 13 || ch == 32 || ch == 9)\n               {\n                  fclose(f);\n                  return 1;\n               }\n\n               state = SkipTag;\n               break;\n\n            default:\n               png_error(png_ptr, \"png_have_neon: internal error (bug)\");\n         }\n      }\n   }\n\n#ifdef PNG_WARNINGS_SUPPORTED\n   else\n      png_warning(png_ptr, \"/proc/cpuinfo open failed\");\n#endif\n\n   return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/README",
    "content": "This directory contains test configuration files, currently always '.dfa' files\nintended to be used in the build by setting the make macro DFA_XTRA to the name\nof the file.\n\nThese files are used in release validation of the 'configure' builds of libpng\nby building 'make check', or 'make all-am' for cross-builds, with each .dfa\nfile.\n\nThe files in this directory may change between minor releases, however\ncontributions describing specific builds of libpng are welcomed.  There is no\nguarantee that libpng will continue to build with such configurations; support\nfor given configurations can be, and has been, dropped between successive minor\nreleases.  However if a .dfa file describing a configuration is not in this\ndirectory it is very unlikely that it will be tested before a minor release!\n\nYou can use these .dfa files as the basis of new configurations.  Files in this\ndirectory should not have any use restrictions or restrictive licenses.\n\nThis directory is not included in the .zip and .7z distributions, which do\nnot contain 'configure' scripts.\n\nDOCUMENTATION\n=============\n\nExamples:\n   ${srcdir}/pngusr.dfa\n   ${srcdir}/contrib/pngminim/*/pngusr.dfa\n\nDocumentation of the options:\n   ${srcdir}/scripts/pnglibconf.dfa\n\nDocumentation of the file format:\n   ${srcdir}/scripts/options.awk\n\nFILE NAMING\n===========\n\nFile names in this directory may NOT contain any of the five characters:\n\n   - , + * ?\n\nNeither may they contain any space character.\n\nWhile other characters may be used it is strongly suggested that file names be\nlimited to lower case Latiin alphabetic characters (a-z), digits (0-9) and, if\nnecessary the underscore (_) character.  File names should be about 8 characters\nlong (excluding the .dfa extension).  Submitted .dfa files should have names\nbetween 7 and 16 characters long, shorter names (6 characters or less) are\nreserved for standard tests.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/pngcp.dfa",
    "content": "# pngcp.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2016\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with support for pngcp.  This means just png_read_png,\n# png_write_png and small number of configuration settings.\n#\neverything = off\n\n# This option is specific to this configuration; it adds a #define to the\n# generated pnglibconf.h which turns on the (not portable) timing option for\n# pngcp.  Note that any option is automatically preceded by PNG_; there is no\n# way round this and this is deliberate.\noption PNGCP_TIMING\n\n# Because of the everything off above the option must also be turned on.  This\n# may not be done in one step because it is safer and avoids mis-spelled options\n# in user .dfa files to error out if an unrecognized option is turned on.\noption PNGCP_TIMING on\n\n# Options to turn on png_read_png and png_write_png:\noption INFO_IMAGE on\noption SEQUENTIAL_READ on\noption EASY_ACCESS on\noption WRITE on\noption WRITE_16BIT on\noption WRITE_FILTER on\n\n# pngcp needs this to preserve unknown chunks, switching all these on means that\n# pngcp can work without explicit known chunk reading suppport\noption UNKNOWN_CHUNKS on\noption SET_UNKNOWN_CHUNKS on\noption HANDLE_AS_UNKNOWN on\noption SAVE_UNKNOWN_CHUNKS on\noption WRITE_UNKNOWN_CHUNKS on\n\n# pngcp needs this to handle palette files with invalid indices:\noption CHECK_FOR_INVALID_INDEX on\noption GET_PALETTE_MAX on\n\n# Pre-libpng 1.7 pngcp has to stash text chunks manually, post 1.7 without this\n# text chunks should be handled as unknown ok.\noption TEXT on\n\n# this is used to turn off limits:\noption USER_LIMITS on\noption SET_USER_LIMITS on\n\n# these are are just required for specific customizations\noption WRITE_CUSTOMIZE_ZTXT_COMPRESSION on\noption WRITE_CUSTOMIZE_COMPRESSION on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/read.dfa",
    "content": "# read.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2013\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with basic read support.  This enables the lowest level libpng\n# read API - the one where the calling code has to use a loop to read each row.\n# At present this is the API used by most programs.\n#\n# Support is enabled only for those chunks and transformations that are\n# typically required - others can be added easily.\n#\n\neverything = off\n\n# The sequential read code is enabled here; the progressive code can be used\n# instead but there is no point enabling both.\n\noption SEQUENTIAL_READ on\n\n# Likewise it is pointless enabling both fixed and floating point APIs.  Choose\n# one or the other for both the API and the internal math.\n\n#Fixed point:\n#option FIXED_POINT on\n#option FLOATING_ARITHMETIC off\n\n#Floating point:\noption FLOATING_POINT on\noption FLOATING_ARITHMETIC on\n\n# Basic error handling, IO and user memory support.  The latter allows the\n# application program to provide its own implementations of 'malloc' and 'free'.\noption SETJMP on\noption STDIO on\noption USER_MEM on\n\n# To read the full set of PNG images correctly interlace, transparency and\n# 16-bit support is required.  The application can implement interlace itself,\n# but very few do and it's no longer possible to disable it when READ is\n# enabled.\noption READ_tRNS on\noption READ_16BIT on\n\n# Everything else is application dependent.  This file assumes the app handles\n# all the native PNG bit layouts, so it doesn't need any of layout change\n# transforms, but needs libpng to perform gamma correction.  It doesn't do any\n# colorspace stuff and ignores the 'significant bit' information.\n#\n# If your app always expands the image to a limited set of bit layouts you\n# probably want to consider using the simplified API instead of the low level\n# one - see png.h and s_read.dfa.\noption READ_GAMMA on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/s_read.dfa",
    "content": "# s_read.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2013\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with simplified read support (only).  This builds a minimal\n# libpng able to read all PNG formats and convert them into a small number of\n# well understood memory formats.\n#\n\neverything = off\n\noption SIMPLIFIED_READ on\n\n# It isn't necessary to chose fixed or floating point for the APIs because the\n# simplified API doesn't need fixed or floating point numbers.  It is necessary\n# to chose an internal math implementation.  The default (because of 'everything\n# = off') is fixed point - turn the floating point implementation on if you have\n# hardware floating point or prefer your software floating point implementation.\noption FLOATING_ARITHMETIC on\n\n# This is not strictly necessary, but without it the message strings in the API\n# will not be filled in\noption ERROR_TEXT on\n\n# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't\n# need this if you don't use them, they just allow the in-memory layout to be\n# changed to match common hardware formats.\noption SIMPLIFIED_READ_AFIRST on\noption SIMPLIFIED_READ_BGR on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/s_write.dfa",
    "content": "# s_write.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2013\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with (just) simplified write support\n#\n\neverything = off\n\noption SIMPLIFIED_WRITE on\n\n# It isn't necessary to chose fixed or floating point for the APIs because the\n# simplified API doesn't need fixed or floating point numbers.  It is necessary\n# to chose an internal math implementation.  The default (because of 'everything\n# = off') is fixed point - turn the floating point implementation on if you have\n# hardware floating point or prefer your software floating point implementation.\noption FLOATING_ARITHMETIC on\n\n# This is not strictly necessary, but without it the message strings in the API\n# will not be filled in\noption ERROR_TEXT on\n\n# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't\n# need this if you don't use them, they just allow the in-memory layout to be\n# changed to match common hardware formats.\noption SIMPLIFIED_WRITE_AFIRST on\noption SIMPLIFIED_WRITE_BGR on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/simple.dfa",
    "content": "# simple.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2013\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with just the simplified APIs (read and write).\n#\n\neverything = off\n\noption SIMPLIFIED_WRITE on\noption SIMPLIFIED_READ on\n\n# It isn't necessary to chose fixed or floating point for the APIs because the\n# simplified API doesn't need fixed or floating point numbers.  It is necessary\n# to chose an internal math implementation.  The default (because of 'everything\n# = off') is fixed point - turn the floating point implementation on if you have\n# hardware floating point or prefer your software floating point implementation.\noption FLOATING_ARITHMETIC on\n\n# This is not strictly necessary, but without it the message strings in the API\n# will not be filled in\noption ERROR_TEXT on\n\n# Switching these options on enables the 'AFIRST' and 'BGR' formats - you don't\n# need this if you don't use them, they just allow the in-memory layout to be\n# changed to match common hardware formats.\noption SIMPLIFIED_READ_AFIRST on\noption SIMPLIFIED_READ_BGR on\noption SIMPLIFIED_WRITE_AFIRST on\noption SIMPLIFIED_WRITE_BGR on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/conftest/write.dfa",
    "content": "# write.dfa\n#  Build time configuration of libpng\n#\n# Author: John Bowler\n# Copyright: (c) John Bowler, 2013\n# Usage rights:\n#  To the extent possible under law, the author has waived all copyright and\n#  related or neighboring rights to this work.  This work is published from:\n#  United States.\n#\n# Build libpng with no read support and minimal write support.\n#\n\neverything = off\n\n# Switch on the write code - this makes a minimalist encoder\n\noption WRITE on\n\n# Choose fixed or floating point APIs and arithmetic.  The choices are\n# independent but normally they will match.  It is typically better to use the\n# floating point if you have floating point hardware.  If you don't know, or\n# (perhaps) to make libpng smaller used fixed point throughout.\n\n#Fixed point:\n#option FIXED_POINT on\n#option FLOATING_ARITHMETIC off\n\n#Floating point:\noption FLOATING_POINT on\noption FLOATING_ARITHMETIC on\n\n# Basic error handling, IO and user memory support.  The latter allows the\n# application program to provide its own implementations of 'malloc' and 'free'.\noption SETJMP on\noption STDIO on\noption USER_MEM on\n\n# Everything else is optional.  Unlike the read code in libpng the write code\n# does not need to deal with arbitrary formats, so only add support for things\n# you really do write!  For example you might only write sRGB images, sometimes\n# with transparency and never write 16 bit images, so:\noption WRITE_sRGB on\noption WRITE_tRNS on\n#option WRITE_16BIT off (this is the default with 'everything = off')\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/examples/README.txt",
    "content": "\nThis directory (contrib/examples) contains examples of libpng usage.\n\nNO COPYRIGHT RIGHTS ARE CLAIMED TO ANY OF THE FILES IN THIS DIRECTORY.\n\nTo the extent possible under law, the authors have waived all copyright and\nrelated or neighboring rights to this work.  This work is published from:\nUnited States.\n\nThe files may be used freely in any way.  The intention is that appropriate\nparts of the files be used in other libpng-using programs without any need for\nthe authors of the using code to seek copyright or license from the original\nauthors.\n\nThe source code and comments in this directory are the original work of the\npeople named below.  No other person or organization has made contributions to\nthe work in this directory.\n\nORIGINAL AUTHORS\n    The following people have contributed to the code in this directory.  None\n    of the people below claim any rights with regard to the contents of this\n    directory.\n\n    John Bowler <jbowler@acm.org>\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/examples/iccfrompng.c",
    "content": "/*- iccfrompng\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2011.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Extract any icc profiles found in the given PNG files.  This is a simple\n * example of a program that extracts information from the header of a PNG file\n * without processing the image.  Notice that some header information may occur\n * after the image data. Textual data and comments are an example; the approach\n * in this file won't work reliably for such data because it only looks for the\n * information in the section of the file that preceeds the image data.\n *\n * Compile and link against libpng and zlib, plus anything else required on the\n * system you use.\n *\n * To use supply a list of PNG files containing iCCP chunks, the chunks will be\n * extracted to a similarly named file with the extension replaced by 'icc',\n * which will be overwritten without warning.\n */\n#include <stdlib.h>\n#include <setjmp.h>\n#include <string.h>\n#include <stdio.h>\n\n#include <png.h>\n\n#if defined(PNG_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED) && \\\n    defined (PNG_iCCP_SUPPORTED)\n\n\nstatic int verbose = 1;\nstatic png_byte no_profile[] = \"no profile\";\n\nstatic png_bytep\nextract(FILE *fp, png_uint_32 *proflen)\n{\n   png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);\n   png_infop info_ptr = NULL;\n   png_bytep result = NULL;\n\n   /* Initialize for error or no profile: */\n   *proflen = 0;\n\n   if (png_ptr == NULL)\n   {\n      fprintf(stderr, \"iccfrompng: version library mismatch?\\n\");\n      return 0;\n   }\n\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n      return 0;\n   }\n\n   png_init_io(png_ptr, fp);\n\n   info_ptr = png_create_info_struct(png_ptr);\n   if (info_ptr == NULL)\n      png_error(png_ptr, \"OOM allocating info structure\");\n\n   png_read_info(png_ptr, info_ptr);\n\n   {\n      png_charp name;\n      int compression_type;\n      png_bytep profile;\n\n      if (png_get_iCCP(png_ptr, info_ptr, &name, &compression_type, &profile,\n         proflen) & PNG_INFO_iCCP)\n      {\n         result = malloc(*proflen);\n         if (result != NULL)\n            memcpy(result, profile, *proflen);\n\n         else\n            png_error(png_ptr, \"OOM allocating profile buffer\");\n      }\n\n      else\n\tresult = no_profile;\n   }\n\n   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n   return result;\n}\n\nstatic int\nextract_one_file(const char *filename)\n{\n   int result = 0;\n   FILE *fp = fopen(filename, \"rb\");\n\n   if (fp != NULL)\n   {\n      png_uint_32 proflen = 0;\n      png_bytep profile = extract(fp, &proflen);\n\n      if (profile != NULL && profile != no_profile)\n      {\n         size_t len;\n         char *output;\n\n         {\n            const char *ep = strrchr(filename, '.');\n\n            if (ep != NULL)\n               len = ep-filename;\n\n            else\n               len = strlen(filename);\n         }\n\n         output = malloc(len + 5);\n         if (output != NULL)\n         {\n            FILE *of;\n\n            memcpy(output, filename, len);\n            strcpy(output+len, \".icc\");\n\n            of = fopen(output, \"wb\");\n            if (of != NULL)\n            {\n               if (fwrite(profile, proflen, 1, of) == 1 &&\n                  fflush(of) == 0 &&\n                  fclose(of) == 0)\n               {\n                  if (verbose)\n                     printf(\"%s -> %s\\n\", filename, output);\n                  /* Success return */\n                  result = 1;\n               }\n\n               else\n               {\n                  fprintf(stderr, \"%s: error writing profile\\n\", output);\n                  if (remove(output))\n                     fprintf(stderr, \"%s: could not remove file\\n\", output);\n               }\n            }\n\n            else\n               fprintf(stderr, \"%s: failed to open output file\\n\", output);\n\n            free(output);\n         }\n\n         else\n            fprintf(stderr, \"%s: OOM allocating string!\\n\", filename);\n\n         free(profile);\n      }\n\n      else if (verbose && profile == no_profile)\n\tprintf(\"%s has no profile\\n\", filename);\n   }\n\n   else\n      fprintf(stderr, \"%s: could not open file\\n\", filename);\n\n   return result;\n}\n\nint\nmain(int argc, char **argv)\n{\n   int i;\n   int extracted = 0;\n\n   for (i=1; i<argc; ++i)\n   {\n      if (strcmp(argv[i], \"-q\") == 0)\n         verbose = 0;\n\n      else if (extract_one_file(argv[i]))\n         extracted = 1;\n   }\n\n   /* Exit code is true if any extract succeeds */\n   return extracted == 0;\n}\n#endif /* READ && STDIO && iCCP */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/examples/pngpixel.c",
    "content": "/*- pngpixel\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2011.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Read a single pixel value from a PNG file.\n *\n * This code illustrates basic 'by-row' reading of a PNG file using libpng.\n * Rows are read until a particular pixel is found; the value of this pixel is\n * then printed on stdout.\n *\n * The code illustrates how to do this on interlaced as well as non-interlaced\n * images.  Normally you would call png_set_interlace_handling() to have libpng\n * deal with the interlace for you, but that obliges you to buffer half of the\n * image to assemble the interlaced rows.  In this code\n * png_set_interlace_handling() is not called and, instead, the code handles the\n * interlace passes directly looking for the required pixel.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <setjmp.h> /* required for error handling */\n\n/* Normally use <png.h> here to get the installed libpng, but this is done to\n * ensure the code picks up the local libpng implementation:\n */\n#include \"../../png.h\"\n\n#if defined(PNG_READ_SUPPORTED) && defined(PNG_SEQUENTIAL_READ_SUPPORTED)\n\n/* Return component 'c' of pixel 'x' from the given row. */\nstatic unsigned int\ncomponent(png_const_bytep row, png_uint_32 x, unsigned int c,\n   unsigned int bit_depth, unsigned int channels)\n{\n   /* PNG images can be up to 2^31 pixels wide, but this means they can be up to\n    * 2^37 bits wide (for a 64-bit pixel - the largest possible) and hence 2^34\n    * bytes wide.  Since the row fitted into memory, however, the following must\n    * work:\n    */\n   png_uint_32 bit_offset_hi = bit_depth * ((x >> 6) * channels);\n   png_uint_32 bit_offset_lo = bit_depth * ((x & 0x3f) * channels + c);\n\n   row = (png_const_bytep)(((PNG_CONST png_byte (*)[8])row) + bit_offset_hi);\n   row += bit_offset_lo >> 3;\n   bit_offset_lo &= 0x07;\n\n   /* PNG pixels are packed into bytes to put the first pixel in the highest\n    * bits of the byte and into two bytes for 16-bit values with the high 8 bits\n    * first, so:\n    */\n   switch (bit_depth)\n   {\n      case 1: return (row[0] >> (7-bit_offset_lo)) & 0x01;\n      case 2: return (row[0] >> (6-bit_offset_lo)) & 0x03;\n      case 4: return (row[0] >> (4-bit_offset_lo)) & 0x0f;\n      case 8: return row[0];\n      case 16: return (row[0] << 8) + row[1];\n      default:\n         /* This should never happen; it indicates a bug in this program or in\n          * libpng itself:\n          */\n         fprintf(stderr, \"pngpixel: invalid bit depth %u\\n\", bit_depth);\n         exit(1);\n   }\n}\n\n/* Print a pixel from a row returned by libpng; determine the row format, find\n * the pixel, and print the relevant information to stdout.\n */\nstatic void\nprint_pixel(png_structp png_ptr, png_infop info_ptr, png_const_bytep row,\n   png_uint_32 x)\n{\n   PNG_CONST unsigned int bit_depth = png_get_bit_depth(png_ptr, info_ptr);\n\n   switch (png_get_color_type(png_ptr, info_ptr))\n   {\n      case PNG_COLOR_TYPE_GRAY:\n         printf(\"GRAY %u\\n\", component(row, x, 0, bit_depth, 1));\n         return;\n\n      /* The palette case is slightly more difficult - the palette and, if\n       * present, the tRNS ('transparency', though the values are really\n       * opacity) data must be read to give the full picture:\n       */\n      case PNG_COLOR_TYPE_PALETTE:\n         {\n            PNG_CONST int index = component(row, x, 0, bit_depth, 1);\n            png_colorp palette = NULL;\n            int num_palette = 0;\n\n            if ((png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) &\n               PNG_INFO_PLTE) && num_palette > 0 && palette != NULL)\n            {\n               png_bytep trans_alpha = NULL;\n               int num_trans = 0;\n               if ((png_get_tRNS(png_ptr, info_ptr, &trans_alpha, &num_trans,\n                  NULL) & PNG_INFO_tRNS) && num_trans > 0 &&\n                  trans_alpha != NULL)\n                  printf(\"INDEXED %u = %d %d %d %d\\n\", index,\n                     palette[index].red, palette[index].green,\n                     palette[index].blue,\n                     index < num_trans ? trans_alpha[index] : 255);\n\n               else /* no transparency */\n                  printf(\"INDEXED %u = %d %d %d\\n\", index,\n                     palette[index].red, palette[index].green,\n                     palette[index].blue);\n            }\n\n            else\n               printf(\"INDEXED %u = invalid index\\n\", index);\n         }\n         return;\n\n      case PNG_COLOR_TYPE_RGB:\n         printf(\"RGB %u %u %u\\n\", component(row, x, 0, bit_depth, 3),\n            component(row, x, 1, bit_depth, 3),\n            component(row, x, 2, bit_depth, 3));\n         return;\n\n      case PNG_COLOR_TYPE_GRAY_ALPHA:\n         printf(\"GRAY+ALPHA %u %u\\n\", component(row, x, 0, bit_depth, 2),\n            component(row, x, 1, bit_depth, 2));\n         return;\n\n      case PNG_COLOR_TYPE_RGB_ALPHA:\n         printf(\"RGBA %u %u %u %u\\n\", component(row, x, 0, bit_depth, 4),\n            component(row, x, 1, bit_depth, 4),\n            component(row, x, 2, bit_depth, 4),\n            component(row, x, 3, bit_depth, 4));\n         return;\n\n      default:\n         png_error(png_ptr, \"pngpixel: invalid color type\");\n   }\n}\n\nint main(int argc, const char **argv)\n{\n   /* This program uses the default, <setjmp.h> based, libpng error handling\n    * mechanism, therefore any local variable that exists before the call to\n    * setjmp and is changed after the call to setjmp returns successfully must\n    * be declared with 'volatile' to ensure that their values don't get\n    * destroyed by longjmp:\n    */\n   volatile int result = 1/*fail*/;\n\n   if (argc == 4)\n   {\n      long x = atol(argv[1]);\n      long y = atol(argv[2]);\n      FILE *f = fopen(argv[3], \"rb\");\n      volatile png_bytep row = NULL;\n\n      if (f != NULL)\n      {\n         /* libpng requires a callback function for handling errors; this\n          * callback must not return.  The default callback function uses a\n          * stored <setjmp.h> style jmp_buf which is held in a png_struct and\n          * writes error messages to stderr.  Creating the png_struct is a\n          * little tricky; just copy the following code.\n          */\n         png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,\n            NULL, NULL, NULL);\n\n         if (png_ptr != NULL)\n         {\n            png_infop info_ptr = png_create_info_struct(png_ptr);\n\n            if (info_ptr != NULL)\n            {\n               /* Declare stack variables to hold pointers to locally allocated\n                * data.\n                */\n\n               /* Initialize the error control buffer: */\n               if (setjmp(png_jmpbuf(png_ptr)) == 0)\n               {\n                  png_uint_32 width, height;\n                  int bit_depth, color_type, interlace_method,\n                     compression_method, filter_method;\n                  png_bytep row_tmp;\n\n                  /* Now associate the recently opened (FILE*) with the default\n                   * libpng initialization functions.  Sometimes libpng is\n                   * compiled without stdio support (it can be difficult to do\n                   * in some environments); in that case you will have to write\n                   * your own read callback to read data from the (FILE*).\n                   */\n                  png_init_io(png_ptr, f);\n\n                  /* And read the first part of the PNG file - the header and\n                   * all the information up to the first pixel.\n                   */\n                  png_read_info(png_ptr, info_ptr);\n\n                  /* This fills in enough information to tell us the width of\n                   * each row in bytes, allocate the appropriate amount of\n                   * space.  In this case png_malloc is used - it will not\n                   * return if memory isn't available.\n                   */\n                  row = png_malloc(png_ptr, png_get_rowbytes(png_ptr,\n                     info_ptr));\n\n                  /* To avoid the overhead of using a volatile auto copy row_tmp\n                   * to a local here - just use row for the png_free below.\n                   */\n                  row_tmp = row;\n\n                  /* All the information we need is in the header is returned by\n                   * png_get_IHDR, if this fails we can now use 'png_error' to\n                   * signal the error and return control to the setjmp above.\n                   */\n                  if (png_get_IHDR(png_ptr, info_ptr, &width, &height,\n                     &bit_depth, &color_type, &interlace_method,\n                     &compression_method, &filter_method))\n                  {\n                     int passes, pass;\n\n                     /* png_set_interlace_handling returns the number of\n                      * passes required as well as turning on libpng's\n                      * handling, but since we do it ourselves this is\n                      * necessary:\n                      */\n                     switch (interlace_method)\n                     {\n                        case PNG_INTERLACE_NONE:\n                           passes = 1;\n                           break;\n\n                        case PNG_INTERLACE_ADAM7:\n                           passes = PNG_INTERLACE_ADAM7_PASSES;\n                           break;\n\n                        default:\n                           png_error(png_ptr, \"pngpixel: unknown interlace\");\n                     }\n\n                     /* Now read the pixels, pass-by-pass, row-by-row: */\n                     png_start_read_image(png_ptr);\n\n                     for (pass=0; pass<passes; ++pass)\n                     {\n                        png_uint_32 ystart, xstart, ystep, xstep;\n                        png_uint_32 py;\n\n                        if (interlace_method == PNG_INTERLACE_ADAM7)\n                        {\n                           /* Sometimes the whole pass is empty because the\n                            * image is too narrow or too short.  libpng\n                            * expects to be called for each row that is\n                            * present in the pass, so it may be necessary to\n                            * skip the loop below (over py) if the image is\n                            * too narrow.\n                            */\n                           if (PNG_PASS_COLS(width, pass) == 0)\n                              continue;\n\n                           /* We need the starting pixel and the offset\n                            * between each pixel in this pass; use the macros\n                            * in png.h:\n                            */\n                           xstart = PNG_PASS_START_COL(pass);\n                           ystart = PNG_PASS_START_ROW(pass);\n                           xstep = PNG_PASS_COL_OFFSET(pass);\n                           ystep = PNG_PASS_ROW_OFFSET(pass);\n                        }\n\n                        else\n                        {\n                           ystart = xstart = 0;\n                           ystep = xstep = 1;\n                        }\n\n                        /* To find the pixel, loop over 'py' for each pass\n                         * reading a row and then checking to see if it\n                         * contains the pixel.\n                         */\n                        for (py = ystart; py < height; py += ystep)\n                        {\n                           png_uint_32 px, ppx;\n\n                           /* png_read_row takes two pointers.  When libpng\n                            * handles the interlace the first is filled in\n                            * pixel-by-pixel, and the second receives the same\n                            * pixels but they are replicated across the\n                            * unwritten pixels so far for each pass.  When we\n                            * do the interlace, however, they just contain\n                            * the pixels from the interlace pass - giving\n                            * both is wasteful and pointless, so we pass a\n                            * NULL pointer.\n                            */\n                           png_read_row(png_ptr, row_tmp, NULL);\n\n                           /* Now find the pixel if it is in this row; there\n                            * are, of course, much better ways of doing this\n                            * than using a for loop:\n                            */\n                           if (y == py) for (px = xstart, ppx = 0;\n                              px < width; px += xstep, ++ppx) if (x == px)\n                           {\n                              /* 'ppx' is the index of the pixel in the row\n                               * buffer.\n                               */\n                              print_pixel(png_ptr, info_ptr, row_tmp, ppx);\n\n                              /* Now terminate the loops early - we have\n                               * found and handled the required data.\n                               */\n                              goto pass_loop_end;\n                           } /* x loop */\n                        } /* y loop */\n                     } /* pass loop */\n\n                     /* Finally free the temporary buffer: */\n                  pass_loop_end:\n                     row = NULL;\n                     png_free(png_ptr, row_tmp);\n                  }\n\n                  else\n                     png_error(png_ptr, \"pngpixel: png_get_IHDR failed\");\n\n               }\n\n               else\n               {\n                  /* Else libpng has raised an error.  An error message has\n                   * already been output, so it is only necessary to clean up\n                   * locally allocated data:\n                   */\n                  if (row != NULL)\n                  {\n                     /* The default implementation of png_free never errors out\n                      * (it just crashes if something goes wrong), but the safe\n                      * way of using it is still to clear 'row' before calling\n                      * png_free:\n                      */\n                     png_bytep row_tmp = row;\n                     row = NULL;\n                     png_free(png_ptr, row_tmp);\n                  }\n               }\n\n               png_destroy_info_struct(png_ptr, &info_ptr);\n            }\n\n            else\n               fprintf(stderr, \"pngpixel: out of memory allocating png_info\\n\");\n\n            png_destroy_read_struct(&png_ptr, NULL, NULL);\n         }\n\n         else\n            fprintf(stderr, \"pngpixel: out of memory allocating png_struct\\n\");\n      }\n\n      else\n         fprintf(stderr, \"pngpixel: %s: could not open file\\n\", argv[3]);\n   }\n\n   else\n      /* Wrong number of arguments */\n      fprintf(stderr, \"pngpixel: usage: pngpixel x y png-file\\n\");\n\n   return result;\n}\n#endif /* READ && SEQUENTIAL_READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/examples/pngtopng.c",
    "content": "/*- pngtopng\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2011.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Read a PNG and write it out in a fixed format, using the 'simplified API'\n * that was introduced in libpng-1.6.0.\n *\n * This sample code is just the code from the top of 'example.c' with some error\n * handling added.  See example.c for more comments.\n */\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n\n/* Normally use <png.h> here to get the installed libpng, but this is done to\n * ensure the code picks up the local libpng implementation:\n */\n#include \"../../png.h\"\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && \\\n    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n\nint main(int argc, const char **argv)\n{\n   int result = 1;\n\n   if (argc == 3)\n   {\n      png_image image;\n\n      /* Only the image structure version number needs to be set. */\n      memset(&image, 0, sizeof image);\n      image.version = PNG_IMAGE_VERSION;\n\n      if (png_image_begin_read_from_file(&image, argv[1]))\n      {\n         png_bytep buffer;\n\n         /* Change this to try different formats!  If you set a colormap format\n          * then you must also supply a colormap below.\n          */\n         image.format = PNG_FORMAT_RGBA;\n\n         buffer = malloc(PNG_IMAGE_SIZE(image));\n\n         if (buffer != NULL)\n         {\n            if (png_image_finish_read(&image, NULL/*background*/, buffer,\n               0/*row_stride*/, NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP */))\n            {\n               if (png_image_write_to_file(&image, argv[2],\n                  0/*convert_to_8bit*/, buffer, 0/*row_stride*/,\n                  NULL/*colormap*/))\n                  result = 0;\n\n               else\n                  fprintf(stderr, \"pngtopng: write %s: %s\\n\", argv[2],\n                      image.message);\n\n               free(buffer);\n            }\n\n            else\n            {\n               fprintf(stderr, \"pngtopng: read %s: %s\\n\", argv[1],\n                   image.message);\n\n               /* This is the only place where a 'free' is required; libpng does\n                * the cleanup on error and success, but in this case we couldn't\n                * complete the read because of running out of memory.\n                */\n               png_image_free(&image);\n            }\n         }\n\n         else\n            fprintf(stderr, \"pngtopng: out of memory: %lu bytes\\n\",\n               (unsigned long)PNG_IMAGE_SIZE(image));\n      }\n\n      else\n         /* Failed to read the first argument: */\n         fprintf(stderr, \"pngtopng: %s: %s\\n\", argv[1], image.message);\n   }\n\n   else\n      /* Wrong number of arguments */\n      fprintf(stderr, \"pngtopng: usage: pngtopng input-file output-file\\n\");\n\n   return result;\n}\n#endif /* READ && WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/examples/simpleover.c",
    "content": "/*- simpleover\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2015.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Read several PNG files, which should have an alpha channel or transparency\n * information, and composite them together to produce one or more 16-bit linear\n * RGBA intermediates.  This involves doing the correct 'over' composition to\n * combine the alpha channels and corresponding data.\n *\n * Finally read an output (background) PNG using the 24-bit RGB format (the\n * PNG will be composited on green (#00ff00) by default if it has an alpha\n * channel), and apply the intermediate image generated above to specified\n * locations in the image.\n *\n * The command line has the general format:\n *\n *    simpleover <background.png> [output.png]\n *        {--sprite=width,height,name {[--at=x,y] {sprite.png}}}\n *        {--add=name {x,y}}\n *\n * The --sprite and --add options may occur multiple times. They are executed\n * in order.  --add may refer to any sprite already read.\n *\n * This code is intended to show how to composite multiple images together\n * correctly.  Apart from the libpng Simplified API the only work done in here\n * is to combine multiple input PNG images into a single sprite; this involves\n * a Porter-Duff 'over' operation and the input PNG images may, as a result,\n * be regarded as being layered one on top of the other with the first (leftmost\n * on the command line) being at the bottom and the last on the top.\n */\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <errno.h>\n\n/* Normally use <png.h> here to get the installed libpng, but this is done to\n * ensure the code picks up the local libpng implementation, so long as this\n * file is linked against a sufficiently recent libpng (1.6+) it is ok to\n * change this to <png.h>:\n */\n#include \"../../png.h\"\n\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED\n\n#define sprite_name_chars 15\nstruct sprite {\n   FILE         *file;\n   png_uint_16p  buffer;\n   unsigned int  width;\n   unsigned int  height;\n   char          name[sprite_name_chars+1];\n};\n\n#if 0 /* div by 65535 test program */\n#include <math.h>\n#include <stdio.h>\n\nint main(void) {\n   double err = 0;\n   unsigned int xerr = 0;\n   unsigned int r = 32769;\n   {\n      unsigned int x = 0;\n\n      do {\n         unsigned int t = x + (x >> 16) /*+ (x >> 31)*/ + r;\n         double v = x, errtest;\n\n         if (t < x) {\n            fprintf(stderr, \"overflow: %u+%u -> %u\\n\", x, r, t);\n            return 1;\n         }\n\n         v /= 65535;\n         errtest = v;\n         t >>= 16;\n         errtest -= t;\n\n         if (errtest > err) {\n            err = errtest;\n            xerr = x;\n\n            if (errtest >= .5) {\n               fprintf(stderr, \"error: %u/65535 = %f, not %u, error %f\\n\",\n                     x, v, t, errtest);\n               return 0;\n            }\n         }\n      } while (++x <= 65535U*65535U);\n   }\n\n   printf(\"error %f @ %u\\n\", err, xerr);\n\n   return 0;\n}\n#endif /* div by 65535 test program */\n\nstatic void\nsprite_op(const struct sprite *sprite, int x_offset, int y_offset,\n   png_imagep image, const png_uint_16 *buffer)\n{\n   /* This is where the Porter-Duff 'Over' operator is evaluated; change this\n    * code to change the operator (this could be parameterized).  Any other\n    * image processing operation could be used here.\n    */\n\n\n   /* Check for an x or y offset that pushes any part of the image beyond the\n    * right or bottom of the sprite:\n    */\n   if ((y_offset < 0 || (unsigned)/*SAFE*/y_offset < sprite->height) &&\n       (x_offset < 0 || (unsigned)/*SAFE*/x_offset < sprite->width))\n   {\n      unsigned int y = 0;\n\n      if (y_offset < 0)\n         y = -y_offset; /* Skip to first visible row */\n\n      do\n      {\n         unsigned int x = 0;\n\n         if (x_offset < 0)\n            x = -x_offset;\n\n         do\n         {\n            /* In and out are RGBA values, so: */\n            const png_uint_16 *in_pixel = buffer + (y * image->width + x)*4;\n            png_uint_32 in_alpha = in_pixel[3];\n\n            /* This is the optimized Porter-Duff 'Over' operation, when the\n             * input alpha is 0 the output is not changed.\n             */\n            if (in_alpha > 0)\n            {\n               png_uint_16 *out_pixel = sprite->buffer +\n                  ((y+y_offset) * sprite->width + (x+x_offset))*4;\n\n               /* This is the weight to apply to the output: */\n               in_alpha = 65535-in_alpha;\n\n               if (in_alpha > 0)\n               {\n                  /* The input must be composed onto the output. This means\n                   * multiplying the current output pixel value by the inverse\n                   * of the input alpha (1-alpha). A division is required but\n                   * it is by the constant 65535.  Approximate this as:\n                   *\n                   *     (x + (x >> 16) + 32769) >> 16;\n                   *\n                   * This is exact (and does not overflow) for all values of\n                   * x in the range 0..65535*65535.  (Note that the calculation\n                   * produces the closest integer; the maximum error is <0.5).\n                   */\n                  png_uint_32 tmp;\n\n#                 define compose(c)\\\n                     tmp = out_pixel[c] * in_alpha;\\\n                     tmp = (tmp + (tmp >> 16) + 32769) >> 16;\\\n                     out_pixel[c] = tmp + in_pixel[c]\n\n                  /* The following is very vectorizable... */\n                  compose(0);\n                  compose(1);\n                  compose(2);\n                  compose(3);\n               }\n\n               else\n                  out_pixel[0] = in_pixel[0],\n                  out_pixel[1] = in_pixel[1],\n                  out_pixel[2] = in_pixel[2],\n                  out_pixel[3] = in_pixel[3];\n            }\n         }\n         while (++x < image->width);\n      }\n      while (++y < image->height);\n   }\n}\n\nstatic int\ncreate_sprite(struct sprite *sprite, int *argc, const char ***argv)\n{\n   /* Read the arguments and create this sprite. The sprite buffer has already\n    * been allocated. This reads the input PNGs one by one in linear format,\n    * composes them onto the sprite buffer (the code in the function above)\n    * then saves the result, converting it on the fly to PNG RGBA 8-bit format.\n    */\n   while (*argc > 0)\n   {\n      char tombstone;\n      int x = 0, y = 0;\n\n      if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')\n      {\n         /* The only supported option is --at. */\n         if (sscanf((*argv)[0], \"--at=%d,%d%c\", &x, &y, &tombstone) != 2)\n            break; /* success; caller will parse this option */\n\n         ++*argv, --*argc;\n      }\n\n      else\n      {\n         /* The argument has to be a file name */\n         png_image image;\n\n         image.version = PNG_IMAGE_VERSION;\n         image.opaque = NULL;\n\n         if (png_image_begin_read_from_file(&image, (*argv)[0]))\n         {\n            png_uint_16p buffer;\n\n            image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;\n\n            buffer = malloc(PNG_IMAGE_SIZE(image));\n\n            if (buffer != NULL)\n            {\n               if (png_image_finish_read(&image, NULL/*background*/, buffer,\n                  0/*row_stride*/,\n                  NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))\n               {\n                  /* This is the place where the Porter-Duff 'Over' operator\n                   * needs to be done by this code.  In fact, any image\n                   * processing required can be done here; the data is in\n                   * the correct format (linear, 16-bit) and source and\n                   * destination are in memory.\n                   */\n                  sprite_op(sprite, x, y, &image, buffer);\n                  free(buffer);\n                  ++*argv, --*argc;\n                  /* And continue to the next argument */\n                  continue;\n               }\n\n               else\n               {\n                  free(buffer);\n                  fprintf(stderr, \"simpleover: read %s: %s\\n\", (*argv)[0],\n                      image.message);\n               }\n            }\n\n            else\n            {\n               fprintf(stderr, \"simpleover: out of memory: %lu bytes\\n\",\n                  (unsigned long)PNG_IMAGE_SIZE(image));\n\n               /* png_image_free must be called if we abort the Simplified API\n                * read because of a problem detected in this code.  If problems\n                * are detected in the Simplified API it cleans up itself.\n                */\n               png_image_free(&image);\n            }\n         }\n\n         else\n         {\n            /* Failed to read the first argument: */\n            fprintf(stderr, \"simpleover: %s: %s\\n\", (*argv)[0], image.message);\n         }\n\n         return 0; /* failure */\n      }\n   }\n\n   /* All the sprite operations have completed successfully. Save the RGBA\n    * buffer as a PNG using the simplified write API.\n    */\n   sprite->file = tmpfile();\n\n   if (sprite->file != NULL)\n   {\n      png_image save;\n\n      memset(&save, 0, sizeof save);\n      save.version = PNG_IMAGE_VERSION;\n      save.opaque = NULL;\n      save.width = sprite->width;\n      save.height = sprite->height;\n      save.format = PNG_FORMAT_LINEAR_RGB_ALPHA;\n      save.flags = PNG_IMAGE_FLAG_FAST;\n      save.colormap_entries = 0;\n\n      if (png_image_write_to_stdio(&save, sprite->file, 1/*convert_to_8_bit*/,\n          sprite->buffer, 0/*row_stride*/, NULL/*colormap*/))\n      {\n         /* Success; the buffer is no longer needed: */\n         free(sprite->buffer);\n         sprite->buffer = NULL;\n         return 1; /* ok */\n      }\n\n      else\n         fprintf(stderr, \"simpleover: write sprite %s: %s\\n\", sprite->name,\n            save.message);\n   }\n\n   else\n      fprintf(stderr, \"simpleover: sprite %s: could not allocate tmpfile: %s\\n\",\n         sprite->name, strerror(errno));\n\n   return 0; /* fail */\n}\n\nstatic int\nadd_sprite(png_imagep output, png_bytep out_buf, struct sprite *sprite,\n   int *argc, const char ***argv)\n{\n   /* Given a --add argument naming this sprite, perform the operations listed\n    * in the following arguments.  The arguments are expected to have the form\n    * (x,y), which is just an offset at which to add the sprite to the\n    * output.\n    */\n   while (*argc > 0)\n   {\n      char tombstone;\n      int x, y;\n\n      if ((*argv)[0][0] == '-' && (*argv)[0][1] == '-')\n         return 1; /* success */\n\n      if (sscanf((*argv)[0], \"%d,%d%c\", &x, &y, &tombstone) == 2)\n      {\n         /* Now add the new image into the sprite data, but only if it\n          * will fit.\n          */\n         if (x < 0 || y < 0 ||\n             (unsigned)/*SAFE*/x >= output->width ||\n             (unsigned)/*SAFE*/y >= output->height ||\n             sprite->width > output->width-x ||\n             sprite->height > output->height-y)\n         {\n            fprintf(stderr, \"simpleover: sprite %s @ (%d,%d) outside image\\n\",\n               sprite->name, x, y);\n            /* Could just skip this, but for the moment it is an error */\n            return 0; /* error */\n         }\n\n         else\n         {\n            /* Since we know the sprite fits we can just read it into the\n             * output using the simplified API.\n             */\n            png_image in;\n\n            in.version = PNG_IMAGE_VERSION;\n            rewind(sprite->file);\n\n            if (png_image_begin_read_from_stdio(&in, sprite->file))\n            {\n               in.format = PNG_FORMAT_RGB; /* force compose */\n\n               if (png_image_finish_read(&in, NULL/*background*/,\n                  out_buf + (y*output->width + x)*3/*RGB*/,\n                  output->width*3/*row_stride*/,\n                  NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP*/))\n               {\n                  ++*argv, --*argc;\n                  continue;\n               }\n            }\n\n            /* The read failed: */\n            fprintf(stderr, \"simpleover: add sprite %s: %s\\n\", sprite->name,\n                in.message);\n            return 0; /* error */\n         }\n      }\n\n      else\n      {\n         fprintf(stderr, \"simpleover: --add='%s': invalid position %s\\n\",\n               sprite->name, (*argv)[0]);\n         return 0; /* error */\n      }\n   }\n\n   return 1; /* ok */\n}\n\nstatic int\nsimpleover_process(png_imagep output, png_bytep out_buf, int argc,\n   const char **argv)\n{\n   int result = 1; /* success */\n#  define csprites 10/*limit*/\n#  define str(a) #a\n   int nsprites = 0;\n   struct sprite sprites[csprites];\n\n   while (argc > 0)\n   {\n      result = 0; /* fail */\n\n      if (strncmp(argv[0], \"--sprite=\", 9) == 0)\n      {\n         char tombstone;\n\n         if (nsprites < csprites)\n         {\n            int n;\n\n            sprites[nsprites].width = sprites[nsprites].height = 0;\n            sprites[nsprites].name[0] = 0;\n\n            n = sscanf(argv[0], \"--sprite=%u,%u,%\" str(sprite_name_chars) \"s%c\",\n                &sprites[nsprites].width, &sprites[nsprites].height,\n                sprites[nsprites].name, &tombstone);\n\n            if ((n == 2 || n == 3) &&\n                sprites[nsprites].width > 0 && sprites[nsprites].height > 0)\n            {\n               size_t buf_size, tmp;\n\n               /* Default a name if not given. */\n               if (sprites[nsprites].name[0] == 0)\n                  sprintf(sprites[nsprites].name, \"sprite-%d\", nsprites+1);\n\n               /* Allocate a buffer for the sprite and calculate the buffer\n                * size:\n                */\n               buf_size = sizeof (png_uint_16 [4]);\n               buf_size *= sprites[nsprites].width;\n               buf_size *= sprites[nsprites].height;\n\n               /* This can overflow a (size_t); check for this: */\n               tmp = buf_size;\n               tmp /= sprites[nsprites].width;\n               tmp /= sprites[nsprites].height;\n\n               if (tmp == sizeof (png_uint_16 [4]))\n               {\n                  sprites[nsprites].buffer = malloc(buf_size);\n                  /* This buffer must be initialized to transparent: */\n                  memset(sprites[nsprites].buffer, 0, buf_size);\n\n                  if (sprites[nsprites].buffer != NULL)\n                  {\n                     sprites[nsprites].file = NULL;\n                     ++argv, --argc;\n\n                     if (create_sprite(sprites+nsprites++, &argc, &argv))\n                     {\n                        result = 1; /* still ok */\n                        continue;\n                     }\n\n                     break; /* error */\n                  }\n               }\n\n               /* Overflow, or OOM */\n               fprintf(stderr, \"simpleover: %s: sprite too large\\n\", argv[0]);\n               break;\n            }\n\n            else\n            {\n               fprintf(stderr, \"simpleover: %s: invalid sprite (%u,%u)\\n\",\n                  argv[0], sprites[nsprites].width, sprites[nsprites].height);\n               break;\n            }\n         }\n\n         else\n         {\n            fprintf(stderr, \"simpleover: %s: too many sprites\\n\", argv[0]);\n            break;\n         }\n      }\n\n      else if (strncmp(argv[0], \"--add=\", 6) == 0)\n      {\n         const char *name = argv[0]+6;\n         int isprite = nsprites;\n\n         ++argv, --argc;\n\n         while (--isprite >= 0)\n         {\n            if (strcmp(sprites[isprite].name, name) == 0)\n            {\n               if (!add_sprite(output, out_buf, sprites+isprite, &argc, &argv))\n                  goto out; /* error in add_sprite */\n\n               break;\n            }\n         }\n\n         if (isprite < 0) /* sprite not found */\n         {\n            fprintf(stderr, \"simpleover: --add='%s': sprite not found\\n\", name);\n            break;\n         }\n      }\n\n      else\n      {\n         fprintf(stderr, \"simpleover: %s: unrecognized operation\\n\", argv[0]);\n         break;\n      }\n\n      result = 1; /* ok  */\n   }\n\n   /* Clean up the cache of sprites: */\nout:\n   while (--nsprites >= 0)\n   {\n      if (sprites[nsprites].buffer != NULL)\n         free(sprites[nsprites].buffer);\n\n      if (sprites[nsprites].file != NULL)\n         (void)fclose(sprites[nsprites].file);\n   }\n\n   return result;\n}\n\nint main(int argc, const char **argv)\n{\n   int result = 1; /* default to fail */\n\n   if (argc >= 2)\n   {\n      int argi = 2;\n      const char *output = NULL;\n      png_image image;\n\n      if (argc > 2 && argv[2][0] != '-'/*an operation*/)\n      {\n         output = argv[2];\n         argi = 3;\n      }\n\n      image.version = PNG_IMAGE_VERSION;\n      image.opaque = NULL;\n\n      if (png_image_begin_read_from_file(&image, argv[1]))\n      {\n         png_bytep buffer;\n\n         image.format = PNG_FORMAT_RGB; /* 24-bit RGB */\n\n         buffer = malloc(PNG_IMAGE_SIZE(image));\n\n         if (buffer != NULL)\n         {\n            png_color background = {0, 0xff, 0}; /* fully saturated green */\n\n            if (png_image_finish_read(&image, &background, buffer,\n               0/*row_stride*/, NULL/*colormap for PNG_FORMAT_FLAG_COLORMAP */))\n            {\n               /* At this point png_image_finish_read has cleaned up the\n                * allocated data in png_image, and only the buffer needs to be\n                * freed.\n                *\n                * Perform the remaining operations:\n                */\n               if (simpleover_process(&image, buffer, argc-argi, argv+argi))\n               {\n                  /* Write the output: */\n                  if ((output != NULL &&\n                       png_image_write_to_file(&image, output,\n                        0/*convert_to_8bit*/, buffer, 0/*row_stride*/,\n                        NULL/*colormap*/)) ||\n                      (output == NULL &&\n                       png_image_write_to_stdio(&image, stdout,\n                        0/*convert_to_8bit*/, buffer, 0/*row_stride*/,\n                        NULL/*colormap*/)))\n                     result = 0;\n\n                  else\n                     fprintf(stderr, \"simpleover: write %s: %s\\n\",\n                        output == NULL ? \"stdout\" : output, image.message);\n               }\n\n               /* else simpleover_process writes an error message */\n            }\n\n            else\n               fprintf(stderr, \"simpleover: read %s: %s\\n\", argv[1],\n                   image.message);\n\n            free(buffer);\n         }\n\n         else\n         {\n            fprintf(stderr, \"simpleover: out of memory: %lu bytes\\n\",\n               (unsigned long)PNG_IMAGE_SIZE(image));\n\n            /* This is the only place where a 'free' is required; libpng does\n             * the cleanup on error and success, but in this case we couldn't\n             * complete the read because of running out of memory.\n             */\n            png_image_free(&image);\n         }\n      }\n\n      else\n      {\n         /* Failed to read the first argument: */\n         fprintf(stderr, \"simpleover: %s: %s\\n\", argv[1], image.message);\n      }\n   }\n\n   else\n   {\n      /* Usage message */\n      fprintf(stderr,\n         \"simpleover: usage: simpleover background.png [output.png]\\n\"\n         \"  Output 'background.png' as a 24-bit RGB PNG file in 'output.png'\\n\"\n         \"   or, if not given, stdout.  'background.png' will be composited\\n\"\n         \"   on fully saturated green.\\n\"\n         \"\\n\"\n         \"  Optionally, before output, process additional PNG files:\\n\"\n         \"\\n\"\n         \"   --sprite=width,height,name {[--at=x,y] {sprite.png}}\\n\"\n         \"    Produce a transparent sprite of size (width,height) and with\\n\"\n         \"     name 'name'.\\n\"\n         \"    For each sprite.png composite it using a Porter-Duff 'Over'\\n\"\n         \"     operation at offset (x,y) in the sprite (defaulting to (0,0)).\\n\"\n         \"     Input PNGs will be truncated to the area of the sprite.\\n\"\n         \"\\n\"\n         \"   --add='name' {x,y}\\n\"\n         \"    Optionally, before output, composite a sprite, 'name', which\\n\"\n         \"     must have been previously produced using --sprite, at each\\n\"\n         \"     offset (x,y) in the output image.  Each sprite must fit\\n\"\n         \"     completely within the output image.\\n\"\n         \"\\n\"\n         \"  PNG files are processed in the order they occur on the command\\n\"\n         \"  line and thus the first PNG processed appears as the bottommost\\n\"\n         \"  in the output image.\\n\");\n   }\n\n   return result;\n}\n#endif /* SIMPLIFIED_READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/COPYING",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 2, June 1991\n\n Copyright (C) 1989, 1991 Free Software Foundation, Inc.\n     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicense is intended to guarantee your freedom to share and change free\nsoftware--to make sure the software is free for all its users.  This\nGeneral Public License applies to most of the Free Software\nFoundation's software and to any other program whose authors commit to\nusing it.  (Some other Free Software Foundation software is covered by\nthe GNU Library General Public License instead.)  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthis service if you wish), that you receive source code or can get it\nif you want it, that you can change the software or use pieces of it\nin new free programs; and that you know you can do these things.\n\n  To protect your rights, we need to make restrictions that forbid\nanyone to deny you these rights or to ask you to surrender the rights.\nThese restrictions translate to certain responsibilities for you if you\ndistribute copies of the software, or if you modify it.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must give the recipients all the rights that\nyou have.  You must make sure that they, too, receive or can get the\nsource code.  And you must show them these terms so they know their\nrights.\n\n  We protect your rights with two steps: (1) copyright the software, and\n(2) offer you this license which gives you legal permission to copy,\ndistribute and/or modify the software.\n\n  Also, for each author's protection and ours, we want to make certain\nthat everyone understands that there is no warranty for this free\nsoftware.  If the software is modified by someone else and passed on, we\nwant its recipients to know that what they have is not the original, so\nthat any problems introduced by others will not reflect on the original\nauthors' reputations.\n\n  Finally, any free program is threatened constantly by software\npatents.  We wish to avoid the danger that redistributors of a free\nprogram will individually obtain patent licenses, in effect making the\nprogram proprietary.  To prevent this, we have made it clear that any\npatent must be licensed for everyone's free use or not licensed at all.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\f\n                    GNU GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License applies to any program or other work which contains\na notice placed by the copyright holder saying it may be distributed\nunder the terms of this General Public License.  The \"Program\", below,\nrefers to any such program or work, and a \"work based on the Program\"\nmeans either the Program or any derivative work under copyright law:\nthat is to say, a work containing the Program or a portion of it,\neither verbatim or with modifications and/or translated into another\nlanguage.  (Hereinafter, translation is included without limitation in\nthe term \"modification\".)  Each licensee is addressed as \"you\".\n\nActivities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning the Program is not restricted, and the output from the Program\nis covered only if its contents constitute a work based on the\nProgram (independent of having been made by running the Program).\nWhether that is true depends on what the Program does.\n\n  1. You may copy and distribute verbatim copies of the Program's\nsource code as you receive it, in any medium, provided that you\nconspicuously and appropriately publish on each copy an appropriate\ncopyright notice and disclaimer of warranty; keep intact all the\nnotices that refer to this License and to the absence of any warranty;\nand give any other recipients of the Program a copy of this License\nalong with the Program.\n\nYou may charge a fee for the physical act of transferring a copy, and\nyou may at your option offer warranty protection in exchange for a fee.\n\n  2. You may modify your copy or copies of the Program or any portion\nof it, thus forming a work based on the Program, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) You must cause the modified files to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    b) You must cause any work that you distribute or publish, that in\n    whole or in part contains or is derived from the Program or any\n    part thereof, to be licensed as a whole at no charge to all third\n    parties under the terms of this License.\n\n    c) If the modified program normally reads commands interactively\n    when run, you must cause it, when started running for such\n    interactive use in the most ordinary way, to print or display an\n    announcement including an appropriate copyright notice and a\n    notice that there is no warranty (or else, saying that you provide\n    a warranty) and that users may redistribute the program under\n    these conditions, and telling the user how to view a copy of this\n    License.  (Exception: if the Program itself is interactive but\n    does not normally print such an announcement, your work based on\n    the Program is not required to print an announcement.)\n\f\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Program,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Program, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote it.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Program.\n\nIn addition, mere aggregation of another work not based on the Program\nwith the Program (or with a work based on the Program) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may copy and distribute the Program (or a work based on it,\nunder Section 2) in object code or executable form under the terms of\nSections 1 and 2 above provided that you also do one of the following:\n\n    a) Accompany it with the complete corresponding machine-readable\n    source code, which must be distributed under the terms of Sections\n    1 and 2 above on a medium customarily used for software interchange; or,\n\n    b) Accompany it with a written offer, valid for at least three\n    years, to give any third party, for a charge no more than your\n    cost of physically performing source distribution, a complete\n    machine-readable copy of the corresponding source code, to be\n    distributed under the terms of Sections 1 and 2 above on a medium\n    customarily used for software interchange; or,\n\n    c) Accompany it with the information you received as to the offer\n    to distribute corresponding source code.  (This alternative is\n    allowed only for noncommercial distribution and only if you\n    received the program in object code or executable form with such\n    an offer, in accord with Subsection b above.)\n\nThe source code for a work means the preferred form of the work for\nmaking modifications to it.  For an executable work, complete source\ncode means all the source code for all modules it contains, plus any\nassociated interface definition files, plus the scripts used to\ncontrol compilation and installation of the executable.  However, as a\nspecial exception, the source code distributed need not include\nanything that is normally distributed (in either source or binary\nform) with the major components (compiler, kernel, and so on) of the\noperating system on which the executable runs, unless that component\nitself accompanies the executable.\n\nIf distribution of executable or object code is made by offering\naccess to copy from a designated place, then offering equivalent\naccess to copy the source code from the same place counts as\ndistribution of the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\f\n  4. You may not copy, modify, sublicense, or distribute the Program\nexcept as expressly provided under this License.  Any attempt\notherwise to copy, modify, sublicense or distribute the Program is\nvoid, and will automatically terminate your rights under this License.\nHowever, parties who have received copies, or rights, from you under\nthis License will not have their licenses terminated so long as such\nparties remain in full compliance.\n\n  5. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Program or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Program (or any work based on the\nProgram), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Program or works based on it.\n\n  6. Each time you redistribute the Program (or any work based on the\nProgram), the recipient automatically receives a license from the\noriginal licensor to copy, distribute or modify the Program subject to\nthese terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties to\nthis License.\n\n  7. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Program at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Program by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Program.\n\nIf any portion of this section is held invalid or unenforceable under\nany particular circumstance, the balance of the section is intended to\napply and the section as a whole is intended to apply in other\ncircumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system, which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\f\n  8. If the distribution and/or use of the Program is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Program under this License\nmay add an explicit geographical distribution limitation excluding\nthose countries, so that distribution is permitted only in or among\ncountries not thus excluded.  In such case, this License incorporates\nthe limitation as if written in the body of this License.\n\n  9. The Free Software Foundation may publish revised and/or new versions\nof the General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Program\nspecifies a version number of this License which applies to it and \"any\nlater version\", you have the option of following the terms and conditions\neither of that version or of any later version published by the Free\nSoftware Foundation.  If the Program does not specify a version number of\nthis License, you may choose any version ever published by the Free Software\nFoundation.\n\n  10. If you wish to incorporate parts of the Program into other free\nprograms whose distribution conditions are different, write to the author\nto ask for permission.  For software which is copyrighted by the Free\nSoftware Foundation, write to the Free Software Foundation; we sometimes\nmake exceptions for this.  Our decision will be guided by the two goals\nof preserving the free status of all derivatives of our free software and\nof promoting the sharing and reuse of software generally.\n\n                            NO WARRANTY\n\n  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\nFOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\nOTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\nPROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\nOR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\nMERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\nTO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\nPROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\nREPAIR OR CORRECTION.\n\n  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\nREDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\nINCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\nOUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\nTO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\nYOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\nPROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\nPOSSIBILITY OF SUCH DAMAGES.\n\n                     END OF TERMS AND CONDITIONS\n\f\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software; you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation; either version 2 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program; if not, write to the Free Software\n    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n\nAlso add information on how to contact you by electronic and paper mail.\n\nIf the program is interactive, make it output a short notice like this\nwhen it starts in an interactive mode:\n\n    Gnomovision version 69, Copyright (C) year  name of author\n    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, the commands you use may\nbe called something other than `show w' and `show c'; they could even be\nmouse-clicks or menu items--whatever suits your program.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the program, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the program\n  `Gnomovision' (which makes passes at compilers) written by James Hacker.\n\n  <signature of Ty Coon>, 1 April 1989\n  Ty Coon, President of Vice\n\nThis General Public License does not permit incorporating your program into\nproprietary programs.  If your program is a subroutine library, you may\nconsider it more useful to permit linking proprietary applications with the\nlibrary.  If this is what you want to do, use the GNU Library General\nPublic License instead of this License.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/LICENSE",
    "content": "  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2008 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/Makefile.mingw32",
    "content": "# Sample makefile for rpng-win / rpng2-win / wpng using mingw32-gcc and make.\n# Greg Roelofs\n# Last modified:  2 June 2007\n#\n#\tThe programs built by this makefile are described in the book,\n#\t\"PNG:  The Definitive Guide,\" by Greg Roelofs (O'Reilly and\n#\tAssociates, 1999).  Go buy a copy, eh?  Well, OK, it's not\n#\tgenerally for sale anymore, but it's the thought that counts,\n#\tright?  (Hint:  http://www.libpng.org/pub/png/book/ )\n#\n# Invoke this makefile from a DOS-prompt window via:\n#\n#\tmake -f Makefile.mingw32\n#\n# This makefile assumes libpng and zlib have already been built or downloaded\n# and are in subdirectories at the same level as the current subdirectory\n# (as indicated by the PNGDIR and ZDIR macros below).  It makes no assumptions\n# at all about the mingw32 installation tree (W32DIR).  Edit as appropriate.\n#\n# Note that the names of the dynamic and static libpng and zlib libraries\n# used below may change in later releases of the libraries.  This makefile\n# builds both statically and dynamically linked executables by default.\n# (You need only one set, but for testing it can be handy to have both.)\n\n\n# macros --------------------------------------------------------------------\n\n#PNGDIR = ../..#\t\tfor libpng-x.y.z/contrib/gregbook builds\nPNGDIR = ../libpng-win32\nPNGINC = -I$(PNGDIR)\nPNGLIBd = $(PNGDIR)/libpng.dll.a\t# dynamically linked\nPNGLIBs = $(PNGDIR)/libpng.a\t\t# statically linked, local libpng\n\n#ZDIR = ../../../zlib-win32#\tfor libpng-x.y.z/contrib/gregbook builds\nZDIR = ../zlib-win32\nZINC = -I$(ZDIR)\nZLIBd = $(ZDIR)/libzdll.a\nZLIBs = $(ZDIR)/libz.a\n\n# change this to be the path where mingw32 installs its stuff:\nW32DIR =\n#W32DIR = /usr/local/cross-tools/i386-mingw32msvc\nW32INC = -I$(W32DIR)/include\nW32LIB = $(W32DIR)/lib/libuser32.a $(W32DIR)/lib/libgdi32.a\n\nCC = gcc\n#CC = i386-mingw32msvc-gcc #\te.g., Linux -> Win32 cross-compilation\nLD = $(CC)\nRM = rm -f\nCPPFLAGS = $(INCS)\nCFLAGS = -O -Wall $(MINGW_CCFLAGS)\n# [note that -Wall is a gcc-specific compilation flag (\"most warnings on\")]\n# [-ansi, -pedantic and -W can also be used]\nLDFLAGS = $(MINGW_LDFLAGS)\nO = .o\nE = .exe\n\nINCS = $(PNGINC) $(ZINC) $(W32INC)\nRLIBSd = $(PNGLIBd) $(ZLIBd) $(W32LIB) -lm\nRLIBSs = $(PNGLIBs) $(ZLIBs) $(W32LIB) -lm\nWLIBSd = $(PNGLIBd) $(ZLIBd)\nWLIBSs = $(PNGLIBs) $(ZLIBs)\n\nRPNG   = rpng-win\nRPNG2  = rpng2-win\nWPNG   = wpng\n\nROBJSd  = $(RPNG)$(O) readpng.pic$(O)\nROBJS2d = $(RPNG2)$(O) readpng2.pic$(O)\nWOBJSd  = $(WPNG)$(O) writepng.pic$(O)\n\nRPNGs  = $(RPNG)-static\nRPNG2s = $(RPNG2)-static\nWPNGs  = $(WPNG)-static\n\nROBJSs  = $(RPNG)$(O) readpng$(O)\nROBJS2s = $(RPNG2)$(O) readpng2$(O)\nWOBJSs  = $(WPNG)$(O) writepng$(O)\n\nSTATIC_EXES  = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)\nDYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)\n\nEXES = $(STATIC_EXES) $(DYNAMIC_EXES)\n\n\n# implicit make rules -------------------------------------------------------\n\n.c$(O):\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\n%.pic$(O): %.c\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -DPNG_BUILD_DLL -o $@ $<\n\n\n# dependencies --------------------------------------------------------------\n\nall:  $(EXES)\n\n$(RPNGs)$(E): $(ROBJSs)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJSs) $(RLIBSs)\n\n$(RPNG)$(E): $(ROBJSd)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJSd) $(RLIBSd)\n\n$(RPNG2s)$(E): $(ROBJS2s)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS2s) $(RLIBSs)\n\n$(RPNG2)$(E): $(ROBJS2d)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS2d) $(RLIBSd)\n\n$(WPNGs)$(E): $(WOBJSs)\n\t$(LD) $(LDFLAGS) -o $@ $(WOBJSs) $(WLIBSs)\n\n$(WPNG)$(E): $(WOBJSd)\n\t$(LD) $(LDFLAGS) -o $@ $(WOBJSd) $(WLIBSd)\n\n$(RPNG)$(O):\t$(RPNG).c readpng.h\n$(RPNG2)$(O):\t$(RPNG2).c readpng2.h\n$(WPNG)$(O):\t$(WPNG).c writepng.h\n\nreadpng$(O) readpng.pic$(O):\treadpng.c readpng.h\nreadpng2$(O) readpng2.pic$(O):\treadpng2.c readpng2.h\nwritepng$(O) writepng.pic$(O):\twritepng.c writepng.h\n\n\n# maintenance ---------------------------------------------------------------\n\nclean:\n\t$(RM) $(EXES)\n\t$(RM) $(ROBJSs) $(ROBJS2s) $(WOBJSs)\n\t$(RM) $(ROBJSd) $(ROBJS2d) $(WOBJSd)\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/Makefile.sgi",
    "content": "# Sample makefile for rpng-x / rpng2-x / wpng for SGI using cc and make.\n# Greg Roelofs\n# Last modified:  7 March 2002\n#\n#\tThe programs built by this makefile are described in the book,\n#\t\"PNG:  The Definitive Guide,\" by Greg Roelofs (O'Reilly and\n#\tAssociates, 1999).  Go buy a copy, eh?  Buy some for friends\n#\tand family, too.  (Not that this is a blatant plug or anything.)\n#\n# Invoke this makefile from a shell prompt in the usual way; for example:\n#\n#\tmake -f Makefile.sgi\n#\n# This makefile assumes libpng and zlib have already been built or downloaded\n# and are both installed in /usr/local/{include,lib} (as indicated by the\n# PNG* and Z* macros below).  Edit as appropriate--choose only ONE each of\n# the PNGINC, PNGLIB, ZINC and ZLIB lines.\n#\n# This makefile builds dynamically linked executables (against libpng and zlib,\n# that is), but that can be changed by uncommenting the appropriate PNGLIB and\n# ZLIB lines.\n\n\n# macros --------------------------------------------------------------------\n\nPNGINC = -I/usr/local/include/libpng16\nPNGLIB = -L/usr/local/lib -lpng16\t  # dynamically linked against libpng\n#PNGLIB = /usr/local/lib/libpng16.a # statically linked against libpng\n# or:\n#PNGINC = -I../..\n#PNGLIB = -L../.. -lpng\n#PNGLIB = ../../libpng.a\n\nZINC = -I/usr/local/include\nZLIB = -L/usr/local/lib -lz\t\t# dynamically linked against zlib\n#ZLIB = /usr/local/lib/libz.a\t\t# statically linked against zlib\n#ZINC = -I../zlib\n#ZLIB = -L../zlib -lz\n#ZLIB = ../../../zlib/libz.a\n\nXINC = -I/usr/include/X11\t\t# old-style, stock X distributions\nXLIB = -L/usr/lib/X11 -lX11\n#XINC = -I/usr/openwin/include    \t# Sun workstations (OpenWindows)\n#XLIB = -L/usr/openwin/lib -lX11\n#XINC = -I/usr/X11R6/include\t\t# new X distributions (XFree86, etc.)\n#XLIB = -L/usr/X11R6/lib -lX11\n\nINCS = $(PNGINC) $(ZINC) $(XINC)\nRLIBS = $(PNGLIB) $(ZLIB) $(XLIB) -lm\nWLIBS = $(PNGLIB) $(ZLIB)\n\nCC = cc\nLD = cc\nRM = rm -f\n# ABI must be the same as that used to build libpng.\nABI =\nCPPFLAGS =\nCFLAGS = $(ABI) -O -fullwarn $(INCS)\nLDFLAGS = $(ABI)\nO = .o\nE =\n\nRPNG  = rpng-x\nRPNG2 = rpng2-x\nWPNG  = wpng\n\nROBJS  = $(RPNG)$(O) readpng$(O)\nROBJS2 = $(RPNG2)$(O) readpng2$(O)\nWOBJS  = $(WPNG)$(O) writepng$(O)\n\nEXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)\n\n\n# implicit make rules -------------------------------------------------------\n\n.c$(O):\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\n\n# dependencies --------------------------------------------------------------\n\nall:  $(EXES)\n\n$(RPNG)$(E): $(ROBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBS)\n\n$(RPNG2)$(E): $(ROBJS2)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBS)\n\n$(WPNG)$(E): $(WOBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBS)\n\n$(RPNG)$(O):\t$(RPNG).c readpng.h\n$(RPNG2)$(O):\t$(RPNG2).c readpng2.h\n$(WPNG)$(O):\t$(WPNG).c writepng.h\n\nreadpng$(O):\treadpng.c readpng.h\nreadpng2$(O):\treadpng2.c readpng2.h\nwritepng$(O):\twritepng.c writepng.h\n\n\n# maintenance ---------------------------------------------------------------\n\nclean:\n\t$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/Makefile.unx",
    "content": "# Sample makefile for rpng-x / rpng2-x / wpng using gcc and make.\n# Greg Roelofs\n# Last modified:  2 June 2007\n#\n#\tThe programs built by this makefile are described in the book,\n#\t\"PNG:  The Definitive Guide,\" by Greg Roelofs (O'Reilly and\n#\tAssociates, 1999).  Go buy a copy, eh?  Well, OK, it's not\n#\tgenerally for sale anymore, but it's the thought that counts,\n#\tright?  (Hint:  http://www.libpng.org/pub/png/book/ )\n#\n# Invoke this makefile from a shell prompt in the usual way; for example:\n#\n#\tmake -f Makefile.unx\n#\n# This makefile assumes libpng and zlib have already been built or downloaded\n# and are installed in /usr/local/{include,lib} or as otherwise indicated by\n# the PNG* and Z* macros below.  Edit as appropriate--choose only ONE each of\n# the PNGINC, PNGLIBd, PNGLIBs, ZINC, ZLIBd and ZLIBs lines.\n#\n# This makefile builds both dynamically and statically linked executables\n# (against libpng and zlib, that is), but that can be changed by modifying\n# the \"EXES =\" line.  (You need only one set, but for testing it can be handy\n# to have both.)\n\n\n# macros --------------------------------------------------------------------\n\n#PNGDIR = /usr/local/lib\n#PNGINC = -I/usr/local/include/libpng16\n#PNGLIBd = -L$(PNGDIR) -lpng16 # dynamically linked, installed libpng\n#PNGLIBs = $(PNGDIR)/libpng16.a # statically linked, installed libpng\n# or:\nPNGDIR = ../..#\tthis one is for libpng-x.y.z/contrib/gregbook builds\n#PNGDIR = ../libpng\nPNGINC = -I$(PNGDIR)\nPNGLIBd = -Wl,-rpath,$(PNGDIR) -L$(PNGDIR) -lpng16\t# dynamically linked\nPNGLIBs = $(PNGDIR)/libpng.a\t\t# statically linked, local libpng\n\nZDIR = /usr/local/lib\n#ZDIR = /usr/lib64\nZINC = -I/usr/local/include\nZLIBd = -L$(ZDIR) -lz\t\t\t# dynamically linked against zlib\nZLIBs = $(ZDIR)/libz.a\t\t\t# statically linked against zlib\n# or:\n#ZDIR = ../zlib\n#ZINC = -I$(ZDIR)\n#ZLIBd = -Wl,-rpath,$(ZDIR) -L$(ZDIR) -lz  # -rpath allows in-place testing\n#ZLIBs = $(ZDIR)/libz.a\n\n#XINC = -I/usr/include\t\t\t# old-style, stock X distributions\n#XLIB = -L/usr/lib/X11 -lX11\t\t#  (including SGI IRIX)\n#XINC = -I/usr/openwin/include\t\t# Sun workstations (OpenWindows)\n#XLIB = -L/usr/openwin/lib -lX11\nXINC = -I/usr/X11R6/include\t\t# new X distributions (X.org, etc.)\nXLIB = -L/usr/X11R6/lib -lX11\n#XLIB = -L/usr/X11R6/lib64 -lX11\t# e.g., Red Hat on AMD64\n\nINCS = $(PNGINC) $(ZINC) $(XINC)\nRLIBSd = $(PNGLIBd) $(ZLIBd) $(XLIB) -lm\nRLIBSs = $(PNGLIBs) $(ZLIBs) $(XLIB) -lm\nWLIBSd = $(PNGLIBd) $(ZLIBd) -lm\nWLIBSs = $(PNGLIBs) $(ZLIBs) -lm\n\nCC = gcc\nLD = gcc\nRM = rm -f\nCPPFLAGS = $(INCS) -DFEATURE_LOOP\nCFLAGS = -O -Wall\n#CFLAGS = -O -W -Wall -Wextra -pedantic -ansi\n# [note that -Wall is a gcc-specific compilation flag (\"most warnings on\")]\n# [-ansi, -pedantic, -Wextra, and -W can also be used]\nLDFLAGS =\nO = .o\nE =\n\nRPNG   = rpng-x\nRPNG2  = rpng2-x\nWPNG   = wpng\n\nRPNGs  = $(RPNG)-static\nRPNG2s = $(RPNG2)-static\nWPNGs  = $(WPNG)-static\n\nROBJS  = $(RPNG)$(O) readpng$(O)\nROBJS2 = $(RPNG2)$(O) readpng2$(O)\nWOBJS  = $(WPNG)$(O) writepng$(O)\n\nSTATIC_EXES  = $(RPNGs)$(E) $(RPNG2s)$(E) $(WPNGs)$(E)\nDYNAMIC_EXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)\n\nEXES = $(STATIC_EXES) $(DYNAMIC_EXES)\n\n\n# implicit make rules -------------------------------------------------------\n\n.c$(O):\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\n\n# dependencies --------------------------------------------------------------\n\nall:  $(EXES)\n\n$(RPNGs)$(E): $(ROBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSs)\n\n$(RPNG)$(E): $(ROBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS) $(RLIBSd)\n\n$(RPNG2s)$(E): $(ROBJS2)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSs)\n\n$(RPNG2)$(E): $(ROBJS2)\n\t$(LD) $(LDFLAGS) -o $@ $(ROBJS2) $(RLIBSd)\n\n$(WPNGs)$(E): $(WOBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSs)\n\n$(WPNG)$(E): $(WOBJS)\n\t$(LD) $(LDFLAGS) -o $@ $(WOBJS) $(WLIBSd)\n\n$(RPNG)$(O):\t$(RPNG).c readpng.h\n$(RPNG2)$(O):\t$(RPNG2).c readpng2.h\n$(WPNG)$(O):\t$(WPNG).c writepng.h\n\nreadpng$(O):\treadpng.c readpng.h\nreadpng2$(O):\treadpng2.c readpng2.h\nwritepng$(O):\twritepng.c writepng.h\n\n\n# maintenance ---------------------------------------------------------------\n\nclean:\n\t$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/Makefile.w32",
    "content": "# Sample makefile for rpng-win / rpng2-win / wpng using MSVC and NMAKE.\n# Greg Roelofs\n# Last modified:  2 June 2007\n#\n#\tThe programs built by this makefile are described in the book,\n#\t\"PNG:  The Definitive Guide,\" by Greg Roelofs (O'Reilly and\n#\tAssociates, 1999).  Go buy a copy, eh?  Well, OK, it's not\n#\tgenerally for sale anymore, but it's the thought that counts,\n#\tright?  (Hint:  http://www.libpng.org/pub/png/book/ )\n#\n# Invoke this makefile from a DOS prompt window via:\n#\n#\t%devstudio%\\vc\\bin\\vcvars32.bat\n#\tnmake -nologo -f Makefile.w32\n#\n# where %devstudio% is the installation directory for MSVC / DevStudio.  If\n# you get \"environment out of space\" errors, create a desktop shortcut with\n# \"c:\\windows\\command.com /e:4096\" as the program command line and set the\n# working directory to this directory.  Then double-click to open the new\n# DOS-prompt window with a bigger environment and retry the commands above.\n#\n# This makefile assumes libpng and zlib have already been built or downloaded\n# and are in subdirectories at the same level as the current subdirectory\n# (as indicated by the PNGPATH and ZPATH macros below).  Edit as appropriate.\n#\n# Note that the names of the dynamic and static libpng and zlib libraries\n# used below may change in later releases of the libraries.  This makefile\n# builds statically linked executables, but that can be changed by uncom-\n# menting the appropriate PNGLIB and ZLIB lines.\n\n!include <ntwin32.mak>\n\n\n# macros --------------------------------------------------------------------\n\nPNGPATH = ../libpng\nPNGINC = -I$(PNGPATH)\n#PNGLIB = $(PNGPATH)/pngdll.lib\nPNGLIB = $(PNGPATH)/libpng.lib\n\nZPATH = ../zlib\nZINC = -I$(ZPATH)\n#ZLIB = $(ZPATH)/zlibdll.lib\nZLIB = $(ZPATH)/zlibstat.lib\n\nWINLIBS = -defaultlib:user32.lib gdi32.lib\n# [\"real\" apps may also need comctl32.lib, comdlg32.lib, winmm.lib, etc.]\n\nINCS = $(PNGINC) $(ZINC)\nRLIBS = $(PNGLIB) $(ZLIB) $(WINLIBS)\nWLIBS = $(PNGLIB) $(ZLIB)\n\nCC = cl\nLD = link\nRM = del\nCPPFLAGS = $(INCS)\nCFLAGS = -nologo -O -W3 $(cvars)\n# [note that -W3 is an MSVC-specific compilation flag (\"all warnings on\")]\n# [see %devstudio%\\vc\\include\\win32.mak for cvars macro definition]\nO = .obj\nE = .exe\n\nRLDFLAGS = -nologo -subsystem:windows\nWLDFLAGS = -nologo\n\nRPNG  = rpng-win\nRPNG2 = rpng2-win\nWPNG  = wpng\n\nROBJS  = $(RPNG)$(O) readpng$(O)\nROBJS2 = $(RPNG2)$(O) readpng2$(O)\nWOBJS  = $(WPNG)$(O) writepng$(O)\n\nEXES = $(RPNG)$(E) $(RPNG2)$(E) $(WPNG)$(E)\n\n\n# implicit make rules -------------------------------------------------------\n\n.c$(O):\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\n\n# dependencies --------------------------------------------------------------\n\nall:  $(EXES)\n\n$(RPNG)$(E): $(ROBJS)\n\t$(LD) $(RLDFLAGS) -out:$@ $(ROBJS) $(RLIBS)\n\n$(RPNG2)$(E): $(ROBJS2)\n\t$(LD) $(RLDFLAGS) -out:$@ $(ROBJS2) $(RLIBS)\n\n$(WPNG)$(E): $(WOBJS)\n\t$(LD) $(WLDFLAGS) -out:$@ $(WOBJS) $(WLIBS)\n\n$(RPNG)$(O):\t$(RPNG).c readpng.h\n$(RPNG2)$(O):\t$(RPNG2).c readpng2.h\n$(WPNG)$(O):\t$(WPNG).c writepng.h\n\nreadpng$(O):\treadpng.c readpng.h\nreadpng2$(O):\treadpng2.c readpng2.h\nwritepng$(O):\twritepng.c writepng.h\n\n\n# maintenance ---------------------------------------------------------------\n\nclean:\n#\tideally we could just do this:\n#\t$(RM) $(EXES) $(ROBJS) $(ROBJS2) $(WOBJS)\n#\t...but the Windows \"DEL\" command is none too bright, so:\n\t$(RM) r*$(E)\n\t$(RM) w*$(E)\n\t$(RM) r*$(O)\n\t$(RM) w*$(O)\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/README",
    "content": "                     ===========================\n                      PNG: The Definitive Guide\n                     ===========================\n\n                             Source Code\n\nChapters 13, 14 and 15 of \"PNG: The Definitive Guide\" discuss three free,\ncross-platform demo programs that show how to use the libpng reference\nlibrary:  rpng, rpng2 and wpng.  rpng and rpng2 are viewers; the first is\na very simple example that that shows how a standard file-viewer might use\nlibpng, while the second is designed to process streaming data and shows\nhow a web browser might be written.  wpng is a simple command-line program\nthat reads binary PGM and PPM files (the ``raw'' grayscale and RGB subsets\nof PBMPLUS/NetPBM) and converts them to PNG.\n\nThe source code for all three demo programs currently compiles under\nUnix, OpenVMS, and 32-bit Windows.  (Special thanks to Martin Zinser,\nzinser@decus.de, for making the necessary changes for OpenVMS and for\nproviding an appropriate build script.)  Build instructions can be found\nbelow.\n\nFiles:\n\n   README             this file\n   LICENSE            terms of distribution and reuse (BSD-like or GNU GPL)\n   COPYING            GNU General Public License (GPL)\n\n   Makefile.unx       Unix makefile\n   Makefile.w32       Windows (MSVC) makefile\n   makevms.com        OpenVMS build script\n\n   rpng-win.c         Windows front end for the basic viewer\n   rpng-x.c           X Window System (Unix, OpenVMS) front end\n   readpng.c          generic back end for the basic viewer\n   readpng.h          header file for the basic viewer\n\n   rpng2-win.c        Windows front end for the progressive viewer\n   rpng2-x.c          X front end for the progressive viewer\n   readpng2.c         generic back end for the progressive viewer\n   readpng2.h         header file for the progressive viewer\n\n   wpng.c             generic (text) front end for the converter\n   writepng.c         generic back end for the converter\n   writepng.h         header file for the converter\n\n   toucan.png         transparent PNG for testing (by Stefan Schneider)\n\nNote that, although the programs are designed to be functional, their\nprimary purpose is to illustrate how to use libpng to add PNG support to\nother programs.  As such, their user interfaces are crude and definitely\nare not intended for everyday use.\n\nPlease see http://www.libpng.org/pub/png/pngbook.html for further infor-\nmation and links to the latest version of the source code, and Chapters\n13-15 of the book for detailed discussion of the three programs.\n\nGreg Roelofs\nhttp://pobox.com/~newt/greg_contact.html\n16 March 2008\n\n\nBUILD INSTRUCTIONS\n\n - Prerequisites (in order of compilation):\n\n      - zlib            http://zlib.net/\n      - libpng          http://www.libpng.org/pub/png/libpng.html\n      - pngbook         http://www.libpng.org/pub/png/book/sources.html\n\n     The pngbook demo programs are explicitly designed to demonstrate proper\n     coding techniques for using the libpng reference library.  As a result,\n     you need to download and build both zlib (on which libpng depends) and\n     libpng.  A common build setup is to place the zlib, libpng and pngbook\n     subdirectory trees (\"folders\") in the same parent directory.  Then the\n     libpng build can refer to files in ../zlib (or ..\\zlib or [-.zlib]),\n     and similarly for the pngbook build.\n\n     Note that all three packages are designed to be built from a command\n     line by default; those who wish to use a graphical or other integrated\n     development environments are on their own.\n\n\n - Unix:\n\n     Unpack the latest pngbook sources (which should correspond to this\n     README file) into a directory and change into that directory.\n\n     Copy Makefile.unx to Makefile and edit the PNG* and Z* variables\n     appropriately (possibly also the X* variables if necessary).\n\n     make\n\n     There is no \"install\" target, so copy the three executables somewhere\n     in your path or run them from the current directory.  All three will\n     print a basic usage screen when run without any command-line arguments;\n     see the book for more details.\n\n\n - Windows:\n\n     Unpack the latest pngbook sources (which should correspond to this\n     README file) into a folder, open a \"DOS shell\" or \"command prompt\"\n     or equivalent command-line window, and cd into the folder where you\n     unpacked the source code.\n\n     For MSVC, set up the necessary environment variables by invoking\n\n        %devstudio%\\vc\\bin\\vcvars32.bat\n\n     where where %devstudio% is the installation directory for MSVC /\n     DevStudio.  If you get \"environment out of space\" errors under 95/98,\n     create a desktop shortcut with \"c:\\windows\\command.com /e:4096\" as\n     the program command line and set the working directory to the pngbook\n     directory.  Then double-click to open the new DOS-prompt window with\n     a bigger environment and retry the commands above.\n\n     Copy Makefile.w32 to Makefile and edit the PNGPATH and ZPATH variables\n     appropriately (possibly also the \"INC\" and \"LIB\" variables if needed).\n     Note that the names of the dynamic and static libpng and zlib libraries\n     used in the makefile may change in later releases of the libraries.\n     Also note that, as of libpng version 1.0.5, MSVC DLL builds do not work.\n     This makefile therefore builds statically linked executables, but if\n     the DLL problems ever get fixed, uncommenting the appropriate PNGLIB\n     and ZLIB lines will build dynamically linked executables instead.\n\n     Do the build by typing\n\n        nmake\n\n     The result should be three executables:  rpng-win.exe, rpng2-win.exe,\n     and wpng.exe.  Copy them somewhere in your PATH or run them from the\n     current folder.  Like the Unix versions, the two windowed programs\n     (rpng and rpng2) now display a usage screen in a console window when\n     invoked without command-line arguments; this is new behavior as of\n     the June 2001 release.  Note that the programs use the Unix-style \"-\"\n     character to specify options, instead of the more common DOS/Windows\n     \"/\" character.  (For example:  \"rpng2-win -bgpat 4 foo.png\", not\n     \"rpng2-win /bgpat 4 foo.png\")\n\n\n - OpenVMS:\n\n     Unpack the pngbook sources into a subdirectory and change into that\n     subdirectory.\n\n     Edit makevms.com appropriately, specifically the zpath and pngpath\n     variables.\n\n     @makevms\n\n     To run the programs, they probably first need to be set up as \"foreign\n     symbols,\" with \"disk\" and \"dir\" set appropriately:\n\n     $ rpng  == \"$disk:[dir]rpng-x.exe\"\n     $ rpng2 == \"$disk:[dir]rpng2-x.exe\"\n     $ wpng  == \"$disk:[dir]wpng.exe\"\n\n     All three will print a basic usage screen when run without any command-\n     line arguments; see the book for more details.  Note that the options\n     style is Unix-like, i.e., preceded by \"-\" rather than \"/\".\n\n\nRUNNING THE PROGRAMS:  (VERY) BRIEF INTRO\n\n     rpng is a simple PNG viewer that can display transparent PNGs with a\n     specified background color; for example,\n\n        rpng -bgcolor \\#ff0000 toucan.png\n\n     would display the image with a red background.  rpng2 is a progressive\n     viewer that simulates a web browser in some respects; it can display\n     images against either a background color or a dynamically generated\n     background image.  For example:\n\n        rpng2 -bgpat 16 toucan.png\n\n     wpng is a purely command-line image converter from binary PBMPLUS/NetPBM\n     format (.pgm or .ppm) to PNG; for example,\n\n        wpng -time < toucan-notrans.ppm > toucan-notrans.png\n\n     would convert the specified PPM file (using redirection) to PNG, auto-\n     matically setting the PNG modification-time chunk.\n\n     All options can be abbreviated to the shortest unique value; for example,\n     \"-bgc\" for -bgcolor (versus \"-bgp\" for -bgpat), or \"-g\" for -gamma.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/makevms.com",
    "content": "$!------------------------------------------------------------------------------\n$! make \"PNG: The Definitive Guide\" demo programs (for X) under OpenVMS\n$!\n$! Script created by Martin Zinser for libpng; modified by Greg Roelofs\n$! for standalone pngbook source distribution.\n$!\n$!\n$!    Set locations where zlib and libpng sources live.\n$!\n$ zpath   = \"\"\n$ pngpath = \"\"\n$!\n$ if f$search(\"[---.zlib]zlib.h\").nes.\"\" then zpath = \"[---.zlib]\"\n$ if f$search(\"[--]png.h\").nes.\"\" then pngpath = \"[--]\"\n$!\n$ if f$search(\"[-.zlib]zlib.h\").nes.\"\" then zpath = \"[-.zlib]\"\n$ if f$search(\"[-.libpng]png.h\").nes.\"\" then pngpath = \"[-.libpng]\"\n$!\n$ if zpath .eqs. \"\"\n$ then\n$   write sys$output \"zlib include not found. Exiting...\"\n$   exit 2\n$ endif\n$!\n$ if pngpath .eqs. \"\"\n$ then\n$   write sys$output \"libpng include not found. Exiting...\"\n$   exit 2\n$ endif\n$!\n$!    Look for the compiler used.\n$!\n$ ccopt=\"/include=(''zpath',''pngpath')\"\n$ if f$getsyi(\"HW_MODEL\").ge.1024\n$ then\n$  ccopt = \"/prefix=all\"+ccopt\n$  comp  = \"__decc__=1\"\n$  if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$ else\n$  if f$search(\"SYS$SYSTEM:DECC$COMPILER.EXE\").eqs.\"\"\n$   then\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$    if f$search(\"SYS$SYSTEM:VAXC.EXE\").eqs.\"\"\n$     then\n$      comp  = \"__gcc__=1\"\n$      CC :== GCC\n$     else\n$      comp = \"__vaxc__=1\"\n$     endif\n$   else\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys decc$library_include:\n$    ccopt = \"/decc/prefix=all\"+ccopt\n$    comp  = \"__decc__=1\"\n$  endif\n$ endif\n$ open/write lopt lib.opt\n$ write lopt \"''pngpath'libpng.olb/lib\"\n$ write lopt \"''zpath'libz.olb/lib\"\n$ close lopt\n$ open/write xopt x11.opt\n$ write xopt \"sys$library:decw$xlibshr.exe/share\"\n$ close xopt\n$!\n$!    Build 'em.\n$!\n$ write sys$output \"Compiling PNG book programs ...\"\n$   CALL MAKE readpng.OBJ \"cc ''CCOPT' readpng\" -\n\treadpng.c readpng.h\n$   CALL MAKE readpng2.OBJ \"cc ''CCOPT' readpng2\" -\n\treadpng2.c readpng2.h\n$   CALL MAKE writepng.OBJ \"cc ''CCOPT' writepng\" -\n\twritepng.c writepng.h\n$   write sys$output \"Building rpng-x...\"\n$   CALL MAKE rpng-x.OBJ \"cc ''CCOPT' rpng-x\" -\n\trpng-x.c readpng.h\n$   call make rpng-x.exe -\n\t\"LINK rpng-x,readpng,lib.opt/opt,x11.opt/opt\" -\n\trpng-x.obj readpng.obj\n$   write sys$output \"Building rpng2-x...\"\n$   CALL MAKE rpng2-x.OBJ \"cc ''CCOPT' rpng2-x\" -\n\trpng2-x.c readpng2.h\n$   call make rpng2-x.exe -\n\t\"LINK rpng2-x,readpng2,lib.opt/opt,x11.opt/opt\" -\n\trpng2-x.obj readpng2.obj\n$   write sys$output \"Building wpng...\"\n$   CALL MAKE wpng.OBJ \"cc ''CCOPT' wpng\" -\n\twpng.c writepng.h\n$   call make wpng.exe -\n\t\"LINK wpng,writepng,lib.opt/opt\" -\n\twpng.obj writepng.obj\n$ exit\n$!\n$!\n$MAKE: SUBROUTINE   !SUBROUTINE TO CHECK DEPENDENCIES\n$ V = 'F$Verify(0)\n$! P1 = What we are trying to make\n$! P2 = Command to make it\n$! P3 - P8  What it depends on\n$\n$ If F$Search(P1) .Eqs. \"\" Then Goto Makeit\n$ Time = F$CvTime(F$File(P1,\"RDT\"))\n$arg=3\n$Loop:\n$       Argument = P'arg\n$       If Argument .Eqs. \"\" Then Goto Exit\n$       El=0\n$Loop2:\n$       File = F$Element(El,\" \",Argument)\n$       If File .Eqs. \" \" Then Goto Endl\n$       AFile = \"\"\n$Loop3:\n$       OFile = AFile\n$       AFile = F$Search(File)\n$       If AFile .Eqs. \"\" .Or. AFile .Eqs. OFile Then Goto NextEl\n$       If F$CvTime(F$File(AFile,\"RDT\")) .Ges. Time Then Goto Makeit\n$       Goto Loop3\n$NextEL:\n$       El = El + 1\n$       Goto Loop2\n$EndL:\n$ arg=arg+1\n$ If arg .Le. 8 Then Goto Loop\n$ Goto Exit\n$\n$Makeit:\n$ VV=F$VERIFY(0)\n$ write sys$output P2\n$ 'P2\n$ VV='F$Verify(VV)\n$Exit:\n$ If V Then Set Verify\n$ENDSUBROUTINE\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/readpng.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng - simple PNG display program                              readpng.c\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <zlib.h>\n\n#include \"png.h\"        /* libpng header */\n#include \"readpng.h\"    /* typedefs, common macros, public prototypes */\n\n/* future versions of libpng will provide this macro: */\n#ifndef png_jmpbuf\n#  define png_jmpbuf(png_ptr)   ((png_ptr)->jmpbuf)\n#endif\n\n\nstatic png_structp png_ptr = NULL;\nstatic png_infop info_ptr = NULL;\n\npng_uint_32  width, height;\nint  bit_depth, color_type;\nuch  *image_data = NULL;\n\n\nvoid readpng_version_info(void)\n{\n    fprintf(stderr, \"   Compiled with libpng %s; using libpng %s.\\n\",\n      PNG_LIBPNG_VER_STRING, png_libpng_ver);\n    fprintf(stderr, \"   Compiled with zlib %s; using zlib %s.\\n\",\n      ZLIB_VERSION, zlib_version);\n}\n\n\n/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */\n\nint readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)\n{\n    uch sig[8];\n\n\n    /* first do a quick check that the file really is a PNG image; could\n     * have used slightly more general png_sig_cmp() function instead */\n\n    fread(sig, 1, 8, infile);\n    if (png_sig_cmp(sig, 0, 8))\n        return 1;   /* bad signature */\n\n\n    /* could pass pointers to user-defined error handlers instead of NULLs: */\n\n    png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), NULL, NULL,\n        NULL);\n    if (!png_ptr)\n        return 4;   /* out of memory */\n\n    info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr) {\n        png_destroy_read_struct(&png_ptr, NULL, NULL);\n        return 4;   /* out of memory */\n    }\n\n\n    /* we could create a second info struct here (end_info), but it's only\n     * useful if we want to keep pre- and post-IDAT chunk info separated\n     * (mainly for PNG-aware image editors and converters) */\n\n\n    /* setjmp() must be called in every function that calls a PNG-reading\n     * libpng function */\n\n    if (setjmp(png_jmpbuf(png_ptr))) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        return 2;\n    }\n\n\n    png_init_io(png_ptr, infile);\n    png_set_sig_bytes(png_ptr, 8);  /* we already read the 8 signature bytes */\n\n    png_read_info(png_ptr, info_ptr);  /* read all PNG info up to image data */\n\n\n    /* alternatively, could make separate calls to png_get_image_width(),\n     * etc., but want bit_depth and color_type for later [don't care about\n     * compression_type and filter_type => NULLs] */\n\n    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,\n      NULL, NULL, NULL);\n    *pWidth = width;\n    *pHeight = height;\n\n\n    /* OK, that's all we need for now; return happy */\n\n    return 0;\n}\n\n\n\n\n/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;\n * scales values to 8-bit if necessary */\n\nint readpng_get_bgcolor(uch *red, uch *green, uch *blue)\n{\n    png_color_16p pBackground;\n\n\n    /* setjmp() must be called in every function that calls a PNG-reading\n     * libpng function */\n\n    if (setjmp(png_jmpbuf(png_ptr))) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        return 2;\n    }\n\n\n    if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_bKGD))\n        return 1;\n\n    /* it is not obvious from the libpng documentation, but this function\n     * takes a pointer to a pointer, and it always returns valid red, green\n     * and blue values, regardless of color_type: */\n\n    png_get_bKGD(png_ptr, info_ptr, &pBackground);\n\n\n    /* however, it always returns the raw bKGD data, regardless of any\n     * bit-depth transformations, so check depth and adjust if necessary */\n\n    if (bit_depth == 16) {\n        *red   = pBackground->red   >> 8;\n        *green = pBackground->green >> 8;\n        *blue  = pBackground->blue  >> 8;\n    } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {\n        if (bit_depth == 1)\n            *red = *green = *blue = pBackground->gray? 255 : 0;\n        else if (bit_depth == 2)\n            *red = *green = *blue = (255/3) * pBackground->gray;\n        else /* bit_depth == 4 */\n            *red = *green = *blue = (255/15) * pBackground->gray;\n    } else {\n        *red   = (uch)pBackground->red;\n        *green = (uch)pBackground->green;\n        *blue  = (uch)pBackground->blue;\n    }\n\n    return 0;\n}\n\n\n\n\n/* display_exponent == LUT_exponent * CRT_exponent */\n\nuch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)\n{\n    double  gamma;\n    png_uint_32  i, rowbytes;\n    png_bytepp  row_pointers = NULL;\n\n\n    /* setjmp() must be called in every function that calls a PNG-reading\n     * libpng function */\n\n    if (setjmp(png_jmpbuf(png_ptr))) {\n        free(image_data);\n        image_data = NULL;\n        free(row_pointers);\n        row_pointers = NULL;\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        return NULL;\n    }\n\n\n    /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,\n     * transparency chunks to full alpha channel; strip 16-bit-per-sample\n     * images to 8 bits per sample; and convert grayscale to RGB[A] */\n\n    if (color_type == PNG_COLOR_TYPE_PALETTE)\n        png_set_expand(png_ptr);\n    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)\n        png_set_expand(png_ptr);\n    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))\n        png_set_expand(png_ptr);\n#ifdef PNG_READ_16_TO_8_SUPPORTED\n    if (bit_depth == 16)\n#  ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n        png_set_scale_16(png_ptr);\n#  else\n        png_set_strip_16(png_ptr);\n#  endif\n#endif\n    if (color_type == PNG_COLOR_TYPE_GRAY ||\n        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n        png_set_gray_to_rgb(png_ptr);\n\n\n    /* unlike the example in the libpng documentation, we have *no* idea where\n     * this file may have come from--so if it doesn't have a file gamma, don't\n     * do any correction (\"do no harm\") */\n\n    if (png_get_gAMA(png_ptr, info_ptr, &gamma))\n        png_set_gamma(png_ptr, display_exponent, gamma);\n\n\n    /* all transformations have been registered; now update info_ptr data,\n     * get rowbytes and channels, and allocate image memory */\n\n    png_read_update_info(png_ptr, info_ptr);\n\n    *pRowbytes = rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n    *pChannels = (int)png_get_channels(png_ptr, info_ptr);\n\n    if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        return NULL;\n    }\n    if ((row_pointers = (png_bytepp)malloc(height*sizeof(png_bytep))) == NULL) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        free(image_data);\n        image_data = NULL;\n        return NULL;\n    }\n\n    Trace((stderr, \"readpng_get_image:  channels = %d, rowbytes = %ld, height = %ld\\n\",\n        *pChannels, rowbytes, height));\n\n\n    /* set the individual row_pointers to point at the correct offsets */\n\n    for (i = 0;  i < height;  ++i)\n        row_pointers[i] = image_data + i*rowbytes;\n\n\n    /* now we can go ahead and just read the whole image */\n\n    png_read_image(png_ptr, row_pointers);\n\n\n    /* and we're done!  (png_read_end() can be omitted if no processing of\n     * post-IDAT text/time/etc. is desired) */\n\n    free(row_pointers);\n    row_pointers = NULL;\n\n    png_read_end(png_ptr, NULL);\n\n    return image_data;\n}\n\n\nvoid readpng_cleanup(int free_image_data)\n{\n    if (free_image_data && image_data) {\n        free(image_data);\n        image_data = NULL;\n    }\n\n    if (png_ptr && info_ptr) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        png_ptr = NULL;\n        info_ptr = NULL;\n    }\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/readpng.h",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng - simple PNG display program                              readpng.h\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#ifndef TRUE\n#  define TRUE 1\n#  define FALSE 0\n#endif\n\n#ifndef MAX\n#  define MAX(a,b)  ((a) > (b)? (a) : (b))\n#  define MIN(a,b)  ((a) < (b)? (a) : (b))\n#endif\n\n#ifdef DEBUG\n#  define Trace(x)  {fprintf x ; fflush(stderr); fflush(stdout);}\n#else\n#  define Trace(x)  ;\n#endif\n\ntypedef unsigned char   uch;\ntypedef unsigned short  ush;\ntypedef unsigned long   ulg;\n\n\n/* prototypes for public functions in readpng.c */\n\nvoid readpng_version_info(void);\n\nint readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight);\n\nint readpng_get_bgcolor(uch *bg_red, uch *bg_green, uch *bg_blue);\n\nuch *readpng_get_image(double display_exponent, int *pChannels,\n                       ulg *pRowbytes);\n\nvoid readpng_cleanup(int free_image_data);\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/readpng2.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng2 - progressive-model PNG display program                 readpng2.c\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2015 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n     2015-11-12 - Check return value of png_get_bKGD() (Glenn R-P)\n\n  ---------------------------------------------------------------------------*/\n\n\n#include <stdlib.h>     /* for exit() prototype */\n#include <setjmp.h>\n\n#include <zlib.h>\n#include \"png.h\"        /* libpng header from the local directory */\n#include \"readpng2.h\"   /* typedefs, common macros, public prototypes */\n\n\n/* local prototypes */\n\nstatic void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr);\nstatic void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,\n                                 png_uint_32 row_num, int pass);\nstatic void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr);\nstatic void readpng2_error_handler(png_structp png_ptr, png_const_charp msg);\nstatic void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg);\n\n\n\n\nvoid readpng2_version_info(void)\n{\n    fprintf(stderr, \"   Compiled with libpng %s; using libpng %s\\n\",\n      PNG_LIBPNG_VER_STRING, png_libpng_ver);\n\n    fprintf(stderr, \"   and with zlib %s; using zlib %s.\\n\",\n      ZLIB_VERSION, zlib_version);\n}\n\n\n\n\nint readpng2_check_sig(uch *sig, int num)\n{\n    return !png_sig_cmp(sig, 0, num);\n}\n\n\n\n\n/* returns 0 for success, 2 for libpng problem, 4 for out of memory */\n\nint readpng2_init(mainprog_info *mainprog_ptr)\n{\n    png_structp  png_ptr;       /* note:  temporary variables! */\n    png_infop  info_ptr;\n\n\n    /* could also replace libpng warning-handler (final NULL), but no need: */\n\n    png_ptr = png_create_read_struct(png_get_libpng_ver(NULL), mainprog_ptr,\n      readpng2_error_handler, readpng2_warning_handler);\n    if (!png_ptr)\n        return 4;   /* out of memory */\n\n    info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr) {\n        png_destroy_read_struct(&png_ptr, NULL, NULL);\n        return 4;   /* out of memory */\n    }\n\n\n    /* we could create a second info struct here (end_info), but it's only\n     * useful if we want to keep pre- and post-IDAT chunk info separated\n     * (mainly for PNG-aware image editors and converters) */\n\n\n    /* setjmp() must be called in every function that calls a PNG-reading\n     * libpng function, unless an alternate error handler was installed--\n     * but compatible error handlers must either use longjmp() themselves\n     * (as in this program) or exit immediately, so here we are: */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        return 2;\n    }\n\n\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n    /* prepare the reader to ignore all recognized chunks whose data won't be\n     * used, i.e., all chunks recognized by libpng except for IHDR, PLTE, IDAT,\n     * IEND, tRNS, bKGD, gAMA, and sRGB (small performance improvement) */\n    {\n        /* These byte strings were copied from png.h.  If a future version\n         * of readpng2.c recognizes more chunks, add them to this list.\n         */\n        static PNG_CONST png_byte chunks_to_process[] = {\n            98,  75,  71,  68, '\\0',  /* bKGD */\n           103,  65,  77,  65, '\\0',  /* gAMA */\n           115,  82,  71,  66, '\\0',  /* sRGB */\n           };\n\n       /* Ignore all chunks except for IHDR, PLTE, tRNS, IDAT, and IEND */\n       png_set_keep_unknown_chunks(png_ptr, -1 /* PNG_HANDLE_CHUNK_NEVER */,\n          NULL, -1);\n\n       /* But do not ignore chunks in the \"chunks_to_process\" list */\n       png_set_keep_unknown_chunks(png_ptr,\n          0 /* PNG_HANDLE_CHUNK_AS_DEFAULT */, chunks_to_process,\n          sizeof(chunks_to_process)/5);\n    }\n#endif /* PNG_HANDLE_AS_UNKNOWN_SUPPORTED */\n\n\n    /* instead of doing png_init_io() here, now we set up our callback\n     * functions for progressive decoding */\n\n    png_set_progressive_read_fn(png_ptr, mainprog_ptr,\n      readpng2_info_callback, readpng2_row_callback, readpng2_end_callback);\n\n\n    /* make sure we save our pointers for use in readpng2_decode_data() */\n\n    mainprog_ptr->png_ptr = png_ptr;\n    mainprog_ptr->info_ptr = info_ptr;\n\n\n    /* and that's all there is to initialization */\n\n    return 0;\n}\n\n\n\n\n/* returns 0 for success, 2 for libpng (longjmp) problem */\n\nint readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length)\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n\n    /* setjmp() must be called in every function that calls a PNG-reading\n     * libpng function */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n        mainprog_ptr->png_ptr = NULL;\n        mainprog_ptr->info_ptr = NULL;\n        return 2;\n    }\n\n\n    /* hand off the next chunk of input data to libpng for decoding */\n\n    png_process_data(png_ptr, info_ptr, rawbuf, length);\n\n    return 0;\n}\n\n\n\n\nstatic void readpng2_info_callback(png_structp png_ptr, png_infop info_ptr)\n{\n    mainprog_info  *mainprog_ptr;\n    int  color_type, bit_depth;\n    png_uint_32 width, height;\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n    double  gamma;\n#else\n    png_fixed_point gamma;\n#endif\n\n\n    /* setjmp() doesn't make sense here, because we'd either have to exit(),\n     * longjmp() ourselves, or return control to libpng, which doesn't want\n     * to see us again.  By not doing anything here, libpng will instead jump\n     * to readpng2_decode_data(), which can return an error value to the main\n     * program. */\n\n\n    /* retrieve the pointer to our special-purpose struct, using the png_ptr\n     * that libpng passed back to us (i.e., not a global this time--there's\n     * no real difference for a single image, but for a multithreaded browser\n     * decoding several PNG images at the same time, one needs to avoid mixing\n     * up different images' structs) */\n\n    mainprog_ptr = png_get_progressive_ptr(png_ptr);\n\n    if (mainprog_ptr == NULL) {         /* we be hosed */\n        fprintf(stderr,\n          \"readpng2 error:  main struct not recoverable in info_callback.\\n\");\n        fflush(stderr);\n        return;\n        /*\n         * Alternatively, we could call our error-handler just like libpng\n         * does, which would effectively terminate the program.  Since this\n         * can only happen if png_ptr gets redirected somewhere odd or the\n         * main PNG struct gets wiped, we're probably toast anyway.  (If\n         * png_ptr itself is NULL, we would not have been called.)\n         */\n    }\n\n\n    /* this is just like in the non-progressive case */\n\n    png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,\n       NULL, NULL, NULL);\n    mainprog_ptr->width = (ulg)width;\n    mainprog_ptr->height = (ulg)height;\n\n\n    /* since we know we've read all of the PNG file's \"header\" (i.e., up\n     * to IDAT), we can check for a background color here */\n\n    if (mainprog_ptr->need_bgcolor)\n    {\n        png_color_16p pBackground;\n\n        /* it is not obvious from the libpng documentation, but this function\n         * takes a pointer to a pointer, and it always returns valid red,\n         * green and blue values, regardless of color_type: */\n        if (png_get_bKGD(png_ptr, info_ptr, &pBackground))\n        {\n\n           /* however, it always returns the raw bKGD data, regardless of any\n            * bit-depth transformations, so check depth and adjust if necessary\n            */\n           if (bit_depth == 16) {\n               mainprog_ptr->bg_red   = pBackground->red   >> 8;\n               mainprog_ptr->bg_green = pBackground->green >> 8;\n               mainprog_ptr->bg_blue  = pBackground->blue  >> 8;\n           } else if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) {\n               if (bit_depth == 1)\n                   mainprog_ptr->bg_red = mainprog_ptr->bg_green =\n                     mainprog_ptr->bg_blue = pBackground->gray? 255 : 0;\n               else if (bit_depth == 2)\n                   mainprog_ptr->bg_red = mainprog_ptr->bg_green =\n                     mainprog_ptr->bg_blue = (255/3) * pBackground->gray;\n               else /* bit_depth == 4 */\n                   mainprog_ptr->bg_red = mainprog_ptr->bg_green =\n                     mainprog_ptr->bg_blue = (255/15) * pBackground->gray;\n           } else {\n               mainprog_ptr->bg_red   = (uch)pBackground->red;\n               mainprog_ptr->bg_green = (uch)pBackground->green;\n               mainprog_ptr->bg_blue  = (uch)pBackground->blue;\n           }\n        }\n    }\n\n\n    /* as before, let libpng expand palette images to RGB, low-bit-depth\n     * grayscale images to 8 bits, transparency chunks to full alpha channel;\n     * strip 16-bit-per-sample images to 8 bits per sample; and convert\n     * grayscale to RGB[A] */\n\n    if (color_type == PNG_COLOR_TYPE_PALETTE)\n        png_set_expand(png_ptr);\n    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)\n        png_set_expand(png_ptr);\n    if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))\n        png_set_expand(png_ptr);\n#ifdef PNG_READ_16_TO_8_SUPPORTED\n    if (bit_depth == 16)\n#  ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n        png_set_scale_16(png_ptr);\n#  else\n        png_set_strip_16(png_ptr);\n#  endif\n#endif\n    if (color_type == PNG_COLOR_TYPE_GRAY ||\n        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n        png_set_gray_to_rgb(png_ptr);\n\n\n    /* Unlike the basic viewer, which was designed to operate on local files,\n     * this program is intended to simulate a web browser--even though we\n     * actually read from a local file, too.  But because we are pretending\n     * that most of the images originate on the Internet, we follow the recom-\n     * mendation of the sRGB proposal and treat unlabelled images (no gAMA\n     * chunk) as existing in the sRGB color space.  That is, we assume that\n     * such images have a file gamma of 0.45455, which corresponds to a PC-like\n     * display system.  This change in assumptions will have no effect on a\n     * PC-like system, but on a Mac, SGI, NeXT or other system with a non-\n     * identity lookup table, it will darken unlabelled images, which effec-\n     * tively favors images from PC-like systems over those originating on\n     * the local platform.  Note that mainprog_ptr->display_exponent is the\n     * \"gamma\" value for the entire display system, i.e., the product of\n     * LUT_exponent and CRT_exponent. */\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n    if (png_get_gAMA(png_ptr, info_ptr, &gamma))\n        png_set_gamma(png_ptr, mainprog_ptr->display_exponent, gamma);\n    else\n        png_set_gamma(png_ptr, mainprog_ptr->display_exponent, 0.45455);\n#else\n    if (png_get_gAMA_fixed(png_ptr, info_ptr, &gamma))\n        png_set_gamma_fixed(png_ptr,\n            (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), gamma);\n    else\n        png_set_gamma_fixed(png_ptr,\n            (png_fixed_point)(100000*mainprog_ptr->display_exponent+.5), 45455);\n#endif\n\n    /* we'll let libpng expand interlaced images, too */\n\n    mainprog_ptr->passes = png_set_interlace_handling(png_ptr);\n\n\n    /* all transformations have been registered; now update info_ptr data and\n     * then get rowbytes and channels */\n\n    png_read_update_info(png_ptr, info_ptr);\n\n    mainprog_ptr->rowbytes = (int)png_get_rowbytes(png_ptr, info_ptr);\n    mainprog_ptr->channels = png_get_channels(png_ptr, info_ptr);\n\n\n    /* Call the main program to allocate memory for the image buffer and\n     * initialize windows and whatnot.  (The old-style function-pointer\n     * invocation is used for compatibility with a few supposedly ANSI\n     * compilers that nevertheless barf on \"fn_ptr()\"-style syntax.) */\n\n    (*mainprog_ptr->mainprog_init)();\n\n\n    /* and that takes care of initialization */\n\n    return;\n}\n\n\n\n\n\nstatic void readpng2_row_callback(png_structp png_ptr, png_bytep new_row,\n                                  png_uint_32 row_num, int pass)\n{\n    mainprog_info  *mainprog_ptr;\n\n\n    /* first check whether the row differs from the previous pass; if not,\n     * nothing to combine or display */\n\n    if (!new_row)\n        return;\n\n\n    /* retrieve the pointer to our special-purpose struct so we can access\n     * the old rows and image-display callback function */\n\n    mainprog_ptr = png_get_progressive_ptr(png_ptr);\n\n\n    /* save the pass number for optional use by the front end */\n\n    mainprog_ptr->pass = pass;\n\n\n    /* have libpng either combine the new row data with the existing row data\n     * from previous passes (if interlaced) or else just copy the new row\n     * into the main program's image buffer */\n\n    png_progressive_combine_row(png_ptr, mainprog_ptr->row_pointers[row_num],\n      new_row);\n\n\n    /* finally, call the display routine in the main program with the number\n     * of the row we just updated */\n\n    (*mainprog_ptr->mainprog_display_row)(row_num);\n\n\n    /* and we're ready for more */\n\n    return;\n}\n\n\n\n\n\nstatic void readpng2_end_callback(png_structp png_ptr, png_infop info_ptr)\n{\n    mainprog_info  *mainprog_ptr;\n\n\n    /* retrieve the pointer to our special-purpose struct */\n\n    mainprog_ptr = png_get_progressive_ptr(png_ptr);\n\n\n    /* let the main program know that it should flush any buffered image\n     * data to the display now and set a \"done\" flag or whatever, but note\n     * that it SHOULD NOT DESTROY THE PNG STRUCTS YET--in other words, do\n     * NOT call readpng2_cleanup() either here or in the finish_display()\n     * routine; wait until control returns to the main program via\n     * readpng2_decode_data() */\n\n    (*mainprog_ptr->mainprog_finish_display)();\n\n\n    /* all done */\n\n    (void)info_ptr; /* Unused */\n\n    return;\n}\n\n\n\n\n\nvoid readpng2_cleanup(mainprog_info *mainprog_ptr)\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n    if (png_ptr && info_ptr)\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n\n    mainprog_ptr->png_ptr = NULL;\n    mainprog_ptr->info_ptr = NULL;\n}\n\n\nstatic void readpng2_warning_handler(png_structp png_ptr, png_const_charp msg)\n{\n    fprintf(stderr, \"readpng2 libpng warning: %s\\n\", msg);\n    fflush(stderr);\n    (void)png_ptr; /* Unused */\n}\n\n\nstatic void readpng2_error_handler(png_structp png_ptr, png_const_charp msg)\n{\n    mainprog_info  *mainprog_ptr;\n\n    /* This function, aside from the extra step of retrieving the \"error\n     * pointer\" (below) and the fact that it exists within the application\n     * rather than within libpng, is essentially identical to libpng's\n     * default error handler.  The second point is critical:  since both\n     * setjmp() and longjmp() are called from the same code, they are\n     * guaranteed to have compatible notions of how big a jmp_buf is,\n     * regardless of whether _BSD_SOURCE or anything else has (or has not)\n     * been defined. */\n\n    fprintf(stderr, \"readpng2 libpng error: %s\\n\", msg);\n    fflush(stderr);\n\n    mainprog_ptr = png_get_error_ptr(png_ptr);\n    if (mainprog_ptr == NULL) {         /* we are completely hosed now */\n        fprintf(stderr,\n          \"readpng2 severe error:  jmpbuf not recoverable; terminating.\\n\");\n        fflush(stderr);\n        exit(99);\n    }\n\n    /* Now we have our data structure we can use the information in it\n     * to return control to our own higher level code (all the points\n     * where 'setjmp' is called in this file.)  This will work with other\n     * error handling mechanisms as well - libpng always calls png_error\n     * when it can proceed no further, thus, so long as the error handler\n     * is intercepted, application code can do its own error recovery.\n     */\n    longjmp(mainprog_ptr->jmpbuf, 1);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/readpng2.h",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng2 - progressive-model PNG display program                 readpng2.h\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2008 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#ifndef TRUE\n#  define TRUE 1\n#  define FALSE 0\n#endif\n\n#ifndef MAX\n#  define MAX(a,b)  ((a) > (b)? (a) : (b))\n#  define MIN(a,b)  ((a) < (b)? (a) : (b))\n#endif\n\n#ifdef DEBUG\n#  define Trace(x)  {fprintf x ; fflush(stderr); fflush(stdout);}\n#else\n#  define Trace(x)  ;\n#endif\n\nenum rpng2_states {\n    kPreInit = 0,\n    kWindowInit,\n    kDone\n};\n\ntypedef unsigned char   uch;\ntypedef unsigned short  ush;\ntypedef unsigned long   ulg;\n\ntypedef struct _mainprog_info {\n    double display_exponent;\n    ulg width;\n    ulg height;\n    void *png_ptr;\n    void *info_ptr;\n    void (*mainprog_init)(void);\n    void (*mainprog_display_row)(ulg row_num);\n    void (*mainprog_finish_display)(void);\n    uch *image_data;\n    uch **row_pointers;\n    jmp_buf jmpbuf;\n    int passes;              /* not used */\n    int pass;\n    int rowbytes;\n    int channels;\n    int need_bgcolor;\n    int state;\n    uch bg_red;\n    uch bg_green;\n    uch bg_blue;\n} mainprog_info;\n\n\n/* prototypes for public functions in readpng2.c */\n\nvoid readpng2_version_info(void);\n\nint readpng2_check_sig(uch *sig, int num);\n\nint readpng2_init(mainprog_info *mainprog_ptr);\n\nint readpng2_decode_data(mainprog_info *mainprog_ptr, uch *rawbuf, ulg length);\n\nvoid readpng2_cleanup(mainprog_info *mainprog_ptr);\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/readppm.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng - simple PNG display program                              readppm.c\n\n  ---------------------------------------------------------------------------\n\n   This is a special-purpose replacement for readpng.c that allows binary\n   PPM files to be used in place of PNG images.\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#include <stdio.h>\n#include <stdlib.h>\n\n#include \"readpng.h\"    /* typedefs, common macros, public prototypes */\n\n\nulg  width, height;\nint  bit_depth, color_type, channels;\nuch  *image_data = NULL;\nFILE *saved_infile;\n\n\nvoid readpng_version_info()\n{\n    fprintf(stderr, \"   Compiled without libpng, zlib or PBMPLUS/NetPBM.\\n\");\n}\n\n\n/* return value = 0 for success, 1 for bad sig, 2 for bad IHDR, 4 for no mem */\n\nint readpng_init(FILE *infile, ulg *pWidth, ulg *pHeight)\n{\n    static uch ppmline[256];\n    int maxval;\n\n\n    saved_infile = infile;\n\n    fgets(ppmline, 256, infile);\n    if (ppmline[0] != 'P' || ppmline[1] != '6') {\n        fprintf(stderr, \"ERROR:  not a PPM file\\n\");\n        return 1;\n    }\n    /* possible color types:  P5 = grayscale (0), P6 = RGB (2), P8 = RGBA (6) */\n    if (ppmline[1] == '6') {\n        color_type = 2;\n        channels = 3;\n    } else if (ppmline[1] == '8') {\n        color_type = 6;\n        channels = 4;\n    } else /* if (ppmline[1] == '5') */ {\n        color_type = 0;\n        channels = 1;\n    }\n\n    do {\n        fgets(ppmline, 256, infile);\n    } while (ppmline[0] == '#');\n    sscanf(ppmline, \"%lu %lu\", &width, &height);\n\n    do {\n        fgets(ppmline, 256, infile);\n    } while (ppmline[0] == '#');\n    sscanf(ppmline, \"%d\", &maxval);\n    if (maxval != 255) {\n        fprintf(stderr, \"ERROR:  maxval = %d\\n\", maxval);\n        return 2;\n    }\n    bit_depth = 8;\n\n    *pWidth = width;\n    *pHeight = height;\n\n    return 0;\n}\n\n\n\n\n/* returns 0 if succeeds, 1 if fails due to no bKGD chunk, 2 if libpng error;\n * scales values to 8-bit if necessary */\n\nint readpng_get_bgcolor(uch *red, uch *green, uch *blue)\n{\n    return 1;\n}\n\n\n\n\n/* display_exponent == LUT_exponent * CRT_exponent */\n\nuch *readpng_get_image(double display_exponent, int *pChannels, ulg *pRowbytes)\n{\n    ulg  rowbytes;\n\n\n    /* expand palette images to RGB, low-bit-depth grayscale images to 8 bits,\n     * transparency chunks to full alpha channel; strip 16-bit-per-sample\n     * images to 8 bits per sample; and convert grayscale to RGB[A] */\n\n    /* GRR WARNING:  grayscale needs to be expanded and channels reset! */\n\n    *pRowbytes = rowbytes = channels*width;\n    *pChannels = channels;\n\n    if ((image_data = (uch *)malloc(rowbytes*height)) == NULL) {\n        return NULL;\n    }\n\n    Trace((stderr, \"readpng_get_image:  rowbytes = %ld, height = %ld\\n\", rowbytes, height));\n\n\n    /* now we can go ahead and just read the whole image */\n\n    if (fread(image_data, 1L, rowbytes*height, saved_infile) <\n       rowbytes*height) {\n        free (image_data);\n        image_data = NULL;\n        return NULL;\n    }\n\n    return image_data;\n}\n\n\nvoid readpng_cleanup(int free_image_data)\n{\n    if (free_image_data && image_data) {\n        free(image_data);\n        image_data = NULL;\n    }\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/rpng-win.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng - simple PNG display program                             rpng-win.c\n\n   This program decodes and displays PNG images, with gamma correction and\n   optionally with a user-specified background color (in case the image has\n   transparency).  It is very nearly the most basic PNG viewer possible.\n   This version is for 32-bit Windows; it may compile under 16-bit Windows\n   with a little tweaking (or maybe not).\n\n   to do:\n    - handle quoted command-line args (especially filenames with spaces)\n    - have minimum window width:  oh well\n    - use %.1023s to simplify truncation of title-bar string?\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n    - 1.00:  initial public release\n    - 1.01:  modified to allow abbreviated options; fixed long/ulong mis-\n              match; switched to png_jmpbuf() macro\n    - 1.02:  added extra set of parentheses to png_jmpbuf() macro; fixed\n              command-line parsing bug\n    - 1.10:  enabled \"message window\"/console (thanks to David Geldreich)\n    - 2.00:  dual-licensed (added GNU GPL)\n    - 2.01:  fixed improper display of usage screen on PNG error(s)\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2008 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#define PROGNAME  \"rpng-win\"\n#define LONGNAME  \"Simple PNG Viewer for Windows\"\n#define VERSION   \"2.01 of 16 March 2008\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <windows.h>\n#ifdef __CYGWIN__\n/* getch replacement. Turns out, we don't really need this,\n * but leave it here if we ever enable any of the uses of\n * _getch in the main code\n */\n#include <unistd.h>\n#include <termio.h>\n#include <sys/ioctl.h>\nint repl_getch( void )\n{\n  char ch;\n  int fd = fileno(stdin);\n  struct termio old_tty, new_tty;\n\n  ioctl(fd, TCGETA, &old_tty);\n  new_tty = old_tty;\n  new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);\n  ioctl(fd, TCSETA, &new_tty);\n  fread(&ch, 1, sizeof(ch), stdin);\n  ioctl(fd, TCSETA, &old_tty);\n\n  return ch;\n}\n#define _getch repl_getch\n#else\n#include <conio.h>      /* only for _getch() */\n#endif\n\n/* #define DEBUG  :  this enables the Trace() macros */\n\n#include \"readpng.h\"    /* typedefs, common macros, readpng prototypes */\n\n\n/* could just include png.h, but this macro is the only thing we need\n * (name and typedefs changed to local versions); note that side effects\n * only happen with alpha (which could easily be avoided with\n * \"ush acopy = (alpha);\") */\n\n#define alpha_composite(composite, fg, alpha, bg) {               \\\n    ush temp = ((ush)(fg)*(ush)(alpha) +                          \\\n                (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128);  \\\n    (composite) = (uch)((temp + (temp >> 8)) >> 8);               \\\n}\n\n\n/* local prototypes */\nstatic int        rpng_win_create_window(HINSTANCE hInst, int showmode);\nstatic int        rpng_win_display_image(void);\nstatic void       rpng_win_cleanup(void);\nLRESULT CALLBACK  rpng_win_wndproc(HWND, UINT, WPARAM, LPARAM);\n\n\nstatic char titlebar[1024];\nstatic char *progname = PROGNAME;\nstatic char *appname = LONGNAME;\nstatic char *filename;\nstatic FILE *infile;\n\nstatic char *bgstr;\nstatic uch bg_red=0, bg_green=0, bg_blue=0;\n\nstatic double display_exponent;\n\nstatic ulg image_width, image_height, image_rowbytes;\nstatic int image_channels;\nstatic uch *image_data;\n\n/* Windows-specific variables */\nstatic ulg wimage_rowbytes;\nstatic uch *dib;\nstatic uch *wimage_data;\nstatic BITMAPINFOHEADER *bmih;\n\nstatic HWND global_hwnd;\n\n\n\n\nint WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)\n{\n    char *args[1024];                 /* arbitrary limit, but should suffice */\n    char *p, *q, **argv = args;\n    int argc = 0;\n    int rc, alen, flen;\n    int error = 0;\n    int have_bg = FALSE;\n    double LUT_exponent;              /* just the lookup table */\n    double CRT_exponent = 2.2;        /* just the monitor */\n    double default_display_exponent;  /* whole display system */\n    MSG msg;\n\n\n    filename = (char *)NULL;\n\n#ifndef __CYGWIN__\n    /* First reenable console output, which normally goes to the bit bucket\n     * for windowed apps.  Closing the console window will terminate the\n     * app.  Thanks to David.Geldreich@realviz.com for supplying the magical\n     * incantation. */\n\n    AllocConsole();\n    freopen(\"CONOUT$\", \"a\", stderr);\n    freopen(\"CONOUT$\", \"a\", stdout);\n#endif\n\n\n    /* Next set the default value for our display-system exponent, i.e.,\n     * the product of the CRT exponent and the exponent corresponding to\n     * the frame-buffer's lookup table (LUT), if any.  This is not an\n     * exhaustive list of LUT values (e.g., OpenStep has a lot of weird\n     * ones), but it should cover 99% of the current possibilities.  And\n     * yes, these ifdefs are completely wasted in a Windows program... */\n\n#if defined(NeXT)\n    LUT_exponent = 1.0 / 2.2;\n    /*\n    if (some_next_function_that_returns_gamma(&next_gamma))\n        LUT_exponent = 1.0 / next_gamma;\n     */\n#elif defined(sgi)\n    LUT_exponent = 1.0 / 1.7;\n    /* there doesn't seem to be any documented function to get the\n     * \"gamma\" value, so we do it the hard way */\n    infile = fopen(\"/etc/config/system.glGammaVal\", \"r\");\n    if (infile) {\n        double sgi_gamma;\n\n        fgets(tmpline, 80, infile);\n        fclose(infile);\n        sgi_gamma = atof(tmpline);\n        if (sgi_gamma > 0.0)\n            LUT_exponent = 1.0 / sgi_gamma;\n    }\n#elif defined(Macintosh)\n    LUT_exponent = 1.8 / 2.61;\n    /*\n    if (some_mac_function_that_returns_gamma(&mac_gamma))\n        LUT_exponent = mac_gamma / 2.61;\n     */\n#else\n    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */\n#endif\n\n    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */\n    default_display_exponent = LUT_exponent * CRT_exponent;\n\n\n    /* If the user has set the SCREEN_GAMMA environment variable as suggested\n     * (somewhat imprecisely) in the libpng documentation, use that; otherwise\n     * use the default value we just calculated.  Either way, the user may\n     * override this via a command-line option. */\n\n    if ((p = getenv(\"SCREEN_GAMMA\")) != NULL)\n        display_exponent = atof(p);\n    else\n        display_exponent = default_display_exponent;\n\n\n    /* Windows really hates command lines, so we have to set up our own argv.\n     * Note that we do NOT bother with quoted arguments here, so don't use\n     * filenames with spaces in 'em! */\n\n    argv[argc++] = PROGNAME;\n    p = cmd;\n    for (;;) {\n        if (*p == ' ')\n            while (*++p == ' ')\n                ;\n        /* now p points at the first non-space after some spaces */\n        if (*p == '\\0')\n            break;    /* nothing after the spaces:  done */\n        argv[argc++] = q = p;\n        while (*q && *q != ' ')\n            ++q;\n        /* now q points at a space or the end of the string */\n        if (*q == '\\0')\n            break;    /* last argv already terminated; quit */\n        *q = '\\0';    /* change space to terminator */\n        p = q + 1;\n    }\n    argv[argc] = NULL;   /* terminate the argv array itself */\n\n\n    /* Now parse the command line for options and the PNG filename. */\n\n    while (*++argv && !error) {\n        if (!strncmp(*argv, \"-gamma\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                display_exponent = atof(*argv);\n                if (display_exponent <= 0.0)\n                    ++error;\n            }\n        } else if (!strncmp(*argv, \"-bgcolor\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                bgstr = *argv;\n                if (strlen(bgstr) != 7 || bgstr[0] != '#')\n                    ++error;\n                else\n                    have_bg = TRUE;\n            }\n        } else {\n            if (**argv != '-') {\n                filename = *argv;\n                if (argv[1])   /* shouldn't be any more args after filename */\n                    ++error;\n            } else\n                ++error;   /* not expecting any other options */\n        }\n    }\n\n    if (!filename)\n        ++error;\n\n\n    /* print usage screen if any errors up to this point */\n\n    if (error) {\n#ifndef __CYGWIN__\n        int ch;\n#endif\n\n        fprintf(stderr, \"\\n%s %s:  %s\\n\\n\", PROGNAME, VERSION, appname);\n        readpng_version_info();\n        fprintf(stderr, \"\\n\"\n          \"Usage:  %s [-gamma exp] [-bgcolor bg] file.png\\n\"\n          \"    exp \\ttransfer-function exponent (``gamma'') of the display\\n\"\n          \"\\t\\t  system in floating-point format (e.g., ``%.1f''); equal\\n\"\n          \"\\t\\t  to the product of the lookup-table exponent (varies)\\n\"\n          \"\\t\\t  and the CRT exponent (usually 2.2); must be positive\\n\"\n          \"    bg  \\tdesired background color in 7-character hex RGB format\\n\"\n          \"\\t\\t  (e.g., ``#ff7700'' for orange:  same as HTML colors);\\n\"\n          \"\\t\\t  used with transparent images\\n\"\n          \"\\nPress Q, Esc or mouse button 1 after image is displayed to quit.\\n\"\n#ifndef __CYGWIN__\n          \"Press Q or Esc to quit this usage screen.\\n\"\n#endif\n          \"\\n\", PROGNAME, default_display_exponent);\n#ifndef __CYGWIN__\n        do\n            ch = _getch();\n        while (ch != 'q' && ch != 'Q' && ch != 0x1B);\n#endif\n        exit(1);\n    }\n\n\n    if (!(infile = fopen(filename, \"rb\"))) {\n        fprintf(stderr, PROGNAME \":  can't open PNG file [%s]\\n\", filename);\n        ++error;\n    } else {\n        if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {\n            switch (rc) {\n                case 1:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] is not a PNG file: incorrect signature\\n\",\n                      filename);\n                    break;\n                case 2:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] has bad IHDR (libpng longjmp)\\n\", filename);\n                    break;\n                case 4:\n                    fprintf(stderr, PROGNAME \":  insufficient memory\\n\");\n                    break;\n                default:\n                    fprintf(stderr, PROGNAME\n                      \":  unknown readpng_init() error\\n\");\n                    break;\n            }\n            ++error;\n        }\n        if (error)\n            fclose(infile);\n    }\n\n\n    if (error) {\n#ifndef __CYGWIN__\n        int ch;\n#endif\n\n        fprintf(stderr, PROGNAME \":  aborting.\\n\");\n#ifndef __CYGWIN__\n        do\n            ch = _getch();\n        while (ch != 'q' && ch != 'Q' && ch != 0x1B);\n#endif\n        exit(2);\n    } else {\n        fprintf(stderr, \"\\n%s %s:  %s\\n\", PROGNAME, VERSION, appname);\n#ifndef __CYGWIN__\n        fprintf(stderr,\n          \"\\n   [console window:  closing this window will terminate %s]\\n\\n\",\n          PROGNAME);\n#endif\n    }\n\n\n    /* set the title-bar string, but make sure buffer doesn't overflow */\n\n    alen = strlen(appname);\n    flen = strlen(filename);\n    if (alen + flen + 3 > 1023)\n        sprintf(titlebar, \"%s:  ...%s\", appname, filename+(alen+flen+6-1023));\n    else\n        sprintf(titlebar, \"%s:  %s\", appname, filename);\n\n\n    /* if the user didn't specify a background color on the command line,\n     * check for one in the PNG file--if not, the initialized values of 0\n     * (black) will be used */\n\n    if (have_bg) {\n        unsigned r, g, b;   /* this approach quiets compiler warnings */\n\n        sscanf(bgstr+1, \"%2x%2x%2x\", &r, &g, &b);\n        bg_red   = (uch)r;\n        bg_green = (uch)g;\n        bg_blue  = (uch)b;\n    } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {\n        readpng_cleanup(TRUE);\n        fprintf(stderr, PROGNAME\n          \":  libpng error while checking for background color\\n\");\n        exit(2);\n    }\n\n\n    /* do the basic Windows initialization stuff, make the window and fill it\n     * with the background color */\n\n    if (rpng_win_create_window(hInst, showmode))\n        exit(2);\n\n\n    /* decode the image, all at once */\n\n    Trace((stderr, \"calling readpng_get_image()\\n\"))\n    image_data = readpng_get_image(display_exponent, &image_channels,\n      &image_rowbytes);\n    Trace((stderr, \"done with readpng_get_image()\\n\"))\n\n\n    /* done with PNG file, so clean up to minimize memory usage (but do NOT\n     * nuke image_data!) */\n\n    readpng_cleanup(FALSE);\n    fclose(infile);\n\n    if (!image_data) {\n        fprintf(stderr, PROGNAME \":  unable to decode PNG image\\n\");\n        exit(3);\n    }\n\n\n    /* display image (composite with background if requested) */\n\n    Trace((stderr, \"calling rpng_win_display_image()\\n\"))\n    if (rpng_win_display_image()) {\n        free(image_data);\n        exit(4);\n    }\n    Trace((stderr, \"done with rpng_win_display_image()\\n\"))\n\n\n    /* wait for the user to tell us when to quit */\n\n    printf(\n#ifndef __CYGWIN__\n      \"Done.  Press Q, Esc or mouse button 1 (within image window) to quit.\\n\"\n#else\n      \"Done.  Press mouse button 1 (within image window) to quit.\\n\"\n#endif\n    );\n    fflush(stdout);\n\n    while (GetMessage(&msg, NULL, 0, 0)) {\n        TranslateMessage(&msg);\n        DispatchMessage(&msg);\n    }\n\n\n    /* OK, we're done:  clean up all image and Windows resources and go away */\n\n    rpng_win_cleanup();\n\n    return msg.wParam;\n}\n\n\n\n\n\nstatic int rpng_win_create_window(HINSTANCE hInst, int showmode)\n{\n    uch *dest;\n    int extra_width, extra_height;\n    ulg i, j;\n    WNDCLASSEX wndclass;\n\n\n/*---------------------------------------------------------------------------\n    Allocate memory for the display-specific version of the image (round up\n    to multiple of 4 for Windows DIB).\n  ---------------------------------------------------------------------------*/\n\n    wimage_rowbytes = ((3*image_width + 3L) >> 2) << 2;\n\n    if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +\n                              wimage_rowbytes*image_height)))\n    {\n        return 4;   /* fail */\n    }\n\n/*---------------------------------------------------------------------------\n    Initialize the DIB.  Negative height means to use top-down BMP ordering\n    (must be uncompressed, but that's what we want).  Bit count of 1, 4 or 8\n    implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values\n    directly => wimage_data begins immediately after BMP header.\n  ---------------------------------------------------------------------------*/\n\n    memset(dib, 0, sizeof(BITMAPINFOHEADER));\n    bmih = (BITMAPINFOHEADER *)dib;\n    bmih->biSize = sizeof(BITMAPINFOHEADER);\n    bmih->biWidth = image_width;\n    bmih->biHeight = -((long)image_height);\n    bmih->biPlanes = 1;\n    bmih->biBitCount = 24;\n    bmih->biCompression = 0;\n    wimage_data = dib + sizeof(BITMAPINFOHEADER);\n\n/*---------------------------------------------------------------------------\n    Fill in background color (black by default); data are in BGR order.\n  ---------------------------------------------------------------------------*/\n\n    for (j = 0;  j < image_height;  ++j) {\n        dest = wimage_data + j*wimage_rowbytes;\n        for (i = image_width;  i > 0;  --i) {\n            *dest++ = bg_blue;\n            *dest++ = bg_green;\n            *dest++ = bg_red;\n        }\n    }\n\n/*---------------------------------------------------------------------------\n    Set the window parameters.\n  ---------------------------------------------------------------------------*/\n\n    memset(&wndclass, 0, sizeof(wndclass));\n\n    wndclass.cbSize = sizeof(wndclass);\n    wndclass.style = CS_HREDRAW | CS_VREDRAW;\n    wndclass.lpfnWndProc = rpng_win_wndproc;\n    wndclass.hInstance = hInst;\n    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);\n    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);\n    wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);\n    wndclass.lpszMenuName = NULL;\n    wndclass.lpszClassName = progname;\n    wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);\n\n    RegisterClassEx(&wndclass);\n\n/*---------------------------------------------------------------------------\n    Finally, create the window.\n  ---------------------------------------------------------------------------*/\n\n    extra_width  = 2*(GetSystemMetrics(SM_CXBORDER) +\n                      GetSystemMetrics(SM_CXDLGFRAME));\n    extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +\n                      GetSystemMetrics(SM_CYDLGFRAME)) +\n                      GetSystemMetrics(SM_CYCAPTION);\n\n    global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,\n      CW_USEDEFAULT, CW_USEDEFAULT, image_width+extra_width,\n      image_height+extra_height, NULL, NULL, hInst, NULL);\n\n    ShowWindow(global_hwnd, showmode);\n    UpdateWindow(global_hwnd);\n\n    return 0;\n\n} /* end function rpng_win_create_window() */\n\n\n\n\n\nstatic int rpng_win_display_image()\n{\n    uch *src, *dest;\n    uch r, g, b, a;\n    ulg i, row, lastrow;\n    RECT rect;\n\n\n    Trace((stderr, \"beginning display loop (image_channels == %d)\\n\",\n      image_channels))\n    Trace((stderr, \"(width = %ld, rowbytes = %ld, wimage_rowbytes = %d)\\n\",\n      image_width, image_rowbytes, wimage_rowbytes))\n\n\n/*---------------------------------------------------------------------------\n    Blast image data to buffer.  This whole routine takes place before the\n    message loop begins, so there's no real point in any pseudo-progressive\n    display...\n  ---------------------------------------------------------------------------*/\n\n    for (lastrow = row = 0;  row < image_height;  ++row) {\n        src = image_data + row*image_rowbytes;\n        dest = wimage_data + row*wimage_rowbytes;\n        if (image_channels == 3) {\n            for (i = image_width;  i > 0;  --i) {\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                *dest++ = b;\n                *dest++ = g;   /* note reverse order */\n                *dest++ = r;\n            }\n        } else /* if (image_channels == 4) */ {\n            for (i = image_width;  i > 0;  --i) {\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                a = *src++;\n                if (a == 255) {\n                    *dest++ = b;\n                    *dest++ = g;\n                    *dest++ = r;\n                } else if (a == 0) {\n                    *dest++ = bg_blue;\n                    *dest++ = bg_green;\n                    *dest++ = bg_red;\n                } else {\n                    /* this macro (copied from png.h) composites the\n                     * foreground and background values and puts the\n                     * result into the first argument; there are no\n                     * side effects with the first argument */\n                    alpha_composite(*dest++, b, a, bg_blue);\n                    alpha_composite(*dest++, g, a, bg_green);\n                    alpha_composite(*dest++, r, a, bg_red);\n                }\n            }\n        }\n        /* display after every 16 lines */\n        if (((row+1) & 0xf) == 0) {\n            rect.left = 0L;\n            rect.top = (LONG)lastrow;\n            rect.right = (LONG)image_width;      /* possibly off by one? */\n            rect.bottom = (LONG)lastrow + 16L;   /* possibly off by one? */\n            InvalidateRect(global_hwnd, &rect, FALSE);\n            UpdateWindow(global_hwnd);     /* similar to XFlush() */\n            lastrow = row + 1;\n        }\n    }\n\n    Trace((stderr, \"calling final image-flush routine\\n\"))\n    if (lastrow < image_height) {\n        rect.left = 0L;\n        rect.top = (LONG)lastrow;\n        rect.right = (LONG)image_width;      /* possibly off by one? */\n        rect.bottom = (LONG)image_height;    /* possibly off by one? */\n        InvalidateRect(global_hwnd, &rect, FALSE);\n        UpdateWindow(global_hwnd);     /* similar to XFlush() */\n    }\n\n/*\n    last param determines whether or not background is wiped before paint\n    InvalidateRect(global_hwnd, NULL, TRUE);\n    UpdateWindow(global_hwnd);\n */\n\n    return 0;\n}\n\n\n\n\n\nstatic void rpng_win_cleanup()\n{\n    if (image_data) {\n        free(image_data);\n        image_data = NULL;\n    }\n\n    if (dib) {\n        free(dib);\n        dib = NULL;\n    }\n}\n\n\n\n\n\nLRESULT CALLBACK rpng_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)\n{\n    HDC         hdc;\n    PAINTSTRUCT ps;\n    int rc;\n\n    switch (iMsg) {\n        case WM_CREATE:\n            /* one-time processing here, if any */\n            return 0;\n\n        case WM_PAINT:\n            hdc = BeginPaint(hwnd, &ps);\n                    /*                    dest                          */\n            rc = StretchDIBits(hdc, 0, 0, image_width, image_height,\n                    /*                    source                        */\n                                    0, 0, image_width, image_height,\n                                    wimage_data, (BITMAPINFO *)bmih,\n                    /*              iUsage: no clue                     */\n                                    0, SRCCOPY);\n            EndPaint(hwnd, &ps);\n            return 0;\n\n        /* wait for the user to tell us when to quit */\n        case WM_CHAR:\n            switch (wP) {      /* only need one, so ignore repeat count */\n                case 'q':\n                case 'Q':\n                case 0x1B:     /* Esc key */\n                    PostQuitMessage(0);\n            }\n            return 0;\n\n        case WM_LBUTTONDOWN:   /* another way of quitting */\n        case WM_DESTROY:\n            PostQuitMessage(0);\n            return 0;\n    }\n\n    return DefWindowProc(hwnd, iMsg, wP, lP);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/rpng-x.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng - simple PNG display program                               rpng-x.c\n\n   This program decodes and displays PNG images, with gamma correction and\n   optionally with a user-specified background color (in case the image has\n   transparency).  It is very nearly the most basic PNG viewer possible.\n   This version is for the X Window System (tested by author under Unix and\n   by Martin Zinser under OpenVMS; may work under OS/2 with some tweaking).\n\n   to do:\n    - 8-bit (colormapped) X support\n    - use %.1023s to simplify truncation of title-bar string?\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n    - 1.01:  initial public release\n    - 1.02:  modified to allow abbreviated options; fixed long/ulong mis-\n              match; switched to png_jmpbuf() macro\n    - 1.10:  added support for non-default visuals; fixed X pixel-conversion\n    - 1.11:  added extra set of parentheses to png_jmpbuf() macro; fixed\n              command-line parsing bug\n    - 1.12:  fixed some small X memory leaks (thanks to Franois Petitjean)\n    - 1.13:  fixed XFreeGC() crash bug (thanks to Patrick Welche)\n    - 1.14:  added support for X resources (thanks to Gerhard Niklasch)\n    - 2.00:  dual-licensed (added GNU GPL)\n    - 2.01:  fixed improper display of usage screen on PNG error(s)\n    - 2.02:  Added \"void(argc);\" statement to quiet pedantic compiler warnings\n             about unused variable (GR-P)\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2008 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#define PROGNAME  \"rpng-x\"\n#define LONGNAME  \"Simple PNG Viewer for X\"\n#define VERSION   \"2.02 of 15 June 2014\"\n#define RESNAME   \"rpng\"        /* our X resource application name */\n#define RESCLASS  \"Rpng\"        /* our X resource class name */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <time.h>\n#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/Xos.h>\n#include <X11/keysym.h>\n\n/* #define DEBUG  :  this enables the Trace() macros */\n\n#include \"readpng.h\"   /* typedefs, common macros, readpng prototypes */\n\n\n/* could just include png.h, but this macro is the only thing we need\n * (name and typedefs changed to local versions); note that side effects\n * only happen with alpha (which could easily be avoided with\n * \"ush acopy = (alpha);\") */\n\n#define alpha_composite(composite, fg, alpha, bg) {               \\\n    ush temp = ((ush)(fg)*(ush)(alpha) +                          \\\n                (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128);  \\\n    (composite) = (uch)((temp + (temp >> 8)) >> 8);               \\\n}\n\n\n/* local prototypes */\nstatic int  rpng_x_create_window(void);\nstatic int  rpng_x_display_image(void);\nstatic void rpng_x_cleanup(void);\nstatic int  rpng_x_msb(ulg u32val);\n\n\nstatic char titlebar[1024], *window_name = titlebar;\nstatic char *appname = LONGNAME;\nstatic char *icon_name = PROGNAME;\nstatic char *res_name = RESNAME;\nstatic char *res_class = RESCLASS;\nstatic char *filename;\nstatic FILE *infile;\n\nstatic char *bgstr;\nstatic uch bg_red=0, bg_green=0, bg_blue=0;\n\nstatic double display_exponent;\n\nstatic ulg image_width, image_height, image_rowbytes;\nstatic int image_channels;\nstatic uch *image_data;\n\n/* X-specific variables */\nstatic char *displayname;\nstatic XImage *ximage;\nstatic Display *display;\nstatic int depth;\nstatic Visual *visual;\nstatic XVisualInfo *visual_list;\nstatic int RShift, GShift, BShift;\nstatic ulg RMask, GMask, BMask;\nstatic Window window;\nstatic GC gc;\nstatic Colormap colormap;\n\nstatic int have_nondefault_visual = FALSE;\nstatic int have_colormap = FALSE;\nstatic int have_window = FALSE;\nstatic int have_gc = FALSE;\n/*\nulg numcolors=0, pixels[256];\nush reds[256], greens[256], blues[256];\n */\n\n\n\n\nint main(int argc, char **argv)\n{\n#ifdef sgi\n    char tmpline[80];\n#endif\n    char *p;\n    int rc, alen, flen;\n    int error = 0;\n    int have_bg = FALSE;\n    double LUT_exponent;               /* just the lookup table */\n    double CRT_exponent = 2.2;         /* just the monitor */\n    double default_display_exponent;   /* whole display system */\n    XEvent e;\n    KeySym k;\n\n\n    displayname = (char *)NULL;\n    filename = (char *)NULL;\n\n\n    /* First set the default value for our display-system exponent, i.e.,\n     * the product of the CRT exponent and the exponent corresponding to\n     * the frame-buffer's lookup table (LUT), if any.  This is not an\n     * exhaustive list of LUT values (e.g., OpenStep has a lot of weird\n     * ones), but it should cover 99% of the current possibilities. */\n\n#if defined(NeXT)\n    LUT_exponent = 1.0 / 2.2;\n    /*\n    if (some_next_function_that_returns_gamma(&next_gamma))\n        LUT_exponent = 1.0 / next_gamma;\n     */\n#elif defined(sgi)\n    LUT_exponent = 1.0 / 1.7;\n    /* there doesn't seem to be any documented function to get the\n     * \"gamma\" value, so we do it the hard way */\n    infile = fopen(\"/etc/config/system.glGammaVal\", \"r\");\n    if (infile) {\n        double sgi_gamma;\n\n        fgets(tmpline, 80, infile);\n        fclose(infile);\n        sgi_gamma = atof(tmpline);\n        if (sgi_gamma > 0.0)\n            LUT_exponent = 1.0 / sgi_gamma;\n    }\n#elif defined(Macintosh)\n    LUT_exponent = 1.8 / 2.61;\n    /*\n    if (some_mac_function_that_returns_gamma(&mac_gamma))\n        LUT_exponent = mac_gamma / 2.61;\n     */\n#else\n    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */\n#endif\n\n    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */\n    default_display_exponent = LUT_exponent * CRT_exponent;\n\n\n    /* If the user has set the SCREEN_GAMMA environment variable as suggested\n     * (somewhat imprecisely) in the libpng documentation, use that; otherwise\n     * use the default value we just calculated.  Either way, the user may\n     * override this via a command-line option. */\n\n    if ((p = getenv(\"SCREEN_GAMMA\")) != NULL)\n        display_exponent = atof(p);\n    else\n        display_exponent = default_display_exponent;\n\n\n    /* Now parse the command line for options and the PNG filename. */\n\n    while (*++argv && !error) {\n        if (!strncmp(*argv, \"-display\", 2)) {\n            if (!*++argv)\n                ++error;\n            else\n                displayname = *argv;\n        } else if (!strncmp(*argv, \"-gamma\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                display_exponent = atof(*argv);\n                if (display_exponent <= 0.0)\n                    ++error;\n            }\n        } else if (!strncmp(*argv, \"-bgcolor\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                bgstr = *argv;\n                if (strlen(bgstr) != 7 || bgstr[0] != '#')\n                    ++error;\n                else\n                    have_bg = TRUE;\n            }\n        } else {\n            if (**argv != '-') {\n                filename = *argv;\n                if (argv[1])   /* shouldn't be any more args after filename */\n                    ++error;\n            } else\n                ++error;   /* not expecting any other options */\n        }\n    }\n\n    if (!filename)\n        ++error;\n\n\n    /* print usage screen if any errors up to this point */\n\n    if (error) {\n        fprintf(stderr, \"\\n%s %s:  %s\\n\", PROGNAME, VERSION, appname);\n        readpng_version_info();\n        fprintf(stderr, \"\\n\"\n          \"Usage:  %s [-display xdpy] [-gamma exp] [-bgcolor bg] file.png\\n\"\n          \"    xdpy\\tname of the target X display (e.g., ``hostname:0'')\\n\"\n          \"    exp \\ttransfer-function exponent (``gamma'') of the display\\n\"\n          \"\\t\\t  system in floating-point format (e.g., ``%.1f''); equal\\n\",\n          PROGNAME, default_display_exponent);\n\n        fprintf(stderr, \"\\n\"\n          \"\\t\\t  to the product of the lookup-table exponent (varies)\\n\"\n          \"\\t\\t  and the CRT exponent (usually 2.2); must be positive\\n\"\n          \"    bg  \\tdesired background color in 7-character hex RGB format\\n\"\n          \"\\t\\t  (e.g., ``#ff7700'' for orange:  same as HTML colors);\\n\"\n          \"\\t\\t  used with transparent images\\n\"\n          \"\\nPress Q, Esc or mouse button 1 (within image window, after image\\n\"\n          \"is displayed) to quit.\\n\");\n        exit(1);\n    }\n\n\n    if (!(infile = fopen(filename, \"rb\"))) {\n        fprintf(stderr, PROGNAME \":  can't open PNG file [%s]\\n\", filename);\n        ++error;\n    } else {\n        if ((rc = readpng_init(infile, &image_width, &image_height)) != 0) {\n            switch (rc) {\n                case 1:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] is not a PNG file: incorrect signature\\n\",\n                      filename);\n                    break;\n                case 2:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] has bad IHDR (libpng longjmp)\\n\", filename);\n                    break;\n                case 4:\n                    fprintf(stderr, PROGNAME \":  insufficient memory\\n\");\n                    break;\n                default:\n                    fprintf(stderr, PROGNAME\n                      \":  unknown readpng_init() error\\n\");\n                    break;\n            }\n            ++error;\n        } else {\n            display = XOpenDisplay(displayname);\n            if (!display) {\n                readpng_cleanup(TRUE);\n                fprintf(stderr, PROGNAME \":  can't open X display [%s]\\n\",\n                  displayname? displayname : \"default\");\n                ++error;\n            }\n        }\n        if (error)\n            fclose(infile);\n    }\n\n\n    if (error) {\n        fprintf(stderr, PROGNAME \":  aborting.\\n\");\n        exit(2);\n    }\n\n\n    /* set the title-bar string, but make sure buffer doesn't overflow */\n\n    alen = strlen(appname);\n    flen = strlen(filename);\n    if (alen + flen + 3 > 1023)\n        sprintf(titlebar, \"%s:  ...%s\", appname, filename+(alen+flen+6-1023));\n    else\n        sprintf(titlebar, \"%s:  %s\", appname, filename);\n\n\n    /* if the user didn't specify a background color on the command line,\n     * check for one in the PNG file--if not, the initialized values of 0\n     * (black) will be used */\n\n    if (have_bg) {\n        unsigned r, g, b;   /* this approach quiets compiler warnings */\n\n        sscanf(bgstr+1, \"%2x%2x%2x\", &r, &g, &b);\n        bg_red   = (uch)r;\n        bg_green = (uch)g;\n        bg_blue  = (uch)b;\n    } else if (readpng_get_bgcolor(&bg_red, &bg_green, &bg_blue) > 1) {\n        readpng_cleanup(TRUE);\n        fprintf(stderr, PROGNAME\n          \":  libpng error while checking for background color\\n\");\n        exit(2);\n    }\n\n\n    /* do the basic X initialization stuff, make the window and fill it\n     * with the background color */\n\n    if (rpng_x_create_window())\n        exit(2);\n\n\n    /* decode the image, all at once */\n\n    Trace((stderr, \"calling readpng_get_image()\\n\"))\n    image_data = readpng_get_image(display_exponent, &image_channels,\n      &image_rowbytes);\n    Trace((stderr, \"done with readpng_get_image()\\n\"))\n\n\n    /* done with PNG file, so clean up to minimize memory usage (but do NOT\n     * nuke image_data!) */\n\n    readpng_cleanup(FALSE);\n    fclose(infile);\n\n    if (!image_data) {\n        fprintf(stderr, PROGNAME \":  unable to decode PNG image\\n\");\n        exit(3);\n    }\n\n\n    /* display image (composite with background if requested) */\n\n    Trace((stderr, \"calling rpng_x_display_image()\\n\"))\n    if (rpng_x_display_image()) {\n        free(image_data);\n        exit(4);\n    }\n    Trace((stderr, \"done with rpng_x_display_image()\\n\"))\n\n\n    /* wait for the user to tell us when to quit */\n\n    printf(\n      \"Done.  Press Q, Esc or mouse button 1 (within image window) to quit.\\n\");\n    fflush(stdout);\n\n    do\n        XNextEvent(display, &e);\n    while (!(e.type == ButtonPress && e.xbutton.button == Button1) &&\n           !(e.type == KeyPress &&    /*  v--- or 1 for shifted keys */\n             ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape) ));\n\n\n    /* OK, we're done:  clean up all image and X resources and go away */\n\n    rpng_x_cleanup();\n\n    (void)argc; /* Unused */\n\n    return 0;\n}\n\n\n\n\n\nstatic int rpng_x_create_window(void)\n{\n    uch *xdata;\n    int need_colormap = FALSE;\n    int screen, pad;\n    ulg bg_pixel = 0L;\n    ulg attrmask;\n    Window root;\n    XEvent e;\n    XGCValues gcvalues;\n    XSetWindowAttributes attr;\n    XTextProperty windowName, *pWindowName = &windowName;\n    XTextProperty iconName, *pIconName = &iconName;\n    XVisualInfo visual_info;\n    XSizeHints *size_hints;\n    XWMHints *wm_hints;\n    XClassHint *class_hints;\n\n\n    screen = DefaultScreen(display);\n    depth = DisplayPlanes(display, screen);\n    root = RootWindow(display, screen);\n\n#ifdef DEBUG\n    XSynchronize(display, True);\n#endif\n\n#if 0\n/* GRR:  add 8-bit support */\n    if (/* depth != 8 && */ depth != 16 && depth != 24 && depth != 32) {\n        fprintf(stderr,\n          \"screen depth %d not supported (only 16-, 24- or 32-bit TrueColor)\\n\",\n          depth);\n        return 2;\n    }\n\n    XMatchVisualInfo(display, screen, depth,\n      (depth == 8)? PseudoColor : TrueColor, &visual_info);\n    visual = visual_info.visual;\n#else\n    if (depth != 16 && depth != 24 && depth != 32) {\n        int visuals_matched = 0;\n\n        Trace((stderr, \"default depth is %d:  checking other visuals\\n\",\n          depth))\n\n        /* 24-bit first */\n        visual_info.screen = screen;\n        visual_info.depth = 24;\n        visual_list = XGetVisualInfo(display,\n          VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);\n        if (visuals_matched == 0) {\n/* GRR:  add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */\n            fprintf(stderr, \"default screen depth %d not supported, and no\"\n              \" 24-bit visuals found\\n\", depth);\n            return 2;\n        }\n        Trace((stderr, \"XGetVisualInfo() returned %d 24-bit visuals\\n\",\n          visuals_matched))\n        visual = visual_list[0].visual;\n        depth = visual_list[0].depth;\n/*\n        colormap_size = visual_list[0].colormap_size;\n        visual_class = visual->class;\n        visualID = XVisualIDFromVisual(visual);\n */\n        have_nondefault_visual = TRUE;\n        need_colormap = TRUE;\n    } else {\n        XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);\n        visual = visual_info.visual;\n    }\n#endif\n\n    RMask = visual->red_mask;\n    GMask = visual->green_mask;\n    BMask = visual->blue_mask;\n\n/* GRR:  add/check 8-bit support */\n    if (depth == 8 || need_colormap) {\n        colormap = XCreateColormap(display, root, visual, AllocNone);\n        if (!colormap) {\n            fprintf(stderr, \"XCreateColormap() failed\\n\");\n            return 2;\n        }\n        have_colormap = TRUE;\n    }\n    if (depth == 15 || depth == 16) {\n        RShift = 15 - rpng_x_msb(RMask);    /* these are right-shifts */\n        GShift = 15 - rpng_x_msb(GMask);\n        BShift = 15 - rpng_x_msb(BMask);\n    } else if (depth > 16) {\n#define NO_24BIT_MASKS\n#ifdef NO_24BIT_MASKS\n        RShift = rpng_x_msb(RMask) - 7;     /* these are left-shifts */\n        GShift = rpng_x_msb(GMask) - 7;\n        BShift = rpng_x_msb(BMask) - 7;\n#else\n        RShift = 7 - rpng_x_msb(RMask);     /* these are right-shifts, too */\n        GShift = 7 - rpng_x_msb(GMask);\n        BShift = 7 - rpng_x_msb(BMask);\n#endif\n    }\n    if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {\n        fprintf(stderr, \"rpng internal logic error:  negative X shift(s)!\\n\");\n        return 2;\n    }\n\n/*---------------------------------------------------------------------------\n    Finally, create the window.\n  ---------------------------------------------------------------------------*/\n\n    attr.backing_store = Always;\n    attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;\n    attrmask = CWBackingStore | CWEventMask;\n    if (have_nondefault_visual) {\n        attr.colormap = colormap;\n        attr.background_pixel = 0;\n        attr.border_pixel = 1;\n        attrmask |= CWColormap | CWBackPixel | CWBorderPixel;\n    }\n\n    window = XCreateWindow(display, root, 0, 0, image_width, image_height, 0,\n      depth, InputOutput, visual, attrmask, &attr);\n\n    if (window == None) {\n        fprintf(stderr, \"XCreateWindow() failed\\n\");\n        return 2;\n    } else\n        have_window = TRUE;\n\n    if (depth == 8)\n        XSetWindowColormap(display, window, colormap);\n\n    if (!XStringListToTextProperty(&window_name, 1, pWindowName))\n        pWindowName = NULL;\n    if (!XStringListToTextProperty(&icon_name, 1, pIconName))\n        pIconName = NULL;\n\n    /* OK if any hints allocation fails; XSetWMProperties() allows NULLs */\n\n    if ((size_hints = XAllocSizeHints()) != NULL) {\n        /* window will not be resizable */\n        size_hints->flags = PMinSize | PMaxSize;\n        size_hints->min_width = size_hints->max_width = (int)image_width;\n        size_hints->min_height = size_hints->max_height = (int)image_height;\n    }\n\n    if ((wm_hints = XAllocWMHints()) != NULL) {\n        wm_hints->initial_state = NormalState;\n        wm_hints->input = True;\n     /* wm_hints->icon_pixmap = icon_pixmap; */\n        wm_hints->flags = StateHint | InputHint  /* | IconPixmapHint */ ;\n    }\n\n    if ((class_hints = XAllocClassHint()) != NULL) {\n        class_hints->res_name = res_name;\n        class_hints->res_class = res_class;\n    }\n\n    XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,\n      size_hints, wm_hints, class_hints);\n\n    /* various properties and hints no longer needed; free memory */\n    if (pWindowName)\n       XFree(pWindowName->value);\n    if (pIconName)\n       XFree(pIconName->value);\n    if (size_hints)\n        XFree(size_hints);\n    if (wm_hints)\n       XFree(wm_hints);\n    if (class_hints)\n       XFree(class_hints);\n\n    XMapWindow(display, window);\n\n    gc = XCreateGC(display, window, 0, &gcvalues);\n    have_gc = TRUE;\n\n/*---------------------------------------------------------------------------\n    Fill window with the specified background color.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        bg_pixel = ((ulg)bg_red   << RShift) |\n                   ((ulg)bg_green << GShift) |\n                   ((ulg)bg_blue  << BShift);\n    } else if (depth == 16) {\n        bg_pixel = ((((ulg)bg_red   << 8) >> RShift) & RMask) |\n                   ((((ulg)bg_green << 8) >> GShift) & GMask) |\n                   ((((ulg)bg_blue  << 8) >> BShift) & BMask);\n    } else /* depth == 8 */ {\n\n        /* GRR:  add 8-bit support */\n\n    }\n\n    XSetForeground(display, gc, bg_pixel);\n    XFillRectangle(display, window, gc, 0, 0, image_width, image_height);\n\n/*---------------------------------------------------------------------------\n    Wait for first Expose event to do any drawing, then flush.\n  ---------------------------------------------------------------------------*/\n\n    do\n        XNextEvent(display, &e);\n    while (e.type != Expose || e.xexpose.count);\n\n    XFlush(display);\n\n/*---------------------------------------------------------------------------\n    Allocate memory for the X- and display-specific version of the image.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        xdata = (uch *)malloc(4*image_width*image_height);\n        pad = 32;\n    } else if (depth == 16) {\n        xdata = (uch *)malloc(2*image_width*image_height);\n        pad = 16;\n    } else /* depth == 8 */ {\n        xdata = (uch *)malloc(image_width*image_height);\n        pad = 8;\n    }\n\n    if (!xdata) {\n        fprintf(stderr, PROGNAME \":  unable to allocate image memory\\n\");\n        return 4;\n    }\n\n    ximage = XCreateImage(display, visual, depth, ZPixmap, 0,\n      (char *)xdata, image_width, image_height, pad, 0);\n\n    if (!ximage) {\n        fprintf(stderr, PROGNAME \":  XCreateImage() failed\\n\");\n        free(xdata);\n        return 3;\n    }\n\n    /* to avoid testing the byte order every pixel (or doubling the size of\n     * the drawing routine with a giant if-test), we arbitrarily set the byte\n     * order to MSBFirst and let Xlib worry about inverting things on little-\n     * endian machines (like Linux/x86, old VAXen, etc.)--this is not the most\n     * efficient approach (the giant if-test would be better), but in the\n     * interest of clarity, we take the easy way out... */\n\n    ximage->byte_order = MSBFirst;\n\n    return 0;\n\n} /* end function rpng_x_create_window() */\n\n\n\n\n\nstatic int rpng_x_display_image(void)\n{\n    uch *src;\n    char *dest;\n    uch r, g, b, a;\n    ulg i, row, lastrow = 0;\n    ulg pixel;\n    int ximage_rowbytes = ximage->bytes_per_line;\n/*  int bpp = ximage->bits_per_pixel;  */\n\n\n    Trace((stderr, \"beginning display loop (image_channels == %d)\\n\",\n      image_channels))\n    Trace((stderr, \"   (width = %ld, rowbytes = %ld, ximage_rowbytes = %d)\\n\",\n      image_width, image_rowbytes, ximage_rowbytes))\n    Trace((stderr, \"   (bpp = %d)\\n\", ximage->bits_per_pixel))\n    Trace((stderr, \"   (byte_order = %s)\\n\", ximage->byte_order == MSBFirst?\n      \"MSBFirst\" : (ximage->byte_order == LSBFirst? \"LSBFirst\" : \"unknown\")))\n\n    if (depth == 24 || depth == 32) {\n        ulg red, green, blue;\n\n        for (lastrow = row = 0;  row < image_height;  ++row) {\n            src = image_data + row*image_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            if (image_channels == 3) {\n                for (i = image_width;  i > 0;  --i) {\n                    red   = *src++;\n                    green = *src++;\n                    blue  = *src++;\n#ifdef NO_24BIT_MASKS\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    /* GRR BUG:  this assumes bpp == 32, but may be 24: */\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n#else\n                    red   = (RShift < 0)? red   << (-RShift) : red   >> RShift;\n                    green = (GShift < 0)? green << (-GShift) : green >> GShift;\n                    blue  = (BShift < 0)? blue  << (-BShift) : blue  >> BShift;\n                    pixel = (red & RMask) | (green & GMask) | (blue & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n#endif\n                }\n            } else /* if (image_channels == 4) */ {\n                for (i = image_width;  i > 0;  --i) {\n                    r = *src++;\n                    g = *src++;\n                    b = *src++;\n                    a = *src++;\n                    if (a == 255) {\n                        red   = r;\n                        green = g;\n                        blue  = b;\n                    } else if (a == 0) {\n                        red   = bg_red;\n                        green = bg_green;\n                        blue  = bg_blue;\n                    } else {\n                        /* this macro (from png.h) composites the foreground\n                         * and background values and puts the result into the\n                         * first argument */\n                        alpha_composite(red,   r, a, bg_red);\n                        alpha_composite(green, g, a, bg_green);\n                        alpha_composite(blue,  b, a, bg_blue);\n                    }\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n            /* display after every 16 lines */\n            if (((row+1) & 0xf) == 0) {\n                XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n                  (int)lastrow, image_width, 16);\n                XFlush(display);\n                lastrow = row + 1;\n            }\n        }\n\n    } else if (depth == 16) {\n        ush red, green, blue;\n\n        for (lastrow = row = 0;  row < image_height;  ++row) {\n            src = image_data + row*image_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            if (image_channels == 3) {\n                for (i = image_width;  i > 0;  --i) {\n                    red   = ((ush)(*src) << 8);\n                    ++src;\n                    green = ((ush)(*src) << 8);\n                    ++src;\n                    blue  = ((ush)(*src) << 8);\n                    ++src;\n                    pixel = ((red   >> RShift) & RMask) |\n                            ((green >> GShift) & GMask) |\n                            ((blue  >> BShift) & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            } else /* if (image_channels == 4) */ {\n                for (i = image_width;  i > 0;  --i) {\n                    r = *src++;\n                    g = *src++;\n                    b = *src++;\n                    a = *src++;\n                    if (a == 255) {\n                        red   = ((ush)r << 8);\n                        green = ((ush)g << 8);\n                        blue  = ((ush)b << 8);\n                    } else if (a == 0) {\n                        red   = ((ush)bg_red   << 8);\n                        green = ((ush)bg_green << 8);\n                        blue  = ((ush)bg_blue  << 8);\n                    } else {\n                        /* this macro (from png.h) composites the foreground\n                         * and background values and puts the result back into\n                         * the first argument (== fg byte here:  safe) */\n                        alpha_composite(r, r, a, bg_red);\n                        alpha_composite(g, g, a, bg_green);\n                        alpha_composite(b, b, a, bg_blue);\n                        red   = ((ush)r << 8);\n                        green = ((ush)g << 8);\n                        blue  = ((ush)b << 8);\n                    }\n                    pixel = ((red   >> RShift) & RMask) |\n                            ((green >> GShift) & GMask) |\n                            ((blue  >> BShift) & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n            /* display after every 16 lines */\n            if (((row+1) & 0xf) == 0) {\n                XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n                  (int)lastrow, image_width, 16);\n                XFlush(display);\n                lastrow = row + 1;\n            }\n        }\n\n    } else /* depth == 8 */ {\n\n        /* GRR:  add 8-bit support */\n\n    }\n\n    Trace((stderr, \"calling final XPutImage()\\n\"))\n    if (lastrow < image_height) {\n        XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n          (int)lastrow, image_width, image_height-lastrow);\n        XFlush(display);\n    }\n\n    return 0;\n}\n\n\n\n\nstatic void rpng_x_cleanup(void)\n{\n    if (image_data) {\n        free(image_data);\n        image_data = NULL;\n    }\n\n    if (ximage) {\n        if (ximage->data) {\n            free(ximage->data);           /* we allocated it, so we free it */\n            ximage->data = (char *)NULL;  /*  instead of XDestroyImage() */\n        }\n        XDestroyImage(ximage);\n        ximage = NULL;\n    }\n\n    if (have_gc)\n        XFreeGC(display, gc);\n\n    if (have_window)\n        XDestroyWindow(display, window);\n\n    if (have_colormap)\n        XFreeColormap(display, colormap);\n\n    if (have_nondefault_visual)\n        XFree(visual_list);\n}\n\n\n\n\n\nstatic int rpng_x_msb(ulg u32val)\n{\n    int i;\n\n    for (i = 31;  i >= 0;  --i) {\n        if (u32val & 0x80000000L)\n            break;\n        u32val <<= 1;\n    }\n    return i;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/rpng2-win.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng2 - progressive-model PNG display program                rpng2-win.c\n\n   This program decodes and displays PNG files progressively, as if it were\n   a web browser (though the front end is only set up to read from files).\n   It supports gamma correction, user-specified background colors, and user-\n   specified background patterns (for transparent images).  This version is\n   for 32-bit Windows; it may compile under 16-bit Windows with a little\n   tweaking (or maybe not).  Thanks to Adam Costello and Pieter S. van der\n   Meulen for the \"diamond\" and \"radial waves\" patterns, respectively.\n\n   to do (someday, maybe):\n    - handle quoted command-line args (especially filenames with spaces)\n    - finish resizable checkerboard-gradient (sizes 4-128?)\n    - use %.1023s to simplify truncation of title-bar string?\n    - have minimum window width:  oh well\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n    - 1.01:  initial public release\n    - 1.02:  fixed cut-and-paste error in usage screen (oops...)\n    - 1.03:  modified to allow abbreviated options\n    - 1.04:  removed bogus extra argument from usage fprintf() [Glenn R-P?];\n              fixed command-line parsing bug\n    - 1.10:  enabled \"message window\"/console (thanks to David Geldreich)\n    - 1.20:  added runtime MMX-enabling/disabling and new -mmx* options\n    - 1.21:  made minor tweak to usage screen to fit within 25-line console\n    - 1.22:  added AMD64/EM64T support (__x86_64__)\n    - 2.00:  dual-licensed (added GNU GPL)\n    - 2.01:  fixed 64-bit typo in readpng2.c\n    - 2.02:  fixed improper display of usage screen on PNG error(s); fixed\n              unexpected-EOF and file-read-error cases\n    - 2.03:  removed runtime MMX-enabling/disabling and obsolete -mmx* options\n    - 2.04:\n             (GR-P)\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2008 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#define PROGNAME  \"rpng2-win\"\n#define LONGNAME  \"Progressive PNG Viewer for Windows\"\n#define VERSION   \"2.02 of 16 March 2008\"\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <setjmp.h>    /* for jmpbuf declaration in readpng2.h */\n#include <time.h>\n#include <math.h>      /* only for PvdM background code */\n#include <windows.h>\n#ifdef __CYGWIN__\n/* getch replacement. Turns out, we don't really need this,\n * but leave it here if we ever enable any of the uses of\n * _getch in the main code\n */\n#include <unistd.h>\n#include <termio.h>\n#include <sys/ioctl.h>\nint repl_getch( void )\n{\n  char ch;\n  int fd = fileno(stdin);\n  struct termio old_tty, new_tty;\n\n  ioctl(fd, TCGETA, &old_tty);\n  new_tty = old_tty;\n  new_tty.c_lflag &= ~(ICANON | ECHO | ISIG);\n  ioctl(fd, TCSETA, &new_tty);\n  fread(&ch, 1, sizeof(ch), stdin);\n  ioctl(fd, TCSETA, &old_tty);\n\n  return ch;\n}\n#define _getch repl_getch\n#else\n#include <conio.h>     /* only for _getch() */\n#endif\n\n/* all for PvdM background code: */\n#ifndef PI\n#  define PI             3.141592653589793238\n#endif\n#define PI_2             (PI*0.5)\n#define INV_PI_360       (360.0 / PI)\n#define MAX(a,b)         (a>b?a:b)\n#define MIN(a,b)         (a<b?a:b)\n#define CLIP(a,min,max)  MAX(min,MIN((a),max))\n#define ABS(a)           ((a)<0?-(a):(a))\n#define CLIP8P(c)        MAX(0,(MIN((c),255)))   /* 8-bit pos. integer (uch) */\n#define ROUNDF(f)        ((int)(f + 0.5))\n\n#define rgb1_max   bg_freq\n#define rgb1_min   bg_gray\n#define rgb2_max   bg_bsat\n#define rgb2_min   bg_brot\n\n/* #define DEBUG */     /* this enables the Trace() macros */\n\n#include \"readpng2.h\"   /* typedefs, common macros, readpng2 prototypes */\n\n\n/* could just include png.h, but this macro is the only thing we need\n * (name and typedefs changed to local versions); note that side effects\n * only happen with alpha (which could easily be avoided with\n * \"ush acopy = (alpha);\") */\n\n#define alpha_composite(composite, fg, alpha, bg) {               \\\n    ush temp = ((ush)(fg)*(ush)(alpha) +                          \\\n                (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128);  \\\n    (composite) = (uch)((temp + (temp >> 8)) >> 8);               \\\n}\n\n\n#define INBUFSIZE 4096   /* with pseudo-timing on (1 sec delay/block), this\n                          *  block size corresponds roughly to a download\n                          *  speed 10% faster than theoretical 33.6K maximum\n                          *  (assuming 8 data bits, 1 stop bit and no other\n                          *  overhead) */\n\n/* local prototypes */\nstatic void       rpng2_win_init(void);\nstatic int        rpng2_win_create_window(void);\nstatic int        rpng2_win_load_bg_image(void);\nstatic void       rpng2_win_display_row(ulg row);\nstatic void       rpng2_win_finish_display(void);\nstatic void       rpng2_win_cleanup(void);\nLRESULT CALLBACK  rpng2_win_wndproc(HWND, UINT, WPARAM, LPARAM);\n\n\nstatic char titlebar[1024];\nstatic char *progname = PROGNAME;\nstatic char *appname = LONGNAME;\nstatic char *filename;\nstatic FILE *infile;\n\nstatic mainprog_info rpng2_info;\n\nstatic uch inbuf[INBUFSIZE];\nstatic int incount;\n\nstatic int pat = 6;         /* must be less than num_bgpat */\nstatic int bg_image = 0;\nstatic int bgscale = 16;\nstatic ulg bg_rowbytes;\nstatic uch *bg_data;\n\nstatic struct rgb_color {\n    uch r, g, b;\n} rgb[] = {\n    {  0,   0,   0},    /*  0:  black */\n    {255, 255, 255},    /*  1:  white */\n    {173, 132,  57},    /*  2:  tan */\n    { 64, 132,   0},    /*  3:  medium green */\n    {189, 117,   1},    /*  4:  gold */\n    {253, 249,   1},    /*  5:  yellow */\n    {  0,   0, 255},    /*  6:  blue */\n    {  0,   0, 120},    /*  7:  medium blue */\n    {255,   0, 255},    /*  8:  magenta */\n    { 64,   0,  64},    /*  9:  dark magenta */\n    {255,   0,   0},    /* 10:  red */\n    { 64,   0,   0},    /* 11:  dark red */\n    {255, 127,   0},    /* 12:  orange */\n    {192,  96,   0},    /* 13:  darker orange */\n    { 24,  60,   0},    /* 14:  dark green-yellow */\n    { 85, 125, 200}     /* 15:  ice blue */\n};\n/* not used for now, but should be for error-checking:\nstatic int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);\n */\n\n/*\n    This whole struct is a fairly cheesy way to keep the number of\n    command-line options to a minimum.  The radial-waves background\n    type is a particularly poor fit to the integer elements of the\n    struct...but a few macros and a little fixed-point math will do\n    wonders for ya.\n\n    type bits:\n       F E D C B A 9 8 7 6 5 4 3 2 1 0\n                             | | | | |\n                             | | +-+-+-- 0 = sharp-edged checkerboard\n                             | |         1 = soft diamonds\n                             | |         2 = radial waves\n                             | |       3-7 = undefined\n                             | +-- gradient #2 inverted?\n                             +-- alternating columns inverted?\n */\nstatic struct background_pattern {\n    ush type;\n    int rgb1_max, rgb1_min;     /* or bg_freq, bg_gray */\n    int rgb2_max, rgb2_min;     /* or bg_bsat, bg_brot (both scaled by 10)*/\n} bg[] = {\n    {0+8,   2,0,  1,15},        /* checkered:  tan/black vs. white/ice blue */\n    {0+24,  2,0,  1,0},         /* checkered:  tan/black vs. white/black */\n    {0+8,   4,5,  0,2},         /* checkered:  gold/yellow vs. black/tan */\n    {0+8,   4,5,  0,6},         /* checkered:  gold/yellow vs. black/blue */\n    {0,     7,0,  8,9},         /* checkered:  deep blue/black vs. magenta */\n    {0+8,  13,0,  5,14},        /* checkered:  orange/black vs. yellow */\n    {0+8,  12,0, 10,11},        /* checkered:  orange/black vs. red */\n    {1,     7,0,  8,0},         /* diamonds:  deep blue/black vs. magenta */\n    {1,    12,0, 11,0},         /* diamonds:  orange vs. dark red */\n    {1,    10,0,  7,0},         /* diamonds:  red vs. medium blue */\n    {1,     4,0,  5,0},         /* diamonds:  gold vs. yellow */\n    {1,     3,0,  0,0},         /* diamonds:  medium green vs. black */\n    {2,    16, 100,  20,   0},  /* radial:  ~hard radial color-beams */\n    {2,    18, 100,  10,   2},  /* radial:  soft, curved radial color-beams */\n    {2,    16, 256, 100, 250},  /* radial:  very tight spiral */\n    {2, 10000, 256,  11,   0}   /* radial:  dipole-moire' (almost fractal) */\n};\nstatic int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);\n\n\n/* Windows-specific global variables (could go in struct, but messy...) */\nstatic ulg wimage_rowbytes;\nstatic uch *dib;\nstatic uch *wimage_data;\nstatic BITMAPINFOHEADER *bmih;\n\nstatic HWND global_hwnd;\nstatic HINSTANCE global_hInst;\nstatic int global_showmode;\n\n\n\n\nint WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, PSTR cmd, int showmode)\n{\n    char *args[1024];                 /* arbitrary limit, but should suffice */\n    char **argv = args;\n    char *p, *q, *bgstr = NULL;\n    int argc = 0;\n    int rc, alen, flen;\n    int error = 0;\n    int timing = FALSE;\n    int have_bg = FALSE;\n    double LUT_exponent;              /* just the lookup table */\n    double CRT_exponent = 2.2;        /* just the monitor */\n    double default_display_exponent;  /* whole display system */\n    MSG msg;\n\n\n    /* First initialize a few things, just to be sure--memset takes care of\n     * default background color (black), booleans (FALSE), pointers (NULL),\n     * etc. */\n\n    global_hInst = hInst;\n    global_showmode = showmode;\n    filename = (char *)NULL;\n    memset(&rpng2_info, 0, sizeof(mainprog_info));\n\n#ifndef __CYGWIN__\n    /* Next reenable console output, which normally goes to the bit bucket\n     * for windowed apps.  Closing the console window will terminate the\n     * app.  Thanks to David.Geldreich@realviz.com for supplying the magical\n     * incantation. */\n\n    AllocConsole();\n    freopen(\"CONOUT$\", \"a\", stderr);\n    freopen(\"CONOUT$\", \"a\", stdout);\n#endif\n\n    /* Set the default value for our display-system exponent, i.e., the\n     * product of the CRT exponent and the exponent corresponding to\n     * the frame-buffer's lookup table (LUT), if any.  This is not an\n     * exhaustive list of LUT values (e.g., OpenStep has a lot of weird\n     * ones), but it should cover 99% of the current possibilities.  And\n     * yes, these ifdefs are completely wasted in a Windows program... */\n\n#if defined(NeXT)\n    /* third-party utilities can modify the default LUT exponent */\n    LUT_exponent = 1.0 / 2.2;\n    /*\n    if (some_next_function_that_returns_gamma(&next_gamma))\n        LUT_exponent = 1.0 / next_gamma;\n     */\n#elif defined(sgi)\n    LUT_exponent = 1.0 / 1.7;\n    /* there doesn't seem to be any documented function to\n     * get the \"gamma\" value, so we do it the hard way */\n    infile = fopen(\"/etc/config/system.glGammaVal\", \"r\");\n    if (infile) {\n        double sgi_gamma;\n\n        fgets(tmpline, 80, infile);\n        fclose(infile);\n        sgi_gamma = atof(tmpline);\n        if (sgi_gamma > 0.0)\n            LUT_exponent = 1.0 / sgi_gamma;\n    }\n#elif defined(Macintosh)\n    LUT_exponent = 1.8 / 2.61;\n    /*\n    if (some_mac_function_that_returns_gamma(&mac_gamma))\n        LUT_exponent = mac_gamma / 2.61;\n     */\n#else\n    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */\n#endif\n\n    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */\n    default_display_exponent = LUT_exponent * CRT_exponent;\n\n\n    /* If the user has set the SCREEN_GAMMA environment variable as suggested\n     * (somewhat imprecisely) in the libpng documentation, use that; otherwise\n     * use the default value we just calculated.  Either way, the user may\n     * override this via a command-line option. */\n\n    if ((p = getenv(\"SCREEN_GAMMA\")) != NULL)\n        rpng2_info.display_exponent = atof(p);\n    else\n        rpng2_info.display_exponent = default_display_exponent;\n\n\n    /* Windows really hates command lines, so we have to set up our own argv.\n     * Note that we do NOT bother with quoted arguments here, so don't use\n     * filenames with spaces in 'em! */\n\n    argv[argc++] = PROGNAME;\n    p = cmd;\n    for (;;) {\n        if (*p == ' ')\n            while (*++p == ' ')\n                ;\n        /* now p points at the first non-space after some spaces */\n        if (*p == '\\0')\n            break;    /* nothing after the spaces:  done */\n        argv[argc++] = q = p;\n        while (*q && *q != ' ')\n            ++q;\n        /* now q points at a space or the end of the string */\n        if (*q == '\\0')\n            break;    /* last argv already terminated; quit */\n        *q = '\\0';    /* change space to terminator */\n        p = q + 1;\n    }\n    argv[argc] = NULL;   /* terminate the argv array itself */\n\n\n    /* Now parse the command line for options and the PNG filename. */\n\n    while (*++argv && !error) {\n        if (!strncmp(*argv, \"-gamma\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                rpng2_info.display_exponent = atof(*argv);\n                if (rpng2_info.display_exponent <= 0.0)\n                    ++error;\n            }\n        } else if (!strncmp(*argv, \"-bgcolor\", 4)) {\n            if (!*++argv)\n                ++error;\n            else {\n                bgstr = *argv;\n                if (strlen(bgstr) != 7 || bgstr[0] != '#')\n                    ++error;\n                else {\n                    have_bg = TRUE;\n                    bg_image = FALSE;\n                }\n            }\n        } else if (!strncmp(*argv, \"-bgpat\", 4)) {\n            if (!*++argv)\n                ++error;\n            else {\n                pat = atoi(*argv) - 1;\n                if (pat < 0 || pat >= num_bgpat)\n                    ++error;\n                else {\n                    bg_image = TRUE;\n                    have_bg = FALSE;\n                }\n            }\n        } else if (!strncmp(*argv, \"-timing\", 2)) {\n            timing = TRUE;\n        } else {\n            if (**argv != '-') {\n                filename = *argv;\n                if (argv[1])   /* shouldn't be any more args after filename */\n                    ++error;\n            } else\n                ++error;   /* not expecting any other options */\n        }\n    }\n\n    if (!filename)\n        ++error;\n\n\n    /* print usage screen if any errors up to this point */\n\n    if (error) {\n#ifndef __CYGWIN__\n        int ch;\n#endif\n\n        fprintf(stderr, \"\\n%s %s:  %s\\n\\n\", PROGNAME, VERSION, appname);\n        readpng2_version_info();\n        fprintf(stderr, \"\\n\"\n          \"Usage:  %s [-gamma exp] [-bgcolor bg | -bgpat pat] [-timing]\\n\"\n          \"        %*s file.png\\n\\n\"\n          \"    exp \\ttransfer-function exponent (``gamma'') of the display\\n\"\n          \"\\t\\t  system in floating-point format (e.g., ``%.1f''); equal\\n\"\n          \"\\t\\t  to the product of the lookup-table exponent (varies)\\n\"\n          \"\\t\\t  and the CRT exponent (usually 2.2); must be positive\\n\"\n          \"    bg  \\tdesired background color in 7-character hex RGB format\\n\"\n          \"\\t\\t  (e.g., ``#ff7700'' for orange:  same as HTML colors);\\n\"\n          \"\\t\\t  used with transparent images; overrides -bgpat option\\n\"\n          \"    pat \\tdesired background pattern number (1-%d); used with\\n\"\n          \"\\t\\t  transparent images; overrides -bgcolor option\\n\"\n          \"    -timing\\tenables delay for every block read, to simulate modem\\n\"\n          \"\\t\\t  download of image (~36 Kbps)\\n\"\n          \"\\nPress Q, Esc or mouse button 1 after image is displayed to quit.\\n\"\n#ifndef __CYGWIN__\n          \"Press Q or Esc to quit this usage screen. \",\n#else\n          ,\n#endif\n          PROGNAME,\n#if (defined(__i386__) || defined(_M_IX86) || defined(__x86_64__)) && \\\n    !(defined(__CYGWIN__) || defined(__MINGW32__))\n          (int)strlen(PROGNAME), \" \",\n#endif\n          (int)strlen(PROGNAME), \" \", default_display_exponent, num_bgpat);\n        fflush(stderr);\n#ifndef __CYGWIN__\n        do\n            ch = _getch();\n        while (ch != 'q' && ch != 'Q' && ch != 0x1B);\n#endif\n        exit(1);\n    }\n\n\n    if (!(infile = fopen(filename, \"rb\"))) {\n        fprintf(stderr, PROGNAME \":  can't open PNG file [%s]\\n\", filename);\n        ++error;\n    } else {\n        incount = fread(inbuf, 1, INBUFSIZE, infile);\n        if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {\n            fprintf(stderr, PROGNAME\n              \":  [%s] is not a PNG file: incorrect signature\\n\",\n              filename);\n            ++error;\n        } else if ((rc = readpng2_init(&rpng2_info)) != 0) {\n            switch (rc) {\n                case 2:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] has bad IHDR (libpng longjmp)\\n\", filename);\n                    break;\n                case 4:\n                    fprintf(stderr, PROGNAME \":  insufficient memory\\n\");\n                    break;\n                default:\n                    fprintf(stderr, PROGNAME\n                      \":  unknown readpng2_init() error\\n\");\n                    break;\n            }\n            ++error;\n        }\n        if (error)\n            fclose(infile);\n    }\n\n\n    if (error) {\n#ifndef __CYGWIN__\n        int ch;\n#endif\n\n        fprintf(stderr, PROGNAME \":  aborting.\\n\");\n#ifndef __CYGWIN__\n        do\n            ch = _getch();\n        while (ch != 'q' && ch != 'Q' && ch != 0x1B);\n#endif\n        exit(2);\n    } else {\n        fprintf(stderr, \"\\n%s %s:  %s\\n\", PROGNAME, VERSION, appname);\n#ifndef __CYGWIN__\n        fprintf(stderr,\n          \"\\n   [console window:  closing this window will terminate %s]\\n\\n\",\n          PROGNAME);\n#endif\n        fflush(stderr);\n    }\n\n\n    /* set the title-bar string, but make sure buffer doesn't overflow */\n\n    alen = strlen(appname);\n    flen = strlen(filename);\n    if (alen + flen + 3 > 1023)\n        sprintf(titlebar, \"%s:  ...%s\", appname, filename+(alen+flen+6-1023));\n    else\n        sprintf(titlebar, \"%s:  %s\", appname, filename);\n\n\n    /* set some final rpng2_info variables before entering main data loop */\n\n    if (have_bg) {\n        unsigned r, g, b;   /* this approach quiets compiler warnings */\n\n        sscanf(bgstr+1, \"%2x%2x%2x\", &r, &g, &b);\n        rpng2_info.bg_red   = (uch)r;\n        rpng2_info.bg_green = (uch)g;\n        rpng2_info.bg_blue  = (uch)b;\n    } else\n        rpng2_info.need_bgcolor = TRUE;\n\n    rpng2_info.state = kPreInit;\n    rpng2_info.mainprog_init = rpng2_win_init;\n    rpng2_info.mainprog_display_row = rpng2_win_display_row;\n    rpng2_info.mainprog_finish_display = rpng2_win_finish_display;\n\n\n    /* OK, this is the fun part:  call readpng2_decode_data() at the start of\n     * the loop to deal with our first buffer of data (read in above to verify\n     * that the file is a PNG image), then loop through the file and continue\n     * calling the same routine to handle each chunk of data.  It in turn\n     * passes the data to libpng, which will invoke one or more of our call-\n     * backs as decoded data become available.  We optionally call Sleep() for\n     * one second per iteration to simulate downloading the image via an analog\n     * modem. */\n\n    for (;;) {\n        Trace((stderr, \"about to call readpng2_decode_data()\\n\"))\n        if (readpng2_decode_data(&rpng2_info, inbuf, incount))\n            ++error;\n        Trace((stderr, \"done with readpng2_decode_data()\\n\"))\n\n        if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {\n            if (rpng2_info.state == kDone) {\n                Trace((stderr, \"done decoding PNG image\\n\"))\n            } else if (ferror(infile)) {\n                fprintf(stderr, PROGNAME\n                  \":  error while reading PNG image file\\n\");\n                exit(3);\n            } else if (feof(infile)) {\n                fprintf(stderr, PROGNAME \":  end of file reached \"\n                  \"(unexpectedly) while reading PNG image file\\n\");\n                exit(3);\n            } else /* if (error) */ {\n                /* will print error message below */\n            }\n            break;\n        }\n\n        if (timing)\n            Sleep(1000L);\n\n        incount = fread(inbuf, 1, INBUFSIZE, infile);\n    }\n\n\n    /* clean up PNG stuff and report any decoding errors */\n\n    fclose(infile);\n    Trace((stderr, \"about to call readpng2_cleanup()\\n\"))\n    readpng2_cleanup(&rpng2_info);\n\n    if (error) {\n        fprintf(stderr, PROGNAME \":  libpng error while decoding PNG image\\n\");\n        exit(3);\n    }\n\n\n    /* wait for the user to tell us when to quit */\n\n    while (GetMessage(&msg, NULL, 0, 0)) {\n        TranslateMessage(&msg);\n        DispatchMessage(&msg);\n    }\n\n\n    /* we're done:  clean up all image and Windows resources and go away */\n\n    Trace((stderr, \"about to call rpng2_win_cleanup()\\n\"))\n    rpng2_win_cleanup();\n\n    return msg.wParam;\n}\n\n\n\n\n\n/* this function is called by readpng2_info_callback() in readpng2.c, which\n * in turn is called by libpng after all of the pre-IDAT chunks have been\n * read and processed--i.e., we now have enough info to finish initializing */\n\nstatic void rpng2_win_init()\n{\n    ulg i;\n    ulg rowbytes = rpng2_info.rowbytes;\n\n    Trace((stderr, \"beginning rpng2_win_init()\\n\"))\n    Trace((stderr, \"  rowbytes = %d\\n\", rpng2_info.rowbytes))\n    Trace((stderr, \"  width  = %ld\\n\", rpng2_info.width))\n    Trace((stderr, \"  height = %ld\\n\", rpng2_info.height))\n\n    rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);\n    if (!rpng2_info.image_data) {\n        readpng2_cleanup(&rpng2_info);\n        return;\n    }\n\n    rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));\n    if (!rpng2_info.row_pointers) {\n        free(rpng2_info.image_data);\n        rpng2_info.image_data = NULL;\n        readpng2_cleanup(&rpng2_info);\n        return;\n    }\n\n    for (i = 0;  i < rpng2_info.height;  ++i)\n        rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;\n\n/*---------------------------------------------------------------------------\n    Do the basic Windows initialization stuff, make the window, and fill it\n    with the user-specified, file-specified or default background color.\n  ---------------------------------------------------------------------------*/\n\n    if (rpng2_win_create_window()) {\n        readpng2_cleanup(&rpng2_info);\n        return;\n    }\n\n    rpng2_info.state = kWindowInit;\n}\n\n\n\n\n\nstatic int rpng2_win_create_window()\n{\n    uch bg_red   = rpng2_info.bg_red;\n    uch bg_green = rpng2_info.bg_green;\n    uch bg_blue  = rpng2_info.bg_blue;\n    uch *dest;\n    int extra_width, extra_height;\n    ulg i, j;\n    WNDCLASSEX wndclass;\n    RECT rect;\n\n\n/*---------------------------------------------------------------------------\n    Allocate memory for the display-specific version of the image (round up\n    to multiple of 4 for Windows DIB).\n  ---------------------------------------------------------------------------*/\n\n    wimage_rowbytes = ((3*rpng2_info.width + 3L) >> 2) << 2;\n\n    if (!(dib = (uch *)malloc(sizeof(BITMAPINFOHEADER) +\n                              wimage_rowbytes*rpng2_info.height)))\n    {\n        return 4;   /* fail */\n    }\n\n/*---------------------------------------------------------------------------\n    Initialize the DIB.  Negative height means to use top-down BMP ordering\n    (must be uncompressed, but that's what we want).  Bit count of 1, 4 or 8\n    implies a colormap of RGBX quads, but 24-bit BMPs just use B,G,R values\n    directly => wimage_data begins immediately after BMP header.\n  ---------------------------------------------------------------------------*/\n\n    memset(dib, 0, sizeof(BITMAPINFOHEADER));\n    bmih = (BITMAPINFOHEADER *)dib;\n    bmih->biSize = sizeof(BITMAPINFOHEADER);\n    bmih->biWidth = rpng2_info.width;\n    bmih->biHeight = -((long)rpng2_info.height);\n    bmih->biPlanes = 1;\n    bmih->biBitCount = 24;\n    bmih->biCompression = 0;\n    wimage_data = dib + sizeof(BITMAPINFOHEADER);\n\n/*---------------------------------------------------------------------------\n    Fill window with the specified background color (default is black), but\n    defer loading faked \"background image\" until window is displayed (may be\n    slow to compute).  Data are in BGR order.\n  ---------------------------------------------------------------------------*/\n\n    if (bg_image) {   /* just fill with black for now */\n        memset(wimage_data, 0, wimage_rowbytes*rpng2_info.height);\n    } else {\n        for (j = 0;  j < rpng2_info.height;  ++j) {\n            dest = wimage_data + j*wimage_rowbytes;\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                *dest++ = bg_blue;\n                *dest++ = bg_green;\n                *dest++ = bg_red;\n            }\n        }\n    }\n\n/*---------------------------------------------------------------------------\n    Set the window parameters.\n  ---------------------------------------------------------------------------*/\n\n    memset(&wndclass, 0, sizeof(wndclass));\n\n    wndclass.cbSize = sizeof(wndclass);\n    wndclass.style = CS_HREDRAW | CS_VREDRAW;\n    wndclass.lpfnWndProc = rpng2_win_wndproc;\n    wndclass.hInstance = global_hInst;\n    wndclass.hIcon = LoadIcon(NULL, IDI_APPLICATION);\n    wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);\n    wndclass.hbrBackground = (HBRUSH)GetStockObject(DKGRAY_BRUSH);\n    wndclass.lpszMenuName = NULL;\n    wndclass.lpszClassName = progname;\n    wndclass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);\n\n    RegisterClassEx(&wndclass);\n\n/*---------------------------------------------------------------------------\n    Finally, create the window.\n  ---------------------------------------------------------------------------*/\n\n    extra_width  = 2*(GetSystemMetrics(SM_CXBORDER) +\n                      GetSystemMetrics(SM_CXDLGFRAME));\n    extra_height = 2*(GetSystemMetrics(SM_CYBORDER) +\n                      GetSystemMetrics(SM_CYDLGFRAME)) +\n                      GetSystemMetrics(SM_CYCAPTION);\n\n    global_hwnd = CreateWindow(progname, titlebar, WS_OVERLAPPEDWINDOW,\n      CW_USEDEFAULT, CW_USEDEFAULT, rpng2_info.width+extra_width,\n      rpng2_info.height+extra_height, NULL, NULL, global_hInst, NULL);\n\n    ShowWindow(global_hwnd, global_showmode);\n    UpdateWindow(global_hwnd);\n\n/*---------------------------------------------------------------------------\n    Now compute the background image and display it.  If it fails (memory\n    allocation), revert to a plain background color.\n  ---------------------------------------------------------------------------*/\n\n    if (bg_image) {\n        static const char *msg = \"Computing background image...\";\n        int x, y, len = strlen(msg);\n        HDC hdc = GetDC(global_hwnd);\n        TEXTMETRIC tm;\n\n        GetTextMetrics(hdc, &tm);\n        x = (rpng2_info.width - len*tm.tmAveCharWidth)/2;\n        y = (rpng2_info.height - tm.tmHeight)/2;\n        SetBkMode(hdc, TRANSPARENT);\n        SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));\n        /* this can still begin out of bounds even if x is positive (???): */\n        TextOut(hdc, ((x < 0)? 0 : x), ((y < 0)? 0 : y), msg, len);\n        ReleaseDC(global_hwnd, hdc);\n\n        rpng2_win_load_bg_image();   /* resets bg_image if fails */\n    }\n\n    if (!bg_image) {\n        for (j = 0;  j < rpng2_info.height;  ++j) {\n            dest = wimage_data + j*wimage_rowbytes;\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                *dest++ = bg_blue;\n                *dest++ = bg_green;\n                *dest++ = bg_red;\n            }\n        }\n    }\n\n    rect.left = 0L;\n    rect.top = 0L;\n    rect.right = (LONG)rpng2_info.width;       /* possibly off by one? */\n    rect.bottom = (LONG)rpng2_info.height;     /* possibly off by one? */\n    InvalidateRect(global_hwnd, &rect, FALSE);\n    UpdateWindow(global_hwnd);                 /* similar to XFlush() */\n\n    return 0;\n\n} /* end function rpng2_win_create_window() */\n\n\n\n\n\nstatic int rpng2_win_load_bg_image()\n{\n    uch *src, *dest;\n    uch r1, r2, g1, g2, b1, b2;\n    uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;\n    int k, hmax, max;\n    int xidx, yidx, yidx_max = (bgscale-1);\n    int even_odd_vert, even_odd_horiz, even_odd;\n    int invert_gradient2 = (bg[pat].type & 0x08);\n    int invert_column;\n    ulg i, row;\n\n/*---------------------------------------------------------------------------\n    Allocate buffer for fake background image to be used with transparent\n    images; if this fails, revert to plain background color.\n  ---------------------------------------------------------------------------*/\n\n    bg_rowbytes = 3 * rpng2_info.width;\n    bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);\n    if (!bg_data) {\n        fprintf(stderr, PROGNAME\n          \":  unable to allocate memory for background image\\n\");\n        bg_image = 0;\n        return 1;\n    }\n\n/*---------------------------------------------------------------------------\n    Vertical gradients (ramps) in NxN squares, alternating direction and\n    colors (N == bgscale).\n  ---------------------------------------------------------------------------*/\n\n    if ((bg[pat].type & 0x07) == 0) {\n        uch r1_min  = rgb[bg[pat].rgb1_min].r;\n        uch g1_min  = rgb[bg[pat].rgb1_min].g;\n        uch b1_min  = rgb[bg[pat].rgb1_min].b;\n        uch r2_min  = rgb[bg[pat].rgb2_min].r;\n        uch g2_min  = rgb[bg[pat].rgb2_min].g;\n        uch b2_min  = rgb[bg[pat].rgb2_min].b;\n        int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;\n        int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;\n        int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;\n        int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;\n        int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;\n        int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = row % bgscale;\n            even_odd_vert = (row / bgscale) & 1;\n\n            r1 = r1_min + (r1_diff * yidx) / yidx_max;\n            g1 = g1_min + (g1_diff * yidx) / yidx_max;\n            b1 = b1_min + (b1_diff * yidx) / yidx_max;\n            r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;\n            g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;\n            b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;\n\n            r2 = r2_min + (r2_diff * yidx) / yidx_max;\n            g2 = g2_min + (g2_diff * yidx) / yidx_max;\n            b2 = b2_min + (b2_diff * yidx) / yidx_max;\n            r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;\n            g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;\n            b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;\n\n            dest = bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                even_odd_horiz = (i / bgscale) & 1;\n                even_odd = even_odd_vert ^ even_odd_horiz;\n                invert_column =\n                  (even_odd_horiz && (bg[pat].type & 0x10));\n                if (even_odd == 0) {         /* gradient #1 */\n                    if (invert_column) {\n                        *dest++ = r1_inv;\n                        *dest++ = g1_inv;\n                        *dest++ = b1_inv;\n                    } else {\n                        *dest++ = r1;\n                        *dest++ = g1;\n                        *dest++ = b1;\n                    }\n                } else {                     /* gradient #2 */\n                    if ((invert_column && invert_gradient2) ||\n                        (!invert_column && !invert_gradient2))\n                    {\n                        *dest++ = r2;        /* not inverted or */\n                        *dest++ = g2;        /*  doubly inverted */\n                        *dest++ = b2;\n                    } else {\n                        *dest++ = r2_inv;\n                        *dest++ = g2_inv;    /* singly inverted */\n                        *dest++ = b2_inv;\n                    }\n                }\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Soft gradient-diamonds with scale = bgscale.  Code contributed by Adam\n    M. Costello.\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 1) {\n\n        hmax = (bgscale-1)/2;   /* half the max weight of a color */\n        max = 2*hmax;           /* the max weight of a color */\n\n        r1 = rgb[bg[pat].rgb1_max].r;\n        g1 = rgb[bg[pat].rgb1_max].g;\n        b1 = rgb[bg[pat].rgb1_max].b;\n        r2 = rgb[bg[pat].rgb2_max].r;\n        g2 = rgb[bg[pat].rgb2_max].g;\n        b2 = rgb[bg[pat].rgb2_max].b;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = row % bgscale;\n            if (yidx > hmax)\n                yidx = bgscale-1 - yidx;\n            dest = bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                xidx = i % bgscale;\n                if (xidx > hmax)\n                    xidx = bgscale-1 - xidx;\n                k = xidx + yidx;\n                *dest++ = (k*r1 + (max-k)*r2) / max;\n                *dest++ = (k*g1 + (max-k)*g2) / max;\n                *dest++ = (k*b1 + (max-k)*b2) / max;\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Radial \"starburst\" with azimuthal sinusoids; [eventually number of sinu-\n    soids will equal bgscale?].  This one is slow but very cool.  Code con-\n    tributed by Pieter S. van der Meulen (originally in Smalltalk).\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 2) {\n        uch ch;\n        int ii, x, y, hw, hh, grayspot;\n        double freq, rotate, saturate, gray, intensity;\n        double angle=0.0, aoffset=0.0, maxDist, dist;\n        double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;\n\n        fprintf(stderr, \"%s:  computing radial background...\",\n          PROGNAME);\n        fflush(stderr);\n\n        hh = rpng2_info.height / 2;\n        hw = rpng2_info.width / 2;\n\n        /* variables for radial waves:\n         *   aoffset:  number of degrees to rotate hue [CURRENTLY NOT USED]\n         *   freq:  number of color beams originating from the center\n         *   grayspot:  size of the graying center area (anti-alias)\n         *   rotate:  rotation of the beams as a function of radius\n         *   saturate:  saturation of beams' shape azimuthally\n         */\n        angle = CLIP(angle, 0.0, 360.0);\n        grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));\n        freq = MAX((double)bg[pat].bg_freq, 0.0);\n        saturate = (double)bg[pat].bg_bsat * 0.1;\n        rotate = (double)bg[pat].bg_brot * 0.1;\n        gray = 0.0;\n        intensity = 0.0;\n        maxDist = (double)((hw*hw) + (hh*hh));\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            y = row - hh;\n            dest = bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                x = i - hw;\n                angle = (x == 0)? PI_2 : atan((double)y / (double)x);\n                gray = (double)MAX(ABS(y), ABS(x)) / grayspot;\n                gray = MIN(1.0, gray);\n                dist = (double)((x*x) + (y*y)) / maxDist;\n                intensity = cos((angle+(rotate*dist*PI)) * freq) *\n                  gray * saturate;\n                intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;\n                hue = (angle + PI) * INV_PI_360 + aoffset;\n                s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));\n                s = MIN(MAX(s,0.0), 1.0);\n                v = MIN(MAX(intensity,0.0), 1.0);\n\n                if (s == 0.0) {\n                    ch = (uch)(v * 255.0);\n                    *dest++ = ch;\n                    *dest++ = ch;\n                    *dest++ = ch;\n                } else {\n                    if ((hue < 0.0) || (hue >= 360.0))\n                        hue -= (((int)(hue / 360.0)) * 360.0);\n                    hue /= 60.0;\n                    ii = (int)hue;\n                    f = hue - (double)ii;\n                    p = (1.0 - s) * v;\n                    q = (1.0 - (s * f)) * v;\n                    t = (1.0 - (s * (1.0 - f))) * v;\n                    if      (ii == 0) { red = v; green = t; blue = p; }\n                    else if (ii == 1) { red = q; green = v; blue = p; }\n                    else if (ii == 2) { red = p; green = v; blue = t; }\n                    else if (ii == 3) { red = p; green = q; blue = v; }\n                    else if (ii == 4) { red = t; green = p; blue = v; }\n                    else if (ii == 5) { red = v; green = p; blue = q; }\n                    *dest++ = (uch)(red * 255.0);\n                    *dest++ = (uch)(green * 255.0);\n                    *dest++ = (uch)(blue * 255.0);\n                }\n            }\n        }\n        fprintf(stderr, \"done.\\n\");\n        fflush(stderr);\n    }\n\n/*---------------------------------------------------------------------------\n    Blast background image to display buffer before beginning PNG decode;\n    calling function will handle invalidation and UpdateWindow() call.\n  ---------------------------------------------------------------------------*/\n\n    for (row = 0;  row < rpng2_info.height;  ++row) {\n        src = bg_data + row*bg_rowbytes;\n        dest = wimage_data + row*wimage_rowbytes;\n        for (i = rpng2_info.width;  i > 0;  --i) {\n            r1 = *src++;\n            g1 = *src++;\n            b1 = *src++;\n            *dest++ = b1;\n            *dest++ = g1;   /* note reverse order */\n            *dest++ = r1;\n        }\n    }\n\n    return 0;\n\n} /* end function rpng2_win_load_bg_image() */\n\n\n\n\n\nstatic void rpng2_win_display_row(ulg row)\n{\n    uch bg_red   = rpng2_info.bg_red;\n    uch bg_green = rpng2_info.bg_green;\n    uch bg_blue  = rpng2_info.bg_blue;\n    uch *src, *src2=NULL, *dest;\n    uch r, g, b, a;\n    ulg i;\n    static int rows=0;\n    static ulg firstrow;\n\n/*---------------------------------------------------------------------------\n    rows and firstrow simply track how many rows (and which ones) have not\n    yet been displayed; alternatively, we could call InvalidateRect() for\n    every row and not bother with the records-keeping.\n  ---------------------------------------------------------------------------*/\n\n    Trace((stderr, \"beginning rpng2_win_display_row()\\n\"))\n\n    if (rows == 0)\n        firstrow = row;   /* first row not yet displayed */\n\n    ++rows;   /* count of rows received but not yet displayed */\n\n/*---------------------------------------------------------------------------\n    Aside from the use of the rpng2_info struct and the lack of an outer\n    loop (over rows), this routine is identical to rpng_win_display_image()\n    in the non-progressive version of the program.\n  ---------------------------------------------------------------------------*/\n\n    src = rpng2_info.image_data + row*rpng2_info.rowbytes;\n    if (bg_image)\n        src2 = bg_data + row*bg_rowbytes;\n    dest = wimage_data + row*wimage_rowbytes;\n\n    if (rpng2_info.channels == 3) {\n        for (i = rpng2_info.width;  i > 0;  --i) {\n            r = *src++;\n            g = *src++;\n            b = *src++;\n            *dest++ = b;\n            *dest++ = g;   /* note reverse order */\n            *dest++ = r;\n        }\n    } else /* if (rpng2_info.channels == 4) */ {\n        for (i = rpng2_info.width;  i > 0;  --i) {\n            r = *src++;\n            g = *src++;\n            b = *src++;\n            a = *src++;\n            if (bg_image) {\n                bg_red   = *src2++;\n                bg_green = *src2++;\n                bg_blue  = *src2++;\n            }\n            if (a == 255) {\n                *dest++ = b;\n                *dest++ = g;\n                *dest++ = r;\n            } else if (a == 0) {\n                *dest++ = bg_blue;\n                *dest++ = bg_green;\n                *dest++ = bg_red;\n            } else {\n                /* this macro (copied from png.h) composites the\n                 * foreground and background values and puts the\n                 * result into the first argument; there are no\n                 * side effects with the first argument */\n                alpha_composite(*dest++, b, a, bg_blue);\n                alpha_composite(*dest++, g, a, bg_green);\n                alpha_composite(*dest++, r, a, bg_red);\n            }\n        }\n    }\n\n/*---------------------------------------------------------------------------\n    Display after every 16 rows or when on last row.  (Region may include\n    previously displayed lines due to interlacing--i.e., not contiguous.)\n  ---------------------------------------------------------------------------*/\n\n    if ((rows & 0xf) == 0 || row == rpng2_info.height-1) {\n        RECT rect;\n\n        rect.left = 0L;\n        rect.top = (LONG)firstrow;\n        rect.right = (LONG)rpng2_info.width;       /* possibly off by one? */\n        rect.bottom = (LONG)row + 1L;              /* possibly off by one? */\n        InvalidateRect(global_hwnd, &rect, FALSE);\n        UpdateWindow(global_hwnd);                 /* similar to XFlush() */\n        rows = 0;\n    }\n\n} /* end function rpng2_win_display_row() */\n\n\n\n\n\nstatic void rpng2_win_finish_display()\n{\n    Trace((stderr, \"beginning rpng2_win_finish_display()\\n\"))\n\n    /* last row has already been displayed by rpng2_win_display_row(), so\n     * we have nothing to do here except set a flag and let the user know\n     * that the image is done */\n\n    rpng2_info.state = kDone;\n    printf(\n#ifndef __CYGWIN__\n      \"Done.  Press Q, Esc or mouse button 1 (within image window) to quit.\\n\"\n#else\n      \"Done.  Press mouse button 1 (within image window) to quit.\\n\"\n#endif\n    );\n    fflush(stdout);\n}\n\n\n\n\n\nstatic void rpng2_win_cleanup()\n{\n    if (bg_image && bg_data) {\n        free(bg_data);\n        bg_data = NULL;\n    }\n\n    if (rpng2_info.image_data) {\n        free(rpng2_info.image_data);\n        rpng2_info.image_data = NULL;\n    }\n\n    if (rpng2_info.row_pointers) {\n        free(rpng2_info.row_pointers);\n        rpng2_info.row_pointers = NULL;\n    }\n\n    if (dib) {\n        free(dib);\n        dib = NULL;\n    }\n}\n\n\n\n\n\nLRESULT CALLBACK rpng2_win_wndproc(HWND hwnd, UINT iMsg, WPARAM wP, LPARAM lP)\n{\n    HDC         hdc;\n    PAINTSTRUCT ps;\n    int rc;\n\n    switch (iMsg) {\n        case WM_CREATE:\n            /* one-time processing here, if any */\n            return 0;\n\n        case WM_PAINT:\n            hdc = BeginPaint(hwnd, &ps);\n            rc = StretchDIBits(hdc, 0, 0, rpng2_info.width, rpng2_info.height,\n                                    0, 0, rpng2_info.width, rpng2_info.height,\n                                    wimage_data, (BITMAPINFO *)bmih,\n                                    0, SRCCOPY);\n            EndPaint(hwnd, &ps);\n            return 0;\n\n        /* wait for the user to tell us when to quit */\n        case WM_CHAR:\n            switch (wP) {       /* only need one, so ignore repeat count */\n                case 'q':\n                case 'Q':\n                case 0x1B:      /* Esc key */\n                    PostQuitMessage(0);\n            }\n            return 0;\n\n        case WM_LBUTTONDOWN:    /* another way of quitting */\n        case WM_DESTROY:\n            PostQuitMessage(0);\n            return 0;\n    }\n\n    return DefWindowProc(hwnd, iMsg, wP, lP);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/rpng2-x.c",
    "content": "/*---------------------------------------------------------------------------\n\n   rpng2 - progressive-model PNG display program                  rpng2-x.c\n\n   This program decodes and displays PNG files progressively, as if it were\n   a web browser (though the front end is only set up to read from files).\n   It supports gamma correction, user-specified background colors, and user-\n   specified background patterns (for transparent images).  This version is\n   for the X Window System (tested by the author under Unix and by Martin\n   Zinser under OpenVMS; may work under OS/2 with a little tweaking).\n\n   Thanks to Adam Costello and Pieter S. van der Meulen for the \"diamond\"\n   and \"radial waves\" patterns, respectively.\n\n   to do (someday, maybe):\n    - fix expose/redraw code:  don't draw entire row if only part exposed\n    - 8-bit (colormapped) X support\n    - finish resizable checkerboard-gradient (sizes 4-128?)\n    - use %.1023s to simplify truncation of title-bar string?\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n    - 1.01:  initial public release\n    - 1.02:  modified to allow abbreviated options; fixed char/uchar mismatch\n    - 1.10:  added support for non-default visuals; fixed X pixel-conversion\n    - 1.11:  added -usleep option for demos; fixed command-line parsing bug\n    - 1.12:  added -pause option for demos and testing\n    - 1.20:  added runtime MMX-enabling/disabling and new -mmx* options\n    - 1.21:  fixed some small X memory leaks (thanks to Franois Petitjean)\n    - 1.22:  fixed XFreeGC() crash bug (thanks to Patrick Welche)\n    - 1.23:  added -bgpat 0 mode (std white/gray checkerboard, 8x8 squares)\n    - 1.30:  added -loop option for -bgpat (ifdef FEATURE_LOOP); fixed bpp =\n              24; added support for X resources (thanks to Gerhard Niklasch)\n    - 1.31:  added code to skip unused chunks (thanks to Glenn Randers-Pehrson)\n    - 1.32:  added AMD64/EM64T support (__x86_64__); added basic expose/redraw\n              handling\n    - 2.00:  dual-licensed (added GNU GPL)\n    - 2.01:  fixed 64-bit typo in readpng2.c; fixed -pause usage description\n    - 2.02:  fixed improper display of usage screen on PNG error(s); fixed\n              unexpected-EOF and file-read-error cases; fixed Trace() cut-and-\n              paste bugs\n    - 2.03:  deleted runtime MMX-enabling/disabling and obsolete -mmx* options\n    - 2.04:  Added \"void(foo);\" statements to quiet pedantic compiler warnings\n             about unused variables (GR-P)\n    - 2.05:  Use nanosleep() instead of usleep(), which is deprecated (GR-P).\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2010, 2014-2015 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#define PROGNAME  \"rpng2-x\"\n#define LONGNAME  \"Progressive PNG Viewer for X\"\n#define VERSION   \"2.04 of 15 June 2014\"\n#define RESNAME   \"rpng2\"       /* our X resource application name */\n#define RESCLASS  \"Rpng\"       /* our X resource class name */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <ctype.h>\n#include <string.h>\n#include <setjmp.h>       /* for jmpbuf declaration in readpng2.h */\n#include <time.h>\n#include <math.h>         /* only for PvdM background code */\n#include <X11/Xlib.h>\n#include <X11/Xutil.h>\n#include <X11/Xos.h>\n#include <X11/keysym.h>   /* defines XK_* macros */\n\n#if _POSIX_C_SOURCE >= 199309L /* have nanosleep() */\n# undef usleep\n# define usleep(usec) {        \\\n   struct timespec ts;         \\\n   ts.tv_sec = 0;              \\\n   ts.tv_nsec = (usec) * 1000; \\\n   nanosleep(&ts, NULL); }\n#  endif\n\n#ifndef usleep /* have neither nanosleep() nor usleep() */\n#  define usleep(x) sleep(((x)+499999)/1000000)\n#endif\n\n#ifdef VMS\n#  include <unistd.h>\n#endif\n\n/* all for PvdM background code: */\n#ifndef PI\n#  define PI             3.141592653589793238\n#endif\n#define PI_2             (PI*0.5)\n#define INV_PI_360       (360.0 / PI)\n#define MAX(a,b)         (a>b?a:b)\n#define MIN(a,b)         (a<b?a:b)\n#define CLIP(a,min,max)  MAX(min,MIN((a),max))\n#define ABS(a)           ((a)<0?-(a):(a))\n#define CLIP8P(c)        MAX(0,(MIN((c),255)))   /* 8-bit pos. integer (uch) */\n#define ROUNDF(f)        ((int)(f + 0.5))\n\n#define QUIT(e,k) ((e.type == ButtonPress && e.xbutton.button == Button1) ||  \\\n                  (e.type == KeyPress &&   /*  v--- or 1 for shifted keys */  \\\n                  ((k = XLookupKeysym(&e.xkey, 0)) == XK_q || k == XK_Escape)))\n\n#define NO_24BIT_MASKS /* undef case not fully written--only for redisplay() */\n\n#define rgb1_max   bg_freq\n#define rgb1_min   bg_gray\n#define rgb2_max   bg_bsat\n#define rgb2_min   bg_brot\n\n/* #define DEBUG */     /* this enables the Trace() macros */\n\n#include \"readpng2.h\"   /* typedefs, common macros, readpng2 prototypes */\n\n\n/* could just include png.h, but this macro is the only thing we need\n * (name and typedefs changed to local versions); note that side effects\n * only happen with alpha (which could easily be avoided with\n * \"ush acopy = (alpha);\") */\n\n#define alpha_composite(composite, fg, alpha, bg) {               \\\n    ush temp = ((ush)(fg)*(ush)(alpha) +                          \\\n                (ush)(bg)*(ush)(255 - (ush)(alpha)) + (ush)128);  \\\n    (composite) = (uch)((temp + (temp >> 8)) >> 8);               \\\n}\n\n\n#define INBUFSIZE 4096   /* with pseudo-timing on (1 sec delay/block), this\n                          *  block size corresponds roughly to a download\n                          *  speed 10% faster than theoretical 33.6K maximum\n                          *  (assuming 8 data bits, 1 stop bit and no other\n                          *  overhead) */\n\n/* local prototypes */\nstatic void rpng2_x_init (void);\nstatic int  rpng2_x_create_window (void);\nstatic int  rpng2_x_load_bg_image (void);\nstatic void rpng2_x_display_row (ulg row);\nstatic void rpng2_x_finish_display (void);\nstatic void rpng2_x_redisplay_image (ulg startcol, ulg startrow,\n                                     ulg width, ulg height);\n#ifdef FEATURE_LOOP\nstatic void rpng2_x_reload_bg_image (void);\nstatic int  is_number (char *p);\n#endif\nstatic void rpng2_x_cleanup (void);\nstatic int  rpng2_x_msb (ulg u32val);\n\n\nstatic char titlebar[1024], *window_name = titlebar;\nstatic char *appname = LONGNAME;\nstatic char *icon_name = PROGNAME;\nstatic char *res_name = RESNAME;\nstatic char *res_class = RESCLASS;\nstatic char *filename;\nstatic FILE *infile;\n\nstatic mainprog_info rpng2_info;\n\nstatic uch inbuf[INBUFSIZE];\nstatic int incount;\n\nstatic int pat = 6;        /* must be less than num_bgpat */\nstatic int bg_image = 0;\nstatic int bgscale, bgscale_default = 16;\nstatic ulg bg_rowbytes;\nstatic uch *bg_data;\n\nint pause_after_pass = FALSE;\nint demo_timing = FALSE;\nulg usleep_duration = 0L;\n\nstatic struct rgb_color {\n    uch r, g, b;\n} rgb[] = {\n    {  0,   0,   0},    /*  0:  black */\n    {255, 255, 255},    /*  1:  white */\n    {173, 132,  57},    /*  2:  tan */\n    { 64, 132,   0},    /*  3:  medium green */\n    {189, 117,   1},    /*  4:  gold */\n    {253, 249,   1},    /*  5:  yellow */\n    {  0,   0, 255},    /*  6:  blue */\n    {  0,   0, 120},    /*  7:  medium blue */\n    {255,   0, 255},    /*  8:  magenta */\n    { 64,   0,  64},    /*  9:  dark magenta */\n    {255,   0,   0},    /* 10:  red */\n    { 64,   0,   0},    /* 11:  dark red */\n    {255, 127,   0},    /* 12:  orange */\n    {192,  96,   0},    /* 13:  darker orange */\n    { 24,  60,   0},    /* 14:  dark green-yellow */\n    { 85, 125, 200},    /* 15:  ice blue */\n    {192, 192, 192}     /* 16:  Netscape/Mosaic gray */\n};\n/* not used for now, but should be for error-checking:\nstatic int num_rgb = sizeof(rgb) / sizeof(struct rgb_color);\n */\n\n/*\n    This whole struct is a fairly cheesy way to keep the number of\n    command-line options to a minimum.  The radial-waves background\n    type is a particularly poor fit to the integer elements of the\n    struct...but a few macros and a little fixed-point math will do\n    wonders for ya.\n\n    type bits:\n       F E D C B A 9 8 7 6 5 4 3 2 1 0\n                             | | | | |\n                             | | +-+-+-- 0 = sharp-edged checkerboard\n                             | |         1 = soft diamonds\n                             | |         2 = radial waves\n                             | |       3-7 = undefined\n                             | +-- gradient #2 inverted?\n                             +-- alternating columns inverted?\n */\nstatic struct background_pattern {\n    ush type;\n    int rgb1_max, rgb1_min;     /* or bg_freq, bg_gray */\n    int rgb2_max, rgb2_min;     /* or bg_bsat, bg_brot (both scaled by 10)*/\n} bg[] = {\n    {0,     1,1, 16,16},        /* checkered:  white vs. light gray (basic) */\n    {0+8,   2,0,  1,15},        /* checkered:  tan/black vs. white/ice blue */\n    {0+24,  2,0,  1,0},         /* checkered:  tan/black vs. white/black */\n    {0+8,   4,5,  0,2},         /* checkered:  gold/yellow vs. black/tan */\n    {0+8,   4,5,  0,6},         /* checkered:  gold/yellow vs. black/blue */\n    {0,     7,0,  8,9},         /* checkered:  deep blue/black vs. magenta */\n    {0+8,  13,0,  5,14},        /* checkered:  orange/black vs. yellow */\n    {0+8,  12,0, 10,11},        /* checkered:  orange/black vs. red */\n    {1,     7,0,  8,0},         /* diamonds:  deep blue/black vs. magenta */\n    {1,    12,0, 11,0},         /* diamonds:  orange vs. dark red */\n    {1,    10,0,  7,0},         /* diamonds:  red vs. medium blue */\n    {1,     4,0,  5,0},         /* diamonds:  gold vs. yellow */\n    {1,     3,0,  0,0},         /* diamonds:  medium green vs. black */\n    {2,    16, 100,  20,   0},  /* radial:  ~hard radial color-beams */\n    {2,    18, 100,  10,   2},  /* radial:  soft, curved radial color-beams */\n    {2,    16, 256, 100, 250},  /* radial:  very tight spiral */\n    {2, 10000, 256,  11,   0}   /* radial:  dipole-moire' (almost fractal) */\n};\nstatic int num_bgpat = sizeof(bg) / sizeof(struct background_pattern);\n\n\n/* X-specific variables */\nstatic char *displayname;\nstatic XImage *ximage;\nstatic Display *display;\nstatic int depth;\nstatic Visual *visual;\nstatic XVisualInfo *visual_list;\nstatic int RShift, GShift, BShift;\nstatic ulg RMask, GMask, BMask;\nstatic Window window;\nstatic GC gc;\nstatic Colormap colormap;\n\nstatic int have_nondefault_visual = FALSE;\nstatic int have_colormap = FALSE;\nstatic int have_window = FALSE;\nstatic int have_gc = FALSE;\n\n\n\n\nint main(int argc, char **argv)\n{\n#ifdef sgi\n    char tmpline[80];\n#endif\n    char *p, *bgstr = NULL;\n    int rc, alen, flen;\n    int error = 0;\n    int timing = FALSE;\n    int have_bg = FALSE;\n#ifdef FEATURE_LOOP\n    int loop = FALSE;\n    long loop_interval = -1;            /* seconds (100,000 max) */\n#endif\n    double LUT_exponent;                /* just the lookup table */\n    double CRT_exponent = 2.2;          /* just the monitor */\n    double default_display_exponent;    /* whole display system */\n    XEvent e;\n    KeySym k;\n\n\n    /* First initialize a few things, just to be sure--memset takes care of\n     * default background color (black), booleans (FALSE), pointers (NULL),\n     * etc. */\n\n    displayname = (char *)NULL;\n    filename = (char *)NULL;\n    memset(&rpng2_info, 0, sizeof(mainprog_info));\n\n\n    /* Set the default value for our display-system exponent, i.e., the\n     * product of the CRT exponent and the exponent corresponding to\n     * the frame-buffer's lookup table (LUT), if any.  This is not an\n     * exhaustive list of LUT values (e.g., OpenStep has a lot of weird\n     * ones), but it should cover 99% of the current possibilities. */\n\n#if defined(NeXT)\n    /* third-party utilities can modify the default LUT exponent */\n    LUT_exponent = 1.0 / 2.2;\n    /*\n    if (some_next_function_that_returns_gamma(&next_gamma))\n        LUT_exponent = 1.0 / next_gamma;\n     */\n#elif defined(sgi)\n    LUT_exponent = 1.0 / 1.7;\n    /* there doesn't seem to be any documented function to\n     * get the \"gamma\" value, so we do it the hard way */\n    infile = fopen(\"/etc/config/system.glGammaVal\", \"r\");\n    if (infile) {\n        double sgi_gamma;\n\n        fgets(tmpline, 80, infile);\n        fclose(infile);\n        sgi_gamma = atof(tmpline);\n        if (sgi_gamma > 0.0)\n            LUT_exponent = 1.0 / sgi_gamma;\n    }\n#elif defined(Macintosh)\n    LUT_exponent = 1.8 / 2.61;\n    /*\n    if (some_mac_function_that_returns_gamma(&mac_gamma))\n        LUT_exponent = mac_gamma / 2.61;\n     */\n#else\n    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */\n#endif\n\n    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */\n    default_display_exponent = LUT_exponent * CRT_exponent;\n\n\n    /* If the user has set the SCREEN_GAMMA environment variable as suggested\n     * (somewhat imprecisely) in the libpng documentation, use that; otherwise\n     * use the default value we just calculated.  Either way, the user may\n     * override this via a command-line option. */\n\n    if ((p = getenv(\"SCREEN_GAMMA\")) != NULL)\n        rpng2_info.display_exponent = atof(p);\n    else\n        rpng2_info.display_exponent = default_display_exponent;\n\n\n    /* Now parse the command line for options and the PNG filename. */\n\n    while (*++argv && !error) {\n        if (!strncmp(*argv, \"-display\", 2)) {\n            if (!*++argv)\n                ++error;\n            else\n                displayname = *argv;\n        } else if (!strncmp(*argv, \"-gamma\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                rpng2_info.display_exponent = atof(*argv);\n                if (rpng2_info.display_exponent <= 0.0)\n                    ++error;\n            }\n        } else if (!strncmp(*argv, \"-bgcolor\", 4)) {\n            if (!*++argv)\n                ++error;\n            else {\n                bgstr = *argv;\n                if (strlen(bgstr) != 7 || bgstr[0] != '#')\n                    ++error;\n                else {\n                    have_bg = TRUE;\n                    bg_image = FALSE;\n                }\n            }\n        } else if (!strncmp(*argv, \"-bgpat\", 4)) {\n            if (!*++argv)\n                ++error;\n            else {\n                pat = atoi(*argv);\n                if (pat >= 0 && pat < num_bgpat) {\n                    bg_image = TRUE;\n                    have_bg = FALSE;\n                } else\n                    ++error;\n            }\n        } else if (!strncmp(*argv, \"-usleep\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                usleep_duration = (ulg)atol(*argv);\n                demo_timing = TRUE;\n            }\n        } else if (!strncmp(*argv, \"-pause\", 2)) {\n            pause_after_pass = TRUE;\n        } else if (!strncmp(*argv, \"-timing\", 2)) {\n            timing = TRUE;\n#ifdef FEATURE_LOOP\n        } else if (!strncmp(*argv, \"-loop\", 2)) {\n            loop = TRUE;\n            if (!argv[1] || !is_number(argv[1]))\n                loop_interval = 2;\n            else {\n                ++argv;\n                loop_interval = atol(*argv);\n                if (loop_interval < 0)\n                    loop_interval = 2;\n                else if (loop_interval > 100000)   /* bit more than one day */\n                    loop_interval = 100000;\n            }\n#endif\n        } else {\n            if (**argv != '-') {\n                filename = *argv;\n                if (argv[1])   /* shouldn't be any more args after filename */\n                    ++error;\n            } else\n                ++error;   /* not expecting any other options */\n        }\n    }\n\n    if (!filename)\n        ++error;\n\n\n    /* print usage screen if any errors up to this point */\n\n    if (error) {\n        fprintf(stderr, \"\\n%s %s:  %s\\n\\n\", PROGNAME, VERSION, appname);\n        readpng2_version_info();\n        fprintf(stderr, \"\\n\"\n          \"Usage:   \");\n        fprintf(stderr,\n          \"%s [-display xdpy] [-gamma exp] [-bgcolor bg | -bgpat pat]\\n\"\n          \"        %*s [-usleep dur | -timing] [-pause]\\n\",\n          PROGNAME, (int)strlen(PROGNAME), \" \");\n        fprintf(stderr,\n#ifdef FEATURE_LOOP\n          \"        [-loop [sec]]\"\n#endif\n          \" file.png\\n\\n\");\n        fprintf(stderr,\n          \"    xdpy\\tname of the target X display (e.g., ``hostname:0'')\\n\"\n          \"    exp \\ttransfer-function exponent (``gamma'') of the display\\n\"\n          \"\\t\\t  system in floating-point format (e.g., ``%.1f''); equal\\n\"\n          \"\\t\\t  to the product of the lookup-table exponent (varies)\\n\",\n          default_display_exponent);\n        fprintf(stderr,\n          \"\\t\\t  and the CRT exponent (usually 2.2); must be positive\\n\"\n          \"    bg  \\tdesired background color in 7-character hex RGB format\\n\"\n          \"\\t\\t  (e.g., ``#ff7700'' for orange:  same as HTML colors);\\n\"\n          \"\\t\\t  used with transparent images; overrides -bgpat\\n\"\n          \"    pat \\tdesired background pattern number (0-%d); used with\\n\"\n          \"\\t\\t  transparent images; overrides -bgcolor\\n\",\n          num_bgpat-1);\n#ifdef FEATURE_LOOP\n        fprintf(stderr,\n          \"    -loop\\tloops through background images after initial display\\n\"\n          \"\\t\\t  is complete (depends on -bgpat)\\n\"\n          \"    sec \\tseconds to display each background image (default = 2)\\n\");\n#endif\n        fprintf(stderr,\n          \"    dur \\tduration in microseconds to wait after displaying each\\n\"\n          \"\\t\\t  row (for demo purposes)\\n\"\n          \"    -timing\\tenables delay for every block read, to simulate modem\\n\"\n          \"\\t\\t  download of image (~36 Kbps)\\n\"\n          \"    -pause\\tpauses after displaying each pass until mouse clicked\\n\"\n          \"\\nPress Q, Esc or mouse button 1 (within image window, after image\\n\"\n          \"is displayed) to quit.\\n\");\n        exit(1);\n    }\n\n    if (!(infile = fopen(filename, \"rb\"))) {\n        fprintf(stderr, PROGNAME \":  can't open PNG file [%s]\\n\", filename);\n        ++error;\n    } else {\n        incount = fread(inbuf, 1, INBUFSIZE, infile);\n        if (incount < 8 || !readpng2_check_sig(inbuf, 8)) {\n            fprintf(stderr, PROGNAME\n              \":  [%s] is not a PNG file: incorrect signature\\n\",\n              filename);\n            ++error;\n        } else if ((rc = readpng2_init(&rpng2_info)) != 0) {\n            switch (rc) {\n                case 2:\n                    fprintf(stderr, PROGNAME\n                      \":  [%s] has bad IHDR (libpng longjmp)\\n\", filename);\n                    break;\n                case 4:\n                    fprintf(stderr, PROGNAME \":  insufficient memory\\n\");\n                    break;\n                default:\n                    fprintf(stderr, PROGNAME\n                      \":  unknown readpng2_init() error\\n\");\n                    break;\n            }\n            ++error;\n        } else {\n            Trace((stderr, \"about to call XOpenDisplay()\\n\"))\n            display = XOpenDisplay(displayname);\n            if (!display) {\n                readpng2_cleanup(&rpng2_info);\n                fprintf(stderr, PROGNAME \":  can't open X display [%s]\\n\",\n                  displayname? displayname : \"default\");\n                ++error;\n            }\n        }\n        if (error)\n            fclose(infile);\n    }\n\n\n    if (error) {\n        fprintf(stderr, PROGNAME \":  aborting.\\n\");\n        exit(2);\n    }\n\n\n    /* set the title-bar string, but make sure buffer doesn't overflow */\n\n    alen = strlen(appname);\n    flen = strlen(filename);\n    if (alen + flen + 3 > 1023)\n        sprintf(titlebar, \"%s:  ...%s\", appname, filename+(alen+flen+6-1023));\n    else\n        sprintf(titlebar, \"%s:  %s\", appname, filename);\n\n\n    /* set some final rpng2_info variables before entering main data loop */\n\n    if (have_bg) {\n        unsigned r, g, b;   /* this approach quiets compiler warnings */\n\n        sscanf(bgstr+1, \"%2x%2x%2x\", &r, &g, &b);\n        rpng2_info.bg_red   = (uch)r;\n        rpng2_info.bg_green = (uch)g;\n        rpng2_info.bg_blue  = (uch)b;\n    } else\n        rpng2_info.need_bgcolor = TRUE;\n\n    rpng2_info.state = kPreInit;\n    rpng2_info.mainprog_init = rpng2_x_init;\n    rpng2_info.mainprog_display_row = rpng2_x_display_row;\n    rpng2_info.mainprog_finish_display = rpng2_x_finish_display;\n\n\n    /* OK, this is the fun part:  call readpng2_decode_data() at the start of\n     * the loop to deal with our first buffer of data (read in above to verify\n     * that the file is a PNG image), then loop through the file and continue\n     * calling the same routine to handle each chunk of data.  It in turn\n     * passes the data to libpng, which will invoke one or more of our call-\n     * backs as decoded data become available.  We optionally call sleep() for\n     * one second per iteration to simulate downloading the image via an analog\n     * modem. */\n\n    for (;;) {\n        Trace((stderr, \"about to call readpng2_decode_data()\\n\"))\n        if (readpng2_decode_data(&rpng2_info, inbuf, incount))\n            ++error;\n        Trace((stderr, \"done with readpng2_decode_data()\\n\"))\n\n        if (error || incount != INBUFSIZE || rpng2_info.state == kDone) {\n            if (rpng2_info.state == kDone) {\n                Trace((stderr, \"done decoding PNG image\\n\"))\n            } else if (ferror(infile)) {\n                fprintf(stderr, PROGNAME\n                  \":  error while reading PNG image file\\n\");\n                exit(3);\n            } else if (feof(infile)) {\n                fprintf(stderr, PROGNAME \":  end of file reached \"\n                  \"(unexpectedly) while reading PNG image file\\n\");\n                exit(3);\n            } else /* if (error) */ {\n                /* will print error message below */\n            }\n            break;\n        }\n\n        if (timing)\n            sleep(1);\n\n        incount = fread(inbuf, 1, INBUFSIZE, infile);\n    }\n\n\n    /* clean up PNG stuff and report any decoding errors */\n\n    fclose(infile);\n    Trace((stderr, \"about to call readpng2_cleanup()\\n\"))\n    readpng2_cleanup(&rpng2_info);\n\n    if (error) {\n        fprintf(stderr, PROGNAME \":  libpng error while decoding PNG image\\n\");\n        exit(3);\n    }\n\n\n#ifdef FEATURE_LOOP\n\n    if (loop && bg_image) {\n        Trace((stderr, \"entering -loop loop (FEATURE_LOOP)\\n\"))\n        for (;;) {\n            int i, use_sleep;\n            struct timeval now, then;\n\n            /* get current time and add loop_interval to get target time */\n            if (gettimeofday(&then, NULL) == 0) {\n                then.tv_sec += loop_interval;\n                use_sleep = FALSE;\n            } else\n                use_sleep = TRUE;\n\n            /* do quick check for a quit event but don't wait for it */\n            /* GRR BUG:  should also check for Expose events and redraw... */\n            if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask, &e))\n                if (QUIT(e,k))\n                    break;\n\n            /* generate next background image */\n            if (++pat >= num_bgpat)\n                pat = 0;\n            rpng2_x_reload_bg_image();\n\n            /* wait for timeout, using whatever means are available */\n            if (use_sleep || gettimeofday(&now, NULL) != 0) {\n                for (i = loop_interval;  i > 0;  --i) {\n                    sleep(1);\n                    /* GRR BUG:  also need to check for Expose (and redraw!) */\n                    if (XCheckMaskEvent(display, KeyPressMask | ButtonPressMask,\n                        &e) && QUIT(e,k))\n                        break;\n                }\n            } else {\n                /* Y2038 BUG! */\n                if (now.tv_sec < then.tv_sec ||\n                    (now.tv_sec == then.tv_sec && now.tv_usec < then.tv_usec))\n                {\n                    int quit = FALSE;\n                    long seconds_to_go = then.tv_sec - now.tv_sec;\n                    long usleep_usec;\n\n                    /* basically chew up most of remaining loop-interval with\n                     *  calls to sleep(1) interleaved with checks for quit\n                     *  events, but also recalc time-to-go periodically; when\n                     *  done, clean up any remaining time with usleep() call\n                     *  (could also use SIGALRM, but signals are a pain...) */\n                    while (seconds_to_go-- > 1) {\n                        int seconds_done = 0;\n\n                        for (i = seconds_to_go;  i > 0 && !quit;  --i) {\n                            sleep(1);\n                            /* GRR BUG:  need to check for Expose and redraw */\n                            if (XCheckMaskEvent(display, KeyPressMask |\n                                ButtonPressMask, &e) && QUIT(e,k))\n                                quit = TRUE;\n                            if (++seconds_done > 1000)\n                                break;   /* time to redo seconds_to_go meas. */\n                        }\n                        if (quit)\n                            break;\n\n                        /* OK, more than 1000 seconds since last check:\n                         *  correct the time-to-go measurement for drift */\n                        if (gettimeofday(&now, NULL) == 0) {\n                            if (now.tv_sec >= then.tv_sec)\n                                break;\n                            seconds_to_go = then.tv_sec - now.tv_sec;\n                        } else\n                            ++seconds_to_go;  /* restore what we subtracted */\n                    }\n                    if (quit)\n                        break;   /* breaks outer do-loop, skips redisplay */\n\n                    /* since difference between \"now\" and \"then\" is already\n                     *  eaten up to within a couple of seconds, don't need to\n                     *  worry about overflow--but might have overshot (neg.) */\n                    if (gettimeofday(&now, NULL) == 0) {\n                        usleep_usec = 1000000L*(then.tv_sec - now.tv_sec) +\n                          then.tv_usec - now.tv_usec;\n                        if (usleep_usec > 0)\n                            usleep((ulg)usleep_usec);\n                    }\n                }\n            }\n\n            /* composite image against new background and display (note that\n             *  we do not take into account the time spent doing this...) */\n            rpng2_x_redisplay_image (0, 0, rpng2_info.width, rpng2_info.height);\n        }\n\n    } else /* FALL THROUGH and do the normal thing */\n\n#endif /* FEATURE_LOOP */\n\n    /* wait for the user to tell us when to quit */\n\n    if (rpng2_info.state >= kWindowInit) {\n        Trace((stderr, \"entering final wait-for-quit-event loop\\n\"))\n        do {\n            XNextEvent(display, &e);\n            if (e.type == Expose) {\n                XExposeEvent *ex = (XExposeEvent *)&e;\n                rpng2_x_redisplay_image (ex->x, ex->y, ex->width, ex->height);\n            }\n        } while (!QUIT(e,k));\n    } else {\n        fprintf(stderr, PROGNAME \":  init callback never called:  probable \"\n          \"libpng error while decoding PNG metadata\\n\");\n        exit(4);\n    }\n\n\n    /* we're done:  clean up all image and X resources and go away */\n\n    Trace((stderr, \"about to call rpng2_x_cleanup()\\n\"))\n    rpng2_x_cleanup();\n\n    (void)argc; /* Unused */\n\n    return 0;\n}\n\n\n\n\n\n/* this function is called by readpng2_info_callback() in readpng2.c, which\n * in turn is called by libpng after all of the pre-IDAT chunks have been\n * read and processed--i.e., we now have enough info to finish initializing */\n\nstatic void rpng2_x_init(void)\n{\n    ulg i;\n    ulg rowbytes = rpng2_info.rowbytes;\n\n    Trace((stderr, \"beginning rpng2_x_init()\\n\"))\n    Trace((stderr, \"  rowbytes = %d\\n\", rpng2_info.rowbytes))\n    Trace((stderr, \"  width  = %ld\\n\", rpng2_info.width))\n    Trace((stderr, \"  height = %ld\\n\", rpng2_info.height))\n\n    rpng2_info.image_data = (uch *)malloc(rowbytes * rpng2_info.height);\n    if (!rpng2_info.image_data) {\n        readpng2_cleanup(&rpng2_info);\n        return;\n    }\n\n    rpng2_info.row_pointers = (uch **)malloc(rpng2_info.height * sizeof(uch *));\n    if (!rpng2_info.row_pointers) {\n        free(rpng2_info.image_data);\n        rpng2_info.image_data = NULL;\n        readpng2_cleanup(&rpng2_info);\n        return;\n    }\n\n    for (i = 0;  i < rpng2_info.height;  ++i)\n        rpng2_info.row_pointers[i] = rpng2_info.image_data + i*rowbytes;\n\n\n    /* do the basic X initialization stuff, make the window, and fill it with\n     * the user-specified, file-specified or default background color or\n     * pattern */\n\n    if (rpng2_x_create_window()) {\n\n        /* GRR TEMPORARY HACK:  this is fundamentally no different from cases\n         * above; libpng should call our error handler to longjmp() back to us\n         * when png_ptr goes away.  If we/it segfault instead, seems like a\n         * libpng bug... */\n\n        /* we're here via libpng callback, so if window fails, clean and bail */\n        readpng2_cleanup(&rpng2_info);\n        rpng2_x_cleanup();\n        exit(2);\n    }\n\n    rpng2_info.state = kWindowInit;\n}\n\n\n\n\n\nstatic int rpng2_x_create_window(void)\n{\n    ulg bg_red   = rpng2_info.bg_red;\n    ulg bg_green = rpng2_info.bg_green;\n    ulg bg_blue  = rpng2_info.bg_blue;\n    ulg bg_pixel = 0L;\n    ulg attrmask;\n    int need_colormap = FALSE;\n    int screen, pad;\n    uch *xdata;\n    Window root;\n    XEvent e;\n    XGCValues gcvalues;\n    XSetWindowAttributes attr;\n    XTextProperty windowName, *pWindowName = &windowName;\n    XTextProperty iconName, *pIconName = &iconName;\n    XVisualInfo visual_info;\n    XSizeHints *size_hints;\n    XWMHints *wm_hints;\n    XClassHint *class_hints;\n\n\n    Trace((stderr, \"beginning rpng2_x_create_window()\\n\"))\n\n    screen = DefaultScreen(display);\n    depth = DisplayPlanes(display, screen);\n    root = RootWindow(display, screen);\n\n#ifdef DEBUG\n    XSynchronize(display, True);\n#endif\n\n    if (depth != 16 && depth != 24 && depth != 32) {\n        int visuals_matched = 0;\n\n        Trace((stderr, \"default depth is %d:  checking other visuals\\n\",\n          depth))\n\n        /* 24-bit first */\n        visual_info.screen = screen;\n        visual_info.depth = 24;\n        visual_list = XGetVisualInfo(display,\n          VisualScreenMask | VisualDepthMask, &visual_info, &visuals_matched);\n        if (visuals_matched == 0) {\n/* GRR:  add 15-, 16- and 32-bit TrueColor visuals (also DirectColor?) */\n            fprintf(stderr, \"default screen depth %d not supported, and no\"\n              \" 24-bit visuals found\\n\", depth);\n            return 2;\n        }\n        Trace((stderr, \"XGetVisualInfo() returned %d 24-bit visuals\\n\",\n          visuals_matched))\n        visual = visual_list[0].visual;\n        depth = visual_list[0].depth;\n/*\n        colormap_size = visual_list[0].colormap_size;\n        visual_class = visual->class;\n        visualID = XVisualIDFromVisual(visual);\n */\n        have_nondefault_visual = TRUE;\n        need_colormap = TRUE;\n    } else {\n        XMatchVisualInfo(display, screen, depth, TrueColor, &visual_info);\n        visual = visual_info.visual;\n    }\n\n    RMask = visual->red_mask;\n    GMask = visual->green_mask;\n    BMask = visual->blue_mask;\n\n/* GRR:  add/check 8-bit support */\n    if (depth == 8 || need_colormap) {\n        colormap = XCreateColormap(display, root, visual, AllocNone);\n        if (!colormap) {\n            fprintf(stderr, \"XCreateColormap() failed\\n\");\n            return 2;\n        }\n        have_colormap = TRUE;\n        if (depth == 8)\n            bg_image = FALSE;   /* gradient just wastes palette entries */\n    }\n    if (depth == 15 || depth == 16) {\n        RShift = 15 - rpng2_x_msb(RMask);    /* these are right-shifts */\n        GShift = 15 - rpng2_x_msb(GMask);\n        BShift = 15 - rpng2_x_msb(BMask);\n    } else if (depth > 16) {\n        RShift = rpng2_x_msb(RMask) - 7;     /* these are left-shifts */\n        GShift = rpng2_x_msb(GMask) - 7;\n        BShift = rpng2_x_msb(BMask) - 7;\n    }\n    if (depth >= 15 && (RShift < 0 || GShift < 0 || BShift < 0)) {\n        fprintf(stderr, \"rpng2 internal logic error:  negative X shift(s)!\\n\");\n        return 2;\n    }\n\n/*---------------------------------------------------------------------------\n    Finally, create the window.\n  ---------------------------------------------------------------------------*/\n\n    attr.backing_store = Always;\n    attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask;\n    attrmask = CWBackingStore | CWEventMask;\n    if (have_nondefault_visual) {\n        attr.colormap = colormap;\n        attr.background_pixel = 0;\n        attr.border_pixel = 1;\n        attrmask |= CWColormap | CWBackPixel | CWBorderPixel;\n    }\n\n    window = XCreateWindow(display, root, 0, 0, rpng2_info.width,\n      rpng2_info.height, 0, depth, InputOutput, visual, attrmask, &attr);\n\n    if (window == None) {\n        fprintf(stderr, \"XCreateWindow() failed\\n\");\n        return 2;\n    } else\n        have_window = TRUE;\n\n    if (depth == 8)\n        XSetWindowColormap(display, window, colormap);\n\n    if (!XStringListToTextProperty(&window_name, 1, pWindowName))\n        pWindowName = NULL;\n    if (!XStringListToTextProperty(&icon_name, 1, pIconName))\n        pIconName = NULL;\n\n    /* OK if either hints allocation fails; XSetWMProperties() allows NULLs */\n\n    if ((size_hints = XAllocSizeHints()) != NULL) {\n        /* window will not be resizable */\n        size_hints->flags = PMinSize | PMaxSize;\n        size_hints->min_width = size_hints->max_width = (int)rpng2_info.width;\n        size_hints->min_height = size_hints->max_height =\n          (int)rpng2_info.height;\n    }\n\n    if ((wm_hints = XAllocWMHints()) != NULL) {\n        wm_hints->initial_state = NormalState;\n        wm_hints->input = True;\n     /* wm_hints->icon_pixmap = icon_pixmap; */\n        wm_hints->flags = StateHint | InputHint  /* | IconPixmapHint */ ;\n    }\n\n    if ((class_hints = XAllocClassHint()) != NULL) {\n        class_hints->res_name = res_name;\n        class_hints->res_class = res_class;\n    }\n\n    XSetWMProperties(display, window, pWindowName, pIconName, NULL, 0,\n      size_hints, wm_hints, class_hints);\n\n    /* various properties and hints no longer needed; free memory */\n    if (pWindowName)\n       XFree(pWindowName->value);\n    if (pIconName)\n       XFree(pIconName->value);\n    if (size_hints)\n        XFree(size_hints);\n    if (wm_hints)\n       XFree(wm_hints);\n    if (class_hints)\n       XFree(class_hints);\n\n    XMapWindow(display, window);\n\n    gc = XCreateGC(display, window, 0, &gcvalues);\n    have_gc = TRUE;\n\n/*---------------------------------------------------------------------------\n    Allocate memory for the X- and display-specific version of the image.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        xdata = (uch *)malloc(4*rpng2_info.width*rpng2_info.height);\n        pad = 32;\n    } else if (depth == 16) {\n        xdata = (uch *)malloc(2*rpng2_info.width*rpng2_info.height);\n        pad = 16;\n    } else /* depth == 8 */ {\n        xdata = (uch *)malloc(rpng2_info.width*rpng2_info.height);\n        pad = 8;\n    }\n\n    if (!xdata) {\n        fprintf(stderr, PROGNAME \":  unable to allocate image memory\\n\");\n        return 4;\n    }\n\n    ximage = XCreateImage(display, visual, depth, ZPixmap, 0,\n      (char *)xdata, rpng2_info.width, rpng2_info.height, pad, 0);\n\n    if (!ximage) {\n        fprintf(stderr, PROGNAME \":  XCreateImage() failed\\n\");\n        free(xdata);\n        return 3;\n    }\n\n    /* to avoid testing the byte order every pixel (or doubling the size of\n     * the drawing routine with a giant if-test), we arbitrarily set the byte\n     * order to MSBFirst and let Xlib worry about inverting things on little-\n     * endian machines (e.g., Linux/x86, old VAXen, etc.)--this is not the\n     * most efficient approach (the giant if-test would be better), but in\n     * the interest of clarity, we'll take the easy way out... */\n\n    ximage->byte_order = MSBFirst;\n\n/*---------------------------------------------------------------------------\n    Fill window with the specified background color (default is black) or\n    faked \"background image\" (but latter is disabled if 8-bit; gradients\n    just waste palette entries).\n  ---------------------------------------------------------------------------*/\n\n    if (bg_image)\n        rpng2_x_load_bg_image();    /* resets bg_image if fails */\n\n    if (!bg_image) {\n        if (depth == 24 || depth == 32) {\n            bg_pixel = (bg_red   << RShift) |\n                       (bg_green << GShift) |\n                       (bg_blue  << BShift);\n        } else if (depth == 16) {\n            bg_pixel = (((bg_red   << 8) >> RShift) & RMask) |\n                       (((bg_green << 8) >> GShift) & GMask) |\n                       (((bg_blue  << 8) >> BShift) & BMask);\n        } else /* depth == 8 */ {\n\n            /* GRR:  add 8-bit support */\n\n        }\n        XSetForeground(display, gc, bg_pixel);\n        XFillRectangle(display, window, gc, 0, 0, rpng2_info.width,\n          rpng2_info.height);\n    }\n\n/*---------------------------------------------------------------------------\n    Wait for first Expose event to do any drawing, then flush and return.\n  ---------------------------------------------------------------------------*/\n\n    do\n        XNextEvent(display, &e);\n    while (e.type != Expose || e.xexpose.count);\n\n    XFlush(display);\n\n    return 0;\n\n} /* end function rpng2_x_create_window() */\n\n\n\n\n\nstatic int rpng2_x_load_bg_image(void)\n{\n    uch *src;\n    char *dest;\n    uch r1, r2, g1, g2, b1, b2;\n    uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;\n    int k, hmax, max;\n    int xidx, yidx, yidx_max;\n    int even_odd_vert, even_odd_horiz, even_odd;\n    int invert_gradient2 = (bg[pat].type & 0x08);\n    int invert_column;\n    int ximage_rowbytes = ximage->bytes_per_line;\n    ulg i, row;\n    ulg pixel;\n\n/*---------------------------------------------------------------------------\n    Allocate buffer for fake background image to be used with transparent\n    images; if this fails, revert to plain background color.\n  ---------------------------------------------------------------------------*/\n\n    bg_rowbytes = 3 * rpng2_info.width;\n    bg_data = (uch *)malloc(bg_rowbytes * rpng2_info.height);\n    if (!bg_data) {\n        fprintf(stderr, PROGNAME\n          \":  unable to allocate memory for background image\\n\");\n        bg_image = 0;\n        return 1;\n    }\n\n    bgscale = (pat == 0)? 8 : bgscale_default;\n    yidx_max = bgscale - 1;\n\n/*---------------------------------------------------------------------------\n    Vertical gradients (ramps) in NxN squares, alternating direction and\n    colors (N == bgscale).\n  ---------------------------------------------------------------------------*/\n\n    if ((bg[pat].type & 0x07) == 0) {\n        uch r1_min  = rgb[bg[pat].rgb1_min].r;\n        uch g1_min  = rgb[bg[pat].rgb1_min].g;\n        uch b1_min  = rgb[bg[pat].rgb1_min].b;\n        uch r2_min  = rgb[bg[pat].rgb2_min].r;\n        uch g2_min  = rgb[bg[pat].rgb2_min].g;\n        uch b2_min  = rgb[bg[pat].rgb2_min].b;\n        int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;\n        int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;\n        int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;\n        int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;\n        int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;\n        int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = (int)(row % bgscale);\n            even_odd_vert = (int)((row / bgscale) & 1);\n\n            r1 = r1_min + (r1_diff * yidx) / yidx_max;\n            g1 = g1_min + (g1_diff * yidx) / yidx_max;\n            b1 = b1_min + (b1_diff * yidx) / yidx_max;\n            r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;\n            g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;\n            b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;\n\n            r2 = r2_min + (r2_diff * yidx) / yidx_max;\n            g2 = g2_min + (g2_diff * yidx) / yidx_max;\n            b2 = b2_min + (b2_diff * yidx) / yidx_max;\n            r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;\n            g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;\n            b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;\n\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                even_odd_horiz = (int)((i / bgscale) & 1);\n                even_odd = even_odd_vert ^ even_odd_horiz;\n                invert_column =\n                  (even_odd_horiz && (bg[pat].type & 0x10));\n                if (even_odd == 0) {        /* gradient #1 */\n                    if (invert_column) {\n                        *dest++ = r1_inv;\n                        *dest++ = g1_inv;\n                        *dest++ = b1_inv;\n                    } else {\n                        *dest++ = r1;\n                        *dest++ = g1;\n                        *dest++ = b1;\n                    }\n                } else {                    /* gradient #2 */\n                    if ((invert_column && invert_gradient2) ||\n                        (!invert_column && !invert_gradient2))\n                    {\n                        *dest++ = r2;       /* not inverted or */\n                        *dest++ = g2;       /*  doubly inverted */\n                        *dest++ = b2;\n                    } else {\n                        *dest++ = r2_inv;\n                        *dest++ = g2_inv;   /* singly inverted */\n                        *dest++ = b2_inv;\n                    }\n                }\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Soft gradient-diamonds with scale = bgscale.  Code contributed by Adam\n    M. Costello.\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 1) {\n\n        hmax = (bgscale-1)/2;   /* half the max weight of a color */\n        max = 2*hmax;           /* the max weight of a color */\n\n        r1 = rgb[bg[pat].rgb1_max].r;\n        g1 = rgb[bg[pat].rgb1_max].g;\n        b1 = rgb[bg[pat].rgb1_max].b;\n        r2 = rgb[bg[pat].rgb2_max].r;\n        g2 = rgb[bg[pat].rgb2_max].g;\n        b2 = rgb[bg[pat].rgb2_max].b;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = (int)(row % bgscale);\n            if (yidx > hmax)\n                yidx = bgscale-1 - yidx;\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                xidx = (int)(i % bgscale);\n                if (xidx > hmax)\n                    xidx = bgscale-1 - xidx;\n                k = xidx + yidx;\n                *dest++ = (k*r1 + (max-k)*r2) / max;\n                *dest++ = (k*g1 + (max-k)*g2) / max;\n                *dest++ = (k*b1 + (max-k)*b2) / max;\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Radial \"starburst\" with azimuthal sinusoids; [eventually number of sinu-\n    soids will equal bgscale?].  This one is slow but very cool.  Code con-\n    tributed by Pieter S. van der Meulen (originally in Smalltalk).\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 2) {\n        uch ch;\n        int ii, x, y, hw, hh, grayspot;\n        double freq, rotate, saturate, gray, intensity;\n        double angle=0.0, aoffset=0.0, maxDist, dist;\n        double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;\n\n        fprintf(stderr, \"%s:  computing radial background...\",\n          PROGNAME);\n        fflush(stderr);\n\n        hh = (int)(rpng2_info.height / 2);\n        hw = (int)(rpng2_info.width / 2);\n\n        /* variables for radial waves:\n         *   aoffset:  number of degrees to rotate hue [CURRENTLY NOT USED]\n         *   freq:  number of color beams originating from the center\n         *   grayspot:  size of the graying center area (anti-alias)\n         *   rotate:  rotation of the beams as a function of radius\n         *   saturate:  saturation of beams' shape azimuthally\n         */\n        angle = CLIP(angle, 0.0, 360.0);\n        grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));\n        freq = MAX((double)bg[pat].bg_freq, 0.0);\n        saturate = (double)bg[pat].bg_bsat * 0.1;\n        rotate = (double)bg[pat].bg_brot * 0.1;\n        gray = 0.0;\n        intensity = 0.0;\n        maxDist = (double)((hw*hw) + (hh*hh));\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            y = (int)(row - hh);\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                x = (int)(i - hw);\n                angle = (x == 0)? PI_2 : atan((double)y / (double)x);\n                gray = (double)MAX(ABS(y), ABS(x)) / grayspot;\n                gray = MIN(1.0, gray);\n                dist = (double)((x*x) + (y*y)) / maxDist;\n                intensity = cos((angle+(rotate*dist*PI)) * freq) *\n                  gray * saturate;\n                intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;\n                hue = (angle + PI) * INV_PI_360 + aoffset;\n                s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));\n                s = MIN(MAX(s,0.0), 1.0);\n                v = MIN(MAX(intensity,0.0), 1.0);\n\n                if (s == 0.0) {\n                    ch = (uch)(v * 255.0);\n                    *dest++ = ch;\n                    *dest++ = ch;\n                    *dest++ = ch;\n                } else {\n                    if ((hue < 0.0) || (hue >= 360.0))\n                        hue -= (((int)(hue / 360.0)) * 360.0);\n                    hue /= 60.0;\n                    ii = (int)hue;\n                    f = hue - (double)ii;\n                    p = (1.0 - s) * v;\n                    q = (1.0 - (s * f)) * v;\n                    t = (1.0 - (s * (1.0 - f))) * v;\n                    if      (ii == 0) { red = v; green = t; blue = p; }\n                    else if (ii == 1) { red = q; green = v; blue = p; }\n                    else if (ii == 2) { red = p; green = v; blue = t; }\n                    else if (ii == 3) { red = p; green = q; blue = v; }\n                    else if (ii == 4) { red = t; green = p; blue = v; }\n                    else if (ii == 5) { red = v; green = p; blue = q; }\n                    *dest++ = (uch)(red * 255.0);\n                    *dest++ = (uch)(green * 255.0);\n                    *dest++ = (uch)(blue * 255.0);\n                }\n            }\n        }\n        fprintf(stderr, \"done.\\n\");\n        fflush(stderr);\n    }\n\n/*---------------------------------------------------------------------------\n    Blast background image to display buffer before beginning PNG decode.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        ulg red, green, blue;\n        int bpp = ximage->bits_per_pixel;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            src = bg_data + row*bg_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            if (bpp == 32) {    /* slightly optimized version */\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    red   = *src++;\n                    green = *src++;\n                    blue  = *src++;\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            } else {\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    red   = *src++;\n                    green = *src++;\n                    blue  = *src++;\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    /* GRR BUG?  this assumes bpp == 24 & bits are packed low */\n                    /*           (probably need to use RShift, RMask, etc.) */\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n        }\n\n    } else if (depth == 16) {\n        ush red, green, blue;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            src = bg_data + row*bg_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                red   = ((ush)(*src) << 8);  ++src;\n                green = ((ush)(*src) << 8);  ++src;\n                blue  = ((ush)(*src) << 8);  ++src;\n                pixel = ((red   >> RShift) & RMask) |\n                        ((green >> GShift) & GMask) |\n                        ((blue  >> BShift) & BMask);\n                /* recall that we set ximage->byte_order = MSBFirst above */\n                *dest++ = (char)((pixel >>  8) & 0xff);\n                *dest++ = (char)( pixel        & 0xff);\n            }\n        }\n\n    } else /* depth == 8 */ {\n\n        /* GRR:  add 8-bit support */\n\n    }\n\n    XPutImage(display, window, gc, ximage, 0, 0, 0, 0, rpng2_info.width,\n      rpng2_info.height);\n\n    return 0;\n\n} /* end function rpng2_x_load_bg_image() */\n\n\n\n\n\nstatic void rpng2_x_display_row(ulg row)\n{\n    uch bg_red   = rpng2_info.bg_red;\n    uch bg_green = rpng2_info.bg_green;\n    uch bg_blue  = rpng2_info.bg_blue;\n    uch *src, *src2=NULL;\n    char *dest;\n    uch r, g, b, a;\n    int ximage_rowbytes = ximage->bytes_per_line;\n    ulg i, pixel;\n    static int rows=0, prevpass=(-1);\n    static ulg firstrow;\n\n/*---------------------------------------------------------------------------\n    rows and firstrow simply track how many rows (and which ones) have not\n    yet been displayed; alternatively, we could call XPutImage() for every\n    row and not bother with the records-keeping.\n  ---------------------------------------------------------------------------*/\n\n    Trace((stderr, \"beginning rpng2_x_display_row()\\n\"))\n\n    if (rpng2_info.pass != prevpass) {\n        if (pause_after_pass && rpng2_info.pass > 0) {\n            XEvent e;\n            KeySym k;\n\n            fprintf(stderr,\n              \"%s:  end of pass %d of 7; click in image window to continue\\n\",\n              PROGNAME, prevpass + 1);\n            do\n                XNextEvent(display, &e);\n            while (!QUIT(e,k));\n        }\n        fprintf(stderr, \"%s:  pass %d of 7\\r\", PROGNAME, rpng2_info.pass + 1);\n        fflush(stderr);\n        prevpass = rpng2_info.pass;\n    }\n\n    if (rows == 0)\n        firstrow = row;   /* first row that is not yet displayed */\n\n    ++rows;   /* count of rows received but not yet displayed */\n\n/*---------------------------------------------------------------------------\n    Aside from the use of the rpng2_info struct, the lack of an outer loop\n    (over rows) and moving the XPutImage() call outside the \"if (depth)\"\n    tests, this routine is identical to rpng_x_display_image() in the non-\n    progressive version of the program.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        ulg red, green, blue;\n        int bpp = ximage->bits_per_pixel;\n\n        src = rpng2_info.image_data + row*rpng2_info.rowbytes;\n        if (bg_image)\n            src2 = bg_data + row*bg_rowbytes;\n        dest = ximage->data + row*ximage_rowbytes;\n        if (rpng2_info.channels == 3) {\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                red   = *src++;\n                green = *src++;\n                blue  = *src++;\n                pixel = (red   << RShift) |\n                        (green << GShift) |\n                        (blue  << BShift);\n                /* recall that we set ximage->byte_order = MSBFirst above */\n                if (bpp == 32) {\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                } else {\n                    /* GRR BUG?  this assumes bpp == 24 & bits are packed low */\n                    /*           (probably need to use RShift, RMask, etc.) */\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n        } else /* if (rpng2_info.channels == 4) */ {\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                a = *src++;\n                if (bg_image) {\n                    bg_red   = *src2++;\n                    bg_green = *src2++;\n                    bg_blue  = *src2++;\n                }\n                if (a == 255) {\n                    red   = r;\n                    green = g;\n                    blue  = b;\n                } else if (a == 0) {\n                    red   = bg_red;\n                    green = bg_green;\n                    blue  = bg_blue;\n                } else {\n                    /* this macro (from png.h) composites the foreground\n                     * and background values and puts the result into the\n                     * first argument */\n                    alpha_composite(red,   r, a, bg_red);\n                    alpha_composite(green, g, a, bg_green);\n                    alpha_composite(blue,  b, a, bg_blue);\n                }\n                pixel = (red   << RShift) |\n                        (green << GShift) |\n                        (blue  << BShift);\n                /* recall that we set ximage->byte_order = MSBFirst above */\n                if (bpp == 32) {\n                    *dest++ = (char)((pixel >> 24) & 0xff);\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                } else {\n                    /* GRR BUG?  this assumes bpp == 24 & bits are packed low */\n                    /*           (probably need to use RShift, RMask, etc.) */\n                    *dest++ = (char)((pixel >> 16) & 0xff);\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n        }\n\n    } else if (depth == 16) {\n        ush red, green, blue;\n\n        src = rpng2_info.row_pointers[row];\n        if (bg_image)\n            src2 = bg_data + row*bg_rowbytes;\n        dest = ximage->data + row*ximage_rowbytes;\n        if (rpng2_info.channels == 3) {\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                red   = ((ush)(*src) << 8);\n                ++src;\n                green = ((ush)(*src) << 8);\n                ++src;\n                blue  = ((ush)(*src) << 8);\n                ++src;\n                pixel = ((red   >> RShift) & RMask) |\n                        ((green >> GShift) & GMask) |\n                        ((blue  >> BShift) & BMask);\n                /* recall that we set ximage->byte_order = MSBFirst above */\n                *dest++ = (char)((pixel >>  8) & 0xff);\n                *dest++ = (char)( pixel        & 0xff);\n            }\n        } else /* if (rpng2_info.channels == 4) */ {\n            for (i = rpng2_info.width;  i > 0;  --i) {\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                a = *src++;\n                if (bg_image) {\n                    bg_red   = *src2++;\n                    bg_green = *src2++;\n                    bg_blue  = *src2++;\n                }\n                if (a == 255) {\n                    red   = ((ush)r << 8);\n                    green = ((ush)g << 8);\n                    blue  = ((ush)b << 8);\n                } else if (a == 0) {\n                    red   = ((ush)bg_red   << 8);\n                    green = ((ush)bg_green << 8);\n                    blue  = ((ush)bg_blue  << 8);\n                } else {\n                    /* this macro (from png.h) composites the foreground\n                     * and background values and puts the result back into\n                     * the first argument (== fg byte here:  safe) */\n                    alpha_composite(r, r, a, bg_red);\n                    alpha_composite(g, g, a, bg_green);\n                    alpha_composite(b, b, a, bg_blue);\n                    red   = ((ush)r << 8);\n                    green = ((ush)g << 8);\n                    blue  = ((ush)b << 8);\n                }\n                pixel = ((red   >> RShift) & RMask) |\n                        ((green >> GShift) & GMask) |\n                        ((blue  >> BShift) & BMask);\n                /* recall that we set ximage->byte_order = MSBFirst above */\n                *dest++ = (char)((pixel >>  8) & 0xff);\n                *dest++ = (char)( pixel        & 0xff);\n            }\n        }\n\n    } else /* depth == 8 */ {\n\n        /* GRR:  add 8-bit support */\n\n    }\n\n\n/*---------------------------------------------------------------------------\n    Display after every 16 rows or when on one of last two rows.  (Region\n    may include previously displayed lines due to interlacing--i.e., not\n    contiguous.  Also, second-to-last row is final one in interlaced images\n    with odd number of rows.)  For demos, flush (and delay) after every 16th\n    row so \"sparse\" passes don't go twice as fast.\n  ---------------------------------------------------------------------------*/\n\n    if (demo_timing && (row - firstrow >= 16 || row >= rpng2_info.height-2)) {\n        XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,\n          (int)firstrow, rpng2_info.width, row - firstrow + 1);\n        XFlush(display);\n        rows = 0;\n        usleep(usleep_duration);\n    } else\n    if (!demo_timing && ((rows & 0xf) == 0 || row >= rpng2_info.height-2)) {\n        XPutImage(display, window, gc, ximage, 0, (int)firstrow, 0,\n          (int)firstrow, rpng2_info.width, row - firstrow + 1);\n        XFlush(display);\n        rows = 0;\n    }\n\n}\n\n\n\n\n\nstatic void rpng2_x_finish_display(void)\n{\n    Trace((stderr, \"beginning rpng2_x_finish_display()\\n\"))\n\n    /* last row has already been displayed by rpng2_x_display_row(), so we\n     * have nothing to do here except set a flag and let the user know that\n     * the image is done */\n\n    rpng2_info.state = kDone;\n    printf(\n      \"Done.  Press Q, Esc or mouse button 1 (within image window) to quit.\\n\");\n    fflush(stdout);\n}\n\n\n\n\n\nstatic void rpng2_x_redisplay_image(ulg startcol, ulg startrow,\n                                    ulg width, ulg height)\n{\n    uch bg_red   = rpng2_info.bg_red;\n    uch bg_green = rpng2_info.bg_green;\n    uch bg_blue  = rpng2_info.bg_blue;\n    uch *src, *src2=NULL;\n    char *dest;\n    uch r, g, b, a;\n    ulg i, row, lastrow = 0;\n    ulg pixel;\n    int ximage_rowbytes = ximage->bytes_per_line;\n\n\n    Trace((stderr, \"beginning display loop (image_channels == %d)\\n\",\n      rpng2_info.channels))\n    Trace((stderr, \"   (width = %ld, rowbytes = %d, ximage_rowbytes = %d)\\n\",\n      rpng2_info.width, rpng2_info.rowbytes, ximage_rowbytes))\n    Trace((stderr, \"   (bpp = %d)\\n\", ximage->bits_per_pixel))\n    Trace((stderr, \"   (byte_order = %s)\\n\", ximage->byte_order == MSBFirst?\n      \"MSBFirst\" : (ximage->byte_order == LSBFirst? \"LSBFirst\" : \"unknown\")))\n\n/*---------------------------------------------------------------------------\n    Aside from the use of the rpng2_info struct and of src2 (for background\n    image), this routine is identical to rpng_x_display_image() in the non-\n    progressive version of the program--for the simple reason that redisplay\n    of the image against a new background happens after the image is fully\n    decoded and therefore is, by definition, non-progressive.\n  ---------------------------------------------------------------------------*/\n\n    if (depth == 24 || depth == 32) {\n        ulg red, green, blue;\n        int bpp = ximage->bits_per_pixel;\n\n        for (lastrow = row = startrow;  row < startrow+height;  ++row) {\n            src = rpng2_info.image_data + row*rpng2_info.rowbytes;\n            if (bg_image)\n                src2 = bg_data + row*bg_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            if (rpng2_info.channels == 3) {\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    red   = *src++;\n                    green = *src++;\n                    blue  = *src++;\n#ifdef NO_24BIT_MASKS\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    if (bpp == 32) {\n                        *dest++ = (char)((pixel >> 24) & 0xff);\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    } else {\n                        /* this assumes bpp == 24 & bits are packed low */\n                        /* (probably need to use RShift, RMask, etc.) */\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    }\n#else\n                    red   = (RShift < 0)? red   << (-RShift) : red   >> RShift;\n                    green = (GShift < 0)? green << (-GShift) : green >> GShift;\n                    blue  = (BShift < 0)? blue  << (-BShift) : blue  >> BShift;\n                    pixel = (red & RMask) | (green & GMask) | (blue & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    if (bpp == 32) {\n                        *dest++ = (char)((pixel >> 24) & 0xff);\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    } else {\n                        /* GRR BUG */\n                        /* this assumes bpp == 24 & bits are packed low */\n                        /* (probably need to use RShift/RMask/etc. here, too) */\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    }\n#endif\n                }\n\n            } else /* if (rpng2_info.channels == 4) */ {\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    r = *src++;\n                    g = *src++;\n                    b = *src++;\n                    a = *src++;\n                    if (bg_image) {\n                        bg_red   = *src2++;\n                        bg_green = *src2++;\n                        bg_blue  = *src2++;\n                    }\n                    if (a == 255) {\n                        red   = r;\n                        green = g;\n                        blue  = b;\n                    } else if (a == 0) {\n                        red   = bg_red;\n                        green = bg_green;\n                        blue  = bg_blue;\n                    } else {\n                        /* this macro (from png.h) composites the foreground\n                         * and background values and puts the result into the\n                         * first argument */\n                        alpha_composite(red,   r, a, bg_red);\n                        alpha_composite(green, g, a, bg_green);\n                        alpha_composite(blue,  b, a, bg_blue);\n                    }\n#ifdef NO_24BIT_MASKS\n                    pixel = (red   << RShift) |\n                            (green << GShift) |\n                            (blue  << BShift);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    if (bpp == 32) {\n                        *dest++ = (char)((pixel >> 24) & 0xff);\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    } else {\n                        /* this assumes bpp == 24 & bits are packed low */\n                        /* (probably need to use RShift, RMask, etc.) */\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    }\n#else\n                    red   = (RShift < 0)? red   << (-RShift) : red   >> RShift;\n                    green = (GShift < 0)? green << (-GShift) : green >> GShift;\n                    blue  = (BShift < 0)? blue  << (-BShift) : blue  >> BShift;\n                    pixel = (red & RMask) | (green & GMask) | (blue & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    if (bpp == 32) {\n                        *dest++ = (char)((pixel >> 24) & 0xff);\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    } else {\n                        /* GRR BUG */\n                        /* this assumes bpp == 24 & bits are packed low */\n                        /* (probably need to use RShift/RMask/etc. here, too) */\n                        *dest++ = (char)((pixel >> 16) & 0xff);\n                        *dest++ = (char)((pixel >>  8) & 0xff);\n                        *dest++ = (char)( pixel        & 0xff);\n                    }\n#endif\n                }\n            }\n            /* display after every 16 lines */\n            if (((row+1) & 0xf) == 0) {\n                XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n                  (int)lastrow, rpng2_info.width, 16);\n                XFlush(display);\n                lastrow = row + 1;\n            }\n        }\n\n    } else if (depth == 16) {\n        ush red, green, blue;\n\n        for (lastrow = row = startrow;  row < startrow+height;  ++row) {\n            src = rpng2_info.row_pointers[row];\n            if (bg_image)\n                src2 = bg_data + row*bg_rowbytes;\n            dest = ximage->data + row*ximage_rowbytes;\n            if (rpng2_info.channels == 3) {\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    red   = ((ush)(*src) << 8);\n                    ++src;\n                    green = ((ush)(*src) << 8);\n                    ++src;\n                    blue  = ((ush)(*src) << 8);\n                    ++src;\n                    pixel = ((red   >> RShift) & RMask) |\n                            ((green >> GShift) & GMask) |\n                            ((blue  >> BShift) & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            } else /* if (rpng2_info.channels == 4) */ {\n                for (i = rpng2_info.width;  i > 0;  --i) {\n                    r = *src++;\n                    g = *src++;\n                    b = *src++;\n                    a = *src++;\n                    if (bg_image) {\n                        bg_red   = *src2++;\n                        bg_green = *src2++;\n                        bg_blue  = *src2++;\n                    }\n                    if (a == 255) {\n                        red   = ((ush)r << 8);\n                        green = ((ush)g << 8);\n                        blue  = ((ush)b << 8);\n                    } else if (a == 0) {\n                        red   = ((ush)bg_red   << 8);\n                        green = ((ush)bg_green << 8);\n                        blue  = ((ush)bg_blue  << 8);\n                    } else {\n                        /* this macro (from png.h) composites the foreground\n                         * and background values and puts the result back into\n                         * the first argument (== fg byte here:  safe) */\n                        alpha_composite(r, r, a, bg_red);\n                        alpha_composite(g, g, a, bg_green);\n                        alpha_composite(b, b, a, bg_blue);\n                        red   = ((ush)r << 8);\n                        green = ((ush)g << 8);\n                        blue  = ((ush)b << 8);\n                    }\n                    pixel = ((red   >> RShift) & RMask) |\n                            ((green >> GShift) & GMask) |\n                            ((blue  >> BShift) & BMask);\n                    /* recall that we set ximage->byte_order = MSBFirst above */\n                    *dest++ = (char)((pixel >>  8) & 0xff);\n                    *dest++ = (char)( pixel        & 0xff);\n                }\n            }\n            /* display after every 16 lines */\n            if (((row+1) & 0xf) == 0) {\n                XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n                  (int)lastrow, rpng2_info.width, 16);\n                XFlush(display);\n                lastrow = row + 1;\n            }\n        }\n\n    } else /* depth == 8 */ {\n\n        /* GRR:  add 8-bit support */\n\n    }\n\n    Trace((stderr, \"calling final XPutImage()\\n\"))\n    if (lastrow < startrow+height) {\n        XPutImage(display, window, gc, ximage, 0, (int)lastrow, 0,\n          (int)lastrow, rpng2_info.width, rpng2_info.height-lastrow);\n        XFlush(display);\n    }\n\n    (void)startcol;\n    (void)width;\n\n} /* end function rpng2_x_redisplay_image() */\n\n\n\n\n\n#ifdef FEATURE_LOOP\n\nstatic void rpng2_x_reload_bg_image(void)\n{\n    char *dest;\n    uch r1, r2, g1, g2, b1, b2;\n    uch r1_inv, r2_inv, g1_inv, g2_inv, b1_inv, b2_inv;\n    int k, hmax, max;\n    int xidx, yidx, yidx_max;\n    int even_odd_vert, even_odd_horiz, even_odd;\n    int invert_gradient2 = (bg[pat].type & 0x08);\n    int invert_column;\n    ulg i, row;\n\n\n    bgscale = (pat == 0)? 8 : bgscale_default;\n    yidx_max = bgscale - 1;\n\n/*---------------------------------------------------------------------------\n    Vertical gradients (ramps) in NxN squares, alternating direction and\n    colors (N == bgscale).\n  ---------------------------------------------------------------------------*/\n\n    if ((bg[pat].type & 0x07) == 0) {\n        uch r1_min  = rgb[bg[pat].rgb1_min].r;\n        uch g1_min  = rgb[bg[pat].rgb1_min].g;\n        uch b1_min  = rgb[bg[pat].rgb1_min].b;\n        uch r2_min  = rgb[bg[pat].rgb2_min].r;\n        uch g2_min  = rgb[bg[pat].rgb2_min].g;\n        uch b2_min  = rgb[bg[pat].rgb2_min].b;\n        int r1_diff = rgb[bg[pat].rgb1_max].r - r1_min;\n        int g1_diff = rgb[bg[pat].rgb1_max].g - g1_min;\n        int b1_diff = rgb[bg[pat].rgb1_max].b - b1_min;\n        int r2_diff = rgb[bg[pat].rgb2_max].r - r2_min;\n        int g2_diff = rgb[bg[pat].rgb2_max].g - g2_min;\n        int b2_diff = rgb[bg[pat].rgb2_max].b - b2_min;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = (int)(row % bgscale);\n            even_odd_vert = (int)((row / bgscale) & 1);\n\n            r1 = r1_min + (r1_diff * yidx) / yidx_max;\n            g1 = g1_min + (g1_diff * yidx) / yidx_max;\n            b1 = b1_min + (b1_diff * yidx) / yidx_max;\n            r1_inv = r1_min + (r1_diff * (yidx_max-yidx)) / yidx_max;\n            g1_inv = g1_min + (g1_diff * (yidx_max-yidx)) / yidx_max;\n            b1_inv = b1_min + (b1_diff * (yidx_max-yidx)) / yidx_max;\n\n            r2 = r2_min + (r2_diff * yidx) / yidx_max;\n            g2 = g2_min + (g2_diff * yidx) / yidx_max;\n            b2 = b2_min + (b2_diff * yidx) / yidx_max;\n            r2_inv = r2_min + (r2_diff * (yidx_max-yidx)) / yidx_max;\n            g2_inv = g2_min + (g2_diff * (yidx_max-yidx)) / yidx_max;\n            b2_inv = b2_min + (b2_diff * (yidx_max-yidx)) / yidx_max;\n\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                even_odd_horiz = (int)((i / bgscale) & 1);\n                even_odd = even_odd_vert ^ even_odd_horiz;\n                invert_column =\n                  (even_odd_horiz && (bg[pat].type & 0x10));\n                if (even_odd == 0) {        /* gradient #1 */\n                    if (invert_column) {\n                        *dest++ = r1_inv;\n                        *dest++ = g1_inv;\n                        *dest++ = b1_inv;\n                    } else {\n                        *dest++ = r1;\n                        *dest++ = g1;\n                        *dest++ = b1;\n                    }\n                } else {                    /* gradient #2 */\n                    if ((invert_column && invert_gradient2) ||\n                        (!invert_column && !invert_gradient2))\n                    {\n                        *dest++ = r2;       /* not inverted or */\n                        *dest++ = g2;       /*  doubly inverted */\n                        *dest++ = b2;\n                    } else {\n                        *dest++ = r2_inv;\n                        *dest++ = g2_inv;   /* singly inverted */\n                        *dest++ = b2_inv;\n                    }\n                }\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Soft gradient-diamonds with scale = bgscale.  Code contributed by Adam\n    M. Costello.\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 1) {\n\n        hmax = (bgscale-1)/2;   /* half the max weight of a color */\n        max = 2*hmax;           /* the max weight of a color */\n\n        r1 = rgb[bg[pat].rgb1_max].r;\n        g1 = rgb[bg[pat].rgb1_max].g;\n        b1 = rgb[bg[pat].rgb1_max].b;\n        r2 = rgb[bg[pat].rgb2_max].r;\n        g2 = rgb[bg[pat].rgb2_max].g;\n        b2 = rgb[bg[pat].rgb2_max].b;\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            yidx = (int)(row % bgscale);\n            if (yidx > hmax)\n                yidx = bgscale-1 - yidx;\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                xidx = (int)(i % bgscale);\n                if (xidx > hmax)\n                    xidx = bgscale-1 - xidx;\n                k = xidx + yidx;\n                *dest++ = (k*r1 + (max-k)*r2) / max;\n                *dest++ = (k*g1 + (max-k)*g2) / max;\n                *dest++ = (k*b1 + (max-k)*b2) / max;\n            }\n        }\n\n/*---------------------------------------------------------------------------\n    Radial \"starburst\" with azimuthal sinusoids; [eventually number of sinu-\n    soids will equal bgscale?].  This one is slow but very cool.  Code con-\n    tributed by Pieter S. van der Meulen (originally in Smalltalk).\n  ---------------------------------------------------------------------------*/\n\n    } else if ((bg[pat].type & 0x07) == 2) {\n        uch ch;\n        int ii, x, y, hw, hh, grayspot;\n        double freq, rotate, saturate, gray, intensity;\n        double angle=0.0, aoffset=0.0, maxDist, dist;\n        double red=0.0, green=0.0, blue=0.0, hue, s, v, f, p, q, t;\n\n        hh = (int)(rpng2_info.height / 2);\n        hw = (int)(rpng2_info.width / 2);\n\n        /* variables for radial waves:\n         *   aoffset:  number of degrees to rotate hue [CURRENTLY NOT USED]\n         *   freq:  number of color beams originating from the center\n         *   grayspot:  size of the graying center area (anti-alias)\n         *   rotate:  rotation of the beams as a function of radius\n         *   saturate:  saturation of beams' shape azimuthally\n         */\n        angle = CLIP(angle, 0.0, 360.0);\n        grayspot = CLIP(bg[pat].bg_gray, 1, (hh + hw));\n        freq = MAX((double)bg[pat].bg_freq, 0.0);\n        saturate = (double)bg[pat].bg_bsat * 0.1;\n        rotate = (double)bg[pat].bg_brot * 0.1;\n        gray = 0.0;\n        intensity = 0.0;\n        maxDist = (double)((hw*hw) + (hh*hh));\n\n        for (row = 0;  row < rpng2_info.height;  ++row) {\n            y = (int)(row - hh);\n            dest = (char *)bg_data + row*bg_rowbytes;\n            for (i = 0;  i < rpng2_info.width;  ++i) {\n                x = (int)(i - hw);\n                angle = (x == 0)? PI_2 : atan((double)y / (double)x);\n                gray = (double)MAX(ABS(y), ABS(x)) / grayspot;\n                gray = MIN(1.0, gray);\n                dist = (double)((x*x) + (y*y)) / maxDist;\n                intensity = cos((angle+(rotate*dist*PI)) * freq) *\n                  gray * saturate;\n                intensity = (MAX(MIN(intensity,1.0),-1.0) + 1.0) * 0.5;\n                hue = (angle + PI) * INV_PI_360 + aoffset;\n                s = gray * ((double)(ABS(x)+ABS(y)) / (double)(hw + hh));\n                s = MIN(MAX(s,0.0), 1.0);\n                v = MIN(MAX(intensity,0.0), 1.0);\n\n                if (s == 0.0) {\n                    ch = (uch)(v * 255.0);\n                    *dest++ = ch;\n                    *dest++ = ch;\n                    *dest++ = ch;\n                } else {\n                    if ((hue < 0.0) || (hue >= 360.0))\n                        hue -= (((int)(hue / 360.0)) * 360.0);\n                    hue /= 60.0;\n                    ii = (int)hue;\n                    f = hue - (double)ii;\n                    p = (1.0 - s) * v;\n                    q = (1.0 - (s * f)) * v;\n                    t = (1.0 - (s * (1.0 - f))) * v;\n                    if      (ii == 0) { red = v; green = t; blue = p; }\n                    else if (ii == 1) { red = q; green = v; blue = p; }\n                    else if (ii == 2) { red = p; green = v; blue = t; }\n                    else if (ii == 3) { red = p; green = q; blue = v; }\n                    else if (ii == 4) { red = t; green = p; blue = v; }\n                    else if (ii == 5) { red = v; green = p; blue = q; }\n                    *dest++ = (uch)(red * 255.0);\n                    *dest++ = (uch)(green * 255.0);\n                    *dest++ = (uch)(blue * 255.0);\n                }\n            }\n        }\n    }\n\n} /* end function rpng2_x_reload_bg_image() */\n\n\n\n\n\nstatic int is_number(char *p)\n{\n    while (*p) {\n        if (!isdigit(*p))\n            return FALSE;\n        ++p;\n    }\n    return TRUE;\n}\n\n#endif /* FEATURE_LOOP */\n\n\n\n\n\nstatic void rpng2_x_cleanup(void)\n{\n    if (bg_image && bg_data) {\n        free(bg_data);\n        bg_data = NULL;\n    }\n\n    if (rpng2_info.image_data) {\n        free(rpng2_info.image_data);\n        rpng2_info.image_data = NULL;\n    }\n\n    if (rpng2_info.row_pointers) {\n        free(rpng2_info.row_pointers);\n        rpng2_info.row_pointers = NULL;\n    }\n\n    if (ximage) {\n        if (ximage->data) {\n            free(ximage->data);           /* we allocated it, so we free it */\n            ximage->data = (char *)NULL;  /*  instead of XDestroyImage() */\n        }\n        XDestroyImage(ximage);\n        ximage = NULL;\n    }\n\n    if (have_gc)\n        XFreeGC(display, gc);\n\n    if (have_window)\n        XDestroyWindow(display, window);\n\n    if (have_colormap)\n        XFreeColormap(display, colormap);\n\n    if (have_nondefault_visual)\n        XFree(visual_list);\n}\n\n\n\n\n\nstatic int rpng2_x_msb(ulg u32val)\n{\n    int i;\n\n    for (i = 31;  i >= 0;  --i) {\n        if (u32val & 0x80000000L)\n            break;\n        u32val <<= 1;\n    }\n    return i;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/wpng.c",
    "content": "/*---------------------------------------------------------------------------\n\n   wpng - simple PNG-writing program                                 wpng.c\n\n   This program converts certain NetPBM binary files (grayscale and RGB,\n   maxval = 255) to PNG.  Non-interlaced PNGs are written progressively;\n   interlaced PNGs are read and written in one memory-intensive blast.\n\n   Thanks to Jean-loup Gailly for providing the necessary trick to read\n   interactive text from the keyboard while stdin is redirected.  Thanks\n   to Cosmin Truta for Cygwin fixes.\n\n   NOTE:  includes provisional support for PNM type \"8\" (portable alphamap)\n          images, presumed to be a 32-bit interleaved RGBA format; no pro-\n          vision for possible interleaved grayscale+alpha (16-bit) format.\n          THIS IS UNLIKELY TO BECOME AN OFFICIAL NETPBM ALPHA FORMAT!\n\n   to do:\n    - delete output file if quit before calling any writepng routines\n    - process backspace with -text option under DOS/Win? (currently get ^H)\n\n  ---------------------------------------------------------------------------\n\n   Changelog:\n    - 1.01:  initial public release\n    - 1.02:  modified to allow abbreviated options\n    - 1.03:  removed extraneous character from usage screen; fixed bug in\n              command-line parsing\n    - 1.04:  fixed DOS/OS2/Win32 detection, including partial Cygwin fix\n              (see http://home.att.net/~perlspinr/diffs/GregBook_cygwin.diff)\n    - 2.00:  dual-licensed (added GNU GPL)\n\n        [REPORTED BUG (win32 only):  \"contrib/gregbook/wpng.c - cmd line\n         dose not work!  In order to do something useful I needed to redirect\n         both input and output, with cygwin and with bcc32 as well.  Under\n         Linux, the same wpng appears to work fine.  I don't know what is\n         the problem.\"]\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#define PROGNAME  \"wpng\"\n#define VERSION   \"2.00 of 2 June 2007\"\n#define APPNAME   \"Simple PGM/PPM/PAM to PNG Converter\"\n\n#if defined(__MSDOS__) || defined(__OS2__)\n#  define DOS_OS2_W32\n#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__)\n#  ifndef __GNUC__   /* treat Win32 native ports of gcc as Unix environments */\n#    define DOS_OS2_W32\n#  endif\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <setjmp.h>     /* for jmpbuf declaration in writepng.h */\n#include <time.h>\n\n#ifdef DOS_OS2_W32\n#  include <io.h>       /* for isatty(), setmode() prototypes */\n#  include <fcntl.h>    /* O_BINARY for fdopen() without text translation */\n#  ifdef __EMX__\n#    ifndef getch\n#      define getch() _read_kbd(0, 1, 0)    /* need getche() */\n#    endif\n#  else /* !__EMX__ */\n#    ifdef __GO32__\n#      include <pc.h>\n#      define getch() getkey()  /* GRR:  need getche() */\n#    else\n#      include <conio.h>        /* for getche() console input */\n#    endif\n#  endif /* ?__EMX__ */\n#  define FGETS(buf,len,stream)  dos_kbd_gets(buf,len)\n#else\n#  include <unistd.h>           /* for isatty() prototype */\n#  define FGETS fgets\n#endif\n\n/* #define DEBUG  :  this enables the Trace() macros */\n\n/* #define FORBID_LATIN1_CTRL  :  this requires the user to re-enter any\n   text that includes control characters discouraged by the PNG spec; text\n   that includes an escape character (27) must be re-entered regardless */\n\n#include \"writepng.h\"   /* typedefs, common macros, writepng prototypes */\n\n\n\n/* local prototypes */\n\nstatic int  wpng_isvalid_latin1(uch *p, int len);\nstatic void wpng_cleanup(void);\n\n#ifdef DOS_OS2_W32\n   static char *dos_kbd_gets(char *buf, int len);\n#endif\n\n\n\nstatic mainprog_info wpng_info;   /* lone global */\n\n\n\nint main(int argc, char **argv)\n{\n#ifndef DOS_OS2_W32\n    FILE *keybd;\n#endif\n#ifdef sgi\n    FILE *tmpfile;      /* or we could just use keybd, since no overlap */\n    char tmpline[80];\n#endif\n    char *inname = NULL, outname[256];\n    char *p, pnmchar, pnmline[256];\n    char *bgstr, *textbuf = NULL;\n    ulg rowbytes;\n    int rc, len = 0;\n    int error = 0;\n    int text = FALSE;\n    int maxval;\n    double LUT_exponent;                /* just the lookup table */\n    double CRT_exponent = 2.2;          /* just the monitor */\n    double default_display_exponent;    /* whole display system */\n    double default_gamma = 0.0;\n\n\n    wpng_info.infile = NULL;\n    wpng_info.outfile = NULL;\n    wpng_info.image_data = NULL;\n    wpng_info.row_pointers = NULL;\n    wpng_info.filter = FALSE;\n    wpng_info.interlaced = FALSE;\n    wpng_info.have_bg = FALSE;\n    wpng_info.have_time = FALSE;\n    wpng_info.have_text = 0;\n    wpng_info.gamma = 0.0;\n\n\n    /* First get the default value for our display-system exponent, i.e.,\n     * the product of the CRT exponent and the exponent corresponding to\n     * the frame-buffer's lookup table (LUT), if any.  If the PNM image\n     * looks correct on the user's display system, its file gamma is the\n     * inverse of this value.  (Note that this is not an exhaustive list\n     * of LUT values--e.g., OpenStep has a lot of weird ones--but it should\n     * cover 99% of the current possibilities.  This section must ensure\n     * that default_display_exponent is positive.) */\n\n#if defined(NeXT)\n    /* third-party utilities can modify the default LUT exponent */\n    LUT_exponent = 1.0 / 2.2;\n    /*\n    if (some_next_function_that_returns_gamma(&next_gamma))\n        LUT_exponent = 1.0 / next_gamma;\n     */\n#elif defined(sgi)\n    LUT_exponent = 1.0 / 1.7;\n    /* there doesn't seem to be any documented function to\n     * get the \"gamma\" value, so we do it the hard way */\n    tmpfile = fopen(\"/etc/config/system.glGammaVal\", \"r\");\n    if (tmpfile) {\n        double sgi_gamma;\n\n        fgets(tmpline, 80, tmpfile);\n        fclose(tmpfile);\n        sgi_gamma = atof(tmpline);\n        if (sgi_gamma > 0.0)\n            LUT_exponent = 1.0 / sgi_gamma;\n    }\n#elif defined(Macintosh)\n    LUT_exponent = 1.8 / 2.61;\n    /*\n    if (some_mac_function_that_returns_gamma(&mac_gamma))\n        LUT_exponent = mac_gamma / 2.61;\n     */\n#else\n    LUT_exponent = 1.0;   /* assume no LUT:  most PCs */\n#endif\n\n    /* the defaults above give 1.0, 1.3, 1.5 and 2.2, respectively: */\n    default_display_exponent = LUT_exponent * CRT_exponent;\n\n\n    /* If the user has set the SCREEN_GAMMA environment variable as suggested\n     * (somewhat imprecisely) in the libpng documentation, use that; otherwise\n     * use the default value we just calculated.  Either way, the user may\n     * override this via a command-line option. */\n\n    if ((p = getenv(\"SCREEN_GAMMA\")) != NULL) {\n        double exponent = atof(p);\n\n        if (exponent > 0.0)\n            default_gamma = 1.0 / exponent;\n    }\n\n    if (default_gamma == 0.0)\n        default_gamma = 1.0 / default_display_exponent;\n\n\n    /* Now parse the command line for options and the PNM filename. */\n\n    while (*++argv && !error) {\n        if (!strncmp(*argv, \"-i\", 2)) {\n            wpng_info.interlaced = TRUE;\n        } else if (!strncmp(*argv, \"-time\", 3)) {\n            wpng_info.modtime = time(NULL);\n            wpng_info.have_time = TRUE;\n        } else if (!strncmp(*argv, \"-text\", 3)) {\n            text = TRUE;\n        } else if (!strncmp(*argv, \"-gamma\", 2)) {\n            if (!*++argv)\n                ++error;\n            else {\n                wpng_info.gamma = atof(*argv);\n                if (wpng_info.gamma <= 0.0)\n                    ++error;\n                else if (wpng_info.gamma > 1.01)\n                    fprintf(stderr, PROGNAME\n                      \" warning:  file gammas are usually less than 1.0\\n\");\n            }\n        } else if (!strncmp(*argv, \"-bgcolor\", 4)) {\n            if (!*++argv)\n                ++error;\n            else {\n                bgstr = *argv;\n                if (strlen(bgstr) != 7 || bgstr[0] != '#')\n                    ++error;\n                else {\n                    unsigned r, g, b;  /* this way quiets compiler warnings */\n\n                    sscanf(bgstr+1, \"%2x%2x%2x\", &r, &g, &b);\n                    wpng_info.bg_red   = (uch)r;\n                    wpng_info.bg_green = (uch)g;\n                    wpng_info.bg_blue  = (uch)b;\n                    wpng_info.have_bg = TRUE;\n                }\n            }\n        } else {\n            if (**argv != '-') {\n                inname = *argv;\n                if (argv[1])   /* shouldn't be any more args after filename */\n                    ++error;\n            } else\n                ++error;   /* not expecting any other options */\n        }\n    }\n\n\n    /* open the input and output files, or register an error and abort */\n\n    if (!inname) {\n        if (isatty(0)) {\n            fprintf(stderr, PROGNAME\n              \":  must give input filename or provide image data via stdin\\n\");\n            ++error;\n        } else {\n#ifdef DOS_OS2_W32\n            /* some buggy C libraries require BOTH setmode() and fdopen(bin) */\n            setmode(fileno(stdin), O_BINARY);\n            setmode(fileno(stdout), O_BINARY);\n#endif\n            if ((wpng_info.infile = fdopen(fileno(stdin), \"rb\")) == NULL) {\n                fprintf(stderr, PROGNAME\n                  \":  unable to reopen stdin in binary mode\\n\");\n                ++error;\n            } else\n            if ((wpng_info.outfile = fdopen(fileno(stdout), \"wb\")) == NULL) {\n                fprintf(stderr, PROGNAME\n                  \":  unable to reopen stdout in binary mode\\n\");\n                fclose(wpng_info.infile);\n                ++error;\n            } else\n                wpng_info.filter = TRUE;\n        }\n    } else if ((len = strlen(inname)) > 250) {\n        fprintf(stderr, PROGNAME \":  input filename is too long [%d chars]\\n\",\n          len);\n        ++error;\n    } else if (!(wpng_info.infile = fopen(inname, \"rb\"))) {\n        fprintf(stderr, PROGNAME \":  can't open input file [%s]\\n\", inname);\n        ++error;\n    }\n\n    if (!error) {\n        fgets(pnmline, 256, wpng_info.infile);\n        if (pnmline[0] != 'P' || ((pnmchar = pnmline[1]) != '5' &&\n            pnmchar != '6' && pnmchar != '8'))\n        {\n            fprintf(stderr, PROGNAME\n              \":  input file [%s] is not a binary PGM, PPM or PAM file\\n\",\n              inname);\n            ++error;\n        } else {\n            wpng_info.pnmtype = (int)(pnmchar - '0');\n            if (wpng_info.pnmtype != 8)\n                wpng_info.have_bg = FALSE;  /* no need for bg if opaque */\n            do {\n                fgets(pnmline, 256, wpng_info.infile);  /* lose any comments */\n            } while (pnmline[0] == '#');\n            sscanf(pnmline, \"%ld %ld\", &wpng_info.width, &wpng_info.height);\n            do {\n                fgets(pnmline, 256, wpng_info.infile);  /* more comment lines */\n            } while (pnmline[0] == '#');\n            sscanf(pnmline, \"%d\", &maxval);\n            if (wpng_info.width <= 0L || wpng_info.height <= 0L ||\n                maxval != 255)\n            {\n                fprintf(stderr, PROGNAME\n                  \":  only positive width/height, maxval == 255 allowed \\n\");\n                ++error;\n            }\n            wpng_info.sample_depth = 8;  /* <==> maxval 255 */\n\n            if (!wpng_info.filter) {\n                /* make outname from inname */\n                if ((p = strrchr(inname, '.')) == NULL ||\n                    (p - inname) != (len - 4))\n                {\n                    strcpy(outname, inname);\n                    strcpy(outname+len, \".png\");\n                } else {\n                    len -= 4;\n                    strncpy(outname, inname, len);\n                    strcpy(outname+len, \".png\");\n                }\n                /* check if outname already exists; if not, open */\n                if ((wpng_info.outfile = fopen(outname, \"rb\")) != NULL) {\n                    fprintf(stderr, PROGNAME \":  output file exists [%s]\\n\",\n                      outname);\n                    fclose(wpng_info.outfile);\n                    ++error;\n                } else if (!(wpng_info.outfile = fopen(outname, \"wb\"))) {\n                    fprintf(stderr, PROGNAME \":  can't open output file [%s]\\n\",\n                      outname);\n                    ++error;\n                }\n            }\n        }\n        if (error) {\n            fclose(wpng_info.infile);\n            wpng_info.infile = NULL;\n            if (wpng_info.filter) {\n                fclose(wpng_info.outfile);\n                wpng_info.outfile = NULL;\n            }\n        }\n    }\n\n\n    /* if we had any errors, print usage and die horrible death...arrr! */\n\n    if (error) {\n        fprintf(stderr, \"\\n%s %s:  %s\\n\", PROGNAME, VERSION, APPNAME);\n        writepng_version_info();\n        fprintf(stderr, \"\\n\"\n\"Usage:  %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] pnmfile\\n\"\n\"or: ... | %s [-gamma exp] [-bgcolor bg] [-text] [-time] [-interlace] | ...\\n\"\n         \"    exp \\ttransfer-function exponent (``gamma'') of the image in\\n\"\n         \"\\t\\t  floating-point format (e.g., ``%.5f''); if image looks\\n\"\n         \"\\t\\t  correct on given display system, image gamma is equal to\\n\"\n         \"\\t\\t  inverse of display-system exponent, i.e., 1 / (LUT * CRT)\\n\"\n         \"\\t\\t  (where LUT = lookup-table exponent and CRT = CRT exponent;\\n\"\n         \"\\t\\t  first varies, second is usually 2.2, all are positive)\\n\"\n         \"    bg  \\tdesired background color for alpha-channel images, in\\n\"\n         \"\\t\\t  7-character hex RGB format (e.g., ``#ff7700'' for orange:\\n\"\n         \"\\t\\t  same as HTML colors)\\n\"\n         \"    -text\\tprompt interactively for text info (tEXt chunks)\\n\"\n         \"    -time\\tinclude a tIME chunk (last modification time)\\n\"\n         \"    -interlace\\twrite interlaced PNG image\\n\"\n         \"\\n\"\n\"pnmfile or stdin must be a binary PGM (`P5'), PPM (`P6') or (extremely\\n\"\n\"unofficial and unsupported!) PAM (`P8') file.  Currently it is required\\n\"\n\"to have maxval == 255 (i.e., no scaling).  If pnmfile is specified, it\\n\"\n\"is converted to the corresponding PNG file with the same base name but a\\n\"\n\"``.png'' extension; files read from stdin are converted and sent to stdout.\\n\"\n\"The conversion is progressive (low memory usage) unless interlacing is\\n\"\n\"requested; in that case the whole image will be buffered in memory and\\n\"\n\"written in one call.\\n\"\n         \"\\n\", PROGNAME, PROGNAME, default_gamma);\n        exit(1);\n    }\n\n\n    /* prepare the text buffers for libpng's use; note that even though\n     * PNG's png_text struct includes a length field, we don't have to fill\n     * it out */\n\n    if (text &&\n#ifndef DOS_OS2_W32\n        (keybd = fdopen(fileno(stderr), \"r\")) != NULL &&\n#endif\n        (textbuf = (char *)malloc((5 + 9)*75)) != NULL)\n    {\n        int i, valid, result;\n\n        fprintf(stderr,\n          \"Enter text info (no more than 72 characters per line);\\n\");\n        fprintf(stderr, \"to skip a field, hit the <Enter> key.\\n\");\n        /* note:  just <Enter> leaves len == 1 */\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_TITLE_OFFSET;\n            fprintf(stderr, \"  Title: \");\n            fflush(stderr);\n            if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {\n                if (p[len-1] == '\\n')\n                    p[--len] = '\\0';\n                wpng_info.title = p;\n                wpng_info.have_text |= TEXT_TITLE;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_TITLE;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_TITLE;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_AUTHOR_OFFSET;\n            fprintf(stderr, \"  Author: \");\n            fflush(stderr);\n            if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {\n                if (p[len-1] == '\\n')\n                    p[--len] = '\\0';\n                wpng_info.author = p;\n                wpng_info.have_text |= TEXT_AUTHOR;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_AUTHOR;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_AUTHOR;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_DESC_OFFSET;\n            fprintf(stderr, \"  Description (up to 9 lines):\\n\");\n            for (i = 1;  i < 10;  ++i) {\n                fprintf(stderr, \"    [%d] \", i);\n                fflush(stderr);\n                if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1)\n                    p += len;   /* now points at NULL; char before is newline */\n                else\n                    break;\n            }\n            if ((len = p - (textbuf + TEXT_DESC_OFFSET)) > 1) {\n                if (p[-1] == '\\n') {\n                    p[-1] = '\\0';\n                    --len;\n                }\n                wpng_info.desc = textbuf + TEXT_DESC_OFFSET;\n                wpng_info.have_text |= TEXT_DESC;\n                p = textbuf + TEXT_DESC_OFFSET;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_DESC;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_DESC;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_COPY_OFFSET;\n            fprintf(stderr, \"  Copyright: \");\n            fflush(stderr);\n            if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {\n                if (p[len-1] == '\\n')\n                    p[--len] = '\\0';\n                wpng_info.copyright = p;\n                wpng_info.have_text |= TEXT_COPY;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_COPY;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_COPY;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_EMAIL_OFFSET;\n            fprintf(stderr, \"  E-mail: \");\n            fflush(stderr);\n            if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {\n                if (p[len-1] == '\\n')\n                    p[--len] = '\\0';\n                wpng_info.email = p;\n                wpng_info.have_text |= TEXT_EMAIL;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_EMAIL;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_EMAIL;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n        do {\n            valid = TRUE;\n            p = textbuf + TEXT_URL_OFFSET;\n            fprintf(stderr, \"  URL: \");\n            fflush(stderr);\n            if (FGETS(p, 74, keybd) && (len = strlen(p)) > 1) {\n                if (p[len-1] == '\\n')\n                    p[--len] = '\\0';\n                wpng_info.url = p;\n                wpng_info.have_text |= TEXT_URL;\n                if ((result = wpng_isvalid_latin1((uch *)p, len)) >= 0) {\n                    fprintf(stderr, \"    \" PROGNAME \" warning:  character code\"\n                      \" %u is %sdiscouraged by the PNG\\n    specification \"\n                      \"[first occurrence was at character position #%d]\\n\",\n                      (unsigned)p[result], (p[result] == 27)? \"strongly \" : \"\",\n                      result+1);\n                    fflush(stderr);\n#ifdef FORBID_LATIN1_CTRL\n                    wpng_info.have_text &= ~TEXT_URL;\n                    valid = FALSE;\n#else\n                    if (p[result] == 27) {    /* escape character */\n                        wpng_info.have_text &= ~TEXT_URL;\n                        valid = FALSE;\n                    }\n#endif\n                }\n            }\n        } while (!valid);\n\n#ifndef DOS_OS2_W32\n        fclose(keybd);\n#endif\n\n    } else if (text) {\n        fprintf(stderr, PROGNAME \":  unable to allocate memory for text\\n\");\n        text = FALSE;\n        wpng_info.have_text = 0;\n    }\n\n\n    /* allocate libpng stuff, initialize transformations, write pre-IDAT data */\n\n    if ((rc = writepng_init(&wpng_info)) != 0) {\n        switch (rc) {\n            case 2:\n                fprintf(stderr, PROGNAME\n                  \":  libpng initialization problem (longjmp)\\n\");\n                break;\n            case 4:\n                fprintf(stderr, PROGNAME \":  insufficient memory\\n\");\n                break;\n            case 11:\n                fprintf(stderr, PROGNAME\n                  \":  internal logic error (unexpected PNM type)\\n\");\n                break;\n            default:\n                fprintf(stderr, PROGNAME\n                  \":  unknown writepng_init() error\\n\");\n                break;\n        }\n        exit(rc);\n    }\n\n\n    /* free textbuf, since it's a completely local variable and all text info\n     * has just been written to the PNG file */\n\n    if (text && textbuf) {\n        free(textbuf);\n        textbuf = NULL;\n    }\n\n\n    /* calculate rowbytes on basis of image type; note that this becomes much\n     * more complicated if we choose to support PBM type, ASCII PNM types, or\n     * 16-bit-per-sample binary data [currently not an official NetPBM type] */\n\n    if (wpng_info.pnmtype == 5)\n        rowbytes = wpng_info.width;\n    else if (wpng_info.pnmtype == 6)\n        rowbytes = wpng_info.width * 3;\n    else /* if (wpng_info.pnmtype == 8) */\n        rowbytes = wpng_info.width * 4;\n\n\n    /* read and write the image, either in its entirety (if writing interlaced\n     * PNG) or row by row (if non-interlaced) */\n\n    fprintf(stderr, \"Encoding image data...\\n\");\n    fflush(stderr);\n\n    if (wpng_info.interlaced) {\n        long i;\n        ulg bytes;\n        ulg image_bytes = rowbytes * wpng_info.height;   /* overflow? */\n\n        wpng_info.image_data = (uch *)malloc(image_bytes);\n        wpng_info.row_pointers = (uch **)malloc(wpng_info.height*sizeof(uch *));\n        if (wpng_info.image_data == NULL || wpng_info.row_pointers == NULL) {\n            fprintf(stderr, PROGNAME \":  insufficient memory for image data\\n\");\n            writepng_cleanup(&wpng_info);\n            wpng_cleanup();\n            exit(5);\n        }\n        for (i = 0;  i < wpng_info.height;  ++i)\n            wpng_info.row_pointers[i] = wpng_info.image_data + i*rowbytes;\n        bytes = fread(wpng_info.image_data, 1, image_bytes, wpng_info.infile);\n        if (bytes != image_bytes) {\n            fprintf(stderr, PROGNAME \":  expected %lu bytes, got %lu bytes\\n\",\n              image_bytes, bytes);\n            fprintf(stderr, \"  (continuing anyway)\\n\");\n        }\n        if (writepng_encode_image(&wpng_info) != 0) {\n            fprintf(stderr, PROGNAME\n              \":  libpng problem (longjmp) while writing image data\\n\");\n            writepng_cleanup(&wpng_info);\n            wpng_cleanup();\n            exit(2);\n        }\n\n    } else /* not interlaced:  write progressively (row by row) */ {\n        long j;\n        ulg bytes;\n\n        wpng_info.image_data = (uch *)malloc(rowbytes);\n        if (wpng_info.image_data == NULL) {\n            fprintf(stderr, PROGNAME \":  insufficient memory for row data\\n\");\n            writepng_cleanup(&wpng_info);\n            wpng_cleanup();\n            exit(5);\n        }\n        error = 0;\n        for (j = wpng_info.height;  j > 0L;  --j) {\n            bytes = fread(wpng_info.image_data, 1, rowbytes, wpng_info.infile);\n            if (bytes != rowbytes) {\n                fprintf(stderr, PROGNAME\n                  \":  expected %lu bytes, got %lu bytes (row %ld)\\n\", rowbytes,\n                  bytes, wpng_info.height-j);\n                ++error;\n                break;\n            }\n            if (writepng_encode_row(&wpng_info) != 0) {\n                fprintf(stderr, PROGNAME\n                  \":  libpng problem (longjmp) while writing row %ld\\n\",\n                  wpng_info.height-j);\n                ++error;\n                break;\n            }\n        }\n        if (error) {\n            writepng_cleanup(&wpng_info);\n            wpng_cleanup();\n            exit(2);\n        }\n        if (writepng_encode_finish(&wpng_info) != 0) {\n            fprintf(stderr, PROGNAME \":  error on final libpng call\\n\");\n            writepng_cleanup(&wpng_info);\n            wpng_cleanup();\n            exit(2);\n        }\n    }\n\n\n    /* OK, we're done (successfully):  clean up all resources and quit */\n\n    fprintf(stderr, \"Done.\\n\");\n    fflush(stderr);\n\n    writepng_cleanup(&wpng_info);\n    wpng_cleanup();\n\n    return 0;\n}\n\n\n\n\n\nstatic int wpng_isvalid_latin1(uch *p, int len)\n{\n    int i, result = -1;\n\n    for (i = 0;  i < len;  ++i) {\n        if (p[i] == 10 || (p[i] > 31 && p[i] < 127) || p[i] > 160)\n            continue;           /* character is completely OK */\n        if (result < 0 || (p[result] != 27 && p[i] == 27))\n            result = i;         /* mark location of first questionable one */\n    }                           /*  or of first escape character (bad) */\n\n    return result;\n}\n\n\n\n\n\nstatic void wpng_cleanup(void)\n{\n    if (wpng_info.outfile) {\n        fclose(wpng_info.outfile);\n        wpng_info.outfile = NULL;\n    }\n\n    if (wpng_info.infile) {\n        fclose(wpng_info.infile);\n        wpng_info.infile = NULL;\n    }\n\n    if (wpng_info.image_data) {\n        free(wpng_info.image_data);\n        wpng_info.image_data = NULL;\n    }\n\n    if (wpng_info.row_pointers) {\n        free(wpng_info.row_pointers);\n        wpng_info.row_pointers = NULL;\n    }\n}\n\n\n\n\n#ifdef DOS_OS2_W32\n\nstatic char *dos_kbd_gets(char *buf, int len)\n{\n    int ch, count=0;\n\n    do {\n        buf[count++] = ch = getche();\n    } while (ch != '\\r' && count < len-1);\n\n    buf[count--] = '\\0';        /* terminate string */\n    if (buf[count] == '\\r')     /* Enter key makes CR, so change to newline */\n        buf[count] = '\\n';\n\n    fprintf(stderr, \"\\n\");      /* Enter key does *not* cause a newline */\n    fflush(stderr);\n\n    return buf;\n}\n\n#endif /* DOS_OS2_W32 */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/writepng.c",
    "content": "/*---------------------------------------------------------------------------\n\n   wpng - simple PNG-writing program                             writepng.c\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n\n#include <stdlib.h>     /* for exit() prototype */\n#include <zlib.h>\n\n#include \"png.h\"        /* libpng header, includes setjmp.h */\n#include \"writepng.h\"   /* typedefs, common macros, public prototypes */\n\n\n/* local prototype */\n\nstatic void writepng_error_handler(png_structp png_ptr, png_const_charp msg);\n\n\n\nvoid writepng_version_info(void)\n{\n  fprintf(stderr, \"   Compiled with libpng %s; using libpng %s.\\n\",\n    PNG_LIBPNG_VER_STRING, png_libpng_ver);\n  fprintf(stderr, \"   Compiled with zlib %s; using zlib %s.\\n\",\n    ZLIB_VERSION, zlib_version);\n}\n\n\n\n\n/* returns 0 for success, 2 for libpng problem, 4 for out of memory, 11 for\n *  unexpected pnmtype; note that outfile might be stdout */\n\nint writepng_init(mainprog_info *mainprog_ptr)\n{\n    png_structp  png_ptr;       /* note:  temporary variables! */\n    png_infop  info_ptr;\n    int color_type, interlace_type;\n\n\n    /* could also replace libpng warning-handler (final NULL), but no need: */\n\n    png_ptr = png_create_write_struct(png_get_libpng_ver(NULL), mainprog_ptr,\n      writepng_error_handler, NULL);\n    if (!png_ptr)\n        return 4;   /* out of memory */\n\n    info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr) {\n        png_destroy_write_struct(&png_ptr, NULL);\n        return 4;   /* out of memory */\n    }\n\n\n    /* setjmp() must be called in every function that calls a PNG-writing\n     * libpng function, unless an alternate error handler was installed--\n     * but compatible error handlers must either use longjmp() themselves\n     * (as in this program) or some other method to return control to\n     * application code, so here we go: */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n        return 2;\n    }\n\n\n    /* make sure outfile is (re)opened in BINARY mode */\n\n    png_init_io(png_ptr, mainprog_ptr->outfile);\n\n\n    /* set the compression levels--in general, always want to leave filtering\n     * turned on (except for palette images) and allow all of the filters,\n     * which is the default; want 32K zlib window, unless entire image buffer\n     * is 16K or smaller (unknown here)--also the default; usually want max\n     * compression (NOT the default); and remaining compression flags should\n     * be left alone */\n\n    png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);\n/*\n    >> this is default for no filtering; Z_FILTERED is default otherwise:\n    png_set_compression_strategy(png_ptr, Z_DEFAULT_STRATEGY);\n    >> these are all defaults:\n    png_set_compression_mem_level(png_ptr, 8);\n    png_set_compression_window_bits(png_ptr, 15);\n    png_set_compression_method(png_ptr, 8);\n */\n\n\n    /* set the image parameters appropriately */\n\n    if (mainprog_ptr->pnmtype == 5)\n        color_type = PNG_COLOR_TYPE_GRAY;\n    else if (mainprog_ptr->pnmtype == 6)\n        color_type = PNG_COLOR_TYPE_RGB;\n    else if (mainprog_ptr->pnmtype == 8)\n        color_type = PNG_COLOR_TYPE_RGB_ALPHA;\n    else {\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n        return 11;\n    }\n\n    interlace_type = mainprog_ptr->interlaced? PNG_INTERLACE_ADAM7 :\n                                               PNG_INTERLACE_NONE;\n\n    png_set_IHDR(png_ptr, info_ptr, mainprog_ptr->width, mainprog_ptr->height,\n      mainprog_ptr->sample_depth, color_type, interlace_type,\n      PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);\n\n    if (mainprog_ptr->gamma > 0.0)\n        png_set_gAMA(png_ptr, info_ptr, mainprog_ptr->gamma);\n\n    if (mainprog_ptr->have_bg) {   /* we know it's RGBA, not gray+alpha */\n        png_color_16  background;\n\n        background.red = mainprog_ptr->bg_red;\n        background.green = mainprog_ptr->bg_green;\n        background.blue = mainprog_ptr->bg_blue;\n        png_set_bKGD(png_ptr, info_ptr, &background);\n    }\n\n    if (mainprog_ptr->have_time) {\n        png_time  modtime;\n\n        png_convert_from_time_t(&modtime, mainprog_ptr->modtime);\n        png_set_tIME(png_ptr, info_ptr, &modtime);\n    }\n\n    if (mainprog_ptr->have_text) {\n        png_text  text[6];\n        int  num_text = 0;\n\n        if (mainprog_ptr->have_text & TEXT_TITLE) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"Title\";\n            text[num_text].text = mainprog_ptr->title;\n            ++num_text;\n        }\n        if (mainprog_ptr->have_text & TEXT_AUTHOR) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"Author\";\n            text[num_text].text = mainprog_ptr->author;\n            ++num_text;\n        }\n        if (mainprog_ptr->have_text & TEXT_DESC) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"Description\";\n            text[num_text].text = mainprog_ptr->desc;\n            ++num_text;\n        }\n        if (mainprog_ptr->have_text & TEXT_COPY) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"Copyright\";\n            text[num_text].text = mainprog_ptr->copyright;\n            ++num_text;\n        }\n        if (mainprog_ptr->have_text & TEXT_EMAIL) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"E-mail\";\n            text[num_text].text = mainprog_ptr->email;\n            ++num_text;\n        }\n        if (mainprog_ptr->have_text & TEXT_URL) {\n            text[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n            text[num_text].key = \"URL\";\n            text[num_text].text = mainprog_ptr->url;\n            ++num_text;\n        }\n        png_set_text(png_ptr, info_ptr, text, num_text);\n    }\n\n\n    /* write all chunks up to (but not including) first IDAT */\n\n    png_write_info(png_ptr, info_ptr);\n\n\n    /* if we wanted to write any more text info *after* the image data, we\n     * would set up text struct(s) here and call png_set_text() again, with\n     * just the new data; png_set_tIME() could also go here, but it would\n     * have no effect since we already called it above (only one tIME chunk\n     * allowed) */\n\n\n    /* set up the transformations:  for now, just pack low-bit-depth pixels\n     * into bytes (one, two or four pixels per byte) */\n\n    png_set_packing(png_ptr);\n/*  png_set_shift(png_ptr, &sig_bit);  to scale low-bit-depth values */\n\n\n    /* make sure we save our pointers for use in writepng_encode_image() */\n\n    mainprog_ptr->png_ptr = png_ptr;\n    mainprog_ptr->info_ptr = info_ptr;\n\n\n    /* OK, that's all we need to do for now; return happy */\n\n    return 0;\n}\n\n\n\n\n\n/* returns 0 for success, 2 for libpng (longjmp) problem */\n\nint writepng_encode_image(mainprog_info *mainprog_ptr)\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n\n    /* as always, setjmp() must be called in every function that calls a\n     * PNG-writing libpng function */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n        mainprog_ptr->png_ptr = NULL;\n        mainprog_ptr->info_ptr = NULL;\n        return 2;\n    }\n\n\n    /* and now we just write the whole image; libpng takes care of interlacing\n     * for us */\n\n    png_write_image(png_ptr, mainprog_ptr->row_pointers);\n\n\n    /* since that's it, we also close out the end of the PNG file now--if we\n     * had any text or time info to write after the IDATs, second argument\n     * would be info_ptr, but we optimize slightly by sending NULL pointer: */\n\n    png_write_end(png_ptr, NULL);\n\n    return 0;\n}\n\n\n\n\n\n/* returns 0 if succeeds, 2 if libpng problem */\n\nint writepng_encode_row(mainprog_info *mainprog_ptr)  /* NON-interlaced only! */\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n\n    /* as always, setjmp() must be called in every function that calls a\n     * PNG-writing libpng function */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n        mainprog_ptr->png_ptr = NULL;\n        mainprog_ptr->info_ptr = NULL;\n        return 2;\n    }\n\n\n    /* image_data points at our one row of image data */\n\n    png_write_row(png_ptr, mainprog_ptr->image_data);\n\n    return 0;\n}\n\n\n\n\n\n/* returns 0 if succeeds, 2 if libpng problem */\n\nint writepng_encode_finish(mainprog_info *mainprog_ptr)   /* NON-interlaced! */\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n\n    /* as always, setjmp() must be called in every function that calls a\n     * PNG-writing libpng function */\n\n    if (setjmp(mainprog_ptr->jmpbuf)) {\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n        mainprog_ptr->png_ptr = NULL;\n        mainprog_ptr->info_ptr = NULL;\n        return 2;\n    }\n\n\n    /* close out PNG file; if we had any text or time info to write after\n     * the IDATs, second argument would be info_ptr: */\n\n    png_write_end(png_ptr, NULL);\n\n    return 0;\n}\n\n\n\n\n\nvoid writepng_cleanup(mainprog_info *mainprog_ptr)\n{\n    png_structp png_ptr = (png_structp)mainprog_ptr->png_ptr;\n    png_infop info_ptr = (png_infop)mainprog_ptr->info_ptr;\n\n    if (png_ptr && info_ptr)\n        png_destroy_write_struct(&png_ptr, &info_ptr);\n}\n\n\n\n\n\nstatic void writepng_error_handler(png_structp png_ptr, png_const_charp msg)\n{\n    mainprog_info  *mainprog_ptr;\n\n    /* This function, aside from the extra step of retrieving the \"error\n     * pointer\" (below) and the fact that it exists within the application\n     * rather than within libpng, is essentially identical to libpng's\n     * default error handler.  The second point is critical:  since both\n     * setjmp() and longjmp() are called from the same code, they are\n     * guaranteed to have compatible notions of how big a jmp_buf is,\n     * regardless of whether _BSD_SOURCE or anything else has (or has not)\n     * been defined. */\n\n    fprintf(stderr, \"writepng libpng error: %s\\n\", msg);\n    fflush(stderr);\n\n    mainprog_ptr = png_get_error_ptr(png_ptr);\n    if (mainprog_ptr == NULL) {         /* we are completely hosed now */\n        fprintf(stderr,\n          \"writepng severe error:  jmpbuf not recoverable; terminating.\\n\");\n        fflush(stderr);\n        exit(99);\n    }\n\n    /* Now we have our data structure we can use the information in it\n     * to return control to our own higher level code (all the points\n     * where 'setjmp' is called in this file.)  This will work with other\n     * error handling mechanisms as well - libpng always calls png_error\n     * when it can proceed no further, thus, so long as the error handler\n     * is intercepted, application code can do its own error recovery.\n     */\n    longjmp(mainprog_ptr->jmpbuf, 1);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/gregbook/writepng.h",
    "content": "/*---------------------------------------------------------------------------\n\n   wpng - simple PNG-writing program                             writepng.h\n\n  ---------------------------------------------------------------------------\n\n      Copyright (c) 1998-2007 Greg Roelofs.  All rights reserved.\n\n      This software is provided \"as is,\" without warranty of any kind,\n      express or implied.  In no event shall the author or contributors\n      be held liable for any damages arising in any way from the use of\n      this software.\n\n      The contents of this file are DUAL-LICENSED.  You may modify and/or\n      redistribute this software according to the terms of one of the\n      following two licenses (at your option):\n\n\n      LICENSE 1 (\"BSD-like with advertising clause\"):\n\n      Permission is granted to anyone to use this software for any purpose,\n      including commercial applications, and to alter it and redistribute\n      it freely, subject to the following restrictions:\n\n      1. Redistributions of source code must retain the above copyright\n         notice, disclaimer, and this list of conditions.\n      2. Redistributions in binary form must reproduce the above copyright\n         notice, disclaimer, and this list of conditions in the documenta-\n         tion and/or other materials provided with the distribution.\n      3. All advertising materials mentioning features or use of this\n         software must display the following acknowledgment:\n\n            This product includes software developed by Greg Roelofs\n            and contributors for the book, \"PNG: The Definitive Guide,\"\n            published by O'Reilly and Associates.\n\n\n      LICENSE 2 (GNU GPL v2 or later):\n\n      This program is free software; you can redistribute it and/or modify\n      it under the terms of the GNU General Public License as published by\n      the Free Software Foundation; either version 2 of the License, or\n      (at your option) any later version.\n\n      This program is distributed in the hope that it will be useful,\n      but WITHOUT ANY WARRANTY; without even the implied warranty of\n      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n      GNU General Public License for more details.\n\n      You should have received a copy of the GNU General Public License\n      along with this program; if not, write to the Free Software Foundation,\n      Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\n\n  ---------------------------------------------------------------------------*/\n\n#ifndef TRUE\n#  define TRUE 1\n#  define FALSE 0\n#endif\n\n#ifndef MAX\n#  define MAX(a,b)  ((a) > (b)? (a) : (b))\n#  define MIN(a,b)  ((a) < (b)? (a) : (b))\n#endif\n\n#ifdef DEBUG\n#  define Trace(x)  {fprintf x ; fflush(stderr); fflush(stdout);}\n#else\n#  define Trace(x)  ;\n#endif\n\n#define TEXT_TITLE    0x01\n#define TEXT_AUTHOR   0x02\n#define TEXT_DESC     0x04\n#define TEXT_COPY     0x08\n#define TEXT_EMAIL    0x10\n#define TEXT_URL      0x20\n\n#define TEXT_TITLE_OFFSET        0\n#define TEXT_AUTHOR_OFFSET      72\n#define TEXT_COPY_OFFSET     (2*72)\n#define TEXT_EMAIL_OFFSET    (3*72)\n#define TEXT_URL_OFFSET      (4*72)\n#define TEXT_DESC_OFFSET     (5*72)\n\ntypedef unsigned char   uch;\ntypedef unsigned short  ush;\ntypedef unsigned long   ulg;\n\ntypedef struct _mainprog_info {\n    double gamma;\n    long width;\n    long height;\n    time_t modtime;\n    FILE *infile;\n    FILE *outfile;\n    void *png_ptr;\n    void *info_ptr;\n    uch *image_data;\n    uch **row_pointers;\n    char *title;\n    char *author;\n    char *desc;\n    char *copyright;\n    char *email;\n    char *url;\n    int filter;    /* command-line-filter flag, not PNG row filter! */\n    int pnmtype;\n    int sample_depth;\n    int interlaced;\n    int have_bg;\n    int have_time;\n    int have_text;\n    jmp_buf jmpbuf;\n    uch bg_red;\n    uch bg_green;\n    uch bg_blue;\n} mainprog_info;\n\n\n/* prototypes for public functions in writepng.c */\n\nvoid writepng_version_info(void);\n\nint writepng_init(mainprog_info *mainprog_ptr);\n\nint writepng_encode_image(mainprog_info *mainprog_ptr);\n\nint writepng_encode_row(mainprog_info *mainprog_ptr);\n\nint writepng_encode_finish(mainprog_info *mainprog_ptr);\n\nvoid writepng_cleanup(mainprog_info *mainprog_ptr);\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/INSTALL",
    "content": "Enabling SSE support\n\nCopyright (c) 2016 Google, Inc.\nWritten by Mike Klein, Matt Sarett\n\nThis INSTALL file written by Glenn Randers-Pehrson, 2016.\n\nIf you have moved intel_init.c and filter_sse2_intrinsics.c to a different\ndirectory, be sure to update the '#include \"../../pngpriv.h\"' line in both\nfiles if necessary to point to the correct relative location of pngpriv.h\nwith respect to the new location of those files.\n\nTo enable SSE support in libpng, follow the instructions in I, II, or III,\nbelow:\n\nI. Using patched \"configure\" scripts:\n\nFirst, apply intel_sse.patch in your build directory.\n\n   patch -i contrib/intel/intel_sse.patch -p1\n\nThen, if you are not building in a new GIT clone, e.g., in a tar\ndistribution, remove any existing pre-built configure scripts:\n\n   ./configure --enable-maintainer-mode\n   make maintainer-clean\n   ./autogen.sh --maintainer --clean\n\nFinally, configure libpng with -DPNG_INTEL_SSE in CPPFLAGS:\n\n   ./autogen.sh --maintainer\n   CPPFLAGS=\"-DPNG_INTEL_SSE\" ./configure [options]\n   make CPPFLAGS=\"-DPNG_INTEL_SSE\" [options]\n   make\n\nII. Using a custom makefile:\n\nIf you are using a custom makefile makefile, you will have to update it\nmanually to include contrib/intel/*.o in the dependencies, and to define\nPNG_INTEL_SSE.\n\nIII. Using manually updated \"configure\" scripts:\n\nIf you prefer, manually edit pngpriv.h, configure.ac, and Makefile.am,\nfollowing the instructions below, then follow the instructions in\nsection II of INSTALL in the main libpng directory, then configure libpng\nwith -DPNG_INTEL_SSE in CPPFLAGS.\n\n1. Add the following code to configure.ac under HOST SPECIFIC OPTIONS\ndirectly beneath the section for ARM:\n\n-----------------cut----------------\n# INTEL\n# =====\n#\n# INTEL SSE (SIMD) support.\n\nAC_ARG_ENABLE([intel-sse],\n   AS_HELP_STRING([[[--enable-intel-sse]]],\n      [Enable Intel SSE optimizations: =no/off, yes/on:]\n      [no/off: disable the optimizations;]\n      [yes/on: enable the optimizations.]\n      [If not specified: determined by the compiler.]),\n   [case \"$enableval\" in\n      no|off)\n         # disable the default enabling:\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [0],\n                   [Disable Intel SSE optimizations])\n         # Prevent inclusion of the assembler files below:\n         enable_intel_sse=no;;\n      yes|on)\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [1],\n                   [Enable Intel SSE optimizations]);;\n      *)\n         AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])\n   esac])\n\n# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')\n# or where Intel optimizations were explicitly requested (this allows a\n# fallback if a future host CPU does not match 'x86*')\nAM_CONDITIONAL([PNG_INTEL_SSE],\n   [test \"$enable_intel_sse\" != 'no' &&\n    case \"$host_cpu\" in\n      i?86|x86_64) :;;\n      *)    test \"$enable_intel_sse\" != '';;\n    esac])\n-----------------cut----------------\n\n2. Add the following code to Makefile.am under HOST SPECIFIC OPTIONS\ndirectly beneath the \"if PNG_ARM_NEON ... endif\" statement:\n\n-----------------cut----------------\nif PNG_INTEL_SSE\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\\\n    contrib/intel/filter_sse2_intrinsics.c\nendif\n-----------------cut----------------\n\n3. Add the following lines to pngpriv.h, following the PNG_ARM_NEON_OPT\ncode:\n\n-----------------cut----------------\n#ifndef PNG_INTEL_SSE_OPT\n#   ifdef PNG_INTEL_SSE\n      /* Only check for SSE if the build configuration has been modified to\n       * enable SSE optimizations.  This means that these optimizations will\n       * be off by default.  See contrib/intel for more details.\n       */\n#     if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \\\n       defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n#         define PNG_INTEL_SSE_OPT 1\n#      endif\n#   endif\n#endif\n\n#if PNG_INTEL_SSE_OPT > 0\n#   ifndef PNG_INTEL_SSE_IMPLEMENTATION\n#      if defined(__SSE4_1__) || defined(__AVX__)\n          /* We are not actually using AVX, but checking for AVX is the best\n             way we can detect SSE4.1 and SSSE3 on MSVC.\n          */\n#         define PNG_INTEL_SSE_IMPLEMENTATION 3\n#      elif defined(__SSSE3__)\n#         define PNG_INTEL_SSE_IMPLEMENTATION 2\n#      elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n#         define PNG_INTEL_SSE_IMPLEMENTATION 1\n#      else\n#         define PNG_INTEL_SSE_IMPLEMENTATION 0\n#      endif\n#   endif\n\n#   if PNG_INTEL_SSE_IMPLEMENTATION > 0\n#      define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2\n#   endif\n#endif\n\n-----------------cut----------------\n\n4. Add the following lines to pngpriv.h, following the prototype for\npng_read_filter_row_paeth4_neon:\n\n-----------------cut----------------\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n\n-----------------cut----------------\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/Makefile.am.patch",
    "content": "\n#\n# Copyright (c) 2016 Google, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n\n# In order to compile Intel SSE optimizations for libpng, please add\n# the following code to Makefile.am directly beneath the\n# \"if PNG_ARM_NEON ... endif\" statement.\n\nif PNG_INTEL_SSE\nlibpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\\\n    contrib/intel/filter_sse2_intrinsics.c\nendif\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/configure.ac.patch",
    "content": "#\n# Copyright (c) 2016 Google, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n\n# In order to compile Intel SSE optimizations for libpng, please add\n# the following code to configure.ac under HOST SPECIFIC OPTIONS\n# directly beneath the section for ARM.\n\n# INTEL\n# ===\n#\n# INTEL SSE (SIMD) support.\n\nAC_ARG_ENABLE([intel-sse],\n   AS_HELP_STRING([[[--enable-intel-sse]]],\n      [Enable Intel SSE optimizations: =no/off, yes/on:]\n      [no/off: disable the optimizations;]\n      [yes/on: enable the optimizations.]\n      [If not specified: determined by the compiler.]),\n   [case \"$enableval\" in\n      no|off)\n         # disable the default enabling:\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [0],\n                   [Disable Intel SSE optimizations])\n         # Prevent inclusion of the assembler files below:\n         enable_intel_sse=no;;\n      yes|on)\n         AC_DEFINE([PNG_INTEL_SSE_OPT], [1],\n                   [Enable Intel SSE optimizations]);;\n      *)\n         AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])\n   esac])\n\n# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')\n# or where Intel optimizations were explicitly requested (this allows a\n# fallback if a future host CPU does not match 'x86*')\nAM_CONDITIONAL([PNG_INTEL_SSE],\n   [test \"$enable_intel_sse\" != 'no' &&\n    case \"$host_cpu\" in\n      i?86|x86_64) :;;\n      *)    test \"$enable_intel_sse\" != '';;\n    esac])\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/filter_sse2_intrinsics.c",
    "content": "\n/* filter_sse2_intrinsics.c - SSE2 optimized filter functions\n *\n * Copyright (c) 2016 Google, Inc.\n * Written by Mike Klein and Matt Sarett\n * Derived from arm/filter_neon_intrinsics.c, which was\n * Copyright (c) 2014,2016 Glenn Randers-Pehrson\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"../../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n#if PNG_INTEL_SSE_IMPLEMENTATION > 0\n\n#include <immintrin.h>\n\n/* Functions in this file look at most 3 pixels (a,b,c) to predict the 4th (d).\n * They're positioned like this:\n *    prev:  c b\n *    row:   a d\n * The Sub filter predicts d=a, Avg d=(a+b)/2, and Paeth predicts d to be\n * whichever of a, b, or c is closest to p=a+b-c.\n */\n\nstatic __m128i load4(const void* p) {\n   return _mm_cvtsi32_si128(*(const int*)p);\n}\n\nstatic void store4(void* p, __m128i v) {\n   *(int*)p = _mm_cvtsi128_si32(v);\n}\n\nstatic __m128i load3(const void* p) {\n   /* We'll load 2 bytes, then 1 byte,\n    * then mask them together, and finally load into SSE.\n    */\n   const png_uint_16* p01 = p;\n   const png_byte*    p2  = (const png_byte*)(p01+1);\n\n   png_uint_32 v012 = (png_uint_32)(*p01)\n                    | (png_uint_32)(*p2) << 16;\n   return load4(&v012);\n}\n\nstatic void store3(void* p, __m128i v) {\n   /* We'll pull from SSE as a 32-bit int, then write\n    * its bottom two bytes, then its third byte.\n    */\n   png_uint_32 v012;\n   store4(&v012, v);\n\n   png_uint_16* p01 = p;\n   png_byte*    p2  = (png_byte*)(p01+1);\n   *p01 = v012;\n   *p2  = v012 >> 16;\n}\n\nvoid png_read_filter_row_sub3_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* The Sub filter predicts each pixel as the previous pixel, a.\n    * There is no pixel to the left of the first pixel.  It's encoded directly.\n    * That works with our main loop if we just say that left pixel was zero.\n    */\n   png_debug(1, \"in png_read_filter_row_sub3_sse2\");\n   __m128i a, d = _mm_setzero_si128();\n\n   int rb = row_info->rowbytes;\n   while (rb >= 4) {\n      a = d; d = load4(row);\n      d = _mm_add_epi8(d, a);\n      store3(row, d);\n\n      row += 3;\n      rb  -= 3;\n   }\n   if (rb > 0) {\n      a = d; d = load3(row);\n      d = _mm_add_epi8(d, a);\n      store3(row, d);\n\n      row += 3;\n      rb  -= 3;\n   }\n}\n\nvoid png_read_filter_row_sub4_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* The Sub filter predicts each pixel as the previous pixel, a.\n    * There is no pixel to the left of the first pixel.  It's encoded directly.\n    * That works with our main loop if we just say that left pixel was zero.\n    */\n   png_debug(1, \"in png_read_filter_row_sub4_sse2\");\n   __m128i a, d = _mm_setzero_si128();\n\n   int rb = row_info->rowbytes;\n   while (rb > 0) {\n      a = d; d = load4(row);\n      d = _mm_add_epi8(d, a);\n      store4(row, d);\n\n      row += 4;\n      rb  -= 4;\n   }\n}\n\nvoid png_read_filter_row_avg3_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* The Avg filter predicts each pixel as the (truncated) average of a and b.\n    * There's no pixel to the left of the first pixel.  Luckily, it's\n    * predicted to be half of the pixel above it.  So again, this works\n    * perfectly with our loop if we make sure a starts at zero.\n    */\n   png_debug(1, \"in png_read_filter_row_avg3_sse2\");\n   const __m128i zero = _mm_setzero_si128();\n   __m128i    b;\n   __m128i a, d = zero;\n\n   int rb = row_info->rowbytes;\n   while (rb >= 4) {\n             b = load4(prev);\n      a = d; d = load4(row );\n\n      /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */\n      __m128i avg = _mm_avg_epu8(a,b);\n      /* ...but we can fix it up by subtracting off 1 if it rounded up. */\n      avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),\n                                            _mm_set1_epi8(1)));\n      d = _mm_add_epi8(d, avg);\n      store3(row, d);\n\n      prev += 3;\n      row  += 3;\n      rb   -= 3;\n   }\n   if (rb > 0) {\n             b = load3(prev);\n      a = d; d = load3(row );\n\n      /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */\n      __m128i avg = _mm_avg_epu8(a,b);\n      /* ...but we can fix it up by subtracting off 1 if it rounded up. */\n      avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),\n                                            _mm_set1_epi8(1)));\n\n      d = _mm_add_epi8(d, avg);\n      store3(row, d);\n\n      prev += 3;\n      row  += 3;\n      rb   -= 3;\n   }\n}\n\nvoid png_read_filter_row_avg4_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* The Avg filter predicts each pixel as the (truncated) average of a and b.\n    * There's no pixel to the left of the first pixel.  Luckily, it's\n    * predicted to be half of the pixel above it.  So again, this works\n    * perfectly with our loop if we make sure a starts at zero.\n    */\n   png_debug(1, \"in png_read_filter_row_avg4_sse2\");\n   const __m128i zero = _mm_setzero_si128();\n   __m128i    b;\n   __m128i a, d = zero;\n\n   int rb = row_info->rowbytes;\n   while (rb > 0) {\n             b = load4(prev);\n      a = d; d = load4(row );\n\n      /* PNG requires a truncating average, so we can't just use _mm_avg_epu8 */\n      __m128i avg = _mm_avg_epu8(a,b);\n      /* ...but we can fix it up by subtracting off 1 if it rounded up. */\n      avg = _mm_sub_epi8(avg, _mm_and_si128(_mm_xor_si128(a,b),\n                                            _mm_set1_epi8(1)));\n\n      d = _mm_add_epi8(d, avg);\n      store4(row, d);\n\n      prev += 4;\n      row  += 4;\n      rb   -= 4;\n   }\n}\n\n/* Returns |x| for 16-bit lanes. */\nstatic __m128i abs_i16(__m128i x) {\n#if PNG_INTEL_SSE_IMPLEMENTATION >= 2\n   return _mm_abs_epi16(x);\n#else\n   /* Read this all as, return x<0 ? -x : x.\n   * To negate two's complement, you flip all the bits then add 1.\n    */\n   __m128i is_negative = _mm_cmplt_epi16(x, _mm_setzero_si128());\n\n   /* Flip negative lanes. */\n   x = _mm_xor_si128(x, is_negative);\n\n   /* +1 to negative lanes, else +0. */\n   x = _mm_sub_epi16(x, is_negative);\n   return x;\n#endif\n}\n\n/* Bytewise c ? t : e. */\nstatic __m128i if_then_else(__m128i c, __m128i t, __m128i e) {\n#if PNG_INTEL_SSE_IMPLEMENTATION >= 3\n   return _mm_blendv_epi8(e,t,c);\n#else\n   return _mm_or_si128(_mm_and_si128(c, t), _mm_andnot_si128(c, e));\n#endif\n}\n\nvoid png_read_filter_row_paeth3_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* Paeth tries to predict pixel d using the pixel to the left of it, a,\n    * and two pixels from the previous row, b and c:\n    *   prev: c b\n    *   row:  a d\n    * The Paeth function predicts d to be whichever of a, b, or c is nearest to\n    * p=a+b-c.\n    *\n    * The first pixel has no left context, and so uses an Up filter, p = b.\n    * This works naturally with our main loop's p = a+b-c if we force a and c\n    * to zero.\n    * Here we zero b and d, which become c and a respectively at the start of\n    * the loop.\n    */\n   png_debug(1, \"in png_read_filter_row_paeth3_sse2\");\n   const __m128i zero = _mm_setzero_si128();\n   __m128i c, b = zero,\n           a, d = zero;\n\n   int rb = row_info->rowbytes;\n   while (rb >= 4) {\n      /* It's easiest to do this math (particularly, deal with pc) with 16-bit\n       * intermediates.\n       */\n      c = b; b = _mm_unpacklo_epi8(load4(prev), zero);\n      a = d; d = _mm_unpacklo_epi8(load4(row ), zero);\n\n      /* (p-a) == (a+b-c - a) == (b-c) */\n      __m128i pa = _mm_sub_epi16(b,c);\n\n      /* (p-b) == (a+b-c - b) == (a-c) */\n      __m128i pb = _mm_sub_epi16(a,c);\n\n      /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */\n      __m128i pc = _mm_add_epi16(pa,pb);\n\n      pa = abs_i16(pa);  /* |p-a| */\n      pb = abs_i16(pb);  /* |p-b| */\n      pc = abs_i16(pc);  /* |p-c| */\n\n      __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));\n\n      /* Paeth breaks ties favoring a over b over c. */\n      __m128i nearest  = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,\n                         if_then_else(_mm_cmpeq_epi16(smallest, pb), b,\n                                                                     c));\n\n      /* Note `_epi8`: we need addition to wrap modulo 255. */\n      d = _mm_add_epi8(d, nearest);\n      store3(row, _mm_packus_epi16(d,d));\n\n      prev += 3;\n      row  += 3;\n      rb   -= 3;\n   }\n   if (rb > 0) {\n      /* It's easiest to do this math (particularly, deal with pc) with 16-bit\n       * intermediates.\n       */\n      c = b; b = _mm_unpacklo_epi8(load3(prev), zero);\n      a = d; d = _mm_unpacklo_epi8(load3(row ), zero);\n\n      /* (p-a) == (a+b-c - a) == (b-c) */\n      __m128i pa = _mm_sub_epi16(b,c);\n\n      /* (p-b) == (a+b-c - b) == (a-c) */\n      __m128i pb = _mm_sub_epi16(a,c);\n\n      /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */\n      __m128i pc = _mm_add_epi16(pa,pb);\n\n      pa = abs_i16(pa);  /* |p-a| */\n      pb = abs_i16(pb);  /* |p-b| */\n      pc = abs_i16(pc);  /* |p-c| */\n\n      __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));\n\n      /* Paeth breaks ties favoring a over b over c. */\n      __m128i nearest  = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,\n                         if_then_else(_mm_cmpeq_epi16(smallest, pb), b,\n                                                                     c));\n\n      /* Note `_epi8`: we need addition to wrap modulo 255. */\n      d = _mm_add_epi8(d, nearest);\n      store3(row, _mm_packus_epi16(d,d));\n\n      prev += 3;\n      row  += 3;\n      rb   -= 3;\n   }\n}\n\nvoid png_read_filter_row_paeth4_sse2(png_row_infop row_info, png_bytep row,\n   png_const_bytep prev)\n{\n   /* Paeth tries to predict pixel d using the pixel to the left of it, a,\n    * and two pixels from the previous row, b and c:\n    *   prev: c b\n    *   row:  a d\n    * The Paeth function predicts d to be whichever of a, b, or c is nearest to\n    * p=a+b-c.\n    *\n    * The first pixel has no left context, and so uses an Up filter, p = b.\n    * This works naturally with our main loop's p = a+b-c if we force a and c\n    * to zero.\n    * Here we zero b and d, which become c and a respectively at the start of\n    * the loop.\n    */\n   png_debug(1, \"in png_read_filter_row_paeth4_sse2\");\n   const __m128i zero = _mm_setzero_si128();\n   __m128i c, b = zero,\n           a, d = zero;\n\n   int rb = row_info->rowbytes;\n   while (rb > 0) {\n      /* It's easiest to do this math (particularly, deal with pc) with 16-bit\n       * intermediates.\n       */\n      c = b; b = _mm_unpacklo_epi8(load4(prev), zero);\n      a = d; d = _mm_unpacklo_epi8(load4(row ), zero);\n\n      /* (p-a) == (a+b-c - a) == (b-c) */\n      __m128i pa = _mm_sub_epi16(b,c);\n\n      /* (p-b) == (a+b-c - b) == (a-c) */\n      __m128i pb = _mm_sub_epi16(a,c);\n\n      /* (p-c) == (a+b-c - c) == (a+b-c-c) == (b-c)+(a-c) */\n      __m128i pc = _mm_add_epi16(pa,pb);\n\n      pa = abs_i16(pa);  /* |p-a| */\n      pb = abs_i16(pb);  /* |p-b| */\n      pc = abs_i16(pc);  /* |p-c| */\n\n      __m128i smallest = _mm_min_epi16(pc, _mm_min_epi16(pa, pb));\n\n      /* Paeth breaks ties favoring a over b over c. */\n      __m128i nearest  = if_then_else(_mm_cmpeq_epi16(smallest, pa), a,\n                         if_then_else(_mm_cmpeq_epi16(smallest, pb), b,\n                                                                     c));\n\n      /* Note `_epi8`: we need addition to wrap modulo 255. */\n      d = _mm_add_epi8(d, nearest);\n      store4(row, _mm_packus_epi16(d,d));\n\n      prev += 4;\n      row  += 4;\n      rb   -= 4;\n   }\n}\n\n#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/intel_init.c",
    "content": "\n/* intel_init.c - SSE2 optimized filter functions\n *\n * Copyright (c) 2016 Google, Inc.\n * Written by Mike Klein and Matt Sarett\n * Derived from arm/arm_init.c, which was\n * Copyright (c) 2014,2016 Glenn Randers-Pehrson\n *\n * Last changed in libpng 1.6.22 [May 26, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"../../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n#if PNG_INTEL_SSE_IMPLEMENTATION > 0\n\nvoid\npng_init_filter_functions_sse2(png_structp pp, unsigned int bpp)\n{\n   /* The techniques used to implement each of these filters in SSE operate on\n    * one pixel at a time.\n    * So they generally speed up 3bpp images about 3x, 4bpp images about 4x.\n    * They can scale up to 6 and 8 bpp images and down to 2 bpp images,\n    * but they'd not likely have any benefit for 1bpp images.\n    * Most of these can be implemented using only MMX and 64-bit registers,\n    * but they end up a bit slower than using the equally-ubiquitous SSE2.\n   */\n   png_debug(1, \"in png_init_filter_functions_sse2\");\n   if (bpp == 3)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_sse2;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_sse2;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n         png_read_filter_row_paeth3_sse2;\n   }\n   else if (bpp == 4)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_sse2;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_sse2;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n          png_read_filter_row_paeth4_sse2;\n   }\n\n   /* No need optimize PNG_FILTER_VALUE_UP.  The compiler should\n    * autovectorize.\n    */\n}\n\n#endif /* PNG_INTEL_SSE_IMPLEMENTATION > 0 */\n#endif /* PNG_READ_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/intel/intel_sse.patch",
    "content": "diff --git a/configure.ac b/configure.ac\n--- a/configure.ac\t2016-08-29 11:46:27.000000000 -0400\n+++ b/configure.ac\t2016-08-29 16:57:03.866355018 -0400\n@@ -386,16 +386,51 @@ AC_ARG_ENABLE([mips-msa],\n # future host CPU does not match 'mips*')\n \n AM_CONDITIONAL([PNG_MIPS_MSA],\n    [test \"$enable_mips_msa\" != 'no' &&\n     case \"$host_cpu\" in\n       mipsel*|mips64el*) :;;\n     esac])\n \n+# INTEL\n+# =====\n+#\n+# INTEL SSE (SIMD) support.\n+\n+AC_ARG_ENABLE([intel-sse],\n+   AS_HELP_STRING([[[--enable-intel-sse]]],\n+      [Enable Intel SSE optimizations: =no/off, yes/on:]\n+      [no/off: disable the optimizations;]\n+      [yes/on: enable the optimizations.]\n+      [If not specified: determined by the compiler.]),\n+   [case \"$enableval\" in\n+      no|off)\n+         # disable the default enabling:\n+         AC_DEFINE([PNG_INTEL_SSE_OPT], [0],\n+                   [Disable Intel SSE optimizations])\n+         # Prevent inclusion of the assembler files below:\n+         enable_intel_sse=no;;\n+      yes|on)\n+         AC_DEFINE([PNG_INTEL_SSE_OPT], [1],\n+                   [Enable Intel SSE optimizations]);;\n+      *)\n+         AC_MSG_ERROR([--enable-intel-sse=${enable_intel_sse}: invalid value])\n+   esac])\n+\n+# Add Intel specific files to all builds where the host_cpu is Intel ('x86*')\n+# or where Intel optimizations were explicitly requested (this allows a\n+# fallback if a future host CPU does not match 'x86*')\n+AM_CONDITIONAL([PNG_INTEL_SSE],\n+   [test \"$enable_intel_sse\" != 'no' &&\n+    case \"$host_cpu\" in\n+      i?86|x86_64) :;;\n+      *)    test \"$enable_intel_sse\" != '';;\n+    esac])\n+\n AC_MSG_NOTICE([[Extra options for compiler: $PNG_COPTS]])\n \n # Config files, substituting as above\n AC_CONFIG_FILES([Makefile libpng.pc:libpng.pc.in])\n AC_CONFIG_FILES([libpng-config:libpng-config.in],\n    [chmod +x libpng-config])\n \n AC_OUTPUT\ndiff --git a/Makefile.am b/Makefile.am\n--- a/Makefile.am\t2016-08-29 11:46:27.000000000 -0400\n+++ b/Makefile.am\t2016-08-29 16:57:45.955528215 -0400\n@@ -97,16 +97,21 @@ libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SO\n \tarm/filter_neon.S arm/filter_neon_intrinsics.c\n endif\n \n if PNG_MIPS_MSA\n libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += mips/mips_init.c\\\n \tmips/filter_msa_intrinsics.c\n endif\n \n+if PNG_INTEL_SSE\n+libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES += contrib/intel/intel_init.c\\\n+    contrib/intel/filter_sse2_intrinsics.c\n+endif\n+\n nodist_libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_SOURCES = pnglibconf.h\n \n libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@_la_LDFLAGS = -no-undefined -export-dynamic \\\n \t-version-number @PNGLIB_MAJOR@@PNGLIB_MINOR@:@PNGLIB_RELEASE@:0\n \n if HAVE_LD_VERSION_SCRIPT\n #   Versioned symbols and restricted exports\n if HAVE_SOLARIS_LD\ndiff --git a/pngpriv.h b/pngpriv.h\n--- debug16/pngpriv.h\t2016-08-30 10:46:36.000000000 -0400\n+++ libpng16/pngpriv.h\t2016-08-30 11:57:25.672280202 -0400\n@@ -185,16 +185,52 @@\n #ifndef PNG_MIPS_MSA_OPT\n #  if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)\n #     define PNG_MIPS_MSA_OPT 2\n #  else\n #     define PNG_MIPS_MSA_OPT 0\n #  endif\n #endif\n \n+#ifndef PNG_INTEL_SSE_OPT\n+#   ifdef PNG_INTEL_SSE\n+      /* Only check for SSE if the build configuration has been modified to\n+       * enable SSE optimizations.  This means that these optimizations will\n+       * be off by default.  See contrib/intel for more details.\n+       */\n+#     if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \\\n+       defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n+       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n+#         define PNG_INTEL_SSE_OPT 1\n+#      endif\n+#   endif\n+#endif\n+\n+#if PNG_INTEL_SSE_OPT > 0\n+#   ifndef PNG_INTEL_SSE_IMPLEMENTATION\n+#      if defined(__SSE4_1__) || defined(__AVX__)\n+          /* We are not actually using AVX, but checking for AVX is the best\n+             way we can detect SSE4.1 and SSSE3 on MSVC.\n+          */\n+#         define PNG_INTEL_SSE_IMPLEMENTATION 3\n+#      elif defined(__SSSE3__)\n+#         define PNG_INTEL_SSE_IMPLEMENTATION 2\n+#      elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n+       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n+#         define PNG_INTEL_SSE_IMPLEMENTATION 1\n+#      else\n+#         define PNG_INTEL_SSE_IMPLEMENTATION 0\n+#      endif\n+#   endif\n+\n+#   if PNG_INTEL_SSE_IMPLEMENTATION > 0\n+#      define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2\n+#   endif\n+#endif\n+\n #if PNG_MIPS_MSA_OPT > 0\n #  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa\n #  ifndef PNG_MIPS_MSA_IMPLEMENTATION\n #     if defined(__mips_msa)\n #        if defined(__clang__)\n #        elif defined(__GNUC__)\n #           if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)\n #              define PNG_MIPS_MSA_IMPLEMENTATION 2\n@@ -1232,16 +1268,31 @@ PNG_INTERNAL_FUNCTION(void,png_read_filt\n PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop\n     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop\n     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop\n     row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n #endif\n \n+#if PNG_INTEL_SSE_IMPLEMENTATION > 0\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+PNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop\n+    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n+#endif\n+\n /* Choose the best filter to use and filter the row data */\n PNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,\n     png_row_infop row_info),PNG_EMPTY);\n \n #ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n PNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr,\n    png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY);\n    /* Read 'avail_out' bytes of data from the IDAT stream.  If the output buffer\n@@ -1967,16 +2018,21 @@ PNG_INTERNAL_FUNCTION(void, PNG_FILTER_O\n PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,\n    (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n #endif\n \n #if PNG_MIPS_MSA_OPT > 0\n PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,\n    (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n #endif\n+\n+#  if PNG_INTEL_SSE_IMPLEMENTATION > 0\n+PNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,\n+   (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n+#  endif\n #endif\n \n PNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,\n    png_const_charp key, png_bytep new_key), PNG_EMPTY);\n \n /* Maintainer: Put new private prototypes here ^ */\n \n #include \"pngdebug.h\"\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/fakepng.c",
    "content": "/* Fake a PNG - just write it out directly.\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2014.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n */\n\n#include <stdio.h>\n#include <zlib.h> /* for crc32 */\n\nvoid\nput_uLong(uLong val)\n{\n   putchar(val >> 24);\n   putchar(val >> 16);\n   putchar(val >>  8);\n   putchar(val >>  0);\n}\n\nvoid\nput_chunk(const unsigned char *chunk, uInt length)\n{\n   uLong crc;\n\n   put_uLong(length-4); /* Exclude the tag */\n\n   fwrite(chunk, length, 1, stdout);\n\n   crc = crc32(0, Z_NULL, 0);\n   put_uLong(crc32(crc, chunk, length));\n}\n\nconst unsigned char signature[] =\n{\n   137, 80, 78, 71, 13, 10, 26, 10\n};\n\nconst unsigned char IHDR[] =\n{\n   73, 72, 68, 82, /* IHDR */\n   0, 0, 0, 1, /* width */\n   0, 0, 0, 1, /* height */\n   1, /* bit depth */\n   0, /* color type: greyscale */\n   0, /* compression method */\n   0, /* filter method */\n   0  /* interlace method: none */\n};\n\nconst unsigned char unknown[] =\n{\n   'u', 'n', 'K', 'n' /* \"unKn\" - private safe to copy */\n};\n\nint\nmain(void)\n{\n   fwrite(signature, sizeof signature, 1, stdout);\n   put_chunk(IHDR, sizeof IHDR);\n\n   for (;;)\n      put_chunk(unknown, sizeof unknown);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/gentests.sh",
    "content": "#!/bin/sh\n#\n# Copyright (c) 2013 John Cunningham Bowler\n#\n# Last changed in libpng 1.6.0 [February 14, 2013]\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Generate a set of PNG test images.  The images are generated in a\n# sub-directory called 'tests' by default, however a command line argument will\n# change that name.  The generation requires a built version of makepng in the\n# current directory.\n#\nusage(){\n   exec >&2\n   echo \"$0 [<directory>]\"\n   echo '  Generate a set of PNG test files in \"directory\" (\"tests\" by default)'\n   exit 1\n}\n\nmp=\"$PWD/makepng\"\ntest -x \"$mp\" || {\n   exec >&2\n   echo \"$0: the 'makepng' program must exist\"\n   echo \"  in the directory within which this program:\"\n   echo \"    $mp\"\n   echo \"  is executed\"\n   usage\n}\n\n# Just one argument: the directory\ntestdir=\"tests\"\ntest $# -gt 1 && {\n   testdir=\"$1\"\n   shift\n}\ntest $# -eq 0 || usage\n\n# Take care not to clobber something\nif test -e \"$testdir\"\nthen\n   test -d \"$testdir\" || usage\nelse\n   # mkdir -p isn't portable, so do the following\n   mkdir \"$testdir\" 2>/dev/null || mkdir -p \"$testdir\" || usage\nfi\n\n# This fails in a very satisfactory way if it's not accessible\ncd \"$testdir\"\n:>\"test$$.png\" || {\n   exec >&2\n   echo \"$testdir: directory not writable\"\n   usage\n}\nrm \"test$$.png\" || {\n   exec >&2\n   echo \"$testdir: you have create but not write privileges here.\"\n   echo \"  This is unexpected.  You have a spurion; \"'\"'\"test$$.png\"'\"'\".\"\n   echo \"  You need to remove this yourself.  Try a different directory.\"\n   exit 1\n}\n\n# Now call makepng ($mp) to create every file we can think of with a\n# reasonable name\ndoit(){\n   for gamma in \"\" --sRGB --linear --1.8\n   do\n      case \"$gamma\" in\n         \"\")\n            gname=;;\n         --sRGB)\n            gname=\"-srgb\";;\n         --linear)\n            gname=\"-lin\";;\n         --1.8)\n            gname=\"-18\";;\n         *)\n            gname=\"-$gamma\";;\n      esac\n      \"$mp\" $gamma \"$1\" \"$2\" \"test-$1-$2$gname.png\"\n   done\n}\n#\nfor ct in gray palette\ndo\n   for bd in 1 2 4 8\n   do\n      doit \"$ct\" \"$bd\"\n   done\ndone\n#\ndoit \"gray\" \"16\"\n#\nfor ct in gray-alpha rgb rgb-alpha\ndo\n   for bd in 8 16\n   do\n      doit \"$ct\" \"$bd\"\n   done\ndone\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/makepng.c",
    "content": "/* makepng.c */\n#define _ISOC99_SOURCE\n/* Copyright: */\n#define COPYRIGHT \"\\251 2013,2015 John Cunningham Bowler\"\n/*\n * Last changed in libpng 1.6.20 [November 24, 2015]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Make a test PNG image.  The arguments are as follows:\n *\n *    makepng [--sRGB|--linear|--1.8] [--tRNS] [--nofilters] \\\n *       color-type bit-depth [file-name]\n *\n * The color-type may be numeric (and must match the numbers used by the PNG\n * specification) or one of the format names listed below.  The bit-depth is the\n * component bit depth, or the pixel bit-depth for a color-mapped image.\n *\n * Without any options no color-space information is written, with the options\n * an sRGB or the appropriate gAMA chunk is written.  \"1.8\" refers to the\n * display system used on older Apple computers to correct for high ambient\n * light levels in the viewing environment; it applies a transform of\n * approximately value^(1/1.45) to the color values and so a gAMA chunk of 65909\n * is written (1.45/2.2).\n *\n * The image data is generated internally.  Unless --color is given the images\n * used are as follows:\n *\n * 1 channel: a square image with a diamond, the least luminous colors are on\n *    the edge of the image, the most luminous in the center.\n *\n * 2 channels: the color channel increases in luminosity from top to bottom, the\n *    alpha channel increases in opacity from left to right.\n *\n * 3 channels: linear combinations of, from the top-left corner clockwise,\n *    black, green, white, red.\n *\n * 4 channels: linear combinations of, from the top-left corner clockwise,\n *    transparent, red, green, blue.\n *\n * For color-mapped images a four channel color-map is used and if --tRNS is\n * given the PNG file has a tRNS chunk, as follows:\n *\n * 1-bit: entry 0 is transparent-red, entry 1 is opaque-white\n * 2-bit: entry 0: transparent-green\n *        entry 1: 40%-red\n *        entry 2: 80%-blue\n *        entry 3: opaque-white\n * 4-bit: the 16 combinations of the 2-bit case\n * 8-bit: the 256 combinations of the 4-bit case\n *\n * The palette always has 2^bit-depth entries and the tRNS chunk one fewer.  The\n * image is the 1-channel diamond, but using palette index, not luminosity.\n *\n * For formats other than color-mapped ones if --tRNS is specified a tRNS chunk\n * is generated with all channels equal to the low bits of 0x0101.\n *\n * Image size is determined by the final pixel depth in bits, i.e. channels x\n * bit-depth, as follows:\n *\n * 8 bits or less:    64x64\n * 16 bits:           256x256\n * More than 16 bits: 1024x1024\n *\n * Row filtering is the libpng default but may be turned off (the 'none' filter\n * is used on every row) with the --nofilters option.\n *\n * The images are not interlaced.\n *\n * If file-name is given then the PNG is written to that file, else it is\n * written to stdout.  Notice that stdout is not supported on systems where, by\n * default, it assumes text output; this program makes no attempt to change the\n * text mode of stdout!\n *\n *    makepng --color=<color> ...\n *\n * If --color is given then the whole image has that color, color-mapped images\n * will have exactly one palette entry and all image files with be 16x16 in\n * size.  The color value is 1 to 4 decimal numbers as appropriate for the color\n * type.\n *\n *    makepng --small ...\n *\n * If --small is given the images are no larger than required to include every\n * possible pixel value for the format.\n *\n * For formats with pixels 8 bits or fewer in size the images consist of a\n * single row with 2^pixel-depth pixels, one of every possible value.\n *\n * For formats with 16-bit pixels a 256x256 image is generated containing every\n * possible pixel value.\n *\n * For larger pixel sizes a 256x256 image is generated where the first row\n * consists of each pixel that has identical byte values throughout the pixel\n * followed by rows where the byte values differ within the pixel.\n *\n * In all cases the pixel values are arranged in such a way that the SUB and UP\n * filters give byte sequences for maximal zlib compression.  By default (if\n * --nofilters is not given) the SUB filter is used on the first row and the UP\n * filter on all following rows.\n *\n * The --small option is meant to provide good test-case coverage, however the\n * images are not easy to examine visually.  Without the --small option the\n * images contain identical color values; the pixel values are adjusted\n * according to the gamma encoding with no gamma encoding being interpreted as\n * sRGB.\n *\n * LICENSING\n * =========\n *\n * This code is copyright of the authors, see the COPYRIGHT define above.  The\n * code is licensed as above, using the libpng license.  The code generates\n * images which are solely the product of the code; the options choose which of\n * the many possibilities to generate.  The images that result (but not the code\n * which generates them) are licensed as defined here:\n *\n * IMPORTANT: the COPYRIGHT #define must contain ISO-Latin-1 characters, the\n * IMAGE_LICENSING #define must contain UTF-8 characters.  The 'copyright'\n * symbol 0xA9U (\\251) in ISO-Latin-1 encoding and 0xC20xA9 (\\302\\251) in UTF-8.\n */\n#define IMAGE_LICENSING \"Dedicated to the public domain per Creative Commons \"\\\n    \"license \\\"CC0 1.0\\\"; https://creativecommons.org/publicdomain/zero/1.0/\"\n\n#include <stddef.h> /* for offsetof */\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <math.h>\n#include <errno.h>\n#include <assert.h>\n#include <stdint.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n#include <zlib.h>\n\n/* Work round for GCC complaints about casting a (double) function result to\n * an unsigned:\n */\nstatic unsigned int\nflooru(double d)\n{\n   d = floor(d);\n   return (unsigned int)d;\n}\n\nstatic png_byte\nfloorb(double d)\n{\n   d = floor(d);\n   return (png_byte)d;\n}\n\n/* This structure is used for inserting extra chunks (the --insert argument, not\n * documented above.)\n */\ntypedef struct chunk_insert\n{\n   struct chunk_insert *next;\n   void               (*insert)(png_structp, png_infop, int, png_charpp);\n   int                  nparams;\n   png_charp            parameters[1];\n} chunk_insert;\n\nstatic unsigned int\nchannels_of_type(int color_type)\n{\n   if (color_type & PNG_COLOR_MASK_PALETTE)\n      return 1;\n\n   else\n   {\n      int channels = 1;\n\n      if (color_type & PNG_COLOR_MASK_COLOR)\n         channels = 3;\n\n      if (color_type & PNG_COLOR_MASK_ALPHA)\n         return channels + 1;\n\n      else\n         return channels;\n   }\n}\n\nstatic unsigned int\npixel_depth_of_type(int color_type, int bit_depth)\n{\n   return channels_of_type(color_type) * bit_depth;\n}\n\nstatic unsigned int\nimage_size_of_type(int color_type, int bit_depth, unsigned int *colors,\n   int small)\n{\n   if (*colors)\n      return 16;\n\n   else\n   {\n      int pixel_depth = pixel_depth_of_type(color_type, bit_depth);\n\n      if (small)\n      {\n         if (pixel_depth <= 8) /* there will be one row */\n            return 1 << pixel_depth;\n\n         else\n            return 256;\n      }\n\n      else if (pixel_depth < 8)\n         return 64;\n\n      else if (pixel_depth > 16)\n         return 1024;\n\n      else\n         return 256;\n   }\n}\n\nstatic void\nset_color(png_colorp color, png_bytep trans, unsigned int red,\n   unsigned int green, unsigned int blue, unsigned int alpha,\n   png_const_bytep gamma_table)\n{\n   color->red = gamma_table[red];\n   color->green = gamma_table[green];\n   color->blue = gamma_table[blue];\n   *trans = (png_byte)alpha;\n}\n\nstatic int\ngenerate_palette(png_colorp palette, png_bytep trans, int bit_depth,\n   png_const_bytep gamma_table, unsigned int *colors)\n{\n   /*\n    * 1-bit: entry 0 is transparent-red, entry 1 is opaque-white\n    * 2-bit: entry 0: transparent-green\n    *        entry 1: 40%-red\n    *        entry 2: 80%-blue\n    *        entry 3: opaque-white\n    * 4-bit: the 16 combinations of the 2-bit case\n    * 8-bit: the 256 combinations of the 4-bit case\n    */\n   switch (colors[0])\n   {\n      default:\n         fprintf(stderr, \"makepng: --colors=...: invalid count %u\\n\",\n            colors[0]);\n         exit(1);\n\n      case 1:\n         set_color(palette+0, trans+0, colors[1], colors[1], colors[1], 255,\n            gamma_table);\n         return 1;\n\n      case 2:\n         set_color(palette+0, trans+0, colors[1], colors[1], colors[1],\n            colors[2], gamma_table);\n         return 1;\n\n      case 3:\n         set_color(palette+0, trans+0, colors[1], colors[2], colors[3], 255,\n            gamma_table);\n         return 1;\n\n      case 4:\n         set_color(palette+0, trans+0, colors[1], colors[2], colors[3],\n            colors[4], gamma_table);\n         return 1;\n\n      case 0:\n         if (bit_depth == 1)\n         {\n            set_color(palette+0, trans+0, 255, 0, 0, 0, gamma_table);\n            set_color(palette+1, trans+1, 255, 255, 255, 255, gamma_table);\n            return 2;\n         }\n\n         else\n         {\n            unsigned int size = 1U << (bit_depth/2); /* 2, 4 or 16 */\n            unsigned int x, y;\n            volatile unsigned int ip = 0;\n\n            for (x=0; x<size; ++x) for (y=0; y<size; ++y)\n            {\n               ip = x + (size * y);\n\n               /* size is at most 16, so the scaled value below fits in 16 bits\n                */\n#              define interp(pos, c1, c2) ((pos * c1) + ((size-pos) * c2))\n#              define xyinterp(x, y, c1, c2, c3, c4) (((size * size / 2) +\\\n                  (interp(x, c1, c2) * y + (size-y) * interp(x, c3, c4))) /\\\n                  (size*size))\n\n               set_color(palette+ip, trans+ip,\n                  /* color:    green, red,blue,white */\n                  xyinterp(x, y,   0, 255,   0, 255),\n                  xyinterp(x, y, 255,   0,   0, 255),\n                  xyinterp(x, y,   0,   0, 255, 255),\n                  /* alpha:        0, 102, 204, 255) */\n                  xyinterp(x, y,   0, 102, 204, 255),\n                  gamma_table);\n            }\n\n            return ip+1;\n         }\n   }\n}\n\nstatic void\nset_value(png_bytep row, size_t rowbytes, png_uint_32 x, unsigned int bit_depth,\n   png_uint_32 value, png_const_bytep gamma_table, double conv)\n{\n   unsigned int mask = (1U << bit_depth)-1;\n\n   x *= bit_depth;  /* Maximum x is 4*1024, maximum bit_depth is 16 */\n\n   if (value <= mask)\n   {\n      png_uint_32 offset = x >> 3;\n\n      if (offset < rowbytes && (bit_depth < 16 || offset+1 < rowbytes))\n      {\n         row += offset;\n\n         switch (bit_depth)\n         {\n            case 1:\n            case 2:\n            case 4:\n               /* Don't gamma correct - values get smashed */\n               {\n                  unsigned int shift = (8 - bit_depth) - (x & 0x7U);\n\n                  mask <<= shift;\n                  value = (value << shift) & mask;\n                  *row = (png_byte)((*row & ~mask) | value);\n               }\n               return;\n\n            default:\n               fprintf(stderr, \"makepng: bad bit depth (internal error)\\n\");\n               exit(1);\n\n            case 16:\n               value = flooru(65535*pow(value/65535.,conv)+.5);\n               *row++ = (png_byte)(value >> 8);\n               *row = (png_byte)value;\n               return;\n\n            case 8:\n               *row = gamma_table[value];\n               return;\n         }\n      }\n\n      else\n      {\n         fprintf(stderr, \"makepng: row buffer overflow (internal error)\\n\");\n         exit(1);\n      }\n   }\n\n   else\n   {\n      fprintf(stderr, \"makepng: component overflow (internal error)\\n\");\n      exit(1);\n   }\n}\n\nstatic int /* filter mask for row */\ngenerate_row(png_bytep row, size_t rowbytes, unsigned int y, int color_type,\n   int bit_depth, png_const_bytep gamma_table, double conv,\n   unsigned int *colors, int small)\n{\n   int filters = 0; /* file *MASK*, 0 means the default, not NONE */\n   png_uint_32 size_max =\n      image_size_of_type(color_type, bit_depth, colors, small)-1;\n   png_uint_32 depth_max = (1U << bit_depth)-1; /* up to 65536 */\n\n   if (colors[0] == 0) if (small)\n   {\n      unsigned int pixel_depth = pixel_depth_of_type(color_type, bit_depth);\n\n      /* For pixel depths less than 16 generate a single row containing all the\n       * possible pixel values.  For 16 generate all 65536 byte pair\n       * combinations in a 256x256 pixel array.\n       */\n      switch (pixel_depth)\n      {\n         case 1:\n            assert(y == 0 && rowbytes == 1 && size_max == 1);\n            row[0] = 0x6CU; /* binary: 01101100, only top 2 bits used */\n            filters = PNG_FILTER_NONE;\n            break;\n\n         case 2:\n            assert(y == 0 && rowbytes == 1 && size_max == 3);\n            row[0] = 0x1BU; /* binary 00011011, all bits used */\n            filters = PNG_FILTER_NONE;\n            break;\n\n         case 4:\n            assert(y == 0 && rowbytes == 8 && size_max == 15);\n            row[0] = 0x01U;\n            row[1] = 0x23U; /* SUB gives 0x22U for all following bytes */\n            row[2] = 0x45U;\n            row[3] = 0x67U;\n            row[4] = 0x89U;\n            row[5] = 0xABU;\n            row[6] = 0xCDU;\n            row[7] = 0xEFU;\n            filters = PNG_FILTER_SUB;\n            break;\n\n         case 8:\n            /* The row will have all the pixel values in order starting with\n             * '1', the SUB filter will change every byte into '1' (including\n             * the last, which generates pixel value '0').  Since the SUB filter\n             * has value 1 this should result in maximum compression.\n             */\n            assert(y == 0 && rowbytes == 256 && size_max == 255);\n            for (;;)\n            {\n               row[size_max] = 0xFFU & (size_max+1);\n               if (size_max == 0)\n                  break;\n               --size_max;\n            }\n            filters = PNG_FILTER_SUB;\n            break;\n\n         case 16:\n            /* Rows are generated such that each row has a constant difference\n             * between the first and second byte of each pixel and so that the\n             * difference increases by 1 at each row.  The rows start with the\n             * first byte value of 0 and the value increases to 255 across the\n             * row.\n             *\n             * The difference starts at 1, so the first row is:\n             *\n             *     0 1 1 2 2 3 3 4 ... 254 255 255 0\n             *\n             * This means that running the SUB filter on the first row produces:\n             *\n             *   [SUB==1] 0 1 0 1 0 1...\n             *\n             * Then the difference is 2 on the next row, giving:\n             *\n             *    0 2 1 3 2 4 3 5 ... 254 0 255 1\n             *\n             * When the UP filter is run on this libpng produces:\n             *\n             *   [UP ==2] 0 1 0 1 0 1...\n             *\n             * And so on for all the remain rows to the final two * rows:\n             *\n             *    row 254: 0 255 1 0 2 1 3 2 4 3 ... 254 253 255 254\n             *    row 255: 0   0 1 1 2 2 3 3 4 4 ... 254 254 255 255\n             */\n            assert(rowbytes == 512 && size_max == 255);\n            for (;;)\n            {\n               row[2*size_max  ] = 0xFFU & size_max;\n               row[2*size_max+1] = 0xFFU & (size_max+y+1);\n               if (size_max == 0)\n                  break;\n               --size_max;\n            }\n            /* The first row must include PNG_FILTER_UP so that libpng knows we\n             * need to keep it for the following row:\n             */\n            filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP);\n            break;\n\n         case 24:\n         case 32:\n         case 48:\n         case 64:\n            /* The rows are filled by an alogorithm similar to the above, in the\n             * first row pixel bytes are all equal, increasing from 0 by 1 for\n             * each pixel.  In the second row the bytes within a pixel are\n             * incremented 1,3,5,7,... from the previous row byte.  Using an odd\n             * number ensures all the possible byte values are used.\n             */\n            assert(size_max == 255 && rowbytes == 256*(pixel_depth>>3));\n            pixel_depth >>= 3; /* now in bytes */\n            while (rowbytes > 0)\n            {\n               const size_t pixel_index = --rowbytes/pixel_depth;\n\n               if (y == 0)\n                  row[rowbytes] = 0xFFU & pixel_index;\n\n               else\n               {\n                  const size_t byte_offset =\n                     rowbytes - pixel_index * pixel_depth;\n\n                  row[rowbytes] =\n                     0xFFU & (pixel_index + (byte_offset * 2*y) + 1);\n               }\n            }\n            filters = (y == 0 ? PNG_FILTER_SUB+PNG_FILTER_UP : PNG_FILTER_UP);\n            break;\n\n         default:\n            assert(0/*NOT REACHED*/);\n      }\n   }\n\n   else switch (channels_of_type(color_type))\n   {\n   /* 1 channel: a square image with a diamond, the least luminous colors are on\n    *    the edge of the image, the most luminous in the center.\n    */\n      case 1:\n         {\n            png_uint_32 x;\n            png_uint_32 base = 2*size_max - abs(2*y-size_max);\n\n            for (x=0; x<=size_max; ++x)\n            {\n               png_uint_32 luma = base - abs(2*x-size_max);\n\n               /* 'luma' is now in the range 0..2*size_max, we need\n                * 0..depth_max\n                */\n               luma = (luma*depth_max + size_max) / (2*size_max);\n               set_value(row, rowbytes, x, bit_depth, luma, gamma_table, conv);\n            }\n         }\n         break;\n\n   /* 2 channels: the color channel increases in luminosity from top to bottom,\n    *    the alpha channel increases in opacity from left to right.\n    */\n      case 2:\n         {\n            png_uint_32 alpha = (depth_max * y * 2 + size_max) / (2 * size_max);\n            png_uint_32 x;\n\n            for (x=0; x<=size_max; ++x)\n            {\n               set_value(row, rowbytes, 2*x, bit_depth,\n                  (depth_max * x * 2 + size_max) / (2 * size_max), gamma_table,\n                  conv);\n               set_value(row, rowbytes, 2*x+1, bit_depth, alpha, gamma_table,\n                  conv);\n            }\n         }\n         break;\n\n   /* 3 channels: linear combinations of, from the top-left corner clockwise,\n    *    black, green, white, red.\n    */\n      case 3:\n         {\n            /* x0: the black->red scale (the value of the red component) at the\n             *     start of the row (blue and green are 0).\n             * x1: the green->white scale (the value of the red and blue\n             *     components at the end of the row; green is depth_max).\n             */\n            png_uint_32 Y = (depth_max * y * 2 + size_max) / (2 * size_max);\n            png_uint_32 x;\n\n            /* Interpolate x/depth_max from start to end:\n             *\n             *        start end         difference\n             * red:     Y    Y            0\n             * green:   0   depth_max   depth_max\n             * blue:    0    Y            Y\n             */\n            for (x=0; x<=size_max; ++x)\n            {\n               set_value(row, rowbytes, 3*x+0, bit_depth, /* red */ Y,\n                     gamma_table, conv);\n               set_value(row, rowbytes, 3*x+1, bit_depth, /* green */\n                  (depth_max * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n               set_value(row, rowbytes, 3*x+2, bit_depth, /* blue */\n                  (Y * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n            }\n         }\n         break;\n\n   /* 4 channels: linear combinations of, from the top-left corner clockwise,\n    *    transparent, red, green, blue.\n    */\n      case 4:\n         {\n            /* x0: the transparent->blue scale (the value of the blue and alpha\n             *     components) at the start of the row (red and green are 0).\n             * x1: the red->green scale (the value of the red and green\n             *     components at the end of the row; blue is 0 and alpha is\n             *     depth_max).\n             */\n            png_uint_32 Y = (depth_max * y * 2 + size_max) / (2 * size_max);\n            png_uint_32 x;\n\n            /* Interpolate x/depth_max from start to end:\n             *\n             *        start    end       difference\n             * red:     0   depth_max-Y depth_max-Y\n             * green:   0       Y             Y\n             * blue:    Y       0            -Y\n             * alpha:   Y    depth_max  depth_max-Y\n             */\n            for (x=0; x<=size_max; ++x)\n            {\n               set_value(row, rowbytes, 4*x+0, bit_depth, /* red */\n                  ((depth_max-Y) * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n               set_value(row, rowbytes, 4*x+1, bit_depth, /* green */\n                  (Y * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n               set_value(row, rowbytes, 4*x+2, bit_depth, /* blue */\n                  Y - (Y * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n               set_value(row, rowbytes, 4*x+3, bit_depth, /* alpha */\n                  Y + ((depth_max-Y) * x * 2 + size_max) / (2 * size_max),\n                  gamma_table, conv);\n            }\n         }\n         break;\n\n      default:\n         fprintf(stderr, \"makepng: internal bad channel count\\n\");\n         exit(2);\n   }\n\n   else if (color_type & PNG_COLOR_MASK_PALETTE)\n   {\n      /* Palette with fixed color: the image rows are all 0 and the image width\n       * is 16.\n       */\n      memset(row, 0, rowbytes);\n   }\n\n   else if (colors[0] == channels_of_type(color_type))\n      switch (channels_of_type(color_type))\n      {\n         case 1:\n            {\n               const png_uint_32 luma = colors[1];\n               png_uint_32 x;\n\n               for (x=0; x<=size_max; ++x)\n                  set_value(row, rowbytes, x, bit_depth, luma, gamma_table,\n                     conv);\n            }\n            break;\n\n         case 2:\n            {\n               const png_uint_32 luma = colors[1];\n               const png_uint_32 alpha = colors[2];\n               png_uint_32 x;\n\n               for (x=0; x<size_max; ++x)\n               {\n                  set_value(row, rowbytes, 2*x, bit_depth, luma, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 2*x+1, bit_depth, alpha, gamma_table,\n                     conv);\n               }\n            }\n            break;\n\n         case 3:\n            {\n               const png_uint_32 red = colors[1];\n               const png_uint_32 green = colors[2];\n               const png_uint_32 blue = colors[3];\n               png_uint_32 x;\n\n               for (x=0; x<=size_max; ++x)\n               {\n                  set_value(row, rowbytes, 3*x+0, bit_depth, red, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 3*x+1, bit_depth, green, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 3*x+2, bit_depth, blue, gamma_table,\n                     conv);\n               }\n            }\n            break;\n\n         case 4:\n            {\n               const png_uint_32 red = colors[1];\n               const png_uint_32 green = colors[2];\n               const png_uint_32 blue = colors[3];\n               const png_uint_32 alpha = colors[4];\n               png_uint_32 x;\n\n               for (x=0; x<=size_max; ++x)\n               {\n                  set_value(row, rowbytes, 4*x+0, bit_depth, red, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 4*x+1, bit_depth, green, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 4*x+2, bit_depth, blue, gamma_table,\n                     conv);\n                  set_value(row, rowbytes, 4*x+3, bit_depth, alpha, gamma_table,\n                     conv);\n               }\n            }\n         break;\n\n         default:\n            fprintf(stderr, \"makepng: internal bad channel count\\n\");\n            exit(2);\n      }\n\n   else\n   {\n      fprintf(stderr,\n         \"makepng: --color: count(%u) does not match channels(%u)\\n\",\n         colors[0], channels_of_type(color_type));\n      exit(1);\n   }\n\n   return filters;\n}\n\n\nstatic void PNGCBAPI\nmakepng_warning(png_structp png_ptr, png_const_charp message)\n{\n   const char **ep = png_get_error_ptr(png_ptr);\n   const char *name;\n\n   if (ep != NULL && *ep != NULL)\n      name = *ep;\n\n   else\n      name = \"makepng\";\n\n  fprintf(stderr, \"%s: warning: %s\\n\", name, message);\n}\n\nstatic void PNGCBAPI\nmakepng_error(png_structp png_ptr, png_const_charp message)\n{\n   makepng_warning(png_ptr, message);\n   png_longjmp(png_ptr, 1);\n}\n\nstatic int /* 0 on success, else an error code */\nwrite_png(const char **name, FILE *fp, int color_type, int bit_depth,\n   volatile png_fixed_point gamma, chunk_insert * volatile insert,\n   unsigned int filters, unsigned int *colors, int small, int tRNS)\n{\n   png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,\n      name, makepng_error, makepng_warning);\n   volatile png_infop info_ptr = NULL;\n   volatile png_bytep row = NULL;\n\n   if (png_ptr == NULL)\n   {\n      fprintf(stderr, \"makepng: OOM allocating write structure\\n\");\n      return 1;\n   }\n\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      png_structp nv_ptr = png_ptr;\n      png_infop nv_info = info_ptr;\n\n      png_ptr = NULL;\n      info_ptr = NULL;\n      png_destroy_write_struct(&nv_ptr, &nv_info);\n      if (row != NULL) free(row);\n      return 1;\n   }\n\n   /* Allow benign errors so that we can write PNGs with errors */\n   png_set_benign_errors(png_ptr, 1/*allowed*/);\n\n   /* Max out the text compression level in an attempt to make the license\n    * small.   If --small then do the same for the IDAT.\n    */\n   if (small)\n      png_set_compression_level(png_ptr, Z_BEST_COMPRESSION);\n\n   png_set_text_compression_level(png_ptr, Z_BEST_COMPRESSION);\n\n   png_init_io(png_ptr, fp);\n\n   info_ptr = png_create_info_struct(png_ptr);\n   if (info_ptr == NULL)\n      png_error(png_ptr, \"OOM allocating info structure\");\n\n   {\n      const unsigned int size =\n         image_size_of_type(color_type, bit_depth, colors, small);\n      unsigned int ysize;\n      png_fixed_point real_gamma = 45455; /* For sRGB */\n      png_byte gamma_table[256];\n      double conv;\n\n      /* Normally images are square, but with 'small' we want to simply generate\n       * all the pixel values, or all that we reasonably can:\n       */\n      if (small)\n      {\n         const unsigned int pixel_depth =\n            pixel_depth_of_type(color_type, bit_depth);\n\n         if (pixel_depth <= 8U)\n         {\n            assert(size == (1U<<pixel_depth));\n            ysize = 1U;\n         }\n\n         else\n         {\n            assert(size == 256U);\n            ysize = 256U;\n         }\n      }\n\n      else\n         ysize = size;\n\n      /* This function uses the libpng values used on read to carry extra\n       * information about the gamma:\n       */\n      if (gamma == PNG_GAMMA_MAC_18)\n         gamma = 65909;\n\n      else if (gamma > 0 && gamma < 1000)\n         gamma = PNG_FP_1;\n\n      if (gamma > 0)\n         real_gamma = gamma;\n\n      {\n         unsigned int i;\n\n         if (real_gamma == 45455) for (i=0; i<256; ++i)\n         {\n            gamma_table[i] = (png_byte)i;\n            conv = 1.;\n         }\n\n         else\n         {\n            /* Convert 'i' from sRGB (45455) to real_gamma, this makes\n             * the images look the same regardless of the gAMA chunk.\n             */\n            conv = real_gamma;\n            conv /= 45455;\n\n            gamma_table[0] = 0;\n\n            for (i=1; i<255; ++i)\n               gamma_table[i] = floorb(pow(i/255.,conv) * 255 + .5);\n\n            gamma_table[255] = 255;\n         }\n      }\n\n      png_set_IHDR(png_ptr, info_ptr, size, ysize, bit_depth, color_type,\n         PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n      if (color_type & PNG_COLOR_MASK_PALETTE)\n      {\n         int npalette;\n         png_color palette[256];\n         png_byte trans[256];\n\n         npalette = generate_palette(palette, trans, bit_depth, gamma_table,\n            colors);\n         png_set_PLTE(png_ptr, info_ptr, palette, npalette);\n\n         if (tRNS)\n            png_set_tRNS(png_ptr, info_ptr, trans, npalette-1,\n               NULL/*transparent color*/);\n\n         /* Reset gamma_table to prevent the image rows being changed */\n         for (npalette=0; npalette<256; ++npalette)\n            gamma_table[npalette] = (png_byte)npalette;\n      }\n\n      else if (tRNS)\n      {\n         png_color_16 col;\n\n         col.red = col.green = col.blue = col.gray =\n            0x0101U & ((1U<<bit_depth)-1U);\n         col.index = 0U;\n         png_set_tRNS(png_ptr, info_ptr, NULL/*trans*/, 1U, &col);\n      }\n\n      if (gamma == PNG_DEFAULT_sRGB)\n         png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_ABSOLUTE);\n\n      else if (gamma > 0) /* Else don't set color space information */\n      {\n         png_set_gAMA_fixed(png_ptr, info_ptr, real_gamma);\n\n         /* Just use the sRGB values here. */\n         png_set_cHRM_fixed(png_ptr, info_ptr,\n            /* color      x       y */\n            /* white */ 31270, 32900,\n            /* red   */ 64000, 33000,\n            /* green */ 30000, 60000,\n            /* blue  */ 15000,  6000\n         );\n      }\n\n      /* Insert extra information. */\n      while (insert != NULL)\n      {\n         insert->insert(png_ptr, info_ptr, insert->nparams, insert->parameters);\n         insert = insert->next;\n      }\n\n      /* Write the file header. */\n      png_write_info(png_ptr, info_ptr);\n\n      /* Restrict the filters */\n      png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, filters);\n\n      {\n#        ifdef PNG_WRITE_INTERLACING_SUPPORTED\n            int passes = png_set_interlace_handling(png_ptr);\n#        else /* !WRITE_INTERLACING */\n            int passes = 1;\n#        endif /* !WRITE_INTERLACING */\n         int pass;\n         png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n\n         row = malloc(rowbytes);\n\n         if (row == NULL)\n            png_error(png_ptr, \"OOM allocating row buffer\");\n\n         for (pass = 0; pass < passes; ++pass)\n         {\n            unsigned int y;\n\n            for (y=0; y<ysize; ++y)\n            {\n               unsigned int row_filters =\n                  generate_row(row, rowbytes, y, color_type, bit_depth,\n                        gamma_table, conv, colors, small);\n\n               if (row_filters != 0 && filters == PNG_ALL_FILTERS)\n                  png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, row_filters);\n\n               png_write_row(png_ptr, row);\n            }\n         }\n      }\n   }\n\n   /* Finish writing the file. */\n   png_write_end(png_ptr, info_ptr);\n\n   {\n      png_structp nv_ptr = png_ptr;\n      png_infop nv_info = info_ptr;\n\n      png_ptr = NULL;\n      info_ptr = NULL;\n      png_destroy_write_struct(&nv_ptr, &nv_info);\n   }\n   free(row);\n   return 0;\n}\n\n\nstatic size_t\nload_file(png_const_charp name, png_bytepp result)\n{\n   FILE *fp = tmpfile();\n\n   if (fp != NULL)\n   {\n      FILE *ip = fopen(name, \"rb\");\n\n      if (ip != NULL)\n      {\n         size_t total = 0;\n         int ch;\n\n         for (;;)\n         {\n            ch = getc(ip);\n            if (ch == EOF) break;\n            putc(ch, fp);\n            ++total;\n         }\n\n         if (ferror(ip))\n         {\n            perror(name);\n            fprintf(stderr, \"%s: read error\\n\", name);\n            (void)fclose(ip);\n         }\n\n         else\n         {\n            (void)fclose(ip);\n\n            if (ferror(fp))\n            {\n               perror(\"temporary file\");\n               fprintf(stderr, \"temporary file write error\\n\");\n            }\n\n            else\n            {\n               rewind(fp);\n\n               if (total > 0)\n               {\n                  /* Round up to a multiple of 4 here to allow an iCCP profile\n                   * to be padded to a 4x boundary.\n                   */\n                  png_bytep data = malloc((total+3)&~3);\n\n                  if (data != NULL)\n                  {\n                     size_t new_size = 0;\n\n                     for (;;)\n                     {\n                        ch = getc(fp);\n                        if (ch == EOF) break;\n                        data[new_size++] = (png_byte)ch;\n                     }\n\n                     if (ferror(fp) || new_size != total)\n                     {\n                        perror(\"temporary file\");\n                        fprintf(stderr, \"temporary file read error\\n\");\n                        free(data);\n                     }\n\n                     else\n                     {\n                        (void)fclose(fp);\n                        *result = data;\n                        return total;\n                     }\n                  }\n\n                  else\n                     fprintf(stderr, \"%s: out of memory loading file\\n\", name);\n               }\n\n               else\n                  fprintf(stderr, \"%s: empty file\\n\", name);\n            }\n         }\n      }\n\n      else\n      {\n         perror(name);\n         fprintf(stderr, \"%s: open failed\\n\", name);\n      }\n\n      fclose(fp);\n   }\n\n   else\n      fprintf(stderr, \"makepng: %s: could not open temporary file\\n\", name);\n\n   exit(1);\n   return 0;\n}\n\nstatic png_size_t\nload_fake(png_charp param, png_bytepp profile)\n{\n   char *endptr = NULL;\n   uint64_t size = strtoull(param, &endptr, 0/*base*/);\n\n   /* The 'fake' format is <number>*[string] */\n   if (endptr != NULL && *endptr == '*')\n   {\n      size_t len = strlen(++endptr);\n      size_t result = (size_t)size;\n\n      if (len == 0) len = 1; /* capture the terminating '\\0' */\n\n      /* Now repeat that string to fill 'size' bytes. */\n      if (result == size && (*profile = malloc(result)) != NULL)\n      {\n         png_bytep out = *profile;\n\n         if (len == 1)\n            memset(out, *endptr, result);\n\n         else\n         {\n            while (size >= len)\n            {\n               memcpy(out, endptr, len);\n               out += len;\n               size -= len;\n            }\n            memcpy(out, endptr, size);\n         }\n\n         return result;\n      }\n\n      else\n      {\n         fprintf(stderr, \"%s: size exceeds system limits\\n\", param);\n         exit(1);\n      }\n   }\n\n   return 0;\n}\n\nstatic void\ncheck_param_count(int nparams, int expect)\n{\n   if (nparams != expect)\n   {\n      fprintf(stderr, \"bad parameter count (internal error)\\n\");\n      exit(1);\n   }\n}\n\nstatic void\ninsert_iCCP(png_structp png_ptr, png_infop info_ptr, int nparams,\n   png_charpp params)\n{\n   png_bytep profile = NULL;\n   png_uint_32 proflen = 0;\n   int result;\n\n   check_param_count(nparams, 2);\n\n   switch (params[1][0])\n   {\n      case '<':\n         {\n            png_size_t filelen = load_file(params[1]+1, &profile);\n            if (filelen > 0xfffffffc) /* Maximum profile length */\n            {\n               fprintf(stderr, \"%s: file too long (%lu) for an ICC profile\\n\",\n                  params[1]+1, (unsigned long)filelen);\n               exit(1);\n            }\n\n            proflen = (png_uint_32)filelen;\n         }\n         break;\n\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9':\n         {\n            png_size_t fake_len = load_fake(params[1], &profile);\n\n            if (fake_len > 0) /* else a simple parameter */\n            {\n               if (fake_len > 0xffffffff) /* Maximum profile length */\n               {\n                  fprintf(stderr,\n                     \"%s: fake data too long (%lu) for an ICC profile\\n\",\n                     params[1], (unsigned long)fake_len);\n                  exit(1);\n               }\n               proflen = (png_uint_32)(fake_len & ~3U);\n               /* Always fix up the profile length. */\n               png_save_uint_32(profile, proflen);\n               break;\n            }\n         }\n\n      default:\n         fprintf(stderr, \"--insert iCCP \\\"%s\\\": unrecognized\\n\", params[1]);\n         fprintf(stderr, \"  use '<' to read a file: \\\"<filename\\\"\\n\");\n         exit(1);\n   }\n\n   result = 1;\n\n   if (proflen & 3)\n   {\n      fprintf(stderr,\n         \"makepng: --insert iCCP %s: profile length made a multiple of 4\\n\",\n         params[1]);\n\n      /* load_file allocates extra space for this padding, the ICC spec requires\n       * padding with zero bytes.\n       */\n      while (proflen & 3)\n         profile[proflen++] = 0;\n   }\n\n   if (profile != NULL && proflen > 3)\n   {\n      png_uint_32 prof_header = png_get_uint_32(profile);\n\n      if (prof_header != proflen)\n      {\n         fprintf(stderr, \"--insert iCCP %s: profile length field wrong:\\n\",\n            params[1]);\n         fprintf(stderr, \"  actual %lu, recorded value %lu (corrected)\\n\",\n            (unsigned long)proflen, (unsigned long)prof_header);\n         png_save_uint_32(profile, proflen);\n      }\n   }\n\n   if (result && profile != NULL && proflen >=4)\n      png_set_iCCP(png_ptr, info_ptr, params[0], PNG_COMPRESSION_TYPE_BASE,\n         profile, proflen);\n\n   if (profile)\n      free(profile);\n\n   if (!result)\n      exit(1);\n}\n\nstatic void\nclear_text(png_text *text, png_charp keyword)\n{\n   text->compression = -1; /* none */\n   text->key = keyword;\n   text->text = NULL;\n   text->text_length = 0; /* libpng calculates this */\n   text->itxt_length = 0; /* libpng calculates this */\n   text->lang = NULL;\n   text->lang_key = NULL;\n}\n\nstatic void\nset_text(png_structp png_ptr, png_infop info_ptr, png_textp text,\n   png_charp param)\n{\n   switch (param[0])\n   {\n      case '<':\n         {\n            png_bytep file = NULL;\n\n            text->text_length = load_file(param+1, &file);\n            text->text = (png_charp)file;\n         }\n         break;\n\n      case '0': case '1': case '2': case '3': case '4':\n      case '5': case '6': case '7': case '8': case '9':\n         {\n            png_bytep data = NULL;\n            png_size_t fake_len = load_fake(param, &data);\n\n            if (fake_len > 0) /* else a simple parameter */\n            {\n               text->text_length = fake_len;\n               text->text = (png_charp)data;\n               break;\n            }\n         }\n\n      default:\n         text->text = param;\n         break;\n   }\n\n   png_set_text(png_ptr, info_ptr, text, 1);\n\n   if (text->text != param)\n      free(text->text);\n}\n\nstatic void\ninsert_tEXt(png_structp png_ptr, png_infop info_ptr, int nparams,\n   png_charpp params)\n{\n   png_text text;\n\n   check_param_count(nparams, 2);\n   clear_text(&text, params[0]);\n   set_text(png_ptr, info_ptr, &text, params[1]);\n}\n\nstatic void\ninsert_zTXt(png_structp png_ptr, png_infop info_ptr, int nparams,\n   png_charpp params)\n{\n   png_text text;\n\n   check_param_count(nparams, 2);\n   clear_text(&text, params[0]);\n   text.compression = 0; /* deflate */\n   set_text(png_ptr, info_ptr, &text, params[1]);\n}\n\nstatic void\ninsert_iTXt(png_structp png_ptr, png_infop info_ptr, int nparams,\n   png_charpp params)\n{\n   png_text text;\n\n   check_param_count(nparams, 4);\n   clear_text(&text, params[0]);\n   text.compression = 2; /* iTXt + deflate */\n   text.lang = params[1];/* language tag */\n   text.lang_key = params[2]; /* translated keyword */\n   set_text(png_ptr, info_ptr, &text, params[3]);\n}\n\nstatic void\ninsert_hIST(png_structp png_ptr, png_infop info_ptr, int nparams,\n      png_charpp params)\n{\n   int i;\n   png_uint_16 freq[256];\n\n   /* libpng takes the count from the PLTE count; we don't check it here but we\n    * do set the array to 0 for unspecified entries.\n    */\n   memset(freq, 0, sizeof freq);\n   for (i=0; i<nparams; ++i)\n   {\n      char *endptr = NULL;\n      unsigned long int l = strtoul(params[i], &endptr, 0/*base*/);\n\n      if (params[i][0] && *endptr == 0 && l <= 65535)\n         freq[i] = (png_uint_16)l;\n\n      else\n      {\n         fprintf(stderr, \"hIST[%d]: %s: invalid frequency\\n\", i, params[i]);\n         exit(1);\n      }\n   }\n\n   png_set_hIST(png_ptr, info_ptr, freq);\n}\n\nstatic png_byte\nbval(png_const_structrp png_ptr, png_charp param, unsigned int maxval)\n{\n   char *endptr = NULL;\n   unsigned long int l = strtoul(param, &endptr, 0/*base*/);\n\n   if (param[0] && *endptr == 0 && l <= maxval)\n      return (png_byte)l;\n\n   else\n      png_error(png_ptr, \"sBIT: invalid sBIT value\");\n}\n\nstatic void\ninsert_sBIT(png_structp png_ptr, png_infop info_ptr, int nparams,\n      png_charpp params)\n{\n   const int ct = png_get_color_type(png_ptr, info_ptr);\n   const int c = (ct & PNG_COLOR_MASK_COLOR ? 3 : 1) +\n      (ct & PNG_COLOR_MASK_ALPHA ? 1 : 0);\n   const unsigned int maxval =\n      ct & PNG_COLOR_MASK_PALETTE ? 8U : png_get_bit_depth(png_ptr, info_ptr);\n   png_color_8 sBIT;\n\n   if (nparams != c)\n      png_error(png_ptr, \"sBIT: incorrect parameter count\");\n\n   if (ct & PNG_COLOR_MASK_COLOR)\n   {\n      sBIT.red = bval(png_ptr, params[0], maxval);\n      sBIT.green = bval(png_ptr, params[1], maxval);\n      sBIT.blue = bval(png_ptr, params[2], maxval);\n      sBIT.gray = 42;\n   }\n\n   else\n   {\n      sBIT.red = sBIT.green = sBIT.blue = 42;\n      sBIT.gray = bval(png_ptr, params[0], maxval);\n   }\n\n   if (ct & PNG_COLOR_MASK_ALPHA)\n      sBIT.alpha = bval(png_ptr, params[nparams-1], maxval);\n\n   else\n      sBIT.alpha = 42;\n\n   png_set_sBIT(png_ptr, info_ptr, &sBIT);\n}\n\n#if 0\nstatic void\ninsert_sPLT(png_structp png_ptr, png_infop info_ptr, int nparams, png_charpp params)\n{\n   fprintf(stderr, \"insert sPLT: NYI\\n\");\n}\n#endif\n\nstatic int\nfind_parameters(png_const_charp what, png_charp param, png_charp *list,\n   int nparams)\n{\n   /* Parameters are separated by '\\n' or ':' characters, up to nparams are\n    * accepted (more is an error) and the number found is returned.\n    */\n   int i;\n   for (i=0; *param && i<nparams; ++i)\n   {\n      list[i] = param;\n      while (*++param) if (*param == '\\n' || *param == ':')\n      {\n         *param++ = 0; /* Terminate last parameter */\n         break;        /* And start a new one. */\n      }\n   }\n\n   if (*param)\n   {\n      fprintf(stderr, \"--insert %s: too many parameters (%s)\\n\", what, param);\n      exit(1);\n   }\n\n   list[i] = NULL; /* terminates list */\n   return i; /* number of parameters filled in */\n}\n\nstatic void\nbad_parameter_count(png_const_charp what, int nparams)\n{\n   fprintf(stderr, \"--insert %s: bad parameter count %d\\n\", what, nparams);\n   exit(1);\n}\n\nstatic chunk_insert *\nmake_insert(png_const_charp what,\n   void (*insert)(png_structp, png_infop, int, png_charpp),\n   int nparams, png_charpp list)\n{\n   int i;\n   chunk_insert *cip;\n\n   cip = malloc(offsetof(chunk_insert,parameters) +\n      nparams * sizeof (png_charp));\n\n   if (cip == NULL)\n   {\n      fprintf(stderr, \"--insert %s: out of memory allocating %d parameters\\n\",\n         what, nparams);\n      exit(1);\n   }\n\n   cip->next = NULL;\n   cip->insert = insert;\n   cip->nparams = nparams;\n   for (i=0; i<nparams; ++i)\n      cip->parameters[i] = list[i];\n\n   return cip;\n}\n\nstatic chunk_insert *\nfind_insert(png_const_charp what, png_charp param)\n{\n   png_uint_32 chunk = 0;\n   png_charp parameter_list[1024];\n   int i, nparams;\n\n   /* Assemble the chunk name */\n   for (i=0; i<4; ++i)\n   {\n      char ch = what[i];\n\n      if ((ch >= 65 && ch <= 90) || (ch >= 97 && ch <= 122))\n         chunk = (chunk << 8) + what[i];\n\n      else\n         break;\n   }\n\n   if (i < 4 || what[4] != 0)\n   {\n      fprintf(stderr, \"makepng --insert \\\"%s\\\": invalid chunk name\\n\", what);\n      exit(1);\n   }\n\n   /* Assemble the parameter list. */\n   nparams = find_parameters(what, param, parameter_list, 1024);\n\n#  define CHUNK(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))\n\n   switch (chunk)\n   {\n      case CHUNK(105,67,67,80):  /* iCCP */\n         if (nparams == 2)\n            return make_insert(what, insert_iCCP, nparams, parameter_list);\n         break;\n\n      case CHUNK(116,69,88,116): /* tEXt */\n         if (nparams == 2)\n            return make_insert(what, insert_tEXt, nparams, parameter_list);\n         break;\n\n      case CHUNK(122,84,88,116): /* zTXt */\n         if (nparams == 2)\n            return make_insert(what, insert_zTXt, nparams, parameter_list);\n         break;\n\n      case CHUNK(105,84,88,116): /* iTXt */\n         if (nparams == 4)\n            return make_insert(what, insert_iTXt, nparams, parameter_list);\n         break;\n\n      case CHUNK(104,73,83,84):  /* hIST */\n         if (nparams <= 256)\n            return make_insert(what, insert_hIST, nparams, parameter_list);\n         break;\n\n      case CHUNK(115,66,73,84): /* sBIT */\n         if (nparams <= 4)\n            return make_insert(what, insert_sBIT, nparams, parameter_list);\n         break;\n\n#if 0\n      case CHUNK(115,80,76,84):  /* sPLT */\n         return make_insert(what, insert_sPLT, nparams, parameter_list);\n#endif\n\n      default:\n         fprintf(stderr, \"makepng --insert \\\"%s\\\": unrecognized chunk name\\n\",\n            what);\n         exit(1);\n   }\n\n   bad_parameter_count(what, nparams);\n   return NULL;\n}\n\n/* This is necessary because libpng expects writeable strings for things like\n * text chunks (maybe this should be fixed...)\n */\nstatic png_charp\nstrstash(png_const_charp foo)\n{\n   /* The program indicates a memory allocation error by crashing, this is by\n    * design.\n    */\n   if (foo != NULL)\n   {\n      png_charp bar = malloc(strlen(foo)+1);\n      return strcpy(bar, foo);\n   }\n\n   return NULL;\n}\n\nstatic png_charp\nstrstash_list(const png_const_charp *text)\n{\n   size_t foo = 0;\n   png_charp result, bar;\n   const png_const_charp *line = text;\n\n   while (*line != NULL)\n      foo += strlen(*line++);\n\n   result = bar = malloc(foo+1);\n\n   line = text;\n   while (*line != NULL)\n   {\n      foo = strlen(*line);\n      memcpy(bar, *line++, foo);\n      bar += foo;\n   }\n\n   *bar = 0;\n   return result;\n}\n\n/* These are used to insert Copyright and Licence fields, they allow the text to\n * have \\n unlike the --insert option.\n */\nstatic chunk_insert *\nadd_tEXt(const char *key, const png_const_charp *text)\n{\n   static char what[5] = { 116, 69, 88, 116, 0 };\n   png_charp parameter_list[3];\n\n   parameter_list[0] = strstash(key);\n   parameter_list[1] = strstash_list(text);\n   parameter_list[2] = NULL;\n\n   return make_insert(what, insert_tEXt, 2, parameter_list);\n}\n\nstatic chunk_insert *\nadd_iTXt(const char *key, const char *language, const char *language_key,\n      const png_const_charp *text)\n{\n   static char what[5] = { 105, 84, 88, 116, 0 };\n   png_charp parameter_list[5];\n\n   parameter_list[0] = strstash(key);\n   parameter_list[1] = strstash(language);\n   parameter_list[2] = strstash(language_key);\n   parameter_list[3] = strstash_list(text);\n   parameter_list[4] = NULL;\n\n   return make_insert(what, insert_iTXt, 4, parameter_list);\n}\n\n/* This is a not-very-good parser for a sequence of numbers (including 0).  It\n * doesn't accept some apparently valid things, but it accepts all the sensible\n * combinations.\n */\nstatic void\nparse_color(char *arg, unsigned int *colors)\n{\n   unsigned int ncolors = 0;\n\n   while (*arg && ncolors < 4)\n   {\n      char *ep = arg;\n\n      unsigned long ul = strtoul(arg, &ep, 0);\n\n      if (ul > 65535)\n      {\n         fprintf(stderr, \"makepng --color=...'%s': too big\\n\", arg);\n         exit(1);\n      }\n\n      if (ep == arg)\n      {\n         fprintf(stderr, \"makepng --color=...'%s': not a valid color\\n\", arg);\n         exit(1);\n      }\n\n      if (*ep) ++ep; /* skip a separator */\n      arg = ep;\n\n      colors[++ncolors] = (unsigned int)ul; /* checked above */\n   }\n\n   if (*arg)\n   {\n      fprintf(stderr, \"makepng --color=...'%s': too many values\\n\", arg);\n      exit(1);\n   }\n\n   *colors = ncolors;\n}\n\nint\nmain(int argc, char **argv)\n{\n   FILE *fp = stdout;\n   const char *file_name = NULL;\n   int color_type = 8; /* invalid */\n   int bit_depth = 32; /* invalid */\n   int small = 0; /* make full size images */\n   int tRNS = 0; /* don't output a tRNS chunk */\n   unsigned int colors[5];\n   unsigned int filters = PNG_ALL_FILTERS;\n   png_fixed_point gamma = 0; /* not set */\n   chunk_insert *head_insert = NULL;\n   chunk_insert **insert_ptr = &head_insert;\n\n   memset(colors, 0, sizeof colors);\n\n   while (--argc > 0)\n   {\n      char *arg = *++argv;\n\n      if (strcmp(arg, \"--small\") == 0)\n      {\n         small = 1;\n         continue;\n      }\n\n      if (strcmp(arg, \"--tRNS\") == 0)\n      {\n         tRNS = 1;\n         continue;\n      }\n\n      if (strcmp(arg, \"--sRGB\") == 0)\n      {\n         gamma = PNG_DEFAULT_sRGB;\n         continue;\n      }\n\n      if (strcmp(arg, \"--linear\") == 0)\n      {\n         gamma = PNG_FP_1;\n         continue;\n      }\n\n      if (strcmp(arg, \"--1.8\") == 0)\n      {\n         gamma = PNG_GAMMA_MAC_18;\n         continue;\n      }\n\n      if (strcmp(arg, \"--nofilters\") == 0)\n      {\n         filters = PNG_FILTER_NONE;\n         continue;\n      }\n\n      if (strncmp(arg, \"--color=\", 8) == 0)\n      {\n          parse_color(arg+8, colors);\n          continue;\n      }\n\n      if (argc >= 3 && strcmp(arg, \"--insert\") == 0)\n      {\n         png_const_charp what = *++argv;\n         png_charp param = *++argv;\n         chunk_insert *new_insert;\n\n         argc -= 2;\n\n         new_insert = find_insert(what, param);\n\n         if (new_insert != NULL)\n         {\n            *insert_ptr = new_insert;\n            insert_ptr = &new_insert->next;\n         }\n\n         continue;\n      }\n\n      if (arg[0] == '-')\n      {\n         fprintf(stderr, \"makepng: %s: invalid option\\n\", arg);\n         exit(1);\n      }\n\n      if (strcmp(arg, \"palette\") == 0)\n      {\n         color_type = PNG_COLOR_TYPE_PALETTE;\n         continue;\n      }\n\n      if (strncmp(arg, \"gray\", 4) == 0)\n      {\n         if (arg[4] == 0)\n         {\n            color_type = PNG_COLOR_TYPE_GRAY;\n            continue;\n         }\n\n         else if (strcmp(arg+4, \"a\") == 0 ||\n            strcmp(arg+4, \"alpha\") == 0 ||\n            strcmp(arg+4, \"-alpha\") == 0)\n         {\n            color_type = PNG_COLOR_TYPE_GRAY_ALPHA;\n            continue;\n         }\n      }\n\n      if (strncmp(arg, \"rgb\", 3) == 0)\n      {\n         if (arg[3] == 0)\n         {\n            color_type = PNG_COLOR_TYPE_RGB;\n            continue;\n         }\n\n         else if (strcmp(arg+3, \"a\") == 0 ||\n            strcmp(arg+3, \"alpha\") == 0 ||\n            strcmp(arg+3, \"-alpha\") == 0)\n         {\n            color_type = PNG_COLOR_TYPE_RGB_ALPHA;\n            continue;\n         }\n      }\n\n      if (color_type == 8 && isdigit(arg[0]))\n      {\n         color_type = atoi(arg);\n         if (color_type < 0 || color_type > 6 || color_type == 1 ||\n            color_type == 5)\n         {\n            fprintf(stderr, \"makepng: %s: not a valid color type\\n\", arg);\n            exit(1);\n         }\n\n         continue;\n      }\n\n      if (bit_depth == 32 && isdigit(arg[0]))\n      {\n         bit_depth = atoi(arg);\n         if (bit_depth <= 0 || bit_depth > 16 ||\n            (bit_depth & -bit_depth) != bit_depth)\n         {\n            fprintf(stderr, \"makepng: %s: not a valid bit depth\\n\", arg);\n            exit(1);\n         }\n\n         continue;\n      }\n\n      if (argc == 1) /* It's the file name */\n      {\n         fp = fopen(arg, \"wb\");\n         if (fp == NULL)\n         {\n            fprintf(stderr, \"%s: %s: could not open\\n\", arg, strerror(errno));\n            exit(1);\n         }\n\n         file_name = arg;\n         continue;\n      }\n\n      fprintf(stderr, \"makepng: %s: unknown argument\\n\", arg);\n      exit(1);\n   } /* argument while loop */\n\n   if (color_type == 8 || bit_depth == 32)\n   {\n      fprintf(stderr, \"usage: makepng [--small] [--sRGB|--linear|--1.8] \"\n         \"[--color=...] color-type bit-depth [file-name]\\n\"\n         \"  Make a test PNG file, by default writes to stdout.\\n\"\n         \"  Other options are available, UTSL.\\n\");\n      exit(1);\n   }\n\n   /* Check the colors */\n   {\n      const unsigned int lim = (color_type == PNG_COLOR_TYPE_PALETTE ? 255U :\n         (1U<<bit_depth)-1);\n      unsigned int i;\n\n      for (i=1; i<=colors[0]; ++i)\n         if (colors[i] > lim)\n         {\n            fprintf(stderr, \"makepng: --color=...: %u out of range [0..%u]\\n\",\n               colors[i], lim);\n            exit(1);\n         }\n   }\n\n   /* small and colors are incomparible (will probably crash if both are used at\n    * the same time!)\n    */\n   if (small && colors[0] != 0)\n   {\n      fprintf(stderr, \"makepng: --color --small: only one at a time!\\n\");\n      exit(1);\n   }\n\n   /* Restrict the filters for more speed to those we know are used for the\n    * generated images.\n    */\n   if (filters == PNG_ALL_FILTERS && !small/*small provides defaults*/)\n   {\n      if ((color_type & PNG_COLOR_MASK_PALETTE) != 0 || bit_depth < 8)\n         filters = PNG_FILTER_NONE;\n\n      else if (color_type & PNG_COLOR_MASK_COLOR) /* rgb */\n      {\n         if (bit_depth == 8)\n            filters &= ~(PNG_FILTER_NONE | PNG_FILTER_AVG);\n\n         else\n            filters = PNG_FILTER_SUB | PNG_FILTER_PAETH;\n      }\n\n      else /* gray 8 or 16-bit */\n         filters &= ~PNG_FILTER_NONE;\n   }\n\n   /* Insert standard copyright and licence text. */\n   {\n      static png_const_charp copyright[] =\n      {\n         COPYRIGHT, /* ISO-Latin-1 */\n         NULL\n      };\n      static png_const_charp licensing[] =\n      {\n         IMAGE_LICENSING, /* UTF-8 */\n         NULL\n      };\n\n      chunk_insert *new_insert;\n\n      new_insert = add_tEXt(\"Copyright\", copyright);\n      if (new_insert != NULL)\n      {\n         *insert_ptr = new_insert;\n         insert_ptr = &new_insert->next;\n      }\n\n      new_insert = add_iTXt(\"Licensing\", \"en\", NULL, licensing);\n      if (new_insert != NULL)\n      {\n         *insert_ptr = new_insert;\n         insert_ptr = &new_insert->next;\n      }\n   }\n\n   {\n      int ret = write_png(&file_name, fp, color_type, bit_depth, gamma,\n         head_insert, filters, colors, small, tRNS);\n\n      if (ret != 0 && file_name != NULL)\n         remove(file_name);\n\n      return ret;\n   }\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/pngimage.c",
    "content": "/* pngimage.c\n *\n * Copyright (c) 2015,2016 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Test the png_read_png and png_write_png interfaces.  Given a PNG file load it\n * using png_read_png and then write with png_write_png.  Test all possible\n * transforms.\n */\n#include <stdarg.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <stdio.h>\n#include <assert.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n#ifndef PNG_SETJMP_SUPPORTED\n#  include <setjmp.h> /* because png.h did *not* include this */\n#endif\n\n/* 1.6.1 added support for the configure test harness, which uses 77 to indicate\n * a skipped test, in earlier versions we need to succeed on a skipped test, so:\n */\n#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)\n#  define SKIP 77\n#else\n#  define SKIP 0\n#endif\n\n#if PNG_LIBPNG_VER < 10700\n   /* READ_PNG and WRITE_PNG were not defined, so: */\n#  ifdef PNG_INFO_IMAGE_SUPPORTED\n#     ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n#        define PNG_READ_PNG_SUPPORTED\n#     endif /* SEQUENTIAL_READ */\n#     ifdef PNG_WRITE_SUPPORTED\n#        define PNG_WRITE_PNG_SUPPORTED\n#     endif /* WRITE */\n#  endif /* INFO_IMAGE */\n#endif /* pre 1.7.0 */\n\n#ifdef PNG_READ_PNG_SUPPORTED\n/* If a transform is valid on both read and write this implies that if the\n * transform is applied to read it must also be applied on write to produce\n * meaningful data.  This is because these transforms when performed on read\n * produce data with a memory format that does not correspond to a PNG format.\n *\n * Most of these transforms are invertible; after applying the transform on\n * write the result is the original PNG data that would have would have been\n * read if no transform were applied.\n *\n * The exception is _SHIFT, which destroys the low order bits marked as not\n * significant in a PNG with the sBIT chunk.\n *\n * The following table lists, for each transform, the conditions under which it\n * is expected to do anything.  Conditions are defined as follows:\n *\n * 1) Color mask bits required - simply a mask to AND with color_type; one of\n *    these must be present for the transform to fire, except that 0 means\n *    'always'.\n * 2) Color mask bits which must be absent - another mask - none of these must\n *    be present.\n * 3) Bit depths - a mask of component bit depths for the transform to fire.\n * 4) 'read' - the transform works in png_read_png.\n * 5) 'write' - the transform works in png_write_png.\n * 6) PNG_INFO_chunk; a mask of the chunks that must be present for the\n *    transform to fire.  All must be present - the requirement is that\n *    png_get_valid() & mask == mask, so if mask is 0 there is no requirement.\n *\n * The condition refers to the original image state - if multiple transforms are\n * used together it is possible to cause a transform that wouldn't fire on the\n * original image to fire.\n */\nstatic struct transform_info\n{\n   const char *name;\n   int         transform;\n   png_uint_32 valid_chunks;\n#     define CHUNK_NONE 0\n#     define CHUNK_sBIT PNG_INFO_sBIT\n#     define CHUNK_tRNS PNG_INFO_tRNS\n   png_byte    color_mask_required;\n   png_byte    color_mask_absent;\n#     define COLOR_MASK_X   0\n#     define COLOR_MASK_P   PNG_COLOR_MASK_PALETTE\n#     define COLOR_MASK_C   PNG_COLOR_MASK_COLOR\n#     define COLOR_MASK_A   PNG_COLOR_MASK_ALPHA\n#     define COLOR_MASK_ALL (PALETTE+COLOR+ALPHA)  /* absent = gray, no alpha */\n   png_byte    bit_depths;\n#     define BD_ALL  (1 + 2 + 4 + 8 + 16)\n#     define BD_PAL  (1 + 2 + 4 + 8)\n#     define BD_LOW  (1 + 2 + 4)\n#     define BD_16   16\n#     define BD_TRUE (8+16) /* i.e. true-color depths */\n   png_byte    when;\n#     define TRANSFORM_R  1\n#     define TRANSFORM_W  2\n#     define TRANSFORM_RW 3\n   png_byte    tested; /* the transform was tested somewhere */\n} transform_info[] =\n{\n   /* List ALL the PNG_TRANSFORM_ macros here.  Check for support using the READ\n    * macros; even if the transform is supported on write it cannot be tested\n    * without the read support.\n    */\n#  define T(name,chunk,cm_required,cm_absent,bd,when)\\\n   {  #name, PNG_TRANSFORM_ ## name, CHUNK_ ## chunk,\\\n      COLOR_MASK_ ## cm_required, COLOR_MASK_ ## cm_absent, BD_ ## bd,\\\n      TRANSFORM_ ## when, 0/*!tested*/ }\n\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n   T(STRIP_16,            NONE, X,   X,   16,  R),\n      /* drops the bottom 8 bits when bit depth is 16 */\n#endif\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n   T(STRIP_ALPHA,         NONE, A,   X,  ALL,  R),\n      /* removes the alpha channel if present */\n#endif\n#ifdef PNG_WRITE_PACK_SUPPORTED\n#  define TRANSFORM_RW_PACK TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_PACK TRANSFORM_R\n#endif\n#ifdef PNG_READ_PACK_SUPPORTED\n   T(PACKING,             NONE, X,   X,  LOW, RW_PACK),\n      /* unpacks low-bit-depth components into 1 byte per component on read,\n       * reverses this on write.\n       */\n#endif\n#ifdef PNG_WRITE_PACKSWAP_SUPPORTED\n#  define TRANSFORM_RW_PACKSWAP TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_PACKSWAP TRANSFORM_R\n#endif\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n   T(PACKSWAP,            NONE, X,   X,  LOW, RW_PACKSWAP),\n      /* reverses the order of low-bit-depth components packed into a byte */\n#endif\n#ifdef PNG_READ_EXPAND_SUPPORTED\n   T(EXPAND,              NONE, P,   X,  ALL,  R),\n      /* expands PLTE PNG files to RGB (no tRNS) or RGBA (tRNS) *\n       * Note that the 'EXPAND' transform does lots of different things: */\n   T(EXPAND,              NONE, X,   C,  ALL,  R),\n      /* expands grayscale PNG files to RGB, or RGBA */\n   T(EXPAND,              tRNS, X,   A,  ALL,  R),\n      /* expands the tRNS chunk in files without alpha */\n#endif\n#ifdef PNG_WRITE_INVERT_SUPPORTED\n#  define TRANSFORM_RW_INVERT TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_INVERT TRANSFORM_R\n#endif\n#ifdef PNG_READ_INVERT_SUPPORTED\n   T(INVERT_MONO,         NONE, X,   C,  ALL, RW_INVERT),\n      /* converts gray-scale components to 1..0 from 0..1 */\n#endif\n#ifdef PNG_WRITE_SHIFT_SUPPORTED\n#  define TRANSFORM_RW_SHIFT TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_SHIFT TRANSFORM_R\n#endif\n#ifdef PNG_READ_SHIFT_SUPPORTED\n   T(SHIFT,               sBIT, X,   X,  ALL, RW_SHIFT),\n      /* reduces component values to the original range based on the sBIT chunk,\n       * this is only partially reversible - the low bits are lost and cannot be\n       * recovered on write.  In fact write code replicates the bits to generate\n       * new low-order bits.\n       */\n#endif\n#ifdef PNG_WRITE_BGR_SUPPORTED\n#  define TRANSFORM_RW_BGR TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_BGR TRANSFORM_R\n#endif\n#ifdef PNG_READ_BGR_SUPPORTED\n   T(BGR,                 NONE, C,   P, TRUE, RW_BGR),\n      /* reverses the rgb component values of true-color pixels */\n#endif\n#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED\n#  define TRANSFORM_RW_SWAP_ALPHA TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_SWAP_ALPHA TRANSFORM_R\n#endif\n#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED\n   T(SWAP_ALPHA,          NONE, A,   X, TRUE, RW_SWAP_ALPHA),\n      /* swaps the alpha channel of RGBA or GA pixels to the front - ARGB or\n       * AG, on write reverses the process.\n       */\n#endif\n#ifdef PNG_WRITE_SWAP_SUPPORTED\n#  define TRANSFORM_RW_SWAP TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_SWAP TRANSFORM_R\n#endif\n#ifdef PNG_READ_SWAP_SUPPORTED\n   T(SWAP_ENDIAN,         NONE, X,   P,   16, RW_SWAP),\n      /* byte-swaps 16-bit component values */\n#endif\n#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED\n#  define TRANSFORM_RW_INVERT_ALPHA TRANSFORM_RW\n#else\n#  define TRANSFORM_RW_INVERT_ALPHA TRANSFORM_R\n#endif\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\n   T(INVERT_ALPHA,        NONE, A,   X, TRUE, RW_INVERT_ALPHA),\n      /* converts an alpha channel from 0..1 to 1..0 */\n#endif\n#ifdef PNG_WRITE_FILLER_SUPPORTED\n   T(STRIP_FILLER_BEFORE, NONE, A,   P, TRUE,  W), /* 'A' for a filler! */\n      /* on write skips a leading filler channel; testing requires data with a\n       * filler channel so this is produced from RGBA or GA images by removing\n       * the 'alpha' flag from the color type in place.\n       */\n   T(STRIP_FILLER_AFTER,  NONE, A,   P, TRUE,  W),\n      /* on write strips a trailing filler channel */\n#endif\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n   T(GRAY_TO_RGB,         NONE, X,   C,  ALL,  R),\n      /* expands grayscale images to RGB, also causes the palette part of\n       * 'EXPAND' to happen.  Low bit depth grayscale images are expanded to\n       * 8-bits per component and no attempt is made to convert the image to a\n       * palette image.  While this transform is partially reversible\n       * png_write_png does not currently support this.\n       */\n   T(GRAY_TO_RGB,         NONE, P,   X,  ALL,  R),\n      /* The 'palette' side effect mentioned above; a bit bogus but this is the\n       * way the libpng code works.\n       */\n#endif\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n   T(EXPAND_16,           NONE, X,   X,  PAL,  R),\n      /* expands images to 16-bits per component, as a side effect expands\n       * palette images to RGB and expands the tRNS chunk if present, so it can\n       * modify 16-bit per component images as well:\n       */\n   T(EXPAND_16,           tRNS, X,   A,   16,  R),\n      /* side effect of EXPAND_16 - expands the tRNS chunk in an RGB or G 16-bit\n       * image.\n       */\n#endif\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n   T(SCALE_16,            NONE, X,   X,   16,  R),\n      /* scales 16-bit components to 8-bits. */\n#endif\n\n   { NULL /*name*/, 0, 0, 0, 0, 0, 0, 0/*!tested*/ }\n\n#undef T\n};\n\n#define ARRAY_SIZE(a) ((sizeof a)/(sizeof a[0]))\n#define TTABLE_SIZE ARRAY_SIZE(transform_info)\n\n/* Some combinations of options that should be reversible are not; these cases\n * are bugs.\n */\nstatic int known_bad_combos[][2] =\n{\n   /* problem, antidote */\n   { PNG_TRANSFORM_SHIFT | PNG_TRANSFORM_INVERT_ALPHA, 0/*antidote*/ }\n};\n\nstatic int\nis_combo(int transforms)\n{\n   return transforms & (transforms-1); /* non-zero if more than one set bit */\n}\n\nstatic int\nfirst_transform(int transforms)\n{\n   return transforms & -transforms; /* lowest set bit */\n}\n\nstatic int\nis_bad_combo(int transforms)\n{\n   unsigned int i;\n\n   for (i=0; i<ARRAY_SIZE(known_bad_combos); ++i)\n   {\n      int combo = known_bad_combos[i][0];\n\n      if ((combo & transforms) == combo &&\n         (transforms & known_bad_combos[i][1]) == 0)\n         return 1;\n   }\n\n   return 0; /* combo is ok */\n}\n\nstatic const char *\ntransform_name(int t)\n   /* The name, if 't' has multiple bits set the name of the lowest set bit is\n    * returned.\n    */\n{\n   unsigned int i;\n\n   t &= -t; /* first set bit */\n\n   for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)\n   {\n      if ((transform_info[i].transform & t) != 0)\n         return transform_info[i].name;\n   }\n\n   return \"invalid transform\";\n}\n\n/* Variables calculated by validate_T below and used to record all the supported\n * transforms.  Need (unsigned int) here because of the places where these\n * values are used (unsigned compares in the 'exhaustive' iterator.)\n */\nstatic unsigned int read_transforms, write_transforms, rw_transforms;\n\nstatic void\nvalidate_T(void)\n   /* Validate the above table - this just builds the above values */\n{\n   unsigned int i;\n\n   for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)\n   {\n      if (transform_info[i].when & TRANSFORM_R)\n         read_transforms |= transform_info[i].transform;\n\n      if (transform_info[i].when & TRANSFORM_W)\n         write_transforms |= transform_info[i].transform;\n   }\n\n   /* Reversible transforms are those which are supported on both read and\n    * write.\n    */\n   rw_transforms = read_transforms & write_transforms;\n}\n\n/* FILE DATA HANDLING\n *    The original file is cached in memory.  During write the output file is\n *    written to memory.\n *\n *    In both cases the file data is held in a linked list of buffers - not all\n *    of these are in use at any time.\n */\n#define NEW(type) ((type *)malloc(sizeof (type)))\n#define DELETE(ptr) (free(ptr))\n\nstruct buffer_list\n{\n   struct buffer_list *next;         /* next buffer in list */\n   png_byte            buffer[1024]; /* the actual buffer */\n};\n\nstruct buffer\n{\n   struct buffer_list  *last;       /* last buffer in use */\n   size_t               end_count;  /* bytes in the last buffer */\n   struct buffer_list  *current;    /* current buffer being read */\n   size_t               read_count; /* count of bytes read from current */\n   struct buffer_list   first;      /* the very first buffer */\n};\n\nstatic void\nbuffer_init(struct buffer *buffer)\n   /* Call this only once for a given buffer */\n{\n   buffer->first.next = NULL;\n   buffer->last = NULL;\n   buffer->current = NULL;\n}\n\nstatic void\nbuffer_destroy_list(struct buffer_list *list)\n{\n   if (list != NULL)\n   {\n      struct buffer_list *next = list->next;\n      DELETE(list);\n      buffer_destroy_list(next);\n   }\n}\n\nstatic void\nbuffer_destroy(struct buffer *buffer)\n{\n   struct buffer_list *list = buffer->first.next;\n   buffer_init(buffer);\n   buffer_destroy_list(list);\n}\n\n#ifdef PNG_WRITE_PNG_SUPPORTED\nstatic void\nbuffer_start_write(struct buffer *buffer)\n{\n   buffer->last = &buffer->first;\n   buffer->end_count = 0;\n   buffer->current = NULL;\n}\n#endif\n\nstatic void\nbuffer_start_read(struct buffer *buffer)\n{\n   buffer->current = &buffer->first;\n   buffer->read_count = 0;\n}\n\n#ifdef ENOMEM /* required by POSIX 1003.1 */\n#  define MEMORY ENOMEM\n#else\n#  define MEMORY ERANGE /* required by ANSI-C */\n#endif\nstatic struct buffer *\nget_buffer(png_structp pp)\n   /* Used from libpng callbacks to get the current buffer */\n{\n   return (struct buffer*)png_get_io_ptr(pp);\n}\n\nstatic struct buffer_list *\nbuffer_extend(struct buffer_list *current)\n{\n   struct buffer_list *add;\n\n   assert(current->next == NULL);\n\n   add = NEW(struct buffer_list);\n   if (add == NULL)\n      return NULL;\n\n   add->next = NULL;\n   current->next = add;\n\n   return add;\n}\n\n/* Load a buffer from a file; does the equivalent of buffer_start_write.  On a\n * read error returns an errno value, else returns 0.\n */\nstatic int\nbuffer_from_file(struct buffer *buffer, FILE *fp)\n{\n   struct buffer_list *last = &buffer->first;\n   size_t count = 0;\n\n   for (;;)\n   {\n      size_t r = fread(last->buffer+count, 1/*size*/,\n         (sizeof last->buffer)-count, fp);\n\n      if (r > 0)\n      {\n         count += r;\n\n         if (count >= sizeof last->buffer)\n         {\n            assert(count == sizeof last->buffer);\n            count = 0;\n\n            if (last->next == NULL)\n            {\n               last = buffer_extend(last);\n               if (last == NULL)\n                  return MEMORY;\n            }\n\n            else\n               last = last->next;\n         }\n      }\n\n      else /* fread failed - probably end of file */\n      {\n         if (feof(fp))\n         {\n            buffer->last = last;\n            buffer->end_count = count;\n            return 0; /* no error */\n         }\n\n         /* Some kind of funky error; errno should be non-zero */\n         return errno == 0 ? ERANGE : errno;\n      }\n   }\n}\n\n/* This structure is used to control the test of a single file. */\ntypedef enum\n{\n   VERBOSE,        /* switches on all messages */\n   INFORMATION,\n   WARNINGS,       /* switches on warnings */\n   LIBPNG_WARNING,\n   APP_WARNING,\n   ERRORS,         /* just errors */\n   APP_FAIL,       /* continuable error - no need to longjmp */\n   LIBPNG_ERROR,   /* this and higher cause a longjmp */\n   LIBPNG_BUG,     /* erroneous behavior in libpng */\n   APP_ERROR,      /* such as out-of-memory in a callback */\n   QUIET,          /* no normal messages */\n   USER_ERROR,     /* such as file-not-found */\n   INTERNAL_ERROR\n} error_level;\n#define LEVEL_MASK      0xf   /* where the level is in 'options' */\n\n#define EXHAUSTIVE      0x010 /* Test all combinations of active options */\n#define STRICT          0x020 /* Fail on warnings as well as errors */\n#define LOG             0x040 /* Log pass/fail to stdout */\n#define CONTINUE        0x080 /* Continue on APP_FAIL errors */\n#define SKIP_BUGS       0x100 /* Skip over known bugs */\n#define LOG_SKIPPED     0x200 /* Log skipped bugs */\n#define FIND_BAD_COMBOS 0x400 /* Attempt to deduce bad combos */\n#define LIST_COMBOS     0x800 /* List combos by name */\n\n/* Result masks apply to the result bits in the 'results' field below; these\n * bits are simple 1U<<error_level.  A pass requires either nothing worse than\n * warnings (--relaxes) or nothing worse than information (--strict)\n */\n#define RESULT_STRICT(r)   (((r) & ~((1U<<WARNINGS)-1)) == 0)\n#define RESULT_RELAXED(r)  (((r) & ~((1U<<ERRORS)-1)) == 0)\n\nstruct display\n{\n   jmp_buf        error_return;      /* Where to go to on error */\n\n   const char    *filename;          /* The name of the original file */\n   const char    *operation;         /* Operation being performed */\n   int            transforms;        /* Transform used in operation */\n   png_uint_32    options;           /* See display_log below */\n   png_uint_32    results;           /* A mask of errors seen */\n\n\n   png_structp    original_pp;       /* used on the original read */\n   png_infop      original_ip;       /* set by the original read */\n\n   png_size_t     original_rowbytes; /* of the original rows: */\n   png_bytepp     original_rows;     /* from the original read */\n\n   /* Original chunks valid */\n   png_uint_32    chunks;\n\n   /* Original IHDR information */\n   png_uint_32    width;\n   png_uint_32    height;\n   int            bit_depth;\n   int            color_type;\n   int            interlace_method;\n   int            compression_method;\n   int            filter_method;\n\n   /* Derived information for the original image. */\n   int            active_transforms;  /* transforms that do something on read */\n   int            ignored_transforms; /* transforms that should do nothing */\n\n   /* Used on a read, both the original read and when validating a written\n    * image.\n    */\n   png_structp    read_pp;\n   png_infop      read_ip;\n\n#  ifdef PNG_WRITE_PNG_SUPPORTED\n      /* Used to write a new image (the original info_ptr is used) */\n      png_structp   write_pp;\n      struct buffer written_file;   /* where the file gets written */\n#  endif\n\n   struct buffer  original_file;     /* Data read from the original file */\n};\n\nstatic void\ndisplay_init(struct display *dp)\n   /* Call this only once right at the start to initialize the control\n    * structure, the (struct buffer) lists are maintained across calls - the\n    * memory is not freed.\n    */\n{\n   memset(dp, 0, sizeof *dp);\n   dp->options = WARNINGS; /* default to !verbose, !quiet */\n   dp->filename = NULL;\n   dp->operation = NULL;\n   dp->original_pp = NULL;\n   dp->original_ip = NULL;\n   dp->original_rows = NULL;\n   dp->read_pp = NULL;\n   dp->read_ip = NULL;\n   buffer_init(&dp->original_file);\n\n#  ifdef PNG_WRITE_PNG_SUPPORTED\n      dp->write_pp = NULL;\n      buffer_init(&dp->written_file);\n#  endif\n}\n\nstatic void\ndisplay_clean_read(struct display *dp)\n{\n   if (dp->read_pp != NULL)\n      png_destroy_read_struct(&dp->read_pp, &dp->read_ip, NULL);\n}\n\n#ifdef PNG_WRITE_PNG_SUPPORTED\nstatic void\ndisplay_clean_write(struct display *dp)\n{\n      if (dp->write_pp != NULL)\n         png_destroy_write_struct(&dp->write_pp, NULL);\n}\n#endif\n\nstatic void\ndisplay_clean(struct display *dp)\n{\n#  ifdef PNG_WRITE_PNG_SUPPORTED\n      display_clean_write(dp);\n#  endif\n   display_clean_read(dp);\n\n   dp->original_rowbytes = 0;\n   dp->original_rows = NULL;\n   dp->chunks = 0;\n\n   png_destroy_read_struct(&dp->original_pp, &dp->original_ip, NULL);\n   /* leave the filename for error detection */\n   dp->results = 0; /* reset for next time */\n}\n\nstatic void\ndisplay_destroy(struct display *dp)\n{\n    /* Release any memory held in the display. */\n#  ifdef PNG_WRITE_PNG_SUPPORTED\n      buffer_destroy(&dp->written_file);\n#  endif\n\n   buffer_destroy(&dp->original_file);\n}\n\nstatic struct display *\nget_dp(png_structp pp)\n   /* The display pointer is always stored in the png_struct error pointer */\n{\n   struct display *dp = (struct display*)png_get_error_ptr(pp);\n\n   if (dp == NULL)\n   {\n      fprintf(stderr, \"pngimage: internal error (no display)\\n\");\n      exit(99); /* prevents a crash */\n   }\n\n   return dp;\n}\n\n/* error handling */\n#ifdef __GNUC__\n#  define VGATTR __attribute__((__format__ (__printf__,3,4)))\n   /* Required to quiet GNUC warnings when the compiler sees a stdarg function\n    * that calls one of the stdio v APIs.\n    */\n#else\n#  define VGATTR\n#endif\nstatic void VGATTR\ndisplay_log(struct display *dp, error_level level, const char *fmt, ...)\n   /* 'level' is as above, fmt is a stdio style format string.  This routine\n    * does not return if level is above LIBPNG_WARNING\n    */\n{\n   dp->results |= 1U << level;\n\n   if (level > (error_level)(dp->options & LEVEL_MASK))\n   {\n      const char *lp;\n      va_list ap;\n\n      switch (level)\n      {\n         case INFORMATION:    lp = \"information\"; break;\n         case LIBPNG_WARNING: lp = \"warning(libpng)\"; break;\n         case APP_WARNING:    lp = \"warning(pngimage)\"; break;\n         case APP_FAIL:       lp = \"error(continuable)\"; break;\n         case LIBPNG_ERROR:   lp = \"error(libpng)\"; break;\n         case LIBPNG_BUG:     lp = \"bug(libpng)\"; break;\n         case APP_ERROR:      lp = \"error(pngimage)\"; break;\n         case USER_ERROR:     lp = \"error(user)\"; break;\n\n         case INTERNAL_ERROR: /* anything unexpected is an internal error: */\n         case VERBOSE: case WARNINGS: case ERRORS: case QUIET:\n         default:             lp = \"bug(pngimage)\"; break;\n      }\n\n      fprintf(stderr, \"%s: %s: %s\",\n         dp->filename != NULL ? dp->filename : \"<stdin>\", lp, dp->operation);\n\n      if (dp->transforms != 0)\n      {\n         int tr = dp->transforms;\n\n         if (is_combo(tr))\n         {\n            if (dp->options & LIST_COMBOS)\n            {\n               int trx = tr;\n\n               fprintf(stderr, \"(\");\n               if (trx)\n               {\n                  int start = 0;\n\n                  while (trx)\n                  {\n                     int trz = trx & -trx;\n\n                     if (start) fprintf(stderr, \"+\");\n                     fprintf(stderr, \"%s\", transform_name(trz));\n                     start = 1;\n                     trx &= ~trz;\n                  }\n               }\n\n               else\n                  fprintf(stderr, \"-\");\n               fprintf(stderr, \")\");\n            }\n\n            else\n               fprintf(stderr, \"(0x%x)\", tr);\n         }\n\n         else\n            fprintf(stderr, \"(%s)\", transform_name(tr));\n      }\n\n      fprintf(stderr, \": \");\n\n      va_start(ap, fmt);\n      vfprintf(stderr, fmt, ap);\n      va_end(ap);\n\n      fputc('\\n', stderr);\n   }\n   /* else do not output any message */\n\n   /* Errors cause this routine to exit to the fail code */\n   if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))\n      longjmp(dp->error_return, level);\n}\n\n/* error handler callbacks for libpng */\nstatic void PNGCBAPI\ndisplay_warning(png_structp pp, png_const_charp warning)\n{\n   display_log(get_dp(pp), LIBPNG_WARNING, \"%s\", warning);\n}\n\nstatic void PNGCBAPI\ndisplay_error(png_structp pp, png_const_charp error)\n{\n   struct display *dp = get_dp(pp);\n\n   display_log(dp, LIBPNG_ERROR, \"%s\", error);\n}\n\nstatic void\ndisplay_cache_file(struct display *dp, const char *filename)\n   /* Does the initial cache of the file. */\n{\n   FILE *fp;\n   int ret;\n\n   dp->filename = filename;\n\n   if (filename != NULL)\n   {\n      fp = fopen(filename, \"rb\");\n      if (fp == NULL)\n         display_log(dp, USER_ERROR, \"open failed: %s\", strerror(errno));\n   }\n\n   else\n      fp = stdin;\n\n   ret = buffer_from_file(&dp->original_file, fp);\n\n   fclose(fp);\n\n   if (ret != 0)\n      display_log(dp, APP_ERROR, \"read failed: %s\", strerror(ret));\n}\n\nstatic void\nbuffer_read(struct display *dp, struct buffer *bp, png_bytep data,\n   png_size_t size)\n{\n   struct buffer_list *last = bp->current;\n   size_t read_count = bp->read_count;\n\n   while (size > 0)\n   {\n      size_t avail;\n\n      if (last == NULL ||\n         (last == bp->last && read_count >= bp->end_count))\n      {\n         display_log(dp, USER_ERROR, \"file truncated (%lu bytes)\",\n            (unsigned long)size);\n         /*NOTREACHED*/\n         break;\n      }\n\n      else if (read_count >= sizeof last->buffer)\n      {\n         /* Move to the next buffer: */\n         last = last->next;\n         read_count = 0;\n         bp->current = last; /* Avoid update outside the loop */\n\n         /* And do a sanity check (the EOF case is caught above) */\n         if (last == NULL)\n         {\n            display_log(dp, INTERNAL_ERROR, \"damaged buffer list\");\n            /*NOTREACHED*/\n            break;\n         }\n      }\n\n      avail = (sizeof last->buffer) - read_count;\n      if (avail > size)\n         avail = size;\n\n      memcpy(data, last->buffer + read_count, avail);\n      read_count += avail;\n      size -= avail;\n      data += avail;\n   }\n\n   bp->read_count = read_count;\n}\n\nstatic void PNGCBAPI\nread_function(png_structp pp, png_bytep data, png_size_t size)\n{\n   buffer_read(get_dp(pp), get_buffer(pp), data, size);\n}\n\nstatic void\nread_png(struct display *dp, struct buffer *bp, const char *operation,\n   int transforms)\n{\n   png_structp pp;\n   png_infop   ip;\n\n   /* This cleans out any previous read and sets operation and transforms to\n    * empty.\n    */\n   display_clean_read(dp);\n\n   if (operation != NULL) /* else this is a verify and do not overwrite info */\n   {\n      dp->operation = operation;\n      dp->transforms = transforms;\n   }\n\n   dp->read_pp = pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,\n      display_error, display_warning);\n   if (pp == NULL)\n      display_log(dp, LIBPNG_ERROR, \"failed to create read struct\");\n\n   /* The png_read_png API requires us to make the info struct, but it does the\n    * call to png_read_info.\n    */\n   dp->read_ip = ip = png_create_info_struct(pp);\n   if (ip == NULL)\n      display_log(dp, LIBPNG_ERROR, \"failed to create info struct\");\n\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n      /* Remove the user limits, if any */\n      png_set_user_limits(pp, 0x7fffffff, 0x7fffffff);\n#  endif\n\n   /* Set the IO handling */\n   buffer_start_read(bp);\n   png_set_read_fn(pp, bp, read_function);\n\n   png_read_png(pp, ip, transforms, NULL/*params*/);\n\n#if 0 /* crazy debugging */\n   {\n      png_bytep pr = png_get_rows(pp, ip)[0];\n      size_t rb = png_get_rowbytes(pp, ip);\n      size_t cb;\n      char c = ' ';\n\n      fprintf(stderr, \"%.4x %2d (%3lu bytes):\", transforms, png_get_bit_depth(pp,ip), (unsigned long)rb);\n\n      for (cb=0; cb<rb; ++cb)\n         fputc(c, stderr), fprintf(stderr, \"%.2x\", pr[cb]), c='.';\n\n      fputc('\\n', stderr);\n   }\n#endif\n}\n\nstatic void\nupdate_display(struct display *dp)\n   /* called once after the first read to update all the info, original_pp and\n    * original_ip must have been filled in.\n    */\n{\n   png_structp pp;\n   png_infop   ip;\n\n   /* Now perform the initial read with a 0 tranform. */\n   read_png(dp, &dp->original_file, \"original read\", 0/*no transform*/);\n\n   /* Move the result to the 'original' fields */\n   dp->original_pp = pp = dp->read_pp, dp->read_pp = NULL;\n   dp->original_ip = ip = dp->read_ip, dp->read_ip = NULL;\n\n   dp->original_rowbytes = png_get_rowbytes(pp, ip);\n   if (dp->original_rowbytes == 0)\n      display_log(dp, LIBPNG_BUG, \"png_get_rowbytes returned 0\");\n\n   dp->chunks = png_get_valid(pp, ip, 0xffffffff);\n   if ((dp->chunks & PNG_INFO_IDAT) == 0) /* set by png_read_png */\n      display_log(dp, LIBPNG_BUG, \"png_read_png did not set IDAT flag\");\n\n   dp->original_rows = png_get_rows(pp, ip);\n   if (dp->original_rows == NULL)\n      display_log(dp, LIBPNG_BUG, \"png_read_png did not create row buffers\");\n\n   if (!png_get_IHDR(pp, ip,\n      &dp->width, &dp->height, &dp->bit_depth, &dp->color_type,\n      &dp->interlace_method, &dp->compression_method, &dp->filter_method))\n      display_log(dp, LIBPNG_BUG, \"png_get_IHDR failed\");\n\n   /* 'active' transforms are discovered based on the original image format;\n    * running one active transform can activate others.  At present the code\n    * does not attempt to determine the closure.\n    */\n   {\n      png_uint_32 chunks = dp->chunks;\n      int active = 0, inactive = 0;\n      int ct = dp->color_type;\n      int bd = dp->bit_depth;\n      unsigned int i;\n\n      for (i=0; i<TTABLE_SIZE; ++i) if (transform_info[i].name != NULL)\n      {\n         int transform = transform_info[i].transform;\n\n         if ((transform_info[i].valid_chunks == 0 ||\n               (transform_info[i].valid_chunks & chunks) != 0) &&\n            (transform_info[i].color_mask_required & ct) ==\n               transform_info[i].color_mask_required &&\n            (transform_info[i].color_mask_absent & ct) == 0 &&\n            (transform_info[i].bit_depths & bd) != 0 &&\n            (transform_info[i].when & TRANSFORM_R) != 0)\n            active |= transform;\n\n         else if ((transform_info[i].when & TRANSFORM_R) != 0)\n            inactive |= transform;\n      }\n\n      /* Some transforms appear multiple times in the table; the 'active' status\n       * is the logical OR of these and the inactive status must be adjusted to\n       * take this into account.\n       */\n      inactive &= ~active;\n\n      dp->active_transforms = active;\n      dp->ignored_transforms = inactive; /* excluding write-only transforms */\n   }\n}\n\nstatic int\ncompare_read(struct display *dp, int applied_transforms)\n{\n   /* Compare the png_info from read_ip with original_info */\n   size_t rowbytes;\n   png_uint_32 width, height;\n   int bit_depth, color_type;\n   int interlace_method, compression_method, filter_method;\n   const char *e = NULL;\n\n   png_get_IHDR(dp->read_pp, dp->read_ip, &width, &height, &bit_depth,\n      &color_type, &interlace_method, &compression_method, &filter_method);\n\n#  define C(item) if (item != dp->item) \\\n      display_log(dp, APP_WARNING, \"IHDR \" #item \"(%lu) changed to %lu\",\\\n         (unsigned long)dp->item, (unsigned long)item), e = #item\n\n   /* The IHDR should be identical: */\n   C(width);\n   C(height);\n   C(bit_depth);\n   C(color_type);\n   C(interlace_method);\n   C(compression_method);\n   C(filter_method);\n\n   /* 'e' remains set to the name of the last thing changed: */\n   if (e)\n      display_log(dp, APP_ERROR, \"IHDR changed (%s)\", e);\n\n   /* All the chunks from the original PNG should be preserved in the output PNG\n    * because the PNG format has not been changed.\n    */\n   {\n      unsigned long chunks =\n         png_get_valid(dp->read_pp, dp->read_ip, 0xffffffff);\n\n      if (chunks != dp->chunks)\n         display_log(dp, APP_FAIL, \"PNG chunks changed from 0x%lx to 0x%lx\",\n            (unsigned long)dp->chunks, chunks);\n   }\n\n   /* rowbytes should be the same */\n   rowbytes = png_get_rowbytes(dp->read_pp, dp->read_ip);\n\n   /* NOTE: on 64-bit systems this may trash the top bits of rowbytes,\n    * which could lead to weird error messages.\n    */\n   if (rowbytes != dp->original_rowbytes)\n      display_log(dp, APP_ERROR, \"PNG rowbytes changed from %lu to %lu\",\n         (unsigned long)dp->original_rowbytes, (unsigned long)rowbytes);\n\n   /* The rows should be the same too, unless the applied transforms includes\n    * the shift transform, in which case low bits may have been lost.\n    */\n   {\n      png_bytepp rows = png_get_rows(dp->read_pp, dp->read_ip);\n      unsigned int mask;  /* mask (if not zero) for the final byte */\n\n      if (bit_depth < 8)\n      {\n         /* Need the stray bits at the end, this depends only on the low bits\n          * of the image width; overflow does not matter.  If the width is an\n          * exact multiple of 8 bits this gives a mask of 0, not 0xff.\n          */\n         mask = 0xff & (0xff00 >> ((bit_depth * width) & 7));\n      }\n\n      else\n         mask = 0;\n\n      if (rows == NULL)\n         display_log(dp, LIBPNG_BUG, \"png_get_rows returned NULL\");\n\n      if ((applied_transforms & PNG_TRANSFORM_SHIFT) == 0 ||\n         (dp->active_transforms & PNG_TRANSFORM_SHIFT) == 0 ||\n         color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         unsigned long y;\n\n         for (y=0; y<height; ++y)\n         {\n            png_bytep row = rows[y];\n            png_bytep orig = dp->original_rows[y];\n\n            if (memcmp(row, orig, rowbytes-(mask != 0)) != 0 || (mask != 0 &&\n               ((row[rowbytes-1] & mask) != (orig[rowbytes-1] & mask))))\n            {\n               size_t x;\n\n               /* Find the first error */\n               for (x=0; x<rowbytes-1; ++x) if (row[x] != orig[x])\n                  break;\n\n               display_log(dp, APP_FAIL,\n                  \"byte(%lu,%lu) changed 0x%.2x -> 0x%.2x\",\n                  (unsigned long)x, (unsigned long)y, orig[x], row[x]);\n               return 0; /* don't keep reporting failed rows on 'continue' */\n            }\n         }\n      }\n\n      else\n#     ifdef PNG_sBIT_SUPPORTED\n      {\n         unsigned long y;\n         int bpp;   /* bits-per-pixel then bytes-per-pixel */\n         /* components are up to 8 bytes in size */\n         png_byte sig_bits[8];\n         png_color_8p sBIT;\n\n         if (png_get_sBIT(dp->read_pp, dp->read_ip, &sBIT) != PNG_INFO_sBIT)\n            display_log(dp, INTERNAL_ERROR,\n               \"active shift transform but no sBIT in file\");\n\n         switch (color_type)\n         {\n            case PNG_COLOR_TYPE_GRAY:\n               sig_bits[0] = sBIT->gray;\n               bpp = bit_depth;\n               break;\n\n            case PNG_COLOR_TYPE_GA:\n               sig_bits[0] = sBIT->gray;\n               sig_bits[1] = sBIT->alpha;\n               bpp = 2 * bit_depth;\n               break;\n\n            case PNG_COLOR_TYPE_RGB:\n               sig_bits[0] = sBIT->red;\n               sig_bits[1] = sBIT->green;\n               sig_bits[2] = sBIT->blue;\n               bpp = 3 * bit_depth;\n               break;\n\n            case PNG_COLOR_TYPE_RGBA:\n               sig_bits[0] = sBIT->red;\n               sig_bits[1] = sBIT->green;\n               sig_bits[2] = sBIT->blue;\n               sig_bits[3] = sBIT->alpha;\n               bpp = 4 * bit_depth;\n               break;\n\n            default:\n               display_log(dp, LIBPNG_ERROR, \"invalid colour type %d\",\n                  color_type);\n               /*NOTREACHED*/\n               bpp = 0;\n               break;\n         }\n\n         {\n            int b;\n\n            for (b=0; 8*b<bpp; ++b)\n            {\n               /* libpng should catch this; if not there is a security issue\n                * because an app (like this one) may overflow an array. In fact\n                * libpng doesn't catch this at present.\n                */\n               if (sig_bits[b] == 0 || sig_bits[b] > bit_depth/*!palette*/)\n                  display_log(dp, LIBPNG_BUG,\n                     \"invalid sBIT[%u]  value %d returned for PNG bit depth %d\",\n                     b, sig_bits[b], bit_depth);\n            }\n         }\n\n         if (bpp < 8 && bpp != bit_depth)\n         {\n            /* sanity check; this is a grayscale PNG; something is wrong in the\n             * code above.\n             */\n            display_log(dp, INTERNAL_ERROR, \"invalid bpp %u for bit_depth %u\",\n               bpp, bit_depth);\n         }\n\n         switch (bit_depth)\n         {\n            int b;\n\n            case 16: /* Two bytes per component, big-endian */\n               for (b = (bpp >> 4); b > 0; --b)\n               {\n                  unsigned int sig = (unsigned int)(0xffff0000 >> sig_bits[b]);\n\n                  sig_bits[2*b+1] = (png_byte)sig;\n                  sig_bits[2*b+0] = (png_byte)(sig >> 8); /* big-endian */\n               }\n               break;\n\n            case 8: /* One byte per component */\n               for (b=0; b*8 < bpp; ++b)\n                  sig_bits[b] = (png_byte)(0xff00 >> sig_bits[b]);\n               break;\n\n            case 1: /* allowed, but dumb */\n               /* Value is 1 */\n               sig_bits[0] = 0xff;\n               break;\n\n            case 2: /* Replicate 4 times */\n               /* Value is 1 or 2 */\n               b = 0x3 & ((0x3<<2) >> sig_bits[0]);\n               b |= b << 2;\n               b |= b << 4;\n               sig_bits[0] = (png_byte)b;\n               break;\n\n            case 4: /* Relicate twice */\n               /* Value is 1, 2, 3 or 4 */\n               b = 0xf & ((0xf << 4) >> sig_bits[0]);\n               b |= b << 4;\n               sig_bits[0] = (png_byte)b;\n               break;\n\n            default:\n               display_log(dp, LIBPNG_BUG, \"invalid bit depth %d\", bit_depth);\n               break;\n         }\n\n         /* Convert bpp to bytes; this gives '1' for low-bit depth grayscale,\n          * where there are multiple pixels per byte.\n          */\n         bpp = (bpp+7) >> 3;\n\n         /* The mask can be combined with sig_bits[0] */\n         if (mask != 0)\n         {\n            mask &= sig_bits[0];\n\n            if (bpp != 1 || mask == 0)\n               display_log(dp, INTERNAL_ERROR, \"mask calculation error %u, %u\",\n                  bpp, mask);\n         }\n\n         for (y=0; y<height; ++y)\n         {\n            png_bytep row = rows[y];\n            png_bytep orig = dp->original_rows[y];\n            unsigned long x;\n\n            for (x=0; x<(width-(mask!=0)); ++x)\n            {\n               int b;\n\n               for (b=0; b<bpp; ++b)\n               {\n                  if ((*row++ & sig_bits[b]) != (*orig++ & sig_bits[b]))\n                  {\n                     display_log(dp, APP_FAIL,\n                        \"significant bits at (%lu[%u],%lu) changed %.2x->%.2x\",\n                        x, b, y, orig[-1], row[-1]);\n                     return 0;\n                  }\n               }\n            }\n\n            if (mask != 0 && (*row & mask) != (*orig & mask))\n            {\n               display_log(dp, APP_FAIL,\n                  \"significant bits at (%lu[end],%lu) changed\", x, y);\n               return 0;\n            }\n         } /* for y */\n      }\n#     else /* !sBIT */\n         display_log(dp, INTERNAL_ERROR,\n               \"active shift transform but no sBIT support\");\n#     endif /* !sBIT */\n   }\n\n   return 1; /* compare succeeded */\n}\n\n#ifdef PNG_WRITE_PNG_SUPPORTED\nstatic void\nbuffer_write(struct display *dp, struct buffer *buffer, png_bytep data,\n   png_size_t size)\n   /* Generic write function used both from the write callback provided to\n    * libpng and from the generic read code.\n    */\n{\n   /* Write the data into the buffer, adding buffers as required */\n   struct buffer_list *last = buffer->last;\n   size_t end_count = buffer->end_count;\n\n   while (size > 0)\n   {\n      size_t avail;\n\n      if (end_count >= sizeof last->buffer)\n      {\n         if (last->next == NULL)\n         {\n            last = buffer_extend(last);\n\n            if (last == NULL)\n               display_log(dp, APP_ERROR, \"out of memory saving file\");\n         }\n\n         else\n            last = last->next;\n\n         buffer->last = last; /* avoid the need to rewrite every time */\n         end_count = 0;\n      }\n\n      avail = (sizeof last->buffer) - end_count;\n      if (avail > size)\n         avail = size;\n\n      memcpy(last->buffer + end_count, data, avail);\n      end_count += avail;\n      size -= avail;\n      data += avail;\n   }\n\n   buffer->end_count = end_count;\n}\n\nstatic void PNGCBAPI\nwrite_function(png_structp pp, png_bytep data, png_size_t size)\n{\n   buffer_write(get_dp(pp), get_buffer(pp), data, size);\n}\n\nstatic void\nwrite_png(struct display *dp, png_infop ip, int transforms)\n{\n   display_clean_write(dp); /* safety */\n\n   buffer_start_write(&dp->written_file);\n   dp->operation = \"write\";\n   dp->transforms = transforms;\n\n   dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp,\n      display_error, display_warning);\n\n   if (dp->write_pp == NULL)\n      display_log(dp, APP_ERROR, \"failed to create write png_struct\");\n\n   png_set_write_fn(dp->write_pp, &dp->written_file, write_function,\n      NULL/*flush*/);\n\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n      /* Remove the user limits, if any */\n      png_set_user_limits(dp->write_pp, 0x7fffffff, 0x7fffffff);\n#  endif\n\n   /* Certain transforms require the png_info to be zapped to allow the\n    * transform to work correctly.\n    */\n   if (transforms & (PNG_TRANSFORM_PACKING|\n                     PNG_TRANSFORM_STRIP_FILLER|\n                     PNG_TRANSFORM_STRIP_FILLER_BEFORE))\n   {\n      int ct = dp->color_type;\n\n      if (transforms & (PNG_TRANSFORM_STRIP_FILLER|\n                        PNG_TRANSFORM_STRIP_FILLER_BEFORE))\n         ct &= ~PNG_COLOR_MASK_ALPHA;\n\n      png_set_IHDR(dp->write_pp, ip, dp->width, dp->height, dp->bit_depth, ct,\n         dp->interlace_method, dp->compression_method, dp->filter_method);\n   }\n\n   png_write_png(dp->write_pp, ip, transforms, NULL/*params*/);\n\n   /* Clean it on the way out - if control returns to the caller then the\n    * written_file contains the required data.\n    */\n   display_clean_write(dp);\n}\n#endif /* WRITE_PNG */\n\nstatic int\nskip_transform(struct display *dp, int tr)\n   /* Helper to test for a bad combo and log it if it is skipped */\n{\n   if ((dp->options & SKIP_BUGS) != 0 && is_bad_combo(tr))\n   {\n      /* Log this to stdout if logging is on, otherwise just do an information\n       * display_log.\n       */\n      if ((dp->options & LOG_SKIPPED) != 0)\n      {\n         printf(\"SKIP: %s transforms \", dp->filename);\n\n         while (tr != 0)\n         {\n            int next = first_transform(tr);\n            tr &= ~next;\n\n            printf(\"%s\", transform_name(next));\n            if (tr != 0)\n               putchar('+');\n         }\n\n         putchar('\\n');\n      }\n\n      else\n         display_log(dp, INFORMATION, \"%s: skipped known bad combo 0x%x\",\n            dp->filename, tr);\n\n      return 1; /* skip */\n   }\n\n   return 0; /* don't skip */\n}\n\nstatic void\ntest_one_file(struct display *dp, const char *filename)\n{\n   /* First cache the file and update the display original file\n    * information for the new file.\n    */\n   dp->operation = \"cache file\";\n   dp->transforms = 0;\n   display_cache_file(dp, filename);\n   update_display(dp);\n\n   /* First test: if there are options that should be ignored for this file\n    * verify that they really are ignored.\n    */\n   if (dp->ignored_transforms != 0)\n   {\n      read_png(dp, &dp->original_file, \"ignored transforms\",\n         dp->ignored_transforms);\n\n      /* The result should be identical to the original_rows */\n      if (!compare_read(dp, 0/*transforms applied*/))\n         return; /* no point testing more */\n   }\n\n#ifdef PNG_WRITE_PNG_SUPPORTED\n   /* Second test: write the original PNG data out to a new file (to test the\n    * write side) then read the result back in and make sure that it hasn't\n    * changed.\n    */\n   dp->operation = \"write\";\n   write_png(dp, dp->original_ip, 0/*transforms*/);\n   read_png(dp, &dp->written_file, NULL, 0/*transforms*/);\n   if (!compare_read(dp, 0/*transforms applied*/))\n      return;\n#endif\n\n   /* Third test: the active options.  Test each in turn, or, with the\n    * EXHAUSTIVE option, test all possible combinations.\n    */\n   {\n      /* Use unsigned int here because the code below to increment through all\n       * the possibilities exhaustively has to use a compare and that must be\n       * unsigned, because some transforms are negative on a 16-bit system.\n       */\n      unsigned int active = dp->active_transforms;\n      const int exhaustive = (dp->options & EXHAUSTIVE) != 0;\n      unsigned int current = first_transform(active);\n      unsigned int bad_transforms = 0;\n      unsigned int bad_combo = ~0U;    /* bitwise AND of failing transforms */\n      unsigned int bad_combo_list = 0; /* bitwise OR of failures */\n\n      for (;;)\n      {\n         read_png(dp, &dp->original_file, \"active transforms\", current);\n\n         /* If this involved any irreversible transformations then if we write\n          * it out with just the reversible transformations and read it in again\n          * with the same transforms we should get the same thing.  At present\n          * this isn't done - it just seems like a waste of time and it would\n          * require two sets of read png_struct/png_info.\n          *\n          * If there were no irreversible transformations then if we write it\n          * out and read it back in again (without the reversible transforms)\n          * we should get back to the place where we started.\n          */\n#ifdef PNG_WRITE_PNG_SUPPORTED\n         if ((current & write_transforms) == current)\n         {\n            /* All transforms reversible: write the PNG with the transformations\n             * reversed, then read it back in with no transformations.  The\n             * result should be the same as the original apart from the loss of\n             * low order bits because of the SHIFT/sBIT transform.\n             */\n            dp->operation = \"reversible transforms\";\n            write_png(dp, dp->read_ip, current);\n\n            /* And if this is read back in, because all the transformations were\n             * reversible, the result should be the same.\n             */\n            read_png(dp, &dp->written_file, NULL, 0);\n            if (!compare_read(dp, current/*for the SHIFT/sBIT transform*/))\n            {\n               /* This set of transforms failed.  If a single bit is set - if\n                * there is just one transform - don't include this in further\n                * 'exhaustive' tests.  Notice that each transform is tested on\n                * its own before testing combos in the exhaustive case.\n                */\n               if (is_combo(current))\n               {\n                  bad_combo &= current;\n                  bad_combo_list |= current;\n               }\n\n               else\n                  bad_transforms |= current;\n            }\n         }\n#endif\n\n         /* Now move to the next transform */\n         if (exhaustive) /* all combinations */\n         {\n            unsigned int next = current;\n\n            do\n            {\n               if (next == read_transforms) /* Everything tested */\n                  goto combo;\n\n               ++next;\n            }  /* skip known bad combos if the relevant option is set; skip\n                * combos involving known bad single transforms in all cases.\n                */\n            while (  (next & read_transforms) <= current\n                  || (next & active) == 0 /* skip cases that do nothing */\n                  || (next & bad_transforms) != 0\n                  || skip_transform(dp, next));\n\n            assert((next & read_transforms) == next);\n            current = next;\n         }\n\n         else /* one at a time */\n         {\n            active &= ~current;\n\n            if (active == 0)\n               goto combo;\n\n            current = first_transform(active);\n         }\n      }\n\ncombo:\n      if (dp->options & FIND_BAD_COMBOS)\n      {\n         /* bad_combos identifies the combos that occur in all failing cases;\n          * bad_combo_list identifies transforms that do not prevent the\n          * failure.\n          */\n         if (bad_combo != ~0U)\n            printf(\"%s[0x%x]: PROBLEM: 0x%x[0x%x] ANTIDOTE: 0x%x\\n\",\n               dp->filename, active, bad_combo, bad_combo_list,\n               rw_transforms & ~bad_combo_list);\n\n         else\n            printf(\"%s: no %sbad combos found\\n\", dp->filename,\n               (dp->options & SKIP_BUGS) ? \"additional \" : \"\");\n      }\n   }\n}\n\nstatic int\ndo_test(struct display *dp, const char *file)\n   /* Exists solely to isolate the setjmp clobbers */\n{\n   int ret = setjmp(dp->error_return);\n\n   if (ret == 0)\n   {\n      test_one_file(dp, file);\n      return 0;\n   }\n\n   else if (ret < ERRORS) /* shouldn't longjmp on warnings */\n      display_log(dp, INTERNAL_ERROR, \"unexpected return code %d\", ret);\n\n   return ret;\n}\n\nint\nmain(const int argc, const char * const * const argv)\n{\n   /* For each file on the command line test it with a range of transforms */\n   int option_end, ilog = 0;\n   struct display d;\n\n   validate_T();\n   display_init(&d);\n\n   for (option_end=1; option_end<argc; ++option_end)\n   {\n      const char *name = argv[option_end];\n\n      if (strcmp(name, \"--verbose\") == 0)\n         d.options = (d.options & ~LEVEL_MASK) | VERBOSE;\n\n      else if (strcmp(name, \"--warnings\") == 0)\n         d.options = (d.options & ~LEVEL_MASK) | WARNINGS;\n\n      else if (strcmp(name, \"--errors\") == 0)\n         d.options = (d.options & ~LEVEL_MASK) | ERRORS;\n\n      else if (strcmp(name, \"--quiet\") == 0)\n         d.options = (d.options & ~LEVEL_MASK) | QUIET;\n\n      else if (strcmp(name, \"--exhaustive\") == 0)\n         d.options |= EXHAUSTIVE;\n\n      else if (strcmp(name, \"--fast\") == 0)\n         d.options &= ~EXHAUSTIVE;\n\n      else if (strcmp(name, \"--strict\") == 0)\n         d.options |= STRICT;\n\n      else if (strcmp(name, \"--relaxed\") == 0)\n         d.options &= ~STRICT;\n\n      else if (strcmp(name, \"--log\") == 0)\n      {\n         ilog = option_end; /* prevent display */\n         d.options |= LOG;\n      }\n\n      else if (strcmp(name, \"--nolog\") == 0)\n         d.options &= ~LOG;\n\n      else if (strcmp(name, \"--continue\") == 0)\n         d.options |= CONTINUE;\n\n      else if (strcmp(name, \"--stop\") == 0)\n         d.options &= ~CONTINUE;\n\n      else if (strcmp(name, \"--skip-bugs\") == 0)\n         d.options |= SKIP_BUGS;\n\n      else if (strcmp(name, \"--test-all\") == 0)\n         d.options &= ~SKIP_BUGS;\n\n      else if (strcmp(name, \"--log-skipped\") == 0)\n         d.options |= LOG_SKIPPED;\n\n      else if (strcmp(name, \"--nolog-skipped\") == 0)\n         d.options &= ~LOG_SKIPPED;\n\n      else if (strcmp(name, \"--find-bad-combos\") == 0)\n         d.options |= FIND_BAD_COMBOS;\n\n      else if (strcmp(name, \"--nofind-bad-combos\") == 0)\n         d.options &= ~FIND_BAD_COMBOS;\n\n      else if (strcmp(name, \"--list-combos\") == 0)\n         d.options |= LIST_COMBOS;\n\n      else if (strcmp(name, \"--nolist-combos\") == 0)\n         d.options &= ~LIST_COMBOS;\n\n      else if (name[0] == '-' && name[1] == '-')\n      {\n         fprintf(stderr, \"pngimage: %s: unknown option\\n\", name);\n         return 99;\n      }\n\n      else\n         break; /* Not an option */\n   }\n\n   {\n      int i;\n      int errors = 0;\n\n      for (i=option_end; i<argc; ++i)\n      {\n         {\n            int ret = do_test(&d, argv[i]);\n\n            if (ret > QUIET) /* abort on user or internal error */\n               return 99;\n         }\n\n         /* Here on any return, including failures, except user/internal issues\n          */\n         {\n            const int pass = (d.options & STRICT) ?\n               RESULT_STRICT(d.results) : RESULT_RELAXED(d.results);\n\n            if (!pass)\n               ++errors;\n\n            if (d.options & LOG)\n            {\n               int j;\n\n               printf(\"%s: pngimage \", pass ? \"PASS\" : \"FAIL\");\n\n               for (j=1; j<option_end; ++j) if (j != ilog)\n                  printf(\"%s \", argv[j]);\n\n               printf(\"%s\\n\", d.filename);\n            }\n         }\n\n         display_clean(&d);\n      }\n\n      /* Release allocated memory */\n      display_destroy(&d);\n\n      return errors != 0;\n   }\n}\n#else /* !READ_PNG */\nint\nmain(void)\n{\n   fprintf(stderr, \"pngimage: no support for png_read/write_image\\n\");\n   return SKIP;\n}\n#endif\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/pngstest-errors.h",
    "content": "/* contrib/libtests/pngstest-errors.h\n *\n * BUILT USING: libpng version 1.6.19beta03 - September 25, 2015\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * THIS IS A MACHINE GENERATED FILE: do not edit it directly!\n * Instead run:\n *\n *    pngstest --accumulate\n *\n * on as many PNG files as possible; at least PNGSuite and\n * contrib/libtests/testpngs.\n */\nstatic png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =\n{\n { /* input: sRGB-gray */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 }, { 0, 0, 372, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: sRGB-gray+alpha */\n  { 0, 19, 0, 0 }, { 0, 0, 0, 0 }, { 0, 20, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: sRGB-rgb */\n  { 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 893, 0 }, { 0, 0, 893, 0 }, { 0, 0, 811, 0 }, { 0, 0, 811, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: sRGB-rgb+alpha */\n  { 0, 16, 17, 0 }, { 0, 17, 17, 0 }, { 0, 19, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 850, 875, 0 }, { 0, 850, 875, 0 }, { 0, 897, 788, 0 }, { 0, 897, 788, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: linear-gray */\n  { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: linear-gray+alpha */\n  { 0, 74, 9, 0 }, { 0, 20, 9, 0 }, { 0, 74, 9, 0 }, { 0, 20, 9, 0 },\n  { 0, 0, 0, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: linear-rgb */\n  { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },\n  { 0, 0, 4, 0 }, { 0, 0, 4, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: linear-rgb+alpha */\n  { 0, 126, 143, 0 }, { 0, 11, 7, 0 }, { 0, 74, 9, 0 }, { 0, 17, 9, 0 },\n  { 0, 4, 4, 0 }, { 0, 5, 4, 0 }, { 0, 0, 0, 0 }, { 0, 1, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-sRGB-gray */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-sRGB-gray+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-sRGB-rgb */\n  { 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },\n  { 0, 0, 673, 0 }, { 0, 0, 673, 0 }, { 0, 0, 674, 0 }, { 0, 0, 674, 0 },\n  { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 460, 0 }, { 0, 0, 460, 0 }, { 0, 0, 263, 0 }, { 0, 0, 263, 0 }\n }, { /* input: color-mapped-sRGB-rgb+alpha */\n  { 0, 6, 8, 0 }, { 0, 7, 8, 0 }, { 0, 75, 9, 0 }, { 0, 9, 9, 0 },\n  { 0, 585, 427, 0 }, { 0, 585, 427, 0 }, { 0, 717, 514, 0 }, { 0, 717, 514, 0 },\n  { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 13323, 460, 0 }, { 0, 427, 460, 0 }, { 0, 16480, 263, 0 }, { 0, 243, 263, 0 }\n }, { /* input: color-mapped-linear-gray */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-gray+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 253, 282, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-rgb */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 265, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-rgb+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 },\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 243, 265, 0 }\n }\n};\nstatic png_uint_16 gpc_error_via_linear[16][4/*out*/][4] =\n{\n { /* input: sRGB-gray */\n  { 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }, { 0, 0, 7, 0 }\n }, { /* input: sRGB-gray+alpha */\n  { 0, 15, 15, 0 }, { 0, 186, 15, 0 }, { 0, 15, 15, 0 }, { 0, 186, 15, 0 }\n }, { /* input: sRGB-rgb */\n  { 0, 0, 20, 0 }, { 0, 0, 20, 0 }, { 0, 0, 15, 0 }, { 0, 0, 15, 0 }\n }, { /* input: sRGB-rgb+alpha */\n  { 0, 16, 17, 0 }, { 0, 187, 17, 0 }, { 0, 15, 15, 0 }, { 0, 186, 15, 0 }\n }, { /* input: linear-gray */\n  { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }\n }, { /* input: linear-gray+alpha */\n  { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }\n }, { /* input: linear-rgb */\n  { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }, { 0, 0, 1, 0 }\n }, { /* input: linear-rgb+alpha */\n  { 0, 1, 1, 0 }, { 0, 9, 1, 0 }, { 0, 1, 1, 0 }, { 0, 1, 1, 0 }\n }, { /* input: color-mapped-sRGB-gray */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-sRGB-gray+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-sRGB-rgb */\n  { 0, 0, 13, 0 }, { 0, 0, 13, 0 }, { 0, 0, 14, 0 }, { 0, 0, 14, 0 }\n }, { /* input: color-mapped-sRGB-rgb+alpha */\n  { 0, 4, 8, 0 }, { 0, 9, 8, 0 }, { 0, 9, 5, 0 }, { 0, 32, 5, 0 }\n }, { /* input: color-mapped-linear-gray */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-gray+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-rgb */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }, { /* input: color-mapped-linear-rgb+alpha */\n  { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0, 0, 0, 0 }\n }\n};\nstatic png_uint_16 gpc_error_to_colormap[8/*i*/][8/*o*/][4] =\n{\n { /* input: sRGB-gray */\n  { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 }, { 0, 0, 9, 0 },\n  { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }, { 0, 0, 560, 0 }\n }, { /* input: sRGB-gray+alpha */\n  { 0, 19, 9, 0 }, { 0, 255, 9, 25 }, { 0, 88, 9, 0 }, { 0, 255, 9, 25 },\n  { 0, 1012, 928, 0 }, { 0, 16026, 928, 6425 }, { 0, 1012, 928, 0 }, { 0, 16026, 928, 6425 }\n }, { /* input: sRGB-rgb */\n  { 0, 0, 19, 0 }, { 0, 0, 19, 0 }, { 0, 0, 25, 0 }, { 0, 0, 25, 0 },\n  { 0, 0, 962, 0 }, { 0, 0, 962, 0 }, { 0, 0, 13677, 0 }, { 0, 0, 13677, 0 }\n }, { /* input: sRGB-rgb+alpha */\n  { 0, 63, 77, 0 }, { 0, 255, 19, 25 }, { 0, 225, 25, 0 }, { 0, 255, 25, 67 },\n  { 0, 17534, 18491, 0 }, { 0, 15736, 2824, 6425 }, { 0, 14019, 13677, 0 }, { 0, 50115, 13677, 17219 }\n }, { /* input: linear-gray */\n  { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 73, 0 },\n  { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }, { 0, 0, 18817, 0 }\n }, { /* input: linear-gray+alpha */\n  { 0, 74, 74, 0 }, { 0, 255, 74, 25 }, { 0, 99, 74, 0 }, { 0, 255, 74, 25 },\n  { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 }, { 0, 18919, 18907, 0 }, { 0, 24549, 18907, 6553 }\n }, { /* input: linear-rgb */\n  { 0, 0, 73, 0 }, { 0, 0, 73, 0 }, { 0, 0, 98, 0 }, { 0, 0, 98, 0 },\n  { 0, 0, 18664, 0 }, { 0, 0, 18664, 0 }, { 0, 0, 24998, 0 }, { 0, 0, 24998, 0 }\n }, { /* input: linear-rgb+alpha */\n  { 0, 181, 196, 0 }, { 0, 255, 61, 25 }, { 206, 187, 98, 0 }, { 0, 255, 98, 67 },\n  { 0, 18141, 18137, 0 }, { 0, 17494, 17504, 6553 }, { 0, 24979, 24992, 0 }, { 0, 49172, 24992, 17347 }\n }\n};\n/* END MACHINE GENERATED */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/pngstest.c",
    "content": "/*-\n * pngstest.c\n *\n * Copyright (c) 2013-2016 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Test for the PNG 'simplified' APIs.\n */\n#define _ISOC90_SOURCE 1\n#define MALLOC_CHECK_ 2/*glibc facility: turn on debugging*/\n\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <errno.h>\n#include <ctype.h>\n#include <math.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n/* 1.6.1 added support for the configure test harness, which uses 77 to indicate\n * a skipped test, in earlier versions we need to succeed on a skipped test, so:\n */\n#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)\n#  define SKIP 77\n#else\n#  define SKIP 0\n#endif\n\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED /* Else nothing can be done */\n#include \"../tools/sRGB.h\"\n\n/* KNOWN ISSUES\n *\n * These defines switch on alternate algorithms for format conversions to match\n * the current libpng implementation; they are set to allow pngstest to pass\n * even though libpng is producing answers that are not as correct as they\n * should be.\n */\n#define ALLOW_UNUSED_GPC 0\n   /* If true include unused static GPC functions and declare an external array\n    * of them to hide the fact that they are unused.  This is for development\n    * use while testing the correct function to use to take into account libpng\n    * misbehavior, such as using a simple power law to correct sRGB to linear.\n    */\n\n/* The following is to support direct compilation of this file as C++ */\n#ifdef __cplusplus\n#  define voidcast(type, value) static_cast<type>(value)\n#  define aligncastconst(type, value) \\\n      static_cast<type>(static_cast<const void*>(value))\n#else\n#  define voidcast(type, value) (value)\n#  define aligncastconst(type, value) ((const void*)(value))\n#endif /* __cplusplus */\n\n/* During parallel runs of pngstest each temporary file needs a unique name,\n * this is used to permit uniqueness using a command line argument which can be\n * up to 22 characters long.\n */\nstatic char tmpf[23] = \"TMP\";\n\n/* Generate random bytes.  This uses a boring repeatable algorithm and it\n * is implemented here so that it gives the same set of numbers on every\n * architecture.  It's a linear congruential generator (Knuth or Sedgewick\n * \"Algorithms\") but it comes from the 'feedback taps' table in Horowitz and\n * Hill, \"The Art of Electronics\".\n */\nstatic void\nmake_random_bytes(png_uint_32* seed, void* pv, size_t size)\n{\n   png_uint_32 u0 = seed[0], u1 = seed[1];\n   png_bytep bytes = voidcast(png_bytep, pv);\n\n   /* There are thirty three bits, the next bit in the sequence is bit-33 XOR\n    * bit-20.  The top 1 bit is in u1, the bottom 32 are in u0.\n    */\n   size_t i;\n   for (i=0; i<size; ++i)\n   {\n      /* First generate 8 new bits then shift them in at the end. */\n      png_uint_32 u = ((u0 >> (20-8)) ^ ((u1 << 7) | (u0 >> (32-7)))) & 0xff;\n      u1 <<= 8;\n      u1 |= u0 >> 24;\n      u0 <<= 8;\n      u0 |= u;\n      *bytes++ = (png_byte)u;\n   }\n\n   seed[0] = u0;\n   seed[1] = u1;\n}\n\nstatic png_uint_32 color_seed[2];\n\nstatic void\nreseed(void)\n{\n   color_seed[0] = 0x12345678U;\n   color_seed[1] = 0x9abcdefU;\n}\n\nstatic void\nrandom_color(png_colorp color)\n{\n   make_random_bytes(color_seed, color, sizeof *color);\n}\n\n/* Math support - neither Cygwin nor Visual Studio have C99 support and we need\n * a predictable rounding function, so make one here:\n */\nstatic double\nclosestinteger(double x)\n{\n   return floor(x + .5);\n}\n\n/* Cast support: remove GCC whines. */\nstatic png_byte\nu8d(double d)\n{\n   d = closestinteger(d);\n   return (png_byte)d;\n}\n\nstatic png_uint_16\nu16d(double d)\n{\n   d = closestinteger(d);\n   return (png_uint_16)d;\n}\n\n/* sRGB support: use exact calculations rounded to the nearest int, see the\n * fesetround() call in main().  sRGB_to_d optimizes the 8 to 16-bit conversion.\n */\nstatic double sRGB_to_d[256];\nstatic double g22_to_d[256];\n\nstatic void\ninit_sRGB_to_d(void)\n{\n   int i;\n\n   sRGB_to_d[0] = 0;\n   for (i=1; i<255; ++i)\n      sRGB_to_d[i] = linear_from_sRGB(i/255.);\n   sRGB_to_d[255] = 1;\n\n   g22_to_d[0] = 0;\n   for (i=1; i<255; ++i)\n      g22_to_d[i] = pow(i/255., 1/.45455);\n   g22_to_d[255] = 1;\n}\n\nstatic png_byte\nsRGB(double linear /*range 0.0 .. 1.0*/)\n{\n   return u8d(255 * sRGB_from_linear(linear));\n}\n\nstatic png_byte\nisRGB(int fixed_linear)\n{\n   return sRGB(fixed_linear / 65535.);\n}\n\n#if 0 /* not used */\nstatic png_byte\nunpremultiply(int component, int alpha)\n{\n   if (alpha <= component)\n      return 255; /* Arbitrary, but consistent with the libpng code */\n\n   else if (alpha >= 65535)\n      return isRGB(component);\n\n   else\n      return sRGB((double)component / alpha);\n}\n#endif\n\nstatic png_uint_16\nilinear(int fixed_srgb)\n{\n   return u16d(65535 * sRGB_to_d[fixed_srgb]);\n}\n\nstatic png_uint_16\nilineara(int fixed_srgb, int alpha)\n{\n   return u16d((257 * alpha) * sRGB_to_d[fixed_srgb]);\n}\n\nstatic png_uint_16\nilinear_g22(int fixed_srgb)\n{\n   return u16d(65535 * g22_to_d[fixed_srgb]);\n}\n\n#if ALLOW_UNUSED_GPC\nstatic png_uint_16\nilineara_g22(int fixed_srgb, int alpha)\n{\n   return u16d((257 * alpha) * g22_to_d[fixed_srgb]);\n}\n#endif\n\nstatic double\nYfromRGBint(int ir, int ig, int ib)\n{\n   double r = ir;\n   double g = ig;\n   double b = ib;\n   return YfromRGB(r, g, b);\n}\n\n#if 0 /* unused */\n/* The error that results from using a 2.2 power law in place of the correct\n * sRGB transform, given an 8-bit value which might be either sRGB or power-law.\n */\nstatic int\npower_law_error8(int value)\n{\n   if (value > 0 && value < 255)\n   {\n      double vd = value / 255.;\n      double e = fabs(\n         pow(sRGB_to_d[value], 1/2.2) - sRGB_from_linear(pow(vd, 2.2)));\n\n      /* Always allow an extra 1 here for rounding errors */\n      e = 1+floor(255 * e);\n      return (int)e;\n   }\n\n   return 0;\n}\n\nstatic int error_in_sRGB_roundtrip = 56; /* by experiment */\nstatic int\npower_law_error16(int value)\n{\n   if (value > 0 && value < 65535)\n   {\n      /* Round trip the value through an 8-bit representation but using\n       * non-matching to/from conversions.\n       */\n      double vd = value / 65535.;\n      double e = fabs(\n         pow(sRGB_from_linear(vd), 2.2) - linear_from_sRGB(pow(vd, 1/2.2)));\n\n      /* Always allow an extra 1 here for rounding errors */\n      e = error_in_sRGB_roundtrip+floor(65535 * e);\n      return (int)e;\n   }\n\n   return 0;\n}\n\nstatic int\ncompare_8bit(int v1, int v2, int error_limit, int multiple_algorithms)\n{\n   int e = abs(v1-v2);\n   int ev1, ev2;\n\n   if (e <= error_limit)\n      return 1;\n\n   if (!multiple_algorithms)\n      return 0;\n\n   ev1 = power_law_error8(v1);\n   if (e <= ev1)\n      return 1;\n\n   ev2 = power_law_error8(v2);\n   if (e <= ev2)\n      return 1;\n\n   return 0;\n}\n\nstatic int\ncompare_16bit(int v1, int v2, int error_limit, int multiple_algorithms)\n{\n   int e = abs(v1-v2);\n   int ev1, ev2;\n\n   if (e <= error_limit)\n      return 1;\n\n   /* \"multiple_algorithms\" in this case means that a color-map has been\n    * involved somewhere, so we can deduce that the values were forced to 8-bit\n    * (like the via_linear case for 8-bit.)\n    */\n   if (!multiple_algorithms)\n      return 0;\n\n   ev1 = power_law_error16(v1);\n   if (e <= ev1)\n      return 1;\n\n   ev2 = power_law_error16(v2);\n   if (e <= ev2)\n      return 1;\n\n   return 0;\n}\n#endif /* unused */\n\n#define USE_FILE 1       /* else memory */\n#define USE_STDIO 2      /* else use file name */\n#define STRICT 4         /* fail on warnings too */\n#define VERBOSE 8\n#define KEEP_TMPFILES 16 /* else delete temporary files */\n#define KEEP_GOING 32\n#define ACCUMULATE 64\n#define FAST_WRITE 128\n#define sRGB_16BIT 256\n#define NO_RESEED  512   /* do not reseed on each new file */\n#define GBG_ERROR 1024   /* do not ignore the gamma+background_rgb_to_gray\n                          * libpng warning. */\n\nstatic void\nprint_opts(png_uint_32 opts)\n{\n   if (opts & USE_FILE)\n      printf(\" --file\");\n   if (opts & USE_STDIO)\n      printf(\" --stdio\");\n   if (!(opts & STRICT))\n      printf(\" --nostrict\");\n   if (opts & VERBOSE)\n      printf(\" --verbose\");\n   if (opts & KEEP_TMPFILES)\n      printf(\" --preserve\");\n   if (opts & KEEP_GOING)\n      printf(\" --keep-going\");\n   if (opts & ACCUMULATE)\n      printf(\" --accumulate\");\n   if (!(opts & FAST_WRITE)) /* --fast is currently the default */\n      printf(\" --slow\");\n   if (opts & sRGB_16BIT)\n      printf(\" --sRGB-16bit\");\n   if (opts & NO_RESEED)\n      printf(\" --noreseed\");\n#if PNG_LIBPNG_VER < 10700 /* else on by default */\n   if (opts & GBG_ERROR)\n      printf(\" --fault-gbg-warning\");\n#endif\n}\n\n#define FORMAT_NO_CHANGE 0x80000000 /* additional flag */\n\n/* A name table for all the formats - defines the format of the '+' arguments to\n * pngstest.\n */\n#define FORMAT_COUNT 64\n#define FORMAT_MASK 0x3f\nstatic PNG_CONST char * PNG_CONST format_names[FORMAT_COUNT] =\n{\n   \"sRGB-gray\",\n   \"sRGB-gray+alpha\",\n   \"sRGB-rgb\",\n   \"sRGB-rgb+alpha\",\n   \"linear-gray\",\n   \"linear-gray+alpha\",\n   \"linear-rgb\",\n   \"linear-rgb+alpha\",\n\n   \"color-mapped-sRGB-gray\",\n   \"color-mapped-sRGB-gray+alpha\",\n   \"color-mapped-sRGB-rgb\",\n   \"color-mapped-sRGB-rgb+alpha\",\n   \"color-mapped-linear-gray\",\n   \"color-mapped-linear-gray+alpha\",\n   \"color-mapped-linear-rgb\",\n   \"color-mapped-linear-rgb+alpha\",\n\n   \"sRGB-gray\",\n   \"sRGB-gray+alpha\",\n   \"sRGB-bgr\",\n   \"sRGB-bgr+alpha\",\n   \"linear-gray\",\n   \"linear-gray+alpha\",\n   \"linear-bgr\",\n   \"linear-bgr+alpha\",\n\n   \"color-mapped-sRGB-gray\",\n   \"color-mapped-sRGB-gray+alpha\",\n   \"color-mapped-sRGB-bgr\",\n   \"color-mapped-sRGB-bgr+alpha\",\n   \"color-mapped-linear-gray\",\n   \"color-mapped-linear-gray+alpha\",\n   \"color-mapped-linear-bgr\",\n   \"color-mapped-linear-bgr+alpha\",\n\n   \"sRGB-gray\",\n   \"alpha+sRGB-gray\",\n   \"sRGB-rgb\",\n   \"alpha+sRGB-rgb\",\n   \"linear-gray\",\n   \"alpha+linear-gray\",\n   \"linear-rgb\",\n   \"alpha+linear-rgb\",\n\n   \"color-mapped-sRGB-gray\",\n   \"color-mapped-alpha+sRGB-gray\",\n   \"color-mapped-sRGB-rgb\",\n   \"color-mapped-alpha+sRGB-rgb\",\n   \"color-mapped-linear-gray\",\n   \"color-mapped-alpha+linear-gray\",\n   \"color-mapped-linear-rgb\",\n   \"color-mapped-alpha+linear-rgb\",\n\n   \"sRGB-gray\",\n   \"alpha+sRGB-gray\",\n   \"sRGB-bgr\",\n   \"alpha+sRGB-bgr\",\n   \"linear-gray\",\n   \"alpha+linear-gray\",\n   \"linear-bgr\",\n   \"alpha+linear-bgr\",\n\n   \"color-mapped-sRGB-gray\",\n   \"color-mapped-alpha+sRGB-gray\",\n   \"color-mapped-sRGB-bgr\",\n   \"color-mapped-alpha+sRGB-bgr\",\n   \"color-mapped-linear-gray\",\n   \"color-mapped-alpha+linear-gray\",\n   \"color-mapped-linear-bgr\",\n   \"color-mapped-alpha+linear-bgr\",\n};\n\n/* Decode an argument to a format number. */\nstatic png_uint_32\nformatof(const char *arg)\n{\n   char *ep;\n   unsigned long format = strtoul(arg, &ep, 0);\n\n   if (ep > arg && *ep == 0 && format < FORMAT_COUNT)\n      return (png_uint_32)format;\n\n   else for (format=0; format < FORMAT_COUNT; ++format)\n   {\n      if (strcmp(format_names[format], arg) == 0)\n         return (png_uint_32)format;\n   }\n\n   fprintf(stderr, \"pngstest: format name '%s' invalid\\n\", arg);\n   return FORMAT_COUNT;\n}\n\n/* Bitset/test functions for formats */\n#define FORMAT_SET_COUNT (FORMAT_COUNT / 32)\ntypedef struct\n{\n   png_uint_32 bits[FORMAT_SET_COUNT];\n}\nformat_list;\n\nstatic void format_init(format_list *pf)\n{\n   int i;\n   for (i=0; i<FORMAT_SET_COUNT; ++i)\n      pf->bits[i] = 0; /* All off */\n}\n\n#if 0 /* currently unused */\nstatic void format_clear(format_list *pf)\n{\n   int i;\n   for (i=0; i<FORMAT_SET_COUNT; ++i)\n      pf->bits[i] = 0;\n}\n#endif\n\nstatic int format_is_initial(format_list *pf)\n{\n   int i;\n   for (i=0; i<FORMAT_SET_COUNT; ++i)\n      if (pf->bits[i] != 0)\n         return 0;\n\n   return 1;\n}\n\nstatic int format_set(format_list *pf, png_uint_32 format)\n{\n   if (format < FORMAT_COUNT)\n      return pf->bits[format >> 5] |= ((png_uint_32)1) << (format & 31);\n\n   return 0;\n}\n\n#if 0 /* currently unused */\nstatic int format_unset(format_list *pf, png_uint_32 format)\n{\n   if (format < FORMAT_COUNT)\n      return pf->bits[format >> 5] &= ~((png_uint_32)1) << (format & 31);\n\n   return 0;\n}\n#endif\n\nstatic int format_isset(format_list *pf, png_uint_32 format)\n{\n   return format < FORMAT_COUNT &&\n      (pf->bits[format >> 5] & (((png_uint_32)1) << (format & 31))) != 0;\n}\n\nstatic void format_default(format_list *pf, int redundant)\n{\n   if (redundant)\n   {\n      int i;\n\n      /* set everything, including flags that are pointless */\n      for (i=0; i<FORMAT_SET_COUNT; ++i)\n         pf->bits[i] = ~(png_uint_32)0;\n   }\n\n   else\n   {\n      png_uint_32 f;\n\n      for (f=0; f<FORMAT_COUNT; ++f)\n      {\n         /* Eliminate redundant and unsupported settings. */\n#        ifdef PNG_FORMAT_BGR_SUPPORTED\n            /* BGR is meaningless if no color: */\n            if ((f & PNG_FORMAT_FLAG_COLOR) == 0 &&\n               (f & PNG_FORMAT_FLAG_BGR) != 0)\n#        else\n            if ((f & 0x10U/*HACK: fixed value*/) != 0)\n#        endif\n            continue;\n\n         /* AFIRST is meaningless if no alpha: */\n#        ifdef PNG_FORMAT_AFIRST_SUPPORTED\n            if ((f & PNG_FORMAT_FLAG_ALPHA) == 0 &&\n               (f & PNG_FORMAT_FLAG_AFIRST) != 0)\n#        else\n            if ((f & 0x20U/*HACK: fixed value*/) != 0)\n#        endif\n            continue;\n\n         format_set(pf, f);\n      }\n   }\n}\n\n/* THE Image STRUCTURE */\n/* The super-class of a png_image, contains the decoded image plus the input\n * data necessary to re-read the file with a different format.\n */\ntypedef struct\n{\n   png_image   image;\n   png_uint_32 opts;\n   const char *file_name;\n   int         stride_extra;\n   FILE       *input_file;\n   png_voidp   input_memory;\n   png_size_t  input_memory_size;\n   png_bytep   buffer;\n   ptrdiff_t   stride;\n   png_size_t  bufsize;\n   png_size_t  allocsize;\n   char        tmpfile_name[32];\n   png_uint_16 colormap[256*4];\n}\nImage;\n\n/* Initializer: also sets the permitted error limit for 16-bit operations. */\nstatic void\nnewimage(Image *image)\n{\n   memset(image, 0, sizeof *image);\n}\n\n/* Reset the image to be read again - only needs to rewind the FILE* at present.\n */\nstatic void\nresetimage(Image *image)\n{\n   if (image->input_file != NULL)\n      rewind(image->input_file);\n}\n\n/* Free the image buffer; the buffer is re-used on a re-read, this is just for\n * cleanup.\n */\nstatic void\nfreebuffer(Image *image)\n{\n   if (image->buffer) free(image->buffer);\n   image->buffer = NULL;\n   image->bufsize = 0;\n   image->allocsize = 0;\n}\n\n/* Delete function; cleans out all the allocated data and the temporary file in\n * the image.\n */\nstatic void\nfreeimage(Image *image)\n{\n   freebuffer(image);\n   png_image_free(&image->image);\n\n   if (image->input_file != NULL)\n   {\n      fclose(image->input_file);\n      image->input_file = NULL;\n   }\n\n   if (image->input_memory != NULL)\n   {\n      free(image->input_memory);\n      image->input_memory = NULL;\n      image->input_memory_size = 0;\n   }\n\n   if (image->tmpfile_name[0] != 0 && (image->opts & KEEP_TMPFILES) == 0)\n   {\n      (void)remove(image->tmpfile_name);\n      image->tmpfile_name[0] = 0;\n   }\n}\n\n/* This is actually a re-initializer; allows an image structure to be re-used by\n * freeing everything that relates to an old image.\n */\nstatic void initimage(Image *image, png_uint_32 opts, const char *file_name,\n   int stride_extra)\n{\n   freeimage(image);\n   memset(&image->image, 0, sizeof image->image);\n   image->opts = opts;\n   image->file_name = file_name;\n   image->stride_extra = stride_extra;\n}\n\n/* Make sure the image buffer is big enough; allows re-use of the buffer if the\n * image is re-read.\n */\n#define BUFFER_INIT8 73\nstatic void\nallocbuffer(Image *image)\n{\n   png_size_t size = PNG_IMAGE_BUFFER_SIZE(image->image, image->stride);\n\n   if (size+32 > image->bufsize)\n   {\n      freebuffer(image);\n      image->buffer = voidcast(png_bytep, malloc(size+32));\n      if (image->buffer == NULL)\n      {\n         fflush(stdout);\n         fprintf(stderr,\n            \"simpletest: out of memory allocating %lu(+32) byte buffer\\n\",\n            (unsigned long)size);\n         exit(1);\n      }\n      image->bufsize = size+32;\n   }\n\n   memset(image->buffer, 95, image->bufsize);\n   memset(image->buffer+16, BUFFER_INIT8, size);\n   image->allocsize = size;\n}\n\n/* Make sure 16 bytes match the given byte. */\nstatic int\ncheck16(png_const_bytep bp, int b)\n{\n   int i = 16;\n\n   do\n      if (*bp != b) return 1;\n   while (--i);\n\n   return 0;\n}\n\n/* Check for overwrite in the image buffer. */\nstatic void\ncheckbuffer(Image *image, const char *arg)\n{\n   if (check16(image->buffer, 95))\n   {\n      fflush(stdout);\n      fprintf(stderr, \"%s: overwrite at start of image buffer\\n\", arg);\n      exit(1);\n   }\n\n   if (check16(image->buffer+16+image->allocsize, 95))\n   {\n      fflush(stdout);\n      fprintf(stderr, \"%s: overwrite at end of image buffer\\n\", arg);\n      exit(1);\n   }\n}\n\n/* ERROR HANDLING */\n/* Log a terminal error, also frees the libpng part of the image if necessary.\n */\nstatic int\nlogerror(Image *image, const char *a1, const char *a2, const char *a3)\n{\n   fflush(stdout);\n   if (image->image.warning_or_error)\n      fprintf(stderr, \"%s%s%s: %s\\n\", a1, a2, a3, image->image.message);\n\n   else\n      fprintf(stderr, \"%s%s%s\\n\", a1, a2, a3);\n\n   if (image->image.opaque != NULL)\n   {\n      fprintf(stderr, \"%s: image opaque pointer non-NULL on error\\n\",\n         image->file_name);\n      png_image_free(&image->image);\n   }\n\n   return 0;\n}\n\n/* Log an error and close a file (just a utility to do both things in one\n * function call.)\n */\nstatic int\nlogclose(Image *image, FILE *f, const char *name, const char *operation)\n{\n   int e = errno;\n\n   fclose(f);\n   return logerror(image, name, operation, strerror(e));\n}\n\n/* Make sure the png_image has been freed - validates that libpng is doing what\n * the spec says and freeing the image.\n */\nstatic int\ncheckopaque(Image *image)\n{\n   if (image->image.opaque != NULL)\n   {\n      png_image_free(&image->image);\n      return logerror(image, image->file_name, \": opaque not NULL\", \"\");\n   }\n\n   /* Separate out the gamma+background_rgb_to_gray warning because it may\n    * produce opaque component errors:\n    */\n   else if (image->image.warning_or_error != 0 &&\n            (strcmp(image->image.message,\n               \"libpng does not support gamma+background+rgb_to_gray\") == 0 ?\n                  (image->opts & GBG_ERROR) != 0 : (image->opts & STRICT) != 0))\n      return logerror(image, image->file_name, (image->opts & GBG_ERROR) != 0 ?\n                      \" --fault-gbg-warning\" : \" --strict\", \"\");\n\n   else\n      return 1;\n}\n\n/* IMAGE COMPARISON/CHECKING */\n/* Compare the pixels of two images, which should be the same but aren't.  The\n * images must have been checked for a size match.\n */\ntypedef struct\n{\n   /* The components, for grayscale images the gray value is in 'g' and if alpha\n    * is not present 'a' is set to 255 or 65535 according to format.\n    */\n   int         r, g, b, a;\n} Pixel;\n\ntypedef struct\n{\n   /* The background as the original sRGB 8-bit value converted to the final\n    * integer format and as a double precision linear value in the range 0..1\n    * for with partially transparent pixels.\n    */\n   int ir, ig, ib;\n   double dr, dg, db; /* linear r,g,b scaled to 0..1 */\n} Background;\n\n/* Basic image formats; control the data but not the layout thereof. */\n#define BASE_FORMATS\\\n   (PNG_FORMAT_FLAG_ALPHA|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_LINEAR)\n\n/* Read a Pixel from a buffer.  The code below stores the correct routine for\n * the format in a function pointer, these are the routines:\n */\nstatic void\ngp_g8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = p->g = p->b = pp[0];\n   p->a = 255;\n}\n\nstatic void\ngp_ga8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = p->g = p->b = pp[0];\n   p->a = pp[1];\n}\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\nstatic void\ngp_ag8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = p->g = p->b = pp[1];\n   p->a = pp[0];\n}\n#endif\n\nstatic void\ngp_rgb8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[0];\n   p->g = pp[1];\n   p->b = pp[2];\n   p->a = 255;\n}\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\nstatic void\ngp_bgr8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[2];\n   p->g = pp[1];\n   p->b = pp[0];\n   p->a = 255;\n}\n#endif\n\nstatic void\ngp_rgba8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[0];\n   p->g = pp[1];\n   p->b = pp[2];\n   p->a = pp[3];\n}\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\nstatic void\ngp_bgra8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[2];\n   p->g = pp[1];\n   p->b = pp[0];\n   p->a = pp[3];\n}\n#endif\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\nstatic void\ngp_argb8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[1];\n   p->g = pp[2];\n   p->b = pp[3];\n   p->a = pp[0];\n}\n#endif\n\n#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)\nstatic void\ngp_abgr8(Pixel *p, png_const_voidp pb)\n{\n   png_const_bytep pp = voidcast(png_const_bytep, pb);\n\n   p->r = pp[3];\n   p->g = pp[2];\n   p->b = pp[1];\n   p->a = pp[0];\n}\n#endif\n\nstatic void\ngp_g16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = p->g = p->b = pp[0];\n   p->a = 65535;\n}\n\nstatic void\ngp_ga16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = p->g = p->b = pp[0];\n   p->a = pp[1];\n}\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\nstatic void\ngp_ag16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = p->g = p->b = pp[1];\n   p->a = pp[0];\n}\n#endif\n\nstatic void\ngp_rgb16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[0];\n   p->g = pp[1];\n   p->b = pp[2];\n   p->a = 65535;\n}\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\nstatic void\ngp_bgr16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[2];\n   p->g = pp[1];\n   p->b = pp[0];\n   p->a = 65535;\n}\n#endif\n\nstatic void\ngp_rgba16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[0];\n   p->g = pp[1];\n   p->b = pp[2];\n   p->a = pp[3];\n}\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\nstatic void\ngp_bgra16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[2];\n   p->g = pp[1];\n   p->b = pp[0];\n   p->a = pp[3];\n}\n#endif\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\nstatic void\ngp_argb16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[1];\n   p->g = pp[2];\n   p->b = pp[3];\n   p->a = pp[0];\n}\n#endif\n\n#if defined(PNG_FORMAT_AFIRST_SUPPORTED) && defined(PNG_FORMAT_BGR_SUPPORTED)\nstatic void\ngp_abgr16(Pixel *p, png_const_voidp pb)\n{\n   png_const_uint_16p pp = voidcast(png_const_uint_16p, pb);\n\n   p->r = pp[3];\n   p->g = pp[2];\n   p->b = pp[1];\n   p->a = pp[0];\n}\n#endif\n\n/* Given a format, return the correct one of the above functions. */\nstatic void (*\nget_pixel(png_uint_32 format))(Pixel *p, png_const_voidp pb)\n{\n   /* The color-map flag is irrelevant here - the caller of the function\n    * returned must either pass the buffer or, for a color-mapped image, the\n    * correct entry in the color-map.\n    */\n   if (format & PNG_FORMAT_FLAG_LINEAR)\n   {\n      if (format & PNG_FORMAT_FLAG_COLOR)\n      {\n#        ifdef PNG_FORMAT_BGR_SUPPORTED\n            if (format & PNG_FORMAT_FLAG_BGR)\n            {\n               if (format & PNG_FORMAT_FLAG_ALPHA)\n               {\n#                 ifdef PNG_FORMAT_AFIRST_SUPPORTED\n                     if (format & PNG_FORMAT_FLAG_AFIRST)\n                        return gp_abgr16;\n\n                     else\n#                 endif\n                     return gp_bgra16;\n               }\n\n               else\n                  return gp_bgr16;\n            }\n\n            else\n#        endif\n         {\n            if (format & PNG_FORMAT_FLAG_ALPHA)\n            {\n#              ifdef PNG_FORMAT_AFIRST_SUPPORTED\n                  if (format & PNG_FORMAT_FLAG_AFIRST)\n                     return gp_argb16;\n\n                  else\n#              endif\n                  return gp_rgba16;\n            }\n\n            else\n               return gp_rgb16;\n         }\n      }\n\n      else\n      {\n         if (format & PNG_FORMAT_FLAG_ALPHA)\n         {\n#           ifdef PNG_FORMAT_AFIRST_SUPPORTED\n               if (format & PNG_FORMAT_FLAG_AFIRST)\n                  return gp_ag16;\n\n               else\n#           endif\n               return gp_ga16;\n         }\n\n         else\n            return gp_g16;\n      }\n   }\n\n   else\n   {\n      if (format & PNG_FORMAT_FLAG_COLOR)\n      {\n#        ifdef PNG_FORMAT_BGR_SUPPORTED\n            if (format & PNG_FORMAT_FLAG_BGR)\n            {\n               if (format & PNG_FORMAT_FLAG_ALPHA)\n               {\n#                 ifdef PNG_FORMAT_AFIRST_SUPPORTED\n                     if (format & PNG_FORMAT_FLAG_AFIRST)\n                        return gp_abgr8;\n\n                     else\n#                 endif\n                     return gp_bgra8;\n               }\n\n               else\n                  return gp_bgr8;\n            }\n\n            else\n#        endif\n         {\n            if (format & PNG_FORMAT_FLAG_ALPHA)\n            {\n#              ifdef PNG_FORMAT_AFIRST_SUPPORTED\n                  if (format & PNG_FORMAT_FLAG_AFIRST)\n                     return gp_argb8;\n\n                  else\n#              endif\n                  return gp_rgba8;\n            }\n\n            else\n               return gp_rgb8;\n         }\n      }\n\n      else\n      {\n         if (format & PNG_FORMAT_FLAG_ALPHA)\n         {\n#           ifdef PNG_FORMAT_AFIRST_SUPPORTED\n               if (format & PNG_FORMAT_FLAG_AFIRST)\n                  return gp_ag8;\n\n               else\n#           endif\n               return gp_ga8;\n         }\n\n         else\n            return gp_g8;\n      }\n   }\n}\n\n/* Convertion between pixel formats.  The code above effectively eliminates the\n * component ordering changes leaving three basic changes:\n *\n * 1) Remove an alpha channel by pre-multiplication or compositing on a\n *    background color.  (Adding an alpha channel is a no-op.)\n *\n * 2) Remove color by mapping to grayscale.  (Grayscale to color is a no-op.)\n *\n * 3) Convert between 8-bit and 16-bit components.  (Both directtions are\n *    relevant.)\n *\n * This gives the following base format conversion matrix:\n *\n *   OUT:    ----- 8-bit -----    ----- 16-bit -----\n *   IN     G    GA   RGB  RGBA  G    GA   RGB  RGBA\n *  8 G     .    .    .    .     lin  lin  lin  lin\n *  8 GA    bckg .    bckc .     pre' pre  pre' pre\n *  8 RGB   g8   g8   .    .     glin glin lin  lin\n *  8 RGBA  g8b  g8   bckc .     gpr' gpre pre' pre\n * 16 G     sRGB sRGB sRGB sRGB  .    .    .    .\n * 16 GA    b16g unpg b16c unpc  A    .    A    .\n * 16 RGB   sG   sG   sRGB sRGB  g16  g16  .    .\n * 16 RGBA  gb16 sGp  cb16 sCp   g16  g16' A    .\n *\n *  8-bit to 8-bit:\n * bckg: composite on gray background\n * bckc: composite on color background\n * g8:   convert sRGB components to sRGB grayscale\n * g8b:  convert sRGB components to grayscale and composite on gray background\n *\n *  8-bit to 16-bit:\n * lin:  make sRGB components linear, alpha := 65535\n * pre:  make sRGB components linear and premultiply by alpha  (scale alpha)\n * pre': as 'pre' but alpha := 65535\n * glin: make sRGB components linear, convert to grayscale, alpha := 65535\n * gpre: make sRGB components grayscale and linear and premultiply by alpha\n * gpr': as 'gpre' but alpha := 65535\n *\n *  16-bit to 8-bit:\n * sRGB: convert linear components to sRGB, alpha := 255\n * unpg: unpremultiply gray component and convert to sRGB (scale alpha)\n * unpc: unpremultiply color components and convert to sRGB (scale alpha)\n * b16g: composite linear onto gray background and convert the result to sRGB\n * b16c: composite linear onto color background and convert the result to sRGB\n * sG:   convert linear RGB to sRGB grayscale\n * sGp:  unpremultiply RGB then convert to sRGB grayscale\n * sCp:  unpremultiply RGB then convert to sRGB\n * gb16: composite linear onto background and convert to sRGB grayscale\n *       (order doesn't matter, the composite and grayscale operations permute)\n * cb16: composite linear onto background and convert to sRGB\n *\n *  16-bit to 16-bit:\n * A:    set alpha to 65535\n * g16:  convert linear RGB to linear grayscale (alpha := 65535)\n * g16': as 'g16' but alpha is unchanged\n */\n/* Simple copy: */\nstatic void\ngpc_noop(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   out->r = in->r;\n   out->g = in->g;\n   out->b = in->b;\n   out->a = in->a;\n}\n\n#if ALLOW_UNUSED_GPC\nstatic void\ngpc_nop8(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   if (in->a == 0)\n      out->r = out->g = out->b = 255;\n\n   else\n   {\n      out->r = in->r;\n      out->g = in->g;\n      out->b = in->b;\n   }\n\n   out->a = in->a;\n}\n#endif\n\n#if ALLOW_UNUSED_GPC\nstatic void\ngpc_nop6(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   if (in->a == 0)\n      out->r = out->g = out->b = 65535;\n\n   else\n   {\n      out->r = in->r;\n      out->g = in->g;\n      out->b = in->b;\n   }\n\n   out->a = in->a;\n}\n#endif\n\n/* 8-bit to 8-bit conversions */\n/* bckg: composite on gray background */\nstatic void\ngpc_bckg(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n      out->r = out->g = out->b = back->ig;\n\n   else if (in->a >= 255)\n      out->r = out->g = out->b = in->g;\n\n   else\n   {\n      double a = in->a / 255.;\n\n      out->r = out->g = out->b = sRGB(sRGB_to_d[in->g] * a + back->dg * (1-a));\n   }\n\n   out->a = 255;\n}\n\n/* bckc: composite on color background */\nstatic void\ngpc_bckc(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n   {\n      out->r = back->ir;\n      out->g = back->ig;\n      out->b = back->ib;\n   }\n\n   else if (in->a >= 255)\n   {\n      out->r = in->r;\n      out->g = in->g;\n      out->b = in->b;\n   }\n\n   else\n   {\n      double a = in->a / 255.;\n\n      out->r = sRGB(sRGB_to_d[in->r] * a + back->dr * (1-a));\n      out->g = sRGB(sRGB_to_d[in->g] * a + back->dg * (1-a));\n      out->b = sRGB(sRGB_to_d[in->b] * a + back->db * (1-a));\n   }\n\n   out->a = 255;\n}\n\n/* g8: convert sRGB components to sRGB grayscale */\nstatic void\ngpc_g8(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = in->g;\n\n   else\n      out->r = out->g = out->b =\n         sRGB(YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));\n\n   out->a = in->a;\n}\n\n/* g8b: convert sRGB components to grayscale and composite on gray background */\nstatic void\ngpc_g8b(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n      out->r = out->g = out->b = back->ig;\n\n   else if (in->a >= 255)\n   {\n      if (in->r == in->g && in->g == in->b)\n         out->r = out->g = out->b = in->g;\n\n      else\n         out->r = out->g = out->b = sRGB(YfromRGB(\n            sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));\n   }\n\n   else\n   {\n      double a = in->a/255.;\n\n      out->r = out->g = out->b = sRGB(a * YfromRGB(sRGB_to_d[in->r],\n         sRGB_to_d[in->g], sRGB_to_d[in->b]) + back->dg * (1-a));\n   }\n\n   out->a = 255;\n}\n\n/* 8-bit to 16-bit conversions */\n/* lin: make sRGB components linear, alpha := 65535 */\nstatic void\ngpc_lin(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilinear(in->r);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilinear(in->b);\n   }\n\n   else\n   {\n      out->g = ilinear(in->g);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilinear(in->b);\n   }\n\n   out->a = 65535;\n}\n\n/* pre: make sRGB components linear and premultiply by alpha (scale alpha) */\nstatic void\ngpc_pre(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilineara(in->r, in->a);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilineara(in->b, in->a);\n   }\n\n   else\n   {\n      out->g = ilineara(in->g, in->a);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilineara(in->b, in->a);\n   }\n\n   out->a = in->a * 257;\n}\n\n/* pre': as 'pre' but alpha := 65535 */\nstatic void\ngpc_preq(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilineara(in->r, in->a);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilineara(in->b, in->a);\n   }\n\n   else\n   {\n      out->g = ilineara(in->g, in->a);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilineara(in->b, in->a);\n   }\n\n   out->a = 65535;\n}\n\n/* glin: make sRGB components linear, convert to grayscale, alpha := 65535 */\nstatic void\ngpc_glin(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilinear(in->g);\n\n   else\n      out->r = out->g = out->b = u16d(65535 *\n         YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));\n\n   out->a = 65535;\n}\n\n/* gpre: make sRGB components grayscale and linear and premultiply by alpha */\nstatic void\ngpc_gpre(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilineara(in->g, in->a);\n\n   else\n      out->r = out->g = out->b = u16d(in->a * 257 *\n         YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));\n\n   out->a = 257 * in->a;\n}\n\n/* gpr': as 'gpre' but alpha := 65535 */\nstatic void\ngpc_gprq(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilineara(in->g, in->a);\n\n   else\n      out->r = out->g = out->b = u16d(in->a * 257 *\n         YfromRGB(sRGB_to_d[in->r], sRGB_to_d[in->g], sRGB_to_d[in->b]));\n\n   out->a = 65535;\n}\n\n/* 8-bit to 16-bit conversions for gAMA 45455 encoded values */\n/* Lin: make gAMA 45455 components linear, alpha := 65535 */\nstatic void\ngpc_Lin(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilinear_g22(in->r);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilinear_g22(in->b);\n   }\n\n   else\n   {\n      out->g = ilinear_g22(in->g);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilinear_g22(in->b);\n   }\n\n   out->a = 65535;\n}\n\n#if ALLOW_UNUSED_GPC\n/* Pre: make gAMA 45455 components linear and premultiply by alpha (scale alpha)\n */\nstatic void\ngpc_Pre(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilineara_g22(in->r, in->a);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilineara_g22(in->b, in->a);\n   }\n\n   else\n   {\n      out->g = ilineara_g22(in->g, in->a);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilineara_g22(in->b, in->a);\n   }\n\n   out->a = in->a * 257;\n}\n#endif\n\n#if ALLOW_UNUSED_GPC\n/* Pre': as 'Pre' but alpha := 65535 */\nstatic void\ngpc_Preq(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = ilineara_g22(in->r, in->a);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = ilineara_g22(in->b, in->a);\n   }\n\n   else\n   {\n      out->g = ilineara_g22(in->g, in->a);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = ilineara_g22(in->b, in->a);\n   }\n\n   out->a = 65535;\n}\n#endif\n\n#if ALLOW_UNUSED_GPC\n/* Glin: make gAMA 45455 components linear, convert to grayscale, alpha := 65535\n */\nstatic void\ngpc_Glin(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilinear_g22(in->g);\n\n   else\n      out->r = out->g = out->b = u16d(65535 *\n         YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));\n\n   out->a = 65535;\n}\n#endif\n\n#if ALLOW_UNUSED_GPC\n/* Gpre: make gAMA 45455 components grayscale and linear and premultiply by\n * alpha.\n */\nstatic void\ngpc_Gpre(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilineara_g22(in->g, in->a);\n\n   else\n      out->r = out->g = out->b = u16d(in->a * 257 *\n         YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));\n\n   out->a = 257 * in->a;\n}\n#endif\n\n#if ALLOW_UNUSED_GPC\n/* Gpr': as 'Gpre' but alpha := 65535 */\nstatic void\ngpc_Gprq(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->r == in->g && in->g == in->b)\n      out->r = out->g = out->b = ilineara_g22(in->g, in->a);\n\n   else\n      out->r = out->g = out->b = u16d(in->a * 257 *\n         YfromRGB(g22_to_d[in->r], g22_to_d[in->g], g22_to_d[in->b]));\n\n   out->a = 65535;\n}\n#endif\n\n/* 16-bit to 8-bit conversions */\n/* sRGB: convert linear components to sRGB, alpha := 255 */\nstatic void\ngpc_sRGB(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = isRGB(in->r);\n\n   if (in->g == in->r)\n   {\n      out->g = out->r;\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else\n         out->b = isRGB(in->b);\n   }\n\n   else\n   {\n      out->g = isRGB(in->g);\n\n      if (in->b == in->r)\n         out->b = out->r;\n\n      else if (in->b == in->g)\n         out->b = out->g;\n\n      else\n         out->b = isRGB(in->b);\n   }\n\n   out->a = 255;\n}\n\n/* unpg: unpremultiply gray component and convert to sRGB (scale alpha) */\nstatic void\ngpc_unpg(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->a <= 128)\n   {\n      out->r = out->g = out->b = 255;\n      out->a = 0;\n   }\n\n   else\n   {\n      out->r = out->g = out->b = sRGB((double)in->g / in->a);\n      out->a = u8d(in->a / 257.);\n   }\n}\n\n/* unpc: unpremultiply color components and convert to sRGB (scale alpha) */\nstatic void\ngpc_unpc(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->a <= 128)\n   {\n      out->r = out->g = out->b = 255;\n      out->a = 0;\n   }\n\n   else\n   {\n      out->r = sRGB((double)in->r / in->a);\n      out->g = sRGB((double)in->g / in->a);\n      out->b = sRGB((double)in->b / in->a);\n      out->a = u8d(in->a / 257.);\n   }\n}\n\n/* b16g: composite linear onto gray background and convert the result to sRGB */\nstatic void\ngpc_b16g(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n      out->r = out->g = out->b = back->ig;\n\n   else\n   {\n      double a = in->a/65535.;\n      double a1 = 1-a;\n\n      a /= 65535;\n      out->r = out->g = out->b = sRGB(in->g * a + back->dg * a1);\n   }\n\n   out->a = 255;\n}\n\n/* b16c: composite linear onto color background and convert the result to sRGB*/\nstatic void\ngpc_b16c(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n   {\n      out->r = back->ir;\n      out->g = back->ig;\n      out->b = back->ib;\n   }\n\n   else\n   {\n      double a = in->a/65535.;\n      double a1 = 1-a;\n\n      a /= 65535;\n      out->r = sRGB(in->r * a + back->dr * a1);\n      out->g = sRGB(in->g * a + back->dg * a1);\n      out->b = sRGB(in->b * a + back->db * a1);\n   }\n\n   out->a = 255;\n}\n\n/* sG: convert linear RGB to sRGB grayscale */\nstatic void\ngpc_sG(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   out->r = out->g = out->b = sRGB(YfromRGBint(in->r, in->g, in->b)/65535);\n   out->a = 255;\n}\n\n/* sGp: unpremultiply RGB then convert to sRGB grayscale */\nstatic void\ngpc_sGp(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->a <= 128)\n   {\n      out->r = out->g = out->b = 255;\n      out->a = 0;\n   }\n\n   else\n   {\n      out->r = out->g = out->b = sRGB(YfromRGBint(in->r, in->g, in->b)/in->a);\n      out->a = u8d(in->a / 257.);\n   }\n}\n\n/* sCp: unpremultiply RGB then convert to sRGB */\nstatic void\ngpc_sCp(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n\n   if (in->a <= 128)\n   {\n      out->r = out->g = out->b = 255;\n      out->a = 0;\n   }\n\n   else\n   {\n      out->r = sRGB((double)in->r / in->a);\n      out->g = sRGB((double)in->g / in->a);\n      out->b = sRGB((double)in->b / in->a);\n      out->a = u8d(in->a / 257.);\n   }\n}\n\n/* gb16: composite linear onto background and convert to sRGB grayscale */\n/*  (order doesn't matter, the composite and grayscale operations permute) */\nstatic void\ngpc_gb16(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n      out->r = out->g = out->b = back->ig;\n\n   else if (in->a >= 65535)\n      out->r = out->g = out->b = isRGB(in->g);\n\n   else\n   {\n      double a = in->a / 65535.;\n      double a1 = 1-a;\n\n      a /= 65535;\n      out->r = out->g = out->b = sRGB(in->g * a + back->dg * a1);\n   }\n\n   out->a = 255;\n}\n\n/* cb16: composite linear onto background and convert to sRGB */\nstatic void\ngpc_cb16(Pixel *out, const Pixel *in, const Background *back)\n{\n   if (in->a <= 0)\n   {\n      out->r = back->ir;\n      out->g = back->ig;\n      out->b = back->ib;\n   }\n\n   else if (in->a >= 65535)\n   {\n      out->r = isRGB(in->r);\n      out->g = isRGB(in->g);\n      out->b = isRGB(in->b);\n   }\n\n   else\n   {\n      double a = in->a / 65535.;\n      double a1 = 1-a;\n\n      a /= 65535;\n      out->r = sRGB(in->r * a + back->dr * a1);\n      out->g = sRGB(in->g * a + back->dg * a1);\n      out->b = sRGB(in->b * a + back->db * a1);\n   }\n\n   out->a = 255;\n}\n\n/* 16-bit to 16-bit conversions */\n/* A:    set alpha to 65535 */\nstatic void\ngpc_A(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   out->r = in->r;\n   out->g = in->g;\n   out->b = in->b;\n   out->a = 65535;\n}\n\n/* g16:  convert linear RGB to linear grayscale (alpha := 65535) */\nstatic void\ngpc_g16(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   out->r = out->g = out->b = u16d(YfromRGBint(in->r, in->g, in->b));\n   out->a = 65535;\n}\n\n/* g16': as 'g16' but alpha is unchanged */\nstatic void\ngpc_g16q(Pixel *out, const Pixel *in, const Background *back)\n{\n   (void)back;\n   out->r = out->g = out->b = u16d(YfromRGBint(in->r, in->g, in->b));\n   out->a = in->a;\n}\n\n#if ALLOW_UNUSED_GPC\n/* Unused functions (to hide them from GCC unused function warnings) */\nvoid (* const gpc_unused[])\n   (Pixel *out, const Pixel *in, const Background *back) =\n{\n   gpc_Pre, gpc_Preq, gpc_Glin, gpc_Gpre, gpc_Gprq, gpc_nop8, gpc_nop6\n};\n#endif\n\n/*   OUT:    ----- 8-bit -----    ----- 16-bit -----\n *   IN     G    GA   RGB  RGBA  G    GA   RGB  RGBA\n *  8 G     .    .    .    .     lin  lin  lin  lin\n *  8 GA    bckg .    bckc .     pre' pre  pre' pre\n *  8 RGB   g8   g8   .    .     glin glin lin  lin\n *  8 RGBA  g8b  g8   bckc .     gpr' gpre pre' pre\n * 16 G     sRGB sRGB sRGB sRGB  .    .    .    .\n * 16 GA    b16g unpg b16c unpc  A    .    A    .\n * 16 RGB   sG   sG   sRGB sRGB  g16  g16  .    .\n * 16 RGBA  gb16 sGp  cb16 sCp   g16  g16' A    .\n *\n * The matrix is held in an array indexed thus:\n *\n *   gpc_fn[out_format & BASE_FORMATS][in_format & BASE_FORMATS];\n */\n/* This will produce a compile time error if the FORMAT_FLAG values don't\n * match the above matrix!\n */\n#if PNG_FORMAT_FLAG_ALPHA == 1 && PNG_FORMAT_FLAG_COLOR == 2 &&\\\n   PNG_FORMAT_FLAG_LINEAR == 4\nstatic void (* const gpc_fn[8/*in*/][8/*out*/])\n   (Pixel *out, const Pixel *in, const Background *back) =\n{\n/*out: G-8     GA-8     RGB-8    RGBA-8    G-16     GA-16   RGB-16  RGBA-16 */\n   {gpc_noop,gpc_noop,gpc_noop,gpc_noop, gpc_Lin, gpc_Lin, gpc_Lin, gpc_Lin },\n   {gpc_bckg,gpc_noop,gpc_bckc,gpc_noop, gpc_preq,gpc_pre, gpc_preq,gpc_pre },\n   {gpc_g8,  gpc_g8,  gpc_noop,gpc_noop, gpc_glin,gpc_glin,gpc_lin, gpc_lin },\n   {gpc_g8b, gpc_g8,  gpc_bckc,gpc_noop, gpc_gprq,gpc_gpre,gpc_preq,gpc_pre },\n   {gpc_sRGB,gpc_sRGB,gpc_sRGB,gpc_sRGB, gpc_noop,gpc_noop,gpc_noop,gpc_noop},\n   {gpc_b16g,gpc_unpg,gpc_b16c,gpc_unpc, gpc_A,   gpc_noop,gpc_A,   gpc_noop},\n   {gpc_sG,  gpc_sG,  gpc_sRGB,gpc_sRGB, gpc_g16, gpc_g16, gpc_noop,gpc_noop},\n   {gpc_gb16,gpc_sGp, gpc_cb16,gpc_sCp,  gpc_g16, gpc_g16q,gpc_A,   gpc_noop}\n};\n\n/* The array is repeated for the cases where both the input and output are color\n * mapped because then different algorithms are used.\n */\nstatic void (* const gpc_fn_colormapped[8/*in*/][8/*out*/])\n   (Pixel *out, const Pixel *in, const Background *back) =\n{\n/*out: G-8     GA-8     RGB-8    RGBA-8    G-16     GA-16   RGB-16  RGBA-16 */\n   {gpc_noop,gpc_noop,gpc_noop,gpc_noop, gpc_lin, gpc_lin, gpc_lin, gpc_lin },\n   {gpc_bckg,gpc_noop,gpc_bckc,gpc_noop, gpc_preq,gpc_pre, gpc_preq,gpc_pre },\n   {gpc_g8,  gpc_g8,  gpc_noop,gpc_noop, gpc_glin,gpc_glin,gpc_lin, gpc_lin },\n   {gpc_g8b, gpc_g8,  gpc_bckc,gpc_noop, gpc_gprq,gpc_gpre,gpc_preq,gpc_pre },\n   {gpc_sRGB,gpc_sRGB,gpc_sRGB,gpc_sRGB, gpc_noop,gpc_noop,gpc_noop,gpc_noop},\n   {gpc_b16g,gpc_unpg,gpc_b16c,gpc_unpc, gpc_A,   gpc_noop,gpc_A,   gpc_noop},\n   {gpc_sG,  gpc_sG,  gpc_sRGB,gpc_sRGB, gpc_g16, gpc_g16, gpc_noop,gpc_noop},\n   {gpc_gb16,gpc_sGp, gpc_cb16,gpc_sCp,  gpc_g16, gpc_g16q,gpc_A,   gpc_noop}\n};\n\n/* The error arrays record the error in the same matrix; 64 entries, however\n * the different algorithms used in libpng for colormap and direct conversions\n * mean that four separate matrices are used (for each combination of\n * colormapped and direct.)\n *\n * In some cases the conversion between sRGB formats goes via a linear\n * intermediate; an sRGB to linear conversion (as above) is followed by a simple\n * linear to sRGB step with no other conversions.  This is done by a separate\n * error array from an arbitrary 'in' format to one of the four basic outputs\n * (since final output is always sRGB not colormapped).\n *\n * These arrays may be modified if the --accumulate flag is set during the run;\n * then instead of logging errors they are simply added in.\n *\n * The three entries are currently for transparent, partially transparent and\n * opaque input pixel values.  Notice that alpha should be exact in each case.\n *\n * Errors in alpha should only occur when converting from a direct format\n * to a colormapped format, when alpha is effectively smashed (so large\n * errors can occur.)  There should be no error in the '0' and 'opaque'\n * values.  The fourth entry in the array is used for the alpha error (and it\n * should always be zero for the 'via linear' case since this is never color\n * mapped.)\n *\n * Mapping to a colormap smashes the colors, it is necessary to have separate\n * values for these cases because they are much larger; it is very much\n * impossible to obtain a reasonable result, these are held in\n * gpc_error_to_colormap.\n */\n#if PNG_FORMAT_FLAG_COLORMAP == 8 /* extra check also required */\n#  include \"pngstest-errors.h\" /* machine generated */\n#endif /* COLORMAP flag check */\n#endif /* flag checks */\n\ntypedef struct\n{\n   /* Basic pixel information: */\n   Image*       in_image;   /* Input image */\n   const Image* out_image;  /* Output image */\n\n   /* 'background' is the value passed to the gpc_ routines, it may be NULL if\n    * it should not be used (*this* program has an error if it crashes as a\n    * result!)\n    */\n   Background        background_color;\n   const Background* background;\n\n   /* Precalculated values: */\n   int          in_opaque;   /* Value of input alpha that is opaque */\n   int          is_palette;  /* Sample values come from the palette */\n   int          accumulate;  /* Accumlate component errors (don't log) */\n   int          output_8bit; /* Output is 8-bit (else 16-bit) */\n\n   void (*in_gp)(Pixel*, png_const_voidp);\n   void (*out_gp)(Pixel*, png_const_voidp);\n\n   void (*transform)(Pixel *out, const Pixel *in, const Background *back);\n      /* A function to perform the required transform */\n\n   void (*from_linear)(Pixel *out, const Pixel *in, const Background *back);\n      /* For 'via_linear' transforms the final, from linear, step, else NULL */\n\n   png_uint_16 error[4];\n      /* Three error values for transparent, partially transparent and opaque\n       * input pixels (in turn).\n       */\n\n   png_uint_16 *error_ptr;\n      /* Where these are stored in the static array (for 'accumulate') */\n}\nTransform;\n\n/* Return a 'transform' as above for the given format conversion. */\nstatic void\ntransform_from_formats(Transform *result, Image *in_image,\n   const Image *out_image, png_const_colorp background, int via_linear)\n{\n   png_uint_32 in_format, out_format;\n   png_uint_32 in_base, out_base;\n\n   memset(result, 0, sizeof *result);\n\n   /* Store the original images for error messages */\n   result->in_image = in_image;\n   result->out_image = out_image;\n\n   in_format = in_image->image.format;\n   out_format = out_image->image.format;\n\n   if (in_format & PNG_FORMAT_FLAG_LINEAR)\n      result->in_opaque = 65535;\n   else\n      result->in_opaque = 255;\n\n   result->output_8bit = (out_format & PNG_FORMAT_FLAG_LINEAR) == 0;\n\n   result->is_palette = 0; /* set by caller if required */\n   result->accumulate = (in_image->opts & ACCUMULATE) != 0;\n\n   /* The loaders (which need the ordering information) */\n   result->in_gp = get_pixel(in_format);\n   result->out_gp = get_pixel(out_format);\n\n   /* Remove the ordering information: */\n   in_format &= BASE_FORMATS | PNG_FORMAT_FLAG_COLORMAP;\n   in_base = in_format & BASE_FORMATS;\n   out_format &= BASE_FORMATS | PNG_FORMAT_FLAG_COLORMAP;\n   out_base = out_format & BASE_FORMATS;\n\n   if (via_linear)\n   {\n      /* Check for an error in this program: */\n      if (out_format & (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLORMAP))\n      {\n         fprintf(stderr, \"internal transform via linear error 0x%x->0x%x\\n\",\n            in_format, out_format);\n         exit(1);\n      }\n\n      result->transform = gpc_fn[in_base][out_base | PNG_FORMAT_FLAG_LINEAR];\n      result->from_linear = gpc_fn[out_base | PNG_FORMAT_FLAG_LINEAR][out_base];\n      result->error_ptr = gpc_error_via_linear[in_format][out_format];\n   }\n\n   else if (~in_format & out_format & PNG_FORMAT_FLAG_COLORMAP)\n   {\n      /* The input is not colormapped but the output is, the errors will\n       * typically be large (only the grayscale-no-alpha case permits preserving\n       * even 8-bit values.)\n       */\n      result->transform = gpc_fn[in_base][out_base];\n      result->from_linear = NULL;\n      result->error_ptr = gpc_error_to_colormap[in_base][out_base];\n   }\n\n   else\n   {\n      /* The caller handles the colormap->pixel value conversion, so the\n       * transform function just gets a pixel value, however because libpng\n       * currently contains a different implementation for mapping a colormap if\n       * both input and output are colormapped we need different conversion\n       * functions to deal with errors in the libpng implementation.\n       */\n      if (in_format & out_format & PNG_FORMAT_FLAG_COLORMAP)\n         result->transform = gpc_fn_colormapped[in_base][out_base];\n      else\n         result->transform = gpc_fn[in_base][out_base];\n      result->from_linear = NULL;\n      result->error_ptr = gpc_error[in_format][out_format];\n   }\n\n   /* Follow the libpng simplified API rules to work out what to pass to the gpc\n    * routines as a background value, if one is not required pass NULL so that\n    * this program crashes in the even of a programming error.\n    */\n   result->background = NULL; /* default: not required */\n\n   /* Rule 1: background only need be supplied if alpha is to be removed */\n   if (in_format & ~out_format & PNG_FORMAT_FLAG_ALPHA)\n   {\n      /* The input value is 'NULL' to use the background and (otherwise) an sRGB\n       * background color (to use a solid color).  The code above uses a fixed\n       * byte value, BUFFER_INIT8, for buffer even for 16-bit output.  For\n       * linear (16-bit) output the sRGB background color is ignored; the\n       * composition is always on the background (so BUFFER_INIT8 * 257), except\n       * that for the colormap (i.e. linear colormapped output) black is used.\n       */\n      result->background = &result->background_color;\n\n      if (out_format & PNG_FORMAT_FLAG_LINEAR || via_linear)\n      {\n         if (out_format & PNG_FORMAT_FLAG_COLORMAP)\n         {\n            result->background_color.ir =\n               result->background_color.ig =\n               result->background_color.ib = 0;\n            result->background_color.dr =\n               result->background_color.dg =\n               result->background_color.db = 0;\n         }\n\n         else\n         {\n            result->background_color.ir =\n               result->background_color.ig =\n               result->background_color.ib = BUFFER_INIT8 * 257;\n            result->background_color.dr =\n               result->background_color.dg =\n               result->background_color.db = 0;\n         }\n      }\n\n      else /* sRGB output */\n      {\n         if (background != NULL)\n         {\n            if (out_format & PNG_FORMAT_FLAG_COLOR)\n            {\n               result->background_color.ir = background->red;\n               result->background_color.ig = background->green;\n               result->background_color.ib = background->blue;\n               /* TODO: sometimes libpng uses the power law conversion here, how\n                * to handle this?\n                */\n               result->background_color.dr = sRGB_to_d[background->red];\n               result->background_color.dg = sRGB_to_d[background->green];\n               result->background_color.db = sRGB_to_d[background->blue];\n            }\n\n            else /* grayscale: libpng only looks at 'g' */\n            {\n               result->background_color.ir =\n                  result->background_color.ig =\n                  result->background_color.ib = background->green;\n               /* TODO: sometimes libpng uses the power law conversion here, how\n                * to handle this?\n                */\n               result->background_color.dr =\n                  result->background_color.dg =\n                  result->background_color.db = sRGB_to_d[background->green];\n            }\n         }\n\n         else if ((out_format & PNG_FORMAT_FLAG_COLORMAP) == 0)\n         {\n            result->background_color.ir =\n               result->background_color.ig =\n               result->background_color.ib = BUFFER_INIT8;\n            /* TODO: sometimes libpng uses the power law conversion here, how\n             * to handle this?\n             */\n            result->background_color.dr =\n               result->background_color.dg =\n               result->background_color.db = sRGB_to_d[BUFFER_INIT8];\n         }\n\n         /* Else the output is colormapped and a background color must be\n          * provided; if pngstest crashes then that is a bug in this program\n          * (though libpng should png_error as well.)\n          */\n         else\n            result->background = NULL;\n      }\n   }\n\n   if (result->background == NULL)\n   {\n      result->background_color.ir =\n         result->background_color.ig =\n         result->background_color.ib = -1; /* not used */\n      result->background_color.dr =\n         result->background_color.dg =\n         result->background_color.db = 1E30; /* not used */\n   }\n\n\n   /* Copy the error values into the Transform: */\n   result->error[0] = result->error_ptr[0];\n   result->error[1] = result->error_ptr[1];\n   result->error[2] = result->error_ptr[2];\n   result->error[3] = result->error_ptr[3];\n}\n\n\n/* Compare two pixels.\n *\n * OLD error values:\nstatic int error_to_linear = 811; * by experiment *\nstatic int error_to_linear_grayscale = 424; * by experiment *\nstatic int error_to_sRGB = 6; * by experiment *\nstatic int error_to_sRGB_grayscale = 17; * libpng error by calculation +\n                                            2 by experiment *\nstatic int error_in_compose = 2; * by experiment *\nstatic int error_in_premultiply = 1;\n *\n * The following is *just* the result of a round trip from 8-bit sRGB to linear\n * then back to 8-bit sRGB when it is done by libpng.  There are two problems:\n *\n * 1) libpng currently uses a 2.2 power law with no linear segment, this results\n * in instability in the low values and even with 16-bit precision sRGB(1) ends\n * up mapping to sRGB(0) as a result of rounding in the 16-bit representation.\n * This gives an error of 1 in the handling of value 1 only.\n *\n * 2) libpng currently uses an intermediate 8-bit linear value in gamma\n * correction of 8-bit values.  This results in many more errors, the worse of\n * which is mapping sRGB(14) to sRGB(0).\n *\n * The general 'error_via_linear' is more complex because of pre-multiplication,\n * this compounds the 8-bit errors according to the alpha value of the pixel.\n * As a result 256 values are pre-calculated for error_via_linear.\n */\n#if 0\nstatic int error_in_libpng_gamma;\nstatic int error_via_linear[256]; /* Indexed by 8-bit alpha */\n\nstatic void\ninit_error_via_linear(void)\n{\n   int alpha;\n\n   error_via_linear[0] = 255; /* transparent pixel */\n\n   for (alpha=1; alpha<=255; ++alpha)\n   {\n      /* 16-bit values less than 128.5 get rounded to 8-bit 0 and so the worst\n       * case error arises with 16-bit 128.5, work out what sRGB\n       * (non-associated) value generates 128.5; any value less than this is\n       * going to map to 0, so the worst error is floor(value).\n       *\n       * Note that errors are considerably higher (more than a factor of 2)\n       * because libpng uses a simple power law for sRGB data at present.\n       *\n       * Add .1 for arithmetic errors inside libpng.\n       */\n      double v = floor(255*pow(.5/*(128.5 * 255 / 65535)*/ / alpha, 1/2.2)+.1);\n\n      error_via_linear[alpha] = (int)v;\n   }\n\n   /* This is actually 14.99, but, despite the closeness to 15, 14 seems to work\n    * ok in this case.\n    */\n   error_in_libpng_gamma = 14;\n}\n#endif\n\nstatic void\nprint_pixel(char string[64], const Pixel *pixel, png_uint_32 format)\n{\n   switch (format & (PNG_FORMAT_FLAG_ALPHA|PNG_FORMAT_FLAG_COLOR))\n   {\n      case 0:\n         sprintf(string, \"%s(%d)\", format_names[format], pixel->g);\n         break;\n\n      case PNG_FORMAT_FLAG_ALPHA:\n         sprintf(string, \"%s(%d,%d)\", format_names[format], pixel->g,\n            pixel->a);\n         break;\n\n      case PNG_FORMAT_FLAG_COLOR:\n         sprintf(string, \"%s(%d,%d,%d)\", format_names[format],\n            pixel->r, pixel->g, pixel->b);\n         break;\n\n      case PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA:\n         sprintf(string, \"%s(%d,%d,%d,%d)\", format_names[format],\n            pixel->r, pixel->g, pixel->b, pixel->a);\n         break;\n\n      default:\n         sprintf(string, \"invalid-format\");\n         break;\n   }\n}\n\nstatic int\nlogpixel(const Transform *transform, png_uint_32 x, png_uint_32 y,\n   const Pixel *in, const Pixel *calc, const Pixel *out, const char *reason)\n{\n   const png_uint_32 in_format = transform->in_image->image.format;\n   const png_uint_32 out_format = transform->out_image->image.format;\n\n   png_uint_32 back_format = out_format & ~PNG_FORMAT_FLAG_ALPHA;\n   const char *via_linear = \"\";\n\n   char pixel_in[64], pixel_calc[64], pixel_out[64], pixel_loc[64];\n   char background_info[100];\n\n   print_pixel(pixel_in, in, in_format);\n   print_pixel(pixel_calc, calc, out_format);\n   print_pixel(pixel_out, out, out_format);\n\n   if (transform->is_palette)\n      sprintf(pixel_loc, \"palette: %lu\", (unsigned long)y);\n   else\n      sprintf(pixel_loc, \"%lu,%lu\", (unsigned long)x, (unsigned long)y);\n\n   if (transform->from_linear != NULL)\n   {\n      via_linear = \" (via linear)\";\n      /* And as a result the *read* format which did any background processing\n       * was itself linear, so the background color information is also\n       * linear.\n       */\n      back_format |= PNG_FORMAT_FLAG_LINEAR;\n   }\n\n   if (transform->background != NULL)\n   {\n      Pixel back;\n      char pixel_back[64];\n\n      back.r = transform->background->ir;\n      back.g = transform->background->ig;\n      back.b = transform->background->ib;\n      back.a = -1; /* not used */\n\n      print_pixel(pixel_back, &back, back_format);\n      sprintf(background_info, \" on background %s\", pixel_back);\n   }\n\n   else\n      background_info[0] = 0;\n\n   if (transform->in_image->file_name != transform->out_image->file_name)\n   {\n      char error_buffer[512];\n      sprintf(error_buffer,\n         \"(%s) %s error%s:\\n %s%s ->\\n       %s\\n  not: %s.\\n\"\n         \"Use --preserve and examine: \", pixel_loc, reason, via_linear,\n         pixel_in, background_info, pixel_out, pixel_calc);\n      return logerror(transform->in_image, transform->in_image->file_name,\n         error_buffer, transform->out_image->file_name);\n   }\n\n   else\n   {\n      char error_buffer[512];\n      sprintf(error_buffer,\n         \"(%s) %s error%s:\\n %s%s ->\\n       %s\\n  not: %s.\\n\"\n         \" The error happened when reading the original file with this format.\",\n         pixel_loc, reason, via_linear, pixel_in, background_info, pixel_out,\n         pixel_calc);\n      return logerror(transform->in_image, transform->in_image->file_name,\n         error_buffer, \"\");\n   }\n}\n\nstatic int\ncmppixel(Transform *transform, png_const_voidp in, png_const_voidp out,\n   png_uint_32 x, png_uint_32 y/*or palette index*/)\n{\n   int maxerr;\n   png_const_charp errmsg;\n   Pixel pixel_in, pixel_calc, pixel_out;\n\n   transform->in_gp(&pixel_in, in);\n\n   if (transform->from_linear == NULL)\n      transform->transform(&pixel_calc, &pixel_in, transform->background);\n\n   else\n   {\n      transform->transform(&pixel_out, &pixel_in, transform->background);\n      transform->from_linear(&pixel_calc, &pixel_out, NULL);\n   }\n\n   transform->out_gp(&pixel_out, out);\n\n   /* Eliminate the case where the input and output values match exactly. */\n   if (pixel_calc.a == pixel_out.a && pixel_calc.r == pixel_out.r &&\n      pixel_calc.g == pixel_out.g && pixel_calc.b == pixel_out.b)\n      return 1;\n\n   /* Eliminate the case where the output pixel is transparent and the output\n    * is 8-bit - any component values are valid.  Don't check the input alpha\n    * here to also skip the 16-bit small alpha cases.\n    */\n   if (transform->output_8bit && pixel_calc.a == 0 && pixel_out.a == 0)\n      return 1;\n\n   /* Check for alpha errors first; an alpha error can damage the components too\n    * so avoid spurious checks on components if one is found.\n    */\n   errmsg = NULL;\n   {\n      int err_a = abs(pixel_calc.a-pixel_out.a);\n\n      if (err_a > transform->error[3])\n      {\n         /* If accumulating check the components too */\n         if (transform->accumulate)\n            transform->error[3] = (png_uint_16)err_a;\n\n         else\n            errmsg = \"alpha\";\n      }\n   }\n\n   /* Now if *either* of the output alphas are 0 but alpha is within tolerance\n    * eliminate the 8-bit component comparison.\n    */\n   if (errmsg == NULL && transform->output_8bit &&\n      (pixel_calc.a == 0 || pixel_out.a == 0))\n      return 1;\n\n   if (errmsg == NULL) /* else just signal an alpha error */\n   {\n      int err_r = abs(pixel_calc.r - pixel_out.r);\n      int err_g = abs(pixel_calc.g - pixel_out.g);\n      int err_b = abs(pixel_calc.b - pixel_out.b);\n      int limit;\n\n      if ((err_r | err_g | err_b) == 0)\n         return 1; /* exact match */\n\n      /* Mismatch on a component, check the input alpha */\n      if (pixel_in.a >= transform->in_opaque)\n      {\n         errmsg = \"opaque component\";\n         limit = 2; /* opaque */\n      }\n\n      else if (pixel_in.a > 0)\n      {\n         errmsg = \"alpha component\";\n         limit = 1; /* partially transparent */\n      }\n\n      else\n      {\n         errmsg = \"transparent component (background)\";\n         limit = 0; /* transparent */\n      }\n\n      maxerr = err_r;\n      if (maxerr < err_g) maxerr = err_g;\n      if (maxerr < err_b) maxerr = err_b;\n\n      if (maxerr <= transform->error[limit])\n         return 1; /* within the error limits */\n\n      /* Handle a component mis-match; log it, just return an error code, or\n       * accumulate it.\n       */\n      if (transform->accumulate)\n      {\n         transform->error[limit] = (png_uint_16)maxerr;\n         return 1; /* to cause the caller to keep going */\n      }\n   }\n\n   /* Failure to match and not accumulating, so the error must be logged. */\n   return logpixel(transform, x, y, &pixel_in, &pixel_calc, &pixel_out, errmsg);\n}\n\nstatic png_byte\ncomponent_loc(png_byte loc[4], png_uint_32 format)\n{\n   /* Given a format return the number of channels and the location of\n    * each channel.\n    *\n    * The mask 'loc' contains the component offset of the channels in the\n    * following order.  Note that if 'format' is grayscale the entries 1-3 must\n    * all contain the location of the gray channel.\n    *\n    * 0: alpha\n    * 1: red or gray\n    * 2: green or gray\n    * 3: blue or gray\n    */\n   png_byte channels;\n\n   if (format & PNG_FORMAT_FLAG_COLOR)\n   {\n      channels = 3;\n\n      loc[2] = 1;\n\n#     ifdef PNG_FORMAT_BGR_SUPPORTED\n         if (format & PNG_FORMAT_FLAG_BGR)\n         {\n            loc[1] = 2;\n            loc[3] = 0;\n         }\n\n         else\n#     endif\n      {\n         loc[1] = 0;\n         loc[3] = 2;\n      }\n   }\n\n   else\n   {\n      channels = 1;\n      loc[1] = loc[2] = loc[3] = 0;\n   }\n\n   if (format & PNG_FORMAT_FLAG_ALPHA)\n   {\n#     ifdef PNG_FORMAT_AFIRST_SUPPORTED\n         if (format & PNG_FORMAT_FLAG_AFIRST)\n         {\n            loc[0] = 0;\n            ++loc[1];\n            ++loc[2];\n            ++loc[3];\n         }\n\n         else\n#     endif\n         loc[0] = channels;\n\n      ++channels;\n   }\n\n   else\n      loc[0] = 4; /* not present */\n\n   return channels;\n}\n\n/* Compare two images, the original 'a', which was written out then read back in\n * to * give image 'b'.  The formats may have been changed.\n */\nstatic int\ncompare_two_images(Image *a, Image *b, int via_linear,\n   png_const_colorp background)\n{\n   ptrdiff_t stridea = a->stride;\n   ptrdiff_t strideb = b->stride;\n   png_const_bytep rowa = a->buffer+16;\n   png_const_bytep rowb = b->buffer+16;\n   const png_uint_32 width = a->image.width;\n   const png_uint_32 height = a->image.height;\n   const png_uint_32 formata = a->image.format;\n   const png_uint_32 formatb = b->image.format;\n   const unsigned int a_sample = PNG_IMAGE_SAMPLE_SIZE(formata);\n   const unsigned int b_sample = PNG_IMAGE_SAMPLE_SIZE(formatb);\n   int alpha_added, alpha_removed;\n   int bchannels;\n   int btoa[4];\n   png_uint_32 y;\n   Transform tr;\n\n   /* This should never happen: */\n   if (width != b->image.width || height != b->image.height)\n      return logerror(a, a->file_name, \": width x height changed: \",\n         b->file_name);\n\n   /* Set up the background and the transform */\n   transform_from_formats(&tr, a, b, background, via_linear);\n\n   /* Find the first row and inter-row space. */\n   if (!(formata & PNG_FORMAT_FLAG_COLORMAP) &&\n      (formata & PNG_FORMAT_FLAG_LINEAR))\n      stridea *= 2;\n\n   if (!(formatb & PNG_FORMAT_FLAG_COLORMAP) &&\n      (formatb & PNG_FORMAT_FLAG_LINEAR))\n      strideb *= 2;\n\n   if (stridea < 0) rowa += (height-1) * (-stridea);\n   if (strideb < 0) rowb += (height-1) * (-strideb);\n\n   /* First shortcut the two colormap case by comparing the image data; if it\n    * matches then we expect the colormaps to match, although this is not\n    * absolutely necessary for an image match.  If the colormaps fail to match\n    * then there is a problem in libpng.\n    */\n   if (formata & formatb & PNG_FORMAT_FLAG_COLORMAP)\n   {\n      /* Only check colormap entries that actually exist; */\n      png_const_bytep ppa, ppb;\n      int match;\n      png_byte in_use[256], amax = 0, bmax = 0;\n\n      memset(in_use, 0, sizeof in_use);\n\n      ppa = rowa;\n      ppb = rowb;\n\n      /* Do this the slow way to accumulate the 'in_use' flags, don't break out\n       * of the loop until the end; this validates the color-mapped data to\n       * ensure all pixels are valid color-map indexes.\n       */\n      for (y=0, match=1; y<height && match; ++y, ppa += stridea, ppb += strideb)\n      {\n         png_uint_32 x;\n\n         for (x=0; x<width; ++x)\n         {\n            png_byte bval = ppb[x];\n            png_byte aval = ppa[x];\n\n            if (bval > bmax)\n               bmax = bval;\n\n            if (bval != aval)\n               match = 0;\n\n            in_use[aval] = 1;\n            if (aval > amax)\n               amax = aval;\n         }\n      }\n\n      /* If the buffers match then the colormaps must too. */\n      if (match)\n      {\n         /* Do the color-maps match, entry by entry?  Only check the 'in_use'\n          * entries.  An error here should be logged as a color-map error.\n          */\n         png_const_bytep a_cmap = (png_const_bytep)a->colormap;\n         png_const_bytep b_cmap = (png_const_bytep)b->colormap;\n         int result = 1; /* match by default */\n\n         /* This is used in logpixel to get the error message correct. */\n         tr.is_palette = 1;\n\n         for (y=0; y<256; ++y, a_cmap += a_sample, b_cmap += b_sample)\n            if (in_use[y])\n         {\n            /* The colormap entries should be valid, but because libpng doesn't\n             * do any checking at present the original image may contain invalid\n             * pixel values.  These cause an error here (at present) unless\n             * accumulating errors in which case the program just ignores them.\n             */\n            if (y >= a->image.colormap_entries)\n            {\n               if ((a->opts & ACCUMULATE) == 0)\n               {\n                  char pindex[9];\n                  sprintf(pindex, \"%lu[%lu]\", (unsigned long)y,\n                     (unsigned long)a->image.colormap_entries);\n                  logerror(a, a->file_name, \": bad pixel index: \", pindex);\n               }\n               result = 0;\n            }\n\n            else if (y >= b->image.colormap_entries)\n            {\n               if ((b->opts & ACCUMULATE) == 0)\n                  {\n                  char pindex[9];\n                  sprintf(pindex, \"%lu[%lu]\", (unsigned long)y,\n                     (unsigned long)b->image.colormap_entries);\n                  logerror(b, b->file_name, \": bad pixel index: \", pindex);\n                  }\n               result = 0;\n            }\n\n            /* All the mismatches are logged here; there can only be 256! */\n            else if (!cmppixel(&tr, a_cmap, b_cmap, 0, y))\n               result = 0;\n         }\n\n         /* If reqested copy the error values back from the Transform. */\n         if (a->opts & ACCUMULATE)\n         {\n            tr.error_ptr[0] = tr.error[0];\n            tr.error_ptr[1] = tr.error[1];\n            tr.error_ptr[2] = tr.error[2];\n            tr.error_ptr[3] = tr.error[3];\n            result = 1; /* force a continue */\n         }\n\n         return result;\n      }\n\n      /* else the image buffers don't match pixel-wise so compare sample values\n       * instead, but first validate that the pixel indexes are in range (but\n       * only if not accumulating, when the error is ignored.)\n       */\n      else if ((a->opts & ACCUMULATE) == 0)\n      {\n         /* Check the original image first,\n          * TODO: deal with input images with bad pixel values?\n          */\n         if (amax >= a->image.colormap_entries)\n         {\n            char pindex[9];\n            sprintf(pindex, \"%d[%lu]\", amax,\n               (unsigned long)a->image.colormap_entries);\n            return logerror(a, a->file_name, \": bad pixel index: \", pindex);\n         }\n\n         else if (bmax >= b->image.colormap_entries)\n         {\n            char pindex[9];\n            sprintf(pindex, \"%d[%lu]\", bmax,\n               (unsigned long)b->image.colormap_entries);\n            return logerror(b, b->file_name, \": bad pixel index: \", pindex);\n         }\n      }\n   }\n\n   /* We can directly compare pixel values without the need to use the read\n    * or transform support (i.e. a memory compare) if:\n    *\n    * 1) The bit depth has not changed.\n    * 2) RGB to grayscale has not been done (the reverse is ok; we just compare\n    *    the three RGB values to the original grayscale.)\n    * 3) An alpha channel has not been removed from an 8-bit format, or the\n    *    8-bit alpha value of the pixel was 255 (opaque).\n    *\n    * If an alpha channel has been *added* then it must have the relevant opaque\n    * value (255 or 65535).\n    *\n    * The fist two the tests (in the order given above) (using the boolean\n    * equivalence !a && !b == !(a || b))\n    */\n   if (!(((formata ^ formatb) & PNG_FORMAT_FLAG_LINEAR) |\n      (formata & (formatb ^ PNG_FORMAT_FLAG_COLOR) & PNG_FORMAT_FLAG_COLOR)))\n   {\n      /* Was an alpha channel changed? */\n      const png_uint_32 alpha_changed = (formata ^ formatb) &\n         PNG_FORMAT_FLAG_ALPHA;\n\n      /* Was an alpha channel removed?  (The third test.)  If so the direct\n       * comparison is only possible if the input alpha is opaque.\n       */\n      alpha_removed = (formata & alpha_changed) != 0;\n\n      /* Was an alpha channel added? */\n      alpha_added = (formatb & alpha_changed) != 0;\n\n      /* The channels may have been moved between input and output, this finds\n       * out how, recording the result in the btoa array, which says where in\n       * 'a' to find each channel of 'b'.  If alpha was added then btoa[alpha]\n       * ends up as 4 (and is not used.)\n       */\n      {\n         int i;\n         png_byte aloc[4];\n         png_byte bloc[4];\n\n         /* The following are used only if the formats match, except that\n          * 'bchannels' is a flag for matching formats.  btoa[x] says, for each\n          * channel in b, where to find the corresponding value in a, for the\n          * bchannels.  achannels may be different for a gray to rgb transform\n          * (a will be 1 or 2, b will be 3 or 4 channels.)\n          */\n         (void)component_loc(aloc, formata);\n         bchannels = component_loc(bloc, formatb);\n\n         /* Hence the btoa array. */\n         for (i=0; i<4; ++i) if (bloc[i] < 4)\n            btoa[bloc[i]] = aloc[i]; /* may be '4' for alpha */\n\n         if (alpha_added)\n            alpha_added = bloc[0]; /* location of alpha channel in image b */\n\n         else\n            alpha_added = 4; /* Won't match an image b channel */\n\n         if (alpha_removed)\n            alpha_removed = aloc[0]; /* location of alpha channel in image a */\n\n         else\n            alpha_removed = 4;\n      }\n   }\n\n   else\n   {\n      /* Direct compare is not possible, cancel out all the corresponding local\n       * variables.\n       */\n      bchannels = 0;\n      alpha_removed = alpha_added = 4;\n      btoa[3] = btoa[2] = btoa[1] = btoa[0] = 4; /* 4 == not present */\n   }\n\n   for (y=0; y<height; ++y, rowa += stridea, rowb += strideb)\n   {\n      png_const_bytep ppa, ppb;\n      png_uint_32 x;\n\n      for (x=0, ppa=rowa, ppb=rowb; x<width; ++x)\n      {\n         png_const_bytep psa, psb;\n\n         if (formata & PNG_FORMAT_FLAG_COLORMAP)\n            psa = (png_const_bytep)a->colormap + a_sample * *ppa++;\n         else\n            psa = ppa, ppa += a_sample;\n\n         if (formatb & PNG_FORMAT_FLAG_COLORMAP)\n            psb = (png_const_bytep)b->colormap + b_sample * *ppb++;\n         else\n            psb = ppb, ppb += b_sample;\n\n         /* Do the fast test if possible. */\n         if (bchannels)\n         {\n            /* Check each 'b' channel against either the corresponding 'a'\n             * channel or the opaque alpha value, as appropriate.  If\n             * alpha_removed value is set (not 4) then also do this only if the\n             * 'a' alpha channel (alpha_removed) is opaque; only relevant for\n             * the 8-bit case.\n             */\n            if (formatb & PNG_FORMAT_FLAG_LINEAR) /* 16-bit checks */\n            {\n               png_const_uint_16p pua = aligncastconst(png_const_uint_16p, psa);\n               png_const_uint_16p pub = aligncastconst(png_const_uint_16p, psb);\n\n               switch (bchannels)\n               {\n                  case 4:\n                     if (pua[btoa[3]] != pub[3]) break;\n                  case 3:\n                     if (pua[btoa[2]] != pub[2]) break;\n                  case 2:\n                     if (pua[btoa[1]] != pub[1]) break;\n                  case 1:\n                     if (pua[btoa[0]] != pub[0]) break;\n                     if (alpha_added != 4 && pub[alpha_added] != 65535) break;\n                     continue; /* x loop */\n                  default:\n                     break; /* impossible */\n               }\n            }\n\n            else if (alpha_removed == 4 || psa[alpha_removed] == 255)\n            {\n               switch (bchannels)\n               {\n                  case 4:\n                     if (psa[btoa[3]] != psb[3]) break;\n                  case 3:\n                     if (psa[btoa[2]] != psb[2]) break;\n                  case 2:\n                     if (psa[btoa[1]] != psb[1]) break;\n                  case 1:\n                     if (psa[btoa[0]] != psb[0]) break;\n                     if (alpha_added != 4 && psb[alpha_added] != 255) break;\n                     continue; /* x loop */\n                  default:\n                     break; /* impossible */\n               }\n            }\n         }\n\n         /* If we get to here the fast match failed; do the slow match for this\n          * pixel.\n          */\n         if (!cmppixel(&tr, psa, psb, x, y) && (a->opts & KEEP_GOING) == 0)\n            return 0; /* error case */\n      }\n   }\n\n   /* If reqested copy the error values back from the Transform. */\n   if (a->opts & ACCUMULATE)\n   {\n      tr.error_ptr[0] = tr.error[0];\n      tr.error_ptr[1] = tr.error[1];\n      tr.error_ptr[2] = tr.error[2];\n      tr.error_ptr[3] = tr.error[3];\n   }\n\n   return 1;\n}\n\n/* Read the file; how the read gets done depends on which of input_file and\n * input_memory have been set.\n */\nstatic int\nread_file(Image *image, png_uint_32 format, png_const_colorp background)\n{\n   memset(&image->image, 0, sizeof image->image);\n   image->image.version = PNG_IMAGE_VERSION;\n\n   if (image->input_memory != NULL)\n   {\n      if (!png_image_begin_read_from_memory(&image->image, image->input_memory,\n         image->input_memory_size))\n         return logerror(image, \"memory init: \", image->file_name, \"\");\n   }\n\n#  ifdef PNG_STDIO_SUPPORTED\n      else if (image->input_file != NULL)\n      {\n         if (!png_image_begin_read_from_stdio(&image->image, image->input_file))\n            return logerror(image, \"stdio init: \", image->file_name, \"\");\n      }\n\n      else\n      {\n         if (!png_image_begin_read_from_file(&image->image, image->file_name))\n            return logerror(image, \"file init: \", image->file_name, \"\");\n      }\n#  else\n      else\n      {\n         return logerror(image, \"unsupported file/stdio init: \",\n            image->file_name, \"\");\n      }\n#  endif\n\n   /* This must be set after the begin_read call: */\n   if (image->opts & sRGB_16BIT)\n      image->image.flags |= PNG_IMAGE_FLAG_16BIT_sRGB;\n\n   /* Have an initialized image with all the data we need plus, maybe, an\n    * allocated file (myfile) or buffer (mybuffer) that need to be freed.\n    */\n   {\n      int result;\n      png_uint_32 image_format;\n\n      /* Print both original and output formats. */\n      image_format = image->image.format;\n\n      if (image->opts & VERBOSE)\n      {\n         printf(\"%s %lu x %lu %s -> %s\", image->file_name,\n            (unsigned long)image->image.width,\n            (unsigned long)image->image.height,\n            format_names[image_format & FORMAT_MASK],\n            (format & FORMAT_NO_CHANGE) != 0 || image->image.format == format\n            ? \"no change\" : format_names[format & FORMAT_MASK]);\n\n         if (background != NULL)\n            printf(\" background(%d,%d,%d)\\n\", background->red,\n               background->green, background->blue);\n         else\n            printf(\"\\n\");\n\n         fflush(stdout);\n      }\n\n      /* 'NO_CHANGE' combined with the color-map flag forces the base format\n       * flags to be set on read to ensure that the original representation is\n       * not lost in the pass through a colormap format.\n       */\n      if ((format & FORMAT_NO_CHANGE) != 0)\n      {\n         if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0 &&\n            (image_format & PNG_FORMAT_FLAG_COLORMAP) != 0)\n            format = (image_format & ~BASE_FORMATS) | (format & BASE_FORMATS);\n\n         else\n            format = image_format;\n      }\n\n      image->image.format = format;\n\n      image->stride = PNG_IMAGE_ROW_STRIDE(image->image) + image->stride_extra;\n      allocbuffer(image);\n\n      result = png_image_finish_read(&image->image, background,\n         image->buffer+16, (png_int_32)image->stride, image->colormap);\n\n      checkbuffer(image, image->file_name);\n\n      if (result)\n         return checkopaque(image);\n\n      else\n         return logerror(image, image->file_name, \": image read failed\", \"\");\n   }\n}\n\n/* Reads from a filename, which must be in image->file_name, but uses\n * image->opts to choose the method.  The file is always read in its native\n * format (the one the simplified API suggests).\n */\nstatic int\nread_one_file(Image *image)\n{\n   if (!(image->opts & USE_FILE) || (image->opts & USE_STDIO))\n   {\n      /* memory or stdio. */\n      FILE *f = fopen(image->file_name, \"rb\");\n\n      if (f != NULL)\n      {\n         if (image->opts & USE_FILE)\n            image->input_file = f;\n\n         else /* memory */\n         {\n            if (fseek(f, 0, SEEK_END) == 0)\n            {\n               long int cb = ftell(f);\n\n               if (cb > 0)\n               {\n#ifndef __COVERITY__\n                  if ((unsigned long int)cb <= (size_t)~(size_t)0)\n#endif\n                  {\n                     png_bytep b = voidcast(png_bytep, malloc((size_t)cb));\n\n                     if (b != NULL)\n                     {\n                        rewind(f);\n\n                        if (fread(b, (size_t)cb, 1, f) == 1)\n                        {\n                           fclose(f);\n                           image->input_memory_size = cb;\n                           image->input_memory = b;\n                        }\n\n                        else\n                        {\n                           free(b);\n                           return logclose(image, f, image->file_name,\n                              \": read failed: \");\n                        }\n                     }\n\n                     else\n                        return logclose(image, f, image->file_name,\n                           \": out of memory: \");\n                  }\n\n                  else\n                     return logclose(image, f, image->file_name,\n                        \": file too big for this architecture: \");\n                     /* cb is the length of the file as a (long) and\n                      * this is greater than the maximum amount of\n                      * memory that can be requested from malloc.\n                      */\n               }\n\n               else if (cb == 0)\n                  return logclose(image, f, image->file_name,\n                     \": zero length: \");\n\n               else\n                  return logclose(image, f, image->file_name,\n                     \": tell failed: \");\n            }\n\n            else\n               return logclose(image, f, image->file_name, \": seek failed: \");\n         }\n      }\n\n      else\n         return logerror(image, image->file_name, \": open failed: \",\n            strerror(errno));\n   }\n\n   return read_file(image, FORMAT_NO_CHANGE, NULL);\n}\n\n#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED\nstatic int\nwrite_one_file(Image *output, Image *image, int convert_to_8bit)\n{\n   if (image->opts & FAST_WRITE)\n      image->image.flags |= PNG_IMAGE_FLAG_FAST;\n\n   if (image->opts & USE_STDIO)\n   {\n#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\n#ifndef __COVERITY__\n      FILE *f = tmpfile();\n#else\n      /* Experimental. Coverity says tmpfile() is insecure because it\n       * generates predictable names.\n       *\n       * It is possible to satisfy Coverity by using mkstemp(); however,\n       * any platform supporting mkstemp() undoubtedly has a secure tmpfile()\n       * implementation as well, and doesn't need the fix.  Note that\n       * the fix won't work on platforms that don't support mkstemp().\n       *\n       * https://www.securecoding.cert.org/confluence/display/c/\n       * FIO21-C.+Do+not+create+temporary+files+in+shared+directories\n       * says that most historic implementations of tmpfile() provide\n       * only a limited number of possible temporary file names\n       * (usually 26) before file names are recycled. That article also\n       * provides a secure solution that unfortunately depends upon mkstemp().\n       */\n      char tmpfile[] = \"pngstest-XXXXXX\";\n      int filedes;\n      FILE *f;\n      umask(0177);\n      filedes = mkstemp(tmpfile);\n      if (filedes < 0)\n        f = NULL;\n      else\n      {\n        f = fdopen(filedes,\"w+\");\n        /* Hide the filename immediately and ensure that the file does\n         * not exist after the program ends\n         */\n        (void) unlink(tmpfile);\n      }\n#endif\n\n      if (f != NULL)\n      {\n         if (png_image_write_to_stdio(&image->image, f, convert_to_8bit,\n            image->buffer+16, (png_int_32)image->stride, image->colormap))\n         {\n            if (fflush(f) == 0)\n            {\n               rewind(f);\n               initimage(output, image->opts, \"tmpfile\", image->stride_extra);\n               output->input_file = f;\n               if (!checkopaque(image))\n                  return 0;\n            }\n\n            else\n               return logclose(image, f, \"tmpfile\", \": flush: \");\n         }\n\n         else\n         {\n            fclose(f);\n            return logerror(image, \"tmpfile\", \": write failed\", \"\");\n         }\n      }\n\n      else\n         return logerror(image, \"tmpfile\", \": open: \", strerror(errno));\n#else /* SIMPLIFIED_WRITE_STDIO */\n      return logerror(image, \"tmpfile\", \": open: unsupported\", \"\");\n#endif /* SIMPLIFIED_WRITE_STDIO */\n   }\n\n   else if (image->opts & USE_FILE)\n   {\n#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\n      static int counter = 0;\n      char name[32];\n\n      sprintf(name, \"%s%d.png\", tmpf, ++counter);\n\n      if (png_image_write_to_file(&image->image, name, convert_to_8bit,\n         image->buffer+16, (png_int_32)image->stride, image->colormap))\n      {\n         initimage(output, image->opts, output->tmpfile_name,\n            image->stride_extra);\n         /* Afterwards, or freeimage will delete it! */\n         strcpy(output->tmpfile_name, name);\n\n         if (!checkopaque(image))\n            return 0;\n      }\n\n      else\n         return logerror(image, name, \": write failed\", \"\");\n#else /* SIMPLIFIED_WRITE_STDIO */\n      return logerror(image, \"stdio\", \": open: unsupported\", \"\");\n#endif /* SIMPLIFIED_WRITE_STDIO */\n   }\n\n   else /* use memory */\n   {\n      png_alloc_size_t size;\n\n      if (png_image_write_get_memory_size(image->image, size, convert_to_8bit,\n               image->buffer+16, (png_int_32)image->stride, image->colormap))\n      {\n         /* This is non-fatal but ignoring it was causing serious problems in\n          * the macro to be ignored:\n          */\n         if (size > PNG_IMAGE_PNG_SIZE_MAX(image->image))\n            return logerror(image, \"memory\", \": PNG_IMAGE_SIZE_MAX wrong\", \"\");\n\n         initimage(output, image->opts, \"memory\", image->stride_extra);\n         output->input_memory = malloc(size);\n\n         if (output->input_memory != NULL)\n         {\n            output->input_memory_size = size;\n\n            if (png_image_write_to_memory(&image->image, output->input_memory,\n                  &output->input_memory_size, convert_to_8bit, image->buffer+16,\n                  (png_int_32)image->stride, image->colormap))\n            {\n               /* This is also non-fatal but it safes safer to error out anyway:\n                */\n               if (size != output->input_memory_size)\n                  return logerror(image, \"memory\", \": memory size wrong\", \"\");\n            }\n\n            else\n               return logerror(image, \"memory\", \": write failed\", \"\");\n         }\n\n         else\n            return logerror(image, \"memory\", \": out of memory\", \"\");\n      }\n\n      else\n         return logerror(image, \"memory\", \": get size:\", \"\");\n   }\n\n   /* 'output' has an initialized temporary image, read this back in and compare\n    * this against the original: there should be no change since the original\n    * format was written unmodified unless 'convert_to_8bit' was specified.\n    * However, if the original image was color-mapped, a simple read will zap\n    * the linear, color and maybe alpha flags, this will cause spurious failures\n    * under some circumstances.\n    */\n   if (read_file(output, image->image.format | FORMAT_NO_CHANGE, NULL))\n   {\n      png_uint_32 original_format = image->image.format;\n\n      if (convert_to_8bit)\n         original_format &= ~PNG_FORMAT_FLAG_LINEAR;\n\n      if ((output->image.format & BASE_FORMATS) !=\n         (original_format & BASE_FORMATS))\n         return logerror(image, image->file_name, \": format changed on read: \",\n            output->file_name);\n\n      return compare_two_images(image, output, 0/*via linear*/, NULL);\n   }\n\n   else\n      return logerror(output, output->tmpfile_name,\n         \": read of new file failed\", \"\");\n}\n#endif\n\nstatic int\ntestimage(Image *image, png_uint_32 opts, format_list *pf)\n{\n   int result;\n   Image copy;\n\n   /* Copy the original data, stealing it from 'image' */\n   checkopaque(image);\n   copy = *image;\n\n   copy.opts = opts;\n   copy.buffer = NULL;\n   copy.bufsize = 0;\n   copy.allocsize = 0;\n\n   image->input_file = NULL;\n   image->input_memory = NULL;\n   image->input_memory_size = 0;\n   image->tmpfile_name[0] = 0;\n\n   {\n      png_uint_32 counter;\n      Image output;\n\n      newimage(&output);\n\n      result = 1;\n\n      /* Use the low bit of 'counter' to indicate whether or not to do alpha\n       * removal with a background color or by composting onto the image; this\n       * step gets skipped if it isn't relevant\n       */\n      for (counter=0; counter<2*FORMAT_COUNT; ++counter)\n         if (format_isset(pf, counter >> 1))\n      {\n         png_uint_32 format = counter >> 1;\n\n         png_color background_color;\n         png_colorp background = NULL;\n\n         /* If there is a format change that removes the alpha channel then\n          * the background is relevant.  If the output is 8-bit color-mapped\n          * then a background color *must* be provided, otherwise there are\n          * two tests to do - one with a color, the other with NULL.  The\n          * NULL test happens second.\n          */\n         if ((counter & 1) == 0)\n         {\n            if ((format & PNG_FORMAT_FLAG_ALPHA) == 0 &&\n               (image->image.format & PNG_FORMAT_FLAG_ALPHA) != 0)\n            {\n               /* Alpha/transparency will be removed, the background is\n                * relevant: make it a color the first time\n                */\n               random_color(&background_color);\n               background = &background_color;\n\n               /* BUT if the output is to a color-mapped 8-bit format then\n                * the background must always be a color, so increment 'counter'\n                * to skip the NULL test.\n                */\n               if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0 &&\n                  (format & PNG_FORMAT_FLAG_LINEAR) == 0)\n                  ++counter;\n            }\n\n            /* Otherwise an alpha channel is not being eliminated, just leave\n             * background NULL and skip the (counter & 1) NULL test.\n             */\n            else\n               ++counter;\n         }\n         /* else just use NULL for background */\n\n         resetimage(&copy);\n         copy.opts = opts; /* in case read_file needs to change it */\n\n         result = read_file(&copy, format, background);\n         if (!result)\n            break;\n\n         /* Make sure the file just read matches the original file. */\n         result = compare_two_images(image, &copy, 0/*via linear*/, background);\n         if (!result)\n            break;\n\n#        ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED\n            /* Write the *copy* just made to a new file to make sure the write\n             * side works ok.  Check the conversion to sRGB if the copy is\n             * linear.\n             */\n            output.opts = opts;\n            result = write_one_file(&output, &copy, 0/*convert to 8bit*/);\n            if (!result)\n               break;\n\n            /* Validate against the original too; the background is needed here\n             * as well so that compare_two_images knows what color was used.\n             */\n            result = compare_two_images(image, &output, 0, background);\n            if (!result)\n               break;\n\n            if ((format & PNG_FORMAT_FLAG_LINEAR) != 0 &&\n               (format & PNG_FORMAT_FLAG_COLORMAP) == 0)\n            {\n               /* 'output' is linear, convert to the corresponding sRGB format.\n                */\n               output.opts = opts;\n               result = write_one_file(&output, &copy, 1/*convert to 8bit*/);\n               if (!result)\n                  break;\n\n               /* This may involve a conversion via linear; in the ideal world\n                * this would round-trip correctly, but libpng 1.5.7 is not the\n                * ideal world so allow a drift (error_via_linear).\n                *\n                * 'image' has an alpha channel but 'output' does not then there\n                * will a strip-alpha-channel operation (because 'output' is\n                * linear), handle this by composing on black when doing the\n                * comparison.\n                */\n               result = compare_two_images(image, &output, 1/*via_linear*/,\n                  background);\n               if (!result)\n                  break;\n            }\n#        endif /* PNG_SIMPLIFIED_WRITE_SUPPORTED */\n      }\n\n      freeimage(&output);\n   }\n\n   freeimage(&copy);\n\n   return result;\n}\n\nstatic int\ntest_one_file(const char *file_name, format_list *formats, png_uint_32 opts,\n   int stride_extra, int log_pass)\n{\n   int result;\n   Image image;\n\n   if (!(opts & NO_RESEED))\n      reseed(); /* ensure that the random numbers don't depend on file order */\n   newimage(&image);\n   initimage(&image, opts, file_name, stride_extra);\n   result = read_one_file(&image);\n   if (result)\n      result = testimage(&image, opts, formats);\n   freeimage(&image);\n\n   /* Ensure that stderr is flushed into any log file */\n   fflush(stderr);\n\n   if (log_pass)\n   {\n      if (result)\n         printf(\"PASS:\");\n\n      else\n         printf(\"FAIL:\");\n\n#     ifndef PNG_SIMPLIFIED_WRITE_SUPPORTED\n         printf(\" (no write)\");\n#     endif\n\n      print_opts(opts);\n      printf(\" %s\\n\", file_name);\n      /* stdout may not be line-buffered if it is piped to a file, so: */\n      fflush(stdout);\n   }\n\n   else if (!result)\n      exit(1);\n\n   return result;\n}\n\nint\nmain(int argc, char **argv)\n{\n   png_uint_32 opts = FAST_WRITE | STRICT;\n   format_list formats;\n   const char *touch = NULL;\n   int log_pass = 0;\n   int redundant = 0;\n   int stride_extra = 0;\n   int retval = 0;\n   int c;\n\n#if PNG_LIBPNG_VER >= 10700\n      /* This error should not exist in 1.7 or later: */\n      opts |= GBG_ERROR;\n#endif\n\n   init_sRGB_to_d();\n#if 0\n   init_error_via_linear();\n#endif\n   format_init(&formats);\n   reseed(); /* initialize random number seeds */\n\n   for (c=1; c<argc; ++c)\n   {\n      const char *arg = argv[c];\n\n      if (strcmp(arg, \"--log\") == 0)\n         log_pass = 1;\n      else if (strcmp(arg, \"--fresh\") == 0)\n      {\n         memset(gpc_error, 0, sizeof gpc_error);\n         memset(gpc_error_via_linear, 0, sizeof gpc_error_via_linear);\n      }\n      else if (strcmp(arg, \"--file\") == 0)\n#        ifdef PNG_STDIO_SUPPORTED\n            opts |= USE_FILE;\n#        else\n            return SKIP; /* skipped: no support */\n#        endif\n      else if (strcmp(arg, \"--memory\") == 0)\n         opts &= ~USE_FILE;\n      else if (strcmp(arg, \"--stdio\") == 0)\n#        ifdef PNG_STDIO_SUPPORTED\n            opts |= USE_STDIO;\n#        else\n            return SKIP; /* skipped: no support */\n#        endif\n      else if (strcmp(arg, \"--name\") == 0)\n         opts &= ~USE_STDIO;\n      else if (strcmp(arg, \"--verbose\") == 0)\n         opts |= VERBOSE;\n      else if (strcmp(arg, \"--quiet\") == 0)\n         opts &= ~VERBOSE;\n      else if (strcmp(arg, \"--preserve\") == 0)\n         opts |= KEEP_TMPFILES;\n      else if (strcmp(arg, \"--nopreserve\") == 0)\n         opts &= ~KEEP_TMPFILES;\n      else if (strcmp(arg, \"--keep-going\") == 0)\n         opts |= KEEP_GOING;\n      else if (strcmp(arg, \"--fast\") == 0)\n         opts |= FAST_WRITE;\n      else if (strcmp(arg, \"--slow\") == 0)\n         opts &= ~FAST_WRITE;\n      else if (strcmp(arg, \"--accumulate\") == 0)\n         opts |= ACCUMULATE;\n      else if (strcmp(arg, \"--redundant\") == 0)\n         redundant = 1;\n      else if (strcmp(arg, \"--stop\") == 0)\n         opts &= ~KEEP_GOING;\n      else if (strcmp(arg, \"--strict\") == 0)\n         opts |= STRICT;\n      else if (strcmp(arg, \"--nostrict\") == 0)\n         opts &= ~STRICT;\n      else if (strcmp(arg, \"--sRGB-16bit\") == 0)\n         opts |= sRGB_16BIT;\n      else if (strcmp(arg, \"--linear-16bit\") == 0)\n         opts &= ~sRGB_16BIT;\n      else if (strcmp(arg, \"--noreseed\") == 0)\n         opts |= NO_RESEED;\n      else if (strcmp(arg, \"--fault-gbg-warning\") == 0)\n         opts |= GBG_ERROR;\n      else if (strcmp(arg, \"--tmpfile\") == 0)\n      {\n         if (c+1 < argc)\n         {\n            if (strlen(argv[++c]) >= sizeof tmpf)\n            {\n               fflush(stdout);\n               fprintf(stderr, \"%s: %s is too long for a temp file prefix\\n\",\n                  argv[0], argv[c]);\n               exit(99);\n            }\n\n            /* Safe: checked above */\n            strncpy(tmpf, argv[c], sizeof (tmpf)-1);\n         }\n\n         else\n         {\n            fflush(stdout);\n            fprintf(stderr, \"%s: %s requires a temporary file prefix\\n\",\n               argv[0], arg);\n            exit(99);\n         }\n      }\n      else if (strcmp(arg, \"--touch\") == 0)\n      {\n         if (c+1 < argc)\n            touch = argv[++c];\n\n         else\n         {\n            fflush(stdout);\n            fprintf(stderr, \"%s: %s requires a file name argument\\n\",\n               argv[0], arg);\n            exit(99);\n         }\n      }\n      else if (arg[0] == '+')\n      {\n         png_uint_32 format = formatof(arg+1);\n\n         if (format > FORMAT_COUNT)\n            exit(99);\n\n         format_set(&formats, format);\n      }\n      else if (arg[0] == '-' && arg[1] != 0 && (arg[1] != '0' || arg[2] != 0))\n      {\n         fflush(stdout);\n         fprintf(stderr, \"%s: unknown option: %s\\n\", argv[0], arg);\n         exit(99);\n      }\n      else\n      {\n         if (format_is_initial(&formats))\n            format_default(&formats, redundant);\n\n         if (arg[0] == '-')\n         {\n            const int term = (arg[1] == '0' ? 0 : '\\n');\n            unsigned int ich = 0;\n\n            /* Loop reading files, use a static buffer to simplify this and just\n             * stop if the name gets to long.\n             */\n            static char buffer[4096];\n\n            do\n            {\n               int ch = getchar();\n\n               /* Don't allow '\\0' in file names, and terminate with '\\n' or,\n                * for -0, just '\\0' (use -print0 to find to make this work!)\n                */\n               if (ch == EOF || ch == term || ch == 0)\n               {\n                  buffer[ich] = 0;\n\n                  if (ich > 0 && !test_one_file(buffer, &formats, opts,\n                     stride_extra, log_pass))\n                     retval = 1;\n\n                  if (ch == EOF)\n                     break;\n\n                  ich = 0;\n                  --ich; /* so that the increment below sets it to 0 again */\n               }\n\n               else\n                  buffer[ich] = (char)ch;\n            } while (++ich < sizeof buffer);\n\n            if (ich)\n            {\n               buffer[32] = 0;\n               buffer[4095] = 0;\n               fprintf(stderr, \"%s...%s: file name too long\\n\", buffer,\n                  buffer+(4096-32));\n               exit(99);\n            }\n         }\n\n         else if (!test_one_file(arg, &formats, opts, stride_extra, log_pass))\n            retval = 1;\n      }\n   }\n\n   if (opts & ACCUMULATE)\n   {\n      unsigned int in;\n\n      printf(\"/* contrib/libtests/pngstest-errors.h\\n\");\n      printf(\" *\\n\");\n      printf(\" * BUILT USING:\" PNG_HEADER_VERSION_STRING);\n      printf(\" *\\n\");\n      printf(\" * This code is released under the libpng license.\\n\");\n      printf(\" * For conditions of distribution and use, see the disclaimer\\n\");\n      printf(\" * and license in png.h\\n\");\n      printf(\" *\\n\");\n      printf(\" * THIS IS A MACHINE GENERATED FILE: do not edit it directly!\\n\");\n      printf(\" * Instead run:\\n\");\n      printf(\" *\\n\");\n      printf(\" *    pngstest --accumulate\\n\");\n      printf(\" *\\n\");\n      printf(\" * on as many PNG files as possible; at least PNGSuite and\\n\");\n      printf(\" * contrib/libtests/testpngs.\\n\");\n      printf(\" */\\n\");\n\n      printf(\"static png_uint_16 gpc_error[16/*in*/][16/*out*/][4/*a*/] =\\n\");\n      printf(\"{\\n\");\n      for (in=0; in<16; ++in)\n      {\n         unsigned int out;\n         printf(\" { /* input: %s */\\n \", format_names[in]);\n         for (out=0; out<16; ++out)\n         {\n            unsigned int alpha;\n            printf(\" {\");\n            for (alpha=0; alpha<4; ++alpha)\n            {\n               printf(\" %d\", gpc_error[in][out][alpha]);\n               if (alpha < 3) putchar(',');\n            }\n            printf(\" }\");\n            if (out < 15)\n            {\n               putchar(',');\n               if (out % 4 == 3) printf(\"\\n \");\n            }\n         }\n         printf(\"\\n }\");\n\n         if (in < 15)\n            putchar(',');\n         else\n            putchar('\\n');\n      }\n      printf(\"};\\n\");\n\n      printf(\"static png_uint_16 gpc_error_via_linear[16][4/*out*/][4] =\\n\");\n      printf(\"{\\n\");\n      for (in=0; in<16; ++in)\n      {\n         unsigned int out;\n         printf(\" { /* input: %s */\\n \", format_names[in]);\n         for (out=0; out<4; ++out)\n         {\n            unsigned int alpha;\n            printf(\" {\");\n            for (alpha=0; alpha<4; ++alpha)\n            {\n               printf(\" %d\", gpc_error_via_linear[in][out][alpha]);\n               if (alpha < 3) putchar(',');\n            }\n            printf(\" }\");\n            if (out < 3)\n               putchar(',');\n         }\n         printf(\"\\n }\");\n\n         if (in < 15)\n            putchar(',');\n         else\n            putchar('\\n');\n      }\n      printf(\"};\\n\");\n\n      printf(\"static png_uint_16 gpc_error_to_colormap[8/*i*/][8/*o*/][4] =\\n\");\n      printf(\"{\\n\");\n      for (in=0; in<8; ++in)\n      {\n         unsigned int out;\n         printf(\" { /* input: %s */\\n \", format_names[in]);\n         for (out=0; out<8; ++out)\n         {\n            unsigned int alpha;\n            printf(\" {\");\n            for (alpha=0; alpha<4; ++alpha)\n            {\n               printf(\" %d\", gpc_error_to_colormap[in][out][alpha]);\n               if (alpha < 3) putchar(',');\n            }\n            printf(\" }\");\n            if (out < 7)\n            {\n               putchar(',');\n               if (out % 4 == 3) printf(\"\\n \");\n            }\n         }\n         printf(\"\\n }\");\n\n         if (in < 7)\n            putchar(',');\n         else\n            putchar('\\n');\n      }\n      printf(\"};\\n\");\n      printf(\"/* END MACHINE GENERATED */\\n\");\n   }\n\n   if (retval == 0 && touch != NULL)\n   {\n      FILE *fsuccess = fopen(touch, \"wt\");\n\n      if (fsuccess != NULL)\n      {\n         int error = 0;\n         fprintf(fsuccess, \"PNG simple API tests succeeded\\n\");\n         fflush(fsuccess);\n         error = ferror(fsuccess);\n\n         if (fclose(fsuccess) || error)\n         {\n            fflush(stdout);\n            fprintf(stderr, \"%s: write failed\\n\", touch);\n            exit(99);\n         }\n      }\n\n      else\n      {\n         fflush(stdout);\n         fprintf(stderr, \"%s: open failed\\n\", touch);\n         exit(99);\n      }\n   }\n\n   return retval;\n}\n\n#else /* !PNG_SIMPLIFIED_READ_SUPPORTED */\nint main(void)\n{\n   fprintf(stderr, \"pngstest: no read support in libpng, test skipped\\n\");\n   /* So the test is skipped: */\n   return SKIP;\n}\n#endif /* PNG_SIMPLIFIED_READ_SUPPORTED */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/pngunknown.c",
    "content": "\n/* pngunknown.c - test the read side unknown chunk handling\n *\n * Last changed in libpng 1.6.22 [May 26, 2016]\n * Copyright (c) 2015,2016 Glenn Randers-Pehrson\n * Written by John Cunningham Bowler\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * NOTES:\n *   This is a C program that is intended to be linked against libpng.  It\n *   allows the libpng unknown handling code to be tested by interpreting\n *   arguments to save or discard combinations of chunks.  The program is\n *   currently just a minimal validation for the built-in libpng facilities.\n */\n\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <setjmp.h>\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n/* 1.6.1 added support for the configure test harness, which uses 77 to indicate\n * a skipped test, in earlier versions we need to succeed on a skipped test, so:\n */\n#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)\n#  define SKIP 77\n#else\n#  define SKIP 0\n#endif\n\n\n/* Since this program tests the ability to change the unknown chunk handling\n * these must be defined:\n */\n#if defined(PNG_SET_UNKNOWN_CHUNKS_SUPPORTED) &&\\\n   defined(PNG_STDIO_SUPPORTED) &&\\\n   defined(PNG_READ_SUPPORTED)\n\n/* One of these must be defined to allow us to find out what happened.  It is\n * still useful to set unknown chunk handling without either of these in order\n * to cause *known* chunks to be discarded.  This can be a significant\n * efficiency gain, but it can't really be tested here.\n */\n#if defined(PNG_READ_USER_CHUNKS_SUPPORTED) ||\\\n   defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)\n\n#if PNG_LIBPNG_VER < 10500\n/* This deliberately lacks the PNG_CONST. */\ntypedef png_byte *png_const_bytep;\n\n/* This is copied from 1.5.1 png.h: */\n#define PNG_INTERLACE_ADAM7_PASSES 7\n#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)\n#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)\n#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)\n#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)\n#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\\\n   -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))\n#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\\\n   -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))\n#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \\\n   (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))\n#define PNG_COL_FROM_PASS_COL(xIn, pass) \\\n   (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))\n#define PNG_PASS_MASK(pass,off) ( \\\n   ((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \\\n   ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))\n#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \\\n   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)\n#define PNG_COL_IN_INTERLACE_PASS(x, pass) \\\n   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)\n\n/* These are needed too for the default build: */\n#define PNG_WRITE_16BIT_SUPPORTED\n#define PNG_READ_16BIT_SUPPORTED\n\n/* This comes from pnglibconf.h afer 1.5: */\n#define PNG_FP_1 100000\n#define PNG_GAMMA_THRESHOLD_FIXED\\\n   ((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))\n#endif\n\n#if PNG_LIBPNG_VER < 10600\n   /* 1.6.0 constifies many APIs. The following exists to allow pngvalid to be\n    * compiled against earlier versions.\n    */\n#  define png_const_structp png_structp\n#endif\n\n#if PNG_LIBPNG_VER < 10700\n   /* Copied from libpng 1.7.0 png.h */\n#define PNG_u2(b1, b2) (((unsigned int)(b1) << 8) + (b2))\n\n#define PNG_U16(b1, b2) ((png_uint_16)PNG_u2(b1, b2))\n#define PNG_U32(b1, b2, b3, b4)\\\n   (((png_uint_32)PNG_u2(b1, b2) << 16) + PNG_u2(b3, b4))\n\n/* Constants for known chunk types.\n */\n#define png_IDAT PNG_U32( 73,  68,  65,  84)\n#define png_IEND PNG_U32( 73,  69,  78,  68)\n#define png_IHDR PNG_U32( 73,  72,  68,  82)\n#define png_PLTE PNG_U32( 80,  76,  84,  69)\n#define png_bKGD PNG_U32( 98,  75,  71,  68)\n#define png_cHRM PNG_U32( 99,  72,  82,  77)\n#define png_fRAc PNG_U32(102,  82,  65,  99) /* registered, not defined */\n#define png_gAMA PNG_U32(103,  65,  77,  65)\n#define png_gIFg PNG_U32(103,  73,  70, 103)\n#define png_gIFt PNG_U32(103,  73,  70, 116) /* deprecated */\n#define png_gIFx PNG_U32(103,  73,  70, 120)\n#define png_hIST PNG_U32(104,  73,  83,  84)\n#define png_iCCP PNG_U32(105,  67,  67,  80)\n#define png_iTXt PNG_U32(105,  84,  88, 116)\n#define png_oFFs PNG_U32(111,  70,  70, 115)\n#define png_pCAL PNG_U32(112,  67,  65,  76)\n#define png_pHYs PNG_U32(112,  72,  89, 115)\n#define png_sBIT PNG_U32(115,  66,  73,  84)\n#define png_sCAL PNG_U32(115,  67,  65,  76)\n#define png_sPLT PNG_U32(115,  80,  76,  84)\n#define png_sRGB PNG_U32(115,  82,  71,  66)\n#define png_sTER PNG_U32(115,  84,  69,  82)\n#define png_tEXt PNG_U32(116,  69,  88, 116)\n#define png_tIME PNG_U32(116,  73,  77,  69)\n#define png_tRNS PNG_U32(116,  82,  78,  83)\n#define png_zTXt PNG_U32(122,  84,  88, 116)\n\n/* Test on flag values as defined in the spec (section 5.4): */\n#define PNG_CHUNK_ANCILLARY(c)    (1 & ((c) >> 29))\n#define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLARY(c))\n#define PNG_CHUNK_PRIVATE(c)      (1 & ((c) >> 21))\n#define PNG_CHUNK_RESERVED(c)     (1 & ((c) >> 13))\n#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >>  5))\n\n#endif /* PNG_LIBPNG_VER < 10700 */\n\n#ifdef __cplusplus\n#  define this not_the_cpp_this\n#  define new not_the_cpp_new\n#  define voidcast(type, value) static_cast<type>(value)\n#else\n#  define voidcast(type, value) (value)\n#endif /* __cplusplus */\n\n/* Unused formal parameter errors are removed using the following macro which is\n * expected to have no bad effects on performance.\n */\n#ifndef UNUSED\n#  if defined(__GNUC__) || defined(_MSC_VER)\n#     define UNUSED(param) (void)param;\n#  else\n#     define UNUSED(param)\n#  endif\n#endif\n\n/* Types of chunks not known to libpng */\n#define png_vpAg PNG_U32(118, 112, 65, 103)\n\n/* Chunk information */\n#define PNG_INFO_tEXt 0x10000000U\n#define PNG_INFO_iTXt 0x20000000U\n#define PNG_INFO_zTXt 0x40000000U\n\n#define PNG_INFO_sTER 0x01000000U\n#define PNG_INFO_vpAg 0x02000000U\n\n#define ABSENT  0\n#define START   1\n#define END     2\n\nstatic struct\n{\n   char        name[5];\n   png_uint_32 flag;\n   png_uint_32 tag;\n   int         unknown;    /* Chunk not known to libpng */\n   int         all;        /* Chunk set by the '-1' option */\n   int         position;   /* position in pngtest.png */\n   int         keep;       /* unknown handling setting */\n} chunk_info[] = {\n   /* Critical chunks */\n   { \"IDAT\", PNG_INFO_IDAT, png_IDAT, 0, 0,  START, 0 }, /* must be [0] */\n   { \"PLTE\", PNG_INFO_PLTE, png_PLTE, 0, 0, ABSENT, 0 },\n\n   /* Non-critical chunks that libpng handles */\n   /* This is a mess but it seems to be the only way to do it - there is no way\n    * to check for a definition outside a #if.\n    */\n   { \"bKGD\", PNG_INFO_bKGD, png_bKGD,\n#     ifdef PNG_READ_bKGD_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"cHRM\", PNG_INFO_cHRM, png_cHRM,\n#     ifdef PNG_READ_cHRM_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"gAMA\", PNG_INFO_gAMA, png_gAMA,\n#     ifdef PNG_READ_gAMA_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"hIST\", PNG_INFO_hIST, png_hIST,\n#     ifdef PNG_READ_hIST_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1, ABSENT, 0 },\n   { \"iCCP\", PNG_INFO_iCCP, png_iCCP,\n#     ifdef PNG_READ_iCCP_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1, ABSENT, 0 },\n   { \"iTXt\", PNG_INFO_iTXt, png_iTXt,\n#     ifdef PNG_READ_iTXt_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1, ABSENT, 0 },\n   { \"oFFs\", PNG_INFO_oFFs, png_oFFs,\n#     ifdef PNG_READ_oFFs_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"pCAL\", PNG_INFO_pCAL, png_pCAL,\n#     ifdef PNG_READ_pCAL_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"pHYs\", PNG_INFO_pHYs, png_pHYs,\n#     ifdef PNG_READ_pHYs_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"sBIT\", PNG_INFO_sBIT, png_sBIT,\n#     ifdef PNG_READ_sBIT_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"sCAL\", PNG_INFO_sCAL, png_sCAL,\n#     ifdef PNG_READ_sCAL_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"sPLT\", PNG_INFO_sPLT, png_sPLT,\n#     ifdef PNG_READ_sPLT_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1, ABSENT, 0 },\n   { \"sRGB\", PNG_INFO_sRGB, png_sRGB,\n#     ifdef PNG_READ_sRGB_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"tEXt\", PNG_INFO_tEXt, png_tEXt,\n#     ifdef PNG_READ_tEXt_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"tIME\", PNG_INFO_tIME, png_tIME,\n#     ifdef PNG_READ_tIME_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,  START, 0 },\n   { \"tRNS\", PNG_INFO_tRNS, png_tRNS,\n#     ifdef PNG_READ_tRNS_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      0, ABSENT, 0 },\n   { \"zTXt\", PNG_INFO_zTXt, png_zTXt,\n#     ifdef PNG_READ_zTXt_SUPPORTED\n         0,\n#     else\n         1,\n#     endif\n      1,    END, 0 },\n\n   /* No libpng handling */\n   { \"sTER\", PNG_INFO_sTER, png_sTER, 1, 1,  START, 0 },\n   { \"vpAg\", PNG_INFO_vpAg, png_vpAg, 1, 0,  START, 0 },\n};\n\n#define NINFO ((int)((sizeof chunk_info)/(sizeof chunk_info[0])))\n\nstatic void\nclear_keep(void)\n{\n   int i = NINFO;\n   while (--i >= 0)\n      chunk_info[i].keep = 0;\n}\n\nstatic int\nfind(const char *name)\n{\n   int i = NINFO;\n   while (--i >= 0)\n   {\n      if (memcmp(chunk_info[i].name, name, 4) == 0)\n         break;\n   }\n\n   return i;\n}\n\nstatic int\nfindb(const png_byte *name)\n{\n   int i = NINFO;\n   while (--i >= 0)\n   {\n      if (memcmp(chunk_info[i].name, name, 4) == 0)\n         break;\n   }\n\n   return i;\n}\n\nstatic int\nfind_by_flag(png_uint_32 flag)\n{\n   int i = NINFO;\n\n   while (--i >= 0) if (chunk_info[i].flag == flag) return i;\n\n   fprintf(stderr, \"pngunknown: internal error\\n\");\n   exit(4);\n}\n\nstatic int\nancillary(const char *name)\n{\n   return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));\n}\n\n#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\nstatic int\nancillaryb(const png_byte *name)\n{\n   return PNG_CHUNK_ANCILLARY(PNG_U32(name[0], name[1], name[2], name[3]));\n}\n#endif\n\n/* Type of an error_ptr */\ntypedef struct\n{\n   jmp_buf     error_return;\n   png_structp png_ptr;\n   png_infop   info_ptr, end_ptr;\n   png_uint_32 before_IDAT;\n   png_uint_32 after_IDAT;\n   int         error_count;\n   int         warning_count;\n   int         keep; /* the default value */\n   const char *program;\n   const char *file;\n   const char *test;\n} display;\n\nstatic const char init[] = \"initialization\";\nstatic const char cmd[] = \"command line\";\n\nstatic void\ninit_display(display *d, const char *program)\n{\n   memset(d, 0, sizeof *d);\n   d->png_ptr = NULL;\n   d->info_ptr = d->end_ptr = NULL;\n   d->error_count = d->warning_count = 0;\n   d->program = program;\n   d->file = program;\n   d->test = init;\n}\n\nstatic void\nclean_display(display *d)\n{\n   png_destroy_read_struct(&d->png_ptr, &d->info_ptr, &d->end_ptr);\n\n   /* This must not happen - it might cause an app crash */\n   if (d->png_ptr != NULL || d->info_ptr != NULL || d->end_ptr != NULL)\n   {\n      fprintf(stderr, \"%s(%s): png_destroy_read_struct error\\n\", d->file,\n         d->test);\n      exit(1);\n   }\n}\n\nPNG_FUNCTION(void, display_exit, (display *d), static PNG_NORETURN)\n{\n   ++(d->error_count);\n\n   if (d->png_ptr != NULL)\n      clean_display(d);\n\n   /* During initialization and if this is a single command line argument set\n    * exit now - there is only one test, otherwise longjmp to do the next test.\n    */\n   if (d->test == init || d->test == cmd)\n      exit(1);\n\n   longjmp(d->error_return, 1);\n}\n\nstatic int\ndisplay_rc(const display *d, int strict)\n{\n   return d->error_count + (strict ? d->warning_count : 0);\n}\n\n/* libpng error and warning callbacks */\nPNG_FUNCTION(void, (PNGCBAPI error), (png_structp png_ptr, const char *message),\n   static PNG_NORETURN)\n{\n   display *d = (display*)png_get_error_ptr(png_ptr);\n\n   fprintf(stderr, \"%s(%s): libpng error: %s\\n\", d->file, d->test, message);\n   display_exit(d);\n}\n\nstatic void PNGCBAPI\nwarning(png_structp png_ptr, const char *message)\n{\n   display *d = (display*)png_get_error_ptr(png_ptr);\n\n   fprintf(stderr, \"%s(%s): libpng warning: %s\\n\", d->file, d->test, message);\n   ++(d->warning_count);\n}\n\nstatic png_uint_32\nget_valid(display *d, png_infop info_ptr)\n{\n   png_uint_32 flags = png_get_valid(d->png_ptr, info_ptr, (png_uint_32)~0);\n\n   /* Map the text chunks back into the flags */\n   {\n      png_textp text;\n      png_uint_32 ntext = png_get_text(d->png_ptr, info_ptr, &text, NULL);\n\n      while (ntext-- > 0) switch (text[ntext].compression)\n      {\n         case -1:\n            flags |= PNG_INFO_tEXt;\n            break;\n         case 0:\n            flags |= PNG_INFO_zTXt;\n            break;\n         case 1:\n         case 2:\n            flags |= PNG_INFO_iTXt;\n            break;\n         default:\n            fprintf(stderr, \"%s(%s): unknown text compression %d\\n\", d->file,\n               d->test, text[ntext].compression);\n            display_exit(d);\n      }\n   }\n\n   return flags;\n}\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\nstatic int PNGCBAPI\nread_callback(png_structp pp, png_unknown_chunkp pc)\n{\n   /* This function mimics the behavior of png_set_keep_unknown_chunks by\n    * returning '0' to keep the chunk and '1' to discard it.\n    */\n   display *d = voidcast(display*, png_get_user_chunk_ptr(pp));\n   int chunk = findb(pc->name);\n   int keep, discard;\n\n   if (chunk < 0) /* not one in our list, so not a known chunk */\n      keep = d->keep;\n\n   else\n   {\n      keep = chunk_info[chunk].keep;\n      if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)\n      {\n         /* See the comments in png.h - use the default for unknown chunks,\n          * do not keep known chunks.\n          */\n         if (chunk_info[chunk].unknown)\n            keep = d->keep;\n\n         else\n            keep = PNG_HANDLE_CHUNK_NEVER;\n      }\n   }\n\n   switch (keep)\n   {\n      default:\n         fprintf(stderr, \"%s(%s): %d: unrecognized chunk option\\n\", d->file,\n            d->test, chunk_info[chunk].keep);\n         display_exit(d);\n\n      case PNG_HANDLE_CHUNK_AS_DEFAULT:\n      case PNG_HANDLE_CHUNK_NEVER:\n         discard = 1/*handled; discard*/;\n         break;\n\n      case PNG_HANDLE_CHUNK_IF_SAFE:\n      case PNG_HANDLE_CHUNK_ALWAYS:\n         discard = 0/*not handled; keep*/;\n         break;\n   }\n\n   /* Also store information about this chunk in the display, the relevant flag\n    * is set if the chunk is to be kept ('not handled'.)\n    */\n   if (chunk >= 0) if (!discard) /* stupidity to stop a GCC warning */\n   {\n      png_uint_32 flag = chunk_info[chunk].flag;\n\n      if (pc->location & PNG_AFTER_IDAT)\n         d->after_IDAT |= flag;\n\n      else\n         d->before_IDAT |= flag;\n   }\n\n   /* However if there is no support to store unknown chunks don't ask libpng to\n    * do it; there will be an png_error.\n    */\n#  ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n      return discard;\n#  else\n      return 1; /*handled; discard*/\n#  endif\n}\n#endif /* READ_USER_CHUNKS_SUPPORTED */\n\n#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\nstatic png_uint_32\nget_unknown(display *d, png_infop info_ptr, int after_IDAT)\n{\n   /* Create corresponding 'unknown' flags */\n   png_uint_32 flags = 0;\n\n   UNUSED(after_IDAT)\n\n   {\n      png_unknown_chunkp unknown;\n      int num_unknown = png_get_unknown_chunks(d->png_ptr, info_ptr, &unknown);\n\n      while (--num_unknown >= 0)\n      {\n         int chunk = findb(unknown[num_unknown].name);\n\n         /* Chunks not known to pngunknown must be validated here; since they\n          * must also be unknown to libpng the 'display->keep' behavior should\n          * have been used.\n          */\n         if (chunk < 0) switch (d->keep)\n         {\n            default: /* impossible */\n            case PNG_HANDLE_CHUNK_AS_DEFAULT:\n            case PNG_HANDLE_CHUNK_NEVER:\n               fprintf(stderr, \"%s(%s): %s: %s: unknown chunk saved\\n\",\n                  d->file, d->test, d->keep ? \"discard\" : \"default\",\n                  unknown[num_unknown].name);\n               ++(d->error_count);\n               break;\n\n            case PNG_HANDLE_CHUNK_IF_SAFE:\n               if (!ancillaryb(unknown[num_unknown].name))\n               {\n                  fprintf(stderr,\n                     \"%s(%s): if-safe: %s: unknown critical chunk saved\\n\",\n                     d->file, d->test, unknown[num_unknown].name);\n                  ++(d->error_count);\n                  break;\n               }\n               /* FALL THROUGH (safe) */\n            case PNG_HANDLE_CHUNK_ALWAYS:\n               break;\n         }\n\n         else\n            flags |= chunk_info[chunk].flag;\n      }\n   }\n\n   return flags;\n}\n#else /* SAVE_UNKNOWN_CHUNKS */\nstatic png_uint_32\nget_unknown(display *d, png_infop info_ptr, int after_IDAT)\n   /* Otherwise this will return the cached values set by any user callback */\n{\n   UNUSED(info_ptr);\n\n   if (after_IDAT)\n      return d->after_IDAT;\n\n   else\n      return d->before_IDAT;\n}\n\n#  ifndef PNG_READ_USER_CHUNKS_SUPPORTED\n      /* The #defines above should mean this is never reached, it's just here as\n       * a check to ensure the logic is correct.\n       */\n#     error No store support and no user chunk support, this will not work\n#  endif /* READ_USER_CHUNKS */\n#endif /* SAVE_UNKNOWN_CHUNKS */\n\nstatic int\ncheck(FILE *fp, int argc, const char **argv, png_uint_32p flags/*out*/,\n   display *d, int set_callback)\n{\n   int i, npasses, ipass;\n   png_uint_32 height;\n\n   d->keep = PNG_HANDLE_CHUNK_AS_DEFAULT;\n   d->before_IDAT = 0;\n   d->after_IDAT = 0;\n\n   /* Some of these errors are permanently fatal and cause an exit here, others\n    * are per-test and cause an error return.\n    */\n   d->png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, d, error,\n      warning);\n   if (d->png_ptr == NULL)\n   {\n      fprintf(stderr, \"%s(%s): could not allocate png struct\\n\", d->file,\n         d->test);\n      /* Terminate here, this error is not test specific. */\n      exit(1);\n   }\n\n   d->info_ptr = png_create_info_struct(d->png_ptr);\n   d->end_ptr = png_create_info_struct(d->png_ptr);\n   if (d->info_ptr == NULL || d->end_ptr == NULL)\n   {\n      fprintf(stderr, \"%s(%s): could not allocate png info\\n\", d->file,\n         d->test);\n      clean_display(d);\n      exit(1);\n   }\n\n   png_init_io(d->png_ptr, fp);\n\n#  ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n      /* This is only done if requested by the caller; it interferes with the\n       * standard store/save mechanism.\n       */\n      if (set_callback)\n         png_set_read_user_chunk_fn(d->png_ptr, d, read_callback);\n#  else\n      UNUSED(set_callback)\n#  endif\n\n   /* Handle each argument in turn; multiple settings are possible for the same\n    * chunk and multiple calls will occur (the last one should override all\n    * preceding ones).\n    */\n   for (i=0; i<argc; ++i)\n   {\n      const char *equals = strchr(argv[i], '=');\n\n      if (equals != NULL)\n      {\n         int chunk, option;\n\n         if (strcmp(equals+1, \"default\") == 0)\n            option = PNG_HANDLE_CHUNK_AS_DEFAULT;\n         else if (strcmp(equals+1, \"discard\") == 0)\n            option = PNG_HANDLE_CHUNK_NEVER;\n         else if (strcmp(equals+1, \"if-safe\") == 0)\n            option = PNG_HANDLE_CHUNK_IF_SAFE;\n         else if (strcmp(equals+1, \"save\") == 0)\n            option = PNG_HANDLE_CHUNK_ALWAYS;\n         else\n         {\n            fprintf(stderr, \"%s(%s): %s: unrecognized chunk option\\n\", d->file,\n               d->test, argv[i]);\n            display_exit(d);\n         }\n\n         switch (equals - argv[i])\n         {\n            case 4: /* chunk name */\n               chunk = find(argv[i]);\n\n               if (chunk >= 0)\n               {\n                  /* These #if tests have the effect of skipping the arguments\n                   * if SAVE support is unavailable - we can't do a useful test\n                   * in this case, so we just check the arguments!  This could\n                   * be improved in the future by using the read callback.\n                   */\n#                 if PNG_LIBPNG_VER >= 10700 &&\\\n                     !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)\n                     if (option < PNG_HANDLE_CHUNK_IF_SAFE)\n#                 endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */\n                  {\n                     png_byte name[5];\n\n                     memcpy(name, chunk_info[chunk].name, 5);\n                     png_set_keep_unknown_chunks(d->png_ptr, option, name, 1);\n                     chunk_info[chunk].keep = option;\n                  }\n                  continue;\n               }\n\n               break;\n\n            case 7: /* default */\n               if (memcmp(argv[i], \"default\", 7) == 0)\n               {\n#                 if PNG_LIBPNG_VER >= 10700 &&\\\n                     !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)\n                     if (option < PNG_HANDLE_CHUNK_IF_SAFE)\n#                 endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */\n                     png_set_keep_unknown_chunks(d->png_ptr, option, NULL, 0);\n\n                  d->keep = option;\n                  continue;\n               }\n\n               break;\n\n            case 3: /* all */\n               if (memcmp(argv[i], \"all\", 3) == 0)\n               {\n#                 if PNG_LIBPNG_VER >= 10700 &&\\\n                     !defined(PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED)\n                     if (option < PNG_HANDLE_CHUNK_IF_SAFE)\n#                 endif /* 1.7+ SAVE_UNKNOWN_CHUNKS */\n                     png_set_keep_unknown_chunks(d->png_ptr, option, NULL, -1);\n\n                  d->keep = option;\n\n                  for (chunk = 0; chunk < NINFO; ++chunk)\n                     if (chunk_info[chunk].all)\n                        chunk_info[chunk].keep = option;\n                  continue;\n               }\n\n               break;\n\n            default: /* some misplaced = */\n\n               break;\n         }\n      }\n\n      fprintf(stderr, \"%s(%s): %s: unrecognized chunk argument\\n\", d->file,\n         d->test, argv[i]);\n      display_exit(d);\n   }\n\n   png_read_info(d->png_ptr, d->info_ptr);\n\n   switch (png_get_interlace_type(d->png_ptr, d->info_ptr))\n   {\n      case PNG_INTERLACE_NONE:\n         npasses = 1;\n         break;\n\n      case PNG_INTERLACE_ADAM7:\n         npasses = PNG_INTERLACE_ADAM7_PASSES;\n         break;\n\n      default:\n         /* Hard error because it is not test specific */\n         fprintf(stderr, \"%s(%s): invalid interlace type\\n\", d->file, d->test);\n         clean_display(d);\n         exit(1);\n   }\n\n   /* Skip the image data, if IDAT is not being handled then don't do this\n    * because it will cause a CRC error.\n    */\n   if (chunk_info[0/*IDAT*/].keep == PNG_HANDLE_CHUNK_AS_DEFAULT)\n   {\n      png_start_read_image(d->png_ptr);\n      height = png_get_image_height(d->png_ptr, d->info_ptr);\n\n      if (npasses > 1)\n      {\n         png_uint_32 width = png_get_image_width(d->png_ptr, d->info_ptr);\n\n         for (ipass=0; ipass<npasses; ++ipass)\n         {\n            png_uint_32 wPass = PNG_PASS_COLS(width, ipass);\n\n            if (wPass > 0)\n            {\n               png_uint_32 y;\n\n               for (y=0; y<height; ++y) if (PNG_ROW_IN_INTERLACE_PASS(y, ipass))\n                  png_read_row(d->png_ptr, NULL, NULL);\n            }\n         }\n      } /* interlaced */\n\n      else /* not interlaced */\n      {\n         png_uint_32 y;\n\n         for (y=0; y<height; ++y)\n            png_read_row(d->png_ptr, NULL, NULL);\n      }\n   }\n\n   png_read_end(d->png_ptr, d->end_ptr);\n\n   flags[0] = get_valid(d, d->info_ptr);\n   flags[1] = get_unknown(d, d->info_ptr, 0/*before IDAT*/);\n\n   /* Only png_read_png sets PNG_INFO_IDAT! */\n   flags[chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT] |=\n      PNG_INFO_IDAT;\n\n   flags[2] = get_valid(d, d->end_ptr);\n   flags[3] = get_unknown(d, d->end_ptr, 1/*after IDAT*/);\n\n   clean_display(d);\n\n   return d->keep;\n}\n\nstatic void\ncheck_error(display *d, png_uint_32 flags, const char *message)\n{\n   while (flags)\n   {\n      png_uint_32 flag = flags & -(png_int_32)flags;\n      int i = find_by_flag(flag);\n\n      fprintf(stderr, \"%s(%s): chunk %s: %s\\n\", d->file, d->test,\n         chunk_info[i].name, message);\n      ++(d->error_count);\n\n      flags &= ~flag;\n   }\n}\n\nstatic void\ncheck_handling(display *d, int def, png_uint_32 chunks, png_uint_32 known,\n   png_uint_32 unknown, const char *position, int set_callback)\n{\n   while (chunks)\n   {\n      png_uint_32 flag = chunks & -(png_int_32)chunks;\n      int i = find_by_flag(flag);\n      int keep = chunk_info[i].keep;\n      const char *type;\n      const char *errorx = NULL;\n\n      if (chunk_info[i].unknown)\n      {\n         if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)\n         {\n            type = \"UNKNOWN (default)\";\n            keep = def;\n         }\n\n         else\n            type = \"UNKNOWN (specified)\";\n\n         if (flag & known)\n            errorx = \"chunk processed\";\n\n         else switch (keep)\n         {\n            case PNG_HANDLE_CHUNK_AS_DEFAULT:\n               if (flag & unknown)\n                  errorx = \"DEFAULT: unknown chunk saved\";\n               break;\n\n            case PNG_HANDLE_CHUNK_NEVER:\n               if (flag & unknown)\n                  errorx = \"DISCARD: unknown chunk saved\";\n               break;\n\n            case PNG_HANDLE_CHUNK_IF_SAFE:\n               if (ancillary(chunk_info[i].name))\n               {\n                  if (!(flag & unknown))\n                     errorx = \"IF-SAFE: unknown ancillary chunk lost\";\n               }\n\n               else if (flag & unknown)\n                  errorx = \"IF-SAFE: unknown critical chunk saved\";\n               break;\n\n            case PNG_HANDLE_CHUNK_ALWAYS:\n               if (!(flag & unknown))\n                  errorx = \"SAVE: unknown chunk lost\";\n               break;\n\n            default:\n               errorx = \"internal error: bad keep\";\n               break;\n         }\n      } /* unknown chunk */\n\n      else /* known chunk */\n      {\n         type = \"KNOWN\";\n\n         if (flag & known)\n         {\n            /* chunk was processed, it won't have been saved because that is\n             * caught below when checking for inconsistent processing.\n             */\n            if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)\n               errorx = \"!DEFAULT: known chunk processed\";\n         }\n\n         else /* not processed */ switch (keep)\n         {\n            case PNG_HANDLE_CHUNK_AS_DEFAULT:\n               errorx = \"DEFAULT: known chunk not processed\";\n               break;\n\n            case PNG_HANDLE_CHUNK_NEVER:\n               if (flag & unknown)\n                  errorx = \"DISCARD: known chunk saved\";\n               break;\n\n            case PNG_HANDLE_CHUNK_IF_SAFE:\n               if (ancillary(chunk_info[i].name))\n               {\n                  if (!(flag & unknown))\n                     errorx = \"IF-SAFE: known ancillary chunk lost\";\n               }\n\n               else if (flag & unknown)\n                  errorx = \"IF-SAFE: known critical chunk saved\";\n               break;\n\n            case PNG_HANDLE_CHUNK_ALWAYS:\n               if (!(flag & unknown))\n                  errorx = \"SAVE: known chunk lost\";\n               break;\n\n            default:\n               errorx = \"internal error: bad keep (2)\";\n               break;\n         }\n      }\n\n      if (errorx != NULL)\n      {\n         ++(d->error_count);\n         fprintf(stderr, \"%s(%s%s): %s %s %s: %s\\n\", d->file, d->test,\n            set_callback ? \",callback\" : \"\",\n            type, chunk_info[i].name, position, errorx);\n      }\n\n      chunks &= ~flag;\n   }\n}\n\nstatic void\nperform_one_test(FILE *fp, int argc, const char **argv,\n   png_uint_32 *default_flags, display *d, int set_callback)\n{\n   int def;\n   png_uint_32 flags[2][4];\n\n   rewind(fp);\n   clear_keep();\n   memcpy(flags[0], default_flags, sizeof flags[0]);\n\n   def = check(fp, argc, argv, flags[1], d, set_callback);\n\n   /* If IDAT is being handled as unknown the image read is skipped and all the\n    * IDATs after the first end up in the end info struct, so in this case add\n    * IDAT to the list of unknowns.  (Do this after 'check' above sets the\n    * chunk_info 'keep' fields.)\n    *\n    * Note that the flag setting has to be in the 'known' field to avoid\n    * triggering the consistency check below and the flag must only be set if\n    * there are multiple IDATs, so if the check above did find an unknown IDAT\n    * after IDAT.\n    */\n   if (chunk_info[0/*IDAT*/].keep != PNG_HANDLE_CHUNK_AS_DEFAULT &&\n       (flags[1][3] & PNG_INFO_IDAT) != 0)\n      flags[0][2] |= PNG_INFO_IDAT;\n\n   /* Chunks should either be known or unknown, never both and this should apply\n    * whether the chunk is before or after the IDAT (actually, the app can\n    * probably change this by swapping the handling after the image, but this\n    * test does not do that.)\n    */\n   check_error(d, (flags[0][0]|flags[0][2]) & (flags[0][1]|flags[0][3]),\n      \"chunk handled inconsistently in count tests\");\n   check_error(d, (flags[1][0]|flags[1][2]) & (flags[1][1]|flags[1][3]),\n      \"chunk handled inconsistently in option tests\");\n\n   /* Now find out what happened to each chunk before and after the IDAT and\n    * determine if the behavior was correct.  First some basic sanity checks,\n    * any known chunk should be known in the original count, any unknown chunk\n    * should be either known or unknown in the original.\n    */\n   {\n      png_uint_32 test;\n\n      test = flags[1][0] & ~flags[0][0];\n      check_error(d, test, \"new known chunk before IDAT\");\n      test = flags[1][1] & ~(flags[0][0] | flags[0][1]);\n      check_error(d, test, \"new unknown chunk before IDAT\");\n      test = flags[1][2] & ~flags[0][2];\n      check_error(d, test, \"new known chunk after IDAT\");\n      test = flags[1][3] & ~(flags[0][2] | flags[0][3]);\n      check_error(d, test, \"new unknown chunk after IDAT\");\n   }\n\n   /* Now each chunk in the original list should have been handled according to\n    * the options set for that chunk, regardless of whether libpng knows about\n    * it or not.\n    */\n   check_handling(d, def, flags[0][0] | flags[0][1], flags[1][0], flags[1][1],\n      \"before IDAT\", set_callback);\n   check_handling(d, def, flags[0][2] | flags[0][3], flags[1][2], flags[1][3],\n      \"after IDAT\", set_callback);\n}\n\nstatic void\nperform_one_test_safe(FILE *fp, int argc, const char **argv,\n   png_uint_32 *default_flags, display *d, const char *test)\n{\n   if (setjmp(d->error_return) == 0)\n   {\n      d->test = test; /* allow use of d->error_return */\n#     ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n         perform_one_test(fp, argc, argv, default_flags, d, 0);\n#     endif\n#     ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n         perform_one_test(fp, argc, argv, default_flags, d, 1);\n#     endif\n      d->test = init; /* prevent use of d->error_return */\n   }\n}\n\nstatic const char *standard_tests[] =\n{\n \"discard\", \"default=discard\", 0,\n \"save\", \"default=save\", 0,\n \"if-safe\", \"default=if-safe\", 0,\n \"vpAg\", \"vpAg=if-safe\", 0,\n \"sTER\", \"sTER=if-safe\", 0,\n \"IDAT\", \"default=discard\", \"IDAT=save\", 0,\n \"sAPI\", \"bKGD=save\", \"cHRM=save\", \"gAMA=save\", \"all=discard\", \"iCCP=save\",\n   \"sBIT=save\", \"sRGB=save\", 0,\n 0/*end*/\n};\n\nstatic PNG_NORETURN void\nusage(const char *program, const char *reason)\n{\n   fprintf(stderr, \"pngunknown: %s: usage:\\n %s [--strict] \"\n      \"--default|{(CHNK|default|all)=(default|discard|if-safe|save)} \"\n      \"testfile.png\\n\", reason, program);\n   exit(99);\n}\n\nint\nmain(int argc, const char **argv)\n{\n   FILE *fp;\n   png_uint_32 default_flags[4/*valid,unknown{before,after}*/];\n   int strict = 0, default_tests = 0;\n   const char *count_argv = \"default=save\";\n   const char *touch_file = NULL;\n   display d;\n\n   init_display(&d, argv[0]);\n\n   while (++argv, --argc > 0)\n   {\n      if (strcmp(*argv, \"--strict\") == 0)\n         strict = 1;\n\n      else if (strcmp(*argv, \"--default\") == 0)\n         default_tests = 1;\n\n      else if (strcmp(*argv, \"--touch\") == 0)\n      {\n         if (argc > 1)\n            touch_file = *++argv, --argc;\n\n         else\n            usage(d.program, \"--touch: missing file name\");\n      }\n\n      else\n         break;\n   }\n\n   /* A file name is required, but there should be no other arguments if\n    * --default was specified.\n    */\n   if (argc <= 0)\n      usage(d.program, \"missing test file\");\n\n   /* GCC BUG: if (default_tests && argc != 1) triggers some weird GCC argc\n    * optimization which causes warnings with -Wstrict-overflow!\n    */\n   else if (default_tests) if (argc != 1)\n      usage(d.program, \"extra arguments\");\n\n   /* The name of the test file is the last argument; remove it. */\n   d.file = argv[--argc];\n\n   fp = fopen(d.file, \"rb\");\n   if (fp == NULL)\n   {\n      perror(d.file);\n      exit(99);\n   }\n\n   /* First find all the chunks, known and unknown, in the test file, a failure\n    * here aborts the whole test.\n    *\n    * If 'save' is supported then the normal saving method should happen,\n    * otherwise if 'read' is supported then the read callback will do the\n    * same thing.  If both are supported the 'read' callback won't be\n    * instantiated by default.  If 'save' is *not* supported then a user\n    * callback is required even though we can call png_get_unknown_chunks.\n    */\n   if (check(fp, 1, &count_argv, default_flags, &d,\n#     ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n         0\n#     else\n         1\n#     endif\n      ) != PNG_HANDLE_CHUNK_ALWAYS)\n   {\n      fprintf(stderr, \"%s: %s: internal error\\n\", d.program, d.file);\n      exit(99);\n   }\n\n   /* Now find what the various supplied options cause to change: */\n   if (!default_tests)\n   {\n      d.test = cmd; /* acts as a flag to say exit, do not longjmp */\n#     ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n         perform_one_test(fp, argc, argv, default_flags, &d, 0);\n#     endif\n#     ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n         perform_one_test(fp, argc, argv, default_flags, &d, 1);\n#     endif\n      d.test = init;\n   }\n\n   else\n   {\n      const char **test = standard_tests;\n\n      /* Set the exit_test pointer here so we can continue after a libpng error.\n       * NOTE: this leaks memory because the png_struct data from the failing\n       * test is never freed.\n       */\n      while (*test)\n      {\n         const char *this_test = *test++;\n         const char **next = test;\n         int count = display_rc(&d, strict), new_count;\n         const char *result;\n         int arg_count = 0;\n\n         while (*next) ++next, ++arg_count;\n\n         perform_one_test_safe(fp, arg_count, test, default_flags, &d,\n            this_test);\n\n         new_count = display_rc(&d, strict);\n\n         if (new_count == count)\n            result = \"PASS\";\n\n         else\n            result = \"FAIL\";\n\n         printf(\"%s: %s %s\\n\", result, d.program, this_test);\n\n         test = next+1;\n      }\n   }\n\n   fclose(fp);\n\n   if (display_rc(&d, strict) == 0)\n   {\n      /* Success, touch the success file if appropriate */\n      if (touch_file != NULL)\n      {\n         FILE *fsuccess = fopen(touch_file, \"wt\");\n\n         if (fsuccess != NULL)\n         {\n            int err = 0;\n            fprintf(fsuccess, \"PNG unknown tests succeeded\\n\");\n            fflush(fsuccess);\n            err = ferror(fsuccess);\n\n            if (fclose(fsuccess) || err)\n            {\n               fprintf(stderr, \"%s: write failed\\n\", touch_file);\n               exit(99);\n            }\n         }\n\n         else\n         {\n            fprintf(stderr, \"%s: open failed\\n\", touch_file);\n            exit(99);\n         }\n      }\n\n      return 0;\n   }\n\n   return 1;\n}\n\n#else /* !(READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS) */\nint\nmain(void)\n{\n   fprintf(stderr,\n      \" test ignored: no support to find out about unknown chunks\\n\");\n   /* So the test is skipped: */\n   return SKIP;\n}\n#endif /* READ_USER_CHUNKS || SAVE_UNKNOWN_CHUNKS */\n\n#else /* !(SET_UNKNOWN_CHUNKS && READ) */\nint\nmain(void)\n{\n   fprintf(stderr,\n      \" test ignored: no support to modify unknown chunk handling\\n\");\n   /* So the test is skipped: */\n   return SKIP;\n}\n#endif /* SET_UNKNOWN_CHUNKS && READ*/\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/pngvalid.c",
    "content": "\n/* pngvalid.c - validate libpng by constructing then reading png files.\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 2014-2016 Glenn Randers-Pehrson\n * Written by John Cunningham Bowler\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * NOTES:\n *   This is a C program that is intended to be linked against libpng.  It\n *   generates bitmaps internally, stores them as PNG files (using the\n *   sequential write code) then reads them back (using the sequential\n *   read code) and validates that the result has the correct data.\n *\n *   The program can be modified and extended to test the correctness of\n *   transformations performed by libpng.\n */\n\n#define _POSIX_SOURCE 1\n#define _ISOC99_SOURCE 1 /* For floating point */\n#define _GNU_SOURCE 1 /* For the floating point exception extension */\n\n#include <signal.h>\n#include <stdio.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n#ifdef HAVE_FEENABLEEXCEPT /* from config.h, if included */\n#  include <fenv.h>\n#endif\n\n#ifndef FE_DIVBYZERO\n#  define FE_DIVBYZERO 0\n#endif\n#ifndef FE_INVALID\n#  define FE_INVALID 0\n#endif\n#ifndef FE_OVERFLOW\n#  define FE_OVERFLOW 0\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n#ifdef PNG_ZLIB_HEADER\n#  include PNG_ZLIB_HEADER\n#else\n#  include <zlib.h>   /* For crc32 */\n#endif\n\n/* 1.6.1 added support for the configure test harness, which uses 77 to indicate\n * a skipped test, in earlier versions we need to succeed on a skipped test, so:\n */\n#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)\n#  define SKIP 77\n#else\n#  define SKIP 0\n#endif\n\n/* pngvalid requires write support and one of the fixed or floating point APIs.\n */\n#if defined(PNG_WRITE_SUPPORTED) &&\\\n   (defined(PNG_FIXED_POINT_SUPPORTED) || defined(PNG_FLOATING_POINT_SUPPORTED))\n\n#if PNG_LIBPNG_VER < 10500\n/* This deliberately lacks the const. */\ntypedef png_byte *png_const_bytep;\n\n/* This is copied from 1.5.1 png.h: */\n#define PNG_INTERLACE_ADAM7_PASSES 7\n#define PNG_PASS_START_ROW(pass) (((1U&~(pass))<<(3-((pass)>>1)))&7)\n#define PNG_PASS_START_COL(pass) (((1U& (pass))<<(3-(((pass)+1)>>1)))&7)\n#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)\n#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)\n#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\\\n   -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))\n#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\\\n   -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))\n#define PNG_ROW_FROM_PASS_ROW(yIn, pass) \\\n   (((yIn)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))\n#define PNG_COL_FROM_PASS_COL(xIn, pass) \\\n   (((xIn)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))\n#define PNG_PASS_MASK(pass,off) ( \\\n   ((0x110145AFU>>(((7-(off))-(pass))<<2)) & 0xFU) | \\\n   ((0x01145AF0U>>(((7-(off))-(pass))<<2)) & 0xF0U))\n#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \\\n   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)\n#define PNG_COL_IN_INTERLACE_PASS(x, pass) \\\n   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)\n\n/* These are needed too for the default build: */\n#define PNG_WRITE_16BIT_SUPPORTED\n#define PNG_READ_16BIT_SUPPORTED\n\n/* This comes from pnglibconf.h afer 1.5: */\n#define PNG_FP_1 100000\n#define PNG_GAMMA_THRESHOLD_FIXED\\\n   ((png_fixed_point)(PNG_GAMMA_THRESHOLD * PNG_FP_1))\n#endif\n\n#if PNG_LIBPNG_VER < 10600\n   /* 1.6.0 constifies many APIs, the following exists to allow pngvalid to be\n    * compiled against earlier versions.\n    */\n#  define png_const_structp png_structp\n#endif\n\n#ifndef RELEASE_BUILD\n   /* RELEASE_BUILD is true for releases and release candidates: */\n#  define RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)\n#endif\n#if RELEASE_BUILD\n#   define debugonly(something)\n#else /* !RELEASE_BUILD */\n#   define debugonly(something) something\n#endif /* !RELEASE_BUILD */\n\n#include <float.h>  /* For floating point constants */\n#include <stdlib.h> /* For malloc */\n#include <string.h> /* For memcpy, memset */\n#include <math.h>   /* For floor */\n\n/* Convenience macros. */\n#define CHUNK(a,b,c,d) (((a)<<24)+((b)<<16)+((c)<<8)+(d))\n#define CHUNK_IHDR CHUNK(73,72,68,82)\n#define CHUNK_PLTE CHUNK(80,76,84,69)\n#define CHUNK_IDAT CHUNK(73,68,65,84)\n#define CHUNK_IEND CHUNK(73,69,78,68)\n#define CHUNK_cHRM CHUNK(99,72,82,77)\n#define CHUNK_gAMA CHUNK(103,65,77,65)\n#define CHUNK_sBIT CHUNK(115,66,73,84)\n#define CHUNK_sRGB CHUNK(115,82,71,66)\n\n/* Unused formal parameter errors are removed using the following macro which is\n * expected to have no bad effects on performance.\n */\n#ifndef UNUSED\n#  if defined(__GNUC__) || defined(_MSC_VER)\n#     define UNUSED(param) (void)param;\n#  else\n#     define UNUSED(param)\n#  endif\n#endif\n\n/***************************** EXCEPTION HANDLING *****************************/\n#ifdef PNG_FREESTANDING_TESTS\n#  include <cexcept.h>\n#else\n#  include \"../visupng/cexcept.h\"\n#endif\n\n#ifdef __cplusplus\n#  define this not_the_cpp_this\n#  define new not_the_cpp_new\n#  define voidcast(type, value) static_cast<type>(value)\n#else\n#  define voidcast(type, value) (value)\n#endif /* __cplusplus */\n\nstruct png_store;\ndefine_exception_type(struct png_store*);\n\n/* The following are macros to reduce typing everywhere where the well known\n * name 'the_exception_context' must be defined.\n */\n#define anon_context(ps) struct exception_context *the_exception_context = \\\n   &(ps)->exception_context\n#define context(ps,fault) anon_context(ps); png_store *fault\n\n/* This macro returns the number of elements in an array as an (unsigned int),\n * it is necessary to avoid the inability of certain versions of GCC to use\n * the value of a compile-time constant when performing range checks.  It must\n * be passed an array name.\n */\n#define ARRAY_SIZE(a) ((unsigned int)((sizeof (a))/(sizeof (a)[0])))\n\n/* GCC BUG 66447 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66447) requires\n * some broken GCC versions to be fixed up to avoid invalid whining about auto\n * variables that are *not* changed within the scope of a setjmp being changed.\n *\n * Feel free to extend the list of broken versions.\n */\n#define is_gnu(major,minor)\\\n   (defined __GNUC__) && __GNUC__ == (major) && __GNUC_MINOR__ == (minor)\n#define is_gnu_patch(major,minor,patch)\\\n   is_gnu(major,minor) && __GNUC_PATCHLEVEL__ == 0\n/* For the moment just do it always; all versions of GCC seem to be broken: */\n#ifdef __GNUC__\n   const void * volatile make_volatile_for_gnu;\n#  define gnu_volatile(x) make_volatile_for_gnu = &x;\n#else /* !GNUC broken versions */\n#  define gnu_volatile(x)\n#endif /* !GNUC broken versions */\n\n/******************************* UTILITIES ************************************/\n/* Error handling is particularly problematic in production code - error\n * handlers often themselves have bugs which lead to programs that detect\n * minor errors crashing.  The following functions deal with one very\n * common class of errors in error handlers - attempting to format error or\n * warning messages into buffers that are too small.\n */\nstatic size_t safecat(char *buffer, size_t bufsize, size_t pos,\n   const char *cat)\n{\n   while (pos < bufsize && cat != NULL && *cat != 0)\n      buffer[pos++] = *cat++;\n\n   if (pos >= bufsize)\n      pos = bufsize-1;\n\n   buffer[pos] = 0;\n   return pos;\n}\n\nstatic size_t safecatn(char *buffer, size_t bufsize, size_t pos, int n)\n{\n   char number[64];\n   sprintf(number, \"%d\", n);\n   return safecat(buffer, bufsize, pos, number);\n}\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nstatic size_t safecatd(char *buffer, size_t bufsize, size_t pos, double d,\n    int precision)\n{\n   char number[64];\n   sprintf(number, \"%.*f\", precision, d);\n   return safecat(buffer, bufsize, pos, number);\n}\n#endif\n\nstatic const char invalid[] = \"invalid\";\nstatic const char sep[] = \": \";\n\nstatic const char *colour_types[8] =\n{\n   \"grayscale\", invalid, \"truecolour\", \"indexed-colour\",\n   \"grayscale with alpha\", invalid, \"truecolour with alpha\", invalid\n};\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n/* Convert a double precision value to fixed point. */\nstatic png_fixed_point\nfix(double d)\n{\n   d = floor(d * PNG_FP_1 + .5);\n   return (png_fixed_point)d;\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* Generate random bytes.  This uses a boring repeatable algorithm and it\n * is implemented here so that it gives the same set of numbers on every\n * architecture.  It's a linear congruential generator (Knuth or Sedgewick\n * \"Algorithms\") but it comes from the 'feedback taps' table in Horowitz and\n * Hill, \"The Art of Electronics\" (Pseudo-Random Bit Sequences and Noise\n * Generation.)\n */\nstatic void\nmake_random_bytes(png_uint_32* seed, void* pv, size_t size)\n{\n   png_uint_32 u0 = seed[0], u1 = seed[1];\n   png_bytep bytes = voidcast(png_bytep, pv);\n\n   /* There are thirty three bits, the next bit in the sequence is bit-33 XOR\n    * bit-20.  The top 1 bit is in u1, the bottom 32 are in u0.\n    */\n   size_t i;\n   for (i=0; i<size; ++i)\n   {\n      /* First generate 8 new bits then shift them in at the end. */\n      png_uint_32 u = ((u0 >> (20-8)) ^ ((u1 << 7) | (u0 >> (32-7)))) & 0xff;\n      u1 <<= 8;\n      u1 |= u0 >> 24;\n      u0 <<= 8;\n      u0 |= u;\n      *bytes++ = (png_byte)u;\n   }\n\n   seed[0] = u0;\n   seed[1] = u1;\n}\n\nstatic void\nmake_four_random_bytes(png_uint_32* seed, png_bytep bytes)\n{\n   make_random_bytes(seed, bytes, 4);\n}\n\n#if defined PNG_READ_SUPPORTED || defined PNG_WRITE_tRNS_SUPPORTED ||\\\n    defined PNG_WRITE_FILTER_SUPPORTED\nstatic void\nrandomize(void *pv, size_t size)\n{\n   static png_uint_32 random_seed[2] = {0x56789abc, 0xd};\n   make_random_bytes(random_seed, pv, size);\n}\n\n#define R8(this) randomize(&(this), sizeof (this))\n\n#ifdef PNG_READ_SUPPORTED\nstatic png_byte\nrandom_byte(void)\n{\n   unsigned char b1[1];\n   randomize(b1, sizeof b1);\n   return b1[0];\n}\n#endif /* READ */\n\nstatic png_uint_16\nrandom_u16(void)\n{\n   unsigned char b2[2];\n   randomize(b2, sizeof b2);\n   return png_get_uint_16(b2);\n}\n\n#if defined PNG_READ_RGB_TO_GRAY_SUPPORTED ||\\\n    defined PNG_READ_FILLER_SUPPORTED\nstatic png_uint_32\nrandom_u32(void)\n{\n   unsigned char b4[4];\n   randomize(b4, sizeof b4);\n   return png_get_uint_32(b4);\n}\n#endif /* READ_FILLER || READ_RGB_TO_GRAY */\n\n#endif /* READ || WRITE_tRNS || WRITE_FILTER */\n\n#if defined PNG_READ_TRANSFORMS_SUPPORTED ||\\\n    defined PNG_WRITE_FILTER_SUPPORTED\nstatic unsigned int\nrandom_mod(unsigned int max)\n{\n   return random_u16() % max; /* 0 .. max-1 */\n}\n#endif /* READ_TRANSFORMS || WRITE_FILTER */\n\n#if (defined PNG_READ_RGB_TO_GRAY_SUPPORTED) ||\\\n    (defined PNG_READ_FILLER_SUPPORTED)\nstatic int\nrandom_choice(void)\n{\n   return random_byte() & 1;\n}\n#endif /* READ_RGB_TO_GRAY || READ_FILLER */\n\n/* A numeric ID based on PNG file characteristics.  The 'do_interlace' field\n * simply records whether pngvalid did the interlace itself or whether it\n * was done by libpng.  Width and height must be less than 256.  'palette' is an\n * index of the palette to use for formats with a palette otherwise a boolean\n * indicating if a tRNS chunk was generated.\n */\n#define FILEID(col, depth, palette, interlace, width, height, do_interlace) \\\n   ((png_uint_32)((col) + ((depth)<<3) + ((palette)<<8) + ((interlace)<<13) + \\\n    (((do_interlace)!=0)<<15) + ((width)<<16) + ((height)<<24)))\n\n#define COL_FROM_ID(id) ((png_byte)((id)& 0x7U))\n#define DEPTH_FROM_ID(id) ((png_byte)(((id) >> 3) & 0x1fU))\n#define PALETTE_FROM_ID(id) (((id) >> 8) & 0x1f)\n#define INTERLACE_FROM_ID(id) ((png_byte)(((id) >> 13) & 0x3))\n#define DO_INTERLACE_FROM_ID(id) ((int)(((id)>>15) & 1))\n#define WIDTH_FROM_ID(id) (((id)>>16) & 0xff)\n#define HEIGHT_FROM_ID(id) (((id)>>24) & 0xff)\n\n/* Utility to construct a standard name for a standard image. */\nstatic size_t\nstandard_name(char *buffer, size_t bufsize, size_t pos, png_byte colour_type,\n    int bit_depth, unsigned int npalette, int interlace_type,\n    png_uint_32 w, png_uint_32 h, int do_interlace)\n{\n   pos = safecat(buffer, bufsize, pos, colour_types[colour_type]);\n   if (colour_type == 3) /* must have a palette */\n   {\n      pos = safecat(buffer, bufsize, pos, \"[\");\n      pos = safecatn(buffer, bufsize, pos, npalette);\n      pos = safecat(buffer, bufsize, pos, \"]\");\n   }\n\n   else if (npalette != 0)\n      pos = safecat(buffer, bufsize, pos, \"+tRNS\");\n\n   pos = safecat(buffer, bufsize, pos, \" \");\n   pos = safecatn(buffer, bufsize, pos, bit_depth);\n   pos = safecat(buffer, bufsize, pos, \" bit\");\n\n   if (interlace_type != PNG_INTERLACE_NONE)\n   {\n      pos = safecat(buffer, bufsize, pos, \" interlaced\");\n      if (do_interlace)\n         pos = safecat(buffer, bufsize, pos, \"(pngvalid)\");\n      else\n         pos = safecat(buffer, bufsize, pos, \"(libpng)\");\n   }\n\n   if (w > 0 || h > 0)\n   {\n      pos = safecat(buffer, bufsize, pos, \" \");\n      pos = safecatn(buffer, bufsize, pos, w);\n      pos = safecat(buffer, bufsize, pos, \"x\");\n      pos = safecatn(buffer, bufsize, pos, h);\n   }\n\n   return pos;\n}\n\nstatic size_t\nstandard_name_from_id(char *buffer, size_t bufsize, size_t pos, png_uint_32 id)\n{\n   return standard_name(buffer, bufsize, pos, COL_FROM_ID(id),\n      DEPTH_FROM_ID(id), PALETTE_FROM_ID(id), INTERLACE_FROM_ID(id),\n      WIDTH_FROM_ID(id), HEIGHT_FROM_ID(id), DO_INTERLACE_FROM_ID(id));\n}\n\n/* Convenience API and defines to list valid formats.  Note that 16 bit read and\n * write support is required to do 16 bit read tests (we must be able to make a\n * 16 bit image to test!)\n */\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n#  define WRITE_BDHI 4\n#  ifdef PNG_READ_16BIT_SUPPORTED\n#     define READ_BDHI 4\n#     define DO_16BIT\n#  endif\n#else\n#  define WRITE_BDHI 3\n#endif\n#ifndef DO_16BIT\n#  define READ_BDHI 3\n#endif\n\n/* The following defines the number of different palettes to generate for\n * each log bit depth of a colour type 3 standard image.\n */\n#define PALETTE_COUNT(bit_depth) ((bit_depth) > 4 ? 1U : 16U)\n\nstatic int\nnext_format(png_bytep colour_type, png_bytep bit_depth,\n   unsigned int* palette_number, int low_depth_gray, int tRNS)\n{\n   if (*bit_depth == 0)\n   {\n      *colour_type = 0;\n      if (low_depth_gray)\n         *bit_depth = 1;\n      else\n         *bit_depth = 8;\n      *palette_number = 0;\n      return 1;\n   }\n\n   if  (*colour_type < 4/*no alpha channel*/)\n   {\n      /* Add multiple palettes for colour type 3, one image with tRNS\n       * and one without for other non-alpha formats:\n       */\n      unsigned int pn = ++*palette_number;\n      png_byte ct = *colour_type;\n\n      if (((ct == 0/*GRAY*/ || ct/*RGB*/ == 2) && tRNS && pn < 2) ||\n          (ct == 3/*PALETTE*/ && pn < PALETTE_COUNT(*bit_depth)))\n         return 1;\n\n      /* No: next bit depth */\n      *palette_number = 0;\n   }\n\n   *bit_depth = (png_byte)(*bit_depth << 1);\n\n   /* Palette images are restricted to 8 bit depth */\n   if (*bit_depth <= 8\n#ifdef DO_16BIT\n         || (*colour_type != 3 && *bit_depth <= 16)\n#endif\n      )\n      return 1;\n\n   /* Move to the next color type, or return 0 at the end. */\n   switch (*colour_type)\n   {\n      case 0:\n         *colour_type = 2;\n         *bit_depth = 8;\n         return 1;\n\n      case 2:\n         *colour_type = 3;\n         *bit_depth = 1;\n         return 1;\n\n      case 3:\n         *colour_type = 4;\n         *bit_depth = 8;\n         return 1;\n\n      case 4:\n         *colour_type = 6;\n         *bit_depth = 8;\n         return 1;\n\n      default:\n         return 0;\n   }\n}\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nstatic unsigned int\nsample(png_const_bytep row, png_byte colour_type, png_byte bit_depth,\n    png_uint_32 x, unsigned int sample_index, int swap16, int littleendian)\n{\n   png_uint_32 bit_index, result;\n\n   /* Find a sample index for the desired sample: */\n   x *= bit_depth;\n   bit_index = x;\n\n   if ((colour_type & 1) == 0) /* !palette */\n   {\n      if (colour_type & 2)\n         bit_index *= 3;\n\n      if (colour_type & 4)\n         bit_index += x; /* Alpha channel */\n\n      /* Multiple channels; select one: */\n      if (colour_type & (2+4))\n         bit_index += sample_index * bit_depth;\n   }\n\n   /* Return the sample from the row as an integer. */\n   row += bit_index >> 3;\n   result = *row;\n\n   if (bit_depth == 8)\n      return result;\n\n   else if (bit_depth > 8)\n   {\n      if (swap16)\n         return (*++row << 8) + result;\n      else\n         return (result << 8) + *++row;\n   }\n\n   /* Less than 8 bits per sample.  By default PNG has the big end of\n    * the egg on the left of the screen, but if littleendian is set\n    * then the big end is on the right.\n    */\n   bit_index &= 7;\n\n   if (!littleendian)\n      bit_index = 8-bit_index-bit_depth;\n\n   return (result >> bit_index) & ((1U<<bit_depth)-1);\n}\n#endif /* PNG_READ_TRANSFORMS_SUPPORTED */\n\n/* Copy a single pixel, of a given size, from one buffer to another -\n * while this is basically bit addressed there is an implicit assumption\n * that pixels 8 or more bits in size are byte aligned and that pixels\n * do not otherwise cross byte boundaries.  (This is, so far as I know,\n * universally true in bitmap computer graphics.  [JCB 20101212])\n *\n * NOTE: The to and from buffers may be the same.\n */\nstatic void\npixel_copy(png_bytep toBuffer, png_uint_32 toIndex,\n   png_const_bytep fromBuffer, png_uint_32 fromIndex, unsigned int pixelSize,\n   int littleendian)\n{\n   /* Assume we can multiply by 'size' without overflow because we are\n    * just working in a single buffer.\n    */\n   toIndex *= pixelSize;\n   fromIndex *= pixelSize;\n   if (pixelSize < 8) /* Sub-byte */\n   {\n      /* Mask to select the location of the copied pixel: */\n      unsigned int destMask = ((1U<<pixelSize)-1) <<\n         (littleendian ? toIndex&7 : 8-pixelSize-(toIndex&7));\n      /* The following read the entire pixels and clears the extra: */\n      unsigned int destByte = toBuffer[toIndex >> 3] & ~destMask;\n      unsigned int sourceByte = fromBuffer[fromIndex >> 3];\n\n      /* Don't rely on << or >> supporting '0' here, just in case: */\n      fromIndex &= 7;\n      if (littleendian)\n      {\n         if (fromIndex > 0) sourceByte >>= fromIndex;\n         if ((toIndex & 7) > 0) sourceByte <<= toIndex & 7;\n      }\n\n      else\n      {\n         if (fromIndex > 0) sourceByte <<= fromIndex;\n         if ((toIndex & 7) > 0) sourceByte >>= toIndex & 7;\n      }\n\n      toBuffer[toIndex >> 3] = (png_byte)(destByte | (sourceByte & destMask));\n   }\n   else /* One or more bytes */\n      memmove(toBuffer+(toIndex>>3), fromBuffer+(fromIndex>>3), pixelSize>>3);\n}\n\n#ifdef PNG_READ_SUPPORTED\n/* Copy a complete row of pixels, taking into account potential partial\n * bytes at the end.\n */\nstatic void\nrow_copy(png_bytep toBuffer, png_const_bytep fromBuffer, unsigned int bitWidth,\n      int littleendian)\n{\n   memcpy(toBuffer, fromBuffer, bitWidth >> 3);\n\n   if ((bitWidth & 7) != 0)\n   {\n      unsigned int mask;\n\n      toBuffer += bitWidth >> 3;\n      fromBuffer += bitWidth >> 3;\n      if (littleendian)\n         mask = 0xff << (bitWidth & 7);\n      else\n         mask = 0xff >> (bitWidth & 7);\n      *toBuffer = (png_byte)((*toBuffer & mask) | (*fromBuffer & ~mask));\n   }\n}\n\n/* Compare pixels - they are assumed to start at the first byte in the\n * given buffers.\n */\nstatic int\npixel_cmp(png_const_bytep pa, png_const_bytep pb, png_uint_32 bit_width)\n{\n#if PNG_LIBPNG_VER < 10506\n   if (memcmp(pa, pb, bit_width>>3) == 0)\n   {\n      png_uint_32 p;\n\n      if ((bit_width & 7) == 0) return 0;\n\n      /* Ok, any differences? */\n      p = pa[bit_width >> 3];\n      p ^= pb[bit_width >> 3];\n\n      if (p == 0) return 0;\n\n      /* There are, but they may not be significant, remove the bits\n       * after the end (the low order bits in PNG.)\n       */\n      bit_width &= 7;\n      p >>= 8-bit_width;\n\n      if (p == 0) return 0;\n   }\n#else\n   /* From libpng-1.5.6 the overwrite should be fixed, so compare the trailing\n    * bits too:\n    */\n   if (memcmp(pa, pb, (bit_width+7)>>3) == 0)\n      return 0;\n#endif\n\n   /* Return the index of the changed byte. */\n   {\n      png_uint_32 where = 0;\n\n      while (pa[where] == pb[where]) ++where;\n      return 1+where;\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/*************************** BASIC PNG FILE WRITING ***************************/\n/* A png_store takes data from the sequential writer or provides data\n * to the sequential reader.  It can also store the result of a PNG\n * write for later retrieval.\n */\n#define STORE_BUFFER_SIZE 500 /* arbitrary */\ntypedef struct png_store_buffer\n{\n   struct png_store_buffer*  prev;    /* NOTE: stored in reverse order */\n   png_byte                  buffer[STORE_BUFFER_SIZE];\n} png_store_buffer;\n\n#define FILE_NAME_SIZE 64\n\ntypedef struct store_palette_entry /* record of a single palette entry */\n{\n   png_byte red;\n   png_byte green;\n   png_byte blue;\n   png_byte alpha;\n} store_palette_entry, store_palette[256];\n\ntypedef struct png_store_file\n{\n   struct png_store_file*  next;      /* as many as you like... */\n   char                    name[FILE_NAME_SIZE];\n   unsigned int            IDAT_bits; /* Number of bits in IDAT size */\n   png_uint_32             IDAT_size; /* Total size of IDAT data */\n   png_uint_32             id;        /* must be correct (see FILEID) */\n   png_size_t              datacount; /* In this (the last) buffer */\n   png_store_buffer        data;      /* Last buffer in file */\n   int                     npalette;  /* Number of entries in palette */\n   store_palette_entry*    palette;   /* May be NULL */\n} png_store_file;\n\n/* The following is a pool of memory allocated by a single libpng read or write\n * operation.\n */\ntypedef struct store_pool\n{\n   struct png_store    *store;   /* Back pointer */\n   struct store_memory *list;    /* List of allocated memory */\n   png_byte             mark[4]; /* Before and after data */\n\n   /* Statistics for this run. */\n   png_alloc_size_t     max;     /* Maximum single allocation */\n   png_alloc_size_t     current; /* Current allocation */\n   png_alloc_size_t     limit;   /* Highest current allocation */\n   png_alloc_size_t     total;   /* Total allocation */\n\n   /* Overall statistics (retained across successive runs). */\n   png_alloc_size_t     max_max;\n   png_alloc_size_t     max_limit;\n   png_alloc_size_t     max_total;\n} store_pool;\n\ntypedef struct png_store\n{\n   /* For cexcept.h exception handling - simply store one of these;\n    * the context is a self pointer but it may point to a different\n    * png_store (in fact it never does in this program.)\n    */\n   struct exception_context\n                      exception_context;\n\n   unsigned int       verbose :1;\n   unsigned int       treat_warnings_as_errors :1;\n   unsigned int       expect_error :1;\n   unsigned int       expect_warning :1;\n   unsigned int       saw_warning :1;\n   unsigned int       speed :1;\n   unsigned int       progressive :1; /* use progressive read */\n   unsigned int       validated :1;   /* used as a temporary flag */\n   int                nerrors;\n   int                nwarnings;\n   int                noptions;       /* number of options below: */\n   struct {\n      unsigned char   option;         /* option number, 0..30 */\n      unsigned char   setting;        /* setting (unset,invalid,on,off) */\n   }                  options[16];\n   char               test[128];      /* Name of test */\n   char               error[256];\n\n   /* Share fields */\n   png_uint_32        chunklen; /* Length of chunk+overhead (chunkpos >= 8) */\n   png_uint_32        chunktype;/* Type of chunk (valid if chunkpos >= 4) */\n   png_uint_32        chunkpos; /* Position in chunk */\n   png_uint_32        IDAT_size;/* Accumulated IDAT size in .new */\n   unsigned int       IDAT_bits;/* Cache of the file store value */\n\n   /* Read fields */\n   png_structp        pread;    /* Used to read a saved file */\n   png_infop          piread;\n   png_store_file*    current;  /* Set when reading */\n   png_store_buffer*  next;     /* Set when reading */\n   png_size_t         readpos;  /* Position in *next */\n   png_byte*          image;    /* Buffer for reading interlaced images */\n   png_size_t         cb_image; /* Size of this buffer */\n   png_size_t         cb_row;   /* Row size of the image(s) */\n   uLong              IDAT_crc;\n   png_uint_32        IDAT_len; /* Used when re-chunking IDAT chunks */\n   png_uint_32        IDAT_pos; /* Used when re-chunking IDAT chunks */\n   png_uint_32        image_h;  /* Number of rows in a single image */\n   store_pool         read_memory_pool;\n\n   /* Write fields */\n   png_store_file*    saved;\n   png_structp        pwrite;   /* Used when writing a new file */\n   png_infop          piwrite;\n   png_size_t         writepos; /* Position in .new */\n   char               wname[FILE_NAME_SIZE];\n   png_store_buffer   new;      /* The end of the new PNG file being written. */\n   store_pool         write_memory_pool;\n   store_palette_entry* palette;\n   int                  npalette;\n} png_store;\n\n/* Initialization and cleanup */\nstatic void\nstore_pool_mark(png_bytep mark)\n{\n   static png_uint_32 store_seed[2] = { 0x12345678, 1};\n\n   make_four_random_bytes(store_seed, mark);\n}\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n/* Use this for random 32 bit values; this function makes sure the result is\n * non-zero.\n */\nstatic png_uint_32\nrandom_32(void)\n{\n\n   for (;;)\n   {\n      png_byte mark[4];\n      png_uint_32 result;\n\n      store_pool_mark(mark);\n      result = png_get_uint_32(mark);\n\n      if (result != 0)\n         return result;\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\nstatic void\nstore_pool_init(png_store *ps, store_pool *pool)\n{\n   memset(pool, 0, sizeof *pool);\n\n   pool->store = ps;\n   pool->list = NULL;\n   pool->max = pool->current = pool->limit = pool->total = 0;\n   pool->max_max = pool->max_limit = pool->max_total = 0;\n   store_pool_mark(pool->mark);\n}\n\nstatic void\nstore_init(png_store* ps)\n{\n   memset(ps, 0, sizeof *ps);\n   init_exception_context(&ps->exception_context);\n   store_pool_init(ps, &ps->read_memory_pool);\n   store_pool_init(ps, &ps->write_memory_pool);\n   ps->verbose = 0;\n   ps->treat_warnings_as_errors = 0;\n   ps->expect_error = 0;\n   ps->expect_warning = 0;\n   ps->saw_warning = 0;\n   ps->speed = 0;\n   ps->progressive = 0;\n   ps->validated = 0;\n   ps->nerrors = ps->nwarnings = 0;\n   ps->pread = NULL;\n   ps->piread = NULL;\n   ps->saved = ps->current = NULL;\n   ps->next = NULL;\n   ps->readpos = 0;\n   ps->image = NULL;\n   ps->cb_image = 0;\n   ps->cb_row = 0;\n   ps->image_h = 0;\n   ps->pwrite = NULL;\n   ps->piwrite = NULL;\n   ps->writepos = 0;\n   ps->chunkpos = 8;\n   ps->chunktype = 0;\n   ps->chunklen = 16;\n   ps->IDAT_size = 0;\n   ps->IDAT_bits = 0;\n   ps->new.prev = NULL;\n   ps->palette = NULL;\n   ps->npalette = 0;\n   ps->noptions = 0;\n}\n\nstatic void\nstore_freebuffer(png_store_buffer* psb)\n{\n   if (psb->prev)\n   {\n      store_freebuffer(psb->prev);\n      free(psb->prev);\n      psb->prev = NULL;\n   }\n}\n\nstatic void\nstore_freenew(png_store *ps)\n{\n   store_freebuffer(&ps->new);\n   ps->writepos = 0;\n   ps->chunkpos = 8;\n   ps->chunktype = 0;\n   ps->chunklen = 16;\n   ps->IDAT_size = 0;\n   ps->IDAT_bits = 0;\n   if (ps->palette != NULL)\n   {\n      free(ps->palette);\n      ps->palette = NULL;\n      ps->npalette = 0;\n   }\n}\n\nstatic void\nstore_storenew(png_store *ps)\n{\n   png_store_buffer *pb;\n\n   pb = voidcast(png_store_buffer*, malloc(sizeof *pb));\n\n   if (pb == NULL)\n      png_error(ps->pwrite, \"store new: OOM\");\n\n   *pb = ps->new;\n   ps->new.prev = pb;\n   ps->writepos = 0;\n}\n\nstatic void\nstore_freefile(png_store_file **ppf)\n{\n   if (*ppf != NULL)\n   {\n      store_freefile(&(*ppf)->next);\n\n      store_freebuffer(&(*ppf)->data);\n      (*ppf)->datacount = 0;\n      if ((*ppf)->palette != NULL)\n      {\n         free((*ppf)->palette);\n         (*ppf)->palette = NULL;\n         (*ppf)->npalette = 0;\n      }\n      free(*ppf);\n      *ppf = NULL;\n   }\n}\n\nstatic unsigned int\nbits_of(png_uint_32 num)\n{\n   /* Return the number of bits in 'num' */\n   unsigned int b = 0;\n\n   if (num & 0xffff0000U)  b += 16U, num >>= 16;\n   if (num & 0xff00U)      b += 8U, num >>= 8;\n   if (num & 0xf0U)        b += 4U, num >>= 4;\n   if (num & 0xcU)         b += 2U, num >>= 2;\n   if (num & 0x2U)         ++b, num >>= 1;\n   if (num)                ++b;\n\n   return b; /* 0..32 */\n}\n\n/* Main interface to file storeage, after writing a new PNG file (see the API\n * below) call store_storefile to store the result with the given name and id.\n */\nstatic void\nstore_storefile(png_store *ps, png_uint_32 id)\n{\n   png_store_file *pf;\n\n   if (ps->chunkpos != 0U || ps->chunktype != 0U || ps->chunklen != 0U ||\n       ps->IDAT_size == 0)\n      png_error(ps->pwrite, \"storefile: incomplete write\");\n\n   pf = voidcast(png_store_file*, malloc(sizeof *pf));\n   if (pf == NULL)\n      png_error(ps->pwrite, \"storefile: OOM\");\n   safecat(pf->name, sizeof pf->name, 0, ps->wname);\n   pf->id = id;\n   pf->data = ps->new;\n   pf->datacount = ps->writepos;\n   pf->IDAT_size = ps->IDAT_size;\n   pf->IDAT_bits = bits_of(ps->IDAT_size);\n   /* Because the IDAT always has zlib header stuff this must be true: */\n   if (pf->IDAT_bits == 0U)\n      png_error(ps->pwrite, \"storefile: 0 sized IDAT\");\n   ps->new.prev = NULL;\n   ps->writepos = 0;\n   ps->chunkpos = 8;\n   ps->chunktype = 0;\n   ps->chunklen = 16;\n   ps->IDAT_size = 0;\n   pf->palette = ps->palette;\n   pf->npalette = ps->npalette;\n   ps->palette = 0;\n   ps->npalette = 0;\n\n   /* And save it. */\n   pf->next = ps->saved;\n   ps->saved = pf;\n}\n\n/* Generate an error message (in the given buffer) */\nstatic size_t\nstore_message(png_store *ps, png_const_structp pp, char *buffer, size_t bufsize,\n   size_t pos, const char *msg)\n{\n   if (pp != NULL && pp == ps->pread)\n   {\n      /* Reading a file */\n      pos = safecat(buffer, bufsize, pos, \"read: \");\n\n      if (ps->current != NULL)\n      {\n         pos = safecat(buffer, bufsize, pos, ps->current->name);\n         pos = safecat(buffer, bufsize, pos, sep);\n      }\n   }\n\n   else if (pp != NULL && pp == ps->pwrite)\n   {\n      /* Writing a file */\n      pos = safecat(buffer, bufsize, pos, \"write: \");\n      pos = safecat(buffer, bufsize, pos, ps->wname);\n      pos = safecat(buffer, bufsize, pos, sep);\n   }\n\n   else\n   {\n      /* Neither reading nor writing (or a memory error in struct delete) */\n      pos = safecat(buffer, bufsize, pos, \"pngvalid: \");\n   }\n\n   if (ps->test[0] != 0)\n   {\n      pos = safecat(buffer, bufsize, pos, ps->test);\n      pos = safecat(buffer, bufsize, pos, sep);\n   }\n   pos = safecat(buffer, bufsize, pos, msg);\n   return pos;\n}\n\n/* Verbose output to the error stream: */\nstatic void\nstore_verbose(png_store *ps, png_const_structp pp, png_const_charp prefix,\n   png_const_charp message)\n{\n   char buffer[512];\n\n   if (prefix)\n      fputs(prefix, stderr);\n\n   (void)store_message(ps, pp, buffer, sizeof buffer, 0, message);\n   fputs(buffer, stderr);\n   fputc('\\n', stderr);\n}\n\n/* Log an error or warning - the relevant count is always incremented. */\nstatic void\nstore_log(png_store* ps, png_const_structp pp, png_const_charp message,\n   int is_error)\n{\n   /* The warning is copied to the error buffer if there are no errors and it is\n    * the first warning.  The error is copied to the error buffer if it is the\n    * first error (overwriting any prior warnings).\n    */\n   if (is_error ? (ps->nerrors)++ == 0 :\n       (ps->nwarnings)++ == 0 && ps->nerrors == 0)\n      store_message(ps, pp, ps->error, sizeof ps->error, 0, message);\n\n   if (ps->verbose)\n      store_verbose(ps, pp, is_error ? \"error: \" : \"warning: \", message);\n}\n\n#ifdef PNG_READ_SUPPORTED\n/* Internal error function, called with a png_store but no libpng stuff. */\nstatic void\ninternal_error(png_store *ps, png_const_charp message)\n{\n   store_log(ps, NULL, message, 1 /* error */);\n\n   /* And finally throw an exception. */\n   {\n      struct exception_context *the_exception_context = &ps->exception_context;\n      Throw ps;\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* Functions to use as PNG callbacks. */\nstatic void PNGCBAPI\nstore_error(png_structp ppIn, png_const_charp message) /* PNG_NORETURN */\n{\n   png_const_structp pp = ppIn;\n   png_store *ps = voidcast(png_store*, png_get_error_ptr(pp));\n\n   if (!ps->expect_error)\n      store_log(ps, pp, message, 1 /* error */);\n\n   /* And finally throw an exception. */\n   {\n      struct exception_context *the_exception_context = &ps->exception_context;\n      Throw ps;\n   }\n}\n\nstatic void PNGCBAPI\nstore_warning(png_structp ppIn, png_const_charp message)\n{\n   png_const_structp pp = ppIn;\n   png_store *ps = voidcast(png_store*, png_get_error_ptr(pp));\n\n   if (!ps->expect_warning)\n      store_log(ps, pp, message, 0 /* warning */);\n   else\n      ps->saw_warning = 1;\n}\n\n/* These somewhat odd functions are used when reading an image to ensure that\n * the buffer is big enough, the png_structp is for errors.\n */\n/* Return a single row from the correct image. */\nstatic png_bytep\nstore_image_row(const png_store* ps, png_const_structp pp, int nImage,\n   png_uint_32 y)\n{\n   png_size_t coffset = (nImage * ps->image_h + y) * (ps->cb_row + 5) + 2;\n\n   if (ps->image == NULL)\n      png_error(pp, \"no allocated image\");\n\n   if (coffset + ps->cb_row + 3 > ps->cb_image)\n      png_error(pp, \"image too small\");\n\n   return ps->image + coffset;\n}\n\nstatic void\nstore_image_free(png_store *ps, png_const_structp pp)\n{\n   if (ps->image != NULL)\n   {\n      png_bytep image = ps->image;\n\n      if (image[-1] != 0xed || image[ps->cb_image] != 0xfe)\n      {\n         if (pp != NULL)\n            png_error(pp, \"png_store image overwrite (1)\");\n         else\n            store_log(ps, NULL, \"png_store image overwrite (2)\", 1);\n      }\n\n      ps->image = NULL;\n      ps->cb_image = 0;\n      --image;\n      free(image);\n   }\n}\n\nstatic void\nstore_ensure_image(png_store *ps, png_const_structp pp, int nImages,\n   png_size_t cbRow, png_uint_32 cRows)\n{\n   png_size_t cb = nImages * cRows * (cbRow + 5);\n\n   if (ps->cb_image < cb)\n   {\n      png_bytep image;\n\n      store_image_free(ps, pp);\n\n      /* The buffer is deliberately mis-aligned. */\n      image = voidcast(png_bytep, malloc(cb+2));\n      if (image == NULL)\n      {\n         /* Called from the startup - ignore the error for the moment. */\n         if (pp == NULL)\n            return;\n\n         png_error(pp, \"OOM allocating image buffer\");\n      }\n\n      /* These magic tags are used to detect overwrites above. */\n      ++image;\n      image[-1] = 0xed;\n      image[cb] = 0xfe;\n\n      ps->image = image;\n      ps->cb_image = cb;\n   }\n\n   /* We have an adequate sized image; lay out the rows.  There are 2 bytes at\n    * the start and three at the end of each (this ensures that the row\n    * alignment starts out odd - 2+1 and changes for larger images on each row.)\n    */\n   ps->cb_row = cbRow;\n   ps->image_h = cRows;\n\n   /* For error checking, the whole buffer is set to 10110010 (0xb2 - 178).\n    * This deliberately doesn't match the bits in the size test image which are\n    * outside the image; these are set to 0xff (all 1).  To make the row\n    * comparison work in the 'size' test case the size rows are pre-initialized\n    * to the same value prior to calling 'standard_row'.\n    */\n   memset(ps->image, 178, cb);\n\n   /* Then put in the marks. */\n   while (--nImages >= 0)\n   {\n      png_uint_32 y;\n\n      for (y=0; y<cRows; ++y)\n      {\n         png_bytep row = store_image_row(ps, pp, nImages, y);\n\n         /* The markers: */\n         row[-2] = 190;\n         row[-1] = 239;\n         row[cbRow] = 222;\n         row[cbRow+1] = 173;\n         row[cbRow+2] = 17;\n      }\n   }\n}\n\n#ifdef PNG_READ_SUPPORTED\nstatic void\nstore_image_check(const png_store* ps, png_const_structp pp, int iImage)\n{\n   png_const_bytep image = ps->image;\n\n   if (image[-1] != 0xed || image[ps->cb_image] != 0xfe)\n      png_error(pp, \"image overwrite\");\n   else\n   {\n      png_size_t cbRow = ps->cb_row;\n      png_uint_32 rows = ps->image_h;\n\n      image += iImage * (cbRow+5) * ps->image_h;\n\n      image += 2; /* skip image first row markers */\n\n      while (rows-- > 0)\n      {\n         if (image[-2] != 190 || image[-1] != 239)\n            png_error(pp, \"row start overwritten\");\n\n         if (image[cbRow] != 222 || image[cbRow+1] != 173 ||\n            image[cbRow+2] != 17)\n            png_error(pp, \"row end overwritten\");\n\n         image += cbRow+5;\n      }\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\nstatic int\nvalid_chunktype(png_uint_32 chunktype)\n{\n   /* Each byte in the chunk type must be in one of the ranges 65..90, 97..122\n    * (both inclusive), so:\n    */\n   unsigned int i;\n\n   for (i=0; i<4; ++i)\n   {\n      unsigned int c = chunktype & 0xffU;\n\n      if (!((c >= 65U && c <= 90U) || (c >= 97U && c <= 122U)))\n         return 0;\n\n      chunktype >>= 8;\n   }\n\n   return 1; /* It's valid */\n}\n\nstatic void PNGCBAPI\nstore_write(png_structp ppIn, png_bytep pb, png_size_t st)\n{\n   png_const_structp pp = ppIn;\n   png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));\n   size_t writepos = ps->writepos;\n   png_uint_32 chunkpos = ps->chunkpos;\n   png_uint_32 chunktype = ps->chunktype;\n   png_uint_32 chunklen = ps->chunklen;\n\n   if (ps->pwrite != pp)\n      png_error(pp, \"store state damaged\");\n\n   /* Technically this is legal, but in practice libpng never writes more than\n    * the maximum chunk size at once so if it happens something weird has\n    * changed inside libpng (probably).\n    */\n   if (st > 0x7fffffffU)\n      png_error(pp, \"unexpected write size\");\n\n   /* Now process the bytes to be written.  Do this in units of the space in the\n    * output (write) buffer or, at the start 4 bytes for the chunk type and\n    * length limited in any case by the amount of data.\n    */\n   while (st > 0)\n   {\n      if (writepos >= STORE_BUFFER_SIZE)\n         store_storenew(ps), writepos = 0;\n\n      if (chunkpos < 4)\n      {\n         png_byte b = *pb++;\n         --st;\n         chunklen = (chunklen << 8) + b;\n         ps->new.buffer[writepos++] = b;\n         ++chunkpos;\n      }\n\n      else if (chunkpos < 8)\n      {\n         png_byte b = *pb++;\n         --st;\n         chunktype = (chunktype << 8) + b;\n         ps->new.buffer[writepos++] = b;\n\n         if (++chunkpos == 8)\n         {\n            chunklen &= 0xffffffffU;\n            if (chunklen > 0x7fffffffU)\n               png_error(pp, \"chunk length too great\");\n\n            chunktype &= 0xffffffffU;\n            if (chunktype == CHUNK_IDAT)\n            {\n               if (chunklen > ~ps->IDAT_size)\n                  png_error(pp, \"pngvalid internal image too large\");\n\n               ps->IDAT_size += chunklen;\n            }\n\n            else if (!valid_chunktype(chunktype))\n               png_error(pp, \"invalid chunk type\");\n\n            chunklen += 12; /* for header and CRC */\n         }\n      }\n\n      else /* chunkpos >= 8 */\n      {\n         png_size_t cb = st;\n\n         if (cb > STORE_BUFFER_SIZE - writepos)\n            cb = STORE_BUFFER_SIZE - writepos;\n\n         if (cb  > chunklen - chunkpos/* bytes left in chunk*/)\n            cb = (png_size_t)/*SAFE*/(chunklen - chunkpos);\n\n         memcpy(ps->new.buffer + writepos, pb, cb);\n         chunkpos += (png_uint_32)/*SAFE*/cb;\n         pb += cb;\n         writepos += cb;\n         st -= cb;\n\n         if (chunkpos >= chunklen) /* must be equal */\n            chunkpos = chunktype = chunklen = 0;\n      }\n   } /* while (st > 0) */\n\n   ps->writepos = writepos;\n   ps->chunkpos = chunkpos;\n   ps->chunktype = chunktype;\n   ps->chunklen = chunklen;\n}\n\nstatic void PNGCBAPI\nstore_flush(png_structp ppIn)\n{\n   UNUSED(ppIn) /*DOES NOTHING*/\n}\n\n#ifdef PNG_READ_SUPPORTED\nstatic size_t\nstore_read_buffer_size(png_store *ps)\n{\n   /* Return the bytes available for read in the current buffer. */\n   if (ps->next != &ps->current->data)\n      return STORE_BUFFER_SIZE;\n\n   return ps->current->datacount;\n}\n\n/* Return total bytes available for read. */\nstatic size_t\nstore_read_buffer_avail(png_store *ps)\n{\n   if (ps->current != NULL && ps->next != NULL)\n   {\n      png_store_buffer *next = &ps->current->data;\n      size_t cbAvail = ps->current->datacount;\n\n      while (next != ps->next && next != NULL)\n      {\n         next = next->prev;\n         cbAvail += STORE_BUFFER_SIZE;\n      }\n\n      if (next != ps->next)\n         png_error(ps->pread, \"buffer read error\");\n\n      if (cbAvail > ps->readpos)\n         return cbAvail - ps->readpos;\n   }\n\n   return 0;\n}\n\nstatic int\nstore_read_buffer_next(png_store *ps)\n{\n   png_store_buffer *pbOld = ps->next;\n   png_store_buffer *pbNew = &ps->current->data;\n   if (pbOld != pbNew)\n   {\n      while (pbNew != NULL && pbNew->prev != pbOld)\n         pbNew = pbNew->prev;\n\n      if (pbNew != NULL)\n      {\n         ps->next = pbNew;\n         ps->readpos = 0;\n         return 1;\n      }\n\n      png_error(ps->pread, \"buffer lost\");\n   }\n\n   return 0; /* EOF or error */\n}\n\n/* Need separate implementation and callback to allow use of the same code\n * during progressive read, where the io_ptr is set internally by libpng.\n */\nstatic void\nstore_read_imp(png_store *ps, png_bytep pb, png_size_t st)\n{\n   if (ps->current == NULL || ps->next == NULL)\n      png_error(ps->pread, \"store state damaged\");\n\n   while (st > 0)\n   {\n      size_t cbAvail = store_read_buffer_size(ps) - ps->readpos;\n\n      if (cbAvail > 0)\n      {\n         if (cbAvail > st) cbAvail = st;\n         memcpy(pb, ps->next->buffer + ps->readpos, cbAvail);\n         st -= cbAvail;\n         pb += cbAvail;\n         ps->readpos += cbAvail;\n      }\n\n      else if (!store_read_buffer_next(ps))\n         png_error(ps->pread, \"read beyond end of file\");\n   }\n}\n\nstatic png_size_t\nstore_read_chunk(png_store *ps, png_bytep pb, const png_size_t max,\n      const png_size_t min)\n{\n   png_uint_32 chunklen = ps->chunklen;\n   png_uint_32 chunktype = ps->chunktype;\n   png_uint_32 chunkpos = ps->chunkpos;\n   png_size_t st = max;\n\n   if (st > 0) do\n   {\n      if (chunkpos >= chunklen) /* end of last chunk */\n      {\n         png_byte buffer[8];\n\n         /* Read the header of the next chunk: */\n         store_read_imp(ps, buffer, 8U);\n         chunklen = png_get_uint_32(buffer) + 12U;\n         chunktype = png_get_uint_32(buffer+4U);\n         chunkpos = 0U; /* Position read so far */\n      }\n\n      if (chunktype == CHUNK_IDAT)\n      {\n         png_uint_32 IDAT_pos = ps->IDAT_pos;\n         png_uint_32 IDAT_len = ps->IDAT_len;\n         png_uint_32 IDAT_size = ps->IDAT_size;\n\n         /* The IDAT headers are constructed here; skip the input header. */\n         if (chunkpos < 8U)\n            chunkpos = 8U;\n\n         if (IDAT_pos == IDAT_len)\n         {\n            png_byte random = random_byte();\n\n            /* Make a new IDAT chunk, if IDAT_len is 0 this is the first IDAT,\n             * if IDAT_size is 0 this is the end.  At present this is set up\n             * using a random number so that there is a 25% chance before\n             * the start of the first IDAT chunk being 0 length.\n             */\n            if (IDAT_len == 0U) /* First IDAT */\n            {\n               switch (random & 3U)\n               {\n                  case 0U: IDAT_len = 12U; break; /* 0 bytes */\n                  case 1U: IDAT_len = 13U; break; /* 1 byte */\n                  default: IDAT_len = random_u32();\n                           IDAT_len %= IDAT_size;\n                           IDAT_len += 13U; /* 1..IDAT_size bytes */\n                           break;\n               }\n            }\n\n            else if (IDAT_size == 0U) /* all IDAT data read */\n            {\n               /* The last (IDAT) chunk should be positioned at the CRC now: */\n               if (chunkpos != chunklen-4U)\n                  png_error(ps->pread, \"internal: IDAT size mismatch\");\n\n               /* The only option here is to add a zero length IDAT, this\n                * happens 25% of the time.  Because of the check above\n                * chunklen-4U-chunkpos must be zero, we just need to skip the\n                * CRC now.\n                */\n               if ((random & 3U) == 0U)\n                  IDAT_len = 12U; /* Output another 0 length IDAT */\n\n               else\n               {\n                  /* End of IDATs, skip the CRC to make the code above load the\n                   * next chunk header next time round.\n                   */\n                  png_byte buffer[4];\n\n                  store_read_imp(ps, buffer, 4U);\n                  chunkpos += 4U;\n                  ps->IDAT_pos = IDAT_pos;\n                  ps->IDAT_len = IDAT_len;\n                  ps->IDAT_size = 0U;\n                  continue; /* Read the next chunk */\n               }\n            }\n\n            else\n            {\n               /* Middle of IDATs, use 'random' to determine the number of bits\n                * to use in the IDAT length.\n                */\n               IDAT_len = random_u32();\n               IDAT_len &= (1U << (1U + random % ps->IDAT_bits)) - 1U;\n               if (IDAT_len > IDAT_size)\n                  IDAT_len = IDAT_size;\n               IDAT_len += 12U; /* zero bytes may occur */\n            }\n\n            IDAT_pos = 0U;\n            ps->IDAT_crc = 0x35af061e; /* Ie: crc32(0UL, \"IDAT\", 4) */\n         } /* IDAT_pos == IDAT_len */\n\n         if (IDAT_pos < 8U) /* Return the header */ do\n         {\n            png_uint_32 b;\n            unsigned int shift;\n\n            if (IDAT_pos < 4U)\n               b = IDAT_len - 12U;\n\n            else\n               b = CHUNK_IDAT;\n\n            shift = 3U & IDAT_pos;\n            ++IDAT_pos;\n\n            if (shift < 3U)\n               b >>= 8U*(3U-shift);\n\n            *pb++ = 0xffU & b;\n         }\n         while (--st > 0 && IDAT_pos < 8);\n\n         else if (IDAT_pos < IDAT_len - 4U) /* I.e not the CRC */\n         {\n            if (chunkpos < chunklen-4U)\n            {\n               uInt avail = (uInt)-1;\n\n               if (avail > (IDAT_len-4U) - IDAT_pos)\n                  avail = (uInt)/*SAFE*/((IDAT_len-4U) - IDAT_pos);\n\n               if (avail > st)\n                  avail = (uInt)/*SAFE*/st;\n\n               if (avail > (chunklen-4U) - chunkpos)\n                  avail = (uInt)/*SAFE*/((chunklen-4U) - chunkpos);\n\n               store_read_imp(ps, pb, avail);\n               ps->IDAT_crc = crc32(ps->IDAT_crc, pb, avail);\n               pb += (png_size_t)/*SAFE*/avail;\n               st -= (png_size_t)/*SAFE*/avail;\n               chunkpos += (png_uint_32)/*SAFE*/avail;\n               IDAT_size -= (png_uint_32)/*SAFE*/avail;\n               IDAT_pos += (png_uint_32)/*SAFE*/avail;\n            }\n\n            else /* skip the input CRC */\n            {\n               png_byte buffer[4];\n\n               store_read_imp(ps, buffer, 4U);\n               chunkpos += 4U;\n            }\n         }\n\n         else /* IDAT crc */ do\n         {\n            uLong b = ps->IDAT_crc;\n            unsigned int shift = (IDAT_len - IDAT_pos); /* 4..1 */\n            ++IDAT_pos;\n\n            if (shift > 1U)\n               b >>= 8U*(shift-1U);\n\n            *pb++ = 0xffU & b;\n         }\n         while (--st > 0 && IDAT_pos < IDAT_len);\n\n         ps->IDAT_pos = IDAT_pos;\n         ps->IDAT_len = IDAT_len;\n         ps->IDAT_size = IDAT_size;\n      }\n\n      else /* !IDAT */\n      {\n         /* If there is still some pending IDAT data after the IDAT chunks have\n          * been processed there is a problem:\n          */\n         if (ps->IDAT_len > 0 && ps->IDAT_size > 0)\n            png_error(ps->pread, \"internal: missing IDAT data\");\n\n         if (chunktype == CHUNK_IEND && ps->IDAT_len == 0U)\n            png_error(ps->pread, \"internal: missing IDAT\");\n\n         if (chunkpos < 8U) /* Return the header */ do\n         {\n            png_uint_32 b;\n            unsigned int shift;\n\n            if (chunkpos < 4U)\n               b = chunklen - 12U;\n\n            else\n               b = chunktype;\n\n            shift = 3U & chunkpos;\n            ++chunkpos;\n\n            if (shift < 3U)\n               b >>= 8U*(3U-shift);\n\n            *pb++ = 0xffU & b;\n         }\n         while (--st > 0 && chunkpos < 8);\n\n         else /* Return chunk bytes, including the CRC */\n         {\n            png_size_t avail = st;\n\n            if (avail > chunklen - chunkpos)\n               avail = (png_size_t)/*SAFE*/(chunklen - chunkpos);\n\n            store_read_imp(ps, pb, avail);\n            pb += avail;\n            st -= avail;\n            chunkpos += (png_uint_32)/*SAFE*/avail;\n\n            /* Check for end of chunk and end-of-file; don't try to read a new\n             * chunk header at this point unless instructed to do so by 'min'.\n             */\n            if (chunkpos >= chunklen && max-st >= min &&\n                     store_read_buffer_avail(ps) == 0)\n               break;\n         }\n      } /* !IDAT */\n   }\n   while (st > 0);\n\n   ps->chunklen = chunklen;\n   ps->chunktype = chunktype;\n   ps->chunkpos = chunkpos;\n\n   return st; /* space left */\n}\n\nstatic void PNGCBAPI\nstore_read(png_structp ppIn, png_bytep pb, png_size_t st)\n{\n   png_const_structp pp = ppIn;\n   png_store *ps = voidcast(png_store*, png_get_io_ptr(pp));\n\n   if (ps == NULL || ps->pread != pp)\n      png_error(pp, \"bad store read call\");\n\n   store_read_chunk(ps, pb, st, st);\n}\n\nstatic void\nstore_progressive_read(png_store *ps, png_structp pp, png_infop pi)\n{\n   if (ps->pread != pp || ps->current == NULL || ps->next == NULL)\n      png_error(pp, \"store state damaged (progressive)\");\n\n   /* This is another Horowitz and Hill random noise generator.  In this case\n    * the aim is to stress the progressive reader with truly horrible variable\n    * buffer sizes in the range 1..500, so a sequence of 9 bit random numbers\n    * is generated.  We could probably just count from 1 to 32767 and get as\n    * good a result.\n    */\n   while (store_read_buffer_avail(ps) > 0)\n   {\n      static png_uint_32 noise = 2;\n      png_size_t cb;\n      png_byte buffer[512];\n\n      /* Generate 15 more bits of stuff: */\n      noise = (noise << 9) | ((noise ^ (noise >> (9-5))) & 0x1ff);\n      cb = noise & 0x1ff;\n      cb -= store_read_chunk(ps, buffer, cb, 1);\n      png_process_data(pp, pi, buffer, cb);\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* The caller must fill this in: */\nstatic store_palette_entry *\nstore_write_palette(png_store *ps, int npalette)\n{\n   if (ps->pwrite == NULL)\n      store_log(ps, NULL, \"attempt to write palette without write stream\", 1);\n\n   if (ps->palette != NULL)\n      png_error(ps->pwrite, \"multiple store_write_palette calls\");\n\n   /* This function can only return NULL if called with '0'! */\n   if (npalette > 0)\n   {\n      ps->palette = voidcast(store_palette_entry*, malloc(npalette *\n         sizeof *ps->palette));\n\n      if (ps->palette == NULL)\n         png_error(ps->pwrite, \"store new palette: OOM\");\n\n      ps->npalette = npalette;\n   }\n\n   return ps->palette;\n}\n\n#ifdef PNG_READ_SUPPORTED\nstatic store_palette_entry *\nstore_current_palette(png_store *ps, int *npalette)\n{\n   /* This is an internal error (the call has been made outside a read\n    * operation.)\n    */\n   if (ps->current == NULL)\n   {\n      store_log(ps, ps->pread, \"no current stream for palette\", 1);\n      return NULL;\n   }\n\n   /* The result may be null if there is no palette. */\n   *npalette = ps->current->npalette;\n   return ps->current->palette;\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/***************************** MEMORY MANAGEMENT*** ***************************/\n#ifdef PNG_USER_MEM_SUPPORTED\n/* A store_memory is simply the header for an allocated block of memory.  The\n * pointer returned to libpng is just after the end of the header block, the\n * allocated memory is followed by a second copy of the 'mark'.\n */\ntypedef struct store_memory\n{\n   store_pool          *pool;    /* Originating pool */\n   struct store_memory *next;    /* Singly linked list */\n   png_alloc_size_t     size;    /* Size of memory allocated */\n   png_byte             mark[4]; /* ID marker */\n} store_memory;\n\n/* Handle a fatal error in memory allocation.  This calls png_error if the\n * libpng struct is non-NULL, else it outputs a message and returns.  This means\n * that a memory problem while libpng is running will abort (png_error) the\n * handling of particular file while one in cleanup (after the destroy of the\n * struct has returned) will simply keep going and free (or attempt to free)\n * all the memory.\n */\nstatic void\nstore_pool_error(png_store *ps, png_const_structp pp, const char *msg)\n{\n   if (pp != NULL)\n      png_error(pp, msg);\n\n   /* Else we have to do it ourselves.  png_error eventually calls store_log,\n    * above.  store_log accepts a NULL png_structp - it just changes what gets\n    * output by store_message.\n    */\n   store_log(ps, pp, msg, 1 /* error */);\n}\n\nstatic void\nstore_memory_free(png_const_structp pp, store_pool *pool, store_memory *memory)\n{\n   /* Note that pp may be NULL (see store_pool_delete below), the caller has\n    * found 'memory' in pool->list *and* unlinked this entry, so this is a valid\n    * pointer (for sure), but the contents may have been trashed.\n    */\n   if (memory->pool != pool)\n      store_pool_error(pool->store, pp, \"memory corrupted (pool)\");\n\n   else if (memcmp(memory->mark, pool->mark, sizeof memory->mark) != 0)\n      store_pool_error(pool->store, pp, \"memory corrupted (start)\");\n\n   /* It should be safe to read the size field now. */\n   else\n   {\n      png_alloc_size_t cb = memory->size;\n\n      if (cb > pool->max)\n         store_pool_error(pool->store, pp, \"memory corrupted (size)\");\n\n      else if (memcmp((png_bytep)(memory+1)+cb, pool->mark, sizeof pool->mark)\n         != 0)\n         store_pool_error(pool->store, pp, \"memory corrupted (end)\");\n\n      /* Finally give the library a chance to find problems too: */\n      else\n         {\n         pool->current -= cb;\n         free(memory);\n         }\n   }\n}\n\nstatic void\nstore_pool_delete(png_store *ps, store_pool *pool)\n{\n   if (pool->list != NULL)\n   {\n      fprintf(stderr, \"%s: %s %s: memory lost (list follows):\\n\", ps->test,\n         pool == &ps->read_memory_pool ? \"read\" : \"write\",\n         pool == &ps->read_memory_pool ? (ps->current != NULL ?\n            ps->current->name : \"unknown file\") : ps->wname);\n      ++ps->nerrors;\n\n      do\n      {\n         store_memory *next = pool->list;\n         pool->list = next->next;\n         next->next = NULL;\n\n         fprintf(stderr, \"\\t%lu bytes @ %p\\n\",\n             (unsigned long)next->size, (const void*)(next+1));\n         /* The NULL means this will always return, even if the memory is\n          * corrupted.\n          */\n         store_memory_free(NULL, pool, next);\n      }\n      while (pool->list != NULL);\n   }\n\n   /* And reset the other fields too for the next time. */\n   if (pool->max > pool->max_max) pool->max_max = pool->max;\n   pool->max = 0;\n   if (pool->current != 0) /* unexpected internal error */\n      fprintf(stderr, \"%s: %s %s: memory counter mismatch (internal error)\\n\",\n         ps->test, pool == &ps->read_memory_pool ? \"read\" : \"write\",\n         pool == &ps->read_memory_pool ? (ps->current != NULL ?\n            ps->current->name : \"unknown file\") : ps->wname);\n   pool->current = 0;\n\n   if (pool->limit > pool->max_limit)\n      pool->max_limit = pool->limit;\n\n   pool->limit = 0;\n\n   if (pool->total > pool->max_total)\n      pool->max_total = pool->total;\n\n   pool->total = 0;\n\n   /* Get a new mark too. */\n   store_pool_mark(pool->mark);\n}\n\n/* The memory callbacks: */\nstatic png_voidp PNGCBAPI\nstore_malloc(png_structp ppIn, png_alloc_size_t cb)\n{\n   png_const_structp pp = ppIn;\n   store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp));\n   store_memory *new = voidcast(store_memory*, malloc(cb + (sizeof *new) +\n      (sizeof pool->mark)));\n\n   if (new != NULL)\n   {\n      if (cb > pool->max)\n         pool->max = cb;\n\n      pool->current += cb;\n\n      if (pool->current > pool->limit)\n         pool->limit = pool->current;\n\n      pool->total += cb;\n\n      new->size = cb;\n      memcpy(new->mark, pool->mark, sizeof new->mark);\n      memcpy((png_byte*)(new+1) + cb, pool->mark, sizeof pool->mark);\n      new->pool = pool;\n      new->next = pool->list;\n      pool->list = new;\n      ++new;\n   }\n\n   else\n   {\n      /* NOTE: the PNG user malloc function cannot use the png_ptr it is passed\n       * other than to retrieve the allocation pointer!  libpng calls the\n       * store_malloc callback in two basic cases:\n       *\n       * 1) From png_malloc; png_malloc will do a png_error itself if NULL is\n       *    returned.\n       * 2) From png_struct or png_info structure creation; png_malloc is\n       *    to return so cleanup can be performed.\n       *\n       * To handle this store_malloc can log a message, but can't do anything\n       * else.\n       */\n      store_log(pool->store, pp, \"out of memory\", 1 /* is_error */);\n   }\n\n   return new;\n}\n\nstatic void PNGCBAPI\nstore_free(png_structp ppIn, png_voidp memory)\n{\n   png_const_structp pp = ppIn;\n   store_pool *pool = voidcast(store_pool*, png_get_mem_ptr(pp));\n   store_memory *this = voidcast(store_memory*, memory), **test;\n\n   /* Because libpng calls store_free with a dummy png_struct when deleting\n    * png_struct or png_info via png_destroy_struct_2 it is necessary to check\n    * the passed in png_structp to ensure it is valid, and not pass it to\n    * png_error if it is not.\n    */\n   if (pp != pool->store->pread && pp != pool->store->pwrite)\n      pp = NULL;\n\n   /* First check that this 'memory' really is valid memory - it must be in the\n    * pool list.  If it is, use the shared memory_free function to free it.\n    */\n   --this;\n   for (test = &pool->list; *test != this; test = &(*test)->next)\n   {\n      if (*test == NULL)\n      {\n         store_pool_error(pool->store, pp, \"bad pointer to free\");\n         return;\n      }\n   }\n\n   /* Unlink this entry, *test == this. */\n   *test = this->next;\n   this->next = NULL;\n   store_memory_free(pp, pool, this);\n}\n#endif /* PNG_USER_MEM_SUPPORTED */\n\n/* Setup functions. */\n/* Cleanup when aborting a write or after storing the new file. */\nstatic void\nstore_write_reset(png_store *ps)\n{\n   if (ps->pwrite != NULL)\n   {\n      anon_context(ps);\n\n      Try\n         png_destroy_write_struct(&ps->pwrite, &ps->piwrite);\n\n      Catch_anonymous\n      {\n         /* memory corruption: continue. */\n      }\n\n      ps->pwrite = NULL;\n      ps->piwrite = NULL;\n   }\n\n   /* And make sure that all the memory has been freed - this will output\n    * spurious errors in the case of memory corruption above, but this is safe.\n    */\n#  ifdef PNG_USER_MEM_SUPPORTED\n      store_pool_delete(ps, &ps->write_memory_pool);\n#  endif\n\n   store_freenew(ps);\n}\n\n/* The following is the main write function, it returns a png_struct and,\n * optionally, a png_info suitable for writiing a new PNG file.  Use\n * store_storefile above to record this file after it has been written.  The\n * returned libpng structures as destroyed by store_write_reset above.\n */\nstatic png_structp\nset_store_for_write(png_store *ps, png_infopp ppi, const char *name)\n{\n   anon_context(ps);\n\n   Try\n   {\n      if (ps->pwrite != NULL)\n         png_error(ps->pwrite, \"write store already in use\");\n\n      store_write_reset(ps);\n      safecat(ps->wname, sizeof ps->wname, 0, name);\n\n      /* Don't do the slow memory checks if doing a speed test, also if user\n       * memory is not supported we can't do it anyway.\n       */\n#     ifdef PNG_USER_MEM_SUPPORTED\n         if (!ps->speed)\n            ps->pwrite = png_create_write_struct_2(PNG_LIBPNG_VER_STRING,\n               ps, store_error, store_warning, &ps->write_memory_pool,\n               store_malloc, store_free);\n\n         else\n#     endif\n         ps->pwrite = png_create_write_struct(PNG_LIBPNG_VER_STRING,\n            ps, store_error, store_warning);\n\n      png_set_write_fn(ps->pwrite, ps, store_write, store_flush);\n\n#     ifdef PNG_SET_OPTION_SUPPORTED\n         {\n            int opt;\n            for (opt=0; opt<ps->noptions; ++opt)\n               if (png_set_option(ps->pwrite, ps->options[opt].option,\n                  ps->options[opt].setting) == PNG_OPTION_INVALID)\n                  png_error(ps->pwrite, \"png option invalid\");\n         }\n#     endif\n\n      if (ppi != NULL)\n         *ppi = ps->piwrite = png_create_info_struct(ps->pwrite);\n   }\n\n   Catch_anonymous\n      return NULL;\n\n   return ps->pwrite;\n}\n\n/* Cleanup when finished reading (either due to error or in the success case).\n * This routine exists even when there is no read support to make the code\n * tidier (avoid a mass of ifdefs) and so easier to maintain.\n */\nstatic void\nstore_read_reset(png_store *ps)\n{\n#  ifdef PNG_READ_SUPPORTED\n      if (ps->pread != NULL)\n      {\n         anon_context(ps);\n\n         Try\n            png_destroy_read_struct(&ps->pread, &ps->piread, NULL);\n\n         Catch_anonymous\n         {\n            /* error already output: continue */\n         }\n\n         ps->pread = NULL;\n         ps->piread = NULL;\n      }\n#  endif\n\n#  ifdef PNG_USER_MEM_SUPPORTED\n      /* Always do this to be safe. */\n      store_pool_delete(ps, &ps->read_memory_pool);\n#  endif\n\n   ps->current = NULL;\n   ps->next = NULL;\n   ps->readpos = 0;\n   ps->validated = 0;\n\n   ps->chunkpos = 8;\n   ps->chunktype = 0;\n   ps->chunklen = 16;\n   ps->IDAT_size = 0;\n}\n\n#ifdef PNG_READ_SUPPORTED\nstatic void\nstore_read_set(png_store *ps, png_uint_32 id)\n{\n   png_store_file *pf = ps->saved;\n\n   while (pf != NULL)\n   {\n      if (pf->id == id)\n      {\n         ps->current = pf;\n         ps->next = NULL;\n         ps->IDAT_size = pf->IDAT_size;\n         ps->IDAT_bits = pf->IDAT_bits; /* just a cache */\n         ps->IDAT_len = 0;\n         ps->IDAT_pos = 0;\n         ps->IDAT_crc = 0UL;\n         store_read_buffer_next(ps);\n         return;\n      }\n\n      pf = pf->next;\n   }\n\n   {\n      size_t pos;\n      char msg[FILE_NAME_SIZE+64];\n\n      pos = standard_name_from_id(msg, sizeof msg, 0, id);\n      pos = safecat(msg, sizeof msg, pos, \": file not found\");\n      png_error(ps->pread, msg);\n   }\n}\n\n/* The main interface for reading a saved file - pass the id number of the file\n * to retrieve.  Ids must be unique or the earlier file will be hidden.  The API\n * returns a png_struct and, optionally, a png_info.  Both of these will be\n * destroyed by store_read_reset above.\n */\nstatic png_structp\nset_store_for_read(png_store *ps, png_infopp ppi, png_uint_32 id,\n   const char *name)\n{\n   /* Set the name for png_error */\n   safecat(ps->test, sizeof ps->test, 0, name);\n\n   if (ps->pread != NULL)\n      png_error(ps->pread, \"read store already in use\");\n\n   store_read_reset(ps);\n\n   /* Both the create APIs can return NULL if used in their default mode\n    * (because there is no other way of handling an error because the jmp_buf\n    * by default is stored in png_struct and that has not been allocated!)\n    * However, given that store_error works correctly in these circumstances\n    * we don't ever expect NULL in this program.\n    */\n#  ifdef PNG_USER_MEM_SUPPORTED\n      if (!ps->speed)\n         ps->pread = png_create_read_struct_2(PNG_LIBPNG_VER_STRING, ps,\n             store_error, store_warning, &ps->read_memory_pool, store_malloc,\n             store_free);\n\n      else\n#  endif\n   ps->pread = png_create_read_struct(PNG_LIBPNG_VER_STRING, ps, store_error,\n      store_warning);\n\n   if (ps->pread == NULL)\n   {\n      struct exception_context *the_exception_context = &ps->exception_context;\n\n      store_log(ps, NULL, \"png_create_read_struct returned NULL (unexpected)\",\n         1 /*error*/);\n\n      Throw ps;\n   }\n\n#  ifdef PNG_SET_OPTION_SUPPORTED\n      {\n         int opt;\n         for (opt=0; opt<ps->noptions; ++opt)\n            if (png_set_option(ps->pread, ps->options[opt].option,\n               ps->options[opt].setting) == PNG_OPTION_INVALID)\n                  png_error(ps->pread, \"png option invalid\");\n      }\n#  endif\n\n   store_read_set(ps, id);\n\n   if (ppi != NULL)\n      *ppi = ps->piread = png_create_info_struct(ps->pread);\n\n   return ps->pread;\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* The overall cleanup of a store simply calls the above then removes all the\n * saved files.  This does not delete the store itself.\n */\nstatic void\nstore_delete(png_store *ps)\n{\n   store_write_reset(ps);\n   store_read_reset(ps);\n   store_freefile(&ps->saved);\n   store_image_free(ps, NULL);\n}\n\n/*********************** PNG FILE MODIFICATION ON READ ************************/\n/* Files may be modified on read.  The following structure contains a complete\n * png_store together with extra members to handle modification and a special\n * read callback for libpng.  To use this the 'modifications' field must be set\n * to a list of png_modification structures that actually perform the\n * modification, otherwise a png_modifier is functionally equivalent to a\n * png_store.  There is a special read function, set_modifier_for_read, which\n * replaces set_store_for_read.\n */\ntypedef enum modifier_state\n{\n   modifier_start,                        /* Initial value */\n   modifier_signature,                    /* Have a signature */\n   modifier_IHDR                          /* Have an IHDR */\n} modifier_state;\n\ntypedef struct CIE_color\n{\n   /* A single CIE tristimulus value, representing the unique response of a\n    * standard observer to a variety of light spectra.  The observer recognizes\n    * all spectra that produce this response as the same color, therefore this\n    * is effectively a description of a color.\n    */\n   double X, Y, Z;\n} CIE_color;\n\ntypedef struct color_encoding\n{\n   /* A description of an (R,G,B) encoding of color (as defined above); this\n    * includes the actual colors of the (R,G,B) triples (1,0,0), (0,1,0) and\n    * (0,0,1) plus an encoding value that is used to encode the linear\n    * components R, G and B to give the actual values R^gamma, G^gamma and\n    * B^gamma that are stored.\n    */\n   double    gamma;            /* Encoding (file) gamma of space */\n   CIE_color red, green, blue; /* End points */\n} color_encoding;\n\n#ifdef PNG_READ_SUPPORTED\n#if defined PNG_READ_TRANSFORMS_SUPPORTED && defined PNG_READ_cHRM_SUPPORTED\nstatic double\nchromaticity_x(CIE_color c)\n{\n   return c.X / (c.X + c.Y + c.Z);\n}\n\nstatic double\nchromaticity_y(CIE_color c)\n{\n   return c.Y / (c.X + c.Y + c.Z);\n}\n\nstatic CIE_color\nwhite_point(const color_encoding *encoding)\n{\n   CIE_color white;\n\n   white.X = encoding->red.X + encoding->green.X + encoding->blue.X;\n   white.Y = encoding->red.Y + encoding->green.Y + encoding->blue.Y;\n   white.Z = encoding->red.Z + encoding->green.Z + encoding->blue.Z;\n\n   return white;\n}\n#endif /* READ_TRANSFORMS && READ_cHRM */\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\nstatic void\nnormalize_color_encoding(color_encoding *encoding)\n{\n   const double whiteY = encoding->red.Y + encoding->green.Y +\n      encoding->blue.Y;\n\n   if (whiteY != 1)\n   {\n      encoding->red.X /= whiteY;\n      encoding->red.Y /= whiteY;\n      encoding->red.Z /= whiteY;\n      encoding->green.X /= whiteY;\n      encoding->green.Y /= whiteY;\n      encoding->green.Z /= whiteY;\n      encoding->blue.X /= whiteY;\n      encoding->blue.Y /= whiteY;\n      encoding->blue.Z /= whiteY;\n   }\n}\n#endif\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nstatic size_t\nsafecat_color_encoding(char *buffer, size_t bufsize, size_t pos,\n   const color_encoding *e, double encoding_gamma)\n{\n   if (e != 0)\n   {\n      if (encoding_gamma != 0)\n         pos = safecat(buffer, bufsize, pos, \"(\");\n      pos = safecat(buffer, bufsize, pos, \"R(\");\n      pos = safecatd(buffer, bufsize, pos, e->red.X, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->red.Y, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->red.Z, 4);\n      pos = safecat(buffer, bufsize, pos, \"),G(\");\n      pos = safecatd(buffer, bufsize, pos, e->green.X, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->green.Y, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->green.Z, 4);\n      pos = safecat(buffer, bufsize, pos, \"),B(\");\n      pos = safecatd(buffer, bufsize, pos, e->blue.X, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->blue.Y, 4);\n      pos = safecat(buffer, bufsize, pos, \",\");\n      pos = safecatd(buffer, bufsize, pos, e->blue.Z, 4);\n      pos = safecat(buffer, bufsize, pos, \")\");\n      if (encoding_gamma != 0)\n         pos = safecat(buffer, bufsize, pos, \")\");\n   }\n\n   if (encoding_gamma != 0)\n   {\n      pos = safecat(buffer, bufsize, pos, \"^\");\n      pos = safecatd(buffer, bufsize, pos, encoding_gamma, 5);\n   }\n\n   return pos;\n}\n#endif /* READ_TRANSFORMS */\n#endif /* PNG_READ_SUPPORTED */\n\ntypedef struct png_modifier\n{\n   png_store               this;             /* I am a png_store */\n   struct png_modification *modifications;   /* Changes to make */\n\n   modifier_state           state;           /* My state */\n\n   /* Information from IHDR: */\n   png_byte                 bit_depth;       /* From IHDR */\n   png_byte                 colour_type;     /* From IHDR */\n\n   /* While handling PLTE, IDAT and IEND these chunks may be pended to allow\n    * other chunks to be inserted.\n    */\n   png_uint_32              pending_len;\n   png_uint_32              pending_chunk;\n\n   /* Test values */\n   double                   *gammas;\n   unsigned int              ngammas;\n   unsigned int              ngamma_tests;     /* Number of gamma tests to run*/\n   double                    current_gamma;    /* 0 if not set */\n   const color_encoding *encodings;\n   unsigned int              nencodings;\n   const color_encoding *current_encoding; /* If an encoding has been set */\n   unsigned int              encoding_counter; /* For iteration */\n   int                       encoding_ignored; /* Something overwrote it */\n\n   /* Control variables used to iterate through possible encodings, the\n    * following must be set to 0 and tested by the function that uses the\n    * png_modifier because the modifier only sets it to 1 (true.)\n    */\n   unsigned int              repeat :1;   /* Repeat this transform test. */\n   unsigned int              test_uses_encoding :1;\n\n   /* Lowest sbit to test (pre-1.7 libpng fails for sbit < 8) */\n   png_byte                 sbitlow;\n\n   /* Error control - these are the limits on errors accepted by the gamma tests\n    * below.\n    */\n   double                   maxout8;  /* Maximum output value error */\n   double                   maxabs8;  /* Absolute sample error 0..1 */\n   double                   maxcalc8; /* Absolute sample error 0..1 */\n   double                   maxpc8;   /* Percentage sample error 0..100% */\n   double                   maxout16; /* Maximum output value error */\n   double                   maxabs16; /* Absolute sample error 0..1 */\n   double                   maxcalc16;/* Absolute sample error 0..1 */\n   double                   maxcalcG; /* Absolute sample error 0..1 */\n   double                   maxpc16;  /* Percentage sample error 0..100% */\n\n   /* This is set by transforms that need to allow a higher limit, it is an\n    * internal check on pngvalid to ensure that the calculated error limits are\n    * not ridiculous; without this it is too easy to make a mistake in pngvalid\n    * that allows any value through.\n    *\n    * NOTE: this is not checked in release builds.\n    */\n   double                   limit;    /* limit on error values, normally 4E-3 */\n\n   /* Log limits - values above this are logged, but not necessarily\n    * warned.\n    */\n   double                   log8;     /* Absolute error in 8 bits to log */\n   double                   log16;    /* Absolute error in 16 bits to log */\n\n   /* Logged 8 and 16 bit errors ('output' values): */\n   double                   error_gray_2;\n   double                   error_gray_4;\n   double                   error_gray_8;\n   double                   error_gray_16;\n   double                   error_color_8;\n   double                   error_color_16;\n   double                   error_indexed;\n\n   /* Flags: */\n   /* Whether to call png_read_update_info, not png_read_start_image, and how\n    * many times to call it.\n    */\n   int                      use_update_info;\n\n   /* Whether or not to interlace. */\n   int                      interlace_type :9; /* int, but must store '1' */\n\n   /* Run the standard tests? */\n   unsigned int             test_standard :1;\n\n   /* Run the odd-sized image and interlace read/write tests? */\n   unsigned int             test_size :1;\n\n   /* Run tests on reading with a combination of transforms, */\n   unsigned int             test_transform :1;\n   unsigned int             test_tRNS :1; /* Includes tRNS images */\n\n   /* When to use the use_input_precision option, this controls the gamma\n    * validation code checks.  If set any value that is within the transformed\n    * range input-.5 to input+.5 will be accepted, otherwise the value must be\n    * within the normal limits.  It should not be necessary to set this; the\n    * result should always be exact within the permitted error limits.\n    */\n   unsigned int             use_input_precision :1;\n   unsigned int             use_input_precision_sbit :1;\n   unsigned int             use_input_precision_16to8 :1;\n\n   /* If set assume that the calculation bit depth is set by the input\n    * precision, not the output precision.\n    */\n   unsigned int             calculations_use_input_precision :1;\n\n   /* If set assume that the calculations are done in 16 bits even if the sample\n    * depth is 8 bits.\n    */\n   unsigned int             assume_16_bit_calculations :1;\n\n   /* Which gamma tests to run: */\n   unsigned int             test_gamma_threshold :1;\n   unsigned int             test_gamma_transform :1; /* main tests */\n   unsigned int             test_gamma_sbit :1;\n   unsigned int             test_gamma_scale16 :1;\n   unsigned int             test_gamma_background :1;\n   unsigned int             test_gamma_alpha_mode :1;\n   unsigned int             test_gamma_expand16 :1;\n   unsigned int             test_exhaustive :1;\n\n   /* Whether or not to run the low-bit-depth grayscale tests.  This fails on\n    * gamma images in some cases because of gross inaccuracies in the grayscale\n    * gamma handling for low bit depth.\n    */\n   unsigned int             test_lbg :1;\n   unsigned int             test_lbg_gamma_threshold :1;\n   unsigned int             test_lbg_gamma_transform :1;\n   unsigned int             test_lbg_gamma_sbit :1;\n   unsigned int             test_lbg_gamma_composition :1;\n\n   unsigned int             log :1;   /* Log max error */\n\n   /* Buffer information, the buffer size limits the size of the chunks that can\n    * be modified - they must fit (including header and CRC) into the buffer!\n    */\n   size_t                   flush;           /* Count of bytes to flush */\n   size_t                   buffer_count;    /* Bytes in buffer */\n   size_t                   buffer_position; /* Position in buffer */\n   png_byte                 buffer[1024];\n} png_modifier;\n\n/* This returns true if the test should be stopped now because it has already\n * failed and it is running silently.\n  */\nstatic int fail(png_modifier *pm)\n{\n   return !pm->log && !pm->this.verbose && (pm->this.nerrors > 0 ||\n       (pm->this.treat_warnings_as_errors && pm->this.nwarnings > 0));\n}\n\nstatic void\nmodifier_init(png_modifier *pm)\n{\n   memset(pm, 0, sizeof *pm);\n   store_init(&pm->this);\n   pm->modifications = NULL;\n   pm->state = modifier_start;\n   pm->sbitlow = 1U;\n   pm->ngammas = 0;\n   pm->ngamma_tests = 0;\n   pm->gammas = 0;\n   pm->current_gamma = 0;\n   pm->encodings = 0;\n   pm->nencodings = 0;\n   pm->current_encoding = 0;\n   pm->encoding_counter = 0;\n   pm->encoding_ignored = 0;\n   pm->repeat = 0;\n   pm->test_uses_encoding = 0;\n   pm->maxout8 = pm->maxpc8 = pm->maxabs8 = pm->maxcalc8 = 0;\n   pm->maxout16 = pm->maxpc16 = pm->maxabs16 = pm->maxcalc16 = 0;\n   pm->maxcalcG = 0;\n   pm->limit = 4E-3;\n   pm->log8 = pm->log16 = 0; /* Means 'off' */\n   pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = 0;\n   pm->error_gray_16 = pm->error_color_8 = pm->error_color_16 = 0;\n   pm->error_indexed = 0;\n   pm->use_update_info = 0;\n   pm->interlace_type = PNG_INTERLACE_NONE;\n   pm->test_standard = 0;\n   pm->test_size = 0;\n   pm->test_transform = 0;\n#  ifdef PNG_WRITE_tRNS_SUPPORTED\n      pm->test_tRNS = 1;\n#  else\n      pm->test_tRNS = 0;\n#  endif\n   pm->use_input_precision = 0;\n   pm->use_input_precision_sbit = 0;\n   pm->use_input_precision_16to8 = 0;\n   pm->calculations_use_input_precision = 0;\n   pm->assume_16_bit_calculations = 0;\n   pm->test_gamma_threshold = 0;\n   pm->test_gamma_transform = 0;\n   pm->test_gamma_sbit = 0;\n   pm->test_gamma_scale16 = 0;\n   pm->test_gamma_background = 0;\n   pm->test_gamma_alpha_mode = 0;\n   pm->test_gamma_expand16 = 0;\n   pm->test_lbg = 1;\n   pm->test_lbg_gamma_threshold = 1;\n   pm->test_lbg_gamma_transform = 1;\n   pm->test_lbg_gamma_sbit = 1;\n   pm->test_lbg_gamma_composition = 1;\n   pm->test_exhaustive = 0;\n   pm->log = 0;\n\n   /* Rely on the memset for all the other fields - there are no pointers */\n}\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n\n/* This controls use of checks that explicitly know how libpng digitizes the\n * samples in calculations; setting this circumvents simple error limit checking\n * in the rgb_to_gray check, replacing it with an exact copy of the libpng 1.5\n * algorithm.\n */\n#define DIGITIZE PNG_LIBPNG_VER < 10700\n\n/* If pm->calculations_use_input_precision is set then operations will happen\n * with the precision of the input, not the precision of the output depth.\n *\n * If pm->assume_16_bit_calculations is set then even 8 bit calculations use 16\n * bit precision.  This only affects those of the following limits that pertain\n * to a calculation - not a digitization operation - unless the following API is\n * called directly.\n */\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n#if DIGITIZE\nstatic double digitize(double value, int depth, int do_round)\n{\n   /* 'value' is in the range 0 to 1, the result is the same value rounded to a\n    * multiple of the digitization factor - 8 or 16 bits depending on both the\n    * sample depth and the 'assume' setting.  Digitization is normally by\n    * rounding and 'do_round' should be 1, if it is 0 the digitized value will\n    * be truncated.\n    */\n   const unsigned int digitization_factor = (1U << depth) -1;\n\n   /* Limiting the range is done as a convenience to the caller - it's easier to\n    * do it once here than every time at the call site.\n    */\n   if (value <= 0)\n      value = 0;\n\n   else if (value >= 1)\n      value = 1;\n\n   value *= digitization_factor;\n   if (do_round) value += .5;\n   return floor(value)/digitization_factor;\n}\n#endif\n#endif /* RGB_TO_GRAY */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\nstatic double abserr(const png_modifier *pm, int in_depth, int out_depth)\n{\n   /* Absolute error permitted in linear values - affected by the bit depth of\n    * the calculations.\n    */\n   if (pm->assume_16_bit_calculations ||\n      (pm->calculations_use_input_precision ? in_depth : out_depth) == 16)\n      return pm->maxabs16;\n   else\n      return pm->maxabs8;\n}\n\nstatic double calcerr(const png_modifier *pm, int in_depth, int out_depth)\n{\n   /* Error in the linear composition arithmetic - only relevant when\n    * composition actually happens (0 < alpha < 1).\n    */\n   if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)\n      return pm->maxcalc16;\n   else if (pm->assume_16_bit_calculations)\n      return pm->maxcalcG;\n   else\n      return pm->maxcalc8;\n}\n\nstatic double pcerr(const png_modifier *pm, int in_depth, int out_depth)\n{\n   /* Percentage error permitted in the linear values.  Note that the specified\n    * value is a percentage but this routine returns a simple number.\n    */\n   if (pm->assume_16_bit_calculations ||\n      (pm->calculations_use_input_precision ? in_depth : out_depth) == 16)\n      return pm->maxpc16 * .01;\n   else\n      return pm->maxpc8 * .01;\n}\n\n/* Output error - the error in the encoded value.  This is determined by the\n * digitization of the output so can be +/-0.5 in the actual output value.  In\n * the expand_16 case with the current code in libpng the expand happens after\n * all the calculations are done in 8 bit arithmetic, so even though the output\n * depth is 16 the output error is determined by the 8 bit calculation.\n *\n * This limit is not determined by the bit depth of internal calculations.\n *\n * The specified parameter does *not* include the base .5 digitization error but\n * it is added here.\n */\nstatic double outerr(const png_modifier *pm, int in_depth, int out_depth)\n{\n   /* There is a serious error in the 2 and 4 bit grayscale transform because\n    * the gamma table value (8 bits) is simply shifted, not rounded, so the\n    * error in 4 bit grayscale gamma is up to the value below.  This is a hack\n    * to allow pngvalid to succeed:\n    *\n    * TODO: fix this in libpng\n    */\n   if (out_depth == 2)\n      return .73182-.5;\n\n   if (out_depth == 4)\n      return .90644-.5;\n\n   if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)\n      return pm->maxout16;\n\n   /* This is the case where the value was calculated at 8-bit precision then\n    * scaled to 16 bits.\n    */\n   else if (out_depth == 16)\n      return pm->maxout8 * 257;\n\n   else\n      return pm->maxout8;\n}\n\n/* This does the same thing as the above however it returns the value to log,\n * rather than raising a warning.  This is useful for debugging to track down\n * exactly what set of parameters cause high error values.\n */\nstatic double outlog(const png_modifier *pm, int in_depth, int out_depth)\n{\n   /* The command line parameters are either 8 bit (0..255) or 16 bit (0..65535)\n    * and so must be adjusted for low bit depth grayscale:\n    */\n   if (out_depth <= 8)\n   {\n      if (pm->log8 == 0) /* switched off */\n         return 256;\n\n      if (out_depth < 8)\n         return pm->log8 / 255 * ((1<<out_depth)-1);\n\n      return pm->log8;\n   }\n\n   if ((pm->calculations_use_input_precision ? in_depth : out_depth) == 16)\n   {\n      if (pm->log16 == 0)\n         return 65536;\n\n      return pm->log16;\n   }\n\n   /* This is the case where the value was calculated at 8-bit precision then\n    * scaled to 16 bits.\n    */\n   if (pm->log8 == 0)\n      return 65536;\n\n   return pm->log8 * 257;\n}\n\n/* This complements the above by providing the appropriate quantization for the\n * final value.  Normally this would just be quantization to an integral value,\n * but in the 8 bit calculation case it's actually quantization to a multiple of\n * 257!\n */\nstatic int output_quantization_factor(const png_modifier *pm, int in_depth,\n   int out_depth)\n{\n   if (out_depth == 16 && in_depth != 16 &&\n      pm->calculations_use_input_precision)\n      return 257;\n   else\n      return 1;\n}\n#endif /* PNG_READ_GAMMA_SUPPORTED */\n\n/* One modification structure must be provided for each chunk to be modified (in\n * fact more than one can be provided if multiple separate changes are desired\n * for a single chunk.)  Modifications include adding a new chunk when a\n * suitable chunk does not exist.\n *\n * The caller of modify_fn will reset the CRC of the chunk and record 'modified'\n * or 'added' as appropriate if the modify_fn returns 1 (true).  If the\n * modify_fn is NULL the chunk is simply removed.\n */\ntypedef struct png_modification\n{\n   struct png_modification *next;\n   png_uint_32              chunk;\n\n   /* If the following is NULL all matching chunks will be removed: */\n   int                    (*modify_fn)(struct png_modifier *pm,\n                               struct png_modification *me, int add);\n\n   /* If the following is set to PLTE, IDAT or IEND and the chunk has not been\n    * found and modified (and there is a modify_fn) the modify_fn will be called\n    * to add the chunk before the relevant chunk.\n    */\n   png_uint_32              add;\n   unsigned int             modified :1;     /* Chunk was modified */\n   unsigned int             added    :1;     /* Chunk was added */\n   unsigned int             removed  :1;     /* Chunk was removed */\n} png_modification;\n\nstatic void\nmodification_reset(png_modification *pmm)\n{\n   if (pmm != NULL)\n   {\n      pmm->modified = 0;\n      pmm->added = 0;\n      pmm->removed = 0;\n      modification_reset(pmm->next);\n   }\n}\n\nstatic void\nmodification_init(png_modification *pmm)\n{\n   memset(pmm, 0, sizeof *pmm);\n   pmm->next = NULL;\n   pmm->chunk = 0;\n   pmm->modify_fn = NULL;\n   pmm->add = 0;\n   modification_reset(pmm);\n}\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\nstatic void\nmodifier_current_encoding(const png_modifier *pm, color_encoding *ce)\n{\n   if (pm->current_encoding != 0)\n      *ce = *pm->current_encoding;\n\n   else\n      memset(ce, 0, sizeof *ce);\n\n   ce->gamma = pm->current_gamma;\n}\n#endif\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nstatic size_t\nsafecat_current_encoding(char *buffer, size_t bufsize, size_t pos,\n   const png_modifier *pm)\n{\n   pos = safecat_color_encoding(buffer, bufsize, pos, pm->current_encoding,\n      pm->current_gamma);\n\n   if (pm->encoding_ignored)\n      pos = safecat(buffer, bufsize, pos, \"[overridden]\");\n\n   return pos;\n}\n#endif\n\n/* Iterate through the usefully testable color encodings.  An encoding is one\n * of:\n *\n * 1) Nothing (no color space, no gamma).\n * 2) Just a gamma value from the gamma array (including 1.0)\n * 3) A color space from the encodings array with the corresponding gamma.\n * 4) The same, but with gamma 1.0 (only really useful with 16 bit calculations)\n *\n * The iterator selects these in turn, the randomizer selects one at random,\n * which is used depends on the setting of the 'test_exhaustive' flag.  Notice\n * that this function changes the colour space encoding so it must only be\n * called on completion of the previous test.  This is what 'modifier_reset'\n * does, below.\n *\n * After the function has been called the 'repeat' flag will still be set; the\n * caller of modifier_reset must reset it at the start of each run of the test!\n */\nstatic unsigned int\nmodifier_total_encodings(const png_modifier *pm)\n{\n   return 1 +                 /* (1) nothing */\n      pm->ngammas +           /* (2) gamma values to test */\n      pm->nencodings +        /* (3) total number of encodings */\n      /* The following test only works after the first time through the\n       * png_modifier code because 'bit_depth' is set when the IHDR is read.\n       * modifier_reset, below, preserves the setting until after it has called\n       * the iterate function (also below.)\n       *\n       * For this reason do not rely on this function outside a call to\n       * modifier_reset.\n       */\n      ((pm->bit_depth == 16 || pm->assume_16_bit_calculations) ?\n         pm->nencodings : 0); /* (4) encodings with gamma == 1.0 */\n}\n\nstatic void\nmodifier_encoding_iterate(png_modifier *pm)\n{\n   if (!pm->repeat && /* Else something needs the current encoding again. */\n      pm->test_uses_encoding) /* Some transform is encoding dependent */\n   {\n      if (pm->test_exhaustive)\n      {\n         if (++pm->encoding_counter >= modifier_total_encodings(pm))\n            pm->encoding_counter = 0; /* This will stop the repeat */\n      }\n\n      else\n      {\n         /* Not exhaustive - choose an encoding at random; generate a number in\n          * the range 1..(max-1), so the result is always non-zero:\n          */\n         if (pm->encoding_counter == 0)\n            pm->encoding_counter = random_mod(modifier_total_encodings(pm)-1)+1;\n         else\n            pm->encoding_counter = 0;\n      }\n\n      if (pm->encoding_counter > 0)\n         pm->repeat = 1;\n   }\n\n   else if (!pm->repeat)\n      pm->encoding_counter = 0;\n}\n\nstatic void\nmodifier_reset(png_modifier *pm)\n{\n   store_read_reset(&pm->this);\n   pm->limit = 4E-3;\n   pm->pending_len = pm->pending_chunk = 0;\n   pm->flush = pm->buffer_count = pm->buffer_position = 0;\n   pm->modifications = NULL;\n   pm->state = modifier_start;\n   modifier_encoding_iterate(pm);\n   /* The following must be set in the next run.  In particular\n    * test_uses_encodings must be set in the _ini function of each transform\n    * that looks at the encodings.  (Not the 'add' function!)\n    */\n   pm->test_uses_encoding = 0;\n   pm->current_gamma = 0;\n   pm->current_encoding = 0;\n   pm->encoding_ignored = 0;\n   /* These only become value after IHDR is read: */\n   pm->bit_depth = pm->colour_type = 0;\n}\n\n/* The following must be called before anything else to get the encoding set up\n * on the modifier.  In particular it must be called before the transform init\n * functions are called.\n */\nstatic void\nmodifier_set_encoding(png_modifier *pm)\n{\n   /* Set the encoding to the one specified by the current encoding counter,\n    * first clear out all the settings - this corresponds to an encoding_counter\n    * of 0.\n    */\n   pm->current_gamma = 0;\n   pm->current_encoding = 0;\n   pm->encoding_ignored = 0; /* not ignored yet - happens in _ini functions. */\n\n   /* Now, if required, set the gamma and encoding fields. */\n   if (pm->encoding_counter > 0)\n   {\n      /* The gammas[] array is an array of screen gammas, not encoding gammas,\n       * so we need the inverse:\n       */\n      if (pm->encoding_counter <= pm->ngammas)\n         pm->current_gamma = 1/pm->gammas[pm->encoding_counter-1];\n\n      else\n      {\n         unsigned int i = pm->encoding_counter - pm->ngammas;\n\n         if (i >= pm->nencodings)\n         {\n            i %= pm->nencodings;\n            pm->current_gamma = 1; /* Linear, only in the 16 bit case */\n         }\n\n         else\n            pm->current_gamma = pm->encodings[i].gamma;\n\n         pm->current_encoding = pm->encodings + i;\n      }\n   }\n}\n\n/* Enquiry functions to find out what is set.  Notice that there is an implicit\n * assumption below that the first encoding in the list is the one for sRGB.\n */\nstatic int\nmodifier_color_encoding_is_sRGB(const png_modifier *pm)\n{\n   return pm->current_encoding != 0 && pm->current_encoding == pm->encodings &&\n      pm->current_encoding->gamma == pm->current_gamma;\n}\n\nstatic int\nmodifier_color_encoding_is_set(const png_modifier *pm)\n{\n   return pm->current_gamma != 0;\n}\n\n/* The guts of modification are performed during a read. */\nstatic void\nmodifier_crc(png_bytep buffer)\n{\n   /* Recalculate the chunk CRC - a complete chunk must be in\n    * the buffer, at the start.\n    */\n   uInt datalen = png_get_uint_32(buffer);\n   uLong crc = crc32(0, buffer+4, datalen+4);\n   /* The cast to png_uint_32 is safe because a crc32 is always a 32 bit value.\n    */\n   png_save_uint_32(buffer+datalen+8, (png_uint_32)crc);\n}\n\nstatic void\nmodifier_setbuffer(png_modifier *pm)\n{\n   modifier_crc(pm->buffer);\n   pm->buffer_count = png_get_uint_32(pm->buffer)+12;\n   pm->buffer_position = 0;\n}\n\n/* Separate the callback into the actual implementation (which is passed the\n * png_modifier explicitly) and the callback, which gets the modifier from the\n * png_struct.\n */\nstatic void\nmodifier_read_imp(png_modifier *pm, png_bytep pb, png_size_t st)\n{\n   while (st > 0)\n   {\n      size_t cb;\n      png_uint_32 len, chunk;\n      png_modification *mod;\n\n      if (pm->buffer_position >= pm->buffer_count) switch (pm->state)\n      {\n         static png_byte sign[8] = { 137, 80, 78, 71, 13, 10, 26, 10 };\n         case modifier_start:\n            store_read_chunk(&pm->this, pm->buffer, 8, 8); /* signature. */\n            pm->buffer_count = 8;\n            pm->buffer_position = 0;\n\n            if (memcmp(pm->buffer, sign, 8) != 0)\n               png_error(pm->this.pread, \"invalid PNG file signature\");\n            pm->state = modifier_signature;\n            break;\n\n         case modifier_signature:\n            store_read_chunk(&pm->this, pm->buffer, 13+12, 13+12); /* IHDR */\n            pm->buffer_count = 13+12;\n            pm->buffer_position = 0;\n\n            if (png_get_uint_32(pm->buffer) != 13 ||\n                png_get_uint_32(pm->buffer+4) != CHUNK_IHDR)\n               png_error(pm->this.pread, \"invalid IHDR\");\n\n            /* Check the list of modifiers for modifications to the IHDR. */\n            mod = pm->modifications;\n            while (mod != NULL)\n            {\n               if (mod->chunk == CHUNK_IHDR && mod->modify_fn &&\n                   (*mod->modify_fn)(pm, mod, 0))\n                  {\n                  mod->modified = 1;\n                  modifier_setbuffer(pm);\n                  }\n\n               /* Ignore removal or add if IHDR! */\n               mod = mod->next;\n            }\n\n            /* Cache information from the IHDR (the modified one.) */\n            pm->bit_depth = pm->buffer[8+8];\n            pm->colour_type = pm->buffer[8+8+1];\n\n            pm->state = modifier_IHDR;\n            pm->flush = 0;\n            break;\n\n         case modifier_IHDR:\n         default:\n            /* Read a new chunk and process it until we see PLTE, IDAT or\n             * IEND.  'flush' indicates that there is still some data to\n             * output from the preceding chunk.\n             */\n            if ((cb = pm->flush) > 0)\n            {\n               if (cb > st) cb = st;\n               pm->flush -= cb;\n               store_read_chunk(&pm->this, pb, cb, cb);\n               pb += cb;\n               st -= cb;\n               if (st == 0) return;\n            }\n\n            /* No more bytes to flush, read a header, or handle a pending\n             * chunk.\n             */\n            if (pm->pending_chunk != 0)\n            {\n               png_save_uint_32(pm->buffer, pm->pending_len);\n               png_save_uint_32(pm->buffer+4, pm->pending_chunk);\n               pm->pending_len = 0;\n               pm->pending_chunk = 0;\n            }\n            else\n               store_read_chunk(&pm->this, pm->buffer, 8, 8);\n\n            pm->buffer_count = 8;\n            pm->buffer_position = 0;\n\n            /* Check for something to modify or a terminator chunk. */\n            len = png_get_uint_32(pm->buffer);\n            chunk = png_get_uint_32(pm->buffer+4);\n\n            /* Terminators first, they may have to be delayed for added\n             * chunks\n             */\n            if (chunk == CHUNK_PLTE || chunk == CHUNK_IDAT ||\n                chunk == CHUNK_IEND)\n            {\n               mod = pm->modifications;\n\n               while (mod != NULL)\n               {\n                  if ((mod->add == chunk ||\n                      (mod->add == CHUNK_PLTE && chunk == CHUNK_IDAT)) &&\n                      mod->modify_fn != NULL && !mod->modified && !mod->added)\n                  {\n                     /* Regardless of what the modify function does do not run\n                      * this again.\n                      */\n                     mod->added = 1;\n\n                     if ((*mod->modify_fn)(pm, mod, 1 /*add*/))\n                     {\n                        /* Reset the CRC on a new chunk */\n                        if (pm->buffer_count > 0)\n                           modifier_setbuffer(pm);\n\n                        else\n                           {\n                           pm->buffer_position = 0;\n                           mod->removed = 1;\n                           }\n\n                        /* The buffer has been filled with something (we assume)\n                         * so output this.  Pend the current chunk.\n                         */\n                        pm->pending_len = len;\n                        pm->pending_chunk = chunk;\n                        break; /* out of while */\n                     }\n                  }\n\n                  mod = mod->next;\n               }\n\n               /* Don't do any further processing if the buffer was modified -\n                * otherwise the code will end up modifying a chunk that was\n                * just added.\n                */\n               if (mod != NULL)\n                  break; /* out of switch */\n            }\n\n            /* If we get to here then this chunk may need to be modified.  To\n             * do this it must be less than 1024 bytes in total size, otherwise\n             * it just gets flushed.\n             */\n            if (len+12 <= sizeof pm->buffer)\n            {\n               png_size_t s = len+12-pm->buffer_count;\n               store_read_chunk(&pm->this, pm->buffer+pm->buffer_count, s, s);\n               pm->buffer_count = len+12;\n\n               /* Check for a modification, else leave it be. */\n               mod = pm->modifications;\n               while (mod != NULL)\n               {\n                  if (mod->chunk == chunk)\n                  {\n                     if (mod->modify_fn == NULL)\n                     {\n                        /* Remove this chunk */\n                        pm->buffer_count = pm->buffer_position = 0;\n                        mod->removed = 1;\n                        break; /* Terminate the while loop */\n                     }\n\n                     else if ((*mod->modify_fn)(pm, mod, 0))\n                     {\n                        mod->modified = 1;\n                        /* The chunk may have been removed: */\n                        if (pm->buffer_count == 0)\n                        {\n                           pm->buffer_position = 0;\n                           break;\n                        }\n                        modifier_setbuffer(pm);\n                     }\n                  }\n\n                  mod = mod->next;\n               }\n            }\n\n            else\n               pm->flush = len+12 - pm->buffer_count; /* data + crc */\n\n            /* Take the data from the buffer (if there is any). */\n            break;\n      }\n\n      /* Here to read from the modifier buffer (not directly from\n       * the store, as in the flush case above.)\n       */\n      cb = pm->buffer_count - pm->buffer_position;\n\n      if (cb > st)\n         cb = st;\n\n      memcpy(pb, pm->buffer + pm->buffer_position, cb);\n      st -= cb;\n      pb += cb;\n      pm->buffer_position += cb;\n   }\n}\n\n/* The callback: */\nstatic void PNGCBAPI\nmodifier_read(png_structp ppIn, png_bytep pb, png_size_t st)\n{\n   png_const_structp pp = ppIn;\n   png_modifier *pm = voidcast(png_modifier*, png_get_io_ptr(pp));\n\n   if (pm == NULL || pm->this.pread != pp)\n      png_error(pp, \"bad modifier_read call\");\n\n   modifier_read_imp(pm, pb, st);\n}\n\n/* Like store_progressive_read but the data is getting changed as we go so we\n * need a local buffer.\n */\nstatic void\nmodifier_progressive_read(png_modifier *pm, png_structp pp, png_infop pi)\n{\n   if (pm->this.pread != pp || pm->this.current == NULL ||\n       pm->this.next == NULL)\n      png_error(pp, \"store state damaged (progressive)\");\n\n   /* This is another Horowitz and Hill random noise generator.  In this case\n    * the aim is to stress the progressive reader with truly horrible variable\n    * buffer sizes in the range 1..500, so a sequence of 9 bit random numbers\n    * is generated.  We could probably just count from 1 to 32767 and get as\n    * good a result.\n    */\n   for (;;)\n   {\n      static png_uint_32 noise = 1;\n      png_size_t cb, cbAvail;\n      png_byte buffer[512];\n\n      /* Generate 15 more bits of stuff: */\n      noise = (noise << 9) | ((noise ^ (noise >> (9-5))) & 0x1ff);\n      cb = noise & 0x1ff;\n\n      /* Check that this number of bytes are available (in the current buffer.)\n       * (This doesn't quite work - the modifier might delete a chunk; unlikely\n       * but possible, it doesn't happen at present because the modifier only\n       * adds chunks to standard images.)\n       */\n      cbAvail = store_read_buffer_avail(&pm->this);\n      if (pm->buffer_count > pm->buffer_position)\n         cbAvail += pm->buffer_count - pm->buffer_position;\n\n      if (cb > cbAvail)\n      {\n         /* Check for EOF: */\n         if (cbAvail == 0)\n            break;\n\n         cb = cbAvail;\n      }\n\n      modifier_read_imp(pm, buffer, cb);\n      png_process_data(pp, pi, buffer, cb);\n   }\n\n   /* Check the invariants at the end (if this fails it's a problem in this\n    * file!)\n    */\n   if (pm->buffer_count > pm->buffer_position ||\n       pm->this.next != &pm->this.current->data ||\n       pm->this.readpos < pm->this.current->datacount)\n      png_error(pp, \"progressive read implementation error\");\n}\n\n/* Set up a modifier. */\nstatic png_structp\nset_modifier_for_read(png_modifier *pm, png_infopp ppi, png_uint_32 id,\n    const char *name)\n{\n   /* Do this first so that the modifier fields are cleared even if an error\n    * happens allocating the png_struct.  No allocation is done here so no\n    * cleanup is required.\n    */\n   pm->state = modifier_start;\n   pm->bit_depth = 0;\n   pm->colour_type = 255;\n\n   pm->pending_len = 0;\n   pm->pending_chunk = 0;\n   pm->flush = 0;\n   pm->buffer_count = 0;\n   pm->buffer_position = 0;\n\n   return set_store_for_read(&pm->this, ppi, id, name);\n}\n\n\n/******************************** MODIFICATIONS *******************************/\n/* Standard modifications to add chunks.  These do not require the _SUPPORTED\n * macros because the chunks can be there regardless of whether this specific\n * libpng supports them.\n */\ntypedef struct gama_modification\n{\n   png_modification this;\n   png_fixed_point  gamma;\n} gama_modification;\n\nstatic int\ngama_modify(png_modifier *pm, png_modification *me, int add)\n{\n   UNUSED(add)\n   /* This simply dumps the given gamma value into the buffer. */\n   png_save_uint_32(pm->buffer, 4);\n   png_save_uint_32(pm->buffer+4, CHUNK_gAMA);\n   png_save_uint_32(pm->buffer+8, ((gama_modification*)me)->gamma);\n   return 1;\n}\n\nstatic void\ngama_modification_init(gama_modification *me, png_modifier *pm, double gammad)\n{\n   double g;\n\n   modification_init(&me->this);\n   me->this.chunk = CHUNK_gAMA;\n   me->this.modify_fn = gama_modify;\n   me->this.add = CHUNK_PLTE;\n   g = fix(gammad);\n   me->gamma = (png_fixed_point)g;\n   me->this.next = pm->modifications;\n   pm->modifications = &me->this;\n}\n\ntypedef struct chrm_modification\n{\n   png_modification          this;\n   const color_encoding *encoding;\n   png_fixed_point           wx, wy, rx, ry, gx, gy, bx, by;\n} chrm_modification;\n\nstatic int\nchrm_modify(png_modifier *pm, png_modification *me, int add)\n{\n   UNUSED(add)\n   /* As with gAMA this just adds the required cHRM chunk to the buffer. */\n   png_save_uint_32(pm->buffer   , 32);\n   png_save_uint_32(pm->buffer+ 4, CHUNK_cHRM);\n   png_save_uint_32(pm->buffer+ 8, ((chrm_modification*)me)->wx);\n   png_save_uint_32(pm->buffer+12, ((chrm_modification*)me)->wy);\n   png_save_uint_32(pm->buffer+16, ((chrm_modification*)me)->rx);\n   png_save_uint_32(pm->buffer+20, ((chrm_modification*)me)->ry);\n   png_save_uint_32(pm->buffer+24, ((chrm_modification*)me)->gx);\n   png_save_uint_32(pm->buffer+28, ((chrm_modification*)me)->gy);\n   png_save_uint_32(pm->buffer+32, ((chrm_modification*)me)->bx);\n   png_save_uint_32(pm->buffer+36, ((chrm_modification*)me)->by);\n   return 1;\n}\n\nstatic void\nchrm_modification_init(chrm_modification *me, png_modifier *pm,\n   const color_encoding *encoding)\n{\n   CIE_color white = white_point(encoding);\n\n   /* Original end points: */\n   me->encoding = encoding;\n\n   /* Chromaticities (in fixed point): */\n   me->wx = fix(chromaticity_x(white));\n   me->wy = fix(chromaticity_y(white));\n\n   me->rx = fix(chromaticity_x(encoding->red));\n   me->ry = fix(chromaticity_y(encoding->red));\n   me->gx = fix(chromaticity_x(encoding->green));\n   me->gy = fix(chromaticity_y(encoding->green));\n   me->bx = fix(chromaticity_x(encoding->blue));\n   me->by = fix(chromaticity_y(encoding->blue));\n\n   modification_init(&me->this);\n   me->this.chunk = CHUNK_cHRM;\n   me->this.modify_fn = chrm_modify;\n   me->this.add = CHUNK_PLTE;\n   me->this.next = pm->modifications;\n   pm->modifications = &me->this;\n}\n\ntypedef struct srgb_modification\n{\n   png_modification this;\n   png_byte         intent;\n} srgb_modification;\n\nstatic int\nsrgb_modify(png_modifier *pm, png_modification *me, int add)\n{\n   UNUSED(add)\n   /* As above, ignore add and just make a new chunk */\n   png_save_uint_32(pm->buffer, 1);\n   png_save_uint_32(pm->buffer+4, CHUNK_sRGB);\n   pm->buffer[8] = ((srgb_modification*)me)->intent;\n   return 1;\n}\n\nstatic void\nsrgb_modification_init(srgb_modification *me, png_modifier *pm, png_byte intent)\n{\n   modification_init(&me->this);\n   me->this.chunk = CHUNK_sBIT;\n\n   if (intent <= 3) /* if valid, else *delete* sRGB chunks */\n   {\n      me->this.modify_fn = srgb_modify;\n      me->this.add = CHUNK_PLTE;\n      me->intent = intent;\n   }\n\n   else\n   {\n      me->this.modify_fn = 0;\n      me->this.add = 0;\n      me->intent = 0;\n   }\n\n   me->this.next = pm->modifications;\n   pm->modifications = &me->this;\n}\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\ntypedef struct sbit_modification\n{\n   png_modification this;\n   png_byte         sbit;\n} sbit_modification;\n\nstatic int\nsbit_modify(png_modifier *pm, png_modification *me, int add)\n{\n   png_byte sbit = ((sbit_modification*)me)->sbit;\n   if (pm->bit_depth > sbit)\n   {\n      int cb = 0;\n      switch (pm->colour_type)\n      {\n         case 0:\n            cb = 1;\n            break;\n\n         case 2:\n         case 3:\n            cb = 3;\n            break;\n\n         case 4:\n            cb = 2;\n            break;\n\n         case 6:\n            cb = 4;\n            break;\n\n         default:\n            png_error(pm->this.pread,\n               \"unexpected colour type in sBIT modification\");\n      }\n\n      png_save_uint_32(pm->buffer, cb);\n      png_save_uint_32(pm->buffer+4, CHUNK_sBIT);\n\n      while (cb > 0)\n         (pm->buffer+8)[--cb] = sbit;\n\n      return 1;\n   }\n   else if (!add)\n   {\n      /* Remove the sBIT chunk */\n      pm->buffer_count = pm->buffer_position = 0;\n      return 1;\n   }\n   else\n      return 0; /* do nothing */\n}\n\nstatic void\nsbit_modification_init(sbit_modification *me, png_modifier *pm, png_byte sbit)\n{\n   modification_init(&me->this);\n   me->this.chunk = CHUNK_sBIT;\n   me->this.modify_fn = sbit_modify;\n   me->this.add = CHUNK_PLTE;\n   me->sbit = sbit;\n   me->this.next = pm->modifications;\n   pm->modifications = &me->this;\n}\n#endif /* PNG_READ_GAMMA_SUPPORTED */\n#endif /* PNG_READ_TRANSFORMS_SUPPORTED */\n\n/***************************** STANDARD PNG FILES *****************************/\n/* Standard files - write and save standard files. */\n/* There are two basic forms of standard images.  Those which attempt to have\n * all the possible pixel values (not possible for 16bpp images, but a range of\n * values are produced) and those which have a range of image sizes.  The former\n * are used for testing transforms, in particular gamma correction and bit\n * reduction and increase.  The latter are reserved for testing the behavior of\n * libpng with respect to 'odd' image sizes - particularly small images where\n * rows become 1 byte and interlace passes disappear.\n *\n * The first, most useful, set are the 'transform' images, the second set of\n * small images are the 'size' images.\n *\n * The transform files are constructed with rows which fit into a 1024 byte row\n * buffer.  This makes allocation easier below.  Further regardless of the file\n * format every row has 128 pixels (giving 1024 bytes for 64bpp formats).\n *\n * Files are stored with no gAMA or sBIT chunks, with a PLTE only when needed\n * and with an ID derived from the colour type, bit depth and interlace type\n * as above (FILEID).  The width (128) and height (variable) are not stored in\n * the FILEID - instead the fields are set to 0, indicating a transform file.\n *\n * The size files ar constructed with rows a maximum of 128 bytes wide, allowing\n * a maximum width of 16 pixels (for the 64bpp case.)  They also have a maximum\n * height of 16 rows.  The width and height are stored in the FILEID and, being\n * non-zero, indicate a size file.\n *\n * Because the PNG filter code is typically the largest CPU consumer within\n * libpng itself there is a tendency to attempt to optimize it.  This results in\n * special case code which needs to be validated.  To cause this to happen the\n * 'size' images are made to use each possible filter, in so far as this is\n * possible for smaller images.\n *\n * For palette image (colour type 3) multiple transform images are stored with\n * the same bit depth to allow testing of more colour combinations -\n * particularly important for testing the gamma code because libpng uses a\n * different code path for palette images.  For size images a single palette is\n * used.\n */\n\n/* Make a 'standard' palette.  Because there are only 256 entries in a palette\n * (maximum) this actually makes a random palette in the hope that enough tests\n * will catch enough errors.  (Note that the same palette isn't produced every\n * time for the same test - it depends on what previous tests have been run -\n * but a given set of arguments to pngvalid will always produce the same palette\n * at the same test!  This is why pseudo-random number generators are useful for\n * testing.)\n *\n * The store must be open for write when this is called, otherwise an internal\n * error will occur.  This routine contains its own magic number seed, so the\n * palettes generated don't change if there are intervening errors (changing the\n * calls to the store_mark seed.)\n */\nstatic store_palette_entry *\nmake_standard_palette(png_store* ps, int npalette, int do_tRNS)\n{\n   static png_uint_32 palette_seed[2] = { 0x87654321, 9 };\n\n   int i = 0;\n   png_byte values[256][4];\n\n   /* Always put in black and white plus the six primary and secondary colors.\n    */\n   for (; i<8; ++i)\n   {\n      values[i][1] = (png_byte)((i&1) ? 255U : 0U);\n      values[i][2] = (png_byte)((i&2) ? 255U : 0U);\n      values[i][3] = (png_byte)((i&4) ? 255U : 0U);\n   }\n\n   /* Then add 62 grays (one quarter of the remaining 256 slots). */\n   {\n      int j = 0;\n      png_byte random_bytes[4];\n      png_byte need[256];\n\n      need[0] = 0; /*got black*/\n      memset(need+1, 1, (sizeof need)-2); /*need these*/\n      need[255] = 0; /*but not white*/\n\n      while (i<70)\n      {\n         png_byte b;\n\n         if (j==0)\n         {\n            make_four_random_bytes(palette_seed, random_bytes);\n            j = 4;\n         }\n\n         b = random_bytes[--j];\n         if (need[b])\n         {\n            values[i][1] = b;\n            values[i][2] = b;\n            values[i++][3] = b;\n         }\n      }\n   }\n\n   /* Finally add 192 colors at random - don't worry about matches to things we\n    * already have, chance is less than 1/65536.  Don't worry about grays,\n    * chance is the same, so we get a duplicate or extra gray less than 1 time\n    * in 170.\n    */\n   for (; i<256; ++i)\n      make_four_random_bytes(palette_seed, values[i]);\n\n   /* Fill in the alpha values in the first byte.  Just use all possible values\n    * (0..255) in an apparently random order:\n    */\n   {\n      store_palette_entry *palette;\n      png_byte selector[4];\n\n      make_four_random_bytes(palette_seed, selector);\n\n      if (do_tRNS)\n         for (i=0; i<256; ++i)\n            values[i][0] = (png_byte)(i ^ selector[0]);\n\n      else\n         for (i=0; i<256; ++i)\n            values[i][0] = 255; /* no transparency/tRNS chunk */\n\n      /* 'values' contains 256 ARGB values, but we only need 'npalette'.\n       * 'npalette' will always be a power of 2: 2, 4, 16 or 256.  In the low\n       * bit depth cases select colors at random, else it is difficult to have\n       * a set of low bit depth palette test with any chance of a reasonable\n       * range of colors.  Do this by randomly permuting values into the low\n       * 'npalette' entries using an XOR mask generated here.  This also\n       * permutes the npalette == 256 case in a potentially useful way (there is\n       * no relationship between palette index and the color value therein!)\n       */\n      palette = store_write_palette(ps, npalette);\n\n      for (i=0; i<npalette; ++i)\n      {\n         palette[i].alpha = values[i ^ selector[1]][0];\n         palette[i].red   = values[i ^ selector[1]][1];\n         palette[i].green = values[i ^ selector[1]][2];\n         palette[i].blue  = values[i ^ selector[1]][3];\n      }\n\n      return palette;\n   }\n}\n\n/* Initialize a standard palette on a write stream.  The 'do_tRNS' argument\n * indicates whether or not to also set the tRNS chunk.\n */\n/* TODO: the png_structp here can probably be 'const' in the future */\nstatic void\ninit_standard_palette(png_store *ps, png_structp pp, png_infop pi, int npalette,\n   int do_tRNS)\n{\n   store_palette_entry *ppal = make_standard_palette(ps, npalette, do_tRNS);\n\n   {\n      int i;\n      png_color palette[256];\n\n      /* Set all entries to detect overread errors. */\n      for (i=0; i<npalette; ++i)\n      {\n         palette[i].red = ppal[i].red;\n         palette[i].green = ppal[i].green;\n         palette[i].blue = ppal[i].blue;\n      }\n\n      /* Just in case fill in the rest with detectable values: */\n      for (; i<256; ++i)\n         palette[i].red = palette[i].green = palette[i].blue = 42;\n\n      png_set_PLTE(pp, pi, palette, npalette);\n   }\n\n   if (do_tRNS)\n   {\n      int i, j;\n      png_byte tRNS[256];\n\n      /* Set all the entries, but skip trailing opaque entries */\n      for (i=j=0; i<npalette; ++i)\n         if ((tRNS[i] = ppal[i].alpha) < 255)\n            j = i+1;\n\n      /* Fill in the remainder with a detectable value: */\n      for (; i<256; ++i)\n         tRNS[i] = 24;\n\n#ifdef PNG_WRITE_tRNS_SUPPORTED\n      if (j > 0)\n         png_set_tRNS(pp, pi, tRNS, j, 0/*color*/);\n#endif\n   }\n}\n\n#ifdef PNG_WRITE_tRNS_SUPPORTED\nstatic void\nset_random_tRNS(png_structp pp, png_infop pi, const png_byte colour_type,\n   const int bit_depth)\n{\n   /* To make this useful the tRNS color needs to match at least one pixel.\n    * Random values are fine for gray, including the 16-bit case where we know\n    * that the test image contains all the gray values.  For RGB we need more\n    * method as only 65536 different RGB values are generated.\n    */\n   png_color_16 tRNS;\n   const png_uint_16 mask = (png_uint_16)((1U << bit_depth)-1);\n\n   R8(tRNS); /* makes unset fields random */\n\n   if (colour_type & 2/*RGB*/)\n   {\n      if (bit_depth == 8)\n      {\n         tRNS.red = random_u16();\n         tRNS.green = random_u16();\n         tRNS.blue = tRNS.red ^ tRNS.green;\n         tRNS.red &= mask;\n         tRNS.green &= mask;\n         tRNS.blue &= mask;\n      }\n\n      else /* bit_depth == 16 */\n      {\n         tRNS.red = random_u16();\n         tRNS.green = (png_uint_16)(tRNS.red * 257);\n         tRNS.blue = (png_uint_16)(tRNS.green * 17);\n      }\n   }\n\n   else\n   {\n      tRNS.gray = random_u16();\n      tRNS.gray &= mask;\n   }\n\n   png_set_tRNS(pp, pi, NULL, 0, &tRNS);\n}\n#endif\n\n/* The number of passes is related to the interlace type. There was no libpng\n * API to determine this prior to 1.5, so we need an inquiry function:\n */\nstatic int\nnpasses_from_interlace_type(png_const_structp pp, int interlace_type)\n{\n   switch (interlace_type)\n   {\n   default:\n      png_error(pp, \"invalid interlace type\");\n\n   case PNG_INTERLACE_NONE:\n      return 1;\n\n   case PNG_INTERLACE_ADAM7:\n      return PNG_INTERLACE_ADAM7_PASSES;\n   }\n}\n\nstatic unsigned int\nbit_size(png_const_structp pp, png_byte colour_type, png_byte bit_depth)\n{\n   switch (colour_type)\n   {\n      default: png_error(pp, \"invalid color type\");\n\n      case 0:  return bit_depth;\n\n      case 2:  return 3*bit_depth;\n\n      case 3:  return bit_depth;\n\n      case 4:  return 2*bit_depth;\n\n      case 6:  return 4*bit_depth;\n   }\n}\n\n#define TRANSFORM_WIDTH  128U\n#define TRANSFORM_ROWMAX (TRANSFORM_WIDTH*8U)\n#define SIZE_ROWMAX (16*8U) /* 16 pixels, max 8 bytes each - 128 bytes */\n#define STANDARD_ROWMAX TRANSFORM_ROWMAX /* The larger of the two */\n#define SIZE_HEIGHTMAX 16 /* Maximum range of size images */\n\nstatic size_t\ntransform_rowsize(png_const_structp pp, png_byte colour_type,\n   png_byte bit_depth)\n{\n   return (TRANSFORM_WIDTH * bit_size(pp, colour_type, bit_depth)) / 8;\n}\n\n/* transform_width(pp, colour_type, bit_depth) current returns the same number\n * every time, so just use a macro:\n */\n#define transform_width(pp, colour_type, bit_depth) TRANSFORM_WIDTH\n\nstatic png_uint_32\ntransform_height(png_const_structp pp, png_byte colour_type, png_byte bit_depth)\n{\n   switch (bit_size(pp, colour_type, bit_depth))\n   {\n      case 1:\n      case 2:\n      case 4:\n         return 1;   /* Total of 128 pixels */\n\n      case 8:\n         return 2;   /* Total of 256 pixels/bytes */\n\n      case 16:\n         return 512; /* Total of 65536 pixels */\n\n      case 24:\n      case 32:\n         return 512; /* 65536 pixels */\n\n      case 48:\n      case 64:\n         return 2048;/* 4 x 65536 pixels. */\n#        define TRANSFORM_HEIGHTMAX 2048\n\n      default:\n         return 0;   /* Error, will be caught later */\n   }\n}\n\n#ifdef PNG_READ_SUPPORTED\n/* The following can only be defined here, now we have the definitions\n * of the transform image sizes.\n */\nstatic png_uint_32\nstandard_width(png_const_structp pp, png_uint_32 id)\n{\n   png_uint_32 width = WIDTH_FROM_ID(id);\n   UNUSED(pp)\n\n   if (width == 0)\n      width = transform_width(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));\n\n   return width;\n}\n\nstatic png_uint_32\nstandard_height(png_const_structp pp, png_uint_32 id)\n{\n   png_uint_32 height = HEIGHT_FROM_ID(id);\n\n   if (height == 0)\n      height = transform_height(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));\n\n   return height;\n}\n\nstatic png_uint_32\nstandard_rowsize(png_const_structp pp, png_uint_32 id)\n{\n   png_uint_32 width = standard_width(pp, id);\n\n   /* This won't overflow: */\n   width *= bit_size(pp, COL_FROM_ID(id), DEPTH_FROM_ID(id));\n   return (width + 7) / 8;\n}\n#endif /* PNG_READ_SUPPORTED */\n\nstatic void\ntransform_row(png_const_structp pp, png_byte buffer[TRANSFORM_ROWMAX],\n   png_byte colour_type, png_byte bit_depth, png_uint_32 y)\n{\n   png_uint_32 v = y << 7;\n   png_uint_32 i = 0;\n\n   switch (bit_size(pp, colour_type, bit_depth))\n   {\n      case 1:\n         while (i<128/8) buffer[i] = (png_byte)(v & 0xff), v += 17, ++i;\n         return;\n\n      case 2:\n         while (i<128/4) buffer[i] = (png_byte)(v & 0xff), v += 33, ++i;\n         return;\n\n      case 4:\n         while (i<128/2) buffer[i] = (png_byte)(v & 0xff), v += 65, ++i;\n         return;\n\n      case 8:\n         /* 256 bytes total, 128 bytes in each row set as follows: */\n         while (i<128) buffer[i] = (png_byte)(v & 0xff), ++v, ++i;\n         return;\n\n      case 16:\n         /* Generate all 65536 pixel values in order, which includes the 8 bit\n          * GA case as well as the 16 bit G case.\n          */\n         while (i<128)\n         {\n            buffer[2*i] = (png_byte)((v>>8) & 0xff);\n            buffer[2*i+1] = (png_byte)(v & 0xff);\n            ++v;\n            ++i;\n         }\n\n         return;\n\n      case 24:\n         /* 65535 pixels, but rotate the values. */\n         while (i<128)\n         {\n            /* Three bytes per pixel, r, g, b, make b by r^g */\n            buffer[3*i+0] = (png_byte)((v >> 8) & 0xff);\n            buffer[3*i+1] = (png_byte)(v & 0xff);\n            buffer[3*i+2] = (png_byte)(((v >> 8) ^ v) & 0xff);\n            ++v;\n            ++i;\n         }\n\n         return;\n\n      case 32:\n         /* 65535 pixels, r, g, b, a; just replicate */\n         while (i<128)\n         {\n            buffer[4*i+0] = (png_byte)((v >> 8) & 0xff);\n            buffer[4*i+1] = (png_byte)(v & 0xff);\n            buffer[4*i+2] = (png_byte)((v >> 8) & 0xff);\n            buffer[4*i+3] = (png_byte)(v & 0xff);\n            ++v;\n            ++i;\n         }\n\n         return;\n\n      case 48:\n         /* y is maximum 2047, giving 4x65536 pixels, make 'r' increase by 1 at\n          * each pixel, g increase by 257 (0x101) and 'b' by 0x1111:\n          */\n         while (i<128)\n         {\n            png_uint_32 t = v++;\n            buffer[6*i+0] = (png_byte)((t >> 8) & 0xff);\n            buffer[6*i+1] = (png_byte)(t & 0xff);\n            t *= 257;\n            buffer[6*i+2] = (png_byte)((t >> 8) & 0xff);\n            buffer[6*i+3] = (png_byte)(t & 0xff);\n            t *= 17;\n            buffer[6*i+4] = (png_byte)((t >> 8) & 0xff);\n            buffer[6*i+5] = (png_byte)(t & 0xff);\n            ++i;\n         }\n\n         return;\n\n      case 64:\n         /* As above in the 32 bit case. */\n         while (i<128)\n         {\n            png_uint_32 t = v++;\n            buffer[8*i+0] = (png_byte)((t >> 8) & 0xff);\n            buffer[8*i+1] = (png_byte)(t & 0xff);\n            buffer[8*i+4] = (png_byte)((t >> 8) & 0xff);\n            buffer[8*i+5] = (png_byte)(t & 0xff);\n            t *= 257;\n            buffer[8*i+2] = (png_byte)((t >> 8) & 0xff);\n            buffer[8*i+3] = (png_byte)(t & 0xff);\n            buffer[8*i+6] = (png_byte)((t >> 8) & 0xff);\n            buffer[8*i+7] = (png_byte)(t & 0xff);\n            ++i;\n         }\n         return;\n\n      default:\n         break;\n   }\n\n   png_error(pp, \"internal error\");\n}\n\n/* This is just to do the right cast - could be changed to a function to check\n * 'bd' but there isn't much point.\n */\n#define DEPTH(bd) ((png_byte)(1U << (bd)))\n\n/* This is just a helper for compiling on minimal systems with no write\n * interlacing support.  If there is no write interlacing we can't generate test\n * cases with interlace:\n */\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n#  define INTERLACE_LAST PNG_INTERLACE_LAST\n#  define check_interlace_type(type) ((void)(type))\n#  define set_write_interlace_handling(pp,type) png_set_interlace_handling(pp)\n#  define do_own_interlace 0\n#elif PNG_LIBPNG_VER < 10700\n#  define set_write_interlace_handling(pp,type) (1)\nstatic void\ncheck_interlace_type(int const interlace_type)\n{\n   /* Prior to 1.7.0 libpng does not support the write of an interlaced image\n    * unless PNG_WRITE_INTERLACING_SUPPORTED, even with do_interlace so the\n    * code here does the pixel interlace itself, so:\n    */\n   if (interlace_type != PNG_INTERLACE_NONE)\n   {\n      /* This is an internal error - --interlace tests should be skipped, not\n       * attempted.\n       */\n      fprintf(stderr, \"pngvalid: no interlace support\\n\");\n      exit(99);\n   }\n}\n#  define INTERLACE_LAST (PNG_INTERLACE_NONE+1)\n#  define do_own_interlace 0\n#else /* libpng 1.7+ */\n#  define set_write_interlace_handling(pp,type)\\\n      npasses_from_interlace_type(pp,type)\n#  define check_interlace_type(type) ((void)(type))\n#  define INTERLACE_LAST PNG_INTERLACE_LAST\n#  define do_own_interlace 1\n#endif /* WRITE_INTERLACING tests */\n\n#define CAN_WRITE_INTERLACE\\\n   PNG_LIBPNG_VER >= 10700 || defined PNG_WRITE_INTERLACING_SUPPORTED\n\n/* Do the same thing for read interlacing; this controls whether read tests do\n * their own de-interlace or use libpng.\n */\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n#  define do_read_interlace 0\n#else /* no libpng read interlace support */\n#  define do_read_interlace 1\n#endif\n/* The following two routines use the PNG interlace support macros from\n * png.h to interlace or deinterlace rows.\n */\nstatic void\ninterlace_row(png_bytep buffer, png_const_bytep imageRow,\n   unsigned int pixel_size, png_uint_32 w, int pass, int littleendian)\n{\n   png_uint_32 xin, xout, xstep;\n\n   /* Note that this can, trivially, be optimized to a memcpy on pass 7, the\n    * code is presented this way to make it easier to understand.  In practice\n    * consult the code in the libpng source to see other ways of doing this.\n    *\n    * It is OK for buffer and imageRow to be identical, because 'xin' moves\n    * faster than 'xout' and we copy up.\n    */\n   xin = PNG_PASS_START_COL(pass);\n   xstep = 1U<<PNG_PASS_COL_SHIFT(pass);\n\n   for (xout=0; xin<w; xin+=xstep)\n   {\n      pixel_copy(buffer, xout, imageRow, xin, pixel_size, littleendian);\n      ++xout;\n   }\n}\n\n#ifdef PNG_READ_SUPPORTED\nstatic void\ndeinterlace_row(png_bytep buffer, png_const_bytep row,\n   unsigned int pixel_size, png_uint_32 w, int pass, int littleendian)\n{\n   /* The inverse of the above, 'row' is part of row 'y' of the output image,\n    * in 'buffer'.  The image is 'w' wide and this is pass 'pass', distribute\n    * the pixels of row into buffer and return the number written (to allow\n    * this to be checked).\n    */\n   png_uint_32 xin, xout, xstep;\n\n   xout = PNG_PASS_START_COL(pass);\n   xstep = 1U<<PNG_PASS_COL_SHIFT(pass);\n\n   for (xin=0; xout<w; xout+=xstep)\n   {\n      pixel_copy(buffer, xout, row, xin, pixel_size, littleendian);\n      ++xin;\n   }\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* Make a standardized image given an image colour type, bit depth and\n * interlace type.  The standard images have a very restricted range of\n * rows and heights and are used for testing transforms rather than image\n * layout details.  See make_size_images below for a way to make images\n * that test odd sizes along with the libpng interlace handling.\n */\n#ifdef PNG_WRITE_FILTER_SUPPORTED\nstatic void\nchoose_random_filter(png_structp pp, int start)\n{\n   /* Choose filters randomly except that on the very first row ensure that\n    * there is at least one previous row filter.\n    */\n   int filters = PNG_ALL_FILTERS & random_mod(256U);\n\n   /* There may be no filters; skip the setting. */\n   if (filters != 0)\n   {\n      if (start && filters < PNG_FILTER_UP)\n         filters |= PNG_FILTER_UP;\n\n      png_set_filter(pp, 0/*method*/, filters);\n   }\n}\n#else /* !WRITE_FILTER */\n#  define choose_random_filter(pp, start) ((void)0)\n#endif /* !WRITE_FILTER */\n\nstatic void\nmake_transform_image(png_store* const ps, png_byte const colour_type,\n    png_byte const bit_depth, unsigned int palette_number,\n    int interlace_type, png_const_charp name)\n{\n   context(ps, fault);\n\n   check_interlace_type(interlace_type);\n\n   Try\n   {\n      png_infop pi;\n      png_structp pp = set_store_for_write(ps, &pi, name);\n      png_uint_32 h, w;\n\n      /* In the event of a problem return control to the Catch statement below\n       * to do the clean up - it is not possible to 'return' directly from a Try\n       * block.\n       */\n      if (pp == NULL)\n         Throw ps;\n\n      w = transform_width(pp, colour_type, bit_depth);\n      h = transform_height(pp, colour_type, bit_depth);\n\n      png_set_IHDR(pp, pi, w, h, bit_depth, colour_type, interlace_type,\n         PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n#ifdef PNG_TEXT_SUPPORTED\n#  if defined(PNG_READ_zTXt_SUPPORTED) && defined(PNG_WRITE_zTXt_SUPPORTED)\n#     define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_zTXt\n#  else\n#     define TEXT_COMPRESSION PNG_TEXT_COMPRESSION_NONE\n#  endif\n      {\n         static char key[] = \"image name\"; /* must be writeable */\n         size_t pos;\n         png_text text;\n         char copy[FILE_NAME_SIZE];\n\n         /* Use a compressed text string to test the correct interaction of text\n          * compression and IDAT compression.\n          */\n         text.compression = TEXT_COMPRESSION;\n         text.key = key;\n         /* Yuck: the text must be writable! */\n         pos = safecat(copy, sizeof copy, 0, ps->wname);\n         text.text = copy;\n         text.text_length = pos;\n         text.itxt_length = 0;\n         text.lang = 0;\n         text.lang_key = 0;\n\n         png_set_text(pp, pi, &text, 1);\n      }\n#endif\n\n      if (colour_type == 3) /* palette */\n         init_standard_palette(ps, pp, pi, 1U << bit_depth, 1/*do tRNS*/);\n\n#     ifdef PNG_WRITE_tRNS_SUPPORTED\n         else if (palette_number)\n            set_random_tRNS(pp, pi, colour_type, bit_depth);\n#     endif\n\n      png_write_info(pp, pi);\n\n      if (png_get_rowbytes(pp, pi) !=\n          transform_rowsize(pp, colour_type, bit_depth))\n         png_error(pp, \"transform row size incorrect\");\n\n      else\n      {\n         /* Somewhat confusingly this must be called *after* png_write_info\n          * because if it is called before, the information in *pp has not been\n          * updated to reflect the interlaced image.\n          */\n         int npasses = set_write_interlace_handling(pp, interlace_type);\n         int pass;\n\n         if (npasses != npasses_from_interlace_type(pp, interlace_type))\n            png_error(pp, \"write: png_set_interlace_handling failed\");\n\n         for (pass=0; pass<npasses; ++pass)\n         {\n            png_uint_32 y;\n\n            /* do_own_interlace is a pre-defined boolean (a #define) which is\n             * set if we have to work out the interlaced rows here.\n             */\n            for (y=0; y<h; ++y)\n            {\n               png_byte buffer[TRANSFORM_ROWMAX];\n\n               transform_row(pp, buffer, colour_type, bit_depth, y);\n\n#              if do_own_interlace\n                  /* If do_own_interlace *and* the image is interlaced we need a\n                   * reduced interlace row; this may be reduced to empty.\n                   */\n                  if (interlace_type == PNG_INTERLACE_ADAM7)\n                  {\n                     /* The row must not be written if it doesn't exist, notice\n                      * that there are two conditions here, either the row isn't\n                      * ever in the pass or the row would be but isn't wide\n                      * enough to contribute any pixels.  In fact the wPass test\n                      * can be used to skip the whole y loop in this case.\n                      */\n                     if (PNG_ROW_IN_INTERLACE_PASS(y, pass) &&\n                         PNG_PASS_COLS(w, pass) > 0)\n                        interlace_row(buffer, buffer,\n                              bit_size(pp, colour_type, bit_depth), w, pass,\n                              0/*data always bigendian*/);\n                     else\n                        continue;\n                  }\n#              endif /* do_own_interlace */\n\n               choose_random_filter(pp, pass == 0 && y == 0);\n               png_write_row(pp, buffer);\n            }\n         }\n      }\n\n#ifdef PNG_TEXT_SUPPORTED\n      {\n         static char key[] = \"end marker\";\n         static char comment[] = \"end\";\n         png_text text;\n\n         /* Use a compressed text string to test the correct interaction of text\n          * compression and IDAT compression.\n          */\n         text.compression = TEXT_COMPRESSION;\n         text.key = key;\n         text.text = comment;\n         text.text_length = (sizeof comment)-1;\n         text.itxt_length = 0;\n         text.lang = 0;\n         text.lang_key = 0;\n\n         png_set_text(pp, pi, &text, 1);\n      }\n#endif\n\n      png_write_end(pp, pi);\n\n      /* And store this under the appropriate id, then clean up. */\n      store_storefile(ps, FILEID(colour_type, bit_depth, palette_number,\n         interlace_type, 0, 0, 0));\n\n      store_write_reset(ps);\n   }\n\n   Catch(fault)\n   {\n      /* Use the png_store returned by the exception. This may help the compiler\n       * because 'ps' is not used in this branch of the setjmp.  Note that fault\n       * and ps will always be the same value.\n       */\n      store_write_reset(fault);\n   }\n}\n\nstatic void\nmake_transform_images(png_modifier *pm)\n{\n   png_byte colour_type = 0;\n   png_byte bit_depth = 0;\n   unsigned int palette_number = 0;\n\n   /* This is in case of errors. */\n   safecat(pm->this.test, sizeof pm->this.test, 0, \"make standard images\");\n\n   /* Use next_format to enumerate all the combinations we test, including\n    * generating multiple low bit depth palette images. Non-A images (palette\n    * and direct) are created with and without tRNS chunks.\n    */\n   while (next_format(&colour_type, &bit_depth, &palette_number, 1, 1))\n   {\n      int interlace_type;\n\n      for (interlace_type = PNG_INTERLACE_NONE;\n           interlace_type < INTERLACE_LAST; ++interlace_type)\n      {\n         char name[FILE_NAME_SIZE];\n\n         standard_name(name, sizeof name, 0, colour_type, bit_depth,\n            palette_number, interlace_type, 0, 0, do_own_interlace);\n         make_transform_image(&pm->this, colour_type, bit_depth, palette_number,\n            interlace_type, name);\n      }\n   }\n}\n\n/* Build a single row for the 'size' test images; this fills in only the\n * first bit_width bits of the sample row.\n */\nstatic void\nsize_row(png_byte buffer[SIZE_ROWMAX], png_uint_32 bit_width, png_uint_32 y)\n{\n   /* height is in the range 1 to 16, so: */\n   y = ((y & 1) << 7) + ((y & 2) << 6) + ((y & 4) << 5) + ((y & 8) << 4);\n   /* the following ensures bits are set in small images: */\n   y ^= 0xA5;\n\n   while (bit_width >= 8)\n      *buffer++ = (png_byte)y++, bit_width -= 8;\n\n   /* There may be up to 7 remaining bits, these go in the most significant\n    * bits of the byte.\n    */\n   if (bit_width > 0)\n   {\n      png_uint_32 mask = (1U<<(8-bit_width))-1;\n      *buffer = (png_byte)((*buffer & mask) | (y & ~mask));\n   }\n}\n\nstatic void\nmake_size_image(png_store* const ps, png_byte const colour_type,\n    png_byte const bit_depth, int const interlace_type,\n    png_uint_32 const w, png_uint_32 const h,\n    int const do_interlace)\n{\n   context(ps, fault);\n\n   check_interlace_type(interlace_type);\n\n   Try\n   {\n      png_infop pi;\n      png_structp pp;\n      unsigned int pixel_size;\n\n      /* Make a name and get an appropriate id for the store: */\n      char name[FILE_NAME_SIZE];\n      const png_uint_32 id = FILEID(colour_type, bit_depth, 0/*palette*/,\n         interlace_type, w, h, do_interlace);\n\n      standard_name_from_id(name, sizeof name, 0, id);\n      pp = set_store_for_write(ps, &pi, name);\n\n      /* In the event of a problem return control to the Catch statement below\n       * to do the clean up - it is not possible to 'return' directly from a Try\n       * block.\n       */\n      if (pp == NULL)\n         Throw ps;\n\n      png_set_IHDR(pp, pi, w, h, bit_depth, colour_type, interlace_type,\n         PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n#ifdef PNG_TEXT_SUPPORTED\n      {\n         static char key[] = \"image name\"; /* must be writeable */\n         size_t pos;\n         png_text text;\n         char copy[FILE_NAME_SIZE];\n\n         /* Use a compressed text string to test the correct interaction of text\n          * compression and IDAT compression.\n          */\n         text.compression = TEXT_COMPRESSION;\n         text.key = key;\n         /* Yuck: the text must be writable! */\n         pos = safecat(copy, sizeof copy, 0, ps->wname);\n         text.text = copy;\n         text.text_length = pos;\n         text.itxt_length = 0;\n         text.lang = 0;\n         text.lang_key = 0;\n\n         png_set_text(pp, pi, &text, 1);\n      }\n#endif\n\n      if (colour_type == 3) /* palette */\n         init_standard_palette(ps, pp, pi, 1U << bit_depth, 0/*do tRNS*/);\n\n      png_write_info(pp, pi);\n\n      /* Calculate the bit size, divide by 8 to get the byte size - this won't\n       * overflow because we know the w values are all small enough even for\n       * a system where 'unsigned int' is only 16 bits.\n       */\n      pixel_size = bit_size(pp, colour_type, bit_depth);\n      if (png_get_rowbytes(pp, pi) != ((w * pixel_size) + 7) / 8)\n         png_error(pp, \"size row size incorrect\");\n\n      else\n      {\n         int npasses = npasses_from_interlace_type(pp, interlace_type);\n         png_uint_32 y;\n         int pass;\n         png_byte image[16][SIZE_ROWMAX];\n\n         /* To help consistent error detection make the parts of this buffer\n          * that aren't set below all '1':\n          */\n         memset(image, 0xff, sizeof image);\n\n         if (!do_interlace &&\n             npasses != set_write_interlace_handling(pp, interlace_type))\n            png_error(pp, \"write: png_set_interlace_handling failed\");\n\n         /* Prepare the whole image first to avoid making it 7 times: */\n         for (y=0; y<h; ++y)\n            size_row(image[y], w * pixel_size, y);\n\n         for (pass=0; pass<npasses; ++pass)\n         {\n            /* The following two are for checking the macros: */\n            const png_uint_32 wPass = PNG_PASS_COLS(w, pass);\n\n            /* If do_interlace is set we don't call png_write_row for every\n             * row because some of them are empty.  In fact, for a 1x1 image,\n             * most of them are empty!\n             */\n            for (y=0; y<h; ++y)\n            {\n               png_const_bytep row = image[y];\n               png_byte tempRow[SIZE_ROWMAX];\n\n               /* If do_interlace *and* the image is interlaced we\n                * need a reduced interlace row; this may be reduced\n                * to empty.\n                */\n               if (do_interlace && interlace_type == PNG_INTERLACE_ADAM7)\n               {\n                  /* The row must not be written if it doesn't exist, notice\n                   * that there are two conditions here, either the row isn't\n                   * ever in the pass or the row would be but isn't wide\n                   * enough to contribute any pixels.  In fact the wPass test\n                   * can be used to skip the whole y loop in this case.\n                   */\n                  if (PNG_ROW_IN_INTERLACE_PASS(y, pass) && wPass > 0)\n                  {\n                     /* Set to all 1's for error detection (libpng tends to\n                      * set unset things to 0).\n                      */\n                     memset(tempRow, 0xff, sizeof tempRow);\n                     interlace_row(tempRow, row, pixel_size, w, pass,\n                           0/*data always bigendian*/);\n                     row = tempRow;\n                  }\n                  else\n                     continue;\n               }\n\n#           ifdef PNG_WRITE_FILTER_SUPPORTED\n               /* Only get to here if the row has some pixels in it, set the\n                * filters to 'all' for the very first row and thereafter to a\n                * single filter.  It isn't well documented, but png_set_filter\n                * does accept a filter number (per the spec) as well as a bit\n                * mask.\n                *\n                * The code now uses filters at random, except that on the first\n                * row of an image it ensures that a previous row filter is in\n                * the set so that libpng allocates the row buffer.\n                */\n               {\n                  int filters = 8 << random_mod(PNG_FILTER_VALUE_LAST);\n\n                  if (pass == 0 && y == 0 &&\n                      (filters < PNG_FILTER_UP || w == 1U))\n                     filters |= PNG_FILTER_UP;\n\n                  png_set_filter(pp, 0/*method*/, filters);\n               }\n#           endif\n\n               png_write_row(pp, row);\n            }\n         }\n      }\n\n#ifdef PNG_TEXT_SUPPORTED\n      {\n         static char key[] = \"end marker\";\n         static char comment[] = \"end\";\n         png_text text;\n\n         /* Use a compressed text string to test the correct interaction of text\n          * compression and IDAT compression.\n          */\n         text.compression = TEXT_COMPRESSION;\n         text.key = key;\n         text.text = comment;\n         text.text_length = (sizeof comment)-1;\n         text.itxt_length = 0;\n         text.lang = 0;\n         text.lang_key = 0;\n\n         png_set_text(pp, pi, &text, 1);\n      }\n#endif\n\n      png_write_end(pp, pi);\n\n      /* And store this under the appropriate id, then clean up. */\n      store_storefile(ps, id);\n\n      store_write_reset(ps);\n   }\n\n   Catch(fault)\n   {\n      /* Use the png_store returned by the exception. This may help the compiler\n       * because 'ps' is not used in this branch of the setjmp.  Note that fault\n       * and ps will always be the same value.\n       */\n      store_write_reset(fault);\n   }\n}\n\nstatic void\nmake_size(png_store* const ps, png_byte const colour_type, int bdlo,\n    int const bdhi)\n{\n   for (; bdlo <= bdhi; ++bdlo)\n   {\n      png_uint_32 width;\n\n      for (width = 1; width <= 16; ++width)\n      {\n         png_uint_32 height;\n\n         for (height = 1; height <= 16; ++height)\n         {\n            /* The four combinations of DIY interlace and interlace or not -\n             * no interlace + DIY should be identical to no interlace with\n             * libpng doing it.\n             */\n            make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_NONE,\n               width, height, 0);\n            make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_NONE,\n               width, height, 1);\n#        ifdef PNG_WRITE_INTERLACING_SUPPORTED\n            make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,\n               width, height, 0);\n#        endif\n#        if CAN_WRITE_INTERLACE\n            /* 1.7.0 removes the hack that prevented app write of an interlaced\n             * image if WRITE_INTERLACE was not supported\n             */\n            make_size_image(ps, colour_type, DEPTH(bdlo), PNG_INTERLACE_ADAM7,\n               width, height, 1);\n#        endif\n         }\n      }\n   }\n}\n\nstatic void\nmake_size_images(png_store *ps)\n{\n   /* This is in case of errors. */\n   safecat(ps->test, sizeof ps->test, 0, \"make size images\");\n\n   /* Arguments are colour_type, low bit depth, high bit depth\n    */\n   make_size(ps, 0, 0, WRITE_BDHI);\n   make_size(ps, 2, 3, WRITE_BDHI);\n   make_size(ps, 3, 0, 3 /*palette: max 8 bits*/);\n   make_size(ps, 4, 3, WRITE_BDHI);\n   make_size(ps, 6, 3, WRITE_BDHI);\n}\n\n#ifdef PNG_READ_SUPPORTED\n/* Return a row based on image id and 'y' for checking: */\nstatic void\nstandard_row(png_const_structp pp, png_byte std[STANDARD_ROWMAX],\n   png_uint_32 id, png_uint_32 y)\n{\n   if (WIDTH_FROM_ID(id) == 0)\n      transform_row(pp, std, COL_FROM_ID(id), DEPTH_FROM_ID(id), y);\n   else\n      size_row(std, WIDTH_FROM_ID(id) * bit_size(pp, COL_FROM_ID(id),\n         DEPTH_FROM_ID(id)), y);\n}\n#endif /* PNG_READ_SUPPORTED */\n\n/* Tests - individual test cases */\n/* Like 'make_standard' but errors are deliberately introduced into the calls\n * to ensure that they get detected - it should not be possible to write an\n * invalid image with libpng!\n */\n/* TODO: the 'set' functions can probably all be made to take a\n * png_const_structp rather than a modifiable one.\n */\n#ifdef PNG_WARNINGS_SUPPORTED\nstatic void\nsBIT0_error_fn(png_structp pp, png_infop pi)\n{\n   /* 0 is invalid... */\n   png_color_8 bad;\n   bad.red = bad.green = bad.blue = bad.gray = bad.alpha = 0;\n   png_set_sBIT(pp, pi, &bad);\n}\n\nstatic void\nsBIT_error_fn(png_structp pp, png_infop pi)\n{\n   png_byte bit_depth;\n   png_color_8 bad;\n\n   if (png_get_color_type(pp, pi) == PNG_COLOR_TYPE_PALETTE)\n      bit_depth = 8;\n\n   else\n      bit_depth = png_get_bit_depth(pp, pi);\n\n   /* Now we know the bit depth we can easily generate an invalid sBIT entry */\n   bad.red = bad.green = bad.blue = bad.gray = bad.alpha =\n      (png_byte)(bit_depth+1);\n   png_set_sBIT(pp, pi, &bad);\n}\n\nstatic const struct\n{\n   void          (*fn)(png_structp, png_infop);\n   const char *msg;\n   unsigned int    warning :1; /* the error is a warning... */\n} error_test[] =\n    {\n       /* no warnings makes these errors undetectable prior to 1.7.0 */\n       { sBIT0_error_fn, \"sBIT(0): failed to detect error\",\n         PNG_LIBPNG_VER < 10700 },\n\n       { sBIT_error_fn, \"sBIT(too big): failed to detect error\",\n         PNG_LIBPNG_VER < 10700 },\n    };\n\nstatic void\nmake_error(png_store* const ps, png_byte const colour_type,\n    png_byte bit_depth, int interlace_type, int test, png_const_charp name)\n{\n   context(ps, fault);\n\n   check_interlace_type(interlace_type);\n\n   Try\n   {\n      png_infop pi;\n      const png_structp pp = set_store_for_write(ps, &pi, name);\n      png_uint_32 w, h;\n      gnu_volatile(pp)\n\n      if (pp == NULL)\n         Throw ps;\n\n      w = transform_width(pp, colour_type, bit_depth);\n      gnu_volatile(w)\n      h = transform_height(pp, colour_type, bit_depth);\n      gnu_volatile(h)\n      png_set_IHDR(pp, pi, w, h, bit_depth, colour_type, interlace_type,\n            PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n      if (colour_type == 3) /* palette */\n         init_standard_palette(ps, pp, pi, 1U << bit_depth, 0/*do tRNS*/);\n\n      /* Time for a few errors; these are in various optional chunks, the\n       * standard tests test the standard chunks pretty well.\n       */\n#     define exception__prev exception_prev_1\n#     define exception__env exception_env_1\n      Try\n      {\n         gnu_volatile(exception__prev)\n\n         /* Expect this to throw: */\n         ps->expect_error = !error_test[test].warning;\n         ps->expect_warning = error_test[test].warning;\n         ps->saw_warning = 0;\n         error_test[test].fn(pp, pi);\n\n         /* Normally the error is only detected here: */\n         png_write_info(pp, pi);\n\n         /* And handle the case where it was only a warning: */\n         if (ps->expect_warning && ps->saw_warning)\n            Throw ps;\n\n         /* If we get here there is a problem, we have success - no error or\n          * no warning - when we shouldn't have success.  Log an error.\n          */\n         store_log(ps, pp, error_test[test].msg, 1 /*error*/);\n      }\n\n      Catch (fault)\n      { /* expected exit */\n      }\n#undef exception__prev\n#undef exception__env\n\n      /* And clear these flags */\n      ps->expect_warning = 0;\n\n      if (ps->expect_error)\n         ps->expect_error = 0;\n\n      else\n      {\n         /* Now write the whole image, just to make sure that the detected, or\n          * undetected, errro has not created problems inside libpng.  This\n          * doesn't work if there was a png_error in png_write_info because that\n          * can abort before PLTE was written.\n          */\n         if (png_get_rowbytes(pp, pi) !=\n             transform_rowsize(pp, colour_type, bit_depth))\n            png_error(pp, \"row size incorrect\");\n\n         else\n         {\n            int npasses = set_write_interlace_handling(pp, interlace_type);\n            int pass;\n\n            if (npasses != npasses_from_interlace_type(pp, interlace_type))\n               png_error(pp, \"write: png_set_interlace_handling failed\");\n\n            for (pass=0; pass<npasses; ++pass)\n            {\n               png_uint_32 y;\n\n               for (y=0; y<h; ++y)\n               {\n                  png_byte buffer[TRANSFORM_ROWMAX];\n\n                  transform_row(pp, buffer, colour_type, bit_depth, y);\n\n#                 if do_own_interlace\n                     /* If do_own_interlace *and* the image is interlaced we\n                      * need a reduced interlace row; this may be reduced to\n                      * empty.\n                      */\n                     if (interlace_type == PNG_INTERLACE_ADAM7)\n                     {\n                        /* The row must not be written if it doesn't exist,\n                         * notice that there are two conditions here, either the\n                         * row isn't ever in the pass or the row would be but\n                         * isn't wide enough to contribute any pixels.  In fact\n                         * the wPass test can be used to skip the whole y loop\n                         * in this case.\n                         */\n                        if (PNG_ROW_IN_INTERLACE_PASS(y, pass) &&\n                            PNG_PASS_COLS(w, pass) > 0)\n                           interlace_row(buffer, buffer,\n                                 bit_size(pp, colour_type, bit_depth), w, pass,\n                                 0/*data always bigendian*/);\n                        else\n                           continue;\n                     }\n#                 endif /* do_own_interlace */\n\n                  png_write_row(pp, buffer);\n               }\n            }\n         } /* image writing */\n\n         png_write_end(pp, pi);\n      }\n\n      /* The following deletes the file that was just written. */\n      store_write_reset(ps);\n   }\n\n   Catch(fault)\n   {\n      store_write_reset(fault);\n   }\n}\n\nstatic int\nmake_errors(png_modifier* const pm, png_byte const colour_type,\n    int bdlo, int const bdhi)\n{\n   for (; bdlo <= bdhi; ++bdlo)\n   {\n      int interlace_type;\n\n      for (interlace_type = PNG_INTERLACE_NONE;\n           interlace_type < INTERLACE_LAST; ++interlace_type)\n      {\n         unsigned int test;\n         char name[FILE_NAME_SIZE];\n\n         standard_name(name, sizeof name, 0, colour_type, 1<<bdlo, 0,\n            interlace_type, 0, 0, do_own_interlace);\n\n         for (test=0; test<ARRAY_SIZE(error_test); ++test)\n         {\n            make_error(&pm->this, colour_type, DEPTH(bdlo), interlace_type,\n               test, name);\n\n            if (fail(pm))\n               return 0;\n         }\n      }\n   }\n\n   return 1; /* keep going */\n}\n#endif /* PNG_WARNINGS_SUPPORTED */\n\nstatic void\nperform_error_test(png_modifier *pm)\n{\n#ifdef PNG_WARNINGS_SUPPORTED /* else there are no cases that work! */\n   /* Need to do this here because we just write in this test. */\n   safecat(pm->this.test, sizeof pm->this.test, 0, \"error test\");\n\n   if (!make_errors(pm, 0, 0, WRITE_BDHI))\n      return;\n\n   if (!make_errors(pm, 2, 3, WRITE_BDHI))\n      return;\n\n   if (!make_errors(pm, 3, 0, 3))\n      return;\n\n   if (!make_errors(pm, 4, 3, WRITE_BDHI))\n      return;\n\n   if (!make_errors(pm, 6, 3, WRITE_BDHI))\n      return;\n#else\n   UNUSED(pm)\n#endif\n}\n\n/* This is just to validate the internal PNG formatting code - if this fails\n * then the warning messages the library outputs will probably be garbage.\n */\nstatic void\nperform_formatting_test(png_store *ps)\n{\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n   /* The handle into the formatting code is the RFC1123 support; this test does\n    * nothing if that is compiled out.\n    */\n   context(ps, fault);\n\n   Try\n   {\n      png_const_charp correct = \"29 Aug 2079 13:53:60 +0000\";\n      png_const_charp result;\n#     if PNG_LIBPNG_VER >= 10600\n         char timestring[29];\n#     endif\n      png_structp pp;\n      png_time pt;\n\n      pp = set_store_for_write(ps, NULL, \"libpng formatting test\");\n\n      if (pp == NULL)\n         Throw ps;\n\n\n      /* Arbitrary settings: */\n      pt.year = 2079;\n      pt.month = 8;\n      pt.day = 29;\n      pt.hour = 13;\n      pt.minute = 53;\n      pt.second = 60; /* a leap second */\n\n#     if PNG_LIBPNG_VER < 10600\n         result = png_convert_to_rfc1123(pp, &pt);\n#     else\n         if (png_convert_to_rfc1123_buffer(timestring, &pt))\n            result = timestring;\n\n         else\n            result = NULL;\n#     endif\n\n      if (result == NULL)\n         png_error(pp, \"png_convert_to_rfc1123 failed\");\n\n      if (strcmp(result, correct) != 0)\n      {\n         size_t pos = 0;\n         char msg[128];\n\n         pos = safecat(msg, sizeof msg, pos, \"png_convert_to_rfc1123(\");\n         pos = safecat(msg, sizeof msg, pos, correct);\n         pos = safecat(msg, sizeof msg, pos, \") returned: '\");\n         pos = safecat(msg, sizeof msg, pos, result);\n         pos = safecat(msg, sizeof msg, pos, \"'\");\n\n         png_error(pp, msg);\n      }\n\n      store_write_reset(ps);\n   }\n\n   Catch(fault)\n   {\n      store_write_reset(fault);\n   }\n#else\n   UNUSED(ps)\n#endif\n}\n\n#ifdef PNG_READ_SUPPORTED\n/* Because we want to use the same code in both the progressive reader and the\n * sequential reader it is necessary to deal with the fact that the progressive\n * reader callbacks only have one parameter (png_get_progressive_ptr()), so this\n * must contain all the test parameters and all the local variables directly\n * accessible to the sequential reader implementation.\n *\n * The technique adopted is to reinvent part of what Dijkstra termed a\n * 'display'; an array of pointers to the stack frames of enclosing functions so\n * that a nested function definition can access the local (C auto) variables of\n * the functions that contain its definition.  In fact C provides the first\n * pointer (the local variables - the stack frame pointer) and the last (the\n * global variables - the BCPL global vector typically implemented as global\n * addresses), this code requires one more pointer to make the display - the\n * local variables (and function call parameters) of the function that actually\n * invokes either the progressive or sequential reader.\n *\n * Perhaps confusingly this technique is confounded with classes - the\n * 'standard_display' defined here is sub-classed as the 'gamma_display' below.\n * A gamma_display is a standard_display, taking advantage of the ANSI-C\n * requirement that the pointer to the first member of a structure must be the\n * same as the pointer to the structure.  This allows us to reuse standard_\n * functions in the gamma test code; something that could not be done with\n * nested functions!\n */\ntypedef struct standard_display\n{\n   png_store*  ps;             /* Test parameters (passed to the function) */\n   png_byte    colour_type;\n   png_byte    bit_depth;\n   png_byte    red_sBIT;       /* Input data sBIT values. */\n   png_byte    green_sBIT;\n   png_byte    blue_sBIT;\n   png_byte    alpha_sBIT;\n   png_byte    interlace_type;\n   png_byte    filler;         /* Output has a filler */\n   png_uint_32 id;             /* Calculated file ID */\n   png_uint_32 w;              /* Width of image */\n   png_uint_32 h;              /* Height of image */\n   int         npasses;        /* Number of interlaced passes */\n   png_uint_32 pixel_size;     /* Width of one pixel in bits */\n   png_uint_32 bit_width;      /* Width of output row in bits */\n   size_t      cbRow;          /* Bytes in a row of the output image */\n   int         do_interlace;   /* Do interlacing internally */\n   int         littleendian;   /* App (row) data is little endian */\n   int         is_transparent; /* Transparency information was present. */\n   int         has_tRNS;       /* color type GRAY or RGB with a tRNS chunk. */\n   int         speed;          /* Doing a speed test */\n   int         use_update_info;/* Call update_info, not start_image */\n   struct\n   {\n      png_uint_16 red;\n      png_uint_16 green;\n      png_uint_16 blue;\n   }           transparent;    /* The transparent color, if set. */\n   int         npalette;       /* Number of entries in the palette. */\n   store_palette\n               palette;\n} standard_display;\n\nstatic void\nstandard_display_init(standard_display *dp, png_store* ps, png_uint_32 id,\n   int do_interlace, int use_update_info)\n{\n   memset(dp, 0, sizeof *dp);\n\n   dp->ps = ps;\n   dp->colour_type = COL_FROM_ID(id);\n   dp->bit_depth = DEPTH_FROM_ID(id);\n   if (dp->bit_depth < 1 || dp->bit_depth > 16)\n      internal_error(ps, \"internal: bad bit depth\");\n   if (dp->colour_type == 3)\n      dp->red_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT = 8;\n   else\n      dp->red_sBIT = dp->blue_sBIT = dp->green_sBIT = dp->alpha_sBIT =\n         dp->bit_depth;\n   dp->interlace_type = INTERLACE_FROM_ID(id);\n   check_interlace_type(dp->interlace_type);\n   dp->id = id;\n   /* All the rest are filled in after the read_info: */\n   dp->w = 0;\n   dp->h = 0;\n   dp->npasses = 0;\n   dp->pixel_size = 0;\n   dp->bit_width = 0;\n   dp->cbRow = 0;\n   dp->do_interlace = do_interlace;\n   dp->littleendian = 0;\n   dp->is_transparent = 0;\n   dp->speed = ps->speed;\n   dp->use_update_info = use_update_info;\n   dp->npalette = 0;\n   /* Preset the transparent color to black: */\n   memset(&dp->transparent, 0, sizeof dp->transparent);\n   /* Preset the palette to full intensity/opaque througout: */\n   memset(dp->palette, 0xff, sizeof dp->palette);\n}\n\n/* Initialize the palette fields - this must be done later because the palette\n * comes from the particular png_store_file that is selected.\n */\nstatic void\nstandard_palette_init(standard_display *dp)\n{\n   store_palette_entry *palette = store_current_palette(dp->ps, &dp->npalette);\n\n   /* The remaining entries remain white/opaque. */\n   if (dp->npalette > 0)\n   {\n      int i = dp->npalette;\n      memcpy(dp->palette, palette, i * sizeof *palette);\n\n      /* Check for a non-opaque palette entry: */\n      while (--i >= 0)\n         if (palette[i].alpha < 255)\n            break;\n\n#     ifdef __GNUC__\n         /* GCC can't handle the more obviously optimizable version. */\n         if (i >= 0)\n            dp->is_transparent = 1;\n         else\n            dp->is_transparent = 0;\n#     else\n         dp->is_transparent = (i >= 0);\n#     endif\n   }\n}\n\n/* Utility to read the palette from the PNG file and convert it into\n * store_palette format.  This returns 1 if there is any transparency in the\n * palette (it does not check for a transparent colour in the non-palette case.)\n */\nstatic int\nread_palette(store_palette palette, int *npalette, png_const_structp pp,\n   png_infop pi)\n{\n   png_colorp pal;\n   png_bytep trans_alpha;\n   int num;\n\n   pal = 0;\n   *npalette = -1;\n\n   if (png_get_PLTE(pp, pi, &pal, npalette) & PNG_INFO_PLTE)\n   {\n      int i = *npalette;\n\n      if (i <= 0 || i > 256)\n         png_error(pp, \"validate: invalid PLTE count\");\n\n      while (--i >= 0)\n      {\n         palette[i].red = pal[i].red;\n         palette[i].green = pal[i].green;\n         palette[i].blue = pal[i].blue;\n      }\n\n      /* Mark the remainder of the entries with a flag value (other than\n       * white/opaque which is the flag value stored above.)\n       */\n      memset(palette + *npalette, 126, (256-*npalette) * sizeof *palette);\n   }\n\n   else /* !png_get_PLTE */\n   {\n      if (*npalette != (-1))\n         png_error(pp, \"validate: invalid PLTE result\");\n      /* But there is no palette, so record this: */\n      *npalette = 0;\n      memset(palette, 113, sizeof (store_palette));\n   }\n\n   trans_alpha = 0;\n   num = 2; /* force error below */\n   if ((png_get_tRNS(pp, pi, &trans_alpha, &num, 0) & PNG_INFO_tRNS) != 0 &&\n      (trans_alpha != NULL || num != 1/*returns 1 for a transparent color*/) &&\n      /* Oops, if a palette tRNS gets expanded png_read_update_info (at least so\n       * far as 1.5.4) does not remove the trans_alpha pointer, only num_trans,\n       * so in the above call we get a success, we get a pointer (who knows what\n       * to) and we get num_trans == 0:\n       */\n      !(trans_alpha != NULL && num == 0)) /* TODO: fix this in libpng. */\n   {\n      int i;\n\n      /* Any of these are crash-worthy - given the implementation of\n       * png_get_tRNS up to 1.5 an app won't crash if it just checks the\n       * result above and fails to check that the variables it passed have\n       * actually been filled in!  Note that if the app were to pass the\n       * last, png_color_16p, variable too it couldn't rely on this.\n       */\n      if (trans_alpha == NULL || num <= 0 || num > 256 || num > *npalette)\n         png_error(pp, \"validate: unexpected png_get_tRNS (palette) result\");\n\n      for (i=0; i<num; ++i)\n         palette[i].alpha = trans_alpha[i];\n\n      for (num=*npalette; i<num; ++i)\n         palette[i].alpha = 255;\n\n      for (; i<256; ++i)\n         palette[i].alpha = 33; /* flag value */\n\n      return 1; /* transparency */\n   }\n\n   else\n   {\n      /* No palette transparency - just set the alpha channel to opaque. */\n      int i;\n\n      for (i=0, num=*npalette; i<num; ++i)\n         palette[i].alpha = 255;\n\n      for (; i<256; ++i)\n         palette[i].alpha = 55; /* flag value */\n\n      return 0; /* no transparency */\n   }\n}\n\n/* Utility to validate the palette if it should not have changed (the\n * non-transform case).\n */\nstatic void\nstandard_palette_validate(standard_display *dp, png_const_structp pp,\n   png_infop pi)\n{\n   int npalette;\n   store_palette palette;\n\n   if (read_palette(palette, &npalette, pp, pi) != dp->is_transparent)\n      png_error(pp, \"validate: palette transparency changed\");\n\n   if (npalette != dp->npalette)\n   {\n      size_t pos = 0;\n      char msg[64];\n\n      pos = safecat(msg, sizeof msg, pos, \"validate: palette size changed: \");\n      pos = safecatn(msg, sizeof msg, pos, dp->npalette);\n      pos = safecat(msg, sizeof msg, pos, \" -> \");\n      pos = safecatn(msg, sizeof msg, pos, npalette);\n      png_error(pp, msg);\n   }\n\n   {\n      int i = npalette; /* npalette is aliased */\n\n      while (--i >= 0)\n         if (palette[i].red != dp->palette[i].red ||\n            palette[i].green != dp->palette[i].green ||\n            palette[i].blue != dp->palette[i].blue ||\n            palette[i].alpha != dp->palette[i].alpha)\n            png_error(pp, \"validate: PLTE or tRNS chunk changed\");\n   }\n}\n\n/* By passing a 'standard_display' the progressive callbacks can be used\n * directly by the sequential code, the functions suffixed \"_imp\" are the\n * implementations, the functions without the suffix are the callbacks.\n *\n * The code for the info callback is split into two because this callback calls\n * png_read_update_info or png_start_read_image and what gets called depends on\n * whether the info needs updating (we want to test both calls in pngvalid.)\n */\nstatic void\nstandard_info_part1(standard_display *dp, png_structp pp, png_infop pi)\n{\n   if (png_get_bit_depth(pp, pi) != dp->bit_depth)\n      png_error(pp, \"validate: bit depth changed\");\n\n   if (png_get_color_type(pp, pi) != dp->colour_type)\n      png_error(pp, \"validate: color type changed\");\n\n   if (png_get_filter_type(pp, pi) != PNG_FILTER_TYPE_BASE)\n      png_error(pp, \"validate: filter type changed\");\n\n   if (png_get_interlace_type(pp, pi) != dp->interlace_type)\n      png_error(pp, \"validate: interlacing changed\");\n\n   if (png_get_compression_type(pp, pi) != PNG_COMPRESSION_TYPE_BASE)\n      png_error(pp, \"validate: compression type changed\");\n\n   dp->w = png_get_image_width(pp, pi);\n\n   if (dp->w != standard_width(pp, dp->id))\n      png_error(pp, \"validate: image width changed\");\n\n   dp->h = png_get_image_height(pp, pi);\n\n   if (dp->h != standard_height(pp, dp->id))\n      png_error(pp, \"validate: image height changed\");\n\n   /* Record (but don't check at present) the input sBIT according to the colour\n    * type information.\n    */\n   {\n      png_color_8p sBIT = 0;\n\n      if (png_get_sBIT(pp, pi, &sBIT) & PNG_INFO_sBIT)\n      {\n         int sBIT_invalid = 0;\n\n         if (sBIT == 0)\n            png_error(pp, \"validate: unexpected png_get_sBIT result\");\n\n         if (dp->colour_type & PNG_COLOR_MASK_COLOR)\n         {\n            if (sBIT->red == 0 || sBIT->red > dp->bit_depth)\n               sBIT_invalid = 1;\n            else\n               dp->red_sBIT = sBIT->red;\n\n            if (sBIT->green == 0 || sBIT->green > dp->bit_depth)\n               sBIT_invalid = 1;\n            else\n               dp->green_sBIT = sBIT->green;\n\n            if (sBIT->blue == 0 || sBIT->blue > dp->bit_depth)\n               sBIT_invalid = 1;\n            else\n               dp->blue_sBIT = sBIT->blue;\n         }\n\n         else /* !COLOR */\n         {\n            if (sBIT->gray == 0 || sBIT->gray > dp->bit_depth)\n               sBIT_invalid = 1;\n            else\n               dp->blue_sBIT = dp->green_sBIT = dp->red_sBIT = sBIT->gray;\n         }\n\n         /* All 8 bits in tRNS for a palette image are significant - see the\n          * spec.\n          */\n         if (dp->colour_type & PNG_COLOR_MASK_ALPHA)\n         {\n            if (sBIT->alpha == 0 || sBIT->alpha > dp->bit_depth)\n               sBIT_invalid = 1;\n            else\n               dp->alpha_sBIT = sBIT->alpha;\n         }\n\n         if (sBIT_invalid)\n            png_error(pp, \"validate: sBIT value out of range\");\n      }\n   }\n\n   /* Important: this is validating the value *before* any transforms have been\n    * put in place.  It doesn't matter for the standard tests, where there are\n    * no transforms, but it does for other tests where rowbytes may change after\n    * png_read_update_info.\n    */\n   if (png_get_rowbytes(pp, pi) != standard_rowsize(pp, dp->id))\n      png_error(pp, \"validate: row size changed\");\n\n   /* Validate the colour type 3 palette (this can be present on other color\n    * types.)\n    */\n   standard_palette_validate(dp, pp, pi);\n\n   /* In any case always check for a tranparent color (notice that the\n    * colour type 3 case must not give a successful return on the get_tRNS call\n    * with these arguments!)\n    */\n   {\n      png_color_16p trans_color = 0;\n\n      if (png_get_tRNS(pp, pi, 0, 0, &trans_color) & PNG_INFO_tRNS)\n      {\n         if (trans_color == 0)\n            png_error(pp, \"validate: unexpected png_get_tRNS (color) result\");\n\n         switch (dp->colour_type)\n         {\n         case 0:\n            dp->transparent.red = dp->transparent.green = dp->transparent.blue =\n               trans_color->gray;\n            dp->has_tRNS = 1;\n            break;\n\n         case 2:\n            dp->transparent.red = trans_color->red;\n            dp->transparent.green = trans_color->green;\n            dp->transparent.blue = trans_color->blue;\n            dp->has_tRNS = 1;\n            break;\n\n         case 3:\n            /* Not expected because it should result in the array case\n             * above.\n             */\n            png_error(pp, \"validate: unexpected png_get_tRNS result\");\n            break;\n\n         default:\n            png_error(pp, \"validate: invalid tRNS chunk with alpha image\");\n         }\n      }\n   }\n\n   /* Read the number of passes - expected to match the value used when\n    * creating the image (interlaced or not).  This has the side effect of\n    * turning on interlace handling (if do_interlace is not set.)\n    */\n   dp->npasses = npasses_from_interlace_type(pp, dp->interlace_type);\n   if (!dp->do_interlace)\n   {\n#     ifdef PNG_READ_INTERLACING_SUPPORTED\n         if (dp->npasses != png_set_interlace_handling(pp))\n            png_error(pp, \"validate: file changed interlace type\");\n#     else /* !READ_INTERLACING */\n         /* This should never happen: the relevant tests (!do_interlace) should\n          * not be run.\n          */\n         if (dp->npasses > 1)\n            png_error(pp, \"validate: no libpng interlace support\");\n#     endif /* !READ_INTERLACING */\n   }\n\n   /* Caller calls png_read_update_info or png_start_read_image now, then calls\n    * part2.\n    */\n}\n\n/* This must be called *after* the png_read_update_info call to get the correct\n * 'rowbytes' value, otherwise png_get_rowbytes will refer to the untransformed\n * image.\n */\nstatic void\nstandard_info_part2(standard_display *dp, png_const_structp pp,\n    png_const_infop pi, int nImages)\n{\n   /* Record cbRow now that it can be found. */\n   {\n      png_byte ct = png_get_color_type(pp, pi);\n      png_byte bd = png_get_bit_depth(pp, pi);\n\n      if (bd >= 8 && (ct == PNG_COLOR_TYPE_RGB || ct == PNG_COLOR_TYPE_GRAY) &&\n          dp->filler)\n          ct |= 4; /* handle filler as faked alpha channel */\n\n      dp->pixel_size = bit_size(pp, ct, bd);\n   }\n   dp->bit_width = png_get_image_width(pp, pi) * dp->pixel_size;\n   dp->cbRow = png_get_rowbytes(pp, pi);\n\n   /* Validate the rowbytes here again. */\n   if (dp->cbRow != (dp->bit_width+7)/8)\n      png_error(pp, \"bad png_get_rowbytes calculation\");\n\n   /* Then ensure there is enough space for the output image(s). */\n   store_ensure_image(dp->ps, pp, nImages, dp->cbRow, dp->h);\n}\n\nstatic void\nstandard_info_imp(standard_display *dp, png_structp pp, png_infop pi,\n    int nImages)\n{\n   /* Note that the validation routine has the side effect of turning on\n    * interlace handling in the subsequent code.\n    */\n   standard_info_part1(dp, pp, pi);\n\n   /* And the info callback has to call this (or png_read_update_info - see\n    * below in the png_modifier code for that variant.\n    */\n   if (dp->use_update_info)\n   {\n      /* For debugging the effect of multiple calls: */\n      int i = dp->use_update_info;\n      while (i-- > 0)\n         png_read_update_info(pp, pi);\n   }\n\n   else\n      png_start_read_image(pp);\n\n   /* Validate the height, width and rowbytes plus ensure that sufficient buffer\n    * exists for decoding the image.\n    */\n   standard_info_part2(dp, pp, pi, nImages);\n}\n\nstatic void PNGCBAPI\nstandard_info(png_structp pp, png_infop pi)\n{\n   standard_display *dp = voidcast(standard_display*,\n      png_get_progressive_ptr(pp));\n\n   /* Call with nImages==1 because the progressive reader can only produce one\n    * image.\n    */\n   standard_info_imp(dp, pp, pi, 1 /*only one image*/);\n}\n\nstatic void PNGCBAPI\nprogressive_row(png_structp ppIn, png_bytep new_row, png_uint_32 y, int pass)\n{\n   png_const_structp pp = ppIn;\n   const standard_display *dp = voidcast(standard_display*,\n      png_get_progressive_ptr(pp));\n\n   /* When handling interlacing some rows will be absent in each pass, the\n    * callback still gets called, but with a NULL pointer.  This is checked\n    * in the 'else' clause below.  We need our own 'cbRow', but we can't call\n    * png_get_rowbytes because we got no info structure.\n    */\n   if (new_row != NULL)\n   {\n      png_bytep row;\n\n      /* In the case where the reader doesn't do the interlace it gives\n       * us the y in the sub-image:\n       */\n      if (dp->do_interlace && dp->interlace_type == PNG_INTERLACE_ADAM7)\n      {\n#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED\n         /* Use this opportunity to validate the png 'current' APIs: */\n         if (y != png_get_current_row_number(pp))\n            png_error(pp, \"png_get_current_row_number is broken\");\n\n         if (pass != png_get_current_pass_number(pp))\n            png_error(pp, \"png_get_current_pass_number is broken\");\n#endif /* USER_TRANSFORM_INFO */\n\n         y = PNG_ROW_FROM_PASS_ROW(y, pass);\n      }\n\n      /* Validate this just in case. */\n      if (y >= dp->h)\n         png_error(pp, \"invalid y to progressive row callback\");\n\n      row = store_image_row(dp->ps, pp, 0, y);\n\n      /* Combine the new row into the old: */\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n      if (dp->do_interlace)\n#endif /* READ_INTERLACING */\n      {\n         if (dp->interlace_type == PNG_INTERLACE_ADAM7)\n            deinterlace_row(row, new_row, dp->pixel_size, dp->w, pass,\n                  dp->littleendian);\n         else\n            row_copy(row, new_row, dp->pixel_size * dp->w, dp->littleendian);\n      }\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n      else\n         png_progressive_combine_row(pp, row, new_row);\n#endif /* PNG_READ_INTERLACING_SUPPORTED */\n   }\n\n   else if (dp->interlace_type == PNG_INTERLACE_ADAM7 &&\n       PNG_ROW_IN_INTERLACE_PASS(y, pass) &&\n       PNG_PASS_COLS(dp->w, pass) > 0)\n      png_error(pp, \"missing row in progressive de-interlacing\");\n}\n\nstatic void\nsequential_row(standard_display *dp, png_structp pp, png_infop pi,\n    const int iImage, const int iDisplay)\n{\n   const int         npasses = dp->npasses;\n   const int         do_interlace = dp->do_interlace &&\n      dp->interlace_type == PNG_INTERLACE_ADAM7;\n   const png_uint_32 height = standard_height(pp, dp->id);\n   const png_uint_32 width = standard_width(pp, dp->id);\n   const png_store*  ps = dp->ps;\n   int pass;\n\n   for (pass=0; pass<npasses; ++pass)\n   {\n      png_uint_32 y;\n      png_uint_32 wPass = PNG_PASS_COLS(width, pass);\n\n      for (y=0; y<height; ++y)\n      {\n         if (do_interlace)\n         {\n            /* wPass may be zero or this row may not be in this pass.\n             * png_read_row must not be called in either case.\n             */\n            if (wPass > 0 && PNG_ROW_IN_INTERLACE_PASS(y, pass))\n            {\n               /* Read the row into a pair of temporary buffers, then do the\n                * merge here into the output rows.\n                */\n               png_byte row[STANDARD_ROWMAX], display[STANDARD_ROWMAX];\n\n               /* The following aids (to some extent) error detection - we can\n                * see where png_read_row wrote.  Use opposite values in row and\n                * display to make this easier.  Don't use 0xff (which is used in\n                * the image write code to fill unused bits) or 0 (which is a\n                * likely value to overwrite unused bits with).\n                */\n               memset(row, 0xc5, sizeof row);\n               memset(display, 0x5c, sizeof display);\n\n               png_read_row(pp, row, display);\n\n               if (iImage >= 0)\n                  deinterlace_row(store_image_row(ps, pp, iImage, y), row,\n                     dp->pixel_size, dp->w, pass, dp->littleendian);\n\n               if (iDisplay >= 0)\n                  deinterlace_row(store_image_row(ps, pp, iDisplay, y), display,\n                     dp->pixel_size, dp->w, pass, dp->littleendian);\n            }\n         }\n         else\n            png_read_row(pp,\n               iImage >= 0 ? store_image_row(ps, pp, iImage, y) : NULL,\n               iDisplay >= 0 ? store_image_row(ps, pp, iDisplay, y) : NULL);\n      }\n   }\n\n   /* And finish the read operation (only really necessary if the caller wants\n    * to find additional data in png_info from chunks after the last IDAT.)\n    */\n   png_read_end(pp, pi);\n}\n\n#ifdef PNG_TEXT_SUPPORTED\nstatic void\nstandard_check_text(png_const_structp pp, png_const_textp tp,\n   png_const_charp keyword, png_const_charp text)\n{\n   char msg[1024];\n   size_t pos = safecat(msg, sizeof msg, 0, \"text: \");\n   size_t ok;\n\n   pos = safecat(msg, sizeof msg, pos, keyword);\n   pos = safecat(msg, sizeof msg, pos, \": \");\n   ok = pos;\n\n   if (tp->compression != TEXT_COMPRESSION)\n   {\n      char buf[64];\n\n      sprintf(buf, \"compression [%d->%d], \", TEXT_COMPRESSION,\n         tp->compression);\n      pos = safecat(msg, sizeof msg, pos, buf);\n   }\n\n   if (tp->key == NULL || strcmp(tp->key, keyword) != 0)\n   {\n      pos = safecat(msg, sizeof msg, pos, \"keyword \\\"\");\n      if (tp->key != NULL)\n      {\n         pos = safecat(msg, sizeof msg, pos, tp->key);\n         pos = safecat(msg, sizeof msg, pos, \"\\\", \");\n      }\n\n      else\n         pos = safecat(msg, sizeof msg, pos, \"null, \");\n   }\n\n   if (tp->text == NULL)\n      pos = safecat(msg, sizeof msg, pos, \"text lost, \");\n\n   else\n   {\n      if (tp->text_length != strlen(text))\n      {\n         char buf[64];\n         sprintf(buf, \"text length changed[%lu->%lu], \",\n            (unsigned long)strlen(text), (unsigned long)tp->text_length);\n         pos = safecat(msg, sizeof msg, pos, buf);\n      }\n\n      if (strcmp(tp->text, text) != 0)\n      {\n         pos = safecat(msg, sizeof msg, pos, \"text becomes \\\"\");\n         pos = safecat(msg, sizeof msg, pos, tp->text);\n         pos = safecat(msg, sizeof msg, pos, \"\\\" (was \\\"\");\n         pos = safecat(msg, sizeof msg, pos, text);\n         pos = safecat(msg, sizeof msg, pos, \"\\\"), \");\n      }\n   }\n\n   if (tp->itxt_length != 0)\n      pos = safecat(msg, sizeof msg, pos, \"iTXt length set, \");\n\n   if (tp->lang != NULL)\n   {\n      pos = safecat(msg, sizeof msg, pos, \"iTXt language \\\"\");\n      pos = safecat(msg, sizeof msg, pos, tp->lang);\n      pos = safecat(msg, sizeof msg, pos, \"\\\", \");\n   }\n\n   if (tp->lang_key != NULL)\n   {\n      pos = safecat(msg, sizeof msg, pos, \"iTXt keyword \\\"\");\n      pos = safecat(msg, sizeof msg, pos, tp->lang_key);\n      pos = safecat(msg, sizeof msg, pos, \"\\\", \");\n   }\n\n   if (pos > ok)\n   {\n      msg[pos-2] = '\\0'; /* Remove the \", \" at the end */\n      png_error(pp, msg);\n   }\n}\n\nstatic void\nstandard_text_validate(standard_display *dp, png_const_structp pp,\n   png_infop pi, int check_end)\n{\n   png_textp tp = NULL;\n   png_uint_32 num_text = png_get_text(pp, pi, &tp, NULL);\n\n   if (num_text == 2 && tp != NULL)\n   {\n      standard_check_text(pp, tp, \"image name\", dp->ps->current->name);\n\n      /* This exists because prior to 1.5.18 the progressive reader left the\n       * png_struct z_stream unreset at the end of the image, so subsequent\n       * attempts to use it simply returns Z_STREAM_END.\n       */\n      if (check_end)\n         standard_check_text(pp, tp+1, \"end marker\", \"end\");\n   }\n\n   else\n   {\n      char msg[64];\n\n      sprintf(msg, \"expected two text items, got %lu\",\n         (unsigned long)num_text);\n      png_error(pp, msg);\n   }\n}\n#else\n#  define standard_text_validate(dp,pp,pi,check_end) ((void)0)\n#endif\n\nstatic void\nstandard_row_validate(standard_display *dp, png_const_structp pp,\n   int iImage, int iDisplay, png_uint_32 y)\n{\n   int where;\n   png_byte std[STANDARD_ROWMAX];\n\n   /* The row must be pre-initialized to the magic number here for the size\n    * tests to pass:\n    */\n   memset(std, 178, sizeof std);\n   standard_row(pp, std, dp->id, y);\n\n   /* At the end both the 'row' and 'display' arrays should end up identical.\n    * In earlier passes 'row' will be partially filled in, with only the pixels\n    * that have been read so far, but 'display' will have those pixels\n    * replicated to fill the unread pixels while reading an interlaced image.\n    */\n   if (iImage >= 0 &&\n      (where = pixel_cmp(std, store_image_row(dp->ps, pp, iImage, y),\n            dp->bit_width)) != 0)\n   {\n      char msg[64];\n      sprintf(msg, \"PNG image row[%lu][%d] changed from %.2x to %.2x\",\n         (unsigned long)y, where-1, std[where-1],\n         store_image_row(dp->ps, pp, iImage, y)[where-1]);\n      png_error(pp, msg);\n   }\n\n   if (iDisplay >= 0 &&\n      (where = pixel_cmp(std, store_image_row(dp->ps, pp, iDisplay, y),\n         dp->bit_width)) != 0)\n   {\n      char msg[64];\n      sprintf(msg, \"display row[%lu][%d] changed from %.2x to %.2x\",\n         (unsigned long)y, where-1, std[where-1],\n         store_image_row(dp->ps, pp, iDisplay, y)[where-1]);\n      png_error(pp, msg);\n   }\n}\n\nstatic void\nstandard_image_validate(standard_display *dp, png_const_structp pp, int iImage,\n    int iDisplay)\n{\n   png_uint_32 y;\n\n   if (iImage >= 0)\n      store_image_check(dp->ps, pp, iImage);\n\n   if (iDisplay >= 0)\n      store_image_check(dp->ps, pp, iDisplay);\n\n   for (y=0; y<dp->h; ++y)\n      standard_row_validate(dp, pp, iImage, iDisplay, y);\n\n   /* This avoids false positives if the validation code is never called! */\n   dp->ps->validated = 1;\n}\n\nstatic void PNGCBAPI\nstandard_end(png_structp ppIn, png_infop pi)\n{\n   png_const_structp pp = ppIn;\n   standard_display *dp = voidcast(standard_display*,\n      png_get_progressive_ptr(pp));\n\n   UNUSED(pi)\n\n   /* Validate the image - progressive reading only produces one variant for\n    * interlaced images.\n    */\n   standard_text_validate(dp, pp, pi,\n      PNG_LIBPNG_VER >= 10518/*check_end: see comments above*/);\n   standard_image_validate(dp, pp, 0, -1);\n}\n\n/* A single test run checking the standard image to ensure it is not damaged. */\nstatic void\nstandard_test(png_store* const psIn, png_uint_32 const id,\n   int do_interlace, int use_update_info)\n{\n   standard_display d;\n   context(psIn, fault);\n\n   /* Set up the display (stack frame) variables from the arguments to the\n    * function and initialize the locals that are filled in later.\n    */\n   standard_display_init(&d, psIn, id, do_interlace, use_update_info);\n\n   /* Everything is protected by a Try/Catch.  The functions called also\n    * typically have local Try/Catch blocks.\n    */\n   Try\n   {\n      png_structp pp;\n      png_infop pi;\n\n      /* Get a png_struct for reading the image. This will throw an error if it\n       * fails, so we don't need to check the result.\n       */\n      pp = set_store_for_read(d.ps, &pi, d.id,\n         d.do_interlace ?  (d.ps->progressive ?\n            \"pngvalid progressive deinterlacer\" :\n            \"pngvalid sequential deinterlacer\") : (d.ps->progressive ?\n               \"progressive reader\" : \"sequential reader\"));\n\n      /* Initialize the palette correctly from the png_store_file. */\n      standard_palette_init(&d);\n\n      /* Introduce the correct read function. */\n      if (d.ps->progressive)\n      {\n         png_set_progressive_read_fn(pp, &d, standard_info, progressive_row,\n            standard_end);\n\n         /* Now feed data into the reader until we reach the end: */\n         store_progressive_read(d.ps, pp, pi);\n      }\n      else\n      {\n         /* Note that this takes the store, not the display. */\n         png_set_read_fn(pp, d.ps, store_read);\n\n         /* Check the header values: */\n         png_read_info(pp, pi);\n\n         /* The code tests both versions of the images that the sequential\n          * reader can produce.\n          */\n         standard_info_imp(&d, pp, pi, 2 /*images*/);\n\n         /* Need the total bytes in the image below; we can't get to this point\n          * unless the PNG file values have been checked against the expected\n          * values.\n          */\n         {\n            sequential_row(&d, pp, pi, 0, 1);\n\n            /* After the last pass loop over the rows again to check that the\n             * image is correct.\n             */\n            if (!d.speed)\n            {\n               standard_text_validate(&d, pp, pi, 1/*check_end*/);\n               standard_image_validate(&d, pp, 0, 1);\n            }\n            else\n               d.ps->validated = 1;\n         }\n      }\n\n      /* Check for validation. */\n      if (!d.ps->validated)\n         png_error(pp, \"image read failed silently\");\n\n      /* Successful completion. */\n   }\n\n   Catch(fault)\n      d.ps = fault; /* make sure this hasn't been clobbered. */\n\n   /* In either case clean up the store. */\n   store_read_reset(d.ps);\n}\n\nstatic int\ntest_standard(png_modifier* const pm, png_byte const colour_type,\n    int bdlo, int const bdhi)\n{\n   for (; bdlo <= bdhi; ++bdlo)\n   {\n      int interlace_type;\n\n      for (interlace_type = PNG_INTERLACE_NONE;\n           interlace_type < INTERLACE_LAST; ++interlace_type)\n      {\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            interlace_type, 0, 0, 0), do_read_interlace, pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n      }\n   }\n\n   return 1; /* keep going */\n}\n\nstatic void\nperform_standard_test(png_modifier *pm)\n{\n   /* Test each colour type over the valid range of bit depths (expressed as\n    * log2(bit_depth) in turn, stop as soon as any error is detected.\n    */\n   if (!test_standard(pm, 0, 0, READ_BDHI))\n      return;\n\n   if (!test_standard(pm, 2, 3, READ_BDHI))\n      return;\n\n   if (!test_standard(pm, 3, 0, 3))\n      return;\n\n   if (!test_standard(pm, 4, 3, READ_BDHI))\n      return;\n\n   if (!test_standard(pm, 6, 3, READ_BDHI))\n      return;\n}\n\n\n/********************************** SIZE TESTS ********************************/\nstatic int\ntest_size(png_modifier* const pm, png_byte const colour_type,\n    int bdlo, int const bdhi)\n{\n   /* Run the tests on each combination.\n    *\n    * NOTE: on my 32 bit x86 each of the following blocks takes\n    * a total of 3.5 seconds if done across every combo of bit depth\n    * width and height.  This is a waste of time in practice, hence the\n    * hinc and winc stuff:\n    */\n   static const png_byte hinc[] = {1, 3, 11, 1, 5};\n   static const png_byte winc[] = {1, 9, 5, 7, 1};\n   const int save_bdlo = bdlo;\n\n   for (; bdlo <= bdhi; ++bdlo)\n   {\n      png_uint_32 h, w;\n\n      for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])\n      {\n         /* First test all the 'size' images against the sequential\n          * reader using libpng to deinterlace (where required.)  This\n          * validates the write side of libpng.  There are four possibilities\n          * to validate.\n          */\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_NONE, w, h, 0), 0/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_NONE, w, h, 1), 0/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n\n         /* Now validate the interlaced read side - do_interlace true,\n          * in the progressive case this does actually make a difference\n          * to the code used in the non-interlaced case too.\n          */\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_NONE, w, h, 0), 1/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n\n#     if CAN_WRITE_INTERLACE\n         /* Validate the pngvalid code itself: */\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_ADAM7, w, h, 1), 1/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n#     endif\n      }\n   }\n\n   /* Now do the tests of libpng interlace handling, after we have made sure\n    * that the pngvalid version works:\n    */\n   for (bdlo = save_bdlo; bdlo <= bdhi; ++bdlo)\n   {\n      png_uint_32 h, w;\n\n      for (h=1; h<=16; h+=hinc[bdlo]) for (w=1; w<=16; w+=winc[bdlo])\n      {\n#     ifdef PNG_READ_INTERLACING_SUPPORTED\n         /* Test with pngvalid generated interlaced images first; we have\n          * already verify these are ok (unless pngvalid has self-consistent\n          * read/write errors, which is unlikely), so this detects errors in the\n          * read side first:\n          */\n#     if CAN_WRITE_INTERLACE\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_ADAM7, w, h, 1), 0/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n#     endif\n#     endif /* READ_INTERLACING */\n\n#     ifdef PNG_WRITE_INTERLACING_SUPPORTED\n         /* Test the libpng write side against the pngvalid read side: */\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_ADAM7, w, h, 0), 1/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n#     endif\n\n#     ifdef PNG_READ_INTERLACING_SUPPORTED\n#     ifdef PNG_WRITE_INTERLACING_SUPPORTED\n         /* Test both together: */\n         standard_test(&pm->this, FILEID(colour_type, DEPTH(bdlo), 0/*palette*/,\n            PNG_INTERLACE_ADAM7, w, h, 0), 0/*do_interlace*/,\n            pm->use_update_info);\n\n         if (fail(pm))\n            return 0;\n#     endif\n#     endif /* READ_INTERLACING */\n      }\n   }\n\n   return 1; /* keep going */\n}\n\nstatic void\nperform_size_test(png_modifier *pm)\n{\n   /* Test each colour type over the valid range of bit depths (expressed as\n    * log2(bit_depth) in turn, stop as soon as any error is detected.\n    */\n   if (!test_size(pm, 0, 0, READ_BDHI))\n      return;\n\n   if (!test_size(pm, 2, 3, READ_BDHI))\n      return;\n\n   /* For the moment don't do the palette test - it's a waste of time when\n    * compared to the grayscale test.\n    */\n#if 0\n   if (!test_size(pm, 3, 0, 3))\n      return;\n#endif\n\n   if (!test_size(pm, 4, 3, READ_BDHI))\n      return;\n\n   if (!test_size(pm, 6, 3, READ_BDHI))\n      return;\n}\n\n\n/******************************* TRANSFORM TESTS ******************************/\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n/* A set of tests to validate libpng image transforms.  The possibilities here\n * are legion because the transforms can be combined in a combinatorial\n * fashion.  To deal with this some measure of restraint is required, otherwise\n * the tests would take forever.\n */\ntypedef struct image_pixel\n{\n   /* A local (pngvalid) representation of a PNG pixel, in all its\n    * various forms.\n    */\n   unsigned int red, green, blue, alpha; /* For non-palette images. */\n   unsigned int palette_index;           /* For a palette image. */\n   png_byte     colour_type;             /* As in the spec. */\n   png_byte     bit_depth;               /* Defines bit size in row */\n   png_byte     sample_depth;            /* Scale of samples */\n   unsigned int have_tRNS :1;            /* tRNS chunk may need processing */\n   unsigned int swap_rgb :1;             /* RGB swapped to BGR */\n   unsigned int alpha_first :1;          /* Alpha at start, not end */\n   unsigned int alpha_inverted :1;       /* Alpha channel inverted */\n   unsigned int mono_inverted :1;        /* Gray channel inverted */\n   unsigned int swap16 :1;               /* Byte swap 16-bit components */\n   unsigned int littleendian :1;         /* High bits on right */\n   unsigned int sig_bits :1;             /* Pixel shifted (sig bits only) */\n\n   /* For checking the code calculates double precision floating point values\n    * along with an error value, accumulated from the transforms.  Because an\n    * sBIT setting allows larger error bounds (indeed, by the spec, apparently\n    * up to just less than +/-1 in the scaled value) the *lowest* sBIT for each\n    * channel is stored.  This sBIT value is folded in to the stored error value\n    * at the end of the application of the transforms to the pixel.\n    *\n    * If sig_bits is set above the red, green, blue and alpha values have been\n    * scaled so they only contain the significant bits of the component values.\n    */\n   double   redf, greenf, bluef, alphaf;\n   double   rede, greene, bluee, alphae;\n   png_byte red_sBIT, green_sBIT, blue_sBIT, alpha_sBIT;\n} image_pixel;\n\n/* Shared utility function, see below. */\nstatic void\nimage_pixel_setf(image_pixel *this, unsigned int rMax, unsigned int gMax,\n        unsigned int bMax, unsigned int aMax)\n{\n   this->redf = this->red / (double)rMax;\n   this->greenf = this->green / (double)gMax;\n   this->bluef = this->blue / (double)bMax;\n   this->alphaf = this->alpha / (double)aMax;\n\n   if (this->red < rMax)\n      this->rede = this->redf * DBL_EPSILON;\n   else\n      this->rede = 0;\n   if (this->green < gMax)\n      this->greene = this->greenf * DBL_EPSILON;\n   else\n      this->greene = 0;\n   if (this->blue < bMax)\n      this->bluee = this->bluef * DBL_EPSILON;\n   else\n      this->bluee = 0;\n   if (this->alpha < aMax)\n      this->alphae = this->alphaf * DBL_EPSILON;\n   else\n      this->alphae = 0;\n}\n\n/* Initialize the structure for the next pixel - call this before doing any\n * transforms and call it for each pixel since all the fields may need to be\n * reset.\n */\nstatic void\nimage_pixel_init(image_pixel *this, png_const_bytep row, png_byte colour_type,\n    png_byte bit_depth, png_uint_32 x, store_palette palette,\n    const image_pixel *format /*from pngvalid transform of input*/)\n{\n   const png_byte sample_depth = (png_byte)(colour_type ==\n      PNG_COLOR_TYPE_PALETTE ? 8 : bit_depth);\n   const unsigned int max = (1U<<sample_depth)-1;\n   const int swap16 = (format != 0 && format->swap16);\n   const int littleendian = (format != 0 && format->littleendian);\n   const int sig_bits = (format != 0 && format->sig_bits);\n\n   /* Initially just set everything to the same number and the alpha to opaque.\n    * Note that this currently assumes a simple palette where entry x has colour\n    * rgb(x,x,x)!\n    */\n   this->palette_index = this->red = this->green = this->blue =\n      sample(row, colour_type, bit_depth, x, 0, swap16, littleendian);\n   this->alpha = max;\n   this->red_sBIT = this->green_sBIT = this->blue_sBIT = this->alpha_sBIT =\n      sample_depth;\n\n   /* Then override as appropriate: */\n   if (colour_type == 3) /* palette */\n   {\n      /* This permits the caller to default to the sample value. */\n      if (palette != 0)\n      {\n         const unsigned int i = this->palette_index;\n\n         this->red = palette[i].red;\n         this->green = palette[i].green;\n         this->blue = palette[i].blue;\n         this->alpha = palette[i].alpha;\n      }\n   }\n\n   else /* not palette */\n   {\n      unsigned int i = 0;\n\n      if ((colour_type & 4) != 0 && format != 0 && format->alpha_first)\n      {\n         this->alpha = this->red;\n         /* This handles the gray case for 'AG' pixels */\n         this->palette_index = this->red = this->green = this->blue =\n            sample(row, colour_type, bit_depth, x, 1, swap16, littleendian);\n         i = 1;\n      }\n\n      if (colour_type & 2)\n      {\n         /* Green is second for both BGR and RGB: */\n         this->green = sample(row, colour_type, bit_depth, x, ++i, swap16,\n                 littleendian);\n\n         if (format != 0 && format->swap_rgb) /* BGR */\n             this->red = sample(row, colour_type, bit_depth, x, ++i, swap16,\n                     littleendian);\n         else\n             this->blue = sample(row, colour_type, bit_depth, x, ++i, swap16,\n                     littleendian);\n      }\n\n      else /* grayscale */ if (format != 0 && format->mono_inverted)\n         this->red = this->green = this->blue = this->red ^ max;\n\n      if ((colour_type & 4) != 0) /* alpha */\n      {\n         if (format == 0 || !format->alpha_first)\n             this->alpha = sample(row, colour_type, bit_depth, x, ++i, swap16,\n                     littleendian);\n\n         if (format != 0 && format->alpha_inverted)\n            this->alpha ^= max;\n      }\n   }\n\n   /* Calculate the scaled values, these are simply the values divided by\n    * 'max' and the error is initialized to the double precision epsilon value\n    * from the header file.\n    */\n   image_pixel_setf(this,\n      sig_bits ? (1U << format->red_sBIT)-1 : max,\n      sig_bits ? (1U << format->green_sBIT)-1 : max,\n      sig_bits ? (1U << format->blue_sBIT)-1 : max,\n      sig_bits ? (1U << format->alpha_sBIT)-1 : max);\n\n   /* Store the input information for use in the transforms - these will\n    * modify the information.\n    */\n   this->colour_type = colour_type;\n   this->bit_depth = bit_depth;\n   this->sample_depth = sample_depth;\n   this->have_tRNS = 0;\n   this->swap_rgb = 0;\n   this->alpha_first = 0;\n   this->alpha_inverted = 0;\n   this->mono_inverted = 0;\n   this->swap16 = 0;\n   this->littleendian = 0;\n   this->sig_bits = 0;\n}\n\n#if defined PNG_READ_EXPAND_SUPPORTED || defined PNG_READ_GRAY_TO_RGB_SUPPORTED\\\n   || defined PNG_READ_EXPAND_SUPPORTED || defined PNG_READ_EXPAND_16_SUPPORTED\\\n   || defined PNG_READ_BACKGROUND_SUPPORTED\n/* Convert a palette image to an rgb image.  This necessarily converts the tRNS\n * chunk at the same time, because the tRNS will be in palette form.  The way\n * palette validation works means that the original palette is never updated,\n * instead the image_pixel value from the row contains the RGB of the\n * corresponding palette entry and *this* is updated.  Consequently this routine\n * only needs to change the colour type information.\n */\nstatic void\nimage_pixel_convert_PLTE(image_pixel *this)\n{\n   if (this->colour_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      if (this->have_tRNS)\n      {\n         this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;\n         this->have_tRNS = 0;\n      }\n      else\n         this->colour_type = PNG_COLOR_TYPE_RGB;\n\n      /* The bit depth of the row changes at this point too (notice that this is\n       * the row format, not the sample depth, which is separate.)\n       */\n      this->bit_depth = 8;\n   }\n}\n\n/* Add an alpha channel; this will import the tRNS information because tRNS is\n * not valid in an alpha image.  The bit depth will invariably be set to at\n * least 8 prior to 1.7.0.  Palette images will be converted to alpha (using\n * the above API).  With png_set_background the alpha channel is never expanded\n * but this routine is used by pngvalid to simplify code; 'for_background'\n * records this.\n */\nstatic void\nimage_pixel_add_alpha(image_pixel *this, const standard_display *display,\n   int for_background)\n{\n   if (this->colour_type == PNG_COLOR_TYPE_PALETTE)\n      image_pixel_convert_PLTE(this);\n\n   if ((this->colour_type & PNG_COLOR_MASK_ALPHA) == 0)\n   {\n      if (this->colour_type == PNG_COLOR_TYPE_GRAY)\n      {\n#        if PNG_LIBPNG_VER < 10700\n            if (!for_background && this->bit_depth < 8)\n               this->bit_depth = this->sample_depth = 8;\n#        endif\n\n         if (this->have_tRNS)\n         {\n            /* After 1.7 the expansion of bit depth only happens if there is a\n             * tRNS chunk to expand at this point.\n             */\n#           if PNG_LIBPNG_VER >= 10700\n               if (!for_background && this->bit_depth < 8)\n                  this->bit_depth = this->sample_depth = 8;\n#           endif\n\n            this->have_tRNS = 0;\n\n            /* Check the input, original, channel value here against the\n             * original tRNS gray chunk valie.\n             */\n            if (this->red == display->transparent.red)\n               this->alphaf = 0;\n            else\n               this->alphaf = 1;\n         }\n         else\n            this->alphaf = 1;\n\n         this->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA;\n      }\n\n      else if (this->colour_type == PNG_COLOR_TYPE_RGB)\n      {\n         if (this->have_tRNS)\n         {\n            this->have_tRNS = 0;\n\n            /* Again, check the exact input values, not the current transformed\n             * value!\n             */\n            if (this->red == display->transparent.red &&\n               this->green == display->transparent.green &&\n               this->blue == display->transparent.blue)\n               this->alphaf = 0;\n            else\n               this->alphaf = 1;\n         }\n         else\n            this->alphaf = 1;\n\n         this->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;\n      }\n\n      /* The error in the alpha is zero and the sBIT value comes from the\n       * original sBIT data (actually it will always be the original bit depth).\n       */\n      this->alphae = 0;\n      this->alpha_sBIT = display->alpha_sBIT;\n   }\n}\n#endif /* transforms that need image_pixel_add_alpha */\n\nstruct transform_display;\ntypedef struct image_transform\n{\n   /* The name of this transform: a string. */\n   const char *name;\n\n   /* Each transform can be disabled from the command line: */\n   int enable;\n\n   /* The global list of transforms; read only. */\n   struct image_transform *const list;\n\n   /* The global count of the number of times this transform has been set on an\n    * image.\n    */\n   unsigned int global_use;\n\n   /* The local count of the number of times this transform has been set. */\n   unsigned int local_use;\n\n   /* The next transform in the list, each transform must call its own next\n    * transform after it has processed the pixel successfully.\n    */\n   const struct image_transform *next;\n\n   /* A single transform for the image, expressed as a series of function\n    * callbacks and some space for values.\n    *\n    * First a callback to add any required modifications to the png_modifier;\n    * this gets called just before the modifier is set up for read.\n    */\n   void (*ini)(const struct image_transform *this,\n      struct transform_display *that);\n\n   /* And a callback to set the transform on the current png_read_struct:\n    */\n   void (*set)(const struct image_transform *this,\n      struct transform_display *that, png_structp pp, png_infop pi);\n\n   /* Then a transform that takes an input pixel in one PNG format or another\n    * and modifies it by a pngvalid implementation of the transform (thus\n    * duplicating the libpng intent without, we hope, duplicating the bugs\n    * in the libpng implementation!)  The png_structp is solely to allow error\n    * reporting via png_error and png_warning.\n    */\n   void (*mod)(const struct image_transform *this, image_pixel *that,\n      png_const_structp pp, const struct transform_display *display);\n\n   /* Add this transform to the list and return true if the transform is\n    * meaningful for this colour type and bit depth - if false then the\n    * transform should have no effect on the image so there's not a lot of\n    * point running it.\n    */\n   int (*add)(struct image_transform *this,\n      const struct image_transform **that, png_byte colour_type,\n      png_byte bit_depth);\n} image_transform;\n\ntypedef struct transform_display\n{\n   standard_display this;\n\n   /* Parameters */\n   png_modifier*              pm;\n   const image_transform* transform_list;\n   unsigned int max_gamma_8;\n\n   /* Local variables */\n   png_byte output_colour_type;\n   png_byte output_bit_depth;\n   png_byte unpacked;\n\n   /* Modifications (not necessarily used.) */\n   gama_modification gama_mod;\n   chrm_modification chrm_mod;\n   srgb_modification srgb_mod;\n} transform_display;\n\n/* Set sRGB, cHRM and gAMA transforms as required by the current encoding. */\nstatic void\ntransform_set_encoding(transform_display *this)\n{\n   /* Set up the png_modifier '_current' fields then use these to determine how\n    * to add appropriate chunks.\n    */\n   png_modifier *pm = this->pm;\n\n   modifier_set_encoding(pm);\n\n   if (modifier_color_encoding_is_set(pm))\n   {\n      if (modifier_color_encoding_is_sRGB(pm))\n         srgb_modification_init(&this->srgb_mod, pm, PNG_sRGB_INTENT_ABSOLUTE);\n\n      else\n      {\n         /* Set gAMA and cHRM separately. */\n         gama_modification_init(&this->gama_mod, pm, pm->current_gamma);\n\n         if (pm->current_encoding != 0)\n            chrm_modification_init(&this->chrm_mod, pm, pm->current_encoding);\n      }\n   }\n}\n\n/* Three functions to end the list: */\nstatic void\nimage_transform_ini_end(const image_transform *this,\n   transform_display *that)\n{\n   UNUSED(this)\n   UNUSED(that)\n}\n\nstatic void\nimage_transform_set_end(const image_transform *this,\n   transform_display *that, png_structp pp, png_infop pi)\n{\n   UNUSED(this)\n   UNUSED(that)\n   UNUSED(pp)\n   UNUSED(pi)\n}\n\n/* At the end of the list recalculate the output image pixel value from the\n * double precision values set up by the preceding 'mod' calls:\n */\nstatic unsigned int\nsample_scale(double sample_value, unsigned int scale)\n{\n   sample_value = floor(sample_value * scale + .5);\n\n   /* Return NaN as 0: */\n   if (!(sample_value > 0))\n      sample_value = 0;\n   else if (sample_value > scale)\n      sample_value = scale;\n\n   return (unsigned int)sample_value;\n}\n\nstatic void\nimage_transform_mod_end(const image_transform *this, image_pixel *that,\n    png_const_structp pp, const transform_display *display)\n{\n   const unsigned int scale = (1U<<that->sample_depth)-1;\n   const int sig_bits = that->sig_bits;\n\n   UNUSED(this)\n   UNUSED(pp)\n   UNUSED(display)\n\n   /* At the end recalculate the digitized red green and blue values according\n    * to the current sample_depth of the pixel.\n    *\n    * The sample value is simply scaled to the maximum, checking for over\n    * and underflow (which can both happen for some image transforms,\n    * including simple size scaling, though libpng doesn't do that at present.\n    */\n   that->red = sample_scale(that->redf, scale);\n\n   /* This is a bit bogus; really the above calculation should use the red_sBIT\n    * value, not sample_depth, but because libpng does png_set_shift by just\n    * shifting the bits we get errors if we don't do it the same way.\n    */\n   if (sig_bits && that->red_sBIT < that->sample_depth)\n      that->red >>= that->sample_depth - that->red_sBIT;\n\n   /* The error value is increased, at the end, according to the lowest sBIT\n    * value seen.  Common sense tells us that the intermediate integer\n    * representations are no more accurate than +/- 0.5 in the integral values,\n    * the sBIT allows the implementation to be worse than this.  In addition the\n    * PNG specification actually permits any error within the range (-1..+1),\n    * but that is ignored here.  Instead the final digitized value is compared,\n    * below to the digitized value of the error limits - this has the net effect\n    * of allowing (almost) +/-1 in the output value.  It's difficult to see how\n    * any algorithm that digitizes intermediate results can be more accurate.\n    */\n   that->rede += 1./(2*((1U<<that->red_sBIT)-1));\n\n   if (that->colour_type & PNG_COLOR_MASK_COLOR)\n   {\n      that->green = sample_scale(that->greenf, scale);\n      if (sig_bits && that->green_sBIT < that->sample_depth)\n         that->green >>= that->sample_depth - that->green_sBIT;\n\n      that->blue = sample_scale(that->bluef, scale);\n      if (sig_bits && that->blue_sBIT < that->sample_depth)\n         that->blue >>= that->sample_depth - that->blue_sBIT;\n\n      that->greene += 1./(2*((1U<<that->green_sBIT)-1));\n      that->bluee += 1./(2*((1U<<that->blue_sBIT)-1));\n   }\n   else\n   {\n      that->blue = that->green = that->red;\n      that->bluef = that->greenf = that->redf;\n      that->bluee = that->greene = that->rede;\n   }\n\n   if ((that->colour_type & PNG_COLOR_MASK_ALPHA) ||\n      that->colour_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      that->alpha = sample_scale(that->alphaf, scale);\n      that->alphae += 1./(2*((1U<<that->alpha_sBIT)-1));\n   }\n   else\n   {\n      that->alpha = scale; /* opaque */\n      that->alphaf = 1;    /* Override this. */\n      that->alphae = 0;    /* It's exact ;-) */\n   }\n\n   if (sig_bits && that->alpha_sBIT < that->sample_depth)\n      that->alpha >>= that->sample_depth - that->alpha_sBIT;\n}\n\n/* Static 'end' structure: */\nstatic image_transform image_transform_end =\n{\n   \"(end)\", /* name */\n   1, /* enable */\n   0, /* list */\n   0, /* global_use */\n   0, /* local_use */\n   0, /* next */\n   image_transform_ini_end,\n   image_transform_set_end,\n   image_transform_mod_end,\n   0 /* never called, I want it to crash if it is! */\n};\n\n/* Reader callbacks and implementations, where they differ from the standard\n * ones.\n */\nstatic void\ntransform_display_init(transform_display *dp, png_modifier *pm, png_uint_32 id,\n    const image_transform *transform_list)\n{\n   memset(dp, 0, sizeof *dp);\n\n   /* Standard fields */\n   standard_display_init(&dp->this, &pm->this, id, do_read_interlace,\n      pm->use_update_info);\n\n   /* Parameter fields */\n   dp->pm = pm;\n   dp->transform_list = transform_list;\n   dp->max_gamma_8 = 16;\n\n   /* Local variable fields */\n   dp->output_colour_type = 255; /* invalid */\n   dp->output_bit_depth = 255;  /* invalid */\n   dp->unpacked = 0; /* not unpacked */\n}\n\nstatic void\ntransform_info_imp(transform_display *dp, png_structp pp, png_infop pi)\n{\n   /* Reuse the standard stuff as appropriate. */\n   standard_info_part1(&dp->this, pp, pi);\n\n   /* Now set the list of transforms. */\n   dp->transform_list->set(dp->transform_list, dp, pp, pi);\n\n   /* Update the info structure for these transforms: */\n   {\n      int i = dp->this.use_update_info;\n      /* Always do one call, even if use_update_info is 0. */\n      do\n         png_read_update_info(pp, pi);\n      while (--i > 0);\n   }\n\n   /* And get the output information into the standard_display */\n   standard_info_part2(&dp->this, pp, pi, 1/*images*/);\n\n   /* Plus the extra stuff we need for the transform tests: */\n   dp->output_colour_type = png_get_color_type(pp, pi);\n   dp->output_bit_depth = png_get_bit_depth(pp, pi);\n\n   /* If png_set_filler is in action then fake the output color type to include\n    * an alpha channel where appropriate.\n    */\n   if (dp->output_bit_depth >= 8 &&\n       (dp->output_colour_type == PNG_COLOR_TYPE_RGB ||\n        dp->output_colour_type == PNG_COLOR_TYPE_GRAY) && dp->this.filler)\n       dp->output_colour_type |= 4;\n\n   /* Validate the combination of colour type and bit depth that we are getting\n    * out of libpng; the semantics of something not in the PNG spec are, at\n    * best, unclear.\n    */\n   switch (dp->output_colour_type)\n   {\n   case PNG_COLOR_TYPE_PALETTE:\n      if (dp->output_bit_depth > 8) goto error;\n      /*FALL THROUGH*/\n   case PNG_COLOR_TYPE_GRAY:\n      if (dp->output_bit_depth == 1 || dp->output_bit_depth == 2 ||\n         dp->output_bit_depth == 4)\n         break;\n      /*FALL THROUGH*/\n   default:\n      if (dp->output_bit_depth == 8 || dp->output_bit_depth == 16)\n         break;\n      /*FALL THROUGH*/\n   error:\n      {\n         char message[128];\n         size_t pos;\n\n         pos = safecat(message, sizeof message, 0,\n            \"invalid final bit depth: colour type(\");\n         pos = safecatn(message, sizeof message, pos, dp->output_colour_type);\n         pos = safecat(message, sizeof message, pos, \") with bit depth: \");\n         pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);\n\n         png_error(pp, message);\n      }\n   }\n\n   /* Use a test pixel to check that the output agrees with what we expect -\n    * this avoids running the whole test if the output is unexpected.  This also\n    * checks for internal errors.\n    */\n   {\n      image_pixel test_pixel;\n\n      memset(&test_pixel, 0, sizeof test_pixel);\n      test_pixel.colour_type = dp->this.colour_type; /* input */\n      test_pixel.bit_depth = dp->this.bit_depth;\n      if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE)\n         test_pixel.sample_depth = 8;\n      else\n         test_pixel.sample_depth = test_pixel.bit_depth;\n      /* Don't need sBIT here, but it must be set to non-zero to avoid\n       * arithmetic overflows.\n       */\n      test_pixel.have_tRNS = dp->this.is_transparent != 0;\n      test_pixel.red_sBIT = test_pixel.green_sBIT = test_pixel.blue_sBIT =\n         test_pixel.alpha_sBIT = test_pixel.sample_depth;\n\n      dp->transform_list->mod(dp->transform_list, &test_pixel, pp, dp);\n\n      if (test_pixel.colour_type != dp->output_colour_type)\n      {\n         char message[128];\n         size_t pos = safecat(message, sizeof message, 0, \"colour type \");\n\n         pos = safecatn(message, sizeof message, pos, dp->output_colour_type);\n         pos = safecat(message, sizeof message, pos, \" expected \");\n         pos = safecatn(message, sizeof message, pos, test_pixel.colour_type);\n\n         png_error(pp, message);\n      }\n\n      if (test_pixel.bit_depth != dp->output_bit_depth)\n      {\n         char message[128];\n         size_t pos = safecat(message, sizeof message, 0, \"bit depth \");\n\n         pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);\n         pos = safecat(message, sizeof message, pos, \" expected \");\n         pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);\n\n         png_error(pp, message);\n      }\n\n      /* If both bit depth and colour type are correct check the sample depth.\n       */\n      if (test_pixel.colour_type == PNG_COLOR_TYPE_PALETTE &&\n          test_pixel.sample_depth != 8) /* oops - internal error! */\n         png_error(pp, \"pngvalid: internal: palette sample depth not 8\");\n      else if (dp->unpacked && test_pixel.bit_depth != 8)\n         png_error(pp, \"pngvalid: internal: bad unpacked pixel depth\");\n      else if (!dp->unpacked && test_pixel.colour_type != PNG_COLOR_TYPE_PALETTE\n              && test_pixel.bit_depth != test_pixel.sample_depth)\n      {\n         char message[128];\n         size_t pos = safecat(message, sizeof message, 0,\n            \"internal: sample depth \");\n\n         /* Because unless something has set 'unpacked' or the image is palette\n          * mapped we expect the transform to keep sample depth and bit depth\n          * the same.\n          */\n         pos = safecatn(message, sizeof message, pos, test_pixel.sample_depth);\n         pos = safecat(message, sizeof message, pos, \" expected \");\n         pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);\n\n         png_error(pp, message);\n      }\n      else if (test_pixel.bit_depth != dp->output_bit_depth)\n      {\n         /* This could be a libpng error too; libpng has not produced what we\n          * expect for the output bit depth.\n          */\n         char message[128];\n         size_t pos = safecat(message, sizeof message, 0,\n            \"internal: bit depth \");\n\n         pos = safecatn(message, sizeof message, pos, dp->output_bit_depth);\n         pos = safecat(message, sizeof message, pos, \" expected \");\n         pos = safecatn(message, sizeof message, pos, test_pixel.bit_depth);\n\n         png_error(pp, message);\n      }\n   }\n}\n\nstatic void PNGCBAPI\ntransform_info(png_structp pp, png_infop pi)\n{\n   transform_info_imp(voidcast(transform_display*, png_get_progressive_ptr(pp)),\n      pp, pi);\n}\n\nstatic void\ntransform_range_check(png_const_structp pp, unsigned int r, unsigned int g,\n   unsigned int b, unsigned int a, unsigned int in_digitized, double in,\n   unsigned int out, png_byte sample_depth, double err, double limit,\n   const char *name, double digitization_error)\n{\n   /* Compare the scaled, digitzed, values of our local calculation (in+-err)\n    * with the digitized values libpng produced;  'sample_depth' is the actual\n    * digitization depth of the libpng output colors (the bit depth except for\n    * palette images where it is always 8.)  The check on 'err' is to detect\n    * internal errors in pngvalid itself.\n    */\n   unsigned int max = (1U<<sample_depth)-1;\n   double in_min = ceil((in-err)*max - digitization_error);\n   double in_max = floor((in+err)*max + digitization_error);\n   if (debugonly(err > limit ||) !(out >= in_min && out <= in_max))\n   {\n      char message[256];\n      size_t pos;\n\n      pos = safecat(message, sizeof message, 0, name);\n      pos = safecat(message, sizeof message, pos, \" output value error: rgba(\");\n      pos = safecatn(message, sizeof message, pos, r);\n      pos = safecat(message, sizeof message, pos, \",\");\n      pos = safecatn(message, sizeof message, pos, g);\n      pos = safecat(message, sizeof message, pos, \",\");\n      pos = safecatn(message, sizeof message, pos, b);\n      pos = safecat(message, sizeof message, pos, \",\");\n      pos = safecatn(message, sizeof message, pos, a);\n      pos = safecat(message, sizeof message, pos, \"): \");\n      pos = safecatn(message, sizeof message, pos, out);\n      pos = safecat(message, sizeof message, pos, \" expected: \");\n      pos = safecatn(message, sizeof message, pos, in_digitized);\n      pos = safecat(message, sizeof message, pos, \" (\");\n      pos = safecatd(message, sizeof message, pos, (in-err)*max, 3);\n      pos = safecat(message, sizeof message, pos, \"..\");\n      pos = safecatd(message, sizeof message, pos, (in+err)*max, 3);\n      pos = safecat(message, sizeof message, pos, \")\");\n\n      png_error(pp, message);\n   }\n\n   UNUSED(limit)\n}\n\nstatic void\ntransform_image_validate(transform_display *dp, png_const_structp pp,\n   png_infop pi)\n{\n   /* Constants for the loop below: */\n   const png_store* const ps = dp->this.ps;\n   const png_byte in_ct = dp->this.colour_type;\n   const png_byte in_bd = dp->this.bit_depth;\n   const png_uint_32 w = dp->this.w;\n   const png_uint_32 h = dp->this.h;\n   const png_byte out_ct = dp->output_colour_type;\n   const png_byte out_bd = dp->output_bit_depth;\n   const png_byte sample_depth = (png_byte)(out_ct ==\n      PNG_COLOR_TYPE_PALETTE ? 8 : out_bd);\n   const png_byte red_sBIT = dp->this.red_sBIT;\n   const png_byte green_sBIT = dp->this.green_sBIT;\n   const png_byte blue_sBIT = dp->this.blue_sBIT;\n   const png_byte alpha_sBIT = dp->this.alpha_sBIT;\n   const int have_tRNS = dp->this.is_transparent;\n   double digitization_error;\n\n   store_palette out_palette;\n   png_uint_32 y;\n\n   UNUSED(pi)\n\n   /* Check for row overwrite errors */\n   store_image_check(dp->this.ps, pp, 0);\n\n   /* Read the palette corresponding to the output if the output colour type\n    * indicates a palette, othewise set out_palette to garbage.\n    */\n   if (out_ct == PNG_COLOR_TYPE_PALETTE)\n   {\n      /* Validate that the palette count itself has not changed - this is not\n       * expected.\n       */\n      int npalette = (-1);\n\n      (void)read_palette(out_palette, &npalette, pp, pi);\n      if (npalette != dp->this.npalette)\n         png_error(pp, \"unexpected change in palette size\");\n\n      digitization_error = .5;\n   }\n   else\n   {\n      png_byte in_sample_depth;\n\n      memset(out_palette, 0x5e, sizeof out_palette);\n\n      /* use-input-precision means assume that if the input has 8 bit (or less)\n       * samples and the output has 16 bit samples the calculations will be done\n       * with 8 bit precision, not 16.\n       */\n      if (in_ct == PNG_COLOR_TYPE_PALETTE || in_bd < 16)\n         in_sample_depth = 8;\n      else\n         in_sample_depth = in_bd;\n\n      if (sample_depth != 16 || in_sample_depth > 8 ||\n         !dp->pm->calculations_use_input_precision)\n         digitization_error = .5;\n\n      /* Else calculations are at 8 bit precision, and the output actually\n       * consists of scaled 8-bit values, so scale .5 in 8 bits to the 16 bits:\n       */\n      else\n         digitization_error = .5 * 257;\n   }\n\n   for (y=0; y<h; ++y)\n   {\n      png_const_bytep const pRow = store_image_row(ps, pp, 0, y);\n      png_uint_32 x;\n\n      /* The original, standard, row pre-transforms. */\n      png_byte std[STANDARD_ROWMAX];\n\n      transform_row(pp, std, in_ct, in_bd, y);\n\n      /* Go through each original pixel transforming it and comparing with what\n       * libpng did to the same pixel.\n       */\n      for (x=0; x<w; ++x)\n      {\n         image_pixel in_pixel, out_pixel;\n         unsigned int r, g, b, a;\n\n         /* Find out what we think the pixel should be: */\n         image_pixel_init(&in_pixel, std, in_ct, in_bd, x, dp->this.palette,\n                 NULL);\n\n         in_pixel.red_sBIT = red_sBIT;\n         in_pixel.green_sBIT = green_sBIT;\n         in_pixel.blue_sBIT = blue_sBIT;\n         in_pixel.alpha_sBIT = alpha_sBIT;\n         in_pixel.have_tRNS = have_tRNS != 0;\n\n         /* For error detection, below. */\n         r = in_pixel.red;\n         g = in_pixel.green;\n         b = in_pixel.blue;\n         a = in_pixel.alpha;\n\n         /* This applies the transforms to the input data, including output\n          * format operations which must be used when reading the output\n          * pixel that libpng produces.\n          */\n         dp->transform_list->mod(dp->transform_list, &in_pixel, pp, dp);\n\n         /* Read the output pixel and compare it to what we got, we don't\n          * use the error field here, so no need to update sBIT.  in_pixel\n          * says whether we expect libpng to change the output format.\n          */\n         image_pixel_init(&out_pixel, pRow, out_ct, out_bd, x, out_palette,\n                 &in_pixel);\n\n         /* We don't expect changes to the index here even if the bit depth is\n          * changed.\n          */\n         if (in_ct == PNG_COLOR_TYPE_PALETTE &&\n            out_ct == PNG_COLOR_TYPE_PALETTE)\n         {\n            if (in_pixel.palette_index != out_pixel.palette_index)\n               png_error(pp, \"unexpected transformed palette index\");\n         }\n\n         /* Check the colours for palette images too - in fact the palette could\n          * be separately verified itself in most cases.\n          */\n         if (in_pixel.red != out_pixel.red)\n            transform_range_check(pp, r, g, b, a, in_pixel.red, in_pixel.redf,\n               out_pixel.red, sample_depth, in_pixel.rede,\n               dp->pm->limit + 1./(2*((1U<<in_pixel.red_sBIT)-1)), \"red/gray\",\n               digitization_error);\n\n         if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 &&\n            in_pixel.green != out_pixel.green)\n            transform_range_check(pp, r, g, b, a, in_pixel.green,\n               in_pixel.greenf, out_pixel.green, sample_depth, in_pixel.greene,\n               dp->pm->limit + 1./(2*((1U<<in_pixel.green_sBIT)-1)), \"green\",\n               digitization_error);\n\n         if ((out_ct & PNG_COLOR_MASK_COLOR) != 0 &&\n            in_pixel.blue != out_pixel.blue)\n            transform_range_check(pp, r, g, b, a, in_pixel.blue, in_pixel.bluef,\n               out_pixel.blue, sample_depth, in_pixel.bluee,\n               dp->pm->limit + 1./(2*((1U<<in_pixel.blue_sBIT)-1)), \"blue\",\n               digitization_error);\n\n         if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0 &&\n            in_pixel.alpha != out_pixel.alpha)\n            transform_range_check(pp, r, g, b, a, in_pixel.alpha,\n               in_pixel.alphaf, out_pixel.alpha, sample_depth, in_pixel.alphae,\n               dp->pm->limit + 1./(2*((1U<<in_pixel.alpha_sBIT)-1)), \"alpha\",\n               digitization_error);\n      } /* pixel (x) loop */\n   } /* row (y) loop */\n\n   /* Record that something was actually checked to avoid a false positive. */\n   dp->this.ps->validated = 1;\n}\n\nstatic void PNGCBAPI\ntransform_end(png_structp ppIn, png_infop pi)\n{\n   png_const_structp pp = ppIn;\n   transform_display *dp = voidcast(transform_display*,\n      png_get_progressive_ptr(pp));\n\n   if (!dp->this.speed)\n      transform_image_validate(dp, pp, pi);\n   else\n      dp->this.ps->validated = 1;\n}\n\n/* A single test run. */\nstatic void\ntransform_test(png_modifier *pmIn, const png_uint_32 idIn,\n    const image_transform* transform_listIn, const char * const name)\n{\n   transform_display d;\n   context(&pmIn->this, fault);\n\n   transform_display_init(&d, pmIn, idIn, transform_listIn);\n\n   Try\n   {\n      size_t pos = 0;\n      png_structp pp;\n      png_infop pi;\n      char full_name[256];\n\n      /* Make sure the encoding fields are correct and enter the required\n       * modifications.\n       */\n      transform_set_encoding(&d);\n\n      /* Add any modifications required by the transform list. */\n      d.transform_list->ini(d.transform_list, &d);\n\n      /* Add the color space information, if any, to the name. */\n      pos = safecat(full_name, sizeof full_name, pos, name);\n      pos = safecat_current_encoding(full_name, sizeof full_name, pos, d.pm);\n\n      /* Get a png_struct for reading the image. */\n      pp = set_modifier_for_read(d.pm, &pi, d.this.id, full_name);\n      standard_palette_init(&d.this);\n\n#     if 0\n         /* Logging (debugging only) */\n         {\n            char buffer[256];\n\n            (void)store_message(&d.pm->this, pp, buffer, sizeof buffer, 0,\n               \"running test\");\n\n            fprintf(stderr, \"%s\\n\", buffer);\n         }\n#     endif\n\n      /* Introduce the correct read function. */\n      if (d.pm->this.progressive)\n      {\n         /* Share the row function with the standard implementation. */\n         png_set_progressive_read_fn(pp, &d, transform_info, progressive_row,\n            transform_end);\n\n         /* Now feed data into the reader until we reach the end: */\n         modifier_progressive_read(d.pm, pp, pi);\n      }\n      else\n      {\n         /* modifier_read expects a png_modifier* */\n         png_set_read_fn(pp, d.pm, modifier_read);\n\n         /* Check the header values: */\n         png_read_info(pp, pi);\n\n         /* Process the 'info' requirements. Only one image is generated */\n         transform_info_imp(&d, pp, pi);\n\n         sequential_row(&d.this, pp, pi, -1, 0);\n\n         if (!d.this.speed)\n            transform_image_validate(&d, pp, pi);\n         else\n            d.this.ps->validated = 1;\n      }\n\n      modifier_reset(d.pm);\n   }\n\n   Catch(fault)\n   {\n      modifier_reset(voidcast(png_modifier*,(void*)fault));\n   }\n}\n\n/* The transforms: */\n#define ITSTRUCT(name) image_transform_##name\n#define ITDATA(name) image_transform_data_##name\n#define image_transform_ini image_transform_default_ini\n#define IT(name)\\\nstatic image_transform ITSTRUCT(name) =\\\n{\\\n   #name,\\\n   1, /*enable*/\\\n   &PT, /*list*/\\\n   0, /*global_use*/\\\n   0, /*local_use*/\\\n   0, /*next*/\\\n   image_transform_ini,\\\n   image_transform_png_set_##name##_set,\\\n   image_transform_png_set_##name##_mod,\\\n   image_transform_png_set_##name##_add\\\n}\n#define PT ITSTRUCT(end) /* stores the previous transform */\n\n/* To save code: */\nextern void image_transform_default_ini(const image_transform *this,\n   transform_display *that); /* silence GCC warnings */\n\nvoid /* private, but almost always needed */\nimage_transform_default_ini(const image_transform *this,\n    transform_display *that)\n{\n   this->next->ini(this->next, that);\n}\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\nstatic int\nimage_transform_default_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return 1;\n}\n#endif\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* png_set_palette_to_rgb */\nstatic void\nimage_transform_png_set_palette_to_rgb_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_palette_to_rgb(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_palette_to_rgb_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type == PNG_COLOR_TYPE_PALETTE)\n      image_pixel_convert_PLTE(that);\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_palette_to_rgb_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return colour_type == PNG_COLOR_TYPE_PALETTE;\n}\n\nIT(palette_to_rgb);\n#undef PT\n#define PT ITSTRUCT(palette_to_rgb)\n#endif /* PNG_READ_EXPAND_SUPPORTED */\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* png_set_tRNS_to_alpha */\nstatic void\nimage_transform_png_set_tRNS_to_alpha_set(const image_transform *this,\n   transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_tRNS_to_alpha(pp);\n\n   /* If there was a tRNS chunk that would get expanded and add an alpha\n    * channel is_transparent must be updated:\n    */\n   if (that->this.has_tRNS)\n      that->this.is_transparent = 1;\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_tRNS_to_alpha_mod(const image_transform *this,\n   image_pixel *that, png_const_structp pp,\n   const transform_display *display)\n{\n#if PNG_LIBPNG_VER < 10700\n   /* LIBPNG BUG: this always forces palette images to RGB. */\n   if (that->colour_type == PNG_COLOR_TYPE_PALETTE)\n      image_pixel_convert_PLTE(that);\n#endif\n\n   /* This effectively does an 'expand' only if there is some transparency to\n    * convert to an alpha channel.\n    */\n   if (that->have_tRNS)\n#     if PNG_LIBPNG_VER >= 10700\n         if (that->colour_type != PNG_COLOR_TYPE_PALETTE &&\n             (that->colour_type & PNG_COLOR_MASK_ALPHA) == 0)\n#     endif\n      image_pixel_add_alpha(that, &display->this, 0/*!for background*/);\n\n#if PNG_LIBPNG_VER < 10700\n   /* LIBPNG BUG: otherwise libpng still expands to 8 bits! */\n   else\n   {\n      if (that->bit_depth < 8)\n         that->bit_depth =8;\n      if (that->sample_depth < 8)\n         that->sample_depth = 8;\n   }\n#endif\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_tRNS_to_alpha_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   /* We don't know yet whether there will be a tRNS chunk, but we know that\n    * this transformation should do nothing if there already is an alpha\n    * channel.  In addition, after the bug fix in 1.7.0, there is no longer\n    * any action on a palette image.\n    */\n   return\n#  if PNG_LIBPNG_VER >= 10700\n      colour_type != PNG_COLOR_TYPE_PALETTE &&\n#  endif\n   (colour_type & PNG_COLOR_MASK_ALPHA) == 0;\n}\n\nIT(tRNS_to_alpha);\n#undef PT\n#define PT ITSTRUCT(tRNS_to_alpha)\n#endif /* PNG_READ_EXPAND_SUPPORTED */\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n/* png_set_gray_to_rgb */\nstatic void\nimage_transform_png_set_gray_to_rgb_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_gray_to_rgb(pp);\n   /* NOTE: this doesn't result in tRNS expansion. */\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_gray_to_rgb_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* NOTE: we can actually pend the tRNS processing at this point because we\n    * can correctly recognize the original pixel value even though we have\n    * mapped the one gray channel to the three RGB ones, but in fact libpng\n    * doesn't do this, so we don't either.\n    */\n   if ((that->colour_type & PNG_COLOR_MASK_COLOR) == 0 && that->have_tRNS)\n      image_pixel_add_alpha(that, &display->this, 0/*!for background*/);\n\n   /* Simply expand the bit depth and alter the colour type as required. */\n   if (that->colour_type == PNG_COLOR_TYPE_GRAY)\n   {\n      /* RGB images have a bit depth at least equal to '8' */\n      if (that->bit_depth < 8)\n         that->sample_depth = that->bit_depth = 8;\n\n      /* And just changing the colour type works here because the green and blue\n       * channels are being maintained in lock-step with the red/gray:\n       */\n      that->colour_type = PNG_COLOR_TYPE_RGB;\n   }\n\n   else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      that->colour_type = PNG_COLOR_TYPE_RGB_ALPHA;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_gray_to_rgb_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return (colour_type & PNG_COLOR_MASK_COLOR) == 0;\n}\n\nIT(gray_to_rgb);\n#undef PT\n#define PT ITSTRUCT(gray_to_rgb)\n#endif /* PNG_READ_GRAY_TO_RGB_SUPPORTED */\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* png_set_expand */\nstatic void\nimage_transform_png_set_expand_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_expand(pp);\n\n   if (that->this.has_tRNS)\n      that->this.is_transparent = 1;\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_expand_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* The general expand case depends on what the colour type is: */\n   if (that->colour_type == PNG_COLOR_TYPE_PALETTE)\n      image_pixel_convert_PLTE(that);\n   else if (that->bit_depth < 8) /* grayscale */\n      that->sample_depth = that->bit_depth = 8;\n\n   if (that->have_tRNS)\n      image_pixel_add_alpha(that, &display->this, 0/*!for background*/);\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_expand_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   /* 'expand' should do nothing for RGBA or GA input - no tRNS and the bit\n    * depth is at least 8 already.\n    */\n   return (colour_type & PNG_COLOR_MASK_ALPHA) == 0;\n}\n\nIT(expand);\n#undef PT\n#define PT ITSTRUCT(expand)\n#endif /* PNG_READ_EXPAND_SUPPORTED */\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* png_set_expand_gray_1_2_4_to_8\n * Pre 1.7.0 LIBPNG BUG: this just does an 'expand'\n */\nstatic void\nimage_transform_png_set_expand_gray_1_2_4_to_8_set(\n    const image_transform *this, transform_display *that, png_structp pp,\n    png_infop pi)\n{\n   png_set_expand_gray_1_2_4_to_8(pp);\n   /* NOTE: don't expect this to expand tRNS */\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_expand_gray_1_2_4_to_8_mod(\n    const image_transform *this, image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n#if PNG_LIBPNG_VER < 10700\n   image_transform_png_set_expand_mod(this, that, pp, display);\n#else\n   /* Only expand grayscale of bit depth less than 8: */\n   if (that->colour_type == PNG_COLOR_TYPE_GRAY &&\n       that->bit_depth < 8)\n      that->sample_depth = that->bit_depth = 8;\n\n   this->next->mod(this->next, that, pp, display);\n#endif /* 1.7 or later */\n}\n\nstatic int\nimage_transform_png_set_expand_gray_1_2_4_to_8_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n#if PNG_LIBPNG_VER < 10700\n   return image_transform_png_set_expand_add(this, that, colour_type,\n      bit_depth);\n#else\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   /* This should do nothing unless the color type is gray and the bit depth is\n    * less than 8:\n    */\n   return colour_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8;\n#endif /* 1.7 or later */\n}\n\nIT(expand_gray_1_2_4_to_8);\n#undef PT\n#define PT ITSTRUCT(expand_gray_1_2_4_to_8)\n#endif /* PNG_READ_EXPAND_SUPPORTED */\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n/* png_set_expand_16 */\nstatic void\nimage_transform_png_set_expand_16_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_expand_16(pp);\n\n   /* NOTE: prior to 1.7 libpng does SET_EXPAND as well, so tRNS is expanded. */\n#  if PNG_LIBPNG_VER < 10700\n      if (that->this.has_tRNS)\n         that->this.is_transparent = 1;\n#  endif\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_expand_16_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* Expect expand_16 to expand everything to 16 bits as a result of also\n    * causing 'expand' to happen.\n    */\n   if (that->colour_type == PNG_COLOR_TYPE_PALETTE)\n      image_pixel_convert_PLTE(that);\n\n   if (that->have_tRNS)\n      image_pixel_add_alpha(that, &display->this, 0/*!for background*/);\n\n   if (that->bit_depth < 16)\n      that->sample_depth = that->bit_depth = 16;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_expand_16_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   /* expand_16 does something unless the bit depth is already 16. */\n   return bit_depth < 16;\n}\n\nIT(expand_16);\n#undef PT\n#define PT ITSTRUCT(expand_16)\n#endif /* PNG_READ_EXPAND_16_SUPPORTED */\n\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED  /* API added in 1.5.4 */\n/* png_set_scale_16 */\nstatic void\nimage_transform_png_set_scale_16_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_scale_16(pp);\n#  if PNG_LIBPNG_VER < 10700\n      /* libpng will limit the gamma table size: */\n      that->max_gamma_8 = PNG_MAX_GAMMA_8;\n#  endif\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_scale_16_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth == 16)\n   {\n      that->sample_depth = that->bit_depth = 8;\n      if (that->red_sBIT > 8) that->red_sBIT = 8;\n      if (that->green_sBIT > 8) that->green_sBIT = 8;\n      if (that->blue_sBIT > 8) that->blue_sBIT = 8;\n      if (that->alpha_sBIT > 8) that->alpha_sBIT = 8;\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_scale_16_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   return bit_depth > 8;\n}\n\nIT(scale_16);\n#undef PT\n#define PT ITSTRUCT(scale_16)\n#endif /* PNG_READ_SCALE_16_TO_8_SUPPORTED (1.5.4 on) */\n\n#ifdef PNG_READ_16_TO_8_SUPPORTED /* the default before 1.5.4 */\n/* png_set_strip_16 */\nstatic void\nimage_transform_png_set_strip_16_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_strip_16(pp);\n#  if PNG_LIBPNG_VER < 10700\n      /* libpng will limit the gamma table size: */\n      that->max_gamma_8 = PNG_MAX_GAMMA_8;\n#  endif\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_strip_16_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth == 16)\n   {\n      that->sample_depth = that->bit_depth = 8;\n      if (that->red_sBIT > 8) that->red_sBIT = 8;\n      if (that->green_sBIT > 8) that->green_sBIT = 8;\n      if (that->blue_sBIT > 8) that->blue_sBIT = 8;\n      if (that->alpha_sBIT > 8) that->alpha_sBIT = 8;\n\n      /* Prior to 1.5.4 png_set_strip_16 would use an 'accurate' method if this\n       * configuration option is set.  From 1.5.4 the flag is never set and the\n       * 'scale' API (above) must be used.\n       */\n#     ifdef PNG_READ_ACCURATE_SCALE_SUPPORTED\n#        if PNG_LIBPNG_VER >= 10504\n#           error PNG_READ_ACCURATE_SCALE should not be set\n#        endif\n\n         /* The strip 16 algorithm drops the low 8 bits rather than calculating\n          * 1/257, so we need to adjust the permitted errors appropriately:\n          * Notice that this is only relevant prior to the addition of the\n          * png_set_scale_16 API in 1.5.4 (but 1.5.4+ always defines the above!)\n          */\n         {\n            const double d = (255-128.5)/65535;\n            that->rede += d;\n            that->greene += d;\n            that->bluee += d;\n            that->alphae += d;\n         }\n#     endif\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_strip_16_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   return bit_depth > 8;\n}\n\nIT(strip_16);\n#undef PT\n#define PT ITSTRUCT(strip_16)\n#endif /* PNG_READ_16_TO_8_SUPPORTED */\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n/* png_set_strip_alpha */\nstatic void\nimage_transform_png_set_strip_alpha_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_strip_alpha(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_strip_alpha_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      that->colour_type = PNG_COLOR_TYPE_GRAY;\n   else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)\n      that->colour_type = PNG_COLOR_TYPE_RGB;\n\n   that->have_tRNS = 0;\n   that->alphaf = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_strip_alpha_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return (colour_type & PNG_COLOR_MASK_ALPHA) != 0;\n}\n\nIT(strip_alpha);\n#undef PT\n#define PT ITSTRUCT(strip_alpha)\n#endif /* PNG_READ_STRIP_ALPHA_SUPPORTED */\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n/* png_set_rgb_to_gray(png_structp, int err_action, double red, double green)\n * png_set_rgb_to_gray_fixed(png_structp, int err_action, png_fixed_point red,\n *    png_fixed_point green)\n * png_get_rgb_to_gray_status\n *\n * The 'default' test here uses values known to be used inside libpng prior to\n * 1.7.0:\n *\n *   red:    6968\n *   green: 23434\n *   blue:   2366\n *\n * These values are being retained for compatibility, along with the somewhat\n * broken truncation calculation in the fast-and-inaccurate code path.  Older\n * versions of libpng will fail the accuracy tests below because they use the\n * truncation algorithm everywhere.\n */\n#define data ITDATA(rgb_to_gray)\nstatic struct\n{\n   double gamma;      /* File gamma to use in processing */\n\n   /* The following are the parameters for png_set_rgb_to_gray: */\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\n      double red_to_set;\n      double green_to_set;\n#  else\n      png_fixed_point red_to_set;\n      png_fixed_point green_to_set;\n#  endif\n\n   /* The actual coefficients: */\n   double red_coefficient;\n   double green_coefficient;\n   double blue_coefficient;\n\n   /* Set if the coeefficients have been overridden. */\n   int coefficients_overridden;\n} data;\n\n#undef image_transform_ini\n#define image_transform_ini image_transform_png_set_rgb_to_gray_ini\nstatic void\nimage_transform_png_set_rgb_to_gray_ini(const image_transform *this,\n    transform_display *that)\n{\n   png_modifier *pm = that->pm;\n   const color_encoding *e = pm->current_encoding;\n\n   UNUSED(this)\n\n   /* Since we check the encoding this flag must be set: */\n   pm->test_uses_encoding = 1;\n\n   /* If 'e' is not NULL chromaticity information is present and either a cHRM\n    * or an sRGB chunk will be inserted.\n    */\n   if (e != 0)\n   {\n      /* Coefficients come from the encoding, but may need to be normalized to a\n       * white point Y of 1.0\n       */\n      const double whiteY = e->red.Y + e->green.Y + e->blue.Y;\n\n      data.red_coefficient = e->red.Y;\n      data.green_coefficient = e->green.Y;\n      data.blue_coefficient = e->blue.Y;\n\n      if (whiteY != 1)\n      {\n         data.red_coefficient /= whiteY;\n         data.green_coefficient /= whiteY;\n         data.blue_coefficient /= whiteY;\n      }\n   }\n\n   else\n   {\n      /* The default (built in) coeffcients, as above: */\n#     if PNG_LIBPNG_VER < 10700\n         data.red_coefficient = 6968 / 32768.;\n         data.green_coefficient = 23434 / 32768.;\n         data.blue_coefficient = 2366 / 32768.;\n#     else\n         data.red_coefficient = .2126;\n         data.green_coefficient = .7152;\n         data.blue_coefficient = .0722;\n#     endif\n   }\n\n   data.gamma = pm->current_gamma;\n\n   /* If not set then the calculations assume linear encoding (implicitly): */\n   if (data.gamma == 0)\n      data.gamma = 1;\n\n   /* The arguments to png_set_rgb_to_gray can override the coefficients implied\n    * by the color space encoding.  If doing exhaustive checks do the override\n    * in each case, otherwise do it randomly.\n    */\n   if (pm->test_exhaustive)\n   {\n      /* First time in coefficients_overridden is 0, the following sets it to 1,\n       * so repeat if it is set.  If a test fails this may mean we subsequently\n       * skip a non-override test, ignore that.\n       */\n      data.coefficients_overridden = !data.coefficients_overridden;\n      pm->repeat = data.coefficients_overridden != 0;\n   }\n\n   else\n      data.coefficients_overridden = random_choice();\n\n   if (data.coefficients_overridden)\n   {\n      /* These values override the color encoding defaults, simply use random\n       * numbers.\n       */\n      png_uint_32 ru;\n      double total;\n\n      ru = random_u32();\n      data.green_coefficient = total = (ru & 0xffff) / 65535.;\n      ru >>= 16;\n      data.red_coefficient = (1 - total) * (ru & 0xffff) / 65535.;\n      total += data.red_coefficient;\n      data.blue_coefficient = 1 - total;\n\n#     ifdef PNG_FLOATING_POINT_SUPPORTED\n         data.red_to_set = data.red_coefficient;\n         data.green_to_set = data.green_coefficient;\n#     else\n         data.red_to_set = fix(data.red_coefficient);\n         data.green_to_set = fix(data.green_coefficient);\n#     endif\n\n      /* The following just changes the error messages: */\n      pm->encoding_ignored = 1;\n   }\n\n   else\n   {\n      data.red_to_set = -1;\n      data.green_to_set = -1;\n   }\n\n   /* Adjust the error limit in the png_modifier because of the larger errors\n    * produced in the digitization during the gamma handling.\n    */\n   if (data.gamma != 1) /* Use gamma tables */\n   {\n      if (that->this.bit_depth == 16 || pm->assume_16_bit_calculations)\n      {\n         /* The computations have the form:\n          *\n          *    r * rc + g * gc + b * bc\n          *\n          *  Each component of which is +/-1/65535 from the gamma_to_1 table\n          *  lookup, resulting in a base error of +/-6.  The gamma_from_1\n          *  conversion adds another +/-2 in the 16-bit case and\n          *  +/-(1<<(15-PNG_MAX_GAMMA_8)) in the 8-bit case.\n          */\n#        if PNG_LIBPNG_VER < 10700\n            if (that->this.bit_depth < 16)\n               that->max_gamma_8 = PNG_MAX_GAMMA_8;\n#        endif\n         that->pm->limit += pow(\n            (that->this.bit_depth == 16 || that->max_gamma_8 > 14 ?\n               8. :\n               6. + (1<<(15-that->max_gamma_8))\n            )/65535, data.gamma);\n      }\n\n      else\n      {\n         /* Rounding to 8 bits in the linear space causes massive errors which\n          * will trigger the error check in transform_range_check.  Fix that\n          * here by taking the gamma encoding into account.\n          *\n          * When DIGITIZE is set because a pre-1.7 version of libpng is being\n          * tested allow a bigger slack.\n          *\n          * NOTE: this number only affects the internal limit check in pngvalid,\n          * it has no effect on the limits applied to the libpng values.\n          */\n         that->pm->limit += pow(\n#        if DIGITIZE\n            2.0\n#        else\n            1.0\n#        endif\n            /255, data.gamma);\n      }\n   }\n\n   else\n   {\n      /* With no gamma correction a large error comes from the truncation of the\n       * calculation in the 8 bit case, allow for that here.\n       */\n      if (that->this.bit_depth != 16 && !pm->assume_16_bit_calculations)\n         that->pm->limit += 4E-3;\n   }\n}\n\nstatic void\nimage_transform_png_set_rgb_to_gray_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   const int error_action = 1; /* no error, no defines in png.h */\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\n      png_set_rgb_to_gray(pp, error_action, data.red_to_set, data.green_to_set);\n#  else\n      png_set_rgb_to_gray_fixed(pp, error_action, data.red_to_set,\n         data.green_to_set);\n#  endif\n\n#  ifdef PNG_READ_cHRM_SUPPORTED\n      if (that->pm->current_encoding != 0)\n      {\n         /* We have an encoding so a cHRM chunk may have been set; if so then\n          * check that the libpng APIs give the correct (X,Y,Z) values within\n          * some margin of error for the round trip through the chromaticity\n          * form.\n          */\n#        ifdef PNG_FLOATING_POINT_SUPPORTED\n#           define API_function png_get_cHRM_XYZ\n#           define API_form \"FP\"\n#           define API_type double\n#           define API_cvt(x) (x)\n#        else\n#           define API_function png_get_cHRM_XYZ_fixed\n#           define API_form \"fixed\"\n#           define API_type png_fixed_point\n#           define API_cvt(x) ((double)(x)/PNG_FP_1)\n#        endif\n\n         API_type rX, gX, bX;\n         API_type rY, gY, bY;\n         API_type rZ, gZ, bZ;\n\n         if ((API_function(pp, pi, &rX, &rY, &rZ, &gX, &gY, &gZ, &bX, &bY, &bZ)\n               & PNG_INFO_cHRM) != 0)\n         {\n            double maxe;\n            const char *el;\n            color_encoding e, o;\n\n            /* Expect libpng to return a normalized result, but the original\n             * color space encoding may not be normalized.\n             */\n            modifier_current_encoding(that->pm, &o);\n            normalize_color_encoding(&o);\n\n            /* Sanity check the pngvalid code - the coefficients should match\n             * the normalized Y values of the encoding unless they were\n             * overridden.\n             */\n            if (data.red_to_set == -1 && data.green_to_set == -1 &&\n               (fabs(o.red.Y - data.red_coefficient) > DBL_EPSILON ||\n               fabs(o.green.Y - data.green_coefficient) > DBL_EPSILON ||\n               fabs(o.blue.Y - data.blue_coefficient) > DBL_EPSILON))\n               png_error(pp, \"internal pngvalid cHRM coefficient error\");\n\n            /* Generate a colour space encoding. */\n            e.gamma = o.gamma; /* not used */\n            e.red.X = API_cvt(rX);\n            e.red.Y = API_cvt(rY);\n            e.red.Z = API_cvt(rZ);\n            e.green.X = API_cvt(gX);\n            e.green.Y = API_cvt(gY);\n            e.green.Z = API_cvt(gZ);\n            e.blue.X = API_cvt(bX);\n            e.blue.Y = API_cvt(bY);\n            e.blue.Z = API_cvt(bZ);\n\n            /* This should match the original one from the png_modifier, within\n             * the range permitted by the libpng fixed point representation.\n             */\n            maxe = 0;\n            el = \"-\"; /* Set to element name with error */\n\n#           define CHECK(col,x)\\\n            {\\\n               double err = fabs(o.col.x - e.col.x);\\\n               if (err > maxe)\\\n               {\\\n                  maxe = err;\\\n                  el = #col \"(\" #x \")\";\\\n               }\\\n            }\n\n            CHECK(red,X)\n            CHECK(red,Y)\n            CHECK(red,Z)\n            CHECK(green,X)\n            CHECK(green,Y)\n            CHECK(green,Z)\n            CHECK(blue,X)\n            CHECK(blue,Y)\n            CHECK(blue,Z)\n\n            /* Here in both fixed and floating cases to check the values read\n             * from the cHRm chunk.  PNG uses fixed point in the cHRM chunk, so\n             * we can't expect better than +/-.5E-5 on the result, allow 1E-5.\n             */\n            if (maxe >= 1E-5)\n            {\n               size_t pos = 0;\n               char buffer[256];\n\n               pos = safecat(buffer, sizeof buffer, pos, API_form);\n               pos = safecat(buffer, sizeof buffer, pos, \" cHRM \");\n               pos = safecat(buffer, sizeof buffer, pos, el);\n               pos = safecat(buffer, sizeof buffer, pos, \" error: \");\n               pos = safecatd(buffer, sizeof buffer, pos, maxe, 7);\n               pos = safecat(buffer, sizeof buffer, pos, \" \");\n               /* Print the color space without the gamma value: */\n               pos = safecat_color_encoding(buffer, sizeof buffer, pos, &o, 0);\n               pos = safecat(buffer, sizeof buffer, pos, \" -> \");\n               pos = safecat_color_encoding(buffer, sizeof buffer, pos, &e, 0);\n\n               png_error(pp, buffer);\n            }\n         }\n      }\n#  endif /* READ_cHRM */\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_rgb_to_gray_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if ((that->colour_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      double gray, err;\n\n#     if PNG_LIBPNG_VER < 10700\n         if (that->colour_type == PNG_COLOR_TYPE_PALETTE)\n            image_pixel_convert_PLTE(that);\n#     endif\n\n      /* Image now has RGB channels... */\n#  if DIGITIZE\n      {\n         png_modifier *pm = display->pm;\n         const unsigned int sample_depth = that->sample_depth;\n         const unsigned int calc_depth = (pm->assume_16_bit_calculations ? 16 :\n            sample_depth);\n         const unsigned int gamma_depth =\n            (sample_depth == 16 ?\n               display->max_gamma_8 :\n               (pm->assume_16_bit_calculations ?\n                  display->max_gamma_8 :\n                  sample_depth));\n         int isgray;\n         double r, g, b;\n         double rlo, rhi, glo, ghi, blo, bhi, graylo, grayhi;\n\n         /* Do this using interval arithmetic, otherwise it is too difficult to\n          * handle the errors correctly.\n          *\n          * To handle the gamma correction work out the upper and lower bounds\n          * of the digitized value.  Assume rounding here - normally the values\n          * will be identical after this operation if there is only one\n          * transform, feel free to delete the png_error checks on this below in\n          * the future (this is just me trying to ensure it works!)\n          *\n          * Interval arithmetic is exact, but to implement it it must be\n          * possible to control the floating point implementation rounding mode.\n          * This cannot be done in ANSI-C, so instead I reduce the 'lo' values\n          * by DBL_EPSILON and increase the 'hi' values by the same.\n          */\n#        define DD(v,d,r) (digitize(v*(1-DBL_EPSILON), d, r) * (1-DBL_EPSILON))\n#        define DU(v,d,r) (digitize(v*(1+DBL_EPSILON), d, r) * (1+DBL_EPSILON))\n\n         r = rlo = rhi = that->redf;\n         rlo -= that->rede;\n         rlo = DD(rlo, calc_depth, 1/*round*/);\n         rhi += that->rede;\n         rhi = DU(rhi, calc_depth, 1/*round*/);\n\n         g = glo = ghi = that->greenf;\n         glo -= that->greene;\n         glo = DD(glo, calc_depth, 1/*round*/);\n         ghi += that->greene;\n         ghi = DU(ghi, calc_depth, 1/*round*/);\n\n         b = blo = bhi = that->bluef;\n         blo -= that->bluee;\n         blo = DD(blo, calc_depth, 1/*round*/);\n         bhi += that->bluee;\n         bhi = DU(bhi, calc_depth, 1/*round*/);\n\n         isgray = r==g && g==b;\n\n         if (data.gamma != 1)\n         {\n            const double power = 1/data.gamma;\n            const double abse = .5/(sample_depth == 16 ? 65535 : 255);\n\n            /* If a gamma calculation is done it is done using lookup tables of\n             * precision gamma_depth, so the already digitized value above may\n             * need to be further digitized here.\n             */\n            if (gamma_depth != calc_depth)\n            {\n               rlo = DD(rlo, gamma_depth, 0/*truncate*/);\n               rhi = DU(rhi, gamma_depth, 0/*truncate*/);\n               glo = DD(glo, gamma_depth, 0/*truncate*/);\n               ghi = DU(ghi, gamma_depth, 0/*truncate*/);\n               blo = DD(blo, gamma_depth, 0/*truncate*/);\n               bhi = DU(bhi, gamma_depth, 0/*truncate*/);\n            }\n\n            /* 'abse' is the error in the gamma table calculation itself. */\n            r = pow(r, power);\n            rlo = DD(pow(rlo, power)-abse, calc_depth, 1);\n            rhi = DU(pow(rhi, power)+abse, calc_depth, 1);\n\n            g = pow(g, power);\n            glo = DD(pow(glo, power)-abse, calc_depth, 1);\n            ghi = DU(pow(ghi, power)+abse, calc_depth, 1);\n\n            b = pow(b, power);\n            blo = DD(pow(blo, power)-abse, calc_depth, 1);\n            bhi = DU(pow(bhi, power)+abse, calc_depth, 1);\n         }\n\n         /* Now calculate the actual gray values.  Although the error in the\n          * coefficients depends on whether they were specified on the command\n          * line (in which case truncation to 15 bits happened) or not (rounding\n          * was used) the maxium error in an individual coefficient is always\n          * 2/32768, because even in the rounding case the requirement that\n          * coefficients add up to 32768 can cause a larger rounding error.\n          *\n          * The only time when rounding doesn't occur in 1.5.5 and later is when\n          * the non-gamma code path is used for less than 16 bit data.\n          */\n         gray = r * data.red_coefficient + g * data.green_coefficient +\n            b * data.blue_coefficient;\n\n         {\n            const int do_round = data.gamma != 1 || calc_depth == 16;\n            const double ce = 2. / 32768;\n\n            graylo = DD(rlo * (data.red_coefficient-ce) +\n               glo * (data.green_coefficient-ce) +\n               blo * (data.blue_coefficient-ce), calc_depth, do_round);\n            if (graylo > gray) /* always accept the right answer */\n               graylo = gray;\n\n            grayhi = DU(rhi * (data.red_coefficient+ce) +\n               ghi * (data.green_coefficient+ce) +\n               bhi * (data.blue_coefficient+ce), calc_depth, do_round);\n            if (grayhi < gray)\n               grayhi = gray;\n         }\n\n         /* And invert the gamma. */\n         if (data.gamma != 1)\n         {\n            const double power = data.gamma;\n\n            /* And this happens yet again, shifting the values once more. */\n            if (gamma_depth != sample_depth)\n            {\n               rlo = DD(rlo, gamma_depth, 0/*truncate*/);\n               rhi = DU(rhi, gamma_depth, 0/*truncate*/);\n               glo = DD(glo, gamma_depth, 0/*truncate*/);\n               ghi = DU(ghi, gamma_depth, 0/*truncate*/);\n               blo = DD(blo, gamma_depth, 0/*truncate*/);\n               bhi = DU(bhi, gamma_depth, 0/*truncate*/);\n            }\n\n            gray = pow(gray, power);\n            graylo = DD(pow(graylo, power), sample_depth, 1);\n            grayhi = DU(pow(grayhi, power), sample_depth, 1);\n         }\n\n#        undef DD\n#        undef DU\n\n         /* Now the error can be calculated.\n          *\n          * If r==g==b because there is no overall gamma correction libpng\n          * currently preserves the original value.\n          */\n         if (isgray)\n            err = (that->rede + that->greene + that->bluee)/3;\n\n         else\n         {\n            err = fabs(grayhi-gray);\n\n            if (fabs(gray - graylo) > err)\n               err = fabs(graylo-gray);\n\n#if !RELEASE_BUILD\n            /* Check that this worked: */\n            if (err > pm->limit)\n            {\n               size_t pos = 0;\n               char buffer[128];\n\n               pos = safecat(buffer, sizeof buffer, pos, \"rgb_to_gray error \");\n               pos = safecatd(buffer, sizeof buffer, pos, err, 6);\n               pos = safecat(buffer, sizeof buffer, pos, \" exceeds limit \");\n               pos = safecatd(buffer, sizeof buffer, pos, pm->limit, 6);\n               png_warning(pp, buffer);\n               pm->limit = err;\n            }\n#endif /* !RELEASE_BUILD */\n         }\n      }\n#  else  /* !DIGITIZE */\n      {\n         double r = that->redf;\n         double re = that->rede;\n         double g = that->greenf;\n         double ge = that->greene;\n         double b = that->bluef;\n         double be = that->bluee;\n\n#        if PNG_LIBPNG_VER < 10700\n            /* The true gray case involves no math in earlier versions (not\n             * true, there was some if gamma correction was happening too.)\n             */\n            if (r == g && r == b)\n            {\n               gray = r;\n               err = re;\n               if (err < ge) err = ge;\n               if (err < be) err = be;\n            }\n\n            else\n#        endif /* before 1.7 */\n         if (data.gamma == 1)\n         {\n            /* There is no need to do the conversions to and from linear space,\n             * so the calculation should be a lot more accurate.  There is a\n             * built in error in the coefficients because they only have 15 bits\n             * and are adjusted to make sure they add up to 32768.  This\n             * involves a integer calculation with truncation of the form:\n             *\n             *     ((int)(coefficient * 100000) * 32768)/100000\n             *\n             * This is done to the red and green coefficients (the ones\n             * provided to the API) then blue is calculated from them so the\n             * result adds up to 32768.  In the worst case this can result in\n             * a -1 error in red and green and a +2 error in blue.  Consequently\n             * the worst case in the calculation below is 2/32768 error.\n             *\n             * TODO: consider fixing this in libpng by rounding the calculation\n             * limiting the error to 1/32768.\n             *\n             * Handling this by adding 2/32768 here avoids needing to increase\n             * the global error limits to take this into account.)\n             */\n            gray = r * data.red_coefficient + g * data.green_coefficient +\n               b * data.blue_coefficient;\n            err = re * data.red_coefficient + ge * data.green_coefficient +\n               be * data.blue_coefficient + 2./32768 + gray * 5 * DBL_EPSILON;\n         }\n\n         else\n         {\n            /* The calculation happens in linear space, and this produces much\n             * wider errors in the encoded space.  These are handled here by\n             * factoring the errors in to the calculation.  There are two table\n             * lookups in the calculation and each introduces a quantization\n             * error defined by the table size.\n             */\n            png_modifier *pm = display->pm;\n            double in_qe = (that->sample_depth > 8 ? .5/65535 : .5/255);\n            double out_qe = (that->sample_depth > 8 ? .5/65535 :\n               (pm->assume_16_bit_calculations ? .5/(1<<display->max_gamma_8) :\n               .5/255));\n            double rhi, ghi, bhi, grayhi;\n            double g1 = 1/data.gamma;\n\n            rhi = r + re + in_qe; if (rhi > 1) rhi = 1;\n            r -= re + in_qe; if (r < 0) r = 0;\n            ghi = g + ge + in_qe; if (ghi > 1) ghi = 1;\n            g -= ge + in_qe; if (g < 0) g = 0;\n            bhi = b + be + in_qe; if (bhi > 1) bhi = 1;\n            b -= be + in_qe; if (b < 0) b = 0;\n\n            r = pow(r, g1)*(1-DBL_EPSILON); rhi = pow(rhi, g1)*(1+DBL_EPSILON);\n            g = pow(g, g1)*(1-DBL_EPSILON); ghi = pow(ghi, g1)*(1+DBL_EPSILON);\n            b = pow(b, g1)*(1-DBL_EPSILON); bhi = pow(bhi, g1)*(1+DBL_EPSILON);\n\n            /* Work out the lower and upper bounds for the gray value in the\n             * encoded space, then work out an average and error.  Remove the\n             * previously added input quantization error at this point.\n             */\n            gray = r * data.red_coefficient + g * data.green_coefficient +\n               b * data.blue_coefficient - 2./32768 - out_qe;\n            if (gray <= 0)\n               gray = 0;\n            else\n            {\n               gray *= (1 - 6 * DBL_EPSILON);\n               gray = pow(gray, data.gamma) * (1-DBL_EPSILON);\n            }\n\n            grayhi = rhi * data.red_coefficient + ghi * data.green_coefficient +\n               bhi * data.blue_coefficient + 2./32768 + out_qe;\n            grayhi *= (1 + 6 * DBL_EPSILON);\n            if (grayhi >= 1)\n               grayhi = 1;\n            else\n               grayhi = pow(grayhi, data.gamma) * (1+DBL_EPSILON);\n\n            err = (grayhi - gray) / 2;\n            gray = (grayhi + gray) / 2;\n\n            if (err <= in_qe)\n               err = gray * DBL_EPSILON;\n\n            else\n               err -= in_qe;\n\n#if !RELEASE_BUILD\n            /* Validate that the error is within limits (this has caused\n             * problems before, it's much easier to detect them here.)\n             */\n            if (err > pm->limit)\n            {\n               size_t pos = 0;\n               char buffer[128];\n\n               pos = safecat(buffer, sizeof buffer, pos, \"rgb_to_gray error \");\n               pos = safecatd(buffer, sizeof buffer, pos, err, 6);\n               pos = safecat(buffer, sizeof buffer, pos, \" exceeds limit \");\n               pos = safecatd(buffer, sizeof buffer, pos, pm->limit, 6);\n               png_warning(pp, buffer);\n               pm->limit = err;\n            }\n#endif /* !RELEASE_BUILD */\n         }\n      }\n#  endif /* !DIGITIZE */\n\n      that->bluef = that->greenf = that->redf = gray;\n      that->bluee = that->greene = that->rede = err;\n\n      /* The sBIT is the minium of the three colour channel sBITs. */\n      if (that->red_sBIT > that->green_sBIT)\n         that->red_sBIT = that->green_sBIT;\n      if (that->red_sBIT > that->blue_sBIT)\n         that->red_sBIT = that->blue_sBIT;\n      that->blue_sBIT = that->green_sBIT = that->red_sBIT;\n\n      /* And remove the colour bit in the type: */\n      if (that->colour_type == PNG_COLOR_TYPE_RGB)\n         that->colour_type = PNG_COLOR_TYPE_GRAY;\n      else if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)\n         that->colour_type = PNG_COLOR_TYPE_GRAY_ALPHA;\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_rgb_to_gray_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return (colour_type & PNG_COLOR_MASK_COLOR) != 0;\n}\n\n#undef data\nIT(rgb_to_gray);\n#undef PT\n#define PT ITSTRUCT(rgb_to_gray)\n#undef image_transform_ini\n#define image_transform_ini image_transform_default_ini\n#endif /* PNG_READ_RGB_TO_GRAY_SUPPORTED */\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n/* png_set_background(png_structp, png_const_color_16p background_color,\n *    int background_gamma_code, int need_expand, double background_gamma)\n * png_set_background_fixed(png_structp, png_const_color_16p background_color,\n *    int background_gamma_code, int need_expand,\n *    png_fixed_point background_gamma)\n *\n * This ignores the gamma (at present.)\n*/\n#define data ITDATA(background)\nstatic image_pixel data;\n\nstatic void\nimage_transform_png_set_background_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_byte colour_type, bit_depth;\n   png_byte random_bytes[8]; /* 8 bytes - 64 bits - the biggest pixel */\n   int expand;\n   png_color_16 back;\n\n   /* We need a background colour, because we don't know exactly what transforms\n    * have been set we have to supply the colour in the original file format and\n    * so we need to know what that is!  The background colour is stored in the\n    * transform_display.\n    */\n   R8(random_bytes);\n\n   /* Read the random value, for colour type 3 the background colour is actually\n    * expressed as a 24bit rgb, not an index.\n    */\n   colour_type = that->this.colour_type;\n   if (colour_type == 3)\n   {\n      colour_type = PNG_COLOR_TYPE_RGB;\n      bit_depth = 8;\n      expand = 0; /* passing in an RGB not a pixel index */\n   }\n\n   else\n   {\n      if (that->this.has_tRNS)\n         that->this.is_transparent = 1;\n\n      bit_depth = that->this.bit_depth;\n      expand = 1;\n   }\n\n   image_pixel_init(&data, random_bytes, colour_type,\n      bit_depth, 0/*x*/, 0/*unused: palette*/, NULL/*format*/);\n\n   /* Extract the background colour from this image_pixel, but make sure the\n    * unused fields of 'back' are garbage.\n    */\n   R8(back);\n\n   if (colour_type & PNG_COLOR_MASK_COLOR)\n   {\n      back.red = (png_uint_16)data.red;\n      back.green = (png_uint_16)data.green;\n      back.blue = (png_uint_16)data.blue;\n   }\n\n   else\n      back.gray = (png_uint_16)data.red;\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n   png_set_background(pp, &back, PNG_BACKGROUND_GAMMA_FILE, expand, 0);\n#else\n   png_set_background_fixed(pp, &back, PNG_BACKGROUND_GAMMA_FILE, expand, 0);\n#endif\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_background_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* Check for tRNS first: */\n   if (that->have_tRNS && that->colour_type != PNG_COLOR_TYPE_PALETTE)\n      image_pixel_add_alpha(that, &display->this, 1/*for background*/);\n\n   /* This is only necessary if the alpha value is less than 1. */\n   if (that->alphaf < 1)\n   {\n      /* Now we do the background calculation without any gamma correction. */\n      if (that->alphaf <= 0)\n      {\n         that->redf = data.redf;\n         that->greenf = data.greenf;\n         that->bluef = data.bluef;\n\n         that->rede = data.rede;\n         that->greene = data.greene;\n         that->bluee = data.bluee;\n\n         that->red_sBIT= data.red_sBIT;\n         that->green_sBIT= data.green_sBIT;\n         that->blue_sBIT= data.blue_sBIT;\n      }\n\n      else /* 0 < alpha < 1 */\n      {\n         double alf = 1 - that->alphaf;\n\n         that->redf = that->redf * that->alphaf + data.redf * alf;\n         that->rede = that->rede * that->alphaf + data.rede * alf +\n            DBL_EPSILON;\n         that->greenf = that->greenf * that->alphaf + data.greenf * alf;\n         that->greene = that->greene * that->alphaf + data.greene * alf +\n            DBL_EPSILON;\n         that->bluef = that->bluef * that->alphaf + data.bluef * alf;\n         that->bluee = that->bluee * that->alphaf + data.bluee * alf +\n            DBL_EPSILON;\n      }\n\n      /* Remove the alpha type and set the alpha (not in that order.) */\n      that->alphaf = 1;\n      that->alphae = 0;\n   }\n\n   if (that->colour_type == PNG_COLOR_TYPE_RGB_ALPHA)\n      that->colour_type = PNG_COLOR_TYPE_RGB;\n   else if (that->colour_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      that->colour_type = PNG_COLOR_TYPE_GRAY;\n   /* PNG_COLOR_TYPE_PALETTE is not changed */\n\n   this->next->mod(this->next, that, pp, display);\n}\n\n#define image_transform_png_set_background_add image_transform_default_add\n\n#undef data\nIT(background);\n#undef PT\n#define PT ITSTRUCT(background)\n#endif /* PNG_READ_BACKGROUND_SUPPORTED */\n\n/* png_set_quantize(png_structp, png_colorp palette, int num_palette,\n *    int maximum_colors, png_const_uint_16p histogram, int full_quantize)\n *\n * Very difficult to validate this!\n */\n/*NOTE: TBD NYI */\n\n/* The data layout transforms are handled by swapping our own channel data,\n * necessarily these need to happen at the end of the transform list because the\n * semantic of the channels changes after these are executed.  Some of these,\n * like set_shift and set_packing, can't be done at present because they change\n * the layout of the data at the sub-sample level so sample() won't get the\n * right answer.\n */\n/* png_set_invert_alpha */\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\n/* Invert the alpha channel\n *\n *  png_set_invert_alpha(png_structrp png_ptr)\n */\nstatic void\nimage_transform_png_set_invert_alpha_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_invert_alpha(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_invert_alpha_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type & 4)\n      that->alpha_inverted = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_invert_alpha_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   /* Only has an effect on pixels with alpha: */\n   return (colour_type & 4) != 0;\n}\n\nIT(invert_alpha);\n#undef PT\n#define PT ITSTRUCT(invert_alpha)\n\n#endif /* PNG_READ_INVERT_ALPHA_SUPPORTED */\n\n/* png_set_bgr */\n#ifdef PNG_READ_BGR_SUPPORTED\n/* Swap R,G,B channels to order B,G,R.\n *\n *  png_set_bgr(png_structrp png_ptr)\n *\n * This only has an effect on RGB and RGBA pixels.\n */\nstatic void\nimage_transform_png_set_bgr_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_bgr(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_bgr_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type == PNG_COLOR_TYPE_RGB ||\n       that->colour_type == PNG_COLOR_TYPE_RGBA)\n       that->swap_rgb = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_bgr_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return colour_type == PNG_COLOR_TYPE_RGB ||\n       colour_type == PNG_COLOR_TYPE_RGBA;\n}\n\nIT(bgr);\n#undef PT\n#define PT ITSTRUCT(bgr)\n\n#endif /* PNG_READ_BGR_SUPPORTED */\n\n/* png_set_swap_alpha */\n#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED\n/* Put the alpha channel first.\n *\n *  png_set_swap_alpha(png_structrp png_ptr)\n *\n * This only has an effect on GA and RGBA pixels.\n */\nstatic void\nimage_transform_png_set_swap_alpha_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_swap_alpha(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_swap_alpha_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type == PNG_COLOR_TYPE_GA ||\n       that->colour_type == PNG_COLOR_TYPE_RGBA)\n      that->alpha_first = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_swap_alpha_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return colour_type == PNG_COLOR_TYPE_GA ||\n       colour_type == PNG_COLOR_TYPE_RGBA;\n}\n\nIT(swap_alpha);\n#undef PT\n#define PT ITSTRUCT(swap_alpha)\n\n#endif /* PNG_READ_SWAP_ALPHA_SUPPORTED */\n\n/* png_set_swap */\n#ifdef PNG_READ_SWAP_SUPPORTED\n/* Byte swap 16-bit components.\n *\n *  png_set_swap(png_structrp png_ptr)\n */\nstatic void\nimage_transform_png_set_swap_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_swap(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_swap_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth == 16)\n      that->swap16 = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_swap_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   return bit_depth == 16;\n}\n\nIT(swap);\n#undef PT\n#define PT ITSTRUCT(swap)\n\n#endif /* PNG_READ_SWAP_SUPPORTED */\n\n#ifdef PNG_READ_FILLER_SUPPORTED\n/* Add a filler byte to 8-bit Gray or 24-bit RGB images.\n *\n *  png_set_filler, (png_structp png_ptr, png_uint_32 filler, int flags));\n *\n * Flags:\n *\n *  PNG_FILLER_BEFORE\n *  PNG_FILLER_AFTER\n */\n#define data ITDATA(filler)\nstatic struct\n{\n   png_uint_32 filler;\n   int         flags;\n} data;\n\nstatic void\nimage_transform_png_set_filler_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   /* Need a random choice for 'before' and 'after' as well as for the\n    * filler.  The 'filler' value has all 32 bits set, but only bit_depth\n    * will be used.  At this point we don't know bit_depth.\n    */\n   data.filler = random_u32();\n   data.flags = random_choice();\n\n   png_set_filler(pp, data.filler, data.flags);\n\n   /* The standard display handling stuff also needs to know that\n    * there is a filler, so set that here.\n    */\n   that->this.filler = 1;\n\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_filler_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth >= 8 &&\n       (that->colour_type == PNG_COLOR_TYPE_RGB ||\n        that->colour_type == PNG_COLOR_TYPE_GRAY))\n   {\n      const unsigned int max = (1U << that->bit_depth)-1;\n      that->alpha = data.filler & max;\n      that->alphaf = ((double)that->alpha) / max;\n      that->alphae = 0;\n\n      /* The filler has been stored in the alpha channel, we must record\n       * that this has been done for the checking later on, the color\n       * type is faked to have an alpha channel, but libpng won't report\n       * this; the app has to know the extra channel is there and this\n       * was recording in standard_display::filler above.\n       */\n      that->colour_type |= 4; /* alpha added */\n      that->alpha_first = data.flags == PNG_FILLER_BEFORE;\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_filler_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   this->next = *that;\n   *that = this;\n\n   return bit_depth >= 8 && (colour_type == PNG_COLOR_TYPE_RGB ||\n           colour_type == PNG_COLOR_TYPE_GRAY);\n}\n\n#undef data\nIT(filler);\n#undef PT\n#define PT ITSTRUCT(filler)\n\n/* png_set_add_alpha, (png_structp png_ptr, png_uint_32 filler, int flags)); */\n/* Add an alpha byte to 8-bit Gray or 24-bit RGB images. */\n#define data ITDATA(add_alpha)\nstatic struct\n{\n   png_uint_32 filler;\n   int         flags;\n} data;\n\nstatic void\nimage_transform_png_set_add_alpha_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   /* Need a random choice for 'before' and 'after' as well as for the\n    * filler.  The 'filler' value has all 32 bits set, but only bit_depth\n    * will be used.  At this point we don't know bit_depth.\n    */\n   data.filler = random_u32();\n   data.flags = random_choice();\n\n   png_set_add_alpha(pp, data.filler, data.flags);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_add_alpha_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth >= 8 &&\n       (that->colour_type == PNG_COLOR_TYPE_RGB ||\n        that->colour_type == PNG_COLOR_TYPE_GRAY))\n   {\n      const unsigned int max = (1U << that->bit_depth)-1;\n      that->alpha = data.filler & max;\n      that->alphaf = ((double)that->alpha) / max;\n      that->alphae = 0;\n\n      that->colour_type |= 4; /* alpha added */\n      that->alpha_first = data.flags == PNG_FILLER_BEFORE;\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_add_alpha_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   this->next = *that;\n   *that = this;\n\n   return bit_depth >= 8 && (colour_type == PNG_COLOR_TYPE_RGB ||\n           colour_type == PNG_COLOR_TYPE_GRAY);\n}\n\n#undef data\nIT(add_alpha);\n#undef PT\n#define PT ITSTRUCT(add_alpha)\n\n#endif /* PNG_READ_FILLER_SUPPORTED */\n\n/* png_set_packing */\n#ifdef PNG_READ_PACK_SUPPORTED\n/* Use 1 byte per pixel in 1, 2, or 4-bit depth files.\n *\n *  png_set_packing(png_structrp png_ptr)\n *\n * This should only affect grayscale and palette images with less than 8 bits\n * per pixel.\n */\nstatic void\nimage_transform_png_set_packing_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_packing(pp);\n   that->unpacked = 1;\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_packing_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* The general expand case depends on what the colour type is,\n    * low bit-depth pixel values are unpacked into bytes without\n    * scaling, so sample_depth is not changed.\n    */\n   if (that->bit_depth < 8) /* grayscale or palette */\n      that->bit_depth = 8;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_packing_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   /* Nothing should happen unless the bit depth is less than 8: */\n   return bit_depth < 8;\n}\n\nIT(packing);\n#undef PT\n#define PT ITSTRUCT(packing)\n\n#endif /* PNG_READ_PACK_SUPPORTED */\n\n/* png_set_packswap */\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n/* Swap pixels packed into bytes; reverses the order on screen so that\n * the high order bits correspond to the rightmost pixels.\n *\n *  png_set_packswap(png_structrp png_ptr)\n */\nstatic void\nimage_transform_png_set_packswap_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_packswap(pp);\n   that->this.littleendian = 1;\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_packswap_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->bit_depth < 8)\n      that->littleendian = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_packswap_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(colour_type)\n\n   this->next = *that;\n   *that = this;\n\n   return bit_depth < 8;\n}\n\nIT(packswap);\n#undef PT\n#define PT ITSTRUCT(packswap)\n\n#endif /* PNG_READ_PACKSWAP_SUPPORTED */\n\n\n/* png_set_invert_mono */\n#ifdef PNG_READ_INVERT_MONO_SUPPORTED\n/* Invert the gray channel\n *\n *  png_set_invert_mono(png_structrp png_ptr)\n */\nstatic void\nimage_transform_png_set_invert_mono_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_invert_mono(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_invert_mono_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   if (that->colour_type & 4)\n      that->mono_inverted = 1;\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_invert_mono_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   /* Only has an effect on pixels with no colour: */\n   return (colour_type & 2) == 0;\n}\n\nIT(invert_mono);\n#undef PT\n#define PT ITSTRUCT(invert_mono)\n\n#endif /* PNG_READ_INVERT_MONO_SUPPORTED */\n\n#ifdef PNG_READ_SHIFT_SUPPORTED\n/* png_set_shift(png_structp, png_const_color_8p true_bits)\n *\n * The output pixels will be shifted by the given true_bits\n * values.\n */\n#define data ITDATA(shift)\nstatic png_color_8 data;\n\nstatic void\nimage_transform_png_set_shift_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   /* Get a random set of shifts.  The shifts need to do something\n    * to test the transform, so they are limited to the bit depth\n    * of the input image.  Notice that in the following the 'gray'\n    * field is randomized independently.  This acts as a check that\n    * libpng does use the correct field.\n    */\n   const unsigned int depth = that->this.bit_depth;\n\n   data.red = (png_byte)/*SAFE*/(random_mod(depth)+1);\n   data.green = (png_byte)/*SAFE*/(random_mod(depth)+1);\n   data.blue = (png_byte)/*SAFE*/(random_mod(depth)+1);\n   data.gray = (png_byte)/*SAFE*/(random_mod(depth)+1);\n   data.alpha = (png_byte)/*SAFE*/(random_mod(depth)+1);\n\n   png_set_shift(pp, &data);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_shift_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   /* Copy the correct values into the sBIT fields, libpng does not do\n    * anything to palette data:\n    */\n   if (that->colour_type != PNG_COLOR_TYPE_PALETTE)\n   {\n       that->sig_bits = 1;\n\n       /* The sBIT fields are reset to the values previously sent to\n        * png_set_shift according to the colour type.\n        * does.\n        */\n       if (that->colour_type & 2) /* RGB channels */\n       {\n          that->red_sBIT = data.red;\n          that->green_sBIT = data.green;\n          that->blue_sBIT = data.blue;\n       }\n\n       else /* One grey channel */\n          that->red_sBIT = that->green_sBIT = that->blue_sBIT = data.gray;\n\n       that->alpha_sBIT = data.alpha;\n   }\n\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_shift_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   UNUSED(bit_depth)\n\n   this->next = *that;\n   *that = this;\n\n   return colour_type != PNG_COLOR_TYPE_PALETTE;\n}\n\nIT(shift);\n#undef PT\n#define PT ITSTRUCT(shift)\n\n#endif /* PNG_READ_SHIFT_SUPPORTED */\n\n#ifdef THIS_IS_THE_PROFORMA\nstatic void\nimage_transform_png_set_@_set(const image_transform *this,\n    transform_display *that, png_structp pp, png_infop pi)\n{\n   png_set_@(pp);\n   this->next->set(this->next, that, pp, pi);\n}\n\nstatic void\nimage_transform_png_set_@_mod(const image_transform *this,\n    image_pixel *that, png_const_structp pp,\n    const transform_display *display)\n{\n   this->next->mod(this->next, that, pp, display);\n}\n\nstatic int\nimage_transform_png_set_@_add(image_transform *this,\n    const image_transform **that, png_byte colour_type, png_byte bit_depth)\n{\n   this->next = *that;\n   *that = this;\n\n   return 1;\n}\n\nIT(@);\n#endif\n\n\n/* This may just be 'end' if all the transforms are disabled! */\nstatic image_transform *const image_transform_first = &PT;\n\nstatic void\ntransform_enable(const char *name)\n{\n   /* Everything starts out enabled, so if we see an 'enable' disabled\n    * everything else the first time round.\n    */\n   static int all_disabled = 0;\n   int found_it = 0;\n   image_transform *list = image_transform_first;\n\n   while (list != &image_transform_end)\n   {\n      if (strcmp(list->name, name) == 0)\n      {\n         list->enable = 1;\n         found_it = 1;\n      }\n      else if (!all_disabled)\n         list->enable = 0;\n\n      list = list->list;\n   }\n\n   all_disabled = 1;\n\n   if (!found_it)\n   {\n      fprintf(stderr, \"pngvalid: --transform-enable=%s: unknown transform\\n\",\n         name);\n      exit(99);\n   }\n}\n\nstatic void\ntransform_disable(const char *name)\n{\n   image_transform *list = image_transform_first;\n\n   while (list != &image_transform_end)\n   {\n      if (strcmp(list->name, name) == 0)\n      {\n         list->enable = 0;\n         return;\n      }\n\n      list = list->list;\n   }\n\n   fprintf(stderr, \"pngvalid: --transform-disable=%s: unknown transform\\n\",\n      name);\n   exit(99);\n}\n\nstatic void\nimage_transform_reset_count(void)\n{\n   image_transform *next = image_transform_first;\n   int count = 0;\n\n   while (next != &image_transform_end)\n   {\n      next->local_use = 0;\n      next->next = 0;\n      next = next->list;\n      ++count;\n   }\n\n   /* This can only happen if we every have more than 32 transforms (excluding\n    * the end) in the list.\n    */\n   if (count > 32) abort();\n}\n\nstatic int\nimage_transform_test_counter(png_uint_32 counter, unsigned int max)\n{\n   /* Test the list to see if there is any point contining, given a current\n    * counter and a 'max' value.\n    */\n   image_transform *next = image_transform_first;\n\n   while (next != &image_transform_end)\n   {\n      /* For max 0 or 1 continue until the counter overflows: */\n      counter >>= 1;\n\n      /* Continue if any entry hasn't reacked the max. */\n      if (max > 1 && next->local_use < max)\n         return 1;\n      next = next->list;\n   }\n\n   return max <= 1 && counter == 0;\n}\n\nstatic png_uint_32\nimage_transform_add(const image_transform **this, unsigned int max,\n   png_uint_32 counter, char *name, size_t sizeof_name, size_t *pos,\n   png_byte colour_type, png_byte bit_depth)\n{\n   for (;;) /* until we manage to add something */\n   {\n      png_uint_32 mask;\n      image_transform *list;\n\n      /* Find the next counter value, if the counter is zero this is the start\n       * of the list.  This routine always returns the current counter (not the\n       * next) so it returns 0 at the end and expects 0 at the beginning.\n       */\n      if (counter == 0) /* first time */\n      {\n         image_transform_reset_count();\n         if (max <= 1)\n            counter = 1;\n         else\n            counter = random_32();\n      }\n      else /* advance the counter */\n      {\n         switch (max)\n         {\n            case 0:  ++counter; break;\n            case 1:  counter <<= 1; break;\n            default: counter = random_32(); break;\n         }\n      }\n\n      /* Now add all these items, if possible */\n      *this = &image_transform_end;\n      list = image_transform_first;\n      mask = 1;\n\n      /* Go through the whole list adding anything that the counter selects: */\n      while (list != &image_transform_end)\n      {\n         if ((counter & mask) != 0 && list->enable &&\n             (max == 0 || list->local_use < max))\n         {\n            /* Candidate to add: */\n            if (list->add(list, this, colour_type, bit_depth) || max == 0)\n            {\n               /* Added, so add to the name too. */\n               *pos = safecat(name, sizeof_name, *pos, \" +\");\n               *pos = safecat(name, sizeof_name, *pos, list->name);\n            }\n\n            else\n            {\n               /* Not useful and max>0, so remove it from *this: */\n               *this = list->next;\n               list->next = 0;\n\n               /* And, since we know it isn't useful, stop it being added again\n                * in this run:\n                */\n               list->local_use = max;\n            }\n         }\n\n         mask <<= 1;\n         list = list->list;\n      }\n\n      /* Now if anything was added we have something to do. */\n      if (*this != &image_transform_end)\n         return counter;\n\n      /* Nothing added, but was there anything in there to add? */\n      if (!image_transform_test_counter(counter, max))\n         return 0;\n   }\n}\n\nstatic void\nperform_transform_test(png_modifier *pm)\n{\n   png_byte colour_type = 0;\n   png_byte bit_depth = 0;\n   unsigned int palette_number = 0;\n\n   while (next_format(&colour_type, &bit_depth, &palette_number, pm->test_lbg,\n            pm->test_tRNS))\n   {\n      png_uint_32 counter = 0;\n      size_t base_pos;\n      char name[64];\n\n      base_pos = safecat(name, sizeof name, 0, \"transform:\");\n\n      for (;;)\n      {\n         size_t pos = base_pos;\n         const image_transform *list = 0;\n\n         /* 'max' is currently hardwired to '1'; this should be settable on the\n          * command line.\n          */\n         counter = image_transform_add(&list, 1/*max*/, counter,\n            name, sizeof name, &pos, colour_type, bit_depth);\n\n         if (counter == 0)\n            break;\n\n         /* The command line can change this to checking interlaced images. */\n         do\n         {\n            pm->repeat = 0;\n            transform_test(pm, FILEID(colour_type, bit_depth, palette_number,\n               pm->interlace_type, 0, 0, 0), list, name);\n\n            if (fail(pm))\n               return;\n         }\n         while (pm->repeat);\n      }\n   }\n}\n#endif /* PNG_READ_TRANSFORMS_SUPPORTED */\n\n/********************************* GAMMA TESTS ********************************/\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* Reader callbacks and implementations, where they differ from the standard\n * ones.\n */\ntypedef struct gamma_display\n{\n   standard_display this;\n\n   /* Parameters */\n   png_modifier*    pm;\n   double           file_gamma;\n   double           screen_gamma;\n   double           background_gamma;\n   png_byte         sbit;\n   int              threshold_test;\n   int              use_input_precision;\n   int              scale16;\n   int              expand16;\n   int              do_background;\n   png_color_16     background_color;\n\n   /* Local variables */\n   double       maxerrout;\n   double       maxerrpc;\n   double       maxerrabs;\n} gamma_display;\n\n#define ALPHA_MODE_OFFSET 4\n\nstatic void\ngamma_display_init(gamma_display *dp, png_modifier *pm, png_uint_32 id,\n    double file_gamma, double screen_gamma, png_byte sbit, int threshold_test,\n    int use_input_precision, int scale16, int expand16,\n    int do_background, const png_color_16 *pointer_to_the_background_color,\n    double background_gamma)\n{\n   /* Standard fields */\n   standard_display_init(&dp->this, &pm->this, id, do_read_interlace,\n      pm->use_update_info);\n\n   /* Parameter fields */\n   dp->pm = pm;\n   dp->file_gamma = file_gamma;\n   dp->screen_gamma = screen_gamma;\n   dp->background_gamma = background_gamma;\n   dp->sbit = sbit;\n   dp->threshold_test = threshold_test;\n   dp->use_input_precision = use_input_precision;\n   dp->scale16 = scale16;\n   dp->expand16 = expand16;\n   dp->do_background = do_background;\n   if (do_background && pointer_to_the_background_color != 0)\n      dp->background_color = *pointer_to_the_background_color;\n   else\n      memset(&dp->background_color, 0, sizeof dp->background_color);\n\n   /* Local variable fields */\n   dp->maxerrout = dp->maxerrpc = dp->maxerrabs = 0;\n}\n\nstatic void\ngamma_info_imp(gamma_display *dp, png_structp pp, png_infop pi)\n{\n   /* Reuse the standard stuff as appropriate. */\n   standard_info_part1(&dp->this, pp, pi);\n\n   /* If requested strip 16 to 8 bits - this is handled automagically below\n    * because the output bit depth is read from the library.  Note that there\n    * are interactions with sBIT but, internally, libpng makes sbit at most\n    * PNG_MAX_GAMMA_8 prior to 1.7 when doing the following.\n    */\n   if (dp->scale16)\n#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n         png_set_scale_16(pp);\n#     else\n         /* The following works both in 1.5.4 and earlier versions: */\n#        ifdef PNG_READ_16_TO_8_SUPPORTED\n            png_set_strip_16(pp);\n#        else\n            png_error(pp, \"scale16 (16 to 8 bit conversion) not supported\");\n#        endif\n#     endif\n\n   if (dp->expand16)\n#     ifdef PNG_READ_EXPAND_16_SUPPORTED\n         png_set_expand_16(pp);\n#     else\n         png_error(pp, \"expand16 (8 to 16 bit conversion) not supported\");\n#     endif\n\n   if (dp->do_background >= ALPHA_MODE_OFFSET)\n   {\n#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      {\n         /* This tests the alpha mode handling, if supported. */\n         int mode = dp->do_background - ALPHA_MODE_OFFSET;\n\n         /* The gamma value is the output gamma, and is in the standard,\n          * non-inverted, represenation.  It provides a default for the PNG file\n          * gamma, but since the file has a gAMA chunk this does not matter.\n          */\n         const double sg = dp->screen_gamma;\n#        ifndef PNG_FLOATING_POINT_SUPPORTED\n            const png_fixed_point g = fix(sg);\n#        endif\n\n#        ifdef PNG_FLOATING_POINT_SUPPORTED\n            png_set_alpha_mode(pp, mode, sg);\n#        else\n            png_set_alpha_mode_fixed(pp, mode, g);\n#        endif\n\n         /* However, for the standard Porter-Duff algorithm the output defaults\n          * to be linear, so if the test requires non-linear output it must be\n          * corrected here.\n          */\n         if (mode == PNG_ALPHA_STANDARD && sg != 1)\n         {\n#           ifdef PNG_FLOATING_POINT_SUPPORTED\n               png_set_gamma(pp, sg, dp->file_gamma);\n#           else\n               png_fixed_point f = fix(dp->file_gamma);\n               png_set_gamma_fixed(pp, g, f);\n#           endif\n         }\n      }\n#     else\n         png_error(pp, \"alpha mode handling not supported\");\n#     endif\n   }\n\n   else\n   {\n      /* Set up gamma processing. */\n#     ifdef PNG_FLOATING_POINT_SUPPORTED\n         png_set_gamma(pp, dp->screen_gamma, dp->file_gamma);\n#     else\n      {\n         png_fixed_point s = fix(dp->screen_gamma);\n         png_fixed_point f = fix(dp->file_gamma);\n         png_set_gamma_fixed(pp, s, f);\n      }\n#     endif\n\n      if (dp->do_background)\n      {\n#     ifdef PNG_READ_BACKGROUND_SUPPORTED\n         /* NOTE: this assumes the caller provided the correct background gamma!\n          */\n         const double bg = dp->background_gamma;\n#        ifndef PNG_FLOATING_POINT_SUPPORTED\n            const png_fixed_point g = fix(bg);\n#        endif\n\n#        ifdef PNG_FLOATING_POINT_SUPPORTED\n            png_set_background(pp, &dp->background_color, dp->do_background,\n               0/*need_expand*/, bg);\n#        else\n            png_set_background_fixed(pp, &dp->background_color,\n               dp->do_background, 0/*need_expand*/, g);\n#        endif\n#     else\n         png_error(pp, \"png_set_background not supported\");\n#     endif\n      }\n   }\n\n   {\n      int i = dp->this.use_update_info;\n      /* Always do one call, even if use_update_info is 0. */\n      do\n         png_read_update_info(pp, pi);\n      while (--i > 0);\n   }\n\n   /* Now we may get a different cbRow: */\n   standard_info_part2(&dp->this, pp, pi, 1 /*images*/);\n}\n\nstatic void PNGCBAPI\ngamma_info(png_structp pp, png_infop pi)\n{\n   gamma_info_imp(voidcast(gamma_display*, png_get_progressive_ptr(pp)), pp,\n      pi);\n}\n\n/* Validate a single component value - the routine gets the input and output\n * sample values as unscaled PNG component values along with a cache of all the\n * information required to validate the values.\n */\ntypedef struct validate_info\n{\n   png_const_structp  pp;\n   gamma_display *dp;\n   png_byte sbit;\n   int use_input_precision;\n   int do_background;\n   int scale16;\n   unsigned int sbit_max;\n   unsigned int isbit_shift;\n   unsigned int outmax;\n\n   double gamma_correction; /* Overall correction required. */\n   double file_inverse;     /* Inverse of file gamma. */\n   double screen_gamma;\n   double screen_inverse;   /* Inverse of screen gamma. */\n\n   double background_red;   /* Linear background value, red or gray. */\n   double background_green;\n   double background_blue;\n\n   double maxabs;\n   double maxpc;\n   double maxcalc;\n   double maxout;\n   double maxout_total;     /* Total including quantization error */\n   double outlog;\n   int    outquant;\n}\nvalidate_info;\n\nstatic void\ninit_validate_info(validate_info *vi, gamma_display *dp, png_const_structp pp,\n    int in_depth, int out_depth)\n{\n   const unsigned int outmax = (1U<<out_depth)-1;\n\n   vi->pp = pp;\n   vi->dp = dp;\n\n   if (dp->sbit > 0 && dp->sbit < in_depth)\n   {\n      vi->sbit = dp->sbit;\n      vi->isbit_shift = in_depth - dp->sbit;\n   }\n\n   else\n   {\n      vi->sbit = (png_byte)in_depth;\n      vi->isbit_shift = 0;\n   }\n\n   vi->sbit_max = (1U << vi->sbit)-1;\n\n   /* This mimics the libpng threshold test, '0' is used to prevent gamma\n    * correction in the validation test.\n    */\n   vi->screen_gamma = dp->screen_gamma;\n   if (fabs(vi->screen_gamma-1) < PNG_GAMMA_THRESHOLD)\n      vi->screen_gamma = vi->screen_inverse = 0;\n   else\n      vi->screen_inverse = 1/vi->screen_gamma;\n\n   vi->use_input_precision = dp->use_input_precision;\n   vi->outmax = outmax;\n   vi->maxabs = abserr(dp->pm, in_depth, out_depth);\n   vi->maxpc = pcerr(dp->pm, in_depth, out_depth);\n   vi->maxcalc = calcerr(dp->pm, in_depth, out_depth);\n   vi->maxout = outerr(dp->pm, in_depth, out_depth);\n   vi->outquant = output_quantization_factor(dp->pm, in_depth, out_depth);\n   vi->maxout_total = vi->maxout + vi->outquant * .5;\n   vi->outlog = outlog(dp->pm, in_depth, out_depth);\n\n   if ((dp->this.colour_type & PNG_COLOR_MASK_ALPHA) != 0 ||\n      (dp->this.colour_type == 3 && dp->this.is_transparent) ||\n      ((dp->this.colour_type == 0 || dp->this.colour_type == 2) &&\n       dp->this.has_tRNS))\n   {\n      vi->do_background = dp->do_background;\n\n      if (vi->do_background != 0)\n      {\n         const double bg_inverse = 1/dp->background_gamma;\n         double r, g, b;\n\n         /* Caller must at least put the gray value into the red channel */\n         r = dp->background_color.red; r /= outmax;\n         g = dp->background_color.green; g /= outmax;\n         b = dp->background_color.blue; b /= outmax;\n\n#     if 0\n         /* libpng doesn't do this optimization, if we do pngvalid will fail.\n          */\n         if (fabs(bg_inverse-1) >= PNG_GAMMA_THRESHOLD)\n#     endif\n         {\n            r = pow(r, bg_inverse);\n            g = pow(g, bg_inverse);\n            b = pow(b, bg_inverse);\n         }\n\n         vi->background_red = r;\n         vi->background_green = g;\n         vi->background_blue = b;\n      }\n   }\n   else /* Do not expect any background processing */\n      vi->do_background = 0;\n\n   if (vi->do_background == 0)\n      vi->background_red = vi->background_green = vi->background_blue = 0;\n\n   vi->gamma_correction = 1/(dp->file_gamma*dp->screen_gamma);\n   if (fabs(vi->gamma_correction-1) < PNG_GAMMA_THRESHOLD)\n      vi->gamma_correction = 0;\n\n   vi->file_inverse = 1/dp->file_gamma;\n   if (fabs(vi->file_inverse-1) < PNG_GAMMA_THRESHOLD)\n      vi->file_inverse = 0;\n\n   vi->scale16 = dp->scale16;\n}\n\n/* This function handles composition of a single non-alpha component.  The\n * argument is the input sample value, in the range 0..1, and the alpha value.\n * The result is the composed, linear, input sample.  If alpha is less than zero\n * this is the alpha component and the function should not be called!\n */\nstatic double\ngamma_component_compose(int do_background, double input_sample, double alpha,\n   double background, int *compose)\n{\n   switch (do_background)\n   {\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n      case PNG_BACKGROUND_GAMMA_SCREEN:\n      case PNG_BACKGROUND_GAMMA_FILE:\n      case PNG_BACKGROUND_GAMMA_UNIQUE:\n         /* Standard PNG background processing. */\n         if (alpha < 1)\n         {\n            if (alpha > 0)\n            {\n               input_sample = input_sample * alpha + background * (1-alpha);\n               if (compose != NULL)\n                  *compose = 1;\n            }\n\n            else\n               input_sample = background;\n         }\n         break;\n#endif\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:\n         /* The components are premultiplied in either case and the output is\n          * gamma encoded (to get standard Porter-Duff we expect the output\n          * gamma to be set to 1.0!)\n          */\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:\n         /* The optimization is that the partial-alpha entries are linear\n          * while the opaque pixels are gamma encoded, but this only affects the\n          * output encoding.\n          */\n         if (alpha < 1)\n         {\n            if (alpha > 0)\n            {\n               input_sample *= alpha;\n               if (compose != NULL)\n                  *compose = 1;\n            }\n\n            else\n               input_sample = 0;\n         }\n         break;\n#endif\n\n      default:\n         /* Standard cases where no compositing is done (so the component\n          * value is already correct.)\n          */\n         UNUSED(alpha)\n         UNUSED(background)\n         UNUSED(compose)\n         break;\n   }\n\n   return input_sample;\n}\n\n/* This API returns the encoded *input* component, in the range 0..1 */\nstatic double\ngamma_component_validate(const char *name, const validate_info *vi,\n    const unsigned int id, const unsigned int od,\n    const double alpha /* <0 for the alpha channel itself */,\n    const double background /* component background value */)\n{\n   const unsigned int isbit = id >> vi->isbit_shift;\n   const unsigned int sbit_max = vi->sbit_max;\n   const unsigned int outmax = vi->outmax;\n   const int do_background = vi->do_background;\n\n   double i;\n\n   /* First check on the 'perfect' result obtained from the digitized input\n    * value, id, and compare this against the actual digitized result, 'od'.\n    * 'i' is the input result in the range 0..1:\n    */\n   i = isbit; i /= sbit_max;\n\n   /* Check for the fast route: if we don't do any background composition or if\n    * this is the alpha channel ('alpha' < 0) or if the pixel is opaque then\n    * just use the gamma_correction field to correct to the final output gamma.\n    */\n   if (alpha == 1 /* opaque pixel component */ || !do_background\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      || do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_PNG\n#endif\n      || (alpha < 0 /* alpha channel */\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      && do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN\n#endif\n      ))\n   {\n      /* Then get the gamma corrected version of 'i' and compare to 'od', any\n       * error less than .5 is insignificant - just quantization of the output\n       * value to the nearest digital value (nevertheless the error is still\n       * recorded - it's interesting ;-)\n       */\n      double encoded_sample = i;\n      double encoded_error;\n\n      /* alpha less than 0 indicates the alpha channel, which is always linear\n       */\n      if (alpha >= 0 && vi->gamma_correction > 0)\n         encoded_sample = pow(encoded_sample, vi->gamma_correction);\n      encoded_sample *= outmax;\n\n      encoded_error = fabs(od-encoded_sample);\n\n      if (encoded_error > vi->dp->maxerrout)\n         vi->dp->maxerrout = encoded_error;\n\n      if (encoded_error < vi->maxout_total && encoded_error < vi->outlog)\n         return i;\n   }\n\n   /* The slow route - attempt to do linear calculations. */\n   /* There may be an error, or background processing is required, so calculate\n    * the actual sample values - unencoded light intensity values.  Note that in\n    * practice these are not completely unencoded because they include a\n    * 'viewing correction' to decrease or (normally) increase the perceptual\n    * contrast of the image.  There's nothing we can do about this - we don't\n    * know what it is - so assume the unencoded value is perceptually linear.\n    */\n   {\n      double input_sample = i; /* In range 0..1 */\n      double output, error, encoded_sample, encoded_error;\n      double es_lo, es_hi;\n      int compose = 0;           /* Set to one if composition done */\n      int output_is_encoded;     /* Set if encoded to screen gamma */\n      int log_max_error = 1;     /* Check maximum error values */\n      png_const_charp pass = 0;  /* Reason test passes (or 0 for fail) */\n\n      /* Convert to linear light (with the above caveat.)  The alpha channel is\n       * already linear.\n       */\n      if (alpha >= 0)\n      {\n         int tcompose;\n\n         if (vi->file_inverse > 0)\n            input_sample = pow(input_sample, vi->file_inverse);\n\n         /* Handle the compose processing: */\n         tcompose = 0;\n         input_sample = gamma_component_compose(do_background, input_sample,\n            alpha, background, &tcompose);\n\n         if (tcompose)\n            compose = 1;\n      }\n\n      /* And similarly for the output value, but we need to check the background\n       * handling to linearize it correctly.\n       */\n      output = od;\n      output /= outmax;\n\n      output_is_encoded = vi->screen_gamma > 0;\n\n      if (alpha < 0) /* The alpha channel */\n      {\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n         if (do_background != ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN)\n#endif\n         {\n            /* In all other cases the output alpha channel is linear already,\n             * don't log errors here, they are much larger in linear data.\n             */\n            output_is_encoded = 0;\n            log_max_error = 0;\n         }\n      }\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      else /* A component */\n      {\n         if (do_background == ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED &&\n            alpha < 1) /* the optimized case - linear output */\n         {\n            if (alpha > 0) log_max_error = 0;\n            output_is_encoded = 0;\n         }\n      }\n#endif\n\n      if (output_is_encoded)\n         output = pow(output, vi->screen_gamma);\n\n      /* Calculate (or recalculate) the encoded_sample value and repeat the\n       * check above (unnecessary if we took the fast route, but harmless.)\n       */\n      encoded_sample = input_sample;\n      if (output_is_encoded)\n         encoded_sample = pow(encoded_sample, vi->screen_inverse);\n      encoded_sample *= outmax;\n\n      encoded_error = fabs(od-encoded_sample);\n\n      /* Don't log errors in the alpha channel, or the 'optimized' case,\n       * neither are significant to the overall perception.\n       */\n      if (log_max_error && encoded_error > vi->dp->maxerrout)\n         vi->dp->maxerrout = encoded_error;\n\n      if (encoded_error < vi->maxout_total)\n      {\n         if (encoded_error < vi->outlog)\n            return i;\n\n         /* Test passed but error is bigger than the log limit, record why the\n          * test passed:\n          */\n         pass = \"less than maxout:\\n\";\n      }\n\n      /* i: the original input value in the range 0..1\n       *\n       * pngvalid calculations:\n       *  input_sample: linear result; i linearized and composed, range 0..1\n       *  encoded_sample: encoded result; input_sample scaled to ouput bit depth\n       *\n       * libpng calculations:\n       *  output: linear result; od scaled to 0..1 and linearized\n       *  od: encoded result from libpng\n       */\n\n      /* Now we have the numbers for real errors, both absolute values as as a\n       * percentage of the correct value (output):\n       */\n      error = fabs(input_sample-output);\n\n      if (log_max_error && error > vi->dp->maxerrabs)\n         vi->dp->maxerrabs = error;\n\n      /* The following is an attempt to ignore the tendency of quantization to\n       * dominate the percentage errors for lower result values:\n       */\n      if (log_max_error && input_sample > .5)\n      {\n         double percentage_error = error/input_sample;\n         if (percentage_error > vi->dp->maxerrpc)\n            vi->dp->maxerrpc = percentage_error;\n      }\n\n      /* Now calculate the digitization limits for 'encoded_sample' using the\n       * 'max' values.  Note that maxout is in the encoded space but maxpc and\n       * maxabs are in linear light space.\n       *\n       * First find the maximum error in linear light space, range 0..1:\n       */\n      {\n         double tmp = input_sample * vi->maxpc;\n         if (tmp < vi->maxabs) tmp = vi->maxabs;\n         /* If 'compose' is true the composition was done in linear space using\n          * integer arithmetic.  This introduces an extra error of +/- 0.5 (at\n          * least) in the integer space used.  'maxcalc' records this, taking\n          * into account the possibility that even for 16 bit output 8 bit space\n          * may have been used.\n          */\n         if (compose && tmp < vi->maxcalc) tmp = vi->maxcalc;\n\n         /* The 'maxout' value refers to the encoded result, to compare with\n          * this encode input_sample adjusted by the maximum error (tmp) above.\n          */\n         es_lo = encoded_sample - vi->maxout;\n\n         if (es_lo > 0 && input_sample-tmp > 0)\n         {\n            double low_value = input_sample-tmp;\n            if (output_is_encoded)\n               low_value = pow(low_value, vi->screen_inverse);\n            low_value *= outmax;\n            if (low_value < es_lo) es_lo = low_value;\n\n            /* Quantize this appropriately: */\n            es_lo = ceil(es_lo / vi->outquant - .5) * vi->outquant;\n         }\n\n         else\n            es_lo = 0;\n\n         es_hi = encoded_sample + vi->maxout;\n\n         if (es_hi < outmax && input_sample+tmp < 1)\n         {\n            double high_value = input_sample+tmp;\n            if (output_is_encoded)\n               high_value = pow(high_value, vi->screen_inverse);\n            high_value *= outmax;\n            if (high_value > es_hi) es_hi = high_value;\n\n            es_hi = floor(es_hi / vi->outquant + .5) * vi->outquant;\n         }\n\n         else\n            es_hi = outmax;\n      }\n\n      /* The primary test is that the final encoded value returned by the\n       * library should be between the two limits (inclusive) that were\n       * calculated above.\n       */\n      if (od >= es_lo && od <= es_hi)\n      {\n         /* The value passes, but we may need to log the information anyway. */\n         if (encoded_error < vi->outlog)\n            return i;\n\n         if (pass == 0)\n            pass = \"within digitization limits:\\n\";\n      }\n\n      {\n         /* There has been an error in processing, or we need to log this\n          * value.\n          */\n         double is_lo, is_hi;\n\n         /* pass is set at this point if either of the tests above would have\n          * passed.  Don't do these additional tests here - just log the\n          * original [es_lo..es_hi] values.\n          */\n         if (pass == 0 && vi->use_input_precision && vi->dp->sbit)\n         {\n            /* Ok, something is wrong - this actually happens in current libpng\n             * 16-to-8 processing.  Assume that the input value (id, adjusted\n             * for sbit) can be anywhere between value-.5 and value+.5 - quite a\n             * large range if sbit is low.\n             *\n             * NOTE: at present because the libpng gamma table stuff has been\n             * changed to use a rounding algorithm to correct errors in 8-bit\n             * calculations the precise sbit calculation (a shift) has been\n             * lost.  This can result in up to a +/-1 error in the presence of\n             * an sbit less than the bit depth.\n             */\n#           if PNG_LIBPNG_VER < 10700\n#              define SBIT_ERROR .5\n#           else\n#              define SBIT_ERROR 1.\n#           endif\n            double tmp = (isbit - SBIT_ERROR)/sbit_max;\n\n            if (tmp <= 0)\n               tmp = 0;\n\n            else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)\n               tmp = pow(tmp, vi->file_inverse);\n\n            tmp = gamma_component_compose(do_background, tmp, alpha, background,\n               NULL);\n\n            if (output_is_encoded && tmp > 0 && tmp < 1)\n               tmp = pow(tmp, vi->screen_inverse);\n\n            is_lo = ceil(outmax * tmp - vi->maxout_total);\n\n            if (is_lo < 0)\n               is_lo = 0;\n\n            tmp = (isbit + SBIT_ERROR)/sbit_max;\n\n            if (tmp >= 1)\n               tmp = 1;\n\n            else if (alpha >= 0 && vi->file_inverse > 0 && tmp < 1)\n               tmp = pow(tmp, vi->file_inverse);\n\n            tmp = gamma_component_compose(do_background, tmp, alpha, background,\n               NULL);\n\n            if (output_is_encoded && tmp > 0 && tmp < 1)\n               tmp = pow(tmp, vi->screen_inverse);\n\n            is_hi = floor(outmax * tmp + vi->maxout_total);\n\n            if (is_hi > outmax)\n               is_hi = outmax;\n\n            if (!(od < is_lo || od > is_hi))\n            {\n               if (encoded_error < vi->outlog)\n                  return i;\n\n               pass = \"within input precision limits:\\n\";\n            }\n\n            /* One last chance.  If this is an alpha channel and the 16to8\n             * option has been used and 'inaccurate' scaling is used then the\n             * bit reduction is obtained by simply using the top 8 bits of the\n             * value.\n             *\n             * This is only done for older libpng versions when the 'inaccurate'\n             * (chop) method of scaling was used.\n             */\n#           ifndef PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\n#              if PNG_LIBPNG_VER < 10504\n                  /* This may be required for other components in the future,\n                   * but at present the presence of gamma correction effectively\n                   * prevents the errors in the component scaling (I don't quite\n                   * understand why, but since it's better this way I care not\n                   * to ask, JB 20110419.)\n                   */\n                  if (pass == 0 && alpha < 0 && vi->scale16 && vi->sbit > 8 &&\n                     vi->sbit + vi->isbit_shift == 16)\n                  {\n                     tmp = ((id >> 8) - .5)/255;\n\n                     if (tmp > 0)\n                     {\n                        is_lo = ceil(outmax * tmp - vi->maxout_total);\n                        if (is_lo < 0) is_lo = 0;\n                     }\n\n                     else\n                        is_lo = 0;\n\n                     tmp = ((id >> 8) + .5)/255;\n\n                     if (tmp < 1)\n                     {\n                        is_hi = floor(outmax * tmp + vi->maxout_total);\n                        if (is_hi > outmax) is_hi = outmax;\n                     }\n\n                     else\n                        is_hi = outmax;\n\n                     if (!(od < is_lo || od > is_hi))\n                     {\n                        if (encoded_error < vi->outlog)\n                           return i;\n\n                        pass = \"within 8 bit limits:\\n\";\n                     }\n                  }\n#              endif\n#           endif\n         }\n         else /* !use_input_precision */\n            is_lo = es_lo, is_hi = es_hi;\n\n         /* Attempt to output a meaningful error/warning message: the message\n          * output depends on the background/composite operation being performed\n          * because this changes what parameters were actually used above.\n          */\n         {\n            size_t pos = 0;\n            /* Need either 1/255 or 1/65535 precision here; 3 or 6 decimal\n             * places.  Just use outmax to work out which.\n             */\n            int precision = (outmax >= 1000 ? 6 : 3);\n            int use_input=1, use_background=0, do_compose=0;\n            char msg[256];\n\n            if (pass != 0)\n               pos = safecat(msg, sizeof msg, pos, \"\\n\\t\");\n\n            /* Set up the various flags, the output_is_encoded flag above\n             * is also used below.  do_compose is just a double check.\n             */\n            switch (do_background)\n            {\n#           ifdef PNG_READ_BACKGROUND_SUPPORTED\n               case PNG_BACKGROUND_GAMMA_SCREEN:\n               case PNG_BACKGROUND_GAMMA_FILE:\n               case PNG_BACKGROUND_GAMMA_UNIQUE:\n                  use_background = (alpha >= 0 && alpha < 1);\n                  /*FALL THROUGH*/\n#           endif\n#           ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n               case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:\n               case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:\n               case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:\n#           endif /* ALPHA_MODE_SUPPORTED */\n               do_compose = (alpha > 0 && alpha < 1);\n               use_input = (alpha != 0);\n               break;\n\n            default:\n               break;\n            }\n\n            /* Check the 'compose' flag */\n            if (compose != do_compose)\n               png_error(vi->pp, \"internal error (compose)\");\n\n            /* 'name' is the component name */\n            pos = safecat(msg, sizeof msg, pos, name);\n            pos = safecat(msg, sizeof msg, pos, \"(\");\n            pos = safecatn(msg, sizeof msg, pos, id);\n            if (use_input || pass != 0/*logging*/)\n            {\n               if (isbit != id)\n               {\n                  /* sBIT has reduced the precision of the input: */\n                  pos = safecat(msg, sizeof msg, pos, \", sbit(\");\n                  pos = safecatn(msg, sizeof msg, pos, vi->sbit);\n                  pos = safecat(msg, sizeof msg, pos, \"): \");\n                  pos = safecatn(msg, sizeof msg, pos, isbit);\n               }\n               pos = safecat(msg, sizeof msg, pos, \"/\");\n               /* The output is either \"id/max\" or \"id sbit(sbit): isbit/max\" */\n               pos = safecatn(msg, sizeof msg, pos, vi->sbit_max);\n            }\n            pos = safecat(msg, sizeof msg, pos, \")\");\n\n            /* A component may have been multiplied (in linear space) by the\n             * alpha value, 'compose' says whether this is relevant.\n             */\n            if (compose || pass != 0)\n            {\n               /* If any form of composition is being done report our\n                * calculated linear value here (the code above doesn't record\n                * the input value before composition is performed, so what\n                * gets reported is the value after composition.)\n                */\n               if (use_input || pass != 0)\n               {\n                  if (vi->file_inverse > 0)\n                  {\n                     pos = safecat(msg, sizeof msg, pos, \"^\");\n                     pos = safecatd(msg, sizeof msg, pos, vi->file_inverse, 2);\n                  }\n\n                  else\n                     pos = safecat(msg, sizeof msg, pos, \"[linear]\");\n\n                  pos = safecat(msg, sizeof msg, pos, \"*(alpha)\");\n                  pos = safecatd(msg, sizeof msg, pos, alpha, precision);\n               }\n\n               /* Now record the *linear* background value if it was used\n                * (this function is not passed the original, non-linear,\n                * value but it is contained in the test name.)\n                */\n               if (use_background)\n               {\n                  pos = safecat(msg, sizeof msg, pos, use_input ? \"+\" : \" \");\n                  pos = safecat(msg, sizeof msg, pos, \"(background)\");\n                  pos = safecatd(msg, sizeof msg, pos, background, precision);\n                  pos = safecat(msg, sizeof msg, pos, \"*\");\n                  pos = safecatd(msg, sizeof msg, pos, 1-alpha, precision);\n               }\n            }\n\n            /* Report the calculated value (input_sample) and the linearized\n             * libpng value (output) unless this is just a component gamma\n             * correction.\n             */\n            if (compose || alpha < 0 || pass != 0)\n            {\n               pos = safecat(msg, sizeof msg, pos,\n                  pass != 0 ? \" =\\n\\t\" : \" = \");\n               pos = safecatd(msg, sizeof msg, pos, input_sample, precision);\n               pos = safecat(msg, sizeof msg, pos, \" (libpng: \");\n               pos = safecatd(msg, sizeof msg, pos, output, precision);\n               pos = safecat(msg, sizeof msg, pos, \")\");\n\n               /* Finally report the output gamma encoding, if any. */\n               if (output_is_encoded)\n               {\n                  pos = safecat(msg, sizeof msg, pos, \" ^\");\n                  pos = safecatd(msg, sizeof msg, pos, vi->screen_inverse, 2);\n                  pos = safecat(msg, sizeof msg, pos, \"(to screen) =\");\n               }\n\n               else\n                  pos = safecat(msg, sizeof msg, pos, \" [screen is linear] =\");\n            }\n\n            if ((!compose && alpha >= 0) || pass != 0)\n            {\n               if (pass != 0) /* logging */\n                  pos = safecat(msg, sizeof msg, pos, \"\\n\\t[overall:\");\n\n               /* This is the non-composition case, the internal linear\n                * values are irrelevant (though the log below will reveal\n                * them.)  Output a much shorter warning/error message and report\n                * the overall gamma correction.\n                */\n               if (vi->gamma_correction > 0)\n               {\n                  pos = safecat(msg, sizeof msg, pos, \" ^\");\n                  pos = safecatd(msg, sizeof msg, pos, vi->gamma_correction, 2);\n                  pos = safecat(msg, sizeof msg, pos, \"(gamma correction) =\");\n               }\n\n               else\n                  pos = safecat(msg, sizeof msg, pos,\n                     \" [no gamma correction] =\");\n\n               if (pass != 0)\n                  pos = safecat(msg, sizeof msg, pos, \"]\");\n            }\n\n            /* This is our calculated encoded_sample which should (but does\n             * not) match od:\n             */\n            pos = safecat(msg, sizeof msg, pos, pass != 0 ? \"\\n\\t\" : \" \");\n            pos = safecatd(msg, sizeof msg, pos, is_lo, 1);\n            pos = safecat(msg, sizeof msg, pos, \" < \");\n            pos = safecatd(msg, sizeof msg, pos, encoded_sample, 1);\n            pos = safecat(msg, sizeof msg, pos, \" (libpng: \");\n            pos = safecatn(msg, sizeof msg, pos, od);\n            pos = safecat(msg, sizeof msg, pos, \")\");\n            pos = safecat(msg, sizeof msg, pos, \"/\");\n            pos = safecatn(msg, sizeof msg, pos, outmax);\n            pos = safecat(msg, sizeof msg, pos, \" < \");\n            pos = safecatd(msg, sizeof msg, pos, is_hi, 1);\n\n            if (pass == 0) /* The error condition */\n            {\n#              ifdef PNG_WARNINGS_SUPPORTED\n                  png_warning(vi->pp, msg);\n#              else\n                  store_warning(vi->pp, msg);\n#              endif\n            }\n\n            else /* logging this value */\n               store_verbose(&vi->dp->pm->this, vi->pp, pass, msg);\n         }\n      }\n   }\n\n   return i;\n}\n\nstatic void\ngamma_image_validate(gamma_display *dp, png_const_structp pp,\n   png_infop pi)\n{\n   /* Get some constants derived from the input and output file formats: */\n   const png_store* const ps = dp->this.ps;\n   const png_byte in_ct = dp->this.colour_type;\n   const png_byte in_bd = dp->this.bit_depth;\n   const png_uint_32 w = dp->this.w;\n   const png_uint_32 h = dp->this.h;\n   const size_t cbRow = dp->this.cbRow;\n   const png_byte out_ct = png_get_color_type(pp, pi);\n   const png_byte out_bd = png_get_bit_depth(pp, pi);\n\n   /* There are three sources of error, firstly the quantization in the\n    * file encoding, determined by sbit and/or the file depth, secondly\n    * the output (screen) gamma and thirdly the output file encoding.\n    *\n    * Since this API receives the screen and file gamma in double\n    * precision it is possible to calculate an exact answer given an input\n    * pixel value.  Therefore we assume that the *input* value is exact -\n    * sample/maxsample - calculate the corresponding gamma corrected\n    * output to the limits of double precision arithmetic and compare with\n    * what libpng returns.\n    *\n    * Since the library must quantize the output to 8 or 16 bits there is\n    * a fundamental limit on the accuracy of the output of +/-.5 - this\n    * quantization limit is included in addition to the other limits\n    * specified by the paramaters to the API.  (Effectively, add .5\n    * everywhere.)\n    *\n    * The behavior of the 'sbit' paramter is defined by section 12.5\n    * (sample depth scaling) of the PNG spec.  That section forces the\n    * decoder to assume that the PNG values have been scaled if sBIT is\n    * present:\n    *\n    *     png-sample = floor( input-sample * (max-out/max-in) + .5);\n    *\n    * This means that only a subset of the possible PNG values should\n    * appear in the input. However, the spec allows the encoder to use a\n    * variety of approximations to the above and doesn't require any\n    * restriction of the values produced.\n    *\n    * Nevertheless the spec requires that the upper 'sBIT' bits of the\n    * value stored in a PNG file be the original sample bits.\n    * Consequently the code below simply scales the top sbit bits by\n    * (1<<sbit)-1 to obtain an original sample value.\n    *\n    * Because there is limited precision in the input it is arguable that\n    * an acceptable result is any valid result from input-.5 to input+.5.\n    * The basic tests below do not do this, however if 'use_input_precision'\n    * is set a subsequent test is performed above.\n    */\n   const unsigned int samples_per_pixel = (out_ct & 2U) ? 3U : 1U;\n   int processing;\n   png_uint_32 y;\n   const store_palette_entry *in_palette = dp->this.palette;\n   const int in_is_transparent = dp->this.is_transparent;\n   int process_tRNS;\n   int out_npalette = -1;\n   int out_is_transparent = 0; /* Just refers to the palette case */\n   store_palette out_palette;\n   validate_info vi;\n\n   /* Check for row overwrite errors */\n   store_image_check(dp->this.ps, pp, 0);\n\n   /* Supply the input and output sample depths here - 8 for an indexed image,\n    * otherwise the bit depth.\n    */\n   init_validate_info(&vi, dp, pp, in_ct==3?8:in_bd, out_ct==3?8:out_bd);\n\n   processing = (vi.gamma_correction > 0 && !dp->threshold_test)\n      || in_bd != out_bd || in_ct != out_ct || vi.do_background;\n   process_tRNS = dp->this.has_tRNS && vi.do_background;\n\n   /* TODO: FIX THIS: MAJOR BUG!  If the transformations all happen inside\n    * the palette there is no way of finding out, because libpng fails to\n    * update the palette on png_read_update_info.  Indeed, libpng doesn't\n    * even do the required work until much later, when it doesn't have any\n    * info pointer.  Oops.  For the moment 'processing' is turned off if\n    * out_ct is palette.\n    */\n   if (in_ct == 3 && out_ct == 3)\n      processing = 0;\n\n   if (processing && out_ct == 3)\n      out_is_transparent = read_palette(out_palette, &out_npalette, pp, pi);\n\n   for (y=0; y<h; ++y)\n   {\n      png_const_bytep pRow = store_image_row(ps, pp, 0, y);\n      png_byte std[STANDARD_ROWMAX];\n\n      transform_row(pp, std, in_ct, in_bd, y);\n\n      if (processing)\n      {\n         unsigned int x;\n\n         for (x=0; x<w; ++x)\n         {\n            double alpha = 1; /* serves as a flag value */\n\n            /* Record the palette index for index images. */\n            const unsigned int in_index =\n               in_ct == 3 ? sample(std, 3, in_bd, x, 0, 0, 0) : 256;\n            const unsigned int out_index =\n               out_ct == 3 ? sample(std, 3, out_bd, x, 0, 0, 0) : 256;\n\n            /* Handle input alpha - png_set_background will cause the output\n             * alpha to disappear so there is nothing to check.\n             */\n            if ((in_ct & PNG_COLOR_MASK_ALPHA) != 0 ||\n                (in_ct == 3 && in_is_transparent))\n            {\n               const unsigned int input_alpha = in_ct == 3 ?\n                  dp->this.palette[in_index].alpha :\n                  sample(std, in_ct, in_bd, x, samples_per_pixel, 0, 0);\n\n               unsigned int output_alpha = 65536 /* as a flag value */;\n\n               if (out_ct == 3)\n               {\n                  if (out_is_transparent)\n                     output_alpha = out_palette[out_index].alpha;\n               }\n\n               else if ((out_ct & PNG_COLOR_MASK_ALPHA) != 0)\n                  output_alpha = sample(pRow, out_ct, out_bd, x,\n                     samples_per_pixel, 0, 0);\n\n               if (output_alpha != 65536)\n                  alpha = gamma_component_validate(\"alpha\", &vi, input_alpha,\n                     output_alpha, -1/*alpha*/, 0/*background*/);\n\n               else /* no alpha in output */\n               {\n                  /* This is a copy of the calculation of 'i' above in order to\n                   * have the alpha value to use in the background calculation.\n                   */\n                  alpha = input_alpha >> vi.isbit_shift;\n                  alpha /= vi.sbit_max;\n               }\n            }\n\n            else if (process_tRNS)\n            {\n               /* alpha needs to be set appropriately for this pixel, it is\n                * currently 1 and needs to be 0 for an input pixel which matches\n                * the values in tRNS.\n                */\n               switch (in_ct)\n               {\n                  case 0: /* gray */\n                     if (sample(std, in_ct, in_bd, x, 0, 0, 0) ==\n                           dp->this.transparent.red)\n                        alpha = 0;\n                     break;\n\n                  case 2: /* RGB */\n                     if (sample(std, in_ct, in_bd, x, 0, 0, 0) ==\n                           dp->this.transparent.red &&\n                         sample(std, in_ct, in_bd, x, 1, 0, 0) ==\n                           dp->this.transparent.green &&\n                         sample(std, in_ct, in_bd, x, 2, 0, 0) ==\n                           dp->this.transparent.blue)\n                        alpha = 0;\n                     break;\n\n                  default:\n                     break;\n               }\n            }\n\n            /* Handle grayscale or RGB components. */\n            if ((in_ct & PNG_COLOR_MASK_COLOR) == 0) /* grayscale */\n               (void)gamma_component_validate(\"gray\", &vi,\n                  sample(std, in_ct, in_bd, x, 0, 0, 0),\n                  sample(pRow, out_ct, out_bd, x, 0, 0, 0),\n                  alpha/*component*/, vi.background_red);\n            else /* RGB or palette */\n            {\n               (void)gamma_component_validate(\"red\", &vi,\n                  in_ct == 3 ? in_palette[in_index].red :\n                     sample(std, in_ct, in_bd, x, 0, 0, 0),\n                  out_ct == 3 ? out_palette[out_index].red :\n                     sample(pRow, out_ct, out_bd, x, 0, 0, 0),\n                  alpha/*component*/, vi.background_red);\n\n               (void)gamma_component_validate(\"green\", &vi,\n                  in_ct == 3 ? in_palette[in_index].green :\n                     sample(std, in_ct, in_bd, x, 1, 0, 0),\n                  out_ct == 3 ? out_palette[out_index].green :\n                     sample(pRow, out_ct, out_bd, x, 1, 0, 0),\n                  alpha/*component*/, vi.background_green);\n\n               (void)gamma_component_validate(\"blue\", &vi,\n                  in_ct == 3 ? in_palette[in_index].blue :\n                     sample(std, in_ct, in_bd, x, 2, 0, 0),\n                  out_ct == 3 ? out_palette[out_index].blue :\n                     sample(pRow, out_ct, out_bd, x, 2, 0, 0),\n                  alpha/*component*/, vi.background_blue);\n            }\n         }\n      }\n\n      else if (memcmp(std, pRow, cbRow) != 0)\n      {\n         char msg[64];\n\n         /* No transform is expected on the threshold tests. */\n         sprintf(msg, \"gamma: below threshold row %lu changed\",\n            (unsigned long)y);\n\n         png_error(pp, msg);\n      }\n   } /* row (y) loop */\n\n   dp->this.ps->validated = 1;\n}\n\nstatic void PNGCBAPI\ngamma_end(png_structp ppIn, png_infop pi)\n{\n   png_const_structp pp = ppIn;\n   gamma_display *dp = voidcast(gamma_display*, png_get_progressive_ptr(pp));\n\n   if (!dp->this.speed)\n      gamma_image_validate(dp, pp, pi);\n   else\n      dp->this.ps->validated = 1;\n}\n\n/* A single test run checking a gamma transformation.\n *\n * maxabs: maximum absolute error as a fraction\n * maxout: maximum output error in the output units\n * maxpc:  maximum percentage error (as a percentage)\n */\nstatic void\ngamma_test(png_modifier *pmIn, const png_byte colour_typeIn,\n    const png_byte bit_depthIn, const int palette_numberIn,\n    const int interlace_typeIn,\n    const double file_gammaIn, const double screen_gammaIn,\n    const png_byte sbitIn, const int threshold_testIn,\n    const char *name,\n    const int use_input_precisionIn, const int scale16In,\n    const int expand16In, const int do_backgroundIn,\n    const png_color_16 *bkgd_colorIn, double bkgd_gammaIn)\n{\n   gamma_display d;\n   context(&pmIn->this, fault);\n\n   gamma_display_init(&d, pmIn, FILEID(colour_typeIn, bit_depthIn,\n      palette_numberIn, interlace_typeIn, 0, 0, 0),\n      file_gammaIn, screen_gammaIn, sbitIn,\n      threshold_testIn, use_input_precisionIn, scale16In,\n      expand16In, do_backgroundIn, bkgd_colorIn, bkgd_gammaIn);\n\n   Try\n   {\n      png_structp pp;\n      png_infop pi;\n      gama_modification gama_mod;\n      srgb_modification srgb_mod;\n      sbit_modification sbit_mod;\n\n      /* For the moment don't use the png_modifier support here. */\n      d.pm->encoding_counter = 0;\n      modifier_set_encoding(d.pm); /* Just resets everything */\n      d.pm->current_gamma = d.file_gamma;\n\n      /* Make an appropriate modifier to set the PNG file gamma to the\n       * given gamma value and the sBIT chunk to the given precision.\n       */\n      d.pm->modifications = NULL;\n      gama_modification_init(&gama_mod, d.pm, d.file_gamma);\n      srgb_modification_init(&srgb_mod, d.pm, 127 /*delete*/);\n      if (d.sbit > 0)\n         sbit_modification_init(&sbit_mod, d.pm, d.sbit);\n\n      modification_reset(d.pm->modifications);\n\n      /* Get a png_struct for reading the image. */\n      pp = set_modifier_for_read(d.pm, &pi, d.this.id, name);\n      standard_palette_init(&d.this);\n\n      /* Introduce the correct read function. */\n      if (d.pm->this.progressive)\n      {\n         /* Share the row function with the standard implementation. */\n         png_set_progressive_read_fn(pp, &d, gamma_info, progressive_row,\n            gamma_end);\n\n         /* Now feed data into the reader until we reach the end: */\n         modifier_progressive_read(d.pm, pp, pi);\n      }\n      else\n      {\n         /* modifier_read expects a png_modifier* */\n         png_set_read_fn(pp, d.pm, modifier_read);\n\n         /* Check the header values: */\n         png_read_info(pp, pi);\n\n         /* Process the 'info' requirements. Only one image is generated */\n         gamma_info_imp(&d, pp, pi);\n\n         sequential_row(&d.this, pp, pi, -1, 0);\n\n         if (!d.this.speed)\n            gamma_image_validate(&d, pp, pi);\n         else\n            d.this.ps->validated = 1;\n      }\n\n      modifier_reset(d.pm);\n\n      if (d.pm->log && !d.threshold_test && !d.this.speed)\n         fprintf(stderr, \"%d bit %s %s: max error %f (%.2g, %2g%%)\\n\",\n            d.this.bit_depth, colour_types[d.this.colour_type], name,\n            d.maxerrout, d.maxerrabs, 100*d.maxerrpc);\n\n      /* Log the summary values too. */\n      if (d.this.colour_type == 0 || d.this.colour_type == 4)\n      {\n         switch (d.this.bit_depth)\n         {\n         case 1:\n            break;\n\n         case 2:\n            if (d.maxerrout > d.pm->error_gray_2)\n               d.pm->error_gray_2 = d.maxerrout;\n\n            break;\n\n         case 4:\n            if (d.maxerrout > d.pm->error_gray_4)\n               d.pm->error_gray_4 = d.maxerrout;\n\n            break;\n\n         case 8:\n            if (d.maxerrout > d.pm->error_gray_8)\n               d.pm->error_gray_8 = d.maxerrout;\n\n            break;\n\n         case 16:\n            if (d.maxerrout > d.pm->error_gray_16)\n               d.pm->error_gray_16 = d.maxerrout;\n\n            break;\n\n         default:\n            png_error(pp, \"bad bit depth (internal: 1)\");\n         }\n      }\n\n      else if (d.this.colour_type == 2 || d.this.colour_type == 6)\n      {\n         switch (d.this.bit_depth)\n         {\n         case 8:\n\n            if (d.maxerrout > d.pm->error_color_8)\n               d.pm->error_color_8 = d.maxerrout;\n\n            break;\n\n         case 16:\n\n            if (d.maxerrout > d.pm->error_color_16)\n               d.pm->error_color_16 = d.maxerrout;\n\n            break;\n\n         default:\n            png_error(pp, \"bad bit depth (internal: 2)\");\n         }\n      }\n\n      else if (d.this.colour_type == 3)\n      {\n         if (d.maxerrout > d.pm->error_indexed)\n            d.pm->error_indexed = d.maxerrout;\n      }\n   }\n\n   Catch(fault)\n      modifier_reset(voidcast(png_modifier*,(void*)fault));\n}\n\nstatic void gamma_threshold_test(png_modifier *pm, png_byte colour_type,\n    png_byte bit_depth, int interlace_type, double file_gamma,\n    double screen_gamma)\n{\n   size_t pos = 0;\n   char name[64];\n   pos = safecat(name, sizeof name, pos, \"threshold \");\n   pos = safecatd(name, sizeof name, pos, file_gamma, 3);\n   pos = safecat(name, sizeof name, pos, \"/\");\n   pos = safecatd(name, sizeof name, pos, screen_gamma, 3);\n\n   (void)gamma_test(pm, colour_type, bit_depth, 0/*palette*/, interlace_type,\n      file_gamma, screen_gamma, 0/*sBIT*/, 1/*threshold test*/, name,\n      0 /*no input precision*/,\n      0 /*no scale16*/, 0 /*no expand16*/, 0 /*no background*/, 0 /*hence*/,\n      0 /*no background gamma*/);\n}\n\nstatic void\nperform_gamma_threshold_tests(png_modifier *pm)\n{\n   png_byte colour_type = 0;\n   png_byte bit_depth = 0;\n   unsigned int palette_number = 0;\n\n   /* Don't test more than one instance of each palette - it's pointless, in\n    * fact this test is somewhat excessive since libpng doesn't make this\n    * decision based on colour type or bit depth!\n    *\n    * CHANGED: now test two palettes and, as a side effect, images with and\n    * without tRNS.\n    */\n   while (next_format(&colour_type, &bit_depth, &palette_number,\n                      pm->test_lbg_gamma_threshold, pm->test_tRNS))\n      if (palette_number < 2)\n   {\n      double test_gamma = 1.0;\n      while (test_gamma >= .4)\n      {\n         /* There's little point testing the interlacing vs non-interlacing,\n          * but this can be set from the command line.\n          */\n         gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,\n            test_gamma, 1/test_gamma);\n         test_gamma *= .95;\n      }\n\n      /* And a special test for sRGB */\n      gamma_threshold_test(pm, colour_type, bit_depth, pm->interlace_type,\n          .45455, 2.2);\n\n      if (fail(pm))\n         return;\n   }\n}\n\nstatic void gamma_transform_test(png_modifier *pm,\n   const png_byte colour_type, const png_byte bit_depth,\n   const int palette_number,\n   const int interlace_type, const double file_gamma,\n   const double screen_gamma, const png_byte sbit,\n   const int use_input_precision, const int scale16)\n{\n   size_t pos = 0;\n   char name[64];\n\n   if (sbit != bit_depth && sbit != 0)\n   {\n      pos = safecat(name, sizeof name, pos, \"sbit(\");\n      pos = safecatn(name, sizeof name, pos, sbit);\n      pos = safecat(name, sizeof name, pos, \") \");\n   }\n\n   else\n      pos = safecat(name, sizeof name, pos, \"gamma \");\n\n   if (scale16)\n      pos = safecat(name, sizeof name, pos, \"16to8 \");\n\n   pos = safecatd(name, sizeof name, pos, file_gamma, 3);\n   pos = safecat(name, sizeof name, pos, \"->\");\n   pos = safecatd(name, sizeof name, pos, screen_gamma, 3);\n\n   gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,\n      file_gamma, screen_gamma, sbit, 0, name, use_input_precision,\n      scale16, pm->test_gamma_expand16, 0 , 0, 0);\n}\n\nstatic void perform_gamma_transform_tests(png_modifier *pm)\n{\n   png_byte colour_type = 0;\n   png_byte bit_depth = 0;\n   unsigned int palette_number = 0;\n\n   while (next_format(&colour_type, &bit_depth, &palette_number,\n                      pm->test_lbg_gamma_transform, pm->test_tRNS))\n   {\n      unsigned int i, j;\n\n      for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)\n         if (i != j)\n         {\n            gamma_transform_test(pm, colour_type, bit_depth, palette_number,\n               pm->interlace_type, 1/pm->gammas[i], pm->gammas[j], 0/*sBIT*/,\n               pm->use_input_precision, 0 /*do not scale16*/);\n\n            if (fail(pm))\n               return;\n         }\n   }\n}\n\nstatic void perform_gamma_sbit_tests(png_modifier *pm)\n{\n   png_byte sbit;\n\n   /* The only interesting cases are colour and grayscale, alpha is ignored here\n    * for overall speed.  Only bit depths where sbit is less than the bit depth\n    * are tested.\n    */\n   for (sbit=pm->sbitlow; sbit<(1<<READ_BDHI); ++sbit)\n   {\n      png_byte colour_type = 0, bit_depth = 0;\n      unsigned int npalette = 0;\n\n      while (next_format(&colour_type, &bit_depth, &npalette,\n                         pm->test_lbg_gamma_sbit, pm->test_tRNS))\n         if ((colour_type & PNG_COLOR_MASK_ALPHA) == 0 &&\n            ((colour_type == 3 && sbit < 8) ||\n            (colour_type != 3 && sbit < bit_depth)))\n      {\n         unsigned int i;\n\n         for (i=0; i<pm->ngamma_tests; ++i)\n         {\n            unsigned int j;\n\n            for (j=0; j<pm->ngamma_tests; ++j) if (i != j)\n            {\n               gamma_transform_test(pm, colour_type, bit_depth, npalette,\n                  pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],\n                  sbit, pm->use_input_precision_sbit, 0 /*scale16*/);\n\n               if (fail(pm))\n                  return;\n            }\n         }\n      }\n   }\n}\n\n/* Note that this requires a 16 bit source image but produces 8 bit output, so\n * we only need the 16bit write support, but the 16 bit images are only\n * generated if DO_16BIT is defined.\n */\n#ifdef DO_16BIT\nstatic void perform_gamma_scale16_tests(png_modifier *pm)\n{\n#  ifndef PNG_MAX_GAMMA_8\n#     define PNG_MAX_GAMMA_8 11\n#  endif\n#  if defined PNG_MAX_GAMMA_8 || PNG_LIBPNG_VER < 10700\n#     define SBIT_16_TO_8 PNG_MAX_GAMMA_8\n#  else\n#     define SBIT_16_TO_8 16\n#  endif\n   /* Include the alpha cases here. Note that sbit matches the internal value\n    * used by the library - otherwise we will get spurious errors from the\n    * internal sbit style approximation.\n    *\n    * The threshold test is here because otherwise the 16 to 8 conversion will\n    * proceed *without* gamma correction, and the tests above will fail (but not\n    * by much) - this could be fixed, it only appears with the -g option.\n    */\n   unsigned int i, j;\n   for (i=0; i<pm->ngamma_tests; ++i)\n   {\n      for (j=0; j<pm->ngamma_tests; ++j)\n      {\n         if (i != j &&\n             fabs(pm->gammas[j]/pm->gammas[i]-1) >= PNG_GAMMA_THRESHOLD)\n         {\n            gamma_transform_test(pm, 0, 16, 0, pm->interlace_type,\n               1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,\n               pm->use_input_precision_16to8, 1 /*scale16*/);\n\n            if (fail(pm))\n               return;\n\n            gamma_transform_test(pm, 2, 16, 0, pm->interlace_type,\n               1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,\n               pm->use_input_precision_16to8, 1 /*scale16*/);\n\n            if (fail(pm))\n               return;\n\n            gamma_transform_test(pm, 4, 16, 0, pm->interlace_type,\n               1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,\n               pm->use_input_precision_16to8, 1 /*scale16*/);\n\n            if (fail(pm))\n               return;\n\n            gamma_transform_test(pm, 6, 16, 0, pm->interlace_type,\n               1/pm->gammas[i], pm->gammas[j], SBIT_16_TO_8,\n               pm->use_input_precision_16to8, 1 /*scale16*/);\n\n            if (fail(pm))\n               return;\n         }\n      }\n   }\n}\n#endif /* 16 to 8 bit conversion */\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\nstatic void gamma_composition_test(png_modifier *pm,\n   const png_byte colour_type, const png_byte bit_depth,\n   const int palette_number,\n   const int interlace_type, const double file_gamma,\n   const double screen_gamma,\n   const int use_input_precision, const int do_background,\n   const int expand_16)\n{\n   size_t pos = 0;\n   png_const_charp base;\n   double bg;\n   char name[128];\n   png_color_16 background;\n\n   /* Make up a name and get an appropriate background gamma value. */\n   switch (do_background)\n   {\n      default:\n         base = \"\";\n         bg = 4; /* should not be used */\n         break;\n      case PNG_BACKGROUND_GAMMA_SCREEN:\n         base = \" bckg(Screen):\";\n         bg = 1/screen_gamma;\n         break;\n      case PNG_BACKGROUND_GAMMA_FILE:\n         base = \" bckg(File):\";\n         bg = file_gamma;\n         break;\n      case PNG_BACKGROUND_GAMMA_UNIQUE:\n         base = \" bckg(Unique):\";\n         /* This tests the handling of a unique value, the math is such that the\n          * value tends to be <1, but is neither screen nor file (even if they\n          * match!)\n          */\n         bg = (file_gamma + screen_gamma) / 3;\n         break;\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_PNG:\n         base = \" alpha(PNG)\";\n         bg = 4; /* should not be used */\n         break;\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD:\n         base = \" alpha(Porter-Duff)\";\n         bg = 4; /* should not be used */\n         break;\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_OPTIMIZED:\n         base = \" alpha(Optimized)\";\n         bg = 4; /* should not be used */\n         break;\n      case ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN:\n         base = \" alpha(Broken)\";\n         bg = 4; /* should not be used */\n         break;\n#endif\n   }\n\n   /* Use random background values - the background is always presented in the\n    * output space (8 or 16 bit components).\n    */\n   if (expand_16 || bit_depth == 16)\n   {\n      png_uint_32 r = random_32();\n\n      background.red = (png_uint_16)r;\n      background.green = (png_uint_16)(r >> 16);\n      r = random_32();\n      background.blue = (png_uint_16)r;\n      background.gray = (png_uint_16)(r >> 16);\n\n      /* In earlier libpng versions, those where DIGITIZE is set, any background\n       * gamma correction in the expand16 case was done using 8-bit gamma\n       * correction tables, resulting in larger errors.  To cope with those\n       * cases use a 16-bit background value which will handle this gamma\n       * correction.\n       */\n#     if DIGITIZE\n         if (expand_16 && (do_background == PNG_BACKGROUND_GAMMA_UNIQUE ||\n                           do_background == PNG_BACKGROUND_GAMMA_FILE) &&\n            fabs(bg*screen_gamma-1) > PNG_GAMMA_THRESHOLD)\n         {\n            /* The background values will be looked up in an 8-bit table to do\n             * the gamma correction, so only select values which are an exact\n             * match for the 8-bit table entries:\n             */\n            background.red = (png_uint_16)((background.red >> 8) * 257);\n            background.green = (png_uint_16)((background.green >> 8) * 257);\n            background.blue = (png_uint_16)((background.blue >> 8) * 257);\n            background.gray = (png_uint_16)((background.gray >> 8) * 257);\n         }\n#     endif\n   }\n\n   else /* 8 bit colors */\n   {\n      png_uint_32 r = random_32();\n\n      background.red = (png_byte)r;\n      background.green = (png_byte)(r >> 8);\n      background.blue = (png_byte)(r >> 16);\n      background.gray = (png_byte)(r >> 24);\n   }\n\n   background.index = 193; /* rgb(193,193,193) to detect errors */\n\n   if (!(colour_type & PNG_COLOR_MASK_COLOR))\n   {\n      /* Because, currently, png_set_background is always called with\n       * 'need_expand' false in this case and because the gamma test itself\n       * doesn't cause an expand to 8-bit for lower bit depths the colour must\n       * be reduced to the correct range.\n       */\n      if (bit_depth < 8)\n         background.gray &= (png_uint_16)((1U << bit_depth)-1);\n\n      /* Grayscale input, we do not convert to RGB (TBD), so we must set the\n       * background to gray - else libpng seems to fail.\n       */\n      background.red = background.green = background.blue = background.gray;\n   }\n\n   pos = safecat(name, sizeof name, pos, \"gamma \");\n   pos = safecatd(name, sizeof name, pos, file_gamma, 3);\n   pos = safecat(name, sizeof name, pos, \"->\");\n   pos = safecatd(name, sizeof name, pos, screen_gamma, 3);\n\n   pos = safecat(name, sizeof name, pos, base);\n   if (do_background < ALPHA_MODE_OFFSET)\n   {\n      /* Include the background color and gamma in the name: */\n      pos = safecat(name, sizeof name, pos, \"(\");\n      /* This assumes no expand gray->rgb - the current code won't handle that!\n       */\n      if (colour_type & PNG_COLOR_MASK_COLOR)\n      {\n         pos = safecatn(name, sizeof name, pos, background.red);\n         pos = safecat(name, sizeof name, pos, \",\");\n         pos = safecatn(name, sizeof name, pos, background.green);\n         pos = safecat(name, sizeof name, pos, \",\");\n         pos = safecatn(name, sizeof name, pos, background.blue);\n      }\n      else\n         pos = safecatn(name, sizeof name, pos, background.gray);\n      pos = safecat(name, sizeof name, pos, \")^\");\n      pos = safecatd(name, sizeof name, pos, bg, 3);\n   }\n\n   gamma_test(pm, colour_type, bit_depth, palette_number, interlace_type,\n      file_gamma, screen_gamma, 0/*sBIT*/, 0, name, use_input_precision,\n      0/*strip 16*/, expand_16, do_background, &background, bg);\n}\n\n\nstatic void\nperform_gamma_composition_tests(png_modifier *pm, int do_background,\n   int expand_16)\n{\n   png_byte colour_type = 0;\n   png_byte bit_depth = 0;\n   unsigned int palette_number = 0;\n\n   /* Skip the non-alpha cases - there is no setting of a transparency colour at\n    * present.\n    *\n    * TODO: incorrect; the palette case sets tRNS and, now RGB and gray do,\n    * however the palette case fails miserably so is commented out below.\n    */\n   while (next_format(&colour_type, &bit_depth, &palette_number,\n                      pm->test_lbg_gamma_composition, pm->test_tRNS))\n      if ((colour_type & PNG_COLOR_MASK_ALPHA) != 0\n#if 0 /* TODO: FIXME */\n          /*TODO: FIXME: this should work */\n          || colour_type == 3\n#endif\n          || (colour_type != 3 && palette_number != 0))\n   {\n      unsigned int i, j;\n\n      /* Don't skip the i==j case here - it's relevant. */\n      for (i=0; i<pm->ngamma_tests; ++i) for (j=0; j<pm->ngamma_tests; ++j)\n      {\n         gamma_composition_test(pm, colour_type, bit_depth, palette_number,\n            pm->interlace_type, 1/pm->gammas[i], pm->gammas[j],\n            pm->use_input_precision, do_background, expand_16);\n\n         if (fail(pm))\n            return;\n      }\n   }\n}\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE */\n\nstatic void\ninit_gamma_errors(png_modifier *pm)\n{\n   /* Use -1 to catch tests that were not actually run */\n   pm->error_gray_2 = pm->error_gray_4 = pm->error_gray_8 = -1.;\n   pm->error_color_8 = -1.;\n   pm->error_indexed = -1.;\n   pm->error_gray_16 = pm->error_color_16 = -1.;\n}\n\nstatic void\nprint_one(const char *leader, double err)\n{\n   if (err != -1.)\n      printf(\" %s %.5f\\n\", leader, err);\n}\n\nstatic void\nsummarize_gamma_errors(png_modifier *pm, png_const_charp who, int low_bit_depth,\n   int indexed)\n{\n   fflush(stderr);\n\n   if (who)\n      printf(\"\\nGamma correction with %s:\\n\", who);\n\n   else\n      printf(\"\\nBasic gamma correction:\\n\");\n\n   if (low_bit_depth)\n   {\n      print_one(\" 2 bit gray: \", pm->error_gray_2);\n      print_one(\" 4 bit gray: \", pm->error_gray_4);\n      print_one(\" 8 bit gray: \", pm->error_gray_8);\n      print_one(\" 8 bit color:\", pm->error_color_8);\n      if (indexed)\n         print_one(\" indexed:    \", pm->error_indexed);\n   }\n\n   print_one(\"16 bit gray: \", pm->error_gray_16);\n   print_one(\"16 bit color:\", pm->error_color_16);\n\n   fflush(stdout);\n}\n\nstatic void\nperform_gamma_test(png_modifier *pm, int summary)\n{\n   /*TODO: remove this*/\n   /* Save certain values for the temporary overrides below. */\n   unsigned int calculations_use_input_precision =\n      pm->calculations_use_input_precision;\n#  ifdef PNG_READ_BACKGROUND_SUPPORTED\n      double maxout8 = pm->maxout8;\n#  endif\n\n   /* First some arbitrary no-transform tests: */\n   if (!pm->this.speed && pm->test_gamma_threshold)\n   {\n      perform_gamma_threshold_tests(pm);\n\n      if (fail(pm))\n         return;\n   }\n\n   /* Now some real transforms. */\n   if (pm->test_gamma_transform)\n   {\n      if (summary)\n      {\n         fflush(stderr);\n         printf(\"Gamma correction error summary\\n\\n\");\n         printf(\"The printed value is the maximum error in the pixel values\\n\");\n         printf(\"calculated by the libpng gamma correction code.  The error\\n\");\n         printf(\"is calculated as the difference between the output pixel\\n\");\n         printf(\"value (always an integer) and the ideal value from the\\n\");\n         printf(\"libpng specification (typically not an integer).\\n\\n\");\n\n         printf(\"Expect this value to be less than .5 for 8 bit formats,\\n\");\n         printf(\"less than 1 for formats with fewer than 8 bits and a small\\n\");\n         printf(\"number (typically less than 5) for the 16 bit formats.\\n\");\n         printf(\"For performance reasons the value for 16 bit formats\\n\");\n         printf(\"increases when the image file includes an sBIT chunk.\\n\");\n         fflush(stdout);\n      }\n\n      init_gamma_errors(pm);\n      /*TODO: remove this.  Necessary because the current libpng\n       * implementation works in 8 bits:\n       */\n      if (pm->test_gamma_expand16)\n         pm->calculations_use_input_precision = 1;\n      perform_gamma_transform_tests(pm);\n      if (!calculations_use_input_precision)\n         pm->calculations_use_input_precision = 0;\n\n      if (summary)\n         summarize_gamma_errors(pm, 0/*who*/, 1/*low bit depth*/, 1/*indexed*/);\n\n      if (fail(pm))\n         return;\n   }\n\n   /* The sbit tests produce much larger errors: */\n   if (pm->test_gamma_sbit)\n   {\n      init_gamma_errors(pm);\n      perform_gamma_sbit_tests(pm);\n\n      if (summary)\n         summarize_gamma_errors(pm, \"sBIT\", pm->sbitlow < 8U, 1/*indexed*/);\n\n      if (fail(pm))\n         return;\n   }\n\n#ifdef DO_16BIT /* Should be READ_16BIT_SUPPORTED */\n   if (pm->test_gamma_scale16)\n   {\n      /* The 16 to 8 bit strip operations: */\n      init_gamma_errors(pm);\n      perform_gamma_scale16_tests(pm);\n\n      if (summary)\n      {\n         fflush(stderr);\n         printf(\"\\nGamma correction with 16 to 8 bit reduction:\\n\");\n         printf(\" 16 bit gray:  %.5f\\n\", pm->error_gray_16);\n         printf(\" 16 bit color: %.5f\\n\", pm->error_color_16);\n         fflush(stdout);\n      }\n\n      if (fail(pm))\n         return;\n   }\n#endif\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n   if (pm->test_gamma_background)\n   {\n      init_gamma_errors(pm);\n\n      /*TODO: remove this.  Necessary because the current libpng\n       * implementation works in 8 bits:\n       */\n      if (pm->test_gamma_expand16)\n      {\n         pm->calculations_use_input_precision = 1;\n         pm->maxout8 = .499; /* because the 16 bit background is smashed */\n      }\n      perform_gamma_composition_tests(pm, PNG_BACKGROUND_GAMMA_UNIQUE,\n         pm->test_gamma_expand16);\n      if (!calculations_use_input_precision)\n         pm->calculations_use_input_precision = 0;\n      pm->maxout8 = maxout8;\n\n      if (summary)\n         summarize_gamma_errors(pm, \"background\", 1, 0/*indexed*/);\n\n      if (fail(pm))\n         return;\n   }\n#endif\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n   if (pm->test_gamma_alpha_mode)\n   {\n      int do_background;\n\n      init_gamma_errors(pm);\n\n      /*TODO: remove this.  Necessary because the current libpng\n       * implementation works in 8 bits:\n       */\n      if (pm->test_gamma_expand16)\n         pm->calculations_use_input_precision = 1;\n      for (do_background = ALPHA_MODE_OFFSET + PNG_ALPHA_STANDARD;\n         do_background <= ALPHA_MODE_OFFSET + PNG_ALPHA_BROKEN && !fail(pm);\n         ++do_background)\n         perform_gamma_composition_tests(pm, do_background,\n            pm->test_gamma_expand16);\n      if (!calculations_use_input_precision)\n         pm->calculations_use_input_precision = 0;\n\n      if (summary)\n         summarize_gamma_errors(pm, \"alpha mode\", 1, 0/*indexed*/);\n\n      if (fail(pm))\n         return;\n   }\n#endif\n}\n#endif /* PNG_READ_GAMMA_SUPPORTED */\n#endif /* PNG_READ_SUPPORTED */\n\n/* INTERLACE MACRO VALIDATION */\n/* This is copied verbatim from the specification, it is simply the pass\n * number in which each pixel in each 8x8 tile appears.  The array must\n * be indexed adam7[y][x] and notice that the pass numbers are based at\n * 1, not 0 - the base libpng uses.\n */\nstatic const\npng_byte adam7[8][8] =\n{\n   { 1,6,4,6,2,6,4,6 },\n   { 7,7,7,7,7,7,7,7 },\n   { 5,6,5,6,5,6,5,6 },\n   { 7,7,7,7,7,7,7,7 },\n   { 3,6,4,6,3,6,4,6 },\n   { 7,7,7,7,7,7,7,7 },\n   { 5,6,5,6,5,6,5,6 },\n   { 7,7,7,7,7,7,7,7 }\n};\n\n/* This routine validates all the interlace support macros in png.h for\n * a variety of valid PNG widths and heights.  It uses a number of similarly\n * named internal routines that feed off the above array.\n */\nstatic png_uint_32\npng_pass_start_row(int pass)\n{\n   int x, y;\n   ++pass;\n   for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)\n      return y;\n   return 0xf;\n}\n\nstatic png_uint_32\npng_pass_start_col(int pass)\n{\n   int x, y;\n   ++pass;\n   for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)\n      return x;\n   return 0xf;\n}\n\nstatic int\npng_pass_row_shift(int pass)\n{\n   int x, y, base=(-1), inc=8;\n   ++pass;\n   for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)\n   {\n      if (base == (-1))\n         base = y;\n      else if (base == y)\n         {}\n      else if (inc == y-base)\n         base=y;\n      else if (inc == 8)\n         inc = y-base, base=y;\n      else if (inc != y-base)\n         return 0xff; /* error - more than one 'inc' value! */\n   }\n\n   if (base == (-1)) return 0xfe; /* error - no row in pass! */\n\n   /* The shift is always 1, 2 or 3 - no pass has all the rows! */\n   switch (inc)\n   {\ncase 2: return 1;\ncase 4: return 2;\ncase 8: return 3;\ndefault: break;\n   }\n\n   /* error - unrecognized 'inc' */\n   return (inc << 8) + 0xfd;\n}\n\nstatic int\npng_pass_col_shift(int pass)\n{\n   int x, y, base=(-1), inc=8;\n   ++pass;\n   for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)\n   {\n      if (base == (-1))\n         base = x;\n      else if (base == x)\n         {}\n      else if (inc == x-base)\n         base=x;\n      else if (inc == 8)\n         inc = x-base, base=x;\n      else if (inc != x-base)\n         return 0xff; /* error - more than one 'inc' value! */\n   }\n\n   if (base == (-1)) return 0xfe; /* error - no row in pass! */\n\n   /* The shift is always 1, 2 or 3 - no pass has all the rows! */\n   switch (inc)\n   {\ncase 1: return 0; /* pass 7 has all the columns */\ncase 2: return 1;\ncase 4: return 2;\ncase 8: return 3;\ndefault: break;\n   }\n\n   /* error - unrecognized 'inc' */\n   return (inc << 8) + 0xfd;\n}\n\nstatic png_uint_32\npng_row_from_pass_row(png_uint_32 yIn, int pass)\n{\n   /* By examination of the array: */\n   switch (pass)\n   {\ncase 0: return yIn * 8;\ncase 1: return yIn * 8;\ncase 2: return yIn * 8 + 4;\ncase 3: return yIn * 4;\ncase 4: return yIn * 4 + 2;\ncase 5: return yIn * 2;\ncase 6: return yIn * 2 + 1;\ndefault: break;\n   }\n\n   return 0xff; /* bad pass number */\n}\n\nstatic png_uint_32\npng_col_from_pass_col(png_uint_32 xIn, int pass)\n{\n   /* By examination of the array: */\n   switch (pass)\n   {\ncase 0: return xIn * 8;\ncase 1: return xIn * 8 + 4;\ncase 2: return xIn * 4;\ncase 3: return xIn * 4 + 2;\ncase 4: return xIn * 2;\ncase 5: return xIn * 2 + 1;\ncase 6: return xIn;\ndefault: break;\n   }\n\n   return 0xff; /* bad pass number */\n}\n\nstatic int\npng_row_in_interlace_pass(png_uint_32 y, int pass)\n{\n   /* Is row 'y' in pass 'pass'? */\n   int x;\n   y &= 7;\n   ++pass;\n   for (x=0; x<8; ++x) if (adam7[y][x] == pass)\n      return 1;\n\n   return 0;\n}\n\nstatic int\npng_col_in_interlace_pass(png_uint_32 x, int pass)\n{\n   /* Is column 'x' in pass 'pass'? */\n   int y;\n   x &= 7;\n   ++pass;\n   for (y=0; y<8; ++y) if (adam7[y][x] == pass)\n      return 1;\n\n   return 0;\n}\n\nstatic png_uint_32\npng_pass_rows(png_uint_32 height, int pass)\n{\n   png_uint_32 tiles = height>>3;\n   png_uint_32 rows = 0;\n   unsigned int x, y;\n\n   height &= 7;\n   ++pass;\n   for (y=0; y<8; ++y) for (x=0; x<8; ++x) if (adam7[y][x] == pass)\n   {\n      rows += tiles;\n      if (y < height) ++rows;\n      break; /* i.e. break the 'x', column, loop. */\n   }\n\n   return rows;\n}\n\nstatic png_uint_32\npng_pass_cols(png_uint_32 width, int pass)\n{\n   png_uint_32 tiles = width>>3;\n   png_uint_32 cols = 0;\n   unsigned int x, y;\n\n   width &= 7;\n   ++pass;\n   for (x=0; x<8; ++x) for (y=0; y<8; ++y) if (adam7[y][x] == pass)\n   {\n      cols += tiles;\n      if (x < width) ++cols;\n      break; /* i.e. break the 'y', row, loop. */\n   }\n\n   return cols;\n}\n\nstatic void\nperform_interlace_macro_validation(void)\n{\n   /* The macros to validate, first those that depend only on pass:\n    *\n    * PNG_PASS_START_ROW(pass)\n    * PNG_PASS_START_COL(pass)\n    * PNG_PASS_ROW_SHIFT(pass)\n    * PNG_PASS_COL_SHIFT(pass)\n    */\n   int pass;\n\n   for (pass=0; pass<7; ++pass)\n   {\n      png_uint_32 m, f, v;\n\n      m = PNG_PASS_START_ROW(pass);\n      f = png_pass_start_row(pass);\n      if (m != f)\n      {\n         fprintf(stderr, \"PNG_PASS_START_ROW(%d) = %u != %x\\n\", pass, m, f);\n         exit(99);\n      }\n\n      m = PNG_PASS_START_COL(pass);\n      f = png_pass_start_col(pass);\n      if (m != f)\n      {\n         fprintf(stderr, \"PNG_PASS_START_COL(%d) = %u != %x\\n\", pass, m, f);\n         exit(99);\n      }\n\n      m = PNG_PASS_ROW_SHIFT(pass);\n      f = png_pass_row_shift(pass);\n      if (m != f)\n      {\n         fprintf(stderr, \"PNG_PASS_ROW_SHIFT(%d) = %u != %x\\n\", pass, m, f);\n         exit(99);\n      }\n\n      m = PNG_PASS_COL_SHIFT(pass);\n      f = png_pass_col_shift(pass);\n      if (m != f)\n      {\n         fprintf(stderr, \"PNG_PASS_COL_SHIFT(%d) = %u != %x\\n\", pass, m, f);\n         exit(99);\n      }\n\n      /* Macros that depend on the image or sub-image height too:\n       *\n       * PNG_PASS_ROWS(height, pass)\n       * PNG_PASS_COLS(width, pass)\n       * PNG_ROW_FROM_PASS_ROW(yIn, pass)\n       * PNG_COL_FROM_PASS_COL(xIn, pass)\n       * PNG_ROW_IN_INTERLACE_PASS(y, pass)\n       * PNG_COL_IN_INTERLACE_PASS(x, pass)\n       */\n      for (v=0;;)\n      {\n         /* First the base 0 stuff: */\n         m = PNG_ROW_FROM_PASS_ROW(v, pass);\n         f = png_row_from_pass_row(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_ROW_FROM_PASS_ROW(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         m = PNG_COL_FROM_PASS_COL(v, pass);\n         f = png_col_from_pass_col(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_COL_FROM_PASS_COL(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         m = PNG_ROW_IN_INTERLACE_PASS(v, pass);\n         f = png_row_in_interlace_pass(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_ROW_IN_INTERLACE_PASS(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         m = PNG_COL_IN_INTERLACE_PASS(v, pass);\n         f = png_col_in_interlace_pass(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_COL_IN_INTERLACE_PASS(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         /* Then the base 1 stuff: */\n         ++v;\n         m = PNG_PASS_ROWS(v, pass);\n         f = png_pass_rows(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_PASS_ROWS(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         m = PNG_PASS_COLS(v, pass);\n         f = png_pass_cols(v, pass);\n         if (m != f)\n         {\n            fprintf(stderr, \"PNG_PASS_COLS(%u, %d) = %u != %x\\n\",\n               v, pass, m, f);\n            exit(99);\n         }\n\n         /* Move to the next v - the stepping algorithm starts skipping\n          * values above 1024.\n          */\n         if (v > 1024)\n         {\n            if (v == PNG_UINT_31_MAX)\n               break;\n\n            v = (v << 1) ^ v;\n            if (v >= PNG_UINT_31_MAX)\n               v = PNG_UINT_31_MAX-1;\n         }\n      }\n   }\n}\n\n/* Test color encodings. These values are back-calculated from the published\n * chromaticities.  The values are accurate to about 14 decimal places; 15 are\n * given.  These values are much more accurate than the ones given in the spec,\n * which typically don't exceed 4 decimal places.  This allows testing of the\n * libpng code to its theoretical accuracy of 4 decimal places.  (If pngvalid\n * used the published errors the 'slack' permitted would have to be +/-.5E-4 or\n * more.)\n *\n * The png_modifier code assumes that encodings[0] is sRGB and treats it\n * specially: do not change the first entry in this list!\n */\nstatic const color_encoding test_encodings[] =\n{\n/* sRGB: must be first in this list! */\n/*gamma:*/ { 1/2.2,\n/*red:  */ { 0.412390799265959, 0.212639005871510, 0.019330818715592 },\n/*green:*/ { 0.357584339383878, 0.715168678767756, 0.119194779794626 },\n/*blue: */ { 0.180480788401834, 0.072192315360734, 0.950532152249660} },\n/* Kodak ProPhoto (wide gamut) */\n/*gamma:*/ { 1/1.6 /*approximate: uses 1.8 power law compared to sRGB 2.4*/,\n/*red:  */ { 0.797760489672303, 0.288071128229293, 0.000000000000000 },\n/*green:*/ { 0.135185837175740, 0.711843217810102, 0.000000000000000 },\n/*blue: */ { 0.031349349581525, 0.000085653960605, 0.825104602510460} },\n/* Adobe RGB (1998) */\n/*gamma:*/ { 1/(2+51./256),\n/*red:  */ { 0.576669042910131, 0.297344975250536, 0.027031361386412 },\n/*green:*/ { 0.185558237906546, 0.627363566255466, 0.070688852535827 },\n/*blue: */ { 0.188228646234995, 0.075291458493998, 0.991337536837639} },\n/* Adobe Wide Gamut RGB */\n/*gamma:*/ { 1/(2+51./256),\n/*red:  */ { 0.716500716779386, 0.258728243040113, 0.000000000000000 },\n/*green:*/ { 0.101020574397477, 0.724682314948566, 0.051211818965388 },\n/*blue: */ { 0.146774385252705, 0.016589442011321, 0.773892783545073} },\n/* Fake encoding which selects just the green channel */\n/*gamma:*/ { 1.45/2.2, /* the 'Mac' gamma */\n/*red:  */ { 0.716500716779386, 0.000000000000000, 0.000000000000000 },\n/*green:*/ { 0.101020574397477, 1.000000000000000, 0.051211818965388 },\n/*blue: */ { 0.146774385252705, 0.000000000000000, 0.773892783545073} },\n};\n\n/* signal handler\n *\n * This attempts to trap signals and escape without crashing.  It needs a\n * context pointer so that it can throw an exception (call longjmp) to recover\n * from the condition; this is handled by making the png_modifier used by 'main'\n * into a global variable.\n */\nstatic png_modifier pm;\n\nstatic void signal_handler(int signum)\n{\n\n   size_t pos = 0;\n   char msg[64];\n\n   pos = safecat(msg, sizeof msg, pos, \"caught signal: \");\n\n   switch (signum)\n   {\n      case SIGABRT:\n         pos = safecat(msg, sizeof msg, pos, \"abort\");\n         break;\n\n      case SIGFPE:\n         pos = safecat(msg, sizeof msg, pos, \"floating point exception\");\n         break;\n\n      case SIGILL:\n         pos = safecat(msg, sizeof msg, pos, \"illegal instruction\");\n         break;\n\n      case SIGINT:\n         pos = safecat(msg, sizeof msg, pos, \"interrupt\");\n         break;\n\n      case SIGSEGV:\n         pos = safecat(msg, sizeof msg, pos, \"invalid memory access\");\n         break;\n\n      case SIGTERM:\n         pos = safecat(msg, sizeof msg, pos, \"termination request\");\n         break;\n\n      default:\n         pos = safecat(msg, sizeof msg, pos, \"unknown \");\n         pos = safecatn(msg, sizeof msg, pos, signum);\n         break;\n   }\n\n   store_log(&pm.this, NULL/*png_structp*/, msg, 1/*error*/);\n\n   /* And finally throw an exception so we can keep going, unless this is\n    * SIGTERM in which case stop now.\n    */\n   if (signum != SIGTERM)\n   {\n      struct exception_context *the_exception_context =\n         &pm.this.exception_context;\n\n      Throw &pm.this;\n   }\n\n   else\n      exit(1);\n}\n\n/* main program */\nint main(int argc, char **argv)\n{\n   int summary = 1;  /* Print the error summary at the end */\n   int memstats = 0; /* Print memory statistics at the end */\n\n   /* Create the given output file on success: */\n   const char *touch = NULL;\n\n   /* This is an array of standard gamma values (believe it or not I've seen\n    * every one of these mentioned somewhere.)\n    *\n    * In the following list the most useful values are first!\n    */\n   static double\n      gammas[]={2.2, 1.0, 2.2/1.45, 1.8, 1.5, 2.4, 2.5, 2.62, 2.9};\n\n   /* This records the command and arguments: */\n   size_t cp = 0;\n   char command[1024];\n\n   anon_context(&pm.this);\n\n   gnu_volatile(summary)\n   gnu_volatile(memstats)\n   gnu_volatile(touch)\n\n   /* Add appropriate signal handlers, just the ANSI specified ones: */\n   signal(SIGABRT, signal_handler);\n   signal(SIGFPE, signal_handler);\n   signal(SIGILL, signal_handler);\n   signal(SIGINT, signal_handler);\n   signal(SIGSEGV, signal_handler);\n   signal(SIGTERM, signal_handler);\n\n#ifdef HAVE_FEENABLEEXCEPT\n   /* Only required to enable FP exceptions on platforms where they start off\n    * disabled; this is not necessary but if it is not done pngvalid will likely\n    * end up ignoring FP conditions that other platforms fault.\n    */\n   feenableexcept(FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);\n#endif\n\n   modifier_init(&pm);\n\n   /* Preallocate the image buffer, because we know how big it needs to be,\n    * note that, for testing purposes, it is deliberately mis-aligned by tag\n    * bytes either side.  All rows have an additional five bytes of padding for\n    * overwrite checking.\n    */\n   store_ensure_image(&pm.this, NULL, 2, TRANSFORM_ROWMAX, TRANSFORM_HEIGHTMAX);\n\n   /* Don't give argv[0], it's normally some horrible libtool string: */\n   cp = safecat(command, sizeof command, cp, \"pngvalid\");\n\n   /* Default to error on warning: */\n   pm.this.treat_warnings_as_errors = 1;\n\n   /* Default assume_16_bit_calculations appropriately; this tells the checking\n    * code that 16-bit arithmetic is used for 8-bit samples when it would make a\n    * difference.\n    */\n   pm.assume_16_bit_calculations = PNG_LIBPNG_VER >= 10700;\n\n   /* Currently 16 bit expansion happens at the end of the pipeline, so the\n    * calculations are done in the input bit depth not the output.\n    *\n    * TODO: fix this\n    */\n   pm.calculations_use_input_precision = 1U;\n\n   /* Store the test gammas */\n   pm.gammas = gammas;\n   pm.ngammas = ARRAY_SIZE(gammas);\n   pm.ngamma_tests = 0; /* default to off */\n\n   /* Low bit depth gray images don't do well in the gamma tests, until\n    * this is fixed turn them off for some gamma cases:\n    */\n#  ifdef PNG_WRITE_tRNS_SUPPORTED\n      pm.test_tRNS = 1;\n#  endif\n   pm.test_lbg = PNG_LIBPNG_VER >= 10600;\n   pm.test_lbg_gamma_threshold = 1;\n   pm.test_lbg_gamma_transform = PNG_LIBPNG_VER >= 10600;\n   pm.test_lbg_gamma_sbit = 1;\n   pm.test_lbg_gamma_composition = PNG_LIBPNG_VER >= 10700;\n\n   /* And the test encodings */\n   pm.encodings = test_encodings;\n   pm.nencodings = ARRAY_SIZE(test_encodings);\n\n#  if PNG_LIBPNG_VER < 10700\n      pm.sbitlow = 8U; /* because libpng doesn't do sBIT below 8! */\n#  else\n      pm.sbitlow = 1U;\n#  endif\n\n   /* The following allows results to pass if they correspond to anything in the\n    * transformed range [input-.5,input+.5]; this is is required because of the\n    * way libpng treates the 16_TO_8 flag when building the gamma tables in\n    * releases up to 1.6.0.\n    *\n    * TODO: review this\n    */\n   pm.use_input_precision_16to8 = 1U;\n   pm.use_input_precision_sbit = 1U; /* because libpng now rounds sBIT */\n\n   /* Some default values (set the behavior for 'make check' here).\n    * These values simply control the maximum error permitted in the gamma\n    * transformations.  The practial limits for human perception are described\n    * below (the setting for maxpc16), however for 8 bit encodings it isn't\n    * possible to meet the accepted capabilities of human vision - i.e. 8 bit\n    * images can never be good enough, regardless of encoding.\n    */\n   pm.maxout8 = .1;     /* Arithmetic error in *encoded* value */\n   pm.maxabs8 = .00005; /* 1/20000 */\n   pm.maxcalc8 = 1./255;  /* +/-1 in 8 bits for compose errors */\n   pm.maxpc8 = .499;    /* I.e., .499% fractional error */\n   pm.maxout16 = .499;  /* Error in *encoded* value */\n   pm.maxabs16 = .00005;/* 1/20000 */\n   pm.maxcalc16 =1./65535;/* +/-1 in 16 bits for compose errors */\n#  if PNG_LIBPNG_VER < 10700\n      pm.maxcalcG = 1./((1<<PNG_MAX_GAMMA_8)-1);\n#  else\n      pm.maxcalcG = 1./((1<<16)-1);\n#  endif\n\n   /* NOTE: this is a reasonable perceptual limit. We assume that humans can\n    * perceive light level differences of 1% over a 100:1 range, so we need to\n    * maintain 1 in 10000 accuracy (in linear light space), which is what the\n    * following guarantees.  It also allows significantly higher errors at\n    * higher 16 bit values, which is important for performance.  The actual\n    * maximum 16 bit error is about +/-1.9 in the fixed point implementation but\n    * this is only allowed for values >38149 by the following:\n    */\n   pm.maxpc16 = .005;   /* I.e., 1/200% - 1/20000 */\n\n   /* Now parse the command line options. */\n   while (--argc >= 1)\n   {\n      int catmore = 0; /* Set if the argument has an argument. */\n\n      /* Record each argument for posterity: */\n      cp = safecat(command, sizeof command, cp, \" \");\n      cp = safecat(command, sizeof command, cp, *++argv);\n\n      if (strcmp(*argv, \"-v\") == 0)\n         pm.this.verbose = 1;\n\n      else if (strcmp(*argv, \"-l\") == 0)\n         pm.log = 1;\n\n      else if (strcmp(*argv, \"-q\") == 0)\n         summary = pm.this.verbose = pm.log = 0;\n\n      else if (strcmp(*argv, \"-w\") == 0 ||\n               strcmp(*argv, \"--strict\") == 0)\n         pm.this.treat_warnings_as_errors = 1; /* NOTE: this is the default! */\n\n      else if (strcmp(*argv, \"--nostrict\") == 0)\n         pm.this.treat_warnings_as_errors = 0;\n\n      else if (strcmp(*argv, \"--speed\") == 0)\n         pm.this.speed = 1, pm.ngamma_tests = pm.ngammas, pm.test_standard = 0,\n            summary = 0;\n\n      else if (strcmp(*argv, \"--memory\") == 0)\n         memstats = 1;\n\n      else if (strcmp(*argv, \"--size\") == 0)\n         pm.test_size = 1;\n\n      else if (strcmp(*argv, \"--nosize\") == 0)\n         pm.test_size = 0;\n\n      else if (strcmp(*argv, \"--standard\") == 0)\n         pm.test_standard = 1;\n\n      else if (strcmp(*argv, \"--nostandard\") == 0)\n         pm.test_standard = 0;\n\n      else if (strcmp(*argv, \"--transform\") == 0)\n         pm.test_transform = 1;\n\n      else if (strcmp(*argv, \"--notransform\") == 0)\n         pm.test_transform = 0;\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n      else if (strncmp(*argv, \"--transform-disable=\",\n         sizeof \"--transform-disable\") == 0)\n         {\n         pm.test_transform = 1;\n         transform_disable(*argv + sizeof \"--transform-disable\");\n         }\n\n      else if (strncmp(*argv, \"--transform-enable=\",\n         sizeof \"--transform-enable\") == 0)\n         {\n         pm.test_transform = 1;\n         transform_enable(*argv + sizeof \"--transform-enable\");\n         }\n#endif /* PNG_READ_TRANSFORMS_SUPPORTED */\n\n      else if (strcmp(*argv, \"--gamma\") == 0)\n         {\n         /* Just do two gamma tests here (2.2 and linear) for speed: */\n         pm.ngamma_tests = 2U;\n         pm.test_gamma_threshold = 1;\n         pm.test_gamma_transform = 1;\n         pm.test_gamma_sbit = 1;\n         pm.test_gamma_scale16 = 1;\n         pm.test_gamma_background = 1; /* composition */\n         pm.test_gamma_alpha_mode = 1;\n         }\n\n      else if (strcmp(*argv, \"--nogamma\") == 0)\n         pm.ngamma_tests = 0;\n\n      else if (strcmp(*argv, \"--gamma-threshold\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_threshold = 1;\n\n      else if (strcmp(*argv, \"--nogamma-threshold\") == 0)\n         pm.test_gamma_threshold = 0;\n\n      else if (strcmp(*argv, \"--gamma-transform\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_transform = 1;\n\n      else if (strcmp(*argv, \"--nogamma-transform\") == 0)\n         pm.test_gamma_transform = 0;\n\n      else if (strcmp(*argv, \"--gamma-sbit\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_sbit = 1;\n\n      else if (strcmp(*argv, \"--nogamma-sbit\") == 0)\n         pm.test_gamma_sbit = 0;\n\n      else if (strcmp(*argv, \"--gamma-16-to-8\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_scale16 = 1;\n\n      else if (strcmp(*argv, \"--nogamma-16-to-8\") == 0)\n         pm.test_gamma_scale16 = 0;\n\n      else if (strcmp(*argv, \"--gamma-background\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_background = 1;\n\n      else if (strcmp(*argv, \"--nogamma-background\") == 0)\n         pm.test_gamma_background = 0;\n\n      else if (strcmp(*argv, \"--gamma-alpha-mode\") == 0)\n         pm.ngamma_tests = 2U, pm.test_gamma_alpha_mode = 1;\n\n      else if (strcmp(*argv, \"--nogamma-alpha-mode\") == 0)\n         pm.test_gamma_alpha_mode = 0;\n\n      else if (strcmp(*argv, \"--expand16\") == 0)\n         pm.test_gamma_expand16 = 1;\n\n      else if (strcmp(*argv, \"--noexpand16\") == 0)\n         pm.test_gamma_expand16 = 0;\n\n      else if (strcmp(*argv, \"--low-depth-gray\") == 0)\n         pm.test_lbg = pm.test_lbg_gamma_threshold =\n            pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =\n            pm.test_lbg_gamma_composition = 1;\n\n      else if (strcmp(*argv, \"--nolow-depth-gray\") == 0)\n         pm.test_lbg = pm.test_lbg_gamma_threshold =\n            pm.test_lbg_gamma_transform = pm.test_lbg_gamma_sbit =\n            pm.test_lbg_gamma_composition = 0;\n\n#     ifdef PNG_WRITE_tRNS_SUPPORTED\n         else if (strcmp(*argv, \"--tRNS\") == 0)\n            pm.test_tRNS = 1;\n#     endif\n\n      else if (strcmp(*argv, \"--notRNS\") == 0)\n         pm.test_tRNS = 0;\n\n      else if (strcmp(*argv, \"--more-gammas\") == 0)\n         pm.ngamma_tests = 3U;\n\n      else if (strcmp(*argv, \"--all-gammas\") == 0)\n         pm.ngamma_tests = pm.ngammas;\n\n      else if (strcmp(*argv, \"--progressive-read\") == 0)\n         pm.this.progressive = 1;\n\n      else if (strcmp(*argv, \"--use-update-info\") == 0)\n         ++pm.use_update_info; /* Can call multiple times */\n\n      else if (strcmp(*argv, \"--interlace\") == 0)\n      {\n#        if CAN_WRITE_INTERLACE\n            pm.interlace_type = PNG_INTERLACE_ADAM7;\n#        else /* !CAN_WRITE_INTERLACE */\n            fprintf(stderr, \"pngvalid: no write interlace support\\n\");\n            return SKIP;\n#        endif /* !CAN_WRITE_INTERLACE */\n      }\n\n      else if (strcmp(*argv, \"--use-input-precision\") == 0)\n         pm.use_input_precision = 1U;\n\n      else if (strcmp(*argv, \"--use-calculation-precision\") == 0)\n         pm.use_input_precision = 0;\n\n      else if (strcmp(*argv, \"--calculations-use-input-precision\") == 0)\n         pm.calculations_use_input_precision = 1U;\n\n      else if (strcmp(*argv, \"--assume-16-bit-calculations\") == 0)\n         pm.assume_16_bit_calculations = 1U;\n\n      else if (strcmp(*argv, \"--calculations-follow-bit-depth\") == 0)\n         pm.calculations_use_input_precision =\n            pm.assume_16_bit_calculations = 0;\n\n      else if (strcmp(*argv, \"--exhaustive\") == 0)\n         pm.test_exhaustive = 1;\n\n      else if (argc > 1 && strcmp(*argv, \"--sbitlow\") == 0)\n         --argc, pm.sbitlow = (png_byte)atoi(*++argv), catmore = 1;\n\n      else if (argc > 1 && strcmp(*argv, \"--touch\") == 0)\n         --argc, touch = *++argv, catmore = 1;\n\n      else if (argc > 1 && strncmp(*argv, \"--max\", 5) == 0)\n      {\n         --argc;\n\n         if (strcmp(5+*argv, \"abs8\") == 0)\n            pm.maxabs8 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"abs16\") == 0)\n            pm.maxabs16 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"calc8\") == 0)\n            pm.maxcalc8 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"calc16\") == 0)\n            pm.maxcalc16 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"out8\") == 0)\n            pm.maxout8 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"out16\") == 0)\n            pm.maxout16 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"pc8\") == 0)\n            pm.maxpc8 = atof(*++argv);\n\n         else if (strcmp(5+*argv, \"pc16\") == 0)\n            pm.maxpc16 = atof(*++argv);\n\n         else\n         {\n            fprintf(stderr, \"pngvalid: %s: unknown 'max' option\\n\", *argv);\n            exit(99);\n         }\n\n         catmore = 1;\n      }\n\n      else if (strcmp(*argv, \"--log8\") == 0)\n         --argc, pm.log8 = atof(*++argv), catmore = 1;\n\n      else if (strcmp(*argv, \"--log16\") == 0)\n         --argc, pm.log16 = atof(*++argv), catmore = 1;\n\n#ifdef PNG_SET_OPTION_SUPPORTED\n      else if (strncmp(*argv, \"--option=\", 9) == 0)\n      {\n         /* Syntax of the argument is <option>:{on|off} */\n         const char *arg = 9+*argv;\n         unsigned char option=0, setting=0;\n\n#ifdef PNG_ARM_NEON\n         if (strncmp(arg, \"arm-neon:\", 9) == 0)\n            option = PNG_ARM_NEON, arg += 9;\n\n         else\n#endif\n#ifdef PNG_EXTENSIONS\n         if (strncmp(arg, \"extensions:\", 11) == 0)\n            option = PNG_EXTENSIONS, arg += 11;\n\n         else\n#endif\n#ifdef PNG_MAXIMUM_INFLATE_WINDOW\n         if (strncmp(arg, \"max-inflate-window:\", 19) == 0)\n            option = PNG_MAXIMUM_INFLATE_WINDOW, arg += 19;\n\n         else\n#endif\n         {\n            fprintf(stderr, \"pngvalid: %s: %s: unknown option\\n\", *argv, arg);\n            exit(99);\n         }\n\n         if (strcmp(arg, \"off\") == 0)\n            setting = PNG_OPTION_OFF;\n\n         else if (strcmp(arg, \"on\") == 0)\n            setting = PNG_OPTION_ON;\n\n         else\n         {\n            fprintf(stderr,\n               \"pngvalid: %s: %s: unknown setting (use 'on' or 'off')\\n\",\n               *argv, arg);\n            exit(99);\n         }\n\n         pm.this.options[pm.this.noptions].option = option;\n         pm.this.options[pm.this.noptions++].setting = setting;\n      }\n#endif /* PNG_SET_OPTION_SUPPORTED */\n\n      else\n      {\n         fprintf(stderr, \"pngvalid: %s: unknown argument\\n\", *argv);\n         exit(99);\n      }\n\n      if (catmore) /* consumed an extra *argv */\n      {\n         cp = safecat(command, sizeof command, cp, \" \");\n         cp = safecat(command, sizeof command, cp, *argv);\n      }\n   }\n\n   /* If pngvalid is run with no arguments default to a reasonable set of the\n    * tests.\n    */\n   if (pm.test_standard == 0 && pm.test_size == 0 && pm.test_transform == 0 &&\n      pm.ngamma_tests == 0)\n   {\n      /* Make this do all the tests done in the test shell scripts with the same\n       * parameters, where possible.  The limitation is that all the progressive\n       * read and interlace stuff has to be done in separate runs, so only the\n       * basic 'standard' and 'size' tests are done.\n       */\n      pm.test_standard = 1;\n      pm.test_size = 1;\n      pm.test_transform = 1;\n      pm.ngamma_tests = 2U;\n   }\n\n   if (pm.ngamma_tests > 0 &&\n      pm.test_gamma_threshold == 0 && pm.test_gamma_transform == 0 &&\n      pm.test_gamma_sbit == 0 && pm.test_gamma_scale16 == 0 &&\n      pm.test_gamma_background == 0 && pm.test_gamma_alpha_mode == 0)\n   {\n      pm.test_gamma_threshold = 1;\n      pm.test_gamma_transform = 1;\n      pm.test_gamma_sbit = 1;\n      pm.test_gamma_scale16 = 1;\n      pm.test_gamma_background = 1;\n      pm.test_gamma_alpha_mode = 1;\n   }\n\n   else if (pm.ngamma_tests == 0)\n   {\n      /* Nothing to test so turn everything off: */\n      pm.test_gamma_threshold = 0;\n      pm.test_gamma_transform = 0;\n      pm.test_gamma_sbit = 0;\n      pm.test_gamma_scale16 = 0;\n      pm.test_gamma_background = 0;\n      pm.test_gamma_alpha_mode = 0;\n   }\n\n   Try\n   {\n      /* Make useful base images */\n      make_transform_images(&pm);\n\n      /* Perform the standard and gamma tests. */\n      if (pm.test_standard)\n      {\n         perform_interlace_macro_validation();\n         perform_formatting_test(&pm.this);\n#        ifdef PNG_READ_SUPPORTED\n            perform_standard_test(&pm);\n#        endif\n         perform_error_test(&pm);\n      }\n\n      /* Various oddly sized images: */\n      if (pm.test_size)\n      {\n         make_size_images(&pm.this);\n#        ifdef PNG_READ_SUPPORTED\n            perform_size_test(&pm);\n#        endif\n      }\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n      /* Combinatorial transforms: */\n      if (pm.test_transform)\n         perform_transform_test(&pm);\n#endif /* PNG_READ_TRANSFORMS_SUPPORTED */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n      if (pm.ngamma_tests > 0)\n         perform_gamma_test(&pm, summary);\n#endif\n   }\n\n   Catch_anonymous\n   {\n      fprintf(stderr, \"pngvalid: test aborted (probably failed in cleanup)\\n\");\n      if (!pm.this.verbose)\n      {\n         if (pm.this.error[0] != 0)\n            fprintf(stderr, \"pngvalid: first error: %s\\n\", pm.this.error);\n\n         fprintf(stderr, \"pngvalid: run with -v to see what happened\\n\");\n      }\n      exit(1);\n   }\n\n   if (summary)\n   {\n      printf(\"%s: %s (%s point arithmetic)\\n\",\n         (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&\n            pm.this.nwarnings)) ? \"FAIL\" : \"PASS\",\n         command,\n#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || PNG_LIBPNG_VER < 10500\n         \"floating\"\n#else\n         \"fixed\"\n#endif\n         );\n   }\n\n   if (memstats)\n   {\n      printf(\"Allocated memory statistics (in bytes):\\n\"\n         \"\\tread  %lu maximum single, %lu peak, %lu total\\n\"\n         \"\\twrite %lu maximum single, %lu peak, %lu total\\n\",\n         (unsigned long)pm.this.read_memory_pool.max_max,\n         (unsigned long)pm.this.read_memory_pool.max_limit,\n         (unsigned long)pm.this.read_memory_pool.max_total,\n         (unsigned long)pm.this.write_memory_pool.max_max,\n         (unsigned long)pm.this.write_memory_pool.max_limit,\n         (unsigned long)pm.this.write_memory_pool.max_total);\n   }\n\n   /* Do this here to provoke memory corruption errors in memory not directly\n    * allocated by libpng - not a complete test, but better than nothing.\n    */\n   store_delete(&pm.this);\n\n   /* Error exit if there are any errors, and maybe if there are any\n    * warnings.\n    */\n   if (pm.this.nerrors || (pm.this.treat_warnings_as_errors &&\n       pm.this.nwarnings))\n   {\n      if (!pm.this.verbose)\n         fprintf(stderr, \"pngvalid: %s\\n\", pm.this.error);\n\n      fprintf(stderr, \"pngvalid: %d errors, %d warnings\\n\", pm.this.nerrors,\n          pm.this.nwarnings);\n\n      exit(1);\n   }\n\n   /* Success case. */\n   if (touch != NULL)\n   {\n      FILE *fsuccess = fopen(touch, \"wt\");\n\n      if (fsuccess != NULL)\n      {\n         int error = 0;\n         fprintf(fsuccess, \"PNG validation succeeded\\n\");\n         fflush(fsuccess);\n         error = ferror(fsuccess);\n\n         if (fclose(fsuccess) || error)\n         {\n            fprintf(stderr, \"%s: write failed\\n\", touch);\n            exit(1);\n         }\n      }\n\n      else\n      {\n         fprintf(stderr, \"%s: open failed\\n\", touch);\n         exit(1);\n      }\n   }\n\n   /* This is required because some very minimal configurations do not use it:\n    */\n   UNUSED(fail)\n   return 0;\n}\n#else /* write or low level APIs not supported */\nint main(void)\n{\n   fprintf(stderr,\n      \"pngvalid: no low level write support in libpng, all tests skipped\\n\");\n   /* So the test is skipped: */\n   return SKIP;\n}\n#endif\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/readpng.c",
    "content": "/* readpng.c\n *\n * Copyright (c) 2013 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.1 [March 28, 2013]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Load an arbitrary number of PNG files (from the command line, or, if there\n * are no arguments on the command line, from stdin) then run a time test by\n * reading each file by row.  The test does nothing with the read result and\n * does no transforms.  The only output is a time as a floating point number of\n * seconds with 9 decimal digits.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\nstatic int\nread_png(FILE *fp)\n{\n   png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,0);\n   png_infop info_ptr = NULL;\n   png_bytep row = NULL, display = NULL;\n\n   if (png_ptr == NULL)\n      return 0;\n\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n      if (row != NULL) free(row);\n      if (display != NULL) free(display);\n      return 0;\n   }\n\n   png_init_io(png_ptr, fp);\n\n   info_ptr = png_create_info_struct(png_ptr);\n   if (info_ptr == NULL)\n      png_error(png_ptr, \"OOM allocating info structure\");\n\n   png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_ALWAYS, NULL, 0);\n\n   png_read_info(png_ptr, info_ptr);\n\n   {\n      png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n\n      /* Failure to initialize these is harmless */\n      row = malloc(rowbytes);\n      display = malloc(rowbytes);\n\n      if (row == NULL || display == NULL)\n         png_error(png_ptr, \"OOM allocating row buffers\");\n\n      {\n         png_uint_32 height = png_get_image_height(png_ptr, info_ptr);\n#        ifdef PNG_READ_INTERLACING_SUPPORTED\n            int passes = png_set_interlace_handling(png_ptr);\n#        else /* !READ_INTERLACING */\n            int passes = png_get_interlace_type(png_ptr, info_ptr) ==\n               PNG_INTERLACE_ADAM7 ? PNG_INTERLACE_ADAM7_PASSES : 1;\n#        endif /* !READ_INTERLACING */\n         int pass;\n\n         png_start_read_image(png_ptr);\n\n         for (pass = 0; pass < passes; ++pass)\n         {\n            png_uint_32 y = height;\n\n#           ifndef PNG_READ_INTERLACING_SUPPORTED\n               if (passes == PNG_INTERLACE_ADAM7_PASSES)\n                  y = PNG_PASS_ROWS(y, pass);\n#           endif /* READ_INTERLACING */\n\n            /* NOTE: this trashes the row each time; interlace handling won't\n             * work, but this avoids memory thrashing for speed testing.\n             */\n            while (y-- > 0)\n               png_read_row(png_ptr, row, display);\n         }\n      }\n   }\n\n   /* Make sure to read to the end of the file: */\n   png_read_end(png_ptr, info_ptr);\n   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n   free(row);\n   free(display);\n   return 1;\n}\n\nint\nmain(void)\n{\n   /* Exit code 0 on success. */\n   return !read_png(stdin);\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/tarith.c",
    "content": "\n/* tarith.c\n *\n * Copyright (c) 2011-2013 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.0 [February 14, 2013]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Test internal arithmetic functions of libpng.\n *\n * This code must be linked against a math library (-lm), but does not require\n * libpng or zlib to work.  Because it includes the complete source of 'png.c'\n * it tests the code with whatever compiler options are used to build it.\n * Changing these options can substantially change the errors in the\n * calculations that the compiler chooses!\n */\n#define _POSIX_SOURCE 1\n#define _ISOC99_SOURCE 1\n\n/* Obtain a copy of the code to be tested (plus other things), disabling\n * stuff that is not required.\n */\n#include <math.h>\n#include <stdlib.h>\n#include <ctype.h>\n#include <string.h>\n#include <assert.h>\n\n#include \"../../pngpriv.h\"\n\n#define png_error png_warning\n\nvoid png_warning(png_const_structrp png_ptr, png_const_charp msg)\n{\n   fprintf(stderr, \"validation: %s\\n\", msg);\n}\n\n#define png_fixed_error png_fixed_warning\n\nvoid png_fixed_warning(png_const_structrp png_ptr, png_const_charp msg)\n{\n   fprintf(stderr, \"overflow in: %s\\n\", msg);\n}\n\n#define png_set_error_fn(pp, ep, efp, wfp) ((void)0)\n#define png_malloc(pp, s) malloc(s)\n#define png_malloc_warn(pp, s) malloc(s)\n#define png_malloc_base(pp, s) malloc(s)\n#define png_calloc(pp, s) calloc(1, (s))\n#define png_free(pp, s) free(s)\n\n#define png_safecat(b, sb, pos, str) (pos)\n#define png_format_number(start, end, format, number) (start)\n\n#define crc32(crc, pp, s) (crc)\n#define inflateReset(zs) Z_OK\n\n#define png_create_struct(type) (0)\n#define png_destroy_struct(pp) ((void)0)\n#define png_create_struct_2(type, m, mm) (0)\n#define png_destroy_struct_2(pp, f, mm) ((void)0)\n\n#undef PNG_SIMPLIFIED_READ_SUPPORTED\n#undef PNG_SIMPLIFIED_WRITE_SUPPORTED\n#undef PNG_USER_MEM_SUPPORTED\n\n#include \"../../png.c\"\n\n/* Validate ASCII to fp routines. */\nstatic int verbose = 0;\n\nint validation_ascii_to_fp(int count, int argc, char **argv)\n{\n   int    showall = 0;\n   double max_error=2;      /* As a percentage error-in-last-digit/.5 */\n   double max_error_abs=17; /* Used when precision is DBL_DIG */\n   double max = 0;\n   double max_abs = 0;\n   double test = 0; /* Important to test this. */\n   int    precision = 5;\n   int    nonfinite = 0;\n   int    finite = 0;\n   int    ok = 0;\n   int    failcount = 0;\n   int    minorarith = 0;\n\n   while (--argc > 0)\n      if (strcmp(*++argv, \"-a\") == 0)\n         showall = 1;\n      else if (strcmp(*argv, \"-e\") == 0 && argc > 0)\n      {\n         --argc;\n         max_error = atof(*++argv);\n      }\n      else if (strcmp(*argv, \"-E\") == 0 && argc > 0)\n      {\n         --argc;\n         max_error_abs = atof(*++argv);\n      }\n      else\n      {\n         fprintf(stderr, \"unknown argument %s\\n\", *argv);\n         return 1;\n      }\n\n   do\n   {\n      png_size_t index;\n      int state, failed = 0;\n      char buffer[64];\n\n      if (isfinite(test))\n         ++finite;\n      else\n         ++nonfinite;\n\n      if (verbose)\n         fprintf(stderr, \"%.*g %d\\n\", DBL_DIG, test, precision);\n\n      /* Check for overflow in the buffer by setting a marker. */\n      memset(buffer, 71, sizeof buffer);\n\n      png_ascii_from_fp(0, buffer, precision+10, test, precision);\n\n      /* Allow for a three digit exponent, this stuff will fail if\n       * the exponent is bigger than this!\n       */\n      if (buffer[precision+7] != 71)\n      {\n         fprintf(stderr, \"%g[%d] -> '%s'[%lu] buffer overflow\\n\", test,\n            precision, buffer, (unsigned long)strlen(buffer));\n         failed = 1;\n      }\n\n      /* Following are used for the number parser below and must be\n       * initialized to zero.\n       */\n      state = 0;\n      index = 0;\n      if (!isfinite(test))\n      {\n         /* Expect 'inf' */\n         if (test >= 0 && strcmp(buffer, \"inf\") ||\n             test <  0 && strcmp(buffer, \"-inf\"))\n         {\n            fprintf(stderr, \"%g[%d] -> '%s' but expected 'inf'\\n\", test,\n               precision, buffer);\n            failed = 1;\n         }\n      }\n      else if (!png_check_fp_number(buffer, precision+10, &state, &index) ||\n          buffer[index] != 0)\n      {\n         fprintf(stderr, \"%g[%d] -> '%s' but has bad format ('%c')\\n\", test,\n         precision, buffer, buffer[index]);\n         failed = 1;\n      }\n      else if (PNG_FP_IS_NEGATIVE(state) && !(test < 0))\n      {\n         fprintf(stderr, \"%g[%d] -> '%s' but negative value not so reported\\n\",\n            test, precision, buffer);\n         failed = 1;\n         assert(!PNG_FP_IS_ZERO(state));\n         assert(!PNG_FP_IS_POSITIVE(state));\n      }\n      else if (PNG_FP_IS_ZERO(state) && !(test == 0))\n      {\n         fprintf(stderr, \"%g[%d] -> '%s' but zero value not so reported\\n\",\n            test, precision, buffer);\n         failed = 1;\n         assert(!PNG_FP_IS_NEGATIVE(state));\n         assert(!PNG_FP_IS_POSITIVE(state));\n      }\n      else if (PNG_FP_IS_POSITIVE(state) && !(test > 0))\n      {\n         fprintf(stderr, \"%g[%d] -> '%s' but postive value not so reported\\n\",\n            test, precision, buffer);\n         failed = 1;\n         assert(!PNG_FP_IS_NEGATIVE(state));\n         assert(!PNG_FP_IS_ZERO(state));\n      }\n      else\n      {\n         /* Check the result against the original. */\n         double out = atof(buffer);\n         double change = fabs((out - test)/test);\n         double allow = .5/pow(10,\n            (precision >= DBL_DIG) ? DBL_DIG-1 : precision-1);\n\n         /* NOTE: if you hit this error case are you compiling with gcc\n          * and -O0?  Try -O2 - the errors can accumulate if the FP\n          * code above is not optimized and may drift outside the .5 in\n          * DBL_DIG allowed.  In any case a small number of errors may\n          * occur (very small ones - 1 or 2%) because of rounding in the\n          * calculations, either in the conversion API or in atof.\n          */\n         if (change >= allow && (isfinite(out) ||\n             fabs(test/DBL_MAX) <= 1-allow))\n         {\n            double percent = (precision >= DBL_DIG) ? max_error_abs : max_error;\n            double allowp = (change-allow)*100/allow;\n\n            if (precision >= DBL_DIG)\n            {\n               if (max_abs < allowp) max_abs = allowp;\n            }\n\n            else\n            {\n               if (max < allowp) max = allowp;\n            }\n\n            if (showall || allowp >= percent)\n            {\n               fprintf(stderr,\n                  \"%.*g[%d] -> '%s' -> %.*g number changed (%g > %g (%d%%))\\n\",\n                  DBL_DIG, test, precision, buffer, DBL_DIG, out, change, allow,\n                  (int)round(allowp));\n               failed = 1;\n            }\n            else\n               ++minorarith;\n         }\n      }\n\n      if (failed)\n         ++failcount;\n      else\n         ++ok;\n\nskip:\n      /* Generate a new number and precision. */\n      precision = rand();\n      if (precision & 1) test = -test;\n      precision >>= 1;\n\n      /* Generate random numbers. */\n      if (test == 0 || !isfinite(test))\n         test = precision+1;\n      else\n      {\n         /* Derive the exponent from the previous rand() value. */\n         int exponent = precision % (DBL_MAX_EXP - DBL_MIN_EXP) + DBL_MIN_EXP;\n         int tmp;\n         test = frexp(test * rand(), &tmp);\n         test = ldexp(test, exponent);\n         precision >>= 8; /* arbitrary */\n      }\n\n      /* This limits the precision to 32 digits, enough for standard\n       * IEEE implementations which have at most 15 digits.\n       */\n      precision = (precision & 0x1f) + 1;\n   }\n   while (--count);\n\n   printf(\"Tested %d finite values, %d non-finite, %d OK (%d failed) %d minor \"\n      \"arithmetic errors\\n\", finite, nonfinite, ok, failcount, minorarith);\n   printf(\" Error with >=%d digit precision %.2f%%\\n\", DBL_DIG, max_abs);\n   printf(\" Error with < %d digit precision %.2f%%\\n\", DBL_DIG, max);\n\n   return 0;\n}\n\n/* Observe that valid FP numbers have the forms listed in the PNG extensions\n * specification:\n *\n * [+,-]{integer,integer.fraction,.fraction}[{e,E}[+,-]integer]\n *\n * Test each of these in turn, including invalid cases.\n */\ntypedef enum checkfp_state\n{\n   start, fraction, exponent, states\n} checkfp_state;\n\n/* The characters (other than digits) that characterize the states: */\nstatic const char none[] = \"\";\nstatic const char hexdigits[16] = \"0123456789ABCDEF\";\n\nstatic const struct\n{\n   const char *start; /* Characters valid at the start */\n   const char *end;   /* Valid characters that end the state */\n   const char *tests; /* Characters to test after 2 digits seen */\n}\nstate_characters[states] =\n{\n   /* start:    */ { \"+-.\", \".eE\", \"+-.e*0369\" },\n   /* fraction: */ { none, \"eE\",  \"+-.E#0147\" },\n   /* exponent: */ { \"+-\", none,  \"+-.eE^0258\" }\n};\n\ntypedef struct\n{\n   char number[1024];  /* Buffer for number being tested */\n   int  limit;         /* Command line limit */\n   int  verbose;       /* Shadows global variable */\n   int  ctimes;        /* Number of numbers tested */\n   int  cmillions;     /* Count of millions of numbers */\n   int  cinvalid;      /* Invalid strings checked */\n   int  cnoaccept;     /* Characters not accepted */\n}\ncheckfp_command;\n\ntypedef struct\n{\n   int           cnumber;          /* Index into number string */\n   checkfp_state check_state;      /* Current number state */\n   int           at_start;         /* At start (first character) of state */\n   int           cdigits_in_state; /* Digits seen in that state */\n   int           limit;            /* Limit on same for checking all chars */\n   int           state;            /* Current parser state */\n   int           is_negative;      /* Number is negative */\n   int           is_zero;          /* Number is (still) zero */\n   int           number_was_valid; /* Previous character validity */\n}\ncheckfp_control;\n\nstatic int check_all_characters(checkfp_command *co, checkfp_control c);\n\nstatic int check_some_characters(checkfp_command *co, checkfp_control c,\n   const char *tests);\n\nstatic int check_one_character(checkfp_command *co, checkfp_control c, int ch)\n{\n   /* Test this character (ch) to ensure the parser does the correct thing.\n    */\n   png_size_t index = 0;\n   const char test = (char)ch;\n   const int number_is_valid = png_check_fp_number(&test, 1, &c.state, &index);\n   const int character_accepted = (index == 1);\n\n   if (c.check_state != exponent && isdigit(ch) && ch != '0')\n      c.is_zero = 0;\n\n   if (c.check_state == start && c.at_start && ch == '-')\n      c.is_negative = 1;\n\n   if (isprint(ch))\n      co->number[c.cnumber++] = (char)ch;\n   else\n   {\n      co->number[c.cnumber++] = '<';\n      co->number[c.cnumber++] = hexdigits[(ch >> 4) & 0xf];\n      co->number[c.cnumber++] = hexdigits[ch & 0xf];\n      co->number[c.cnumber++] = '>';\n   }\n   co->number[c.cnumber] = 0;\n\n   if (co->verbose > 1)\n      fprintf(stderr, \"%s\\n\", co->number);\n\n   if (++(co->ctimes) == 1000000)\n   {\n      if (co->verbose == 1)\n         fputc('.', stderr);\n      co->ctimes = 0;\n      ++(co->cmillions);\n   }\n\n   if (!number_is_valid)\n      ++(co->cinvalid);\n\n   if (!character_accepted)\n      ++(co->cnoaccept);\n\n   /* This should never fail (it's a serious bug if it does): */\n   if (index != 0 && index != 1)\n   {\n      fprintf(stderr, \"%s: read beyond end of string (%lu)\\n\", co->number,\n         (unsigned long)index);\n      return 0;\n   }\n\n   /* Validate the new state, note that the PNG_FP_IS_ macros all return\n    * false unless the number is valid.\n    */\n   if (PNG_FP_IS_NEGATIVE(c.state) !=\n      (number_is_valid && !c.is_zero && c.is_negative))\n   {\n      fprintf(stderr, \"%s: negative when it is not\\n\", co->number);\n      return 0;\n   }\n\n   if (PNG_FP_IS_ZERO(c.state) != (number_is_valid && c.is_zero))\n   {\n      fprintf(stderr, \"%s: zero when it is not\\n\", co->number);\n      return 0;\n   }\n\n   if (PNG_FP_IS_POSITIVE(c.state) !=\n      (number_is_valid && !c.is_zero && !c.is_negative))\n   {\n      fprintf(stderr, \"%s: positive when it is not\\n\", co->number);\n      return 0;\n   }\n\n   /* Testing a digit */\n   if (isdigit(ch))\n   {\n      if (!character_accepted)\n      {\n         fprintf(stderr, \"%s: digit '%c' not accepted\\n\", co->number, ch);\n         return 0;\n      }\n\n      if (!number_is_valid)\n      {\n         fprintf(stderr, \"%s: saw a digit (%c) but number not valid\\n\",\n            co->number, ch);\n         return 0;\n      }\n\n      ++c.cdigits_in_state;\n      c.at_start = 0;\n      c.number_was_valid = 1;\n\n      /* Continue testing characters in this state.  Either test all of\n       * them or, if we have already seen one digit in this state, just test a\n       * limited set.\n       */\n      if (c.cdigits_in_state < 1)\n         return check_all_characters(co, c);\n\n      else\n         return check_some_characters(co, c,\n            state_characters[c.check_state].tests);\n   }\n\n   /* A non-digit; is it allowed here? */\n   else if (((ch == '+' || ch == '-') && c.check_state != fraction &&\n               c.at_start) ||\n            (ch == '.' && c.check_state == start) ||\n            ((ch == 'e' || ch == 'E') && c.number_was_valid &&\n               c.check_state != exponent))\n   {\n      if (!character_accepted)\n      {\n         fprintf(stderr, \"%s: character '%c' not accepted\\n\", co->number, ch);\n         return 0;\n      }\n\n      /* The number remains valid after start of fraction but nowhere else. */\n      if (number_is_valid && (c.check_state != start || ch != '.'))\n      {\n         fprintf(stderr, \"%s: saw a non-digit (%c) but number valid\\n\",\n            co->number, ch);\n         return 0;\n      }\n\n      c.number_was_valid = number_is_valid;\n\n      /* Check for a state change.  When changing to 'fraction' if the number\n       * is valid at this point set the at_start to false to allow an exponent\n       * 'e' to come next.\n       */\n      if (c.check_state == start && ch == '.')\n      {\n         c.check_state = fraction;\n         c.at_start = !number_is_valid;\n         c.cdigits_in_state = 0;\n         c.limit = co->limit;\n         return check_all_characters(co, c);\n      }\n\n      else if (c.check_state < exponent && (ch == 'e' || ch == 'E'))\n      {\n         c.check_state = exponent;\n         c.at_start = 1;\n         c.cdigits_in_state = 0;\n         c.limit = co->limit;\n         return check_all_characters(co, c);\n      }\n\n      /* Else it was a sign, and the state doesn't change. */\n      else\n      {\n         if (ch != '-' && ch != '+')\n         {\n            fprintf(stderr, \"checkfp: internal error (1)\\n\");\n            return 0;\n         }\n\n         c.at_start = 0;\n         return check_all_characters(co, c);\n      }\n   }\n\n   /* Testing an invalid character */\n   else\n   {\n      if (character_accepted)\n      {\n         fprintf(stderr, \"%s: character '%c' [0x%.2x] accepted\\n\", co->number,\n            ch, ch);\n         return 0;\n      }\n\n      if (number_is_valid != c.number_was_valid)\n      {\n         fprintf(stderr,\n            \"%s: character '%c' [0x%.2x] changed number validity\\n\", co->number,\n            ch, ch);\n         return 0;\n      }\n\n      /* Do nothing - the parser has stuck; return success and keep going with\n       * the next character.\n       */\n   }\n\n   /* Successful return (the caller will try the next character.) */\n   return 1;\n}\n\nstatic int check_all_characters(checkfp_command *co, checkfp_control c)\n{\n   int ch;\n\n   if (c.cnumber+4 < sizeof co->number) for (ch=0; ch<256; ++ch)\n   {\n      if (!check_one_character(co, c, ch))\n         return 0;\n   }\n\n   return 1;\n}\n\nstatic int check_some_characters(checkfp_command *co, checkfp_control c,\n   const char *tests)\n{\n   int i;\n\n   --(c.limit);\n\n   if (c.cnumber+4 < sizeof co->number && c.limit >= 0)\n   {\n      if (c.limit > 0) for (i=0; tests[i]; ++i)\n      {\n         if (!check_one_character(co, c, tests[i]))\n               return 0;\n      }\n\n      /* At the end check all the characters. */\n      else\n         return check_all_characters(co, c);\n   }\n\n   return 1;\n}\n\nint validation_checkfp(int count, int argc, char **argv)\n{\n   int result;\n   checkfp_command command;\n   checkfp_control control;\n\n   command.number[0] = 0;\n   command.limit = 3;\n   command.verbose = verbose;\n   command.ctimes = 0;\n   command.cmillions = 0;\n   command.cinvalid = 0;\n   command.cnoaccept = 0;\n\n   while (--argc > 0)\n   {\n      ++argv;\n      if (argc > 1 && strcmp(*argv, \"-l\") == 0)\n      {\n         --argc;\n         command.limit = atoi(*++argv);\n      }\n\n      else\n      {\n         fprintf(stderr, \"unknown argument %s\\n\", *argv);\n         return 1;\n      }\n   }\n\n   control.cnumber = 0;\n   control.check_state = start;\n   control.at_start = 1;\n   control.cdigits_in_state = 0;\n   control.limit = command.limit;\n   control.state = 0;\n   control.is_negative = 0;\n   control.is_zero = 1;\n   control.number_was_valid = 0;\n\n   result = check_all_characters(&command, control);\n\n   printf(\"checkfp: %s: checked %d,%.3d,%.3d,%.3d strings (%d invalid)\\n\",\n      result ? \"pass\" : \"FAIL\", command.cmillions / 1000,\n      command.cmillions % 1000, command.ctimes / 1000, command.ctimes % 1000,\n      command.cinvalid);\n\n   return result;\n}\n\nint validation_muldiv(int count, int argc, char **argv)\n{\n   int tested = 0;\n   int overflow = 0;\n   int error = 0;\n   int error64 = 0;\n   int passed = 0;\n   int randbits = 0;\n   png_uint_32 randbuffer;\n   png_fixed_point a;\n   png_int_32 times, div;\n\n   while (--argc > 0)\n      {\n         fprintf(stderr, \"unknown argument %s\\n\", *++argv);\n         return 1;\n      }\n\n   /* Find out about the random number generator. */\n   randbuffer = RAND_MAX;\n   while (randbuffer != 0) ++randbits, randbuffer >>= 1;\n   printf(\"Using random number generator that makes %d bits\\n\", randbits);\n   for (div=0; div<32; div += randbits)\n      randbuffer = (randbuffer << randbits) ^ rand();\n\n   a = 0;\n   times = div = 0;\n   do\n   {\n      png_fixed_point result;\n      /* NOTE: your mileage may vary, a type is required below that can\n       * hold 64 bits or more, if floating point is used a 64-bit or\n       * better mantissa is required.\n       */\n      long long int fp, fpround;\n      unsigned long hi, lo;\n      int ok;\n\n      /* Check the values, png_64bit_product can only handle positive\n       * numbers, so correct for that here.\n       */\n      {\n         long u1, u2;\n         int n = 0;\n         if (a < 0) u1 = -a, n = 1; else u1 = a;\n         if (times < 0) u2 = -times, n = !n; else u2 = times;\n         png_64bit_product(u1, u2, &hi, &lo);\n         if (n)\n         {\n            /* -x = ~x+1 */\n            lo = ((~lo) + 1) & 0xffffffff;\n            hi = ~hi;\n            if (lo == 0) ++hi;\n         }\n      }\n\n      fp = a;\n      fp *= times;\n      if ((fp & 0xffffffff) != lo || ((fp >> 32) & 0xffffffff) != hi)\n      {\n         fprintf(stderr, \"png_64bit_product %d * %d -> %lx|%.8lx not %llx\\n\",\n            a, times, hi, lo, fp);\n         ++error64;\n      }\n\n      if (div != 0)\n      {\n         /* Round - this is C round to zero. */\n         if ((fp < 0) != (div < 0))\n           fp -= div/2;\n         else\n           fp += div/2;\n\n         fp /= div;\n         fpround = fp;\n         /* Assume 2's complement here: */\n         ok = fpround <= PNG_UINT_31_MAX &&\n              fpround >= -1-(long long int)PNG_UINT_31_MAX;\n         if (!ok) ++overflow;\n      }\n      else\n        ok = 0, ++overflow, fpround = fp/*misleading*/;\n\n      if (verbose)\n         fprintf(stderr, \"TEST %d * %d / %d -> %lld (%s)\\n\", a, times, div,\n            fp, ok ? \"ok\" : \"overflow\");\n\n      ++tested;\n      if (png_muldiv(&result, a, times, div) != ok)\n      {\n         ++error;\n         if (ok)\n             fprintf(stderr, \"%d * %d / %d -> overflow (expected %lld)\\n\", a,\n                times, div, fp);\n         else\n             fprintf(stderr, \"%d * %d / %d -> %d (expected overflow %lld)\\n\", a,\n                times, div, result, fp);\n      }\n      else if (ok && result != fpround)\n      {\n         ++error;\n         fprintf(stderr, \"%d * %d / %d -> %d not %lld\\n\", a, times, div, result,\n            fp);\n      }\n      else\n         ++passed;\n\n      /* Generate three new values, this uses rand() and rand() only returns\n       * up to RAND_MAX.\n       */\n      /* CRUDE */\n      a += times;\n      times += div;\n      div = randbuffer;\n      randbuffer = (randbuffer << randbits) ^ rand();\n   }\n   while (--count > 0);\n\n   printf(\"%d tests including %d overflows, %d passed, %d failed (%d 64-bit \"\n      \"errors)\\n\", tested, overflow, passed, error, error64);\n   return 0;\n}\n\n/* When FP is on this just becomes a speed test - compile without FP to get real\n * validation.\n */\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n#define LN2 .000010576586617430806112933839 /* log(2)/65536 */\n#define L2INV 94548.46219969910586572651    /* 65536/log(2) */\n\n/* For speed testing, need the internal functions too: */\nstatic png_uint_32 png_log8bit(unsigned x)\n{\n   if (x > 0)\n      return (png_uint_32)floor(.5-log(x/255.)*L2INV);\n\n   return 0xffffffff;\n}\n\nstatic png_uint_32 png_log16bit(png_uint_32 x)\n{\n   if (x > 0)\n      return (png_uint_32)floor(.5-log(x/65535.)*L2INV);\n\n   return 0xffffffff;\n}\n\nstatic png_uint_32 png_exp(png_uint_32 x)\n{\n   return (png_uint_32)floor(.5 + exp(x * -LN2) * 0xffffffffU);\n}\n\nstatic png_byte png_exp8bit(png_uint_32 log)\n{\n   return (png_byte)floor(.5 + exp(log * -LN2) * 255);\n}\n\nstatic png_uint_16 png_exp16bit(png_uint_32 log)\n{\n   return (png_uint_16)floor(.5 + exp(log * -LN2) * 65535);\n}\n#endif /* FLOATING_ARITHMETIC */\n\nint validation_gamma(int argc, char **argv)\n{\n   double gamma[9] = { 2.2, 1.8, 1.52, 1.45, 1., 1/1.45, 1/1.52, 1/1.8, 1/2.2 };\n   double maxerr;\n   int i, silent=0, onlygamma=0;\n\n   /* Silence the output with -s, just test the gamma functions with -g: */\n   while (--argc > 0)\n      if (strcmp(*++argv, \"-s\") == 0)\n         silent = 1;\n      else if (strcmp(*argv, \"-g\") == 0)\n         onlygamma = 1;\n      else\n      {\n         fprintf(stderr, \"unknown argument %s\\n\", *argv);\n         return 1;\n      }\n\n   if (!onlygamma)\n   {\n      /* First validate the log functions: */\n      maxerr = 0;\n      for (i=0; i<256; ++i)\n      {\n         double correct = -log(i/255.)/log(2.)*65536;\n         double error = png_log8bit(i) - correct;\n\n         if (i != 0 && fabs(error) > maxerr)\n            maxerr = fabs(error);\n\n         if (i == 0 && png_log8bit(i) != 0xffffffff ||\n             i != 0 && png_log8bit(i) != floor(correct+.5))\n         {\n            fprintf(stderr, \"8-bit log error: %d: got %u, expected %f\\n\",\n               i, png_log8bit(i), correct);\n         }\n      }\n\n      if (!silent)\n         printf(\"maximum 8-bit log error = %f\\n\", maxerr);\n\n      maxerr = 0;\n      for (i=0; i<65536; ++i)\n      {\n         double correct = -log(i/65535.)/log(2.)*65536;\n         double error = png_log16bit(i) - correct;\n\n         if (i != 0 && fabs(error) > maxerr)\n            maxerr = fabs(error);\n\n         if (i == 0 && png_log16bit(i) != 0xffffffff ||\n             i != 0 && png_log16bit(i) != floor(correct+.5))\n         {\n            if (error > .68) /* By experiment error is less than .68 */\n            {\n               fprintf(stderr, \"16-bit log error: %d: got %u, expected %f\"\n                  \" error: %f\\n\", i, png_log16bit(i), correct, error);\n            }\n         }\n      }\n\n      if (!silent)\n         printf(\"maximum 16-bit log error = %f\\n\", maxerr);\n\n      /* Now exponentiations. */\n      maxerr = 0;\n      for (i=0; i<=0xfffff; ++i)\n      {\n         double correct = exp(-i/65536. * log(2.)) * (65536. * 65536);\n         double error = png_exp(i) - correct;\n\n         if (fabs(error) > maxerr)\n            maxerr = fabs(error);\n         if (fabs(error) > 1883) /* By experiment. */\n         {\n            fprintf(stderr, \"32-bit exp error: %d: got %u, expected %f\"\n                  \" error: %f\\n\", i, png_exp(i), correct, error);\n         }\n      }\n\n      if (!silent)\n         printf(\"maximum 32-bit exp error = %f\\n\", maxerr);\n\n      maxerr = 0;\n      for (i=0; i<=0xfffff; ++i)\n      {\n         double correct = exp(-i/65536. * log(2.)) * 255;\n         double error = png_exp8bit(i) - correct;\n\n         if (fabs(error) > maxerr)\n            maxerr = fabs(error);\n         if (fabs(error) > .50002) /* By experiment */\n         {\n            fprintf(stderr, \"8-bit exp error: %d: got %u, expected %f\"\n                  \" error: %f\\n\", i, png_exp8bit(i), correct, error);\n         }\n      }\n\n      if (!silent)\n         printf(\"maximum 8-bit exp error = %f\\n\", maxerr);\n\n      maxerr = 0;\n      for (i=0; i<=0xfffff; ++i)\n      {\n         double correct = exp(-i/65536. * log(2.)) * 65535;\n         double error = png_exp16bit(i) - correct;\n\n         if (fabs(error) > maxerr)\n            maxerr = fabs(error);\n         if (fabs(error) > .524) /* By experiment */\n         {\n            fprintf(stderr, \"16-bit exp error: %d: got %u, expected %f\"\n                  \" error: %f\\n\", i, png_exp16bit(i), correct, error);\n         }\n      }\n\n      if (!silent)\n         printf(\"maximum 16-bit exp error = %f\\n\", maxerr);\n   } /* !onlygamma */\n\n   /* Test the overall gamma correction. */\n   for (i=0; i<9; ++i)\n   {\n      unsigned j;\n      double g = gamma[i];\n      png_fixed_point gfp = floor(g * PNG_FP_1 + .5);\n\n      if (!silent)\n         printf(\"Test gamma %f\\n\", g);\n\n      maxerr = 0;\n      for (j=0; j<256; ++j)\n      {\n         double correct = pow(j/255., g) * 255;\n         png_byte out = png_gamma_8bit_correct(j, gfp);\n         double error = out - correct;\n\n         if (fabs(error) > maxerr)\n            maxerr = fabs(error);\n         if (out != floor(correct+.5))\n         {\n            fprintf(stderr, \"8bit %d ^ %f: got %d expected %f error %f\\n\",\n               j, g, out, correct, error);\n         }\n      }\n\n      if (!silent)\n         printf(\"gamma %f: maximum 8-bit error %f\\n\", g, maxerr);\n\n      maxerr = 0;\n      for (j=0; j<65536; ++j)\n      {\n         double correct = pow(j/65535., g) * 65535;\n         png_uint_16 out = png_gamma_16bit_correct(j, gfp);\n         double error = out - correct;\n\n         if (fabs(error) > maxerr)\n            maxerr = fabs(error);\n         if (fabs(error) > 1.62)\n         {\n            fprintf(stderr, \"16bit %d ^ %f: got %d expected %f error %f\\n\",\n               j, g, out, correct, error);\n         }\n      }\n\n      if (!silent)\n         printf(\"gamma %f: maximum 16-bit error %f\\n\", g, maxerr);\n   }\n\n   return 0;\n}\n\n/**************************** VALIDATION TESTS ********************************/\n/* Various validation routines are included herein, they require some\n * definition for png_warning and png_error, seetings of VALIDATION:\n *\n * 1: validates the ASCII to floating point conversions\n * 2: validates png_muldiv\n * 3: accuracy test of fixed point gamma tables\n */\n\n/* The following COUNT (10^8) takes about 1 hour on a 1GHz Pentium IV\n * processor.\n */\n#define COUNT 1000000000\n\nint main(int argc, char **argv)\n{\n   int count = COUNT;\n\n   while (argc > 1)\n   {\n      if (argc > 2 && strcmp(argv[1], \"-c\") == 0)\n      {\n         count = atoi(argv[2]);\n         argc -= 2;\n         argv += 2;\n      }\n\n      else if (strcmp(argv[1], \"-v\") == 0)\n      {\n         ++verbose;\n         --argc;\n         ++argv;\n      }\n\n      else\n         break;\n   }\n\n   if (count > 0 && argc > 1)\n   {\n      if (strcmp(argv[1], \"ascii\") == 0)\n         return validation_ascii_to_fp(count, argc-1, argv+1);\n      else if (strcmp(argv[1], \"checkfp\") == 0)\n         return validation_checkfp(count, argc-1, argv+1);\n      else if (strcmp(argv[1], \"muldiv\") == 0)\n         return validation_muldiv(count, argc-1, argv+1);\n      else if (strcmp(argv[1], \"gamma\") == 0)\n         return validation_gamma(argc-1, argv+1);\n   }\n\n   /* Bad argument: */\n   fprintf(stderr,\n      \"usage: tarith [-v] [-c count] {ascii,muldiv,gamma} [args]\\n\");\n   fprintf(stderr, \" arguments: ascii [-a (all results)] [-e error%%]\\n\");\n   fprintf(stderr, \"            checkfp [-l max-number-chars]\\n\");\n   fprintf(stderr, \"            muldiv\\n\");\n   fprintf(stderr, \"            gamma -s (silent) -g (only gamma; no log)\\n\");\n   return 1;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/libtests/timepng.c",
    "content": "/* timepng.c\n *\n * Copyright (c) 2013,2016 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.22 [May 26, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Load an arbitrary number of PNG files (from the command line, or, if there\n * are no arguments on the command line, from stdin) then run a time test by\n * reading each file by row or by image (possibly with transforms in the latter\n * case).  The only output is a time as a floating point number of seconds with\n * 9 decimal digits.\n */\n#define _POSIX_C_SOURCE 199309L /* for clock_gettime */\n\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <errno.h>\n#include <limits.h>\n\n#include <time.h>\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n/* The following is to support direct compilation of this file as C++ */\n#ifdef __cplusplus\n#  define voidcast(type, value) static_cast<type>(value)\n#else\n#  define voidcast(type, value) (value)\n#endif /* __cplusplus */\n\n/* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime.  It\n * need not be supported even when clock_gettime is available.  It returns the\n * 'CPU' time the process has consumed.  'CPU' time is assumed to include time\n * when the CPU is actually blocked by a pending cache fill but not time\n * waiting for page faults.  The attempt is to get a measure of the actual time\n * the implementation takes to read a PNG ignoring the potentially very large IO\n * overhead.\n */\n#if defined (CLOCK_PROCESS_CPUTIME_ID) && defined(PNG_STDIO_SUPPORTED) &&\\\n    defined(PNG_EASY_ACCESS_SUPPORTED) &&\\\n    (PNG_LIBPNG_VER >= 10700 ? defined(PNG_READ_PNG_SUPPORTED) :\\\n     defined (PNG_SEQUENTIAL_READ_SUPPORTED) &&\\\n     defined(PNG_INFO_IMAGE_SUPPORTED))\n\ntypedef struct\n{\n   FILE *input;\n   FILE *output;\n}  io_data;\n\nstatic PNG_CALLBACK(void, read_and_copy,\n      (png_structp png_ptr, png_bytep buffer, png_size_t cb))\n{\n   io_data *io = (io_data*)png_get_io_ptr(png_ptr);\n\n   if (fread(buffer, cb, 1, io->input) != 1)\n      png_error(png_ptr, strerror(errno));\n\n   if (fwrite(buffer, cb, 1, io->output) != 1)\n   {\n      perror(\"temporary file\");\n      fprintf(stderr, \"temporary file PNG write failed\\n\");\n      exit(1);\n   }\n}\n\nstatic void read_by_row(png_structp png_ptr, png_infop info_ptr,\n      FILE *write_ptr, FILE *read_ptr)\n{\n   /* These don't get freed on error, this is fine; the program immediately\n    * exits.\n    */\n   png_bytep row = NULL, display = NULL;\n   io_data io_copy;\n\n   if (write_ptr != NULL)\n   {\n      /* Set up for a copy to the temporary file: */\n      io_copy.input = read_ptr;\n      io_copy.output = write_ptr;\n      png_set_read_fn(png_ptr, &io_copy, read_and_copy);\n   }\n\n   png_read_info(png_ptr, info_ptr);\n\n   {\n      png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n\n      row = voidcast(png_bytep,malloc(rowbytes));\n      display = voidcast(png_bytep,malloc(rowbytes));\n\n      if (row == NULL || display == NULL)\n         png_error(png_ptr, \"OOM allocating row buffers\");\n\n      {\n         png_uint_32 height = png_get_image_height(png_ptr, info_ptr);\n         int passes = png_set_interlace_handling(png_ptr);\n         int pass;\n\n         png_start_read_image(png_ptr);\n\n         for (pass = 0; pass < passes; ++pass)\n         {\n            png_uint_32 y = height;\n\n            /* NOTE: this trashes the row each time; interlace handling won't\n             * work, but this avoids memory thrashing for speed testing and is\n             * somewhat representative of an application that works row-by-row.\n             */\n            while (y-- > 0)\n               png_read_row(png_ptr, row, display);\n         }\n      }\n   }\n\n   /* Make sure to read to the end of the file: */\n   png_read_end(png_ptr, info_ptr);\n\n   /* Free this up: */\n   free(row);\n   free(display);\n}\n\nstatic PNG_CALLBACK(void, no_warnings, (png_structp png_ptr,\n         png_const_charp warning))\n{\n   (void)png_ptr;\n   (void)warning;\n}\n\nstatic int read_png(FILE *fp, png_int_32 transforms, FILE *write_file)\n{\n   png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,0,0,\n         no_warnings);\n   png_infop info_ptr = NULL;\n\n   if (png_ptr == NULL)\n      return 0;\n\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n      return 0;\n   }\n\n#  ifdef PNG_BENIGN_ERRORS_SUPPORTED\n      png_set_benign_errors(png_ptr, 1/*allowed*/);\n#  endif\n   png_init_io(png_ptr, fp);\n\n   info_ptr = png_create_info_struct(png_ptr);\n\n   if (info_ptr == NULL)\n      png_error(png_ptr, \"OOM allocating info structure\");\n\n   if (transforms < 0)\n      read_by_row(png_ptr, info_ptr, write_file, fp);\n\n   else\n      png_read_png(png_ptr, info_ptr, transforms, NULL/*params*/);\n\n   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n   return 1;\n}\n\nstatic int mytime(struct timespec *t)\n{\n   /* Do the timing using clock_gettime and the per-process timer. */\n   if (!clock_gettime(CLOCK_PROCESS_CPUTIME_ID, t))\n      return 1;\n\n   perror(\"CLOCK_PROCESS_CPUTIME_ID\");\n   fprintf(stderr, \"timepng: could not get the time\\n\");\n   return 0;\n}\n\nstatic int perform_one_test(FILE *fp, int nfiles, png_int_32 transforms)\n{\n   int i;\n   struct timespec before, after;\n\n   /* Clear out all errors: */\n   rewind(fp);\n\n   if (mytime(&before))\n   {\n      for (i=0; i<nfiles; ++i)\n      {\n         if (read_png(fp, transforms, NULL/*write*/))\n         {\n            if (ferror(fp))\n            {\n               perror(\"temporary file\");\n               fprintf(stderr, \"file %d: error reading PNG data\\n\", i);\n               return 0;\n            }\n         }\n\n         else\n         {\n            perror(\"temporary file\");\n            fprintf(stderr, \"file %d: error from libpng\\n\", i);\n            return 0;\n         }\n      }\n   }\n\n   else\n      return 0;\n\n   if (mytime(&after))\n   {\n      /* Work out the time difference and print it - this is the only output,\n       * so flush it immediately.\n       */\n      unsigned long s = after.tv_sec - before.tv_sec;\n      long ns = after.tv_nsec - before.tv_nsec;\n\n      if (ns < 0)\n      {\n         --s;\n         ns += 1000000000;\n\n         if (ns < 0)\n         {\n            fprintf(stderr, \"timepng: bad clock from kernel\\n\");\n            return 0;\n         }\n      }\n\n      printf(\"%lu.%.9ld\\n\", s, ns);\n      fflush(stdout);\n      if (ferror(stdout))\n      {\n         fprintf(stderr, \"timepng: error writing output\\n\");\n         return 0;\n      }\n\n      /* Successful return */\n      return 1;\n   }\n\n   else\n      return 0;\n}\n\nstatic int add_one_file(FILE *fp, char *name)\n{\n   FILE *ip = fopen(name, \"rb\");\n\n   if (ip != NULL)\n   {\n      /* Read the file using libpng; this detects errors and also deals with\n       * files which contain data beyond the end of the file.\n       */\n      int ok = 0;\n      fpos_t pos;\n\n      if (fgetpos(fp, &pos))\n      {\n         /* Fatal error reading the start: */\n         perror(\"temporary file\");\n         fprintf(stderr, \"temporary file fgetpos error\\n\");\n         exit(1);\n      }\n\n      if (read_png(ip, -1/*by row*/, fp/*output*/))\n      {\n         if (ferror(ip))\n         {\n            perror(name);\n            fprintf(stderr, \"%s: read error\\n\", name);\n         }\n\n         else\n            ok = 1; /* read ok */\n      }\n\n      else\n         fprintf(stderr, \"%s: file not added\\n\", name);\n\n      (void)fclose(ip);\n\n      /* An error in the output is fatal; exit immediately: */\n      if (ferror(fp))\n      {\n         perror(\"temporary file\");\n         fprintf(stderr, \"temporary file write error\\n\");\n         exit(1);\n      }\n\n      if (ok)\n         return 1;\n\n      /* Did not read the file successfully, simply rewind the temporary\n       * file.  This must happen after the ferror check above to avoid clearing\n       * the error.\n       */\n      if (fsetpos(fp, &pos))\n      {\n         perror(\"temporary file\");\n         fprintf(stderr, \"temporary file fsetpos error\\n\");\n         exit(1);\n      }\n   }\n\n   else\n   {\n      /* file open error: */\n      perror(name);\n      fprintf(stderr, \"%s: open failed\\n\", name);\n   }\n\n   return 0; /* file not added */\n}\n\nstatic void\nusage(FILE *fp)\n{\n   if (fp != NULL) fclose(fp);\n\n   fprintf(stderr,\n\"Usage:\\n\"\n\" timepng --assemble <assembly> {files}\\n\"\n\"  Read the files into <assembly>, output the count.  Options are ignored.\\n\"\n\" timepng --dissemble <assembly> <count> [options]\\n\"\n\"  Time <count> files from <assembly>, additional files may not be given.\\n\"\n\" Otherwise:\\n\"\n\"  Read the files into a temporary file and time the decode\\n\"\n\"Transforms:\\n\"\n\"  --by-image: read by image with png_read_png\\n\"\n\"  --<transform>: implies by-image, use PNG_TRANSFORM_<transform>\\n\"\n\"  Otherwise: read by row using png_read_row (to a single row buffer)\\n\"\n   /* ISO C90 string length max 509 */);fprintf(stderr,\n\"{files}:\\n\"\n\"  PNG files to copy into the assembly and time.  Invalid files are skipped\\n\"\n\"  with appropriate error messages.  If no files are given the list of files\\n\"\n\"  is read from stdin with each file name terminated by a newline\\n\"\n\"Output:\\n\"\n\"  For --assemble the output is the name of the assembly file followed by the\\n\"\n\"  count of the files it contains; the arguments for --dissemble.  Otherwise\\n\"\n\"  the output is the total decode time in seconds.\\n\");\n\n   exit(99);\n}\n\nint main(int argc, char **argv)\n{\n   int ok = 0;\n   int err = 0;\n   int nfiles = 0;\n   int transforms = -1; /* by row */\n   const char *assembly = NULL;\n   FILE *fp;\n\n   if (argc > 2 && strcmp(argv[1], \"--assemble\") == 0)\n   {\n      /* Just build the test file, argv[2] is the file name. */\n      assembly = argv[2];\n      fp = fopen(assembly, \"wb\");\n      if (fp == NULL)\n      {\n         perror(assembly);\n         fprintf(stderr, \"timepng --assemble %s: could not open for write\\n\",\n               assembly);\n         usage(NULL);\n      }\n\n      argv += 2;\n      argc -= 2;\n   }\n\n   else if (argc > 3 && strcmp(argv[1], \"--dissemble\") == 0)\n   {\n      fp = fopen(argv[2], \"rb\");\n\n      if (fp == NULL)\n      {\n         perror(argv[2]);\n         fprintf(stderr, \"timepng --dissemble %s: could not open for read\\n\",\n               argv[2]);\n         usage(NULL);\n      }\n\n      nfiles = atoi(argv[3]);\n      if (nfiles <= 0)\n      {\n         fprintf(stderr,\n               \"timepng --dissemble <file> <count>: %s is not a count\\n\",\n               argv[3]);\n         exit(99);\n      }\n#ifdef __COVERITY__\n      else\n      {\n         nfiles &= PNG_UINT_31_MAX;\n      }\n#endif\n\n      argv += 3;\n      argc -= 3;\n   }\n\n   else /* Else use a temporary file */\n   {\n#ifndef __COVERITY__\n      fp = tmpfile();\n#else\n      /* Experimental. Coverity says tmpfile() is insecure because it\n       * generates predictable names.\n       *\n       * It is possible to satisfy Coverity by using mkstemp(); however,\n       * any platform supporting mkstemp() undoubtedly has a secure tmpfile()\n       * implementation as well, and doesn't need the fix.  Note that\n       * the fix won't work on platforms that don't support mkstemp().\n       *\n       * https://www.securecoding.cert.org/confluence/display/c/\n       * FIO21-C.+Do+not+create+temporary+files+in+shared+directories\n       * says that most historic implementations of tmpfile() provide\n       * only a limited number of possible temporary file names\n       * (usually 26) before file names are recycled. That article also\n       * provides a secure solution that unfortunately depends upon mkstemp().\n       */\n      char tmpfile[] = \"timepng-XXXXXX\";\n      int filedes;\n      umask(0177);\n      filedes = mkstemp(tmpfile);\n      if (filedes < 0)\n        fp = NULL;\n      else\n      {\n        fp = fdopen(filedes,\"w+\");\n        /* Hide the filename immediately and ensure that the file does\n         * not exist after the program ends\n         */\n        (void) unlink(tmpfile);\n      }\n#endif\n\n      if (fp == NULL)\n      {\n         perror(\"tmpfile\");\n         fprintf(stderr, \"timepng: could not open the temporary file\\n\");\n         exit(1); /* not a user error */\n      }\n   }\n\n   /* Handle the transforms: */\n   while (argc > 1 && argv[1][0] == '-' && argv[1][1] == '-')\n   {\n      const char *opt = *++argv + 2;\n\n      --argc;\n\n      /* Transforms turn on the by-image processing and maybe set some\n       * transforms:\n       */\n      if (transforms == -1)\n         transforms = PNG_TRANSFORM_IDENTITY;\n\n      if (strcmp(opt, \"by-image\") == 0)\n      {\n         /* handled above */\n      }\n\n#        define OPT(name) else if (strcmp(opt, #name) == 0)\\\n         transforms |= PNG_TRANSFORM_ ## name\n\n      OPT(STRIP_16);\n      OPT(STRIP_ALPHA);\n      OPT(PACKING);\n      OPT(PACKSWAP);\n      OPT(EXPAND);\n      OPT(INVERT_MONO);\n      OPT(SHIFT);\n      OPT(BGR);\n      OPT(SWAP_ALPHA);\n      OPT(SWAP_ENDIAN);\n      OPT(INVERT_ALPHA);\n      OPT(STRIP_FILLER);\n      OPT(STRIP_FILLER_BEFORE);\n      OPT(STRIP_FILLER_AFTER);\n      OPT(GRAY_TO_RGB);\n      OPT(EXPAND_16);\n      OPT(SCALE_16);\n\n      else\n      {\n         fprintf(stderr, \"timepng %s: unrecognized transform\\n\", opt);\n         usage(fp);\n      }\n   }\n\n   /* Handle the files: */\n   if (argc > 1 && nfiles > 0)\n      usage(fp); /* Additional files not valid with --dissemble */\n\n   else if (argc > 1)\n   {\n      int i;\n\n      for (i=1; i<argc; ++i)\n      {\n         if (nfiles == INT_MAX)\n         {\n            fprintf(stderr, \"%s: skipped, too many files\\n\", argv[i]);\n            break;\n         }\n\n         else if (add_one_file(fp, argv[i]))\n            ++nfiles;\n      }\n   }\n\n   else if (nfiles == 0) /* Read from stdin withoout --dissemble */\n   {\n      char filename[FILENAME_MAX+1];\n\n      while (fgets(filename, FILENAME_MAX+1, stdin))\n      {\n         size_t len = strlen(filename);\n\n         if (filename[len-1] == '\\n')\n         {\n            filename[len-1] = 0;\n            if (nfiles == INT_MAX)\n            {\n               fprintf(stderr, \"%s: skipped, too many files\\n\", filename);\n               break;\n            }\n\n            else if (add_one_file(fp, filename))\n               ++nfiles;\n         }\n\n         else\n         {\n            fprintf(stderr, \"timepng: file name too long: ...%s\\n\",\n               filename+len-32);\n            err = 1;\n            break;\n         }\n      }\n\n      if (ferror(stdin))\n      {\n         fprintf(stderr, \"timepng: stdin: read error\\n\");\n         err = 1;\n      }\n   }\n\n   /* Perform the test, or produce the --assemble output: */\n   if (!err)\n   {\n      if (nfiles > 0)\n      {\n         if (assembly != NULL)\n         {\n            if (fflush(fp) && !ferror(fp) && fclose(fp))\n            {\n               perror(assembly);\n               fprintf(stderr, \"%s: close failed\\n\", assembly);\n            }\n\n            else\n            {\n               printf(\"%s %d\\n\", assembly, nfiles);\n               fflush(stdout);\n               ok = !ferror(stdout);\n            }\n         }\n\n         else\n         {\n            ok = perform_one_test(fp, nfiles, transforms);\n            (void)fclose(fp);\n         }\n      }\n\n      else\n         usage(fp);\n   }\n\n   else\n      (void)fclose(fp);\n\n   /* Exit code 0 on success. */\n   return ok == 0;\n}\n#else /* !sufficient support */\nint main(void) { return 77; }\n#endif /* !sufficient support */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/mips-msa/README",
    "content": "OPERATING SYSTEM SPECIFIC MIPS MSA DETECTION\n--------------------------------------------\n\nDetection of the ability to execute MIPS MSA on an MIPS processor requires\noperating system support.  (The information is not available in user mode.)\n\nHOW TO USE THIS\n---------------\n\nThis directory contains C code fragments that can be included in mips/mips_init.c\nby setting the macro PNG_MIPS_MSA_FILE to the file name in \"\" or <> at build\ntime.  This setting is not recorded in pnglibconf.h and can be changed simply by\nrebuilding mips/msa_init.o with the required macro definition.\n\nFor any of this code to be used the MIPS MSA code must be enabled and run time\nchecks must be supported.  I.e.:\n\n#if PNG_MIPS_MSA_OPT > 0\n#ifdef PNG_MIPS_MSA_CHECK_SUPPORTED\n\nThis is done in a 'configure' build by passing configure the argument:\n\n   --enable-mips-msa=check\n\nApart from the basic Linux implementation in contrib/mips-msa/linux.c this code\nis unsupported.  That means that it is not even compiled on a regular basis and\nmay be broken in any given minor release.\n\nFILE FORMAT\n-----------\n\nEach file documents its testing status as of the last time it was tested (which\nmay have been a long time ago):\n\nSTATUS: one of:\n   SUPPORTED: This indicates that the file is included in the regularly\n         performed test builds and bugs are fixed when discovered.\n   COMPILED: This indicates that the code did compile at least once.  See the\n         more detailed description for the extent to which the result was\n         successful.\n   TESTED: This means the code was fully compiled into the libpng test programs\n         and these were run at least once.\n\nBUG REPORTS: an email address to which to send reports of problems\n\nThe file is a fragment of C code. It should not define any 'extern' symbols;\neverything should be static.  It must define the function:\n\nstatic int png_have_msa(png_structp png_ptr);\n\nThat function must return 1 if MIPS MSA instructions are supported, 0 if not.\nIt must not execute png_error unless it detects a bug.  A png_error will prevent\nthe reading of the PNG and in the future, writing too.\n\nBUG REPORTS\n-----------\n\nIf you mail a bug report for any file that is not SUPPORTED there may only be\nlimited response.  Consider fixing it and sending a patch to fix the problem -\nthis is more likely to result in action.\n\nCONTRIBUTIONS\n-------------\n\nYou may send contributions of new implementations to\npng-mng-implement@sourceforge.net.  Please write code in strict C90 C where\npossible.  Obviously OS dependencies are to be expected.  If you submit code you\nmust have the authors permission and it must have a license that is acceptable\nto the current maintainer; in particular that license must permit modification\nand redistribution.\n\nPlease try to make the contribution a single file and give the file a clear and\nunambiguous name that identifies the target OS.  If multiple files really are\nrequired put them all in a sub-directory.\n\nYou must also be prepared to handle bug reports from users of the code, either\nby joining the png-mng-implement mailing list or by providing an email for the\n\"BUG REPORTS\" entry or both.  Please make sure that the header of the file\ncontains the STATUS and BUG REPORTS fields as above.\n\nPlease list the OS requirements as precisely as possible.  Ideally you should\nalso list the environment in which the code has been tested and certainly list\nany environments where you suspect it might not work.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/mips-msa/linux.c",
    "content": "/* contrib/mips-msa/linux.c\n *\n * Copyright (c) 2016 Glenn Randers-Pehrson\n * Written by Mandar Sahastrabuddhe, 2016.\n * Last changed in libpng 1.6.25beta03 [August 29, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * SEE contrib/mips-msa/README before reporting bugs\n *\n * STATUS: SUPPORTED\n * BUG REPORTS: png-mng-implement@sourceforge.net\n *\n * png_have_msa implemented for Linux by reading the widely available\n * pseudo-file /proc/cpuinfo.\n *\n * This code is strict ANSI-C and is probably moderately portable; it does\n * however use <stdio.h> and it assumes that /proc/cpuinfo is never localized.\n */\n\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n\nstatic int\npng_have_msa(png_structp png_ptr)\n{\n   FILE *f = fopen(\"/proc/cpuinfo\", \"rb\");\n\n   char *string = \"msa\";\n   char word[10];\n\n   if (f != NULL)\n   {\n      while(!feof(f))\n      {\n         int ch = fgetc(f);\n         static int i = 0;\n\n         while(!(ch <= 32))\n         {\n            word[i++] = ch;\n            ch = fgetc(f);\n         }\n\n         int val = strcmp(string, word);\n\n         if (val == 0)\n            return 1;\n\n         i = 0;\n         memset(word, 0, 10);\n      }\n\n      fclose(f);\n   }\n#ifdef PNG_WARNINGS_SUPPORTED\n   else\n      png_warning(png_ptr, \"/proc/cpuinfo open failed\");\n#endif\n   return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/README",
    "content": "\nThis demonstrates the use of PNG_USER_CONFIG, pngusr.h and pngusr.dfa\nto build minimal decoder, encoder, and progressive reader applications.\n\nSee the individual README and pngusr.dfa files for more explanation.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/decoder/README",
    "content": "This demonstrates the use of PNG_USER_CONFIG, pngusr.h and pngusr.dfa\n\nThe makefile builds a minimal read-only decoder with embedded libpng\nand zlib.\n\nSpecify the location of the zlib source (1.2.1 or later) as ZLIBSRC\non the make command line.\n\nIf you prefer to use the shared libraries, go to contrib/pngminus\nand build the png2pnm application there.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/decoder/pngusr.dfa",
    "content": "# pngminim/decoder/pngusr.dfa\n#\n# Copyright (c) 2010-2013 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# First all the build options off:\n\neverything = off\n\n# All that is required is some read code. This example switches\n# on the sequential read code (see ../preader for a progressive\n# read example).\n\noption SEQUENTIAL_READ on\n\n# You must choose fixed or floating point arithmetic:\n# option FLOATING_POINT on\n\noption FIXED_POINT on\n\n# You must chose the internal fixed point implementation or to\n# use the system floating point.  The latter is considerably\n# smaller (by about 1kbyte on an x86 system):\n# option FLOATING_ARITHMETIC on\n\noption FLOATING_ARITHMETIC off\n\n# Your program will probably need other options.  The example\n# program here, pngm2pnm, requires the following.  Take a look\n# at pnglibconf.h to find out the full set of what has to be\n# enabled to make the following work.\n\noption SETJMP on\noption STDIO on\noption READ_EXPAND on\noption READ_STRIP_16_TO_8 on\noption USER_LIMITS on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/decoder/pngusr.h",
    "content": "/* minrdpngconf.h: headers to make a minimal png-read-only library\n *\n * Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson\n */\n\n#ifndef MINRDPNGCONF_H\n#define MINRDPNGCONF_H\n\n/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */\n\n/* List options to turn off features of the build that do not\n * affect the API (so are not recorded in pnglibconf.h)\n */\n\n#define PNG_ALIGN_TYPE PNG_ALIGN_NONE\n\n#endif /* MINRDPNGCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/encoder/README",
    "content": "This demonstrates the use of PNG_USER_CONFIG and pngusr.h\n\nThe makefile builds a minimal write-only encoder with embedded libpng\nand zlib.\n\nSpecify the location of the zlib source (1.2.1 or later) as ZLIBSRC\non the make command line.\n\nIf you prefer to use the shared libraries, go to contrib/pngminus\nand build the pnm2png application there.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/encoder/pngusr.dfa",
    "content": "# pngminim/encoder/pngusr.dfa\n#\n# Copyright (c) 2010-2013 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# First all the build options off:\n\neverything = off\n\n# Switch on the write code - this makes a minimalist encoder\n\noption WRITE on\n\n# These 2 options are required if you need to read PBM (P1 or P4) files.\noption WRITE_INVERT on\noption WRITE_PACK on\n\n# You must choose fixed or floating point arithmetic:\n# option FLOATING_POINT on\n\noption FIXED_POINT on\n\n# You must chose the internal fixed point implementation or to\n# use the system floating point.  The latter is considerably\n# smaller (by about 1kbyte on an x86 system):\n# option FLOATING_ARITHMETIC on\n\noption FLOATING_ARITHMETIC off\n\n# Your program will probably need other options.  The example\n# program here, pnm2pngm, requires the following.  Take a look\n# at pnglibconf.h to find out the full set of what has to be\n# enabled to make the following work.\n\noption SETJMP on\noption STDIO on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/encoder/pngusr.h",
    "content": "/* minwrpngconf.h: headers to make a minimal png-write-only library\n *\n * Copyright (c) 2007, 2010-2013 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson\n */\n\n#ifndef MINWRPNGCONF_H\n#define MINWRPNGCONF_H\n\n/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */\n\n/* List options to turn off features of the build that do not\n * affect the API (so are not recorded in pnglibconf.h)\n */\n\n#define PNG_ALIGN_TYPE PNG_ALIGN_NONE\n\n#endif /* MINWRPNGCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/preader/README",
    "content": "This demonstrates the use of PNG_USER_CONFIG and pngusr.h\n\nThe makefile builds a minimal read-only progressive decoder with\nembedded libpng, zlib and your system's X library.\n\nSpecify the location of the zlib source (1.2.1 or later) as ZLIBSRC\non the make command line.\n\nEdit makefile if required, to find your X library and include files,\nthen\n\n    make ZLIBSRC=directory\n\nIf you prefer to use the shared libraries, go to contrib/gregbook\nand build the rpng2-x application there.\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/preader/pngusr.dfa",
    "content": "# pngminim/preader/pngusr.dfa\n#\n# Copyright (c) 2010-2013 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# First all the build options off:\n\neverything = off\n\n# Just switch on the progressive read code\n\noption PROGRESSIVE_READ on\n\n# You may choose fixed or floating point APIs:\n# option FLOATING_POINT on\n\noption FIXED_POINT on\n\n# You must chose the internal fixed point implementation or to\n# use the system floating point.  The latter is considerably\n# smaller (by about 1kbyte on an x86 system):\n\noption FLOATING_ARITHMETIC on\n# option FLOATING_ARITHMETIC off\n\n# Your program will probably need other options.  The example\n# program here, rpng2-x, requires the following.  Take a look\n# at pnglibconf.h to find out the full set of what has to be\n# enabled to make the following work.\n\noption SETJMP on\noption STDIO on\noption READ_bKGD on\noption READ_GAMMA on\noption READ_EXPAND on\noption READ_STRIP_16_TO_8 on\noption READ_GRAY_TO_RGB on\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminim/preader/pngusr.h",
    "content": "/* minrdpngconf.h: headers to make a minimal png-read-only library\n *\n * Copyright (c) 2009, 2010-2013 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Derived from pngcrush.h, Copyright 1998-2007, Glenn Randers-Pehrson\n */\n\n#ifndef MINPRDPNGCONF_H\n#define MINPRDPNGCONF_H\n\n/* To include pngusr.h set -DPNG_USER_CONFIG in CPPFLAGS */\n\n/* List options to turn off features of the build that do not\n * affect the API (so are not recorded in pnglibconf.h)\n */\n\n#define PNG_ALIGN_TYPE PNG_ALIGN_NONE\n\n#endif /* MINPRDPNGCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/README",
    "content": "PngMinus\n--------\n(copyright Willem van Schaik, 1999)\n\n\nLicense\n-------\n\nPermission to use, copy, modify, and distribute this software and\nits documentation for any purpose and without fee is hereby granted,\nprovided that the above copyright notice appear in all copies and\nthat both that copyright notice and this permission notice appear in\nsupporting documentation. This software is provided \"as is\" without\nexpress or implied warranty.\n\n\nSome history\n------------\nSoon after the creation of PNG in 1995, the need was felt for a set of\npnmtopng / pngtopnm utilities. Independantly Alexander Lehmann and I\n(Willem van Schaik) started such a project. Luckily we discovered this\nand merged the two together into pnmtopng.tar.gz, which is available\nfrom a/o ftp://ftp.simplesystems.org/pub/libpng/png/.\n\nThese two utilities have many, many options and make use of most of the\nfeatures of PNG, like gamma, alpha, sbit, text-chunks, etc. This makes\nthe utilities quite complex and by now not anymore very maintainable.\nWhen we wrote these programs, libpng was still in an early stage.\nTherefore, lots of the functionality that we put in our software can now\nbe done using transform-functions in libpng.\n\nFinally, to compile these programs, you need to have installed and\ncompiled three libraries: libpng, zlib and netpbm. Especially the latter\nmakes the whole setup a bit bulky. But that's unavoidable given the many\nfeatures of pnmtopng.\n\n\nWhat now\n--------\nAt this moment libpng is in a very stable state and can do much of the\nwork done in pnmtopng. Also, pnmtopng needs to be upgraded to the new\ninterface of libpng. Hence, it is time for a rewrite from the ground up\nof pnmtopng and pngtopnm. This will happen in the near future (stay\ntuned). The new package will get a different name to distinguish it from\nthe old one: PngPlus.\n\nTo experiment a bit with the new interface of libpng, I started off with\na small prototype that contains only the basic functionality. It doesn't\nhave any of the options to read or write special chunks and it will do\nno gamma correction. But this makes it also a simple program that is\nquite easy to understand and can serve well as a template for other\nsoftware developments. (By now there are of course a couple of programs,\nlike Greg Roelofs' rpng/wpng, that can be used just as good.)\n\n\nCan and can not\n---------------\nAs this is the small brother of the future PngPlus, I called this fellow\nPngMinus. Because I started this development in good-old Turbo-C, I\navoided the use the netpbm library, which requires DOS extenders. Again,\nanother reason to call it PngMinus (minus netpbm :-). So, part of the\nprogram are some elementary routines to read / write pgm- and ppm-files.\nIt does not read b&w pbm-files.\n\nThe downside of this approach is that you can not use them on images\nthat require blocks of memory bigger than 64k (the DOS version). For\nlarger images you will get an out-of-memory error.\n\nAs said before, PngMinus doesn't correct for gamma. When reading\npng-files you can do this just as well by piping the output of png2pnm\nto pnmgamma, one of the standard PbmPlus tools. This same scenario will\nmost probably also be followed in the full-blown future PngPlus, with\nthe addition of course of the possibility to create gamma-chunks when\nwriting png-files.\n\nOn the other hand it supports alpha-channels. When reading a png-image\nyou can write the alpha-channel into a pgm-file. And when creating an\nRGB+A png-image, you just combine a ppm-file with a corresponding\npgm-file containing the alpha-channel. When reading, transparency chunks\nare converted into an alpha-channel and from there on treated the same\nway.\n\nFinally you can opt for writing ascii or binary pgm- and ppm-files. When\nthe bit-depth is 16, the format will always be ascii.\n\n\nUsing it\n--------\nTo distinguish them from pnmtopng and PngPlus, the utilities are named\npng2pnm and pnm2png (2 instead of to). The input- and output-files can\nbe given as parameters or through redirection. Therefore the programs\ncan be part of a pipe.\n\nTo list the options type \"png2pnm -h\" or \"pnm2png -h\".\n\n\nJust like Scandinavian furniture\n--------------------------------\nYou have to put it together yourself. I did test the software under\nMS-DOS with Turbo-C 3.0 and under RedHat Linux 4.2 with gcc. In both\ncases I used libpng-1.0.4 and zlib-1.1.3. Later versions should be OK,\nhowever some older libpng versions have a bug in pngmem.c when using\nTurbo-C 3.0 (see below).\n\nYou can build it using one of the two makefiles (make -f makefile.###)\nor use the batch/script files pngminus.bat / pngminus.sh. This assumes\nthat you have built the libraries in ../libpng and ../zlib. Using Linux,\nmake sure that you have built libpng with makefile.std and not\nmakefile.linux (also called .lnx in earlier versions of libpng). The\nlatter creates a .so shared-library, while the PngMinus makefile assumes\na normal .a static library.\n\nIf you create a ../pngsuite directory and then store the basn####.png\nfiles from PngSuite (http://www.schaik.com/pngsuite/) in there, you can\ntest in one go the proper functioning of PngMinus, see png2pnm.bat and\npnm2png.bat (or the .sh versions).\n\n\nWarranty\n-------\nPlease, remember that this was just a small experiment to learn a few\nthings. It will have many unforeseen features <vbg>. Who said bugs? Use\nit when you are in need for something simple or when you want to start\ndeveloping your own stuff.\n\n\nThe Turbo bug\n-------------\n** pngmem.old\n          hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);\n          hptr += 16L;\n** pngmem.c\n          hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);\n          hptr = hptr + 16L;\n**\n\n** pngmem.old\n          png_ptr->offset_table_ptr[i] = (png_bytep)hptr;\n          hptr += (png_uint_32)65536L;\n** pngmem.c\n          png_ptr->offset_table_ptr[i] = (png_bytep)hptr;\n          hptr = hptr + 65536L;\n**\n\n\nThe end\n-------\nWillem van Schaik\nmailto:willem@schaik.com\nhttp://www.schaik.com/png/\n-------\nOct 1999\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/makefile.std",
    "content": "# Makefile for PngMinus (png2pnm and pnm2png)\n# Linux / Unix\n\n#CC=cc\nCC=gcc\nLD=$(CC)\n\nRM=rm -f\n\n#PNGPATH = /usr/local\n#PNGINC = -I$(PNGPATH)/include/libpng16\n#PNGLIB = -L$(PNGPATH)/lib -lpng16\n#PNGLIBS = $(PNGPATH)/lib/libpng16.a\nPNGINC = -I../..\nPNGLIB = -L../.. -lpng\nPNGLIBS = ../../libpng.a\n\n#ZPATH = /usr/local\n#ZINC = -I$(ZPATH)/include\n#ZLIB = -L$(ZPATH)/lib -lz\n#ZLIBS = $(ZPATH)/lib/libz.a\nZINC = -I../../../zlib\nZLIB = -L../../../zlib -lz\nZLIBS = ../../../zlib/libz.a\n\nCPPFLAGS=$(PNGINC) $(ZINC)\nCFLAGS=\nLDLIBS=$(PNGLIB) $(ZLIB)\nLDLIBSS=$(PNGLIBS) $(ZLIBS)\nC=.c\nO=.o\nL=.a\nE=\n\n# dependencies\n\n#all: png2pnm$(E) pnm2png$(E)\nall: png2pnm$(E) pnm2png$(E) png2pnm-static$(E) pnm2png-static$(E)\n\npng2pnm$(O): png2pnm$(C)\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) png2pnm$(C)\n\npng2pnm$(E): png2pnm$(O)\n\t$(LD) $(LDFLAGS) -o png2pnm$(E) png2pnm$(O) $(LDLIBS) -lm\n\npng2pnm-static$(E): png2pnm$(O)\n\t$(LD) $(LDFLAGS) -o png2pnm-static$(E) png2pnm$(O) $(LDLIBSS) -lm\n\npnm2png$(O): pnm2png$(C)\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) pnm2png$(C)\n\npnm2png$(E): pnm2png$(O)\n\t$(LD) $(LDFLAGS) -o pnm2png$(E) pnm2png$(O) $(LDLIBS) -lm\n\npnm2png-static$(E): pnm2png$(O)\n\t$(LD) $(LDFLAGS) -o pnm2png-static$(E) pnm2png$(O) $(LDLIBSS) -lm\n\nclean:\n\t$(RM) png2pnm$(O)\n\t$(RM) pnm2png$(O)\n\t$(RM) png2pnm$(E)\n\t$(RM) pnm2png$(E)\n\t$(RM) png2pnm-static$(E)\n\t$(RM) pnm2png-static$(E)\n\n# End of makefile for png2pnm / pnm2png\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/makefile.tc3",
    "content": "# Makefile for PngMinus (png2pnm and pnm2png)\n# TurboC++ 3.0\n\nCC=tcc -Ic:\\tc3\\inc\nLD=tcc -Lc:\\tc3\\lib\nLB=tlib\nRM=del\nCP=copy\nMODEL=l\nCPPFLAGS=-I..\\libpng -I..\\zlib\nCFLAGS=-O -m$(MODEL)\nLDFLAGS=-m$(MODEL) -L..\\libpng -L..\\zlib\nC=.c\nO=.obj\nL=.lib\nE=.exe\n\n# dependencies\n\nall: png2pnm$(E) pnm2png$(E)\n\npng2pnm$(O): png2pnm$(C)\n        $(CC) -c $(CPPFLAGS) $(CFLAGS) png2pnm$(C)\n\npng2pnm$(E): png2pnm$(O)\n        $(LD) $(LDFLAGS) png2pnm$(O) libpng$(L) zlib$(L)\n\npnm2png$(O): pnm2png$(C)\n        $(CC) -c $(CPPFLAGS) $(CFLAGS) pnm2png$(C)\n\npnm2png$(E): pnm2png$(O)\n        $(LD) $(LDFLAGS) pnm2png$(O) libpng$(L) zlib$(L)\n\nclean:\n        $(RM) *$(O)\n        $(RM) *$(E)\n\n# End of makefile for png2pnm / pnm2png\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/makevms.com",
    "content": "$!------------------------------------------------------------------------------\n$! make Contrib programs of libpng under OpenVMS\n$!\n$!\n$! Look for the compiler used\n$!\n$ zlibsrc = \"[---.zlib]\"\n$ ccopt=\"/include=(''zlibsrc',[--])\"\n$ if f$getsyi(\"HW_MODEL\").ge.1024\n$ then\n$  ccopt = \"/prefix=all\"+ccopt\n$  comp  = \"__decc__=1\"\n$  if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$ else\n$  if f$search(\"SYS$SYSTEM:DECC$COMPILER.EXE\").eqs.\"\"\n$   then\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$    if f$search(\"SYS$SYSTEM:VAXC.EXE\").eqs.\"\"\n$     then\n$      comp  = \"__gcc__=1\"\n$      CC :== GCC\n$     else\n$      comp = \"__vaxc__=1\"\n$     endif\n$   else\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys decc$library_include:\n$    ccopt = \"/decc/prefix=all\"+ccopt\n$    comp  = \"__decc__=1\"\n$  endif\n$ endif\n$ open/write lopt lib.opt\n$ write lopt \"[--]libpng.olb/lib\"\n$ write lopt \"''zlibsrc'libz.olb/lib\"\n$ close lopt\n$ open/write xopt x11.opt\n$ write xopt \"sys$library:decw$xlibshr.exe/share\"\n$ close xopt\n$ write sys$output \"Compiling PNG contrib programs ...\"\n$   write sys$output \"Building pnm2png...\"\n$   CALL MAKE pnm2png.OBJ \"cc ''CCOPT' pnm2png\" -\n\tpnm2png.c\n$   call make pnm2png.exe -\n\t\"LINK pnm2png,lib.opt/opt\" -\n\tpnm2png.obj\n$   write sys$output \"Building png2pnm...\"\n$   CALL MAKE png2pnm.OBJ \"cc ''CCOPT' png2pnm\" -\n\tpng2pnm.c\n$   call make png2pnm.exe -\n\t\"LINK png2pnm,lib.opt/opt\" -\n\tpng2pnm.obj\n$ exit\n$!\n$!\n$MAKE: SUBROUTINE   !SUBROUTINE TO CHECK DEPENDENCIES\n$ V = 'F$Verify(0)\n$! P1 = What we are trying to make\n$! P2 = Command to make it\n$! P3 - P8  What it depends on\n$\n$ If F$Search(P1) .Eqs. \"\" Then Goto Makeit\n$ Time = F$CvTime(F$File(P1,\"RDT\"))\n$arg=3\n$Loop:\n$       Argument = P'arg\n$       If Argument .Eqs. \"\" Then Goto Exit\n$       El=0\n$Loop2:\n$       File = F$Element(El,\" \",Argument)\n$       If File .Eqs. \" \" Then Goto Endl\n$       AFile = \"\"\n$Loop3:\n$       OFile = AFile\n$       AFile = F$Search(File)\n$       If AFile .Eqs. \"\" .Or. AFile .Eqs. OFile Then Goto NextEl\n$       If F$CvTime(F$File(AFile,\"RDT\")) .Ges. Time Then Goto Makeit\n$       Goto Loop3\n$NextEL:\n$       El = El + 1\n$       Goto Loop2\n$EndL:\n$ arg=arg+1\n$ If arg .Le. 8 Then Goto Loop\n$ Goto Exit\n$\n$Makeit:\n$ VV=F$VERIFY(0)\n$ write sys$output P2\n$ 'P2\n$ VV='F$Verify(VV)\n$Exit:\n$ If V Then Set Verify\n$ENDSUBROUTINE\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/png2pnm.bat",
    "content": "REM -- grayscale\npng2pnm.exe -noraw ..\\pngsuite\\basn0g01.png basn0g01.pgm\npng2pnm.exe -noraw ..\\pngsuite\\basn0g02.png basn0g02.pgm\npng2pnm.exe -noraw ..\\pngsuite\\basn0g04.png basn0g04.pgm\npng2pnm.exe -noraw ..\\pngsuite\\basn0g08.png basn0g08.pgm\npng2pnm.exe -noraw ..\\pngsuite\\basn0g16.png basn0g16.pgm\nREM -- full-color\npng2pnm.exe -noraw ..\\pngsuite\\basn2c08.png basn2c08.ppm\npng2pnm.exe -noraw ..\\pngsuite\\basn2c16.png basn2c16.ppm\nREM -- palletted\npng2pnm.exe -noraw ..\\pngsuite\\basn3p01.png basn3p01.ppm\npng2pnm.exe -noraw ..\\pngsuite\\basn3p02.png basn3p02.ppm\npng2pnm.exe -noraw ..\\pngsuite\\basn3p04.png basn3p04.ppm\npng2pnm.exe -noraw ..\\pngsuite\\basn3p08.png basn3p08.ppm\nREM -- gray with alpha-channel\npng2pnm.exe -noraw ..\\pngsuite\\basn4a08.png basn4a08.pgm\npng2pnm.exe -noraw ..\\pngsuite\\basn4a16.png basn4a16.pgm\nREM -- color with alpha-channel\npng2pnm.exe -noraw -alpha basn6a08.pgm ..\\pngsuite\\basn6a08.png basn6a08.ppm\npng2pnm.exe -noraw -alpha basn6a16.pgm ..\\pngsuite\\basn6a16.png basn6a16.ppm\nREM -- grayscale\npng2pnm.exe -raw ..\\pngsuite\\basn0g01.png rawn0g01.pgm\npng2pnm.exe -raw ..\\pngsuite\\basn0g02.png rawn0g02.pgm\npng2pnm.exe -raw ..\\pngsuite\\basn0g04.png rawn0g04.pgm\npng2pnm.exe -raw ..\\pngsuite\\basn0g08.png rawn0g08.pgm\npng2pnm.exe -raw ..\\pngsuite\\basn0g16.png rawn0g16.pgm\nREM -- full-color\npng2pnm.exe -raw ..\\pngsuite\\basn2c08.png rawn2c08.ppm\npng2pnm.exe -raw ..\\pngsuite\\basn2c16.png rawn2c16.ppm\nREM -- palletted\npng2pnm.exe -raw ..\\pngsuite\\basn3p01.png rawn3p01.ppm\npng2pnm.exe -raw ..\\pngsuite\\basn3p02.png rawn3p02.ppm\npng2pnm.exe -raw ..\\pngsuite\\basn3p04.png rawn3p04.ppm\npng2pnm.exe -raw ..\\pngsuite\\basn3p08.png rawn3p08.ppm\nREM -- gray with alpha-channel\npng2pnm.exe -raw ..\\pngsuite\\basn4a08.png rawn4a08.pgm\npng2pnm.exe -raw ..\\pngsuite\\basn4a16.png rawn4a16.pgm\nREM -- color with alpha-channel\npng2pnm.exe -noraw -alpha rawn6a08.pgm ..\\pngsuite\\basn6a08.png rawn6a08.ppm\npng2pnm.exe -noraw -alpha rawn6a16.pgm ..\\pngsuite\\basn6a16.png rawn6a16.ppm\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/png2pnm.c",
    "content": "/*\n *  png2pnm.c --- conversion from PNG-file to PGM/PPM-file\n *  copyright (C) 1999 by Willem van Schaik <willem@schaik.com>\n *\n *  version 1.0 - 1999.10.15 - First version.\n *\n *  Permission to use, copy, modify, and distribute this software and\n *  its documentation for any purpose and without fee is hereby granted,\n *  provided that the above copyright notice appear in all copies and\n *  that both that copyright notice and this permission notice appear in\n *  supporting documentation. This software is provided \"as is\" without\n *  express or implied warranty.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#ifdef __TURBOC__\n#include <mem.h>\n#include <fcntl.h>\n#endif\n#include <zlib.h>\n\n#ifndef BOOL\n#define BOOL unsigned char\n#endif\n#ifndef TRUE\n#define TRUE (BOOL) 1\n#endif\n#ifndef FALSE\n#define FALSE (BOOL) 0\n#endif\n\n#ifdef __TURBOC__\n#define STDIN  0\n#define STDOUT 1\n#define STDERR 2\n#endif\n\n/* to make png2pnm verbose so we can find problems (needs to be before png.h) */\n#ifndef PNG_DEBUG\n#define PNG_DEBUG 0\n#endif\n\n#include \"png.h\"\n\n/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */\n#ifndef png_jmpbuf\n#  define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)\n#endif\n\n/* function prototypes */\n\nint  main (int argc, char *argv[]);\nvoid usage ();\nBOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file, BOOL raw,\n   BOOL alpha);\n\n/*\n *  main\n */\n\nint main(int argc, char *argv[])\n{\n  FILE *fp_rd = stdin;\n  FILE *fp_wr = stdout;\n  FILE *fp_al = NULL;\n  BOOL raw = TRUE;\n  BOOL alpha = FALSE;\n  int argi;\n\n  for (argi = 1; argi < argc; argi++)\n  {\n    if (argv[argi][0] == '-')\n    {\n      switch (argv[argi][1])\n      {\n        case 'n':\n          raw = FALSE;\n          break;\n        case 'r':\n          raw = TRUE;\n          break;\n        case 'a':\n          alpha = TRUE;\n          argi++;\n          if ((fp_al = fopen (argv[argi], \"wb\")) == NULL)\n          {\n            fprintf (stderr, \"PNM2PNG\\n\");\n            fprintf (stderr, \"Error:  can not create alpha-channel file %s\\n\",\n               argv[argi]);\n            exit (1);\n          }\n          break;\n        case 'h':\n        case '?':\n          usage();\n          exit(0);\n          break;\n        default:\n          fprintf (stderr, \"PNG2PNM\\n\");\n          fprintf (stderr, \"Error:  unknown option %s\\n\", argv[argi]);\n          usage();\n          exit(1);\n          break;\n      } /* end switch */\n    }\n    else if (fp_rd == stdin)\n    {\n      if ((fp_rd = fopen (argv[argi], \"rb\")) == NULL)\n      {\n             fprintf (stderr, \"PNG2PNM\\n\");\n            fprintf (stderr, \"Error:  file %s does not exist\\n\", argv[argi]);\n            exit (1);\n      }\n    }\n    else if (fp_wr == stdout)\n    {\n      if ((fp_wr = fopen (argv[argi], \"wb\")) == NULL)\n      {\n        fprintf (stderr, \"PNG2PNM\\n\");\n        fprintf (stderr, \"Error:  can not create file %s\\n\", argv[argi]);\n        exit (1);\n      }\n    }\n    else\n    {\n      fprintf (stderr, \"PNG2PNM\\n\");\n      fprintf (stderr, \"Error:  too many parameters\\n\");\n      usage();\n      exit(1);\n    }\n  } /* end for */\n\n#ifdef __TURBOC__\n  /* set stdin/stdout if required to binary */\n  if (fp_rd == stdin)\n  {\n    setmode (STDIN, O_BINARY);\n  }\n  if ((raw) && (fp_wr == stdout))\n  {\n    setmode (STDOUT, O_BINARY);\n  }\n#endif\n\n  /* call the conversion program itself */\n  if (png2pnm (fp_rd, fp_wr, fp_al, raw, alpha) == FALSE)\n  {\n    fprintf (stderr, \"PNG2PNM\\n\");\n    fprintf (stderr, \"Error:  unsuccessful conversion of PNG-image\\n\");\n    exit(1);\n  }\n\n  /* close input file */\n  fclose (fp_rd);\n  /* close output file */\n  fclose (fp_wr);\n  /* close alpha file */\n  if (alpha)\n    fclose (fp_al);\n\n  return 0;\n}\n\n/*\n *  usage\n */\n\nvoid usage()\n{\n  fprintf (stderr, \"PNG2PNM\\n\");\n  fprintf (stderr, \"   by Willem van Schaik, 1999\\n\");\n#ifdef __TURBOC__\n  fprintf (stderr, \"   for Turbo-C and Borland-C compilers\\n\");\n#else\n  fprintf (stderr, \"   for Linux (and Unix) compilers\\n\");\n#endif\n  fprintf (stderr, \"Usage:  png2pnm [options] <file>.png [<file>.pnm]\\n\");\n  fprintf (stderr, \"   or:  ... | png2pnm [options]\\n\");\n  fprintf (stderr, \"Options:\\n\");\n  fprintf (stderr,\n     \"   -r[aw]   write pnm-file in binary format (P4/P5/P6) (default)\\n\");\n  fprintf (stderr, \"   -n[oraw] write pnm-file in ascii format (P1/P2/P3)\\n\");\n  fprintf (stderr,\n     \"   -a[lpha] <file>.pgm write PNG alpha channel as pgm-file\\n\");\n  fprintf (stderr, \"   -h | -?  print this help-information\\n\");\n}\n\n/*\n *  png2pnm\n */\n\nBOOL png2pnm (FILE *png_file, FILE *pnm_file, FILE *alpha_file,\n    volatile BOOL raw, BOOL alpha)\n{\n  png_struct    *png_ptr = NULL;\n  png_info        *info_ptr = NULL;\n  png_byte      buf[8];\n  png_byte      *png_pixels = NULL;\n  png_byte      **row_pointers = NULL;\n  png_byte      *pix_ptr = NULL;\n  png_uint_32   row_bytes;\n\n  png_uint_32   width;\n  png_uint_32   height;\n  int           bit_depth;\n  int           channels;\n  int           color_type;\n  int           alpha_present;\n  int           row, col;\n  int           ret;\n  int           i;\n  long          dep_16;\n\n  /* read and check signature in PNG file */\n  ret = fread (buf, 1, 8, png_file);\n  if (ret != 8)\n    return FALSE;\n\n  ret = png_sig_cmp (buf, 0, 8);\n  if (ret)\n    return FALSE;\n\n  /* create png and info structures */\n\n  png_ptr = png_create_read_struct (png_get_libpng_ver(NULL),\n    NULL, NULL, NULL);\n  if (!png_ptr)\n    return FALSE;   /* out of memory */\n\n  info_ptr = png_create_info_struct (png_ptr);\n  if (!info_ptr)\n  {\n    png_destroy_read_struct (&png_ptr, NULL, NULL);\n    return FALSE;   /* out of memory */\n  }\n\n  if (setjmp (png_jmpbuf(png_ptr)))\n  {\n    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);\n    return FALSE;\n  }\n\n  /* set up the input control for C streams */\n  png_init_io (png_ptr, png_file);\n  png_set_sig_bytes (png_ptr, 8);  /* we already read the 8 signature bytes */\n\n  /* read the file information */\n  png_read_info (png_ptr, info_ptr);\n\n  /* get size and bit-depth of the PNG-image */\n  png_get_IHDR (png_ptr, info_ptr,\n    &width, &height, &bit_depth, &color_type,\n    NULL, NULL, NULL);\n\n  /* set-up the transformations */\n\n  /* transform paletted images into full-color rgb */\n  if (color_type == PNG_COLOR_TYPE_PALETTE)\n    png_set_expand (png_ptr);\n  /* expand images to bit-depth 8 (only applicable for grayscale images) */\n  if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)\n    png_set_expand (png_ptr);\n  /* transform transparency maps into full alpha-channel */\n  if (png_get_valid (png_ptr, info_ptr, PNG_INFO_tRNS))\n    png_set_expand (png_ptr);\n\n#ifdef NJET\n  /* downgrade 16-bit images to 8-bit */\n  if (bit_depth == 16)\n    png_set_strip_16 (png_ptr);\n  /* transform grayscale images into full-color */\n  if (color_type == PNG_COLOR_TYPE_GRAY ||\n    color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n    png_set_gray_to_rgb (png_ptr);\n  /* only if file has a file gamma, we do a correction */\n  if (png_get_gAMA (png_ptr, info_ptr, &file_gamma))\n    png_set_gamma (png_ptr, (double) 2.2, file_gamma);\n#endif\n\n  /* all transformations have been registered; now update info_ptr data,\n   * get rowbytes and channels, and allocate image memory */\n\n  png_read_update_info (png_ptr, info_ptr);\n\n  /* get the new color-type and bit-depth (after expansion/stripping) */\n  png_get_IHDR (png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,\n    NULL, NULL, NULL);\n\n  /* check for 16-bit files */\n  if (bit_depth == 16)\n  {\n    raw = FALSE;\n#ifdef __TURBOC__\n    pnm_file->flags &= ~((unsigned) _F_BIN);\n#endif\n  }\n\n  /* calculate new number of channels and store alpha-presence */\n  if (color_type == PNG_COLOR_TYPE_GRAY)\n    channels = 1;\n  else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n    channels = 2;\n  else if (color_type == PNG_COLOR_TYPE_RGB)\n    channels = 3;\n  else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n    channels = 4;\n  else\n    channels = 0; /* should never happen */\n  alpha_present = (channels - 1) % 2;\n\n  /* check if alpha is expected to be present in file */\n  if (alpha && !alpha_present)\n  {\n    fprintf (stderr, \"PNG2PNM\\n\");\n    fprintf (stderr, \"Error:  PNG-file doesn't contain alpha channel\\n\");\n    exit (1);\n  }\n\n  /* row_bytes is the width x number of channels x (bit-depth / 8) */\n  row_bytes = png_get_rowbytes (png_ptr, info_ptr);\n\n  if ((png_pixels = (png_byte *)\n     malloc (row_bytes * height * sizeof (png_byte))) == NULL) {\n    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);\n    return FALSE;\n  }\n\n  if ((row_pointers = (png_byte **)\n     malloc (height * sizeof (png_bytep))) == NULL)\n  {\n    png_destroy_read_struct (&png_ptr, &info_ptr, NULL);\n    free (png_pixels);\n    png_pixels = NULL;\n    return FALSE;\n  }\n\n  /* set the individual row_pointers to point at the correct offsets */\n  for (i = 0; i < ((int) height); i++)\n    row_pointers[i] = png_pixels + i * row_bytes;\n\n  /* now we can go ahead and just read the whole image */\n  png_read_image (png_ptr, row_pointers);\n\n  /* read rest of file, and get additional chunks in info_ptr - REQUIRED */\n  png_read_end (png_ptr, info_ptr);\n\n  /* clean up after the read, and free any memory allocated - REQUIRED */\n  png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL);\n\n  /* write header of PNM file */\n\n  if ((color_type == PNG_COLOR_TYPE_GRAY) ||\n      (color_type == PNG_COLOR_TYPE_GRAY_ALPHA))\n  {\n    fprintf (pnm_file, \"%s\\n\", (raw) ? \"P5\" : \"P2\");\n    fprintf (pnm_file, \"%d %d\\n\", (int) width, (int) height);\n    fprintf (pnm_file, \"%ld\\n\", ((1L << (int) bit_depth) - 1L));\n  }\n  else if ((color_type == PNG_COLOR_TYPE_RGB) ||\n           (color_type == PNG_COLOR_TYPE_RGB_ALPHA))\n  {\n    fprintf (pnm_file, \"%s\\n\", (raw) ? \"P6\" : \"P3\");\n    fprintf (pnm_file, \"%d %d\\n\", (int) width, (int) height);\n    fprintf (pnm_file, \"%ld\\n\", ((1L << (int) bit_depth) - 1L));\n  }\n\n  /* write header of PGM file with alpha channel */\n\n  if ((alpha) &&\n      ((color_type == PNG_COLOR_TYPE_GRAY_ALPHA) ||\n       (color_type == PNG_COLOR_TYPE_RGB_ALPHA)))\n  {\n    fprintf (alpha_file, \"%s\\n\", (raw) ? \"P5\" : \"P2\");\n    fprintf (alpha_file, \"%d %d\\n\", (int) width, (int) height);\n    fprintf (alpha_file, \"%ld\\n\", ((1L << (int) bit_depth) - 1L));\n  }\n\n  /* write data to PNM file */\n  pix_ptr = png_pixels;\n\n  for (row = 0; row < (int) height; row++)\n  {\n    for (col = 0; col < (int) width; col++)\n    {\n      for (i = 0; i < (channels - alpha_present); i++)\n      {\n        if (raw)\n          fputc ((int) *pix_ptr++ , pnm_file);\n        else\n          if (bit_depth == 16){\n            dep_16 = (long) *pix_ptr++;\n            fprintf (pnm_file, \"%ld \", (dep_16 << 8) + ((long) *pix_ptr++));\n          }\n          else\n            fprintf (pnm_file, \"%ld \", (long) *pix_ptr++);\n      }\n      if (alpha_present)\n      {\n        if (!alpha)\n        {\n          pix_ptr++; /* alpha */\n          if (bit_depth == 16)\n            pix_ptr++;\n        }\n        else /* output alpha-channel as pgm file */\n        {\n          if (raw)\n            fputc ((int) *pix_ptr++ , alpha_file);\n          else\n            if (bit_depth == 16){\n              dep_16 = (long) *pix_ptr++;\n              fprintf (alpha_file, \"%ld \", (dep_16 << 8) + (long) *pix_ptr++);\n            }\n            else\n              fprintf (alpha_file, \"%ld \", (long) *pix_ptr++);\n        }\n      } /* if alpha_present */\n\n      if (!raw)\n        if (col % 4 == 3)\n          fprintf (pnm_file, \"\\n\");\n    } /* end for col */\n\n    if (!raw)\n      if (col % 4 != 0)\n        fprintf (pnm_file, \"\\n\");\n  } /* end for row */\n\n  if (row_pointers != (unsigned char**) NULL)\n    free (row_pointers);\n  if (png_pixels != (unsigned char*) NULL)\n    free (png_pixels);\n\n  return TRUE;\n\n} /* end of source */\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/png2pnm.sh",
    "content": "#!/bin/sh\n# -- grayscale\n./png2pnm -noraw ../pngsuite/basn0g01.png basn0g01.pgm\n./png2pnm -noraw ../pngsuite/basn0g02.png basn0g02.pgm\n./png2pnm -noraw ../pngsuite/basn0g04.png basn0g04.pgm\n./png2pnm -noraw ../pngsuite/basn0g08.png basn0g08.pgm\n./png2pnm -noraw ../pngsuite/basn0g16.png basn0g16.pgm\n# -- full-color\n./png2pnm -noraw ../pngsuite/basn2c08.png basn2c08.ppm\n./png2pnm -noraw ../pngsuite/basn2c16.png basn2c16.ppm\n# -- palletted\n./png2pnm -noraw ../pngsuite/basn3p01.png basn3p01.ppm\n./png2pnm -noraw ../pngsuite/basn3p02.png basn3p02.ppm\n./png2pnm -noraw ../pngsuite/basn3p04.png basn3p04.ppm\n./png2pnm -noraw ../pngsuite/basn3p08.png basn3p08.ppm\n# -- gray with alpha-channel\n./png2pnm -noraw ../pngsuite/basn4a08.png basn4a08.pgm\n./png2pnm -noraw ../pngsuite/basn4a16.png basn4a16.pgm\n# -- color with alpha-channel\n./png2pnm -noraw -alpha basn6a08.pgm ../pngsuite/basn6a08.png basn6a08.ppm\n./png2pnm -noraw -alpha basn6a16.pgm ../pngsuite/basn6a16.png basn6a16.ppm\n# -- grayscale\n./png2pnm -raw ../pngsuite/basn0g01.png rawn0g01.pgm\n./png2pnm -raw ../pngsuite/basn0g02.png rawn0g02.pgm\n./png2pnm -raw ../pngsuite/basn0g04.png rawn0g04.pgm\n./png2pnm -raw ../pngsuite/basn0g08.png rawn0g08.pgm\n./png2pnm -raw ../pngsuite/basn0g16.png rawn0g16.pgm\n# -- full-color\n./png2pnm -raw ../pngsuite/basn2c08.png rawn2c08.ppm\n./png2pnm -raw ../pngsuite/basn2c16.png rawn2c16.ppm\n# -- palletted\n./png2pnm -raw ../pngsuite/basn3p01.png rawn3p01.ppm\n./png2pnm -raw ../pngsuite/basn3p02.png rawn3p02.ppm\n./png2pnm -raw ../pngsuite/basn3p04.png rawn3p04.ppm\n./png2pnm -raw ../pngsuite/basn3p08.png rawn3p08.ppm\n# -- gray with alpha-channel\n./png2pnm -raw ../pngsuite/basn4a08.png rawn4a08.pgm\n./png2pnm -raw ../pngsuite/basn4a16.png rawn4a16.pgm\n# -- color with alpha-channel\n./png2pnm -noraw -alpha rawn6a08.pgm ../pngsuite/basn6a08.png rawn6a08.ppm\n./png2pnm -noraw -alpha rawn6a16.pgm ../pngsuite/basn6a16.png rawn6a16.ppm\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/pngminus.bat",
    "content": "make -f makefile.tc3\ncall png2pnm.bat\ncall pnm2png.bat\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/pngminus.sh",
    "content": "#!/bin/sh\nmake -f makefile.std\nsh png2pnm.sh\nsh pnm2png.sh\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/pnm2png.bat",
    "content": "REM -- grayscale\npnm2png.exe basn0g01.pgm basn0g01.png\npnm2png.exe basn0g02.pgm basn0g02.png\npnm2png.exe basn0g04.pgm basn0g04.png\npnm2png.exe basn0g08.pgm basn0g08.png\npnm2png.exe basn0g16.pgm basn0g16.png\nREM -- full-color\npnm2png.exe basn2c08.ppm basn2c08.png\npnm2png.exe basn2c16.ppm basn2c16.png\nREM -- palletted\npnm2png.exe basn3p01.ppm basn3p01.png\npnm2png.exe basn3p02.ppm basn3p02.png\npnm2png.exe basn3p04.ppm basn3p04.png\npnm2png.exe basn3p08.ppm basn3p08.png\nREM -- gray with alpha-channel\npnm2png.exe -alpha basn6a08.pgm basn4a08.pgm basn4a08.png\npnm2png.exe -alpha basn6a16.pgm basn4a16.pgm basn4a16.png\nREM -- color with alpha-channel\npnm2png.exe -alpha basn6a08.pgm basn6a08.ppm basn6a08.png\npnm2png.exe -alpha basn6a16.pgm basn6a16.ppm basn6a16.png\nREM -- grayscale\npnm2png.exe rawn0g01.pgm rawn0g01.png\npnm2png.exe rawn0g02.pgm rawn0g02.png\npnm2png.exe rawn0g04.pgm rawn0g04.png\npnm2png.exe rawn0g08.pgm rawn0g08.png\npnm2png.exe rawn0g16.pgm rawn0g16.png\nREM -- full-color\npnm2png.exe rawn2c08.ppm rawn2c08.png\npnm2png.exe rawn2c16.ppm rawn2c16.png\nREM -- palletted\npnm2png.exe rawn3p01.ppm rawn3p01.png\npnm2png.exe rawn3p02.ppm rawn3p02.png\npnm2png.exe rawn3p04.ppm rawn3p04.png\npnm2png.exe rawn3p08.ppm rawn3p08.png\nREM -- gray with alpha-channel\npnm2png.exe -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png\npnm2png.exe -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png\nREM -- color with alpha-channel\npnm2png.exe -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png\npnm2png.exe -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/pnm2png.c",
    "content": "/*\n *  pnm2png.c --- conversion from PBM/PGM/PPM-file to PNG-file\n *  copyright (C) 1999 by Willem van Schaik <willem@schaik.com>\n *\n *  version 1.0 - 1999.10.15 - First version.\n *  version 1.1 - 2015.07.29 - Fixed leaks (Glenn Randers-Pehrson)\n *\n *  Permission to use, copy, modify, and distribute this software and\n *  its documentation for any purpose and without fee is hereby granted,\n *  provided that the above copyright notice appear in all copies and\n *  that both that copyright notice and this permission notice appear in\n *  supporting documentation. This software is provided \"as is\" without\n *  express or implied warranty.\n */\n\n#include <stdio.h>\n#include <stdlib.h>\n#ifdef __TURBOC__\n#include <mem.h>\n#include <fcntl.h>\n#endif\n#include <zlib.h>\n\n#ifndef BOOL\n#define BOOL unsigned char\n#endif\n#ifndef TRUE\n#define TRUE (BOOL) 1\n#endif\n#ifndef FALSE\n#define FALSE (BOOL) 0\n#endif\n\n#define STDIN  0\n#define STDOUT 1\n#define STDERR 2\n\n/* to make pnm2png verbose so we can find problems (needs to be before png.h) */\n#ifndef PNG_DEBUG\n#define PNG_DEBUG 0\n#endif\n\n#include \"png.h\"\n\n/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */\n#ifndef png_jmpbuf\n#  define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)\n#endif\n\n/* function prototypes */\n\nint  main (int argc, char *argv[]);\nvoid usage ();\nBOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,\n    BOOL alpha);\nvoid get_token(FILE *pnm_file, char *token);\npng_uint_32 get_data (FILE *pnm_file, int depth);\npng_uint_32 get_value (FILE *pnm_file, int depth);\n\n/*\n *  main\n */\n\nint main(int argc, char *argv[])\n{\n  FILE *fp_rd = stdin;\n  FILE *fp_al = NULL;\n  FILE *fp_wr = stdout;\n  BOOL interlace = FALSE;\n  BOOL alpha = FALSE;\n  int argi;\n\n  for (argi = 1; argi < argc; argi++)\n  {\n    if (argv[argi][0] == '-')\n    {\n      switch (argv[argi][1])\n      {\n        case 'i':\n          interlace = TRUE;\n          break;\n        case 'a':\n          alpha = TRUE;\n          argi++;\n          if ((fp_al = fopen (argv[argi], \"rb\")) == NULL)\n          {\n            fprintf (stderr, \"PNM2PNG\\n\");\n            fprintf (stderr, \"Error:  alpha-channel file %s does not exist\\n\",\n               argv[argi]);\n            exit (1);\n          }\n          break;\n        case 'h':\n        case '?':\n          usage();\n          exit(0);\n          break;\n        default:\n          fprintf (stderr, \"PNM2PNG\\n\");\n          fprintf (stderr, \"Error:  unknown option %s\\n\", argv[argi]);\n          usage();\n          exit(1);\n          break;\n      } /* end switch */\n    }\n    else if (fp_rd == stdin)\n    {\n      if ((fp_rd = fopen (argv[argi], \"rb\")) == NULL)\n      {\n        fprintf (stderr, \"PNM2PNG\\n\");\n        fprintf (stderr, \"Error:  file %s does not exist\\n\", argv[argi]);\n        exit (1);\n      }\n    }\n    else if (fp_wr == stdout)\n    {\n      if ((fp_wr = fopen (argv[argi], \"wb\")) == NULL)\n      {\n        fprintf (stderr, \"PNM2PNG\\n\");\n        fprintf (stderr, \"Error:  can not create PNG-file %s\\n\", argv[argi]);\n        exit (1);\n      }\n    }\n    else\n    {\n      fprintf (stderr, \"PNM2PNG\\n\");\n      fprintf (stderr, \"Error:  too many parameters\\n\");\n      usage();\n      exit (1);\n    }\n  } /* end for */\n\n#ifdef __TURBOC__\n  /* set stdin/stdout to binary, we're reading the PNM always! in binary format */\n  if (fp_rd == stdin)\n  {\n    setmode (STDIN, O_BINARY);\n  }\n  if (fp_wr == stdout)\n  {\n    setmode (STDOUT, O_BINARY);\n  }\n#endif\n\n  /* call the conversion program itself */\n  if (pnm2png (fp_rd, fp_wr, fp_al, interlace, alpha) == FALSE)\n  {\n    fprintf (stderr, \"PNM2PNG\\n\");\n    fprintf (stderr, \"Error:  unsuccessful converting to PNG-image\\n\");\n    exit (1);\n  }\n\n  /* close input file */\n  fclose (fp_rd);\n  /* close output file */\n  fclose (fp_wr);\n  /* close alpha file */\n  if (alpha)\n    fclose (fp_al);\n\n  return 0;\n}\n\n/*\n *  usage\n */\n\nvoid usage()\n{\n  fprintf (stderr, \"PNM2PNG\\n\");\n  fprintf (stderr, \"   by Willem van Schaik, 1999\\n\");\n#ifdef __TURBOC__\n  fprintf (stderr, \"   for Turbo-C and Borland-C compilers\\n\");\n#else\n  fprintf (stderr, \"   for Linux (and Unix) compilers\\n\");\n#endif\n  fprintf (stderr, \"Usage:  pnm2png [options] <file>.<pnm> [<file>.png]\\n\");\n  fprintf (stderr, \"   or:  ... | pnm2png [options]\\n\");\n  fprintf (stderr, \"Options:\\n\");\n  fprintf (stderr, \"   -i[nterlace]   write png-file with interlacing on\\n\");\n  fprintf (stderr,\n      \"   -a[lpha] <file>.pgm read PNG alpha channel as pgm-file\\n\");\n  fprintf (stderr, \"   -h | -?  print this help-information\\n\");\n}\n\n/*\n *  pnm2png\n */\n\nBOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,\n     BOOL alpha)\n{\n  png_struct    *png_ptr = NULL;\n  png_info      *info_ptr = NULL;\n  png_byte      *png_pixels = NULL;\n  png_byte      **row_pointers = NULL;\n  png_byte      *pix_ptr = NULL;\n  volatile png_uint_32   row_bytes;\n\n  char          type_token[16];\n  char          width_token[16];\n  char          height_token[16];\n  char          maxval_token[16];\n  volatile int    color_type=1;\n  unsigned long   ul_width=0, ul_alpha_width=0;\n  unsigned long   ul_height=0, ul_alpha_height=0;\n  unsigned long   ul_maxval=0;\n  volatile png_uint_32   width=0, height=0;\n  volatile png_uint_32   alpha_width=0, alpha_height=0;\n  png_uint_32   maxval;\n  volatile int           bit_depth = 0;\n  int           channels=0;\n  int           alpha_depth = 0;\n  int           alpha_present=0;\n  int           row, col;\n  BOOL          raw, alpha_raw = FALSE;\n#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n  BOOL          packed_bitmap = FALSE;\n#endif\n  png_uint_32   tmp16;\n  int           i;\n\n  /* read header of PNM file */\n\n  get_token(pnm_file, type_token);\n  if (type_token[0] != 'P')\n  {\n    return FALSE;\n  }\n  else if ((type_token[1] == '1') || (type_token[1] == '4'))\n  {\n#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n    raw = (type_token[1] == '4');\n    color_type = PNG_COLOR_TYPE_GRAY;\n    get_token(pnm_file, width_token);\n    sscanf (width_token, \"%lu\", &ul_width);\n    width = (png_uint_32) ul_width;\n    get_token(pnm_file, height_token);\n    sscanf (height_token, \"%lu\", &ul_height);\n    height = (png_uint_32) ul_height;\n    bit_depth = 1;\n    packed_bitmap = TRUE;\n#else\n    fprintf (stderr, \"PNM2PNG built without PNG_WRITE_INVERT_SUPPORTED and \\n\");\n    fprintf (stderr, \"PNG_WRITE_PACK_SUPPORTED can't read PBM (P1,P4) files\\n\");\n#endif\n  }\n  else if ((type_token[1] == '2') || (type_token[1] == '5'))\n  {\n    raw = (type_token[1] == '5');\n    color_type = PNG_COLOR_TYPE_GRAY;\n    get_token(pnm_file, width_token);\n    sscanf (width_token, \"%lu\", &ul_width);\n    width = (png_uint_32) ul_width;\n    get_token(pnm_file, height_token);\n    sscanf (height_token, \"%lu\", &ul_height);\n    height = (png_uint_32) ul_height;\n    get_token(pnm_file, maxval_token);\n    sscanf (maxval_token, \"%lu\", &ul_maxval);\n    maxval = (png_uint_32) ul_maxval;\n\n    if (maxval <= 1)\n      bit_depth = 1;\n    else if (maxval <= 3)\n      bit_depth = 2;\n    else if (maxval <= 15)\n      bit_depth = 4;\n    else if (maxval <= 255)\n      bit_depth = 8;\n    else /* if (maxval <= 65535) */\n      bit_depth = 16;\n  }\n  else if ((type_token[1] == '3') || (type_token[1] == '6'))\n  {\n    raw = (type_token[1] == '6');\n    color_type = PNG_COLOR_TYPE_RGB;\n    get_token(pnm_file, width_token);\n    sscanf (width_token, \"%lu\", &ul_width);\n    width = (png_uint_32) ul_width;\n    get_token(pnm_file, height_token);\n    sscanf (height_token, \"%lu\", &ul_height);\n    height = (png_uint_32) ul_height;\n    get_token(pnm_file, maxval_token);\n    sscanf (maxval_token, \"%lu\", &ul_maxval);\n    maxval = (png_uint_32) ul_maxval;\n    if (maxval <= 1)\n      bit_depth = 1;\n    else if (maxval <= 3)\n      bit_depth = 2;\n    else if (maxval <= 15)\n      bit_depth = 4;\n    else if (maxval <= 255)\n      bit_depth = 8;\n    else /* if (maxval <= 65535) */\n      bit_depth = 16;\n  }\n  else\n  {\n    return FALSE;\n  }\n\n  /* read header of PGM file with alpha channel */\n\n  if (alpha)\n  {\n    if (color_type == PNG_COLOR_TYPE_GRAY)\n      color_type = PNG_COLOR_TYPE_GRAY_ALPHA;\n    if (color_type == PNG_COLOR_TYPE_RGB)\n      color_type = PNG_COLOR_TYPE_RGB_ALPHA;\n\n    get_token(alpha_file, type_token);\n    if (type_token[0] != 'P')\n    {\n      return FALSE;\n    }\n    else if ((type_token[1] == '2') || (type_token[1] == '5'))\n    {\n      alpha_raw = (type_token[1] == '5');\n      get_token(alpha_file, width_token);\n      sscanf (width_token, \"%lu\", &ul_alpha_width);\n      alpha_width=(png_uint_32) ul_alpha_width;\n      if (alpha_width != width)\n        return FALSE;\n      get_token(alpha_file, height_token);\n      sscanf (height_token, \"%lu\", &ul_alpha_height);\n      alpha_height = (png_uint_32) ul_alpha_height;\n      if (alpha_height != height)\n        return FALSE;\n      get_token(alpha_file, maxval_token);\n      sscanf (maxval_token, \"%lu\", &ul_maxval);\n      maxval = (png_uint_32) ul_maxval;\n      if (maxval <= 1)\n        alpha_depth = 1;\n      else if (maxval <= 3)\n        alpha_depth = 2;\n      else if (maxval <= 15)\n        alpha_depth = 4;\n      else if (maxval <= 255)\n        alpha_depth = 8;\n      else /* if (maxval <= 65535) */\n        alpha_depth = 16;\n      if (alpha_depth != bit_depth)\n        return FALSE;\n    }\n    else\n    {\n      return FALSE;\n    }\n  } /* end if alpha */\n\n  /* calculate the number of channels and store alpha-presence */\n  if (color_type == PNG_COLOR_TYPE_GRAY)\n    channels = 1;\n  else if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n    channels = 2;\n  else if (color_type == PNG_COLOR_TYPE_RGB)\n    channels = 3;\n  else if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n    channels = 4;\n#if 0\n  else\n    channels = 0; /* cannot happen */\n#endif\n\n  alpha_present = (channels - 1) % 2;\n\n#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n  if (packed_bitmap)\n    /* row data is as many bytes as can fit width x channels x bit_depth */\n    row_bytes = (width * channels * bit_depth + 7) / 8;\n  else\n#endif\n    /* row_bytes is the width x number of channels x (bit-depth / 8) */\n    row_bytes = width * channels * ((bit_depth <= 8) ? 1 : 2);\n\n  if ((png_pixels = (png_byte *)\n     malloc (row_bytes * height * sizeof (png_byte))) == NULL)\n    return FALSE;\n\n  /* read data from PNM file */\n  pix_ptr = png_pixels;\n\n  for (row = 0; row < (int) height; row++)\n  {\n#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n    if (packed_bitmap) {\n      for (i = 0; i < (int) row_bytes; i++)\n        /* png supports this format natively so no conversion is needed */\n        *pix_ptr++ = get_data (pnm_file, 8);\n    } else\n#endif\n    {\n      for (col = 0; col < (int) width; col++)\n      {\n        for (i = 0; i < (channels - alpha_present); i++)\n        {\n          if (raw)\n            *pix_ptr++ = get_data (pnm_file, bit_depth);\n          else\n            if (bit_depth <= 8)\n              *pix_ptr++ = get_value (pnm_file, bit_depth);\n            else\n            {\n              tmp16 = get_value (pnm_file, bit_depth);\n              *pix_ptr = (png_byte) ((tmp16 >> 8) & 0xFF);\n              pix_ptr++;\n              *pix_ptr = (png_byte) (tmp16 & 0xFF);\n              pix_ptr++;\n            }\n        }\n\n        if (alpha) /* read alpha-channel from pgm file */\n        {\n          if (alpha_raw)\n            *pix_ptr++ = get_data (alpha_file, alpha_depth);\n          else\n            if (alpha_depth <= 8)\n              *pix_ptr++ = get_value (alpha_file, bit_depth);\n            else\n            {\n              tmp16 = get_value (alpha_file, bit_depth);\n              *pix_ptr++ = (png_byte) ((tmp16 >> 8) & 0xFF);\n              *pix_ptr++ = (png_byte) (tmp16 & 0xFF);\n            }\n        } /* if alpha */\n      } /* if packed_bitmap */\n    } /* end for col */\n  } /* end for row */\n\n  /* prepare the standard PNG structures */\n  png_ptr = png_create_write_struct (png_get_libpng_ver(NULL), NULL, NULL,\n      NULL);\n  if (!png_ptr)\n  {\n    free (png_pixels);\n    png_pixels = NULL;\n    return FALSE;\n  }\n  info_ptr = png_create_info_struct (png_ptr);\n  if (!info_ptr)\n  {\n    png_destroy_write_struct (&png_ptr, (png_infopp) NULL);\n    free (png_pixels);\n    png_pixels = NULL;\n    return FALSE;\n  }\n\n#if defined(PNG_WRITE_INVERT_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n  if (packed_bitmap == TRUE)\n  {\n    png_set_packing (png_ptr);\n    png_set_invert_mono (png_ptr);\n  }\n#endif\n\n  /* setjmp() must be called in every function that calls a PNG-reading libpng function */\n  if (setjmp (png_jmpbuf(png_ptr)))\n  {\n    png_destroy_write_struct (&png_ptr, &info_ptr);\n    free (png_pixels);\n    png_pixels = NULL;\n    return FALSE;\n  }\n\n  /* initialize the png structure */\n  png_init_io (png_ptr, png_file);\n\n  /* we're going to write more or less the same PNG as the input file */\n  png_set_IHDR (png_ptr, info_ptr, width, height, bit_depth, color_type,\n    (!interlace) ? PNG_INTERLACE_NONE : PNG_INTERLACE_ADAM7,\n    PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n  /* write the file header information */\n  png_write_info (png_ptr, info_ptr);\n\n  /* if needed we will allocate memory for an new array of row-pointers */\n  if (row_pointers == (unsigned char**) NULL)\n  {\n    if ((row_pointers = (png_byte **)\n        malloc (height * sizeof (png_bytep))) == NULL)\n    {\n      png_destroy_write_struct (&png_ptr, &info_ptr);\n      free (png_pixels);\n      png_pixels = NULL;\n      return FALSE;\n    }\n  }\n\n  /* set the individual row_pointers to point at the correct offsets */\n  for (i = 0; i < (int) height; i++)\n    row_pointers[i] = png_pixels + i * row_bytes;\n\n  /* write out the entire image data in one call */\n  png_write_image (png_ptr, row_pointers);\n\n  /* write the additional chunks to the PNG file (not really needed) */\n  png_write_end (png_ptr, info_ptr);\n\n  /* clean up after the write, and free any memory allocated */\n  png_destroy_write_struct (&png_ptr, &info_ptr);\n\n  if (row_pointers != (unsigned char**) NULL)\n    free (row_pointers);\n  if (png_pixels != (unsigned char*) NULL)\n    free (png_pixels);\n\n  return TRUE;\n} /* end of pnm2png */\n\n/*\n * get_token() - gets the first string after whitespace\n */\n\nvoid get_token(FILE *pnm_file, char *token)\n{\n  int i = 0;\n  int ret;\n\n  /* remove white-space and comment lines */\n  do\n  {\n    ret = fgetc(pnm_file);\n    if (ret == '#') {\n      /* the rest of this line is a comment */\n      do\n      {\n        ret = fgetc(pnm_file);\n      }\n      while ((ret != '\\n') && (ret != '\\r') && (ret != EOF));\n    }\n    if (ret == EOF) break;\n    token[i] = (unsigned char) ret;\n  }\n  while ((token[i] == '\\n') || (token[i] == '\\r') || (token[i] == ' '));\n\n  /* read string */\n  do\n  {\n    ret = fgetc(pnm_file);\n    if (ret == EOF) break;\n    i++;\n    token[i] = (unsigned char) ret;\n  }\n  while ((token[i] != '\\n') && (token[i] != '\\r') && (token[i] != ' '));\n\n  token[i] = '\\0';\n\n  return;\n}\n\n/*\n * get_data() - takes first byte and converts into next pixel value,\n *        taking as much bits as defined by bit-depth and\n *        using the bit-depth to fill up a byte (0Ah -> AAh)\n */\n\npng_uint_32 get_data (FILE *pnm_file, int depth)\n{\n  static int bits_left = 0;\n  static int old_value = 0;\n  static int mask = 0;\n  int i;\n  png_uint_32 ret_value;\n\n  if (mask == 0)\n    for (i = 0; i < depth; i++)\n      mask = (mask >> 1) | 0x80;\n\n  if (bits_left <= 0)\n  {\n    old_value = fgetc (pnm_file);\n    bits_left = 8;\n  }\n\n  ret_value = old_value & mask;\n  for (i = 1; i < (8 / depth); i++)\n    ret_value = ret_value || (ret_value >> depth);\n\n  old_value = (old_value << depth) & 0xFF;\n  bits_left -= depth;\n\n  return ret_value;\n}\n\n/*\n * get_value() - takes first (numeric) string and converts into number,\n *         using the bit-depth to fill up a byte (0Ah -> AAh)\n */\n\npng_uint_32 get_value (FILE *pnm_file, int depth)\n{\n  static png_uint_32 mask = 0;\n  png_byte token[16];\n  unsigned long ul_ret_value;\n  png_uint_32 ret_value;\n  int i = 0;\n\n  if (mask == 0)\n    for (i = 0; i < depth; i++)\n      mask = (mask << 1) | 0x01;\n\n  get_token (pnm_file, (char *) token);\n  sscanf ((const char *) token, \"%lu\", &ul_ret_value);\n  ret_value = (png_uint_32) ul_ret_value;\n\n  ret_value &= mask;\n\n  if (depth < 8)\n    for (i = 0; i < (8 / depth); i++)\n      ret_value = (ret_value << depth) || ret_value;\n\n  return ret_value;\n}\n\n/* end of source */\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngminus/pnm2png.sh",
    "content": "#!/bin/sh\n# -- grayscale\n./pnm2png basn0g01.pgm basn0g01.png\n./pnm2png basn0g02.pgm basn0g02.png\n./pnm2png basn0g04.pgm basn0g04.png\n./pnm2png basn0g08.pgm basn0g08.png\n./pnm2png basn0g16.pgm basn0g16.png\n# -- full-color\n./pnm2png basn2c08.ppm basn2c08.png\n./pnm2png basn2c16.ppm basn2c16.png\n# -- palletted\n./pnm2png basn3p01.ppm basn3p01.png\n./pnm2png basn3p02.ppm basn3p02.png\n./pnm2png basn3p04.ppm basn3p04.png\n./pnm2png basn3p08.ppm basn3p08.png\n# -- gray with alpha-channel\n./pnm2png -alpha basn6a08.pgm basn4a08.pgm basn4a08.png\n./pnm2png -alpha basn6a16.pgm basn4a16.pgm basn4a16.png\n# -- color with alpha-channel\n./pnm2png -alpha basn6a08.pgm basn6a08.ppm basn6a08.png\n./pnm2png -alpha basn6a16.pgm basn6a16.ppm basn6a16.png\n# -- grayscale\n./pnm2png rawn0g01.pgm rawn0g01.png\n./pnm2png rawn0g02.pgm rawn0g02.png\n./pnm2png rawn0g04.pgm rawn0g04.png\n./pnm2png rawn0g08.pgm rawn0g08.png\n./pnm2png rawn0g16.pgm rawn0g16.png\n# -- full-color\n./pnm2png rawn2c08.ppm rawn2c08.png\n./pnm2png rawn2c16.ppm rawn2c16.png\n# -- palletted\n./pnm2png rawn3p01.ppm rawn3p01.png\n./pnm2png rawn3p02.ppm rawn3p02.png\n./pnm2png rawn3p04.ppm rawn3p04.png\n./pnm2png rawn3p08.ppm rawn3p08.png\n# -- gray with alpha-channel\n./pnm2png -alpha rawn6a08.pgm rawn4a08.pgm rawn4a08.png\n./pnm2png -alpha rawn6a16.pgm rawn4a16.pgm rawn4a16.png\n# -- color with alpha-channel\n./pnm2png -alpha rawn6a08.pgm rawn6a08.ppm rawn6a08.png\n./pnm2png -alpha rawn6a16.pgm rawn6a16.ppm rawn6a16.png\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/pngsuite/README",
    "content": "\npngsuite\n--------\nCopyright (c) Willem van Schaik, 1999, 2011, 2012\nTwo images (ftbbn0g01.png and ftbbn0g02.png) are by Glenn Randers-Pehrson, 2012\n\nPermission to use, copy, modify, and distribute these images for any\npurpose and without fee is hereby granted.\n\nThe 15 \"bas*.png\" images are part of the much larger PngSuite test-set of\nimages, available for developers of PNG supporting software. The\ncomplete set, available at http:/www.schaik.com/pngsuite/, contains\na variety of images to test interlacing, gamma settings, ancillary\nchunks, etc.\n\nThe \"ft*.png\" images are \"free/libre\" replacements for the transparent\ncorresponding t*.png images in the PngSuite.\n\nThe images in this directory represent the basic PNG color-types:\ngrayscale (1-16 bit deep), full color (8 or 16 bit), paletted\n(1-8 bit) and grayscale or color images with alpha channel. You\ncan use them to test the proper functioning of PNG software.\n\n    filename       depth type\n    ------------ ------ --------------\n    basn0g01.png   1-bit grayscale\n    basn0g02.png   2-bit grayscale\n    basn0g04.png   4-bit grayscale\n    basn0g08.png   8-bit grayscale\n    basn0g16.png  16-bit grayscale\n    basn2c08.png   8-bit truecolor\n    basn2c16.png  16-bit truecolor\n    basn3p01.png   1-bit paletted\n    basn3p02.png   2-bit paletted\n    basn3p04.png   4-bit paletted\n    basn3p08.png   8-bit paletted\n    basn4a08.png   8-bit gray with alpha\n    basn4a16.png  16-bit gray with alpha\n    basn6a08.png   8-bit RGBA\n    basn6a16.png  16-bit RGBA\n\n    ftbbn0g01.png  1-bit grayscale, black bKGD\n    ftbbn0g02.png  2-bit grayscale, black bKGD\n    ftbbn0g04.png  4-bit grayscale, black bKGD\n    ftbbn2c16.png 16-bit truecolor, black bKGD\n    ftbbn3p08.png  8-bit paletted, black bKGD\n    ftbgn2c16.png 16-bit truecolor, gray bKGD\n    ftbgn3p08.png  8-bit paletted, gray bKGD\n    ftbrn2c08.png  8-bit truecolor, red bKGD\n    ftbwn0g16.png 16-bit gray, white bKGD\n    ftbwn3p08.png  8-bit paletted, white bKGD\n    ftbyn3p08.png  8-bit paletted, yellow bKGD\n    ftp0n0g08.png  8-bit grayscale, opaque\n    ftp0n2c08.png  8-bit truecolor, opaque\n    ftp0n3p08.png  8-bit paletted, opaque\n    ftp1n3p08.png  8-bit paletted, no bKGD\n\nHere is the correct result of typing \"pngtest -m bas*.png\" in\nthis directory:\n\nTesting basn0g01.png: PASS (524 zero samples)\n Filter 0 was used 32 times\nTesting basn0g02.png: PASS (448 zero samples)\n Filter 0 was used 32 times\nTesting basn0g04.png: PASS (520 zero samples)\n Filter 0 was used 32 times\nTesting basn0g08.png: PASS (3 zero samples)\n Filter 1 was used 9 times\n Filter 4 was used 23 times\nTesting basn0g16.png: PASS (1 zero samples)\n Filter 1 was used 1 times\n Filter 2 was used 31 times\nTesting basn2c08.png: PASS (6 zero samples)\n Filter 1 was used 5 times\n Filter 4 was used 27 times\nTesting basn2c16.png: PASS (592 zero samples)\n Filter 1 was used 1 times\n Filter 4 was used 31 times\nTesting basn3p01.png: PASS (512 zero samples)\n Filter 0 was used 32 times\nTesting basn3p02.png: PASS (448 zero samples)\n Filter 0 was used 32 times\nTesting basn3p04.png: PASS (544 zero samples)\n Filter 0 was used 32 times\nTesting basn3p08.png: PASS (4 zero samples)\n Filter 0 was used 32 times\nTesting basn4a08.png: PASS (32 zero samples)\n Filter 1 was used 1 times\n Filter 4 was used 31 times\nTesting basn4a16.png: PASS (64 zero samples)\n Filter 0 was used 1 times\n Filter 1 was used 2 times\n Filter 2 was used 1 times\n Filter 4 was used 28 times\nTesting basn6a08.png: PASS (160 zero samples)\n Filter 1 was used 1 times\n Filter 4 was used 31 times\nTesting basn6a16.png: PASS (1072 zero samples)\n Filter 1 was used 4 times\n Filter 4 was used 28 times\nlibpng passes test\n\nWillem van Schaik\n<willem@schaik.com>\nOctober 1999\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/README.txt",
    "content": "This directory (contrib/tools) contains tools used by the authors of libpng.\n\nCode and data placed in this directory is not required to build libpng,\nhowever the code in this directory has been used to generate data or code in\nthe body of the libpng source.  The source code identifies where this has\nbeen done.  Code in this directory may not compile on all operating systems\nthat libpng supports.\n\nNO COPYRIGHT RIGHTS ARE CLAIMED TO ANY OF THE FILES IN THIS DIRECTORY.\n\nTo the extent possible under law, the authors have waived all copyright and\nrelated or neighboring rights to this work.  This work is published from:\nUnited States.\n\nThe files may be used freely in any way.\n\nThe source code and comments in this directory are the original work of the\npeople named below.  No other person or organization has made contributions to\nthe work in this directory.\n\nORIGINAL AUTHORS\n    The following people have contributed to the code in this directory.  None\n    of the people below claim any rights with regard to the contents of this\n    directory.\n\n    John Bowler <jbowler@acm.org>\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/checksum-icc.c",
    "content": "/* checksum-icc.c\n *\n * Copyright (c) 2013 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.0 [February 14, 2013]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Generate crc32 and adler32 checksums of the given input files, used to\n * generate check-codes for use when matching ICC profiles within libpng.\n */\n#include <stdio.h>\n\n#include <zlib.h>\n\nstatic int\nread_one_file(FILE *ip, const char *name)\n{\n   uLong length = 0;\n   uLong a32 = adler32(0, NULL, 0);\n   uLong c32 = crc32(0, NULL, 0);\n   Byte header[132];\n\n   for (;;)\n   {\n      int ch = getc(ip);\n      Byte b;\n\n      if (ch == EOF) break;\n\n      b = (Byte)ch;\n\n      if (length < sizeof header)\n         header[length] = b;\n\n      ++length;\n      a32 = adler32(a32, &b, 1);\n      c32 = crc32(c32, &b, 1);\n   }\n\n   if (ferror(ip))\n      return 0;\n\n   /* Success */\n   printf(\"PNG_ICC_CHECKSUM(0x%8.8lx, 0x%8.8lx,\\n   PNG_MD5(\"\n      \"0x%2.2x%2.2x%2.2x%2.2x, 0x%2.2x%2.2x%2.2x%2.2x, 0x%2.2x%2.2x%2.2x%2.2x,\"\n      \" 0x%2.2x%2.2x%2.2x%2.2x), %d,\\n\"\n      \"   \\\"%4.4d/%2.2d/%2.2d %2.2d:%2.2d:%2.2d\\\", %lu, \\\"%s\\\")\\n\",\n      (unsigned long)a32, (unsigned long)c32,\n      header[84], header[85], header[86], header[87],\n      header[88], header[89], header[90], header[91],\n      header[92], header[93], header[94], header[95],\n      header[96], header[97], header[98], header[99],\n#     define u16(x) (header[x] * 256 + header[x+1])\n#     define u32(x) (u16(x) * 65536 + u16(x+2))\n      u32(64), u16(24), u16(26), u16(28), u16(30), u16(32), u16(34),\n      (unsigned long)length, name);\n\n   return 1;\n}\n\nint main(int argc, char **argv)\n{\n   int err = 0;\n\n   printf(\"/* adler32, crc32, MD5[16], intent, date, length, file-name */\\n\");\n\n   if (argc > 1)\n   {\n      int i;\n\n      for (i=1; i<argc; ++i)\n      {\n         FILE *ip = fopen(argv[i], \"rb\");\n\n         if (ip == NULL || !read_one_file(ip, argv[i]))\n         {\n            err = 1;\n            perror(argv[i]);\n            fprintf(stderr, \"%s: read error\\n\", argv[i]);\n            printf(\"/* ERROR: %s */\\n\", argv[i]);\n         }\n\n         (void)fclose(ip);\n      }\n   }\n\n   else\n   {\n      if (!read_one_file(stdin, \"-\"))\n      {\n         err = 1;\n         perror(\"stdin\");\n         fprintf(stderr, \"stdin: read error\\n\");\n         printf(\"/* ERROR: stdin */\\n\");\n      }\n   }\n\n   return err;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/chkfmt",
    "content": "#!/bin/sh\n\n# chkfmt\n#\n# COPYRIGHT: Written by John Cunningham Bowler, 2010.\n# To the extent possible under law, the author has waived all copyright and\n# related or neighboring rights to this work.  This work is published from:\n# United States.\n#\n# Check the format of the source files in the current directory - checks for a\n# line length of 80 characters max and no tab characters.\n#\n# Optionally arguments are files or directories to check.\n#\n# -v: output the long lines (makes fixing them easier)\n# -e: spawn an editor for each file that needs a change ($EDITOR must be\n#     defined).  When using -e the script MUST be run from an interactive\n#     command line.\nverbose=\nedit=\nvers=\ntest \"$1\" = \"-v\" && {\n   shift\n   verbose=yes\n}\ntest \"$1\" = \"-e\" && {\n   shift\n   if test -n \"$EDITOR\"\n   then\n      edit=yes\n\n      # Copy the standard streams for the editor\n      exec 3>&0 4>&1 5>&2\n   else\n      echo \"chkfmt -e: EDITOR must be defined\" >&2\n      exit 1\n   fi\n}\n\n# Function to edit a single file - if the file isn't changed ask the user\n# whether or not to continue.  This stuff only works if the script is run from\n# the command line (otherwise, don't specify -e or you will be sorry).\ndoed(){\n   cp \"$file\" \"$file\".orig\n   \"$EDITOR\" \"$file\" 0>&3 1>&4 2>&5 3>&- 4>&- 5>&- || exit 1\n   if cmp -s \"$file\".orig \"$file\"\n   then\n      rm \"$file\".orig\n      echo -n \"$file: file not changed, type anything to continue: \" >&5\n      read ans 0>&3\n      test -n \"$ans\" || return 1\n   fi\n   return 0\n}\n\n# In beta versions the version string which appears in files can be a little\n# long and cause spuriously overlong lines.  To avoid this subtitute the version\n# string with a 'standard' version a.b.cc before checking for long lines.\nif test -r png.h\nthen\n   vers=\"`sed -n -e \\\n   's/^#define PNG_LIBPNG_VER_STRING .\\([0-9]\\.[0-9]\\.[0-9][0-9a-z]*\\).$/\\1/p' \\\n   png.h`\"\n   echo \"chkfmt: checking version $vers\"\nfi\nif test -z \"$vers\"\nthen\n   echo \"chkfmt: png.h not found, ignoring version number\" >&2\nfi\n\ntest -n \"$1\" || set -- .\nfind \"$@\" \\( -type d \\( -name '.git' -o -name '.libs' -o -name 'projects' \\) \\\n   -prune \\) -o \\( -type f \\\n   ! -name '*.[oa]' ! -name '*.l[oa]' !  -name '*.png' ! -name '*.out' \\\n   ! -name '*.jpg' ! -name '*.patch' ! -name '*.obj' ! -name '*.exe' \\\n   ! -name '*.com' ! -name '*.tar.*' ! -name '*.zip' ! -name '*.ico' \\\n   ! -name '*.res' ! -name '*.rc' ! -name '*.mms' ! -name '*.rej' \\\n   ! -name '*.dsp' ! -name '*.orig' ! -name '*.dfn' ! -name '*.swp' \\\n   ! -name '~*' ! -name '*.3' \\\n   ! -name 'missing' ! -name 'mkinstalldirs' ! -name 'depcomp' \\\n   ! -name 'aclocal.m4' ! -name 'install-sh' ! -name 'Makefile.in' \\\n   ! -name 'ltmain.sh' ! -name 'config*' -print \\) | {\n   st=0\n   while read file\n   do\n      case \"$file\" in\n      *.mak|*[Mm]akefile.*|*[Mm]akefile)\n         # Makefiles require tabs, dependency lines can be this long.\n         check_tabs=\n         line_length=100;;\n      *.awk)\n         # Includes literal tabs\n         check_tabs=\n         # The following is arbitrary\n         line_length=132;;\n      *contrib/*/*.[ch])\n         check_tabs=yes\n         line_length=96;;\n      *)\n         check_tabs=yes\n         line_length=80;;\n      esac\n\n      # Note that vers can only contain 0-9, . and a-z\n      if test -n \"$vers\"\n      then\n         sed -e \"s/$vers/a.b.cc/g\" \"$file\" >\"$file\".$$\n      else\n         cp \"$file\" \"$file\".$$\n      fi\n      splt=\"`fold -$line_length \"$file\".$$ | diff -c \"$file\".$$ -`\"\n      rm \"$file\".$$\n\n      if test -n \"$splt\"\n      then\n         echo \"$file: lines too long\"\n         st=1\n         if test -n \"$EDITOR\" -a -n \"$edit\"\n         then\n            doed \"$file\" || exit 1\n         elif test -n \"$verbose\"\n         then\n            echo \"$splt\"\n         fi\n      fi\n      if test -n \"$check_tabs\"\n      then\n         tab=\"`tr -c -d '\\t' <\"$file\"`\"\n         if test -n \"$tab\"\n         then\n            echo \"$file: file contains tab characters\"\n            st=1\n            if test -n \"$EDITOR\" -a -n \"$edit\"\n            then\n               doed \"$file\" || exit 1\n            elif test -n \"$verbose\"\n            then\n               echo \"$splt\"\n            fi\n         fi\n      fi\n   done\n   exit $st\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/cvtcolor.c",
    "content": "/*-\n * convert.c\n *\n * Last changed in libpng 1.6.0 [February 14, 2013]\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2013.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Convert 8-bit sRGB or 16-bit linear values to another format.\n */\n#define _ISOC99_SOURCE 1\n\n#include <stdlib.h>\n#include <string.h>\n#include <math.h>\n#include <stdio.h>\n\n#include <fenv.h>\n\n#include \"sRGB.h\"\n\nstatic void\nusage(const char *prog)\n{\n   fprintf(stderr,\n      \"%s: usage: %s [-linear|-sRGB] [-gray|-color] component{1,4}\\n\",\n      prog, prog);\n   exit(1);\n}\n\nunsigned long\ncomponent(const char *prog, const char *arg, int issRGB)\n{\n   char *ep;\n   unsigned long c = strtoul(arg, &ep, 0);\n\n   if (ep <= arg || *ep || c > 65535 || (issRGB && c > 255))\n   {\n      fprintf(stderr, \"%s: %s: invalid component value (%lu)\\n\", prog, arg, c);\n      usage(prog);\n   }\n\n   return c;\n}\n\nint\nmain(int argc, const char **argv)\n{\n   const char *prog = *argv++;\n   int to_linear = 0, to_gray = 0, to_color = 0;\n   int channels = 0;\n   double c[4];\n\n   /* FE_TONEAREST is the IEEE754 round to nearest, preferring even, mode; i.e.\n    * everything rounds to the nearest value except that '.5' rounds to the\n    * nearest even value.\n    */\n   fesetround(FE_TONEAREST);\n\n   c[3] = c[2] = c[1] = c[0] = 0;\n\n   while (--argc > 0 && **argv == '-')\n   {\n      const char *arg = 1+*argv++;\n\n      if (strcmp(arg, \"sRGB\") == 0)\n         to_linear = 0;\n\n      else if (strcmp(arg, \"linear\") == 0)\n         to_linear = 1;\n\n      else if (strcmp(arg, \"gray\") == 0)\n         to_gray = 1, to_color = 0;\n\n      else if (strcmp(arg, \"color\") == 0)\n         to_gray = 0, to_color = 1;\n\n      else\n         usage(prog);\n   }\n\n   switch (argc)\n   {\n      default:\n         usage(prog);\n         break;\n\n      case 4:\n         c[3] = component(prog, argv[3], to_linear);\n         ++channels;\n      case 3:\n         c[2] = component(prog, argv[2], to_linear);\n         ++channels;\n      case 2:\n         c[1] = component(prog, argv[1], to_linear);\n         ++channels;\n      case 1:\n         c[0] = component(prog, argv[0], to_linear);\n         ++channels;\n         break;\n      }\n\n   if (to_linear)\n   {\n      int i;\n      int components = channels;\n\n      if ((components & 1) == 0)\n         --components;\n\n      for (i=0; i<components; ++i) c[i] = linear_from_sRGB(c[i] / 255);\n      if (components < channels)\n         c[components] = c[components] / 255;\n   }\n\n   else\n   {\n      int i;\n      for (i=0; i<4; ++i) c[i] /= 65535;\n\n      if ((channels & 1) == 0)\n      {\n         double alpha = c[channels-1];\n\n         if (alpha > 0)\n            for (i=0; i<channels-1; ++i) c[i] /= alpha;\n         else\n            for (i=0; i<channels-1; ++i) c[i] = 1;\n      }\n   }\n\n   if (to_gray)\n   {\n      if (channels < 3)\n      {\n         fprintf(stderr, \"%s: too few channels (%d) for -gray\\n\",\n            prog, channels);\n         usage(prog);\n      }\n\n      c[0] = YfromRGB(c[0], c[1], c[2]);\n      channels -= 2;\n   }\n\n   if (to_color)\n   {\n      if (channels > 2)\n      {\n         fprintf(stderr, \"%s: too many channels (%d) for -color\\n\",\n            prog, channels);\n         usage(prog);\n      }\n\n      c[3] = c[1]; /* alpha, if present */\n      c[2] = c[1] = c[0];\n   }\n\n   if (to_linear)\n   {\n      int i;\n      if ((channels & 1) == 0)\n      {\n         double alpha = c[channels-1];\n         for (i=0; i<channels-1; ++i) c[i] *= alpha;\n      }\n\n      for (i=0; i<channels; ++i) c[i] = nearbyint(c[i] * 65535);\n   }\n\n   else /* to sRGB */\n   {\n      int i = (channels+1)&~1;\n      while (--i >= 0)\n         c[i] = sRGB_from_linear(c[i]);\n\n      for (i=0; i<channels; ++i) c[i] = nearbyint(c[i] * 255);\n   }\n\n   {\n      int i;\n      for (i=0; i<channels; ++i) printf(\" %g\", c[i]);\n   }\n   printf(\"\\n\");\n\n   return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/genpng.c",
    "content": "/*- genpng\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2015.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Generate a PNG with an alpha channel, correctly.\n *\n * This is a test case generator; the resultant PNG files are only of interest\n * to those of us who care about whether the edges of circles are green, red,\n * or yellow.\n *\n * The program generates an RGB+Alpha PNG of a given size containing the given\n * shapes on a transparent background:\n *\n *  genpng width height { shape }\n *    shape ::= color width shape x1 y1 x2 y2\n *\n * 'color' is:\n *\n *  black white red green yellow blue brown purple pink orange gray cyan\n *\n * The point is to have colors that are linguistically meaningful plus that old\n * bugbear of the department store dress murders, Cyan, the only color we argue\n * about.\n *\n * 'shape' is:\n *\n *  circle: an ellipse\n *  square: a rectangle\n *  line: a straight line\n *\n * Each shape is followed by four numbers, these are two points in the output\n * coordinate space (as real numbers) which describe the circle, square, or\n * line.  The shape is filled if it is preceded by 'filled' (not valid for\n * 'line') or is drawn with a line, in which case the width of the line must\n * precede the shape.\n *\n * The whole set of information can be repeated as many times as desired:\n *\n *    shape ::= color width shape x1 y1 x2 y2\n *\n *    color ::= black|white|red|green|yellow|blue\n *    color ::= brown|purple|pink|orange|gray|cyan\n *    width ::= filled\n *    width ::= <number>\n *    shape ::= circle|square|line\n *    x1    ::= <number>\n *    x2    ::= <number>\n *    y1    ::= <number>\n *    y2    ::= <number>\n *\n * The output PNG is generated by down-sampling a 4x supersampled image using\n * a bi-cubic filter.  The bi-cubic has a 2 (output) pixel width, so an 8x8\n * array of super-sampled points contribute to each output pixel.  The value of\n * a super-sampled point is found using an unfiltered, aliased, infinite\n * precision image: Each shape from the last to the first is checked to see if\n * the point is in the drawn area and, if it is, the color of the point is the\n * color of the shape and the alpha is 1, if not the previous shape is checked.\n *\n * This is an aliased algorithm because no filtering is done; a point is either\n * inside or outside each shape and 'close' points do not contribute to the\n * sample.  The down-sampling is relied on to correct the error of not using\n * a filter.\n *\n * The line end-caps are 'flat'; they go through the points.  The square line\n * joins are mitres; the outside of the lines are continued to the point of\n * intersection.\n */\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <math.h>\n\n/* Normally use <png.h> here to get the installed libpng, but this is done to\n * ensure the code picks up the local libpng implementation:\n */\n#include \"../../png.h\"\n\n#if defined(PNG_SIMPLIFIED_WRITE_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)\n\nstatic const struct color\n{\n   const char *name;\n   double      red;\n   double      green;\n   double      blue;\n} colors[] =\n/* color ::= black|white|red|green|yellow|blue\n * color ::= brown|purple|pink|orange|gray|cyan\n */\n{\n   { \"black\",   0,    0,  0 },\n   { \"white\",   1,    1,  1 },\n   { \"red\",     1,    0,  0 },\n   { \"green\",   0,    1,  0 },\n   { \"yellow\",  1,    1,  0 },\n   { \"blue\",    0,    0,  1 },\n   { \"brown\",  .5, .125,  0 },\n   { \"purple\",  1,    0,  1 },\n   { \"pink\",    1,   .5, .5 },\n   { \"orange\",  1,   .5,  0 },\n   { \"gray\",    0,   .5, .5 },\n   { \"cyan\",    0,    1,  1 }\n};\n#define color_count ((sizeof colors)/(sizeof colors[0]))\n\nstatic const struct color *\ncolor_of(const char *arg)\n{\n   int icolor = color_count;\n\n   while (--icolor >= 0)\n   {\n      if (strcmp(colors[icolor].name, arg) == 0)\n         return colors+icolor;\n   }\n\n   fprintf(stderr, \"genpng: invalid color %s\\n\", arg);\n   exit(1);\n}\n\nstatic double\nwidth_of(const char *arg)\n{\n   if (strcmp(arg, \"filled\") == 0)\n      return 0;\n\n   else\n   {\n      char *ep = NULL;\n      double w = strtod(arg, &ep);\n\n      if (ep != NULL && *ep == 0 && w > 0)\n         return w;\n   }\n\n   fprintf(stderr, \"genpng: invalid line width %s\\n\", arg);\n   exit(1);\n}\n\nstatic double\ncoordinate_of(const char *arg)\n{\n   char *ep = NULL;\n   double w = strtod(arg, &ep);\n\n   if (ep != NULL && *ep == 0)\n      return w;\n\n   fprintf(stderr, \"genpng: invalid coordinate value %s\\n\", arg);\n   exit(1);\n}\n\nstruct arg; /* forward declaration */\n\ntypedef int (*shape_fn_ptr)(const struct arg *arg, double x, double y);\n   /* A function to determine if (x,y) is inside the shape.\n    *\n    * There are two implementations:\n    *\n    *    inside_fn: returns true if the point is inside\n    *    check_fn:  returns;\n    *       -1: the point is outside the shape by more than the filter width (2)\n    *        0: the point may be inside the shape\n    *       +1: the point is inside the shape by more than the filter width\n    */\n#define OUTSIDE (-1)\n#define INSIDE  (1)\n\nstruct arg\n{\n   const struct color *color;\n   shape_fn_ptr        inside_fn;\n   shape_fn_ptr        check_fn;\n   double              width; /* line width, 0 for 'filled' */\n   double              x1, y1, x2, y2;\n};\n\n/* IMPLEMENTATION NOTE:\n *\n * We want the contribution of each shape to the sample corresponding to each\n * pixel.  This could be obtained by super sampling the image to infinite\n * dimensions, finding each point within the shape and assigning that a value\n * '1' while leaving every point outside the shape with value '0' then\n * downsampling to the image size with sinc; computationally very expensive.\n *\n * Approximations are as follows:\n *\n * 1) If the pixel coordinate is within the shape assume the sample has the\n *    shape color and is opaque, else assume there is no contribution from\n *    the shape.\n *\n *    This is the equivalent of aliased rendering or resampling an image with\n *    a block filter.  The maximum error in the calculated alpha (which will\n *    always be 0 or 1) is 0.5.\n *\n * 2) If the shape is within a square of size 1x1 centered on the pixel assume\n *    that the shape obscures an amount of the pixel equal to its area within\n *    that square.\n *\n *    This is the equivalent of 'pixel coverage' alpha calculation or resampling\n *    an image with a bi-linear filter.  The maximum error is over 0.2, but the\n *    results are often acceptable.\n *\n *    This can be approximated by applying (1) to a super-sampled image then\n *    downsampling with a bi-linear filter.  The error in the super-sampled\n *    image is 0.5 per sample, but the resampling reduces this.\n *\n * 3) Use a better filter with a super-sampled image; in the limit this is the\n *    sinc() approach.\n *\n * 4) Do the geometric calculation; a bivariate definite integral across the\n *    shape, unfortunately this means evaluating Si(x), the integral of sinc(x),\n *    which is still a lot of math.\n *\n * This code uses approach (3) with a bi-cubic filter and 8x super-sampling\n * and method (1) for the super-samples.  This means that the sample is either\n * 0 or 1, depending on whether the sub-pixel is within or outside the shape.\n * The bi-cubic weights are also fixed and the 16 required weights are\n * pre-computed here (note that the 'scale' setting will need to be changed if\n * 'super' is increased).\n *\n * The code also calculates a sum to the edge of the filter. This is not\n * currently used by could be used to optimize the calculation.\n */\n#if 0 /* bc code */\nscale=10\nsuper=8\ndefine bicubic(x) {\n   if (x <= 1) return (1.5*x - 2.5)*x*x + 1;\n   if (x <  2) return (((2.5 - 0.5*x)*x - 4)*x + 2);\n   return 0;\n}\ndefine sum(x) {\n   auto s;\n   s = 0;\n   while (x < 2*super) {\n      s = s + bicubic(x/super);\n      x = x + 1;\n   }\n   return s;\n}\ndefine results(x) {\n   auto b, s;\n   b = bicubic(x/super);\n   s = sum(x);\n\n   print \"   /*\", x, \"*/ { \", b, \", \", s, \" }\";\n   return 1;\n}\nx=0\nwhile (x<2*super) {\n   x = x + results(x)\n   if (x < 2*super) print \",\"\n   print \"\\n\"\n}\nquit\n#endif\n\n#define BICUBIC1(x) /*     |x| <= 1 */ ((1.5*(x)* - 2.5)*(x)*(x) + 1)\n#define BICUBIC2(x) /* 1 < |x| <  2 */ (((2.5 - 0.5*(x))*(x) - 4)*(x) + 2)\n#define FILTER_WEIGHT 9 /* Twice the first sum below */\n#define FILTER_WIDTH  2 /* Actually half the width; -2..+2 */\n#define FILTER_STEPS  8 /* steps per filter unit */\nstatic const double\nbicubic[16][2] =\n{\n   /* These numbers are exact; the weight for the filter is 1/9, but this\n    * would make the numbers inexact, so it is not included here.\n    */\n   /*          bicubic      sum        */\n   /* 0*/ { 1.0000000000, 4.5000000000 },\n   /* 1*/ {  .9638671875, 3.5000000000 },\n   /* 2*/ {  .8671875000, 2.5361328125 },\n   /* 3*/ {  .7275390625, 1.6689453125 },\n   /* 4*/ {  .5625000000,  .9414062500 },\n   /* 5*/ {  .3896484375,  .3789062500 },\n   /* 6*/ {  .2265625000, -.0107421875 },\n   /* 7*/ {  .0908203125, -.2373046875 },\n   /* 8*/ {            0, -.3281250000 },\n   /* 9*/ { -.0478515625, -.3281250000 },\n   /*10*/ { -.0703125000, -.2802734375 },\n   /*11*/ { -.0732421875, -.2099609375 },\n   /*12*/ { -.0625000000, -.1367187500 },\n   /*13*/ { -.0439453125, -.0742187500 },\n   /*14*/ { -.0234375000, -.0302734375 },\n   /*15*/ { -.0068359375, -.0068359375 }\n};\n\nstatic double\nalpha_calc(const struct arg *arg, double x, double y)\n{\n   /* For [x-2..x+2],[y-2,y+2] calculate the weighted bicubic given a function\n    * which tells us whether a point is inside or outside the shape.  First\n    * check if we need to do this at all:\n    */\n   switch (arg->check_fn(arg, x, y))\n   {\n      case OUTSIDE:\n         return 0; /* all samples outside the shape */\n\n      case INSIDE:\n         return 1; /* all samples inside the shape */\n\n      default:\n      {\n         int dy;\n         double alpha = 0;\n\n#        define FILTER_D (FILTER_WIDTH*FILTER_STEPS-1)\n         for (dy=-FILTER_D; dy<=FILTER_D; ++dy)\n         {\n            double wy = bicubic[abs(dy)][0];\n\n            if (wy != 0)\n            {\n               double alphay = 0;\n               int dx;\n\n               for (dx=-FILTER_D; dx<=FILTER_D; ++dx)\n               {\n                  double wx = bicubic[abs(dx)][0];\n\n                  if (wx != 0 && arg->inside_fn(arg, x+dx/16, y+dy/16))\n                     alphay += wx;\n               }\n\n               alpha += wy * alphay;\n            }\n         }\n\n         /* This needs to be weighted for each dimension: */\n         return alpha / (FILTER_WEIGHT*FILTER_WEIGHT);\n      }\n   }\n}\n\n/* These are the shape functions. */\n/* \"square\",\n * { inside_square_filled, check_square_filled },\n * { inside_square, check_square }\n */\nstatic int\nsquare_check(double x, double y, double x1, double y1, double x2, double y2)\n   /* Is x,y inside the square (x1,y1)..(x2,y2)? */\n{\n   /* Do a modified Cohen-Sutherland on one point, bit patterns that indicate\n    * 'outside' are:\n    *\n    *   x<x1 | x<y1 | x<x2 | x<y2\n    *    0      x      0      x     To the right\n    *    1      x      1      x     To the left\n    *    x      0      x      0     Below\n    *    x      1      x      1     Above\n    *\n    * So 'inside' is (x<x1) != (x<x2) && (y<y1) != (y<y2);\n    */\n   return ((x<x1) ^ (x<x2)) & ((y<y1) ^ (y<y2));\n}\n\nstatic int\ninside_square_filled(const struct arg *arg, double x, double y)\n{\n   return square_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2);\n}\n\nstatic int\nsquare_check_line(const struct arg *arg, double x, double y, double w)\n   /* Check for a point being inside the boundaries implied by the given arg\n    * and assuming a width 2*w each side of the boundaries.  This returns the\n    * 'check' INSIDE/OUTSIDE/0 result but note the semantics:\n    *\n    *          +--------------+\n    *          |              |   OUTSIDE\n    *          |   INSIDE     |\n    *          |              |\n    *          +--------------+\n    *\n    * And '0' means within the line boundaries.\n    */\n{\n   double cx = (arg->x1+arg->x2)/2;\n   double wx = fabs(arg->x1-arg->x2)/2;\n   double cy = (arg->y1+arg->y2)/2;\n   double wy = fabs(arg->y1-arg->y2)/2;\n\n   if (square_check(x, y, cx-wx-w, cy-wy-w, cx+wx+w, cy+wy+w))\n   {\n      /* Inside, but maybe too far; check for the redundant case where\n       * the lines overlap:\n       */\n      wx -= w;\n      wy -= w;\n      if (wx > 0 && wy > 0 && square_check(x, y, cx-wx, cy-wy, cx+wx, cy+wy))\n         return INSIDE; /* between (inside) the boundary lines. */\n\n      return 0; /* inside the lines themselves. */\n   }\n\n   return OUTSIDE; /* outside the boundary lines. */\n}\n\nstatic int\ncheck_square_filled(const struct arg *arg, double x, double y)\n{\n   /* The filter extends +/-FILTER_WIDTH each side of each output point, so\n    * the check has to expand and contract the square by that amount; '0'\n    * means close enough to the edge of the square that the bicubic filter has\n    * to be run, OUTSIDE means alpha==0, INSIDE means alpha==1.\n    */\n   return square_check_line(arg, x, y, FILTER_WIDTH);\n}\n\nstatic int\ninside_square(const struct arg *arg, double x, double y)\n{\n   /* Return true if within the drawn lines, else false, no need to distinguish\n    * INSIDE vs OUTSIDE here:\n    */\n   return square_check_line(arg, x, y, arg->width/2) == 0;\n}\n\nstatic int\ncheck_square(const struct arg *arg, double x, double y)\n{\n   /* So for this function a result of 'INSIDE' means inside the actual lines.\n    */\n   double w = arg->width/2;\n\n   if (square_check_line(arg, x, y, w+FILTER_WIDTH) == 0)\n   {\n      /* Somewhere close to the boundary lines. If far enough inside one of\n       * them then we can return INSIDE:\n       */\n      w -= FILTER_WIDTH;\n\n      if (w > 0 && square_check_line(arg, x, y, w) == 0)\n         return INSIDE;\n\n      /* Point is somewhere in the filter region: */\n      return 0;\n   }\n\n   else /* Inside or outside the square by more than w+FILTER_WIDTH. */\n      return OUTSIDE;\n}\n\n/* \"circle\",\n * { inside_circle_filled, check_circle_filled },\n * { inside_circle, check_circle }\n *\n * The functions here are analoguous to the square ones; however, they check\n * the corresponding ellipse as opposed to the rectangle.\n */\nstatic int\ncircle_check(double x, double y, double x1, double y1, double x2, double y2)\n{\n   if (square_check(x, y, x1, y1, x2, y2))\n   {\n      /* Inside the square, so maybe inside the circle too: */\n      const double cx = (x1 + x2)/2;\n      const double cy = (y1 + y2)/2;\n      const double dx = x1 - x2;\n      const double dy = y1 - y2;\n\n      x = (x - cx)/dx;\n      y = (y - cy)/dy;\n\n      /* It is outside if the distance from the center is more than half the\n       * diameter:\n       */\n      return x*x+y*y < .25;\n   }\n\n   return 0; /* outside */\n}\n\nstatic int\ninside_circle_filled(const struct arg *arg, double x, double y)\n{\n   return circle_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2);\n}\n\nstatic int\ncircle_check_line(const struct arg *arg, double x, double y, double w)\n   /* Check for a point being inside the boundaries implied by the given arg\n    * and assuming a width 2*w each side of the boundaries.  This function has\n    * the same semantic as square_check_line but tests the circle.\n    */\n{\n   double cx = (arg->x1+arg->x2)/2;\n   double wx = fabs(arg->x1-arg->x2)/2;\n   double cy = (arg->y1+arg->y2)/2;\n   double wy = fabs(arg->y1-arg->y2)/2;\n\n   if (circle_check(x, y, cx-wx-w, cy-wy-w, cx+wx+w, cy+wy+w))\n   {\n      /* Inside, but maybe too far; check for the redundant case where\n       * the lines overlap:\n       */\n      wx -= w;\n      wy -= w;\n      if (wx > 0 && wy > 0 && circle_check(x, y, cx-wx, cy-wy, cx+wx, cy+wy))\n         return INSIDE; /* between (inside) the boundary lines. */\n\n      return 0; /* inside the lines themselves. */\n   }\n\n   return OUTSIDE; /* outside the boundary lines. */\n}\n\nstatic int\ncheck_circle_filled(const struct arg *arg, double x, double y)\n{\n   return circle_check_line(arg, x, y, FILTER_WIDTH);\n}\n\nstatic int\ninside_circle(const struct arg *arg, double x, double y)\n{\n   return circle_check_line(arg, x, y, arg->width/2) == 0;\n}\n\nstatic int\ncheck_circle(const struct arg *arg, double x, double y)\n{\n   /* Exactly as the 'square' code.  */\n   double w = arg->width/2;\n\n   if (circle_check_line(arg, x, y, w+FILTER_WIDTH) == 0)\n   {\n      w -= FILTER_WIDTH;\n\n      if (w > 0 && circle_check_line(arg, x, y, w) == 0)\n         return INSIDE;\n\n      /* Point is somewhere in the filter region: */\n      return 0;\n   }\n\n   else /* Inside or outside the square by more than w+FILTER_WIDTH. */\n      return OUTSIDE;\n}\n\n/* \"line\",\n * { NULL, NULL },  There is no 'filled' line.\n * { inside_line, check_line }\n */\nstatic int\nline_check(double x, double y, double x1, double y1, double x2, double y2,\n   double w, double expand)\n{\n   /* Shift all the points to (arg->x1, arg->y1) */\n   double lx = x2 - x1;\n   double ly = y2 - y1;\n   double len2 = lx*lx + ly*ly;\n   double cross, dot;\n\n   x -= x1;\n   y -= y1;\n\n   /* The dot product is the distance down the line, the cross product is\n    * the distance away from the line:\n    *\n    *    distance = |cross| / sqrt(len2)\n    */\n   cross = x * ly - y * lx;\n\n   /* If 'distance' is more than w the point is definitely outside the line:\n    *\n    *     distance >= w\n    *     |cross|  >= w * sqrt(len2)\n    *     cross^2  >= w^2 * len2:\n    */\n   if (cross*cross >= (w+expand)*(w+expand)*len2)\n      return 0; /* outside */\n\n   /* Now find the distance *along* the line; this comes from the dot product\n    * lx.x+ly.y. The actual distance (in pixels) is:\n    *\n    *   distance = dot / sqrt(len2)\n    */\n   dot = lx * x + ly * y;\n\n   /* The test for 'outside' is:\n    *\n    *    distance < 0 || distance > sqrt(len2)\n    *                 -> dot / sqrt(len2) > sqrt(len2)\n    *                 -> dot > len2\n    *\n    * But 'expand' is used for the filter width and needs to be handled too:\n    */\n   return dot > -expand && dot < len2+expand;\n}\n\nstatic int\ninside_line(const struct arg *arg, double x, double y)\n{\n   return line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2, 0);\n}\n\nstatic int\ncheck_line(const struct arg *arg, double x, double y)\n{\n   /* The end caps of the line must be checked too; it's not enough just to\n    * widen the line by FILTER_WIDTH; 'expand' exists for this purpose:\n    */\n   if (line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2,\n       FILTER_WIDTH))\n   {\n      /* Inside the line+filter; far enough inside that the filter isn't\n       * required?\n       */\n      if (arg->width > 2*FILTER_WIDTH &&\n          line_check(x, y, arg->x1, arg->y1, arg->x2, arg->y2, arg->width/2,\n             -FILTER_WIDTH))\n         return INSIDE;\n\n      return 0;\n   }\n\n   return OUTSIDE;\n}\n\nstatic const struct\n{\n   const char    *name;\n   shape_fn_ptr   function[2/*fill,line*/][2];\n#  define         FN_INSIDE 0\n#  define         FN_CHECK 1\n} shape_defs[] =\n{\n   {  \"square\",\n      {  { inside_square_filled, check_square_filled },\n         { inside_square, check_square } }\n   },\n   {  \"circle\",\n      {  { inside_circle_filled, check_circle_filled },\n         { inside_circle, check_circle } }\n   },\n   {  \"line\",\n      {  { NULL, NULL },\n         { inside_line, check_line } }\n   }\n};\n\n#define shape_count ((sizeof shape_defs)/(sizeof shape_defs[0]))\n\nstatic shape_fn_ptr\nshape_of(const char *arg, double width, int f)\n{\n   unsigned int i;\n\n   for (i=0; i<shape_count; ++i) if (strcmp(shape_defs[i].name, arg) == 0)\n   {\n      shape_fn_ptr fn = shape_defs[i].function[width != 0][f];\n\n      if (fn != NULL)\n         return fn;\n\n      fprintf(stderr, \"genpng: %s %s not supported\\n\",\n         width == 0 ? \"filled\" : \"unfilled\", arg);\n      exit(1);\n   }\n\n   fprintf(stderr, \"genpng: %s: not a valid shape name\\n\", arg);\n   exit(1);\n}\n\nstatic void\nparse_arg(struct arg *arg, const char **argv/*7 arguments*/)\n{\n   /* shape ::= color width shape x1 y1 x2 y2 */\n   arg->color = color_of(argv[0]);\n   arg->width = width_of(argv[1]);\n   arg->inside_fn = shape_of(argv[2], arg->width, FN_INSIDE);\n   arg->check_fn = shape_of(argv[2], arg->width, FN_CHECK);\n   arg->x1 = coordinate_of(argv[3]);\n   arg->y1 = coordinate_of(argv[4]);\n   arg->x2 = coordinate_of(argv[5]);\n   arg->y2 = coordinate_of(argv[6]);\n}\n\nstatic png_uint_32\nread_wh(const char *name, const char *str)\n   /* read a PNG width or height */\n{\n   char *ep = NULL;\n   unsigned long ul = strtoul(str, &ep, 10);\n\n   if (ep != NULL && *ep == 0 && ul > 0 && ul <= 0x7fffffff)\n      return (png_uint_32)/*SAFE*/ul;\n\n   fprintf(stderr, \"genpng: %s: invalid number %s\\n\", name, str);\n   exit(1);\n}\n\nstatic void\npixel(png_uint_16p p, struct arg *args, int nargs, double x, double y)\n{\n   /* Fill in the pixel by checking each shape (args[nargs]) for effects on\n    * the corresponding sample:\n    */\n   double r=0, g=0, b=0, a=0;\n\n   while (--nargs >= 0 && a != 1)\n   {\n      /* NOTE: alpha_calc can return a value outside the range 0..1 with the\n       * bicubic filter.\n       */\n      const double alpha = alpha_calc(args+nargs, x, y) * (1-a);\n\n      r += alpha * args[nargs].color->red;\n      g += alpha * args[nargs].color->green;\n      b += alpha * args[nargs].color->blue;\n      a += alpha;\n   }\n\n   /* 'a' may be negative or greater than 1; if it is, negative clamp the\n    * pixel to 0 if >1 clamp r/g/b:\n    */\n   if (a > 0)\n   {\n      if (a > 1)\n      {\n         if (r > 1) r = 1;\n         if (g > 1) g = 1;\n         if (b > 1) b = 1;\n         a = 1;\n      }\n\n      /* And fill in the pixel: */\n      p[0] = (png_uint_16)/*SAFE*/round(r * 65535);\n      p[1] = (png_uint_16)/*SAFE*/round(g * 65535);\n      p[2] = (png_uint_16)/*SAFE*/round(b * 65535);\n      p[3] = (png_uint_16)/*SAFE*/round(a * 65535);\n   }\n\n   else\n      p[3] = p[2] = p[1] = p[0] = 0;\n}\n\nint\nmain(int argc, const char **argv)\n{\n   int convert_to_8bit = 0;\n\n   /* There is one option: --8bit: */\n   if (argc > 1 && strcmp(argv[1], \"--8bit\") == 0)\n      --argc, ++argv, convert_to_8bit = 1;\n\n   if (argc >= 3)\n   {\n      png_uint_16p buffer;\n      int nshapes;\n      png_image image;\n#     define max_shapes 256\n      struct arg arg_list[max_shapes];\n\n      /* The libpng Simplified API write code requires a fully initialized\n       * structure.\n       */\n      memset(&image, 0, sizeof image);\n      image.version = PNG_IMAGE_VERSION;\n      image.opaque = NULL;\n      image.width = read_wh(\"width\", argv[1]);\n      image.height = read_wh(\"height\", argv[2]);\n      image.format = PNG_FORMAT_LINEAR_RGB_ALPHA;\n      image.flags = 0;\n      image.colormap_entries = 0;\n\n      /* Check the remainder of the arguments */\n      for (nshapes=0; 3+7*(nshapes+1) <= argc && nshapes < max_shapes;\n           ++nshapes)\n         parse_arg(arg_list+nshapes, argv+3+7*nshapes);\n\n      if (3+7*nshapes != argc)\n      {\n         fprintf(stderr, \"genpng: %s: too many arguments\\n\", argv[3+7*nshapes]);\n         return 1;\n      }\n\n      /* Create the buffer: */\n      buffer = malloc(PNG_IMAGE_SIZE(image));\n\n      if (buffer != NULL)\n      {\n         png_uint_32 y;\n\n         /* Write each row... */\n         for (y=0; y<image.height; ++y)\n         {\n            png_uint_32 x;\n\n            /* Each pixel in each row: */\n            for (x=0; x<image.width; ++x)\n               pixel(buffer + 4*(x + y*image.width), arg_list, nshapes, x, y);\n         }\n\n         /* Write the result (to stdout) */\n         if (png_image_write_to_stdio(&image, stdout, convert_to_8bit,\n             buffer, 0/*row_stride*/, NULL/*colormap*/))\n         {\n            free(buffer);\n            return 0; /* success */\n         }\n\n         else\n            fprintf(stderr, \"genpng: write stdout: %s\\n\", image.message);\n\n         free(buffer);\n      }\n\n      else\n         fprintf(stderr, \"genpng: out of memory: %lu bytes\\n\",\n               (unsigned long)PNG_IMAGE_SIZE(image));\n   }\n\n   else\n   {\n      /* Wrong number of arguments */\n      fprintf(stderr, \"genpng: usage: genpng [--8bit] width height {shape}\\n\"\n         \" Generate a transparent PNG in RGBA (truecolor+alpha) format\\n\"\n         \" containing the given shape or shapes.  Shapes are defined:\\n\"\n         \"\\n\"\n         \"  shape ::= color width shape x1 y1 x2 y2\\n\"\n         \"  color ::= black|white|red|green|yellow|blue\\n\"\n         \"  color ::= brown|purple|pink|orange|gray|cyan\\n\"\n         \"  width ::= filled|<number>\\n\"\n         \"  shape ::= circle|square|line\\n\"\n         \"  x1,x2 ::= <number>\\n\"\n         \"  y1,y2 ::= <number>\\n\"\n         \"\\n\"\n         \" Numbers are floating point numbers describing points relative to\\n\"\n         \" the top left of the output PNG as pixel coordinates.  The 'width'\\n\"\n         \" parameter is either the width of the line (in output pixels) used\\n\"\n         \" to draw the shape or 'filled' to indicate that the shape should\\n\"\n         \" be filled with the color.\\n\"\n         \"\\n\"\n         \" Colors are interpreted loosely to give access to the eight full\\n\"\n         \" intensity RGB values:\\n\"\n         \"\\n\"\n         \"  black, red, green, blue, yellow, cyan, purple, white,\\n\"\n         \"\\n\"\n         \" Cyan is full intensity blue+green; RGB(0,1,1), plus the following\\n\"\n         \" lower intensity values:\\n\"\n         \"\\n\"\n         \"  brown:  red+orange:  RGB(0.5, 0.125, 0) (dark red+orange)\\n\"\n         \"  pink:   red+white:   RGB(1.0, 0.5,   0.5)\\n\"\n         \"  orange: red+yellow:  RGB(1.0, 0.5,   0)\\n\"\n         \"  gray:   black+white: RGB(0.5, 0.5,   0.5)\\n\"\n         \"\\n\"\n         \" The RGB values are selected to make detection of aliasing errors\\n\"\n         \" easy. The names are selected to make the description of errors\\n\"\n         \" easy.\\n\"\n         \"\\n\"\n         \" The PNG is written to stdout, if --8bit is given a 32bpp RGBA sRGB\\n\"\n         \" file is produced, otherwise a 64bpp RGBA linear encoded file is\\n\"\n         \" written.\\n\");\n   }\n\n   return 1;\n}\n#endif /* SIMPLIFIED_WRITE && STDIO */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/intgamma.sh",
    "content": "#!/bin/sh\n#\n# intgamma.sh\n#\n# Last changed in libpng 1.6.0 [February 14, 2013]\n#\n# COPYRIGHT: Written by John Cunningham Bowler, 2013.\n# To the extent possible under law, the author has waived all copyright and\n# related or neighboring rights to this work.  This work is published from:\n# United States.\n#\n# Shell script to generate png.c 8-bit and 16-bit log tables (see the code in\n# png.c for details).\n#\n# This script uses the \"bc\" arbitrary precision calculator to calculate 32-bit\n# fixed point values of logarithms appropriate to finding the log of an 8-bit\n# (0..255) value and a similar table for the exponent calculation.\n#\n# \"bc\" must be on the path when the script is executed, and the math library\n# (-lm) must be available\n#\n# function to print out a list of numbers as integers; the function truncates\n# the integers which must be one-per-line\nfunction print(){\n   awk 'BEGIN{\n      str = \"\"\n   }\n   {\n      sub(\"\\\\.[0-9]*$\", \"\")\n      if ($0 == \"\")\n         $0 = \"0\"\n\n      if (str == \"\")\n         t = \"   \" $0 \"U\"\n      else\n         t = str \", \" $0 \"U\"\n\n      if (length(t) >= 80) {\n         print str \",\"\n         str = \"   \" $0 \"U\"\n      } else\n         str = t\n   }\n   END{\n      print str\n   }'\n}\n#\n# The logarithm table.\ncat <<END\n/* 8-bit log table: png_8bit_l2[128]\n * This is a table of -log(value/255)/log(2) for 'value' in the range 128 to\n * 255, so it's the base 2 logarithm of a normalized 8-bit floating point\n * mantissa.  The numbers are 32-bit fractions.\n */\nstatic const png_uint_32\npng_8bit_l2[128] =\n{\nEND\n#\nbc -lqws <<END | print\nf=65536*65536/l(2)\nfor (i=128;i<256;++i) { .5 - l(i/255)*f; }\nEND\necho '};'\necho\n#\n# The exponent table.\ncat <<END\n/* The 'exp()' case must invert the above, taking a 20-bit fixed point\n * logarithmic value and returning a 16 or 8-bit number as appropriate.  In\n * each case only the low 16 bits are relevant - the fraction - since the\n * integer bits (the top 4) simply determine a shift.\n *\n * The worst case is the 16-bit distinction between 65535 and 65534; this\n * requires perhaps spurious accuracy in the decoding of the logarithm to\n * distinguish log2(65535/65534.5) - 10^-5 or 17 bits.  There is little chance\n * of getting this accuracy in practice.\n *\n * To deal with this the following exp() function works out the exponent of the\n * frational part of the logarithm by using an accurate 32-bit value from the\n * top four fractional bits then multiplying in the remaining bits.\n */\nstatic const png_uint_32\npng_32bit_exp[16] =\n{\nEND\n#\nbc -lqws <<END | print\nf=l(2)/16\nfor (i=0;i<16;++i) {\n   x = .5 + e(-i*f)*2^32;\n   if (x >= 2^32) x = 2^32-1;\n   x;\n}\nEND\necho '};'\necho\n#\n# And the table of adjustment values.\ncat <<END\n/* Adjustment table; provided to explain the numbers in the code below. */\n#if 0\nEND\nbc -lqws <<END | awk '{ printf \"%5d %s\\n\", 12-NR, $0 }'\nfor (i=11;i>=0;--i){\n   (1 - e(-(2^i)/65536*l(2))) * 2^(32-i)\n}\nEND\necho '#endif'\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/makesRGB.c",
    "content": "/* makesRGB.c -- build sRGB-to-linear and linear-to-sRGB conversion tables\n *\n * Last changed in libpng 1.6.0 [February 14, 2013]\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2013.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Make a table to convert 8-bit sRGB encoding values into the closest 16-bit\n * linear value.\n *\n * Make two tables to take a linear value scaled to 255*65535 and return an\n * approximation to the 8-bit sRGB encoded value.  Calculate the error in these\n * tables and display it.\n */\n#define _C99_SOURCE 1\n#include <stdio.h>\n#include <math.h>\n#include <stdlib.h>\n\n/* pngpriv.h includes the definition of 'PNG_sRGB_FROM_LINEAR' which is required\n * to verify the actual code.\n */\n#include \"../../pngpriv.h\"\n\n#include \"sRGB.h\"\n\n/* The tables are declared 'const' in pngpriv.h, so this redefines the tables to\n * be used.\n */\n#define png_sRGB_table sRGB_table\n#define png_sRGB_base sRGB_base\n#define png_sRGB_delta sRGB_delta\n\nstatic png_uint_16 png_sRGB_table[256];\nstatic png_uint_16 png_sRGB_base[512];\nstatic png_byte png_sRGB_delta[512];\n\nstatic const unsigned int max_input = 255*65535;\n\ndouble\nfsRGB(double l)\n{\n   return sRGB_from_linear(l/max_input);\n}\n\ndouble\nsRGB(unsigned int i)\n{\n   return fsRGB(i);\n}\n\ndouble\nfinvsRGB(unsigned int i)\n{\n   return 65535 * linear_from_sRGB(i/255.);\n}\n\npng_uint_16\ninvsRGB(unsigned int i)\n{\n   unsigned int x = nearbyint(finvsRGB(i));\n\n   if (x > 65535)\n   {\n      fprintf(stderr, \"invsRGB(%u) overflows to %u\\n\", i, x);\n      exit(1);\n   }\n\n   return (png_uint_16)x;\n}\n\nint\nmain(int argc, char **argv)\n{\n   unsigned int i, i16, ibase;\n   double min_error = 0;\n   double max_error = 0;\n   double min_error16 = 0;\n   double max_error16 = 0;\n   double adjust;\n   double adjust_lo = 0.4, adjust_hi = 0.6, adjust_mid = 0.5;\n   unsigned int ec_lo = 0, ec_hi = 0, ec_mid = 0;\n   unsigned int error_count = 0;\n   unsigned int error_count16 = 0;\n   int test_only = 0;\n\n   if (argc > 1)\n      test_only = strcmp(\"--test\", argv[1]) == 0;\n\n   /* Initialize the encoding table first. */\n   for (i=0; i<256; ++i)\n   {\n      png_sRGB_table[i] = invsRGB(i);\n   }\n\n   /* Now work out the decoding tables (this is where the error comes in because\n    * there are 512 set points and 512 straight lines between them.)\n    */\n   for (;;)\n   {\n      if (ec_lo == 0)\n         adjust = adjust_lo;\n\n      else if (ec_hi == 0)\n         adjust = adjust_hi;\n\n      else if (ec_mid == 0)\n         adjust = adjust_mid;\n\n      else if (ec_mid < ec_hi)\n         adjust = (adjust_mid + adjust_hi)/2;\n\n      else if (ec_mid < ec_lo)\n         adjust = (adjust_mid + adjust_lo)/2;\n\n      else\n      {\n         fprintf(stderr, \"not reached: %u .. %u .. %u\\n\", ec_lo, ec_mid, ec_hi);\n         exit(1);\n      }\n\n      /* Calculate the table using the current 'adjust' */\n      for (i=0; i<=511; ++i)\n      {\n         double lo = 255 * sRGB(i << 15);\n         double hi = 255 * sRGB((i+1) << 15);\n         unsigned int calc;\n\n         calc = nearbyint((lo+adjust) * 256);\n         if (calc > 65535)\n         {\n            fprintf(stderr, \"table[%d][0]: overflow %08x (%d)\\n\", i, calc,\n               calc);\n            exit(1);\n         }\n         png_sRGB_base[i] = calc;\n\n         calc = nearbyint((hi-lo) * 32);\n         if (calc > 255)\n         {\n            fprintf(stderr, \"table[%d][1]: overflow %08x (%d)\\n\", i, calc,\n               calc);\n            exit(1);\n         }\n         png_sRGB_delta[i] = calc;\n      }\n\n      /* Check the 16-bit linear values alone: */\n      error_count16 = 0;\n      for (i16=0; i16 <= 65535; ++i16)\n      {\n         unsigned int i = 255*i16;\n         unsigned int iexact = nearbyint(255*sRGB(i));\n         unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);\n\n         if (icalc != iexact)\n            ++error_count16;\n      }\n\n      /* Now try changing the adjustment. */\n      if (ec_lo == 0)\n         ec_lo = error_count16;\n\n      else if (ec_hi == 0)\n         ec_hi = error_count16;\n\n      else if (ec_mid == 0)\n      {\n         ec_mid = error_count16;\n         printf(\"/* initial error counts: %u .. %u .. %u */\\n\", ec_lo, ec_mid,\n            ec_hi);\n      }\n\n      else if (error_count16 < ec_mid)\n      {\n         printf(\"/* adjust (mid ): %f: %u -> %u */\\n\", adjust, ec_mid,\n            error_count16);\n         ec_mid = error_count16;\n         adjust_mid = adjust;\n      }\n\n      else if (adjust < adjust_mid && error_count16 < ec_lo)\n      {\n         printf(\"/* adjust (low ): %f: %u -> %u */\\n\", adjust, ec_lo,\n            error_count16);\n         ec_lo = error_count16;\n         adjust_lo = adjust;\n      }\n\n      else if (adjust > adjust_mid && error_count16 < ec_hi)\n      {\n         printf(\"/* adjust (high): %f: %u -> %u */\\n\", adjust, ec_hi,\n            error_count16);\n         ec_hi = error_count16;\n         adjust_hi = adjust;\n      }\n\n      else\n      {\n         adjust = adjust_mid;\n         printf(\"/* adjust: %f: %u */\\n\", adjust, ec_mid);\n         break;\n      }\n   }\n\n   /* For each entry in the table try to adjust it to minimize the error count\n    * in that entry.  Each entry corresponds to 128 input values.\n    */\n   for (ibase=0; ibase<65536; ibase+=128)\n   {\n      png_uint_16 base = png_sRGB_base[ibase >> 7], trybase = base, ob=base;\n      png_byte delta = png_sRGB_delta[ibase >> 7], trydelta = delta, od=delta;\n      unsigned int ecbase = 0, eco;\n\n      for (;;)\n      {\n         png_sRGB_base[ibase >> 7] = trybase;\n         png_sRGB_delta[ibase >> 7] = trydelta;\n\n         /* Check the 16-bit linear values alone: */\n         error_count16 = 0;\n         for (i16=ibase; i16 < ibase+128; ++i16)\n         {\n            unsigned int i = 255*i16;\n            unsigned int iexact = nearbyint(255*sRGB(i));\n            unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);\n\n            if (icalc != iexact)\n               ++error_count16;\n         }\n\n         if (error_count16 == 0)\n            break;\n\n         if (ecbase == 0)\n         {\n            eco = ecbase = error_count16;\n            ++trybase; /* First test */\n         }\n\n         else if (error_count16 < ecbase)\n         {\n            if (trybase > base)\n            {\n               base = trybase;\n               ++trybase;\n            }\n            else if (trybase < base)\n            {\n               base = trybase;\n               --trybase;\n            }\n            else if (trydelta > delta)\n            {\n               delta = trydelta;\n               ++trydelta;\n            }\n            else if (trydelta < delta)\n            {\n               delta = trydelta;\n               --trydelta;\n            }\n            else\n            {\n               fprintf(stderr, \"makesRGB: impossible\\n\");\n               exit(1);\n            }\n            ecbase = error_count16;\n         }\n\n         else\n         {\n            if (trybase > base)\n               trybase = base-1;\n            else if (trybase < base)\n            {\n               trybase = base;\n               ++trydelta;\n            }\n            else if (trydelta > delta)\n               trydelta = delta-1;\n            else if (trydelta < delta)\n               break; /* end of tests */\n         }\n      }\n\n      png_sRGB_base[ibase >> 7] = base;\n      png_sRGB_delta[ibase >> 7] = delta;\n      if (base != ob || delta != od)\n      {\n         printf(\"/* table[%u]={%u,%u} -> {%u,%u} %u -> %u errors */\\n\",\n            ibase>>7, ob, od, base, delta, eco, ecbase);\n      }\n      else if (0)\n         printf(\"/* table[%u]={%u,%u} %u errors */\\n\", ibase>>7, ob, od,\n            ecbase);\n   }\n\n   /* Only do the full (slow) test at the end: */\n   min_error = -.4999;\n   max_error = .4999;\n   error_count = 0;\n\n   for (i=0; i <= max_input; ++i)\n   {\n      unsigned int iexact = nearbyint(255*sRGB(i));\n      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);\n\n      if (icalc != iexact)\n      {\n         double err = 255*sRGB(i) - icalc;\n\n         if (err > (max_error+.001) || err < (min_error-.001))\n         {\n            printf(\n               \"/* 0x%08x: exact: %3d, got: %3d [tables: %08x, %08x] (%f) */\\n\",\n               i, iexact, icalc, png_sRGB_base[i>>15],\n               png_sRGB_delta[i>>15], err);\n         }\n\n         ++error_count;\n         if (err > max_error)\n            max_error = err;\n         else if (err < min_error)\n            min_error = err;\n      }\n   }\n\n   /* Re-check the 16-bit cases too, including the warning if there is an error\n    * bigger than 1.\n    */\n   error_count16 = 0;\n   max_error16 = 0;\n   min_error16 = 0;\n   for (i16=0; i16 <= 65535; ++i16)\n   {\n      unsigned int i = 255*i16;\n      unsigned int iexact = nearbyint(255*sRGB(i));\n      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);\n\n      if (icalc != iexact)\n      {\n         double err = 255*sRGB(i) - icalc;\n\n         ++error_count16;\n         if (err > max_error16)\n            max_error16 = err;\n         else if (err < min_error16)\n            min_error16 = err;\n\n         if (abs(icalc - iexact) > 1)\n            printf(\n               \"/* 0x%04x: exact: %3d, got: %3d [tables: %08x, %08x] (%f) */\\n\",\n               i16, iexact, icalc, png_sRGB_base[i>>15],\n               png_sRGB_delta[i>>15], err);\n      }\n   }\n\n   /* Check the round trip for each 8-bit sRGB value. */\n   for (i16=0; i16 <= 255; ++i16)\n   {\n      unsigned int i = 255 * png_sRGB_table[i16];\n      unsigned int iexact = nearbyint(255*sRGB(i));\n      unsigned int icalc = PNG_sRGB_FROM_LINEAR(i);\n\n      if (i16 != iexact)\n      {\n         fprintf(stderr, \"8-bit rounding error: %d -> %d\\n\", i16, iexact);\n         exit(1);\n      }\n\n      if (icalc != i16)\n      {\n         double finv = finvsRGB(i16);\n\n         printf(\"/* 8-bit roundtrip error: %d -> %f -> %d(%f) */\\n\",\n            i16, finv, icalc, fsRGB(255*finv));\n      }\n   }\n\n\n   printf(\"/* error: %g - %g, %u (%g%%) of readings inexact */\\n\",\n      min_error, max_error, error_count, (100.*error_count)/max_input);\n   printf(\"/* 16-bit error: %g - %g, %u (%g%%) of readings inexact */\\n\",\n      min_error16, max_error16, error_count16, (100.*error_count16)/65535);\n\n   if (!test_only)\n   {\n      printf(\"PNG_CONST png_uint_16 png_sRGB_table[256] =\\n{\\n   \");\n      for (i=0; i<255; )\n      {\n         do\n         {\n            printf(\"%d,\", png_sRGB_table[i++]);\n         }\n         while ((i & 0x7) != 0 && i<255);\n         if (i<255) printf(\"\\n   \");\n      }\n      printf(\"%d\\n};\\n\\n\", png_sRGB_table[i]);\n\n\n      printf(\"PNG_CONST png_uint_16 png_sRGB_base[512] =\\n{\\n   \");\n      for (i=0; i<511; )\n      {\n         do\n         {\n            printf(\"%d,\", png_sRGB_base[i++]);\n         }\n         while ((i & 0x7) != 0 && i<511);\n         if (i<511) printf(\"\\n   \");\n      }\n      printf(\"%d\\n};\\n\\n\", png_sRGB_base[i]);\n\n      printf(\"PNG_CONST png_byte png_sRGB_delta[512] =\\n{\\n   \");\n      for (i=0; i<511; )\n      {\n         do\n         {\n            printf(\"%d,\", png_sRGB_delta[i++]);\n         }\n         while ((i & 0xf) != 0 && i<511);\n         if (i<511) printf(\"\\n   \");\n      }\n      printf(\"%d\\n};\\n\\n\", png_sRGB_delta[i]);\n   }\n\n   return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/png-fix-itxt.c",
    "content": "\n/* png-fix-itxt version 1.0.0\n *\n * Copyright 2015 Glenn Randers-Pehrson\n * Last changed in libpng 1.6.18 [July 23, 2015]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Usage:\n *\n *     png-fix-itxt.exe < bad.png > good.png\n *\n * Fixes a PNG file written with libpng-1.6.0 or 1.6.1 that has one or more\n * uncompressed iTXt chunks.  Assumes that the actual length is greater\n * than or equal to the value in the length byte, and that the CRC is\n * correct for the actual length.  This program hunts for the CRC and\n * adjusts the length byte accordingly.  It is not an error to process a\n * PNG file that has no iTXt chunks or one that has valid iTXt chunks;\n * such files will simply be copied.\n *\n * Requires zlib (for crc32 and Z_NULL); build with\n *\n *     gcc -O -o png-fix-itxt png-fix-itxt.c -lz\n *\n * If you need to handle iTXt chunks larger than 500000 kbytes you must\n * rebuild png-fix-itxt with a larger values of MAX_LENGTH (or a smaller value\n * if you know you will never encounter such huge iTXt chunks).\n */\n\n#include <stdio.h>\n#include <zlib.h>\n\n#define MAX_LENGTH 500000\n\n/* Read one character (inchar), also return octet (c), break if EOF */\n#define GETBREAK inchar=getchar(); \\\n                 c=(inchar & 0xffU);\\\n                 if (inchar != c) break\nint\nmain(void)\n{\n   unsigned int i;\n   unsigned char buf[MAX_LENGTH];\n   unsigned long crc;\n   unsigned char c;\n   int inchar;\n\n/* Skip 8-byte signature */\n   for (i=8; i; i--)\n   {\n      GETBREAK;\n      putchar(c);\n   }\n\nif (inchar == c) /* !EOF */\nfor (;;)\n {\n   /* Read the length */\n   unsigned long length; /* must be 32 bits! */\n   GETBREAK; buf[0] = c; length  = c; length <<= 8;\n   GETBREAK; buf[1] = c; length += c; length <<= 8;\n   GETBREAK; buf[2] = c; length += c; length <<= 8;\n   GETBREAK; buf[3] = c; length += c;\n\n   /* Read the chunkname */\n   GETBREAK; buf[4] = c;\n   GETBREAK; buf[5] = c;\n   GETBREAK; buf[6] = c;\n   GETBREAK; buf[7] = c;\n\n\n   /* The iTXt chunk type expressed as integers is (105, 84, 88, 116) */\n   if (buf[4] == 105 && buf[5] == 84 && buf[6] == 88 && buf[7] == 116)\n   {\n      if (length >= MAX_LENGTH-12)\n         break;  /* To do: handle this more gracefully */\n\n      /* Initialize the CRC */\n      crc = crc32(0, Z_NULL, 0);\n\n      /* Copy the data bytes */\n      for (i=8; i < length + 12; i++)\n      {\n         GETBREAK; buf[i] = c;\n      }\n\n      if (inchar != c) /* EOF */\n         break;\n\n      /* Calculate the CRC */\n      crc = crc32(crc, buf+4, (uInt)length+4);\n\n      for (;;)\n      {\n        /* Check the CRC */\n        if (((crc >> 24) & 0xffU) == buf[length+8] &&\n            ((crc >> 16) & 0xffU) == buf[length+9] &&\n            ((crc >>  8) & 0xffU) == buf[length+10] &&\n            ((crc      ) & 0xffU) == buf[length+11])\n           break;\n\n        length++;\n\n        if (length >= MAX_LENGTH-12)\n           break;\n\n        GETBREAK;\n        buf[length+11] = c;\n\n        /* Update the CRC */\n        crc = crc32(crc, buf+7+length, 1);\n      }\n\n      if (inchar != c) /* EOF */\n         break;\n\n      /* Update length bytes */\n      buf[0] = (unsigned char)((length >> 24) & 0xffU);\n      buf[1] = (unsigned char)((length >> 16) & 0xffU);\n      buf[2] = (unsigned char)((length >>  8) & 0xffU);\n      buf[3] = (unsigned char)((length      ) & 0xffU);\n\n      /* Write the fixed iTXt chunk (length, name, data, crc) */\n      for (i=0; i<length+12; i++)\n         putchar(buf[i]);\n   }\n\n   else\n   {\n      if (inchar != c) /* EOF */\n         break;\n\n      /* Copy bytes that were already read (length and chunk name) */\n      for (i=0; i<8; i++)\n         putchar(buf[i]);\n\n      /* Copy data bytes and CRC */\n      for (i=8; i< length+12; i++)\n      {\n         GETBREAK;\n         putchar(c);\n      }\n\n      if (inchar != c) /* EOF */\n      {\n         break;\n      }\n\n   /* The IEND chunk type expressed as integers is (73, 69, 78, 68) */\n      if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)\n         break;\n   }\n\n   if (inchar != c) /* EOF */\n      break;\n\n   if (buf[4] == 73 && buf[5] == 69 && buf[6] == 78 && buf[7] == 68)\n     break;\n }\n\n return 0;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/pngcp.c",
    "content": "/* pngcp.c\n *\n * Copyright (c) 2016 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This is an example of copying a PNG without changes using the png_read_png\n * and png_write_png interfaces.  A considerable number of options are provided\n * to manipulate the compression of the PNG data and other compressed chunks.\n *\n * For a more extensive example that uses the transforms see\n * contrib/libtests/pngimage.c in the libpng distribution.\n */\n#include \"pnglibconf.h\" /* To find how libpng was configured. */\n\n#ifdef PNG_PNGCP_TIMING_SUPPORTED\n   /* WARNING:\n    *\n    * This test is here to allow POSIX.1b extensions to be used if enabled in\n    * the compile; specifically the code requires_POSIX_C_SOURCE support of\n    * 199309L or later to enable clock_gettime use.\n    *\n    * IF this causes problems THEN compile with a strict ANSI C compiler and let\n    * this code turn on the POSIX features that it minimally requires.\n    *\n    * IF this does not work there is probably a bug in your ANSI C compiler or\n    * your POSIX implementation.\n    */\n#  define _POSIX_C_SOURCE 199309L\n#else /* No timing support required */\n#  define _POSIX_SOURCE 1\n#endif\n\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n#endif\n\n#include <stdio.h>\n\n/* Define the following to use this test against your installed libpng, rather\n * than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n#if PNG_LIBPNG_VER < 10700\n   /* READ_PNG and WRITE_PNG were not defined, so: */\n#  ifdef PNG_INFO_IMAGE_SUPPORTED\n#     ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n#        define PNG_READ_PNG_SUPPORTED\n#     endif /* SEQUENTIAL_READ */\n#     ifdef PNG_WRITE_SUPPORTED\n#        define PNG_WRITE_PNG_SUPPORTED\n#     endif /* WRITE */\n#  endif /* INFO_IMAGE */\n#endif /* pre 1.7.0 */\n\n#if (defined(PNG_READ_PNG_SUPPORTED)) && (defined(PNG_WRITE_PNG_SUPPORTED))\n#include <stdarg.h>\n#include <stdlib.h>\n#include <string.h>\n#include <errno.h>\n#include <limits.h>\n#include <assert.h>\n\n#include <unistd.h>\n#include <sys/stat.h>\n\n#include <zlib.h>\n\n#ifndef PNG_SETJMP_SUPPORTED\n#  include <setjmp.h> /* because png.h did *not* include this */\n#endif\n\n#ifdef __cplusplus\n#  define voidcast(type, value) static_cast<type>(value)\n#else\n#  define voidcast(type, value) (value)\n#endif /* __cplusplus */\n\n#ifdef __GNUC__\n   /* Many versions of GCC erroneously report that local variables unmodified\n    * within the scope of a setjmp may be clobbered.  This hacks round the\n    * problem (sometimes) without harming other compilers.\n    */\n#  define gv volatile\n#else\n#  define gv\n#endif\n\n/* 'CLOCK_PROCESS_CPUTIME_ID' is one of the clock timers for clock_gettime.  It\n * need not be supported even when clock_gettime is available.  It returns the\n * 'CPU' time the process has consumed.  'CPU' time is assumed to include time\n * when the CPU is actually blocked by a pending cache fill but not time\n * waiting for page faults.  The attempt is to get a measure of the actual time\n * the implementation takes to read a PNG ignoring the potentially very large IO\n * overhead.\n */\n#ifdef PNG_PNGCP_TIMING_SUPPORTED\n#  include <time.h>   /* clock_gettime and associated definitions */\n#  ifndef CLOCK_PROCESS_CPUTIME_ID\n      /* Prevent inclusion of the spurious code: */\n#     undef PNG_PNGCP_TIMING_SUPPORTED\n#  endif\n#endif /* PNGCP_TIMING */\n\n/* So if the timing feature has been activated: */\n\n/* This structure is used to control the test of a single file. */\ntypedef enum\n{\n   VERBOSE,        /* switches on all messages */\n   INFORMATION,\n   WARNINGS,       /* switches on warnings */\n   LIBPNG_WARNING,\n   APP_WARNING,\n   ERRORS,         /* just errors */\n   APP_FAIL,       /* continuable error - no need to longjmp */\n   LIBPNG_ERROR,   /* this and higher cause a longjmp */\n   LIBPNG_BUG,     /* erroneous behavior in libpng */\n   APP_ERROR,      /* such as out-of-memory in a callback */\n   QUIET,          /* no normal messages */\n   USER_ERROR,     /* such as file-not-found */\n   INTERNAL_ERROR\n} error_level;\n#define LEVEL_MASK      0xf   /* where the level is in 'options' */\n\n#define STRICT          0x010 /* Fail on warnings as well as errors */\n#define LOG             0x020 /* Log pass/fail to stdout */\n#define CONTINUE        0x040 /* Continue on APP_FAIL errors */\n#define SIZES           0x080 /* Report input and output sizes */\n#define SEARCH          0x100 /* Search IDAT compression options */\n#define NOWRITE         0x200 /* Do not write an output file */\n#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#  define IGNORE_INDEX  0x400 /* Ignore out of range palette indices (BAD!) */\n#  ifdef PNG_GET_PALETTE_MAX_SUPPORTED\n#     define FIX_INDEX  0x800 /* 'Fix' out of range palette indices (OK) */\n#  endif /* GET_PALETTE_MAX */\n#endif /* CHECK_FOR_INVALID_INDEX */\n#define OPTION     0x80000000 /* Used for handling options */\n#define LIST       0x80000001 /* Used for handling options */\n\n/* Result masks apply to the result bits in the 'results' field below; these\n * bits are simple 1U<<error_level.  A pass requires either nothing worse than\n * warnings (--relaxes) or nothing worse than information (--strict)\n */\n#define RESULT_STRICT(r)   (((r) & ~((1U<<WARNINGS)-1)) == 0)\n#define RESULT_RELAXED(r)  (((r) & ~((1U<<ERRORS)-1)) == 0)\n\n/* OPTION DEFINITIONS */\nstatic const char range_lo[] = \"low\";\nstatic const char range_hi[] = \"high\";\nstatic const char all[] = \"all\";\n#define RANGE(lo,hi) { range_lo, lo }, { range_hi, hi }\ntypedef struct value_list\n{\n   const char *name;  /* the command line name of the value */\n   int         value; /* the actual value to use */\n}  value_list;\n\nstatic const value_list\n#ifdef PNG_SW_COMPRESS_png_level\nvl_compression[] =\n{\n   /* Overall compression control.  The order controls the search order for\n    * 'all'.  Since the search is for the smallest the order used is low memory\n    * then high speed.\n    */\n   { \"low-memory\",      PNG_COMPRESSION_LOW_MEMORY },\n   { \"high-speed\",      PNG_COMPRESSION_HIGH_SPEED },\n   { \"high-read-speed\", PNG_COMPRESSION_HIGH_READ_SPEED },\n   { \"low\",             PNG_COMPRESSION_LOW },\n   { \"medium\",          PNG_COMPRESSION_MEDIUM },\n   { \"old\",             PNG_COMPRESSION_COMPAT },\n   { \"high\",            PNG_COMPRESSION_HIGH },\n   { all, 0 }\n},\n#endif /* SW_COMPRESS_png_level */\n\n#if defined(PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED) ||\\\n    defined(PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED)\nvl_strategy[] =\n{\n   /* This controls the order of search. */\n   { \"huffman\", Z_HUFFMAN_ONLY },\n   { \"RLE\", Z_RLE },\n   { \"fixed\", Z_FIXED }, /* the remainder do window searchs */\n   { \"filtered\", Z_FILTERED },\n   { \"default\", Z_DEFAULT_STRATEGY },\n   { all, 0 }\n},\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\nvl_windowBits_text[] =\n{\n   { \"default\", MAX_WBITS/*from zlib*/ },\n   { \"minimum\", 8 },\n   RANGE(8, MAX_WBITS/*from zlib*/),\n   { all, 0 }\n},\n#endif /* text compression */\nvl_level[] =\n{\n   { \"default\", Z_DEFAULT_COMPRESSION /* this is -1 */ },\n   { \"none\", Z_NO_COMPRESSION },\n   { \"speed\", Z_BEST_SPEED },\n   { \"best\", Z_BEST_COMPRESSION },\n   { \"0\", Z_NO_COMPRESSION },\n   RANGE(1, 9), /* this deliberately excludes '0' */\n   { all, 0 }\n},\nvl_memLevel[] =\n{\n   { \"max\", MAX_MEM_LEVEL }, /* zlib maximum */\n   { \"1\", 1 }, /* zlib minimum */\n   { \"default\", 8 }, /* zlib default */\n   { \"2\", 2 },\n   { \"3\", 3 },\n   { \"4\", 4 },\n   { \"5\", 5 }, /* for explicit testing */\n   RANGE(6, MAX_MEM_LEVEL/*zlib*/), /* exclude 5 and below: zlib bugs */\n   { all, 0 }\n},\n#endif /* WRITE_CUSTOMIZE_*COMPRESSION */\n#ifdef PNG_WRITE_FILTER_SUPPORTED\nvl_filter[] =\n{\n   { all,      PNG_ALL_FILTERS   },\n   { \"off\",    PNG_NO_FILTERS    },\n   { \"none\",   PNG_FILTER_NONE   },\n   { \"sub\",    PNG_FILTER_SUB    },\n   { \"up\",     PNG_FILTER_UP     },\n   { \"avg\",    PNG_FILTER_AVG    },\n   { \"paeth\",  PNG_FILTER_PAETH  }\n},\n#endif /* WRITE_FILTER */\n#ifdef PNG_PNGCP_TIMING_SUPPORTED\n#  define PNGCP_TIME_READ  1\n#  define PNGCP_TIME_WRITE 2\nvl_time[] =\n{\n   { \"both\",  PNGCP_TIME_READ+PNGCP_TIME_WRITE },\n   { \"off\",   0 },\n   { \"read\",  PNGCP_TIME_READ },\n   { \"write\", PNGCP_TIME_WRITE }\n},\n#endif /* PNGCP_TIMING */\nvl_IDAT_size[] = /* for png_set_IDAT_size */\n{\n   { \"default\", 0x7FFFFFFF },\n   { \"minimal\", 1 },\n   RANGE(1, 0x7FFFFFFF)\n},\n#ifndef PNG_SW_IDAT_size\n   /* Pre 1.7 API: */\n#  define png_set_IDAT_size(p,v) png_set_compression_buffer_size(p, v)\n#endif /* !SW_IDAT_size */\n#define SL 8 /* stack limit in display, below */\nvl_log_depth[] = { { \"on\", 1 }, { \"off\", 0 }, RANGE(0, SL) },\nvl_on_off[] = { { \"on\", 1 }, { \"off\", 0 } };\n\n#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\nstatic value_list\nvl_windowBits_IDAT[] =\n{\n   { \"default\", MAX_WBITS },\n   { \"small\", 9 },\n   RANGE(8, MAX_WBITS), /* modified by set_windowBits_hi */\n   { all, 0 }\n};\n#endif /* IDAT compression */\n\ntypedef struct option\n{\n   const char       *name;         /* name of the option */\n   png_uint_32       opt;          /* an option, or OPTION or LIST */\n   png_byte          search;       /* Search on --search */\n   png_byte          value_count;  /* length of the list of values: */\n   const value_list *values;       /* values for OPTION or LIST */\n}  option;\n\nstatic const option options[] =\n{\n   /* struct display options, these are set when the command line is read */\n#  define S(n,v) { #n, v, 0, 2, vl_on_off },\n   S(verbose,  VERBOSE)\n   S(warnings, WARNINGS)\n   S(errors,   ERRORS)\n   S(quiet,    QUIET)\n   S(strict,   STRICT)\n   S(log,      LOG)\n   S(continue, CONTINUE)\n   S(sizes,    SIZES)\n   S(search,   SEARCH)\n   S(nowrite,  NOWRITE)\n#  ifdef IGNORE_INDEX\n      S(ignore-palette-index, IGNORE_INDEX)\n#  endif /* IGNORE_INDEX */\n#  ifdef FIX_INDEX\n      S(fix-palette-index, FIX_INDEX)\n#  endif /* FIX_INDEX */\n#  undef S\n\n   /* OPTION settings, these and LIST settings are read on demand */\n#  define VLNAME(name) vl_ ## name\n#  define VLSIZE(name) voidcast(png_byte,\\\n                           (sizeof VLNAME(name))/(sizeof VLNAME(name)[0]))\n#  define VL(oname, name, type, search)\\\n   { oname, type, search, VLSIZE(name), VLNAME(name) },\n#  define VLO(oname, name, search) VL(oname, name, OPTION, search)\n\n#  ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\n#     define VLCIDAT(name) VLO(#name, name, 1/*search*/)\n#     ifdef PNG_SW_COMPRESS_level\n#        define VLCiCCP(name) VLO(\"ICC-profile-\" #name, name, 0/*search*/)\n#     else\n#        define VLCiCCP(name)\n#     endif\n#  else\n#     define VLCIDAT(name)\n#     define VLCiCCP(name)\n#  endif /* WRITE_CUSTOMIZE_COMPRESSION */\n\n#  ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n#     define VLCzTXt(name) VLO(\"text-\" #name, name, 0/*search*/)\n#  else\n#     define VLCzTXt(name)\n#  endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */\n\n#  define VLC(name) VLCIDAT(name) VLCiCCP(name) VLCzTXt(name)\n\n#  ifdef PNG_SW_COMPRESS_png_level\n      /* The libpng compression level isn't searched beause it justs sets the\n       * other things that are searched!\n       */\n      VLO(\"compression\", compression, 0)\n      VLO(\"text-compression\", compression, 0)\n      VLO(\"ICC-profile-compression\", compression, 0)\n#  endif /* SW_COMPRESS_png_level */\n   VLC(strategy)\n   VLO(\"windowBits\", windowBits_IDAT, 1)\n#  ifdef PNG_SW_COMPRESS_windowBits\n      VLO(\"ICC-profile-windowBits\", windowBits_text/*sic*/, 0)\n#  endif\n   VLO(\"text-windowBits\", windowBits_text, 0)\n   VLC(level)\n   VLC(memLevel)\n   VLO(\"IDAT-size\", IDAT_size, 0)\n   VLO(\"log-depth\", log_depth, 0)\n\n#  undef VLO\n\n   /* LIST settings */\n#  define VLL(name, search) VL(#name, name, LIST, search)\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   VLL(filter, 0)\n#endif /* WRITE_FILTER */\n#ifdef PNG_PNGCP_TIMING_SUPPORTED\n   VLL(time, 0)\n#endif /* PNGCP_TIMING */\n#  undef VLL\n#  undef VL\n};\n\n#ifdef __cplusplus\n   static const size_t option_count((sizeof options)/(sizeof options[0]));\n#else /* !__cplusplus */\n#  define option_count ((sizeof options)/(sizeof options[0]))\n#endif /* !__cplusplus */\n\nstatic const char *\ncts(int ct)\n{\n   switch (ct)\n   {\n      case PNG_COLOR_TYPE_PALETTE:     return \"P\";\n      case PNG_COLOR_TYPE_GRAY:        return \"G\";\n      case PNG_COLOR_TYPE_GRAY_ALPHA:  return \"GA\";\n      case PNG_COLOR_TYPE_RGB:         return \"RGB\";\n      case PNG_COLOR_TYPE_RGB_ALPHA:   return \"RGBA\";\n      default:                         return \"INVALID\";\n   }\n}\n\nstruct display\n{\n   jmp_buf          error_return;      /* Where to go to on error */\n   unsigned int     errset;            /* error_return is set */\n\n   const char      *operation;         /* What is happening */\n   const char      *filename;          /* The name of the original file */\n   const char      *output_file;       /* The name of the output file */\n\n   /* Used on both read and write: */\n   FILE            *fp;\n\n   /* Used on a read, both the original read and when validating a written\n    * image.\n    */\n   png_alloc_size_t read_size;\n   png_structp      read_pp;\n   png_infop        ip;\n#  if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED\n      png_textp     text_ptr; /* stash of text chunks */\n      int           num_text;\n      int           text_stashed;\n#  endif /* pre 1.7 */\n\n#  ifdef PNG_PNGCP_TIMING_SUPPORTED\n      struct timespec   read_time;\n      struct timespec   read_time_total;\n      struct timespec   write_time;\n      struct timespec   write_time_total;\n#  endif /* PNGCP_TIMING */\n\n   /* Used to write a new image (the original info_ptr is used) */\n#  define MAX_SIZE ((png_alloc_size_t)(-1))\n   png_alloc_size_t write_size;\n   png_alloc_size_t best_size;\n   png_structp      write_pp;\n\n   /* Base file information */\n   png_alloc_size_t size;\n   png_uint_32      w;\n   png_uint_32      h;\n   int              bpp;\n   png_byte         ct;\n   int              no_warnings;       /* Do not output libpng warnings */\n   int              min_windowBits;    /* The windowBits range is 8..8 */\n\n   /* Options handling */\n   png_uint_32      results;             /* A mask of errors seen */\n   png_uint_32      options;             /* See display_log below */\n   png_byte         entry[option_count]; /* The selected entry+1 of an option\n                                          * that appears on the command line, or\n                                          * 0 if it was not given. */\n   int              value[option_count]; /* Corresponding value */\n\n   /* Compression exhaustive testing */\n   /* Temporary variables used only while testing a single collection of\n    * settings:\n    */\n   unsigned int     csp;               /* next stack entry to use */\n   unsigned int     nsp;               /* highest active entry+1 found so far */\n\n   /* Values used while iterating through all the combinations of settings for a\n    * single file:\n    */\n   unsigned int     tsp;               /* nsp from the last run; this is the\n                                        * index+1 of the highest active entry on\n                                        * this run; this entry will be advanced.\n                                        */\n   int              opt_string_start;  /* Position in buffer for the first\n                                        * searched option; non-zero if earlier\n                                        * options were set on the command line.\n                                        */\n   struct stack\n   {\n      png_alloc_size_t best_size;      /* Best so far for this option */\n      png_alloc_size_t lo_size;\n      png_alloc_size_t hi_size;\n      int              lo, hi;         /* For binary chop of a range */\n      int              best_val;       /* Best value found so far */\n      int              opt_string_end; /* End of the option string in 'curr' */\n      png_byte         opt;            /* The option being tested */\n      png_byte         entry;          /* The next value entry to be tested */\n      png_byte         end;            /* This is the last entry */\n   }                stack[SL];         /* Stack of entries being tested */\n   char             curr[32*SL];       /* current options being tested */\n   char             best[32*SL];       /* best options */\n\n   char             namebuf[FILENAME_MAX]; /* output file name */\n};\n\nstatic void\ndisplay_init(struct display *dp)\n   /* Call this only once right at the start to initialize the control\n    * structure, the (struct buffer) lists are maintained across calls - the\n    * memory is not freed.\n    */\n{\n   memset(dp, 0, sizeof *dp);\n   dp->operation = \"internal error\";\n   dp->filename = \"command line\";\n   dp->output_file = \"no output file\";\n   dp->options = WARNINGS; /* default to !verbose, !quiet */\n   dp->fp = NULL;\n   dp->read_pp = NULL;\n   dp->ip = NULL;\n   dp->write_pp = NULL;\n   dp->min_windowBits = -1; /* this is an OPTIND, so -1 won't match anything */\n#  if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED\n      dp->text_ptr = NULL;\n      dp->num_text = 0;\n      dp->text_stashed = 0;\n#  endif /* pre 1.7 */\n}\n\nstatic void\ndisplay_clean_read(struct display *dp)\n{\n   if (dp->read_pp != NULL)\n      png_destroy_read_struct(&dp->read_pp, NULL, NULL);\n\n   if (dp->fp != NULL)\n   {\n      FILE *fp = dp->fp;\n      dp->fp = NULL;\n      (void)fclose(fp);\n   }\n}\n\nstatic void\ndisplay_clean_write(struct display *dp)\n{\n   if (dp->fp != NULL)\n   {\n      FILE *fp = dp->fp;\n      dp->fp = NULL;\n      (void)fclose(fp);\n   }\n\n   if (dp->write_pp != NULL)\n      png_destroy_write_struct(&dp->write_pp, dp->tsp > 0 ? NULL : &dp->ip);\n}\n\nstatic void\ndisplay_clean(struct display *dp)\n{\n   display_clean_read(dp);\n   display_clean_write(dp);\n   dp->output_file = NULL;\n\n#  if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED\n      /* This is actually created and used by the write code, but only\n       * once; it has to be retained for subsequent writes of the same file.\n       */\n      if (dp->text_stashed)\n      {\n         dp->text_stashed = 0;\n         dp->num_text = 0;\n         free(dp->text_ptr);\n         dp->text_ptr = NULL;\n      }\n#  endif /* pre 1.7 */\n\n   /* leave the filename for error detection */\n   dp->results = 0; /* reset for next time */\n}\n\nstatic void\ndisplay_destroy(struct display *dp)\n{\n   /* Release any memory held in the display. */\n   display_clean(dp);\n}\n\nstatic struct display *\nget_dp(png_structp pp)\n   /* The display pointer is always stored in the png_struct error pointer */\n{\n   struct display *dp = (struct display*)png_get_error_ptr(pp);\n\n   if (dp == NULL)\n   {\n      fprintf(stderr, \"pngcp: internal error (no display)\\n\");\n      exit(99); /* prevents a crash */\n   }\n\n   return dp;\n}\n\n/* error handling */\n#ifdef __GNUC__\n#  define VGATTR __attribute__((__format__ (__printf__,3,4)))\n   /* Required to quiet GNUC warnings when the compiler sees a stdarg function\n    * that calls one of the stdio v APIs.\n    */\n#else\n#  define VGATTR\n#endif\nstatic void VGATTR\ndisplay_log(struct display *dp, error_level level, const char *fmt, ...)\n   /* 'level' is as above, fmt is a stdio style format string.  This routine\n    * does not return if level is above LIBPNG_WARNING\n    */\n{\n   dp->results |= 1U << level;\n\n   if (level > (error_level)(dp->options & LEVEL_MASK))\n   {\n      const char *lp;\n      va_list ap;\n\n      switch (level)\n      {\n         case INFORMATION:    lp = \"information\"; break;\n         case LIBPNG_WARNING: lp = \"warning(libpng)\"; break;\n         case APP_WARNING:    lp = \"warning(pngcp)\"; break;\n         case APP_FAIL:       lp = \"error(continuable)\"; break;\n         case LIBPNG_ERROR:   lp = \"error(libpng)\"; break;\n         case LIBPNG_BUG:     lp = \"bug(libpng)\"; break;\n         case APP_ERROR:      lp = \"error(pngcp)\"; break;\n         case USER_ERROR:     lp = \"error(user)\"; break;\n\n         case INTERNAL_ERROR: /* anything unexpected is an internal error: */\n         case VERBOSE: case WARNINGS: case ERRORS: case QUIET:\n         default:             lp = \"bug(pngcp)\"; break;\n      }\n\n      fprintf(stderr, \"%s: %s: %s\",\n         dp->filename != NULL ? dp->filename : \"<stdin>\", lp, dp->operation);\n\n      fprintf(stderr, \": \");\n\n      va_start(ap, fmt);\n      vfprintf(stderr, fmt, ap);\n      va_end(ap);\n\n      fputc('\\n', stderr);\n   }\n   /* else do not output any message */\n\n   /* Errors cause this routine to exit to the fail code */\n   if (level > APP_FAIL || (level > ERRORS && !(dp->options & CONTINUE)))\n   {\n      if (dp->errset)\n         longjmp(dp->error_return, level);\n\n      else\n         exit(99);\n   }\n}\n\n#if PNG_LIBPNG_VER < 10700 && defined PNG_TEXT_SUPPORTED\nstatic void\ntext_stash(struct display *dp)\n{\n   /* libpng 1.6 and earlier fixed a bug whereby text chunks were written\n    * multiple times by png_write_png; the issue was that png_write_png passed\n    * the same png_info to both png_write_info and png_write_end.  Rather than\n    * fixing it by recording the information in the png_struct, or by recording\n    * where to write the chunks, the fix made was to change the 'compression'\n    * field of the chunk to invalid values, rendering the png_info somewhat\n    * useless.\n    *\n    * The only fix for this given that we use the png_info more than once is to\n    * make a copy of the text chunks and png_set_text it each time.  This adds a\n    * text chunks, so they get replicated, but only the new set gets written\n    * each time.  This uses memory like crazy but there is no way to delete the\n    * useless chunks from the png_info.\n    *\n    * To make this slightly more efficient only the top level structure is\n    * copied; since the old strings are actually preserved (in 1.6 and earlier)\n    * this happens to work.\n    */\n   png_textp chunks = NULL;\n\n   dp->num_text = png_get_text(dp->write_pp, dp->ip, &chunks, NULL);\n\n   if (dp->num_text > 0)\n   {\n      dp->text_ptr = voidcast(png_textp, malloc(dp->num_text * sizeof *chunks));\n\n      if (dp->text_ptr == NULL)\n         display_log(dp, APP_ERROR, \"text chunks: stash malloc failed\");\n\n      else\n         memcpy(dp->text_ptr, chunks, dp->num_text * sizeof *chunks);\n   }\n\n   dp->text_stashed = 1; /* regardless of whether there are chunks or not */\n}\n\n#define text_stash(dp) if (!dp->text_stashed) text_stash(dp)\n\nstatic void\ntext_restore(struct display *dp)\n{\n   /* libpng makes a copy, so this is fine: */\n   if (dp->text_ptr != NULL)\n      png_set_text(dp->write_pp, dp->ip, dp->text_ptr, dp->num_text);\n}\n\n#define text_restore(dp) if (dp->text_stashed) text_restore(dp)\n\n#else\n#define text_stash(dp) ((void)0)\n#define text_restore(dp) ((void)0)\n#endif /* pre 1.7 */\n\n/* OPTIONS:\n *\n * The command handles options of the forms:\n *\n *    --option\n *       Turn an option on (Option)\n *    --no-option\n *       Turn an option off (Option)\n *    --option=value\n *       Set an option to a value (Value)\n *    --option=val1,val2,val3\n *       Set an option to a bitmask constructed from the values (List)\n */\nstatic png_byte\noption_index(struct display *dp, const char *opt, size_t len)\n   /* Return the index (in options[]) of the given option, outputs an error if\n    * it does not exist.  Takes the name of the option and a length (number of\n    * characters in the name).\n    */\n{\n   png_byte j;\n\n   for (j=0; j<option_count; ++j)\n      if (strncmp(options[j].name, opt, len) == 0 && options[j].name[len] == 0)\n         return j;\n\n   /* If the setjmp buffer is set the code is asking for an option index; this\n    * is bad.  Otherwise this is the command line option parsing.\n    */\n   display_log(dp, dp->errset ? INTERNAL_ERROR : USER_ERROR,\n         \"%.*s: unknown option\", (int)/*SAFE*/len, opt);\n   abort(); /* NOT REACHED */\n}\n\n/* This works for an option name (no quotes): */\n#define OPTIND(dp, name) option_index(dp, #name, (sizeof #name)-1)\n\nstatic int\nget_option(struct display *dp, const char *opt, int *value)\n{\n   const png_byte i = option_index(dp, opt, strlen(opt));\n\n   if (dp->entry[i]) /* option was set on command line */\n   {\n      *value = dp->value[i];\n      return 1;\n   }\n\n   else\n      return 0;\n}\n\nstatic int\nset_opt_string_(struct display *dp, unsigned int sp, png_byte opt,\n      const char *entry_name)\n   /* Add the appropriate option string to dp->curr. */\n{\n   int offset, add;\n\n   if (sp > 0)\n      offset = dp->stack[sp-1].opt_string_end;\n\n   else\n      offset = dp->opt_string_start;\n\n   if (entry_name == range_lo)\n      add = sprintf(dp->curr+offset, \" --%s=%d\", options[opt].name,\n            dp->value[opt]);\n\n   else\n      add = sprintf(dp->curr+offset, \" --%s=%s\", options[opt].name, entry_name);\n\n   if (add < 0)\n      display_log(dp, INTERNAL_ERROR, \"sprintf failed\");\n\n   assert(offset+add < (int)/*SAFE*/sizeof dp->curr);\n   return offset+add;\n}\n\nstatic void\nset_opt_string(struct display *dp, unsigned int sp)\n   /* Add the appropriate option string to dp->curr. */\n{\n   dp->stack[sp].opt_string_end = set_opt_string_(dp, sp, dp->stack[sp].opt, \n      options[dp->stack[sp].opt].values[dp->stack[sp].entry].name);\n}\n\nstatic void\nrecord_opt(struct display *dp, png_byte opt, const char *entry_name)\n   /* Record this option in dp->curr; called for an option not being searched,\n    * the caller passes in the name of the value, or range_lo to use the\n    * numerical value.\n    */\n{\n   const unsigned int sp = dp->csp; /* stack entry of next searched option */\n\n   if (sp >= dp->tsp)\n   {\n      /* At top of stack; add the opt string for this entry to the previous\n       * searched entry or the start of the dp->curr buffer if there is nothing\n       * on the stack yet (sp == 0).\n       */\n      const int offset = set_opt_string_(dp, sp, opt, entry_name);\n\n      if (sp > 0)\n         dp->stack[sp-1].opt_string_end = offset;\n\n      else\n         dp->opt_string_start = offset;\n   }\n\n   /* else do nothing: option already recorded */\n}\n\nstatic int\nopt_list_end(struct display *dp, png_byte opt, png_byte entry)\n{\n   if (options[opt].values[entry].name == range_lo)\n      return entry+1U >= options[opt].value_count /* missing range_hi */ ||\n         options[opt].values[entry+1U].name != range_hi /* likewise */ ||\n         options[opt].values[entry+1U].value <= dp->value[opt] /* range end */;\n\n   else\n      return entry+1U >= options[opt].value_count /* missing 'all' */ ||\n         options[opt].values[entry+1U].name == all /* last entry */;\n}\n\nstatic void\npush_opt(struct display *dp, unsigned int sp, png_byte opt, int search)\n   /* Push a new option onto the stack, initializing the new stack entry\n    * appropriately; this does all the work of next_opt (setting end/nsp) for\n    * the first entry in the list.\n    */\n{\n   png_byte entry;\n   const char *entry_name;\n\n   assert(sp == dp->tsp && sp < SL);\n\n   /* The starting entry is entry 0 unless there is a range in which case it is\n    * the entry corresponding to range_lo:\n    */\n   entry = options[opt].value_count;\n   assert(entry > 0U);\n\n   do\n   {\n      entry_name = options[opt].values[--entry].name;\n      if (entry_name == range_lo)\n         break;\n   }\n   while (entry > 0U);\n\n   dp->tsp = sp+1U;\n   dp->stack[sp].best_size =\n      dp->stack[sp].lo_size =\n      dp->stack[sp].hi_size = MAX_SIZE;\n\n   if (search && entry_name == range_lo) /* search this range */\n   {\n      dp->stack[sp].lo = options[opt].values[entry].value;\n      /* check for a mal-formed RANGE above: */\n      assert(entry+1 < options[opt].value_count &&\n             options[opt].values[entry+1].name == range_hi);\n      dp->stack[sp].hi = options[opt].values[entry+1].value;\n   }\n\n   else\n   {\n      /* next_opt will just iterate over the range. */\n      dp->stack[sp].lo = INT_MAX;\n      dp->stack[sp].hi = INT_MIN; /* Prevent range chop */\n   }\n\n   dp->stack[sp].opt = opt;\n   dp->stack[sp].entry = entry;\n   dp->stack[sp].best_val = dp->value[opt] = options[opt].values[entry].value;\n\n   set_opt_string(dp, sp);\n\n   /* This works for the search case too; if the range has only one entry 'end'\n    * will be marked here.\n    */\n   if (opt_list_end(dp, opt, entry))\n   {\n      dp->stack[sp].end = 1;\n      /* Skip the warning if pngcp did this itself.  See the code in\n       * set_windowBits_hi.\n       */\n      if (opt != dp->min_windowBits)\n         display_log(dp, APP_WARNING, \"%s: only testing one value\",\n               options[opt].name);\n   }\n\n   else\n   {\n      dp->stack[sp].end = 0;\n      dp->nsp = dp->tsp;\n   }\n\n   /* Do a lazy cache of the text chunks for libpng 1.6 and earlier; this is\n    * because they can only be written once(!) so if we are going to re-use the\n    * png_info we need a copy.\n    */\n   text_stash(dp);\n}\n\nstatic void\nnext_opt(struct display *dp, unsigned int sp)\n   /* Return the next value for this option.  When called 'sp' is expected to be\n    * the topmost stack entry - only the topmost entry changes each time round -\n    * and there must be a valid entry to return.  next_opt will set dp->nsp to\n    * sp+1 if more entries are available, otherwise it will not change it and\n    * set dp->stack[s].end to true.\n    */\n{\n   int search = 0;\n   png_byte entry, opt;\n   const char *entry_name;\n\n   /* dp->stack[sp] must be the top stack entry and it must be active: */\n   assert(sp+1U == dp->tsp && !dp->stack[sp].end);\n\n   opt = dp->stack[sp].opt;\n   entry = dp->stack[sp].entry;\n   assert(entry+1U < options[opt].value_count);\n   entry_name = options[opt].values[entry].name;\n   assert(entry_name != NULL);\n\n   /* For ranges increment the value but don't change the entry, for all other\n    * cases move to the next entry and load its value:\n    */\n   if (entry_name == range_lo) /* a range */\n   {\n      /* A range can be iterated over or searched.  The default iteration option\n       * is indicated by hi < lo on the stack, otherwise the range being search\n       * is [lo..hi] (inclusive).\n       */\n      if (dp->stack[sp].lo > dp->stack[sp].hi)\n         dp->value[opt]++;\n\n      else\n      {\n         /* This is the best size found for this option value: */\n         png_alloc_size_t best_size = dp->stack[sp].best_size;\n         int lo = dp->stack[sp].lo;\n         int hi = dp->stack[sp].hi;\n         int val = dp->value[opt];\n\n         search = 1; /* end is determined here */\n         assert(best_size < MAX_SIZE);\n\n         if (val == lo)\n         {\n            /* Finding the best for the low end of the range: */\n            dp->stack[sp].lo_size = best_size;\n            assert(hi > val);\n\n            if (hi == val+1) /* only 2 entries */\n               dp->stack[sp].end = 1;\n\n            val = hi;\n         }\n\n         else if (val == hi)\n         {\n            dp->stack[sp].hi_size = best_size;\n            assert(val > lo+1); /* else 'end' set above */\n\n            if (val == lo+2) /* only three entries to test */\n               dp->stack[sp].end = 1;\n\n            val = (lo + val)/2;\n         }\n\n         else\n         {\n            png_alloc_size_t lo_size = dp->stack[sp].lo_size;\n            png_alloc_size_t hi_size = dp->stack[sp].hi_size;\n\n            /* lo and hi should have been tested. */\n            assert(lo_size < MAX_SIZE && hi_size < MAX_SIZE);\n\n            /* These cases arise with the 'probe' handling below when there is a\n             * dip or peak in the size curve.\n             */\n            if (val < lo) /* probing a new lo */\n            {\n               /* Swap lo and val: */\n               dp->stack[sp].lo = val;\n               dp->stack[sp].lo_size = best_size;\n               val = lo;\n               best_size = lo_size;\n               lo = dp->stack[sp].lo;\n               lo_size = dp->stack[sp].lo_size;\n            }\n\n            else if (val > hi) /* probing a new hi */\n            {\n               /* Swap hi and val: */\n               dp->stack[sp].hi = val;\n               dp->stack[sp].hi_size = best_size;\n               val = hi;\n               best_size = hi_size;\n               hi = dp->stack[sp].hi;\n               hi_size = dp->stack[sp].hi_size;\n            }\n\n            /* The following should be true or something got messed up above. */\n            assert(lo < val && val < hi);\n\n            /* If there are only four entries (lo, val, hi plus one more) just\n             * test the remaining entry.\n             */\n            if (hi == lo+3)\n            {\n               /* Because of the 'probe' code val can either be lo+1 or hi-1; we\n                * need to test the other.\n                */\n               val = lo + ((val == lo+1) ? 2 : 1);\n               assert(lo < val && val < hi);\n               dp->stack[sp].end = 1;\n            }\n\n            else\n            {\n               /* There are at least 2 entries still untested between lo and hi,\n                * i.e. hi >= lo+4.  'val' is the midpoint +/- 0.5\n                *\n                * Separate out the four easy cases when lo..val..hi are\n                * monotonically decreased or (more weird) increasing:\n                */\n               assert(hi > lo+3);\n\n               if (lo_size <= best_size && best_size <= hi_size)\n               {\n                  /* Select the low range; testing this first favours the low\n                   * range over the high range when everything comes out equal.\n                   * Because of the probing 'val' may be lo+1.  In that case end\n                   * the search and set 'val' to lo+2.\n                   */\n                  if (val == lo+1)\n                  {\n                     ++val;\n                     dp->stack[sp].end = 1;\n                  }\n\n                  else\n                  {\n                     dp->stack[sp].hi = hi = val;\n                     dp->stack[sp].hi_size = best_size;\n                     val = (lo + val) / 2;\n                  }\n               }\n\n               else if (lo_size >= best_size && best_size >= hi_size)\n               {\n                  /* Monotonically decreasing size; this is the expected case.\n                   * Select the high end of the range.  As above, val may be\n                   * hi-1.\n                   */\n                  if (val == hi-1)\n                  {\n                     --val;\n                     dp->stack[sp].end = 1;\n                  }\n\n                  else\n                  {\n                     dp->stack[sp].lo = lo = val;\n                     dp->stack[sp].lo_size = best_size;\n                     val = (val + hi) / 2;\n                  }\n               }\n\n               /* If both those tests failed 'best_size' is either greater than\n                * or less than both lo_size and hi_size.  There is a peak or dip\n                * in the curve of sizes from lo to hi and val is on the peak or\n                * dip.\n                *\n                * Because the ranges being searched as so small (level is 1..9,\n                * windowBits 8..15, memLevel 1..9) there will only be at most\n                * three untested values between lo..val and val..hi, so solve\n                * the problem by probing down from hi or up from lo, whichever\n                * is the higher.\n                *\n                * This is the place where 'val' is set to outside the range\n                * lo..hi, described as 'probing', though maybe 'narrowing' would\n                * be more accurate.\n                */\n               else if (lo_size <= hi_size) /* down from hi */\n               {\n                  dp->stack[sp].hi = val;\n                  dp->stack[sp].hi_size = best_size;\n                  val = --hi;\n               }\n\n               else /* up from low */\n               {\n                  dp->stack[sp].lo = val;\n                  dp->stack[sp].lo_size = best_size;\n                  val = ++lo;\n               }\n\n               /* lo and hi are still the true range limits, check for the end\n                * condition.\n                */\n               assert(hi > lo+1);\n               if (hi <= lo+2)\n                  dp->stack[sp].end = 1;\n            }\n         }\n\n         assert(val != dp->stack[sp].best_val); /* should be a new value */\n         dp->value[opt] = val;\n         dp->stack[sp].best_size = MAX_SIZE;\n      }\n   }\n\n   else\n   {\n      /* Increment 'entry' */\n      dp->value[opt] = options[opt].values[++entry].value;\n      dp->stack[sp].entry = entry;\n   }\n\n   set_opt_string(dp, sp);\n\n   if (!search && opt_list_end(dp, opt, entry)) /* end of list */\n      dp->stack[sp].end = 1;\n\n   else if (!dp->stack[sp].end) /* still active after all these tests */\n      dp->nsp = dp->tsp;\n}\n\nstatic int\ncompare_option(const struct display *dp, unsigned int sp)\n{\n   int opt = dp->stack[sp].opt;\n\n   /* If the best so far is numerically less than the current value the\n    * current set of options is invariably worse.\n    */\n   if (dp->stack[sp].best_val < dp->value[opt])\n      return -1;\n\n   /* Lists of options are searched out of numerical order (currently only\n    * strategy), so only return +1 here when a range is being searched.\n    */\n   else if (dp->stack[sp].best_val > dp->value[opt])\n   {\n      if (dp->stack[sp].lo <= dp->stack[sp].hi /*searching*/)\n         return 1;\n\n      else\n         return -1;\n   }\n\n   else\n      return 0; /* match; current value is the best one */\n}\n\nstatic int\nadvance_opt(struct display *dp, png_byte opt, int search)\n{\n   unsigned int sp = dp->csp++; /* my stack entry */\n\n   assert(sp >= dp->nsp); /* nsp starts off zero */\n\n   /* If the entry was active in the previous run dp->stack[sp] is already\n    * set up and dp->tsp will be greater than sp, otherwise a new entry\n    * needs to be created.\n    *\n    * dp->nsp is handled this way:\n    *\n    * 1) When an option is pushed onto the stack dp->nsp and dp->tsp are\n    *    both set (by push_opt) to the next stack entry *unless* there is\n    *    only one entry in the new list, in which case dp->stack[sp].end\n    *    is set.\n    *\n    * 2) For the top stack entry next_opt is called.  The entry must be\n    *    active (dp->stack[sp].end is not set) and either 'nsp' or 'end'\n    *    will be updated as appropriate.\n    *\n    * 3) For lower stack entries nsp is set unless the stack entry is\n    *    already at the end.  This means that when all the higher entries\n    *    are popped this entry will be too.\n    */\n   if (sp >= dp->tsp)\n   {\n      push_opt(dp, sp, opt, search); /* This sets tsp to sp+1 */\n      return 1; /* initialized */\n   }\n\n   else\n   {\n      int ret = 0; /* unchanged */\n\n      /* An option that is already on the stack; update best_size and best_val\n       * if appropriate.  On the first run there are no previous values and\n       * dp->write_size will be MAX_SIZE, however on the first run dp->tsp\n       * starts off as 0.\n       */\n      assert(dp->write_size > 0U && dp->write_size < MAX_SIZE);\n\n      if (dp->stack[sp].best_size > dp->write_size ||\n          (dp->stack[sp].best_size == dp->write_size &&\n           compare_option(dp, sp) > 0))\n      {\n         dp->stack[sp].best_size = dp->write_size;\n         dp->stack[sp].best_val = dp->value[opt];\n      }\n\n      if (sp+1U >= dp->tsp)\n      {\n         next_opt(dp, sp);\n         ret = 1; /* advanced */\n      }\n\n      else if (!dp->stack[sp].end) /* Active, not at top of stack */\n         dp->nsp = sp+1U;\n\n      return ret; /* advanced || unchanged */\n   }\n}\n\nstatic int\ngetallopts_(struct display *dp, const png_byte opt, int *value, int record)\n   /* Like getop but iterate over all the values if the option was set to \"all\".\n    */\n{\n   if (dp->entry[opt]) /* option was set on command line */\n   {\n      /* Simple, single value, entries don't have a stack frame and have a fixed\n       * value (it doesn't change once set on the command line).  Otherwise the\n       * value (entry) selected from the command line is 'all':\n       */\n      const char *entry_name = options[opt].values[dp->entry[opt]-1].name;\n\n      if (entry_name == all)\n         (void)advance_opt(dp, opt, 0/*do not search; iterate*/);\n\n      else if (record)\n         record_opt(dp, opt, entry_name);\n\n      *value = dp->value[opt];\n      return 1; /* set */\n   }\n\n   else\n      return 0; /* not set */\n}\n\nstatic int\ngetallopts(struct display *dp, const char *opt_str, int *value)\n{\n   return getallopts_(dp, option_index(dp, opt_str, strlen(opt_str)), value, 0);\n}\n\nstatic int\ngetsearchopts(struct display *dp, const char *opt_str, int *value)\n   /* As above except that if the option was not set try a search */\n{\n   png_byte istrat;\n   const png_byte opt = option_index(dp, opt_str, strlen(opt_str));\n   int record = options[opt].search;\n   const char *entry_name;\n\n   /* If it was set on the command line honour the setting, including 'all'\n    * which will override the built in search:\n    */\n   if (getallopts_(dp, opt, value, record))\n      return 1;\n\n   else if (!record) /* not a search option */\n      return 0; /* unset and not searched */\n\n   /* Otherwise decide what to do here. */\n   istrat = OPTIND(dp, strategy);\n   entry_name = range_lo; /* record the value, not the name */\n\n   if (opt == istrat) /* search all strategies */\n      (void)advance_opt(dp, opt, 0/*iterate*/), record=0;\n\n   else if (opt == OPTIND(dp, level))\n   {\n      /* Both RLE and HUFFMAN don't benefit from level increases */\n      if (dp->value[istrat] == Z_RLE || dp->value[istrat] == Z_HUFFMAN_ONLY)\n         dp->value[opt] = 1;\n\n      else /* fixed, filtered or default */\n         (void)advance_opt(dp, opt, 1/*search*/), record=0;\n   }\n\n   else if (opt == OPTIND(dp, windowBits))\n   {\n      /* Changing windowBits for strategies that do not search the window is\n       * pointless.  Huffman-only does not search, RLE only searches backwards\n       * one byte, so given that the maximum string length is 258, a windowBits\n       * of 9 is always sufficient.\n       */\n      if (dp->value[istrat] == Z_HUFFMAN_ONLY)\n         dp->value[opt] = 8;\n\n      else if (dp->value[istrat] == Z_RLE)\n         dp->value[opt] = 9;\n\n      else /* fixed, filtered or default */\n         (void)advance_opt(dp, opt, 1/*search*/), record=0;\n   }\n\n   else if (opt == OPTIND(dp, memLevel))\n   {\n#     if 0\n         (void)advance_opt(dp, opt, 0/*all*/), record=0;\n#     else\n         dp->value[opt] = MAX_MEM_LEVEL;\n#     endif\n   }\n\n   else /* something else */\n      assert(0==\"reached\");\n\n   if (record)\n      record_opt(dp, opt, entry_name);\n\n   /* One of the above searched options: */\n   *value = dp->value[opt];\n   return 1;\n}\n\nstatic int\nfind_val(struct display *dp, png_byte opt, const char *str, size_t len)\n   /* Like option_index but sets (index+i) of the entry in options[opt] that\n    * matches str[0..len-1] into dp->entry[opt] as well as returning the actual\n    * value.\n    */\n{\n   int rlo = INT_MAX, rhi = INT_MIN;\n   png_byte j, irange = 0;\n\n   for (j=1U; j<=options[opt].value_count; ++j)\n   {\n      if (strncmp(options[opt].values[j-1U].name, str, len) == 0 &&\n          options[opt].values[j-1U].name[len] == 0)\n      {\n         dp->entry[opt] = j;\n         return options[opt].values[j-1U].value;\n      }\n      else if (options[opt].values[j-1U].name == range_lo)\n         rlo = options[opt].values[j-1U].value, irange = j;\n      else if (options[opt].values[j-1U].name == range_hi)\n         rhi = options[opt].values[j-1U].value;\n   }\n\n   /* No match on the name, but there may be a range. */\n   if (irange > 0)\n   {\n      char *ep = NULL;\n      long l = strtol(str, &ep, 0);\n\n      if (ep == str+len && l >= rlo && l <= rhi)\n      {\n         dp->entry[opt] = irange; /* range_lo */\n         return (int)/*SAFE*/l;\n      }\n   }\n\n   display_log(dp, dp->errset ? INTERNAL_ERROR : USER_ERROR,\n         \"%s: unknown value setting '%.*s'\", options[opt].name,\n         (int)/*SAFE*/len, str);\n   abort(); /* NOT REACHED */\n}\n\nstatic int\nopt_check(struct display *dp, const char *arg)\n{\n   assert(dp->errset == 0);\n\n   if (arg != NULL && arg[0] == '-' && arg[1] == '-')\n   {\n      int i = 0, negate = (strncmp(arg+2, \"no-\", 3) == 0), val;\n      png_byte j;\n\n      if (negate)\n         arg += 5; /* --no- */\n\n      else\n         arg += 2; /* -- */\n\n      /* Find the length (expect arg\\0 or arg=) */\n      while (arg[i] != 0 && arg[i] != '=') ++i;\n\n      /* So arg[0..i-1] is the argument name, this does not return if this isn't\n       * a valid option name.\n       */\n      j = option_index(dp, arg, i);\n\n      /* It matcheth an option; check the remainder. */\n      if (arg[i] == 0) /* no specified value, use the default */\n      {\n         val = options[j].values[negate].value;\n         dp->entry[j] = (png_byte)/*SAFE*/(negate + 1U);\n      }\n\n      else\n      {\n         const char *list = arg + (i+1);\n\n         /* Expect a single value here unless this is a list, in which case\n          * multiple values are combined.\n          */\n         if (options[j].opt != LIST)\n         {\n            /* find_val sets 'dp->entry[j]' to a non-zero value: */\n            val = find_val(dp, j, list, strlen(list));\n\n            if (negate)\n            {\n               if (options[j].opt < OPTION)\n                  val = !val;\n\n               else\n               {\n                  display_log(dp, USER_ERROR,\n                        \"%.*s: option=arg cannot be negated\", i, arg);\n                  abort(); /* NOT REACHED */\n               }\n            }\n         }\n\n         else /* multiple options separated by ',' characters */\n         {\n            /* --no-option negates list values from the default, which should\n             * therefore be 'all'.  Notice that if the option list is empty in\n             * this case nothing will be removed and therefore --no-option= is\n             * the same as --option.\n             */\n            if (negate)\n               val = options[j].values[0].value;\n\n            else\n               val = 0;\n\n            while (*list != 0) /* allows option= which sets 0 */\n            {\n               /* A value is terminated by the end of the list or a ','\n                * character.\n                */\n               int v, iv;\n\n               iv = 0; /* an index into 'list' */\n               while (list[++iv] != 0 && list[iv] != ',') {}\n\n               v = find_val(dp, j, list, iv);\n\n               if (negate)\n                  val &= ~v;\n\n               else\n                  val |= v;\n\n               list += iv;\n               if (*list != 0)\n                  ++list; /* skip the ',' */\n            }\n         }\n      }\n\n      /* 'val' is the new value, store it for use later and debugging: */\n      dp->value[j] = val;\n\n      if (options[j].opt < LEVEL_MASK)\n      {\n         /* The handling for error levels is to set the level. */\n         if (val) /* Set this level */\n            dp->options = (dp->options & ~LEVEL_MASK) | options[j].opt;\n\n         else\n            display_log(dp, USER_ERROR,\n      \"%.*s: messages cannot be turned off individually; set a message level\",\n                  i, arg);\n      }\n\n      else if (options[j].opt < OPTION)\n      {\n         if (val)\n            dp->options |= options[j].opt;\n\n         else\n            dp->options &= ~options[j].opt;\n      }\n\n      return 1; /* this is an option */\n   }\n\n   else\n      return 0; /* not an option */\n}\n\n#ifdef PNG_PNGCP_TIMING_SUPPORTED\nstatic void\nset_timer(struct display *dp, struct timespec *timer)\n{\n   /* Do the timing using clock_gettime and the per-process timer. */\n   if (clock_gettime(CLOCK_PROCESS_CPUTIME_ID, timer))\n   {\n      display_log(dp, APP_ERROR,\n            \"CLOCK_PROCESS_CPUTIME_ID: %s: timing disabled\\n\", strerror(errno));\n      dp->value[OPTIND(dp,time)] = 0; /* i.e. off */\n   }\n}\n\nstatic void\nstart_timer(struct display *dp, int what)\n{\n   if ((dp->value[OPTIND(dp,time)] & what) != 0)\n      set_timer(dp, what == PNGCP_TIME_READ ? &dp->read_time : &dp->write_time);\n}\n\nstatic void\nend_timer(struct display *dp, int what)\n{\n   if ((dp->value[OPTIND(dp,time)] & what) != 0)\n   {\n      struct timespec t, tmp;\n\n      set_timer(dp, &t);\n\n      if (what == PNGCP_TIME_READ)\n         tmp = dp->read_time;\n\n      else\n         tmp = dp->write_time;\n\n      t.tv_sec -= tmp.tv_sec;\n      t.tv_nsec -= tmp.tv_nsec;\n\n      if (t.tv_nsec < 0)\n      {\n         --(t.tv_sec);\n         t.tv_nsec += 1000000000L;\n      }\n\n      if (what == PNGCP_TIME_READ)\n         dp->read_time = t, tmp = dp->read_time_total;\n\n      else\n         dp->write_time = t, tmp = dp->write_time_total;\n\n      tmp.tv_sec += t.tv_sec;\n      tmp.tv_nsec += t.tv_nsec;\n\n      if (tmp.tv_nsec >= 1000000000L)\n      {\n         ++(tmp.tv_sec);\n         tmp.tv_nsec -= 1000000000L;\n      }\n\n      if (what == PNGCP_TIME_READ)\n         dp->read_time_total = tmp;\n\n      else\n         dp->write_time_total = tmp;\n   }\n}\n\nstatic void\nprint_time(const char *what, struct timespec t)\n{\n   printf(\"%s %.2lu.%.9ld\", what, (unsigned long)t.tv_sec, t.tv_nsec);\n}\n#else /* !PNGCP_TIMING */\n#define start_timer(dp, what) ((void)0)\n#define end_timer(dp, what) ((void)0)\n#endif /* !PNGCP_TIMING */\n\n/* The following is used in main to verify that the final argument is a\n * directory:\n */\nstatic int\ncheckdir(const char *pathname)\n{\n   struct stat buf;\n   return stat(pathname, &buf) == 0 && S_ISDIR(buf.st_mode);\n}\n\n/* Work out whether a path is valid (if not a display_log occurs), a directory\n * (1 is returned) or a file *or* non-existent (0 is returned).\n *\n * Used for a write path.\n */\nstatic int\nisdir(struct display *dp, const char *pathname)\n{\n   if (pathname == NULL)\n      return 0; /* stdout */\n\n   else if (pathname[0] == 0)\n      return 1; /* empty string */\n\n   else\n   {\n      struct stat buf;\n      int ret = stat(pathname, &buf);\n\n      if (ret == 0) /* the entry exists */\n      {\n         if (S_ISDIR(buf.st_mode))\n            return 1;\n\n         /* Else expect an object that exists and can be written: */\n         if (access(pathname, W_OK) != 0)\n            display_log(dp, USER_ERROR, \"%s: cannot be written (%s)\", pathname,\n                  strerror(errno));\n\n         return 0; /* file (exists, can be written) */\n      }\n\n      else /* an error */\n      {\n         /* Non-existence is fine, other errors are not: */\n         if (errno != ENOENT)\n            display_log(dp, USER_ERROR, \"%s: invalid output name (%s)\",\n                  pathname, strerror(errno));\n\n         return 0; /* file (does not exist) */\n      }\n   }\n}\n\nstatic void\nmakename(struct display *dp, const char *dir, const char *infile)\n{\n   /* Make a name for an output file (and check it). */\n   dp->namebuf[0] = 0;\n\n   if (dir == NULL || infile == NULL)\n      display_log(dp, INTERNAL_ERROR, \"NULL name to makename\");\n\n   else\n   {\n      size_t dsize = strlen(dir);\n\n      if (dsize <= (sizeof dp->namebuf)-2) /* Allow for name + '/' + '\\0' */\n      {\n         size_t isize = strlen(infile);\n         size_t istart = isize-1;\n\n         /* This should fail before here: */\n         if (infile[istart] == '/')\n            display_log(dp, INTERNAL_ERROR, \"infile with trailing /\");\n\n         memcpy(dp->namebuf, dir, dsize);\n         if (dsize > 0 && dp->namebuf[dsize-1] != '/')\n            dp->namebuf[dsize++] = '/';\n\n         /* Find the rightmost non-/ character: */\n         while (istart > 0 && infile[istart-1] != '/')\n            --istart;\n\n         isize -= istart;\n         infile += istart;\n\n         if (dsize+isize < (sizeof dp->namebuf)) /* dsize + infile + '\\0' */\n         {\n            memcpy(dp->namebuf+dsize, infile, isize+1);\n\n            if (isdir(dp, dp->namebuf))\n               display_log(dp, USER_ERROR, \"%s: output file is a directory\",\n                     dp->namebuf);\n         }\n\n         else\n         {\n            dp->namebuf[dsize] = 0; /* allowed for: -2 at start */\n            display_log(dp, USER_ERROR, \"%s%s: output file name too long\",\n                  dp->namebuf, infile);\n         }\n      }\n\n      else\n         display_log(dp, USER_ERROR, \"%s: output directory name too long\", dir);\n   }\n}\n\n/* error handler callbacks for libpng */\nstatic void PNGCBAPI\ndisplay_warning(png_structp pp, png_const_charp warning)\n{\n   struct display *dp = get_dp(pp);\n\n   /* This is used to prevent repeated warnings while searching */\n   if (!dp->no_warnings)\n      display_log(get_dp(pp), LIBPNG_WARNING, \"%s\", warning);\n}\n\nstatic void PNGCBAPI\ndisplay_error(png_structp pp, png_const_charp error)\n{\n   struct display *dp = get_dp(pp);\n\n   display_log(dp, LIBPNG_ERROR, \"%s\", error);\n}\n\nstatic void\ndisplay_start_read(struct display *dp, const char *filename)\n{\n   if (filename != NULL)\n   {\n      dp->filename = filename;\n      dp->fp = fopen(filename, \"rb\");\n   }\n\n   else\n   {\n      dp->filename = \"<stdin>\";\n      dp->fp = stdin;\n   }\n\n   dp->w = dp->h = 0U;\n   dp->bpp = 0U;\n   dp->size = 0U;\n   dp->read_size = 0U;\n\n   if (dp->fp == NULL)\n      display_log(dp, USER_ERROR, \"file open failed (%s)\", strerror(errno));\n}\n\nstatic void PNGCBAPI\nread_function(png_structp pp, png_bytep data, png_size_t size)\n{\n   struct display *dp = get_dp(pp);\n\n   if (size == 0U || fread(data, size, 1U, dp->fp) == 1U)\n      dp->read_size += size;\n\n   else\n   {\n      if (feof(dp->fp))\n         display_log(dp, LIBPNG_ERROR, \"PNG file truncated\");\n      else\n         display_log(dp, LIBPNG_ERROR, \"PNG file read failed (%s)\",\n               strerror(errno));\n   }\n}\n\nstatic void\nread_png(struct display *dp, const char *filename)\n{\n   display_clean_read(dp); /* safety */\n   display_start_read(dp, filename);\n\n   dp->read_pp = png_create_read_struct(PNG_LIBPNG_VER_STRING, dp,\n      display_error, display_warning);\n   if (dp->read_pp == NULL)\n      display_log(dp, LIBPNG_ERROR, \"failed to create read struct\");\n\n#  ifdef PNG_BENIGN_ERRORS_SUPPORTED\n      png_set_benign_errors(dp->read_pp, 1/*allowed*/);\n#  endif /* BENIGN_ERRORS */\n\n#  ifdef FIX_INDEX\n      if ((dp->options & FIX_INDEX) != 0)\n         png_set_check_for_invalid_index(dp->read_pp, 1/*on, no warning*/);\n#     ifdef IGNORE_INDEX\n         else\n#     endif /* IGNORE_INDEX */\n#  endif /* FIX_INDEX */\n#  ifdef IGNORE_INDEX\n      if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */\n         png_set_check_for_invalid_index(dp->read_pp, -1/*off completely*/);\n#  endif /* IGNORE_INDEX */\n\n   /* The png_read_png API requires us to make the info struct, but it does the\n    * call to png_read_info.\n    */\n   dp->ip = png_create_info_struct(dp->read_pp);\n   if (dp->ip == NULL)\n      png_error(dp->read_pp, \"failed to create info struct\");\n\n   /* Set the IO handling */\n   png_set_read_fn(dp->read_pp, dp, read_function);\n\n#  ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n      png_set_keep_unknown_chunks(dp->read_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL,\n            0);\n#  endif /* HANDLE_AS_UNKNOWN */\n\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n      /* Remove the user limits, if any */\n      png_set_user_limits(dp->read_pp, 0x7fffffff, 0x7fffffff);\n#  endif /* SET_USER_LIMITS */\n\n   /* Now read the PNG. */\n   start_timer(dp, PNGCP_TIME_READ);\n   png_read_png(dp->read_pp, dp->ip, 0U/*transforms*/, NULL/*params*/);\n   end_timer(dp, PNGCP_TIME_READ);\n   dp->w = png_get_image_width(dp->read_pp, dp->ip);\n   dp->h = png_get_image_height(dp->read_pp, dp->ip);\n   dp->ct = png_get_color_type(dp->read_pp, dp->ip);\n   dp->bpp = png_get_bit_depth(dp->read_pp, dp->ip) *\n             png_get_channels(dp->read_pp, dp->ip);\n   {\n      /* png_get_rowbytes should never return 0 because the value is set by the\n       * first call to png_set_IHDR, which should have happened by now, but just\n       * in case:\n       */\n      png_alloc_size_t rb = png_get_rowbytes(dp->read_pp, dp->ip);\n\n      if (rb == 0)\n         png_error(dp->read_pp, \"invalid row byte count from libpng\");\n\n      /* The size calc can overflow. */\n      if ((MAX_SIZE-dp->h)/rb < dp->h)\n         png_error(dp->read_pp, \"image too large\");\n\n      dp->size = rb * dp->h + dp->h/*filter byte*/;\n   }\n\n#ifdef FIX_INDEX\n   if (dp->ct == PNG_COLOR_TYPE_PALETTE && (dp->options & FIX_INDEX) != 0)\n   {\n      int max = png_get_palette_max(dp->read_pp, dp->ip);\n      png_colorp palette = NULL;\n      int num = -1;\n\n      if (png_get_PLTE(dp->read_pp, dp->ip, &palette, &num) != PNG_INFO_PLTE\n          || max < 0 || num <= 0 || palette == NULL)\n         display_log(dp, LIBPNG_ERROR, \"invalid png_get_PLTE result\");\n\n      if (max >= num)\n      {\n         /* 'Fix' the palette. */\n         int i;\n         png_color newpal[256];\n\n         for (i=0; i<num; ++i)\n            newpal[i] = palette[i];\n\n         /* Fill in any remainder with a warning color: */\n         for (; i<=max; ++i)\n         {\n            newpal[i].red = 0xbe;\n            newpal[i].green = 0xad;\n            newpal[i].blue = 0xed;\n         }\n\n         png_set_PLTE(dp->read_pp, dp->ip, newpal, i);\n      }\n   }\n#endif /* FIX_INDEX */\n\n   display_clean_read(dp);\n   dp->operation = \"none\";\n}\n\nstatic void\ndisplay_start_write(struct display *dp, const char *filename)\n{\n   assert(dp->fp == NULL);\n\n   if ((dp->options & NOWRITE) != 0)\n      dp->output_file = \"<no write>\";\n\n   else\n   {\n      if (filename != NULL)\n      {\n         dp->output_file = filename;\n         dp->fp = fopen(filename, \"wb\");\n      }\n\n      else\n      {\n         dp->output_file = \"<stdout>\";\n         dp->fp = stdout;\n      }\n\n      if (dp->fp == NULL)\n         display_log(dp, USER_ERROR, \"%s: file open failed (%s)\",\n               dp->output_file, strerror(errno));\n   }\n}\n\nstatic void PNGCBAPI\nwrite_function(png_structp pp, png_bytep data, png_size_t size)\n{\n   struct display *dp = get_dp(pp);\n\n   /* The write fail is classed as a USER_ERROR, so --quiet does not turn it\n    * off, this seems more likely to be correct.\n    */\n   if (dp->fp == NULL || fwrite(data, size, 1U, dp->fp) == 1U)\n   {\n      dp->write_size += size;\n      if (dp->write_size < size || dp->write_size == MAX_SIZE)\n         png_error(pp, \"IDAT size overflow\");\n   }\n\n   else\n      display_log(dp, USER_ERROR, \"%s: PNG file write failed (%s)\",\n            dp->output_file, strerror(errno));\n}\n\n/* Compression option, 'method' is never set: there is no choice.\n *\n * IMPORTANT: the order of the entries in this macro determines the preference\n * order when two different combos of two of these options produce an IDAT of\n * the same size.  The logic here is to put the things that affect the decoding\n * of the PNG image ahead of those that are relevant only to the encoding.\n */\n#define SET_COMPRESSION\\\n   SET(strategy, strategy);\\\n   SET(windowBits, window_bits);\\\n   SET(level, level);\\\n   SET(memLevel, mem_level);\n\n#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\nstatic void\nsearch_compression(struct display *dp)\n{\n   /* Like set_compression below but use a more restricted search than 'all' */\n   int val;\n\n#  define SET(name, func) if (getsearchopts(dp, #name, &val))\\\n      png_set_compression_ ## func(dp->write_pp, val);\n   SET_COMPRESSION\n#  undef SET\n}\n\nstatic void\nset_compression(struct display *dp)\n{\n   int val;\n\n#  define SET(name, func) if (getallopts(dp, #name, &val))\\\n      png_set_compression_ ## func(dp->write_pp, val);\n   SET_COMPRESSION\n#  undef SET\n}\n\n#ifdef PNG_SW_COMPRESS_level /* 1.7.0+ */\nstatic void\nset_ICC_profile_compression(struct display *dp)\n{\n   int val;\n\n#  define SET(name, func) if (getallopts(dp, \"ICC-profile-\" #name, &val))\\\n      png_set_ICC_profile_compression_ ## func(dp->write_pp, val);\n   SET_COMPRESSION\n#  undef SET\n}\n#else\n#  define set_ICC_profile_compression(dp) ((void)0)\n#endif\n#else\n#  define search_compression(dp) ((void)0)\n#  define set_compression(dp) ((void)0)\n#  define set_ICC_profile_compression(dp) ((void)0)\n#endif /* WRITE_CUSTOMIZE_COMPRESSION */\n\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\nstatic void\nset_text_compression(struct display *dp)\n{\n   int val;\n\n#  define SET(name, func) if (getallopts(dp, \"text-\" #name, &val))\\\n      png_set_text_compression_ ## func(dp->write_pp, val);\n   SET_COMPRESSION\n#  undef SET\n}\n#else\n#  define set_text_compression(dp) ((void)0)\n#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */\n\nstatic void\nwrite_png(struct display *dp, const char *destname)\n{\n   display_clean_write(dp); /* safety */\n   display_start_write(dp, destname);\n\n   dp->write_pp = png_create_write_struct(PNG_LIBPNG_VER_STRING, dp,\n      display_error, display_warning);\n\n   if (dp->write_pp == NULL)\n      display_log(dp, LIBPNG_ERROR, \"failed to create write png_struct\");\n\n#  ifdef PNG_BENIGN_ERRORS_SUPPORTED\n      png_set_benign_errors(dp->write_pp, 1/*allowed*/);\n#  endif /* BENIGN_ERRORS */\n\n   png_set_write_fn(dp->write_pp, dp, write_function, NULL/*flush*/);\n\n#ifdef IGNORE_INDEX\n   if ((dp->options & IGNORE_INDEX) != 0) /* DANGEROUS */\n      png_set_check_for_invalid_index(dp->write_pp, -1/*off completely*/);\n#endif /* IGNORE_INDEX */\n\n   /* Restore the text chunks when using libpng 1.6 or less; this is a macro\n    * which expands to nothing in 1.7+  In earlier versions it tests\n    * dp->text_stashed, which is only set (below) *after* the first write.\n    */\n   text_restore(dp);\n\n#  ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n      png_set_keep_unknown_chunks(dp->write_pp, PNG_HANDLE_CHUNK_ALWAYS, NULL,\n            0);\n#  endif /* HANDLE_AS_UNKNOWN */\n\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n      /* Remove the user limits, if any */\n      png_set_user_limits(dp->write_pp, 0x7fffffff, 0x7fffffff);\n#  endif\n\n   /* OPTION HANDLING */\n   /* compression outputs, IDAT and zTXt/iTXt: */\n   dp->tsp = dp->nsp;\n   dp->nsp = dp->csp = 0;\n#  ifdef PNG_SW_COMPRESS_png_level\n      {\n         int val;\n\n         /* This sets everything, but then the following options just override\n          * the specific settings for ICC profiles and text.\n          */\n         if (getallopts(dp, \"compression\", &val))\n            png_set_compression(dp->write_pp, val);\n\n         if (getallopts(dp, \"ICC-profile-compression\", &val))\n            png_set_ICC_profile_compression(dp->write_pp, val);\n\n         if (getallopts(dp, \"text-compression\", &val))\n            png_set_text_compression(dp->write_pp, val);\n      }\n#  endif /* png_level support */\n   if (dp->options & SEARCH)\n      search_compression(dp);\n   else\n      set_compression(dp);\n   set_ICC_profile_compression(dp);\n   set_text_compression(dp);\n\n   {\n      int val;\n\n      /* The permitted range is 1..0x7FFFFFFF, so the cast is safe */\n      if (get_option(dp, \"IDAT-size\", &val))\n         png_set_IDAT_size(dp->write_pp, val);\n   }\n\n   /* filter handling */\n#  ifdef PNG_WRITE_FILTER_SUPPORTED\n      {\n         int val;\n\n         if (get_option(dp, \"filter\", &val))\n            png_set_filter(dp->write_pp, PNG_FILTER_TYPE_BASE, val);\n      }\n#  endif /* WRITE_FILTER */\n\n   /* This just uses the 'read' info_struct directly, it contains the image. */\n   dp->write_size = 0U;\n   start_timer(dp, PNGCP_TIME_WRITE);\n   png_write_png(dp->write_pp, dp->ip, 0U/*transforms*/, NULL/*params*/);\n   end_timer(dp, PNGCP_TIME_WRITE);\n\n   /* Make sure the file was written ok: */\n   if (dp->fp != NULL)\n   {\n      FILE *fp = dp->fp;\n      dp->fp = NULL;\n      if (fclose(fp))\n         display_log(dp, APP_ERROR, \"%s: write failed (%s)\",\n               destname == NULL ? \"stdout\" : destname, strerror(errno));\n   }\n\n   /* Clean it on the way out - if control returns to the caller then the\n    * written_file contains the required data.\n    */\n   display_clean_write(dp);\n   dp->operation = \"none\";\n}\n\nstatic void\nset_windowBits_hi(struct display *dp)\n{\n   /* windowBits is in the range 8..15 but zlib maps '8' to '9' so it is only\n    * worth using if the data size is 256 byte or less.\n    */\n   int wb = MAX_WBITS; /* for large images */\n   int i = VLSIZE(windowBits_IDAT);\n\n   while (wb > 8 && dp->size <= 1U<<(wb-1)) --wb;\n\n   while (--i >= 0) if (VLNAME(windowBits_IDAT)[i].name == range_hi) break;\n\n   assert(i > 1); /* vl_windowBits_IDAT always has a RANGE() */\n   VLNAME(windowBits_IDAT)[i].value = wb;\n\n   assert(VLNAME(windowBits_IDAT)[--i].name == range_lo);\n   VLNAME(windowBits_IDAT)[i].value = wb > 8 ? 9 : 8;\n\n   /* If wb == 8 then any search has been restricted to just one windowBits\n    * entry.  Record that here to avoid producing a spurious app-level warning\n    * above.\n    */\n   if (wb == 8)\n      dp->min_windowBits = OPTIND(dp, windowBits);\n}\n\nstatic int\nbetter_options(const struct display *dp)\n{\n   /* Are these options better than the best found so far?  Normally the\n    * options are tested in preference order, best first, however when doing a\n    * search operation on a range the range values are tested out of order.  In\n    * that case preferable options will get tested later.\n    *\n    * This function looks through the stack from the bottom up looking for an\n    * option that does not match the current best value.  When it finds one it\n    * checks to see if it is more or less desireable and returns true or false\n    * as appropriate.\n    *\n    * Notice that this means that the order options are pushed onto the stack\n    * conveys a priority; lower/earlier options are more important than later\n    * ones.\n    */\n   unsigned int sp;\n\n   for (sp=0; sp<dp->csp; ++sp)\n   {\n      int c = compare_option(dp, sp);\n\n      if (c < 0)\n         return 0; /* worse */\n\n      else if (c > 0)\n         return 1; /* better */\n   }\n\n   assert(0 && \"unreached\");\n}\n\nstatic void\nprint_search_results(struct display *dp)\n{\n   assert(dp->filename != NULL);\n   printf(\"%s [%ld x %ld %d bpp %s, %lu bytes] %lu -> %lu with '%s'\\n\",\n      dp->filename, (unsigned long)dp->w, (unsigned long)dp->h, dp->bpp,\n      cts(dp->ct), (unsigned long)dp->size, (unsigned long)dp->read_size,\n      (unsigned long)dp->best_size, dp->best);\n   fflush(stdout);\n}\n\nstatic void\nlog_search(struct display *dp, unsigned int log_depth)\n{\n   /* Log, and reset, the search so far: */\n   if (dp->nsp/*next entry to change*/ <= log_depth)\n   {\n      print_search_results(dp);\n      /* Start again with this entry: */\n      dp->best_size = MAX_SIZE;\n   }\n}\n\nstatic void\ncp_one_file(struct display *dp, const char *filename, const char *destname)\n{\n   unsigned int log_depth;\n\n   dp->filename = filename;\n   dp->operation = \"read\";\n   dp->no_warnings = 0;\n\n   /* Read it then write it: */\n   if (filename != NULL && access(filename, R_OK) != 0)\n      display_log(dp, USER_ERROR, \"%s: invalid file name (%s)\",\n            filename, strerror(errno));\n\n   read_png(dp, filename);\n\n   /* But 'destname' may be a directory. */\n   dp->operation = \"write\";\n\n   /* Limit the upper end of the windowBits range for this file */\n   set_windowBits_hi(dp);\n\n   /* For logging, depth to log: */\n   {\n      int val;\n\n      if (get_option(dp, \"log-depth\", &val) && val >= 0)\n         log_depth = (unsigned int)/*SAFE*/val;\n\n      else\n         log_depth = 0U;\n   }\n\n   if (destname != NULL) /* else stdout */\n   {\n      if (isdir(dp, destname))\n      {\n         makename(dp, destname, filename);\n         destname = dp->namebuf;\n      }\n\n      else if (access(destname, W_OK) != 0 && errno != ENOENT)\n         display_log(dp, USER_ERROR, \"%s: invalid output name (%s)\", destname,\n               strerror(errno));\n   }\n\n   dp->nsp = 0;\n   dp->curr[0] = 0; /* acts as a flag for the caller */\n   dp->opt_string_start = 0;\n   dp->best[0] = 0; /* safety */\n   dp->best_size = MAX_SIZE;\n   write_png(dp, destname);\n\n   /* Initialize the 'best' fields: */\n   strcpy(dp->best, dp->curr);\n   dp->best_size = dp->write_size;\n\n   if (dp->nsp > 0) /* interating over lists */\n   {\n      char *tmpname, tmpbuf[(sizeof dp->namebuf) + 4];\n      assert(dp->curr[0] == ' ' && dp->tsp > 0);\n\n      /* Cancel warnings on subsequent writes */\n      log_search(dp, log_depth);\n      dp->no_warnings = 1;\n\n      /* Make a temporary name for the subsequent tests: */\n      if (destname != NULL)\n      {\n         strcpy(tmpbuf, destname);\n         strcat(tmpbuf, \".tmp\"); /* space for .tmp allocated above */\n         tmpname = tmpbuf;\n      }\n\n      else\n         tmpname = NULL; /* stdout */\n\n      /* Loop to find the best option. */\n      do\n      {\n         write_png(dp, tmpname);\n\n         /* And compare the sizes (the write function makes sure write_size\n          * doesn't overflow.)\n          */\n         assert(dp->csp > 0);\n\n         if (dp->write_size < dp->best_size ||\n             (dp->write_size == dp->best_size && better_options(dp)))\n         {\n            if (destname != NULL && rename(tmpname, destname) != 0)\n               display_log(dp, APP_ERROR, \"rename %s %s failed (%s)\", tmpname,\n                     destname, strerror(errno));\n\n            strcpy(dp->best, dp->curr);\n            dp->best_size = dp->write_size;\n         }\n\n         else if (tmpname != NULL && unlink(tmpname) != 0)\n            display_log(dp, APP_WARNING, \"unlink %s failed (%s)\", tmpname,\n                  strerror(errno));\n\n         log_search(dp, log_depth);\n      }\n      while (dp->nsp > 0);\n\n      /* Do this for the 'sizes' option so that it reports the correct size. */\n      dp->write_size = dp->best_size;\n   }\n}\n\nstatic int\ncppng(struct display *dp, const char *file, const char *gv dest)\n   /* Exists solely to isolate the setjmp clobbers which some versions of GCC\n    * erroneously generate.\n    */\n{\n   int ret = setjmp(dp->error_return);\n\n   if (ret == 0)\n   {\n      dp->errset = 1;\n      cp_one_file(dp, file, dest);\n      dp->errset = 0;\n      return 0;\n   }\n\n   else\n   {\n      dp->errset = 0;\n\n      if (ret < ERRORS) /* shouldn't longjmp on warnings */\n         display_log(dp, INTERNAL_ERROR, \"unexpected return code %d\", ret);\n\n      return ret;\n   }\n}\n\nint\nmain(const int argc, const char * const * const argv)\n{\n   /* For each file on the command line test it with a range of transforms */\n   int option_end;\n   struct display d;\n\n   display_init(&d);\n\n   d.operation = \"options\";\n   for (option_end = 1;\n        option_end < argc && opt_check(&d, argv[option_end]);\n        ++option_end)\n   {\n   }\n\n   /* Do a quick check on the directory target case; when there are more than\n    * two arguments the last one must be a directory.\n    */\n   if (!(d.options & NOWRITE) && option_end+2 < argc && !checkdir(argv[argc-1]))\n   {\n      fprintf(stderr,\n            \"pngcp: %s: directory required with more than two arguments\\n\",\n            argv[argc-1]);\n      return 99;\n   }\n\n   {\n      int errors = 0;\n      int i = option_end;\n\n      /* Do this at least once; if there are no arguments stdin/stdout are used.\n       */\n      d.operation = \"files\";\n      do\n      {\n         const char *infile = NULL;\n         const char *outfile = NULL;\n         int ret;\n\n         if (i < argc)\n         {\n            infile = argv[i++];\n            if (!(d.options & NOWRITE) && i < argc)\n               outfile = argv[argc-1];\n         }\n\n         ret = cppng(&d, infile, outfile);\n\n         if (ret)\n         {\n            if (ret > QUIET) /* abort on user or internal error */\n               return 99;\n\n            /* An error: the output is meaningless */\n         }\n\n         else if (d.best[0] != 0)\n         {\n            /* This result may already have been output, in which case best_size\n             * has been reset.\n             */\n            if (d.best_size < MAX_SIZE)\n               print_search_results(&d);\n         }\n\n         else if (d.options & SIZES)\n         {\n            printf(\"%s [%ld x %ld %d bpp %s, %lu bytes] %lu -> %lu [0x%lx]\\n\",\n                  infile, (unsigned long)d.w, (unsigned long)d.h, d.bpp,\n                  cts(d.ct), (unsigned long)d.size, (unsigned long)d.read_size,\n                  (unsigned long)d.write_size, (unsigned long)d.results);\n            fflush(stdout);\n         }\n\n         /* Here on any return, including failures, except user/internal issues\n          */\n         {\n            const int pass = (d.options & STRICT) ?\n               RESULT_STRICT(d.results) : RESULT_RELAXED(d.results);\n\n            if (!pass)\n               ++errors;\n\n            if (d.options & LOG)\n            {\n               int j;\n\n               printf(\"%s: pngcp\", pass ? \"PASS\" : \"FAIL\");\n\n               for (j=1; j<option_end; ++j)\n                  printf(\" %s\", argv[j]);\n\n               if (infile != NULL)\n                  printf(\" %s\", infile);\n\n#              ifdef PNG_PNGCP_TIMING_SUPPORTED\n                  /* When logging output the files for each file, if enabled. */\n                  if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_READ) != 0)\n                     print_time(\" read\", d.read_time);\n\n                  if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_WRITE) != 0)\n                     print_time(\" write\", d.write_time);\n#              endif /* PNGCP_TIMING */\n\n               printf(\"\\n\");\n               fflush(stdout);\n            }\n         }\n\n         display_clean(&d);\n      }\n      while (i+!(d.options & NOWRITE) < argc);\n         /* I.e. for write cases after the first time through the loop require\n          * there to be at least two arguments left and for the last one to be a\n          * directory (this was checked above).\n          */\n\n      /* Release allocated memory */\n      display_destroy(&d);\n\n#     ifdef PNG_PNGCP_TIMING_SUPPORTED\n         {\n            int output = 0;\n\n            if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_READ) != 0)\n               print_time(\"read\", d.read_time_total), output = 1;\n\n            if ((d.value[OPTIND(&d,time)] & PNGCP_TIME_WRITE) != 0)\n            {\n               if (output) putchar(' ');\n               print_time(\"write\", d.write_time_total);\n               output = 1;\n            }\n\n            if (output) putchar('\\n');\n         }\n#     endif /* PNGCP_TIMING */\n\n      return errors != 0;\n   }\n}\n#else /* !READ_PNG || !WRITE_PNG */\nint\nmain(void)\n{\n   fprintf(stderr, \"pngcp: no support for png_read/write_image\\n\");\n   return 77;\n}\n#endif /* !READ_PNG || !WRITE_PNG */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/pngfix.c",
    "content": "/* pngfix.c\n *\n * Copyright (c) 2014-2016 John Cunningham Bowler\n *\n * Last changed in libpng 1.6.21 [January 15, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Tool to check and fix the zlib inflate 'too far back' problem.\n * See the usage message for more information.\n */\n#include <stdlib.h>\n#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n#include <limits.h>\n#include <errno.h>\n#include <assert.h>\n\n#define implies(x,y) assert(!(x) || (y))\n\n#ifdef __GNUC__\n   /* This is used to fix the error:\n    *\n    * pngfix.c:\n    * In function 'zlib_advance':\n    * pngfix.c:181:13: error: assuming signed overflow does not\n    *   occur when simplifying conditional to constant [-Werror=strict-overflow]\n    */\n#  define FIX_GCC volatile\n#else\n#  define FIX_GCC\n#endif\n\n#define PROGRAM_NAME \"pngfix\"\n\n/* Define the following to use this program against your installed libpng,\n * rather than the one being built here:\n */\n#ifdef PNG_FREESTANDING_TESTS\n#  include <png.h>\n#else\n#  include \"../../png.h\"\n#endif\n\n#if PNG_LIBPNG_VER < 10603 /* 1.6.3 */\n#  error \"pngfix will not work with libpng prior to 1.6.3\"\n#endif\n\n#ifdef PNG_SETJMP_SUPPORTED\n#include <setjmp.h>\n\n#if defined(PNG_READ_SUPPORTED) && defined(PNG_EASY_ACCESS_SUPPORTED) &&\\\n   (defined(PNG_READ_DEINTERLACE_SUPPORTED) ||\\\n    defined(PNG_READ_INTERLACING_SUPPORTED))\n\n/* zlib.h defines the structure z_stream, an instance of which is included\n * in this structure and is required for decompressing the LZ compressed\n * data in PNG files.\n */\n#ifndef ZLIB_CONST\n   /* We must ensure that zlib uses 'const' in declarations. */\n#  define ZLIB_CONST\n#endif\n#include <zlib.h>\n#ifdef const\n   /* zlib.h sometimes #defines const to nothing, undo this. */\n#  undef const\n#endif\n\n/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility\n * with older builds.\n */\n#if ZLIB_VERNUM < 0x1260\n#  define PNGZ_MSG_CAST(s) constcast(char*,s)\n#  define PNGZ_INPUT_CAST(b) constcast(png_bytep,b)\n#else\n#  define PNGZ_MSG_CAST(s) (s)\n#  define PNGZ_INPUT_CAST(b) (b)\n#endif\n\n#ifndef PNG_MAXIMUM_INFLATE_WINDOW\n#  error \"pngfix not supported in this libpng version\"\n#endif\n\n#if ZLIB_VERNUM >= 0x1240\n\n/* Copied from pngpriv.h */\n#ifdef __cplusplus\n#  define voidcast(type, value) static_cast<type>(value)\n#  define constcast(type, value) const_cast<type>(value)\n#  define aligncast(type, value) \\\n   static_cast<type>(static_cast<void*>(value))\n#  define aligncastconst(type, value) \\\n   static_cast<type>(static_cast<const void*>(value))\n#else\n#  define voidcast(type, value) (value)\n#  define constcast(type, value) ((type)(value))\n#  define aligncast(type, value) ((void*)(value))\n#  define aligncastconst(type, value) ((const void*)(value))\n#endif /* __cplusplus */\n\n#if PNG_LIBPNG_VER < 10700\n/* Chunk tags (copied from pngpriv.h) */\n#define PNG_32b(b,s) ((png_uint_32)(b) << (s))\n#define PNG_U32(b1,b2,b3,b4) \\\n   (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))\n\n/* Constants for known chunk types. */\n#define png_IDAT PNG_U32( 73,  68,  65,  84)\n#define png_IEND PNG_U32( 73,  69,  78,  68)\n#define png_IHDR PNG_U32( 73,  72,  68,  82)\n#define png_PLTE PNG_U32( 80,  76,  84,  69)\n#define png_bKGD PNG_U32( 98,  75,  71,  68)\n#define png_cHRM PNG_U32( 99,  72,  82,  77)\n#define png_fRAc PNG_U32(102,  82,  65,  99) /* registered, not defined */\n#define png_gAMA PNG_U32(103,  65,  77,  65)\n#define png_gIFg PNG_U32(103,  73,  70, 103)\n#define png_gIFt PNG_U32(103,  73,  70, 116) /* deprecated */\n#define png_gIFx PNG_U32(103,  73,  70, 120)\n#define png_hIST PNG_U32(104,  73,  83,  84)\n#define png_iCCP PNG_U32(105,  67,  67,  80)\n#define png_iTXt PNG_U32(105,  84,  88, 116)\n#define png_oFFs PNG_U32(111,  70,  70, 115)\n#define png_pCAL PNG_U32(112,  67,  65,  76)\n#define png_pHYs PNG_U32(112,  72,  89, 115)\n#define png_sBIT PNG_U32(115,  66,  73,  84)\n#define png_sCAL PNG_U32(115,  67,  65,  76)\n#define png_sPLT PNG_U32(115,  80,  76,  84)\n#define png_sRGB PNG_U32(115,  82,  71,  66)\n#define png_sTER PNG_U32(115,  84,  69,  82)\n#define png_tEXt PNG_U32(116,  69,  88, 116)\n#define png_tIME PNG_U32(116,  73,  77,  69)\n#define png_tRNS PNG_U32(116,  82,  78,  83)\n#define png_zTXt PNG_U32(122,  84,  88, 116)\n#endif\n\n/* The 8-byte signature as a pair of 32-bit quantities */\n#define sig1 PNG_U32(137,  80,  78,  71)\n#define sig2 PNG_U32( 13,  10,  26,  10)\n\n/* Is the chunk critical? */\n#define CRITICAL(chunk) (((chunk) & PNG_U32(32,0,0,0)) == 0)\n\n/* Is it safe to copy? */\n#define SAFE_TO_COPY(chunk) (((chunk) & PNG_U32(0,0,0,32)) != 0)\n\n/* Fix ups for builds with limited read support */\n#ifndef PNG_ERROR_TEXT_SUPPORTED\n#  define png_error(a,b) png_err(a)\n#endif\n\n/********************************* UTILITIES **********************************/\n/* UNREACHED is a value to cause an assert to fail. Because of the way the\n * assert macro is written the string \"UNREACHED\" is produced in the error\n * message.\n */\n#define UNREACHED 0\n\n/* 80-bit number handling - a PNG image can be up to (2^31-1)x(2^31-1) 8-byte\n * (16-bit RGBA) pixels in size; that's less than 2^65 bytes or 2^68 bits, so\n * arithmetic of 80-bit numbers is sufficient.  This representation uses an\n * arbitrary length array of png_uint_16 digits (0..65535).  The representation\n * is little endian.\n *\n * The arithmetic functions take zero to two uarb values together with the\n * number of digits in those values and write the result to the given uarb\n * (always the first argument) returning the number of digits in the result.\n * If the result is negative the return value is also negative (this would\n * normally be an error).\n */\ntypedef png_uint_16  udigit; /* A 'unum' is an array of these */\ntypedef png_uint_16p uarb;\ntypedef png_const_uint_16p uarbc;\n\n#define UDIGITS(unum) ((sizeof unum)/(sizeof (udigit))\n   /* IMPORTANT: only apply this to an array, applied to a pointer the result\n    * will typically be '2', which is not useful.\n    */\n\nstatic int\nuarb_set(uarb result, png_alloc_size_t val)\n   /* Set (initialize) 'result' to 'val'.  The size required for 'result' must\n    * be determined by the caller from a knowledge of the maximum for 'val'.\n    */\n{\n   int ndigits = 0;\n\n   while (val > 0)\n   {\n      result[ndigits++] = (png_uint_16)(val & 0xffff);\n      val >>= 16;\n   }\n\n   return ndigits;\n}\n\nstatic int\nuarb_copy(uarb to, uarb from, int idigits)\n   /* Copy a uarb, may reduce the digit count */\n{\n   int d, odigits;\n\n   for (d=odigits=0; d<idigits; ++d)\n      if ((to[d] = from[d]) != 0)\n         odigits = d+1;\n\n   return odigits;\n}\n\nstatic int\nuarb_inc(uarb num, int in_digits, png_int_32 add)\n   /* This is a signed 32-bit add, except that to avoid overflow the value added\n    * or subtracted must be no more than 2^31-65536.  A negative result\n    * indicates a negative number (which is an error below).  The size of\n    * 'num' should be max(in_digits+1,2) for arbitrary 'add' but can be just\n    * in_digits+1 if add is known to be in the range -65535..65535.\n    */\n{\n   FIX_GCC int out_digits = 0;\n\n   while (out_digits < in_digits)\n   {\n      add += num[out_digits];\n      num[out_digits++] = (png_uint_16)(add & 0xffff);\n      add >>= 16;\n   }\n\n   while (add != 0 && add != (-1))\n   {\n      num[out_digits++] = (png_uint_16)(add & 0xffff);\n      add >>= 16;\n   }\n\n   if (add == 0)\n   {\n      while (out_digits > 0 && num[out_digits-1] == 0)\n         --out_digits;\n      return out_digits; /* may be 0 */\n   }\n\n   else /* negative result */\n   {\n      while (out_digits > 1 && num[out_digits-1] == 0xffff)\n         --out_digits;\n\n      return -out_digits;\n   }\n}\n\nstatic int\nuarb_add32(uarb num, int in_digits, png_uint_32 add)\n   /* As above but this works with any 32-bit value and only does 'add' */\n{\n   if (in_digits > 0)\n   {\n      in_digits = uarb_inc(num, in_digits, add & 0xffff);\n      return uarb_inc(num+1, in_digits-1, add >> 16)+1;\n   }\n\n   return uarb_set(num, add);\n}\n\nstatic int\nuarb_mult_digit(uarb acc, int a_digits, uarb num, FIX_GCC int n_digits,\n   png_uint_16 val)\n   /* Primitive one-digit multiply - 'val' must be 0..65535. Note that this\n    * primitive is a multiply and accumulate - the result of *num * val is added\n    * to *acc.\n    *\n    * This is a one-digit multiply, so the product may be up to one digit longer\n    * than 'num', however the add to 'acc' means that the caller must ensure\n    * that 'acc' is at least one digit longer than this *and* at least one digit\n    * longer than the current length of 'acc'.  (Or the caller must otherwise\n    * ensure 'adigits' is adequate from knowledge of the values.)\n    */\n{\n   /* The digits in *acc, *num and val are in the range 0..65535, so the\n    * result below is at most (65535*65535)+2*65635 = 65535*(65535+2), which is\n    * exactly 0xffffffff.\n    */\n   if (val > 0 && n_digits > 0) /* Else the product is 0 */\n   {\n      png_uint_32 carry = 0;\n      int out_digits = 0;\n\n      while (out_digits < n_digits || carry > 0)\n      {\n         if (out_digits < a_digits)\n            carry += acc[out_digits];\n\n         if (out_digits < n_digits)\n            carry += (png_uint_32)num[out_digits] * val;\n\n         acc[out_digits++] = (png_uint_16)(carry & 0xffff);\n         carry >>= 16;\n      }\n\n      /* So carry is 0 and all the input digits have been consumed. This means\n       * that it is possible to skip any remaining digits in acc.\n       */\n      if (out_digits > a_digits)\n         return out_digits;\n   }\n\n   return a_digits;\n}\n\nstatic int\nuarb_mult32(uarb acc, int a_digits, uarb num, int n_digits, png_uint_32 val)\n   /* calculate acc += num * val, 'val' may be any 32-bit value, 'acc' and 'num'\n    * may be any value, returns the number of digits in 'acc'.\n    */\n{\n   if (n_digits > 0 && val > 0)\n   {\n      a_digits = uarb_mult_digit(acc, a_digits, num, n_digits,\n         (png_uint_16)(val & 0xffff));\n\n      val >>= 16;\n      if (val > 0)\n         a_digits = uarb_mult_digit(acc+1, a_digits-1, num, n_digits,\n            (png_uint_16)val) + 1;\n\n      /* Because n_digits and val are >0 the following must be true: */\n      assert(a_digits > 0);\n   }\n\n   return a_digits;\n}\n\nstatic int\nuarb_shift(uarb inout, int ndigits, unsigned int right_shift)\n   /* Shift inout right by right_shift bits, right_shift must be in the range\n    * 1..15\n    */\n{\n   FIX_GCC int i = ndigits;\n   png_uint_16 carry = 0;\n\n   assert(right_shift >= 1 && right_shift <= 15);\n\n   while (--i >= 0)\n   {\n      png_uint_16 temp = (png_uint_16)(carry | (inout[i] >> right_shift));\n\n      /* Bottom bits to top bits of carry */\n      carry = (png_uint_16)((inout[i] << (16-right_shift)) & 0xffff);\n\n      inout[i] = temp;\n\n      /* The shift may reduce ndigits */\n      if (i == ndigits-1 && temp == 0)\n         ndigits = i;\n   }\n\n   return ndigits;\n}\n\nstatic int\nuarb_cmp(uarb a, int adigits, uarb b, int bdigits)\n   /* Return -1/0/+1 according as a<b/a==b/a>b */\n{\n   if (adigits < bdigits)\n      return -1;\n\n   if (adigits > bdigits)\n      return 1;\n\n   while (adigits-- > 0)\n      if (a[adigits] < b[adigits])\n         return -1;\n\n      else if (a[adigits] > b[adigits])\n         return 1;\n\n   return 0;\n}\n\n#if 0 /*UNUSED*/\nstatic int\nuarb_eq32(uarb num, int digits, png_uint_32 val)\n   /* Return true if the uarb is equal to 'val' */\n{\n   switch (digits)\n   {\n      case 0:  return val == 0;\n      case 1:  return val == num[0];\n      case 2:  return (val & 0xffff) == num[0] && (val >> 16) == num[1];\n      default: return 0;\n   }\n}\n#endif\n\nstatic void\nuarb_printx(uarb num, int digits, FILE *out)\n   /* Print 'num' as a hexadecimal number (easier than decimal!) */\n{\n   while (digits > 0)\n      if (num[--digits] > 0)\n      {\n         fprintf(out, \"0x%x\", num[digits]);\n\n         while (digits > 0)\n            fprintf(out, \"%.4x\", num[--digits]);\n      }\n\n      else if (digits == 0) /* the number is 0 */\n         fputs(\"0x0\", out);\n}\n\nstatic void\nuarb_print(uarb num, int digits, FILE *out)\n   /* Prints 'num' as a decimal if it will fit in an unsigned long, else as a\n    * hexadecimal number.  Notice that the results vary for images over 4GByte\n    * in a system dependent way, and the hexadecimal form doesn't work very well\n    * in awk script input.\n    *\n    *\n    * TODO: write uarb_div10\n    */\n{\n   if (digits * sizeof (udigit) > sizeof (unsigned long))\n      uarb_printx(num, digits, out);\n\n   else\n   {\n      unsigned long n = 0;\n\n      while (digits > 0)\n         n = (n << 16) + num[--digits];\n\n      fprintf(out, \"%lu\", n);\n   }\n}\n\n/* Generate random bytes.  This uses a boring repeatable algorithm and it\n * is implemented here so that it gives the same set of numbers on every\n * architecture.  It's a linear congruential generator (Knuth or Sedgewick\n * \"Algorithms\") but it comes from the 'feedback taps' table in Horowitz and\n * Hill, \"The Art of Electronics\" (Pseudo-Random Bit Sequences and Noise\n * Generation.)\n *\n * (Copied from contrib/libtests/pngvalid.c)\n */\nstatic void\nmake_random_bytes(png_uint_32* seed, void* pv, size_t size)\n{\n   png_uint_32 u0 = seed[0], u1 = seed[1];\n   png_bytep bytes = voidcast(png_bytep, pv);\n\n   /* There are thirty-three bits; the next bit in the sequence is bit-33 XOR\n    * bit-20.  The top 1 bit is in u1, the bottom 32 are in u0.\n    */\n   size_t i;\n   for (i=0; i<size; ++i)\n   {\n      /* First generate 8 new bits then shift them in at the end. */\n      png_uint_32 u = ((u0 >> (20-8)) ^ ((u1 << 7) | (u0 >> (32-7)))) & 0xff;\n      u1 <<= 8;\n      u1 |= u0 >> 24;\n      u0 <<= 8;\n      u0 |= u;\n      *bytes++ = (png_byte)u;\n   }\n\n   seed[0] = u0;\n   seed[1] = u1;\n}\n\n/* Clear an object to a random value. */\nstatic void\nclear(void *pv, size_t size)\n{\n   static png_uint_32 clear_seed[2] = { 0x12345678, 0x9abcdef0 };\n   make_random_bytes(clear_seed, pv, size);\n}\n\n#define CLEAR(object) clear(&(object), sizeof (object))\n\n/* Copied from unreleased 1.7 code.\n *\n * CRC checking uses a local pre-built implementation of the Ethernet CRC32.\n * This is to avoid a function call to the zlib DLL and to optimize the\n * byte-by-byte case.\n */\nstatic png_uint_32 crc_table[256] =\n{\n   0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,\n   0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,\n   0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,\n   0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,\n   0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,\n   0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,\n   0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,\n   0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,\n   0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,\n   0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,\n   0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,\n   0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,\n   0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,\n   0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,\n   0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,\n   0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,\n   0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,\n   0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,\n   0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,\n   0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,\n   0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,\n   0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,\n   0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,\n   0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,\n   0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,\n   0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,\n   0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,\n   0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,\n   0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,\n   0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,\n   0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,\n   0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,\n   0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,\n   0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,\n   0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,\n   0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,\n   0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,\n   0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,\n   0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,\n   0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,\n   0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,\n   0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,\n   0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,\n   0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,\n   0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,\n   0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,\n   0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,\n   0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,\n   0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,\n   0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,\n   0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,\n   0x2d02ef8d\n};\n\n/* The CRC calculated here *IS* conditioned, the corresponding value used by\n * zlib and the result value is obtained by XORing with CRC_INIT, which is also\n * the first value that must be passed in (for the first byte) to crc_one_byte.\n */\n#define CRC_INIT 0xffffffff\n\nstatic png_uint_32\ncrc_one_byte(png_uint_32 crc, int b)\n{\n   return crc_table[(crc ^ b) & 0xff] ^ (crc >> 8);\n}\n\nstatic png_uint_32\ncrc_init_4(png_uint_32 value)\n{\n   /* This is an alternative to the algorithm used in zlib, which requires four\n    * separate tables to parallelize the four byte operations, it only works for\n    * a CRC of the first four bytes of the stream, but this is what happens in\n    * the parser below where length+chunk-name is read and chunk-name used to\n    * initialize the CRC.  Notice that the calculation here avoids repeated\n    * conditioning (xor with 0xffffffff) by storing the conditioned value.\n    */\n   png_uint_32 crc = crc_table[(~value >> 24)] ^ 0xffffff;\n\n   crc = crc_table[(crc ^ (value >> 16)) & 0xff] ^ (crc >> 8);\n   crc = crc_table[(crc ^ (value >> 8)) & 0xff] ^ (crc >> 8);\n   return crc_table[(crc ^ value) & 0xff] ^ (crc >> 8);\n}\n\nstatic int\nchunk_type_valid(png_uint_32 c)\n   /* Bit whacking approach to chunk name validation that is intended to avoid\n    * branches.  The cost is that it uses a lot of 32-bit constants, which might\n    * be bad on some architectures.\n    */\n{\n   png_uint_32 t;\n\n   /* Remove bit 5 from all but the reserved byte; this means every\n    * 8-bit unit must be in the range 65-90 to be valid.  So bit 5\n    * must be zero, bit 6 must be set and bit 7 zero.\n    */\n   c &= ~PNG_U32(32,32,0,32);\n   t = (c & ~0x1f1f1f1f) ^ 0x40404040;\n\n   /* Subtract 65 for each 8-bit quantity, this must not overflow\n    * and each byte must then be in the range 0-25.\n    */\n   c -= PNG_U32(65,65,65,65);\n   t |=c ;\n\n   /* Subtract 26, handling the overflow which should set the top\n    * three bits of each byte.\n    */\n   c -= PNG_U32(25,25,25,26);\n   t |= ~c;\n\n   return (t & 0xe0e0e0e0) == 0;\n}\n\n/**************************** CONTROL INFORMATION *****************************/\n\n/* Information about a sequence of IDAT chunks, the chunks have been re-synced\n * using sync_stream below and the new lengths are recorded here.  Because the\n * number of chunks is unlimited this is handled using a linked list of these\n * structures.\n */\nstruct IDAT_list\n{\n   struct IDAT_list *next;     /* Linked list */\n   unsigned int      length;   /* Actual length of the array below */\n   unsigned int      count;    /* Number of entries that are valid */\n#     define IDAT_INIT_LENGTH 16\n   png_uint_32       lengths[IDAT_INIT_LENGTH];\n};\n\nstatic void\nIDAT_list_init(struct IDAT_list *list)\n{\n   CLEAR(*list);\n\n   list->next = NULL;\n   list->length = IDAT_INIT_LENGTH;\n}\n\nstatic size_t\nIDAT_list_size(struct IDAT_list *list, unsigned int length)\n   /* Return the size in bytes of an IDAT_list of the given length. */\n{\n   if (list != NULL)\n      length = list->length;\n\n   return sizeof *list - sizeof list->lengths +\n      length * sizeof list->lengths[0];\n}\n\nstatic void\nIDAT_list_end(struct IDAT_list *IDAT_list)\n{\n   struct IDAT_list *list = IDAT_list->next;\n\n   CLEAR(*IDAT_list);\n\n   while (list != NULL)\n   {\n      struct IDAT_list *next = list->next;\n\n      clear(list, IDAT_list_size(list, 0));\n      free(list);\n      list = next;\n   }\n}\n\nstatic struct IDAT_list *\nIDAT_list_extend(struct IDAT_list *tail)\n{\n   /* Use the previous cached value if available. */\n   struct IDAT_list *next = tail->next;\n\n   if (next == NULL)\n   {\n      /* Insert a new, malloc'ed, block of IDAT information buffers, this\n       * one twice as large as the previous one:\n       */\n      unsigned int length = 2 * tail->length;\n\n      if (length < tail->length) /* arithmetic overflow */\n         length = tail->length;\n\n      next = voidcast(IDAT_list*, malloc(IDAT_list_size(NULL, length)));\n      CLEAR(*next);\n\n      /* The caller must handle this: */\n      if (next == NULL)\n         return NULL;\n\n      next->next = NULL;\n      next->length = length;\n      tail->next = next;\n   }\n\n   return next;\n}\n\n/* GLOBAL CONTROL STRUCTURE */\nstruct global\n{\n   /* PUBLIC GLOBAL VARIABLES: OWNER INITIALIZE */\n   unsigned int   errors        :1; /* print file errors to stderr */\n   unsigned int   warnings      :1; /* print libpng warnings to stderr */\n   unsigned int   optimize_zlib :1; /* Run optimization search */\n   unsigned int   quiet         :2; /* don't output summaries */\n   unsigned int   verbose       :3; /* various internal tracking */\n   unsigned int   skip          :3; /* Non-critical chunks to skip */\n#     define SKIP_NONE      0\n#     define SKIP_BAD_CRC   1    /* Chunks with a bad CRC */\n#     define SKIP_UNSAFE    2    /* Chunks not safe to copy */\n#     define SKIP_UNUSED    3    /* Chunks not used by libpng */\n#     define SKIP_TRANSFORM 4    /* Chunks only used in transforms */\n#     define SKIP_COLOR     5    /* Everything but tRNS, sBIT, gAMA and sRGB */\n#     define SKIP_ALL       6    /* Everything but tRNS and sBIT */\n\n   png_uint_32    idat_max;         /* 0 to perform no re-chunking */\n\n   int            status_code;      /* Accumulated status code */\n#     define TOO_FAR_BACK   0x01 /* found a too-far-back error */\n#     define CRC_ERROR      0x02 /* fixed an invalid CRC */\n#     define STREAM_ERROR   0x04 /* damaged PNG stream (may be fixable) */\n#     define TRUNCATED      0x08 /* truncated but still readable */\n#     define FILE_ERROR     0x10 /* could not read the file */\n#     define WRITE_ERROR    0x20 /* write error (this terminates the read) */\n#     define INTERNAL_ERROR 0x40 /* internal limits/errors encountered */\n\n   /* PUBLIC GLOBAL VARIABLES: USED INTERNALLY BY IDAT READ CODE */\n   struct IDAT_list idat_cache;  /* Cache of file IDAT information buffers */\n      /* The structure is shared across all uses of this global control\n       * structure to avoid reallocation between IDAT streams.\n       */\n};\n\nstatic int\nglobal_end(struct global *global)\n{\n\n   int rc;\n\n   IDAT_list_end(&global->idat_cache);\n   rc = global->status_code;\n   CLEAR(*global);\n   return rc;\n}\n\nstatic void\nglobal_init(struct global *global)\n   /* Call this once (and only once) to initialize the control */\n{\n   CLEAR(*global);\n\n   /* Globals */\n   global->errors        = 0;\n   global->warnings      = 0;\n   global->quiet         = 0;\n   global->verbose       = 0;\n   global->idat_max      = 0;         /* no re-chunking of IDAT */\n   global->optimize_zlib = 0;\n   global->skip          = SKIP_NONE;\n   global->status_code   = 0;\n\n   IDAT_list_init(&global->idat_cache);\n}\n\nstatic int\nskip_chunk_type(const struct global *global, png_uint_32 type)\n   /* Return true if this chunk is to be skipped according to the --strip\n    * option.  This code needs to recognize all known ancillary chunks in order\n    * to handle the --strip=unsafe option.\n    */\n{\n   /* Never strip critical chunks: */\n   if (CRITICAL(type))\n      return 0;\n\n   switch (type)\n   {\n      /* Chunks that are treated as, effectively, critical because they affect\n       * correct interpretation of the pixel values:\n       */\n      case png_tRNS: case png_sBIT:\n         return 0;\n\n      /* Chunks that specify gamma encoding which should therefore only be\n       * removed the the user insists:\n       */\n      case png_gAMA: case png_sRGB:\n         if (global->skip >= SKIP_ALL)\n            return 1;\n         return 0;\n\n      /* Chunks that affect color interpretation - not used by libpng and rarely\n       * used by applications, but technically still required for correct\n       * interpretation of the image data:\n       */\n      case png_cHRM: case png_iCCP:\n         if (global->skip >= SKIP_COLOR)\n            return 1;\n         return 0;\n\n      /* Other chunks that are used by libpng in image transformations (as\n       * opposed to known chunks that have get/set APIs but are not otherwise\n       * used.)\n       */\n      case png_bKGD:\n         if (global->skip >= SKIP_TRANSFORM)\n            return 1;\n         return 0;\n\n      /* All other chunks that libpng knows about and affect neither image\n       * interpretation nor libpng transforms - chunks that are effectively\n       * unused by libpng even though libpng might recognize and store them.\n       */\n      case png_fRAc: case png_gIFg: case png_gIFt: case png_gIFx: case png_hIST:\n      case png_iTXt: case png_oFFs: case png_pCAL: case png_pHYs: case png_sCAL:\n      case png_sPLT: case png_sTER: case png_tEXt: case png_tIME: case png_zTXt:\n         if (global->skip >= SKIP_UNUSED)\n            return 1;\n         return 0;\n\n      /* Chunks that libpng does not know about (notice that this depends on the\n       * list above including all known chunks!)  The decision here depends on\n       * whether the safe-to-copy bit is set in the chunk type.\n       */\n      default:\n         if (SAFE_TO_COPY(type))\n         {\n            if (global->skip >= SKIP_UNUSED) /* as above */\n               return 1;\n         }\n\n         else if (global->skip >= SKIP_UNSAFE)\n            return 1;\n\n         return 0;\n   }\n}\n\n/* PER-FILE CONTROL STRUCTURE */\nstruct chunk;\nstruct IDAT;\nstruct file\n{\n   /* ANCESTORS */\n   struct global *global;\n\n   /* PUBLIC PER-FILE VARIABLES: CALLER INITIALIZE */\n   const char *   file_name;\n   const char *   out_name;      /* Name of output file (if required) */\n\n   /* PUBLIC PER-FILE VARIABLES: SET BY PNG READ CODE */\n   /* File specific result codes */\n   int            status_code;   /* Set to a bit mask of the following: */\n   int            read_errno;    /* Records a read error errno */\n   int            write_errno;   /* Records a write error errno */\n\n   /* IHDR information */\n   png_uint_32    width;\n   png_uint_32    height;\n   png_byte       bit_depth;\n   png_byte       color_type;\n   png_byte       compression_method;\n   png_byte       filter_method;\n   png_byte       interlace_method;\n\n   udigit         image_bytes[5];\n   int            image_digits;\n\n   /* PROTECTED PER-FILE VARIABLES: USED BY THE READ CODE */\n   FILE *         file;          /* Original PNG file */\n   FILE *         out;           /* If a new one is being written */\n   jmp_buf        jmpbuf;        /* Set while reading a PNG */\n\n   /* PROTECTED CHUNK SPECIFIC VARIABLES: USED BY CHUNK CODE */\n   /* The following variables are used during reading to record the length, type\n    * and data position of the *next* chunk or, right at the start, the\n    * signature (in length,type).\n    *\n    * When a chunk control structure is instantiated these values are copied\n    * into the structure and can then be overritten with the data for the next\n    * chunk.\n    */\n   fpos_t         data_pos;      /* Position of first byte of chunk data */\n   png_uint_32    length;        /* First word (length or signature start) */\n   png_uint_32    type;          /* Second word (type or signature end) */\n   png_uint_32    crc;           /* Running chunk CRC (used by read_chunk) */\n\n   /* These counts are maintained by the read and write routines below and are\n    * reset by the chunk handling code.  They record the total number of bytes\n    * read or written for the chunk, including the header (length,type) bytes.\n    */\n   png_uint_32    read_count;    /* Count of bytes read (in the chunk) */\n   png_uint_32    write_count;   /* Count of bytes written (in the chunk) */\n   int            state;         /* As defined here: */\n#     define STATE_SIGNATURE  0  /* The signature is being written */\n#     define STATE_CHUNKS     1  /* Non-IDAT chunks are being written */\n#     define STATE_IDAT       2  /* An IDAT stream is being written */\n\n   /* Two pointers used to enable clean-up in the event of fatal errors and to\n    * hold state about the parser process (only one of each at present.)\n    */\n   struct chunk * chunk;\n   struct IDAT *  idat;\n\n   /* Interface to allocate a new chunk or IDAT control structure.  The result\n    * is returned by setting one or other of the above variables.  Note that the\n    * relevant initializer is called by the allocator function.  The alloc_ptr\n    * is used only by the implementation of the allocate function.\n    */\n   void *         alloc_ptr;\n   void         (*alloc)(struct file*,int idat);\n                                  /* idat: allocate IDAT not chunk */\n};\n\n/* Valid longjmp (stop) codes are: */\n#define LIBPNG_WARNING_CODE   1 /* generic png_error */\n#define LIBPNG_ERROR_CODE     2 /* generic png_error */\n#define ZLIB_ERROR_CODE       3 /* generic zlib error */\n#define INVALID_ERROR_CODE    4 /* detected an invalid PNG */\n#define READ_ERROR_CODE       5 /* read failed */\n#define WRITE_ERROR_CODE      6 /* error in write */\n#define UNEXPECTED_ERROR_CODE 7 /* unexpected (internal?) error */\n\nstatic void\nemit_string(const char *str, FILE *out)\n   /* Print a string with spaces replaced by '_' and non-printing characters by\n    * an octal escape.\n    */\n{\n   for (; *str; ++str)\n      if (isgraph(UCHAR_MAX & *str))\n         putc(*str, out);\n\n      else if (isspace(UCHAR_MAX & *str))\n         putc('_', out);\n\n      else\n         fprintf(out, \"\\\\%.3o\", *str);\n}\n\nstatic const char *\nstrcode(int code)\n{\n   switch (code)\n   {\n      case LIBPNG_WARNING_CODE:   return \"warning\";\n      case LIBPNG_ERROR_CODE:     return \"libpng\";\n      case ZLIB_ERROR_CODE:       return \"zlib\";\n      case INVALID_ERROR_CODE:    return \"invalid\";\n      case READ_ERROR_CODE:       return \"read\";\n      case WRITE_ERROR_CODE:      return \"write\";\n      case UNEXPECTED_ERROR_CODE: return \"unexpected\";\n      default:                    return \"INVALID\";\n   }\n}\n\nstatic void\nemit_error(struct file *file, int code, const char *what)\n   /* Generic error message routine, takes a 'stop' code but can be used\n    * elsewhere.  Always outputs a message.\n    */\n{\n   const char *reason;\n   int err = 0;\n\n   switch (code)\n   {\n      case LIBPNG_WARNING_CODE:   reason = \"libpng warning:\"; break;\n      case LIBPNG_ERROR_CODE:     reason = \"libpng error:\"; break;\n      case ZLIB_ERROR_CODE:       reason = \"zlib error:\"; break;\n      case INVALID_ERROR_CODE:    reason = \"invalid\"; break;\n      case READ_ERROR_CODE:       reason = \"read failure:\";\n                                  err = file->read_errno;\n                                  break;\n      case WRITE_ERROR_CODE:      reason = \"write error\";\n                                  err = file->write_errno;\n                                  break;\n      case UNEXPECTED_ERROR_CODE: reason = \"unexpected error:\";\n                                  err = file->read_errno;\n                                  if (err == 0)\n                                     err = file->write_errno;\n                                  break;\n      default:                    reason = \"INVALID (internal error):\"; break;\n   }\n\n   if (err != 0)\n      fprintf(stderr, \"%s: %s %s [%s]\\n\", file->file_name, reason, what,\n         strerror(err));\n\n   else\n      fprintf(stderr, \"%s: %s %s\\n\", file->file_name, reason, what);\n}\n\nstatic void chunk_end(struct chunk **);\nstatic void IDAT_end(struct IDAT **);\n\nstatic int\nfile_end(struct file *file)\n{\n   int rc;\n\n   /* If either of the chunk pointers are set end them here, the IDAT structure\n    * must be deallocated first as it may deallocate the chunk structure.\n    */\n   if (file->idat != NULL)\n      IDAT_end(&file->idat);\n\n   if (file->chunk != NULL)\n      chunk_end(&file->chunk);\n\n   rc = file->status_code;\n\n   if (file->file != NULL)\n      (void)fclose(file->file);\n\n   if (file->out != NULL)\n   {\n      /* NOTE: this is bitwise |, all the following functions must execute and\n       * must succeed.\n       */\n      if (ferror(file->out) | fflush(file->out) | fclose(file->out))\n      {\n         perror(file->out_name);\n         emit_error(file, READ_ERROR_CODE, \"output write error\");\n         rc |= WRITE_ERROR;\n      }\n   }\n\n   /* Accumulate the result codes */\n   file->global->status_code |= rc;\n\n   CLEAR(*file);\n\n   return rc; /* status code: non-zero on read or write error */\n}\n\nstatic int\nfile_init(struct file *file, struct global *global, const char *file_name,\n   const char *out_name, void *alloc_ptr, void (*alloc)(struct file*,int))\n   /* Initialize a file control structure.  This will open the given files as\n    * well.  The status code returned is 0 on success, non zero (using the flags\n    * above) on a file open error.\n    */\n{\n   CLEAR(*file);\n   file->global = global;\n\n   file->file_name = file_name;\n   file->out_name = out_name;\n   file->status_code = 0;\n   file->read_errno = 0;\n   file->write_errno = 0;\n\n   file->file = NULL;\n   file->out = NULL;\n   /* jmpbuf is garbage: must be set by read_png */\n\n   file->read_count = 0;\n   file->state = STATE_SIGNATURE;\n\n   file->chunk = NULL;\n   file->idat = NULL;\n\n   file->alloc_ptr = alloc_ptr;\n   file->alloc = alloc;\n\n   /* Open the files: */\n   assert(file_name != NULL);\n   file->file = fopen(file_name, \"rb\");\n\n   if (file->file == NULL)\n   {\n      file->read_errno = errno;\n      file->status_code |= FILE_ERROR;\n      /* Always output: please give a readable file! */\n      perror(file_name);\n      return FILE_ERROR;\n   }\n\n   if (out_name != NULL)\n   {\n      file->out = fopen(out_name, \"wb\");\n\n      if (file->out == NULL)\n      {\n         file->write_errno = errno;\n         file->status_code |= WRITE_ERROR;\n         perror(out_name);\n         return WRITE_ERROR;\n      }\n   }\n\n   return 0;\n}\n\nstatic void\nlog_error(struct file *file, int code, const char *what)\n   /* Like emit_error but checks the global 'errors' flag */\n{\n   if (file->global->errors)\n      emit_error(file, code, what);\n}\n\nstatic char\ntype_char(png_uint_32 v)\n{\n   /* In fact because chunk::chunk_type is validated prior to any call to this\n    * function it will always return a-zA-Z, but the extra codes are just there\n    * to help in finding internal (programming) errors.  Note that the code only\n    * ever considers the low 7 bits of the value (so it is not necessary for the\n    * type_name function to mask of the byte.)\n    */\n   if (v & 32)\n      return \"!abcdefghijklmnopqrstuvwxyz56789\"[(v-96)&31];\n\n   else\n      return \"@ABCDEFGHIJKLMNOPQRSTUVWXYZ01234\"[(v-64)&31];\n}\n\nstatic void\ntype_name(png_uint_32 type, FILE *out)\n{\n   putc(type_char(type >> 24), out);\n   putc(type_char(type >> 16), out);\n   putc(type_char(type >>  8), out);\n   putc(type_char(type      ), out);\n}\n\nstatic void\ntype_sep(FILE *out)\n{\n   putc(':', out);\n   putc(' ', out);\n}\n\nstatic png_uint_32 current_type(struct file *file, int code);\n\nPNG_NORETURN static void\nstop(struct file *file, int code, const char *what)\n   /* Return control when a PNG file cannot be read. This outputs an 'ERR'\n    * summary line too.\n    */\n{\n   log_error(file, code, what);\n\n   /* The chunk being read is typically identified by file->chunk or, if this is\n    * NULL, by file->type.  This may be wrong if libpng reads ahead, but this\n    * only happens with IDAT where libpng reads the header then jumps around\n    * finding errors in the previous chunks.  We know that is happening because\n    * we are at the start of the IDAT (i.e. no IDAT data has yet been written.)\n    *\n    * SUMMARY FORMAT (stop):\n    *\n    * IDAT ERR status code read-errno write-errno message file\n    *\n    * 'uncompressed' will be 0 if there was a problem in the IHDR.  The errno\n    * values are emit_string(strerror(errno)).\n    */\n   if (file->global->quiet < 2) /* need two quiets to stop this. */\n   {\n      png_uint_32 type;\n\n      if (file->chunk != NULL)\n         type = current_type(file, code); /* Gropes in struct chunk and IDAT */\n\n      else\n         type = file->type;\n\n      if (type)\n         type_name(type, stdout);\n\n      else /* magic: an IDAT header, produces bogons for too many IDATs */\n         fputs(\"HEAD\", stdout); /* not a registered chunk! */\n\n      printf(\" ERR %.2x %s \", file->status_code, strcode(code));\n      /* This only works one strerror at a time, because of the way strerror is\n       * implemented.\n       */\n      emit_string(strerror(file->read_errno), stdout);\n      putc(' ', stdout);\n      emit_string(strerror(file->write_errno), stdout);\n      putc(' ', stdout);\n      emit_string(what, stdout);\n      putc(' ', stdout);\n      fputs(file->file_name, stdout);\n      putc('\\n', stdout);\n   }\n\n   file->status_code |= FILE_ERROR;\n   longjmp(file->jmpbuf, code);\n}\n\nPNG_NORETURN static void\nstop_invalid(struct file *file, const char *what)\n{\n   stop(file, INVALID_ERROR_CODE, what);\n}\n\nstatic void\ntype_message(struct file *file, png_uint_32 type, const char *what)\n   /* Error message for a chunk; the chunk name comes from 'type' */\n{\n   if (file->global->errors)\n   {\n      fputs(file->file_name, stderr);\n      type_sep(stderr);\n      type_name(type, stderr);\n      type_sep(stderr);\n      fputs(what, stderr);\n      putc('\\n', stderr);\n   }\n}\n\n/* Input file positioning - we jump around in the input file while reading\n * stuff, these wrappers deal with the error handling.\n */\nstatic void\nfile_getpos(struct file *file, fpos_t *pos)\n{\n   if (fgetpos(file->file, pos))\n   {\n      /* This is unexpected, so perror it */\n      perror(file->file_name);\n      stop(file, READ_ERROR_CODE, \"fgetpos\");\n   }\n}\n\nstatic void\nfile_setpos(struct file *file, const fpos_t *pos)\n{\n   if (fsetpos(file->file, pos))\n   {\n      perror(file->file_name);\n      stop(file, READ_ERROR_CODE, \"fsetpos\");\n   }\n}\n\nstatic void\ngetpos(struct file *file)\n   /* Get the current position and store it in 'data_pos'.  The corresponding\n    * setpos() function is chunk specific because it uses the copy of the\n    * position for the specific chunk.\n    */\n{\n   file_getpos(file, &file->data_pos);\n}\n\n\n/* Read utility - read a single byte, returns a value in the range 0..255 or EOF\n * on a read error.  In the latter case status_code and read_errno are updated\n * appropriately.\n */\nstatic int\nread_byte(struct file *file)\n{\n   int ch = getc(file->file);\n\n   if (ch >= 0 && ch <= 255)\n   {\n      ++(file->read_count);\n      return ch;\n   }\n\n   else if (ch != EOF)\n   {\n      file->status_code |= INTERNAL_ERROR;\n      file->read_errno = ERANGE; /* out of range character */\n\n      /* This is very unexpected; an error message is always output: */\n      emit_error(file, UNEXPECTED_ERROR_CODE, \"file read\");\n   }\n\n#  ifdef EINTR\n      else if (errno == EINTR) /* Interrupted, try again */\n      {\n         errno = 0;\n         return read_byte(file);\n      }\n#  endif\n\n   else\n   {\n      /* An error, it doesn't really matter what the error is but it gets\n       * recorded anyway.\n       */\n      if (ferror(file->file))\n         file->read_errno = errno;\n\n      else if (feof(file->file))\n         file->read_errno = 0; /* I.e. a regular EOF, no error */\n\n      else /* unexpected */\n         file->read_errno = EDOM;\n   }\n\n   /* 'TRUNCATED' is used for all cases of failure to read a byte, because of\n    * the way libpng works a byte read is never attempted unless the byte is\n    * expected to be there, so EOF should not occur.\n    */\n   file->status_code |= TRUNCATED;\n   return EOF;\n}\n\nstatic png_byte\nreread_byte(struct file *file)\n   /* Read a byte when an error is not expected to happen because the byte has\n    * been read before without error.\n    */\n{\n   int ch = getc(file->file);\n\n   if (errno != 0)\n      file->read_errno = errno;\n\n   if (ch < 0 || ch > 255)\n      stop(file, UNEXPECTED_ERROR_CODE, \"reread\");\n\n   return (png_byte)ch;\n}\n\nstatic png_uint_32\nreread_4(struct file *file)\n   /* The same but for a four byte quantity */\n{\n   png_uint_32 result = 0;\n   int i = 0;\n\n   while (++i <= 4)\n      result = (result << 8) + reread_byte(file);\n\n   return result;\n}\n\nstatic void\nskip_12(struct file *file)\n   /* Skip exactly 12 bytes in the input stream - used to skip a CRC and chunk\n    * header that has been read before.\n    */\n{\n   /* Since the chunks were read before this shouldn't fail: */\n   if (fseek(file->file, 12, SEEK_CUR) != 0)\n   {\n      if (errno != 0)\n         file->read_errno = errno;\n\n      stop(file, UNEXPECTED_ERROR_CODE, \"reskip\");\n   }\n}\n\nstatic void\nwrite_byte(struct file *file, int b)\n   /* Write one byte to the output - this causes a fatal error if the write\n    * fails and the read of this PNG file immediately terminates.  Just\n    * increments the write count if there is no output file.\n    */\n{\n   if (file->out != NULL)\n   {\n      if (putc(b, file->out) != b)\n      {\n         file->write_errno = errno;\n         file->status_code |= WRITE_ERROR;\n         stop(file, WRITE_ERROR_CODE, \"write byte\");\n      }\n   }\n\n   ++(file->write_count);\n}\n\n/* Derivatives of the read/write functions. */\nstatic unsigned int\nread_4(struct file *file, png_uint_32 *pu)\n   /* Read four bytes, returns the number of bytes read successfully and, if all\n    * four bytes are read, assigns the result to *pu.\n    */\n{\n   unsigned int i = 0;\n   png_uint_32 val = 0;\n\n   do\n   {\n      int ch = read_byte(file);\n\n      if (ch == EOF)\n         return i;\n\n      val = (val << 8) + ch;\n   } while (++i < 4);\n\n   *pu = val;\n   return i;\n}\n\n/* CRC handling - read but calculate the CRC while doing so. */\nstatic int\ncrc_read_many(struct file *file, png_uint_32 length)\n   /* Reads 'length' bytes and updates the CRC, returns true on success, false\n    * if the input is truncated.\n    */\n{\n   if (length > 0)\n   {\n      png_uint_32 crc = file->crc;\n\n      do\n      {\n         int ch = read_byte(file);\n\n         if (ch == EOF)\n            return 0; /* Truncated */\n\n         crc = crc_one_byte(crc, ch);\n      }\n      while (--length > 0);\n\n      file->crc = crc;\n   }\n\n   return 1; /* OK */\n}\n\nstatic int\ncalc_image_size(struct file *file)\n   /* Fill in the image_bytes field given the IHDR information, calls stop on\n    * error.\n    */\n{\n   png_uint_16 pd = file->bit_depth;\n\n   switch (file->color_type)\n   {\n      default:\n         stop_invalid(file, \"IHDR: colour type\");\n\n      invalid_bit_depth:\n         stop_invalid(file, \"IHDR: bit depth\");\n\n      case 0: /* g */\n         if (pd != 1 && pd != 2 && pd != 4 && pd != 8 && pd != 16)\n            goto invalid_bit_depth;\n         break;\n\n      case 3:\n         if (pd != 1 && pd != 2 && pd != 4 && pd != 8)\n            goto invalid_bit_depth;\n         break;\n\n      case 2: /* rgb */\n         if (pd != 8 && pd != 16)\n            goto invalid_bit_depth;\n\n         pd = (png_uint_16)(pd * 3);\n         break;\n\n      case 4: /* ga */\n         if (pd != 8 && pd != 16)\n            goto invalid_bit_depth;\n\n         pd = (png_uint_16)(pd * 2);\n         break;\n\n      case 6: /* rgba */\n         if (pd != 8 && pd != 16)\n            goto invalid_bit_depth;\n\n         pd = (png_uint_16)(pd * 4);\n         break;\n   }\n\n   if (file->width < 1 || file->width > 0x7fffffff)\n      stop_invalid(file, \"IHDR: width\");\n\n   else if (file->height < 1 || file->height > 0x7fffffff)\n      stop_invalid(file, \"IHDR: height\");\n\n   else if (file->compression_method != 0)\n      stop_invalid(file, \"IHDR: compression method\");\n\n   else if (file->filter_method != 0)\n      stop_invalid(file, \"IHDR: filter method\");\n\n   else switch (file->interlace_method)\n   {\n      case PNG_INTERLACE_ADAM7:\n         /* Interlacing makes the image larger because of the replication of\n          * both the filter byte and the padding to a byte boundary.\n          */\n         {\n            int pass;\n            int image_digits = 0;\n            udigit row_width[2], row_bytes[3];\n\n            for (pass=0; pass<=6; ++pass)\n            {\n               png_uint_32 pw = PNG_PASS_COLS(file->width, pass);\n\n               if (pw > 0)\n               {\n                  int  digits;\n\n                  /* calculate 1+((pw*pd+7)>>3) in row_bytes */\n                  digits = uarb_mult_digit(row_bytes, uarb_set(row_bytes, 7),\n                     row_width, uarb_set(row_width, pw), pd);\n                  digits = uarb_shift(row_bytes, digits, 3);\n                  digits = uarb_inc(row_bytes, digits, 1);\n\n                  /* Add row_bytes * pass-height to the file image_bytes field\n                   */\n                  image_digits = uarb_mult32(file->image_bytes, image_digits,\n                     row_bytes, digits,\n                     PNG_PASS_ROWS(file->height, pass));\n               }\n            }\n\n            file->image_digits = image_digits;\n         }\n         break;\n\n      case PNG_INTERLACE_NONE:\n         {\n            int  digits;\n            udigit row_width[2], row_bytes[3];\n\n            /* As above, but use image_width in place of the pass width: */\n            digits = uarb_mult_digit(row_bytes, uarb_set(row_bytes, 7),\n               row_width, uarb_set(row_width, file->width), pd);\n            digits = uarb_shift(row_bytes, digits, 3);\n            digits = uarb_inc(row_bytes, digits, 1);\n\n            /* Set row_bytes * image-height to the file image_bytes field */\n            file->image_digits = uarb_mult32(file->image_bytes, 0,\n               row_bytes, digits, file->height);\n         }\n         break;\n\n      default:\n         stop_invalid(file, \"IHDR: interlace method\");\n   }\n\n   assert(file->image_digits >= 1 && file->image_digits <= 5);\n   return 1;\n}\n\n/* PER-CHUNK CONTROL STRUCTURE\n * This structure is instantiated for each chunk, except for the IDAT chunks\n * where one chunk control structure is used for the whole of a single stream of\n * IDAT chunks (see the IDAT control structure below).\n */\nstruct chunk\n{\n   /* ANCESTORS */\n   struct file *         file;\n   struct global *       global;\n\n   /* PUBLIC IDAT INFORMATION: SET BY THE ZLIB CODE */\n   udigit         uncompressed_bytes[5];\n   int            uncompressed_digits;\n   udigit         compressed_bytes[5];\n   int            compressed_digits;\n\n   /* PUBLIC PER-CHUNK INFORMATION: USED BY CHUNK READ CODE */\n   /* This information is filled in by chunk_init from the data in the file\n    * control structure, but chunk_length may be changed later.\n    */\n   fpos_t         chunk_data_pos;    /* Position of first byte of chunk data */\n   png_uint_32    chunk_length;      /* From header (or modified below) */\n   png_uint_32    chunk_type;        /* From header */\n\n   /* PUBLIC PER-CHUNK INFORMATION: FOR THE CHUNK WRITE CODE */\n   png_uint_32    write_crc;         /* Output CRC (may differ from read_crc) */\n   png_uint_32    rewrite_offset;    /* Count of bytes before rewrite. */\n   int            rewrite_length;    /* Number of bytes left to change */\n   png_byte       rewrite_buffer[2]; /* Buffer of new byte values */\n};\n\nstatic void\nchunk_message(struct chunk *chunk, const char *message)\n{\n   type_message(chunk->file, chunk->chunk_type, message);\n}\n\nstatic void\nchunk_end(struct chunk **chunk_var)\n{\n   struct chunk *chunk = *chunk_var;\n\n   *chunk_var = NULL;\n   CLEAR(*chunk);\n}\n\nstatic void\nchunk_init(struct chunk * const chunk, struct file * const file)\n   /* When a chunk is initialized the file length/type/pos are copied into the\n    * corresponding chunk fields and the new chunk is registered in the file\n    * structure.  There can only be one chunk at a time.\n    *\n    * NOTE: this routine must onely be called from the file alloc routine!\n    */\n{\n   assert(file->chunk == NULL);\n\n   CLEAR(*chunk);\n\n   chunk->file = file;\n   chunk->global = file->global;\n\n   chunk->chunk_data_pos = file->data_pos;\n   chunk->chunk_length = file->length;\n   chunk->chunk_type = file->type;\n\n   /* Compresssed/uncompressed size information (from the zlib control structure\n    * that is used to check the compressed data in a chunk.)\n    */\n   chunk->uncompressed_digits = 0;\n   chunk->compressed_digits = 0;\n\n   file->chunk = chunk;\n}\n\nstatic png_uint_32\ncurrent_type(struct file *file, int code)\n   /* Guess the actual chunk type that causes a stop() */\n{\n   /* This may return png_IDAT for errors detected (late) in the header; that\n    * includes any inter-chunk consistency check that libpng performs.  Assume\n    * that if the chunk_type is png_IDAT and the file write count is 8 this is\n    * what is happening.\n    */\n   if (file->chunk != NULL)\n   {\n      png_uint_32 type = file->chunk->chunk_type;\n\n      /* This is probably wrong for the excess IDATs case, because then libpng\n       * whines about too many of them (apparently in some cases erroneously)\n       * when the header is read.\n       */\n      if (code <= LIBPNG_ERROR_CODE && type == png_IDAT &&\n         file->write_count == 8)\n         type = 0; /* magic */\n\n      return type;\n   }\n\n   else\n      return file->type;\n}\n\nstatic void\nsetpos(struct chunk *chunk)\n   /* Reset the position to 'chunk_data_pos' - the start of the data for this\n    * chunk.  As a side effect the read_count in the file is reset to 8, just\n    * after the length/type header.\n    */\n{\n   chunk->file->read_count = 8;\n   file_setpos(chunk->file, &chunk->chunk_data_pos);\n}\n\n/* Specific chunk handling - called for each chunk header, all special chunk\n * processing is initiated in these functions.\n */\n/* The next functions handle special processing for those chunks with LZ data,\n * the data is identified and checked for validity.  If there are problems which\n * cannot be corrected the routines return false, otherwise true (although\n * modification to the zlib header may be required.)\n *\n * The compressed data is in zlib format (RFC1950) and consequently has a\n * minimum length of 7 bytes.\n */\nstatic int zlib_check(struct file *file, png_uint_32 offset);\n\nstatic int\nprocess_zTXt_iCCP(struct file *file)\n   /* zTXt and iCCP have exactly the same form - keyword, null, compression\n    * method then compressed data.\n    */\n{\n   struct chunk *chunk = file->chunk;\n   png_uint_32 length;\n   png_uint_32 index = 0;\n\n   assert(chunk != NULL && file->idat == NULL);\n   length = chunk->chunk_length;\n   setpos(chunk);\n\n   while (length >= 9)\n   {\n      --length;\n      ++index;\n      if (reread_byte(file) == 0) /* keyword null terminator */\n      {\n         --length;\n         ++index;\n         (void)reread_byte(file); /* compression method */\n         return zlib_check(file, index);\n      }\n   }\n\n   chunk_message(chunk, \"too short\");\n   return 0; /* skip */\n}\n\nstatic int\nprocess_iTXt(struct file *file)\n{\n   /* Like zTXt but more fields. */\n   struct chunk *chunk = file->chunk;\n   png_uint_32 length;\n   png_uint_32 index = 0;\n\n   assert(chunk != NULL && file->idat == NULL);\n   length = chunk->chunk_length;\n   setpos(chunk);\n\n   while (length >= 5)\n   {\n      --length;\n      ++index;\n      if (reread_byte(file) == 0) /* keyword null terminator */\n      {\n         --length;\n         ++index;\n         if (reread_byte(file) == 0) /* uncompressed text */\n            return 1; /* nothing to check */\n\n         --length;\n         ++index;\n         (void)reread_byte(file); /* compression method */\n\n         /* Skip the language tag (null terminated). */\n         while (length >= 9)\n         {\n            --length;\n            ++index;\n            if (reread_byte(file) == 0) /* terminator */\n            {\n               /* Skip the translated keyword */\n               while (length >= 8)\n               {\n                  --length;\n                  ++index;\n                  if (reread_byte(file) == 0) /* terminator */\n                     return zlib_check(file, index);\n               }\n            }\n         }\n\n         /* Ran out of bytes in the compressed case. */\n         break;\n      }\n   }\n\n   log_error(file, INVALID_ERROR_CODE, \"iTXt chunk length\");\n\n   return 0; /* skip */\n}\n\n/* IDAT READ/WRITE CONTROL STRUCTURE */\nstruct IDAT\n{\n   /* ANCESTORS */\n   struct file *         file;\n   struct global *       global;\n\n   /* PROTECTED IDAT INFORMATION: SET BY THE IDAT READ CODE */\n   struct IDAT_list *idat_list_head; /* START of the list of IDAT information */\n   struct IDAT_list *idat_list_tail; /* *END* of the list of IDAT information */\n\n   /* PROTECTED IDAT INFORMATION: USED BY THE IDAT WRITE CODE */\n   struct IDAT_list *idat_cur;       /* Current list entry */\n   unsigned int      idat_count;     /* And the *current* index into the list */\n   png_uint_32       idat_index;     /* Index of *next* input byte to write */\n   png_uint_32       idat_length;    /* Cache of current chunk length */\n};\n\n/* NOTE: there is currently no IDAT_reset, so a stream cannot contain more than\n * one IDAT sequence (i.e. MNG is not supported).\n */\n\nstatic void\nIDAT_end(struct IDAT **idat_var)\n{\n   struct IDAT *idat = *idat_var;\n   struct file *file = idat->file;\n\n   *idat_var = NULL;\n\n   CLEAR(*idat);\n\n   assert(file->chunk != NULL);\n   chunk_end(&file->chunk);\n\n   /* Regardless of why the IDAT was killed set the state back to CHUNKS (it may\n    * already be CHUNKS because the state isn't changed until process_IDAT\n    * returns; a stop will cause IDAT_end to be entered in state CHUNKS!)\n    */\n   file->state = STATE_CHUNKS;\n}\n\nstatic void\nIDAT_init(struct IDAT * const idat, struct file * const file)\n   /* When the chunk is png_IDAT instantiate an IDAT control structure in place\n    * of a chunk control structure.  The IDAT will instantiate a chunk control\n    * structure using the file alloc routine.\n    *\n    * NOTE: this routine must only be called from the file alloc routine!\n    */\n{\n   assert(file->chunk == NULL);\n   assert(file->idat == NULL);\n\n   CLEAR(*idat);\n\n   idat->file = file;\n   idat->global = file->global;\n\n   /* Initialize the tail to the pre-allocated buffer and set the count to 0\n    * (empty.)\n    */\n   idat->global->idat_cache.count = 0;\n   idat->idat_list_head = idat->idat_list_tail = &idat->global->idat_cache;\n\n   /* Now the chunk.  The allocator calls the initializer of the new chunk and\n    * stores the result in file->chunk:\n    */\n   file->alloc(file, 0/*chunk*/);\n   assert(file->chunk != NULL);\n\n   /* And store this for cleanup (and to check for double alloc or failure to\n    * free.)\n    */\n   file->idat = idat;\n}\n\nstatic png_uint_32\nrechunk_length(struct IDAT *idat)\n   /* Return the length for the next IDAT chunk, taking into account\n    * rechunking.\n    */\n{\n   png_uint_32 len = idat->global->idat_max;\n\n   if (len == 0) /* use original chunk lengths */\n   {\n      const struct IDAT_list *cur;\n      unsigned int count;\n\n      if (idat->idat_index == 0) /* at the new chunk (first time) */\n         return idat->idat_length; /* use the cache */\n\n      /* Otherwise rechunk_length is called at the end of a chunk for the length\n       * of the next one.\n       */\n      cur = idat->idat_cur;\n      count = idat->idat_count;\n\n      assert(idat->idat_index == idat->idat_length &&\n         idat->idat_length == cur->lengths[count]);\n\n      /* Return length of the *next* chunk */\n      if (++count < cur->count)\n         return cur->lengths[count];\n\n      /* End of this list */\n      assert(cur != idat->idat_list_tail);\n      cur = cur->next;\n      assert(cur != NULL && cur->count > 0);\n      return cur->lengths[0];\n   }\n\n   else /* rechunking */\n   {\n      /* The chunk size is the lesser of file->idat_max and the number\n       * of remaining bytes.\n       */\n      png_uint_32 have = idat->idat_length - idat->idat_index;\n\n      if (len > have)\n      {\n         struct IDAT_list *cur = idat->idat_cur;\n         unsigned int j = idat->idat_count+1; /* the next IDAT in the list */\n\n         do\n         {\n            /* Add up the remaining bytes.  This can't overflow because the\n             * individual lengths are always <= 0x7fffffff, so when we add two\n             * of them overflow is not possible.\n             */\n            assert(cur != NULL);\n\n            for (;;)\n            {\n               /* NOTE: IDAT_list::count here, not IDAT_list::length */\n               for (; j < cur->count; ++j)\n               {\n                  have += cur->lengths[j];\n                  if (len <= have)\n                     return len;\n               }\n\n               /* If this was the end return the count of the available bytes */\n               if (cur == idat->idat_list_tail)\n                  return have;\n\n               cur = cur->next;\n               j = 0;\n            }\n         }\n         while (len > have);\n      }\n\n      return len;\n   }\n}\n\nstatic int\nprocess_IDAT(struct file *file)\n   /* Process the IDAT stream, this is the more complex than the preceding\n    * cases because the compressed data is spread across multiple IDAT chunks\n    * (typically).  Rechunking of the data is not handled here; all this\n    * function does is establish whether the zlib header needs to be modified.\n    *\n    * Initially the function returns false, indicating that the chunk should not\n    * be written.  It does this until the last IDAT chunk is passed in, then it\n    * checks the zlib data and returns true.\n    *\n    * It does not return false on a fatal error; it calls stop instead.\n    *\n    * The caller must have an instantiated (IDAT) control structure and it must\n    * have extent over the whole read of the IDAT stream.  For a PNG this means\n    * the whole PNG read, for MNG it could have lesser extent.\n    */\n{\n   struct IDAT_list *list;\n\n   assert(file->idat != NULL && file->chunk != NULL);\n\n   /* We need to first check the entire sequence of IDAT chunks to ensure the\n    * stream is in sync.  Do this by building a list of all the chunks and\n    * recording the length of each because the length may have been fixed up by\n    * sync_stream below.\n    *\n    * At the end of the list of chunks, where the type of the next chunk is not\n    * png_IDAT, process the whole stream using the list data to check validity\n    * then return control to the start and rewrite everything.\n    */\n   list = file->idat->idat_list_tail;\n\n   if (list->count == list->length)\n   {\n      list = IDAT_list_extend(list);\n\n      if (list == NULL)\n         stop(file, READ_ERROR_CODE, \"out of memory\");\n\n      /* Move to the next block */\n      list->count = 0;\n      file->idat->idat_list_tail = list;\n   }\n\n   /* And fill in the next IDAT information buffer. */\n   list->lengths[(list->count)++] = file->chunk->chunk_length;\n\n   /* The type of the next chunk was recorded in the file control structure by\n    * the caller, if this is png_IDAT return 'skip' to the caller.\n    */\n   if (file->type == png_IDAT)\n      return 0; /* skip this for the moment */\n\n   /* This is the final IDAT chunk, so run the tests to check for the too far\n    * back error and possibly optimize the window bits.  This means going back\n    * to the start of the first chunk data, which is stored in the original\n    * chunk allocation.\n    */\n   setpos(file->chunk);\n\n   if (zlib_check(file, 0))\n   {\n      struct IDAT *idat;\n      int cmp;\n\n      /* The IDAT stream was successfully uncompressed; see whether it\n       * contained the correct number of bytes of image data.\n       */\n      cmp = uarb_cmp(file->image_bytes, file->image_digits,\n         file->chunk->uncompressed_bytes, file->chunk->uncompressed_digits);\n\n      if (cmp < 0)\n         type_message(file, png_IDAT, \"extra uncompressed data\");\n\n      else if (cmp > 0)\n         stop(file, LIBPNG_ERROR_CODE, \"IDAT: uncompressed data too small\");\n\n      /* Return the stream to the start of the first IDAT chunk; the length\n       * is set in the write case below but the input chunk variables must be\n       * set (once) here:\n       */\n      setpos(file->chunk);\n\n      idat = file->idat;\n      idat->idat_cur = idat->idat_list_head;\n      idat->idat_length = idat->idat_cur->lengths[0];\n      idat->idat_count = 0; /* Count of chunks read in current list */\n      idat->idat_index = 0; /* Index into chunk data */\n\n      /* Update the chunk length to the correct value for the IDAT chunk: */\n      file->chunk->chunk_length = rechunk_length(idat);\n\n      /* Change the state to writing IDAT chunks */\n      file->state = STATE_IDAT;\n\n      return 1;\n   }\n\n   else /* Failure to decompress the IDAT stream; give up. */\n      stop(file, ZLIB_ERROR_CODE, \"could not uncompress IDAT\");\n}\n\n/* ZLIB CONTROL STRUCTURE */\nstruct zlib\n{\n   /* ANCESTORS */\n   struct IDAT *  idat;          /* NOTE: May be NULL */\n   struct chunk * chunk;\n   struct file *  file;\n   struct global *global;\n\n   /* GLOBAL ZLIB INFORMATION: SET BY THE CALLER */\n   png_uint_32    rewrite_offset;\n\n   /* GLOBAL ZLIB INFORMATION: SET BY THE ZLIB READ CODE */\n   udigit         compressed_bytes[5];\n   int            compressed_digits;\n   udigit         uncompressed_bytes[5];\n   int            uncompressed_digits;\n   int            file_bits;             /* window bits from the file */\n   int            ok_bits;               /* Set <16 on a successful read */\n   int            cksum;                 /* Set on a checksum error */\n\n   /* PROTECTED ZLIB INFORMATION: USED BY THE ZLIB ROUTINES */\n   z_stream       z;\n   png_uint_32    extra_bytes;   /* Count of extra compressed bytes */\n   int            state;\n   int            rc;            /* Last return code */\n   int            window_bits;   /* 0 if no change */\n   png_byte       header[2];\n};\n\nstatic const char *\nzlib_flevel(struct zlib *zlib)\n{\n   switch (zlib->header[1] >> 6)\n   {\n      case 0:  return \"supfast\";\n      case 1:  return \"stdfast\";\n      case 2:  return \"default\";\n      case 3:  return \"maximum\";\n      default: assert(UNREACHED);\n   }\n\n   return \"COMPILER BUG\";\n}\n\nstatic const char *\nzlib_rc(struct zlib *zlib)\n   /* Return a string for the zlib return code */\n{\n   switch (zlib->rc)\n   {\n      case Z_OK:              return \"Z_OK\";\n      case Z_STREAM_END:      return \"Z_STREAM_END\";\n      case Z_NEED_DICT:       return \"Z_NEED_DICT\";\n      case Z_ERRNO:           return \"Z_ERRNO\";\n      case Z_STREAM_ERROR:    return \"Z_STREAM_ERROR\";\n      case Z_DATA_ERROR:      return \"Z_DATA_ERROR\";\n      case Z_MEM_ERROR:       return \"Z_MEM_ERROR\";\n      case Z_BUF_ERROR:       return \"Z_BUF_ERROR\";\n      case Z_VERSION_ERROR:   return \"Z_VERSION_ERROR\";\n      default:                return \"Z_*INVALID_RC*\";\n   }\n}\n\nstatic void\nzlib_message(struct zlib *zlib, int unexpected)\n   /* Output a message given a zlib rc */\n{\n   if (zlib->global->errors)\n   {\n      const char *reason = zlib->z.msg;\n\n      if (reason == NULL)\n         reason = \"[no message]\";\n\n      fputs(zlib->file->file_name, stderr);\n      type_sep(stderr);\n      type_name(zlib->chunk->chunk_type, stderr);\n      fprintf(stderr, \": %szlib error: %d (%s) (%s)\\n\",\n         unexpected ? \"unexpected \" : \"\", zlib->rc, zlib_rc(zlib), reason);\n   }\n}\n\nstatic void\nzlib_end(struct zlib *zlib)\n{\n   /* Output the summary line now; this ensures a summary line always gets\n    * output regardless of the manner of exit.\n    */\n   if (!zlib->global->quiet)\n   {\n      if (zlib->ok_bits < 16) /* stream was read ok */\n      {\n         const char *reason;\n\n         if (zlib->cksum)\n            reason = \"CHK\"; /* checksum error */\n\n         else if (zlib->ok_bits > zlib->file_bits)\n            reason = \"TFB\"; /* fixing a too-far-back error */\n\n         else if (zlib->ok_bits == zlib->file_bits)\n            reason = \"OK \";\n\n         else\n            reason = \"OPT\"; /* optimizing window bits */\n\n         /* SUMMARY FORMAT (for a successful zlib inflate):\n          *\n          * IDAT reason flevel file-bits ok-bits compressed uncompressed file\n          */\n         type_name(zlib->chunk->chunk_type, stdout);\n         printf(\" %s %s %d %d \", reason, zlib_flevel(zlib), zlib->file_bits,\n            zlib->ok_bits);\n         uarb_print(zlib->compressed_bytes, zlib->compressed_digits, stdout);\n         putc(' ', stdout);\n         uarb_print(zlib->uncompressed_bytes, zlib->uncompressed_digits,\n            stdout);\n         putc(' ', stdout);\n         fputs(zlib->file->file_name, stdout);\n         putc('\\n', stdout);\n      }\n\n      else\n      {\n         /* This is a zlib read error; the chunk will be skipped.  For an IDAT\n          * stream this will also cause a fatal read error (via stop()).\n          *\n          * SUMMARY FORMAT:\n          *\n          * IDAT SKP flevel file-bits z-rc compressed message file\n          *\n          * z-rc is the zlib failure code; message is the error message with\n          * spaces replaced by '-'.  The compressed byte count indicates where\n          * in the zlib stream the error occurred.\n          */\n         type_name(zlib->chunk->chunk_type, stdout);\n         printf(\" SKP %s %d %s \", zlib_flevel(zlib), zlib->file_bits,\n            zlib_rc(zlib));\n         uarb_print(zlib->compressed_bytes, zlib->compressed_digits, stdout);\n         putc(' ', stdout);\n         emit_string(zlib->z.msg ? zlib->z.msg : \"[no_message]\", stdout);\n         putc(' ', stdout);\n         fputs(zlib->file->file_name, stdout);\n         putc('\\n', stdout);\n      }\n   }\n\n   if (zlib->state >= 0)\n   {\n      zlib->rc = inflateEnd(&zlib->z);\n\n      if (zlib->rc != Z_OK)\n         zlib_message(zlib, 1/*unexpected*/);\n   }\n\n   CLEAR(*zlib);\n}\n\nstatic int\nzlib_reset(struct zlib *zlib, int window_bits)\n   /* Reinitializes a zlib with a different window_bits */\n{\n   assert(zlib->state >= 0); /* initialized by zlib_init */\n\n   zlib->z.next_in = Z_NULL;\n   zlib->z.avail_in = 0;\n   zlib->z.next_out = Z_NULL;\n   zlib->z.avail_out = 0;\n\n   zlib->window_bits = window_bits;\n   zlib->compressed_digits = 0;\n   zlib->uncompressed_digits = 0;\n\n   zlib->state = 0; /* initialized, once */\n   zlib->rc = inflateReset2(&zlib->z, 0);\n   if (zlib->rc != Z_OK)\n   {\n      zlib_message(zlib, 1/*unexpected*/);\n      return 0;\n   }\n\n   return 1;\n}\n\nstatic int\nzlib_init(struct zlib *zlib, struct IDAT *idat, struct chunk *chunk,\n   int window_bits, png_uint_32 offset)\n   /* Initialize a zlib_control; the result is true/false */\n{\n   CLEAR(*zlib);\n\n   zlib->idat = idat;\n   zlib->chunk = chunk;\n   zlib->file = chunk->file;\n   zlib->global = chunk->global;\n   zlib->rewrite_offset = offset; /* never changed for this zlib */\n\n   /* *_out does not need to be set: */\n   zlib->z.next_in = Z_NULL;\n   zlib->z.avail_in = 0;\n   zlib->z.zalloc = Z_NULL;\n   zlib->z.zfree = Z_NULL;\n   zlib->z.opaque = Z_NULL;\n\n   zlib->state = -1;\n   zlib->window_bits = window_bits;\n\n   zlib->compressed_digits = 0;\n   zlib->uncompressed_digits = 0;\n\n   /* These values are sticky across reset (in addition to the stuff in the\n    * first block, which is actually constant.)\n    */\n   zlib->file_bits = 24;\n   zlib->ok_bits = 16; /* unset */\n   zlib->cksum = 0; /* set when a checksum error is detected */\n\n   /* '0' means use the header; inflateInit2 should always succeed because it\n    * does nothing apart from allocating the internal zstate.\n    */\n   zlib->rc = inflateInit2(&zlib->z, 0);\n   if (zlib->rc != Z_OK)\n   {\n      zlib_message(zlib, 1/*unexpected*/);\n      return 0;\n   }\n\n   else\n   {\n      zlib->state = 0; /* initialized */\n      return 1;\n   }\n}\n\nstatic int\nmax_window_bits(uarbc size, int ndigits)\n   /* Return the zlib stream window bits required for data of the given size. */\n{\n   png_uint_16 cb;\n\n   if (ndigits > 1)\n      return 15;\n\n   cb = size[0];\n\n   if (cb > 16384) return 15;\n   if (cb >  8192) return 14;\n   if (cb >  4096) return 13;\n   if (cb >  2048) return 12;\n   if (cb >  1024) return 11;\n   if (cb >   512) return 10;\n   if (cb >   256) return  9;\n   return 8;\n}\n\nstatic int\nzlib_advance(struct zlib *zlib, png_uint_32 nbytes)\n   /* Read nbytes compressed bytes; the stream will be initialized if required.\n    * Bytes are always being reread and errors are fatal.  The return code is as\n    * follows:\n    *\n    *    -1: saw the \"too far back\" error\n    *     0: ok, keep going\n    *     1: saw Z_STREAM_END (zlib->extra_bytes indicates too much data)\n    *     2: a zlib error that cannot be corrected (error message already\n    *        output if required.)\n    */\n#  define ZLIB_TOO_FAR_BACK (-1)\n#  define ZLIB_OK           0\n#  define ZLIB_STREAM_END   1\n#  define ZLIB_FATAL        2\n{\n   int state = zlib->state;\n   int endrc = ZLIB_OK;\n   png_uint_32 in_bytes = 0;\n   struct file *file = zlib->file;\n\n   assert(state >= 0);\n\n   while (in_bytes < nbytes && endrc == ZLIB_OK)\n   {\n      png_uint_32 out_bytes;\n      int flush;\n      png_byte bIn = reread_byte(file);\n      png_byte bOut;\n\n      switch (state)\n      {\n         case 0: /* first header byte */\n            {\n               int file_bits = 8+(bIn >> 4);\n               int new_bits = zlib->window_bits;\n\n               zlib->file_bits = file_bits;\n\n               /* Check against the existing value - it may not need to be\n                * changed.  Note that a bogus file_bits is allowed through once,\n                * to see if it works, but the window_bits value is set to 15,\n                * the maximum.\n                */\n               if (new_bits == 0) /* no change */\n                  zlib->window_bits = ((file_bits > 15) ? 15 : file_bits);\n\n               else if (new_bits != file_bits) /* rewrite required */\n                  bIn = (png_byte)((bIn & 0xf) + ((new_bits-8) << 4));\n            }\n\n            zlib->header[0] = bIn;\n            zlib->state = state = 1;\n            break;\n\n         case 1: /* second header byte */\n            {\n               int b2 = bIn & 0xe0; /* top 3 bits */\n\n               /* The checksum calculation, on the first 11 bits: */\n               b2 += 0x1f - ((zlib->header[0] << 8) + b2) % 0x1f;\n\n               /* Update the checksum byte if required: */\n               if (bIn != b2)\n               {\n                  /* If the first byte wasn't changed this indicates an error in\n                   * the checksum calculation; signal this by setting 'cksum'.\n                   */\n                  if (zlib->file_bits == zlib->window_bits)\n                     zlib->cksum = 1;\n\n                  bIn = (png_byte)b2;\n               }\n            }\n\n            zlib->header[1] = bIn;\n            zlib->state = state = 2;\n            break;\n\n         default: /* After the header bytes */\n            break;\n      }\n\n      /* For some streams, perhaps only those compressed with 'superfast\n       * compression' (which results in a lot of copying) Z_BUF_ERROR can happen\n       * immediately after all output has been flushed on the next input byte.\n       * This is handled below when Z_BUF_ERROR is detected by adding an output\n       * byte.\n       */\n      zlib->z.next_in = &bIn;\n      zlib->z.avail_in = 1;\n      zlib->z.next_out = &bOut;\n      zlib->z.avail_out = 0;     /* Initially */\n\n      /* Initially use Z_NO_FLUSH in an attempt to persuade zlib to look at this\n       * byte without confusing what is going on with output.\n       */\n      flush = Z_NO_FLUSH;\n      out_bytes = 0;\n\n      /* NOTE: expression 3 is only evaluted on 'continue', because of the\n       * 'break' at the end of this loop below.\n       */\n      for (;endrc == ZLIB_OK;\n         flush = Z_SYNC_FLUSH,\n         zlib->z.next_out = &bOut,\n         zlib->z.avail_out = 1,\n         ++out_bytes)\n      {\n         zlib->rc = inflate(&zlib->z, flush);\n         out_bytes -= zlib->z.avail_out;\n\n         switch (zlib->rc)\n         {\n            case Z_BUF_ERROR:\n               if (zlib->z.avail_out == 0)\n                  continue; /* Try another output byte. */\n\n               if (zlib->z.avail_in == 0)\n                  break; /* Try another input byte */\n\n               /* Both avail_out and avail_in are 1 yet zlib returned a code\n                * indicating no progress was possible.  This is unexpected.\n                */\n               zlib_message(zlib, 1/*unexpected*/);\n               endrc = ZLIB_FATAL; /* stop processing */\n               break;\n\n            case Z_OK:\n               /* Zlib is supposed to have made progress: */\n               assert(zlib->z.avail_out == 0 || zlib->z.avail_in == 0);\n               continue;\n\n            case Z_STREAM_END:\n               /* This is the successful end. */\n               zlib->state = 3; /* end of stream */\n               endrc = ZLIB_STREAM_END;\n               break;\n\n            case Z_NEED_DICT:\n               zlib_message(zlib, 0/*stream error*/);\n               endrc = ZLIB_FATAL;\n               break;\n\n            case Z_DATA_ERROR:\n               /* The too far back error can be corrected, others cannot: */\n               if (zlib->z.msg != NULL &&\n                  strcmp(zlib->z.msg, \"invalid distance too far back\") == 0)\n               {\n                  endrc = ZLIB_TOO_FAR_BACK;\n                  break;\n               }\n               /* FALL THROUGH */\n\n            default:\n               zlib_message(zlib, 0/*stream error*/);\n               endrc = ZLIB_FATAL;\n               break;\n         } /* switch (inflate rc) */\n\n         /* Control gets here when further output is not possible; endrc may\n          * still be ZLIB_OK if more input is required.\n          */\n         break;\n      } /* for (output bytes) */\n\n      /* Keep a running count of output byte produced: */\n      zlib->uncompressed_digits = uarb_add32(zlib->uncompressed_bytes,\n         zlib->uncompressed_digits, out_bytes);\n\n      /* Keep going, the loop will terminate when endrc is no longer set to\n       * ZLIB_OK or all the input bytes have been consumed; meanwhile keep\n       * adding input bytes.\n       */\n      assert(zlib->z.avail_in == 0 || endrc != ZLIB_OK);\n\n      in_bytes += 1 - zlib->z.avail_in;\n   } /* while (input bytes) */\n\n   assert(in_bytes == nbytes || endrc != ZLIB_OK);\n\n   /* Update the running total of input bytes consumed */\n   zlib->compressed_digits = uarb_add32(zlib->compressed_bytes,\n      zlib->compressed_digits, in_bytes - zlib->z.avail_in);\n\n   /* At the end of the stream update the chunk with the accumulated\n    * information if it is an improvement:\n    */\n   if (endrc == ZLIB_STREAM_END && zlib->window_bits < zlib->ok_bits)\n   {\n      struct chunk *chunk = zlib->chunk;\n\n      chunk->uncompressed_digits = uarb_copy(chunk->uncompressed_bytes,\n         zlib->uncompressed_bytes, zlib->uncompressed_digits);\n      chunk->compressed_digits = uarb_copy(chunk->compressed_bytes,\n         zlib->compressed_bytes, zlib->compressed_digits);\n      chunk->rewrite_buffer[0] = zlib->header[0];\n      chunk->rewrite_buffer[1] = zlib->header[1];\n\n      if (zlib->window_bits != zlib->file_bits || zlib->cksum)\n      {\n         /* A rewrite is required */\n         chunk->rewrite_offset = zlib->rewrite_offset;\n         chunk->rewrite_length = 2;\n      }\n\n      else\n      {\n         chunk->rewrite_offset = 0;\n         chunk->rewrite_length = 0;\n      }\n\n      if (in_bytes < nbytes)\n         chunk_message(chunk, \"extra compressed data\");\n\n      zlib->extra_bytes = nbytes - in_bytes;\n      zlib->ok_bits = zlib->window_bits;\n   }\n\n   return endrc;\n}\n\nstatic int\nzlib_run(struct zlib *zlib)\n   /* Like zlib_advance but also handles a stream of IDAT chunks. */\n{\n   /* The 'extra_bytes' field is set by zlib_advance if there is extra\n    * compressed data in the chunk it handles (if it sees Z_STREAM_END before\n    * all the input data has been used.)  This function uses the value to update\n    * the correct chunk length, so the problem should only ever be detected once\n    * for each chunk.  zlib_advance outputs the error message, though see the\n    * IDAT specific check below.\n    */\n   zlib->extra_bytes = 0;\n\n   if (zlib->idat != NULL)\n   {\n      struct IDAT_list *list = zlib->idat->idat_list_head;\n      struct IDAT_list *last = zlib->idat->idat_list_tail;\n      int        skip = 0;\n\n      /* 'rewrite_offset' is the offset of the LZ data within the chunk, for\n       * IDAT it should be 0:\n       */\n      assert(zlib->rewrite_offset == 0);\n\n      /* Process each IDAT_list in turn; the caller has left the stream\n       * positioned at the start of the first IDAT chunk data.\n       */\n      for (;;)\n      {\n         const unsigned int count = list->count;\n         unsigned int i;\n\n         for (i = 0; i<count; ++i)\n         {\n            int rc;\n\n            if (skip > 0) /* Skip CRC and next IDAT header */\n               skip_12(zlib->file);\n\n            skip = 12; /* for the next time */\n\n            rc = zlib_advance(zlib, list->lengths[i]);\n\n            switch (rc)\n            {\n               case ZLIB_OK: /* keep going */\n                  break;\n\n               case ZLIB_STREAM_END: /* stop */\n                  /* There may be extra chunks; if there are and one of them is\n                   * not zero length output the 'extra data' message.  Only do\n                   * this check if errors are being output.\n                   */\n                  if (zlib->global->errors && zlib->extra_bytes == 0)\n                  {\n                     struct IDAT_list *check = list;\n                     int j = i+1, jcount = count;\n\n                     for (;;)\n                     {\n                        for (; j<jcount; ++j)\n                           if (check->lengths[j] > 0)\n                           {\n                              chunk_message(zlib->chunk,\n                                 \"extra compressed data\");\n                              goto end_check;\n                           }\n\n                        if (check == last)\n                           break;\n\n                        check = check->next;\n                        jcount = check->count;\n                        j = 0;\n                     }\n                  }\n\n               end_check:\n                  /* Terminate the list at the current position, reducing the\n                   * length of the last IDAT too if required.\n                   */\n                  list->lengths[i] -= zlib->extra_bytes;\n                  list->count = i+1;\n                  zlib->idat->idat_list_tail = list;\n                  /* FALL THROUGH */\n\n               default:\n                  return rc;\n            }\n         }\n\n         /* At the end of the compressed data and Z_STREAM_END was not seen. */\n         if (list == last)\n            return ZLIB_OK;\n\n         list = list->next;\n      }\n   }\n\n   else\n   {\n      struct chunk *chunk = zlib->chunk;\n      int rc;\n\n      assert(zlib->rewrite_offset < chunk->chunk_length);\n\n      rc = zlib_advance(zlib, chunk->chunk_length - zlib->rewrite_offset);\n\n      /* The extra bytes in the chunk are handled now by adjusting the chunk\n       * length to exclude them; the zlib data is always stored at the end of\n       * the PNG chunk (although clearly this is not necessary.)  zlib_advance\n       * has already output a warning message.\n       */\n      chunk->chunk_length -= zlib->extra_bytes;\n      return rc;\n   }\n}\n\nstatic int /* global function; not a member function */\nzlib_check(struct file *file, png_uint_32 offset)\n   /* Check the stream of zlib compressed data in either idat (if given) or (if\n    * not) chunk.  In fact it is zlib_run that handles the difference in reading\n    * a single chunk and a list of IDAT chunks.\n    *\n    * In either case the input file must be positioned at the first byte of zlib\n    * compressed data (the first header byte).\n    *\n    * The return value is true on success, including the case where the zlib\n    * header may need to be rewritten, and false on an unrecoverable error.\n    *\n    * In the case of IDAT chunks 'offset' should be 0.\n    */\n{\n   fpos_t start_pos;\n   struct zlib zlib;\n\n   /* Record the start of the LZ data to allow a re-read. */\n   file_getpos(file, &start_pos);\n\n   /* First test the existing (file) window bits: */\n   if (zlib_init(&zlib, file->idat, file->chunk, 0/*window bits*/, offset))\n   {\n      int min_bits, max_bits, rc;\n\n      /* The first run using the existing window bits. */\n      rc = zlib_run(&zlib);\n\n      switch (rc)\n      {\n         case ZLIB_TOO_FAR_BACK:\n            /* too far back error */\n            file->status_code |= TOO_FAR_BACK;\n            min_bits = zlib.window_bits + 1;\n            max_bits = 15;\n            break;\n\n         case ZLIB_STREAM_END:\n            if (!zlib.global->optimize_zlib &&\n               zlib.window_bits == zlib.file_bits && !zlib.cksum)\n            {\n               /* The trivial case where the stream is ok and optimization was\n                * not requested.\n                */\n               zlib_end(&zlib);\n               return 1;\n            }\n\n            max_bits = max_window_bits(zlib.uncompressed_bytes,\n               zlib.uncompressed_digits);\n            if (zlib.ok_bits < max_bits)\n               max_bits = zlib.ok_bits;\n            min_bits = 8;\n\n            /* cksum is set if there is an error in the zlib header checksum\n             * calculation in the original file (and this may be the only reason\n             * a rewrite is required).  We can't rely on the file window bits in\n             * this case, so do the optimization anyway.\n             */\n            if (zlib.cksum)\n               chunk_message(zlib.chunk, \"zlib checkum\");\n            break;\n\n\n         case ZLIB_OK:\n            /* Truncated stream; unrecoverable, gets converted to ZLIB_FATAL */\n            zlib.z.msg = PNGZ_MSG_CAST(\"[truncated]\");\n            zlib_message(&zlib, 0/*expected*/);\n            /* FALL THROUGH */\n\n         default:\n            /* Unrecoverable error; skip the chunk; a zlib_message has already\n             * been output.\n             */\n            zlib_end(&zlib);\n            return 0;\n      }\n\n      /* Optimize window bits or fix a too-far-back error.  min_bits and\n       * max_bits have been set appropriately, ok_bits records the bit value\n       * known to work.\n       */\n      while (min_bits < max_bits || max_bits < zlib.ok_bits/*if 16*/)\n      {\n         int test_bits = (min_bits + max_bits) >> 1;\n\n         if (zlib_reset(&zlib, test_bits))\n         {\n            file_setpos(file, &start_pos);\n            rc = zlib_run(&zlib);\n\n            switch (rc)\n            {\n               case ZLIB_TOO_FAR_BACK:\n                  min_bits = test_bits+1;\n                  if (min_bits > max_bits)\n                  {\n                     /* This happens when the stream really is damaged and it\n                      * contains a distance code that addresses bytes before\n                      * the start of the uncompressed data.\n                      */\n                     assert(test_bits == 15);\n\n                     /* Output the error that wasn't output before: */\n                     if (zlib.z.msg == NULL)\n                        zlib.z.msg = PNGZ_MSG_CAST(\n                           \"invalid distance too far back\");\n                     zlib_message(&zlib, 0/*stream error*/);\n                     zlib_end(&zlib);\n                     return 0;\n                  }\n                  break;\n\n               case ZLIB_STREAM_END: /* success */\n                  max_bits = test_bits;\n                  break;\n\n               default:\n                  /* A fatal error; this happens if a too-far-back error was\n                   * hiding a more serious error, zlib_advance has already\n                   * output a zlib_message.\n                   */\n                  zlib_end(&zlib);\n                  return 0;\n            }\n         }\n\n         else /* inflateReset2 failed */\n         {\n            zlib_end(&zlib);\n            return 0;\n         }\n      }\n\n      /* The loop guarantees this */\n      assert(zlib.ok_bits == max_bits);\n      zlib_end(&zlib);\n      return 1;\n   }\n\n   else /* zlib initialization failed - skip the chunk */\n   {\n      zlib_end(&zlib);\n      return 0;\n   }\n}\n\n/***************************** LIBPNG CALLBACKS *******************************/\n/* The strategy here is to run a regular libpng PNG file read but examine the\n * input data (from the file) before passing it to libpng so as to be aware of\n * the state we expect libpng to be in.  Warning and error callbacks are also\n * intercepted so that they can be quieted and interpreted.  Interpretation\n * depends on a somewhat risky string match for known error messages; let us\n * hope that this can be fixed in the next version of libpng.\n *\n * The control structure is pointed to by the libpng error pointer.  It contains\n * that set of structures which must persist across multiple read callbacks,\n * which is pretty much everything except the 'zlib' control structure.\n *\n * The file structure is instantiated in the caller of the per-file routine, but\n * the per-file routine contains the chunk and IDAT control structures.\n */\n/* The three routines read_chunk, process_chunk and sync_stream can only be\n * called via a call to read_chunk and only exit at a return from process_chunk.\n * These routines could have been written as one confusing large routine,\n * instead this code relies on the compiler to do tail call elimination.  The\n * possible calls are as follows:\n *\n * read_chunk\n *    -> sync_stream\n *       -> process_chunk\n *    -> process_chunk\n *       -> read_chunk\n *       returns\n */\nstatic void read_chunk(struct file *file);\nstatic void\nprocess_chunk(struct file *file, png_uint_32 file_crc, png_uint_32 next_length,\n   png_uint_32 next_type)\n   /* Called when the chunk data has been read, next_length and next_type\n    * will be set for the next chunk (or 0 if this is IEND).\n    *\n    * When this routine returns, chunk_length and chunk_type will be set for the\n    * next chunk to write because if a chunk is skipped this return calls back\n    * to read_chunk.\n    */\n{\n   const png_uint_32 type = file->type;\n\n   if (file->global->verbose > 1)\n   {\n      fputs(\"  \", stderr);\n      type_name(file->type, stderr);\n      fprintf(stderr, \" %lu 0x%.8x 0x%.8x\\n\", (unsigned long)file->length,\n         file->crc ^ 0xffffffff, file_crc);\n   }\n\n   /* The basic structure seems correct but the CRC may not match, in this\n    * case assume that it is simply a bad CRC, either wrongly calculated or\n    * because of damaged stream data.\n    */\n   if ((file->crc ^ 0xffffffff) != file_crc)\n   {\n      /* The behavior is set by the 'skip' setting; if it is anything other\n       * than SKIP_BAD_CRC ignore the bad CRC and return the chunk, with a\n       * corrected CRC and possibly processed, to libpng.  Otherwise skip the\n       * chunk, which will result in a fatal error if the chunk is critical.\n       */\n      file->status_code |= CRC_ERROR;\n\n      /* Ignore the bad CRC  */\n      if (file->global->skip != SKIP_BAD_CRC)\n         type_message(file, type, \"bad CRC\");\n\n      /* This will cause an IEND with a bad CRC to stop */\n      else if (CRITICAL(type))\n         stop(file, READ_ERROR_CODE, \"bad CRC in critical chunk\");\n\n      else\n      {\n         type_message(file, type, \"skipped: bad CRC\");\n\n         /* NOTE: this cannot be reached for IEND because it is critical. */\n         goto skip_chunk;\n      }\n   }\n\n   /* Check for other 'skip' cases and handle these; these only apply to\n    * ancillary chunks (and not tRNS, which should probably have been a critical\n    * chunk.)\n    */\n   if (skip_chunk_type(file->global, type))\n      goto skip_chunk;\n\n   /* The chunk may still be skipped if problems are detected in the LZ data,\n    * however the LZ data check requires a chunk.  Handle this by instantiating\n    * a chunk unless an IDAT is already instantiated (IDAT control structures\n    * instantiate their own chunk.)\n    */\n   if (type != png_IDAT)\n      file->alloc(file, 0/*chunk*/);\n\n   else if (file->idat == NULL)\n      file->alloc(file, 1/*IDAT*/);\n\n   else\n   {\n      /* The chunk length must be updated for process_IDAT */\n      assert(file->chunk != NULL);\n      assert(file->chunk->chunk_type == png_IDAT);\n      file->chunk->chunk_length = file->length;\n   }\n\n   /* Record the 'next' information too, now that the original values for\n    * this chunk have been copied.  Notice that the IDAT chunks only make a\n    * copy of the position of the first chunk, this is fine - process_IDAT does\n    * not need the position of this chunk.\n    */\n   file->length = next_length;\n   file->type = next_type;\n   getpos(file);\n\n   /* Do per-type processing, note that if this code does not return from the\n    * function the chunk will be skipped.  The rewrite is cancelled here so that\n    * it can be set in the per-chunk processing.\n    */\n   file->chunk->rewrite_length = 0;\n   file->chunk->rewrite_offset = 0;\n   switch (type)\n   {\n      default:\n         return;\n\n      case png_IHDR:\n         /* Read this now and update the control structure with the information\n          * it contains.  The header is validated completely to ensure this is a\n          * PNG.\n          */\n         {\n            struct chunk *chunk = file->chunk;\n\n            if (chunk->chunk_length != 13)\n               stop_invalid(file, \"IHDR length\");\n\n            /* Read all the IHDR information and validate it. */\n            setpos(chunk);\n            file->width = reread_4(file);\n            file->height = reread_4(file);\n            file->bit_depth = reread_byte(file);\n            file->color_type = reread_byte(file);\n            file->compression_method = reread_byte(file);\n            file->filter_method = reread_byte(file);\n            file->interlace_method = reread_byte(file);\n\n            /* This validates all the fields, and calls stop_invalid if\n             * there is a problem.\n             */\n            calc_image_size(file);\n         }\n         return;\n\n         /* Ancillary chunks that require further processing: */\n      case png_zTXt: case png_iCCP:\n         if (process_zTXt_iCCP(file))\n            return;\n         chunk_end(&file->chunk);\n         file_setpos(file, &file->data_pos);\n         break;\n\n      case png_iTXt:\n         if (process_iTXt(file))\n            return;\n         chunk_end(&file->chunk);\n         file_setpos(file, &file->data_pos);\n         break;\n\n      case png_IDAT:\n         if (process_IDAT(file))\n            return;\n         /* First pass: */\n         assert(next_type == png_IDAT);\n         break;\n   }\n\n   /* Control reaches this point if the chunk must be skipped.  For chunks other\n    * than IDAT this means that the zlib compressed data is fatally damanged and\n    * the chunk will not be passed to libpng.  For IDAT it means that the end of\n    * the IDAT stream has not yet been reached and we must handle the next\n    * (IDAT) chunk.  If the LZ data in an IDAT stream cannot be read 'stop' must\n    * be used to halt parsing of the PNG.\n    */\n   read_chunk(file);\n   return;\n\n   /* This is the generic code to skip the current chunk; simply jump to the\n    * next one.\n    */\nskip_chunk:\n   file->length = next_length;\n   file->type = next_type;\n   getpos(file);\n   read_chunk(file);\n}\n\nstatic png_uint_32\nget32(png_bytep buffer, int offset)\n   /* Read a 32-bit value from an 8-byte circular buffer (used only below).\n    */\n{\n   return\n      (buffer[ offset    & 7] << 24) +\n      (buffer[(offset+1) & 7] << 16) +\n      (buffer[(offset+2) & 7] <<  8) +\n      (buffer[(offset+3) & 7]      );\n}\n\nstatic void\nsync_stream(struct file *file)\n   /* The stream seems to be messed up, attempt to resync from the current chunk\n    * header.  Executes stop on a fatal error, otherwise calls process_chunk.\n    */\n{\n   png_uint_32 file_crc;\n\n   file->status_code |= STREAM_ERROR;\n\n   if (file->global->verbose)\n   {\n      fputs(\" SYNC \", stderr);\n      type_name(file->type, stderr);\n      putc('\\n', stderr);\n   }\n\n   /* Return to the start of the chunk data */\n   file_setpos(file, &file->data_pos);\n   file->read_count = 8;\n\n   if (read_4(file, &file_crc) == 4) /* else completely truncated */\n   {\n      /* Ignore the recorded chunk length, proceed through the data looking for\n       * a leading sequence of bytes that match the CRC in the following four\n       * bytes.  Each time a match is found check the next 8 bytes for a valid\n       * length, chunk-type pair.\n       */\n      png_uint_32 length;\n      png_uint_32 type = file->type;\n      png_uint_32 crc = crc_init_4(type);\n      png_byte buffer[8];\n      unsigned int nread = 0, nused = 0;\n\n      for (length=0; length <= 0x7fffffff; ++length)\n      {\n         int ch;\n\n         if ((crc ^ 0xffffffff) == file_crc)\n         {\n            /* A match on the CRC; for IEND this is sufficient, but for anything\n             * else expect a following chunk header.\n             */\n            if (type == png_IEND)\n            {\n               file->length = length;\n               process_chunk(file, file_crc, 0, 0);\n               return;\n            }\n\n            else\n            {\n               /* Need 8 bytes */\n               while (nread < 8+nused)\n               {\n                  ch = read_byte(file);\n                  if (ch == EOF)\n                     goto truncated;\n                  buffer[(nread++) & 7] = (png_byte)ch;\n               }\n\n               /* Prevent overflow */\n               nread -= nused & ~7;\n               nused -= nused & ~7; /* or, nused &= 7 ;-) */\n\n               /* Examine the 8 bytes for a valid chunk header. */\n               {\n                  png_uint_32 next_length = get32(buffer, nused);\n\n                  if (next_length < 0x7fffffff)\n                  {\n                     png_uint_32 next_type = get32(buffer, nused+4);\n\n                     if (chunk_type_valid(next_type))\n                     {\n                        file->read_count -= 8;\n                        process_chunk(file, file_crc, next_length, next_type);\n                        return;\n                     }\n                  }\n\n                  /* Not valid, keep going. */\n               }\n            }\n         }\n\n         /* This catches up with the circular buffer which gets filled above\n          * while checking a chunk header.  This code is slightly tricky - if\n          * the chunk_type is IEND the buffer will never be used, if it is not\n          * the code will always read ahead exactly 8 bytes and pass this on to\n          * process_chunk.  So the invariant that IEND leaves the file position\n          * after the IEND CRC and other chunk leave it after the *next* chunk\n          * header is not broken.\n          */\n         if (nread <= nused)\n         {\n            ch = read_byte(file);\n\n            if (ch == EOF)\n               goto truncated;\n         }\n\n         else\n            ch = buffer[(++nused) & 7];\n\n         crc = crc_one_byte(crc, file_crc >> 24);\n         file_crc = (file_crc << 8) + ch;\n      }\n\n      /* Control gets to here if when 0x7fffffff bytes (plus 8) have been read,\n       * ok, treat this as a damaged stream too:\n       */\n   }\n\ntruncated:\n   stop(file, READ_ERROR_CODE, \"damaged PNG stream\");\n}\n\nstatic void\nread_chunk(struct file *file)\n   /* On entry file::data_pos must be set to the position of the first byte\n    * of the chunk data *and* the input file must be at this position.  This\n    * routine (via process_chunk) instantiates a chunk or IDAT control structure\n    * based on file::length and file::type and also resets these fields and\n    * file::data_pos for the chunk after this one.  For an IDAT chunk the whole\n    * stream of IDATs will be read, until something other than an IDAT is\n    * encountered, and the file fields will be set for the chunk after the end\n    * of the stream of IDATs.\n    *\n    * For IEND the file::type field will be set to 0, and nothing beyond the end\n    * of the IEND chunk will have been read.\n    */\n{\n   png_uint_32 length = file->length;\n   png_uint_32 type = file->type;\n\n   /* After IEND file::type is set to 0, if libpng attempts to read\n    * more data at this point this is a bug in libpng.\n    */\n   if (type == 0)\n      stop(file, UNEXPECTED_ERROR_CODE, \"read beyond IEND\");\n\n   if (file->global->verbose > 2)\n   {\n      fputs(\"   \", stderr);\n      type_name(type, stderr);\n      fprintf(stderr, \" %lu\\n\", (unsigned long)length);\n   }\n\n   /* Start the read_crc calculation with the chunk type, then read to the end\n    * of the chunk data (without processing it in any way) to check that it is\n    * all there and calculate the CRC.\n    */\n   file->crc = crc_init_4(type);\n   if (crc_read_many(file, length)) /* else it was truncated */\n   {\n      png_uint_32 file_crc; /* CRC read from file */\n      unsigned int nread = read_4(file, &file_crc);\n\n      if (nread == 4)\n      {\n         if (type != png_IEND) /* do not read beyond IEND */\n         {\n            png_uint_32 next_length;\n\n            nread += read_4(file, &next_length);\n            if (nread == 8 && next_length <= 0x7fffffff)\n            {\n               png_uint_32 next_type;\n\n               nread += read_4(file, &next_type);\n\n               if (nread == 12 && chunk_type_valid(next_type))\n               {\n                  /* Adjust the read count back to the correct value for this\n                   * chunk.\n                   */\n                  file->read_count -= 8;\n                  process_chunk(file, file_crc, next_length, next_type);\n                  return;\n               }\n            }\n         }\n\n         else /* IEND */\n         {\n            process_chunk(file, file_crc, 0, 0);\n            return;\n         }\n      }\n   }\n\n   /* Control gets to here if the the stream seems invalid or damaged in some\n    * way.  Either there was a problem reading all the expected data (this\n    * chunk's data, its CRC and the length and type of the next chunk) or the\n    * next chunk length/type are invalid.  Notice that the cases that end up\n    * here all correspond to cases that would otherwise terminate the read of\n    * the PNG file.\n    */\n   sync_stream(file);\n}\n\n/* This returns a file* from a png_struct in an implementation specific way. */\nstatic struct file *get_control(png_const_structrp png_ptr);\n\nstatic void PNGCBAPI\nerror_handler(png_structp png_ptr, png_const_charp message)\n{\n   stop(get_control(png_ptr),  LIBPNG_ERROR_CODE, message);\n}\n\nstatic void PNGCBAPI\nwarning_handler(png_structp png_ptr, png_const_charp message)\n{\n   struct file *file = get_control(png_ptr);\n\n   if (file->global->warnings)\n      emit_error(file, LIBPNG_WARNING_CODE, message);\n}\n\n/* Read callback - this is where the work gets done to check the stream before\n * passing it to libpng\n */\nstatic void PNGCBAPI\nread_callback(png_structp png_ptr, png_bytep buffer, size_t count)\n   /* Return 'count' bytes to libpng in 'buffer' */\n{\n   struct file *file = get_control(png_ptr);\n   png_uint_32 type, length; /* For the chunk be *WRITTEN* */\n   struct chunk *chunk;\n\n   /* libpng should always ask for at least one byte */\n   if (count == 0)\n      stop(file, UNEXPECTED_ERROR_CODE, \"read callback for 0 bytes\");\n\n   /* The callback always reads ahead by 8 bytes - the signature or chunk header\n    * - these bytes are stored in chunk_length and chunk_type.  This block is\n    * executed once for the signature and once for the first chunk right at the\n    * start.\n    */\n   if (file->read_count < 8)\n   {\n      assert(file->read_count == 0);\n      assert((file->status_code & TRUNCATED) == 0);\n\n      (void)read_4(file, &file->length);\n\n      if (file->read_count == 4)\n         (void)read_4(file, &file->type);\n\n      if (file->read_count < 8)\n      {\n         assert((file->status_code & TRUNCATED) != 0);\n         stop(file, READ_ERROR_CODE, \"not a PNG (too short)\");\n      }\n\n      if (file->state == STATE_SIGNATURE)\n      {\n         if (file->length != sig1 || file->type != sig2)\n            stop(file, LIBPNG_ERROR_CODE, \"not a PNG (signature)\");\n\n         /* Else write it (this is the initialization of write_count, prior to\n          * this it contains CLEAR garbage.)\n          */\n         file->write_count = 0;\n      }\n\n      else\n      {\n         assert(file->state == STATE_CHUNKS);\n\n         /* The first chunk must be a well formed IHDR (this could be relaxed to\n          * use the checks in process_chunk, but that seems unnecessary.)\n          */\n         if (file->length != 13 || file->type != png_IHDR)\n            stop(file, LIBPNG_ERROR_CODE, \"not a PNG (IHDR)\");\n\n         /* The position of the data must be stored too */\n         getpos(file);\n      }\n   }\n\n   /* Retrieve previous state (because the read callbacks are made pretty much\n    * byte-by-byte in the sequential reader prior to 1.7).\n    */\n   chunk = file->chunk;\n\n   if (chunk != NULL)\n   {\n      length = chunk->chunk_length;\n      type = chunk->chunk_type;\n   }\n\n   else\n   {\n      /* This is the signature case; for IDAT and other chunks these values will\n       * be overwritten when read_chunk is called below.\n       */\n      length = file->length;\n      type = file->type;\n   }\n\n   do\n   {\n      png_uint_32 b;\n\n      /* Complete the read of a chunk; as a side effect this also instantiates\n       * a chunk control structure and sets the file length/type/data_pos fields\n       * for the *NEXT* chunk header.\n       *\n       * NOTE: at an IDAT any following IDAT chunks will also be read and the\n       * next_ fields will refer to the chunk after the last IDAT.\n       *\n       * NOTE: read_chunk only returns when it has read a chunk that must now be\n       * written.\n       */\n      if (file->state != STATE_SIGNATURE && chunk == NULL)\n      {\n         assert(file->read_count == 8);\n         assert(file->idat == NULL);\n         read_chunk(file);\n         chunk = file->chunk;\n         assert(chunk != NULL);\n\n         /* Do the initialization that was not done before. */\n         length = chunk->chunk_length;\n         type = chunk->chunk_type;\n\n         /* And start writing the new chunk. */\n         file->write_count = 0;\n      }\n\n      /* The chunk_ fields describe a chunk that must be written, or hold the\n       * signature.  Write the header first.  In the signature case this\n       * rewrites the signature.\n       */\n      switch (file->write_count)\n      {\n         case 0: b = length >> 24; break;\n         case 1: b = length >> 16; break;\n         case 2: b = length >>  8; break;\n         case 3: b = length      ; break;\n\n         case 4: b = type >> 24; break;\n         case 5: b = type >> 16; break;\n         case 6: b = type >>  8; break;\n         case 7: b = type      ; break;\n\n         case 8:\n            /* The header has been written.  If this is really the signature\n             * that's all that is required and we can go to normal chunk\n             * processing.\n             */\n            if (file->state == STATE_SIGNATURE)\n            {\n               /* The signature has been written, the tail call to read_callback\n                * below (it's just a goto to the start with a decent compiler)\n                * will read the IHDR header ahead and validate it.\n                */\n               assert(length == sig1 && type == sig2);\n               file->read_count = 0; /* Forces a header read */\n               file->state = STATE_CHUNKS; /* IHDR: checked above */\n               read_callback(png_ptr, buffer, count);\n               return;\n            }\n\n            else\n            {\n               assert(chunk != NULL);\n\n               /* Set up for write, notice that repositioning the input stream\n                * is only necessary if something is to be read from it.  Also\n                * notice that for the IDAT stream this must only happen once -\n                * on the first IDAT - to get back to the start of the list and\n                * this is done inside process_IDAT:\n                */\n               chunk->write_crc = crc_init_4(type);\n               if (file->state != STATE_IDAT && length > 0)\n                  setpos(chunk);\n            }\n            /* FALL THROUGH */\n\n         default:\n            assert(chunk != NULL);\n\n            /* NOTE: the arithmetic below overflows and gives a large positive\n             * png_uint_32 value until the whole chunk data has been written.\n             */\n            switch (file->write_count - length)\n            {\n               /* Write the chunk data, normally this just comes from\n                * the file.  The only exception is for that part of a\n                * chunk which is zlib data and which must be rewritten,\n                * and IDAT chunks which can be completely\n                * reconstructed.\n                */\n               default:\n                  if (file->state == STATE_IDAT)\n                  {\n                     struct IDAT *idat = file->idat;\n\n                     assert(idat != NULL);\n\n                     /* Read an IDAT byte from the input stream of IDAT chunks.\n                      * Because the IDAT stream can be re-chunked this stream is\n                      * held in the struct IDAT members.  The chunk members, in\n                      * particular chunk_length (and therefore the length local)\n                      * refer to the output chunk.\n                      */\n                     while (idat->idat_index >= idat->idat_length)\n                     {\n                        /* Advance one chunk */\n                        struct IDAT_list *cur = idat->idat_cur;\n\n                        assert(idat->idat_index == idat->idat_length);\n                        assert(cur != NULL && cur->count > 0);\n\n                        /* NOTE: IDAT_list::count here, not IDAT_list::length */\n                        if (++(idat->idat_count) >= cur->count)\n                        {\n                           assert(idat->idat_count == cur->count);\n\n                           /* Move on to the next IDAT_list: */\n                           cur = cur->next;\n\n                           /* This is an internal error - read beyond the end of\n                            * the pre-calculated stream.\n                            */\n                           if (cur == NULL || cur->count == 0)\n                              stop(file, UNEXPECTED_ERROR_CODE,\n                                 \"read beyond end of IDAT\");\n\n                           idat->idat_count = 0;\n                           idat->idat_cur = cur;\n                        }\n\n                        idat->idat_index = 0;\n                        /* Zero length IDAT chunks are permitted, so the length\n                         * here may be 0.\n                         */\n                        idat->idat_length = cur->lengths[idat->idat_count];\n\n                        /* And skip 12 bytes to the next chunk data */\n                        skip_12(file);\n                     }\n\n                     /* The index is always that of the next byte, the rest of\n                      * the information is always the current IDAT chunk and the\n                      * current list.\n                      */\n                     ++(idat->idat_index);\n                  }\n\n                  /* Read the byte from the stream. */\n                  b = reread_byte(file);\n\n                  /* If the byte must be rewritten handle that here */\n                  if (chunk->rewrite_length > 0)\n                  {\n                     if (chunk->rewrite_offset > 0)\n                        --(chunk->rewrite_offset);\n\n                     else\n                     {\n                        b = chunk->rewrite_buffer[0];\n                        memmove(chunk->rewrite_buffer, chunk->rewrite_buffer+1,\n                           (sizeof chunk->rewrite_buffer)-\n                              (sizeof chunk->rewrite_buffer[0]));\n\n                        --(chunk->rewrite_length);\n                     }\n                  }\n\n                  chunk->write_crc = crc_one_byte(chunk->write_crc, b);\n                  break;\n\n               /* The CRC is written at:\n                *\n                *    chunk_write == chunk_length+8..chunk_length+11\n                *\n                * so 8 to 11.  The CRC is not (yet) conditioned.\n                */\n               case  8: b = chunk->write_crc >> 24; goto write_crc;\n               case  9: b = chunk->write_crc >> 16; goto write_crc;\n               case 10: b = chunk->write_crc >>  8; goto write_crc;\n               case 11:\n                  /* This must happen before the chunk_end below: */\n                  b = chunk->write_crc;\n\n                  if (file->global->verbose > 2)\n                  {\n                     fputs(\"   \", stderr);\n                     type_name(type, stderr);\n                     fprintf(stderr, \" %lu 0x%.8x\\n\", (unsigned long)length,\n                        chunk->write_crc ^ 0xffffffff);\n                  }\n\n                  /* The IDAT stream is written without a call to read_chunk\n                   * until the end is reached.  rechunk_length() calculates the\n                   * length of the output chunks.  Control gets to this point at\n                   * the end of an *output* chunk - the length calculated by\n                   * rechunk_length.  If this corresponds to the end of the\n                   * input stream stop writing IDAT chunks, otherwise continue.\n                   */\n                  if (file->state == STATE_IDAT &&\n                     (file->idat->idat_index < file->idat->idat_length ||\n                      1+file->idat->idat_count < file->idat->idat_cur->count ||\n                      file->idat->idat_cur != file->idat->idat_list_tail))\n                  {\n                     /* Write another IDAT chunk.  Call rechunk_length to\n                      * calculate the length required.\n                      */\n                     length = chunk->chunk_length = rechunk_length(file->idat);\n                     assert(type == png_IDAT);\n                     file->write_count = 0; /* for the new chunk */\n                     --(file->write_count); /* fake out the increment below */\n                  }\n\n                  else\n                  {\n                     /* Entered at the end of a non-IDAT chunk and at the end of\n                      * the IDAT stream.  The rewrite should have been cleared.\n                      */\n                     if (chunk->rewrite_length > 0 || chunk->rewrite_offset > 0)\n                        stop(file, UNEXPECTED_ERROR_CODE, \"pending rewrite\");\n\n                     /* This is the last byte so reset chunk_read for the next\n                      * chunk and move the input file to the position after the\n                      * *next* chunk header if required.\n                      */\n                     file->read_count = 8;\n                     file_setpos(file, &file->data_pos);\n\n                     if (file->idat == NULL)\n                        chunk_end(&file->chunk);\n\n                     else\n                        IDAT_end(&file->idat);\n                  }\n\n               write_crc:\n                  b ^= 0xff; /* conditioning */\n                  break;\n            }\n            break;\n      }\n\n      /* Write one byte */\n      b &= 0xff;\n      *buffer++ = (png_byte)b;\n      --count;\n      write_byte(file, (png_byte)b); /* increments chunk_write */\n   }\n   while (count > 0);\n}\n\n/* Bundle the file and an uninitialized chunk and IDAT control structure\n * together to allow implementation of the chunk/IDAT allocate routine.\n */\nstruct control\n{\n   struct file  file;\n   struct chunk chunk;\n   struct IDAT  idat;\n};\n\nstatic int\ncontrol_end(struct control *control)\n{\n   return file_end(&control->file);\n}\n\nstatic struct file *\nget_control(png_const_structrp png_ptr)\n{\n   /* This just returns the (file*).  The chunk and idat control structures\n    * don't always exist.\n    */\n   struct control *control = voidcast(struct control*,\n      png_get_error_ptr(png_ptr));\n   return &control->file;\n}\n\nstatic void\nallocate(struct file *file, int allocate_idat)\n{\n   struct control *control = voidcast(struct control*, file->alloc_ptr);\n\n   if (allocate_idat)\n   {\n      assert(file->idat == NULL);\n      IDAT_init(&control->idat, file);\n   }\n\n   else /* chunk */\n   {\n      assert(file->chunk == NULL);\n      chunk_init(&control->chunk, file);\n   }\n}\n\nstatic int\ncontrol_init(struct control *control, struct global *global,\n   const char *file_name, const char *out_name)\n   /* This wraps file_init(&control::file) and simply returns the result from\n    * file_init.\n    */\n{\n   return file_init(&control->file, global, file_name, out_name, control,\n      allocate);\n}\n\nstatic int\nread_png(struct control *control)\n   /* Read a PNG, return 0 on success else an error (status) code; a bit mask as\n    * defined for file::status_code as above.\n    */\n{\n   png_structp png_ptr;\n   png_infop info_ptr = NULL;\n   volatile int rc;\n\n   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, control,\n      error_handler, warning_handler);\n\n   if (png_ptr == NULL)\n   {\n      /* This is not really expected. */\n      log_error(&control->file, LIBPNG_ERROR_CODE, \"OOM allocating png_struct\");\n      control->file.status_code |= INTERNAL_ERROR;\n      return LIBPNG_ERROR_CODE;\n   }\n\n   rc = setjmp(control->file.jmpbuf);\n   if (rc == 0)\n   {\n#     ifdef PNG_SET_USER_LIMITS_SUPPORTED\n         /* Remove any limits on the size of PNG files that can be read,\n          * without this we may reject files based on built-in safety\n          * limits.\n          */\n         png_set_user_limits(png_ptr, 0x7fffffff, 0x7fffffff);\n         png_set_chunk_cache_max(png_ptr, 0);\n         png_set_chunk_malloc_max(png_ptr, 0);\n#     endif\n\n      png_set_read_fn(png_ptr, control, read_callback);\n\n      info_ptr = png_create_info_struct(png_ptr);\n      if (info_ptr == NULL)\n         png_error(png_ptr, \"OOM allocating info structure\");\n\n      if (control->file.global->verbose)\n         fprintf(stderr, \" INFO\\n\");\n\n      png_read_info(png_ptr, info_ptr);\n\n      {\n        png_uint_32 height = png_get_image_height(png_ptr, info_ptr);\n        int passes = png_set_interlace_handling(png_ptr);\n        int pass;\n\n        png_start_read_image(png_ptr);\n\n        for (pass = 0; pass < passes; ++pass)\n        {\n           png_uint_32 y = height;\n\n           /* NOTE: this skips asking libpng to return either version of\n            * the image row, but libpng still reads the rows.\n            */\n           while (y-- > 0)\n              png_read_row(png_ptr, NULL, NULL);\n        }\n      }\n\n      if (control->file.global->verbose)\n         fprintf(stderr, \" END\\n\");\n\n      /* Make sure to read to the end of the file: */\n      png_read_end(png_ptr, info_ptr);\n   }\n\n   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n   return rc;\n}\n\nstatic int\none_file(struct global *global, const char *file_name, const char *out_name)\n{\n   int rc;\n   struct control control;\n\n   if (global->verbose)\n      fprintf(stderr, \"FILE %s -> %s\\n\", file_name,\n         out_name ? out_name : \"<none>\");\n\n   /* Although control_init can return a failure code the structure is always\n    * initialized, so control_end can be used to accumulate any status codes.\n    */\n   rc = control_init(&control, global, file_name, out_name);\n\n   if (rc == 0)\n      rc = read_png(&control);\n\n   rc |= control_end(&control);\n\n   return rc;\n}\n\nstatic void\nusage(const char *prog)\n{\n   /* ANSI C-90 limits strings to 509 characters, so use a string array: */\n   size_t i;\n   static const char *usage_string[] = {\n\"  Tests, optimizes and optionally fixes the zlib header in PNG files.\",\n\"  Optionally, when fixing, strips ancilliary chunks from the file.\",\n0,\n\"OPTIONS\",\n\"  OPERATION\",\n\"      By default files are just checked for readability with a summary of the\",\n\"      of zlib issues founds for each compressed chunk and the IDAT stream in\",\n\"      the file.\",\n\"    --optimize (-o):\",\n\"      Find the smallest deflate window size for the compressed data.\",\n\"    --strip=[none|crc|unsafe|unused|transform|color|all]:\",\n\"        none (default):   Retain all chunks.\",\n\"        crc:    Remove chunks with a bad CRC.\",\n\"        unsafe: Remove chunks that may be unsafe to retain if the image data\",\n\"                is modified.  This is set automatically if --max is given but\",\n\"                may be cancelled by a later --strip=none.\",\n\"        unused: Remove chunks not used by libpng when decoding an image.\",\n\"                This retains any chunks that might be used by libpng image\",\n\"                transformations.\",\n\"        transform: unused+bKGD.\",\n\"        color:  transform+iCCP and cHRM.\",\n\"        all:    color+gAMA and sRGB.\",\n\"      Only ancillary chunks are ever removed.  In addition the tRNS and sBIT\",\n\"      chunks are never removed as they affect exact interpretation of the\",\n\"      image pixel values.  The following known chunks are treated specially\",\n\"      by the above options:\",\n\"        gAMA, sRGB [all]: These specify the gamma encoding used for the pixel\",\n\"            values.\",\n\"        cHRM, iCCP [color]: These specify how colors are encoded.  iCCP also\",\n\"            specifies the exact encoding of a pixel value; however, in\",\n\"            practice most programs will ignore it.\",\n\"        bKGD [transform]: This is used by libpng transforms.\"\n\"    --max=<number>:\",\n\"      Use IDAT chunks sized <number>.  If no number is given the the IDAT\",\n\"      chunks will be the maximum size permitted; 2^31-1 bytes.  If the option\",\n\"      is omitted the original chunk sizes will not be changed.  When the\",\n\"      option is given --strip=unsafe is set automatically. This may be\",\n\"      cancelled if you know that all unknown unsafe-to-copy chunks really are\",\n\"      safe to copy across an IDAT size change.  This is true of all chunks\",\n\"      that have ever been formally proposed as PNG extensions.\",\n\"  MESSAGES\",\n\"      By default the program only outputs summaries for each file.\",\n\"    --quiet (-q):\",\n\"      Do not output the summaries except for files that cannot be read. With\",\n\"      two --quiets these are not output either.\",\n\"    --errors (-e):\",\n\"      Output errors from libpng and the program (except too-far-back).\",\n\"    --warnings (-w):\",\n\"      Output warnings from libpng.\",\n\"  OUTPUT\",\n\"      By default nothing is written.\",\n\"    --out=<file>:\",\n\"      Write the optimized/corrected version of the next PNG to <file>.  This\",\n\"      overrides the following two options\",\n\"    --suffix=<suffix>:\",\n\"      Set --out=<name><suffix> for all following files unless overridden on\",\n\"      a per-file basis by explicit --out.\",\n\"    --prefix=<prefix>:\",\n\"      Set --out=<prefix><name> for all the following files unless overridden\",\n\"      on a per-file basis by explicit --out.\",\n\"      These two options can be used together to produce a suffix and prefix.\",\n\"  INTERNAL OPTIONS\",\n#if 0 /*NYI*/\n#ifdef PNG_MAXIMUM_INFLATE_WINDOW\n\"    --test:\",\n\"      Test the PNG_MAXIMUM_INFLATE_WINDOW option.  Setting this disables\",\n\"      output as this would produce a broken file.\",\n#endif\n#endif\n0,\n\"EXIT CODES\",\n\"  *** SUBJECT TO CHANGE ***\",\n\"  The program exit code is value in the range 0..127 holding a bit mask of\",\n\"  the following codes.  Notice that the results for each file are combined\",\n\"  together - check one file at a time to get a meaningful error code!\",\n\"    0x01: The zlib too-far-back error existed in at least one chunk.\",\n\"    0x02: At least one chunk had a CRC error.\",\n\"    0x04: A chunk length was incorrect.\",\n\"    0x08: The file was truncated.\",\n\"  Errors less than 16 are potentially recoverable, for a single file if the\",\n\"  exit code is less than 16 the file could be read (with corrections if a\",\n\"  non-zero code is returned).\",\n\"    0x10: The file could not be read, even with corrections.\",\n\"    0x20: The output file could not be written.\",\n\"    0x40: An unexpected, potentially internal, error occurred.\",\n\"  If the command line arguments are incorrect the program exits with exit\",\n\"  255.  Some older operating systems only support 7-bit exit codes, on those\",\n\"  systems it is suggested that this program is first tested by supplying\",\n\"  invalid arguments.\",\n0,\n\"DESCRIPTION\",\n\"  \" PROGRAM_NAME \":\",\n\"  checks each PNG file on the command line for errors.  By default errors are\",\n\"  not output and the program just returns an exit code and prints a summary.\",\n\"  With the --quiet (-q) option the summaries are suppressed too and the\",\n\"  program only outputs unexpected errors (internal errors and file open\",\n\"  errors).\",\n\"  Various known problems in PNG files are fixed while the file is being read\",\n\"  The exit code says what problems were fixed.  In particular the zlib error:\",\n0,\n\"        \\\"invalid distance too far back\\\"\",\n0,\n\"  caused by an incorrect optimization of a zlib stream is fixed in any\",\n\"  compressed chunk in which it is encountered.  An integrity problem of the\",\n\"  PNG stream caused by a bug in libpng which wrote an incorrect chunk length\",\n\"  is also fixed.  Chunk CRC errors are automatically fixed up.\",\n0,\n\"  Setting one of the \\\"OUTPUT\\\" options causes the possibly modified file to\",\n\"  be written to a new file.\",\n0,\n\"  Notice that some PNG files with the zlib optimization problem can still be\",\n\"  read by libpng under some circumstances.  This program will still detect\",\n\"  and, if requested, correct the error.\",\n0,\n\"  The program will reliably process all files on the command line unless\",\n\"  either an invalid argument causes the usage message (this message) to be\",\n\"  produced or the program crashes.\",\n0,\n\"  The summary lines describe issues encountered with the zlib compressed\",\n\"  stream of a chunk.  They have the following format, which is SUBJECT TO\",\n\"  CHANGE in the future:\",\n0,\n\"     chunk reason comp-level p1 p2 p3 p4 file\",\n0,\n\"  p1 through p4 vary according to the 'reason'.  There are always 8 space\",\n\"  separated fields.  Reasons specific formats are:\",\n0,\n\"     chunk ERR status code read-errno write-errno message file\",\n\"     chunk SKP comp-level file-bits zlib-rc compressed message file\",\n\"     chunk ??? comp-level file-bits ok-bits compressed uncompress file\",\n0,\n\"  The various fields are\",\n0,\n\"$1 chunk:      The chunk type of a chunk in the file or 'HEAD' if a problem\",\n\"               is reported by libpng at the start of the IDAT stream.\",\n\"$2 reason:     One of:\",\n\"          CHK: A zlib header checksum was detected and fixed.\",\n\"          TFB: The zlib too far back error was detected and fixed.\",\n\"          OK : No errors were detected in the zlib stream and optimization\",\n\"               was not requested, or was not possible.\",\n\"          OPT: The zlib stream window bits value could be improved (and was).\",\n\"          SKP: The chunk was skipped because of a zlib issue (zlib-rc) with\",\n\"               explanation 'message'\",\n\"          ERR: The read of the file was aborted.  The parameters explain why.\",\n\"$3 status:     For 'ERR' the accumulated status code from 'EXIT CODES' above.\",\n\"               This is printed as a 2 digit hexadecimal value\",\n\"   comp-level: The recorded compression level (FLEVEL) of a zlib stream\",\n\"               expressed as a string {supfast,stdfast,default,maximum}\",\n\"$4 code:       The file exit code; where stop was called, as a fairly terse\",\n\"               string {warning,libpng,zlib,invalid,read,write,unexpected}.\",\n\"   file-bits:  The zlib window bits recorded in the file.\",\n\"$5 read-errno: A system errno value from a read translated by strerror(3).\",\n\"   zlib-rc:    A zlib return code as a string (see zlib.h).\",\n\"   ok-bits:    The smallest zlib window bits value that works.\",\n\"$6 write-errno:A system errno value from a write translated by strerror(3).\",\n\"   compressed: The count of compressed bytes in the zlib stream, when the\",\n\"               reason is 'SKP'; this is a count of the bytes read from the\",\n\"               stream when the fatal error was encountered.\",\n\"$7 message:    An error message (spaces replaced by _, as in all parameters),\",\n\"   uncompress: The count of bytes from uncompressing the zlib stream; this\",\n\"               may not be the same as the number of bytes in the image.\",\n\"$8 file:       The name of the file (this may contain spaces).\",\n};\n\n   fprintf(stderr, \"Usage: %s {[options] png-file}\\n\", prog);\n\n   for (i=0; i < (sizeof usage_string)/(sizeof usage_string[0]); ++i)\n   {\n      if (usage_string[i] != 0)\n         fputs(usage_string[i], stderr);\n\n      fputc('\\n', stderr);\n   }\n\n   exit(255);\n}\n\nint\nmain(int argc, const char **argv)\n{\n   char temp_name[FILENAME_MAX+1];\n   const char *  prog = *argv;\n   const char *  outfile = NULL;\n   const char *  suffix = NULL;\n   const char *  prefix = NULL;\n   int           done = 0; /* if at least one file is processed */\n   struct global global;\n\n   global_init(&global);\n\n   while (--argc > 0)\n   {\n      ++argv;\n\n      if (strcmp(*argv, \"--debug\") == 0)\n      {\n         /* To help debugging problems: */\n         global.errors = global.warnings = 1;\n         global.quiet = 0;\n         global.verbose = 7;\n      }\n\n      else if (strncmp(*argv, \"--max=\", 6) == 0)\n      {\n         global.idat_max = (png_uint_32)atol(6+*argv);\n\n         if (global.skip < SKIP_UNSAFE)\n            global.skip = SKIP_UNSAFE;\n      }\n\n      else if (strcmp(*argv, \"--max\") == 0)\n      {\n         global.idat_max = 0x7fffffff;\n\n         if (global.skip < SKIP_UNSAFE)\n            global.skip = SKIP_UNSAFE;\n      }\n\n      else if (strcmp(*argv, \"--optimize\") == 0 || strcmp(*argv, \"-o\") == 0)\n         global.optimize_zlib = 1;\n\n      else if (strncmp(*argv, \"--out=\", 6) == 0)\n         outfile = 6+*argv;\n\n      else if (strncmp(*argv, \"--suffix=\", 9) == 0)\n         suffix = 9+*argv;\n\n      else if (strncmp(*argv, \"--prefix=\", 9) == 0)\n         prefix = 9+*argv;\n\n      else if (strcmp(*argv, \"--strip=none\") == 0)\n         global.skip = SKIP_NONE;\n\n      else if (strcmp(*argv, \"--strip=crc\") == 0)\n         global.skip = SKIP_BAD_CRC;\n\n      else if (strcmp(*argv, \"--strip=unsafe\") == 0)\n         global.skip = SKIP_UNSAFE;\n\n      else if (strcmp(*argv, \"--strip=unused\") == 0)\n         global.skip = SKIP_UNUSED;\n\n      else if (strcmp(*argv, \"--strip=transform\") == 0)\n         global.skip = SKIP_TRANSFORM;\n\n      else if (strcmp(*argv, \"--strip=color\") == 0)\n         global.skip = SKIP_COLOR;\n\n      else if (strcmp(*argv, \"--strip=all\") == 0)\n         global.skip = SKIP_ALL;\n\n      else if (strcmp(*argv, \"--errors\") == 0 || strcmp(*argv, \"-e\") == 0)\n         global.errors = 1;\n\n      else if (strcmp(*argv, \"--warnings\") == 0 || strcmp(*argv, \"-w\") == 0)\n         global.warnings = 1;\n\n      else if (strcmp(*argv, \"--quiet\") == 0 || strcmp(*argv, \"-q\") == 0)\n      {\n         if (global.quiet)\n            global.quiet = 2;\n\n         else\n            global.quiet = 1;\n      }\n\n      else if (strcmp(*argv, \"--verbose\") == 0 || strcmp(*argv, \"-v\") == 0)\n         ++global.verbose;\n\n#if 0\n      /* NYI */\n#     ifdef PNG_MAXIMUM_INFLATE_WINDOW\n         else if (strcmp(*argv, \"--test\") == 0)\n            ++set_option;\n#     endif\n#endif\n\n      else if ((*argv)[0] == '-')\n         usage(prog);\n\n      else\n      {\n         size_t outlen = strlen(*argv);\n\n         if (outfile == NULL) /* else this takes precedence */\n         {\n            /* Consider the prefix/suffix options */\n            if (prefix != NULL)\n            {\n               size_t prefixlen = strlen(prefix);\n\n               if (prefixlen+outlen > FILENAME_MAX)\n               {\n                  fprintf(stderr, \"%s: output file name too long: %s%s%s\\n\",\n                     prog, prefix, *argv, suffix ? suffix : \"\");\n                  global.status_code |= WRITE_ERROR;\n                  continue;\n               }\n\n               memcpy(temp_name, prefix, prefixlen);\n               memcpy(temp_name+prefixlen, *argv, outlen);\n               outlen += prefixlen;\n               outfile = temp_name;\n            }\n\n            else if (suffix != NULL)\n               memcpy(temp_name, *argv, outlen);\n\n            temp_name[outlen] = 0;\n\n            if (suffix != NULL)\n            {\n               size_t suffixlen = strlen(suffix);\n\n               if (outlen+suffixlen > FILENAME_MAX)\n               {\n                  fprintf(stderr, \"%s: output file name too long: %s%s\\n\",\n                     prog, *argv, suffix);\n                  global.status_code |= WRITE_ERROR;\n                  continue;\n               }\n\n               memcpy(temp_name+outlen, suffix, suffixlen);\n               outlen += suffixlen;\n               temp_name[outlen] = 0;\n               outfile = temp_name;\n            }\n         }\n\n         (void)one_file(&global, *argv, outfile);\n         ++done;\n         outfile = NULL;\n      }\n   }\n\n   if (!done)\n      usage(prog);\n\n   return global_end(&global);\n}\n\n#else /* ZLIB_VERNUM < 0x1240 */\nint\nmain(void)\n{\n   fprintf(stderr,\n      \"pngfix needs libpng with a zlib >=1.2.4 (not 0x%x)\\n\",\n      ZLIB_VERNUM);\n   return 77;\n}\n#endif /* ZLIB_VERNUM */\n\n#else /* No read support */\n\nint\nmain(void)\n{\n   fprintf(stderr, \"pngfix does not work without read deinterlace support\\n\");\n   return 77;\n}\n#endif /* PNG_READ_SUPPORTED && PNG_EASY_ACCESS_SUPPORTED */\n#else /* No setjmp support */\nint\nmain(void)\n{\n   fprintf(stderr, \"pngfix does not work without setjmp support\\n\");\n   return 77;\n}\n#endif /* PNG_SETJMP_SUPPORTED */\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/reindent",
    "content": "#!/bin/sh\n\n# reindent a libpng C source\n\n# COPYRIGHT: Written by Glenn Randers-Pehrson, 2016.\n# To the extent possible under law, the author has waived all copyright and\n# related or neighboring rights to this work.  This work is published from:\n# United States.\n\n# Usage:\n# reindent inputtabsize outputtabsize inputcontinuestring outputcontinuestring\n#\n# Assumes that continued lines begin with indentation plus one space, and\n# that continued comments begin with indentation plus \" *\".\n#\n# eg, to change libpng coding style from 3-space indentation with 4-space\n# continuations to 4-space indentation with 2-space continuations:\n#\n#  reindent 3 4 \"\\t \" \"  \" < example.c > example.c_4_2\n# and to restore the file back to libpng coding style\n#  reindent 4 3 \"  \" \"    \" < example.c_4_2 > example.c_3_4\n\nunexpand --first-only --t $1 | \\\n   sed -e \"/^\t*$3[^\\*]/{s/$3/$4/}\" | \\\n   expand -t $2\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/tools/sRGB.h",
    "content": "/*-\n * sRGB.h\n *\n * Last changed in libpng 1.6.0 [February 14, 2013]\n *\n * COPYRIGHT: Written by John Cunningham Bowler, 2013.\n * To the extent possible under law, the author has waived all copyright and\n * related or neighboring rights to this work.  This work is published from:\n * United States.\n *\n * Utility file; not actually a header, this contains definitions of sRGB\n * calculation functions for inclusion in those test programs that need them.\n *\n * All routines take and return a floating point value in the range\n * 0 to 1.0, doing a calculation according to the sRGB specification\n * (in fact the source of the numbers is the wikipedia article at\n * http://en.wikipedia.org/wiki/SRGB).\n */\nstatic double\nsRGB_from_linear(double l)\n{\n   if (l <= 0.0031308)\n      l *= 12.92;\n\n   else\n      l = 1.055 * pow(l, 1/2.4) - 0.055;\n\n   return l;\n}\n\nstatic double\nlinear_from_sRGB(double s)\n{\n   if (s <= 0.04045)\n      return s / 12.92;\n\n   else\n      return pow((s+0.055)/1.055, 2.4);\n}\n\nstatic double\nYfromRGB(double r, double g, double b)\n{\n   /* Use the sRGB (rounded) coefficients for Rlinear, Glinear, Blinear to get\n    * the CIE Y value (also linear).\n    */\n   return 0.2126 * r + 0.7152 * g + 0.0722 * b;\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/PngFile.c",
    "content": "/*-------------------------------------\n *  PNGFILE.C -- Image File Functions\n *-------------------------------------\n *\n * Copyright 2000, Willem van Schaik.\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include <windows.h>\n#include <commdlg.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <zlib.h>\n\n#include \"png.h\"\n#include \"pngfile.h\"\n#include \"cexcept.h\"\n\ndefine_exception_type(const char *);\nextern struct exception_context the_exception_context[1];\nstruct exception_context the_exception_context[1];\npng_const_charp msg;\n\nstatic OPENFILENAME ofn;\n\nstatic png_structp png_ptr = NULL;\nstatic png_infop info_ptr = NULL;\n\n\n/* cexcept interface */\n\nstatic void\npng_cexcept_error(png_structp png_ptr, png_const_charp msg)\n{\n   if(png_ptr)\n     ;\n#ifdef PNG_CONSOLE_IO_SUPPORTED\n   fprintf(stderr, \"libpng error: %s\\n\", msg);\n#endif\n   {\n      Throw msg;\n   }\n}\n\n/* Windows open-file functions */\n\nvoid PngFileInitialize (HWND hwnd)\n{\n    static TCHAR szFilter[] = TEXT (\"PNG Files (*.PNG)\\0*.png\\0\")\n        TEXT (\"All Files (*.*)\\0*.*\\0\\0\");\n\n    ofn.lStructSize       = sizeof (OPENFILENAME);\n    ofn.hwndOwner         = hwnd;\n    ofn.hInstance         = NULL;\n    ofn.lpstrFilter       = szFilter;\n    ofn.lpstrCustomFilter = NULL;\n    ofn.nMaxCustFilter    = 0;\n    ofn.nFilterIndex      = 0;\n    ofn.lpstrFile         = NULL;          /* Set in Open and Close functions */\n    ofn.nMaxFile          = MAX_PATH;\n    ofn.lpstrFileTitle    = NULL;          /* Set in Open and Close functions */\n    ofn.nMaxFileTitle     = MAX_PATH;\n    ofn.lpstrInitialDir   = NULL;\n    ofn.lpstrTitle        = NULL;\n    ofn.Flags             = 0;             /* Set in Open and Close functions */\n    ofn.nFileOffset       = 0;\n    ofn.nFileExtension    = 0;\n    ofn.lpstrDefExt       = TEXT (\"png\");\n    ofn.lCustData         = 0;\n    ofn.lpfnHook          = NULL;\n    ofn.lpTemplateName    = NULL;\n}\n\nBOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)\n{\n    ofn.hwndOwner         = hwnd;\n    ofn.lpstrFile         = pstrFileName;\n    ofn.lpstrFileTitle    = pstrTitleName;\n    ofn.Flags             = OFN_HIDEREADONLY;\n\n    return GetOpenFileName (&ofn);\n}\n\nBOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName)\n{\n    ofn.hwndOwner         = hwnd;\n    ofn.lpstrFile         = pstrFileName;\n    ofn.lpstrFileTitle    = pstrTitleName;\n    ofn.Flags             = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;\n\n    return GetSaveFileName (&ofn);\n}\n\n/* PNG image handler functions */\n\nBOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,\n                   int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor)\n{\n    static FILE        *pfFile;\n    png_byte            pbSig[8];\n    int                 iBitDepth;\n    int                 iColorType;\n    double              dGamma;\n    png_color_16       *pBackground;\n    png_uint_32         ulChannels;\n    png_uint_32         ulRowBytes;\n    png_byte           *pbImageData = *ppbImageData;\n    static png_byte   **ppbRowPointers = NULL;\n    int                 i;\n\n    /* open the PNG input file */\n\n    if (!pstrFileName)\n    {\n        *ppbImageData = pbImageData = NULL;\n        return FALSE;\n    }\n\n    if (!(pfFile = fopen(pstrFileName, \"rb\")))\n    {\n        *ppbImageData = pbImageData = NULL;\n        return FALSE;\n    }\n\n    /* first check the eight byte PNG signature */\n\n    fread(pbSig, 1, 8, pfFile);\n    if (png_sig_cmp(pbSig, 0, 8))\n    {\n        *ppbImageData = pbImageData = NULL;\n        return FALSE;\n    }\n\n    /* create the two png(-info) structures */\n\n    png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL,\n      (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);\n    if (!png_ptr)\n    {\n        *ppbImageData = pbImageData = NULL;\n        return FALSE;\n    }\n\n    info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr)\n    {\n        png_destroy_read_struct(&png_ptr, NULL, NULL);\n        *ppbImageData = pbImageData = NULL;\n        return FALSE;\n    }\n\n    Try\n    {\n\n        /* initialize the png structure */\n\n#ifdef PNG_STDIO_SUPPORTED\n        png_init_io(png_ptr, pfFile);\n#else\n        png_set_read_fn(png_ptr, (png_voidp)pfFile, png_read_data);\n#endif\n\n        png_set_sig_bytes(png_ptr, 8);\n\n        /* read all PNG info up to image data */\n\n        png_read_info(png_ptr, info_ptr);\n\n        /* get width, height, bit-depth and color-type */\n\n        png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,\n            &iColorType, NULL, NULL, NULL);\n\n        /* expand images of all color-type and bit-depth to 3x8-bit RGB */\n        /* let the library process alpha, transparency, background, etc. */\n\n#ifdef PNG_READ_16_TO_8_SUPPORTED\n    if (iBitDepth == 16)\n#  ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n        png_set_scale_16(png_ptr);\n#  else\n        png_set_strip_16(png_ptr);\n#  endif\n#endif\n        if (iColorType == PNG_COLOR_TYPE_PALETTE)\n            png_set_expand(png_ptr);\n        if (iBitDepth < 8)\n            png_set_expand(png_ptr);\n        if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))\n            png_set_expand(png_ptr);\n        if (iColorType == PNG_COLOR_TYPE_GRAY ||\n            iColorType == PNG_COLOR_TYPE_GRAY_ALPHA)\n            png_set_gray_to_rgb(png_ptr);\n\n        /* set the background color to draw transparent and alpha images over */\n        if (png_get_bKGD(png_ptr, info_ptr, &pBackground))\n        {\n            png_set_background(png_ptr, pBackground, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);\n            pBkgColor->red   = (byte) pBackground->red;\n            pBkgColor->green = (byte) pBackground->green;\n            pBkgColor->blue  = (byte) pBackground->blue;\n        }\n        else\n        {\n            pBkgColor = NULL;\n        }\n\n        /* if required set gamma conversion */\n        if (png_get_gAMA(png_ptr, info_ptr, &dGamma))\n            png_set_gamma(png_ptr, (double) 2.2, dGamma);\n\n        /* after the transformations are registered, update info_ptr data */\n\n        png_read_update_info(png_ptr, info_ptr);\n\n        /* get again width, height and the new bit-depth and color-type */\n\n        png_get_IHDR(png_ptr, info_ptr, piWidth, piHeight, &iBitDepth,\n            &iColorType, NULL, NULL, NULL);\n\n\n        /* row_bytes is the width x number of channels */\n\n        ulRowBytes = png_get_rowbytes(png_ptr, info_ptr);\n        ulChannels = png_get_channels(png_ptr, info_ptr);\n\n        *piChannels = ulChannels;\n\n        /* now we can allocate memory to store the image */\n\n        if (pbImageData)\n        {\n            free (pbImageData);\n            pbImageData = NULL;\n        }\n        if ((pbImageData = (png_byte *) malloc(ulRowBytes * (*piHeight)\n                            * sizeof(png_byte))) == NULL)\n        {\n            png_error(png_ptr, \"Visual PNG: out of memory\");\n        }\n        *ppbImageData = pbImageData;\n\n        /* and allocate memory for an array of row-pointers */\n\n        if ((ppbRowPointers = (png_bytepp) malloc((*piHeight)\n                            * sizeof(png_bytep))) == NULL)\n        {\n            png_error(png_ptr, \"Visual PNG: out of memory\");\n        }\n\n        /* set the individual row-pointers to point at the correct offsets */\n\n        for (i = 0; i < (*piHeight); i++)\n            ppbRowPointers[i] = pbImageData + i * ulRowBytes;\n\n        /* now we can go ahead and just read the whole image */\n\n        png_read_image(png_ptr, ppbRowPointers);\n\n        /* read the additional chunks in the PNG file (not really needed) */\n\n        png_read_end(png_ptr, NULL);\n\n        /* and we're done */\n\n        free (ppbRowPointers);\n        ppbRowPointers = NULL;\n\n        /* yepp, done */\n    }\n\n    Catch (msg)\n    {\n        png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n\n        *ppbImageData = pbImageData = NULL;\n\n        if(ppbRowPointers)\n            free (ppbRowPointers);\n\n        fclose(pfFile);\n\n        return FALSE;\n    }\n\n    fclose (pfFile);\n\n    return TRUE;\n}\n\n\nBOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,\n                   int iWidth, int iHeight, png_color bkgColor)\n{\n    const int           ciBitDepth = 8;\n    const int           ciChannels = 3;\n\n    static FILE        *pfFile;\n    png_uint_32         ulRowBytes;\n    static png_byte   **ppbRowPointers = NULL;\n    int                 i;\n\n    /* open the PNG output file */\n\n    if (!pstrFileName)\n        return FALSE;\n\n    if (!(pfFile = fopen(pstrFileName, \"wb\")))\n        return FALSE;\n\n    /* prepare the standard PNG structures */\n\n    png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL,\n      (png_error_ptr)png_cexcept_error, (png_error_ptr)NULL);\n    if (!png_ptr)\n    {\n        fclose(pfFile);\n        return FALSE;\n    }\n\n    info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr) {\n        fclose(pfFile);\n        png_destroy_write_struct(&png_ptr, (png_infopp) NULL);\n        return FALSE;\n    }\n\n    Try\n    {\n        /* initialize the png structure */\n\n#ifdef PNG_STDIO_SUPPORTED\n        png_init_io(png_ptr, pfFile);\n#else\n        png_set_write_fn(png_ptr, (png_voidp)pfFile, png_write_data, png_flush);\n#endif\n\n        /* we're going to write a very simple 3x8-bit RGB image */\n\n        png_set_IHDR(png_ptr, info_ptr, iWidth, iHeight, ciBitDepth,\n            PNG_COLOR_TYPE_RGB, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,\n            PNG_FILTER_TYPE_BASE);\n\n        /* write the file header information */\n\n        png_write_info(png_ptr, info_ptr);\n\n        /* swap the BGR pixels in the DiData structure to RGB */\n\n        png_set_bgr(png_ptr);\n\n        /* row_bytes is the width x number of channels */\n\n        ulRowBytes = iWidth * ciChannels;\n\n        /* we can allocate memory for an array of row-pointers */\n\n        if ((ppbRowPointers = (png_bytepp) malloc(iHeight * sizeof(png_bytep))) == NULL)\n            Throw \"Visualpng: Out of memory\";\n\n        /* set the individual row-pointers to point at the correct offsets */\n\n        for (i = 0; i < iHeight; i++)\n            ppbRowPointers[i] = pDiData + i * (((ulRowBytes + 3) >> 2) << 2);\n\n        /* write out the entire image data in one call */\n\n        png_write_image (png_ptr, ppbRowPointers);\n\n        /* write the additional chunks to the PNG file (not really needed) */\n\n        png_write_end(png_ptr, info_ptr);\n\n        /* and we're done */\n\n        free (ppbRowPointers);\n        ppbRowPointers = NULL;\n\n        /* clean up after the write, and free any memory allocated */\n\n        png_destroy_write_struct(&png_ptr, (png_infopp) NULL);\n\n        /* yepp, done */\n    }\n\n    Catch (msg)\n    {\n        png_destroy_write_struct(&png_ptr, (png_infopp) NULL);\n\n        if(ppbRowPointers)\n            free (ppbRowPointers);\n\n        fclose(pfFile);\n\n        return FALSE;\n    }\n\n    fclose (pfFile);\n\n    return TRUE;\n}\n\n#ifndef PNG_STDIO_SUPPORTED\n\nstatic void\npng_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_size_t check;\n\n   /* fread() returns 0 on error, so it is OK to store this in a png_size_t\n    * instead of an int, which is what fread() actually returns.\n    */\n   check = (png_size_t)fread(data, (png_size_t)1, length,\n      (FILE *)png_ptr->io_ptr);\n\n   if (check != length)\n   {\n      png_error(png_ptr, \"Read Error\");\n   }\n}\n\nstatic void\npng_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_uint_32 check;\n\n   check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));\n   if (check != length)\n   {\n      png_error(png_ptr, \"Write Error\");\n   }\n}\n\nstatic void\npng_flush(png_structp png_ptr)\n{\n   FILE *io_ptr;\n   io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));\n   if (io_ptr != NULL)\n      fflush(io_ptr);\n}\n\n#endif\n\n/*-----------------\n *  end of source\n *-----------------\n */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/PngFile.h",
    "content": "/*------------------------------------------*/\n/*  PNGFILE.H -- Header File for pngfile.c*/\n/*------------------------------------------*/\n\n/* Copyright 2000, Willem van Schaik.*/\n\n/* This code is released under the libpng license.*/\n/* For conditions of distribution and use, see the disclaimer*/\n/* and license in png.h*/\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <windows.h>\n\nvoid PngFileInitialize (HWND hwnd) ;\nBOOL PngFileOpenDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;\nBOOL PngFileSaveDlg (HWND hwnd, PTSTR pstrFileName, PTSTR pstrTitleName) ;\n\nBOOL PngLoadImage (PTSTR pstrFileName, png_byte **ppbImageData,\n                   int *piWidth, int *piHeight, int *piChannels, png_color *pBkgColor);\nBOOL PngSaveImage (PTSTR pstrFileName, png_byte *pDiData,\n                   int iWidth, int iHeight, png_color BkgColor);\n\n#ifndef PNG_STDIO_SUPPORTED\nstatic void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length);\nstatic void png_write_data(png_structp png_ptr, png_bytep data, png_size_t length);\nstatic void png_flush(png_structp png_ptr);\n#endif\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/README.txt",
    "content": "Microsoft Developer Studio Build File, Format Version 6.00 for VisualPng\n------------------------------------------------------------------------\n\nCopyright 2000, Willem van Schaik.\n\nThis code is released under the libpng license.\nFor conditions of distribution and use, see the disclaimer\nand license in png.h\n\nAs a PNG .dll demo VisualPng is finished. More features would only hinder\nthe program's objective. However, further extensions (like support for other\ngraphics formats) are in development. To get these, or for pre-compiled\nbinaries, go to \"http://www.schaik.com/png/visualpng.html\".\n\n------------------------------------------------------------------------\n\nAssumes that\n\n   libpng DLLs and LIBs are in ..\\..\\projects\\msvc\\win32\\libpng\n   zlib DLLs and LIBs are in   ..\\..\\projects\\msvc\\win32\\zlib\n   libpng header files are in  ..\\..\\..\\libpng\n   zlib header files are in    ..\\..\\..\\zlib\n   the pngsuite images are in  ..\\pngsuite\n\nTo build:\n\n1) On the main menu Select \"Build|Set Active configuration\".\n   Choose the configuration that corresponds to the library you want to test.\n   This library must have been built using the libpng MS project located in\n   the \"..\\..\\mscv\" subdirectory.\n\n2) Select \"Build|Clean\"\n\n3) Select \"Build|Rebuild All\"\n\n4) After compiling and linking VisualPng will be started to view an image\n   from the PngSuite directory.  Press Ctrl-N (and Ctrl-V) for other images.\n\n\nTo install:\n\nWhen distributing VisualPng (or a further development) the following options\nare available:\n\n1) Build the program with the configuration \"Win32 LIB\" and you only need to\n   include the executable from the ./lib directory in your distribution.\n\n2) Build the program with the configuration \"Win32 DLL\" and you need to put\n   in your distribution the executable from the ./dll directory and the dll's\n   libpng1.dll, zlib.dll and msvcrt.dll.  These need to be in the user's PATH.\n\n\nWillem van Schaik\nCalgary, June 6th 2000\n\nP.S. VisualPng was written based on preliminary work of:\n\n    - Simon-Pierre Cadieux\n    - Glenn Randers-Pehrson\n    - Greg Roelofs\n\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/VisualPng.c",
    "content": "/*------------------------------------\n *  VisualPng.C -- Shows a PNG image\n *------------------------------------\n *\n * Copyright 2000, Willem van Schaik.\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* switches */\n\n/* defines */\n\n#define PROGNAME  \"VisualPng\"\n#define LONGNAME  \"Win32 Viewer for PNG-files\"\n#define VERSION   \"1.0 of 2000 June 07\"\n\n/* constants */\n\n#define MARGIN 8\n\n/* standard includes */\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <windows.h>\n#include <zlib.h>\n\n/* application includes */\n\n#include \"png.h\"\n#include \"pngfile.h\"\n#include \"resource.h\"\n\n/* macros */\n\n/* function prototypes */\n\nLRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);\nBOOL    CALLBACK AboutDlgProc (HWND, UINT, WPARAM, LPARAM) ;\n\nBOOL CenterAbout (HWND hwndChild, HWND hwndParent);\n\nBOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,\n        int *pFileIndex);\n\nBOOL SearchPngList (TCHAR *pFileList, int FileCount, int *pFileIndex,\n        PTSTR pstrPrevName, PTSTR pstrNextName);\n\nBOOL LoadImageFile(HWND hwnd, PTSTR pstrPathName,\n        png_byte **ppbImage, int *pxImgSize, int *pyImgSize, int *piChannels,\n        png_color *pBkgColor);\n\nBOOL DisplayImage (HWND hwnd, BYTE **ppDib,\n        BYTE **ppDiData, int cxWinSize, int cyWinSize,\n        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,\n        BOOL bStretched);\n\nBOOL InitBitmap (\n        BYTE *pDiData, int cxWinSize, int cyWinSize);\n\nBOOL FillBitmap (\n        BYTE *pDiData, int cxWinSize, int cyWinSize,\n        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,\n        BOOL bStretched);\n\n/* a few global variables */\n\nstatic char *szProgName = PROGNAME;\nstatic char *szAppName = LONGNAME;\nstatic char *szIconName = PROGNAME;\nstatic char szCmdFileName [MAX_PATH];\n\n/* MAIN routine */\n\nint WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,\n                    PSTR szCmdLine, int iCmdShow)\n{\n    HACCEL   hAccel;\n    HWND     hwnd;\n    MSG      msg;\n    WNDCLASS wndclass;\n    int ixBorders, iyBorders;\n\n    wndclass.style         = CS_HREDRAW | CS_VREDRAW;\n    wndclass.lpfnWndProc   = WndProc;\n    wndclass.cbClsExtra    = 0;\n    wndclass.cbWndExtra    = 0;\n    wndclass.hInstance     = hInstance;\n    wndclass.hIcon         = LoadIcon (hInstance, szIconName) ;\n    wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);\n    wndclass.hbrBackground = NULL; /* (HBRUSH) GetStockObject (GRAY_BRUSH); */\n    wndclass.lpszMenuName  = szProgName;\n    wndclass.lpszClassName = szProgName;\n\n    if (!RegisterClass (&wndclass))\n    {\n        MessageBox (NULL, TEXT (\"Error: this program requires Windows NT!\"),\n            szProgName, MB_ICONERROR);\n        return 0;\n    }\n\n    /* if filename given on commandline, store it */\n    if ((szCmdLine != NULL) && (*szCmdLine != '\\0'))\n        if (szCmdLine[0] == '\"')\n            strncpy (szCmdFileName, szCmdLine + 1, strlen(szCmdLine) - 2);\n        else\n            strcpy (szCmdFileName, szCmdLine);\n    else\n        strcpy (szCmdFileName, \"\");\n\n    /* calculate size of window-borders */\n    ixBorders = 2 * (GetSystemMetrics (SM_CXBORDER) +\n                     GetSystemMetrics (SM_CXDLGFRAME));\n    iyBorders = 2 * (GetSystemMetrics (SM_CYBORDER) +\n                     GetSystemMetrics (SM_CYDLGFRAME)) +\n                     GetSystemMetrics (SM_CYCAPTION) +\n                     GetSystemMetrics (SM_CYMENUSIZE) +\n                     1; /* WvS: don't ask me why?  */\n\n    hwnd = CreateWindow (szProgName, szAppName,\n        WS_OVERLAPPEDWINDOW,\n        CW_USEDEFAULT, CW_USEDEFAULT,\n        512 + 2 * MARGIN + ixBorders, 384 + 2 * MARGIN + iyBorders,\n/*      CW_USEDEFAULT, CW_USEDEFAULT, */\n        NULL, NULL, hInstance, NULL);\n\n    ShowWindow (hwnd, iCmdShow);\n    UpdateWindow (hwnd);\n\n    hAccel = LoadAccelerators (hInstance, szProgName);\n\n    while (GetMessage (&msg, NULL, 0, 0))\n    {\n        if (!TranslateAccelerator (hwnd, hAccel, &msg))\n        {\n            TranslateMessage (&msg);\n            DispatchMessage (&msg);\n        }\n    }\n    return msg.wParam;\n}\n\nLRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam,\n        LPARAM lParam)\n{\n    static HINSTANCE          hInstance ;\n    static HDC                hdc;\n    static PAINTSTRUCT        ps;\n    static HMENU              hMenu;\n\n    static BITMAPFILEHEADER  *pbmfh;\n    static BITMAPINFOHEADER  *pbmih;\n    static BYTE              *pbImage;\n    static int                cxWinSize, cyWinSize;\n    static int                cxImgSize, cyImgSize;\n    static int                cImgChannels;\n    static png_color          bkgColor = {127, 127, 127};\n\n    static BOOL               bStretched = TRUE;\n\n    static BYTE              *pDib = NULL;\n    static BYTE              *pDiData = NULL;\n\n    static TCHAR              szImgPathName [MAX_PATH];\n    static TCHAR              szTitleName [MAX_PATH];\n\n    static TCHAR             *pPngFileList = NULL;\n    static int                iPngFileCount;\n    static int                iPngFileIndex;\n\n    BOOL                      bOk;\n\n    switch (message)\n    {\n    case WM_CREATE:\n        hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;\n        PngFileInitialize (hwnd);\n\n        strcpy (szImgPathName, \"\");\n\n        /* in case we process file given on command-line */\n\n        if (szCmdFileName[0] != '\\0')\n        {\n            strcpy (szImgPathName, szCmdFileName);\n\n            /* read the other png-files in the directory for later */\n            /* next/previous commands */\n\n            BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,\n                          &iPngFileIndex);\n\n            /* load the image from file */\n\n            if (!LoadImageFile (hwnd, szImgPathName,\n                &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))\n                return 0;\n\n            /* invalidate the client area for later update */\n\n            InvalidateRect (hwnd, NULL, TRUE);\n\n            /* display the PNG into the DIBitmap */\n\n            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n        }\n\n        return 0;\n\n    case WM_SIZE:\n        cxWinSize = LOWORD (lParam);\n        cyWinSize = HIWORD (lParam);\n\n        /* invalidate the client area for later update */\n\n        InvalidateRect (hwnd, NULL, TRUE);\n\n        /* display the PNG into the DIBitmap */\n\n        DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n            pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n\n        return 0;\n\n    case WM_INITMENUPOPUP:\n        hMenu = GetMenu (hwnd);\n\n        if (pbImage)\n            EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_ENABLED);\n        else\n            EnableMenuItem (hMenu, IDM_FILE_SAVE, MF_GRAYED);\n\n        return 0;\n\n    case WM_COMMAND:\n        hMenu = GetMenu (hwnd);\n\n        switch (LOWORD (wParam))\n        {\n        case IDM_FILE_OPEN:\n\n            /* show the File Open dialog box */\n\n            if (!PngFileOpenDlg (hwnd, szImgPathName, szTitleName))\n                return 0;\n\n            /* read the other png-files in the directory for later */\n            /* next/previous commands */\n\n            BuildPngList (szImgPathName, &pPngFileList, &iPngFileCount,\n                          &iPngFileIndex);\n\n            /* load the image from file */\n\n            if (!LoadImageFile (hwnd, szImgPathName,\n                &pbImage, &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))\n                return 0;\n\n            /* invalidate the client area for later update */\n\n            InvalidateRect (hwnd, NULL, TRUE);\n\n            /* display the PNG into the DIBitmap */\n\n            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n\n            return 0;\n\n        case IDM_FILE_SAVE:\n\n            /* show the File Save dialog box */\n\n            if (!PngFileSaveDlg (hwnd, szImgPathName, szTitleName))\n                return 0;\n\n            /* save the PNG to a disk file */\n\n            SetCursor (LoadCursor (NULL, IDC_WAIT));\n            ShowCursor (TRUE);\n\n            bOk = PngSaveImage (szImgPathName, pDiData, cxWinSize, cyWinSize,\n                  bkgColor);\n\n            ShowCursor (FALSE);\n            SetCursor (LoadCursor (NULL, IDC_ARROW));\n\n            if (!bOk)\n                MessageBox (hwnd, TEXT (\"Error in saving the PNG image\"),\n                szProgName, MB_ICONEXCLAMATION | MB_OK);\n            return 0;\n\n        case IDM_FILE_NEXT:\n\n            /* read next entry in the directory */\n\n            if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,\n                NULL, szImgPathName))\n            {\n                if (strcmp (szImgPathName, \"\") == 0)\n                    return 0;\n\n                /* load the image from file */\n\n                if (!LoadImageFile (hwnd, szImgPathName, &pbImage,\n                        &cxImgSize, &cyImgSize, &cImgChannels, &bkgColor))\n                    return 0;\n\n                /* invalidate the client area for later update */\n\n                InvalidateRect (hwnd, NULL, TRUE);\n\n                /* display the PNG into the DIBitmap */\n\n                DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n                    pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n            }\n\n            return 0;\n\n        case IDM_FILE_PREVIOUS:\n\n            /* read previous entry in the directory */\n\n            if (SearchPngList (pPngFileList, iPngFileCount, &iPngFileIndex,\n                szImgPathName, NULL))\n            {\n\n                if (strcmp (szImgPathName, \"\") == 0)\n                    return 0;\n\n                /* load the image from file */\n\n                if (!LoadImageFile (hwnd, szImgPathName, &pbImage, &cxImgSize,\n                    &cyImgSize, &cImgChannels, &bkgColor))\n                    return 0;\n\n                /* invalidate the client area for later update */\n\n                InvalidateRect (hwnd, NULL, TRUE);\n\n                /* display the PNG into the DIBitmap */\n\n                DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n                    pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n            }\n\n            return 0;\n\n        case IDM_FILE_EXIT:\n\n            /* more cleanup needed... */\n\n            /* free image buffer */\n\n            if (pDib != NULL)\n            {\n                free (pDib);\n                pDib = NULL;\n            }\n\n            /* free file-list */\n\n            if (pPngFileList != NULL)\n            {\n                free (pPngFileList);\n                pPngFileList = NULL;\n            }\n\n            /* let's go ... */\n\n            exit (0);\n\n            return 0;\n\n        case IDM_OPTIONS_STRETCH:\n            bStretched = !bStretched;\n            if (bStretched)\n                CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_CHECKED);\n            else\n                CheckMenuItem (hMenu, IDM_OPTIONS_STRETCH, MF_UNCHECKED);\n\n            /* invalidate the client area for later update */\n\n            InvalidateRect (hwnd, NULL, TRUE);\n\n            /* display the PNG into the DIBitmap */\n\n            DisplayImage (hwnd, &pDib, &pDiData, cxWinSize, cyWinSize,\n                pbImage, cxImgSize, cyImgSize, cImgChannels, bStretched);\n\n            return 0;\n\n        case IDM_HELP_ABOUT:\n            DialogBox (hInstance, TEXT (\"AboutBox\"), hwnd, AboutDlgProc) ;\n            return 0;\n\n        } /* end switch */\n\n        break;\n\n    case WM_PAINT:\n        hdc = BeginPaint (hwnd, &ps);\n\n        if (pDib)\n            SetDIBitsToDevice (hdc, 0, 0, cxWinSize, cyWinSize, 0, 0,\n                0, cyWinSize, pDiData, (BITMAPINFO *) pDib, DIB_RGB_COLORS);\n\n        EndPaint (hwnd, &ps);\n        return 0;\n\n    case WM_DESTROY:\n        if (pbmfh)\n        {\n            free (pbmfh);\n            pbmfh = NULL;\n        }\n\n        PostQuitMessage (0);\n        return 0;\n    }\n\n    return DefWindowProc (hwnd, message, wParam, lParam);\n}\n\nBOOL CALLBACK AboutDlgProc (HWND hDlg, UINT message,\n                            WPARAM wParam, LPARAM lParam)\n{\n     switch (message)\n     {\n     case WM_INITDIALOG :\n          ShowWindow (hDlg, SW_HIDE);\n          CenterAbout (hDlg, GetWindow (hDlg, GW_OWNER));\n          ShowWindow (hDlg, SW_SHOW);\n          return TRUE ;\n\n     case WM_COMMAND :\n          switch (LOWORD (wParam))\n          {\n          case IDOK :\n          case IDCANCEL :\n               EndDialog (hDlg, 0) ;\n               return TRUE ;\n          }\n          break ;\n     }\n     return FALSE ;\n}\n\n/*---------------\n *  CenterAbout\n *---------------\n */\nBOOL CenterAbout (HWND hwndChild, HWND hwndParent)\n{\n   RECT    rChild, rParent, rWorkArea;\n   int     wChild, hChild, wParent, hParent;\n   int     xNew, yNew;\n   BOOL  bResult;\n\n   /* Get the Height and Width of the child window */\n   GetWindowRect (hwndChild, &rChild);\n   wChild = rChild.right - rChild.left;\n   hChild = rChild.bottom - rChild.top;\n\n   /* Get the Height and Width of the parent window */\n   GetWindowRect (hwndParent, &rParent);\n   wParent = rParent.right - rParent.left;\n   hParent = rParent.bottom - rParent.top;\n\n   /* Get the limits of the 'workarea' */\n   bResult = SystemParametersInfo(\n      SPI_GETWORKAREA,  /* system parameter to query or set */\n      sizeof(RECT),\n      &rWorkArea,\n      0);\n   if (!bResult) {\n      rWorkArea.left = rWorkArea.top = 0;\n      rWorkArea.right = GetSystemMetrics(SM_CXSCREEN);\n      rWorkArea.bottom = GetSystemMetrics(SM_CYSCREEN);\n   }\n\n   /* Calculate new X position, then adjust for workarea */\n   xNew = rParent.left + ((wParent - wChild) /2);\n   if (xNew < rWorkArea.left) {\n      xNew = rWorkArea.left;\n   } else if ((xNew+wChild) > rWorkArea.right) {\n      xNew = rWorkArea.right - wChild;\n   }\n\n   /* Calculate new Y position, then adjust for workarea */\n   yNew = rParent.top  + ((hParent - hChild) /2);\n   if (yNew < rWorkArea.top) {\n      yNew = rWorkArea.top;\n   } else if ((yNew+hChild) > rWorkArea.bottom) {\n      yNew = rWorkArea.bottom - hChild;\n   }\n\n   /* Set it, and return */\n   return SetWindowPos (hwndChild, NULL, xNew, yNew, 0, 0, SWP_NOSIZE |\n          SWP_NOZORDER);\n}\n\n/*----------------\n *  BuildPngList\n *----------------\n */\nBOOL BuildPngList (PTSTR pstrPathName, TCHAR **ppFileList, int *pFileCount,\n     int *pFileIndex)\n{\n    static TCHAR              szImgPathName [MAX_PATH];\n    static TCHAR              szImgFileName [MAX_PATH];\n    static TCHAR              szImgFindName [MAX_PATH];\n\n    WIN32_FIND_DATA           finddata;\n    HANDLE                    hFind;\n\n    static TCHAR              szTmp [MAX_PATH];\n    BOOL                      bOk;\n    int                       i, ii;\n    int                       j, jj;\n\n    /* free previous file-list */\n\n    if (*ppFileList != NULL)\n    {\n        free (*ppFileList);\n        *ppFileList = NULL;\n    }\n\n    /* extract foldername, filename and search-name */\n\n    strcpy (szImgPathName, pstrPathName);\n    strcpy (szImgFileName, strrchr (pstrPathName, '\\\\') + 1);\n\n    strcpy (szImgFindName, szImgPathName);\n    *(strrchr (szImgFindName, '\\\\') + 1) = '\\0';\n    strcat (szImgFindName, \"*.png\");\n\n    /* first cycle: count number of files in directory for memory allocation */\n\n    *pFileCount = 0;\n\n    hFind = FindFirstFile(szImgFindName, &finddata);\n    bOk = (hFind != (HANDLE) -1);\n\n    while (bOk)\n    {\n        *pFileCount += 1;\n        bOk = FindNextFile(hFind, &finddata);\n    }\n    FindClose(hFind);\n\n    /* allocation memory for file-list */\n\n    *ppFileList = (TCHAR *) malloc (*pFileCount * MAX_PATH);\n\n    /* second cycle: read directory and store filenames in file-list */\n\n    hFind = FindFirstFile(szImgFindName, &finddata);\n    bOk = (hFind != (HANDLE) -1);\n\n    i = 0;\n    ii = 0;\n    while (bOk)\n    {\n        strcpy (*ppFileList + ii, szImgPathName);\n        strcpy (strrchr(*ppFileList + ii, '\\\\') + 1, finddata.cFileName);\n\n        if (strcmp(pstrPathName, *ppFileList + ii) == 0)\n            *pFileIndex = i;\n\n        ii += MAX_PATH;\n        i++;\n\n        bOk = FindNextFile(hFind, &finddata);\n    }\n    FindClose(hFind);\n\n    /* finally we must sort the file-list */\n\n    for (i = 0; i < *pFileCount - 1; i++)\n    {\n        ii = i * MAX_PATH;\n        for (j = i+1; j < *pFileCount; j++)\n        {\n            jj = j * MAX_PATH;\n            if (strcmp (*ppFileList + ii, *ppFileList + jj) > 0)\n            {\n                strcpy (szTmp, *ppFileList + jj);\n                strcpy (*ppFileList + jj, *ppFileList + ii);\n                strcpy (*ppFileList + ii, szTmp);\n\n                /* check if this was the current image that we moved */\n\n                if (*pFileIndex == i)\n                    *pFileIndex = j;\n                else\n                    if (*pFileIndex == j)\n                        *pFileIndex = i;\n            }\n        }\n    }\n\n    return TRUE;\n}\n\n/*----------------\n *  SearchPngList\n *----------------\n */\n\nBOOL SearchPngList (\n        TCHAR *pFileList, int FileCount, int *pFileIndex,\n        PTSTR pstrPrevName, PTSTR pstrNextName)\n{\n    if (FileCount > 0)\n    {\n        /* get previous entry */\n\n        if (pstrPrevName != NULL)\n        {\n            if (*pFileIndex > 0)\n                *pFileIndex -= 1;\n            else\n                *pFileIndex = FileCount - 1;\n\n            strcpy (pstrPrevName, pFileList + (*pFileIndex * MAX_PATH));\n        }\n\n        /* get next entry */\n\n        if (pstrNextName != NULL)\n        {\n            if (*pFileIndex < FileCount - 1)\n                *pFileIndex += 1;\n            else\n                *pFileIndex = 0;\n\n            strcpy (pstrNextName, pFileList + (*pFileIndex * MAX_PATH));\n        }\n\n        return TRUE;\n    }\n    else\n    {\n        return FALSE;\n    }\n}\n\n/*-----------------\n *  LoadImageFile\n *-----------------\n */\n\nBOOL LoadImageFile (HWND hwnd, PTSTR pstrPathName,\n                png_byte **ppbImage, int *pxImgSize, int *pyImgSize,\n                int *piChannels, png_color *pBkgColor)\n{\n    static TCHAR szTmp [MAX_PATH];\n\n    /* if there's an existing PNG, free the memory */\n\n    if (*ppbImage)\n    {\n        free (*ppbImage);\n        *ppbImage = NULL;\n    }\n\n    /* Load the entire PNG into memory */\n\n    SetCursor (LoadCursor (NULL, IDC_WAIT));\n    ShowCursor (TRUE);\n\n    PngLoadImage (pstrPathName, ppbImage, pxImgSize, pyImgSize, piChannels,\n                  pBkgColor);\n\n    ShowCursor (FALSE);\n    SetCursor (LoadCursor (NULL, IDC_ARROW));\n\n    if (*ppbImage != NULL)\n    {\n        sprintf (szTmp, \"VisualPng - %s\", strrchr(pstrPathName, '\\\\') + 1);\n        SetWindowText (hwnd, szTmp);\n    }\n    else\n    {\n        MessageBox (hwnd, TEXT (\"Error in loading the PNG image\"),\n            szProgName, MB_ICONEXCLAMATION | MB_OK);\n        return FALSE;\n    }\n\n    return TRUE;\n}\n\n/*----------------\n *  DisplayImage\n *----------------\n */\nBOOL DisplayImage (HWND hwnd, BYTE **ppDib,\n        BYTE **ppDiData, int cxWinSize, int cyWinSize,\n        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,\n        BOOL bStretched)\n{\n    BYTE                       *pDib = *ppDib;\n    BYTE                       *pDiData = *ppDiData;\n    /* BITMAPFILEHEADER        *pbmfh; */\n    BITMAPINFOHEADER           *pbmih;\n    WORD                        wDIRowBytes;\n    png_color                   bkgBlack = {0, 0, 0};\n    png_color                   bkgGray  = {127, 127, 127};\n    png_color                   bkgWhite = {255, 255, 255};\n\n    /* allocate memory for the Device Independant bitmap */\n\n    wDIRowBytes = (WORD) ((3 * cxWinSize + 3L) >> 2) << 2;\n\n    if (pDib)\n    {\n        free (pDib);\n        pDib = NULL;\n    }\n\n    if (!(pDib = (BYTE *) malloc (sizeof(BITMAPINFOHEADER) +\n        wDIRowBytes * cyWinSize)))\n    {\n        MessageBox (hwnd, TEXT (\"Error in displaying the PNG image\"),\n            szProgName, MB_ICONEXCLAMATION | MB_OK);\n        *ppDib = pDib = NULL;\n        return FALSE;\n    }\n    *ppDib = pDib;\n    memset (pDib, 0, sizeof(BITMAPINFOHEADER));\n\n    /* initialize the dib-structure */\n\n    pbmih = (BITMAPINFOHEADER *) pDib;\n    pbmih->biSize = sizeof(BITMAPINFOHEADER);\n    pbmih->biWidth = cxWinSize;\n    pbmih->biHeight = -((long) cyWinSize);\n    pbmih->biPlanes = 1;\n    pbmih->biBitCount = 24;\n    pbmih->biCompression = 0;\n    pDiData = pDib + sizeof(BITMAPINFOHEADER);\n    *ppDiData = pDiData;\n\n    /* first fill bitmap with gray and image border */\n\n    InitBitmap (pDiData, cxWinSize, cyWinSize);\n\n    /* then fill bitmap with image */\n\n    if (pbImage)\n    {\n        FillBitmap (\n            pDiData, cxWinSize, cyWinSize,\n            pbImage, cxImgSize, cyImgSize, cImgChannels,\n            bStretched);\n    }\n\n    return TRUE;\n}\n\n/*--------------\n *  InitBitmap\n *--------------\n */\nBOOL InitBitmap (BYTE *pDiData, int cxWinSize, int cyWinSize)\n{\n    BYTE *dst;\n    int x, y, col;\n\n    /* initialize the background with gray */\n\n    dst = pDiData;\n    for (y = 0; y < cyWinSize; y++)\n    {\n        col = 0;\n        for (x = 0; x < cxWinSize; x++)\n        {\n            /* fill with GRAY */\n            *dst++ = 127;\n            *dst++ = 127;\n            *dst++ = 127;\n            col += 3;\n        }\n        /* rows start on 4 byte boundaries */\n        while ((col % 4) != 0)\n        {\n            dst++;\n            col++;\n        }\n    }\n\n    return TRUE;\n}\n\n/*--------------\n *  FillBitmap\n *--------------\n */\nBOOL FillBitmap (\n        BYTE *pDiData, int cxWinSize, int cyWinSize,\n        BYTE *pbImage, int cxImgSize, int cyImgSize, int cImgChannels,\n        BOOL bStretched)\n{\n    BYTE *pStretchedImage;\n    BYTE *pImg;\n    BYTE *src, *dst;\n    BYTE r, g, b, a;\n    const int cDIChannels = 3;\n    WORD wImgRowBytes;\n    WORD wDIRowBytes;\n    int cxNewSize, cyNewSize;\n    int cxImgPos, cyImgPos;\n    int xImg, yImg;\n    int xWin, yWin;\n    int xOld, yOld;\n    int xNew, yNew;\n\n    if (bStretched)\n    {\n        cxNewSize = cxWinSize - 2 * MARGIN;\n        cyNewSize = cyWinSize - 2 * MARGIN;\n\n        /* stretch the image to it's window determined size */\n\n        /* the following two are mathematically the same, but the first\n         * has side-effects because of rounding\n         */\n/*      if ((cyNewSize / cxNewSize) > (cyImgSize / cxImgSize)) */\n        if ((cyNewSize * cxImgSize) > (cyImgSize * cxNewSize))\n        {\n            cyNewSize = cxNewSize * cyImgSize / cxImgSize;\n            cxImgPos = MARGIN;\n            cyImgPos = (cyWinSize - cyNewSize) / 2;\n        }\n        else\n        {\n            cxNewSize = cyNewSize * cxImgSize / cyImgSize;\n            cyImgPos = MARGIN;\n            cxImgPos = (cxWinSize - cxNewSize) / 2;\n        }\n\n        pStretchedImage = malloc (cImgChannels * cxNewSize * cyNewSize);\n        pImg = pStretchedImage;\n\n        for (yNew = 0; yNew < cyNewSize; yNew++)\n        {\n            yOld = yNew * cyImgSize / cyNewSize;\n            for (xNew = 0; xNew < cxNewSize; xNew++)\n            {\n                xOld = xNew * cxImgSize / cxNewSize;\n\n                r = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 0);\n                g = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 1);\n                b = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld) + 2);\n                *pImg++ = r;\n                *pImg++ = g;\n                *pImg++ = b;\n                if (cImgChannels == 4)\n                {\n                    a = *(pbImage + cImgChannels * ((yOld * cxImgSize) + xOld)\n                        + 3);\n                    *pImg++ = a;\n                }\n            }\n        }\n\n        /* calculate row-bytes */\n\n        wImgRowBytes = cImgChannels * cxNewSize;\n        wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;\n\n        /* copy image to screen */\n\n        for (yImg = 0, yWin = cyImgPos; yImg < cyNewSize; yImg++, yWin++)\n        {\n            if (yWin >= cyWinSize - cyImgPos)\n                break;\n            src = pStretchedImage + yImg * wImgRowBytes;\n            dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;\n\n            for (xImg = 0, xWin = cxImgPos; xImg < cxNewSize; xImg++, xWin++)\n            {\n                if (xWin >= cxWinSize - cxImgPos)\n                    break;\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                *dst++ = b; /* note the reverse order  */\n                *dst++ = g;\n                *dst++ = r;\n                if (cImgChannels == 4)\n                {\n                    a = *src++;\n                }\n            }\n        }\n\n        /* free memory */\n\n        if (pStretchedImage != NULL)\n        {\n            free (pStretchedImage);\n            pStretchedImage = NULL;\n        }\n\n    }\n\n    /* process the image not-stretched */\n\n    else\n    {\n        /* calculate the central position */\n\n        cxImgPos = (cxWinSize - cxImgSize) / 2;\n        cyImgPos = (cyWinSize - cyImgSize) / 2;\n\n        /* check for image larger than window */\n\n        if (cxImgPos < MARGIN)\n            cxImgPos = MARGIN;\n        if (cyImgPos < MARGIN)\n            cyImgPos = MARGIN;\n\n        /* calculate both row-bytes */\n\n        wImgRowBytes = cImgChannels * cxImgSize;\n        wDIRowBytes = (WORD) ((cDIChannels * cxWinSize + 3L) >> 2) << 2;\n\n        /* copy image to screen */\n\n        for (yImg = 0, yWin = cyImgPos; yImg < cyImgSize; yImg++, yWin++)\n        {\n            if (yWin >= cyWinSize - MARGIN)\n                break;\n            src = pbImage + yImg * wImgRowBytes;\n            dst = pDiData + yWin * wDIRowBytes + cxImgPos * cDIChannels;\n\n            for (xImg = 0, xWin = cxImgPos; xImg < cxImgSize; xImg++, xWin++)\n            {\n                if (xWin >= cxWinSize - MARGIN)\n                    break;\n                r = *src++;\n                g = *src++;\n                b = *src++;\n                *dst++ = b; /* note the reverse order  */\n                *dst++ = g;\n                *dst++ = r;\n                if (cImgChannels == 4)\n                {\n                    a = *src++;\n                }\n            }\n        }\n    }\n\n    return TRUE;\n}\n\n/*-----------------\n *  end of source\n *-----------------\n */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/VisualPng.dsp",
    "content": "# Microsoft Developer Studio Project File - Name=\"VisualPng\" - Package Owner=<4>\r\n# Microsoft Developer Studio Generated Build File, Format Version 6.00\r\n# ** DO NOT EDIT **\r\n\r\n# TARGTYPE \"Win32 (x86) Application\" 0x0101\r\n\r\nCFG=VisualPng - Win32 Debug\r\n!MESSAGE This is not a valid makefile. To build this project using NMAKE,\r\n!MESSAGE use the Export Makefile command and run\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"VisualPng.mak\".\r\n!MESSAGE \r\n!MESSAGE You can specify a configuration when running NMAKE\r\n!MESSAGE by defining the macro CFG on the command line. For example:\r\n!MESSAGE \r\n!MESSAGE NMAKE /f \"VisualPng.mak\" CFG=\"VisualPng - Win32 Debug\"\r\n!MESSAGE \r\n!MESSAGE Possible choices for configuration are:\r\n!MESSAGE \r\n!MESSAGE \"VisualPng - Win32 Release\" (based on \"Win32 (x86) Application\")\r\n!MESSAGE \"VisualPng - Win32 Debug\" (based on \"Win32 (x86) Application\")\r\n!MESSAGE \r\n\r\n# Begin Project\r\n# PROP AllowPerConfigDependencies 0\r\n# PROP Scc_ProjName \"\"\r\n# PROP Scc_LocalPath \"\"\r\nCPP=cl.exe\r\nMTL=midl.exe\r\nRSC=rc.exe\r\n\r\n!IF  \"$(CFG)\" == \"VisualPng - Win32 Release\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 0\r\n# PROP BASE Output_Dir \"Release\"\r\n# PROP BASE Intermediate_Dir \"Release\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 0\r\n# PROP Output_Dir \"Release\"\r\n# PROP Intermediate_Dir \"Release\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /O2 /I \"..\\..\" /I \"..\\..\\..\\zlib\" /D \"WIN32\" /D \"NDEBUG\" /D \"PNG_NO_STDIO\" /FD /c\r\n# SUBTRACT BASE CPP /YX\r\n# ADD CPP /nologo /MD /W3 /O2 /I \"..\\..\" /I \"..\\..\\..\\zlib\" /D \"WIN32\" /D \"NDEBUG\" /D \"PNG_NO_STDIO\" /FD /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"NDEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x409 /d \"NDEBUG\"\r\n# ADD RSC /l 0x409 /d \"NDEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386\r\n# ADD LINK32 ..\\..\\projects\\visualc6\\Win32_LIB_Release\\libpng.lib ..\\..\\..\\zlib\\projects\\visualc6\\Win32_LIB_Release\\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /machine:I386\r\n# Begin Special Build Tool\r\nOutDir=.\\Release\r\nSOURCE=\"$(InputPath)\"\r\nPostBuild_Cmds=$(outdir)\\VisualPng.exe ..\\..\\contrib\\pngsuite\\basn6a16.png\r\n# End Special Build Tool\r\n\r\n!ELSEIF  \"$(CFG)\" == \"VisualPng - Win32 Debug\"\r\n\r\n# PROP BASE Use_MFC 0\r\n# PROP BASE Use_Debug_Libraries 1\r\n# PROP BASE Output_Dir \"Debug\"\r\n# PROP BASE Intermediate_Dir \"Debug\"\r\n# PROP BASE Ignore_Export_Lib 0\r\n# PROP BASE Target_Dir \"\"\r\n# PROP Use_MFC 0\r\n# PROP Use_Debug_Libraries 1\r\n# PROP Output_Dir \"Debug\"\r\n# PROP Intermediate_Dir \"Debug\"\r\n# PROP Ignore_Export_Lib 0\r\n# PROP Target_Dir \"\"\r\n# ADD BASE CPP /nologo /W3 /Gm /ZI /Od /I \"..\\..\" /I \"..\\..\\..\\zlib\" /D \"WIN32\" /D \"_DEBUG\" /D \"PNG_NO_STDIO\" /FD /GZ /c\r\n# SUBTRACT BASE CPP /YX\r\n# ADD CPP /nologo /MDd /W3 /Gm /ZI /Od /I \"..\\..\" /I \"..\\..\\..\\zlib\" /D \"WIN32\" /D \"_DEBUG\" /D \"PNG_NO_STDIO\" /FD /GZ /c\r\n# SUBTRACT CPP /YX\r\n# ADD BASE MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD MTL /nologo /D \"_DEBUG\" /mktyplib203 /win32\r\n# ADD BASE RSC /l 0x409 /d \"_DEBUG\"\r\n# ADD RSC /l 0x409 /d \"_DEBUG\"\r\nBSC32=bscmake.exe\r\n# ADD BASE BSC32 /nologo\r\n# ADD BSC32 /nologo\r\nLINK32=link.exe\r\n# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /pdbtype:sept\r\n# ADD LINK32 ..\\..\\projects\\visualc6\\Win32_LIB_Release\\libpng.lib ..\\..\\..\\zlib\\projects\\visualc6\\Win32_LIB_Release\\zlib.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:windows /debug /machine:I386 /nodefaultlib:\"msvcrt.lib\" /pdbtype:sept\r\n# Begin Special Build Tool\r\nOutDir=.\\Debug\r\nSOURCE=\"$(InputPath)\"\r\nPostBuild_Cmds=$(outdir)\\VisualPng.exe ..\\..\\contrib\\pngsuite\\basn6a16.png\r\n# End Special Build Tool\r\n\r\n!ENDIF \r\n\r\n# Begin Target\r\n\r\n# Name \"VisualPng - Win32 Release\"\r\n# Name \"VisualPng - Win32 Debug\"\r\n# Begin Group \"Source Files\"\r\n\r\n# PROP Default_Filter \"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\PngFile.c\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\VisualPng.c\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Header Files\"\r\n\r\n# PROP Default_Filter \"h;hpp;hxx;hm;inl\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\cexcept.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\PngFile.h\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\resource.h\r\n# End Source File\r\n# End Group\r\n# Begin Group \"Resource Files\"\r\n\r\n# PROP Default_Filter \"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\"\r\n# Begin Source File\r\n\r\nSOURCE=.\\VisualPng.ico\r\n# End Source File\r\n# Begin Source File\r\n\r\nSOURCE=.\\VisualPng.rc\r\n# End Source File\r\n# End Group\r\n# End Target\r\n# End Project\r\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/VisualPng.dsw",
    "content": "Microsoft Developer Studio Workspace File, Format Version 6.00\r\n# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!\r\n\r\n###############################################################################\r\n\r\nProject: \"VisualPng\"=.\\VisualPng.dsp - Package Owner=<4>\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<4>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\nGlobal:\r\n\r\nPackage=<5>\r\n{{{\r\n}}}\r\n\r\nPackage=<3>\r\n{{{\r\n}}}\r\n\r\n###############################################################################\r\n\r\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/VisualPng.rc",
    "content": "//Microsoft Developer Studio generated resource script.\r\n//\r\n#include \"resource.h\"\r\n\r\n#define APSTUDIO_READONLY_SYMBOLS\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Generated from the TEXTINCLUDE 2 resource.\r\n//\r\n#include \"afxres.h\"\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n#undef APSTUDIO_READONLY_SYMBOLS\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n// English (U.S.) resources\r\n\r\n#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r\n#ifdef _WIN32\r\nLANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US\r\n#pragma code_page(1252)\r\n#endif //_WIN32\r\n\r\n#ifdef APSTUDIO_INVOKED\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// TEXTINCLUDE\r\n//\r\n\r\n1 TEXTINCLUDE DISCARDABLE \r\nBEGIN\r\n    \"resource.h\\0\"\r\nEND\r\n\r\n2 TEXTINCLUDE DISCARDABLE \r\nBEGIN\r\n    \"#include \"\"afxres.h\"\"\\r\\n\"\r\n    \"\\0\"\r\nEND\r\n\r\n3 TEXTINCLUDE DISCARDABLE \r\nBEGIN\r\n    \"\\r\\n\"\r\n    \"\\0\"\r\nEND\r\n\r\n#endif    // APSTUDIO_INVOKED\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Menu\r\n//\r\n\r\nVISUALPNG MENU DISCARDABLE \r\nBEGIN\r\n    POPUP \"&File\"\r\n    BEGIN\r\n        MENUITEM \"&Open Image...\\tCtrl+O\",      IDM_FILE_OPEN\r\n        MENUITEM \"Save &As...\",                 IDM_FILE_SAVE\r\n        MENUITEM SEPARATOR\r\n        MENUITEM \"&Next Image\\tCtrl+N\",         IDM_FILE_NEXT\r\n        MENUITEM \"Pre&vious Image\\tCtrl+V\",     IDM_FILE_PREVIOUS\r\n        MENUITEM SEPARATOR\r\n        MENUITEM \"E&xit\\tAlt+X\",                IDM_FILE_EXIT\r\n    END\r\n    POPUP \"&Options\"\r\n    BEGIN\r\n        MENUITEM \"&Stretch\",                    IDM_OPTIONS_STRETCH, CHECKED\r\n    END\r\n    POPUP \"&Help\"\r\n    BEGIN\r\n        MENUITEM \"&About\",                      IDM_HELP_ABOUT\r\n    END\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Accelerator\r\n//\r\n\r\nVISUALPNG ACCELERATORS DISCARDABLE \r\nBEGIN\r\n    \"N\",            IDM_FILE_NEXT,          VIRTKEY, CONTROL, NOINVERT\r\n    \"O\",            IDM_FILE_OPEN,          VIRTKEY, CONTROL, NOINVERT\r\n    \"P\",            IDM_FILE_PREVIOUS,      VIRTKEY, CONTROL, NOINVERT\r\n    \"V\",            IDM_FILE_PREVIOUS,      VIRTKEY, CONTROL, NOINVERT\r\n    \"X\",            IDM_FILE_EXIT,          VIRTKEY, ALT, NOINVERT\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Icon\r\n//\r\n\r\n// Icon with lowest ID value placed first to ensure application icon\r\n// remains consistent on all systems.\r\nVISUALPNG               ICON    DISCARDABLE     \"VisualPng.ico\"\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Dialog\r\n//\r\n\r\nABOUTBOX DIALOG DISCARDABLE  0, 0, 186, 94\r\nSTYLE DS_MODALFRAME | WS_POPUP\r\nFONT 8, \"MS Sans Serif\"\r\nBEGIN\r\n    DEFPUSHBUTTON   \"OK\",IDOK,68,67,50,14\r\n    CTEXT           \"VisualPng 1.0  -  June 2000\",IDC_STATIC,49,14,88,8\r\n    LTEXT           \"a PNG image viewer\",IDC_STATIC,60,30,66,8\r\n    LTEXT           \"(c) Willem van Schaik, 2000\",IDC_STATIC,48,52,90,8\r\n    LTEXT           \"to demonstrate the use of libpng in Visual C\",\r\n                    IDC_STATIC,25,38,136,8\r\nEND\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// DESIGNINFO\r\n//\r\n\r\n#ifdef APSTUDIO_INVOKED\r\nGUIDELINES DESIGNINFO DISCARDABLE \r\nBEGIN\r\n    \"ABOUTBOX\", DIALOG\r\n    BEGIN\r\n        LEFTMARGIN, 7\r\n        RIGHTMARGIN, 179\r\n        TOPMARGIN, 7\r\n        BOTTOMMARGIN, 87\r\n    END\r\nEND\r\n#endif    // APSTUDIO_INVOKED\r\n\r\n#endif    // English (U.S.) resources\r\n/////////////////////////////////////////////////////////////////////////////\r\n\r\n\r\n\r\n#ifndef APSTUDIO_INVOKED\r\n/////////////////////////////////////////////////////////////////////////////\r\n//\r\n// Generated from the TEXTINCLUDE 3 resource.\r\n//\r\n\r\n\r\n/////////////////////////////////////////////////////////////////////////////\r\n#endif    // not APSTUDIO_INVOKED\r\n\r\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/cexcept.h",
    "content": "/*===\ncexcept.h 2.0.1 (2008-Jul-19-Sat)\nhttp://www.nicemice.net/cexcept/\nAdam M. Costello\nhttp://www.nicemice.net/amc/\n\nAn interface for exception-handling in ANSI C (C89 and subsequent ISO\nstandards), developed jointly with Cosmin Truta.\n\n    Copyright (c) 2000-2008 Adam M. Costello and Cosmin Truta.\n    This software may be modified only if its author and version\n    information is updated accurately, and may be redistributed\n    only if accompanied by this unaltered notice.  Subject to those\n    restrictions, permission is granted to anyone to do anything\n    with this software.  The copyright holders make no guarantees\n    regarding this software, and are not responsible for any damage\n    resulting from its use.\n\nThe cexcept interface is not compatible with and cannot interact\nwith system exceptions (like division by zero or memory segmentation\nviolation), compiler-generated exceptions (like C++ exceptions), or\nother exception-handling interfaces.\n\nWhen using this interface across multiple .c files, do not include\nthis header file directly.  Instead, create a wrapper header file that\nincludes this header file and then invokes the define_exception_type\nmacro (see below).  The .c files should then include that header file.\n\nThe interface consists of one type, one well-known name, and six macros.\n\n\ndefine_exception_type(type_name);\n\n    This macro is used like an external declaration.  It specifies\n    the type of object that gets copied from the exception thrower to\n    the exception catcher.  The type_name can be any type that can be\n    assigned to, that is, a non-constant arithmetic type, struct, union,\n    or pointer.  Examples:\n\n        define_exception_type(int);\n\n        enum exception { out_of_memory, bad_arguments, disk_full };\n        define_exception_type(enum exception);\n\n        struct exception { int code; const char *msg; };\n        define_exception_type(struct exception);\n\n    Because throwing an exception causes the object to be copied (not\n    just once, but twice), programmers may wish to consider size when\n    choosing the exception type.\n\n\nstruct exception_context;\n\n    This type may be used after the define_exception_type() macro has\n    been invoked.  A struct exception_context must be known to both\n    the thrower and the catcher.  It is expected that there be one\n    context for each thread that uses exceptions.  It would certainly\n    be dangerous for multiple threads to access the same context.\n    One thread can use multiple contexts, but that is likely to be\n    confusing and not typically useful.  The application can allocate\n    this structure in any way it pleases--automatic, static, or dynamic.\n    The application programmer should pretend not to know the structure\n    members, which are subject to change.\n\n\nstruct exception_context *the_exception_context;\n\n    The Try/Catch and Throw statements (described below) implicitly\n    refer to a context, using the name the_exception_context.  It is\n    the application's responsibility to make sure that this name yields\n    the address of a mutable (non-constant) struct exception_context\n    wherever those statements are used.  Subject to that constraint, the\n    application may declare a variable of this name anywhere it likes\n    (inside a function, in a parameter list, or externally), and may\n    use whatever storage class specifiers (static, extern, etc) or type\n    qualifiers (const, volatile, etc) it likes.  Examples:\n\n        static struct exception_context\n          * const the_exception_context = &foo;\n\n        { struct exception_context *the_exception_context = bar; ... }\n\n        int blah(struct exception_context *the_exception_context, ...);\n\n        extern struct exception_context the_exception_context[1];\n\n    The last example illustrates a trick that avoids creating a pointer\n    object separate from the structure object.\n\n    The name could even be a macro, for example:\n\n        struct exception_context ec_array[numthreads];\n        #define the_exception_context (ec_array + thread_id)\n\n    Be aware that the_exception_context is used several times by the\n    Try/Catch/Throw macros, so it shouldn't be expensive or have side\n    effects.  The expansion must be a drop-in replacement for an\n    identifier, so it's safest to put parentheses around it.\n\n\nvoid init_exception_context(struct exception_context *ec);\n\n    For context structures allocated statically (by an external\n    definition or using the \"static\" keyword), the implicit\n    initialization to all zeros is sufficient, but contexts allocated\n    by other means must be initialized using this macro before they\n    are used by a Try/Catch statement.  It does no harm to initialize\n    a context more than once (by using this macro on a statically\n    allocated context, or using this macro twice on the same context),\n    but a context must not be re-initialized after it has been used by a\n    Try/Catch statement.\n\n\nTry statement\nCatch (expression) statement\n\n    The Try/Catch/Throw macros are capitalized in order to avoid\n    confusion with the C++ keywords, which have subtly different\n    semantics.\n\n    A Try/Catch statement has a syntax similar to an if/else statement,\n    except that the parenthesized expression goes after the second\n    keyword rather than the first.  As with if/else, there are two\n    clauses, each of which may be a simple statement ending with a\n    semicolon or a brace-enclosed compound statement.  But whereas\n    the else clause is optional, the Catch clause is required.  The\n    expression must be a modifiable lvalue (something capable of being\n    assigned to) of the same type (disregarding type qualifiers) that\n    was passed to define_exception_type().\n\n    If a Throw that uses the same exception context as the Try/Catch is\n    executed within the Try clause (typically within a function called\n    by the Try clause), and the exception is not caught by a nested\n    Try/Catch statement, then a copy of the exception will be assigned\n    to the expression, and control will jump to the Catch clause.  If no\n    such Throw is executed, then the assignment is not performed, and\n    the Catch clause is not executed.\n\n    The expression is not evaluated unless and until the exception is\n    caught, which is significant if it has side effects, for example:\n\n        Try foo();\n        Catch (p[++i].e) { ... }\n\n    IMPORTANT: Jumping into or out of a Try clause (for example via\n    return, break, continue, goto, longjmp) is forbidden--the compiler\n    will not complain, but bad things will happen at run-time.  Jumping\n    into or out of a Catch clause is okay, and so is jumping around\n    inside a Try clause.  In many cases where one is tempted to return\n    from a Try clause, it will suffice to use Throw, and then return\n    from the Catch clause.  Another option is to set a flag variable and\n    use goto to jump to the end of the Try clause, then check the flag\n    after the Try/Catch statement.\n\n    IMPORTANT: The values of any non-volatile automatic variables\n    changed within the Try clause are undefined after an exception is\n    caught.  Therefore, variables modified inside the Try block whose\n    values are needed later outside the Try block must either use static\n    storage or be declared with the \"volatile\" type qualifier.\n\n\nThrow expression;\n\n    A Throw statement is very much like a return statement, except that\n    the expression is required.  Whereas return jumps back to the place\n    where the current function was called, Throw jumps back to the Catch\n    clause of the innermost enclosing Try clause.  The expression must\n    be compatible with the type passed to define_exception_type().  The\n    exception must be caught, otherwise the program may crash.\n\n    Slight limitation:  If the expression is a comma-expression, it must\n    be enclosed in parentheses.\n\n\nTry statement\nCatch_anonymous statement\n\n    When the value of the exception is not needed, a Try/Catch statement\n    can use Catch_anonymous instead of Catch (expression).\n\n\nEverything below this point is for the benefit of the compiler.  The\napplication programmer should pretend not to know any of it, because it\nis subject to change.\n\n===*/\n\n\n#ifndef CEXCEPT_H\n#define CEXCEPT_H\n\n\n#include <setjmp.h>\n\n#define define_exception_type(etype) \\\nstruct exception_context { \\\n  jmp_buf *penv; \\\n  int caught; \\\n  volatile struct { etype etmp; } v; \\\n}\n\n/* etmp must be volatile because the application might use automatic */\n/* storage for the_exception_context, and etmp is modified between   */\n/* the calls to setjmp() and longjmp().  A wrapper struct is used to */\n/* avoid warnings about a duplicate volatile qualifier in case etype */\n/* already includes it.                                              */\n\n#define init_exception_context(ec) ((void)((ec)->penv = 0))\n\n#define Try \\\n  { \\\n    jmp_buf *exception__prev, exception__env; \\\n    exception__prev = the_exception_context->penv; \\\n    the_exception_context->penv = &exception__env; \\\n    if (setjmp(exception__env) == 0) { \\\n      do\n\n#define exception__catch(action) \\\n      while (the_exception_context->caught = 0, \\\n             the_exception_context->caught); \\\n    } \\\n    else { \\\n      the_exception_context->caught = 1; \\\n    } \\\n    the_exception_context->penv = exception__prev; \\\n  } \\\n  if (!the_exception_context->caught || action) { } \\\n  else\n\n#define Catch(e) exception__catch(((e) = the_exception_context->v.etmp, 0))\n#define Catch_anonymous exception__catch(0)\n\n/* Try ends with do, and Catch begins with while(0) and ends with     */\n/* else, to ensure that Try/Catch syntax is similar to if/else        */\n/* syntax.                                                            */\n/*                                                                    */\n/* The 0 in while(0) is expressed as x=0,x in order to appease        */\n/* compilers that warn about constant expressions inside while().     */\n/* Most compilers should still recognize that the condition is always */\n/* false and avoid generating code for it.                            */\n\n#define Throw \\\n  for (;; longjmp(*the_exception_context->penv, 1)) \\\n    the_exception_context->v.etmp =\n\n\n#endif /* CEXCEPT_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/contrib/visupng/resource.h",
    "content": "//{{NO_DEPENDENCIES}}\n// Microsoft Developer Studio generated include file.\n// Used by VisualPng.rc\n//\n#define IDM_FILE_OPEN                   40001\n#define IDM_FILE_SAVE                   40002\n#define IDM_FILE_NEXT                   40003\n#define IDM_FILE_PREVIOUS               40004\n#define IDM_FILE_EXIT                   40005\n#define IDM_OPTIONS_BACKGROUND          40006\n#define IDM_OPTIONS_STRETCH             40007\n#define IDM_HELP_ABOUT                  40008\n\n// Next default values for new objects\n//\n#ifdef APSTUDIO_INVOKED\n#ifndef APSTUDIO_READONLY_SYMBOLS\n#define _APS_NEXT_RESOURCE_VALUE        113\n#define _APS_NEXT_COMMAND_VALUE         40009\n#define _APS_NEXT_CONTROL_VALUE         1001\n#define _APS_NEXT_SYMED_VALUE           101\n#endif\n#endif\n"
  },
  {
    "path": "tess-two/jni/libpng/example.c",
    "content": "\n#if 0 /* in case someone actually tries to compile this */\n\n/* example.c - an example of using libpng\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Maintained 1998-2016 Glenn Randers-Pehrson\n * Maintained 1996, 1997 Andreas Dilger)\n * Written 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n * To the extent possible under law, the authors have waived\n * all copyright and related or neighboring rights to this file.\n * This work is published from: United States.\n */\n\n/* This is an example of how to use libpng to read and write PNG files.\n * The file libpng-manual.txt is much more verbose then this.  If you have not\n * read it, do so first.  This was designed to be a starting point of an\n * implementation.  This is not officially part of libpng, is hereby placed\n * in the public domain, and therefore does not require a copyright notice.\n *\n * This file does not currently compile, because it is missing certain\n * parts, like allocating memory to hold an image.  You will have to\n * supply these parts to get it to compile.  For an example of a minimal\n * working PNG reader/writer, see pngtest.c, included in this distribution;\n * see also the programs in the contrib directory.\n */\n\n/* The simple, but restricted, approach to reading a PNG file or data stream\n * just requires two function calls, as in the following complete program.\n * Writing a file just needs one function call, so long as the data has an\n * appropriate layout.\n *\n * The following code reads PNG image data from a file and writes it, in a\n * potentially new format, to a new file.  While this code will compile there is\n * minimal (insufficient) error checking; for a more realistic version look at\n * contrib/examples/pngtopng.c\n */\n#include <stddef.h>\n#include <stdlib.h>\n#include <string.h>\n#include <stdio.h>\n#include <png.h>\n#include <zlib.h>\n\nint main(int argc, const char **argv)\n{\n   if (argc == 3)\n   {\n      png_image image; /* The control structure used by libpng */\n\n      /* Initialize the 'png_image' structure. */\n      memset(&image, 0, (sizeof image));\n      image.version = PNG_IMAGE_VERSION;\n\n      /* The first argument is the file to read: */\n      if (png_image_begin_read_from_file(&image, argv[1]) != 0)\n      {\n         png_bytep buffer;\n\n         /* Set the format in which to read the PNG file; this code chooses a\n          * simple sRGB format with a non-associated alpha channel, adequate to\n          * store most images.\n          */\n         image.format = PNG_FORMAT_RGBA;\n\n         /* Now allocate enough memory to hold the image in this format; the\n          * PNG_IMAGE_SIZE macro uses the information about the image (width,\n          * height and format) stored in 'image'.\n          */\n         buffer = malloc(PNG_IMAGE_SIZE(image));\n\n         /* If enough memory was available read the image in the desired format\n          * then write the result out to the new file.  'background' is not\n          * necessary when reading the image because the alpha channel is\n          * preserved; if it were to be removed, for example if we requested\n          * PNG_FORMAT_RGB, then either a solid background color would have to\n          * be supplied or the output buffer would have to be initialized to the\n          * actual background of the image.\n          *\n          * The fourth argument to png_image_finish_read is the 'row_stride' -\n          * this is the number of components allocated for the image in each\n          * row.  It has to be at least as big as the value returned by\n          * PNG_IMAGE_ROW_STRIDE, but if you just allocate space for the\n          * default, minimum, size using PNG_IMAGE_SIZE as above you can pass\n          * zero.\n          *\n          * The final argument is a pointer to a buffer for the colormap;\n          * colormaps have exactly the same format as a row of image pixels (so\n          * you choose what format to make the colormap by setting\n          * image.format).  A colormap is only returned if\n          * PNG_FORMAT_FLAG_COLORMAP is also set in image.format, so in this\n          * case NULL is passed as the final argument.  If you do want to force\n          * all images into an index/color-mapped format then you can use:\n          *\n          *    PNG_IMAGE_COLORMAP_SIZE(image)\n          *\n          * to find the maximum size of the colormap in bytes.\n          */\n         if (buffer != NULL &&\n            png_image_finish_read(&image, NULL/*background*/, buffer,\n                0/*row_stride*/, NULL/*colormap*/) != 0)\n         {\n            /* Now write the image out to the second argument.  In the write\n             * call 'convert_to_8bit' allows 16-bit data to be squashed down to\n             * 8 bits; this isn't necessary here because the original read was\n             * to the 8-bit format.\n             */\n            if (png_image_write_to_file(&image, argv[2], 0/*convert_to_8bit*/,\n                buffer, 0/*row_stride*/, NULL/*colormap*/) != 0)\n            {\n               /* The image has been written successfully. */\n               exit(0);\n            }\n         }\n\n         else\n         {\n            /* Calling png_free_image is optional unless the simplified API was\n             * not run to completion.  In this case if there wasn't enough\n             * memory for 'buffer' we didn't complete the read, so we must free\n             * the image:\n             */\n            if (buffer == NULL)\n               png_free_image(&image);\n\n            else\n               free(buffer);\n      }\n\n      /* Something went wrong reading or writing the image.  libpng stores a\n       * textual message in the 'png_image' structure:\n       */\n      fprintf(stderr, \"pngtopng: error: %s\\n\", image.message);\n      exit (1);\n   }\n\n   fprintf(stderr, \"pngtopng: usage: pngtopng input-file output-file\\n\");\n   exit(1);\n}\n\n/* That's it ;-)  Of course you probably want to do more with PNG files than\n * just converting them all to 32-bit RGBA PNG files; you can do that between\n * the call to png_image_finish_read and png_image_write_to_file.  You can also\n * ask for the image data to be presented in a number of different formats.  You\n * do this by simply changing the 'format' parameter set before allocating the\n * buffer.\n *\n * The format parameter consists of five flags that define various aspects of\n * the image, you can simply add these together to get the format or you can use\n * one of the predefined macros from png.h (as above):\n *\n * PNG_FORMAT_FLAG_COLOR: if set the image will have three color components per\n *    pixel (red, green and blue), if not set the image will just have one\n *    luminance (grayscale) component.\n *\n * PNG_FORMAT_FLAG_ALPHA: if set each pixel in the image will have an additional\n *    alpha value; a linear value that describes the degree the image pixel\n *    covers (overwrites) the contents of the existing pixel on the display.\n *\n * PNG_FORMAT_FLAG_LINEAR: if set the components of each pixel will be returned\n *    as a series of 16-bit linear values, if not set the components will be\n *    returned as a series of 8-bit values encoded according to the 'sRGB'\n *    standard.  The 8-bit format is the normal format for images intended for\n *    direct display, because almost all display devices do the inverse of the\n *    sRGB transformation to the data they receive.  The 16-bit format is more\n *    common for scientific data and image data that must be further processed;\n *    because it is linear simple math can be done on the component values.\n *    Regardless of the setting of this flag the alpha channel is always linear,\n *    although it will be 8 bits or 16 bits wide as specified by the flag.\n *\n * PNG_FORMAT_FLAG_BGR: if set the components of a color pixel will be returned\n *    in the order blue, then green, then red.  If not set the pixel components\n *    are in the order red, then green, then blue.\n *\n * PNG_FORMAT_FLAG_AFIRST: if set the alpha channel (if present) precedes the\n *    color or grayscale components.  If not set the alpha channel follows the\n *    components.\n *\n * You do not have to read directly from a file.  You can read from memory or,\n * on systems that support it, from a <stdio.h> FILE*.  This is controlled by\n * the particular png_image_read_from_ function you call at the start.  Likewise\n * on write you can write to a FILE* if your system supports it.  Check the\n * macro PNG_STDIO_SUPPORTED to see if stdio support has been included in your\n * libpng build.\n *\n * If you read 16-bit (PNG_FORMAT_FLAG_LINEAR) data you may need to write it in\n * the 8-bit format for display.  You do this by setting the convert_to_8bit\n * flag to 'true'.\n *\n * Don't repeatedly convert between the 8-bit and 16-bit forms.  There is\n * significant data loss when 16-bit data is converted to the 8-bit encoding and\n * the current libpng implementation of conversion to 16-bit is also\n * significantly lossy.  The latter will be fixed in the future, but the former\n * is unavoidable - the 8-bit format just doesn't have enough resolution.\n */\n\n/* If your program needs more information from the PNG data it reads, or if you\n * need to do more complex transformations, or minimize transformations, on the\n * data you read, then you must use one of the several lower level libpng\n * interfaces.\n *\n * All these interfaces require that you do your own error handling - your\n * program must be able to arrange for control to return to your own code any\n * time libpng encounters a problem.  There are several ways to do this, but the\n * standard way is to use the ANSI-C (C90) <setjmp.h> interface to establish a\n * return point within your own code.  You must do this if you do not use the\n * simplified interface (above).\n *\n * The first step is to include the header files you need, including the libpng\n * header file.  Include any standard headers and feature test macros your\n * program requires before including png.h:\n */\n#include <png.h>\n\n /* The png_jmpbuf() macro, used in error handling, became available in\n  * libpng version 1.0.6.  If you want to be able to run your code with older\n  * versions of libpng, you must define the macro yourself (but only if it\n  * is not already defined by libpng!).\n  */\n\n#ifndef png_jmpbuf\n#  define png_jmpbuf(png_ptr) ((png_ptr)->png_jmpbuf)\n#endif\n\n/* Check to see if a file is a PNG file using png_sig_cmp().  png_sig_cmp()\n * returns zero if the image is a PNG and nonzero if it isn't a PNG.\n *\n * The function check_if_png() shown here, but not used, returns nonzero (true)\n * if the file can be opened and is a PNG, 0 (false) otherwise.\n *\n * If this call is successful, and you are going to keep the file open,\n * you should call png_set_sig_bytes(png_ptr, PNG_BYTES_TO_CHECK); once\n * you have created the png_ptr, so that libpng knows your application\n * has read that many bytes from the start of the file.  Make sure you\n * don't call png_set_sig_bytes() with more than 8 bytes read or give it\n * an incorrect number of bytes read, or you will either have read too\n * many bytes (your fault), or you are telling libpng to read the wrong\n * number of magic bytes (also your fault).\n *\n * Many applications already read the first 2 or 4 bytes from the start\n * of the image to determine the file type, so it would be easiest just\n * to pass the bytes to png_sig_cmp() or even skip that if you know\n * you have a PNG file, and call png_set_sig_bytes().\n */\n#define PNG_BYTES_TO_CHECK 4\nint check_if_png(char *file_name, FILE **fp)\n{\n   char buf[PNG_BYTES_TO_CHECK];\n\n   /* Open the prospective PNG file. */\n   if ((*fp = fopen(file_name, \"rb\")) == NULL)\n      return 0;\n\n   /* Read in some of the signature bytes */\n   if (fread(buf, 1, PNG_BYTES_TO_CHECK, *fp) != PNG_BYTES_TO_CHECK)\n      return 0;\n\n   /* Compare the first PNG_BYTES_TO_CHECK bytes of the signature.\n      Return nonzero (true) if they match */\n\n   return(!png_sig_cmp(buf, (png_size_t)0, PNG_BYTES_TO_CHECK));\n}\n\n/* Read a PNG file.  You may want to return an error code if the read\n * fails (depending upon the failure).  There are two \"prototypes\" given\n * here - one where we are given the filename, and we need to open the\n * file, and the other where we are given an open file (possibly with\n * some or all of the magic bytes read - see comments above).\n */\n#ifdef open_file /* prototype 1 */\nvoid read_png(char *file_name)  /* We need to open the file */\n{\n   png_structp png_ptr;\n   png_infop info_ptr;\n   int sig_read = 0;\n   png_uint_32 width, height;\n   int bit_depth, color_type, interlace_type;\n   FILE *fp;\n\n   if ((fp = fopen(file_name, \"rb\")) == NULL)\n      return (ERROR);\n\n#else no_open_file /* prototype 2 */\nvoid read_png(FILE *fp, int sig_read)  /* File is already open */\n{\n   png_structp png_ptr;\n   png_infop info_ptr;\n   png_uint_32 width, height;\n   int bit_depth, color_type, interlace_type;\n#endif no_open_file /* Only use one prototype! */\n\n   /* Create and initialize the png_struct with the desired error handler\n    * functions.  If you want to use the default stderr and longjump method,\n    * you can supply NULL for the last three parameters.  We also supply the\n    * the compiler header file version, so that we know if the application\n    * was compiled with a compatible version of the library.  REQUIRED\n    */\n   png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,\n       png_voidp user_error_ptr, user_error_fn, user_warning_fn);\n\n   if (png_ptr == NULL)\n   {\n      fclose(fp);\n      return (ERROR);\n   }\n\n   /* Allocate/initialize the memory for image information.  REQUIRED. */\n   info_ptr = png_create_info_struct(png_ptr);\n   if (info_ptr == NULL)\n   {\n      fclose(fp);\n      png_destroy_read_struct(&png_ptr, NULL, NULL);\n      return (ERROR);\n   }\n\n   /* Set error handling if you are using the setjmp/longjmp method (this is\n    * the normal method of doing things with libpng).  REQUIRED unless you\n    * set up your own error handlers in the png_create_read_struct() earlier.\n    */\n\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      /* Free all of the memory associated with the png_ptr and info_ptr */\n      png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n      fclose(fp);\n      /* If we get here, we had a problem reading the file */\n      return (ERROR);\n   }\n\n   /* One of the following I/O initialization methods is REQUIRED */\n#ifdef streams /* PNG file I/O method 1 */\n   /* Set up the input control if you are using standard C streams */\n   png_init_io(png_ptr, fp);\n\n#else no_streams /* PNG file I/O method 2 */\n   /* If you are using replacement read functions, instead of calling\n    * png_init_io() here you would call:\n    */\n   png_set_read_fn(png_ptr, (void *)user_io_ptr, user_read_fn);\n   /* where user_io_ptr is a structure you want available to the callbacks */\n#endif no_streams /* Use only one I/O method! */\n\n   /* If we have already read some of the signature */\n   png_set_sig_bytes(png_ptr, sig_read);\n\n#ifdef hilevel\n   /*\n    * If you have enough memory to read in the entire image at once,\n    * and you need to specify only transforms that can be controlled\n    * with one of the PNG_TRANSFORM_* bits (this presently excludes\n    * quantizing, filling, setting background, and doing gamma\n    * adjustment), then you can read the entire image (including\n    * pixels) into the info structure with this call:\n    */\n   png_read_png(png_ptr, info_ptr, png_transforms, NULL);\n\n#else\n   /* OK, you're doing it the hard way, with the lower-level functions */\n\n   /* The call to png_read_info() gives us all of the information from the\n    * PNG file before the first IDAT (image data chunk).  REQUIRED\n    */\n   png_read_info(png_ptr, info_ptr);\n\n   png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,\n       &interlace_type, NULL, NULL);\n\n   /* Set up the data transformations you want.  Note that these are all\n    * optional.  Only call them if you want/need them.  Many of the\n    * transformations only work on specific types of images, and many\n    * are mutually exclusive.\n    */\n\n   /* Tell libpng to strip 16 bits/color files down to 8 bits/color.\n    * Use accurate scaling if it's available, otherwise just chop off the\n    * low byte.\n    */\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n   png_set_scale_16(png_ptr);\n#else\n   png_set_strip_16(png_ptr);\n#endif\n\n   /* Strip alpha bytes from the input data without combining with the\n    * background (not recommended).\n    */\n   png_set_strip_alpha(png_ptr);\n\n   /* Extract multiple pixels with bit depths of 1, 2, and 4 from a single\n    * byte into separate bytes (useful for paletted and grayscale images).\n    */\n   png_set_packing(png_ptr);\n\n   /* Change the order of packed pixels to least significant bit first\n    * (not useful if you are using png_set_packing). */\n   png_set_packswap(png_ptr);\n\n   /* Expand paletted colors into true RGB triplets */\n   if (color_type == PNG_COLOR_TYPE_PALETTE)\n      png_set_palette_to_rgb(png_ptr);\n\n   /* Expand grayscale images to the full 8 bits from 1, 2, or 4 bits/pixel */\n   if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)\n      png_set_expand_gray_1_2_4_to_8(png_ptr);\n\n   /* Expand paletted or RGB images with transparency to full alpha channels\n    * so the data will be available as RGBA quartets.\n    */\n   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)\n      png_set_tRNS_to_alpha(png_ptr);\n\n   /* Set the background color to draw transparent and alpha images over.\n    * It is possible to set the red, green, and blue components directly\n    * for paletted images instead of supplying a palette index.  Note that\n    * even if the PNG file supplies a background, you are not required to\n    * use it - you should use the (solid) application background if it has one.\n    */\n\n   png_color_16 my_background, *image_background;\n\n   if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0)\n      png_set_background(png_ptr, image_background,\n          PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);\n   else\n      png_set_background(png_ptr, &my_background,\n          PNG_BACKGROUND_GAMMA_SCREEN, 0, 1.0);\n\n   /* Some suggestions as to how to get a screen gamma value\n    *\n    * Note that screen gamma is the display_exponent, which includes\n    * the CRT_exponent and any correction for viewing conditions\n    */\n   if (/* We have a user-defined screen gamma value */)\n   {\n      screen_gamma = user-defined screen_gamma;\n   }\n   /* This is one way that applications share the same screen gamma value */\n   else if ((gamma_str = getenv(\"SCREEN_GAMMA\")) != NULL)\n   {\n      screen_gamma = atof(gamma_str);\n   }\n   /* If we don't have another value */\n   else\n   {\n      screen_gamma = PNG_DEFAULT_sRGB;  /* A good guess for a PC monitor\n                                           in a dimly lit room */\n      screen_gamma = PNG_GAMMA_MAC_18 or 1.0; /* Good guesses for Mac systems */\n   }\n\n   /* Tell libpng to handle the gamma conversion for you.  The final call\n    * is a good guess for PC generated images, but it should be configurable\n    * by the user at run time by the user.  It is strongly suggested that\n    * your application support gamma correction.\n    */\n\n   int intent;\n\n   if (png_get_sRGB(png_ptr, info_ptr, &intent) != 0)\n      png_set_gamma(png_ptr, screen_gamma, PNG_DEFAULT_sRGB);\n   else\n   {\n      double image_gamma;\n      if (png_get_gAMA(png_ptr, info_ptr, &image_gamma) != 0)\n         png_set_gamma(png_ptr, screen_gamma, image_gamma);\n      else\n         png_set_gamma(png_ptr, screen_gamma, 0.45455);\n   }\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n   /* Quantize RGB files down to 8-bit palette or reduce palettes\n    * to the number of colors available on your screen.\n    */\n   if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      int num_palette;\n      png_colorp palette;\n\n      /* This reduces the image to the application supplied palette */\n      if (/* We have our own palette */)\n      {\n         /* An array of colors to which the image should be quantized */\n         png_color std_color_cube[MAX_SCREEN_COLORS];\n\n         png_set_quantize(png_ptr, std_color_cube, MAX_SCREEN_COLORS,\n             MAX_SCREEN_COLORS, NULL, 0);\n      }\n      /* This reduces the image to the palette supplied in the file */\n      else if (png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette) != 0)\n      {\n         png_uint_16p histogram = NULL;\n\n         png_get_hIST(png_ptr, info_ptr, &histogram);\n\n         png_set_quantize(png_ptr, palette, num_palette,\n             max_screen_colors, histogram, 0);\n      }\n   }\n#endif /* READ_QUANTIZE */\n\n   /* Invert monochrome files to have 0 as white and 1 as black */\n   png_set_invert_mono(png_ptr);\n\n   /* If you want to shift the pixel values from the range [0,255] or\n    * [0,65535] to the original [0,7] or [0,31], or whatever range the\n    * colors were originally in:\n    */\n   if (png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT) != 0)\n   {\n      png_color_8p sig_bit_p;\n\n      png_get_sBIT(png_ptr, info_ptr, &sig_bit_p);\n      png_set_shift(png_ptr, sig_bit_p);\n   }\n\n   /* Flip the RGB pixels to BGR (or RGBA to BGRA) */\n   if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n      png_set_bgr(png_ptr);\n\n   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */\n   png_set_swap_alpha(png_ptr);\n\n   /* Swap bytes of 16-bit files to least significant byte first */\n   png_set_swap(png_ptr);\n\n   /* Add filler (or alpha) byte (before/after each RGB triplet) */\n   png_set_filler(png_ptr, 0xffff, PNG_FILLER_AFTER);\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* Turn on interlace handling.  REQUIRED if you are not using\n    * png_read_image().  To see how to handle interlacing passes,\n    * see the png_read_row() method below:\n    */\n   number_passes = png_set_interlace_handling(png_ptr);\n#else /* !READ_INTERLACING */\n   number_passes = 1;\n#endif /* READ_INTERLACING */\n\n\n   /* Optional call to gamma correct and add the background to the palette\n    * and update info structure.  REQUIRED if you are expecting libpng to\n    * update the palette for you (ie you selected such a transform above).\n    */\n   png_read_update_info(png_ptr, info_ptr);\n\n   /* Allocate the memory to hold the image using the fields of info_ptr. */\n\n   /* The easiest way to read the image: */\n   png_bytep row_pointers[height];\n\n   /* Clear the pointer array */\n   for (row = 0; row < height; row++)\n      row_pointers[row] = NULL;\n\n   for (row = 0; row < height; row++)\n      row_pointers[row] = png_malloc(png_ptr, png_get_rowbytes(png_ptr,\n          info_ptr));\n\n   /* Now it's time to read the image.  One of these methods is REQUIRED */\n#ifdef entire /* Read the entire image in one go */\n   png_read_image(png_ptr, row_pointers);\n\n#else no_entire /* Read the image one or more scanlines at a time */\n   /* The other way to read images - deal with interlacing: */\n\n   for (pass = 0; pass < number_passes; pass++)\n   {\n#ifdef single /* Read the image a single row at a time */\n      for (y = 0; y < height; y++)\n      {\n         png_read_rows(png_ptr, &row_pointers[y], NULL, 1);\n      }\n\n#else no_single /* Read the image several rows at a time */\n      for (y = 0; y < height; y += number_of_rows)\n      {\n#ifdef sparkle /* Read the image using the \"sparkle\" effect. */\n         png_read_rows(png_ptr, &row_pointers[y], NULL,\n             number_of_rows);\n#else no_sparkle /* Read the image using the \"rectangle\" effect */\n         png_read_rows(png_ptr, NULL, &row_pointers[y],\n             number_of_rows);\n#endif no_sparkle /* Use only one of these two methods */\n      }\n\n      /* If you want to display the image after every pass, do so here */\n#endif no_single /* Use only one of these two methods */\n   }\n#endif no_entire /* Use only one of these two methods */\n\n   /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */\n   png_read_end(png_ptr, info_ptr);\n#endif hilevel\n\n   /* At this point you have read the entire image */\n\n   /* Clean up after the read, and free any memory allocated - REQUIRED */\n   png_destroy_read_struct(&png_ptr, &info_ptr, NULL);\n\n   /* Close the file */\n   fclose(fp);\n\n   /* That's it */\n   return (OK);\n}\n\n/* Progressively read a file */\n\nint\ninitialize_png_reader(png_structp *png_ptr, png_infop *info_ptr)\n{\n   /* Create and initialize the png_struct with the desired error handler\n    * functions.  If you want to use the default stderr and longjump method,\n    * you can supply NULL for the last three parameters.  We also check that\n    * the library version is compatible in case we are using dynamically\n    * linked libraries.\n    */\n   *png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING,\n        png_voidp user_error_ptr, user_error_fn, user_warning_fn);\n\n   if (*png_ptr == NULL)\n   {\n      *info_ptr = NULL;\n      return (ERROR);\n   }\n\n   *info_ptr = png_create_info_struct(png_ptr);\n\n   if (*info_ptr == NULL)\n   {\n      png_destroy_read_struct(png_ptr, info_ptr, NULL);\n      return (ERROR);\n   }\n\n   if (setjmp(png_jmpbuf((*png_ptr))))\n   {\n      png_destroy_read_struct(png_ptr, info_ptr, NULL);\n      return (ERROR);\n   }\n\n   /* This one's new.  You will need to provide all three\n    * function callbacks, even if you aren't using them all.\n    * If you aren't using all functions, you can specify NULL\n    * parameters.  Even when all three functions are NULL,\n    * you need to call png_set_progressive_read_fn().\n    * These functions shouldn't be dependent on global or\n    * static variables if you are decoding several images\n    * simultaneously.  You should store stream specific data\n    * in a separate struct, given as the second parameter,\n    * and retrieve the pointer from inside the callbacks using\n    * the function png_get_progressive_ptr(png_ptr).\n    */\n   png_set_progressive_read_fn(*png_ptr, (void *)stream_data,\n       info_callback, row_callback, end_callback);\n\n   return (OK);\n}\n\nint\nprocess_data(png_structp *png_ptr, png_infop *info_ptr,\n    png_bytep buffer, png_uint_32 length)\n{\n   if (setjmp(png_jmpbuf((*png_ptr))))\n   {\n      /* Free the png_ptr and info_ptr memory on error */\n      png_destroy_read_struct(png_ptr, info_ptr, NULL);\n      return (ERROR);\n   }\n\n   /* This one's new also.  Simply give it chunks of data as\n    * they arrive from the data stream (in order, of course).\n    * On segmented machines, don't give it any more than 64K.\n    * The library seems to run fine with sizes of 4K, although\n    * you can give it much less if necessary (I assume you can\n    * give it chunks of 1 byte, but I haven't tried with less\n    * than 256 bytes yet).  When this function returns, you may\n    * want to display any rows that were generated in the row\n    * callback, if you aren't already displaying them there.\n    */\n   png_process_data(*png_ptr, *info_ptr, buffer, length);\n   return (OK);\n}\n\ninfo_callback(png_structp png_ptr, png_infop info)\n{\n   /* Do any setup here, including setting any of the transformations\n    * mentioned in the Reading PNG files section.  For now, you _must_\n    * call either png_start_read_image() or png_read_update_info()\n    * after all the transformations are set (even if you don't set\n    * any).  You may start getting rows before png_process_data()\n    * returns, so this is your last chance to prepare for that.\n    */\n}\n\nrow_callback(png_structp png_ptr, png_bytep new_row,\n    png_uint_32 row_num, int pass)\n{\n   /*\n    * This function is called for every row in the image.  If the\n    * image is interlaced, and you turned on the interlace handler,\n    * this function will be called for every row in every pass.\n    *\n    * In this function you will receive a pointer to new row data from\n    * libpng called new_row that is to replace a corresponding row (of\n    * the same data format) in a buffer allocated by your application.\n    *\n    * The new row data pointer \"new_row\" may be NULL, indicating there is\n    * no new data to be replaced (in cases of interlace loading).\n    *\n    * If new_row is not NULL then you need to call\n    * png_progressive_combine_row() to replace the corresponding row as\n    * shown below:\n    */\n\n   /* Get pointer to corresponding row in our\n    * PNG read buffer.\n    */\n   png_bytep old_row = ((png_bytep *)our_data)[row_num];\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* If both rows are allocated then copy the new row\n    * data to the corresponding row data.\n    */\n   if ((old_row != NULL) && (new_row != NULL))\n   png_progressive_combine_row(png_ptr, old_row, new_row);\n\n   /*\n    * The rows and passes are called in order, so you don't really\n    * need the row_num and pass, but I'm supplying them because it\n    * may make your life easier.\n    *\n    * For the non-NULL rows of interlaced images, you must call\n    * png_progressive_combine_row() passing in the new row and the\n    * old row, as demonstrated above.  You can call this function for\n    * NULL rows (it will just return) and for non-interlaced images\n    * (it just does the memcpy for you) if it will make the code\n    * easier.  Thus, you can just do this for all cases:\n    */\n\n   png_progressive_combine_row(png_ptr, old_row, new_row);\n\n   /* where old_row is what was displayed for previous rows.  Note\n    * that the first pass (pass == 0 really) will completely cover\n    * the old row, so the rows do not have to be initialized.  After\n    * the first pass (and only for interlaced images), you will have\n    * to pass the current row as new_row, and the function will combine\n    * the old row and the new row.\n    */\n#endif /* READ_INTERLACING */\n}\n\nend_callback(png_structp png_ptr, png_infop info)\n{\n   /* This function is called when the whole image has been read,\n    * including any chunks after the image (up to and including\n    * the IEND).  You will usually have the same info chunk as you\n    * had in the header, although some data may have been added\n    * to the comments and time fields.\n    *\n    * Most people won't do much here, perhaps setting a flag that\n    * marks the image as finished.\n    */\n}\n\n/* Write a png file */\nvoid write_png(char *file_name /* , ... other image information ... */)\n{\n   FILE *fp;\n   png_structp png_ptr;\n   png_infop info_ptr;\n   png_colorp palette;\n\n   /* Open the file */\n   fp = fopen(file_name, \"wb\");\n   if (fp == NULL)\n      return (ERROR);\n\n   /* Create and initialize the png_struct with the desired error handler\n    * functions.  If you want to use the default stderr and longjump method,\n    * you can supply NULL for the last three parameters.  We also check that\n    * the library version is compatible with the one used at compile time,\n    * in case we are using dynamically linked libraries.  REQUIRED.\n    */\n   png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING,\n       png_voidp user_error_ptr, user_error_fn, user_warning_fn);\n\n   if (png_ptr == NULL)\n   {\n      fclose(fp);\n      return (ERROR);\n   }\n\n   /* Allocate/initialize the image information data.  REQUIRED */\n   info_ptr = png_create_info_struct(png_ptr);\n   if (info_ptr == NULL)\n   {\n      fclose(fp);\n      png_destroy_write_struct(&png_ptr,  NULL);\n      return (ERROR);\n   }\n\n   /* Set error handling.  REQUIRED if you aren't supplying your own\n    * error handling functions in the png_create_write_struct() call.\n    */\n   if (setjmp(png_jmpbuf(png_ptr)))\n   {\n      /* If we get here, we had a problem writing the file */\n      fclose(fp);\n      png_destroy_write_struct(&png_ptr, &info_ptr);\n      return (ERROR);\n   }\n\n   /* One of the following I/O initialization functions is REQUIRED */\n\n#ifdef streams /* I/O initialization method 1 */\n   /* Set up the output control if you are using standard C streams */\n   png_init_io(png_ptr, fp);\n\n#else no_streams /* I/O initialization method 2 */\n   /* If you are using replacement write functions, instead of calling\n    * png_init_io() here you would call\n    */\n   png_set_write_fn(png_ptr, (void *)user_io_ptr, user_write_fn,\n       user_IO_flush_function);\n   /* where user_io_ptr is a structure you want available to the callbacks */\n#endif no_streams /* Only use one initialization method */\n\n#ifdef hilevel\n   /* This is the easy way.  Use it if you already have all the\n    * image info living in the structure.  You could \"|\" many\n    * PNG_TRANSFORM flags into the png_transforms integer here.\n    */\n   png_write_png(png_ptr, info_ptr, png_transforms, NULL);\n\n#else\n   /* This is the hard way */\n\n   /* Set the image information here.  Width and height are up to 2^31,\n    * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on\n    * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY,\n    * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB,\n    * or PNG_COLOR_TYPE_RGB_ALPHA.  interlace is either PNG_INTERLACE_NONE or\n    * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST\n    * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. REQUIRED\n    */\n   png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, PNG_COLOR_TYPE_???,\n       PNG_INTERLACE_????, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n   /* Set the palette if there is one.  REQUIRED for indexed-color images */\n   palette = (png_colorp)png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH\n             * (sizeof (png_color)));\n   /* ... Set palette colors ... */\n   png_set_PLTE(png_ptr, info_ptr, palette, PNG_MAX_PALETTE_LENGTH);\n   /* You must not free palette here, because png_set_PLTE only makes a link to\n    * the palette that you malloced.  Wait until you are about to destroy\n    * the png structure.\n    */\n\n   /* Optional significant bit (sBIT) chunk */\n   png_color_8 sig_bit;\n\n   /* If we are dealing with a grayscale image then */\n   sig_bit.gray = true_bit_depth;\n\n   /* Otherwise, if we are dealing with a color image then */\n   sig_bit.red = true_red_bit_depth;\n   sig_bit.green = true_green_bit_depth;\n   sig_bit.blue = true_blue_bit_depth;\n\n   /* If the image has an alpha channel then */\n   sig_bit.alpha = true_alpha_bit_depth;\n\n   png_set_sBIT(png_ptr, info_ptr, &sig_bit);\n\n\n   /* Optional gamma chunk is strongly suggested if you have any guess\n    * as to the correct gamma of the image.\n    */\n   png_set_gAMA(png_ptr, info_ptr, gamma);\n\n   /* Optionally write comments into the image */\n   {\n      png_text text_ptr[3];\n\n      char key0[]=\"Title\";\n      char text0[]=\"Mona Lisa\";\n      text_ptr[0].key = key0;\n      text_ptr[0].text = text0;\n      text_ptr[0].compression = PNG_TEXT_COMPRESSION_NONE;\n      text_ptr[0].itxt_length = 0;\n      text_ptr[0].lang = NULL;\n      text_ptr[0].lang_key = NULL;\n\n      char key1[]=\"Author\";\n      char text1[]=\"Leonardo DaVinci\";\n      text_ptr[1].key = key1;\n      text_ptr[1].text = text1;\n      text_ptr[1].compression = PNG_TEXT_COMPRESSION_NONE;\n      text_ptr[1].itxt_length = 0;\n      text_ptr[1].lang = NULL;\n      text_ptr[1].lang_key = NULL;\n\n      char key2[]=\"Description\";\n      char text2[]=\"<long text>\";\n      text_ptr[2].key = key2;\n      text_ptr[2].text = text2;\n      text_ptr[2].compression = PNG_TEXT_COMPRESSION_zTXt;\n      text_ptr[2].itxt_length = 0;\n      text_ptr[2].lang = NULL;\n      text_ptr[2].lang_key = NULL;\n\n      png_set_text(write_ptr, write_info_ptr, text_ptr, 3);\n   }\n\n   /* Other optional chunks like cHRM, bKGD, tRNS, tIME, oFFs, pHYs */\n\n   /* Note that if sRGB is present the gAMA and cHRM chunks must be ignored\n    * on read and, if your application chooses to write them, they must\n    * be written in accordance with the sRGB profile\n    */\n\n   /* Write the file header information.  REQUIRED */\n   png_write_info(png_ptr, info_ptr);\n\n   /* If you want, you can write the info in two steps, in case you need to\n    * write your private chunk ahead of PLTE:\n    *\n    *   png_write_info_before_PLTE(write_ptr, write_info_ptr);\n    *   write_my_chunk();\n    *   png_write_info(png_ptr, info_ptr);\n    *\n    * However, given the level of known- and unknown-chunk support in 1.2.0\n    * and up, this should no longer be necessary.\n    */\n\n   /* Once we write out the header, the compression type on the text\n    * chunk gets changed to PNG_TEXT_COMPRESSION_NONE_WR or\n    * PNG_TEXT_COMPRESSION_zTXt_WR, so it doesn't get written out again\n    * at the end.\n    */\n\n   /* Set up the transformations you want.  Note that these are\n    * all optional.  Only call them if you want them.\n    */\n\n   /* Invert monochrome pixels */\n   png_set_invert_mono(png_ptr);\n\n   /* Shift the pixels up to a legal bit depth and fill in\n    * as appropriate to correctly scale the image.\n    */\n   png_set_shift(png_ptr, &sig_bit);\n\n   /* Pack pixels into bytes */\n   png_set_packing(png_ptr);\n\n   /* Swap location of alpha bytes from ARGB to RGBA */\n   png_set_swap_alpha(png_ptr);\n\n   /* Get rid of filler (OR ALPHA) bytes, pack XRGB/RGBX/ARGB/RGBA into\n    * RGB (4 channels -> 3 channels). The second parameter is not used.\n    */\n   png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);\n\n   /* Flip BGR pixels to RGB */\n   png_set_bgr(png_ptr);\n\n   /* Swap bytes of 16-bit files to most significant byte first */\n   png_set_swap(png_ptr);\n\n   /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */\n   png_set_packswap(png_ptr);\n\n   /* Turn on interlace handling if you are not using png_write_image() */\n   if (interlacing != 0)\n      number_passes = png_set_interlace_handling(png_ptr);\n\n   else\n      number_passes = 1;\n\n   /* The easiest way to write the image (you may have a different memory\n    * layout, however, so choose what fits your needs best).  You need to\n    * use the first method if you aren't handling interlacing yourself.\n    */\n   png_uint_32 k, height, width;\n\n   /* In this example, \"image\" is a one-dimensional array of bytes */\n   png_byte image[height*width*bytes_per_pixel];\n\n   png_bytep row_pointers[height];\n\n   if (height > PNG_UINT_32_MAX/(sizeof (png_bytep)))\n      png_error (png_ptr, \"Image is too tall to process in memory\");\n\n   /* Set up pointers into your \"image\" byte array */\n   for (k = 0; k < height; k++)\n      row_pointers[k] = image + k*width*bytes_per_pixel;\n\n   /* One of the following output methods is REQUIRED */\n\n#ifdef entire /* Write out the entire image data in one call */\n   png_write_image(png_ptr, row_pointers);\n\n   /* The other way to write the image - deal with interlacing */\n\n#else no_entire /* Write out the image data by one or more scanlines */\n\n   /* The number of passes is either 1 for non-interlaced images,\n    * or 7 for interlaced images.\n    */\n   for (pass = 0; pass < number_passes; pass++)\n   {\n      /* Write a few rows at a time. */\n      png_write_rows(png_ptr, &row_pointers[first_row], number_of_rows);\n\n      /* If you are only writing one row at a time, this works */\n      for (y = 0; y < height; y++)\n         png_write_rows(png_ptr, &row_pointers[y], 1);\n   }\n#endif no_entire /* Use only one output method */\n\n   /* You can write optional chunks like tEXt, zTXt, and tIME at the end\n    * as well.  Shouldn't be necessary in 1.2.0 and up as all the public\n    * chunks are supported and you can use png_set_unknown_chunks() to\n    * register unknown chunks into the info structure to be written out.\n    */\n\n   /* It is REQUIRED to call this to finish writing the rest of the file */\n   png_write_end(png_ptr, info_ptr);\n#endif hilevel\n\n   /* If you png_malloced a palette, free it here (don't free info_ptr->palette,\n    * as recommended in versions 1.0.5m and earlier of this example; if\n    * libpng mallocs info_ptr->palette, libpng will free it).  If you\n    * allocated it with malloc() instead of png_malloc(), use free() instead\n    * of png_free().\n    */\n   png_free(png_ptr, palette);\n   palette = NULL;\n\n   /* Similarly, if you png_malloced any data that you passed in with\n    * png_set_something(), such as a hist or trans array, free it here,\n    * when you can be sure that libpng is through with it.\n    */\n   png_free(png_ptr, trans);\n   trans = NULL;\n   /* Whenever you use png_free() it is a good idea to set the pointer to\n    * NULL in case your application inadvertently tries to png_free() it\n    * again.  When png_free() sees a NULL it returns without action, thus\n    * avoiding the double-free security problem.\n    */\n\n   /* Clean up after the write, and free any memory allocated */\n   png_destroy_write_struct(&png_ptr, &info_ptr);\n\n   /* Close the file */\n   fclose(fp);\n\n   /* That's it */\n   return (OK);\n}\n\n#endif /* if 0 */\n"
  },
  {
    "path": "tess-two/jni/libpng/libpng-config.in",
    "content": "#! /bin/sh\n\n# libpng-config\n# provides configuration info for libpng.\n\n# Copyright (C) 2002, 2004, 2006, 2007 Glenn Randers-Pehrson\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Modeled after libxml-config.\n\nversion=\"@PNGLIB_VERSION@\"\nprefix=\"@prefix@\"\nexec_prefix=\"@exec_prefix@\"\nlibdir=\"@libdir@\"\nincludedir=\"@includedir@/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@\"\nlibs=\"-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@\"\nall_libs=\"-lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@ @LIBS@\"\nI_opts=\"-I${includedir}\"\nL_opts=\"-L${libdir}\"\nR_opts=\"\"\ncppflags=\"\"\nccopts=\"\"\nldopts=\"\"\n\nusage()\n{\n    cat <<EOF\nUsage: $0 [OPTION] ...\n\nKnown values for OPTION are:\n\n  --prefix        print libpng prefix\n  --libdir        print path to directory containing library\n  --libs          print library linking information\n  --ccopts        print compiler options\n  --cppflags      print pre-processor flags\n  --cflags        print preprocessor flags, I_opts, and compiler options\n  --I_opts        print \"-I\" include options\n  --L_opts        print linker \"-L\" flags for dynamic linking\n  --R_opts        print dynamic linker \"-R\" or \"-rpath\" flags\n  --ldopts        print linker options\n  --ldflags       print linker flags (ldopts, L_opts, R_opts, and libs)\n  --static        revise subsequent outputs for static linking\n  --help          print this help and exit\n  --version       print version information\nEOF\n\n    exit $1\n}\n\nif test $# -eq 0; then\n    usage 1\nfi\n\nwhile test $# -gt 0; do\n    case \"$1\" in\n\n    --prefix)\n        echo ${prefix}\n        ;;\n\n    --version)\n        echo ${version}\n        exit 0\n        ;;\n\n    --help)\n        usage 0\n        ;;\n\n    --ccopts)\n        echo ${ccopts}\n        ;;\n\n    --cppflags)\n        echo ${cppflags}\n        ;;\n\n    --cflags)\n        echo ${I_opts} ${cppflags} ${ccopts}\n        ;;\n\n    --libdir)\n        echo ${libdir}\n        ;;\n\n    --libs)\n        echo ${libs}\n        ;;\n\n    --I_opts)\n        echo ${I_opts}\n        ;;\n\n    --L_opts)\n        echo ${L_opts}\n        ;;\n\n    --R_opts)\n        echo ${R_opts}\n        ;;\n\n    --ldopts)\n        echo ${ldopts}\n        ;;\n\n    --ldflags)\n        echo ${ldopts} ${L_opts} ${R_opts} ${libs}\n        ;;\n\n    --static)\n        R_opts=\"\"\n        libs=${all_libs}\n        ;;\n\n    *)\n        usage\n        exit 1\n        ;;\n    esac\n    shift\ndone\n\nexit 0\n"
  },
  {
    "path": "tess-two/jni/libpng/libpng-manual.txt",
    "content": "libpng-manual.txt - A description on how to use and modify libpng\n\n libpng version 1.6.25 - September 1, 2016\n Updated and distributed by Glenn Randers-Pehrson\n <glennrp at users.sourceforge.net>\n Copyright (c) 1998-2016 Glenn Randers-Pehrson\n\n This document is released under the libpng license.\n For conditions of distribution and use, see the disclaimer\n and license in png.h\n\n Based on:\n\n libpng versions 0.97, January 1998, through 1.6.25 - September 1, 2016\n Updated and distributed by Glenn Randers-Pehrson\n Copyright (c) 1998-2016 Glenn Randers-Pehrson\n\n libpng 1.0 beta 6 - version 0.96 - May 28, 1997\n Updated and distributed by Andreas Dilger\n Copyright (c) 1996, 1997 Andreas Dilger\n\n libpng 1.0 beta 2 - version 0.88 - January 26, 1996\n For conditions of distribution and use, see copyright\n notice in png.h. Copyright (c) 1995, 1996 Guy Eric\n Schalnat, Group 42, Inc.\n\n Updated/rewritten per request in the libpng FAQ\n Copyright (c) 1995, 1996 Frank J. T. Wojcik\n December 18, 1995 & January 20, 1996\n\n TABLE OF CONTENTS\n\n    I. Introduction\n   II. Structures\n  III. Reading\n   IV. Writing\n    V. Simplified API\n   VI. Modifying/Customizing libpng\n  VII. MNG support\n VIII. Changes to Libpng from version 0.88\n   IX. Changes to Libpng from version 1.0.x to 1.2.x\n    X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x\n   XI. Changes to Libpng from version 1.4.x to 1.5.x\n  XII. Changes to Libpng from version 1.5.x to 1.6.x\n XIII. Detecting libpng\n  XIV. Source code repository\n   XV. Coding style\n  XVI. Y2K Compliance in libpng\n\nI. Introduction\n\nThis file describes how to use and modify the PNG reference library\n(known as libpng) for your own use.  In addition to this\nfile, example.c is a good starting point for using the library, as\nit is heavily commented and should include everything most people\nwill need.  We assume that libpng is already installed; see the\nINSTALL file for instructions on how to configure and install libpng.\n\nFor examples of libpng usage, see the files \"example.c\", \"pngtest.c\",\nand the files in the \"contrib\" directory, all of which are included in\nthe libpng distribution.\n\nLibpng was written as a companion to the PNG specification, as a way\nof reducing the amount of time and effort it takes to support the PNG\nfile format in application programs.\n\nThe PNG specification (second edition), November 2003, is available as\na W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at\n<http://www.w3.org/TR/2003/REC-PNG-20031110/\nThe W3C and ISO documents have identical technical content.\n\nThe PNG-1.2 specification is available at\n<http://png-mng.sourceforge.net/pub/png/spec/1.2/>.\nIt is technically equivalent\nto the PNG specification (second edition) but has some additional material.\n\nThe PNG-1.0 specification is available as RFC 2083 \n<http://png-mng.sourceforge.net/pub/png/spec/1.0/> and as a\nW3C Recommendation <http://www.w3.org/TR/REC-png-961001>.\n\nSome additional chunks are described in the special-purpose public chunks\ndocuments at <http://www.libpng.org/pub/png/spec/register/>\n\nOther information\nabout PNG, and the latest version of libpng, can be found at the PNG home\npage, <http://www.libpng.org/pub/png/>.\n\nMost users will not have to modify the library significantly; advanced\nusers may want to modify it more.  All attempts were made to make it as\ncomplete as possible, while keeping the code easy to understand.\nCurrently, this library only supports C.  Support for other languages\nis being considered.\n\nLibpng has been designed to handle multiple sessions at one time,\nto be easily modifiable, to be portable to the vast majority of\nmachines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy\nto use.  The ultimate goal of libpng is to promote the acceptance of\nthe PNG file format in whatever way possible.  While there is still\nwork to be done (see the TODO file), libpng should cover the\nmajority of the needs of its users.\n\nLibpng uses zlib for its compression and decompression of PNG files.\nFurther information about zlib, and the latest version of zlib, can\nbe found at the zlib home page, <http://zlib.net/>.\nThe zlib compression utility is a general purpose utility that is\nuseful for more than PNG files, and can be used without libpng.\nSee the documentation delivered with zlib for more details.\nYou can usually find the source files for the zlib utility wherever you\nfind the libpng source files.\n\nLibpng is thread safe, provided the threads are using different\ninstances of the structures.  Each thread should have its own\npng_struct and png_info instances, and thus its own image.\nLibpng does not protect itself against two threads using the\nsame instance of a structure.\n\nII. Structures\n\nThere are two main structures that are important to libpng, png_struct\nand png_info.  Both are internal structures that are no longer exposed\nin the libpng interface (as of libpng 1.5.0).\n\nThe png_info structure is designed to provide information about the\nPNG file.  At one time, the fields of png_info were intended to be\ndirectly accessible to the user.  However, this tended to cause problems\nwith applications using dynamically loaded libraries, and as a result\na set of interface functions for png_info (the png_get_*() and png_set_*()\nfunctions) was developed, and direct access to the png_info fields was\ndeprecated..\n\nThe png_struct structure is the object used by the library to decode a\nsingle image.  As of 1.5.0 this structure is also not exposed.\n\nAlmost all libpng APIs require a pointer to a png_struct as the first argument.\nMany (in particular the png_set and png_get APIs) also require a pointer\nto png_info as the second argument.  Some application visible macros\ndefined in png.h designed for basic data access (reading and writing\nintegers in the PNG format) don't take a png_info pointer, but it's almost\nalways safe to assume that a (png_struct*) has to be passed to call an API\nfunction.\n\nYou can have more than one png_info structure associated with an image,\nas illustrated in pngtest.c, one for information valid prior to the\nIDAT chunks and another (called \"end_info\" below) for things after them.\n\nThe png.h header file is an invaluable reference for programming with libpng.\nAnd while I'm on the topic, make sure you include the libpng header file:\n\n#include <png.h>\n\nand also (as of libpng-1.5.0) the zlib header file, if you need it:\n\n#include <zlib.h>\n\nTypes\n\nThe png.h header file defines a number of integral types used by the\nAPIs.  Most of these are fairly obvious; for example types corresponding\nto integers of particular sizes and types for passing color values.\n\nOne exception is how non-integral numbers are handled.  For application\nconvenience most APIs that take such numbers have C (double) arguments;\nhowever, internally PNG, and libpng, use 32 bit signed integers and encode\nthe value by multiplying by 100,000.  As of libpng 1.5.0 a convenience\nmacro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)\nwhich is simply (png_int_32).\n\nAll APIs that take (double) arguments also have a matching API that\ntakes the corresponding fixed point integer arguments.  The fixed point\nAPI has the same name as the floating point one with \"_fixed\" appended.\nThe actual range of values permitted in the APIs is frequently less than\nthe full range of (png_fixed_point) (-21474 to +21474).  When APIs require\na non-negative argument the type is recorded as png_uint_32 above.  Consult\nthe header file and the text below for more information.\n\nSpecial care must be take with sCAL chunk handling because the chunk itself\nuses non-integral values encoded as strings containing decimal floating point\nnumbers.  See the comments in the header file.\n\nConfiguration\n\nThe main header file function declarations are frequently protected by C\npreprocessing directives of the form:\n\n    #ifdef PNG_feature_SUPPORTED\n    declare-function\n    #endif\n    ...\n    #ifdef PNG_feature_SUPPORTED\n    use-function\n    #endif\n\nThe library can be built without support for these APIs, although a\nstandard build will have all implemented APIs.  Application programs\nshould check the feature macros before using an API for maximum\nportability.  From libpng 1.5.0 the feature macros set during the build\nof libpng are recorded in the header file \"pnglibconf.h\" and this file\nis always included by png.h.\n\nIf you don't need to change the library configuration from the default, skip to\nthe next section (\"Reading\").\n\nNotice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all\nof the build project files in the 'projects' directory simply copy\nscripts/pnglibconf.h.prebuilt to pnglibconf.h.  This means that these build\nsystems do not permit easy auto-configuration of the library - they only\nsupport the default configuration.\n\nThe easiest way to make minor changes to the libpng configuration when\nauto-configuration is supported is to add definitions to the command line\nusing (typically) CPPFLAGS.  For example:\n\nCPPFLAGS=-DPNG_NO_FLOATING_ARITHMETIC\n\nwill change the internal libpng math implementation for gamma correction and\nother arithmetic calculations to fixed point, avoiding the need for fast\nfloating point support.  The result can be seen in the generated pnglibconf.h -\nmake sure it contains the changed feature macro setting.\n\nIf you need to make more extensive configuration changes - more than one or two\nfeature macro settings - you can either add -DPNG_USER_CONFIG to the build\ncommand line and put a list of feature macro settings in pngusr.h or you can set\nDFA_XTRA (a makefile variable) to a file containing the same information in the\nform of 'option' settings.\n\nA. Changing pnglibconf.h\n\nA variety of methods exist to build libpng.  Not all of these support\nreconfiguration of pnglibconf.h.  To reconfigure pnglibconf.h it must either be\nrebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.\n\nHand editing is achieved by copying scripts/pnglibconf.h.prebuilt to\npnglibconf.h and changing the lines defining the supported features, paying\nvery close attention to the 'option' information in scripts/pnglibconf.dfa\nthat describes those features and their requirements.  This is easy to get\nwrong.\n\nB. Configuration using DFA_XTRA\n\nRebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later\nvariant such as 'nawk' or 'gawk', is available.  The configure build will\nautomatically find an appropriate awk and build pnglibconf.h.\nThe scripts/pnglibconf.mak file contains a set of make rules for doing the\nsame thing if configure is not used, and many of the makefiles in the scripts\ndirectory use this approach.\n\nWhen rebuilding simply write a new file containing changed options and set\nDFA_XTRA to the name of this file.  This causes the build to append the new file\nto the end of scripts/pnglibconf.dfa.  The pngusr.dfa file should contain lines\nof the following forms:\n\neverything = off\n\nThis turns all optional features off.  Include it at the start of pngusr.dfa to\nmake it easier to build a minimal configuration.  You will need to turn at least\nsome features on afterward to enable either reading or writing code, or both.\n\noption feature on\noption feature off\n\nEnable or disable a single feature.  This will automatically enable other\nfeatures required by a feature that is turned on or disable other features that\nrequire a feature which is turned off.  Conflicting settings will cause an error\nmessage to be emitted by awk.\n\nsetting feature default value\n\nChanges the default value of setting 'feature' to 'value'.  There are a small\nnumber of settings listed at the top of pnglibconf.h, they are documented in the\nsource code.  Most of these values have performance implications for the library\nbut most of them have no visible effect on the API.  Some can also be overridden\nfrom the API.\n\nThis method of building a customized pnglibconf.h is illustrated in\ncontrib/pngminim/*.  See the \"$(PNGCONF):\" target in the makefile and\npngusr.dfa in these directories.\n\nC. Configuration using PNG_USER_CONFIG\n\nIf -DPNG_USER_CONFIG is added to the CPPFLAGS when pnglibconf.h is built,\nthe file pngusr.h will automatically be included before the options in\nscripts/pnglibconf.dfa are processed.  Your pngusr.h file should contain only\nmacro definitions turning features on or off or setting settings.\n\nApart from the global setting \"everything = off\" all the options listed above\ncan be set using macros in pngusr.h:\n\n#define PNG_feature_SUPPORTED\n\nis equivalent to:\n\noption feature on\n\n#define PNG_NO_feature\n\nis equivalent to:\n\noption feature off\n\n#define PNG_feature value\n\nis equivalent to:\n\nsetting feature default value\n\nNotice that in both cases, pngusr.dfa and pngusr.h, the contents of the\npngusr file you supply override the contents of scripts/pnglibconf.dfa\n\nIf confusing or incomprehensible behavior results it is possible to\nexamine the intermediate file pnglibconf.dfn to find the full set of\ndependency information for each setting and option.  Simply locate the\nfeature in the file and read the C comments that precede it.\n\nThis method is also illustrated in the contrib/pngminim/* makefiles and\npngusr.h.\n\nIII. Reading\n\nWe'll now walk you through the possible functions to call when reading\nin a PNG file sequentially, briefly explaining the syntax and purpose\nof each one.  See example.c and png.h for more detail.  While\nprogressive reading is covered in the next section, you will still\nneed some of the functions discussed in this section to read a PNG\nfile.\n\nSetup\n\nYou will want to do the I/O initialization(*) before you get into libpng,\nso if it doesn't work, you don't have much to undo.  Of course, you\nwill also want to insure that you are, in fact, dealing with a PNG\nfile.  Libpng provides a simple check to see if a file is a PNG file.\nTo use it, pass in the first 1 to 8 bytes of the file to the function\npng_sig_cmp(), and it will return 0 (false) if the bytes match the\ncorresponding bytes of the PNG signature, or nonzero (true) otherwise.\nOf course, the more bytes you pass in, the greater the accuracy of the\nprediction.\n\nIf you are intending to keep the file pointer open for use in libpng,\nyou must ensure you don't read more than 8 bytes from the beginning\nof the file, and you also have to make a call to png_set_sig_bytes()\nwith the number of bytes you read from the beginning.  Libpng will\nthen only check the bytes (if any) that your program didn't read.\n\n(*): If you are not using the standard I/O functions, you will need\nto replace them with custom functions.  See the discussion under\nCustomizing libpng.\n\n    FILE *fp = fopen(file_name, \"rb\");\n    if (!fp)\n    {\n       return (ERROR);\n    }\n\n    if (fread(header, 1, number, fp) != number)\n    {\n       return (ERROR);\n    }\n\n    is_png = !png_sig_cmp(header, 0, number);\n    if (!is_png)\n    {\n       return (NOT_PNG);\n    }\n\nNext, png_struct and png_info need to be allocated and initialized.  In\norder to ensure that the size of these structures is correct even with a\ndynamically linked libpng, there are functions to initialize and\nallocate the structures.  We also pass the library version, optional\npointers to error handling functions, and a pointer to a data struct for\nuse by the error functions, if necessary (the pointer and functions can\nbe NULL if the default error handlers are to be used).  See the section\non Changes to Libpng below regarding the old initialization functions.\nThe structure allocation functions quietly return NULL if they fail to\ncreate the structure, so your application should check for that.\n\n    png_structp png_ptr = png_create_read_struct\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n       return (ERROR);\n\n    png_infop info_ptr = png_create_info_struct(png_ptr);\n\n    if (!info_ptr)\n    {\n       png_destroy_read_struct(&png_ptr,\n           (png_infopp)NULL, (png_infopp)NULL);\n       return (ERROR);\n    }\n\nIf you want to use your own memory allocation routines,\nuse a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use\npng_create_read_struct_2() instead of png_create_read_struct():\n\n    png_structp png_ptr = png_create_read_struct_2\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn, (png_voidp)\n        user_mem_ptr, user_malloc_fn, user_free_fn);\n\nThe error handling routines passed to png_create_read_struct()\nand the memory alloc/free routines passed to png_create_struct_2()\nare only necessary if you are not using the libpng supplied error\nhandling and memory alloc/free functions.\n\nWhen libpng encounters an error, it expects to longjmp back\nto your routine.  Therefore, you will need to call setjmp and pass\nyour png_jmpbuf(png_ptr).  If you read the file from different\nroutines, you will need to update the longjmp buffer every time you enter\na new routine that will call a png_*() function.\n\nSee your documentation of setjmp/longjmp for your compiler for more\ninformation on setjmp/longjmp.  See the discussion on libpng error\nhandling in the Customizing Libpng section below for more information\non the libpng error handling.  If an error occurs, and libpng longjmp's\nback to your setjmp, you will want to call png_destroy_read_struct() to\nfree any memory.\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           &end_info);\n       fclose(fp);\n       return (ERROR);\n    }\n\nPass (png_infopp)NULL instead of &end_info if you didn't create\nan end_info structure.\n\nIf you would rather avoid the complexity of setjmp/longjmp issues,\nyou can compile libpng with PNG_NO_SETJMP, in which case\nerrors will result in a call to PNG_ABORT() which defaults to abort().\n\nYou can #define PNG_ABORT() to a function that does something\nmore useful than abort(), as long as your function does not\nreturn.\n\nNow you need to set up the input code.  The default for libpng is to\nuse the C function fread().  If you use this, you will need to pass a\nvalid FILE * in the function png_init_io().  Be sure that the file is\nopened in binary mode.  If you wish to handle reading data in another\nway, you need not call the png_init_io() function, but you must then\nimplement the libpng I/O methods discussed in the Customizing Libpng\nsection below.\n\n    png_init_io(png_ptr, fp);\n\nIf you had previously opened the file and read any of the signature from\nthe beginning in order to see if this was a PNG file, you need to let\nlibpng know that there are some bytes missing from the start of the file.\n\n    png_set_sig_bytes(png_ptr, number);\n\nYou can change the zlib compression buffer size to be used while\nreading compressed data with\n\n    png_set_compression_buffer_size(png_ptr, buffer_size);\n\nwhere the default size is 8192 bytes.  Note that the buffer size\nis changed immediately and the buffer is reallocated immediately,\ninstead of setting a flag to be acted upon later.\n\nIf you want CRC errors to be handled in a different manner than\nthe default, use\n\n    png_set_crc_action(png_ptr, crit_action, ancil_action);\n\nThe values for png_set_crc_action() say how libpng is to handle CRC errors in\nancillary and critical chunks, and whether to use the data contained\ntherein.  Note that it is impossible to \"discard\" data in a critical\nchunk.\n\nChoices for (int) crit_action are\n   PNG_CRC_DEFAULT      0  error/quit\n   PNG_CRC_ERROR_QUIT   1  error/quit\n   PNG_CRC_WARN_USE     3  warn/use data\n   PNG_CRC_QUIET_USE    4  quiet/use data\n   PNG_CRC_NO_CHANGE    5  use the current value\n\nChoices for (int) ancil_action are\n   PNG_CRC_DEFAULT      0  error/quit\n   PNG_CRC_ERROR_QUIT   1  error/quit\n   PNG_CRC_WARN_DISCARD 2  warn/discard data\n   PNG_CRC_WARN_USE     3  warn/use data\n   PNG_CRC_QUIET_USE    4  quiet/use data\n   PNG_CRC_NO_CHANGE    5  use the current value\n\nSetting up callback code\n\nYou can set up a callback function to handle any unknown chunks in the\ninput stream. You must supply the function\n\n    read_chunk_callback(png_structp png_ptr,\n         png_unknown_chunkp chunk);\n    {\n       /* The unknown chunk structure contains your\n          chunk data, along with similar data for any other\n          unknown chunks: */\n\n           png_byte name[5];\n           png_byte *data;\n           png_size_t size;\n\n       /* Note that libpng has already taken care of\n          the CRC handling */\n\n       /* put your code here.  Search for your chunk in the\n          unknown chunk structure, process it, and return one\n          of the following: */\n\n       return (-n); /* chunk had an error */\n       return (0); /* did not recognize */\n       return (n); /* success */\n    }\n\n(You can give your function another name that you like instead of\n\"read_chunk_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,\n        read_chunk_callback);\n\nThis names not only the callback function, but also a user pointer that\nyou can retrieve with\n\n    png_get_user_chunk_ptr(png_ptr);\n\nIf you call the png_set_read_user_chunk_fn() function, then all unknown\nchunks which the callback does not handle will be saved when read.  You can\ncause them to be discarded by returning '1' (\"handled\") instead of '0'.  This\nbehavior will change in libpng 1.7 and the default handling set by the\npng_set_keep_unknown_chunks() function, described below, will be used when the\ncallback returns 0.  If you want the existing behavior you should set the global\ndefault to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current\nversions of libpng and with 1.7.  Libpng 1.6 issues a warning if you keep the\ndefault, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.\n\nAt this point, you can set up a callback function that will be\ncalled after each row has been read, which you can use to control\na progress meter or the like.  It's demonstrated in pngtest.c.\nYou must supply a function\n\n    void read_row_callback(png_structp png_ptr,\n       png_uint_32 row, int pass);\n    {\n      /* put your code here */\n    }\n\n(You can give it another name that you like instead of \"read_row_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_read_status_fn(png_ptr, read_row_callback);\n\nWhen this function is called the row has already been completely processed and\nthe 'row' and 'pass' refer to the next row to be handled.  For the\nnon-interlaced case the row that was just handled is simply one less than the\npassed in row number, and pass will always be 0.  For the interlaced case the\nsame applies unless the row value is 0, in which case the row just handled was\nthe last one from one of the preceding passes.  Because interlacing may skip a\npass you cannot be sure that the preceding pass is just 'pass-1'; if you really\nneed to know what the last pass is record (row,pass) from the callback and use\nthe last recorded value each time.\n\nAs with the user transform you can find the output row using the\nPNG_ROW_FROM_PASS_ROW macro.\n\nUnknown-chunk handling\n\nNow you get to set the way the library processes unknown chunks in the\ninput PNG stream. Both known and unknown chunks will be read.  Normal\nbehavior is that known chunks will be parsed into information in\nvarious info_ptr members while unknown chunks will be discarded. This\nbehavior can be wasteful if your application will never use some known\nchunk types. To change this, you can call:\n\n    png_set_keep_unknown_chunks(png_ptr, keep,\n        chunk_list, num_chunks);\n\n    keep       - 0: default unknown chunk handling\n                 1: ignore; do not keep\n                 2: keep only if safe-to-copy\n                 3: keep even if unsafe-to-copy\n\n               You can use these definitions:\n                 PNG_HANDLE_CHUNK_AS_DEFAULT   0\n                 PNG_HANDLE_CHUNK_NEVER        1\n                 PNG_HANDLE_CHUNK_IF_SAFE      2\n                 PNG_HANDLE_CHUNK_ALWAYS       3\n\n    chunk_list - list of chunks affected (a byte string,\n                 five bytes per chunk, NULL or '\\0' if\n                 num_chunks is positive; ignored if\n                 numchunks <= 0).\n\n    num_chunks - number of chunks affected; if 0, all\n                 unknown chunks are affected.  If positive,\n                 only the chunks in the list are affected,\n                 and if negative all unknown chunks and\n                 all known chunks except for the IHDR,\n                 PLTE, tRNS, IDAT, and IEND chunks are\n                 affected.\n\nUnknown chunks declared in this way will be saved as raw data onto a\nlist of png_unknown_chunk structures.  If a chunk that is normally\nknown to libpng is named in the list, it will be handled as unknown,\naccording to the \"keep\" directive.  If a chunk is named in successive\ninstances of png_set_keep_unknown_chunks(), the final instance will\ntake precedence.  The IHDR and IEND chunks should not be named in\nchunk_list; if they are, libpng will process them normally anyway.\nIf you know that your application will never make use of some particular\nchunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.\n\nHere is an example of the usage of png_set_keep_unknown_chunks(),\nwhere the private \"vpAg\" chunk will later be processed by a user chunk\ncallback function:\n\n    png_byte vpAg[5]={118, 112,  65, 103, (png_byte) '\\0'};\n\n    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)\n      png_byte unused_chunks[]=\n      {\n        104,  73,  83,  84, (png_byte) '\\0',   /* hIST */\n        105,  84,  88, 116, (png_byte) '\\0',   /* iTXt */\n        112,  67,  65,  76, (png_byte) '\\0',   /* pCAL */\n        115,  67,  65,  76, (png_byte) '\\0',   /* sCAL */\n        115,  80,  76,  84, (png_byte) '\\0',   /* sPLT */\n        116,  73,  77,  69, (png_byte) '\\0',   /* tIME */\n      };\n    #endif\n\n    ...\n\n    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)\n      /* ignore all unknown chunks\n       * (use global setting \"2\" for libpng16 and earlier):\n       */\n      png_set_keep_unknown_chunks(read_ptr, 2, NULL, 0);\n\n      /* except for vpAg: */\n      png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);\n\n      /* also ignore unused known chunks: */\n      png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,\n         (int)(sizeof unused_chunks)/5);\n    #endif\n\nUser limits\n\nThe PNG specification allows the width and height of an image to be as\nlarge as 2^31-1 (0x7fffffff), or about 2.147 billion rows and columns.\nFor safety, libpng imposes a default limit of 1 million rows and columns.\nLarger images will be rejected immediately with a png_error() call. If\nyou wish to change these limits, you can use\n\n   png_set_user_limits(png_ptr, width_max, height_max);\n\nto set your own limits (libpng may reject some very wide images\nanyway because of potential buffer overflow conditions).\n\nYou should put this statement after you create the PNG structure and\nbefore calling png_read_info(), png_read_png(), or png_process_data().\n\nWhen writing a PNG datastream, put this statement before calling\npng_write_info() or png_write_png().\n\nIf you need to retrieve the limits that are being applied, use\n\n   width_max = png_get_user_width_max(png_ptr);\n   height_max = png_get_user_height_max(png_ptr);\n\nThe PNG specification sets no limit on the number of ancillary chunks\nallowed in a PNG datastream.  By default, libpng imposes a limit of\na total of 1000 sPLT, tEXt, iTXt, zTXt, and unknown chunks to be stored.\nIf you have set up both info_ptr and end_info_ptr, the limit applies\nseparately to each.  You can change the limit on the total number of such\nchunks that will be stored, with\n\n   png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);\n\nwhere 0x7fffffffL means unlimited.  You can retrieve this limit with\n\n   chunk_cache_max = png_get_chunk_cache_max(png_ptr);\n\nLibpng imposes a limit of 8 Megabytes (8,000,000 bytes) on the amount of\nmemory that a compressed chunk other than IDAT can occupy, when decompressed.\nYou can change this limit with\n\n   png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);\n\nand you can retrieve the limit with\n\n   chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);\n\nAny chunks that would cause either of these limits to be exceeded will\nbe ignored.\n\nInformation about your system\n\nIf you intend to display the PNG or to incorporate it in other image data you\nneed to tell libpng information about your display or drawing surface so that\nlibpng can convert the values in the image to match the display.\n\nFrom libpng-1.5.4 this information can be set before reading the PNG file\nheader.  In earlier versions png_set_gamma() existed but behaved incorrectly if\ncalled before the PNG file header had been read and png_set_alpha_mode() did not\nexist.\n\nIf you need to support versions prior to libpng-1.5.4 test the version number\nas illustrated below using \"PNG_LIBPNG_VER >= 10504\" and follow the procedures\ndescribed in the appropriate manual page.\n\nYou give libpng the encoding expected by your system expressed as a 'gamma'\nvalue.  You can also specify a default encoding for the PNG file in\ncase the required information is missing from the file.  By default libpng\nassumes that the PNG data matches your system, to keep this default call:\n\n   png_set_gamma(png_ptr, screen_gamma, output_gamma);\n\nor you can use the fixed point equivalent:\n\n   png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma,\n      PNG_FP_1*output_gamma);\n\nIf you don't know the gamma for your system it is probably 2.2 - a good\napproximation to the IEC standard for display systems (sRGB).  If images are\ntoo contrasty or washed out you got the value wrong - check your system\ndocumentation!\n\nMany systems permit the system gamma to be changed via a lookup table in the\ndisplay driver, a few systems, including older Macs, change the response by\ndefault.  As of 1.5.4 three special values are available to handle common\nsituations:\n\n   PNG_DEFAULT_sRGB: Indicates that the system conforms to the\n                     IEC 61966-2-1 standard.  This matches almost\n                     all systems.\n   PNG_GAMMA_MAC_18: Indicates that the system is an older\n                     (pre Mac OS 10.6) Apple Macintosh system with\n                     the default settings.\n   PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates\n                     that the system expects data with no gamma\n                     encoding.\n\nYou would use the linear (unencoded) value if you need to process the pixel\nvalues further because this avoids the need to decode and re-encode each\ncomponent value whenever arithmetic is performed.  A lot of graphics software\nuses linear values for this reason, often with higher precision component values\nto preserve overall accuracy.\n\n\nThe output_gamma value expresses how to decode the output values, not how\nthey are encoded.  The values used correspond to the normal numbers used to\ndescribe the overall gamma of a computer display system; for example 2.2 for\nan sRGB conformant system.  The values are scaled by 100000 in the _fixed\nversion of the API (so 220000 for sRGB.)\n\nThe inverse of the value is always used to provide a default for the PNG file\nencoding if it has no gAMA chunk and if png_set_gamma() has not been called\nto override the PNG gamma information.\n\nWhen the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode\nopaque pixels however pixels with lower alpha values are not encoded,\nregardless of the output gamma setting.\n\nWhen the standard Porter Duff handling is requested with mode 1 the output\nencoding is set to be linear and the output_gamma value is only relevant\nas a default for input data that has no gamma information.  The linear output\nencoding will be overridden if png_set_gamma() is called - the results may be\nhighly unexpected!\n\nThe following numbers are derived from the sRGB standard and the research\nbehind it.  sRGB is defined to be approximated by a PNG gAMA chunk value of\n0.45455 (1/2.2) for PNG.  The value implicitly includes any viewing\ncorrection required to take account of any differences in the color\nenvironment of the original scene and the intended display environment; the\nvalue expresses how to *decode* the image for display, not how the original\ndata was *encoded*.\n\nsRGB provides a peg for the PNG standard by defining a viewing environment.\nsRGB itself, and earlier TV standards, actually use a more complex transform\n(a linear portion then a gamma 2.4 power law) than PNG can express.  (PNG is\nlimited to simple power laws.)  By saying that an image for direct display on\nan sRGB conformant system should be stored with a gAMA chunk value of 45455\n(11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification\nmakes it possible to derive values for other display systems and\nenvironments.\n\nThe Mac value is deduced from the sRGB based on an assumption that the actual\nextra viewing correction used in early Mac display systems was implemented as\na power 1.45 lookup table.\n\nAny system where a programmable lookup table is used or where the behavior of\nthe final display device characteristics can be changed requires system\nspecific code to obtain the current characteristic.  However this can be\ndifficult and most PNG gamma correction only requires an approximate value.\n\nBy default, if png_set_alpha_mode() is not called, libpng assumes that all\nvalues are unencoded, linear, values and that the output device also has a\nlinear characteristic.  This is only very rarely correct - it is invariably\nbetter to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the\ndefault if you don't know what the right answer is!\n\nThe special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS\n10.6) which used a correction table to implement a somewhat lower gamma on an\notherwise sRGB system.\n\nBoth these values are reserved (not simple gamma values) in order to allow\nmore precise correction internally in the future.\n\nNOTE: the values can be passed to either the fixed or floating\npoint APIs, but the floating point API will also accept floating point\nvalues.\n\nThe second thing you may need to tell libpng about is how your system handles\nalpha channel information.  Some, but not all, PNG files contain an alpha\nchannel.  To display these files correctly you need to compose the data onto a\nsuitable background, as described in the PNG specification.\n\nLibpng only supports composing onto a single color (using png_set_background;\nsee below).  Otherwise you must do the composition yourself and, in this case,\nyou may need to call png_set_alpha_mode:\n\n   #if PNG_LIBPNG_VER >= 10504\n      png_set_alpha_mode(png_ptr, mode, screen_gamma);\n   #else\n      png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);\n   #endif\n\nThe screen_gamma value is the same as the argument to png_set_gamma; however,\nhow it affects the output depends on the mode.  png_set_alpha_mode() sets the\nfile gamma default to 1/screen_gamma, so normally you don't need to call\npng_set_gamma.  If you need different defaults call png_set_gamma() before\npng_set_alpha_mode() - if you call it after it will override the settings made\nby png_set_alpha_mode().\n\nThe mode is as follows:\n\n    PNG_ALPHA_PNG: The data is encoded according to the PNG\nspecification.  Red, green and blue, or gray, components are\ngamma encoded color values and are not premultiplied by the\nalpha value.  The alpha value is a linear measure of the\ncontribution of the pixel to the corresponding final output pixel.\n\nYou should normally use this format if you intend to perform\ncolor correction on the color values; most, maybe all, color\ncorrection software has no handling for the alpha channel and,\nanyway, the math to handle pre-multiplied component values is\nunnecessarily complex.\n\nBefore you do any arithmetic on the component values you need\nto remove the gamma encoding and multiply out the alpha\nchannel.  See the PNG specification for more detail.  It is\nimportant to note that when an image with an alpha channel is\nscaled, linear encoded, pre-multiplied component values must\nbe used!\n\nThe remaining modes assume you don't need to do any further color correction or\nthat if you do, your color correction software knows all about alpha (it\nprobably doesn't!).  They 'associate' the alpha with the color information by\nstoring color channel values that have been scaled by the alpha.  The\nadvantage is that the color channels can be resampled (the image can be\nscaled) in this form.  The disadvantage is that normal practice is to store\nlinear, not (gamma) encoded, values and this requires 16-bit channels for\nstill images rather than the 8-bit channels that are just about sufficient if\ngamma encoding is used.  In addition all non-transparent pixel values,\nincluding completely opaque ones, must be gamma encoded to produce the final\nimage.  These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes\ndescribed below (the latter being the two common names for associated alpha\ncolor channels). Note that PNG files always contain non-associated color\nchannels; png_set_alpha_mode() with one of the modes causes the decoder to\nconvert the pixels to an associated form before returning them to your\napplication. \n\nSince it is not necessary to perform arithmetic on opaque color values so\nlong as they are not to be resampled and are in the final color space it is\npossible to optimize the handling of alpha by storing the opaque pixels in\nthe PNG format (adjusted for the output color space) while storing partially\nopaque pixels in the standard, linear, format.  The accuracy required for\nstandard alpha composition is relatively low, because the pixels are\nisolated, therefore typically the accuracy loss in storing 8-bit linear\nvalues is acceptable.  (This is not true if the alpha channel is used to\nsimulate transparency over large areas - use 16 bits or the PNG mode in\nthis case!)  This is the 'OPTIMIZED' mode.  For this mode a pixel is\ntreated as opaque only if the alpha value is equal to the maximum value.\n\n    PNG_ALPHA_STANDARD:  The data libpng produces is encoded in the\nstandard way assumed by most correctly written graphics software.\nThe gamma encoding will be removed by libpng and the\nlinear component values will be pre-multiplied by the\nalpha channel.\n\nWith this format the final image must be re-encoded to\nmatch the display gamma before the image is displayed.\nIf your system doesn't do that, yet still seems to\nperform arithmetic on the pixels without decoding them,\nit is broken - check out the modes below.\n\nWith PNG_ALPHA_STANDARD libpng always produces linear\ncomponent values, whatever screen_gamma you supply.  The\nscreen_gamma value is, however, used as a default for\nthe file gamma if the PNG file has no gamma information.\n\nIf you call png_set_gamma() after png_set_alpha_mode() you\nwill override the linear encoding.  Instead the\npre-multiplied pixel values will be gamma encoded but\nthe alpha channel will still be linear.  This may\nactually match the requirements of some broken software,\nbut it is unlikely.\n\nWhile linear 8-bit data is often used it has\ninsufficient precision for any image with a reasonable\ndynamic range.  To avoid problems, and if your software\nsupports it, use png_set_expand_16() to force all\ncomponents to 16 bits.\n\n    PNG_ALPHA_OPTIMIZED: This mode is the same as PNG_ALPHA_STANDARD\nexcept that completely opaque pixels are gamma encoded according to\nthe screen_gamma value.  Pixels with alpha less than 1.0\nwill still have linear components.\n\nUse this format if you have control over your\ncompositing software and so don't do other arithmetic\n(such as scaling) on the data you get from libpng.  Your\ncompositing software can simply copy opaque pixels to\nthe output but still has linear values for the\nnon-opaque pixels.\n\nIn normal compositing, where the alpha channel encodes\npartial pixel coverage (as opposed to broad area\ntranslucency), the inaccuracies of the 8-bit\nrepresentation of non-opaque pixels are irrelevant.\n\nYou can also try this format if your software is broken;\nit might look better.\n\n    PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; however, all component\nvalues, including the alpha channel are gamma encoded.  This is\nbroken because, in practice, no implementation that uses this choice\ncorrectly undoes the encoding before handling alpha composition.  Use this\nchoice only if other serious errors in the software or hardware you use\nmandate it.  In most cases of broken software or hardware the bug in the\nfinal display manifests as a subtle halo around composited parts of the\nimage.  You may not even perceive this as a halo; the composited part of\nthe image may simply appear separate from the background, as though it had\nbeen cut out of paper and pasted on afterward.\n\nIf you don't have to deal with bugs in software or hardware, or if you can fix\nthem, there are three recommended ways of using png_set_alpha_mode():\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,\n       screen_gamma);\n\nYou can do color correction on the result (libpng does not currently\nsupport color correction internally).  When you handle the alpha channel\nyou need to undo the gamma encoding and multiply out the alpha.\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,\n       screen_gamma);\n   png_set_expand_16(png_ptr);\n\nIf you are using the high level interface, don't call png_set_expand_16();\ninstead pass PNG_TRANSFORM_EXPAND_16 to the interface.\n\nWith this mode you can't do color correction, but you can do arithmetic,\nincluding composition and scaling, on the data without further processing.\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,\n       screen_gamma);\n\nYou can avoid the expansion to 16-bit components with this mode, but you\nlose the ability to scale the image or perform other linear arithmetic.\nAll you can do is compose the result onto a matching output.  Since this\nmode is libpng-specific you also need to write your own composition\nsoftware.\n\nThe following are examples of calls to png_set_alpha_mode to achieve the\nrequired overall gamma correction and, where necessary, alpha\npremultiplication.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n\nThis is the default libpng handling of the alpha channel - it is not\npre-multiplied into the color components.  In addition the call states\nthat the output is for a sRGB system and causes all PNG files without gAMA\nchunks to be assumed to be encoded using sRGB.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n\nIn this case the output is assumed to be something like an sRGB conformant\ndisplay preceeded by a power-law lookup table of power 1.45.  This is how\nearly Mac systems behaved.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);\n\nThis is the classic Jim Blinn approach and will work in academic\nenvironments where everything is done by the book.  It has the shortcoming\nof assuming that input PNG data with no gamma information is linear - this\nis unlikely to be correct unless the PNG files where generated locally.\nMost of the time the output precision will be so low as to show\nsignificant banding in dark areas of the image.\n\n    png_set_expand_16(pp);\n    png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);\n\nThis is a somewhat more realistic Jim Blinn inspired approach.  PNG files\nare assumed to have the sRGB encoding if not marked with a gamma value and\nthe output is always 16 bits per component.  This permits accurate scaling\nand processing of the data.  If you know that your input PNG files were\ngenerated locally you might need to replace PNG_DEFAULT_sRGB with the\ncorrect value for your system.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);\n\nIf you just need to composite the PNG image onto an existing background\nand if you control the code that does this you can use the optimization\nsetting.  In this case you just copy completely opaque pixels to the\noutput.  For pixels that are not completely transparent (you just skip\nthose) you do the composition math using png_composite or png_composite_16\nbelow then encode the resultant 8-bit or 16-bit values to match the output\nencoding.\n\n    Other cases\n\nIf neither the PNG nor the standard linear encoding work for you because\nof the software or hardware you use then you have a big problem.  The PNG\ncase will probably result in halos around the image.  The linear encoding\nwill probably result in a washed out, too bright, image (it's actually too\ncontrasty.)  Try the ALPHA_OPTIMIZED mode above - this will probably\nsubstantially reduce the halos.  Alternatively try:\n\n    png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);\n\nThis option will also reduce the halos, but there will be slight dark\nhalos round the opaque parts of the image where the background is light.\nIn the OPTIMIZED mode the halos will be light halos where the background\nis dark.  Take your pick - the halos are unavoidable unless you can get\nyour hardware/software fixed!  (The OPTIMIZED approach is slightly\nfaster.)\n\nWhen the default gamma of PNG files doesn't match the output gamma.\nIf you have PNG files with no gamma information png_set_alpha_mode allows\nyou to provide a default gamma, but it also sets the ouput gamma to the\nmatching value.  If you know your PNG files have a gamma that doesn't\nmatch the output you can take advantage of the fact that\npng_set_alpha_mode always sets the output gamma but only sets the PNG\ndefault if it is not already set:\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n\nThe first call sets both the default and the output gamma values, the\nsecond call overrides the output gamma without changing the default.  This\nis easier than achieving the same effect with png_set_gamma.  You must use\nPNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will\nfire if more than one call to png_set_alpha_mode and png_set_background is\nmade in the same read operation, however multiple calls with PNG_ALPHA_PNG\nare ignored.\n\nIf you don't need, or can't handle, the alpha channel you can call\npng_set_background() to remove it by compositing against a fixed color.  Don't\ncall png_set_strip_alpha() to do this - it will leave spurious pixel values in\ntransparent parts of this image.\n\n   png_set_background(png_ptr, &background_color,\n       PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);\n\nThe background_color is an RGB or grayscale value according to the data format\nlibpng will produce for you.  Because you don't yet know the format of the PNG\nfile, if you call png_set_background at this point you must arrange for the\nformat produced by libpng to always have 8-bit or 16-bit components and then\nstore the color as an 8-bit or 16-bit color as appropriate.  The color contains\nseparate gray and RGB component values, so you can let libpng produce gray or\nRGB output according to the input format, but low bit depth grayscale images\nmust always be converted to at least 8-bit format.  (Even though low bit depth\ngrayscale images can't have an alpha channel they can have a transparent\ncolor!)\n\nYou set the transforms you need later, either as flags to the high level\ninterface or libpng API calls for the low level interface.  For reference the\nsettings and API calls required are:\n\n8-bit values:\n   PNG_TRANSFORM_SCALE_16 | PNG_EXPAND\n   png_set_expand(png_ptr); png_set_scale_16(png_ptr);\n\n   If you must get exactly the same inaccurate results\n   produced by default in versions prior to libpng-1.5.4,\n   use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)\n   instead.\n\n16-bit values:\n   PNG_TRANSFORM_EXPAND_16\n   png_set_expand_16(png_ptr);\n\nIn either case palette image data will be expanded to RGB.  If you just want\ncolor data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)\nto the list.\n\nCalling png_set_background before the PNG file header is read will not work\nprior to libpng-1.5.4.  Because the failure may result in unexpected warnings or\nerrors it is therefore much safer to call png_set_background after the head has\nbeen read.  Unfortunately this means that prior to libpng-1.5.4 it cannot be\nused with the high level interface.\n\nThe high-level read interface\n\nAt this point there are two ways to proceed; through the high-level\nread interface, or through a sequence of low-level read operations.\nYou can use the high-level interface if (a) you are willing to read\nthe entire image into memory, and (b) the input transformations\nyou want to do are limited to the following set:\n\n    PNG_TRANSFORM_IDENTITY      No transformation\n    PNG_TRANSFORM_SCALE_16      Strip 16-bit samples to\n                                8-bit accurately\n    PNG_TRANSFORM_STRIP_16      Chop 16-bit samples to\n                                8-bit less accurately\n    PNG_TRANSFORM_STRIP_ALPHA   Discard the alpha channel\n    PNG_TRANSFORM_PACKING       Expand 1, 2 and 4-bit\n                                samples to bytes\n    PNG_TRANSFORM_PACKSWAP      Change order of packed\n                                pixels to LSB first\n    PNG_TRANSFORM_EXPAND        Perform set_expand()\n    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images\n    PNG_TRANSFORM_SHIFT         Normalize pixels to the\n                                sBIT depth\n    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA\n                                to BGRA\n    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA\n                                to AG\n    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity\n                                to transparency\n    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples\n    PNG_TRANSFORM_GRAY_TO_RGB   Expand grayscale samples\n                                to RGB (or GA to RGBA)\n    PNG_TRANSFORM_EXPAND_16     Expand samples to 16 bits\n\n(This excludes setting a background color, doing gamma transformation,\nquantizing, and setting filler.)  If this is the case, simply do this:\n\n    png_read_png(png_ptr, info_ptr, png_transforms, NULL)\n\nwhere png_transforms is an integer containing the bitwise OR of some\nset of transformation flags.  This call is equivalent to png_read_info(),\nfollowed the set of transformations indicated by the transform mask,\nthen png_read_image(), and finally png_read_end().\n\n(The final parameter of this call is not yet used.  Someday it might point\nto transformation parameters required by some future input transform.)\n\nYou must use png_transforms and not call any png_set_transform() functions\nwhen you use png_read_png().\n\nAfter you have called png_read_png(), you can retrieve the image data\nwith\n\n   row_pointers = png_get_rows(png_ptr, info_ptr);\n\nwhere row_pointers is an array of pointers to the pixel data for each row:\n\n   png_bytep row_pointers[height];\n\nIf you know your image size and pixel size ahead of time, you can allocate\nrow_pointers prior to calling png_read_png() with\n\n   if (height > PNG_UINT_32_MAX/(sizeof (png_byte)))\n      png_error (png_ptr,\n          \"Image is too tall to process in memory\");\n\n   if (width > PNG_UINT_32_MAX/pixel_size)\n      png_error (png_ptr,\n          \"Image is too wide to process in memory\");\n\n   row_pointers = png_malloc(png_ptr,\n       height*(sizeof (png_bytep)));\n\n   for (int i=0; i<height, i++)\n      row_pointers[i]=NULL;  /* security precaution */\n\n   for (int i=0; i<height, i++)\n      row_pointers[i]=png_malloc(png_ptr,\n          width*pixel_size);\n\n   png_set_rows(png_ptr, info_ptr, &row_pointers);\n\nAlternatively you could allocate your image in one big block and define\nrow_pointers[i] to point into the proper places in your block.\n\nIf you use png_set_rows(), the application is responsible for freeing\nrow_pointers (and row_pointers[i], if they were separately allocated).\n\nIf you don't allocate row_pointers ahead of time, png_read_png() will\ndo it, and it'll be free'ed by libpng when you call png_destroy_*().\n\nThe low-level read interface\n\nIf you are going the low-level route, you are now ready to read all\nthe file information up to the actual image data.  You do this with a\ncall to png_read_info().\n\n    png_read_info(png_ptr, info_ptr);\n\nThis will process all chunks up to but not including the image data.\n\nThis also copies some of the data from the PNG file into the decode structure\nfor use in later transformations.  Important information copied in is:\n\n1) The PNG file gamma from the gAMA chunk.  This overwrites the default value\nprovided by an earlier call to png_set_gamma or png_set_alpha_mode.\n\n2) Prior to libpng-1.5.4 the background color from a bKGd chunk.  This\ndamages the information provided by an earlier call to png_set_background\nresulting in unexpected behavior.  Libpng-1.5.4 no longer does this.\n\n3) The number of significant bits in each component value.  Libpng uses this to\noptimize gamma handling by reducing the internal lookup table sizes.\n\n4) The transparent color information from a tRNS chunk.  This can be modified by\na later call to png_set_tRNS.\n\nQuerying the info structure\n\nFunctions are used to get the information from the info_ptr once it\nhas been read.  Note that these fields may not be completely filled\nin until png_read_end() has read the chunk data following the image.\n\n    png_get_IHDR(png_ptr, info_ptr, &width, &height,\n       &bit_depth, &color_type, &interlace_type,\n       &compression_type, &filter_method);\n\n    width          - holds the width of the image\n                     in pixels (up to 2^31).\n\n    height         - holds the height of the image\n                     in pixels (up to 2^31).\n\n    bit_depth      - holds the bit depth of one of the\n                     image channels.  (valid values are\n                     1, 2, 4, 8, 16 and depend also on\n                     the color_type.  See also\n                     significant bits (sBIT) below).\n\n    color_type     - describes which color/alpha channels\n                         are present.\n                     PNG_COLOR_TYPE_GRAY\n                        (bit depths 1, 2, 4, 8, 16)\n                     PNG_COLOR_TYPE_GRAY_ALPHA\n                        (bit depths 8, 16)\n                     PNG_COLOR_TYPE_PALETTE\n                        (bit depths 1, 2, 4, 8)\n                     PNG_COLOR_TYPE_RGB\n                        (bit_depths 8, 16)\n                     PNG_COLOR_TYPE_RGB_ALPHA\n                        (bit_depths 8, 16)\n\n                     PNG_COLOR_MASK_PALETTE\n                     PNG_COLOR_MASK_COLOR\n                     PNG_COLOR_MASK_ALPHA\n\n    interlace_type - (PNG_INTERLACE_NONE or\n                     PNG_INTERLACE_ADAM7)\n\n    compression_type - (must be PNG_COMPRESSION_TYPE_BASE\n                     for PNG 1.0)\n\n    filter_method  - (must be PNG_FILTER_TYPE_BASE\n                     for PNG 1.0, and can also be\n                     PNG_INTRAPIXEL_DIFFERENCING if\n                     the PNG datastream is embedded in\n                     a MNG-1.0 datastream)\n\n    Any of width, height, color_type, bit_depth,\n    interlace_type, compression_type, or filter_method can\n    be NULL if you are not interested in their values.\n\n    Note that png_get_IHDR() returns 32-bit data into\n    the application's width and height variables.\n    This is an unsafe situation if these are not png_uint_32\n    variables.  In such situations, the\n    png_get_image_width() and png_get_image_height()\n    functions described below are safer.\n\n    width            = png_get_image_width(png_ptr,\n                         info_ptr);\n\n    height           = png_get_image_height(png_ptr,\n                         info_ptr);\n\n    bit_depth        = png_get_bit_depth(png_ptr,\n                         info_ptr);\n\n    color_type       = png_get_color_type(png_ptr,\n                         info_ptr);\n\n    interlace_type   = png_get_interlace_type(png_ptr,\n                         info_ptr);\n\n    compression_type = png_get_compression_type(png_ptr,\n                         info_ptr);\n\n    filter_method    = png_get_filter_type(png_ptr,\n                         info_ptr);\n\n    channels = png_get_channels(png_ptr, info_ptr);\n\n    channels       - number of channels of info for the\n                     color type (valid values are 1 (GRAY,\n                     PALETTE), 2 (GRAY_ALPHA), 3 (RGB),\n                     4 (RGB_ALPHA or RGB + filler byte))\n\n    rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n\n    rowbytes       - number of bytes needed to hold a row\n\n    signature = png_get_signature(png_ptr, info_ptr);\n\n    signature      - holds the signature read from the\n                     file (if any).  The data is kept in\n                     the same offset it would be if the\n                     whole signature were read (i.e. if an\n                     application had already read in 4\n                     bytes of signature before starting\n                     libpng, the remaining 4 bytes would\n                     be in signature[4] through signature[7]\n                     (see png_set_sig_bytes())).\n\nThese are also important, but their validity depends on whether the chunk\nhas been read.  The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and\npng_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the\ndata has been read, or zero if it is missing.  The parameters to the\npng_get_<chunk> are set directly if they are simple data types, or a\npointer into the info_ptr is returned for any complex types.\n\nThe colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks\nis simply returned to give the application information about how the\nimage was encoded.  Libpng itself only does transformations using the file\ngamma when combining semitransparent pixels with the background color, and,\nsince libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels\nwithin the simplified API.  Libpng also uses the file gamma when converting\nRGB to gray, beginning with libpng-1.0.5, if the application calls\npng_set_rgb_to_gray()).\n\n    png_get_PLTE(png_ptr, info_ptr, &palette,\n                     &num_palette);\n\n    palette        - the palette for the file\n                     (array of png_color)\n\n    num_palette    - number of entries in the palette\n\n    png_get_gAMA(png_ptr, info_ptr, &file_gamma);\n    png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);\n\n    file_gamma     - the gamma at which the file is\n                     written (PNG_INFO_gAMA)\n\n    int_file_gamma - 100,000 times the gamma at which the\n                     file is written\n\n    png_get_cHRM(png_ptr, info_ptr,  &white_x, &white_y, &red_x,\n                     &red_y, &green_x, &green_y, &blue_x, &blue_y)\n    png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z,\n                     &green_X, &green_Y, &green_Z, &blue_X, &blue_Y,\n                     &blue_Z)\n    png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x,\n                     &int_white_y, &int_red_x, &int_red_y,\n                     &int_green_x, &int_green_y, &int_blue_x,\n                     &int_blue_y)\n    png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,\n                     &int_red_Z, &int_green_X, &int_green_Y,\n                     &int_green_Z, &int_blue_X, &int_blue_Y,\n                     &int_blue_Z)\n\n    {white,red,green,blue}_{x,y}\n                     A color space encoding specified using the\n                     chromaticities of the end points and the\n                     white point. (PNG_INFO_cHRM)\n\n    {red,green,blue}_{X,Y,Z}\n                     A color space encoding specified using the\n                     encoding end points - the CIE tristimulus\n                     specification of the intended color of the red,\n                     green and blue channels in the PNG RGB data.\n                     The white point is simply the sum of the three\n                     end points. (PNG_INFO_cHRM)\n\n    png_get_sRGB(png_ptr, info_ptr, &srgb_intent);\n\n    srgb_intent -    the rendering intent (PNG_INFO_sRGB)\n                     The presence of the sRGB chunk\n                     means that the pixel data is in the\n                     sRGB color space.  This chunk also\n                     implies specific values of gAMA and\n                     cHRM.\n\n    png_get_iCCP(png_ptr, info_ptr, &name,\n       &compression_type, &profile, &proflen);\n\n    name             - The profile name.\n\n    compression_type - The compression type; always\n                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.\n                       You may give NULL to this argument to\n                       ignore it.\n\n    profile          - International Color Consortium color\n                       profile data. May contain NULs.\n\n    proflen          - length of profile data in bytes.\n\n    png_get_sBIT(png_ptr, info_ptr, &sig_bit);\n\n    sig_bit        - the number of significant bits for\n                     (PNG_INFO_sBIT) each of the gray,\n                     red, green, and blue channels,\n                     whichever are appropriate for the\n                     given color type (png_color_16)\n\n    png_get_tRNS(png_ptr, info_ptr, &trans_alpha,\n                     &num_trans, &trans_color);\n\n    trans_alpha    - array of alpha (transparency)\n                     entries for palette (PNG_INFO_tRNS)\n\n    num_trans      - number of transparent entries\n                     (PNG_INFO_tRNS)\n\n    trans_color    - graylevel or color sample values of\n                     the single transparent color for\n                     non-paletted images (PNG_INFO_tRNS)\n\n    png_get_hIST(png_ptr, info_ptr, &hist);\n                     (PNG_INFO_hIST)\n\n    hist           - histogram of palette (array of\n                     png_uint_16)\n\n    png_get_tIME(png_ptr, info_ptr, &mod_time);\n\n    mod_time       - time image was last modified\n                    (PNG_VALID_tIME)\n\n    png_get_bKGD(png_ptr, info_ptr, &background);\n\n    background     - background color (of type\n                     png_color_16p) (PNG_VALID_bKGD)\n                     valid 16-bit red, green and blue\n                     values, regardless of color_type\n\n    num_comments   = png_get_text(png_ptr, info_ptr,\n                     &text_ptr, &num_text);\n\n    num_comments   - number of comments\n\n    text_ptr       - array of png_text holding image\n                     comments\n\n    text_ptr[i].compression - type of compression used\n                 on \"text\" PNG_TEXT_COMPRESSION_NONE\n                           PNG_TEXT_COMPRESSION_zTXt\n                           PNG_ITXT_COMPRESSION_NONE\n                           PNG_ITXT_COMPRESSION_zTXt\n\n    text_ptr[i].key   - keyword for comment.  Must contain\n                         1-79 characters.\n\n    text_ptr[i].text  - text comments for current\n                         keyword.  Can be empty.\n\n    text_ptr[i].text_length - length of text string,\n                 after decompression, 0 for iTXt\n\n    text_ptr[i].itxt_length - length of itxt string,\n                 after decompression, 0 for tEXt/zTXt\n\n    text_ptr[i].lang  - language of comment (empty\n                         string for unknown).\n\n    text_ptr[i].lang_key  - keyword in UTF-8\n                         (empty string for unknown).\n\n    Note that the itxt_length, lang, and lang_key\n    members of the text_ptr structure only exist when the\n    library is built with iTXt chunk support.  Prior to\n    libpng-1.4.0 the library was built by default without\n    iTXt support. Also note that when iTXt is supported,\n    they contain NULL pointers when the \"compression\"\n    field contains PNG_TEXT_COMPRESSION_NONE or\n    PNG_TEXT_COMPRESSION_zTXt.\n\n    num_text       - number of comments (same as\n                     num_comments; you can put NULL here\n                     to avoid the duplication)\n\n    Note while png_set_text() will accept text, language,\n    and translated keywords that can be NULL pointers, the\n    structure returned by png_get_text will always contain\n    regular zero-terminated C strings.  They might be\n    empty strings but they will never be NULL pointers.\n\n    num_spalettes = png_get_sPLT(png_ptr, info_ptr,\n       &palette_ptr);\n\n    num_spalettes  - number of sPLT chunks read.\n\n    palette_ptr    - array of palette structures holding\n                     contents of one or more sPLT chunks\n                     read.\n\n    png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,\n       &unit_type);\n\n    offset_x       - positive offset from the left edge\n                     of the screen (can be negative)\n\n    offset_y       - positive offset from the top edge\n                     of the screen (can be negative)\n\n    unit_type      - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER\n\n    png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,\n       &unit_type);\n\n    res_x          - pixels/unit physical resolution in\n                     x direction\n\n    res_y          - pixels/unit physical resolution in\n                     x direction\n\n    unit_type      - PNG_RESOLUTION_UNKNOWN,\n                     PNG_RESOLUTION_METER\n\n    png_get_sCAL(png_ptr, info_ptr, &unit, &width,\n       &height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n\n    height      - height of a pixel in physical scale units\n                 (width and height are doubles)\n\n    png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,\n       &height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n                  (expressed as a string)\n\n    height      - height of a pixel in physical scale units\n                 (width and height are strings like \"2.54\")\n\n    num_unknown_chunks = png_get_unknown_chunks(png_ptr,\n       info_ptr, &unknowns)\n\n    unknowns          - array of png_unknown_chunk\n                        structures holding unknown chunks\n\n    unknowns[i].name  - name of unknown chunk\n\n    unknowns[i].data  - data of unknown chunk\n\n    unknowns[i].size  - size of unknown chunk's data\n\n    unknowns[i].location - position of chunk in file\n\n    The value of \"i\" corresponds to the order in which the\n    chunks were read from the PNG file or inserted with the\n    png_set_unknown_chunks() function.\n\n    The value of \"location\" is a bitwise \"or\" of\n\n         PNG_HAVE_IHDR  (0x01)\n         PNG_HAVE_PLTE  (0x02)\n         PNG_AFTER_IDAT (0x08)\n\nThe data from the pHYs chunk can be retrieved in several convenient\nforms:\n\n    res_x = png_get_x_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_y = png_get_y_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_x_and_y = png_get_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_x = png_get_x_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    res_y = png_get_y_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    res_x_and_y = png_get_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,\n       info_ptr)\n\n    Each of these returns 0 [signifying \"unknown\"] if\n       the data is not present or if res_x is 0;\n       res_x_and_y is 0 if res_x != res_y\n\n    Note that because of the way the resolutions are\n       stored internally, the inch conversions won't\n       come out to exactly even number.  For example,\n       72 dpi is stored as 0.28346 pixels/meter, and\n       when this is retrieved it is 71.9988 dpi, so\n       be sure to round the returned value appropriately\n       if you want to display a reasonable-looking result.\n\nThe data from the oFFs chunk can be retrieved in several convenient\nforms:\n\n    x_offset = png_get_x_offset_microns(png_ptr, info_ptr);\n\n    y_offset = png_get_y_offset_microns(png_ptr, info_ptr);\n\n    x_offset = png_get_x_offset_inches(png_ptr, info_ptr);\n\n    y_offset = png_get_y_offset_inches(png_ptr, info_ptr);\n\n    Each of these returns 0 [signifying \"unknown\" if both\n       x and y are 0] if the data is not present or if the\n       chunk is present but the unit is the pixel.  The\n       remark about inexact inch conversions applies here\n       as well, because a value in inches can't always be\n       converted to microns and back without some loss\n       of precision.\n\nFor more information, see the\nPNG specification for chunk contents.  Be careful with trusting\nrowbytes, as some of the transformations could increase the space\nneeded to hold a row (expand, filler, gray_to_rgb, etc.).\nSee png_read_update_info(), below.\n\nA quick word about text_ptr and num_text.  PNG stores comments in\nkeyword/text pairs, one pair per chunk, with no limit on the number\nof text chunks, and a 2^31 byte limit on their size.  While there are\nsuggested keywords, there is no requirement to restrict the use to these\nstrings.  It is strongly suggested that keywords and text be sensible\nto humans (that's the point), so don't use abbreviations.  Non-printing\nsymbols are not allowed.  See the PNG specification for more details.\nThere is also no requirement to have text after the keyword.\n\nKeywords should be limited to 79 Latin-1 characters without leading or\ntrailing spaces, but non-consecutive spaces are allowed within the\nkeyword.  It is possible to have the same keyword any number of times.\nThe text_ptr is an array of png_text structures, each holding a\npointer to a language string, a pointer to a keyword and a pointer to\na text string.  The text string, language code, and translated\nkeyword may be empty or NULL pointers.  The keyword/text\npairs are put into the array in the order that they are received.\nHowever, some or all of the text chunks may be after the image, so, to\nmake sure you have read all the text chunks, don't mess with these\nuntil after you read the stuff after the image.  This will be\nmentioned again below in the discussion that goes with png_read_end().\n\nInput transformations\n\nAfter you've read the header information, you can set up the library\nto handle any special transformations of the image data.  The various\nways to transform the data will be described in the order that they\nshould occur.  This is important, as some of these change the color\ntype and/or bit depth of the data, and some others only work on\ncertain color types and bit depths.\n\nTransformations you request are ignored if they don't have any meaning for a\nparticular input data format.  However some transformations can have an effect\nas a result of a previous transformation.  If you specify a contradictory set of\ntransformations, for example both adding and removing the alpha channel, you\ncannot predict the final result.\n\nThe color used for the transparency values should be supplied in the same\nformat/depth as the current image data.  It is stored in the same format/depth\nas the image data in a tRNS chunk, so this is what libpng expects for this data.\n\nThe color used for the background value depends on the need_expand argument as\ndescribed below.\n\nData will be decoded into the supplied row buffers packed into bytes\nunless the library has been told to transform it into another format.\nFor example, 4 bit/pixel paletted or grayscale data will be returned\n2 pixels/byte with the leftmost pixel in the high-order bits of the byte,\nunless png_set_packing() is called.  8-bit RGB data will be stored\nin RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()\nis called to insert filler bytes, either before or after each RGB triplet.\n\n16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant\nbyte of the color value first, unless png_set_scale_16() is called to\ntransform it to regular RGB RGB triplets, or png_set_filler() or\npng_set_add alpha() is called to insert two filler bytes, either before\nor after each RRGGBB triplet.  Similarly, 8-bit or 16-bit grayscale data can\nbe modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),\nor png_set_scale_16().\n\nThe following code transforms grayscale images of less than 8 to 8 bits,\nchanges paletted images to RGB, and adds a full alpha channel if there is\ntransparency information in a tRNS chunk.  This is most useful on\ngrayscale images with bit depths of 2 or 4 or if there is a multiple-image\nviewing application that wishes to treat all images in the same way.\n\n    if (color_type == PNG_COLOR_TYPE_PALETTE)\n        png_set_palette_to_rgb(png_ptr);\n\n    if (png_get_valid(png_ptr, info_ptr,\n        PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);\n\n    if (color_type == PNG_COLOR_TYPE_GRAY &&\n        bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);\n\nThe first two functions are actually aliases for png_set_expand(), added\nin libpng version 1.0.4, with the function names expanded to improve code\nreadability.  In some future version they may actually do different\nthings.\n\nAs of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was\nadded.  It expands the sample depth without changing tRNS to alpha.\n\nAs of libpng version 1.5.2, png_set_expand_16() was added.  It behaves as\npng_set_expand(); however, the resultant channels have 16 bits rather than 8.\nUse this when the output color or gray channels are made linear to avoid fairly\nsevere accuracy loss.\n\n   if (bit_depth < 16)\n      png_set_expand_16(png_ptr);\n\nPNG can have files with 16 bits per channel.  If you only can handle\n8 bits per channel, this will strip the pixels down to 8-bit.\n\n    if (bit_depth == 16)\n#if PNG_LIBPNG_VER >= 10504\n       png_set_scale_16(png_ptr);\n#else\n       png_set_strip_16(png_ptr);\n#endif\n\n(The more accurate \"png_set_scale_16()\" API became available in libpng version\n1.5.4).\n\nIf you need to process the alpha channel on the image separately from the image\ndata (for example if you convert it to a bitmap mask) it is possible to have\nlibpng strip the channel leaving just RGB or gray data:\n\n    if (color_type & PNG_COLOR_MASK_ALPHA)\n       png_set_strip_alpha(png_ptr);\n\nIf you strip the alpha channel you need to find some other way of dealing with\nthe information.  If, instead, you want to convert the image to an opaque\nversion with no alpha channel use png_set_background; see below.\n\nAs of libpng version 1.5.2, almost all useful expansions are supported, the\nmajor ommissions are conversion of grayscale to indexed images (which can be\ndone trivially in the application) and conversion of indexed to grayscale (which\ncan be done by a trivial manipulation of the palette.)\n\nIn the following table, the 01 means grayscale with depth<8, 31 means\nindexed with depth<8, other numerals represent the color type, \"T\" means\nthe tRNS chunk is present, A means an alpha channel is present, and O\nmeans tRNS or alpha is present but all pixels in the image are opaque.\n\n  FROM  01  31   0  0T  0O   2  2T  2O   3  3T  3O  4A  4O  6A  6O\n   TO\n   01    -  [G]  -   -   -   -   -   -   -   -   -   -   -   -   -\n   31   [Q]  Q  [Q] [Q] [Q]  Q   Q   Q   Q   Q   Q  [Q] [Q]  Q   Q\n    0    1   G   +   .   .   G   G   G   G   G   G   B   B  GB  GB\n   0T    lt  Gt  t   +   .   Gt  G   G   Gt  G   G   Bt  Bt GBt GBt\n   0O    lt  Gt  t   .   +   Gt  Gt  G   Gt  Gt  G   Bt  Bt GBt GBt\n    2    C   P   C   C   C   +   .   .   C   -   -  CB  CB   B   B\n   2T    Ct  -   Ct  C   C   t   +   t   -   -   -  CBt CBt  Bt  Bt\n   2O    Ct  -   Ct  C   C   t   t   +   -   -   -  CBt CBt  Bt  Bt\n    3   [Q]  p  [Q] [Q] [Q]  Q   Q   Q   +   .   .  [Q] [Q]  Q   Q\n   3T   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   +   t  [Qt][Qt] Qt  Qt\n   3O   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   t   +  [Qt][Qt] Qt  Qt\n   4A    lA  G   A   T   T   GA  GT  GT  GA  GT  GT  +   BA  G  GBA\n   4O    lA GBA  A   T   T   GA  GT  GT  GA  GT  GT  BA  +  GBA  G\n   6A    CA  PA  CA  C   C   A   T  tT   PA  P   P   C  CBA  +   BA\n   6O    CA PBA  CA  C   C   A  tT   T   PA  P   P  CBA  C   BA  +\n\nWithin the matrix,\n     \"+\" identifies entries where 'from' and 'to' are the same.\n     \"-\" means the transformation is not supported.\n     \".\" means nothing is necessary (a tRNS chunk can just be ignored).\n     \"t\" means the transformation is obtained by png_set_tRNS.\n     \"A\" means the transformation is obtained by png_set_add_alpha().\n     \"X\" means the transformation is obtained by png_set_expand().\n     \"1\" means the transformation is obtained by\n         png_set_expand_gray_1_2_4_to_8() (and by png_set_expand()\n         if there is no transparency in the original or the final\n         format).\n     \"C\" means the transformation is obtained by png_set_gray_to_rgb().\n     \"G\" means the transformation is obtained by png_set_rgb_to_gray().\n     \"P\" means the transformation is obtained by\n         png_set_expand_palette_to_rgb().\n     \"p\" means the transformation is obtained by png_set_packing().\n     \"Q\" means the transformation is obtained by png_set_quantize().\n     \"T\" means the transformation is obtained by\n         png_set_tRNS_to_alpha().\n     \"B\" means the transformation is obtained by\n         png_set_background(), or png_strip_alpha().\n\nWhen an entry has multiple transforms listed all are required to cause the\nright overall transformation.  When two transforms are separated by a comma\neither will do the job.  When transforms are enclosed in [] the transform should\ndo the job but this is currently unimplemented - a different format will result\nif the suggested transformations are used.\n\nIn PNG files, the alpha channel in an image\nis the level of opacity.  If you need the alpha channel in an image to\nbe the level of transparency instead of opacity, you can invert the\nalpha channel (or the tRNS chunk data) after it's read, so that 0 is\nfully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit\nimages) is fully transparent, with\n\n    png_set_invert_alpha(png_ptr);\n\nPNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as\nthey can, resulting in, for example, 8 pixels per byte for 1 bit\nfiles.  This code expands to 1 pixel per byte without changing the\nvalues of the pixels:\n\n    if (bit_depth < 8)\n       png_set_packing(png_ptr);\n\nPNG files have possible bit depths of 1, 2, 4, 8, and 16.  All pixels\nstored in a PNG image have been \"scaled\" or \"shifted\" up to the next\nhigher possible bit depth (e.g. from 5 bits/sample in the range [0,31]\nto 8 bits/sample in the range [0, 255]).  However, it is also possible\nto convert the PNG pixel data back to the original bit depth of the\nimage.  This call reduces the pixels back down to the original bit depth:\n\n    png_color_8p sig_bit;\n\n    if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))\n       png_set_shift(png_ptr, sig_bit);\n\nPNG files store 3-color pixels in red, green, blue order.  This code\nchanges the storage of the pixels to blue, green, red:\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n        color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_bgr(png_ptr);\n\nPNG files store RGB pixels packed into 3 or 6 bytes. This code expands them\ninto 4 or 8 bytes for windowing systems that need them in this format:\n\n    if (color_type == PNG_COLOR_TYPE_RGB)\n       png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);\n\nwhere \"filler\" is the 8-bit or 16-bit number to fill with, and the location\nis either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether\nyou want the filler before the RGB or after. When filling an 8-bit pixel,\nthe least significant 8 bits of the number are used, if a 16-bit number is\nsupplied.  This transformation does not affect images that already have full\nalpha channels.  To add an opaque alpha channel, use filler=0xffff and\nPNG_FILLER_AFTER which will generate RGBA pixels.\n\nNote that png_set_filler() does not change the color type.  If you want\nto do that, you can add a true alpha channel with\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n       color_type == PNG_COLOR_TYPE_GRAY)\n       png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);\n\nwhere \"filler\" contains the alpha value to assign to each pixel.\nThe png_set_add_alpha() function was added in libpng-1.2.7.\n\nIf you are reading an image with an alpha channel, and you need the\ndata as ARGB instead of the normal PNG format RGBA:\n\n    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_swap_alpha(png_ptr);\n\nFor some uses, you may want a grayscale image to be represented as\nRGB.  This code will do that conversion:\n\n    if (color_type == PNG_COLOR_TYPE_GRAY ||\n        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n       png_set_gray_to_rgb(png_ptr);\n\nConversely, you can convert an RGB or RGBA image to grayscale or grayscale\nwith alpha.\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n        color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_rgb_to_gray(png_ptr, error_action,\n          double red_weight, double green_weight);\n\n    error_action = 1: silently do the conversion\n\n    error_action = 2: issue a warning if the original\n                      image has any pixel where\n                      red != green or red != blue\n\n    error_action = 3: issue an error and abort the\n                      conversion if the original\n                      image has any pixel where\n                      red != green or red != blue\n\n    red_weight:       weight of red component\n\n    green_weight:     weight of green component\n                      If either weight is negative, default\n                      weights are used.\n\nIn the corresponding fixed point API the red_weight and green_weight values are\nsimply scaled by 100,000:\n\n    png_set_rgb_to_gray(png_ptr, error_action,\n       png_fixed_point red_weight,\n       png_fixed_point green_weight);\n\nIf you have set error_action = 1 or 2, you can\nlater check whether the image really was gray, after processing\nthe image rows, with the png_get_rgb_to_gray_status(png_ptr) function.\nIt will return a png_byte that is zero if the image was gray or\n1 if there were any non-gray pixels.  Background and sBIT data\nwill be silently converted to grayscale, using the green channel\ndata for sBIT, regardless of the error_action setting.\n\nThe default values come from the PNG file cHRM chunk if present; otherwise, the\ndefaults correspond to the ITU-R recommendation 709, and also the sRGB color\nspace, as recommended in the Charles Poynton's Colour FAQ,\nCopyright (c) 2006-11-28 Charles Poynton, in section 9:\n\n<http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>\n\n    Y = 0.2126 * R + 0.7152 * G + 0.0722 * B\n\nPrevious versions of this document, 1998 through 2002, recommended a slightly\ndifferent formula:\n\n    Y = 0.212671 * R + 0.715160 * G + 0.072169 * B\n\nLibpng uses an integer approximation:\n\n    Y = (6968 * R + 23434 * G + 2366 * B)/32768\n\nThe calculation is done in a linear colorspace, if the image gamma\ncan be determined.\n\nThe png_set_background() function has been described already; it tells libpng to\ncomposite images with alpha or simple transparency against the supplied\nbackground color.  For compatibility with versions of libpng earlier than\nlibpng-1.5.4 it is recommended that you call the function after reading the file\nheader, even if you don't want to use the color in a bKGD chunk, if one exists.\n\nIf the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),\nyou may use this color, or supply another color more suitable for\nthe current display (e.g., the background color from a web page).  You\nneed to tell libpng how the color is represented, both the format of the\ncomponent values in the color (the number of bits) and the gamma encoding of the\ncolor.  The function takes two arguments, background_gamma_mode and need_expand\nto convey this information; however, only two combinations are likely to be\nuseful:\n\n    png_color_16 my_background;\n    png_color_16p image_background;\n\n    if (png_get_bKGD(png_ptr, info_ptr, &image_background))\n       png_set_background(png_ptr, image_background,\n           PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);\n    else\n       png_set_background(png_ptr, &my_background,\n           PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);\n\nThe second call was described above - my_background is in the format of the\nfinal, display, output produced by libpng.  Because you now know the format of\nthe PNG it is possible to avoid the need to choose either 8-bit or 16-bit\noutput and to retain palette images (the palette colors will be modified\nappropriately and the tRNS chunk removed.)  However, if you are doing this,\ntake great care not to ask for transformations without checking first that\nthey apply!\n\nIn the first call the background color has the original bit depth and color type\nof the PNG file.  So, for palette images the color is supplied as a palette\nindex and for low bit greyscale images the color is a reduced bit value in\nimage_background->gray.\n\nIf you didn't call png_set_gamma() before reading the file header, for example\nif you need your code to remain compatible with older versions of libpng prior\nto libpng-1.5.4, this is the place to call it.\n\nDo not call it if you called png_set_alpha_mode(); doing so will damage the\nsettings put in place by png_set_alpha_mode().  (If png_set_alpha_mode() is\nsupported then you can certainly do png_set_gamma() before reading the PNG\nheader.)\n\nThis API unconditionally sets the screen and file gamma values, so it will\noverride the value in the PNG file unless it is called before the PNG file\nreading starts.  For this reason you must always call it with the PNG file\nvalue when you call it in this position:\n\n   if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))\n      png_set_gamma(png_ptr, screen_gamma, file_gamma);\n\n   else\n      png_set_gamma(png_ptr, screen_gamma, 0.45455);\n\nIf you need to reduce an RGB file to a paletted file, or if a paletted\nfile has more entries than will fit on your screen, png_set_quantize()\nwill do that.  Note that this is a simple match quantization that merely\nfinds the closest color available.  This should work fairly well with\noptimized palettes, but fairly badly with linear color cubes.  If you\npass a palette that is larger than maximum_colors, the file will\nreduce the number of colors in the palette so it will fit into\nmaximum_colors.  If there is a histogram, libpng will use it to make\nmore intelligent choices when reducing the palette.  If there is no\nhistogram, it may not do as good a job.\n\n   if (color_type & PNG_COLOR_MASK_COLOR)\n   {\n      if (png_get_valid(png_ptr, info_ptr,\n          PNG_INFO_PLTE))\n      {\n         png_uint_16p histogram = NULL;\n\n         png_get_hIST(png_ptr, info_ptr,\n             &histogram);\n         png_set_quantize(png_ptr, palette, num_palette,\n            max_screen_colors, histogram, 1);\n      }\n\n      else\n      {\n         png_color std_color_cube[MAX_SCREEN_COLORS] =\n            { ... colors ... };\n\n         png_set_quantize(png_ptr, std_color_cube,\n            MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,\n            NULL,0);\n      }\n   }\n\nPNG files describe monochrome as black being zero and white being one.\nThe following code will reverse this (make black be one and white be\nzero):\n\n   if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)\n      png_set_invert_mono(png_ptr);\n\nThis function can also be used to invert grayscale and gray-alpha images:\n\n   if (color_type == PNG_COLOR_TYPE_GRAY ||\n       color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      png_set_invert_mono(png_ptr);\n\nPNG files store 16-bit pixels in network byte order (big-endian,\nie. most significant bits first).  This code changes the storage to the\nother way (little-endian, i.e. least significant bits first, the\nway PCs store them):\n\n    if (bit_depth == 16)\n       png_set_swap(png_ptr);\n\nIf you are using packed-pixel images (1, 2, or 4 bits/pixel), and you\nneed to change the order the pixels are packed into bytes, you can use:\n\n    if (bit_depth < 8)\n       png_set_packswap(png_ptr);\n\nFinally, you can write your own transformation function if none of\nthe existing ones meets your needs.  This is done by setting a callback\nwith\n\n    png_set_read_user_transform_fn(png_ptr,\n        read_transform_fn);\n\nYou must supply the function\n\n    void read_transform_fn(png_structp png_ptr, png_row_infop\n        row_info, png_bytep data)\n\nSee pngtest.c for a working example.  Your function will be called\nafter all of the other transformations have been processed.  Take care with\ninterlaced images if you do the interlace yourself - the width of the row is the\nwidth in 'row_info', not the overall image width.\n\nIf supported, libpng provides two information routines that you can use to find\nwhere you are in processing the image:\n\n   png_get_current_pass_number(png_structp png_ptr);\n   png_get_current_row_number(png_structp png_ptr);\n\nDon't try using these outside a transform callback - firstly they are only\nsupported if user transforms are supported, secondly they may well return\nunexpected results unless the row is actually being processed at the moment they\nare called.\n\nWith interlaced\nimages the value returned is the row in the input sub-image image.  Use\nPNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\nfind the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).\n\nThe discussion of interlace handling above contains more information on how to\nuse these values.\n\nYou can also set up a pointer to a user structure for use by your\ncallback function, and you can inform libpng that your transform\nfunction will change the number of channels or bit depth with the\nfunction\n\n    png_set_user_transform_info(png_ptr, user_ptr,\n        user_depth, user_channels);\n\nThe user's application, not libpng, is responsible for allocating and\nfreeing any memory required for the user structure.\n\nYou can retrieve the pointer via the function\npng_get_user_transform_ptr().  For example:\n\n    voidp read_user_transform_ptr =\n        png_get_user_transform_ptr(png_ptr);\n\nThe last thing to handle is interlacing; this is covered in detail below,\nbut you must call the function here if you want libpng to handle expansion\nof the interlaced image.\n\n    number_of_passes = png_set_interlace_handling(png_ptr);\n\nAfter setting the transformations, libpng can update your png_info\nstructure to reflect any transformations you've requested with this\ncall.\n\n    png_read_update_info(png_ptr, info_ptr);\n\nThis is most useful to update the info structure's rowbytes\nfield so you can use it to allocate your image memory.  This function\nwill also update your palette with the correct screen_gamma and\nbackground if these have been given with the calls above.  You may\nonly call png_read_update_info() once with a particular info_ptr.\n\nAfter you call png_read_update_info(), you can allocate any\nmemory you need to hold the image.  The row data is simply\nraw byte data for all forms of images.  As the actual allocation\nvaries among applications, no example will be given.  If you\nare allocating one large chunk, you will need to build an\narray of pointers to each row, as it will be needed for some\nof the functions below.\n\nRemember: Before you call png_read_update_info(), the png_get_*()\nfunctions return the values corresponding to the original PNG image.\nAfter you call png_read_update_info the values refer to the image\nthat libpng will output.  Consequently you must call all the png_set_\nfunctions before you call png_read_update_info().  This is particularly\nimportant for png_set_interlace_handling() - if you are going to call\npng_read_update_info() you must call png_set_interlace_handling() before\nit unless you want to receive interlaced output.\n\nReading image data\n\nAfter you've allocated memory, you can read the image data.\nThe simplest way to do this is in one function call.  If you are\nallocating enough memory to hold the whole image, you can just\ncall png_read_image() and libpng will read in all the image data\nand put it in the memory area supplied.  You will need to pass in\nan array of pointers to each row.\n\nThis function automatically handles interlacing, so you don't\nneed to call png_set_interlace_handling() (unless you call\npng_read_update_info()) or call this function multiple times, or any\nof that other stuff necessary with png_read_rows().\n\n   png_read_image(png_ptr, row_pointers);\n\nwhere row_pointers is:\n\n   png_bytep row_pointers[height];\n\nYou can point to void or char or whatever you use for pixels.\n\nIf you don't want to read in the whole image at once, you can\nuse png_read_rows() instead.  If there is no interlacing (check\ninterlace_type == PNG_INTERLACE_NONE), this is simple:\n\n    png_read_rows(png_ptr, row_pointers, NULL,\n        number_of_rows);\n\nwhere row_pointers is the same as in the png_read_image() call.\n\nIf you are doing this just one row at a time, you can do this with\na single row_pointer instead of an array of row_pointers:\n\n    png_bytep row_pointer = row;\n    png_read_row(png_ptr, row_pointer, NULL);\n\nIf the file is interlaced (interlace_type != 0 in the IHDR chunk), things\nget somewhat harder.  The only current (PNG Specification version 1.2)\ninterlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);\na somewhat complicated 2D interlace scheme, known as Adam7, that\nbreaks down an image into seven smaller images of varying size, based\non an 8x8 grid.  This number is defined (from libpng 1.5) as\nPNG_INTERLACE_ADAM7_PASSES in png.h\n\nlibpng can fill out those images or it can give them to you \"as is\".\nIt is almost always better to have libpng handle the interlacing for you.\nIf you want the images filled out, there are two ways to do that.  The one\nmentioned in the PNG specification is to expand each pixel to cover\nthose pixels that have not been read yet (the \"rectangle\" method).\nThis results in a blocky image for the first pass, which gradually\nsmooths out as more pixels are read.  The other method is the \"sparkle\"\nmethod, where pixels are drawn only in their final locations, with the\nrest of the image remaining whatever colors they were initialized to\nbefore the start of the read.  The first method usually looks better,\nbut tends to be slower, as there are more pixels to put in the rows.\n\nIf, as is likely, you want libpng to expand the images, call this before\ncalling png_start_read_image() or png_read_update_info():\n\n    if (interlace_type == PNG_INTERLACE_ADAM7)\n       number_of_passes\n           = png_set_interlace_handling(png_ptr);\n\nThis will return the number of passes needed.  Currently, this is seven,\nbut may change if another interlace type is added.  This function can be\ncalled even if the file is not interlaced, where it will return one pass.\nYou then need to read the whole image 'number_of_passes' times.  Each time\nwill distribute the pixels from the current pass to the correct place in\nthe output image, so you need to supply the same rows to png_read_rows in\neach pass.\n\nIf you are not going to display the image after each pass, but are\ngoing to wait until the entire image is read in, use the sparkle\neffect.  This effect is faster and the end result of either method\nis exactly the same.  If you are planning on displaying the image\nafter each pass, the \"rectangle\" effect is generally considered the\nbetter looking one.\n\nIf you only want the \"sparkle\" effect, just call png_read_row() or\npng_read_rows() as\nnormal, with the third parameter NULL.  Make sure you make pass over\nthe image number_of_passes times, and you don't change the data in the\nrows between calls.  You can change the locations of the data, just\nnot the data.  Each pass only writes the pixels appropriate for that\npass, and assumes the data from previous passes is still valid.\n\n    png_read_rows(png_ptr, row_pointers, NULL,\n        number_of_rows);\n    or\n    png_read_row(png_ptr, row_pointers, NULL);\n\nIf you only want the first effect (the rectangles), do the same as\nbefore except pass the row buffer in the third parameter, and leave\nthe second parameter NULL.\n\n    png_read_rows(png_ptr, NULL, row_pointers,\n        number_of_rows);\n    or\n    png_read_row(png_ptr, NULL, row_pointers);\n\nIf you don't want libpng to handle the interlacing details, just call\npng_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.\nEach of the images is a valid image by itself; however, you will almost\ncertainly need to distribute the pixels from each sub-image to the\ncorrect place.  This is where everything gets very tricky.\n\nIf you want to retrieve the separate images you must pass the correct\nnumber of rows to each successive call of png_read_rows().  The calculation\ngets pretty complicated for small images, where some sub-images may\nnot even exist because either their width or height ends up zero.\nlibpng provides two macros to help you in 1.5 and later versions:\n\n   png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);\n   png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);\n\nRespectively these tell you the width and height of the sub-image\ncorresponding to the numbered pass.  'pass' is in in the range 0 to 6 -\nthis can be confusing because the specification refers to the same passes\nas 1 to 7!  Be careful, you must check both the width and height before\ncalling png_read_rows() and not call it for that pass if either is zero.\n\nYou can, of course, read each sub-image row by row.  If you want to\nproduce optimal code to make a pixel-by-pixel transformation of an\ninterlaced image this is the best approach; read each row of each pass,\ntransform it, and write it out to a new interlaced image.\n\nIf you want to de-interlace the image yourself libpng provides further\nmacros to help that tell you where to place the pixels in the output image.\nBecause the interlacing scheme is rectangular - sub-image pixels are always\narranged on a rectangular grid - all you need to know for each pass is the\nstarting column and row in the output image of the first pixel plus the\nspacing between each pixel.  As of libpng 1.5 there are four macros to\nretrieve this information:\n\n   png_uint_32 x = PNG_PASS_START_COL(pass);\n   png_uint_32 y = PNG_PASS_START_ROW(pass);\n   png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);\n   png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);\n\nThese allow you to write the obvious loop:\n\n   png_uint_32 input_y = 0;\n   png_uint_32 output_y = PNG_PASS_START_ROW(pass);\n\n   while (output_y < output_image_height)\n   {\n      png_uint_32 input_x = 0;\n      png_uint_32 output_x = PNG_PASS_START_COL(pass);\n\n      while (output_x < output_image_width)\n      {\n         image[output_y][output_x] =\n             subimage[pass][input_y][input_x++];\n\n         output_x += xStep;\n      }\n\n      ++input_y;\n      output_y += yStep;\n   }\n\nNotice that the steps between successive output rows and columns are\nreturned as shifts.  This is possible because the pixels in the subimages\nare always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original\nimage.  In practice you may need to directly calculate the output coordinate\ngiven an input coordinate.  libpng provides two further macros for this\npurpose:\n\n   png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);\n   png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);\n\nFinally a pair of macros are provided to tell you if a particular image\nrow or column appears in a given pass:\n\n   int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);\n   int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);\n\nBear in mind that you will probably also need to check the width and height\nof the pass in addition to the above to be sure the pass even exists!\n\nWith any luck you are convinced by now that you don't want to do your own\ninterlace handling.  In reality normally the only good reason for doing this\nis if you are processing PNG files on a pixel-by-pixel basis and don't want\nto load the whole file into memory when it is interlaced.\n\nlibpng includes a test program, pngvalid, that illustrates reading and\nwriting of interlaced images.  If you can't get interlacing to work in your\ncode and don't want to leave it to libpng (the recommended approach), see\nhow pngvalid.c does it.\n\nFinishing a sequential read\n\nAfter you are finished reading the image through the\nlow-level interface, you can finish reading the file.\n\nIf you want to use a different crc action for handling CRC errors in\nchunks after the image data, you can call png_set_crc_action()\nagain at this point.\n\nIf you are interested in comments or time, which may be stored either\nbefore or after the image data, you should pass the separate png_info\nstruct if you want to keep the comments from before and after the image\nseparate.\n\n    png_infop end_info = png_create_info_struct(png_ptr);\n\n    if (!end_info)\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\n   png_read_end(png_ptr, end_info);\n\nIf you are not interested, you should still call png_read_end()\nbut you can pass NULL, avoiding the need to create an end_info structure.\nIf you do this, libpng will not process any chunks after IDAT other than\nskipping over them and perhaps (depending on whether you have called\npng_set_crc_action) checking their CRCs while looking for the IEND chunk.\n\n   png_read_end(png_ptr, (png_infop)NULL);\n\nIf you don't call png_read_end(), then your file pointer will be\nleft pointing to the first chunk after the last IDAT, which is probably\nnot what you want if you expect to read something beyond the end of\nthe PNG datastream.\n\nWhen you are done, you can free all memory allocated by libpng like this:\n\n   png_destroy_read_struct(&png_ptr, &info_ptr,\n       &end_info);\n\nor, if you didn't create an end_info structure,\n\n   png_destroy_read_struct(&png_ptr, &info_ptr,\n       (png_infopp)NULL);\n\nIt is also possible to individually free the info_ptr members that\npoint to libpng-allocated storage with the following function:\n\n    png_free_data(png_ptr, info_ptr, mask, seq)\n\n    mask - identifies data to be freed, a mask\n           containing the bitwise OR of one or\n           more of\n             PNG_FREE_PLTE, PNG_FREE_TRNS,\n             PNG_FREE_HIST, PNG_FREE_ICCP,\n             PNG_FREE_PCAL, PNG_FREE_ROWS,\n             PNG_FREE_SCAL, PNG_FREE_SPLT,\n             PNG_FREE_TEXT, PNG_FREE_UNKN,\n           or simply PNG_FREE_ALL\n\n    seq  - sequence number of item to be freed\n           (-1 for all items)\n\nThis function may be safely called when the relevant storage has\nalready been freed, or has not yet been allocated, or was allocated\nby the user and not by libpng,  and will in those cases do nothing.\nThe \"seq\" parameter is ignored if only one item of the selected data\ntype, such as PLTE, is allowed.  If \"seq\" is not -1, and multiple items\nare allowed for the data type identified in the mask, such as text or\nsPLT, only the n'th item in the structure is freed, where n is \"seq\".\n\nThe default behavior is only to free data that was allocated internally\nby libpng.  This can be changed, so that libpng will not free the data,\nor so that it will free data that was allocated by the user with png_malloc()\nor png_calloc() and passed in via a png_set_*() function, with\n\n    png_data_freer(png_ptr, info_ptr, freer, mask)\n\n    freer  - one of\n               PNG_DESTROY_WILL_FREE_DATA\n               PNG_SET_WILL_FREE_DATA\n               PNG_USER_WILL_FREE_DATA\n\n    mask   - which data elements are affected\n             same choices as in png_free_data()\n\nThis function only affects data that has already been allocated.\nYou can call this function after reading the PNG data but before calling\nany png_set_*() functions, to control whether the user or the png_set_*()\nfunction is responsible for freeing any existing data that might be present,\nand again after the png_set_*() functions to control whether the user\nor png_destroy_*() is supposed to free the data.  When the user assumes\nresponsibility for libpng-allocated data, the application must use\npng_free() to free it, and when the user transfers responsibility to libpng\nfor data that the user has allocated, the user must have used png_malloc()\nor png_calloc() to allocate it.\n\nIf you allocated your row_pointers in a single block, as suggested above in\nthe description of the high level read interface, you must not transfer\nresponsibility for freeing it to the png_set_rows or png_read_destroy function,\nbecause they would also try to free the individual row_pointers[i].\n\nIf you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword\nseparately, do not transfer responsibility for freeing text_ptr to libpng,\nbecause when libpng fills a png_text structure it combines these members with\nthe key member, and png_free_data() will free only text_ptr.key.  Similarly,\nif you transfer responsibility for free'ing text_ptr from libpng to your\napplication, your application must not separately free those members.\n\nThe png_free_data() function will turn off the \"valid\" flag for anything\nit frees.  If you need to turn the flag off for a chunk that was freed by\nyour application instead of by libpng, you can use\n\n    png_set_invalid(png_ptr, info_ptr, mask);\n\n    mask - identifies the chunks to be made invalid,\n           containing the bitwise OR of one or\n           more of\n             PNG_INFO_gAMA, PNG_INFO_sBIT,\n             PNG_INFO_cHRM, PNG_INFO_PLTE,\n             PNG_INFO_tRNS, PNG_INFO_bKGD,\n             PNG_INFO_hIST, PNG_INFO_pHYs,\n             PNG_INFO_oFFs, PNG_INFO_tIME,\n             PNG_INFO_pCAL, PNG_INFO_sRGB,\n             PNG_INFO_iCCP, PNG_INFO_sPLT,\n             PNG_INFO_sCAL, PNG_INFO_IDAT\n\nFor a more compact example of reading a PNG image, see the file example.c.\n\nReading PNG files progressively\n\nThe progressive reader is slightly different from the non-progressive\nreader.  Instead of calling png_read_info(), png_read_rows(), and\npng_read_end(), you make one call to png_process_data(), which calls\ncallbacks when it has the info, a row, or the end of the image.  You\nset up these callbacks with png_set_progressive_read_fn().  You don't\nhave to worry about the input/output functions of libpng, as you are\ngiving the library the data directly in png_process_data().  I will\nassume that you have read the section on reading PNG files above,\nso I will only highlight the differences (although I will show\nall of the code).\n\npng_structp png_ptr;\npng_infop info_ptr;\n\n /*  An example code fragment of how you would\n     initialize the progressive reader in your\n     application. */\n int\n initialize_png_reader()\n {\n    png_ptr = png_create_read_struct\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n         user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n        return (ERROR);\n\n    info_ptr = png_create_info_struct(png_ptr);\n\n    if (!info_ptr)\n    {\n       png_destroy_read_struct(&png_ptr,\n          (png_infopp)NULL, (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n          (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    /* This one's new.  You can provide functions\n       to be called when the header info is valid,\n       when each row is completed, and when the image\n       is finished.  If you aren't using all functions,\n       you can specify NULL parameters.  Even when all\n       three functions are NULL, you need to call\n       png_set_progressive_read_fn().  You can use\n       any struct as the user_ptr (cast to a void pointer\n       for the function call), and retrieve the pointer\n       from inside the callbacks using the function\n\n          png_get_progressive_ptr(png_ptr);\n\n       which will return a void pointer, which you have\n       to cast appropriately.\n     */\n    png_set_progressive_read_fn(png_ptr, (void *)user_ptr,\n        info_callback, row_callback, end_callback);\n\n    return 0;\n }\n\n /* A code fragment that you call as you receive blocks\n   of data */\n int\n process_data(png_bytep buffer, png_uint_32 length)\n {\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    /* This one's new also.  Simply give it a chunk\n       of data from the file stream (in order, of\n       course).  On machines with segmented memory\n       models machines, don't give it any more than\n       64K.  The library seems to run fine with sizes\n       of 4K. Although you can give it much less if\n       necessary (I assume you can give it chunks of\n       1 byte, I haven't tried less than 256 bytes\n       yet).  When this function returns, you may\n       want to display any rows that were generated\n       in the row callback if you don't already do\n       so there.\n     */\n    png_process_data(png_ptr, info_ptr, buffer, length);\n\n    /* At this point you can call png_process_data_skip if\n       you want to handle data the library will skip yourself;\n       it simply returns the number of bytes to skip (and stops\n       libpng skipping that number of bytes on the next\n       png_process_data call).\n    return 0;\n }\n\n /* This function is called (as set by\n    png_set_progressive_read_fn() above) when enough data\n    has been supplied so all of the header has been\n    read.\n */\n void\n info_callback(png_structp png_ptr, png_infop info)\n {\n    /* Do any setup here, including setting any of\n       the transformations mentioned in the Reading\n       PNG files section.  For now, you _must_ call\n       either png_start_read_image() or\n       png_read_update_info() after all the\n       transformations are set (even if you don't set\n       any).  You may start getting rows before\n       png_process_data() returns, so this is your\n       last chance to prepare for that.\n\n       This is where you turn on interlace handling,\n       assuming you don't want to do it yourself.\n\n       If you need to you can stop the processing of\n       your original input data at this point by calling\n       png_process_data_pause.  This returns the number\n       of unprocessed bytes from the last png_process_data\n       call - it is up to you to ensure that the next call\n       sees these bytes again.  If you don't want to bother\n       with this you can get libpng to cache the unread\n       bytes by setting the 'save' parameter (see png.h) but\n       then libpng will have to copy the data internally.\n     */\n }\n\n /* This function is called when each row of image\n    data is complete */\n void\n row_callback(png_structp png_ptr, png_bytep new_row,\n    png_uint_32 row_num, int pass)\n {\n    /* If the image is interlaced, and you turned\n       on the interlace handler, this function will\n       be called for every row in every pass.  Some\n       of these rows will not be changed from the\n       previous pass.  When the row is not changed,\n       the new_row variable will be NULL.  The rows\n       and passes are called in order, so you don't\n       really need the row_num and pass, but I'm\n       supplying them because it may make your life\n       easier.\n\n       If you did not turn on interlace handling then\n       the callback is called for each row of each\n       sub-image when the image is interlaced.  In this\n       case 'row_num' is the row in the sub-image, not\n       the row in the output image as it is in all other\n       cases.\n\n       For the non-NULL rows of interlaced images when\n       you have switched on libpng interlace handling,\n       you must call png_progressive_combine_row()\n       passing in the row and the old row.  You can\n       call this function for NULL rows (it will just\n       return) and for non-interlaced images (it just\n       does the memcpy for you) if it will make the\n       code easier.  Thus, you can just do this for\n       all cases if you switch on interlace handling;\n     */\n\n        png_progressive_combine_row(png_ptr, old_row,\n          new_row);\n\n    /* where old_row is what was displayed\n       previously for the row.  Note that the first\n       pass (pass == 0, really) will completely cover\n       the old row, so the rows do not have to be\n       initialized.  After the first pass (and only\n       for interlaced images), you will have to pass\n       the current row, and the function will combine\n       the old row and the new row.\n\n       You can also call png_process_data_pause in this\n       callback - see above.\n    */\n }\n\n void\n end_callback(png_structp png_ptr, png_infop info)\n {\n    /* This function is called after the whole image\n       has been read, including any chunks after the\n       image (up to and including the IEND).  You\n       will usually have the same info chunk as you\n       had in the header, although some data may have\n       been added to the comments and time fields.\n\n       Most people won't do much here, perhaps setting\n       a flag that marks the image as finished.\n     */\n }\n\n\n\nIV. Writing\n\nMuch of this is very similar to reading.  However, everything of\nimportance is repeated here, so you won't have to constantly look\nback up in the reading section to understand writing.\n\nSetup\n\nYou will want to do the I/O initialization before you get into libpng,\nso if it doesn't work, you don't have anything to undo. If you are not\nusing the standard I/O functions, you will need to replace them with\ncustom writing functions.  See the discussion under Customizing libpng.\n\n    FILE *fp = fopen(file_name, \"wb\");\n\n    if (!fp)\n       return (ERROR);\n\nNext, png_struct and png_info need to be allocated and initialized.\nAs these can be both relatively large, you may not want to store these\non the stack, unless you have stack space to spare.  Of course, you\nwill want to check if they return NULL.  If you are also reading,\nyou won't want to name your read structure and your write structure\nboth \"png_ptr\"; you can call them anything you like, such as\n\"read_ptr\" and \"write_ptr\".  Look at pngtest.c, for example.\n\n    png_structp png_ptr = png_create_write_struct\n       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n       return (ERROR);\n\n    png_infop info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr)\n    {\n       png_destroy_write_struct(&png_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\nIf you want to use your own memory allocation routines,\ndefine PNG_USER_MEM_SUPPORTED and use\npng_create_write_struct_2() instead of png_create_write_struct():\n\n    png_structp png_ptr = png_create_write_struct_2\n       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn, (png_voidp)\n        user_mem_ptr, user_malloc_fn, user_free_fn);\n\nAfter you have these structures, you will need to set up the\nerror handling.  When libpng encounters an error, it expects to\nlongjmp() back to your routine.  Therefore, you will need to call\nsetjmp() and pass the png_jmpbuf(png_ptr).  If you\nwrite the file from different routines, you will need to update\nthe png_jmpbuf(png_ptr) every time you enter a new routine that will\ncall a png_*() function.  See your documentation of setjmp/longjmp\nfor your compiler for more information on setjmp/longjmp.  See\nthe discussion on libpng error handling in the Customizing Libpng\nsection below for more information on the libpng error handling.\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n    png_destroy_write_struct(&png_ptr, &info_ptr);\n       fclose(fp);\n       return (ERROR);\n    }\n    ...\n    return;\n\nIf you would rather avoid the complexity of setjmp/longjmp issues,\nyou can compile libpng with PNG_NO_SETJMP, in which case\nerrors will result in a call to PNG_ABORT() which defaults to abort().\n\nYou can #define PNG_ABORT() to a function that does something\nmore useful than abort(), as long as your function does not\nreturn.\n\nChecking for invalid palette index on write was added at libpng\n1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues\na benign error.  This is enabled by default because this condition is an\nerror according to the PNG specification, Clause 11.3.2, but the error can\nbe ignored in each png_ptr with\n\n   png_set_check_for_invalid_index(png_ptr, 0);\n\nIf the error is ignored, or if png_benign_error() treats it as a warning,\nany invalid pixels are written as-is by the encoder, resulting in an\ninvalid PNG datastream as output.  In this case the application is\nresponsible for ensuring that the pixel indexes are in range when it writes\na PLTE chunk with fewer entries than the bit depth would allow.\n\nNow you need to set up the output code.  The default for libpng is to\nuse the C function fwrite().  If you use this, you will need to pass a\nvalid FILE * in the function png_init_io().  Be sure that the file is\nopened in binary mode.  Again, if you wish to handle writing data in\nanother way, see the discussion on libpng I/O handling in the Customizing\nLibpng section below.\n\n    png_init_io(png_ptr, fp);\n\nIf you are embedding your PNG into a datastream such as MNG, and don't\nwant libpng to write the 8-byte signature, or if you have already\nwritten the signature in your application, use\n\n    png_set_sig_bytes(png_ptr, 8);\n\nto inform libpng that it should not write a signature.\n\nWrite callbacks\n\nAt this point, you can set up a callback function that will be\ncalled after each row has been written, which you can use to control\na progress meter or the like.  It's demonstrated in pngtest.c.\nYou must supply a function\n\n    void write_row_callback(png_structp png_ptr, png_uint_32 row,\n       int pass);\n    {\n      /* put your code here */\n    }\n\n(You can give it another name that you like instead of \"write_row_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_write_status_fn(png_ptr, write_row_callback);\n\nWhen this function is called the row has already been completely processed and\nit has also been written out.  The 'row' and 'pass' refer to the next row to be\nhandled.  For the\nnon-interlaced case the row that was just handled is simply one less than the\npassed in row number, and pass will always be 0.  For the interlaced case the\nsame applies unless the row value is 0, in which case the row just handled was\nthe last one from one of the preceding passes.  Because interlacing may skip a\npass you cannot be sure that the preceding pass is just 'pass-1', if you really\nneed to know what the last pass is record (row,pass) from the callback and use\nthe last recorded value each time.\n\nAs with the user transform you can find the output row using the\nPNG_ROW_FROM_PASS_ROW macro.\n\nYou now have the option of modifying how the compression library will\nrun.  The following functions are mainly for testing, but may be useful\nin some cases, like if you need to write PNG files extremely fast and\nare willing to give up some compression, or if you want to get the\nmaximum possible compression at the expense of slower writing.  If you\nhave no special needs in this area, let the library do what it wants by\nnot calling this function at all, as it has been tuned to deliver a good\nspeed/compression ratio. The second parameter to png_set_filter() is\nthe filter method, for which the only valid values are 0 (as of the\nJuly 1999 PNG specification, version 1.2) or 64 (if you are writing\na PNG datastream that is to be embedded in a MNG datastream).  The third\nparameter is a flag that indicates which filter type(s) are to be tested\nfor each scanline.  See the PNG specification for details on the specific\nfilter types.\n\n\n    /* turn on or off filtering, and/or choose\n       specific filters.  You can use either a single\n       PNG_FILTER_VALUE_NAME or the bitwise OR of one\n       or more PNG_FILTER_NAME masks.\n     */\n    png_set_filter(png_ptr, 0,\n       PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE |\n       PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB  |\n       PNG_FILTER_UP    | PNG_FILTER_VALUE_UP   |\n       PNG_FILTER_AVG   | PNG_FILTER_VALUE_AVG  |\n       PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|\n       PNG_ALL_FILTERS  | PNG_FAST_FILTERS);\n\nIf an application wants to start and stop using particular filters during\ncompression, it should start out with all of the filters (to ensure that\nthe previous row of pixels will be stored in case it's needed later),\nand then add and remove them after the start of compression.\n\nIf you are writing a PNG datastream that is to be embedded in a MNG\ndatastream, the second parameter can be either 0 or 64.\n\nThe png_set_compression_*() functions interface to the zlib compression\nlibrary, and should mostly be ignored unless you really know what you are\ndoing.  The only generally useful call is png_set_compression_level()\nwhich changes how much time zlib spends on trying to compress the image\ndata.  See the Compression Library (zlib.h and algorithm.txt, distributed\nwith zlib) for details on the compression levels.\n\n    #include zlib.h\n\n    /* Set the zlib compression level */\n    png_set_compression_level(png_ptr,\n        Z_BEST_COMPRESSION);\n\n    /* Set other zlib parameters for compressing IDAT */\n    png_set_compression_mem_level(png_ptr, 8);\n    png_set_compression_strategy(png_ptr,\n        Z_DEFAULT_STRATEGY);\n    png_set_compression_window_bits(png_ptr, 15);\n    png_set_compression_method(png_ptr, 8);\n    png_set_compression_buffer_size(png_ptr, 8192)\n\n    /* Set zlib parameters for text compression\n     * If you don't call these, the parameters\n     * fall back on those defined for IDAT chunks\n     */\n    png_set_text_compression_mem_level(png_ptr, 8);\n    png_set_text_compression_strategy(png_ptr,\n        Z_DEFAULT_STRATEGY);\n    png_set_text_compression_window_bits(png_ptr, 15);\n    png_set_text_compression_method(png_ptr, 8);\n\nSetting the contents of info for output\n\nYou now need to fill in the png_info structure with all the data you\nwish to write before the actual image.  Note that the only thing you\nare allowed to write after the image is the text chunks and the time\nchunk (as of PNG Specification 1.2, anyway).  See png_write_end() and\nthe latest PNG specification for more information on that.  If you\nwish to write them before the image, fill them in now, and flag that\ndata as being valid.  If you want to wait until after the data, don't\nfill them until png_write_end().  For all the fields in png_info and\ntheir data types, see png.h.  For explanations of what the fields\ncontain, see the PNG specification.\n\nSome of the more important parts of the png_info are:\n\n    png_set_IHDR(png_ptr, info_ptr, width, height,\n       bit_depth, color_type, interlace_type,\n       compression_type, filter_method)\n\n    width          - holds the width of the image\n                     in pixels (up to 2^31).\n\n    height         - holds the height of the image\n                     in pixels (up to 2^31).\n\n    bit_depth      - holds the bit depth of one of the\n                     image channels.\n                     (valid values are 1, 2, 4, 8, 16\n                     and depend also on the\n                     color_type.  See also significant\n                     bits (sBIT) below).\n\n    color_type     - describes which color/alpha\n                     channels are present.\n                     PNG_COLOR_TYPE_GRAY\n                        (bit depths 1, 2, 4, 8, 16)\n                     PNG_COLOR_TYPE_GRAY_ALPHA\n                        (bit depths 8, 16)\n                     PNG_COLOR_TYPE_PALETTE\n                        (bit depths 1, 2, 4, 8)\n                     PNG_COLOR_TYPE_RGB\n                        (bit_depths 8, 16)\n                     PNG_COLOR_TYPE_RGB_ALPHA\n                        (bit_depths 8, 16)\n\n                     PNG_COLOR_MASK_PALETTE\n                     PNG_COLOR_MASK_COLOR\n                     PNG_COLOR_MASK_ALPHA\n\n    interlace_type - PNG_INTERLACE_NONE or\n                     PNG_INTERLACE_ADAM7\n\n    compression_type - (must be\n                     PNG_COMPRESSION_TYPE_DEFAULT)\n\n    filter_method  - (must be PNG_FILTER_TYPE_DEFAULT\n                     or, if you are writing a PNG to\n                     be embedded in a MNG datastream,\n                     can also be\n                     PNG_INTRAPIXEL_DIFFERENCING)\n\nIf you call png_set_IHDR(), the call must appear before any of the\nother png_set_*() functions, because they might require access to some of\nthe IHDR settings.  The remaining png_set_*() functions can be called\nin any order.\n\nIf you wish, you can reset the compression_type, interlace_type, or\nfilter_method later by calling png_set_IHDR() again; if you do this, the\nwidth, height, bit_depth, and color_type must be the same in each call.\n\n    png_set_PLTE(png_ptr, info_ptr, palette,\n       num_palette);\n\n    palette        - the palette for the file\n                     (array of png_color)\n    num_palette    - number of entries in the palette\n\n\n    png_set_gAMA(png_ptr, info_ptr, file_gamma);\n    png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);\n\n    file_gamma     - the gamma at which the image was\n                     created (PNG_INFO_gAMA)\n\n    int_file_gamma - 100,000 times the gamma at which\n                     the image was created\n\n    png_set_cHRM(png_ptr, info_ptr,  white_x, white_y, red_x, red_y,\n                     green_x, green_y, blue_x, blue_y)\n    png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,\n                     green_Y, green_Z, blue_X, blue_Y, blue_Z)\n    png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,\n                     int_red_x, int_red_y, int_green_x, int_green_y,\n                     int_blue_x, int_blue_y)\n    png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,\n                     int_red_Z, int_green_X, int_green_Y, int_green_Z,\n                     int_blue_X, int_blue_Y, int_blue_Z)\n\n    {white,red,green,blue}_{x,y}\n                     A color space encoding specified using the chromaticities\n                     of the end points and the white point.\n\n    {red,green,blue}_{X,Y,Z}\n                     A color space encoding specified using the encoding end\n                     points - the CIE tristimulus specification of the intended\n                     color of the red, green and blue channels in the PNG RGB\n                     data.  The white point is simply the sum of the three end\n                     points.\n\n    png_set_sRGB(png_ptr, info_ptr, srgb_intent);\n\n    srgb_intent    - the rendering intent\n                     (PNG_INFO_sRGB) The presence of\n                     the sRGB chunk means that the pixel\n                     data is in the sRGB color space.\n                     This chunk also implies specific\n                     values of gAMA and cHRM.  Rendering\n                     intent is the CSS-1 property that\n                     has been defined by the International\n                     Color Consortium\n                     (http://www.color.org).\n                     It can be one of\n                     PNG_sRGB_INTENT_SATURATION,\n                     PNG_sRGB_INTENT_PERCEPTUAL,\n                     PNG_sRGB_INTENT_ABSOLUTE, or\n                     PNG_sRGB_INTENT_RELATIVE.\n\n\n    png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,\n       srgb_intent);\n\n    srgb_intent    - the rendering intent\n                     (PNG_INFO_sRGB) The presence of the\n                     sRGB chunk means that the pixel\n                     data is in the sRGB color space.\n                     This function also causes gAMA and\n                     cHRM chunks with the specific values\n                     that are consistent with sRGB to be\n                     written.\n\n    png_set_iCCP(png_ptr, info_ptr, name, compression_type,\n                       profile, proflen);\n\n    name             - The profile name.\n\n    compression_type - The compression type; always\n                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.\n                       You may give NULL to this argument to\n                       ignore it.\n\n    profile          - International Color Consortium color\n                       profile data. May contain NULs.\n\n    proflen          - length of profile data in bytes.\n\n    png_set_sBIT(png_ptr, info_ptr, sig_bit);\n\n    sig_bit        - the number of significant bits for\n                     (PNG_INFO_sBIT) each of the gray, red,\n                     green, and blue channels, whichever are\n                     appropriate for the given color type\n                     (png_color_16)\n\n    png_set_tRNS(png_ptr, info_ptr, trans_alpha,\n       num_trans, trans_color);\n\n    trans_alpha    - array of alpha (transparency)\n                     entries for palette (PNG_INFO_tRNS)\n\n    num_trans      - number of transparent entries\n                     (PNG_INFO_tRNS)\n\n    trans_color    - graylevel or color sample values\n                     (in order red, green, blue) of the\n                     single transparent color for\n                     non-paletted images (PNG_INFO_tRNS)\n\n    png_set_hIST(png_ptr, info_ptr, hist);\n\n    hist           - histogram of palette (array of\n                     png_uint_16) (PNG_INFO_hIST)\n\n    png_set_tIME(png_ptr, info_ptr, mod_time);\n\n    mod_time       - time image was last modified\n                     (PNG_VALID_tIME)\n\n    png_set_bKGD(png_ptr, info_ptr, background);\n\n    background     - background color (of type\n                     png_color_16p) (PNG_VALID_bKGD)\n\n    png_set_text(png_ptr, info_ptr, text_ptr, num_text);\n\n    text_ptr       - array of png_text holding image\n                     comments\n\n    text_ptr[i].compression - type of compression used\n                 on \"text\" PNG_TEXT_COMPRESSION_NONE\n                           PNG_TEXT_COMPRESSION_zTXt\n                           PNG_ITXT_COMPRESSION_NONE\n                           PNG_ITXT_COMPRESSION_zTXt\n    text_ptr[i].key   - keyword for comment.  Must contain\n                 1-79 characters.\n    text_ptr[i].text  - text comments for current\n                         keyword.  Can be NULL or empty.\n    text_ptr[i].text_length - length of text string,\n                 after decompression, 0 for iTXt\n    text_ptr[i].itxt_length - length of itxt string,\n                 after decompression, 0 for tEXt/zTXt\n    text_ptr[i].lang  - language of comment (NULL or\n                         empty for unknown).\n    text_ptr[i].translated_keyword  - keyword in UTF-8 (NULL\n                         or empty for unknown).\n\n    Note that the itxt_length, lang, and lang_key\n    members of the text_ptr structure only exist when the\n    library is built with iTXt chunk support.  Prior to\n    libpng-1.4.0 the library was built by default without\n    iTXt support. Also note that when iTXt is supported,\n    they contain NULL pointers when the \"compression\"\n    field contains PNG_TEXT_COMPRESSION_NONE or\n    PNG_TEXT_COMPRESSION_zTXt.\n\n    num_text       - number of comments\n\n    png_set_sPLT(png_ptr, info_ptr, &palette_ptr,\n       num_spalettes);\n\n    palette_ptr    - array of png_sPLT_struct structures\n                     to be added to the list of palettes\n                     in the info structure.\n    num_spalettes  - number of palette structures to be\n                     added.\n\n    png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,\n        unit_type);\n\n    offset_x  - positive offset from the left\n                     edge of the screen\n\n    offset_y  - positive offset from the top\n                     edge of the screen\n\n    unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER\n\n    png_set_pHYs(png_ptr, info_ptr, res_x, res_y,\n        unit_type);\n\n    res_x       - pixels/unit physical resolution\n                  in x direction\n\n    res_y       - pixels/unit physical resolution\n                  in y direction\n\n    unit_type   - PNG_RESOLUTION_UNKNOWN,\n                  PNG_RESOLUTION_METER\n\n    png_set_sCAL(png_ptr, info_ptr, unit, width, height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n\n    height      - height of a pixel in physical scale units\n                  (width and height are doubles)\n\n    png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n                  expressed as a string\n\n    height      - height of a pixel in physical scale units\n                 (width and height are strings like \"2.54\")\n\n    png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,\n       num_unknowns)\n\n    unknowns          - array of png_unknown_chunk\n                        structures holding unknown chunks\n    unknowns[i].name  - name of unknown chunk\n    unknowns[i].data  - data of unknown chunk\n    unknowns[i].size  - size of unknown chunk's data\n    unknowns[i].location - position to write chunk in file\n                           0: do not write chunk\n                           PNG_HAVE_IHDR: before PLTE\n                           PNG_HAVE_PLTE: before IDAT\n                           PNG_AFTER_IDAT: after IDAT\n\nThe \"location\" member is set automatically according to\nwhat part of the output file has already been written.\nYou can change its value after calling png_set_unknown_chunks()\nas demonstrated in pngtest.c.  Within each of the \"locations\",\nthe chunks are sequenced according to their position in the\nstructure (that is, the value of \"i\", which is the order in which\nthe chunk was either read from the input file or defined with\npng_set_unknown_chunks).\n\nA quick word about text and num_text.  text is an array of png_text\nstructures.  num_text is the number of valid structures in the array.\nEach png_text structure holds a language code, a keyword, a text value,\nand a compression type.\n\nThe compression types have the same valid numbers as the compression\ntypes of the image data.  Currently, the only valid number is zero.\nHowever, you can store text either compressed or uncompressed, unlike\nimages, which always have to be compressed.  So if you don't want the\ntext compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.\nBecause tEXt and zTXt chunks don't have a language field, if you\nspecify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt\nany language code or translated keyword will not be written out.\n\nUntil text gets around a few hundred bytes, it is not worth compressing it.\nAfter the text has been written out to the file, the compression type\nis set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,\nso that it isn't written out again at the end (in case you are calling\npng_write_end() with the same struct).\n\nThe keywords that are given in the PNG Specification are:\n\n    Title            Short (one line) title or\n                     caption for image\n\n    Author           Name of image's creator\n\n    Description      Description of image (possibly long)\n\n    Copyright        Copyright notice\n\n    Creation Time    Time of original image creation\n                     (usually RFC 1123 format, see below)\n\n    Software         Software used to create the image\n\n    Disclaimer       Legal disclaimer\n\n    Warning          Warning of nature of content\n\n    Source           Device used to create the image\n\n    Comment          Miscellaneous comment; conversion\n                     from other image format\n\nThe keyword-text pairs work like this.  Keywords should be short\nsimple descriptions of what the comment is about.  Some typical\nkeywords are found in the PNG specification, as is some recommendations\non keywords.  You can repeat keywords in a file.  You can even write\nsome text before the image and some after.  For example, you may want\nto put a description of the image before the image, but leave the\ndisclaimer until after, so viewers working over modem connections\ndon't have to wait for the disclaimer to go over the modem before\nthey start seeing the image.  Finally, keywords should be full\nwords, not abbreviations.  Keywords and text are in the ISO 8859-1\n(Latin-1) character set (a superset of regular ASCII) and can not\ncontain NUL characters, and should not contain control or other\nunprintable characters.  To make the comments widely readable, stick\nwith basic ASCII, and avoid machine specific character set extensions\nlike the IBM-PC character set.  The keyword must be present, but\nyou can leave off the text string on non-compressed pairs.\nCompressed pairs must have a text string, as only the text string\nis compressed anyway, so the compression would be meaningless.\n\nPNG supports modification time via the png_time structure.  Two\nconversion routines are provided, png_convert_from_time_t() for\ntime_t and png_convert_from_struct_tm() for struct tm.  The\ntime_t routine uses gmtime().  You don't have to use either of\nthese, but if you wish to fill in the png_time structure directly,\nyou should provide the time in universal time (GMT) if possible\ninstead of your local time.  Note that the year number is the full\nyear (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and\nthat months start with 1.\n\nIf you want to store the time of the original image creation, you should\nuse a plain tEXt chunk with the \"Creation Time\" keyword.  This is\nnecessary because the \"creation time\" of a PNG image is somewhat vague,\ndepending on whether you mean the PNG file, the time the image was\ncreated in a non-PNG format, a still photo from which the image was\nscanned, or possibly the subject matter itself.  In order to facilitate\nmachine-readable dates, it is recommended that the \"Creation Time\"\ntEXt chunk use RFC 1123 format dates (e.g. \"22 May 1997 18:07:10 GMT\"),\nalthough this isn't a requirement.  Unlike the tIME chunk, the\n\"Creation Time\" tEXt chunk is not expected to be automatically changed\nby the software.  To facilitate the use of RFC 1123 dates, a function\npng_convert_to_rfc1123_buffer(buffer, png_timep) is provided to\nconvert from PNG time to an RFC 1123 format string.  The caller must provide\na writeable buffer of at least 29 bytes.\n\nWriting unknown chunks\n\nYou can use the png_set_unknown_chunks function to queue up private chunks\nfor writing.  You give it a chunk name, location, raw data, and a size.  You\nalso must use png_set_keep_unknown_chunks() to ensure that libpng will\nhandle them.  That's all there is to it.  The chunks will be written by the\nnext following png_write_info_before_PLTE, png_write_info, or png_write_end\nfunction, depending upon the specified location.  Any chunks previously\nread into the info structure's unknown-chunk list will also be written out\nin a sequence that satisfies the PNG specification's ordering rules.\n\nHere is an example of writing two private chunks, prVt and miNE:\n\n    #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n    /* Set unknown chunk data */\n    png_unknown_chunk unk_chunk[2];\n    strcpy((char *) unk_chunk[0].name, \"prVt\";\n    unk_chunk[0].data = (unsigned char *) \"PRIVATE DATA\";\n    unk_chunk[0].size = strlen(unk_chunk[0].data)+1;\n    unk_chunk[0].location = PNG_HAVE_IHDR;\n    strcpy((char *) unk_chunk[1].name, \"miNE\";\n    unk_chunk[1].data = (unsigned char *) \"MY CHUNK DATA\";\n    unk_chunk[1].size = strlen(unk_chunk[0].data)+1;\n    unk_chunk[1].location = PNG_AFTER_IDAT;\n    png_set_unknown_chunks(write_ptr, write_info_ptr,\n        unk_chunk, 2);\n    /* Needed because miNE is not safe-to-copy */\n    png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS,\n       (png_bytep) \"miNE\", 1);\n    # if PNG_LIBPNG_VER < 10600\n      /* Deal with unknown chunk location bug in 1.5.x and earlier */\n      png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_IHDR);\n      png_set_unknown_chunk_location(png, info, 1, PNG_AFTER_IDAT);\n    # endif\n    # if PNG_LIBPNG_VER < 10500\n      /* PNG_AFTER_IDAT writes two copies of the chunk prior to libpng-1.5.0,\n       * one before IDAT and another after IDAT, so don't use it; only use\n       * PNG_HAVE_IHDR location.  This call resets the location previously\n       * set by assignment and png_set_unknown_chunk_location() for chunk 1.\n       */\n      png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_IHDR);\n    # endif\n    #endif\n\nThe high-level write interface\n\nAt this point there are two ways to proceed; through the high-level\nwrite interface, or through a sequence of low-level write operations.\nYou can use the high-level interface if your image data is present\nin the info structure.  All defined output\ntransformations are permitted, enabled by the following masks.\n\n    PNG_TRANSFORM_IDENTITY      No transformation\n    PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples\n    PNG_TRANSFORM_PACKSWAP      Change order of packed\n                                pixels to LSB first\n    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images\n    PNG_TRANSFORM_SHIFT         Normalize pixels to the\n                                sBIT depth\n    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA\n                                to BGRA\n    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA\n                                to AG\n    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity\n                                to transparency\n    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples\n    PNG_TRANSFORM_STRIP_FILLER        Strip out filler\n                                      bytes (deprecated).\n    PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading\n                                      filler bytes\n    PNG_TRANSFORM_STRIP_FILLER_AFTER  Strip out trailing\n                                      filler bytes\n\nIf you have valid image data in the info structure (you can use\npng_set_rows() to put image data in the info structure), simply do this:\n\n    png_write_png(png_ptr, info_ptr, png_transforms, NULL)\n\nwhere png_transforms is an integer containing the bitwise OR of some set of\ntransformation flags.  This call is equivalent to png_write_info(),\nfollowed the set of transformations indicated by the transform mask,\nthen png_write_image(), and finally png_write_end().\n\n(The final parameter of this call is not yet used.  Someday it might point\nto transformation parameters required by some future output transform.)\n\nYou must use png_transforms and not call any png_set_transform() functions\nwhen you use png_write_png().\n\nThe low-level write interface\n\nIf you are going the low-level route instead, you are now ready to\nwrite all the file information up to the actual image data.  You do\nthis with a call to png_write_info().\n\n    png_write_info(png_ptr, info_ptr);\n\nNote that there is one transformation you may need to do before\npng_write_info().  In PNG files, the alpha channel in an image is the\nlevel of opacity.  If your data is supplied as a level of transparency,\nyou can invert the alpha channel before you write it, so that 0 is\nfully transparent and 255 (in 8-bit or paletted images) or 65535\n(in 16-bit images) is fully opaque, with\n\n    png_set_invert_alpha(png_ptr);\n\nThis must appear before png_write_info() instead of later with the\nother transformations because in the case of paletted images the tRNS\nchunk data has to be inverted before the tRNS chunk is written.  If\nyour image is not a paletted image, the tRNS data (which in such cases\nrepresents a single color to be rendered as transparent) won't need to\nbe changed, and you can safely do this transformation after your\npng_write_info() call.\n\nIf you need to write a private chunk that you want to appear before\nthe PLTE chunk when PLTE is present, you can write the PNG info in\ntwo steps, and insert code to write your own chunk between them:\n\n    png_write_info_before_PLTE(png_ptr, info_ptr);\n    png_set_unknown_chunks(png_ptr, info_ptr, ...);\n    png_write_info(png_ptr, info_ptr);\n\nAfter you've written the file information, you can set up the library\nto handle any special transformations of the image data.  The various\nways to transform the data will be described in the order that they\nshould occur.  This is important, as some of these change the color\ntype and/or bit depth of the data, and some others only work on\ncertain color types and bit depths.  Even though each transformation\nchecks to see if it has data that it can do something with, you should\nmake sure to only enable a transformation if it will be valid for the\ndata.  For example, don't swap red and blue on grayscale data.\n\nPNG files store RGB pixels packed into 3 or 6 bytes.  This code tells\nthe library to strip input data that has 4 or 8 bytes per pixel down\nto 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2\nbytes per pixel).\n\n    png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);\n\nwhere the 0 is unused, and the location is either PNG_FILLER_BEFORE or\nPNG_FILLER_AFTER, depending upon whether the filler byte in the pixel\nis stored XRGB or RGBX.\n\nPNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as\nthey can, resulting in, for example, 8 pixels per byte for 1 bit files.\nIf the data is supplied at 1 pixel per byte, use this code, which will\ncorrectly pack the pixels into a single byte:\n\n    png_set_packing(png_ptr);\n\nPNG files reduce possible bit depths to 1, 2, 4, 8, and 16.  If your\ndata is of another bit depth, you can write an sBIT chunk into the\nfile so that decoders can recover the original data if desired.\n\n    /* Set the true bit depth of the image data */\n    if (color_type & PNG_COLOR_MASK_COLOR)\n    {\n       sig_bit.red = true_bit_depth;\n       sig_bit.green = true_bit_depth;\n       sig_bit.blue = true_bit_depth;\n    }\n\n    else\n    {\n       sig_bit.gray = true_bit_depth;\n    }\n\n    if (color_type & PNG_COLOR_MASK_ALPHA)\n    {\n       sig_bit.alpha = true_bit_depth;\n    }\n\n    png_set_sBIT(png_ptr, info_ptr, &sig_bit);\n\nIf the data is stored in the row buffer in a bit depth other than\none supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),\nthis will scale the values to appear to be the correct bit depth as\nis required by PNG.\n\n    png_set_shift(png_ptr, &sig_bit);\n\nPNG files store 16-bit pixels in network byte order (big-endian,\nie. most significant bits first).  This code would be used if they are\nsupplied the other way (little-endian, i.e. least significant bits\nfirst, the way PCs store them):\n\n    if (bit_depth > 8)\n       png_set_swap(png_ptr);\n\nIf you are using packed-pixel images (1, 2, or 4 bits/pixel), and you\nneed to change the order the pixels are packed into bytes, you can use:\n\n    if (bit_depth < 8)\n       png_set_packswap(png_ptr);\n\nPNG files store 3 color pixels in red, green, blue order.  This code\nwould be used if they are supplied as blue, green, red:\n\n    png_set_bgr(png_ptr);\n\nPNG files describe monochrome as black being zero and white being\none. This code would be used if the pixels are supplied with this reversed\n(black being one and white being zero):\n\n    png_set_invert_mono(png_ptr);\n\nFinally, you can write your own transformation function if none of\nthe existing ones meets your needs.  This is done by setting a callback\nwith\n\n    png_set_write_user_transform_fn(png_ptr,\n       write_transform_fn);\n\nYou must supply the function\n\n    void write_transform_fn(png_structp png_ptr, png_row_infop\n       row_info, png_bytep data)\n\nSee pngtest.c for a working example.  Your function will be called\nbefore any of the other transformations are processed.  If supported\nlibpng also supplies an information routine that may be called from\nyour callback:\n\n   png_get_current_row_number(png_ptr);\n   png_get_current_pass_number(png_ptr);\n\nThis returns the current row passed to the transform.  With interlaced\nimages the value returned is the row in the input sub-image image.  Use\nPNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\nfind the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).\n\nThe discussion of interlace handling above contains more information on how to\nuse these values.\n\nYou can also set up a pointer to a user structure for use by your\ncallback function.\n\n    png_set_user_transform_info(png_ptr, user_ptr, 0, 0);\n\nThe user_channels and user_depth parameters of this function are ignored\nwhen writing; you can set them to zero as shown.\n\nYou can retrieve the pointer via the function png_get_user_transform_ptr().\nFor example:\n\n    voidp write_user_transform_ptr =\n       png_get_user_transform_ptr(png_ptr);\n\nIt is possible to have libpng flush any pending output, either manually,\nor automatically after a certain number of lines have been written.  To\nflush the output stream a single time call:\n\n    png_write_flush(png_ptr);\n\nand to have libpng flush the output stream periodically after a certain\nnumber of scanlines have been written, call:\n\n    png_set_flush(png_ptr, nrows);\n\nNote that the distance between rows is from the last time png_write_flush()\nwas called, or the first row of the image if it has never been called.\nSo if you write 50 lines, and then png_set_flush 25, it will flush the\noutput on the next scanline, and every 25 lines thereafter, unless\npng_write_flush() is called before 25 more lines have been written.\nIf nrows is too small (less than about 10 lines for a 640 pixel wide\nRGB image) the image compression may decrease noticeably (although this\nmay be acceptable for real-time applications).  Infrequent flushing will\nonly degrade the compression performance by a few percent over images\nthat do not use flushing.\n\nWriting the image data\n\nThat's it for the transformations.  Now you can write the image data.\nThe simplest way to do this is in one function call.  If you have the\nwhole image in memory, you can just call png_write_image() and libpng\nwill write the image.  You will need to pass in an array of pointers to\neach row.  This function automatically handles interlacing, so you don't\nneed to call png_set_interlace_handling() or call this function multiple\ntimes, or any of that other stuff necessary with png_write_rows().\n\n    png_write_image(png_ptr, row_pointers);\n\nwhere row_pointers is:\n\n    png_byte *row_pointers[height];\n\nYou can point to void or char or whatever you use for pixels.\n\nIf you don't want to write the whole image at once, you can\nuse png_write_rows() instead.  If the file is not interlaced,\nthis is simple:\n\n    png_write_rows(png_ptr, row_pointers,\n       number_of_rows);\n\nrow_pointers is the same as in the png_write_image() call.\n\nIf you are just writing one row at a time, you can do this with\na single row_pointer instead of an array of row_pointers:\n\n    png_bytep row_pointer = row;\n\n    png_write_row(png_ptr, row_pointer);\n\nWhen the file is interlaced, things can get a good deal more complicated.\nThe only currently (as of the PNG Specification version 1.2, dated July\n1999) defined interlacing scheme for PNG files is the \"Adam7\" interlace\nscheme, that breaks down an image into seven smaller images of varying\nsize.  libpng will build these images for you, or you can do them\nyourself.  If you want to build them yourself, see the PNG specification\nfor details of which pixels to write when.\n\nIf you don't want libpng to handle the interlacing details, just\nuse png_set_interlace_handling() and call png_write_rows() the\ncorrect number of times to write all the sub-images\n(png_set_interlace_handling() returns the number of sub-images.)\n\nIf you want libpng to build the sub-images, call this before you start\nwriting any rows:\n\n    number_of_passes = png_set_interlace_handling(png_ptr);\n\nThis will return the number of passes needed.  Currently, this is seven,\nbut may change if another interlace type is added.\n\nThen write the complete image number_of_passes times.\n\n    png_write_rows(png_ptr, row_pointers, number_of_rows);\n\nThink carefully before you write an interlaced image.  Typically code that\nreads such images reads all the image data into memory, uncompressed, before\ndoing any processing.  Only code that can display an image on the fly can\ntake advantage of the interlacing and even then the image has to be exactly\nthe correct size for the output device, because scaling an image requires\nadjacent pixels and these are not available until all the passes have been\nread.\n\nIf you do write an interlaced image you will hardly ever need to handle\nthe interlacing yourself.  Call png_set_interlace_handling() and use the\napproach described above.\n\nThe only time it is conceivable that you will really need to write an\ninterlaced image pass-by-pass is when you have read one pass by pass and\nmade some pixel-by-pixel transformation to it, as described in the read\ncode above.  In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros\nto determine the size of each sub-image in turn and simply write the rows\nyou obtained from the read code.\n\nFinishing a sequential write\n\nAfter you are finished writing the image, you should finish writing\nthe file.  If you are interested in writing comments or time, you should\npass an appropriately filled png_info pointer.  If you are not interested,\nyou can pass NULL.\n\n    png_write_end(png_ptr, info_ptr);\n\nWhen you are done, you can free all memory used by libpng like this:\n\n    png_destroy_write_struct(&png_ptr, &info_ptr);\n\nIt is also possible to individually free the info_ptr members that\npoint to libpng-allocated storage with the following function:\n\n    png_free_data(png_ptr, info_ptr, mask, seq)\n\n    mask  - identifies data to be freed, a mask\n            containing the bitwise OR of one or\n            more of\n              PNG_FREE_PLTE, PNG_FREE_TRNS,\n              PNG_FREE_HIST, PNG_FREE_ICCP,\n              PNG_FREE_PCAL, PNG_FREE_ROWS,\n              PNG_FREE_SCAL, PNG_FREE_SPLT,\n              PNG_FREE_TEXT, PNG_FREE_UNKN,\n            or simply PNG_FREE_ALL\n\n    seq   - sequence number of item to be freed\n            (-1 for all items)\n\nThis function may be safely called when the relevant storage has\nalready been freed, or has not yet been allocated, or was allocated\nby the user  and not by libpng,  and will in those cases do nothing.\nThe \"seq\" parameter is ignored if only one item of the selected data\ntype, such as PLTE, is allowed.  If \"seq\" is not -1, and multiple items\nare allowed for the data type identified in the mask, such as text or\nsPLT, only the n'th item in the structure is freed, where n is \"seq\".\n\nIf you allocated data such as a palette that you passed in to libpng\nwith png_set_*, you must not free it until just before the call to\npng_destroy_write_struct().\n\nThe default behavior is only to free data that was allocated internally\nby libpng.  This can be changed, so that libpng will not free the data,\nor so that it will free data that was allocated by the user with png_malloc()\nor png_calloc() and passed in via a png_set_*() function, with\n\n    png_data_freer(png_ptr, info_ptr, freer, mask)\n\n    freer  - one of\n               PNG_DESTROY_WILL_FREE_DATA\n               PNG_SET_WILL_FREE_DATA\n               PNG_USER_WILL_FREE_DATA\n\n    mask   - which data elements are affected\n             same choices as in png_free_data()\n\nFor example, to transfer responsibility for some data from a read structure\nto a write structure, you could use\n\n    png_data_freer(read_ptr, read_info_ptr,\n       PNG_USER_WILL_FREE_DATA,\n       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)\n\n    png_data_freer(write_ptr, write_info_ptr,\n       PNG_DESTROY_WILL_FREE_DATA,\n       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)\n\nthereby briefly reassigning responsibility for freeing to the user but\nimmediately afterwards reassigning it once more to the write_destroy\nfunction.  Having done this, it would then be safe to destroy the read\nstructure and continue to use the PLTE, tRNS, and hIST data in the write\nstructure.\n\nThis function only affects data that has already been allocated.\nYou can call this function before calling after the png_set_*() functions\nto control whether the user or png_destroy_*() is supposed to free the data.\nWhen the user assumes responsibility for libpng-allocated data, the\napplication must use\npng_free() to free it, and when the user transfers responsibility to libpng\nfor data that the user has allocated, the user must have used png_malloc()\nor png_calloc() to allocate it.\n\nIf you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword\nseparately, do not transfer responsibility for freeing text_ptr to libpng,\nbecause when libpng fills a png_text structure it combines these members with\nthe key member, and png_free_data() will free only text_ptr.key.  Similarly,\nif you transfer responsibility for free'ing text_ptr from libpng to your\napplication, your application must not separately free those members.\nFor a more compact example of writing a PNG image, see the file example.c.\n\nV. Simplified API\n\nThe simplified API, which became available in libpng-1.6.0, hides the details\nof both libpng and the PNG file format itself.\nIt allows PNG files to be read into a very limited number of\nin-memory bitmap formats or to be written from the same formats.  If these\nformats do not accommodate your needs then you can, and should, use the more\nsophisticated APIs above - these support a wide variety of in-memory formats\nand a wide variety of sophisticated transformations to those formats as well\nas a wide variety of APIs to manipulate ancilliary information.\n\nTo read a PNG file using the simplified API:\n\n  1) Declare a 'png_image' structure (see below) on the stack, set the\n     version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL\n     (this is REQUIRED, your program may crash if you don't do it.)\n\n  2) Call the appropriate png_image_begin_read... function.\n\n  3) Set the png_image 'format' member to the required sample format.\n\n  4) Allocate a buffer for the image and, if required, the color-map.\n\n  5) Call png_image_finish_read to read the image and, if required, the\n     color-map into your buffers.\n\nThere are no restrictions on the format of the PNG input itself; all valid\ncolor types, bit depths, and interlace methods are acceptable, and the\ninput image is transformed as necessary to the requested in-memory format\nduring the png_image_finish_read() step.  The only caveat is that if you\nrequest a color-mapped image from a PNG that is full-color or makes\ncomplex use of an alpha channel the transformation is extremely lossy and the\nresult may look terrible.\n\nTo write a PNG file using the simplified API:\n\n  1) Declare a 'png_image' structure on the stack and memset()\n     it to all zero.\n\n  2) Initialize the members of the structure that describe the\n     image, setting the 'format' member to the format of the\n     image samples.\n\n  3) Call the appropriate png_image_write... function with a\n     pointer to the image and, if necessary, the color-map to write\n     the PNG data.\n\npng_image is a structure that describes the in-memory format of an image\nwhen it is being read or defines the in-memory format of an image that you\nneed to write.  The \"png_image\" structure contains the following members:\n\n   png_controlp opaque  Initialize to NULL, free with png_image_free\n   png_uint_32  version Set to PNG_IMAGE_VERSION\n   png_uint_32  width   Image width in pixels (columns)\n   png_uint_32  height  Image height in pixels (rows)\n   png_uint_32  format  Image format as defined below\n   png_uint_32  flags   A bit mask containing informational flags\n   png_uint_32  colormap_entries; Number of entries in the color-map\n   png_uint_32  warning_or_error;\n   char         message[64];\n\nIn the event of an error or warning the \"warning_or_error\"\nfield will be set to a non-zero value and the 'message' field will contain\na '\\0' terminated string with the libpng error or warning message.  If both\nwarnings and an error were encountered, only the error is recorded.  If there\nare multiple warnings, only the first one is recorded.\n\nThe upper 30 bits of the \"warning_or_error\" value are reserved; the low two\nbits contain a two bit code such that a value more than 1 indicates a failure\nin the API just called:\n\n   0 - no warning or error\n   1 - warning\n   2 - error\n   3 - error preceded by warning\n\nThe pixels (samples) of the image have one to four channels whose components\nhave original values in the range 0 to 1.0:\n\n  1: A single gray or luminance channel (G).\n  2: A gray/luminance channel and an alpha channel (GA).\n  3: Three red, green, blue color channels (RGB).\n  4: Three color channels and an alpha channel (RGBA).\n\nThe channels are encoded in one of two ways:\n\n  a) As a small integer, value 0..255, contained in a single byte.  For the\nalpha channel the original value is simply value/255.  For the color or\nluminance channels the value is encoded according to the sRGB specification\nand matches the 8-bit format expected by typical display devices.\n\nThe color/gray channels are not scaled (pre-multiplied) by the alpha\nchannel and are suitable for passing to color management software.\n\n  b) As a value in the range 0..65535, contained in a 2-byte integer, in\nthe native byte order of the platform on which the application is running.\nAll channels can be converted to the original value by dividing by 65535; all\nchannels are linear.  Color channels use the RGB encoding (RGB end-points) of\nthe sRGB specification.  This encoding is identified by the\nPNG_FORMAT_FLAG_LINEAR flag below.\n\nWhen the simplified API needs to convert between sRGB and linear colorspaces,\nthe actual sRGB transfer curve defined in the sRGB specification (see the\narticle at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2\napproximation used elsewhere in libpng.\n\nWhen an alpha channel is present it is expected to denote pixel coverage\nof the color or luminance channels and is returned as an associated alpha\nchannel: the color/gray channels are scaled (pre-multiplied) by the alpha\nvalue.\n\nThe samples are either contained directly in the image data, between 1 and 8\nbytes per pixel according to the encoding, or are held in a color-map indexed\nby bytes in the image data.  In the case of a color-map the color-map entries\nare individual samples, encoded as above, and the image data has one byte per\npixel to select the relevant sample from the color-map.\n\nPNG_FORMAT_*\n\nThe #defines to be used in png_image::format.  Each #define identifies a\nparticular layout of channel data and, if present, alpha values.  There are\nseparate defines for each of the two component encodings.\n\nA format is built up using single bit flag values.  All combinations are\nvalid.  Formats can be built up from the flag values or you can use one of\nthe predefined values below.  When testing formats always use the FORMAT_FLAG\nmacros to test for individual features - future versions of the library may\nadd new flags.\n\nWhen reading or writing color-mapped images the format should be set to the\nformat of the entries in the color-map then png_image_{read,write}_colormap\ncalled to read or write the color-map and set the format correctly for the\nimage data.  Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!\n\nNOTE: libpng can be built with particular features disabled. If you see\ncompiler errors because the definition of one of the following flags has been\ncompiled out it is because libpng does not have the required support.  It is\npossible, however, for the libpng configuration to enable the format on just\nread or just write; in that case you may see an error at run time.\nYou can guard against this by checking for the definition of the\nappropriate \"_SUPPORTED\" macro, one of:\n\n   PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED\n\n   PNG_FORMAT_FLAG_ALPHA    format with an alpha channel\n   PNG_FORMAT_FLAG_COLOR    color format: otherwise grayscale\n   PNG_FORMAT_FLAG_LINEAR   2-byte channels else 1-byte\n   PNG_FORMAT_FLAG_COLORMAP image data is color-mapped\n   PNG_FORMAT_FLAG_BGR      BGR colors, else order is RGB\n   PNG_FORMAT_FLAG_AFIRST   alpha channel comes first\n\nSupported formats are as follows.  Future versions of libpng may support more\nformats; for compatibility with older versions simply check if the format\nmacro is defined using #ifdef.  These defines describe the in-memory layout\nof the components of the pixels of the image.\n\nFirst the single byte (sRGB) formats:\n\n   PNG_FORMAT_GRAY\n   PNG_FORMAT_GA\n   PNG_FORMAT_AG\n   PNG_FORMAT_RGB\n   PNG_FORMAT_BGR\n   PNG_FORMAT_RGBA\n   PNG_FORMAT_ARGB\n   PNG_FORMAT_BGRA\n   PNG_FORMAT_ABGR\n\nThen the linear 2-byte formats.  When naming these \"Y\" is used to\nindicate a luminance (gray) channel.  The component order within the pixel\nis always the same - there is no provision for swapping the order of the\ncomponents in the linear format.  The components are 16-bit integers in\nthe native byte order for your platform, and there is no provision for\nswapping the bytes to a different endian condition.\n\n   PNG_FORMAT_LINEAR_Y\n   PNG_FORMAT_LINEAR_Y_ALPHA\n   PNG_FORMAT_LINEAR_RGB\n   PNG_FORMAT_LINEAR_RGB_ALPHA\n\nWith color-mapped formats the image data is one byte for each pixel. The byte\nis an index into the color-map which is formatted as above.  To obtain a\ncolor-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP\nto one of the above definitions, or you can use one of the definitions below.\n\n   PNG_FORMAT_RGB_COLORMAP\n   PNG_FORMAT_BGR_COLORMAP\n   PNG_FORMAT_RGBA_COLORMAP\n   PNG_FORMAT_ARGB_COLORMAP\n   PNG_FORMAT_BGRA_COLORMAP\n   PNG_FORMAT_ABGR_COLORMAP\n\nPNG_IMAGE macros\n\nThese are convenience macros to derive information from a png_image\nstructure.  The PNG_IMAGE_SAMPLE_ macros return values appropriate to the\nactual image sample values - either the entries in the color-map or the\npixels in the image.  The PNG_IMAGE_PIXEL_ macros return corresponding values\nfor the pixels and will always return 1 for color-mapped formats.  The\nremaining macros return information about the rows in the image and the\ncomplete image.\n\nNOTE: All the macros that take a png_image::format parameter are compile time\nconstants if the format parameter is, itself, a constant.  Therefore these\nmacros can be used in array declarations and case labels where required.\nSimilarly the macros are also pre-processor constants (sizeof is not used) so\nthey can be used in #if tests.\n\n  PNG_IMAGE_SAMPLE_CHANNELS(fmt)\n    Returns the total number of channels in a given format: 1..4\n\n  PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\n    Returns the size in bytes of a single component of a pixel or color-map\n    entry (as appropriate) in the image: 1 or 2.\n\n  PNG_IMAGE_SAMPLE_SIZE(fmt)\n    This is the size of the sample data for one sample.  If the image is\n    color-mapped it is the size of one color-map entry (and image pixels are\n    one byte in size), otherwise it is the size of one image pixel.\n\n  PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\n    The maximum size of the color-map required by the format expressed in a\n    count of components.  This can be used to compile-time allocate a\n    color-map:\n\n    png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];\n\n    png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];\n\n    Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the\n    information from one of the png_image_begin_read_ APIs and dynamically\n    allocate the required memory.\n\n  PNG_IMAGE_COLORMAP_SIZE(fmt)\n   The size of the color-map required by the format; this is the size of the\n   color-map buffer passed to the png_image_{read,write}_colormap APIs. It is\n   a fixed number determined by the format so can easily be allocated on the\n   stack if necessary.\n\nCorresponding information about the pixels\n\n  PNG_IMAGE_PIXEL_CHANNELS(fmt)\n   The number of separate channels (components) in a pixel; 1 for a\n   color-mapped image.\n\n  PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\\\n   The size, in bytes, of each component in a pixel; 1 for a color-mapped\n   image.\n\n  PNG_IMAGE_PIXEL_SIZE(fmt)\n   The size, in bytes, of a complete pixel; 1 for a color-mapped image.\n\nInformation about the whole row, or whole image\n\n  PNG_IMAGE_ROW_STRIDE(image)\n   Returns the total number of components in a single row of the image; this\n   is the minimum 'row stride', the minimum count of components between each\n   row.  For a color-mapped image this is the minimum number of bytes in a\n   row.\n\n   If you need the stride measured in bytes, row_stride_bytes is\n   PNG_IMAGE_ROW_STRIDE(image) * PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\n   plus any padding bytes that your application might need, for example\n   to start the next row on a 4-byte boundary.\n\n  PNG_IMAGE_BUFFER_SIZE(image, row_stride)\n   Return the size, in bytes, of an image buffer given a png_image and a row\n   stride - the number of components to leave space for in each row.\n\n  PNG_IMAGE_SIZE(image)\n   Return the size, in bytes, of the image in memory given just a png_image;\n   the row stride is the minimum stride required for the image.\n\n  PNG_IMAGE_COLORMAP_SIZE(image)\n   Return the size, in bytes, of the color-map of this image.  If the image\n   format is not a color-map format this will return a size sufficient for\n   256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if\n   you don't want to allocate a color-map in this case.\n\nPNG_IMAGE_FLAG_*\n\nFlags containing additional information about the image are held in\nthe 'flags' field of png_image.\n\n  PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB == 0x01\n    This indicates the the RGB values of the in-memory bitmap do not\n    correspond to the red, green and blue end-points defined by sRGB.\n\n  PNG_IMAGE_FLAG_FAST == 0x02\n   On write emphasise speed over compression; the resultant PNG file will be\n   larger but will be produced significantly faster, particular for large\n   images.  Do not use this option for images which will be distributed, only\n   used it when producing intermediate files that will be read back in\n   repeatedly.  For a typical 24-bit image the option will double the read\n   speed at the cost of increasing the image size by 25%, however for many\n   more compressible images the PNG file can be 10 times larger with only a\n   slight speed gain.\n\n  PNG_IMAGE_FLAG_16BIT_sRGB == 0x04\n    On read if the image is a 16-bit per component image and there is no gAMA\n    or sRGB chunk assume that the components are sRGB encoded.  Notice that\n    images output by the simplified API always have gamma information; setting\n    this flag only affects the interpretation of 16-bit images from an\n    external source.  It is recommended that the application expose this flag\n    to the user; the user can normally easily recognize the difference between\n    linear and sRGB encoding.  This flag has no effect on write - the data\n    passed to the write APIs must have the correct encoding (as defined\n    above.)\n\n    If the flag is not set (the default) input 16-bit per component data is\n    assumed to be linear.\n\n    NOTE: the flag can only be set after the png_image_begin_read_ call,\n    because that call initializes the 'flags' field.\n\nREAD APIs\n\n   The png_image passed to the read APIs must have been initialized by setting\n   the png_controlp field 'opaque' to NULL (or, better, memset the whole thing.)\n\n   int png_image_begin_read_from_file( png_imagep image,\n     const char *file_name)\n\n     The named file is opened for read and the image header\n     is filled in from the PNG header in the file.\n\n   int png_image_begin_read_from_stdio (png_imagep image,\n     FILE* file)\n\n      The PNG header is read from the stdio FILE object.\n\n   int png_image_begin_read_from_memory(png_imagep image,\n      png_const_voidp memory, png_size_t size)\n\n      The PNG header is read from the given memory buffer.\n\n   int png_image_finish_read(png_imagep image,\n      png_colorp background, void *buffer,\n      png_int_32 row_stride, void *colormap));\n\n      Finish reading the image into the supplied buffer and\n      clean up the png_image structure.\n\n      row_stride is the step, in png_byte or png_uint_16 units\n      as appropriate, between adjacent rows.  A positive stride\n      indicates that the top-most row is first in the buffer -\n      the normal top-down arrangement.  A negative stride\n      indicates that the bottom-most row is first in the buffer.\n\n      background need only be supplied if an alpha channel must\n      be removed from a png_byte format and the removal is to be\n      done by compositing on a solid color; otherwise it may be\n      NULL and any composition will be done directly onto the\n      buffer.  The value is an sRGB color to use for the\n      background, for grayscale output the green channel is used.\n\n      For linear output removing the alpha channel is always done\n      by compositing on black.\n\n   void png_image_free(png_imagep image)\n\n      Free any data allocated by libpng in image->opaque,\n      setting the pointer to NULL.  May be called at any time\n      after the structure is initialized.\n\nWhen the simplified API needs to convert between sRGB and linear colorspaces,\nthe actual sRGB transfer curve defined in the sRGB specification (see the\narticle at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2\napproximation used elsewhere in libpng.\n\nWRITE APIS\n\nFor write you must initialize a png_image structure to describe the image to\nbe written:\n\n   version: must be set to PNG_IMAGE_VERSION\n   opaque: must be initialized to NULL\n   width: image width in pixels\n   height: image height in rows\n   format: the format of the data you wish to write\n   flags: set to 0 unless one of the defined flags applies; set\n      PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images\n      where the RGB values do not correspond to the colors in sRGB.\n   colormap_entries: set to the number of entries in the color-map (0 to 256)\n\n   int png_image_write_to_file, (png_imagep image,\n      const char *file, int convert_to_8bit, const void *buffer,\n      png_int_32 row_stride, const void *colormap));\n\n      Write the image to the named file.\n\n   int png_image_write_to_memory (png_imagep image, void *memory,\n      png_alloc_size_t * PNG_RESTRICT memory_bytes,\n      int convert_to_8_bit, const void *buffer, ptrdiff_t row_stride,\n      const void *colormap));\n\n      Write the image to memory.\n\n   int png_image_write_to_stdio(png_imagep image, FILE *file,\n      int convert_to_8_bit, const void *buffer,\n      png_int_32 row_stride, const void *colormap)\n\n      Write the image to the given (FILE*).\n\nWith all write APIs if image is in one of the linear formats with\n(png_uint_16) data then setting convert_to_8_bit will cause the output to be\na (png_byte) PNG gamma encoded according to the sRGB specification, otherwise\na 16-bit linear encoded PNG file is written.\n\nWith all APIs row_stride is handled as in the read APIs - it is the spacing\nfrom one row to the next in component sized units (float) and if negative\nindicates a bottom-up row layout in the buffer.  If you pass zero, libpng will\ncalculate the row_stride for you from the width and number of channels.\n\nNote that the write API does not support interlacing, sub-8-bit pixels,\nindexed (paletted) images, or most ancillary chunks.\n\nVI. Modifying/Customizing libpng\n\nThere are two issues here.  The first is changing how libpng does\nstandard things like memory allocation, input/output, and error handling.\nThe second deals with more complicated things like adding new chunks,\nadding new transformations, and generally changing how libpng works.\nBoth of those are compile-time issues; that is, they are generally\ndetermined at the time the code is written, and there is rarely a need\nto provide the user with a means of changing them.\n\nMemory allocation, input/output, and error handling\n\nAll of the memory allocation, input/output, and error handling in libpng\ngoes through callbacks that are user-settable.  The default routines are\nin pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively.  To change\nthese functions, call the appropriate png_set_*_fn() function.\n\nMemory allocation is done through the functions png_malloc(), png_calloc(),\nand png_free().  The png_malloc() and png_free() functions currently just\ncall the standard C functions and png_calloc() calls png_malloc() and then\nclears the newly allocated memory to zero; note that png_calloc(png_ptr, size)\nis not the same as the calloc(number, size) function provided by stdlib.h.\nThere is limited support for certain systems with segmented memory\narchitectures and the types of pointers declared by png.h match this; you\nwill have to use appropriate pointers in your application.  If you prefer\nto use a different method of allocating and freeing data, you can use\npng_create_read_struct_2() or png_create_write_struct_2() to register your\nown functions as described above.  These functions also provide a void\npointer that can be retrieved via\n\n    mem_ptr=png_get_mem_ptr(png_ptr);\n\nYour replacement memory functions must have prototypes as follows:\n\n    png_voidp malloc_fn(png_structp png_ptr,\n       png_alloc_size_t size);\n\n    void free_fn(png_structp png_ptr, png_voidp ptr);\n\nYour malloc_fn() must return NULL in case of failure.  The png_malloc()\nfunction will normally call png_error() if it receives a NULL from the\nsystem memory allocator or from your replacement malloc_fn().\n\nYour free_fn() will never be called with a NULL ptr, since libpng's\npng_free() checks for NULL before calling free_fn().\n\nInput/Output in libpng is done through png_read() and png_write(),\nwhich currently just call fread() and fwrite().  The FILE * is stored in\npng_struct and is initialized via png_init_io().  If you wish to change\nthe method of I/O, the library supplies callbacks that you can set\nthrough the function png_set_read_fn() and png_set_write_fn() at run\ntime, instead of calling the png_init_io() function.  These functions\nalso provide a void pointer that can be retrieved via the function\npng_get_io_ptr().  For example:\n\n    png_set_read_fn(png_structp read_ptr,\n        voidp read_io_ptr, png_rw_ptr read_data_fn)\n\n    png_set_write_fn(png_structp write_ptr,\n        voidp write_io_ptr, png_rw_ptr write_data_fn,\n        png_flush_ptr output_flush_fn);\n\n    voidp read_io_ptr = png_get_io_ptr(read_ptr);\n    voidp write_io_ptr = png_get_io_ptr(write_ptr);\n\nThe replacement I/O functions must have prototypes as follows:\n\n    void user_read_data(png_structp png_ptr,\n        png_bytep data, png_size_t length);\n\n    void user_write_data(png_structp png_ptr,\n        png_bytep data, png_size_t length);\n\n    void user_flush_data(png_structp png_ptr);\n\nThe user_read_data() function is responsible for detecting and\nhandling end-of-data errors.\n\nSupplying NULL for the read, write, or flush functions sets them back\nto using the default C stream functions, which expect the io_ptr to\npoint to a standard *FILE structure.  It is probably a mistake\nto use NULL for one of write_data_fn and output_flush_fn but not both\nof them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.\nIt is an error to read from a write stream, and vice versa.\n\nError handling in libpng is done through png_error() and png_warning().\nErrors handled through png_error() are fatal, meaning that png_error()\nshould never return to its caller.  Currently, this is handled via\nsetjmp() and longjmp() (unless you have compiled libpng with\nPNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),\nbut you could change this to do things like exit() if you should wish,\nas long as your function does not return.\n\nOn non-fatal errors, png_warning() is called\nto print a warning message, and then control returns to the calling code.\nBy default png_error() and png_warning() print a message on stderr via\nfprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined\n(because you don't want the messages) or PNG_NO_STDIO defined (because\nfprintf() isn't available).  If you wish to change the behavior of the error\nfunctions, you will need to set up your own message callbacks.  These\nfunctions are normally supplied at the time that the png_struct is created.\nIt is also possible to redirect errors and warnings to your own replacement\nfunctions after png_create_*_struct() has been called by calling:\n\n    png_set_error_fn(png_structp png_ptr,\n        png_voidp error_ptr, png_error_ptr error_fn,\n        png_error_ptr warning_fn);\n\n    png_voidp error_ptr = png_get_error_ptr(png_ptr);\n\nIf NULL is supplied for either error_fn or warning_fn, then the libpng\ndefault function will be used, calling fprintf() and/or longjmp() if a\nproblem is encountered.  The replacement error functions should have\nparameters as follows:\n\n    void user_error_fn(png_structp png_ptr,\n        png_const_charp error_msg);\n\n    void user_warning_fn(png_structp png_ptr,\n        png_const_charp warning_msg);\n\nThe motivation behind using setjmp() and longjmp() is the C++ throw and\ncatch exception handling methods.  This makes the code much easier to write,\nas there is no need to check every return code of every function call.\nHowever, there are some uncertainties about the status of local variables\nafter a longjmp, so the user may want to be careful about doing anything\nafter setjmp returns non-zero besides returning itself.  Consult your\ncompiler documentation for more details.  For an alternative approach, you\nmay wish to use the \"cexcept\" facility (see http://cexcept.sourceforge.net),\nwhich is illustrated in pngvalid.c and in contrib/visupng.\n\nBeginning in libpng-1.4.0, the png_set_benign_errors() API became available.\nYou can use this to handle certain errors (normally handled as errors)\nas warnings.\n\n    png_set_benign_errors (png_ptr, int allowed);\n\n    allowed: 0: treat png_benign_error() as an error.\n             1: treat png_benign_error() as a warning.\n\nAs of libpng-1.6.0, the default condition is to treat benign errors as\nwarnings while reading and as errors while writing.\n\nCustom chunks\n\nIf you need to read or write custom chunks, you may need to get deeper\ninto the libpng code.  The library now has mechanisms for storing\nand writing chunks of unknown type; you can even declare callbacks\nfor custom chunks.  However, this may not be good enough if the\nlibrary code itself needs to know about interactions between your\nchunk and existing `intrinsic' chunks.\n\nIf you need to write a new intrinsic chunk, first read the PNG\nspecification. Acquire a first level of understanding of how it works.\nPay particular attention to the sections that describe chunk names,\nand look at how other chunks were designed, so you can do things\nsimilarly.  Second, check out the sections of libpng that read and\nwrite chunks.  Try to find a chunk that is similar to yours and use\nit as a template.  More details can be found in the comments inside\nthe code.  It is best to handle private or unknown chunks in a generic method,\nvia callback functions, instead of by modifying libpng functions. This\nis illustrated in pngtest.c, which uses a callback function to handle a\nprivate \"vpAg\" chunk and the new \"sTER\" chunk, which are both unknown to\nlibpng.\n\nIf you wish to write your own transformation for the data, look through\nthe part of the code that does the transformations, and check out some of\nthe simpler ones to get an idea of how they work.  Try to find a similar\ntransformation to the one you want to add and copy off of it.  More details\ncan be found in the comments inside the code itself.\n\nConfiguring for gui/windowing platforms:\n\nYou will need to write new error and warning functions that use the GUI\ninterface, as described previously, and set them to be the error and\nwarning functions at the time that png_create_*_struct() is called,\nin order to have them available during the structure initialization.\nThey can be changed later via png_set_error_fn().  On some compilers,\nyou may also have to change the memory allocators (png_malloc, etc.).\n\nConfiguring zlib:\n\nThere are special functions to configure the compression.  Perhaps the\nmost useful one changes the compression level, which currently uses\ninput compression values in the range 0 - 9.  The library normally\nuses the default compression level (Z_DEFAULT_COMPRESSION = 6).  Tests\nhave shown that for a large majority of images, compression values in\nthe range 3-6 compress nearly as well as higher levels, and do so much\nfaster.  For online applications it may be desirable to have maximum speed\n(Z_BEST_SPEED = 1).  With versions of zlib after v0.99, you can also\nspecify no compression (Z_NO_COMPRESSION = 0), but this would create\nfiles larger than just storing the raw bitmap.  You can specify the\ncompression level by calling:\n\n    #include zlib.h\n    png_set_compression_level(png_ptr, level);\n\nAnother useful one is to reduce the memory level used by the library.\nThe memory level defaults to 8, but it can be lowered if you are\nshort on memory (running DOS, for example, where you only have 640K).\nNote that the memory level does have an effect on compression; among\nother things, lower levels will result in sections of incompressible\ndata being emitted in smaller stored blocks, with a correspondingly\nlarger relative overhead of up to 15% in the worst case.\n\n    #include zlib.h\n    png_set_compression_mem_level(png_ptr, level);\n\nThe other functions are for configuring zlib.  They are not recommended\nfor normal use and may result in writing an invalid PNG file.  See\nzlib.h for more information on what these mean.\n\n    #include zlib.h\n    png_set_compression_strategy(png_ptr,\n        strategy);\n\n    png_set_compression_window_bits(png_ptr,\n        window_bits);\n\n    png_set_compression_method(png_ptr, method);\n\nThis controls the size of the IDAT chunks (default 8192):\n\n    png_set_compression_buffer_size(png_ptr, size);\n\nAs of libpng version 1.5.4, additional APIs became\navailable to set these separately for non-IDAT\ncompressed chunks such as zTXt, iTXt, and iCCP:\n\n    #include zlib.h\n    #if PNG_LIBPNG_VER >= 10504\n    png_set_text_compression_level(png_ptr, level);\n\n    png_set_text_compression_mem_level(png_ptr, level);\n\n    png_set_text_compression_strategy(png_ptr,\n        strategy);\n\n    png_set_text_compression_window_bits(png_ptr,\n        window_bits);\n\n    png_set_text_compression_method(png_ptr, method);\n    #endif\n\nControlling row filtering\n\nIf you want to control whether libpng uses filtering or not, which\nfilters are used, and how it goes about picking row filters, you\ncan call one of these functions.  The selection and configuration\nof row filters can have a significant impact on the size and\nencoding speed and a somewhat lesser impact on the decoding speed\nof an image.  Filtering is enabled by default for RGB and grayscale\nimages (with and without alpha), but not for paletted images nor\nfor any images with bit depths less than 8 bits/pixel.\n\nThe 'method' parameter sets the main filtering method, which is\ncurrently only '0' in the PNG 1.2 specification.  The 'filters'\nparameter sets which filter(s), if any, should be used for each\nscanline.  Possible values are PNG_ALL_FILTERS, PNG_NO_FILTERS,\nor PNG_FAST_FILTERS to turn filtering on and off, or to turn on\njust the fast-decoding subset of filters, respectively.\n\nIndividual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,\nPNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise\nORed together with '|' to specify one or more filters to use.\nThese filters are described in more detail in the PNG specification.\nIf you intend to change the filter type during the course of writing\nthe image, you should start with flags set for all of the filters\nyou intend to use so that libpng can initialize its internal\nstructures appropriately for all of the filter types.  (Note that this\nmeans the first row must always be adaptively filtered, because libpng\ncurrently does not allocate the filter buffers until png_write_row()\nis called for the first time.)\n\n    filters = PNG_NO_FILTERS;\n    filters = PNG_ALL_FILTERS;\n    filters = PNG_FAST_FILTERS;\n\n    or\n\n    filters = PNG_FILTER_NONE | PNG_FILTER_SUB |\n              PNG_FILTER_UP | PNG_FILTER_AVG |\n              PNG_FILTER_PAETH;\n\n    png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,\n       filters);\n\n              The second parameter can also be\n              PNG_INTRAPIXEL_DIFFERENCING if you are\n              writing a PNG to be embedded in a MNG\n              datastream.  This parameter must be the\n              same as the value of filter_method used\n              in png_set_IHDR().\n\nRequesting debug printout\n\nThe macro definition PNG_DEBUG can be used to request debugging\nprintout.  Set it to an integer value in the range 0 to 3.  Higher\nnumbers result in increasing amounts of debugging information.  The\ninformation is printed to the \"stderr\" file, unless another file\nname is specified in the PNG_DEBUG_FILE macro definition.\n\nWhen PNG_DEBUG > 0, the following functions (macros) become available:\n\n   png_debug(level, message)\n   png_debug1(level, message, p1)\n   png_debug2(level, message, p1, p2)\n\nin which \"level\" is compared to PNG_DEBUG to decide whether to print\nthe message, \"message\" is the formatted string to be printed,\nand p1 and p2 are parameters that are to be embedded in the string\naccording to printf-style formatting directives.  For example,\n\n   png_debug1(2, \"foo=%d\", foo);\n\nis expanded to\n\n   if (PNG_DEBUG > 2)\n      fprintf(PNG_DEBUG_FILE, \"foo=%d\\n\", foo);\n\nWhen PNG_DEBUG is defined but is zero, the macros aren't defined, but you\ncan still use PNG_DEBUG to control your own debugging:\n\n   #ifdef PNG_DEBUG\n       fprintf(stderr, ...\n   #endif\n\nWhen PNG_DEBUG = 1, the macros are defined, but only png_debug statements\nhaving level = 0 will be printed.  There aren't any such statements in\nthis version of libpng, but if you insert some they will be printed.\n\nVII.  MNG support\n\nThe MNG specification (available at http://www.libpng.org/pub/mng) allows\ncertain extensions to PNG for PNG images that are embedded in MNG datastreams.\nLibpng can support some of these extensions.  To enable them, use the\npng_permit_mng_features() function:\n\n   feature_set = png_permit_mng_features(png_ptr, mask)\n\n   mask is a png_uint_32 containing the bitwise OR of the\n        features you want to enable.  These include\n        PNG_FLAG_MNG_EMPTY_PLTE\n        PNG_FLAG_MNG_FILTER_64\n        PNG_ALL_MNG_FEATURES\n\n   feature_set is a png_uint_32 that is the bitwise AND of\n      your mask with the set of MNG features that is\n      supported by the version of libpng that you are using.\n\nIt is an error to use this function when reading or writing a standalone\nPNG file with the PNG 8-byte signature.  The PNG datastream must be wrapped\nin a MNG datastream.  As a minimum, it must have the MNG 8-byte signature\nand the MHDR and MEND chunks.  Libpng does not provide support for these\nor any other MNG chunks; your application must provide its own support for\nthem.  You may wish to consider using libmng (available at\nhttp://www.libmng.com) instead.\n\nVIII.  Changes to Libpng from version 0.88\n\nIt should be noted that versions of libpng later than 0.96 are not\ndistributed by the original libpng author, Guy Schalnat, nor by\nAndreas Dilger, who had taken over from Guy during 1996 and 1997, and\ndistributed versions 0.89 through 0.96, but rather by another member\nof the original PNG Group, Glenn Randers-Pehrson.  Guy and Andreas are\nstill alive and well, but they have moved on to other things.\n\nThe old libpng functions png_read_init(), png_write_init(),\npng_info_init(), png_read_destroy(), and png_write_destroy() have been\nmoved to PNG_INTERNAL in version 0.95 to discourage their use.  These\nfunctions will be removed from libpng version 1.4.0.\n\nThe preferred method of creating and initializing the libpng structures is\nvia the png_create_read_struct(), png_create_write_struct(), and\npng_create_info_struct() because they isolate the size of the structures\nfrom the application, allow version error checking, and also allow the\nuse of custom error handling routines during the initialization, which\nthe old functions do not.  The functions png_read_destroy() and\npng_write_destroy() do not actually free the memory that libpng\nallocated for these structs, but just reset the data structures, so they\ncan be used instead of png_destroy_read_struct() and\npng_destroy_write_struct() if you feel there is too much system overhead\nallocating and freeing the png_struct for each image read.\n\nSetting the error callbacks via png_set_message_fn() before\npng_read_init() as was suggested in libpng-0.88 is no longer supported\nbecause this caused applications that do not use custom error functions\nto fail if the png_ptr was not initialized to zero.  It is still possible\nto set the error callbacks AFTER png_read_init(), or to change them with\npng_set_error_fn(), which is essentially the same function, but with a new\nname to force compilation errors with applications that try to use the old\nmethod.\n\nSupport for the sCAL, iCCP, iTXt, and sPLT chunks was added at libpng-1.0.6;\nhowever, iTXt support was not enabled by default.\n\nStarting with version 1.0.7, you can find out which version of the library\nyou are using at run-time:\n\n   png_uint_32 libpng_vn = png_access_version_number();\n\nThe number libpng_vn is constructed from the major version, minor\nversion with leading zero, and release number with leading zero,\n(e.g., libpng_vn for version 1.0.7 is 10007).\n\nNote that this function does not take a png_ptr, so you can call it\nbefore you've created one.\n\nYou can also check which version of png.h you used when compiling your\napplication:\n\n   png_uint_32 application_vn = PNG_LIBPNG_VER;\n\nIX.  Changes to Libpng from version 1.0.x to 1.2.x\n\nSupport for user memory management was enabled by default.  To\naccomplish this, the functions png_create_read_struct_2(),\npng_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),\npng_malloc_default(), and png_free_default() were added.\n\nSupport for the iTXt chunk has been enabled by default as of\nversion 1.2.41.\n\nSupport for certain MNG features was enabled.\n\nSupport for numbered error messages was added.  However, we never got\naround to actually numbering the error messages.  The function\npng_set_strip_error_numbers() was added (Note: the prototype for this\nfunction was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE\nbuilds of libpng-1.2.15.  It was restored in libpng-1.2.36).\n\nThe png_malloc_warn() function was added at libpng-1.2.3.  This issues\na png_warning and returns NULL instead of aborting when it fails to\nacquire the requested memory allocation.\n\nSupport for setting user limits on image width and height was enabled\nby default.  The functions png_set_user_limits(), png_get_user_width_max(),\nand png_get_user_height_max() were added at libpng-1.2.6.\n\nThe png_set_add_alpha() function was added at libpng-1.2.7.\n\nThe function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.\nUnlike png_set_gray_1_2_4_to_8(), the new function does not expand the\ntRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is\ndeprecated.\n\nA number of macro definitions in support of runtime selection of\nassembler code features (especially Intel MMX code support) were\nadded at libpng-1.2.0:\n\n    PNG_ASM_FLAG_MMX_SUPPORT_COMPILED\n    PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU\n    PNG_ASM_FLAG_MMX_READ_COMBINE_ROW\n    PNG_ASM_FLAG_MMX_READ_INTERLACE\n    PNG_ASM_FLAG_MMX_READ_FILTER_SUB\n    PNG_ASM_FLAG_MMX_READ_FILTER_UP\n    PNG_ASM_FLAG_MMX_READ_FILTER_AVG\n    PNG_ASM_FLAG_MMX_READ_FILTER_PAETH\n    PNG_ASM_FLAGS_INITIALIZED\n    PNG_MMX_READ_FLAGS\n    PNG_MMX_FLAGS\n    PNG_MMX_WRITE_FLAGS\n    PNG_MMX_FLAGS\n\nWe added the following functions in support of runtime\nselection of assembler code features:\n\n    png_get_mmx_flagmask()\n    png_set_mmx_thresholds()\n    png_get_asm_flags()\n    png_get_mmx_bitdepth_threshold()\n    png_get_mmx_rowbytes_threshold()\n    png_set_asm_flags()\n\nWe replaced all of these functions with simple stubs in libpng-1.2.20,\nwhen the Intel assembler code was removed due to a licensing issue.\n\nThese macros are deprecated:\n\n    PNG_READ_TRANSFORMS_NOT_SUPPORTED\n    PNG_PROGRESSIVE_READ_NOT_SUPPORTED\n    PNG_NO_SEQUENTIAL_READ_SUPPORTED\n    PNG_WRITE_TRANSFORMS_NOT_SUPPORTED\n    PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED\n    PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED\n\nThey have been replaced, respectively, by:\n\n    PNG_NO_READ_TRANSFORMS\n    PNG_NO_PROGRESSIVE_READ\n    PNG_NO_SEQUENTIAL_READ\n    PNG_NO_WRITE_TRANSFORMS\n    PNG_NO_READ_ANCILLARY_CHUNKS\n    PNG_NO_WRITE_ANCILLARY_CHUNKS\n\nPNG_MAX_UINT was replaced with PNG_UINT_31_MAX.  It has been\ndeprecated since libpng-1.0.16 and libpng-1.2.6.\n\nThe function\n    png_check_sig(sig, num)\nwas replaced with\n    !png_sig_cmp(sig, 0, num)\nIt has been deprecated since libpng-0.90.\n\nThe function\n    png_set_gray_1_2_4_to_8()\nwhich also expands tRNS to alpha was replaced with\n    png_set_expand_gray_1_2_4_to_8()\nwhich does not. It has been deprecated since libpng-1.0.18 and 1.2.9.\n\nX.  Changes to Libpng from version 1.0.x/1.2.x to 1.4.x\n\nPrivate libpng prototypes and macro definitions were moved from\npng.h and pngconf.h into a new pngpriv.h header file.\n\nFunctions png_set_benign_errors(), png_benign_error(), and\npng_chunk_benign_error() were added.\n\nSupport for setting the maximum amount of memory that the application\nwill allocate for reading chunks was added, as a security measure.\nThe functions png_set_chunk_cache_max() and png_get_chunk_cache_max()\nwere added to the library.\n\nWe implemented support for I/O states by adding png_ptr member io_state\nand functions png_get_io_chunk_name() and png_get_io_state() in pngget.c\n\nWe added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level\ninput transforms.\n\nChecking for and reporting of errors in the IHDR chunk is more thorough.\n\nSupport for global arrays was removed, to improve thread safety.\n\nSome obsolete/deprecated macros and functions have been removed.\n\nTypecasted NULL definitions such as\n   #define png_voidp_NULL            (png_voidp)NULL\nwere eliminated.  If you used these in your application, just use\nNULL instead.\n\nThe png_struct and info_struct members \"trans\" and \"trans_values\" were\nchanged to \"trans_alpha\" and \"trans_color\", respectively.\n\nThe obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles\nwere removed.\n\nThe PNG_1_0_X and PNG_1_2_X macros were eliminated.\n\nThe PNG_LEGACY_SUPPORTED macro was eliminated.\n\nMany WIN32_WCE #ifdefs were removed.\n\nThe functions png_read_init(info_ptr), png_write_init(info_ptr),\npng_info_init(info_ptr), png_read_destroy(), and png_write_destroy()\nhave been removed.  They have been deprecated since libpng-0.95.\n\nThe png_permit_empty_plte() was removed. It has been deprecated\nsince libpng-1.0.9.  Use png_permit_mng_features() instead.\n\nWe removed the obsolete stub functions png_get_mmx_flagmask(),\npng_set_mmx_thresholds(), png_get_asm_flags(),\npng_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),\npng_set_asm_flags(), and png_mmx_supported()\n\nWe removed the obsolete png_check_sig(), png_memcpy_check(), and\npng_memset_check() functions.  Instead use !png_sig_cmp(), memcpy(),\nand memset(), respectively.\n\nThe function png_set_gray_1_2_4_to_8() was removed. It has been\ndeprecated since libpng-1.0.18 and 1.2.9, when it was replaced with\npng_set_expand_gray_1_2_4_to_8() because the former function also\nexpanded any tRNS chunk to an alpha channel.\n\nMacros for png_get_uint_16, png_get_uint_32, and png_get_int_32\nwere added and are used by default instead of the corresponding\nfunctions. Unfortunately,\nfrom libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the\nfunction) incorrectly returned a value of type png_uint_32.\n\nWe changed the prototype for png_malloc() from\n    png_malloc(png_structp png_ptr, png_uint_32 size)\nto\n    png_malloc(png_structp png_ptr, png_alloc_size_t size)\n\nThis also applies to the prototype for the user replacement malloc_fn().\n\nThe png_calloc() function was added and is used in place of\nof \"png_malloc(); memset();\" except in the case in png_read_png()\nwhere the array consists of pointers; in this case a \"for\" loop is used\nafter the png_malloc() to set the pointers to NULL, to give robust.\nbehavior in case the application runs out of memory part-way through\nthe process.\n\nWe changed the prototypes of png_get_compression_buffer_size() and\npng_set_compression_buffer_size() to work with png_size_t instead of\npng_uint_32.\n\nSupport for numbered error messages was removed by default, since we\nnever got around to actually numbering the error messages. The function\npng_set_strip_error_numbers() was removed from the library by default.\n\nThe png_zalloc() and png_zfree() functions are no longer exported.\nThe png_zalloc() function no longer zeroes out the memory that it\nallocates.  Applications that called png_zalloc(png_ptr, number, size)\ncan call png_calloc(png_ptr, number*size) instead, and can call\npng_free() instead of png_zfree().\n\nSupport for dithering was disabled by default in libpng-1.4.0, because\nit has not been well tested and doesn't actually \"dither\".\nThe code was not\nremoved, however, and could be enabled by building libpng with\nPNG_READ_DITHER_SUPPORTED defined.  In libpng-1.4.2, this support\nwas re-enabled, but the function was renamed png_set_quantize() to\nreflect more accurately what it actually does.  At the same time,\nthe PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to\nPNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED\nwas renamed to PNG_READ_QUANTIZE_SUPPORTED.\n\nWe removed the trailing '.' from the warning and error messages.\n\nXI.  Changes to Libpng from version 1.4.x to 1.5.x\n\nFrom libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the\nfunction) incorrectly returned a value of type png_uint_32.\nThe incorrect macro was removed from libpng-1.4.5.\n\nChecking for invalid palette index on write was added at libpng\n1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues\na benign error.  This is enabled by default because this condition is an\nerror according to the PNG specification, Clause 11.3.2, but the error can\nbe ignored in each png_ptr with\n\n   png_set_check_for_invalid_index(png_ptr, allowed);\n\n      allowed  - one of\n                 0: disable benign error (accept the\n                    invalid data without warning).\n                 1: enable benign error (treat the\n                    invalid data as an error or a\n                    warning).\n\nIf the error is ignored, or if png_benign_error() treats it as a warning,\nany invalid pixels are decoded as opaque black by the decoder and written\nas-is by the encoder.\n\nRetrieving the maximum palette index found was added at libpng-1.5.15.\nThis statement must appear after png_read_png() or png_read_image() while\nreading, and after png_write_png() or png_write_image() while writing.\n\n   int max_palette = png_get_palette_max(png_ptr, info_ptr);\n\nThis will return the maximum palette index found in the image, or \"-1\" if\nthe palette was not checked, or \"0\" if no palette was found.  Note that this\ndoes not account for any palette index used by ancillary chunks such as the\nbKGD chunk; you must check those separately to determine the maximum\npalette index actually used.\n\nThere are no substantial API changes between the non-deprecated parts of\nthe 1.4.5 API and the 1.5.0 API; however, the ability to directly access\nmembers of the main libpng control structures, png_struct and png_info,\ndeprecated in earlier versions of libpng, has been completely removed from\nlibpng 1.5, and new private \"pngstruct.h\", \"pnginfo.h\", and \"pngdebug.h\"\nheader files were created.\n\nWe no longer include zlib.h in png.h.  The include statement has been moved\nto pngstruct.h, where it is not accessible by applications. Applications that\nneed access to information in zlib.h will need to add the '#include \"zlib.h\"'\ndirective.  It does not matter whether this is placed prior to or after\nthe '\"#include png.h\"' directive.\n\nThe png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used\nand were removed.\n\nWe moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()\nmacros into a private header file (pngpriv.h) that is not accessible to\napplications.\n\nIn png_get_iCCP, the type of \"profile\" was changed from png_charpp\nto png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.\n\nThere are changes of form in png.h, including new and changed macros to\ndeclare parts of the API.  Some API functions with arguments that are\npointers to data not modified within the function have been corrected to\ndeclare these arguments with PNG_CONST.\n\nMuch of the internal use of C macros to control the library build has also\nchanged and some of this is visible in the exported header files, in\nparticular the use of macros to control data and API elements visible\nduring application compilation may require significant revision to\napplication code.  (It is extremely rare for an application to do this.)\n\nAny program that compiled against libpng 1.4 and did not use deprecated\nfeatures or access internal library structures should compile and work\nagainst libpng 1.5, except for the change in the prototype for\npng_get_iCCP() and png_set_iCCP() API functions mentioned above.\n\nlibpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of\ninterlaced images.  The macros return the number of rows and columns in\neach pass and information that can be used to de-interlace and (if\nabsolutely necessary) interlace an image.\n\nlibpng 1.5.0 adds an API png_longjmp(png_ptr, value).  This API calls\nthe application-provided png_longjmp_ptr on the internal, but application\ninitialized, longjmp buffer.  It is provided as a convenience to avoid\nthe need to use the png_jmpbuf macro, which had the unnecessary side\neffect of resetting the internal png_longjmp_ptr value.\n\nlibpng 1.5.0 includes a complete fixed point API.  By default this is\npresent along with the corresponding floating point API.  In general the\nfixed point API is faster and smaller than the floating point one because\nthe PNG file format used fixed point, not floating point.  This applies\neven if the library uses floating point in internal calculations.  A new\nmacro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library\nuses floating point arithmetic (the default) or fixed point arithmetic\ninternally for performance critical calculations such as gamma correction.\nIn some cases, the gamma calculations may produce slightly different\nresults.  This has changed the results in png_rgb_to_gray and in alpha\ncomposition (png_set_background for example). This applies even if the\noriginal image was already linear (gamma == 1.0) and, therefore, it is\nnot necessary to linearize the image.  This is because libpng has *not*\nbeen changed to optimize that case correctly, yet.\n\nFixed point support for the sCAL chunk comes with an important caveat;\nthe sCAL specification uses a decimal encoding of floating point values\nand the accuracy of PNG fixed point values is insufficient for\nrepresentation of these values. Consequently a \"string\" API\n(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading\narbitrary sCAL chunks in the absence of either the floating point API or\ninternal floating point calculations.  Starting with libpng-1.5.0, both\nof these functions are present when PNG_sCAL_SUPPORTED is defined.  Prior\nto libpng-1.5.0, their presence also depended upon PNG_FIXED_POINT_SUPPORTED\nbeing defined and PNG_FLOATING_POINT_SUPPORTED not being defined.\n\nApplications no longer need to include the optional distribution header\nfile pngusr.h or define the corresponding macros during application\nbuild in order to see the correct variant of the libpng API.  From 1.5.0\napplication code can check for the corresponding _SUPPORTED macro:\n\n#ifdef PNG_INCH_CONVERSIONS_SUPPORTED\n   /* code that uses the inch conversion APIs. */\n#endif\n\nThis macro will only be defined if the inch conversion functions have been\ncompiled into libpng.  The full set of macros, and whether or not support\nhas been compiled in, are available in the header file pnglibconf.h.\nThis header file is specific to the libpng build.  Notice that prior to\n1.5.0 the _SUPPORTED macros would always have the default definition unless\nreset by pngusr.h or by explicit settings on the compiler command line.\nThese settings may produce compiler warnings or errors in 1.5.0 because\nof macro redefinition.\n\nApplications can now choose whether to use these macros or to call the\ncorresponding function by defining PNG_USE_READ_MACROS or\nPNG_NO_USE_READ_MACROS before including png.h.  Notice that this is\nonly supported from 1.5.0; defining PNG_NO_USE_READ_MACROS prior to 1.5.0\nwill lead to a link failure.\n\nPrior to libpng-1.5.4, the zlib compressor used the same set of parameters\nwhen compressing the IDAT data and textual data such as zTXt and iCCP.\nIn libpng-1.5.4 we reinitialized the zlib stream for each type of data.\nWe added five png_set_text_*() functions for setting the parameters to\nuse with textual data.\n\nPrior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\noption was off by default, and slightly inaccurate scaling occurred.\nThis option can no longer be turned off, and the choice of accurate\nor inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()\nAPI for accurate scaling or the old png_set_strip_16_to_8() API for simple\nchopping.  In libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\nmacro became PNG_READ_SCALE_16_TO_8_SUPPORTED, and the PNG_READ_16_TO_8\nmacro became PNG_READ_STRIP_16_TO_8_SUPPORTED, to enable the two\npng_set_*_16_to_8() functions separately.\n\nPrior to libpng-1.5.4, the png_set_user_limits() function could only be\nused to reduce the width and height limits from the value of\nPNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said\nthat it could be used to override them.  Now this function will reduce or\nincrease the limits.\n\nStarting in libpng-1.5.10, the user limits can be set en masse with the\nconfiguration option PNG_SAFE_LIMITS_SUPPORTED.  If this option is enabled,\na set of \"safe\" limits is applied in pngpriv.h.  These can be overridden by\napplication calls to png_set_user_limits(), png_set_user_chunk_cache_max(),\nand/or png_set_user_malloc_max() that increase or decrease the limits.  Also,\nin libpng-1.5.10 the default width and height limits were increased\nfrom 1,000,000 to 0x7fffffff (i.e., made unlimited).  Therefore, the\nlimits are now\n                               default      safe\n   png_user_width_max        0x7fffffff    1,000,000\n   png_user_height_max       0x7fffffff    1,000,000\n   png_user_chunk_cache_max  0 (unlimited)   128\n   png_user_chunk_malloc_max 0 (unlimited) 8,000,000\n\nThe png_set_option() function (and the \"options\" member of the png struct) was\nadded to libpng-1.5.15, with option PNG_ARM_NEON.\n\nThe library now supports a complete fixed point implementation and can\nthus be used on systems that have no floating point support or very\nlimited or slow support.  Previously gamma correction, an essential part\nof complete PNG support, required reasonably fast floating point.\n\nAs part of this the choice of internal implementation has been made\nindependent of the choice of fixed versus floating point APIs and all the\nmissing fixed point APIs have been implemented.\n\nThe exact mechanism used to control attributes of API functions has\nchanged, as described in the INSTALL file.\n\nA new test program, pngvalid, is provided in addition to pngtest.\npngvalid validates the arithmetic accuracy of the gamma correction\ncalculations and includes a number of validations of the file format.\nA subset of the full range of tests is run when \"make check\" is done\n(in the 'configure' build.)  pngvalid also allows total allocated memory\nusage to be evaluated and performs additional memory overwrite validation.\n\nMany changes to individual feature macros have been made. The following\nare the changes most likely to be noticed by library builders who\nconfigure libpng:\n\n1) All feature macros now have consistent naming:\n\n#define PNG_NO_feature turns the feature off\n#define PNG_feature_SUPPORTED turns the feature on\n\npnglibconf.h contains one line for each feature macro which is either:\n\n#define PNG_feature_SUPPORTED\n\nif the feature is supported or:\n\n/*#undef PNG_feature_SUPPORTED*/\n\nif it is not.  Library code consistently checks for the 'SUPPORTED' macro.\nIt does not, and libpng applications should not, check for the 'NO' macro\nwhich will not normally be defined even if the feature is not supported.\nThe 'NO' macros are only used internally for setting or not setting the\ncorresponding 'SUPPORTED' macros.\n\nCompatibility with the old names is provided as follows:\n\nPNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED\n\nAnd the following definitions disable the corresponding feature:\n\nPNG_SETJMP_NOT_SUPPORTED disables SETJMP\nPNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS\nPNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV\nPNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS\nPNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS\nPNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS\n\nLibrary builders should remove use of the above, inconsistent, names.\n\n2) Warning and error message formatting was previously conditional on\nthe STDIO feature. The library has been changed to use the\nCONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled\nthe library no longer uses the printf(3) functions, even though the\ndefault read/write implementations use (FILE) style stdio.h functions.\n\n3) Three feature macros now control the fixed/floating point decisions:\n\nPNG_FLOATING_POINT_SUPPORTED enables the floating point APIs\n\nPNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in\npractice these are normally required internally anyway (because the PNG\nfile format is fixed point), therefore in most cases PNG_NO_FIXED_POINT\nmerely stops the function from being exported.\n\nPNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating\npoint implementation or the fixed point one.  Typically the fixed point\nimplementation is larger and slower than the floating point implementation\non a system that supports floating point; however, it may be faster on a\nsystem which lacks floating point hardware and therefore uses a software\nemulation.\n\n4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED.  This allows the\nfunctions to read and write ints to be disabled independently of\nPNG_USE_READ_MACROS, which allows libpng to be built with the functions\neven though the default is to use the macros - this allows applications\nto choose at app buildtime whether or not to use macros (previously\nimpossible because the functions weren't in the default build.)\n\nXII.  Changes to Libpng from version 1.5.x to 1.6.x\n\nA \"simplified API\" has been added (see documentation in png.h and a simple\nexample in contrib/examples/pngtopng.c).  The new publicly visible API\nincludes the following:\n\n   macros:\n     PNG_FORMAT_*\n     PNG_IMAGE_*\n   structures:\n     png_control\n     png_image\n   read functions\n     png_image_begin_read_from_file()\n     png_image_begin_read_from_stdio()\n     png_image_begin_read_from_memory()\n     png_image_finish_read()\n     png_image_free()\n   write functions\n     png_image_write_to_file()\n     png_image_write_to_memory()\n     png_image_write_to_stdio()\n\nStarting with libpng-1.6.0, you can configure libpng to prefix all exported\nsymbols, using the PNG_PREFIX macro.\n\nWe no longer include string.h in png.h.  The include statement has been moved\nto pngpriv.h, where it is not accessible by applications.  Applications that\nneed access to information in string.h must add an '#include <string.h>'\ndirective.  It does not matter whether this is placed prior to or after\nthe '#include \"png.h\"' directive.\n\nThe following API are now DEPRECATED:\n   png_info_init_3()\n   png_convert_to_rfc1123() which has been replaced\n     with png_convert_to_rfc1123_buffer()\n   png_malloc_default()\n   png_free_default()\n   png_reset_zstream()\n\nThe following have been removed:\n   png_get_io_chunk_name(), which has been replaced\n     with png_get_io_chunk_type().  The new\n     function returns a 32-bit integer instead of\n     a string.\n   The png_sizeof(), png_strlen(), png_memcpy(), png_memcmp(), and\n     png_memset() macros are no longer used in the libpng sources and\n     have been removed.  These had already been made invisible to applications\n     (i.e., defined in the private pngpriv.h header file) since libpng-1.5.0.\n\nThe signatures of many exported functions were changed, such that\n   png_structp became png_structrp or png_const_structrp\n   png_infop became png_inforp or png_const_inforp\nwhere \"rp\" indicates a \"restricted pointer\".\n\nDropped support for 16-bit platforms. The support for FAR/far types has\nbeen eliminated and the definition of png_alloc_size_t is now controlled\nby a flag so that 'small size_t' systems can select it if necessary.\n\nError detection in some chunks has improved; in particular the iCCP chunk\nreader now does pretty complete validation of the basic format.  Some bad\nprofiles that were previously accepted are now accepted with a warning or\nrejected, depending upon the png_set_benign_errors() setting, in particular\nthe very old broken Microsoft/HP 3144-byte sRGB profile.  Starting with\nlibpng-1.6.11, recognizing and checking sRGB profiles can be avoided by\nmeans of\n\n    #if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && \\\n        defined(PNG_SET_OPTION_SUPPORTED)\n       png_set_option(png_ptr, PNG_SKIP_sRGB_CHECK_PROFILE,\n           PNG_OPTION_ON);\n    #endif\n\nIt's not a good idea to do this if you are using the \"simplified API\",\nwhich needs to be able to recognize sRGB profiles conveyed via the iCCP\nchunk.\n\nThe PNG spec requirement that only grayscale profiles may appear in images\nwith color type 0 or 4 and that even if the image only contains gray pixels,\nonly RGB profiles may appear in images with color type 2, 3, or 6, is now\nenforced.  The sRGB chunk is allowed to appear in images with any color type\nand is interpreted by libpng to convey a one-tracer-curve gray profile or a\nthree-tracer-curve RGB profile as appropriate.\n\nLibpng 1.5.x erroneously used /MD for Debug DLL builds; if you used the debug\nbuilds in your app and you changed your app to use /MD you will need to\nchange it back to /MDd for libpng 1.6.x.\n\nPrior to libpng-1.6.0 a warning would be issued if the iTXt chunk contained\nan empty language field or an empty translated keyword.  Both of these\nare allowed by the PNG specification, so these warnings are no longer issued.\n\nThe library now issues an error if the application attempts to set a\ntransform after it calls png_read_update_info() or if it attempts to call\nboth png_read_update_info() and png_start_read_image() or to call either\nof them more than once.\n\nThe default condition for benign_errors is now to treat benign errors as\nwarnings while reading and as errors while writing.\n\nThe library now issues a warning if both background processing and RGB to\ngray are used when gamma correction happens. As with previous versions of\nthe library the results are numerically very incorrect in this case.\n\nThere are some minor arithmetic changes in some transforms such as\npng_set_background(), that might be detected by certain regression tests.\n\nUnknown chunk handling has been improved internally, without any API change.\nThis adds more correct option control of the unknown handling, corrects\na pre-existing bug where the per-chunk 'keep' setting is ignored, and makes\nit possible to skip IDAT chunks in the sequential reader.\n\nThe machine-generated configure files are no longer included in branches\nlibpng16 and later of the GIT repository.  They continue to be included\nin the tarball releases, however.\n\nLibpng-1.6.0 through 1.6.2 used the CMF bytes at the beginning of the IDAT\nstream to set the size of the sliding window for reading instead of using the\ndefault 32-kbyte sliding window size.  It was discovered that there are\nhundreds of PNG files in the wild that have incorrect CMF bytes that caused\nzlib to issue the \"invalid distance too far back\" error and reject the file.\nLibpng-1.6.3 and later calculate their own safe CMF from the image dimensions,\nprovide a way to revert to the libpng-1.5.x behavior (ignoring the CMF bytes\nand using a 32-kbyte sliding window), by using\n\n    png_set_option(png_ptr, PNG_MAXIMUM_INFLATE_WINDOW,\n        PNG_OPTION_ON);\n\nand provide a tool (contrib/tools/pngfix) for rewriting a PNG file while\noptimizing the CMF bytes in its IDAT chunk correctly.\n\nLibpng-1.6.0 and libpng-1.6.1 wrote uncompressed iTXt chunks with the wrong\nlength, which resulted in PNG files that cannot be read beyond the bad iTXt\nchunk.  This error was fixed in libpng-1.6.3, and a tool (called\ncontrib/tools/png-fix-itxt) has been added to the libpng distribution.\n\nStarting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated\nand safe limits are used by default (users who need larger limits\ncan still override them at compile time or run time, as described above).\n\nThe new limits are\n                                default   spec limit\n   png_user_width_max         1,000,000  2,147,483,647\n   png_user_height_max        1,000,000  2,147,483,647\n   png_user_chunk_cache_max         128  unlimited\n   png_user_chunk_malloc_max  8,000,000  unlimited\n\nStarting with libpng-1.6.18, a PNG_RELEASE_BUILD macro was added, which allows\nlibrary builders to control compilation for an installed system (a release build).\nIt can be set for testing debug or beta builds to ensure that they will compile\nwhen the build type is switched to RC or STABLE. In essence this overrides the\nPNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.\n\nStarting with libpng-1.6.19, attempting to set an over-length PLTE chunk\nis an error. Previously this requirement of the PNG specification was not\nenforced, and the palette was always limited to 256 entries. An over-length\nPLTE chunk found in an input PNG is silently truncated.\n\nXIII.  Detecting libpng\n\nThe png_get_io_ptr() function has been present since libpng-0.88, has never\nchanged, and is unaffected by conditional compilation macros.  It is the\nbest choice for use in configure scripts for detecting the presence of any\nlibpng version since 0.88.  In an autoconf \"configure.in\" you could use\n\n    AC_CHECK_LIB(png, png_get_io_ptr, ...\n\nXV. Source code repository\n\nSince about February 2009, version 1.2.34, libpng has been under \"git\" source\ncontrol.  The git repository was built from old libpng-x.y.z.tar.gz files\ngoing back to version 0.70.  You can access the git repository (read only)\nat\n\n    git://git.code.sf.net/p/libpng/code\n\nor you can browse it with a web browser by selecting the \"code\" button at\n\n    https://sourceforge.net/projects/libpng\n\nPatches can be sent to glennrp at users.sourceforge.net or to\npng-mng-implement at lists.sourceforge.net or you can upload them to\nthe libpng bug tracker at\n\n    http://libpng.sourceforge.net\n\nWe also accept patches built from the tar or zip distributions, and\nsimple verbal discriptions of bug fixes, reported either to the\nSourceForge bug tracker, to the png-mng-implement at lists.sf.net\nmailing list, or directly to glennrp.\n\nXV. Coding style\n\nOur coding style is similar to the \"Allman\" style\n(See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly\nbraces on separate lines:\n\n    if (condition)\n    {\n       action;\n    }\n\n    else if (another condition)\n    {\n       another action;\n    }\n\nThe braces can be omitted from simple one-line actions:\n\n    if (condition)\n       return (0);\n\nWe use 3-space indentation, except for continued statements which\nare usually indented the same as the first line of the statement\nplus four more spaces.\n\nFor macro definitions we use 2-space indentation, always leaving the \"#\"\nin the first column.\n\n    #ifndef PNG_NO_FEATURE\n    #  ifndef PNG_FEATURE_SUPPORTED\n    #    define PNG_FEATURE_SUPPORTED\n    #  endif\n    #endif\n\nComments appear with the leading \"/*\" at the same indentation as\nthe statement that follows the comment:\n\n    /* Single-line comment */\n    statement;\n\n    /* This is a multiple-line\n     * comment.\n     */\n    statement;\n\nVery short comments can be placed after the end of the statement\nto which they pertain:\n\n    statement;    /* comment */\n\nWe don't use C++ style (\"//\") comments. We have, however,\nused them in the past in some now-abandoned MMX assembler\ncode.\n\nFunctions and their curly braces are not indented, and\nexported functions are marked with PNGAPI:\n\n /* This is a public function that is visible to\n  * application programmers. It does thus-and-so.\n  */\n void PNGAPI\n png_exported_function(png_ptr, png_info, foo)\n {\n    body;\n }\n\nThe return type and decorations are placed on a separate line\nahead of the function name, as illustrated above.\n\nThe prototypes for all exported functions appear in png.h,\nabove the comment that says\n\n    /* Maintainer: Put new public prototypes here ... */\n\nWe mark all non-exported functions with \"/* PRIVATE */\"\":\n\n void /* PRIVATE */\n png_non_exported_function(png_ptr, png_info, foo)\n {\n    body;\n }\n\nThe prototypes for non-exported functions (except for those in\npngtest) appear in pngpriv.h above the comment that says\n\n  /* Maintainer: Put new private prototypes here ^ */\n\nTo avoid polluting the global namespace, the names of all exported\nfunctions and variables begin with \"png_\", and all publicly visible C\npreprocessor macros begin with \"PNG\".  We request that applications that\nuse libpng *not* begin any of their own symbols with either of these strings.\n\nWe put a space after the \"sizeof\" operator and we omit the\noptional parentheses around its argument when the argument\nis an expression, not a type name, and we always enclose the\nsizeof operator, with its argument, in parentheses:\n\n  (sizeof (png_uint_32))\n  (sizeof array)\n\nPrior to libpng-1.6.0 we used a \"png_sizeof()\" macro, formatted as\nthough it were a function.\n\nControl keywords if, for, while, and switch are always followed by a space\nto distinguish them from function calls, which have no trailing space. \n\nWe put a space after each comma and after each semicolon\nin \"for\" statements, and we put spaces before and after each\nC binary operator and after \"for\" or \"while\", and before\n\"?\".  We don't put a space between a typecast and the expression\nbeing cast, nor do we put one between a function name and the\nleft parenthesis that follows it:\n\n    for (i = 2; i > 0; --i)\n       y[i] = a(x) + (int)b;\n\nWe prefer #ifdef and #ifndef to #if defined() and #if !defined()\nwhen there is only one macro being tested.  We always use parentheses\nwith \"defined\".\n\nWe express integer constants that are used as bit masks in hex format,\nwith an even number of lower-case hex digits, and to make them unsigned\n(e.g., 0x00U, 0xffU, 0x0100U) and long if they are greater than 0x7fff\n(e.g., 0xffffUL).\n\nWe prefer to use underscores rather than camelCase in names, except\nfor a few type names that we inherit from zlib.h.\n\nWe prefer \"if (something != 0)\" and \"if (something == 0)\"\nover \"if (something)\" and if \"(!something)\", respectively.\n\nWe do not use the TAB character for indentation in the C sources.\n\nLines do not exceed 80 characters.\n\nOther rules can be inferred by inspecting the libpng source.\n\nXVI. Y2K Compliance in libpng\n\nSince the PNG Development group is an ad-hoc body, we can't make\nan official declaration.\n\nThis is your unofficial assurance that libpng from version 0.71 and\nupward through 1.6.25 are Y2K compliant.  It is my belief that earlier\nversions were also Y2K compliant.\n\nLibpng only has two year fields.  One is a 2-byte unsigned integer\nthat will hold years up to 65535.  The other, which is deprecated,\nholds the date in text format, and will hold years up to 9999.\n\nThe integer is\n    \"png_uint_16 year\" in png_time_struct.\n\nThe string is\n    \"char time_buffer[29]\" in png_struct.  This is no longer used\nin libpng-1.6.x and will be removed from libpng-1.7.0.\n\nThere are seven time-related functions:\n\n    png_convert_to_rfc_1123_buffer() in png.c\n      (formerly png_convert_to_rfc_1152() in error, and\n      also formerly png_convert_to_rfc_1123())\n    png_convert_from_struct_tm() in pngwrite.c, called\n      in pngwrite.c\n    png_convert_from_time_t() in pngwrite.c\n    png_get_tIME() in pngget.c\n    png_handle_tIME() in pngrutil.c, called in pngread.c\n    png_set_tIME() in pngset.c\n    png_write_tIME() in pngwutil.c, called in pngwrite.c\n\nAll appear to handle dates properly in a Y2K environment.  The\npng_convert_from_time_t() function calls gmtime() to convert from system\nclock time, which returns (year - 1900), which we properly convert to\nthe full 4-digit year.  There is a possibility that applications using\nlibpng are not passing 4-digit years into the png_convert_to_rfc_1123()\nfunction, or that they are incorrectly passing only a 2-digit year\ninstead of \"year - 1900\" into the png_convert_from_struct_tm() function,\nbut this is not under our control.  The libpng documentation has always\nstated that it works with 4-digit years, and the APIs have been\ndocumented as such.\n\nThe tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned\ninteger to hold the year, and can hold years as large as 65535.\n\nzlib, upon which libpng depends, is also Y2K compliant.  It contains\nno date-related code.\n\n\n   Glenn Randers-Pehrson\n   libpng maintainer\n   PNG Development Group\n"
  },
  {
    "path": "tess-two/jni/libpng/libpng.3",
    "content": ".TH LIBPNG 3 \"September 1, 2016\"\n.SH NAME\nlibpng \\- Portable Network Graphics (PNG) Reference Library 1.6.25\n.SH SYNOPSIS\n\\fB\n#include <png.h>\\fP\n\n\\fBpng_uint_32 png_access_version_number \\fI(void\\fP\\fB);\\fP\n\n\\fBvoid png_benign_error (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fIerror\\fP\\fB);\\fP\n\n\\fBvoid png_build_grayscale_palette (int \\fP\\fIbit_depth\\fP\\fB, png_colorp \\fIpalette\\fP\\fB);\\fP\n\n\\fBpng_voidp png_calloc (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_alloc_size_t \\fIsize\\fP\\fB);\\fP\n\n\\fBvoid png_chunk_benign_error (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fIerror\\fP\\fB);\\fP\n\n\\fBvoid png_chunk_error (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fIerror\\fP\\fB);\\fP\n\n\\fBvoid png_chunk_warning (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fImessage\\fP\\fB);\\fP\n\n\\fBvoid png_convert_from_struct_tm (png_timep \\fP\\fIptime\\fP\\fB, struct tm FAR * \\fIttime\\fP\\fB);\\fP\n\n\\fBvoid png_convert_from_time_t (png_timep \\fP\\fIptime\\fP\\fB, time_t \\fIttime\\fP\\fB);\\fP\n\n\\fBpng_charp png_convert_to_rfc1123 (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_timep \\fIptime\\fP\\fB);\\fP\n\n\\fBpng_infop png_create_info_struct (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_structp png_create_read_struct (png_const_charp \\fP\\fIuser_png_ver\\fP\\fB, png_voidp \\fP\\fIerror_ptr\\fP\\fB, png_error_ptr \\fP\\fIerror_fn\\fP\\fB, png_error_ptr \\fIwarn_fn\\fP\\fB);\\fP\n\n\\fBpng_structp png_create_read_struct_2 (png_const_charp \\fP\\fIuser_png_ver\\fP\\fB, png_voidp \\fP\\fIerror_ptr\\fP\\fB, png_error_ptr \\fP\\fIerror_fn\\fP\\fB, png_error_ptr \\fP\\fIwarn_fn\\fP\\fB, png_voidp \\fP\\fImem_ptr\\fP\\fB, png_malloc_ptr \\fP\\fImalloc_fn\\fP\\fB, png_free_ptr \\fIfree_fn\\fP\\fB);\\fP\n\n\\fBpng_structp png_create_write_struct (png_const_charp \\fP\\fIuser_png_ver\\fP\\fB, png_voidp \\fP\\fIerror_ptr\\fP\\fB, png_error_ptr \\fP\\fIerror_fn\\fP\\fB, png_error_ptr \\fIwarn_fn\\fP\\fB);\\fP\n\n\\fBpng_structp png_create_write_struct_2 (png_const_charp \\fP\\fIuser_png_ver\\fP\\fB, png_voidp \\fP\\fIerror_ptr\\fP\\fB, png_error_ptr \\fP\\fIerror_fn\\fP\\fB, png_error_ptr \\fP\\fIwarn_fn\\fP\\fB, png_voidp \\fP\\fImem_ptr\\fP\\fB, png_malloc_ptr \\fP\\fImalloc_fn\\fP\\fB, png_free_ptr \\fIfree_fn\\fP\\fB);\\fP\n\n\\fBvoid png_data_freer (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fIfreer\\fP\\fB, png_uint_32 \\fImask)\\fP\\fB);\\fP\n\n\\fBvoid png_destroy_info_struct (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infopp \\fIinfo_ptr_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_destroy_read_struct (png_structpp \\fP\\fIpng_ptr_ptr\\fP\\fB, png_infopp \\fP\\fIinfo_ptr_ptr\\fP\\fB, png_infopp \\fIend_info_ptr_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_destroy_write_struct (png_structpp \\fP\\fIpng_ptr_ptr\\fP\\fB, png_infopp \\fIinfo_ptr_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_err (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_error (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fIerror\\fP\\fB);\\fP\n\n\\fBvoid png_free (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fIptr\\fP\\fB);\\fP\n\n\\fBvoid png_free_chunk_list (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_free_default (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fIptr\\fP\\fB);\\fP\n\n\\fBvoid png_free_data (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fInum\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_bit_depth (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_bKGD (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_color_16p \\fI*background\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_channels (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_cHRM (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fP\\fI*white_x\\fP\\fB, double \\fP\\fI*white_y\\fP\\fB, double \\fP\\fI*red_x\\fP\\fB, double \\fP\\fI*red_y\\fP\\fB, double \\fP\\fI*green_x\\fP\\fB, double \\fP\\fI*green_y\\fP\\fB, double \\fP\\fI*blue_x\\fP\\fB, double \\fI*blue_y\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_cHRM_fixed (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fI*white_x\\fP\\fB, png_uint_32 \\fP\\fI*white_y\\fP\\fB, png_uint_32 \\fP\\fI*red_x\\fP\\fB, png_uint_32 \\fP\\fI*red_y\\fP\\fB, png_uint_32 \\fP\\fI*green_x\\fP\\fB, png_uint_32 \\fP\\fI*green_y\\fP\\fB, png_uint_32 \\fP\\fI*blue_x\\fP\\fB, png_uint_32 \\fI*blue_y\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_cHRM_XYZ (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fP\\fI*red_X\\fP\\fB, double \\fP\\fI*red_Y\\fP\\fB, double \\fP\\fI*red_Z\\fP\\fB, double \\fP\\fI*green_X\\fP\\fB, double \\fP\\fI*green_Y\\fP\\fB, double \\fP\\fI*green_Z\\fP\\fB, double \\fP\\fI*blue_X\\fP\\fB, double \\fP\\fI*blue_Y\\fP\\fB, double \\fI*blue_Z\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_cHRM_XYZ_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_fixed_point \\fP\\fI*int_red_X\\fP\\fB, png_fixed_point \\fP\\fI*int_red_Y\\fP\\fB, png_fixed_point \\fP\\fI*int_red_Z\\fP\\fB, png_fixed_point \\fP\\fI*int_green_X\\fP\\fB, png_fixed_point \\fP\\fI*int_green_Y\\fP\\fB, png_fixed_point \\fP\\fI*int_green_Z\\fP\\fB, png_fixed_point \\fP\\fI*int_blue_X\\fP\\fB, png_fixed_point \\fP\\fI*int_blue_Y\\fP\\fB, png_fixed_point \\fI*int_blue_Z\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_chunk_cache_max (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_alloc_size_t png_get_chunk_malloc_max (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_color_type (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_compression_buffer_size (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_compression_type (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_copyright (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_current_row_number \\fI(png_const_structp\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_current_pass_number \\fI(png_const_structp\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_error_ptr (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_filter_type (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_gAMA (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fI*file_gamma\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_gAMA_fixed (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fI*int_file_gamma\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_header_ver (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_header_version (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_hIST (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_16p \\fI*hist\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_iCCP (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_charpp \\fP\\fIname\\fP\\fB, int \\fP\\fI*compression_type\\fP\\fB, png_bytepp \\fP\\fIprofile\\fP\\fB, png_uint_32 \\fI*proflen\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_IHDR (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fI*width\\fP\\fB, png_uint_32 \\fP\\fI*height\\fP\\fB, int \\fP\\fI*bit_depth\\fP\\fB, int \\fP\\fI*color_type\\fP\\fB, int \\fP\\fI*interlace_type\\fP\\fB, int \\fP\\fI*compression_type\\fP\\fB, int \\fI*filter_type\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_image_height (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_image_width (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_int_32 png_get_int_32 (png_bytep \\fIbuf\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_interlace_type (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_io_chunk_type (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_io_ptr (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_io_state (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_libpng_ver (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBint png_get_palette_max(png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_mem_ptr (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_oFFs (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fI*offset_x\\fP\\fB, png_uint_32 \\fP\\fI*offset_y\\fP\\fB, int \\fI*unit_type\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_pCAL (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_charp \\fP\\fI*purpose\\fP\\fB, png_int_32 \\fP\\fI*X0\\fP\\fB, png_int_32 \\fP\\fI*X1\\fP\\fB, int \\fP\\fI*type\\fP\\fB, int \\fP\\fI*nparams\\fP\\fB, png_charp \\fP\\fI*units\\fP\\fB, png_charpp \\fI*params\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_pHYs (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fI*res_x\\fP\\fB, png_uint_32 \\fP\\fI*res_y\\fP\\fB, int \\fI*unit_type\\fP\\fB);\\fP\n\n\\fBfloat png_get_pixel_aspect_ratio (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_pHYs_dpi (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fI*res_x\\fP\\fB, png_uint_32 \\fP\\fI*res_y\\fP\\fB, int \\fI*unit_type\\fP\\fB);\\fP\n\n\\fBpng_fixed_point png_get_pixel_aspect_ratio_fixed (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_pixels_per_inch (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_pixels_per_meter (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_progressive_ptr (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_PLTE (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_colorp \\fP\\fI*palette\\fP\\fB, int \\fI*num_palette\\fP\\fB);\\fP\n\n\\fBpng_byte png_get_rgb_to_gray_status (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_rowbytes (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_bytepp png_get_rows (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_sBIT (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_color_8p \\fI*sig_bit\\fP\\fB);\\fP\n\n\\fBvoid png_get_sCAL (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, int* \\fP\\fIunit\\fP\\fB, double* \\fP\\fIwidth\\fP\\fB, double* \\fIheight\\fP\\fB);\\fP\n\n\\fBvoid png_get_sCAL_fixed (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, int* \\fP\\fIunit\\fP\\fB, png_fixed_pointp \\fP\\fIwidth\\fP\\fB, png_fixed_pointp \\fIheight\\fP\\fB);\\fP\n\n\\fBvoid png_get_sCAL_s (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, int* \\fP\\fIunit\\fP\\fB, png_charpp \\fP\\fIwidth\\fP\\fB, png_charpp \\fIheight\\fP\\fB);\\fP\n\n\\fBpng_bytep png_get_signature (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_sPLT (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_spalette_p \\fI*splt_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_sRGB (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fI*file_srgb_intent\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_text (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_textp \\fP\\fI*text_ptr\\fP\\fB, int \\fI*num_text\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_tIME (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_timep \\fI*mod_time\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_tRNS (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_bytep \\fP\\fI*trans_alpha\\fP\\fB, int \\fP\\fI*num_trans\\fP\\fB, png_color_16p \\fI*trans_color\\fP\\fB);\\fP\n\n\\fB/* This function is really an inline macro. \\fI*/\n\n\\fBpng_uint_16 png_get_uint_16 (png_bytep \\fIbuf\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_uint_31 (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fIbuf\\fP\\fB);\\fP\n\n\\fB/* This function is really an inline macro. \\fI*/\n\n\\fBpng_uint_32 png_get_uint_32 (png_bytep \\fIbuf\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_unknown_chunks (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_unknown_chunkpp \\fIunknowns\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_user_chunk_ptr (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_user_height_max (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_voidp png_get_user_transform_ptr (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_user_width_max (png_const_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_valid (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fIflag\\fP\\fB);\\fP\n\n\\fBfloat png_get_x_offset_inches (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_fixed_point png_get_x_offset_inches_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_int_32 png_get_x_offset_microns (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_int_32 png_get_x_offset_pixels (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_x_pixels_per_inch (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_x_pixels_per_meter (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBfloat png_get_y_offset_inches (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_fixed_point png_get_y_offset_inches_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_int_32 png_get_y_offset_microns (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_int_32 png_get_y_offset_pixels (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_y_pixels_per_inch (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_get_y_pixels_per_meter (png_const_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBint png_handle_as_unknown (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fIchunk_name\\fP\\fB);\\fP\n\n\\fBint png_image_begin_read_from_file (png_imagep \\fP\\fIimage\\fP\\fB, const char \\fI*file_name\\fP\\fB);\\fP\n\n\\fBint png_image_begin_read_from_stdio (png_imagep \\fP\\fIimage\\fP\\fB, FILE* \\fIfile\\fP\\fB);\\fP\n\n\\fBint, png_image_begin_read_from_memory (png_imagep \\fP\\fIimage\\fP\\fB, png_const_voidp \\fP\\fImemory\\fP\\fB, png_size_t \\fIsize\\fP\\fB);\\fP\n\n\\fBint png_image_finish_read (png_imagep \\fP\\fIimage\\fP\\fB, png_colorp \\fP\\fIbackground\\fP\\fB, void \\fP\\fI*buffer\\fP\\fB, png_int_32 \\fP\\fIrow_stride\\fP\\fB, void \\fI*colormap\\fP\\fB);\\fP\n\n\\fBvoid png_image_free (png_imagep \\fIimage\\fP\\fB);\\fP\n\n\\fBint png_image_write_to_file (png_imagep \\fP\\fIimage\\fP\\fB, const char \\fP\\fI*file\\fP\\fB, int \\fP\\fIconvert_to_8bit\\fP\\fB, const void \\fP\\fI*buffer\\fP\\fB, png_int_32 \\fP\\fIrow_stride\\fP\\fB, void \\fI*colormap\\fP\\fB);\\fP\n\n\\fBint png_image_write_to_memory (png_imagep \\fP\\fIimage\\fP\\fB, void \\fP\\fI*memory\\fP\\fB, png_alloc_size_t * PNG_RESTRICT \\fP\\fImemory_bytes\\fP\\fB, int \\fP\\fIconvert_to_8_bit\\fP\\fB, const void \\fP\\fI*buffer\\fP\\fB, png_int_32 \\fP\\fIrow_stride\\fP\\fB, const void \\fI*colormap)\\fP\\fB);\\fP\n\n\\fBint png_image_write_to_stdio (png_imagep \\fP\\fIimage\\fP\\fB, FILE \\fP\\fI*file\\fP\\fB, int \\fP\\fIconvert_to_8_bit\\fP\\fB, const void \\fP\\fI*buffer\\fP\\fB, png_int_32 \\fP\\fIrow_stride\\fP\\fB, void \\fI*colormap)\\fP\\fB);\\fP\n\n\\fBvoid png_info_init_3 (png_infopp \\fP\\fIinfo_ptr\\fP\\fB, png_size_t \\fIpng_info_struct_size\\fP\\fB);\\fP\n\n\\fBvoid png_init_io (png_structp \\fP\\fIpng_ptr\\fP\\fB, FILE \\fI*fp\\fP\\fB);\\fP\n\n\\fBvoid png_longjmp (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIval\\fP\\fB);\\fP\n\n\\fBpng_voidp png_malloc (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_alloc_size_t \\fIsize\\fP\\fB);\\fP\n\n\\fBpng_voidp png_malloc_default (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_alloc_size_t \\fIsize\\fP\\fB);\\fP\n\n\\fBpng_voidp png_malloc_warn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_alloc_size_t \\fIsize\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_permit_mng_features (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fImng_features_permitted\\fP\\fB);\\fP\n\n\\fBvoid png_process_data (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_bytep \\fP\\fIbuffer\\fP\\fB, png_size_t \\fIbuffer_size\\fP\\fB);\\fP\n\n\\fBpng_size_t png_process_data_pause \\fP\\fI(png_structp\\fP\\fB, int \\fIsave\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_process_data_skip \\fI(png_structp\\fP\\fB);\\fP\n\n\\fBvoid png_progressive_combine_row (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fP\\fIold_row\\fP\\fB, png_bytep \\fInew_row\\fP\\fB);\\fP\n\n\\fBvoid png_read_end (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_read_image (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytepp \\fIimage\\fP\\fB);\\fP\n\n\\fBvoid png_read_info (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_read_png (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fItransforms\\fP\\fB, png_voidp \\fIparams\\fP\\fB);\\fP\n\n\\fBvoid png_read_row (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fP\\fIrow\\fP\\fB, png_bytep \\fIdisplay_row\\fP\\fB);\\fP\n\n\\fBvoid png_read_rows (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytepp \\fP\\fIrow\\fP\\fB, png_bytepp \\fP\\fIdisplay_row\\fP\\fB, png_uint_32 \\fInum_rows\\fP\\fB);\\fP\n\n\\fBvoid png_read_update_info (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBint png_reset_zstream (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_save_int_32 (png_bytep \\fP\\fIbuf\\fP\\fB, png_int_32 \\fIi\\fP\\fB);\\fP\n\n\\fBvoid png_save_uint_16 (png_bytep \\fP\\fIbuf\\fP\\fB, unsigned int \\fIi\\fP\\fB);\\fP\n\n\\fBvoid png_save_uint_32 (png_bytep \\fP\\fIbuf\\fP\\fB, png_uint_32 \\fIi\\fP\\fB);\\fP\n\n\\fBvoid png_set_add_alpha (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fP\\fIfiller\\fP\\fB, int \\fIflags\\fP\\fB);\\fP\n\n\\fBvoid png_set_alpha_mode (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fImode\\fP\\fB, double \\fIoutput_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_alpha_mode_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fImode\\fP\\fB, png_fixed_point \\fIoutput_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_background (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_color_16p \\fP\\fIbackground_color\\fP\\fB, int \\fP\\fIbackground_gamma_code\\fP\\fB, int \\fP\\fIneed_expand\\fP\\fB, double \\fIbackground_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_background_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_color_16p \\fP\\fIbackground_color\\fP\\fB, int \\fP\\fIbackground_gamma_code\\fP\\fB, int \\fP\\fIneed_expand\\fP\\fB, png_uint_32 \\fIbackground_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_benign_errors (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIallowed\\fP\\fB);\\fP\n\n\\fBvoid png_set_bgr (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_bKGD (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_color_16p \\fIbackground\\fP\\fB);\\fP\n\n\\fBvoid png_set_check_for_invalid_index(png_structrp \\fP\\fIpng_ptr\\fP\\fB, int \\fIallowed\\fP\\fB);\\fP\n\n\\fBvoid png_set_cHRM (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fP\\fIwhite_x\\fP\\fB, double \\fP\\fIwhite_y\\fP\\fB, double \\fP\\fIred_x\\fP\\fB, double \\fP\\fIred_y\\fP\\fB, double \\fP\\fIgreen_x\\fP\\fB, double \\fP\\fIgreen_y\\fP\\fB, double \\fP\\fIblue_x\\fP\\fB, double \\fIblue_y\\fP\\fB);\\fP\n\n\\fBvoid png_set_cHRM_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fIwhite_x\\fP\\fB, png_uint_32 \\fP\\fIwhite_y\\fP\\fB, png_uint_32 \\fP\\fIred_x\\fP\\fB, png_uint_32 \\fP\\fIred_y\\fP\\fB, png_uint_32 \\fP\\fIgreen_x\\fP\\fB, png_uint_32 \\fP\\fIgreen_y\\fP\\fB, png_uint_32 \\fP\\fIblue_x\\fP\\fB, png_uint_32 \\fIblue_y\\fP\\fB);\\fP\n\n\\fBvoid png_set_cHRM_XYZ (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fP\\fIred_X\\fP\\fB, double \\fP\\fIred_Y\\fP\\fB, double \\fP\\fIred_Z\\fP\\fB, double \\fP\\fIgreen_X\\fP\\fB, double \\fP\\fIgreen_Y\\fP\\fB, double \\fP\\fIgreen_Z\\fP\\fB, double \\fP\\fIblue_X\\fP\\fB, double \\fP\\fIblue_Y\\fP\\fB, double \\fIblue_Z\\fP\\fB);\\fP\n\n\\fBvoid png_set_cHRM_XYZ_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_fixed_point \\fP\\fIint_red_X\\fP\\fB, png_fixed_point \\fP\\fIint_red_Y\\fP\\fB, png_fixed_point \\fP\\fIint_red_Z\\fP\\fB, png_fixed_point \\fP\\fIint_green_X\\fP\\fB, png_fixed_point \\fP\\fIint_green_Y\\fP\\fB, png_fixed_point \\fP\\fIint_green_Z\\fP\\fB, png_fixed_point \\fP\\fIint_blue_X\\fP\\fB, png_fixed_point \\fP\\fIint_blue_Y\\fP\\fB, png_fixed_point \\fIint_blue_Z\\fP\\fB);\\fP\n\n\\fBvoid png_set_chunk_cache_max (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fIuser_chunk_cache_max\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_level (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIlevel\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_mem_level (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fImem_level\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_method (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fImethod\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_strategy (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIstrategy\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_window_bits (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIwindow_bits\\fP\\fB);\\fP\n\n\\fBvoid png_set_crc_action (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIcrit_action\\fP\\fB, int \\fIancil_action\\fP\\fB);\\fP\n\n\\fBvoid png_set_error_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIerror_ptr\\fP\\fB, png_error_ptr \\fP\\fIerror_fn\\fP\\fB, png_error_ptr \\fIwarning_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_expand (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_expand_16 (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_expand_gray_1_2_4_to_8 (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_filler (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fP\\fIfiller\\fP\\fB, int \\fIflags\\fP\\fB);\\fP\n\n\\fBvoid png_set_filter (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fImethod\\fP\\fB, int \\fIfilters\\fP\\fB);\\fP\n\n\\fBvoid png_set_filter_heuristics (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIheuristic_method\\fP\\fB, int \\fP\\fInum_weights\\fP\\fB, png_doublep \\fP\\fIfilter_weights\\fP\\fB, png_doublep \\fIfilter_costs\\fP\\fB);\\fP\n\n\\fBvoid png_set_filter_heuristics_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIheuristic_method\\fP\\fB, int \\fP\\fInum_weights\\fP\\fB, png_fixed_point_p \\fP\\fIfilter_weights\\fP\\fB, png_fixed_point_p \\fIfilter_costs\\fP\\fB);\\fP\n\n\\fBvoid png_set_flush (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fInrows\\fP\\fB);\\fP\n\n\\fBvoid png_set_gamma (png_structp \\fP\\fIpng_ptr\\fP\\fB, double \\fP\\fIscreen_gamma\\fP\\fB, double \\fIdefault_file_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_gamma_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fP\\fIscreen_gamma\\fP\\fB, png_uint_32 \\fIdefault_file_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_gAMA (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, double \\fIfile_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_gAMA_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fIfile_gamma\\fP\\fB);\\fP\n\n\\fBvoid png_set_gray_1_2_4_to_8 (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_gray_to_rgb (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_hIST (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_16p \\fIhist\\fP\\fB);\\fP\n\n\\fBvoid png_set_iCCP (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_const_charp \\fP\\fIname\\fP\\fB, int \\fP\\fIcompression_type\\fP\\fB, png_const_bytep \\fP\\fIprofile\\fP\\fB, png_uint_32 \\fIproflen\\fP\\fB);\\fP\n\n\\fBint png_set_interlace_handling (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_invalid (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fImask\\fP\\fB);\\fP\n\n\\fBvoid png_set_invert_alpha (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_invert_mono (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_IHDR (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fIwidth\\fP\\fB, png_uint_32 \\fP\\fIheight\\fP\\fB, int \\fP\\fIbit_depth\\fP\\fB, int \\fP\\fIcolor_type\\fP\\fB, int \\fP\\fIinterlace_type\\fP\\fB, int \\fP\\fIcompression_type\\fP\\fB, int \\fIfilter_type\\fP\\fB);\\fP\n\n\\fBvoid png_set_keep_unknown_chunks (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIkeep\\fP\\fB, png_bytep \\fP\\fIchunk_list\\fP\\fB, int \\fInum_chunks\\fP\\fB);\\fP\n\n\\fBjmp_buf* png_set_longjmp_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_longjmp_ptr \\fP\\fIlongjmp_fn\\fP\\fB, size_t \\fIjmp_buf_size\\fP\\fB);\\fP\n\n\\fBvoid png_set_chunk_malloc_max (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_alloc_size_t \\fIuser_chunk_cache_max\\fP\\fB);\\fP\n\n\\fBvoid png_set_compression_buffer_size (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fIsize\\fP\\fB);\\fP\n\n\\fBvoid png_set_mem_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fImem_ptr\\fP\\fB, png_malloc_ptr \\fP\\fImalloc_fn\\fP\\fB, png_free_ptr \\fIfree_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_oFFs (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fIoffset_x\\fP\\fB, png_uint_32 \\fP\\fIoffset_y\\fP\\fB, int \\fIunit_type\\fP\\fB);\\fP\n\n\\fBint png_set_option(png_structrp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIoption\\fP\\fB, int \\fIonoff\\fP\\fB);\\fP\n\n\\fBvoid png_set_packing (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_packswap (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_palette_to_rgb (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_pCAL (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_charp \\fP\\fIpurpose\\fP\\fB, png_int_32 \\fP\\fIX0\\fP\\fB, png_int_32 \\fP\\fIX1\\fP\\fB, int \\fP\\fItype\\fP\\fB, int \\fP\\fInparams\\fP\\fB, png_charp \\fP\\fIunits\\fP\\fB, png_charpp \\fIparams\\fP\\fB);\\fP\n\n\\fBvoid png_set_pHYs (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_uint_32 \\fP\\fIres_x\\fP\\fB, png_uint_32 \\fP\\fIres_y\\fP\\fB, int \\fIunit_type\\fP\\fB);\\fP\n\n\\fBvoid png_set_progressive_read_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIprogressive_ptr\\fP\\fB, png_progressive_info_ptr \\fP\\fIinfo_fn\\fP\\fB, png_progressive_row_ptr \\fP\\fIrow_fn\\fP\\fB, png_progressive_end_ptr \\fIend_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_PLTE (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_colorp \\fP\\fIpalette\\fP\\fB, int \\fInum_palette\\fP\\fB);\\fP\n\n\\fBvoid png_set_quantize (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_colorp \\fP\\fIpalette\\fP\\fB, int \\fP\\fInum_palette\\fP\\fB, int \\fP\\fImaximum_colors\\fP\\fB, png_uint_16p \\fP\\fIhistogram\\fP\\fB, int \\fIfull_quantize\\fP\\fB);\\fP\n\n\\fBvoid png_set_read_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIio_ptr\\fP\\fB, png_rw_ptr \\fIread_data_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_read_status_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_read_status_ptr \\fIread_row_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_read_user_chunk_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIuser_chunk_ptr\\fP\\fB, png_user_chunk_ptr \\fIread_user_chunk_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_read_user_transform_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_user_transform_ptr \\fIread_user_transform_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_rgb_to_gray (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fP\\fIerror_action\\fP\\fB, double \\fP\\fIred\\fP\\fB, double \\fIgreen\\fP\\fB);\\fP\n\n\\fBvoid png_set_rgb_to_gray_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, int error_action png_uint_32 \\fP\\fIred\\fP\\fB, png_uint_32 \\fIgreen\\fP\\fB);\\fP\n\n\\fBvoid png_set_rows (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_bytepp \\fIrow_pointers\\fP\\fB);\\fP\n\n\\fBvoid png_set_sBIT (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_color_8p \\fIsig_bit\\fP\\fB);\\fP\n\n\\fBvoid png_set_sCAL (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fIunit\\fP\\fB, double \\fP\\fIwidth\\fP\\fB, double \\fIheight\\fP\\fB);\\fP\n\n\\fBvoid png_set_sCAL_fixed (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fIunit\\fP\\fB, png_fixed_point \\fP\\fIwidth\\fP\\fB, png_fixed_point \\fIheight\\fP\\fB);\\fP\n\n\\fBvoid png_set_sCAL_s (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fIunit\\fP\\fB, png_charp \\fP\\fIwidth\\fP\\fB, png_charp \\fIheight\\fP\\fB);\\fP\n\n\\fBvoid png_set_scale_16 (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_shift (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_color_8p \\fItrue_bits\\fP\\fB);\\fP\n\n\\fBvoid png_set_sig_bytes (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fInum_bytes\\fP\\fB);\\fP\n\n\\fBvoid png_set_sPLT (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_spalette_p \\fP\\fIsplt_ptr\\fP\\fB, int \\fInum_spalettes\\fP\\fB);\\fP\n\n\\fBvoid png_set_sRGB (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fIsrgb_intent\\fP\\fB);\\fP\n\n\\fBvoid png_set_sRGB_gAMA_and_cHRM (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fIsrgb_intent\\fP\\fB);\\fP\n\n\\fBvoid png_set_strip_16 (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_strip_alpha (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_strip_error_numbers (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fIstrip_mode\\fP\\fB);\\fP\n\n\\fBvoid png_set_swap (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_swap_alpha (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_set_text (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_textp \\fP\\fItext_ptr\\fP\\fB, int \\fInum_text\\fP\\fB);\\fP\n\n\\fBvoid png_set_text_compression_level (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIlevel\\fP\\fB);\\fP\n\n\\fBvoid png_set_text_compression_mem_level (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fImem_level\\fP\\fB);\\fP\n\n\\fBvoid png_set_text_compression_strategy (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIstrategy\\fP\\fB);\\fP\n\n\\fBvoid png_set_text_compression_window_bits (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fIwindow_bits\\fP\\fB);\\fP\n\n\\fBvoid \\fP\\fIpng_set_text_compression_method\\fP\\fB, (png_structp \\fP\\fIpng_ptr\\fP\\fB, int \\fImethod)\\fP\\fB);\\fP\n\n\\fBvoid png_set_tIME (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_timep \\fImod_time\\fP\\fB);\\fP\n\n\\fBvoid png_set_tRNS (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_bytep \\fP\\fItrans_alpha\\fP\\fB, int \\fP\\fInum_trans\\fP\\fB, png_color_16p \\fItrans_color\\fP\\fB);\\fP\n\n\\fBvoid png_set_tRNS_to_alpha (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBpng_uint_32 png_set_unknown_chunks (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, png_unknown_chunkp \\fP\\fIunknowns\\fP\\fB, int \\fP\\fInum\\fP\\fB, int \\fIlocation\\fP\\fB);\\fP\n\n\\fBvoid png_set_unknown_chunk_location (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fIchunk\\fP\\fB, int \\fIlocation\\fP\\fB);\\fP\n\n\\fBvoid png_set_user_limits (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_uint_32 \\fP\\fIuser_width_max\\fP\\fB, png_uint_32 \\fIuser_height_max\\fP\\fB);\\fP\n\n\\fBvoid png_set_user_transform_info (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIuser_transform_ptr\\fP\\fB, int \\fP\\fIuser_transform_depth\\fP\\fB, int \\fIuser_transform_channels\\fP\\fB);\\fP\n\n\\fBvoid png_set_write_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_voidp \\fP\\fIio_ptr\\fP\\fB, png_rw_ptr \\fP\\fIwrite_data_fn\\fP\\fB, png_flush_ptr \\fIoutput_flush_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_write_status_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_write_status_ptr \\fIwrite_row_fn\\fP\\fB);\\fP\n\n\\fBvoid png_set_write_user_transform_fn (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_user_transform_ptr \\fIwrite_user_transform_fn\\fP\\fB);\\fP\n\n\\fBint png_sig_cmp (png_bytep \\fP\\fIsig\\fP\\fB, png_size_t \\fP\\fIstart\\fP\\fB, png_size_t \\fInum_to_check\\fP\\fB);\\fP\n\n\\fBvoid png_start_read_image (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_warning (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_const_charp \\fImessage\\fP\\fB);\\fP\n\n\\fBvoid png_write_chunk (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fP\\fIchunk_name\\fP\\fB, png_bytep \\fP\\fIdata\\fP\\fB, png_size_t \\fIlength\\fP\\fB);\\fP\n\n\\fBvoid png_write_chunk_data (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fP\\fIdata\\fP\\fB, png_size_t \\fIlength\\fP\\fB);\\fP\n\n\\fBvoid png_write_chunk_end (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_write_chunk_start (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fP\\fIchunk_name\\fP\\fB, png_uint_32 \\fIlength\\fP\\fB);\\fP\n\n\\fBvoid png_write_end (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_write_flush (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_write_image (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytepp \\fIimage\\fP\\fB);\\fP\n\n\\fBvoid png_write_info (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_write_info_before_PLTE (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fIinfo_ptr\\fP\\fB);\\fP\n\n\\fBvoid png_write_png (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_infop \\fP\\fIinfo_ptr\\fP\\fB, int \\fP\\fItransforms\\fP\\fB, png_voidp \\fIparams\\fP\\fB);\\fP\n\n\\fBvoid png_write_row (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytep \\fIrow\\fP\\fB);\\fP\n\n\\fBvoid png_write_rows (png_structp \\fP\\fIpng_ptr\\fP\\fB, png_bytepp \\fP\\fIrow\\fP\\fB, png_uint_32 \\fInum_rows\\fP\\fB);\\fP\n\n\\fBvoid png_write_sig (png_structp \\fIpng_ptr\\fP\\fB);\\fP\n\n.SH DESCRIPTION\nThe\n.I libpng\nlibrary supports encoding, decoding, and various manipulations of\nthe Portable Network Graphics (PNG) format image files.  It uses the\n.IR zlib(3)\ncompression library.\nFollowing is a copy of the libpng-manual.txt file that accompanies libpng.\n.SH LIBPNG.TXT\nlibpng-manual.txt - A description on how to use and modify libpng\n\n libpng version 1.6.25 - September 1, 2016\n Updated and distributed by Glenn Randers-Pehrson\n <glennrp at users.sourceforge.net>\n Copyright (c) 1998-2016 Glenn Randers-Pehrson\n\n This document is released under the libpng license.\n For conditions of distribution and use, see the disclaimer\n and license in png.h\n\n Based on:\n\n libpng versions 0.97, January 1998, through 1.6.25 - September 1, 2016\n Updated and distributed by Glenn Randers-Pehrson\n Copyright (c) 1998-2016 Glenn Randers-Pehrson\n\n libpng 1.0 beta 6 - version 0.96 - May 28, 1997\n Updated and distributed by Andreas Dilger\n Copyright (c) 1996, 1997 Andreas Dilger\n\n libpng 1.0 beta 2 - version 0.88 - January 26, 1996\n For conditions of distribution and use, see copyright\n notice in png.h. Copyright (c) 1995, 1996 Guy Eric\n Schalnat, Group 42, Inc.\n\n Updated/rewritten per request in the libpng FAQ\n Copyright (c) 1995, 1996 Frank J. T. Wojcik\n December 18, 1995 & January 20, 1996\n\n TABLE OF CONTENTS\n\n    I. Introduction\n   II. Structures\n  III. Reading\n   IV. Writing\n    V. Simplified API\n   VI. Modifying/Customizing libpng\n  VII. MNG support\n VIII. Changes to Libpng from version 0.88\n   IX. Changes to Libpng from version 1.0.x to 1.2.x\n    X. Changes to Libpng from version 1.0.x/1.2.x to 1.4.x\n   XI. Changes to Libpng from version 1.4.x to 1.5.x\n  XII. Changes to Libpng from version 1.5.x to 1.6.x\n XIII. Detecting libpng\n  XIV. Source code repository\n   XV. Coding style\n  XVI. Y2K Compliance in libpng\n\n.SH I. Introduction\n\nThis file describes how to use and modify the PNG reference library\n(known as libpng) for your own use.  In addition to this\nfile, example.c is a good starting point for using the library, as\nit is heavily commented and should include everything most people\nwill need.  We assume that libpng is already installed; see the\nINSTALL file for instructions on how to configure and install libpng.\n\nFor examples of libpng usage, see the files \"example.c\", \"pngtest.c\",\nand the files in the \"contrib\" directory, all of which are included in\nthe libpng distribution.\n\nLibpng was written as a companion to the PNG specification, as a way\nof reducing the amount of time and effort it takes to support the PNG\nfile format in application programs.\n\nThe PNG specification (second edition), November 2003, is available as\na W3C Recommendation and as an ISO Standard (ISO/IEC 15948:2004 (E)) at\n<http://www.w3.org/TR/2003/REC-PNG-20031110/\nThe W3C and ISO documents have identical technical content.\n\nThe PNG-1.2 specification is available at\n<http://png-mng.sourceforge.net/pub/png/spec/1.2/>.\nIt is technically equivalent\nto the PNG specification (second edition) but has some additional material.\n\nThe PNG-1.0 specification is available as RFC 2083 \n<http://png-mng.sourceforge.net/pub/png/spec/1.0/> and as a\nW3C Recommendation <http://www.w3.org/TR/REC-png-961001>.\n\nSome additional chunks are described in the special-purpose public chunks\ndocuments at <http://www.libpng.org/pub/png/spec/register/>\n\nOther information\nabout PNG, and the latest version of libpng, can be found at the PNG home\npage, <http://www.libpng.org/pub/png/>.\n\nMost users will not have to modify the library significantly; advanced\nusers may want to modify it more.  All attempts were made to make it as\ncomplete as possible, while keeping the code easy to understand.\nCurrently, this library only supports C.  Support for other languages\nis being considered.\n\nLibpng has been designed to handle multiple sessions at one time,\nto be easily modifiable, to be portable to the vast majority of\nmachines (ANSI, K&R, 16-, 32-, and 64-bit) available, and to be easy\nto use.  The ultimate goal of libpng is to promote the acceptance of\nthe PNG file format in whatever way possible.  While there is still\nwork to be done (see the TODO file), libpng should cover the\nmajority of the needs of its users.\n\nLibpng uses zlib for its compression and decompression of PNG files.\nFurther information about zlib, and the latest version of zlib, can\nbe found at the zlib home page, <http://zlib.net/>.\nThe zlib compression utility is a general purpose utility that is\nuseful for more than PNG files, and can be used without libpng.\nSee the documentation delivered with zlib for more details.\nYou can usually find the source files for the zlib utility wherever you\nfind the libpng source files.\n\nLibpng is thread safe, provided the threads are using different\ninstances of the structures.  Each thread should have its own\npng_struct and png_info instances, and thus its own image.\nLibpng does not protect itself against two threads using the\nsame instance of a structure.\n\n.SH II. Structures\n\nThere are two main structures that are important to libpng, png_struct\nand png_info.  Both are internal structures that are no longer exposed\nin the libpng interface (as of libpng 1.5.0).\n\nThe png_info structure is designed to provide information about the\nPNG file.  At one time, the fields of png_info were intended to be\ndirectly accessible to the user.  However, this tended to cause problems\nwith applications using dynamically loaded libraries, and as a result\na set of interface functions for png_info (the png_get_*() and png_set_*()\nfunctions) was developed, and direct access to the png_info fields was\ndeprecated..\n\nThe png_struct structure is the object used by the library to decode a\nsingle image.  As of 1.5.0 this structure is also not exposed.\n\nAlmost all libpng APIs require a pointer to a png_struct as the first argument.\nMany (in particular the png_set and png_get APIs) also require a pointer\nto png_info as the second argument.  Some application visible macros\ndefined in png.h designed for basic data access (reading and writing\nintegers in the PNG format) don't take a png_info pointer, but it's almost\nalways safe to assume that a (png_struct*) has to be passed to call an API\nfunction.\n\nYou can have more than one png_info structure associated with an image,\nas illustrated in pngtest.c, one for information valid prior to the\nIDAT chunks and another (called \"end_info\" below) for things after them.\n\nThe png.h header file is an invaluable reference for programming with libpng.\nAnd while I'm on the topic, make sure you include the libpng header file:\n\n#include <png.h>\n\nand also (as of libpng-1.5.0) the zlib header file, if you need it:\n\n#include <zlib.h>\n\n.SS Types\n\nThe png.h header file defines a number of integral types used by the\nAPIs.  Most of these are fairly obvious; for example types corresponding\nto integers of particular sizes and types for passing color values.\n\nOne exception is how non-integral numbers are handled.  For application\nconvenience most APIs that take such numbers have C (double) arguments;\nhowever, internally PNG, and libpng, use 32 bit signed integers and encode\nthe value by multiplying by 100,000.  As of libpng 1.5.0 a convenience\nmacro PNG_FP_1 is defined in png.h along with a type (png_fixed_point)\nwhich is simply (png_int_32).\n\nAll APIs that take (double) arguments also have a matching API that\ntakes the corresponding fixed point integer arguments.  The fixed point\nAPI has the same name as the floating point one with \"_fixed\" appended.\nThe actual range of values permitted in the APIs is frequently less than\nthe full range of (png_fixed_point) (\\-21474 to +21474).  When APIs require\na non-negative argument the type is recorded as png_uint_32 above.  Consult\nthe header file and the text below for more information.\n\nSpecial care must be take with sCAL chunk handling because the chunk itself\nuses non-integral values encoded as strings containing decimal floating point\nnumbers.  See the comments in the header file.\n\n.SS Configuration\n\nThe main header file function declarations are frequently protected by C\npreprocessing directives of the form:\n\n    #ifdef PNG_feature_SUPPORTED\n    declare-function\n    #endif\n    ...\n    #ifdef PNG_feature_SUPPORTED\n    use-function\n    #endif\n\nThe library can be built without support for these APIs, although a\nstandard build will have all implemented APIs.  Application programs\nshould check the feature macros before using an API for maximum\nportability.  From libpng 1.5.0 the feature macros set during the build\nof libpng are recorded in the header file \"pnglibconf.h\" and this file\nis always included by png.h.\n\nIf you don't need to change the library configuration from the default, skip to\nthe next section (\"Reading\").\n\nNotice that some of the makefiles in the 'scripts' directory and (in 1.5.0) all\nof the build project files in the 'projects' directory simply copy\nscripts/pnglibconf.h.prebuilt to pnglibconf.h.  This means that these build\nsystems do not permit easy auto-configuration of the library - they only\nsupport the default configuration.\n\nThe easiest way to make minor changes to the libpng configuration when\nauto-configuration is supported is to add definitions to the command line\nusing (typically) CPPFLAGS.  For example:\n\nCPPFLAGS=\\-DPNG_NO_FLOATING_ARITHMETIC\n\nwill change the internal libpng math implementation for gamma correction and\nother arithmetic calculations to fixed point, avoiding the need for fast\nfloating point support.  The result can be seen in the generated pnglibconf.h -\nmake sure it contains the changed feature macro setting.\n\nIf you need to make more extensive configuration changes - more than one or two\nfeature macro settings - you can either add \\-DPNG_USER_CONFIG to the build\ncommand line and put a list of feature macro settings in pngusr.h or you can set\nDFA_XTRA (a makefile variable) to a file containing the same information in the\nform of 'option' settings.\n\nA. Changing pnglibconf.h\n\nA variety of methods exist to build libpng.  Not all of these support\nreconfiguration of pnglibconf.h.  To reconfigure pnglibconf.h it must either be\nrebuilt from scripts/pnglibconf.dfa using awk or it must be edited by hand.\n\nHand editing is achieved by copying scripts/pnglibconf.h.prebuilt to\npnglibconf.h and changing the lines defining the supported features, paying\nvery close attention to the 'option' information in scripts/pnglibconf.dfa\nthat describes those features and their requirements.  This is easy to get\nwrong.\n\nB. Configuration using DFA_XTRA\n\nRebuilding from pnglibconf.dfa is easy if a functioning 'awk', or a later\nvariant such as 'nawk' or 'gawk', is available.  The configure build will\nautomatically find an appropriate awk and build pnglibconf.h.\nThe scripts/pnglibconf.mak file contains a set of make rules for doing the\nsame thing if configure is not used, and many of the makefiles in the scripts\ndirectory use this approach.\n\nWhen rebuilding simply write a new file containing changed options and set\nDFA_XTRA to the name of this file.  This causes the build to append the new file\nto the end of scripts/pnglibconf.dfa.  The pngusr.dfa file should contain lines\nof the following forms:\n\neverything = off\n\nThis turns all optional features off.  Include it at the start of pngusr.dfa to\nmake it easier to build a minimal configuration.  You will need to turn at least\nsome features on afterward to enable either reading or writing code, or both.\n\noption feature on\noption feature off\n\nEnable or disable a single feature.  This will automatically enable other\nfeatures required by a feature that is turned on or disable other features that\nrequire a feature which is turned off.  Conflicting settings will cause an error\nmessage to be emitted by awk.\n\nsetting feature default value\n\nChanges the default value of setting 'feature' to 'value'.  There are a small\nnumber of settings listed at the top of pnglibconf.h, they are documented in the\nsource code.  Most of these values have performance implications for the library\nbut most of them have no visible effect on the API.  Some can also be overridden\nfrom the API.\n\nThis method of building a customized pnglibconf.h is illustrated in\ncontrib/pngminim/*.  See the \"$(PNGCONF):\" target in the makefile and\npngusr.dfa in these directories.\n\nC. Configuration using PNG_USER_CONFIG\n\nIf \\-DPNG_USER_CONFIG is added to the CPPFLAGS when pnglibconf.h is built,\nthe file pngusr.h will automatically be included before the options in\nscripts/pnglibconf.dfa are processed.  Your pngusr.h file should contain only\nmacro definitions turning features on or off or setting settings.\n\nApart from the global setting \"everything = off\" all the options listed above\ncan be set using macros in pngusr.h:\n\n#define PNG_feature_SUPPORTED\n\nis equivalent to:\n\noption feature on\n\n#define PNG_NO_feature\n\nis equivalent to:\n\noption feature off\n\n#define PNG_feature value\n\nis equivalent to:\n\nsetting feature default value\n\nNotice that in both cases, pngusr.dfa and pngusr.h, the contents of the\npngusr file you supply override the contents of scripts/pnglibconf.dfa\n\nIf confusing or incomprehensible behavior results it is possible to\nexamine the intermediate file pnglibconf.dfn to find the full set of\ndependency information for each setting and option.  Simply locate the\nfeature in the file and read the C comments that precede it.\n\nThis method is also illustrated in the contrib/pngminim/* makefiles and\npngusr.h.\n\n.SH III. Reading\n\nWe'll now walk you through the possible functions to call when reading\nin a PNG file sequentially, briefly explaining the syntax and purpose\nof each one.  See example.c and png.h for more detail.  While\nprogressive reading is covered in the next section, you will still\nneed some of the functions discussed in this section to read a PNG\nfile.\n\n.SS Setup\n\nYou will want to do the I/O initialization(*) before you get into libpng,\nso if it doesn't work, you don't have much to undo.  Of course, you\nwill also want to insure that you are, in fact, dealing with a PNG\nfile.  Libpng provides a simple check to see if a file is a PNG file.\nTo use it, pass in the first 1 to 8 bytes of the file to the function\npng_sig_cmp(), and it will return 0 (false) if the bytes match the\ncorresponding bytes of the PNG signature, or nonzero (true) otherwise.\nOf course, the more bytes you pass in, the greater the accuracy of the\nprediction.\n\nIf you are intending to keep the file pointer open for use in libpng,\nyou must ensure you don't read more than 8 bytes from the beginning\nof the file, and you also have to make a call to png_set_sig_bytes()\nwith the number of bytes you read from the beginning.  Libpng will\nthen only check the bytes (if any) that your program didn't read.\n\n(*): If you are not using the standard I/O functions, you will need\nto replace them with custom functions.  See the discussion under\nCustomizing libpng.\n\n    FILE *fp = fopen(file_name, \"rb\");\n    if (!fp)\n    {\n       return (ERROR);\n    }\n\n    if (fread(header, 1, number, fp) != number)\n    {\n       return (ERROR);\n    }\n\n    is_png = !png_sig_cmp(header, 0, number);\n    if (!is_png)\n    {\n       return (NOT_PNG);\n    }\n\nNext, png_struct and png_info need to be allocated and initialized.  In\norder to ensure that the size of these structures is correct even with a\ndynamically linked libpng, there are functions to initialize and\nallocate the structures.  We also pass the library version, optional\npointers to error handling functions, and a pointer to a data struct for\nuse by the error functions, if necessary (the pointer and functions can\nbe NULL if the default error handlers are to be used).  See the section\non Changes to Libpng below regarding the old initialization functions.\nThe structure allocation functions quietly return NULL if they fail to\ncreate the structure, so your application should check for that.\n\n    png_structp png_ptr = png_create_read_struct\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n       return (ERROR);\n\n    png_infop info_ptr = png_create_info_struct(png_ptr);\n\n    if (!info_ptr)\n    {\n       png_destroy_read_struct(&png_ptr,\n           (png_infopp)NULL, (png_infopp)NULL);\n       return (ERROR);\n    }\n\nIf you want to use your own memory allocation routines,\nuse a libpng that was built with PNG_USER_MEM_SUPPORTED defined, and use\npng_create_read_struct_2() instead of png_create_read_struct():\n\n    png_structp png_ptr = png_create_read_struct_2\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn, (png_voidp)\n        user_mem_ptr, user_malloc_fn, user_free_fn);\n\nThe error handling routines passed to png_create_read_struct()\nand the memory alloc/free routines passed to png_create_struct_2()\nare only necessary if you are not using the libpng supplied error\nhandling and memory alloc/free functions.\n\nWhen libpng encounters an error, it expects to longjmp back\nto your routine.  Therefore, you will need to call setjmp and pass\nyour png_jmpbuf(png_ptr).  If you read the file from different\nroutines, you will need to update the longjmp buffer every time you enter\na new routine that will call a png_*() function.\n\nSee your documentation of setjmp/longjmp for your compiler for more\ninformation on setjmp/longjmp.  See the discussion on libpng error\nhandling in the Customizing Libpng section below for more information\non the libpng error handling.  If an error occurs, and libpng longjmp's\nback to your setjmp, you will want to call png_destroy_read_struct() to\nfree any memory.\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           &end_info);\n       fclose(fp);\n       return (ERROR);\n    }\n\nPass (png_infopp)NULL instead of &end_info if you didn't create\nan end_info structure.\n\nIf you would rather avoid the complexity of setjmp/longjmp issues,\nyou can compile libpng with PNG_NO_SETJMP, in which case\nerrors will result in a call to PNG_ABORT() which defaults to abort().\n\nYou can #define PNG_ABORT() to a function that does something\nmore useful than abort(), as long as your function does not\nreturn.\n\nNow you need to set up the input code.  The default for libpng is to\nuse the C function fread().  If you use this, you will need to pass a\nvalid FILE * in the function png_init_io().  Be sure that the file is\nopened in binary mode.  If you wish to handle reading data in another\nway, you need not call the png_init_io() function, but you must then\nimplement the libpng I/O methods discussed in the Customizing Libpng\nsection below.\n\n    png_init_io(png_ptr, fp);\n\nIf you had previously opened the file and read any of the signature from\nthe beginning in order to see if this was a PNG file, you need to let\nlibpng know that there are some bytes missing from the start of the file.\n\n    png_set_sig_bytes(png_ptr, number);\n\nYou can change the zlib compression buffer size to be used while\nreading compressed data with\n\n    png_set_compression_buffer_size(png_ptr, buffer_size);\n\nwhere the default size is 8192 bytes.  Note that the buffer size\nis changed immediately and the buffer is reallocated immediately,\ninstead of setting a flag to be acted upon later.\n\nIf you want CRC errors to be handled in a different manner than\nthe default, use\n\n    png_set_crc_action(png_ptr, crit_action, ancil_action);\n\nThe values for png_set_crc_action() say how libpng is to handle CRC errors in\nancillary and critical chunks, and whether to use the data contained\ntherein.  Note that it is impossible to \"discard\" data in a critical\nchunk.\n\nChoices for (int) crit_action are\n   PNG_CRC_DEFAULT      0  error/quit\n   PNG_CRC_ERROR_QUIT   1  error/quit\n   PNG_CRC_WARN_USE     3  warn/use data\n   PNG_CRC_QUIET_USE    4  quiet/use data\n   PNG_CRC_NO_CHANGE    5  use the current value\n\nChoices for (int) ancil_action are\n   PNG_CRC_DEFAULT      0  error/quit\n   PNG_CRC_ERROR_QUIT   1  error/quit\n   PNG_CRC_WARN_DISCARD 2  warn/discard data\n   PNG_CRC_WARN_USE     3  warn/use data\n   PNG_CRC_QUIET_USE    4  quiet/use data\n   PNG_CRC_NO_CHANGE    5  use the current value\n\n.SS Setting up callback code\n\nYou can set up a callback function to handle any unknown chunks in the\ninput stream. You must supply the function\n\n    read_chunk_callback(png_structp png_ptr,\n         png_unknown_chunkp chunk);\n    {\n       /* The unknown chunk structure contains your\n          chunk data, along with similar data for any other\n          unknown chunks: */\n\n           png_byte name[5];\n           png_byte *data;\n           png_size_t size;\n\n       /* Note that libpng has already taken care of\n          the CRC handling */\n\n       /* put your code here.  Search for your chunk in the\n          unknown chunk structure, process it, and return one\n          of the following: */\n\n       return (\\-n); /* chunk had an error */\n       return (0); /* did not recognize */\n       return (n); /* success */\n    }\n\n(You can give your function another name that you like instead of\n\"read_chunk_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_read_user_chunk_fn(png_ptr, user_chunk_ptr,\n        read_chunk_callback);\n\nThis names not only the callback function, but also a user pointer that\nyou can retrieve with\n\n    png_get_user_chunk_ptr(png_ptr);\n\nIf you call the png_set_read_user_chunk_fn() function, then all unknown\nchunks which the callback does not handle will be saved when read.  You can\ncause them to be discarded by returning '1' (\"handled\") instead of '0'.  This\nbehavior will change in libpng 1.7 and the default handling set by the\npng_set_keep_unknown_chunks() function, described below, will be used when the\ncallback returns 0.  If you want the existing behavior you should set the global\ndefault to PNG_HANDLE_CHUNK_IF_SAFE now; this is compatible with all current\nversions of libpng and with 1.7.  Libpng 1.6 issues a warning if you keep the\ndefault, or PNG_HANDLE_CHUNK_NEVER, and the callback returns 0.\n\nAt this point, you can set up a callback function that will be\ncalled after each row has been read, which you can use to control\na progress meter or the like.  It's demonstrated in pngtest.c.\nYou must supply a function\n\n    void read_row_callback(png_structp png_ptr,\n       png_uint_32 row, int pass);\n    {\n      /* put your code here */\n    }\n\n(You can give it another name that you like instead of \"read_row_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_read_status_fn(png_ptr, read_row_callback);\n\nWhen this function is called the row has already been completely processed and\nthe 'row' and 'pass' refer to the next row to be handled.  For the\nnon-interlaced case the row that was just handled is simply one less than the\npassed in row number, and pass will always be 0.  For the interlaced case the\nsame applies unless the row value is 0, in which case the row just handled was\nthe last one from one of the preceding passes.  Because interlacing may skip a\npass you cannot be sure that the preceding pass is just 'pass\\-1'; if you really\nneed to know what the last pass is record (row,pass) from the callback and use\nthe last recorded value each time.\n\nAs with the user transform you can find the output row using the\nPNG_ROW_FROM_PASS_ROW macro.\n\n.SS Unknown-chunk handling\n\nNow you get to set the way the library processes unknown chunks in the\ninput PNG stream. Both known and unknown chunks will be read.  Normal\nbehavior is that known chunks will be parsed into information in\nvarious info_ptr members while unknown chunks will be discarded. This\nbehavior can be wasteful if your application will never use some known\nchunk types. To change this, you can call:\n\n    png_set_keep_unknown_chunks(png_ptr, keep,\n        chunk_list, num_chunks);\n\n    keep       - 0: default unknown chunk handling\n                 1: ignore; do not keep\n                 2: keep only if safe-to-copy\n                 3: keep even if unsafe-to-copy\n\n               You can use these definitions:\n                 PNG_HANDLE_CHUNK_AS_DEFAULT   0\n                 PNG_HANDLE_CHUNK_NEVER        1\n                 PNG_HANDLE_CHUNK_IF_SAFE      2\n                 PNG_HANDLE_CHUNK_ALWAYS       3\n\n    chunk_list - list of chunks affected (a byte string,\n                 five bytes per chunk, NULL or '\\0' if\n                 num_chunks is positive; ignored if\n                 numchunks <= 0).\n\n    num_chunks - number of chunks affected; if 0, all\n                 unknown chunks are affected.  If positive,\n                 only the chunks in the list are affected,\n                 and if negative all unknown chunks and\n                 all known chunks except for the IHDR,\n                 PLTE, tRNS, IDAT, and IEND chunks are\n                 affected.\n\nUnknown chunks declared in this way will be saved as raw data onto a\nlist of png_unknown_chunk structures.  If a chunk that is normally\nknown to libpng is named in the list, it will be handled as unknown,\naccording to the \"keep\" directive.  If a chunk is named in successive\ninstances of png_set_keep_unknown_chunks(), the final instance will\ntake precedence.  The IHDR and IEND chunks should not be named in\nchunk_list; if they are, libpng will process them normally anyway.\nIf you know that your application will never make use of some particular\nchunks, use PNG_HANDLE_CHUNK_NEVER (or 1) as demonstrated below.\n\nHere is an example of the usage of png_set_keep_unknown_chunks(),\nwhere the private \"vpAg\" chunk will later be processed by a user chunk\ncallback function:\n\n    png_byte vpAg[5]={118, 112,  65, 103, (png_byte) '\\0'};\n\n    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)\n      png_byte unused_chunks[]=\n      {\n        104,  73,  83,  84, (png_byte) '\\0',   /* hIST */\n        105,  84,  88, 116, (png_byte) '\\0',   /* iTXt */\n        112,  67,  65,  76, (png_byte) '\\0',   /* pCAL */\n        115,  67,  65,  76, (png_byte) '\\0',   /* sCAL */\n        115,  80,  76,  84, (png_byte) '\\0',   /* sPLT */\n        116,  73,  77,  69, (png_byte) '\\0',   /* tIME */\n      };\n    #endif\n\n    ...\n\n    #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)\n      /* ignore all unknown chunks\n       * (use global setting \"2\" for libpng16 and earlier):\n       */\n      png_set_keep_unknown_chunks(read_ptr, 2, NULL, 0);\n\n      /* except for vpAg: */\n      png_set_keep_unknown_chunks(read_ptr, 2, vpAg, 1);\n\n      /* also ignore unused known chunks: */\n      png_set_keep_unknown_chunks(read_ptr, 1, unused_chunks,\n         (int)(sizeof unused_chunks)/5);\n    #endif\n\n.SS User limits\n\nThe PNG specification allows the width and height of an image to be as\nlarge as 2^(31\\-1 (0x7fffffff), or about 2.147 billion rows and columns.\nFor safety, libpng imposes a default limit of 1 million rows and columns.\nLarger images will be rejected immediately with a png_error() call. If\nyou wish to change these limits, you can use\n\n   png_set_user_limits(png_ptr, width_max, height_max);\n\nto set your own limits (libpng may reject some very wide images\nanyway because of potential buffer overflow conditions).\n\nYou should put this statement after you create the PNG structure and\nbefore calling png_read_info(), png_read_png(), or png_process_data().\n\nWhen writing a PNG datastream, put this statement before calling\npng_write_info() or png_write_png().\n\nIf you need to retrieve the limits that are being applied, use\n\n   width_max = png_get_user_width_max(png_ptr);\n   height_max = png_get_user_height_max(png_ptr);\n\nThe PNG specification sets no limit on the number of ancillary chunks\nallowed in a PNG datastream.  By default, libpng imposes a limit of\na total of 1000 sPLT, tEXt, iTXt, zTXt, and unknown chunks to be stored.\nIf you have set up both info_ptr and end_info_ptr, the limit applies\nseparately to each.  You can change the limit on the total number of such\nchunks that will be stored, with\n\n   png_set_chunk_cache_max(png_ptr, user_chunk_cache_max);\n\nwhere 0x7fffffffL means unlimited.  You can retrieve this limit with\n\n   chunk_cache_max = png_get_chunk_cache_max(png_ptr);\n\nLibpng imposes a limit of 8 Megabytes (8,000,000 bytes) on the amount of\nmemory that a compressed chunk other than IDAT can occupy, when decompressed.\nYou can change this limit with\n\n   png_set_chunk_malloc_max(png_ptr, user_chunk_malloc_max);\n\nand you can retrieve the limit with\n\n   chunk_malloc_max = png_get_chunk_malloc_max(png_ptr);\n\nAny chunks that would cause either of these limits to be exceeded will\nbe ignored.\n\n.SS Information about your system\n\nIf you intend to display the PNG or to incorporate it in other image data you\nneed to tell libpng information about your display or drawing surface so that\nlibpng can convert the values in the image to match the display.\n\nFrom libpng-1.5.4 this information can be set before reading the PNG file\nheader.  In earlier versions png_set_gamma() existed but behaved incorrectly if\ncalled before the PNG file header had been read and png_set_alpha_mode() did not\nexist.\n\nIf you need to support versions prior to libpng-1.5.4 test the version number\nas illustrated below using \"PNG_LIBPNG_VER >= 10504\" and follow the procedures\ndescribed in the appropriate manual page.\n\nYou give libpng the encoding expected by your system expressed as a 'gamma'\nvalue.  You can also specify a default encoding for the PNG file in\ncase the required information is missing from the file.  By default libpng\nassumes that the PNG data matches your system, to keep this default call:\n\n   png_set_gamma(png_ptr, screen_gamma, output_gamma);\n\nor you can use the fixed point equivalent:\n\n   png_set_gamma_fixed(png_ptr, PNG_FP_1*screen_gamma,\n      PNG_FP_1*output_gamma);\n\nIf you don't know the gamma for your system it is probably 2.2 - a good\napproximation to the IEC standard for display systems (sRGB).  If images are\ntoo contrasty or washed out you got the value wrong - check your system\ndocumentation!\n\nMany systems permit the system gamma to be changed via a lookup table in the\ndisplay driver, a few systems, including older Macs, change the response by\ndefault.  As of 1.5.4 three special values are available to handle common\nsituations:\n\n   PNG_DEFAULT_sRGB: Indicates that the system conforms to the\n                     IEC 61966-2-1 standard.  This matches almost\n                     all systems.\n   PNG_GAMMA_MAC_18: Indicates that the system is an older\n                     (pre Mac OS 10.6) Apple Macintosh system with\n                     the default settings.\n   PNG_GAMMA_LINEAR: Just the fixed point value for 1.0 - indicates\n                     that the system expects data with no gamma\n                     encoding.\n\nYou would use the linear (unencoded) value if you need to process the pixel\nvalues further because this avoids the need to decode and re-encode each\ncomponent value whenever arithmetic is performed.  A lot of graphics software\nuses linear values for this reason, often with higher precision component values\nto preserve overall accuracy.\n\n\nThe output_gamma value expresses how to decode the output values, not how\nthey are encoded.  The values used correspond to the normal numbers used to\ndescribe the overall gamma of a computer display system; for example 2.2 for\nan sRGB conformant system.  The values are scaled by 100000 in the _fixed\nversion of the API (so 220000 for sRGB.)\n\nThe inverse of the value is always used to provide a default for the PNG file\nencoding if it has no gAMA chunk and if png_set_gamma() has not been called\nto override the PNG gamma information.\n\nWhen the ALPHA_OPTIMIZED mode is selected the output gamma is used to encode\nopaque pixels however pixels with lower alpha values are not encoded,\nregardless of the output gamma setting.\n\nWhen the standard Porter Duff handling is requested with mode 1 the output\nencoding is set to be linear and the output_gamma value is only relevant\nas a default for input data that has no gamma information.  The linear output\nencoding will be overridden if png_set_gamma() is called - the results may be\nhighly unexpected!\n\nThe following numbers are derived from the sRGB standard and the research\nbehind it.  sRGB is defined to be approximated by a PNG gAMA chunk value of\n0.45455 (1/2.2) for PNG.  The value implicitly includes any viewing\ncorrection required to take account of any differences in the color\nenvironment of the original scene and the intended display environment; the\nvalue expresses how to *decode* the image for display, not how the original\ndata was *encoded*.\n\nsRGB provides a peg for the PNG standard by defining a viewing environment.\nsRGB itself, and earlier TV standards, actually use a more complex transform\n(a linear portion then a gamma 2.4 power law) than PNG can express.  (PNG is\nlimited to simple power laws.)  By saying that an image for direct display on\nan sRGB conformant system should be stored with a gAMA chunk value of 45455\n(11.3.3.2 and 11.3.3.5 of the ISO PNG specification) the PNG specification\nmakes it possible to derive values for other display systems and\nenvironments.\n\nThe Mac value is deduced from the sRGB based on an assumption that the actual\nextra viewing correction used in early Mac display systems was implemented as\na power 1.45 lookup table.\n\nAny system where a programmable lookup table is used or where the behavior of\nthe final display device characteristics can be changed requires system\nspecific code to obtain the current characteristic.  However this can be\ndifficult and most PNG gamma correction only requires an approximate value.\n\nBy default, if png_set_alpha_mode() is not called, libpng assumes that all\nvalues are unencoded, linear, values and that the output device also has a\nlinear characteristic.  This is only very rarely correct - it is invariably\nbetter to call png_set_alpha_mode() with PNG_DEFAULT_sRGB than rely on the\ndefault if you don't know what the right answer is!\n\nThe special value PNG_GAMMA_MAC_18 indicates an older Mac system (pre Mac OS\n10.6) which used a correction table to implement a somewhat lower gamma on an\notherwise sRGB system.\n\nBoth these values are reserved (not simple gamma values) in order to allow\nmore precise correction internally in the future.\n\nNOTE: the values can be passed to either the fixed or floating\npoint APIs, but the floating point API will also accept floating point\nvalues.\n\nThe second thing you may need to tell libpng about is how your system handles\nalpha channel information.  Some, but not all, PNG files contain an alpha\nchannel.  To display these files correctly you need to compose the data onto a\nsuitable background, as described in the PNG specification.\n\nLibpng only supports composing onto a single color (using png_set_background;\nsee below).  Otherwise you must do the composition yourself and, in this case,\nyou may need to call png_set_alpha_mode:\n\n   #if PNG_LIBPNG_VER >= 10504\n      png_set_alpha_mode(png_ptr, mode, screen_gamma);\n   #else\n      png_set_gamma(png_ptr, screen_gamma, 1.0/screen_gamma);\n   #endif\n\nThe screen_gamma value is the same as the argument to png_set_gamma; however,\nhow it affects the output depends on the mode.  png_set_alpha_mode() sets the\nfile gamma default to 1/screen_gamma, so normally you don't need to call\npng_set_gamma.  If you need different defaults call png_set_gamma() before\npng_set_alpha_mode() - if you call it after it will override the settings made\nby png_set_alpha_mode().\n\nThe mode is as follows:\n\n    PNG_ALPHA_PNG: The data is encoded according to the PNG\nspecification.  Red, green and blue, or gray, components are\ngamma encoded color values and are not premultiplied by the\nalpha value.  The alpha value is a linear measure of the\ncontribution of the pixel to the corresponding final output pixel.\n\nYou should normally use this format if you intend to perform\ncolor correction on the color values; most, maybe all, color\ncorrection software has no handling for the alpha channel and,\nanyway, the math to handle pre-multiplied component values is\nunnecessarily complex.\n\nBefore you do any arithmetic on the component values you need\nto remove the gamma encoding and multiply out the alpha\nchannel.  See the PNG specification for more detail.  It is\nimportant to note that when an image with an alpha channel is\nscaled, linear encoded, pre-multiplied component values must\nbe used!\n\nThe remaining modes assume you don't need to do any further color correction or\nthat if you do, your color correction software knows all about alpha (it\nprobably doesn't!).  They 'associate' the alpha with the color information by\nstoring color channel values that have been scaled by the alpha.  The\nadvantage is that the color channels can be resampled (the image can be\nscaled) in this form.  The disadvantage is that normal practice is to store\nlinear, not (gamma) encoded, values and this requires 16-bit channels for\nstill images rather than the 8-bit channels that are just about sufficient if\ngamma encoding is used.  In addition all non-transparent pixel values,\nincluding completely opaque ones, must be gamma encoded to produce the final\nimage.  These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes\ndescribed below (the latter being the two common names for associated alpha\ncolor channels). Note that PNG files always contain non-associated color\nchannels; png_set_alpha_mode() with one of the modes causes the decoder to\nconvert the pixels to an associated form before returning them to your\napplication. \n\nSince it is not necessary to perform arithmetic on opaque color values so\nlong as they are not to be resampled and are in the final color space it is\npossible to optimize the handling of alpha by storing the opaque pixels in\nthe PNG format (adjusted for the output color space) while storing partially\nopaque pixels in the standard, linear, format.  The accuracy required for\nstandard alpha composition is relatively low, because the pixels are\nisolated, therefore typically the accuracy loss in storing 8-bit linear\nvalues is acceptable.  (This is not true if the alpha channel is used to\nsimulate transparency over large areas - use 16 bits or the PNG mode in\nthis case!)  This is the 'OPTIMIZED' mode.  For this mode a pixel is\ntreated as opaque only if the alpha value is equal to the maximum value.\n\n    PNG_ALPHA_STANDARD:  The data libpng produces is encoded in the\nstandard way assumed by most correctly written graphics software.\nThe gamma encoding will be removed by libpng and the\nlinear component values will be pre-multiplied by the\nalpha channel.\n\nWith this format the final image must be re-encoded to\nmatch the display gamma before the image is displayed.\nIf your system doesn't do that, yet still seems to\nperform arithmetic on the pixels without decoding them,\nit is broken - check out the modes below.\n\nWith PNG_ALPHA_STANDARD libpng always produces linear\ncomponent values, whatever screen_gamma you supply.  The\nscreen_gamma value is, however, used as a default for\nthe file gamma if the PNG file has no gamma information.\n\nIf you call png_set_gamma() after png_set_alpha_mode() you\nwill override the linear encoding.  Instead the\npre-multiplied pixel values will be gamma encoded but\nthe alpha channel will still be linear.  This may\nactually match the requirements of some broken software,\nbut it is unlikely.\n\nWhile linear 8-bit data is often used it has\ninsufficient precision for any image with a reasonable\ndynamic range.  To avoid problems, and if your software\nsupports it, use png_set_expand_16() to force all\ncomponents to 16 bits.\n\n    PNG_ALPHA_OPTIMIZED: This mode is the same as PNG_ALPHA_STANDARD\nexcept that completely opaque pixels are gamma encoded according to\nthe screen_gamma value.  Pixels with alpha less than 1.0\nwill still have linear components.\n\nUse this format if you have control over your\ncompositing software and so don't do other arithmetic\n(such as scaling) on the data you get from libpng.  Your\ncompositing software can simply copy opaque pixels to\nthe output but still has linear values for the\nnon-opaque pixels.\n\nIn normal compositing, where the alpha channel encodes\npartial pixel coverage (as opposed to broad area\ntranslucency), the inaccuracies of the 8-bit\nrepresentation of non-opaque pixels are irrelevant.\n\nYou can also try this format if your software is broken;\nit might look better.\n\n    PNG_ALPHA_BROKEN: This is PNG_ALPHA_STANDARD; however, all component\nvalues, including the alpha channel are gamma encoded.  This is\nbroken because, in practice, no implementation that uses this choice\ncorrectly undoes the encoding before handling alpha composition.  Use this\nchoice only if other serious errors in the software or hardware you use\nmandate it.  In most cases of broken software or hardware the bug in the\nfinal display manifests as a subtle halo around composited parts of the\nimage.  You may not even perceive this as a halo; the composited part of\nthe image may simply appear separate from the background, as though it had\nbeen cut out of paper and pasted on afterward.\n\nIf you don't have to deal with bugs in software or hardware, or if you can fix\nthem, there are three recommended ways of using png_set_alpha_mode():\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_PNG,\n       screen_gamma);\n\nYou can do color correction on the result (libpng does not currently\nsupport color correction internally).  When you handle the alpha channel\nyou need to undo the gamma encoding and multiply out the alpha.\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_STANDARD,\n       screen_gamma);\n   png_set_expand_16(png_ptr);\n\nIf you are using the high level interface, don't call png_set_expand_16();\ninstead pass PNG_TRANSFORM_EXPAND_16 to the interface.\n\nWith this mode you can't do color correction, but you can do arithmetic,\nincluding composition and scaling, on the data without further processing.\n\n   png_set_alpha_mode(png_ptr, PNG_ALPHA_OPTIMIZED,\n       screen_gamma);\n\nYou can avoid the expansion to 16-bit components with this mode, but you\nlose the ability to scale the image or perform other linear arithmetic.\nAll you can do is compose the result onto a matching output.  Since this\nmode is libpng-specific you also need to write your own composition\nsoftware.\n\nThe following are examples of calls to png_set_alpha_mode to achieve the\nrequired overall gamma correction and, where necessary, alpha\npremultiplication.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n\nThis is the default libpng handling of the alpha channel - it is not\npre-multiplied into the color components.  In addition the call states\nthat the output is for a sRGB system and causes all PNG files without gAMA\nchunks to be assumed to be encoded using sRGB.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n\nIn this case the output is assumed to be something like an sRGB conformant\ndisplay preceeded by a power-law lookup table of power 1.45.  This is how\nearly Mac systems behaved.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);\n\nThis is the classic Jim Blinn approach and will work in academic\nenvironments where everything is done by the book.  It has the shortcoming\nof assuming that input PNG data with no gamma information is linear - this\nis unlikely to be correct unless the PNG files where generated locally.\nMost of the time the output precision will be so low as to show\nsignificant banding in dark areas of the image.\n\n    png_set_expand_16(pp);\n    png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);\n\nThis is a somewhat more realistic Jim Blinn inspired approach.  PNG files\nare assumed to have the sRGB encoding if not marked with a gamma value and\nthe output is always 16 bits per component.  This permits accurate scaling\nand processing of the data.  If you know that your input PNG files were\ngenerated locally you might need to replace PNG_DEFAULT_sRGB with the\ncorrect value for your system.\n\n    png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);\n\nIf you just need to composite the PNG image onto an existing background\nand if you control the code that does this you can use the optimization\nsetting.  In this case you just copy completely opaque pixels to the\noutput.  For pixels that are not completely transparent (you just skip\nthose) you do the composition math using png_composite or png_composite_16\nbelow then encode the resultant 8-bit or 16-bit values to match the output\nencoding.\n\n    Other cases\n\nIf neither the PNG nor the standard linear encoding work for you because\nof the software or hardware you use then you have a big problem.  The PNG\ncase will probably result in halos around the image.  The linear encoding\nwill probably result in a washed out, too bright, image (it's actually too\ncontrasty.)  Try the ALPHA_OPTIMIZED mode above - this will probably\nsubstantially reduce the halos.  Alternatively try:\n\n    png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);\n\nThis option will also reduce the halos, but there will be slight dark\nhalos round the opaque parts of the image where the background is light.\nIn the OPTIMIZED mode the halos will be light halos where the background\nis dark.  Take your pick - the halos are unavoidable unless you can get\nyour hardware/software fixed!  (The OPTIMIZED approach is slightly\nfaster.)\n\nWhen the default gamma of PNG files doesn't match the output gamma.\nIf you have PNG files with no gamma information png_set_alpha_mode allows\nyou to provide a default gamma, but it also sets the ouput gamma to the\nmatching value.  If you know your PNG files have a gamma that doesn't\nmatch the output you can take advantage of the fact that\npng_set_alpha_mode always sets the output gamma but only sets the PNG\ndefault if it is not already set:\n\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n    png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n\nThe first call sets both the default and the output gamma values, the\nsecond call overrides the output gamma without changing the default.  This\nis easier than achieving the same effect with png_set_gamma.  You must use\nPNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will\nfire if more than one call to png_set_alpha_mode and png_set_background is\nmade in the same read operation, however multiple calls with PNG_ALPHA_PNG\nare ignored.\n\nIf you don't need, or can't handle, the alpha channel you can call\npng_set_background() to remove it by compositing against a fixed color.  Don't\ncall png_set_strip_alpha() to do this - it will leave spurious pixel values in\ntransparent parts of this image.\n\n   png_set_background(png_ptr, &background_color,\n       PNG_BACKGROUND_GAMMA_SCREEN, 0, 1);\n\nThe background_color is an RGB or grayscale value according to the data format\nlibpng will produce for you.  Because you don't yet know the format of the PNG\nfile, if you call png_set_background at this point you must arrange for the\nformat produced by libpng to always have 8-bit or 16-bit components and then\nstore the color as an 8-bit or 16-bit color as appropriate.  The color contains\nseparate gray and RGB component values, so you can let libpng produce gray or\nRGB output according to the input format, but low bit depth grayscale images\nmust always be converted to at least 8-bit format.  (Even though low bit depth\ngrayscale images can't have an alpha channel they can have a transparent\ncolor!)\n\nYou set the transforms you need later, either as flags to the high level\ninterface or libpng API calls for the low level interface.  For reference the\nsettings and API calls required are:\n\n8-bit values:\n   PNG_TRANSFORM_SCALE_16 | PNG_EXPAND\n   png_set_expand(png_ptr); png_set_scale_16(png_ptr);\n\n   If you must get exactly the same inaccurate results\n   produced by default in versions prior to libpng-1.5.4,\n   use PNG_TRANSFORM_STRIP_16 and png_set_strip_16(png_ptr)\n   instead.\n\n16-bit values:\n   PNG_TRANSFORM_EXPAND_16\n   png_set_expand_16(png_ptr);\n\nIn either case palette image data will be expanded to RGB.  If you just want\ncolor data you can add PNG_TRANSFORM_GRAY_TO_RGB or png_set_gray_to_rgb(png_ptr)\nto the list.\n\nCalling png_set_background before the PNG file header is read will not work\nprior to libpng-1.5.4.  Because the failure may result in unexpected warnings or\nerrors it is therefore much safer to call png_set_background after the head has\nbeen read.  Unfortunately this means that prior to libpng-1.5.4 it cannot be\nused with the high level interface.\n\n.SS The high-level read interface\n\nAt this point there are two ways to proceed; through the high-level\nread interface, or through a sequence of low-level read operations.\nYou can use the high-level interface if (a) you are willing to read\nthe entire image into memory, and (b) the input transformations\nyou want to do are limited to the following set:\n\n    PNG_TRANSFORM_IDENTITY      No transformation\n    PNG_TRANSFORM_SCALE_16      Strip 16-bit samples to\n                                8-bit accurately\n    PNG_TRANSFORM_STRIP_16      Chop 16-bit samples to\n                                8-bit less accurately\n    PNG_TRANSFORM_STRIP_ALPHA   Discard the alpha channel\n    PNG_TRANSFORM_PACKING       Expand 1, 2 and 4-bit\n                                samples to bytes\n    PNG_TRANSFORM_PACKSWAP      Change order of packed\n                                pixels to LSB first\n    PNG_TRANSFORM_EXPAND        Perform set_expand()\n    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images\n    PNG_TRANSFORM_SHIFT         Normalize pixels to the\n                                sBIT depth\n    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA\n                                to BGRA\n    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA\n                                to AG\n    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity\n                                to transparency\n    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples\n    PNG_TRANSFORM_GRAY_TO_RGB   Expand grayscale samples\n                                to RGB (or GA to RGBA)\n    PNG_TRANSFORM_EXPAND_16     Expand samples to 16 bits\n\n(This excludes setting a background color, doing gamma transformation,\nquantizing, and setting filler.)  If this is the case, simply do this:\n\n    png_read_png(png_ptr, info_ptr, png_transforms, NULL)\n\nwhere png_transforms is an integer containing the bitwise OR of some\nset of transformation flags.  This call is equivalent to png_read_info(),\nfollowed the set of transformations indicated by the transform mask,\nthen png_read_image(), and finally png_read_end().\n\n(The final parameter of this call is not yet used.  Someday it might point\nto transformation parameters required by some future input transform.)\n\nYou must use png_transforms and not call any png_set_transform() functions\nwhen you use png_read_png().\n\nAfter you have called png_read_png(), you can retrieve the image data\nwith\n\n   row_pointers = png_get_rows(png_ptr, info_ptr);\n\nwhere row_pointers is an array of pointers to the pixel data for each row:\n\n   png_bytep row_pointers[height];\n\nIf you know your image size and pixel size ahead of time, you can allocate\nrow_pointers prior to calling png_read_png() with\n\n   if (height > PNG_UINT_32_MAX/(sizeof (png_byte)))\n      png_error (png_ptr,\n          \"Image is too tall to process in memory\");\n\n   if (width > PNG_UINT_32_MAX/pixel_size)\n      png_error (png_ptr,\n          \"Image is too wide to process in memory\");\n\n   row_pointers = png_malloc(png_ptr,\n       height*(sizeof (png_bytep)));\n\n   for (int i=0; i<height, i++)\n      row_pointers[i]=NULL;  /* security precaution */\n\n   for (int i=0; i<height, i++)\n      row_pointers[i]=png_malloc(png_ptr,\n          width*pixel_size);\n\n   png_set_rows(png_ptr, info_ptr, &row_pointers);\n\nAlternatively you could allocate your image in one big block and define\nrow_pointers[i] to point into the proper places in your block.\n\nIf you use png_set_rows(), the application is responsible for freeing\nrow_pointers (and row_pointers[i], if they were separately allocated).\n\nIf you don't allocate row_pointers ahead of time, png_read_png() will\ndo it, and it'll be free'ed by libpng when you call png_destroy_*().\n\n.SS The low-level read interface\n\nIf you are going the low-level route, you are now ready to read all\nthe file information up to the actual image data.  You do this with a\ncall to png_read_info().\n\n    png_read_info(png_ptr, info_ptr);\n\nThis will process all chunks up to but not including the image data.\n\nThis also copies some of the data from the PNG file into the decode structure\nfor use in later transformations.  Important information copied in is:\n\n1) The PNG file gamma from the gAMA chunk.  This overwrites the default value\nprovided by an earlier call to png_set_gamma or png_set_alpha_mode.\n\n2) Prior to libpng-1.5.4 the background color from a bKGd chunk.  This\ndamages the information provided by an earlier call to png_set_background\nresulting in unexpected behavior.  Libpng-1.5.4 no longer does this.\n\n3) The number of significant bits in each component value.  Libpng uses this to\noptimize gamma handling by reducing the internal lookup table sizes.\n\n4) The transparent color information from a tRNS chunk.  This can be modified by\na later call to png_set_tRNS.\n\n.SS Querying the info structure\n\nFunctions are used to get the information from the info_ptr once it\nhas been read.  Note that these fields may not be completely filled\nin until png_read_end() has read the chunk data following the image.\n\n    png_get_IHDR(png_ptr, info_ptr, &width, &height,\n       &bit_depth, &color_type, &interlace_type,\n       &compression_type, &filter_method);\n\n    width          - holds the width of the image\n                     in pixels (up to 2^31).\n\n    height         - holds the height of the image\n                     in pixels (up to 2^31).\n\n    bit_depth      - holds the bit depth of one of the\n                     image channels.  (valid values are\n                     1, 2, 4, 8, 16 and depend also on\n                     the color_type.  See also\n                     significant bits (sBIT) below).\n\n    color_type     - describes which color/alpha channels\n                         are present.\n                     PNG_COLOR_TYPE_GRAY\n                        (bit depths 1, 2, 4, 8, 16)\n                     PNG_COLOR_TYPE_GRAY_ALPHA\n                        (bit depths 8, 16)\n                     PNG_COLOR_TYPE_PALETTE\n                        (bit depths 1, 2, 4, 8)\n                     PNG_COLOR_TYPE_RGB\n                        (bit_depths 8, 16)\n                     PNG_COLOR_TYPE_RGB_ALPHA\n                        (bit_depths 8, 16)\n\n                     PNG_COLOR_MASK_PALETTE\n                     PNG_COLOR_MASK_COLOR\n                     PNG_COLOR_MASK_ALPHA\n\n    interlace_type - (PNG_INTERLACE_NONE or\n                     PNG_INTERLACE_ADAM7)\n\n    compression_type - (must be PNG_COMPRESSION_TYPE_BASE\n                     for PNG 1.0)\n\n    filter_method  - (must be PNG_FILTER_TYPE_BASE\n                     for PNG 1.0, and can also be\n                     PNG_INTRAPIXEL_DIFFERENCING if\n                     the PNG datastream is embedded in\n                     a MNG-1.0 datastream)\n\n    Any of width, height, color_type, bit_depth,\n    interlace_type, compression_type, or filter_method can\n    be NULL if you are not interested in their values.\n\n    Note that png_get_IHDR() returns 32-bit data into\n    the application's width and height variables.\n    This is an unsafe situation if these are not png_uint_32\n    variables.  In such situations, the\n    png_get_image_width() and png_get_image_height()\n    functions described below are safer.\n\n    width            = png_get_image_width(png_ptr,\n                         info_ptr);\n\n    height           = png_get_image_height(png_ptr,\n                         info_ptr);\n\n    bit_depth        = png_get_bit_depth(png_ptr,\n                         info_ptr);\n\n    color_type       = png_get_color_type(png_ptr,\n                         info_ptr);\n\n    interlace_type   = png_get_interlace_type(png_ptr,\n                         info_ptr);\n\n    compression_type = png_get_compression_type(png_ptr,\n                         info_ptr);\n\n    filter_method    = png_get_filter_type(png_ptr,\n                         info_ptr);\n\n    channels = png_get_channels(png_ptr, info_ptr);\n\n    channels       - number of channels of info for the\n                     color type (valid values are 1 (GRAY,\n                     PALETTE), 2 (GRAY_ALPHA), 3 (RGB),\n                     4 (RGB_ALPHA or RGB + filler byte))\n\n    rowbytes = png_get_rowbytes(png_ptr, info_ptr);\n\n    rowbytes       - number of bytes needed to hold a row\n\n    signature = png_get_signature(png_ptr, info_ptr);\n\n    signature      - holds the signature read from the\n                     file (if any).  The data is kept in\n                     the same offset it would be if the\n                     whole signature were read (i.e. if an\n                     application had already read in 4\n                     bytes of signature before starting\n                     libpng, the remaining 4 bytes would\n                     be in signature[4] through signature[7]\n                     (see png_set_sig_bytes())).\n\nThese are also important, but their validity depends on whether the chunk\nhas been read.  The png_get_valid(png_ptr, info_ptr, PNG_INFO_<chunk>) and\npng_get_<chunk>(png_ptr, info_ptr, ...) functions return non-zero if the\ndata has been read, or zero if it is missing.  The parameters to the\npng_get_<chunk> are set directly if they are simple data types, or a\npointer into the info_ptr is returned for any complex types.\n\nThe colorspace data from gAMA, cHRM, sRGB, iCCP, and sBIT chunks\nis simply returned to give the application information about how the\nimage was encoded.  Libpng itself only does transformations using the file\ngamma when combining semitransparent pixels with the background color, and,\nsince libpng-1.6.0, when converting between 8-bit sRGB and 16-bit linear pixels\nwithin the simplified API.  Libpng also uses the file gamma when converting\nRGB to gray, beginning with libpng-1.0.5, if the application calls\npng_set_rgb_to_gray()).\n\n    png_get_PLTE(png_ptr, info_ptr, &palette,\n                     &num_palette);\n\n    palette        - the palette for the file\n                     (array of png_color)\n\n    num_palette    - number of entries in the palette\n\n    png_get_gAMA(png_ptr, info_ptr, &file_gamma);\n    png_get_gAMA_fixed(png_ptr, info_ptr, &int_file_gamma);\n\n    file_gamma     - the gamma at which the file is\n                     written (PNG_INFO_gAMA)\n\n    int_file_gamma - 100,000 times the gamma at which the\n                     file is written\n\n    png_get_cHRM(png_ptr, info_ptr,  &white_x, &white_y, &red_x,\n                     &red_y, &green_x, &green_y, &blue_x, &blue_y)\n    png_get_cHRM_XYZ(png_ptr, info_ptr, &red_X, &red_Y, &red_Z,\n                     &green_X, &green_Y, &green_Z, &blue_X, &blue_Y,\n                     &blue_Z)\n    png_get_cHRM_fixed(png_ptr, info_ptr, &int_white_x,\n                     &int_white_y, &int_red_x, &int_red_y,\n                     &int_green_x, &int_green_y, &int_blue_x,\n                     &int_blue_y)\n    png_get_cHRM_XYZ_fixed(png_ptr, info_ptr, &int_red_X, &int_red_Y,\n                     &int_red_Z, &int_green_X, &int_green_Y,\n                     &int_green_Z, &int_blue_X, &int_blue_Y,\n                     &int_blue_Z)\n\n    {white,red,green,blue}_{x,y}\n                     A color space encoding specified using the\n                     chromaticities of the end points and the\n                     white point. (PNG_INFO_cHRM)\n\n    {red,green,blue}_{X,Y,Z}\n                     A color space encoding specified using the\n                     encoding end points - the CIE tristimulus\n                     specification of the intended color of the red,\n                     green and blue channels in the PNG RGB data.\n                     The white point is simply the sum of the three\n                     end points. (PNG_INFO_cHRM)\n\n    png_get_sRGB(png_ptr, info_ptr, &srgb_intent);\n\n    srgb_intent -    the rendering intent (PNG_INFO_sRGB)\n                     The presence of the sRGB chunk\n                     means that the pixel data is in the\n                     sRGB color space.  This chunk also\n                     implies specific values of gAMA and\n                     cHRM.\n\n    png_get_iCCP(png_ptr, info_ptr, &name,\n       &compression_type, &profile, &proflen);\n\n    name             - The profile name.\n\n    compression_type - The compression type; always\n                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.\n                       You may give NULL to this argument to\n                       ignore it.\n\n    profile          - International Color Consortium color\n                       profile data. May contain NULs.\n\n    proflen          - length of profile data in bytes.\n\n    png_get_sBIT(png_ptr, info_ptr, &sig_bit);\n\n    sig_bit        - the number of significant bits for\n                     (PNG_INFO_sBIT) each of the gray,\n                     red, green, and blue channels,\n                     whichever are appropriate for the\n                     given color type (png_color_16)\n\n    png_get_tRNS(png_ptr, info_ptr, &trans_alpha,\n                     &num_trans, &trans_color);\n\n    trans_alpha    - array of alpha (transparency)\n                     entries for palette (PNG_INFO_tRNS)\n\n    num_trans      - number of transparent entries\n                     (PNG_INFO_tRNS)\n\n    trans_color    - graylevel or color sample values of\n                     the single transparent color for\n                     non-paletted images (PNG_INFO_tRNS)\n\n    png_get_hIST(png_ptr, info_ptr, &hist);\n                     (PNG_INFO_hIST)\n\n    hist           - histogram of palette (array of\n                     png_uint_16)\n\n    png_get_tIME(png_ptr, info_ptr, &mod_time);\n\n    mod_time       - time image was last modified\n                    (PNG_VALID_tIME)\n\n    png_get_bKGD(png_ptr, info_ptr, &background);\n\n    background     - background color (of type\n                     png_color_16p) (PNG_VALID_bKGD)\n                     valid 16-bit red, green and blue\n                     values, regardless of color_type\n\n    num_comments   = png_get_text(png_ptr, info_ptr,\n                     &text_ptr, &num_text);\n\n    num_comments   - number of comments\n\n    text_ptr       - array of png_text holding image\n                     comments\n\n    text_ptr[i].compression - type of compression used\n                 on \"text\" PNG_TEXT_COMPRESSION_NONE\n                           PNG_TEXT_COMPRESSION_zTXt\n                           PNG_ITXT_COMPRESSION_NONE\n                           PNG_ITXT_COMPRESSION_zTXt\n\n    text_ptr[i].key   - keyword for comment.  Must contain\n                         1-79 characters.\n\n    text_ptr[i].text  - text comments for current\n                         keyword.  Can be empty.\n\n    text_ptr[i].text_length - length of text string,\n                 after decompression, 0 for iTXt\n\n    text_ptr[i].itxt_length - length of itxt string,\n                 after decompression, 0 for tEXt/zTXt\n\n    text_ptr[i].lang  - language of comment (empty\n                         string for unknown).\n\n    text_ptr[i].lang_key  - keyword in UTF-8\n                         (empty string for unknown).\n\n    Note that the itxt_length, lang, and lang_key\n    members of the text_ptr structure only exist when the\n    library is built with iTXt chunk support.  Prior to\n    libpng-1.4.0 the library was built by default without\n    iTXt support. Also note that when iTXt is supported,\n    they contain NULL pointers when the \"compression\"\n    field contains PNG_TEXT_COMPRESSION_NONE or\n    PNG_TEXT_COMPRESSION_zTXt.\n\n    num_text       - number of comments (same as\n                     num_comments; you can put NULL here\n                     to avoid the duplication)\n\n    Note while png_set_text() will accept text, language,\n    and translated keywords that can be NULL pointers, the\n    structure returned by png_get_text will always contain\n    regular zero-terminated C strings.  They might be\n    empty strings but they will never be NULL pointers.\n\n    num_spalettes = png_get_sPLT(png_ptr, info_ptr,\n       &palette_ptr);\n\n    num_spalettes  - number of sPLT chunks read.\n\n    palette_ptr    - array of palette structures holding\n                     contents of one or more sPLT chunks\n                     read.\n\n    png_get_oFFs(png_ptr, info_ptr, &offset_x, &offset_y,\n       &unit_type);\n\n    offset_x       - positive offset from the left edge\n                     of the screen (can be negative)\n\n    offset_y       - positive offset from the top edge\n                     of the screen (can be negative)\n\n    unit_type      - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER\n\n    png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y,\n       &unit_type);\n\n    res_x          - pixels/unit physical resolution in\n                     x direction\n\n    res_y          - pixels/unit physical resolution in\n                     x direction\n\n    unit_type      - PNG_RESOLUTION_UNKNOWN,\n                     PNG_RESOLUTION_METER\n\n    png_get_sCAL(png_ptr, info_ptr, &unit, &width,\n       &height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n\n    height      - height of a pixel in physical scale units\n                 (width and height are doubles)\n\n    png_get_sCAL_s(png_ptr, info_ptr, &unit, &width,\n       &height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n                  (expressed as a string)\n\n    height      - height of a pixel in physical scale units\n                 (width and height are strings like \"2.54\")\n\n    num_unknown_chunks = png_get_unknown_chunks(png_ptr,\n       info_ptr, &unknowns)\n\n    unknowns          - array of png_unknown_chunk\n                        structures holding unknown chunks\n\n    unknowns[i].name  - name of unknown chunk\n\n    unknowns[i].data  - data of unknown chunk\n\n    unknowns[i].size  - size of unknown chunk's data\n\n    unknowns[i].location - position of chunk in file\n\n    The value of \"i\" corresponds to the order in which the\n    chunks were read from the PNG file or inserted with the\n    png_set_unknown_chunks() function.\n\n    The value of \"location\" is a bitwise \"or\" of\n\n         PNG_HAVE_IHDR  (0x01)\n         PNG_HAVE_PLTE  (0x02)\n         PNG_AFTER_IDAT (0x08)\n\nThe data from the pHYs chunk can be retrieved in several convenient\nforms:\n\n    res_x = png_get_x_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_y = png_get_y_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_x_and_y = png_get_pixels_per_meter(png_ptr,\n       info_ptr)\n\n    res_x = png_get_x_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    res_y = png_get_y_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    res_x_and_y = png_get_pixels_per_inch(png_ptr,\n       info_ptr)\n\n    aspect_ratio = png_get_pixel_aspect_ratio(png_ptr,\n       info_ptr)\n\n    Each of these returns 0 [signifying \"unknown\"] if\n       the data is not present or if res_x is 0;\n       res_x_and_y is 0 if res_x != res_y\n\n    Note that because of the way the resolutions are\n       stored internally, the inch conversions won't\n       come out to exactly even number.  For example,\n       72 dpi is stored as 0.28346 pixels/meter, and\n       when this is retrieved it is 71.9988 dpi, so\n       be sure to round the returned value appropriately\n       if you want to display a reasonable-looking result.\n\nThe data from the oFFs chunk can be retrieved in several convenient\nforms:\n\n    x_offset = png_get_x_offset_microns(png_ptr, info_ptr);\n\n    y_offset = png_get_y_offset_microns(png_ptr, info_ptr);\n\n    x_offset = png_get_x_offset_inches(png_ptr, info_ptr);\n\n    y_offset = png_get_y_offset_inches(png_ptr, info_ptr);\n\n    Each of these returns 0 [signifying \"unknown\" if both\n       x and y are 0] if the data is not present or if the\n       chunk is present but the unit is the pixel.  The\n       remark about inexact inch conversions applies here\n       as well, because a value in inches can't always be\n       converted to microns and back without some loss\n       of precision.\n\nFor more information, see the\nPNG specification for chunk contents.  Be careful with trusting\nrowbytes, as some of the transformations could increase the space\nneeded to hold a row (expand, filler, gray_to_rgb, etc.).\nSee png_read_update_info(), below.\n\nA quick word about text_ptr and num_text.  PNG stores comments in\nkeyword/text pairs, one pair per chunk, with no limit on the number\nof text chunks, and a 2^31 byte limit on their size.  While there are\nsuggested keywords, there is no requirement to restrict the use to these\nstrings.  It is strongly suggested that keywords and text be sensible\nto humans (that's the point), so don't use abbreviations.  Non-printing\nsymbols are not allowed.  See the PNG specification for more details.\nThere is also no requirement to have text after the keyword.\n\nKeywords should be limited to 79 Latin-1 characters without leading or\ntrailing spaces, but non-consecutive spaces are allowed within the\nkeyword.  It is possible to have the same keyword any number of times.\nThe text_ptr is an array of png_text structures, each holding a\npointer to a language string, a pointer to a keyword and a pointer to\na text string.  The text string, language code, and translated\nkeyword may be empty or NULL pointers.  The keyword/text\npairs are put into the array in the order that they are received.\nHowever, some or all of the text chunks may be after the image, so, to\nmake sure you have read all the text chunks, don't mess with these\nuntil after you read the stuff after the image.  This will be\nmentioned again below in the discussion that goes with png_read_end().\n\n.SS Input transformations\n\nAfter you've read the header information, you can set up the library\nto handle any special transformations of the image data.  The various\nways to transform the data will be described in the order that they\nshould occur.  This is important, as some of these change the color\ntype and/or bit depth of the data, and some others only work on\ncertain color types and bit depths.\n\nTransformations you request are ignored if they don't have any meaning for a\nparticular input data format.  However some transformations can have an effect\nas a result of a previous transformation.  If you specify a contradictory set of\ntransformations, for example both adding and removing the alpha channel, you\ncannot predict the final result.\n\nThe color used for the transparency values should be supplied in the same\nformat/depth as the current image data.  It is stored in the same format/depth\nas the image data in a tRNS chunk, so this is what libpng expects for this data.\n\nThe color used for the background value depends on the need_expand argument as\ndescribed below.\n\nData will be decoded into the supplied row buffers packed into bytes\nunless the library has been told to transform it into another format.\nFor example, 4 bit/pixel paletted or grayscale data will be returned\n2 pixels/byte with the leftmost pixel in the high-order bits of the byte,\nunless png_set_packing() is called.  8-bit RGB data will be stored\nin RGB RGB RGB format unless png_set_filler() or png_set_add_alpha()\nis called to insert filler bytes, either before or after each RGB triplet.\n\n16-bit RGB data will be returned RRGGBB RRGGBB, with the most significant\nbyte of the color value first, unless png_set_scale_16() is called to\ntransform it to regular RGB RGB triplets, or png_set_filler() or\npng_set_add alpha() is called to insert two filler bytes, either before\nor after each RRGGBB triplet.  Similarly, 8-bit or 16-bit grayscale data can\nbe modified with png_set_filler(), png_set_add_alpha(), png_set_strip_16(),\nor png_set_scale_16().\n\nThe following code transforms grayscale images of less than 8 to 8 bits,\nchanges paletted images to RGB, and adds a full alpha channel if there is\ntransparency information in a tRNS chunk.  This is most useful on\ngrayscale images with bit depths of 2 or 4 or if there is a multiple-image\nviewing application that wishes to treat all images in the same way.\n\n    if (color_type == PNG_COLOR_TYPE_PALETTE)\n        png_set_palette_to_rgb(png_ptr);\n\n    if (png_get_valid(png_ptr, info_ptr,\n        PNG_INFO_tRNS)) png_set_tRNS_to_alpha(png_ptr);\n\n    if (color_type == PNG_COLOR_TYPE_GRAY &&\n        bit_depth < 8) png_set_expand_gray_1_2_4_to_8(png_ptr);\n\nThe first two functions are actually aliases for png_set_expand(), added\nin libpng version 1.0.4, with the function names expanded to improve code\nreadability.  In some future version they may actually do different\nthings.\n\nAs of libpng version 1.2.9, png_set_expand_gray_1_2_4_to_8() was\nadded.  It expands the sample depth without changing tRNS to alpha.\n\nAs of libpng version 1.5.2, png_set_expand_16() was added.  It behaves as\npng_set_expand(); however, the resultant channels have 16 bits rather than 8.\nUse this when the output color or gray channels are made linear to avoid fairly\nsevere accuracy loss.\n\n   if (bit_depth < 16)\n      png_set_expand_16(png_ptr);\n\nPNG can have files with 16 bits per channel.  If you only can handle\n8 bits per channel, this will strip the pixels down to 8-bit.\n\n    if (bit_depth == 16)\n#if PNG_LIBPNG_VER >= 10504\n       png_set_scale_16(png_ptr);\n#else\n       png_set_strip_16(png_ptr);\n#endif\n\n(The more accurate \"png_set_scale_16()\" API became available in libpng version\n1.5.4).\n\nIf you need to process the alpha channel on the image separately from the image\ndata (for example if you convert it to a bitmap mask) it is possible to have\nlibpng strip the channel leaving just RGB or gray data:\n\n    if (color_type & PNG_COLOR_MASK_ALPHA)\n       png_set_strip_alpha(png_ptr);\n\nIf you strip the alpha channel you need to find some other way of dealing with\nthe information.  If, instead, you want to convert the image to an opaque\nversion with no alpha channel use png_set_background; see below.\n\nAs of libpng version 1.5.2, almost all useful expansions are supported, the\nmajor ommissions are conversion of grayscale to indexed images (which can be\ndone trivially in the application) and conversion of indexed to grayscale (which\ncan be done by a trivial manipulation of the palette.)\n\nIn the following table, the 01 means grayscale with depth<8, 31 means\nindexed with depth<8, other numerals represent the color type, \"T\" means\nthe tRNS chunk is present, A means an alpha channel is present, and O\nmeans tRNS or alpha is present but all pixels in the image are opaque.\n\n  FROM  01  31   0  0T  0O   2  2T  2O   3  3T  3O  4A  4O  6A  6O\n   TO\n   01    -  [G]  -   -   -   -   -   -   -   -   -   -   -   -   -\n   31   [Q]  Q  [Q] [Q] [Q]  Q   Q   Q   Q   Q   Q  [Q] [Q]  Q   Q\n    0    1   G   +   .   .   G   G   G   G   G   G   B   B  GB  GB\n   0T    lt  Gt  t   +   .   Gt  G   G   Gt  G   G   Bt  Bt GBt GBt\n   0O    lt  Gt  t   .   +   Gt  Gt  G   Gt  Gt  G   Bt  Bt GBt GBt\n    2    C   P   C   C   C   +   .   .   C   -   -  CB  CB   B   B\n   2T    Ct  -   Ct  C   C   t   +   t   -   -   -  CBt CBt  Bt  Bt\n   2O    Ct  -   Ct  C   C   t   t   +   -   -   -  CBt CBt  Bt  Bt\n    3   [Q]  p  [Q] [Q] [Q]  Q   Q   Q   +   .   .  [Q] [Q]  Q   Q\n   3T   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   +   t  [Qt][Qt] Qt  Qt\n   3O   [Qt] p  [Qt][Q] [Q]  Qt  Qt  Qt  t   t   +  [Qt][Qt] Qt  Qt\n   4A    lA  G   A   T   T   GA  GT  GT  GA  GT  GT  +   BA  G  GBA\n   4O    lA GBA  A   T   T   GA  GT  GT  GA  GT  GT  BA  +  GBA  G\n   6A    CA  PA  CA  C   C   A   T  tT   PA  P   P   C  CBA  +   BA\n   6O    CA PBA  CA  C   C   A  tT   T   PA  P   P  CBA  C   BA  +\n\nWithin the matrix,\n     \"+\" identifies entries where 'from' and 'to' are the same.\n     \"-\" means the transformation is not supported.\n     \".\" means nothing is necessary (a tRNS chunk can just be ignored).\n     \"t\" means the transformation is obtained by png_set_tRNS.\n     \"A\" means the transformation is obtained by png_set_add_alpha().\n     \"X\" means the transformation is obtained by png_set_expand().\n     \"1\" means the transformation is obtained by\n         png_set_expand_gray_1_2_4_to_8() (and by png_set_expand()\n         if there is no transparency in the original or the final\n         format).\n     \"C\" means the transformation is obtained by png_set_gray_to_rgb().\n     \"G\" means the transformation is obtained by png_set_rgb_to_gray().\n     \"P\" means the transformation is obtained by\n         png_set_expand_palette_to_rgb().\n     \"p\" means the transformation is obtained by png_set_packing().\n     \"Q\" means the transformation is obtained by png_set_quantize().\n     \"T\" means the transformation is obtained by\n         png_set_tRNS_to_alpha().\n     \"B\" means the transformation is obtained by\n         png_set_background(), or png_strip_alpha().\n\nWhen an entry has multiple transforms listed all are required to cause the\nright overall transformation.  When two transforms are separated by a comma\neither will do the job.  When transforms are enclosed in [] the transform should\ndo the job but this is currently unimplemented - a different format will result\nif the suggested transformations are used.\n\nIn PNG files, the alpha channel in an image\nis the level of opacity.  If you need the alpha channel in an image to\nbe the level of transparency instead of opacity, you can invert the\nalpha channel (or the tRNS chunk data) after it's read, so that 0 is\nfully opaque and 255 (in 8-bit or paletted images) or 65535 (in 16-bit\nimages) is fully transparent, with\n\n    png_set_invert_alpha(png_ptr);\n\nPNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as\nthey can, resulting in, for example, 8 pixels per byte for 1 bit\nfiles.  This code expands to 1 pixel per byte without changing the\nvalues of the pixels:\n\n    if (bit_depth < 8)\n       png_set_packing(png_ptr);\n\nPNG files have possible bit depths of 1, 2, 4, 8, and 16.  All pixels\nstored in a PNG image have been \"scaled\" or \"shifted\" up to the next\nhigher possible bit depth (e.g. from 5 bits/sample in the range [0,31]\nto 8 bits/sample in the range [0, 255]).  However, it is also possible\nto convert the PNG pixel data back to the original bit depth of the\nimage.  This call reduces the pixels back down to the original bit depth:\n\n    png_color_8p sig_bit;\n\n    if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))\n       png_set_shift(png_ptr, sig_bit);\n\nPNG files store 3-color pixels in red, green, blue order.  This code\nchanges the storage of the pixels to blue, green, red:\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n        color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_bgr(png_ptr);\n\nPNG files store RGB pixels packed into 3 or 6 bytes. This code expands them\ninto 4 or 8 bytes for windowing systems that need them in this format:\n\n    if (color_type == PNG_COLOR_TYPE_RGB)\n       png_set_filler(png_ptr, filler, PNG_FILLER_BEFORE);\n\nwhere \"filler\" is the 8-bit or 16-bit number to fill with, and the location\nis either PNG_FILLER_BEFORE or PNG_FILLER_AFTER, depending upon whether\nyou want the filler before the RGB or after. When filling an 8-bit pixel,\nthe least significant 8 bits of the number are used, if a 16-bit number is\nsupplied.  This transformation does not affect images that already have full\nalpha channels.  To add an opaque alpha channel, use filler=0xffff and\nPNG_FILLER_AFTER which will generate RGBA pixels.\n\nNote that png_set_filler() does not change the color type.  If you want\nto do that, you can add a true alpha channel with\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n       color_type == PNG_COLOR_TYPE_GRAY)\n       png_set_add_alpha(png_ptr, filler, PNG_FILLER_AFTER);\n\nwhere \"filler\" contains the alpha value to assign to each pixel.\nThe png_set_add_alpha() function was added in libpng-1.2.7.\n\nIf you are reading an image with an alpha channel, and you need the\ndata as ARGB instead of the normal PNG format RGBA:\n\n    if (color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_swap_alpha(png_ptr);\n\nFor some uses, you may want a grayscale image to be represented as\nRGB.  This code will do that conversion:\n\n    if (color_type == PNG_COLOR_TYPE_GRAY ||\n        color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n       png_set_gray_to_rgb(png_ptr);\n\nConversely, you can convert an RGB or RGBA image to grayscale or grayscale\nwith alpha.\n\n    if (color_type == PNG_COLOR_TYPE_RGB ||\n        color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n       png_set_rgb_to_gray(png_ptr, error_action,\n          double red_weight, double green_weight);\n\n    error_action = 1: silently do the conversion\n\n    error_action = 2: issue a warning if the original\n                      image has any pixel where\n                      red != green or red != blue\n\n    error_action = 3: issue an error and abort the\n                      conversion if the original\n                      image has any pixel where\n                      red != green or red != blue\n\n    red_weight:       weight of red component\n\n    green_weight:     weight of green component\n                      If either weight is negative, default\n                      weights are used.\n\nIn the corresponding fixed point API the red_weight and green_weight values are\nsimply scaled by 100,000:\n\n    png_set_rgb_to_gray(png_ptr, error_action,\n       png_fixed_point red_weight,\n       png_fixed_point green_weight);\n\nIf you have set error_action = 1 or 2, you can\nlater check whether the image really was gray, after processing\nthe image rows, with the png_get_rgb_to_gray_status(png_ptr) function.\nIt will return a png_byte that is zero if the image was gray or\n1 if there were any non-gray pixels.  Background and sBIT data\nwill be silently converted to grayscale, using the green channel\ndata for sBIT, regardless of the error_action setting.\n\nThe default values come from the PNG file cHRM chunk if present; otherwise, the\ndefaults correspond to the ITU-R recommendation 709, and also the sRGB color\nspace, as recommended in the Charles Poynton's Colour FAQ,\nCopyright (c) 2006-11-28 Charles Poynton, in section 9:\n\n<http://www.poynton.com/notes/colour_and_gamma/ColorFAQ.html#RTFToC9>\n\n    Y = 0.2126 * R + 0.7152 * G + 0.0722 * B\n\nPrevious versions of this document, 1998 through 2002, recommended a slightly\ndifferent formula:\n\n    Y = 0.212671 * R + 0.715160 * G + 0.072169 * B\n\nLibpng uses an integer approximation:\n\n    Y = (6968 * R + 23434 * G + 2366 * B)/32768\n\nThe calculation is done in a linear colorspace, if the image gamma\ncan be determined.\n\nThe png_set_background() function has been described already; it tells libpng to\ncomposite images with alpha or simple transparency against the supplied\nbackground color.  For compatibility with versions of libpng earlier than\nlibpng-1.5.4 it is recommended that you call the function after reading the file\nheader, even if you don't want to use the color in a bKGD chunk, if one exists.\n\nIf the PNG file contains a bKGD chunk (PNG_INFO_bKGD valid),\nyou may use this color, or supply another color more suitable for\nthe current display (e.g., the background color from a web page).  You\nneed to tell libpng how the color is represented, both the format of the\ncomponent values in the color (the number of bits) and the gamma encoding of the\ncolor.  The function takes two arguments, background_gamma_mode and need_expand\nto convey this information; however, only two combinations are likely to be\nuseful:\n\n    png_color_16 my_background;\n    png_color_16p image_background;\n\n    if (png_get_bKGD(png_ptr, info_ptr, &image_background))\n       png_set_background(png_ptr, image_background,\n           PNG_BACKGROUND_GAMMA_FILE, 1/*needs to be expanded*/, 1);\n    else\n       png_set_background(png_ptr, &my_background,\n           PNG_BACKGROUND_GAMMA_SCREEN, 0/*do not expand*/, 1);\n\nThe second call was described above - my_background is in the format of the\nfinal, display, output produced by libpng.  Because you now know the format of\nthe PNG it is possible to avoid the need to choose either 8-bit or 16-bit\noutput and to retain palette images (the palette colors will be modified\nappropriately and the tRNS chunk removed.)  However, if you are doing this,\ntake great care not to ask for transformations without checking first that\nthey apply!\n\nIn the first call the background color has the original bit depth and color type\nof the PNG file.  So, for palette images the color is supplied as a palette\nindex and for low bit greyscale images the color is a reduced bit value in\nimage_background->gray.\n\nIf you didn't call png_set_gamma() before reading the file header, for example\nif you need your code to remain compatible with older versions of libpng prior\nto libpng-1.5.4, this is the place to call it.\n\nDo not call it if you called png_set_alpha_mode(); doing so will damage the\nsettings put in place by png_set_alpha_mode().  (If png_set_alpha_mode() is\nsupported then you can certainly do png_set_gamma() before reading the PNG\nheader.)\n\nThis API unconditionally sets the screen and file gamma values, so it will\noverride the value in the PNG file unless it is called before the PNG file\nreading starts.  For this reason you must always call it with the PNG file\nvalue when you call it in this position:\n\n   if (png_get_gAMA(png_ptr, info_ptr, &file_gamma))\n      png_set_gamma(png_ptr, screen_gamma, file_gamma);\n\n   else\n      png_set_gamma(png_ptr, screen_gamma, 0.45455);\n\nIf you need to reduce an RGB file to a paletted file, or if a paletted\nfile has more entries than will fit on your screen, png_set_quantize()\nwill do that.  Note that this is a simple match quantization that merely\nfinds the closest color available.  This should work fairly well with\noptimized palettes, but fairly badly with linear color cubes.  If you\npass a palette that is larger than maximum_colors, the file will\nreduce the number of colors in the palette so it will fit into\nmaximum_colors.  If there is a histogram, libpng will use it to make\nmore intelligent choices when reducing the palette.  If there is no\nhistogram, it may not do as good a job.\n\n   if (color_type & PNG_COLOR_MASK_COLOR)\n   {\n      if (png_get_valid(png_ptr, info_ptr,\n          PNG_INFO_PLTE))\n      {\n         png_uint_16p histogram = NULL;\n\n         png_get_hIST(png_ptr, info_ptr,\n             &histogram);\n         png_set_quantize(png_ptr, palette, num_palette,\n            max_screen_colors, histogram, 1);\n      }\n\n      else\n      {\n         png_color std_color_cube[MAX_SCREEN_COLORS] =\n            { ... colors ... };\n\n         png_set_quantize(png_ptr, std_color_cube,\n            MAX_SCREEN_COLORS, MAX_SCREEN_COLORS,\n            NULL,0);\n      }\n   }\n\nPNG files describe monochrome as black being zero and white being one.\nThe following code will reverse this (make black be one and white be\nzero):\n\n   if (bit_depth == 1 && color_type == PNG_COLOR_TYPE_GRAY)\n      png_set_invert_mono(png_ptr);\n\nThis function can also be used to invert grayscale and gray-alpha images:\n\n   if (color_type == PNG_COLOR_TYPE_GRAY ||\n       color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      png_set_invert_mono(png_ptr);\n\nPNG files store 16-bit pixels in network byte order (big-endian,\nie. most significant bits first).  This code changes the storage to the\nother way (little-endian, i.e. least significant bits first, the\nway PCs store them):\n\n    if (bit_depth == 16)\n       png_set_swap(png_ptr);\n\nIf you are using packed-pixel images (1, 2, or 4 bits/pixel), and you\nneed to change the order the pixels are packed into bytes, you can use:\n\n    if (bit_depth < 8)\n       png_set_packswap(png_ptr);\n\nFinally, you can write your own transformation function if none of\nthe existing ones meets your needs.  This is done by setting a callback\nwith\n\n    png_set_read_user_transform_fn(png_ptr,\n        read_transform_fn);\n\nYou must supply the function\n\n    void read_transform_fn(png_structp png_ptr, png_row_infop\n        row_info, png_bytep data)\n\nSee pngtest.c for a working example.  Your function will be called\nafter all of the other transformations have been processed.  Take care with\ninterlaced images if you do the interlace yourself - the width of the row is the\nwidth in 'row_info', not the overall image width.\n\nIf supported, libpng provides two information routines that you can use to find\nwhere you are in processing the image:\n\n   png_get_current_pass_number(png_structp png_ptr);\n   png_get_current_row_number(png_structp png_ptr);\n\nDon't try using these outside a transform callback - firstly they are only\nsupported if user transforms are supported, secondly they may well return\nunexpected results unless the row is actually being processed at the moment they\nare called.\n\nWith interlaced\nimages the value returned is the row in the input sub-image image.  Use\nPNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\nfind the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).\n\nThe discussion of interlace handling above contains more information on how to\nuse these values.\n\nYou can also set up a pointer to a user structure for use by your\ncallback function, and you can inform libpng that your transform\nfunction will change the number of channels or bit depth with the\nfunction\n\n    png_set_user_transform_info(png_ptr, user_ptr,\n        user_depth, user_channels);\n\nThe user's application, not libpng, is responsible for allocating and\nfreeing any memory required for the user structure.\n\nYou can retrieve the pointer via the function\npng_get_user_transform_ptr().  For example:\n\n    voidp read_user_transform_ptr =\n        png_get_user_transform_ptr(png_ptr);\n\nThe last thing to handle is interlacing; this is covered in detail below,\nbut you must call the function here if you want libpng to handle expansion\nof the interlaced image.\n\n    number_of_passes = png_set_interlace_handling(png_ptr);\n\nAfter setting the transformations, libpng can update your png_info\nstructure to reflect any transformations you've requested with this\ncall.\n\n    png_read_update_info(png_ptr, info_ptr);\n\nThis is most useful to update the info structure's rowbytes\nfield so you can use it to allocate your image memory.  This function\nwill also update your palette with the correct screen_gamma and\nbackground if these have been given with the calls above.  You may\nonly call png_read_update_info() once with a particular info_ptr.\n\nAfter you call png_read_update_info(), you can allocate any\nmemory you need to hold the image.  The row data is simply\nraw byte data for all forms of images.  As the actual allocation\nvaries among applications, no example will be given.  If you\nare allocating one large chunk, you will need to build an\narray of pointers to each row, as it will be needed for some\nof the functions below.\n\nRemember: Before you call png_read_update_info(), the png_get_*()\nfunctions return the values corresponding to the original PNG image.\nAfter you call png_read_update_info the values refer to the image\nthat libpng will output.  Consequently you must call all the png_set_\nfunctions before you call png_read_update_info().  This is particularly\nimportant for png_set_interlace_handling() - if you are going to call\npng_read_update_info() you must call png_set_interlace_handling() before\nit unless you want to receive interlaced output.\n\n.SS Reading image data\n\nAfter you've allocated memory, you can read the image data.\nThe simplest way to do this is in one function call.  If you are\nallocating enough memory to hold the whole image, you can just\ncall png_read_image() and libpng will read in all the image data\nand put it in the memory area supplied.  You will need to pass in\nan array of pointers to each row.\n\nThis function automatically handles interlacing, so you don't\nneed to call png_set_interlace_handling() (unless you call\npng_read_update_info()) or call this function multiple times, or any\nof that other stuff necessary with png_read_rows().\n\n   png_read_image(png_ptr, row_pointers);\n\nwhere row_pointers is:\n\n   png_bytep row_pointers[height];\n\nYou can point to void or char or whatever you use for pixels.\n\nIf you don't want to read in the whole image at once, you can\nuse png_read_rows() instead.  If there is no interlacing (check\ninterlace_type == PNG_INTERLACE_NONE), this is simple:\n\n    png_read_rows(png_ptr, row_pointers, NULL,\n        number_of_rows);\n\nwhere row_pointers is the same as in the png_read_image() call.\n\nIf you are doing this just one row at a time, you can do this with\na single row_pointer instead of an array of row_pointers:\n\n    png_bytep row_pointer = row;\n    png_read_row(png_ptr, row_pointer, NULL);\n\nIf the file is interlaced (interlace_type != 0 in the IHDR chunk), things\nget somewhat harder.  The only current (PNG Specification version 1.2)\ninterlacing type for PNG is (interlace_type == PNG_INTERLACE_ADAM7);\na somewhat complicated 2D interlace scheme, known as Adam7, that\nbreaks down an image into seven smaller images of varying size, based\non an 8x8 grid.  This number is defined (from libpng 1.5) as\nPNG_INTERLACE_ADAM7_PASSES in png.h\n\nlibpng can fill out those images or it can give them to you \"as is\".\nIt is almost always better to have libpng handle the interlacing for you.\nIf you want the images filled out, there are two ways to do that.  The one\nmentioned in the PNG specification is to expand each pixel to cover\nthose pixels that have not been read yet (the \"rectangle\" method).\nThis results in a blocky image for the first pass, which gradually\nsmooths out as more pixels are read.  The other method is the \"sparkle\"\nmethod, where pixels are drawn only in their final locations, with the\nrest of the image remaining whatever colors they were initialized to\nbefore the start of the read.  The first method usually looks better,\nbut tends to be slower, as there are more pixels to put in the rows.\n\nIf, as is likely, you want libpng to expand the images, call this before\ncalling png_start_read_image() or png_read_update_info():\n\n    if (interlace_type == PNG_INTERLACE_ADAM7)\n       number_of_passes\n           = png_set_interlace_handling(png_ptr);\n\nThis will return the number of passes needed.  Currently, this is seven,\nbut may change if another interlace type is added.  This function can be\ncalled even if the file is not interlaced, where it will return one pass.\nYou then need to read the whole image 'number_of_passes' times.  Each time\nwill distribute the pixels from the current pass to the correct place in\nthe output image, so you need to supply the same rows to png_read_rows in\neach pass.\n\nIf you are not going to display the image after each pass, but are\ngoing to wait until the entire image is read in, use the sparkle\neffect.  This effect is faster and the end result of either method\nis exactly the same.  If you are planning on displaying the image\nafter each pass, the \"rectangle\" effect is generally considered the\nbetter looking one.\n\nIf you only want the \"sparkle\" effect, just call png_read_row() or\npng_read_rows() as\nnormal, with the third parameter NULL.  Make sure you make pass over\nthe image number_of_passes times, and you don't change the data in the\nrows between calls.  You can change the locations of the data, just\nnot the data.  Each pass only writes the pixels appropriate for that\npass, and assumes the data from previous passes is still valid.\n\n    png_read_rows(png_ptr, row_pointers, NULL,\n        number_of_rows);\n    or\n    png_read_row(png_ptr, row_pointers, NULL);\n\nIf you only want the first effect (the rectangles), do the same as\nbefore except pass the row buffer in the third parameter, and leave\nthe second parameter NULL.\n\n    png_read_rows(png_ptr, NULL, row_pointers,\n        number_of_rows);\n    or\n    png_read_row(png_ptr, NULL, row_pointers);\n\nIf you don't want libpng to handle the interlacing details, just call\npng_read_rows() PNG_INTERLACE_ADAM7_PASSES times to read in all the images.\nEach of the images is a valid image by itself; however, you will almost\ncertainly need to distribute the pixels from each sub-image to the\ncorrect place.  This is where everything gets very tricky.\n\nIf you want to retrieve the separate images you must pass the correct\nnumber of rows to each successive call of png_read_rows().  The calculation\ngets pretty complicated for small images, where some sub-images may\nnot even exist because either their width or height ends up zero.\nlibpng provides two macros to help you in 1.5 and later versions:\n\n   png_uint_32 width = PNG_PASS_COLS(image_width, pass_number);\n   png_uint_32 height = PNG_PASS_ROWS(image_height, pass_number);\n\nRespectively these tell you the width and height of the sub-image\ncorresponding to the numbered pass.  'pass' is in in the range 0 to 6 -\nthis can be confusing because the specification refers to the same passes\nas 1 to 7!  Be careful, you must check both the width and height before\ncalling png_read_rows() and not call it for that pass if either is zero.\n\nYou can, of course, read each sub-image row by row.  If you want to\nproduce optimal code to make a pixel-by-pixel transformation of an\ninterlaced image this is the best approach; read each row of each pass,\ntransform it, and write it out to a new interlaced image.\n\nIf you want to de-interlace the image yourself libpng provides further\nmacros to help that tell you where to place the pixels in the output image.\nBecause the interlacing scheme is rectangular - sub-image pixels are always\narranged on a rectangular grid - all you need to know for each pass is the\nstarting column and row in the output image of the first pixel plus the\nspacing between each pixel.  As of libpng 1.5 there are four macros to\nretrieve this information:\n\n   png_uint_32 x = PNG_PASS_START_COL(pass);\n   png_uint_32 y = PNG_PASS_START_ROW(pass);\n   png_uint_32 xStep = 1U << PNG_PASS_COL_SHIFT(pass);\n   png_uint_32 yStep = 1U << PNG_PASS_ROW_SHIFT(pass);\n\nThese allow you to write the obvious loop:\n\n   png_uint_32 input_y = 0;\n   png_uint_32 output_y = PNG_PASS_START_ROW(pass);\n\n   while (output_y < output_image_height)\n   {\n      png_uint_32 input_x = 0;\n      png_uint_32 output_x = PNG_PASS_START_COL(pass);\n\n      while (output_x < output_image_width)\n      {\n         image[output_y][output_x] =\n             subimage[pass][input_y][input_x++];\n\n         output_x += xStep;\n      }\n\n      ++input_y;\n      output_y += yStep;\n   }\n\nNotice that the steps between successive output rows and columns are\nreturned as shifts.  This is possible because the pixels in the subimages\nare always a power of 2 apart - 1, 2, 4 or 8 pixels - in the original\nimage.  In practice you may need to directly calculate the output coordinate\ngiven an input coordinate.  libpng provides two further macros for this\npurpose:\n\n   png_uint_32 output_x = PNG_COL_FROM_PASS_COL(input_x, pass);\n   png_uint_32 output_y = PNG_ROW_FROM_PASS_ROW(input_y, pass);\n\nFinally a pair of macros are provided to tell you if a particular image\nrow or column appears in a given pass:\n\n   int col_in_pass = PNG_COL_IN_INTERLACE_PASS(output_x, pass);\n   int row_in_pass = PNG_ROW_IN_INTERLACE_PASS(output_y, pass);\n\nBear in mind that you will probably also need to check the width and height\nof the pass in addition to the above to be sure the pass even exists!\n\nWith any luck you are convinced by now that you don't want to do your own\ninterlace handling.  In reality normally the only good reason for doing this\nis if you are processing PNG files on a pixel-by-pixel basis and don't want\nto load the whole file into memory when it is interlaced.\n\nlibpng includes a test program, pngvalid, that illustrates reading and\nwriting of interlaced images.  If you can't get interlacing to work in your\ncode and don't want to leave it to libpng (the recommended approach), see\nhow pngvalid.c does it.\n\n.SS Finishing a sequential read\n\nAfter you are finished reading the image through the\nlow-level interface, you can finish reading the file.\n\nIf you want to use a different crc action for handling CRC errors in\nchunks after the image data, you can call png_set_crc_action()\nagain at this point.\n\nIf you are interested in comments or time, which may be stored either\nbefore or after the image data, you should pass the separate png_info\nstruct if you want to keep the comments from before and after the image\nseparate.\n\n    png_infop end_info = png_create_info_struct(png_ptr);\n\n    if (!end_info)\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\n   png_read_end(png_ptr, end_info);\n\nIf you are not interested, you should still call png_read_end()\nbut you can pass NULL, avoiding the need to create an end_info structure.\nIf you do this, libpng will not process any chunks after IDAT other than\nskipping over them and perhaps (depending on whether you have called\npng_set_crc_action) checking their CRCs while looking for the IEND chunk.\n\n   png_read_end(png_ptr, (png_infop)NULL);\n\nIf you don't call png_read_end(), then your file pointer will be\nleft pointing to the first chunk after the last IDAT, which is probably\nnot what you want if you expect to read something beyond the end of\nthe PNG datastream.\n\nWhen you are done, you can free all memory allocated by libpng like this:\n\n   png_destroy_read_struct(&png_ptr, &info_ptr,\n       &end_info);\n\nor, if you didn't create an end_info structure,\n\n   png_destroy_read_struct(&png_ptr, &info_ptr,\n       (png_infopp)NULL);\n\nIt is also possible to individually free the info_ptr members that\npoint to libpng-allocated storage with the following function:\n\n    png_free_data(png_ptr, info_ptr, mask, seq)\n\n    mask - identifies data to be freed, a mask\n           containing the bitwise OR of one or\n           more of\n             PNG_FREE_PLTE, PNG_FREE_TRNS,\n             PNG_FREE_HIST, PNG_FREE_ICCP,\n             PNG_FREE_PCAL, PNG_FREE_ROWS,\n             PNG_FREE_SCAL, PNG_FREE_SPLT,\n             PNG_FREE_TEXT, PNG_FREE_UNKN,\n           or simply PNG_FREE_ALL\n\n    seq  - sequence number of item to be freed\n           (\\-1 for all items)\n\nThis function may be safely called when the relevant storage has\nalready been freed, or has not yet been allocated, or was allocated\nby the user and not by libpng,  and will in those cases do nothing.\nThe \"seq\" parameter is ignored if only one item of the selected data\ntype, such as PLTE, is allowed.  If \"seq\" is not \\-1, and multiple items\nare allowed for the data type identified in the mask, such as text or\nsPLT, only the n'th item in the structure is freed, where n is \"seq\".\n\nThe default behavior is only to free data that was allocated internally\nby libpng.  This can be changed, so that libpng will not free the data,\nor so that it will free data that was allocated by the user with png_malloc()\nor png_calloc() and passed in via a png_set_*() function, with\n\n    png_data_freer(png_ptr, info_ptr, freer, mask)\n\n    freer  - one of\n               PNG_DESTROY_WILL_FREE_DATA\n               PNG_SET_WILL_FREE_DATA\n               PNG_USER_WILL_FREE_DATA\n\n    mask   - which data elements are affected\n             same choices as in png_free_data()\n\nThis function only affects data that has already been allocated.\nYou can call this function after reading the PNG data but before calling\nany png_set_*() functions, to control whether the user or the png_set_*()\nfunction is responsible for freeing any existing data that might be present,\nand again after the png_set_*() functions to control whether the user\nor png_destroy_*() is supposed to free the data.  When the user assumes\nresponsibility for libpng-allocated data, the application must use\npng_free() to free it, and when the user transfers responsibility to libpng\nfor data that the user has allocated, the user must have used png_malloc()\nor png_calloc() to allocate it.\n\nIf you allocated your row_pointers in a single block, as suggested above in\nthe description of the high level read interface, you must not transfer\nresponsibility for freeing it to the png_set_rows or png_read_destroy function,\nbecause they would also try to free the individual row_pointers[i].\n\nIf you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword\nseparately, do not transfer responsibility for freeing text_ptr to libpng,\nbecause when libpng fills a png_text structure it combines these members with\nthe key member, and png_free_data() will free only text_ptr.key.  Similarly,\nif you transfer responsibility for free'ing text_ptr from libpng to your\napplication, your application must not separately free those members.\n\nThe png_free_data() function will turn off the \"valid\" flag for anything\nit frees.  If you need to turn the flag off for a chunk that was freed by\nyour application instead of by libpng, you can use\n\n    png_set_invalid(png_ptr, info_ptr, mask);\n\n    mask - identifies the chunks to be made invalid,\n           containing the bitwise OR of one or\n           more of\n             PNG_INFO_gAMA, PNG_INFO_sBIT,\n             PNG_INFO_cHRM, PNG_INFO_PLTE,\n             PNG_INFO_tRNS, PNG_INFO_bKGD,\n             PNG_INFO_hIST, PNG_INFO_pHYs,\n             PNG_INFO_oFFs, PNG_INFO_tIME,\n             PNG_INFO_pCAL, PNG_INFO_sRGB,\n             PNG_INFO_iCCP, PNG_INFO_sPLT,\n             PNG_INFO_sCAL, PNG_INFO_IDAT\n\nFor a more compact example of reading a PNG image, see the file example.c.\n\n.SS Reading PNG files progressively\n\nThe progressive reader is slightly different from the non-progressive\nreader.  Instead of calling png_read_info(), png_read_rows(), and\npng_read_end(), you make one call to png_process_data(), which calls\ncallbacks when it has the info, a row, or the end of the image.  You\nset up these callbacks with png_set_progressive_read_fn().  You don't\nhave to worry about the input/output functions of libpng, as you are\ngiving the library the data directly in png_process_data().  I will\nassume that you have read the section on reading PNG files above,\nso I will only highlight the differences (although I will show\nall of the code).\n\npng_structp png_ptr;\npng_infop info_ptr;\n\n /*  An example code fragment of how you would\n     initialize the progressive reader in your\n     application. */\n int\n initialize_png_reader()\n {\n    png_ptr = png_create_read_struct\n        (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n         user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n        return (ERROR);\n\n    info_ptr = png_create_info_struct(png_ptr);\n\n    if (!info_ptr)\n    {\n       png_destroy_read_struct(&png_ptr,\n          (png_infopp)NULL, (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n          (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    /* This one's new.  You can provide functions\n       to be called when the header info is valid,\n       when each row is completed, and when the image\n       is finished.  If you aren't using all functions,\n       you can specify NULL parameters.  Even when all\n       three functions are NULL, you need to call\n       png_set_progressive_read_fn().  You can use\n       any struct as the user_ptr (cast to a void pointer\n       for the function call), and retrieve the pointer\n       from inside the callbacks using the function\n\n          png_get_progressive_ptr(png_ptr);\n\n       which will return a void pointer, which you have\n       to cast appropriately.\n     */\n    png_set_progressive_read_fn(png_ptr, (void *)user_ptr,\n        info_callback, row_callback, end_callback);\n\n    return 0;\n }\n\n /* A code fragment that you call as you receive blocks\n   of data */\n int\n process_data(png_bytep buffer, png_uint_32 length)\n {\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n       png_destroy_read_struct(&png_ptr, &info_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\n    /* This one's new also.  Simply give it a chunk\n       of data from the file stream (in order, of\n       course).  On machines with segmented memory\n       models machines, don't give it any more than\n       64K.  The library seems to run fine with sizes\n       of 4K. Although you can give it much less if\n       necessary (I assume you can give it chunks of\n       1 byte, I haven't tried less than 256 bytes\n       yet).  When this function returns, you may\n       want to display any rows that were generated\n       in the row callback if you don't already do\n       so there.\n     */\n    png_process_data(png_ptr, info_ptr, buffer, length);\n\n    /* At this point you can call png_process_data_skip if\n       you want to handle data the library will skip yourself;\n       it simply returns the number of bytes to skip (and stops\n       libpng skipping that number of bytes on the next\n       png_process_data call).\n    return 0;\n }\n\n /* This function is called (as set by\n    png_set_progressive_read_fn() above) when enough data\n    has been supplied so all of the header has been\n    read.\n */\n void\n info_callback(png_structp png_ptr, png_infop info)\n {\n    /* Do any setup here, including setting any of\n       the transformations mentioned in the Reading\n       PNG files section.  For now, you _must_ call\n       either png_start_read_image() or\n       png_read_update_info() after all the\n       transformations are set (even if you don't set\n       any).  You may start getting rows before\n       png_process_data() returns, so this is your\n       last chance to prepare for that.\n\n       This is where you turn on interlace handling,\n       assuming you don't want to do it yourself.\n\n       If you need to you can stop the processing of\n       your original input data at this point by calling\n       png_process_data_pause.  This returns the number\n       of unprocessed bytes from the last png_process_data\n       call - it is up to you to ensure that the next call\n       sees these bytes again.  If you don't want to bother\n       with this you can get libpng to cache the unread\n       bytes by setting the 'save' parameter (see png.h) but\n       then libpng will have to copy the data internally.\n     */\n }\n\n /* This function is called when each row of image\n    data is complete */\n void\n row_callback(png_structp png_ptr, png_bytep new_row,\n    png_uint_32 row_num, int pass)\n {\n    /* If the image is interlaced, and you turned\n       on the interlace handler, this function will\n       be called for every row in every pass.  Some\n       of these rows will not be changed from the\n       previous pass.  When the row is not changed,\n       the new_row variable will be NULL.  The rows\n       and passes are called in order, so you don't\n       really need the row_num and pass, but I'm\n       supplying them because it may make your life\n       easier.\n\n       If you did not turn on interlace handling then\n       the callback is called for each row of each\n       sub-image when the image is interlaced.  In this\n       case 'row_num' is the row in the sub-image, not\n       the row in the output image as it is in all other\n       cases.\n\n       For the non-NULL rows of interlaced images when\n       you have switched on libpng interlace handling,\n       you must call png_progressive_combine_row()\n       passing in the row and the old row.  You can\n       call this function for NULL rows (it will just\n       return) and for non-interlaced images (it just\n       does the memcpy for you) if it will make the\n       code easier.  Thus, you can just do this for\n       all cases if you switch on interlace handling;\n     */\n\n        png_progressive_combine_row(png_ptr, old_row,\n          new_row);\n\n    /* where old_row is what was displayed\n       previously for the row.  Note that the first\n       pass (pass == 0, really) will completely cover\n       the old row, so the rows do not have to be\n       initialized.  After the first pass (and only\n       for interlaced images), you will have to pass\n       the current row, and the function will combine\n       the old row and the new row.\n\n       You can also call png_process_data_pause in this\n       callback - see above.\n    */\n }\n\n void\n end_callback(png_structp png_ptr, png_infop info)\n {\n    /* This function is called after the whole image\n       has been read, including any chunks after the\n       image (up to and including the IEND).  You\n       will usually have the same info chunk as you\n       had in the header, although some data may have\n       been added to the comments and time fields.\n\n       Most people won't do much here, perhaps setting\n       a flag that marks the image as finished.\n     */\n }\n\n\n\n.SH IV. Writing\n\nMuch of this is very similar to reading.  However, everything of\nimportance is repeated here, so you won't have to constantly look\nback up in the reading section to understand writing.\n\n.SS Setup\n\nYou will want to do the I/O initialization before you get into libpng,\nso if it doesn't work, you don't have anything to undo. If you are not\nusing the standard I/O functions, you will need to replace them with\ncustom writing functions.  See the discussion under Customizing libpng.\n\n    FILE *fp = fopen(file_name, \"wb\");\n\n    if (!fp)\n       return (ERROR);\n\nNext, png_struct and png_info need to be allocated and initialized.\nAs these can be both relatively large, you may not want to store these\non the stack, unless you have stack space to spare.  Of course, you\nwill want to check if they return NULL.  If you are also reading,\nyou won't want to name your read structure and your write structure\nboth \"png_ptr\"; you can call them anything you like, such as\n\"read_ptr\" and \"write_ptr\".  Look at pngtest.c, for example.\n\n    png_structp png_ptr = png_create_write_struct\n       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn);\n\n    if (!png_ptr)\n       return (ERROR);\n\n    png_infop info_ptr = png_create_info_struct(png_ptr);\n    if (!info_ptr)\n    {\n       png_destroy_write_struct(&png_ptr,\n           (png_infopp)NULL);\n       return (ERROR);\n    }\n\nIf you want to use your own memory allocation routines,\ndefine PNG_USER_MEM_SUPPORTED and use\npng_create_write_struct_2() instead of png_create_write_struct():\n\n    png_structp png_ptr = png_create_write_struct_2\n       (PNG_LIBPNG_VER_STRING, (png_voidp)user_error_ptr,\n        user_error_fn, user_warning_fn, (png_voidp)\n        user_mem_ptr, user_malloc_fn, user_free_fn);\n\nAfter you have these structures, you will need to set up the\nerror handling.  When libpng encounters an error, it expects to\nlongjmp() back to your routine.  Therefore, you will need to call\nsetjmp() and pass the png_jmpbuf(png_ptr).  If you\nwrite the file from different routines, you will need to update\nthe png_jmpbuf(png_ptr) every time you enter a new routine that will\ncall a png_*() function.  See your documentation of setjmp/longjmp\nfor your compiler for more information on setjmp/longjmp.  See\nthe discussion on libpng error handling in the Customizing Libpng\nsection below for more information on the libpng error handling.\n\n    if (setjmp(png_jmpbuf(png_ptr)))\n    {\n    png_destroy_write_struct(&png_ptr, &info_ptr);\n       fclose(fp);\n       return (ERROR);\n    }\n    ...\n    return;\n\nIf you would rather avoid the complexity of setjmp/longjmp issues,\nyou can compile libpng with PNG_NO_SETJMP, in which case\nerrors will result in a call to PNG_ABORT() which defaults to abort().\n\nYou can #define PNG_ABORT() to a function that does something\nmore useful than abort(), as long as your function does not\nreturn.\n\nChecking for invalid palette index on write was added at libpng\n1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues\na benign error.  This is enabled by default because this condition is an\nerror according to the PNG specification, Clause 11.3.2, but the error can\nbe ignored in each png_ptr with\n\n   png_set_check_for_invalid_index(png_ptr, 0);\n\nIf the error is ignored, or if png_benign_error() treats it as a warning,\nany invalid pixels are written as-is by the encoder, resulting in an\ninvalid PNG datastream as output.  In this case the application is\nresponsible for ensuring that the pixel indexes are in range when it writes\na PLTE chunk with fewer entries than the bit depth would allow.\n\nNow you need to set up the output code.  The default for libpng is to\nuse the C function fwrite().  If you use this, you will need to pass a\nvalid FILE * in the function png_init_io().  Be sure that the file is\nopened in binary mode.  Again, if you wish to handle writing data in\nanother way, see the discussion on libpng I/O handling in the Customizing\nLibpng section below.\n\n    png_init_io(png_ptr, fp);\n\nIf you are embedding your PNG into a datastream such as MNG, and don't\nwant libpng to write the 8-byte signature, or if you have already\nwritten the signature in your application, use\n\n    png_set_sig_bytes(png_ptr, 8);\n\nto inform libpng that it should not write a signature.\n\n.SS Write callbacks\n\nAt this point, you can set up a callback function that will be\ncalled after each row has been written, which you can use to control\na progress meter or the like.  It's demonstrated in pngtest.c.\nYou must supply a function\n\n    void write_row_callback(png_structp png_ptr, png_uint_32 row,\n       int pass);\n    {\n      /* put your code here */\n    }\n\n(You can give it another name that you like instead of \"write_row_callback\")\n\nTo inform libpng about your function, use\n\n    png_set_write_status_fn(png_ptr, write_row_callback);\n\nWhen this function is called the row has already been completely processed and\nit has also been written out.  The 'row' and 'pass' refer to the next row to be\nhandled.  For the\nnon-interlaced case the row that was just handled is simply one less than the\npassed in row number, and pass will always be 0.  For the interlaced case the\nsame applies unless the row value is 0, in which case the row just handled was\nthe last one from one of the preceding passes.  Because interlacing may skip a\npass you cannot be sure that the preceding pass is just 'pass\\-1', if you really\nneed to know what the last pass is record (row,pass) from the callback and use\nthe last recorded value each time.\n\nAs with the user transform you can find the output row using the\nPNG_ROW_FROM_PASS_ROW macro.\n\nYou now have the option of modifying how the compression library will\nrun.  The following functions are mainly for testing, but may be useful\nin some cases, like if you need to write PNG files extremely fast and\nare willing to give up some compression, or if you want to get the\nmaximum possible compression at the expense of slower writing.  If you\nhave no special needs in this area, let the library do what it wants by\nnot calling this function at all, as it has been tuned to deliver a good\nspeed/compression ratio. The second parameter to png_set_filter() is\nthe filter method, for which the only valid values are 0 (as of the\nJuly 1999 PNG specification, version 1.2) or 64 (if you are writing\na PNG datastream that is to be embedded in a MNG datastream).  The third\nparameter is a flag that indicates which filter type(s) are to be tested\nfor each scanline.  See the PNG specification for details on the specific\nfilter types.\n\n\n    /* turn on or off filtering, and/or choose\n       specific filters.  You can use either a single\n       PNG_FILTER_VALUE_NAME or the bitwise OR of one\n       or more PNG_FILTER_NAME masks.\n     */\n    png_set_filter(png_ptr, 0,\n       PNG_FILTER_NONE  | PNG_FILTER_VALUE_NONE |\n       PNG_FILTER_SUB   | PNG_FILTER_VALUE_SUB  |\n       PNG_FILTER_UP    | PNG_FILTER_VALUE_UP   |\n       PNG_FILTER_AVG   | PNG_FILTER_VALUE_AVG  |\n       PNG_FILTER_PAETH | PNG_FILTER_VALUE_PAETH|\n       PNG_ALL_FILTERS  | PNG_FAST_FILTERS);\n\nIf an application wants to start and stop using particular filters during\ncompression, it should start out with all of the filters (to ensure that\nthe previous row of pixels will be stored in case it's needed later),\nand then add and remove them after the start of compression.\n\nIf you are writing a PNG datastream that is to be embedded in a MNG\ndatastream, the second parameter can be either 0 or 64.\n\nThe png_set_compression_*() functions interface to the zlib compression\nlibrary, and should mostly be ignored unless you really know what you are\ndoing.  The only generally useful call is png_set_compression_level()\nwhich changes how much time zlib spends on trying to compress the image\ndata.  See the Compression Library (zlib.h and algorithm.txt, distributed\nwith zlib) for details on the compression levels.\n\n    #include zlib.h\n\n    /* Set the zlib compression level */\n    png_set_compression_level(png_ptr,\n        Z_BEST_COMPRESSION);\n\n    /* Set other zlib parameters for compressing IDAT */\n    png_set_compression_mem_level(png_ptr, 8);\n    png_set_compression_strategy(png_ptr,\n        Z_DEFAULT_STRATEGY);\n    png_set_compression_window_bits(png_ptr, 15);\n    png_set_compression_method(png_ptr, 8);\n    png_set_compression_buffer_size(png_ptr, 8192)\n\n    /* Set zlib parameters for text compression\n     * If you don't call these, the parameters\n     * fall back on those defined for IDAT chunks\n     */\n    png_set_text_compression_mem_level(png_ptr, 8);\n    png_set_text_compression_strategy(png_ptr,\n        Z_DEFAULT_STRATEGY);\n    png_set_text_compression_window_bits(png_ptr, 15);\n    png_set_text_compression_method(png_ptr, 8);\n\n.SS Setting the contents of info for output\n\nYou now need to fill in the png_info structure with all the data you\nwish to write before the actual image.  Note that the only thing you\nare allowed to write after the image is the text chunks and the time\nchunk (as of PNG Specification 1.2, anyway).  See png_write_end() and\nthe latest PNG specification for more information on that.  If you\nwish to write them before the image, fill them in now, and flag that\ndata as being valid.  If you want to wait until after the data, don't\nfill them until png_write_end().  For all the fields in png_info and\ntheir data types, see png.h.  For explanations of what the fields\ncontain, see the PNG specification.\n\nSome of the more important parts of the png_info are:\n\n    png_set_IHDR(png_ptr, info_ptr, width, height,\n       bit_depth, color_type, interlace_type,\n       compression_type, filter_method)\n\n    width          - holds the width of the image\n                     in pixels (up to 2^31).\n\n    height         - holds the height of the image\n                     in pixels (up to 2^31).\n\n    bit_depth      - holds the bit depth of one of the\n                     image channels.\n                     (valid values are 1, 2, 4, 8, 16\n                     and depend also on the\n                     color_type.  See also significant\n                     bits (sBIT) below).\n\n    color_type     - describes which color/alpha\n                     channels are present.\n                     PNG_COLOR_TYPE_GRAY\n                        (bit depths 1, 2, 4, 8, 16)\n                     PNG_COLOR_TYPE_GRAY_ALPHA\n                        (bit depths 8, 16)\n                     PNG_COLOR_TYPE_PALETTE\n                        (bit depths 1, 2, 4, 8)\n                     PNG_COLOR_TYPE_RGB\n                        (bit_depths 8, 16)\n                     PNG_COLOR_TYPE_RGB_ALPHA\n                        (bit_depths 8, 16)\n\n                     PNG_COLOR_MASK_PALETTE\n                     PNG_COLOR_MASK_COLOR\n                     PNG_COLOR_MASK_ALPHA\n\n    interlace_type - PNG_INTERLACE_NONE or\n                     PNG_INTERLACE_ADAM7\n\n    compression_type - (must be\n                     PNG_COMPRESSION_TYPE_DEFAULT)\n\n    filter_method  - (must be PNG_FILTER_TYPE_DEFAULT\n                     or, if you are writing a PNG to\n                     be embedded in a MNG datastream,\n                     can also be\n                     PNG_INTRAPIXEL_DIFFERENCING)\n\nIf you call png_set_IHDR(), the call must appear before any of the\nother png_set_*() functions, because they might require access to some of\nthe IHDR settings.  The remaining png_set_*() functions can be called\nin any order.\n\nIf you wish, you can reset the compression_type, interlace_type, or\nfilter_method later by calling png_set_IHDR() again; if you do this, the\nwidth, height, bit_depth, and color_type must be the same in each call.\n\n    png_set_PLTE(png_ptr, info_ptr, palette,\n       num_palette);\n\n    palette        - the palette for the file\n                     (array of png_color)\n    num_palette    - number of entries in the palette\n\n\n    png_set_gAMA(png_ptr, info_ptr, file_gamma);\n    png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);\n\n    file_gamma     - the gamma at which the image was\n                     created (PNG_INFO_gAMA)\n\n    int_file_gamma - 100,000 times the gamma at which\n                     the image was created\n\n    png_set_cHRM(png_ptr, info_ptr,  white_x, white_y, red_x, red_y,\n                     green_x, green_y, blue_x, blue_y)\n    png_set_cHRM_XYZ(png_ptr, info_ptr, red_X, red_Y, red_Z, green_X,\n                     green_Y, green_Z, blue_X, blue_Y, blue_Z)\n    png_set_cHRM_fixed(png_ptr, info_ptr, int_white_x, int_white_y,\n                     int_red_x, int_red_y, int_green_x, int_green_y,\n                     int_blue_x, int_blue_y)\n    png_set_cHRM_XYZ_fixed(png_ptr, info_ptr, int_red_X, int_red_Y,\n                     int_red_Z, int_green_X, int_green_Y, int_green_Z,\n                     int_blue_X, int_blue_Y, int_blue_Z)\n\n    {white,red,green,blue}_{x,y}\n                     A color space encoding specified using the chromaticities\n                     of the end points and the white point.\n\n    {red,green,blue}_{X,Y,Z}\n                     A color space encoding specified using the encoding end\n                     points - the CIE tristimulus specification of the intended\n                     color of the red, green and blue channels in the PNG RGB\n                     data.  The white point is simply the sum of the three end\n                     points.\n\n    png_set_sRGB(png_ptr, info_ptr, srgb_intent);\n\n    srgb_intent    - the rendering intent\n                     (PNG_INFO_sRGB) The presence of\n                     the sRGB chunk means that the pixel\n                     data is in the sRGB color space.\n                     This chunk also implies specific\n                     values of gAMA and cHRM.  Rendering\n                     intent is the CSS-1 property that\n                     has been defined by the International\n                     Color Consortium\n                     (http://www.color.org).\n                     It can be one of\n                     PNG_sRGB_INTENT_SATURATION,\n                     PNG_sRGB_INTENT_PERCEPTUAL,\n                     PNG_sRGB_INTENT_ABSOLUTE, or\n                     PNG_sRGB_INTENT_RELATIVE.\n\n\n    png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr,\n       srgb_intent);\n\n    srgb_intent    - the rendering intent\n                     (PNG_INFO_sRGB) The presence of the\n                     sRGB chunk means that the pixel\n                     data is in the sRGB color space.\n                     This function also causes gAMA and\n                     cHRM chunks with the specific values\n                     that are consistent with sRGB to be\n                     written.\n\n    png_set_iCCP(png_ptr, info_ptr, name, compression_type,\n                       profile, proflen);\n\n    name             - The profile name.\n\n    compression_type - The compression type; always\n                       PNG_COMPRESSION_TYPE_BASE for PNG 1.0.\n                       You may give NULL to this argument to\n                       ignore it.\n\n    profile          - International Color Consortium color\n                       profile data. May contain NULs.\n\n    proflen          - length of profile data in bytes.\n\n    png_set_sBIT(png_ptr, info_ptr, sig_bit);\n\n    sig_bit        - the number of significant bits for\n                     (PNG_INFO_sBIT) each of the gray, red,\n                     green, and blue channels, whichever are\n                     appropriate for the given color type\n                     (png_color_16)\n\n    png_set_tRNS(png_ptr, info_ptr, trans_alpha,\n       num_trans, trans_color);\n\n    trans_alpha    - array of alpha (transparency)\n                     entries for palette (PNG_INFO_tRNS)\n\n    num_trans      - number of transparent entries\n                     (PNG_INFO_tRNS)\n\n    trans_color    - graylevel or color sample values\n                     (in order red, green, blue) of the\n                     single transparent color for\n                     non-paletted images (PNG_INFO_tRNS)\n\n    png_set_hIST(png_ptr, info_ptr, hist);\n\n    hist           - histogram of palette (array of\n                     png_uint_16) (PNG_INFO_hIST)\n\n    png_set_tIME(png_ptr, info_ptr, mod_time);\n\n    mod_time       - time image was last modified\n                     (PNG_VALID_tIME)\n\n    png_set_bKGD(png_ptr, info_ptr, background);\n\n    background     - background color (of type\n                     png_color_16p) (PNG_VALID_bKGD)\n\n    png_set_text(png_ptr, info_ptr, text_ptr, num_text);\n\n    text_ptr       - array of png_text holding image\n                     comments\n\n    text_ptr[i].compression - type of compression used\n                 on \"text\" PNG_TEXT_COMPRESSION_NONE\n                           PNG_TEXT_COMPRESSION_zTXt\n                           PNG_ITXT_COMPRESSION_NONE\n                           PNG_ITXT_COMPRESSION_zTXt\n    text_ptr[i].key   - keyword for comment.  Must contain\n                 1-79 characters.\n    text_ptr[i].text  - text comments for current\n                         keyword.  Can be NULL or empty.\n    text_ptr[i].text_length - length of text string,\n                 after decompression, 0 for iTXt\n    text_ptr[i].itxt_length - length of itxt string,\n                 after decompression, 0 for tEXt/zTXt\n    text_ptr[i].lang  - language of comment (NULL or\n                         empty for unknown).\n    text_ptr[i].translated_keyword  - keyword in UTF-8 (NULL\n                         or empty for unknown).\n\n    Note that the itxt_length, lang, and lang_key\n    members of the text_ptr structure only exist when the\n    library is built with iTXt chunk support.  Prior to\n    libpng-1.4.0 the library was built by default without\n    iTXt support. Also note that when iTXt is supported,\n    they contain NULL pointers when the \"compression\"\n    field contains PNG_TEXT_COMPRESSION_NONE or\n    PNG_TEXT_COMPRESSION_zTXt.\n\n    num_text       - number of comments\n\n    png_set_sPLT(png_ptr, info_ptr, &palette_ptr,\n       num_spalettes);\n\n    palette_ptr    - array of png_sPLT_struct structures\n                     to be added to the list of palettes\n                     in the info structure.\n    num_spalettes  - number of palette structures to be\n                     added.\n\n    png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y,\n        unit_type);\n\n    offset_x  - positive offset from the left\n                     edge of the screen\n\n    offset_y  - positive offset from the top\n                     edge of the screen\n\n    unit_type - PNG_OFFSET_PIXEL, PNG_OFFSET_MICROMETER\n\n    png_set_pHYs(png_ptr, info_ptr, res_x, res_y,\n        unit_type);\n\n    res_x       - pixels/unit physical resolution\n                  in x direction\n\n    res_y       - pixels/unit physical resolution\n                  in y direction\n\n    unit_type   - PNG_RESOLUTION_UNKNOWN,\n                  PNG_RESOLUTION_METER\n\n    png_set_sCAL(png_ptr, info_ptr, unit, width, height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n\n    height      - height of a pixel in physical scale units\n                  (width and height are doubles)\n\n    png_set_sCAL_s(png_ptr, info_ptr, unit, width, height)\n\n    unit        - physical scale units (an integer)\n\n    width       - width of a pixel in physical scale units\n                  expressed as a string\n\n    height      - height of a pixel in physical scale units\n                 (width and height are strings like \"2.54\")\n\n    png_set_unknown_chunks(png_ptr, info_ptr, &unknowns,\n       num_unknowns)\n\n    unknowns          - array of png_unknown_chunk\n                        structures holding unknown chunks\n    unknowns[i].name  - name of unknown chunk\n    unknowns[i].data  - data of unknown chunk\n    unknowns[i].size  - size of unknown chunk's data\n    unknowns[i].location - position to write chunk in file\n                           0: do not write chunk\n                           PNG_HAVE_IHDR: before PLTE\n                           PNG_HAVE_PLTE: before IDAT\n                           PNG_AFTER_IDAT: after IDAT\n\nThe \"location\" member is set automatically according to\nwhat part of the output file has already been written.\nYou can change its value after calling png_set_unknown_chunks()\nas demonstrated in pngtest.c.  Within each of the \"locations\",\nthe chunks are sequenced according to their position in the\nstructure (that is, the value of \"i\", which is the order in which\nthe chunk was either read from the input file or defined with\npng_set_unknown_chunks).\n\nA quick word about text and num_text.  text is an array of png_text\nstructures.  num_text is the number of valid structures in the array.\nEach png_text structure holds a language code, a keyword, a text value,\nand a compression type.\n\nThe compression types have the same valid numbers as the compression\ntypes of the image data.  Currently, the only valid number is zero.\nHowever, you can store text either compressed or uncompressed, unlike\nimages, which always have to be compressed.  So if you don't want the\ntext compressed, set the compression type to PNG_TEXT_COMPRESSION_NONE.\nBecause tEXt and zTXt chunks don't have a language field, if you\nspecify PNG_TEXT_COMPRESSION_NONE or PNG_TEXT_COMPRESSION_zTXt\nany language code or translated keyword will not be written out.\n\nUntil text gets around a few hundred bytes, it is not worth compressing it.\nAfter the text has been written out to the file, the compression type\nis set to PNG_TEXT_COMPRESSION_NONE_WR or PNG_TEXT_COMPRESSION_zTXt_WR,\nso that it isn't written out again at the end (in case you are calling\npng_write_end() with the same struct).\n\nThe keywords that are given in the PNG Specification are:\n\n    Title            Short (one line) title or\n                     caption for image\n\n    Author           Name of image's creator\n\n    Description      Description of image (possibly long)\n\n    Copyright        Copyright notice\n\n    Creation Time    Time of original image creation\n                     (usually RFC 1123 format, see below)\n\n    Software         Software used to create the image\n\n    Disclaimer       Legal disclaimer\n\n    Warning          Warning of nature of content\n\n    Source           Device used to create the image\n\n    Comment          Miscellaneous comment; conversion\n                     from other image format\n\nThe keyword-text pairs work like this.  Keywords should be short\nsimple descriptions of what the comment is about.  Some typical\nkeywords are found in the PNG specification, as is some recommendations\non keywords.  You can repeat keywords in a file.  You can even write\nsome text before the image and some after.  For example, you may want\nto put a description of the image before the image, but leave the\ndisclaimer until after, so viewers working over modem connections\ndon't have to wait for the disclaimer to go over the modem before\nthey start seeing the image.  Finally, keywords should be full\nwords, not abbreviations.  Keywords and text are in the ISO 8859-1\n(Latin-1) character set (a superset of regular ASCII) and can not\ncontain NUL characters, and should not contain control or other\nunprintable characters.  To make the comments widely readable, stick\nwith basic ASCII, and avoid machine specific character set extensions\nlike the IBM-PC character set.  The keyword must be present, but\nyou can leave off the text string on non-compressed pairs.\nCompressed pairs must have a text string, as only the text string\nis compressed anyway, so the compression would be meaningless.\n\nPNG supports modification time via the png_time structure.  Two\nconversion routines are provided, png_convert_from_time_t() for\ntime_t and png_convert_from_struct_tm() for struct tm.  The\ntime_t routine uses gmtime().  You don't have to use either of\nthese, but if you wish to fill in the png_time structure directly,\nyou should provide the time in universal time (GMT) if possible\ninstead of your local time.  Note that the year number is the full\nyear (e.g. 1998, rather than 98 - PNG is year 2000 compliant!), and\nthat months start with 1.\n\nIf you want to store the time of the original image creation, you should\nuse a plain tEXt chunk with the \"Creation Time\" keyword.  This is\nnecessary because the \"creation time\" of a PNG image is somewhat vague,\ndepending on whether you mean the PNG file, the time the image was\ncreated in a non-PNG format, a still photo from which the image was\nscanned, or possibly the subject matter itself.  In order to facilitate\nmachine-readable dates, it is recommended that the \"Creation Time\"\ntEXt chunk use RFC 1123 format dates (e.g. \"22 May 1997 18:07:10 GMT\"),\nalthough this isn't a requirement.  Unlike the tIME chunk, the\n\"Creation Time\" tEXt chunk is not expected to be automatically changed\nby the software.  To facilitate the use of RFC 1123 dates, a function\npng_convert_to_rfc1123_buffer(buffer, png_timep) is provided to\nconvert from PNG time to an RFC 1123 format string.  The caller must provide\na writeable buffer of at least 29 bytes.\n\n.SS Writing unknown chunks\n\nYou can use the png_set_unknown_chunks function to queue up private chunks\nfor writing.  You give it a chunk name, location, raw data, and a size.  You\nalso must use png_set_keep_unknown_chunks() to ensure that libpng will\nhandle them.  That's all there is to it.  The chunks will be written by the\nnext following png_write_info_before_PLTE, png_write_info, or png_write_end\nfunction, depending upon the specified location.  Any chunks previously\nread into the info structure's unknown-chunk list will also be written out\nin a sequence that satisfies the PNG specification's ordering rules.\n\nHere is an example of writing two private chunks, prVt and miNE:\n\n    #ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n    /* Set unknown chunk data */\n    png_unknown_chunk unk_chunk[2];\n    strcpy((char *) unk_chunk[0].name, \"prVt\";\n    unk_chunk[0].data = (unsigned char *) \"PRIVATE DATA\";\n    unk_chunk[0].size = strlen(unk_chunk[0].data)+1;\n    unk_chunk[0].location = PNG_HAVE_IHDR;\n    strcpy((char *) unk_chunk[1].name, \"miNE\";\n    unk_chunk[1].data = (unsigned char *) \"MY CHUNK DATA\";\n    unk_chunk[1].size = strlen(unk_chunk[0].data)+1;\n    unk_chunk[1].location = PNG_AFTER_IDAT;\n    png_set_unknown_chunks(write_ptr, write_info_ptr,\n        unk_chunk, 2);\n    /* Needed because miNE is not safe-to-copy */\n    png_set_keep_unknown_chunks(png, PNG_HANDLE_CHUNK_ALWAYS,\n       (png_bytep) \"miNE\", 1);\n    # if PNG_LIBPNG_VER < 10600\n      /* Deal with unknown chunk location bug in 1.5.x and earlier */\n      png_set_unknown_chunk_location(png, info, 0, PNG_HAVE_IHDR);\n      png_set_unknown_chunk_location(png, info, 1, PNG_AFTER_IDAT);\n    # endif\n    # if PNG_LIBPNG_VER < 10500\n      /* PNG_AFTER_IDAT writes two copies of the chunk prior to libpng-1.5.0,\n       * one before IDAT and another after IDAT, so don't use it; only use\n       * PNG_HAVE_IHDR location.  This call resets the location previously\n       * set by assignment and png_set_unknown_chunk_location() for chunk 1.\n       */\n      png_set_unknown_chunk_location(png, info, 1, PNG_HAVE_IHDR);\n    # endif\n    #endif\n\n.SS The high-level write interface\n\nAt this point there are two ways to proceed; through the high-level\nwrite interface, or through a sequence of low-level write operations.\nYou can use the high-level interface if your image data is present\nin the info structure.  All defined output\ntransformations are permitted, enabled by the following masks.\n\n    PNG_TRANSFORM_IDENTITY      No transformation\n    PNG_TRANSFORM_PACKING       Pack 1, 2 and 4-bit samples\n    PNG_TRANSFORM_PACKSWAP      Change order of packed\n                                pixels to LSB first\n    PNG_TRANSFORM_INVERT_MONO   Invert monochrome images\n    PNG_TRANSFORM_SHIFT         Normalize pixels to the\n                                sBIT depth\n    PNG_TRANSFORM_BGR           Flip RGB to BGR, RGBA\n                                to BGRA\n    PNG_TRANSFORM_SWAP_ALPHA    Flip RGBA to ARGB or GA\n                                to AG\n    PNG_TRANSFORM_INVERT_ALPHA  Change alpha from opacity\n                                to transparency\n    PNG_TRANSFORM_SWAP_ENDIAN   Byte-swap 16-bit samples\n    PNG_TRANSFORM_STRIP_FILLER        Strip out filler\n                                      bytes (deprecated).\n    PNG_TRANSFORM_STRIP_FILLER_BEFORE Strip out leading\n                                      filler bytes\n    PNG_TRANSFORM_STRIP_FILLER_AFTER  Strip out trailing\n                                      filler bytes\n\nIf you have valid image data in the info structure (you can use\npng_set_rows() to put image data in the info structure), simply do this:\n\n    png_write_png(png_ptr, info_ptr, png_transforms, NULL)\n\nwhere png_transforms is an integer containing the bitwise OR of some set of\ntransformation flags.  This call is equivalent to png_write_info(),\nfollowed the set of transformations indicated by the transform mask,\nthen png_write_image(), and finally png_write_end().\n\n(The final parameter of this call is not yet used.  Someday it might point\nto transformation parameters required by some future output transform.)\n\nYou must use png_transforms and not call any png_set_transform() functions\nwhen you use png_write_png().\n\n.SS The low-level write interface\n\nIf you are going the low-level route instead, you are now ready to\nwrite all the file information up to the actual image data.  You do\nthis with a call to png_write_info().\n\n    png_write_info(png_ptr, info_ptr);\n\nNote that there is one transformation you may need to do before\npng_write_info().  In PNG files, the alpha channel in an image is the\nlevel of opacity.  If your data is supplied as a level of transparency,\nyou can invert the alpha channel before you write it, so that 0 is\nfully transparent and 255 (in 8-bit or paletted images) or 65535\n(in 16-bit images) is fully opaque, with\n\n    png_set_invert_alpha(png_ptr);\n\nThis must appear before png_write_info() instead of later with the\nother transformations because in the case of paletted images the tRNS\nchunk data has to be inverted before the tRNS chunk is written.  If\nyour image is not a paletted image, the tRNS data (which in such cases\nrepresents a single color to be rendered as transparent) won't need to\nbe changed, and you can safely do this transformation after your\npng_write_info() call.\n\nIf you need to write a private chunk that you want to appear before\nthe PLTE chunk when PLTE is present, you can write the PNG info in\ntwo steps, and insert code to write your own chunk between them:\n\n    png_write_info_before_PLTE(png_ptr, info_ptr);\n    png_set_unknown_chunks(png_ptr, info_ptr, ...);\n    png_write_info(png_ptr, info_ptr);\n\nAfter you've written the file information, you can set up the library\nto handle any special transformations of the image data.  The various\nways to transform the data will be described in the order that they\nshould occur.  This is important, as some of these change the color\ntype and/or bit depth of the data, and some others only work on\ncertain color types and bit depths.  Even though each transformation\nchecks to see if it has data that it can do something with, you should\nmake sure to only enable a transformation if it will be valid for the\ndata.  For example, don't swap red and blue on grayscale data.\n\nPNG files store RGB pixels packed into 3 or 6 bytes.  This code tells\nthe library to strip input data that has 4 or 8 bytes per pixel down\nto 3 or 6 bytes (or strip 2 or 4-byte grayscale+filler data to 1 or 2\nbytes per pixel).\n\n    png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);\n\nwhere the 0 is unused, and the location is either PNG_FILLER_BEFORE or\nPNG_FILLER_AFTER, depending upon whether the filler byte in the pixel\nis stored XRGB or RGBX.\n\nPNG files pack pixels of bit depths 1, 2, and 4 into bytes as small as\nthey can, resulting in, for example, 8 pixels per byte for 1 bit files.\nIf the data is supplied at 1 pixel per byte, use this code, which will\ncorrectly pack the pixels into a single byte:\n\n    png_set_packing(png_ptr);\n\nPNG files reduce possible bit depths to 1, 2, 4, 8, and 16.  If your\ndata is of another bit depth, you can write an sBIT chunk into the\nfile so that decoders can recover the original data if desired.\n\n    /* Set the true bit depth of the image data */\n    if (color_type & PNG_COLOR_MASK_COLOR)\n    {\n       sig_bit.red = true_bit_depth;\n       sig_bit.green = true_bit_depth;\n       sig_bit.blue = true_bit_depth;\n    }\n\n    else\n    {\n       sig_bit.gray = true_bit_depth;\n    }\n\n    if (color_type & PNG_COLOR_MASK_ALPHA)\n    {\n       sig_bit.alpha = true_bit_depth;\n    }\n\n    png_set_sBIT(png_ptr, info_ptr, &sig_bit);\n\nIf the data is stored in the row buffer in a bit depth other than\none supported by PNG (e.g. 3 bit data in the range 0-7 for a 4-bit PNG),\nthis will scale the values to appear to be the correct bit depth as\nis required by PNG.\n\n    png_set_shift(png_ptr, &sig_bit);\n\nPNG files store 16-bit pixels in network byte order (big-endian,\nie. most significant bits first).  This code would be used if they are\nsupplied the other way (little-endian, i.e. least significant bits\nfirst, the way PCs store them):\n\n    if (bit_depth > 8)\n       png_set_swap(png_ptr);\n\nIf you are using packed-pixel images (1, 2, or 4 bits/pixel), and you\nneed to change the order the pixels are packed into bytes, you can use:\n\n    if (bit_depth < 8)\n       png_set_packswap(png_ptr);\n\nPNG files store 3 color pixels in red, green, blue order.  This code\nwould be used if they are supplied as blue, green, red:\n\n    png_set_bgr(png_ptr);\n\nPNG files describe monochrome as black being zero and white being\none. This code would be used if the pixels are supplied with this reversed\n(black being one and white being zero):\n\n    png_set_invert_mono(png_ptr);\n\nFinally, you can write your own transformation function if none of\nthe existing ones meets your needs.  This is done by setting a callback\nwith\n\n    png_set_write_user_transform_fn(png_ptr,\n       write_transform_fn);\n\nYou must supply the function\n\n    void write_transform_fn(png_structp png_ptr, png_row_infop\n       row_info, png_bytep data)\n\nSee pngtest.c for a working example.  Your function will be called\nbefore any of the other transformations are processed.  If supported\nlibpng also supplies an information routine that may be called from\nyour callback:\n\n   png_get_current_row_number(png_ptr);\n   png_get_current_pass_number(png_ptr);\n\nThis returns the current row passed to the transform.  With interlaced\nimages the value returned is the row in the input sub-image image.  Use\nPNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\nfind the output pixel (x,y) given an interlaced sub-image pixel (row,col,pass).\n\nThe discussion of interlace handling above contains more information on how to\nuse these values.\n\nYou can also set up a pointer to a user structure for use by your\ncallback function.\n\n    png_set_user_transform_info(png_ptr, user_ptr, 0, 0);\n\nThe user_channels and user_depth parameters of this function are ignored\nwhen writing; you can set them to zero as shown.\n\nYou can retrieve the pointer via the function png_get_user_transform_ptr().\nFor example:\n\n    voidp write_user_transform_ptr =\n       png_get_user_transform_ptr(png_ptr);\n\nIt is possible to have libpng flush any pending output, either manually,\nor automatically after a certain number of lines have been written.  To\nflush the output stream a single time call:\n\n    png_write_flush(png_ptr);\n\nand to have libpng flush the output stream periodically after a certain\nnumber of scanlines have been written, call:\n\n    png_set_flush(png_ptr, nrows);\n\nNote that the distance between rows is from the last time png_write_flush()\nwas called, or the first row of the image if it has never been called.\nSo if you write 50 lines, and then png_set_flush 25, it will flush the\noutput on the next scanline, and every 25 lines thereafter, unless\npng_write_flush() is called before 25 more lines have been written.\nIf nrows is too small (less than about 10 lines for a 640 pixel wide\nRGB image) the image compression may decrease noticeably (although this\nmay be acceptable for real-time applications).  Infrequent flushing will\nonly degrade the compression performance by a few percent over images\nthat do not use flushing.\n\n.SS Writing the image data\n\nThat's it for the transformations.  Now you can write the image data.\nThe simplest way to do this is in one function call.  If you have the\nwhole image in memory, you can just call png_write_image() and libpng\nwill write the image.  You will need to pass in an array of pointers to\neach row.  This function automatically handles interlacing, so you don't\nneed to call png_set_interlace_handling() or call this function multiple\ntimes, or any of that other stuff necessary with png_write_rows().\n\n    png_write_image(png_ptr, row_pointers);\n\nwhere row_pointers is:\n\n    png_byte *row_pointers[height];\n\nYou can point to void or char or whatever you use for pixels.\n\nIf you don't want to write the whole image at once, you can\nuse png_write_rows() instead.  If the file is not interlaced,\nthis is simple:\n\n    png_write_rows(png_ptr, row_pointers,\n       number_of_rows);\n\nrow_pointers is the same as in the png_write_image() call.\n\nIf you are just writing one row at a time, you can do this with\na single row_pointer instead of an array of row_pointers:\n\n    png_bytep row_pointer = row;\n\n    png_write_row(png_ptr, row_pointer);\n\nWhen the file is interlaced, things can get a good deal more complicated.\nThe only currently (as of the PNG Specification version 1.2, dated July\n1999) defined interlacing scheme for PNG files is the \"Adam7\" interlace\nscheme, that breaks down an image into seven smaller images of varying\nsize.  libpng will build these images for you, or you can do them\nyourself.  If you want to build them yourself, see the PNG specification\nfor details of which pixels to write when.\n\nIf you don't want libpng to handle the interlacing details, just\nuse png_set_interlace_handling() and call png_write_rows() the\ncorrect number of times to write all the sub-images\n(png_set_interlace_handling() returns the number of sub-images.)\n\nIf you want libpng to build the sub-images, call this before you start\nwriting any rows:\n\n    number_of_passes = png_set_interlace_handling(png_ptr);\n\nThis will return the number of passes needed.  Currently, this is seven,\nbut may change if another interlace type is added.\n\nThen write the complete image number_of_passes times.\n\n    png_write_rows(png_ptr, row_pointers, number_of_rows);\n\nThink carefully before you write an interlaced image.  Typically code that\nreads such images reads all the image data into memory, uncompressed, before\ndoing any processing.  Only code that can display an image on the fly can\ntake advantage of the interlacing and even then the image has to be exactly\nthe correct size for the output device, because scaling an image requires\nadjacent pixels and these are not available until all the passes have been\nread.\n\nIf you do write an interlaced image you will hardly ever need to handle\nthe interlacing yourself.  Call png_set_interlace_handling() and use the\napproach described above.\n\nThe only time it is conceivable that you will really need to write an\ninterlaced image pass-by-pass is when you have read one pass by pass and\nmade some pixel-by-pixel transformation to it, as described in the read\ncode above.  In this case use the PNG_PASS_ROWS and PNG_PASS_COLS macros\nto determine the size of each sub-image in turn and simply write the rows\nyou obtained from the read code.\n\n.SS Finishing a sequential write\n\nAfter you are finished writing the image, you should finish writing\nthe file.  If you are interested in writing comments or time, you should\npass an appropriately filled png_info pointer.  If you are not interested,\nyou can pass NULL.\n\n    png_write_end(png_ptr, info_ptr);\n\nWhen you are done, you can free all memory used by libpng like this:\n\n    png_destroy_write_struct(&png_ptr, &info_ptr);\n\nIt is also possible to individually free the info_ptr members that\npoint to libpng-allocated storage with the following function:\n\n    png_free_data(png_ptr, info_ptr, mask, seq)\n\n    mask  - identifies data to be freed, a mask\n            containing the bitwise OR of one or\n            more of\n              PNG_FREE_PLTE, PNG_FREE_TRNS,\n              PNG_FREE_HIST, PNG_FREE_ICCP,\n              PNG_FREE_PCAL, PNG_FREE_ROWS,\n              PNG_FREE_SCAL, PNG_FREE_SPLT,\n              PNG_FREE_TEXT, PNG_FREE_UNKN,\n            or simply PNG_FREE_ALL\n\n    seq   - sequence number of item to be freed\n            (\\-1 for all items)\n\nThis function may be safely called when the relevant storage has\nalready been freed, or has not yet been allocated, or was allocated\nby the user  and not by libpng,  and will in those cases do nothing.\nThe \"seq\" parameter is ignored if only one item of the selected data\ntype, such as PLTE, is allowed.  If \"seq\" is not \\-1, and multiple items\nare allowed for the data type identified in the mask, such as text or\nsPLT, only the n'th item in the structure is freed, where n is \"seq\".\n\nIf you allocated data such as a palette that you passed in to libpng\nwith png_set_*, you must not free it until just before the call to\npng_destroy_write_struct().\n\nThe default behavior is only to free data that was allocated internally\nby libpng.  This can be changed, so that libpng will not free the data,\nor so that it will free data that was allocated by the user with png_malloc()\nor png_calloc() and passed in via a png_set_*() function, with\n\n    png_data_freer(png_ptr, info_ptr, freer, mask)\n\n    freer  - one of\n               PNG_DESTROY_WILL_FREE_DATA\n               PNG_SET_WILL_FREE_DATA\n               PNG_USER_WILL_FREE_DATA\n\n    mask   - which data elements are affected\n             same choices as in png_free_data()\n\nFor example, to transfer responsibility for some data from a read structure\nto a write structure, you could use\n\n    png_data_freer(read_ptr, read_info_ptr,\n       PNG_USER_WILL_FREE_DATA,\n       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)\n\n    png_data_freer(write_ptr, write_info_ptr,\n       PNG_DESTROY_WILL_FREE_DATA,\n       PNG_FREE_PLTE|PNG_FREE_tRNS|PNG_FREE_hIST)\n\nthereby briefly reassigning responsibility for freeing to the user but\nimmediately afterwards reassigning it once more to the write_destroy\nfunction.  Having done this, it would then be safe to destroy the read\nstructure and continue to use the PLTE, tRNS, and hIST data in the write\nstructure.\n\nThis function only affects data that has already been allocated.\nYou can call this function before calling after the png_set_*() functions\nto control whether the user or png_destroy_*() is supposed to free the data.\nWhen the user assumes responsibility for libpng-allocated data, the\napplication must use\npng_free() to free it, and when the user transfers responsibility to libpng\nfor data that the user has allocated, the user must have used png_malloc()\nor png_calloc() to allocate it.\n\nIf you allocated text_ptr.text, text_ptr.lang, and text_ptr.translated_keyword\nseparately, do not transfer responsibility for freeing text_ptr to libpng,\nbecause when libpng fills a png_text structure it combines these members with\nthe key member, and png_free_data() will free only text_ptr.key.  Similarly,\nif you transfer responsibility for free'ing text_ptr from libpng to your\napplication, your application must not separately free those members.\nFor a more compact example of writing a PNG image, see the file example.c.\n\n.SH V. Simplified API\n\nThe simplified API, which became available in libpng-1.6.0, hides the details\nof both libpng and the PNG file format itself.\nIt allows PNG files to be read into a very limited number of\nin-memory bitmap formats or to be written from the same formats.  If these\nformats do not accommodate your needs then you can, and should, use the more\nsophisticated APIs above - these support a wide variety of in-memory formats\nand a wide variety of sophisticated transformations to those formats as well\nas a wide variety of APIs to manipulate ancilliary information.\n\nTo read a PNG file using the simplified API:\n\n  1) Declare a 'png_image' structure (see below) on the stack, set the\n     version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL\n     (this is REQUIRED, your program may crash if you don't do it.)\n\n  2) Call the appropriate png_image_begin_read... function.\n\n  3) Set the png_image 'format' member to the required sample format.\n\n  4) Allocate a buffer for the image and, if required, the color-map.\n\n  5) Call png_image_finish_read to read the image and, if required, the\n     color-map into your buffers.\n\nThere are no restrictions on the format of the PNG input itself; all valid\ncolor types, bit depths, and interlace methods are acceptable, and the\ninput image is transformed as necessary to the requested in-memory format\nduring the png_image_finish_read() step.  The only caveat is that if you\nrequest a color-mapped image from a PNG that is full-color or makes\ncomplex use of an alpha channel the transformation is extremely lossy and the\nresult may look terrible.\n\nTo write a PNG file using the simplified API:\n\n  1) Declare a 'png_image' structure on the stack and memset()\n     it to all zero.\n\n  2) Initialize the members of the structure that describe the\n     image, setting the 'format' member to the format of the\n     image samples.\n\n  3) Call the appropriate png_image_write... function with a\n     pointer to the image and, if necessary, the color-map to write\n     the PNG data.\n\npng_image is a structure that describes the in-memory format of an image\nwhen it is being read or defines the in-memory format of an image that you\nneed to write.  The \"png_image\" structure contains the following members:\n\n   png_controlp opaque  Initialize to NULL, free with png_image_free\n   png_uint_32  version Set to PNG_IMAGE_VERSION\n   png_uint_32  width   Image width in pixels (columns)\n   png_uint_32  height  Image height in pixels (rows)\n   png_uint_32  format  Image format as defined below\n   png_uint_32  flags   A bit mask containing informational flags\n   png_uint_32  colormap_entries; Number of entries in the color-map\n   png_uint_32  warning_or_error;\n   char         message[64];\n\nIn the event of an error or warning the \"warning_or_error\"\nfield will be set to a non-zero value and the 'message' field will contain\na '\\0' terminated string with the libpng error or warning message.  If both\nwarnings and an error were encountered, only the error is recorded.  If there\nare multiple warnings, only the first one is recorded.\n\nThe upper 30 bits of the \"warning_or_error\" value are reserved; the low two\nbits contain a two bit code such that a value more than 1 indicates a failure\nin the API just called:\n\n   0 - no warning or error\n   1 - warning\n   2 - error\n   3 - error preceded by warning\n\nThe pixels (samples) of the image have one to four channels whose components\nhave original values in the range 0 to 1.0:\n\n  1: A single gray or luminance channel (G).\n  2: A gray/luminance channel and an alpha channel (GA).\n  3: Three red, green, blue color channels (RGB).\n  4: Three color channels and an alpha channel (RGBA).\n\nThe channels are encoded in one of two ways:\n\n  a) As a small integer, value 0..255, contained in a single byte.  For the\nalpha channel the original value is simply value/255.  For the color or\nluminance channels the value is encoded according to the sRGB specification\nand matches the 8-bit format expected by typical display devices.\n\nThe color/gray channels are not scaled (pre-multiplied) by the alpha\nchannel and are suitable for passing to color management software.\n\n  b) As a value in the range 0..65535, contained in a 2-byte integer, in\nthe native byte order of the platform on which the application is running.\nAll channels can be converted to the original value by dividing by 65535; all\nchannels are linear.  Color channels use the RGB encoding (RGB end-points) of\nthe sRGB specification.  This encoding is identified by the\nPNG_FORMAT_FLAG_LINEAR flag below.\n\nWhen the simplified API needs to convert between sRGB and linear colorspaces,\nthe actual sRGB transfer curve defined in the sRGB specification (see the\narticle at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2\napproximation used elsewhere in libpng.\n\nWhen an alpha channel is present it is expected to denote pixel coverage\nof the color or luminance channels and is returned as an associated alpha\nchannel: the color/gray channels are scaled (pre-multiplied) by the alpha\nvalue.\n\nThe samples are either contained directly in the image data, between 1 and 8\nbytes per pixel according to the encoding, or are held in a color-map indexed\nby bytes in the image data.  In the case of a color-map the color-map entries\nare individual samples, encoded as above, and the image data has one byte per\npixel to select the relevant sample from the color-map.\n\nPNG_FORMAT_*\n\nThe #defines to be used in png_image::format.  Each #define identifies a\nparticular layout of channel data and, if present, alpha values.  There are\nseparate defines for each of the two component encodings.\n\nA format is built up using single bit flag values.  All combinations are\nvalid.  Formats can be built up from the flag values or you can use one of\nthe predefined values below.  When testing formats always use the FORMAT_FLAG\nmacros to test for individual features - future versions of the library may\nadd new flags.\n\nWhen reading or writing color-mapped images the format should be set to the\nformat of the entries in the color-map then png_image_{read,write}_colormap\ncalled to read or write the color-map and set the format correctly for the\nimage data.  Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!\n\nNOTE: libpng can be built with particular features disabled. If you see\ncompiler errors because the definition of one of the following flags has been\ncompiled out it is because libpng does not have the required support.  It is\npossible, however, for the libpng configuration to enable the format on just\nread or just write; in that case you may see an error at run time.\nYou can guard against this by checking for the definition of the\nappropriate \"_SUPPORTED\" macro, one of:\n\n   PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED\n\n   PNG_FORMAT_FLAG_ALPHA    format with an alpha channel\n   PNG_FORMAT_FLAG_COLOR    color format: otherwise grayscale\n   PNG_FORMAT_FLAG_LINEAR   2-byte channels else 1-byte\n   PNG_FORMAT_FLAG_COLORMAP image data is color-mapped\n   PNG_FORMAT_FLAG_BGR      BGR colors, else order is RGB\n   PNG_FORMAT_FLAG_AFIRST   alpha channel comes first\n\nSupported formats are as follows.  Future versions of libpng may support more\nformats; for compatibility with older versions simply check if the format\nmacro is defined using #ifdef.  These defines describe the in-memory layout\nof the components of the pixels of the image.\n\nFirst the single byte (sRGB) formats:\n\n   PNG_FORMAT_GRAY\n   PNG_FORMAT_GA\n   PNG_FORMAT_AG\n   PNG_FORMAT_RGB\n   PNG_FORMAT_BGR\n   PNG_FORMAT_RGBA\n   PNG_FORMAT_ARGB\n   PNG_FORMAT_BGRA\n   PNG_FORMAT_ABGR\n\nThen the linear 2-byte formats.  When naming these \"Y\" is used to\nindicate a luminance (gray) channel.  The component order within the pixel\nis always the same - there is no provision for swapping the order of the\ncomponents in the linear format.  The components are 16-bit integers in\nthe native byte order for your platform, and there is no provision for\nswapping the bytes to a different endian condition.\n\n   PNG_FORMAT_LINEAR_Y\n   PNG_FORMAT_LINEAR_Y_ALPHA\n   PNG_FORMAT_LINEAR_RGB\n   PNG_FORMAT_LINEAR_RGB_ALPHA\n\nWith color-mapped formats the image data is one byte for each pixel. The byte\nis an index into the color-map which is formatted as above.  To obtain a\ncolor-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP\nto one of the above definitions, or you can use one of the definitions below.\n\n   PNG_FORMAT_RGB_COLORMAP\n   PNG_FORMAT_BGR_COLORMAP\n   PNG_FORMAT_RGBA_COLORMAP\n   PNG_FORMAT_ARGB_COLORMAP\n   PNG_FORMAT_BGRA_COLORMAP\n   PNG_FORMAT_ABGR_COLORMAP\n\nPNG_IMAGE macros\n\nThese are convenience macros to derive information from a png_image\nstructure.  The PNG_IMAGE_SAMPLE_ macros return values appropriate to the\nactual image sample values - either the entries in the color-map or the\npixels in the image.  The PNG_IMAGE_PIXEL_ macros return corresponding values\nfor the pixels and will always return 1 for color-mapped formats.  The\nremaining macros return information about the rows in the image and the\ncomplete image.\n\nNOTE: All the macros that take a png_image::format parameter are compile time\nconstants if the format parameter is, itself, a constant.  Therefore these\nmacros can be used in array declarations and case labels where required.\nSimilarly the macros are also pre-processor constants (sizeof is not used) so\nthey can be used in #if tests.\n\n  PNG_IMAGE_SAMPLE_CHANNELS(fmt)\n    Returns the total number of channels in a given format: 1..4\n\n  PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\n    Returns the size in bytes of a single component of a pixel or color-map\n    entry (as appropriate) in the image: 1 or 2.\n\n  PNG_IMAGE_SAMPLE_SIZE(fmt)\n    This is the size of the sample data for one sample.  If the image is\n    color-mapped it is the size of one color-map entry (and image pixels are\n    one byte in size), otherwise it is the size of one image pixel.\n\n  PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\n    The maximum size of the color-map required by the format expressed in a\n    count of components.  This can be used to compile-time allocate a\n    color-map:\n\n    png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];\n\n    png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];\n\n    Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the\n    information from one of the png_image_begin_read_ APIs and dynamically\n    allocate the required memory.\n\n  PNG_IMAGE_COLORMAP_SIZE(fmt)\n   The size of the color-map required by the format; this is the size of the\n   color-map buffer passed to the png_image_{read,write}_colormap APIs. It is\n   a fixed number determined by the format so can easily be allocated on the\n   stack if necessary.\n\nCorresponding information about the pixels\n\n  PNG_IMAGE_PIXEL_CHANNELS(fmt)\n   The number of separate channels (components) in a pixel; 1 for a\n   color-mapped image.\n\n  PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\\\n   The size, in bytes, of each component in a pixel; 1 for a color-mapped\n   image.\n\n  PNG_IMAGE_PIXEL_SIZE(fmt)\n   The size, in bytes, of a complete pixel; 1 for a color-mapped image.\n\nInformation about the whole row, or whole image\n\n  PNG_IMAGE_ROW_STRIDE(image)\n   Returns the total number of components in a single row of the image; this\n   is the minimum 'row stride', the minimum count of components between each\n   row.  For a color-mapped image this is the minimum number of bytes in a\n   row.\n\n   If you need the stride measured in bytes, row_stride_bytes is\n   PNG_IMAGE_ROW_STRIDE(image) * PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\n   plus any padding bytes that your application might need, for example\n   to start the next row on a 4-byte boundary.\n\n  PNG_IMAGE_BUFFER_SIZE(image, row_stride)\n   Return the size, in bytes, of an image buffer given a png_image and a row\n   stride - the number of components to leave space for in each row.\n\n  PNG_IMAGE_SIZE(image)\n   Return the size, in bytes, of the image in memory given just a png_image;\n   the row stride is the minimum stride required for the image.\n\n  PNG_IMAGE_COLORMAP_SIZE(image)\n   Return the size, in bytes, of the color-map of this image.  If the image\n   format is not a color-map format this will return a size sufficient for\n   256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if\n   you don't want to allocate a color-map in this case.\n\nPNG_IMAGE_FLAG_*\n\nFlags containing additional information about the image are held in\nthe 'flags' field of png_image.\n\n  PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB == 0x01\n    This indicates the the RGB values of the in-memory bitmap do not\n    correspond to the red, green and blue end-points defined by sRGB.\n\n  PNG_IMAGE_FLAG_FAST == 0x02\n   On write emphasise speed over compression; the resultant PNG file will be\n   larger but will be produced significantly faster, particular for large\n   images.  Do not use this option for images which will be distributed, only\n   used it when producing intermediate files that will be read back in\n   repeatedly.  For a typical 24-bit image the option will double the read\n   speed at the cost of increasing the image size by 25%, however for many\n   more compressible images the PNG file can be 10 times larger with only a\n   slight speed gain.\n\n  PNG_IMAGE_FLAG_16BIT_sRGB == 0x04\n    On read if the image is a 16-bit per component image and there is no gAMA\n    or sRGB chunk assume that the components are sRGB encoded.  Notice that\n    images output by the simplified API always have gamma information; setting\n    this flag only affects the interpretation of 16-bit images from an\n    external source.  It is recommended that the application expose this flag\n    to the user; the user can normally easily recognize the difference between\n    linear and sRGB encoding.  This flag has no effect on write - the data\n    passed to the write APIs must have the correct encoding (as defined\n    above.)\n\n    If the flag is not set (the default) input 16-bit per component data is\n    assumed to be linear.\n\n    NOTE: the flag can only be set after the png_image_begin_read_ call,\n    because that call initializes the 'flags' field.\n\nREAD APIs\n\n   The png_image passed to the read APIs must have been initialized by setting\n   the png_controlp field 'opaque' to NULL (or, better, memset the whole thing.)\n\n   int png_image_begin_read_from_file( png_imagep image,\n     const char *file_name)\n\n     The named file is opened for read and the image header\n     is filled in from the PNG header in the file.\n\n   int png_image_begin_read_from_stdio (png_imagep image,\n     FILE* file)\n\n      The PNG header is read from the stdio FILE object.\n\n   int png_image_begin_read_from_memory(png_imagep image,\n      png_const_voidp memory, png_size_t size)\n\n      The PNG header is read from the given memory buffer.\n\n   int png_image_finish_read(png_imagep image,\n      png_colorp background, void *buffer,\n      png_int_32 row_stride, void *colormap));\n\n      Finish reading the image into the supplied buffer and\n      clean up the png_image structure.\n\n      row_stride is the step, in png_byte or png_uint_16 units\n      as appropriate, between adjacent rows.  A positive stride\n      indicates that the top-most row is first in the buffer -\n      the normal top-down arrangement.  A negative stride\n      indicates that the bottom-most row is first in the buffer.\n\n      background need only be supplied if an alpha channel must\n      be removed from a png_byte format and the removal is to be\n      done by compositing on a solid color; otherwise it may be\n      NULL and any composition will be done directly onto the\n      buffer.  The value is an sRGB color to use for the\n      background, for grayscale output the green channel is used.\n\n      For linear output removing the alpha channel is always done\n      by compositing on black.\n\n   void png_image_free(png_imagep image)\n\n      Free any data allocated by libpng in image->opaque,\n      setting the pointer to NULL.  May be called at any time\n      after the structure is initialized.\n\nWhen the simplified API needs to convert between sRGB and linear colorspaces,\nthe actual sRGB transfer curve defined in the sRGB specification (see the\narticle at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2\napproximation used elsewhere in libpng.\n\nWRITE APIS\n\nFor write you must initialize a png_image structure to describe the image to\nbe written:\n\n   version: must be set to PNG_IMAGE_VERSION\n   opaque: must be initialized to NULL\n   width: image width in pixels\n   height: image height in rows\n   format: the format of the data you wish to write\n   flags: set to 0 unless one of the defined flags applies; set\n      PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images\n      where the RGB values do not correspond to the colors in sRGB.\n   colormap_entries: set to the number of entries in the color-map (0 to 256)\n\n   int png_image_write_to_file, (png_imagep image,\n      const char *file, int convert_to_8bit, const void *buffer,\n      png_int_32 row_stride, const void *colormap));\n\n      Write the image to the named file.\n\n   int png_image_write_to_memory (png_imagep image, void *memory,\n      png_alloc_size_t * PNG_RESTRICT memory_bytes,\n      int convert_to_8_bit, const void *buffer, ptrdiff_t row_stride,\n      const void *colormap));\n\n      Write the image to memory.\n\n   int png_image_write_to_stdio(png_imagep image, FILE *file,\n      int convert_to_8_bit, const void *buffer,\n      png_int_32 row_stride, const void *colormap)\n\n      Write the image to the given (FILE*).\n\nWith all write APIs if image is in one of the linear formats with\n(png_uint_16) data then setting convert_to_8_bit will cause the output to be\na (png_byte) PNG gamma encoded according to the sRGB specification, otherwise\na 16-bit linear encoded PNG file is written.\n\nWith all APIs row_stride is handled as in the read APIs - it is the spacing\nfrom one row to the next in component sized units (float) and if negative\nindicates a bottom-up row layout in the buffer.  If you pass zero, libpng will\ncalculate the row_stride for you from the width and number of channels.\n\nNote that the write API does not support interlacing, sub-8-bit pixels,\nindexed (paletted) images, or most ancillary chunks.\n\n.SH VI. Modifying/Customizing libpng\n\nThere are two issues here.  The first is changing how libpng does\nstandard things like memory allocation, input/output, and error handling.\nThe second deals with more complicated things like adding new chunks,\nadding new transformations, and generally changing how libpng works.\nBoth of those are compile-time issues; that is, they are generally\ndetermined at the time the code is written, and there is rarely a need\nto provide the user with a means of changing them.\n\nMemory allocation, input/output, and error handling\n\nAll of the memory allocation, input/output, and error handling in libpng\ngoes through callbacks that are user-settable.  The default routines are\nin pngmem.c, pngrio.c, pngwio.c, and pngerror.c, respectively.  To change\nthese functions, call the appropriate png_set_*_fn() function.\n\nMemory allocation is done through the functions png_malloc(), png_calloc(),\nand png_free().  The png_malloc() and png_free() functions currently just\ncall the standard C functions and png_calloc() calls png_malloc() and then\nclears the newly allocated memory to zero; note that png_calloc(png_ptr, size)\nis not the same as the calloc(number, size) function provided by stdlib.h.\nThere is limited support for certain systems with segmented memory\narchitectures and the types of pointers declared by png.h match this; you\nwill have to use appropriate pointers in your application.  If you prefer\nto use a different method of allocating and freeing data, you can use\npng_create_read_struct_2() or png_create_write_struct_2() to register your\nown functions as described above.  These functions also provide a void\npointer that can be retrieved via\n\n    mem_ptr=png_get_mem_ptr(png_ptr);\n\nYour replacement memory functions must have prototypes as follows:\n\n    png_voidp malloc_fn(png_structp png_ptr,\n       png_alloc_size_t size);\n\n    void free_fn(png_structp png_ptr, png_voidp ptr);\n\nYour malloc_fn() must return NULL in case of failure.  The png_malloc()\nfunction will normally call png_error() if it receives a NULL from the\nsystem memory allocator or from your replacement malloc_fn().\n\nYour free_fn() will never be called with a NULL ptr, since libpng's\npng_free() checks for NULL before calling free_fn().\n\nInput/Output in libpng is done through png_read() and png_write(),\nwhich currently just call fread() and fwrite().  The FILE * is stored in\npng_struct and is initialized via png_init_io().  If you wish to change\nthe method of I/O, the library supplies callbacks that you can set\nthrough the function png_set_read_fn() and png_set_write_fn() at run\ntime, instead of calling the png_init_io() function.  These functions\nalso provide a void pointer that can be retrieved via the function\npng_get_io_ptr().  For example:\n\n    png_set_read_fn(png_structp read_ptr,\n        voidp read_io_ptr, png_rw_ptr read_data_fn)\n\n    png_set_write_fn(png_structp write_ptr,\n        voidp write_io_ptr, png_rw_ptr write_data_fn,\n        png_flush_ptr output_flush_fn);\n\n    voidp read_io_ptr = png_get_io_ptr(read_ptr);\n    voidp write_io_ptr = png_get_io_ptr(write_ptr);\n\nThe replacement I/O functions must have prototypes as follows:\n\n    void user_read_data(png_structp png_ptr,\n        png_bytep data, png_size_t length);\n\n    void user_write_data(png_structp png_ptr,\n        png_bytep data, png_size_t length);\n\n    void user_flush_data(png_structp png_ptr);\n\nThe user_read_data() function is responsible for detecting and\nhandling end-of-data errors.\n\nSupplying NULL for the read, write, or flush functions sets them back\nto using the default C stream functions, which expect the io_ptr to\npoint to a standard *FILE structure.  It is probably a mistake\nto use NULL for one of write_data_fn and output_flush_fn but not both\nof them, unless you have built libpng with PNG_NO_WRITE_FLUSH defined.\nIt is an error to read from a write stream, and vice versa.\n\nError handling in libpng is done through png_error() and png_warning().\nErrors handled through png_error() are fatal, meaning that png_error()\nshould never return to its caller.  Currently, this is handled via\nsetjmp() and longjmp() (unless you have compiled libpng with\nPNG_NO_SETJMP, in which case it is handled via PNG_ABORT()),\nbut you could change this to do things like exit() if you should wish,\nas long as your function does not return.\n\nOn non-fatal errors, png_warning() is called\nto print a warning message, and then control returns to the calling code.\nBy default png_error() and png_warning() print a message on stderr via\nfprintf() unless the library is compiled with PNG_NO_CONSOLE_IO defined\n(because you don't want the messages) or PNG_NO_STDIO defined (because\nfprintf() isn't available).  If you wish to change the behavior of the error\nfunctions, you will need to set up your own message callbacks.  These\nfunctions are normally supplied at the time that the png_struct is created.\nIt is also possible to redirect errors and warnings to your own replacement\nfunctions after png_create_*_struct() has been called by calling:\n\n    png_set_error_fn(png_structp png_ptr,\n        png_voidp error_ptr, png_error_ptr error_fn,\n        png_error_ptr warning_fn);\n\n    png_voidp error_ptr = png_get_error_ptr(png_ptr);\n\nIf NULL is supplied for either error_fn or warning_fn, then the libpng\ndefault function will be used, calling fprintf() and/or longjmp() if a\nproblem is encountered.  The replacement error functions should have\nparameters as follows:\n\n    void user_error_fn(png_structp png_ptr,\n        png_const_charp error_msg);\n\n    void user_warning_fn(png_structp png_ptr,\n        png_const_charp warning_msg);\n\nThe motivation behind using setjmp() and longjmp() is the C++ throw and\ncatch exception handling methods.  This makes the code much easier to write,\nas there is no need to check every return code of every function call.\nHowever, there are some uncertainties about the status of local variables\nafter a longjmp, so the user may want to be careful about doing anything\nafter setjmp returns non-zero besides returning itself.  Consult your\ncompiler documentation for more details.  For an alternative approach, you\nmay wish to use the \"cexcept\" facility (see http://cexcept.sourceforge.net),\nwhich is illustrated in pngvalid.c and in contrib/visupng.\n\nBeginning in libpng-1.4.0, the png_set_benign_errors() API became available.\nYou can use this to handle certain errors (normally handled as errors)\nas warnings.\n\n    png_set_benign_errors (png_ptr, int allowed);\n\n    allowed: 0: treat png_benign_error() as an error.\n             1: treat png_benign_error() as a warning.\n\nAs of libpng-1.6.0, the default condition is to treat benign errors as\nwarnings while reading and as errors while writing.\n\n.SS Custom chunks\n\nIf you need to read or write custom chunks, you may need to get deeper\ninto the libpng code.  The library now has mechanisms for storing\nand writing chunks of unknown type; you can even declare callbacks\nfor custom chunks.  However, this may not be good enough if the\nlibrary code itself needs to know about interactions between your\nchunk and existing `intrinsic' chunks.\n\nIf you need to write a new intrinsic chunk, first read the PNG\nspecification. Acquire a first level of understanding of how it works.\nPay particular attention to the sections that describe chunk names,\nand look at how other chunks were designed, so you can do things\nsimilarly.  Second, check out the sections of libpng that read and\nwrite chunks.  Try to find a chunk that is similar to yours and use\nit as a template.  More details can be found in the comments inside\nthe code.  It is best to handle private or unknown chunks in a generic method,\nvia callback functions, instead of by modifying libpng functions. This\nis illustrated in pngtest.c, which uses a callback function to handle a\nprivate \"vpAg\" chunk and the new \"sTER\" chunk, which are both unknown to\nlibpng.\n\nIf you wish to write your own transformation for the data, look through\nthe part of the code that does the transformations, and check out some of\nthe simpler ones to get an idea of how they work.  Try to find a similar\ntransformation to the one you want to add and copy off of it.  More details\ncan be found in the comments inside the code itself.\n\n.SS Configuring for gui/windowing platforms:\n\nYou will need to write new error and warning functions that use the GUI\ninterface, as described previously, and set them to be the error and\nwarning functions at the time that png_create_*_struct() is called,\nin order to have them available during the structure initialization.\nThey can be changed later via png_set_error_fn().  On some compilers,\nyou may also have to change the memory allocators (png_malloc, etc.).\n\n.SS Configuring zlib:\n\nThere are special functions to configure the compression.  Perhaps the\nmost useful one changes the compression level, which currently uses\ninput compression values in the range 0 - 9.  The library normally\nuses the default compression level (Z_DEFAULT_COMPRESSION = 6).  Tests\nhave shown that for a large majority of images, compression values in\nthe range 3-6 compress nearly as well as higher levels, and do so much\nfaster.  For online applications it may be desirable to have maximum speed\n(Z_BEST_SPEED = 1).  With versions of zlib after v0.99, you can also\nspecify no compression (Z_NO_COMPRESSION = 0), but this would create\nfiles larger than just storing the raw bitmap.  You can specify the\ncompression level by calling:\n\n    #include zlib.h\n    png_set_compression_level(png_ptr, level);\n\nAnother useful one is to reduce the memory level used by the library.\nThe memory level defaults to 8, but it can be lowered if you are\nshort on memory (running DOS, for example, where you only have 640K).\nNote that the memory level does have an effect on compression; among\nother things, lower levels will result in sections of incompressible\ndata being emitted in smaller stored blocks, with a correspondingly\nlarger relative overhead of up to 15% in the worst case.\n\n    #include zlib.h\n    png_set_compression_mem_level(png_ptr, level);\n\nThe other functions are for configuring zlib.  They are not recommended\nfor normal use and may result in writing an invalid PNG file.  See\nzlib.h for more information on what these mean.\n\n    #include zlib.h\n    png_set_compression_strategy(png_ptr,\n        strategy);\n\n    png_set_compression_window_bits(png_ptr,\n        window_bits);\n\n    png_set_compression_method(png_ptr, method);\n\nThis controls the size of the IDAT chunks (default 8192):\n\n    png_set_compression_buffer_size(png_ptr, size);\n\nAs of libpng version 1.5.4, additional APIs became\navailable to set these separately for non-IDAT\ncompressed chunks such as zTXt, iTXt, and iCCP:\n\n    #include zlib.h\n    #if PNG_LIBPNG_VER >= 10504\n    png_set_text_compression_level(png_ptr, level);\n\n    png_set_text_compression_mem_level(png_ptr, level);\n\n    png_set_text_compression_strategy(png_ptr,\n        strategy);\n\n    png_set_text_compression_window_bits(png_ptr,\n        window_bits);\n\n    png_set_text_compression_method(png_ptr, method);\n    #endif\n\n.SS Controlling row filtering\n\nIf you want to control whether libpng uses filtering or not, which\nfilters are used, and how it goes about picking row filters, you\ncan call one of these functions.  The selection and configuration\nof row filters can have a significant impact on the size and\nencoding speed and a somewhat lesser impact on the decoding speed\nof an image.  Filtering is enabled by default for RGB and grayscale\nimages (with and without alpha), but not for paletted images nor\nfor any images with bit depths less than 8 bits/pixel.\n\nThe 'method' parameter sets the main filtering method, which is\ncurrently only '0' in the PNG 1.2 specification.  The 'filters'\nparameter sets which filter(s), if any, should be used for each\nscanline.  Possible values are PNG_ALL_FILTERS, PNG_NO_FILTERS,\nor PNG_FAST_FILTERS to turn filtering on and off, or to turn on\njust the fast-decoding subset of filters, respectively.\n\nIndividual filter types are PNG_FILTER_NONE, PNG_FILTER_SUB,\nPNG_FILTER_UP, PNG_FILTER_AVG, PNG_FILTER_PAETH, which can be bitwise\nORed together with '|' to specify one or more filters to use.\nThese filters are described in more detail in the PNG specification.\nIf you intend to change the filter type during the course of writing\nthe image, you should start with flags set for all of the filters\nyou intend to use so that libpng can initialize its internal\nstructures appropriately for all of the filter types.  (Note that this\nmeans the first row must always be adaptively filtered, because libpng\ncurrently does not allocate the filter buffers until png_write_row()\nis called for the first time.)\n\n    filters = PNG_NO_FILTERS;\n    filters = PNG_ALL_FILTERS;\n    filters = PNG_FAST_FILTERS;\n\n    or\n\n    filters = PNG_FILTER_NONE | PNG_FILTER_SUB |\n              PNG_FILTER_UP | PNG_FILTER_AVG |\n              PNG_FILTER_PAETH;\n\n    png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE,\n       filters);\n\n              The second parameter can also be\n              PNG_INTRAPIXEL_DIFFERENCING if you are\n              writing a PNG to be embedded in a MNG\n              datastream.  This parameter must be the\n              same as the value of filter_method used\n              in png_set_IHDR().\n\n.SS Requesting debug printout\n\nThe macro definition PNG_DEBUG can be used to request debugging\nprintout.  Set it to an integer value in the range 0 to 3.  Higher\nnumbers result in increasing amounts of debugging information.  The\ninformation is printed to the \"stderr\" file, unless another file\nname is specified in the PNG_DEBUG_FILE macro definition.\n\nWhen PNG_DEBUG > 0, the following functions (macros) become available:\n\n   png_debug(level, message)\n   png_debug1(level, message, p1)\n   png_debug2(level, message, p1, p2)\n\nin which \"level\" is compared to PNG_DEBUG to decide whether to print\nthe message, \"message\" is the formatted string to be printed,\nand p1 and p2 are parameters that are to be embedded in the string\naccording to printf-style formatting directives.  For example,\n\n   png_debug1(2, \"foo=%d\", foo);\n\nis expanded to\n\n   if (PNG_DEBUG > 2)\n      fprintf(PNG_DEBUG_FILE, \"foo=%d\\en\", foo);\n\nWhen PNG_DEBUG is defined but is zero, the macros aren't defined, but you\ncan still use PNG_DEBUG to control your own debugging:\n\n   #ifdef PNG_DEBUG\n       fprintf(stderr, ...\n   #endif\n\nWhen PNG_DEBUG = 1, the macros are defined, but only png_debug statements\nhaving level = 0 will be printed.  There aren't any such statements in\nthis version of libpng, but if you insert some they will be printed.\n\n.SH VII.  MNG support\n\nThe MNG specification (available at http://www.libpng.org/pub/mng) allows\ncertain extensions to PNG for PNG images that are embedded in MNG datastreams.\nLibpng can support some of these extensions.  To enable them, use the\npng_permit_mng_features() function:\n\n   feature_set = png_permit_mng_features(png_ptr, mask)\n\n   mask is a png_uint_32 containing the bitwise OR of the\n        features you want to enable.  These include\n        PNG_FLAG_MNG_EMPTY_PLTE\n        PNG_FLAG_MNG_FILTER_64\n        PNG_ALL_MNG_FEATURES\n\n   feature_set is a png_uint_32 that is the bitwise AND of\n      your mask with the set of MNG features that is\n      supported by the version of libpng that you are using.\n\nIt is an error to use this function when reading or writing a standalone\nPNG file with the PNG 8-byte signature.  The PNG datastream must be wrapped\nin a MNG datastream.  As a minimum, it must have the MNG 8-byte signature\nand the MHDR and MEND chunks.  Libpng does not provide support for these\nor any other MNG chunks; your application must provide its own support for\nthem.  You may wish to consider using libmng (available at\nhttp://www.libmng.com) instead.\n\n.SH VIII.  Changes to Libpng from version 0.88\n\nIt should be noted that versions of libpng later than 0.96 are not\ndistributed by the original libpng author, Guy Schalnat, nor by\nAndreas Dilger, who had taken over from Guy during 1996 and 1997, and\ndistributed versions 0.89 through 0.96, but rather by another member\nof the original PNG Group, Glenn Randers-Pehrson.  Guy and Andreas are\nstill alive and well, but they have moved on to other things.\n\nThe old libpng functions png_read_init(), png_write_init(),\npng_info_init(), png_read_destroy(), and png_write_destroy() have been\nmoved to PNG_INTERNAL in version 0.95 to discourage their use.  These\nfunctions will be removed from libpng version 1.4.0.\n\nThe preferred method of creating and initializing the libpng structures is\nvia the png_create_read_struct(), png_create_write_struct(), and\npng_create_info_struct() because they isolate the size of the structures\nfrom the application, allow version error checking, and also allow the\nuse of custom error handling routines during the initialization, which\nthe old functions do not.  The functions png_read_destroy() and\npng_write_destroy() do not actually free the memory that libpng\nallocated for these structs, but just reset the data structures, so they\ncan be used instead of png_destroy_read_struct() and\npng_destroy_write_struct() if you feel there is too much system overhead\nallocating and freeing the png_struct for each image read.\n\nSetting the error callbacks via png_set_message_fn() before\npng_read_init() as was suggested in libpng-0.88 is no longer supported\nbecause this caused applications that do not use custom error functions\nto fail if the png_ptr was not initialized to zero.  It is still possible\nto set the error callbacks AFTER png_read_init(), or to change them with\npng_set_error_fn(), which is essentially the same function, but with a new\nname to force compilation errors with applications that try to use the old\nmethod.\n\nSupport for the sCAL, iCCP, iTXt, and sPLT chunks was added at libpng-1.0.6;\nhowever, iTXt support was not enabled by default.\n\nStarting with version 1.0.7, you can find out which version of the library\nyou are using at run-time:\n\n   png_uint_32 libpng_vn = png_access_version_number();\n\nThe number libpng_vn is constructed from the major version, minor\nversion with leading zero, and release number with leading zero,\n(e.g., libpng_vn for version 1.0.7 is 10007).\n\nNote that this function does not take a png_ptr, so you can call it\nbefore you've created one.\n\nYou can also check which version of png.h you used when compiling your\napplication:\n\n   png_uint_32 application_vn = PNG_LIBPNG_VER;\n\n.SH IX.  Changes to Libpng from version 1.0.x to 1.2.x\n\nSupport for user memory management was enabled by default.  To\naccomplish this, the functions png_create_read_struct_2(),\npng_create_write_struct_2(), png_set_mem_fn(), png_get_mem_ptr(),\npng_malloc_default(), and png_free_default() were added.\n\nSupport for the iTXt chunk has been enabled by default as of\nversion 1.2.41.\n\nSupport for certain MNG features was enabled.\n\nSupport for numbered error messages was added.  However, we never got\naround to actually numbering the error messages.  The function\npng_set_strip_error_numbers() was added (Note: the prototype for this\nfunction was inadvertently removed from png.h in PNG_NO_ASSEMBLER_CODE\nbuilds of libpng-1.2.15.  It was restored in libpng-1.2.36).\n\nThe png_malloc_warn() function was added at libpng-1.2.3.  This issues\na png_warning and returns NULL instead of aborting when it fails to\nacquire the requested memory allocation.\n\nSupport for setting user limits on image width and height was enabled\nby default.  The functions png_set_user_limits(), png_get_user_width_max(),\nand png_get_user_height_max() were added at libpng-1.2.6.\n\nThe png_set_add_alpha() function was added at libpng-1.2.7.\n\nThe function png_set_expand_gray_1_2_4_to_8() was added at libpng-1.2.9.\nUnlike png_set_gray_1_2_4_to_8(), the new function does not expand the\ntRNS chunk to alpha. The png_set_gray_1_2_4_to_8() function is\ndeprecated.\n\nA number of macro definitions in support of runtime selection of\nassembler code features (especially Intel MMX code support) were\nadded at libpng-1.2.0:\n\n    PNG_ASM_FLAG_MMX_SUPPORT_COMPILED\n    PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU\n    PNG_ASM_FLAG_MMX_READ_COMBINE_ROW\n    PNG_ASM_FLAG_MMX_READ_INTERLACE\n    PNG_ASM_FLAG_MMX_READ_FILTER_SUB\n    PNG_ASM_FLAG_MMX_READ_FILTER_UP\n    PNG_ASM_FLAG_MMX_READ_FILTER_AVG\n    PNG_ASM_FLAG_MMX_READ_FILTER_PAETH\n    PNG_ASM_FLAGS_INITIALIZED\n    PNG_MMX_READ_FLAGS\n    PNG_MMX_FLAGS\n    PNG_MMX_WRITE_FLAGS\n    PNG_MMX_FLAGS\n\nWe added the following functions in support of runtime\nselection of assembler code features:\n\n    png_get_mmx_flagmask()\n    png_set_mmx_thresholds()\n    png_get_asm_flags()\n    png_get_mmx_bitdepth_threshold()\n    png_get_mmx_rowbytes_threshold()\n    png_set_asm_flags()\n\nWe replaced all of these functions with simple stubs in libpng-1.2.20,\nwhen the Intel assembler code was removed due to a licensing issue.\n\nThese macros are deprecated:\n\n    PNG_READ_TRANSFORMS_NOT_SUPPORTED\n    PNG_PROGRESSIVE_READ_NOT_SUPPORTED\n    PNG_NO_SEQUENTIAL_READ_SUPPORTED\n    PNG_WRITE_TRANSFORMS_NOT_SUPPORTED\n    PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED\n    PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED\n\nThey have been replaced, respectively, by:\n\n    PNG_NO_READ_TRANSFORMS\n    PNG_NO_PROGRESSIVE_READ\n    PNG_NO_SEQUENTIAL_READ\n    PNG_NO_WRITE_TRANSFORMS\n    PNG_NO_READ_ANCILLARY_CHUNKS\n    PNG_NO_WRITE_ANCILLARY_CHUNKS\n\nPNG_MAX_UINT was replaced with PNG_UINT_31_MAX.  It has been\ndeprecated since libpng-1.0.16 and libpng-1.2.6.\n\nThe function\n    png_check_sig(sig, num)\nwas replaced with\n    !png_sig_cmp(sig, 0, num)\nIt has been deprecated since libpng-0.90.\n\nThe function\n    png_set_gray_1_2_4_to_8()\nwhich also expands tRNS to alpha was replaced with\n    png_set_expand_gray_1_2_4_to_8()\nwhich does not. It has been deprecated since libpng-1.0.18 and 1.2.9.\n\n.SH X.  Changes to Libpng from version 1.0.x/1.2.x to 1.4.x\n\nPrivate libpng prototypes and macro definitions were moved from\npng.h and pngconf.h into a new pngpriv.h header file.\n\nFunctions png_set_benign_errors(), png_benign_error(), and\npng_chunk_benign_error() were added.\n\nSupport for setting the maximum amount of memory that the application\nwill allocate for reading chunks was added, as a security measure.\nThe functions png_set_chunk_cache_max() and png_get_chunk_cache_max()\nwere added to the library.\n\nWe implemented support for I/O states by adding png_ptr member io_state\nand functions png_get_io_chunk_name() and png_get_io_state() in pngget.c\n\nWe added PNG_TRANSFORM_GRAY_TO_RGB to the available high-level\ninput transforms.\n\nChecking for and reporting of errors in the IHDR chunk is more thorough.\n\nSupport for global arrays was removed, to improve thread safety.\n\nSome obsolete/deprecated macros and functions have been removed.\n\nTypecasted NULL definitions such as\n   #define png_voidp_NULL            (png_voidp)NULL\nwere eliminated.  If you used these in your application, just use\nNULL instead.\n\nThe png_struct and info_struct members \"trans\" and \"trans_values\" were\nchanged to \"trans_alpha\" and \"trans_color\", respectively.\n\nThe obsolete, unused pnggccrd.c and pngvcrd.c files and related makefiles\nwere removed.\n\nThe PNG_1_0_X and PNG_1_2_X macros were eliminated.\n\nThe PNG_LEGACY_SUPPORTED macro was eliminated.\n\nMany WIN32_WCE #ifdefs were removed.\n\nThe functions png_read_init(info_ptr), png_write_init(info_ptr),\npng_info_init(info_ptr), png_read_destroy(), and png_write_destroy()\nhave been removed.  They have been deprecated since libpng-0.95.\n\nThe png_permit_empty_plte() was removed. It has been deprecated\nsince libpng-1.0.9.  Use png_permit_mng_features() instead.\n\nWe removed the obsolete stub functions png_get_mmx_flagmask(),\npng_set_mmx_thresholds(), png_get_asm_flags(),\npng_get_mmx_bitdepth_threshold(), png_get_mmx_rowbytes_threshold(),\npng_set_asm_flags(), and png_mmx_supported()\n\nWe removed the obsolete png_check_sig(), png_memcpy_check(), and\npng_memset_check() functions.  Instead use !png_sig_cmp(), memcpy(),\nand memset(), respectively.\n\nThe function png_set_gray_1_2_4_to_8() was removed. It has been\ndeprecated since libpng-1.0.18 and 1.2.9, when it was replaced with\npng_set_expand_gray_1_2_4_to_8() because the former function also\nexpanded any tRNS chunk to an alpha channel.\n\nMacros for png_get_uint_16, png_get_uint_32, and png_get_int_32\nwere added and are used by default instead of the corresponding\nfunctions. Unfortunately,\nfrom libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the\nfunction) incorrectly returned a value of type png_uint_32.\n\nWe changed the prototype for png_malloc() from\n    png_malloc(png_structp png_ptr, png_uint_32 size)\nto\n    png_malloc(png_structp png_ptr, png_alloc_size_t size)\n\nThis also applies to the prototype for the user replacement malloc_fn().\n\nThe png_calloc() function was added and is used in place of\nof \"png_malloc(); memset();\" except in the case in png_read_png()\nwhere the array consists of pointers; in this case a \"for\" loop is used\nafter the png_malloc() to set the pointers to NULL, to give robust.\nbehavior in case the application runs out of memory part-way through\nthe process.\n\nWe changed the prototypes of png_get_compression_buffer_size() and\npng_set_compression_buffer_size() to work with png_size_t instead of\npng_uint_32.\n\nSupport for numbered error messages was removed by default, since we\nnever got around to actually numbering the error messages. The function\npng_set_strip_error_numbers() was removed from the library by default.\n\nThe png_zalloc() and png_zfree() functions are no longer exported.\nThe png_zalloc() function no longer zeroes out the memory that it\nallocates.  Applications that called png_zalloc(png_ptr, number, size)\ncan call png_calloc(png_ptr, number*size) instead, and can call\npng_free() instead of png_zfree().\n\nSupport for dithering was disabled by default in libpng-1.4.0, because\nit has not been well tested and doesn't actually \"dither\".\nThe code was not\nremoved, however, and could be enabled by building libpng with\nPNG_READ_DITHER_SUPPORTED defined.  In libpng-1.4.2, this support\nwas re-enabled, but the function was renamed png_set_quantize() to\nreflect more accurately what it actually does.  At the same time,\nthe PNG_DITHER_[RED,GREEN_BLUE]_BITS macros were also renamed to\nPNG_QUANTIZE_[RED,GREEN,BLUE]_BITS, and PNG_READ_DITHER_SUPPORTED\nwas renamed to PNG_READ_QUANTIZE_SUPPORTED.\n\nWe removed the trailing '.' from the warning and error messages.\n\n.SH XI.  Changes to Libpng from version 1.4.x to 1.5.x\n\nFrom libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the\nfunction) incorrectly returned a value of type png_uint_32.\nThe incorrect macro was removed from libpng-1.4.5.\n\nChecking for invalid palette index on write was added at libpng\n1.5.10.  If a pixel contains an invalid (out-of-range) index libpng issues\na benign error.  This is enabled by default because this condition is an\nerror according to the PNG specification, Clause 11.3.2, but the error can\nbe ignored in each png_ptr with\n\n   png_set_check_for_invalid_index(png_ptr, allowed);\n\n      allowed  - one of\n                 0: disable benign error (accept the\n                    invalid data without warning).\n                 1: enable benign error (treat the\n                    invalid data as an error or a\n                    warning).\n\nIf the error is ignored, or if png_benign_error() treats it as a warning,\nany invalid pixels are decoded as opaque black by the decoder and written\nas-is by the encoder.\n\nRetrieving the maximum palette index found was added at libpng-1.5.15.\nThis statement must appear after png_read_png() or png_read_image() while\nreading, and after png_write_png() or png_write_image() while writing.\n\n   int max_palette = png_get_palette_max(png_ptr, info_ptr);\n\nThis will return the maximum palette index found in the image, or \"\\-1\" if\nthe palette was not checked, or \"0\" if no palette was found.  Note that this\ndoes not account for any palette index used by ancillary chunks such as the\nbKGD chunk; you must check those separately to determine the maximum\npalette index actually used.\n\nThere are no substantial API changes between the non-deprecated parts of\nthe 1.4.5 API and the 1.5.0 API; however, the ability to directly access\nmembers of the main libpng control structures, png_struct and png_info,\ndeprecated in earlier versions of libpng, has been completely removed from\nlibpng 1.5, and new private \"pngstruct.h\", \"pnginfo.h\", and \"pngdebug.h\"\nheader files were created.\n\nWe no longer include zlib.h in png.h.  The include statement has been moved\nto pngstruct.h, where it is not accessible by applications. Applications that\nneed access to information in zlib.h will need to add the '#include \"zlib.h\"'\ndirective.  It does not matter whether this is placed prior to or after\nthe '\"#include png.h\"' directive.\n\nThe png_sprintf(), png_strcpy(), and png_strncpy() macros are no longer used\nand were removed.\n\nWe moved the png_strlen(), png_memcpy(), png_memset(), and png_memcmp()\nmacros into a private header file (pngpriv.h) that is not accessible to\napplications.\n\nIn png_get_iCCP, the type of \"profile\" was changed from png_charpp\nto png_bytepp, and in png_set_iCCP, from png_charp to png_const_bytep.\n\nThere are changes of form in png.h, including new and changed macros to\ndeclare parts of the API.  Some API functions with arguments that are\npointers to data not modified within the function have been corrected to\ndeclare these arguments with PNG_CONST.\n\nMuch of the internal use of C macros to control the library build has also\nchanged and some of this is visible in the exported header files, in\nparticular the use of macros to control data and API elements visible\nduring application compilation may require significant revision to\napplication code.  (It is extremely rare for an application to do this.)\n\nAny program that compiled against libpng 1.4 and did not use deprecated\nfeatures or access internal library structures should compile and work\nagainst libpng 1.5, except for the change in the prototype for\npng_get_iCCP() and png_set_iCCP() API functions mentioned above.\n\nlibpng 1.5.0 adds PNG_ PASS macros to help in the reading and writing of\ninterlaced images.  The macros return the number of rows and columns in\neach pass and information that can be used to de-interlace and (if\nabsolutely necessary) interlace an image.\n\nlibpng 1.5.0 adds an API png_longjmp(png_ptr, value).  This API calls\nthe application-provided png_longjmp_ptr on the internal, but application\ninitialized, longjmp buffer.  It is provided as a convenience to avoid\nthe need to use the png_jmpbuf macro, which had the unnecessary side\neffect of resetting the internal png_longjmp_ptr value.\n\nlibpng 1.5.0 includes a complete fixed point API.  By default this is\npresent along with the corresponding floating point API.  In general the\nfixed point API is faster and smaller than the floating point one because\nthe PNG file format used fixed point, not floating point.  This applies\neven if the library uses floating point in internal calculations.  A new\nmacro, PNG_FLOATING_ARITHMETIC_SUPPORTED, reveals whether the library\nuses floating point arithmetic (the default) or fixed point arithmetic\ninternally for performance critical calculations such as gamma correction.\nIn some cases, the gamma calculations may produce slightly different\nresults.  This has changed the results in png_rgb_to_gray and in alpha\ncomposition (png_set_background for example). This applies even if the\noriginal image was already linear (gamma == 1.0) and, therefore, it is\nnot necessary to linearize the image.  This is because libpng has *not*\nbeen changed to optimize that case correctly, yet.\n\nFixed point support for the sCAL chunk comes with an important caveat;\nthe sCAL specification uses a decimal encoding of floating point values\nand the accuracy of PNG fixed point values is insufficient for\nrepresentation of these values. Consequently a \"string\" API\n(png_get_sCAL_s and png_set_sCAL_s) is the only reliable way of reading\narbitrary sCAL chunks in the absence of either the floating point API or\ninternal floating point calculations.  Starting with libpng-1.5.0, both\nof these functions are present when PNG_sCAL_SUPPORTED is defined.  Prior\nto libpng-1.5.0, their presence also depended upon PNG_FIXED_POINT_SUPPORTED\nbeing defined and PNG_FLOATING_POINT_SUPPORTED not being defined.\n\nApplications no longer need to include the optional distribution header\nfile pngusr.h or define the corresponding macros during application\nbuild in order to see the correct variant of the libpng API.  From 1.5.0\napplication code can check for the corresponding _SUPPORTED macro:\n\n#ifdef PNG_INCH_CONVERSIONS_SUPPORTED\n   /* code that uses the inch conversion APIs. */\n#endif\n\nThis macro will only be defined if the inch conversion functions have been\ncompiled into libpng.  The full set of macros, and whether or not support\nhas been compiled in, are available in the header file pnglibconf.h.\nThis header file is specific to the libpng build.  Notice that prior to\n1.5.0 the _SUPPORTED macros would always have the default definition unless\nreset by pngusr.h or by explicit settings on the compiler command line.\nThese settings may produce compiler warnings or errors in 1.5.0 because\nof macro redefinition.\n\nApplications can now choose whether to use these macros or to call the\ncorresponding function by defining PNG_USE_READ_MACROS or\nPNG_NO_USE_READ_MACROS before including png.h.  Notice that this is\nonly supported from 1.5.0; defining PNG_NO_USE_READ_MACROS prior to 1.5.0\nwill lead to a link failure.\n\nPrior to libpng-1.5.4, the zlib compressor used the same set of parameters\nwhen compressing the IDAT data and textual data such as zTXt and iCCP.\nIn libpng-1.5.4 we reinitialized the zlib stream for each type of data.\nWe added five png_set_text_*() functions for setting the parameters to\nuse with textual data.\n\nPrior to libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\noption was off by default, and slightly inaccurate scaling occurred.\nThis option can no longer be turned off, and the choice of accurate\nor inaccurate 16-to-8 scaling is by using the new png_set_scale_16_to_8()\nAPI for accurate scaling or the old png_set_strip_16_to_8() API for simple\nchopping.  In libpng-1.5.4, the PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\nmacro became PNG_READ_SCALE_16_TO_8_SUPPORTED, and the PNG_READ_16_TO_8\nmacro became PNG_READ_STRIP_16_TO_8_SUPPORTED, to enable the two\npng_set_*_16_to_8() functions separately.\n\nPrior to libpng-1.5.4, the png_set_user_limits() function could only be\nused to reduce the width and height limits from the value of\nPNG_USER_WIDTH_MAX and PNG_USER_HEIGHT_MAX, although this document said\nthat it could be used to override them.  Now this function will reduce or\nincrease the limits.\n\nStarting in libpng-1.5.10, the user limits can be set en masse with the\nconfiguration option PNG_SAFE_LIMITS_SUPPORTED.  If this option is enabled,\na set of \"safe\" limits is applied in pngpriv.h.  These can be overridden by\napplication calls to png_set_user_limits(), png_set_user_chunk_cache_max(),\nand/or png_set_user_malloc_max() that increase or decrease the limits.  Also,\nin libpng-1.5.10 the default width and height limits were increased\nfrom 1,000,000 to 0x7fffffff (i.e., made unlimited).  Therefore, the\nlimits are now\n                               default      safe\n   png_user_width_max        0x7fffffff    1,000,000\n   png_user_height_max       0x7fffffff    1,000,000\n   png_user_chunk_cache_max  0 (unlimited)   128\n   png_user_chunk_malloc_max 0 (unlimited) 8,000,000\n\nThe png_set_option() function (and the \"options\" member of the png struct) was\nadded to libpng-1.5.15, with option PNG_ARM_NEON.\n\nThe library now supports a complete fixed point implementation and can\nthus be used on systems that have no floating point support or very\nlimited or slow support.  Previously gamma correction, an essential part\nof complete PNG support, required reasonably fast floating point.\n\nAs part of this the choice of internal implementation has been made\nindependent of the choice of fixed versus floating point APIs and all the\nmissing fixed point APIs have been implemented.\n\nThe exact mechanism used to control attributes of API functions has\nchanged, as described in the INSTALL file.\n\nA new test program, pngvalid, is provided in addition to pngtest.\npngvalid validates the arithmetic accuracy of the gamma correction\ncalculations and includes a number of validations of the file format.\nA subset of the full range of tests is run when \"make check\" is done\n(in the 'configure' build.)  pngvalid also allows total allocated memory\nusage to be evaluated and performs additional memory overwrite validation.\n\nMany changes to individual feature macros have been made. The following\nare the changes most likely to be noticed by library builders who\nconfigure libpng:\n\n1) All feature macros now have consistent naming:\n\n#define PNG_NO_feature turns the feature off\n#define PNG_feature_SUPPORTED turns the feature on\n\npnglibconf.h contains one line for each feature macro which is either:\n\n#define PNG_feature_SUPPORTED\n\nif the feature is supported or:\n\n/*#undef PNG_feature_SUPPORTED*/\n\nif it is not.  Library code consistently checks for the 'SUPPORTED' macro.\nIt does not, and libpng applications should not, check for the 'NO' macro\nwhich will not normally be defined even if the feature is not supported.\nThe 'NO' macros are only used internally for setting or not setting the\ncorresponding 'SUPPORTED' macros.\n\nCompatibility with the old names is provided as follows:\n\nPNG_INCH_CONVERSIONS turns on PNG_INCH_CONVERSIONS_SUPPORTED\n\nAnd the following definitions disable the corresponding feature:\n\nPNG_SETJMP_NOT_SUPPORTED disables SETJMP\nPNG_READ_TRANSFORMS_NOT_SUPPORTED disables READ_TRANSFORMS\nPNG_NO_READ_COMPOSITED_NODIV disables READ_COMPOSITE_NODIV\nPNG_WRITE_TRANSFORMS_NOT_SUPPORTED disables WRITE_TRANSFORMS\nPNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED disables READ_ANCILLARY_CHUNKS\nPNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED disables WRITE_ANCILLARY_CHUNKS\n\nLibrary builders should remove use of the above, inconsistent, names.\n\n2) Warning and error message formatting was previously conditional on\nthe STDIO feature. The library has been changed to use the\nCONSOLE_IO feature instead. This means that if CONSOLE_IO is disabled\nthe library no longer uses the printf(3) functions, even though the\ndefault read/write implementations use (FILE) style stdio.h functions.\n\n3) Three feature macros now control the fixed/floating point decisions:\n\nPNG_FLOATING_POINT_SUPPORTED enables the floating point APIs\n\nPNG_FIXED_POINT_SUPPORTED enables the fixed point APIs; however, in\npractice these are normally required internally anyway (because the PNG\nfile format is fixed point), therefore in most cases PNG_NO_FIXED_POINT\nmerely stops the function from being exported.\n\nPNG_FLOATING_ARITHMETIC_SUPPORTED chooses between the internal floating\npoint implementation or the fixed point one.  Typically the fixed point\nimplementation is larger and slower than the floating point implementation\non a system that supports floating point; however, it may be faster on a\nsystem which lacks floating point hardware and therefore uses a software\nemulation.\n\n4) Added PNG_{READ,WRITE}_INT_FUNCTIONS_SUPPORTED.  This allows the\nfunctions to read and write ints to be disabled independently of\nPNG_USE_READ_MACROS, which allows libpng to be built with the functions\neven though the default is to use the macros - this allows applications\nto choose at app buildtime whether or not to use macros (previously\nimpossible because the functions weren't in the default build.)\n\n.SH XII.  Changes to Libpng from version 1.5.x to 1.6.x\n\nA \"simplified API\" has been added (see documentation in png.h and a simple\nexample in contrib/examples/pngtopng.c).  The new publicly visible API\nincludes the following:\n\n   macros:\n     PNG_FORMAT_*\n     PNG_IMAGE_*\n   structures:\n     png_control\n     png_image\n   read functions\n     png_image_begin_read_from_file()\n     png_image_begin_read_from_stdio()\n     png_image_begin_read_from_memory()\n     png_image_finish_read()\n     png_image_free()\n   write functions\n     png_image_write_to_file()\n     png_image_write_to_memory()\n     png_image_write_to_stdio()\n\nStarting with libpng-1.6.0, you can configure libpng to prefix all exported\nsymbols, using the PNG_PREFIX macro.\n\nWe no longer include string.h in png.h.  The include statement has been moved\nto pngpriv.h, where it is not accessible by applications.  Applications that\nneed access to information in string.h must add an '#include <string.h>'\ndirective.  It does not matter whether this is placed prior to or after\nthe '#include \"png.h\"' directive.\n\nThe following API are now DEPRECATED:\n   png_info_init_3()\n   png_convert_to_rfc1123() which has been replaced\n     with png_convert_to_rfc1123_buffer()\n   png_malloc_default()\n   png_free_default()\n   png_reset_zstream()\n\nThe following have been removed:\n   png_get_io_chunk_name(), which has been replaced\n     with png_get_io_chunk_type().  The new\n     function returns a 32-bit integer instead of\n     a string.\n   The png_sizeof(), png_strlen(), png_memcpy(), png_memcmp(), and\n     png_memset() macros are no longer used in the libpng sources and\n     have been removed.  These had already been made invisible to applications\n     (i.e., defined in the private pngpriv.h header file) since libpng-1.5.0.\n\nThe signatures of many exported functions were changed, such that\n   png_structp became png_structrp or png_const_structrp\n   png_infop became png_inforp or png_const_inforp\nwhere \"rp\" indicates a \"restricted pointer\".\n\nDropped support for 16-bit platforms. The support for FAR/far types has\nbeen eliminated and the definition of png_alloc_size_t is now controlled\nby a flag so that 'small size_t' systems can select it if necessary.\n\nError detection in some chunks has improved; in particular the iCCP chunk\nreader now does pretty complete validation of the basic format.  Some bad\nprofiles that were previously accepted are now accepted with a warning or\nrejected, depending upon the png_set_benign_errors() setting, in particular\nthe very old broken Microsoft/HP 3144-byte sRGB profile.  Starting with\nlibpng-1.6.11, recognizing and checking sRGB profiles can be avoided by\nmeans of\n\n    #if defined(PNG_SKIP_sRGB_CHECK_PROFILE) && \\\n        defined(PNG_SET_OPTION_SUPPORTED)\n       png_set_option(png_ptr, PNG_SKIP_sRGB_CHECK_PROFILE,\n           PNG_OPTION_ON);\n    #endif\n\nIt's not a good idea to do this if you are using the \"simplified API\",\nwhich needs to be able to recognize sRGB profiles conveyed via the iCCP\nchunk.\n\nThe PNG spec requirement that only grayscale profiles may appear in images\nwith color type 0 or 4 and that even if the image only contains gray pixels,\nonly RGB profiles may appear in images with color type 2, 3, or 6, is now\nenforced.  The sRGB chunk is allowed to appear in images with any color type\nand is interpreted by libpng to convey a one-tracer-curve gray profile or a\nthree-tracer-curve RGB profile as appropriate.\n\nLibpng 1.5.x erroneously used /MD for Debug DLL builds; if you used the debug\nbuilds in your app and you changed your app to use /MD you will need to\nchange it back to /MDd for libpng 1.6.x.\n\nPrior to libpng-1.6.0 a warning would be issued if the iTXt chunk contained\nan empty language field or an empty translated keyword.  Both of these\nare allowed by the PNG specification, so these warnings are no longer issued.\n\nThe library now issues an error if the application attempts to set a\ntransform after it calls png_read_update_info() or if it attempts to call\nboth png_read_update_info() and png_start_read_image() or to call either\nof them more than once.\n\nThe default condition for benign_errors is now to treat benign errors as\nwarnings while reading and as errors while writing.\n\nThe library now issues a warning if both background processing and RGB to\ngray are used when gamma correction happens. As with previous versions of\nthe library the results are numerically very incorrect in this case.\n\nThere are some minor arithmetic changes in some transforms such as\npng_set_background(), that might be detected by certain regression tests.\n\nUnknown chunk handling has been improved internally, without any API change.\nThis adds more correct option control of the unknown handling, corrects\na pre-existing bug where the per-chunk 'keep' setting is ignored, and makes\nit possible to skip IDAT chunks in the sequential reader.\n\nThe machine-generated configure files are no longer included in branches\nlibpng16 and later of the GIT repository.  They continue to be included\nin the tarball releases, however.\n\nLibpng-1.6.0 through 1.6.2 used the CMF bytes at the beginning of the IDAT\nstream to set the size of the sliding window for reading instead of using the\ndefault 32-kbyte sliding window size.  It was discovered that there are\nhundreds of PNG files in the wild that have incorrect CMF bytes that caused\nzlib to issue the \"invalid distance too far back\" error and reject the file.\nLibpng-1.6.3 and later calculate their own safe CMF from the image dimensions,\nprovide a way to revert to the libpng-1.5.x behavior (ignoring the CMF bytes\nand using a 32-kbyte sliding window), by using\n\n    png_set_option(png_ptr, PNG_MAXIMUM_INFLATE_WINDOW,\n        PNG_OPTION_ON);\n\nand provide a tool (contrib/tools/pngfix) for rewriting a PNG file while\noptimizing the CMF bytes in its IDAT chunk correctly.\n\nLibpng-1.6.0 and libpng-1.6.1 wrote uncompressed iTXt chunks with the wrong\nlength, which resulted in PNG files that cannot be read beyond the bad iTXt\nchunk.  This error was fixed in libpng-1.6.3, and a tool (called\ncontrib/tools/png-fix-itxt) has been added to the libpng distribution.\n\nStarting with libpng-1.6.17, the PNG_SAFE_LIMITS macro was eliminated\nand safe limits are used by default (users who need larger limits\ncan still override them at compile time or run time, as described above).\n\nThe new limits are\n                                default   spec limit\n   png_user_width_max         1,000,000  2,147,483,647\n   png_user_height_max        1,000,000  2,147,483,647\n   png_user_chunk_cache_max         128  unlimited\n   png_user_chunk_malloc_max  8,000,000  unlimited\n\nStarting with libpng-1.6.18, a PNG_RELEASE_BUILD macro was added, which allows\nlibrary builders to control compilation for an installed system (a release build).\nIt can be set for testing debug or beta builds to ensure that they will compile\nwhen the build type is switched to RC or STABLE. In essence this overrides the\nPNG_LIBPNG_BUILD_BASE_TYPE definition which is not directly user controllable.\n\nStarting with libpng-1.6.19, attempting to set an over-length PLTE chunk\nis an error. Previously this requirement of the PNG specification was not\nenforced, and the palette was always limited to 256 entries. An over-length\nPLTE chunk found in an input PNG is silently truncated.\n\n.SH XIII.  Detecting libpng\n\nThe png_get_io_ptr() function has been present since libpng-0.88, has never\nchanged, and is unaffected by conditional compilation macros.  It is the\nbest choice for use in configure scripts for detecting the presence of any\nlibpng version since 0.88.  In an autoconf \"configure.in\" you could use\n\n    AC_CHECK_LIB(png, png_get_io_ptr, ...\n\n.SH XV. Source code repository\n\nSince about February 2009, version 1.2.34, libpng has been under \"git\" source\ncontrol.  The git repository was built from old libpng-x.y.z.tar.gz files\ngoing back to version 0.70.  You can access the git repository (read only)\nat\n\n    git://git.code.sf.net/p/libpng/code\n\nor you can browse it with a web browser by selecting the \"code\" button at\n\n    https://sourceforge.net/projects/libpng\n\nPatches can be sent to glennrp at users.sourceforge.net or to\npng-mng-implement at lists.sourceforge.net or you can upload them to\nthe libpng bug tracker at\n\n    http://libpng.sourceforge.net\n\nWe also accept patches built from the tar or zip distributions, and\nsimple verbal discriptions of bug fixes, reported either to the\nSourceForge bug tracker, to the png-mng-implement at lists.sf.net\nmailing list, or directly to glennrp.\n\n.SH XV. Coding style\n\nOur coding style is similar to the \"Allman\" style\n(See http://en.wikipedia.org/wiki/Indent_style#Allman_style), with curly\nbraces on separate lines:\n\n    if (condition)\n    {\n       action;\n    }\n\n    else if (another condition)\n    {\n       another action;\n    }\n\nThe braces can be omitted from simple one-line actions:\n\n    if (condition)\n       return (0);\n\nWe use 3-space indentation, except for continued statements which\nare usually indented the same as the first line of the statement\nplus four more spaces.\n\nFor macro definitions we use 2-space indentation, always leaving the \"#\"\nin the first column.\n\n    #ifndef PNG_NO_FEATURE\n    #  ifndef PNG_FEATURE_SUPPORTED\n    #    define PNG_FEATURE_SUPPORTED\n    #  endif\n    #endif\n\nComments appear with the leading \"/*\" at the same indentation as\nthe statement that follows the comment:\n\n    /* Single-line comment */\n    statement;\n\n    /* This is a multiple-line\n     * comment.\n     */\n    statement;\n\nVery short comments can be placed after the end of the statement\nto which they pertain:\n\n    statement;    /* comment */\n\nWe don't use C++ style (\"//\") comments. We have, however,\nused them in the past in some now-abandoned MMX assembler\ncode.\n\nFunctions and their curly braces are not indented, and\nexported functions are marked with PNGAPI:\n\n /* This is a public function that is visible to\n  * application programmers. It does thus-and-so.\n  */\n void PNGAPI\n png_exported_function(png_ptr, png_info, foo)\n {\n    body;\n }\n\nThe return type and decorations are placed on a separate line\nahead of the function name, as illustrated above.\n\nThe prototypes for all exported functions appear in png.h,\nabove the comment that says\n\n    /* Maintainer: Put new public prototypes here ... */\n\nWe mark all non-exported functions with \"/* PRIVATE */\"\":\n\n void /* PRIVATE */\n png_non_exported_function(png_ptr, png_info, foo)\n {\n    body;\n }\n\nThe prototypes for non-exported functions (except for those in\npngtest) appear in pngpriv.h above the comment that says\n\n  /* Maintainer: Put new private prototypes here ^ */\n\nTo avoid polluting the global namespace, the names of all exported\nfunctions and variables begin with \"png_\", and all publicly visible C\npreprocessor macros begin with \"PNG\".  We request that applications that\nuse libpng *not* begin any of their own symbols with either of these strings.\n\nWe put a space after the \"sizeof\" operator and we omit the\noptional parentheses around its argument when the argument\nis an expression, not a type name, and we always enclose the\nsizeof operator, with its argument, in parentheses:\n\n  (sizeof (png_uint_32))\n  (sizeof array)\n\nPrior to libpng-1.6.0 we used a \"png_sizeof()\" macro, formatted as\nthough it were a function.\n\nControl keywords if, for, while, and switch are always followed by a space\nto distinguish them from function calls, which have no trailing space. \n\nWe put a space after each comma and after each semicolon\nin \"for\" statements, and we put spaces before and after each\nC binary operator and after \"for\" or \"while\", and before\n\"?\".  We don't put a space between a typecast and the expression\nbeing cast, nor do we put one between a function name and the\nleft parenthesis that follows it:\n\n    for (i = 2; i > 0; \\-\\-i)\n       y[i] = a(x) + (int)b;\n\nWe prefer #ifdef and #ifndef to #if defined() and #if !defined()\nwhen there is only one macro being tested.  We always use parentheses\nwith \"defined\".\n\nWe express integer constants that are used as bit masks in hex format,\nwith an even number of lower-case hex digits, and to make them unsigned\n(e.g., 0x00U, 0xffU, 0x0100U) and long if they are greater than 0x7fff\n(e.g., 0xffffUL).\n\nWe prefer to use underscores rather than camelCase in names, except\nfor a few type names that we inherit from zlib.h.\n\nWe prefer \"if (something != 0)\" and \"if (something == 0)\"\nover \"if (something)\" and if \"(!something)\", respectively.\n\nWe do not use the TAB character for indentation in the C sources.\n\nLines do not exceed 80 characters.\n\nOther rules can be inferred by inspecting the libpng source.\n\n.SH XVI. Y2K Compliance in libpng\n\nSince the PNG Development group is an ad-hoc body, we can't make\nan official declaration.\n\nThis is your unofficial assurance that libpng from version 0.71 and\nupward through 1.6.25 are Y2K compliant.  It is my belief that earlier\nversions were also Y2K compliant.\n\nLibpng only has two year fields.  One is a 2-byte unsigned integer\nthat will hold years up to 65535.  The other, which is deprecated,\nholds the date in text format, and will hold years up to 9999.\n\nThe integer is\n    \"png_uint_16 year\" in png_time_struct.\n\nThe string is\n    \"char time_buffer[29]\" in png_struct.  This is no longer used\nin libpng-1.6.x and will be removed from libpng-1.7.0.\n\nThere are seven time-related functions:\n\n    png_convert_to_rfc_1123_buffer() in png.c\n      (formerly png_convert_to_rfc_1152() in error, and\n      also formerly png_convert_to_rfc_1123())\n    png_convert_from_struct_tm() in pngwrite.c, called\n      in pngwrite.c\n    png_convert_from_time_t() in pngwrite.c\n    png_get_tIME() in pngget.c\n    png_handle_tIME() in pngrutil.c, called in pngread.c\n    png_set_tIME() in pngset.c\n    png_write_tIME() in pngwutil.c, called in pngwrite.c\n\nAll appear to handle dates properly in a Y2K environment.  The\npng_convert_from_time_t() function calls gmtime() to convert from system\nclock time, which returns (year - 1900), which we properly convert to\nthe full 4-digit year.  There is a possibility that applications using\nlibpng are not passing 4-digit years into the png_convert_to_rfc_1123()\nfunction, or that they are incorrectly passing only a 2-digit year\ninstead of \"year - 1900\" into the png_convert_from_struct_tm() function,\nbut this is not under our control.  The libpng documentation has always\nstated that it works with 4-digit years, and the APIs have been\ndocumented as such.\n\nThe tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned\ninteger to hold the year, and can hold years as large as 65535.\n\nzlib, upon which libpng depends, is also Y2K compliant.  It contains\nno date-related code.\n\n\n   Glenn Randers-Pehrson\n   libpng maintainer\n   PNG Development Group\n\n.SH NOTE\n\nNote about libpng version numbers:\n\nDue to various miscommunications, unforeseen code incompatibilities\nand occasional factors outside the authors' control, version numbering\non the library has not always been consistent and straightforward.\nThe following table summarizes matters since version 0.89c, which was\nthe first widely used release:\n\n source             png.h  png.h  shared-lib\n version            string   int  version\n -------            ------  ----- ----------\n 0.89c \"1.0 beta 3\"     0.89      89  1.0.89\n 0.90  \"1.0 beta 4\"     0.90      90  0.90  [should have been 2.0.90]\n 0.95  \"1.0 beta 5\"     0.95      95  0.95  [should have been 2.0.95]\n 0.96  \"1.0 beta 6\"     0.96      96  0.96  [should have been 2.0.96]\n 0.97b \"1.00.97 beta 7\" 1.00.97   97  1.0.1 [should have been 2.0.97]\n 0.97c                  0.97      97  2.0.97\n 0.98                   0.98      98  2.0.98\n 0.99                   0.99      98  2.0.99\n 0.99a-m                0.99      99  2.0.99\n 1.00                   1.00     100  2.1.0 [100 should be 10000]\n 1.0.0      (from here on, the   100  2.1.0 [100 should be 10000]\n 1.0.1       png.h string is   10001  2.1.0\n 1.0.1a-e    identical to the  10002  from here on, the shared library\n 1.0.2       source version)   10002  is 2.V where V is the source code\n 1.0.2a-b                      10003  version, except as noted.\n 1.0.3                         10003\n 1.0.3a-d                      10004\n 1.0.4                         10004\n 1.0.4a-f                      10005\n 1.0.5 (+ 2 patches)           10005\n 1.0.5a-d                      10006\n 1.0.5e-r                      10100 (not source compatible)\n 1.0.5s-v                      10006 (not binary compatible)\n 1.0.6 (+ 3 patches)           10006 (still binary incompatible)\n 1.0.6d-f                      10007 (still binary incompatible)\n 1.0.6g                        10007\n 1.0.6h                        10007  10.6h (testing xy.z so-numbering)\n 1.0.6i                        10007  10.6i\n 1.0.6j                        10007  2.1.0.6j (incompatible with 1.0.0)\n 1.0.7beta11-14        DLLNUM  10007  2.1.0.7beta11-14 (binary compatible)\n 1.0.7beta15-18           1    10007  2.1.0.7beta15-18 (binary compatible)\n 1.0.7rc1-2               1    10007  2.1.0.7rc1-2 (binary compatible)\n 1.0.7                    1    10007  (still compatible)\n ...\n 1.0.19                  10    10019  10.so.0.19[.0]\n ...\n 1.2.56                  13    10256  12.so.0.56[.0]\n ...\n 1.5.27                  15    10527  15.so.15.27[.0]\n ...\n 1.6.25                  16    10625  16.so.16.25[.0]\n\nHenceforth the source version will match the shared-library minor\nand patch numbers; the shared-library major version number will be\nused for changes in backward compatibility, as it is intended.  The\nPNG_PNGLIB_VER macro, which is not used within libpng but is available\nfor applications, is an unsigned integer of the form xyyzz corresponding\nto the source version x.y.z (leading zeros in y and z).  Beta versions\nwere given the previous public release number plus a letter, until\nversion 1.0.6j; from then on they were given the upcoming public\nrelease number plus \"betaNN\" or \"rcNN\".\n\n.SH \"SEE ALSO\"\n.IR libpngpf(3) \", \" png(5)\n.LP\n.IR libpng :\n.IP\nhttp://libpng.sourceforge.net (follow the [DOWNLOAD] link)\nhttp://www.libpng.org/pub/png\n\n.LP\n.IR zlib :\n.IP\n(generally) at the same location as\n.I libpng\nor at\n.br\nftp://ftp.info-zip.org/pub/infozip/zlib\n\n.LP\n.IR PNG specification: RFC 2083\n.IP\n(generally) at the same location as\n.I libpng\nor at\n.br\nftp://ftp.rfc-editor.org:/in-notes/rfc2083.txt\n.br\nor (as a W3C Recommendation) at\n.br\nhttp://www.w3.org/TR/REC-png.html\n\n.LP\nIn the case of any inconsistency between the PNG specification\nand this library, the specification takes precedence.\n\n.SH AUTHORS\nThis man page: Glenn Randers-Pehrson\n<glennrp at users.sourceforge.net>\n\nThe contributing authors would like to thank all those who helped\nwith testing, bug fixes, and patience.  This wouldn't have been\npossible without all of you.\n\nThanks to Frank J. T. Wojcik for helping with the documentation.\n\nLibpng version 1.6.25 - September 1, 2016:\nInitially created in 1995 by Guy Eric Schalnat, then of Group 42, Inc.\nCurrently maintained by Glenn Randers-Pehrson (glennrp at users.sourceforge.net).\n\nSupported by the PNG development group\n.br\npng-mng-implement at lists.sf.net\n(subscription required; visit\npng-mng-implement at lists.sourceforge.net (subscription required; visit\nhttps://lists.sourceforge.net/lists/listinfo/png-mng-implement\nto subscribe).\n\n.SH NOTICES:\n\nThis copy of the libpng notices is provided for your convenience.  In case of\nany discrepancy between this copy and the notices in the file png.h that is\nincluded in the libpng distribution, the latter shall prevail.\n\nCOPYRIGHT NOTICE, DISCLAIMER, and LICENSE:\n\nIf you modify libpng you may insert additional notices immediately following\nthis sentence.\n\nThis code is released under the libpng license.\n\nlibpng versions 1.0.7, July 1, 2000 through 1.6.25, September 1, 2016 are\nCopyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are\nderived from libpng-1.0.6, and are distributed according to the same\ndisclaimer and license as libpng-1.0.6 with the following individuals\nadded to the list of Contributing Authors:\n\n   Simon-Pierre Cadieux\n   Eric S. Raymond\n   Mans Rullgard\n   Cosmin Truta\n   Gilles Vollant\n   James Yu\n\nand with the following additions to the disclaimer:\n\n   There is no warranty against interference with your enjoyment of the\n   library or against infringement.  There is no warranty that our\n   efforts or the library will fulfill any of your particular purposes\n   or needs.  This library is provided with all faults, and the entire\n   risk of satisfactory quality, performance, accuracy, and effort is with\n   the user.\n\nSome files in the \"contrib\" directory and some configure-generated\nfiles that are distributed with libpng have other copyright owners and\nare released under other open source licenses.\n\nlibpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are\nCopyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from\nlibpng-0.96, and are distributed according to the same disclaimer and\nlicense as libpng-0.96, with the following individuals added to the list\nof Contributing Authors:\n\n   Tom Lane\n   Glenn Randers-Pehrson\n   Willem van Schaik\n\nlibpng versions 0.89, June 1996, through 0.96, May 1997, are\nCopyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,\nand are distributed according to the same disclaimer and license as\nlibpng-0.88, with the following individuals added to the list of\nContributing Authors:\n\n   John Bowler\n   Kevin Bracey\n   Sam Bushell\n   Magnus Holmgren\n   Greg Roelofs\n   Tom Tanner\n\nSome files in the \"scripts\" directory have other copyright owners\nbut are released under this license.\n\nlibpng versions 0.5, May 1995, through 0.88, January 1996, are\nCopyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n\nFor the purposes of this copyright and license, \"Contributing Authors\"\nis defined as the following set of individuals:\n\n   Andreas Dilger\n   Dave Martindale\n   Guy Eric Schalnat\n   Paul Schmidt\n   Tim Wegner\n\nThe PNG Reference Library is supplied \"AS IS\".  The Contributing Authors\nand Group 42, Inc. disclaim all warranties, expressed or implied,\nincluding, without limitation, the warranties of merchantability and of\nfitness for any purpose.  The Contributing Authors and Group 42, Inc.\nassume no liability for direct, indirect, incidental, special, exemplary,\nor consequential damages, which may result from the use of the PNG\nReference Library, even if advised of the possibility of such damage.\n\nPermission is hereby granted to use, copy, modify, and distribute this\nsource code, or portions hereof, for any purpose, without fee, subject\nto the following restrictions:\n\n  1. The origin of this source code must not be misrepresented.\n\n  2. Altered versions must be plainly marked as such and must not\n     be misrepresented as being the original source.\n\n  3. This Copyright notice may not be removed or altered from any\n     source or altered source distribution.\n\nThe Contributing Authors and Group 42, Inc. specifically permit, without\nfee, and encourage the use of this source code as a component to\nsupporting the PNG file format in commercial products.  If you use this\nsource code in a product, acknowledgment is not required but would be\nappreciated.\n\nEND OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.\n\nTRADEMARK:\n\nThe name \"libpng\" has not been registered by the Copyright owner\nas a trademark in any jurisdiction.  However, because libpng has\nbeen distributed and maintained world-wide, continually since 1995,\nthe Copyright owner claims \"common-law trademark protection\" in any\njurisdiction where common-law trademark is recognized.\n\nOSI CERTIFICATION:\n\nLibpng is OSI Certified Open Source Software.  OSI Certified Open Source is\na certification mark of the Open Source Initiative. OSI has not addressed\nthe additional disclaimers inserted at version 1.0.7.\n\nEXPORT CONTROL:\n\nThe Copyright owner believes that the Export Control Classification\nNumber (ECCN) for libpng is EAR99, which means not subject to export\ncontrols or International Traffic in Arms Regulations (ITAR) because\nit is open source, publicly available software, that does not contain\nany encryption software.  See the EAR, paragraphs 734.3(b)(3) and\n734.7(b).\n\nA \"png_get_copyright\" function is available, for convenient use in \"about\"\nboxes and the like:\n\n   printf(\"%s\", png_get_copyright(NULL));\n\nAlso, the PNG logo (in PNG format, of course) is supplied in the\nfiles \"pngbar.png\" and \"pngbar.jpg (88x31) and \"pngnow.png\" (98x31).\n\nGlenn Randers-Pehrson\nglennrp at users.sourceforge.net\nSeptember 1, 2016\n\n.\\\" end of man page\n\n"
  },
  {
    "path": "tess-two/jni/libpng/libpng.pc.in",
    "content": "prefix=@prefix@\nexec_prefix=@exec_prefix@\nlibdir=@libdir@\nincludedir=@includedir@/libpng@PNGLIB_MAJOR@@PNGLIB_MINOR@\n\nName: libpng\nDescription: Loads and saves PNG files\nVersion: @PNGLIB_VERSION@\nLibs: -L${libdir} -lpng@PNGLIB_MAJOR@@PNGLIB_MINOR@\nLibs.private: @LIBS@\nCflags: -I${includedir}\n"
  },
  {
    "path": "tess-two/jni/libpng/libpngpf.3",
    "content": ".TH LIBPNGPF 3 \"September 1, 2016\"\n.SH NAME\nlibpng \\- Portable Network Graphics (PNG) Reference Library 1.6.25\n(private functions)\n.SH SYNOPSIS\n\\fB#include \\fI\"pngpriv.h\"\n\n\\fBAs of libpng version \\fP\\fI1.5.1\\fP\\fB, this section is no longer \\fP\\fImaintained\\fP\\fB, now that the private function prototypes are hidden in pngpriv.h and not accessible to applications. Look in pngpriv.h for the prototypes and a short description of each \\fIfunction.\n\n.SH DESCRIPTION\nThe functions previously listed here are used privately by libpng and are not\navailable for use by applications.  They are not \"exported\" to applications\nusing shared libraries.\n\n.SH SEE ALSO\n.BR \"png\"(5), \" libpng\"(3), \" zlib\"(3), \" deflate\"(5), \" \" and \" zlib\"(5)\n.SH AUTHOR\nGlenn Randers-Pehrson\n"
  },
  {
    "path": "tess-two/jni/libpng/mips/filter_msa_intrinsics.c",
    "content": "\n/* filter_msa_intrinsics.c - MSA optimised filter functions\n *\n * Copyright (c) 2016 Glenn Randers-Pehrson\n * Written by Mandar Sahastrabuddhe, August 2016.\n * Last changed in libpng 1.6.25 [September 1, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n#include <stdio.h>\n#include <stdint.h>\n#include \"../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n/* This code requires -mfpu=msa on the command line: */\n#if PNG_MIPS_MSA_IMPLEMENTATION == 1 /* intrinsics code from pngpriv.h */\n\n#include <msa.h>\n\n/* libpng row pointers are not necessarily aligned to any particular boundary,\n * however this code will only work with appropriate alignment. mips/mips_init.c\n * checks for this (and will not compile unless it is done). This code uses\n * variants of png_aligncast to avoid compiler warnings.\n */\n#define png_ptr(type,pointer) png_aligncast(type *,pointer)\n#define png_ptrc(type,pointer) png_aligncastconst(const type *,pointer)\n\n/* The following relies on a variable 'temp_pointer' being declared with type\n * 'type'.  This is written this way just to hide the GCC strict aliasing\n * warning; note that the code is safe because there never is an alias between\n * the input and output pointers.\n */\n#define png_ldr(type,pointer)\\\n   (temp_pointer = png_ptr(type,pointer), *temp_pointer)\n\n#if PNG_MIPS_MSA_OPT > 0\n\n#ifdef CLANG_BUILD\n   #define MSA_SRLI_B(a, b)   __msa_srli_b((v16i8) a, b)\n\n   #define LW(psrc)                              \\\n   ( {                                           \\\n       uint8_t *psrc_lw_m = (uint8_t *) (psrc);  \\\n       uint32_t val_m;                           \\\n                                                 \\\n       asm volatile (                            \\\n           \"lw  %[val_m],  %[psrc_lw_m]  \\n\\t\"   \\\n                                                 \\\n           : [val_m] \"=r\" (val_m)                \\\n           : [psrc_lw_m] \"m\" (*psrc_lw_m)        \\\n       );                                        \\\n                                                 \\\n       val_m;                                    \\\n   } )\n\n   #define SH(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sh_m = (uint8_t *) (pdst);  \\\n       uint16_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"sh  %[val_m],  %[pdst_sh_m]  \\n\\t\"   \\\n                                                 \\\n           : [pdst_sh_m] \"=m\" (*pdst_sh_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n   #define SW(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sw_m = (uint8_t *) (pdst);  \\\n       uint32_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"sw  %[val_m],  %[pdst_sw_m]  \\n\\t\"   \\\n                                                 \\\n           : [pdst_sw_m] \"=m\" (*pdst_sw_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n       #if (__mips == 64)\n        #define SD(val, pdst)                         \\\n        {                                             \\\n            uint8_t *pdst_sd_m = (uint8_t *) (pdst);  \\\n            uint64_t val_m = (val);                   \\\n                                                      \\\n            asm volatile (                            \\\n                \"sd  %[val_m],  %[pdst_sd_m]  \\n\\t\"   \\\n                                                      \\\n                : [pdst_sd_m] \"=m\" (*pdst_sd_m)       \\\n                : [val_m] \"r\" (val_m)                 \\\n            );                                        \\\n        }\n    #else\n        #define SD(val, pdst)                                          \\\n        {                                                              \\\n            uint8_t *pdst_sd_m = (uint8_t *) (pdst);                   \\\n            uint32_t val0_m, val1_m;                                   \\\n                                                                       \\\n            val0_m = (uint32_t) ((val) & 0x00000000FFFFFFFF);          \\\n            val1_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF);  \\\n                                                                       \\\n            SW(val0_m, pdst_sd_m);                                     \\\n            SW(val1_m, pdst_sd_m + 4);                                 \\\n        }\n    #endif\n#else\n   #define MSA_SRLI_B(a, b)   (a >> b)\n\n#if (__mips_isa_rev >= 6)\n   #define LW(psrc)                              \\\n   ( {                                           \\\n       uint8_t *psrc_lw_m = (uint8_t *) (psrc);  \\\n       uint32_t val_m;                           \\\n                                                 \\\n       asm volatile (                            \\\n           \"lw  %[val_m],  %[psrc_lw_m]  \\n\\t\"   \\\n                                                 \\\n           : [val_m] \"=r\" (val_m)                \\\n           : [psrc_lw_m] \"m\" (*psrc_lw_m)        \\\n       );                                        \\\n                                                 \\\n       val_m;                                    \\\n   } )\n\n   #define SH(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sh_m = (uint8_t *) (pdst);  \\\n       uint16_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"sh  %[val_m],  %[pdst_sh_m]  \\n\\t\"   \\\n                                                 \\\n           : [pdst_sh_m] \"=m\" (*pdst_sh_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n   #define SW(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sw_m = (uint8_t *) (pdst);  \\\n       uint32_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"sw  %[val_m],  %[pdst_sw_m]  \\n\\t\"   \\\n                                                 \\\n           : [pdst_sw_m] \"=m\" (*pdst_sw_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n   #if (__mips == 64)\n        #define SD(val, pdst)                         \\\n        {                                             \\\n            uint8_t *pdst_sd_m = (uint8_t *) (pdst);  \\\n            uint64_t val_m = (val);                   \\\n                                                      \\\n            asm volatile (                            \\\n                \"sd  %[val_m],  %[pdst_sd_m]  \\n\\t\"   \\\n                                                      \\\n                : [pdst_sd_m] \"=m\" (*pdst_sd_m)       \\\n                : [val_m] \"r\" (val_m)                 \\\n            );                                        \\\n        }\n    #else\n        #define SD(val, pdst)                                          \\\n        {                                                              \\\n            uint8_t *pdst_sd_m = (uint8_t *) (pdst);                   \\\n            uint32_t val0_m, val1_m;                                   \\\n                                                                       \\\n            val0_m = (uint32_t) ((val) & 0x00000000FFFFFFFF);          \\\n            val1_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF);  \\\n                                                                       \\\n            SW(val0_m, pdst_sd_m);                                     \\\n            SW(val1_m, pdst_sd_m + 4);                                 \\\n        }\n    #endif\n#else  // !(__mips_isa_rev >= 6)\n   #define LW(psrc)                              \\\n   ( {                                           \\\n       uint8_t *psrc_lw_m = (uint8_t *) (psrc);  \\\n       uint32_t val_m;                           \\\n                                                 \\\n       asm volatile (                            \\\n           \"ulw  %[val_m],  %[psrc_lw_m]  \\n\\t\"  \\\n                                                 \\\n           : [val_m] \"=r\" (val_m)                \\\n           : [psrc_lw_m] \"m\" (*psrc_lw_m)        \\\n       );                                        \\\n                                                 \\\n       val_m;                                    \\\n   } )\n\n   #define SH(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sh_m = (uint8_t *) (pdst);  \\\n       uint16_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"ush  %[val_m],  %[pdst_sh_m]  \\n\\t\"  \\\n                                                 \\\n           : [pdst_sh_m] \"=m\" (*pdst_sh_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n   #define SW(val, pdst)                         \\\n   {                                             \\\n       uint8_t *pdst_sw_m = (uint8_t *) (pdst);  \\\n       uint32_t val_m = (val);                   \\\n                                                 \\\n       asm volatile (                            \\\n           \"usw  %[val_m],  %[pdst_sw_m]  \\n\\t\"  \\\n                                                 \\\n           : [pdst_sw_m] \"=m\" (*pdst_sw_m)       \\\n           : [val_m] \"r\" (val_m)                 \\\n       );                                        \\\n   }\n\n   #define SD(val, pdst)                                          \\\n    {                                                              \\\n        uint8_t *pdst_sd_m = (uint8_t *) (pdst);                   \\\n        uint32_t val0_m, val1_m;                                   \\\n                                                                   \\\n        val0_m = (uint32_t) ((val) & 0x00000000FFFFFFFF);          \\\n        val1_m = (uint32_t) (((val) >> 32) & 0x00000000FFFFFFFF);  \\\n                                                                   \\\n        SW(val0_m, pdst_sd_m);                                     \\\n        SW(val1_m, pdst_sd_m + 4);                                 \\\n    }\n\n    #define SW_ZERO(pdst)                      \\\n    {                                          \\\n        uint8_t *pdst_m = (uint8_t *) (pdst);  \\\n                                               \\\n        asm volatile (                         \\\n            \"usw  $0,  %[pdst_m]  \\n\\t\"        \\\n                                               \\\n            : [pdst_m] \"=m\" (*pdst_m)          \\\n            :                                  \\\n        );                                     \\\n    }\n#endif  // (__mips_isa_rev >= 6)\n#endif\n\n#define LD_B(RTYPE, psrc) *((RTYPE *) (psrc))\n#define LD_UB(...) LD_B(v16u8, __VA_ARGS__)\n#define LD_B2(RTYPE, psrc, stride, out0, out1)  \\\n{                                               \\\n    out0 = LD_B(RTYPE, (psrc));                 \\\n    out1 = LD_B(RTYPE, (psrc) + stride);        \\\n}\n#define LD_UB2(...) LD_B2(v16u8, __VA_ARGS__)\n#define LD_B4(RTYPE, psrc, stride, out0, out1, out2, out3)   \\\n{                                                            \\\n    LD_B2(RTYPE, (psrc), stride, out0, out1);                \\\n    LD_B2(RTYPE, (psrc) + 2 * stride , stride, out2, out3);  \\\n}\n#define LD_UB4(...) LD_B4(v16u8, __VA_ARGS__)\n\n#define ST_B(RTYPE, in, pdst) *((RTYPE *) (pdst)) = (in)\n#define ST_UB(...) ST_B(v16u8, __VA_ARGS__)\n#define ST_B2(RTYPE, in0, in1, pdst, stride)  \\\n{                                             \\\n    ST_B(RTYPE, in0, (pdst));                 \\\n    ST_B(RTYPE, in1, (pdst) + stride);        \\\n}\n#define ST_UB2(...) ST_B2(v16u8, __VA_ARGS__)\n#define ST_B4(RTYPE, in0, in1, in2, in3, pdst, stride)    \\\n{                                                         \\\n    ST_B2(RTYPE, in0, in1, (pdst), stride);               \\\n    ST_B2(RTYPE, in2, in3, (pdst) + 2 * stride, stride);  \\\n}\n#define ST_UB4(...) ST_B4(v16u8, __VA_ARGS__)\n\n#define ADD2(in0, in1, in2, in3, out0, out1)  \\\n{                                             \\\n    out0 = in0 + in1;                         \\\n    out1 = in2 + in3;                         \\\n}\n#define ADD3(in0, in1, in2, in3, in4, in5,  \\\n             out0, out1, out2)              \\\n{                                           \\\n    ADD2(in0, in1, in2, in3, out0, out1);   \\\n    out2 = in4 + in5;                       \\\n}\n#define ADD4(in0, in1, in2, in3, in4, in5, in6, in7,  \\\n             out0, out1, out2, out3)                  \\\n{                                                     \\\n    ADD2(in0, in1, in2, in3, out0, out1);             \\\n    ADD2(in4, in5, in6, in7, out2, out3);             \\\n}\n\n#define ILVR_B2(RTYPE, in0, in1, in2, in3, out0, out1)      \\\n{                                                           \\\n    out0 = (RTYPE) __msa_ilvr_b((v16i8) in0, (v16i8) in1);  \\\n    out1 = (RTYPE) __msa_ilvr_b((v16i8) in2, (v16i8) in3);  \\\n}\n#define ILVR_B2_SH(...) ILVR_B2(v8i16, __VA_ARGS__)\n\n#define HSUB_UB2(RTYPE, in0, in1, out0, out1)                 \\\n{                                                             \\\n    out0 = (RTYPE) __msa_hsub_u_h((v16u8) in0, (v16u8) in0);  \\\n    out1 = (RTYPE) __msa_hsub_u_h((v16u8) in1, (v16u8) in1);  \\\n}\n#define HSUB_UB2_SH(...) HSUB_UB2(v8i16, __VA_ARGS__)\n\n#define SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val)                 \\\n{                                                                         \\\n    v16i8 zero_m = { 0 };                                                 \\\n    out0 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in0, slide_val);  \\\n    out1 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in1, slide_val);  \\\n}\n#define SLDI_B2_0_UB(...) SLDI_B2_0(v16u8, __VA_ARGS__)\n\n#define SLDI_B3_0(RTYPE, in0, in1, in2, out0, out1, out2,  slide_val)     \\\n{                                                                         \\\n    v16i8 zero_m = { 0 };                                                 \\\n    SLDI_B2_0(RTYPE, in0, in1, out0, out1, slide_val);                    \\\n    out2 = (RTYPE) __msa_sldi_b((v16i8) zero_m, (v16i8) in2, slide_val);  \\\n}\n#define SLDI_B3_0_UB(...) SLDI_B3_0(v16u8, __VA_ARGS__)\n\n#define ILVEV_W2(RTYPE, in0, in1, in2, in3, out0, out1)      \\\n{                                                            \\\n    out0 = (RTYPE) __msa_ilvev_w((v4i32) in1, (v4i32) in0);  \\\n    out1 = (RTYPE) __msa_ilvev_w((v4i32) in3, (v4i32) in2);  \\\n}\n#define ILVEV_W2_UB(...) ILVEV_W2(v16u8, __VA_ARGS__)\n\n#define ADD_ABS_H3(RTYPE, in0, in1, in2, out0, out1, out2)  \\\n{                                                           \\\n    RTYPE zero = {0};                                       \\\n                                                            \\\n    out0 = __msa_add_a_h((v8i16) zero, in0);                \\\n    out1 = __msa_add_a_h((v8i16) zero, in1);                \\\n    out2 = __msa_add_a_h((v8i16) zero, in2);                \\\n}\n#define ADD_ABS_H3_SH(...) ADD_ABS_H3(v8i16, __VA_ARGS__)\n\n#define VSHF_B2(RTYPE, in0, in1, in2, in3, mask0, mask1, out0, out1)       \\\n{                                                                          \\\n    out0 = (RTYPE) __msa_vshf_b((v16i8) mask0, (v16i8) in1, (v16i8) in0);  \\\n    out1 = (RTYPE) __msa_vshf_b((v16i8) mask1, (v16i8) in3, (v16i8) in2);  \\\n}\n#define VSHF_B2_UB(...) VSHF_B2(v16u8, __VA_ARGS__)\n\n#define CMP_AND_SELECT(inp0, inp1, inp2, inp3, inp4, inp5, out0)              \\\n{                                                                             \\\n   v8i16 _sel_h0, _sel_h1;                                                    \\\n   v16u8 _sel_b0, _sel_b1;                                                    \\\n   _sel_h0 = (v8i16) __msa_clt_u_h((v8u16) inp1, (v8u16) inp0);               \\\n   _sel_b0 = (v16u8) __msa_pckev_b((v16i8) _sel_h0, (v16i8) _sel_h0);         \\\n   inp0 = (v8i16) __msa_bmnz_v((v16u8) inp0, (v16u8) inp1, (v16u8) _sel_h0);  \\\n   inp4 = (v16u8) __msa_bmnz_v(inp3, inp4, _sel_b0);                          \\\n   _sel_h1 = (v8i16) __msa_clt_u_h((v8u16) inp2, (v8u16) inp0);               \\\n   _sel_b1 = (v16u8) __msa_pckev_b((v16i8) _sel_h1, (v16i8) _sel_h1);         \\\n   inp4 = (v16u8) __msa_bmnz_v(inp4, inp5, _sel_b1);                          \\\n   out0 += inp4;                                                              \\\n}\n\nvoid png_read_filter_row_up_msa(png_row_infop row_info, png_bytep row,\n                                png_const_bytep prev_row)\n{\n   png_size_t i, cnt, cnt16, cnt32;\n   png_size_t istop = row_info->rowbytes;\n   png_bytep rp = row;\n   png_const_bytep pp = prev_row;\n   v16u8 src0, src1, src2, src3, src4, src5, src6, src7;\n\n   for (i = 0; i < (istop >> 6); i++)\n   {\n      LD_UB4(rp, 16, src0, src1, src2, src3);\n      LD_UB4(pp, 16, src4, src5, src6, src7);\n      pp += 64;\n\n\t  ADD4(src0, src4, src1, src5, src2, src6, src3, src7,\n\t       src0, src1, src2, src3);\n\n      ST_UB4(src0, src1, src2, src3, rp, 16);\n      rp += 64;\n   }\n\n   if (istop & 0x3F)\n   {\n      cnt32 = istop & 0x20;\n      cnt16 = istop & 0x10;\n      cnt = istop & 0xF;\n\n      if(cnt32)\n      {\n         if (cnt16 && cnt)\n         {\n            LD_UB4(rp, 16, src0, src1, src2, src3);\n            LD_UB4(pp, 16, src4, src5, src6, src7);\n\n            ADD4(src0, src4, src1, src5, src2, src6, src3, src7,\n\t             src0, src1, src2, src3);\n\n            ST_UB4(src0, src1, src2, src3, rp, 16);\n            rp += 64;\n         }\n         else if (cnt16 || cnt)\n         {\n            LD_UB2(rp, 16, src0, src1);\n            LD_UB2(pp, 16, src4, src5);\n            pp += 32;\n            src2 = LD_UB(rp + 32);\n            src6 = LD_UB(pp);\n\n            ADD3(src0, src4, src1, src5, src2, src6, src0, src1, src2);\n\n            ST_UB2(src0, src1, rp, 16);\n            rp += 32;\n            ST_UB(src2, rp);\n            rp += 16;\n         }\n         else\n         {\n            LD_UB2(rp, 16, src0, src1);\n            LD_UB2(pp, 16, src4, src5);\n\n\t\t\tADD2(src0, src4, src1, src5, src0, src1);\n\n            ST_UB2(src0, src1, rp, 16);\n            rp += 32;\n         }\n      }\n      else if (cnt16 && cnt)\n      {\n         LD_UB2(rp, 16, src0, src1);\n         LD_UB2(pp, 16, src4, src5);\n\n         ADD2(src0, src4, src1, src5, src0, src1);\n\n         ST_UB2(src0, src1, rp, 16);\n         rp += 32;\n      }\n      else if (cnt16 || cnt)\n      {\n         src0 = LD_UB(rp);\n         src4 = LD_UB(pp);\n         pp += 16;\n\n         src0 += src4;\n\n         ST_UB(src0, rp);\n         rp += 16;\n      }\n   }\n}\n\nvoid png_read_filter_row_sub4_msa(png_row_infop row_info, png_bytep row,\n                                  png_const_bytep prev_row)\n{\n   png_size_t count;\n   png_size_t istop = row_info->rowbytes;\n   png_bytep src = row;\n   png_bytep nxt = row + 4;\n   int32_t inp0;\n   v16u8 src0, src1, src2, src3, src4;\n   v16u8 dst0, dst1;\n   v16u8 zero = { 0 };\n\n   istop -= 4;\n\n   inp0 = LW(src);\n   src += 4;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n\n   for (count = 0; count < istop; count += 16)\n   {\n      src1 = LD_UB(src);\n      src += 16;\n\n      src2 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 4);\n      src3 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 8);\n      src4 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 12);\n      src1 += src0;\n      src2 += src1;\n      src3 += src2;\n      src4 += src3;\n      src0 = src4;\n      ILVEV_W2_UB(src1, src2, src3, src4, dst0, dst1);\n      dst0 = (v16u8) __msa_pckev_d((v2i64) dst1, (v2i64) dst0);\n\n      ST_UB(dst0, nxt);\n      nxt += 16;\n   }\n}\n\nvoid png_read_filter_row_sub3_msa(png_row_infop row_info, png_bytep row,\n                                  png_const_bytep prev_row)\n{\n   png_size_t count;\n   png_size_t istop = row_info->rowbytes;\n   png_bytep src = row;\n   png_bytep nxt = row + 3;\n   int64_t out0;\n   int32_t inp0, out1;\n   v16u8 src0, src1, src2, src3, src4, dst0, dst1;\n   v16u8 zero = { 0 };\n   v16i8 mask0 = { 0, 1, 2, 16, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n   v16i8 mask1 = { 0, 1, 2, 3, 4, 5, 16, 17, 18, 19, 20, 21, 0, 0, 0, 0 };\n\n   istop -= 3;\n\n   inp0 = LW(src);\n   src += 3;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n\n   for (count = 0; count < istop; count += 12)\n   {\n      src1 = LD_UB(src);\n      src += 12;\n\n      src2 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 3);\n      src3 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 6);\n      src4 = (v16u8) __msa_sldi_b((v16i8) zero, (v16i8) src1, 9);\n      src1 += src0;\n      src2 += src1;\n      src3 += src2;\n      src4 += src3;\n      src0 = src4;\n      VSHF_B2_UB(src1, src2, src3, src4, mask0, mask0, dst0, dst1);\n      dst0 = (v16u8) __msa_vshf_b(mask1, (v16i8) dst1, (v16i8) dst0);\n      out0 = __msa_copy_s_d((v2i64) dst0, 0);\n      out1 = __msa_copy_s_w((v4i32) dst0, 2);\n\n      SD(out0, nxt);\n      nxt += 8;\n      SW(out1, nxt);\n      nxt += 4;\n   }\n}\n\nvoid png_read_filter_row_avg4_msa(png_row_infop row_info, png_bytep row,\n                                  png_const_bytep prev_row)\n{\n   png_size_t i;\n   png_bytep src = row;\n   png_bytep nxt = row;\n   png_const_bytep pp = prev_row;\n   png_size_t istop = row_info->rowbytes - 4;\n   int32_t inp0, inp1, out0;\n   v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, dst0, dst1;\n   v16u8 zero = { 0 };\n\n   inp0 = LW(pp);\n   pp += 4;\n   inp1 = LW(src);\n   src += 4;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n   src1 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp1);\n   src0 = (v16u8) MSA_SRLI_B(src0, 1);\n   src1 += src0;\n   out0 = __msa_copy_s_w((v4i32) src1, 0);\n   SW(out0, nxt);\n   nxt += 4;\n\n   for (i = 0; i < istop; i += 16)\n   {\n      src2 = LD_UB(pp);\n      pp += 16;\n      src6 = LD_UB(src);\n      src += 16;\n\n      SLDI_B2_0_UB(src2, src6, src3, src7, 4);\n      SLDI_B2_0_UB(src2, src6, src4, src8, 8);\n      SLDI_B2_0_UB(src2, src6, src5, src9, 12);\n      src2 = __msa_ave_u_b(src2, src1);\n      src6 += src2;\n      src3 = __msa_ave_u_b(src3, src6);\n      src7 += src3;\n      src4 = __msa_ave_u_b(src4, src7);\n      src8 += src4;\n      src5 = __msa_ave_u_b(src5, src8);\n      src9 += src5;\n      src1 = src9;\n      ILVEV_W2_UB(src6, src7, src8, src9, dst0, dst1);\n      dst0 = (v16u8) __msa_pckev_d((v2i64) dst1, (v2i64) dst0);\n\n      ST_UB(dst0, nxt);\n      nxt += 16;\n   }\n}\n\nvoid png_read_filter_row_avg3_msa(png_row_infop row_info, png_bytep row,\n                                  png_const_bytep prev_row)\n{\n   png_size_t i;\n   png_bytep src = row;\n   png_bytep nxt = row;\n   png_const_bytep pp = prev_row;\n   png_size_t istop = row_info->rowbytes - 3;\n   int64_t out0;\n   int32_t inp0, inp1, out1;\n   int16_t out2;\n   v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, dst0, dst1;\n   v16u8 zero = { 0 };\n   v16i8 mask0 = { 0, 1, 2, 16, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n   v16i8 mask1 = { 0, 1, 2, 3, 4, 5, 16, 17, 18, 19, 20, 21, 0, 0, 0, 0 };\n\n   inp0 = LW(pp);\n   pp += 3;\n   inp1 = LW(src);\n   src += 3;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n   src1 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp1);\n   src0 = (v16u8) MSA_SRLI_B(src0, 1);\n   src1 += src0;\n   out2 = __msa_copy_s_h((v8i16) src1, 0);\n   SH(out2, nxt);\n   nxt += 2;\n   nxt[0] = src1[2];\n   nxt++;\n\n   for (i = 0; i < istop; i += 12)\n   {\n      src2 = LD_UB(pp);\n      pp += 12;\n      src6 = LD_UB(src);\n      src += 12;\n\n      SLDI_B2_0_UB(src2, src6, src3, src7, 3);\n      SLDI_B2_0_UB(src2, src6, src4, src8, 6);\n      SLDI_B2_0_UB(src2, src6, src5, src9, 9);\n      src2 = __msa_ave_u_b(src2, src1);\n      src6 += src2;\n      src3 = __msa_ave_u_b(src3, src6);\n      src7 += src3;\n      src4 = __msa_ave_u_b(src4, src7);\n      src8 += src4;\n      src5 = __msa_ave_u_b(src5, src8);\n      src9 += src5;\n      src1 = src9;\n      VSHF_B2_UB(src6, src7, src8, src9, mask0, mask0, dst0, dst1);\n      dst0 = (v16u8) __msa_vshf_b(mask1, (v16i8) dst1, (v16i8) dst0);\n      out0 = __msa_copy_s_d((v2i64) dst0, 0);\n      out1 = __msa_copy_s_w((v4i32) dst0, 2);\n\n      SD(out0, nxt);\n      nxt += 8;\n      SW(out1, nxt);\n      nxt += 4;\n   }\n}\n\nvoid png_read_filter_row_paeth4_msa(png_row_infop row_info,\n                                    png_bytep row,\n                                    png_const_bytep prev_row)\n{\n   int32_t count, rp_end;\n   png_bytep nxt;\n   png_const_bytep prev_nxt;\n   int32_t inp0, inp1, res0;\n   v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9;\n   v16u8 src10, src11, src12, src13, dst0, dst1;\n   v8i16 vec0, vec1, vec2;\n   v16u8 zero = { 0 };\n\n   nxt = row;\n   prev_nxt = prev_row;\n\n   inp0 = LW(nxt);\n   inp1 = LW(prev_nxt);\n   prev_nxt += 4;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n   src1 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp1);\n\n   src1 += src0;\n   res0 = __msa_copy_s_w((v4i32) src1, 0);\n\n   SW(res0, nxt);\n   nxt += 4;\n\n   /* Remainder */\n   rp_end = row_info->rowbytes - 4;\n\n   for (count = 0; count < rp_end; count += 16)\n   {\n      src2 = LD_UB(prev_nxt);\n      prev_nxt += 16;\n      src6 = LD_UB(prev_row);\n      prev_row += 16;\n      src10 = LD_UB(nxt);\n\n      SLDI_B3_0_UB(src2, src6, src10, src3, src7, src11, 4);\n      SLDI_B3_0_UB(src2, src6, src10, src4, src8, src12, 8);\n      SLDI_B3_0_UB(src2, src6, src10, src5, src9, src13, 12);\n      ILVR_B2_SH(src2, src6, src1, src6, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src1, src2, src6, src10);\n      ILVR_B2_SH(src3, src7, src10, src7, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src10, src3, src7, src11);\n      ILVR_B2_SH(src4, src8, src11, src8, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src11, src4, src8, src12);\n      ILVR_B2_SH(src5, src9, src12, src9, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src12, src5, src9, src13);\n      src1 = src13;\n      ILVEV_W2_UB(src10, src11, src12, src1, dst0, dst1);\n      dst0 = (v16u8) __msa_pckev_d((v2i64) dst1, (v2i64) dst0);\n\n      ST_UB(dst0, nxt);\n      nxt += 16;\n   }\n}\n\nvoid png_read_filter_row_paeth3_msa(png_row_infop row_info,\n                                    png_bytep row,\n                                    png_const_bytep prev_row)\n{\n   int32_t count, rp_end;\n   png_bytep nxt;\n   png_const_bytep prev_nxt;\n   int64_t out0;\n   int32_t inp0, inp1, out1;\n   int16_t out2;\n   v16u8 src0, src1, src2, src3, src4, src5, src6, src7, src8, src9, dst0, dst1;\n   v16u8 src10, src11, src12, src13;\n   v8i16 vec0, vec1, vec2;\n   v16u8 zero = { 0 };\n   v16i8 mask0 = { 0, 1, 2, 16, 17, 18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };\n   v16i8 mask1 = { 0, 1, 2, 3, 4, 5, 16, 17, 18, 19, 20, 21, 0, 0, 0, 0 };\n\n   nxt = row;\n   prev_nxt = prev_row;\n\n   inp0 = LW(nxt);\n   inp1 = LW(prev_nxt);\n   prev_nxt += 3;\n   src0 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp0);\n   src1 = (v16u8) __msa_insert_w((v4i32) zero, 0, inp1);\n\n   src1 += src0;\n   out2 = __msa_copy_s_h((v8i16) src1, 0);\n\n   SH(out2, nxt);\n   nxt += 2;\n   nxt[0] = src1[2];\n   nxt++;\n\n   /* Remainder */\n   rp_end = row_info->rowbytes - 3;\n\n   for (count = 0; count < rp_end; count += 12)\n   {\n      src2 = LD_UB(prev_nxt);\n      prev_nxt += 12;\n      src6 = LD_UB(prev_row);\n      prev_row += 12;\n      src10 = LD_UB(nxt);\n\n      SLDI_B3_0_UB(src2, src6, src10, src3, src7, src11, 3);\n      SLDI_B3_0_UB(src2, src6, src10, src4, src8, src12, 6);\n      SLDI_B3_0_UB(src2, src6, src10, src5, src9, src13, 9);\n      ILVR_B2_SH(src2, src6, src1, src6, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src1, src2, src6, src10);\n      ILVR_B2_SH(src3, src7, src10, src7, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src10, src3, src7, src11);\n      ILVR_B2_SH(src4, src8, src11, src8, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src11, src4, src8, src12);\n      ILVR_B2_SH(src5, src9, src12, src9, vec0, vec1);\n      HSUB_UB2_SH(vec0, vec1, vec0, vec1);\n      vec2 = vec0 + vec1;\n      ADD_ABS_H3_SH(vec0, vec1, vec2, vec0, vec1, vec2);\n      CMP_AND_SELECT(vec0, vec1, vec2, src12, src5, src9, src13);\n      src1 = src13;\n      VSHF_B2_UB(src10, src11, src12, src13, mask0, mask0, dst0, dst1);\n      dst0 = (v16u8) __msa_vshf_b(mask1, (v16i8) dst1, (v16i8) dst0);\n      out0 = __msa_copy_s_d((v2i64) dst0, 0);\n      out1 = __msa_copy_s_w((v4i32) dst0, 2);\n\n      SD(out0, nxt);\n      nxt += 8;\n      SW(out1, nxt);\n      nxt += 4;\n   }\n}\n\n#endif /* PNG_MIPS_MSA_OPT > 0 */\n#endif /* PNG_MIPS_MSA_IMPLEMENTATION == 1 (intrinsics) */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/mips/mips_init.c",
    "content": "\n/* mips_init.c - MSA optimised filter functions\n *\n * Copyright (c) 2016 Glenn Randers-Pehrson\n * Written by Mandar Sahastrabuddhe, 2016.\n * Last changed in libpng 1.6.25 [September 1, 2016]\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n/* Below, after checking __linux__, various non-C90 POSIX 1003.1 functions are\n * called.\n */\n#define _POSIX_SOURCE 1\n\n#include <stdio.h>\n#include \"../pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n#if PNG_MIPS_MSA_OPT > 0\n#ifdef PNG_MIPS_MSA_CHECK_SUPPORTED /* Do run-time checks */\n/* WARNING: it is strongly recommended that you do not build libpng with\n * run-time checks for CPU features if at all possible.  In the case of the MIPS\n * MSA instructions there is no processor-specific way of detecting the\n * presence of the required support, therefore run-time detection is extremely\n * OS specific.\n *\n * You may set the macro PNG_MIPS_MSA_FILE to the file name of file containing\n * a fragment of C source code which defines the png_have_msa function.  There\n * are a number of implementations in contrib/mips-msa, but the only one that\n * has partial support is contrib/mips-msa/linux.c - a generic Linux\n * implementation which reads /proc/cpufino.\n */\n#ifndef PNG_MIPS_MSA_FILE\n#  ifdef __linux__\n#     define PNG_MIPS_MSA_FILE \"contrib/mips-msa/linux.c\"\n#  endif\n#endif\n\n#ifdef PNG_MIPS_MSA_FILE\n\n#include <signal.h> /* for sig_atomic_t */\nstatic int png_have_msa(png_structp png_ptr);\n#include PNG_MIPS_MSA_FILE\n\n#else  /* PNG_MIPS_MSA_FILE */\n#  error \"PNG_MIPS_MSA_FILE undefined: no support for run-time MIPS MSA checks\"\n#endif /* PNG_MIPS_MSA_FILE */\n#endif /* PNG_MIPS_MSA_CHECK_SUPPORTED */\n\n#ifndef PNG_ALIGNED_MEMORY_SUPPORTED\n#  error \"ALIGNED_MEMORY is required; set: -DPNG_ALIGNED_MEMORY_SUPPORTED\"\n#endif\n\nvoid\npng_init_filter_functions_msa(png_structp pp, unsigned int bpp)\n{\n   /* The switch statement is compiled in for MIPS_MSA_API, the call to\n    * png_have_msa is compiled in for MIPS_MSA_CHECK. If both are defined\n    * the check is only performed if the API has not set the MSA option on\n    * or off explicitly. In this case the check controls what happens.\n    */\n\n#ifdef PNG_MIPS_MSA_API_SUPPORTED\n   switch ((pp->options >> PNG_MIPS_MSA) & 3)\n   {\n      case PNG_OPTION_UNSET:\n         /* Allow the run-time check to execute if it has been enabled -\n          * thus both API and CHECK can be turned on.  If it isn't supported\n          * this case will fall through to the 'default' below, which just\n          * returns.\n          */\n#endif /* PNG_MIPS_MSA_API_SUPPORTED */\n#ifdef PNG_MIPS_MSA_CHECK_SUPPORTED\n         {\n            static volatile sig_atomic_t no_msa = -1; /* not checked */\n\n            if (no_msa < 0)\n               no_msa = !png_have_msa(pp);\n\n            if (no_msa)\n               return;\n         }\n#ifdef PNG_MIPS_MSA_API_SUPPORTED\n         break;\n#endif\n#endif /* PNG_MIPS_MSA_CHECK_SUPPORTED */\n\n#ifdef PNG_MIPS_MSA_API_SUPPORTED\n      default: /* OFF or INVALID */\n         return;\n\n      case PNG_OPTION_ON:\n         /* Option turned on */\n         break;\n   }\n#endif\n\n   /* IMPORTANT: any new external functions used here must be declared using\n    * PNG_INTERNAL_FUNCTION in ../pngpriv.h.  This is required so that the\n    * 'prefix' option to configure works:\n    *\n    *    ./configure --with-libpng-prefix=foobar_\n    *\n    * Verify you have got this right by running the above command, doing a build\n    * and examining pngprefix.h; it must contain a #define for every external\n    * function you add.  (Notice that this happens automatically for the\n    * initialization function.)\n    */\n   pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up_msa;\n\n   if (bpp == 3)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub3_msa;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg3_msa;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth3_msa;\n   }\n\n   else if (bpp == 4)\n   {\n      pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub4_msa;\n      pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg4_msa;\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] = png_read_filter_row_paeth4_msa;\n   }\n}\n#endif /* PNG_MIPS_MSA_OPT > 0 */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/png.5",
    "content": ".TH PNG 5 \"September 1, 2016\"\n.SH NAME\npng \\- Portable Network Graphics (PNG) format\n.SH DESCRIPTION\nPNG (Portable Network Graphics) is an extensible file format for the\nlossless, portable, well-compressed storage of raster images. PNG provides\na patent-free replacement for GIF and can also replace many\ncommon uses of TIFF. Indexed-color, grayscale, and truecolor images are\nsupported, plus an optional alpha channel. Sample depths range from\n1 to 16 bits.\n.br\n\nPNG is designed to work well in online viewing applications, such as the\nWorld Wide Web, so it is fully streamable with a progressive display\noption. PNG is robust, providing both full file integrity checking and\nfast, simple detection of common transmission errors. Also, PNG can store\ngamma and chromaticity data for improved color matching on heterogeneous\nplatforms.\n\n.SH \"SEE ALSO\"\n.BR \"libpng\"(3), \" libpngpf\"(3), \" zlib\"(3), \" deflate\"(5), \" \" and \" zlib\"(5)\n.LP\nPNG specification (second edition), November 2003:\n.IP\n.br\n  <http://www.w3.org/TR/2003/REC-PNG-20031110/\nPNG 1.2 specification, July 1999:\n.IP\n.br\nhttp://png-mng.sourceforge.net/pub/png/spec/1.2/\n.LP\nPNG 1.0 specification, October 1996:\n.IP\n.br\nRFC 2083\n.IP\n.br\nhttp://www.ietf.org/rfc/rfc2083.txt\n.br\nor (as a W3C Recommendation) at\n.br\nhttp://www.w3.org/TR/REC-png-961001\n.SH AUTHORS\nThis man page: Glenn Randers-Pehrson\n.LP\nPortable Network Graphics (PNG) Specification (Second Edition)\nInformation technology - Computer graphics and image processing -\nPortable Network Graphics (PNG): Functional specification.\nISO/IEC 15948:2003 (E) (November 10, 2003): David Duce and others.\n.LP\nPortable Network Graphics (PNG) Specification Version 1.2 (July 8, 1999):\nGlenn Randers-Pehrson and others (png-list).\n.LP\nPortable Network Graphics (PNG) Specification Version 1.0 (October 1, 1996):\nThomas Boutell and others (png-list).\n.LP\n\n\n.SH COPYRIGHT NOTICE\n.LP\nThis man page is Copyright (c) 1998-2006 Glenn Randers-Pehrson.  See png.h\nfor conditions of use and distribution.\n.LP\nThe PNG Specification (Second Edition) is\nCopyright (c) 2003 W3C. (MIT, ERCIM, Keio), All Rights Reserved.\n.LP\nThe PNG-1.2 specification is copyright (c) 1999 Glenn Randers-Pehrson.\nSee the specification for conditions of use and distribution.\n.LP\nThe PNG-1.0 specification is copyright (c) 1996 Massachusetts Institute of\nTechnology.  See the specification for conditions of use and distribution.\n.LP\n.\\\" end of man page\n\n"
  },
  {
    "path": "tess-two/jni/libpng/png.c",
    "content": "\n/* png.c - location for general purpose libpng functions\n *\n * Last changed in libpng 1.6.25 [September 1, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n\n/* Generate a compiler error if there is an old png.h in the search path. */\ntypedef png_libpng_version_1_6_25 Your_png_h_is_not_version_1_6_25;\n\n/* Tells libpng that we have already handled the first \"num_bytes\" bytes\n * of the PNG file signature.  If the PNG data is embedded into another\n * stream we can set num_bytes = 8 so that libpng will not attempt to read\n * or write any of the magic bytes before it starts on the IHDR.\n */\n\n#ifdef PNG_READ_SUPPORTED\nvoid PNGAPI\npng_set_sig_bytes(png_structrp png_ptr, int num_bytes)\n{\n   unsigned int nb = (unsigned int)num_bytes;\n\n   png_debug(1, \"in png_set_sig_bytes\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (num_bytes < 0)\n      nb = 0;\n\n   if (nb > 8)\n      png_error(png_ptr, \"Too many bytes for PNG signature\");\n\n   png_ptr->sig_bytes = (png_byte)nb;\n}\n\n/* Checks whether the supplied bytes match the PNG signature.  We allow\n * checking less than the full 8-byte signature so that those apps that\n * already read the first few bytes of a file to determine the file type\n * can simply check the remaining bytes for extra assurance.  Returns\n * an integer less than, equal to, or greater than zero if sig is found,\n * respectively, to be less than, to match, or be greater than the correct\n * PNG signature (this is the same behavior as strcmp, memcmp, etc).\n */\nint PNGAPI\npng_sig_cmp(png_const_bytep sig, png_size_t start, png_size_t num_to_check)\n{\n   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};\n\n   if (num_to_check > 8)\n      num_to_check = 8;\n\n   else if (num_to_check < 1)\n      return (-1);\n\n   if (start > 7)\n      return (-1);\n\n   if (start + num_to_check > 8)\n      num_to_check = 8 - start;\n\n   return ((int)(memcmp(&sig[start], &png_signature[start], num_to_check)));\n}\n\n#endif /* READ */\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n/* Function to allocate memory for zlib */\nPNG_FUNCTION(voidpf /* PRIVATE */,\npng_zalloc,(voidpf png_ptr, uInt items, uInt size),PNG_ALLOCATED)\n{\n   png_alloc_size_t num_bytes = size;\n\n   if (png_ptr == NULL)\n      return NULL;\n\n   if (items >= (~(png_alloc_size_t)0)/size)\n   {\n      png_warning (png_voidcast(png_structrp, png_ptr),\n          \"Potential overflow in png_zalloc()\");\n      return NULL;\n   }\n\n   num_bytes *= items;\n   return png_malloc_warn(png_voidcast(png_structrp, png_ptr), num_bytes);\n}\n\n/* Function to free memory for zlib */\nvoid /* PRIVATE */\npng_zfree(voidpf png_ptr, voidpf ptr)\n{\n   png_free(png_voidcast(png_const_structrp,png_ptr), ptr);\n}\n\n/* Reset the CRC variable to 32 bits of 1's.  Care must be taken\n * in case CRC is > 32 bits to leave the top bits 0.\n */\nvoid /* PRIVATE */\npng_reset_crc(png_structrp png_ptr)\n{\n   /* The cast is safe because the crc is a 32-bit value. */\n   png_ptr->crc = (png_uint_32)crc32(0, Z_NULL, 0);\n}\n\n/* Calculate the CRC over a section of data.  We can only pass as\n * much data to this routine as the largest single buffer size.  We\n * also check that this data will actually be used before going to the\n * trouble of calculating it.\n */\nvoid /* PRIVATE */\npng_calculate_crc(png_structrp png_ptr, png_const_bytep ptr, png_size_t length)\n{\n   int need_crc = 1;\n\n   if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)\n   {\n      if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==\n          (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))\n         need_crc = 0;\n   }\n\n   else /* critical */\n   {\n      if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)\n         need_crc = 0;\n   }\n\n   /* 'uLong' is defined in zlib.h as unsigned long; this means that on some\n    * systems it is a 64-bit value.  crc32, however, returns 32 bits so the\n    * following cast is safe.  'uInt' may be no more than 16 bits, so it is\n    * necessary to perform a loop here.\n    */\n   if (need_crc != 0 && length > 0)\n   {\n      uLong crc = png_ptr->crc; /* Should never issue a warning */\n\n      do\n      {\n         uInt safe_length = (uInt)length;\n#ifndef __COVERITY__\n         if (safe_length == 0)\n            safe_length = (uInt)-1; /* evil, but safe */\n#endif\n\n         crc = crc32(crc, ptr, safe_length);\n\n         /* The following should never issue compiler warnings; if they do the\n          * target system has characteristics that will probably violate other\n          * assumptions within the libpng code.\n          */\n         ptr += safe_length;\n         length -= safe_length;\n      }\n      while (length > 0);\n\n      /* And the following is always safe because the crc is only 32 bits. */\n      png_ptr->crc = (png_uint_32)crc;\n   }\n}\n\n/* Check a user supplied version number, called from both read and write\n * functions that create a png_struct.\n */\nint\npng_user_version_check(png_structrp png_ptr, png_const_charp user_png_ver)\n{\n   /* Libpng versions 1.0.0 and later are binary compatible if the version\n    * string matches through the second '.'; we must recompile any\n    * applications that use any older library version.\n    */\n\n   if (user_png_ver != NULL)\n   {\n      int i = -1;\n      int found_dots = 0;\n\n      do\n      {\n         i++;\n         if (user_png_ver[i] != PNG_LIBPNG_VER_STRING[i])\n            png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;\n         if (user_png_ver[i] == '.')\n            found_dots++;\n      } while (found_dots < 2 && user_png_ver[i] != 0 &&\n            PNG_LIBPNG_VER_STRING[i] != 0);\n   }\n\n   else\n      png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;\n\n   if ((png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH) != 0)\n   {\n#ifdef PNG_WARNINGS_SUPPORTED\n      size_t pos = 0;\n      char m[128];\n\n      pos = png_safecat(m, (sizeof m), pos,\n          \"Application built with libpng-\");\n      pos = png_safecat(m, (sizeof m), pos, user_png_ver);\n      pos = png_safecat(m, (sizeof m), pos, \" but running with \");\n      pos = png_safecat(m, (sizeof m), pos, PNG_LIBPNG_VER_STRING);\n      PNG_UNUSED(pos)\n\n      png_warning(png_ptr, m);\n#endif\n\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\n      png_ptr->flags = 0;\n#endif\n\n      return 0;\n   }\n\n   /* Success return. */\n   return 1;\n}\n\n/* Generic function to create a png_struct for either read or write - this\n * contains the common initialization.\n */\nPNG_FUNCTION(png_structp /* PRIVATE */,\npng_create_png_struct,(png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,\n    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)\n{\n   png_struct create_struct;\n#  ifdef PNG_SETJMP_SUPPORTED\n      jmp_buf create_jmp_buf;\n#  endif\n\n   /* This temporary stack-allocated structure is used to provide a place to\n    * build enough context to allow the user provided memory allocator (if any)\n    * to be called.\n    */\n   memset(&create_struct, 0, (sizeof create_struct));\n\n   /* Added at libpng-1.2.6 */\n#  ifdef PNG_USER_LIMITS_SUPPORTED\n      create_struct.user_width_max = PNG_USER_WIDTH_MAX;\n      create_struct.user_height_max = PNG_USER_HEIGHT_MAX;\n\n#     ifdef PNG_USER_CHUNK_CACHE_MAX\n      /* Added at libpng-1.2.43 and 1.4.0 */\n      create_struct.user_chunk_cache_max = PNG_USER_CHUNK_CACHE_MAX;\n#     endif\n\n#     ifdef PNG_USER_CHUNK_MALLOC_MAX\n      /* Added at libpng-1.2.43 and 1.4.1, required only for read but exists\n       * in png_struct regardless.\n       */\n      create_struct.user_chunk_malloc_max = PNG_USER_CHUNK_MALLOC_MAX;\n#     endif\n#  endif\n\n   /* The following two API calls simply set fields in png_struct, so it is safe\n    * to do them now even though error handling is not yet set up.\n    */\n#  ifdef PNG_USER_MEM_SUPPORTED\n      png_set_mem_fn(&create_struct, mem_ptr, malloc_fn, free_fn);\n#  else\n      PNG_UNUSED(mem_ptr)\n      PNG_UNUSED(malloc_fn)\n      PNG_UNUSED(free_fn)\n#  endif\n\n   /* (*error_fn) can return control to the caller after the error_ptr is set,\n    * this will result in a memory leak unless the error_fn does something\n    * extremely sophisticated.  The design lacks merit but is implicit in the\n    * API.\n    */\n   png_set_error_fn(&create_struct, error_ptr, error_fn, warn_fn);\n\n#  ifdef PNG_SETJMP_SUPPORTED\n      if (!setjmp(create_jmp_buf))\n#  endif\n      {\n#  ifdef PNG_SETJMP_SUPPORTED\n         /* Temporarily fake out the longjmp information until we have\n          * successfully completed this function.  This only works if we have\n          * setjmp() support compiled in, but it is safe - this stuff should\n          * never happen.\n          */\n         create_struct.jmp_buf_ptr = &create_jmp_buf;\n         create_struct.jmp_buf_size = 0; /*stack allocation*/\n         create_struct.longjmp_fn = longjmp;\n#  endif\n         /* Call the general version checker (shared with read and write code):\n          */\n         if (png_user_version_check(&create_struct, user_png_ver) != 0)\n         {\n            png_structrp png_ptr = png_voidcast(png_structrp,\n                png_malloc_warn(&create_struct, (sizeof *png_ptr)));\n\n            if (png_ptr != NULL)\n            {\n               /* png_ptr->zstream holds a back-pointer to the png_struct, so\n                * this can only be done now:\n                */\n               create_struct.zstream.zalloc = png_zalloc;\n               create_struct.zstream.zfree = png_zfree;\n               create_struct.zstream.opaque = png_ptr;\n\n#              ifdef PNG_SETJMP_SUPPORTED\n               /* Eliminate the local error handling: */\n               create_struct.jmp_buf_ptr = NULL;\n               create_struct.jmp_buf_size = 0;\n               create_struct.longjmp_fn = 0;\n#              endif\n\n               *png_ptr = create_struct;\n\n               /* This is the successful return point */\n               return png_ptr;\n            }\n         }\n      }\n\n   /* A longjmp because of a bug in the application storage allocator or a\n    * simple failure to allocate the png_struct.\n    */\n   return NULL;\n}\n\n/* Allocate the memory for an info_struct for the application. */\nPNG_FUNCTION(png_infop,PNGAPI\npng_create_info_struct,(png_const_structrp png_ptr),PNG_ALLOCATED)\n{\n   png_inforp info_ptr;\n\n   png_debug(1, \"in png_create_info_struct\");\n\n   if (png_ptr == NULL)\n      return NULL;\n\n   /* Use the internal API that does not (or at least should not) error out, so\n    * that this call always returns ok.  The application typically sets up the\n    * error handling *after* creating the info_struct because this is the way it\n    * has always been done in 'example.c'.\n    */\n   info_ptr = png_voidcast(png_inforp, png_malloc_base(png_ptr,\n       (sizeof *info_ptr)));\n\n   if (info_ptr != NULL)\n      memset(info_ptr, 0, (sizeof *info_ptr));\n\n   return info_ptr;\n}\n\n/* This function frees the memory associated with a single info struct.\n * Normally, one would use either png_destroy_read_struct() or\n * png_destroy_write_struct() to free an info struct, but this may be\n * useful for some applications.  From libpng 1.6.0 this function is also used\n * internally to implement the png_info release part of the 'struct' destroy\n * APIs.  This ensures that all possible approaches free the same data (all of\n * it).\n */\nvoid PNGAPI\npng_destroy_info_struct(png_const_structrp png_ptr, png_infopp info_ptr_ptr)\n{\n   png_inforp info_ptr = NULL;\n\n   png_debug(1, \"in png_destroy_info_struct\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (info_ptr_ptr != NULL)\n      info_ptr = *info_ptr_ptr;\n\n   if (info_ptr != NULL)\n   {\n      /* Do this first in case of an error below; if the app implements its own\n       * memory management this can lead to png_free calling png_error, which\n       * will abort this routine and return control to the app error handler.\n       * An infinite loop may result if it then tries to free the same info\n       * ptr.\n       */\n      *info_ptr_ptr = NULL;\n\n      png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);\n      memset(info_ptr, 0, (sizeof *info_ptr));\n      png_free(png_ptr, info_ptr);\n   }\n}\n\n/* Initialize the info structure.  This is now an internal function (0.89)\n * and applications using it are urged to use png_create_info_struct()\n * instead.  Use deprecated in 1.6.0, internal use removed (used internally it\n * is just a memset).\n *\n * NOTE: it is almost inconceivable that this API is used because it bypasses\n * the user-memory mechanism and the user error handling/warning mechanisms in\n * those cases where it does anything other than a memset.\n */\nPNG_FUNCTION(void,PNGAPI\npng_info_init_3,(png_infopp ptr_ptr, png_size_t png_info_struct_size),\n    PNG_DEPRECATED)\n{\n   png_inforp info_ptr = *ptr_ptr;\n\n   png_debug(1, \"in png_info_init_3\");\n\n   if (info_ptr == NULL)\n      return;\n\n   if ((sizeof (png_info)) > png_info_struct_size)\n   {\n      *ptr_ptr = NULL;\n      /* The following line is why this API should not be used: */\n      free(info_ptr);\n      info_ptr = png_voidcast(png_inforp, png_malloc_base(NULL,\n          (sizeof *info_ptr)));\n      if (info_ptr == NULL)\n         return;\n      *ptr_ptr = info_ptr;\n   }\n\n   /* Set everything to 0 */\n   memset(info_ptr, 0, (sizeof *info_ptr));\n}\n\n/* The following API is not called internally */\nvoid PNGAPI\npng_data_freer(png_const_structrp png_ptr, png_inforp info_ptr,\n    int freer, png_uint_32 mask)\n{\n   png_debug(1, \"in png_data_freer\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if (freer == PNG_DESTROY_WILL_FREE_DATA)\n      info_ptr->free_me |= mask;\n\n   else if (freer == PNG_USER_WILL_FREE_DATA)\n      info_ptr->free_me &= ~mask;\n\n   else\n      png_error(png_ptr, \"Unknown freer parameter in png_data_freer\");\n}\n\nvoid PNGAPI\npng_free_data(png_const_structrp png_ptr, png_inforp info_ptr, png_uint_32 mask,\n    int num)\n{\n   png_debug(1, \"in png_free_data\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n#ifdef PNG_TEXT_SUPPORTED\n   /* Free text item num or (if num == -1) all text items */\n   if (info_ptr->text != 0 &&\n       ((mask & PNG_FREE_TEXT) & info_ptr->free_me) != 0)\n   {\n      if (num != -1)\n      {\n         png_free(png_ptr, info_ptr->text[num].key);\n         info_ptr->text[num].key = NULL;\n      }\n\n      else\n      {\n         int i;\n\n         for (i = 0; i < info_ptr->num_text; i++)\n            png_free(png_ptr, info_ptr->text[i].key);\n\n         png_free(png_ptr, info_ptr->text);\n         info_ptr->text = NULL;\n         info_ptr->num_text = 0;\n      }\n   }\n#endif\n\n#ifdef PNG_tRNS_SUPPORTED\n   /* Free any tRNS entry */\n   if (((mask & PNG_FREE_TRNS) & info_ptr->free_me) != 0)\n   {\n      info_ptr->valid &= ~PNG_INFO_tRNS;\n      png_free(png_ptr, info_ptr->trans_alpha);\n      info_ptr->trans_alpha = NULL;\n      info_ptr->num_trans = 0;\n   }\n#endif\n\n#ifdef PNG_sCAL_SUPPORTED\n   /* Free any sCAL entry */\n   if (((mask & PNG_FREE_SCAL) & info_ptr->free_me) != 0)\n   {\n      png_free(png_ptr, info_ptr->scal_s_width);\n      png_free(png_ptr, info_ptr->scal_s_height);\n      info_ptr->scal_s_width = NULL;\n      info_ptr->scal_s_height = NULL;\n      info_ptr->valid &= ~PNG_INFO_sCAL;\n   }\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\n   /* Free any pCAL entry */\n   if (((mask & PNG_FREE_PCAL) & info_ptr->free_me) != 0)\n   {\n      png_free(png_ptr, info_ptr->pcal_purpose);\n      png_free(png_ptr, info_ptr->pcal_units);\n      info_ptr->pcal_purpose = NULL;\n      info_ptr->pcal_units = NULL;\n\n      if (info_ptr->pcal_params != NULL)\n         {\n            int i;\n\n            for (i = 0; i < info_ptr->pcal_nparams; i++)\n               png_free(png_ptr, info_ptr->pcal_params[i]);\n\n            png_free(png_ptr, info_ptr->pcal_params);\n            info_ptr->pcal_params = NULL;\n         }\n      info_ptr->valid &= ~PNG_INFO_pCAL;\n   }\n#endif\n\n#ifdef PNG_iCCP_SUPPORTED\n   /* Free any profile entry */\n   if (((mask & PNG_FREE_ICCP) & info_ptr->free_me) != 0)\n   {\n      png_free(png_ptr, info_ptr->iccp_name);\n      png_free(png_ptr, info_ptr->iccp_profile);\n      info_ptr->iccp_name = NULL;\n      info_ptr->iccp_profile = NULL;\n      info_ptr->valid &= ~PNG_INFO_iCCP;\n   }\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\n   /* Free a given sPLT entry, or (if num == -1) all sPLT entries */\n   if (info_ptr->splt_palettes != 0 &&\n       ((mask & PNG_FREE_SPLT) & info_ptr->free_me) != 0)\n   {\n      if (num != -1)\n      {\n         png_free(png_ptr, info_ptr->splt_palettes[num].name);\n         png_free(png_ptr, info_ptr->splt_palettes[num].entries);\n         info_ptr->splt_palettes[num].name = NULL;\n         info_ptr->splt_palettes[num].entries = NULL;\n      }\n\n      else\n      {\n         int i;\n\n         for (i = 0; i < info_ptr->splt_palettes_num; i++)\n         {\n            png_free(png_ptr, info_ptr->splt_palettes[i].name);\n            png_free(png_ptr, info_ptr->splt_palettes[i].entries);\n         }\n\n         png_free(png_ptr, info_ptr->splt_palettes);\n         info_ptr->splt_palettes = NULL;\n         info_ptr->splt_palettes_num = 0;\n         info_ptr->valid &= ~PNG_INFO_sPLT;\n      }\n   }\n#endif\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n   if (info_ptr->unknown_chunks != 0 &&\n       ((mask & PNG_FREE_UNKN) & info_ptr->free_me) != 0)\n   {\n      if (num != -1)\n      {\n          png_free(png_ptr, info_ptr->unknown_chunks[num].data);\n          info_ptr->unknown_chunks[num].data = NULL;\n      }\n\n      else\n      {\n         int i;\n\n         for (i = 0; i < info_ptr->unknown_chunks_num; i++)\n            png_free(png_ptr, info_ptr->unknown_chunks[i].data);\n\n         png_free(png_ptr, info_ptr->unknown_chunks);\n         info_ptr->unknown_chunks = NULL;\n         info_ptr->unknown_chunks_num = 0;\n      }\n   }\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\n   /* Free any hIST entry */\n   if (((mask & PNG_FREE_HIST) & info_ptr->free_me) != 0)\n   {\n      png_free(png_ptr, info_ptr->hist);\n      info_ptr->hist = NULL;\n      info_ptr->valid &= ~PNG_INFO_hIST;\n   }\n#endif\n\n   /* Free any PLTE entry that was internally allocated */\n   if (((mask & PNG_FREE_PLTE) & info_ptr->free_me) != 0)\n   {\n      png_free(png_ptr, info_ptr->palette);\n      info_ptr->palette = NULL;\n      info_ptr->valid &= ~PNG_INFO_PLTE;\n      info_ptr->num_palette = 0;\n   }\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\n   /* Free any image bits attached to the info structure */\n   if (((mask & PNG_FREE_ROWS) & info_ptr->free_me) != 0)\n   {\n      if (info_ptr->row_pointers != 0)\n      {\n         png_uint_32 row;\n         for (row = 0; row < info_ptr->height; row++)\n            png_free(png_ptr, info_ptr->row_pointers[row]);\n\n         png_free(png_ptr, info_ptr->row_pointers);\n         info_ptr->row_pointers = NULL;\n      }\n      info_ptr->valid &= ~PNG_INFO_IDAT;\n   }\n#endif\n\n   if (num != -1)\n      mask &= ~PNG_FREE_MUL;\n\n   info_ptr->free_me &= ~mask;\n}\n#endif /* READ || WRITE */\n\n/* This function returns a pointer to the io_ptr associated with the user\n * functions.  The application should free any memory associated with this\n * pointer before png_write_destroy() or png_read_destroy() are called.\n */\npng_voidp PNGAPI\npng_get_io_ptr(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return (NULL);\n\n   return (png_ptr->io_ptr);\n}\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n#  ifdef PNG_STDIO_SUPPORTED\n/* Initialize the default input/output functions for the PNG file.  If you\n * use your own read or write routines, you can call either png_set_read_fn()\n * or png_set_write_fn() instead of png_init_io().  If you have defined\n * PNG_NO_STDIO or otherwise disabled PNG_STDIO_SUPPORTED, you must use a\n * function of your own because \"FILE *\" isn't necessarily available.\n */\nvoid PNGAPI\npng_init_io(png_structrp png_ptr, png_FILE_p fp)\n{\n   png_debug(1, \"in png_init_io\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->io_ptr = (png_voidp)fp;\n}\n#  endif\n\n#  ifdef PNG_SAVE_INT_32_SUPPORTED\n/* PNG signed integers are saved in 32-bit 2's complement format.  ANSI C-90\n * defines a cast of a signed integer to an unsigned integer either to preserve\n * the value, if it is positive, or to calculate:\n *\n *     (UNSIGNED_MAX+1) + integer\n *\n * Where UNSIGNED_MAX is the appropriate maximum unsigned value, so when the\n * negative integral value is added the result will be an unsigned value\n * correspnding to the 2's complement representation.\n */\nvoid PNGAPI\npng_save_int_32(png_bytep buf, png_int_32 i)\n{\n   png_save_uint_32(buf, i);\n}\n#  endif\n\n#  ifdef PNG_TIME_RFC1123_SUPPORTED\n/* Convert the supplied time into an RFC 1123 string suitable for use in\n * a \"Creation Time\" or other text-based time string.\n */\nint PNGAPI\npng_convert_to_rfc1123_buffer(char out[29], png_const_timep ptime)\n{\n   static PNG_CONST char short_months[12][4] =\n        {\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\",\n         \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"};\n\n   if (out == NULL)\n      return 0;\n\n   if (ptime->year > 9999 /* RFC1123 limitation */ ||\n       ptime->month == 0    ||  ptime->month > 12  ||\n       ptime->day   == 0    ||  ptime->day   > 31  ||\n       ptime->hour  > 23    ||  ptime->minute > 59 ||\n       ptime->second > 60)\n      return 0;\n\n   {\n      size_t pos = 0;\n      char number_buf[5]; /* enough for a four-digit year */\n\n#     define APPEND_STRING(string) pos = png_safecat(out, 29, pos, (string))\n#     define APPEND_NUMBER(format, value)\\\n         APPEND_STRING(PNG_FORMAT_NUMBER(number_buf, format, (value)))\n#     define APPEND(ch) if (pos < 28) out[pos++] = (ch)\n\n      APPEND_NUMBER(PNG_NUMBER_FORMAT_u, (unsigned)ptime->day);\n      APPEND(' ');\n      APPEND_STRING(short_months[(ptime->month - 1)]);\n      APPEND(' ');\n      APPEND_NUMBER(PNG_NUMBER_FORMAT_u, ptime->year);\n      APPEND(' ');\n      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->hour);\n      APPEND(':');\n      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->minute);\n      APPEND(':');\n      APPEND_NUMBER(PNG_NUMBER_FORMAT_02u, (unsigned)ptime->second);\n      APPEND_STRING(\" +0000\"); /* This reliably terminates the buffer */\n      PNG_UNUSED (pos)\n\n#     undef APPEND\n#     undef APPEND_NUMBER\n#     undef APPEND_STRING\n   }\n\n   return 1;\n}\n\n#    if PNG_LIBPNG_VER < 10700\n/* To do: remove the following from libpng-1.7 */\n/* Original API that uses a private buffer in png_struct.\n * Deprecated because it causes png_struct to carry a spurious temporary\n * buffer (png_struct::time_buffer), better to have the caller pass this in.\n */\npng_const_charp PNGAPI\npng_convert_to_rfc1123(png_structrp png_ptr, png_const_timep ptime)\n{\n   if (png_ptr != NULL)\n   {\n      /* The only failure above if png_ptr != NULL is from an invalid ptime */\n      if (png_convert_to_rfc1123_buffer(png_ptr->time_buffer, ptime) == 0)\n         png_warning(png_ptr, \"Ignoring invalid time value\");\n\n      else\n         return png_ptr->time_buffer;\n   }\n\n   return NULL;\n}\n#    endif /* LIBPNG_VER < 10700 */\n#  endif /* TIME_RFC1123 */\n\n#endif /* READ || WRITE */\n\npng_const_charp PNGAPI\npng_get_copyright(png_const_structrp png_ptr)\n{\n   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */\n#ifdef PNG_STRING_COPYRIGHT\n   return PNG_STRING_COPYRIGHT\n#else\n#  ifdef __STDC__\n   return PNG_STRING_NEWLINE \\\n      \"libpng version 1.6.25 - September 1, 2016\" PNG_STRING_NEWLINE \\\n      \"Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\" \\\n      PNG_STRING_NEWLINE \\\n      \"Copyright (c) 1996-1997 Andreas Dilger\" PNG_STRING_NEWLINE \\\n      \"Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\" \\\n      PNG_STRING_NEWLINE;\n#  else\n   return \"libpng version 1.6.25 - September 1, 2016\\\n      Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\\\n      Copyright (c) 1996-1997 Andreas Dilger\\\n      Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\";\n#  endif\n#endif\n}\n\n/* The following return the library version as a short string in the\n * format 1.0.0 through 99.99.99zz.  To get the version of *.h files\n * used with your application, print out PNG_LIBPNG_VER_STRING, which\n * is defined in png.h.\n * Note: now there is no difference between png_get_libpng_ver() and\n * png_get_header_ver().  Due to the version_nn_nn_nn typedef guard,\n * it is guaranteed that png.c uses the correct version of png.h.\n */\npng_const_charp PNGAPI\npng_get_libpng_ver(png_const_structrp png_ptr)\n{\n   /* Version of *.c files used when building libpng */\n   return png_get_header_ver(png_ptr);\n}\n\npng_const_charp PNGAPI\npng_get_header_ver(png_const_structrp png_ptr)\n{\n   /* Version of *.h files used when building libpng */\n   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */\n   return PNG_LIBPNG_VER_STRING;\n}\n\npng_const_charp PNGAPI\npng_get_header_version(png_const_structrp png_ptr)\n{\n   /* Returns longer string containing both version and date */\n   PNG_UNUSED(png_ptr)  /* Silence compiler warning about unused png_ptr */\n#ifdef __STDC__\n   return PNG_HEADER_VERSION_STRING\n#  ifndef PNG_READ_SUPPORTED\n      \" (NO READ SUPPORT)\"\n#  endif\n      PNG_STRING_NEWLINE;\n#else\n   return PNG_HEADER_VERSION_STRING;\n#endif\n}\n\n#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED\n/* NOTE: this routine is not used internally! */\n/* Build a grayscale palette.  Palette is assumed to be 1 << bit_depth\n * large of png_color.  This lets grayscale images be treated as\n * paletted.  Most useful for gamma correction and simplification\n * of code.  This API is not used internally.\n */\nvoid PNGAPI\npng_build_grayscale_palette(int bit_depth, png_colorp palette)\n{\n   int num_palette;\n   int color_inc;\n   int i;\n   int v;\n\n   png_debug(1, \"in png_do_build_grayscale_palette\");\n\n   if (palette == NULL)\n      return;\n\n   switch (bit_depth)\n   {\n      case 1:\n         num_palette = 2;\n         color_inc = 0xff;\n         break;\n\n      case 2:\n         num_palette = 4;\n         color_inc = 0x55;\n         break;\n\n      case 4:\n         num_palette = 16;\n         color_inc = 0x11;\n         break;\n\n      case 8:\n         num_palette = 256;\n         color_inc = 1;\n         break;\n\n      default:\n         num_palette = 0;\n         color_inc = 0;\n         break;\n   }\n\n   for (i = 0, v = 0; i < num_palette; i++, v += color_inc)\n   {\n      palette[i].red = (png_byte)(v & 0xff);\n      palette[i].green = (png_byte)(v & 0xff);\n      palette[i].blue = (png_byte)(v & 0xff);\n   }\n}\n#endif\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\nint PNGAPI\npng_handle_as_unknown(png_const_structrp png_ptr, png_const_bytep chunk_name)\n{\n   /* Check chunk_name and return \"keep\" value if it's on the list, else 0 */\n   png_const_bytep p, p_end;\n\n   if (png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list == 0)\n      return PNG_HANDLE_CHUNK_AS_DEFAULT;\n\n   p_end = png_ptr->chunk_list;\n   p = p_end + png_ptr->num_chunk_list*5; /* beyond end */\n\n   /* The code is the fifth byte after each four byte string.  Historically this\n    * code was always searched from the end of the list, this is no longer\n    * necessary because the 'set' routine handles duplicate entries correcty.\n    */\n   do /* num_chunk_list > 0, so at least one */\n   {\n      p -= 5;\n\n      if (memcmp(chunk_name, p, 4) == 0)\n         return p[4];\n   }\n   while (p > p_end);\n\n   /* This means that known chunks should be processed and unknown chunks should\n    * be handled according to the value of png_ptr->unknown_default; this can be\n    * confusing because, as a result, there are two levels of defaulting for\n    * unknown chunks.\n    */\n   return PNG_HANDLE_CHUNK_AS_DEFAULT;\n}\n\n#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\\\n   defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)\nint /* PRIVATE */\npng_chunk_unknown_handling(png_const_structrp png_ptr, png_uint_32 chunk_name)\n{\n   png_byte chunk_string[5];\n\n   PNG_CSTRING_FROM_CHUNK(chunk_string, chunk_name);\n   return png_handle_as_unknown(png_ptr, chunk_string);\n}\n#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */\n#endif /* SET_UNKNOWN_CHUNKS */\n\n#ifdef PNG_READ_SUPPORTED\n/* This function, added to libpng-1.0.6g, is untested. */\nint PNGAPI\npng_reset_zstream(png_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return Z_STREAM_ERROR;\n\n   /* WARNING: this resets the window bits to the maximum! */\n   return (inflateReset(&png_ptr->zstream));\n}\n#endif /* READ */\n\n/* This function was added to libpng-1.0.7 */\npng_uint_32 PNGAPI\npng_access_version_number(void)\n{\n   /* Version of *.c files used when building libpng */\n   return((png_uint_32)PNG_LIBPNG_VER);\n}\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n/* Ensure that png_ptr->zstream.msg holds some appropriate error message string.\n * If it doesn't 'ret' is used to set it to something appropriate, even in cases\n * like Z_OK or Z_STREAM_END where the error code is apparently a success code.\n */\nvoid /* PRIVATE */\npng_zstream_error(png_structrp png_ptr, int ret)\n{\n   /* Translate 'ret' into an appropriate error string, priority is given to the\n    * one in zstream if set.  This always returns a string, even in cases like\n    * Z_OK or Z_STREAM_END where the error code is a success code.\n    */\n   if (png_ptr->zstream.msg == NULL) switch (ret)\n   {\n      default:\n      case Z_OK:\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"unexpected zlib return code\");\n         break;\n\n      case Z_STREAM_END:\n         /* Normal exit */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"unexpected end of LZ stream\");\n         break;\n\n      case Z_NEED_DICT:\n         /* This means the deflate stream did not have a dictionary; this\n          * indicates a bogus PNG.\n          */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"missing LZ dictionary\");\n         break;\n\n      case Z_ERRNO:\n         /* gz APIs only: should not happen */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"zlib IO error\");\n         break;\n\n      case Z_STREAM_ERROR:\n         /* internal libpng error */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"bad parameters to zlib\");\n         break;\n\n      case Z_DATA_ERROR:\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"damaged LZ stream\");\n         break;\n\n      case Z_MEM_ERROR:\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"insufficient memory\");\n         break;\n\n      case Z_BUF_ERROR:\n         /* End of input or output; not a problem if the caller is doing\n          * incremental read or write.\n          */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"truncated\");\n         break;\n\n      case Z_VERSION_ERROR:\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"unsupported zlib version\");\n         break;\n\n      case PNG_UNEXPECTED_ZLIB_RETURN:\n         /* Compile errors here mean that zlib now uses the value co-opted in\n          * pngpriv.h for PNG_UNEXPECTED_ZLIB_RETURN; update the switch above\n          * and change pngpriv.h.  Note that this message is \"... return\",\n          * whereas the default/Z_OK one is \"... return code\".\n          */\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"unexpected zlib return\");\n         break;\n   }\n}\n\n/* png_convert_size: a PNGAPI but no longer in png.h, so deleted\n * at libpng 1.5.5!\n */\n\n/* Added at libpng version 1.2.34 and 1.4.0 (moved from pngset.c) */\n#ifdef PNG_GAMMA_SUPPORTED /* always set if COLORSPACE */\nstatic int\npng_colorspace_check_gamma(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, png_fixed_point gAMA, int from)\n   /* This is called to check a new gamma value against an existing one.  The\n    * routine returns false if the new gamma value should not be written.\n    *\n    * 'from' says where the new gamma value comes from:\n    *\n    *    0: the new gamma value is the libpng estimate for an ICC profile\n    *    1: the new gamma value comes from a gAMA chunk\n    *    2: the new gamma value comes from an sRGB chunk\n    */\n{\n   png_fixed_point gtest;\n\n   if ((colorspace->flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&\n       (png_muldiv(&gtest, colorspace->gamma, PNG_FP_1, gAMA) == 0  ||\n      png_gamma_significant(gtest) != 0))\n   {\n      /* Either this is an sRGB image, in which case the calculated gamma\n       * approximation should match, or this is an image with a profile and the\n       * value libpng calculates for the gamma of the profile does not match the\n       * value recorded in the file.  The former, sRGB, case is an error, the\n       * latter is just a warning.\n       */\n      if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0 || from == 2)\n      {\n         png_chunk_report(png_ptr, \"gamma value does not match sRGB\",\n             PNG_CHUNK_ERROR);\n         /* Do not overwrite an sRGB value */\n         return from == 2;\n      }\n\n      else /* sRGB tag not involved */\n      {\n         png_chunk_report(png_ptr, \"gamma value does not match libpng estimate\",\n             PNG_CHUNK_WARNING);\n         return from == 1;\n      }\n   }\n\n   return 1;\n}\n\nvoid /* PRIVATE */\npng_colorspace_set_gamma(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, png_fixed_point gAMA)\n{\n   /* Changed in libpng-1.5.4 to limit the values to ensure overflow can't\n    * occur.  Since the fixed point representation is asymetrical it is\n    * possible for 1/gamma to overflow the limit of 21474 and this means the\n    * gamma value must be at least 5/100000 and hence at most 20000.0.  For\n    * safety the limits here are a little narrower.  The values are 0.00016 to\n    * 6250.0, which are truly ridiculous gamma values (and will produce\n    * displays that are all black or all white.)\n    *\n    * In 1.6.0 this test replaces the ones in pngrutil.c, in the gAMA chunk\n    * handling code, which only required the value to be >0.\n    */\n   png_const_charp errmsg;\n\n   if (gAMA < 16 || gAMA > 625000000)\n      errmsg = \"gamma value out of range\";\n\n#  ifdef PNG_READ_gAMA_SUPPORTED\n   /* Allow the application to set the gamma value more than once */\n   else if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&\n      (colorspace->flags & PNG_COLORSPACE_FROM_gAMA) != 0)\n      errmsg = \"duplicate\";\n#  endif\n\n   /* Do nothing if the colorspace is already invalid */\n   else if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)\n      return;\n\n   else\n   {\n      if (png_colorspace_check_gamma(png_ptr, colorspace, gAMA,\n          1/*from gAMA*/) != 0)\n      {\n         /* Store this gamma value. */\n         colorspace->gamma = gAMA;\n         colorspace->flags |=\n            (PNG_COLORSPACE_HAVE_GAMMA | PNG_COLORSPACE_FROM_gAMA);\n      }\n\n      /* At present if the check_gamma test fails the gamma of the colorspace is\n       * not updated however the colorspace is not invalidated.  This\n       * corresponds to the case where the existing gamma comes from an sRGB\n       * chunk or profile.  An error message has already been output.\n       */\n      return;\n   }\n\n   /* Error exit - errmsg has been set. */\n   colorspace->flags |= PNG_COLORSPACE_INVALID;\n   png_chunk_report(png_ptr, errmsg, PNG_CHUNK_WRITE_ERROR);\n}\n\nvoid /* PRIVATE */\npng_colorspace_sync_info(png_const_structrp png_ptr, png_inforp info_ptr)\n{\n   if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)\n   {\n      /* Everything is invalid */\n      info_ptr->valid &= ~(PNG_INFO_gAMA|PNG_INFO_cHRM|PNG_INFO_sRGB|\n         PNG_INFO_iCCP);\n\n#     ifdef PNG_COLORSPACE_SUPPORTED\n      /* Clean up the iCCP profile now if it won't be used. */\n      png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, -1/*not used*/);\n#     else\n      PNG_UNUSED(png_ptr)\n#     endif\n   }\n\n   else\n   {\n#     ifdef PNG_COLORSPACE_SUPPORTED\n      /* Leave the INFO_iCCP flag set if the pngset.c code has already set\n       * it; this allows a PNG to contain a profile which matches sRGB and\n       * yet still have that profile retrievable by the application.\n       */\n      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_MATCHES_sRGB) != 0)\n         info_ptr->valid |= PNG_INFO_sRGB;\n\n      else\n         info_ptr->valid &= ~PNG_INFO_sRGB;\n\n      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n         info_ptr->valid |= PNG_INFO_cHRM;\n\n      else\n         info_ptr->valid &= ~PNG_INFO_cHRM;\n#     endif\n\n      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0)\n         info_ptr->valid |= PNG_INFO_gAMA;\n\n      else\n         info_ptr->valid &= ~PNG_INFO_gAMA;\n   }\n}\n\n#ifdef PNG_READ_SUPPORTED\nvoid /* PRIVATE */\npng_colorspace_sync(png_const_structrp png_ptr, png_inforp info_ptr)\n{\n   if (info_ptr == NULL) /* reduce code size; check here not in the caller */\n      return;\n\n   info_ptr->colorspace = png_ptr->colorspace;\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n#endif\n#endif /* GAMMA */\n\n#ifdef PNG_COLORSPACE_SUPPORTED\n/* Added at libpng-1.5.5 to support read and write of true CIEXYZ values for\n * cHRM, as opposed to using chromaticities.  These internal APIs return\n * non-zero on a parameter error.  The X, Y and Z values are required to be\n * positive and less than 1.0.\n */\nstatic int\npng_xy_from_XYZ(png_xy *xy, const png_XYZ *XYZ)\n{\n   png_int_32 d, dwhite, whiteX, whiteY;\n\n   d = XYZ->red_X + XYZ->red_Y + XYZ->red_Z;\n   if (png_muldiv(&xy->redx, XYZ->red_X, PNG_FP_1, d) == 0)\n      return 1;\n   if (png_muldiv(&xy->redy, XYZ->red_Y, PNG_FP_1, d) == 0)\n      return 1;\n   dwhite = d;\n   whiteX = XYZ->red_X;\n   whiteY = XYZ->red_Y;\n\n   d = XYZ->green_X + XYZ->green_Y + XYZ->green_Z;\n   if (png_muldiv(&xy->greenx, XYZ->green_X, PNG_FP_1, d) == 0)\n      return 1;\n   if (png_muldiv(&xy->greeny, XYZ->green_Y, PNG_FP_1, d) == 0)\n      return 1;\n   dwhite += d;\n   whiteX += XYZ->green_X;\n   whiteY += XYZ->green_Y;\n\n   d = XYZ->blue_X + XYZ->blue_Y + XYZ->blue_Z;\n   if (png_muldiv(&xy->bluex, XYZ->blue_X, PNG_FP_1, d) == 0)\n      return 1;\n   if (png_muldiv(&xy->bluey, XYZ->blue_Y, PNG_FP_1, d) == 0)\n      return 1;\n   dwhite += d;\n   whiteX += XYZ->blue_X;\n   whiteY += XYZ->blue_Y;\n\n   /* The reference white is simply the sum of the end-point (X,Y,Z) vectors,\n    * thus:\n    */\n   if (png_muldiv(&xy->whitex, whiteX, PNG_FP_1, dwhite) == 0)\n      return 1;\n   if (png_muldiv(&xy->whitey, whiteY, PNG_FP_1, dwhite) == 0)\n      return 1;\n\n   return 0;\n}\n\nstatic int\npng_XYZ_from_xy(png_XYZ *XYZ, const png_xy *xy)\n{\n   png_fixed_point red_inverse, green_inverse, blue_scale;\n   png_fixed_point left, right, denominator;\n\n   /* Check xy and, implicitly, z.  Note that wide gamut color spaces typically\n    * have end points with 0 tristimulus values (these are impossible end\n    * points, but they are used to cover the possible colors).  We check\n    * xy->whitey against 5, not 0, to avoid a possible integer overflow.\n    */\n   if (xy->redx   < 0 || xy->redx > PNG_FP_1) return 1;\n   if (xy->redy   < 0 || xy->redy > PNG_FP_1-xy->redx) return 1;\n   if (xy->greenx < 0 || xy->greenx > PNG_FP_1) return 1;\n   if (xy->greeny < 0 || xy->greeny > PNG_FP_1-xy->greenx) return 1;\n   if (xy->bluex  < 0 || xy->bluex > PNG_FP_1) return 1;\n   if (xy->bluey  < 0 || xy->bluey > PNG_FP_1-xy->bluex) return 1;\n   if (xy->whitex < 0 || xy->whitex > PNG_FP_1) return 1;\n   if (xy->whitey < 5 || xy->whitey > PNG_FP_1-xy->whitex) return 1;\n\n   /* The reverse calculation is more difficult because the original tristimulus\n    * value had 9 independent values (red,green,blue)x(X,Y,Z) however only 8\n    * derived values were recorded in the cHRM chunk;\n    * (red,green,blue,white)x(x,y).  This loses one degree of freedom and\n    * therefore an arbitrary ninth value has to be introduced to undo the\n    * original transformations.\n    *\n    * Think of the original end-points as points in (X,Y,Z) space.  The\n    * chromaticity values (c) have the property:\n    *\n    *           C\n    *   c = ---------\n    *       X + Y + Z\n    *\n    * For each c (x,y,z) from the corresponding original C (X,Y,Z).  Thus the\n    * three chromaticity values (x,y,z) for each end-point obey the\n    * relationship:\n    *\n    *   x + y + z = 1\n    *\n    * This describes the plane in (X,Y,Z) space that intersects each axis at the\n    * value 1.0; call this the chromaticity plane.  Thus the chromaticity\n    * calculation has scaled each end-point so that it is on the x+y+z=1 plane\n    * and chromaticity is the intersection of the vector from the origin to the\n    * (X,Y,Z) value with the chromaticity plane.\n    *\n    * To fully invert the chromaticity calculation we would need the three\n    * end-point scale factors, (red-scale, green-scale, blue-scale), but these\n    * were not recorded.  Instead we calculated the reference white (X,Y,Z) and\n    * recorded the chromaticity of this.  The reference white (X,Y,Z) would have\n    * given all three of the scale factors since:\n    *\n    *    color-C = color-c * color-scale\n    *    white-C = red-C + green-C + blue-C\n    *            = red-c*red-scale + green-c*green-scale + blue-c*blue-scale\n    *\n    * But cHRM records only white-x and white-y, so we have lost the white scale\n    * factor:\n    *\n    *    white-C = white-c*white-scale\n    *\n    * To handle this the inverse transformation makes an arbitrary assumption\n    * about white-scale:\n    *\n    *    Assume: white-Y = 1.0\n    *    Hence:  white-scale = 1/white-y\n    *    Or:     red-Y + green-Y + blue-Y = 1.0\n    *\n    * Notice the last statement of the assumption gives an equation in three of\n    * the nine values we want to calculate.  8 more equations come from the\n    * above routine as summarised at the top above (the chromaticity\n    * calculation):\n    *\n    *    Given: color-x = color-X / (color-X + color-Y + color-Z)\n    *    Hence: (color-x - 1)*color-X + color.x*color-Y + color.x*color-Z = 0\n    *\n    * This is 9 simultaneous equations in the 9 variables \"color-C\" and can be\n    * solved by Cramer's rule.  Cramer's rule requires calculating 10 9x9 matrix\n    * determinants, however this is not as bad as it seems because only 28 of\n    * the total of 90 terms in the various matrices are non-zero.  Nevertheless\n    * Cramer's rule is notoriously numerically unstable because the determinant\n    * calculation involves the difference of large, but similar, numbers.  It is\n    * difficult to be sure that the calculation is stable for real world values\n    * and it is certain that it becomes unstable where the end points are close\n    * together.\n    *\n    * So this code uses the perhaps slightly less optimal but more\n    * understandable and totally obvious approach of calculating color-scale.\n    *\n    * This algorithm depends on the precision in white-scale and that is\n    * (1/white-y), so we can immediately see that as white-y approaches 0 the\n    * accuracy inherent in the cHRM chunk drops off substantially.\n    *\n    * libpng arithmetic: a simple inversion of the above equations\n    * ------------------------------------------------------------\n    *\n    *    white_scale = 1/white-y\n    *    white-X = white-x * white-scale\n    *    white-Y = 1.0\n    *    white-Z = (1 - white-x - white-y) * white_scale\n    *\n    *    white-C = red-C + green-C + blue-C\n    *            = red-c*red-scale + green-c*green-scale + blue-c*blue-scale\n    *\n    * This gives us three equations in (red-scale,green-scale,blue-scale) where\n    * all the coefficients are now known:\n    *\n    *    red-x*red-scale + green-x*green-scale + blue-x*blue-scale\n    *       = white-x/white-y\n    *    red-y*red-scale + green-y*green-scale + blue-y*blue-scale = 1\n    *    red-z*red-scale + green-z*green-scale + blue-z*blue-scale\n    *       = (1 - white-x - white-y)/white-y\n    *\n    * In the last equation color-z is (1 - color-x - color-y) so we can add all\n    * three equations together to get an alternative third:\n    *\n    *    red-scale + green-scale + blue-scale = 1/white-y = white-scale\n    *\n    * So now we have a Cramer's rule solution where the determinants are just\n    * 3x3 - far more tractible.  Unfortunately 3x3 determinants still involve\n    * multiplication of three coefficients so we can't guarantee to avoid\n    * overflow in the libpng fixed point representation.  Using Cramer's rule in\n    * floating point is probably a good choice here, but it's not an option for\n    * fixed point.  Instead proceed to simplify the first two equations by\n    * eliminating what is likely to be the largest value, blue-scale:\n    *\n    *    blue-scale = white-scale - red-scale - green-scale\n    *\n    * Hence:\n    *\n    *    (red-x - blue-x)*red-scale + (green-x - blue-x)*green-scale =\n    *                (white-x - blue-x)*white-scale\n    *\n    *    (red-y - blue-y)*red-scale + (green-y - blue-y)*green-scale =\n    *                1 - blue-y*white-scale\n    *\n    * And now we can trivially solve for (red-scale,green-scale):\n    *\n    *    green-scale =\n    *                (white-x - blue-x)*white-scale - (red-x - blue-x)*red-scale\n    *                -----------------------------------------------------------\n    *                                  green-x - blue-x\n    *\n    *    red-scale =\n    *                1 - blue-y*white-scale - (green-y - blue-y) * green-scale\n    *                ---------------------------------------------------------\n    *                                  red-y - blue-y\n    *\n    * Hence:\n    *\n    *    red-scale =\n    *          ( (green-x - blue-x) * (white-y - blue-y) -\n    *            (green-y - blue-y) * (white-x - blue-x) ) / white-y\n    * -------------------------------------------------------------------------\n    *  (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x)\n    *\n    *    green-scale =\n    *          ( (red-y - blue-y) * (white-x - blue-x) -\n    *            (red-x - blue-x) * (white-y - blue-y) ) / white-y\n    * -------------------------------------------------------------------------\n    *  (green-x - blue-x)*(red-y - blue-y)-(green-y - blue-y)*(red-x - blue-x)\n    *\n    * Accuracy:\n    * The input values have 5 decimal digits of accuracy.  The values are all in\n    * the range 0 < value < 1, so simple products are in the same range but may\n    * need up to 10 decimal digits to preserve the original precision and avoid\n    * underflow.  Because we are using a 32-bit signed representation we cannot\n    * match this; the best is a little over 9 decimal digits, less than 10.\n    *\n    * The approach used here is to preserve the maximum precision within the\n    * signed representation.  Because the red-scale calculation above uses the\n    * difference between two products of values that must be in the range -1..+1\n    * it is sufficient to divide the product by 7; ceil(100,000/32767*2).  The\n    * factor is irrelevant in the calculation because it is applied to both\n    * numerator and denominator.\n    *\n    * Note that the values of the differences of the products of the\n    * chromaticities in the above equations tend to be small, for example for\n    * the sRGB chromaticities they are:\n    *\n    * red numerator:    -0.04751\n    * green numerator:  -0.08788\n    * denominator:      -0.2241 (without white-y multiplication)\n    *\n    *  The resultant Y coefficients from the chromaticities of some widely used\n    *  color space definitions are (to 15 decimal places):\n    *\n    *  sRGB\n    *    0.212639005871510 0.715168678767756 0.072192315360734\n    *  Kodak ProPhoto\n    *    0.288071128229293 0.711843217810102 0.000085653960605\n    *  Adobe RGB\n    *    0.297344975250536 0.627363566255466 0.075291458493998\n    *  Adobe Wide Gamut RGB\n    *    0.258728243040113 0.724682314948566 0.016589442011321\n    */\n   /* By the argument, above overflow should be impossible here. The return\n    * value of 2 indicates an internal error to the caller.\n    */\n   if (png_muldiv(&left, xy->greenx-xy->bluex, xy->redy - xy->bluey, 7) == 0)\n      return 2;\n   if (png_muldiv(&right, xy->greeny-xy->bluey, xy->redx - xy->bluex, 7) == 0)\n      return 2;\n   denominator = left - right;\n\n   /* Now find the red numerator. */\n   if (png_muldiv(&left, xy->greenx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)\n      return 2;\n   if (png_muldiv(&right, xy->greeny-xy->bluey, xy->whitex-xy->bluex, 7) == 0)\n      return 2;\n\n   /* Overflow is possible here and it indicates an extreme set of PNG cHRM\n    * chunk values.  This calculation actually returns the reciprocal of the\n    * scale value because this allows us to delay the multiplication of white-y\n    * into the denominator, which tends to produce a small number.\n    */\n   if (png_muldiv(&red_inverse, xy->whitey, denominator, left-right) == 0 ||\n       red_inverse <= xy->whitey /* r+g+b scales = white scale */)\n      return 1;\n\n   /* Similarly for green_inverse: */\n   if (png_muldiv(&left, xy->redy-xy->bluey, xy->whitex-xy->bluex, 7) == 0)\n      return 2;\n   if (png_muldiv(&right, xy->redx-xy->bluex, xy->whitey-xy->bluey, 7) == 0)\n      return 2;\n   if (png_muldiv(&green_inverse, xy->whitey, denominator, left-right) == 0 ||\n       green_inverse <= xy->whitey)\n      return 1;\n\n   /* And the blue scale, the checks above guarantee this can't overflow but it\n    * can still produce 0 for extreme cHRM values.\n    */\n   blue_scale = png_reciprocal(xy->whitey) - png_reciprocal(red_inverse) -\n       png_reciprocal(green_inverse);\n   if (blue_scale <= 0)\n      return 1;\n\n\n   /* And fill in the png_XYZ: */\n   if (png_muldiv(&XYZ->red_X, xy->redx, PNG_FP_1, red_inverse) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->red_Y, xy->redy, PNG_FP_1, red_inverse) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->red_Z, PNG_FP_1 - xy->redx - xy->redy, PNG_FP_1,\n       red_inverse) == 0)\n      return 1;\n\n   if (png_muldiv(&XYZ->green_X, xy->greenx, PNG_FP_1, green_inverse) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->green_Y, xy->greeny, PNG_FP_1, green_inverse) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->green_Z, PNG_FP_1 - xy->greenx - xy->greeny, PNG_FP_1,\n       green_inverse) == 0)\n      return 1;\n\n   if (png_muldiv(&XYZ->blue_X, xy->bluex, blue_scale, PNG_FP_1) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->blue_Y, xy->bluey, blue_scale, PNG_FP_1) == 0)\n      return 1;\n   if (png_muldiv(&XYZ->blue_Z, PNG_FP_1 - xy->bluex - xy->bluey, blue_scale,\n       PNG_FP_1) == 0)\n      return 1;\n\n   return 0; /*success*/\n}\n\nstatic int\npng_XYZ_normalize(png_XYZ *XYZ)\n{\n   png_int_32 Y;\n\n   if (XYZ->red_Y < 0 || XYZ->green_Y < 0 || XYZ->blue_Y < 0 ||\n      XYZ->red_X < 0 || XYZ->green_X < 0 || XYZ->blue_X < 0 ||\n      XYZ->red_Z < 0 || XYZ->green_Z < 0 || XYZ->blue_Z < 0)\n      return 1;\n\n   /* Normalize by scaling so the sum of the end-point Y values is PNG_FP_1.\n    * IMPLEMENTATION NOTE: ANSI requires signed overflow not to occur, therefore\n    * relying on addition of two positive values producing a negative one is not\n    * safe.\n    */\n   Y = XYZ->red_Y;\n   if (0x7fffffff - Y < XYZ->green_X)\n      return 1;\n   Y += XYZ->green_Y;\n   if (0x7fffffff - Y < XYZ->blue_X)\n      return 1;\n   Y += XYZ->blue_Y;\n\n   if (Y != PNG_FP_1)\n   {\n      if (png_muldiv(&XYZ->red_X, XYZ->red_X, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->red_Y, XYZ->red_Y, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->red_Z, XYZ->red_Z, PNG_FP_1, Y) == 0)\n         return 1;\n\n      if (png_muldiv(&XYZ->green_X, XYZ->green_X, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->green_Y, XYZ->green_Y, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->green_Z, XYZ->green_Z, PNG_FP_1, Y) == 0)\n         return 1;\n\n      if (png_muldiv(&XYZ->blue_X, XYZ->blue_X, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->blue_Y, XYZ->blue_Y, PNG_FP_1, Y) == 0)\n         return 1;\n      if (png_muldiv(&XYZ->blue_Z, XYZ->blue_Z, PNG_FP_1, Y) == 0)\n         return 1;\n   }\n\n   return 0;\n}\n\nstatic int\npng_colorspace_endpoints_match(const png_xy *xy1, const png_xy *xy2, int delta)\n{\n   /* Allow an error of +/-0.01 (absolute value) on each chromaticity */\n   if (PNG_OUT_OF_RANGE(xy1->whitex, xy2->whitex,delta) ||\n       PNG_OUT_OF_RANGE(xy1->whitey, xy2->whitey,delta) ||\n       PNG_OUT_OF_RANGE(xy1->redx,   xy2->redx,  delta) ||\n       PNG_OUT_OF_RANGE(xy1->redy,   xy2->redy,  delta) ||\n       PNG_OUT_OF_RANGE(xy1->greenx, xy2->greenx,delta) ||\n       PNG_OUT_OF_RANGE(xy1->greeny, xy2->greeny,delta) ||\n       PNG_OUT_OF_RANGE(xy1->bluex,  xy2->bluex, delta) ||\n       PNG_OUT_OF_RANGE(xy1->bluey,  xy2->bluey, delta))\n      return 0;\n   return 1;\n}\n\n/* Added in libpng-1.6.0, a different check for the validity of a set of cHRM\n * chunk chromaticities.  Earlier checks used to simply look for the overflow\n * condition (where the determinant of the matrix to solve for XYZ ends up zero\n * because the chromaticity values are not all distinct.)  Despite this it is\n * theoretically possible to produce chromaticities that are apparently valid\n * but that rapidly degrade to invalid, potentially crashing, sets because of\n * arithmetic inaccuracies when calculations are performed on them.  The new\n * check is to round-trip xy -> XYZ -> xy and then check that the result is\n * within a small percentage of the original.\n */\nstatic int\npng_colorspace_check_xy(png_XYZ *XYZ, const png_xy *xy)\n{\n   int result;\n   png_xy xy_test;\n\n   /* As a side-effect this routine also returns the XYZ endpoints. */\n   result = png_XYZ_from_xy(XYZ, xy);\n   if (result != 0)\n      return result;\n\n   result = png_xy_from_XYZ(&xy_test, XYZ);\n   if (result != 0)\n      return result;\n\n   if (png_colorspace_endpoints_match(xy, &xy_test,\n       5/*actually, the math is pretty accurate*/) != 0)\n      return 0;\n\n   /* Too much slip */\n   return 1;\n}\n\n/* This is the check going the other way.  The XYZ is modified to normalize it\n * (another side-effect) and the xy chromaticities are returned.\n */\nstatic int\npng_colorspace_check_XYZ(png_xy *xy, png_XYZ *XYZ)\n{\n   int result;\n   png_XYZ XYZtemp;\n\n   result = png_XYZ_normalize(XYZ);\n   if (result != 0)\n      return result;\n\n   result = png_xy_from_XYZ(xy, XYZ);\n   if (result != 0)\n      return result;\n\n   XYZtemp = *XYZ;\n   return png_colorspace_check_xy(&XYZtemp, xy);\n}\n\n/* Used to check for an endpoint match against sRGB */\nstatic const png_xy sRGB_xy = /* From ITU-R BT.709-3 */\n{\n   /* color      x       y */\n   /* red   */ 64000, 33000,\n   /* green */ 30000, 60000,\n   /* blue  */ 15000,  6000,\n   /* white */ 31270, 32900\n};\n\nstatic int\npng_colorspace_set_xy_and_XYZ(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, const png_xy *xy, const png_XYZ *XYZ,\n    int preferred)\n{\n   if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)\n      return 0;\n\n   /* The consistency check is performed on the chromaticities; this factors out\n    * variations because of the normalization (or not) of the end point Y\n    * values.\n    */\n   if (preferred < 2 &&\n       (colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      /* The end points must be reasonably close to any we already have.  The\n       * following allows an error of up to +/-.001\n       */\n      if (png_colorspace_endpoints_match(xy, &colorspace->end_points_xy,\n          100) == 0)\n      {\n         colorspace->flags |= PNG_COLORSPACE_INVALID;\n         png_benign_error(png_ptr, \"inconsistent chromaticities\");\n         return 0; /* failed */\n      }\n\n      /* Only overwrite with preferred values */\n      if (preferred == 0)\n         return 1; /* ok, but no change */\n   }\n\n   colorspace->end_points_xy = *xy;\n   colorspace->end_points_XYZ = *XYZ;\n   colorspace->flags |= PNG_COLORSPACE_HAVE_ENDPOINTS;\n\n   /* The end points are normally quoted to two decimal digits, so allow +/-0.01\n    * on this test.\n    */\n   if (png_colorspace_endpoints_match(xy, &sRGB_xy, 1000) != 0)\n      colorspace->flags |= PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB;\n\n   else\n      colorspace->flags &= PNG_COLORSPACE_CANCEL(\n         PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB);\n\n   return 2; /* ok and changed */\n}\n\nint /* PRIVATE */\npng_colorspace_set_chromaticities(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, const png_xy *xy, int preferred)\n{\n   /* We must check the end points to ensure they are reasonable - in the past\n    * color management systems have crashed as a result of getting bogus\n    * colorant values, while this isn't the fault of libpng it is the\n    * responsibility of libpng because PNG carries the bomb and libpng is in a\n    * position to protect against it.\n    */\n   png_XYZ XYZ;\n\n   switch (png_colorspace_check_xy(&XYZ, xy))\n   {\n      case 0: /* success */\n         return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, xy, &XYZ,\n             preferred);\n\n      case 1:\n         /* We can't invert the chromaticities so we can't produce value XYZ\n          * values.  Likely as not a color management system will fail too.\n          */\n         colorspace->flags |= PNG_COLORSPACE_INVALID;\n         png_benign_error(png_ptr, \"invalid chromaticities\");\n         break;\n\n      default:\n         /* libpng is broken; this should be a warning but if it happens we\n          * want error reports so for the moment it is an error.\n          */\n         colorspace->flags |= PNG_COLORSPACE_INVALID;\n         png_error(png_ptr, \"internal error checking chromaticities\");\n   }\n\n   return 0; /* failed */\n}\n\nint /* PRIVATE */\npng_colorspace_set_endpoints(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, const png_XYZ *XYZ_in, int preferred)\n{\n   png_XYZ XYZ = *XYZ_in;\n   png_xy xy;\n\n   switch (png_colorspace_check_XYZ(&xy, &XYZ))\n   {\n      case 0:\n         return png_colorspace_set_xy_and_XYZ(png_ptr, colorspace, &xy, &XYZ,\n             preferred);\n\n      case 1:\n         /* End points are invalid. */\n         colorspace->flags |= PNG_COLORSPACE_INVALID;\n         png_benign_error(png_ptr, \"invalid end points\");\n         break;\n\n      default:\n         colorspace->flags |= PNG_COLORSPACE_INVALID;\n         png_error(png_ptr, \"internal error checking chromaticities\");\n   }\n\n   return 0; /* failed */\n}\n\n#if defined(PNG_sRGB_SUPPORTED) || defined(PNG_iCCP_SUPPORTED)\n/* Error message generation */\nstatic char\npng_icc_tag_char(png_uint_32 byte)\n{\n   byte &= 0xff;\n   if (byte >= 32 && byte <= 126)\n      return (char)byte;\n   else\n      return '?';\n}\n\nstatic void\npng_icc_tag_name(char *name, png_uint_32 tag)\n{\n   name[0] = '\\'';\n   name[1] = png_icc_tag_char(tag >> 24);\n   name[2] = png_icc_tag_char(tag >> 16);\n   name[3] = png_icc_tag_char(tag >>  8);\n   name[4] = png_icc_tag_char(tag      );\n   name[5] = '\\'';\n}\n\nstatic int\nis_ICC_signature_char(png_alloc_size_t it)\n{\n   return it == 32 || (it >= 48 && it <= 57) || (it >= 65 && it <= 90) ||\n      (it >= 97 && it <= 122);\n}\n\nstatic int\nis_ICC_signature(png_alloc_size_t it)\n{\n   return is_ICC_signature_char(it >> 24) /* checks all the top bits */ &&\n      is_ICC_signature_char((it >> 16) & 0xff) &&\n      is_ICC_signature_char((it >> 8) & 0xff) &&\n      is_ICC_signature_char(it & 0xff);\n}\n\nstatic int\npng_icc_profile_error(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_alloc_size_t value, png_const_charp reason)\n{\n   size_t pos;\n   char message[196]; /* see below for calculation */\n\n   if (colorspace != NULL)\n      colorspace->flags |= PNG_COLORSPACE_INVALID;\n\n   pos = png_safecat(message, (sizeof message), 0, \"profile '\"); /* 9 chars */\n   pos = png_safecat(message, pos+79, pos, name); /* Truncate to 79 chars */\n   pos = png_safecat(message, (sizeof message), pos, \"': \"); /* +2 = 90 */\n   if (is_ICC_signature(value) != 0)\n   {\n      /* So 'value' is at most 4 bytes and the following cast is safe */\n      png_icc_tag_name(message+pos, (png_uint_32)value);\n      pos += 6; /* total +8; less than the else clause */\n      message[pos++] = ':';\n      message[pos++] = ' ';\n   }\n#  ifdef PNG_WARNINGS_SUPPORTED\n   else\n      {\n         char number[PNG_NUMBER_BUFFER_SIZE]; /* +24 = 114*/\n\n         pos = png_safecat(message, (sizeof message), pos,\n             png_format_number(number, number+(sizeof number),\n             PNG_NUMBER_FORMAT_x, value));\n         pos = png_safecat(message, (sizeof message), pos, \"h: \"); /*+2 = 116*/\n      }\n#  endif\n   /* The 'reason' is an arbitrary message, allow +79 maximum 195 */\n   pos = png_safecat(message, (sizeof message), pos, reason);\n   PNG_UNUSED(pos)\n\n   /* This is recoverable, but make it unconditionally an app_error on write to\n    * avoid writing invalid ICC profiles into PNG files (i.e., we handle them\n    * on read, with a warning, but on write unless the app turns off\n    * application errors the PNG won't be written.)\n    */\n   png_chunk_report(png_ptr, message,\n       (colorspace != NULL) ? PNG_CHUNK_ERROR : PNG_CHUNK_WRITE_ERROR);\n\n   return 0;\n}\n#endif /* sRGB || iCCP */\n\n#ifdef PNG_sRGB_SUPPORTED\nint /* PRIVATE */\npng_colorspace_set_sRGB(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    int intent)\n{\n   /* sRGB sets known gamma, end points and (from the chunk) intent. */\n   /* IMPORTANT: these are not necessarily the values found in an ICC profile\n    * because ICC profiles store values adapted to a D50 environment; it is\n    * expected that the ICC profile mediaWhitePointTag will be D50; see the\n    * checks and code elsewhere to understand this better.\n    *\n    * These XYZ values, which are accurate to 5dp, produce rgb to gray\n    * coefficients of (6968,23435,2366), which are reduced (because they add up\n    * to 32769 not 32768) to (6968,23434,2366).  These are the values that\n    * libpng has traditionally used (and are the best values given the 15bit\n    * algorithm used by the rgb to gray code.)\n    */\n   static const png_XYZ sRGB_XYZ = /* D65 XYZ (*not* the D50 adapted values!) */\n   {\n      /* color      X      Y      Z */\n      /* red   */ 41239, 21264,  1933,\n      /* green */ 35758, 71517, 11919,\n      /* blue  */ 18048,  7219, 95053\n   };\n\n   /* Do nothing if the colorspace is already invalidated. */\n   if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)\n      return 0;\n\n   /* Check the intent, then check for existing settings.  It is valid for the\n    * PNG file to have cHRM or gAMA chunks along with sRGB, but the values must\n    * be consistent with the correct values.  If, however, this function is\n    * called below because an iCCP chunk matches sRGB then it is quite\n    * conceivable that an older app recorded incorrect gAMA and cHRM because of\n    * an incorrect calculation based on the values in the profile - this does\n    * *not* invalidate the profile (though it still produces an error, which can\n    * be ignored.)\n    */\n   if (intent < 0 || intent >= PNG_sRGB_INTENT_LAST)\n      return png_icc_profile_error(png_ptr, colorspace, \"sRGB\",\n          (unsigned)intent, \"invalid sRGB rendering intent\");\n\n   if ((colorspace->flags & PNG_COLORSPACE_HAVE_INTENT) != 0 &&\n       colorspace->rendering_intent != intent)\n      return png_icc_profile_error(png_ptr, colorspace, \"sRGB\",\n         (unsigned)intent, \"inconsistent rendering intents\");\n\n   if ((colorspace->flags & PNG_COLORSPACE_FROM_sRGB) != 0)\n   {\n      png_benign_error(png_ptr, \"duplicate sRGB information ignored\");\n      return 0;\n   }\n\n   /* If the standard sRGB cHRM chunk does not match the one from the PNG file\n    * warn but overwrite the value with the correct one.\n    */\n   if ((colorspace->flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0 &&\n       !png_colorspace_endpoints_match(&sRGB_xy, &colorspace->end_points_xy,\n       100))\n      png_chunk_report(png_ptr, \"cHRM chunk does not match sRGB\",\n         PNG_CHUNK_ERROR);\n\n   /* This check is just done for the error reporting - the routine always\n    * returns true when the 'from' argument corresponds to sRGB (2).\n    */\n   (void)png_colorspace_check_gamma(png_ptr, colorspace, PNG_GAMMA_sRGB_INVERSE,\n       2/*from sRGB*/);\n\n   /* intent: bugs in GCC force 'int' to be used as the parameter type. */\n   colorspace->rendering_intent = (png_uint_16)intent;\n   colorspace->flags |= PNG_COLORSPACE_HAVE_INTENT;\n\n   /* endpoints */\n   colorspace->end_points_xy = sRGB_xy;\n   colorspace->end_points_XYZ = sRGB_XYZ;\n   colorspace->flags |=\n      (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB);\n\n   /* gamma */\n   colorspace->gamma = PNG_GAMMA_sRGB_INVERSE;\n   colorspace->flags |= PNG_COLORSPACE_HAVE_GAMMA;\n\n   /* Finally record that we have an sRGB profile */\n   colorspace->flags |=\n      (PNG_COLORSPACE_MATCHES_sRGB|PNG_COLORSPACE_FROM_sRGB);\n\n   return 1; /* set */\n}\n#endif /* sRGB */\n\n#ifdef PNG_iCCP_SUPPORTED\n/* Encoded value of D50 as an ICC XYZNumber.  From the ICC 2010 spec the value\n * is XYZ(0.9642,1.0,0.8249), which scales to:\n *\n *    (63189.8112, 65536, 54060.6464)\n */\nstatic const png_byte D50_nCIEXYZ[12] =\n   { 0x00, 0x00, 0xf6, 0xd6, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0xd3, 0x2d };\n\nstatic int /* bool */\nicc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_uint_32 profile_length)\n{\n   if (profile_length < 132)\n      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,\n          \"too short\");\n\n   return 1;\n}\n\n#ifdef PNG_READ_iCCP_SUPPORTED\nint /* PRIVATE */\npng_icc_check_length(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_uint_32 profile_length)\n{\n   if (!icc_check_length(png_ptr, colorspace, name, profile_length))\n      return 0;\n\n   /* This needs to be here because the 'normal' check is in\n    * png_decompress_chunk, yet this happens after the attempt to\n    * png_malloc_base the required data.  We only need this on read; on write\n    * the caller supplies the profile buffer so libpng doesn't allocate it.  See\n    * the call to icc_check_length below (the write case).\n    */\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n      else if (png_ptr->user_chunk_malloc_max > 0 &&\n               png_ptr->user_chunk_malloc_max < profile_length)\n         return png_icc_profile_error(png_ptr, colorspace, name, profile_length,\n             \"exceeds application limits\");\n#  elif PNG_USER_CHUNK_MALLOC_MAX > 0\n      else if (PNG_USER_CHUNK_MALLOC_MAX < profile_length)\n         return png_icc_profile_error(png_ptr, colorspace, name, profile_length,\n             \"exceeds libpng limits\");\n#  else /* !SET_USER_LIMITS */\n      /* This will get compiled out on all 32-bit and better systems. */\n      else if (PNG_SIZE_MAX < profile_length)\n         return png_icc_profile_error(png_ptr, colorspace, name, profile_length,\n             \"exceeds system limits\");\n#  endif /* !SET_USER_LIMITS */\n\n   return 1;\n}\n#endif /* READ_iCCP */\n\nint /* PRIVATE */\npng_icc_check_header(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_uint_32 profile_length,\n    png_const_bytep profile/* first 132 bytes only */, int color_type)\n{\n   png_uint_32 temp;\n\n   /* Length check; this cannot be ignored in this code because profile_length\n    * is used later to check the tag table, so even if the profile seems over\n    * long profile_length from the caller must be correct.  The caller can fix\n    * this up on read or write by just passing in the profile header length.\n    */\n   temp = png_get_uint_32(profile);\n   if (temp != profile_length)\n      return png_icc_profile_error(png_ptr, colorspace, name, temp,\n          \"length does not match profile\");\n\n   temp = (png_uint_32) (*(profile+8));\n   if (temp > 3 && (profile_length & 3))\n      return png_icc_profile_error(png_ptr, colorspace, name, profile_length,\n          \"invalid length\");\n\n   temp = png_get_uint_32(profile+128); /* tag count: 12 bytes/tag */\n   if (temp > 357913930 || /* (2^32-4-132)/12: maximum possible tag count */\n      profile_length < 132+12*temp) /* truncated tag table */\n      return png_icc_profile_error(png_ptr, colorspace, name, temp,\n          \"tag count too large\");\n\n   /* The 'intent' must be valid or we can't store it, ICC limits the intent to\n    * 16 bits.\n    */\n   temp = png_get_uint_32(profile+64);\n   if (temp >= 0xffff) /* The ICC limit */\n      return png_icc_profile_error(png_ptr, colorspace, name, temp,\n          \"invalid rendering intent\");\n\n   /* This is just a warning because the profile may be valid in future\n    * versions.\n    */\n   if (temp >= PNG_sRGB_INTENT_LAST)\n      (void)png_icc_profile_error(png_ptr, NULL, name, temp,\n          \"intent outside defined range\");\n\n   /* At this point the tag table can't be checked because it hasn't necessarily\n    * been loaded; however, various header fields can be checked.  These checks\n    * are for values permitted by the PNG spec in an ICC profile; the PNG spec\n    * restricts the profiles that can be passed in an iCCP chunk (they must be\n    * appropriate to processing PNG data!)\n    */\n\n   /* Data checks (could be skipped).  These checks must be independent of the\n    * version number; however, the version number doesn't accomodate changes in\n    * the header fields (just the known tags and the interpretation of the\n    * data.)\n    */\n   temp = png_get_uint_32(profile+36); /* signature 'ascp' */\n   if (temp != 0x61637370)\n      return png_icc_profile_error(png_ptr, colorspace, name, temp,\n          \"invalid signature\");\n\n   /* Currently the PCS illuminant/adopted white point (the computational\n    * white point) are required to be D50,\n    * however the profile contains a record of the illuminant so perhaps ICC\n    * expects to be able to change this in the future (despite the rationale in\n    * the introduction for using a fixed PCS adopted white.)  Consequently the\n    * following is just a warning.\n    */\n   if (memcmp(profile+68, D50_nCIEXYZ, 12) != 0)\n      (void)png_icc_profile_error(png_ptr, NULL, name, 0/*no tag value*/,\n          \"PCS illuminant is not D50\");\n\n   /* The PNG spec requires this:\n    * \"If the iCCP chunk is present, the image samples conform to the colour\n    * space represented by the embedded ICC profile as defined by the\n    * International Color Consortium [ICC]. The colour space of the ICC profile\n    * shall be an RGB colour space for colour images (PNG colour types 2, 3, and\n    * 6), or a greyscale colour space for greyscale images (PNG colour types 0\n    * and 4).\"\n    *\n    * This checking code ensures the embedded profile (on either read or write)\n    * conforms to the specification requirements.  Notice that an ICC 'gray'\n    * color-space profile contains the information to transform the monochrome\n    * data to XYZ or L*a*b (according to which PCS the profile uses) and this\n    * should be used in preference to the standard libpng K channel replication\n    * into R, G and B channels.\n    *\n    * Previously it was suggested that an RGB profile on grayscale data could be\n    * handled.  However it it is clear that using an RGB profile in this context\n    * must be an error - there is no specification of what it means.  Thus it is\n    * almost certainly more correct to ignore the profile.\n    */\n   temp = png_get_uint_32(profile+16); /* data colour space field */\n   switch (temp)\n   {\n      case 0x52474220: /* 'RGB ' */\n         if ((color_type & PNG_COLOR_MASK_COLOR) == 0)\n            return png_icc_profile_error(png_ptr, colorspace, name, temp,\n                \"RGB color space not permitted on grayscale PNG\");\n         break;\n\n      case 0x47524159: /* 'GRAY' */\n         if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n            return png_icc_profile_error(png_ptr, colorspace, name, temp,\n                \"Gray color space not permitted on RGB PNG\");\n         break;\n\n      default:\n         return png_icc_profile_error(png_ptr, colorspace, name, temp,\n             \"invalid ICC profile color space\");\n   }\n\n   /* It is up to the application to check that the profile class matches the\n    * application requirements; the spec provides no guidance, but it's pretty\n    * weird if the profile is not scanner ('scnr'), monitor ('mntr'), printer\n    * ('prtr') or 'spac' (for generic color spaces).  Issue a warning in these\n    * cases.  Issue an error for device link or abstract profiles - these don't\n    * contain the records necessary to transform the color-space to anything\n    * other than the target device (and not even that for an abstract profile).\n    * Profiles of these classes may not be embedded in images.\n    */\n   temp = png_get_uint_32(profile+12); /* profile/device class */\n   switch (temp)\n   {\n      case 0x73636e72: /* 'scnr' */\n      case 0x6d6e7472: /* 'mntr' */\n      case 0x70727472: /* 'prtr' */\n      case 0x73706163: /* 'spac' */\n         /* All supported */\n         break;\n\n      case 0x61627374: /* 'abst' */\n         /* May not be embedded in an image */\n         return png_icc_profile_error(png_ptr, colorspace, name, temp,\n             \"invalid embedded Abstract ICC profile\");\n\n      case 0x6c696e6b: /* 'link' */\n         /* DeviceLink profiles cannot be interpreted in a non-device specific\n          * fashion, if an app uses the AToB0Tag in the profile the results are\n          * undefined unless the result is sent to the intended device,\n          * therefore a DeviceLink profile should not be found embedded in a\n          * PNG.\n          */\n         return png_icc_profile_error(png_ptr, colorspace, name, temp,\n             \"unexpected DeviceLink ICC profile class\");\n\n      case 0x6e6d636c: /* 'nmcl' */\n         /* A NamedColor profile is also device specific, however it doesn't\n          * contain an AToB0 tag that is open to misinterpretation.  Almost\n          * certainly it will fail the tests below.\n          */\n         (void)png_icc_profile_error(png_ptr, NULL, name, temp,\n             \"unexpected NamedColor ICC profile class\");\n         break;\n\n      default:\n         /* To allow for future enhancements to the profile accept unrecognized\n          * profile classes with a warning, these then hit the test below on the\n          * tag content to ensure they are backward compatible with one of the\n          * understood profiles.\n          */\n         (void)png_icc_profile_error(png_ptr, NULL, name, temp,\n             \"unrecognized ICC profile class\");\n         break;\n   }\n\n   /* For any profile other than a device link one the PCS must be encoded\n    * either in XYZ or Lab.\n    */\n   temp = png_get_uint_32(profile+20);\n   switch (temp)\n   {\n      case 0x58595a20: /* 'XYZ ' */\n      case 0x4c616220: /* 'Lab ' */\n         break;\n\n      default:\n         return png_icc_profile_error(png_ptr, colorspace, name, temp,\n             \"unexpected ICC PCS encoding\");\n   }\n\n   return 1;\n}\n\nint /* PRIVATE */\npng_icc_check_tag_table(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_uint_32 profile_length,\n    png_const_bytep profile /* header plus whole tag table */)\n{\n   png_uint_32 tag_count = png_get_uint_32(profile+128);\n   png_uint_32 itag;\n   png_const_bytep tag = profile+132; /* The first tag */\n\n   /* First scan all the tags in the table and add bits to the icc_info value\n    * (temporarily in 'tags').\n    */\n   for (itag=0; itag < tag_count; ++itag, tag += 12)\n   {\n      png_uint_32 tag_id = png_get_uint_32(tag+0);\n      png_uint_32 tag_start = png_get_uint_32(tag+4); /* must be aligned */\n      png_uint_32 tag_length = png_get_uint_32(tag+8);/* not padded */\n\n      /* The ICC specification does not exclude zero length tags, therefore the\n       * start might actually be anywhere if there is no data, but this would be\n       * a clear abuse of the intent of the standard so the start is checked for\n       * being in range.  All defined tag types have an 8 byte header - a 4 byte\n       * type signature then 0.\n       */\n      if ((tag_start & 3) != 0)\n      {\n         /* CNHP730S.icc shipped with Microsoft Windows 64 violates this, it is\n          * only a warning here because libpng does not care about the\n          * alignment.\n          */\n         (void)png_icc_profile_error(png_ptr, NULL, name, tag_id,\n             \"ICC profile tag start not a multiple of 4\");\n      }\n\n      /* This is a hard error; potentially it can cause read outside the\n       * profile.\n       */\n      if (tag_start > profile_length || tag_length > profile_length - tag_start)\n         return png_icc_profile_error(png_ptr, colorspace, name, tag_id,\n             \"ICC profile tag outside profile\");\n   }\n\n   return 1; /* success, maybe with warnings */\n}\n\n#ifdef PNG_sRGB_SUPPORTED\n#if PNG_sRGB_PROFILE_CHECKS >= 0\n/* Information about the known ICC sRGB profiles */\nstatic const struct\n{\n   png_uint_32 adler, crc, length;\n   png_uint_32 md5[4];\n   png_byte    have_md5;\n   png_byte    is_broken;\n   png_uint_16 intent;\n\n#  define PNG_MD5(a,b,c,d) { a, b, c, d }, (a!=0)||(b!=0)||(c!=0)||(d!=0)\n#  define PNG_ICC_CHECKSUM(adler, crc, md5, intent, broke, date, length, fname)\\\n      { adler, crc, length, md5, broke, intent },\n\n} png_sRGB_checks[] =\n{\n   /* This data comes from contrib/tools/checksum-icc run on downloads of\n    * all four ICC sRGB profiles from www.color.org.\n    */\n   /* adler32, crc32, MD5[4], intent, date, length, file-name */\n   PNG_ICC_CHECKSUM(0x0a3fd9f6, 0x3b8772b9,\n       PNG_MD5(0x29f83dde, 0xaff255ae, 0x7842fae4, 0xca83390d), 0, 0,\n       \"2009/03/27 21:36:31\", 3048, \"sRGB_IEC61966-2-1_black_scaled.icc\")\n\n   /* ICC sRGB v2 perceptual no black-compensation: */\n   PNG_ICC_CHECKSUM(0x4909e5e1, 0x427ebb21,\n       PNG_MD5(0xc95bd637, 0xe95d8a3b, 0x0df38f99, 0xc1320389), 1, 0,\n       \"2009/03/27 21:37:45\", 3052, \"sRGB_IEC61966-2-1_no_black_scaling.icc\")\n\n   PNG_ICC_CHECKSUM(0xfd2144a1, 0x306fd8ae,\n       PNG_MD5(0xfc663378, 0x37e2886b, 0xfd72e983, 0x8228f1b8), 0, 0,\n       \"2009/08/10 17:28:01\", 60988, \"sRGB_v4_ICC_preference_displayclass.icc\")\n\n   /* ICC sRGB v4 perceptual */\n   PNG_ICC_CHECKSUM(0x209c35d2, 0xbbef7812,\n       PNG_MD5(0x34562abf, 0x994ccd06, 0x6d2c5721, 0xd0d68c5d), 0, 0,\n       \"2007/07/25 00:05:37\", 60960, \"sRGB_v4_ICC_preference.icc\")\n\n   /* The following profiles have no known MD5 checksum. If there is a match\n    * on the (empty) MD5 the other fields are used to attempt a match and\n    * a warning is produced.  The first two of these profiles have a 'cprt' tag\n    * which suggests that they were also made by Hewlett Packard.\n    */\n   PNG_ICC_CHECKSUM(0xa054d762, 0x5d5129ce,\n       PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 0,\n       \"2004/07/21 18:57:42\", 3024, \"sRGB_IEC61966-2-1_noBPC.icc\")\n\n   /* This is a 'mntr' (display) profile with a mediaWhitePointTag that does not\n    * match the D50 PCS illuminant in the header (it is in fact the D65 values,\n    * so the white point is recorded as the un-adapted value.)  The profiles\n    * below only differ in one byte - the intent - and are basically the same as\n    * the previous profile except for the mediaWhitePointTag error and a missing\n    * chromaticAdaptationTag.\n    */\n   PNG_ICC_CHECKSUM(0xf784f3fb, 0x182ea552,\n       PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 0, 1/*broken*/,\n       \"1998/02/09 06:49:00\", 3144, \"HP-Microsoft sRGB v2 perceptual\")\n\n   PNG_ICC_CHECKSUM(0x0398f3fc, 0xf29e526d,\n       PNG_MD5(0x00000000, 0x00000000, 0x00000000, 0x00000000), 1, 1/*broken*/,\n       \"1998/02/09 06:49:00\", 3144, \"HP-Microsoft sRGB v2 media-relative\")\n};\n\nstatic int\npng_compare_ICC_profile_with_sRGB(png_const_structrp png_ptr,\n    png_const_bytep profile, uLong adler)\n{\n   /* The quick check is to verify just the MD5 signature and trust the\n    * rest of the data.  Because the profile has already been verified for\n    * correctness this is safe.  png_colorspace_set_sRGB will check the 'intent'\n    * field too, so if the profile has been edited with an intent not defined\n    * by sRGB (but maybe defined by a later ICC specification) the read of\n    * the profile will fail at that point.\n    */\n\n   png_uint_32 length = 0;\n   png_uint_32 intent = 0x10000; /* invalid */\n#if PNG_sRGB_PROFILE_CHECKS > 1\n   uLong crc = 0; /* the value for 0 length data */\n#endif\n   unsigned int i;\n\n#ifdef PNG_SET_OPTION_SUPPORTED\n   /* First see if PNG_SKIP_sRGB_CHECK_PROFILE has been set to \"on\" */\n   if (((png_ptr->options >> PNG_SKIP_sRGB_CHECK_PROFILE) & 3) ==\n               PNG_OPTION_ON)\n      return 0;\n#endif\n\n   for (i=0; i < (sizeof png_sRGB_checks) / (sizeof png_sRGB_checks[0]); ++i)\n   {\n      if (png_get_uint_32(profile+84) == png_sRGB_checks[i].md5[0] &&\n         png_get_uint_32(profile+88) == png_sRGB_checks[i].md5[1] &&\n         png_get_uint_32(profile+92) == png_sRGB_checks[i].md5[2] &&\n         png_get_uint_32(profile+96) == png_sRGB_checks[i].md5[3])\n      {\n         /* This may be one of the old HP profiles without an MD5, in that\n          * case we can only use the length and Adler32 (note that these\n          * are not used by default if there is an MD5!)\n          */\n#        if PNG_sRGB_PROFILE_CHECKS == 0\n            if (png_sRGB_checks[i].have_md5 != 0)\n               return 1+png_sRGB_checks[i].is_broken;\n#        endif\n\n         /* Profile is unsigned or more checks have been configured in. */\n         if (length == 0)\n         {\n            length = png_get_uint_32(profile);\n            intent = png_get_uint_32(profile+64);\n         }\n\n         /* Length *and* intent must match */\n         if (length == (png_uint_32) png_sRGB_checks[i].length &&\n            intent == (png_uint_32) png_sRGB_checks[i].intent)\n         {\n            /* Now calculate the adler32 if not done already. */\n            if (adler == 0)\n            {\n               adler = adler32(0, NULL, 0);\n               adler = adler32(adler, profile, length);\n            }\n\n            if (adler == png_sRGB_checks[i].adler)\n            {\n               /* These basic checks suggest that the data has not been\n                * modified, but if the check level is more than 1 perform\n                * our own crc32 checksum on the data.\n                */\n#              if PNG_sRGB_PROFILE_CHECKS > 1\n                  if (crc == 0)\n                  {\n                     crc = crc32(0, NULL, 0);\n                     crc = crc32(crc, profile, length);\n                  }\n\n                  /* So this check must pass for the 'return' below to happen.\n                   */\n                  if (crc == png_sRGB_checks[i].crc)\n#              endif\n               {\n                  if (png_sRGB_checks[i].is_broken != 0)\n                  {\n                     /* These profiles are known to have bad data that may cause\n                      * problems if they are used, therefore attempt to\n                      * discourage their use, skip the 'have_md5' warning below,\n                      * which is made irrelevant by this error.\n                      */\n                     png_chunk_report(png_ptr, \"known incorrect sRGB profile\",\n                         PNG_CHUNK_ERROR);\n                  }\n\n                  /* Warn that this being done; this isn't even an error since\n                   * the profile is perfectly valid, but it would be nice if\n                   * people used the up-to-date ones.\n                   */\n                  else if (png_sRGB_checks[i].have_md5 == 0)\n                  {\n                     png_chunk_report(png_ptr,\n                         \"out-of-date sRGB profile with no signature\",\n                         PNG_CHUNK_WARNING);\n                  }\n\n                  return 1+png_sRGB_checks[i].is_broken;\n               }\n            }\n\n# if PNG_sRGB_PROFILE_CHECKS > 0\n         /* The signature matched, but the profile had been changed in some\n          * way.  This probably indicates a data error or uninformed hacking.\n          * Fall through to \"no match\".\n          */\n         png_chunk_report(png_ptr,\n             \"Not recognizing known sRGB profile that has been edited\",\n             PNG_CHUNK_WARNING);\n         break;\n# endif\n         }\n      }\n   }\n\n   return 0; /* no match */\n}\n\nvoid /* PRIVATE */\npng_icc_set_sRGB(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, png_const_bytep profile, uLong adler)\n{\n   /* Is this profile one of the known ICC sRGB profiles?  If it is, just set\n    * the sRGB information.\n    */\n   if (png_compare_ICC_profile_with_sRGB(png_ptr, profile, adler) != 0)\n      (void)png_colorspace_set_sRGB(png_ptr, colorspace,\n         (int)/*already checked*/png_get_uint_32(profile+64));\n}\n#endif /* PNG_sRGB_PROFILE_CHECKS >= 0 */\n#endif /* sRGB */\n\nint /* PRIVATE */\npng_colorspace_set_ICC(png_const_structrp png_ptr, png_colorspacerp colorspace,\n    png_const_charp name, png_uint_32 profile_length, png_const_bytep profile,\n    int color_type)\n{\n   if ((colorspace->flags & PNG_COLORSPACE_INVALID) != 0)\n      return 0;\n\n   if (icc_check_length(png_ptr, colorspace, name, profile_length) != 0 &&\n       png_icc_check_header(png_ptr, colorspace, name, profile_length, profile,\n           color_type) != 0 &&\n       png_icc_check_tag_table(png_ptr, colorspace, name, profile_length,\n           profile) != 0)\n   {\n#     if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0\n         /* If no sRGB support, don't try storing sRGB information */\n         png_icc_set_sRGB(png_ptr, colorspace, profile, 0);\n#     endif\n      return 1;\n   }\n\n   /* Failure case */\n   return 0;\n}\n#endif /* iCCP */\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\nvoid /* PRIVATE */\npng_colorspace_set_rgb_coefficients(png_structrp png_ptr)\n{\n   /* Set the rgb_to_gray coefficients from the colorspace. */\n   if (png_ptr->rgb_to_gray_coefficients_set == 0 &&\n      (png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      /* png_set_background has not been called, get the coefficients from the Y\n       * values of the colorspace colorants.\n       */\n      png_fixed_point r = png_ptr->colorspace.end_points_XYZ.red_Y;\n      png_fixed_point g = png_ptr->colorspace.end_points_XYZ.green_Y;\n      png_fixed_point b = png_ptr->colorspace.end_points_XYZ.blue_Y;\n      png_fixed_point total = r+g+b;\n\n      if (total > 0 &&\n         r >= 0 && png_muldiv(&r, r, 32768, total) && r >= 0 && r <= 32768 &&\n         g >= 0 && png_muldiv(&g, g, 32768, total) && g >= 0 && g <= 32768 &&\n         b >= 0 && png_muldiv(&b, b, 32768, total) && b >= 0 && b <= 32768 &&\n         r+g+b <= 32769)\n      {\n         /* We allow 0 coefficients here.  r+g+b may be 32769 if two or\n          * all of the coefficients were rounded up.  Handle this by\n          * reducing the *largest* coefficient by 1; this matches the\n          * approach used for the default coefficients in pngrtran.c\n          */\n         int add = 0;\n\n         if (r+g+b > 32768)\n            add = -1;\n         else if (r+g+b < 32768)\n            add = 1;\n\n         if (add != 0)\n         {\n            if (g >= r && g >= b)\n               g += add;\n            else if (r >= g && r >= b)\n               r += add;\n            else\n               b += add;\n         }\n\n         /* Check for an internal error. */\n         if (r+g+b != 32768)\n            png_error(png_ptr,\n                \"internal error handling cHRM coefficients\");\n\n         else\n         {\n            png_ptr->rgb_to_gray_red_coeff   = (png_uint_16)r;\n            png_ptr->rgb_to_gray_green_coeff = (png_uint_16)g;\n         }\n      }\n\n      /* This is a png_error at present even though it could be ignored -\n       * it should never happen, but it is important that if it does, the\n       * bug is fixed.\n       */\n      else\n         png_error(png_ptr, \"internal error handling cHRM->XYZ\");\n   }\n}\n#endif /* READ_RGB_TO_GRAY */\n\n#endif /* COLORSPACE */\n\n#ifdef __GNUC__\n/* This exists solely to work round a warning from GNU C. */\nstatic int /* PRIVATE */\npng_gt(size_t a, size_t b)\n{\n   return a > b;\n}\n#else\n#   define png_gt(a,b) ((a) > (b))\n#endif\n\nvoid /* PRIVATE */\npng_check_IHDR(png_const_structrp png_ptr,\n    png_uint_32 width, png_uint_32 height, int bit_depth,\n    int color_type, int interlace_type, int compression_type,\n    int filter_type)\n{\n   int error = 0;\n\n   /* Check for width and height valid values */\n   if (width == 0)\n   {\n      png_warning(png_ptr, \"Image width is zero in IHDR\");\n      error = 1;\n   }\n\n   if (width > PNG_UINT_31_MAX)\n   {\n      png_warning(png_ptr, \"Invalid image width in IHDR\");\n      error = 1;\n   }\n\n   if (png_gt(((width + 7) & (~7)),\n       ((PNG_SIZE_MAX\n           - 48        /* big_row_buf hack */\n           - 1)        /* filter byte */\n           / 8)        /* 8-byte RGBA pixels */\n           - 1))       /* extra max_pixel_depth pad */\n   {\n      /* The size of the row must be within the limits of this architecture.\n       * Because the read code can perform arbitrary transformations the\n       * maximum size is checked here.  Because the code in png_read_start_row\n       * adds extra space \"for safety's sake\" in several places a conservative\n       * limit is used here.\n       *\n       * NOTE: it would be far better to check the size that is actually used,\n       * but the effect in the real world is minor and the changes are more\n       * extensive, therefore much more dangerous and much more difficult to\n       * write in a way that avoids compiler warnings.\n       */\n      png_warning(png_ptr, \"Image width is too large for this architecture\");\n      error = 1;\n   }\n\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\n   if (width > png_ptr->user_width_max)\n#else\n   if (width > PNG_USER_WIDTH_MAX)\n#endif\n   {\n      png_warning(png_ptr, \"Image width exceeds user limit in IHDR\");\n      error = 1;\n   }\n\n   if (height == 0)\n   {\n      png_warning(png_ptr, \"Image height is zero in IHDR\");\n      error = 1;\n   }\n\n   if (height > PNG_UINT_31_MAX)\n   {\n      png_warning(png_ptr, \"Invalid image height in IHDR\");\n      error = 1;\n   }\n\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\n   if (height > png_ptr->user_height_max)\n#else\n   if (height > PNG_USER_HEIGHT_MAX)\n#endif\n   {\n      png_warning(png_ptr, \"Image height exceeds user limit in IHDR\");\n      error = 1;\n   }\n\n   /* Check other values */\n   if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&\n       bit_depth != 8 && bit_depth != 16)\n   {\n      png_warning(png_ptr, \"Invalid bit depth in IHDR\");\n      error = 1;\n   }\n\n   if (color_type < 0 || color_type == 1 ||\n       color_type == 5 || color_type > 6)\n   {\n      png_warning(png_ptr, \"Invalid color type in IHDR\");\n      error = 1;\n   }\n\n   if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||\n       ((color_type == PNG_COLOR_TYPE_RGB ||\n         color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||\n         color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))\n   {\n      png_warning(png_ptr, \"Invalid color type/bit depth combination in IHDR\");\n      error = 1;\n   }\n\n   if (interlace_type >= PNG_INTERLACE_LAST)\n   {\n      png_warning(png_ptr, \"Unknown interlace method in IHDR\");\n      error = 1;\n   }\n\n   if (compression_type != PNG_COMPRESSION_TYPE_BASE)\n   {\n      png_warning(png_ptr, \"Unknown compression method in IHDR\");\n      error = 1;\n   }\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   /* Accept filter_method 64 (intrapixel differencing) only if\n    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and\n    * 2. Libpng did not read a PNG signature (this filter_method is only\n    *    used in PNG datastreams that are embedded in MNG datastreams) and\n    * 3. The application called png_permit_mng_features with a mask that\n    *    included PNG_FLAG_MNG_FILTER_64 and\n    * 4. The filter_method is 64 and\n    * 5. The color_type is RGB or RGBA\n    */\n   if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 &&\n       png_ptr->mng_features_permitted != 0)\n      png_warning(png_ptr, \"MNG features are not allowed in a PNG datastream\");\n\n   if (filter_type != PNG_FILTER_TYPE_BASE)\n   {\n      if (!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&\n          (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&\n          ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&\n          (color_type == PNG_COLOR_TYPE_RGB ||\n          color_type == PNG_COLOR_TYPE_RGB_ALPHA)))\n      {\n         png_warning(png_ptr, \"Unknown filter method in IHDR\");\n         error = 1;\n      }\n\n      if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0)\n      {\n         png_warning(png_ptr, \"Invalid filter method in IHDR\");\n         error = 1;\n      }\n   }\n\n#else\n   if (filter_type != PNG_FILTER_TYPE_BASE)\n   {\n      png_warning(png_ptr, \"Unknown filter method in IHDR\");\n      error = 1;\n   }\n#endif\n\n   if (error == 1)\n      png_error(png_ptr, \"Invalid IHDR data\");\n}\n\n#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)\n/* ASCII to fp functions */\n/* Check an ASCII formated floating point value, see the more detailed\n * comments in pngpriv.h\n */\n/* The following is used internally to preserve the sticky flags */\n#define png_fp_add(state, flags) ((state) |= (flags))\n#define png_fp_set(state, value) ((state) = (value) | ((state) & PNG_FP_STICKY))\n\nint /* PRIVATE */\npng_check_fp_number(png_const_charp string, png_size_t size, int *statep,\n    png_size_tp whereami)\n{\n   int state = *statep;\n   png_size_t i = *whereami;\n\n   while (i < size)\n   {\n      int type;\n      /* First find the type of the next character */\n      switch (string[i])\n      {\n      case 43:  type = PNG_FP_SAW_SIGN;                   break;\n      case 45:  type = PNG_FP_SAW_SIGN + PNG_FP_NEGATIVE; break;\n      case 46:  type = PNG_FP_SAW_DOT;                    break;\n      case 48:  type = PNG_FP_SAW_DIGIT;                  break;\n      case 49: case 50: case 51: case 52:\n      case 53: case 54: case 55: case 56:\n      case 57:  type = PNG_FP_SAW_DIGIT + PNG_FP_NONZERO; break;\n      case 69:\n      case 101: type = PNG_FP_SAW_E;                      break;\n      default:  goto PNG_FP_End;\n      }\n\n      /* Now deal with this type according to the current\n       * state, the type is arranged to not overlap the\n       * bits of the PNG_FP_STATE.\n       */\n      switch ((state & PNG_FP_STATE) + (type & PNG_FP_SAW_ANY))\n      {\n      case PNG_FP_INTEGER + PNG_FP_SAW_SIGN:\n         if ((state & PNG_FP_SAW_ANY) != 0)\n            goto PNG_FP_End; /* not a part of the number */\n\n         png_fp_add(state, type);\n         break;\n\n      case PNG_FP_INTEGER + PNG_FP_SAW_DOT:\n         /* Ok as trailer, ok as lead of fraction. */\n         if ((state & PNG_FP_SAW_DOT) != 0) /* two dots */\n            goto PNG_FP_End;\n\n         else if ((state & PNG_FP_SAW_DIGIT) != 0) /* trailing dot? */\n            png_fp_add(state, type);\n\n         else\n            png_fp_set(state, PNG_FP_FRACTION | type);\n\n         break;\n\n      case PNG_FP_INTEGER + PNG_FP_SAW_DIGIT:\n         if ((state & PNG_FP_SAW_DOT) != 0) /* delayed fraction */\n            png_fp_set(state, PNG_FP_FRACTION | PNG_FP_SAW_DOT);\n\n         png_fp_add(state, type | PNG_FP_WAS_VALID);\n\n         break;\n\n      case PNG_FP_INTEGER + PNG_FP_SAW_E:\n         if ((state & PNG_FP_SAW_DIGIT) == 0)\n            goto PNG_FP_End;\n\n         png_fp_set(state, PNG_FP_EXPONENT);\n\n         break;\n\n   /* case PNG_FP_FRACTION + PNG_FP_SAW_SIGN:\n         goto PNG_FP_End; ** no sign in fraction */\n\n   /* case PNG_FP_FRACTION + PNG_FP_SAW_DOT:\n         goto PNG_FP_End; ** Because SAW_DOT is always set */\n\n      case PNG_FP_FRACTION + PNG_FP_SAW_DIGIT:\n         png_fp_add(state, type | PNG_FP_WAS_VALID);\n         break;\n\n      case PNG_FP_FRACTION + PNG_FP_SAW_E:\n         /* This is correct because the trailing '.' on an\n          * integer is handled above - so we can only get here\n          * with the sequence \".E\" (with no preceding digits).\n          */\n         if ((state & PNG_FP_SAW_DIGIT) == 0)\n            goto PNG_FP_End;\n\n         png_fp_set(state, PNG_FP_EXPONENT);\n\n         break;\n\n      case PNG_FP_EXPONENT + PNG_FP_SAW_SIGN:\n         if ((state & PNG_FP_SAW_ANY) != 0)\n            goto PNG_FP_End; /* not a part of the number */\n\n         png_fp_add(state, PNG_FP_SAW_SIGN);\n\n         break;\n\n   /* case PNG_FP_EXPONENT + PNG_FP_SAW_DOT:\n         goto PNG_FP_End; */\n\n      case PNG_FP_EXPONENT + PNG_FP_SAW_DIGIT:\n         png_fp_add(state, PNG_FP_SAW_DIGIT | PNG_FP_WAS_VALID);\n\n         break;\n\n   /* case PNG_FP_EXPONEXT + PNG_FP_SAW_E:\n         goto PNG_FP_End; */\n\n      default: goto PNG_FP_End; /* I.e. break 2 */\n      }\n\n      /* The character seems ok, continue. */\n      ++i;\n   }\n\nPNG_FP_End:\n   /* Here at the end, update the state and return the correct\n    * return code.\n    */\n   *statep = state;\n   *whereami = i;\n\n   return (state & PNG_FP_SAW_DIGIT) != 0;\n}\n\n\n/* The same but for a complete string. */\nint\npng_check_fp_string(png_const_charp string, png_size_t size)\n{\n   int        state=0;\n   png_size_t char_index=0;\n\n   if (png_check_fp_number(string, size, &state, &char_index) != 0 &&\n      (char_index == size || string[char_index] == 0))\n      return state /* must be non-zero - see above */;\n\n   return 0; /* i.e. fail */\n}\n#endif /* pCAL || sCAL */\n\n#ifdef PNG_sCAL_SUPPORTED\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\n/* Utility used below - a simple accurate power of ten from an integral\n * exponent.\n */\nstatic double\npng_pow10(int power)\n{\n   int recip = 0;\n   double d = 1;\n\n   /* Handle negative exponent with a reciprocal at the end because\n    * 10 is exact whereas .1 is inexact in base 2\n    */\n   if (power < 0)\n   {\n      if (power < DBL_MIN_10_EXP) return 0;\n      recip = 1, power = -power;\n   }\n\n   if (power > 0)\n   {\n      /* Decompose power bitwise. */\n      double mult = 10;\n      do\n      {\n         if (power & 1) d *= mult;\n         mult *= mult;\n         power >>= 1;\n      }\n      while (power > 0);\n\n      if (recip != 0) d = 1/d;\n   }\n   /* else power is 0 and d is 1 */\n\n   return d;\n}\n\n/* Function to format a floating point value in ASCII with a given\n * precision.\n */\nvoid /* PRIVATE */\npng_ascii_from_fp(png_const_structrp png_ptr, png_charp ascii, png_size_t size,\n    double fp, unsigned int precision)\n{\n   /* We use standard functions from math.h, but not printf because\n    * that would require stdio.  The caller must supply a buffer of\n    * sufficient size or we will png_error.  The tests on size and\n    * the space in ascii[] consumed are indicated below.\n    */\n   if (precision < 1)\n      precision = DBL_DIG;\n\n   /* Enforce the limit of the implementation precision too. */\n   if (precision > DBL_DIG+1)\n      precision = DBL_DIG+1;\n\n   /* Basic sanity checks */\n   if (size >= precision+5) /* See the requirements below. */\n   {\n      if (fp < 0)\n      {\n         fp = -fp;\n         *ascii++ = 45; /* '-'  PLUS 1 TOTAL 1 */\n         --size;\n      }\n\n      if (fp >= DBL_MIN && fp <= DBL_MAX)\n      {\n         int exp_b10;   /* A base 10 exponent */\n         double base;   /* 10^exp_b10 */\n\n         /* First extract a base 10 exponent of the number,\n          * the calculation below rounds down when converting\n          * from base 2 to base 10 (multiply by log10(2) -\n          * 0.3010, but 77/256 is 0.3008, so exp_b10 needs to\n          * be increased.  Note that the arithmetic shift\n          * performs a floor() unlike C arithmetic - using a\n          * C multiply would break the following for negative\n          * exponents.\n          */\n         (void)frexp(fp, &exp_b10); /* exponent to base 2 */\n\n         exp_b10 = (exp_b10 * 77) >> 8; /* <= exponent to base 10 */\n\n         /* Avoid underflow here. */\n         base = png_pow10(exp_b10); /* May underflow */\n\n         while (base < DBL_MIN || base < fp)\n         {\n            /* And this may overflow. */\n            double test = png_pow10(exp_b10+1);\n\n            if (test <= DBL_MAX)\n               ++exp_b10, base = test;\n\n            else\n               break;\n         }\n\n         /* Normalize fp and correct exp_b10, after this fp is in the\n          * range [.1,1) and exp_b10 is both the exponent and the digit\n          * *before* which the decimal point should be inserted\n          * (starting with 0 for the first digit).  Note that this\n          * works even if 10^exp_b10 is out of range because of the\n          * test on DBL_MAX above.\n          */\n         fp /= base;\n         while (fp >= 1) fp /= 10, ++exp_b10;\n\n         /* Because of the code above fp may, at this point, be\n          * less than .1, this is ok because the code below can\n          * handle the leading zeros this generates, so no attempt\n          * is made to correct that here.\n          */\n\n         {\n            unsigned int czero, clead, cdigits;\n            char exponent[10];\n\n            /* Allow up to two leading zeros - this will not lengthen\n             * the number compared to using E-n.\n             */\n            if (exp_b10 < 0 && exp_b10 > -3) /* PLUS 3 TOTAL 4 */\n            {\n               czero = -exp_b10; /* PLUS 2 digits: TOTAL 3 */\n               exp_b10 = 0;      /* Dot added below before first output. */\n            }\n            else\n               czero = 0;    /* No zeros to add */\n\n            /* Generate the digit list, stripping trailing zeros and\n             * inserting a '.' before a digit if the exponent is 0.\n             */\n            clead = czero; /* Count of leading zeros */\n            cdigits = 0;   /* Count of digits in list. */\n\n            do\n            {\n               double d;\n\n               fp *= 10;\n               /* Use modf here, not floor and subtract, so that\n                * the separation is done in one step.  At the end\n                * of the loop don't break the number into parts so\n                * that the final digit is rounded.\n                */\n               if (cdigits+czero+1 < precision+clead)\n                  fp = modf(fp, &d);\n\n               else\n               {\n                  d = floor(fp + .5);\n\n                  if (d > 9)\n                  {\n                     /* Rounding up to 10, handle that here. */\n                     if (czero > 0)\n                     {\n                        --czero, d = 1;\n                        if (cdigits == 0) --clead;\n                     }\n                     else\n                     {\n                        while (cdigits > 0 && d > 9)\n                        {\n                           int ch = *--ascii;\n\n                           if (exp_b10 != (-1))\n                              ++exp_b10;\n\n                           else if (ch == 46)\n                           {\n                              ch = *--ascii, ++size;\n                              /* Advance exp_b10 to '1', so that the\n                               * decimal point happens after the\n                               * previous digit.\n                               */\n                              exp_b10 = 1;\n                           }\n\n                           --cdigits;\n                           d = ch - 47;  /* I.e. 1+(ch-48) */\n                        }\n\n                        /* Did we reach the beginning? If so adjust the\n                         * exponent but take into account the leading\n                         * decimal point.\n                         */\n                        if (d > 9)  /* cdigits == 0 */\n                        {\n                           if (exp_b10 == (-1))\n                           {\n                              /* Leading decimal point (plus zeros?), if\n                               * we lose the decimal point here it must\n                               * be reentered below.\n                               */\n                              int ch = *--ascii;\n\n                              if (ch == 46)\n                                 ++size, exp_b10 = 1;\n\n                              /* Else lost a leading zero, so 'exp_b10' is\n                               * still ok at (-1)\n                               */\n                           }\n                           else\n                              ++exp_b10;\n\n                           /* In all cases we output a '1' */\n                           d = 1;\n                        }\n                     }\n                  }\n                  fp = 0; /* Guarantees termination below. */\n               }\n\n               if (d == 0)\n               {\n                  ++czero;\n                  if (cdigits == 0) ++clead;\n               }\n               else\n               {\n                  /* Included embedded zeros in the digit count. */\n                  cdigits += czero - clead;\n                  clead = 0;\n\n                  while (czero > 0)\n                  {\n                     /* exp_b10 == (-1) means we just output the decimal\n                      * place - after the DP don't adjust 'exp_b10' any\n                      * more!\n                      */\n                     if (exp_b10 != (-1))\n                     {\n                        if (exp_b10 == 0) *ascii++ = 46, --size;\n                        /* PLUS 1: TOTAL 4 */\n                        --exp_b10;\n                     }\n                     *ascii++ = 48, --czero;\n                  }\n\n                  if (exp_b10 != (-1))\n                  {\n                     if (exp_b10 == 0)\n                        *ascii++ = 46, --size; /* counted above */\n\n                     --exp_b10;\n                  }\n                  *ascii++ = (char)(48 + (int)d), ++cdigits;\n               }\n            }\n            while (cdigits+czero < precision+clead && fp > DBL_MIN);\n\n            /* The total output count (max) is now 4+precision */\n\n            /* Check for an exponent, if we don't need one we are\n             * done and just need to terminate the string.  At\n             * this point exp_b10==(-1) is effectively if flag - it got\n             * to '-1' because of the decrement after outputting\n             * the decimal point above (the exponent required is\n             * *not* -1!)\n             */\n            if (exp_b10 >= (-1) && exp_b10 <= 2)\n            {\n               /* The following only happens if we didn't output the\n                * leading zeros above for negative exponent, so this\n                * doesn't add to the digit requirement.  Note that the\n                * two zeros here can only be output if the two leading\n                * zeros were *not* output, so this doesn't increase\n                * the output count.\n                */\n               while (--exp_b10 >= 0) *ascii++ = 48;\n\n               *ascii = 0;\n\n               /* Total buffer requirement (including the '\\0') is\n                * 5+precision - see check at the start.\n                */\n               return;\n            }\n\n            /* Here if an exponent is required, adjust size for\n             * the digits we output but did not count.  The total\n             * digit output here so far is at most 1+precision - no\n             * decimal point and no leading or trailing zeros have\n             * been output.\n             */\n            size -= cdigits;\n\n            *ascii++ = 69, --size;    /* 'E': PLUS 1 TOTAL 2+precision */\n\n            /* The following use of an unsigned temporary avoids ambiguities in\n             * the signed arithmetic on exp_b10 and permits GCC at least to do\n             * better optimization.\n             */\n            {\n               unsigned int uexp_b10;\n\n               if (exp_b10 < 0)\n               {\n                  *ascii++ = 45, --size; /* '-': PLUS 1 TOTAL 3+precision */\n                  uexp_b10 = -exp_b10;\n               }\n\n               else\n                  uexp_b10 = exp_b10;\n\n               cdigits = 0;\n\n               while (uexp_b10 > 0)\n               {\n                  exponent[cdigits++] = (char)(48 + uexp_b10 % 10);\n                  uexp_b10 /= 10;\n               }\n            }\n\n            /* Need another size check here for the exponent digits, so\n             * this need not be considered above.\n             */\n            if (size > cdigits)\n            {\n               while (cdigits > 0) *ascii++ = exponent[--cdigits];\n\n               *ascii = 0;\n\n               return;\n            }\n         }\n      }\n      else if (!(fp >= DBL_MIN))\n      {\n         *ascii++ = 48; /* '0' */\n         *ascii = 0;\n         return;\n      }\n      else\n      {\n         *ascii++ = 105; /* 'i' */\n         *ascii++ = 110; /* 'n' */\n         *ascii++ = 102; /* 'f' */\n         *ascii = 0;\n         return;\n      }\n   }\n\n   /* Here on buffer too small. */\n   png_error(png_ptr, \"ASCII conversion buffer too small\");\n}\n\n#  endif /* FLOATING_POINT */\n\n#  ifdef PNG_FIXED_POINT_SUPPORTED\n/* Function to format a fixed point value in ASCII.\n */\nvoid /* PRIVATE */\npng_ascii_from_fixed(png_const_structrp png_ptr, png_charp ascii,\n    png_size_t size, png_fixed_point fp)\n{\n   /* Require space for 10 decimal digits, a decimal point, a minus sign and a\n    * trailing \\0, 13 characters:\n    */\n   if (size > 12)\n   {\n      png_uint_32 num;\n\n      /* Avoid overflow here on the minimum integer. */\n      if (fp < 0)\n         *ascii++ = 45, num = -fp;\n      else\n         num = fp;\n\n      if (num <= 0x80000000) /* else overflowed */\n      {\n         unsigned int ndigits = 0, first = 16 /* flag value */;\n         char digits[10];\n\n         while (num)\n         {\n            /* Split the low digit off num: */\n            unsigned int tmp = num/10;\n            num -= tmp*10;\n            digits[ndigits++] = (char)(48 + num);\n            /* Record the first non-zero digit, note that this is a number\n             * starting at 1, it's not actually the array index.\n             */\n            if (first == 16 && num > 0)\n               first = ndigits;\n            num = tmp;\n         }\n\n         if (ndigits > 0)\n         {\n            while (ndigits > 5) *ascii++ = digits[--ndigits];\n            /* The remaining digits are fractional digits, ndigits is '5' or\n             * smaller at this point.  It is certainly not zero.  Check for a\n             * non-zero fractional digit:\n             */\n            if (first <= 5)\n            {\n               unsigned int i;\n               *ascii++ = 46; /* decimal point */\n               /* ndigits may be <5 for small numbers, output leading zeros\n                * then ndigits digits to first:\n                */\n               i = 5;\n               while (ndigits < i) *ascii++ = 48, --i;\n               while (ndigits >= first) *ascii++ = digits[--ndigits];\n               /* Don't output the trailing zeros! */\n            }\n         }\n         else\n            *ascii++ = 48;\n\n         /* And null terminate the string: */\n         *ascii = 0;\n         return;\n      }\n   }\n\n   /* Here on buffer too small. */\n   png_error(png_ptr, \"ASCII conversion buffer too small\");\n}\n#   endif /* FIXED_POINT */\n#endif /* SCAL */\n\n#if defined(PNG_FLOATING_POINT_SUPPORTED) && \\\n   !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \\\n   (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \\\n   defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \\\n   (defined(PNG_sCAL_SUPPORTED) && \\\n   defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))\npng_fixed_point\npng_fixed(png_const_structrp png_ptr, double fp, png_const_charp text)\n{\n   double r = floor(100000 * fp + .5);\n\n   if (r > 2147483647. || r < -2147483648.)\n      png_fixed_error(png_ptr, text);\n\n#  ifndef PNG_ERROR_TEXT_SUPPORTED\n   PNG_UNUSED(text)\n#  endif\n\n   return (png_fixed_point)r;\n}\n#endif\n\n#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_COLORSPACE_SUPPORTED) ||\\\n    defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)\n/* muldiv functions */\n/* This API takes signed arguments and rounds the result to the nearest\n * integer (or, for a fixed point number - the standard argument - to\n * the nearest .00001).  Overflow and divide by zero are signalled in\n * the result, a boolean - true on success, false on overflow.\n */\nint\npng_muldiv(png_fixed_point_p res, png_fixed_point a, png_int_32 times,\n    png_int_32 divisor)\n{\n   /* Return a * times / divisor, rounded. */\n   if (divisor != 0)\n   {\n      if (a == 0 || times == 0)\n      {\n         *res = 0;\n         return 1;\n      }\n      else\n      {\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n         double r = a;\n         r *= times;\n         r /= divisor;\n         r = floor(r+.5);\n\n         /* A png_fixed_point is a 32-bit integer. */\n         if (r <= 2147483647. && r >= -2147483648.)\n         {\n            *res = (png_fixed_point)r;\n            return 1;\n         }\n#else\n         int negative = 0;\n         png_uint_32 A, T, D;\n         png_uint_32 s16, s32, s00;\n\n         if (a < 0)\n            negative = 1, A = -a;\n         else\n            A = a;\n\n         if (times < 0)\n            negative = !negative, T = -times;\n         else\n            T = times;\n\n         if (divisor < 0)\n            negative = !negative, D = -divisor;\n         else\n            D = divisor;\n\n         /* Following can't overflow because the arguments only\n          * have 31 bits each, however the result may be 32 bits.\n          */\n         s16 = (A >> 16) * (T & 0xffff) +\n                           (A & 0xffff) * (T >> 16);\n         /* Can't overflow because the a*times bit is only 30\n          * bits at most.\n          */\n         s32 = (A >> 16) * (T >> 16) + (s16 >> 16);\n         s00 = (A & 0xffff) * (T & 0xffff);\n\n         s16 = (s16 & 0xffff) << 16;\n         s00 += s16;\n\n         if (s00 < s16)\n            ++s32; /* carry */\n\n         if (s32 < D) /* else overflow */\n         {\n            /* s32.s00 is now the 64-bit product, do a standard\n             * division, we know that s32 < D, so the maximum\n             * required shift is 31.\n             */\n            int bitshift = 32;\n            png_fixed_point result = 0; /* NOTE: signed */\n\n            while (--bitshift >= 0)\n            {\n               png_uint_32 d32, d00;\n\n               if (bitshift > 0)\n                  d32 = D >> (32-bitshift), d00 = D << bitshift;\n\n               else\n                  d32 = 0, d00 = D;\n\n               if (s32 > d32)\n               {\n                  if (s00 < d00) --s32; /* carry */\n                  s32 -= d32, s00 -= d00, result += 1<<bitshift;\n               }\n\n               else\n                  if (s32 == d32 && s00 >= d00)\n                     s32 = 0, s00 -= d00, result += 1<<bitshift;\n            }\n\n            /* Handle the rounding. */\n            if (s00 >= (D >> 1))\n               ++result;\n\n            if (negative != 0)\n               result = -result;\n\n            /* Check for overflow. */\n            if ((negative != 0 && result <= 0) ||\n                (negative == 0 && result >= 0))\n            {\n               *res = result;\n               return 1;\n            }\n         }\n#endif\n      }\n   }\n\n   return 0;\n}\n#endif /* READ_GAMMA || INCH_CONVERSIONS */\n\n#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)\n/* The following is for when the caller doesn't much care about the\n * result.\n */\npng_fixed_point\npng_muldiv_warn(png_const_structrp png_ptr, png_fixed_point a, png_int_32 times,\n    png_int_32 divisor)\n{\n   png_fixed_point result;\n\n   if (png_muldiv(&result, a, times, divisor) != 0)\n      return result;\n\n   png_warning(png_ptr, \"fixed point overflow ignored\");\n   return 0;\n}\n#endif\n\n#ifdef PNG_GAMMA_SUPPORTED /* more fixed point functions for gamma */\n/* Calculate a reciprocal, return 0 on div-by-zero or overflow. */\npng_fixed_point\npng_reciprocal(png_fixed_point a)\n{\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n   double r = floor(1E10/a+.5);\n\n   if (r <= 2147483647. && r >= -2147483648.)\n      return (png_fixed_point)r;\n#else\n   png_fixed_point res;\n\n   if (png_muldiv(&res, 100000, 100000, a) != 0)\n      return res;\n#endif\n\n   return 0; /* error/overflow */\n}\n\n/* This is the shared test on whether a gamma value is 'significant' - whether\n * it is worth doing gamma correction.\n */\nint /* PRIVATE */\npng_gamma_significant(png_fixed_point gamma_val)\n{\n   return gamma_val < PNG_FP_1 - PNG_GAMMA_THRESHOLD_FIXED ||\n       gamma_val > PNG_FP_1 + PNG_GAMMA_THRESHOLD_FIXED;\n}\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n#ifdef PNG_16BIT_SUPPORTED\n/* A local convenience routine. */\nstatic png_fixed_point\npng_product2(png_fixed_point a, png_fixed_point b)\n{\n   /* The required result is 1/a * 1/b; the following preserves accuracy. */\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n   double r = a * 1E-5;\n   r *= b;\n   r = floor(r+.5);\n\n   if (r <= 2147483647. && r >= -2147483648.)\n      return (png_fixed_point)r;\n#else\n   png_fixed_point res;\n\n   if (png_muldiv(&res, a, b, 100000) != 0)\n      return res;\n#endif\n\n   return 0; /* overflow */\n}\n#endif /* 16BIT */\n\n/* The inverse of the above. */\npng_fixed_point\npng_reciprocal2(png_fixed_point a, png_fixed_point b)\n{\n   /* The required result is 1/a * 1/b; the following preserves accuracy. */\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n   if (a != 0 && b != 0)\n   {\n      double r = 1E15/a;\n      r /= b;\n      r = floor(r+.5);\n\n      if (r <= 2147483647. && r >= -2147483648.)\n         return (png_fixed_point)r;\n   }\n#else\n   /* This may overflow because the range of png_fixed_point isn't symmetric,\n    * but this API is only used for the product of file and screen gamma so it\n    * doesn't matter that the smallest number it can produce is 1/21474, not\n    * 1/100000\n    */\n   png_fixed_point res = png_product2(a, b);\n\n   if (res != 0)\n      return png_reciprocal(res);\n#endif\n\n   return 0; /* overflow */\n}\n#endif /* READ_GAMMA */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED /* gamma table code */\n#ifndef PNG_FLOATING_ARITHMETIC_SUPPORTED\n/* Fixed point gamma.\n *\n * The code to calculate the tables used below can be found in the shell script\n * contrib/tools/intgamma.sh\n *\n * To calculate gamma this code implements fast log() and exp() calls using only\n * fixed point arithmetic.  This code has sufficient precision for either 8-bit\n * or 16-bit sample values.\n *\n * The tables used here were calculated using simple 'bc' programs, but C double\n * precision floating point arithmetic would work fine.\n *\n * 8-bit log table\n *   This is a table of -log(value/255)/log(2) for 'value' in the range 128 to\n *   255, so it's the base 2 logarithm of a normalized 8-bit floating point\n *   mantissa.  The numbers are 32-bit fractions.\n */\nstatic const png_uint_32\npng_8bit_l2[128] =\n{\n   4270715492U, 4222494797U, 4174646467U, 4127164793U, 4080044201U, 4033279239U,\n   3986864580U, 3940795015U, 3895065449U, 3849670902U, 3804606499U, 3759867474U,\n   3715449162U, 3671346997U, 3627556511U, 3584073329U, 3540893168U, 3498011834U,\n   3455425220U, 3413129301U, 3371120137U, 3329393864U, 3287946700U, 3246774933U,\n   3205874930U, 3165243125U, 3124876025U, 3084770202U, 3044922296U, 3005329011U,\n   2965987113U, 2926893432U, 2888044853U, 2849438323U, 2811070844U, 2772939474U,\n   2735041326U, 2697373562U, 2659933400U, 2622718104U, 2585724991U, 2548951424U,\n   2512394810U, 2476052606U, 2439922311U, 2404001468U, 2368287663U, 2332778523U,\n   2297471715U, 2262364947U, 2227455964U, 2192742551U, 2158222529U, 2123893754U,\n   2089754119U, 2055801552U, 2022034013U, 1988449497U, 1955046031U, 1921821672U,\n   1888774511U, 1855902668U, 1823204291U, 1790677560U, 1758320682U, 1726131893U,\n   1694109454U, 1662251657U, 1630556815U, 1599023271U, 1567649391U, 1536433567U,\n   1505374214U, 1474469770U, 1443718700U, 1413119487U, 1382670639U, 1352370686U,\n   1322218179U, 1292211689U, 1262349810U, 1232631153U, 1203054352U, 1173618059U,\n   1144320946U, 1115161701U, 1086139034U, 1057251672U, 1028498358U, 999877854U,\n   971388940U, 943030410U, 914801076U, 886699767U, 858725327U, 830876614U,\n   803152505U, 775551890U, 748073672U, 720716771U, 693480120U, 666362667U,\n   639363374U, 612481215U, 585715177U, 559064263U, 532527486U, 506103872U,\n   479792461U, 453592303U, 427502463U, 401522014U, 375650043U, 349885648U,\n   324227938U, 298676034U, 273229066U, 247886176U, 222646516U, 197509248U,\n   172473545U, 147538590U, 122703574U, 97967701U, 73330182U, 48790236U,\n   24347096U, 0U\n\n#if 0\n   /* The following are the values for 16-bit tables - these work fine for the\n    * 8-bit conversions but produce very slightly larger errors in the 16-bit\n    * log (about 1.2 as opposed to 0.7 absolute error in the final value).  To\n    * use these all the shifts below must be adjusted appropriately.\n    */\n   65166, 64430, 63700, 62976, 62257, 61543, 60835, 60132, 59434, 58741, 58054,\n   57371, 56693, 56020, 55352, 54689, 54030, 53375, 52726, 52080, 51439, 50803,\n   50170, 49542, 48918, 48298, 47682, 47070, 46462, 45858, 45257, 44661, 44068,\n   43479, 42894, 42312, 41733, 41159, 40587, 40020, 39455, 38894, 38336, 37782,\n   37230, 36682, 36137, 35595, 35057, 34521, 33988, 33459, 32932, 32408, 31887,\n   31369, 30854, 30341, 29832, 29325, 28820, 28319, 27820, 27324, 26830, 26339,\n   25850, 25364, 24880, 24399, 23920, 23444, 22970, 22499, 22029, 21562, 21098,\n   20636, 20175, 19718, 19262, 18808, 18357, 17908, 17461, 17016, 16573, 16132,\n   15694, 15257, 14822, 14390, 13959, 13530, 13103, 12678, 12255, 11834, 11415,\n   10997, 10582, 10168, 9756, 9346, 8937, 8531, 8126, 7723, 7321, 6921, 6523,\n   6127, 5732, 5339, 4947, 4557, 4169, 3782, 3397, 3014, 2632, 2251, 1872, 1495,\n   1119, 744, 372\n#endif\n};\n\nstatic png_int_32\npng_log8bit(unsigned int x)\n{\n   unsigned int lg2 = 0;\n   /* Each time 'x' is multiplied by 2, 1 must be subtracted off the final log,\n    * because the log is actually negate that means adding 1.  The final\n    * returned value thus has the range 0 (for 255 input) to 7.994 (for 1\n    * input), return -1 for the overflow (log 0) case, - so the result is\n    * always at most 19 bits.\n    */\n   if ((x &= 0xff) == 0)\n      return -1;\n\n   if ((x & 0xf0) == 0)\n      lg2  = 4, x <<= 4;\n\n   if ((x & 0xc0) == 0)\n      lg2 += 2, x <<= 2;\n\n   if ((x & 0x80) == 0)\n      lg2 += 1, x <<= 1;\n\n   /* result is at most 19 bits, so this cast is safe: */\n   return (png_int_32)((lg2 << 16) + ((png_8bit_l2[x-128]+32768)>>16));\n}\n\n/* The above gives exact (to 16 binary places) log2 values for 8-bit images,\n * for 16-bit images we use the most significant 8 bits of the 16-bit value to\n * get an approximation then multiply the approximation by a correction factor\n * determined by the remaining up to 8 bits.  This requires an additional step\n * in the 16-bit case.\n *\n * We want log2(value/65535), we have log2(v'/255), where:\n *\n *    value = v' * 256 + v''\n *          = v' * f\n *\n * So f is value/v', which is equal to (256+v''/v') since v' is in the range 128\n * to 255 and v'' is in the range 0 to 255 f will be in the range 256 to less\n * than 258.  The final factor also needs to correct for the fact that our 8-bit\n * value is scaled by 255, whereas the 16-bit values must be scaled by 65535.\n *\n * This gives a final formula using a calculated value 'x' which is value/v' and\n * scaling by 65536 to match the above table:\n *\n *   log2(x/257) * 65536\n *\n * Since these numbers are so close to '1' we can use simple linear\n * interpolation between the two end values 256/257 (result -368.61) and 258/257\n * (result 367.179).  The values used below are scaled by a further 64 to give\n * 16-bit precision in the interpolation:\n *\n * Start (256): -23591\n * Zero  (257):      0\n * End   (258):  23499\n */\n#ifdef PNG_16BIT_SUPPORTED\nstatic png_int_32\npng_log16bit(png_uint_32 x)\n{\n   unsigned int lg2 = 0;\n\n   /* As above, but now the input has 16 bits. */\n   if ((x &= 0xffff) == 0)\n      return -1;\n\n   if ((x & 0xff00) == 0)\n      lg2  = 8, x <<= 8;\n\n   if ((x & 0xf000) == 0)\n      lg2 += 4, x <<= 4;\n\n   if ((x & 0xc000) == 0)\n      lg2 += 2, x <<= 2;\n\n   if ((x & 0x8000) == 0)\n      lg2 += 1, x <<= 1;\n\n   /* Calculate the base logarithm from the top 8 bits as a 28-bit fractional\n    * value.\n    */\n   lg2 <<= 28;\n   lg2 += (png_8bit_l2[(x>>8)-128]+8) >> 4;\n\n   /* Now we need to interpolate the factor, this requires a division by the top\n    * 8 bits.  Do this with maximum precision.\n    */\n   x = ((x << 16) + (x >> 9)) / (x >> 8);\n\n   /* Since we divided by the top 8 bits of 'x' there will be a '1' at 1<<24,\n    * the value at 1<<16 (ignoring this) will be 0 or 1; this gives us exactly\n    * 16 bits to interpolate to get the low bits of the result.  Round the\n    * answer.  Note that the end point values are scaled by 64 to retain overall\n    * precision and that 'lg2' is current scaled by an extra 12 bits, so adjust\n    * the overall scaling by 6-12.  Round at every step.\n    */\n   x -= 1U << 24;\n\n   if (x <= 65536U) /* <= '257' */\n      lg2 += ((23591U * (65536U-x)) + (1U << (16+6-12-1))) >> (16+6-12);\n\n   else\n      lg2 -= ((23499U * (x-65536U)) + (1U << (16+6-12-1))) >> (16+6-12);\n\n   /* Safe, because the result can't have more than 20 bits: */\n   return (png_int_32)((lg2 + 2048) >> 12);\n}\n#endif /* 16BIT */\n\n/* The 'exp()' case must invert the above, taking a 20-bit fixed point\n * logarithmic value and returning a 16 or 8-bit number as appropriate.  In\n * each case only the low 16 bits are relevant - the fraction - since the\n * integer bits (the top 4) simply determine a shift.\n *\n * The worst case is the 16-bit distinction between 65535 and 65534. This\n * requires perhaps spurious accuracy in the decoding of the logarithm to\n * distinguish log2(65535/65534.5) - 10^-5 or 17 bits.  There is little chance\n * of getting this accuracy in practice.\n *\n * To deal with this the following exp() function works out the exponent of the\n * frational part of the logarithm by using an accurate 32-bit value from the\n * top four fractional bits then multiplying in the remaining bits.\n */\nstatic const png_uint_32\npng_32bit_exp[16] =\n{\n   /* NOTE: the first entry is deliberately set to the maximum 32-bit value. */\n   4294967295U, 4112874773U, 3938502376U, 3771522796U, 3611622603U, 3458501653U,\n   3311872529U, 3171459999U, 3037000500U, 2908241642U, 2784941738U, 2666869345U,\n   2553802834U, 2445529972U, 2341847524U, 2242560872U\n};\n\n/* Adjustment table; provided to explain the numbers in the code below. */\n#if 0\nfor (i=11;i>=0;--i){ print i, \" \", (1 - e(-(2^i)/65536*l(2))) * 2^(32-i), \"\\n\"}\n   11 44937.64284865548751208448\n   10 45180.98734845585101160448\n    9 45303.31936980687359311872\n    8 45364.65110595323018870784\n    7 45395.35850361789624614912\n    6 45410.72259715102037508096\n    5 45418.40724413220722311168\n    4 45422.25021786898173001728\n    3 45424.17186732298419044352\n    2 45425.13273269940811464704\n    1 45425.61317555035558641664\n    0 45425.85339951654943850496\n#endif\n\nstatic png_uint_32\npng_exp(png_fixed_point x)\n{\n   if (x > 0 && x <= 0xfffff) /* Else overflow or zero (underflow) */\n   {\n      /* Obtain a 4-bit approximation */\n      png_uint_32 e = png_32bit_exp[(x >> 12) & 0x0f];\n\n      /* Incorporate the low 12 bits - these decrease the returned value by\n       * multiplying by a number less than 1 if the bit is set.  The multiplier\n       * is determined by the above table and the shift. Notice that the values\n       * converge on 45426 and this is used to allow linear interpolation of the\n       * low bits.\n       */\n      if (x & 0x800)\n         e -= (((e >> 16) * 44938U) +  16U) >> 5;\n\n      if (x & 0x400)\n         e -= (((e >> 16) * 45181U) +  32U) >> 6;\n\n      if (x & 0x200)\n         e -= (((e >> 16) * 45303U) +  64U) >> 7;\n\n      if (x & 0x100)\n         e -= (((e >> 16) * 45365U) + 128U) >> 8;\n\n      if (x & 0x080)\n         e -= (((e >> 16) * 45395U) + 256U) >> 9;\n\n      if (x & 0x040)\n         e -= (((e >> 16) * 45410U) + 512U) >> 10;\n\n      /* And handle the low 6 bits in a single block. */\n      e -= (((e >> 16) * 355U * (x & 0x3fU)) + 256U) >> 9;\n\n      /* Handle the upper bits of x. */\n      e >>= x >> 16;\n      return e;\n   }\n\n   /* Check for overflow */\n   if (x <= 0)\n      return png_32bit_exp[0];\n\n   /* Else underflow */\n   return 0;\n}\n\nstatic png_byte\npng_exp8bit(png_fixed_point lg2)\n{\n   /* Get a 32-bit value: */\n   png_uint_32 x = png_exp(lg2);\n\n   /* Convert the 32-bit value to 0..255 by multiplying by 256-1. Note that the\n    * second, rounding, step can't overflow because of the first, subtraction,\n    * step.\n    */\n   x -= x >> 8;\n   return (png_byte)(((x + 0x7fffffU) >> 24) & 0xff);\n}\n\n#ifdef PNG_16BIT_SUPPORTED\nstatic png_uint_16\npng_exp16bit(png_fixed_point lg2)\n{\n   /* Get a 32-bit value: */\n   png_uint_32 x = png_exp(lg2);\n\n   /* Convert the 32-bit value to 0..65535 by multiplying by 65536-1: */\n   x -= x >> 16;\n   return (png_uint_16)((x + 32767U) >> 16);\n}\n#endif /* 16BIT */\n#endif /* FLOATING_ARITHMETIC */\n\npng_byte\npng_gamma_8bit_correct(unsigned int value, png_fixed_point gamma_val)\n{\n   if (value > 0 && value < 255)\n   {\n#     ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n         /* 'value' is unsigned, ANSI-C90 requires the compiler to correctly\n          * convert this to a floating point value.  This includes values that\n          * would overflow if 'value' were to be converted to 'int'.\n          *\n          * Apparently GCC, however, does an intermediate conversion to (int)\n          * on some (ARM) but not all (x86) platforms, possibly because of\n          * hardware FP limitations.  (E.g. if the hardware conversion always\n          * assumes the integer register contains a signed value.)  This results\n          * in ANSI-C undefined behavior for large values.\n          *\n          * Other implementations on the same machine might actually be ANSI-C90\n          * conformant and therefore compile spurious extra code for the large\n          * values.\n          *\n          * We can be reasonably sure that an unsigned to float conversion\n          * won't be faster than an int to float one.  Therefore this code\n          * assumes responsibility for the undefined behavior, which it knows\n          * can't happen because of the check above.\n          *\n          * Note the argument to this routine is an (unsigned int) because, on\n          * 16-bit platforms, it is assigned a value which might be out of\n          * range for an (int); that would result in undefined behavior in the\n          * caller if the *argument* ('value') were to be declared (int).\n          */\n         double r = floor(255*pow((int)/*SAFE*/value/255.,gamma_val*.00001)+.5);\n         return (png_byte)r;\n#     else\n         png_int_32 lg2 = png_log8bit(value);\n         png_fixed_point res;\n\n         if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)\n            return png_exp8bit(res);\n\n         /* Overflow. */\n         value = 0;\n#     endif\n   }\n\n   return (png_byte)(value & 0xff);\n}\n\n#ifdef PNG_16BIT_SUPPORTED\npng_uint_16\npng_gamma_16bit_correct(unsigned int value, png_fixed_point gamma_val)\n{\n   if (value > 0 && value < 65535)\n   {\n# ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n      /* The same (unsigned int)->(double) constraints apply here as above,\n       * however in this case the (unsigned int) to (int) conversion can\n       * overflow on an ANSI-C90 compliant system so the cast needs to ensure\n       * that this is not possible.\n       */\n      double r = floor(65535*pow((png_int_32)value/65535.,\n          gamma_val*.00001)+.5);\n      return (png_uint_16)r;\n# else\n      png_int_32 lg2 = png_log16bit(value);\n      png_fixed_point res;\n\n      if (png_muldiv(&res, gamma_val, lg2, PNG_FP_1) != 0)\n         return png_exp16bit(res);\n\n      /* Overflow. */\n      value = 0;\n# endif\n   }\n\n   return (png_uint_16)value;\n}\n#endif /* 16BIT */\n\n/* This does the right thing based on the bit_depth field of the\n * png_struct, interpreting values as 8-bit or 16-bit.  While the result\n * is nominally a 16-bit value if bit depth is 8 then the result is\n * 8-bit (as are the arguments.)\n */\npng_uint_16 /* PRIVATE */\npng_gamma_correct(png_structrp png_ptr, unsigned int value,\n    png_fixed_point gamma_val)\n{\n   if (png_ptr->bit_depth == 8)\n      return png_gamma_8bit_correct(value, gamma_val);\n\n#ifdef PNG_16BIT_SUPPORTED\n   else\n      return png_gamma_16bit_correct(value, gamma_val);\n#else\n      /* should not reach this */\n      return 0;\n#endif /* 16BIT */\n}\n\n#ifdef PNG_16BIT_SUPPORTED\n/* Internal function to build a single 16-bit table - the table consists of\n * 'num' 256 entry subtables, where 'num' is determined by 'shift' - the amount\n * to shift the input values right (or 16-number_of_signifiant_bits).\n *\n * The caller is responsible for ensuring that the table gets cleaned up on\n * png_error (i.e. if one of the mallocs below fails) - i.e. the *table argument\n * should be somewhere that will be cleaned.\n */\nstatic void\npng_build_16bit_table(png_structrp png_ptr, png_uint_16pp *ptable,\n    PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)\n{\n   /* Various values derived from 'shift': */\n   PNG_CONST unsigned int num = 1U << (8U - shift);\n#ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n   /* CSE the division and work round wacky GCC warnings (see the comments\n    * in png_gamma_8bit_correct for where these come from.)\n    */\n   PNG_CONST double fmax = 1./(((png_int_32)1 << (16U - shift))-1);\n#endif\n   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;\n   PNG_CONST unsigned int max_by_2 = 1U << (15U-shift);\n   unsigned int i;\n\n   png_uint_16pp table = *ptable =\n       (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p)));\n\n   for (i = 0; i < num; i++)\n   {\n      png_uint_16p sub_table = table[i] =\n          (png_uint_16p)png_malloc(png_ptr, 256 * (sizeof (png_uint_16)));\n\n      /* The 'threshold' test is repeated here because it can arise for one of\n       * the 16-bit tables even if the others don't hit it.\n       */\n      if (png_gamma_significant(gamma_val) != 0)\n      {\n         /* The old code would overflow at the end and this would cause the\n          * 'pow' function to return a result >1, resulting in an\n          * arithmetic error.  This code follows the spec exactly; ig is\n          * the recovered input sample, it always has 8-16 bits.\n          *\n          * We want input * 65535/max, rounded, the arithmetic fits in 32\n          * bits (unsigned) so long as max <= 32767.\n          */\n         unsigned int j;\n         for (j = 0; j < 256; j++)\n         {\n            png_uint_32 ig = (j << (8-shift)) + i;\n#           ifdef PNG_FLOATING_ARITHMETIC_SUPPORTED\n               /* Inline the 'max' scaling operation: */\n               /* See png_gamma_8bit_correct for why the cast to (int) is\n                * required here.\n                */\n               double d = floor(65535.*pow(ig*fmax, gamma_val*.00001)+.5);\n               sub_table[j] = (png_uint_16)d;\n#           else\n               if (shift != 0)\n                  ig = (ig * 65535U + max_by_2)/max;\n\n               sub_table[j] = png_gamma_16bit_correct(ig, gamma_val);\n#           endif\n         }\n      }\n      else\n      {\n         /* We must still build a table, but do it the fast way. */\n         unsigned int j;\n\n         for (j = 0; j < 256; j++)\n         {\n            png_uint_32 ig = (j << (8-shift)) + i;\n\n            if (shift != 0)\n               ig = (ig * 65535U + max_by_2)/max;\n\n            sub_table[j] = (png_uint_16)ig;\n         }\n      }\n   }\n}\n\n/* NOTE: this function expects the *inverse* of the overall gamma transformation\n * required.\n */\nstatic void\npng_build_16to8_table(png_structrp png_ptr, png_uint_16pp *ptable,\n    PNG_CONST unsigned int shift, PNG_CONST png_fixed_point gamma_val)\n{\n   PNG_CONST unsigned int num = 1U << (8U - shift);\n   PNG_CONST unsigned int max = (1U << (16U - shift))-1U;\n   unsigned int i;\n   png_uint_32 last;\n\n   png_uint_16pp table = *ptable =\n       (png_uint_16pp)png_calloc(png_ptr, num * (sizeof (png_uint_16p)));\n\n   /* 'num' is the number of tables and also the number of low bits of low\n    * bits of the input 16-bit value used to select a table.  Each table is\n    * itself indexed by the high 8 bits of the value.\n    */\n   for (i = 0; i < num; i++)\n      table[i] = (png_uint_16p)png_malloc(png_ptr,\n          256 * (sizeof (png_uint_16)));\n\n   /* 'gamma_val' is set to the reciprocal of the value calculated above, so\n    * pow(out,g) is an *input* value.  'last' is the last input value set.\n    *\n    * In the loop 'i' is used to find output values.  Since the output is\n    * 8-bit there are only 256 possible values.  The tables are set up to\n    * select the closest possible output value for each input by finding\n    * the input value at the boundary between each pair of output values\n    * and filling the table up to that boundary with the lower output\n    * value.\n    *\n    * The boundary values are 0.5,1.5..253.5,254.5.  Since these are 9-bit\n    * values the code below uses a 16-bit value in i; the values start at\n    * 128.5 (for 0.5) and step by 257, for a total of 254 values (the last\n    * entries are filled with 255).  Start i at 128 and fill all 'last'\n    * table entries <= 'max'\n    */\n   last = 0;\n   for (i = 0; i < 255; ++i) /* 8-bit output value */\n   {\n      /* Find the corresponding maximum input value */\n      png_uint_16 out = (png_uint_16)(i * 257U); /* 16-bit output value */\n\n      /* Find the boundary value in 16 bits: */\n      png_uint_32 bound = png_gamma_16bit_correct(out+128U, gamma_val);\n\n      /* Adjust (round) to (16-shift) bits: */\n      bound = (bound * max + 32768U)/65535U + 1U;\n\n      while (last < bound)\n      {\n         table[last & (0xffU >> shift)][last >> (8U - shift)] = out;\n         last++;\n      }\n   }\n\n   /* And fill in the final entries. */\n   while (last < (num << 8))\n   {\n      table[last & (0xff >> shift)][last >> (8U - shift)] = 65535U;\n      last++;\n   }\n}\n#endif /* 16BIT */\n\n/* Build a single 8-bit table: same as the 16-bit case but much simpler (and\n * typically much faster).  Note that libpng currently does no sBIT processing\n * (apparently contrary to the spec) so a 256-entry table is always generated.\n */\nstatic void\npng_build_8bit_table(png_structrp png_ptr, png_bytepp ptable,\n    PNG_CONST png_fixed_point gamma_val)\n{\n   unsigned int i;\n   png_bytep table = *ptable = (png_bytep)png_malloc(png_ptr, 256);\n\n   if (png_gamma_significant(gamma_val) != 0)\n      for (i=0; i<256; i++)\n         table[i] = png_gamma_8bit_correct(i, gamma_val);\n\n   else\n      for (i=0; i<256; ++i)\n         table[i] = (png_byte)(i & 0xff);\n}\n\n/* Used from png_read_destroy and below to release the memory used by the gamma\n * tables.\n */\nvoid /* PRIVATE */\npng_destroy_gamma_table(png_structrp png_ptr)\n{\n   png_free(png_ptr, png_ptr->gamma_table);\n   png_ptr->gamma_table = NULL;\n\n#ifdef PNG_16BIT_SUPPORTED\n   if (png_ptr->gamma_16_table != NULL)\n   {\n      int i;\n      int istop = (1 << (8 - png_ptr->gamma_shift));\n      for (i = 0; i < istop; i++)\n      {\n         png_free(png_ptr, png_ptr->gamma_16_table[i]);\n      }\n   png_free(png_ptr, png_ptr->gamma_16_table);\n   png_ptr->gamma_16_table = NULL;\n   }\n#endif /* 16BIT */\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)\n   png_free(png_ptr, png_ptr->gamma_from_1);\n   png_ptr->gamma_from_1 = NULL;\n   png_free(png_ptr, png_ptr->gamma_to_1);\n   png_ptr->gamma_to_1 = NULL;\n\n#ifdef PNG_16BIT_SUPPORTED\n   if (png_ptr->gamma_16_from_1 != NULL)\n   {\n      int i;\n      int istop = (1 << (8 - png_ptr->gamma_shift));\n      for (i = 0; i < istop; i++)\n      {\n         png_free(png_ptr, png_ptr->gamma_16_from_1[i]);\n      }\n   png_free(png_ptr, png_ptr->gamma_16_from_1);\n   png_ptr->gamma_16_from_1 = NULL;\n   }\n   if (png_ptr->gamma_16_to_1 != NULL)\n   {\n      int i;\n      int istop = (1 << (8 - png_ptr->gamma_shift));\n      for (i = 0; i < istop; i++)\n      {\n         png_free(png_ptr, png_ptr->gamma_16_to_1[i]);\n      }\n   png_free(png_ptr, png_ptr->gamma_16_to_1);\n   png_ptr->gamma_16_to_1 = NULL;\n   }\n#endif /* 16BIT */\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */\n}\n\n/* We build the 8- or 16-bit gamma tables here.  Note that for 16-bit\n * tables, we don't make a full table if we are reducing to 8-bit in\n * the future.  Note also how the gamma_16 tables are segmented so that\n * we don't need to allocate > 64K chunks for a full 16-bit table.\n */\nvoid /* PRIVATE */\npng_build_gamma_table(png_structrp png_ptr, int bit_depth)\n{\n   png_debug(1, \"in png_build_gamma_table\");\n\n   /* Remove any existing table; this copes with multiple calls to\n    * png_read_update_info. The warning is because building the gamma tables\n    * multiple times is a performance hit - it's harmless but the ability to\n    * call png_read_update_info() multiple times is new in 1.5.6 so it seems\n    * sensible to warn if the app introduces such a hit.\n    */\n   if (png_ptr->gamma_table != NULL || png_ptr->gamma_16_table != NULL)\n   {\n      png_warning(png_ptr, \"gamma table being rebuilt\");\n      png_destroy_gamma_table(png_ptr);\n   }\n\n   if (bit_depth <= 8)\n   {\n      png_build_8bit_table(png_ptr, &png_ptr->gamma_table,\n          png_ptr->screen_gamma > 0 ?\n          png_reciprocal2(png_ptr->colorspace.gamma,\n          png_ptr->screen_gamma) : PNG_FP_1);\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)\n      if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)\n      {\n         png_build_8bit_table(png_ptr, &png_ptr->gamma_to_1,\n             png_reciprocal(png_ptr->colorspace.gamma));\n\n         png_build_8bit_table(png_ptr, &png_ptr->gamma_from_1,\n             png_ptr->screen_gamma > 0 ?\n             png_reciprocal(png_ptr->screen_gamma) :\n             png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);\n      }\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */\n   }\n#ifdef PNG_16BIT_SUPPORTED\n   else\n   {\n      png_byte shift, sig_bit;\n\n      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      {\n         sig_bit = png_ptr->sig_bit.red;\n\n         if (png_ptr->sig_bit.green > sig_bit)\n            sig_bit = png_ptr->sig_bit.green;\n\n         if (png_ptr->sig_bit.blue > sig_bit)\n            sig_bit = png_ptr->sig_bit.blue;\n      }\n      else\n         sig_bit = png_ptr->sig_bit.gray;\n\n      /* 16-bit gamma code uses this equation:\n       *\n       *   ov = table[(iv & 0xff) >> gamma_shift][iv >> 8]\n       *\n       * Where 'iv' is the input color value and 'ov' is the output value -\n       * pow(iv, gamma).\n       *\n       * Thus the gamma table consists of up to 256 256-entry tables.  The table\n       * is selected by the (8-gamma_shift) most significant of the low 8 bits\n       * of the color value then indexed by the upper 8 bits:\n       *\n       *   table[low bits][high 8 bits]\n       *\n       * So the table 'n' corresponds to all those 'iv' of:\n       *\n       *   <all high 8-bit values><n << gamma_shift>..<(n+1 << gamma_shift)-1>\n       *\n       */\n      if (sig_bit > 0 && sig_bit < 16U)\n         /* shift == insignificant bits */\n         shift = (png_byte)((16U - sig_bit) & 0xff);\n\n      else\n         shift = 0; /* keep all 16 bits */\n\n      if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)\n      {\n         /* PNG_MAX_GAMMA_8 is the number of bits to keep - effectively\n          * the significant bits in the *input* when the output will\n          * eventually be 8 bits.  By default it is 11.\n          */\n         if (shift < (16U - PNG_MAX_GAMMA_8))\n            shift = (16U - PNG_MAX_GAMMA_8);\n      }\n\n      if (shift > 8U)\n         shift = 8U; /* Guarantees at least one table! */\n\n      png_ptr->gamma_shift = shift;\n\n      /* NOTE: prior to 1.5.4 this test used to include PNG_BACKGROUND (now\n       * PNG_COMPOSE).  This effectively smashed the background calculation for\n       * 16-bit output because the 8-bit table assumes the result will be\n       * reduced to 8 bits.\n       */\n      if ((png_ptr->transformations & (PNG_16_TO_8 | PNG_SCALE_16_TO_8)) != 0)\n          png_build_16to8_table(png_ptr, &png_ptr->gamma_16_table, shift,\n          png_ptr->screen_gamma > 0 ? png_product2(png_ptr->colorspace.gamma,\n          png_ptr->screen_gamma) : PNG_FP_1);\n\n      else\n          png_build_16bit_table(png_ptr, &png_ptr->gamma_16_table, shift,\n          png_ptr->screen_gamma > 0 ? png_reciprocal2(png_ptr->colorspace.gamma,\n          png_ptr->screen_gamma) : PNG_FP_1);\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)\n      if ((png_ptr->transformations & (PNG_COMPOSE | PNG_RGB_TO_GRAY)) != 0)\n      {\n         png_build_16bit_table(png_ptr, &png_ptr->gamma_16_to_1, shift,\n             png_reciprocal(png_ptr->colorspace.gamma));\n\n         /* Notice that the '16 from 1' table should be full precision, however\n          * the lookup on this table still uses gamma_shift, so it can't be.\n          * TODO: fix this.\n          */\n         png_build_16bit_table(png_ptr, &png_ptr->gamma_16_from_1, shift,\n             png_ptr->screen_gamma > 0 ? png_reciprocal(png_ptr->screen_gamma) :\n             png_ptr->colorspace.gamma/* Probably doing rgb_to_gray */);\n      }\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */\n   }\n#endif /* 16BIT */\n}\n#endif /* READ_GAMMA */\n\n/* HARDWARE OR SOFTWARE OPTION SUPPORT */\n#ifdef PNG_SET_OPTION_SUPPORTED\nint PNGAPI\npng_set_option(png_structrp png_ptr, int option, int onoff)\n{\n   if (png_ptr != NULL && option >= 0 && option < PNG_OPTION_NEXT &&\n      (option & 1) == 0)\n   {\n      int mask = 3 << option;\n      int setting = (2 + (onoff != 0)) << option;\n      int current = png_ptr->options;\n\n      png_ptr->options = (png_byte)(((current & ~mask) | setting) & 0xff);\n\n      return (current & mask) >> option;\n   }\n\n   return PNG_OPTION_INVALID;\n}\n#endif\n\n/* sRGB support */\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\\\n   defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n/* sRGB conversion tables; these are machine generated with the code in\n * contrib/tools/makesRGB.c.  The actual sRGB transfer curve defined in the\n * specification (see the article at http://en.wikipedia.org/wiki/SRGB)\n * is used, not the gamma=1/2.2 approximation use elsewhere in libpng.\n * The sRGB to linear table is exact (to the nearest 16-bit linear fraction).\n * The inverse (linear to sRGB) table has accuracies as follows:\n *\n * For all possible (255*65535+1) input values:\n *\n *    error: -0.515566 - 0.625971, 79441 (0.475369%) of readings inexact\n *\n * For the input values corresponding to the 65536 16-bit values:\n *\n *    error: -0.513727 - 0.607759, 308 (0.469978%) of readings inexact\n *\n * In all cases the inexact readings are only off by one.\n */\n\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED\n/* The convert-to-sRGB table is only currently required for read. */\nconst png_uint_16 png_sRGB_table[256] =\n{\n   0,20,40,60,80,99,119,139,\n   159,179,199,219,241,264,288,313,\n   340,367,396,427,458,491,526,562,\n   599,637,677,718,761,805,851,898,\n   947,997,1048,1101,1156,1212,1270,1330,\n   1391,1453,1517,1583,1651,1720,1790,1863,\n   1937,2013,2090,2170,2250,2333,2418,2504,\n   2592,2681,2773,2866,2961,3058,3157,3258,\n   3360,3464,3570,3678,3788,3900,4014,4129,\n   4247,4366,4488,4611,4736,4864,4993,5124,\n   5257,5392,5530,5669,5810,5953,6099,6246,\n   6395,6547,6700,6856,7014,7174,7335,7500,\n   7666,7834,8004,8177,8352,8528,8708,8889,\n   9072,9258,9445,9635,9828,10022,10219,10417,\n   10619,10822,11028,11235,11446,11658,11873,12090,\n   12309,12530,12754,12980,13209,13440,13673,13909,\n   14146,14387,14629,14874,15122,15371,15623,15878,\n   16135,16394,16656,16920,17187,17456,17727,18001,\n   18277,18556,18837,19121,19407,19696,19987,20281,\n   20577,20876,21177,21481,21787,22096,22407,22721,\n   23038,23357,23678,24002,24329,24658,24990,25325,\n   25662,26001,26344,26688,27036,27386,27739,28094,\n   28452,28813,29176,29542,29911,30282,30656,31033,\n   31412,31794,32179,32567,32957,33350,33745,34143,\n   34544,34948,35355,35764,36176,36591,37008,37429,\n   37852,38278,38706,39138,39572,40009,40449,40891,\n   41337,41785,42236,42690,43147,43606,44069,44534,\n   45002,45473,45947,46423,46903,47385,47871,48359,\n   48850,49344,49841,50341,50844,51349,51858,52369,\n   52884,53401,53921,54445,54971,55500,56032,56567,\n   57105,57646,58190,58737,59287,59840,60396,60955,\n   61517,62082,62650,63221,63795,64372,64952,65535\n};\n#endif /* SIMPLIFIED_READ */\n\n/* The base/delta tables are required for both read and write (but currently\n * only the simplified versions.)\n */\nconst png_uint_16 png_sRGB_base[512] =\n{\n   128,1782,3383,4644,5675,6564,7357,8074,\n   8732,9346,9921,10463,10977,11466,11935,12384,\n   12816,13233,13634,14024,14402,14769,15125,15473,\n   15812,16142,16466,16781,17090,17393,17690,17981,\n   18266,18546,18822,19093,19359,19621,19879,20133,\n   20383,20630,20873,21113,21349,21583,21813,22041,\n   22265,22487,22707,22923,23138,23350,23559,23767,\n   23972,24175,24376,24575,24772,24967,25160,25352,\n   25542,25730,25916,26101,26284,26465,26645,26823,\n   27000,27176,27350,27523,27695,27865,28034,28201,\n   28368,28533,28697,28860,29021,29182,29341,29500,\n   29657,29813,29969,30123,30276,30429,30580,30730,\n   30880,31028,31176,31323,31469,31614,31758,31902,\n   32045,32186,32327,32468,32607,32746,32884,33021,\n   33158,33294,33429,33564,33697,33831,33963,34095,\n   34226,34357,34486,34616,34744,34873,35000,35127,\n   35253,35379,35504,35629,35753,35876,35999,36122,\n   36244,36365,36486,36606,36726,36845,36964,37083,\n   37201,37318,37435,37551,37668,37783,37898,38013,\n   38127,38241,38354,38467,38580,38692,38803,38915,\n   39026,39136,39246,39356,39465,39574,39682,39790,\n   39898,40005,40112,40219,40325,40431,40537,40642,\n   40747,40851,40955,41059,41163,41266,41369,41471,\n   41573,41675,41777,41878,41979,42079,42179,42279,\n   42379,42478,42577,42676,42775,42873,42971,43068,\n   43165,43262,43359,43456,43552,43648,43743,43839,\n   43934,44028,44123,44217,44311,44405,44499,44592,\n   44685,44778,44870,44962,45054,45146,45238,45329,\n   45420,45511,45601,45692,45782,45872,45961,46051,\n   46140,46229,46318,46406,46494,46583,46670,46758,\n   46846,46933,47020,47107,47193,47280,47366,47452,\n   47538,47623,47709,47794,47879,47964,48048,48133,\n   48217,48301,48385,48468,48552,48635,48718,48801,\n   48884,48966,49048,49131,49213,49294,49376,49458,\n   49539,49620,49701,49782,49862,49943,50023,50103,\n   50183,50263,50342,50422,50501,50580,50659,50738,\n   50816,50895,50973,51051,51129,51207,51285,51362,\n   51439,51517,51594,51671,51747,51824,51900,51977,\n   52053,52129,52205,52280,52356,52432,52507,52582,\n   52657,52732,52807,52881,52956,53030,53104,53178,\n   53252,53326,53400,53473,53546,53620,53693,53766,\n   53839,53911,53984,54056,54129,54201,54273,54345,\n   54417,54489,54560,54632,54703,54774,54845,54916,\n   54987,55058,55129,55199,55269,55340,55410,55480,\n   55550,55620,55689,55759,55828,55898,55967,56036,\n   56105,56174,56243,56311,56380,56448,56517,56585,\n   56653,56721,56789,56857,56924,56992,57059,57127,\n   57194,57261,57328,57395,57462,57529,57595,57662,\n   57728,57795,57861,57927,57993,58059,58125,58191,\n   58256,58322,58387,58453,58518,58583,58648,58713,\n   58778,58843,58908,58972,59037,59101,59165,59230,\n   59294,59358,59422,59486,59549,59613,59677,59740,\n   59804,59867,59930,59993,60056,60119,60182,60245,\n   60308,60370,60433,60495,60558,60620,60682,60744,\n   60806,60868,60930,60992,61054,61115,61177,61238,\n   61300,61361,61422,61483,61544,61605,61666,61727,\n   61788,61848,61909,61969,62030,62090,62150,62211,\n   62271,62331,62391,62450,62510,62570,62630,62689,\n   62749,62808,62867,62927,62986,63045,63104,63163,\n   63222,63281,63340,63398,63457,63515,63574,63632,\n   63691,63749,63807,63865,63923,63981,64039,64097,\n   64155,64212,64270,64328,64385,64443,64500,64557,\n   64614,64672,64729,64786,64843,64900,64956,65013,\n   65070,65126,65183,65239,65296,65352,65409,65465\n};\n\nconst png_byte png_sRGB_delta[512] =\n{\n   207,201,158,129,113,100,90,82,77,72,68,64,61,59,56,54,\n   52,50,49,47,46,45,43,42,41,40,39,39,38,37,36,36,\n   35,34,34,33,33,32,32,31,31,30,30,30,29,29,28,28,\n   28,27,27,27,27,26,26,26,25,25,25,25,24,24,24,24,\n   23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,\n   21,20,20,20,20,20,20,20,20,19,19,19,19,19,19,19,\n   19,18,18,18,18,18,18,18,18,18,18,17,17,17,17,17,\n   17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,\n   16,16,16,16,15,15,15,15,15,15,15,15,15,15,15,15,\n   15,15,15,15,14,14,14,14,14,14,14,14,14,14,14,14,\n   14,14,14,14,14,14,14,13,13,13,13,13,13,13,13,13,\n   13,13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,\n   12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,\n   12,12,12,12,12,12,12,12,12,12,12,12,11,11,11,11,\n   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,\n   11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,\n   11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,\n   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,\n   10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,\n   10,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,\n   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,\n   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,\n   9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,\n   9,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n   8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,\n   8,8,8,8,8,8,8,8,8,7,7,7,7,7,7,7,\n   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,\n   7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7\n};\n#endif /* SIMPLIFIED READ/WRITE sRGB support */\n\n/* SIMPLIFIED READ/WRITE SUPPORT */\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\\\n   defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\nstatic int\npng_image_free_function(png_voidp argument)\n{\n   png_imagep image = png_voidcast(png_imagep, argument);\n   png_controlp cp = image->opaque;\n   png_control c;\n\n   /* Double check that we have a png_ptr - it should be impossible to get here\n    * without one.\n    */\n   if (cp->png_ptr == NULL)\n      return 0;\n\n   /* First free any data held in the control structure. */\n#  ifdef PNG_STDIO_SUPPORTED\n      if (cp->owned_file != 0)\n      {\n         FILE *fp = png_voidcast(FILE*, cp->png_ptr->io_ptr);\n         cp->owned_file = 0;\n\n         /* Ignore errors here. */\n         if (fp != NULL)\n         {\n            cp->png_ptr->io_ptr = NULL;\n            (void)fclose(fp);\n         }\n      }\n#  endif\n\n   /* Copy the control structure so that the original, allocated, version can be\n    * safely freed.  Notice that a png_error here stops the remainder of the\n    * cleanup, but this is probably fine because that would indicate bad memory\n    * problems anyway.\n    */\n   c = *cp;\n   image->opaque = &c;\n   png_free(c.png_ptr, cp);\n\n   /* Then the structures, calling the correct API. */\n   if (c.for_write != 0)\n   {\n#     ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED\n         png_destroy_write_struct(&c.png_ptr, &c.info_ptr);\n#     else\n         png_error(c.png_ptr, \"simplified write not supported\");\n#     endif\n   }\n   else\n   {\n#     ifdef PNG_SIMPLIFIED_READ_SUPPORTED\n         png_destroy_read_struct(&c.png_ptr, &c.info_ptr, NULL);\n#     else\n         png_error(c.png_ptr, \"simplified read not supported\");\n#     endif\n   }\n\n   /* Success. */\n   return 1;\n}\n\nvoid PNGAPI\npng_image_free(png_imagep image)\n{\n   /* Safely call the real function, but only if doing so is safe at this point\n    * (if not inside an error handling context).  Otherwise assume\n    * png_safe_execute will call this API after the return.\n    */\n   if (image != NULL && image->opaque != NULL &&\n      image->opaque->error_buf == NULL)\n   {\n      /* Ignore errors here: */\n      (void)png_safe_execute(image, png_image_free_function, image);\n      image->opaque = NULL;\n   }\n}\n\nint /* PRIVATE */\npng_image_error(png_imagep image, png_const_charp error_message)\n{\n   /* Utility to log an error. */\n   png_safecat(image->message, (sizeof image->message), 0, error_message);\n   image->warning_or_error |= PNG_IMAGE_ERROR;\n   png_image_free(image);\n   return 0;\n}\n\n#endif /* SIMPLIFIED READ/WRITE */\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/png.h",
    "content": "\n/* png.h - header file for PNG reference library\n *\n * libpng version 1.6.25, September 1, 2016\n *\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license (See LICENSE, below)\n *\n * Authors and maintainers:\n *   libpng versions 0.71, May 1995, through 0.88, January 1996: Guy Schalnat\n *   libpng versions 0.89, June 1996, through 0.96, May 1997: Andreas Dilger\n *   libpng versions 0.97, January 1998, through 1.6.25, September 1, 2016:\n *     Glenn Randers-Pehrson.\n *   See also \"Contributing Authors\", below.\n */\n\n/*\n * COPYRIGHT NOTICE, DISCLAIMER, and LICENSE:\n *\n * If you modify libpng you may insert additional notices immediately following\n * this sentence.\n *\n * This code is released under the libpng license.\n *\n * Some files in the \"contrib\" directory and some configure-generated\n * files that are distributed with libpng have other copyright owners and\n * are released under other open source licenses.\n *\n * libpng versions 1.0.7, July 1, 2000 through 1.6.25, September 1, 2016 are\n * Copyright (c) 2000-2002, 2004, 2006-2016 Glenn Randers-Pehrson, are\n * derived from libpng-1.0.6, and are distributed according to the same\n * disclaimer and license as libpng-1.0.6 with the following individuals\n * added to the list of Contributing Authors:\n *\n *    Simon-Pierre Cadieux\n *    Eric S. Raymond\n *    Mans Rullgard\n *    Cosmin Truta\n *    Gilles Vollant\n *    James Yu\n *    Mandar Sahastrabuddhe\n *\n * and with the following additions to the disclaimer:\n *\n *    There is no warranty against interference with your enjoyment of the\n *    library or against infringement.  There is no warranty that our\n *    efforts or the library will fulfill any of your particular purposes\n *    or needs.  This library is provided with all faults, and the entire\n *    risk of satisfactory quality, performance, accuracy, and effort is with\n *    the user.\n *\n * Some files in the \"contrib\" directory have other copyright owners and\n * are released under other open source licenses.\n *\n *\n * libpng versions 0.97, January 1998, through 1.0.6, March 20, 2000, are\n * Copyright (c) 1998-2000 Glenn Randers-Pehrson, are derived from\n * libpng-0.96, and are distributed according to the same disclaimer and\n * license as libpng-0.96, with the following individuals added to the list\n * of Contributing Authors:\n *\n *    Tom Lane\n *    Glenn Randers-Pehrson\n *    Willem van Schaik\n *\n * Some files in the \"scripts\" directory have different copyright owners\n * but are also released under this license.\n *\n * libpng versions 0.89, June 1996, through 0.96, May 1997, are\n * Copyright (c) 1996-1997 Andreas Dilger, are derived from libpng-0.88,\n * and are distributed according to the same disclaimer and license as\n * libpng-0.88, with the following individuals added to the list of\n * Contributing Authors:\n *\n *    John Bowler\n *    Kevin Bracey\n *    Sam Bushell\n *    Magnus Holmgren\n *    Greg Roelofs\n *    Tom Tanner\n *\n * Some files in the \"scripts\" directory have other copyright owners\n * but are released under this license.\n *\n * libpng versions 0.5, May 1995, through 0.88, January 1996, are\n * Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n *\n * For the purposes of this copyright and license, \"Contributing Authors\"\n * is defined as the following set of individuals:\n *\n *    Andreas Dilger\n *    Dave Martindale\n *    Guy Eric Schalnat\n *    Paul Schmidt\n *    Tim Wegner\n *\n * The PNG Reference Library is supplied \"AS IS\".  The Contributing Authors\n * and Group 42, Inc. disclaim all warranties, expressed or implied,\n * including, without limitation, the warranties of merchantability and of\n * fitness for any purpose.  The Contributing Authors and Group 42, Inc.\n * assume no liability for direct, indirect, incidental, special, exemplary,\n * or consequential damages, which may result from the use of the PNG\n * Reference Library, even if advised of the possibility of such damage.\n *\n * Permission is hereby granted to use, copy, modify, and distribute this\n * source code, or portions hereof, for any purpose, without fee, subject\n * to the following restrictions:\n *\n *   1. The origin of this source code must not be misrepresented.\n *\n *   2. Altered versions must be plainly marked as such and must not\n *      be misrepresented as being the original source.\n *\n *   3. This Copyright notice may not be removed or altered from any\n *      source or altered source distribution.\n *\n * The Contributing Authors and Group 42, Inc. specifically permit, without\n * fee, and encourage the use of this source code as a component to\n * supporting the PNG file format in commercial products.  If you use this\n * source code in a product, acknowledgment is not required but would be\n * appreciated.\n *\n * END OF COPYRIGHT NOTICE, DISCLAIMER, and LICENSE.\n *\n * TRADEMARK:\n *\n * The name \"libpng\" has not been registered by the Copyright owner\n * as a trademark in any jurisdiction.  However, because libpng has\n * been distributed and maintained world-wide, continually since 1995,\n * the Copyright owner claims \"common-law trademark protection\" in any\n * jurisdiction where common-law trademark is recognized.\n *\n * OSI CERTIFICATION:\n *\n * Libpng is OSI Certified Open Source Software.  OSI Certified Open Source is\n * a certification mark of the Open Source Initiative. OSI has not addressed\n * the additional disclaimers inserted at version 1.0.7.\n *\n * EXPORT CONTROL:\n *\n * The Copyright owner believes that the Export Control Classification\n * Number (ECCN) for libpng is EAR99, which means not subject to export\n * controls or International Traffic in Arms Regulations (ITAR) because\n * it is open source, publicly available software, that does not contain\n * any encryption software.  See the EAR, paragraphs 734.3(b)(3) and\n * 734.7(b).\n */\n\n/*\n * A \"png_get_copyright\" function is available, for convenient use in \"about\"\n * boxes and the like:\n *\n *    printf(\"%s\", png_get_copyright(NULL));\n *\n * Also, the PNG logo (in PNG format, of course) is supplied in the\n * files \"pngbar.png\" and \"pngbar.jpg (88x31) and \"pngnow.png\" (98x31).\n */\n\n/*\n * The contributing authors would like to thank all those who helped\n * with testing, bug fixes, and patience.  This wouldn't have been\n * possible without all of you.\n *\n * Thanks to Frank J. T. Wojcik for helping with the documentation.\n */\n\n/* Note about libpng version numbers:\n *\n *    Due to various miscommunications, unforeseen code incompatibilities\n *    and occasional factors outside the authors' control, version numbering\n *    on the library has not always been consistent and straightforward.\n *    The following table summarizes matters since version 0.89c, which was\n *    the first widely used release:\n *\n *    source                 png.h  png.h  shared-lib\n *    version                string   int  version\n *    -------                ------ -----  ----------\n *    0.89c \"1.0 beta 3\"     0.89      89  1.0.89\n *    0.90  \"1.0 beta 4\"     0.90      90  0.90  [should have been 2.0.90]\n *    0.95  \"1.0 beta 5\"     0.95      95  0.95  [should have been 2.0.95]\n *    0.96  \"1.0 beta 6\"     0.96      96  0.96  [should have been 2.0.96]\n *    0.97b \"1.00.97 beta 7\" 1.00.97   97  1.0.1 [should have been 2.0.97]\n *    0.97c                  0.97      97  2.0.97\n *    0.98                   0.98      98  2.0.98\n *    0.99                   0.99      98  2.0.99\n *    0.99a-m                0.99      99  2.0.99\n *    1.00                   1.00     100  2.1.0 [100 should be 10000]\n *    1.0.0      (from here on, the   100  2.1.0 [100 should be 10000]\n *    1.0.1       png.h string is   10001  2.1.0\n *    1.0.1a-e    identical to the  10002  from here on, the shared library\n *    1.0.2       source version)   10002  is 2.V where V is the source code\n *    1.0.2a-b                      10003  version, except as noted.\n *    1.0.3                         10003\n *    1.0.3a-d                      10004\n *    1.0.4                         10004\n *    1.0.4a-f                      10005\n *    1.0.5 (+ 2 patches)           10005\n *    1.0.5a-d                      10006\n *    1.0.5e-r                      10100 (not source compatible)\n *    1.0.5s-v                      10006 (not binary compatible)\n *    1.0.6 (+ 3 patches)           10006 (still binary incompatible)\n *    1.0.6d-f                      10007 (still binary incompatible)\n *    1.0.6g                        10007\n *    1.0.6h                        10007  10.6h (testing xy.z so-numbering)\n *    1.0.6i                        10007  10.6i\n *    1.0.6j                        10007  2.1.0.6j (incompatible with 1.0.0)\n *    1.0.7beta11-14        DLLNUM  10007  2.1.0.7beta11-14 (binary compatible)\n *    1.0.7beta15-18           1    10007  2.1.0.7beta15-18 (binary compatible)\n *    1.0.7rc1-2               1    10007  2.1.0.7rc1-2 (binary compatible)\n *    1.0.7                    1    10007  (still compatible)\n *    ...\n *    1.0.19                  10    10019  10.so.0.19[.0]\n *    ...\n *    1.2.56                  13    10256  12.so.0.56[.0]\n *    ...\n *    1.5.27                  15    10527  15.so.15.27[.0]\n *    ...\n *    1.6.25                  16    10625  16.so.16.25[.0]\n *\n *    Henceforth the source version will match the shared-library major\n *    and minor numbers; the shared-library major version number will be\n *    used for changes in backward compatibility, as it is intended.  The\n *    PNG_LIBPNG_VER macro, which is not used within libpng but is available\n *    for applications, is an unsigned integer of the form xyyzz corresponding\n *    to the source version x.y.z (leading zeros in y and z).  Beta versions\n *    were given the previous public release number plus a letter, until\n *    version 1.0.6j; from then on they were given the upcoming public\n *    release number plus \"betaNN\" or \"rcNN\".\n *\n *    Binary incompatibility exists only when applications make direct access\n *    to the info_ptr or png_ptr members through png.h, and the compiled\n *    application is loaded with a different version of the library.\n *\n *    DLLNUM will change each time there are forward or backward changes\n *    in binary compatibility (e.g., when a new feature is added).\n *\n * See libpng.txt or libpng.3 for more information.  The PNG specification\n * is available as a W3C Recommendation and as an ISO Specification,\n * <http://www.w3.org/TR/2003/REC-PNG-20031110/\n */\n\n/*\n * Y2K compliance in libpng:\n * =========================\n *\n *    September 1, 2016\n *\n *    Since the PNG Development group is an ad-hoc body, we can't make\n *    an official declaration.\n *\n *    This is your unofficial assurance that libpng from version 0.71 and\n *    upward through 1.6.25 are Y2K compliant.  It is my belief that\n *    earlier versions were also Y2K compliant.\n *\n *    Libpng only has two year fields.  One is a 2-byte unsigned integer\n *    that will hold years up to 65535.  The other, which is deprecated,\n *    holds the date in text format, and will hold years up to 9999.\n *\n *    The integer is\n *        \"png_uint_16 year\" in png_time_struct.\n *\n *    The string is\n *        \"char time_buffer[29]\" in png_struct.  This is no longer used\n *    in libpng-1.6.x and will be removed from libpng-1.7.0.\n *\n *    There are seven time-related functions:\n *        png.c: png_convert_to_rfc_1123_buffer() in png.c\n *          (formerly png_convert_to_rfc_1123() prior to libpng-1.5.x and\n *          png_convert_to_rfc_1152() in error prior to libpng-0.98)\n *        png_convert_from_struct_tm() in pngwrite.c, called in pngwrite.c\n *        png_convert_from_time_t() in pngwrite.c\n *        png_get_tIME() in pngget.c\n *        png_handle_tIME() in pngrutil.c, called in pngread.c\n *        png_set_tIME() in pngset.c\n *        png_write_tIME() in pngwutil.c, called in pngwrite.c\n *\n *    All handle dates properly in a Y2K environment.  The\n *    png_convert_from_time_t() function calls gmtime() to convert from system\n *    clock time, which returns (year - 1900), which we properly convert to\n *    the full 4-digit year.  There is a possibility that libpng applications\n *    are not passing 4-digit years into the png_convert_to_rfc_1123_buffer()\n *    function, or that they are incorrectly passing only a 2-digit year\n *    instead of \"year - 1900\" into the png_convert_from_struct_tm() function,\n *    but this is not under our control.  The libpng documentation has always\n *    stated that it works with 4-digit years, and the APIs have been\n *    documented as such.\n *\n *    The tIME chunk itself is also Y2K compliant.  It uses a 2-byte unsigned\n *    integer to hold the year, and can hold years as large as 65535.\n *\n *    zlib, upon which libpng depends, is also Y2K compliant.  It contains\n *    no date-related code.\n *\n *       Glenn Randers-Pehrson\n *       libpng maintainer\n *       PNG Development Group\n */\n\n#ifndef PNG_H\n#define PNG_H\n\n/* This is not the place to learn how to use libpng. The file libpng-manual.txt\n * describes how to use libpng, and the file example.c summarizes it\n * with some code on which to build.  This file is useful for looking\n * at the actual function definitions and structure components.  If that\n * file has been stripped from your copy of libpng, you can find it at\n * <http://www.libpng.org/pub/png/libpng-manual.txt>\n *\n * If you just need to read a PNG file and don't want to read the documentation\n * skip to the end of this file and read the section entitled 'simplified API'.\n */\n\n/* Version information for png.h - this should match the version in png.c */\n#define PNG_LIBPNG_VER_STRING \"1.6.25\"\n#define PNG_HEADER_VERSION_STRING \" libpng version 1.6.25 - September 1, 2016\\n\"\n\n#define PNG_LIBPNG_VER_SONUM   16\n#define PNG_LIBPNG_VER_DLLNUM  16\n\n/* These should match the first 3 components of PNG_LIBPNG_VER_STRING: */\n#define PNG_LIBPNG_VER_MAJOR   1\n#define PNG_LIBPNG_VER_MINOR   6\n#define PNG_LIBPNG_VER_RELEASE 25\n\n/* This should match the numeric part of the final component of\n * PNG_LIBPNG_VER_STRING, omitting any leading zero:\n */\n\n#define PNG_LIBPNG_VER_BUILD  0\n\n/* Release Status */\n#define PNG_LIBPNG_BUILD_ALPHA    1\n#define PNG_LIBPNG_BUILD_BETA     2\n#define PNG_LIBPNG_BUILD_RC       3\n#define PNG_LIBPNG_BUILD_STABLE   4\n#define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7\n\n/* Release-Specific Flags */\n#define PNG_LIBPNG_BUILD_PATCH    8 /* Can be OR'ed with\n                                       PNG_LIBPNG_BUILD_STABLE only */\n#define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with\n                                       PNG_LIBPNG_BUILD_SPECIAL */\n#define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with\n                                       PNG_LIBPNG_BUILD_PRIVATE */\n\n#define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE\n\n/* Careful here.  At one time, Guy wanted to use 082, but that would be octal.\n * We must not include leading zeros.\n * Versions 0.7 through 1.0.0 were in the range 0 to 100 here (only\n * version 1.0.0 was mis-numbered 100 instead of 10000).  From\n * version 1.0.1 it's    xxyyzz, where x=major, y=minor, z=release\n */\n#define PNG_LIBPNG_VER 10625 /* 1.6.25 */\n\n/* Library configuration: these options cannot be changed after\n * the library has been built.\n */\n#ifndef PNGLCONF_H\n/* If pnglibconf.h is missing, you can\n * copy scripts/pnglibconf.h.prebuilt to pnglibconf.h\n */\n#   include \"pnglibconf.h\"\n#endif\n\n#ifndef PNG_VERSION_INFO_ONLY\n/* Machine specific configuration. */\n#  include \"pngconf.h\"\n#endif\n\n/*\n * Added at libpng-1.2.8\n *\n * Ref MSDN: Private as priority over Special\n * VS_FF_PRIVATEBUILD File *was not* built using standard release\n * procedures. If this value is given, the StringFileInfo block must\n * contain a PrivateBuild string.\n *\n * VS_FF_SPECIALBUILD File *was* built by the original company using\n * standard release procedures but is a variation of the standard\n * file of the same version number. If this value is given, the\n * StringFileInfo block must contain a SpecialBuild string.\n */\n\n#ifdef PNG_USER_PRIVATEBUILD /* From pnglibconf.h */\n#  define PNG_LIBPNG_BUILD_TYPE \\\n       (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)\n#else\n#  ifdef PNG_LIBPNG_SPECIALBUILD\n#    define PNG_LIBPNG_BUILD_TYPE \\\n         (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)\n#  else\n#    define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)\n#  endif\n#endif\n\n#ifndef PNG_VERSION_INFO_ONLY\n\n/* Inhibit C++ name-mangling for libpng functions but not for system calls. */\n#ifdef __cplusplus\nextern \"C\" {\n#endif /* __cplusplus */\n\n/* Version information for C files, stored in png.c.  This had better match\n * the version above.\n */\n#define png_libpng_ver png_get_header_ver(NULL)\n\n/* This file is arranged in several sections:\n *\n * 1. [omitted]\n * 2. Any configuration options that can be specified by for the application\n *    code when it is built.  (Build time configuration is in pnglibconf.h)\n * 3. Type definitions (base types are defined in pngconf.h), structure\n *    definitions.\n * 4. Exported library functions.\n * 5. Simplified API.\n * 6. Implementation options.\n *\n * The library source code has additional files (principally pngpriv.h) that\n * allow configuration of the library.\n */\n\n/* Section 1: [omitted] */\n\n/* Section 2: run time configuration\n * See pnglibconf.h for build time configuration\n *\n * Run time configuration allows the application to choose between\n * implementations of certain arithmetic APIs.  The default is set\n * at build time and recorded in pnglibconf.h, but it is safe to\n * override these (and only these) settings.  Note that this won't\n * change what the library does, only application code, and the\n * settings can (and probably should) be made on a per-file basis\n * by setting the #defines before including png.h\n *\n * Use macros to read integers from PNG data or use the exported\n * functions?\n *   PNG_USE_READ_MACROS: use the macros (see below)  Note that\n *     the macros evaluate their argument multiple times.\n *   PNG_NO_USE_READ_MACROS: call the relevant library function.\n *\n * Use the alternative algorithm for compositing alpha samples that\n * does not use division?\n *   PNG_READ_COMPOSITE_NODIV_SUPPORTED: use the 'no division'\n *      algorithm.\n *   PNG_NO_READ_COMPOSITE_NODIV: use the 'division' algorithm.\n *\n * How to handle benign errors if PNG_ALLOW_BENIGN_ERRORS is\n * false?\n *   PNG_ALLOW_BENIGN_ERRORS: map calls to the benign error\n *      APIs to png_warning.\n * Otherwise the calls are mapped to png_error.\n */\n\n/* Section 3: type definitions, including structures and compile time\n * constants.\n * See pngconf.h for base types that vary by machine/system\n */\n\n/* This triggers a compiler error in png.c, if png.c and png.h\n * do not agree upon the version number.\n */\ntypedef char* png_libpng_version_1_6_25;\n\n/* Basic control structions.  Read libpng-manual.txt or libpng.3 for more info.\n *\n * png_struct is the cache of information used while reading or writing a single\n * PNG file.  One of these is always required, although the simplified API\n * (below) hides the creation and destruction of it.\n */\ntypedef struct png_struct_def png_struct;\ntypedef const png_struct * png_const_structp;\ntypedef png_struct * png_structp;\ntypedef png_struct * * png_structpp;\n\n/* png_info contains information read from or to be written to a PNG file.  One\n * or more of these must exist while reading or creating a PNG file.  The\n * information is not used by libpng during read but is used to control what\n * gets written when a PNG file is created.  \"png_get_\" function calls read\n * information during read and \"png_set_\" functions calls write information\n * when creating a PNG.\n * been moved into a separate header file that is not accessible to\n * applications.  Read libpng-manual.txt or libpng.3 for more info.\n */\ntypedef struct png_info_def png_info;\ntypedef png_info * png_infop;\ntypedef const png_info * png_const_infop;\ntypedef png_info * * png_infopp;\n\n/* Types with names ending 'p' are pointer types.  The corresponding types with\n * names ending 'rp' are identical pointer types except that the pointer is\n * marked 'restrict', which means that it is the only pointer to the object\n * passed to the function.  Applications should not use the 'restrict' types;\n * it is always valid to pass 'p' to a pointer with a function argument of the\n * corresponding 'rp' type.  Different compilers have different rules with\n * regard to type matching in the presence of 'restrict'.  For backward\n * compatibility libpng callbacks never have 'restrict' in their parameters and,\n * consequentially, writing portable application code is extremely difficult if\n * an attempt is made to use 'restrict'.\n */\ntypedef png_struct * PNG_RESTRICT png_structrp;\ntypedef const png_struct * PNG_RESTRICT png_const_structrp;\ntypedef png_info * PNG_RESTRICT png_inforp;\ntypedef const png_info * PNG_RESTRICT png_const_inforp;\n\n/* Three color definitions.  The order of the red, green, and blue, (and the\n * exact size) is not important, although the size of the fields need to\n * be png_byte or png_uint_16 (as defined below).\n */\ntypedef struct png_color_struct\n{\n   png_byte red;\n   png_byte green;\n   png_byte blue;\n} png_color;\ntypedef png_color * png_colorp;\ntypedef const png_color * png_const_colorp;\ntypedef png_color * * png_colorpp;\n\ntypedef struct png_color_16_struct\n{\n   png_byte index;    /* used for palette files */\n   png_uint_16 red;   /* for use in red green blue files */\n   png_uint_16 green;\n   png_uint_16 blue;\n   png_uint_16 gray;  /* for use in grayscale files */\n} png_color_16;\ntypedef png_color_16 * png_color_16p;\ntypedef const png_color_16 * png_const_color_16p;\ntypedef png_color_16 * * png_color_16pp;\n\ntypedef struct png_color_8_struct\n{\n   png_byte red;   /* for use in red green blue files */\n   png_byte green;\n   png_byte blue;\n   png_byte gray;  /* for use in grayscale files */\n   png_byte alpha; /* for alpha channel files */\n} png_color_8;\ntypedef png_color_8 * png_color_8p;\ntypedef const png_color_8 * png_const_color_8p;\ntypedef png_color_8 * * png_color_8pp;\n\n/*\n * The following two structures are used for the in-core representation\n * of sPLT chunks.\n */\ntypedef struct png_sPLT_entry_struct\n{\n   png_uint_16 red;\n   png_uint_16 green;\n   png_uint_16 blue;\n   png_uint_16 alpha;\n   png_uint_16 frequency;\n} png_sPLT_entry;\ntypedef png_sPLT_entry * png_sPLT_entryp;\ntypedef const png_sPLT_entry * png_const_sPLT_entryp;\ntypedef png_sPLT_entry * * png_sPLT_entrypp;\n\n/*  When the depth of the sPLT palette is 8 bits, the color and alpha samples\n *  occupy the LSB of their respective members, and the MSB of each member\n *  is zero-filled.  The frequency member always occupies the full 16 bits.\n */\n\ntypedef struct png_sPLT_struct\n{\n   png_charp name;           /* palette name */\n   png_byte depth;           /* depth of palette samples */\n   png_sPLT_entryp entries;  /* palette entries */\n   png_int_32 nentries;      /* number of palette entries */\n} png_sPLT_t;\ntypedef png_sPLT_t * png_sPLT_tp;\ntypedef const png_sPLT_t * png_const_sPLT_tp;\ntypedef png_sPLT_t * * png_sPLT_tpp;\n\n#ifdef PNG_TEXT_SUPPORTED\n/* png_text holds the contents of a text/ztxt/itxt chunk in a PNG file,\n * and whether that contents is compressed or not.  The \"key\" field\n * points to a regular zero-terminated C string.  The \"text\" fields can be a\n * regular C string, an empty string, or a NULL pointer.\n * However, the structure returned by png_get_text() will always contain\n * the \"text\" field as a regular zero-terminated C string (possibly\n * empty), never a NULL pointer, so it can be safely used in printf() and\n * other string-handling functions.  Note that the \"itxt_length\", \"lang\", and\n * \"lang_key\" members of the structure only exist when the library is built\n * with iTXt chunk support.  Prior to libpng-1.4.0 the library was built by\n * default without iTXt support. Also note that when iTXt *is* supported,\n * the \"lang\" and \"lang_key\" fields contain NULL pointers when the\n * \"compression\" field contains * PNG_TEXT_COMPRESSION_NONE or\n * PNG_TEXT_COMPRESSION_zTXt. Note that the \"compression value\" is not the\n * same as what appears in the PNG tEXt/zTXt/iTXt chunk's \"compression flag\"\n * which is always 0 or 1, or its \"compression method\" which is always 0.\n */\ntypedef struct png_text_struct\n{\n   int  compression;       /* compression value:\n                             -1: tEXt, none\n                              0: zTXt, deflate\n                              1: iTXt, none\n                              2: iTXt, deflate  */\n   png_charp key;          /* keyword, 1-79 character description of \"text\" */\n   png_charp text;         /* comment, may be an empty string (ie \"\")\n                              or a NULL pointer */\n   png_size_t text_length; /* length of the text string */\n   png_size_t itxt_length; /* length of the itxt string */\n   png_charp lang;         /* language code, 0-79 characters\n                              or a NULL pointer */\n   png_charp lang_key;     /* keyword translated UTF-8 string, 0 or more\n                              chars or a NULL pointer */\n} png_text;\ntypedef png_text * png_textp;\ntypedef const png_text * png_const_textp;\ntypedef png_text * * png_textpp;\n#endif\n\n/* Supported compression types for text in PNG files (tEXt, and zTXt).\n * The values of the PNG_TEXT_COMPRESSION_ defines should NOT be changed. */\n#define PNG_TEXT_COMPRESSION_NONE_WR -3\n#define PNG_TEXT_COMPRESSION_zTXt_WR -2\n#define PNG_TEXT_COMPRESSION_NONE    -1\n#define PNG_TEXT_COMPRESSION_zTXt     0\n#define PNG_ITXT_COMPRESSION_NONE     1\n#define PNG_ITXT_COMPRESSION_zTXt     2\n#define PNG_TEXT_COMPRESSION_LAST     3  /* Not a valid value */\n\n/* png_time is a way to hold the time in an machine independent way.\n * Two conversions are provided, both from time_t and struct tm.  There\n * is no portable way to convert to either of these structures, as far\n * as I know.  If you know of a portable way, send it to me.  As a side\n * note - PNG has always been Year 2000 compliant!\n */\ntypedef struct png_time_struct\n{\n   png_uint_16 year; /* full year, as in, 1995 */\n   png_byte month;   /* month of year, 1 - 12 */\n   png_byte day;     /* day of month, 1 - 31 */\n   png_byte hour;    /* hour of day, 0 - 23 */\n   png_byte minute;  /* minute of hour, 0 - 59 */\n   png_byte second;  /* second of minute, 0 - 60 (for leap seconds) */\n} png_time;\ntypedef png_time * png_timep;\ntypedef const png_time * png_const_timep;\ntypedef png_time * * png_timepp;\n\n#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) ||\\\n   defined(PNG_USER_CHUNKS_SUPPORTED)\n/* png_unknown_chunk is a structure to hold queued chunks for which there is\n * no specific support.  The idea is that we can use this to queue\n * up private chunks for output even though the library doesn't actually\n * know about their semantics.\n *\n * The data in the structure is set by libpng on read and used on write.\n */\ntypedef struct png_unknown_chunk_t\n{\n   png_byte name[5]; /* Textual chunk name with '\\0' terminator */\n   png_byte *data;   /* Data, should not be modified on read! */\n   png_size_t size;\n\n   /* On write 'location' must be set using the flag values listed below.\n    * Notice that on read it is set by libpng however the values stored have\n    * more bits set than are listed below.  Always treat the value as a\n    * bitmask.  On write set only one bit - setting multiple bits may cause the\n    * chunk to be written in multiple places.\n    */\n   png_byte location; /* mode of operation at read time */\n}\npng_unknown_chunk;\n\ntypedef png_unknown_chunk * png_unknown_chunkp;\ntypedef const png_unknown_chunk * png_const_unknown_chunkp;\ntypedef png_unknown_chunk * * png_unknown_chunkpp;\n#endif\n\n/* Flag values for the unknown chunk location byte. */\n#define PNG_HAVE_IHDR  0x01\n#define PNG_HAVE_PLTE  0x02\n#define PNG_AFTER_IDAT 0x08\n\n/* Maximum positive integer used in PNG is (2^31)-1 */\n#define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)\n#define PNG_UINT_32_MAX ((png_uint_32)(-1))\n#define PNG_SIZE_MAX ((png_size_t)(-1))\n\n/* These are constants for fixed point values encoded in the\n * PNG specification manner (x100000)\n */\n#define PNG_FP_1    100000\n#define PNG_FP_HALF  50000\n#define PNG_FP_MAX  ((png_fixed_point)0x7fffffffL)\n#define PNG_FP_MIN  (-PNG_FP_MAX)\n\n/* These describe the color_type field in png_info. */\n/* color type masks */\n#define PNG_COLOR_MASK_PALETTE    1\n#define PNG_COLOR_MASK_COLOR      2\n#define PNG_COLOR_MASK_ALPHA      4\n\n/* color types.  Note that not all combinations are legal */\n#define PNG_COLOR_TYPE_GRAY 0\n#define PNG_COLOR_TYPE_PALETTE  (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)\n#define PNG_COLOR_TYPE_RGB        (PNG_COLOR_MASK_COLOR)\n#define PNG_COLOR_TYPE_RGB_ALPHA  (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)\n#define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)\n/* aliases */\n#define PNG_COLOR_TYPE_RGBA  PNG_COLOR_TYPE_RGB_ALPHA\n#define PNG_COLOR_TYPE_GA  PNG_COLOR_TYPE_GRAY_ALPHA\n\n/* This is for compression type. PNG 1.0-1.2 only define the single type. */\n#define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */\n#define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE\n\n/* This is for filter type. PNG 1.0-1.2 only define the single type. */\n#define PNG_FILTER_TYPE_BASE      0 /* Single row per-byte filtering */\n#define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */\n#define PNG_FILTER_TYPE_DEFAULT   PNG_FILTER_TYPE_BASE\n\n/* These are for the interlacing type.  These values should NOT be changed. */\n#define PNG_INTERLACE_NONE        0 /* Non-interlaced image */\n#define PNG_INTERLACE_ADAM7       1 /* Adam7 interlacing */\n#define PNG_INTERLACE_LAST        2 /* Not a valid value */\n\n/* These are for the oFFs chunk.  These values should NOT be changed. */\n#define PNG_OFFSET_PIXEL          0 /* Offset in pixels */\n#define PNG_OFFSET_MICROMETER     1 /* Offset in micrometers (1/10^6 meter) */\n#define PNG_OFFSET_LAST           2 /* Not a valid value */\n\n/* These are for the pCAL chunk.  These values should NOT be changed. */\n#define PNG_EQUATION_LINEAR       0 /* Linear transformation */\n#define PNG_EQUATION_BASE_E       1 /* Exponential base e transform */\n#define PNG_EQUATION_ARBITRARY    2 /* Arbitrary base exponential transform */\n#define PNG_EQUATION_HYPERBOLIC   3 /* Hyperbolic sine transformation */\n#define PNG_EQUATION_LAST         4 /* Not a valid value */\n\n/* These are for the sCAL chunk.  These values should NOT be changed. */\n#define PNG_SCALE_UNKNOWN         0 /* unknown unit (image scale) */\n#define PNG_SCALE_METER           1 /* meters per pixel */\n#define PNG_SCALE_RADIAN          2 /* radians per pixel */\n#define PNG_SCALE_LAST            3 /* Not a valid value */\n\n/* These are for the pHYs chunk.  These values should NOT be changed. */\n#define PNG_RESOLUTION_UNKNOWN    0 /* pixels/unknown unit (aspect ratio) */\n#define PNG_RESOLUTION_METER      1 /* pixels/meter */\n#define PNG_RESOLUTION_LAST       2 /* Not a valid value */\n\n/* These are for the sRGB chunk.  These values should NOT be changed. */\n#define PNG_sRGB_INTENT_PERCEPTUAL 0\n#define PNG_sRGB_INTENT_RELATIVE   1\n#define PNG_sRGB_INTENT_SATURATION 2\n#define PNG_sRGB_INTENT_ABSOLUTE   3\n#define PNG_sRGB_INTENT_LAST       4 /* Not a valid value */\n\n/* This is for text chunks */\n#define PNG_KEYWORD_MAX_LENGTH     79\n\n/* Maximum number of entries in PLTE/sPLT/tRNS arrays */\n#define PNG_MAX_PALETTE_LENGTH    256\n\n/* These determine if an ancillary chunk's data has been successfully read\n * from the PNG header, or if the application has filled in the corresponding\n * data in the info_struct to be written into the output file.  The values\n * of the PNG_INFO_<chunk> defines should NOT be changed.\n */\n#define PNG_INFO_gAMA 0x0001U\n#define PNG_INFO_sBIT 0x0002U\n#define PNG_INFO_cHRM 0x0004U\n#define PNG_INFO_PLTE 0x0008U\n#define PNG_INFO_tRNS 0x0010U\n#define PNG_INFO_bKGD 0x0020U\n#define PNG_INFO_hIST 0x0040U\n#define PNG_INFO_pHYs 0x0080U\n#define PNG_INFO_oFFs 0x0100U\n#define PNG_INFO_tIME 0x0200U\n#define PNG_INFO_pCAL 0x0400U\n#define PNG_INFO_sRGB 0x0800U  /* GR-P, 0.96a */\n#define PNG_INFO_iCCP 0x1000U  /* ESR, 1.0.6 */\n#define PNG_INFO_sPLT 0x2000U  /* ESR, 1.0.6 */\n#define PNG_INFO_sCAL 0x4000U  /* ESR, 1.0.6 */\n#define PNG_INFO_IDAT 0x8000U  /* ESR, 1.0.6 */\n\n/* This is used for the transformation routines, as some of them\n * change these values for the row.  It also should enable using\n * the routines for other purposes.\n */\ntypedef struct png_row_info_struct\n{\n   png_uint_32 width;    /* width of row */\n   png_size_t rowbytes;  /* number of bytes in row */\n   png_byte color_type;  /* color type of row */\n   png_byte bit_depth;   /* bit depth of row */\n   png_byte channels;    /* number of channels (1, 2, 3, or 4) */\n   png_byte pixel_depth; /* bits per pixel (depth * channels) */\n} png_row_info;\n\ntypedef png_row_info * png_row_infop;\ntypedef png_row_info * * png_row_infopp;\n\n/* These are the function types for the I/O functions and for the functions\n * that allow the user to override the default I/O functions with his or her\n * own.  The png_error_ptr type should match that of user-supplied warning\n * and error functions, while the png_rw_ptr type should match that of the\n * user read/write data functions.  Note that the 'write' function must not\n * modify the buffer it is passed. The 'read' function, on the other hand, is\n * expected to return the read data in the buffer.\n */\ntypedef PNG_CALLBACK(void, *png_error_ptr, (png_structp, png_const_charp));\ntypedef PNG_CALLBACK(void, *png_rw_ptr, (png_structp, png_bytep, png_size_t));\ntypedef PNG_CALLBACK(void, *png_flush_ptr, (png_structp));\ntypedef PNG_CALLBACK(void, *png_read_status_ptr, (png_structp, png_uint_32,\n    int));\ntypedef PNG_CALLBACK(void, *png_write_status_ptr, (png_structp, png_uint_32,\n    int));\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\ntypedef PNG_CALLBACK(void, *png_progressive_info_ptr, (png_structp, png_infop));\ntypedef PNG_CALLBACK(void, *png_progressive_end_ptr, (png_structp, png_infop));\n\n/* The following callback receives png_uint_32 row_number, int pass for the\n * png_bytep data of the row.  When transforming an interlaced image the\n * row number is the row number within the sub-image of the interlace pass, so\n * the value will increase to the height of the sub-image (not the full image)\n * then reset to 0 for the next pass.\n *\n * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\n * find the output pixel (x,y) given an interlaced sub-image pixel\n * (row,col,pass).  (See below for these macros.)\n */\ntypedef PNG_CALLBACK(void, *png_progressive_row_ptr, (png_structp, png_bytep,\n    png_uint_32, int));\n#endif\n\n#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \\\n    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)\ntypedef PNG_CALLBACK(void, *png_user_transform_ptr, (png_structp, png_row_infop,\n    png_bytep));\n#endif\n\n#ifdef PNG_USER_CHUNKS_SUPPORTED\ntypedef PNG_CALLBACK(int, *png_user_chunk_ptr, (png_structp,\n    png_unknown_chunkp));\n#endif\n#ifdef PNG_UNKNOWN_CHUNKS_SUPPORTED\n/* not used anywhere */\n/* typedef PNG_CALLBACK(void, *png_unknown_chunk_ptr, (png_structp)); */\n#endif\n\n#ifdef PNG_SETJMP_SUPPORTED\n/* This must match the function definition in <setjmp.h>, and the application\n * must include this before png.h to obtain the definition of jmp_buf.  The\n * function is required to be PNG_NORETURN, but this is not checked.  If the\n * function does return the application will crash via an abort() or similar\n * system level call.\n *\n * If you get a warning here while building the library you may need to make\n * changes to ensure that pnglibconf.h records the calling convention used by\n * your compiler.  This may be very difficult - try using a different compiler\n * to build the library!\n */\nPNG_FUNCTION(void, (PNGCAPI *png_longjmp_ptr), PNGARG((jmp_buf, int)), typedef);\n#endif\n\n/* Transform masks for the high-level interface */\n#define PNG_TRANSFORM_IDENTITY       0x0000    /* read and write */\n#define PNG_TRANSFORM_STRIP_16       0x0001    /* read only */\n#define PNG_TRANSFORM_STRIP_ALPHA    0x0002    /* read only */\n#define PNG_TRANSFORM_PACKING        0x0004    /* read and write */\n#define PNG_TRANSFORM_PACKSWAP       0x0008    /* read and write */\n#define PNG_TRANSFORM_EXPAND         0x0010    /* read only */\n#define PNG_TRANSFORM_INVERT_MONO    0x0020    /* read and write */\n#define PNG_TRANSFORM_SHIFT          0x0040    /* read and write */\n#define PNG_TRANSFORM_BGR            0x0080    /* read and write */\n#define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */\n#define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */\n#define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */\n#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* write only */\n/* Added to libpng-1.2.34 */\n#define PNG_TRANSFORM_STRIP_FILLER_BEFORE PNG_TRANSFORM_STRIP_FILLER\n#define PNG_TRANSFORM_STRIP_FILLER_AFTER 0x1000 /* write only */\n/* Added to libpng-1.4.0 */\n#define PNG_TRANSFORM_GRAY_TO_RGB   0x2000      /* read only */\n/* Added to libpng-1.5.4 */\n#define PNG_TRANSFORM_EXPAND_16     0x4000      /* read only */\n#if INT_MAX >= 0x8000 /* else this might break */\n#define PNG_TRANSFORM_SCALE_16      0x8000      /* read only */\n#endif\n\n/* Flags for MNG supported features */\n#define PNG_FLAG_MNG_EMPTY_PLTE     0x01\n#define PNG_FLAG_MNG_FILTER_64      0x04\n#define PNG_ALL_MNG_FEATURES        0x05\n\n/* NOTE: prior to 1.5 these functions had no 'API' style declaration,\n * this allowed the zlib default functions to be used on Windows\n * platforms.  In 1.5 the zlib default malloc (which just calls malloc and\n * ignores the first argument) should be completely compatible with the\n * following.\n */\ntypedef PNG_CALLBACK(png_voidp, *png_malloc_ptr, (png_structp,\n    png_alloc_size_t));\ntypedef PNG_CALLBACK(void, *png_free_ptr, (png_structp, png_voidp));\n\n/* Section 4: exported functions\n * Here are the function definitions most commonly used.  This is not\n * the place to find out how to use libpng.  See libpng-manual.txt for the\n * full explanation, see example.c for the summary.  This just provides\n * a simple one line description of the use of each function.\n *\n * The PNG_EXPORT() and PNG_EXPORTA() macros used below are defined in\n * pngconf.h and in the *.dfn files in the scripts directory.\n *\n *   PNG_EXPORT(ordinal, type, name, (args));\n *\n *       ordinal:    ordinal that is used while building\n *                   *.def files. The ordinal value is only\n *                   relevant when preprocessing png.h with\n *                   the *.dfn files for building symbol table\n *                   entries, and are removed by pngconf.h.\n *       type:       return type of the function\n *       name:       function name\n *       args:       function arguments, with types\n *\n * When we wish to append attributes to a function prototype we use\n * the PNG_EXPORTA() macro instead.\n *\n *   PNG_EXPORTA(ordinal, type, name, (args), attributes);\n *\n *       ordinal, type, name, and args: same as in PNG_EXPORT().\n *       attributes: function attributes\n */\n\n/* Returns the version number of the library */\nPNG_EXPORT(1, png_uint_32, png_access_version_number, (void));\n\n/* Tell lib we have already handled the first <num_bytes> magic bytes.\n * Handling more than 8 bytes from the beginning of the file is an error.\n */\nPNG_EXPORT(2, void, png_set_sig_bytes, (png_structrp png_ptr, int num_bytes));\n\n/* Check sig[start] through sig[start + num_to_check - 1] to see if it's a\n * PNG file.  Returns zero if the supplied bytes match the 8-byte PNG\n * signature, and non-zero otherwise.  Having num_to_check == 0 or\n * start > 7 will always fail (ie return non-zero).\n */\nPNG_EXPORT(3, int, png_sig_cmp, (png_const_bytep sig, png_size_t start,\n    png_size_t num_to_check));\n\n/* Simple signature checking function.  This is the same as calling\n * png_check_sig(sig, n) := !png_sig_cmp(sig, 0, n).\n */\n#define png_check_sig(sig, n) !png_sig_cmp((sig), 0, (n))\n\n/* Allocate and initialize png_ptr struct for reading, and any other memory. */\nPNG_EXPORTA(4, png_structp, png_create_read_struct,\n    (png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn),\n    PNG_ALLOCATED);\n\n/* Allocate and initialize png_ptr struct for writing, and any other memory */\nPNG_EXPORTA(5, png_structp, png_create_write_struct,\n    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,\n    png_error_ptr warn_fn),\n    PNG_ALLOCATED);\n\nPNG_EXPORT(6, png_size_t, png_get_compression_buffer_size,\n    (png_const_structrp png_ptr));\n\nPNG_EXPORT(7, void, png_set_compression_buffer_size, (png_structrp png_ptr,\n    png_size_t size));\n\n/* Moved from pngconf.h in 1.4.0 and modified to ensure setjmp/longjmp\n * match up.\n */\n#ifdef PNG_SETJMP_SUPPORTED\n/* This function returns the jmp_buf built in to *png_ptr.  It must be\n * supplied with an appropriate 'longjmp' function to use on that jmp_buf\n * unless the default error function is overridden in which case NULL is\n * acceptable.  The size of the jmp_buf is checked against the actual size\n * allocated by the library - the call will return NULL on a mismatch\n * indicating an ABI mismatch.\n */\nPNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr,\n    png_longjmp_ptr longjmp_fn, size_t jmp_buf_size));\n#  define png_jmpbuf(png_ptr) \\\n      (*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf))))\n#else\n#  define png_jmpbuf(png_ptr) \\\n      (LIBPNG_WAS_COMPILED_WITH__PNG_NO_SETJMP)\n#endif\n/* This function should be used by libpng applications in place of\n * longjmp(png_ptr->jmpbuf, val).  If longjmp_fn() has been set, it\n * will use it; otherwise it will call PNG_ABORT().  This function was\n * added in libpng-1.5.0.\n */\nPNG_EXPORTA(9, void, png_longjmp, (png_const_structrp png_ptr, int val),\n    PNG_NORETURN);\n\n#ifdef PNG_READ_SUPPORTED\n/* Reset the compression stream */\nPNG_EXPORTA(10, int, png_reset_zstream, (png_structrp png_ptr), PNG_DEPRECATED);\n#endif\n\n/* New functions added in libpng-1.0.2 (not enabled by default until 1.2.0) */\n#ifdef PNG_USER_MEM_SUPPORTED\nPNG_EXPORTA(11, png_structp, png_create_read_struct_2,\n    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,\n    png_error_ptr warn_fn,\n    png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),\n    PNG_ALLOCATED);\nPNG_EXPORTA(12, png_structp, png_create_write_struct_2,\n    (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,\n    png_error_ptr warn_fn,\n    png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn),\n    PNG_ALLOCATED);\n#endif\n\n/* Write the PNG file signature. */\nPNG_EXPORT(13, void, png_write_sig, (png_structrp png_ptr));\n\n/* Write a PNG chunk - size, type, (optional) data, CRC. */\nPNG_EXPORT(14, void, png_write_chunk, (png_structrp png_ptr, png_const_bytep\n    chunk_name, png_const_bytep data, png_size_t length));\n\n/* Write the start of a PNG chunk - length and chunk name. */\nPNG_EXPORT(15, void, png_write_chunk_start, (png_structrp png_ptr,\n    png_const_bytep chunk_name, png_uint_32 length));\n\n/* Write the data of a PNG chunk started with png_write_chunk_start(). */\nPNG_EXPORT(16, void, png_write_chunk_data, (png_structrp png_ptr,\n    png_const_bytep data, png_size_t length));\n\n/* Finish a chunk started with png_write_chunk_start() (includes CRC). */\nPNG_EXPORT(17, void, png_write_chunk_end, (png_structrp png_ptr));\n\n/* Allocate and initialize the info structure */\nPNG_EXPORTA(18, png_infop, png_create_info_struct, (png_const_structrp png_ptr),\n    PNG_ALLOCATED);\n\n/* DEPRECATED: this function allowed init structures to be created using the\n * default allocation method (typically malloc).  Use is deprecated in 1.6.0 and\n * the API will be removed in the future.\n */\nPNG_EXPORTA(19, void, png_info_init_3, (png_infopp info_ptr,\n    png_size_t png_info_struct_size), PNG_DEPRECATED);\n\n/* Writes all the PNG information before the image. */\nPNG_EXPORT(20, void, png_write_info_before_PLTE,\n    (png_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(21, void, png_write_info,\n    (png_structrp png_ptr, png_const_inforp info_ptr));\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the information before the actual image data. */\nPNG_EXPORT(22, void, png_read_info,\n    (png_structrp png_ptr, png_inforp info_ptr));\n#endif\n\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n   /* Convert to a US string format: there is no localization support in this\n    * routine.  The original implementation used a 29 character buffer in\n    * png_struct, this will be removed in future versions.\n    */\n#if PNG_LIBPNG_VER < 10700\n/* To do: remove this from libpng17 (and from libpng17/png.c and pngstruct.h) */\nPNG_EXPORTA(23, png_const_charp, png_convert_to_rfc1123, (png_structrp png_ptr,\n    png_const_timep ptime),PNG_DEPRECATED);\n#endif\nPNG_EXPORT(241, int, png_convert_to_rfc1123_buffer, (char out[29],\n    png_const_timep ptime));\n#endif\n\n#ifdef PNG_CONVERT_tIME_SUPPORTED\n/* Convert from a struct tm to png_time */\nPNG_EXPORT(24, void, png_convert_from_struct_tm, (png_timep ptime,\n    const struct tm * ttime));\n\n/* Convert from time_t to png_time.  Uses gmtime() */\nPNG_EXPORT(25, void, png_convert_from_time_t, (png_timep ptime, time_t ttime));\n#endif /* CONVERT_tIME */\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* Expand data to 24-bit RGB, or 8-bit grayscale, with alpha if available. */\nPNG_EXPORT(26, void, png_set_expand, (png_structrp png_ptr));\nPNG_EXPORT(27, void, png_set_expand_gray_1_2_4_to_8, (png_structrp png_ptr));\nPNG_EXPORT(28, void, png_set_palette_to_rgb, (png_structrp png_ptr));\nPNG_EXPORT(29, void, png_set_tRNS_to_alpha, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n/* Expand to 16-bit channels, forces conversion of palette to RGB and expansion\n * of a tRNS chunk if present.\n */\nPNG_EXPORT(221, void, png_set_expand_16, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)\n/* Use blue, green, red order for pixels. */\nPNG_EXPORT(30, void, png_set_bgr, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n/* Expand the grayscale to 24-bit RGB if necessary. */\nPNG_EXPORT(31, void, png_set_gray_to_rgb, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n/* Reduce RGB to grayscale. */\n#define PNG_ERROR_ACTION_NONE  1\n#define PNG_ERROR_ACTION_WARN  2\n#define PNG_ERROR_ACTION_ERROR 3\n#define PNG_RGB_TO_GRAY_DEFAULT (-1)/*for red/green coefficients*/\n\nPNG_FP_EXPORT(32, void, png_set_rgb_to_gray, (png_structrp png_ptr,\n    int error_action, double red, double green))\nPNG_FIXED_EXPORT(33, void, png_set_rgb_to_gray_fixed, (png_structrp png_ptr,\n    int error_action, png_fixed_point red, png_fixed_point green))\n\nPNG_EXPORT(34, png_byte, png_get_rgb_to_gray_status, (png_const_structrp\n    png_ptr));\n#endif\n\n#ifdef PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED\nPNG_EXPORT(35, void, png_build_grayscale_palette, (int bit_depth,\n    png_colorp palette));\n#endif\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n/* How the alpha channel is interpreted - this affects how the color channels\n * of a PNG file are returned to the calling application when an alpha channel,\n * or a tRNS chunk in a palette file, is present.\n *\n * This has no effect on the way pixels are written into a PNG output\n * datastream. The color samples in a PNG datastream are never premultiplied\n * with the alpha samples.\n *\n * The default is to return data according to the PNG specification: the alpha\n * channel is a linear measure of the contribution of the pixel to the\n * corresponding composited pixel, and the color channels are unassociated\n * (not premultiplied).  The gamma encoded color channels must be scaled\n * according to the contribution and to do this it is necessary to undo\n * the encoding, scale the color values, perform the composition and reencode\n * the values.  This is the 'PNG' mode.\n *\n * The alternative is to 'associate' the alpha with the color information by\n * storing color channel values that have been scaled by the alpha.\n * image.  These are the 'STANDARD', 'ASSOCIATED' or 'PREMULTIPLIED' modes\n * (the latter being the two common names for associated alpha color channels).\n *\n * For the 'OPTIMIZED' mode, a pixel is treated as opaque only if the alpha\n * value is equal to the maximum value.\n *\n * The final choice is to gamma encode the alpha channel as well.  This is\n * broken because, in practice, no implementation that uses this choice\n * correctly undoes the encoding before handling alpha composition.  Use this\n * choice only if other serious errors in the software or hardware you use\n * mandate it; the typical serious error is for dark halos to appear around\n * opaque areas of the composited PNG image because of arithmetic overflow.\n *\n * The API function png_set_alpha_mode specifies which of these choices to use\n * with an enumerated 'mode' value and the gamma of the required output:\n */\n#define PNG_ALPHA_PNG           0 /* according to the PNG standard */\n#define PNG_ALPHA_STANDARD      1 /* according to Porter/Duff */\n#define PNG_ALPHA_ASSOCIATED    1 /* as above; this is the normal practice */\n#define PNG_ALPHA_PREMULTIPLIED 1 /* as above */\n#define PNG_ALPHA_OPTIMIZED     2 /* 'PNG' for opaque pixels, else 'STANDARD' */\n#define PNG_ALPHA_BROKEN        3 /* the alpha channel is gamma encoded */\n\nPNG_FP_EXPORT(227, void, png_set_alpha_mode, (png_structrp png_ptr, int mode,\n    double output_gamma))\nPNG_FIXED_EXPORT(228, void, png_set_alpha_mode_fixed, (png_structrp png_ptr,\n    int mode, png_fixed_point output_gamma))\n#endif\n\n#if defined(PNG_GAMMA_SUPPORTED) || defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n/* The output_gamma value is a screen gamma in libpng terminology: it expresses\n * how to decode the output values, not how they are encoded.\n */\n#define PNG_DEFAULT_sRGB -1       /* sRGB gamma and color space */\n#define PNG_GAMMA_MAC_18 -2       /* Old Mac '1.8' gamma and color space */\n#define PNG_GAMMA_sRGB   220000   /* Television standards--matches sRGB gamma */\n#define PNG_GAMMA_LINEAR PNG_FP_1 /* Linear */\n#endif\n\n/* The following are examples of calls to png_set_alpha_mode to achieve the\n * required overall gamma correction and, where necessary, alpha\n * premultiplication.\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n *    This is the default libpng handling of the alpha channel - it is not\n *    pre-multiplied into the color components.  In addition the call states\n *    that the output is for a sRGB system and causes all PNG files without gAMA\n *    chunks to be assumed to be encoded using sRGB.\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n *    In this case the output is assumed to be something like an sRGB conformant\n *    display preceeded by a power-law lookup table of power 1.45.  This is how\n *    early Mac systems behaved.\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_GAMMA_LINEAR);\n *    This is the classic Jim Blinn approach and will work in academic\n *    environments where everything is done by the book.  It has the shortcoming\n *    of assuming that input PNG data with no gamma information is linear - this\n *    is unlikely to be correct unless the PNG files where generated locally.\n *    Most of the time the output precision will be so low as to show\n *    significant banding in dark areas of the image.\n *\n * png_set_expand_16(pp);\n * png_set_alpha_mode(pp, PNG_ALPHA_STANDARD, PNG_DEFAULT_sRGB);\n *    This is a somewhat more realistic Jim Blinn inspired approach.  PNG files\n *    are assumed to have the sRGB encoding if not marked with a gamma value and\n *    the output is always 16 bits per component.  This permits accurate scaling\n *    and processing of the data.  If you know that your input PNG files were\n *    generated locally you might need to replace PNG_DEFAULT_sRGB with the\n *    correct value for your system.\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_OPTIMIZED, PNG_DEFAULT_sRGB);\n *    If you just need to composite the PNG image onto an existing background\n *    and if you control the code that does this you can use the optimization\n *    setting.  In this case you just copy completely opaque pixels to the\n *    output.  For pixels that are not completely transparent (you just skip\n *    those) you do the composition math using png_composite or png_composite_16\n *    below then encode the resultant 8-bit or 16-bit values to match the output\n *    encoding.\n *\n * Other cases\n *    If neither the PNG nor the standard linear encoding work for you because\n *    of the software or hardware you use then you have a big problem.  The PNG\n *    case will probably result in halos around the image.  The linear encoding\n *    will probably result in a washed out, too bright, image (it's actually too\n *    contrasty.)  Try the ALPHA_OPTIMIZED mode above - this will probably\n *    substantially reduce the halos.  Alternatively try:\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_BROKEN, PNG_DEFAULT_sRGB);\n *    This option will also reduce the halos, but there will be slight dark\n *    halos round the opaque parts of the image where the background is light.\n *    In the OPTIMIZED mode the halos will be light halos where the background\n *    is dark.  Take your pick - the halos are unavoidable unless you can get\n *    your hardware/software fixed!  (The OPTIMIZED approach is slightly\n *    faster.)\n *\n * When the default gamma of PNG files doesn't match the output gamma.\n *    If you have PNG files with no gamma information png_set_alpha_mode allows\n *    you to provide a default gamma, but it also sets the ouput gamma to the\n *    matching value.  If you know your PNG files have a gamma that doesn't\n *    match the output you can take advantage of the fact that\n *    png_set_alpha_mode always sets the output gamma but only sets the PNG\n *    default if it is not already set:\n *\n * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_DEFAULT_sRGB);\n * png_set_alpha_mode(pp, PNG_ALPHA_PNG, PNG_GAMMA_MAC);\n *    The first call sets both the default and the output gamma values, the\n *    second call overrides the output gamma without changing the default.  This\n *    is easier than achieving the same effect with png_set_gamma.  You must use\n *    PNG_ALPHA_PNG for the first call - internal checking in png_set_alpha will\n *    fire if more than one call to png_set_alpha_mode and png_set_background is\n *    made in the same read operation, however multiple calls with PNG_ALPHA_PNG\n *    are ignored.\n */\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\nPNG_EXPORT(36, void, png_set_strip_alpha, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \\\n    defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)\nPNG_EXPORT(37, void, png_set_swap_alpha, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \\\n    defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)\nPNG_EXPORT(38, void, png_set_invert_alpha, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)\n/* Add a filler byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */\nPNG_EXPORT(39, void, png_set_filler, (png_structrp png_ptr, png_uint_32 filler,\n    int flags));\n/* The values of the PNG_FILLER_ defines should NOT be changed */\n#  define PNG_FILLER_BEFORE 0\n#  define PNG_FILLER_AFTER 1\n/* Add an alpha byte to 8-bit or 16-bit Gray or 24-bit or 48-bit RGB images. */\nPNG_EXPORT(40, void, png_set_add_alpha, (png_structrp png_ptr,\n    png_uint_32 filler, int flags));\n#endif /* READ_FILLER || WRITE_FILLER */\n\n#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)\n/* Swap bytes in 16-bit depth files. */\nPNG_EXPORT(41, void, png_set_swap, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n/* Use 1 byte per pixel in 1, 2, or 4-bit depth files. */\nPNG_EXPORT(42, void, png_set_packing, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \\\n    defined(PNG_WRITE_PACKSWAP_SUPPORTED)\n/* Swap packing order of pixels in bytes. */\nPNG_EXPORT(43, void, png_set_packswap, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)\n/* Converts files to legal bit depths. */\nPNG_EXPORT(44, void, png_set_shift, (png_structrp png_ptr, png_const_color_8p\n    true_bits));\n#endif\n\n#if defined(PNG_READ_INTERLACING_SUPPORTED) || \\\n    defined(PNG_WRITE_INTERLACING_SUPPORTED)\n/* Have the code handle the interlacing.  Returns the number of passes.\n * MUST be called before png_read_update_info or png_start_read_image,\n * otherwise it will not have the desired effect.  Note that it is still\n * necessary to call png_read_row or png_read_rows png_get_image_height\n * times for each pass.\n*/\nPNG_EXPORT(45, int, png_set_interlace_handling, (png_structrp png_ptr));\n#endif\n\n#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)\n/* Invert monochrome files */\nPNG_EXPORT(46, void, png_set_invert_mono, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n/* Handle alpha and tRNS by replacing with a background color.  Prior to\n * libpng-1.5.4 this API must not be called before the PNG file header has been\n * read.  Doing so will result in unexpected behavior and possible warnings or\n * errors if the PNG file contains a bKGD chunk.\n */\nPNG_FP_EXPORT(47, void, png_set_background, (png_structrp png_ptr,\n    png_const_color_16p background_color, int background_gamma_code,\n    int need_expand, double background_gamma))\nPNG_FIXED_EXPORT(215, void, png_set_background_fixed, (png_structrp png_ptr,\n    png_const_color_16p background_color, int background_gamma_code,\n    int need_expand, png_fixed_point background_gamma))\n#endif\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n#  define PNG_BACKGROUND_GAMMA_UNKNOWN 0\n#  define PNG_BACKGROUND_GAMMA_SCREEN  1\n#  define PNG_BACKGROUND_GAMMA_FILE    2\n#  define PNG_BACKGROUND_GAMMA_UNIQUE  3\n#endif\n\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n/* Scale a 16-bit depth file down to 8-bit, accurately. */\nPNG_EXPORT(229, void, png_set_scale_16, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n#define PNG_READ_16_TO_8_SUPPORTED /* Name prior to 1.5.4 */\n/* Strip the second byte of information from a 16-bit depth file. */\nPNG_EXPORT(48, void, png_set_strip_16, (png_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n/* Turn on quantizing, and reduce the palette to the number of colors\n * available.\n */\nPNG_EXPORT(49, void, png_set_quantize, (png_structrp png_ptr,\n    png_colorp palette, int num_palette, int maximum_colors,\n    png_const_uint_16p histogram, int full_quantize));\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* The threshold on gamma processing is configurable but hard-wired into the\n * library.  The following is the floating point variant.\n */\n#define PNG_GAMMA_THRESHOLD (PNG_GAMMA_THRESHOLD_FIXED*.00001)\n\n/* Handle gamma correction. Screen_gamma=(display_exponent).\n * NOTE: this API simply sets the screen and file gamma values. It will\n * therefore override the value for gamma in a PNG file if it is called after\n * the file header has been read - use with care  - call before reading the PNG\n * file for best results!\n *\n * These routines accept the same gamma values as png_set_alpha_mode (described\n * above).  The PNG_GAMMA_ defines and PNG_DEFAULT_sRGB can be passed to either\n * API (floating point or fixed.)  Notice, however, that the 'file_gamma' value\n * is the inverse of a 'screen gamma' value.\n */\nPNG_FP_EXPORT(50, void, png_set_gamma, (png_structrp png_ptr,\n    double screen_gamma, double override_file_gamma))\nPNG_FIXED_EXPORT(208, void, png_set_gamma_fixed, (png_structrp png_ptr,\n    png_fixed_point screen_gamma, png_fixed_point override_file_gamma))\n#endif\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n/* Set how many lines between output flushes - 0 for no flushing */\nPNG_EXPORT(51, void, png_set_flush, (png_structrp png_ptr, int nrows));\n/* Flush the current PNG output buffer */\nPNG_EXPORT(52, void, png_write_flush, (png_structrp png_ptr));\n#endif\n\n/* Optional update palette with requested transformations */\nPNG_EXPORT(53, void, png_start_read_image, (png_structrp png_ptr));\n\n/* Optional call to update the users info structure */\nPNG_EXPORT(54, void, png_read_update_info, (png_structrp png_ptr,\n    png_inforp info_ptr));\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read one or more rows of image data. */\nPNG_EXPORT(55, void, png_read_rows, (png_structrp png_ptr, png_bytepp row,\n    png_bytepp display_row, png_uint_32 num_rows));\n#endif\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read a row of data. */\nPNG_EXPORT(56, void, png_read_row, (png_structrp png_ptr, png_bytep row,\n    png_bytep display_row));\n#endif\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the whole image into memory at once. */\nPNG_EXPORT(57, void, png_read_image, (png_structrp png_ptr, png_bytepp image));\n#endif\n\n/* Write a row of image data */\nPNG_EXPORT(58, void, png_write_row, (png_structrp png_ptr,\n    png_const_bytep row));\n\n/* Write a few rows of image data: (*row) is not written; however, the type\n * is declared as writeable to maintain compatibility with previous versions\n * of libpng and to allow the 'display_row' array from read_rows to be passed\n * unchanged to write_rows.\n */\nPNG_EXPORT(59, void, png_write_rows, (png_structrp png_ptr, png_bytepp row,\n    png_uint_32 num_rows));\n\n/* Write the image data */\nPNG_EXPORT(60, void, png_write_image, (png_structrp png_ptr, png_bytepp image));\n\n/* Write the end of the PNG file. */\nPNG_EXPORT(61, void, png_write_end, (png_structrp png_ptr,\n    png_inforp info_ptr));\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the end of the PNG file. */\nPNG_EXPORT(62, void, png_read_end, (png_structrp png_ptr, png_inforp info_ptr));\n#endif\n\n/* Free any memory associated with the png_info_struct */\nPNG_EXPORT(63, void, png_destroy_info_struct, (png_const_structrp png_ptr,\n    png_infopp info_ptr_ptr));\n\n/* Free any memory associated with the png_struct and the png_info_structs */\nPNG_EXPORT(64, void, png_destroy_read_struct, (png_structpp png_ptr_ptr,\n    png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));\n\n/* Free any memory associated with the png_struct and the png_info_structs */\nPNG_EXPORT(65, void, png_destroy_write_struct, (png_structpp png_ptr_ptr,\n    png_infopp info_ptr_ptr));\n\n/* Set the libpng method of handling chunk CRC errors */\nPNG_EXPORT(66, void, png_set_crc_action, (png_structrp png_ptr, int crit_action,\n    int ancil_action));\n\n/* Values for png_set_crc_action() say how to handle CRC errors in\n * ancillary and critical chunks, and whether to use the data contained\n * therein.  Note that it is impossible to \"discard\" data in a critical\n * chunk.  For versions prior to 0.90, the action was always error/quit,\n * whereas in version 0.90 and later, the action for CRC errors in ancillary\n * chunks is warn/discard.  These values should NOT be changed.\n *\n *      value                       action:critical     action:ancillary\n */\n#define PNG_CRC_DEFAULT       0  /* error/quit          warn/discard data */\n#define PNG_CRC_ERROR_QUIT    1  /* error/quit          error/quit        */\n#define PNG_CRC_WARN_DISCARD  2  /* (INVALID)           warn/discard data */\n#define PNG_CRC_WARN_USE      3  /* warn/use data       warn/use data     */\n#define PNG_CRC_QUIET_USE     4  /* quiet/use data      quiet/use data    */\n#define PNG_CRC_NO_CHANGE     5  /* use current value   use current value */\n\n#ifdef PNG_WRITE_SUPPORTED\n/* These functions give the user control over the scan-line filtering in\n * libpng and the compression methods used by zlib.  These functions are\n * mainly useful for testing, as the defaults should work with most users.\n * Those users who are tight on memory or want faster performance at the\n * expense of compression can modify them.  See the compression library\n * header file (zlib.h) for an explination of the compression functions.\n */\n\n/* Set the filtering method(s) used by libpng.  Currently, the only valid\n * value for \"method\" is 0.\n */\nPNG_EXPORT(67, void, png_set_filter, (png_structrp png_ptr, int method,\n    int filters));\n#endif /* WRITE */\n\n/* Flags for png_set_filter() to say which filters to use.  The flags\n * are chosen so that they don't conflict with real filter types\n * below, in case they are supplied instead of the #defined constants.\n * These values should NOT be changed.\n */\n#define PNG_NO_FILTERS     0x00\n#define PNG_FILTER_NONE    0x08\n#define PNG_FILTER_SUB     0x10\n#define PNG_FILTER_UP      0x20\n#define PNG_FILTER_AVG     0x40\n#define PNG_FILTER_PAETH   0x80\n#define PNG_FAST_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP)\n#define PNG_ALL_FILTERS (PNG_FAST_FILTERS | PNG_FILTER_AVG | PNG_FILTER_PAETH)\n\n/* Filter values (not flags) - used in pngwrite.c, pngwutil.c for now.\n * These defines should NOT be changed.\n */\n#define PNG_FILTER_VALUE_NONE  0\n#define PNG_FILTER_VALUE_SUB   1\n#define PNG_FILTER_VALUE_UP    2\n#define PNG_FILTER_VALUE_AVG   3\n#define PNG_FILTER_VALUE_PAETH 4\n#define PNG_FILTER_VALUE_LAST  5\n\n#ifdef PNG_WRITE_SUPPORTED\n#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */\nPNG_FP_EXPORT(68, void, png_set_filter_heuristics, (png_structrp png_ptr,\n    int heuristic_method, int num_weights, png_const_doublep filter_weights,\n    png_const_doublep filter_costs))\nPNG_FIXED_EXPORT(209, void, png_set_filter_heuristics_fixed,\n    (png_structrp png_ptr, int heuristic_method, int num_weights,\n    png_const_fixed_point_p filter_weights,\n    png_const_fixed_point_p filter_costs))\n#endif /* WRITE_WEIGHTED_FILTER */\n\n/* The following are no longer used and will be removed from libpng-1.7: */\n#define PNG_FILTER_HEURISTIC_DEFAULT    0  /* Currently \"UNWEIGHTED\" */\n#define PNG_FILTER_HEURISTIC_UNWEIGHTED 1  /* Used by libpng < 0.95 */\n#define PNG_FILTER_HEURISTIC_WEIGHTED   2  /* Experimental feature */\n#define PNG_FILTER_HEURISTIC_LAST       3  /* Not a valid value */\n\n/* Set the library compression level.  Currently, valid values range from\n * 0 - 9, corresponding directly to the zlib compression levels 0 - 9\n * (0 - no compression, 9 - \"maximal\" compression).  Note that tests have\n * shown that zlib compression levels 3-6 usually perform as well as level 9\n * for PNG images, and do considerably fewer caclulations.  In the future,\n * these values may not correspond directly to the zlib compression levels.\n */\n#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\nPNG_EXPORT(69, void, png_set_compression_level, (png_structrp png_ptr,\n    int level));\n\nPNG_EXPORT(70, void, png_set_compression_mem_level, (png_structrp png_ptr,\n    int mem_level));\n\nPNG_EXPORT(71, void, png_set_compression_strategy, (png_structrp png_ptr,\n    int strategy));\n\n/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a\n * smaller value of window_bits if it can do so safely.\n */\nPNG_EXPORT(72, void, png_set_compression_window_bits, (png_structrp png_ptr,\n    int window_bits));\n\nPNG_EXPORT(73, void, png_set_compression_method, (png_structrp png_ptr,\n    int method));\n#endif /* WRITE_CUSTOMIZE_COMPRESSION */\n\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n/* Also set zlib parameters for compressing non-IDAT chunks */\nPNG_EXPORT(222, void, png_set_text_compression_level, (png_structrp png_ptr,\n    int level));\n\nPNG_EXPORT(223, void, png_set_text_compression_mem_level, (png_structrp png_ptr,\n    int mem_level));\n\nPNG_EXPORT(224, void, png_set_text_compression_strategy, (png_structrp png_ptr,\n    int strategy));\n\n/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a\n * smaller value of window_bits if it can do so safely.\n */\nPNG_EXPORT(225, void, png_set_text_compression_window_bits,\n    (png_structrp png_ptr, int window_bits));\n\nPNG_EXPORT(226, void, png_set_text_compression_method, (png_structrp png_ptr,\n    int method));\n#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */\n#endif /* WRITE */\n\n/* These next functions are called for input/output, memory, and error\n * handling.  They are in the file pngrio.c, pngwio.c, and pngerror.c,\n * and call standard C I/O routines such as fread(), fwrite(), and\n * fprintf().  These functions can be made to use other I/O routines\n * at run time for those applications that need to handle I/O in a\n * different manner by calling png_set_???_fn().  See libpng-manual.txt for\n * more information.\n */\n\n#ifdef PNG_STDIO_SUPPORTED\n/* Initialize the input/output for the PNG file to the default functions. */\nPNG_EXPORT(74, void, png_init_io, (png_structrp png_ptr, png_FILE_p fp));\n#endif\n\n/* Replace the (error and abort), and warning functions with user\n * supplied functions.  If no messages are to be printed you must still\n * write and use replacement functions. The replacement error_fn should\n * still do a longjmp to the last setjmp location if you are using this\n * method of error handling.  If error_fn or warning_fn is NULL, the\n * default function will be used.\n */\n\nPNG_EXPORT(75, void, png_set_error_fn, (png_structrp png_ptr,\n    png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));\n\n/* Return the user pointer associated with the error functions */\nPNG_EXPORT(76, png_voidp, png_get_error_ptr, (png_const_structrp png_ptr));\n\n/* Replace the default data output functions with a user supplied one(s).\n * If buffered output is not used, then output_flush_fn can be set to NULL.\n * If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time\n * output_flush_fn will be ignored (and thus can be NULL).\n * It is probably a mistake to use NULL for output_flush_fn if\n * write_data_fn is not also NULL unless you have built libpng with\n * PNG_WRITE_FLUSH_SUPPORTED undefined, because in this case libpng's\n * default flush function, which uses the standard *FILE structure, will\n * be used.\n */\nPNG_EXPORT(77, void, png_set_write_fn, (png_structrp png_ptr, png_voidp io_ptr,\n    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));\n\n/* Replace the default data input function with a user supplied one. */\nPNG_EXPORT(78, void, png_set_read_fn, (png_structrp png_ptr, png_voidp io_ptr,\n    png_rw_ptr read_data_fn));\n\n/* Return the user pointer associated with the I/O functions */\nPNG_EXPORT(79, png_voidp, png_get_io_ptr, (png_const_structrp png_ptr));\n\nPNG_EXPORT(80, void, png_set_read_status_fn, (png_structrp png_ptr,\n    png_read_status_ptr read_row_fn));\n\nPNG_EXPORT(81, void, png_set_write_status_fn, (png_structrp png_ptr,\n    png_write_status_ptr write_row_fn));\n\n#ifdef PNG_USER_MEM_SUPPORTED\n/* Replace the default memory allocation functions with user supplied one(s). */\nPNG_EXPORT(82, void, png_set_mem_fn, (png_structrp png_ptr, png_voidp mem_ptr,\n    png_malloc_ptr malloc_fn, png_free_ptr free_fn));\n/* Return the user pointer associated with the memory functions */\nPNG_EXPORT(83, png_voidp, png_get_mem_ptr, (png_const_structrp png_ptr));\n#endif\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\nPNG_EXPORT(84, void, png_set_read_user_transform_fn, (png_structrp png_ptr,\n    png_user_transform_ptr read_user_transform_fn));\n#endif\n\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\nPNG_EXPORT(85, void, png_set_write_user_transform_fn, (png_structrp png_ptr,\n    png_user_transform_ptr write_user_transform_fn));\n#endif\n\n#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED\nPNG_EXPORT(86, void, png_set_user_transform_info, (png_structrp png_ptr,\n    png_voidp user_transform_ptr, int user_transform_depth,\n    int user_transform_channels));\n/* Return the user pointer associated with the user transform functions */\nPNG_EXPORT(87, png_voidp, png_get_user_transform_ptr,\n    (png_const_structrp png_ptr));\n#endif\n\n#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED\n/* Return information about the row currently being processed.  Note that these\n * APIs do not fail but will return unexpected results if called outside a user\n * transform callback.  Also note that when transforming an interlaced image the\n * row number is the row number within the sub-image of the interlace pass, so\n * the value will increase to the height of the sub-image (not the full image)\n * then reset to 0 for the next pass.\n *\n * Use PNG_ROW_FROM_PASS_ROW(row, pass) and PNG_COL_FROM_PASS_COL(col, pass) to\n * find the output pixel (x,y) given an interlaced sub-image pixel\n * (row,col,pass).  (See below for these macros.)\n */\nPNG_EXPORT(217, png_uint_32, png_get_current_row_number, (png_const_structrp));\nPNG_EXPORT(218, png_byte, png_get_current_pass_number, (png_const_structrp));\n#endif\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n/* This callback is called only for *unknown* chunks.  If\n * PNG_HANDLE_AS_UNKNOWN_SUPPORTED is set then it is possible to set known\n * chunks to be treated as unknown, however in this case the callback must do\n * any processing required by the chunk (e.g. by calling the appropriate\n * png_set_ APIs.)\n *\n * There is no write support - on write, by default, all the chunks in the\n * 'unknown' list are written in the specified position.\n *\n * The integer return from the callback function is interpreted thus:\n *\n * negative: An error occurred; png_chunk_error will be called.\n *     zero: The chunk was not handled, the chunk will be saved. A critical\n *           chunk will cause an error at this point unless it is to be saved.\n * positive: The chunk was handled, libpng will ignore/discard it.\n *\n * See \"INTERACTION WTIH USER CHUNK CALLBACKS\" below for important notes about\n * how this behavior will change in libpng 1.7\n */\nPNG_EXPORT(88, void, png_set_read_user_chunk_fn, (png_structrp png_ptr,\n    png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));\n#endif\n\n#ifdef PNG_USER_CHUNKS_SUPPORTED\nPNG_EXPORT(89, png_voidp, png_get_user_chunk_ptr, (png_const_structrp png_ptr));\n#endif\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\n/* Sets the function callbacks for the push reader, and a pointer to a\n * user-defined structure available to the callback functions.\n */\nPNG_EXPORT(90, void, png_set_progressive_read_fn, (png_structrp png_ptr,\n    png_voidp progressive_ptr, png_progressive_info_ptr info_fn,\n    png_progressive_row_ptr row_fn, png_progressive_end_ptr end_fn));\n\n/* Returns the user pointer associated with the push read functions */\nPNG_EXPORT(91, png_voidp, png_get_progressive_ptr,\n    (png_const_structrp png_ptr));\n\n/* Function to be called when data becomes available */\nPNG_EXPORT(92, void, png_process_data, (png_structrp png_ptr,\n    png_inforp info_ptr, png_bytep buffer, png_size_t buffer_size));\n\n/* A function which may be called *only* within png_process_data to stop the\n * processing of any more data.  The function returns the number of bytes\n * remaining, excluding any that libpng has cached internally.  A subsequent\n * call to png_process_data must supply these bytes again.  If the argument\n * 'save' is set to true the routine will first save all the pending data and\n * will always return 0.\n */\nPNG_EXPORT(219, png_size_t, png_process_data_pause, (png_structrp, int save));\n\n/* A function which may be called *only* outside (after) a call to\n * png_process_data.  It returns the number of bytes of data to skip in the\n * input.  Normally it will return 0, but if it returns a non-zero value the\n * application must skip than number of bytes of input data and pass the\n * following data to the next call to png_process_data.\n */\nPNG_EXPORT(220, png_uint_32, png_process_data_skip, (png_structrp));\n\n/* Function that combines rows.  'new_row' is a flag that should come from\n * the callback and be non-NULL if anything needs to be done; the library\n * stores its own version of the new data internally and ignores the passed\n * in value.\n */\nPNG_EXPORT(93, void, png_progressive_combine_row, (png_const_structrp png_ptr,\n    png_bytep old_row, png_const_bytep new_row));\n#endif /* PROGRESSIVE_READ */\n\nPNG_EXPORTA(94, png_voidp, png_malloc, (png_const_structrp png_ptr,\n    png_alloc_size_t size), PNG_ALLOCATED);\n/* Added at libpng version 1.4.0 */\nPNG_EXPORTA(95, png_voidp, png_calloc, (png_const_structrp png_ptr,\n    png_alloc_size_t size), PNG_ALLOCATED);\n\n/* Added at libpng version 1.2.4 */\nPNG_EXPORTA(96, png_voidp, png_malloc_warn, (png_const_structrp png_ptr,\n    png_alloc_size_t size), PNG_ALLOCATED);\n\n/* Frees a pointer allocated by png_malloc() */\nPNG_EXPORT(97, void, png_free, (png_const_structrp png_ptr, png_voidp ptr));\n\n/* Free data that was allocated internally */\nPNG_EXPORT(98, void, png_free_data, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 free_me, int num));\n\n/* Reassign responsibility for freeing existing data, whether allocated\n * by libpng or by the application; this works on the png_info structure passed\n * in, it does not change the state for other png_info structures.\n *\n * It is unlikely that this function works correctly as of 1.6.0 and using it\n * may result either in memory leaks or double free of allocated data.\n */\nPNG_EXPORT(99, void, png_data_freer, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int freer, png_uint_32 mask));\n\n/* Assignments for png_data_freer */\n#define PNG_DESTROY_WILL_FREE_DATA 1\n#define PNG_SET_WILL_FREE_DATA 1\n#define PNG_USER_WILL_FREE_DATA 2\n/* Flags for png_ptr->free_me and info_ptr->free_me */\n#define PNG_FREE_HIST 0x0008U\n#define PNG_FREE_ICCP 0x0010U\n#define PNG_FREE_SPLT 0x0020U\n#define PNG_FREE_ROWS 0x0040U\n#define PNG_FREE_PCAL 0x0080U\n#define PNG_FREE_SCAL 0x0100U\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n#  define PNG_FREE_UNKN 0x0200U\n#endif\n/*      PNG_FREE_LIST 0x0400U   removed in 1.6.0 because it is ignored */\n#define PNG_FREE_PLTE 0x1000U\n#define PNG_FREE_TRNS 0x2000U\n#define PNG_FREE_TEXT 0x4000U\n#define PNG_FREE_ALL  0x7fffU\n#define PNG_FREE_MUL  0x4220U /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */\n\n#ifdef PNG_USER_MEM_SUPPORTED\nPNG_EXPORTA(100, png_voidp, png_malloc_default, (png_const_structrp png_ptr,\n    png_alloc_size_t size), PNG_ALLOCATED PNG_DEPRECATED);\nPNG_EXPORTA(101, void, png_free_default, (png_const_structrp png_ptr,\n    png_voidp ptr), PNG_DEPRECATED);\n#endif\n\n#ifdef PNG_ERROR_TEXT_SUPPORTED\n/* Fatal error in PNG image of libpng - can't continue */\nPNG_EXPORTA(102, void, png_error, (png_const_structrp png_ptr,\n    png_const_charp error_message), PNG_NORETURN);\n\n/* The same, but the chunk name is prepended to the error string. */\nPNG_EXPORTA(103, void, png_chunk_error, (png_const_structrp png_ptr,\n    png_const_charp error_message), PNG_NORETURN);\n\n#else\n/* Fatal error in PNG image of libpng - can't continue */\nPNG_EXPORTA(104, void, png_err, (png_const_structrp png_ptr), PNG_NORETURN);\n#  define png_error(s1,s2) png_err(s1)\n#  define png_chunk_error(s1,s2) png_err(s1)\n#endif\n\n#ifdef PNG_WARNINGS_SUPPORTED\n/* Non-fatal error in libpng.  Can continue, but may have a problem. */\nPNG_EXPORT(105, void, png_warning, (png_const_structrp png_ptr,\n    png_const_charp warning_message));\n\n/* Non-fatal error in libpng, chunk name is prepended to message. */\nPNG_EXPORT(106, void, png_chunk_warning, (png_const_structrp png_ptr,\n    png_const_charp warning_message));\n#else\n#  define png_warning(s1,s2) ((void)(s1))\n#  define png_chunk_warning(s1,s2) ((void)(s1))\n#endif\n\n#ifdef PNG_BENIGN_ERRORS_SUPPORTED\n/* Benign error in libpng.  Can continue, but may have a problem.\n * User can choose whether to handle as a fatal error or as a warning. */\nPNG_EXPORT(107, void, png_benign_error, (png_const_structrp png_ptr,\n    png_const_charp warning_message));\n\n#ifdef PNG_READ_SUPPORTED\n/* Same, chunk name is prepended to message (only during read) */\nPNG_EXPORT(108, void, png_chunk_benign_error, (png_const_structrp png_ptr,\n    png_const_charp warning_message));\n#endif\n\nPNG_EXPORT(109, void, png_set_benign_errors,\n    (png_structrp png_ptr, int allowed));\n#else\n#  ifdef PNG_ALLOW_BENIGN_ERRORS\n#    define png_benign_error png_warning\n#    define png_chunk_benign_error png_chunk_warning\n#  else\n#    define png_benign_error png_error\n#    define png_chunk_benign_error png_chunk_error\n#  endif\n#endif\n\n/* The png_set_<chunk> functions are for storing values in the png_info_struct.\n * Similarly, the png_get_<chunk> calls are used to read values from the\n * png_info_struct, either storing the parameters in the passed variables, or\n * setting pointers into the png_info_struct where the data is stored.  The\n * png_get_<chunk> functions return a non-zero value if the data was available\n * in info_ptr, or return zero and do not change any of the parameters if the\n * data was not available.\n *\n * These functions should be used instead of directly accessing png_info\n * to avoid problems with future changes in the size and internal layout of\n * png_info_struct.\n */\n/* Returns \"flag\" if chunk data is valid in info_ptr. */\nPNG_EXPORT(110, png_uint_32, png_get_valid, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, png_uint_32 flag));\n\n/* Returns number of bytes needed to hold a transformed row. */\nPNG_EXPORT(111, png_size_t, png_get_rowbytes, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\n/* Returns row_pointers, which is an array of pointers to scanlines that was\n * returned from png_read_png().\n */\nPNG_EXPORT(112, png_bytepp, png_get_rows, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Set row_pointers, which is an array of pointers to scanlines for use\n * by png_write_png().\n */\nPNG_EXPORT(113, void, png_set_rows, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_bytepp row_pointers));\n#endif\n\n/* Returns number of color channels in image. */\nPNG_EXPORT(114, png_byte, png_get_channels, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n#ifdef PNG_EASY_ACCESS_SUPPORTED\n/* Returns image width in pixels. */\nPNG_EXPORT(115, png_uint_32, png_get_image_width, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image height in pixels. */\nPNG_EXPORT(116, png_uint_32, png_get_image_height, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image bit_depth. */\nPNG_EXPORT(117, png_byte, png_get_bit_depth, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image color_type. */\nPNG_EXPORT(118, png_byte, png_get_color_type, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image filter_type. */\nPNG_EXPORT(119, png_byte, png_get_filter_type, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image interlace_type. */\nPNG_EXPORT(120, png_byte, png_get_interlace_type, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image compression_type. */\nPNG_EXPORT(121, png_byte, png_get_compression_type, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n\n/* Returns image resolution in pixels per meter, from pHYs chunk data. */\nPNG_EXPORT(122, png_uint_32, png_get_pixels_per_meter,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(123, png_uint_32, png_get_x_pixels_per_meter,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(124, png_uint_32, png_get_y_pixels_per_meter,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\n\n/* Returns pixel aspect ratio, computed from pHYs chunk data.  */\nPNG_FP_EXPORT(125, float, png_get_pixel_aspect_ratio,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr))\nPNG_FIXED_EXPORT(210, png_fixed_point, png_get_pixel_aspect_ratio_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr))\n\n/* Returns image x, y offset in pixels or microns, from oFFs chunk data. */\nPNG_EXPORT(126, png_int_32, png_get_x_offset_pixels,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(127, png_int_32, png_get_y_offset_pixels,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(128, png_int_32, png_get_x_offset_microns,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\nPNG_EXPORT(129, png_int_32, png_get_y_offset_microns,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\n\n#endif /* EASY_ACCESS */\n\n#ifdef PNG_READ_SUPPORTED\n/* Returns pointer to signature string read from PNG header */\nPNG_EXPORT(130, png_const_bytep, png_get_signature, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr));\n#endif\n\n#ifdef PNG_bKGD_SUPPORTED\nPNG_EXPORT(131, png_uint_32, png_get_bKGD, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_color_16p *background));\n#endif\n\n#ifdef PNG_bKGD_SUPPORTED\nPNG_EXPORT(132, void, png_set_bKGD, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_color_16p background));\n#endif\n\n#ifdef PNG_cHRM_SUPPORTED\nPNG_FP_EXPORT(133, png_uint_32, png_get_cHRM, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, double *white_x, double *white_y, double *red_x,\n    double *red_y, double *green_x, double *green_y, double *blue_x,\n    double *blue_y))\nPNG_FP_EXPORT(230, png_uint_32, png_get_cHRM_XYZ, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, double *red_X, double *red_Y, double *red_Z,\n    double *green_X, double *green_Y, double *green_Z, double *blue_X,\n    double *blue_Y, double *blue_Z))\nPNG_FIXED_EXPORT(134, png_uint_32, png_get_cHRM_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *int_white_x, png_fixed_point *int_white_y,\n    png_fixed_point *int_red_x, png_fixed_point *int_red_y,\n    png_fixed_point *int_green_x, png_fixed_point *int_green_y,\n    png_fixed_point *int_blue_x, png_fixed_point *int_blue_y))\nPNG_FIXED_EXPORT(231, png_uint_32, png_get_cHRM_XYZ_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *int_red_X, png_fixed_point *int_red_Y,\n    png_fixed_point *int_red_Z, png_fixed_point *int_green_X,\n    png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,\n    png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,\n    png_fixed_point *int_blue_Z))\n#endif\n\n#ifdef PNG_cHRM_SUPPORTED\nPNG_FP_EXPORT(135, void, png_set_cHRM, (png_const_structrp png_ptr,\n    png_inforp info_ptr,\n    double white_x, double white_y, double red_x, double red_y, double green_x,\n    double green_y, double blue_x, double blue_y))\nPNG_FP_EXPORT(232, void, png_set_cHRM_XYZ, (png_const_structrp png_ptr,\n    png_inforp info_ptr, double red_X, double red_Y, double red_Z,\n    double green_X, double green_Y, double green_Z, double blue_X,\n    double blue_Y, double blue_Z))\nPNG_FIXED_EXPORT(136, void, png_set_cHRM_fixed, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_fixed_point int_white_x,\n    png_fixed_point int_white_y, png_fixed_point int_red_x,\n    png_fixed_point int_red_y, png_fixed_point int_green_x,\n    png_fixed_point int_green_y, png_fixed_point int_blue_x,\n    png_fixed_point int_blue_y))\nPNG_FIXED_EXPORT(233, void, png_set_cHRM_XYZ_fixed, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_fixed_point int_red_X, png_fixed_point int_red_Y,\n    png_fixed_point int_red_Z, png_fixed_point int_green_X,\n    png_fixed_point int_green_Y, png_fixed_point int_green_Z,\n    png_fixed_point int_blue_X, png_fixed_point int_blue_Y,\n    png_fixed_point int_blue_Z))\n#endif\n\n#ifdef PNG_gAMA_SUPPORTED\nPNG_FP_EXPORT(137, png_uint_32, png_get_gAMA, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, double *file_gamma))\nPNG_FIXED_EXPORT(138, png_uint_32, png_get_gAMA_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *int_file_gamma))\n#endif\n\n#ifdef PNG_gAMA_SUPPORTED\nPNG_FP_EXPORT(139, void, png_set_gAMA, (png_const_structrp png_ptr,\n    png_inforp info_ptr, double file_gamma))\nPNG_FIXED_EXPORT(140, void, png_set_gAMA_fixed, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_fixed_point int_file_gamma))\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\nPNG_EXPORT(141, png_uint_32, png_get_hIST, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_uint_16p *hist));\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\nPNG_EXPORT(142, void, png_set_hIST, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_uint_16p hist));\n#endif\n\nPNG_EXPORT(143, png_uint_32, png_get_IHDR, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, png_uint_32 *width, png_uint_32 *height,\n    int *bit_depth, int *color_type, int *interlace_method,\n    int *compression_method, int *filter_method));\n\nPNG_EXPORT(144, void, png_set_IHDR, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,\n    int color_type, int interlace_method, int compression_method,\n    int filter_method));\n\n#ifdef PNG_oFFs_SUPPORTED\nPNG_EXPORT(145, png_uint_32, png_get_oFFs, (png_const_structrp png_ptr,\n   png_const_inforp info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,\n   int *unit_type));\n#endif\n\n#ifdef PNG_oFFs_SUPPORTED\nPNG_EXPORT(146, void, png_set_oFFs, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_int_32 offset_x, png_int_32 offset_y,\n    int unit_type));\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\nPNG_EXPORT(147, png_uint_32, png_get_pCAL, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_charp *purpose, png_int_32 *X0,\n    png_int_32 *X1, int *type, int *nparams, png_charp *units,\n    png_charpp *params));\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\nPNG_EXPORT(148, void, png_set_pCAL, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_charp purpose, png_int_32 X0, png_int_32 X1,\n    int type, int nparams, png_const_charp units, png_charpp params));\n#endif\n\n#ifdef PNG_pHYs_SUPPORTED\nPNG_EXPORT(149, png_uint_32, png_get_pHYs, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,\n    int *unit_type));\n#endif\n\n#ifdef PNG_pHYs_SUPPORTED\nPNG_EXPORT(150, void, png_set_pHYs, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));\n#endif\n\nPNG_EXPORT(151, png_uint_32, png_get_PLTE, (png_const_structrp png_ptr,\n   png_inforp info_ptr, png_colorp *palette, int *num_palette));\n\nPNG_EXPORT(152, void, png_set_PLTE, (png_structrp png_ptr,\n    png_inforp info_ptr, png_const_colorp palette, int num_palette));\n\n#ifdef PNG_sBIT_SUPPORTED\nPNG_EXPORT(153, png_uint_32, png_get_sBIT, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_color_8p *sig_bit));\n#endif\n\n#ifdef PNG_sBIT_SUPPORTED\nPNG_EXPORT(154, void, png_set_sBIT, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_color_8p sig_bit));\n#endif\n\n#ifdef PNG_sRGB_SUPPORTED\nPNG_EXPORT(155, png_uint_32, png_get_sRGB, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, int *file_srgb_intent));\n#endif\n\n#ifdef PNG_sRGB_SUPPORTED\nPNG_EXPORT(156, void, png_set_sRGB, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int srgb_intent));\nPNG_EXPORT(157, void, png_set_sRGB_gAMA_and_cHRM, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int srgb_intent));\n#endif\n\n#ifdef PNG_iCCP_SUPPORTED\nPNG_EXPORT(158, png_uint_32, png_get_iCCP, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_charpp name, int *compression_type,\n    png_bytepp profile, png_uint_32 *proflen));\n#endif\n\n#ifdef PNG_iCCP_SUPPORTED\nPNG_EXPORT(159, void, png_set_iCCP, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_charp name, int compression_type,\n    png_const_bytep profile, png_uint_32 proflen));\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\nPNG_EXPORT(160, int, png_get_sPLT, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_sPLT_tpp entries));\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\nPNG_EXPORT(161, void, png_set_sPLT, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_sPLT_tp entries, int nentries));\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED\n/* png_get_text also returns the number of text chunks in *num_text */\nPNG_EXPORT(162, int, png_get_text, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_textp *text_ptr, int *num_text));\n#endif\n\n/* Note while png_set_text() will accept a structure whose text,\n * language, and  translated keywords are NULL pointers, the structure\n * returned by png_get_text will always contain regular\n * zero-terminated C strings.  They might be empty strings but\n * they will never be NULL pointers.\n */\n\n#ifdef PNG_TEXT_SUPPORTED\nPNG_EXPORT(163, void, png_set_text, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_textp text_ptr, int num_text));\n#endif\n\n#ifdef PNG_tIME_SUPPORTED\nPNG_EXPORT(164, png_uint_32, png_get_tIME, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_timep *mod_time));\n#endif\n\n#ifdef PNG_tIME_SUPPORTED\nPNG_EXPORT(165, void, png_set_tIME, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_timep mod_time));\n#endif\n\n#ifdef PNG_tRNS_SUPPORTED\nPNG_EXPORT(166, png_uint_32, png_get_tRNS, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_bytep *trans_alpha, int *num_trans,\n    png_color_16p *trans_color));\n#endif\n\n#ifdef PNG_tRNS_SUPPORTED\nPNG_EXPORT(167, void, png_set_tRNS, (png_structrp png_ptr,\n    png_inforp info_ptr, png_const_bytep trans_alpha, int num_trans,\n    png_const_color_16p trans_color));\n#endif\n\n#ifdef PNG_sCAL_SUPPORTED\nPNG_FP_EXPORT(168, png_uint_32, png_get_sCAL, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, int *unit, double *width, double *height))\n#if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \\\n   defined(PNG_FLOATING_POINT_SUPPORTED)\n/* NOTE: this API is currently implemented using floating point arithmetic,\n * consequently it can only be used on systems with floating point support.\n * In any case the range of values supported by png_fixed_point is small and it\n * is highly recommended that png_get_sCAL_s be used instead.\n */\nPNG_FIXED_EXPORT(214, png_uint_32, png_get_sCAL_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,\n    png_fixed_point *width, png_fixed_point *height))\n#endif\nPNG_EXPORT(169, png_uint_32, png_get_sCAL_s,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr, int *unit,\n    png_charpp swidth, png_charpp sheight));\n\nPNG_FP_EXPORT(170, void, png_set_sCAL, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int unit, double width, double height))\nPNG_FIXED_EXPORT(213, void, png_set_sCAL_fixed, (png_const_structrp png_ptr,\n   png_inforp info_ptr, int unit, png_fixed_point width,\n   png_fixed_point height))\nPNG_EXPORT(171, void, png_set_sCAL_s, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int unit,\n    png_const_charp swidth, png_const_charp sheight));\n#endif /* sCAL */\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n/* Provide the default handling for all unknown chunks or, optionally, for\n * specific unknown chunks.\n *\n * NOTE: prior to 1.6.0 the handling specified for particular chunks on read was\n * ignored and the default was used, the per-chunk setting only had an effect on\n * write.  If you wish to have chunk-specific handling on read in code that must\n * work on earlier versions you must use a user chunk callback to specify the\n * desired handling (keep or discard.)\n *\n * The 'keep' parameter is a PNG_HANDLE_CHUNK_ value as listed below.  The\n * parameter is interpreted as follows:\n *\n * READ:\n *    PNG_HANDLE_CHUNK_AS_DEFAULT:\n *       Known chunks: do normal libpng processing, do not keep the chunk (but\n *          see the comments below about PNG_HANDLE_AS_UNKNOWN_SUPPORTED)\n *       Unknown chunks: for a specific chunk use the global default, when used\n *          as the default discard the chunk data.\n *    PNG_HANDLE_CHUNK_NEVER:\n *       Discard the chunk data.\n *    PNG_HANDLE_CHUNK_IF_SAFE:\n *       Keep the chunk data if the chunk is not critical else raise a chunk\n *       error.\n *    PNG_HANDLE_CHUNK_ALWAYS:\n *       Keep the chunk data.\n *\n * If the chunk data is saved it can be retrieved using png_get_unknown_chunks,\n * below.  Notice that specifying \"AS_DEFAULT\" as a global default is equivalent\n * to specifying \"NEVER\", however when \"AS_DEFAULT\" is used for specific chunks\n * it simply resets the behavior to the libpng default.\n *\n * INTERACTION WTIH USER CHUNK CALLBACKS:\n * The per-chunk handling is always used when there is a png_user_chunk_ptr\n * callback and the callback returns 0; the chunk is then always stored *unless*\n * it is critical and the per-chunk setting is other than ALWAYS.  Notice that\n * the global default is *not* used in this case.  (In effect the per-chunk\n * value is incremented to at least IF_SAFE.)\n *\n * IMPORTANT NOTE: this behavior will change in libpng 1.7 - the global and\n * per-chunk defaults will be honored.  If you want to preserve the current\n * behavior when your callback returns 0 you must set PNG_HANDLE_CHUNK_IF_SAFE\n * as the default - if you don't do this libpng 1.6 will issue a warning.\n *\n * If you want unhandled unknown chunks to be discarded in libpng 1.6 and\n * earlier simply return '1' (handled).\n *\n * PNG_HANDLE_AS_UNKNOWN_SUPPORTED:\n *    If this is *not* set known chunks will always be handled by libpng and\n *    will never be stored in the unknown chunk list.  Known chunks listed to\n *    png_set_keep_unknown_chunks will have no effect.  If it is set then known\n *    chunks listed with a keep other than AS_DEFAULT will *never* be processed\n *    by libpng, in addition critical chunks must either be processed by the\n *    callback or saved.\n *\n *    The IHDR and IEND chunks must not be listed.  Because this turns off the\n *    default handling for chunks that would otherwise be recognized the\n *    behavior of libpng transformations may well become incorrect!\n *\n * WRITE:\n *    When writing chunks the options only apply to the chunks specified by\n *    png_set_unknown_chunks (below), libpng will *always* write known chunks\n *    required by png_set_ calls and will always write the core critical chunks\n *    (as required for PLTE).\n *\n *    Each chunk in the png_set_unknown_chunks list is looked up in the\n *    png_set_keep_unknown_chunks list to find the keep setting, this is then\n *    interpreted as follows:\n *\n *    PNG_HANDLE_CHUNK_AS_DEFAULT:\n *       Write safe-to-copy chunks and write other chunks if the global\n *       default is set to _ALWAYS, otherwise don't write this chunk.\n *    PNG_HANDLE_CHUNK_NEVER:\n *       Do not write the chunk.\n *    PNG_HANDLE_CHUNK_IF_SAFE:\n *       Write the chunk if it is safe-to-copy, otherwise do not write it.\n *    PNG_HANDLE_CHUNK_ALWAYS:\n *       Write the chunk.\n *\n * Note that the default behavior is effectively the opposite of the read case -\n * in read unknown chunks are not stored by default, in write they are written\n * by default.  Also the behavior of PNG_HANDLE_CHUNK_IF_SAFE is very different\n * - on write the safe-to-copy bit is checked, on read the critical bit is\n * checked and on read if the chunk is critical an error will be raised.\n *\n * num_chunks:\n * ===========\n *    If num_chunks is positive, then the \"keep\" parameter specifies the manner\n *    for handling only those chunks appearing in the chunk_list array,\n *    otherwise the chunk list array is ignored.\n *\n *    If num_chunks is 0 the \"keep\" parameter specifies the default behavior for\n *    unknown chunks, as described above.\n *\n *    If num_chunks is negative, then the \"keep\" parameter specifies the manner\n *    for handling all unknown chunks plus all chunks recognized by libpng\n *    except for the IHDR, PLTE, tRNS, IDAT, and IEND chunks (which continue to\n *    be processed by libpng.\n */\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\nPNG_EXPORT(172, void, png_set_keep_unknown_chunks, (png_structrp png_ptr,\n    int keep, png_const_bytep chunk_list, int num_chunks));\n#endif /* HANDLE_AS_UNKNOWN */\n\n/* The \"keep\" PNG_HANDLE_CHUNK_ parameter for the specified chunk is returned;\n * the result is therefore true (non-zero) if special handling is required,\n * false for the default handling.\n */\nPNG_EXPORT(173, int, png_handle_as_unknown, (png_const_structrp png_ptr,\n    png_const_bytep chunk_name));\n#endif /* SET_UNKNOWN_CHUNKS */\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\nPNG_EXPORT(174, void, png_set_unknown_chunks, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_unknown_chunkp unknowns,\n    int num_unknowns));\n   /* NOTE: prior to 1.6.0 this routine set the 'location' field of the added\n    * unknowns to the location currently stored in the png_struct.  This is\n    * invariably the wrong value on write.  To fix this call the following API\n    * for each chunk in the list with the correct location.  If you know your\n    * code won't be compiled on earlier versions you can rely on\n    * png_set_unknown_chunks(write-ptr, png_get_unknown_chunks(read-ptr)) doing\n    * the correct thing.\n    */\n\nPNG_EXPORT(175, void, png_set_unknown_chunk_location,\n    (png_const_structrp png_ptr, png_inforp info_ptr, int chunk, int location));\n\nPNG_EXPORT(176, int, png_get_unknown_chunks, (png_const_structrp png_ptr,\n    png_inforp info_ptr, png_unknown_chunkpp entries));\n#endif\n\n/* Png_free_data() will turn off the \"valid\" flag for anything it frees.\n * If you need to turn it off for a chunk that your application has freed,\n * you can use png_set_invalid(png_ptr, info_ptr, PNG_INFO_CHNK);\n */\nPNG_EXPORT(177, void, png_set_invalid, (png_const_structrp png_ptr,\n    png_inforp info_ptr, int mask));\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\n/* The \"params\" pointer is currently not used and is for future expansion. */\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\nPNG_EXPORT(178, void, png_read_png, (png_structrp png_ptr, png_inforp info_ptr,\n    int transforms, png_voidp params));\n#endif\n#ifdef PNG_WRITE_SUPPORTED\nPNG_EXPORT(179, void, png_write_png, (png_structrp png_ptr, png_inforp info_ptr,\n    int transforms, png_voidp params));\n#endif\n#endif\n\nPNG_EXPORT(180, png_const_charp, png_get_copyright,\n    (png_const_structrp png_ptr));\nPNG_EXPORT(181, png_const_charp, png_get_header_ver,\n    (png_const_structrp png_ptr));\nPNG_EXPORT(182, png_const_charp, png_get_header_version,\n    (png_const_structrp png_ptr));\nPNG_EXPORT(183, png_const_charp, png_get_libpng_ver,\n    (png_const_structrp png_ptr));\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\nPNG_EXPORT(184, png_uint_32, png_permit_mng_features, (png_structrp png_ptr,\n    png_uint_32 mng_features_permitted));\n#endif\n\n/* For use in png_set_keep_unknown, added to version 1.2.6 */\n#define PNG_HANDLE_CHUNK_AS_DEFAULT   0\n#define PNG_HANDLE_CHUNK_NEVER        1\n#define PNG_HANDLE_CHUNK_IF_SAFE      2\n#define PNG_HANDLE_CHUNK_ALWAYS       3\n#define PNG_HANDLE_CHUNK_LAST         4\n\n/* Strip the prepended error numbers (\"#nnn \") from error and warning\n * messages before passing them to the error or warning handler.\n */\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\nPNG_EXPORT(185, void, png_set_strip_error_numbers, (png_structrp png_ptr,\n    png_uint_32 strip_mode));\n#endif\n\n/* Added in libpng-1.2.6 */\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\nPNG_EXPORT(186, void, png_set_user_limits, (png_structrp png_ptr,\n    png_uint_32 user_width_max, png_uint_32 user_height_max));\nPNG_EXPORT(187, png_uint_32, png_get_user_width_max,\n    (png_const_structrp png_ptr));\nPNG_EXPORT(188, png_uint_32, png_get_user_height_max,\n    (png_const_structrp png_ptr));\n/* Added in libpng-1.4.0 */\nPNG_EXPORT(189, void, png_set_chunk_cache_max, (png_structrp png_ptr,\n    png_uint_32 user_chunk_cache_max));\nPNG_EXPORT(190, png_uint_32, png_get_chunk_cache_max,\n    (png_const_structrp png_ptr));\n/* Added in libpng-1.4.1 */\nPNG_EXPORT(191, void, png_set_chunk_malloc_max, (png_structrp png_ptr,\n    png_alloc_size_t user_chunk_cache_max));\nPNG_EXPORT(192, png_alloc_size_t, png_get_chunk_malloc_max,\n    (png_const_structrp png_ptr));\n#endif\n\n#if defined(PNG_INCH_CONVERSIONS_SUPPORTED)\nPNG_EXPORT(193, png_uint_32, png_get_pixels_per_inch,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\n\nPNG_EXPORT(194, png_uint_32, png_get_x_pixels_per_inch,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\n\nPNG_EXPORT(195, png_uint_32, png_get_y_pixels_per_inch,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr));\n\nPNG_FP_EXPORT(196, float, png_get_x_offset_inches,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr))\n#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */\nPNG_FIXED_EXPORT(211, png_fixed_point, png_get_x_offset_inches_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr))\n#endif\n\nPNG_FP_EXPORT(197, float, png_get_y_offset_inches, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr))\n#ifdef PNG_FIXED_POINT_SUPPORTED /* otherwise not implemented. */\nPNG_FIXED_EXPORT(212, png_fixed_point, png_get_y_offset_inches_fixed,\n    (png_const_structrp png_ptr, png_const_inforp info_ptr))\n#endif\n\n#  ifdef PNG_pHYs_SUPPORTED\nPNG_EXPORT(198, png_uint_32, png_get_pHYs_dpi, (png_const_structrp png_ptr,\n    png_const_inforp info_ptr, png_uint_32 *res_x, png_uint_32 *res_y,\n    int *unit_type));\n#  endif /* pHYs */\n#endif  /* INCH_CONVERSIONS */\n\n/* Added in libpng-1.4.0 */\n#ifdef PNG_IO_STATE_SUPPORTED\nPNG_EXPORT(199, png_uint_32, png_get_io_state, (png_const_structrp png_ptr));\n\n/* Removed from libpng 1.6; use png_get_io_chunk_type. */\nPNG_REMOVED(200, png_const_bytep, png_get_io_chunk_name, (png_structrp png_ptr),\n    PNG_DEPRECATED)\n\nPNG_EXPORT(216, png_uint_32, png_get_io_chunk_type,\n    (png_const_structrp png_ptr));\n\n/* The flags returned by png_get_io_state() are the following: */\n#  define PNG_IO_NONE        0x0000   /* no I/O at this moment */\n#  define PNG_IO_READING     0x0001   /* currently reading */\n#  define PNG_IO_WRITING     0x0002   /* currently writing */\n#  define PNG_IO_SIGNATURE   0x0010   /* currently at the file signature */\n#  define PNG_IO_CHUNK_HDR   0x0020   /* currently at the chunk header */\n#  define PNG_IO_CHUNK_DATA  0x0040   /* currently at the chunk data */\n#  define PNG_IO_CHUNK_CRC   0x0080   /* currently at the chunk crc */\n#  define PNG_IO_MASK_OP     0x000f   /* current operation: reading/writing */\n#  define PNG_IO_MASK_LOC    0x00f0   /* current location: sig/hdr/data/crc */\n#endif /* IO_STATE */\n\n/* Interlace support.  The following macros are always defined so that if\n * libpng interlace handling is turned off the macros may be used to handle\n * interlaced images within the application.\n */\n#define PNG_INTERLACE_ADAM7_PASSES 7\n\n/* Two macros to return the first row and first column of the original,\n * full, image which appears in a given pass.  'pass' is in the range 0\n * to 6 and the result is in the range 0 to 7.\n */\n#define PNG_PASS_START_ROW(pass) (((1&~(pass))<<(3-((pass)>>1)))&7)\n#define PNG_PASS_START_COL(pass) (((1& (pass))<<(3-(((pass)+1)>>1)))&7)\n\n/* A macro to return the offset between pixels in the output row for a pair of\n * pixels in the input - effectively the inverse of the 'COL_SHIFT' macro that\n * follows.  Note that ROW_OFFSET is the offset from one row to the next whereas\n * COL_OFFSET is from one column to the next, within a row.\n */\n#define PNG_PASS_ROW_OFFSET(pass) ((pass)>2?(8>>(((pass)-1)>>1)):8)\n#define PNG_PASS_COL_OFFSET(pass) (1<<((7-(pass))>>1))\n\n/* Two macros to help evaluate the number of rows or columns in each\n * pass.  This is expressed as a shift - effectively log2 of the number or\n * rows or columns in each 8x8 tile of the original image.\n */\n#define PNG_PASS_ROW_SHIFT(pass) ((pass)>2?(8-(pass))>>1:3)\n#define PNG_PASS_COL_SHIFT(pass) ((pass)>1?(7-(pass))>>1:3)\n\n/* Hence two macros to determine the number of rows or columns in a given\n * pass of an image given its height or width.  In fact these macros may\n * return non-zero even though the sub-image is empty, because the other\n * dimension may be empty for a small image.\n */\n#define PNG_PASS_ROWS(height, pass) (((height)+(((1<<PNG_PASS_ROW_SHIFT(pass))\\\n   -1)-PNG_PASS_START_ROW(pass)))>>PNG_PASS_ROW_SHIFT(pass))\n#define PNG_PASS_COLS(width, pass) (((width)+(((1<<PNG_PASS_COL_SHIFT(pass))\\\n   -1)-PNG_PASS_START_COL(pass)))>>PNG_PASS_COL_SHIFT(pass))\n\n/* For the reader row callbacks (both progressive and sequential) it is\n * necessary to find the row in the output image given a row in an interlaced\n * image, so two more macros:\n */\n#define PNG_ROW_FROM_PASS_ROW(y_in, pass) \\\n   (((y_in)<<PNG_PASS_ROW_SHIFT(pass))+PNG_PASS_START_ROW(pass))\n#define PNG_COL_FROM_PASS_COL(x_in, pass) \\\n   (((x_in)<<PNG_PASS_COL_SHIFT(pass))+PNG_PASS_START_COL(pass))\n\n/* Two macros which return a boolean (0 or 1) saying whether the given row\n * or column is in a particular pass.  These use a common utility macro that\n * returns a mask for a given pass - the offset 'off' selects the row or\n * column version.  The mask has the appropriate bit set for each column in\n * the tile.\n */\n#define PNG_PASS_MASK(pass,off) ( \\\n   ((0x110145AF>>(((7-(off))-(pass))<<2)) & 0xF) | \\\n   ((0x01145AF0>>(((7-(off))-(pass))<<2)) & 0xF0))\n\n#define PNG_ROW_IN_INTERLACE_PASS(y, pass) \\\n   ((PNG_PASS_MASK(pass,0) >> ((y)&7)) & 1)\n#define PNG_COL_IN_INTERLACE_PASS(x, pass) \\\n   ((PNG_PASS_MASK(pass,1) >> ((x)&7)) & 1)\n\n#ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED\n/* With these routines we avoid an integer divide, which will be slower on\n * most machines.  However, it does take more operations than the corresponding\n * divide method, so it may be slower on a few RISC systems.  There are two\n * shifts (by 8 or 16 bits) and an addition, versus a single integer divide.\n *\n * Note that the rounding factors are NOT supposed to be the same!  128 and\n * 32768 are correct for the NODIV code; 127 and 32767 are correct for the\n * standard method.\n *\n * [Optimized code by Greg Roelofs and Mark Adler...blame us for bugs. :-) ]\n */\n\n /* fg and bg should be in `gamma 1.0' space; alpha is the opacity */\n\n#  define png_composite(composite, fg, alpha, bg)        \\\n   {                                                     \\\n      png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) \\\n          * (png_uint_16)(alpha)                         \\\n          + (png_uint_16)(bg)*(png_uint_16)(255          \\\n          - (png_uint_16)(alpha)) + 128);                \\\n      (composite) = (png_byte)(((temp + (temp >> 8)) >> 8) & 0xff); \\\n   }\n\n#  define png_composite_16(composite, fg, alpha, bg)     \\\n   {                                                     \\\n      png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) \\\n          * (png_uint_32)(alpha)                         \\\n          + (png_uint_32)(bg)*(65535                     \\\n          - (png_uint_32)(alpha)) + 32768);              \\\n      (composite) = (png_uint_16)(0xffff & ((temp + (temp >> 16)) >> 16)); \\\n   }\n\n#else  /* Standard method using integer division */\n\n#  define png_composite(composite, fg, alpha, bg)                      \\\n   (composite) =                                                       \\\n       (png_byte)(0xff & (((png_uint_16)(fg) * (png_uint_16)(alpha) +  \\\n       (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \\\n       127) / 255))\n\n#  define png_composite_16(composite, fg, alpha, bg)                       \\\n   (composite) =                                                           \\\n       (png_uint_16)(0xffff & (((png_uint_32)(fg) * (png_uint_32)(alpha) + \\\n       (png_uint_32)(bg)*(png_uint_32)(65535 - (png_uint_32)(alpha)) +     \\\n       32767) / 65535))\n#endif /* READ_COMPOSITE_NODIV */\n\n#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED\nPNG_EXPORT(201, png_uint_32, png_get_uint_32, (png_const_bytep buf));\nPNG_EXPORT(202, png_uint_16, png_get_uint_16, (png_const_bytep buf));\nPNG_EXPORT(203, png_int_32, png_get_int_32, (png_const_bytep buf));\n#endif\n\nPNG_EXPORT(204, png_uint_32, png_get_uint_31, (png_const_structrp png_ptr,\n    png_const_bytep buf));\n/* No png_get_int_16 -- may be added if there's a real need for it. */\n\n/* Place a 32-bit number into a buffer in PNG byte order (big-endian). */\n#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED\nPNG_EXPORT(205, void, png_save_uint_32, (png_bytep buf, png_uint_32 i));\n#endif\n#ifdef PNG_SAVE_INT_32_SUPPORTED\nPNG_EXPORT(206, void, png_save_int_32, (png_bytep buf, png_int_32 i));\n#endif\n\n/* Place a 16-bit number into a buffer in PNG byte order.\n * The parameter is declared unsigned int, not png_uint_16,\n * just to avoid potential problems on pre-ANSI C compilers.\n */\n#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED\nPNG_EXPORT(207, void, png_save_uint_16, (png_bytep buf, unsigned int i));\n/* No png_save_int_16 -- may be added if there's a real need for it. */\n#endif\n\n#ifdef PNG_USE_READ_MACROS\n/* Inline macros to do direct reads of bytes from the input buffer.\n * The png_get_int_32() routine assumes we are using two's complement\n * format for negative values, which is almost certainly true.\n */\n#  define PNG_get_uint_32(buf) \\\n   (((png_uint_32)(*(buf)) << 24) + \\\n    ((png_uint_32)(*((buf) + 1)) << 16) + \\\n    ((png_uint_32)(*((buf) + 2)) << 8) + \\\n    ((png_uint_32)(*((buf) + 3))))\n\n   /* From libpng-1.4.0 until 1.4.4, the png_get_uint_16 macro (but not the\n    * function) incorrectly returned a value of type png_uint_32.\n    */\n#  define PNG_get_uint_16(buf) \\\n   ((png_uint_16) \\\n    (((unsigned int)(*(buf)) << 8) + \\\n    ((unsigned int)(*((buf) + 1)))))\n\n#  define PNG_get_int_32(buf) \\\n   ((png_int_32)((*(buf) & 0x80) \\\n    ? -((png_int_32)(((png_get_uint_32(buf)^0xffffffffU)+1U)&0x7fffffffU)) \\\n    : (png_int_32)png_get_uint_32(buf)))\n\n/* If PNG_PREFIX is defined the same thing as below happens in pnglibconf.h,\n * but defining a macro name prefixed with PNG_PREFIX.\n */\n#  ifndef PNG_PREFIX\n#    define png_get_uint_32(buf) PNG_get_uint_32(buf)\n#    define png_get_uint_16(buf) PNG_get_uint_16(buf)\n#    define png_get_int_32(buf)  PNG_get_int_32(buf)\n#  endif\n#else\n#  ifdef PNG_PREFIX\n   /* No macros; revert to the (redefined) function */\n#    define PNG_get_uint_32 (png_get_uint_32)\n#    define PNG_get_uint_16 (png_get_uint_16)\n#    define PNG_get_int_32  (png_get_int_32)\n#  endif\n#endif\n\n#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\nPNG_EXPORT(242, void, png_set_check_for_invalid_index,\n    (png_structrp png_ptr, int allowed));\n#  ifdef PNG_GET_PALETTE_MAX_SUPPORTED\nPNG_EXPORT(243, int, png_get_palette_max, (png_const_structp png_ptr,\n    png_const_infop info_ptr));\n#  endif\n#endif /* CHECK_FOR_INVALID_INDEX */\n\n/*******************************************************************************\n * Section 5: SIMPLIFIED API\n *******************************************************************************\n *\n * Please read the documentation in libpng-manual.txt (TODO: write said\n * documentation) if you don't understand what follows.\n *\n * The simplified API hides the details of both libpng and the PNG file format\n * itself.  It allows PNG files to be read into a very limited number of\n * in-memory bitmap formats or to be written from the same formats.  If these\n * formats do not accomodate your needs then you can, and should, use the more\n * sophisticated APIs above - these support a wide variety of in-memory formats\n * and a wide variety of sophisticated transformations to those formats as well\n * as a wide variety of APIs to manipulate ancillary information.\n *\n * To read a PNG file using the simplified API:\n *\n * 1) Declare a 'png_image' structure (see below) on the stack, set the\n *    version field to PNG_IMAGE_VERSION and the 'opaque' pointer to NULL\n *    (this is REQUIRED, your program may crash if you don't do it.)\n * 2) Call the appropriate png_image_begin_read... function.\n * 3) Set the png_image 'format' member to the required sample format.\n * 4) Allocate a buffer for the image and, if required, the color-map.\n * 5) Call png_image_finish_read to read the image and, if required, the\n *    color-map into your buffers.\n *\n * There are no restrictions on the format of the PNG input itself; all valid\n * color types, bit depths, and interlace methods are acceptable, and the\n * input image is transformed as necessary to the requested in-memory format\n * during the png_image_finish_read() step.  The only caveat is that if you\n * request a color-mapped image from a PNG that is full-color or makes\n * complex use of an alpha channel the transformation is extremely lossy and the\n * result may look terrible.\n *\n * To write a PNG file using the simplified API:\n *\n * 1) Declare a 'png_image' structure on the stack and memset() it to all zero.\n * 2) Initialize the members of the structure that describe the image, setting\n *    the 'format' member to the format of the image samples.\n * 3) Call the appropriate png_image_write... function with a pointer to the\n *    image and, if necessary, the color-map to write the PNG data.\n *\n * png_image is a structure that describes the in-memory format of an image\n * when it is being read or defines the in-memory format of an image that you\n * need to write:\n */\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) || \\\n    defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n\n#define PNG_IMAGE_VERSION 1\n\ntypedef struct png_control *png_controlp;\ntypedef struct\n{\n   png_controlp opaque;    /* Initialize to NULL, free with png_image_free */\n   png_uint_32  version;   /* Set to PNG_IMAGE_VERSION */\n   png_uint_32  width;     /* Image width in pixels (columns) */\n   png_uint_32  height;    /* Image height in pixels (rows) */\n   png_uint_32  format;    /* Image format as defined below */\n   png_uint_32  flags;     /* A bit mask containing informational flags */\n   png_uint_32  colormap_entries;\n                           /* Number of entries in the color-map */\n\n   /* In the event of an error or warning the following field will be set to a\n    * non-zero value and the 'message' field will contain a '\\0' terminated\n    * string with the libpng error or warning message.  If both warnings and\n    * an error were encountered, only the error is recorded.  If there\n    * are multiple warnings, only the first one is recorded.\n    *\n    * The upper 30 bits of this value are reserved, the low two bits contain\n    * a value as follows:\n    */\n#  define PNG_IMAGE_WARNING 1\n#  define PNG_IMAGE_ERROR 2\n   /*\n    * The result is a two-bit code such that a value more than 1 indicates\n    * a failure in the API just called:\n    *\n    *    0 - no warning or error\n    *    1 - warning\n    *    2 - error\n    *    3 - error preceded by warning\n    */\n#  define PNG_IMAGE_FAILED(png_cntrl) ((((png_cntrl).warning_or_error)&0x03)>1)\n\n   png_uint_32  warning_or_error;\n\n   char         message[64];\n} png_image, *png_imagep;\n\n/* The samples of the image have one to four channels whose components have\n * original values in the range 0 to 1.0:\n *\n * 1: A single gray or luminance channel (G).\n * 2: A gray/luminance channel and an alpha channel (GA).\n * 3: Three red, green, blue color channels (RGB).\n * 4: Three color channels and an alpha channel (RGBA).\n *\n * The components are encoded in one of two ways:\n *\n * a) As a small integer, value 0..255, contained in a single byte.  For the\n * alpha channel the original value is simply value/255.  For the color or\n * luminance channels the value is encoded according to the sRGB specification\n * and matches the 8-bit format expected by typical display devices.\n *\n * The color/gray channels are not scaled (pre-multiplied) by the alpha\n * channel and are suitable for passing to color management software.\n *\n * b) As a value in the range 0..65535, contained in a 2-byte integer.  All\n * channels can be converted to the original value by dividing by 65535; all\n * channels are linear.  Color channels use the RGB encoding (RGB end-points) of\n * the sRGB specification.  This encoding is identified by the\n * PNG_FORMAT_FLAG_LINEAR flag below.\n *\n * When the simplified API needs to convert between sRGB and linear colorspaces,\n * the actual sRGB transfer curve defined in the sRGB specification (see the\n * article at http://en.wikipedia.org/wiki/SRGB) is used, not the gamma=1/2.2\n * approximation used elsewhere in libpng.\n *\n * When an alpha channel is present it is expected to denote pixel coverage\n * of the color or luminance channels and is returned as an associated alpha\n * channel: the color/gray channels are scaled (pre-multiplied) by the alpha\n * value.\n *\n * The samples are either contained directly in the image data, between 1 and 8\n * bytes per pixel according to the encoding, or are held in a color-map indexed\n * by bytes in the image data.  In the case of a color-map the color-map entries\n * are individual samples, encoded as above, and the image data has one byte per\n * pixel to select the relevant sample from the color-map.\n */\n\n/* PNG_FORMAT_*\n *\n * #defines to be used in png_image::format.  Each #define identifies a\n * particular layout of sample data and, if present, alpha values.  There are\n * separate defines for each of the two component encodings.\n *\n * A format is built up using single bit flag values.  All combinations are\n * valid.  Formats can be built up from the flag values or you can use one of\n * the predefined values below.  When testing formats always use the FORMAT_FLAG\n * macros to test for individual features - future versions of the library may\n * add new flags.\n *\n * When reading or writing color-mapped images the format should be set to the\n * format of the entries in the color-map then png_image_{read,write}_colormap\n * called to read or write the color-map and set the format correctly for the\n * image data.  Do not set the PNG_FORMAT_FLAG_COLORMAP bit directly!\n *\n * NOTE: libpng can be built with particular features disabled. If you see\n * compiler errors because the definition of one of the following flags has been\n * compiled out it is because libpng does not have the required support.  It is\n * possible, however, for the libpng configuration to enable the format on just\n * read or just write; in that case you may see an error at run time.  You can\n * guard against this by checking for the definition of the appropriate\n * \"_SUPPORTED\" macro, one of:\n *\n *    PNG_SIMPLIFIED_{READ,WRITE}_{BGR,AFIRST}_SUPPORTED\n */\n#define PNG_FORMAT_FLAG_ALPHA    0x01U /* format with an alpha channel */\n#define PNG_FORMAT_FLAG_COLOR    0x02U /* color format: otherwise grayscale */\n#define PNG_FORMAT_FLAG_LINEAR   0x04U /* 2-byte channels else 1-byte */\n#define PNG_FORMAT_FLAG_COLORMAP 0x08U /* image data is color-mapped */\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\n#  define PNG_FORMAT_FLAG_BGR    0x10U /* BGR colors, else order is RGB */\n#endif\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\n#  define PNG_FORMAT_FLAG_AFIRST 0x20U /* alpha channel comes first */\n#endif\n\n/* Commonly used formats have predefined macros.\n *\n * First the single byte (sRGB) formats:\n */\n#define PNG_FORMAT_GRAY 0\n#define PNG_FORMAT_GA   PNG_FORMAT_FLAG_ALPHA\n#define PNG_FORMAT_AG   (PNG_FORMAT_GA|PNG_FORMAT_FLAG_AFIRST)\n#define PNG_FORMAT_RGB  PNG_FORMAT_FLAG_COLOR\n#define PNG_FORMAT_BGR  (PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_BGR)\n#define PNG_FORMAT_RGBA (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_ALPHA)\n#define PNG_FORMAT_ARGB (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_AFIRST)\n#define PNG_FORMAT_BGRA (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_ALPHA)\n#define PNG_FORMAT_ABGR (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_AFIRST)\n\n/* Then the linear 2-byte formats.  When naming these \"Y\" is used to\n * indicate a luminance (gray) channel.\n */\n#define PNG_FORMAT_LINEAR_Y PNG_FORMAT_FLAG_LINEAR\n#define PNG_FORMAT_LINEAR_Y_ALPHA (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_ALPHA)\n#define PNG_FORMAT_LINEAR_RGB (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR)\n#define PNG_FORMAT_LINEAR_RGB_ALPHA \\\n   (PNG_FORMAT_FLAG_LINEAR|PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA)\n\n/* With color-mapped formats the image data is one byte for each pixel, the byte\n * is an index into the color-map which is formatted as above.  To obtain a\n * color-mapped format it is sufficient just to add the PNG_FOMAT_FLAG_COLORMAP\n * to one of the above definitions, or you can use one of the definitions below.\n */\n#define PNG_FORMAT_RGB_COLORMAP  (PNG_FORMAT_RGB|PNG_FORMAT_FLAG_COLORMAP)\n#define PNG_FORMAT_BGR_COLORMAP  (PNG_FORMAT_BGR|PNG_FORMAT_FLAG_COLORMAP)\n#define PNG_FORMAT_RGBA_COLORMAP (PNG_FORMAT_RGBA|PNG_FORMAT_FLAG_COLORMAP)\n#define PNG_FORMAT_ARGB_COLORMAP (PNG_FORMAT_ARGB|PNG_FORMAT_FLAG_COLORMAP)\n#define PNG_FORMAT_BGRA_COLORMAP (PNG_FORMAT_BGRA|PNG_FORMAT_FLAG_COLORMAP)\n#define PNG_FORMAT_ABGR_COLORMAP (PNG_FORMAT_ABGR|PNG_FORMAT_FLAG_COLORMAP)\n\n/* PNG_IMAGE macros\n *\n * These are convenience macros to derive information from a png_image\n * structure.  The PNG_IMAGE_SAMPLE_ macros return values appropriate to the\n * actual image sample values - either the entries in the color-map or the\n * pixels in the image.  The PNG_IMAGE_PIXEL_ macros return corresponding values\n * for the pixels and will always return 1 for color-mapped formats.  The\n * remaining macros return information about the rows in the image and the\n * complete image.\n *\n * NOTE: All the macros that take a png_image::format parameter are compile time\n * constants if the format parameter is, itself, a constant.  Therefore these\n * macros can be used in array declarations and case labels where required.\n * Similarly the macros are also pre-processor constants (sizeof is not used) so\n * they can be used in #if tests.\n *\n * First the information about the samples.\n */\n#define PNG_IMAGE_SAMPLE_CHANNELS(fmt)\\\n   (((fmt)&(PNG_FORMAT_FLAG_COLOR|PNG_FORMAT_FLAG_ALPHA))+1)\n   /* Return the total number of channels in a given format: 1..4 */\n\n#define PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt)\\\n   ((((fmt) & PNG_FORMAT_FLAG_LINEAR) >> 2)+1)\n   /* Return the size in bytes of a single component of a pixel or color-map\n    * entry (as appropriate) in the image: 1 or 2.\n    */\n\n#define PNG_IMAGE_SAMPLE_SIZE(fmt)\\\n   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * PNG_IMAGE_SAMPLE_COMPONENT_SIZE(fmt))\n   /* This is the size of the sample data for one sample.  If the image is\n    * color-mapped it is the size of one color-map entry (and image pixels are\n    * one byte in size), otherwise it is the size of one image pixel.\n    */\n\n#define PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(fmt)\\\n   (PNG_IMAGE_SAMPLE_CHANNELS(fmt) * 256)\n   /* The maximum size of the color-map required by the format expressed in a\n    * count of components.  This can be used to compile-time allocate a\n    * color-map:\n    *\n    * png_uint_16 colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(linear_fmt)];\n    *\n    * png_byte colormap[PNG_IMAGE_MAXIMUM_COLORMAP_COMPONENTS(sRGB_fmt)];\n    *\n    * Alternatively use the PNG_IMAGE_COLORMAP_SIZE macro below to use the\n    * information from one of the png_image_begin_read_ APIs and dynamically\n    * allocate the required memory.\n    */\n\n/* Corresponding information about the pixels */\n#define PNG_IMAGE_PIXEL_(test,fmt)\\\n   (((fmt)&PNG_FORMAT_FLAG_COLORMAP)?1:test(fmt))\n\n#define PNG_IMAGE_PIXEL_CHANNELS(fmt)\\\n   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_CHANNELS,fmt)\n   /* The number of separate channels (components) in a pixel; 1 for a\n    * color-mapped image.\n    */\n\n#define PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)\\\n   PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_COMPONENT_SIZE,fmt)\n   /* The size, in bytes, of each component in a pixel; 1 for a color-mapped\n    * image.\n    */\n\n#define PNG_IMAGE_PIXEL_SIZE(fmt) PNG_IMAGE_PIXEL_(PNG_IMAGE_SAMPLE_SIZE,fmt)\n   /* The size, in bytes, of a complete pixel; 1 for a color-mapped image. */\n\n/* Information about the whole row, or whole image */\n#define PNG_IMAGE_ROW_STRIDE(image)\\\n   (PNG_IMAGE_PIXEL_CHANNELS((image).format) * (image).width)\n   /* Return the total number of components in a single row of the image; this\n    * is the minimum 'row stride', the minimum count of components between each\n    * row.  For a color-mapped image this is the minimum number of bytes in a\n    * row.\n    *\n    * WARNING: this macro overflows for some images with more than one component\n    * and very large image widths.  libpng will refuse to process an image where\n    * this macro would overflow.\n    */\n\n#define PNG_IMAGE_BUFFER_SIZE(image, row_stride)\\\n   (PNG_IMAGE_PIXEL_COMPONENT_SIZE((image).format)*(image).height*(row_stride))\n   /* Return the size, in bytes, of an image buffer given a png_image and a row\n    * stride - the number of components to leave space for in each row.\n    *\n    * WARNING: this macro overflows a 32-bit integer for some large PNG images,\n    * libpng will refuse to process an image where such an overflow would occur.\n    */\n\n#define PNG_IMAGE_SIZE(image)\\\n   PNG_IMAGE_BUFFER_SIZE(image, PNG_IMAGE_ROW_STRIDE(image))\n   /* Return the size, in bytes, of the image in memory given just a png_image;\n    * the row stride is the minimum stride required for the image.\n    */\n\n#define PNG_IMAGE_COLORMAP_SIZE(image)\\\n   (PNG_IMAGE_SAMPLE_SIZE((image).format) * (image).colormap_entries)\n   /* Return the size, in bytes, of the color-map of this image.  If the image\n    * format is not a color-map format this will return a size sufficient for\n    * 256 entries in the given format; check PNG_FORMAT_FLAG_COLORMAP if\n    * you don't want to allocate a color-map in this case.\n    */\n\n/* PNG_IMAGE_FLAG_*\n *\n * Flags containing additional information about the image are held in the\n * 'flags' field of png_image.\n */\n#define PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB 0x01\n   /* This indicates the the RGB values of the in-memory bitmap do not\n    * correspond to the red, green and blue end-points defined by sRGB.\n    */\n\n#define PNG_IMAGE_FLAG_FAST 0x02\n   /* On write emphasise speed over compression; the resultant PNG file will be\n    * larger but will be produced significantly faster, particular for large\n    * images.  Do not use this option for images which will be distributed, only\n    * used it when producing intermediate files that will be read back in\n    * repeatedly.  For a typical 24-bit image the option will double the read\n    * speed at the cost of increasing the image size by 25%, however for many\n    * more compressible images the PNG file can be 10 times larger with only a\n    * slight speed gain.\n    */\n\n#define PNG_IMAGE_FLAG_16BIT_sRGB 0x04\n   /* On read if the image is a 16-bit per component image and there is no gAMA\n    * or sRGB chunk assume that the components are sRGB encoded.  Notice that\n    * images output by the simplified API always have gamma information; setting\n    * this flag only affects the interpretation of 16-bit images from an\n    * external source.  It is recommended that the application expose this flag\n    * to the user; the user can normally easily recognize the difference between\n    * linear and sRGB encoding.  This flag has no effect on write - the data\n    * passed to the write APIs must have the correct encoding (as defined\n    * above.)\n    *\n    * If the flag is not set (the default) input 16-bit per component data is\n    * assumed to be linear.\n    *\n    * NOTE: the flag can only be set after the png_image_begin_read_ call,\n    * because that call initializes the 'flags' field.\n    */\n\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED\n/* READ APIs\n * ---------\n *\n * The png_image passed to the read APIs must have been initialized by setting\n * the png_controlp field 'opaque' to NULL (or, safer, memset the whole thing.)\n */\n#ifdef PNG_STDIO_SUPPORTED\nPNG_EXPORT(234, int, png_image_begin_read_from_file, (png_imagep image,\n   const char *file_name));\n   /* The named file is opened for read and the image header is filled in\n    * from the PNG header in the file.\n    */\n\nPNG_EXPORT(235, int, png_image_begin_read_from_stdio, (png_imagep image,\n   FILE* file));\n   /* The PNG header is read from the stdio FILE object. */\n#endif /* STDIO */\n\nPNG_EXPORT(236, int, png_image_begin_read_from_memory, (png_imagep image,\n   png_const_voidp memory, png_size_t size));\n   /* The PNG header is read from the given memory buffer. */\n\nPNG_EXPORT(237, int, png_image_finish_read, (png_imagep image,\n   png_const_colorp background, void *buffer, png_int_32 row_stride,\n   void *colormap));\n   /* Finish reading the image into the supplied buffer and clean up the\n    * png_image structure.\n    *\n    * row_stride is the step, in byte or 2-byte units as appropriate,\n    * between adjacent rows.  A positive stride indicates that the top-most row\n    * is first in the buffer - the normal top-down arrangement.  A negative\n    * stride indicates that the bottom-most row is first in the buffer.\n    *\n    * background need only be supplied if an alpha channel must be removed from\n    * a png_byte format and the removal is to be done by compositing on a solid\n    * color; otherwise it may be NULL and any composition will be done directly\n    * onto the buffer.  The value is an sRGB color to use for the background,\n    * for grayscale output the green channel is used.\n    *\n    * background must be supplied when an alpha channel must be removed from a\n    * single byte color-mapped output format, in other words if:\n    *\n    * 1) The original format from png_image_begin_read_from_* had\n    *    PNG_FORMAT_FLAG_ALPHA set.\n    * 2) The format set by the application does not.\n    * 3) The format set by the application has PNG_FORMAT_FLAG_COLORMAP set and\n    *    PNG_FORMAT_FLAG_LINEAR *not* set.\n    *\n    * For linear output removing the alpha channel is always done by compositing\n    * on black and background is ignored.\n    *\n    * colormap must be supplied when PNG_FORMAT_FLAG_COLORMAP is set.  It must\n    * be at least the size (in bytes) returned by PNG_IMAGE_COLORMAP_SIZE.\n    * image->colormap_entries will be updated to the actual number of entries\n    * written to the colormap; this may be less than the original value.\n    */\n\nPNG_EXPORT(238, void, png_image_free, (png_imagep image));\n   /* Free any data allocated by libpng in image->opaque, setting the pointer to\n    * NULL.  May be called at any time after the structure is initialized.\n    */\n#endif /* SIMPLIFIED_READ */\n\n#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED\n/* WRITE APIS\n * ----------\n * For write you must initialize a png_image structure to describe the image to\n * be written.  To do this use memset to set the whole structure to 0 then\n * initialize fields describing your image.\n *\n * version: must be set to PNG_IMAGE_VERSION\n * opaque: must be initialized to NULL\n * width: image width in pixels\n * height: image height in rows\n * format: the format of the data (image and color-map) you wish to write\n * flags: set to 0 unless one of the defined flags applies; set\n *    PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB for color format images where the RGB\n *    values do not correspond to the colors in sRGB.\n * colormap_entries: set to the number of entries in the color-map (0 to 256)\n */\n#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\nPNG_EXPORT(239, int, png_image_write_to_file, (png_imagep image,\n   const char *file, int convert_to_8bit, const void *buffer,\n   png_int_32 row_stride, const void *colormap));\n   /* Write the image to the named file. */\n\nPNG_EXPORT(240, int, png_image_write_to_stdio, (png_imagep image, FILE *file,\n   int convert_to_8_bit, const void *buffer, png_int_32 row_stride,\n   const void *colormap));\n   /* Write the image to the given (FILE*). */\n#endif /* SIMPLIFIED_WRITE_STDIO */\n\n/* With all write APIs if image is in one of the linear formats with 16-bit\n * data then setting convert_to_8_bit will cause the output to be an 8-bit PNG\n * gamma encoded according to the sRGB specification, otherwise a 16-bit linear\n * encoded PNG file is written.\n *\n * With color-mapped data formats the colormap parameter point to a color-map\n * with at least image->colormap_entries encoded in the specified format.  If\n * the format is linear the written PNG color-map will be converted to sRGB\n * regardless of the convert_to_8_bit flag.\n *\n * With all APIs row_stride is handled as in the read APIs - it is the spacing\n * from one row to the next in component sized units (1 or 2 bytes) and if\n * negative indicates a bottom-up row layout in the buffer.  If row_stride is\n * zero, libpng will calculate it for you from the image width and number of\n * channels.\n *\n * Note that the write API does not support interlacing, sub-8-bit pixels or\n * most ancillary chunks.  If you need to write text chunks (e.g. for copyright\n * notices) you need to use one of the other APIs.\n */\n\nPNG_EXPORT(245, int, png_image_write_to_memory, (png_imagep image, void *memory,\n   png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8_bit,\n   const void *buffer, png_int_32 row_stride, const void *colormap));\n   /* Write the image to the given memory buffer.  The function both writes the\n    * whole PNG data stream to *memory and updates *memory_bytes with the count\n    * of bytes written.\n    *\n    * 'memory' may be NULL.  In this case *memory_bytes is not read however on\n    * success the number of bytes which would have been written will still be\n    * stored in *memory_bytes.  On failure *memory_bytes will contain 0.\n    *\n    * If 'memory' is not NULL it must point to memory[*memory_bytes] of\n    * writeable memory.\n    *\n    * If the function returns success memory[*memory_bytes] (if 'memory' is not\n    * NULL) contains the written PNG data.  *memory_bytes will always be less\n    * than or equal to the original value.\n    *\n    * If the function returns false and *memory_bytes was not changed an error\n    * occured during write.  If *memory_bytes was changed, or is not 0 if\n    * 'memory' was NULL, the write would have succeeded but for the memory\n    * buffer being too small.  *memory_bytes contains the required number of\n    * bytes and will be bigger that the original value.\n    */\n\n#define png_image_write_get_memory_size(image, size, convert_to_8_bit, buffer,\\\n   row_stride, colormap)\\\n   png_image_write_to_memory(&(image), 0, &(size), convert_to_8_bit, buffer,\\\n         row_stride, colormap)\n   /* Return the amount of memory in 'size' required to compress this image.\n    * The png_image structure 'image' must be filled in as in the above\n    * function and must not be changed before the actual write call, the buffer\n    * and all other parameters must also be identical to that in the final\n    * write call.  The 'size' variable need not be initialized.\n    *\n    * NOTE: the macro returns true/false, if false is returned 'size' will be\n    * set to zero and the write failed and probably will fail if tried again.\n    */\n\n/* You can pre-allocate the buffer by making sure it is of sufficient size\n * regardless of the amount of compression achieved.  The buffer size will\n * always be bigger than the original image and it will never be filled.  The\n * following macros are provided to assist in allocating the buffer.\n */\n#define PNG_IMAGE_DATA_SIZE(image) (PNG_IMAGE_SIZE(image)+(image).height)\n   /* The number of uncompressed bytes in the PNG byte encoding of the image;\n    * uncompressing the PNG IDAT data will give this number of bytes.\n    *\n    * NOTE: while PNG_IMAGE_SIZE cannot overflow for an image in memory this\n    * macro can because of the extra bytes used in the PNG byte encoding.  You\n    * need to avoid this macro if your image size approaches 2^30 in width or\n    * height.  The same goes for the remainder of these macros; they all produce\n    * bigger numbers than the actual in-memory image size.\n    */\n#ifndef PNG_ZLIB_MAX_SIZE\n#  define PNG_ZLIB_MAX_SIZE(b) ((b)+(((b)+7U)>>3)+(((b)+63U)>>6)+11U)\n   /* An upper bound on the number of compressed bytes given 'b' uncompressed\n    * bytes.  This is based on deflateBounds() in zlib; different\n    * implementations of zlib compression may conceivably produce more data so\n    * if your zlib implementation is not zlib itself redefine this macro\n    * appropriately.\n    */\n#endif\n\n#define PNG_IMAGE_COMPRESSED_SIZE_MAX(image)\\\n   PNG_ZLIB_MAX_SIZE((png_alloc_size_t)PNG_IMAGE_DATA_SIZE(image))\n   /* An upper bound on the size of the data in the PNG IDAT chunks. */\n\n#define PNG_IMAGE_PNG_SIZE_MAX_(image, image_size)\\\n   ((8U/*sig*/+25U/*IHDR*/+16U/*gAMA*/+44U/*cHRM*/+12U/*IEND*/+\\\n    (((image).format&PNG_FORMAT_FLAG_COLORMAP)?/*colormap: PLTE, tRNS*/\\\n    12U+3U*(image).colormap_entries/*PLTE data*/+\\\n    (((image).format&PNG_FORMAT_FLAG_ALPHA)?\\\n    12U/*tRNS*/+(image).colormap_entries:0U):0U)+\\\n    12U)+(12U*((image_size)/PNG_ZBUF_SIZE))/*IDAT*/+(image_size))\n   /* A helper for the following macro; if your compiler cannot handle the\n    * following macro use this one with the result of\n    * PNG_IMAGE_COMPRESSED_SIZE_MAX(image) as the second argument (most\n    * compilers should handle this just fine.)\n    */\n\n#define PNG_IMAGE_PNG_SIZE_MAX(image)\\\n   PNG_IMAGE_PNG_SIZE_MAX_(image, PNG_IMAGE_COMPRESSED_SIZE_MAX(image))\n   /* An upper bound on the total length of the PNG data stream for 'image'.\n    * The result is of type png_alloc_size_t, on 32-bit systems this may\n    * overflow even though PNG_IMAGE_DATA_SIZE does not overflow; the write will\n    * run out of buffer space but return a corrected size which should work.\n    */\n#endif /* SIMPLIFIED_WRITE */\n/*******************************************************************************\n *  END OF SIMPLIFIED API\n ******************************************************************************/\n#endif /* SIMPLIFIED_{READ|WRITE} */\n\n/*******************************************************************************\n * Section 6: IMPLEMENTATION OPTIONS\n *******************************************************************************\n *\n * Support for arbitrary implementation-specific optimizations.  The API allows\n * particular options to be turned on or off.  'Option' is the number of the\n * option and 'onoff' is 0 (off) or non-0 (on).  The value returned is given\n * by the PNG_OPTION_ defines below.\n *\n * HARDWARE: normally hardware capabilites, such as the Intel SSE instructions,\n *           are detected at run time, however sometimes it may be impossible\n *           to do this in user mode, in which case it is necessary to discover\n *           the capabilities in an OS specific way.  Such capabilities are\n *           listed here when libpng has support for them and must be turned\n *           ON by the application if present.\n *\n * SOFTWARE: sometimes software optimizations actually result in performance\n *           decrease on some architectures or systems, or with some sets of\n *           PNG images.  'Software' options allow such optimizations to be\n *           selected at run time.\n */\n#ifdef PNG_SET_OPTION_SUPPORTED\n#ifdef PNG_ARM_NEON_API_SUPPORTED\n#  define PNG_ARM_NEON   0 /* HARDWARE: ARM Neon SIMD instructions supported */\n#endif\n#define PNG_MAXIMUM_INFLATE_WINDOW 2 /* SOFTWARE: force maximum window */\n#define PNG_SKIP_sRGB_CHECK_PROFILE 4 /* SOFTWARE: Check ICC profile for sRGB */\n#ifdef PNG_MIPS_MSA_API_SUPPORTED\n#  define PNG_MIPS_MSA   6 /* HARDWARE: MIPS Msa SIMD instructions supported */\n#endif\n#define PNG_OPTION_NEXT  8 /* Next option - numbers must be even */\n\n/* Return values: NOTE: there are four values and 'off' is *not* zero */\n#define PNG_OPTION_UNSET   0 /* Unset - defaults to off */\n#define PNG_OPTION_INVALID 1 /* Option number out of range */\n#define PNG_OPTION_OFF     2\n#define PNG_OPTION_ON      3\n\nPNG_EXPORT(244, int, png_set_option, (png_structrp png_ptr, int option,\n   int onoff));\n#endif /* SET_OPTION */\n\n/*******************************************************************************\n *  END OF HARDWARE AND SOFTWARE OPTIONS\n ******************************************************************************/\n\n/* Maintainer: Put new public prototypes here ^, in libpng.3, in project\n * defs, and in scripts/symbols.def.\n */\n\n/* The last ordinal number (this is the *last* one already used; the next\n * one to use is one more than this.)\n */\n#ifdef PNG_EXPORT_LAST_ORDINAL\n  PNG_EXPORT_LAST_ORDINAL(245);\n#endif\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* PNG_VERSION_INFO_ONLY */\n/* Do not put anything past this line */\n#endif /* PNG_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngconf.h",
    "content": "\n/* pngconf.h - machine configurable file for libpng\n *\n * libpng version 1.6.25, September 1, 2016\n *\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * Any machine specific code is near the front of this file, so if you\n * are configuring libpng for a machine, you may want to read the section\n * starting here down to where it starts to typedef png_color, png_text,\n * and png_info.\n */\n\n#ifndef PNGCONF_H\n#define PNGCONF_H\n\n#ifndef PNG_BUILDING_SYMBOL_TABLE /* else includes may cause problems */\n\n/* From libpng 1.6.0 libpng requires an ANSI X3.159-1989 (\"ISOC90\") compliant C\n * compiler for correct compilation.  The following header files are required by\n * the standard.  If your compiler doesn't provide these header files, or they\n * do not match the standard, you will need to provide/improve them.\n */\n#include <limits.h>\n#include <stddef.h>\n\n/* Library header files.  These header files are all defined by ISOC90; libpng\n * expects conformant implementations, however, an ISOC90 conformant system need\n * not provide these header files if the functionality cannot be implemented.\n * In this case it will be necessary to disable the relevant parts of libpng in\n * the build of pnglibconf.h.\n *\n * Prior to 1.6.0 string.h was included here; the API changes in 1.6.0 to not\n * include this unnecessary header file.\n */\n\n#ifdef PNG_STDIO_SUPPORTED\n   /* Required for the definition of FILE: */\n#  include <stdio.h>\n#endif\n\n#ifdef PNG_SETJMP_SUPPORTED\n   /* Required for the definition of jmp_buf and the declaration of longjmp: */\n#  include <setjmp.h>\n#endif\n\n#ifdef PNG_CONVERT_tIME_SUPPORTED\n   /* Required for struct tm: */\n#  include <time.h>\n#endif\n\n#endif /* PNG_BUILDING_SYMBOL_TABLE */\n\n/* Prior to 1.6.0 it was possible to turn off 'const' in declarations using\n * PNG_NO_CONST; this is no longer supported except for data declarations which\n * apparently still cause problems in 2011 on some compilers.\n */\n#define PNG_CONST const /* backward compatibility only */\n\n/* This controls optimization of the reading of 16-bit and 32-bit values\n * from PNG files.  It can be set on a per-app-file basis - it\n * just changes whether a macro is used when the function is called.\n * The library builder sets the default; if read functions are not\n * built into the library the macro implementation is forced on.\n */\n#ifndef PNG_READ_INT_FUNCTIONS_SUPPORTED\n#  define PNG_USE_READ_MACROS\n#endif\n#if !defined(PNG_NO_USE_READ_MACROS) && !defined(PNG_USE_READ_MACROS)\n#  if PNG_DEFAULT_READ_MACROS\n#    define PNG_USE_READ_MACROS\n#  endif\n#endif\n\n/* COMPILER SPECIFIC OPTIONS.\n *\n * These options are provided so that a variety of difficult compilers\n * can be used.  Some are fixed at build time (e.g. PNG_API_RULE\n * below) but still have compiler specific implementations, others\n * may be changed on a per-file basis when compiling against libpng.\n */\n\n/* The PNGARG macro was used in versions of libpng prior to 1.6.0 to protect\n * against legacy (pre ISOC90) compilers that did not understand function\n * prototypes.  It is not required for modern C compilers.\n */\n#ifndef PNGARG\n#  define PNGARG(arglist) arglist\n#endif\n\n/* Function calling conventions.\n * =============================\n * Normally it is not necessary to specify to the compiler how to call\n * a function - it just does it - however on x86 systems derived from\n * Microsoft and Borland C compilers ('IBM PC', 'DOS', 'Windows' systems\n * and some others) there are multiple ways to call a function and the\n * default can be changed on the compiler command line.  For this reason\n * libpng specifies the calling convention of every exported function and\n * every function called via a user supplied function pointer.  This is\n * done in this file by defining the following macros:\n *\n * PNGAPI    Calling convention for exported functions.\n * PNGCBAPI  Calling convention for user provided (callback) functions.\n * PNGCAPI   Calling convention used by the ANSI-C library (required\n *           for longjmp callbacks and sometimes used internally to\n *           specify the calling convention for zlib).\n *\n * These macros should never be overridden.  If it is necessary to\n * change calling convention in a private build this can be done\n * by setting PNG_API_RULE (which defaults to 0) to one of the values\n * below to select the correct 'API' variants.\n *\n * PNG_API_RULE=0 Use PNGCAPI - the 'C' calling convention - throughout.\n *                This is correct in every known environment.\n * PNG_API_RULE=1 Use the operating system convention for PNGAPI and\n *                the 'C' calling convention (from PNGCAPI) for\n *                callbacks (PNGCBAPI).  This is no longer required\n *                in any known environment - if it has to be used\n *                please post an explanation of the problem to the\n *                libpng mailing list.\n *\n * These cases only differ if the operating system does not use the C\n * calling convention, at present this just means the above cases\n * (x86 DOS/Windows sytems) and, even then, this does not apply to\n * Cygwin running on those systems.\n *\n * Note that the value must be defined in pnglibconf.h so that what\n * the application uses to call the library matches the conventions\n * set when building the library.\n */\n\n/* Symbol export\n * =============\n * When building a shared library it is almost always necessary to tell\n * the compiler which symbols to export.  The png.h macro 'PNG_EXPORT'\n * is used to mark the symbols.  On some systems these symbols can be\n * extracted at link time and need no special processing by the compiler,\n * on other systems the symbols are flagged by the compiler and just\n * the declaration requires a special tag applied (unfortunately) in a\n * compiler dependent way.  Some systems can do either.\n *\n * A small number of older systems also require a symbol from a DLL to\n * be flagged to the program that calls it.  This is a problem because\n * we do not know in the header file included by application code that\n * the symbol will come from a shared library, as opposed to a statically\n * linked one.  For this reason the application must tell us by setting\n * the magic flag PNG_USE_DLL to turn on the special processing before\n * it includes png.h.\n *\n * Four additional macros are used to make this happen:\n *\n * PNG_IMPEXP The magic (if any) to cause a symbol to be exported from\n *            the build or imported if PNG_USE_DLL is set - compiler\n *            and system specific.\n *\n * PNG_EXPORT_TYPE(type) A macro that pre or appends PNG_IMPEXP to\n *                       'type', compiler specific.\n *\n * PNG_DLL_EXPORT Set to the magic to use during a libpng build to\n *                make a symbol exported from the DLL.  Not used in the\n *                public header files; see pngpriv.h for how it is used\n *                in the libpng build.\n *\n * PNG_DLL_IMPORT Set to the magic to force the libpng symbols to come\n *                from a DLL - used to define PNG_IMPEXP when\n *                PNG_USE_DLL is set.\n */\n\n/* System specific discovery.\n * ==========================\n * This code is used at build time to find PNG_IMPEXP, the API settings\n * and PNG_EXPORT_TYPE(), it may also set a macro to indicate the DLL\n * import processing is possible.  On Windows systems it also sets\n * compiler-specific macros to the values required to change the calling\n * conventions of the various functions.\n */\n#if defined(_Windows) || defined(_WINDOWS) || defined(WIN32) ||\\\n    defined(_WIN32) || defined(__WIN32__) || defined(__CYGWIN__)\n  /* Windows system (DOS doesn't support DLLs).  Includes builds under Cygwin or\n   * MinGW on any architecture currently supported by Windows.  Also includes\n   * Watcom builds but these need special treatment because they are not\n   * compatible with GCC or Visual C because of different calling conventions.\n   */\n#  if PNG_API_RULE == 2\n   /* If this line results in an error, either because __watcall is not\n    * understood or because of a redefine just below you cannot use *this*\n    * build of the library with the compiler you are using.  *This* build was\n    * build using Watcom and applications must also be built using Watcom!\n    */\n#    define PNGCAPI __watcall\n#  endif\n\n#  if defined(__GNUC__) || (defined(_MSC_VER) && (_MSC_VER >= 800))\n#    define PNGCAPI __cdecl\n#    if PNG_API_RULE == 1\n   /* If this line results in an error __stdcall is not understood and\n    * PNG_API_RULE should not have been set to '1'.\n    */\n#      define PNGAPI __stdcall\n#    endif\n#  else\n   /* An older compiler, or one not detected (erroneously) above,\n    * if necessary override on the command line to get the correct\n    * variants for the compiler.\n    */\n#    ifndef PNGCAPI\n#      define PNGCAPI _cdecl\n#    endif\n#    if PNG_API_RULE == 1 && !defined(PNGAPI)\n#      define PNGAPI _stdcall\n#    endif\n#  endif /* compiler/api */\n\n  /* NOTE: PNGCBAPI always defaults to PNGCAPI. */\n\n#  if defined(PNGAPI) && !defined(PNG_USER_PRIVATEBUILD)\n#     error \"PNG_USER_PRIVATEBUILD must be defined if PNGAPI is changed\"\n#  endif\n\n#  if (defined(_MSC_VER) && _MSC_VER < 800) ||\\\n      (defined(__BORLANDC__) && __BORLANDC__ < 0x500)\n   /* older Borland and MSC\n    * compilers used '__export' and required this to be after\n    * the type.\n    */\n#    ifndef PNG_EXPORT_TYPE\n#      define PNG_EXPORT_TYPE(type) type PNG_IMPEXP\n#    endif\n#    define PNG_DLL_EXPORT __export\n#  else /* newer compiler */\n#    define PNG_DLL_EXPORT __declspec(dllexport)\n#    ifndef PNG_DLL_IMPORT\n#      define PNG_DLL_IMPORT __declspec(dllimport)\n#    endif\n#  endif /* compiler */\n\n#else /* !Windows */\n#  if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)\n#    define PNGAPI _System\n#  else /* !Windows/x86 && !OS/2 */\n   /* Use the defaults, or define PNG*API on the command line (but\n    * this will have to be done for every compile!)\n    */\n#  endif /* other system, !OS/2 */\n#endif /* !Windows/x86 */\n\n/* Now do all the defaulting . */\n#ifndef PNGCAPI\n#  define PNGCAPI\n#endif\n#ifndef PNGCBAPI\n#  define PNGCBAPI PNGCAPI\n#endif\n#ifndef PNGAPI\n#  define PNGAPI PNGCAPI\n#endif\n\n/* PNG_IMPEXP may be set on the compilation system command line or (if not set)\n * then in an internal header file when building the library, otherwise (when\n * using the library) it is set here.\n */\n#ifndef PNG_IMPEXP\n#  if defined(PNG_USE_DLL) && defined(PNG_DLL_IMPORT)\n   /* This forces use of a DLL, disallowing static linking */\n#    define PNG_IMPEXP PNG_DLL_IMPORT\n#  endif\n\n#  ifndef PNG_IMPEXP\n#    define PNG_IMPEXP\n#  endif\n#endif\n\n/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat\n * 'attributes' as a storage class - the attributes go at the start of the\n * function definition, and attributes are always appended regardless of the\n * compiler.  This considerably simplifies these macros but may cause problems\n * if any compilers both need function attributes and fail to handle them as\n * a storage class (this is unlikely.)\n */\n#ifndef PNG_FUNCTION\n#  define PNG_FUNCTION(type, name, args, attributes) attributes type name args\n#endif\n\n#ifndef PNG_EXPORT_TYPE\n#  define PNG_EXPORT_TYPE(type) PNG_IMPEXP type\n#endif\n\n   /* The ordinal value is only relevant when preprocessing png.h for symbol\n    * table entries, so we discard it here.  See the .dfn files in the\n    * scripts directory.\n    */\n\n#ifndef PNG_EXPORTA\n#  define PNG_EXPORTA(ordinal, type, name, args, attributes) \\\n      PNG_FUNCTION(PNG_EXPORT_TYPE(type), (PNGAPI name), PNGARG(args), \\\n      PNG_LINKAGE_API attributes)\n#endif\n\n/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,\n * so make something non-empty to satisfy the requirement:\n */\n#define PNG_EMPTY /*empty list*/\n\n#define PNG_EXPORT(ordinal, type, name, args) \\\n   PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)\n\n/* Use PNG_REMOVED to comment out a removed interface. */\n#ifndef PNG_REMOVED\n#  define PNG_REMOVED(ordinal, type, name, args, attributes)\n#endif\n\n#ifndef PNG_CALLBACK\n#  define PNG_CALLBACK(type, name, args) type (PNGCBAPI name) PNGARG(args)\n#endif\n\n/* Support for compiler specific function attributes.  These are used\n * so that where compiler support is available incorrect use of API\n * functions in png.h will generate compiler warnings.\n *\n * Added at libpng-1.2.41.\n */\n\n#ifndef PNG_NO_PEDANTIC_WARNINGS\n#  ifndef PNG_PEDANTIC_WARNINGS_SUPPORTED\n#    define PNG_PEDANTIC_WARNINGS_SUPPORTED\n#  endif\n#endif\n\n#ifdef PNG_PEDANTIC_WARNINGS_SUPPORTED\n  /* Support for compiler specific function attributes.  These are used\n   * so that where compiler support is available, incorrect use of API\n   * functions in png.h will generate compiler warnings.  Added at libpng\n   * version 1.2.41.  Disabling these removes the warnings but may also produce\n   * less efficient code.\n   */\n#  if defined(__clang__) && defined(__has_attribute)\n   /* Clang defines both __clang__ and __GNUC__. Check __clang__ first. */\n#    if !defined(PNG_USE_RESULT) && __has_attribute(__warn_unused_result__)\n#      define PNG_USE_RESULT __attribute__((__warn_unused_result__))\n#    endif\n#    if !defined(PNG_NORETURN) && __has_attribute(__noreturn__)\n#      define PNG_NORETURN __attribute__((__noreturn__))\n#    endif\n#    if !defined(PNG_ALLOCATED) && __has_attribute(__malloc__)\n#      define PNG_ALLOCATED __attribute__((__malloc__))\n#    endif\n#    if !defined(PNG_DEPRECATED) && __has_attribute(__deprecated__)\n#      define PNG_DEPRECATED __attribute__((__deprecated__))\n#    endif\n#    if !defined(PNG_PRIVATE)\n#      ifdef __has_extension\n#        if __has_extension(attribute_unavailable_with_message)\n#          define PNG_PRIVATE __attribute__((__unavailable__(\\\n             \"This function is not exported by libpng.\")))\n#        endif\n#      endif\n#    endif\n#    ifndef PNG_RESTRICT\n#      define PNG_RESTRICT __restrict\n#    endif\n\n#  elif defined(__GNUC__)\n#    ifndef PNG_USE_RESULT\n#      define PNG_USE_RESULT __attribute__((__warn_unused_result__))\n#    endif\n#    ifndef PNG_NORETURN\n#      define PNG_NORETURN   __attribute__((__noreturn__))\n#    endif\n#    if __GNUC__ >= 3\n#      ifndef PNG_ALLOCATED\n#        define PNG_ALLOCATED  __attribute__((__malloc__))\n#      endif\n#      ifndef PNG_DEPRECATED\n#        define PNG_DEPRECATED __attribute__((__deprecated__))\n#      endif\n#      ifndef PNG_PRIVATE\n#        if 0 /* Doesn't work so we use deprecated instead*/\n#          define PNG_PRIVATE \\\n            __attribute__((warning(\"This function is not exported by libpng.\")))\n#        else\n#          define PNG_PRIVATE \\\n            __attribute__((__deprecated__))\n#        endif\n#      endif\n#      if ((__GNUC__ > 3) || !defined(__GNUC_MINOR__) || (__GNUC_MINOR__ >= 1))\n#        ifndef PNG_RESTRICT\n#          define PNG_RESTRICT __restrict\n#        endif\n#      endif /* __GNUC__.__GNUC_MINOR__ > 3.0 */\n#    endif /* __GNUC__ >= 3 */\n\n#  elif defined(_MSC_VER)  && (_MSC_VER >= 1300)\n#    ifndef PNG_USE_RESULT\n#      define PNG_USE_RESULT /* not supported */\n#    endif\n#    ifndef PNG_NORETURN\n#      define PNG_NORETURN   __declspec(noreturn)\n#    endif\n#    ifndef PNG_ALLOCATED\n#      if (_MSC_VER >= 1400)\n#        define PNG_ALLOCATED __declspec(restrict)\n#      endif\n#    endif\n#    ifndef PNG_DEPRECATED\n#      define PNG_DEPRECATED __declspec(deprecated)\n#    endif\n#    ifndef PNG_PRIVATE\n#      define PNG_PRIVATE __declspec(deprecated)\n#    endif\n#    ifndef PNG_RESTRICT\n#      if (_MSC_VER >= 1400)\n#        define PNG_RESTRICT __restrict\n#      endif\n#    endif\n\n#  elif defined(__WATCOMC__)\n#    ifndef PNG_RESTRICT\n#      define PNG_RESTRICT __restrict\n#    endif\n#  endif\n#endif /* PNG_PEDANTIC_WARNINGS */\n\n#ifndef PNG_DEPRECATED\n#  define PNG_DEPRECATED  /* Use of this function is deprecated */\n#endif\n#ifndef PNG_USE_RESULT\n#  define PNG_USE_RESULT  /* The result of this function must be checked */\n#endif\n#ifndef PNG_NORETURN\n#  define PNG_NORETURN    /* This function does not return */\n#endif\n#ifndef PNG_ALLOCATED\n#  define PNG_ALLOCATED   /* The result of the function is new memory */\n#endif\n#ifndef PNG_PRIVATE\n#  define PNG_PRIVATE     /* This is a private libpng function */\n#endif\n#ifndef PNG_RESTRICT\n#  define PNG_RESTRICT    /* The C99 \"restrict\" feature */\n#endif\n\n#ifndef PNG_FP_EXPORT     /* A floating point API. */\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\n#     define PNG_FP_EXPORT(ordinal, type, name, args)\\\n         PNG_EXPORT(ordinal, type, name, args);\n#  else                   /* No floating point APIs */\n#     define PNG_FP_EXPORT(ordinal, type, name, args)\n#  endif\n#endif\n#ifndef PNG_FIXED_EXPORT  /* A fixed point API. */\n#  ifdef PNG_FIXED_POINT_SUPPORTED\n#     define PNG_FIXED_EXPORT(ordinal, type, name, args)\\\n         PNG_EXPORT(ordinal, type, name, args);\n#  else                   /* No fixed point APIs */\n#     define PNG_FIXED_EXPORT(ordinal, type, name, args)\n#  endif\n#endif\n\n#ifndef PNG_BUILDING_SYMBOL_TABLE\n/* Some typedefs to get us started.  These should be safe on most of the common\n * platforms.\n *\n * png_uint_32 and png_int_32 may, currently, be larger than required to hold a\n * 32-bit value however this is not normally advisable.\n *\n * png_uint_16 and png_int_16 should always be two bytes in size - this is\n * verified at library build time.\n *\n * png_byte must always be one byte in size.\n *\n * The checks below use constants from limits.h, as defined by the ISOC90\n * standard.\n */\n#if CHAR_BIT == 8 && UCHAR_MAX == 255\n   typedef unsigned char png_byte;\n#else\n#  error \"libpng requires 8-bit bytes\"\n#endif\n\n#if INT_MIN == -32768 && INT_MAX == 32767\n   typedef int png_int_16;\n#elif SHRT_MIN == -32768 && SHRT_MAX == 32767\n   typedef short png_int_16;\n#else\n#  error \"libpng requires a signed 16-bit type\"\n#endif\n\n#if UINT_MAX == 65535\n   typedef unsigned int png_uint_16;\n#elif USHRT_MAX == 65535\n   typedef unsigned short png_uint_16;\n#else\n#  error \"libpng requires an unsigned 16-bit type\"\n#endif\n\n#if INT_MIN < -2147483646 && INT_MAX > 2147483646\n   typedef int png_int_32;\n#elif LONG_MIN < -2147483646 && LONG_MAX > 2147483646\n   typedef long int png_int_32;\n#else\n#  error \"libpng requires a signed 32-bit (or more) type\"\n#endif\n\n#if UINT_MAX > 4294967294\n   typedef unsigned int png_uint_32;\n#elif ULONG_MAX > 4294967294\n   typedef unsigned long int png_uint_32;\n#else\n#  error \"libpng requires an unsigned 32-bit (or more) type\"\n#endif\n\n/* Prior to 1.6.0 it was possible to disable the use of size_t, 1.6.0, however,\n * requires an ISOC90 compiler and relies on consistent behavior of sizeof.\n */\ntypedef size_t png_size_t;\ntypedef ptrdiff_t png_ptrdiff_t;\n\n/* libpng needs to know the maximum value of 'size_t' and this controls the\n * definition of png_alloc_size_t, below.  This maximum value of size_t limits\n * but does not control the maximum allocations the library makes - there is\n * direct application control of this through png_set_user_limits().\n */\n#ifndef PNG_SMALL_SIZE_T\n   /* Compiler specific tests for systems where size_t is known to be less than\n    * 32 bits (some of these systems may no longer work because of the lack of\n    * 'far' support; see above.)\n    */\n#  if (defined(__TURBOC__) && !defined(__FLAT__)) ||\\\n   (defined(_MSC_VER) && defined(MAXSEG_64K))\n#     define PNG_SMALL_SIZE_T\n#  endif\n#endif\n\n/* png_alloc_size_t is guaranteed to be no smaller than png_size_t, and no\n * smaller than png_uint_32.  Casts from png_size_t or png_uint_32 to\n * png_alloc_size_t are not necessary; in fact, it is recommended not to use\n * them at all so that the compiler can complain when something turns out to be\n * problematic.\n *\n * Casts in the other direction (from png_alloc_size_t to png_size_t or\n * png_uint_32) should be explicitly applied; however, we do not expect to\n * encounter practical situations that require such conversions.\n *\n * PNG_SMALL_SIZE_T must be defined if the maximum value of size_t is less than\n * 4294967295 - i.e. less than the maximum value of png_uint_32.\n */\n#ifdef PNG_SMALL_SIZE_T\n   typedef png_uint_32 png_alloc_size_t;\n#else\n   typedef png_size_t png_alloc_size_t;\n#endif\n\n/* Prior to 1.6.0 libpng offered limited support for Microsoft C compiler\n * implementations of Intel CPU specific support of user-mode segmented address\n * spaces, where 16-bit pointers address more than 65536 bytes of memory using\n * separate 'segment' registers.  The implementation requires two different\n * types of pointer (only one of which includes the segment value.)\n *\n * If required this support is available in version 1.2 of libpng and may be\n * available in versions through 1.5, although the correctness of the code has\n * not been verified recently.\n */\n\n/* Typedef for floating-point numbers that are converted to fixed-point with a\n * multiple of 100,000, e.g., gamma\n */\ntypedef png_int_32 png_fixed_point;\n\n/* Add typedefs for pointers */\ntypedef void                  * png_voidp;\ntypedef const void            * png_const_voidp;\ntypedef png_byte              * png_bytep;\ntypedef const png_byte        * png_const_bytep;\ntypedef png_uint_32           * png_uint_32p;\ntypedef const png_uint_32     * png_const_uint_32p;\ntypedef png_int_32            * png_int_32p;\ntypedef const png_int_32      * png_const_int_32p;\ntypedef png_uint_16           * png_uint_16p;\ntypedef const png_uint_16     * png_const_uint_16p;\ntypedef png_int_16            * png_int_16p;\ntypedef const png_int_16      * png_const_int_16p;\ntypedef char                  * png_charp;\ntypedef const char            * png_const_charp;\ntypedef png_fixed_point       * png_fixed_point_p;\ntypedef const png_fixed_point * png_const_fixed_point_p;\ntypedef png_size_t            * png_size_tp;\ntypedef const png_size_t      * png_const_size_tp;\n\n#ifdef PNG_STDIO_SUPPORTED\ntypedef FILE            * png_FILE_p;\n#endif\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\ntypedef double       * png_doublep;\ntypedef const double * png_const_doublep;\n#endif\n\n/* Pointers to pointers; i.e. arrays */\ntypedef png_byte        * * png_bytepp;\ntypedef png_uint_32     * * png_uint_32pp;\ntypedef png_int_32      * * png_int_32pp;\ntypedef png_uint_16     * * png_uint_16pp;\ntypedef png_int_16      * * png_int_16pp;\ntypedef const char      * * png_const_charpp;\ntypedef char            * * png_charpp;\ntypedef png_fixed_point * * png_fixed_point_pp;\n#ifdef PNG_FLOATING_POINT_SUPPORTED\ntypedef double          * * png_doublepp;\n#endif\n\n/* Pointers to pointers to pointers; i.e., pointer to array */\ntypedef char            * * * png_charppp;\n\n#endif /* PNG_BUILDING_SYMBOL_TABLE */\n\n#endif /* PNGCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngdebug.h",
    "content": "\n/* pngdebug.h - Debugging macros for libpng, also used in pngtest.c\n *\n * Last changed in libpng 1.6.8 [December 19, 2013]\n * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* Define PNG_DEBUG at compile time for debugging information.  Higher\n * numbers for PNG_DEBUG mean more debugging information.  This has\n * only been added since version 0.95 so it is not implemented throughout\n * libpng yet, but more support will be added as needed.\n *\n * png_debug[1-2]?(level, message ,arg{0-2})\n *   Expands to a statement (either a simple expression or a compound\n *   do..while(0) statement) that outputs a message with parameter\n *   substitution if PNG_DEBUG is defined to 2 or more.  If PNG_DEBUG\n *   is undefined, 0 or 1 every png_debug expands to a simple expression\n *   (actually ((void)0)).\n *\n *   level: level of detail of message, starting at 0.  A level 'n'\n *          message is preceded by 'n' 3-space indentations (not implemented\n *          on Microsoft compilers unless PNG_DEBUG_FILE is also\n *          defined, to allow debug DLL compilation with no standard IO).\n *   message: a printf(3) style text string.  A trailing '\\n' is added\n *            to the message.\n *   arg: 0 to 2 arguments for printf(3) style substitution in message.\n */\n#ifndef PNGDEBUG_H\n#define PNGDEBUG_H\n/* These settings control the formatting of messages in png.c and pngerror.c */\n/* Moved to pngdebug.h at 1.5.0 */\n#  ifndef PNG_LITERAL_SHARP\n#    define PNG_LITERAL_SHARP 0x23\n#  endif\n#  ifndef PNG_LITERAL_LEFT_SQUARE_BRACKET\n#    define PNG_LITERAL_LEFT_SQUARE_BRACKET 0x5b\n#  endif\n#  ifndef PNG_LITERAL_RIGHT_SQUARE_BRACKET\n#    define PNG_LITERAL_RIGHT_SQUARE_BRACKET 0x5d\n#  endif\n#  ifndef PNG_STRING_NEWLINE\n#    define PNG_STRING_NEWLINE \"\\n\"\n#  endif\n\n#ifdef PNG_DEBUG\n#  if (PNG_DEBUG > 0)\n#    if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)\n#      include <crtdbg.h>\n#      if (PNG_DEBUG > 1)\n#        ifndef _DEBUG\n#          define _DEBUG\n#        endif\n#        ifndef png_debug\n#          define png_debug(l,m)  _RPT0(_CRT_WARN,m PNG_STRING_NEWLINE)\n#        endif\n#        ifndef png_debug1\n#          define png_debug1(l,m,p1)  _RPT1(_CRT_WARN,m PNG_STRING_NEWLINE,p1)\n#        endif\n#        ifndef png_debug2\n#          define png_debug2(l,m,p1,p2) \\\n             _RPT2(_CRT_WARN,m PNG_STRING_NEWLINE,p1,p2)\n#        endif\n#      endif\n#    else /* PNG_DEBUG_FILE || !_MSC_VER */\n#      ifndef PNG_STDIO_SUPPORTED\n#        include <stdio.h> /* not included yet */\n#      endif\n#      ifndef PNG_DEBUG_FILE\n#        define PNG_DEBUG_FILE stderr\n#      endif /* PNG_DEBUG_FILE */\n\n#      if (PNG_DEBUG > 1)\n#        ifdef __STDC__\n#          ifndef png_debug\n#            define png_debug(l,m) \\\n       do { \\\n       int num_tabs=l; \\\n       fprintf(PNG_DEBUG_FILE,\"%s\" m PNG_STRING_NEWLINE,(num_tabs==1 ? \"   \" : \\\n         (num_tabs==2 ? \"      \" : (num_tabs>2 ? \"         \" : \"\")))); \\\n       } while (0)\n#          endif\n#          ifndef png_debug1\n#            define png_debug1(l,m,p1) \\\n       do { \\\n       int num_tabs=l; \\\n       fprintf(PNG_DEBUG_FILE,\"%s\" m PNG_STRING_NEWLINE,(num_tabs==1 ? \"   \" : \\\n         (num_tabs==2 ? \"      \" : (num_tabs>2 ? \"         \" : \"\"))),p1); \\\n       } while (0)\n#          endif\n#          ifndef png_debug2\n#            define png_debug2(l,m,p1,p2) \\\n       do { \\\n       int num_tabs=l; \\\n       fprintf(PNG_DEBUG_FILE,\"%s\" m PNG_STRING_NEWLINE,(num_tabs==1 ? \"   \" : \\\n         (num_tabs==2 ? \"      \" : (num_tabs>2 ? \"         \" : \"\"))),p1,p2);\\\n       } while (0)\n#          endif\n#        else /* __STDC __ */\n#          ifndef png_debug\n#            define png_debug(l,m) \\\n       do { \\\n       int num_tabs=l; \\\n       char format[256]; \\\n       snprintf(format,256,\"%s%s%s\",(num_tabs==1 ? \"\\t\" : \\\n         (num_tabs==2 ? \"\\t\\t\":(num_tabs>2 ? \"\\t\\t\\t\":\"\"))), \\\n         m,PNG_STRING_NEWLINE); \\\n       fprintf(PNG_DEBUG_FILE,format); \\\n       } while (0)\n#          endif\n#          ifndef png_debug1\n#            define png_debug1(l,m,p1) \\\n       do { \\\n       int num_tabs=l; \\\n       char format[256]; \\\n       snprintf(format,256,\"%s%s%s\",(num_tabs==1 ? \"\\t\" : \\\n         (num_tabs==2 ? \"\\t\\t\":(num_tabs>2 ? \"\\t\\t\\t\":\"\"))), \\\n         m,PNG_STRING_NEWLINE); \\\n       fprintf(PNG_DEBUG_FILE,format,p1); \\\n       } while (0)\n#          endif\n#          ifndef png_debug2\n#            define png_debug2(l,m,p1,p2) \\\n       do { \\\n       int num_tabs=l; \\\n       char format[256]; \\\n       snprintf(format,256,\"%s%s%s\",(num_tabs==1 ? \"\\t\" : \\\n         (num_tabs==2 ? \"\\t\\t\":(num_tabs>2 ? \"\\t\\t\\t\":\"\"))), \\\n         m,PNG_STRING_NEWLINE); \\\n       fprintf(PNG_DEBUG_FILE,format,p1,p2); \\\n       } while (0)\n#          endif\n#        endif /* __STDC __ */\n#      endif /* (PNG_DEBUG > 1) */\n\n#    endif /* _MSC_VER */\n#  endif /* (PNG_DEBUG > 0) */\n#endif /* PNG_DEBUG */\n#ifndef png_debug\n#  define png_debug(l, m) ((void)0)\n#endif\n#ifndef png_debug1\n#  define png_debug1(l, m, p1) ((void)0)\n#endif\n#ifndef png_debug2\n#  define png_debug2(l, m, p1, p2) ((void)0)\n#endif\n#endif /* PNGDEBUG_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngerror.c",
    "content": "\n/* pngerror.c - stub functions for i/o and memory allocation\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file provides a location for all error handling.  Users who\n * need special error handling are expected to write replacement functions\n * and use png_set_error_fn() to use those functions.  See the instructions\n * at each function.\n */\n\n#include \"pngpriv.h\"\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n\nstatic PNG_FUNCTION(void, png_default_error,PNGARG((png_const_structrp png_ptr,\n    png_const_charp error_message)),PNG_NORETURN);\n\n#ifdef PNG_WARNINGS_SUPPORTED\nstatic void /* PRIVATE */\npng_default_warning PNGARG((png_const_structrp png_ptr,\n    png_const_charp warning_message));\n#endif /* WARNINGS */\n\n/* This function is called whenever there is a fatal error.  This function\n * should not be changed.  If there is a need to handle errors differently,\n * you should supply a replacement error function and use png_set_error_fn()\n * to replace the error function at run-time.\n */\n#ifdef PNG_ERROR_TEXT_SUPPORTED\nPNG_FUNCTION(void,PNGAPI\npng_error,(png_const_structrp png_ptr, png_const_charp error_message),\n    PNG_NORETURN)\n{\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\n   char msg[16];\n   if (png_ptr != NULL)\n   {\n      if ((png_ptr->flags &\n         (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)\n      {\n         if (*error_message == PNG_LITERAL_SHARP)\n         {\n            /* Strip \"#nnnn \" from beginning of error message. */\n            int offset;\n            for (offset = 1; offset<15; offset++)\n               if (error_message[offset] == ' ')\n                  break;\n\n            if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)\n            {\n               int i;\n               for (i = 0; i < offset - 1; i++)\n                  msg[i] = error_message[i + 1];\n               msg[i - 1] = '\\0';\n               error_message = msg;\n            }\n\n            else\n               error_message += offset;\n         }\n\n         else\n         {\n            if ((png_ptr->flags & PNG_FLAG_STRIP_ERROR_TEXT) != 0)\n            {\n               msg[0] = '0';\n               msg[1] = '\\0';\n               error_message = msg;\n            }\n         }\n      }\n   }\n#endif\n   if (png_ptr != NULL && png_ptr->error_fn != NULL)\n      (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr),\n          error_message);\n\n   /* If the custom handler doesn't exist, or if it returns,\n      use the default handler, which will not return. */\n   png_default_error(png_ptr, error_message);\n}\n#else\nPNG_FUNCTION(void,PNGAPI\npng_err,(png_const_structrp png_ptr),PNG_NORETURN)\n{\n   /* Prior to 1.5.2 the error_fn received a NULL pointer, expressed\n    * erroneously as '\\0', instead of the empty string \"\".  This was\n    * apparently an error, introduced in libpng-1.2.20, and png_default_error\n    * will crash in this case.\n    */\n   if (png_ptr != NULL && png_ptr->error_fn != NULL)\n      (*(png_ptr->error_fn))(png_constcast(png_structrp,png_ptr), \"\");\n\n   /* If the custom handler doesn't exist, or if it returns,\n      use the default handler, which will not return. */\n   png_default_error(png_ptr, \"\");\n}\n#endif /* ERROR_TEXT */\n\n/* Utility to safely appends strings to a buffer.  This never errors out so\n * error checking is not required in the caller.\n */\nsize_t\npng_safecat(png_charp buffer, size_t bufsize, size_t pos,\n    png_const_charp string)\n{\n   if (buffer != NULL && pos < bufsize)\n   {\n      if (string != NULL)\n         while (*string != '\\0' && pos < bufsize-1)\n           buffer[pos++] = *string++;\n\n      buffer[pos] = '\\0';\n   }\n\n   return pos;\n}\n\n#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)\n/* Utility to dump an unsigned value into a buffer, given a start pointer and\n * and end pointer (which should point just *beyond* the end of the buffer!)\n * Returns the pointer to the start of the formatted string.\n */\npng_charp\npng_format_number(png_const_charp start, png_charp end, int format,\n    png_alloc_size_t number)\n{\n   int count = 0;    /* number of digits output */\n   int mincount = 1; /* minimum number required */\n   int output = 0;   /* digit output (for the fixed point format) */\n\n   *--end = '\\0';\n\n   /* This is written so that the loop always runs at least once, even with\n    * number zero.\n    */\n   while (end > start && (number != 0 || count < mincount))\n   {\n\n      static const char digits[] = \"0123456789ABCDEF\";\n\n      switch (format)\n      {\n         case PNG_NUMBER_FORMAT_fixed:\n            /* Needs five digits (the fraction) */\n            mincount = 5;\n            if (output != 0 || number % 10 != 0)\n            {\n               *--end = digits[number % 10];\n               output = 1;\n            }\n            number /= 10;\n            break;\n\n         case PNG_NUMBER_FORMAT_02u:\n            /* Expects at least 2 digits. */\n            mincount = 2;\n            /* FALL THROUGH */\n\n         case PNG_NUMBER_FORMAT_u:\n            *--end = digits[number % 10];\n            number /= 10;\n            break;\n\n         case PNG_NUMBER_FORMAT_02x:\n            /* This format expects at least two digits */\n            mincount = 2;\n            /* FALL THROUGH */\n\n         case PNG_NUMBER_FORMAT_x:\n            *--end = digits[number & 0xf];\n            number >>= 4;\n            break;\n\n         default: /* an error */\n            number = 0;\n            break;\n      }\n\n      /* Keep track of the number of digits added */\n      ++count;\n\n      /* Float a fixed number here: */\n      if ((format == PNG_NUMBER_FORMAT_fixed) && (count == 5) && (end > start))\n      {\n         /* End of the fraction, but maybe nothing was output?  In that case\n          * drop the decimal point.  If the number is a true zero handle that\n          * here.\n          */\n         if (output != 0)\n            *--end = '.';\n         else if (number == 0) /* and !output */\n            *--end = '0';\n      }\n   }\n\n   return end;\n}\n#endif\n\n#ifdef PNG_WARNINGS_SUPPORTED\n/* This function is called whenever there is a non-fatal error.  This function\n * should not be changed.  If there is a need to handle warnings differently,\n * you should supply a replacement warning function and use\n * png_set_error_fn() to replace the warning function at run-time.\n */\nvoid PNGAPI\npng_warning(png_const_structrp png_ptr, png_const_charp warning_message)\n{\n   int offset = 0;\n   if (png_ptr != NULL)\n   {\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\n   if ((png_ptr->flags &\n       (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT)) != 0)\n#endif\n      {\n         if (*warning_message == PNG_LITERAL_SHARP)\n         {\n            for (offset = 1; offset < 15; offset++)\n               if (warning_message[offset] == ' ')\n                  break;\n         }\n      }\n   }\n   if (png_ptr != NULL && png_ptr->warning_fn != NULL)\n      (*(png_ptr->warning_fn))(png_constcast(png_structrp,png_ptr),\n          warning_message + offset);\n   else\n      png_default_warning(png_ptr, warning_message + offset);\n}\n\n/* These functions support 'formatted' warning messages with up to\n * PNG_WARNING_PARAMETER_COUNT parameters.  In the format string the parameter\n * is introduced by @<number>, where 'number' starts at 1.  This follows the\n * standard established by X/Open for internationalizable error messages.\n */\nvoid\npng_warning_parameter(png_warning_parameters p, int number,\n    png_const_charp string)\n{\n   if (number > 0 && number <= PNG_WARNING_PARAMETER_COUNT)\n      (void)png_safecat(p[number-1], (sizeof p[number-1]), 0, string);\n}\n\nvoid\npng_warning_parameter_unsigned(png_warning_parameters p, int number, int format,\n    png_alloc_size_t value)\n{\n   char buffer[PNG_NUMBER_BUFFER_SIZE];\n   png_warning_parameter(p, number, PNG_FORMAT_NUMBER(buffer, format, value));\n}\n\nvoid\npng_warning_parameter_signed(png_warning_parameters p, int number, int format,\n    png_int_32 value)\n{\n   png_alloc_size_t u;\n   png_charp str;\n   char buffer[PNG_NUMBER_BUFFER_SIZE];\n\n   /* Avoid overflow by doing the negate in a png_alloc_size_t: */\n   u = (png_alloc_size_t)value;\n   if (value < 0)\n      u = ~u + 1;\n\n   str = PNG_FORMAT_NUMBER(buffer, format, u);\n\n   if (value < 0 && str > buffer)\n      *--str = '-';\n\n   png_warning_parameter(p, number, str);\n}\n\nvoid\npng_formatted_warning(png_const_structrp png_ptr, png_warning_parameters p,\n    png_const_charp message)\n{\n   /* The internal buffer is just 192 bytes - enough for all our messages,\n    * overflow doesn't happen because this code checks!  If someone figures\n    * out how to send us a message longer than 192 bytes, all that will\n    * happen is that the message will be truncated appropriately.\n    */\n   size_t i = 0; /* Index in the msg[] buffer: */\n   char msg[192];\n\n   /* Each iteration through the following loop writes at most one character\n    * to msg[i++] then returns here to validate that there is still space for\n    * the trailing '\\0'.  It may (in the case of a parameter) read more than\n    * one character from message[]; it must check for '\\0' and continue to the\n    * test if it finds the end of string.\n    */\n   while (i<(sizeof msg)-1 && *message != '\\0')\n   {\n      /* '@' at end of string is now just printed (previously it was skipped);\n       * it is an error in the calling code to terminate the string with @.\n       */\n      if (p != NULL && *message == '@' && message[1] != '\\0')\n      {\n         int parameter_char = *++message; /* Consume the '@' */\n         static const char valid_parameters[] = \"123456789\";\n         int parameter = 0;\n\n         /* Search for the parameter digit, the index in the string is the\n          * parameter to use.\n          */\n         while (valid_parameters[parameter] != parameter_char &&\n            valid_parameters[parameter] != '\\0')\n            ++parameter;\n\n         /* If the parameter digit is out of range it will just get printed. */\n         if (parameter < PNG_WARNING_PARAMETER_COUNT)\n         {\n            /* Append this parameter */\n            png_const_charp parm = p[parameter];\n            png_const_charp pend = p[parameter] + (sizeof p[parameter]);\n\n            /* No need to copy the trailing '\\0' here, but there is no guarantee\n             * that parm[] has been initialized, so there is no guarantee of a\n             * trailing '\\0':\n             */\n            while (i<(sizeof msg)-1 && *parm != '\\0' && parm < pend)\n               msg[i++] = *parm++;\n\n            /* Consume the parameter digit too: */\n            ++message;\n            continue;\n         }\n\n         /* else not a parameter and there is a character after the @ sign; just\n          * copy that.  This is known not to be '\\0' because of the test above.\n          */\n      }\n\n      /* At this point *message can't be '\\0', even in the bad parameter case\n       * above where there is a lone '@' at the end of the message string.\n       */\n      msg[i++] = *message++;\n   }\n\n   /* i is always less than (sizeof msg), so: */\n   msg[i] = '\\0';\n\n   /* And this is the formatted message. It may be larger than\n    * PNG_MAX_ERROR_TEXT, but that is only used for 'chunk' errors and these\n    * are not (currently) formatted.\n    */\n   png_warning(png_ptr, msg);\n}\n#endif /* WARNINGS */\n\n#ifdef PNG_BENIGN_ERRORS_SUPPORTED\nvoid PNGAPI\npng_benign_error(png_const_structrp png_ptr, png_const_charp error_message)\n{\n   if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)\n   {\n#     ifdef PNG_READ_SUPPORTED\n         if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&\n            png_ptr->chunk_name != 0)\n            png_chunk_warning(png_ptr, error_message);\n         else\n#     endif\n      png_warning(png_ptr, error_message);\n   }\n\n   else\n   {\n#     ifdef PNG_READ_SUPPORTED\n         if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&\n            png_ptr->chunk_name != 0)\n            png_chunk_error(png_ptr, error_message);\n         else\n#     endif\n      png_error(png_ptr, error_message);\n   }\n\n#  ifndef PNG_ERROR_TEXT_SUPPORTED\n      PNG_UNUSED(error_message)\n#  endif\n}\n\nvoid /* PRIVATE */\npng_app_warning(png_const_structrp png_ptr, png_const_charp error_message)\n{\n   if ((png_ptr->flags & PNG_FLAG_APP_WARNINGS_WARN) != 0)\n      png_warning(png_ptr, error_message);\n   else\n      png_error(png_ptr, error_message);\n\n#  ifndef PNG_ERROR_TEXT_SUPPORTED\n      PNG_UNUSED(error_message)\n#  endif\n}\n\nvoid /* PRIVATE */\npng_app_error(png_const_structrp png_ptr, png_const_charp error_message)\n{\n   if ((png_ptr->flags & PNG_FLAG_APP_ERRORS_WARN) != 0)\n      png_warning(png_ptr, error_message);\n   else\n      png_error(png_ptr, error_message);\n\n#  ifndef PNG_ERROR_TEXT_SUPPORTED\n      PNG_UNUSED(error_message)\n#  endif\n}\n#endif /* BENIGN_ERRORS */\n\n#define PNG_MAX_ERROR_TEXT 196 /* Currently limited by profile_error in png.c */\n#if defined(PNG_WARNINGS_SUPPORTED) || \\\n   (defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED))\n/* These utilities are used internally to build an error message that relates\n * to the current chunk.  The chunk name comes from png_ptr->chunk_name,\n * which is used to prefix the message.  The message is limited in length\n * to 63 bytes. The name characters are output as hex digits wrapped in []\n * if the character is invalid.\n */\n#define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))\nstatic PNG_CONST char png_digit[16] = {\n   '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\n   'A', 'B', 'C', 'D', 'E', 'F'\n};\n\nstatic void /* PRIVATE */\npng_format_buffer(png_const_structrp png_ptr, png_charp buffer, png_const_charp\n    error_message)\n{\n   png_uint_32 chunk_name = png_ptr->chunk_name;\n   int iout = 0, ishift = 24;\n\n   while (ishift >= 0)\n   {\n      int c = (int)(chunk_name >> ishift) & 0xff;\n\n      ishift -= 8;\n      if (isnonalpha(c) != 0)\n      {\n         buffer[iout++] = PNG_LITERAL_LEFT_SQUARE_BRACKET;\n         buffer[iout++] = png_digit[(c & 0xf0) >> 4];\n         buffer[iout++] = png_digit[c & 0x0f];\n         buffer[iout++] = PNG_LITERAL_RIGHT_SQUARE_BRACKET;\n      }\n\n      else\n      {\n         buffer[iout++] = (char)c;\n      }\n   }\n\n   if (error_message == NULL)\n      buffer[iout] = '\\0';\n\n   else\n   {\n      int iin = 0;\n\n      buffer[iout++] = ':';\n      buffer[iout++] = ' ';\n\n      while (iin < PNG_MAX_ERROR_TEXT-1 && error_message[iin] != '\\0')\n         buffer[iout++] = error_message[iin++];\n\n      /* iin < PNG_MAX_ERROR_TEXT, so the following is safe: */\n      buffer[iout] = '\\0';\n   }\n}\n#endif /* WARNINGS || ERROR_TEXT */\n\n#if defined(PNG_READ_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)\nPNG_FUNCTION(void,PNGAPI\npng_chunk_error,(png_const_structrp png_ptr, png_const_charp error_message),\n    PNG_NORETURN)\n{\n   char msg[18+PNG_MAX_ERROR_TEXT];\n   if (png_ptr == NULL)\n      png_error(png_ptr, error_message);\n\n   else\n   {\n      png_format_buffer(png_ptr, msg, error_message);\n      png_error(png_ptr, msg);\n   }\n}\n#endif /* READ && ERROR_TEXT */\n\n#ifdef PNG_WARNINGS_SUPPORTED\nvoid PNGAPI\npng_chunk_warning(png_const_structrp png_ptr, png_const_charp warning_message)\n{\n   char msg[18+PNG_MAX_ERROR_TEXT];\n   if (png_ptr == NULL)\n      png_warning(png_ptr, warning_message);\n\n   else\n   {\n      png_format_buffer(png_ptr, msg, warning_message);\n      png_warning(png_ptr, msg);\n   }\n}\n#endif /* WARNINGS */\n\n#ifdef PNG_READ_SUPPORTED\n#ifdef PNG_BENIGN_ERRORS_SUPPORTED\nvoid PNGAPI\npng_chunk_benign_error(png_const_structrp png_ptr, png_const_charp\n    error_message)\n{\n   if ((png_ptr->flags & PNG_FLAG_BENIGN_ERRORS_WARN) != 0)\n      png_chunk_warning(png_ptr, error_message);\n\n   else\n      png_chunk_error(png_ptr, error_message);\n\n#  ifndef PNG_ERROR_TEXT_SUPPORTED\n      PNG_UNUSED(error_message)\n#  endif\n}\n#endif\n#endif /* READ */\n\nvoid /* PRIVATE */\npng_chunk_report(png_const_structrp png_ptr, png_const_charp message, int error)\n{\n#  ifndef PNG_WARNINGS_SUPPORTED\n      PNG_UNUSED(message)\n#  endif\n\n   /* This is always supported, but for just read or just write it\n    * unconditionally does the right thing.\n    */\n#  if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)\n      if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\n#  endif\n\n#  ifdef PNG_READ_SUPPORTED\n      {\n         if (error < PNG_CHUNK_ERROR)\n            png_chunk_warning(png_ptr, message);\n\n         else\n            png_chunk_benign_error(png_ptr, message);\n      }\n#  endif\n\n#  if defined(PNG_READ_SUPPORTED) && defined(PNG_WRITE_SUPPORTED)\n      else if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\n#  endif\n\n#  ifdef PNG_WRITE_SUPPORTED\n      {\n         if (error < PNG_CHUNK_WRITE_ERROR)\n            png_app_warning(png_ptr, message);\n\n         else\n            png_app_error(png_ptr, message);\n      }\n#  endif\n}\n\n#ifdef PNG_ERROR_TEXT_SUPPORTED\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nPNG_FUNCTION(void,\npng_fixed_error,(png_const_structrp png_ptr, png_const_charp name),PNG_NORETURN)\n{\n#  define fixed_message \"fixed point overflow in \"\n#  define fixed_message_ln ((sizeof fixed_message)-1)\n   int  iin;\n   char msg[fixed_message_ln+PNG_MAX_ERROR_TEXT];\n   memcpy(msg, fixed_message, fixed_message_ln);\n   iin = 0;\n   if (name != NULL)\n      while (iin < (PNG_MAX_ERROR_TEXT-1) && name[iin] != 0)\n      {\n         msg[fixed_message_ln + iin] = name[iin];\n         ++iin;\n      }\n   msg[fixed_message_ln + iin] = 0;\n   png_error(png_ptr, msg);\n}\n#endif\n#endif\n\n#ifdef PNG_SETJMP_SUPPORTED\n/* This API only exists if ANSI-C style error handling is used,\n * otherwise it is necessary for png_default_error to be overridden.\n */\njmp_buf* PNGAPI\npng_set_longjmp_fn(png_structrp png_ptr, png_longjmp_ptr longjmp_fn,\n    size_t jmp_buf_size)\n{\n   /* From libpng 1.6.0 the app gets one chance to set a 'jmpbuf_size' value\n    * and it must not change after that.  Libpng doesn't care how big the\n    * buffer is, just that it doesn't change.\n    *\n    * If the buffer size is no *larger* than the size of jmp_buf when libpng is\n    * compiled a built in jmp_buf is returned; this preserves the pre-1.6.0\n    * semantics that this call will not fail.  If the size is larger, however,\n    * the buffer is allocated and this may fail, causing the function to return\n    * NULL.\n    */\n   if (png_ptr == NULL)\n      return NULL;\n\n   if (png_ptr->jmp_buf_ptr == NULL)\n   {\n      png_ptr->jmp_buf_size = 0; /* not allocated */\n\n      if (jmp_buf_size <= (sizeof png_ptr->jmp_buf_local))\n         png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local;\n\n      else\n      {\n         png_ptr->jmp_buf_ptr = png_voidcast(jmp_buf *,\n             png_malloc_warn(png_ptr, jmp_buf_size));\n\n         if (png_ptr->jmp_buf_ptr == NULL)\n            return NULL; /* new NULL return on OOM */\n\n         png_ptr->jmp_buf_size = jmp_buf_size;\n      }\n   }\n\n   else /* Already allocated: check the size */\n   {\n      size_t size = png_ptr->jmp_buf_size;\n\n      if (size == 0)\n      {\n         size = (sizeof png_ptr->jmp_buf_local);\n         if (png_ptr->jmp_buf_ptr != &png_ptr->jmp_buf_local)\n         {\n            /* This is an internal error in libpng: somehow we have been left\n             * with a stack allocated jmp_buf when the application regained\n             * control.  It's always possible to fix this up, but for the moment\n             * this is a png_error because that makes it easy to detect.\n             */\n            png_error(png_ptr, \"Libpng jmp_buf still allocated\");\n            /* png_ptr->jmp_buf_ptr = &png_ptr->jmp_buf_local; */\n         }\n      }\n\n      if (size != jmp_buf_size)\n      {\n         png_warning(png_ptr, \"Application jmp_buf size changed\");\n         return NULL; /* caller will probably crash: no choice here */\n      }\n   }\n\n   /* Finally fill in the function, now we have a satisfactory buffer. It is\n    * valid to change the function on every call.\n    */\n   png_ptr->longjmp_fn = longjmp_fn;\n   return png_ptr->jmp_buf_ptr;\n}\n\nvoid /* PRIVATE */\npng_free_jmpbuf(png_structrp png_ptr)\n{\n   if (png_ptr != NULL)\n   {\n      jmp_buf *jb = png_ptr->jmp_buf_ptr;\n\n      /* A size of 0 is used to indicate a local, stack, allocation of the\n       * pointer; used here and in png.c\n       */\n      if (jb != NULL && png_ptr->jmp_buf_size > 0)\n      {\n\n         /* This stuff is so that a failure to free the error control structure\n          * does not leave libpng in a state with no valid error handling: the\n          * free always succeeds, if there is an error it gets ignored.\n          */\n         if (jb != &png_ptr->jmp_buf_local)\n         {\n            /* Make an internal, libpng, jmp_buf to return here */\n            jmp_buf free_jmp_buf;\n\n            if (!setjmp(free_jmp_buf))\n            {\n               png_ptr->jmp_buf_ptr = &free_jmp_buf; /* come back here */\n               png_ptr->jmp_buf_size = 0; /* stack allocation */\n               png_ptr->longjmp_fn = longjmp;\n               png_free(png_ptr, jb); /* Return to setjmp on error */\n            }\n         }\n      }\n\n      /* *Always* cancel everything out: */\n      png_ptr->jmp_buf_size = 0;\n      png_ptr->jmp_buf_ptr = NULL;\n      png_ptr->longjmp_fn = 0;\n   }\n}\n#endif\n\n/* This is the default error handling function.  Note that replacements for\n * this function MUST NOT RETURN, or the program will likely crash.  This\n * function is used by default, or if the program supplies NULL for the\n * error function pointer in png_set_error_fn().\n */\nstatic PNG_FUNCTION(void /* PRIVATE */,\npng_default_error,(png_const_structrp png_ptr, png_const_charp error_message),\n    PNG_NORETURN)\n{\n#ifdef PNG_CONSOLE_IO_SUPPORTED\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\n   /* Check on NULL only added in 1.5.4 */\n   if (error_message != NULL && *error_message == PNG_LITERAL_SHARP)\n   {\n      /* Strip \"#nnnn \" from beginning of error message. */\n      int offset;\n      char error_number[16];\n      for (offset = 0; offset<15; offset++)\n      {\n         error_number[offset] = error_message[offset + 1];\n         if (error_message[offset] == ' ')\n            break;\n      }\n\n      if ((offset > 1) && (offset < 15))\n      {\n         error_number[offset - 1] = '\\0';\n         fprintf(stderr, \"libpng error no. %s: %s\",\n             error_number, error_message + offset + 1);\n         fprintf(stderr, PNG_STRING_NEWLINE);\n      }\n\n      else\n      {\n         fprintf(stderr, \"libpng error: %s, offset=%d\",\n             error_message, offset);\n         fprintf(stderr, PNG_STRING_NEWLINE);\n      }\n   }\n   else\n#endif\n   {\n      fprintf(stderr, \"libpng error: %s\", error_message ? error_message :\n         \"undefined\");\n      fprintf(stderr, PNG_STRING_NEWLINE);\n   }\n#else\n   PNG_UNUSED(error_message) /* Make compiler happy */\n#endif\n   png_longjmp(png_ptr, 1);\n}\n\nPNG_FUNCTION(void,PNGAPI\npng_longjmp,(png_const_structrp png_ptr, int val),PNG_NORETURN)\n{\n#ifdef PNG_SETJMP_SUPPORTED\n   if (png_ptr != NULL && png_ptr->longjmp_fn != NULL &&\n       png_ptr->jmp_buf_ptr != NULL)\n      png_ptr->longjmp_fn(*png_ptr->jmp_buf_ptr, val);\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(val)\n#endif\n\n   /* If control reaches this point, png_longjmp() must not return. The only\n    * choice is to terminate the whole process (or maybe the thread); to do\n    * this the ANSI-C abort() function is used unless a different method is\n    * implemented by overriding the default configuration setting for\n    * PNG_ABORT().\n    */\n   PNG_ABORT();\n}\n\n#ifdef PNG_WARNINGS_SUPPORTED\n/* This function is called when there is a warning, but the library thinks\n * it can continue anyway.  Replacement functions don't have to do anything\n * here if you don't want them to.  In the default configuration, png_ptr is\n * not used, but it is passed in case it may be useful.\n */\nstatic void /* PRIVATE */\npng_default_warning(png_const_structrp png_ptr, png_const_charp warning_message)\n{\n#ifdef PNG_CONSOLE_IO_SUPPORTED\n#  ifdef PNG_ERROR_NUMBERS_SUPPORTED\n   if (*warning_message == PNG_LITERAL_SHARP)\n   {\n      int offset;\n      char warning_number[16];\n      for (offset = 0; offset < 15; offset++)\n      {\n         warning_number[offset] = warning_message[offset + 1];\n         if (warning_message[offset] == ' ')\n            break;\n      }\n\n      if ((offset > 1) && (offset < 15))\n      {\n         warning_number[offset + 1] = '\\0';\n         fprintf(stderr, \"libpng warning no. %s: %s\",\n             warning_number, warning_message + offset);\n         fprintf(stderr, PNG_STRING_NEWLINE);\n      }\n\n      else\n      {\n         fprintf(stderr, \"libpng warning: %s\",\n             warning_message);\n         fprintf(stderr, PNG_STRING_NEWLINE);\n      }\n   }\n   else\n#  endif\n\n   {\n      fprintf(stderr, \"libpng warning: %s\", warning_message);\n      fprintf(stderr, PNG_STRING_NEWLINE);\n   }\n#else\n   PNG_UNUSED(warning_message) /* Make compiler happy */\n#endif\n   PNG_UNUSED(png_ptr) /* Make compiler happy */\n}\n#endif /* WARNINGS */\n\n/* This function is called when the application wants to use another method\n * of handling errors and warnings.  Note that the error function MUST NOT\n * return to the calling routine or serious problems will occur.  The return\n * method used in the default routine calls longjmp(png_ptr->jmp_buf_ptr, 1)\n */\nvoid PNGAPI\npng_set_error_fn(png_structrp png_ptr, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warning_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->error_ptr = error_ptr;\n   png_ptr->error_fn = error_fn;\n#ifdef PNG_WARNINGS_SUPPORTED\n   png_ptr->warning_fn = warning_fn;\n#else\n   PNG_UNUSED(warning_fn)\n#endif\n}\n\n\n/* This function returns a pointer to the error_ptr associated with the user\n * functions.  The application should free any memory associated with this\n * pointer before png_write_destroy and png_read_destroy are called.\n */\npng_voidp PNGAPI\npng_get_error_ptr(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return NULL;\n\n   return ((png_voidp)png_ptr->error_ptr);\n}\n\n\n#ifdef PNG_ERROR_NUMBERS_SUPPORTED\nvoid PNGAPI\npng_set_strip_error_numbers(png_structrp png_ptr, png_uint_32 strip_mode)\n{\n   if (png_ptr != NULL)\n   {\n      png_ptr->flags &=\n         ((~(PNG_FLAG_STRIP_ERROR_NUMBERS |\n         PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);\n   }\n}\n#endif\n\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\\\n   defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n   /* Currently the above both depend on SETJMP_SUPPORTED, however it would be\n    * possible to implement without setjmp support just so long as there is some\n    * way to handle the error return here:\n    */\nPNG_FUNCTION(void /* PRIVATE */, (PNGCBAPI\npng_safe_error),(png_structp png_nonconst_ptr, png_const_charp error_message),\n    PNG_NORETURN)\n{\n   const png_const_structrp png_ptr = png_nonconst_ptr;\n   png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);\n\n   /* An error is always logged here, overwriting anything (typically a warning)\n    * that is already there:\n    */\n   if (image != NULL)\n   {\n      png_safecat(image->message, (sizeof image->message), 0, error_message);\n      image->warning_or_error |= PNG_IMAGE_ERROR;\n\n      /* Retrieve the jmp_buf from within the png_control, making this work for\n       * C++ compilation too is pretty tricky: C++ wants a pointer to the first\n       * element of a jmp_buf, but C doesn't tell us the type of that.\n       */\n      if (image->opaque != NULL && image->opaque->error_buf != NULL)\n         longjmp(png_control_jmp_buf(image->opaque), 1);\n\n      /* Missing longjmp buffer, the following is to help debugging: */\n      {\n         size_t pos = png_safecat(image->message, (sizeof image->message), 0,\n             \"bad longjmp: \");\n         png_safecat(image->message, (sizeof image->message), pos,\n             error_message);\n      }\n   }\n\n   /* Here on an internal programming error. */\n   abort();\n}\n\n#ifdef PNG_WARNINGS_SUPPORTED\nvoid /* PRIVATE */ PNGCBAPI\npng_safe_warning(png_structp png_nonconst_ptr, png_const_charp warning_message)\n{\n   const png_const_structrp png_ptr = png_nonconst_ptr;\n   png_imagep image = png_voidcast(png_imagep, png_ptr->error_ptr);\n\n   /* A warning is only logged if there is no prior warning or error. */\n   if (image->warning_or_error == 0)\n   {\n      png_safecat(image->message, (sizeof image->message), 0, warning_message);\n      image->warning_or_error |= PNG_IMAGE_WARNING;\n   }\n}\n#endif\n\nint /* PRIVATE */\npng_safe_execute(png_imagep image_in, int (*function)(png_voidp), png_voidp arg)\n{\n   volatile png_imagep image = image_in;\n   volatile int result;\n   volatile png_voidp saved_error_buf;\n   jmp_buf safe_jmpbuf;\n\n   /* Safely execute function(arg) with png_error returning to this function. */\n   saved_error_buf = image->opaque->error_buf;\n   result = setjmp(safe_jmpbuf) == 0;\n\n   if (result != 0)\n   {\n\n      image->opaque->error_buf = safe_jmpbuf;\n      result = function(arg);\n   }\n\n   image->opaque->error_buf = saved_error_buf;\n\n   /* And do the cleanup prior to any failure return. */\n   if (result == 0)\n      png_image_free(image);\n\n   return result;\n}\n#endif /* SIMPLIFIED READ || SIMPLIFIED_WRITE */\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngget.c",
    "content": "\n/* pngget.c - retrieval of values from info struct\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n */\n\n#include \"pngpriv.h\"\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n\npng_uint_32 PNGAPI\npng_get_valid(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_uint_32 flag)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return(info_ptr->valid & flag);\n\n   return(0);\n}\n\npng_size_t PNGAPI\npng_get_rowbytes(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return(info_ptr->rowbytes);\n\n   return(0);\n}\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\npng_bytepp PNGAPI\npng_get_rows(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return(info_ptr->row_pointers);\n\n   return(0);\n}\n#endif\n\n#ifdef PNG_EASY_ACCESS_SUPPORTED\n/* Easy access to info, added in libpng-0.99 */\npng_uint_32 PNGAPI\npng_get_image_width(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->width;\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_image_height(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->height;\n\n   return (0);\n}\n\npng_byte PNGAPI\npng_get_bit_depth(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->bit_depth;\n\n   return (0);\n}\n\npng_byte PNGAPI\npng_get_color_type(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->color_type;\n\n   return (0);\n}\n\npng_byte PNGAPI\npng_get_filter_type(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->filter_type;\n\n   return (0);\n}\n\npng_byte PNGAPI\npng_get_interlace_type(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->interlace_type;\n\n   return (0);\n}\n\npng_byte PNGAPI\npng_get_compression_type(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return info_ptr->compression_type;\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_x_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp\n   info_ptr)\n{\n#ifdef PNG_pHYs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n      {\n         png_debug1(1, \"in %s retrieval function\",\n             \"png_get_x_pixels_per_meter\");\n\n         if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)\n            return (info_ptr->x_pixels_per_unit);\n      }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_y_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp\n    info_ptr)\n{\n#ifdef PNG_pHYs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\",\n          \"png_get_y_pixels_per_meter\");\n\n      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER)\n         return (info_ptr->y_pixels_per_unit);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_pixels_per_meter(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n#ifdef PNG_pHYs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_pixels_per_meter\");\n\n      if (info_ptr->phys_unit_type == PNG_RESOLUTION_METER &&\n          info_ptr->x_pixels_per_unit == info_ptr->y_pixels_per_unit)\n         return (info_ptr->x_pixels_per_unit);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nfloat PNGAPI\npng_get_pixel_aspect_ratio(png_const_structrp png_ptr, png_const_inforp\n   info_ptr)\n{\n#ifdef PNG_READ_pHYs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_aspect_ratio\");\n\n      if (info_ptr->x_pixels_per_unit != 0)\n         return ((float)((float)info_ptr->y_pixels_per_unit\n             /(float)info_ptr->x_pixels_per_unit));\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return ((float)0.0);\n}\n#endif\n\n#ifdef PNG_FIXED_POINT_SUPPORTED\npng_fixed_point PNGAPI\npng_get_pixel_aspect_ratio_fixed(png_const_structrp png_ptr,\n    png_const_inforp info_ptr)\n{\n#ifdef PNG_READ_pHYs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0 &&\n       info_ptr->x_pixels_per_unit > 0 && info_ptr->y_pixels_per_unit > 0 &&\n       info_ptr->x_pixels_per_unit <= PNG_UINT_31_MAX &&\n       info_ptr->y_pixels_per_unit <= PNG_UINT_31_MAX)\n   {\n      png_fixed_point res;\n\n      png_debug1(1, \"in %s retrieval function\", \"png_get_aspect_ratio_fixed\");\n\n      /* The following casts work because a PNG 4 byte integer only has a valid\n       * range of 0..2^31-1; otherwise the cast might overflow.\n       */\n      if (png_muldiv(&res, (png_int_32)info_ptr->y_pixels_per_unit, PNG_FP_1,\n          (png_int_32)info_ptr->x_pixels_per_unit) != 0)\n         return res;\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return 0;\n}\n#endif\n\npng_int_32 PNGAPI\npng_get_x_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n#ifdef PNG_oFFs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_oFFs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_x_offset_microns\");\n\n      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)\n         return (info_ptr->x_offset);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\npng_int_32 PNGAPI\npng_get_y_offset_microns(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n#ifdef PNG_oFFs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_oFFs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_y_offset_microns\");\n\n      if (info_ptr->offset_unit_type == PNG_OFFSET_MICROMETER)\n         return (info_ptr->y_offset);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\npng_int_32 PNGAPI\npng_get_x_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n#ifdef PNG_oFFs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_oFFs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_x_offset_pixels\");\n\n      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)\n         return (info_ptr->x_offset);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\npng_int_32 PNGAPI\npng_get_y_offset_pixels(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n#ifdef PNG_oFFs_SUPPORTED\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_oFFs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"png_get_y_offset_pixels\");\n\n      if (info_ptr->offset_unit_type == PNG_OFFSET_PIXEL)\n         return (info_ptr->y_offset);\n   }\n#else\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(info_ptr)\n#endif\n\n   return (0);\n}\n\n#ifdef PNG_INCH_CONVERSIONS_SUPPORTED\nstatic png_uint_32\nppi_from_ppm(png_uint_32 ppm)\n{\n#if 0\n   /* The conversion is *(2.54/100), in binary (32 digits):\n    * .00000110100000001001110101001001\n    */\n   png_uint_32 t1001, t1101;\n   ppm >>= 1;                  /* .1 */\n   t1001 = ppm + (ppm >> 3);   /* .1001 */\n   t1101 = t1001 + (ppm >> 1); /* .1101 */\n   ppm >>= 20;                 /* .000000000000000000001 */\n   t1101 += t1101 >> 15;       /* .1101000000000001101 */\n   t1001 >>= 11;               /* .000000000001001 */\n   t1001 += t1001 >> 12;       /* .000000000001001000000001001 */\n   ppm += t1001;               /* .000000000001001000001001001 */\n   ppm += t1101;               /* .110100000001001110101001001 */\n   return (ppm + 16) >> 5;/* .00000110100000001001110101001001 */\n#else\n   /* The argument is a PNG unsigned integer, so it is not permitted\n    * to be bigger than 2^31.\n    */\n   png_fixed_point result;\n   if (ppm <= PNG_UINT_31_MAX && png_muldiv(&result, (png_int_32)ppm, 127,\n       5000) != 0)\n      return result;\n\n   /* Overflow. */\n   return 0;\n#endif\n}\n\npng_uint_32 PNGAPI\npng_get_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   return ppi_from_ppm(png_get_pixels_per_meter(png_ptr, info_ptr));\n}\n\npng_uint_32 PNGAPI\npng_get_x_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   return ppi_from_ppm(png_get_x_pixels_per_meter(png_ptr, info_ptr));\n}\n\npng_uint_32 PNGAPI\npng_get_y_pixels_per_inch(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   return ppi_from_ppm(png_get_y_pixels_per_meter(png_ptr, info_ptr));\n}\n\n#ifdef PNG_FIXED_POINT_SUPPORTED\nstatic png_fixed_point\npng_fixed_inches_from_microns(png_const_structrp png_ptr, png_int_32 microns)\n{\n   /* Convert from metres * 1,000,000 to inches * 100,000, meters to\n    * inches is simply *(100/2.54), so we want *(10/2.54) == 500/127.\n    * Notice that this can overflow - a warning is output and 0 is\n    * returned.\n    */\n   return png_muldiv_warn(png_ptr, microns, 500, 127);\n}\n\npng_fixed_point PNGAPI\npng_get_x_offset_inches_fixed(png_const_structrp png_ptr,\n    png_const_inforp info_ptr)\n{\n   return png_fixed_inches_from_microns(png_ptr,\n       png_get_x_offset_microns(png_ptr, info_ptr));\n}\n#endif\n\n#ifdef PNG_FIXED_POINT_SUPPORTED\npng_fixed_point PNGAPI\npng_get_y_offset_inches_fixed(png_const_structrp png_ptr,\n    png_const_inforp info_ptr)\n{\n   return png_fixed_inches_from_microns(png_ptr,\n       png_get_y_offset_microns(png_ptr, info_ptr));\n}\n#endif\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nfloat PNGAPI\npng_get_x_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   /* To avoid the overflow do the conversion directly in floating\n    * point.\n    */\n   return (float)(png_get_x_offset_microns(png_ptr, info_ptr) * .00003937);\n}\n#endif\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nfloat PNGAPI\npng_get_y_offset_inches(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   /* To avoid the overflow do the conversion directly in floating\n    * point.\n    */\n   return (float)(png_get_y_offset_microns(png_ptr, info_ptr) * .00003937);\n}\n#endif\n\n#ifdef PNG_pHYs_SUPPORTED\npng_uint_32 PNGAPI\npng_get_pHYs_dpi(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)\n{\n   png_uint_32 retval = 0;\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"pHYs\");\n\n      if (res_x != NULL)\n      {\n         *res_x = info_ptr->x_pixels_per_unit;\n         retval |= PNG_INFO_pHYs;\n      }\n\n      if (res_y != NULL)\n      {\n         *res_y = info_ptr->y_pixels_per_unit;\n         retval |= PNG_INFO_pHYs;\n      }\n\n      if (unit_type != NULL)\n      {\n         *unit_type = (int)info_ptr->phys_unit_type;\n         retval |= PNG_INFO_pHYs;\n\n         if (*unit_type == 1)\n         {\n            if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);\n            if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);\n         }\n      }\n   }\n\n   return (retval);\n}\n#endif /* pHYs */\n#endif /* INCH_CONVERSIONS */\n\n/* png_get_channels really belongs in here, too, but it's been around longer */\n\n#endif /* EASY_ACCESS */\n\n\npng_byte PNGAPI\npng_get_channels(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return(info_ptr->channels);\n\n   return (0);\n}\n\n#ifdef PNG_READ_SUPPORTED\npng_const_bytep PNGAPI\npng_get_signature(png_const_structrp png_ptr, png_const_inforp info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return(info_ptr->signature);\n\n   return (NULL);\n}\n#endif\n\n#ifdef PNG_bKGD_SUPPORTED\npng_uint_32 PNGAPI\npng_get_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_color_16p *background)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_bKGD) != 0 &&\n       background != NULL)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"bKGD\");\n\n      *background = &(info_ptr->background);\n      return (PNG_INFO_bKGD);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_cHRM_SUPPORTED\n/* The XYZ APIs were added in 1.5.5 to take advantage of the code added at the\n * same time to correct the rgb grayscale coefficient defaults obtained from the\n * cHRM chunk in 1.5.4\n */\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_cHRM(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    double *white_x, double *white_y, double *red_x, double *red_y,\n    double *green_x, double *green_y, double *blue_x, double *blue_y)\n{\n   /* Quiet API change: this code used to only return the end points if a cHRM\n    * chunk was present, but the end points can also come from iCCP or sRGB\n    * chunks, so in 1.6.0 the png_get_ APIs return the end points regardless and\n    * the png_set_ APIs merely check that set end points are mutually\n    * consistent.\n    */\n   if (png_ptr != NULL && info_ptr != NULL &&\n      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"cHRM\");\n\n      if (white_x != NULL)\n         *white_x = png_float(png_ptr,\n             info_ptr->colorspace.end_points_xy.whitex, \"cHRM white X\");\n      if (white_y != NULL)\n         *white_y = png_float(png_ptr,\n             info_ptr->colorspace.end_points_xy.whitey, \"cHRM white Y\");\n      if (red_x != NULL)\n         *red_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redx,\n             \"cHRM red X\");\n      if (red_y != NULL)\n         *red_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.redy,\n             \"cHRM red Y\");\n      if (green_x != NULL)\n         *green_x = png_float(png_ptr,\n             info_ptr->colorspace.end_points_xy.greenx, \"cHRM green X\");\n      if (green_y != NULL)\n         *green_y = png_float(png_ptr,\n             info_ptr->colorspace.end_points_xy.greeny, \"cHRM green Y\");\n      if (blue_x != NULL)\n         *blue_x = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluex,\n             \"cHRM blue X\");\n      if (blue_y != NULL)\n         *blue_y = png_float(png_ptr, info_ptr->colorspace.end_points_xy.bluey,\n             \"cHRM blue Y\");\n      return (PNG_INFO_cHRM);\n   }\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_cHRM_XYZ(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    double *red_X, double *red_Y, double *red_Z, double *green_X,\n    double *green_Y, double *green_Z, double *blue_X, double *blue_Y,\n    double *blue_Z)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"cHRM_XYZ(float)\");\n\n      if (red_X != NULL)\n         *red_X = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_X,\n             \"cHRM red X\");\n      if (red_Y != NULL)\n         *red_Y = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Y,\n             \"cHRM red Y\");\n      if (red_Z != NULL)\n         *red_Z = png_float(png_ptr, info_ptr->colorspace.end_points_XYZ.red_Z,\n             \"cHRM red Z\");\n      if (green_X != NULL)\n         *green_X = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.green_X, \"cHRM green X\");\n      if (green_Y != NULL)\n         *green_Y = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.green_Y, \"cHRM green Y\");\n      if (green_Z != NULL)\n         *green_Z = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.green_Z, \"cHRM green Z\");\n      if (blue_X != NULL)\n         *blue_X = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.blue_X, \"cHRM blue X\");\n      if (blue_Y != NULL)\n         *blue_Y = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.blue_Y, \"cHRM blue Y\");\n      if (blue_Z != NULL)\n         *blue_Z = png_float(png_ptr,\n             info_ptr->colorspace.end_points_XYZ.blue_Z, \"cHRM blue Z\");\n      return (PNG_INFO_cHRM);\n   }\n\n   return (0);\n}\n#  endif\n\n#  ifdef PNG_FIXED_POINT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *int_red_X, png_fixed_point *int_red_Y,\n    png_fixed_point *int_red_Z, png_fixed_point *int_green_X,\n    png_fixed_point *int_green_Y, png_fixed_point *int_green_Z,\n    png_fixed_point *int_blue_X, png_fixed_point *int_blue_Y,\n    png_fixed_point *int_blue_Z)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"cHRM_XYZ\");\n\n      if (int_red_X != NULL)\n         *int_red_X = info_ptr->colorspace.end_points_XYZ.red_X;\n      if (int_red_Y != NULL)\n         *int_red_Y = info_ptr->colorspace.end_points_XYZ.red_Y;\n      if (int_red_Z != NULL)\n         *int_red_Z = info_ptr->colorspace.end_points_XYZ.red_Z;\n      if (int_green_X != NULL)\n         *int_green_X = info_ptr->colorspace.end_points_XYZ.green_X;\n      if (int_green_Y != NULL)\n         *int_green_Y = info_ptr->colorspace.end_points_XYZ.green_Y;\n      if (int_green_Z != NULL)\n         *int_green_Z = info_ptr->colorspace.end_points_XYZ.green_Z;\n      if (int_blue_X != NULL)\n         *int_blue_X = info_ptr->colorspace.end_points_XYZ.blue_X;\n      if (int_blue_Y != NULL)\n         *int_blue_Y = info_ptr->colorspace.end_points_XYZ.blue_Y;\n      if (int_blue_Z != NULL)\n         *int_blue_Z = info_ptr->colorspace.end_points_XYZ.blue_Z;\n      return (PNG_INFO_cHRM);\n   }\n\n   return (0);\n}\n\npng_uint_32 PNGAPI\npng_get_cHRM_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,\n    png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,\n    png_fixed_point *blue_x, png_fixed_point *blue_y)\n{\n   png_debug1(1, \"in %s retrieval function\", \"cHRM\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_ENDPOINTS) != 0)\n   {\n      if (white_x != NULL)\n         *white_x = info_ptr->colorspace.end_points_xy.whitex;\n      if (white_y != NULL)\n         *white_y = info_ptr->colorspace.end_points_xy.whitey;\n      if (red_x != NULL)\n         *red_x = info_ptr->colorspace.end_points_xy.redx;\n      if (red_y != NULL)\n         *red_y = info_ptr->colorspace.end_points_xy.redy;\n      if (green_x != NULL)\n         *green_x = info_ptr->colorspace.end_points_xy.greenx;\n      if (green_y != NULL)\n         *green_y = info_ptr->colorspace.end_points_xy.greeny;\n      if (blue_x != NULL)\n         *blue_x = info_ptr->colorspace.end_points_xy.bluex;\n      if (blue_y != NULL)\n         *blue_y = info_ptr->colorspace.end_points_xy.bluey;\n      return (PNG_INFO_cHRM);\n   }\n\n   return (0);\n}\n#  endif\n#endif\n\n#ifdef PNG_gAMA_SUPPORTED\n#  ifdef PNG_FIXED_POINT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_gAMA_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_fixed_point *file_gamma)\n{\n   png_debug1(1, \"in %s retrieval function\", \"gAMA\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&\n       file_gamma != NULL)\n   {\n      *file_gamma = info_ptr->colorspace.gamma;\n      return (PNG_INFO_gAMA);\n   }\n\n   return (0);\n}\n#  endif\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_gAMA(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    double *file_gamma)\n{\n   png_debug1(1, \"in %s retrieval function\", \"gAMA(float)\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n      (info_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) != 0 &&\n      file_gamma != NULL)\n   {\n      *file_gamma = png_float(png_ptr, info_ptr->colorspace.gamma,\n          \"png_get_gAMA\");\n      return (PNG_INFO_gAMA);\n   }\n\n   return (0);\n}\n#  endif\n#endif\n\n#ifdef PNG_sRGB_SUPPORTED\npng_uint_32 PNGAPI\npng_get_sRGB(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    int *file_srgb_intent)\n{\n   png_debug1(1, \"in %s retrieval function\", \"sRGB\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n      (info_ptr->valid & PNG_INFO_sRGB) != 0 && file_srgb_intent != NULL)\n   {\n      *file_srgb_intent = info_ptr->colorspace.rendering_intent;\n      return (PNG_INFO_sRGB);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_iCCP_SUPPORTED\npng_uint_32 PNGAPI\npng_get_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_charpp name, int *compression_type,\n    png_bytepp profile, png_uint_32 *proflen)\n{\n   png_debug1(1, \"in %s retrieval function\", \"iCCP\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_iCCP) != 0 &&\n       name != NULL && compression_type != NULL && profile != NULL &&\n           proflen != NULL)\n   {\n      *name = info_ptr->iccp_name;\n      *profile = info_ptr->iccp_profile;\n      *proflen = png_get_uint_32(info_ptr->iccp_profile);\n      /* This is somewhat irrelevant since the profile data returned has\n       * actually been uncompressed.\n       */\n      *compression_type = PNG_COMPRESSION_TYPE_BASE;\n      return (PNG_INFO_iCCP);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\nint PNGAPI\npng_get_sPLT(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_sPLT_tpp spalettes)\n{\n   if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)\n   {\n      *spalettes = info_ptr->splt_palettes;\n      return info_ptr->splt_palettes_num;\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\npng_uint_32 PNGAPI\npng_get_hIST(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_uint_16p *hist)\n{\n   png_debug1(1, \"in %s retrieval function\", \"hIST\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_hIST) != 0 && hist != NULL)\n   {\n      *hist = info_ptr->hist;\n      return (PNG_INFO_hIST);\n   }\n\n   return (0);\n}\n#endif\n\npng_uint_32 PNGAPI\npng_get_IHDR(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_uint_32 *width, png_uint_32 *height, int *bit_depth,\n    int *color_type, int *interlace_type, int *compression_type,\n    int *filter_type)\n{\n   png_debug1(1, \"in %s retrieval function\", \"IHDR\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return (0);\n\n   if (width != NULL)\n       *width = info_ptr->width;\n\n   if (height != NULL)\n       *height = info_ptr->height;\n\n   if (bit_depth != NULL)\n       *bit_depth = info_ptr->bit_depth;\n\n   if (color_type != NULL)\n       *color_type = info_ptr->color_type;\n\n   if (compression_type != NULL)\n      *compression_type = info_ptr->compression_type;\n\n   if (filter_type != NULL)\n      *filter_type = info_ptr->filter_type;\n\n   if (interlace_type != NULL)\n      *interlace_type = info_ptr->interlace_type;\n\n   /* This is redundant if we can be sure that the info_ptr values were all\n    * assigned in png_set_IHDR().  We do the check anyhow in case an\n    * application has ignored our advice not to mess with the members\n    * of info_ptr directly.\n    */\n   png_check_IHDR(png_ptr, info_ptr->width, info_ptr->height,\n       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,\n       info_ptr->compression_type, info_ptr->filter_type);\n\n   return (1);\n}\n\n#ifdef PNG_oFFs_SUPPORTED\npng_uint_32 PNGAPI\npng_get_oFFs(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)\n{\n   png_debug1(1, \"in %s retrieval function\", \"oFFs\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_oFFs) != 0 &&\n       offset_x != NULL && offset_y != NULL && unit_type != NULL)\n   {\n      *offset_x = info_ptr->x_offset;\n      *offset_y = info_ptr->y_offset;\n      *unit_type = (int)info_ptr->offset_unit_type;\n      return (PNG_INFO_oFFs);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\npng_uint_32 PNGAPI\npng_get_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,\n    png_charp *units, png_charpp *params)\n{\n   png_debug1(1, \"in %s retrieval function\", \"pCAL\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pCAL) != 0 &&\n       purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&\n       nparams != NULL && units != NULL && params != NULL)\n   {\n      *purpose = info_ptr->pcal_purpose;\n      *X0 = info_ptr->pcal_X0;\n      *X1 = info_ptr->pcal_X1;\n      *type = (int)info_ptr->pcal_type;\n      *nparams = (int)info_ptr->pcal_nparams;\n      *units = info_ptr->pcal_units;\n      *params = info_ptr->pcal_params;\n      return (PNG_INFO_pCAL);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_sCAL_SUPPORTED\n#  ifdef PNG_FIXED_POINT_SUPPORTED\n#    if defined(PNG_FLOATING_ARITHMETIC_SUPPORTED) || \\\n         defined(PNG_FLOATING_POINT_SUPPORTED)\npng_uint_32 PNGAPI\npng_get_sCAL_fixed(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    int *unit, png_fixed_point *width, png_fixed_point *height)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_sCAL) != 0)\n   {\n      *unit = info_ptr->scal_unit;\n      /*TODO: make this work without FP support; the API is currently eliminated\n       * if neither floating point APIs nor internal floating point arithmetic\n       * are enabled.\n       */\n      *width = png_fixed(png_ptr, atof(info_ptr->scal_s_width), \"sCAL width\");\n      *height = png_fixed(png_ptr, atof(info_ptr->scal_s_height),\n          \"sCAL height\");\n      return (PNG_INFO_sCAL);\n   }\n\n   return(0);\n}\n#    endif /* FLOATING_ARITHMETIC */\n#  endif /* FIXED_POINT */\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_sCAL(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    int *unit, double *width, double *height)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_sCAL) != 0)\n   {\n      *unit = info_ptr->scal_unit;\n      *width = atof(info_ptr->scal_s_width);\n      *height = atof(info_ptr->scal_s_height);\n      return (PNG_INFO_sCAL);\n   }\n\n   return(0);\n}\n#  endif /* FLOATING POINT */\npng_uint_32 PNGAPI\npng_get_sCAL_s(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    int *unit, png_charpp width, png_charpp height)\n{\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_sCAL) != 0)\n   {\n      *unit = info_ptr->scal_unit;\n      *width = info_ptr->scal_s_width;\n      *height = info_ptr->scal_s_height;\n      return (PNG_INFO_sCAL);\n   }\n\n   return(0);\n}\n#endif /* sCAL */\n\n#ifdef PNG_pHYs_SUPPORTED\npng_uint_32 PNGAPI\npng_get_pHYs(png_const_structrp png_ptr, png_const_inforp info_ptr,\n    png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)\n{\n   png_uint_32 retval = 0;\n\n   png_debug1(1, \"in %s retrieval function\", \"pHYs\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      if (res_x != NULL)\n      {\n         *res_x = info_ptr->x_pixels_per_unit;\n         retval |= PNG_INFO_pHYs;\n      }\n\n      if (res_y != NULL)\n      {\n         *res_y = info_ptr->y_pixels_per_unit;\n         retval |= PNG_INFO_pHYs;\n      }\n\n      if (unit_type != NULL)\n      {\n         *unit_type = (int)info_ptr->phys_unit_type;\n         retval |= PNG_INFO_pHYs;\n      }\n   }\n\n   return (retval);\n}\n#endif /* pHYs */\n\npng_uint_32 PNGAPI\npng_get_PLTE(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_colorp *palette, int *num_palette)\n{\n   png_debug1(1, \"in %s retrieval function\", \"PLTE\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_PLTE) != 0 && palette != NULL)\n   {\n      *palette = info_ptr->palette;\n      *num_palette = info_ptr->num_palette;\n      png_debug1(3, \"num_palette = %d\", *num_palette);\n      return (PNG_INFO_PLTE);\n   }\n\n   return (0);\n}\n\n#ifdef PNG_sBIT_SUPPORTED\npng_uint_32 PNGAPI\npng_get_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_color_8p *sig_bit)\n{\n   png_debug1(1, \"in %s retrieval function\", \"sBIT\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_sBIT) != 0 && sig_bit != NULL)\n   {\n      *sig_bit = &(info_ptr->sig_bit);\n      return (PNG_INFO_sBIT);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED\nint PNGAPI\npng_get_text(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_textp *text_ptr, int *num_text)\n{\n   if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)\n   {\n      png_debug1(1, \"in 0x%lx retrieval function\",\n         (unsigned long)png_ptr->chunk_name);\n\n      if (text_ptr != NULL)\n         *text_ptr = info_ptr->text;\n\n      if (num_text != NULL)\n         *num_text = info_ptr->num_text;\n\n      return info_ptr->num_text;\n   }\n\n   if (num_text != NULL)\n      *num_text = 0;\n\n   return(0);\n}\n#endif\n\n#ifdef PNG_tIME_SUPPORTED\npng_uint_32 PNGAPI\npng_get_tIME(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_timep *mod_time)\n{\n   png_debug1(1, \"in %s retrieval function\", \"tIME\");\n\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_tIME) != 0 && mod_time != NULL)\n   {\n      *mod_time = &(info_ptr->mod_time);\n      return (PNG_INFO_tIME);\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_tRNS_SUPPORTED\npng_uint_32 PNGAPI\npng_get_tRNS(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_bytep *trans_alpha, int *num_trans, png_color_16p *trans_color)\n{\n   png_uint_32 retval = 0;\n   if (png_ptr != NULL && info_ptr != NULL &&\n       (info_ptr->valid & PNG_INFO_tRNS) != 0)\n   {\n      png_debug1(1, \"in %s retrieval function\", \"tRNS\");\n\n      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         if (trans_alpha != NULL)\n         {\n            *trans_alpha = info_ptr->trans_alpha;\n            retval |= PNG_INFO_tRNS;\n         }\n\n         if (trans_color != NULL)\n            *trans_color = &(info_ptr->trans_color);\n      }\n\n      else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */\n      {\n         if (trans_color != NULL)\n         {\n            *trans_color = &(info_ptr->trans_color);\n            retval |= PNG_INFO_tRNS;\n         }\n\n         if (trans_alpha != NULL)\n            *trans_alpha = NULL;\n      }\n\n      if (num_trans != NULL)\n      {\n         *num_trans = info_ptr->num_trans;\n         retval |= PNG_INFO_tRNS;\n      }\n   }\n\n   return (retval);\n}\n#endif\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\nint PNGAPI\npng_get_unknown_chunks(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_unknown_chunkpp unknowns)\n{\n   if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)\n   {\n      *unknowns = info_ptr->unknown_chunks;\n      return info_ptr->unknown_chunks_num;\n   }\n\n   return (0);\n}\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\npng_byte PNGAPI\npng_get_rgb_to_gray_status (png_const_structrp png_ptr)\n{\n   return (png_byte)(png_ptr ? png_ptr->rgb_to_gray_status : 0);\n}\n#endif\n\n#ifdef PNG_USER_CHUNKS_SUPPORTED\npng_voidp PNGAPI\npng_get_user_chunk_ptr(png_const_structrp png_ptr)\n{\n   return (png_ptr ? png_ptr->user_chunk_ptr : NULL);\n}\n#endif\n\npng_size_t PNGAPI\npng_get_compression_buffer_size(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return 0;\n\n#ifdef PNG_WRITE_SUPPORTED\n   if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\n#endif\n   {\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n      return png_ptr->IDAT_read_size;\n#else\n      return PNG_IDAT_READ_SIZE;\n#endif\n   }\n\n#ifdef PNG_WRITE_SUPPORTED\n   else\n      return png_ptr->zbuffer_size;\n#endif\n}\n\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\n/* These functions were added to libpng 1.2.6 and were enabled\n * by default in libpng-1.4.0 */\npng_uint_32 PNGAPI\npng_get_user_width_max (png_const_structrp png_ptr)\n{\n   return (png_ptr ? png_ptr->user_width_max : 0);\n}\n\npng_uint_32 PNGAPI\npng_get_user_height_max (png_const_structrp png_ptr)\n{\n   return (png_ptr ? png_ptr->user_height_max : 0);\n}\n\n/* This function was added to libpng 1.4.0 */\npng_uint_32 PNGAPI\npng_get_chunk_cache_max (png_const_structrp png_ptr)\n{\n   return (png_ptr ? png_ptr->user_chunk_cache_max : 0);\n}\n\n/* This function was added to libpng 1.4.1 */\npng_alloc_size_t PNGAPI\npng_get_chunk_malloc_max (png_const_structrp png_ptr)\n{\n   return (png_ptr ? png_ptr->user_chunk_malloc_max : 0);\n}\n#endif /* SET_USER_LIMITS */\n\n/* These functions were added to libpng 1.4.0 */\n#ifdef PNG_IO_STATE_SUPPORTED\npng_uint_32 PNGAPI\npng_get_io_state (png_const_structrp png_ptr)\n{\n   return png_ptr->io_state;\n}\n\npng_uint_32 PNGAPI\npng_get_io_chunk_type (png_const_structrp png_ptr)\n{\n   return png_ptr->chunk_name;\n}\n#endif /* IO_STATE */\n\n#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#  ifdef PNG_GET_PALETTE_MAX_SUPPORTED\nint PNGAPI\npng_get_palette_max(png_const_structp png_ptr, png_const_infop info_ptr)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      return png_ptr->num_palette_max;\n\n   return (-1);\n}\n#  endif\n#endif\n\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pnginfo.h",
    "content": "\n/* pnginfo.h - header file for PNG reference library\n *\n * Last changed in libpng 1.6.1 [March 28, 2013]\n * Copyright (c) 1998-2002,2004,2006-2013 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n /* png_info is a structure that holds the information in a PNG file so\n * that the application can find out the characteristics of the image.\n * If you are reading the file, this structure will tell you what is\n * in the PNG file.  If you are writing the file, fill in the information\n * you want to put into the PNG file, using png_set_*() functions, then\n * call png_write_info().\n *\n * The names chosen should be very close to the PNG specification, so\n * consult that document for information about the meaning of each field.\n *\n * With libpng < 0.95, it was only possible to directly set and read the\n * the values in the png_info_struct, which meant that the contents and\n * order of the values had to remain fixed.  With libpng 0.95 and later,\n * however, there are now functions that abstract the contents of\n * png_info_struct from the application, so this makes it easier to use\n * libpng with dynamic libraries, and even makes it possible to use\n * libraries that don't have all of the libpng ancillary chunk-handing\n * functionality.  In libpng-1.5.0 this was moved into a separate private\n * file that is not visible to applications.\n *\n * The following members may have allocated storage attached that should be\n * cleaned up before the structure is discarded: palette, trans, text,\n * pcal_purpose, pcal_units, pcal_params, hist, iccp_name, iccp_profile,\n * splt_palettes, scal_unit, row_pointers, and unknowns.   By default, these\n * are automatically freed when the info structure is deallocated, if they were\n * allocated internally by libpng.  This behavior can be changed by means\n * of the png_data_freer() function.\n *\n * More allocation details: all the chunk-reading functions that\n * change these members go through the corresponding png_set_*\n * functions.  A function to clear these members is available: see\n * png_free_data().  The png_set_* functions do not depend on being\n * able to point info structure members to any of the storage they are\n * passed (they make their own copies), EXCEPT that the png_set_text\n * functions use the same storage passed to them in the text_ptr or\n * itxt_ptr structure argument, and the png_set_rows and png_set_unknowns\n * functions do not make their own copies.\n */\n#ifndef PNGINFO_H\n#define PNGINFO_H\n\nstruct png_info_def\n{\n   /* The following are necessary for every PNG file */\n   png_uint_32 width;  /* width of image in pixels (from IHDR) */\n   png_uint_32 height; /* height of image in pixels (from IHDR) */\n   png_uint_32 valid;  /* valid chunk data (see PNG_INFO_ below) */\n   png_size_t rowbytes; /* bytes needed to hold an untransformed row */\n   png_colorp palette;      /* array of color values (valid & PNG_INFO_PLTE) */\n   png_uint_16 num_palette; /* number of color entries in \"palette\" (PLTE) */\n   png_uint_16 num_trans;   /* number of transparent palette color (tRNS) */\n   png_byte bit_depth;      /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */\n   png_byte color_type;     /* see PNG_COLOR_TYPE_ below (from IHDR) */\n   /* The following three should have been named *_method not *_type */\n   png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */\n   png_byte filter_type;    /* must be PNG_FILTER_TYPE_BASE (from IHDR) */\n   png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */\n\n   /* The following are set by png_set_IHDR, called from the application on\n    * write, but the are never actually used by the write code.\n    */\n   png_byte channels;       /* number of data channels per pixel (1, 2, 3, 4) */\n   png_byte pixel_depth;    /* number of bits per pixel */\n   png_byte spare_byte;     /* to align the data, and for future use */\n\n#ifdef PNG_READ_SUPPORTED\n   /* This is never set during write */\n   png_byte signature[8];   /* magic bytes read by libpng from start of file */\n#endif\n\n   /* The rest of the data is optional.  If you are reading, check the\n    * valid field to see if the information in these are valid.  If you\n    * are writing, set the valid field to those chunks you want written,\n    * and initialize the appropriate fields below.\n    */\n\n#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)\n   /* png_colorspace only contains 'flags' if neither GAMMA or COLORSPACE are\n    * defined.  When COLORSPACE is switched on all the colorspace-defining\n    * chunks should be enabled, when GAMMA is switched on all the gamma-defining\n    * chunks should be enabled.  If this is not done it becomes possible to read\n    * inconsistent PNG files and assign a probably incorrect interpretation to\n    * the information.  (In other words, by carefully choosing which chunks to\n    * recognize the system configuration can select an interpretation for PNG\n    * files containing ambiguous data and this will result in inconsistent\n    * behavior between different libpng builds!)\n    */\n   png_colorspace colorspace;\n#endif\n\n#ifdef PNG_iCCP_SUPPORTED\n   /* iCCP chunk data. */\n   png_charp iccp_name;     /* profile name */\n   png_bytep iccp_profile;  /* International Color Consortium profile data */\n   png_uint_32 iccp_proflen;  /* ICC profile data length */\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED\n   /* The tEXt, and zTXt chunks contain human-readable textual data in\n    * uncompressed, compressed, and optionally compressed forms, respectively.\n    * The data in \"text\" is an array of pointers to uncompressed,\n    * null-terminated C strings. Each chunk has a keyword that describes the\n    * textual data contained in that chunk.  Keywords are not required to be\n    * unique, and the text string may be empty.  Any number of text chunks may\n    * be in an image.\n    */\n   int num_text; /* number of comments read or comments to write */\n   int max_text; /* current size of text array */\n   png_textp text; /* array of comments read or comments to write */\n#endif /* TEXT */\n\n#ifdef PNG_tIME_SUPPORTED\n   /* The tIME chunk holds the last time the displayed image data was\n    * modified.  See the png_time struct for the contents of this struct.\n    */\n   png_time mod_time;\n#endif\n\n#ifdef PNG_sBIT_SUPPORTED\n   /* The sBIT chunk specifies the number of significant high-order bits\n    * in the pixel data.  Values are in the range [1, bit_depth], and are\n    * only specified for the channels in the pixel data.  The contents of\n    * the low-order bits is not specified.  Data is valid if\n    * (valid & PNG_INFO_sBIT) is non-zero.\n    */\n   png_color_8 sig_bit; /* significant bits in color channels */\n#endif\n\n#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \\\ndefined(PNG_READ_BACKGROUND_SUPPORTED)\n   /* The tRNS chunk supplies transparency data for paletted images and\n    * other image types that don't need a full alpha channel.  There are\n    * \"num_trans\" transparency values for a paletted image, stored in the\n    * same order as the palette colors, starting from index 0.  Values\n    * for the data are in the range [0, 255], ranging from fully transparent\n    * to fully opaque, respectively.  For non-paletted images, there is a\n    * single color specified that should be treated as fully transparent.\n    * Data is valid if (valid & PNG_INFO_tRNS) is non-zero.\n    */\n   png_bytep trans_alpha;    /* alpha values for paletted image */\n   png_color_16 trans_color; /* transparent color for non-palette image */\n#endif\n\n#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)\n   /* The bKGD chunk gives the suggested image background color if the\n    * display program does not have its own background color and the image\n    * is needs to composited onto a background before display.  The colors\n    * in \"background\" are normally in the same color space/depth as the\n    * pixel data.  Data is valid if (valid & PNG_INFO_bKGD) is non-zero.\n    */\n   png_color_16 background;\n#endif\n\n#ifdef PNG_oFFs_SUPPORTED\n   /* The oFFs chunk gives the offset in \"offset_unit_type\" units rightwards\n    * and downwards from the top-left corner of the display, page, or other\n    * application-specific co-ordinate space.  See the PNG_OFFSET_ defines\n    * below for the unit types.  Valid if (valid & PNG_INFO_oFFs) non-zero.\n    */\n   png_int_32 x_offset; /* x offset on page */\n   png_int_32 y_offset; /* y offset on page */\n   png_byte offset_unit_type; /* offset units type */\n#endif\n\n#ifdef PNG_pHYs_SUPPORTED\n   /* The pHYs chunk gives the physical pixel density of the image for\n    * display or printing in \"phys_unit_type\" units (see PNG_RESOLUTION_\n    * defines below).  Data is valid if (valid & PNG_INFO_pHYs) is non-zero.\n    */\n   png_uint_32 x_pixels_per_unit; /* horizontal pixel density */\n   png_uint_32 y_pixels_per_unit; /* vertical pixel density */\n   png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\n   /* The hIST chunk contains the relative frequency or importance of the\n    * various palette entries, so that a viewer can intelligently select a\n    * reduced-color palette, if required.  Data is an array of \"num_palette\"\n    * values in the range [0,65535]. Data valid if (valid & PNG_INFO_hIST)\n    * is non-zero.\n    */\n   png_uint_16p hist;\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\n   /* The pCAL chunk describes a transformation between the stored pixel\n    * values and original physical data values used to create the image.\n    * The integer range [0, 2^bit_depth - 1] maps to the floating-point\n    * range given by [pcal_X0, pcal_X1], and are further transformed by a\n    * (possibly non-linear) transformation function given by \"pcal_type\"\n    * and \"pcal_params\" into \"pcal_units\".  Please see the PNG_EQUATION_\n    * defines below, and the PNG-Group's PNG extensions document for a\n    * complete description of the transformations and how they should be\n    * implemented, and for a description of the ASCII parameter strings.\n    * Data values are valid if (valid & PNG_INFO_pCAL) non-zero.\n    */\n   png_charp pcal_purpose;  /* pCAL chunk description string */\n   png_int_32 pcal_X0;      /* minimum value */\n   png_int_32 pcal_X1;      /* maximum value */\n   png_charp pcal_units;    /* Latin-1 string giving physical units */\n   png_charpp pcal_params;  /* ASCII strings containing parameter values */\n   png_byte pcal_type;      /* equation type (see PNG_EQUATION_ below) */\n   png_byte pcal_nparams;   /* number of parameters given in pcal_params */\n#endif\n\n/* New members added in libpng-1.0.6 */\n   png_uint_32 free_me;     /* flags items libpng is responsible for freeing */\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n   /* Storage for unknown chunks that the library doesn't recognize. */\n   png_unknown_chunkp unknown_chunks;\n\n   /* The type of this field is limited by the type of\n    * png_struct::user_chunk_cache_max, else overflow can occur.\n    */\n   int                unknown_chunks_num;\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\n   /* Data on sPLT chunks (there may be more than one). */\n   png_sPLT_tp splt_palettes;\n   int         splt_palettes_num; /* Match type returned by png_get API */\n#endif\n\n#ifdef PNG_sCAL_SUPPORTED\n   /* The sCAL chunk describes the actual physical dimensions of the\n    * subject matter of the graphic.  The chunk contains a unit specification\n    * a byte value, and two ASCII strings representing floating-point\n    * values.  The values are width and height corresponsing to one pixel\n    * in the image.  Data values are valid if (valid & PNG_INFO_sCAL) is\n    * non-zero.\n    */\n   png_byte scal_unit;         /* unit of physical scale */\n   png_charp scal_s_width;     /* string containing height */\n   png_charp scal_s_height;    /* string containing width */\n#endif\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\n   /* Memory has been allocated if (valid & PNG_ALLOCATED_INFO_ROWS)\n      non-zero */\n   /* Data valid if (valid & PNG_INFO_IDAT) non-zero */\n   png_bytepp row_pointers;        /* the image bits */\n#endif\n\n};\n#endif /* PNGINFO_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pnglibconf.h",
    "content": "/* libpng 1.6.25 STANDARD API DEFINITION */\n\n/* pnglibconf.h - library build configuration */\n\n/* Libpng version 1.6.25 - September 1, 2016 */\n\n/* Copyright (c) 1998-2015 Glenn Randers-Pehrson */\n\n/* This code is released under the libpng license. */\n/* For conditions of distribution and use, see the disclaimer */\n/* and license in png.h */\n\n/* pnglibconf.h */\n/* Machine generated file: DO NOT EDIT */\n/* Derived from: scripts/pnglibconf.dfa */\n#ifndef PNGLCONF_H\n#define PNGLCONF_H\n/* options */\n#define PNG_16BIT_SUPPORTED\n#define PNG_ALIGNED_MEMORY_SUPPORTED\n/*#undef PNG_ARM_NEON_API_SUPPORTED*/\n/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/\n#define PNG_BENIGN_ERRORS_SUPPORTED\n#define PNG_BENIGN_READ_ERRORS_SUPPORTED\n/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/\n#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED\n#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_COLORSPACE_SUPPORTED\n#define PNG_CONSOLE_IO_SUPPORTED\n#define PNG_CONVERT_tIME_SUPPORTED\n#define PNG_EASY_ACCESS_SUPPORTED\n/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/\n#define PNG_ERROR_TEXT_SUPPORTED\n#define PNG_FIXED_POINT_SUPPORTED\n#define PNG_FLOATING_ARITHMETIC_SUPPORTED\n#define PNG_FLOATING_POINT_SUPPORTED\n#define PNG_FORMAT_AFIRST_SUPPORTED\n#define PNG_FORMAT_BGR_SUPPORTED\n#define PNG_GAMMA_SUPPORTED\n#define PNG_GET_PALETTE_MAX_SUPPORTED\n#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n#define PNG_INCH_CONVERSIONS_SUPPORTED\n#define PNG_INFO_IMAGE_SUPPORTED\n#define PNG_IO_STATE_SUPPORTED\n#define PNG_MNG_FEATURES_SUPPORTED\n#define PNG_POINTER_INDEXING_SUPPORTED\n#define PNG_PROGRESSIVE_READ_SUPPORTED\n#define PNG_READ_16BIT_SUPPORTED\n#define PNG_READ_ALPHA_MODE_SUPPORTED\n#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED\n#define PNG_READ_BACKGROUND_SUPPORTED\n#define PNG_READ_BGR_SUPPORTED\n#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_READ_COMPOSITE_NODIV_SUPPORTED\n#define PNG_READ_COMPRESSED_TEXT_SUPPORTED\n#define PNG_READ_EXPAND_16_SUPPORTED\n#define PNG_READ_EXPAND_SUPPORTED\n#define PNG_READ_FILLER_SUPPORTED\n#define PNG_READ_GAMMA_SUPPORTED\n#define PNG_READ_GET_PALETTE_MAX_SUPPORTED\n#define PNG_READ_GRAY_TO_RGB_SUPPORTED\n#define PNG_READ_INTERLACING_SUPPORTED\n#define PNG_READ_INT_FUNCTIONS_SUPPORTED\n#define PNG_READ_INVERT_ALPHA_SUPPORTED\n#define PNG_READ_INVERT_SUPPORTED\n#define PNG_READ_OPT_PLTE_SUPPORTED\n#define PNG_READ_PACKSWAP_SUPPORTED\n#define PNG_READ_PACK_SUPPORTED\n#define PNG_READ_QUANTIZE_SUPPORTED\n#define PNG_READ_RGB_TO_GRAY_SUPPORTED\n#define PNG_READ_SCALE_16_TO_8_SUPPORTED\n#define PNG_READ_SHIFT_SUPPORTED\n#define PNG_READ_STRIP_16_TO_8_SUPPORTED\n#define PNG_READ_STRIP_ALPHA_SUPPORTED\n#define PNG_READ_SUPPORTED\n#define PNG_READ_SWAP_ALPHA_SUPPORTED\n#define PNG_READ_SWAP_SUPPORTED\n#define PNG_READ_TEXT_SUPPORTED\n#define PNG_READ_TRANSFORMS_SUPPORTED\n#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_READ_USER_CHUNKS_SUPPORTED\n#define PNG_READ_USER_TRANSFORM_SUPPORTED\n#define PNG_READ_bKGD_SUPPORTED\n#define PNG_READ_cHRM_SUPPORTED\n#define PNG_READ_gAMA_SUPPORTED\n#define PNG_READ_hIST_SUPPORTED\n#define PNG_READ_iCCP_SUPPORTED\n#define PNG_READ_iTXt_SUPPORTED\n#define PNG_READ_oFFs_SUPPORTED\n#define PNG_READ_pCAL_SUPPORTED\n#define PNG_READ_pHYs_SUPPORTED\n#define PNG_READ_sBIT_SUPPORTED\n#define PNG_READ_sCAL_SUPPORTED\n#define PNG_READ_sPLT_SUPPORTED\n#define PNG_READ_sRGB_SUPPORTED\n#define PNG_READ_tEXt_SUPPORTED\n#define PNG_READ_tIME_SUPPORTED\n#define PNG_READ_tRNS_SUPPORTED\n#define PNG_READ_zTXt_SUPPORTED\n#define PNG_SAVE_INT_32_SUPPORTED\n#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_SEQUENTIAL_READ_SUPPORTED\n#define PNG_SETJMP_SUPPORTED\n#define PNG_SET_OPTION_SUPPORTED\n#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_SET_USER_LIMITS_SUPPORTED\n#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED\n#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED\n#define PNG_SIMPLIFIED_READ_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_SUPPORTED\n#define PNG_STDIO_SUPPORTED\n#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_TEXT_SUPPORTED\n#define PNG_TIME_RFC1123_SUPPORTED\n#define PNG_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_USER_CHUNKS_SUPPORTED\n#define PNG_USER_LIMITS_SUPPORTED\n#define PNG_USER_MEM_SUPPORTED\n#define PNG_USER_TRANSFORM_INFO_SUPPORTED\n#define PNG_USER_TRANSFORM_PTR_SUPPORTED\n/*#undef PNG_WARNINGS_SUPPORTED*/\n#define PNG_WRITE_16BIT_SUPPORTED\n#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED\n#define PNG_WRITE_BGR_SUPPORTED\n#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED\n#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\n#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n#define PNG_WRITE_FILLER_SUPPORTED\n#define PNG_WRITE_FILTER_SUPPORTED\n#define PNG_WRITE_FLUSH_SUPPORTED\n#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED\n#define PNG_WRITE_INTERLACING_SUPPORTED\n#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED\n#define PNG_WRITE_INVERT_ALPHA_SUPPORTED\n#define PNG_WRITE_INVERT_SUPPORTED\n#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n#define PNG_WRITE_PACKSWAP_SUPPORTED\n#define PNG_WRITE_PACK_SUPPORTED\n#define PNG_WRITE_SHIFT_SUPPORTED\n#define PNG_WRITE_SUPPORTED\n#define PNG_WRITE_SWAP_ALPHA_SUPPORTED\n#define PNG_WRITE_SWAP_SUPPORTED\n#define PNG_WRITE_TEXT_SUPPORTED\n#define PNG_WRITE_TRANSFORMS_SUPPORTED\n#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_WRITE_USER_TRANSFORM_SUPPORTED\n#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED\n#define PNG_WRITE_bKGD_SUPPORTED\n#define PNG_WRITE_cHRM_SUPPORTED\n#define PNG_WRITE_gAMA_SUPPORTED\n#define PNG_WRITE_hIST_SUPPORTED\n#define PNG_WRITE_iCCP_SUPPORTED\n#define PNG_WRITE_iTXt_SUPPORTED\n#define PNG_WRITE_oFFs_SUPPORTED\n#define PNG_WRITE_pCAL_SUPPORTED\n#define PNG_WRITE_pHYs_SUPPORTED\n#define PNG_WRITE_sBIT_SUPPORTED\n#define PNG_WRITE_sCAL_SUPPORTED\n#define PNG_WRITE_sPLT_SUPPORTED\n#define PNG_WRITE_sRGB_SUPPORTED\n#define PNG_WRITE_tEXt_SUPPORTED\n#define PNG_WRITE_tIME_SUPPORTED\n#define PNG_WRITE_tRNS_SUPPORTED\n#define PNG_WRITE_zTXt_SUPPORTED\n#define PNG_bKGD_SUPPORTED\n#define PNG_cHRM_SUPPORTED\n#define PNG_gAMA_SUPPORTED\n#define PNG_hIST_SUPPORTED\n#define PNG_iCCP_SUPPORTED\n#define PNG_iTXt_SUPPORTED\n#define PNG_oFFs_SUPPORTED\n#define PNG_pCAL_SUPPORTED\n#define PNG_pHYs_SUPPORTED\n#define PNG_sBIT_SUPPORTED\n#define PNG_sCAL_SUPPORTED\n#define PNG_sPLT_SUPPORTED\n#define PNG_sRGB_SUPPORTED\n#define PNG_tEXt_SUPPORTED\n#define PNG_tIME_SUPPORTED\n#define PNG_tRNS_SUPPORTED\n#define PNG_zTXt_SUPPORTED\n/* end of options */\n/* settings */\n#define PNG_API_RULE 0\n#define PNG_DEFAULT_READ_MACROS 1\n#define PNG_GAMMA_THRESHOLD_FIXED 5000\n#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE\n#define PNG_INFLATE_BUF_SIZE 1024\n#define PNG_LINKAGE_API extern\n#define PNG_LINKAGE_CALLBACK extern\n#define PNG_LINKAGE_DATA extern\n#define PNG_LINKAGE_FUNCTION extern\n#define PNG_MAX_GAMMA_8 11\n#define PNG_QUANTIZE_BLUE_BITS 5\n#define PNG_QUANTIZE_GREEN_BITS 5\n#define PNG_QUANTIZE_RED_BITS 5\n#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)\n#define PNG_TEXT_Z_DEFAULT_STRATEGY 0\n#define PNG_USER_CHUNK_CACHE_MAX 1000\n#define PNG_USER_CHUNK_MALLOC_MAX 8000000\n#define PNG_USER_HEIGHT_MAX 1000000\n#define PNG_USER_WIDTH_MAX 1000000\n#define PNG_ZBUF_SIZE 8192\n#define PNG_ZLIB_VERNUM 0 /* unknown */\n#define PNG_Z_DEFAULT_COMPRESSION (-1)\n#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0\n#define PNG_Z_DEFAULT_STRATEGY 1\n#define PNG_sCAL_PRECISION 5\n#define PNG_sRGB_PROFILE_CHECKS 2\n/* end of settings */\n#endif /* PNGLCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngmem.c",
    "content": "\n/* pngmem.c - stub functions for memory allocation\n *\n * Last changed in libpng 1.6.24 [August 4, 2016%]\n * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file provides a location for all memory allocation.  Users who\n * need special memory handling are expected to supply replacement\n * functions for png_malloc() and png_free(), and to use\n * png_create_read_struct_2() and png_create_write_struct_2() to\n * identify the replacement functions.\n */\n\n#include \"pngpriv.h\"\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n/* Free a png_struct */\nvoid /* PRIVATE */\npng_destroy_png_struct(png_structrp png_ptr)\n{\n   if (png_ptr != NULL)\n   {\n      /* png_free might call png_error and may certainly call\n       * png_get_mem_ptr, so fake a temporary png_struct to support this.\n       */\n      png_struct dummy_struct = *png_ptr;\n      memset(png_ptr, 0, (sizeof *png_ptr));\n      png_free(&dummy_struct, png_ptr);\n\n#     ifdef PNG_SETJMP_SUPPORTED\n         /* We may have a jmp_buf left to deallocate. */\n         png_free_jmpbuf(&dummy_struct);\n#     endif\n   }\n}\n\n/* Allocate memory.  For reasonable files, size should never exceed\n * 64K.  However, zlib may allocate more than 64K if you don't tell\n * it not to.  See zconf.h and png.h for more information.  zlib does\n * need to allocate exactly 64K, so whatever you call here must\n * have the ability to do that.\n */\nPNG_FUNCTION(png_voidp,PNGAPI\npng_calloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)\n{\n   png_voidp ret;\n\n   ret = png_malloc(png_ptr, size);\n\n   if (ret != NULL)\n      memset(ret, 0, size);\n\n   return ret;\n}\n\n/* png_malloc_base, an internal function added at libpng 1.6.0, does the work of\n * allocating memory, taking into account limits and PNG_USER_MEM_SUPPORTED.\n * Checking and error handling must happen outside this routine; it returns NULL\n * if the allocation cannot be done (for any reason.)\n */\nPNG_FUNCTION(png_voidp /* PRIVATE */,\npng_malloc_base,(png_const_structrp png_ptr, png_alloc_size_t size),\n    PNG_ALLOCATED)\n{\n   /* Moved to png_malloc_base from png_malloc_default in 1.6.0; the DOS\n    * allocators have also been removed in 1.6.0, so any 16-bit system now has\n    * to implement a user memory handler.  This checks to be sure it isn't\n    * called with big numbers.\n    */\n#ifndef PNG_USER_MEM_SUPPORTED\n   PNG_UNUSED(png_ptr)\n#endif\n\n   /* Some compilers complain that this is always true.  However, it\n    * can be false when integer overflow happens.\n    */\n   if (size > 0 && size <= PNG_SIZE_MAX\n#     ifdef PNG_MAX_MALLOC_64K\n         && size <= 65536U\n#     endif\n      )\n   {\n#ifdef PNG_USER_MEM_SUPPORTED\n      if (png_ptr != NULL && png_ptr->malloc_fn != NULL)\n         return png_ptr->malloc_fn(png_constcast(png_structrp,png_ptr), size);\n\n      else\n#endif\n         return malloc((size_t)size); /* checked for truncation above */\n   }\n\n   else\n      return NULL;\n}\n\n#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\\\n   defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)\n/* This is really here only to work round a spurious warning in GCC 4.6 and 4.7\n * that arises because of the checks in png_realloc_array that are repeated in\n * png_malloc_array.\n */\nstatic png_voidp\npng_malloc_array_checked(png_const_structrp png_ptr, int nelements,\n    size_t element_size)\n{\n   png_alloc_size_t req = nelements; /* known to be > 0 */\n\n   if (req <= PNG_SIZE_MAX/element_size)\n      return png_malloc_base(png_ptr, req * element_size);\n\n   /* The failure case when the request is too large */\n   return NULL;\n}\n\nPNG_FUNCTION(png_voidp /* PRIVATE */,\npng_malloc_array,(png_const_structrp png_ptr, int nelements,\n    size_t element_size),PNG_ALLOCATED)\n{\n   if (nelements <= 0 || element_size == 0)\n      png_error(png_ptr, \"internal error: array alloc\");\n\n   return png_malloc_array_checked(png_ptr, nelements, element_size);\n}\n\nPNG_FUNCTION(png_voidp /* PRIVATE */,\npng_realloc_array,(png_const_structrp png_ptr, png_const_voidp old_array,\n    int old_elements, int add_elements, size_t element_size),PNG_ALLOCATED)\n{\n   /* These are internal errors: */\n   if (add_elements <= 0 || element_size == 0 || old_elements < 0 ||\n      (old_array == NULL && old_elements > 0))\n      png_error(png_ptr, \"internal error: array realloc\");\n\n   /* Check for overflow on the elements count (so the caller does not have to\n    * check.)\n    */\n   if (add_elements <= INT_MAX - old_elements)\n   {\n      png_voidp new_array = png_malloc_array_checked(png_ptr,\n          old_elements+add_elements, element_size);\n\n      if (new_array != NULL)\n      {\n         /* Because png_malloc_array worked the size calculations below cannot\n          * overflow.\n          */\n         if (old_elements > 0)\n            memcpy(new_array, old_array, element_size*(unsigned)old_elements);\n\n         memset((char*)new_array + element_size*(unsigned)old_elements, 0,\n             element_size*(unsigned)add_elements);\n\n         return new_array;\n      }\n   }\n\n   return NULL; /* error */\n}\n#endif /* TEXT || sPLT || STORE_UNKNOWN_CHUNKS */\n\n/* Various functions that have different error handling are derived from this.\n * png_malloc always exists, but if PNG_USER_MEM_SUPPORTED is defined a separate\n * function png_malloc_default is also provided.\n */\nPNG_FUNCTION(png_voidp,PNGAPI\npng_malloc,(png_const_structrp png_ptr, png_alloc_size_t size),PNG_ALLOCATED)\n{\n   png_voidp ret;\n\n   if (png_ptr == NULL)\n      return NULL;\n\n   ret = png_malloc_base(png_ptr, size);\n\n   if (ret == NULL)\n       png_error(png_ptr, \"Out of memory\"); /* 'm' means png_malloc */\n\n   return ret;\n}\n\n#ifdef PNG_USER_MEM_SUPPORTED\nPNG_FUNCTION(png_voidp,PNGAPI\npng_malloc_default,(png_const_structrp png_ptr, png_alloc_size_t size),\n    PNG_ALLOCATED PNG_DEPRECATED)\n{\n   png_voidp ret;\n\n   if (png_ptr == NULL)\n      return NULL;\n\n   /* Passing 'NULL' here bypasses the application provided memory handler. */\n   ret = png_malloc_base(NULL/*use malloc*/, size);\n\n   if (ret == NULL)\n      png_error(png_ptr, \"Out of Memory\"); /* 'M' means png_malloc_default */\n\n   return ret;\n}\n#endif /* USER_MEM */\n\n/* This function was added at libpng version 1.2.3.  The png_malloc_warn()\n * function will issue a png_warning and return NULL instead of issuing a\n * png_error, if it fails to allocate the requested memory.\n */\nPNG_FUNCTION(png_voidp,PNGAPI\npng_malloc_warn,(png_const_structrp png_ptr, png_alloc_size_t size),\n    PNG_ALLOCATED)\n{\n   if (png_ptr != NULL)\n   {\n      png_voidp ret = png_malloc_base(png_ptr, size);\n\n      if (ret != NULL)\n         return ret;\n\n      png_warning(png_ptr, \"Out of memory\");\n   }\n\n   return NULL;\n}\n\n/* Free a pointer allocated by png_malloc().  If ptr is NULL, return\n * without taking any action.\n */\nvoid PNGAPI\npng_free(png_const_structrp png_ptr, png_voidp ptr)\n{\n   if (png_ptr == NULL || ptr == NULL)\n      return;\n\n#ifdef PNG_USER_MEM_SUPPORTED\n   if (png_ptr->free_fn != NULL)\n      png_ptr->free_fn(png_constcast(png_structrp,png_ptr), ptr);\n\n   else\n      png_free_default(png_ptr, ptr);\n}\n\nPNG_FUNCTION(void,PNGAPI\npng_free_default,(png_const_structrp png_ptr, png_voidp ptr),PNG_DEPRECATED)\n{\n   if (png_ptr == NULL || ptr == NULL)\n      return;\n#endif /* USER_MEM */\n\n   free(ptr);\n}\n\n#ifdef PNG_USER_MEM_SUPPORTED\n/* This function is called when the application wants to use another method\n * of allocating and freeing memory.\n */\nvoid PNGAPI\npng_set_mem_fn(png_structrp png_ptr, png_voidp mem_ptr, png_malloc_ptr\n  malloc_fn, png_free_ptr free_fn)\n{\n   if (png_ptr != NULL)\n   {\n      png_ptr->mem_ptr = mem_ptr;\n      png_ptr->malloc_fn = malloc_fn;\n      png_ptr->free_fn = free_fn;\n   }\n}\n\n/* This function returns a pointer to the mem_ptr associated with the user\n * functions.  The application should free any memory associated with this\n * pointer before png_write_destroy and png_read_destroy are called.\n */\npng_voidp PNGAPI\npng_get_mem_ptr(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return NULL;\n\n   return png_ptr->mem_ptr;\n}\n#endif /* USER_MEM */\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngpread.c",
    "content": "\n/* pngpread.c - read a png file in push mode\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\n\n/* Push model modes */\n#define PNG_READ_SIG_MODE   0\n#define PNG_READ_CHUNK_MODE 1\n#define PNG_READ_IDAT_MODE  2\n#define PNG_READ_tEXt_MODE  4\n#define PNG_READ_zTXt_MODE  5\n#define PNG_READ_DONE_MODE  6\n#define PNG_READ_iTXt_MODE  7\n#define PNG_ERROR_MODE      8\n\n#define PNG_PUSH_SAVE_BUFFER_IF_FULL \\\nif (png_ptr->push_length + 4 > png_ptr->buffer_size) \\\n   { png_push_save_buffer(png_ptr); return; }\n#define PNG_PUSH_SAVE_BUFFER_IF_LT(N) \\\nif (png_ptr->buffer_size < N) \\\n   { png_push_save_buffer(png_ptr); return; }\n\nvoid PNGAPI\npng_process_data(png_structrp png_ptr, png_inforp info_ptr,\n    png_bytep buffer, png_size_t buffer_size)\n{\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   png_push_restore_buffer(png_ptr, buffer, buffer_size);\n\n   while (png_ptr->buffer_size)\n   {\n      png_process_some_data(png_ptr, info_ptr);\n   }\n}\n\npng_size_t PNGAPI\npng_process_data_pause(png_structrp png_ptr, int save)\n{\n   if (png_ptr != NULL)\n   {\n      /* It's easiest for the caller if we do the save; then the caller doesn't\n       * have to supply the same data again:\n       */\n      if (save != 0)\n         png_push_save_buffer(png_ptr);\n      else\n      {\n         /* This includes any pending saved bytes: */\n         png_size_t remaining = png_ptr->buffer_size;\n         png_ptr->buffer_size = 0;\n\n         /* So subtract the saved buffer size, unless all the data\n          * is actually 'saved', in which case we just return 0\n          */\n         if (png_ptr->save_buffer_size < remaining)\n            return remaining - png_ptr->save_buffer_size;\n      }\n   }\n\n   return 0;\n}\n\npng_uint_32 PNGAPI\npng_process_data_skip(png_structrp png_ptr)\n{\n/* TODO: Deprecate and remove this API.\n * Somewhere the implementation of this seems to have been lost,\n * or abandoned.  It was only to support some internal back-door access\n * to png_struct) in libpng-1.4.x.\n */\n   png_app_warning(png_ptr,\n\"png_process_data_skip is not implemented in any current version of libpng\");\n   return 0;\n}\n\n/* What we do with the incoming data depends on what we were previously\n * doing before we ran out of data...\n */\nvoid /* PRIVATE */\npng_process_some_data(png_structrp png_ptr, png_inforp info_ptr)\n{\n   if (png_ptr == NULL)\n      return;\n\n   switch (png_ptr->process_mode)\n   {\n      case PNG_READ_SIG_MODE:\n      {\n         png_push_read_sig(png_ptr, info_ptr);\n         break;\n      }\n\n      case PNG_READ_CHUNK_MODE:\n      {\n         png_push_read_chunk(png_ptr, info_ptr);\n         break;\n      }\n\n      case PNG_READ_IDAT_MODE:\n      {\n         png_push_read_IDAT(png_ptr);\n         break;\n      }\n\n      default:\n      {\n         png_ptr->buffer_size = 0;\n         break;\n      }\n   }\n}\n\n/* Read any remaining signature bytes from the stream and compare them with\n * the correct PNG signature.  It is possible that this routine is called\n * with bytes already read from the signature, either because they have been\n * checked by the calling application, or because of multiple calls to this\n * routine.\n */\nvoid /* PRIVATE */\npng_push_read_sig(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_size_t num_checked = png_ptr->sig_bytes, /* SAFE, does not exceed 8 */\n       num_to_check = 8 - num_checked;\n\n   if (png_ptr->buffer_size < num_to_check)\n   {\n      num_to_check = png_ptr->buffer_size;\n   }\n\n   png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),\n       num_to_check);\n   png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes + num_to_check);\n\n   if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))\n   {\n      if (num_checked < 4 &&\n          png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))\n         png_error(png_ptr, \"Not a PNG file\");\n\n      else\n         png_error(png_ptr, \"PNG file corrupted by ASCII conversion\");\n   }\n   else\n   {\n      if (png_ptr->sig_bytes >= 8)\n      {\n         png_ptr->process_mode = PNG_READ_CHUNK_MODE;\n      }\n   }\n}\n\nvoid /* PRIVATE */\npng_push_read_chunk(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_uint_32 chunk_name;\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n   int keep; /* unknown handling method */\n#endif\n\n   /* First we make sure we have enough data for the 4-byte chunk name\n    * and the 4-byte chunk length before proceeding with decoding the\n    * chunk data.  To fully decode each of these chunks, we also make\n    * sure we have enough data in the buffer for the 4-byte CRC at the\n    * end of every chunk (except IDAT, which is handled separately).\n    */\n   if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)\n   {\n      png_byte chunk_length[4];\n      png_byte chunk_tag[4];\n\n      PNG_PUSH_SAVE_BUFFER_IF_LT(8)\n      png_push_fill_buffer(png_ptr, chunk_length, 4);\n      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);\n      png_reset_crc(png_ptr);\n      png_crc_read(png_ptr, chunk_tag, 4);\n      png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);\n      png_check_chunk_name(png_ptr, png_ptr->chunk_name);\n      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;\n   }\n\n   chunk_name = png_ptr->chunk_name;\n\n   if (chunk_name == png_IDAT)\n   {\n      if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)\n         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;\n\n      /* If we reach an IDAT chunk, this means we have read all of the\n       * header chunks, and we can start reading the image (or if this\n       * is called after the image has been read - we have an error).\n       */\n      if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n         png_error(png_ptr, \"Missing IHDR before IDAT\");\n\n      else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&\n          (png_ptr->mode & PNG_HAVE_PLTE) == 0)\n         png_error(png_ptr, \"Missing PLTE before IDAT\");\n\n      png_ptr->process_mode = PNG_READ_IDAT_MODE;\n\n      if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n         if ((png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) == 0)\n            if (png_ptr->push_length == 0)\n               return;\n\n      png_ptr->mode |= PNG_HAVE_IDAT;\n\n      if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)\n         png_benign_error(png_ptr, \"Too many IDATs found\");\n   }\n\n   if (chunk_name == png_IHDR)\n   {\n      if (png_ptr->push_length != 13)\n         png_error(png_ptr, \"Invalid IHDR length\");\n\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n   else if (chunk_name == png_IEND)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);\n\n      png_ptr->process_mode = PNG_READ_DONE_MODE;\n      png_push_have_end(png_ptr, info_ptr);\n   }\n\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n   else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length, keep);\n\n      if (chunk_name == png_PLTE)\n         png_ptr->mode |= PNG_HAVE_PLTE;\n   }\n#endif\n\n   else if (chunk_name == png_PLTE)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n   else if (chunk_name == png_IDAT)\n   {\n      png_ptr->idat_size = png_ptr->push_length;\n      png_ptr->process_mode = PNG_READ_IDAT_MODE;\n      png_push_have_info(png_ptr, info_ptr);\n      png_ptr->zstream.avail_out =\n          (uInt) PNG_ROWBYTES(png_ptr->pixel_depth,\n          png_ptr->iwidth) + 1;\n      png_ptr->zstream.next_out = png_ptr->row_buf;\n      return;\n   }\n\n#ifdef PNG_READ_gAMA_SUPPORTED\n   else if (png_ptr->chunk_name == png_gAMA)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_sBIT_SUPPORTED\n   else if (png_ptr->chunk_name == png_sBIT)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_cHRM_SUPPORTED\n   else if (png_ptr->chunk_name == png_cHRM)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_sRGB_SUPPORTED\n   else if (chunk_name == png_sRGB)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_iCCP_SUPPORTED\n   else if (png_ptr->chunk_name == png_iCCP)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_sPLT_SUPPORTED\n   else if (chunk_name == png_sPLT)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_tRNS_SUPPORTED\n   else if (chunk_name == png_tRNS)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_bKGD_SUPPORTED\n   else if (chunk_name == png_bKGD)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_hIST_SUPPORTED\n   else if (chunk_name == png_hIST)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_pHYs_SUPPORTED\n   else if (chunk_name == png_pHYs)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_oFFs_SUPPORTED\n   else if (chunk_name == png_oFFs)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);\n   }\n#endif\n\n#ifdef PNG_READ_pCAL_SUPPORTED\n   else if (chunk_name == png_pCAL)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_sCAL_SUPPORTED\n   else if (chunk_name == png_sCAL)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_tIME_SUPPORTED\n   else if (chunk_name == png_tIME)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_tEXt_SUPPORTED\n   else if (chunk_name == png_tEXt)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_zTXt_SUPPORTED\n   else if (chunk_name == png_zTXt)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);\n   }\n\n#endif\n#ifdef PNG_READ_iTXt_SUPPORTED\n   else if (chunk_name == png_iTXt)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);\n   }\n#endif\n\n   else\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_FULL\n      png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length,\n          PNG_HANDLE_CHUNK_AS_DEFAULT);\n   }\n\n   png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;\n}\n\nvoid PNGCBAPI\npng_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)\n{\n   png_bytep ptr;\n\n   if (png_ptr == NULL)\n      return;\n\n   ptr = buffer;\n   if (png_ptr->save_buffer_size != 0)\n   {\n      png_size_t save_size;\n\n      if (length < png_ptr->save_buffer_size)\n         save_size = length;\n\n      else\n         save_size = png_ptr->save_buffer_size;\n\n      memcpy(ptr, png_ptr->save_buffer_ptr, save_size);\n      length -= save_size;\n      ptr += save_size;\n      png_ptr->buffer_size -= save_size;\n      png_ptr->save_buffer_size -= save_size;\n      png_ptr->save_buffer_ptr += save_size;\n   }\n   if (length != 0 && png_ptr->current_buffer_size != 0)\n   {\n      png_size_t save_size;\n\n      if (length < png_ptr->current_buffer_size)\n         save_size = length;\n\n      else\n         save_size = png_ptr->current_buffer_size;\n\n      memcpy(ptr, png_ptr->current_buffer_ptr, save_size);\n      png_ptr->buffer_size -= save_size;\n      png_ptr->current_buffer_size -= save_size;\n      png_ptr->current_buffer_ptr += save_size;\n   }\n}\n\nvoid /* PRIVATE */\npng_push_save_buffer(png_structrp png_ptr)\n{\n   if (png_ptr->save_buffer_size != 0)\n   {\n      if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)\n      {\n         png_size_t i, istop;\n         png_bytep sp;\n         png_bytep dp;\n\n         istop = png_ptr->save_buffer_size;\n         for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;\n             i < istop; i++, sp++, dp++)\n         {\n            *dp = *sp;\n         }\n      }\n   }\n   if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >\n       png_ptr->save_buffer_max)\n   {\n      png_size_t new_max;\n      png_bytep old_buffer;\n\n      if (png_ptr->save_buffer_size > PNG_SIZE_MAX -\n          (png_ptr->current_buffer_size + 256))\n      {\n         png_error(png_ptr, \"Potential overflow of save_buffer\");\n      }\n\n      new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;\n      old_buffer = png_ptr->save_buffer;\n      png_ptr->save_buffer = (png_bytep)png_malloc_warn(png_ptr,\n          (png_size_t)new_max);\n\n      if (png_ptr->save_buffer == NULL)\n      {\n         png_free(png_ptr, old_buffer);\n         png_error(png_ptr, \"Insufficient memory for save_buffer\");\n      }\n\n      if (old_buffer)\n         memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);\n      else if (png_ptr->save_buffer_size)\n         png_error(png_ptr, \"save_buffer error\");\n      png_free(png_ptr, old_buffer);\n      png_ptr->save_buffer_max = new_max;\n   }\n   if (png_ptr->current_buffer_size)\n   {\n      memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,\n         png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);\n      png_ptr->save_buffer_size += png_ptr->current_buffer_size;\n      png_ptr->current_buffer_size = 0;\n   }\n   png_ptr->save_buffer_ptr = png_ptr->save_buffer;\n   png_ptr->buffer_size = 0;\n}\n\nvoid /* PRIVATE */\npng_push_restore_buffer(png_structrp png_ptr, png_bytep buffer,\n    png_size_t buffer_length)\n{\n   png_ptr->current_buffer = buffer;\n   png_ptr->current_buffer_size = buffer_length;\n   png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;\n   png_ptr->current_buffer_ptr = png_ptr->current_buffer;\n}\n\nvoid /* PRIVATE */\npng_push_read_IDAT(png_structrp png_ptr)\n{\n   if ((png_ptr->mode & PNG_HAVE_CHUNK_HEADER) == 0)\n   {\n      png_byte chunk_length[4];\n      png_byte chunk_tag[4];\n\n      /* TODO: this code can be commoned up with the same code in push_read */\n      PNG_PUSH_SAVE_BUFFER_IF_LT(8)\n      png_push_fill_buffer(png_ptr, chunk_length, 4);\n      png_ptr->push_length = png_get_uint_31(png_ptr, chunk_length);\n      png_reset_crc(png_ptr);\n      png_crc_read(png_ptr, chunk_tag, 4);\n      png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(chunk_tag);\n      png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;\n\n      if (png_ptr->chunk_name != png_IDAT)\n      {\n         png_ptr->process_mode = PNG_READ_CHUNK_MODE;\n\n         if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)\n            png_error(png_ptr, \"Not enough compressed data\");\n\n         return;\n      }\n\n      png_ptr->idat_size = png_ptr->push_length;\n   }\n\n   if (png_ptr->idat_size != 0 && png_ptr->save_buffer_size != 0)\n   {\n      png_size_t save_size = png_ptr->save_buffer_size;\n      png_uint_32 idat_size = png_ptr->idat_size;\n\n      /* We want the smaller of 'idat_size' and 'current_buffer_size', but they\n       * are of different types and we don't know which variable has the fewest\n       * bits.  Carefully select the smaller and cast it to the type of the\n       * larger - this cannot overflow.  Do not cast in the following test - it\n       * will break on either 16-bit or 64-bit platforms.\n       */\n      if (idat_size < save_size)\n         save_size = (png_size_t)idat_size;\n\n      else\n         idat_size = (png_uint_32)save_size;\n\n      png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);\n\n      png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);\n\n      png_ptr->idat_size -= idat_size;\n      png_ptr->buffer_size -= save_size;\n      png_ptr->save_buffer_size -= save_size;\n      png_ptr->save_buffer_ptr += save_size;\n   }\n\n   if (png_ptr->idat_size != 0 && png_ptr->current_buffer_size != 0)\n   {\n      png_size_t save_size = png_ptr->current_buffer_size;\n      png_uint_32 idat_size = png_ptr->idat_size;\n\n      /* We want the smaller of 'idat_size' and 'current_buffer_size', but they\n       * are of different types and we don't know which variable has the fewest\n       * bits.  Carefully select the smaller and cast it to the type of the\n       * larger - this cannot overflow.\n       */\n      if (idat_size < save_size)\n         save_size = (png_size_t)idat_size;\n\n      else\n         idat_size = (png_uint_32)save_size;\n\n      png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);\n\n      png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);\n\n      png_ptr->idat_size -= idat_size;\n      png_ptr->buffer_size -= save_size;\n      png_ptr->current_buffer_size -= save_size;\n      png_ptr->current_buffer_ptr += save_size;\n   }\n\n   if (png_ptr->idat_size == 0)\n   {\n      PNG_PUSH_SAVE_BUFFER_IF_LT(4)\n      png_crc_finish(png_ptr, 0);\n      png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;\n      png_ptr->mode |= PNG_AFTER_IDAT;\n      png_ptr->zowner = 0;\n   }\n}\n\nvoid /* PRIVATE */\npng_process_IDAT_data(png_structrp png_ptr, png_bytep buffer,\n    png_size_t buffer_length)\n{\n   /* The caller checks for a non-zero buffer length. */\n   if (!(buffer_length > 0) || buffer == NULL)\n      png_error(png_ptr, \"No IDAT data (internal error)\");\n\n   /* This routine must process all the data it has been given\n    * before returning, calling the row callback as required to\n    * handle the uncompressed results.\n    */\n   png_ptr->zstream.next_in = buffer;\n   /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */\n   png_ptr->zstream.avail_in = (uInt)buffer_length;\n\n   /* Keep going until the decompressed data is all processed\n    * or the stream marked as finished.\n    */\n   while (png_ptr->zstream.avail_in > 0 &&\n      (png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)\n   {\n      int ret;\n\n      /* We have data for zlib, but we must check that zlib\n       * has someplace to put the results.  It doesn't matter\n       * if we don't expect any results -- it may be the input\n       * data is just the LZ end code.\n       */\n      if (!(png_ptr->zstream.avail_out > 0))\n      {\n         /* TODO: WARNING: TRUNCATION ERROR: DANGER WILL ROBINSON: */\n         png_ptr->zstream.avail_out = (uInt)(PNG_ROWBYTES(png_ptr->pixel_depth,\n             png_ptr->iwidth) + 1);\n\n         png_ptr->zstream.next_out = png_ptr->row_buf;\n      }\n\n      /* Using Z_SYNC_FLUSH here means that an unterminated\n       * LZ stream (a stream with a missing end code) can still\n       * be handled, otherwise (Z_NO_FLUSH) a future zlib\n       * implementation might defer output and therefore\n       * change the current behavior (see comments in inflate.c\n       * for why this doesn't happen at present with zlib 1.2.5).\n       */\n      ret = PNG_INFLATE(png_ptr, Z_SYNC_FLUSH);\n\n      /* Check for any failure before proceeding. */\n      if (ret != Z_OK && ret != Z_STREAM_END)\n      {\n         /* Terminate the decompression. */\n         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;\n         png_ptr->zowner = 0;\n\n         /* This may be a truncated stream (missing or\n          * damaged end code).  Treat that as a warning.\n          */\n         if (png_ptr->row_number >= png_ptr->num_rows ||\n             png_ptr->pass > 6)\n            png_warning(png_ptr, \"Truncated compressed data in IDAT\");\n\n         else\n         {\n            if (ret == Z_DATA_ERROR)\n               png_benign_error(png_ptr, \"IDAT: ADLER32 checksum mismatch\");\n            else\n               png_error(png_ptr, \"Decompression error in IDAT\");\n         }\n\n         /* Skip the check on unprocessed input */\n         return;\n      }\n\n      /* Did inflate output any data? */\n      if (png_ptr->zstream.next_out != png_ptr->row_buf)\n      {\n         /* Is this unexpected data after the last row?\n          * If it is, artificially terminate the LZ output\n          * here.\n          */\n         if (png_ptr->row_number >= png_ptr->num_rows ||\n             png_ptr->pass > 6)\n         {\n            /* Extra data. */\n            png_warning(png_ptr, \"Extra compressed data in IDAT\");\n            png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;\n            png_ptr->zowner = 0;\n\n            /* Do no more processing; skip the unprocessed\n             * input check below.\n             */\n            return;\n         }\n\n         /* Do we have a complete row? */\n         if (png_ptr->zstream.avail_out == 0)\n            png_push_process_row(png_ptr);\n      }\n\n      /* And check for the end of the stream. */\n      if (ret == Z_STREAM_END)\n         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;\n   }\n\n   /* All the data should have been processed, if anything\n    * is left at this point we have bytes of IDAT data\n    * after the zlib end code.\n    */\n   if (png_ptr->zstream.avail_in > 0)\n      png_warning(png_ptr, \"Extra compression data in IDAT\");\n}\n\nvoid /* PRIVATE */\npng_push_process_row(png_structrp png_ptr)\n{\n   /* 1.5.6: row_info moved out of png_struct to a local here. */\n   png_row_info row_info;\n\n   row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */\n   row_info.color_type = png_ptr->color_type;\n   row_info.bit_depth = png_ptr->bit_depth;\n   row_info.channels = png_ptr->channels;\n   row_info.pixel_depth = png_ptr->pixel_depth;\n   row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);\n\n   if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)\n   {\n      if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)\n         png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,\n            png_ptr->prev_row + 1, png_ptr->row_buf[0]);\n      else\n         png_error(png_ptr, \"bad adaptive filter value\");\n   }\n\n   /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before\n    * 1.5.6, while the buffer really is this big in current versions of libpng\n    * it may not be in the future, so this was changed just to copy the\n    * interlaced row count:\n    */\n   memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n   if (png_ptr->transformations != 0)\n      png_do_read_transformations(png_ptr, &row_info);\n#endif\n\n   /* The transformed pixel depth should match the depth now in row_info. */\n   if (png_ptr->transformed_pixel_depth == 0)\n   {\n      png_ptr->transformed_pixel_depth = row_info.pixel_depth;\n      if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)\n         png_error(png_ptr, \"progressive row overflow\");\n   }\n\n   else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)\n      png_error(png_ptr, \"internal progressive row size calculation error\");\n\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* Expand interlaced rows to full size */\n   if (png_ptr->interlaced != 0 &&\n       (png_ptr->transformations & PNG_INTERLACE) != 0)\n   {\n      if (png_ptr->pass < 6)\n         png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,\n             png_ptr->transformations);\n\n      switch (png_ptr->pass)\n      {\n         case 0:\n         {\n            int i;\n            for (i = 0; i < 8 && png_ptr->pass == 0; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr); /* Updates png_ptr->pass */\n            }\n\n            if (png_ptr->pass == 2) /* Pass 1 might be empty */\n            {\n               for (i = 0; i < 4 && png_ptr->pass == 2; i++)\n               {\n                  png_push_have_row(png_ptr, NULL);\n                  png_read_push_finish_row(png_ptr);\n               }\n            }\n\n            if (png_ptr->pass == 4 && png_ptr->height <= 4)\n            {\n               for (i = 0; i < 2 && png_ptr->pass == 4; i++)\n               {\n                  png_push_have_row(png_ptr, NULL);\n                  png_read_push_finish_row(png_ptr);\n               }\n            }\n\n            if (png_ptr->pass == 6 && png_ptr->height <= 4)\n            {\n                png_push_have_row(png_ptr, NULL);\n                png_read_push_finish_row(png_ptr);\n            }\n\n            break;\n         }\n\n         case 1:\n         {\n            int i;\n            for (i = 0; i < 8 && png_ptr->pass == 1; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            if (png_ptr->pass == 2) /* Skip top 4 generated rows */\n            {\n               for (i = 0; i < 4 && png_ptr->pass == 2; i++)\n               {\n                  png_push_have_row(png_ptr, NULL);\n                  png_read_push_finish_row(png_ptr);\n               }\n            }\n\n            break;\n         }\n\n         case 2:\n         {\n            int i;\n\n            for (i = 0; i < 4 && png_ptr->pass == 2; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            for (i = 0; i < 4 && png_ptr->pass == 2; i++)\n            {\n               png_push_have_row(png_ptr, NULL);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            if (png_ptr->pass == 4) /* Pass 3 might be empty */\n            {\n               for (i = 0; i < 2 && png_ptr->pass == 4; i++)\n               {\n                  png_push_have_row(png_ptr, NULL);\n                  png_read_push_finish_row(png_ptr);\n               }\n            }\n\n            break;\n         }\n\n         case 3:\n         {\n            int i;\n\n            for (i = 0; i < 4 && png_ptr->pass == 3; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            if (png_ptr->pass == 4) /* Skip top two generated rows */\n            {\n               for (i = 0; i < 2 && png_ptr->pass == 4; i++)\n               {\n                  png_push_have_row(png_ptr, NULL);\n                  png_read_push_finish_row(png_ptr);\n               }\n            }\n\n            break;\n         }\n\n         case 4:\n         {\n            int i;\n\n            for (i = 0; i < 2 && png_ptr->pass == 4; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            for (i = 0; i < 2 && png_ptr->pass == 4; i++)\n            {\n               png_push_have_row(png_ptr, NULL);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            if (png_ptr->pass == 6) /* Pass 5 might be empty */\n            {\n               png_push_have_row(png_ptr, NULL);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            break;\n         }\n\n         case 5:\n         {\n            int i;\n\n            for (i = 0; i < 2 && png_ptr->pass == 5; i++)\n            {\n               png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            if (png_ptr->pass == 6) /* Skip top generated row */\n            {\n               png_push_have_row(png_ptr, NULL);\n               png_read_push_finish_row(png_ptr);\n            }\n\n            break;\n         }\n\n         default:\n         case 6:\n         {\n            png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n            png_read_push_finish_row(png_ptr);\n\n            if (png_ptr->pass != 6)\n               break;\n\n            png_push_have_row(png_ptr, NULL);\n            png_read_push_finish_row(png_ptr);\n         }\n      }\n   }\n   else\n#endif\n   {\n      png_push_have_row(png_ptr, png_ptr->row_buf + 1);\n      png_read_push_finish_row(png_ptr);\n   }\n}\n\nvoid /* PRIVATE */\npng_read_push_finish_row(png_structrp png_ptr)\n{\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};\n\n   /* Start of interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};\n\n   /* Offset to next interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};\n\n   /* Height of interlace block.  This is not currently used - if you need\n    * it, uncomment it here and in png.h\n   static PNG_CONST png_byte png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};\n   */\n#endif\n\n   png_ptr->row_number++;\n   if (png_ptr->row_number < png_ptr->num_rows)\n      return;\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   if (png_ptr->interlaced != 0)\n   {\n      png_ptr->row_number = 0;\n      memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);\n\n      do\n      {\n         png_ptr->pass++;\n         if ((png_ptr->pass == 1 && png_ptr->width < 5) ||\n             (png_ptr->pass == 3 && png_ptr->width < 3) ||\n             (png_ptr->pass == 5 && png_ptr->width < 2))\n            png_ptr->pass++;\n\n         if (png_ptr->pass > 7)\n            png_ptr->pass--;\n\n         if (png_ptr->pass >= 7)\n            break;\n\n         png_ptr->iwidth = (png_ptr->width +\n             png_pass_inc[png_ptr->pass] - 1 -\n             png_pass_start[png_ptr->pass]) /\n             png_pass_inc[png_ptr->pass];\n\n         if ((png_ptr->transformations & PNG_INTERLACE) != 0)\n            break;\n\n         png_ptr->num_rows = (png_ptr->height +\n             png_pass_yinc[png_ptr->pass] - 1 -\n             png_pass_ystart[png_ptr->pass]) /\n             png_pass_yinc[png_ptr->pass];\n\n      } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);\n   }\n#endif /* READ_INTERLACING */\n}\n\nvoid /* PRIVATE */\npng_push_have_info(png_structrp png_ptr, png_inforp info_ptr)\n{\n   if (png_ptr->info_fn != NULL)\n      (*(png_ptr->info_fn))(png_ptr, info_ptr);\n}\n\nvoid /* PRIVATE */\npng_push_have_end(png_structrp png_ptr, png_inforp info_ptr)\n{\n   if (png_ptr->end_fn != NULL)\n      (*(png_ptr->end_fn))(png_ptr, info_ptr);\n}\n\nvoid /* PRIVATE */\npng_push_have_row(png_structrp png_ptr, png_bytep row)\n{\n   if (png_ptr->row_fn != NULL)\n      (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,\n          (int)png_ptr->pass);\n}\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\nvoid PNGAPI\npng_progressive_combine_row(png_const_structrp png_ptr, png_bytep old_row,\n    png_const_bytep new_row)\n{\n   if (png_ptr == NULL)\n      return;\n\n   /* new_row is a flag here - if it is NULL then the app callback was called\n    * from an empty row (see the calls to png_struct::row_fn below), otherwise\n    * it must be png_ptr->row_buf+1\n    */\n   if (new_row != NULL)\n      png_combine_row(png_ptr, old_row, 1/*blocky display*/);\n}\n#endif /* READ_INTERLACING */\n\nvoid PNGAPI\npng_set_progressive_read_fn(png_structrp png_ptr, png_voidp progressive_ptr,\n    png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,\n    png_progressive_end_ptr end_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->info_fn = info_fn;\n   png_ptr->row_fn = row_fn;\n   png_ptr->end_fn = end_fn;\n\n   png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);\n}\n\npng_voidp PNGAPI\npng_get_progressive_ptr(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return (NULL);\n\n   return png_ptr->io_ptr;\n}\n#endif /* PROGRESSIVE_READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngpriv.h",
    "content": "\n/* pngpriv.h - private declarations for use inside libpng\n *\n * Last changed in libpng 1.6.25 [September 1, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* The symbols declared in this file (including the functions declared\n * as extern) are PRIVATE.  They are not part of the libpng public\n * interface, and are not recommended for use by regular applications.\n * Some of them may become public in the future; others may stay private,\n * change in an incompatible way, or even disappear.\n * Although the libpng users are not forbidden to include this header,\n * they should be well aware of the issues that may arise from doing so.\n */\n\n#ifndef PNGPRIV_H\n#define PNGPRIV_H\n\n/* Feature Test Macros.  The following are defined here to ensure that correctly\n * implemented libraries reveal the APIs libpng needs to build and hide those\n * that are not needed and potentially damaging to the compilation.\n *\n * Feature Test Macros must be defined before any system header is included (see\n * POSIX 1003.1 2.8.2 \"POSIX Symbols.\"\n *\n * These macros only have an effect if the operating system supports either\n * POSIX 1003.1 or C99, or both.  On other operating systems (particularly\n * Windows/Visual Studio) there is no effect; the OS specific tests below are\n * still required (as of 2011-05-02.)\n */\n#define _POSIX_SOURCE 1 /* Just the POSIX 1003.1 and C89 APIs */\n\n#ifndef PNG_VERSION_INFO_ONLY\n/* Standard library headers not required by png.h: */\n#  include <stdlib.h>\n#  include <string.h>\n#endif\n\n#define PNGLIB_BUILD /*libpng is being built, not used*/\n\n/* If HAVE_CONFIG_H is defined during the build then the build system must\n * provide an appropriate \"config.h\" file on the include path.  The header file\n * must provide definitions as required below (search for \"HAVE_CONFIG_H\");\n * see configure.ac for more details of the requirements.  The macro\n * \"PNG_NO_CONFIG_H\" is provided for maintainers to test for dependencies on\n * 'configure'; define this macro to prevent the configure build including the\n * configure generated config.h.  Libpng is expected to compile without *any*\n * special build system support on a reasonably ANSI-C compliant system.\n */\n#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n#  include <config.h>\n\n   /* Pick up the definition of 'restrict' from config.h if it was read: */\n#  define PNG_RESTRICT restrict\n#endif\n\n/* To support symbol prefixing it is necessary to know *before* including png.h\n * whether the fixed point (and maybe other) APIs are exported, because if they\n * are not internal definitions may be required.  This is handled below just\n * before png.h is included, but load the configuration now if it is available.\n */\n#ifndef PNGLCONF_H\n#  include \"pnglibconf.h\"\n#endif\n\n/* Local renames may change non-exported API functions from png.h */\n#if defined(PNG_PREFIX) && !defined(PNGPREFIX_H)\n#  include \"pngprefix.h\"\n#endif\n\n#ifdef PNG_USER_CONFIG\n#  include \"pngusr.h\"\n   /* These should have been defined in pngusr.h */\n#  ifndef PNG_USER_PRIVATEBUILD\n#    define PNG_USER_PRIVATEBUILD \"Custom libpng build\"\n#  endif\n#  ifndef PNG_USER_DLLFNAME_POSTFIX\n#    define PNG_USER_DLLFNAME_POSTFIX \"Cb\"\n#  endif\n#endif\n\n/* Compile time options.\n * =====================\n * In a multi-arch build the compiler may compile the code several times for the\n * same object module, producing different binaries for different architectures.\n * When this happens configure-time setting of the target host options cannot be\n * done and this interferes with the handling of the ARM NEON optimizations, and\n * possibly other similar optimizations.  Put additional tests here; in general\n * this is needed when the same option can be changed at both compile time and\n * run time depending on the target OS (i.e. iOS vs Android.)\n *\n * NOTE: symbol prefixing does not pass $(CFLAGS) to the preprocessor, because\n * this is not possible with certain compilers (Oracle SUN OS CC), as a result\n * it is necessary to ensure that all extern functions that *might* be used\n * regardless of $(CFLAGS) get declared in this file.  The test on __ARM_NEON__\n * below is one example of this behavior because it is controlled by the\n * presence or not of -mfpu=neon on the GCC command line, it is possible to do\n * this in $(CC), e.g. \"CC=gcc -mfpu=neon\", but people who build libpng rarely\n * do this.\n */\n#ifndef PNG_ARM_NEON_OPT\n   /* ARM NEON optimizations are being controlled by the compiler settings,\n    * typically the target FPU.  If the FPU has been set to NEON (-mfpu=neon\n    * with GCC) then the compiler will define __ARM_NEON__ and we can rely\n    * unconditionally on NEON instructions not crashing, otherwise we must\n    * disable use of NEON instructions.\n    *\n    * NOTE: at present these optimizations depend on 'ALIGNED_MEMORY', so they\n    * can only be turned on automatically if that is supported too.  If\n    * PNG_ARM_NEON_OPT is set in CPPFLAGS (to >0) then arm/arm_init.c will fail\n    * to compile with an appropriate #error if ALIGNED_MEMORY has been turned\n    * off.\n    *\n    * Note that gcc-4.9 defines __ARM_NEON instead of the deprecated\n    * __ARM_NEON__, so we check both variants.\n    *\n    * To disable ARM_NEON optimizations entirely, and skip compiling the\n    * associated assembler code, pass --enable-arm-neon=no to configure\n    * or put -DPNG_ARM_NEON_OPT=0 in CPPFLAGS.\n    */\n#  if defined(PNG_ARM_NEON) && (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \\\n   defined(PNG_ALIGNED_MEMORY_SUPPORTED)\n#     define PNG_ARM_NEON_OPT 2\n#  else\n#     define PNG_ARM_NEON_OPT 0\n#  endif\n#endif\n\n#if PNG_ARM_NEON_OPT > 0\n   /* NEON optimizations are to be at least considered by libpng, so enable the\n    * callbacks to do this.\n    */\n#  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_neon\n\n   /* By default the 'intrinsics' code in arm/filter_neon_intrinsics.c is used\n    * if possible - if __ARM_NEON__ is set and the compiler version is not known\n    * to be broken.  This is controlled by PNG_ARM_NEON_IMPLEMENTATION which can\n    * be:\n    *\n    *    1  The intrinsics code (the default with __ARM_NEON__)\n    *    2  The hand coded assembler (the default without __ARM_NEON__)\n    *\n    * It is possible to set PNG_ARM_NEON_IMPLEMENTATION in CPPFLAGS, however\n    * this is *NOT* supported and may cease to work even after a minor revision\n    * to libpng.  It *is* valid to do this for testing purposes, e.g. speed\n    * testing or a new compiler, but the results should be communicated to the\n    * libpng implementation list for incorporation in the next minor release.\n    */\n#  ifndef PNG_ARM_NEON_IMPLEMENTATION\n#     if defined(__ARM_NEON__) || defined(__ARM_NEON)\n#        if defined(__clang__)\n            /* At present it is unknown by the libpng developers which versions\n             * of clang support the intrinsics, however some or perhaps all\n             * versions do not work with the assembler so this may be\n             * irrelevant, so just use the default (do nothing here.)\n             */\n#        elif defined(__GNUC__)\n            /* GCC 4.5.4 NEON support is known to be broken.  4.6.3 is known to\n             * work, so if this *is* GCC, or G++, look for a version >4.5\n             */\n#           if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 6)\n#              define PNG_ARM_NEON_IMPLEMENTATION 2\n#           endif /* no GNUC support */\n#        endif /* __GNUC__ */\n#     else /* !defined __ARM_NEON__ */\n         /* The 'intrinsics' code simply won't compile without this -mfpu=neon:\n          */\n#        define PNG_ARM_NEON_IMPLEMENTATION 2\n#     endif /* __ARM_NEON__ */\n#  endif /* !PNG_ARM_NEON_IMPLEMENTATION */\n\n#  ifndef PNG_ARM_NEON_IMPLEMENTATION\n      /* Use the intrinsics code by default. */\n#     define PNG_ARM_NEON_IMPLEMENTATION 1\n#  endif\n#endif /* PNG_ARM_NEON_OPT > 0 */\n\n#ifndef PNG_MIPS_MSA_OPT\n#  if defined(__mips_msa) && (__mips_isa_rev >= 5) && defined(PNG_ALIGNED_MEMORY_SUPPORTED)\n#     define PNG_MIPS_MSA_OPT 2\n#  else\n#     define PNG_MIPS_MSA_OPT 0\n#  endif\n#endif\n\n#ifndef PNG_INTEL_SSE_OPT\n#   ifdef PNG_INTEL_SSE\n      /* Only check for SSE if the build configuration has been modified to\n       * enable SSE optimizations.  This means that these optimizations will\n       * be off by default.  See contrib/intel for more details.\n       */\n#     if defined(__SSE4_1__) || defined(__AVX__) || defined(__SSSE3__) || \\\n       defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n#         define PNG_INTEL_SSE_OPT 1\n#      endif\n#   endif\n#endif\n\n#if PNG_INTEL_SSE_OPT > 0\n#   ifndef PNG_INTEL_SSE_IMPLEMENTATION\n#      if defined(__SSE4_1__) || defined(__AVX__)\n          /* We are not actually using AVX, but checking for AVX is the best\n             way we can detect SSE4.1 and SSSE3 on MSVC.\n          */\n#         define PNG_INTEL_SSE_IMPLEMENTATION 3\n#      elif defined(__SSSE3__)\n#         define PNG_INTEL_SSE_IMPLEMENTATION 2\n#      elif defined(__SSE2__) || defined(_M_X64) || defined(_M_AMD64) || \\\n       (defined(_M_IX86_FP) && _M_IX86_FP >= 2)\n#         define PNG_INTEL_SSE_IMPLEMENTATION 1\n#      else\n#         define PNG_INTEL_SSE_IMPLEMENTATION 0\n#      endif\n#   endif\n\n#   if PNG_INTEL_SSE_IMPLEMENTATION > 0\n#      define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_sse2\n#   endif\n#endif\n\n#if PNG_MIPS_MSA_OPT > 0\n#  define PNG_FILTER_OPTIMIZATIONS png_init_filter_functions_msa\n#  ifndef PNG_MIPS_MSA_IMPLEMENTATION\n#     if defined(__mips_msa)\n#        if defined(__clang__)\n#        elif defined(__GNUC__)\n#           if __GNUC__ < 4 || (__GNUC__ == 4 && __GNUC_MINOR__ < 7)\n#              define PNG_MIPS_MSA_IMPLEMENTATION 2\n#           endif /* no GNUC support */\n#        endif /* __GNUC__ */\n#     else /* !defined __mips_msa */\n#        define PNG_MIPS_MSA_IMPLEMENTATION 2\n#     endif /* __mips_msa */\n#  endif /* !PNG_MIPS_MSA_IMPLEMENTATION */\n\n#  ifndef PNG_MIPS_MSA_IMPLEMENTATION\n#     define PNG_MIPS_MSA_IMPLEMENTATION 1\n#  endif\n#endif /* PNG_MIPS_MSA_OPT > 0 */\n\n\n/* Is this a build of a DLL where compilation of the object modules requires\n * different preprocessor settings to those required for a simple library?  If\n * so PNG_BUILD_DLL must be set.\n *\n * If libpng is used inside a DLL but that DLL does not export the libpng APIs\n * PNG_BUILD_DLL must not be set.  To avoid the code below kicking in build a\n * static library of libpng then link the DLL against that.\n */\n#ifndef PNG_BUILD_DLL\n#  ifdef DLL_EXPORT\n      /* This is set by libtool when files are compiled for a DLL; libtool\n       * always compiles twice, even on systems where it isn't necessary.  Set\n       * PNG_BUILD_DLL in case it is necessary:\n       */\n#     define PNG_BUILD_DLL\n#  else\n#     ifdef _WINDLL\n         /* This is set by the Microsoft Visual Studio IDE in projects that\n          * build a DLL.  It can't easily be removed from those projects (it\n          * isn't visible in the Visual Studio UI) so it is a fairly reliable\n          * indication that PNG_IMPEXP needs to be set to the DLL export\n          * attributes.\n          */\n#        define PNG_BUILD_DLL\n#     else\n#        ifdef __DLL__\n            /* This is set by the Borland C system when compiling for a DLL\n             * (as above.)\n             */\n#           define PNG_BUILD_DLL\n#        else\n            /* Add additional compiler cases here. */\n#        endif\n#     endif\n#  endif\n#endif /* Setting PNG_BUILD_DLL if required */\n\n/* See pngconf.h for more details: the builder of the library may set this on\n * the command line to the right thing for the specific compilation system or it\n * may be automagically set above (at present we know of no system where it does\n * need to be set on the command line.)\n *\n * PNG_IMPEXP must be set here when building the library to prevent pngconf.h\n * setting it to the \"import\" setting for a DLL build.\n */\n#ifndef PNG_IMPEXP\n#  ifdef PNG_BUILD_DLL\n#     define PNG_IMPEXP PNG_DLL_EXPORT\n#  else\n      /* Not building a DLL, or the DLL doesn't require specific export\n       * definitions.\n       */\n#     define PNG_IMPEXP\n#  endif\n#endif\n\n/* No warnings for private or deprecated functions in the build: */\n#ifndef PNG_DEPRECATED\n#  define PNG_DEPRECATED\n#endif\n#ifndef PNG_PRIVATE\n#  define PNG_PRIVATE\n#endif\n\n/* Symbol preprocessing support.\n *\n * To enable listing global, but internal, symbols the following macros should\n * always be used to declare an extern data or function object in this file.\n */\n#ifndef PNG_INTERNAL_DATA\n#  define PNG_INTERNAL_DATA(type, name, array) PNG_LINKAGE_DATA type name array\n#endif\n\n#ifndef PNG_INTERNAL_FUNCTION\n#  define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\\\n      PNG_LINKAGE_FUNCTION PNG_FUNCTION(type, name, args, PNG_EMPTY attributes)\n#endif\n\n#ifndef PNG_INTERNAL_CALLBACK\n#  define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\\\n      PNG_LINKAGE_CALLBACK PNG_FUNCTION(type, (PNGCBAPI name), args,\\\n         PNG_EMPTY attributes)\n#endif\n\n/* If floating or fixed point APIs are disabled they may still be compiled\n * internally.  To handle this make sure they are declared as the appropriate\n * internal extern function (otherwise the symbol prefixing stuff won't work and\n * the functions will be used without definitions.)\n *\n * NOTE: although all the API functions are declared here they are not all\n * actually built!  Because the declarations are still made it is necessary to\n * fake out types that they depend on.\n */\n#ifndef PNG_FP_EXPORT\n#  ifndef PNG_FLOATING_POINT_SUPPORTED\n#     define PNG_FP_EXPORT(ordinal, type, name, args)\\\n         PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);\n#     ifndef PNG_VERSION_INFO_ONLY\n         typedef struct png_incomplete png_double;\n         typedef png_double*           png_doublep;\n         typedef const png_double*     png_const_doublep;\n         typedef png_double**          png_doublepp;\n#     endif\n#  endif\n#endif\n#ifndef PNG_FIXED_EXPORT\n#  ifndef PNG_FIXED_POINT_SUPPORTED\n#     define PNG_FIXED_EXPORT(ordinal, type, name, args)\\\n         PNG_INTERNAL_FUNCTION(type, name, args, PNG_EMPTY);\n#  endif\n#endif\n\n#include \"png.h\"\n\n/* pngconf.h does not set PNG_DLL_EXPORT unless it is required, so: */\n#ifndef PNG_DLL_EXPORT\n#  define PNG_DLL_EXPORT\n#endif\n\n/* This is a global switch to set the compilation for an installed system\n * (a release build).  It can be set for testing debug builds to ensure that\n * they will compile when the build type is switched to RC or STABLE, the\n * default is just to use PNG_LIBPNG_BUILD_BASE_TYPE.  Set this in CPPFLAGS\n * with either:\n *\n *   -DPNG_RELEASE_BUILD Turns on the release compile path\n *   -DPNG_RELEASE_BUILD=0 Turns it off\n * or in your pngusr.h with\n *   #define PNG_RELEASE_BUILD=1 Turns on the release compile path\n *   #define PNG_RELEASE_BUILD=0 Turns it off\n */\n#ifndef PNG_RELEASE_BUILD\n#  define PNG_RELEASE_BUILD (PNG_LIBPNG_BUILD_BASE_TYPE >= PNG_LIBPNG_BUILD_RC)\n#endif\n\n/* SECURITY and SAFETY:\n *\n * libpng is built with support for internal limits on image dimensions and\n * memory usage.  These are documented in scripts/pnglibconf.dfa of the\n * source and recorded in the machine generated header file pnglibconf.h.\n */\n\n/* If you are running on a machine where you cannot allocate more\n * than 64K of memory at once, uncomment this.  While libpng will not\n * normally need that much memory in a chunk (unless you load up a very\n * large file), zlib needs to know how big of a chunk it can use, and\n * libpng thus makes sure to check any memory allocation to verify it\n * will fit into memory.\n *\n * zlib provides 'MAXSEG_64K' which, if defined, indicates the\n * same limit and pngconf.h (already included) sets the limit\n * if certain operating systems are detected.\n */\n#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)\n#  define PNG_MAX_MALLOC_64K\n#endif\n\n#ifndef PNG_UNUSED\n/* Unused formal parameter warnings are silenced using the following macro\n * which is expected to have no bad effects on performance (optimizing\n * compilers will probably remove it entirely).  Note that if you replace\n * it with something other than whitespace, you must include the terminating\n * semicolon.\n */\n#  define PNG_UNUSED(param) (void)param;\n#endif\n\n/* Just a little check that someone hasn't tried to define something\n * contradictory.\n */\n#if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)\n#  undef PNG_ZBUF_SIZE\n#  define PNG_ZBUF_SIZE 65536L\n#endif\n\n/* If warnings or errors are turned off the code is disabled or redirected here.\n * From 1.5.4 functions have been added to allow very limited formatting of\n * error and warning messages - this code will also be disabled here.\n */\n#ifdef PNG_WARNINGS_SUPPORTED\n#  define PNG_WARNING_PARAMETERS(p) png_warning_parameters p;\n#else\n#  define png_warning_parameter(p,number,string) ((void)0)\n#  define png_warning_parameter_unsigned(p,number,format,value) ((void)0)\n#  define png_warning_parameter_signed(p,number,format,value) ((void)0)\n#  define png_formatted_warning(pp,p,message) ((void)(pp))\n#  define PNG_WARNING_PARAMETERS(p)\n#endif\n#ifndef PNG_ERROR_TEXT_SUPPORTED\n#  define png_fixed_error(s1,s2) png_err(s1)\n#endif\n\n/* C allows up-casts from (void*) to any pointer and (const void*) to any\n * pointer to a const object.  C++ regards this as a type error and requires an\n * explicit, static, cast and provides the static_cast<> rune to ensure that\n * const is not cast away.\n */\n#ifdef __cplusplus\n#  define png_voidcast(type, value) static_cast<type>(value)\n#  define png_constcast(type, value) const_cast<type>(value)\n#  define png_aligncast(type, value) \\\n   static_cast<type>(static_cast<void*>(value))\n#  define png_aligncastconst(type, value) \\\n   static_cast<type>(static_cast<const void*>(value))\n#else\n#  define png_voidcast(type, value) (value)\n#  define png_constcast(type, value) ((type)(value))\n#  define png_aligncast(type, value) ((void*)(value))\n#  define png_aligncastconst(type, value) ((const void*)(value))\n#endif /* __cplusplus */\n\n/* Some fixed point APIs are still required even if not exported because\n * they get used by the corresponding floating point APIs.  This magic\n * deals with this:\n */\n#ifdef PNG_FIXED_POINT_SUPPORTED\n#  define PNGFAPI PNGAPI\n#else\n#  define PNGFAPI /* PRIVATE */\n#endif\n\n#ifndef PNG_VERSION_INFO_ONLY\n/* Other defines specific to compilers can go here.  Try to keep\n * them inside an appropriate ifdef/endif pair for portability.\n */\n#if defined(PNG_FLOATING_POINT_SUPPORTED) ||\\\n    defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)\n   /* png.c requires the following ANSI-C constants if the conversion of\n    * floating point to ASCII is implemented therein:\n    *\n    *  DBL_DIG  Maximum number of decimal digits (can be set to any constant)\n    *  DBL_MIN  Smallest normalized fp number (can be set to an arbitrary value)\n    *  DBL_MAX  Maximum floating point number (can be set to an arbitrary value)\n    */\n#  include <float.h>\n\n#  if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \\\n    defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)\n   /* We need to check that <math.h> hasn't already been included earlier\n    * as it seems it doesn't agree with <fp.h>, yet we should really use\n    * <fp.h> if possible.\n    */\n#    if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)\n#      include <fp.h>\n#    endif\n#  else\n#    include <math.h>\n#  endif\n#  if defined(_AMIGA) && defined(__SASC) && defined(_M68881)\n   /* Amiga SAS/C: We must include builtin FPU functions when compiling using\n    * MATH=68881\n    */\n#    include <m68881.h>\n#  endif\n#endif\n\n/* This provides the non-ANSI (far) memory allocation routines. */\n#if defined(__TURBOC__) && defined(__MSDOS__)\n#  include <mem.h>\n#  include <alloc.h>\n#endif\n\n#if defined(WIN32) || defined(_Windows) || defined(_WINDOWS) || \\\n    defined(_WIN32) || defined(__WIN32__)\n#  include <windows.h>  /* defines _WINDOWS_ macro */\n#endif\n#endif /* PNG_VERSION_INFO_ONLY */\n\n/* Moved here around 1.5.0beta36 from pngconf.h */\n/* Users may want to use these so they are not private.  Any library\n * functions that are passed far data must be model-independent.\n */\n\n/* Memory model/platform independent fns */\n#ifndef PNG_ABORT\n#  ifdef _WINDOWS_\n#    define PNG_ABORT() ExitProcess(0)\n#  else\n#    define PNG_ABORT() abort()\n#  endif\n#endif\n\n/* These macros may need to be architecture dependent. */\n#define PNG_ALIGN_NONE   0 /* do not use data alignment */\n#define PNG_ALIGN_ALWAYS 1 /* assume unaligned accesses are OK */\n#ifdef offsetof\n#  define PNG_ALIGN_OFFSET 2 /* use offsetof to determine alignment */\n#else\n#  define PNG_ALIGN_OFFSET -1 /* prevent the use of this */\n#endif\n#define PNG_ALIGN_SIZE   3 /* use sizeof to determine alignment */\n\n#ifndef PNG_ALIGN_TYPE\n   /* Default to using aligned access optimizations and requiring alignment to a\n    * multiple of the data type size.  Override in a compiler specific fashion\n    * if necessary by inserting tests here:\n    */\n#  define PNG_ALIGN_TYPE PNG_ALIGN_SIZE\n#endif\n\n#if PNG_ALIGN_TYPE == PNG_ALIGN_SIZE\n   /* This is used because in some compiler implementations non-aligned\n    * structure members are supported, so the offsetof approach below fails.\n    * Set PNG_ALIGN_SIZE=0 for compiler combinations where unaligned access\n    * is good for performance.  Do not do this unless you have tested the result\n    * and understand it.\n    */\n#  define png_alignof(type) (sizeof (type))\n#else\n#  if PNG_ALIGN_TYPE == PNG_ALIGN_OFFSET\n#     define png_alignof(type) offsetof(struct{char c; type t;}, t)\n#  else\n#     if PNG_ALIGN_TYPE == PNG_ALIGN_ALWAYS\n#        define png_alignof(type) (1)\n#     endif\n      /* Else leave png_alignof undefined to prevent use thereof */\n#  endif\n#endif\n\n/* This implicitly assumes alignment is always to a power of 2. */\n#ifdef png_alignof\n#  define png_isaligned(ptr, type)\\\n   ((((const char*)ptr-(const char*)0) & (png_alignof(type)-1)) == 0)\n#else\n#  define png_isaligned(ptr, type) 0\n#endif\n\n/* End of memory model/platform independent support */\n/* End of 1.5.0beta36 move from pngconf.h */\n\n/* CONSTANTS and UTILITY MACROS\n * These are used internally by libpng and not exposed in the API\n */\n\n/* Various modes of operation.  Note that after an init, mode is set to\n * zero automatically when the structure is created.  Three of these\n * are defined in png.h because they need to be visible to applications\n * that call png_set_unknown_chunk().\n */\n/* #define PNG_HAVE_IHDR            0x01 (defined in png.h) */\n/* #define PNG_HAVE_PLTE            0x02 (defined in png.h) */\n#define PNG_HAVE_IDAT               0x04\n/* #define PNG_AFTER_IDAT           0x08 (defined in png.h) */\n#define PNG_HAVE_IEND               0x10\n                   /*               0x20 (unused) */\n                   /*               0x40 (unused) */\n                   /*               0x80 (unused) */\n#define PNG_HAVE_CHUNK_HEADER      0x100\n#define PNG_WROTE_tIME             0x200\n#define PNG_WROTE_INFO_BEFORE_PLTE 0x400\n#define PNG_BACKGROUND_IS_GRAY     0x800\n#define PNG_HAVE_PNG_SIGNATURE    0x1000\n#define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */\n                   /*             0x4000 (unused) */\n#define PNG_IS_READ_STRUCT        0x8000 /* Else is a write struct */\n\n/* Flags for the transformations the PNG library does on the image data */\n#define PNG_BGR                 0x0001\n#define PNG_INTERLACE           0x0002\n#define PNG_PACK                0x0004\n#define PNG_SHIFT               0x0008\n#define PNG_SWAP_BYTES          0x0010\n#define PNG_INVERT_MONO         0x0020\n#define PNG_QUANTIZE            0x0040\n#define PNG_COMPOSE             0x0080     /* Was PNG_BACKGROUND */\n#define PNG_BACKGROUND_EXPAND   0x0100\n#define PNG_EXPAND_16           0x0200     /* Added to libpng 1.5.2 */\n#define PNG_16_TO_8             0x0400     /* Becomes 'chop' in 1.5.4 */\n#define PNG_RGBA                0x0800\n#define PNG_EXPAND              0x1000\n#define PNG_GAMMA               0x2000\n#define PNG_GRAY_TO_RGB         0x4000\n#define PNG_FILLER              0x8000\n#define PNG_PACKSWAP           0x10000\n#define PNG_SWAP_ALPHA         0x20000\n#define PNG_STRIP_ALPHA        0x40000\n#define PNG_INVERT_ALPHA       0x80000\n#define PNG_USER_TRANSFORM    0x100000\n#define PNG_RGB_TO_GRAY_ERR   0x200000\n#define PNG_RGB_TO_GRAY_WARN  0x400000\n#define PNG_RGB_TO_GRAY       0x600000 /* two bits, RGB_TO_GRAY_ERR|WARN */\n#define PNG_ENCODE_ALPHA      0x800000 /* Added to libpng-1.5.4 */\n#define PNG_ADD_ALPHA        0x1000000 /* Added to libpng-1.2.7 */\n#define PNG_EXPAND_tRNS      0x2000000 /* Added to libpng-1.2.9 */\n#define PNG_SCALE_16_TO_8    0x4000000 /* Added to libpng-1.5.4 */\n                       /*    0x8000000 unused */\n                       /*   0x10000000 unused */\n                       /*   0x20000000 unused */\n                       /*   0x40000000 unused */\n/* Flags for png_create_struct */\n#define PNG_STRUCT_PNG   0x0001\n#define PNG_STRUCT_INFO  0x0002\n\n/* Flags for the png_ptr->flags rather than declaring a byte for each one */\n#define PNG_FLAG_ZLIB_CUSTOM_STRATEGY     0x0001\n#define PNG_FLAG_ZSTREAM_INITIALIZED      0x0002 /* Added to libpng-1.6.0 */\n                                  /*      0x0004    unused */\n#define PNG_FLAG_ZSTREAM_ENDED            0x0008 /* Added to libpng-1.6.0 */\n                                  /*      0x0010    unused */\n                                  /*      0x0020    unused */\n#define PNG_FLAG_ROW_INIT                 0x0040\n#define PNG_FLAG_FILLER_AFTER             0x0080\n#define PNG_FLAG_CRC_ANCILLARY_USE        0x0100\n#define PNG_FLAG_CRC_ANCILLARY_NOWARN     0x0200\n#define PNG_FLAG_CRC_CRITICAL_USE         0x0400\n#define PNG_FLAG_CRC_CRITICAL_IGNORE      0x0800\n#define PNG_FLAG_ASSUME_sRGB              0x1000 /* Added to libpng-1.5.4 */\n#define PNG_FLAG_OPTIMIZE_ALPHA           0x2000 /* Added to libpng-1.5.4 */\n#define PNG_FLAG_DETECT_UNINITIALIZED     0x4000 /* Added to libpng-1.5.4 */\n/* #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS      0x8000 */\n/* #define PNG_FLAG_KEEP_UNSAFE_CHUNKS      0x10000 */\n#define PNG_FLAG_LIBRARY_MISMATCH        0x20000\n#define PNG_FLAG_STRIP_ERROR_NUMBERS     0x40000\n#define PNG_FLAG_STRIP_ERROR_TEXT        0x80000\n#define PNG_FLAG_BENIGN_ERRORS_WARN     0x100000 /* Added to libpng-1.4.0 */\n#define PNG_FLAG_APP_WARNINGS_WARN      0x200000 /* Added to libpng-1.6.0 */\n#define PNG_FLAG_APP_ERRORS_WARN        0x400000 /* Added to libpng-1.6.0 */\n                                  /*    0x800000    unused */\n                                  /*   0x1000000    unused */\n                                  /*   0x2000000    unused */\n                                  /*   0x4000000    unused */\n                                  /*   0x8000000    unused */\n                                  /*  0x10000000    unused */\n                                  /*  0x20000000    unused */\n                                  /*  0x40000000    unused */\n\n#define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \\\n                                     PNG_FLAG_CRC_ANCILLARY_NOWARN)\n\n#define PNG_FLAG_CRC_CRITICAL_MASK  (PNG_FLAG_CRC_CRITICAL_USE | \\\n                                     PNG_FLAG_CRC_CRITICAL_IGNORE)\n\n#define PNG_FLAG_CRC_MASK           (PNG_FLAG_CRC_ANCILLARY_MASK | \\\n                                     PNG_FLAG_CRC_CRITICAL_MASK)\n\n/* Save typing and make code easier to understand */\n\n#define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \\\n   abs((int)((c1).green) - (int)((c2).green)) + \\\n   abs((int)((c1).blue) - (int)((c2).blue)))\n\n/* Added to libpng-1.6.0: scale a 16-bit value in the range 0..65535 to 0..255\n * by dividing by 257 *with rounding*.  This macro is exact for the given range.\n * See the discourse in pngrtran.c png_do_scale_16_to_8.  The values in the\n * macro were established by experiment (modifying the added value).  The macro\n * has a second variant that takes a value already scaled by 255 and divides by\n * 65535 - this has a maximum error of .502.  Over the range 0..65535*65535 it\n * only gives off-by-one errors and only for 0.5% (1 in 200) of the values.\n */\n#define PNG_DIV65535(v24) (((v24) + 32895) >> 16)\n#define PNG_DIV257(v16) PNG_DIV65535((png_uint_32)(v16) * 255)\n\n/* Added to libpng-1.2.6 JB */\n#define PNG_ROWBYTES(pixel_bits, width) \\\n    ((pixel_bits) >= 8 ? \\\n    ((png_size_t)(width) * (((png_size_t)(pixel_bits)) >> 3)) : \\\n    (( ((png_size_t)(width) * ((png_size_t)(pixel_bits))) + 7) >> 3) )\n\n/* PNG_OUT_OF_RANGE returns true if value is outside the range\n * ideal-delta..ideal+delta.  Each argument is evaluated twice.\n * \"ideal\" and \"delta\" should be constants, normally simple\n * integers, \"value\" a variable. Added to libpng-1.2.6 JB\n */\n#define PNG_OUT_OF_RANGE(value, ideal, delta) \\\n   ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )\n\n/* Conversions between fixed and floating point, only defined if\n * required (to make sure the code doesn't accidentally use float\n * when it is supposedly disabled.)\n */\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n/* The floating point conversion can't overflow, though it can and\n * does lose accuracy relative to the original fixed point value.\n * In practice this doesn't matter because png_fixed_point only\n * stores numbers with very low precision.  The png_ptr and s\n * arguments are unused by default but are there in case error\n * checking becomes a requirement.\n */\n#define png_float(png_ptr, fixed, s) (.00001 * (fixed))\n\n/* The fixed point conversion performs range checking and evaluates\n * its argument multiple times, so must be used with care.  The\n * range checking uses the PNG specification values for a signed\n * 32-bit fixed point value except that the values are deliberately\n * rounded-to-zero to an integral value - 21474 (21474.83 is roughly\n * (2^31-1) * 100000). 's' is a string that describes the value being\n * converted.\n *\n * NOTE: this macro will raise a png_error if the range check fails,\n * therefore it is normally only appropriate to use this on values\n * that come from API calls or other sources where an out of range\n * error indicates a programming error, not a data error!\n *\n * NOTE: by default this is off - the macro is not used - because the\n * function call saves a lot of code.\n */\n#ifdef PNG_FIXED_POINT_MACRO_SUPPORTED\n#define png_fixed(png_ptr, fp, s) ((fp) <= 21474 && (fp) >= -21474 ?\\\n    ((png_fixed_point)(100000 * (fp))) : (png_fixed_error(png_ptr, s),0))\n#endif\n/* else the corresponding function is defined below, inside the scope of the\n * cplusplus test.\n */\n#endif\n\n/* Constants for known chunk types.  If you need to add a chunk, define the name\n * here.  For historical reasons these constants have the form png_<name>; i.e.\n * the prefix is lower case.  Please use decimal values as the parameters to\n * match the ISO PNG specification and to avoid relying on the C locale\n * interpretation of character values.\n *\n * Prior to 1.5.6 these constants were strings, as of 1.5.6 png_uint_32 values\n * are computed and a new macro (PNG_STRING_FROM_CHUNK) added to allow a string\n * to be generated if required.\n *\n * PNG_32b correctly produces a value shifted by up to 24 bits, even on\n * architectures where (int) is only 16 bits.\n */\n#define PNG_32b(b,s) ((png_uint_32)(b) << (s))\n#define PNG_U32(b1,b2,b3,b4) \\\n   (PNG_32b(b1,24) | PNG_32b(b2,16) | PNG_32b(b3,8) | PNG_32b(b4,0))\n\n/* Constants for known chunk types.\n *\n * MAINTAINERS: If you need to add a chunk, define the name here.\n * For historical reasons these constants have the form png_<name>; i.e.\n * the prefix is lower case.  Please use decimal values as the parameters to\n * match the ISO PNG specification and to avoid relying on the C locale\n * interpretation of character values.  Please keep the list sorted.\n *\n * Notice that PNG_U32 is used to define a 32-bit value for the 4 byte chunk\n * type.  In fact the specification does not express chunk types this way,\n * however using a 32-bit value means that the chunk type can be read from the\n * stream using exactly the same code as used for a 32-bit unsigned value and\n * can be examined far more efficiently (using one arithmetic compare).\n *\n * Prior to 1.5.6 the chunk type constants were expressed as C strings.  The\n * libpng API still uses strings for 'unknown' chunks and a macro,\n * PNG_STRING_FROM_CHUNK, allows a string to be generated if required.  Notice\n * that for portable code numeric values must still be used; the string \"IHDR\"\n * is not portable and neither is PNG_U32('I', 'H', 'D', 'R').\n *\n * In 1.7.0 the definitions will be made public in png.h to avoid having to\n * duplicate the same definitions in application code.\n */\n#define png_IDAT PNG_U32( 73,  68,  65,  84)\n#define png_IEND PNG_U32( 73,  69,  78,  68)\n#define png_IHDR PNG_U32( 73,  72,  68,  82)\n#define png_PLTE PNG_U32( 80,  76,  84,  69)\n#define png_bKGD PNG_U32( 98,  75,  71,  68)\n#define png_cHRM PNG_U32( 99,  72,  82,  77)\n#define png_fRAc PNG_U32(102,  82,  65,  99) /* registered, not defined */\n#define png_gAMA PNG_U32(103,  65,  77,  65)\n#define png_gIFg PNG_U32(103,  73,  70, 103)\n#define png_gIFt PNG_U32(103,  73,  70, 116) /* deprecated */\n#define png_gIFx PNG_U32(103,  73,  70, 120)\n#define png_hIST PNG_U32(104,  73,  83,  84)\n#define png_iCCP PNG_U32(105,  67,  67,  80)\n#define png_iTXt PNG_U32(105,  84,  88, 116)\n#define png_oFFs PNG_U32(111,  70,  70, 115)\n#define png_pCAL PNG_U32(112,  67,  65,  76)\n#define png_pHYs PNG_U32(112,  72,  89, 115)\n#define png_sBIT PNG_U32(115,  66,  73,  84)\n#define png_sCAL PNG_U32(115,  67,  65,  76)\n#define png_sPLT PNG_U32(115,  80,  76,  84)\n#define png_sRGB PNG_U32(115,  82,  71,  66)\n#define png_sTER PNG_U32(115,  84,  69,  82)\n#define png_tEXt PNG_U32(116,  69,  88, 116)\n#define png_tIME PNG_U32(116,  73,  77,  69)\n#define png_tRNS PNG_U32(116,  82,  78,  83)\n#define png_zTXt PNG_U32(122,  84,  88, 116)\n\n/* The following will work on (signed char*) strings, whereas the get_uint_32\n * macro will fail on top-bit-set values because of the sign extension.\n */\n#define PNG_CHUNK_FROM_STRING(s)\\\n   PNG_U32(0xff & (s)[0], 0xff & (s)[1], 0xff & (s)[2], 0xff & (s)[3])\n\n/* This uses (char), not (png_byte) to avoid warnings on systems where (char) is\n * signed and the argument is a (char[])  This macro will fail miserably on\n * systems where (char) is more than 8 bits.\n */\n#define PNG_STRING_FROM_CHUNK(s,c)\\\n   (void)(((char*)(s))[0]=(char)(((c)>>24) & 0xff), \\\n   ((char*)(s))[1]=(char)(((c)>>16) & 0xff),\\\n   ((char*)(s))[2]=(char)(((c)>>8) & 0xff), \\\n   ((char*)(s))[3]=(char)((c & 0xff)))\n\n/* Do the same but terminate with a null character. */\n#define PNG_CSTRING_FROM_CHUNK(s,c)\\\n   (void)(PNG_STRING_FROM_CHUNK(s,c), ((char*)(s))[4] = 0)\n\n/* Test on flag values as defined in the spec (section 5.4): */\n#define PNG_CHUNK_ANCILLARY(c)   (1 & ((c) >> 29))\n#define PNG_CHUNK_CRITICAL(c)     (!PNG_CHUNK_ANCILLARY(c))\n#define PNG_CHUNK_PRIVATE(c)      (1 & ((c) >> 21))\n#define PNG_CHUNK_RESERVED(c)     (1 & ((c) >> 13))\n#define PNG_CHUNK_SAFE_TO_COPY(c) (1 & ((c) >>  5))\n\n/* Gamma values (new at libpng-1.5.4): */\n#define PNG_GAMMA_MAC_OLD 151724  /* Assume '1.8' is really 2.2/1.45! */\n#define PNG_GAMMA_MAC_INVERSE 65909\n#define PNG_GAMMA_sRGB_INVERSE 45455\n\n/* Almost everything below is C specific; the #defines above can be used in\n * non-C code (so long as it is C-preprocessed) the rest of this stuff cannot.\n */\n#ifndef PNG_VERSION_INFO_ONLY\n\n#include \"pngstruct.h\"\n#include \"pnginfo.h\"\n\n/* Validate the include paths - the include path used to generate pnglibconf.h\n * must match that used in the build, or we must be using pnglibconf.h.prebuilt:\n */\n#if PNG_ZLIB_VERNUM != 0 && PNG_ZLIB_VERNUM != ZLIB_VERNUM\n#  error ZLIB_VERNUM != PNG_ZLIB_VERNUM \\\n      \"-I (include path) error: see the notes in pngpriv.h\"\n   /* This means that when pnglibconf.h was built the copy of zlib.h that it\n    * used is not the same as the one being used here.  Because the build of\n    * libpng makes decisions to use inflateInit2 and inflateReset2 based on the\n    * zlib version number and because this affects handling of certain broken\n    * PNG files the -I directives must match.\n    *\n    * The most likely explanation is that you passed a -I in CFLAGS. This will\n    * not work; all the preprocessor directories and in particular all the -I\n    * directives must be in CPPFLAGS.\n    */\n#endif\n\n/* This is used for 16-bit gamma tables -- only the top level pointers are\n * const; this could be changed:\n */\ntypedef const png_uint_16p * png_const_uint_16pp;\n\n/* Added to libpng-1.5.7: sRGB conversion tables */\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\\\n   defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED\nPNG_INTERNAL_DATA(const png_uint_16, png_sRGB_table, [256]);\n   /* Convert from an sRGB encoded value 0..255 to a 16-bit linear value,\n    * 0..65535.  This table gives the closest 16-bit answers (no errors).\n    */\n#endif\n\nPNG_INTERNAL_DATA(const png_uint_16, png_sRGB_base, [512]);\nPNG_INTERNAL_DATA(const png_byte, png_sRGB_delta, [512]);\n\n#define PNG_sRGB_FROM_LINEAR(linear) \\\n  ((png_byte)(0xff & ((png_sRGB_base[(linear)>>15] \\\n   + ((((linear) & 0x7fff)*png_sRGB_delta[(linear)>>15])>>12)) >> 8)))\n   /* Given a value 'linear' in the range 0..255*65535 calculate the 8-bit sRGB\n    * encoded value with maximum error 0.646365.  Note that the input is not a\n    * 16-bit value; it has been multiplied by 255! */\n#endif /* SIMPLIFIED_READ/WRITE */\n\n\n/* Inhibit C++ name-mangling for libpng functions but not for system calls. */\n#ifdef __cplusplus\nextern \"C\" {\n#endif /* __cplusplus */\n\n/* Internal functions; these are not exported from a DLL however because they\n * are used within several of the C source files they have to be C extern.\n *\n * All of these functions must be declared with PNG_INTERNAL_FUNCTION.\n */\n\n/* Zlib support */\n#define PNG_UNEXPECTED_ZLIB_RETURN (-7)\nPNG_INTERNAL_FUNCTION(void, png_zstream_error,(png_structrp png_ptr, int ret),\n   PNG_EMPTY);\n   /* Used by the zlib handling functions to ensure that z_stream::msg is always\n    * set before they return.\n    */\n\n#ifdef PNG_WRITE_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_free_buffer_list,(png_structrp png_ptr,\n   png_compression_bufferp *list),PNG_EMPTY);\n   /* Free the buffer list used by the compressed write code. */\n#endif\n\n#if defined(PNG_FLOATING_POINT_SUPPORTED) && \\\n   !defined(PNG_FIXED_POINT_MACRO_SUPPORTED) && \\\n   (defined(PNG_gAMA_SUPPORTED) || defined(PNG_cHRM_SUPPORTED) || \\\n   defined(PNG_sCAL_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)) || \\\n   (defined(PNG_sCAL_SUPPORTED) && \\\n   defined(PNG_FLOATING_ARITHMETIC_SUPPORTED))\nPNG_INTERNAL_FUNCTION(png_fixed_point,png_fixed,(png_const_structrp png_ptr,\n   double fp, png_const_charp text),PNG_EMPTY);\n#endif\n\n/* Check the user version string for compatibility, returns false if the version\n * numbers aren't compatible.\n */\nPNG_INTERNAL_FUNCTION(int,png_user_version_check,(png_structrp png_ptr,\n   png_const_charp user_png_ver),PNG_EMPTY);\n\n/* Internal base allocator - no messages, NULL on failure to allocate.  This\n * does, however, call the application provided allocator and that could call\n * png_error (although that would be a bug in the application implementation.)\n */\nPNG_INTERNAL_FUNCTION(png_voidp,png_malloc_base,(png_const_structrp png_ptr,\n   png_alloc_size_t size),PNG_ALLOCATED);\n\n#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_sPLT_SUPPORTED) ||\\\n   defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED)\n/* Internal array allocator, outputs no error or warning messages on failure,\n * just returns NULL.\n */\nPNG_INTERNAL_FUNCTION(png_voidp,png_malloc_array,(png_const_structrp png_ptr,\n   int nelements, size_t element_size),PNG_ALLOCATED);\n\n/* The same but an existing array is extended by add_elements.  This function\n * also memsets the new elements to 0 and copies the old elements.  The old\n * array is not freed or altered.\n */\nPNG_INTERNAL_FUNCTION(png_voidp,png_realloc_array,(png_const_structrp png_ptr,\n   png_const_voidp array, int old_elements, int add_elements,\n   size_t element_size),PNG_ALLOCATED);\n#endif /* text, sPLT or unknown chunks */\n\n/* Magic to create a struct when there is no struct to call the user supplied\n * memory allocators.  Because error handling has not been set up the memory\n * handlers can't safely call png_error, but this is an obscure and undocumented\n * restriction so libpng has to assume that the 'free' handler, at least, might\n * call png_error.\n */\nPNG_INTERNAL_FUNCTION(png_structp,png_create_png_struct,\n   (png_const_charp user_png_ver, png_voidp error_ptr, png_error_ptr error_fn,\n    png_error_ptr warn_fn, png_voidp mem_ptr, png_malloc_ptr malloc_fn,\n    png_free_ptr free_fn),PNG_ALLOCATED);\n\n/* Free memory from internal libpng struct */\nPNG_INTERNAL_FUNCTION(void,png_destroy_png_struct,(png_structrp png_ptr),\n   PNG_EMPTY);\n\n/* Free an allocated jmp_buf (always succeeds) */\nPNG_INTERNAL_FUNCTION(void,png_free_jmpbuf,(png_structrp png_ptr),PNG_EMPTY);\n\n/* Function to allocate memory for zlib.  PNGAPI is disallowed. */\nPNG_INTERNAL_FUNCTION(voidpf,png_zalloc,(voidpf png_ptr, uInt items, uInt size),\n   PNG_ALLOCATED);\n\n/* Function to free memory for zlib.  PNGAPI is disallowed. */\nPNG_INTERNAL_FUNCTION(void,png_zfree,(voidpf png_ptr, voidpf ptr),PNG_EMPTY);\n\n/* Next four functions are used internally as callbacks.  PNGCBAPI is required\n * but not PNG_EXPORT.  PNGAPI added at libpng version 1.2.3, changed to\n * PNGCBAPI at 1.5.0\n */\n\nPNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_read_data,(png_structp png_ptr,\n    png_bytep data, png_size_t length),PNG_EMPTY);\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\nPNG_INTERNAL_FUNCTION(void PNGCBAPI,png_push_fill_buffer,(png_structp png_ptr,\n    png_bytep buffer, png_size_t length),PNG_EMPTY);\n#endif\n\nPNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_write_data,(png_structp png_ptr,\n    png_bytep data, png_size_t length),PNG_EMPTY);\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n#  ifdef PNG_STDIO_SUPPORTED\nPNG_INTERNAL_FUNCTION(void PNGCBAPI,png_default_flush,(png_structp png_ptr),\n   PNG_EMPTY);\n#  endif\n#endif\n\n/* Reset the CRC variable */\nPNG_INTERNAL_FUNCTION(void,png_reset_crc,(png_structrp png_ptr),PNG_EMPTY);\n\n/* Write the \"data\" buffer to whatever output you are using */\nPNG_INTERNAL_FUNCTION(void,png_write_data,(png_structrp png_ptr,\n    png_const_bytep data, png_size_t length),PNG_EMPTY);\n\n/* Read and check the PNG file signature */\nPNG_INTERNAL_FUNCTION(void,png_read_sig,(png_structrp png_ptr,\n   png_inforp info_ptr),PNG_EMPTY);\n\n/* Read the chunk header (length + type name) */\nPNG_INTERNAL_FUNCTION(png_uint_32,png_read_chunk_header,(png_structrp png_ptr),\n   PNG_EMPTY);\n\n/* Read data from whatever input you are using into the \"data\" buffer */\nPNG_INTERNAL_FUNCTION(void,png_read_data,(png_structrp png_ptr, png_bytep data,\n    png_size_t length),PNG_EMPTY);\n\n/* Read bytes into buf, and update png_ptr->crc */\nPNG_INTERNAL_FUNCTION(void,png_crc_read,(png_structrp png_ptr, png_bytep buf,\n    png_uint_32 length),PNG_EMPTY);\n\n/* Read \"skip\" bytes, read the file crc, and (optionally) verify png_ptr->crc */\nPNG_INTERNAL_FUNCTION(int,png_crc_finish,(png_structrp png_ptr,\n   png_uint_32 skip),PNG_EMPTY);\n\n/* Read the CRC from the file and compare it to the libpng calculated CRC */\nPNG_INTERNAL_FUNCTION(int,png_crc_error,(png_structrp png_ptr),PNG_EMPTY);\n\n/* Calculate the CRC over a section of data.  Note that we are only\n * passing a maximum of 64K on systems that have this as a memory limit,\n * since this is the maximum buffer size we can specify.\n */\nPNG_INTERNAL_FUNCTION(void,png_calculate_crc,(png_structrp png_ptr,\n   png_const_bytep ptr, png_size_t length),PNG_EMPTY);\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_flush,(png_structrp png_ptr),PNG_EMPTY);\n#endif\n\n/* Write various chunks */\n\n/* Write the IHDR chunk, and update the png_struct with the necessary\n * information.\n */\nPNG_INTERNAL_FUNCTION(void,png_write_IHDR,(png_structrp png_ptr,\n   png_uint_32 width, png_uint_32 height, int bit_depth, int color_type,\n   int compression_method, int filter_method, int interlace_method),PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(void,png_write_PLTE,(png_structrp png_ptr,\n   png_const_colorp palette, png_uint_32 num_pal),PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(void,png_compress_IDAT,(png_structrp png_ptr,\n   png_const_bytep row_data, png_alloc_size_t row_data_length, int flush),\n   PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(void,png_write_IEND,(png_structrp png_ptr),PNG_EMPTY);\n\n#ifdef PNG_WRITE_gAMA_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_gAMA_fixed,(png_structrp png_ptr,\n    png_fixed_point file_gamma),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_sBIT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_sBIT,(png_structrp png_ptr,\n    png_const_color_8p sbit, int color_type),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_cHRM_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_cHRM_fixed,(png_structrp png_ptr,\n    const png_xy *xy), PNG_EMPTY);\n   /* The xy value must have been previously validated */\n#endif\n\n#ifdef PNG_WRITE_sRGB_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_sRGB,(png_structrp png_ptr,\n    int intent),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_iCCP_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_iCCP,(png_structrp png_ptr,\n   png_const_charp name, png_const_bytep profile), PNG_EMPTY);\n   /* The profile must have been previously validated for correctness, the\n    * length comes from the first four bytes.  Only the base, deflate,\n    * compression is supported.\n    */\n#endif\n\n#ifdef PNG_WRITE_sPLT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_sPLT,(png_structrp png_ptr,\n    png_const_sPLT_tp palette),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_tRNS_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_tRNS,(png_structrp png_ptr,\n    png_const_bytep trans, png_const_color_16p values, int number,\n    int color_type),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_bKGD_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_bKGD,(png_structrp png_ptr,\n    png_const_color_16p values, int color_type),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_hIST_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_hIST,(png_structrp png_ptr,\n    png_const_uint_16p hist, int num_hist),PNG_EMPTY);\n#endif\n\n/* Chunks that have keywords */\n#ifdef PNG_WRITE_tEXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_tEXt,(png_structrp png_ptr,\n   png_const_charp key, png_const_charp text, png_size_t text_len),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_zTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_zTXt,(png_structrp png_ptr, png_const_charp\n    key, png_const_charp text, int compression),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_iTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_iTXt,(png_structrp png_ptr,\n    int compression, png_const_charp key, png_const_charp lang,\n    png_const_charp lang_key, png_const_charp text),PNG_EMPTY);\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED  /* Added at version 1.0.14 and 1.2.4 */\nPNG_INTERNAL_FUNCTION(int,png_set_text_2,(png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_textp text_ptr, int num_text),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_oFFs_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_oFFs,(png_structrp png_ptr,\n    png_int_32 x_offset, png_int_32 y_offset, int unit_type),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_pCAL_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_pCAL,(png_structrp png_ptr,\n    png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,\n    png_const_charp units, png_charpp params),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_pHYs_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_pHYs,(png_structrp png_ptr,\n    png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,\n    int unit_type),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_tIME_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_tIME,(png_structrp png_ptr,\n    png_const_timep mod_time),PNG_EMPTY);\n#endif\n\n#ifdef PNG_WRITE_sCAL_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_write_sCAL_s,(png_structrp png_ptr,\n    int unit, png_const_charp width, png_const_charp height),PNG_EMPTY);\n#endif\n\n/* Called when finished processing a row of data */\nPNG_INTERNAL_FUNCTION(void,png_write_finish_row,(png_structrp png_ptr),\n    PNG_EMPTY);\n\n/* Internal use only.   Called before first row of data */\nPNG_INTERNAL_FUNCTION(void,png_write_start_row,(png_structrp png_ptr),\n    PNG_EMPTY);\n\n/* Combine a row of data, dealing with alpha, etc. if requested.  'row' is an\n * array of png_ptr->width pixels.  If the image is not interlaced or this\n * is the final pass this just does a memcpy, otherwise the \"display\" flag\n * is used to determine whether to copy pixels that are not in the current pass.\n *\n * Because 'png_do_read_interlace' (below) replicates pixels this allows this\n * function to achieve the documented 'blocky' appearance during interlaced read\n * if display is 1 and the 'sparkle' appearance, where existing pixels in 'row'\n * are not changed if they are not in the current pass, when display is 0.\n *\n * 'display' must be 0 or 1, otherwise the memcpy will be done regardless.\n *\n * The API always reads from the png_struct row buffer and always assumes that\n * it is full width (png_do_read_interlace has already been called.)\n *\n * This function is only ever used to write to row buffers provided by the\n * caller of the relevant libpng API and the row must have already been\n * transformed by the read transformations.\n *\n * The PNG_USE_COMPILE_TIME_MASKS option causes generation of pre-computed\n * bitmasks for use within the code, otherwise runtime generated masks are used.\n * The default is compile time masks.\n */\n#ifndef PNG_USE_COMPILE_TIME_MASKS\n#  define PNG_USE_COMPILE_TIME_MASKS 1\n#endif\nPNG_INTERNAL_FUNCTION(void,png_combine_row,(png_const_structrp png_ptr,\n    png_bytep row, int display),PNG_EMPTY);\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n/* Expand an interlaced row: the 'row_info' describes the pass data that has\n * been read in and must correspond to the pixels in 'row', the pixels are\n * expanded (moved apart) in 'row' to match the final layout, when doing this\n * the pixels are *replicated* to the intervening space.  This is essential for\n * the correct operation of png_combine_row, above.\n */\nPNG_INTERNAL_FUNCTION(void,png_do_read_interlace,(png_row_infop row_info,\n    png_bytep row, int pass, png_uint_32 transformations),PNG_EMPTY);\n#endif\n\n/* GRR TO DO (2.0 or whenever):  simplify other internal calling interfaces */\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n/* Grab pixels out of a row for an interlaced pass */\nPNG_INTERNAL_FUNCTION(void,png_do_write_interlace,(png_row_infop row_info,\n    png_bytep row, int pass),PNG_EMPTY);\n#endif\n\n/* Unfilter a row: check the filter value before calling this, there is no point\n * calling it for PNG_FILTER_VALUE_NONE.\n */\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row,(png_structrp pp, png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row, int filter),PNG_EMPTY);\n\n#if PNG_ARM_NEON_OPT > 0\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_neon,(png_row_infop row_info,\n    png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_neon,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n#endif\n\n#if PNG_MIPS_MSA_OPT > 0\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_up_msa,(png_row_infop row_info,\n    png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_msa,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n#endif\n\n#if PNG_INTEL_SSE_IMPLEMENTATION > 0\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_sub4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_avg4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth3_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_filter_row_paeth4_sse2,(png_row_infop\n    row_info, png_bytep row, png_const_bytep prev_row),PNG_EMPTY);\n#endif\n\n/* Choose the best filter to use and filter the row data */\nPNG_INTERNAL_FUNCTION(void,png_write_find_filter,(png_structrp png_ptr,\n    png_row_infop row_info),PNG_EMPTY);\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_read_IDAT_data,(png_structrp png_ptr,\n   png_bytep output, png_alloc_size_t avail_out),PNG_EMPTY);\n   /* Read 'avail_out' bytes of data from the IDAT stream.  If the output buffer\n    * is NULL the function checks, instead, for the end of the stream.  In this\n    * case a benign error will be issued if the stream end is not found or if\n    * extra data has to be consumed.\n    */\nPNG_INTERNAL_FUNCTION(void,png_read_finish_IDAT,(png_structrp png_ptr),\n   PNG_EMPTY);\n   /* This cleans up when the IDAT LZ stream does not end when the last image\n    * byte is read; there is still some pending input.\n    */\n\nPNG_INTERNAL_FUNCTION(void,png_read_finish_row,(png_structrp png_ptr),\n   PNG_EMPTY);\n   /* Finish a row while reading, dealing with interlacing passes, etc. */\n#endif /* SEQUENTIAL_READ */\n\n/* Initialize the row buffers, etc. */\nPNG_INTERNAL_FUNCTION(void,png_read_start_row,(png_structrp png_ptr),PNG_EMPTY);\n\n#if PNG_ZLIB_VERNUM >= 0x1240\nPNG_INTERNAL_FUNCTION(int,png_zlib_inflate,(png_structrp png_ptr, int flush),\n      PNG_EMPTY);\n#  define PNG_INFLATE(pp, flush) png_zlib_inflate(pp, flush)\n#else /* Zlib < 1.2.4 */\n#  define PNG_INFLATE(pp, flush) inflate(&(pp)->zstream, flush)\n#endif /* Zlib < 1.2.4 */\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n/* Optional call to update the users info structure */\nPNG_INTERNAL_FUNCTION(void,png_read_transform_info,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\n#endif\n\n/* Shared transform functions, defined in pngtran.c */\n#if defined(PNG_WRITE_FILLER_SUPPORTED) || \\\n    defined(PNG_READ_STRIP_ALPHA_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_strip_channel,(png_row_infop row_info,\n    png_bytep row, int at_start),PNG_EMPTY);\n#endif\n\n#ifdef PNG_16BIT_SUPPORTED\n#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_swap,(png_row_infop row_info,\n    png_bytep row),PNG_EMPTY);\n#endif\n#endif\n\n#if defined(PNG_READ_PACKSWAP_SUPPORTED) || \\\n    defined(PNG_WRITE_PACKSWAP_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_packswap,(png_row_infop row_info,\n    png_bytep row),PNG_EMPTY);\n#endif\n\n#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_invert,(png_row_infop row_info,\n    png_bytep row),PNG_EMPTY);\n#endif\n\n#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_bgr,(png_row_infop row_info,\n    png_bytep row),PNG_EMPTY);\n#endif\n\n/* The following decodes the appropriate chunks, and does error correction,\n * then calls the appropriate callback for the chunk if it is valid.\n */\n\n/* Decode the IHDR chunk */\nPNG_INTERNAL_FUNCTION(void,png_handle_IHDR,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_handle_PLTE,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_handle_IEND,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n\n#ifdef PNG_READ_bKGD_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_bKGD,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_cHRM_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_cHRM,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_gAMA_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_gAMA,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_hIST_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_hIST,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_iCCP_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_iCCP,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif /* READ_iCCP */\n\n#ifdef PNG_READ_iTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_iTXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_oFFs_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_oFFs,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_pCAL_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_pCAL,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_pHYs_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_pHYs,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_sBIT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_sBIT,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_sCAL_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_sCAL,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_sPLT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_sPLT,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif /* READ_sPLT */\n\n#ifdef PNG_READ_sRGB_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_sRGB,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_tEXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_tEXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_tIME_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_tIME,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_tRNS_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_tRNS,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_zTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_handle_zTXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\n#endif\n\nPNG_INTERNAL_FUNCTION(void,png_check_chunk_name,(png_structrp png_ptr,\n    png_uint_32 chunk_name),PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(void,png_handle_unknown,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length, int keep),PNG_EMPTY);\n   /* This is the function that gets called for unknown chunks.  The 'keep'\n    * argument is either non-zero for a known chunk that has been set to be\n    * handled as unknown or zero for an unknown chunk.  By default the function\n    * just skips the chunk or errors out if it is critical.\n    */\n\n#if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) ||\\\n    defined(PNG_HANDLE_AS_UNKNOWN_SUPPORTED)\nPNG_INTERNAL_FUNCTION(int,png_chunk_unknown_handling,\n    (png_const_structrp png_ptr, png_uint_32 chunk_name),PNG_EMPTY);\n   /* Exactly as the API png_handle_as_unknown() except that the argument is a\n    * 32-bit chunk name, not a string.\n    */\n#endif /* READ_UNKNOWN_CHUNKS || HANDLE_AS_UNKNOWN */\n\n/* Handle the transformations for reading and writing */\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_do_read_transformations,(png_structrp png_ptr,\n   png_row_infop row_info),PNG_EMPTY);\n#endif\n#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_do_write_transformations,(png_structrp png_ptr,\n   png_row_infop row_info),PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_init_read_transformations,(png_structrp png_ptr),\n    PNG_EMPTY);\n#endif\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_push_read_chunk,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_sig,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_check_crc,(png_structrp png_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_save_buffer,(png_structrp png_ptr),\n    PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_restore_buffer,(png_structrp png_ptr,\n    png_bytep buffer, png_size_t buffer_length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_IDAT,(png_structrp png_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_process_IDAT_data,(png_structrp png_ptr,\n    png_bytep buffer, png_size_t buffer_length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_process_row,(png_structrp png_ptr),\n    PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_handle_unknown,(png_structrp png_ptr,\n   png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_have_info,(png_structrp png_ptr,\n   png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_have_end,(png_structrp png_ptr,\n   png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_have_row,(png_structrp png_ptr,\n    png_bytep row),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_end,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_process_some_data,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_read_push_finish_row,(png_structrp png_ptr),\n    PNG_EMPTY);\n#  ifdef PNG_READ_tEXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_push_handle_tEXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_tEXt,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\n#  endif\n#  ifdef PNG_READ_zTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_push_handle_zTXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_zTXt,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\n#  endif\n#  ifdef PNG_READ_iTXt_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_push_handle_iTXt,(png_structrp png_ptr,\n    png_inforp info_ptr, png_uint_32 length),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_push_read_iTXt,(png_structrp png_ptr,\n    png_inforp info_ptr),PNG_EMPTY);\n#  endif\n\n#endif /* PROGRESSIVE_READ */\n\n/* Added at libpng version 1.6.0 */\n#ifdef PNG_GAMMA_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_colorspace_set_gamma,(png_const_structrp png_ptr,\n    png_colorspacerp colorspace, png_fixed_point gAMA), PNG_EMPTY);\n   /* Set the colorspace gamma with a value provided by the application or by\n    * the gAMA chunk on read.  The value will override anything set by an ICC\n    * profile.\n    */\n\nPNG_INTERNAL_FUNCTION(void,png_colorspace_sync_info,(png_const_structrp png_ptr,\n    png_inforp info_ptr), PNG_EMPTY);\n   /* Synchronize the info 'valid' flags with the colorspace */\n\nPNG_INTERNAL_FUNCTION(void,png_colorspace_sync,(png_const_structrp png_ptr,\n    png_inforp info_ptr), PNG_EMPTY);\n   /* Copy the png_struct colorspace to the info_struct and call the above to\n    * synchronize the flags.  Checks for NULL info_ptr and does nothing.\n    */\n#endif\n\n/* Added at libpng version 1.4.0 */\n#ifdef PNG_COLORSPACE_SUPPORTED\n/* These internal functions are for maintaining the colorspace structure within\n * a png_info or png_struct (or, indeed, both).\n */\nPNG_INTERNAL_FUNCTION(int,png_colorspace_set_chromaticities,\n   (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_xy *xy,\n    int preferred), PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(int,png_colorspace_set_endpoints,\n   (png_const_structrp png_ptr, png_colorspacerp colorspace, const png_XYZ *XYZ,\n    int preferred), PNG_EMPTY);\n\n#ifdef PNG_sRGB_SUPPORTED\nPNG_INTERNAL_FUNCTION(int,png_colorspace_set_sRGB,(png_const_structrp png_ptr,\n   png_colorspacerp colorspace, int intent), PNG_EMPTY);\n   /* This does set the colorspace gAMA and cHRM values too, but doesn't set the\n    * flags to write them, if it returns false there was a problem and an error\n    * message has already been output (but the colorspace may still need to be\n    * synced to record the invalid flag).\n    */\n#endif /* sRGB */\n\n#ifdef PNG_iCCP_SUPPORTED\nPNG_INTERNAL_FUNCTION(int,png_colorspace_set_ICC,(png_const_structrp png_ptr,\n   png_colorspacerp colorspace, png_const_charp name,\n   png_uint_32 profile_length, png_const_bytep profile, int color_type),\n   PNG_EMPTY);\n   /* The 'name' is used for information only */\n\n/* Routines for checking parts of an ICC profile. */\n#ifdef PNG_READ_iCCP_SUPPORTED\nPNG_INTERNAL_FUNCTION(int,png_icc_check_length,(png_const_structrp png_ptr,\n   png_colorspacerp colorspace, png_const_charp name,\n   png_uint_32 profile_length), PNG_EMPTY);\n#endif /* READ_iCCP */\nPNG_INTERNAL_FUNCTION(int,png_icc_check_header,(png_const_structrp png_ptr,\n   png_colorspacerp colorspace, png_const_charp name,\n   png_uint_32 profile_length,\n   png_const_bytep profile /* first 132 bytes only */, int color_type),\n   PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(int,png_icc_check_tag_table,(png_const_structrp png_ptr,\n   png_colorspacerp colorspace, png_const_charp name,\n   png_uint_32 profile_length,\n   png_const_bytep profile /* header plus whole tag table */), PNG_EMPTY);\n#ifdef PNG_sRGB_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_icc_set_sRGB,(\n   png_const_structrp png_ptr, png_colorspacerp colorspace,\n   png_const_bytep profile, uLong adler), PNG_EMPTY);\n   /* 'adler' is the Adler32 checksum of the uncompressed profile data. It may\n    * be zero to indicate that it is not available.  It is used, if provided,\n    * as a fast check on the profile when checking to see if it is sRGB.\n    */\n#endif\n#endif /* iCCP */\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_colorspace_set_rgb_coefficients,\n   (png_structrp png_ptr), PNG_EMPTY);\n   /* Set the rgb_to_gray coefficients from the colorspace Y values */\n#endif /* READ_RGB_TO_GRAY */\n#endif /* COLORSPACE */\n\n/* Added at libpng version 1.4.0 */\nPNG_INTERNAL_FUNCTION(void,png_check_IHDR,(png_const_structrp png_ptr,\n    png_uint_32 width, png_uint_32 height, int bit_depth,\n    int color_type, int interlace_type, int compression_type,\n    int filter_type),PNG_EMPTY);\n\n/* Added at libpng version 1.5.10 */\n#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \\\n    defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_do_check_palette_indexes,\n   (png_structrp png_ptr, png_row_infop row_info),PNG_EMPTY);\n#endif\n\n#if defined(PNG_FLOATING_POINT_SUPPORTED) && defined(PNG_ERROR_TEXT_SUPPORTED)\nPNG_INTERNAL_FUNCTION(void,png_fixed_error,(png_const_structrp png_ptr,\n   png_const_charp name),PNG_NORETURN);\n#endif\n\n/* Puts 'string' into 'buffer' at buffer[pos], taking care never to overwrite\n * the end.  Always leaves the buffer nul terminated.  Never errors out (and\n * there is no error code.)\n */\nPNG_INTERNAL_FUNCTION(size_t,png_safecat,(png_charp buffer, size_t bufsize,\n   size_t pos, png_const_charp string),PNG_EMPTY);\n\n/* Various internal functions to handle formatted warning messages, currently\n * only implemented for warnings.\n */\n#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_TIME_RFC1123_SUPPORTED)\n/* Utility to dump an unsigned value into a buffer, given a start pointer and\n * and end pointer (which should point just *beyond* the end of the buffer!)\n * Returns the pointer to the start of the formatted string.  This utility only\n * does unsigned values.\n */\nPNG_INTERNAL_FUNCTION(png_charp,png_format_number,(png_const_charp start,\n   png_charp end, int format, png_alloc_size_t number),PNG_EMPTY);\n\n/* Convenience macro that takes an array: */\n#define PNG_FORMAT_NUMBER(buffer,format,number) \\\n   png_format_number(buffer, buffer + (sizeof buffer), format, number)\n\n/* Suggested size for a number buffer (enough for 64 bits and a sign!) */\n#define PNG_NUMBER_BUFFER_SIZE 24\n\n/* These are the integer formats currently supported, the name is formed from\n * the standard printf(3) format string.\n */\n#define PNG_NUMBER_FORMAT_u     1 /* chose unsigned API! */\n#define PNG_NUMBER_FORMAT_02u   2\n#define PNG_NUMBER_FORMAT_d     1 /* chose signed API! */\n#define PNG_NUMBER_FORMAT_02d   2\n#define PNG_NUMBER_FORMAT_x     3\n#define PNG_NUMBER_FORMAT_02x   4\n#define PNG_NUMBER_FORMAT_fixed 5 /* choose the signed API */\n#endif\n\n#ifdef PNG_WARNINGS_SUPPORTED\n/* New defines and members adding in libpng-1.5.4 */\n#  define PNG_WARNING_PARAMETER_SIZE 32\n#  define PNG_WARNING_PARAMETER_COUNT 8 /* Maximum 9; see pngerror.c */\n\n/* An l-value of this type has to be passed to the APIs below to cache the\n * values of the parameters to a formatted warning message.\n */\ntypedef char png_warning_parameters[PNG_WARNING_PARAMETER_COUNT][\n   PNG_WARNING_PARAMETER_SIZE];\n\nPNG_INTERNAL_FUNCTION(void,png_warning_parameter,(png_warning_parameters p,\n   int number, png_const_charp string),PNG_EMPTY);\n   /* Parameters are limited in size to PNG_WARNING_PARAMETER_SIZE characters,\n    * including the trailing '\\0'.\n    */\nPNG_INTERNAL_FUNCTION(void,png_warning_parameter_unsigned,\n   (png_warning_parameters p, int number, int format, png_alloc_size_t value),\n   PNG_EMPTY);\n   /* Use png_alloc_size_t because it is an unsigned type as big as any we\n    * need to output.  Use the following for a signed value.\n    */\nPNG_INTERNAL_FUNCTION(void,png_warning_parameter_signed,\n   (png_warning_parameters p, int number, int format, png_int_32 value),\n   PNG_EMPTY);\n\nPNG_INTERNAL_FUNCTION(void,png_formatted_warning,(png_const_structrp png_ptr,\n   png_warning_parameters p, png_const_charp message),PNG_EMPTY);\n   /* 'message' follows the X/Open approach of using @1, @2 to insert\n    * parameters previously supplied using the above functions.  Errors in\n    * specifying the parameters will simply result in garbage substitutions.\n    */\n#endif\n\n#ifdef PNG_BENIGN_ERRORS_SUPPORTED\n/* Application errors (new in 1.6); use these functions (declared below) for\n * errors in the parameters or order of API function calls on read.  The\n * 'warning' should be used for an error that can be handled completely; the\n * 'error' for one which can be handled safely but which may lose application\n * information or settings.\n *\n * By default these both result in a png_error call prior to release, while in a\n * released version the 'warning' is just a warning.  However if the application\n * explicitly disables benign errors (explicitly permitting the code to lose\n * information) they both turn into warnings.\n *\n * If benign errors aren't supported they end up as the corresponding base call\n * (png_warning or png_error.)\n */\nPNG_INTERNAL_FUNCTION(void,png_app_warning,(png_const_structrp png_ptr,\n   png_const_charp message),PNG_EMPTY);\n   /* The application provided invalid parameters to an API function or called\n    * an API function at the wrong time, libpng can completely recover.\n    */\n\nPNG_INTERNAL_FUNCTION(void,png_app_error,(png_const_structrp png_ptr,\n   png_const_charp message),PNG_EMPTY);\n   /* As above but libpng will ignore the call, or attempt some other partial\n    * recovery from the error.\n    */\n#else\n#  define png_app_warning(pp,s) png_warning(pp,s)\n#  define png_app_error(pp,s) png_error(pp,s)\n#endif\n\nPNG_INTERNAL_FUNCTION(void,png_chunk_report,(png_const_structrp png_ptr,\n   png_const_charp message, int error),PNG_EMPTY);\n   /* Report a recoverable issue in chunk data.  On read this is used to report\n    * a problem found while reading a particular chunk and the\n    * png_chunk_benign_error or png_chunk_warning function is used as\n    * appropriate.  On write this is used to report an error that comes from\n    * data set via an application call to a png_set_ API and png_app_error or\n    * png_app_warning is used as appropriate.\n    *\n    * The 'error' parameter must have one of the following values:\n    */\n#define PNG_CHUNK_WARNING     0 /* never an error */\n#define PNG_CHUNK_WRITE_ERROR 1 /* an error only on write */\n#define PNG_CHUNK_ERROR       2 /* always an error */\n\n/* ASCII to FP interfaces, currently only implemented if sCAL\n * support is required.\n */\n#if defined(PNG_sCAL_SUPPORTED)\n/* MAX_DIGITS is actually the maximum number of characters in an sCAL\n * width or height, derived from the precision (number of significant\n * digits - a build time settable option) and assumptions about the\n * maximum ridiculous exponent.\n */\n#define PNG_sCAL_MAX_DIGITS (PNG_sCAL_PRECISION+1/*.*/+1/*E*/+10/*exponent*/)\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_ascii_from_fp,(png_const_structrp png_ptr,\n   png_charp ascii, png_size_t size, double fp, unsigned int precision),\n   PNG_EMPTY);\n#endif /* FLOATING_POINT */\n\n#ifdef PNG_FIXED_POINT_SUPPORTED\nPNG_INTERNAL_FUNCTION(void,png_ascii_from_fixed,(png_const_structrp png_ptr,\n   png_charp ascii, png_size_t size, png_fixed_point fp),PNG_EMPTY);\n#endif /* FIXED_POINT */\n#endif /* sCAL */\n\n#if defined(PNG_sCAL_SUPPORTED) || defined(PNG_pCAL_SUPPORTED)\n/* An internal API to validate the format of a floating point number.\n * The result is the index of the next character.  If the number is\n * not valid it will be the index of a character in the supposed number.\n *\n * The format of a number is defined in the PNG extensions specification\n * and this API is strictly conformant to that spec, not anyone elses!\n *\n * The format as a regular expression is:\n *\n * [+-]?[0-9]+.?([Ee][+-]?[0-9]+)?\n *\n * or:\n *\n * [+-]?.[0-9]+(.[0-9]+)?([Ee][+-]?[0-9]+)?\n *\n * The complexity is that either integer or fraction must be present and the\n * fraction is permitted to have no digits only if the integer is present.\n *\n * NOTE: The dangling E problem.\n *   There is a PNG valid floating point number in the following:\n *\n *       PNG floating point numbers are not greedy.\n *\n *   Working this out requires *TWO* character lookahead (because of the\n *   sign), the parser does not do this - it will fail at the 'r' - this\n *   doesn't matter for PNG sCAL chunk values, but it requires more care\n *   if the value were ever to be embedded in something more complex.  Use\n *   ANSI-C strtod if you need the lookahead.\n */\n/* State table for the parser. */\n#define PNG_FP_INTEGER    0  /* before or in integer */\n#define PNG_FP_FRACTION   1  /* before or in fraction */\n#define PNG_FP_EXPONENT   2  /* before or in exponent */\n#define PNG_FP_STATE      3  /* mask for the above */\n#define PNG_FP_SAW_SIGN   4  /* Saw +/- in current state */\n#define PNG_FP_SAW_DIGIT  8  /* Saw a digit in current state */\n#define PNG_FP_SAW_DOT   16  /* Saw a dot in current state */\n#define PNG_FP_SAW_E     32  /* Saw an E (or e) in current state */\n#define PNG_FP_SAW_ANY   60  /* Saw any of the above 4 */\n\n/* These three values don't affect the parser.  They are set but not used.\n */\n#define PNG_FP_WAS_VALID 64  /* Preceding substring is a valid fp number */\n#define PNG_FP_NEGATIVE 128  /* A negative number, including \"-0\" */\n#define PNG_FP_NONZERO  256  /* A non-zero value */\n#define PNG_FP_STICKY   448  /* The above three flags */\n\n/* This is available for the caller to store in 'state' if required.  Do not\n * call the parser after setting it (the parser sometimes clears it.)\n */\n#define PNG_FP_INVALID  512  /* Available for callers as a distinct value */\n\n/* Result codes for the parser (boolean - true meants ok, false means\n * not ok yet.)\n */\n#define PNG_FP_MAYBE      0  /* The number may be valid in the future */\n#define PNG_FP_OK         1  /* The number is valid */\n\n/* Tests on the sticky non-zero and negative flags.  To pass these checks\n * the state must also indicate that the whole number is valid - this is\n * achieved by testing PNG_FP_SAW_DIGIT (see the implementation for why this\n * is equivalent to PNG_FP_OK above.)\n */\n#define PNG_FP_NZ_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NEGATIVE | PNG_FP_NONZERO)\n   /* NZ_MASK: the string is valid and a non-zero negative value */\n#define PNG_FP_Z_MASK (PNG_FP_SAW_DIGIT | PNG_FP_NONZERO)\n   /* Z MASK: the string is valid and a non-zero value. */\n   /* PNG_FP_SAW_DIGIT: the string is valid. */\n#define PNG_FP_IS_ZERO(state) (((state) & PNG_FP_Z_MASK) == PNG_FP_SAW_DIGIT)\n#define PNG_FP_IS_POSITIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_Z_MASK)\n#define PNG_FP_IS_NEGATIVE(state) (((state) & PNG_FP_NZ_MASK) == PNG_FP_NZ_MASK)\n\n/* The actual parser.  This can be called repeatedly. It updates\n * the index into the string and the state variable (which must\n * be initialized to 0).  It returns a result code, as above.  There\n * is no point calling the parser any more if it fails to advance to\n * the end of the string - it is stuck on an invalid character (or\n * terminated by '\\0').\n *\n * Note that the pointer will consume an E or even an E+ and then leave\n * a 'maybe' state even though a preceding integer.fraction is valid.\n * The PNG_FP_WAS_VALID flag indicates that a preceding substring was\n * a valid number.  It's possible to recover from this by calling\n * the parser again (from the start, with state 0) but with a string\n * that omits the last character (i.e. set the size to the index of\n * the problem character.)  This has not been tested within libpng.\n */\nPNG_INTERNAL_FUNCTION(int,png_check_fp_number,(png_const_charp string,\n   png_size_t size, int *statep, png_size_tp whereami),PNG_EMPTY);\n\n/* This is the same but it checks a complete string and returns true\n * only if it just contains a floating point number.  As of 1.5.4 this\n * function also returns the state at the end of parsing the number if\n * it was valid (otherwise it returns 0.)  This can be used for testing\n * for negative or zero values using the sticky flag.\n */\nPNG_INTERNAL_FUNCTION(int,png_check_fp_string,(png_const_charp string,\n   png_size_t size),PNG_EMPTY);\n#endif /* pCAL || sCAL */\n\n#if defined(PNG_GAMMA_SUPPORTED) ||\\\n    defined(PNG_INCH_CONVERSIONS_SUPPORTED) || defined(PNG_READ_pHYs_SUPPORTED)\n/* Added at libpng version 1.5.0 */\n/* This is a utility to provide a*times/div (rounded) and indicate\n * if there is an overflow.  The result is a boolean - false (0)\n * for overflow, true (1) if no overflow, in which case *res\n * holds the result.\n */\nPNG_INTERNAL_FUNCTION(int,png_muldiv,(png_fixed_point_p res, png_fixed_point a,\n   png_int_32 multiplied_by, png_int_32 divided_by),PNG_EMPTY);\n#endif\n\n#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_INCH_CONVERSIONS_SUPPORTED)\n/* Same deal, but issue a warning on overflow and return 0. */\nPNG_INTERNAL_FUNCTION(png_fixed_point,png_muldiv_warn,\n   (png_const_structrp png_ptr, png_fixed_point a, png_int_32 multiplied_by,\n   png_int_32 divided_by),PNG_EMPTY);\n#endif\n\n#ifdef PNG_GAMMA_SUPPORTED\n/* Calculate a reciprocal - used for gamma values.  This returns\n * 0 if the argument is 0 in order to maintain an undefined value;\n * there are no warnings.\n */\nPNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal,(png_fixed_point a),\n   PNG_EMPTY);\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* The same but gives a reciprocal of the product of two fixed point\n * values.  Accuracy is suitable for gamma calculations but this is\n * not exact - use png_muldiv for that.  Only required at present on read.\n */\nPNG_INTERNAL_FUNCTION(png_fixed_point,png_reciprocal2,(png_fixed_point a,\n   png_fixed_point b),PNG_EMPTY);\n#endif\n\n/* Return true if the gamma value is significantly different from 1.0 */\nPNG_INTERNAL_FUNCTION(int,png_gamma_significant,(png_fixed_point gamma_value),\n   PNG_EMPTY);\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* Internal fixed point gamma correction.  These APIs are called as\n * required to convert single values - they don't need to be fast,\n * they are not used when processing image pixel values.\n *\n * While the input is an 'unsigned' value it must actually be the\n * correct bit value - 0..255 or 0..65535 as required.\n */\nPNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_correct,(png_structrp png_ptr,\n   unsigned int value, png_fixed_point gamma_value),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(png_uint_16,png_gamma_16bit_correct,(unsigned int value,\n   png_fixed_point gamma_value),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(png_byte,png_gamma_8bit_correct,(unsigned int value,\n   png_fixed_point gamma_value),PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_destroy_gamma_table,(png_structrp png_ptr),\n   PNG_EMPTY);\nPNG_INTERNAL_FUNCTION(void,png_build_gamma_table,(png_structrp png_ptr,\n   int bit_depth),PNG_EMPTY);\n#endif\n\n/* SIMPLIFIED READ/WRITE SUPPORT */\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) ||\\\n   defined(PNG_SIMPLIFIED_WRITE_SUPPORTED)\n/* The internal structure that png_image::opaque points to. */\ntypedef struct png_control\n{\n   png_structp png_ptr;\n   png_infop   info_ptr;\n   png_voidp   error_buf;           /* Always a jmp_buf at present. */\n\n   png_const_bytep memory;          /* Memory buffer. */\n   png_size_t      size;            /* Size of the memory buffer. */\n\n   unsigned int for_write       :1; /* Otherwise it is a read structure */\n   unsigned int owned_file      :1; /* We own the file in io_ptr */\n} png_control;\n\n/* Return the pointer to the jmp_buf from a png_control: necessary because C\n * does not reveal the type of the elements of jmp_buf.\n */\n#ifdef __cplusplus\n#  define png_control_jmp_buf(pc) (((jmp_buf*)((pc)->error_buf))[0])\n#else\n#  define png_control_jmp_buf(pc) ((pc)->error_buf)\n#endif\n\n/* Utility to safely execute a piece of libpng code catching and logging any\n * errors that might occur.  Returns true on success, false on failure (either\n * of the function or as a result of a png_error.)\n */\nPNG_INTERNAL_CALLBACK(void,png_safe_error,(png_structp png_ptr,\n   png_const_charp error_message),PNG_NORETURN);\n\n#ifdef PNG_WARNINGS_SUPPORTED\nPNG_INTERNAL_CALLBACK(void,png_safe_warning,(png_structp png_ptr,\n   png_const_charp warning_message),PNG_EMPTY);\n#else\n#  define png_safe_warning 0/*dummy argument*/\n#endif\n\nPNG_INTERNAL_FUNCTION(int,png_safe_execute,(png_imagep image,\n   int (*function)(png_voidp), png_voidp arg),PNG_EMPTY);\n\n/* Utility to log an error; this also cleans up the png_image; the function\n * always returns 0 (false).\n */\nPNG_INTERNAL_FUNCTION(int,png_image_error,(png_imagep image,\n   png_const_charp error_message),PNG_EMPTY);\n\n#ifndef PNG_SIMPLIFIED_READ_SUPPORTED\n/* png_image_free is used by the write code but not exported */\nPNG_INTERNAL_FUNCTION(void, png_image_free, (png_imagep image), PNG_EMPTY);\n#endif /* !SIMPLIFIED_READ */\n\n#endif /* SIMPLIFIED READ/WRITE */\n\n/* These are initialization functions for hardware specific PNG filter\n * optimizations; list these here then select the appropriate one at compile\n * time using the macro PNG_FILTER_OPTIMIZATIONS.  If the macro is not defined\n * the generic code is used.\n */\n#ifdef PNG_FILTER_OPTIMIZATIONS\nPNG_INTERNAL_FUNCTION(void, PNG_FILTER_OPTIMIZATIONS, (png_structp png_ptr,\n   unsigned int bpp), PNG_EMPTY);\n   /* Just declare the optimization that will be used */\n#else\n   /* List *all* the possible optimizations here - this branch is required if\n    * the builder of libpng passes the definition of PNG_FILTER_OPTIMIZATIONS in\n    * CFLAGS in place of CPPFLAGS *and* uses symbol prefixing.\n    */\n#  if PNG_ARM_NEON_OPT > 0\nPNG_INTERNAL_FUNCTION(void, png_init_filter_functions_neon,\n   (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n#endif\n\n#if PNG_MIPS_MSA_OPT > 0\nPNG_INTERNAL_FUNCTION(void, png_init_filter_functions_msa,\n   (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n#endif\n\n#  if PNG_INTEL_SSE_IMPLEMENTATION > 0\nPNG_INTERNAL_FUNCTION(void, png_init_filter_functions_sse2,\n   (png_structp png_ptr, unsigned int bpp), PNG_EMPTY);\n#  endif\n#endif\n\nPNG_INTERNAL_FUNCTION(png_uint_32, png_check_keyword, (png_structrp png_ptr,\n   png_const_charp key, png_bytep new_key), PNG_EMPTY);\n\n/* Maintainer: Put new private prototypes here ^ */\n\n#include \"pngdebug.h\"\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif /* PNG_VERSION_INFO_ONLY */\n#endif /* PNGPRIV_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngread.c",
    "content": "\n/* pngread.c - read a PNG file\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file contains routines that an application calls directly to\n * read a PNG file or stream.\n */\n\n#include \"pngpriv.h\"\n#if defined(PNG_SIMPLIFIED_READ_SUPPORTED) && defined(PNG_STDIO_SUPPORTED)\n#  include <errno.h>\n#endif\n\n#ifdef PNG_READ_SUPPORTED\n\n/* Create a PNG structure for reading, and allocate any memory needed. */\nPNG_FUNCTION(png_structp,PNGAPI\npng_create_read_struct,(png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)\n{\n#ifndef PNG_USER_MEM_SUPPORTED\n   png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,\n        error_fn, warn_fn, NULL, NULL, NULL);\n#else\n   return png_create_read_struct_2(user_png_ver, error_ptr, error_fn,\n        warn_fn, NULL, NULL, NULL);\n}\n\n/* Alternate create PNG structure for reading, and allocate any memory\n * needed.\n */\nPNG_FUNCTION(png_structp,PNGAPI\npng_create_read_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,\n    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)\n{\n   png_structp png_ptr = png_create_png_struct(user_png_ver, error_ptr,\n       error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);\n#endif /* USER_MEM */\n\n   if (png_ptr != NULL)\n   {\n      png_ptr->mode = PNG_IS_READ_STRUCT;\n\n      /* Added in libpng-1.6.0; this can be used to detect a read structure if\n       * required (it will be zero in a write structure.)\n       */\n#     ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n         png_ptr->IDAT_read_size = PNG_IDAT_READ_SIZE;\n#     endif\n\n#     ifdef PNG_BENIGN_READ_ERRORS_SUPPORTED\n         png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;\n\n         /* In stable builds only warn if an application error can be completely\n          * handled.\n          */\n#        if PNG_RELEASE_BUILD\n            png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;\n#        endif\n#     endif\n\n      /* TODO: delay this, it can be done in png_init_io (if the app doesn't\n       * do it itself) avoiding setting the default function if it is not\n       * required.\n       */\n      png_set_read_fn(png_ptr, NULL, NULL);\n   }\n\n   return png_ptr;\n}\n\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the information before the actual image data.  This has been\n * changed in v0.90 to allow reading a file that already has the magic\n * bytes read from the stream.  You can tell libpng how many bytes have\n * been read from the beginning of the stream (up to the maximum of 8)\n * via png_set_sig_bytes(), and we will only check the remaining bytes\n * here.  The application can then have access to the signature bytes we\n * read if it is determined that this isn't a valid PNG file.\n */\nvoid PNGAPI\npng_read_info(png_structrp png_ptr, png_inforp info_ptr)\n{\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n   int keep;\n#endif\n\n   png_debug(1, \"in png_read_info\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   /* Read and check the PNG file signature. */\n   png_read_sig(png_ptr, info_ptr);\n\n   for (;;)\n   {\n      png_uint_32 length = png_read_chunk_header(png_ptr);\n      png_uint_32 chunk_name = png_ptr->chunk_name;\n\n      /* IDAT logic needs to happen here to simplify getting the two flags\n       * right.\n       */\n      if (chunk_name == png_IDAT)\n      {\n         if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n            png_chunk_error(png_ptr, \"Missing IHDR before IDAT\");\n\n         else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&\n             (png_ptr->mode & PNG_HAVE_PLTE) == 0)\n            png_chunk_error(png_ptr, \"Missing PLTE before IDAT\");\n\n         else if ((png_ptr->mode & PNG_AFTER_IDAT) != 0)\n            png_chunk_benign_error(png_ptr, \"Too many IDATs found\");\n\n         png_ptr->mode |= PNG_HAVE_IDAT;\n      }\n\n      else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n      {\n         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;\n         png_ptr->mode |= PNG_AFTER_IDAT;\n      }\n\n      /* This should be a binary subdivision search or a hash for\n       * matching the chunk name rather than a linear search.\n       */\n      if (chunk_name == png_IHDR)\n         png_handle_IHDR(png_ptr, info_ptr, length);\n\n      else if (chunk_name == png_IEND)\n         png_handle_IEND(png_ptr, info_ptr, length);\n\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n      else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)\n      {\n         png_handle_unknown(png_ptr, info_ptr, length, keep);\n\n         if (chunk_name == png_PLTE)\n            png_ptr->mode |= PNG_HAVE_PLTE;\n\n         else if (chunk_name == png_IDAT)\n         {\n            png_ptr->idat_size = 0; /* It has been consumed */\n            break;\n         }\n      }\n#endif\n      else if (chunk_name == png_PLTE)\n         png_handle_PLTE(png_ptr, info_ptr, length);\n\n      else if (chunk_name == png_IDAT)\n      {\n         png_ptr->idat_size = length;\n         break;\n      }\n\n#ifdef PNG_READ_bKGD_SUPPORTED\n      else if (chunk_name == png_bKGD)\n         png_handle_bKGD(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_cHRM_SUPPORTED\n      else if (chunk_name == png_cHRM)\n         png_handle_cHRM(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_gAMA_SUPPORTED\n      else if (chunk_name == png_gAMA)\n         png_handle_gAMA(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_hIST_SUPPORTED\n      else if (chunk_name == png_hIST)\n         png_handle_hIST(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_oFFs_SUPPORTED\n      else if (chunk_name == png_oFFs)\n         png_handle_oFFs(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_pCAL_SUPPORTED\n      else if (chunk_name == png_pCAL)\n         png_handle_pCAL(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sCAL_SUPPORTED\n      else if (chunk_name == png_sCAL)\n         png_handle_sCAL(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_pHYs_SUPPORTED\n      else if (chunk_name == png_pHYs)\n         png_handle_pHYs(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sBIT_SUPPORTED\n      else if (chunk_name == png_sBIT)\n         png_handle_sBIT(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sRGB_SUPPORTED\n      else if (chunk_name == png_sRGB)\n         png_handle_sRGB(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_iCCP_SUPPORTED\n      else if (chunk_name == png_iCCP)\n         png_handle_iCCP(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sPLT_SUPPORTED\n      else if (chunk_name == png_sPLT)\n         png_handle_sPLT(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tEXt_SUPPORTED\n      else if (chunk_name == png_tEXt)\n         png_handle_tEXt(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tIME_SUPPORTED\n      else if (chunk_name == png_tIME)\n         png_handle_tIME(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tRNS_SUPPORTED\n      else if (chunk_name == png_tRNS)\n         png_handle_tRNS(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_zTXt_SUPPORTED\n      else if (chunk_name == png_zTXt)\n         png_handle_zTXt(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_iTXt_SUPPORTED\n      else if (chunk_name == png_iTXt)\n         png_handle_iTXt(png_ptr, info_ptr, length);\n#endif\n\n      else\n         png_handle_unknown(png_ptr, info_ptr, length,\n             PNG_HANDLE_CHUNK_AS_DEFAULT);\n   }\n}\n#endif /* SEQUENTIAL_READ */\n\n/* Optional call to update the users info_ptr structure */\nvoid PNGAPI\npng_read_update_info(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_debug(1, \"in png_read_update_info\");\n\n   if (png_ptr != NULL)\n   {\n      if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)\n      {\n         png_read_start_row(png_ptr);\n\n#        ifdef PNG_READ_TRANSFORMS_SUPPORTED\n            png_read_transform_info(png_ptr, info_ptr);\n#        else\n            PNG_UNUSED(info_ptr)\n#        endif\n      }\n\n      /* New in 1.6.0 this avoids the bug of doing the initializations twice */\n      else\n         png_app_error(png_ptr,\n             \"png_read_update_info/png_start_read_image: duplicate call\");\n   }\n}\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Initialize palette, background, etc, after transformations\n * are set, but before any reading takes place.  This allows\n * the user to obtain a gamma-corrected palette, for example.\n * If the user doesn't call this, we will do it ourselves.\n */\nvoid PNGAPI\npng_start_read_image(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_start_read_image\");\n\n   if (png_ptr != NULL)\n   {\n      if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)\n         png_read_start_row(png_ptr);\n\n      /* New in 1.6.0 this avoids the bug of doing the initializations twice */\n      else\n         png_app_error(png_ptr,\n             \"png_start_read_image/png_read_update_info: duplicate call\");\n   }\n}\n#endif /* SEQUENTIAL_READ */\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n/* Undoes intrapixel differencing,\n * NOTE: this is apparently only supported in the 'sequential' reader.\n */\nstatic void\npng_do_read_intrapixel(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_read_intrapixel\");\n\n   if (\n       (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      int bytes_per_pixel;\n      png_uint_32 row_width = row_info->width;\n\n      if (row_info->bit_depth == 8)\n      {\n         png_bytep rp;\n         png_uint_32 i;\n\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n            bytes_per_pixel = 3;\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n            bytes_per_pixel = 4;\n\n         else\n            return;\n\n         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)\n         {\n            *(rp) = (png_byte)((256 + *rp + *(rp + 1)) & 0xff);\n            *(rp+2) = (png_byte)((256 + *(rp + 2) + *(rp + 1)) & 0xff);\n         }\n      }\n      else if (row_info->bit_depth == 16)\n      {\n         png_bytep rp;\n         png_uint_32 i;\n\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n            bytes_per_pixel = 6;\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n            bytes_per_pixel = 8;\n\n         else\n            return;\n\n         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)\n         {\n            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);\n            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);\n            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);\n            png_uint_32 red  = (s0 + s1 + 65536) & 0xffff;\n            png_uint_32 blue = (s2 + s1 + 65536) & 0xffff;\n            *(rp    ) = (png_byte)((red >> 8) & 0xff);\n            *(rp + 1) = (png_byte)(red & 0xff);\n            *(rp + 4) = (png_byte)((blue >> 8) & 0xff);\n            *(rp + 5) = (png_byte)(blue & 0xff);\n         }\n      }\n   }\n}\n#endif /* MNG_FEATURES */\n\nvoid PNGAPI\npng_read_row(png_structrp png_ptr, png_bytep row, png_bytep dsp_row)\n{\n   png_row_info row_info;\n\n   if (png_ptr == NULL)\n      return;\n\n   png_debug2(1, \"in png_read_row (row %lu, pass %d)\",\n       (unsigned long)png_ptr->row_number, png_ptr->pass);\n\n   /* png_read_start_row sets the information (in particular iwidth) for this\n    * interlace pass.\n    */\n   if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)\n      png_read_start_row(png_ptr);\n\n   /* 1.5.6: row_info moved out of png_struct to a local here. */\n   row_info.width = png_ptr->iwidth; /* NOTE: width of current interlaced row */\n   row_info.color_type = png_ptr->color_type;\n   row_info.bit_depth = png_ptr->bit_depth;\n   row_info.channels = png_ptr->channels;\n   row_info.pixel_depth = png_ptr->pixel_depth;\n   row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);\n\n#ifdef PNG_WARNINGS_SUPPORTED\n   if (png_ptr->row_number == 0 && png_ptr->pass == 0)\n   {\n   /* Check for transforms that have been set but were defined out */\n#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)\n   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)\n      png_warning(png_ptr, \"PNG_READ_INVERT_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)\n   if ((png_ptr->transformations & PNG_FILLER) != 0)\n      png_warning(png_ptr, \"PNG_READ_FILLER_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \\\n    !defined(PNG_READ_PACKSWAP_SUPPORTED)\n   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n      png_warning(png_ptr, \"PNG_READ_PACKSWAP_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)\n   if ((png_ptr->transformations & PNG_PACK) != 0)\n      png_warning(png_ptr, \"PNG_READ_PACK_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)\n   if ((png_ptr->transformations & PNG_SHIFT) != 0)\n      png_warning(png_ptr, \"PNG_READ_SHIFT_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)\n   if ((png_ptr->transformations & PNG_BGR) != 0)\n      png_warning(png_ptr, \"PNG_READ_BGR_SUPPORTED is not defined\");\n#endif\n\n#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)\n   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)\n      png_warning(png_ptr, \"PNG_READ_SWAP_SUPPORTED is not defined\");\n#endif\n   }\n#endif /* WARNINGS */\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* If interlaced and we do not need a new row, combine row and return.\n    * Notice that the pixels we have from previous rows have been transformed\n    * already; we can only combine like with like (transformed or\n    * untransformed) and, because of the libpng API for interlaced images, this\n    * means we must transform before de-interlacing.\n    */\n   if (png_ptr->interlaced != 0 &&\n       (png_ptr->transformations & PNG_INTERLACE) != 0)\n   {\n      switch (png_ptr->pass)\n      {\n         case 0:\n            if (png_ptr->row_number & 0x07)\n            {\n               if (dsp_row != NULL)\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 1:\n            if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)\n            {\n               if (dsp_row != NULL)\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 2:\n            if ((png_ptr->row_number & 0x07) != 4)\n            {\n               if (dsp_row != NULL && (png_ptr->row_number & 4))\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 3:\n            if ((png_ptr->row_number & 3) || png_ptr->width < 3)\n            {\n               if (dsp_row != NULL)\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 4:\n            if ((png_ptr->row_number & 3) != 2)\n            {\n               if (dsp_row != NULL && (png_ptr->row_number & 2))\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 5:\n            if ((png_ptr->row_number & 1) || png_ptr->width < 2)\n            {\n               if (dsp_row != NULL)\n                  png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         default:\n         case 6:\n            if ((png_ptr->row_number & 1) == 0)\n            {\n               png_read_finish_row(png_ptr);\n               return;\n            }\n            break;\n      }\n   }\n#endif\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)\n      png_error(png_ptr, \"Invalid attempt to read row data\");\n\n   /* Fill the row with IDAT data: */\n   png_read_IDAT_data(png_ptr, png_ptr->row_buf, row_info.rowbytes + 1);\n\n   if (png_ptr->row_buf[0] > PNG_FILTER_VALUE_NONE)\n   {\n      if (png_ptr->row_buf[0] < PNG_FILTER_VALUE_LAST)\n         png_read_filter_row(png_ptr, &row_info, png_ptr->row_buf + 1,\n             png_ptr->prev_row + 1, png_ptr->row_buf[0]);\n      else\n         png_error(png_ptr, \"bad adaptive filter value\");\n   }\n\n   /* libpng 1.5.6: the following line was copying png_ptr->rowbytes before\n    * 1.5.6, while the buffer really is this big in current versions of libpng\n    * it may not be in the future, so this was changed just to copy the\n    * interlaced count:\n    */\n   memcpy(png_ptr->prev_row, png_ptr->row_buf, row_info.rowbytes + 1);\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&\n       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))\n   {\n      /* Intrapixel differencing */\n      png_do_read_intrapixel(&row_info, png_ptr->row_buf + 1);\n   }\n#endif\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n   if (png_ptr->transformations)\n      png_do_read_transformations(png_ptr, &row_info);\n#endif\n\n   /* The transformed pixel depth should match the depth now in row_info. */\n   if (png_ptr->transformed_pixel_depth == 0)\n   {\n      png_ptr->transformed_pixel_depth = row_info.pixel_depth;\n      if (row_info.pixel_depth > png_ptr->maximum_pixel_depth)\n         png_error(png_ptr, \"sequential row overflow\");\n   }\n\n   else if (png_ptr->transformed_pixel_depth != row_info.pixel_depth)\n      png_error(png_ptr, \"internal sequential row size calculation error\");\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   /* Expand interlaced rows to full size */\n   if (png_ptr->interlaced != 0 &&\n      (png_ptr->transformations & PNG_INTERLACE) != 0)\n   {\n      if (png_ptr->pass < 6)\n         png_do_read_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass,\n             png_ptr->transformations);\n\n      if (dsp_row != NULL)\n         png_combine_row(png_ptr, dsp_row, 1/*display*/);\n\n      if (row != NULL)\n         png_combine_row(png_ptr, row, 0/*row*/);\n   }\n\n   else\n#endif\n   {\n      if (row != NULL)\n         png_combine_row(png_ptr, row, -1/*ignored*/);\n\n      if (dsp_row != NULL)\n         png_combine_row(png_ptr, dsp_row, -1/*ignored*/);\n   }\n   png_read_finish_row(png_ptr);\n\n   if (png_ptr->read_row_fn != NULL)\n      (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);\n\n}\n#endif /* SEQUENTIAL_READ */\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read one or more rows of image data.  If the image is interlaced,\n * and png_set_interlace_handling() has been called, the rows need to\n * contain the contents of the rows from the previous pass.  If the\n * image has alpha or transparency, and png_handle_alpha()[*] has been\n * called, the rows contents must be initialized to the contents of the\n * screen.\n *\n * \"row\" holds the actual image, and pixels are placed in it\n * as they arrive.  If the image is displayed after each pass, it will\n * appear to \"sparkle\" in.  \"display_row\" can be used to display a\n * \"chunky\" progressive image, with finer detail added as it becomes\n * available.  If you do not want this \"chunky\" display, you may pass\n * NULL for display_row.  If you do not want the sparkle display, and\n * you have not called png_handle_alpha(), you may pass NULL for rows.\n * If you have called png_handle_alpha(), and the image has either an\n * alpha channel or a transparency chunk, you must provide a buffer for\n * rows.  In this case, you do not have to provide a display_row buffer\n * also, but you may.  If the image is not interlaced, or if you have\n * not called png_set_interlace_handling(), the display_row buffer will\n * be ignored, so pass NULL to it.\n *\n * [*] png_handle_alpha() does not exist yet, as of this version of libpng\n */\n\nvoid PNGAPI\npng_read_rows(png_structrp png_ptr, png_bytepp row,\n    png_bytepp display_row, png_uint_32 num_rows)\n{\n   png_uint_32 i;\n   png_bytepp rp;\n   png_bytepp dp;\n\n   png_debug(1, \"in png_read_rows\");\n\n   if (png_ptr == NULL)\n      return;\n\n   rp = row;\n   dp = display_row;\n   if (rp != NULL && dp != NULL)\n      for (i = 0; i < num_rows; i++)\n      {\n         png_bytep rptr = *rp++;\n         png_bytep dptr = *dp++;\n\n         png_read_row(png_ptr, rptr, dptr);\n      }\n\n   else if (rp != NULL)\n      for (i = 0; i < num_rows; i++)\n      {\n         png_bytep rptr = *rp;\n         png_read_row(png_ptr, rptr, NULL);\n         rp++;\n      }\n\n   else if (dp != NULL)\n      for (i = 0; i < num_rows; i++)\n      {\n         png_bytep dptr = *dp;\n         png_read_row(png_ptr, NULL, dptr);\n         dp++;\n      }\n}\n#endif /* SEQUENTIAL_READ */\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the entire image.  If the image has an alpha channel or a tRNS\n * chunk, and you have called png_handle_alpha()[*], you will need to\n * initialize the image to the current image that PNG will be overlaying.\n * We set the num_rows again here, in case it was incorrectly set in\n * png_read_start_row() by a call to png_read_update_info() or\n * png_start_read_image() if png_set_interlace_handling() wasn't called\n * prior to either of these functions like it should have been.  You can\n * only call this function once.  If you desire to have an image for\n * each pass of a interlaced image, use png_read_rows() instead.\n *\n * [*] png_handle_alpha() does not exist yet, as of this version of libpng\n */\nvoid PNGAPI\npng_read_image(png_structrp png_ptr, png_bytepp image)\n{\n   png_uint_32 i, image_height;\n   int pass, j;\n   png_bytepp rp;\n\n   png_debug(1, \"in png_read_image\");\n\n   if (png_ptr == NULL)\n      return;\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   if ((png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)\n   {\n      pass = png_set_interlace_handling(png_ptr);\n      /* And make sure transforms are initialized. */\n      png_start_read_image(png_ptr);\n   }\n   else\n   {\n      if (png_ptr->interlaced != 0 &&\n          (png_ptr->transformations & PNG_INTERLACE) == 0)\n      {\n         /* Caller called png_start_read_image or png_read_update_info without\n          * first turning on the PNG_INTERLACE transform.  We can fix this here,\n          * but the caller should do it!\n          */\n         png_warning(png_ptr, \"Interlace handling should be turned on when \"\n             \"using png_read_image\");\n         /* Make sure this is set correctly */\n         png_ptr->num_rows = png_ptr->height;\n      }\n\n      /* Obtain the pass number, which also turns on the PNG_INTERLACE flag in\n       * the above error case.\n       */\n      pass = png_set_interlace_handling(png_ptr);\n   }\n#else\n   if (png_ptr->interlaced)\n      png_error(png_ptr,\n          \"Cannot read interlaced image -- interlace handler disabled\");\n\n   pass = 1;\n#endif\n\n   image_height=png_ptr->height;\n\n   for (j = 0; j < pass; j++)\n   {\n      rp = image;\n      for (i = 0; i < image_height; i++)\n      {\n         png_read_row(png_ptr, *rp, NULL);\n         rp++;\n      }\n   }\n}\n#endif /* SEQUENTIAL_READ */\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n/* Read the end of the PNG file.  Will not read past the end of the\n * file, will verify the end is accurate, and will read any comments\n * or time information at the end of the file, if info is not NULL.\n */\nvoid PNGAPI\npng_read_end(png_structrp png_ptr, png_inforp info_ptr)\n{\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n   int keep;\n#endif\n\n   png_debug(1, \"in png_read_end\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* If png_read_end is called in the middle of reading the rows there may\n    * still be pending IDAT data and an owned zstream.  Deal with this here.\n    */\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n   if (png_chunk_unknown_handling(png_ptr, png_IDAT) == 0)\n#endif\n      png_read_finish_IDAT(png_ptr);\n\n#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   /* Report invalid palette index; added at libng-1.5.10 */\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&\n       png_ptr->num_palette_max > png_ptr->num_palette)\n      png_benign_error(png_ptr, \"Read palette index exceeding num_palette\");\n#endif\n\n   do\n   {\n      png_uint_32 length = png_read_chunk_header(png_ptr);\n      png_uint_32 chunk_name = png_ptr->chunk_name;\n\n      if (chunk_name != png_IDAT)\n         png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;\n\n      if (chunk_name == png_IEND)\n         png_handle_IEND(png_ptr, info_ptr, length);\n\n      else if (chunk_name == png_IHDR)\n         png_handle_IHDR(png_ptr, info_ptr, length);\n\n      else if (info_ptr == NULL)\n         png_crc_finish(png_ptr, length);\n\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n      else if ((keep = png_chunk_unknown_handling(png_ptr, chunk_name)) != 0)\n      {\n         if (chunk_name == png_IDAT)\n         {\n            if ((length > 0 && !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))\n                || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)\n               png_benign_error(png_ptr, \".Too many IDATs found\");\n         }\n         png_handle_unknown(png_ptr, info_ptr, length, keep);\n         if (chunk_name == png_PLTE)\n            png_ptr->mode |= PNG_HAVE_PLTE;\n      }\n#endif\n\n      else if (chunk_name == png_IDAT)\n      {\n         /* Zero length IDATs are legal after the last IDAT has been\n          * read, but not after other chunks have been read.  1.6 does not\n          * always read all the deflate data; specifically it cannot be relied\n          * upon to read the Adler32 at the end.  If it doesn't ignore IDAT\n          * chunks which are longer than zero as well:\n          */\n         if ((length > 0 && !(png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED))\n             || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT) != 0)\n            png_benign_error(png_ptr, \"..Too many IDATs found\");\n\n         png_crc_finish(png_ptr, length);\n      }\n      else if (chunk_name == png_PLTE)\n         png_handle_PLTE(png_ptr, info_ptr, length);\n\n#ifdef PNG_READ_bKGD_SUPPORTED\n      else if (chunk_name == png_bKGD)\n         png_handle_bKGD(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_cHRM_SUPPORTED\n      else if (chunk_name == png_cHRM)\n         png_handle_cHRM(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_gAMA_SUPPORTED\n      else if (chunk_name == png_gAMA)\n         png_handle_gAMA(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_hIST_SUPPORTED\n      else if (chunk_name == png_hIST)\n         png_handle_hIST(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_oFFs_SUPPORTED\n      else if (chunk_name == png_oFFs)\n         png_handle_oFFs(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_pCAL_SUPPORTED\n      else if (chunk_name == png_pCAL)\n         png_handle_pCAL(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sCAL_SUPPORTED\n      else if (chunk_name == png_sCAL)\n         png_handle_sCAL(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_pHYs_SUPPORTED\n      else if (chunk_name == png_pHYs)\n         png_handle_pHYs(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sBIT_SUPPORTED\n      else if (chunk_name == png_sBIT)\n         png_handle_sBIT(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sRGB_SUPPORTED\n      else if (chunk_name == png_sRGB)\n         png_handle_sRGB(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_iCCP_SUPPORTED\n      else if (chunk_name == png_iCCP)\n         png_handle_iCCP(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_sPLT_SUPPORTED\n      else if (chunk_name == png_sPLT)\n         png_handle_sPLT(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tEXt_SUPPORTED\n      else if (chunk_name == png_tEXt)\n         png_handle_tEXt(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tIME_SUPPORTED\n      else if (chunk_name == png_tIME)\n         png_handle_tIME(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_tRNS_SUPPORTED\n      else if (chunk_name == png_tRNS)\n         png_handle_tRNS(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_zTXt_SUPPORTED\n      else if (chunk_name == png_zTXt)\n         png_handle_zTXt(png_ptr, info_ptr, length);\n#endif\n\n#ifdef PNG_READ_iTXt_SUPPORTED\n      else if (chunk_name == png_iTXt)\n         png_handle_iTXt(png_ptr, info_ptr, length);\n#endif\n\n      else\n         png_handle_unknown(png_ptr, info_ptr, length,\n             PNG_HANDLE_CHUNK_AS_DEFAULT);\n   } while ((png_ptr->mode & PNG_HAVE_IEND) == 0);\n}\n#endif /* SEQUENTIAL_READ */\n\n/* Free all memory used in the read struct */\nstatic void\npng_read_destroy(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_read_destroy\");\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   png_destroy_gamma_table(png_ptr);\n#endif\n\n   png_free(png_ptr, png_ptr->big_row_buf);\n   png_ptr->big_row_buf = NULL;\n   png_free(png_ptr, png_ptr->big_prev_row);\n   png_ptr->big_prev_row = NULL;\n   png_free(png_ptr, png_ptr->read_buffer);\n   png_ptr->read_buffer = NULL;\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n   png_free(png_ptr, png_ptr->palette_lookup);\n   png_ptr->palette_lookup = NULL;\n   png_free(png_ptr, png_ptr->quantize_index);\n   png_ptr->quantize_index = NULL;\n#endif\n\n   if ((png_ptr->free_me & PNG_FREE_PLTE) != 0)\n   {\n      png_zfree(png_ptr, png_ptr->palette);\n      png_ptr->palette = NULL;\n   }\n   png_ptr->free_me &= ~PNG_FREE_PLTE;\n\n#if defined(PNG_tRNS_SUPPORTED) || \\\n    defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)\n   if ((png_ptr->free_me & PNG_FREE_TRNS) != 0)\n   {\n      png_free(png_ptr, png_ptr->trans_alpha);\n      png_ptr->trans_alpha = NULL;\n   }\n   png_ptr->free_me &= ~PNG_FREE_TRNS;\n#endif\n\n   inflateEnd(&png_ptr->zstream);\n\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\n   png_free(png_ptr, png_ptr->save_buffer);\n   png_ptr->save_buffer = NULL;\n#endif\n\n#if defined(PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED) && \\\n   defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)\n   png_free(png_ptr, png_ptr->unknown_chunk.data);\n   png_ptr->unknown_chunk.data = NULL;\n#endif\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n   png_free(png_ptr, png_ptr->chunk_list);\n   png_ptr->chunk_list = NULL;\n#endif\n\n   /* NOTE: the 'setjmp' buffer may still be allocated and the memory and error\n    * callbacks are still set at this point.  They are required to complete the\n    * destruction of the png_struct itself.\n    */\n}\n\n/* Free all memory used by the read */\nvoid PNGAPI\npng_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,\n    png_infopp end_info_ptr_ptr)\n{\n   png_structrp png_ptr = NULL;\n\n   png_debug(1, \"in png_destroy_read_struct\");\n\n   if (png_ptr_ptr != NULL)\n      png_ptr = *png_ptr_ptr;\n\n   if (png_ptr == NULL)\n      return;\n\n   /* libpng 1.6.0: use the API to destroy info structs to ensure consistent\n    * behavior.  Prior to 1.6.0 libpng did extra 'info' destruction in this API.\n    * The extra was, apparently, unnecessary yet this hides memory leak bugs.\n    */\n   png_destroy_info_struct(png_ptr, end_info_ptr_ptr);\n   png_destroy_info_struct(png_ptr, info_ptr_ptr);\n\n   *png_ptr_ptr = NULL;\n   png_read_destroy(png_ptr);\n   png_destroy_png_struct(png_ptr);\n}\n\nvoid PNGAPI\npng_set_read_status_fn(png_structrp png_ptr, png_read_status_ptr read_row_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->read_row_fn = read_row_fn;\n}\n\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n#ifdef PNG_INFO_IMAGE_SUPPORTED\nvoid PNGAPI\npng_read_png(png_structrp png_ptr, png_inforp info_ptr,\n    int transforms, voidp params)\n{\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   /* png_read_info() gives us all of the information from the\n    * PNG file before the first IDAT (image data chunk).\n    */\n   png_read_info(png_ptr, info_ptr);\n   if (info_ptr->height > PNG_UINT_32_MAX/(sizeof (png_bytep)))\n      png_error(png_ptr, \"Image is too high to process with png_read_png()\");\n\n   /* -------------- image transformations start here ------------------- */\n   /* libpng 1.6.10: add code to cause a png_app_error if a selected TRANSFORM\n    * is not implemented.  This will only happen in de-configured (non-default)\n    * libpng builds.  The results can be unexpected - png_read_png may return\n    * short or mal-formed rows because the transform is skipped.\n    */\n\n   /* Tell libpng to strip 16-bit/color files down to 8 bits per color.\n    */\n   if ((transforms & PNG_TRANSFORM_SCALE_16) != 0)\n      /* Added at libpng-1.5.4. \"strip_16\" produces the same result that it\n       * did in earlier versions, while \"scale_16\" is now more accurate.\n       */\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n      png_set_scale_16(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SCALE_16 not supported\");\n#endif\n\n   /* If both SCALE and STRIP are required pngrtran will effectively cancel the\n    * latter by doing SCALE first.  This is ok and allows apps not to check for\n    * which is supported to get the right answer.\n    */\n   if ((transforms & PNG_TRANSFORM_STRIP_16) != 0)\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n      png_set_strip_16(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_STRIP_16 not supported\");\n#endif\n\n   /* Strip alpha bytes from the input data without combining with\n    * the background (not recommended).\n    */\n   if ((transforms & PNG_TRANSFORM_STRIP_ALPHA) != 0)\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n      png_set_strip_alpha(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_STRIP_ALPHA not supported\");\n#endif\n\n   /* Extract multiple pixels with bit depths of 1, 2, or 4 from a single\n    * byte into separate bytes (useful for paletted and grayscale images).\n    */\n   if ((transforms & PNG_TRANSFORM_PACKING) != 0)\n#ifdef PNG_READ_PACK_SUPPORTED\n      png_set_packing(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_PACKING not supported\");\n#endif\n\n   /* Change the order of packed pixels to least significant bit first\n    * (not useful if you are using png_set_packing).\n    */\n   if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n      png_set_packswap(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_PACKSWAP not supported\");\n#endif\n\n   /* Expand paletted colors into true RGB triplets\n    * Expand grayscale images to full 8 bits from 1, 2, or 4 bits/pixel\n    * Expand paletted or RGB images with transparency to full alpha\n    * channels so the data will be available as RGBA quartets.\n    */\n   if ((transforms & PNG_TRANSFORM_EXPAND) != 0)\n#ifdef PNG_READ_EXPAND_SUPPORTED\n      png_set_expand(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_EXPAND not supported\");\n#endif\n\n   /* We don't handle background color or gamma transformation or quantizing.\n    */\n\n   /* Invert monochrome files to have 0 as white and 1 as black\n    */\n   if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0)\n#ifdef PNG_READ_INVERT_SUPPORTED\n      png_set_invert_mono(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_INVERT_MONO not supported\");\n#endif\n\n   /* If you want to shift the pixel values from the range [0,255] or\n    * [0,65535] to the original [0,7] or [0,31], or whatever range the\n    * colors were originally in:\n    */\n   if ((transforms & PNG_TRANSFORM_SHIFT) != 0)\n#ifdef PNG_READ_SHIFT_SUPPORTED\n      if ((info_ptr->valid & PNG_INFO_sBIT) != 0)\n         png_set_shift(png_ptr, &info_ptr->sig_bit);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SHIFT not supported\");\n#endif\n\n   /* Flip the RGB pixels to BGR (or RGBA to BGRA) */\n   if ((transforms & PNG_TRANSFORM_BGR) != 0)\n#ifdef PNG_READ_BGR_SUPPORTED\n      png_set_bgr(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_BGR not supported\");\n#endif\n\n   /* Swap the RGBA or GA data to ARGB or AG (or BGRA to ABGR) */\n   if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0)\n#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED\n      png_set_swap_alpha(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SWAP_ALPHA not supported\");\n#endif\n\n   /* Swap bytes of 16-bit files to least significant byte first */\n   if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0)\n#ifdef PNG_READ_SWAP_SUPPORTED\n      png_set_swap(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SWAP_ENDIAN not supported\");\n#endif\n\n/* Added at libpng-1.2.41 */\n   /* Invert the alpha channel from opacity to transparency */\n   if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0)\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\n      png_set_invert_alpha(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_INVERT_ALPHA not supported\");\n#endif\n\n/* Added at libpng-1.2.41 */\n   /* Expand grayscale image to RGB */\n   if ((transforms & PNG_TRANSFORM_GRAY_TO_RGB) != 0)\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n      png_set_gray_to_rgb(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_GRAY_TO_RGB not supported\");\n#endif\n\n/* Added at libpng-1.5.4 */\n   if ((transforms & PNG_TRANSFORM_EXPAND_16) != 0)\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n      png_set_expand_16(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_EXPAND_16 not supported\");\n#endif\n\n   /* We don't handle adding filler bytes */\n\n   /* We use png_read_image and rely on that for interlace handling, but we also\n    * call png_read_update_info therefore must turn on interlace handling now:\n    */\n   (void)png_set_interlace_handling(png_ptr);\n\n   /* Optional call to gamma correct and add the background to the palette\n    * and update info structure.  REQUIRED if you are expecting libpng to\n    * update the palette for you (i.e., you selected such a transform above).\n    */\n   png_read_update_info(png_ptr, info_ptr);\n\n   /* -------------- image transformations end here ------------------- */\n\n   png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);\n   if (info_ptr->row_pointers == NULL)\n   {\n      png_uint_32 iptr;\n\n      info_ptr->row_pointers = png_voidcast(png_bytepp, png_malloc(png_ptr,\n          info_ptr->height * (sizeof (png_bytep))));\n\n      for (iptr=0; iptr<info_ptr->height; iptr++)\n         info_ptr->row_pointers[iptr] = NULL;\n\n      info_ptr->free_me |= PNG_FREE_ROWS;\n\n      for (iptr = 0; iptr < info_ptr->height; iptr++)\n         info_ptr->row_pointers[iptr] = png_voidcast(png_bytep,\n             png_malloc(png_ptr, info_ptr->rowbytes));\n   }\n\n   png_read_image(png_ptr, info_ptr->row_pointers);\n   info_ptr->valid |= PNG_INFO_IDAT;\n\n   /* Read rest of file, and get additional chunks in info_ptr - REQUIRED */\n   png_read_end(png_ptr, info_ptr);\n\n   PNG_UNUSED(params)\n}\n#endif /* INFO_IMAGE */\n#endif /* SEQUENTIAL_READ */\n\n#ifdef PNG_SIMPLIFIED_READ_SUPPORTED\n/* SIMPLIFIED READ\n *\n * This code currently relies on the sequential reader, though it could easily\n * be made to work with the progressive one.\n */\n/* Arguments to png_image_finish_read: */\n\n/* Encoding of PNG data (used by the color-map code) */\n#  define P_NOTSET  0 /* File encoding not yet known */\n#  define P_sRGB    1 /* 8-bit encoded to sRGB gamma */\n#  define P_LINEAR  2 /* 16-bit linear: not encoded, NOT pre-multiplied! */\n#  define P_FILE    3 /* 8-bit encoded to file gamma, not sRGB or linear */\n#  define P_LINEAR8 4 /* 8-bit linear: only from a file value */\n\n/* Color-map processing: after libpng has run on the PNG image further\n * processing may be needed to convert the data to color-map indices.\n */\n#define PNG_CMAP_NONE      0\n#define PNG_CMAP_GA        1 /* Process GA data to a color-map with alpha */\n#define PNG_CMAP_TRANS     2 /* Process GA data to a background index */\n#define PNG_CMAP_RGB       3 /* Process RGB data */\n#define PNG_CMAP_RGB_ALPHA 4 /* Process RGBA data */\n\n/* The following document where the background is for each processing case. */\n#define PNG_CMAP_NONE_BACKGROUND      256\n#define PNG_CMAP_GA_BACKGROUND        231\n#define PNG_CMAP_TRANS_BACKGROUND     254\n#define PNG_CMAP_RGB_BACKGROUND       256\n#define PNG_CMAP_RGB_ALPHA_BACKGROUND 216\n\ntypedef struct\n{\n   /* Arguments: */\n   png_imagep image;\n   png_voidp  buffer;\n   png_int_32 row_stride;\n   png_voidp  colormap;\n   png_const_colorp background;\n   /* Local variables: */\n   png_voidp       local_row;\n   png_voidp       first_row;\n   ptrdiff_t       row_bytes;           /* step between rows */\n   int             file_encoding;       /* E_ values above */\n   png_fixed_point gamma_to_linear;     /* For P_FILE, reciprocal of gamma */\n   int             colormap_processing; /* PNG_CMAP_ values above */\n} png_image_read_control;\n\n/* Do all the *safe* initialization - 'safe' means that png_error won't be\n * called, so setting up the jmp_buf is not required.  This means that anything\n * called from here must *not* call png_malloc - it has to call png_malloc_warn\n * instead so that control is returned safely back to this routine.\n */\nstatic int\npng_image_read_init(png_imagep image)\n{\n   if (image->opaque == NULL)\n   {\n      png_structp png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, image,\n          png_safe_error, png_safe_warning);\n\n      /* And set the rest of the structure to NULL to ensure that the various\n       * fields are consistent.\n       */\n      memset(image, 0, (sizeof *image));\n      image->version = PNG_IMAGE_VERSION;\n\n      if (png_ptr != NULL)\n      {\n         png_infop info_ptr = png_create_info_struct(png_ptr);\n\n         if (info_ptr != NULL)\n         {\n            png_controlp control = png_voidcast(png_controlp,\n                png_malloc_warn(png_ptr, (sizeof *control)));\n\n            if (control != NULL)\n            {\n               memset(control, 0, (sizeof *control));\n\n               control->png_ptr = png_ptr;\n               control->info_ptr = info_ptr;\n               control->for_write = 0;\n\n               image->opaque = control;\n               return 1;\n            }\n\n            /* Error clean up */\n            png_destroy_info_struct(png_ptr, &info_ptr);\n         }\n\n         png_destroy_read_struct(&png_ptr, NULL, NULL);\n      }\n\n      return png_image_error(image, \"png_image_read: out of memory\");\n   }\n\n   return png_image_error(image, \"png_image_read: opaque pointer not NULL\");\n}\n\n/* Utility to find the base format of a PNG file from a png_struct. */\nstatic png_uint_32\npng_image_format(png_structrp png_ptr)\n{\n   png_uint_32 format = 0;\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      format |= PNG_FORMAT_FLAG_COLOR;\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      format |= PNG_FORMAT_FLAG_ALPHA;\n\n   /* Use png_ptr here, not info_ptr, because by examination png_handle_tRNS\n    * sets the png_struct fields; that's all we are interested in here.  The\n    * precise interaction with an app call to png_set_tRNS and PNG file reading\n    * is unclear.\n    */\n   else if (png_ptr->num_trans > 0)\n      format |= PNG_FORMAT_FLAG_ALPHA;\n\n   if (png_ptr->bit_depth == 16)\n      format |= PNG_FORMAT_FLAG_LINEAR;\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_PALETTE) != 0)\n      format |= PNG_FORMAT_FLAG_COLORMAP;\n\n   return format;\n}\n\n/* Is the given gamma significantly different from sRGB?  The test is the same\n * one used in pngrtran.c when deciding whether to do gamma correction.  The\n * arithmetic optimizes the division by using the fact that the inverse of the\n * file sRGB gamma is 2.2\n */\nstatic int\npng_gamma_not_sRGB(png_fixed_point g)\n{\n   if (g < PNG_FP_1)\n   {\n      /* An uninitialized gamma is assumed to be sRGB for the simplified API. */\n      if (g == 0)\n         return 0;\n\n      return png_gamma_significant((g * 11 + 2)/5 /* i.e. *2.2, rounded */);\n   }\n\n   return 1;\n}\n\n/* Do the main body of a 'png_image_begin_read' function; read the PNG file\n * header and fill in all the information.  This is executed in a safe context,\n * unlike the init routine above.\n */\nstatic int\npng_image_read_header(png_voidp argument)\n{\n   png_imagep image = png_voidcast(png_imagep, argument);\n   png_structrp png_ptr = image->opaque->png_ptr;\n   png_inforp info_ptr = image->opaque->info_ptr;\n\n   png_set_benign_errors(png_ptr, 1/*warn*/);\n   png_read_info(png_ptr, info_ptr);\n\n   /* Do this the fast way; just read directly out of png_struct. */\n   image->width = png_ptr->width;\n   image->height = png_ptr->height;\n\n   {\n      png_uint_32 format = png_image_format(png_ptr);\n\n      image->format = format;\n\n#ifdef PNG_COLORSPACE_SUPPORTED\n      /* Does the colorspace match sRGB?  If there is no color endpoint\n       * (colorant) information assume yes, otherwise require the\n       * 'ENDPOINTS_MATCHP_sRGB' colorspace flag to have been set.  If the\n       * colorspace has been determined to be invalid ignore it.\n       */\n      if ((format & PNG_FORMAT_FLAG_COLOR) != 0 && ((png_ptr->colorspace.flags\n         & (PNG_COLORSPACE_HAVE_ENDPOINTS|PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB|\n            PNG_COLORSPACE_INVALID)) == PNG_COLORSPACE_HAVE_ENDPOINTS))\n         image->flags |= PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB;\n#endif\n   }\n\n   /* We need the maximum number of entries regardless of the format the\n    * application sets here.\n    */\n   {\n      png_uint_32 cmap_entries;\n\n      switch (png_ptr->color_type)\n      {\n         case PNG_COLOR_TYPE_GRAY:\n            cmap_entries = 1U << png_ptr->bit_depth;\n            break;\n\n         case PNG_COLOR_TYPE_PALETTE:\n            cmap_entries = png_ptr->num_palette;\n            break;\n\n         default:\n            cmap_entries = 256;\n            break;\n      }\n\n      if (cmap_entries > 256)\n         cmap_entries = 256;\n\n      image->colormap_entries = cmap_entries;\n   }\n\n   return 1;\n}\n\n#ifdef PNG_STDIO_SUPPORTED\nint PNGAPI\npng_image_begin_read_from_stdio(png_imagep image, FILE* file)\n{\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (file != NULL)\n      {\n         if (png_image_read_init(image) != 0)\n         {\n            /* This is slightly evil, but png_init_io doesn't do anything other\n             * than this and we haven't changed the standard IO functions so\n             * this saves a 'safe' function.\n             */\n            image->opaque->png_ptr->io_ptr = file;\n            return png_safe_execute(image, png_image_read_header, image);\n         }\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_begin_read_from_stdio: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_begin_read_from_stdio: incorrect PNG_IMAGE_VERSION\");\n\n   return 0;\n}\n\nint PNGAPI\npng_image_begin_read_from_file(png_imagep image, const char *file_name)\n{\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (file_name != NULL)\n      {\n         FILE *fp = fopen(file_name, \"rb\");\n\n         if (fp != NULL)\n         {\n            if (png_image_read_init(image) != 0)\n            {\n               image->opaque->png_ptr->io_ptr = fp;\n               image->opaque->owned_file = 1;\n               return png_safe_execute(image, png_image_read_header, image);\n            }\n\n            /* Clean up: just the opened file. */\n            (void)fclose(fp);\n         }\n\n         else\n            return png_image_error(image, strerror(errno));\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_begin_read_from_file: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_begin_read_from_file: incorrect PNG_IMAGE_VERSION\");\n\n   return 0;\n}\n#endif /* STDIO */\n\nstatic void PNGCBAPI\npng_image_memory_read(png_structp png_ptr, png_bytep out, png_size_t need)\n{\n   if (png_ptr != NULL)\n   {\n      png_imagep image = png_voidcast(png_imagep, png_ptr->io_ptr);\n      if (image != NULL)\n      {\n         png_controlp cp = image->opaque;\n         if (cp != NULL)\n         {\n            png_const_bytep memory = cp->memory;\n            png_size_t size = cp->size;\n\n            if (memory != NULL && size >= need)\n            {\n               memcpy(out, memory, need);\n               cp->memory = memory + need;\n               cp->size = size - need;\n               return;\n            }\n\n            png_error(png_ptr, \"read beyond end of data\");\n         }\n      }\n\n      png_error(png_ptr, \"invalid memory read\");\n   }\n}\n\nint PNGAPI png_image_begin_read_from_memory(png_imagep image,\n    png_const_voidp memory, png_size_t size)\n{\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (memory != NULL && size > 0)\n      {\n         if (png_image_read_init(image) != 0)\n         {\n            /* Now set the IO functions to read from the memory buffer and\n             * store it into io_ptr.  Again do this in-place to avoid calling a\n             * libpng function that requires error handling.\n             */\n            image->opaque->memory = png_voidcast(png_const_bytep, memory);\n            image->opaque->size = size;\n            image->opaque->png_ptr->io_ptr = image;\n            image->opaque->png_ptr->read_data_fn = png_image_memory_read;\n\n            return png_safe_execute(image, png_image_read_header, image);\n         }\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_begin_read_from_memory: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_begin_read_from_memory: incorrect PNG_IMAGE_VERSION\");\n\n   return 0;\n}\n\n/* Utility function to skip chunks that are not used by the simplified image\n * read functions and an appropriate macro to call it.\n */\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\nstatic void\npng_image_skip_unused_chunks(png_structrp png_ptr)\n{\n   /* Prepare the reader to ignore all recognized chunks whose data will not\n    * be used, i.e., all chunks recognized by libpng except for those\n    * involved in basic image reading:\n    *\n    *    IHDR, PLTE, IDAT, IEND\n    *\n    * Or image data handling:\n    *\n    *    tRNS, bKGD, gAMA, cHRM, sRGB, [iCCP] and sBIT.\n    *\n    * This provides a small performance improvement and eliminates any\n    * potential vulnerability to security problems in the unused chunks.\n    *\n    * At present the iCCP chunk data isn't used, so iCCP chunk can be ignored\n    * too.  This allows the simplified API to be compiled without iCCP support,\n    * however if the support is there the chunk is still checked to detect\n    * errors (which are unfortunately quite common.)\n    */\n   {\n         static PNG_CONST png_byte chunks_to_process[] = {\n            98,  75,  71,  68, '\\0',  /* bKGD */\n            99,  72,  82,  77, '\\0',  /* cHRM */\n           103,  65,  77,  65, '\\0',  /* gAMA */\n#        ifdef PNG_READ_iCCP_SUPPORTED\n           105,  67,  67,  80, '\\0',  /* iCCP */\n#        endif\n           115,  66,  73,  84, '\\0',  /* sBIT */\n           115,  82,  71,  66, '\\0',  /* sRGB */\n           };\n\n       /* Ignore unknown chunks and all other chunks except for the\n        * IHDR, PLTE, tRNS, IDAT, and IEND chunks.\n        */\n       png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_NEVER,\n           NULL, -1);\n\n       /* But do not ignore image data handling chunks */\n       png_set_keep_unknown_chunks(png_ptr, PNG_HANDLE_CHUNK_AS_DEFAULT,\n           chunks_to_process, (int)/*SAFE*/(sizeof chunks_to_process)/5);\n   }\n}\n\n#  define PNG_SKIP_CHUNKS(p) png_image_skip_unused_chunks(p)\n#else\n#  define PNG_SKIP_CHUNKS(p) ((void)0)\n#endif /* HANDLE_AS_UNKNOWN */\n\n/* The following macro gives the exact rounded answer for all values in the\n * range 0..255 (it actually divides by 51.2, but the rounding still generates\n * the correct numbers 0..5\n */\n#define PNG_DIV51(v8) (((v8) * 5 + 130) >> 8)\n\n/* Utility functions to make particular color-maps */\nstatic void\nset_file_encoding(png_image_read_control *display)\n{\n   png_fixed_point g = display->image->opaque->png_ptr->colorspace.gamma;\n   if (png_gamma_significant(g) != 0)\n   {\n      if (png_gamma_not_sRGB(g) != 0)\n      {\n         display->file_encoding = P_FILE;\n         display->gamma_to_linear = png_reciprocal(g);\n      }\n\n      else\n         display->file_encoding = P_sRGB;\n   }\n\n   else\n      display->file_encoding = P_LINEAR8;\n}\n\nstatic unsigned int\ndecode_gamma(png_image_read_control *display, png_uint_32 value, int encoding)\n{\n   if (encoding == P_FILE) /* double check */\n      encoding = display->file_encoding;\n\n   if (encoding == P_NOTSET) /* must be the file encoding */\n   {\n      set_file_encoding(display);\n      encoding = display->file_encoding;\n   }\n\n   switch (encoding)\n   {\n      case P_FILE:\n         value = png_gamma_16bit_correct(value*257, display->gamma_to_linear);\n         break;\n\n      case P_sRGB:\n         value = png_sRGB_table[value];\n         break;\n\n      case P_LINEAR:\n         break;\n\n      case P_LINEAR8:\n         value *= 257;\n         break;\n\n#ifdef __GNUC__\n      default:\n         png_error(display->image->opaque->png_ptr,\n             \"unexpected encoding (internal error)\");\n#endif\n   }\n\n   return value;\n}\n\nstatic png_uint_32\npng_colormap_compose(png_image_read_control *display,\n    png_uint_32 foreground, int foreground_encoding, png_uint_32 alpha,\n    png_uint_32 background, int encoding)\n{\n   /* The file value is composed on the background, the background has the given\n    * encoding and so does the result, the file is encoded with P_FILE and the\n    * file and alpha are 8-bit values.  The (output) encoding will always be\n    * P_LINEAR or P_sRGB.\n    */\n   png_uint_32 f = decode_gamma(display, foreground, foreground_encoding);\n   png_uint_32 b = decode_gamma(display, background, encoding);\n\n   /* The alpha is always an 8-bit value (it comes from the palette), the value\n    * scaled by 255 is what PNG_sRGB_FROM_LINEAR requires.\n    */\n   f = f * alpha + b * (255-alpha);\n\n   if (encoding == P_LINEAR)\n   {\n      /* Scale to 65535; divide by 255, approximately (in fact this is extremely\n       * accurate, it divides by 255.00000005937181414556, with no overflow.)\n       */\n      f *= 257; /* Now scaled by 65535 */\n      f += f >> 16;\n      f = (f+32768) >> 16;\n   }\n\n   else /* P_sRGB */\n      f = PNG_sRGB_FROM_LINEAR(f);\n\n   return f;\n}\n\n/* NOTE: P_LINEAR values to this routine must be 16-bit, but P_FILE values must\n * be 8-bit.\n */\nstatic void\npng_create_colormap_entry(png_image_read_control *display,\n    png_uint_32 ip, png_uint_32 red, png_uint_32 green, png_uint_32 blue,\n    png_uint_32 alpha, int encoding)\n{\n   png_imagep image = display->image;\n   const int output_encoding = (image->format & PNG_FORMAT_FLAG_LINEAR) != 0 ?\n       P_LINEAR : P_sRGB;\n   const int convert_to_Y = (image->format & PNG_FORMAT_FLAG_COLOR) == 0 &&\n       (red != green || green != blue);\n\n   if (ip > 255)\n      png_error(image->opaque->png_ptr, \"color-map index out of range\");\n\n   /* Update the cache with whether the file gamma is significantly different\n    * from sRGB.\n    */\n   if (encoding == P_FILE)\n   {\n      if (display->file_encoding == P_NOTSET)\n         set_file_encoding(display);\n\n      /* Note that the cached value may be P_FILE too, but if it is then the\n       * gamma_to_linear member has been set.\n       */\n      encoding = display->file_encoding;\n   }\n\n   if (encoding == P_FILE)\n   {\n      png_fixed_point g = display->gamma_to_linear;\n\n      red = png_gamma_16bit_correct(red*257, g);\n      green = png_gamma_16bit_correct(green*257, g);\n      blue = png_gamma_16bit_correct(blue*257, g);\n\n      if (convert_to_Y != 0 || output_encoding == P_LINEAR)\n      {\n         alpha *= 257;\n         encoding = P_LINEAR;\n      }\n\n      else\n      {\n         red = PNG_sRGB_FROM_LINEAR(red * 255);\n         green = PNG_sRGB_FROM_LINEAR(green * 255);\n         blue = PNG_sRGB_FROM_LINEAR(blue * 255);\n         encoding = P_sRGB;\n      }\n   }\n\n   else if (encoding == P_LINEAR8)\n   {\n      /* This encoding occurs quite frequently in test cases because PngSuite\n       * includes a gAMA 1.0 chunk with most images.\n       */\n      red *= 257;\n      green *= 257;\n      blue *= 257;\n      alpha *= 257;\n      encoding = P_LINEAR;\n   }\n\n   else if (encoding == P_sRGB &&\n       (convert_to_Y  != 0 || output_encoding == P_LINEAR))\n   {\n      /* The values are 8-bit sRGB values, but must be converted to 16-bit\n       * linear.\n       */\n      red = png_sRGB_table[red];\n      green = png_sRGB_table[green];\n      blue = png_sRGB_table[blue];\n      alpha *= 257;\n      encoding = P_LINEAR;\n   }\n\n   /* This is set if the color isn't gray but the output is. */\n   if (encoding == P_LINEAR)\n   {\n      if (convert_to_Y != 0)\n      {\n         /* NOTE: these values are copied from png_do_rgb_to_gray */\n         png_uint_32 y = (png_uint_32)6968 * red  + (png_uint_32)23434 * green +\n            (png_uint_32)2366 * blue;\n\n         if (output_encoding == P_LINEAR)\n            y = (y + 16384) >> 15;\n\n         else\n         {\n            /* y is scaled by 32768, we need it scaled by 255: */\n            y = (y + 128) >> 8;\n            y *= 255;\n            y = PNG_sRGB_FROM_LINEAR((y + 64) >> 7);\n            alpha = PNG_DIV257(alpha);\n            encoding = P_sRGB;\n         }\n\n         blue = red = green = y;\n      }\n\n      else if (output_encoding == P_sRGB)\n      {\n         red = PNG_sRGB_FROM_LINEAR(red * 255);\n         green = PNG_sRGB_FROM_LINEAR(green * 255);\n         blue = PNG_sRGB_FROM_LINEAR(blue * 255);\n         alpha = PNG_DIV257(alpha);\n         encoding = P_sRGB;\n      }\n   }\n\n   if (encoding != output_encoding)\n      png_error(image->opaque->png_ptr, \"bad encoding (internal error)\");\n\n   /* Store the value. */\n   {\n#     ifdef PNG_FORMAT_AFIRST_SUPPORTED\n         const int afirst = (image->format & PNG_FORMAT_FLAG_AFIRST) != 0 &&\n            (image->format & PNG_FORMAT_FLAG_ALPHA) != 0;\n#     else\n#        define afirst 0\n#     endif\n#     ifdef PNG_FORMAT_BGR_SUPPORTED\n         const int bgr = (image->format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;\n#     else\n#        define bgr 0\n#     endif\n\n      if (output_encoding == P_LINEAR)\n      {\n         png_uint_16p entry = png_voidcast(png_uint_16p, display->colormap);\n\n         entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format);\n\n         /* The linear 16-bit values must be pre-multiplied by the alpha channel\n          * value, if less than 65535 (this is, effectively, composite on black\n          * if the alpha channel is removed.)\n          */\n         switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))\n         {\n            case 4:\n               entry[afirst ? 0 : 3] = (png_uint_16)alpha;\n               /* FALL THROUGH */\n\n            case 3:\n               if (alpha < 65535)\n               {\n                  if (alpha > 0)\n                  {\n                     blue = (blue * alpha + 32767U)/65535U;\n                     green = (green * alpha + 32767U)/65535U;\n                     red = (red * alpha + 32767U)/65535U;\n                  }\n\n                  else\n                     red = green = blue = 0;\n               }\n               entry[afirst + (2 ^ bgr)] = (png_uint_16)blue;\n               entry[afirst + 1] = (png_uint_16)green;\n               entry[afirst + bgr] = (png_uint_16)red;\n               break;\n\n            case 2:\n               entry[1 ^ afirst] = (png_uint_16)alpha;\n               /* FALL THROUGH */\n\n            case 1:\n               if (alpha < 65535)\n               {\n                  if (alpha > 0)\n                     green = (green * alpha + 32767U)/65535U;\n\n                  else\n                     green = 0;\n               }\n               entry[afirst] = (png_uint_16)green;\n               break;\n\n            default:\n               break;\n         }\n      }\n\n      else /* output encoding is P_sRGB */\n      {\n         png_bytep entry = png_voidcast(png_bytep, display->colormap);\n\n         entry += ip * PNG_IMAGE_SAMPLE_CHANNELS(image->format);\n\n         switch (PNG_IMAGE_SAMPLE_CHANNELS(image->format))\n         {\n            case 4:\n               entry[afirst ? 0 : 3] = (png_byte)alpha;\n            case 3:\n               entry[afirst + (2 ^ bgr)] = (png_byte)blue;\n               entry[afirst + 1] = (png_byte)green;\n               entry[afirst + bgr] = (png_byte)red;\n               break;\n\n            case 2:\n               entry[1 ^ afirst] = (png_byte)alpha;\n            case 1:\n               entry[afirst] = (png_byte)green;\n               break;\n\n            default:\n               break;\n         }\n      }\n\n#     ifdef afirst\n#        undef afirst\n#     endif\n#     ifdef bgr\n#        undef bgr\n#     endif\n   }\n}\n\nstatic int\nmake_gray_file_colormap(png_image_read_control *display)\n{\n   unsigned int i;\n\n   for (i=0; i<256; ++i)\n      png_create_colormap_entry(display, i, i, i, i, 255, P_FILE);\n\n   return i;\n}\n\nstatic int\nmake_gray_colormap(png_image_read_control *display)\n{\n   unsigned int i;\n\n   for (i=0; i<256; ++i)\n      png_create_colormap_entry(display, i, i, i, i, 255, P_sRGB);\n\n   return i;\n}\n#define PNG_GRAY_COLORMAP_ENTRIES 256\n\nstatic int\nmake_ga_colormap(png_image_read_control *display)\n{\n   unsigned int i, a;\n\n   /* Alpha is retained, the output will be a color-map with entries\n    * selected by six levels of alpha.  One transparent entry, 6 gray\n    * levels for all the intermediate alpha values, leaving 230 entries\n    * for the opaque grays.  The color-map entries are the six values\n    * [0..5]*51, the GA processing uses PNG_DIV51(value) to find the\n    * relevant entry.\n    *\n    * if (alpha > 229) // opaque\n    * {\n    *    // The 231 entries are selected to make the math below work:\n    *    base = 0;\n    *    entry = (231 * gray + 128) >> 8;\n    * }\n    * else if (alpha < 26) // transparent\n    * {\n    *    base = 231;\n    *    entry = 0;\n    * }\n    * else // partially opaque\n    * {\n    *    base = 226 + 6 * PNG_DIV51(alpha);\n    *    entry = PNG_DIV51(gray);\n    * }\n    */\n   i = 0;\n   while (i < 231)\n   {\n      unsigned int gray = (i * 256 + 115) / 231;\n      png_create_colormap_entry(display, i++, gray, gray, gray, 255, P_sRGB);\n   }\n\n   /* 255 is used here for the component values for consistency with the code\n    * that undoes premultiplication in pngwrite.c.\n    */\n   png_create_colormap_entry(display, i++, 255, 255, 255, 0, P_sRGB);\n\n   for (a=1; a<5; ++a)\n   {\n      unsigned int g;\n\n      for (g=0; g<6; ++g)\n         png_create_colormap_entry(display, i++, g*51, g*51, g*51, a*51,\n             P_sRGB);\n   }\n\n   return i;\n}\n\n#define PNG_GA_COLORMAP_ENTRIES 256\n\nstatic int\nmake_rgb_colormap(png_image_read_control *display)\n{\n   unsigned int i, r;\n\n   /* Build a 6x6x6 opaque RGB cube */\n   for (i=r=0; r<6; ++r)\n   {\n      unsigned int g;\n\n      for (g=0; g<6; ++g)\n      {\n         unsigned int b;\n\n         for (b=0; b<6; ++b)\n            png_create_colormap_entry(display, i++, r*51, g*51, b*51, 255,\n                P_sRGB);\n      }\n   }\n\n   return i;\n}\n\n#define PNG_RGB_COLORMAP_ENTRIES 216\n\n/* Return a palette index to the above palette given three 8-bit sRGB values. */\n#define PNG_RGB_INDEX(r,g,b) \\\n   ((png_byte)(6 * (6 * PNG_DIV51(r) + PNG_DIV51(g)) + PNG_DIV51(b)))\n\nstatic int\npng_image_read_colormap(png_voidp argument)\n{\n   png_image_read_control *display =\n      png_voidcast(png_image_read_control*, argument);\n   const png_imagep image = display->image;\n\n   const png_structrp png_ptr = image->opaque->png_ptr;\n   const png_uint_32 output_format = image->format;\n   const int output_encoding = (output_format & PNG_FORMAT_FLAG_LINEAR) != 0 ?\n      P_LINEAR : P_sRGB;\n\n   unsigned int cmap_entries;\n   unsigned int output_processing;        /* Output processing option */\n   unsigned int data_encoding = P_NOTSET; /* Encoding libpng must produce */\n\n   /* Background information; the background color and the index of this color\n    * in the color-map if it exists (else 256).\n    */\n   unsigned int background_index = 256;\n   png_uint_32 back_r, back_g, back_b;\n\n   /* Flags to accumulate things that need to be done to the input. */\n   int expand_tRNS = 0;\n\n   /* Exclude the NYI feature of compositing onto a color-mapped buffer; it is\n    * very difficult to do, the results look awful, and it is difficult to see\n    * what possible use it is because the application can't control the\n    * color-map.\n    */\n   if (((png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0 ||\n         png_ptr->num_trans > 0) /* alpha in input */ &&\n      ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0) /* no alpha in output */)\n   {\n      if (output_encoding == P_LINEAR) /* compose on black */\n         back_b = back_g = back_r = 0;\n\n      else if (display->background == NULL /* no way to remove it */)\n         png_error(png_ptr,\n             \"background color must be supplied to remove alpha/transparency\");\n\n      /* Get a copy of the background color (this avoids repeating the checks\n       * below.)  The encoding is 8-bit sRGB or 16-bit linear, depending on the\n       * output format.\n       */\n      else\n      {\n         back_g = display->background->green;\n         if ((output_format & PNG_FORMAT_FLAG_COLOR) != 0)\n         {\n            back_r = display->background->red;\n            back_b = display->background->blue;\n         }\n         else\n            back_b = back_r = back_g;\n      }\n   }\n\n   else if (output_encoding == P_LINEAR)\n      back_b = back_r = back_g = 65535;\n\n   else\n      back_b = back_r = back_g = 255;\n\n   /* Default the input file gamma if required - this is necessary because\n    * libpng assumes that if no gamma information is present the data is in the\n    * output format, but the simplified API deduces the gamma from the input\n    * format.\n    */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_GAMMA) == 0)\n   {\n      /* Do this directly, not using the png_colorspace functions, to ensure\n       * that it happens even if the colorspace is invalid (though probably if\n       * it is the setting will be ignored)  Note that the same thing can be\n       * achieved at the application interface with png_set_gAMA.\n       */\n      if (png_ptr->bit_depth == 16 &&\n         (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)\n         png_ptr->colorspace.gamma = PNG_GAMMA_LINEAR;\n\n      else\n         png_ptr->colorspace.gamma = PNG_GAMMA_sRGB_INVERSE;\n\n      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;\n   }\n\n   /* Decide what to do based on the PNG color type of the input data.  The\n    * utility function png_create_colormap_entry deals with most aspects of the\n    * output transformations; this code works out how to produce bytes of\n    * color-map entries from the original format.\n    */\n   switch (png_ptr->color_type)\n   {\n      case PNG_COLOR_TYPE_GRAY:\n         if (png_ptr->bit_depth <= 8)\n         {\n            /* There at most 256 colors in the output, regardless of\n             * transparency.\n             */\n            unsigned int step, i, val, trans = 256/*ignore*/, back_alpha = 0;\n\n            cmap_entries = 1U << png_ptr->bit_depth;\n            if (cmap_entries > image->colormap_entries)\n               png_error(png_ptr, \"gray[8] color-map: too few entries\");\n\n            step = 255 / (cmap_entries - 1);\n            output_processing = PNG_CMAP_NONE;\n\n            /* If there is a tRNS chunk then this either selects a transparent\n             * value or, if the output has no alpha, the background color.\n             */\n            if (png_ptr->num_trans > 0)\n            {\n               trans = png_ptr->trans_color.gray;\n\n               if ((output_format & PNG_FORMAT_FLAG_ALPHA) == 0)\n                  back_alpha = output_encoding == P_LINEAR ? 65535 : 255;\n            }\n\n            /* png_create_colormap_entry just takes an RGBA and writes the\n             * corresponding color-map entry using the format from 'image',\n             * including the required conversion to sRGB or linear as\n             * appropriate.  The input values are always either sRGB (if the\n             * gamma correction flag is 0) or 0..255 scaled file encoded values\n             * (if the function must gamma correct them).\n             */\n            for (i=val=0; i<cmap_entries; ++i, val += step)\n            {\n               /* 'i' is a file value.  While this will result in duplicated\n                * entries for 8-bit non-sRGB encoded files it is necessary to\n                * have non-gamma corrected values to do tRNS handling.\n                */\n               if (i != trans)\n                  png_create_colormap_entry(display, i, val, val, val, 255,\n                      P_FILE/*8-bit with file gamma*/);\n\n               /* Else this entry is transparent.  The colors don't matter if\n                * there is an alpha channel (back_alpha == 0), but it does no\n                * harm to pass them in; the values are not set above so this\n                * passes in white.\n                *\n                * NOTE: this preserves the full precision of the application\n                * supplied background color when it is used.\n                */\n               else\n                  png_create_colormap_entry(display, i, back_r, back_g, back_b,\n                      back_alpha, output_encoding);\n            }\n\n            /* We need libpng to preserve the original encoding. */\n            data_encoding = P_FILE;\n\n            /* The rows from libpng, while technically gray values, are now also\n             * color-map indices; however, they may need to be expanded to 1\n             * byte per pixel.  This is what png_set_packing does (i.e., it\n             * unpacks the bit values into bytes.)\n             */\n            if (png_ptr->bit_depth < 8)\n               png_set_packing(png_ptr);\n         }\n\n         else /* bit depth is 16 */\n         {\n            /* The 16-bit input values can be converted directly to 8-bit gamma\n             * encoded values; however, if a tRNS chunk is present 257 color-map\n             * entries are required.  This means that the extra entry requires\n             * special processing; add an alpha channel, sacrifice gray level\n             * 254 and convert transparent (alpha==0) entries to that.\n             *\n             * Use libpng to chop the data to 8 bits.  Convert it to sRGB at the\n             * same time to minimize quality loss.  If a tRNS chunk is present\n             * this means libpng must handle it too; otherwise it is impossible\n             * to do the exact match on the 16-bit value.\n             *\n             * If the output has no alpha channel *and* the background color is\n             * gray then it is possible to let libpng handle the substitution by\n             * ensuring that the corresponding gray level matches the background\n             * color exactly.\n             */\n            data_encoding = P_sRGB;\n\n            if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)\n               png_error(png_ptr, \"gray[16] color-map: too few entries\");\n\n            cmap_entries = make_gray_colormap(display);\n\n            if (png_ptr->num_trans > 0)\n            {\n               unsigned int back_alpha;\n\n               if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n                  back_alpha = 0;\n\n               else\n               {\n                  if (back_r == back_g && back_g == back_b)\n                  {\n                     /* Background is gray; no special processing will be\n                      * required.\n                      */\n                     png_color_16 c;\n                     png_uint_32 gray = back_g;\n\n                     if (output_encoding == P_LINEAR)\n                     {\n                        gray = PNG_sRGB_FROM_LINEAR(gray * 255);\n\n                        /* And make sure the corresponding palette entry\n                         * matches.\n                         */\n                        png_create_colormap_entry(display, gray, back_g, back_g,\n                            back_g, 65535, P_LINEAR);\n                     }\n\n                     /* The background passed to libpng, however, must be the\n                      * sRGB value.\n                      */\n                     c.index = 0; /*unused*/\n                     c.gray = c.red = c.green = c.blue = (png_uint_16)gray;\n\n                     /* NOTE: does this work without expanding tRNS to alpha?\n                      * It should be the color->gray case below apparently\n                      * doesn't.\n                      */\n                     png_set_background_fixed(png_ptr, &c,\n                         PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,\n                         0/*gamma: not used*/);\n\n                     output_processing = PNG_CMAP_NONE;\n                     break;\n                  }\n#ifdef __COVERITY__\n                 /* Coverity claims that output_encoding cannot be 2 (P_LINEAR)\n                  * here.\n                  */\n                  back_alpha = 255;\n#else\n                  back_alpha = output_encoding == P_LINEAR ? 65535 : 255;\n#endif\n               }\n\n               /* output_processing means that the libpng-processed row will be\n                * 8-bit GA and it has to be processing to single byte color-map\n                * values.  Entry 254 is replaced by either a completely\n                * transparent entry or by the background color at full\n                * precision (and the background color is not a simple gray\n                * level in this case.)\n                */\n               expand_tRNS = 1;\n               output_processing = PNG_CMAP_TRANS;\n               background_index = 254;\n\n               /* And set (overwrite) color-map entry 254 to the actual\n                * background color at full precision.\n                */\n               png_create_colormap_entry(display, 254, back_r, back_g, back_b,\n                   back_alpha, output_encoding);\n            }\n\n            else\n               output_processing = PNG_CMAP_NONE;\n         }\n         break;\n\n      case PNG_COLOR_TYPE_GRAY_ALPHA:\n         /* 8-bit or 16-bit PNG with two channels - gray and alpha.  A minimum\n          * of 65536 combinations.  If, however, the alpha channel is to be\n          * removed there are only 256 possibilities if the background is gray.\n          * (Otherwise there is a subset of the 65536 possibilities defined by\n          * the triangle between black, white and the background color.)\n          *\n          * Reduce 16-bit files to 8-bit and sRGB encode the result.  No need to\n          * worry about tRNS matching - tRNS is ignored if there is an alpha\n          * channel.\n          */\n         data_encoding = P_sRGB;\n\n         if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n         {\n            if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)\n               png_error(png_ptr, \"gray+alpha color-map: too few entries\");\n\n            cmap_entries = make_ga_colormap(display);\n\n            background_index = PNG_CMAP_GA_BACKGROUND;\n            output_processing = PNG_CMAP_GA;\n         }\n\n         else /* alpha is removed */\n         {\n            /* Alpha must be removed as the PNG data is processed when the\n             * background is a color because the G and A channels are\n             * independent and the vector addition (non-parallel vectors) is a\n             * 2-D problem.\n             *\n             * This can be reduced to the same algorithm as above by making a\n             * colormap containing gray levels (for the opaque grays), a\n             * background entry (for a transparent pixel) and a set of four six\n             * level color values, one set for each intermediate alpha value.\n             * See the comments in make_ga_colormap for how this works in the\n             * per-pixel processing.\n             *\n             * If the background is gray, however, we only need a 256 entry gray\n             * level color map.  It is sufficient to make the entry generated\n             * for the background color be exactly the color specified.\n             */\n            if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0 ||\n               (back_r == back_g && back_g == back_b))\n            {\n               /* Background is gray; no special processing will be required. */\n               png_color_16 c;\n               png_uint_32 gray = back_g;\n\n               if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)\n                  png_error(png_ptr, \"gray-alpha color-map: too few entries\");\n\n               cmap_entries = make_gray_colormap(display);\n\n               if (output_encoding == P_LINEAR)\n               {\n                  gray = PNG_sRGB_FROM_LINEAR(gray * 255);\n\n                  /* And make sure the corresponding palette entry matches. */\n                  png_create_colormap_entry(display, gray, back_g, back_g,\n                      back_g, 65535, P_LINEAR);\n               }\n\n               /* The background passed to libpng, however, must be the sRGB\n                * value.\n                */\n               c.index = 0; /*unused*/\n               c.gray = c.red = c.green = c.blue = (png_uint_16)gray;\n\n               png_set_background_fixed(png_ptr, &c,\n                   PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,\n                   0/*gamma: not used*/);\n\n               output_processing = PNG_CMAP_NONE;\n            }\n\n            else\n            {\n               png_uint_32 i, a;\n\n               /* This is the same as png_make_ga_colormap, above, except that\n                * the entries are all opaque.\n                */\n               if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)\n                  png_error(png_ptr, \"ga-alpha color-map: too few entries\");\n\n               i = 0;\n               while (i < 231)\n               {\n                  png_uint_32 gray = (i * 256 + 115) / 231;\n                  png_create_colormap_entry(display, i++, gray, gray, gray,\n                      255, P_sRGB);\n               }\n\n               /* NOTE: this preserves the full precision of the application\n                * background color.\n                */\n               background_index = i;\n               png_create_colormap_entry(display, i++, back_r, back_g, back_b,\n#ifdef __COVERITY__\n                   /* Coverity claims that output_encoding\n                    * cannot be 2 (P_LINEAR) here.\n                    */ 255U,\n#else\n                    output_encoding == P_LINEAR ? 65535U : 255U,\n#endif\n                    output_encoding);\n\n               /* For non-opaque input composite on the sRGB background - this\n                * requires inverting the encoding for each component.  The input\n                * is still converted to the sRGB encoding because this is a\n                * reasonable approximate to the logarithmic curve of human\n                * visual sensitivity, at least over the narrow range which PNG\n                * represents.  Consequently 'G' is always sRGB encoded, while\n                * 'A' is linear.  We need the linear background colors.\n                */\n               if (output_encoding == P_sRGB) /* else already linear */\n               {\n                  /* This may produce a value not exactly matching the\n                   * background, but that's ok because these numbers are only\n                   * used when alpha != 0\n                   */\n                  back_r = png_sRGB_table[back_r];\n                  back_g = png_sRGB_table[back_g];\n                  back_b = png_sRGB_table[back_b];\n               }\n\n               for (a=1; a<5; ++a)\n               {\n                  unsigned int g;\n\n                  /* PNG_sRGB_FROM_LINEAR expects a 16-bit linear value scaled\n                   * by an 8-bit alpha value (0..255).\n                   */\n                  png_uint_32 alpha = 51 * a;\n                  png_uint_32 back_rx = (255-alpha) * back_r;\n                  png_uint_32 back_gx = (255-alpha) * back_g;\n                  png_uint_32 back_bx = (255-alpha) * back_b;\n\n                  for (g=0; g<6; ++g)\n                  {\n                     png_uint_32 gray = png_sRGB_table[g*51] * alpha;\n\n                     png_create_colormap_entry(display, i++,\n                         PNG_sRGB_FROM_LINEAR(gray + back_rx),\n                         PNG_sRGB_FROM_LINEAR(gray + back_gx),\n                         PNG_sRGB_FROM_LINEAR(gray + back_bx), 255, P_sRGB);\n                  }\n               }\n\n               cmap_entries = i;\n               output_processing = PNG_CMAP_GA;\n            }\n         }\n         break;\n\n      case PNG_COLOR_TYPE_RGB:\n      case PNG_COLOR_TYPE_RGB_ALPHA:\n         /* Exclude the case where the output is gray; we can always handle this\n          * with the cases above.\n          */\n         if ((output_format & PNG_FORMAT_FLAG_COLOR) == 0)\n         {\n            /* The color-map will be grayscale, so we may as well convert the\n             * input RGB values to a simple grayscale and use the grayscale\n             * code above.\n             *\n             * NOTE: calling this apparently damages the recognition of the\n             * transparent color in background color handling; call\n             * png_set_tRNS_to_alpha before png_set_background_fixed.\n             */\n            png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE, -1,\n                -1);\n            data_encoding = P_sRGB;\n\n            /* The output will now be one or two 8-bit gray or gray+alpha\n             * channels.  The more complex case arises when the input has alpha.\n             */\n            if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n               png_ptr->num_trans > 0) &&\n               (output_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n            {\n               /* Both input and output have an alpha channel, so no background\n                * processing is required; just map the GA bytes to the right\n                * color-map entry.\n                */\n               expand_tRNS = 1;\n\n               if (PNG_GA_COLORMAP_ENTRIES > image->colormap_entries)\n                  png_error(png_ptr, \"rgb[ga] color-map: too few entries\");\n\n               cmap_entries = make_ga_colormap(display);\n               background_index = PNG_CMAP_GA_BACKGROUND;\n               output_processing = PNG_CMAP_GA;\n            }\n\n            else\n            {\n               /* Either the input or the output has no alpha channel, so there\n                * will be no non-opaque pixels in the color-map; it will just be\n                * grayscale.\n                */\n               if (PNG_GRAY_COLORMAP_ENTRIES > image->colormap_entries)\n                  png_error(png_ptr, \"rgb[gray] color-map: too few entries\");\n\n               /* Ideally this code would use libpng to do the gamma correction,\n                * but if an input alpha channel is to be removed we will hit the\n                * libpng bug in gamma+compose+rgb-to-gray (the double gamma\n                * correction bug).  Fix this by dropping the gamma correction in\n                * this case and doing it in the palette; this will result in\n                * duplicate palette entries, but that's better than the\n                * alternative of double gamma correction.\n                */\n               if ((png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n                  png_ptr->num_trans > 0) &&\n                  png_gamma_not_sRGB(png_ptr->colorspace.gamma) != 0)\n               {\n                  cmap_entries = make_gray_file_colormap(display);\n                  data_encoding = P_FILE;\n               }\n\n               else\n                  cmap_entries = make_gray_colormap(display);\n\n               /* But if the input has alpha or transparency it must be removed\n                */\n               if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n                  png_ptr->num_trans > 0)\n               {\n                  png_color_16 c;\n                  png_uint_32 gray = back_g;\n\n                  /* We need to ensure that the application background exists in\n                   * the colormap and that completely transparent pixels map to\n                   * it.  Achieve this simply by ensuring that the entry\n                   * selected for the background really is the background color.\n                   */\n                  if (data_encoding == P_FILE) /* from the fixup above */\n                  {\n                     /* The app supplied a gray which is in output_encoding, we\n                      * need to convert it to a value of the input (P_FILE)\n                      * encoding then set this palette entry to the required\n                      * output encoding.\n                      */\n                     if (output_encoding == P_sRGB)\n                        gray = png_sRGB_table[gray]; /* now P_LINEAR */\n\n                     gray = PNG_DIV257(png_gamma_16bit_correct(gray,\n                         png_ptr->colorspace.gamma)); /* now P_FILE */\n\n                     /* And make sure the corresponding palette entry contains\n                      * exactly the required sRGB value.\n                      */\n                     png_create_colormap_entry(display, gray, back_g, back_g,\n                         back_g, 0/*unused*/, output_encoding);\n                  }\n\n                  else if (output_encoding == P_LINEAR)\n                  {\n                     gray = PNG_sRGB_FROM_LINEAR(gray * 255);\n\n                     /* And make sure the corresponding palette entry matches.\n                      */\n                     png_create_colormap_entry(display, gray, back_g, back_g,\n                        back_g, 0/*unused*/, P_LINEAR);\n                  }\n\n                  /* The background passed to libpng, however, must be the\n                   * output (normally sRGB) value.\n                   */\n                  c.index = 0; /*unused*/\n                  c.gray = c.red = c.green = c.blue = (png_uint_16)gray;\n\n                  /* NOTE: the following is apparently a bug in libpng. Without\n                   * it the transparent color recognition in\n                   * png_set_background_fixed seems to go wrong.\n                   */\n                  expand_tRNS = 1;\n                  png_set_background_fixed(png_ptr, &c,\n                      PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,\n                      0/*gamma: not used*/);\n               }\n\n               output_processing = PNG_CMAP_NONE;\n            }\n         }\n\n         else /* output is color */\n         {\n            /* We could use png_quantize here so long as there is no transparent\n             * color or alpha; png_quantize ignores alpha.  Easier overall just\n             * to do it once and using PNG_DIV51 on the 6x6x6 reduced RGB cube.\n             * Consequently we always want libpng to produce sRGB data.\n             */\n            data_encoding = P_sRGB;\n\n            /* Is there any transparency or alpha? */\n            if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n               png_ptr->num_trans > 0)\n            {\n               /* Is there alpha in the output too?  If so all four channels are\n                * processed into a special RGB cube with alpha support.\n                */\n               if ((output_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n               {\n                  png_uint_32 r;\n\n                  if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries)\n                     png_error(png_ptr, \"rgb+alpha color-map: too few entries\");\n\n                  cmap_entries = make_rgb_colormap(display);\n\n                  /* Add a transparent entry. */\n                  png_create_colormap_entry(display, cmap_entries, 255, 255,\n                      255, 0, P_sRGB);\n\n                  /* This is stored as the background index for the processing\n                   * algorithm.\n                   */\n                  background_index = cmap_entries++;\n\n                  /* Add 27 r,g,b entries each with alpha 0.5. */\n                  for (r=0; r<256; r = (r << 1) | 0x7f)\n                  {\n                     png_uint_32 g;\n\n                     for (g=0; g<256; g = (g << 1) | 0x7f)\n                     {\n                        png_uint_32 b;\n\n                        /* This generates components with the values 0, 127 and\n                         * 255\n                         */\n                        for (b=0; b<256; b = (b << 1) | 0x7f)\n                           png_create_colormap_entry(display, cmap_entries++,\n                               r, g, b, 128, P_sRGB);\n                     }\n                  }\n\n                  expand_tRNS = 1;\n                  output_processing = PNG_CMAP_RGB_ALPHA;\n               }\n\n               else\n               {\n                  /* Alpha/transparency must be removed.  The background must\n                   * exist in the color map (achieved by setting adding it after\n                   * the 666 color-map).  If the standard processing code will\n                   * pick up this entry automatically that's all that is\n                   * required; libpng can be called to do the background\n                   * processing.\n                   */\n                  unsigned int sample_size =\n                     PNG_IMAGE_SAMPLE_SIZE(output_format);\n                  png_uint_32 r, g, b; /* sRGB background */\n\n                  if (PNG_RGB_COLORMAP_ENTRIES+1+27 > image->colormap_entries)\n                     png_error(png_ptr, \"rgb-alpha color-map: too few entries\");\n\n                  cmap_entries = make_rgb_colormap(display);\n\n                  png_create_colormap_entry(display, cmap_entries, back_r,\n                      back_g, back_b, 0/*unused*/, output_encoding);\n\n                  if (output_encoding == P_LINEAR)\n                  {\n                     r = PNG_sRGB_FROM_LINEAR(back_r * 255);\n                     g = PNG_sRGB_FROM_LINEAR(back_g * 255);\n                     b = PNG_sRGB_FROM_LINEAR(back_b * 255);\n                  }\n\n                  else\n                  {\n                     r = back_r;\n                     g = back_g;\n                     b = back_g;\n                  }\n\n                  /* Compare the newly-created color-map entry with the one the\n                   * PNG_CMAP_RGB algorithm will use.  If the two entries don't\n                   * match, add the new one and set this as the background\n                   * index.\n                   */\n                  if (memcmp((png_const_bytep)display->colormap +\n                      sample_size * cmap_entries,\n                      (png_const_bytep)display->colormap +\n                          sample_size * PNG_RGB_INDEX(r,g,b),\n                     sample_size) != 0)\n                  {\n                     /* The background color must be added. */\n                     background_index = cmap_entries++;\n\n                     /* Add 27 r,g,b entries each with created by composing with\n                      * the background at alpha 0.5.\n                      */\n                     for (r=0; r<256; r = (r << 1) | 0x7f)\n                     {\n                        for (g=0; g<256; g = (g << 1) | 0x7f)\n                        {\n                           /* This generates components with the values 0, 127\n                            * and 255\n                            */\n                           for (b=0; b<256; b = (b << 1) | 0x7f)\n                              png_create_colormap_entry(display, cmap_entries++,\n                                  png_colormap_compose(display, r, P_sRGB, 128,\n                                      back_r, output_encoding),\n                                  png_colormap_compose(display, g, P_sRGB, 128,\n                                      back_g, output_encoding),\n                                  png_colormap_compose(display, b, P_sRGB, 128,\n                                      back_b, output_encoding),\n                                  0/*unused*/, output_encoding);\n                        }\n                     }\n\n                     expand_tRNS = 1;\n                     output_processing = PNG_CMAP_RGB_ALPHA;\n                  }\n\n                  else /* background color is in the standard color-map */\n                  {\n                     png_color_16 c;\n\n                     c.index = 0; /*unused*/\n                     c.red = (png_uint_16)back_r;\n                     c.gray = c.green = (png_uint_16)back_g;\n                     c.blue = (png_uint_16)back_b;\n\n                     png_set_background_fixed(png_ptr, &c,\n                         PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,\n                         0/*gamma: not used*/);\n\n                     output_processing = PNG_CMAP_RGB;\n                  }\n               }\n            }\n\n            else /* no alpha or transparency in the input */\n            {\n               /* Alpha in the output is irrelevant, simply map the opaque input\n                * pixels to the 6x6x6 color-map.\n                */\n               if (PNG_RGB_COLORMAP_ENTRIES > image->colormap_entries)\n                  png_error(png_ptr, \"rgb color-map: too few entries\");\n\n               cmap_entries = make_rgb_colormap(display);\n               output_processing = PNG_CMAP_RGB;\n            }\n         }\n         break;\n\n      case PNG_COLOR_TYPE_PALETTE:\n         /* It's already got a color-map.  It may be necessary to eliminate the\n          * tRNS entries though.\n          */\n         {\n            unsigned int num_trans = png_ptr->num_trans;\n            png_const_bytep trans = num_trans > 0 ? png_ptr->trans_alpha : NULL;\n            png_const_colorp colormap = png_ptr->palette;\n            const int do_background = trans != NULL &&\n               (output_format & PNG_FORMAT_FLAG_ALPHA) == 0;\n            unsigned int i;\n\n            /* Just in case: */\n            if (trans == NULL)\n               num_trans = 0;\n\n            output_processing = PNG_CMAP_NONE;\n            data_encoding = P_FILE; /* Don't change from color-map indices */\n            cmap_entries = png_ptr->num_palette;\n            if (cmap_entries > 256)\n               cmap_entries = 256;\n\n            if (cmap_entries > image->colormap_entries)\n               png_error(png_ptr, \"palette color-map: too few entries\");\n\n            for (i=0; i < cmap_entries; ++i)\n            {\n               if (do_background != 0 && i < num_trans && trans[i] < 255)\n               {\n                  if (trans[i] == 0)\n                     png_create_colormap_entry(display, i, back_r, back_g,\n                         back_b, 0, output_encoding);\n\n                  else\n                  {\n                     /* Must compose the PNG file color in the color-map entry\n                      * on the sRGB color in 'back'.\n                      */\n                     png_create_colormap_entry(display, i,\n                         png_colormap_compose(display, colormap[i].red,\n                             P_FILE, trans[i], back_r, output_encoding),\n                         png_colormap_compose(display, colormap[i].green,\n                             P_FILE, trans[i], back_g, output_encoding),\n                         png_colormap_compose(display, colormap[i].blue,\n                             P_FILE, trans[i], back_b, output_encoding),\n                         output_encoding == P_LINEAR ? trans[i] * 257U :\n                             trans[i],\n                         output_encoding);\n                  }\n               }\n\n               else\n                  png_create_colormap_entry(display, i, colormap[i].red,\n                      colormap[i].green, colormap[i].blue,\n                      i < num_trans ? trans[i] : 255U, P_FILE/*8-bit*/);\n            }\n\n            /* The PNG data may have indices packed in fewer than 8 bits, it\n             * must be expanded if so.\n             */\n            if (png_ptr->bit_depth < 8)\n               png_set_packing(png_ptr);\n         }\n         break;\n\n      default:\n         png_error(png_ptr, \"invalid PNG color type\");\n         /*NOT REACHED*/\n   }\n\n   /* Now deal with the output processing */\n   if (expand_tRNS != 0 && png_ptr->num_trans > 0 &&\n       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) == 0)\n      png_set_tRNS_to_alpha(png_ptr);\n\n   switch (data_encoding)\n   {\n      case P_sRGB:\n         /* Change to 8-bit sRGB */\n         png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, PNG_GAMMA_sRGB);\n         /* FALL THROUGH */\n\n      case P_FILE:\n         if (png_ptr->bit_depth > 8)\n            png_set_scale_16(png_ptr);\n         break;\n\n#ifdef __GNUC__\n      default:\n         png_error(png_ptr, \"bad data option (internal error)\");\n#endif\n   }\n\n   if (cmap_entries > 256 || cmap_entries > image->colormap_entries)\n      png_error(png_ptr, \"color map overflow (BAD internal error)\");\n\n   image->colormap_entries = cmap_entries;\n\n   /* Double check using the recorded background index */\n   switch (output_processing)\n   {\n      case PNG_CMAP_NONE:\n         if (background_index != PNG_CMAP_NONE_BACKGROUND)\n            goto bad_background;\n         break;\n\n      case PNG_CMAP_GA:\n         if (background_index != PNG_CMAP_GA_BACKGROUND)\n            goto bad_background;\n         break;\n\n      case PNG_CMAP_TRANS:\n         if (background_index >= cmap_entries ||\n            background_index != PNG_CMAP_TRANS_BACKGROUND)\n            goto bad_background;\n         break;\n\n      case PNG_CMAP_RGB:\n         if (background_index != PNG_CMAP_RGB_BACKGROUND)\n            goto bad_background;\n         break;\n\n      case PNG_CMAP_RGB_ALPHA:\n         if (background_index != PNG_CMAP_RGB_ALPHA_BACKGROUND)\n            goto bad_background;\n         break;\n\n      default:\n         png_error(png_ptr, \"bad processing option (internal error)\");\n\n      bad_background:\n         png_error(png_ptr, \"bad background index (internal error)\");\n   }\n\n   display->colormap_processing = output_processing;\n\n   return 1/*ok*/;\n}\n\n/* The final part of the color-map read called from png_image_finish_read. */\nstatic int\npng_image_read_and_map(png_voidp argument)\n{\n   png_image_read_control *display = png_voidcast(png_image_read_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n   int passes;\n\n   /* Called when the libpng data must be transformed into the color-mapped\n    * form.  There is a local row buffer in display->local and this routine must\n    * do the interlace handling.\n    */\n   switch (png_ptr->interlaced)\n   {\n      case PNG_INTERLACE_NONE:\n         passes = 1;\n         break;\n\n      case PNG_INTERLACE_ADAM7:\n         passes = PNG_INTERLACE_ADAM7_PASSES;\n         break;\n\n      default:\n         png_error(png_ptr, \"unknown interlace type\");\n   }\n\n   {\n      png_uint_32  height = image->height;\n      png_uint_32  width = image->width;\n      int          proc = display->colormap_processing;\n      png_bytep    first_row = png_voidcast(png_bytep, display->first_row);\n      ptrdiff_t    step_row = display->row_bytes;\n      int pass;\n\n      for (pass = 0; pass < passes; ++pass)\n      {\n         unsigned int     startx, stepx, stepy;\n         png_uint_32      y;\n\n         if (png_ptr->interlaced == PNG_INTERLACE_ADAM7)\n         {\n            /* The row may be empty for a short image: */\n            if (PNG_PASS_COLS(width, pass) == 0)\n               continue;\n\n            startx = PNG_PASS_START_COL(pass);\n            stepx = PNG_PASS_COL_OFFSET(pass);\n            y = PNG_PASS_START_ROW(pass);\n            stepy = PNG_PASS_ROW_OFFSET(pass);\n         }\n\n         else\n         {\n            y = 0;\n            startx = 0;\n            stepx = stepy = 1;\n         }\n\n         for (; y<height; y += stepy)\n         {\n            png_bytep inrow = png_voidcast(png_bytep, display->local_row);\n            png_bytep outrow = first_row + y * step_row;\n            png_const_bytep end_row = outrow + width;\n\n            /* Read read the libpng data into the temporary buffer. */\n            png_read_row(png_ptr, inrow, NULL);\n\n            /* Now process the row according to the processing option, note\n             * that the caller verifies that the format of the libpng output\n             * data is as required.\n             */\n            outrow += startx;\n            switch (proc)\n            {\n               case PNG_CMAP_GA:\n                  for (; outrow < end_row; outrow += stepx)\n                  {\n                     /* The data is always in the PNG order */\n                     unsigned int gray = *inrow++;\n                     unsigned int alpha = *inrow++;\n                     unsigned int entry;\n\n                     /* NOTE: this code is copied as a comment in\n                      * make_ga_colormap above.  Please update the\n                      * comment if you change this code!\n                      */\n                     if (alpha > 229) /* opaque */\n                     {\n                        entry = (231 * gray + 128) >> 8;\n                     }\n                     else if (alpha < 26) /* transparent */\n                     {\n                        entry = 231;\n                     }\n                     else /* partially opaque */\n                     {\n                        entry = 226 + 6 * PNG_DIV51(alpha) + PNG_DIV51(gray);\n                     }\n\n                     *outrow = (png_byte)entry;\n                  }\n                  break;\n\n               case PNG_CMAP_TRANS:\n                  for (; outrow < end_row; outrow += stepx)\n                  {\n                     png_byte gray = *inrow++;\n                     png_byte alpha = *inrow++;\n\n                     if (alpha == 0)\n                        *outrow = PNG_CMAP_TRANS_BACKGROUND;\n\n                     else if (gray != PNG_CMAP_TRANS_BACKGROUND)\n                        *outrow = gray;\n\n                     else\n                        *outrow = (png_byte)(PNG_CMAP_TRANS_BACKGROUND+1);\n                  }\n                  break;\n\n               case PNG_CMAP_RGB:\n                  for (; outrow < end_row; outrow += stepx)\n                  {\n                     *outrow = PNG_RGB_INDEX(inrow[0], inrow[1], inrow[2]);\n                     inrow += 3;\n                  }\n                  break;\n\n               case PNG_CMAP_RGB_ALPHA:\n                  for (; outrow < end_row; outrow += stepx)\n                  {\n                     unsigned int alpha = inrow[3];\n\n                     /* Because the alpha entries only hold alpha==0.5 values\n                      * split the processing at alpha==0.25 (64) and 0.75\n                      * (196).\n                      */\n\n                     if (alpha >= 196)\n                        *outrow = PNG_RGB_INDEX(inrow[0], inrow[1],\n                            inrow[2]);\n\n                     else if (alpha < 64)\n                        *outrow = PNG_CMAP_RGB_ALPHA_BACKGROUND;\n\n                     else\n                     {\n                        /* Likewise there are three entries for each of r, g\n                         * and b.  We could select the entry by popcount on\n                         * the top two bits on those architectures that\n                         * support it, this is what the code below does,\n                         * crudely.\n                         */\n                        unsigned int back_i = PNG_CMAP_RGB_ALPHA_BACKGROUND+1;\n\n                        /* Here are how the values map:\n                         *\n                         * 0x00 .. 0x3f -> 0\n                         * 0x40 .. 0xbf -> 1\n                         * 0xc0 .. 0xff -> 2\n                         *\n                         * So, as above with the explicit alpha checks, the\n                         * breakpoints are at 64 and 196.\n                         */\n                        if (inrow[0] & 0x80) back_i += 9; /* red */\n                        if (inrow[0] & 0x40) back_i += 9;\n                        if (inrow[0] & 0x80) back_i += 3; /* green */\n                        if (inrow[0] & 0x40) back_i += 3;\n                        if (inrow[0] & 0x80) back_i += 1; /* blue */\n                        if (inrow[0] & 0x40) back_i += 1;\n\n                        *outrow = (png_byte)back_i;\n                     }\n\n                     inrow += 4;\n                  }\n                  break;\n\n               default:\n                  break;\n            }\n         }\n      }\n   }\n\n   return 1;\n}\n\nstatic int\npng_image_read_colormapped(png_voidp argument)\n{\n   png_image_read_control *display = png_voidcast(png_image_read_control*,\n       argument);\n   png_imagep image = display->image;\n   png_controlp control = image->opaque;\n   png_structrp png_ptr = control->png_ptr;\n   png_inforp info_ptr = control->info_ptr;\n\n   int passes = 0; /* As a flag */\n\n   PNG_SKIP_CHUNKS(png_ptr);\n\n   /* Update the 'info' structure and make sure the result is as required; first\n    * make sure to turn on the interlace handling if it will be required\n    * (because it can't be turned on *after* the call to png_read_update_info!)\n    */\n   if (display->colormap_processing == PNG_CMAP_NONE)\n      passes = png_set_interlace_handling(png_ptr);\n\n   png_read_update_info(png_ptr, info_ptr);\n\n   /* The expected output can be deduced from the colormap_processing option. */\n   switch (display->colormap_processing)\n   {\n      case PNG_CMAP_NONE:\n         /* Output must be one channel and one byte per pixel, the output\n          * encoding can be anything.\n          */\n         if ((info_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||\n            info_ptr->color_type == PNG_COLOR_TYPE_GRAY) &&\n            info_ptr->bit_depth == 8)\n            break;\n\n         goto bad_output;\n\n      case PNG_CMAP_TRANS:\n      case PNG_CMAP_GA:\n         /* Output must be two channels and the 'G' one must be sRGB, the latter\n          * can be checked with an exact number because it should have been set\n          * to this number above!\n          */\n         if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&\n            info_ptr->bit_depth == 8 &&\n            png_ptr->screen_gamma == PNG_GAMMA_sRGB &&\n            image->colormap_entries == 256)\n            break;\n\n         goto bad_output;\n\n      case PNG_CMAP_RGB:\n         /* Output must be 8-bit sRGB encoded RGB */\n         if (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&\n            info_ptr->bit_depth == 8 &&\n            png_ptr->screen_gamma == PNG_GAMMA_sRGB &&\n            image->colormap_entries == 216)\n            break;\n\n         goto bad_output;\n\n      case PNG_CMAP_RGB_ALPHA:\n         /* Output must be 8-bit sRGB encoded RGBA */\n         if (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&\n            info_ptr->bit_depth == 8 &&\n            png_ptr->screen_gamma == PNG_GAMMA_sRGB &&\n            image->colormap_entries == 244 /* 216 + 1 + 27 */)\n            break;\n\n         /* goto bad_output; */\n         /* FALL THROUGH */\n\n      default:\n      bad_output:\n         png_error(png_ptr, \"bad color-map processing (internal error)\");\n   }\n\n   /* Now read the rows.  Do this here if it is possible to read directly into\n    * the output buffer, otherwise allocate a local row buffer of the maximum\n    * size libpng requires and call the relevant processing routine safely.\n    */\n   {\n      png_voidp first_row = display->buffer;\n      ptrdiff_t row_bytes = display->row_stride;\n\n      /* The following expression is designed to work correctly whether it gives\n       * a signed or an unsigned result.\n       */\n      if (row_bytes < 0)\n      {\n         char *ptr = png_voidcast(char*, first_row);\n         ptr += (image->height-1) * (-row_bytes);\n         first_row = png_voidcast(png_voidp, ptr);\n      }\n\n      display->first_row = first_row;\n      display->row_bytes = row_bytes;\n   }\n\n   if (passes == 0)\n   {\n      int result;\n      png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));\n\n      display->local_row = row;\n      result = png_safe_execute(image, png_image_read_and_map, display);\n      display->local_row = NULL;\n      png_free(png_ptr, row);\n\n      return result;\n   }\n\n   else\n   {\n      png_alloc_size_t row_bytes = display->row_bytes;\n\n      while (--passes >= 0)\n      {\n         png_uint_32      y = image->height;\n         png_bytep        row = png_voidcast(png_bytep, display->first_row);\n\n         while (y-- > 0)\n         {\n            png_read_row(png_ptr, row, NULL);\n            row += row_bytes;\n         }\n      }\n\n      return 1;\n   }\n}\n\n/* Just the row reading part of png_image_read. */\nstatic int\npng_image_read_composite(png_voidp argument)\n{\n   png_image_read_control *display = png_voidcast(png_image_read_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n   int passes;\n\n   switch (png_ptr->interlaced)\n   {\n      case PNG_INTERLACE_NONE:\n         passes = 1;\n         break;\n\n      case PNG_INTERLACE_ADAM7:\n         passes = PNG_INTERLACE_ADAM7_PASSES;\n         break;\n\n      default:\n         png_error(png_ptr, \"unknown interlace type\");\n   }\n\n   {\n      png_uint_32  height = image->height;\n      png_uint_32  width = image->width;\n      ptrdiff_t    step_row = display->row_bytes;\n      unsigned int channels =\n          (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;\n      int pass;\n\n      for (pass = 0; pass < passes; ++pass)\n      {\n         unsigned int     startx, stepx, stepy;\n         png_uint_32      y;\n\n         if (png_ptr->interlaced == PNG_INTERLACE_ADAM7)\n         {\n            /* The row may be empty for a short image: */\n            if (PNG_PASS_COLS(width, pass) == 0)\n               continue;\n\n            startx = PNG_PASS_START_COL(pass) * channels;\n            stepx = PNG_PASS_COL_OFFSET(pass) * channels;\n            y = PNG_PASS_START_ROW(pass);\n            stepy = PNG_PASS_ROW_OFFSET(pass);\n         }\n\n         else\n         {\n            y = 0;\n            startx = 0;\n            stepx = channels;\n            stepy = 1;\n         }\n\n         for (; y<height; y += stepy)\n         {\n            png_bytep inrow = png_voidcast(png_bytep, display->local_row);\n            png_bytep outrow;\n            png_const_bytep end_row;\n\n            /* Read the row, which is packed: */\n            png_read_row(png_ptr, inrow, NULL);\n\n            outrow = png_voidcast(png_bytep, display->first_row);\n            outrow += y * step_row;\n            end_row = outrow + width * channels;\n\n            /* Now do the composition on each pixel in this row. */\n            outrow += startx;\n            for (; outrow < end_row; outrow += stepx)\n            {\n               png_byte alpha = inrow[channels];\n\n               if (alpha > 0) /* else no change to the output */\n               {\n                  unsigned int c;\n\n                  for (c=0; c<channels; ++c)\n                  {\n                     png_uint_32 component = inrow[c];\n\n                     if (alpha < 255) /* else just use component */\n                     {\n                        /* This is PNG_OPTIMIZED_ALPHA, the component value\n                         * is a linear 8-bit value.  Combine this with the\n                         * current outrow[c] value which is sRGB encoded.\n                         * Arithmetic here is 16-bits to preserve the output\n                         * values correctly.\n                         */\n                        component *= 257*255; /* =65535 */\n                        component += (255-alpha)*png_sRGB_table[outrow[c]];\n\n                        /* So 'component' is scaled by 255*65535 and is\n                         * therefore appropriate for the sRGB to linear\n                         * conversion table.\n                         */\n                        component = PNG_sRGB_FROM_LINEAR(component);\n                     }\n\n                     outrow[c] = (png_byte)component;\n                  }\n               }\n\n               inrow += channels+1; /* components and alpha channel */\n            }\n         }\n      }\n   }\n\n   return 1;\n}\n\n/* The do_local_background case; called when all the following transforms are to\n * be done:\n *\n * PNG_RGB_TO_GRAY\n * PNG_COMPOSITE\n * PNG_GAMMA\n *\n * This is a work-around for the fact that both the PNG_RGB_TO_GRAY and\n * PNG_COMPOSITE code performs gamma correction, so we get double gamma\n * correction.  The fix-up is to prevent the PNG_COMPOSITE operation from\n * happening inside libpng, so this routine sees an 8 or 16-bit gray+alpha\n * row and handles the removal or pre-multiplication of the alpha channel.\n */\nstatic int\npng_image_read_background(png_voidp argument)\n{\n   png_image_read_control *display = png_voidcast(png_image_read_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n   png_inforp info_ptr = image->opaque->info_ptr;\n   png_uint_32 height = image->height;\n   png_uint_32 width = image->width;\n   int pass, passes;\n\n   /* Double check the convoluted logic below.  We expect to get here with\n    * libpng doing rgb to gray and gamma correction but background processing\n    * left to the png_image_read_background function.  The rows libpng produce\n    * might be 8 or 16-bit but should always have two channels; gray plus alpha.\n    */\n   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)\n      png_error(png_ptr, \"lost rgb to gray\");\n\n   if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n      png_error(png_ptr, \"unexpected compose\");\n\n   if (png_get_channels(png_ptr, info_ptr) != 2)\n      png_error(png_ptr, \"lost/gained channels\");\n\n   /* Expect the 8-bit case to always remove the alpha channel */\n   if ((image->format & PNG_FORMAT_FLAG_LINEAR) == 0 &&\n      (image->format & PNG_FORMAT_FLAG_ALPHA) != 0)\n      png_error(png_ptr, \"unexpected 8-bit transformation\");\n\n   switch (png_ptr->interlaced)\n   {\n      case PNG_INTERLACE_NONE:\n         passes = 1;\n         break;\n\n      case PNG_INTERLACE_ADAM7:\n         passes = PNG_INTERLACE_ADAM7_PASSES;\n         break;\n\n      default:\n         png_error(png_ptr, \"unknown interlace type\");\n   }\n\n   /* Use direct access to info_ptr here because otherwise the simplified API\n    * would require PNG_EASY_ACCESS_SUPPORTED (just for this.)  Note this is\n    * checking the value after libpng expansions, not the original value in the\n    * PNG.\n    */\n   switch (info_ptr->bit_depth)\n   {\n      case 8:\n         /* 8-bit sRGB gray values with an alpha channel; the alpha channel is\n          * to be removed by composing on a background: either the row if\n          * display->background is NULL or display->background->green if not.\n          * Unlike the code above ALPHA_OPTIMIZED has *not* been done.\n          */\n         {\n            png_bytep first_row = png_voidcast(png_bytep, display->first_row);\n            ptrdiff_t step_row = display->row_bytes;\n\n            for (pass = 0; pass < passes; ++pass)\n            {\n               png_bytep row = png_voidcast(png_bytep, display->first_row);\n               unsigned int     startx, stepx, stepy;\n               png_uint_32      y;\n\n               if (png_ptr->interlaced == PNG_INTERLACE_ADAM7)\n               {\n                  /* The row may be empty for a short image: */\n                  if (PNG_PASS_COLS(width, pass) == 0)\n                     continue;\n\n                  startx = PNG_PASS_START_COL(pass);\n                  stepx = PNG_PASS_COL_OFFSET(pass);\n                  y = PNG_PASS_START_ROW(pass);\n                  stepy = PNG_PASS_ROW_OFFSET(pass);\n               }\n\n               else\n               {\n                  y = 0;\n                  startx = 0;\n                  stepx = stepy = 1;\n               }\n\n               if (display->background == NULL)\n               {\n                  for (; y<height; y += stepy)\n                  {\n                     png_bytep inrow = png_voidcast(png_bytep,\n                         display->local_row);\n                     png_bytep outrow = first_row + y * step_row;\n                     png_const_bytep end_row = outrow + width;\n\n                     /* Read the row, which is packed: */\n                     png_read_row(png_ptr, inrow, NULL);\n\n                     /* Now do the composition on each pixel in this row. */\n                     outrow += startx;\n                     for (; outrow < end_row; outrow += stepx)\n                     {\n                        png_byte alpha = inrow[1];\n\n                        if (alpha > 0) /* else no change to the output */\n                        {\n                           png_uint_32 component = inrow[0];\n\n                           if (alpha < 255) /* else just use component */\n                           {\n                              /* Since PNG_OPTIMIZED_ALPHA was not set it is\n                               * necessary to invert the sRGB transfer\n                               * function and multiply the alpha out.\n                               */\n                              component = png_sRGB_table[component] * alpha;\n                              component += png_sRGB_table[outrow[0]] *\n                                 (255-alpha);\n                              component = PNG_sRGB_FROM_LINEAR(component);\n                           }\n\n                           outrow[0] = (png_byte)component;\n                        }\n\n                        inrow += 2; /* gray and alpha channel */\n                     }\n                  }\n               }\n\n               else /* constant background value */\n               {\n                  png_byte background8 = display->background->green;\n                  png_uint_16 background = png_sRGB_table[background8];\n\n                  for (; y<height; y += stepy)\n                  {\n                     png_bytep inrow = png_voidcast(png_bytep,\n                         display->local_row);\n                     png_bytep outrow = first_row + y * step_row;\n                     png_const_bytep end_row = outrow + width;\n\n                     /* Read the row, which is packed: */\n                     png_read_row(png_ptr, inrow, NULL);\n\n                     /* Now do the composition on each pixel in this row. */\n                     outrow += startx;\n                     for (; outrow < end_row; outrow += stepx)\n                     {\n                        png_byte alpha = inrow[1];\n\n                        if (alpha > 0) /* else use background */\n                        {\n                           png_uint_32 component = inrow[0];\n\n                           if (alpha < 255) /* else just use component */\n                           {\n                              component = png_sRGB_table[component] * alpha;\n                              component += background * (255-alpha);\n                              component = PNG_sRGB_FROM_LINEAR(component);\n                           }\n\n                           outrow[0] = (png_byte)component;\n                        }\n\n                        else\n                           outrow[0] = background8;\n\n                        inrow += 2; /* gray and alpha channel */\n                     }\n\n                     row += display->row_bytes;\n                  }\n               }\n            }\n         }\n         break;\n\n      case 16:\n         /* 16-bit linear with pre-multiplied alpha; the pre-multiplication must\n          * still be done and, maybe, the alpha channel removed.  This code also\n          * handles the alpha-first option.\n          */\n         {\n            png_uint_16p first_row = png_voidcast(png_uint_16p,\n                display->first_row);\n            /* The division by two is safe because the caller passed in a\n             * stride which was multiplied by 2 (below) to get row_bytes.\n             */\n            ptrdiff_t    step_row = display->row_bytes / 2;\n            int preserve_alpha = (image->format & PNG_FORMAT_FLAG_ALPHA) != 0;\n            unsigned int outchannels = 1+preserve_alpha;\n            int swap_alpha = 0;\n\n#           ifdef PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED\n               if (preserve_alpha != 0 &&\n                   (image->format & PNG_FORMAT_FLAG_AFIRST) != 0)\n                  swap_alpha = 1;\n#           endif\n\n            for (pass = 0; pass < passes; ++pass)\n            {\n               unsigned int     startx, stepx, stepy;\n               png_uint_32      y;\n\n               /* The 'x' start and step are adjusted to output components here.\n                */\n               if (png_ptr->interlaced == PNG_INTERLACE_ADAM7)\n               {\n                  /* The row may be empty for a short image: */\n                  if (PNG_PASS_COLS(width, pass) == 0)\n                     continue;\n\n                  startx = PNG_PASS_START_COL(pass) * outchannels;\n                  stepx = PNG_PASS_COL_OFFSET(pass) * outchannels;\n                  y = PNG_PASS_START_ROW(pass);\n                  stepy = PNG_PASS_ROW_OFFSET(pass);\n               }\n\n               else\n               {\n                  y = 0;\n                  startx = 0;\n                  stepx = outchannels;\n                  stepy = 1;\n               }\n\n               for (; y<height; y += stepy)\n               {\n                  png_const_uint_16p inrow;\n                  png_uint_16p outrow = first_row + y*step_row;\n                  png_uint_16p end_row = outrow + width * outchannels;\n\n                  /* Read the row, which is packed: */\n                  png_read_row(png_ptr, png_voidcast(png_bytep,\n                      display->local_row), NULL);\n                  inrow = png_voidcast(png_const_uint_16p, display->local_row);\n\n                  /* Now do the pre-multiplication on each pixel in this row.\n                   */\n                  outrow += startx;\n                  for (; outrow < end_row; outrow += stepx)\n                  {\n                     png_uint_32 component = inrow[0];\n                     png_uint_16 alpha = inrow[1];\n\n                     if (alpha > 0) /* else 0 */\n                     {\n                        if (alpha < 65535) /* else just use component */\n                        {\n                           component *= alpha;\n                           component += 32767;\n                           component /= 65535;\n                        }\n                     }\n\n                     else\n                        component = 0;\n\n                     outrow[swap_alpha] = (png_uint_16)component;\n                     if (preserve_alpha != 0)\n                        outrow[1 ^ swap_alpha] = alpha;\n\n                     inrow += 2; /* components and alpha channel */\n                  }\n               }\n            }\n         }\n         break;\n\n#ifdef __GNUC__\n      default:\n         png_error(png_ptr, \"unexpected bit depth\");\n#endif\n   }\n\n   return 1;\n}\n\n/* The guts of png_image_finish_read as a png_safe_execute callback. */\nstatic int\npng_image_read_direct(png_voidp argument)\n{\n   png_image_read_control *display = png_voidcast(png_image_read_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n   png_inforp info_ptr = image->opaque->info_ptr;\n\n   png_uint_32 format = image->format;\n   int linear = (format & PNG_FORMAT_FLAG_LINEAR) != 0;\n   int do_local_compose = 0;\n   int do_local_background = 0; /* to avoid double gamma correction bug */\n   int passes = 0;\n\n   /* Add transforms to ensure the correct output format is produced then check\n    * that the required implementation support is there.  Always expand; always\n    * need 8 bits minimum, no palette and expanded tRNS.\n    */\n   png_set_expand(png_ptr);\n\n   /* Now check the format to see if it was modified. */\n   {\n      png_uint_32 base_format = png_image_format(png_ptr) &\n         ~PNG_FORMAT_FLAG_COLORMAP /* removed by png_set_expand */;\n      png_uint_32 change = format ^ base_format;\n      png_fixed_point output_gamma;\n      int mode; /* alpha mode */\n\n      /* Do this first so that we have a record if rgb to gray is happening. */\n      if ((change & PNG_FORMAT_FLAG_COLOR) != 0)\n      {\n         /* gray<->color transformation required. */\n         if ((format & PNG_FORMAT_FLAG_COLOR) != 0)\n            png_set_gray_to_rgb(png_ptr);\n\n         else\n         {\n            /* libpng can't do both rgb to gray and\n             * background/pre-multiplication if there is also significant gamma\n             * correction, because both operations require linear colors and\n             * the code only supports one transform doing the gamma correction.\n             * Handle this by doing the pre-multiplication or background\n             * operation in this code, if necessary.\n             *\n             * TODO: fix this by rewriting pngrtran.c (!)\n             *\n             * For the moment (given that fixing this in pngrtran.c is an\n             * enormous change) 'do_local_background' is used to indicate that\n             * the problem exists.\n             */\n            if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n               do_local_background = 1/*maybe*/;\n\n            png_set_rgb_to_gray_fixed(png_ptr, PNG_ERROR_ACTION_NONE,\n                PNG_RGB_TO_GRAY_DEFAULT, PNG_RGB_TO_GRAY_DEFAULT);\n         }\n\n         change &= ~PNG_FORMAT_FLAG_COLOR;\n      }\n\n      /* Set the gamma appropriately, linear for 16-bit input, sRGB otherwise.\n       */\n      {\n         png_fixed_point input_gamma_default;\n\n         if ((base_format & PNG_FORMAT_FLAG_LINEAR) != 0 &&\n             (image->flags & PNG_IMAGE_FLAG_16BIT_sRGB) == 0)\n            input_gamma_default = PNG_GAMMA_LINEAR;\n         else\n            input_gamma_default = PNG_DEFAULT_sRGB;\n\n         /* Call png_set_alpha_mode to set the default for the input gamma; the\n          * output gamma is set by a second call below.\n          */\n         png_set_alpha_mode_fixed(png_ptr, PNG_ALPHA_PNG, input_gamma_default);\n      }\n\n      if (linear != 0)\n      {\n         /* If there *is* an alpha channel in the input it must be multiplied\n          * out; use PNG_ALPHA_STANDARD, otherwise just use PNG_ALPHA_PNG.\n          */\n         if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n            mode = PNG_ALPHA_STANDARD; /* associated alpha */\n\n         else\n            mode = PNG_ALPHA_PNG;\n\n         output_gamma = PNG_GAMMA_LINEAR;\n      }\n\n      else\n      {\n         mode = PNG_ALPHA_PNG;\n         output_gamma = PNG_DEFAULT_sRGB;\n      }\n\n      /* If 'do_local_background' is set check for the presence of gamma\n       * correction; this is part of the work-round for the libpng bug\n       * described above.\n       *\n       * TODO: fix libpng and remove this.\n       */\n      if (do_local_background != 0)\n      {\n         png_fixed_point gtest;\n\n         /* This is 'png_gamma_threshold' from pngrtran.c; the test used for\n          * gamma correction, the screen gamma hasn't been set on png_struct\n          * yet; it's set below.  png_struct::gamma, however, is set to the\n          * final value.\n          */\n         if (png_muldiv(&gtest, output_gamma, png_ptr->colorspace.gamma,\n             PNG_FP_1) != 0 && png_gamma_significant(gtest) == 0)\n            do_local_background = 0;\n\n         else if (mode == PNG_ALPHA_STANDARD)\n         {\n            do_local_background = 2/*required*/;\n            mode = PNG_ALPHA_PNG; /* prevent libpng doing it */\n         }\n\n         /* else leave as 1 for the checks below */\n      }\n\n      /* If the bit-depth changes then handle that here. */\n      if ((change & PNG_FORMAT_FLAG_LINEAR) != 0)\n      {\n         if (linear != 0 /*16-bit output*/)\n            png_set_expand_16(png_ptr);\n\n         else /* 8-bit output */\n            png_set_scale_16(png_ptr);\n\n         change &= ~PNG_FORMAT_FLAG_LINEAR;\n      }\n\n      /* Now the background/alpha channel changes. */\n      if ((change & PNG_FORMAT_FLAG_ALPHA) != 0)\n      {\n         /* Removing an alpha channel requires composition for the 8-bit\n          * formats; for the 16-bit it is already done, above, by the\n          * pre-multiplication and the channel just needs to be stripped.\n          */\n         if ((base_format & PNG_FORMAT_FLAG_ALPHA) != 0)\n         {\n            /* If RGB->gray is happening the alpha channel must be left and the\n             * operation completed locally.\n             *\n             * TODO: fix libpng and remove this.\n             */\n            if (do_local_background != 0)\n               do_local_background = 2/*required*/;\n\n            /* 16-bit output: just remove the channel */\n            else if (linear != 0) /* compose on black (well, pre-multiply) */\n               png_set_strip_alpha(png_ptr);\n\n            /* 8-bit output: do an appropriate compose */\n            else if (display->background != NULL)\n            {\n               png_color_16 c;\n\n               c.index = 0; /*unused*/\n               c.red = display->background->red;\n               c.green = display->background->green;\n               c.blue = display->background->blue;\n               c.gray = display->background->green;\n\n               /* This is always an 8-bit sRGB value, using the 'green' channel\n                * for gray is much better than calculating the luminance here;\n                * we can get off-by-one errors in that calculation relative to\n                * the app expectations and that will show up in transparent\n                * pixels.\n                */\n               png_set_background_fixed(png_ptr, &c,\n                   PNG_BACKGROUND_GAMMA_SCREEN, 0/*need_expand*/,\n                   0/*gamma: not used*/);\n            }\n\n            else /* compose on row: implemented below. */\n            {\n               do_local_compose = 1;\n               /* This leaves the alpha channel in the output, so it has to be\n                * removed by the code below.  Set the encoding to the 'OPTIMIZE'\n                * one so the code only has to hack on the pixels that require\n                * composition.\n                */\n               mode = PNG_ALPHA_OPTIMIZED;\n            }\n         }\n\n         else /* output needs an alpha channel */\n         {\n            /* This is tricky because it happens before the swap operation has\n             * been accomplished; however, the swap does *not* swap the added\n             * alpha channel (weird API), so it must be added in the correct\n             * place.\n             */\n            png_uint_32 filler; /* opaque filler */\n            int where;\n\n            if (linear != 0)\n               filler = 65535;\n\n            else\n               filler = 255;\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\n            if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)\n            {\n               where = PNG_FILLER_BEFORE;\n               change &= ~PNG_FORMAT_FLAG_AFIRST;\n            }\n\n            else\n#endif\n            where = PNG_FILLER_AFTER;\n\n            png_set_add_alpha(png_ptr, filler, where);\n         }\n\n         /* This stops the (irrelevant) call to swap_alpha below. */\n         change &= ~PNG_FORMAT_FLAG_ALPHA;\n      }\n\n      /* Now set the alpha mode correctly; this is always done, even if there is\n       * no alpha channel in either the input or the output because it correctly\n       * sets the output gamma.\n       */\n      png_set_alpha_mode_fixed(png_ptr, mode, output_gamma);\n\n#     ifdef PNG_FORMAT_BGR_SUPPORTED\n         if ((change & PNG_FORMAT_FLAG_BGR) != 0)\n         {\n            /* Check only the output format; PNG is never BGR; don't do this if\n             * the output is gray, but fix up the 'format' value in that case.\n             */\n            if ((format & PNG_FORMAT_FLAG_COLOR) != 0)\n               png_set_bgr(png_ptr);\n\n            else\n               format &= ~PNG_FORMAT_FLAG_BGR;\n\n            change &= ~PNG_FORMAT_FLAG_BGR;\n         }\n#     endif\n\n#     ifdef PNG_FORMAT_AFIRST_SUPPORTED\n         if ((change & PNG_FORMAT_FLAG_AFIRST) != 0)\n         {\n            /* Only relevant if there is an alpha channel - it's particularly\n             * important to handle this correctly because do_local_compose may\n             * be set above and then libpng will keep the alpha channel for this\n             * code to remove.\n             */\n            if ((format & PNG_FORMAT_FLAG_ALPHA) != 0)\n            {\n               /* Disable this if doing a local background,\n                * TODO: remove this when local background is no longer required.\n                */\n               if (do_local_background != 2)\n                  png_set_swap_alpha(png_ptr);\n            }\n\n            else\n               format &= ~PNG_FORMAT_FLAG_AFIRST;\n\n            change &= ~PNG_FORMAT_FLAG_AFIRST;\n         }\n#     endif\n\n      /* If the *output* is 16-bit then we need to check for a byte-swap on this\n       * architecture.\n       */\n      if (linear != 0)\n      {\n         PNG_CONST png_uint_16 le = 0x0001;\n\n         if ((*(png_const_bytep) & le) != 0)\n            png_set_swap(png_ptr);\n      }\n\n      /* If change is not now 0 some transformation is missing - error out. */\n      if (change != 0)\n         png_error(png_ptr, \"png_read_image: unsupported transformation\");\n   }\n\n   PNG_SKIP_CHUNKS(png_ptr);\n\n   /* Update the 'info' structure and make sure the result is as required; first\n    * make sure to turn on the interlace handling if it will be required\n    * (because it can't be turned on *after* the call to png_read_update_info!)\n    *\n    * TODO: remove the do_local_background fixup below.\n    */\n   if (do_local_compose == 0 && do_local_background != 2)\n      passes = png_set_interlace_handling(png_ptr);\n\n   png_read_update_info(png_ptr, info_ptr);\n\n   {\n      png_uint_32 info_format = 0;\n\n      if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n         info_format |= PNG_FORMAT_FLAG_COLOR;\n\n      if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      {\n         /* do_local_compose removes this channel below. */\n         if (do_local_compose == 0)\n         {\n            /* do_local_background does the same if required. */\n            if (do_local_background != 2 ||\n               (format & PNG_FORMAT_FLAG_ALPHA) != 0)\n               info_format |= PNG_FORMAT_FLAG_ALPHA;\n         }\n      }\n\n      else if (do_local_compose != 0) /* internal error */\n         png_error(png_ptr, \"png_image_read: alpha channel lost\");\n\n      if (info_ptr->bit_depth == 16)\n         info_format |= PNG_FORMAT_FLAG_LINEAR;\n\n#ifdef PNG_FORMAT_BGR_SUPPORTED\n      if ((png_ptr->transformations & PNG_BGR) != 0)\n         info_format |= PNG_FORMAT_FLAG_BGR;\n#endif\n\n#ifdef PNG_FORMAT_AFIRST_SUPPORTED\n         if (do_local_background == 2)\n         {\n            if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)\n               info_format |= PNG_FORMAT_FLAG_AFIRST;\n         }\n\n         if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0 ||\n            ((png_ptr->transformations & PNG_ADD_ALPHA) != 0 &&\n            (png_ptr->flags & PNG_FLAG_FILLER_AFTER) == 0))\n         {\n            if (do_local_background == 2)\n               png_error(png_ptr, \"unexpected alpha swap transformation\");\n\n            info_format |= PNG_FORMAT_FLAG_AFIRST;\n         }\n#     endif\n\n      /* This is actually an internal error. */\n      if (info_format != format)\n         png_error(png_ptr, \"png_read_image: invalid transformations\");\n   }\n\n   /* Now read the rows.  If do_local_compose is set then it is necessary to use\n    * a local row buffer.  The output will be GA, RGBA or BGRA and must be\n    * converted to G, RGB or BGR as appropriate.  The 'local_row' member of the\n    * display acts as a flag.\n    */\n   {\n      png_voidp first_row = display->buffer;\n      ptrdiff_t row_bytes = display->row_stride;\n\n      if (linear != 0)\n         row_bytes *= 2;\n\n      /* The following expression is designed to work correctly whether it gives\n       * a signed or an unsigned result.\n       */\n      if (row_bytes < 0)\n      {\n         char *ptr = png_voidcast(char*, first_row);\n         ptr += (image->height-1) * (-row_bytes);\n         first_row = png_voidcast(png_voidp, ptr);\n      }\n\n      display->first_row = first_row;\n      display->row_bytes = row_bytes;\n   }\n\n   if (do_local_compose != 0)\n   {\n      int result;\n      png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));\n\n      display->local_row = row;\n      result = png_safe_execute(image, png_image_read_composite, display);\n      display->local_row = NULL;\n      png_free(png_ptr, row);\n\n      return result;\n   }\n\n   else if (do_local_background == 2)\n   {\n      int result;\n      png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));\n\n      display->local_row = row;\n      result = png_safe_execute(image, png_image_read_background, display);\n      display->local_row = NULL;\n      png_free(png_ptr, row);\n\n      return result;\n   }\n\n   else\n   {\n      png_alloc_size_t row_bytes = display->row_bytes;\n\n      while (--passes >= 0)\n      {\n         png_uint_32      y = image->height;\n         png_bytep        row = png_voidcast(png_bytep, display->first_row);\n\n         while (y-- > 0)\n         {\n            png_read_row(png_ptr, row, NULL);\n            row += row_bytes;\n         }\n      }\n\n      return 1;\n   }\n}\n\nint PNGAPI\npng_image_finish_read(png_imagep image, png_const_colorp background,\n    void *buffer, png_int_32 row_stride, void *colormap)\n{\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      /* Check for row_stride overflow.  This check is not performed on the\n       * original PNG format because it may not occur in the output PNG format\n       * and libpng deals with the issues of reading the original.\n       */\n      const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);\n\n      /* The following checks just the 'row_stride' calculation to ensure it\n       * fits in a signed 32-bit value.  Because channels/components can be\n       * either 1 or 2 bytes in size the length of a row can still overflow 32\n       * bits; this is just to verify that the 'row_stride' argument can be\n       * represented.\n       */\n      if (image->width <= 0x7FFFFFFFU/channels) /* no overflow */\n      {\n         png_uint_32 check;\n         const png_uint_32 png_row_stride = image->width * channels;\n\n         if (row_stride == 0)\n            row_stride = (png_int_32)/*SAFE*/png_row_stride;\n\n         if (row_stride < 0)\n            check = -row_stride;\n\n         else\n            check = row_stride;\n\n         /* This verifies 'check', the absolute value of the actual stride\n          * passed in and detects overflow in the application calculation (i.e.\n          * if the app did actually pass in a non-zero 'row_stride'.\n          */\n         if (image->opaque != NULL && buffer != NULL && check >= png_row_stride)\n         {\n            /* Now check for overflow of the image buffer calculation; this\n             * limits the whole image size to 32 bits for API compatibility with\n             * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro.\n             *\n             * The PNG_IMAGE_BUFFER_SIZE macro is:\n             *\n             *    (PNG_IMAGE_PIXEL_COMPONENT_SIZE(fmt)*height*(row_stride))\n             *\n             * And the component size is always 1 or 2, so make sure that the\n             * number of *bytes* that the application is saying are available\n             * does actually fit into a 32-bit number.\n             *\n             * NOTE: this will be changed in 1.7 because PNG_IMAGE_BUFFER_SIZE\n             * will be changed to use png_alloc_size_t; bigger images can be\n             * accomodated on 64-bit systems.\n             */\n            if (image->height <=\n                0xFFFFFFFFU/PNG_IMAGE_PIXEL_COMPONENT_SIZE(image->format)/check)\n            {\n               if ((image->format & PNG_FORMAT_FLAG_COLORMAP) == 0 ||\n                  (image->colormap_entries > 0 && colormap != NULL))\n               {\n                  int result;\n                  png_image_read_control display;\n\n                  memset(&display, 0, (sizeof display));\n                  display.image = image;\n                  display.buffer = buffer;\n                  display.row_stride = row_stride;\n                  display.colormap = colormap;\n                  display.background = background;\n                  display.local_row = NULL;\n\n                  /* Choose the correct 'end' routine; for the color-map case\n                   * all the setup has already been done.\n                   */\n                  if ((image->format & PNG_FORMAT_FLAG_COLORMAP) != 0)\n                     result =\n                         png_safe_execute(image,\n                             png_image_read_colormap, &display) &&\n                             png_safe_execute(image,\n                             png_image_read_colormapped, &display);\n\n                  else\n                     result =\n                        png_safe_execute(image,\n                            png_image_read_direct, &display);\n\n                  png_image_free(image);\n                  return result;\n               }\n\n               else\n                  return png_image_error(image,\n                      \"png_image_finish_read[color-map]: no color-map\");\n            }\n\n            else\n               return png_image_error(image,\n                   \"png_image_finish_read: image too large\");\n         }\n\n         else\n            return png_image_error(image,\n                \"png_image_finish_read: invalid argument\");\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_finish_read: row_stride too large\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_finish_read: damaged PNG_IMAGE_VERSION\");\n\n   return 0;\n}\n\n#endif /* SIMPLIFIED_READ */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngrio.c",
    "content": "\n/* pngrio.c - functions for data input\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file provides a location for all input.  Users who need\n * special handling are expected to write a function that has the same\n * arguments as this and performs a similar function, but that possibly\n * has a different input method.  Note that you shouldn't change this\n * function, but rather write a replacement function and then make\n * libpng use it at run time with png_set_read_fn(...).\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n/* Read the data from whatever input you are using.  The default routine\n * reads from a file pointer.  Note that this routine sometimes gets called\n * with very small lengths, so you should implement some kind of simple\n * buffering if you are using unbuffered reads.  This should never be asked\n * to read more than 64K on a 16-bit machine.\n */\nvoid /* PRIVATE */\npng_read_data(png_structrp png_ptr, png_bytep data, png_size_t length)\n{\n   png_debug1(4, \"reading %d bytes\", (int)length);\n\n   if (png_ptr->read_data_fn != NULL)\n      (*(png_ptr->read_data_fn))(png_ptr, data, length);\n\n   else\n      png_error(png_ptr, \"Call to NULL read function\");\n}\n\n#ifdef PNG_STDIO_SUPPORTED\n/* This is the function that does the actual reading of data.  If you are\n * not reading from a standard C stream, you should create a replacement\n * read_data function and use it at run time with png_set_read_fn(), rather\n * than changing the library.\n */\nvoid PNGCBAPI\npng_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_size_t check;\n\n   if (png_ptr == NULL)\n      return;\n\n   /* fread() returns 0 on error, so it is OK to store this in a png_size_t\n    * instead of an int, which is what fread() actually returns.\n    */\n   check = fread(data, 1, length, png_voidcast(png_FILE_p, png_ptr->io_ptr));\n\n   if (check != length)\n      png_error(png_ptr, \"Read Error\");\n}\n#endif\n\n/* This function allows the application to supply a new input function\n * for libpng if standard C streams aren't being used.\n *\n * This function takes as its arguments:\n *\n * png_ptr      - pointer to a png input data structure\n *\n * io_ptr       - pointer to user supplied structure containing info about\n *                the input functions.  May be NULL.\n *\n * read_data_fn - pointer to a new input function that takes as its\n *                arguments a pointer to a png_struct, a pointer to\n *                a location where input data can be stored, and a 32-bit\n *                unsigned int that is the number of bytes to be read.\n *                To exit and output any fatal error messages the new write\n *                function should call png_error(png_ptr, \"Error msg\").\n *                May be NULL, in which case libpng's default function will\n *                be used.\n */\nvoid PNGAPI\npng_set_read_fn(png_structrp png_ptr, png_voidp io_ptr,\n    png_rw_ptr read_data_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->io_ptr = io_ptr;\n\n#ifdef PNG_STDIO_SUPPORTED\n   if (read_data_fn != NULL)\n      png_ptr->read_data_fn = read_data_fn;\n\n   else\n      png_ptr->read_data_fn = png_default_read_data;\n#else\n   png_ptr->read_data_fn = read_data_fn;\n#endif\n\n#ifdef PNG_WRITE_SUPPORTED\n   /* It is an error to write to a read device */\n   if (png_ptr->write_data_fn != NULL)\n   {\n      png_ptr->write_data_fn = NULL;\n      png_warning(png_ptr,\n          \"Can't set both read_data_fn and write_data_fn in the\"\n          \" same structure\");\n   }\n#endif\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n   png_ptr->output_flush_fn = NULL;\n#endif\n}\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngrtran.c",
    "content": "\n/* pngrtran.c - transforms the data in a row for PNG readers\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file contains functions optionally called by an application\n * in order to tell libpng how to handle data when reading a PNG.\n * Transformations that are used in both reading and writing are\n * in pngtrans.c.\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\n/* Set the action on getting a CRC error for an ancillary or critical chunk. */\nvoid PNGAPI\npng_set_crc_action(png_structrp png_ptr, int crit_action, int ancil_action)\n{\n   png_debug(1, \"in png_set_crc_action\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* Tell libpng how we react to CRC errors in critical chunks */\n   switch (crit_action)\n   {\n      case PNG_CRC_NO_CHANGE:                        /* Leave setting as is */\n         break;\n\n      case PNG_CRC_WARN_USE:                               /* Warn/use data */\n         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;\n         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;\n         break;\n\n      case PNG_CRC_QUIET_USE:                             /* Quiet/use data */\n         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;\n         png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |\n                           PNG_FLAG_CRC_CRITICAL_IGNORE;\n         break;\n\n      case PNG_CRC_WARN_DISCARD:    /* Not a valid action for critical data */\n         png_warning(png_ptr,\n             \"Can't discard critical data on CRC error\");\n      case PNG_CRC_ERROR_QUIT:                                /* Error/quit */\n\n      case PNG_CRC_DEFAULT:\n      default:\n         png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;\n         break;\n   }\n\n   /* Tell libpng how we react to CRC errors in ancillary chunks */\n   switch (ancil_action)\n   {\n      case PNG_CRC_NO_CHANGE:                       /* Leave setting as is */\n         break;\n\n      case PNG_CRC_WARN_USE:                              /* Warn/use data */\n         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;\n         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;\n         break;\n\n      case PNG_CRC_QUIET_USE:                            /* Quiet/use data */\n         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;\n         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |\n                           PNG_FLAG_CRC_ANCILLARY_NOWARN;\n         break;\n\n      case PNG_CRC_ERROR_QUIT:                               /* Error/quit */\n         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;\n         png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;\n         break;\n\n      case PNG_CRC_WARN_DISCARD:                      /* Warn/discard data */\n\n      case PNG_CRC_DEFAULT:\n      default:\n         png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;\n         break;\n   }\n}\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n/* Is it OK to set a transformation now?  Only if png_start_read_image or\n * png_read_update_info have not been called.  It is not necessary for the IHDR\n * to have been read in all cases; the need_IHDR parameter allows for this\n * check too.\n */\nstatic int\npng_rtran_ok(png_structrp png_ptr, int need_IHDR)\n{\n   if (png_ptr != NULL)\n   {\n      if ((png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)\n         png_app_error(png_ptr,\n             \"invalid after png_start_read_image or png_read_update_info\");\n\n      else if (need_IHDR && (png_ptr->mode & PNG_HAVE_IHDR) == 0)\n         png_app_error(png_ptr, \"invalid before the PNG header has been read\");\n\n      else\n      {\n         /* Turn on failure to initialize correctly for all transforms. */\n         png_ptr->flags |= PNG_FLAG_DETECT_UNINITIALIZED;\n\n         return 1; /* Ok */\n      }\n   }\n\n   return 0; /* no png_error possible! */\n}\n#endif\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n/* Handle alpha and tRNS via a background color */\nvoid PNGFAPI\npng_set_background_fixed(png_structrp png_ptr,\n    png_const_color_16p background_color, int background_gamma_code,\n    int need_expand, png_fixed_point background_gamma)\n{\n   png_debug(1, \"in png_set_background_fixed\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0 || background_color == NULL)\n      return;\n\n   if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)\n   {\n      png_warning(png_ptr, \"Application must supply a known background gamma\");\n      return;\n   }\n\n   png_ptr->transformations |= PNG_COMPOSE | PNG_STRIP_ALPHA;\n   png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n   png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n\n   png_ptr->background = *background_color;\n   png_ptr->background_gamma = background_gamma;\n   png_ptr->background_gamma_type = (png_byte)(background_gamma_code);\n   if (need_expand != 0)\n      png_ptr->transformations |= PNG_BACKGROUND_EXPAND;\n   else\n      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_background(png_structrp png_ptr,\n    png_const_color_16p background_color, int background_gamma_code,\n    int need_expand, double background_gamma)\n{\n   png_set_background_fixed(png_ptr, background_color, background_gamma_code,\n      need_expand, png_fixed(png_ptr, background_gamma, \"png_set_background\"));\n}\n#  endif /* FLOATING_POINT */\n#endif /* READ_BACKGROUND */\n\n/* Scale 16-bit depth files to 8-bit depth.  If both of these are set then the\n * one that pngrtran does first (scale) happens.  This is necessary to allow the\n * TRANSFORM and API behavior to be somewhat consistent, and it's simpler.\n */\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\nvoid PNGAPI\npng_set_scale_16(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_scale_16\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= PNG_SCALE_16_TO_8;\n}\n#endif\n\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n/* Chop 16-bit depth files to 8-bit depth */\nvoid PNGAPI\npng_set_strip_16(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_strip_16\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= PNG_16_TO_8;\n}\n#endif\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\nvoid PNGAPI\npng_set_strip_alpha(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_strip_alpha\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= PNG_STRIP_ALPHA;\n}\n#endif\n\n#if defined(PNG_READ_ALPHA_MODE_SUPPORTED) || defined(PNG_READ_GAMMA_SUPPORTED)\nstatic png_fixed_point\ntranslate_gamma_flags(png_structrp png_ptr, png_fixed_point output_gamma,\n    int is_screen)\n{\n   /* Check for flag values.  The main reason for having the old Mac value as a\n    * flag is that it is pretty near impossible to work out what the correct\n    * value is from Apple documentation - a working Mac system is needed to\n    * discover the value!\n    */\n   if (output_gamma == PNG_DEFAULT_sRGB ||\n      output_gamma == PNG_FP_1 / PNG_DEFAULT_sRGB)\n   {\n      /* If there is no sRGB support this just sets the gamma to the standard\n       * sRGB value.  (This is a side effect of using this function!)\n       */\n#     ifdef PNG_READ_sRGB_SUPPORTED\n         png_ptr->flags |= PNG_FLAG_ASSUME_sRGB;\n#     else\n         PNG_UNUSED(png_ptr)\n#     endif\n      if (is_screen != 0)\n         output_gamma = PNG_GAMMA_sRGB;\n      else\n         output_gamma = PNG_GAMMA_sRGB_INVERSE;\n   }\n\n   else if (output_gamma == PNG_GAMMA_MAC_18 ||\n      output_gamma == PNG_FP_1 / PNG_GAMMA_MAC_18)\n   {\n      if (is_screen != 0)\n         output_gamma = PNG_GAMMA_MAC_OLD;\n      else\n         output_gamma = PNG_GAMMA_MAC_INVERSE;\n   }\n\n   return output_gamma;\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nstatic png_fixed_point\nconvert_gamma_value(png_structrp png_ptr, double output_gamma)\n{\n   /* The following silently ignores cases where fixed point (times 100,000)\n    * gamma values are passed to the floating point API.  This is safe and it\n    * means the fixed point constants work just fine with the floating point\n    * API.  The alternative would just lead to undetected errors and spurious\n    * bug reports.  Negative values fail inside the _fixed API unless they\n    * correspond to the flag values.\n    */\n   if (output_gamma > 0 && output_gamma < 128)\n      output_gamma *= PNG_FP_1;\n\n   /* This preserves -1 and -2 exactly: */\n   output_gamma = floor(output_gamma + .5);\n\n   if (output_gamma > PNG_FP_MAX || output_gamma < PNG_FP_MIN)\n      png_fixed_error(png_ptr, \"gamma value\");\n\n   return (png_fixed_point)output_gamma;\n}\n#  endif\n#endif /* READ_ALPHA_MODE || READ_GAMMA */\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\nvoid PNGFAPI\npng_set_alpha_mode_fixed(png_structrp png_ptr, int mode,\n    png_fixed_point output_gamma)\n{\n   int compose = 0;\n   png_fixed_point file_gamma;\n\n   png_debug(1, \"in png_set_alpha_mode\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   output_gamma = translate_gamma_flags(png_ptr, output_gamma, 1/*screen*/);\n\n   /* Validate the value to ensure it is in a reasonable range. The value\n    * is expected to be 1 or greater, but this range test allows for some\n    * viewing correction values.  The intent is to weed out users of this API\n    * who use the inverse of the gamma value accidentally!  Since some of these\n    * values are reasonable this may have to be changed:\n    *\n    * 1.6.x: changed from 0.07..3 to 0.01..100 (to accomodate the optimal 16-bit\n    * gamma of 36, and its reciprocal.)\n    */\n   if (output_gamma < 1000 || output_gamma > 10000000)\n      png_error(png_ptr, \"output gamma out of expected range\");\n\n   /* The default file gamma is the inverse of the output gamma; the output\n    * gamma may be changed below so get the file value first:\n    */\n   file_gamma = png_reciprocal(output_gamma);\n\n   /* There are really 8 possibilities here, composed of any combination\n    * of:\n    *\n    *    premultiply the color channels\n    *    do not encode non-opaque pixels\n    *    encode the alpha as well as the color channels\n    *\n    * The differences disappear if the input/output ('screen') gamma is 1.0,\n    * because then the encoding is a no-op and there is only the choice of\n    * premultiplying the color channels or not.\n    *\n    * png_set_alpha_mode and png_set_background interact because both use\n    * png_compose to do the work.  Calling both is only useful when\n    * png_set_alpha_mode is used to set the default mode - PNG_ALPHA_PNG - along\n    * with a default gamma value.  Otherwise PNG_COMPOSE must not be set.\n    */\n   switch (mode)\n   {\n      case PNG_ALPHA_PNG:        /* default: png standard */\n         /* No compose, but it may be set by png_set_background! */\n         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n         break;\n\n      case PNG_ALPHA_ASSOCIATED: /* color channels premultiplied */\n         compose = 1;\n         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n         /* The output is linear: */\n         output_gamma = PNG_FP_1;\n         break;\n\n      case PNG_ALPHA_OPTIMIZED:  /* associated, non-opaque pixels linear */\n         compose = 1;\n         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n         png_ptr->flags |= PNG_FLAG_OPTIMIZE_ALPHA;\n         /* output_gamma records the encoding of opaque pixels! */\n         break;\n\n      case PNG_ALPHA_BROKEN:     /* associated, non-linear, alpha encoded */\n         compose = 1;\n         png_ptr->transformations |= PNG_ENCODE_ALPHA;\n         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n         break;\n\n      default:\n         png_error(png_ptr, \"invalid alpha mode\");\n   }\n\n   /* Only set the default gamma if the file gamma has not been set (this has\n    * the side effect that the gamma in a second call to png_set_alpha_mode will\n    * be ignored.)\n    */\n   if (png_ptr->colorspace.gamma == 0)\n   {\n      png_ptr->colorspace.gamma = file_gamma;\n      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;\n   }\n\n   /* But always set the output gamma: */\n   png_ptr->screen_gamma = output_gamma;\n\n   /* Finally, if pre-multiplying, set the background fields to achieve the\n    * desired result.\n    */\n   if (compose != 0)\n   {\n      /* And obtain alpha pre-multiplication by composing on black: */\n      memset(&png_ptr->background, 0, (sizeof png_ptr->background));\n      png_ptr->background_gamma = png_ptr->colorspace.gamma; /* just in case */\n      png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_FILE;\n      png_ptr->transformations &= ~PNG_BACKGROUND_EXPAND;\n\n      if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n         png_error(png_ptr,\n             \"conflicting calls to set alpha mode and background\");\n\n      png_ptr->transformations |= PNG_COMPOSE;\n   }\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_alpha_mode(png_structrp png_ptr, int mode, double output_gamma)\n{\n   png_set_alpha_mode_fixed(png_ptr, mode, convert_gamma_value(png_ptr,\n       output_gamma));\n}\n#  endif\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n/* Dither file to 8-bit.  Supply a palette, the current number\n * of elements in the palette, the maximum number of elements\n * allowed, and a histogram if possible.  If the current number\n * of colors is greater than the maximum number, the palette will be\n * modified to fit in the maximum number.  \"full_quantize\" indicates\n * whether we need a quantizing cube set up for RGB images, or if we\n * simply are reducing the number of colors in a paletted image.\n */\n\ntypedef struct png_dsort_struct\n{\n   struct png_dsort_struct * next;\n   png_byte left;\n   png_byte right;\n} png_dsort;\ntypedef png_dsort *   png_dsortp;\ntypedef png_dsort * * png_dsortpp;\n\nvoid PNGAPI\npng_set_quantize(png_structrp png_ptr, png_colorp palette,\n    int num_palette, int maximum_colors, png_const_uint_16p histogram,\n    int full_quantize)\n{\n   png_debug(1, \"in png_set_quantize\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= PNG_QUANTIZE;\n\n   if (full_quantize == 0)\n   {\n      int i;\n\n      png_ptr->quantize_index = (png_bytep)png_malloc(png_ptr,\n          (png_uint_32)(num_palette * (sizeof (png_byte))));\n      for (i = 0; i < num_palette; i++)\n         png_ptr->quantize_index[i] = (png_byte)i;\n   }\n\n   if (num_palette > maximum_colors)\n   {\n      if (histogram != NULL)\n      {\n         /* This is easy enough, just throw out the least used colors.\n          * Perhaps not the best solution, but good enough.\n          */\n\n         int i;\n\n         /* Initialize an array to sort colors */\n         png_ptr->quantize_sort = (png_bytep)png_malloc(png_ptr,\n             (png_uint_32)(num_palette * (sizeof (png_byte))));\n\n         /* Initialize the quantize_sort array */\n         for (i = 0; i < num_palette; i++)\n            png_ptr->quantize_sort[i] = (png_byte)i;\n\n         /* Find the least used palette entries by starting a\n          * bubble sort, and running it until we have sorted\n          * out enough colors.  Note that we don't care about\n          * sorting all the colors, just finding which are\n          * least used.\n          */\n\n         for (i = num_palette - 1; i >= maximum_colors; i--)\n         {\n            int done; /* To stop early if the list is pre-sorted */\n            int j;\n\n            done = 1;\n            for (j = 0; j < i; j++)\n            {\n               if (histogram[png_ptr->quantize_sort[j]]\n                   < histogram[png_ptr->quantize_sort[j + 1]])\n               {\n                  png_byte t;\n\n                  t = png_ptr->quantize_sort[j];\n                  png_ptr->quantize_sort[j] = png_ptr->quantize_sort[j + 1];\n                  png_ptr->quantize_sort[j + 1] = t;\n                  done = 0;\n               }\n            }\n\n            if (done != 0)\n               break;\n         }\n\n         /* Swap the palette around, and set up a table, if necessary */\n         if (full_quantize != 0)\n         {\n            int j = num_palette;\n\n            /* Put all the useful colors within the max, but don't\n             * move the others.\n             */\n            for (i = 0; i < maximum_colors; i++)\n            {\n               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)\n               {\n                  do\n                     j--;\n                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);\n\n                  palette[i] = palette[j];\n               }\n            }\n         }\n         else\n         {\n            int j = num_palette;\n\n            /* Move all the used colors inside the max limit, and\n             * develop a translation table.\n             */\n            for (i = 0; i < maximum_colors; i++)\n            {\n               /* Only move the colors we need to */\n               if ((int)png_ptr->quantize_sort[i] >= maximum_colors)\n               {\n                  png_color tmp_color;\n\n                  do\n                     j--;\n                  while ((int)png_ptr->quantize_sort[j] >= maximum_colors);\n\n                  tmp_color = palette[j];\n                  palette[j] = palette[i];\n                  palette[i] = tmp_color;\n                  /* Indicate where the color went */\n                  png_ptr->quantize_index[j] = (png_byte)i;\n                  png_ptr->quantize_index[i] = (png_byte)j;\n               }\n            }\n\n            /* Find closest color for those colors we are not using */\n            for (i = 0; i < num_palette; i++)\n            {\n               if ((int)png_ptr->quantize_index[i] >= maximum_colors)\n               {\n                  int min_d, k, min_k, d_index;\n\n                  /* Find the closest color to one we threw out */\n                  d_index = png_ptr->quantize_index[i];\n                  min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);\n                  for (k = 1, min_k = 0; k < maximum_colors; k++)\n                  {\n                     int d;\n\n                     d = PNG_COLOR_DIST(palette[d_index], palette[k]);\n\n                     if (d < min_d)\n                     {\n                        min_d = d;\n                        min_k = k;\n                     }\n                  }\n                  /* Point to closest color */\n                  png_ptr->quantize_index[i] = (png_byte)min_k;\n               }\n            }\n         }\n         png_free(png_ptr, png_ptr->quantize_sort);\n         png_ptr->quantize_sort = NULL;\n      }\n      else\n      {\n         /* This is much harder to do simply (and quickly).  Perhaps\n          * we need to go through a median cut routine, but those\n          * don't always behave themselves with only a few colors\n          * as input.  So we will just find the closest two colors,\n          * and throw out one of them (chosen somewhat randomly).\n          * [We don't understand this at all, so if someone wants to\n          *  work on improving it, be our guest - AED, GRP]\n          */\n         int i;\n         int max_d;\n         int num_new_palette;\n         png_dsortp t;\n         png_dsortpp hash;\n\n         t = NULL;\n\n         /* Initialize palette index arrays */\n         png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,\n             (png_uint_32)(num_palette * (sizeof (png_byte))));\n         png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,\n             (png_uint_32)(num_palette * (sizeof (png_byte))));\n\n         /* Initialize the sort array */\n         for (i = 0; i < num_palette; i++)\n         {\n            png_ptr->index_to_palette[i] = (png_byte)i;\n            png_ptr->palette_to_index[i] = (png_byte)i;\n         }\n\n         hash = (png_dsortpp)png_calloc(png_ptr, (png_uint_32)(769 *\n             (sizeof (png_dsortp))));\n\n         num_new_palette = num_palette;\n\n         /* Initial wild guess at how far apart the farthest pixel\n          * pair we will be eliminating will be.  Larger\n          * numbers mean more areas will be allocated, Smaller\n          * numbers run the risk of not saving enough data, and\n          * having to do this all over again.\n          *\n          * I have not done extensive checking on this number.\n          */\n         max_d = 96;\n\n         while (num_new_palette > maximum_colors)\n         {\n            for (i = 0; i < num_new_palette - 1; i++)\n            {\n               int j;\n\n               for (j = i + 1; j < num_new_palette; j++)\n               {\n                  int d;\n\n                  d = PNG_COLOR_DIST(palette[i], palette[j]);\n\n                  if (d <= max_d)\n                  {\n\n                     t = (png_dsortp)png_malloc_warn(png_ptr,\n                         (png_uint_32)(sizeof (png_dsort)));\n\n                     if (t == NULL)\n                         break;\n\n                     t->next = hash[d];\n                     t->left = (png_byte)i;\n                     t->right = (png_byte)j;\n                     hash[d] = t;\n                  }\n               }\n               if (t == NULL)\n                  break;\n            }\n\n            if (t != NULL)\n            for (i = 0; i <= max_d; i++)\n            {\n               if (hash[i] != NULL)\n               {\n                  png_dsortp p;\n\n                  for (p = hash[i]; p; p = p->next)\n                  {\n                     if ((int)png_ptr->index_to_palette[p->left]\n                         < num_new_palette &&\n                         (int)png_ptr->index_to_palette[p->right]\n                         < num_new_palette)\n                     {\n                        int j, next_j;\n\n                        if (num_new_palette & 0x01)\n                        {\n                           j = p->left;\n                           next_j = p->right;\n                        }\n                        else\n                        {\n                           j = p->right;\n                           next_j = p->left;\n                        }\n\n                        num_new_palette--;\n                        palette[png_ptr->index_to_palette[j]]\n                            = palette[num_new_palette];\n                        if (full_quantize == 0)\n                        {\n                           int k;\n\n                           for (k = 0; k < num_palette; k++)\n                           {\n                              if (png_ptr->quantize_index[k] ==\n                                  png_ptr->index_to_palette[j])\n                                 png_ptr->quantize_index[k] =\n                                     png_ptr->index_to_palette[next_j];\n\n                              if ((int)png_ptr->quantize_index[k] ==\n                                  num_new_palette)\n                                 png_ptr->quantize_index[k] =\n                                     png_ptr->index_to_palette[j];\n                           }\n                        }\n\n                        png_ptr->index_to_palette[png_ptr->palette_to_index\n                            [num_new_palette]] = png_ptr->index_to_palette[j];\n\n                        png_ptr->palette_to_index[png_ptr->index_to_palette[j]]\n                            = png_ptr->palette_to_index[num_new_palette];\n\n                        png_ptr->index_to_palette[j] =\n                            (png_byte)num_new_palette;\n\n                        png_ptr->palette_to_index[num_new_palette] =\n                            (png_byte)j;\n                     }\n                     if (num_new_palette <= maximum_colors)\n                        break;\n                  }\n                  if (num_new_palette <= maximum_colors)\n                     break;\n               }\n            }\n\n            for (i = 0; i < 769; i++)\n            {\n               if (hash[i] != NULL)\n               {\n                  png_dsortp p = hash[i];\n                  while (p)\n                  {\n                     t = p->next;\n                     png_free(png_ptr, p);\n                     p = t;\n                  }\n               }\n               hash[i] = 0;\n            }\n            max_d += 96;\n         }\n         png_free(png_ptr, hash);\n         png_free(png_ptr, png_ptr->palette_to_index);\n         png_free(png_ptr, png_ptr->index_to_palette);\n         png_ptr->palette_to_index = NULL;\n         png_ptr->index_to_palette = NULL;\n      }\n      num_palette = maximum_colors;\n   }\n   if (png_ptr->palette == NULL)\n   {\n      png_ptr->palette = palette;\n   }\n   png_ptr->num_palette = (png_uint_16)num_palette;\n\n   if (full_quantize != 0)\n   {\n      int i;\n      png_bytep distance;\n      int total_bits = PNG_QUANTIZE_RED_BITS + PNG_QUANTIZE_GREEN_BITS +\n          PNG_QUANTIZE_BLUE_BITS;\n      int num_red = (1 << PNG_QUANTIZE_RED_BITS);\n      int num_green = (1 << PNG_QUANTIZE_GREEN_BITS);\n      int num_blue = (1 << PNG_QUANTIZE_BLUE_BITS);\n      png_size_t num_entries = ((png_size_t)1 << total_bits);\n\n      png_ptr->palette_lookup = (png_bytep)png_calloc(png_ptr,\n          (png_uint_32)(num_entries * (sizeof (png_byte))));\n\n      distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *\n          (sizeof (png_byte))));\n\n      memset(distance, 0xff, num_entries * (sizeof (png_byte)));\n\n      for (i = 0; i < num_palette; i++)\n      {\n         int ir, ig, ib;\n         int r = (palette[i].red >> (8 - PNG_QUANTIZE_RED_BITS));\n         int g = (palette[i].green >> (8 - PNG_QUANTIZE_GREEN_BITS));\n         int b = (palette[i].blue >> (8 - PNG_QUANTIZE_BLUE_BITS));\n\n         for (ir = 0; ir < num_red; ir++)\n         {\n            /* int dr = abs(ir - r); */\n            int dr = ((ir > r) ? ir - r : r - ir);\n            int index_r = (ir << (PNG_QUANTIZE_BLUE_BITS +\n                PNG_QUANTIZE_GREEN_BITS));\n\n            for (ig = 0; ig < num_green; ig++)\n            {\n               /* int dg = abs(ig - g); */\n               int dg = ((ig > g) ? ig - g : g - ig);\n               int dt = dr + dg;\n               int dm = ((dr > dg) ? dr : dg);\n               int index_g = index_r | (ig << PNG_QUANTIZE_BLUE_BITS);\n\n               for (ib = 0; ib < num_blue; ib++)\n               {\n                  int d_index = index_g | ib;\n                  /* int db = abs(ib - b); */\n                  int db = ((ib > b) ? ib - b : b - ib);\n                  int dmax = ((dm > db) ? dm : db);\n                  int d = dmax + dt + db;\n\n                  if (d < (int)distance[d_index])\n                  {\n                     distance[d_index] = (png_byte)d;\n                     png_ptr->palette_lookup[d_index] = (png_byte)i;\n                  }\n               }\n            }\n         }\n      }\n\n      png_free(png_ptr, distance);\n   }\n}\n#endif /* READ_QUANTIZE */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\nvoid PNGFAPI\npng_set_gamma_fixed(png_structrp png_ptr, png_fixed_point scrn_gamma,\n    png_fixed_point file_gamma)\n{\n   png_debug(1, \"in png_set_gamma_fixed\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   /* New in libpng-1.5.4 - reserve particular negative values as flags. */\n   scrn_gamma = translate_gamma_flags(png_ptr, scrn_gamma, 1/*screen*/);\n   file_gamma = translate_gamma_flags(png_ptr, file_gamma, 0/*file*/);\n\n   /* Checking the gamma values for being >0 was added in 1.5.4 along with the\n    * premultiplied alpha support; this actually hides an undocumented feature\n    * of the previous implementation which allowed gamma processing to be\n    * disabled in background handling.  There is no evidence (so far) that this\n    * was being used; however, png_set_background itself accepted and must still\n    * accept '0' for the gamma value it takes, because it isn't always used.\n    *\n    * Since this is an API change (albeit a very minor one that removes an\n    * undocumented API feature) the following checks were only enabled in\n    * libpng-1.6.0.\n    */\n   if (file_gamma <= 0)\n      png_error(png_ptr, \"invalid file gamma in png_set_gamma\");\n\n   if (scrn_gamma <= 0)\n      png_error(png_ptr, \"invalid screen gamma in png_set_gamma\");\n\n   /* Set the gamma values unconditionally - this overrides the value in the PNG\n    * file if a gAMA chunk was present.  png_set_alpha_mode provides a\n    * different, easier, way to default the file gamma.\n    */\n   png_ptr->colorspace.gamma = file_gamma;\n   png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;\n   png_ptr->screen_gamma = scrn_gamma;\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_gamma(png_structrp png_ptr, double scrn_gamma, double file_gamma)\n{\n   png_set_gamma_fixed(png_ptr, convert_gamma_value(png_ptr, scrn_gamma),\n       convert_gamma_value(png_ptr, file_gamma));\n}\n#  endif /* FLOATING_POINT */\n#endif /* READ_GAMMA */\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* Expand paletted images to RGB, expand grayscale images of\n * less than 8-bit depth to 8-bit depth, and expand tRNS chunks\n * to alpha channels.\n */\nvoid PNGAPI\npng_set_expand(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_expand\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);\n}\n\n/* GRR 19990627:  the following three functions currently are identical\n *  to png_set_expand().  However, it is entirely reasonable that someone\n *  might wish to expand an indexed image to RGB but *not* expand a single,\n *  fully transparent palette entry to a full alpha channel--perhaps instead\n *  convert tRNS to the grayscale/RGB format (16-bit RGB value), or replace\n *  the transparent color with a particular RGB value, or drop tRNS entirely.\n *  IOW, a future version of the library may make the transformations flag\n *  a bit more fine-grained, with separate bits for each of these three\n *  functions.\n *\n *  More to the point, these functions make it obvious what libpng will be\n *  doing, whereas \"expand\" can (and does) mean any number of things.\n *\n *  GRP 20060307: In libpng-1.2.9, png_set_gray_1_2_4_to_8() was modified\n *  to expand only the sample depth but not to expand the tRNS to alpha\n *  and its name was changed to png_set_expand_gray_1_2_4_to_8().\n */\n\n/* Expand paletted images to RGB. */\nvoid PNGAPI\npng_set_palette_to_rgb(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_palette_to_rgb\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);\n}\n\n/* Expand grayscale images of less than 8-bit depth to 8 bits. */\nvoid PNGAPI\npng_set_expand_gray_1_2_4_to_8(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_expand_gray_1_2_4_to_8\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= PNG_EXPAND;\n}\n\n/* Expand tRNS chunks to alpha channels. */\nvoid PNGAPI\npng_set_tRNS_to_alpha(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_tRNS_to_alpha\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);\n}\n#endif /* READ_EXPAND */\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n/* Expand to 16-bit channels, expand the tRNS chunk too (because otherwise\n * it may not work correctly.)\n */\nvoid PNGAPI\npng_set_expand_16(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_expand_16\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   png_ptr->transformations |= (PNG_EXPAND_16 | PNG_EXPAND | PNG_EXPAND_tRNS);\n}\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\nvoid PNGAPI\npng_set_gray_to_rgb(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_gray_to_rgb\");\n\n   if (png_rtran_ok(png_ptr, 0) == 0)\n      return;\n\n   /* Because rgb must be 8 bits or more: */\n   png_set_expand_gray_1_2_4_to_8(png_ptr);\n   png_ptr->transformations |= PNG_GRAY_TO_RGB;\n}\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\nvoid PNGFAPI\npng_set_rgb_to_gray_fixed(png_structrp png_ptr, int error_action,\n    png_fixed_point red, png_fixed_point green)\n{\n   png_debug(1, \"in png_set_rgb_to_gray\");\n\n   /* Need the IHDR here because of the check on color_type below. */\n   /* TODO: fix this */\n   if (png_rtran_ok(png_ptr, 1) == 0)\n      return;\n\n   switch (error_action)\n   {\n      case PNG_ERROR_ACTION_NONE:\n         png_ptr->transformations |= PNG_RGB_TO_GRAY;\n         break;\n\n      case PNG_ERROR_ACTION_WARN:\n         png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;\n         break;\n\n      case PNG_ERROR_ACTION_ERROR:\n         png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;\n         break;\n\n      default:\n         png_error(png_ptr, \"invalid error action to rgb_to_gray\");\n   }\n\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n#ifdef PNG_READ_EXPAND_SUPPORTED\n      png_ptr->transformations |= PNG_EXPAND;\n#else\n   {\n      /* Make this an error in 1.6 because otherwise the application may assume\n       * that it just worked and get a memory overwrite.\n       */\n      png_error(png_ptr,\n          \"Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED\");\n\n      /* png_ptr->transformations &= ~PNG_RGB_TO_GRAY; */\n   }\n#endif\n   {\n      if (red >= 0 && green >= 0 && red + green <= PNG_FP_1)\n      {\n         png_uint_16 red_int, green_int;\n\n         /* NOTE: this calculation does not round, but this behavior is retained\n          * for consistency; the inaccuracy is very small.  The code here always\n          * overwrites the coefficients, regardless of whether they have been\n          * defaulted or set already.\n          */\n         red_int = (png_uint_16)(((png_uint_32)red*32768)/100000);\n         green_int = (png_uint_16)(((png_uint_32)green*32768)/100000);\n\n         png_ptr->rgb_to_gray_red_coeff   = red_int;\n         png_ptr->rgb_to_gray_green_coeff = green_int;\n         png_ptr->rgb_to_gray_coefficients_set = 1;\n      }\n\n      else\n      {\n         if (red >= 0 && green >= 0)\n            png_app_warning(png_ptr,\n                \"ignoring out of range rgb_to_gray coefficients\");\n\n         /* Use the defaults, from the cHRM chunk if set, else the historical\n          * values which are close to the sRGB/HDTV/ITU-Rec 709 values.  See\n          * png_do_rgb_to_gray for more discussion of the values.  In this case\n          * the coefficients are not marked as 'set' and are not overwritten if\n          * something has already provided a default.\n          */\n         if (png_ptr->rgb_to_gray_red_coeff == 0 &&\n             png_ptr->rgb_to_gray_green_coeff == 0)\n         {\n            png_ptr->rgb_to_gray_red_coeff   = 6968;\n            png_ptr->rgb_to_gray_green_coeff = 23434;\n            /* png_ptr->rgb_to_gray_blue_coeff  = 2366; */\n         }\n      }\n   }\n}\n\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n/* Convert a RGB image to a grayscale of the same width.  This allows us,\n * for example, to convert a 24 bpp RGB image into an 8 bpp grayscale image.\n */\n\nvoid PNGAPI\npng_set_rgb_to_gray(png_structrp png_ptr, int error_action, double red,\n    double green)\n{\n   png_set_rgb_to_gray_fixed(png_ptr, error_action,\n       png_fixed(png_ptr, red, \"rgb to gray red coefficient\"),\n      png_fixed(png_ptr, green, \"rgb to gray green coefficient\"));\n}\n#endif /* FLOATING POINT */\n\n#endif /* RGB_TO_GRAY */\n\n#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \\\n    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)\nvoid PNGAPI\npng_set_read_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr\n    read_user_transform_fn)\n{\n   png_debug(1, \"in png_set_read_user_transform_fn\");\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n   png_ptr->transformations |= PNG_USER_TRANSFORM;\n   png_ptr->read_user_transform_fn = read_user_transform_fn;\n#endif\n}\n#endif\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* In the case of gamma transformations only do transformations on images where\n * the [file] gamma and screen_gamma are not close reciprocals, otherwise it\n * slows things down slightly, and also needlessly introduces small errors.\n */\nstatic int /* PRIVATE */\npng_gamma_threshold(png_fixed_point screen_gamma, png_fixed_point file_gamma)\n{\n   /* PNG_GAMMA_THRESHOLD is the threshold for performing gamma\n    * correction as a difference of the overall transform from 1.0\n    *\n    * We want to compare the threshold with s*f - 1, if we get\n    * overflow here it is because of wacky gamma values so we\n    * turn on processing anyway.\n    */\n   png_fixed_point gtest;\n   return !png_muldiv(&gtest, screen_gamma, file_gamma, PNG_FP_1) ||\n       png_gamma_significant(gtest);\n}\n#endif\n\n/* Initialize everything needed for the read.  This includes modifying\n * the palette.\n */\n\n/* For the moment 'png_init_palette_transformations' and\n * 'png_init_rgb_transformations' only do some flag canceling optimizations.\n * The intent is that these two routines should have palette or rgb operations\n * extracted from 'png_init_read_transformations'.\n */\nstatic void /* PRIVATE */\npng_init_palette_transformations(png_structrp png_ptr)\n{\n   /* Called to handle the (input) palette case.  In png_do_read_transformations\n    * the first step is to expand the palette if requested, so this code must\n    * take care to only make changes that are invariant with respect to the\n    * palette expansion, or only do them if there is no expansion.\n    *\n    * STRIP_ALPHA has already been handled in the caller (by setting num_trans\n    * to 0.)\n    */\n   int input_has_alpha = 0;\n   int input_has_transparency = 0;\n\n   if (png_ptr->num_trans > 0)\n   {\n      int i;\n\n      /* Ignore if all the entries are opaque (unlikely!) */\n      for (i=0; i<png_ptr->num_trans; ++i)\n      {\n         if (png_ptr->trans_alpha[i] == 255)\n            continue;\n         else if (png_ptr->trans_alpha[i] == 0)\n            input_has_transparency = 1;\n         else\n         {\n            input_has_transparency = 1;\n            input_has_alpha = 1;\n            break;\n         }\n      }\n   }\n\n   /* If no alpha we can optimize. */\n   if (input_has_alpha == 0)\n   {\n      /* Any alpha means background and associative alpha processing is\n       * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA\n       * and ENCODE_ALPHA are irrelevant.\n       */\n      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n\n      if (input_has_transparency == 0)\n         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);\n   }\n\n#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)\n   /* png_set_background handling - deals with the complexity of whether the\n    * background color is in the file format or the screen format in the case\n    * where an 'expand' will happen.\n    */\n\n   /* The following code cannot be entered in the alpha pre-multiplication case\n    * because PNG_BACKGROUND_EXPAND is cancelled below.\n    */\n   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&\n       (png_ptr->transformations & PNG_EXPAND) != 0)\n   {\n      {\n         png_ptr->background.red   =\n             png_ptr->palette[png_ptr->background.index].red;\n         png_ptr->background.green =\n             png_ptr->palette[png_ptr->background.index].green;\n         png_ptr->background.blue  =\n             png_ptr->palette[png_ptr->background.index].blue;\n\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\n        if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)\n        {\n           if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)\n           {\n              /* Invert the alpha channel (in tRNS) unless the pixels are\n               * going to be expanded, in which case leave it for later\n               */\n              int i, istop = png_ptr->num_trans;\n\n              for (i=0; i<istop; i++)\n                 png_ptr->trans_alpha[i] = (png_byte)(255 -\n                    png_ptr->trans_alpha[i]);\n           }\n        }\n#endif /* READ_INVERT_ALPHA */\n      }\n   } /* background expand and (therefore) no alpha association. */\n#endif /* READ_EXPAND && READ_BACKGROUND */\n}\n\nstatic void /* PRIVATE */\npng_init_rgb_transformations(png_structrp png_ptr)\n{\n   /* Added to libpng-1.5.4: check the color type to determine whether there\n    * is any alpha or transparency in the image and simply cancel the\n    * background and alpha mode stuff if there isn't.\n    */\n   int input_has_alpha = (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0;\n   int input_has_transparency = png_ptr->num_trans > 0;\n\n   /* If no alpha we can optimize. */\n   if (input_has_alpha == 0)\n   {\n      /* Any alpha means background and associative alpha processing is\n       * required, however if the alpha is 0 or 1 throughout OPTIMIZE_ALPHA\n       * and ENCODE_ALPHA are irrelevant.\n       */\n#     ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n         png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n         png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n#     endif\n\n      if (input_has_transparency == 0)\n         png_ptr->transformations &= ~(PNG_COMPOSE | PNG_BACKGROUND_EXPAND);\n   }\n\n#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)\n   /* png_set_background handling - deals with the complexity of whether the\n    * background color is in the file format or the screen format in the case\n    * where an 'expand' will happen.\n    */\n\n   /* The following code cannot be entered in the alpha pre-multiplication case\n    * because PNG_BACKGROUND_EXPAND is cancelled below.\n    */\n   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0 &&\n       (png_ptr->transformations & PNG_EXPAND) != 0 &&\n       (png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)\n       /* i.e., GRAY or GRAY_ALPHA */\n   {\n      {\n         /* Expand background and tRNS chunks */\n         int gray = png_ptr->background.gray;\n         int trans_gray = png_ptr->trans_color.gray;\n\n         switch (png_ptr->bit_depth)\n         {\n            case 1:\n               gray *= 0xff;\n               trans_gray *= 0xff;\n               break;\n\n            case 2:\n               gray *= 0x55;\n               trans_gray *= 0x55;\n               break;\n\n            case 4:\n               gray *= 0x11;\n               trans_gray *= 0x11;\n               break;\n\n            default:\n\n            case 8:\n               /* FALL THROUGH (Already 8 bits) */\n\n            case 16:\n               /* Already a full 16 bits */\n               break;\n         }\n\n         png_ptr->background.red = png_ptr->background.green =\n            png_ptr->background.blue = (png_uint_16)gray;\n\n         if ((png_ptr->transformations & PNG_EXPAND_tRNS) == 0)\n         {\n            png_ptr->trans_color.red = png_ptr->trans_color.green =\n               png_ptr->trans_color.blue = (png_uint_16)trans_gray;\n         }\n      }\n   } /* background expand and (therefore) no alpha association. */\n#endif /* READ_EXPAND && READ_BACKGROUND */\n}\n\nvoid /* PRIVATE */\npng_init_read_transformations(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_init_read_transformations\");\n\n   /* This internal function is called from png_read_start_row in pngrutil.c\n    * and it is called before the 'rowbytes' calculation is done, so the code\n    * in here can change or update the transformations flags.\n    *\n    * First do updates that do not depend on the details of the PNG image data\n    * being processed.\n    */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   /* Prior to 1.5.4 these tests were performed from png_set_gamma, 1.5.4 adds\n    * png_set_alpha_mode and this is another source for a default file gamma so\n    * the test needs to be performed later - here.  In addition prior to 1.5.4\n    * the tests were repeated for the PALETTE color type here - this is no\n    * longer necessary (and doesn't seem to have been necessary before.)\n    */\n   {\n      /* The following temporary indicates if overall gamma correction is\n       * required.\n       */\n      int gamma_correction = 0;\n\n      if (png_ptr->colorspace.gamma != 0) /* has been set */\n      {\n         if (png_ptr->screen_gamma != 0) /* screen set too */\n            gamma_correction = png_gamma_threshold(png_ptr->colorspace.gamma,\n                png_ptr->screen_gamma);\n\n         else\n            /* Assume the output matches the input; a long time default behavior\n             * of libpng, although the standard has nothing to say about this.\n             */\n            png_ptr->screen_gamma = png_reciprocal(png_ptr->colorspace.gamma);\n      }\n\n      else if (png_ptr->screen_gamma != 0)\n         /* The converse - assume the file matches the screen, note that this\n          * perhaps undesireable default can (from 1.5.4) be changed by calling\n          * png_set_alpha_mode (even if the alpha handling mode isn't required\n          * or isn't changed from the default.)\n          */\n         png_ptr->colorspace.gamma = png_reciprocal(png_ptr->screen_gamma);\n\n      else /* neither are set */\n         /* Just in case the following prevents any processing - file and screen\n          * are both assumed to be linear and there is no way to introduce a\n          * third gamma value other than png_set_background with 'UNIQUE', and,\n          * prior to 1.5.4\n          */\n         png_ptr->screen_gamma = png_ptr->colorspace.gamma = PNG_FP_1;\n\n      /* We have a gamma value now. */\n      png_ptr->colorspace.flags |= PNG_COLORSPACE_HAVE_GAMMA;\n\n      /* Now turn the gamma transformation on or off as appropriate.  Notice\n       * that PNG_GAMMA just refers to the file->screen correction.  Alpha\n       * composition may independently cause gamma correction because it needs\n       * linear data (e.g. if the file has a gAMA chunk but the screen gamma\n       * hasn't been specified.)  In any case this flag may get turned off in\n       * the code immediately below if the transform can be handled outside the\n       * row loop.\n       */\n      if (gamma_correction != 0)\n         png_ptr->transformations |= PNG_GAMMA;\n\n      else\n         png_ptr->transformations &= ~PNG_GAMMA;\n   }\n#endif\n\n   /* Certain transformations have the effect of preventing other\n    * transformations that happen afterward in png_do_read_transformations;\n    * resolve the interdependencies here.  From the code of\n    * png_do_read_transformations the order is:\n    *\n    *  1) PNG_EXPAND (including PNG_EXPAND_tRNS)\n    *  2) PNG_STRIP_ALPHA (if no compose)\n    *  3) PNG_RGB_TO_GRAY\n    *  4) PNG_GRAY_TO_RGB iff !PNG_BACKGROUND_IS_GRAY\n    *  5) PNG_COMPOSE\n    *  6) PNG_GAMMA\n    *  7) PNG_STRIP_ALPHA (if compose)\n    *  8) PNG_ENCODE_ALPHA\n    *  9) PNG_SCALE_16_TO_8\n    * 10) PNG_16_TO_8\n    * 11) PNG_QUANTIZE (converts to palette)\n    * 12) PNG_EXPAND_16\n    * 13) PNG_GRAY_TO_RGB iff PNG_BACKGROUND_IS_GRAY\n    * 14) PNG_INVERT_MONO\n    * 15) PNG_INVERT_ALPHA\n    * 16) PNG_SHIFT\n    * 17) PNG_PACK\n    * 18) PNG_BGR\n    * 19) PNG_PACKSWAP\n    * 20) PNG_FILLER (includes PNG_ADD_ALPHA)\n    * 21) PNG_SWAP_ALPHA\n    * 22) PNG_SWAP_BYTES\n    * 23) PNG_USER_TRANSFORM [must be last]\n    */\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&\n       (png_ptr->transformations & PNG_COMPOSE) == 0)\n   {\n      /* Stripping the alpha channel happens immediately after the 'expand'\n       * transformations, before all other transformation, so it cancels out\n       * the alpha handling.  It has the side effect negating the effect of\n       * PNG_EXPAND_tRNS too:\n       */\n      png_ptr->transformations &= ~(PNG_BACKGROUND_EXPAND | PNG_ENCODE_ALPHA |\n         PNG_EXPAND_tRNS);\n      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n\n      /* Kill the tRNS chunk itself too.  Prior to 1.5.4 this did not happen\n       * so transparency information would remain just so long as it wasn't\n       * expanded.  This produces unexpected API changes if the set of things\n       * that do PNG_EXPAND_tRNS changes (perfectly possible given the\n       * documentation - which says ask for what you want, accept what you\n       * get.)  This makes the behavior consistent from 1.5.4:\n       */\n      png_ptr->num_trans = 0;\n   }\n#endif /* STRIP_ALPHA supported, no COMPOSE */\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n   /* If the screen gamma is about 1.0 then the OPTIMIZE_ALPHA and ENCODE_ALPHA\n    * settings will have no effect.\n    */\n   if (png_gamma_significant(png_ptr->screen_gamma) == 0)\n   {\n      png_ptr->transformations &= ~PNG_ENCODE_ALPHA;\n      png_ptr->flags &= ~PNG_FLAG_OPTIMIZE_ALPHA;\n   }\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n   /* Make sure the coefficients for the rgb to gray conversion are set\n    * appropriately.\n    */\n   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)\n      png_colorspace_set_rgb_coefficients(png_ptr);\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n#if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)\n   /* Detect gray background and attempt to enable optimization for\n    * gray --> RGB case.\n    *\n    * Note:  if PNG_BACKGROUND_EXPAND is set and color_type is either RGB or\n    * RGB_ALPHA (in which case need_expand is superfluous anyway), the\n    * background color might actually be gray yet not be flagged as such.\n    * This is not a problem for the current code, which uses\n    * PNG_BACKGROUND_IS_GRAY only to decide when to do the\n    * png_do_gray_to_rgb() transformation.\n    *\n    * TODO: this code needs to be revised to avoid the complexity and\n    * interdependencies.  The color type of the background should be recorded in\n    * png_set_background, along with the bit depth, then the code has a record\n    * of exactly what color space the background is currently in.\n    */\n   if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) != 0)\n   {\n      /* PNG_BACKGROUND_EXPAND: the background is in the file color space, so if\n       * the file was grayscale the background value is gray.\n       */\n      if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)\n         png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;\n   }\n\n   else if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n   {\n      /* PNG_COMPOSE: png_set_background was called with need_expand false,\n       * so the color is in the color space of the output or png_set_alpha_mode\n       * was called and the color is black.  Ignore RGB_TO_GRAY because that\n       * happens before GRAY_TO_RGB.\n       */\n      if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)\n      {\n         if (png_ptr->background.red == png_ptr->background.green &&\n             png_ptr->background.red == png_ptr->background.blue)\n         {\n            png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;\n            png_ptr->background.gray = png_ptr->background.red;\n         }\n      }\n   }\n#endif /* READ_EXPAND && READ_BACKGROUND */\n#endif /* READ_GRAY_TO_RGB */\n\n   /* For indexed PNG data (PNG_COLOR_TYPE_PALETTE) many of the transformations\n    * can be performed directly on the palette, and some (such as rgb to gray)\n    * can be optimized inside the palette.  This is particularly true of the\n    * composite (background and alpha) stuff, which can be pretty much all done\n    * in the palette even if the result is expanded to RGB or gray afterward.\n    *\n    * NOTE: this is Not Yet Implemented, the code behaves as in 1.5.1 and\n    * earlier and the palette stuff is actually handled on the first row.  This\n    * leads to the reported bug that the palette returned by png_get_PLTE is not\n    * updated.\n    */\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      png_init_palette_transformations(png_ptr);\n\n   else\n      png_init_rgb_transformations(png_ptr);\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \\\n   defined(PNG_READ_EXPAND_16_SUPPORTED)\n   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&\n       (png_ptr->transformations & PNG_COMPOSE) != 0 &&\n       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&\n       png_ptr->bit_depth != 16)\n   {\n      /* TODO: fix this.  Because the expand_16 operation is after the compose\n       * handling the background color must be 8, not 16, bits deep, but the\n       * application will supply a 16-bit value so reduce it here.\n       *\n       * The PNG_BACKGROUND_EXPAND code above does not expand to 16 bits at\n       * present, so that case is ok (until do_expand_16 is moved.)\n       *\n       * NOTE: this discards the low 16 bits of the user supplied background\n       * color, but until expand_16 works properly there is no choice!\n       */\n#     define CHOP(x) (x)=((png_uint_16)PNG_DIV257(x))\n      CHOP(png_ptr->background.red);\n      CHOP(png_ptr->background.green);\n      CHOP(png_ptr->background.blue);\n      CHOP(png_ptr->background.gray);\n#     undef CHOP\n   }\n#endif /* READ_BACKGROUND && READ_EXPAND_16 */\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) && \\\n   (defined(PNG_READ_SCALE_16_TO_8_SUPPORTED) || \\\n   defined(PNG_READ_STRIP_16_TO_8_SUPPORTED))\n   if ((png_ptr->transformations & (PNG_16_TO_8|PNG_SCALE_16_TO_8)) != 0 &&\n       (png_ptr->transformations & PNG_COMPOSE) != 0 &&\n       (png_ptr->transformations & PNG_BACKGROUND_EXPAND) == 0 &&\n       png_ptr->bit_depth == 16)\n   {\n      /* On the other hand, if a 16-bit file is to be reduced to 8-bits per\n       * component this will also happen after PNG_COMPOSE and so the background\n       * color must be pre-expanded here.\n       *\n       * TODO: fix this too.\n       */\n      png_ptr->background.red = (png_uint_16)(png_ptr->background.red * 257);\n      png_ptr->background.green =\n         (png_uint_16)(png_ptr->background.green * 257);\n      png_ptr->background.blue = (png_uint_16)(png_ptr->background.blue * 257);\n      png_ptr->background.gray = (png_uint_16)(png_ptr->background.gray * 257);\n   }\n#endif\n\n   /* NOTE: below 'PNG_READ_ALPHA_MODE_SUPPORTED' is presumed to also enable the\n    * background support (see the comments in scripts/pnglibconf.dfa), this\n    * allows pre-multiplication of the alpha channel to be implemented as\n    * compositing on black.  This is probably sub-optimal and has been done in\n    * 1.5.4 betas simply to enable external critique and testing (i.e. to\n    * implement the new API quickly, without lots of internal changes.)\n    */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n#  ifdef PNG_READ_BACKGROUND_SUPPORTED\n      /* Includes ALPHA_MODE */\n      png_ptr->background_1 = png_ptr->background;\n#  endif\n\n   /* This needs to change - in the palette image case a whole set of tables are\n    * built when it would be quicker to just calculate the correct value for\n    * each palette entry directly.  Also, the test is too tricky - why check\n    * PNG_RGB_TO_GRAY if PNG_GAMMA is not set?  The answer seems to be that\n    * PNG_GAMMA is cancelled even if the gamma is known?  The test excludes the\n    * PNG_COMPOSE case, so apparently if there is no *overall* gamma correction\n    * the gamma tables will not be built even if composition is required on a\n    * gamma encoded value.\n    *\n    * In 1.5.4 this is addressed below by an additional check on the individual\n    * file gamma - if it is not 1.0 both RGB_TO_GRAY and COMPOSE need the\n    * tables.\n    */\n   if ((png_ptr->transformations & PNG_GAMMA) != 0 ||\n       ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0 &&\n        (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||\n         png_gamma_significant(png_ptr->screen_gamma) != 0)) ||\n        ((png_ptr->transformations & PNG_COMPOSE) != 0 &&\n         (png_gamma_significant(png_ptr->colorspace.gamma) != 0 ||\n          png_gamma_significant(png_ptr->screen_gamma) != 0\n#  ifdef PNG_READ_BACKGROUND_SUPPORTED\n         || (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_UNIQUE &&\n           png_gamma_significant(png_ptr->background_gamma) != 0)\n#  endif\n        )) || ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&\n       png_gamma_significant(png_ptr->screen_gamma) != 0))\n   {\n      png_build_gamma_table(png_ptr, png_ptr->bit_depth);\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n      if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n      {\n         /* Issue a warning about this combination: because RGB_TO_GRAY is\n          * optimized to do the gamma transform if present yet do_background has\n          * to do the same thing if both options are set a\n          * double-gamma-correction happens.  This is true in all versions of\n          * libpng to date.\n          */\n         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)\n            png_warning(png_ptr,\n                \"libpng does not support gamma+background+rgb_to_gray\");\n\n         if ((png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) != 0)\n         {\n            /* We don't get to here unless there is a tRNS chunk with non-opaque\n             * entries - see the checking code at the start of this function.\n             */\n            png_color back, back_1;\n            png_colorp palette = png_ptr->palette;\n            int num_palette = png_ptr->num_palette;\n            int i;\n            if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)\n            {\n\n               back.red = png_ptr->gamma_table[png_ptr->background.red];\n               back.green = png_ptr->gamma_table[png_ptr->background.green];\n               back.blue = png_ptr->gamma_table[png_ptr->background.blue];\n\n               back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];\n               back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];\n               back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];\n            }\n            else\n            {\n               png_fixed_point g, gs;\n\n               switch (png_ptr->background_gamma_type)\n               {\n                  case PNG_BACKGROUND_GAMMA_SCREEN:\n                     g = (png_ptr->screen_gamma);\n                     gs = PNG_FP_1;\n                     break;\n\n                  case PNG_BACKGROUND_GAMMA_FILE:\n                     g = png_reciprocal(png_ptr->colorspace.gamma);\n                     gs = png_reciprocal2(png_ptr->colorspace.gamma,\n                         png_ptr->screen_gamma);\n                     break;\n\n                  case PNG_BACKGROUND_GAMMA_UNIQUE:\n                     g = png_reciprocal(png_ptr->background_gamma);\n                     gs = png_reciprocal2(png_ptr->background_gamma,\n                         png_ptr->screen_gamma);\n                     break;\n                  default:\n                     g = PNG_FP_1;    /* back_1 */\n                     gs = PNG_FP_1;   /* back */\n                     break;\n               }\n\n               if (png_gamma_significant(gs) != 0)\n               {\n                  back.red = png_gamma_8bit_correct(png_ptr->background.red,\n                      gs);\n                  back.green = png_gamma_8bit_correct(png_ptr->background.green,\n                      gs);\n                  back.blue = png_gamma_8bit_correct(png_ptr->background.blue,\n                      gs);\n               }\n\n               else\n               {\n                  back.red   = (png_byte)png_ptr->background.red;\n                  back.green = (png_byte)png_ptr->background.green;\n                  back.blue  = (png_byte)png_ptr->background.blue;\n               }\n\n               if (png_gamma_significant(g) != 0)\n               {\n                  back_1.red = png_gamma_8bit_correct(png_ptr->background.red,\n                      g);\n                  back_1.green = png_gamma_8bit_correct(\n                      png_ptr->background.green, g);\n                  back_1.blue = png_gamma_8bit_correct(png_ptr->background.blue,\n                      g);\n               }\n\n               else\n               {\n                  back_1.red   = (png_byte)png_ptr->background.red;\n                  back_1.green = (png_byte)png_ptr->background.green;\n                  back_1.blue  = (png_byte)png_ptr->background.blue;\n               }\n            }\n\n            for (i = 0; i < num_palette; i++)\n            {\n               if (i < (int)png_ptr->num_trans &&\n                   png_ptr->trans_alpha[i] != 0xff)\n               {\n                  if (png_ptr->trans_alpha[i] == 0)\n                  {\n                     palette[i] = back;\n                  }\n                  else /* if (png_ptr->trans_alpha[i] != 0xff) */\n                  {\n                     png_byte v, w;\n\n                     v = png_ptr->gamma_to_1[palette[i].red];\n                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.red);\n                     palette[i].red = png_ptr->gamma_from_1[w];\n\n                     v = png_ptr->gamma_to_1[palette[i].green];\n                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.green);\n                     palette[i].green = png_ptr->gamma_from_1[w];\n\n                     v = png_ptr->gamma_to_1[palette[i].blue];\n                     png_composite(w, v, png_ptr->trans_alpha[i], back_1.blue);\n                     palette[i].blue = png_ptr->gamma_from_1[w];\n                  }\n               }\n               else\n               {\n                  palette[i].red = png_ptr->gamma_table[palette[i].red];\n                  palette[i].green = png_ptr->gamma_table[palette[i].green];\n                  palette[i].blue = png_ptr->gamma_table[palette[i].blue];\n               }\n            }\n\n            /* Prevent the transformations being done again.\n             *\n             * NOTE: this is highly dubious; it removes the transformations in\n             * place.  This seems inconsistent with the general treatment of the\n             * transformations elsewhere.\n             */\n            png_ptr->transformations &= ~(PNG_COMPOSE | PNG_GAMMA);\n         } /* color_type == PNG_COLOR_TYPE_PALETTE */\n\n         /* if (png_ptr->background_gamma_type!=PNG_BACKGROUND_GAMMA_UNKNOWN) */\n         else /* color_type != PNG_COLOR_TYPE_PALETTE */\n         {\n            int gs_sig, g_sig;\n            png_fixed_point g = PNG_FP_1;  /* Correction to linear */\n            png_fixed_point gs = PNG_FP_1; /* Correction to screen */\n\n            switch (png_ptr->background_gamma_type)\n            {\n               case PNG_BACKGROUND_GAMMA_SCREEN:\n                  g = png_ptr->screen_gamma;\n                  /* gs = PNG_FP_1; */\n                  break;\n\n               case PNG_BACKGROUND_GAMMA_FILE:\n                  g = png_reciprocal(png_ptr->colorspace.gamma);\n                  gs = png_reciprocal2(png_ptr->colorspace.gamma,\n                      png_ptr->screen_gamma);\n                  break;\n\n               case PNG_BACKGROUND_GAMMA_UNIQUE:\n                  g = png_reciprocal(png_ptr->background_gamma);\n                  gs = png_reciprocal2(png_ptr->background_gamma,\n                      png_ptr->screen_gamma);\n                  break;\n\n               default:\n                  png_error(png_ptr, \"invalid background gamma type\");\n            }\n\n            g_sig = png_gamma_significant(g);\n            gs_sig = png_gamma_significant(gs);\n\n            if (g_sig != 0)\n               png_ptr->background_1.gray = png_gamma_correct(png_ptr,\n                   png_ptr->background.gray, g);\n\n            if (gs_sig != 0)\n               png_ptr->background.gray = png_gamma_correct(png_ptr,\n                   png_ptr->background.gray, gs);\n\n            if ((png_ptr->background.red != png_ptr->background.green) ||\n                (png_ptr->background.red != png_ptr->background.blue) ||\n                (png_ptr->background.red != png_ptr->background.gray))\n            {\n               /* RGB or RGBA with color background */\n               if (g_sig != 0)\n               {\n                  png_ptr->background_1.red = png_gamma_correct(png_ptr,\n                      png_ptr->background.red, g);\n\n                  png_ptr->background_1.green = png_gamma_correct(png_ptr,\n                      png_ptr->background.green, g);\n\n                  png_ptr->background_1.blue = png_gamma_correct(png_ptr,\n                      png_ptr->background.blue, g);\n               }\n\n               if (gs_sig != 0)\n               {\n                  png_ptr->background.red = png_gamma_correct(png_ptr,\n                      png_ptr->background.red, gs);\n\n                  png_ptr->background.green = png_gamma_correct(png_ptr,\n                      png_ptr->background.green, gs);\n\n                  png_ptr->background.blue = png_gamma_correct(png_ptr,\n                      png_ptr->background.blue, gs);\n               }\n            }\n\n            else\n            {\n               /* GRAY, GRAY ALPHA, RGB, or RGBA with gray background */\n               png_ptr->background_1.red = png_ptr->background_1.green\n                   = png_ptr->background_1.blue = png_ptr->background_1.gray;\n\n               png_ptr->background.red = png_ptr->background.green\n                   = png_ptr->background.blue = png_ptr->background.gray;\n            }\n\n            /* The background is now in screen gamma: */\n            png_ptr->background_gamma_type = PNG_BACKGROUND_GAMMA_SCREEN;\n         } /* color_type != PNG_COLOR_TYPE_PALETTE */\n      }/* png_ptr->transformations & PNG_BACKGROUND */\n\n      else\n      /* Transformation does not include PNG_BACKGROUND */\n#endif /* READ_BACKGROUND */\n      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n         /* RGB_TO_GRAY needs to have non-gamma-corrected values! */\n         && ((png_ptr->transformations & PNG_EXPAND) == 0 ||\n         (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0)\n#endif\n         )\n      {\n         png_colorp palette = png_ptr->palette;\n         int num_palette = png_ptr->num_palette;\n         int i;\n\n         /* NOTE: there are other transformations that should probably be in\n          * here too.\n          */\n         for (i = 0; i < num_palette; i++)\n         {\n            palette[i].red = png_ptr->gamma_table[palette[i].red];\n            palette[i].green = png_ptr->gamma_table[palette[i].green];\n            palette[i].blue = png_ptr->gamma_table[palette[i].blue];\n         }\n\n         /* Done the gamma correction. */\n         png_ptr->transformations &= ~PNG_GAMMA;\n      } /* color_type == PALETTE && !PNG_BACKGROUND transformation */\n   }\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n   else\n#endif\n#endif /* READ_GAMMA */\n\n#ifdef PNG_READ_BACKGROUND_SUPPORTED\n   /* No GAMMA transformation (see the hanging else 4 lines above) */\n   if ((png_ptr->transformations & PNG_COMPOSE) != 0 &&\n       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))\n   {\n      int i;\n      int istop = (int)png_ptr->num_trans;\n      png_color back;\n      png_colorp palette = png_ptr->palette;\n\n      back.red   = (png_byte)png_ptr->background.red;\n      back.green = (png_byte)png_ptr->background.green;\n      back.blue  = (png_byte)png_ptr->background.blue;\n\n      for (i = 0; i < istop; i++)\n      {\n         if (png_ptr->trans_alpha[i] == 0)\n         {\n            palette[i] = back;\n         }\n\n         else if (png_ptr->trans_alpha[i] != 0xff)\n         {\n            /* The png_composite() macro is defined in png.h */\n            png_composite(palette[i].red, palette[i].red,\n                png_ptr->trans_alpha[i], back.red);\n\n            png_composite(palette[i].green, palette[i].green,\n                png_ptr->trans_alpha[i], back.green);\n\n            png_composite(palette[i].blue, palette[i].blue,\n                png_ptr->trans_alpha[i], back.blue);\n         }\n      }\n\n      png_ptr->transformations &= ~PNG_COMPOSE;\n   }\n#endif /* READ_BACKGROUND */\n\n#ifdef PNG_READ_SHIFT_SUPPORTED\n   if ((png_ptr->transformations & PNG_SHIFT) != 0 &&\n       (png_ptr->transformations & PNG_EXPAND) == 0 &&\n       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))\n   {\n      int i;\n      int istop = png_ptr->num_palette;\n      int shift = 8 - png_ptr->sig_bit.red;\n\n      png_ptr->transformations &= ~PNG_SHIFT;\n\n      /* significant bits can be in the range 1 to 7 for a meaninful result, if\n       * the number of significant bits is 0 then no shift is done (this is an\n       * error condition which is silently ignored.)\n       */\n      if (shift > 0 && shift < 8)\n         for (i=0; i<istop; ++i)\n         {\n            int component = png_ptr->palette[i].red;\n\n            component >>= shift;\n            png_ptr->palette[i].red = (png_byte)component;\n         }\n\n      shift = 8 - png_ptr->sig_bit.green;\n      if (shift > 0 && shift < 8)\n         for (i=0; i<istop; ++i)\n         {\n            int component = png_ptr->palette[i].green;\n\n            component >>= shift;\n            png_ptr->palette[i].green = (png_byte)component;\n         }\n\n      shift = 8 - png_ptr->sig_bit.blue;\n      if (shift > 0 && shift < 8)\n         for (i=0; i<istop; ++i)\n         {\n            int component = png_ptr->palette[i].blue;\n\n            component >>= shift;\n            png_ptr->palette[i].blue = (png_byte)component;\n         }\n   }\n#endif /* READ_SHIFT */\n}\n\n/* Modify the info structure to reflect the transformations.  The\n * info should be updated so a PNG file could be written with it,\n * assuming the transformations result in valid PNG data.\n */\nvoid /* PRIVATE */\npng_read_transform_info(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_debug(1, \"in png_read_transform_info\");\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n   if ((png_ptr->transformations & PNG_EXPAND) != 0)\n   {\n      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         /* This check must match what actually happens in\n          * png_do_expand_palette; if it ever checks the tRNS chunk to see if\n          * it is all opaque we must do the same (at present it does not.)\n          */\n         if (png_ptr->num_trans > 0)\n            info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;\n\n         else\n            info_ptr->color_type = PNG_COLOR_TYPE_RGB;\n\n         info_ptr->bit_depth = 8;\n         info_ptr->num_trans = 0;\n\n         if (png_ptr->palette == NULL)\n            png_error (png_ptr, \"Palette is NULL in indexed image\");\n      }\n      else\n      {\n         if (png_ptr->num_trans != 0)\n         {\n            if ((png_ptr->transformations & PNG_EXPAND_tRNS) != 0)\n               info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;\n         }\n         if (info_ptr->bit_depth < 8)\n            info_ptr->bit_depth = 8;\n\n         info_ptr->num_trans = 0;\n      }\n   }\n#endif\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n   /* The following is almost certainly wrong unless the background value is in\n    * the screen space!\n    */\n   if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n      info_ptr->background = png_ptr->background;\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   /* The following used to be conditional on PNG_GAMMA (prior to 1.5.4),\n    * however it seems that the code in png_init_read_transformations, which has\n    * been called before this from png_read_update_info->png_read_start_row\n    * sometimes does the gamma transform and cancels the flag.\n    *\n    * TODO: this looks wrong; the info_ptr should end up with a gamma equal to\n    * the screen_gamma value.  The following probably results in weirdness if\n    * the info_ptr is used by the app after the rows have been read.\n    */\n   info_ptr->colorspace.gamma = png_ptr->colorspace.gamma;\n#endif\n\n   if (info_ptr->bit_depth == 16)\n   {\n#  ifdef PNG_READ_16BIT_SUPPORTED\n#     ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n         if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)\n            info_ptr->bit_depth = 8;\n#     endif\n\n#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n         if ((png_ptr->transformations & PNG_16_TO_8) != 0)\n            info_ptr->bit_depth = 8;\n#     endif\n\n#  else\n      /* No 16-bit support: force chopping 16-bit input down to 8, in this case\n       * the app program can chose if both APIs are available by setting the\n       * correct scaling to use.\n       */\n#     ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n         /* For compatibility with previous versions use the strip method by\n          * default.  This code works because if PNG_SCALE_16_TO_8 is already\n          * set the code below will do that in preference to the chop.\n          */\n         png_ptr->transformations |= PNG_16_TO_8;\n         info_ptr->bit_depth = 8;\n#     else\n\n#        ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n            png_ptr->transformations |= PNG_SCALE_16_TO_8;\n            info_ptr->bit_depth = 8;\n#        else\n\n            CONFIGURATION ERROR: you must enable at least one 16 to 8 method\n#        endif\n#    endif\n#endif /* !READ_16BIT */\n   }\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)\n      info_ptr->color_type = (png_byte)(info_ptr->color_type |\n         PNG_COLOR_MASK_COLOR);\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)\n      info_ptr->color_type = (png_byte)(info_ptr->color_type &\n         ~PNG_COLOR_MASK_COLOR);\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)\n   {\n      if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||\n          (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&\n          png_ptr->palette_lookup != 0 && info_ptr->bit_depth == 8)\n      {\n         info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;\n      }\n   }\n#endif\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n   if ((png_ptr->transformations & PNG_EXPAND_16) != 0 &&\n       info_ptr->bit_depth == 8 &&\n       info_ptr->color_type != PNG_COLOR_TYPE_PALETTE)\n   {\n      info_ptr->bit_depth = 16;\n   }\n#endif\n\n#ifdef PNG_READ_PACK_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACK) != 0 &&\n       (info_ptr->bit_depth < 8))\n      info_ptr->bit_depth = 8;\n#endif\n\n   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      info_ptr->channels = 1;\n\n   else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      info_ptr->channels = 3;\n\n   else\n      info_ptr->channels = 1;\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0)\n   {\n      info_ptr->color_type = (png_byte)(info_ptr->color_type &\n         ~PNG_COLOR_MASK_ALPHA);\n      info_ptr->num_trans = 0;\n   }\n#endif\n\n   if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      info_ptr->channels++;\n\n#ifdef PNG_READ_FILLER_SUPPORTED\n   /* STRIP_ALPHA and FILLER allowed:  MASK_ALPHA bit stripped above */\n   if ((png_ptr->transformations & PNG_FILLER) != 0 &&\n       (info_ptr->color_type == PNG_COLOR_TYPE_RGB ||\n       info_ptr->color_type == PNG_COLOR_TYPE_GRAY))\n   {\n      info_ptr->channels++;\n      /* If adding a true alpha channel not just filler */\n      if ((png_ptr->transformations & PNG_ADD_ALPHA) != 0)\n         info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;\n   }\n#endif\n\n#if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \\\ndefined(PNG_READ_USER_TRANSFORM_SUPPORTED)\n   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)\n   {\n      if (png_ptr->user_transform_depth != 0)\n         info_ptr->bit_depth = png_ptr->user_transform_depth;\n\n      if (png_ptr->user_transform_channels != 0)\n         info_ptr->channels = png_ptr->user_transform_channels;\n   }\n#endif\n\n   info_ptr->pixel_depth = (png_byte)(info_ptr->channels *\n       info_ptr->bit_depth);\n\n   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, info_ptr->width);\n\n   /* Adding in 1.5.4: cache the above value in png_struct so that we can later\n    * check in png_rowbytes that the user buffer won't get overwritten.  Note\n    * that the field is not always set - if png_read_update_info isn't called\n    * the application has to either not do any transforms or get the calculation\n    * right itself.\n    */\n   png_ptr->info_rowbytes = info_ptr->rowbytes;\n\n#ifndef PNG_READ_EXPAND_SUPPORTED\n   if (png_ptr != NULL)\n      return;\n#endif\n}\n\n#ifdef PNG_READ_PACK_SUPPORTED\n/* Unpack pixels of 1, 2, or 4 bits per pixel into 1 byte per pixel,\n * without changing the actual values.  Thus, if you had a row with\n * a bit depth of 1, you would end up with bytes that only contained\n * the numbers 0 or 1.  If you would rather they contain 0 and 255, use\n * png_do_shift() after this.\n */\nstatic void\npng_do_unpack(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_unpack\");\n\n   if (row_info->bit_depth < 8)\n   {\n      png_uint_32 i;\n      png_uint_32 row_width=row_info->width;\n\n      switch (row_info->bit_depth)\n      {\n         case 1:\n         {\n            png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);\n            png_bytep dp = row + (png_size_t)row_width - 1;\n            png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);\n            for (i = 0; i < row_width; i++)\n            {\n               *dp = (png_byte)((*sp >> shift) & 0x01);\n\n               if (shift == 7)\n               {\n                  shift = 0;\n                  sp--;\n               }\n\n               else\n                  shift++;\n\n               dp--;\n            }\n            break;\n         }\n\n         case 2:\n         {\n\n            png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);\n            png_bytep dp = row + (png_size_t)row_width - 1;\n            png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);\n            for (i = 0; i < row_width; i++)\n            {\n               *dp = (png_byte)((*sp >> shift) & 0x03);\n\n               if (shift == 6)\n               {\n                  shift = 0;\n                  sp--;\n               }\n\n               else\n                  shift += 2;\n\n               dp--;\n            }\n            break;\n         }\n\n         case 4:\n         {\n            png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);\n            png_bytep dp = row + (png_size_t)row_width - 1;\n            png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);\n            for (i = 0; i < row_width; i++)\n            {\n               *dp = (png_byte)((*sp >> shift) & 0x0f);\n\n               if (shift == 4)\n               {\n                  shift = 0;\n                  sp--;\n               }\n\n               else\n                  shift = 4;\n\n               dp--;\n            }\n            break;\n         }\n\n         default:\n            break;\n      }\n      row_info->bit_depth = 8;\n      row_info->pixel_depth = (png_byte)(8 * row_info->channels);\n      row_info->rowbytes = row_width * row_info->channels;\n   }\n}\n#endif\n\n#ifdef PNG_READ_SHIFT_SUPPORTED\n/* Reverse the effects of png_do_shift.  This routine merely shifts the\n * pixels back to their significant bits values.  Thus, if you have\n * a row of bit depth 8, but only 5 are significant, this will shift\n * the values back to 0 through 31.\n */\nstatic void\npng_do_unshift(png_row_infop row_info, png_bytep row,\n    png_const_color_8p sig_bits)\n{\n   int color_type;\n\n   png_debug(1, \"in png_do_unshift\");\n\n   /* The palette case has already been handled in the _init routine. */\n   color_type = row_info->color_type;\n\n   if (color_type != PNG_COLOR_TYPE_PALETTE)\n   {\n      int shift[4];\n      int channels = 0;\n      int bit_depth = row_info->bit_depth;\n\n      if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n      {\n         shift[channels++] = bit_depth - sig_bits->red;\n         shift[channels++] = bit_depth - sig_bits->green;\n         shift[channels++] = bit_depth - sig_bits->blue;\n      }\n\n      else\n      {\n         shift[channels++] = bit_depth - sig_bits->gray;\n      }\n\n      if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      {\n         shift[channels++] = bit_depth - sig_bits->alpha;\n      }\n\n      {\n         int c, have_shift;\n\n         for (c = have_shift = 0; c < channels; ++c)\n         {\n            /* A shift of more than the bit depth is an error condition but it\n             * gets ignored here.\n             */\n            if (shift[c] <= 0 || shift[c] >= bit_depth)\n               shift[c] = 0;\n\n            else\n               have_shift = 1;\n         }\n\n         if (have_shift == 0)\n            return;\n      }\n\n      switch (bit_depth)\n      {\n         default:\n         /* Must be 1bpp gray: should not be here! */\n            /* NOTREACHED */\n            break;\n\n         case 2:\n         /* Must be 2bpp gray */\n         /* assert(channels == 1 && shift[0] == 1) */\n         {\n            png_bytep bp = row;\n            png_bytep bp_end = bp + row_info->rowbytes;\n\n            while (bp < bp_end)\n            {\n               int b = (*bp >> 1) & 0x55;\n               *bp++ = (png_byte)b;\n            }\n            break;\n         }\n\n         case 4:\n         /* Must be 4bpp gray */\n         /* assert(channels == 1) */\n         {\n            png_bytep bp = row;\n            png_bytep bp_end = bp + row_info->rowbytes;\n            int gray_shift = shift[0];\n            int mask =  0xf >> gray_shift;\n\n            mask |= mask << 4;\n\n            while (bp < bp_end)\n            {\n               int b = (*bp >> gray_shift) & mask;\n               *bp++ = (png_byte)b;\n            }\n            break;\n         }\n\n         case 8:\n         /* Single byte components, G, GA, RGB, RGBA */\n         {\n            png_bytep bp = row;\n            png_bytep bp_end = bp + row_info->rowbytes;\n            int channel = 0;\n\n            while (bp < bp_end)\n            {\n               int b = *bp >> shift[channel];\n               if (++channel >= channels)\n                  channel = 0;\n               *bp++ = (png_byte)b;\n            }\n            break;\n         }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n         case 16:\n         /* Double byte components, G, GA, RGB, RGBA */\n         {\n            png_bytep bp = row;\n            png_bytep bp_end = bp + row_info->rowbytes;\n            int channel = 0;\n\n            while (bp < bp_end)\n            {\n               int value = (bp[0] << 8) + bp[1];\n\n               value >>= shift[channel];\n               if (++channel >= channels)\n                  channel = 0;\n               *bp++ = (png_byte)(value >> 8);\n               *bp++ = (png_byte)value;\n            }\n            break;\n         }\n#endif\n      }\n   }\n}\n#endif\n\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n/* Scale rows of bit depth 16 down to 8 accurately */\nstatic void\npng_do_scale_16_to_8(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_scale_16_to_8\");\n\n   if (row_info->bit_depth == 16)\n   {\n      png_bytep sp = row; /* source */\n      png_bytep dp = row; /* destination */\n      png_bytep ep = sp + row_info->rowbytes; /* end+1 */\n\n      while (sp < ep)\n      {\n         /* The input is an array of 16-bit components, these must be scaled to\n          * 8 bits each.  For a 16-bit value V the required value (from the PNG\n          * specification) is:\n          *\n          *    (V * 255) / 65535\n          *\n          * This reduces to round(V / 257), or floor((V + 128.5)/257)\n          *\n          * Represent V as the two byte value vhi.vlo.  Make a guess that the\n          * result is the top byte of V, vhi, then the correction to this value\n          * is:\n          *\n          *    error = floor(((V-vhi.vhi) + 128.5) / 257)\n          *          = floor(((vlo-vhi) + 128.5) / 257)\n          *\n          * This can be approximated using integer arithmetic (and a signed\n          * shift):\n          *\n          *    error = (vlo-vhi+128) >> 8;\n          *\n          * The approximate differs from the exact answer only when (vlo-vhi) is\n          * 128; it then gives a correction of +1 when the exact correction is\n          * 0.  This gives 128 errors.  The exact answer (correct for all 16-bit\n          * input values) is:\n          *\n          *    error = (vlo-vhi+128)*65535 >> 24;\n          *\n          * An alternative arithmetic calculation which also gives no errors is:\n          *\n          *    (V * 255 + 32895) >> 16\n          */\n\n         png_int_32 tmp = *sp++; /* must be signed! */\n         tmp += (((int)*sp++ - tmp + 128) * 65535) >> 24;\n         *dp++ = (png_byte)tmp;\n      }\n\n      row_info->bit_depth = 8;\n      row_info->pixel_depth = (png_byte)(8 * row_info->channels);\n      row_info->rowbytes = row_info->width * row_info->channels;\n   }\n}\n#endif\n\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\nstatic void\n/* Simply discard the low byte.  This was the default behavior prior\n * to libpng-1.5.4.\n */\npng_do_chop(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_chop\");\n\n   if (row_info->bit_depth == 16)\n   {\n      png_bytep sp = row; /* source */\n      png_bytep dp = row; /* destination */\n      png_bytep ep = sp + row_info->rowbytes; /* end+1 */\n\n      while (sp < ep)\n      {\n         *dp++ = *sp;\n         sp += 2; /* skip low byte */\n      }\n\n      row_info->bit_depth = 8;\n      row_info->pixel_depth = (png_byte)(8 * row_info->channels);\n      row_info->rowbytes = row_info->width * row_info->channels;\n   }\n}\n#endif\n\n#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED\nstatic void\npng_do_read_swap_alpha(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_read_swap_alpha\");\n\n   {\n      png_uint_32 row_width = row_info->width;\n      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n      {\n         /* This converts from RGBA to ARGB */\n         if (row_info->bit_depth == 8)\n         {\n            png_bytep sp = row + row_info->rowbytes;\n            png_bytep dp = sp;\n            png_byte save;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               save = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = save;\n            }\n         }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n         /* This converts from RRGGBBAA to AARRGGBB */\n         else\n         {\n            png_bytep sp = row + row_info->rowbytes;\n            png_bytep dp = sp;\n            png_byte save[2];\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               save[0] = *(--sp);\n               save[1] = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = save[0];\n               *(--dp) = save[1];\n            }\n         }\n#endif\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      {\n         /* This converts from GA to AG */\n         if (row_info->bit_depth == 8)\n         {\n            png_bytep sp = row + row_info->rowbytes;\n            png_bytep dp = sp;\n            png_byte save;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               save = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = save;\n            }\n         }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n         /* This converts from GGAA to AAGG */\n         else\n         {\n            png_bytep sp = row + row_info->rowbytes;\n            png_bytep dp = sp;\n            png_byte save[2];\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               save[0] = *(--sp);\n               save[1] = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = save[0];\n               *(--dp) = save[1];\n            }\n         }\n#endif\n      }\n   }\n}\n#endif\n\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\nstatic void\npng_do_read_invert_alpha(png_row_infop row_info, png_bytep row)\n{\n   png_uint_32 row_width;\n   png_debug(1, \"in png_do_read_invert_alpha\");\n\n   row_width = row_info->width;\n   if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         /* This inverts the alpha channel in RGBA */\n         png_bytep sp = row + row_info->rowbytes;\n         png_bytep dp = sp;\n         png_uint_32 i;\n\n         for (i = 0; i < row_width; i++)\n         {\n            *(--dp) = (png_byte)(255 - *(--sp));\n\n/*          This does nothing:\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            We can replace it with:\n*/\n            sp-=3;\n            dp=sp;\n         }\n      }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n      /* This inverts the alpha channel in RRGGBBAA */\n      else\n      {\n         png_bytep sp = row + row_info->rowbytes;\n         png_bytep dp = sp;\n         png_uint_32 i;\n\n         for (i = 0; i < row_width; i++)\n         {\n            *(--dp) = (png_byte)(255 - *(--sp));\n            *(--dp) = (png_byte)(255 - *(--sp));\n\n/*          This does nothing:\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n            We can replace it with:\n*/\n            sp-=6;\n            dp=sp;\n         }\n      }\n#endif\n   }\n   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         /* This inverts the alpha channel in GA */\n         png_bytep sp = row + row_info->rowbytes;\n         png_bytep dp = sp;\n         png_uint_32 i;\n\n         for (i = 0; i < row_width; i++)\n         {\n            *(--dp) = (png_byte)(255 - *(--sp));\n            *(--dp) = *(--sp);\n         }\n      }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n      else\n      {\n         /* This inverts the alpha channel in GGAA */\n         png_bytep sp  = row + row_info->rowbytes;\n         png_bytep dp = sp;\n         png_uint_32 i;\n\n         for (i = 0; i < row_width; i++)\n         {\n            *(--dp) = (png_byte)(255 - *(--sp));\n            *(--dp) = (png_byte)(255 - *(--sp));\n/*\n            *(--dp) = *(--sp);\n            *(--dp) = *(--sp);\n*/\n            sp-=2;\n            dp=sp;\n         }\n      }\n#endif\n   }\n}\n#endif\n\n#ifdef PNG_READ_FILLER_SUPPORTED\n/* Add filler channel if we have RGB color */\nstatic void\npng_do_read_filler(png_row_infop row_info, png_bytep row,\n    png_uint_32 filler, png_uint_32 flags)\n{\n   png_uint_32 i;\n   png_uint_32 row_width = row_info->width;\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n   png_byte hi_filler = (png_byte)(filler>>8);\n#endif\n   png_byte lo_filler = (png_byte)filler;\n\n   png_debug(1, \"in png_do_read_filler\");\n\n   if (\n       row_info->color_type == PNG_COLOR_TYPE_GRAY)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)\n         {\n            /* This changes the data from G to GX */\n            png_bytep sp = row + (png_size_t)row_width;\n            png_bytep dp =  sp + (png_size_t)row_width;\n            for (i = 1; i < row_width; i++)\n            {\n               *(--dp) = lo_filler;\n               *(--dp) = *(--sp);\n            }\n            *(--dp) = lo_filler;\n            row_info->channels = 2;\n            row_info->pixel_depth = 16;\n            row_info->rowbytes = row_width * 2;\n         }\n\n         else\n         {\n            /* This changes the data from G to XG */\n            png_bytep sp = row + (png_size_t)row_width;\n            png_bytep dp = sp  + (png_size_t)row_width;\n            for (i = 0; i < row_width; i++)\n            {\n               *(--dp) = *(--sp);\n               *(--dp) = lo_filler;\n            }\n            row_info->channels = 2;\n            row_info->pixel_depth = 16;\n            row_info->rowbytes = row_width * 2;\n         }\n      }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n      else if (row_info->bit_depth == 16)\n      {\n         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)\n         {\n            /* This changes the data from GG to GGXX */\n            png_bytep sp = row + (png_size_t)row_width * 2;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 1; i < row_width; i++)\n            {\n               *(--dp) = lo_filler;\n               *(--dp) = hi_filler;\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n            }\n            *(--dp) = lo_filler;\n            *(--dp) = hi_filler;\n            row_info->channels = 2;\n            row_info->pixel_depth = 32;\n            row_info->rowbytes = row_width * 4;\n         }\n\n         else\n         {\n            /* This changes the data from GG to XXGG */\n            png_bytep sp = row + (png_size_t)row_width * 2;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 0; i < row_width; i++)\n            {\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = lo_filler;\n               *(--dp) = hi_filler;\n            }\n            row_info->channels = 2;\n            row_info->pixel_depth = 32;\n            row_info->rowbytes = row_width * 4;\n         }\n      }\n#endif\n   } /* COLOR_TYPE == GRAY */\n   else if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)\n         {\n            /* This changes the data from RGB to RGBX */\n            png_bytep sp = row + (png_size_t)row_width * 3;\n            png_bytep dp = sp  + (png_size_t)row_width;\n            for (i = 1; i < row_width; i++)\n            {\n               *(--dp) = lo_filler;\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n            }\n            *(--dp) = lo_filler;\n            row_info->channels = 4;\n            row_info->pixel_depth = 32;\n            row_info->rowbytes = row_width * 4;\n         }\n\n         else\n         {\n            /* This changes the data from RGB to XRGB */\n            png_bytep sp = row + (png_size_t)row_width * 3;\n            png_bytep dp = sp + (png_size_t)row_width;\n            for (i = 0; i < row_width; i++)\n            {\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = lo_filler;\n            }\n            row_info->channels = 4;\n            row_info->pixel_depth = 32;\n            row_info->rowbytes = row_width * 4;\n         }\n      }\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n      else if (row_info->bit_depth == 16)\n      {\n         if ((flags & PNG_FLAG_FILLER_AFTER) != 0)\n         {\n            /* This changes the data from RRGGBB to RRGGBBXX */\n            png_bytep sp = row + (png_size_t)row_width * 6;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 1; i < row_width; i++)\n            {\n               *(--dp) = lo_filler;\n               *(--dp) = hi_filler;\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n            }\n            *(--dp) = lo_filler;\n            *(--dp) = hi_filler;\n            row_info->channels = 4;\n            row_info->pixel_depth = 64;\n            row_info->rowbytes = row_width * 8;\n         }\n\n         else\n         {\n            /* This changes the data from RRGGBB to XXRRGGBB */\n            png_bytep sp = row + (png_size_t)row_width * 6;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 0; i < row_width; i++)\n            {\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = *(--sp);\n               *(--dp) = lo_filler;\n               *(--dp) = hi_filler;\n            }\n\n            row_info->channels = 4;\n            row_info->pixel_depth = 64;\n            row_info->rowbytes = row_width * 8;\n         }\n      }\n#endif\n   } /* COLOR_TYPE == RGB */\n}\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n/* Expand grayscale files to RGB, with or without alpha */\nstatic void\npng_do_gray_to_rgb(png_row_infop row_info, png_bytep row)\n{\n   png_uint_32 i;\n   png_uint_32 row_width = row_info->width;\n\n   png_debug(1, \"in png_do_gray_to_rgb\");\n\n   if (row_info->bit_depth >= 8 &&\n       (row_info->color_type & PNG_COLOR_MASK_COLOR) == 0)\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This changes G to RGB */\n            png_bytep sp = row + (png_size_t)row_width - 1;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 0; i < row_width; i++)\n            {\n               *(dp--) = *sp;\n               *(dp--) = *sp;\n               *(dp--) = *(sp--);\n            }\n         }\n\n         else\n         {\n            /* This changes GG to RRGGBB */\n            png_bytep sp = row + (png_size_t)row_width * 2 - 1;\n            png_bytep dp = sp  + (png_size_t)row_width * 4;\n            for (i = 0; i < row_width; i++)\n            {\n               *(dp--) = *sp;\n               *(dp--) = *(sp - 1);\n               *(dp--) = *sp;\n               *(dp--) = *(sp - 1);\n               *(dp--) = *(sp--);\n               *(dp--) = *(sp--);\n            }\n         }\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This changes GA to RGBA */\n            png_bytep sp = row + (png_size_t)row_width * 2 - 1;\n            png_bytep dp = sp  + (png_size_t)row_width * 2;\n            for (i = 0; i < row_width; i++)\n            {\n               *(dp--) = *(sp--);\n               *(dp--) = *sp;\n               *(dp--) = *sp;\n               *(dp--) = *(sp--);\n            }\n         }\n\n         else\n         {\n            /* This changes GGAA to RRGGBBAA */\n            png_bytep sp = row + (png_size_t)row_width * 4 - 1;\n            png_bytep dp = sp  + (png_size_t)row_width * 4;\n            for (i = 0; i < row_width; i++)\n            {\n               *(dp--) = *(sp--);\n               *(dp--) = *(sp--);\n               *(dp--) = *sp;\n               *(dp--) = *(sp - 1);\n               *(dp--) = *sp;\n               *(dp--) = *(sp - 1);\n               *(dp--) = *(sp--);\n               *(dp--) = *(sp--);\n            }\n         }\n      }\n      row_info->channels = (png_byte)(row_info->channels + 2);\n      row_info->color_type |= PNG_COLOR_MASK_COLOR;\n      row_info->pixel_depth = (png_byte)(row_info->channels *\n          row_info->bit_depth);\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);\n   }\n}\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n/* Reduce RGB files to grayscale, with or without alpha\n * using the equation given in Poynton's ColorFAQ of 1998-01-04 at\n * <http://www.inforamp.net/~poynton/>  (THIS LINK IS DEAD June 2008 but\n * versions dated 1998 through November 2002 have been archived at\n * http://web.archive.org/web/20000816232553/http://www.inforamp.net/\n * ~poynton/notes/colour_and_gamma/ColorFAQ.txt )\n * Charles Poynton poynton at poynton.com\n *\n *     Y = 0.212671 * R + 0.715160 * G + 0.072169 * B\n *\n *  which can be expressed with integers as\n *\n *     Y = (6969 * R + 23434 * G + 2365 * B)/32768\n *\n * Poynton's current link (as of January 2003 through July 2011):\n * <http://www.poynton.com/notes/colour_and_gamma/>\n * has changed the numbers slightly:\n *\n *     Y = 0.2126*R + 0.7152*G + 0.0722*B\n *\n *  which can be expressed with integers as\n *\n *     Y = (6966 * R + 23436 * G + 2366 * B)/32768\n *\n *  Historically, however, libpng uses numbers derived from the ITU-R Rec 709\n *  end point chromaticities and the D65 white point.  Depending on the\n *  precision used for the D65 white point this produces a variety of different\n *  numbers, however if the four decimal place value used in ITU-R Rec 709 is\n *  used (0.3127,0.3290) the Y calculation would be:\n *\n *     Y = (6968 * R + 23435 * G + 2366 * B)/32768\n *\n *  While this is correct the rounding results in an overflow for white, because\n *  the sum of the rounded coefficients is 32769, not 32768.  Consequently\n *  libpng uses, instead, the closest non-overflowing approximation:\n *\n *     Y = (6968 * R + 23434 * G + 2366 * B)/32768\n *\n *  Starting with libpng-1.5.5, if the image being converted has a cHRM chunk\n *  (including an sRGB chunk) then the chromaticities are used to calculate the\n *  coefficients.  See the chunk handling in pngrutil.c for more information.\n *\n *  In all cases the calculation is to be done in a linear colorspace.  If no\n *  gamma information is available to correct the encoding of the original RGB\n *  values this results in an implicit assumption that the original PNG RGB\n *  values were linear.\n *\n *  Other integer coefficents can be used via png_set_rgb_to_gray().  Because\n *  the API takes just red and green coefficients the blue coefficient is\n *  calculated to make the sum 32768.  This will result in different rounding\n *  to that used above.\n */\nstatic int\npng_do_rgb_to_gray(png_structrp png_ptr, png_row_infop row_info, png_bytep row)\n\n{\n   int rgb_error = 0;\n\n   png_debug(1, \"in png_do_rgb_to_gray\");\n\n   if ((row_info->color_type & PNG_COLOR_MASK_PALETTE) == 0 &&\n       (row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      PNG_CONST png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;\n      PNG_CONST png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;\n      PNG_CONST png_uint_32 bc = 32768 - rc - gc;\n      PNG_CONST png_uint_32 row_width = row_info->width;\n      PNG_CONST int have_alpha =\n         (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0;\n\n      if (row_info->bit_depth == 8)\n      {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n         /* Notice that gamma to/from 1 are not necessarily inverses (if\n          * there is an overall gamma correction).  Prior to 1.5.5 this code\n          * checked the linearized values for equality; this doesn't match\n          * the documentation, the original values must be checked.\n          */\n         if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)\n         {\n            png_bytep sp = row;\n            png_bytep dp = row;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_byte red   = *(sp++);\n               png_byte green = *(sp++);\n               png_byte blue  = *(sp++);\n\n               if (red != green || red != blue)\n               {\n                  red = png_ptr->gamma_to_1[red];\n                  green = png_ptr->gamma_to_1[green];\n                  blue = png_ptr->gamma_to_1[blue];\n\n                  rgb_error |= 1;\n                  *(dp++) = png_ptr->gamma_from_1[\n                      (rc*red + gc*green + bc*blue + 16384)>>15];\n               }\n\n               else\n               {\n                  /* If there is no overall correction the table will not be\n                   * set.\n                   */\n                  if (png_ptr->gamma_table != NULL)\n                     red = png_ptr->gamma_table[red];\n\n                  *(dp++) = red;\n               }\n\n               if (have_alpha != 0)\n                  *(dp++) = *(sp++);\n            }\n         }\n         else\n#endif\n         {\n            png_bytep sp = row;\n            png_bytep dp = row;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_byte red   = *(sp++);\n               png_byte green = *(sp++);\n               png_byte blue  = *(sp++);\n\n               if (red != green || red != blue)\n               {\n                  rgb_error |= 1;\n                  /* NOTE: this is the historical approach which simply\n                   * truncates the results.\n                   */\n                  *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);\n               }\n\n               else\n                  *(dp++) = red;\n\n               if (have_alpha != 0)\n                  *(dp++) = *(sp++);\n            }\n         }\n      }\n\n      else /* RGB bit_depth == 16 */\n      {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n         if (png_ptr->gamma_16_to_1 != NULL && png_ptr->gamma_16_from_1 != NULL)\n         {\n            png_bytep sp = row;\n            png_bytep dp = row;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_uint_16 red, green, blue, w;\n               png_byte hi,lo;\n\n               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));\n               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));\n               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));\n\n               if (red == green && red == blue)\n               {\n                  if (png_ptr->gamma_16_table != NULL)\n                     w = png_ptr->gamma_16_table[(red & 0xff)\n                         >> png_ptr->gamma_shift][red >> 8];\n\n                  else\n                     w = red;\n               }\n\n               else\n               {\n                  png_uint_16 red_1   = png_ptr->gamma_16_to_1[(red & 0xff)\n                      >> png_ptr->gamma_shift][red>>8];\n                  png_uint_16 green_1 =\n                      png_ptr->gamma_16_to_1[(green & 0xff) >>\n                      png_ptr->gamma_shift][green>>8];\n                  png_uint_16 blue_1  = png_ptr->gamma_16_to_1[(blue & 0xff)\n                      >> png_ptr->gamma_shift][blue>>8];\n                  png_uint_16 gray16  = (png_uint_16)((rc*red_1 + gc*green_1\n                      + bc*blue_1 + 16384)>>15);\n                  w = png_ptr->gamma_16_from_1[(gray16 & 0xff) >>\n                      png_ptr->gamma_shift][gray16 >> 8];\n                  rgb_error |= 1;\n               }\n\n               *(dp++) = (png_byte)((w>>8) & 0xff);\n               *(dp++) = (png_byte)(w & 0xff);\n\n               if (have_alpha != 0)\n               {\n                  *(dp++) = *(sp++);\n                  *(dp++) = *(sp++);\n               }\n            }\n         }\n         else\n#endif\n         {\n            png_bytep sp = row;\n            png_bytep dp = row;\n            png_uint_32 i;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_uint_16 red, green, blue, gray16;\n               png_byte hi,lo;\n\n               hi=*(sp)++; lo=*(sp)++; red   = (png_uint_16)((hi << 8) | (lo));\n               hi=*(sp)++; lo=*(sp)++; green = (png_uint_16)((hi << 8) | (lo));\n               hi=*(sp)++; lo=*(sp)++; blue  = (png_uint_16)((hi << 8) | (lo));\n\n               if (red != green || red != blue)\n                  rgb_error |= 1;\n\n               /* From 1.5.5 in the 16-bit case do the accurate conversion even\n                * in the 'fast' case - this is because this is where the code\n                * ends up when handling linear 16-bit data.\n                */\n               gray16  = (png_uint_16)((rc*red + gc*green + bc*blue + 16384) >>\n                  15);\n               *(dp++) = (png_byte)((gray16 >> 8) & 0xff);\n               *(dp++) = (png_byte)(gray16 & 0xff);\n\n               if (have_alpha != 0)\n               {\n                  *(dp++) = *(sp++);\n                  *(dp++) = *(sp++);\n               }\n            }\n         }\n      }\n\n      row_info->channels = (png_byte)(row_info->channels - 2);\n      row_info->color_type = (png_byte)(row_info->color_type &\n          ~PNG_COLOR_MASK_COLOR);\n      row_info->pixel_depth = (png_byte)(row_info->channels *\n          row_info->bit_depth);\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);\n   }\n   return rgb_error;\n}\n#endif\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n/* Replace any alpha or transparency with the supplied background color.\n * \"background\" is already in the screen gamma, while \"background_1\" is\n * at a gamma of 1.0.  Paletted files have already been taken care of.\n */\nstatic void\npng_do_compose(png_row_infop row_info, png_bytep row, png_structrp png_ptr)\n{\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   png_const_bytep gamma_table = png_ptr->gamma_table;\n   png_const_bytep gamma_from_1 = png_ptr->gamma_from_1;\n   png_const_bytep gamma_to_1 = png_ptr->gamma_to_1;\n   png_const_uint_16pp gamma_16 = png_ptr->gamma_16_table;\n   png_const_uint_16pp gamma_16_from_1 = png_ptr->gamma_16_from_1;\n   png_const_uint_16pp gamma_16_to_1 = png_ptr->gamma_16_to_1;\n   int gamma_shift = png_ptr->gamma_shift;\n   int optimize = (png_ptr->flags & PNG_FLAG_OPTIMIZE_ALPHA) != 0;\n#endif\n\n   png_bytep sp;\n   png_uint_32 i;\n   png_uint_32 row_width = row_info->width;\n   int shift;\n\n   png_debug(1, \"in png_do_compose\");\n\n   {\n      switch (row_info->color_type)\n      {\n         case PNG_COLOR_TYPE_GRAY:\n         {\n            switch (row_info->bit_depth)\n            {\n               case 1:\n               {\n                  sp = row;\n                  shift = 7;\n                  for (i = 0; i < row_width; i++)\n                  {\n                     if ((png_uint_16)((*sp >> shift) & 0x01)\n                        == png_ptr->trans_color.gray)\n                     {\n                        unsigned int tmp = *sp & (0x7f7f >> (7 - shift));\n                        tmp |= png_ptr->background.gray << shift;\n                        *sp = (png_byte)(tmp & 0xff);\n                     }\n\n                     if (shift == 0)\n                     {\n                        shift = 7;\n                        sp++;\n                     }\n\n                     else\n                        shift--;\n                  }\n                  break;\n               }\n\n               case 2:\n               {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n                  if (gamma_table != NULL)\n                  {\n                     sp = row;\n                     shift = 6;\n                     for (i = 0; i < row_width; i++)\n                     {\n                        if ((png_uint_16)((*sp >> shift) & 0x03)\n                            == png_ptr->trans_color.gray)\n                        {\n                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));\n                           tmp |= png_ptr->background.gray << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        else\n                        {\n                           unsigned int p = (*sp >> shift) & 0x03;\n                           unsigned int g = (gamma_table [p | (p << 2) |\n                               (p << 4) | (p << 6)] >> 6) & 0x03;\n                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));\n                           tmp |= g << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        if (shift == 0)\n                        {\n                           shift = 6;\n                           sp++;\n                        }\n\n                        else\n                           shift -= 2;\n                     }\n                  }\n\n                  else\n#endif\n                  {\n                     sp = row;\n                     shift = 6;\n                     for (i = 0; i < row_width; i++)\n                     {\n                        if ((png_uint_16)((*sp >> shift) & 0x03)\n                            == png_ptr->trans_color.gray)\n                        {\n                           unsigned int tmp = *sp & (0x3f3f >> (6 - shift));\n                           tmp |= png_ptr->background.gray << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        if (shift == 0)\n                        {\n                           shift = 6;\n                           sp++;\n                        }\n\n                        else\n                           shift -= 2;\n                     }\n                  }\n                  break;\n               }\n\n               case 4:\n               {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n                  if (gamma_table != NULL)\n                  {\n                     sp = row;\n                     shift = 4;\n                     for (i = 0; i < row_width; i++)\n                     {\n                        if ((png_uint_16)((*sp >> shift) & 0x0f)\n                            == png_ptr->trans_color.gray)\n                        {\n                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));\n                           tmp |= png_ptr->background.gray << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        else\n                        {\n                           unsigned int p = (*sp >> shift) & 0x0f;\n                           unsigned int g = (gamma_table[p | (p << 4)] >> 4) &\n                              0x0f;\n                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));\n                           tmp |= g << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        if (shift == 0)\n                        {\n                           shift = 4;\n                           sp++;\n                        }\n\n                        else\n                           shift -= 4;\n                     }\n                  }\n\n                  else\n#endif\n                  {\n                     sp = row;\n                     shift = 4;\n                     for (i = 0; i < row_width; i++)\n                     {\n                        if ((png_uint_16)((*sp >> shift) & 0x0f)\n                            == png_ptr->trans_color.gray)\n                        {\n                           unsigned int tmp = *sp & (0x0f0f >> (4 - shift));\n                           tmp |= png_ptr->background.gray << shift;\n                           *sp = (png_byte)(tmp & 0xff);\n                        }\n\n                        if (shift == 0)\n                        {\n                           shift = 4;\n                           sp++;\n                        }\n\n                        else\n                           shift -= 4;\n                     }\n                  }\n                  break;\n               }\n\n               case 8:\n               {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n                  if (gamma_table != NULL)\n                  {\n                     sp = row;\n                     for (i = 0; i < row_width; i++, sp++)\n                     {\n                        if (*sp == png_ptr->trans_color.gray)\n                           *sp = (png_byte)png_ptr->background.gray;\n\n                        else\n                           *sp = gamma_table[*sp];\n                     }\n                  }\n                  else\n#endif\n                  {\n                     sp = row;\n                     for (i = 0; i < row_width; i++, sp++)\n                     {\n                        if (*sp == png_ptr->trans_color.gray)\n                           *sp = (png_byte)png_ptr->background.gray;\n                     }\n                  }\n                  break;\n               }\n\n               case 16:\n               {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n                  if (gamma_16 != NULL)\n                  {\n                     sp = row;\n                     for (i = 0; i < row_width; i++, sp += 2)\n                     {\n                        png_uint_16 v;\n\n                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n\n                        if (v == png_ptr->trans_color.gray)\n                        {\n                           /* Background is already in screen gamma */\n                           *sp = (png_byte)((png_ptr->background.gray >> 8)\n                                & 0xff);\n                           *(sp + 1) = (png_byte)(png_ptr->background.gray\n                                & 0xff);\n                        }\n\n                        else\n                        {\n                           v = gamma_16[*(sp + 1) >> gamma_shift][*sp];\n                           *sp = (png_byte)((v >> 8) & 0xff);\n                           *(sp + 1) = (png_byte)(v & 0xff);\n                        }\n                     }\n                  }\n                  else\n#endif\n                  {\n                     sp = row;\n                     for (i = 0; i < row_width; i++, sp += 2)\n                     {\n                        png_uint_16 v;\n\n                        v = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n\n                        if (v == png_ptr->trans_color.gray)\n                        {\n                           *sp = (png_byte)((png_ptr->background.gray >> 8)\n                                & 0xff);\n                           *(sp + 1) = (png_byte)(png_ptr->background.gray\n                                & 0xff);\n                        }\n                     }\n                  }\n                  break;\n               }\n\n               default:\n                  break;\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_RGB:\n         {\n            if (row_info->bit_depth == 8)\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_table != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 3)\n                  {\n                     if (*sp == png_ptr->trans_color.red &&\n                         *(sp + 1) == png_ptr->trans_color.green &&\n                         *(sp + 2) == png_ptr->trans_color.blue)\n                     {\n                        *sp = (png_byte)png_ptr->background.red;\n                        *(sp + 1) = (png_byte)png_ptr->background.green;\n                        *(sp + 2) = (png_byte)png_ptr->background.blue;\n                     }\n\n                     else\n                     {\n                        *sp = gamma_table[*sp];\n                        *(sp + 1) = gamma_table[*(sp + 1)];\n                        *(sp + 2) = gamma_table[*(sp + 2)];\n                     }\n                  }\n               }\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 3)\n                  {\n                     if (*sp == png_ptr->trans_color.red &&\n                         *(sp + 1) == png_ptr->trans_color.green &&\n                         *(sp + 2) == png_ptr->trans_color.blue)\n                     {\n                        *sp = (png_byte)png_ptr->background.red;\n                        *(sp + 1) = (png_byte)png_ptr->background.green;\n                        *(sp + 2) = (png_byte)png_ptr->background.blue;\n                     }\n                  }\n               }\n            }\n            else /* if (row_info->bit_depth == 16) */\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_16 != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 6)\n                  {\n                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n\n                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)\n                         + *(sp + 3));\n\n                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)\n                         + *(sp + 5));\n\n                     if (r == png_ptr->trans_color.red &&\n                         g == png_ptr->trans_color.green &&\n                         b == png_ptr->trans_color.blue)\n                     {\n                        /* Background is already in screen gamma */\n                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);\n                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)\n                                & 0xff);\n                        *(sp + 3) = (png_byte)(png_ptr->background.green\n                                & 0xff);\n                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)\n                                & 0xff);\n                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);\n                     }\n\n                     else\n                     {\n                        png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];\n                        *sp = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(v & 0xff);\n\n                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];\n                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 3) = (png_byte)(v & 0xff);\n\n                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];\n                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 5) = (png_byte)(v & 0xff);\n                     }\n                  }\n               }\n\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 6)\n                  {\n                     png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n\n                     png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)\n                         + *(sp + 3));\n\n                     png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)\n                         + *(sp + 5));\n\n                     if (r == png_ptr->trans_color.red &&\n                         g == png_ptr->trans_color.green &&\n                         b == png_ptr->trans_color.blue)\n                     {\n                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);\n                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)\n                                & 0xff);\n                        *(sp + 3) = (png_byte)(png_ptr->background.green\n                                & 0xff);\n                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)\n                                & 0xff);\n                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);\n                     }\n                  }\n               }\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_GRAY_ALPHA:\n         {\n            if (row_info->bit_depth == 8)\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&\n                   gamma_table != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 2)\n                  {\n                     png_uint_16 a = *(sp + 1);\n\n                     if (a == 0xff)\n                        *sp = gamma_table[*sp];\n\n                     else if (a == 0)\n                     {\n                        /* Background is already in screen gamma */\n                        *sp = (png_byte)png_ptr->background.gray;\n                     }\n\n                     else\n                     {\n                        png_byte v, w;\n\n                        v = gamma_to_1[*sp];\n                        png_composite(w, v, a, png_ptr->background_1.gray);\n                        if (optimize == 0)\n                           w = gamma_from_1[w];\n                        *sp = w;\n                     }\n                  }\n               }\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 2)\n                  {\n                     png_byte a = *(sp + 1);\n\n                     if (a == 0)\n                        *sp = (png_byte)png_ptr->background.gray;\n\n                     else if (a < 0xff)\n                        png_composite(*sp, *sp, a, png_ptr->background.gray);\n                  }\n               }\n            }\n            else /* if (png_ptr->bit_depth == 16) */\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&\n                   gamma_16_to_1 != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 4)\n                  {\n                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)\n                         + *(sp + 3));\n\n                     if (a == (png_uint_16)0xffff)\n                     {\n                        png_uint_16 v;\n\n                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];\n                        *sp = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(v & 0xff);\n                     }\n\n                     else if (a == 0)\n                     {\n                        /* Background is already in screen gamma */\n                        *sp = (png_byte)((png_ptr->background.gray >> 8)\n                                & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);\n                     }\n\n                     else\n                     {\n                        png_uint_16 g, v, w;\n\n                        g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];\n                        png_composite_16(v, g, a, png_ptr->background_1.gray);\n                        if (optimize != 0)\n                           w = v;\n                        else\n                           w = gamma_16_from_1[(v & 0xff) >>\n                               gamma_shift][v >> 8];\n                        *sp = (png_byte)((w >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(w & 0xff);\n                     }\n                  }\n               }\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 4)\n                  {\n                     png_uint_16 a = (png_uint_16)(((*(sp + 2)) << 8)\n                         + *(sp + 3));\n\n                     if (a == 0)\n                     {\n                        *sp = (png_byte)((png_ptr->background.gray >> 8)\n                                & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.gray & 0xff);\n                     }\n\n                     else if (a < 0xffff)\n                     {\n                        png_uint_16 g, v;\n\n                        g = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n                        png_composite_16(v, g, a, png_ptr->background.gray);\n                        *sp = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(v & 0xff);\n                     }\n                  }\n               }\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_RGB_ALPHA:\n         {\n            if (row_info->bit_depth == 8)\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_to_1 != NULL && gamma_from_1 != NULL &&\n                   gamma_table != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 4)\n                  {\n                     png_byte a = *(sp + 3);\n\n                     if (a == 0xff)\n                     {\n                        *sp = gamma_table[*sp];\n                        *(sp + 1) = gamma_table[*(sp + 1)];\n                        *(sp + 2) = gamma_table[*(sp + 2)];\n                     }\n\n                     else if (a == 0)\n                     {\n                        /* Background is already in screen gamma */\n                        *sp = (png_byte)png_ptr->background.red;\n                        *(sp + 1) = (png_byte)png_ptr->background.green;\n                        *(sp + 2) = (png_byte)png_ptr->background.blue;\n                     }\n\n                     else\n                     {\n                        png_byte v, w;\n\n                        v = gamma_to_1[*sp];\n                        png_composite(w, v, a, png_ptr->background_1.red);\n                        if (optimize == 0) w = gamma_from_1[w];\n                        *sp = w;\n\n                        v = gamma_to_1[*(sp + 1)];\n                        png_composite(w, v, a, png_ptr->background_1.green);\n                        if (optimize == 0) w = gamma_from_1[w];\n                        *(sp + 1) = w;\n\n                        v = gamma_to_1[*(sp + 2)];\n                        png_composite(w, v, a, png_ptr->background_1.blue);\n                        if (optimize == 0) w = gamma_from_1[w];\n                        *(sp + 2) = w;\n                     }\n                  }\n               }\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 4)\n                  {\n                     png_byte a = *(sp + 3);\n\n                     if (a == 0)\n                     {\n                        *sp = (png_byte)png_ptr->background.red;\n                        *(sp + 1) = (png_byte)png_ptr->background.green;\n                        *(sp + 2) = (png_byte)png_ptr->background.blue;\n                     }\n\n                     else if (a < 0xff)\n                     {\n                        png_composite(*sp, *sp, a, png_ptr->background.red);\n\n                        png_composite(*(sp + 1), *(sp + 1), a,\n                            png_ptr->background.green);\n\n                        png_composite(*(sp + 2), *(sp + 2), a,\n                            png_ptr->background.blue);\n                     }\n                  }\n               }\n            }\n            else /* if (row_info->bit_depth == 16) */\n            {\n#ifdef PNG_READ_GAMMA_SUPPORTED\n               if (gamma_16 != NULL && gamma_16_from_1 != NULL &&\n                   gamma_16_to_1 != NULL)\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 8)\n                  {\n                     png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))\n                         << 8) + (png_uint_16)(*(sp + 7)));\n\n                     if (a == (png_uint_16)0xffff)\n                     {\n                        png_uint_16 v;\n\n                        v = gamma_16[*(sp + 1) >> gamma_shift][*sp];\n                        *sp = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(v & 0xff);\n\n                        v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];\n                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 3) = (png_byte)(v & 0xff);\n\n                        v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];\n                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 5) = (png_byte)(v & 0xff);\n                     }\n\n                     else if (a == 0)\n                     {\n                        /* Background is already in screen gamma */\n                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);\n                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)\n                                & 0xff);\n                        *(sp + 3) = (png_byte)(png_ptr->background.green\n                                & 0xff);\n                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)\n                                & 0xff);\n                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);\n                     }\n\n                     else\n                     {\n                        png_uint_16 v, w;\n\n                        v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];\n                        png_composite_16(w, v, a, png_ptr->background_1.red);\n                        if (optimize == 0)\n                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>\n                                8];\n                        *sp = (png_byte)((w >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(w & 0xff);\n\n                        v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];\n                        png_composite_16(w, v, a, png_ptr->background_1.green);\n                        if (optimize == 0)\n                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>\n                                8];\n\n                        *(sp + 2) = (png_byte)((w >> 8) & 0xff);\n                        *(sp + 3) = (png_byte)(w & 0xff);\n\n                        v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];\n                        png_composite_16(w, v, a, png_ptr->background_1.blue);\n                        if (optimize == 0)\n                           w = gamma_16_from_1[((w & 0xff) >> gamma_shift)][w >>\n                                8];\n\n                        *(sp + 4) = (png_byte)((w >> 8) & 0xff);\n                        *(sp + 5) = (png_byte)(w & 0xff);\n                     }\n                  }\n               }\n\n               else\n#endif\n               {\n                  sp = row;\n                  for (i = 0; i < row_width; i++, sp += 8)\n                  {\n                     png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))\n                         << 8) + (png_uint_16)(*(sp + 7)));\n\n                     if (a == 0)\n                     {\n                        *sp = (png_byte)((png_ptr->background.red >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(png_ptr->background.red & 0xff);\n                        *(sp + 2) = (png_byte)((png_ptr->background.green >> 8)\n                                & 0xff);\n                        *(sp + 3) = (png_byte)(png_ptr->background.green\n                                & 0xff);\n                        *(sp + 4) = (png_byte)((png_ptr->background.blue >> 8)\n                                & 0xff);\n                        *(sp + 5) = (png_byte)(png_ptr->background.blue & 0xff);\n                     }\n\n                     else if (a < 0xffff)\n                     {\n                        png_uint_16 v;\n\n                        png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));\n                        png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)\n                            + *(sp + 3));\n                        png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)\n                            + *(sp + 5));\n\n                        png_composite_16(v, r, a, png_ptr->background.red);\n                        *sp = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 1) = (png_byte)(v & 0xff);\n\n                        png_composite_16(v, g, a, png_ptr->background.green);\n                        *(sp + 2) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 3) = (png_byte)(v & 0xff);\n\n                        png_composite_16(v, b, a, png_ptr->background.blue);\n                        *(sp + 4) = (png_byte)((v >> 8) & 0xff);\n                        *(sp + 5) = (png_byte)(v & 0xff);\n                     }\n                  }\n               }\n            }\n            break;\n         }\n\n         default:\n            break;\n      }\n   }\n}\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE */\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n/* Gamma correct the image, avoiding the alpha channel.  Make sure\n * you do this after you deal with the transparency issue on grayscale\n * or RGB images. If your bit depth is 8, use gamma_table, if it\n * is 16, use gamma_16_table and gamma_shift.  Build these with\n * build_gamma_table().\n */\nstatic void\npng_do_gamma(png_row_infop row_info, png_bytep row, png_structrp png_ptr)\n{\n   png_const_bytep gamma_table = png_ptr->gamma_table;\n   png_const_uint_16pp gamma_16_table = png_ptr->gamma_16_table;\n   int gamma_shift = png_ptr->gamma_shift;\n\n   png_bytep sp;\n   png_uint_32 i;\n   png_uint_32 row_width=row_info->width;\n\n   png_debug(1, \"in png_do_gamma\");\n\n   if (((row_info->bit_depth <= 8 && gamma_table != NULL) ||\n       (row_info->bit_depth == 16 && gamma_16_table != NULL)))\n   {\n      switch (row_info->color_type)\n      {\n         case PNG_COLOR_TYPE_RGB:\n         {\n            if (row_info->bit_depth == 8)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  *sp = gamma_table[*sp];\n                  sp++;\n                  *sp = gamma_table[*sp];\n                  sp++;\n                  *sp = gamma_table[*sp];\n                  sp++;\n               }\n            }\n\n            else /* if (row_info->bit_depth == 16) */\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  png_uint_16 v;\n\n                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n\n                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n\n                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n               }\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_RGB_ALPHA:\n         {\n            if (row_info->bit_depth == 8)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  *sp = gamma_table[*sp];\n                  sp++;\n\n                  *sp = gamma_table[*sp];\n                  sp++;\n\n                  *sp = gamma_table[*sp];\n                  sp++;\n\n                  sp++;\n               }\n            }\n\n            else /* if (row_info->bit_depth == 16) */\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n\n                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n\n                  v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 4;\n               }\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_GRAY_ALPHA:\n         {\n            if (row_info->bit_depth == 8)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  *sp = gamma_table[*sp];\n                  sp += 2;\n               }\n            }\n\n            else /* if (row_info->bit_depth == 16) */\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 4;\n               }\n            }\n            break;\n         }\n\n         case PNG_COLOR_TYPE_GRAY:\n         {\n            if (row_info->bit_depth == 2)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i += 4)\n               {\n                  int a = *sp & 0xc0;\n                  int b = *sp & 0x30;\n                  int c = *sp & 0x0c;\n                  int d = *sp & 0x03;\n\n                  *sp = (png_byte)(\n                      ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)])   ) & 0xc0)|\n                      ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|\n                      ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|\n                      ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));\n                  sp++;\n               }\n            }\n\n            if (row_info->bit_depth == 4)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i += 2)\n               {\n                  int msb = *sp & 0xf0;\n                  int lsb = *sp & 0x0f;\n\n                  *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)\n                      | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));\n                  sp++;\n               }\n            }\n\n            else if (row_info->bit_depth == 8)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  *sp = gamma_table[*sp];\n                  sp++;\n               }\n            }\n\n            else if (row_info->bit_depth == 16)\n            {\n               sp = row;\n               for (i = 0; i < row_width; i++)\n               {\n                  png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];\n                  *sp = (png_byte)((v >> 8) & 0xff);\n                  *(sp + 1) = (png_byte)(v & 0xff);\n                  sp += 2;\n               }\n            }\n            break;\n         }\n\n         default:\n            break;\n      }\n   }\n}\n#endif\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n/* Encode the alpha channel to the output gamma (the input channel is always\n * linear.)  Called only with color types that have an alpha channel.  Needs the\n * from_1 tables.\n */\nstatic void\npng_do_encode_alpha(png_row_infop row_info, png_bytep row, png_structrp png_ptr)\n{\n   png_uint_32 row_width = row_info->width;\n\n   png_debug(1, \"in png_do_encode_alpha\");\n\n   if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         PNG_CONST png_bytep table = png_ptr->gamma_from_1;\n\n         if (table != NULL)\n         {\n            PNG_CONST int step =\n               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 4 : 2;\n\n            /* The alpha channel is the last component: */\n            row += step - 1;\n\n            for (; row_width > 0; --row_width, row += step)\n               *row = table[*row];\n\n            return;\n         }\n      }\n\n      else if (row_info->bit_depth == 16)\n      {\n         PNG_CONST png_uint_16pp table = png_ptr->gamma_16_from_1;\n         PNG_CONST int gamma_shift = png_ptr->gamma_shift;\n\n         if (table != NULL)\n         {\n            PNG_CONST int step =\n               (row_info->color_type & PNG_COLOR_MASK_COLOR) ? 8 : 4;\n\n            /* The alpha channel is the last component: */\n            row += step - 2;\n\n            for (; row_width > 0; --row_width, row += step)\n            {\n               png_uint_16 v;\n\n               v = table[*(row + 1) >> gamma_shift][*row];\n               *row = (png_byte)((v >> 8) & 0xff);\n               *(row + 1) = (png_byte)(v & 0xff);\n            }\n\n            return;\n         }\n      }\n   }\n\n   /* Only get to here if called with a weird row_info; no harm has been done,\n    * so just issue a warning.\n    */\n   png_warning(png_ptr, \"png_do_encode_alpha: unexpected call\");\n}\n#endif\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n/* Expands a palette row to an RGB or RGBA row depending\n * upon whether you supply trans and num_trans.\n */\nstatic void\npng_do_expand_palette(png_row_infop row_info, png_bytep row,\n    png_const_colorp palette, png_const_bytep trans_alpha, int num_trans)\n{\n   int shift, value;\n   png_bytep sp, dp;\n   png_uint_32 i;\n   png_uint_32 row_width=row_info->width;\n\n   png_debug(1, \"in png_do_expand_palette\");\n\n   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      if (row_info->bit_depth < 8)\n      {\n         switch (row_info->bit_depth)\n         {\n            case 1:\n            {\n               sp = row + (png_size_t)((row_width - 1) >> 3);\n               dp = row + (png_size_t)row_width - 1;\n               shift = 7 - (int)((row_width + 7) & 0x07);\n               for (i = 0; i < row_width; i++)\n               {\n                  if ((*sp >> shift) & 0x01)\n                     *dp = 1;\n\n                  else\n                     *dp = 0;\n\n                  if (shift == 7)\n                  {\n                     shift = 0;\n                     sp--;\n                  }\n\n                  else\n                     shift++;\n\n                  dp--;\n               }\n               break;\n            }\n\n            case 2:\n            {\n               sp = row + (png_size_t)((row_width - 1) >> 2);\n               dp = row + (png_size_t)row_width - 1;\n               shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);\n               for (i = 0; i < row_width; i++)\n               {\n                  value = (*sp >> shift) & 0x03;\n                  *dp = (png_byte)value;\n                  if (shift == 6)\n                  {\n                     shift = 0;\n                     sp--;\n                  }\n\n                  else\n                     shift += 2;\n\n                  dp--;\n               }\n               break;\n            }\n\n            case 4:\n            {\n               sp = row + (png_size_t)((row_width - 1) >> 1);\n               dp = row + (png_size_t)row_width - 1;\n               shift = (int)((row_width & 0x01) << 2);\n               for (i = 0; i < row_width; i++)\n               {\n                  value = (*sp >> shift) & 0x0f;\n                  *dp = (png_byte)value;\n                  if (shift == 4)\n                  {\n                     shift = 0;\n                     sp--;\n                  }\n\n                  else\n                     shift += 4;\n\n                  dp--;\n               }\n               break;\n            }\n\n            default:\n               break;\n         }\n         row_info->bit_depth = 8;\n         row_info->pixel_depth = 8;\n         row_info->rowbytes = row_width;\n      }\n\n      if (row_info->bit_depth == 8)\n      {\n         {\n            if (num_trans > 0)\n            {\n               sp = row + (png_size_t)row_width - 1;\n               dp = row + (png_size_t)(row_width << 2) - 1;\n\n               for (i = 0; i < row_width; i++)\n               {\n                  if ((int)(*sp) >= num_trans)\n                     *dp-- = 0xff;\n\n                  else\n                     *dp-- = trans_alpha[*sp];\n\n                  *dp-- = palette[*sp].blue;\n                  *dp-- = palette[*sp].green;\n                  *dp-- = palette[*sp].red;\n                  sp--;\n               }\n               row_info->bit_depth = 8;\n               row_info->pixel_depth = 32;\n               row_info->rowbytes = row_width * 4;\n               row_info->color_type = 6;\n               row_info->channels = 4;\n            }\n\n            else\n            {\n               sp = row + (png_size_t)row_width - 1;\n               dp = row + (png_size_t)(row_width * 3) - 1;\n\n               for (i = 0; i < row_width; i++)\n               {\n                  *dp-- = palette[*sp].blue;\n                  *dp-- = palette[*sp].green;\n                  *dp-- = palette[*sp].red;\n                  sp--;\n               }\n\n               row_info->bit_depth = 8;\n               row_info->pixel_depth = 24;\n               row_info->rowbytes = row_width * 3;\n               row_info->color_type = 2;\n               row_info->channels = 3;\n            }\n         }\n      }\n   }\n}\n\n/* If the bit depth < 8, it is expanded to 8.  Also, if the already\n * expanded transparency value is supplied, an alpha channel is built.\n */\nstatic void\npng_do_expand(png_row_infop row_info, png_bytep row,\n    png_const_color_16p trans_color)\n{\n   int shift, value;\n   png_bytep sp, dp;\n   png_uint_32 i;\n   png_uint_32 row_width=row_info->width;\n\n   png_debug(1, \"in png_do_expand\");\n\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_GRAY)\n      {\n         unsigned int gray = trans_color != NULL ? trans_color->gray : 0;\n\n         if (row_info->bit_depth < 8)\n         {\n            switch (row_info->bit_depth)\n            {\n               case 1:\n               {\n                  gray = (gray & 0x01) * 0xff;\n                  sp = row + (png_size_t)((row_width - 1) >> 3);\n                  dp = row + (png_size_t)row_width - 1;\n                  shift = 7 - (int)((row_width + 7) & 0x07);\n                  for (i = 0; i < row_width; i++)\n                  {\n                     if ((*sp >> shift) & 0x01)\n                        *dp = 0xff;\n\n                     else\n                        *dp = 0;\n\n                     if (shift == 7)\n                     {\n                        shift = 0;\n                        sp--;\n                     }\n\n                     else\n                        shift++;\n\n                     dp--;\n                  }\n                  break;\n               }\n\n               case 2:\n               {\n                  gray = (gray & 0x03) * 0x55;\n                  sp = row + (png_size_t)((row_width - 1) >> 2);\n                  dp = row + (png_size_t)row_width - 1;\n                  shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);\n                  for (i = 0; i < row_width; i++)\n                  {\n                     value = (*sp >> shift) & 0x03;\n                     *dp = (png_byte)(value | (value << 2) | (value << 4) |\n                        (value << 6));\n                     if (shift == 6)\n                     {\n                        shift = 0;\n                        sp--;\n                     }\n\n                     else\n                        shift += 2;\n\n                     dp--;\n                  }\n                  break;\n               }\n\n               case 4:\n               {\n                  gray = (gray & 0x0f) * 0x11;\n                  sp = row + (png_size_t)((row_width - 1) >> 1);\n                  dp = row + (png_size_t)row_width - 1;\n                  shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);\n                  for (i = 0; i < row_width; i++)\n                  {\n                     value = (*sp >> shift) & 0x0f;\n                     *dp = (png_byte)(value | (value << 4));\n                     if (shift == 4)\n                     {\n                        shift = 0;\n                        sp--;\n                     }\n\n                     else\n                        shift = 4;\n\n                     dp--;\n                  }\n                  break;\n               }\n\n               default:\n                  break;\n            }\n\n            row_info->bit_depth = 8;\n            row_info->pixel_depth = 8;\n            row_info->rowbytes = row_width;\n         }\n\n         if (trans_color != NULL)\n         {\n            if (row_info->bit_depth == 8)\n            {\n               gray = gray & 0xff;\n               sp = row + (png_size_t)row_width - 1;\n               dp = row + (png_size_t)(row_width << 1) - 1;\n\n               for (i = 0; i < row_width; i++)\n               {\n                  if ((*sp & 0xffU) == gray)\n                     *dp-- = 0;\n\n                  else\n                     *dp-- = 0xff;\n\n                  *dp-- = *sp--;\n               }\n            }\n\n            else if (row_info->bit_depth == 16)\n            {\n               unsigned int gray_high = (gray >> 8) & 0xff;\n               unsigned int gray_low = gray & 0xff;\n               sp = row + row_info->rowbytes - 1;\n               dp = row + (row_info->rowbytes << 1) - 1;\n               for (i = 0; i < row_width; i++)\n               {\n                  if ((*(sp - 1) & 0xffU) == gray_high &&\n                      (*(sp) & 0xffU) == gray_low)\n                  {\n                     *dp-- = 0;\n                     *dp-- = 0;\n                  }\n\n                  else\n                  {\n                     *dp-- = 0xff;\n                     *dp-- = 0xff;\n                  }\n\n                  *dp-- = *sp--;\n                  *dp-- = *sp--;\n               }\n            }\n\n            row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;\n            row_info->channels = 2;\n            row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);\n            row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,\n                row_width);\n         }\n      }\n      else if (row_info->color_type == PNG_COLOR_TYPE_RGB &&\n          trans_color != NULL)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            png_byte red = (png_byte)(trans_color->red & 0xff);\n            png_byte green = (png_byte)(trans_color->green & 0xff);\n            png_byte blue = (png_byte)(trans_color->blue & 0xff);\n            sp = row + (png_size_t)row_info->rowbytes - 1;\n            dp = row + (png_size_t)(row_width << 2) - 1;\n            for (i = 0; i < row_width; i++)\n            {\n               if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)\n                  *dp-- = 0;\n\n               else\n                  *dp-- = 0xff;\n\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n            }\n         }\n         else if (row_info->bit_depth == 16)\n         {\n            png_byte red_high = (png_byte)((trans_color->red >> 8) & 0xff);\n            png_byte green_high = (png_byte)((trans_color->green >> 8) & 0xff);\n            png_byte blue_high = (png_byte)((trans_color->blue >> 8) & 0xff);\n            png_byte red_low = (png_byte)(trans_color->red & 0xff);\n            png_byte green_low = (png_byte)(trans_color->green & 0xff);\n            png_byte blue_low = (png_byte)(trans_color->blue & 0xff);\n            sp = row + row_info->rowbytes - 1;\n            dp = row + (png_size_t)(row_width << 3) - 1;\n            for (i = 0; i < row_width; i++)\n            {\n               if (*(sp - 5) == red_high &&\n                   *(sp - 4) == red_low &&\n                   *(sp - 3) == green_high &&\n                   *(sp - 2) == green_low &&\n                   *(sp - 1) == blue_high &&\n                   *(sp    ) == blue_low)\n               {\n                  *dp-- = 0;\n                  *dp-- = 0;\n               }\n\n               else\n               {\n                  *dp-- = 0xff;\n                  *dp-- = 0xff;\n               }\n\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n               *dp-- = *sp--;\n            }\n         }\n         row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;\n         row_info->channels = 4;\n         row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);\n         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);\n      }\n   }\n}\n#endif\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n/* If the bit depth is 8 and the color type is not a palette type expand the\n * whole row to 16 bits.  Has no effect otherwise.\n */\nstatic void\npng_do_expand_16(png_row_infop row_info, png_bytep row)\n{\n   if (row_info->bit_depth == 8 &&\n      row_info->color_type != PNG_COLOR_TYPE_PALETTE)\n   {\n      /* The row have a sequence of bytes containing [0..255] and we need\n       * to turn it into another row containing [0..65535], to do this we\n       * calculate:\n       *\n       *  (input / 255) * 65535\n       *\n       *  Which happens to be exactly input * 257 and this can be achieved\n       *  simply by byte replication in place (copying backwards).\n       */\n      png_byte *sp = row + row_info->rowbytes; /* source, last byte + 1 */\n      png_byte *dp = sp + row_info->rowbytes;  /* destination, end + 1 */\n      while (dp > sp)\n         dp[-2] = dp[-1] = *--sp, dp -= 2;\n\n      row_info->rowbytes *= 2;\n      row_info->bit_depth = 16;\n      row_info->pixel_depth = (png_byte)(row_info->channels * 16);\n   }\n}\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\nstatic void\npng_do_quantize(png_row_infop row_info, png_bytep row,\n    png_const_bytep palette_lookup, png_const_bytep quantize_lookup)\n{\n   png_bytep sp, dp;\n   png_uint_32 i;\n   png_uint_32 row_width=row_info->width;\n\n   png_debug(1, \"in png_do_quantize\");\n\n   if (row_info->bit_depth == 8)\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_RGB && palette_lookup)\n      {\n         int r, g, b, p;\n         sp = row;\n         dp = row;\n         for (i = 0; i < row_width; i++)\n         {\n            r = *sp++;\n            g = *sp++;\n            b = *sp++;\n\n            /* This looks real messy, but the compiler will reduce\n             * it down to a reasonable formula.  For example, with\n             * 5 bits per color, we get:\n             * p = (((r >> 3) & 0x1f) << 10) |\n             *    (((g >> 3) & 0x1f) << 5) |\n             *    ((b >> 3) & 0x1f);\n             */\n            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &\n                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<\n                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |\n                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &\n                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<\n                (PNG_QUANTIZE_BLUE_BITS)) |\n                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &\n                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));\n\n            *dp++ = palette_lookup[p];\n         }\n\n         row_info->color_type = PNG_COLOR_TYPE_PALETTE;\n         row_info->channels = 1;\n         row_info->pixel_depth = row_info->bit_depth;\n         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&\n         palette_lookup != NULL)\n      {\n         int r, g, b, p;\n         sp = row;\n         dp = row;\n         for (i = 0; i < row_width; i++)\n         {\n            r = *sp++;\n            g = *sp++;\n            b = *sp++;\n            sp++;\n\n            p = (((r >> (8 - PNG_QUANTIZE_RED_BITS)) &\n                ((1 << PNG_QUANTIZE_RED_BITS) - 1)) <<\n                (PNG_QUANTIZE_GREEN_BITS + PNG_QUANTIZE_BLUE_BITS)) |\n                (((g >> (8 - PNG_QUANTIZE_GREEN_BITS)) &\n                ((1 << PNG_QUANTIZE_GREEN_BITS) - 1)) <<\n                (PNG_QUANTIZE_BLUE_BITS)) |\n                ((b >> (8 - PNG_QUANTIZE_BLUE_BITS)) &\n                ((1 << PNG_QUANTIZE_BLUE_BITS) - 1));\n\n            *dp++ = palette_lookup[p];\n         }\n\n         row_info->color_type = PNG_COLOR_TYPE_PALETTE;\n         row_info->channels = 1;\n         row_info->pixel_depth = row_info->bit_depth;\n         row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_width);\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&\n         quantize_lookup)\n      {\n         sp = row;\n\n         for (i = 0; i < row_width; i++, sp++)\n         {\n            *sp = quantize_lookup[*sp];\n         }\n      }\n   }\n}\n#endif /* READ_QUANTIZE */\n\n/* Transform the row.  The order of transformations is significant,\n * and is very touchy.  If you add a transformation, take care to\n * decide how it fits in with the other transformations here.\n */\nvoid /* PRIVATE */\npng_do_read_transformations(png_structrp png_ptr, png_row_infop row_info)\n{\n   png_debug(1, \"in png_do_read_transformations\");\n\n   if (png_ptr->row_buf == NULL)\n   {\n      /* Prior to 1.5.4 this output row/pass where the NULL pointer is, but this\n       * error is incredibly rare and incredibly easy to debug without this\n       * information.\n       */\n      png_error(png_ptr, \"NULL row buffer\");\n   }\n\n   /* The following is debugging; prior to 1.5.4 the code was never compiled in;\n    * in 1.5.4 PNG_FLAG_DETECT_UNINITIALIZED was added and the macro\n    * PNG_WARN_UNINITIALIZED_ROW removed.  In 1.6 the new flag is set only for\n    * all transformations, however in practice the ROW_INIT always gets done on\n    * demand, if necessary.\n    */\n   if ((png_ptr->flags & PNG_FLAG_DETECT_UNINITIALIZED) != 0 &&\n       (png_ptr->flags & PNG_FLAG_ROW_INIT) == 0)\n   {\n      /* Application has failed to call either png_read_start_image() or\n       * png_read_update_info() after setting transforms that expand pixels.\n       * This check added to libpng-1.2.19 (but not enabled until 1.5.4).\n       */\n      png_error(png_ptr, \"Uninitialized row\");\n   }\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n   if ((png_ptr->transformations & PNG_EXPAND) != 0)\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         png_do_expand_palette(row_info, png_ptr->row_buf + 1,\n             png_ptr->palette, png_ptr->trans_alpha, png_ptr->num_trans);\n      }\n\n      else\n      {\n         if (png_ptr->num_trans != 0 &&\n             (png_ptr->transformations & PNG_EXPAND_tRNS) != 0)\n            png_do_expand(row_info, png_ptr->row_buf + 1,\n                &(png_ptr->trans_color));\n\n         else\n            png_do_expand(row_info, png_ptr->row_buf + 1,\n                NULL);\n      }\n   }\n#endif\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&\n       (png_ptr->transformations & PNG_COMPOSE) == 0 &&\n       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))\n      png_do_strip_channel(row_info, png_ptr->row_buf + 1,\n          0 /* at_start == false, because SWAP_ALPHA happens later */);\n#endif\n\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n   if ((png_ptr->transformations & PNG_RGB_TO_GRAY) != 0)\n   {\n      int rgb_error =\n          png_do_rgb_to_gray(png_ptr, row_info,\n              png_ptr->row_buf + 1);\n\n      if (rgb_error != 0)\n      {\n         png_ptr->rgb_to_gray_status=1;\n         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==\n             PNG_RGB_TO_GRAY_WARN)\n            png_warning(png_ptr, \"png_do_rgb_to_gray found nongray pixel\");\n\n         if ((png_ptr->transformations & PNG_RGB_TO_GRAY) ==\n             PNG_RGB_TO_GRAY_ERR)\n            png_error(png_ptr, \"png_do_rgb_to_gray found nongray pixel\");\n      }\n   }\n#endif\n\n/* From Andreas Dilger e-mail to png-implement, 26 March 1998:\n *\n *   In most cases, the \"simple transparency\" should be done prior to doing\n *   gray-to-RGB, or you will have to test 3x as many bytes to check if a\n *   pixel is transparent.  You would also need to make sure that the\n *   transparency information is upgraded to RGB.\n *\n *   To summarize, the current flow is:\n *   - Gray + simple transparency -> compare 1 or 2 gray bytes and composite\n *                                   with background \"in place\" if transparent,\n *                                   convert to RGB if necessary\n *   - Gray + alpha -> composite with gray background and remove alpha bytes,\n *                                   convert to RGB if necessary\n *\n *   To support RGB backgrounds for gray images we need:\n *   - Gray + simple transparency -> convert to RGB + simple transparency,\n *                                   compare 3 or 6 bytes and composite with\n *                                   background \"in place\" if transparent\n *                                   (3x compare/pixel compared to doing\n *                                   composite with gray bkgrnd)\n *   - Gray + alpha -> convert to RGB + alpha, composite with background and\n *                                   remove alpha bytes (3x float\n *                                   operations/pixel compared with composite\n *                                   on gray background)\n *\n *  Greg's change will do this.  The reason it wasn't done before is for\n *  performance, as this increases the per-pixel operations.  If we would check\n *  in advance if the background was gray or RGB, and position the gray-to-RGB\n *  transform appropriately, then it would save a lot of work/time.\n */\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n   /* If gray -> RGB, do so now only if background is non-gray; else do later\n    * for performance reasons\n    */\n   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&\n       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) == 0)\n      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);\n#endif\n\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n   if ((png_ptr->transformations & PNG_COMPOSE) != 0)\n      png_do_compose(row_info, png_ptr->row_buf + 1, png_ptr);\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   if ((png_ptr->transformations & PNG_GAMMA) != 0 &&\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n      /* Because RGB_TO_GRAY does the gamma transform. */\n      (png_ptr->transformations & PNG_RGB_TO_GRAY) == 0 &&\n#endif\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n      /* Because PNG_COMPOSE does the gamma transform if there is something to\n       * do (if there is an alpha channel or transparency.)\n       */\n       !((png_ptr->transformations & PNG_COMPOSE) != 0 &&\n       ((png_ptr->num_trans != 0) ||\n       (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)) &&\n#endif\n      /* Because png_init_read_transformations transforms the palette, unless\n       * RGB_TO_GRAY will do the transform.\n       */\n       (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))\n      png_do_gamma(row_info, png_ptr->row_buf + 1, png_ptr);\n#endif\n\n#ifdef PNG_READ_STRIP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_STRIP_ALPHA) != 0 &&\n       (png_ptr->transformations & PNG_COMPOSE) != 0 &&\n       (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA ||\n       row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA))\n      png_do_strip_channel(row_info, png_ptr->row_buf + 1,\n          0 /* at_start == false, because SWAP_ALPHA happens later */);\n#endif\n\n#ifdef PNG_READ_ALPHA_MODE_SUPPORTED\n   if ((png_ptr->transformations & PNG_ENCODE_ALPHA) != 0 &&\n       (row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      png_do_encode_alpha(row_info, png_ptr->row_buf + 1, png_ptr);\n#endif\n\n#ifdef PNG_READ_SCALE_16_TO_8_SUPPORTED\n   if ((png_ptr->transformations & PNG_SCALE_16_TO_8) != 0)\n      png_do_scale_16_to_8(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_STRIP_16_TO_8_SUPPORTED\n   /* There is no harm in doing both of these because only one has any effect,\n    * by putting the 'scale' option first if the app asks for scale (either by\n    * calling the API or in a TRANSFORM flag) this is what happens.\n    */\n   if ((png_ptr->transformations & PNG_16_TO_8) != 0)\n      png_do_chop(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n   if ((png_ptr->transformations & PNG_QUANTIZE) != 0)\n   {\n      png_do_quantize(row_info, png_ptr->row_buf + 1,\n          png_ptr->palette_lookup, png_ptr->quantize_index);\n\n      if (row_info->rowbytes == 0)\n         png_error(png_ptr, \"png_do_quantize returned rowbytes=0\");\n   }\n#endif /* READ_QUANTIZE */\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n   /* Do the expansion now, after all the arithmetic has been done.  Notice\n    * that previous transformations can handle the PNG_EXPAND_16 flag if this\n    * is efficient (particularly true in the case of gamma correction, where\n    * better accuracy results faster!)\n    */\n   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)\n      png_do_expand_16(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n   /* NOTE: moved here in 1.5.4 (from much later in this list.) */\n   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0 &&\n       (png_ptr->mode & PNG_BACKGROUND_IS_GRAY) != 0)\n      png_do_gray_to_rgb(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_INVERT_SUPPORTED\n   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)\n      png_do_invert(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_INVERT_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)\n      png_do_read_invert_alpha(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_SHIFT_SUPPORTED\n   if ((png_ptr->transformations & PNG_SHIFT) != 0)\n      png_do_unshift(row_info, png_ptr->row_buf + 1,\n          &(png_ptr->shift));\n#endif\n\n#ifdef PNG_READ_PACK_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACK) != 0)\n      png_do_unpack(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   /* Added at libpng-1.5.10 */\n   if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&\n       png_ptr->num_palette_max >= 0)\n      png_do_check_palette_indexes(png_ptr, row_info);\n#endif\n\n#ifdef PNG_READ_BGR_SUPPORTED\n   if ((png_ptr->transformations & PNG_BGR) != 0)\n      png_do_bgr(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n      png_do_packswap(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_FILLER_SUPPORTED\n   if ((png_ptr->transformations & PNG_FILLER) != 0)\n      png_do_read_filler(row_info, png_ptr->row_buf + 1,\n          (png_uint_32)png_ptr->filler, png_ptr->flags);\n#endif\n\n#ifdef PNG_READ_SWAP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)\n      png_do_read_swap_alpha(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_READ_16BIT_SUPPORTED\n#ifdef PNG_READ_SWAP_SUPPORTED\n   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)\n      png_do_swap(row_info, png_ptr->row_buf + 1);\n#endif\n#endif\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)\n   {\n      if (png_ptr->read_user_transform_fn != NULL)\n         (*(png_ptr->read_user_transform_fn)) /* User read transform function */\n             (png_ptr,     /* png_ptr */\n             row_info,     /* row_info: */\n                /*  png_uint_32 width;       width of row */\n                /*  png_size_t rowbytes;     number of bytes in row */\n                /*  png_byte color_type;     color type of pixels */\n                /*  png_byte bit_depth;      bit depth of samples */\n                /*  png_byte channels;       number of channels (1-4) */\n                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */\n             png_ptr->row_buf + 1);    /* start of pixel data for row */\n#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED\n      if (png_ptr->user_transform_depth != 0)\n         row_info->bit_depth = png_ptr->user_transform_depth;\n\n      if (png_ptr->user_transform_channels != 0)\n         row_info->channels = png_ptr->user_transform_channels;\n#endif\n      row_info->pixel_depth = (png_byte)(row_info->bit_depth *\n          row_info->channels);\n\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, row_info->width);\n   }\n#endif\n}\n\n#endif /* READ_TRANSFORMS */\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngrutil.c",
    "content": "\n/* pngrutil.c - utilities to read a PNG file\n *\n * Last changed in libpng 1.6.25 [September 1, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file contains routines that are only called from within\n * libpng itself during the course of reading an image.\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_READ_SUPPORTED\n\npng_uint_32 PNGAPI\npng_get_uint_31(png_const_structrp png_ptr, png_const_bytep buf)\n{\n   png_uint_32 uval = png_get_uint_32(buf);\n\n   if (uval > PNG_UINT_31_MAX)\n      png_error(png_ptr, \"PNG unsigned integer out of range\");\n\n   return (uval);\n}\n\n#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_READ_cHRM_SUPPORTED)\n/* The following is a variation on the above for use with the fixed\n * point values used for gAMA and cHRM.  Instead of png_error it\n * issues a warning and returns (-1) - an invalid value because both\n * gAMA and cHRM use *unsigned* integers for fixed point values.\n */\n#define PNG_FIXED_ERROR (-1)\n\nstatic png_fixed_point /* PRIVATE */\npng_get_fixed_point(png_structrp png_ptr, png_const_bytep buf)\n{\n   png_uint_32 uval = png_get_uint_32(buf);\n\n   if (uval <= PNG_UINT_31_MAX)\n      return (png_fixed_point)uval; /* known to be in range */\n\n   /* The caller can turn off the warning by passing NULL. */\n   if (png_ptr != NULL)\n      png_warning(png_ptr, \"PNG fixed point integer out of range\");\n\n   return PNG_FIXED_ERROR;\n}\n#endif\n\n#ifdef PNG_READ_INT_FUNCTIONS_SUPPORTED\n/* NOTE: the read macros will obscure these definitions, so that if\n * PNG_USE_READ_MACROS is set the library will not use them internally,\n * but the APIs will still be available externally.\n *\n * The parentheses around \"PNGAPI function_name\" in the following three\n * functions are necessary because they allow the macros to co-exist with\n * these (unused but exported) functions.\n */\n\n/* Grab an unsigned 32-bit integer from a buffer in big-endian format. */\npng_uint_32 (PNGAPI\npng_get_uint_32)(png_const_bytep buf)\n{\n   png_uint_32 uval =\n       ((png_uint_32)(*(buf    )) << 24) +\n       ((png_uint_32)(*(buf + 1)) << 16) +\n       ((png_uint_32)(*(buf + 2)) <<  8) +\n       ((png_uint_32)(*(buf + 3))      ) ;\n\n   return uval;\n}\n\n/* Grab a signed 32-bit integer from a buffer in big-endian format.  The\n * data is stored in the PNG file in two's complement format and there\n * is no guarantee that a 'png_int_32' is exactly 32 bits, therefore\n * the following code does a two's complement to native conversion.\n */\npng_int_32 (PNGAPI\npng_get_int_32)(png_const_bytep buf)\n{\n   png_uint_32 uval = png_get_uint_32(buf);\n   if ((uval & 0x80000000) == 0) /* non-negative */\n      return uval;\n\n   uval = (uval ^ 0xffffffff) + 1;  /* 2's complement: -x = ~x+1 */\n   if ((uval & 0x80000000) == 0) /* no overflow */\n      return -(png_int_32)uval;\n   /* The following has to be safe; this function only gets called on PNG data\n    * and if we get here that data is invalid.  0 is the most safe value and\n    * if not then an attacker would surely just generate a PNG with 0 instead.\n    */\n   return 0;\n}\n\n/* Grab an unsigned 16-bit integer from a buffer in big-endian format. */\npng_uint_16 (PNGAPI\npng_get_uint_16)(png_const_bytep buf)\n{\n   /* ANSI-C requires an int value to accomodate at least 16 bits so this\n    * works and allows the compiler not to worry about possible narrowing\n    * on 32-bit systems.  (Pre-ANSI systems did not make integers smaller\n    * than 16 bits either.)\n    */\n   unsigned int val =\n       ((unsigned int)(*buf) << 8) +\n       ((unsigned int)(*(buf + 1)));\n\n   return (png_uint_16)val;\n}\n\n#endif /* READ_INT_FUNCTIONS */\n\n/* Read and check the PNG file signature */\nvoid /* PRIVATE */\npng_read_sig(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_size_t num_checked, num_to_check;\n\n   /* Exit if the user application does not expect a signature. */\n   if (png_ptr->sig_bytes >= 8)\n      return;\n\n   num_checked = png_ptr->sig_bytes;\n   num_to_check = 8 - num_checked;\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   png_ptr->io_state = PNG_IO_READING | PNG_IO_SIGNATURE;\n#endif\n\n   /* The signature must be serialized in a single I/O call. */\n   png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);\n   png_ptr->sig_bytes = 8;\n\n   if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check) != 0)\n   {\n      if (num_checked < 4 &&\n          png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))\n         png_error(png_ptr, \"Not a PNG file\");\n      else\n         png_error(png_ptr, \"PNG file corrupted by ASCII conversion\");\n   }\n   if (num_checked < 3)\n      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;\n}\n\n/* Read the chunk header (length + type name).\n * Put the type name into png_ptr->chunk_name, and return the length.\n */\npng_uint_32 /* PRIVATE */\npng_read_chunk_header(png_structrp png_ptr)\n{\n   png_byte buf[8];\n   png_uint_32 length;\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_HDR;\n#endif\n\n   /* Read the length and the chunk name.\n    * This must be performed in a single I/O call.\n    */\n   png_read_data(png_ptr, buf, 8);\n   length = png_get_uint_31(png_ptr, buf);\n\n   /* Put the chunk name into png_ptr->chunk_name. */\n   png_ptr->chunk_name = PNG_CHUNK_FROM_STRING(buf+4);\n\n   png_debug2(0, \"Reading %lx chunk, length = %lu\",\n       (unsigned long)png_ptr->chunk_name, (unsigned long)length);\n\n   /* Reset the crc and run it over the chunk name. */\n   png_reset_crc(png_ptr);\n   png_calculate_crc(png_ptr, buf + 4, 4);\n\n   /* Check to see if chunk name is valid. */\n   png_check_chunk_name(png_ptr, png_ptr->chunk_name);\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_DATA;\n#endif\n\n   return length;\n}\n\n/* Read data, and (optionally) run it through the CRC. */\nvoid /* PRIVATE */\npng_crc_read(png_structrp png_ptr, png_bytep buf, png_uint_32 length)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_read_data(png_ptr, buf, length);\n   png_calculate_crc(png_ptr, buf, length);\n}\n\n/* Optionally skip data and then check the CRC.  Depending on whether we\n * are reading an ancillary or critical chunk, and how the program has set\n * things up, we may calculate the CRC on the data and print a message.\n * Returns '1' if there was a CRC error, '0' otherwise.\n */\nint /* PRIVATE */\npng_crc_finish(png_structrp png_ptr, png_uint_32 skip)\n{\n   /* The size of the local buffer for inflate is a good guess as to a\n    * reasonable size to use for buffering reads from the application.\n    */\n   while (skip > 0)\n   {\n      png_uint_32 len;\n      png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];\n\n      len = (sizeof tmpbuf);\n      if (len > skip)\n         len = skip;\n      skip -= len;\n\n      png_crc_read(png_ptr, tmpbuf, len);\n   }\n\n   if (png_crc_error(png_ptr) != 0)\n   {\n      if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0 ?\n          (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0 :\n          (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE) != 0)\n      {\n         png_chunk_warning(png_ptr, \"CRC error\");\n      }\n\n      else\n         png_chunk_error(png_ptr, \"CRC error\");\n\n      return (1);\n   }\n\n   return (0);\n}\n\n/* Compare the CRC stored in the PNG file with that calculated by libpng from\n * the data it has read thus far.\n */\nint /* PRIVATE */\npng_crc_error(png_structrp png_ptr)\n{\n   png_byte crc_bytes[4];\n   png_uint_32 crc;\n   int need_crc = 1;\n\n   if (PNG_CHUNK_ANCILLARY(png_ptr->chunk_name) != 0)\n   {\n      if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==\n          (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))\n         need_crc = 0;\n   }\n\n   else /* critical */\n   {\n      if ((png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE) != 0)\n         need_crc = 0;\n   }\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   png_ptr->io_state = PNG_IO_READING | PNG_IO_CHUNK_CRC;\n#endif\n\n   /* The chunk CRC must be serialized in a single I/O call. */\n   png_read_data(png_ptr, crc_bytes, 4);\n\n   if (need_crc != 0)\n   {\n      crc = png_get_uint_32(crc_bytes);\n      return ((int)(crc != png_ptr->crc));\n   }\n\n   else\n      return (0);\n}\n\n#if defined(PNG_READ_iCCP_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) ||\\\n    defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_READ_sCAL_SUPPORTED) ||\\\n    defined(PNG_READ_sPLT_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) ||\\\n    defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_SEQUENTIAL_READ_SUPPORTED)\n/* Manage the read buffer; this simply reallocates the buffer if it is not small\n * enough (or if it is not allocated).  The routine returns a pointer to the\n * buffer; if an error occurs and 'warn' is set the routine returns NULL, else\n * it will call png_error (via png_malloc) on failure.  (warn == 2 means\n * 'silent').\n */\nstatic png_bytep\npng_read_buffer(png_structrp png_ptr, png_alloc_size_t new_size, int warn)\n{\n   png_bytep buffer = png_ptr->read_buffer;\n\n   if (buffer != NULL && new_size > png_ptr->read_buffer_size)\n   {\n      png_ptr->read_buffer = NULL;\n      png_ptr->read_buffer = NULL;\n      png_ptr->read_buffer_size = 0;\n      png_free(png_ptr, buffer);\n      buffer = NULL;\n   }\n\n   if (buffer == NULL)\n   {\n      buffer = png_voidcast(png_bytep, png_malloc_base(png_ptr, new_size));\n\n      if (buffer != NULL)\n      {\n         png_ptr->read_buffer = buffer;\n         png_ptr->read_buffer_size = new_size;\n      }\n\n      else if (warn < 2) /* else silent */\n      {\n         if (warn != 0)\n             png_chunk_warning(png_ptr, \"insufficient memory to read chunk\");\n\n         else\n             png_chunk_error(png_ptr, \"insufficient memory to read chunk\");\n      }\n   }\n\n   return buffer;\n}\n#endif /* READ_iCCP|iTXt|pCAL|sCAL|sPLT|tEXt|zTXt|SEQUENTIAL_READ */\n\n/* png_inflate_claim: claim the zstream for some nefarious purpose that involves\n * decompression.  Returns Z_OK on success, else a zlib error code.  It checks\n * the owner but, in final release builds, just issues a warning if some other\n * chunk apparently owns the stream.  Prior to release it does a png_error.\n */\nstatic int\npng_inflate_claim(png_structrp png_ptr, png_uint_32 owner)\n{\n   if (png_ptr->zowner != 0)\n   {\n      char msg[64];\n\n      PNG_STRING_FROM_CHUNK(msg, png_ptr->zowner);\n      /* So the message that results is \"<chunk> using zstream\"; this is an\n       * internal error, but is very useful for debugging.  i18n requirements\n       * are minimal.\n       */\n      (void)png_safecat(msg, (sizeof msg), 4, \" using zstream\");\n#if PNG_RELEASE_BUILD\n      png_chunk_warning(png_ptr, msg);\n      png_ptr->zowner = 0;\n#else\n      png_chunk_error(png_ptr, msg);\n#endif\n   }\n\n   /* Implementation note: unlike 'png_deflate_claim' this internal function\n    * does not take the size of the data as an argument.  Some efficiency could\n    * be gained by using this when it is known *if* the zlib stream itself does\n    * not record the number; however, this is an illusion: the original writer\n    * of the PNG may have selected a lower window size, and we really must\n    * follow that because, for systems with with limited capabilities, we\n    * would otherwise reject the application's attempts to use a smaller window\n    * size (zlib doesn't have an interface to say \"this or lower\"!).\n    *\n    * inflateReset2 was added to zlib 1.2.4; before this the window could not be\n    * reset, therefore it is necessary to always allocate the maximum window\n    * size with earlier zlibs just in case later compressed chunks need it.\n    */\n   {\n      int ret; /* zlib return code */\n#if PNG_ZLIB_VERNUM >= 0x1240\n\n# if defined(PNG_SET_OPTION_SUPPORTED) && defined(PNG_MAXIMUM_INFLATE_WINDOW)\n      int window_bits;\n\n      if (((png_ptr->options >> PNG_MAXIMUM_INFLATE_WINDOW) & 3) ==\n          PNG_OPTION_ON)\n      {\n         window_bits = 15;\n         png_ptr->zstream_start = 0; /* fixed window size */\n      }\n\n      else\n      {\n         window_bits = 0;\n         png_ptr->zstream_start = 1;\n      }\n# else\n#   define window_bits 0\n# endif\n#endif\n\n      /* Set this for safety, just in case the previous owner left pointers to\n       * memory allocations.\n       */\n      png_ptr->zstream.next_in = NULL;\n      png_ptr->zstream.avail_in = 0;\n      png_ptr->zstream.next_out = NULL;\n      png_ptr->zstream.avail_out = 0;\n\n      if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)\n      {\n#if PNG_ZLIB_VERNUM < 0x1240\n         ret = inflateReset(&png_ptr->zstream);\n#else\n         ret = inflateReset2(&png_ptr->zstream, window_bits);\n#endif\n      }\n\n      else\n      {\n#if PNG_ZLIB_VERNUM < 0x1240\n         ret = inflateInit(&png_ptr->zstream);\n#else\n         ret = inflateInit2(&png_ptr->zstream, window_bits);\n#endif\n\n         if (ret == Z_OK)\n            png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;\n      }\n\n      if (ret == Z_OK)\n         png_ptr->zowner = owner;\n\n      else\n         png_zstream_error(png_ptr, ret);\n\n      return ret;\n   }\n\n#ifdef window_bits\n# undef window_bits\n#endif\n}\n\n#if PNG_ZLIB_VERNUM >= 0x1240\n/* Handle the start of the inflate stream if we called inflateInit2(strm,0);\n * in this case some zlib versions skip validation of the CINFO field and, in\n * certain circumstances, libpng may end up displaying an invalid image, in\n * contrast to implementations that call zlib in the normal way (e.g. libpng\n * 1.5).\n */\nint /* PRIVATE */\npng_zlib_inflate(png_structrp png_ptr, int flush)\n{\n   if (png_ptr->zstream_start && png_ptr->zstream.avail_in > 0)\n   {\n      if ((*png_ptr->zstream.next_in >> 4) > 7)\n      {\n         png_ptr->zstream.msg = \"invalid window size (libpng)\";\n         return Z_DATA_ERROR;\n      }\n\n      png_ptr->zstream_start = 0;\n   }\n\n   return inflate(&png_ptr->zstream, flush);\n}\n#endif /* Zlib >= 1.2.4 */\n\n#ifdef PNG_READ_COMPRESSED_TEXT_SUPPORTED\n#if defined(PNG_READ_zTXt_SUPPORTED) || defined (PNG_READ_iTXt_SUPPORTED)\n/* png_inflate now returns zlib error codes including Z_OK and Z_STREAM_END to\n * allow the caller to do multiple calls if required.  If the 'finish' flag is\n * set Z_FINISH will be passed to the final inflate() call and Z_STREAM_END must\n * be returned or there has been a problem, otherwise Z_SYNC_FLUSH is used and\n * Z_OK or Z_STREAM_END will be returned on success.\n *\n * The input and output sizes are updated to the actual amounts of data consumed\n * or written, not the amount available (as in a z_stream).  The data pointers\n * are not changed, so the next input is (data+input_size) and the next\n * available output is (output+output_size).\n */\nstatic int\npng_inflate(png_structrp png_ptr, png_uint_32 owner, int finish,\n    /* INPUT: */ png_const_bytep input, png_uint_32p input_size_ptr,\n    /* OUTPUT: */ png_bytep output, png_alloc_size_t *output_size_ptr)\n{\n   if (png_ptr->zowner == owner) /* Else not claimed */\n   {\n      int ret;\n      png_alloc_size_t avail_out = *output_size_ptr;\n      png_uint_32 avail_in = *input_size_ptr;\n\n      /* zlib can't necessarily handle more than 65535 bytes at once (i.e. it\n       * can't even necessarily handle 65536 bytes) because the type uInt is\n       * \"16 bits or more\".  Consequently it is necessary to chunk the input to\n       * zlib.  This code uses ZLIB_IO_MAX, from pngpriv.h, as the maximum (the\n       * maximum value that can be stored in a uInt.)  It is possible to set\n       * ZLIB_IO_MAX to a lower value in pngpriv.h and this may sometimes have\n       * a performance advantage, because it reduces the amount of data accessed\n       * at each step and that may give the OS more time to page it in.\n       */\n      png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input);\n      /* avail_in and avail_out are set below from 'size' */\n      png_ptr->zstream.avail_in = 0;\n      png_ptr->zstream.avail_out = 0;\n\n      /* Read directly into the output if it is available (this is set to\n       * a local buffer below if output is NULL).\n       */\n      if (output != NULL)\n         png_ptr->zstream.next_out = output;\n\n      do\n      {\n         uInt avail;\n         Byte local_buffer[PNG_INFLATE_BUF_SIZE];\n\n         /* zlib INPUT BUFFER */\n         /* The setting of 'avail_in' used to be outside the loop; by setting it\n          * inside it is possible to chunk the input to zlib and simply rely on\n          * zlib to advance the 'next_in' pointer.  This allows arbitrary\n          * amounts of data to be passed through zlib at the unavoidable cost of\n          * requiring a window save (memcpy of up to 32768 output bytes)\n          * every ZLIB_IO_MAX input bytes.\n          */\n         avail_in += png_ptr->zstream.avail_in; /* not consumed last time */\n\n         avail = ZLIB_IO_MAX;\n\n         if (avail_in < avail)\n            avail = (uInt)avail_in; /* safe: < than ZLIB_IO_MAX */\n\n         avail_in -= avail;\n         png_ptr->zstream.avail_in = avail;\n\n         /* zlib OUTPUT BUFFER */\n         avail_out += png_ptr->zstream.avail_out; /* not written last time */\n\n         avail = ZLIB_IO_MAX; /* maximum zlib can process */\n\n         if (output == NULL)\n         {\n            /* Reset the output buffer each time round if output is NULL and\n             * make available the full buffer, up to 'remaining_space'\n             */\n            png_ptr->zstream.next_out = local_buffer;\n            if ((sizeof local_buffer) < avail)\n               avail = (sizeof local_buffer);\n         }\n\n         if (avail_out < avail)\n            avail = (uInt)avail_out; /* safe: < ZLIB_IO_MAX */\n\n         png_ptr->zstream.avail_out = avail;\n         avail_out -= avail;\n\n         /* zlib inflate call */\n         /* In fact 'avail_out' may be 0 at this point, that happens at the end\n          * of the read when the final LZ end code was not passed at the end of\n          * the previous chunk of input data.  Tell zlib if we have reached the\n          * end of the output buffer.\n          */\n         ret = PNG_INFLATE(png_ptr, avail_out > 0 ? Z_NO_FLUSH :\n             (finish ? Z_FINISH : Z_SYNC_FLUSH));\n      } while (ret == Z_OK);\n\n      /* For safety kill the local buffer pointer now */\n      if (output == NULL)\n         png_ptr->zstream.next_out = NULL;\n\n      /* Claw back the 'size' and 'remaining_space' byte counts. */\n      avail_in += png_ptr->zstream.avail_in;\n      avail_out += png_ptr->zstream.avail_out;\n\n      /* Update the input and output sizes; the updated values are the amount\n       * consumed or written, effectively the inverse of what zlib uses.\n       */\n      if (avail_out > 0)\n         *output_size_ptr -= avail_out;\n\n      if (avail_in > 0)\n         *input_size_ptr -= avail_in;\n\n      /* Ensure png_ptr->zstream.msg is set (even in the success case!) */\n      png_zstream_error(png_ptr, ret);\n      return ret;\n   }\n\n   else\n   {\n      /* This is a bad internal error.  The recovery assigns to the zstream msg\n       * pointer, which is not owned by the caller, but this is safe; it's only\n       * used on errors!\n       */\n      png_ptr->zstream.msg = PNGZ_MSG_CAST(\"zstream unclaimed\");\n      return Z_STREAM_ERROR;\n   }\n}\n\n/*\n * Decompress trailing data in a chunk.  The assumption is that read_buffer\n * points at an allocated area holding the contents of a chunk with a\n * trailing compressed part.  What we get back is an allocated area\n * holding the original prefix part and an uncompressed version of the\n * trailing part (the malloc area passed in is freed).\n */\nstatic int\npng_decompress_chunk(png_structrp png_ptr,\n    png_uint_32 chunklength, png_uint_32 prefix_size,\n    png_alloc_size_t *newlength /* must be initialized to the maximum! */,\n    int terminate /*add a '\\0' to the end of the uncompressed data*/)\n{\n   /* TODO: implement different limits for different types of chunk.\n    *\n    * The caller supplies *newlength set to the maximum length of the\n    * uncompressed data, but this routine allocates space for the prefix and\n    * maybe a '\\0' terminator too.  We have to assume that 'prefix_size' is\n    * limited only by the maximum chunk size.\n    */\n   png_alloc_size_t limit = PNG_SIZE_MAX;\n\n# ifdef PNG_SET_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_malloc_max > 0 &&\n       png_ptr->user_chunk_malloc_max < limit)\n      limit = png_ptr->user_chunk_malloc_max;\n# elif PNG_USER_CHUNK_MALLOC_MAX > 0\n   if (PNG_USER_CHUNK_MALLOC_MAX < limit)\n      limit = PNG_USER_CHUNK_MALLOC_MAX;\n# endif\n\n   if (limit >= prefix_size + (terminate != 0))\n   {\n      int ret;\n\n      limit -= prefix_size + (terminate != 0);\n\n      if (limit < *newlength)\n         *newlength = limit;\n\n      /* Now try to claim the stream. */\n      ret = png_inflate_claim(png_ptr, png_ptr->chunk_name);\n\n      if (ret == Z_OK)\n      {\n         png_uint_32 lzsize = chunklength - prefix_size;\n\n         ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,\n             /* input: */ png_ptr->read_buffer + prefix_size, &lzsize,\n             /* output: */ NULL, newlength);\n\n         if (ret == Z_STREAM_END)\n         {\n            /* Use 'inflateReset' here, not 'inflateReset2' because this\n             * preserves the previously decided window size (otherwise it would\n             * be necessary to store the previous window size.)  In practice\n             * this doesn't matter anyway, because png_inflate will call inflate\n             * with Z_FINISH in almost all cases, so the window will not be\n             * maintained.\n             */\n            if (inflateReset(&png_ptr->zstream) == Z_OK)\n            {\n               /* Because of the limit checks above we know that the new,\n                * expanded, size will fit in a size_t (let alone an\n                * png_alloc_size_t).  Use png_malloc_base here to avoid an\n                * extra OOM message.\n                */\n               png_alloc_size_t new_size = *newlength;\n               png_alloc_size_t buffer_size = prefix_size + new_size +\n                   (terminate != 0);\n               png_bytep text = png_voidcast(png_bytep, png_malloc_base(png_ptr,\n                   buffer_size));\n\n               if (text != NULL)\n               {\n                  ret = png_inflate(png_ptr, png_ptr->chunk_name, 1/*finish*/,\n                      png_ptr->read_buffer + prefix_size, &lzsize,\n                      text + prefix_size, newlength);\n\n                  if (ret == Z_STREAM_END)\n                  {\n                     if (new_size == *newlength)\n                     {\n                        if (terminate != 0)\n                           text[prefix_size + *newlength] = 0;\n\n                        if (prefix_size > 0)\n                           memcpy(text, png_ptr->read_buffer, prefix_size);\n\n                        {\n                           png_bytep old_ptr = png_ptr->read_buffer;\n\n                           png_ptr->read_buffer = text;\n                           png_ptr->read_buffer_size = buffer_size;\n                           text = old_ptr; /* freed below */\n                        }\n                     }\n\n                     else\n                     {\n                        /* The size changed on the second read, there can be no\n                         * guarantee that anything is correct at this point.\n                         * The 'msg' pointer has been set to \"unexpected end of\n                         * LZ stream\", which is fine, but return an error code\n                         * that the caller won't accept.\n                         */\n                        ret = PNG_UNEXPECTED_ZLIB_RETURN;\n                     }\n                  }\n\n                  else if (ret == Z_OK)\n                     ret = PNG_UNEXPECTED_ZLIB_RETURN; /* for safety */\n\n                  /* Free the text pointer (this is the old read_buffer on\n                   * success)\n                   */\n                  png_free(png_ptr, text);\n\n                  /* This really is very benign, but it's still an error because\n                   * the extra space may otherwise be used as a Trojan Horse.\n                   */\n                  if (ret == Z_STREAM_END &&\n                     chunklength - prefix_size != lzsize)\n                     png_chunk_benign_error(png_ptr, \"extra compressed data\");\n               }\n\n               else\n               {\n                  /* Out of memory allocating the buffer */\n                  ret = Z_MEM_ERROR;\n                  png_zstream_error(png_ptr, Z_MEM_ERROR);\n               }\n            }\n\n            else\n            {\n               /* inflateReset failed, store the error message */\n               png_zstream_error(png_ptr, ret);\n\n               if (ret == Z_STREAM_END)\n                  ret = PNG_UNEXPECTED_ZLIB_RETURN;\n            }\n         }\n\n         else if (ret == Z_OK)\n            ret = PNG_UNEXPECTED_ZLIB_RETURN;\n\n         /* Release the claimed stream */\n         png_ptr->zowner = 0;\n      }\n\n      else /* the claim failed */ if (ret == Z_STREAM_END) /* impossible! */\n         ret = PNG_UNEXPECTED_ZLIB_RETURN;\n\n      return ret;\n   }\n\n   else\n   {\n      /* Application/configuration limits exceeded */\n      png_zstream_error(png_ptr, Z_MEM_ERROR);\n      return Z_MEM_ERROR;\n   }\n}\n#endif /* READ_zTXt || READ_iTXt */\n#endif /* READ_COMPRESSED_TEXT */\n\n#ifdef PNG_READ_iCCP_SUPPORTED\n/* Perform a partial read and decompress, producing 'avail_out' bytes and\n * reading from the current chunk as required.\n */\nstatic int\npng_inflate_read(png_structrp png_ptr, png_bytep read_buffer, uInt read_size,\n    png_uint_32p chunk_bytes, png_bytep next_out, png_alloc_size_t *out_size,\n    int finish)\n{\n   if (png_ptr->zowner == png_ptr->chunk_name)\n   {\n      int ret;\n\n      /* next_in and avail_in must have been initialized by the caller. */\n      png_ptr->zstream.next_out = next_out;\n      png_ptr->zstream.avail_out = 0; /* set in the loop */\n\n      do\n      {\n         if (png_ptr->zstream.avail_in == 0)\n         {\n            if (read_size > *chunk_bytes)\n               read_size = (uInt)*chunk_bytes;\n            *chunk_bytes -= read_size;\n\n            if (read_size > 0)\n               png_crc_read(png_ptr, read_buffer, read_size);\n\n            png_ptr->zstream.next_in = read_buffer;\n            png_ptr->zstream.avail_in = read_size;\n         }\n\n         if (png_ptr->zstream.avail_out == 0)\n         {\n            uInt avail = ZLIB_IO_MAX;\n            if (avail > *out_size)\n               avail = (uInt)*out_size;\n            *out_size -= avail;\n\n            png_ptr->zstream.avail_out = avail;\n         }\n\n         /* Use Z_SYNC_FLUSH when there is no more chunk data to ensure that all\n          * the available output is produced; this allows reading of truncated\n          * streams.\n          */\n         ret = PNG_INFLATE(png_ptr, *chunk_bytes > 0 ?\n             Z_NO_FLUSH : (finish ? Z_FINISH : Z_SYNC_FLUSH));\n      }\n      while (ret == Z_OK && (*out_size > 0 || png_ptr->zstream.avail_out > 0));\n\n      *out_size += png_ptr->zstream.avail_out;\n      png_ptr->zstream.avail_out = 0; /* Should not be required, but is safe */\n\n      /* Ensure the error message pointer is always set: */\n      png_zstream_error(png_ptr, ret);\n      return ret;\n   }\n\n   else\n   {\n      png_ptr->zstream.msg = PNGZ_MSG_CAST(\"zstream unclaimed\");\n      return Z_STREAM_ERROR;\n   }\n}\n#endif\n\n/* Read and check the IDHR chunk */\n\nvoid /* PRIVATE */\npng_handle_IHDR(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte buf[13];\n   png_uint_32 width, height;\n   int bit_depth, color_type, compression_type, filter_type;\n   int interlace_type;\n\n   png_debug(1, \"in png_handle_IHDR\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) != 0)\n      png_chunk_error(png_ptr, \"out of place\");\n\n   /* Check the length */\n   if (length != 13)\n      png_chunk_error(png_ptr, \"invalid\");\n\n   png_ptr->mode |= PNG_HAVE_IHDR;\n\n   png_crc_read(png_ptr, buf, 13);\n   png_crc_finish(png_ptr, 0);\n\n   width = png_get_uint_31(png_ptr, buf);\n   height = png_get_uint_31(png_ptr, buf + 4);\n   bit_depth = buf[8];\n   color_type = buf[9];\n   compression_type = buf[10];\n   filter_type = buf[11];\n   interlace_type = buf[12];\n\n   /* Set internal variables */\n   png_ptr->width = width;\n   png_ptr->height = height;\n   png_ptr->bit_depth = (png_byte)bit_depth;\n   png_ptr->interlaced = (png_byte)interlace_type;\n   png_ptr->color_type = (png_byte)color_type;\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   png_ptr->filter_type = (png_byte)filter_type;\n#endif\n   png_ptr->compression_type = (png_byte)compression_type;\n\n   /* Find number of channels */\n   switch (png_ptr->color_type)\n   {\n      default: /* invalid, png_set_IHDR calls png_error */\n      case PNG_COLOR_TYPE_GRAY:\n      case PNG_COLOR_TYPE_PALETTE:\n         png_ptr->channels = 1;\n         break;\n\n      case PNG_COLOR_TYPE_RGB:\n         png_ptr->channels = 3;\n         break;\n\n      case PNG_COLOR_TYPE_GRAY_ALPHA:\n         png_ptr->channels = 2;\n         break;\n\n      case PNG_COLOR_TYPE_RGB_ALPHA:\n         png_ptr->channels = 4;\n         break;\n   }\n\n   /* Set up other useful info */\n   png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth * png_ptr->channels);\n   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->width);\n   png_debug1(3, \"bit_depth = %d\", png_ptr->bit_depth);\n   png_debug1(3, \"channels = %d\", png_ptr->channels);\n   png_debug1(3, \"rowbytes = %lu\", (unsigned long)png_ptr->rowbytes);\n   png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,\n       color_type, interlace_type, compression_type, filter_type);\n}\n\n/* Read and check the palette */\nvoid /* PRIVATE */\npng_handle_PLTE(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_color palette[PNG_MAX_PALETTE_LENGTH];\n   int max_palette_length, num, i;\n#ifdef PNG_POINTER_INDEXING_SUPPORTED\n   png_colorp pal_ptr;\n#endif\n\n   png_debug(1, \"in png_handle_PLTE\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   /* Moved to before the 'after IDAT' check below because otherwise duplicate\n    * PLTE chunks are potentially ignored (the spec says there shall not be more\n    * than one PLTE, the error is not treated as benign, so this check trumps\n    * the requirement that PLTE appears before IDAT.)\n    */\n   else if ((png_ptr->mode & PNG_HAVE_PLTE) != 0)\n      png_chunk_error(png_ptr, \"duplicate\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      /* This is benign because the non-benign error happened before, when an\n       * IDAT was encountered in a color-mapped image with no PLTE.\n       */\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   png_ptr->mode |= PNG_HAVE_PLTE;\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"ignored in grayscale PNG\");\n      return;\n   }\n\n#ifndef PNG_READ_OPT_PLTE_SUPPORTED\n   if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)\n   {\n      png_crc_finish(png_ptr, length);\n      return;\n   }\n#endif\n\n   if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)\n   {\n      png_crc_finish(png_ptr, length);\n\n      if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)\n         png_chunk_benign_error(png_ptr, \"invalid\");\n\n      else\n         png_chunk_error(png_ptr, \"invalid\");\n\n      return;\n   }\n\n   /* The cast is safe because 'length' is less than 3*PNG_MAX_PALETTE_LENGTH */\n   num = (int)length / 3;\n\n   /* If the palette has 256 or fewer entries but is too large for the bit\n    * depth, we don't issue an error, to preserve the behavior of previous\n    * libpng versions. We silently truncate the unused extra palette entries\n    * here.\n    */\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      max_palette_length = (1 << png_ptr->bit_depth);\n   else\n      max_palette_length = PNG_MAX_PALETTE_LENGTH;\n\n   if (num > max_palette_length)\n      num = max_palette_length;\n\n#ifdef PNG_POINTER_INDEXING_SUPPORTED\n   for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)\n   {\n      png_byte buf[3];\n\n      png_crc_read(png_ptr, buf, 3);\n      pal_ptr->red = buf[0];\n      pal_ptr->green = buf[1];\n      pal_ptr->blue = buf[2];\n   }\n#else\n   for (i = 0; i < num; i++)\n   {\n      png_byte buf[3];\n\n      png_crc_read(png_ptr, buf, 3);\n      /* Don't depend upon png_color being any order */\n      palette[i].red = buf[0];\n      palette[i].green = buf[1];\n      palette[i].blue = buf[2];\n   }\n#endif\n\n   /* If we actually need the PLTE chunk (ie for a paletted image), we do\n    * whatever the normal CRC configuration tells us.  However, if we\n    * have an RGB image, the PLTE can be considered ancillary, so\n    * we will act as though it is.\n    */\n#ifndef PNG_READ_OPT_PLTE_SUPPORTED\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n#endif\n   {\n      png_crc_finish(png_ptr, (int) length - num * 3);\n   }\n\n#ifndef PNG_READ_OPT_PLTE_SUPPORTED\n   else if (png_crc_error(png_ptr) != 0)  /* Only if we have a CRC error */\n   {\n      /* If we don't want to use the data from an ancillary chunk,\n       * we have two options: an error abort, or a warning and we\n       * ignore the data in this chunk (which should be OK, since\n       * it's considered ancillary for a RGB or RGBA image).\n       *\n       * IMPLEMENTATION NOTE: this is only here because png_crc_finish uses the\n       * chunk type to determine whether to check the ancillary or the critical\n       * flags.\n       */\n      if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE) == 0)\n      {\n         if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) != 0)\n            return;\n\n         else\n            png_chunk_error(png_ptr, \"CRC error\");\n      }\n\n      /* Otherwise, we (optionally) emit a warning and use the chunk. */\n      else if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN) == 0)\n         png_chunk_warning(png_ptr, \"CRC error\");\n   }\n#endif\n\n   /* TODO: png_set_PLTE has the side effect of setting png_ptr->palette to its\n    * own copy of the palette.  This has the side effect that when png_start_row\n    * is called (this happens after any call to png_read_update_info) the\n    * info_ptr palette gets changed.  This is extremely unexpected and\n    * confusing.\n    *\n    * Fix this by not sharing the palette in this way.\n    */\n   png_set_PLTE(png_ptr, info_ptr, palette, num);\n\n   /* The three chunks, bKGD, hIST and tRNS *must* appear after PLTE and before\n    * IDAT.  Prior to 1.6.0 this was not checked; instead the code merely\n    * checked the apparent validity of a tRNS chunk inserted before PLTE on a\n    * palette PNG.  1.6.0 attempts to rigorously follow the standard and\n    * therefore does a benign error if the erroneous condition is detected *and*\n    * cancels the tRNS if the benign error returns.  The alternative is to\n    * amend the standard since it would be rather hypocritical of the standards\n    * maintainers to ignore it.\n    */\n#ifdef PNG_READ_tRNS_SUPPORTED\n   if (png_ptr->num_trans > 0 ||\n       (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0))\n   {\n      /* Cancel this because otherwise it would be used if the transforms\n       * require it.  Don't cancel the 'valid' flag because this would prevent\n       * detection of duplicate chunks.\n       */\n      png_ptr->num_trans = 0;\n\n      if (info_ptr != NULL)\n         info_ptr->num_trans = 0;\n\n      png_chunk_benign_error(png_ptr, \"tRNS must be after\");\n   }\n#endif\n\n#ifdef PNG_READ_hIST_SUPPORTED\n   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)\n      png_chunk_benign_error(png_ptr, \"hIST must be after\");\n#endif\n\n#ifdef PNG_READ_bKGD_SUPPORTED\n   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)\n      png_chunk_benign_error(png_ptr, \"bKGD must be after\");\n#endif\n}\n\nvoid /* PRIVATE */\npng_handle_IEND(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_debug(1, \"in png_handle_IEND\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0 ||\n       (png_ptr->mode & PNG_HAVE_IDAT) == 0)\n      png_chunk_error(png_ptr, \"out of place\");\n\n   png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);\n\n   png_crc_finish(png_ptr, length);\n\n   if (length != 0)\n      png_chunk_benign_error(png_ptr, \"invalid\");\n\n   PNG_UNUSED(info_ptr)\n}\n\n#ifdef PNG_READ_gAMA_SUPPORTED\nvoid /* PRIVATE */\npng_handle_gAMA(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_fixed_point igamma;\n   png_byte buf[4];\n\n   png_debug(1, \"in png_handle_gAMA\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   if (length != 4)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, 4);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   igamma = png_get_fixed_point(NULL, buf);\n\n   png_colorspace_set_gamma(png_ptr, &png_ptr->colorspace, igamma);\n   png_colorspace_sync(png_ptr, info_ptr);\n}\n#endif\n\n#ifdef PNG_READ_sBIT_SUPPORTED\nvoid /* PRIVATE */\npng_handle_sBIT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   unsigned int truelen, i;\n   png_byte sample_depth;\n   png_byte buf[4];\n\n   png_debug(1, \"in png_handle_sBIT\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      truelen = 3;\n      sample_depth = 8;\n   }\n\n   else\n   {\n      truelen = png_ptr->channels;\n      sample_depth = png_ptr->bit_depth;\n   }\n\n   if (length != truelen || length > 4)\n   {\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      png_crc_finish(png_ptr, length);\n      return;\n   }\n\n   buf[0] = buf[1] = buf[2] = buf[3] = sample_depth;\n   png_crc_read(png_ptr, buf, truelen);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   for (i=0; i<truelen; ++i)\n   {\n      if (buf[i] == 0 || buf[i] > sample_depth)\n      {\n         png_chunk_benign_error(png_ptr, \"invalid\");\n         return;\n      }\n   }\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      png_ptr->sig_bit.red = buf[0];\n      png_ptr->sig_bit.green = buf[1];\n      png_ptr->sig_bit.blue = buf[2];\n      png_ptr->sig_bit.alpha = buf[3];\n   }\n\n   else\n   {\n      png_ptr->sig_bit.gray = buf[0];\n      png_ptr->sig_bit.red = buf[0];\n      png_ptr->sig_bit.green = buf[0];\n      png_ptr->sig_bit.blue = buf[0];\n      png_ptr->sig_bit.alpha = buf[1];\n   }\n\n   png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));\n}\n#endif\n\n#ifdef PNG_READ_cHRM_SUPPORTED\nvoid /* PRIVATE */\npng_handle_cHRM(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte buf[32];\n   png_xy xy;\n\n   png_debug(1, \"in png_handle_cHRM\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   if (length != 32)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, 32);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   xy.whitex = png_get_fixed_point(NULL, buf);\n   xy.whitey = png_get_fixed_point(NULL, buf + 4);\n   xy.redx   = png_get_fixed_point(NULL, buf + 8);\n   xy.redy   = png_get_fixed_point(NULL, buf + 12);\n   xy.greenx = png_get_fixed_point(NULL, buf + 16);\n   xy.greeny = png_get_fixed_point(NULL, buf + 20);\n   xy.bluex  = png_get_fixed_point(NULL, buf + 24);\n   xy.bluey  = png_get_fixed_point(NULL, buf + 28);\n\n   if (xy.whitex == PNG_FIXED_ERROR ||\n       xy.whitey == PNG_FIXED_ERROR ||\n       xy.redx   == PNG_FIXED_ERROR ||\n       xy.redy   == PNG_FIXED_ERROR ||\n       xy.greenx == PNG_FIXED_ERROR ||\n       xy.greeny == PNG_FIXED_ERROR ||\n       xy.bluex  == PNG_FIXED_ERROR ||\n       xy.bluey  == PNG_FIXED_ERROR)\n   {\n      png_chunk_benign_error(png_ptr, \"invalid values\");\n      return;\n   }\n\n   /* If a colorspace error has already been output skip this chunk */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)\n      return;\n\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0)\n   {\n      png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;\n      png_colorspace_sync(png_ptr, info_ptr);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   png_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;\n   (void)png_colorspace_set_chromaticities(png_ptr, &png_ptr->colorspace, &xy,\n       1/*prefer cHRM values*/);\n   png_colorspace_sync(png_ptr, info_ptr);\n}\n#endif\n\n#ifdef PNG_READ_sRGB_SUPPORTED\nvoid /* PRIVATE */\npng_handle_sRGB(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte intent;\n\n   png_debug(1, \"in png_handle_sRGB\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   if (length != 1)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, &intent, 1);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   /* If a colorspace error has already been output skip this chunk */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)\n      return;\n\n   /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect\n    * this.\n    */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) != 0)\n   {\n      png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;\n      png_colorspace_sync(png_ptr, info_ptr);\n      png_chunk_benign_error(png_ptr, \"too many profiles\");\n      return;\n   }\n\n   (void)png_colorspace_set_sRGB(png_ptr, &png_ptr->colorspace, intent);\n   png_colorspace_sync(png_ptr, info_ptr);\n}\n#endif /* READ_sRGB */\n\n#ifdef PNG_READ_iCCP_SUPPORTED\nvoid /* PRIVATE */\npng_handle_iCCP(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n/* Note: this does not properly handle profiles that are > 64K under DOS */\n{\n   png_const_charp errmsg = NULL; /* error message output, or no error */\n   int finished = 0; /* crc checked */\n\n   png_debug(1, \"in png_handle_iCCP\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & (PNG_HAVE_IDAT|PNG_HAVE_PLTE)) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   /* Consistent with all the above colorspace handling an obviously *invalid*\n    * chunk is just ignored, so does not invalidate the color space.  An\n    * alternative is to set the 'invalid' flags at the start of this routine\n    * and only clear them in they were not set before and all the tests pass.\n    * The minimum 'deflate' stream is assumed to be just the 2 byte header and\n    * 4 byte checksum.  The keyword must be at least one character and there is\n    * a terminator (0) byte and the compression method.\n    */\n   if (length < 9)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"too short\");\n      return;\n   }\n\n   /* If a colorspace error has already been output skip this chunk */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      return;\n   }\n\n   /* Only one sRGB or iCCP chunk is allowed, use the HAVE_INTENT flag to detect\n    * this.\n    */\n   if ((png_ptr->colorspace.flags & PNG_COLORSPACE_HAVE_INTENT) == 0)\n   {\n      uInt read_length, keyword_length;\n      char keyword[81];\n\n      /* Find the keyword; the keyword plus separator and compression method\n       * bytes can be at most 81 characters long.\n       */\n      read_length = 81; /* maximum */\n      if (read_length > length)\n         read_length = (uInt)length;\n\n      png_crc_read(png_ptr, (png_bytep)keyword, read_length);\n      length -= read_length;\n\n      keyword_length = 0;\n      while (keyword_length < 80 && keyword_length < read_length &&\n         keyword[keyword_length] != 0)\n         ++keyword_length;\n\n      /* TODO: make the keyword checking common */\n      if (keyword_length >= 1 && keyword_length <= 79)\n      {\n         /* We only understand '0' compression - deflate - so if we get a\n          * different value we can't safely decode the chunk.\n          */\n         if (keyword_length+1 < read_length &&\n            keyword[keyword_length+1] == PNG_COMPRESSION_TYPE_BASE)\n         {\n            read_length -= keyword_length+2;\n\n            if (png_inflate_claim(png_ptr, png_iCCP) == Z_OK)\n            {\n               Byte profile_header[132];\n               Byte local_buffer[PNG_INFLATE_BUF_SIZE];\n               png_alloc_size_t size = (sizeof profile_header);\n\n               png_ptr->zstream.next_in = (Bytef*)keyword + (keyword_length+2);\n               png_ptr->zstream.avail_in = read_length;\n               (void)png_inflate_read(png_ptr, local_buffer,\n                   (sizeof local_buffer), &length, profile_header, &size,\n                   0/*finish: don't, because the output is too small*/);\n\n               if (size == 0)\n               {\n                  /* We have the ICC profile header; do the basic header checks.\n                   */\n                  const png_uint_32 profile_length =\n                     png_get_uint_32(profile_header);\n\n                  if (png_icc_check_length(png_ptr, &png_ptr->colorspace,\n                      keyword, profile_length) != 0)\n                  {\n                     /* The length is apparently ok, so we can check the 132\n                      * byte header.\n                      */\n                     if (png_icc_check_header(png_ptr, &png_ptr->colorspace,\n                         keyword, profile_length, profile_header,\n                         png_ptr->color_type) != 0)\n                     {\n                        /* Now read the tag table; a variable size buffer is\n                         * needed at this point, allocate one for the whole\n                         * profile.  The header check has already validated\n                         * that none of these stuff will overflow.\n                         */\n                        const png_uint_32 tag_count = png_get_uint_32(\n                            profile_header+128);\n                        png_bytep profile = png_read_buffer(png_ptr,\n                            profile_length, 2/*silent*/);\n\n                        if (profile != NULL)\n                        {\n                           memcpy(profile, profile_header,\n                               (sizeof profile_header));\n\n                           size = 12 * tag_count;\n\n                           (void)png_inflate_read(png_ptr, local_buffer,\n                               (sizeof local_buffer), &length,\n                               profile + (sizeof profile_header), &size, 0);\n\n                           /* Still expect a buffer error because we expect\n                            * there to be some tag data!\n                            */\n                           if (size == 0)\n                           {\n                              if (png_icc_check_tag_table(png_ptr,\n                                  &png_ptr->colorspace, keyword, profile_length,\n                                  profile) != 0)\n                              {\n                                 /* The profile has been validated for basic\n                                  * security issues, so read the whole thing in.\n                                  */\n                                 size = profile_length - (sizeof profile_header)\n                                     - 12 * tag_count;\n\n                                 (void)png_inflate_read(png_ptr, local_buffer,\n                                     (sizeof local_buffer), &length,\n                                     profile + (sizeof profile_header) +\n                                     12 * tag_count, &size, 1/*finish*/);\n\n                                 if (length > 0 && !(png_ptr->flags &\n                                     PNG_FLAG_BENIGN_ERRORS_WARN))\n                                    errmsg = \"extra compressed data\";\n\n                                 /* But otherwise allow extra data: */\n                                 else if (size == 0)\n                                 {\n                                    if (length > 0)\n                                    {\n                                       /* This can be handled completely, so\n                                        * keep going.\n                                        */\n                                       png_chunk_warning(png_ptr,\n                                           \"extra compressed data\");\n                                    }\n\n                                    png_crc_finish(png_ptr, length);\n                                    finished = 1;\n\n# if defined(PNG_sRGB_SUPPORTED) && PNG_sRGB_PROFILE_CHECKS >= 0\n                                    /* Check for a match against sRGB */\n                                    png_icc_set_sRGB(png_ptr,\n                                        &png_ptr->colorspace, profile,\n                                        png_ptr->zstream.adler);\n# endif\n\n                                    /* Steal the profile for info_ptr. */\n                                    if (info_ptr != NULL)\n                                    {\n                                       png_free_data(png_ptr, info_ptr,\n                                           PNG_FREE_ICCP, 0);\n\n                                       info_ptr->iccp_name = png_voidcast(char*,\n                                           png_malloc_base(png_ptr,\n                                           keyword_length+1));\n                                       if (info_ptr->iccp_name != NULL)\n                                       {\n                                          memcpy(info_ptr->iccp_name, keyword,\n                                              keyword_length+1);\n                                          info_ptr->iccp_proflen =\n                                              profile_length;\n                                          info_ptr->iccp_profile = profile;\n                                          png_ptr->read_buffer = NULL; /*steal*/\n                                          info_ptr->free_me |= PNG_FREE_ICCP;\n                                          info_ptr->valid |= PNG_INFO_iCCP;\n                                       }\n\n                                       else\n                                       {\n                                          png_ptr->colorspace.flags |=\n                                             PNG_COLORSPACE_INVALID;\n                                          errmsg = \"out of memory\";\n                                       }\n                                    }\n\n                                    /* else the profile remains in the read\n                                     * buffer which gets reused for subsequent\n                                     * chunks.\n                                     */\n\n                                    if (info_ptr != NULL)\n                                       png_colorspace_sync(png_ptr, info_ptr);\n\n                                    if (errmsg == NULL)\n                                    {\n                                       png_ptr->zowner = 0;\n                                       return;\n                                    }\n                                 }\n\n                                 else if (size > 0)\n                                    errmsg = \"truncated\";\n\n#ifndef __COVERITY__\n                                 else\n                                    errmsg = png_ptr->zstream.msg;\n#endif\n                              }\n\n                              /* else png_icc_check_tag_table output an error */\n                           }\n\n                           else /* profile truncated */\n                              errmsg = png_ptr->zstream.msg;\n                        }\n\n                        else\n                           errmsg = \"out of memory\";\n                     }\n\n                     /* else png_icc_check_header output an error */\n                  }\n\n                  /* else png_icc_check_length output an error */\n               }\n\n               else /* profile truncated */\n                  errmsg = png_ptr->zstream.msg;\n\n               /* Release the stream */\n               png_ptr->zowner = 0;\n            }\n\n            else /* png_inflate_claim failed */\n               errmsg = png_ptr->zstream.msg;\n         }\n\n         else\n            errmsg = \"bad compression method\"; /* or missing */\n      }\n\n      else\n         errmsg = \"bad keyword\";\n   }\n\n   else\n      errmsg = \"too many profiles\";\n\n   /* Failure: the reason is in 'errmsg' */\n   if (finished == 0)\n      png_crc_finish(png_ptr, length);\n\n   png_ptr->colorspace.flags |= PNG_COLORSPACE_INVALID;\n   png_colorspace_sync(png_ptr, info_ptr);\n   if (errmsg != NULL) /* else already output */\n      png_chunk_benign_error(png_ptr, errmsg);\n}\n#endif /* READ_iCCP */\n\n#ifdef PNG_READ_sPLT_SUPPORTED\nvoid /* PRIVATE */\npng_handle_sPLT(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n/* Note: this does not properly handle chunks that are > 64K under DOS */\n{\n   png_bytep entry_start, buffer;\n   png_sPLT_t new_palette;\n   png_sPLT_entryp pp;\n   png_uint_32 data_length;\n   int entry_size, i;\n   png_uint_32 skip = 0;\n   png_uint_32 dl;\n   png_size_t max_dl;\n\n   png_debug(1, \"in png_handle_sPLT\");\n\n#ifdef PNG_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_cache_max != 0)\n   {\n      if (png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         return;\n      }\n\n      if (--png_ptr->user_chunk_cache_max == 1)\n      {\n         png_warning(png_ptr, \"No space in chunk cache for sPLT\");\n         png_crc_finish(png_ptr, length);\n         return;\n      }\n   }\n#endif\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n#ifdef PNG_MAX_MALLOC_64K\n   if (length > 65535U)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"too large to fit in memory\");\n      return;\n   }\n#endif\n\n   buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);\n   if (buffer == NULL)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n\n   /* WARNING: this may break if size_t is less than 32 bits; it is assumed\n    * that the PNG_MAX_MALLOC_64K test is enabled in this case, but this is a\n    * potential breakage point if the types in pngconf.h aren't exactly right.\n    */\n   png_crc_read(png_ptr, buffer, length);\n\n   if (png_crc_finish(png_ptr, skip) != 0)\n      return;\n\n   buffer[length] = 0;\n\n   for (entry_start = buffer; *entry_start; entry_start++)\n      /* Empty loop to find end of name */ ;\n\n   ++entry_start;\n\n   /* A sample depth should follow the separator, and we should be on it  */\n   if (length < 2U || entry_start > buffer + (length - 2U))\n   {\n      png_warning(png_ptr, \"malformed sPLT chunk\");\n      return;\n   }\n\n   new_palette.depth = *entry_start++;\n   entry_size = (new_palette.depth == 8 ? 6 : 10);\n   /* This must fit in a png_uint_32 because it is derived from the original\n    * chunk data length.\n    */\n   data_length = length - (png_uint_32)(entry_start - buffer);\n\n   /* Integrity-check the data length */\n   if ((data_length % entry_size) != 0)\n   {\n      png_warning(png_ptr, \"sPLT chunk has bad length\");\n      return;\n   }\n\n   dl = (png_int_32)(data_length / entry_size);\n   max_dl = PNG_SIZE_MAX / (sizeof (png_sPLT_entry));\n\n   if (dl > max_dl)\n   {\n      png_warning(png_ptr, \"sPLT chunk too long\");\n      return;\n   }\n\n   new_palette.nentries = (png_int_32)(data_length / entry_size);\n\n   new_palette.entries = (png_sPLT_entryp)png_malloc_warn(\n       png_ptr, new_palette.nentries * (sizeof (png_sPLT_entry)));\n\n   if (new_palette.entries == NULL)\n   {\n      png_warning(png_ptr, \"sPLT chunk requires too much memory\");\n      return;\n   }\n\n#ifdef PNG_POINTER_INDEXING_SUPPORTED\n   for (i = 0; i < new_palette.nentries; i++)\n   {\n      pp = new_palette.entries + i;\n\n      if (new_palette.depth == 8)\n      {\n         pp->red = *entry_start++;\n         pp->green = *entry_start++;\n         pp->blue = *entry_start++;\n         pp->alpha = *entry_start++;\n      }\n\n      else\n      {\n         pp->red   = png_get_uint_16(entry_start); entry_start += 2;\n         pp->green = png_get_uint_16(entry_start); entry_start += 2;\n         pp->blue  = png_get_uint_16(entry_start); entry_start += 2;\n         pp->alpha = png_get_uint_16(entry_start); entry_start += 2;\n      }\n\n      pp->frequency = png_get_uint_16(entry_start); entry_start += 2;\n   }\n#else\n   pp = new_palette.entries;\n\n   for (i = 0; i < new_palette.nentries; i++)\n   {\n\n      if (new_palette.depth == 8)\n      {\n         pp[i].red   = *entry_start++;\n         pp[i].green = *entry_start++;\n         pp[i].blue  = *entry_start++;\n         pp[i].alpha = *entry_start++;\n      }\n\n      else\n      {\n         pp[i].red   = png_get_uint_16(entry_start); entry_start += 2;\n         pp[i].green = png_get_uint_16(entry_start); entry_start += 2;\n         pp[i].blue  = png_get_uint_16(entry_start); entry_start += 2;\n         pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;\n      }\n\n      pp[i].frequency = png_get_uint_16(entry_start); entry_start += 2;\n   }\n#endif\n\n   /* Discard all chunk data except the name and stash that */\n   new_palette.name = (png_charp)buffer;\n\n   png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);\n\n   png_free(png_ptr, new_palette.entries);\n}\n#endif /* READ_sPLT */\n\n#ifdef PNG_READ_tRNS_SUPPORTED\nvoid /* PRIVATE */\npng_handle_tRNS(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte readbuf[PNG_MAX_PALETTE_LENGTH];\n\n   png_debug(1, \"in png_handle_tRNS\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)\n   {\n      png_byte buf[2];\n\n      if (length != 2)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"invalid\");\n         return;\n      }\n\n      png_crc_read(png_ptr, buf, 2);\n      png_ptr->num_trans = 1;\n      png_ptr->trans_color.gray = png_get_uint_16(buf);\n   }\n\n   else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)\n   {\n      png_byte buf[6];\n\n      if (length != 6)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"invalid\");\n         return;\n      }\n\n      png_crc_read(png_ptr, buf, length);\n      png_ptr->num_trans = 1;\n      png_ptr->trans_color.red = png_get_uint_16(buf);\n      png_ptr->trans_color.green = png_get_uint_16(buf + 2);\n      png_ptr->trans_color.blue = png_get_uint_16(buf + 4);\n   }\n\n   else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      if ((png_ptr->mode & PNG_HAVE_PLTE) == 0)\n      {\n         /* TODO: is this actually an error in the ISO spec? */\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"out of place\");\n         return;\n      }\n\n      if (length > (unsigned int) png_ptr->num_palette ||\n         length > (unsigned int) PNG_MAX_PALETTE_LENGTH ||\n         length == 0)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"invalid\");\n         return;\n      }\n\n      png_crc_read(png_ptr, readbuf, length);\n      png_ptr->num_trans = (png_uint_16)length;\n   }\n\n   else\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid with alpha channel\");\n      return;\n   }\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n   {\n      png_ptr->num_trans = 0;\n      return;\n   }\n\n   /* TODO: this is a horrible side effect in the palette case because the\n    * png_struct ends up with a pointer to the tRNS buffer owned by the\n    * png_info.  Fix this.\n    */\n   png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,\n       &(png_ptr->trans_color));\n}\n#endif\n\n#ifdef PNG_READ_bKGD_SUPPORTED\nvoid /* PRIVATE */\npng_handle_bKGD(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   unsigned int truelen;\n   png_byte buf[6];\n   png_color_16 background;\n\n   png_debug(1, \"in png_handle_bKGD\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||\n       (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&\n       (png_ptr->mode & PNG_HAVE_PLTE) == 0))\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      truelen = 1;\n\n   else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      truelen = 6;\n\n   else\n      truelen = 2;\n\n   if (length != truelen)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, truelen);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   /* We convert the index value into RGB components so that we can allow\n    * arbitrary RGB values for background when we have transparency, and\n    * so it is easy to determine the RGB values of the background color\n    * from the info_ptr struct.\n    */\n   if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      background.index = buf[0];\n\n      if (info_ptr != NULL && info_ptr->num_palette != 0)\n      {\n         if (buf[0] >= info_ptr->num_palette)\n         {\n            png_chunk_benign_error(png_ptr, \"invalid index\");\n            return;\n         }\n\n         background.red = (png_uint_16)png_ptr->palette[buf[0]].red;\n         background.green = (png_uint_16)png_ptr->palette[buf[0]].green;\n         background.blue = (png_uint_16)png_ptr->palette[buf[0]].blue;\n      }\n\n      else\n         background.red = background.green = background.blue = 0;\n\n      background.gray = 0;\n   }\n\n   else if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0) /* GRAY */\n   {\n      background.index = 0;\n      background.red =\n      background.green =\n      background.blue =\n      background.gray = png_get_uint_16(buf);\n   }\n\n   else\n   {\n      background.index = 0;\n      background.red = png_get_uint_16(buf);\n      background.green = png_get_uint_16(buf + 2);\n      background.blue = png_get_uint_16(buf + 4);\n      background.gray = 0;\n   }\n\n   png_set_bKGD(png_ptr, info_ptr, &background);\n}\n#endif\n\n#ifdef PNG_READ_hIST_SUPPORTED\nvoid /* PRIVATE */\npng_handle_hIST(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   unsigned int num, i;\n   png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];\n\n   png_debug(1, \"in png_handle_hIST\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0 ||\n       (png_ptr->mode & PNG_HAVE_PLTE) == 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   num = length / 2 ;\n\n   if (num != (unsigned int) png_ptr->num_palette ||\n       num > (unsigned int) PNG_MAX_PALETTE_LENGTH)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   for (i = 0; i < num; i++)\n   {\n      png_byte buf[2];\n\n      png_crc_read(png_ptr, buf, 2);\n      readbuf[i] = png_get_uint_16(buf);\n   }\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   png_set_hIST(png_ptr, info_ptr, readbuf);\n}\n#endif\n\n#ifdef PNG_READ_pHYs_SUPPORTED\nvoid /* PRIVATE */\npng_handle_pHYs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte buf[9];\n   png_uint_32 res_x, res_y;\n   int unit_type;\n\n   png_debug(1, \"in png_handle_pHYs\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if (length != 9)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, 9);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   res_x = png_get_uint_32(buf);\n   res_y = png_get_uint_32(buf + 4);\n   unit_type = buf[8];\n   png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);\n}\n#endif\n\n#ifdef PNG_READ_oFFs_SUPPORTED\nvoid /* PRIVATE */\npng_handle_oFFs(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte buf[9];\n   png_int_32 offset_x, offset_y;\n   int unit_type;\n\n   png_debug(1, \"in png_handle_oFFs\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if (length != 9)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, 9);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   offset_x = png_get_int_32(buf);\n   offset_y = png_get_int_32(buf + 4);\n   unit_type = buf[8];\n   png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);\n}\n#endif\n\n#ifdef PNG_READ_pCAL_SUPPORTED\n/* Read the pCAL chunk (described in the PNG Extensions document) */\nvoid /* PRIVATE */\npng_handle_pCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_int_32 X0, X1;\n   png_byte type, nparams;\n   png_bytep buffer, buf, units, endptr;\n   png_charpp params;\n   int i;\n\n   png_debug(1, \"in png_handle_pCAL\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   png_debug1(2, \"Allocating and reading pCAL chunk data (%u bytes)\",\n       length + 1);\n\n   buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);\n\n   if (buffer == NULL)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buffer, length);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   buffer[length] = 0; /* Null terminate the last string */\n\n   png_debug(3, \"Finding end of pCAL purpose string\");\n   for (buf = buffer; *buf; buf++)\n      /* Empty loop */ ;\n\n   endptr = buffer + length;\n\n   /* We need to have at least 12 bytes after the purpose string\n    * in order to get the parameter information.\n    */\n   if (endptr - buf <= 12)\n   {\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_debug(3, \"Reading pCAL X0, X1, type, nparams, and units\");\n   X0 = png_get_int_32((png_bytep)buf+1);\n   X1 = png_get_int_32((png_bytep)buf+5);\n   type = buf[9];\n   nparams = buf[10];\n   units = buf + 11;\n\n   png_debug(3, \"Checking pCAL equation type and number of parameters\");\n   /* Check that we have the right number of parameters for known\n    * equation types.\n    */\n   if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||\n       (type == PNG_EQUATION_BASE_E && nparams != 3) ||\n       (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||\n       (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))\n   {\n      png_chunk_benign_error(png_ptr, \"invalid parameter count\");\n      return;\n   }\n\n   else if (type >= PNG_EQUATION_LAST)\n   {\n      png_chunk_benign_error(png_ptr, \"unrecognized equation type\");\n   }\n\n   for (buf = units; *buf; buf++)\n      /* Empty loop to move past the units string. */ ;\n\n   png_debug(3, \"Allocating pCAL parameters array\");\n\n   params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,\n       nparams * (sizeof (png_charp))));\n\n   if (params == NULL)\n   {\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n   /* Get pointers to the start of each parameter string. */\n   for (i = 0; i < nparams; i++)\n   {\n      buf++; /* Skip the null string terminator from previous parameter. */\n\n      png_debug1(3, \"Reading pCAL parameter %d\", i);\n\n      for (params[i] = (png_charp)buf; buf <= endptr && *buf != 0; buf++)\n         /* Empty loop to move past each parameter string */ ;\n\n      /* Make sure we haven't run out of data yet */\n      if (buf > endptr)\n      {\n         png_free(png_ptr, params);\n         png_chunk_benign_error(png_ptr, \"invalid data\");\n         return;\n      }\n   }\n\n   png_set_pCAL(png_ptr, info_ptr, (png_charp)buffer, X0, X1, type, nparams,\n       (png_charp)units, params);\n\n   png_free(png_ptr, params);\n}\n#endif\n\n#ifdef PNG_READ_sCAL_SUPPORTED\n/* Read the sCAL chunk */\nvoid /* PRIVATE */\npng_handle_sCAL(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_bytep buffer;\n   png_size_t i;\n   int state;\n\n   png_debug(1, \"in png_handle_sCAL\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of place\");\n      return;\n   }\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   /* Need unit type, width, \\0, height: minimum 4 bytes */\n   else if (length < 4)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_debug1(2, \"Allocating and reading sCAL chunk data (%u bytes)\",\n       length + 1);\n\n   buffer = png_read_buffer(png_ptr, length+1, 2/*silent*/);\n\n   if (buffer == NULL)\n   {\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      png_crc_finish(png_ptr, length);\n      return;\n   }\n\n   png_crc_read(png_ptr, buffer, length);\n   buffer[length] = 0; /* Null terminate the last string */\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   /* Validate the unit. */\n   if (buffer[0] != 1 && buffer[0] != 2)\n   {\n      png_chunk_benign_error(png_ptr, \"invalid unit\");\n      return;\n   }\n\n   /* Validate the ASCII numbers, need two ASCII numbers separated by\n    * a '\\0' and they need to fit exactly in the chunk data.\n    */\n   i = 1;\n   state = 0;\n\n   if (png_check_fp_number((png_const_charp)buffer, length, &state, &i) == 0 ||\n       i >= length || buffer[i++] != 0)\n      png_chunk_benign_error(png_ptr, \"bad width format\");\n\n   else if (PNG_FP_IS_POSITIVE(state) == 0)\n      png_chunk_benign_error(png_ptr, \"non-positive width\");\n\n   else\n   {\n      png_size_t heighti = i;\n\n      state = 0;\n      if (png_check_fp_number((png_const_charp)buffer, length,\n          &state, &i) == 0 || i != length)\n         png_chunk_benign_error(png_ptr, \"bad height format\");\n\n      else if (PNG_FP_IS_POSITIVE(state) == 0)\n         png_chunk_benign_error(png_ptr, \"non-positive height\");\n\n      else\n         /* This is the (only) success case. */\n         png_set_sCAL_s(png_ptr, info_ptr, buffer[0],\n             (png_charp)buffer+1, (png_charp)buffer+heighti);\n   }\n}\n#endif\n\n#ifdef PNG_READ_tIME_SUPPORTED\nvoid /* PRIVATE */\npng_handle_tIME(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_byte buf[7];\n   png_time mod_time;\n\n   png_debug(1, \"in png_handle_tIME\");\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME) != 0)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"duplicate\");\n      return;\n   }\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n      png_ptr->mode |= PNG_AFTER_IDAT;\n\n   if (length != 7)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"invalid\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buf, 7);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   mod_time.second = buf[6];\n   mod_time.minute = buf[5];\n   mod_time.hour = buf[4];\n   mod_time.day = buf[3];\n   mod_time.month = buf[2];\n   mod_time.year = png_get_uint_16(buf);\n\n   png_set_tIME(png_ptr, info_ptr, &mod_time);\n}\n#endif\n\n#ifdef PNG_READ_tEXt_SUPPORTED\n/* Note: this does not properly handle chunks that are > 64K under DOS */\nvoid /* PRIVATE */\npng_handle_tEXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_text  text_info;\n   png_bytep buffer;\n   png_charp key;\n   png_charp text;\n   png_uint_32 skip = 0;\n\n   png_debug(1, \"in png_handle_tEXt\");\n\n#ifdef PNG_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_cache_max != 0)\n   {\n      if (png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         return;\n      }\n\n      if (--png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"no space in chunk cache\");\n         return;\n      }\n   }\n#endif\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n      png_ptr->mode |= PNG_AFTER_IDAT;\n\n#ifdef PNG_MAX_MALLOC_64K\n   if (length > 65535U)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"too large to fit in memory\");\n      return;\n   }\n#endif\n\n   buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);\n\n   if (buffer == NULL)\n   {\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buffer, length);\n\n   if (png_crc_finish(png_ptr, skip) != 0)\n      return;\n\n   key = (png_charp)buffer;\n   key[length] = 0;\n\n   for (text = key; *text; text++)\n      /* Empty loop to find end of key */ ;\n\n   if (text != key + length)\n      text++;\n\n   text_info.compression = PNG_TEXT_COMPRESSION_NONE;\n   text_info.key = key;\n   text_info.lang = NULL;\n   text_info.lang_key = NULL;\n   text_info.itxt_length = 0;\n   text_info.text = text;\n   text_info.text_length = strlen(text);\n\n   if (png_set_text_2(png_ptr, info_ptr, &text_info, 1) != 0)\n      png_warning(png_ptr, \"Insufficient memory to process text chunk\");\n}\n#endif\n\n#ifdef PNG_READ_zTXt_SUPPORTED\n/* Note: this does not correctly handle chunks that are > 64K under DOS */\nvoid /* PRIVATE */\npng_handle_zTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_const_charp errmsg = NULL;\n   png_bytep       buffer;\n   png_uint_32     keyword_length;\n\n   png_debug(1, \"in png_handle_zTXt\");\n\n#ifdef PNG_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_cache_max != 0)\n   {\n      if (png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         return;\n      }\n\n      if (--png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"no space in chunk cache\");\n         return;\n      }\n   }\n#endif\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n      png_ptr->mode |= PNG_AFTER_IDAT;\n\n   buffer = png_read_buffer(png_ptr, length, 2/*silent*/);\n\n   if (buffer == NULL)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buffer, length);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   /* TODO: also check that the keyword contents match the spec! */\n   for (keyword_length = 0;\n      keyword_length < length && buffer[keyword_length] != 0;\n      ++keyword_length)\n      /* Empty loop to find end of name */ ;\n\n   if (keyword_length > 79 || keyword_length < 1)\n      errmsg = \"bad keyword\";\n\n   /* zTXt must have some LZ data after the keyword, although it may expand to\n    * zero bytes; we need a '\\0' at the end of the keyword, the compression type\n    * then the LZ data:\n    */\n   else if (keyword_length + 3 > length)\n      errmsg = \"truncated\";\n\n   else if (buffer[keyword_length+1] != PNG_COMPRESSION_TYPE_BASE)\n      errmsg = \"unknown compression type\";\n\n   else\n   {\n      png_alloc_size_t uncompressed_length = PNG_SIZE_MAX;\n\n      /* TODO: at present png_decompress_chunk imposes a single application\n       * level memory limit, this should be split to different values for iCCP\n       * and text chunks.\n       */\n      if (png_decompress_chunk(png_ptr, length, keyword_length+2,\n          &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\n      {\n         png_text text;\n\n         /* It worked; png_ptr->read_buffer now looks like a tEXt chunk except\n          * for the extra compression type byte and the fact that it isn't\n          * necessarily '\\0' terminated.\n          */\n         buffer = png_ptr->read_buffer;\n         buffer[uncompressed_length+(keyword_length+2)] = 0;\n\n         text.compression = PNG_TEXT_COMPRESSION_zTXt;\n         text.key = (png_charp)buffer;\n         text.text = (png_charp)(buffer + keyword_length+2);\n         text.text_length = uncompressed_length;\n         text.itxt_length = 0;\n         text.lang = NULL;\n         text.lang_key = NULL;\n\n         if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)\n            errmsg = \"insufficient memory\";\n      }\n\n      else\n         errmsg = png_ptr->zstream.msg;\n   }\n\n   if (errmsg != NULL)\n      png_chunk_benign_error(png_ptr, errmsg);\n}\n#endif\n\n#ifdef PNG_READ_iTXt_SUPPORTED\n/* Note: this does not correctly handle chunks that are > 64K under DOS */\nvoid /* PRIVATE */\npng_handle_iTXt(png_structrp png_ptr, png_inforp info_ptr, png_uint_32 length)\n{\n   png_const_charp errmsg = NULL;\n   png_bytep buffer;\n   png_uint_32 prefix_length;\n\n   png_debug(1, \"in png_handle_iTXt\");\n\n#ifdef PNG_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_cache_max != 0)\n   {\n      if (png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         return;\n      }\n\n      if (--png_ptr->user_chunk_cache_max == 1)\n      {\n         png_crc_finish(png_ptr, length);\n         png_chunk_benign_error(png_ptr, \"no space in chunk cache\");\n         return;\n      }\n   }\n#endif\n\n   if ((png_ptr->mode & PNG_HAVE_IHDR) == 0)\n      png_chunk_error(png_ptr, \"missing IHDR\");\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) != 0)\n      png_ptr->mode |= PNG_AFTER_IDAT;\n\n   buffer = png_read_buffer(png_ptr, length+1, 1/*warn*/);\n\n   if (buffer == NULL)\n   {\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"out of memory\");\n      return;\n   }\n\n   png_crc_read(png_ptr, buffer, length);\n\n   if (png_crc_finish(png_ptr, 0) != 0)\n      return;\n\n   /* First the keyword. */\n   for (prefix_length=0;\n      prefix_length < length && buffer[prefix_length] != 0;\n      ++prefix_length)\n      /* Empty loop */ ;\n\n   /* Perform a basic check on the keyword length here. */\n   if (prefix_length > 79 || prefix_length < 1)\n      errmsg = \"bad keyword\";\n\n   /* Expect keyword, compression flag, compression type, language, translated\n    * keyword (both may be empty but are 0 terminated) then the text, which may\n    * be empty.\n    */\n   else if (prefix_length + 5 > length)\n      errmsg = \"truncated\";\n\n   else if (buffer[prefix_length+1] == 0 ||\n      (buffer[prefix_length+1] == 1 &&\n      buffer[prefix_length+2] == PNG_COMPRESSION_TYPE_BASE))\n   {\n      int compressed = buffer[prefix_length+1] != 0;\n      png_uint_32 language_offset, translated_keyword_offset;\n      png_alloc_size_t uncompressed_length = 0;\n\n      /* Now the language tag */\n      prefix_length += 3;\n      language_offset = prefix_length;\n\n      for (; prefix_length < length && buffer[prefix_length] != 0;\n         ++prefix_length)\n         /* Empty loop */ ;\n\n      /* WARNING: the length may be invalid here, this is checked below. */\n      translated_keyword_offset = ++prefix_length;\n\n      for (; prefix_length < length && buffer[prefix_length] != 0;\n         ++prefix_length)\n         /* Empty loop */ ;\n\n      /* prefix_length should now be at the trailing '\\0' of the translated\n       * keyword, but it may already be over the end.  None of this arithmetic\n       * can overflow because chunks are at most 2^31 bytes long, but on 16-bit\n       * systems the available allocation may overflow.\n       */\n      ++prefix_length;\n\n      if (compressed == 0 && prefix_length <= length)\n         uncompressed_length = length - prefix_length;\n\n      else if (compressed != 0 && prefix_length < length)\n      {\n         uncompressed_length = PNG_SIZE_MAX;\n\n         /* TODO: at present png_decompress_chunk imposes a single application\n          * level memory limit, this should be split to different values for\n          * iCCP and text chunks.\n          */\n         if (png_decompress_chunk(png_ptr, length, prefix_length,\n             &uncompressed_length, 1/*terminate*/) == Z_STREAM_END)\n            buffer = png_ptr->read_buffer;\n\n         else\n            errmsg = png_ptr->zstream.msg;\n      }\n\n      else\n         errmsg = \"truncated\";\n\n      if (errmsg == NULL)\n      {\n         png_text text;\n\n         buffer[uncompressed_length+prefix_length] = 0;\n\n         if (compressed == 0)\n            text.compression = PNG_ITXT_COMPRESSION_NONE;\n\n         else\n            text.compression = PNG_ITXT_COMPRESSION_zTXt;\n\n         text.key = (png_charp)buffer;\n         text.lang = (png_charp)buffer + language_offset;\n         text.lang_key = (png_charp)buffer + translated_keyword_offset;\n         text.text = (png_charp)buffer + prefix_length;\n         text.text_length = 0;\n         text.itxt_length = uncompressed_length;\n\n         if (png_set_text_2(png_ptr, info_ptr, &text, 1) != 0)\n            errmsg = \"insufficient memory\";\n      }\n   }\n\n   else\n      errmsg = \"bad compression info\";\n\n   if (errmsg != NULL)\n      png_chunk_benign_error(png_ptr, errmsg);\n}\n#endif\n\n#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n/* Utility function for png_handle_unknown; set up png_ptr::unknown_chunk */\nstatic int\npng_cache_unknown_chunk(png_structrp png_ptr, png_uint_32 length)\n{\n   png_alloc_size_t limit = PNG_SIZE_MAX;\n\n   if (png_ptr->unknown_chunk.data != NULL)\n   {\n      png_free(png_ptr, png_ptr->unknown_chunk.data);\n      png_ptr->unknown_chunk.data = NULL;\n   }\n\n#  ifdef PNG_SET_USER_LIMITS_SUPPORTED\n   if (png_ptr->user_chunk_malloc_max > 0 &&\n       png_ptr->user_chunk_malloc_max < limit)\n      limit = png_ptr->user_chunk_malloc_max;\n\n#  elif PNG_USER_CHUNK_MALLOC_MAX > 0\n   if (PNG_USER_CHUNK_MALLOC_MAX < limit)\n      limit = PNG_USER_CHUNK_MALLOC_MAX;\n#  endif\n\n   if (length <= limit)\n   {\n      PNG_CSTRING_FROM_CHUNK(png_ptr->unknown_chunk.name, png_ptr->chunk_name);\n      /* The following is safe because of the PNG_SIZE_MAX init above */\n      png_ptr->unknown_chunk.size = (png_size_t)length/*SAFE*/;\n      /* 'mode' is a flag array, only the bottom four bits matter here */\n      png_ptr->unknown_chunk.location = (png_byte)png_ptr->mode/*SAFE*/;\n\n      if (length == 0)\n         png_ptr->unknown_chunk.data = NULL;\n\n      else\n      {\n         /* Do a 'warn' here - it is handled below. */\n         png_ptr->unknown_chunk.data = png_voidcast(png_bytep,\n             png_malloc_warn(png_ptr, length));\n      }\n   }\n\n   if (png_ptr->unknown_chunk.data == NULL && length > 0)\n   {\n      /* This is benign because we clean up correctly */\n      png_crc_finish(png_ptr, length);\n      png_chunk_benign_error(png_ptr, \"unknown chunk exceeds memory limits\");\n      return 0;\n   }\n\n   else\n   {\n      if (length > 0)\n         png_crc_read(png_ptr, png_ptr->unknown_chunk.data, length);\n      png_crc_finish(png_ptr, 0);\n      return 1;\n   }\n}\n#endif /* READ_UNKNOWN_CHUNKS */\n\n/* Handle an unknown, or known but disabled, chunk */\nvoid /* PRIVATE */\npng_handle_unknown(png_structrp png_ptr, png_inforp info_ptr,\n    png_uint_32 length, int keep)\n{\n   int handled = 0; /* the chunk was handled */\n\n   png_debug(1, \"in png_handle_unknown\");\n\n#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n   /* NOTE: this code is based on the code in libpng-1.4.12 except for fixing\n    * the bug which meant that setting a non-default behavior for a specific\n    * chunk would be ignored (the default was always used unless a user\n    * callback was installed).\n    *\n    * 'keep' is the value from the png_chunk_unknown_handling, the setting for\n    * this specific chunk_name, if PNG_HANDLE_AS_UNKNOWN_SUPPORTED, if not it\n    * will always be PNG_HANDLE_CHUNK_AS_DEFAULT and it needs to be set here.\n    * This is just an optimization to avoid multiple calls to the lookup\n    * function.\n    */\n#  ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n#     ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n   keep = png_chunk_unknown_handling(png_ptr, png_ptr->chunk_name);\n#     endif\n#  endif\n\n   /* One of the following methods will read the chunk or skip it (at least one\n    * of these is always defined because this is the only way to switch on\n    * PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)\n    */\n#  ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n   /* The user callback takes precedence over the chunk keep value, but the\n    * keep value is still required to validate a save of a critical chunk.\n    */\n   if (png_ptr->read_user_chunk_fn != NULL)\n   {\n      if (png_cache_unknown_chunk(png_ptr, length) != 0)\n      {\n         /* Callback to user unknown chunk handler */\n         int ret = (*(png_ptr->read_user_chunk_fn))(png_ptr,\n             &png_ptr->unknown_chunk);\n\n         /* ret is:\n          * negative: An error occurred; png_chunk_error will be called.\n          *     zero: The chunk was not handled, the chunk will be discarded\n          *           unless png_set_keep_unknown_chunks has been used to set\n          *           a 'keep' behavior for this particular chunk, in which\n          *           case that will be used.  A critical chunk will cause an\n          *           error at this point unless it is to be saved.\n          * positive: The chunk was handled, libpng will ignore/discard it.\n          */\n         if (ret < 0)\n            png_chunk_error(png_ptr, \"error in user chunk\");\n\n         else if (ret == 0)\n         {\n            /* If the keep value is 'default' or 'never' override it, but\n             * still error out on critical chunks unless the keep value is\n             * 'always'  While this is weird it is the behavior in 1.4.12.\n             * A possible improvement would be to obey the value set for the\n             * chunk, but this would be an API change that would probably\n             * damage some applications.\n             *\n             * The png_app_warning below catches the case that matters, where\n             * the application has not set specific save or ignore for this\n             * chunk or global save or ignore.\n             */\n            if (keep < PNG_HANDLE_CHUNK_IF_SAFE)\n            {\n#              ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n               if (png_ptr->unknown_default < PNG_HANDLE_CHUNK_IF_SAFE)\n               {\n                  png_chunk_warning(png_ptr, \"Saving unknown chunk:\");\n                  png_app_warning(png_ptr,\n                      \"forcing save of an unhandled chunk;\"\n                      \" please call png_set_keep_unknown_chunks\");\n                      /* with keep = PNG_HANDLE_CHUNK_IF_SAFE */\n               }\n#              endif\n               keep = PNG_HANDLE_CHUNK_IF_SAFE;\n            }\n         }\n\n         else /* chunk was handled */\n         {\n            handled = 1;\n            /* Critical chunks can be safely discarded at this point. */\n            keep = PNG_HANDLE_CHUNK_NEVER;\n         }\n      }\n\n      else\n         keep = PNG_HANDLE_CHUNK_NEVER; /* insufficient memory */\n   }\n\n   else\n   /* Use the SAVE_UNKNOWN_CHUNKS code or skip the chunk */\n#  endif /* READ_USER_CHUNKS */\n\n#  ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n   {\n      /* keep is currently just the per-chunk setting, if there was no\n       * setting change it to the global default now (not that this may\n       * still be AS_DEFAULT) then obtain the cache of the chunk if required,\n       * if not simply skip the chunk.\n       */\n      if (keep == PNG_HANDLE_CHUNK_AS_DEFAULT)\n         keep = png_ptr->unknown_default;\n\n      if (keep == PNG_HANDLE_CHUNK_ALWAYS ||\n         (keep == PNG_HANDLE_CHUNK_IF_SAFE &&\n          PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))\n      {\n         if (png_cache_unknown_chunk(png_ptr, length) == 0)\n            keep = PNG_HANDLE_CHUNK_NEVER;\n      }\n\n      else\n         png_crc_finish(png_ptr, length);\n   }\n#  else\n#     ifndef PNG_READ_USER_CHUNKS_SUPPORTED\n#        error no method to support READ_UNKNOWN_CHUNKS\n#     endif\n\n   {\n      /* If here there is no read callback pointer set and no support is\n       * compiled in to just save the unknown chunks, so simply skip this\n       * chunk.  If 'keep' is something other than AS_DEFAULT or NEVER then\n       * the app has erroneously asked for unknown chunk saving when there\n       * is no support.\n       */\n      if (keep > PNG_HANDLE_CHUNK_NEVER)\n         png_app_error(png_ptr, \"no unknown chunk support available\");\n\n      png_crc_finish(png_ptr, length);\n   }\n#  endif\n\n#  ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n   /* Now store the chunk in the chunk list if appropriate, and if the limits\n    * permit it.\n    */\n   if (keep == PNG_HANDLE_CHUNK_ALWAYS ||\n      (keep == PNG_HANDLE_CHUNK_IF_SAFE &&\n       PNG_CHUNK_ANCILLARY(png_ptr->chunk_name)))\n   {\n#     ifdef PNG_USER_LIMITS_SUPPORTED\n      switch (png_ptr->user_chunk_cache_max)\n      {\n         case 2:\n            png_ptr->user_chunk_cache_max = 1;\n            png_chunk_benign_error(png_ptr, \"no space in chunk cache\");\n            /* FALL THROUGH */\n         case 1:\n            /* NOTE: prior to 1.6.0 this case resulted in an unknown critical\n             * chunk being skipped, now there will be a hard error below.\n             */\n            break;\n\n         default: /* not at limit */\n            --(png_ptr->user_chunk_cache_max);\n            /* FALL THROUGH */\n         case 0: /* no limit */\n#  endif /* USER_LIMITS */\n            /* Here when the limit isn't reached or when limits are compiled\n             * out; store the chunk.\n             */\n            png_set_unknown_chunks(png_ptr, info_ptr,\n                &png_ptr->unknown_chunk, 1);\n            handled = 1;\n#  ifdef PNG_USER_LIMITS_SUPPORTED\n            break;\n      }\n#  endif\n   }\n#  else /* no store support: the chunk must be handled by the user callback */\n   PNG_UNUSED(info_ptr)\n#  endif\n\n   /* Regardless of the error handling below the cached data (if any) can be\n    * freed now.  Notice that the data is not freed if there is a png_error, but\n    * it will be freed by destroy_read_struct.\n    */\n   if (png_ptr->unknown_chunk.data != NULL)\n      png_free(png_ptr, png_ptr->unknown_chunk.data);\n   png_ptr->unknown_chunk.data = NULL;\n\n#else /* !PNG_READ_UNKNOWN_CHUNKS_SUPPORTED */\n   /* There is no support to read an unknown chunk, so just skip it. */\n   png_crc_finish(png_ptr, length);\n   PNG_UNUSED(info_ptr)\n   PNG_UNUSED(keep)\n#endif /* !READ_UNKNOWN_CHUNKS */\n\n   /* Check for unhandled critical chunks */\n   if (handled == 0 && PNG_CHUNK_CRITICAL(png_ptr->chunk_name))\n      png_chunk_error(png_ptr, \"unhandled critical chunk\");\n}\n\n/* This function is called to verify that a chunk name is valid.\n * This function can't have the \"critical chunk check\" incorporated\n * into it, since in the future we will need to be able to call user\n * functions to handle unknown critical chunks after we check that\n * the chunk name itself is valid.\n */\n\n/* Bit hacking: the test for an invalid byte in the 4 byte chunk name is:\n *\n * ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))\n */\n\nvoid /* PRIVATE */\npng_check_chunk_name(png_structrp png_ptr, png_uint_32 chunk_name)\n{\n   int i;\n\n   png_debug(1, \"in png_check_chunk_name\");\n\n   for (i=1; i<=4; ++i)\n   {\n      int c = chunk_name & 0xff;\n\n      if (c < 65 || c > 122 || (c > 90 && c < 97))\n         png_chunk_error(png_ptr, \"invalid chunk type\");\n\n      chunk_name >>= 8;\n   }\n}\n\n/* Combines the row recently read in with the existing pixels in the row.  This\n * routine takes care of alpha and transparency if requested.  This routine also\n * handles the two methods of progressive display of interlaced images,\n * depending on the 'display' value; if 'display' is true then the whole row\n * (dp) is filled from the start by replicating the available pixels.  If\n * 'display' is false only those pixels present in the pass are filled in.\n */\nvoid /* PRIVATE */\npng_combine_row(png_const_structrp png_ptr, png_bytep dp, int display)\n{\n   unsigned int pixel_depth = png_ptr->transformed_pixel_depth;\n   png_const_bytep sp = png_ptr->row_buf + 1;\n   png_alloc_size_t row_width = png_ptr->width;\n   unsigned int pass = png_ptr->pass;\n   png_bytep end_ptr = 0;\n   png_byte end_byte = 0;\n   unsigned int end_mask;\n\n   png_debug(1, \"in png_combine_row\");\n\n   /* Added in 1.5.6: it should not be possible to enter this routine until at\n    * least one row has been read from the PNG data and transformed.\n    */\n   if (pixel_depth == 0)\n      png_error(png_ptr, \"internal row logic error\");\n\n   /* Added in 1.5.4: the pixel depth should match the information returned by\n    * any call to png_read_update_info at this point.  Do not continue if we got\n    * this wrong.\n    */\n   if (png_ptr->info_rowbytes != 0 && png_ptr->info_rowbytes !=\n          PNG_ROWBYTES(pixel_depth, row_width))\n      png_error(png_ptr, \"internal row size calculation error\");\n\n   /* Don't expect this to ever happen: */\n   if (row_width == 0)\n      png_error(png_ptr, \"internal row width error\");\n\n   /* Preserve the last byte in cases where only part of it will be overwritten,\n    * the multiply below may overflow, we don't care because ANSI-C guarantees\n    * we get the low bits.\n    */\n   end_mask = (pixel_depth * row_width) & 7;\n   if (end_mask != 0)\n   {\n      /* end_ptr == NULL is a flag to say do nothing */\n      end_ptr = dp + PNG_ROWBYTES(pixel_depth, row_width) - 1;\n      end_byte = *end_ptr;\n#     ifdef PNG_READ_PACKSWAP_SUPPORTED\n      if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n         /* little-endian byte */\n         end_mask = 0xff << end_mask;\n\n      else /* big-endian byte */\n#     endif\n      end_mask = 0xff >> end_mask;\n      /* end_mask is now the bits to *keep* from the destination row */\n   }\n\n   /* For non-interlaced images this reduces to a memcpy(). A memcpy()\n    * will also happen if interlacing isn't supported or if the application\n    * does not call png_set_interlace_handling().  In the latter cases the\n    * caller just gets a sequence of the unexpanded rows from each interlace\n    * pass.\n    */\n#ifdef PNG_READ_INTERLACING_SUPPORTED\n   if (png_ptr->interlaced != 0 &&\n       (png_ptr->transformations & PNG_INTERLACE) != 0 &&\n       pass < 6 && (display == 0 ||\n       /* The following copies everything for 'display' on passes 0, 2 and 4. */\n       (display == 1 && (pass & 1) != 0)))\n   {\n      /* Narrow images may have no bits in a pass; the caller should handle\n       * this, but this test is cheap:\n       */\n      if (row_width <= PNG_PASS_START_COL(pass))\n         return;\n\n      if (pixel_depth < 8)\n      {\n         /* For pixel depths up to 4 bpp the 8-pixel mask can be expanded to fit\n          * into 32 bits, then a single loop over the bytes using the four byte\n          * values in the 32-bit mask can be used.  For the 'display' option the\n          * expanded mask may also not require any masking within a byte.  To\n          * make this work the PACKSWAP option must be taken into account - it\n          * simply requires the pixels to be reversed in each byte.\n          *\n          * The 'regular' case requires a mask for each of the first 6 passes,\n          * the 'display' case does a copy for the even passes in the range\n          * 0..6.  This has already been handled in the test above.\n          *\n          * The masks are arranged as four bytes with the first byte to use in\n          * the lowest bits (little-endian) regardless of the order (PACKSWAP or\n          * not) of the pixels in each byte.\n          *\n          * NOTE: the whole of this logic depends on the caller of this function\n          * only calling it on rows appropriate to the pass.  This function only\n          * understands the 'x' logic; the 'y' logic is handled by the caller.\n          *\n          * The following defines allow generation of compile time constant bit\n          * masks for each pixel depth and each possibility of swapped or not\n          * swapped bytes.  Pass 'p' is in the range 0..6; 'x', a pixel index,\n          * is in the range 0..7; and the result is 1 if the pixel is to be\n          * copied in the pass, 0 if not.  'S' is for the sparkle method, 'B'\n          * for the block method.\n          *\n          * With some compilers a compile time expression of the general form:\n          *\n          *    (shift >= 32) ? (a >> (shift-32)) : (b >> shift)\n          *\n          * Produces warnings with values of 'shift' in the range 33 to 63\n          * because the right hand side of the ?: expression is evaluated by\n          * the compiler even though it isn't used.  Microsoft Visual C (various\n          * versions) and the Intel C compiler are known to do this.  To avoid\n          * this the following macros are used in 1.5.6.  This is a temporary\n          * solution to avoid destabilizing the code during the release process.\n          */\n#        if PNG_USE_COMPILE_TIME_MASKS\n#           define PNG_LSR(x,s) ((x)>>((s) & 0x1f))\n#           define PNG_LSL(x,s) ((x)<<((s) & 0x1f))\n#        else\n#           define PNG_LSR(x,s) ((x)>>(s))\n#           define PNG_LSL(x,s) ((x)<<(s))\n#        endif\n#        define S_COPY(p,x) (((p)<4 ? PNG_LSR(0x80088822,(3-(p))*8+(7-(x))) :\\\n           PNG_LSR(0xaa55ff00,(7-(p))*8+(7-(x)))) & 1)\n#        define B_COPY(p,x) (((p)<4 ? PNG_LSR(0xff0fff33,(3-(p))*8+(7-(x))) :\\\n           PNG_LSR(0xff55ff00,(7-(p))*8+(7-(x)))) & 1)\n\n         /* Return a mask for pass 'p' pixel 'x' at depth 'd'.  The mask is\n          * little endian - the first pixel is at bit 0 - however the extra\n          * parameter 's' can be set to cause the mask position to be swapped\n          * within each byte, to match the PNG format.  This is done by XOR of\n          * the shift with 7, 6 or 4 for bit depths 1, 2 and 4.\n          */\n#        define PIXEL_MASK(p,x,d,s) \\\n            (PNG_LSL(((PNG_LSL(1U,(d)))-1),(((x)*(d))^((s)?8-(d):0))))\n\n         /* Hence generate the appropriate 'block' or 'sparkle' pixel copy mask.\n          */\n#        define S_MASKx(p,x,d,s) (S_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)\n#        define B_MASKx(p,x,d,s) (B_COPY(p,x)?PIXEL_MASK(p,x,d,s):0)\n\n         /* Combine 8 of these to get the full mask.  For the 1-bpp and 2-bpp\n          * cases the result needs replicating, for the 4-bpp case the above\n          * generates a full 32 bits.\n          */\n#        define MASK_EXPAND(m,d) ((m)*((d)==1?0x01010101:((d)==2?0x00010001:1)))\n\n#        define S_MASK(p,d,s) MASK_EXPAND(S_MASKx(p,0,d,s) + S_MASKx(p,1,d,s) +\\\n            S_MASKx(p,2,d,s) + S_MASKx(p,3,d,s) + S_MASKx(p,4,d,s) +\\\n            S_MASKx(p,5,d,s) + S_MASKx(p,6,d,s) + S_MASKx(p,7,d,s), d)\n\n#        define B_MASK(p,d,s) MASK_EXPAND(B_MASKx(p,0,d,s) + B_MASKx(p,1,d,s) +\\\n            B_MASKx(p,2,d,s) + B_MASKx(p,3,d,s) + B_MASKx(p,4,d,s) +\\\n            B_MASKx(p,5,d,s) + B_MASKx(p,6,d,s) + B_MASKx(p,7,d,s), d)\n\n#if PNG_USE_COMPILE_TIME_MASKS\n         /* Utility macros to construct all the masks for a depth/swap\n          * combination.  The 's' parameter says whether the format is PNG\n          * (big endian bytes) or not.  Only the three odd-numbered passes are\n          * required for the display/block algorithm.\n          */\n#        define S_MASKS(d,s) { S_MASK(0,d,s), S_MASK(1,d,s), S_MASK(2,d,s),\\\n            S_MASK(3,d,s), S_MASK(4,d,s), S_MASK(5,d,s) }\n\n#        define B_MASKS(d,s) { B_MASK(1,d,s), B_MASK(3,d,s), B_MASK(5,d,s) }\n\n#        define DEPTH_INDEX(d) ((d)==1?0:((d)==2?1:2))\n\n         /* Hence the pre-compiled masks indexed by PACKSWAP (or not), depth and\n          * then pass:\n          */\n         static PNG_CONST png_uint_32 row_mask[2/*PACKSWAP*/][3/*depth*/][6] =\n         {\n            /* Little-endian byte masks for PACKSWAP */\n            { S_MASKS(1,0), S_MASKS(2,0), S_MASKS(4,0) },\n            /* Normal (big-endian byte) masks - PNG format */\n            { S_MASKS(1,1), S_MASKS(2,1), S_MASKS(4,1) }\n         };\n\n         /* display_mask has only three entries for the odd passes, so index by\n          * pass>>1.\n          */\n         static PNG_CONST png_uint_32 display_mask[2][3][3] =\n         {\n            /* Little-endian byte masks for PACKSWAP */\n            { B_MASKS(1,0), B_MASKS(2,0), B_MASKS(4,0) },\n            /* Normal (big-endian byte) masks - PNG format */\n            { B_MASKS(1,1), B_MASKS(2,1), B_MASKS(4,1) }\n         };\n\n#        define MASK(pass,depth,display,png)\\\n            ((display)?display_mask[png][DEPTH_INDEX(depth)][pass>>1]:\\\n               row_mask[png][DEPTH_INDEX(depth)][pass])\n\n#else /* !PNG_USE_COMPILE_TIME_MASKS */\n         /* This is the runtime alternative: it seems unlikely that this will\n          * ever be either smaller or faster than the compile time approach.\n          */\n#        define MASK(pass,depth,display,png)\\\n            ((display)?B_MASK(pass,depth,png):S_MASK(pass,depth,png))\n#endif /* !USE_COMPILE_TIME_MASKS */\n\n         /* Use the appropriate mask to copy the required bits.  In some cases\n          * the byte mask will be 0 or 0xff; optimize these cases.  row_width is\n          * the number of pixels, but the code copies bytes, so it is necessary\n          * to special case the end.\n          */\n         png_uint_32 pixels_per_byte = 8 / pixel_depth;\n         png_uint_32 mask;\n\n#        ifdef PNG_READ_PACKSWAP_SUPPORTED\n         if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n            mask = MASK(pass, pixel_depth, display, 0);\n\n         else\n#        endif\n         mask = MASK(pass, pixel_depth, display, 1);\n\n         for (;;)\n         {\n            png_uint_32 m;\n\n            /* It doesn't matter in the following if png_uint_32 has more than\n             * 32 bits because the high bits always match those in m<<24; it is,\n             * however, essential to use OR here, not +, because of this.\n             */\n            m = mask;\n            mask = (m >> 8) | (m << 24); /* rotate right to good compilers */\n            m &= 0xff;\n\n            if (m != 0) /* something to copy */\n            {\n               if (m != 0xff)\n                  *dp = (png_byte)((*dp & ~m) | (*sp & m));\n               else\n                  *dp = *sp;\n            }\n\n            /* NOTE: this may overwrite the last byte with garbage if the image\n             * is not an exact number of bytes wide; libpng has always done\n             * this.\n             */\n            if (row_width <= pixels_per_byte)\n               break; /* May need to restore part of the last byte */\n\n            row_width -= pixels_per_byte;\n            ++dp;\n            ++sp;\n         }\n      }\n\n      else /* pixel_depth >= 8 */\n      {\n         unsigned int bytes_to_copy, bytes_to_jump;\n\n         /* Validate the depth - it must be a multiple of 8 */\n         if (pixel_depth & 7)\n            png_error(png_ptr, \"invalid user transform pixel depth\");\n\n         pixel_depth >>= 3; /* now in bytes */\n         row_width *= pixel_depth;\n\n         /* Regardless of pass number the Adam 7 interlace always results in a\n          * fixed number of pixels to copy then to skip.  There may be a\n          * different number of pixels to skip at the start though.\n          */\n         {\n            unsigned int offset = PNG_PASS_START_COL(pass) * pixel_depth;\n\n            row_width -= offset;\n            dp += offset;\n            sp += offset;\n         }\n\n         /* Work out the bytes to copy. */\n         if (display != 0)\n         {\n            /* When doing the 'block' algorithm the pixel in the pass gets\n             * replicated to adjacent pixels.  This is why the even (0,2,4,6)\n             * passes are skipped above - the entire expanded row is copied.\n             */\n            bytes_to_copy = (1<<((6-pass)>>1)) * pixel_depth;\n\n            /* But don't allow this number to exceed the actual row width. */\n            if (bytes_to_copy > row_width)\n               bytes_to_copy = (unsigned int)/*SAFE*/row_width;\n         }\n\n         else /* normal row; Adam7 only ever gives us one pixel to copy. */\n            bytes_to_copy = pixel_depth;\n\n         /* In Adam7 there is a constant offset between where the pixels go. */\n         bytes_to_jump = PNG_PASS_COL_OFFSET(pass) * pixel_depth;\n\n         /* And simply copy these bytes.  Some optimization is possible here,\n          * depending on the value of 'bytes_to_copy'.  Special case the low\n          * byte counts, which we know to be frequent.\n          *\n          * Notice that these cases all 'return' rather than 'break' - this\n          * avoids an unnecessary test on whether to restore the last byte\n          * below.\n          */\n         switch (bytes_to_copy)\n         {\n            case 1:\n               for (;;)\n               {\n                  *dp = *sp;\n\n                  if (row_width <= bytes_to_jump)\n                     return;\n\n                  dp += bytes_to_jump;\n                  sp += bytes_to_jump;\n                  row_width -= bytes_to_jump;\n               }\n\n            case 2:\n               /* There is a possibility of a partial copy at the end here; this\n                * slows the code down somewhat.\n                */\n               do\n               {\n                  dp[0] = sp[0], dp[1] = sp[1];\n\n                  if (row_width <= bytes_to_jump)\n                     return;\n\n                  sp += bytes_to_jump;\n                  dp += bytes_to_jump;\n                  row_width -= bytes_to_jump;\n               }\n               while (row_width > 1);\n\n               /* And there can only be one byte left at this point: */\n               *dp = *sp;\n               return;\n\n            case 3:\n               /* This can only be the RGB case, so each copy is exactly one\n                * pixel and it is not necessary to check for a partial copy.\n                */\n               for (;;)\n               {\n                  dp[0] = sp[0], dp[1] = sp[1], dp[2] = sp[2];\n\n                  if (row_width <= bytes_to_jump)\n                     return;\n\n                  sp += bytes_to_jump;\n                  dp += bytes_to_jump;\n                  row_width -= bytes_to_jump;\n               }\n\n            default:\n#if PNG_ALIGN_TYPE != PNG_ALIGN_NONE\n               /* Check for double byte alignment and, if possible, use a\n                * 16-bit copy.  Don't attempt this for narrow images - ones that\n                * are less than an interlace panel wide.  Don't attempt it for\n                * wide bytes_to_copy either - use the memcpy there.\n                */\n               if (bytes_to_copy < 16 /*else use memcpy*/ &&\n                   png_isaligned(dp, png_uint_16) &&\n                   png_isaligned(sp, png_uint_16) &&\n                   bytes_to_copy % (sizeof (png_uint_16)) == 0 &&\n                   bytes_to_jump % (sizeof (png_uint_16)) == 0)\n               {\n                  /* Everything is aligned for png_uint_16 copies, but try for\n                   * png_uint_32 first.\n                   */\n                  if (png_isaligned(dp, png_uint_32) &&\n                      png_isaligned(sp, png_uint_32) &&\n                      bytes_to_copy % (sizeof (png_uint_32)) == 0 &&\n                      bytes_to_jump % (sizeof (png_uint_32)) == 0)\n                  {\n                     png_uint_32p dp32 = png_aligncast(png_uint_32p,dp);\n                     png_const_uint_32p sp32 = png_aligncastconst(\n                         png_const_uint_32p, sp);\n                     size_t skip = (bytes_to_jump-bytes_to_copy) /\n                         (sizeof (png_uint_32));\n\n                     do\n                     {\n                        size_t c = bytes_to_copy;\n                        do\n                        {\n                           *dp32++ = *sp32++;\n                           c -= (sizeof (png_uint_32));\n                        }\n                        while (c > 0);\n\n                        if (row_width <= bytes_to_jump)\n                           return;\n\n                        dp32 += skip;\n                        sp32 += skip;\n                        row_width -= bytes_to_jump;\n                     }\n                     while (bytes_to_copy <= row_width);\n\n                     /* Get to here when the row_width truncates the final copy.\n                      * There will be 1-3 bytes left to copy, so don't try the\n                      * 16-bit loop below.\n                      */\n                     dp = (png_bytep)dp32;\n                     sp = (png_const_bytep)sp32;\n                     do\n                        *dp++ = *sp++;\n                     while (--row_width > 0);\n                     return;\n                  }\n\n                  /* Else do it in 16-bit quantities, but only if the size is\n                   * not too large.\n                   */\n                  else\n                  {\n                     png_uint_16p dp16 = png_aligncast(png_uint_16p, dp);\n                     png_const_uint_16p sp16 = png_aligncastconst(\n                        png_const_uint_16p, sp);\n                     size_t skip = (bytes_to_jump-bytes_to_copy) /\n                        (sizeof (png_uint_16));\n\n                     do\n                     {\n                        size_t c = bytes_to_copy;\n                        do\n                        {\n                           *dp16++ = *sp16++;\n                           c -= (sizeof (png_uint_16));\n                        }\n                        while (c > 0);\n\n                        if (row_width <= bytes_to_jump)\n                           return;\n\n                        dp16 += skip;\n                        sp16 += skip;\n                        row_width -= bytes_to_jump;\n                     }\n                     while (bytes_to_copy <= row_width);\n\n                     /* End of row - 1 byte left, bytes_to_copy > row_width: */\n                     dp = (png_bytep)dp16;\n                     sp = (png_const_bytep)sp16;\n                     do\n                        *dp++ = *sp++;\n                     while (--row_width > 0);\n                     return;\n                  }\n               }\n#endif /* ALIGN_TYPE code */\n\n               /* The true default - use a memcpy: */\n               for (;;)\n               {\n                  memcpy(dp, sp, bytes_to_copy);\n\n                  if (row_width <= bytes_to_jump)\n                     return;\n\n                  sp += bytes_to_jump;\n                  dp += bytes_to_jump;\n                  row_width -= bytes_to_jump;\n                  if (bytes_to_copy > row_width)\n                     bytes_to_copy = (unsigned int)/*SAFE*/row_width;\n               }\n         }\n\n         /* NOT REACHED*/\n      } /* pixel_depth >= 8 */\n\n      /* Here if pixel_depth < 8 to check 'end_ptr' below. */\n   }\n   else\n#endif /* READ_INTERLACING */\n\n   /* If here then the switch above wasn't used so just memcpy the whole row\n    * from the temporary row buffer (notice that this overwrites the end of the\n    * destination row if it is a partial byte.)\n    */\n   memcpy(dp, sp, PNG_ROWBYTES(pixel_depth, row_width));\n\n   /* Restore the overwritten bits from the last byte if necessary. */\n   if (end_ptr != NULL)\n      *end_ptr = (png_byte)((end_byte & end_mask) | (*end_ptr & ~end_mask));\n}\n\n#ifdef PNG_READ_INTERLACING_SUPPORTED\nvoid /* PRIVATE */\npng_do_read_interlace(png_row_infop row_info, png_bytep row, int pass,\n    png_uint_32 transformations /* Because these may affect the byte layout */)\n{\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n   /* Offset to next interlace block */\n   static PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   png_debug(1, \"in png_do_read_interlace\");\n   if (row != NULL && row_info != NULL)\n   {\n      png_uint_32 final_width;\n\n      final_width = row_info->width * png_pass_inc[pass];\n\n      switch (row_info->pixel_depth)\n      {\n         case 1:\n         {\n            png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);\n            png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);\n            int sshift, dshift;\n            int s_start, s_end, s_inc;\n            int jstop = png_pass_inc[pass];\n            png_byte v;\n            png_uint_32 i;\n            int j;\n\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n            if ((transformations & PNG_PACKSWAP) != 0)\n            {\n                sshift = (int)((row_info->width + 7) & 0x07);\n                dshift = (int)((final_width + 7) & 0x07);\n                s_start = 7;\n                s_end = 0;\n                s_inc = -1;\n            }\n\n            else\n#endif\n            {\n                sshift = 7 - (int)((row_info->width + 7) & 0x07);\n                dshift = 7 - (int)((final_width + 7) & 0x07);\n                s_start = 0;\n                s_end = 7;\n                s_inc = 1;\n            }\n\n            for (i = 0; i < row_info->width; i++)\n            {\n               v = (png_byte)((*sp >> sshift) & 0x01);\n               for (j = 0; j < jstop; j++)\n               {\n                  unsigned int tmp = *dp & (0x7f7f >> (7 - dshift));\n                  tmp |= v << dshift;\n                  *dp = (png_byte)(tmp & 0xff);\n\n                  if (dshift == s_end)\n                  {\n                     dshift = s_start;\n                     dp--;\n                  }\n\n                  else\n                     dshift += s_inc;\n               }\n\n               if (sshift == s_end)\n               {\n                  sshift = s_start;\n                  sp--;\n               }\n\n               else\n                  sshift += s_inc;\n            }\n            break;\n         }\n\n         case 2:\n         {\n            png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);\n            png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);\n            int sshift, dshift;\n            int s_start, s_end, s_inc;\n            int jstop = png_pass_inc[pass];\n            png_uint_32 i;\n\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n            if ((transformations & PNG_PACKSWAP) != 0)\n            {\n               sshift = (int)(((row_info->width + 3) & 0x03) << 1);\n               dshift = (int)(((final_width + 3) & 0x03) << 1);\n               s_start = 6;\n               s_end = 0;\n               s_inc = -2;\n            }\n\n            else\n#endif\n            {\n               sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);\n               dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);\n               s_start = 0;\n               s_end = 6;\n               s_inc = 2;\n            }\n\n            for (i = 0; i < row_info->width; i++)\n            {\n               png_byte v;\n               int j;\n\n               v = (png_byte)((*sp >> sshift) & 0x03);\n               for (j = 0; j < jstop; j++)\n               {\n                  unsigned int tmp = *dp & (0x3f3f >> (6 - dshift));\n                  tmp |= v << dshift;\n                  *dp = (png_byte)(tmp & 0xff);\n\n                  if (dshift == s_end)\n                  {\n                     dshift = s_start;\n                     dp--;\n                  }\n\n                  else\n                     dshift += s_inc;\n               }\n\n               if (sshift == s_end)\n               {\n                  sshift = s_start;\n                  sp--;\n               }\n\n               else\n                  sshift += s_inc;\n            }\n            break;\n         }\n\n         case 4:\n         {\n            png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);\n            png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);\n            int sshift, dshift;\n            int s_start, s_end, s_inc;\n            png_uint_32 i;\n            int jstop = png_pass_inc[pass];\n\n#ifdef PNG_READ_PACKSWAP_SUPPORTED\n            if ((transformations & PNG_PACKSWAP) != 0)\n            {\n               sshift = (int)(((row_info->width + 1) & 0x01) << 2);\n               dshift = (int)(((final_width + 1) & 0x01) << 2);\n               s_start = 4;\n               s_end = 0;\n               s_inc = -4;\n            }\n\n            else\n#endif\n            {\n               sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);\n               dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);\n               s_start = 0;\n               s_end = 4;\n               s_inc = 4;\n            }\n\n            for (i = 0; i < row_info->width; i++)\n            {\n               png_byte v = (png_byte)((*sp >> sshift) & 0x0f);\n               int j;\n\n               for (j = 0; j < jstop; j++)\n               {\n                  unsigned int tmp = *dp & (0xf0f >> (4 - dshift));\n                  tmp |= v << dshift;\n                  *dp = (png_byte)(tmp & 0xff);\n\n                  if (dshift == s_end)\n                  {\n                     dshift = s_start;\n                     dp--;\n                  }\n\n                  else\n                     dshift += s_inc;\n               }\n\n               if (sshift == s_end)\n               {\n                  sshift = s_start;\n                  sp--;\n               }\n\n               else\n                  sshift += s_inc;\n            }\n            break;\n         }\n\n         default:\n         {\n            png_size_t pixel_bytes = (row_info->pixel_depth >> 3);\n\n            png_bytep sp = row + (png_size_t)(row_info->width - 1)\n                * pixel_bytes;\n\n            png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;\n\n            int jstop = png_pass_inc[pass];\n            png_uint_32 i;\n\n            for (i = 0; i < row_info->width; i++)\n            {\n               png_byte v[8]; /* SAFE; pixel_depth does not exceed 64 */\n               int j;\n\n               memcpy(v, sp, pixel_bytes);\n\n               for (j = 0; j < jstop; j++)\n               {\n                  memcpy(dp, v, pixel_bytes);\n                  dp -= pixel_bytes;\n               }\n\n               sp -= pixel_bytes;\n            }\n            break;\n         }\n      }\n\n      row_info->width = final_width;\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth, final_width);\n   }\n#ifndef PNG_READ_PACKSWAP_SUPPORTED\n   PNG_UNUSED(transformations)  /* Silence compiler warning */\n#endif\n}\n#endif /* READ_INTERLACING */\n\nstatic void\npng_read_filter_row_sub(png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row)\n{\n   png_size_t i;\n   png_size_t istop = row_info->rowbytes;\n   unsigned int bpp = (row_info->pixel_depth + 7) >> 3;\n   png_bytep rp = row + bpp;\n\n   PNG_UNUSED(prev_row)\n\n   for (i = bpp; i < istop; i++)\n   {\n      *rp = (png_byte)(((int)(*rp) + (int)(*(rp-bpp))) & 0xff);\n      rp++;\n   }\n}\n\nstatic void\npng_read_filter_row_up(png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row)\n{\n   png_size_t i;\n   png_size_t istop = row_info->rowbytes;\n   png_bytep rp = row;\n   png_const_bytep pp = prev_row;\n\n   for (i = 0; i < istop; i++)\n   {\n      *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);\n      rp++;\n   }\n}\n\nstatic void\npng_read_filter_row_avg(png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row)\n{\n   png_size_t i;\n   png_bytep rp = row;\n   png_const_bytep pp = prev_row;\n   unsigned int bpp = (row_info->pixel_depth + 7) >> 3;\n   png_size_t istop = row_info->rowbytes - bpp;\n\n   for (i = 0; i < bpp; i++)\n   {\n      *rp = (png_byte)(((int)(*rp) +\n         ((int)(*pp++) / 2 )) & 0xff);\n\n      rp++;\n   }\n\n   for (i = 0; i < istop; i++)\n   {\n      *rp = (png_byte)(((int)(*rp) +\n         (int)(*pp++ + *(rp-bpp)) / 2 ) & 0xff);\n\n      rp++;\n   }\n}\n\nstatic void\npng_read_filter_row_paeth_1byte_pixel(png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row)\n{\n   png_bytep rp_end = row + row_info->rowbytes;\n   int a, c;\n\n   /* First pixel/byte */\n   c = *prev_row++;\n   a = *row + c;\n   *row++ = (png_byte)a;\n\n   /* Remainder */\n   while (row < rp_end)\n   {\n      int b, pa, pb, pc, p;\n\n      a &= 0xff; /* From previous iteration or start */\n      b = *prev_row++;\n\n      p = b - c;\n      pc = a - c;\n\n#ifdef PNG_USE_ABS\n      pa = abs(p);\n      pb = abs(pc);\n      pc = abs(p + pc);\n#else\n      pa = p < 0 ? -p : p;\n      pb = pc < 0 ? -pc : pc;\n      pc = (p + pc) < 0 ? -(p + pc) : p + pc;\n#endif\n\n      /* Find the best predictor, the least of pa, pb, pc favoring the earlier\n       * ones in the case of a tie.\n       */\n      if (pb < pa) pa = pb, a = b;\n      if (pc < pa) a = c;\n\n      /* Calculate the current pixel in a, and move the previous row pixel to c\n       * for the next time round the loop\n       */\n      c = b;\n      a += *row;\n      *row++ = (png_byte)a;\n   }\n}\n\nstatic void\npng_read_filter_row_paeth_multibyte_pixel(png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row)\n{\n   int bpp = (row_info->pixel_depth + 7) >> 3;\n   png_bytep rp_end = row + bpp;\n\n   /* Process the first pixel in the row completely (this is the same as 'up'\n    * because there is only one candidate predictor for the first row).\n    */\n   while (row < rp_end)\n   {\n      int a = *row + *prev_row++;\n      *row++ = (png_byte)a;\n   }\n\n   /* Remainder */\n   rp_end += row_info->rowbytes - bpp;\n\n   while (row < rp_end)\n   {\n      int a, b, c, pa, pb, pc, p;\n\n      c = *(prev_row - bpp);\n      a = *(row - bpp);\n      b = *prev_row++;\n\n      p = b - c;\n      pc = a - c;\n\n#ifdef PNG_USE_ABS\n      pa = abs(p);\n      pb = abs(pc);\n      pc = abs(p + pc);\n#else\n      pa = p < 0 ? -p : p;\n      pb = pc < 0 ? -pc : pc;\n      pc = (p + pc) < 0 ? -(p + pc) : p + pc;\n#endif\n\n      if (pb < pa) pa = pb, a = b;\n      if (pc < pa) a = c;\n\n      a += *row;\n      *row++ = (png_byte)a;\n   }\n}\n\nstatic void\npng_init_filter_functions(png_structrp pp)\n   /* This function is called once for every PNG image (except for PNG images\n    * that only use PNG_FILTER_VALUE_NONE for all rows) to set the\n    * implementations required to reverse the filtering of PNG rows.  Reversing\n    * the filter is the first transformation performed on the row data.  It is\n    * performed in place, therefore an implementation can be selected based on\n    * the image pixel format.  If the implementation depends on image width then\n    * take care to ensure that it works correctly if the image is interlaced -\n    * interlacing causes the actual row width to vary.\n    */\n{\n   unsigned int bpp = (pp->pixel_depth + 7) >> 3;\n\n   pp->read_filter[PNG_FILTER_VALUE_SUB-1] = png_read_filter_row_sub;\n   pp->read_filter[PNG_FILTER_VALUE_UP-1] = png_read_filter_row_up;\n   pp->read_filter[PNG_FILTER_VALUE_AVG-1] = png_read_filter_row_avg;\n   if (bpp == 1)\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n         png_read_filter_row_paeth_1byte_pixel;\n   else\n      pp->read_filter[PNG_FILTER_VALUE_PAETH-1] =\n         png_read_filter_row_paeth_multibyte_pixel;\n\n#ifdef PNG_FILTER_OPTIMIZATIONS\n   /* To use this define PNG_FILTER_OPTIMIZATIONS as the name of a function to\n    * call to install hardware optimizations for the above functions; simply\n    * replace whatever elements of the pp->read_filter[] array with a hardware\n    * specific (or, for that matter, generic) optimization.\n    *\n    * To see an example of this examine what configure.ac does when\n    * --enable-arm-neon is specified on the command line.\n    */\n   PNG_FILTER_OPTIMIZATIONS(pp, bpp);\n#endif\n}\n\nvoid /* PRIVATE */\npng_read_filter_row(png_structrp pp, png_row_infop row_info, png_bytep row,\n    png_const_bytep prev_row, int filter)\n{\n   /* OPTIMIZATION: DO NOT MODIFY THIS FUNCTION, instead #define\n    * PNG_FILTER_OPTIMIZATIONS to a function that overrides the generic\n    * implementations.  See png_init_filter_functions above.\n    */\n   if (filter > PNG_FILTER_VALUE_NONE && filter < PNG_FILTER_VALUE_LAST)\n   {\n      if (pp->read_filter[0] == NULL)\n         png_init_filter_functions(pp);\n\n      pp->read_filter[filter-1](row_info, row, prev_row);\n   }\n}\n\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\nvoid /* PRIVATE */\npng_read_IDAT_data(png_structrp png_ptr, png_bytep output,\n    png_alloc_size_t avail_out)\n{\n   /* Loop reading IDATs and decompressing the result into output[avail_out] */\n   png_ptr->zstream.next_out = output;\n   png_ptr->zstream.avail_out = 0; /* safety: set below */\n\n   if (output == NULL)\n      avail_out = 0;\n\n   do\n   {\n      int ret;\n      png_byte tmpbuf[PNG_INFLATE_BUF_SIZE];\n\n      if (png_ptr->zstream.avail_in == 0)\n      {\n         uInt avail_in;\n         png_bytep buffer;\n\n         while (png_ptr->idat_size == 0)\n         {\n            png_crc_finish(png_ptr, 0);\n\n            png_ptr->idat_size = png_read_chunk_header(png_ptr);\n            /* This is an error even in the 'check' case because the code just\n             * consumed a non-IDAT header.\n             */\n            if (png_ptr->chunk_name != png_IDAT)\n               png_error(png_ptr, \"Not enough image data\");\n         }\n\n         avail_in = png_ptr->IDAT_read_size;\n\n         if (avail_in > png_ptr->idat_size)\n            avail_in = (uInt)png_ptr->idat_size;\n\n         /* A PNG with a gradually increasing IDAT size will defeat this attempt\n          * to minimize memory usage by causing lots of re-allocs, but\n          * realistically doing IDAT_read_size re-allocs is not likely to be a\n          * big problem.\n          */\n         buffer = png_read_buffer(png_ptr, avail_in, 0/*error*/);\n\n         png_crc_read(png_ptr, buffer, avail_in);\n         png_ptr->idat_size -= avail_in;\n\n         png_ptr->zstream.next_in = buffer;\n         png_ptr->zstream.avail_in = avail_in;\n      }\n\n      /* And set up the output side. */\n      if (output != NULL) /* standard read */\n      {\n         uInt out = ZLIB_IO_MAX;\n\n         if (out > avail_out)\n            out = (uInt)avail_out;\n\n         avail_out -= out;\n         png_ptr->zstream.avail_out = out;\n      }\n\n      else /* after last row, checking for end */\n      {\n         png_ptr->zstream.next_out = tmpbuf;\n         png_ptr->zstream.avail_out = (sizeof tmpbuf);\n      }\n\n      /* Use NO_FLUSH; this gives zlib the maximum opportunity to optimize the\n       * process.  If the LZ stream is truncated the sequential reader will\n       * terminally damage the stream, above, by reading the chunk header of the\n       * following chunk (it then exits with png_error).\n       *\n       * TODO: deal more elegantly with truncated IDAT lists.\n       */\n      ret = PNG_INFLATE(png_ptr, Z_NO_FLUSH);\n\n      /* Take the unconsumed output back. */\n      if (output != NULL)\n         avail_out += png_ptr->zstream.avail_out;\n\n      else /* avail_out counts the extra bytes */\n         avail_out += (sizeof tmpbuf) - png_ptr->zstream.avail_out;\n\n      png_ptr->zstream.avail_out = 0;\n\n      if (ret == Z_STREAM_END)\n      {\n         /* Do this for safety; we won't read any more into this row. */\n         png_ptr->zstream.next_out = NULL;\n\n         png_ptr->mode |= PNG_AFTER_IDAT;\n         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;\n\n         if (png_ptr->zstream.avail_in > 0 || png_ptr->idat_size > 0)\n            png_chunk_benign_error(png_ptr, \"Extra compressed data\");\n         break;\n      }\n\n      if (ret != Z_OK)\n      {\n         png_zstream_error(png_ptr, ret);\n\n         if (output != NULL)\n         {\n            if(!strncmp(png_ptr->zstream.msg,\"incorrect data check\",20))\n            {\n               png_chunk_benign_error(png_ptr, \"ADLER32 checksum mismatch\");\n               continue;\n            }\n            else\n               png_chunk_error(png_ptr, png_ptr->zstream.msg);\n         }\n\n         else /* checking */\n         {\n            png_chunk_benign_error(png_ptr, png_ptr->zstream.msg);\n            return;\n         }\n      }\n   } while (avail_out > 0);\n\n   if (avail_out > 0)\n   {\n      /* The stream ended before the image; this is the same as too few IDATs so\n       * should be handled the same way.\n       */\n      if (output != NULL)\n         png_error(png_ptr, \"Not enough image data\");\n\n      else /* the deflate stream contained extra data */\n         png_chunk_benign_error(png_ptr, \"Too much image data\");\n   }\n}\n\nvoid /* PRIVATE */\npng_read_finish_IDAT(png_structrp png_ptr)\n{\n   /* We don't need any more data and the stream should have ended, however the\n    * LZ end code may actually not have been processed.  In this case we must\n    * read it otherwise stray unread IDAT data or, more likely, an IDAT chunk\n    * may still remain to be consumed.\n    */\n   if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)\n   {\n      /* The NULL causes png_read_IDAT_data to swallow any remaining bytes in\n       * the compressed stream, but the stream may be damaged too, so even after\n       * this call we may need to terminate the zstream ownership.\n       */\n      png_read_IDAT_data(png_ptr, NULL, 0);\n      png_ptr->zstream.next_out = NULL; /* safety */\n\n      /* Now clear everything out for safety; the following may not have been\n       * done.\n       */\n      if ((png_ptr->flags & PNG_FLAG_ZSTREAM_ENDED) == 0)\n      {\n         png_ptr->mode |= PNG_AFTER_IDAT;\n         png_ptr->flags |= PNG_FLAG_ZSTREAM_ENDED;\n      }\n   }\n\n   /* If the zstream has not been released do it now *and* terminate the reading\n    * of the final IDAT chunk.\n    */\n   if (png_ptr->zowner == png_IDAT)\n   {\n      /* Always do this; the pointers otherwise point into the read buffer. */\n      png_ptr->zstream.next_in = NULL;\n      png_ptr->zstream.avail_in = 0;\n\n      /* Now we no longer own the zstream. */\n      png_ptr->zowner = 0;\n\n      /* The slightly weird semantics of the sequential IDAT reading is that we\n       * are always in or at the end of an IDAT chunk, so we always need to do a\n       * crc_finish here.  If idat_size is non-zero we also need to read the\n       * spurious bytes at the end of the chunk now.\n       */\n      (void)png_crc_finish(png_ptr, png_ptr->idat_size);\n   }\n}\n\nvoid /* PRIVATE */\npng_read_finish_row(png_structrp png_ptr)\n{\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   /* Start of interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\n\n   /* Offset to next interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\n\n   png_debug(1, \"in png_read_finish_row\");\n   png_ptr->row_number++;\n   if (png_ptr->row_number < png_ptr->num_rows)\n      return;\n\n   if (png_ptr->interlaced != 0)\n   {\n      png_ptr->row_number = 0;\n\n      /* TO DO: don't do this if prev_row isn't needed (requires\n       * read-ahead of the next row's filter byte.\n       */\n      memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);\n\n      do\n      {\n         png_ptr->pass++;\n\n         if (png_ptr->pass >= 7)\n            break;\n\n         png_ptr->iwidth = (png_ptr->width +\n            png_pass_inc[png_ptr->pass] - 1 -\n            png_pass_start[png_ptr->pass]) /\n            png_pass_inc[png_ptr->pass];\n\n         if ((png_ptr->transformations & PNG_INTERLACE) == 0)\n         {\n            png_ptr->num_rows = (png_ptr->height +\n                png_pass_yinc[png_ptr->pass] - 1 -\n                png_pass_ystart[png_ptr->pass]) /\n                png_pass_yinc[png_ptr->pass];\n         }\n\n         else  /* if (png_ptr->transformations & PNG_INTERLACE) */\n            break; /* libpng deinterlacing sees every row */\n\n      } while (png_ptr->num_rows == 0 || png_ptr->iwidth == 0);\n\n      if (png_ptr->pass < 7)\n         return;\n   }\n\n   /* Here after at the end of the last row of the last pass. */\n   png_read_finish_IDAT(png_ptr);\n}\n#endif /* SEQUENTIAL_READ */\n\nvoid /* PRIVATE */\npng_read_start_row(png_structrp png_ptr)\n{\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   /* Start of interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\n\n   /* Offset to next interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\n\n   int max_pixel_depth;\n   png_size_t row_bytes;\n\n   png_debug(1, \"in png_read_start_row\");\n\n#ifdef PNG_READ_TRANSFORMS_SUPPORTED\n   png_init_read_transformations(png_ptr);\n#endif\n   if (png_ptr->interlaced != 0)\n   {\n      if ((png_ptr->transformations & PNG_INTERLACE) == 0)\n         png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -\n             png_pass_ystart[0]) / png_pass_yinc[0];\n\n      else\n         png_ptr->num_rows = png_ptr->height;\n\n      png_ptr->iwidth = (png_ptr->width +\n          png_pass_inc[png_ptr->pass] - 1 -\n          png_pass_start[png_ptr->pass]) /\n          png_pass_inc[png_ptr->pass];\n   }\n\n   else\n   {\n      png_ptr->num_rows = png_ptr->height;\n      png_ptr->iwidth = png_ptr->width;\n   }\n\n   max_pixel_depth = png_ptr->pixel_depth;\n\n   /* WARNING: * png_read_transform_info (pngrtran.c) performs a simpler set of\n    * calculations to calculate the final pixel depth, then\n    * png_do_read_transforms actually does the transforms.  This means that the\n    * code which effectively calculates this value is actually repeated in three\n    * separate places.  They must all match.  Innocent changes to the order of\n    * transformations can and will break libpng in a way that causes memory\n    * overwrites.\n    *\n    * TODO: fix this.\n    */\n#ifdef PNG_READ_PACK_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACK) != 0 && png_ptr->bit_depth < 8)\n      max_pixel_depth = 8;\n#endif\n\n#ifdef PNG_READ_EXPAND_SUPPORTED\n   if ((png_ptr->transformations & PNG_EXPAND) != 0)\n   {\n      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         if (png_ptr->num_trans != 0)\n            max_pixel_depth = 32;\n\n         else\n            max_pixel_depth = 24;\n      }\n\n      else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)\n      {\n         if (max_pixel_depth < 8)\n            max_pixel_depth = 8;\n\n         if (png_ptr->num_trans != 0)\n            max_pixel_depth *= 2;\n      }\n\n      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)\n      {\n         if (png_ptr->num_trans != 0)\n         {\n            max_pixel_depth *= 4;\n            max_pixel_depth /= 3;\n         }\n      }\n   }\n#endif\n\n#ifdef PNG_READ_EXPAND_16_SUPPORTED\n   if ((png_ptr->transformations & PNG_EXPAND_16) != 0)\n   {\n#  ifdef PNG_READ_EXPAND_SUPPORTED\n      /* In fact it is an error if it isn't supported, but checking is\n       * the safe way.\n       */\n      if ((png_ptr->transformations & PNG_EXPAND) != 0)\n      {\n         if (png_ptr->bit_depth < 16)\n            max_pixel_depth *= 2;\n      }\n      else\n#  endif\n      png_ptr->transformations &= ~PNG_EXPAND_16;\n   }\n#endif\n\n#ifdef PNG_READ_FILLER_SUPPORTED\n   if ((png_ptr->transformations & (PNG_FILLER)) != 0)\n   {\n      if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)\n      {\n         if (max_pixel_depth <= 8)\n            max_pixel_depth = 16;\n\n         else\n            max_pixel_depth = 32;\n      }\n\n      else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB ||\n         png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         if (max_pixel_depth <= 32)\n            max_pixel_depth = 32;\n\n         else\n            max_pixel_depth = 64;\n      }\n   }\n#endif\n\n#ifdef PNG_READ_GRAY_TO_RGB_SUPPORTED\n   if ((png_ptr->transformations & PNG_GRAY_TO_RGB) != 0)\n   {\n      if (\n#ifdef PNG_READ_EXPAND_SUPPORTED\n          (png_ptr->num_trans != 0 &&\n          (png_ptr->transformations & PNG_EXPAND) != 0) ||\n#endif\n#ifdef PNG_READ_FILLER_SUPPORTED\n          (png_ptr->transformations & (PNG_FILLER)) != 0 ||\n#endif\n          png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      {\n         if (max_pixel_depth <= 16)\n            max_pixel_depth = 32;\n\n         else\n            max_pixel_depth = 64;\n      }\n\n      else\n      {\n         if (max_pixel_depth <= 8)\n         {\n            if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n               max_pixel_depth = 32;\n\n            else\n               max_pixel_depth = 24;\n         }\n\n         else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n            max_pixel_depth = 64;\n\n         else\n            max_pixel_depth = 48;\n      }\n   }\n#endif\n\n#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \\\ndefined(PNG_USER_TRANSFORM_PTR_SUPPORTED)\n   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)\n   {\n      int user_pixel_depth = png_ptr->user_transform_depth *\n         png_ptr->user_transform_channels;\n\n      if (user_pixel_depth > max_pixel_depth)\n         max_pixel_depth = user_pixel_depth;\n   }\n#endif\n\n   /* This value is stored in png_struct and double checked in the row read\n    * code.\n    */\n   png_ptr->maximum_pixel_depth = (png_byte)max_pixel_depth;\n   png_ptr->transformed_pixel_depth = 0; /* calculated on demand */\n\n   /* Align the width on the next larger 8 pixels.  Mainly used\n    * for interlacing\n    */\n   row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));\n   /* Calculate the maximum bytes needed, adding a byte and a pixel\n    * for safety's sake\n    */\n   row_bytes = PNG_ROWBYTES(max_pixel_depth, row_bytes) +\n       1 + ((max_pixel_depth + 7) >> 3);\n\n#ifdef PNG_MAX_MALLOC_64K\n   if (row_bytes > (png_uint_32)65536L)\n      png_error(png_ptr, \"This image requires a row greater than 64KB\");\n#endif\n\n   if (row_bytes + 48 > png_ptr->old_big_row_buf_size)\n   {\n      png_free(png_ptr, png_ptr->big_row_buf);\n      png_free(png_ptr, png_ptr->big_prev_row);\n\n      if (png_ptr->interlaced != 0)\n         png_ptr->big_row_buf = (png_bytep)png_calloc(png_ptr,\n             row_bytes + 48);\n\n      else\n         png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\n\n      png_ptr->big_prev_row = (png_bytep)png_malloc(png_ptr, row_bytes + 48);\n\n#ifdef PNG_ALIGNED_MEMORY_SUPPORTED\n      /* Use 16-byte aligned memory for row_buf with at least 16 bytes\n       * of padding before and after row_buf; treat prev_row similarly.\n       * NOTE: the alignment is to the start of the pixels, one beyond the start\n       * of the buffer, because of the filter byte.  Prior to libpng 1.5.6 this\n       * was incorrect; the filter byte was aligned, which had the exact\n       * opposite effect of that intended.\n       */\n      {\n         png_bytep temp = png_ptr->big_row_buf + 32;\n         int extra = (int)((temp - (png_bytep)0) & 0x0f);\n         png_ptr->row_buf = temp - extra - 1/*filter byte*/;\n\n         temp = png_ptr->big_prev_row + 32;\n         extra = (int)((temp - (png_bytep)0) & 0x0f);\n         png_ptr->prev_row = temp - extra - 1/*filter byte*/;\n      }\n\n#else\n      /* Use 31 bytes of padding before and 17 bytes after row_buf. */\n      png_ptr->row_buf = png_ptr->big_row_buf + 31;\n      png_ptr->prev_row = png_ptr->big_prev_row + 31;\n#endif\n      png_ptr->old_big_row_buf_size = row_bytes + 48;\n   }\n\n#ifdef PNG_MAX_MALLOC_64K\n   if (png_ptr->rowbytes > 65535)\n      png_error(png_ptr, \"This image requires a row greater than 64KB\");\n\n#endif\n   if (png_ptr->rowbytes > (PNG_SIZE_MAX - 1))\n      png_error(png_ptr, \"Row has too many bytes to allocate in memory\");\n\n   memset(png_ptr->prev_row, 0, png_ptr->rowbytes + 1);\n\n   png_debug1(3, \"width = %u,\", png_ptr->width);\n   png_debug1(3, \"height = %u,\", png_ptr->height);\n   png_debug1(3, \"iwidth = %u,\", png_ptr->iwidth);\n   png_debug1(3, \"num_rows = %u,\", png_ptr->num_rows);\n   png_debug1(3, \"rowbytes = %lu,\", (unsigned long)png_ptr->rowbytes);\n   png_debug1(3, \"irowbytes = %lu\",\n       (unsigned long)PNG_ROWBYTES(png_ptr->pixel_depth, png_ptr->iwidth) + 1);\n\n   /* The sequential reader needs a buffer for IDAT, but the progressive reader\n    * does not, so free the read buffer now regardless; the sequential reader\n    * reallocates it on demand.\n    */\n   if (png_ptr->read_buffer != 0)\n   {\n      png_bytep buffer = png_ptr->read_buffer;\n\n      png_ptr->read_buffer_size = 0;\n      png_ptr->read_buffer = NULL;\n      png_free(png_ptr, buffer);\n   }\n\n   /* Finally claim the zstream for the inflate of the IDAT data, use the bits\n    * value from the stream (note that this will result in a fatal error if the\n    * IDAT stream has a bogus deflate header window_bits value, but this should\n    * not be happening any longer!)\n    */\n   if (png_inflate_claim(png_ptr, png_IDAT) != Z_OK)\n      png_error(png_ptr, png_ptr->zstream.msg);\n\n   png_ptr->flags |= PNG_FLAG_ROW_INIT;\n}\n#endif /* READ */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngset.c",
    "content": "\n/* pngset.c - storage of image information into info struct\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * The functions here are used during reads to store data from the file\n * into the info struct, and during writes to store application data\n * into the info struct for writing into the file.  This abstracts the\n * info struct and allows us to change the structure in the future.\n */\n\n#include \"pngpriv.h\"\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n\n#ifdef PNG_bKGD_SUPPORTED\nvoid PNGAPI\npng_set_bKGD(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_color_16p background)\n{\n   png_debug1(1, \"in %s storage function\", \"bKGD\");\n\n   if (png_ptr == NULL || info_ptr == NULL || background == NULL)\n      return;\n\n   info_ptr->background = *background;\n   info_ptr->valid |= PNG_INFO_bKGD;\n}\n#endif\n\n#ifdef PNG_cHRM_SUPPORTED\nvoid PNGFAPI\npng_set_cHRM_fixed(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,\n    png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,\n    png_fixed_point blue_x, png_fixed_point blue_y)\n{\n   png_xy xy;\n\n   png_debug1(1, \"in %s storage function\", \"cHRM fixed\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   xy.redx = red_x;\n   xy.redy = red_y;\n   xy.greenx = green_x;\n   xy.greeny = green_y;\n   xy.bluex = blue_x;\n   xy.bluey = blue_y;\n   xy.whitex = white_x;\n   xy.whitey = white_y;\n\n   if (png_colorspace_set_chromaticities(png_ptr, &info_ptr->colorspace, &xy,\n       2/* override with app values*/) != 0)\n      info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;\n\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n\nvoid PNGFAPI\npng_set_cHRM_XYZ_fixed(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_fixed_point int_red_X, png_fixed_point int_red_Y,\n    png_fixed_point int_red_Z, png_fixed_point int_green_X,\n    png_fixed_point int_green_Y, png_fixed_point int_green_Z,\n    png_fixed_point int_blue_X, png_fixed_point int_blue_Y,\n    png_fixed_point int_blue_Z)\n{\n   png_XYZ XYZ;\n\n   png_debug1(1, \"in %s storage function\", \"cHRM XYZ fixed\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   XYZ.red_X = int_red_X;\n   XYZ.red_Y = int_red_Y;\n   XYZ.red_Z = int_red_Z;\n   XYZ.green_X = int_green_X;\n   XYZ.green_Y = int_green_Y;\n   XYZ.green_Z = int_green_Z;\n   XYZ.blue_X = int_blue_X;\n   XYZ.blue_Y = int_blue_Y;\n   XYZ.blue_Z = int_blue_Z;\n\n   if (png_colorspace_set_endpoints(png_ptr, &info_ptr->colorspace,\n       &XYZ, 2) != 0)\n      info_ptr->colorspace.flags |= PNG_COLORSPACE_FROM_cHRM;\n\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,\n    double white_x, double white_y, double red_x, double red_y,\n    double green_x, double green_y, double blue_x, double blue_y)\n{\n   png_set_cHRM_fixed(png_ptr, info_ptr,\n       png_fixed(png_ptr, white_x, \"cHRM White X\"),\n       png_fixed(png_ptr, white_y, \"cHRM White Y\"),\n       png_fixed(png_ptr, red_x, \"cHRM Red X\"),\n       png_fixed(png_ptr, red_y, \"cHRM Red Y\"),\n       png_fixed(png_ptr, green_x, \"cHRM Green X\"),\n       png_fixed(png_ptr, green_y, \"cHRM Green Y\"),\n       png_fixed(png_ptr, blue_x, \"cHRM Blue X\"),\n       png_fixed(png_ptr, blue_y, \"cHRM Blue Y\"));\n}\n\nvoid PNGAPI\npng_set_cHRM_XYZ(png_const_structrp png_ptr, png_inforp info_ptr, double red_X,\n    double red_Y, double red_Z, double green_X, double green_Y, double green_Z,\n    double blue_X, double blue_Y, double blue_Z)\n{\n   png_set_cHRM_XYZ_fixed(png_ptr, info_ptr,\n       png_fixed(png_ptr, red_X, \"cHRM Red X\"),\n       png_fixed(png_ptr, red_Y, \"cHRM Red Y\"),\n       png_fixed(png_ptr, red_Z, \"cHRM Red Z\"),\n       png_fixed(png_ptr, green_X, \"cHRM Green X\"),\n       png_fixed(png_ptr, green_Y, \"cHRM Green Y\"),\n       png_fixed(png_ptr, green_Z, \"cHRM Green Z\"),\n       png_fixed(png_ptr, blue_X, \"cHRM Blue X\"),\n       png_fixed(png_ptr, blue_Y, \"cHRM Blue Y\"),\n       png_fixed(png_ptr, blue_Z, \"cHRM Blue Z\"));\n}\n#  endif /* FLOATING_POINT */\n\n#endif /* cHRM */\n\n#ifdef PNG_gAMA_SUPPORTED\nvoid PNGFAPI\npng_set_gAMA_fixed(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_fixed_point file_gamma)\n{\n   png_debug1(1, \"in %s storage function\", \"gAMA\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   png_colorspace_set_gamma(png_ptr, &info_ptr->colorspace, file_gamma);\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_gAMA(png_const_structrp png_ptr, png_inforp info_ptr, double file_gamma)\n{\n   png_set_gAMA_fixed(png_ptr, info_ptr, png_fixed(png_ptr, file_gamma,\n       \"png_set_gAMA\"));\n}\n#  endif\n#endif\n\n#ifdef PNG_hIST_SUPPORTED\nvoid PNGAPI\npng_set_hIST(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_uint_16p hist)\n{\n   int i;\n\n   png_debug1(1, \"in %s storage function\", \"hIST\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if (info_ptr->num_palette == 0 || info_ptr->num_palette\n       > PNG_MAX_PALETTE_LENGTH)\n   {\n      png_warning(png_ptr,\n          \"Invalid palette size, hIST allocation skipped\");\n\n      return;\n   }\n\n   png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);\n\n   /* Changed from info->num_palette to PNG_MAX_PALETTE_LENGTH in\n    * version 1.2.1\n    */\n   info_ptr->hist = png_voidcast(png_uint_16p, png_malloc_warn(png_ptr,\n       PNG_MAX_PALETTE_LENGTH * (sizeof (png_uint_16))));\n\n   if (info_ptr->hist == NULL)\n   {\n      png_warning(png_ptr, \"Insufficient memory for hIST chunk data\");\n\n      return;\n   }\n\n   info_ptr->free_me |= PNG_FREE_HIST;\n\n   for (i = 0; i < info_ptr->num_palette; i++)\n      info_ptr->hist[i] = hist[i];\n\n   info_ptr->valid |= PNG_INFO_hIST;\n}\n#endif\n\nvoid PNGAPI\npng_set_IHDR(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_uint_32 width, png_uint_32 height, int bit_depth,\n    int color_type, int interlace_type, int compression_type,\n    int filter_type)\n{\n   png_debug1(1, \"in %s storage function\", \"IHDR\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   info_ptr->width = width;\n   info_ptr->height = height;\n   info_ptr->bit_depth = (png_byte)bit_depth;\n   info_ptr->color_type = (png_byte)color_type;\n   info_ptr->compression_type = (png_byte)compression_type;\n   info_ptr->filter_type = (png_byte)filter_type;\n   info_ptr->interlace_type = (png_byte)interlace_type;\n\n   png_check_IHDR (png_ptr, info_ptr->width, info_ptr->height,\n       info_ptr->bit_depth, info_ptr->color_type, info_ptr->interlace_type,\n       info_ptr->compression_type, info_ptr->filter_type);\n\n   if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      info_ptr->channels = 1;\n\n   else if ((info_ptr->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      info_ptr->channels = 3;\n\n   else\n      info_ptr->channels = 1;\n\n   if ((info_ptr->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      info_ptr->channels++;\n\n   info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);\n\n   info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth, width);\n}\n\n#ifdef PNG_oFFs_SUPPORTED\nvoid PNGAPI\npng_set_oFFs(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_int_32 offset_x, png_int_32 offset_y, int unit_type)\n{\n   png_debug1(1, \"in %s storage function\", \"oFFs\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   info_ptr->x_offset = offset_x;\n   info_ptr->y_offset = offset_y;\n   info_ptr->offset_unit_type = (png_byte)unit_type;\n   info_ptr->valid |= PNG_INFO_oFFs;\n}\n#endif\n\n#ifdef PNG_pCAL_SUPPORTED\nvoid PNGAPI\npng_set_pCAL(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_charp purpose, png_int_32 X0, png_int_32 X1, int type,\n    int nparams, png_const_charp units, png_charpp params)\n{\n   png_size_t length;\n   int i;\n\n   png_debug1(1, \"in %s storage function\", \"pCAL\");\n\n   if (png_ptr == NULL || info_ptr == NULL || purpose == NULL || units == NULL\n       || (nparams > 0 && params == NULL))\n      return;\n\n   length = strlen(purpose) + 1;\n   png_debug1(3, \"allocating purpose for info (%lu bytes)\",\n       (unsigned long)length);\n\n   /* TODO: validate format of calibration name and unit name */\n\n   /* Check that the type matches the specification. */\n   if (type < 0 || type > 3)\n      png_error(png_ptr, \"Invalid pCAL equation type\");\n\n   if (nparams < 0 || nparams > 255)\n      png_error(png_ptr, \"Invalid pCAL parameter count\");\n\n   /* Validate params[nparams] */\n   for (i=0; i<nparams; ++i)\n   {\n      if (params[i] == NULL ||\n          !png_check_fp_string(params[i], strlen(params[i])))\n         png_error(png_ptr, \"Invalid format for pCAL parameter\");\n   }\n\n   info_ptr->pcal_purpose = png_voidcast(png_charp,\n       png_malloc_warn(png_ptr, length));\n\n   if (info_ptr->pcal_purpose == NULL)\n   {\n      png_warning(png_ptr, \"Insufficient memory for pCAL purpose\");\n\n      return;\n   }\n\n   memcpy(info_ptr->pcal_purpose, purpose, length);\n\n   png_debug(3, \"storing X0, X1, type, and nparams in info\");\n   info_ptr->pcal_X0 = X0;\n   info_ptr->pcal_X1 = X1;\n   info_ptr->pcal_type = (png_byte)type;\n   info_ptr->pcal_nparams = (png_byte)nparams;\n\n   length = strlen(units) + 1;\n   png_debug1(3, \"allocating units for info (%lu bytes)\",\n       (unsigned long)length);\n\n   info_ptr->pcal_units = png_voidcast(png_charp,\n       png_malloc_warn(png_ptr, length));\n\n   if (info_ptr->pcal_units == NULL)\n   {\n      png_warning(png_ptr, \"Insufficient memory for pCAL units\");\n\n      return;\n   }\n\n   memcpy(info_ptr->pcal_units, units, length);\n\n   info_ptr->pcal_params = png_voidcast(png_charpp, png_malloc_warn(png_ptr,\n       (png_size_t)((nparams + 1) * (sizeof (png_charp)))));\n\n   if (info_ptr->pcal_params == NULL)\n   {\n      png_warning(png_ptr, \"Insufficient memory for pCAL params\");\n\n      return;\n   }\n\n   memset(info_ptr->pcal_params, 0, (nparams + 1) * (sizeof (png_charp)));\n\n   for (i = 0; i < nparams; i++)\n   {\n      length = strlen(params[i]) + 1;\n      png_debug2(3, \"allocating parameter %d for info (%lu bytes)\", i,\n          (unsigned long)length);\n\n      info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);\n\n      if (info_ptr->pcal_params[i] == NULL)\n      {\n         png_warning(png_ptr, \"Insufficient memory for pCAL parameter\");\n\n         return;\n      }\n\n      memcpy(info_ptr->pcal_params[i], params[i], length);\n   }\n\n   info_ptr->valid |= PNG_INFO_pCAL;\n   info_ptr->free_me |= PNG_FREE_PCAL;\n}\n#endif\n\n#ifdef PNG_sCAL_SUPPORTED\nvoid PNGAPI\npng_set_sCAL_s(png_const_structrp png_ptr, png_inforp info_ptr,\n    int unit, png_const_charp swidth, png_const_charp sheight)\n{\n   png_size_t lengthw = 0, lengthh = 0;\n\n   png_debug1(1, \"in %s storage function\", \"sCAL\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   /* Double check the unit (should never get here with an invalid\n    * unit unless this is an API call.)\n    */\n   if (unit != 1 && unit != 2)\n      png_error(png_ptr, \"Invalid sCAL unit\");\n\n   if (swidth == NULL || (lengthw = strlen(swidth)) == 0 ||\n       swidth[0] == 45 /* '-' */ || !png_check_fp_string(swidth, lengthw))\n      png_error(png_ptr, \"Invalid sCAL width\");\n\n   if (sheight == NULL || (lengthh = strlen(sheight)) == 0 ||\n       sheight[0] == 45 /* '-' */ || !png_check_fp_string(sheight, lengthh))\n      png_error(png_ptr, \"Invalid sCAL height\");\n\n   info_ptr->scal_unit = (png_byte)unit;\n\n   ++lengthw;\n\n   png_debug1(3, \"allocating unit for info (%u bytes)\", (unsigned int)lengthw);\n\n   info_ptr->scal_s_width = png_voidcast(png_charp,\n       png_malloc_warn(png_ptr, lengthw));\n\n   if (info_ptr->scal_s_width == NULL)\n   {\n      png_warning(png_ptr, \"Memory allocation failed while processing sCAL\");\n\n      return;\n   }\n\n   memcpy(info_ptr->scal_s_width, swidth, lengthw);\n\n   ++lengthh;\n\n   png_debug1(3, \"allocating unit for info (%u bytes)\", (unsigned int)lengthh);\n\n   info_ptr->scal_s_height = png_voidcast(png_charp,\n       png_malloc_warn(png_ptr, lengthh));\n\n   if (info_ptr->scal_s_height == NULL)\n   {\n      png_free (png_ptr, info_ptr->scal_s_width);\n      info_ptr->scal_s_width = NULL;\n\n      png_warning(png_ptr, \"Memory allocation failed while processing sCAL\");\n\n      return;\n   }\n\n   memcpy(info_ptr->scal_s_height, sheight, lengthh);\n\n   info_ptr->valid |= PNG_INFO_sCAL;\n   info_ptr->free_me |= PNG_FREE_SCAL;\n}\n\n#  ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_sCAL(png_const_structrp png_ptr, png_inforp info_ptr, int unit,\n    double width, double height)\n{\n   png_debug1(1, \"in %s storage function\", \"sCAL\");\n\n   /* Check the arguments. */\n   if (width <= 0)\n      png_warning(png_ptr, \"Invalid sCAL width ignored\");\n\n   else if (height <= 0)\n      png_warning(png_ptr, \"Invalid sCAL height ignored\");\n\n   else\n   {\n      /* Convert 'width' and 'height' to ASCII. */\n      char swidth[PNG_sCAL_MAX_DIGITS+1];\n      char sheight[PNG_sCAL_MAX_DIGITS+1];\n\n      png_ascii_from_fp(png_ptr, swidth, (sizeof swidth), width,\n          PNG_sCAL_PRECISION);\n      png_ascii_from_fp(png_ptr, sheight, (sizeof sheight), height,\n          PNG_sCAL_PRECISION);\n\n      png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);\n   }\n}\n#  endif\n\n#  ifdef PNG_FIXED_POINT_SUPPORTED\nvoid PNGAPI\npng_set_sCAL_fixed(png_const_structrp png_ptr, png_inforp info_ptr, int unit,\n    png_fixed_point width, png_fixed_point height)\n{\n   png_debug1(1, \"in %s storage function\", \"sCAL\");\n\n   /* Check the arguments. */\n   if (width <= 0)\n      png_warning(png_ptr, \"Invalid sCAL width ignored\");\n\n   else if (height <= 0)\n      png_warning(png_ptr, \"Invalid sCAL height ignored\");\n\n   else\n   {\n      /* Convert 'width' and 'height' to ASCII. */\n      char swidth[PNG_sCAL_MAX_DIGITS+1];\n      char sheight[PNG_sCAL_MAX_DIGITS+1];\n\n      png_ascii_from_fixed(png_ptr, swidth, (sizeof swidth), width);\n      png_ascii_from_fixed(png_ptr, sheight, (sizeof sheight), height);\n\n      png_set_sCAL_s(png_ptr, info_ptr, unit, swidth, sheight);\n   }\n}\n#  endif\n#endif\n\n#ifdef PNG_pHYs_SUPPORTED\nvoid PNGAPI\npng_set_pHYs(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_uint_32 res_x, png_uint_32 res_y, int unit_type)\n{\n   png_debug1(1, \"in %s storage function\", \"pHYs\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   info_ptr->x_pixels_per_unit = res_x;\n   info_ptr->y_pixels_per_unit = res_y;\n   info_ptr->phys_unit_type = (png_byte)unit_type;\n   info_ptr->valid |= PNG_INFO_pHYs;\n}\n#endif\n\nvoid PNGAPI\npng_set_PLTE(png_structrp png_ptr, png_inforp info_ptr,\n    png_const_colorp palette, int num_palette)\n{\n\n   png_uint_32 max_palette_length;\n\n   png_debug1(1, \"in %s storage function\", \"PLTE\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   max_palette_length = (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?\n      (1 << info_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;\n\n   if (num_palette < 0 || num_palette > (int) max_palette_length)\n   {\n      if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n         png_error(png_ptr, \"Invalid palette length\");\n\n      else\n      {\n         png_warning(png_ptr, \"Invalid palette length\");\n\n         return;\n      }\n   }\n\n   if ((num_palette > 0 && palette == NULL) ||\n      (num_palette == 0\n#        ifdef PNG_MNG_FEATURES_SUPPORTED\n            && (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0\n#        endif\n      ))\n   {\n      png_error(png_ptr, \"Invalid palette\");\n   }\n\n   /* It may not actually be necessary to set png_ptr->palette here;\n    * we do it for backward compatibility with the way the png_handle_tRNS\n    * function used to do the allocation.\n    *\n    * 1.6.0: the above statement appears to be incorrect; something has to set\n    * the palette inside png_struct on read.\n    */\n   png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);\n\n   /* Changed in libpng-1.2.1 to allocate PNG_MAX_PALETTE_LENGTH instead\n    * of num_palette entries, in case of an invalid PNG file or incorrect\n    * call to png_set_PLTE() with too-large sample values.\n    */\n   png_ptr->palette = png_voidcast(png_colorp, png_calloc(png_ptr,\n       PNG_MAX_PALETTE_LENGTH * (sizeof (png_color))));\n\n   if (num_palette > 0)\n      memcpy(png_ptr->palette, palette, num_palette * (sizeof (png_color)));\n   info_ptr->palette = png_ptr->palette;\n   info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;\n\n   info_ptr->free_me |= PNG_FREE_PLTE;\n\n   info_ptr->valid |= PNG_INFO_PLTE;\n}\n\n#ifdef PNG_sBIT_SUPPORTED\nvoid PNGAPI\npng_set_sBIT(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_color_8p sig_bit)\n{\n   png_debug1(1, \"in %s storage function\", \"sBIT\");\n\n   if (png_ptr == NULL || info_ptr == NULL || sig_bit == NULL)\n      return;\n\n   info_ptr->sig_bit = *sig_bit;\n   info_ptr->valid |= PNG_INFO_sBIT;\n}\n#endif\n\n#ifdef PNG_sRGB_SUPPORTED\nvoid PNGAPI\npng_set_sRGB(png_const_structrp png_ptr, png_inforp info_ptr, int srgb_intent)\n{\n   png_debug1(1, \"in %s storage function\", \"sRGB\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   (void)png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace, srgb_intent);\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n\nvoid PNGAPI\npng_set_sRGB_gAMA_and_cHRM(png_const_structrp png_ptr, png_inforp info_ptr,\n    int srgb_intent)\n{\n   png_debug1(1, \"in %s storage function\", \"sRGB_gAMA_and_cHRM\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if (png_colorspace_set_sRGB(png_ptr, &info_ptr->colorspace,\n       srgb_intent) != 0)\n   {\n      /* This causes the gAMA and cHRM to be written too */\n      info_ptr->colorspace.flags |=\n         PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;\n   }\n\n   png_colorspace_sync_info(png_ptr, info_ptr);\n}\n#endif /* sRGB */\n\n\n#ifdef PNG_iCCP_SUPPORTED\nvoid PNGAPI\npng_set_iCCP(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_charp name, int compression_type,\n    png_const_bytep profile, png_uint_32 proflen)\n{\n   png_charp new_iccp_name;\n   png_bytep new_iccp_profile;\n   png_size_t length;\n\n   png_debug1(1, \"in %s storage function\", \"iCCP\");\n\n   if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)\n      return;\n\n   if (compression_type != PNG_COMPRESSION_TYPE_BASE)\n      png_app_error(png_ptr, \"Invalid iCCP compression method\");\n\n   /* Set the colorspace first because this validates the profile; do not\n    * override previously set app cHRM or gAMA here (because likely as not the\n    * application knows better than libpng what the correct values are.)  Pass\n    * the info_ptr color_type field to png_colorspace_set_ICC because in the\n    * write case it has not yet been stored in png_ptr.\n    */\n   {\n      int result = png_colorspace_set_ICC(png_ptr, &info_ptr->colorspace, name,\n          proflen, profile, info_ptr->color_type);\n\n      png_colorspace_sync_info(png_ptr, info_ptr);\n\n      /* Don't do any of the copying if the profile was bad, or inconsistent. */\n      if (result == 0)\n         return;\n\n      /* But do write the gAMA and cHRM chunks from the profile. */\n      info_ptr->colorspace.flags |=\n         PNG_COLORSPACE_FROM_gAMA|PNG_COLORSPACE_FROM_cHRM;\n   }\n\n   length = strlen(name)+1;\n   new_iccp_name = png_voidcast(png_charp, png_malloc_warn(png_ptr, length));\n\n   if (new_iccp_name == NULL)\n   {\n      png_benign_error(png_ptr, \"Insufficient memory to process iCCP chunk\");\n\n      return;\n   }\n\n   memcpy(new_iccp_name, name, length);\n   new_iccp_profile = png_voidcast(png_bytep,\n       png_malloc_warn(png_ptr, proflen));\n\n   if (new_iccp_profile == NULL)\n   {\n      png_free(png_ptr, new_iccp_name);\n      png_benign_error(png_ptr,\n          \"Insufficient memory to process iCCP profile\");\n\n      return;\n   }\n\n   memcpy(new_iccp_profile, profile, proflen);\n\n   png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);\n\n   info_ptr->iccp_proflen = proflen;\n   info_ptr->iccp_name = new_iccp_name;\n   info_ptr->iccp_profile = new_iccp_profile;\n   info_ptr->free_me |= PNG_FREE_ICCP;\n   info_ptr->valid |= PNG_INFO_iCCP;\n}\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED\nvoid PNGAPI\npng_set_text(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_textp text_ptr, int num_text)\n{\n   int ret;\n   ret = png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);\n\n   if (ret != 0)\n      png_error(png_ptr, \"Insufficient memory to store text\");\n}\n\nint /* PRIVATE */\npng_set_text_2(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_textp text_ptr, int num_text)\n{\n   int i;\n\n   png_debug1(1, \"in %lx storage function\", png_ptr == NULL ? 0xabadca11U :\n      (unsigned long)png_ptr->chunk_name);\n\n   if (png_ptr == NULL || info_ptr == NULL || num_text <= 0 || text_ptr == NULL)\n      return(0);\n\n   /* Make sure we have enough space in the \"text\" array in info_struct\n    * to hold all of the incoming text_ptr objects.  This compare can't overflow\n    * because max_text >= num_text (anyway, subtract of two positive integers\n    * can't overflow in any case.)\n    */\n   if (num_text > info_ptr->max_text - info_ptr->num_text)\n   {\n      int old_num_text = info_ptr->num_text;\n      int max_text;\n      png_textp new_text = NULL;\n\n      /* Calculate an appropriate max_text, checking for overflow. */\n      max_text = old_num_text;\n      if (num_text <= INT_MAX - max_text)\n      {\n         max_text += num_text;\n\n         /* Round up to a multiple of 8 */\n         if (max_text < INT_MAX-8)\n            max_text = (max_text + 8) & ~0x7;\n\n         else\n            max_text = INT_MAX;\n\n         /* Now allocate a new array and copy the old members in; this does all\n          * the overflow checks.\n          */\n         new_text = png_voidcast(png_textp,png_realloc_array(png_ptr,\n             info_ptr->text, old_num_text, max_text-old_num_text,\n             sizeof *new_text));\n      }\n\n      if (new_text == NULL)\n      {\n         png_chunk_report(png_ptr, \"too many text chunks\",\n             PNG_CHUNK_WRITE_ERROR);\n\n         return 1;\n      }\n\n      png_free(png_ptr, info_ptr->text);\n\n      info_ptr->text = new_text;\n      info_ptr->free_me |= PNG_FREE_TEXT;\n      info_ptr->max_text = max_text;\n      /* num_text is adjusted below as the entries are copied in */\n\n      png_debug1(3, \"allocated %d entries for info_ptr->text\", max_text);\n   }\n\n   for (i = 0; i < num_text; i++)\n   {\n      size_t text_length, key_len;\n      size_t lang_len, lang_key_len;\n      png_textp textp = &(info_ptr->text[info_ptr->num_text]);\n\n      if (text_ptr[i].key == NULL)\n          continue;\n\n      if (text_ptr[i].compression < PNG_TEXT_COMPRESSION_NONE ||\n          text_ptr[i].compression >= PNG_TEXT_COMPRESSION_LAST)\n      {\n         png_chunk_report(png_ptr, \"text compression mode is out of range\",\n             PNG_CHUNK_WRITE_ERROR);\n         continue;\n      }\n\n      key_len = strlen(text_ptr[i].key);\n\n      if (text_ptr[i].compression <= 0)\n      {\n         lang_len = 0;\n         lang_key_len = 0;\n      }\n\n      else\n#  ifdef PNG_iTXt_SUPPORTED\n      {\n         /* Set iTXt data */\n\n         if (text_ptr[i].lang != NULL)\n            lang_len = strlen(text_ptr[i].lang);\n\n         else\n            lang_len = 0;\n\n         if (text_ptr[i].lang_key != NULL)\n            lang_key_len = strlen(text_ptr[i].lang_key);\n\n         else\n            lang_key_len = 0;\n      }\n#  else /* iTXt */\n      {\n         png_chunk_report(png_ptr, \"iTXt chunk not supported\",\n             PNG_CHUNK_WRITE_ERROR);\n         continue;\n      }\n#  endif\n\n      if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\\0')\n      {\n         text_length = 0;\n#  ifdef PNG_iTXt_SUPPORTED\n         if (text_ptr[i].compression > 0)\n            textp->compression = PNG_ITXT_COMPRESSION_NONE;\n\n         else\n#  endif\n            textp->compression = PNG_TEXT_COMPRESSION_NONE;\n      }\n\n      else\n      {\n         text_length = strlen(text_ptr[i].text);\n         textp->compression = text_ptr[i].compression;\n      }\n\n      textp->key = png_voidcast(png_charp,png_malloc_base(png_ptr,\n          key_len + text_length + lang_len + lang_key_len + 4));\n\n      if (textp->key == NULL)\n      {\n         png_chunk_report(png_ptr, \"text chunk: out of memory\",\n             PNG_CHUNK_WRITE_ERROR);\n\n         return 1;\n      }\n\n      png_debug2(2, \"Allocated %lu bytes at %p in png_set_text\",\n          (unsigned long)(png_uint_32)\n          (key_len + lang_len + lang_key_len + text_length + 4),\n          textp->key);\n\n      memcpy(textp->key, text_ptr[i].key, key_len);\n      *(textp->key + key_len) = '\\0';\n\n      if (text_ptr[i].compression > 0)\n      {\n         textp->lang = textp->key + key_len + 1;\n         memcpy(textp->lang, text_ptr[i].lang, lang_len);\n         *(textp->lang + lang_len) = '\\0';\n         textp->lang_key = textp->lang + lang_len + 1;\n         memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);\n         *(textp->lang_key + lang_key_len) = '\\0';\n         textp->text = textp->lang_key + lang_key_len + 1;\n      }\n\n      else\n      {\n         textp->lang=NULL;\n         textp->lang_key=NULL;\n         textp->text = textp->key + key_len + 1;\n      }\n\n      if (text_length != 0)\n         memcpy(textp->text, text_ptr[i].text, text_length);\n\n      *(textp->text + text_length) = '\\0';\n\n#  ifdef PNG_iTXt_SUPPORTED\n      if (textp->compression > 0)\n      {\n         textp->text_length = 0;\n         textp->itxt_length = text_length;\n      }\n\n      else\n#  endif\n      {\n         textp->text_length = text_length;\n         textp->itxt_length = 0;\n      }\n\n      info_ptr->num_text++;\n      png_debug1(3, \"transferred text chunk %d\", info_ptr->num_text);\n   }\n\n   return(0);\n}\n#endif\n\n#ifdef PNG_tIME_SUPPORTED\nvoid PNGAPI\npng_set_tIME(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_const_timep mod_time)\n{\n   png_debug1(1, \"in %s storage function\", \"tIME\");\n\n   if (png_ptr == NULL || info_ptr == NULL || mod_time == NULL ||\n       (png_ptr->mode & PNG_WROTE_tIME) != 0)\n      return;\n\n   if (mod_time->month == 0   || mod_time->month > 12  ||\n       mod_time->day   == 0   || mod_time->day   > 31  ||\n       mod_time->hour  > 23   || mod_time->minute > 59 ||\n       mod_time->second > 60)\n   {\n      png_warning(png_ptr, \"Ignoring invalid time value\");\n\n      return;\n   }\n\n   info_ptr->mod_time = *mod_time;\n   info_ptr->valid |= PNG_INFO_tIME;\n}\n#endif\n\n#ifdef PNG_tRNS_SUPPORTED\nvoid PNGAPI\npng_set_tRNS(png_structrp png_ptr, png_inforp info_ptr,\n    png_const_bytep trans_alpha, int num_trans, png_const_color_16p trans_color)\n{\n   png_debug1(1, \"in %s storage function\", \"tRNS\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n\n      return;\n\n   if (trans_alpha != NULL)\n   {\n       /* It may not actually be necessary to set png_ptr->trans_alpha here;\n        * we do it for backward compatibility with the way the png_handle_tRNS\n        * function used to do the allocation.\n        *\n        * 1.6.0: The above statement is incorrect; png_handle_tRNS effectively\n        * relies on png_set_tRNS storing the information in png_struct\n        * (otherwise it won't be there for the code in pngrtran.c).\n        */\n\n       png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);\n\n       if (num_trans > 0 && num_trans <= PNG_MAX_PALETTE_LENGTH)\n       {\n         /* Changed from num_trans to PNG_MAX_PALETTE_LENGTH in version 1.2.1 */\n          info_ptr->trans_alpha = png_voidcast(png_bytep,\n              png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH));\n          memcpy(info_ptr->trans_alpha, trans_alpha, (png_size_t)num_trans);\n       }\n       png_ptr->trans_alpha = info_ptr->trans_alpha;\n   }\n\n   if (trans_color != NULL)\n   {\n#ifdef PNG_WARNINGS_SUPPORTED\n      if (info_ptr->bit_depth < 16)\n      {\n         int sample_max = (1 << info_ptr->bit_depth) - 1;\n\n         if ((info_ptr->color_type == PNG_COLOR_TYPE_GRAY &&\n             trans_color->gray > sample_max) ||\n             (info_ptr->color_type == PNG_COLOR_TYPE_RGB &&\n             (trans_color->red > sample_max ||\n             trans_color->green > sample_max ||\n             trans_color->blue > sample_max)))\n            png_warning(png_ptr,\n                \"tRNS chunk has out-of-range samples for bit_depth\");\n      }\n#endif\n\n      info_ptr->trans_color = *trans_color;\n\n      if (num_trans == 0)\n         num_trans = 1;\n   }\n\n   info_ptr->num_trans = (png_uint_16)num_trans;\n\n   if (num_trans != 0)\n   {\n      info_ptr->valid |= PNG_INFO_tRNS;\n      info_ptr->free_me |= PNG_FREE_TRNS;\n   }\n}\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\nvoid PNGAPI\npng_set_sPLT(png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_sPLT_tp entries, int nentries)\n/*\n *  entries        - array of png_sPLT_t structures\n *                   to be added to the list of palettes\n *                   in the info structure.\n *\n *  nentries       - number of palette structures to be\n *                   added.\n */\n{\n   png_sPLT_tp np;\n\n   if (png_ptr == NULL || info_ptr == NULL || nentries <= 0 || entries == NULL)\n      return;\n\n   /* Use the internal realloc function, which checks for all the possible\n    * overflows.  Notice that the parameters are (int) and (size_t)\n    */\n   np = png_voidcast(png_sPLT_tp,png_realloc_array(png_ptr,\n       info_ptr->splt_palettes, info_ptr->splt_palettes_num, nentries,\n       sizeof *np));\n\n   if (np == NULL)\n   {\n      /* Out of memory or too many chunks */\n      png_chunk_report(png_ptr, \"too many sPLT chunks\", PNG_CHUNK_WRITE_ERROR);\n\n      return;\n   }\n\n   png_free(png_ptr, info_ptr->splt_palettes);\n   info_ptr->splt_palettes = np;\n   info_ptr->free_me |= PNG_FREE_SPLT;\n\n   np += info_ptr->splt_palettes_num;\n\n   do\n   {\n      png_size_t length;\n\n      /* Skip invalid input entries */\n      if (entries->name == NULL || entries->entries == NULL)\n      {\n         /* png_handle_sPLT doesn't do this, so this is an app error */\n         png_app_error(png_ptr, \"png_set_sPLT: invalid sPLT\");\n         /* Just skip the invalid entry */\n         continue;\n      }\n\n      np->depth = entries->depth;\n\n      /* In the event of out-of-memory just return - there's no point keeping\n       * on trying to add sPLT chunks.\n       */\n      length = strlen(entries->name) + 1;\n      np->name = png_voidcast(png_charp, png_malloc_base(png_ptr, length));\n\n      if (np->name == NULL)\n         break;\n\n      memcpy(np->name, entries->name, length);\n\n      /* IMPORTANT: we have memory now that won't get freed if something else\n       * goes wrong; this code must free it.  png_malloc_array produces no\n       * warnings; use a png_chunk_report (below) if there is an error.\n       */\n      np->entries = png_voidcast(png_sPLT_entryp, png_malloc_array(png_ptr,\n          entries->nentries, sizeof (png_sPLT_entry)));\n\n      if (np->entries == NULL)\n      {\n         png_free(png_ptr, np->name);\n         np->name = NULL;\n         break;\n      }\n\n      np->nentries = entries->nentries;\n      /* This multiply can't overflow because png_malloc_array has already\n       * checked it when doing the allocation.\n       */\n      memcpy(np->entries, entries->entries,\n          entries->nentries * sizeof (png_sPLT_entry));\n\n      /* Note that 'continue' skips the advance of the out pointer and out\n       * count, so an invalid entry is not added.\n       */\n      info_ptr->valid |= PNG_INFO_sPLT;\n      ++(info_ptr->splt_palettes_num);\n      ++np;\n   }\n   while (++entries, --nentries);\n\n   if (nentries > 0)\n      png_chunk_report(png_ptr, \"sPLT out of memory\", PNG_CHUNK_WRITE_ERROR);\n}\n#endif /* sPLT */\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\nstatic png_byte\ncheck_location(png_const_structrp png_ptr, int location)\n{\n   location &= (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT);\n\n   /* New in 1.6.0; copy the location and check it.  This is an API\n    * change; previously the app had to use the\n    * png_set_unknown_chunk_location API below for each chunk.\n    */\n   if (location == 0 && (png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\n   {\n      /* Write struct, so unknown chunks come from the app */\n      png_app_warning(png_ptr,\n          \"png_set_unknown_chunks now expects a valid location\");\n      /* Use the old behavior */\n      location = (png_byte)(png_ptr->mode &\n          (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT));\n   }\n\n   /* This need not be an internal error - if the app calls\n    * png_set_unknown_chunks on a read pointer it must get the location right.\n    */\n   if (location == 0)\n      png_error(png_ptr, \"invalid location in png_set_unknown_chunks\");\n\n   /* Now reduce the location to the top-most set bit by removing each least\n    * significant bit in turn.\n    */\n   while (location != (location & -location))\n      location &= ~(location & -location);\n\n   /* The cast is safe because 'location' is a bit mask and only the low four\n    * bits are significant.\n    */\n   return (png_byte)location;\n}\n\nvoid PNGAPI\npng_set_unknown_chunks(png_const_structrp png_ptr,\n    png_inforp info_ptr, png_const_unknown_chunkp unknowns, int num_unknowns)\n{\n   png_unknown_chunkp np;\n\n   if (png_ptr == NULL || info_ptr == NULL || num_unknowns <= 0 ||\n       unknowns == NULL)\n      return;\n\n   /* Check for the failure cases where support has been disabled at compile\n    * time.  This code is hardly ever compiled - it's here because\n    * STORE_UNKNOWN_CHUNKS is set by both read and write code (compiling in this\n    * code) but may be meaningless if the read or write handling of unknown\n    * chunks is not compiled in.\n    */\n#  if !defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED) && \\\n      defined(PNG_READ_SUPPORTED)\n      if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\n      {\n         png_app_error(png_ptr, \"no unknown chunk support on read\");\n\n         return;\n      }\n#  endif\n#  if !defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED) && \\\n      defined(PNG_WRITE_SUPPORTED)\n      if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\n      {\n         png_app_error(png_ptr, \"no unknown chunk support on write\");\n\n         return;\n      }\n#  endif\n\n   /* Prior to 1.6.0 this code used png_malloc_warn; however, this meant that\n    * unknown critical chunks could be lost with just a warning resulting in\n    * undefined behavior.  Now png_chunk_report is used to provide behavior\n    * appropriate to read or write.\n    */\n   np = png_voidcast(png_unknown_chunkp, png_realloc_array(png_ptr,\n       info_ptr->unknown_chunks, info_ptr->unknown_chunks_num, num_unknowns,\n       sizeof *np));\n\n   if (np == NULL)\n   {\n      png_chunk_report(png_ptr, \"too many unknown chunks\",\n          PNG_CHUNK_WRITE_ERROR);\n\n      return;\n   }\n\n   png_free(png_ptr, info_ptr->unknown_chunks);\n   info_ptr->unknown_chunks = np; /* safe because it is initialized */\n   info_ptr->free_me |= PNG_FREE_UNKN;\n\n   np += info_ptr->unknown_chunks_num;\n\n   /* Increment unknown_chunks_num each time round the loop to protect the\n    * just-allocated chunk data.\n    */\n   for (; num_unknowns > 0; --num_unknowns, ++unknowns)\n   {\n      memcpy(np->name, unknowns->name, (sizeof np->name));\n      np->name[(sizeof np->name)-1] = '\\0';\n      np->location = check_location(png_ptr, unknowns->location);\n\n      if (unknowns->size == 0)\n      {\n         np->data = NULL;\n         np->size = 0;\n      }\n\n      else\n      {\n         np->data = png_voidcast(png_bytep,\n             png_malloc_base(png_ptr, unknowns->size));\n\n         if (np->data == NULL)\n         {\n            png_chunk_report(png_ptr, \"unknown chunk: out of memory\",\n                PNG_CHUNK_WRITE_ERROR);\n            /* But just skip storing the unknown chunk */\n            continue;\n         }\n\n         memcpy(np->data, unknowns->data, unknowns->size);\n         np->size = unknowns->size;\n      }\n\n      /* These increments are skipped on out-of-memory for the data - the\n       * unknown chunk entry gets overwritten if the png_chunk_report returns.\n       * This is correct in the read case (the chunk is just dropped.)\n       */\n      ++np;\n      ++(info_ptr->unknown_chunks_num);\n   }\n}\n\nvoid PNGAPI\npng_set_unknown_chunk_location(png_const_structrp png_ptr, png_inforp info_ptr,\n    int chunk, int location)\n{\n   /* This API is pretty pointless in 1.6.0 because the location can be set\n    * before the call to png_set_unknown_chunks.\n    *\n    * TODO: add a png_app_warning in 1.7\n    */\n   if (png_ptr != NULL && info_ptr != NULL && chunk >= 0 &&\n      chunk < info_ptr->unknown_chunks_num)\n   {\n      if ((location & (PNG_HAVE_IHDR|PNG_HAVE_PLTE|PNG_AFTER_IDAT)) == 0)\n      {\n         png_app_error(png_ptr, \"invalid unknown chunk location\");\n         /* Fake out the pre 1.6.0 behavior: */\n         if ((location & PNG_HAVE_IDAT) != 0) /* undocumented! */\n            location = PNG_AFTER_IDAT;\n\n         else\n            location = PNG_HAVE_IHDR; /* also undocumented */\n      }\n\n      info_ptr->unknown_chunks[chunk].location =\n         check_location(png_ptr, location);\n   }\n}\n#endif /* STORE_UNKNOWN_CHUNKS */\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\npng_uint_32 PNGAPI\npng_permit_mng_features (png_structrp png_ptr, png_uint_32 mng_features)\n{\n   png_debug(1, \"in png_permit_mng_features\");\n\n   if (png_ptr == NULL)\n      return 0;\n\n   png_ptr->mng_features_permitted = mng_features & PNG_ALL_MNG_FEATURES;\n\n   return png_ptr->mng_features_permitted;\n}\n#endif\n\n#ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED\nstatic unsigned int\nadd_one_chunk(png_bytep list, unsigned int count, png_const_bytep add, int keep)\n{\n   unsigned int i;\n\n   /* Utility function: update the 'keep' state of a chunk if it is already in\n    * the list, otherwise add it to the list.\n    */\n   for (i=0; i<count; ++i, list += 5)\n   {\n      if (memcmp(list, add, 4) == 0)\n      {\n         list[4] = (png_byte)keep;\n\n         return count;\n      }\n   }\n\n   if (keep != PNG_HANDLE_CHUNK_AS_DEFAULT)\n   {\n      ++count;\n      memcpy(list, add, 4);\n      list[4] = (png_byte)keep;\n   }\n\n   return count;\n}\n\nvoid PNGAPI\npng_set_keep_unknown_chunks(png_structrp png_ptr, int keep,\n    png_const_bytep chunk_list, int num_chunks_in)\n{\n   png_bytep new_list;\n   unsigned int num_chunks, old_num_chunks;\n\n   if (png_ptr == NULL)\n      return;\n\n   if (keep < 0 || keep >= PNG_HANDLE_CHUNK_LAST)\n   {\n      png_app_error(png_ptr, \"png_set_keep_unknown_chunks: invalid keep\");\n\n      return;\n   }\n\n   if (num_chunks_in <= 0)\n   {\n      png_ptr->unknown_default = keep;\n\n      /* '0' means just set the flags, so stop here */\n      if (num_chunks_in == 0)\n        return;\n   }\n\n   if (num_chunks_in < 0)\n   {\n      /* Ignore all unknown chunks and all chunks recognized by\n       * libpng except for IHDR, PLTE, tRNS, IDAT, and IEND\n       */\n      static PNG_CONST png_byte chunks_to_ignore[] = {\n         98,  75,  71,  68, '\\0',  /* bKGD */\n         99,  72,  82,  77, '\\0',  /* cHRM */\n        103,  65,  77,  65, '\\0',  /* gAMA */\n        104,  73,  83,  84, '\\0',  /* hIST */\n        105,  67,  67,  80, '\\0',  /* iCCP */\n        105,  84,  88, 116, '\\0',  /* iTXt */\n        111,  70,  70, 115, '\\0',  /* oFFs */\n        112,  67,  65,  76, '\\0',  /* pCAL */\n        112,  72,  89, 115, '\\0',  /* pHYs */\n        115,  66,  73,  84, '\\0',  /* sBIT */\n        115,  67,  65,  76, '\\0',  /* sCAL */\n        115,  80,  76,  84, '\\0',  /* sPLT */\n        115,  84,  69,  82, '\\0',  /* sTER */\n        115,  82,  71,  66, '\\0',  /* sRGB */\n        116,  69,  88, 116, '\\0',  /* tEXt */\n        116,  73,  77,  69, '\\0',  /* tIME */\n        122,  84,  88, 116, '\\0'   /* zTXt */\n      };\n\n      chunk_list = chunks_to_ignore;\n      num_chunks = (unsigned int)/*SAFE*/(sizeof chunks_to_ignore)/5U;\n   }\n\n   else /* num_chunks_in > 0 */\n   {\n      if (chunk_list == NULL)\n      {\n         /* Prior to 1.6.0 this was silently ignored, now it is an app_error\n          * which can be switched off.\n          */\n         png_app_error(png_ptr, \"png_set_keep_unknown_chunks: no chunk list\");\n\n         return;\n      }\n\n      num_chunks = num_chunks_in;\n   }\n\n   old_num_chunks = png_ptr->num_chunk_list;\n   if (png_ptr->chunk_list == NULL)\n      old_num_chunks = 0;\n\n   /* Since num_chunks is always restricted to UINT_MAX/5 this can't overflow.\n    */\n   if (num_chunks + old_num_chunks > UINT_MAX/5)\n   {\n      png_app_error(png_ptr, \"png_set_keep_unknown_chunks: too many chunks\");\n\n      return;\n   }\n\n   /* If these chunks are being reset to the default then no more memory is\n    * required because add_one_chunk above doesn't extend the list if the 'keep'\n    * parameter is the default.\n    */\n   if (keep != 0)\n   {\n      new_list = png_voidcast(png_bytep, png_malloc(png_ptr,\n          5 * (num_chunks + old_num_chunks)));\n\n      if (old_num_chunks > 0)\n         memcpy(new_list, png_ptr->chunk_list, 5*old_num_chunks);\n   }\n\n   else if (old_num_chunks > 0)\n      new_list = png_ptr->chunk_list;\n\n   else\n      new_list = NULL;\n\n   /* Add the new chunks together with each one's handling code.  If the chunk\n    * already exists the code is updated, otherwise the chunk is added to the\n    * end.  (In libpng 1.6.0 order no longer matters because this code enforces\n    * the earlier convention that the last setting is the one that is used.)\n    */\n   if (new_list != NULL)\n   {\n      png_const_bytep inlist;\n      png_bytep outlist;\n      unsigned int i;\n\n      for (i=0; i<num_chunks; ++i)\n      {\n         old_num_chunks = add_one_chunk(new_list, old_num_chunks,\n             chunk_list+5*i, keep);\n      }\n\n      /* Now remove any spurious 'default' entries. */\n      num_chunks = 0;\n      for (i=0, inlist=outlist=new_list; i<old_num_chunks; ++i, inlist += 5)\n      {\n         if (inlist[4])\n         {\n            if (outlist != inlist)\n               memcpy(outlist, inlist, 5);\n            outlist += 5;\n            ++num_chunks;\n         }\n      }\n\n      /* This means the application has removed all the specialized handling. */\n      if (num_chunks == 0)\n      {\n         if (png_ptr->chunk_list != new_list)\n            png_free(png_ptr, new_list);\n\n         new_list = NULL;\n      }\n   }\n\n   else\n      num_chunks = 0;\n\n   png_ptr->num_chunk_list = num_chunks;\n\n   if (png_ptr->chunk_list != new_list)\n   {\n      if (png_ptr->chunk_list != NULL)\n         png_free(png_ptr, png_ptr->chunk_list);\n\n      png_ptr->chunk_list = new_list;\n   }\n}\n#endif\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\nvoid PNGAPI\npng_set_read_user_chunk_fn(png_structrp png_ptr, png_voidp user_chunk_ptr,\n    png_user_chunk_ptr read_user_chunk_fn)\n{\n   png_debug(1, \"in png_set_read_user_chunk_fn\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->read_user_chunk_fn = read_user_chunk_fn;\n   png_ptr->user_chunk_ptr = user_chunk_ptr;\n}\n#endif\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\nvoid PNGAPI\npng_set_rows(png_const_structrp png_ptr, png_inforp info_ptr,\n    png_bytepp row_pointers)\n{\n   png_debug1(1, \"in %s storage function\", \"rows\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if (info_ptr->row_pointers != NULL &&\n       (info_ptr->row_pointers != row_pointers))\n      png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);\n\n   info_ptr->row_pointers = row_pointers;\n\n   if (row_pointers != NULL)\n      info_ptr->valid |= PNG_INFO_IDAT;\n}\n#endif\n\nvoid PNGAPI\npng_set_compression_buffer_size(png_structrp png_ptr, png_size_t size)\n{\n   if (png_ptr == NULL)\n      return;\n\n   if (size == 0 || size > PNG_UINT_31_MAX)\n      png_error(png_ptr, \"invalid compression buffer size\");\n\n#  ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n   if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\n   {\n      png_ptr->IDAT_read_size = (png_uint_32)size; /* checked above */\n      return;\n   }\n#  endif\n\n#  ifdef PNG_WRITE_SUPPORTED\n   if ((png_ptr->mode & PNG_IS_READ_STRUCT) == 0)\n   {\n      if (png_ptr->zowner != 0)\n      {\n         png_warning(png_ptr,\n             \"Compression buffer size cannot be changed because it is in use\");\n\n         return;\n      }\n\n#ifndef __COVERITY__\n      /* Some compilers complain that this is always false.  However, it\n       * can be true when integer overflow happens.\n       */\n      if (size > ZLIB_IO_MAX)\n      {\n         png_warning(png_ptr,\n             \"Compression buffer size limited to system maximum\");\n         size = ZLIB_IO_MAX; /* must fit */\n      }\n#endif\n\n      if (size < 6)\n      {\n         /* Deflate will potentially go into an infinite loop on a SYNC_FLUSH\n          * if this is permitted.\n          */\n         png_warning(png_ptr,\n             \"Compression buffer size cannot be reduced below 6\");\n\n         return;\n      }\n\n      if (png_ptr->zbuffer_size != size)\n      {\n         png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);\n         png_ptr->zbuffer_size = (uInt)size;\n      }\n   }\n#  endif\n}\n\nvoid PNGAPI\npng_set_invalid(png_const_structrp png_ptr, png_inforp info_ptr, int mask)\n{\n   if (png_ptr != NULL && info_ptr != NULL)\n      info_ptr->valid &= ~mask;\n}\n\n\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\n/* This function was added to libpng 1.2.6 */\nvoid PNGAPI\npng_set_user_limits (png_structrp png_ptr, png_uint_32 user_width_max,\n    png_uint_32 user_height_max)\n{\n   /* Images with dimensions larger than these limits will be\n    * rejected by png_set_IHDR().  To accept any PNG datastream\n    * regardless of dimensions, set both limits to 0x7fffffff.\n    */\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->user_width_max = user_width_max;\n   png_ptr->user_height_max = user_height_max;\n}\n\n/* This function was added to libpng 1.4.0 */\nvoid PNGAPI\npng_set_chunk_cache_max (png_structrp png_ptr, png_uint_32 user_chunk_cache_max)\n{\n   if (png_ptr != NULL)\n      png_ptr->user_chunk_cache_max = user_chunk_cache_max;\n}\n\n/* This function was added to libpng 1.4.1 */\nvoid PNGAPI\npng_set_chunk_malloc_max (png_structrp png_ptr,\n    png_alloc_size_t user_chunk_malloc_max)\n{\n   if (png_ptr != NULL)\n      png_ptr->user_chunk_malloc_max = user_chunk_malloc_max;\n}\n#endif /* ?SET_USER_LIMITS */\n\n\n#ifdef PNG_BENIGN_ERRORS_SUPPORTED\nvoid PNGAPI\npng_set_benign_errors(png_structrp png_ptr, int allowed)\n{\n   png_debug(1, \"in png_set_benign_errors\");\n\n   /* If allowed is 1, png_benign_error() is treated as a warning.\n    *\n    * If allowed is 0, png_benign_error() is treated as an error (which\n    * is the default behavior if png_set_benign_errors() is not called).\n    */\n\n   if (allowed != 0)\n      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN |\n         PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN;\n\n   else\n      png_ptr->flags &= ~(PNG_FLAG_BENIGN_ERRORS_WARN |\n         PNG_FLAG_APP_WARNINGS_WARN | PNG_FLAG_APP_ERRORS_WARN);\n}\n#endif /* BENIGN_ERRORS */\n\n#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   /* Whether to report invalid palette index; added at libng-1.5.10.\n    * It is possible for an indexed (color-type==3) PNG file to contain\n    * pixels with invalid (out-of-range) indexes if the PLTE chunk has\n    * fewer entries than the image's bit-depth would allow. We recover\n    * from this gracefully by filling any incomplete palette with zeros\n    * (opaque black).  By default, when this occurs libpng will issue\n    * a benign error.  This API can be used to override that behavior.\n    */\nvoid PNGAPI\npng_set_check_for_invalid_index(png_structrp png_ptr, int allowed)\n{\n   png_debug(1, \"in png_set_check_for_invalid_index\");\n\n   if (allowed > 0)\n      png_ptr->num_palette_max = 0;\n\n   else\n      png_ptr->num_palette_max = -1;\n}\n#endif\n\n#if defined(PNG_TEXT_SUPPORTED) || defined(PNG_pCAL_SUPPORTED) || \\\n    defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)\n/* Check that the tEXt or zTXt keyword is valid per PNG 1.0 specification,\n * and if invalid, correct the keyword rather than discarding the entire\n * chunk.  The PNG 1.0 specification requires keywords 1-79 characters in\n * length, forbids leading or trailing whitespace, multiple internal spaces,\n * and the non-break space (0x80) from ISO 8859-1.  Returns keyword length.\n *\n * The 'new_key' buffer must be 80 characters in size (for the keyword plus a\n * trailing '\\0').  If this routine returns 0 then there was no keyword, or a\n * valid one could not be generated, and the caller must png_error.\n */\npng_uint_32 /* PRIVATE */\npng_check_keyword(png_structrp png_ptr, png_const_charp key, png_bytep new_key)\n{\n#ifdef PNG_WARNINGS_SUPPORTED\n   png_const_charp orig_key = key;\n#endif\n   png_uint_32 key_len = 0;\n   int bad_character = 0;\n   int space = 1;\n\n   png_debug(1, \"in png_check_keyword\");\n\n   if (key == NULL)\n   {\n      *new_key = 0;\n      return 0;\n   }\n\n   while (*key && key_len < 79)\n   {\n      png_byte ch = (png_byte)*key++;\n\n      if ((ch > 32 && ch <= 126) || (ch >= 161 /*&& ch <= 255*/))\n         *new_key++ = ch, ++key_len, space = 0;\n\n      else if (space == 0)\n      {\n         /* A space or an invalid character when one wasn't seen immediately\n          * before; output just a space.\n          */\n         *new_key++ = 32, ++key_len, space = 1;\n\n         /* If the character was not a space then it is invalid. */\n         if (ch != 32)\n            bad_character = ch;\n      }\n\n      else if (bad_character == 0)\n         bad_character = ch; /* just skip it, record the first error */\n   }\n\n   if (key_len > 0 && space != 0) /* trailing space */\n   {\n      --key_len, --new_key;\n      if (bad_character == 0)\n         bad_character = 32;\n   }\n\n   /* Terminate the keyword */\n   *new_key = 0;\n\n   if (key_len == 0)\n      return 0;\n\n#ifdef PNG_WARNINGS_SUPPORTED\n   /* Try to only output one warning per keyword: */\n   if (*key != 0) /* keyword too long */\n      png_warning(png_ptr, \"keyword truncated\");\n\n   else if (bad_character != 0)\n   {\n      PNG_WARNING_PARAMETERS(p)\n\n      png_warning_parameter(p, 1, orig_key);\n      png_warning_parameter_signed(p, 2, PNG_NUMBER_FORMAT_02x, bad_character);\n\n      png_formatted_warning(png_ptr, p, \"keyword \\\"@1\\\": bad character '0x@2'\");\n   }\n#else /* !WARNINGS */\n   PNG_UNUSED(png_ptr)\n#endif /* !WARNINGS */\n\n   return key_len;\n}\n#endif /* TEXT || pCAL || iCCP || sPLT */\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngstruct.h",
    "content": "\n/* pngstruct.h - header file for PNG reference library\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* The structure that holds the information to read and write PNG files.\n * The only people who need to care about what is inside of this are the\n * people who will be modifying the library for their own special needs.\n * It should NOT be accessed directly by an application.\n */\n\n#ifndef PNGSTRUCT_H\n#define PNGSTRUCT_H\n/* zlib.h defines the structure z_stream, an instance of which is included\n * in this structure and is required for decompressing the LZ compressed\n * data in PNG files.\n */\n#ifndef ZLIB_CONST\n   /* We must ensure that zlib uses 'const' in declarations. */\n#  define ZLIB_CONST\n#endif\n#include \"zlib.h\"\n#ifdef const\n   /* zlib.h sometimes #defines const to nothing, undo this. */\n#  undef const\n#endif\n\n/* zlib.h has mediocre z_const use before 1.2.6, this stuff is for compatibility\n * with older builds.\n */\n#if ZLIB_VERNUM < 0x1260\n#  define PNGZ_MSG_CAST(s) png_constcast(char*,s)\n#  define PNGZ_INPUT_CAST(b) png_constcast(png_bytep,b)\n#else\n#  define PNGZ_MSG_CAST(s) (s)\n#  define PNGZ_INPUT_CAST(b) (b)\n#endif\n\n/* zlib.h declares a magic type 'uInt' that limits the amount of data that zlib\n * can handle at once.  This type need be no larger than 16 bits (so maximum of\n * 65535), this define allows us to discover how big it is, but limited by the\n * maximuum for png_size_t.  The value can be overriden in a library build\n * (pngusr.h, or set it in CPPFLAGS) and it works to set it to a considerably\n * lower value (e.g. 255 works).  A lower value may help memory usage (slightly)\n * and may even improve performance on some systems (and degrade it on others.)\n */\n#ifndef ZLIB_IO_MAX\n#  define ZLIB_IO_MAX ((uInt)-1)\n#endif\n\n#ifdef PNG_WRITE_SUPPORTED\n/* The type of a compression buffer list used by the write code. */\ntypedef struct png_compression_buffer\n{\n   struct png_compression_buffer *next;\n   png_byte                       output[1]; /* actually zbuf_size */\n} png_compression_buffer, *png_compression_bufferp;\n\n#define PNG_COMPRESSION_BUFFER_SIZE(pp)\\\n   (offsetof(png_compression_buffer, output) + (pp)->zbuffer_size)\n#endif\n\n/* Colorspace support; structures used in png_struct, png_info and in internal\n * functions to hold and communicate information about the color space.\n *\n * PNG_COLORSPACE_SUPPORTED is only required if the application will perform\n * colorspace corrections, otherwise all the colorspace information can be\n * skipped and the size of libpng can be reduced (significantly) by compiling\n * out the colorspace support.\n */\n#ifdef PNG_COLORSPACE_SUPPORTED\n/* The chromaticities of the red, green and blue colorants and the chromaticity\n * of the corresponding white point (i.e. of rgb(1.0,1.0,1.0)).\n */\ntypedef struct png_xy\n{\n   png_fixed_point redx, redy;\n   png_fixed_point greenx, greeny;\n   png_fixed_point bluex, bluey;\n   png_fixed_point whitex, whitey;\n} png_xy;\n\n/* The same data as above but encoded as CIE XYZ values.  When this data comes\n * from chromaticities the sum of the Y values is assumed to be 1.0\n */\ntypedef struct png_XYZ\n{\n   png_fixed_point red_X, red_Y, red_Z;\n   png_fixed_point green_X, green_Y, green_Z;\n   png_fixed_point blue_X, blue_Y, blue_Z;\n} png_XYZ;\n#endif /* COLORSPACE */\n\n#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)\n/* A colorspace is all the above plus, potentially, profile information;\n * however at present libpng does not use the profile internally so it is only\n * stored in the png_info struct (if iCCP is supported.)  The rendering intent\n * is retained here and is checked.\n *\n * The file gamma encoding information is also stored here and gamma correction\n * is done by libpng, whereas color correction must currently be done by the\n * application.\n */\ntypedef struct png_colorspace\n{\n#ifdef PNG_GAMMA_SUPPORTED\n   png_fixed_point gamma;        /* File gamma */\n#endif\n\n#ifdef PNG_COLORSPACE_SUPPORTED\n   png_xy      end_points_xy;    /* End points as chromaticities */\n   png_XYZ     end_points_XYZ;   /* End points as CIE XYZ colorant values */\n   png_uint_16 rendering_intent; /* Rendering intent of a profile */\n#endif\n\n   /* Flags are always defined to simplify the code. */\n   png_uint_16 flags;            /* As defined below */\n} png_colorspace, * PNG_RESTRICT png_colorspacerp;\n\ntypedef const png_colorspace * PNG_RESTRICT png_const_colorspacerp;\n\n/* General flags for the 'flags' field */\n#define PNG_COLORSPACE_HAVE_GAMMA           0x0001\n#define PNG_COLORSPACE_HAVE_ENDPOINTS       0x0002\n#define PNG_COLORSPACE_HAVE_INTENT          0x0004\n#define PNG_COLORSPACE_FROM_gAMA            0x0008\n#define PNG_COLORSPACE_FROM_cHRM            0x0010\n#define PNG_COLORSPACE_FROM_sRGB            0x0020\n#define PNG_COLORSPACE_ENDPOINTS_MATCH_sRGB 0x0040\n#define PNG_COLORSPACE_MATCHES_sRGB         0x0080 /* exact match on profile */\n#define PNG_COLORSPACE_INVALID              0x8000\n#define PNG_COLORSPACE_CANCEL(flags)        (0xffff ^ (flags))\n#endif /* COLORSPACE || GAMMA */\n\nstruct png_struct_def\n{\n#ifdef PNG_SETJMP_SUPPORTED\n   jmp_buf jmp_buf_local;     /* New name in 1.6.0 for jmp_buf in png_struct */\n   png_longjmp_ptr longjmp_fn;/* setjmp non-local goto function. */\n   jmp_buf *jmp_buf_ptr;      /* passed to longjmp_fn */\n   size_t jmp_buf_size;       /* size of the above, if allocated */\n#endif\n   png_error_ptr error_fn;    /* function for printing errors and aborting */\n#ifdef PNG_WARNINGS_SUPPORTED\n   png_error_ptr warning_fn;  /* function for printing warnings */\n#endif\n   png_voidp error_ptr;       /* user supplied struct for error functions */\n   png_rw_ptr write_data_fn;  /* function for writing output data */\n   png_rw_ptr read_data_fn;   /* function for reading input data */\n   png_voidp io_ptr;          /* ptr to application struct for I/O functions */\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n   png_user_transform_ptr read_user_transform_fn; /* user read transform */\n#endif\n\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n   png_user_transform_ptr write_user_transform_fn; /* user write transform */\n#endif\n\n/* These were added in libpng-1.0.2 */\n#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED\n#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \\\n    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)\n   png_voidp user_transform_ptr; /* user supplied struct for user transform */\n   png_byte user_transform_depth;    /* bit depth of user transformed pixels */\n   png_byte user_transform_channels; /* channels in user transformed pixels */\n#endif\n#endif\n\n   png_uint_32 mode;          /* tells us where we are in the PNG file */\n   png_uint_32 flags;         /* flags indicating various things to libpng */\n   png_uint_32 transformations; /* which transformations to perform */\n\n   png_uint_32 zowner;        /* ID (chunk type) of zstream owner, 0 if none */\n   z_stream    zstream;       /* decompression structure */\n\n#ifdef PNG_WRITE_SUPPORTED\n   png_compression_bufferp zbuffer_list; /* Created on demand during write */\n   uInt                    zbuffer_size; /* size of the actual buffer */\n\n   int zlib_level;            /* holds zlib compression level */\n   int zlib_method;           /* holds zlib compression method */\n   int zlib_window_bits;      /* holds zlib compression window bits */\n   int zlib_mem_level;        /* holds zlib compression memory level */\n   int zlib_strategy;         /* holds zlib compression strategy */\n#endif\n/* Added at libpng 1.5.4 */\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n   int zlib_text_level;            /* holds zlib compression level */\n   int zlib_text_method;           /* holds zlib compression method */\n   int zlib_text_window_bits;      /* holds zlib compression window bits */\n   int zlib_text_mem_level;        /* holds zlib compression memory level */\n   int zlib_text_strategy;         /* holds zlib compression strategy */\n#endif\n/* End of material added at libpng 1.5.4 */\n/* Added at libpng 1.6.0 */\n#ifdef PNG_WRITE_SUPPORTED\n   int zlib_set_level;        /* Actual values set into the zstream on write */\n   int zlib_set_method;\n   int zlib_set_window_bits;\n   int zlib_set_mem_level;\n   int zlib_set_strategy;\n#endif\n\n   png_uint_32 width;         /* width of image in pixels */\n   png_uint_32 height;        /* height of image in pixels */\n   png_uint_32 num_rows;      /* number of rows in current pass */\n   png_uint_32 usr_width;     /* width of row at start of write */\n   png_size_t rowbytes;       /* size of row in bytes */\n   png_uint_32 iwidth;        /* width of current interlaced row in pixels */\n   png_uint_32 row_number;    /* current row in interlace pass */\n   png_uint_32 chunk_name;    /* PNG_CHUNK() id of current chunk */\n   png_bytep prev_row;        /* buffer to save previous (unfiltered) row.\n                               * While reading this is a pointer into\n                               * big_prev_row; while writing it is separately\n                               * allocated if needed.\n                               */\n   png_bytep row_buf;         /* buffer to save current (unfiltered) row.\n                               * While reading, this is a pointer into\n                               * big_row_buf; while writing it is separately\n                               * allocated.\n                               */\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   png_bytep try_row;    /* buffer to save trial row when filtering */\n   png_bytep tst_row;    /* buffer to save best trial row when filtering */\n#endif\n   png_size_t info_rowbytes;  /* Added in 1.5.4: cache of updated row bytes */\n\n   png_uint_32 idat_size;     /* current IDAT size for read */\n   png_uint_32 crc;           /* current chunk CRC value */\n   png_colorp palette;        /* palette from the input file */\n   png_uint_16 num_palette;   /* number of color entries in palette */\n\n/* Added at libpng-1.5.10 */\n#ifdef PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   int num_palette_max;       /* maximum palette index found in IDAT */\n#endif\n\n   png_uint_16 num_trans;     /* number of transparency values */\n   png_byte compression;      /* file compression type (always 0) */\n   png_byte filter;           /* file filter type (always 0) */\n   png_byte interlaced;       /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */\n   png_byte pass;             /* current interlace pass (0 - 6) */\n   png_byte do_filter;        /* row filter flags (see PNG_FILTER_ in png.h ) */\n   png_byte color_type;       /* color type of file */\n   png_byte bit_depth;        /* bit depth of file */\n   png_byte usr_bit_depth;    /* bit depth of users row: write only */\n   png_byte pixel_depth;      /* number of bits per pixel */\n   png_byte channels;         /* number of channels in file */\n#ifdef PNG_WRITE_SUPPORTED\n   png_byte usr_channels;     /* channels at start of write: write only */\n#endif\n   png_byte sig_bytes;        /* magic bytes read/written from start of file */\n   png_byte maximum_pixel_depth;\n                              /* pixel depth used for the row buffers */\n   png_byte transformed_pixel_depth;\n                              /* pixel depth after read/write transforms */\n#if PNG_ZLIB_VERNUM >= 0x1240\n   png_byte zstream_start;    /* at start of an input zlib stream */\n#endif /* Zlib >= 1.2.4 */\n#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)\n   png_uint_16 filler;           /* filler bytes for pixel expansion */\n#endif\n\n#if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) ||\\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED)\n   png_byte background_gamma_type;\n   png_fixed_point background_gamma;\n   png_color_16 background;   /* background color in screen gamma space */\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   png_color_16 background_1; /* background normalized to gamma 1.0 */\n#endif\n#endif /* bKGD */\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n   png_flush_ptr output_flush_fn; /* Function for flushing output */\n   png_uint_32 flush_dist;    /* how many rows apart to flush, 0 - no flush */\n   png_uint_32 flush_rows;    /* number of rows written since last flush */\n#endif\n\n#ifdef PNG_READ_GAMMA_SUPPORTED\n   int gamma_shift;      /* number of \"insignificant\" bits in 16-bit gamma */\n   png_fixed_point screen_gamma; /* screen gamma value (display_exponent) */\n\n   png_bytep gamma_table;     /* gamma table for 8-bit depth files */\n   png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */\n#if defined(PNG_READ_BACKGROUND_SUPPORTED) || \\\n   defined(PNG_READ_ALPHA_MODE_SUPPORTED) || \\\n   defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)\n   png_bytep gamma_from_1;    /* converts from 1.0 to screen */\n   png_bytep gamma_to_1;      /* converts from file to 1.0 */\n   png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */\n   png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */\n#endif /* READ_BACKGROUND || READ_ALPHA_MODE || RGB_TO_GRAY */\n#endif\n\n#if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)\n   png_color_8 sig_bit;       /* significant bits in each available channel */\n#endif\n\n#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)\n   png_color_8 shift;         /* shift for significant bit tranformation */\n#endif\n\n#if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \\\n || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)\n   png_bytep trans_alpha;           /* alpha values for paletted files */\n   png_color_16 trans_color;  /* transparent color for non-paletted files */\n#endif\n\n   png_read_status_ptr read_row_fn;   /* called after each row is decoded */\n   png_write_status_ptr write_row_fn; /* called after each row is encoded */\n#ifdef PNG_PROGRESSIVE_READ_SUPPORTED\n   png_progressive_info_ptr info_fn; /* called after header data fully read */\n   png_progressive_row_ptr row_fn;   /* called after a prog. row is decoded */\n   png_progressive_end_ptr end_fn;   /* called after image is complete */\n   png_bytep save_buffer_ptr;        /* current location in save_buffer */\n   png_bytep save_buffer;            /* buffer for previously read data */\n   png_bytep current_buffer_ptr;     /* current location in current_buffer */\n   png_bytep current_buffer;         /* buffer for recently used data */\n   png_uint_32 push_length;          /* size of current input chunk */\n   png_uint_32 skip_length;          /* bytes to skip in input data */\n   png_size_t save_buffer_size;      /* amount of data now in save_buffer */\n   png_size_t save_buffer_max;       /* total size of save_buffer */\n   png_size_t buffer_size;           /* total amount of available input data */\n   png_size_t current_buffer_size;   /* amount of data now in current_buffer */\n   int process_mode;                 /* what push library is currently doing */\n   int cur_palette;                  /* current push library palette index */\n\n#endif /* PROGRESSIVE_READ */\n\n#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)\n/* For the Borland special 64K segment handler */\n   png_bytepp offset_table_ptr;\n   png_bytep offset_table;\n   png_uint_16 offset_table_number;\n   png_uint_16 offset_table_count;\n   png_uint_16 offset_table_count_free;\n#endif\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n   png_bytep palette_lookup; /* lookup table for quantizing */\n   png_bytep quantize_index; /* index translation for palette files */\n#endif\n\n/* Options */\n#ifdef PNG_SET_OPTION_SUPPORTED\n   png_byte options;           /* On/off state (up to 4 options) */\n#endif\n\n#if PNG_LIBPNG_VER < 10700\n/* To do: remove this from libpng-1.7 */\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n   char time_buffer[29]; /* String to hold RFC 1123 time text */\n#endif\n#endif\n\n/* New members added in libpng-1.0.6 */\n\n   png_uint_32 free_me;    /* flags items libpng is responsible for freeing */\n\n#ifdef PNG_USER_CHUNKS_SUPPORTED\n   png_voidp user_chunk_ptr;\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n   png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */\n#endif\n#endif\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n   int          unknown_default; /* As PNG_HANDLE_* */\n   unsigned int num_chunk_list;  /* Number of entries in the list */\n   png_bytep    chunk_list;      /* List of png_byte[5]; the textual chunk name\n                                  * followed by a PNG_HANDLE_* byte */\n#endif\n\n/* New members added in libpng-1.0.3 */\n#ifdef PNG_READ_RGB_TO_GRAY_SUPPORTED\n   png_byte rgb_to_gray_status;\n   /* Added in libpng 1.5.5 to record setting of coefficients: */\n   png_byte rgb_to_gray_coefficients_set;\n   /* These were changed from png_byte in libpng-1.0.6 */\n   png_uint_16 rgb_to_gray_red_coeff;\n   png_uint_16 rgb_to_gray_green_coeff;\n   /* deleted in 1.5.5: rgb_to_gray_blue_coeff; */\n#endif\n\n/* New member added in libpng-1.0.4 (renamed in 1.0.9) */\n#if defined(PNG_MNG_FEATURES_SUPPORTED)\n/* Changed from png_byte to png_uint_32 at version 1.2.0 */\n   png_uint_32 mng_features_permitted;\n#endif\n\n/* New member added in libpng-1.0.9, ifdef'ed out in 1.0.12, enabled in 1.2.0 */\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   png_byte filter_type;\n#endif\n\n/* New members added in libpng-1.2.0 */\n\n/* New members added in libpng-1.0.2 but first enabled by default in 1.2.0 */\n#ifdef PNG_USER_MEM_SUPPORTED\n   png_voidp mem_ptr;             /* user supplied struct for mem functions */\n   png_malloc_ptr malloc_fn;      /* function for allocating memory */\n   png_free_ptr free_fn;          /* function for freeing memory */\n#endif\n\n/* New member added in libpng-1.0.13 and 1.2.0 */\n   png_bytep big_row_buf;         /* buffer to save current (unfiltered) row */\n\n#ifdef PNG_READ_QUANTIZE_SUPPORTED\n/* The following three members were added at version 1.0.14 and 1.2.4 */\n   png_bytep quantize_sort;          /* working sort array */\n   png_bytep index_to_palette;       /* where the original index currently is\n                                        in the palette */\n   png_bytep palette_to_index;       /* which original index points to this\n                                         palette color */\n#endif\n\n/* New members added in libpng-1.0.16 and 1.2.6 */\n   png_byte compression_type;\n\n#ifdef PNG_USER_LIMITS_SUPPORTED\n   png_uint_32 user_width_max;\n   png_uint_32 user_height_max;\n\n   /* Added in libpng-1.4.0: Total number of sPLT, text, and unknown\n    * chunks that can be stored (0 means unlimited).\n    */\n   png_uint_32 user_chunk_cache_max;\n\n   /* Total memory that a zTXt, sPLT, iTXt, iCCP, or unknown chunk\n    * can occupy when decompressed.  0 means unlimited.\n    */\n   png_alloc_size_t user_chunk_malloc_max;\n#endif\n\n/* New member added in libpng-1.0.25 and 1.2.17 */\n#ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n   /* Temporary storage for unknown chunk that the library doesn't recognize,\n    * used while reading the chunk.\n    */\n   png_unknown_chunk unknown_chunk;\n#endif\n\n/* New member added in libpng-1.2.26 */\n  png_size_t old_big_row_buf_size;\n\n#ifdef PNG_READ_SUPPORTED\n/* New member added in libpng-1.2.30 */\n  png_bytep        read_buffer;      /* buffer for reading chunk data */\n  png_alloc_size_t read_buffer_size; /* current size of the buffer */\n#endif\n#ifdef PNG_SEQUENTIAL_READ_SUPPORTED\n  uInt             IDAT_read_size;   /* limit on read buffer size for IDAT */\n#endif\n\n#ifdef PNG_IO_STATE_SUPPORTED\n/* New member added in libpng-1.4.0 */\n   png_uint_32 io_state;\n#endif\n\n/* New member added in libpng-1.5.6 */\n   png_bytep big_prev_row;\n\n/* New member added in libpng-1.5.7 */\n   void (*read_filter[PNG_FILTER_VALUE_LAST-1])(png_row_infop row_info,\n      png_bytep row, png_const_bytep prev_row);\n\n#ifdef PNG_READ_SUPPORTED\n#if defined(PNG_COLORSPACE_SUPPORTED) || defined(PNG_GAMMA_SUPPORTED)\n   png_colorspace   colorspace;\n#endif\n#endif\n};\n#endif /* PNGSTRUCT_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngtest.c",
    "content": "\n/* pngtest.c - a simple test program to test libpng\n *\n * Last changed in libpng 1.6.25 [September 1, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This program reads in a PNG image, writes it out again, and then\n * compares the two files.  If the files are identical, this shows that\n * the basic chunk handling, filtering, and (de)compression code is working\n * properly.  It does not currently test all of the transforms, although\n * it probably should.\n *\n * The program will report \"FAIL\" in certain legitimate cases:\n * 1) when the compression level or filter selection method is changed.\n * 2) when the maximum IDAT size (PNG_ZBUF_SIZE in pngconf.h) is not 8192.\n * 3) unknown unsafe-to-copy ancillary chunks or unknown critical chunks\n *    exist in the input file.\n * 4) others not listed here...\n * In these cases, it is best to check with another tool such as \"pngcheck\"\n * to see what the differences between the two files are.\n *\n * If a filename is given on the command-line, then this file is used\n * for the input, rather than the default \"pngtest.png\".  This allows\n * testing a wide variety of files easily.  You can also test a number\n * of files at once by typing \"pngtest -m file1.png file2.png ...\"\n */\n\n#define _POSIX_SOURCE 1\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\n/* Defined so I can write to a file on gui/windowing platforms */\n/*  #define STDERR stderr  */\n#define STDERR stdout   /* For DOS */\n\n#include \"png.h\"\n\n/* 1.6.1 added support for the configure test harness, which uses 77 to indicate\n * a skipped test, in earlier versions we need to succeed on a skipped test, so:\n */\n#if PNG_LIBPNG_VER >= 10601 && defined(HAVE_CONFIG_H)\n#  define SKIP 77\n#else\n#  define SKIP 0\n#endif\n\n/* Known chunks that exist in pngtest.png must be supported or pngtest will fail\n * simply as a result of re-ordering them.  This may be fixed in 1.7\n *\n * pngtest allocates a single row buffer for each row and overwrites it,\n * therefore if the write side doesn't support the writing of interlaced images\n * nothing can be done for an interlaced image (and the code below will fail\n * horribly trying to write extra data after writing garbage).\n */\n#if defined PNG_READ_SUPPORTED && /* else nothing can be done */\\\n   defined PNG_READ_bKGD_SUPPORTED &&\\\n   defined PNG_READ_cHRM_SUPPORTED &&\\\n   defined PNG_READ_gAMA_SUPPORTED &&\\\n   defined PNG_READ_oFFs_SUPPORTED &&\\\n   defined PNG_READ_pCAL_SUPPORTED &&\\\n   defined PNG_READ_pHYs_SUPPORTED &&\\\n   defined PNG_READ_sBIT_SUPPORTED &&\\\n   defined PNG_READ_sCAL_SUPPORTED &&\\\n   defined PNG_READ_sRGB_SUPPORTED &&\\\n   defined PNG_READ_sPLT_SUPPORTED &&\\\n   defined PNG_READ_tEXt_SUPPORTED &&\\\n   defined PNG_READ_tIME_SUPPORTED &&\\\n   defined PNG_READ_zTXt_SUPPORTED &&\\\n   (defined PNG_WRITE_INTERLACING_SUPPORTED || PNG_LIBPNG_VER >= 10700)\n\n#ifdef PNG_ZLIB_HEADER\n#  include PNG_ZLIB_HEADER /* defined by pnglibconf.h from 1.7 */\n#else\n#  include \"zlib.h\"\n#endif\n\n/* Copied from pngpriv.h but only used in error messages below. */\n#ifndef PNG_ZBUF_SIZE\n#  define PNG_ZBUF_SIZE 8192\n#endif\n#define FCLOSE(file) fclose(file)\n\n#ifndef PNG_STDIO_SUPPORTED\ntypedef FILE                * png_FILE_p;\n#endif\n\n/* Makes pngtest verbose so we can find problems. */\n#ifndef PNG_DEBUG\n#  define PNG_DEBUG 0\n#endif\n\n#if PNG_DEBUG > 1\n#  define pngtest_debug(m)        ((void)fprintf(stderr, m \"\\n\"))\n#  define pngtest_debug1(m,p1)    ((void)fprintf(stderr, m \"\\n\", p1))\n#  define pngtest_debug2(m,p1,p2) ((void)fprintf(stderr, m \"\\n\", p1, p2))\n#else\n#  define pngtest_debug(m)        ((void)0)\n#  define pngtest_debug1(m,p1)    ((void)0)\n#  define pngtest_debug2(m,p1,p2) ((void)0)\n#endif\n\n#if !PNG_DEBUG\n#  define SINGLE_ROWBUF_ALLOC  /* Makes buffer overruns easier to nail */\n#endif\n\n#ifndef PNG_UNUSED\n#  define PNG_UNUSED(param) (void)param;\n#endif\n\n/* Turn on CPU timing\n#define PNGTEST_TIMING\n*/\n\n#ifndef PNG_FLOATING_POINT_SUPPORTED\n#undef PNGTEST_TIMING\n#endif\n\n#ifdef PNGTEST_TIMING\nstatic float t_start, t_stop, t_decode, t_encode, t_misc;\n#include <time.h>\n#endif\n\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n#define PNG_tIME_STRING_LENGTH 29\nstatic int tIME_chunk_present = 0;\nstatic char tIME_string[PNG_tIME_STRING_LENGTH] = \"tIME chunk is not present\";\n\n#if PNG_LIBPNG_VER < 10619\n#define png_convert_to_rfc1123_buffer(ts, t) tIME_to_str(read_ptr, ts, t)\n\nstatic int\ntIME_to_str(png_structp png_ptr, png_charp ts, png_const_timep t)\n{\n   png_const_charp str = png_convert_to_rfc1123(png_ptr, t);\n\n   if (str == NULL)\n       return 0;\n\n   strcpy(ts, str);\n   return 1;\n}\n#endif /* older libpng */\n#endif\n\nstatic int verbose = 0;\nstatic int strict = 0;\nstatic int relaxed = 0;\nstatic int unsupported_chunks = 0; /* chunk unsupported by libpng in input */\nstatic int error_count = 0; /* count calls to png_error */\nstatic int warning_count = 0; /* count calls to png_warning */\n\n/* Define png_jmpbuf() in case we are using a pre-1.0.6 version of libpng */\n#ifndef png_jmpbuf\n#  define png_jmpbuf(png_ptr) png_ptr->jmpbuf\n#endif\n\n/* Defines for unknown chunk handling if required. */\n#ifndef PNG_HANDLE_CHUNK_ALWAYS\n#  define PNG_HANDLE_CHUNK_ALWAYS       3\n#endif\n#ifndef PNG_HANDLE_CHUNK_IF_SAFE\n#  define PNG_HANDLE_CHUNK_IF_SAFE      2\n#endif\n\n/* Utility to save typing/errors, the argument must be a name */\n#define MEMZERO(var) ((void)memset(&var, 0, sizeof var))\n\n/* Example of using row callbacks to make a simple progress meter */\nstatic int status_pass = 1;\nstatic int status_dots_requested = 0;\nstatic int status_dots = 1;\n\nstatic void PNGCBAPI\nread_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)\n{\n   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX)\n      return;\n\n   if (status_pass != pass)\n   {\n      fprintf(stdout, \"\\n Pass %d: \", pass);\n      status_pass = pass;\n      status_dots = 31;\n   }\n\n   status_dots--;\n\n   if (status_dots == 0)\n   {\n      fprintf(stdout, \"\\n         \");\n      status_dots=30;\n   }\n\n   fprintf(stdout, \"r\");\n}\n\n#ifdef PNG_WRITE_SUPPORTED\nstatic void PNGCBAPI\nwrite_row_callback(png_structp png_ptr, png_uint_32 row_number, int pass)\n{\n   if (png_ptr == NULL || row_number > PNG_UINT_31_MAX || pass > 7)\n      return;\n\n   fprintf(stdout, \"w\");\n}\n#endif\n\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n/* Example of using a user transform callback (doesn't do anything at present).\n */\nstatic void PNGCBAPI\nread_user_callback(png_structp png_ptr, png_row_infop row_info, png_bytep data)\n{\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(row_info)\n   PNG_UNUSED(data)\n}\n#endif\n\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n/* Example of using user transform callback (we don't transform anything,\n * but merely count the zero samples)\n */\n\nstatic png_uint_32 zero_samples;\n\nstatic void PNGCBAPI\ncount_zero_samples(png_structp png_ptr, png_row_infop row_info, png_bytep data)\n{\n   png_bytep dp = data;\n   if (png_ptr == NULL)\n      return;\n\n   /* Contents of row_info:\n    *  png_uint_32 width      width of row\n    *  png_uint_32 rowbytes   number of bytes in row\n    *  png_byte color_type    color type of pixels\n    *  png_byte bit_depth     bit depth of samples\n    *  png_byte channels      number of channels (1-4)\n    *  png_byte pixel_depth   bits per pixel (depth*channels)\n    */\n\n   /* Counts the number of zero samples (or zero pixels if color_type is 3 */\n\n   if (row_info->color_type == 0 || row_info->color_type == 3)\n   {\n      int pos = 0;\n      png_uint_32 n, nstop;\n\n      for (n = 0, nstop=row_info->width; n<nstop; n++)\n      {\n         if (row_info->bit_depth == 1)\n         {\n            if (((*dp << pos++ ) & 0x80) == 0)\n               zero_samples++;\n\n            if (pos == 8)\n            {\n               pos = 0;\n               dp++;\n            }\n         }\n\n         if (row_info->bit_depth == 2)\n         {\n            if (((*dp << (pos+=2)) & 0xc0) == 0)\n               zero_samples++;\n\n            if (pos == 8)\n            {\n               pos = 0;\n               dp++;\n            }\n         }\n\n         if (row_info->bit_depth == 4)\n         {\n            if (((*dp << (pos+=4)) & 0xf0) == 0)\n               zero_samples++;\n\n            if (pos == 8)\n            {\n               pos = 0;\n               dp++;\n            }\n         }\n\n         if (row_info->bit_depth == 8)\n            if (*dp++ == 0)\n               zero_samples++;\n\n         if (row_info->bit_depth == 16)\n         {\n            if ((*dp | *(dp+1)) == 0)\n               zero_samples++;\n            dp+=2;\n         }\n      }\n   }\n   else /* Other color types */\n   {\n      png_uint_32 n, nstop;\n      int channel;\n      int color_channels = row_info->channels;\n      if (row_info->color_type > 3)\n         color_channels--;\n\n      for (n = 0, nstop=row_info->width; n<nstop; n++)\n      {\n         for (channel = 0; channel < color_channels; channel++)\n         {\n            if (row_info->bit_depth == 8)\n               if (*dp++ == 0)\n                  zero_samples++;\n\n            if (row_info->bit_depth == 16)\n            {\n               if ((*dp | *(dp+1)) == 0)\n                  zero_samples++;\n\n               dp+=2;\n            }\n         }\n         if (row_info->color_type > 3)\n         {\n            dp++;\n            if (row_info->bit_depth == 16)\n               dp++;\n         }\n      }\n   }\n}\n#endif /* WRITE_USER_TRANSFORM */\n\n#ifndef PNG_STDIO_SUPPORTED\n/* START of code to validate stdio-free compilation */\n/* These copies of the default read/write functions come from pngrio.c and\n * pngwio.c.  They allow \"don't include stdio\" testing of the library.\n * This is the function that does the actual reading of data.  If you are\n * not reading from a standard C stream, you should create a replacement\n * read_data function and use it at run time with png_set_read_fn(), rather\n * than changing the library.\n */\n\n#ifdef PNG_IO_STATE_SUPPORTED\nvoid\npngtest_check_io_state(png_structp png_ptr, png_size_t data_length,\n    png_uint_32 io_op);\nvoid\npngtest_check_io_state(png_structp png_ptr, png_size_t data_length,\n    png_uint_32 io_op)\n{\n   png_uint_32 io_state = png_get_io_state(png_ptr);\n   int err = 0;\n\n   /* Check if the current operation (reading / writing) is as expected. */\n   if ((io_state & PNG_IO_MASK_OP) != io_op)\n      png_error(png_ptr, \"Incorrect operation in I/O state\");\n\n   /* Check if the buffer size specific to the current location\n    * (file signature / header / data / crc) is as expected.\n    */\n   switch (io_state & PNG_IO_MASK_LOC)\n   {\n   case PNG_IO_SIGNATURE:\n      if (data_length > 8)\n         err = 1;\n      break;\n   case PNG_IO_CHUNK_HDR:\n      if (data_length != 8)\n         err = 1;\n      break;\n   case PNG_IO_CHUNK_DATA:\n      break;  /* no restrictions here */\n   case PNG_IO_CHUNK_CRC:\n      if (data_length != 4)\n         err = 1;\n      break;\n   default:\n      err = 1;  /* uninitialized */\n   }\n   if (err != 0)\n      png_error(png_ptr, \"Bad I/O state or buffer size\");\n}\n#endif\n\nstatic void PNGCBAPI\npngtest_read_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_size_t check = 0;\n   png_voidp io_ptr;\n\n   /* fread() returns 0 on error, so it is OK to store this in a png_size_t\n    * instead of an int, which is what fread() actually returns.\n    */\n   io_ptr = png_get_io_ptr(png_ptr);\n   if (io_ptr != NULL)\n   {\n      check = fread(data, 1, length, (png_FILE_p)io_ptr);\n   }\n\n   if (check != length)\n   {\n      png_error(png_ptr, \"Read Error\");\n   }\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   pngtest_check_io_state(png_ptr, length, PNG_IO_READING);\n#endif\n}\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\nstatic void PNGCBAPI\npngtest_flush(png_structp png_ptr)\n{\n   /* Do nothing; fflush() is said to be just a waste of energy. */\n   PNG_UNUSED(png_ptr)   /* Stifle compiler warning */\n}\n#endif\n\n/* This is the function that does the actual writing of data.  If you are\n * not writing to a standard C stream, you should create a replacement\n * write_data function and use it at run time with png_set_write_fn(), rather\n * than changing the library.\n */\nstatic void PNGCBAPI\npngtest_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_size_t check;\n\n   check = fwrite(data, 1, length, (png_FILE_p)png_get_io_ptr(png_ptr));\n\n   if (check != length)\n   {\n      png_error(png_ptr, \"Write Error\");\n   }\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   pngtest_check_io_state(png_ptr, length, PNG_IO_WRITING);\n#endif\n}\n#endif /* !STDIO */\n\n/* This function is called when there is a warning, but the library thinks\n * it can continue anyway.  Replacement functions don't have to do anything\n * here if you don't want to.  In the default configuration, png_ptr is\n * not used, but it is passed in case it may be useful.\n */\ntypedef struct\n{\n   PNG_CONST char *file_name;\n}  pngtest_error_parameters;\n\nstatic void PNGCBAPI\npngtest_warning(png_structp png_ptr, png_const_charp message)\n{\n   PNG_CONST char *name = \"UNKNOWN (ERROR!)\";\n   pngtest_error_parameters *test =\n      (pngtest_error_parameters*)png_get_error_ptr(png_ptr);\n\n   ++warning_count;\n\n   if (test != NULL && test->file_name != NULL)\n      name = test->file_name;\n\n   fprintf(STDERR, \"%s: libpng warning: %s\\n\", name, message);\n}\n\n/* This is the default error handling function.  Note that replacements for\n * this function MUST NOT RETURN, or the program will likely crash.  This\n * function is used by default, or if the program supplies NULL for the\n * error function pointer in png_set_error_fn().\n */\nstatic void PNGCBAPI\npngtest_error(png_structp png_ptr, png_const_charp message)\n{\n   ++error_count;\n\n   pngtest_warning(png_ptr, message);\n   /* We can return because png_error calls the default handler, which is\n    * actually OK in this case.\n    */\n}\n\n/* END of code to validate stdio-free compilation */\n\n/* START of code to validate memory allocation and deallocation */\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n\n/* Allocate memory.  For reasonable files, size should never exceed\n * 64K.  However, zlib may allocate more than 64K if you don't tell\n * it not to.  See zconf.h and png.h for more information.  zlib does\n * need to allocate exactly 64K, so whatever you call here must\n * have the ability to do that.\n *\n * This piece of code can be compiled to validate max 64K allocations\n * by setting MAXSEG_64K in zlib zconf.h *or* PNG_MAX_MALLOC_64K.\n */\ntypedef struct memory_information\n{\n   png_alloc_size_t          size;\n   png_voidp                 pointer;\n   struct memory_information *next;\n} memory_information;\ntypedef memory_information *memory_infop;\n\nstatic memory_infop pinformation = NULL;\nstatic png_alloc_size_t current_allocation = 0;\nstatic png_alloc_size_t maximum_allocation = 0;\nstatic png_alloc_size_t total_allocation = 0;\nstatic png_alloc_size_t num_allocations = 0;\n\npng_voidp PNGCBAPI png_debug_malloc PNGARG((png_structp png_ptr,\n    png_alloc_size_t size));\nvoid PNGCBAPI png_debug_free PNGARG((png_structp png_ptr, png_voidp ptr));\n\npng_voidp\nPNGCBAPI png_debug_malloc(png_structp png_ptr, png_alloc_size_t size)\n{\n\n   /* png_malloc has already tested for NULL; png_create_struct calls\n    * png_debug_malloc directly, with png_ptr == NULL which is OK\n    */\n\n   if (size == 0)\n      return (NULL);\n\n   /* This calls the library allocator twice, once to get the requested\n      buffer and once to get a new free list entry. */\n   {\n      /* Disable malloc_fn and free_fn */\n      memory_infop pinfo;\n      png_set_mem_fn(png_ptr, NULL, NULL, NULL);\n      pinfo = (memory_infop)png_malloc(png_ptr,\n          (sizeof *pinfo));\n      pinfo->size = size;\n      current_allocation += size;\n      total_allocation += size;\n      num_allocations ++;\n\n      if (current_allocation > maximum_allocation)\n         maximum_allocation = current_allocation;\n\n      pinfo->pointer = png_malloc(png_ptr, size);\n      /* Restore malloc_fn and free_fn */\n\n      png_set_mem_fn(png_ptr,\n          NULL, png_debug_malloc, png_debug_free);\n\n      if (size != 0 && pinfo->pointer == NULL)\n      {\n         current_allocation -= size;\n         total_allocation -= size;\n         png_error(png_ptr,\n           \"out of memory in pngtest->png_debug_malloc\");\n      }\n\n      pinfo->next = pinformation;\n      pinformation = pinfo;\n      /* Make sure the caller isn't assuming zeroed memory. */\n      memset(pinfo->pointer, 0xdd, pinfo->size);\n\n      if (verbose != 0)\n         printf(\"png_malloc %lu bytes at %p\\n\", (unsigned long)size,\n             pinfo->pointer);\n\n      return (png_voidp)(pinfo->pointer);\n   }\n}\n\n/* Free a pointer.  It is removed from the list at the same time. */\nvoid PNGCBAPI\npng_debug_free(png_structp png_ptr, png_voidp ptr)\n{\n   if (png_ptr == NULL)\n      fprintf(STDERR, \"NULL pointer to png_debug_free.\\n\");\n\n   if (ptr == 0)\n   {\n#if 0 /* This happens all the time. */\n      fprintf(STDERR, \"WARNING: freeing NULL pointer\\n\");\n#endif\n      return;\n   }\n\n   /* Unlink the element from the list. */\n   if (pinformation != NULL)\n   {\n      memory_infop *ppinfo = &pinformation;\n\n      for (;;)\n      {\n         memory_infop pinfo = *ppinfo;\n\n         if (pinfo->pointer == ptr)\n         {\n            *ppinfo = pinfo->next;\n            if (current_allocation < pinfo->size)\n               fprintf(STDERR, \"Duplicate free of memory\\n\");\n            else\n               current_allocation -= pinfo->size;\n            /* We must free the list element too, but first kill\n               the memory that is to be freed. */\n            memset(ptr, 0x55, pinfo->size);\n            free(pinfo);\n            pinfo = NULL;\n            break;\n         }\n\n         if (pinfo->next == NULL)\n         {\n            fprintf(STDERR, \"Pointer %p not found\\n\", ptr);\n            break;\n         }\n\n         ppinfo = &pinfo->next;\n      }\n   }\n\n   /* Finally free the data. */\n   if (verbose != 0)\n      printf(\"Freeing %p\\n\", ptr);\n\n   if (ptr != NULL)\n      free(ptr);\n   ptr = NULL;\n}\n#endif /* USER_MEM && DEBUG */\n/* END of code to test memory allocation/deallocation */\n\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n/* Demonstration of user chunk support of the sTER and vpAg chunks */\n\n/* (sTER is a public chunk not yet known by libpng.  vpAg is a private\nchunk used in ImageMagick to store \"virtual page\" size).  */\n\nstatic struct user_chunk_data\n{\n   png_const_infop info_ptr;\n   png_uint_32     vpAg_width, vpAg_height;\n   png_byte        vpAg_units;\n   png_byte        sTER_mode;\n   int             location[2];\n}\nuser_chunk_data;\n\n/* Used for location and order; zero means nothing. */\n#define have_sTER   0x01\n#define have_vpAg   0x02\n#define before_PLTE 0x10\n#define before_IDAT 0x20\n#define after_IDAT  0x40\n\nstatic void\ninit_callback_info(png_const_infop info_ptr)\n{\n   MEMZERO(user_chunk_data);\n   user_chunk_data.info_ptr = info_ptr;\n}\n\nstatic int\nset_location(png_structp png_ptr, struct user_chunk_data *data, int what)\n{\n   int location;\n\n   if ((data->location[0] & what) != 0 || (data->location[1] & what) != 0)\n      return 0; /* already have one of these */\n\n   /* Find where we are (the code below zeroes info_ptr to indicate that the\n    * chunks before the first IDAT have been read.)\n    */\n   if (data->info_ptr == NULL) /* after IDAT */\n      location = what | after_IDAT;\n\n   else if (png_get_valid(png_ptr, data->info_ptr, PNG_INFO_PLTE) != 0)\n      location = what | before_IDAT;\n\n   else\n      location = what | before_PLTE;\n\n   if (data->location[0] == 0)\n      data->location[0] = location;\n\n   else\n      data->location[1] = location;\n\n   return 1; /* handled */\n}\n\nstatic int PNGCBAPI\nread_user_chunk_callback(png_struct *png_ptr, png_unknown_chunkp chunk)\n{\n   struct user_chunk_data *my_user_chunk_data =\n      (struct user_chunk_data*)png_get_user_chunk_ptr(png_ptr);\n\n   if (my_user_chunk_data == NULL)\n      png_error(png_ptr, \"lost user chunk pointer\");\n\n   /* Return one of the following:\n    *    return (-n);  chunk had an error\n    *    return (0);  did not recognize\n    *    return (n);  success\n    *\n    * The unknown chunk structure contains the chunk data:\n    * png_byte name[5];\n    * png_byte *data;\n    * png_size_t size;\n    *\n    * Note that libpng has already taken care of the CRC handling.\n    */\n\n   if (chunk->name[0] == 115 && chunk->name[1] ==  84 &&     /* s  T */\n       chunk->name[2] ==  69 && chunk->name[3] ==  82)       /* E  R */\n      {\n         /* Found sTER chunk */\n         if (chunk->size != 1)\n            return (-1); /* Error return */\n\n         if (chunk->data[0] != 0 && chunk->data[0] != 1)\n            return (-1);  /* Invalid mode */\n\n         if (set_location(png_ptr, my_user_chunk_data, have_sTER) != 0)\n         {\n            my_user_chunk_data->sTER_mode=chunk->data[0];\n            return (1);\n         }\n\n         else\n            return (0); /* duplicate sTER - give it to libpng */\n      }\n\n   if (chunk->name[0] != 118 || chunk->name[1] != 112 ||    /* v  p */\n       chunk->name[2] !=  65 || chunk->name[3] != 103)      /* A  g */\n      return (0); /* Did not recognize */\n\n   /* Found ImageMagick vpAg chunk */\n\n   if (chunk->size != 9)\n      return (-1); /* Error return */\n\n   if (set_location(png_ptr, my_user_chunk_data, have_vpAg) == 0)\n      return (0);  /* duplicate vpAg */\n\n   my_user_chunk_data->vpAg_width = png_get_uint_31(png_ptr, chunk->data);\n   my_user_chunk_data->vpAg_height = png_get_uint_31(png_ptr, chunk->data + 4);\n   my_user_chunk_data->vpAg_units = chunk->data[8];\n\n   return (1);\n}\n\n#ifdef PNG_WRITE_SUPPORTED\nstatic void\nwrite_sTER_chunk(png_structp write_ptr)\n{\n   png_byte sTER[5] = {115,  84,  69,  82, '\\0'};\n\n   if (verbose != 0)\n      fprintf(STDERR, \"\\n stereo mode = %d\\n\", user_chunk_data.sTER_mode);\n\n   png_write_chunk(write_ptr, sTER, &user_chunk_data.sTER_mode, 1);\n}\n\nstatic void\nwrite_vpAg_chunk(png_structp write_ptr)\n{\n   png_byte vpAg[5] = {118, 112,  65, 103, '\\0'};\n\n   png_byte vpag_chunk_data[9];\n\n   if (verbose != 0)\n      fprintf(STDERR, \" vpAg = %lu x %lu, units = %d\\n\",\n          (unsigned long)user_chunk_data.vpAg_width,\n          (unsigned long)user_chunk_data.vpAg_height,\n          user_chunk_data.vpAg_units);\n\n   png_save_uint_32(vpag_chunk_data, user_chunk_data.vpAg_width);\n   png_save_uint_32(vpag_chunk_data + 4, user_chunk_data.vpAg_height);\n   vpag_chunk_data[8] = user_chunk_data.vpAg_units;\n   png_write_chunk(write_ptr, vpAg, vpag_chunk_data, 9);\n}\n\nstatic void\nwrite_chunks(png_structp write_ptr, int location)\n{\n   int i;\n\n   /* Notice that this preserves the original chunk order, however chunks\n    * intercepted by the callback will be written *after* chunks passed to\n    * libpng.  This will actually reverse a pair of sTER chunks or a pair of\n    * vpAg chunks, resulting in an error later.  This is not worth worrying\n    * about - the chunks should not be duplicated!\n    */\n   for (i=0; i<2; ++i)\n   {\n      if (user_chunk_data.location[i] == (location | have_sTER))\n         write_sTER_chunk(write_ptr);\n\n      else if (user_chunk_data.location[i] == (location | have_vpAg))\n         write_vpAg_chunk(write_ptr);\n   }\n}\n#endif /* WRITE */\n#else /* !READ_USER_CHUNKS */\n#  define write_chunks(pp,loc) ((void)0)\n#endif\n/* END of code to demonstrate user chunk support */\n\n/* START of code to check that libpng has the required text support; this only\n * checks for the write support because if read support is missing the chunk\n * will simply not be reported back to pngtest.\n */\n#ifdef PNG_TEXT_SUPPORTED\nstatic void\npngtest_check_text_support(png_structp png_ptr, png_textp text_ptr,\n    int num_text)\n{\n   while (num_text > 0)\n   {\n      switch (text_ptr[--num_text].compression)\n      {\n         case PNG_TEXT_COMPRESSION_NONE:\n            break;\n\n         case PNG_TEXT_COMPRESSION_zTXt:\n#           ifndef PNG_WRITE_zTXt_SUPPORTED\n               ++unsupported_chunks;\n               /* In libpng 1.7 this now does an app-error, so stop it: */\n               text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n#           endif\n            break;\n\n         case PNG_ITXT_COMPRESSION_NONE:\n         case PNG_ITXT_COMPRESSION_zTXt:\n#           ifndef PNG_WRITE_iTXt_SUPPORTED\n               ++unsupported_chunks;\n               text_ptr[num_text].compression = PNG_TEXT_COMPRESSION_NONE;\n#           endif\n            break;\n\n         default:\n            /* This is an error */\n            png_error(png_ptr, \"invalid text chunk compression field\");\n            break;\n      }\n   }\n}\n#endif\n/* END of code to check that libpng has the required text support */\n\n/* Test one file */\nstatic int\ntest_one_file(PNG_CONST char *inname, PNG_CONST char *outname)\n{\n   static png_FILE_p fpin;\n   static png_FILE_p fpout;  /* \"static\" prevents setjmp corruption */\n   pngtest_error_parameters error_parameters;\n   png_structp read_ptr;\n   png_infop read_info_ptr, end_info_ptr;\n#ifdef PNG_WRITE_SUPPORTED\n   png_structp write_ptr;\n   png_infop write_info_ptr;\n   png_infop write_end_info_ptr;\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   int interlace_preserved = 1;\n#endif /* WRITE_FILTER */\n#else /* !WRITE */\n   png_structp write_ptr = NULL;\n   png_infop write_info_ptr = NULL;\n   png_infop write_end_info_ptr = NULL;\n#endif /* !WRITE */\n   png_bytep row_buf;\n   png_uint_32 y;\n   png_uint_32 width, height;\n   volatile int num_passes;\n   int pass;\n   int bit_depth, color_type;\n\n   row_buf = NULL;\n   error_parameters.file_name = inname;\n\n   if ((fpin = fopen(inname, \"rb\")) == NULL)\n   {\n      fprintf(STDERR, \"Could not find input file %s\\n\", inname);\n      return (1);\n   }\n\n   if ((fpout = fopen(outname, \"wb\")) == NULL)\n   {\n      fprintf(STDERR, \"Could not open output file %s\\n\", outname);\n      FCLOSE(fpin);\n      return (1);\n   }\n\n   pngtest_debug(\"Allocating read and write structures\");\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n   read_ptr =\n       png_create_read_struct_2(PNG_LIBPNG_VER_STRING, NULL,\n       NULL, NULL, NULL, png_debug_malloc, png_debug_free);\n#else\n   read_ptr =\n       png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\n#endif\n   png_set_error_fn(read_ptr, &error_parameters, pngtest_error,\n       pngtest_warning);\n\n#ifdef PNG_WRITE_SUPPORTED\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n   write_ptr =\n       png_create_write_struct_2(PNG_LIBPNG_VER_STRING, NULL,\n       NULL, NULL, NULL, png_debug_malloc, png_debug_free);\n#else\n   write_ptr =\n       png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\n#endif\n   png_set_error_fn(write_ptr, &error_parameters, pngtest_error,\n       pngtest_warning);\n#endif\n   pngtest_debug(\"Allocating read_info, write_info and end_info structures\");\n   read_info_ptr = png_create_info_struct(read_ptr);\n   end_info_ptr = png_create_info_struct(read_ptr);\n#ifdef PNG_WRITE_SUPPORTED\n   write_info_ptr = png_create_info_struct(write_ptr);\n   write_end_info_ptr = png_create_info_struct(write_ptr);\n#endif\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n   init_callback_info(read_info_ptr);\n   png_set_read_user_chunk_fn(read_ptr, &user_chunk_data,\n       read_user_chunk_callback);\n#endif\n\n#ifdef PNG_SET_USER_LIMITS_SUPPORTED\n#  ifdef CHUNK_LIMIT /* from the build, for testing */\n      png_set_chunk_malloc_max(read_ptr, CHUNK_LIMIT);\n#  endif /* CHUNK_LIMIT */\n#endif\n\n#ifdef PNG_SETJMP_SUPPORTED\n   pngtest_debug(\"Setting jmpbuf for read struct\");\n   if (setjmp(png_jmpbuf(read_ptr)))\n   {\n      fprintf(STDERR, \"%s -> %s: libpng read error\\n\", inname, outname);\n      png_free(read_ptr, row_buf);\n      row_buf = NULL;\n      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\n#ifdef PNG_WRITE_SUPPORTED\n      png_destroy_info_struct(write_ptr, &write_end_info_ptr);\n      png_destroy_write_struct(&write_ptr, &write_info_ptr);\n#endif\n      FCLOSE(fpin);\n      FCLOSE(fpout);\n      return (1);\n   }\n\n#ifdef PNG_WRITE_SUPPORTED\n   pngtest_debug(\"Setting jmpbuf for write struct\");\n\n   if (setjmp(png_jmpbuf(write_ptr)))\n   {\n      fprintf(STDERR, \"%s -> %s: libpng write error\\n\", inname, outname);\n      png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\n      png_destroy_info_struct(write_ptr, &write_end_info_ptr);\n#ifdef PNG_WRITE_SUPPORTED\n      png_destroy_write_struct(&write_ptr, &write_info_ptr);\n#endif\n      FCLOSE(fpin);\n      FCLOSE(fpout);\n      return (1);\n   }\n#endif\n#endif\n\n   if (strict != 0)\n   {\n      /* Treat png_benign_error() as errors on read */\n      png_set_benign_errors(read_ptr, 0);\n\n#ifdef PNG_WRITE_SUPPORTED\n      /* Treat them as errors on write */\n      png_set_benign_errors(write_ptr, 0);\n#endif\n\n      /* if strict is not set, then app warnings and errors are treated as\n       * warnings in release builds, but not in unstable builds; this can be\n       * changed with '--relaxed'.\n       */\n   }\n\n   else if (relaxed != 0)\n   {\n      /* Allow application (pngtest) errors and warnings to pass */\n      png_set_benign_errors(read_ptr, 1);\n\n#ifdef PNG_WRITE_SUPPORTED\n      png_set_benign_errors(write_ptr, 1);\n#endif\n   }\n\n   pngtest_debug(\"Initializing input and output streams\");\n#ifdef PNG_STDIO_SUPPORTED\n   png_init_io(read_ptr, fpin);\n#  ifdef PNG_WRITE_SUPPORTED\n   png_init_io(write_ptr, fpout);\n#  endif\n#else\n   png_set_read_fn(read_ptr, (png_voidp)fpin, pngtest_read_data);\n#  ifdef PNG_WRITE_SUPPORTED\n   png_set_write_fn(write_ptr, (png_voidp)fpout,  pngtest_write_data,\n#    ifdef PNG_WRITE_FLUSH_SUPPORTED\n       pngtest_flush);\n#    else\n       NULL);\n#    endif\n#  endif\n#endif\n\n   if (status_dots_requested == 1)\n   {\n#ifdef PNG_WRITE_SUPPORTED\n      png_set_write_status_fn(write_ptr, write_row_callback);\n#endif\n      png_set_read_status_fn(read_ptr, read_row_callback);\n   }\n\n   else\n   {\n#ifdef PNG_WRITE_SUPPORTED\n      png_set_write_status_fn(write_ptr, NULL);\n#endif\n      png_set_read_status_fn(read_ptr, NULL);\n   }\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n   png_set_read_user_transform_fn(read_ptr, read_user_callback);\n#endif\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n   zero_samples = 0;\n   png_set_write_user_transform_fn(write_ptr, count_zero_samples);\n#endif\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n   /* Preserve all the unknown chunks, if possible.  If this is disabled then,\n    * even if the png_{get,set}_unknown_chunks stuff is enabled, we can't use\n    * libpng to *save* the unknown chunks on read (because we can't switch the\n    * save option on!)\n    *\n    * Notice that if SET_UNKNOWN_CHUNKS is *not* supported read will discard all\n    * unknown chunks and write will write them all.\n    */\n#ifdef PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n   png_set_keep_unknown_chunks(read_ptr, PNG_HANDLE_CHUNK_ALWAYS,\n       NULL, 0);\n#endif\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n   png_set_keep_unknown_chunks(write_ptr, PNG_HANDLE_CHUNK_ALWAYS,\n       NULL, 0);\n#endif\n#endif\n\n   pngtest_debug(\"Reading info struct\");\n   png_read_info(read_ptr, read_info_ptr);\n\n#ifdef PNG_READ_USER_CHUNKS_SUPPORTED\n   /* This is a bit of a hack; there is no obvious way in the callback function\n    * to determine that the chunks before the first IDAT have been read, so\n    * remove the info_ptr (which is only used to determine position relative to\n    * PLTE) here to indicate that we are after the IDAT.\n    */\n   user_chunk_data.info_ptr = NULL;\n#endif\n\n   pngtest_debug(\"Transferring info struct\");\n   {\n      int interlace_type, compression_type, filter_type;\n\n      if (png_get_IHDR(read_ptr, read_info_ptr, &width, &height, &bit_depth,\n          &color_type, &interlace_type, &compression_type, &filter_type) != 0)\n      {\n         png_set_IHDR(write_ptr, write_info_ptr, width, height, bit_depth,\n             color_type, interlace_type, compression_type, filter_type);\n         /* num_passes may not be available below if interlace support is not\n          * provided by libpng for both read and write.\n          */\n         switch (interlace_type)\n         {\n            case PNG_INTERLACE_NONE:\n               num_passes = 1;\n               break;\n\n            case PNG_INTERLACE_ADAM7:\n               num_passes = 7;\n               break;\n\n            default:\n               png_error(read_ptr, \"invalid interlace type\");\n               /*NOT REACHED*/\n         }\n      }\n\n      else\n         png_error(read_ptr, \"png_get_IHDR failed\");\n   }\n#ifdef PNG_FIXED_POINT_SUPPORTED\n#ifdef PNG_cHRM_SUPPORTED\n   {\n      png_fixed_point white_x, white_y, red_x, red_y, green_x, green_y, blue_x,\n          blue_y;\n\n      if (png_get_cHRM_fixed(read_ptr, read_info_ptr, &white_x, &white_y,\n          &red_x, &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)\n      {\n         png_set_cHRM_fixed(write_ptr, write_info_ptr, white_x, white_y, red_x,\n             red_y, green_x, green_y, blue_x, blue_y);\n      }\n   }\n#endif\n#ifdef PNG_gAMA_SUPPORTED\n   {\n      png_fixed_point gamma;\n\n      if (png_get_gAMA_fixed(read_ptr, read_info_ptr, &gamma) != 0)\n         png_set_gAMA_fixed(write_ptr, write_info_ptr, gamma);\n   }\n#endif\n#else /* Use floating point versions */\n#ifdef PNG_FLOATING_POINT_SUPPORTED\n#ifdef PNG_cHRM_SUPPORTED\n   {\n      double white_x, white_y, red_x, red_y, green_x, green_y, blue_x,\n          blue_y;\n\n      if (png_get_cHRM(read_ptr, read_info_ptr, &white_x, &white_y, &red_x,\n          &red_y, &green_x, &green_y, &blue_x, &blue_y) != 0)\n      {\n         png_set_cHRM(write_ptr, write_info_ptr, white_x, white_y, red_x,\n             red_y, green_x, green_y, blue_x, blue_y);\n      }\n   }\n#endif\n#ifdef PNG_gAMA_SUPPORTED\n   {\n      double gamma;\n\n      if (png_get_gAMA(read_ptr, read_info_ptr, &gamma) != 0)\n         png_set_gAMA(write_ptr, write_info_ptr, gamma);\n   }\n#endif\n#endif /* Floating point */\n#endif /* Fixed point */\n#ifdef PNG_iCCP_SUPPORTED\n   {\n      png_charp name;\n      png_bytep profile;\n      png_uint_32 proflen;\n      int compression_type;\n\n      if (png_get_iCCP(read_ptr, read_info_ptr, &name, &compression_type,\n          &profile, &proflen) != 0)\n      {\n         png_set_iCCP(write_ptr, write_info_ptr, name, compression_type,\n             profile, proflen);\n      }\n   }\n#endif\n#ifdef PNG_sRGB_SUPPORTED\n   {\n      int intent;\n\n      if (png_get_sRGB(read_ptr, read_info_ptr, &intent) != 0)\n         png_set_sRGB(write_ptr, write_info_ptr, intent);\n   }\n#endif\n   {\n      png_colorp palette;\n      int num_palette;\n\n      if (png_get_PLTE(read_ptr, read_info_ptr, &palette, &num_palette) != 0)\n         png_set_PLTE(write_ptr, write_info_ptr, palette, num_palette);\n   }\n#ifdef PNG_bKGD_SUPPORTED\n   {\n      png_color_16p background;\n\n      if (png_get_bKGD(read_ptr, read_info_ptr, &background) != 0)\n      {\n         png_set_bKGD(write_ptr, write_info_ptr, background);\n      }\n   }\n#endif\n#ifdef PNG_hIST_SUPPORTED\n   {\n      png_uint_16p hist;\n\n      if (png_get_hIST(read_ptr, read_info_ptr, &hist) != 0)\n         png_set_hIST(write_ptr, write_info_ptr, hist);\n   }\n#endif\n#ifdef PNG_oFFs_SUPPORTED\n   {\n      png_int_32 offset_x, offset_y;\n      int unit_type;\n\n      if (png_get_oFFs(read_ptr, read_info_ptr, &offset_x, &offset_y,\n          &unit_type) != 0)\n      {\n         png_set_oFFs(write_ptr, write_info_ptr, offset_x, offset_y, unit_type);\n      }\n   }\n#endif\n#ifdef PNG_pCAL_SUPPORTED\n   {\n      png_charp purpose, units;\n      png_charpp params;\n      png_int_32 X0, X1;\n      int type, nparams;\n\n      if (png_get_pCAL(read_ptr, read_info_ptr, &purpose, &X0, &X1, &type,\n          &nparams, &units, &params) != 0)\n      {\n         png_set_pCAL(write_ptr, write_info_ptr, purpose, X0, X1, type,\n             nparams, units, params);\n      }\n   }\n#endif\n#ifdef PNG_pHYs_SUPPORTED\n   {\n      png_uint_32 res_x, res_y;\n      int unit_type;\n\n      if (png_get_pHYs(read_ptr, read_info_ptr, &res_x, &res_y,\n          &unit_type) != 0)\n         png_set_pHYs(write_ptr, write_info_ptr, res_x, res_y, unit_type);\n   }\n#endif\n#ifdef PNG_sBIT_SUPPORTED\n   {\n      png_color_8p sig_bit;\n\n      if (png_get_sBIT(read_ptr, read_info_ptr, &sig_bit) != 0)\n         png_set_sBIT(write_ptr, write_info_ptr, sig_bit);\n   }\n#endif\n#ifdef PNG_sCAL_SUPPORTED\n#if defined(PNG_FLOATING_POINT_SUPPORTED) && \\\n   defined(PNG_FLOATING_ARITHMETIC_SUPPORTED)\n   {\n      int unit;\n      double scal_width, scal_height;\n\n      if (png_get_sCAL(read_ptr, read_info_ptr, &unit, &scal_width,\n          &scal_height) != 0)\n      {\n         png_set_sCAL(write_ptr, write_info_ptr, unit, scal_width, scal_height);\n      }\n   }\n#else\n#ifdef PNG_FIXED_POINT_SUPPORTED\n   {\n      int unit;\n      png_charp scal_width, scal_height;\n\n      if (png_get_sCAL_s(read_ptr, read_info_ptr, &unit, &scal_width,\n           &scal_height) != 0)\n      {\n         png_set_sCAL_s(write_ptr, write_info_ptr, unit, scal_width,\n             scal_height);\n      }\n   }\n#endif\n#endif\n#endif\n\n#ifdef PNG_sPLT_SUPPORTED\n   {\n       png_sPLT_tp entries;\n\n       int num_entries = (int) png_get_sPLT(read_ptr, read_info_ptr, &entries);\n       if (num_entries)\n       {\n           png_set_sPLT(write_ptr, write_info_ptr, entries, num_entries);\n       }\n   }\n#endif\n\n#ifdef PNG_TEXT_SUPPORTED\n   {\n      png_textp text_ptr;\n      int num_text;\n\n      if (png_get_text(read_ptr, read_info_ptr, &text_ptr, &num_text) > 0)\n      {\n         pngtest_debug1(\"Handling %d iTXt/tEXt/zTXt chunks\", num_text);\n\n         pngtest_check_text_support(read_ptr, text_ptr, num_text);\n\n         if (verbose != 0)\n         {\n            int i;\n\n            printf(\"\\n\");\n            for (i=0; i<num_text; i++)\n            {\n               printf(\"   Text compression[%d]=%d\\n\",\n                   i, text_ptr[i].compression);\n            }\n         }\n\n         png_set_text(write_ptr, write_info_ptr, text_ptr, num_text);\n      }\n   }\n#endif\n#ifdef PNG_tIME_SUPPORTED\n   {\n      png_timep mod_time;\n\n      if (png_get_tIME(read_ptr, read_info_ptr, &mod_time) != 0)\n      {\n         png_set_tIME(write_ptr, write_info_ptr, mod_time);\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n         if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)\n            tIME_string[(sizeof tIME_string) - 1] = '\\0';\n\n         else\n         {\n            strncpy(tIME_string, \"*** invalid time ***\", (sizeof tIME_string));\n            tIME_string[(sizeof tIME_string) - 1] = '\\0';\n         }\n\n         tIME_chunk_present++;\n#endif /* TIME_RFC1123 */\n      }\n   }\n#endif\n#ifdef PNG_tRNS_SUPPORTED\n   {\n      png_bytep trans_alpha;\n      int num_trans;\n      png_color_16p trans_color;\n\n      if (png_get_tRNS(read_ptr, read_info_ptr, &trans_alpha, &num_trans,\n          &trans_color) != 0)\n      {\n         int sample_max = (1 << bit_depth);\n         /* libpng doesn't reject a tRNS chunk with out-of-range samples */\n         if (!((color_type == PNG_COLOR_TYPE_GRAY &&\n             (int)trans_color->gray > sample_max) ||\n             (color_type == PNG_COLOR_TYPE_RGB &&\n             ((int)trans_color->red > sample_max ||\n             (int)trans_color->green > sample_max ||\n             (int)trans_color->blue > sample_max))))\n            png_set_tRNS(write_ptr, write_info_ptr, trans_alpha, num_trans,\n               trans_color);\n      }\n   }\n#endif\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n   {\n      png_unknown_chunkp unknowns;\n      int num_unknowns = png_get_unknown_chunks(read_ptr, read_info_ptr,\n          &unknowns);\n\n      if (num_unknowns != 0)\n      {\n         png_set_unknown_chunks(write_ptr, write_info_ptr, unknowns,\n             num_unknowns);\n#if PNG_LIBPNG_VER < 10600\n         /* Copy the locations from the read_info_ptr.  The automatically\n          * generated locations in write_end_info_ptr are wrong prior to 1.6.0\n          * because they are reset from the write pointer (removed in 1.6.0).\n          */\n         {\n            int i;\n            for (i = 0; i < num_unknowns; i++)\n              png_set_unknown_chunk_location(write_ptr, write_info_ptr, i,\n                  unknowns[i].location);\n         }\n#endif\n      }\n   }\n#endif\n\n#ifdef PNG_WRITE_SUPPORTED\n   pngtest_debug(\"Writing info struct\");\n\n   /* Write the info in two steps so that if we write the 'unknown' chunks here\n    * they go to the correct place.\n    */\n   png_write_info_before_PLTE(write_ptr, write_info_ptr);\n\n   write_chunks(write_ptr, before_PLTE); /* before PLTE */\n\n   png_write_info(write_ptr, write_info_ptr);\n\n   write_chunks(write_ptr, before_IDAT); /* after PLTE */\n#endif\n\n#ifdef SINGLE_ROWBUF_ALLOC\n   pngtest_debug(\"Allocating row buffer...\");\n   row_buf = (png_bytep)png_malloc(read_ptr,\n       png_get_rowbytes(read_ptr, read_info_ptr));\n\n   pngtest_debug1(\"\\t0x%08lx\", (unsigned long)row_buf);\n#endif /* SINGLE_ROWBUF_ALLOC */\n   pngtest_debug(\"Writing row data\");\n\n#if defined(PNG_READ_INTERLACING_SUPPORTED) &&\\\n   defined(PNG_WRITE_INTERLACING_SUPPORTED)\n   /* Both must be defined for libpng to be able to handle the interlace,\n    * otherwise it gets handled below by simply reading and writing the passes\n    * directly.\n    */\n   if (png_set_interlace_handling(read_ptr) != num_passes)\n      png_error(write_ptr,\n          \"png_set_interlace_handling(read): wrong pass count \");\n   if (png_set_interlace_handling(write_ptr) != num_passes)\n      png_error(write_ptr,\n          \"png_set_interlace_handling(write): wrong pass count \");\n#else /* png_set_interlace_handling not called on either read or write */\n#  define calc_pass_height\n#endif /* not using libpng interlace handling */\n\n#ifdef PNGTEST_TIMING\n   t_stop = (float)clock();\n   t_misc += (t_stop - t_start);\n   t_start = t_stop;\n#endif\n   for (pass = 0; pass < num_passes; pass++)\n   {\n#     ifdef calc_pass_height\n         png_uint_32 pass_height;\n\n         if (num_passes == 7) /* interlaced */\n         {\n            if (PNG_PASS_COLS(width, pass) > 0)\n               pass_height = PNG_PASS_ROWS(height, pass);\n\n            else\n               pass_height = 0;\n         }\n\n         else /* not interlaced */\n            pass_height = height;\n#     else\n#        define pass_height height\n#     endif\n\n      pngtest_debug1(\"Writing row data for pass %d\", pass);\n      for (y = 0; y < pass_height; y++)\n      {\n#ifndef SINGLE_ROWBUF_ALLOC\n         pngtest_debug2(\"Allocating row buffer (pass %d, y = %u)...\", pass, y);\n\n         row_buf = (png_bytep)png_malloc(read_ptr,\n             png_get_rowbytes(read_ptr, read_info_ptr));\n\n         pngtest_debug2(\"\\t0x%08lx (%lu bytes)\", (unsigned long)row_buf,\n             (unsigned long)png_get_rowbytes(read_ptr, read_info_ptr));\n\n#endif /* !SINGLE_ROWBUF_ALLOC */\n         png_read_rows(read_ptr, (png_bytepp)&row_buf, NULL, 1);\n\n#ifdef PNG_WRITE_SUPPORTED\n#ifdef PNGTEST_TIMING\n         t_stop = (float)clock();\n         t_decode += (t_stop - t_start);\n         t_start = t_stop;\n#endif\n         png_write_rows(write_ptr, (png_bytepp)&row_buf, 1);\n#ifdef PNGTEST_TIMING\n         t_stop = (float)clock();\n         t_encode += (t_stop - t_start);\n         t_start = t_stop;\n#endif\n#endif /* WRITE */\n\n#ifndef SINGLE_ROWBUF_ALLOC\n         pngtest_debug2(\"Freeing row buffer (pass %d, y = %u)\", pass, y);\n         png_free(read_ptr, row_buf);\n         row_buf = NULL;\n#endif /* !SINGLE_ROWBUF_ALLOC */\n      }\n   }\n\n#ifdef PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n#  ifdef PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n      png_free_data(read_ptr, read_info_ptr, PNG_FREE_UNKN, -1);\n#  endif\n#  ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n      png_free_data(write_ptr, write_info_ptr, PNG_FREE_UNKN, -1);\n#  endif\n#endif\n\n   pngtest_debug(\"Reading and writing end_info data\");\n\n   png_read_end(read_ptr, end_info_ptr);\n#ifdef PNG_TEXT_SUPPORTED\n   {\n      png_textp text_ptr;\n      int num_text;\n\n      if (png_get_text(read_ptr, end_info_ptr, &text_ptr, &num_text) > 0)\n      {\n         pngtest_debug1(\"Handling %d iTXt/tEXt/zTXt chunks\", num_text);\n\n         pngtest_check_text_support(read_ptr, text_ptr, num_text);\n\n         if (verbose != 0)\n         {\n            int i;\n\n            printf(\"\\n\");\n            for (i=0; i<num_text; i++)\n            {\n               printf(\"   Text compression[%d]=%d\\n\",\n                   i, text_ptr[i].compression);\n            }\n         }\n\n         png_set_text(write_ptr, write_end_info_ptr, text_ptr, num_text);\n      }\n   }\n#endif\n#ifdef PNG_tIME_SUPPORTED\n   {\n      png_timep mod_time;\n\n      if (png_get_tIME(read_ptr, end_info_ptr, &mod_time) != 0)\n      {\n         png_set_tIME(write_ptr, write_end_info_ptr, mod_time);\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n         if (png_convert_to_rfc1123_buffer(tIME_string, mod_time) != 0)\n            tIME_string[(sizeof tIME_string) - 1] = '\\0';\n\n         else\n         {\n            strncpy(tIME_string, \"*** invalid time ***\", sizeof tIME_string);\n            tIME_string[(sizeof tIME_string)-1] = '\\0';\n         }\n\n         tIME_chunk_present++;\n#endif /* TIME_RFC1123 */\n      }\n   }\n#endif\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n   {\n      png_unknown_chunkp unknowns;\n      int num_unknowns = png_get_unknown_chunks(read_ptr, end_info_ptr,\n          &unknowns);\n\n      if (num_unknowns != 0)\n      {\n         png_set_unknown_chunks(write_ptr, write_end_info_ptr, unknowns,\n             num_unknowns);\n#if PNG_LIBPNG_VER < 10600\n         /* Copy the locations from the read_info_ptr.  The automatically\n          * generated locations in write_end_info_ptr are wrong prior to 1.6.0\n          * because they are reset from the write pointer (removed in 1.6.0).\n          */\n         {\n            int i;\n            for (i = 0; i < num_unknowns; i++)\n              png_set_unknown_chunk_location(write_ptr, write_end_info_ptr, i,\n                  unknowns[i].location);\n         }\n#endif\n      }\n   }\n#endif\n\n#ifdef PNG_WRITE_SUPPORTED\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n   /* Normally one would use Z_DEFAULT_STRATEGY for text compression.\n    * This is here just to make pngtest replicate the results from libpng\n    * versions prior to 1.5.4, and to test this new API.\n    */\n   png_set_text_compression_strategy(write_ptr, Z_FILTERED);\n#endif\n\n   /* When the unknown vpAg/sTER chunks are written by pngtest the only way to\n    * do it is to write them *before* calling png_write_end.  When unknown\n    * chunks are written by libpng, however, they are written just before IEND.\n    * There seems to be no way round this, however vpAg/sTER are not expected\n    * after IDAT.\n    */\n   write_chunks(write_ptr, after_IDAT);\n\n   png_write_end(write_ptr, write_end_info_ptr);\n#endif\n\n#ifdef PNG_EASY_ACCESS_SUPPORTED\n   if (verbose != 0)\n   {\n      png_uint_32 iwidth, iheight;\n      iwidth = png_get_image_width(write_ptr, write_info_ptr);\n      iheight = png_get_image_height(write_ptr, write_info_ptr);\n      fprintf(STDERR, \"\\n Image width = %lu, height = %lu\\n\",\n          (unsigned long)iwidth, (unsigned long)iheight);\n   }\n#endif\n\n   pngtest_debug(\"Destroying data structs\");\n#ifdef SINGLE_ROWBUF_ALLOC\n   pngtest_debug(\"destroying row_buf for read_ptr\");\n   png_free(read_ptr, row_buf);\n   row_buf = NULL;\n#endif /* SINGLE_ROWBUF_ALLOC */\n   pngtest_debug(\"destroying read_ptr, read_info_ptr, end_info_ptr\");\n   png_destroy_read_struct(&read_ptr, &read_info_ptr, &end_info_ptr);\n#ifdef PNG_WRITE_SUPPORTED\n   pngtest_debug(\"destroying write_end_info_ptr\");\n   png_destroy_info_struct(write_ptr, &write_end_info_ptr);\n   pngtest_debug(\"destroying write_ptr, write_info_ptr\");\n   png_destroy_write_struct(&write_ptr, &write_info_ptr);\n#endif\n   pngtest_debug(\"Destruction complete.\");\n\n   FCLOSE(fpin);\n   FCLOSE(fpout);\n\n   /* Summarize any warnings or errors and in 'strict' mode fail the test.\n    * Unsupported chunks can result in warnings, in that case ignore the strict\n    * setting, otherwise fail the test on warnings as well as errors.\n    */\n   if (error_count > 0)\n   {\n      /* We don't really expect to get here because of the setjmp handling\n       * above, but this is safe.\n       */\n      fprintf(STDERR, \"\\n  %s: %d libpng errors found (%d warnings)\",\n          inname, error_count, warning_count);\n\n      if (strict != 0)\n         return (1);\n   }\n\n#  ifdef PNG_WRITE_SUPPORTED\n      /* If there is no write support nothing was written! */\n      else if (unsupported_chunks > 0)\n      {\n         fprintf(STDERR, \"\\n  %s: unsupported chunks (%d)%s\",\n             inname, unsupported_chunks, strict ? \": IGNORED --strict!\" : \"\");\n      }\n#  endif\n\n   else if (warning_count > 0)\n   {\n      fprintf(STDERR, \"\\n  %s: %d libpng warnings found\",\n          inname, warning_count);\n\n      if (strict != 0)\n         return (1);\n   }\n\n   pngtest_debug(\"Opening files for comparison\");\n   if ((fpin = fopen(inname, \"rb\")) == NULL)\n   {\n      fprintf(STDERR, \"Could not find file %s\\n\", inname);\n      return (1);\n   }\n\n   if ((fpout = fopen(outname, \"rb\")) == NULL)\n   {\n      fprintf(STDERR, \"Could not find file %s\\n\", outname);\n      FCLOSE(fpin);\n      return (1);\n   }\n\n#if defined (PNG_WRITE_SUPPORTED) /* else nothing was written */ &&\\\n    defined (PNG_WRITE_FILTER_SUPPORTED)\n   if (interlace_preserved != 0) /* else the files will be changed */\n   {\n      for (;;)\n      {\n         static int wrote_question = 0;\n         png_size_t num_in, num_out;\n         char inbuf[256], outbuf[256];\n\n         num_in = fread(inbuf, 1, sizeof inbuf, fpin);\n         num_out = fread(outbuf, 1, sizeof outbuf, fpout);\n\n         if (num_in != num_out)\n         {\n            fprintf(STDERR, \"\\nFiles %s and %s are of a different size\\n\",\n                inname, outname);\n\n            if (wrote_question == 0 && unsupported_chunks == 0)\n            {\n               fprintf(STDERR,\n                   \"   Was %s written with the same maximum IDAT\"\n                   \" chunk size (%d bytes),\",\n                   inname, PNG_ZBUF_SIZE);\n               fprintf(STDERR,\n                   \"\\n   filtering heuristic (libpng default), compression\");\n               fprintf(STDERR,\n                   \" level (zlib default),\\n   and zlib version (%s)?\\n\\n\",\n                   ZLIB_VERSION);\n               wrote_question = 1;\n            }\n\n            FCLOSE(fpin);\n            FCLOSE(fpout);\n\n            if (strict != 0 && unsupported_chunks == 0)\n              return (1);\n\n            else\n              return (0);\n         }\n\n         if (num_in == 0)\n            break;\n\n         if (memcmp(inbuf, outbuf, num_in))\n         {\n            fprintf(STDERR, \"\\nFiles %s and %s are different\\n\", inname,\n                outname);\n\n            if (wrote_question == 0 && unsupported_chunks == 0)\n            {\n               fprintf(STDERR,\n                   \"   Was %s written with the same maximum\"\n                   \" IDAT chunk size (%d bytes),\",\n                    inname, PNG_ZBUF_SIZE);\n               fprintf(STDERR,\n                   \"\\n   filtering heuristic (libpng default), compression\");\n               fprintf(STDERR,\n                   \" level (zlib default),\\n   and zlib version (%s)?\\n\\n\",\n                 ZLIB_VERSION);\n               wrote_question = 1;\n            }\n\n            FCLOSE(fpin);\n            FCLOSE(fpout);\n\n            /* NOTE: the unsupported_chunks escape is permitted here because\n             * unsupported text chunk compression will result in the compression\n             * mode being changed (to NONE) yet, in the test case, the result\n             * can be exactly the same size!\n             */\n            if (strict != 0 && unsupported_chunks == 0)\n              return (1);\n\n            else\n              return (0);\n         }\n      }\n   }\n#endif /* WRITE && WRITE_FILTER */\n\n   FCLOSE(fpin);\n   FCLOSE(fpout);\n\n   return (0);\n}\n\n/* Input and output filenames */\n#ifdef RISCOS\nstatic PNG_CONST char *inname = \"pngtest/png\";\nstatic PNG_CONST char *outname = \"pngout/png\";\n#else\nstatic PNG_CONST char *inname = \"pngtest.png\";\nstatic PNG_CONST char *outname = \"pngout.png\";\n#endif\n\nint\nmain(int argc, char *argv[])\n{\n   int multiple = 0;\n   int ierror = 0;\n\n   png_structp dummy_ptr;\n\n   fprintf(STDERR, \"\\n Testing libpng version %s\\n\", PNG_LIBPNG_VER_STRING);\n   fprintf(STDERR, \"   with zlib   version %s\\n\", ZLIB_VERSION);\n   fprintf(STDERR, \"%s\", png_get_copyright(NULL));\n   /* Show the version of libpng used in building the library */\n   fprintf(STDERR, \" library (%lu):%s\",\n       (unsigned long)png_access_version_number(),\n       png_get_header_version(NULL));\n\n   /* Show the version of libpng used in building the application */\n   fprintf(STDERR, \" pngtest (%lu):%s\", (unsigned long)PNG_LIBPNG_VER,\n       PNG_HEADER_VERSION_STRING);\n\n   /* Do some consistency checking on the memory allocation settings, I'm\n    * not sure this matters, but it is nice to know, the first of these\n    * tests should be impossible because of the way the macros are set\n    * in pngconf.h\n    */\n#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)\n      fprintf(STDERR, \" NOTE: Zlib compiled for max 64k, libpng not\\n\");\n#endif\n   /* I think the following can happen. */\n#if !defined(MAXSEG_64K) && defined(PNG_MAX_MALLOC_64K)\n      fprintf(STDERR, \" NOTE: libpng compiled for max 64k, zlib not\\n\");\n#endif\n\n   if (strcmp(png_libpng_ver, PNG_LIBPNG_VER_STRING))\n   {\n      fprintf(STDERR,\n          \"Warning: versions are different between png.h and png.c\\n\");\n      fprintf(STDERR, \"  png.h version: %s\\n\", PNG_LIBPNG_VER_STRING);\n      fprintf(STDERR, \"  png.c version: %s\\n\\n\", png_libpng_ver);\n      ++ierror;\n   }\n\n   if (argc > 1)\n   {\n      if (strcmp(argv[1], \"-m\") == 0)\n      {\n         multiple = 1;\n         status_dots_requested = 0;\n      }\n\n      else if (strcmp(argv[1], \"-mv\") == 0 ||\n               strcmp(argv[1], \"-vm\") == 0 )\n      {\n         multiple = 1;\n         verbose = 1;\n         status_dots_requested = 1;\n      }\n\n      else if (strcmp(argv[1], \"-v\") == 0)\n      {\n         verbose = 1;\n         status_dots_requested = 1;\n         inname = argv[2];\n      }\n\n      else if (strcmp(argv[1], \"--strict\") == 0)\n      {\n         status_dots_requested = 0;\n         verbose = 1;\n         inname = argv[2];\n         strict++;\n         relaxed = 0;\n      }\n\n      else if (strcmp(argv[1], \"--relaxed\") == 0)\n      {\n         status_dots_requested = 0;\n         verbose = 1;\n         inname = argv[2];\n         strict = 0;\n         relaxed++;\n      }\n\n      else\n      {\n         inname = argv[1];\n         status_dots_requested = 0;\n      }\n   }\n\n   if (multiple == 0 && argc == 3 + verbose)\n      outname = argv[2 + verbose];\n\n   if ((multiple == 0 && argc > 3 + verbose) ||\n       (multiple != 0 && argc < 2))\n   {\n      fprintf(STDERR,\n          \"usage: %s [infile.png] [outfile.png]\\n\\t%s -m {infile.png}\\n\",\n          argv[0], argv[0]);\n      fprintf(STDERR,\n          \"  reads/writes one PNG file (without -m) or multiple files (-m)\\n\");\n      fprintf(STDERR,\n          \"  with -m %s is used as a temporary file\\n\", outname);\n      exit(1);\n   }\n\n   if (multiple != 0)\n   {\n      int i;\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n      png_alloc_size_t allocation_now = current_allocation;\n#endif\n      for (i=2; i<argc; ++i)\n      {\n         int kerror;\n         fprintf(STDERR, \"\\n Testing %s:\", argv[i]);\n#if PNG_DEBUG > 0\n         fprintf(STDERR, \"\\n\");\n#endif\n         kerror = test_one_file(argv[i], outname);\n         if (kerror == 0)\n         {\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n            fprintf(STDERR, \"\\n PASS (%lu zero samples)\\n\",\n                (unsigned long)zero_samples);\n#else\n            fprintf(STDERR, \" PASS\\n\");\n#endif\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n            if (tIME_chunk_present != 0)\n               fprintf(STDERR, \" tIME = %s\\n\", tIME_string);\n\n            tIME_chunk_present = 0;\n#endif /* TIME_RFC1123 */\n         }\n\n         else\n         {\n            fprintf(STDERR, \" FAIL\\n\");\n            ierror += kerror;\n         }\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n         if (allocation_now != current_allocation)\n            fprintf(STDERR, \"MEMORY ERROR: %lu bytes lost\\n\",\n                (unsigned long)(current_allocation - allocation_now));\n\n         if (current_allocation != 0)\n         {\n            memory_infop pinfo = pinformation;\n\n            fprintf(STDERR, \"MEMORY ERROR: %lu bytes still allocated\\n\",\n                (unsigned long)current_allocation);\n\n            while (pinfo != NULL)\n            {\n               fprintf(STDERR, \" %lu bytes at %p\\n\",\n                   (unsigned long)pinfo->size,\n                   pinfo->pointer);\n               pinfo = pinfo->next;\n            }\n         }\n#endif\n      }\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n         fprintf(STDERR, \" Current memory allocation: %20lu bytes\\n\",\n             (unsigned long)current_allocation);\n         fprintf(STDERR, \" Maximum memory allocation: %20lu bytes\\n\",\n             (unsigned long) maximum_allocation);\n         fprintf(STDERR, \" Total   memory allocation: %20lu bytes\\n\",\n             (unsigned long)total_allocation);\n         fprintf(STDERR, \"     Number of allocations: %20lu\\n\",\n             (unsigned long)num_allocations);\n#endif\n   }\n\n   else\n   {\n      int i;\n      for (i = 0; i<3; ++i)\n      {\n         int kerror;\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n         png_alloc_size_t allocation_now = current_allocation;\n#endif\n         if (i == 1)\n            status_dots_requested = 1;\n\n         else if (verbose == 0)\n            status_dots_requested = 0;\n\n         if (i == 0 || verbose == 1 || ierror != 0)\n         {\n            fprintf(STDERR, \"\\n Testing %s:\", inname);\n#if PNG_DEBUG > 0\n            fprintf(STDERR, \"\\n\");\n#endif\n         }\n\n         kerror = test_one_file(inname, outname);\n\n         if (kerror == 0)\n         {\n            if (verbose == 1 || i == 2)\n            {\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n                fprintf(STDERR, \"\\n PASS (%lu zero samples)\\n\",\n                    (unsigned long)zero_samples);\n#else\n                fprintf(STDERR, \" PASS\\n\");\n#endif\n#ifdef PNG_TIME_RFC1123_SUPPORTED\n             if (tIME_chunk_present != 0)\n                fprintf(STDERR, \" tIME = %s\\n\", tIME_string);\n#endif /* TIME_RFC1123 */\n            }\n         }\n\n         else\n         {\n            if (verbose == 0 && i != 2)\n            {\n               fprintf(STDERR, \"\\n Testing %s:\", inname);\n#if PNG_DEBUG > 0\n               fprintf(STDERR, \"\\n\");\n#endif\n            }\n\n            fprintf(STDERR, \" FAIL\\n\");\n            ierror += kerror;\n         }\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n         if (allocation_now != current_allocation)\n             fprintf(STDERR, \"MEMORY ERROR: %lu bytes lost\\n\",\n                 (unsigned long)(current_allocation - allocation_now));\n\n         if (current_allocation != 0)\n         {\n             memory_infop pinfo = pinformation;\n\n             fprintf(STDERR, \"MEMORY ERROR: %lu bytes still allocated\\n\",\n                 (unsigned long)current_allocation);\n\n             while (pinfo != NULL)\n             {\n                fprintf(STDERR, \" %lu bytes at %p\\n\",\n                    (unsigned long)pinfo->size, pinfo->pointer);\n                pinfo = pinfo->next;\n             }\n          }\n#endif\n       }\n#if defined(PNG_USER_MEM_SUPPORTED) && PNG_DEBUG\n       fprintf(STDERR, \" Current memory allocation: %20lu bytes\\n\",\n           (unsigned long)current_allocation);\n       fprintf(STDERR, \" Maximum memory allocation: %20lu bytes\\n\",\n           (unsigned long)maximum_allocation);\n       fprintf(STDERR, \" Total   memory allocation: %20lu bytes\\n\",\n           (unsigned long)total_allocation);\n       fprintf(STDERR, \"     Number of allocations: %20lu\\n\",\n           (unsigned long)num_allocations);\n#endif\n   }\n\n#ifdef PNGTEST_TIMING\n   t_stop = (float)clock();\n   t_misc += (t_stop - t_start);\n   t_start = t_stop;\n   fprintf(STDERR, \" CPU time used = %.3f seconds\",\n       (t_misc+t_decode+t_encode)/(float)CLOCKS_PER_SEC);\n   fprintf(STDERR, \" (decoding %.3f,\\n\",\n       t_decode/(float)CLOCKS_PER_SEC);\n   fprintf(STDERR, \"        encoding %.3f ,\",\n       t_encode/(float)CLOCKS_PER_SEC);\n   fprintf(STDERR, \" other %.3f seconds)\\n\\n\",\n       t_misc/(float)CLOCKS_PER_SEC);\n#endif\n\n   if (ierror == 0)\n      fprintf(STDERR, \" libpng passes test\\n\");\n\n   else\n      fprintf(STDERR, \" libpng FAILS test\\n\");\n\n   dummy_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);\n   fprintf(STDERR, \" Default limits:\\n\");\n   fprintf(STDERR, \"  width_max  = %lu\\n\",\n       (unsigned long) png_get_user_width_max(dummy_ptr));\n   fprintf(STDERR, \"  height_max = %lu\\n\",\n       (unsigned long) png_get_user_height_max(dummy_ptr));\n   if (png_get_chunk_cache_max(dummy_ptr) == 0)\n      fprintf(STDERR, \"  cache_max  = unlimited\\n\");\n   else\n      fprintf(STDERR, \"  cache_max  = %lu\\n\",\n          (unsigned long) png_get_chunk_cache_max(dummy_ptr));\n   if (png_get_chunk_malloc_max(dummy_ptr) == 0)\n      fprintf(STDERR, \"  malloc_max = unlimited\\n\");\n   else\n      fprintf(STDERR, \"  malloc_max = %lu\\n\",\n          (unsigned long) png_get_chunk_malloc_max(dummy_ptr));\n   png_destroy_read_struct(&dummy_ptr, NULL, NULL);\n\n   return (int)(ierror != 0);\n}\n#else\nint\nmain(void)\n{\n   fprintf(STDERR,\n       \" test ignored because libpng was not built with read support\\n\");\n   /* And skip this test */\n   return SKIP;\n}\n#endif\n\n/* Generate a compiler error if there is an old png.h in the search path. */\ntypedef png_libpng_version_1_6_25 Your_png_h_is_not_version_1_6_25;\n"
  },
  {
    "path": "tess-two/jni/libpng/pngtrans.c",
    "content": "\n/* pngtrans.c - transforms the data in a row (used by both readers and writers)\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n\n#if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)\n\n#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)\n/* Turn on BGR-to-RGB mapping */\nvoid PNGAPI\npng_set_bgr(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_bgr\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_BGR;\n}\n#endif\n\n#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)\n/* Turn on 16-bit byte swapping */\nvoid PNGAPI\npng_set_swap(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_swap\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (png_ptr->bit_depth == 16)\n      png_ptr->transformations |= PNG_SWAP_BYTES;\n}\n#endif\n\n#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)\n/* Turn on pixel packing */\nvoid PNGAPI\npng_set_packing(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_packing\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (png_ptr->bit_depth < 8)\n   {\n      png_ptr->transformations |= PNG_PACK;\n#     ifdef PNG_WRITE_SUPPORTED\n         png_ptr->usr_bit_depth = 8;\n#     endif\n   }\n}\n#endif\n\n#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)\n/* Turn on packed pixel swapping */\nvoid PNGAPI\npng_set_packswap(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_packswap\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (png_ptr->bit_depth < 8)\n      png_ptr->transformations |= PNG_PACKSWAP;\n}\n#endif\n\n#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)\nvoid PNGAPI\npng_set_shift(png_structrp png_ptr, png_const_color_8p true_bits)\n{\n   png_debug(1, \"in png_set_shift\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_SHIFT;\n   png_ptr->shift = *true_bits;\n}\n#endif\n\n#if defined(PNG_READ_INTERLACING_SUPPORTED) || \\\n    defined(PNG_WRITE_INTERLACING_SUPPORTED)\nint PNGAPI\npng_set_interlace_handling(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_interlace handling\");\n\n   if (png_ptr != 0 && png_ptr->interlaced != 0)\n   {\n      png_ptr->transformations |= PNG_INTERLACE;\n      return (7);\n   }\n\n   return (1);\n}\n#endif\n\n#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)\n/* Add a filler byte on read, or remove a filler or alpha byte on write.\n * The filler type has changed in v0.95 to allow future 2-byte fillers\n * for 48-bit input data, as well as to avoid problems with some compilers\n * that don't like bytes as parameters.\n */\nvoid PNGAPI\npng_set_filler(png_structrp png_ptr, png_uint_32 filler, int filler_loc)\n{\n   png_debug(1, \"in png_set_filler\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* In libpng 1.6 it is possible to determine whether this is a read or write\n    * operation and therefore to do more checking here for a valid call.\n    */\n   if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0)\n   {\n#     ifdef PNG_READ_FILLER_SUPPORTED\n         /* On read png_set_filler is always valid, regardless of the base PNG\n          * format, because other transformations can give a format where the\n          * filler code can execute (basically an 8 or 16-bit component RGB or G\n          * format.)\n          *\n          * NOTE: usr_channels is not used by the read code!  (This has led to\n          * confusion in the past.)  The filler is only used in the read code.\n          */\n         png_ptr->filler = (png_uint_16)filler;\n#     else\n         png_app_error(png_ptr, \"png_set_filler not supported on read\");\n         PNG_UNUSED(filler) /* not used in the write case */\n         return;\n#     endif\n   }\n\n   else /* write */\n   {\n#     ifdef PNG_WRITE_FILLER_SUPPORTED\n         /* On write the usr_channels parameter must be set correctly at the\n          * start to record the number of channels in the app-supplied data.\n          */\n         switch (png_ptr->color_type)\n         {\n            case PNG_COLOR_TYPE_RGB:\n               png_ptr->usr_channels = 4;\n               break;\n\n            case PNG_COLOR_TYPE_GRAY:\n               if (png_ptr->bit_depth >= 8)\n               {\n                  png_ptr->usr_channels = 2;\n                  break;\n               }\n\n               else\n               {\n                  /* There simply isn't any code in libpng to strip out bits\n                   * from bytes when the components are less than a byte in\n                   * size!\n                   */\n                  png_app_error(png_ptr,\n                      \"png_set_filler is invalid for\"\n                      \" low bit depth gray output\");\n                  return;\n               }\n\n            default:\n               png_app_error(png_ptr,\n                   \"png_set_filler: inappropriate color type\");\n               return;\n         }\n#     else\n         png_app_error(png_ptr, \"png_set_filler not supported on write\");\n         return;\n#     endif\n   }\n\n   /* Here on success - libpng supports the operation, set the transformation\n    * and the flag to say where the filler channel is.\n    */\n   png_ptr->transformations |= PNG_FILLER;\n\n   if (filler_loc == PNG_FILLER_AFTER)\n      png_ptr->flags |= PNG_FLAG_FILLER_AFTER;\n\n   else\n      png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;\n}\n\n/* Added to libpng-1.2.7 */\nvoid PNGAPI\npng_set_add_alpha(png_structrp png_ptr, png_uint_32 filler, int filler_loc)\n{\n   png_debug(1, \"in png_set_add_alpha\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_set_filler(png_ptr, filler, filler_loc);\n   /* The above may fail to do anything. */\n   if ((png_ptr->transformations & PNG_FILLER) != 0)\n      png_ptr->transformations |= PNG_ADD_ALPHA;\n}\n\n#endif\n\n#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \\\n    defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)\nvoid PNGAPI\npng_set_swap_alpha(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_swap_alpha\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_SWAP_ALPHA;\n}\n#endif\n\n#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \\\n    defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)\nvoid PNGAPI\npng_set_invert_alpha(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_invert_alpha\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_INVERT_ALPHA;\n}\n#endif\n\n#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)\nvoid PNGAPI\npng_set_invert_mono(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_set_invert_mono\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_INVERT_MONO;\n}\n\n/* Invert monochrome grayscale data */\nvoid /* PRIVATE */\npng_do_invert(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_invert\");\n\n  /* This test removed from libpng version 1.0.13 and 1.2.0:\n   *   if (row_info->bit_depth == 1 &&\n   */\n   if (row_info->color_type == PNG_COLOR_TYPE_GRAY)\n   {\n      png_bytep rp = row;\n      png_size_t i;\n      png_size_t istop = row_info->rowbytes;\n\n      for (i = 0; i < istop; i++)\n      {\n         *rp = (png_byte)(~(*rp));\n         rp++;\n      }\n   }\n\n   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&\n      row_info->bit_depth == 8)\n   {\n      png_bytep rp = row;\n      png_size_t i;\n      png_size_t istop = row_info->rowbytes;\n\n      for (i = 0; i < istop; i += 2)\n      {\n         *rp = (png_byte)(~(*rp));\n         rp += 2;\n      }\n   }\n\n#ifdef PNG_16BIT_SUPPORTED\n   else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&\n      row_info->bit_depth == 16)\n   {\n      png_bytep rp = row;\n      png_size_t i;\n      png_size_t istop = row_info->rowbytes;\n\n      for (i = 0; i < istop; i += 4)\n      {\n         *rp = (png_byte)(~(*rp));\n         *(rp + 1) = (png_byte)(~(*(rp + 1)));\n         rp += 4;\n      }\n   }\n#endif\n}\n#endif\n\n#ifdef PNG_16BIT_SUPPORTED\n#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)\n/* Swaps byte order on 16-bit depth images */\nvoid /* PRIVATE */\npng_do_swap(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_swap\");\n\n   if (row_info->bit_depth == 16)\n   {\n      png_bytep rp = row;\n      png_uint_32 i;\n      png_uint_32 istop= row_info->width * row_info->channels;\n\n      for (i = 0; i < istop; i++, rp += 2)\n      {\n#ifdef PNG_BUILTIN_BSWAP16_SUPPORTED\n         /* Feature added to libpng-1.6.11 for testing purposes, not\n          * enabled by default.\n          */\n         *(png_uint_16*)rp = __builtin_bswap16(*(png_uint_16*)rp);\n#else\n         png_byte t = *rp;\n         *rp = *(rp + 1);\n         *(rp + 1) = t;\n#endif\n      }\n   }\n}\n#endif\n#endif\n\n#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)\nstatic PNG_CONST png_byte onebppswaptable[256] = {\n   0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,\n   0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,\n   0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,\n   0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,\n   0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,\n   0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,\n   0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,\n   0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,\n   0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,\n   0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,\n   0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,\n   0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,\n   0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,\n   0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,\n   0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,\n   0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,\n   0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,\n   0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,\n   0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,\n   0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,\n   0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,\n   0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,\n   0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,\n   0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,\n   0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,\n   0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,\n   0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,\n   0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,\n   0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,\n   0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,\n   0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,\n   0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF\n};\n\nstatic PNG_CONST png_byte twobppswaptable[256] = {\n   0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,\n   0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,\n   0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,\n   0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,\n   0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,\n   0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,\n   0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,\n   0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,\n   0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,\n   0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,\n   0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,\n   0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,\n   0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,\n   0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,\n   0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,\n   0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,\n   0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,\n   0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,\n   0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,\n   0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,\n   0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,\n   0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,\n   0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,\n   0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,\n   0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,\n   0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,\n   0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,\n   0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,\n   0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,\n   0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,\n   0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,\n   0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF\n};\n\nstatic PNG_CONST png_byte fourbppswaptable[256] = {\n   0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,\n   0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,\n   0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,\n   0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,\n   0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,\n   0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,\n   0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,\n   0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,\n   0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,\n   0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,\n   0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,\n   0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,\n   0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,\n   0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,\n   0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,\n   0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,\n   0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,\n   0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,\n   0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,\n   0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,\n   0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,\n   0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,\n   0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,\n   0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,\n   0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,\n   0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,\n   0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,\n   0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,\n   0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,\n   0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,\n   0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,\n   0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF\n};\n\n/* Swaps pixel packing order within bytes */\nvoid /* PRIVATE */\npng_do_packswap(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_packswap\");\n\n   if (row_info->bit_depth < 8)\n   {\n      png_bytep rp;\n      png_const_bytep end, table;\n\n      end = row + row_info->rowbytes;\n\n      if (row_info->bit_depth == 1)\n         table = onebppswaptable;\n\n      else if (row_info->bit_depth == 2)\n         table = twobppswaptable;\n\n      else if (row_info->bit_depth == 4)\n         table = fourbppswaptable;\n\n      else\n         return;\n\n      for (rp = row; rp < end; rp++)\n         *rp = table[*rp];\n   }\n}\n#endif /* PACKSWAP || WRITE_PACKSWAP */\n\n#if defined(PNG_WRITE_FILLER_SUPPORTED) || \\\n    defined(PNG_READ_STRIP_ALPHA_SUPPORTED)\n/* Remove a channel - this used to be 'png_do_strip_filler' but it used a\n * somewhat weird combination of flags to determine what to do.  All the calls\n * to png_do_strip_filler are changed in 1.5.2 to call this instead with the\n * correct arguments.\n *\n * The routine isn't general - the channel must be the channel at the start or\n * end (not in the middle) of each pixel.\n */\nvoid /* PRIVATE */\npng_do_strip_channel(png_row_infop row_info, png_bytep row, int at_start)\n{\n   png_bytep sp = row; /* source pointer */\n   png_bytep dp = row; /* destination pointer */\n   png_bytep ep = row + row_info->rowbytes; /* One beyond end of row */\n\n   /* At the start sp will point to the first byte to copy and dp to where\n    * it is copied to.  ep always points just beyond the end of the row, so\n    * the loop simply copies (channels-1) channels until sp reaches ep.\n    *\n    * at_start:        0 -- convert AG, XG, ARGB, XRGB, AAGG, XXGG, etc.\n    *            nonzero -- convert GA, GX, RGBA, RGBX, GGAA, RRGGBBXX, etc.\n    */\n\n   /* GA, GX, XG cases */\n   if (row_info->channels == 2)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         if (at_start != 0) /* Skip initial filler */\n            ++sp;\n         else          /* Skip initial channel and, for sp, the filler */\n            sp += 2, ++dp;\n\n         /* For a 1 pixel wide image there is nothing to do */\n         while (sp < ep)\n            *dp++ = *sp, sp += 2;\n\n         row_info->pixel_depth = 8;\n      }\n\n      else if (row_info->bit_depth == 16)\n      {\n         if (at_start != 0) /* Skip initial filler */\n            sp += 2;\n         else          /* Skip initial channel and, for sp, the filler */\n            sp += 4, dp += 2;\n\n         while (sp < ep)\n            *dp++ = *sp++, *dp++ = *sp, sp += 3;\n\n         row_info->pixel_depth = 16;\n      }\n\n      else\n         return; /* bad bit depth */\n\n      row_info->channels = 1;\n\n      /* Finally fix the color type if it records an alpha channel */\n      if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n         row_info->color_type = PNG_COLOR_TYPE_GRAY;\n   }\n\n   /* RGBA, RGBX, XRGB cases */\n   else if (row_info->channels == 4)\n   {\n      if (row_info->bit_depth == 8)\n      {\n         if (at_start != 0) /* Skip initial filler */\n            ++sp;\n         else          /* Skip initial channels and, for sp, the filler */\n            sp += 4, dp += 3;\n\n         /* Note that the loop adds 3 to dp and 4 to sp each time. */\n         while (sp < ep)\n            *dp++ = *sp++, *dp++ = *sp++, *dp++ = *sp, sp += 2;\n\n         row_info->pixel_depth = 24;\n      }\n\n      else if (row_info->bit_depth == 16)\n      {\n         if (at_start != 0) /* Skip initial filler */\n            sp += 2;\n         else          /* Skip initial channels and, for sp, the filler */\n            sp += 8, dp += 6;\n\n         while (sp < ep)\n         {\n            /* Copy 6 bytes, skip 2 */\n            *dp++ = *sp++, *dp++ = *sp++;\n            *dp++ = *sp++, *dp++ = *sp++;\n            *dp++ = *sp++, *dp++ = *sp, sp += 3;\n         }\n\n         row_info->pixel_depth = 48;\n      }\n\n      else\n         return; /* bad bit depth */\n\n      row_info->channels = 3;\n\n      /* Finally fix the color type if it records an alpha channel */\n      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n         row_info->color_type = PNG_COLOR_TYPE_RGB;\n   }\n\n   else\n      return; /* The filler channel has gone already */\n\n   /* Fix the rowbytes value. */\n   row_info->rowbytes = dp-row;\n}\n#endif\n\n#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)\n/* Swaps red and blue bytes within a pixel */\nvoid /* PRIVATE */\npng_do_bgr(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_bgr\");\n\n   if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      png_uint_32 row_width = row_info->width;\n      if (row_info->bit_depth == 8)\n      {\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n         {\n            png_bytep rp;\n            png_uint_32 i;\n\n            for (i = 0, rp = row; i < row_width; i++, rp += 3)\n            {\n               png_byte save = *rp;\n               *rp = *(rp + 2);\n               *(rp + 2) = save;\n            }\n         }\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n         {\n            png_bytep rp;\n            png_uint_32 i;\n\n            for (i = 0, rp = row; i < row_width; i++, rp += 4)\n            {\n               png_byte save = *rp;\n               *rp = *(rp + 2);\n               *(rp + 2) = save;\n            }\n         }\n      }\n\n#ifdef PNG_16BIT_SUPPORTED\n      else if (row_info->bit_depth == 16)\n      {\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n         {\n            png_bytep rp;\n            png_uint_32 i;\n\n            for (i = 0, rp = row; i < row_width; i++, rp += 6)\n            {\n               png_byte save = *rp;\n               *rp = *(rp + 4);\n               *(rp + 4) = save;\n               save = *(rp + 1);\n               *(rp + 1) = *(rp + 5);\n               *(rp + 5) = save;\n            }\n         }\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n         {\n            png_bytep rp;\n            png_uint_32 i;\n\n            for (i = 0, rp = row; i < row_width; i++, rp += 8)\n            {\n               png_byte save = *rp;\n               *rp = *(rp + 4);\n               *(rp + 4) = save;\n               save = *(rp + 1);\n               *(rp + 1) = *(rp + 5);\n               *(rp + 5) = save;\n            }\n         }\n      }\n#endif\n   }\n}\n#endif /* READ_BGR || WRITE_BGR */\n\n#if defined(PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED) || \\\n    defined(PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED)\n/* Added at libpng-1.5.10 */\nvoid /* PRIVATE */\npng_do_check_palette_indexes(png_structrp png_ptr, png_row_infop row_info)\n{\n   if (png_ptr->num_palette < (1 << row_info->bit_depth) &&\n      png_ptr->num_palette > 0) /* num_palette can be 0 in MNG files */\n   {\n      /* Calculations moved outside switch in an attempt to stop different\n       * compiler warnings.  'padding' is in *bits* within the last byte, it is\n       * an 'int' because pixel_depth becomes an 'int' in the expression below,\n       * and this calculation is used because it avoids warnings that other\n       * forms produced on either GCC or MSVC.\n       */\n      int padding = (-row_info->pixel_depth * row_info->width) & 7;\n      png_bytep rp = png_ptr->row_buf + row_info->rowbytes;\n\n      switch (row_info->bit_depth)\n      {\n         case 1:\n         {\n            /* in this case, all bytes must be 0 so we don't need\n             * to unpack the pixels except for the rightmost one.\n             */\n            for (; rp > png_ptr->row_buf; rp--)\n            {\n              if ((*rp >> padding) != 0)\n                 png_ptr->num_palette_max = 1;\n              padding = 0;\n            }\n\n            break;\n         }\n\n         case 2:\n         {\n            for (; rp > png_ptr->row_buf; rp--)\n            {\n              int i = ((*rp >> padding) & 0x03);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              i = (((*rp >> padding) >> 2) & 0x03);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              i = (((*rp >> padding) >> 4) & 0x03);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              i = (((*rp >> padding) >> 6) & 0x03);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              padding = 0;\n            }\n\n            break;\n         }\n\n         case 4:\n         {\n            for (; rp > png_ptr->row_buf; rp--)\n            {\n              int i = ((*rp >> padding) & 0x0f);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              i = (((*rp >> padding) >> 4) & 0x0f);\n\n              if (i > png_ptr->num_palette_max)\n                 png_ptr->num_palette_max = i;\n\n              padding = 0;\n            }\n\n            break;\n         }\n\n         case 8:\n         {\n            for (; rp > png_ptr->row_buf; rp--)\n            {\n               if (*rp > png_ptr->num_palette_max)\n                  png_ptr->num_palette_max = (int) *rp;\n            }\n\n            break;\n         }\n\n         default:\n            break;\n      }\n   }\n}\n#endif /* CHECK_FOR_INVALID_INDEX */\n\n#if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \\\n    defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)\n#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED\nvoid PNGAPI\npng_set_user_transform_info(png_structrp png_ptr, png_voidp\n   user_transform_ptr, int user_transform_depth, int user_transform_channels)\n{\n   png_debug(1, \"in png_set_user_transform_info\");\n\n   if (png_ptr == NULL)\n      return;\n\n#ifdef PNG_READ_USER_TRANSFORM_SUPPORTED\n   if ((png_ptr->mode & PNG_IS_READ_STRUCT) != 0 &&\n      (png_ptr->flags & PNG_FLAG_ROW_INIT) != 0)\n   {\n      png_app_error(png_ptr,\n          \"info change after png_start_read_image or png_read_update_info\");\n      return;\n   }\n#endif\n\n   png_ptr->user_transform_ptr = user_transform_ptr;\n   png_ptr->user_transform_depth = (png_byte)user_transform_depth;\n   png_ptr->user_transform_channels = (png_byte)user_transform_channels;\n}\n#endif\n\n/* This function returns a pointer to the user_transform_ptr associated with\n * the user transform functions.  The application should free any memory\n * associated with this pointer before png_write_destroy and png_read_destroy\n * are called.\n */\n#ifdef PNG_USER_TRANSFORM_PTR_SUPPORTED\npng_voidp PNGAPI\npng_get_user_transform_ptr(png_const_structrp png_ptr)\n{\n   if (png_ptr == NULL)\n      return (NULL);\n\n   return png_ptr->user_transform_ptr;\n}\n#endif\n\n#ifdef PNG_USER_TRANSFORM_INFO_SUPPORTED\npng_uint_32 PNGAPI\npng_get_current_row_number(png_const_structrp png_ptr)\n{\n   /* See the comments in png.h - this is the sub-image row when reading an\n    * interlaced image.\n    */\n   if (png_ptr != NULL)\n      return png_ptr->row_number;\n\n   return PNG_UINT_32_MAX; /* help the app not to fail silently */\n}\n\npng_byte PNGAPI\npng_get_current_pass_number(png_const_structrp png_ptr)\n{\n   if (png_ptr != NULL)\n      return png_ptr->pass;\n   return 8; /* invalid */\n}\n#endif /* USER_TRANSFORM_INFO */\n#endif /* READ_USER_TRANSFORM || WRITE_USER_TRANSFORM */\n#endif /* READ || WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngusr.dfa",
    "content": "# pngusr.dfa\n#\n# Build time configuration of libpng\n#\n# Enter build configuration options in this file\n#\n# Security settings: by default these limits are unset, you can change them\n# here by entering the appropriate values as #defines preceded by '@' (to cause,\n# them to be passed through to the build of pnglibconf.h), for example:\n#\n# @# define PNG_USER_WIDTH_MAX 65535\n# @# define PNG_USER_HEIGHT_MAX 65535\n# @# define PNG_USER_CHUNK_CACHE_MAX 256\n# @# define PNG_USER_CHUNK_MALLOC_MAX 640000\n"
  },
  {
    "path": "tess-two/jni/libpng/pngusr.h",
    "content": "#define PNG_USER_PRIVATEBUILD \"Skia build; no MNG features\"\n#define PNG_USER_DLLFNAME_POSTFIX \"Sk\"\n#define PNG_NO_MNG_FEATURES\n#define PNG_NO_READ_GAMMA\n"
  },
  {
    "path": "tess-two/jni/libpng/pngwio.c",
    "content": "\n/* pngwio.c - functions for data output\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2014,2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n *\n * This file provides a location for all output.  Users who need\n * special handling are expected to write functions that have the same\n * arguments as these and perform similar functions, but that possibly\n * use different output methods.  Note that you shouldn't change these\n * functions, but rather write replacement functions and then change\n * them at run time with png_set_write_fn(...).\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_WRITE_SUPPORTED\n\n/* Write the data to whatever output you are using.  The default routine\n * writes to a file pointer.  Note that this routine sometimes gets called\n * with very small lengths, so you should implement some kind of simple\n * buffering if you are using unbuffered writes.  This should never be asked\n * to write more than 64K on a 16-bit machine.\n */\n\nvoid /* PRIVATE */\npng_write_data(png_structrp png_ptr, png_const_bytep data, png_size_t length)\n{\n   /* NOTE: write_data_fn must not change the buffer! */\n   if (png_ptr->write_data_fn != NULL )\n      (*(png_ptr->write_data_fn))(png_ptr, png_constcast(png_bytep,data),\n          length);\n\n   else\n      png_error(png_ptr, \"Call to NULL write function\");\n}\n\n#ifdef PNG_STDIO_SUPPORTED\n/* This is the function that does the actual writing of data.  If you are\n * not writing to a standard C stream, you should create a replacement\n * write_data function and use it at run time with png_set_write_fn(), rather\n * than changing the library.\n */\nvoid PNGCBAPI\npng_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)\n{\n   png_size_t check;\n\n   if (png_ptr == NULL)\n      return;\n\n   check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));\n\n   if (check != length)\n      png_error(png_ptr, \"Write Error\");\n}\n#endif\n\n/* This function is called to output any data pending writing (normally\n * to disk).  After png_flush is called, there should be no data pending\n * writing in any buffers.\n */\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\nvoid /* PRIVATE */\npng_flush(png_structrp png_ptr)\n{\n   if (png_ptr->output_flush_fn != NULL)\n      (*(png_ptr->output_flush_fn))(png_ptr);\n}\n\n#  ifdef PNG_STDIO_SUPPORTED\nvoid PNGCBAPI\npng_default_flush(png_structp png_ptr)\n{\n   png_FILE_p io_ptr;\n\n   if (png_ptr == NULL)\n      return;\n\n   io_ptr = png_voidcast(png_FILE_p, (png_ptr->io_ptr));\n   fflush(io_ptr);\n}\n#  endif\n#endif\n\n/* This function allows the application to supply new output functions for\n * libpng if standard C streams aren't being used.\n *\n * This function takes as its arguments:\n * png_ptr       - pointer to a png output data structure\n * io_ptr        - pointer to user supplied structure containing info about\n *                 the output functions.  May be NULL.\n * write_data_fn - pointer to a new output function that takes as its\n *                 arguments a pointer to a png_struct, a pointer to\n *                 data to be written, and a 32-bit unsigned int that is\n *                 the number of bytes to be written.  The new write\n *                 function should call png_error(png_ptr, \"Error msg\")\n *                 to exit and output any fatal error messages.  May be\n *                 NULL, in which case libpng's default function will\n *                 be used.\n * flush_data_fn - pointer to a new flush function that takes as its\n *                 arguments a pointer to a png_struct.  After a call to\n *                 the flush function, there should be no data in any buffers\n *                 or pending transmission.  If the output method doesn't do\n *                 any buffering of output, a function prototype must still be\n *                 supplied although it doesn't have to do anything.  If\n *                 PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile\n *                 time, output_flush_fn will be ignored, although it must be\n *                 supplied for compatibility.  May be NULL, in which case\n *                 libpng's default function will be used, if\n *                 PNG_WRITE_FLUSH_SUPPORTED is defined.  This is not\n *                 a good idea if io_ptr does not point to a standard\n *                 *FILE structure.\n */\nvoid PNGAPI\npng_set_write_fn(png_structrp png_ptr, png_voidp io_ptr,\n    png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->io_ptr = io_ptr;\n\n#ifdef PNG_STDIO_SUPPORTED\n   if (write_data_fn != NULL)\n      png_ptr->write_data_fn = write_data_fn;\n\n   else\n      png_ptr->write_data_fn = png_default_write_data;\n#else\n   png_ptr->write_data_fn = write_data_fn;\n#endif\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n#  ifdef PNG_STDIO_SUPPORTED\n\n   if (output_flush_fn != NULL)\n      png_ptr->output_flush_fn = output_flush_fn;\n\n   else\n      png_ptr->output_flush_fn = png_default_flush;\n\n#  else\n   png_ptr->output_flush_fn = output_flush_fn;\n#  endif\n#else\n   PNG_UNUSED(output_flush_fn)\n#endif /* WRITE_FLUSH */\n\n#ifdef PNG_READ_SUPPORTED\n   /* It is an error to read while writing a png file */\n   if (png_ptr->read_data_fn != NULL)\n   {\n      png_ptr->read_data_fn = NULL;\n\n      png_warning(png_ptr,\n          \"Can't set both read_data_fn and write_data_fn in the\"\n          \" same structure\");\n   }\n#endif\n}\n#endif /* WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngwrite.c",
    "content": "\n/* pngwrite.c - general routines to write a PNG file\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\n#  include <errno.h>\n#endif /* SIMPLIFIED_WRITE_STDIO */\n\n#ifdef PNG_WRITE_SUPPORTED\n\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n/* Write out all the unknown chunks for the current given location */\nstatic void\nwrite_unknown_chunks(png_structrp png_ptr, png_const_inforp info_ptr,\n    unsigned int where)\n{\n   if (info_ptr->unknown_chunks_num != 0)\n   {\n      png_const_unknown_chunkp up;\n\n      png_debug(5, \"writing extra chunks\");\n\n      for (up = info_ptr->unknown_chunks;\n           up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;\n           ++up)\n         if ((up->location & where) != 0)\n      {\n         /* If per-chunk unknown chunk handling is enabled use it, otherwise\n          * just write the chunks the application has set.\n          */\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n         int keep = png_handle_as_unknown(png_ptr, up->name);\n\n         /* NOTE: this code is radically different from the read side in the\n          * matter of handling an ancillary unknown chunk.  In the read side\n          * the default behavior is to discard it, in the code below the default\n          * behavior is to write it.  Critical chunks are, however, only\n          * written if explicitly listed or if the default is set to write all\n          * unknown chunks.\n          *\n          * The default handling is also slightly weird - it is not possible to\n          * stop the writing of all unsafe-to-copy chunks!\n          *\n          * TODO: REVIEW: this would seem to be a bug.\n          */\n         if (keep != PNG_HANDLE_CHUNK_NEVER &&\n             ((up->name[3] & 0x20) /* safe-to-copy overrides everything */ ||\n              keep == PNG_HANDLE_CHUNK_ALWAYS ||\n              (keep == PNG_HANDLE_CHUNK_AS_DEFAULT &&\n               png_ptr->unknown_default == PNG_HANDLE_CHUNK_ALWAYS)))\n#endif\n         {\n            /* TODO: review, what is wrong with a zero length unknown chunk? */\n            if (up->size == 0)\n               png_warning(png_ptr, \"Writing zero-length unknown chunk\");\n\n            png_write_chunk(png_ptr, up->name, up->data, up->size);\n         }\n      }\n   }\n}\n#endif /* WRITE_UNKNOWN_CHUNKS */\n\n/* Writes all the PNG information.  This is the suggested way to use the\n * library.  If you have a new chunk to add, make a function to write it,\n * and put it in the correct location here.  If you want the chunk written\n * after the image data, put it in png_write_end().  I strongly encourage\n * you to supply a PNG_INFO_ flag, and check info_ptr->valid before writing\n * the chunk, as that will keep the code from breaking if you want to just\n * write a plain PNG file.  If you have long comments, I suggest writing\n * them in png_write_end(), and compressing them.\n */\nvoid PNGAPI\npng_write_info_before_PLTE(png_structrp png_ptr, png_const_inforp info_ptr)\n{\n   png_debug(1, \"in png_write_info_before_PLTE\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)\n   {\n      /* Write PNG signature */\n      png_write_sig(png_ptr);\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n      if ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) != 0 && \\\n          png_ptr->mng_features_permitted != 0)\n      {\n         png_warning(png_ptr,\n             \"MNG features are not allowed in a PNG datastream\");\n         png_ptr->mng_features_permitted = 0;\n      }\n#endif\n\n      /* Write IHDR information. */\n      png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,\n          info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,\n          info_ptr->filter_type,\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n          info_ptr->interlace_type\n#else\n          0\n#endif\n         );\n\n      /* The rest of these check to see if the valid field has the appropriate\n       * flag set, and if it does, writes the chunk.\n       *\n       * 1.6.0: COLORSPACE support controls the writing of these chunks too, and\n       * the chunks will be written if the WRITE routine is there and\n       * information * is available in the COLORSPACE. (See\n       * png_colorspace_sync_info in png.c for where the valid flags get set.)\n       *\n       * Under certain circumstances the colorspace can be invalidated without\n       * syncing the info_struct 'valid' flags; this happens if libpng detects\n       * an error and calls png_error while the color space is being set, yet\n       * the application continues writing the PNG.  So check the 'invalid'\n       * flag here too.\n       */\n#ifdef PNG_GAMMA_SUPPORTED\n#  ifdef PNG_WRITE_gAMA_SUPPORTED\n      if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&\n          (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_gAMA) != 0 &&\n          (info_ptr->valid & PNG_INFO_gAMA) != 0)\n         png_write_gAMA_fixed(png_ptr, info_ptr->colorspace.gamma);\n#  endif\n#endif\n\n#ifdef PNG_COLORSPACE_SUPPORTED\n      /* Write only one of sRGB or an ICC profile.  If a profile was supplied\n       * and it matches one of the known sRGB ones issue a warning.\n       */\n#  ifdef PNG_WRITE_iCCP_SUPPORTED\n         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&\n             (info_ptr->valid & PNG_INFO_iCCP) != 0)\n         {\n#    ifdef PNG_WRITE_sRGB_SUPPORTED\n               if ((info_ptr->valid & PNG_INFO_sRGB) != 0)\n                  png_app_warning(png_ptr,\n                      \"profile matches sRGB but writing iCCP instead\");\n#     endif\n\n            png_write_iCCP(png_ptr, info_ptr->iccp_name,\n                info_ptr->iccp_profile);\n         }\n#     ifdef PNG_WRITE_sRGB_SUPPORTED\n         else\n#     endif\n#  endif\n\n#  ifdef PNG_WRITE_sRGB_SUPPORTED\n         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&\n             (info_ptr->valid & PNG_INFO_sRGB) != 0)\n            png_write_sRGB(png_ptr, info_ptr->colorspace.rendering_intent);\n#  endif /* WRITE_sRGB */\n#endif /* COLORSPACE */\n\n#ifdef PNG_WRITE_sBIT_SUPPORTED\n         if ((info_ptr->valid & PNG_INFO_sBIT) != 0)\n            png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);\n#endif\n\n#ifdef PNG_COLORSPACE_SUPPORTED\n#  ifdef PNG_WRITE_cHRM_SUPPORTED\n         if ((info_ptr->colorspace.flags & PNG_COLORSPACE_INVALID) == 0 &&\n             (info_ptr->colorspace.flags & PNG_COLORSPACE_FROM_cHRM) != 0 &&\n             (info_ptr->valid & PNG_INFO_cHRM) != 0)\n            png_write_cHRM_fixed(png_ptr, &info_ptr->colorspace.end_points_xy);\n#  endif\n#endif\n\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n         write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_IHDR);\n#endif\n\n      png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;\n   }\n}\n\nvoid PNGAPI\npng_write_info(png_structrp png_ptr, png_const_inforp info_ptr)\n{\n#if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)\n   int i;\n#endif\n\n   png_debug(1, \"in png_write_info\");\n\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   png_write_info_before_PLTE(png_ptr, info_ptr);\n\n   if ((info_ptr->valid & PNG_INFO_PLTE) != 0)\n      png_write_PLTE(png_ptr, info_ptr->palette,\n          (png_uint_32)info_ptr->num_palette);\n\n   else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      png_error(png_ptr, \"Valid palette required for paletted images\");\n\n#ifdef PNG_WRITE_tRNS_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_tRNS) !=0)\n   {\n#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED\n      /* Invert the alpha channel (in tRNS) */\n      if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0 &&\n          info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         int j, jend;\n\n         jend = info_ptr->num_trans;\n         if (jend > PNG_MAX_PALETTE_LENGTH)\n            jend = PNG_MAX_PALETTE_LENGTH;\n\n         for (j = 0; j<jend; ++j)\n            info_ptr->trans_alpha[j] =\n               (png_byte)(255 - info_ptr->trans_alpha[j]);\n      }\n#endif\n      png_write_tRNS(png_ptr, info_ptr->trans_alpha, &(info_ptr->trans_color),\n          info_ptr->num_trans, info_ptr->color_type);\n   }\n#endif\n#ifdef PNG_WRITE_bKGD_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_bKGD) != 0)\n      png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);\n#endif\n\n#ifdef PNG_WRITE_hIST_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_hIST) != 0)\n      png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);\n#endif\n\n#ifdef PNG_WRITE_oFFs_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_oFFs) != 0)\n      png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,\n          info_ptr->offset_unit_type);\n#endif\n\n#ifdef PNG_WRITE_pCAL_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_pCAL) != 0)\n      png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,\n          info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,\n          info_ptr->pcal_units, info_ptr->pcal_params);\n#endif\n\n#ifdef PNG_WRITE_sCAL_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_sCAL) != 0)\n      png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,\n          info_ptr->scal_s_width, info_ptr->scal_s_height);\n#endif /* sCAL */\n\n#ifdef PNG_WRITE_pHYs_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_pHYs) != 0)\n      png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,\n          info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);\n#endif /* pHYs */\n\n#ifdef PNG_WRITE_tIME_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_tIME) != 0)\n   {\n      png_write_tIME(png_ptr, &(info_ptr->mod_time));\n      png_ptr->mode |= PNG_WROTE_tIME;\n   }\n#endif /* tIME */\n\n#ifdef PNG_WRITE_sPLT_SUPPORTED\n   if ((info_ptr->valid & PNG_INFO_sPLT) != 0)\n      for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)\n         png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);\n#endif /* sPLT */\n\n#ifdef PNG_WRITE_TEXT_SUPPORTED\n   /* Check to see if we need to write text chunks */\n   for (i = 0; i < info_ptr->num_text; i++)\n   {\n      png_debug2(2, \"Writing header text chunk %d, type %d\", i,\n          info_ptr->text[i].compression);\n      /* An internationalized chunk? */\n      if (info_ptr->text[i].compression > 0)\n      {\n#ifdef PNG_WRITE_iTXt_SUPPORTED\n         /* Write international chunk */\n         png_write_iTXt(png_ptr,\n             info_ptr->text[i].compression,\n             info_ptr->text[i].key,\n             info_ptr->text[i].lang,\n             info_ptr->text[i].lang_key,\n             info_ptr->text[i].text);\n         /* Mark this chunk as written */\n         if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)\n            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;\n         else\n            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;\n#else\n         png_warning(png_ptr, \"Unable to write international text\");\n#endif\n      }\n\n      /* If we want a compressed text chunk */\n      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)\n      {\n#ifdef PNG_WRITE_zTXt_SUPPORTED\n         /* Write compressed chunk */\n         png_write_zTXt(png_ptr, info_ptr->text[i].key,\n             info_ptr->text[i].text, info_ptr->text[i].compression);\n         /* Mark this chunk as written */\n         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;\n#else\n         png_warning(png_ptr, \"Unable to write compressed text\");\n#endif\n      }\n\n      else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)\n      {\n#ifdef PNG_WRITE_tEXt_SUPPORTED\n         /* Write uncompressed chunk */\n         png_write_tEXt(png_ptr, info_ptr->text[i].key,\n             info_ptr->text[i].text,\n             0);\n         /* Mark this chunk as written */\n         info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;\n#else\n         /* Can't get here */\n         png_warning(png_ptr, \"Unable to write uncompressed text\");\n#endif\n      }\n   }\n#endif /* tEXt */\n\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n   write_unknown_chunks(png_ptr, info_ptr, PNG_HAVE_PLTE);\n#endif\n}\n\n/* Writes the end of the PNG file.  If you don't want to write comments or\n * time information, you can pass NULL for info.  If you already wrote these\n * in png_write_info(), do not write them again here.  If you have long\n * comments, I suggest writing them here, and compressing them.\n */\nvoid PNGAPI\npng_write_end(png_structrp png_ptr, png_inforp info_ptr)\n{\n   png_debug(1, \"in png_write_end\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if ((png_ptr->mode & PNG_HAVE_IDAT) == 0)\n      png_error(png_ptr, \"No IDATs written into file\");\n\n#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   if (png_ptr->num_palette_max > png_ptr->num_palette)\n      png_benign_error(png_ptr, \"Wrote palette index exceeding num_palette\");\n#endif\n\n   /* See if user wants us to write information chunks */\n   if (info_ptr != NULL)\n   {\n#ifdef PNG_WRITE_TEXT_SUPPORTED\n      int i; /* local index variable */\n#endif\n#ifdef PNG_WRITE_tIME_SUPPORTED\n      /* Check to see if user has supplied a time chunk */\n      if ((info_ptr->valid & PNG_INFO_tIME) != 0 &&\n          (png_ptr->mode & PNG_WROTE_tIME) == 0)\n         png_write_tIME(png_ptr, &(info_ptr->mod_time));\n\n#endif\n#ifdef PNG_WRITE_TEXT_SUPPORTED\n      /* Loop through comment chunks */\n      for (i = 0; i < info_ptr->num_text; i++)\n      {\n         png_debug2(2, \"Writing trailer text chunk %d, type %d\", i,\n             info_ptr->text[i].compression);\n         /* An internationalized chunk? */\n         if (info_ptr->text[i].compression > 0)\n         {\n#ifdef PNG_WRITE_iTXt_SUPPORTED\n            /* Write international chunk */\n            png_write_iTXt(png_ptr,\n                info_ptr->text[i].compression,\n                info_ptr->text[i].key,\n                info_ptr->text[i].lang,\n                info_ptr->text[i].lang_key,\n                info_ptr->text[i].text);\n            /* Mark this chunk as written */\n            if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)\n               info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;\n            else\n               info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;\n#else\n            png_warning(png_ptr, \"Unable to write international text\");\n#endif\n         }\n\n         else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)\n         {\n#ifdef PNG_WRITE_zTXt_SUPPORTED\n            /* Write compressed chunk */\n            png_write_zTXt(png_ptr, info_ptr->text[i].key,\n                info_ptr->text[i].text, info_ptr->text[i].compression);\n            /* Mark this chunk as written */\n            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;\n#else\n            png_warning(png_ptr, \"Unable to write compressed text\");\n#endif\n         }\n\n         else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)\n         {\n#ifdef PNG_WRITE_tEXt_SUPPORTED\n            /* Write uncompressed chunk */\n            png_write_tEXt(png_ptr, info_ptr->text[i].key,\n                info_ptr->text[i].text, 0);\n            /* Mark this chunk as written */\n            info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;\n#else\n            png_warning(png_ptr, \"Unable to write uncompressed text\");\n#endif\n         }\n      }\n#endif\n#ifdef PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n      write_unknown_chunks(png_ptr, info_ptr, PNG_AFTER_IDAT);\n#endif\n   }\n\n   png_ptr->mode |= PNG_AFTER_IDAT;\n\n   /* Write end of PNG file */\n   png_write_IEND(png_ptr);\n\n   /* This flush, added in libpng-1.0.8, removed from libpng-1.0.9beta03,\n    * and restored again in libpng-1.2.30, may cause some applications that\n    * do not set png_ptr->output_flush_fn to crash.  If your application\n    * experiences a problem, please try building libpng with\n    * PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED defined, and report the event to\n    * png-mng-implement at lists.sf.net .\n    */\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n#  ifdef PNG_WRITE_FLUSH_AFTER_IEND_SUPPORTED\n   png_flush(png_ptr);\n#  endif\n#endif\n}\n\n#ifdef PNG_CONVERT_tIME_SUPPORTED\nvoid PNGAPI\npng_convert_from_struct_tm(png_timep ptime, PNG_CONST struct tm * ttime)\n{\n   png_debug(1, \"in png_convert_from_struct_tm\");\n\n   ptime->year = (png_uint_16)(1900 + ttime->tm_year);\n   ptime->month = (png_byte)(ttime->tm_mon + 1);\n   ptime->day = (png_byte)ttime->tm_mday;\n   ptime->hour = (png_byte)ttime->tm_hour;\n   ptime->minute = (png_byte)ttime->tm_min;\n   ptime->second = (png_byte)ttime->tm_sec;\n}\n\nvoid PNGAPI\npng_convert_from_time_t(png_timep ptime, time_t ttime)\n{\n   struct tm *tbuf;\n\n   png_debug(1, \"in png_convert_from_time_t\");\n\n   tbuf = gmtime(&ttime);\n   png_convert_from_struct_tm(ptime, tbuf);\n}\n#endif\n\n/* Initialize png_ptr structure, and allocate any memory needed */\nPNG_FUNCTION(png_structp,PNGAPI\npng_create_write_struct,(png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn),PNG_ALLOCATED)\n{\n#ifndef PNG_USER_MEM_SUPPORTED\n   png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr,\n       error_fn, warn_fn, NULL, NULL, NULL);\n#else\n   return png_create_write_struct_2(user_png_ver, error_ptr, error_fn,\n       warn_fn, NULL, NULL, NULL);\n}\n\n/* Alternate initialize png_ptr structure, and allocate any memory needed */\nPNG_FUNCTION(png_structp,PNGAPI\npng_create_write_struct_2,(png_const_charp user_png_ver, png_voidp error_ptr,\n    png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,\n    png_malloc_ptr malloc_fn, png_free_ptr free_fn),PNG_ALLOCATED)\n{\n   png_structrp png_ptr = png_create_png_struct(user_png_ver, error_ptr,\n       error_fn, warn_fn, mem_ptr, malloc_fn, free_fn);\n#endif /* USER_MEM */\n   if (png_ptr != NULL)\n   {\n      /* Set the zlib control values to defaults; they can be overridden by the\n       * application after the struct has been created.\n       */\n      png_ptr->zbuffer_size = PNG_ZBUF_SIZE;\n\n      /* The 'zlib_strategy' setting is irrelevant because png_default_claim in\n       * pngwutil.c defaults it according to whether or not filters will be\n       * used, and ignores this setting.\n       */\n      png_ptr->zlib_strategy = PNG_Z_DEFAULT_STRATEGY;\n      png_ptr->zlib_level = PNG_Z_DEFAULT_COMPRESSION;\n      png_ptr->zlib_mem_level = 8;\n      png_ptr->zlib_window_bits = 15;\n      png_ptr->zlib_method = 8;\n\n#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED\n      png_ptr->zlib_text_strategy = PNG_TEXT_Z_DEFAULT_STRATEGY;\n      png_ptr->zlib_text_level = PNG_TEXT_Z_DEFAULT_COMPRESSION;\n      png_ptr->zlib_text_mem_level = 8;\n      png_ptr->zlib_text_window_bits = 15;\n      png_ptr->zlib_text_method = 8;\n#endif /* WRITE_COMPRESSED_TEXT */\n\n      /* This is a highly dubious configuration option; by default it is off,\n       * but it may be appropriate for private builds that are testing\n       * extensions not conformant to the current specification, or of\n       * applications that must not fail to write at all costs!\n       */\n#ifdef PNG_BENIGN_WRITE_ERRORS_SUPPORTED\n      /* In stable builds only warn if an application error can be completely\n       * handled.\n       */\n      png_ptr->flags |= PNG_FLAG_BENIGN_ERRORS_WARN;\n#endif\n\n      /* App warnings are warnings in release (or release candidate) builds but\n       * are errors during development.\n       */\n#if PNG_RELEASE_BUILD\n      png_ptr->flags |= PNG_FLAG_APP_WARNINGS_WARN;\n#endif\n\n      /* TODO: delay this, it can be done in png_init_io() (if the app doesn't\n       * do it itself) avoiding setting the default function if it is not\n       * required.\n       */\n      png_set_write_fn(png_ptr, NULL, NULL, NULL);\n   }\n\n   return png_ptr;\n}\n\n\n/* Write a few rows of image data.  If the image is interlaced,\n * either you will have to write the 7 sub images, or, if you\n * have called png_set_interlace_handling(), you will have to\n * \"write\" the image seven times.\n */\nvoid PNGAPI\npng_write_rows(png_structrp png_ptr, png_bytepp row,\n    png_uint_32 num_rows)\n{\n   png_uint_32 i; /* row counter */\n   png_bytepp rp; /* row pointer */\n\n   png_debug(1, \"in png_write_rows\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* Loop through the rows */\n   for (i = 0, rp = row; i < num_rows; i++, rp++)\n   {\n      png_write_row(png_ptr, *rp);\n   }\n}\n\n/* Write the image.  You only need to call this function once, even\n * if you are writing an interlaced image.\n */\nvoid PNGAPI\npng_write_image(png_structrp png_ptr, png_bytepp image)\n{\n   png_uint_32 i; /* row index */\n   int pass, num_pass; /* pass variables */\n   png_bytepp rp; /* points to current row */\n\n   if (png_ptr == NULL)\n      return;\n\n   png_debug(1, \"in png_write_image\");\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* Initialize interlace handling.  If image is not interlaced,\n    * this will set pass to 1\n    */\n   num_pass = png_set_interlace_handling(png_ptr);\n#else\n   num_pass = 1;\n#endif\n   /* Loop through passes */\n   for (pass = 0; pass < num_pass; pass++)\n   {\n      /* Loop through image */\n      for (i = 0, rp = image; i < png_ptr->height; i++, rp++)\n      {\n         png_write_row(png_ptr, *rp);\n      }\n   }\n}\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n/* Performs intrapixel differencing  */\nstatic void\npng_do_write_intrapixel(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_write_intrapixel\");\n\n   if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      int bytes_per_pixel;\n      png_uint_32 row_width = row_info->width;\n      if (row_info->bit_depth == 8)\n      {\n         png_bytep rp;\n         png_uint_32 i;\n\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n            bytes_per_pixel = 3;\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n            bytes_per_pixel = 4;\n\n         else\n            return;\n\n         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)\n         {\n            *(rp)     = (png_byte)(*rp       - *(rp + 1));\n            *(rp + 2) = (png_byte)(*(rp + 2) - *(rp + 1));\n         }\n      }\n\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n      else if (row_info->bit_depth == 16)\n      {\n         png_bytep rp;\n         png_uint_32 i;\n\n         if (row_info->color_type == PNG_COLOR_TYPE_RGB)\n            bytes_per_pixel = 6;\n\n         else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n            bytes_per_pixel = 8;\n\n         else\n            return;\n\n         for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)\n         {\n            png_uint_32 s0   = (*(rp    ) << 8) | *(rp + 1);\n            png_uint_32 s1   = (*(rp + 2) << 8) | *(rp + 3);\n            png_uint_32 s2   = (*(rp + 4) << 8) | *(rp + 5);\n            png_uint_32 red  = (png_uint_32)((s0 - s1) & 0xffffL);\n            png_uint_32 blue = (png_uint_32)((s2 - s1) & 0xffffL);\n            *(rp    ) = (png_byte)(red >> 8);\n            *(rp + 1) = (png_byte)red;\n            *(rp + 4) = (png_byte)(blue >> 8);\n            *(rp + 5) = (png_byte)blue;\n         }\n      }\n#endif /* WRITE_16BIT */\n   }\n}\n#endif /* MNG_FEATURES */\n\n/* Called by user to write a row of image data */\nvoid PNGAPI\npng_write_row(png_structrp png_ptr, png_const_bytep row)\n{\n   /* 1.5.6: moved from png_struct to be a local structure: */\n   png_row_info row_info;\n\n   if (png_ptr == NULL)\n      return;\n\n   png_debug2(1, \"in png_write_row (row %u, pass %d)\",\n       png_ptr->row_number, png_ptr->pass);\n\n   /* Initialize transformations and other stuff if first time */\n   if (png_ptr->row_number == 0 && png_ptr->pass == 0)\n   {\n      /* Make sure we wrote the header info */\n      if ((png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE) == 0)\n         png_error(png_ptr,\n             \"png_write_info was never called before png_write_row\");\n\n      /* Check for transforms that have been set but were defined out */\n#if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)\n      if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_INVERT_SUPPORTED is not defined\");\n#endif\n\n#if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)\n      if ((png_ptr->transformations & PNG_FILLER) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_FILLER_SUPPORTED is not defined\");\n#endif\n#if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && \\\n    defined(PNG_READ_PACKSWAP_SUPPORTED)\n      if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n         png_warning(png_ptr,\n             \"PNG_WRITE_PACKSWAP_SUPPORTED is not defined\");\n#endif\n\n#if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)\n      if ((png_ptr->transformations & PNG_PACK) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_PACK_SUPPORTED is not defined\");\n#endif\n\n#if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)\n      if ((png_ptr->transformations & PNG_SHIFT) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_SHIFT_SUPPORTED is not defined\");\n#endif\n\n#if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)\n      if ((png_ptr->transformations & PNG_BGR) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_BGR_SUPPORTED is not defined\");\n#endif\n\n#if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)\n      if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)\n         png_warning(png_ptr, \"PNG_WRITE_SWAP_SUPPORTED is not defined\");\n#endif\n\n      png_write_start_row(png_ptr);\n   }\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* If interlaced and not interested in row, return */\n   if (png_ptr->interlaced != 0 &&\n       (png_ptr->transformations & PNG_INTERLACE) != 0)\n   {\n      switch (png_ptr->pass)\n      {\n         case 0:\n            if ((png_ptr->row_number & 0x07) != 0)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 1:\n            if ((png_ptr->row_number & 0x07) != 0 || png_ptr->width < 5)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 2:\n            if ((png_ptr->row_number & 0x07) != 4)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 3:\n            if ((png_ptr->row_number & 0x03) != 0 || png_ptr->width < 3)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 4:\n            if ((png_ptr->row_number & 0x03) != 2)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 5:\n            if ((png_ptr->row_number & 0x01) != 0 || png_ptr->width < 2)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         case 6:\n            if ((png_ptr->row_number & 0x01) == 0)\n            {\n               png_write_finish_row(png_ptr);\n               return;\n            }\n            break;\n\n         default: /* error: ignore it */\n            break;\n      }\n   }\n#endif\n\n   /* Set up row info for transformations */\n   row_info.color_type = png_ptr->color_type;\n   row_info.width = png_ptr->usr_width;\n   row_info.channels = png_ptr->usr_channels;\n   row_info.bit_depth = png_ptr->usr_bit_depth;\n   row_info.pixel_depth = (png_byte)(row_info.bit_depth * row_info.channels);\n   row_info.rowbytes = PNG_ROWBYTES(row_info.pixel_depth, row_info.width);\n\n   png_debug1(3, \"row_info->color_type = %d\", row_info.color_type);\n   png_debug1(3, \"row_info->width = %u\", row_info.width);\n   png_debug1(3, \"row_info->channels = %d\", row_info.channels);\n   png_debug1(3, \"row_info->bit_depth = %d\", row_info.bit_depth);\n   png_debug1(3, \"row_info->pixel_depth = %d\", row_info.pixel_depth);\n   png_debug1(3, \"row_info->rowbytes = %lu\", (unsigned long)row_info.rowbytes);\n\n   /* Copy user's row into buffer, leaving room for filter byte. */\n   memcpy(png_ptr->row_buf + 1, row, row_info.rowbytes);\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* Handle interlacing */\n   if (png_ptr->interlaced && png_ptr->pass < 6 &&\n       (png_ptr->transformations & PNG_INTERLACE) != 0)\n   {\n      png_do_write_interlace(&row_info, png_ptr->row_buf + 1, png_ptr->pass);\n      /* This should always get caught above, but still ... */\n      if (row_info.width == 0)\n      {\n         png_write_finish_row(png_ptr);\n         return;\n      }\n   }\n#endif\n\n#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED\n   /* Handle other transformations */\n   if (png_ptr->transformations != 0)\n      png_do_write_transformations(png_ptr, &row_info);\n#endif\n\n   /* At this point the row_info pixel depth must match the 'transformed' depth,\n    * which is also the output depth.\n    */\n   if (row_info.pixel_depth != png_ptr->pixel_depth ||\n       row_info.pixel_depth != png_ptr->transformed_pixel_depth)\n      png_error(png_ptr, \"internal write transform logic error\");\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   /* Write filter_method 64 (intrapixel differencing) only if\n    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and\n    * 2. Libpng did not write a PNG signature (this filter_method is only\n    *    used in PNG datastreams that are embedded in MNG datastreams) and\n    * 3. The application called png_permit_mng_features with a mask that\n    *    included PNG_FLAG_MNG_FILTER_64 and\n    * 4. The filter_method is 64 and\n    * 5. The color_type is RGB or RGBA\n    */\n   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&\n       (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))\n   {\n      /* Intrapixel differencing */\n      png_do_write_intrapixel(&row_info, png_ptr->row_buf + 1);\n   }\n#endif\n\n/* Added at libpng-1.5.10 */\n#ifdef PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED\n   /* Check for out-of-range palette index */\n   if (row_info.color_type == PNG_COLOR_TYPE_PALETTE &&\n       png_ptr->num_palette_max >= 0)\n      png_do_check_palette_indexes(png_ptr, &row_info);\n#endif\n\n   /* Find a filter if necessary, filter the row and write it out. */\n   png_write_find_filter(png_ptr, &row_info);\n\n   if (png_ptr->write_row_fn != NULL)\n      (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);\n}\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n/* Set the automatic flush interval or 0 to turn flushing off */\nvoid PNGAPI\npng_set_flush(png_structrp png_ptr, int nrows)\n{\n   png_debug(1, \"in png_set_flush\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);\n}\n\n/* Flush the current output buffers now */\nvoid PNGAPI\npng_write_flush(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_write_flush\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* We have already written out all of the data */\n   if (png_ptr->row_number >= png_ptr->num_rows)\n      return;\n\n   png_compress_IDAT(png_ptr, NULL, 0, Z_SYNC_FLUSH);\n   png_ptr->flush_rows = 0;\n   png_flush(png_ptr);\n}\n#endif /* WRITE_FLUSH */\n\n/* Free any memory used in png_ptr struct without freeing the struct itself. */\nstatic void\npng_write_destroy(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_write_destroy\");\n\n   /* Free any memory zlib uses */\n   if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)\n      deflateEnd(&png_ptr->zstream);\n\n   /* Free our memory.  png_free checks NULL for us. */\n   png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list);\n   png_free(png_ptr, png_ptr->row_buf);\n   png_ptr->row_buf = NULL;\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   png_free(png_ptr, png_ptr->prev_row);\n   png_free(png_ptr, png_ptr->try_row);\n   png_free(png_ptr, png_ptr->tst_row);\n   png_ptr->prev_row = NULL;\n   png_ptr->try_row = NULL;\n   png_ptr->tst_row = NULL;\n#endif\n\n#ifdef PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n   png_free(png_ptr, png_ptr->chunk_list);\n   png_ptr->chunk_list = NULL;\n#endif\n\n   /* The error handling and memory handling information is left intact at this\n    * point: the jmp_buf may still have to be freed.  See png_destroy_png_struct\n    * for how this happens.\n    */\n}\n\n/* Free all memory used by the write.\n * In libpng 1.6.0 this API changed quietly to no longer accept a NULL value for\n * *png_ptr_ptr.  Prior to 1.6.0 it would accept such a value and it would free\n * the passed in info_structs but it would quietly fail to free any of the data\n * inside them.  In 1.6.0 it quietly does nothing (it has to be quiet because it\n * has no png_ptr.)\n */\nvoid PNGAPI\npng_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)\n{\n   png_debug(1, \"in png_destroy_write_struct\");\n\n   if (png_ptr_ptr != NULL)\n   {\n      png_structrp png_ptr = *png_ptr_ptr;\n\n      if (png_ptr != NULL) /* added in libpng 1.6.0 */\n      {\n         png_destroy_info_struct(png_ptr, info_ptr_ptr);\n\n         *png_ptr_ptr = NULL;\n         png_write_destroy(png_ptr);\n         png_destroy_png_struct(png_ptr);\n      }\n   }\n}\n\n/* Allow the application to select one or more row filters to use. */\nvoid PNGAPI\npng_set_filter(png_structrp png_ptr, int method, int filters)\n{\n   png_debug(1, \"in png_set_filter\");\n\n   if (png_ptr == NULL)\n      return;\n\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   if ((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&\n       (method == PNG_INTRAPIXEL_DIFFERENCING))\n      method = PNG_FILTER_TYPE_BASE;\n\n#endif\n   if (method == PNG_FILTER_TYPE_BASE)\n   {\n      switch (filters & (PNG_ALL_FILTERS | 0x07))\n      {\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n         case 5:\n         case 6:\n         case 7: png_app_error(png_ptr, \"Unknown row filter for method 0\");\n            /* FALL THROUGH */\n#endif /* WRITE_FILTER */\n         case PNG_FILTER_VALUE_NONE:\n            png_ptr->do_filter = PNG_FILTER_NONE; break;\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n         case PNG_FILTER_VALUE_SUB:\n            png_ptr->do_filter = PNG_FILTER_SUB; break;\n\n         case PNG_FILTER_VALUE_UP:\n            png_ptr->do_filter = PNG_FILTER_UP; break;\n\n         case PNG_FILTER_VALUE_AVG:\n            png_ptr->do_filter = PNG_FILTER_AVG; break;\n\n         case PNG_FILTER_VALUE_PAETH:\n            png_ptr->do_filter = PNG_FILTER_PAETH; break;\n\n         default:\n            png_ptr->do_filter = (png_byte)filters; break;\n#else\n         default:\n            png_app_error(png_ptr, \"Unknown row filter for method 0\");\n#endif /* WRITE_FILTER */\n      }\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n      /* If we have allocated the row_buf, this means we have already started\n       * with the image and we should have allocated all of the filter buffers\n       * that have been selected.  If prev_row isn't already allocated, then\n       * it is too late to start using the filters that need it, since we\n       * will be missing the data in the previous row.  If an application\n       * wants to start and stop using particular filters during compression,\n       * it should start out with all of the filters, and then remove them\n       * or add them back after the start of compression.\n       *\n       * NOTE: this is a nasty constraint on the code, because it means that the\n       * prev_row buffer must be maintained even if there are currently no\n       * 'prev_row' requiring filters active.\n       */\n      if (png_ptr->row_buf != NULL)\n      {\n         int num_filters;\n         png_alloc_size_t buf_size;\n\n         /* Repeat the checks in png_write_start_row; 1 pixel high or wide\n          * images cannot benefit from certain filters.  If this isn't done here\n          * the check below will fire on 1 pixel high images.\n          */\n         if (png_ptr->height == 1)\n            filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);\n\n         if (png_ptr->width == 1)\n            filters &= ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);\n\n         if ((filters & (PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH)) != 0\n            && png_ptr->prev_row == NULL)\n         {\n            /* This is the error case, however it is benign - the previous row\n             * is not available so the filter can't be used.  Just warn here.\n             */\n            png_app_warning(png_ptr,\n                \"png_set_filter: UP/AVG/PAETH cannot be added after start\");\n            filters &= ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);\n         }\n\n         num_filters = 0;\n\n         if (filters & PNG_FILTER_SUB)\n            num_filters++;\n\n         if (filters & PNG_FILTER_UP)\n            num_filters++;\n\n         if (filters & PNG_FILTER_AVG)\n            num_filters++;\n\n         if (filters & PNG_FILTER_PAETH)\n            num_filters++;\n\n         /* Allocate needed row buffers if they have not already been\n          * allocated.\n          */\n         buf_size = PNG_ROWBYTES(png_ptr->usr_channels * png_ptr->usr_bit_depth,\n             png_ptr->width) + 1;\n\n         if (png_ptr->try_row == NULL)\n            png_ptr->try_row = png_voidcast(png_bytep,\n                png_malloc(png_ptr, buf_size));\n\n         if (num_filters > 1)\n         {\n            if (png_ptr->tst_row == NULL)\n               png_ptr->tst_row = png_voidcast(png_bytep,\n                   png_malloc(png_ptr, buf_size));\n         }\n      }\n      png_ptr->do_filter = (png_byte)filters;\n#endif\n   }\n   else\n      png_error(png_ptr, \"Unknown custom filter method\");\n}\n\n#ifdef PNG_WRITE_WEIGHTED_FILTER_SUPPORTED /* DEPRECATED */\n/* Provide floating and fixed point APIs */\n#ifdef PNG_FLOATING_POINT_SUPPORTED\nvoid PNGAPI\npng_set_filter_heuristics(png_structrp png_ptr, int heuristic_method,\n    int num_weights, png_const_doublep filter_weights,\n    png_const_doublep filter_costs)\n{\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(heuristic_method)\n   PNG_UNUSED(num_weights)\n   PNG_UNUSED(filter_weights)\n   PNG_UNUSED(filter_costs)\n}\n#endif /* FLOATING_POINT */\n\n#ifdef PNG_FIXED_POINT_SUPPORTED\nvoid PNGAPI\npng_set_filter_heuristics_fixed(png_structrp png_ptr, int heuristic_method,\n    int num_weights, png_const_fixed_point_p filter_weights,\n    png_const_fixed_point_p filter_costs)\n{\n   PNG_UNUSED(png_ptr)\n   PNG_UNUSED(heuristic_method)\n   PNG_UNUSED(num_weights)\n   PNG_UNUSED(filter_weights)\n   PNG_UNUSED(filter_costs)\n}\n#endif /* FIXED_POINT */\n#endif /* WRITE_WEIGHTED_FILTER */\n\n#ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\nvoid PNGAPI\npng_set_compression_level(png_structrp png_ptr, int level)\n{\n   png_debug(1, \"in png_set_compression_level\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->zlib_level = level;\n}\n\nvoid PNGAPI\npng_set_compression_mem_level(png_structrp png_ptr, int mem_level)\n{\n   png_debug(1, \"in png_set_compression_mem_level\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->zlib_mem_level = mem_level;\n}\n\nvoid PNGAPI\npng_set_compression_strategy(png_structrp png_ptr, int strategy)\n{\n   png_debug(1, \"in png_set_compression_strategy\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* The flag setting here prevents the libpng dynamic selection of strategy.\n    */\n   png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;\n   png_ptr->zlib_strategy = strategy;\n}\n\n/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a\n * smaller value of window_bits if it can do so safely.\n */\nvoid PNGAPI\npng_set_compression_window_bits(png_structrp png_ptr, int window_bits)\n{\n   if (png_ptr == NULL)\n      return;\n\n   /* Prior to 1.6.0 this would warn but then set the window_bits value. This\n    * meant that negative window bits values could be selected that would cause\n    * libpng to write a non-standard PNG file with raw deflate or gzip\n    * compressed IDAT or ancillary chunks.  Such files can be read and there is\n    * no warning on read, so this seems like a very bad idea.\n    */\n   if (window_bits > 15)\n   {\n      png_warning(png_ptr, \"Only compression windows <= 32k supported by PNG\");\n      window_bits = 15;\n   }\n\n   else if (window_bits < 8)\n   {\n      png_warning(png_ptr, \"Only compression windows >= 256 supported by PNG\");\n      window_bits = 8;\n   }\n\n   png_ptr->zlib_window_bits = window_bits;\n}\n\nvoid PNGAPI\npng_set_compression_method(png_structrp png_ptr, int method)\n{\n   png_debug(1, \"in png_set_compression_method\");\n\n   if (png_ptr == NULL)\n      return;\n\n   /* This would produce an invalid PNG file if it worked, but it doesn't and\n    * deflate will fault it, so it is harmless to just warn here.\n    */\n   if (method != 8)\n      png_warning(png_ptr, \"Only compression method 8 is supported by PNG\");\n\n   png_ptr->zlib_method = method;\n}\n#endif /* WRITE_CUSTOMIZE_COMPRESSION */\n\n/* The following were added to libpng-1.5.4 */\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\nvoid PNGAPI\npng_set_text_compression_level(png_structrp png_ptr, int level)\n{\n   png_debug(1, \"in png_set_text_compression_level\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->zlib_text_level = level;\n}\n\nvoid PNGAPI\npng_set_text_compression_mem_level(png_structrp png_ptr, int mem_level)\n{\n   png_debug(1, \"in png_set_text_compression_mem_level\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->zlib_text_mem_level = mem_level;\n}\n\nvoid PNGAPI\npng_set_text_compression_strategy(png_structrp png_ptr, int strategy)\n{\n   png_debug(1, \"in png_set_text_compression_strategy\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->zlib_text_strategy = strategy;\n}\n\n/* If PNG_WRITE_OPTIMIZE_CMF_SUPPORTED is defined, libpng will use a\n * smaller value of window_bits if it can do so safely.\n */\nvoid PNGAPI\npng_set_text_compression_window_bits(png_structrp png_ptr, int window_bits)\n{\n   if (png_ptr == NULL)\n      return;\n\n   if (window_bits > 15)\n   {\n      png_warning(png_ptr, \"Only compression windows <= 32k supported by PNG\");\n      window_bits = 15;\n   }\n\n   else if (window_bits < 8)\n   {\n      png_warning(png_ptr, \"Only compression windows >= 256 supported by PNG\");\n      window_bits = 8;\n   }\n\n   png_ptr->zlib_text_window_bits = window_bits;\n}\n\nvoid PNGAPI\npng_set_text_compression_method(png_structrp png_ptr, int method)\n{\n   png_debug(1, \"in png_set_text_compression_method\");\n\n   if (png_ptr == NULL)\n      return;\n\n   if (method != 8)\n      png_warning(png_ptr, \"Only compression method 8 is supported by PNG\");\n\n   png_ptr->zlib_text_method = method;\n}\n#endif /* WRITE_CUSTOMIZE_ZTXT_COMPRESSION */\n/* end of API added to libpng-1.5.4 */\n\nvoid PNGAPI\npng_set_write_status_fn(png_structrp png_ptr, png_write_status_ptr write_row_fn)\n{\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->write_row_fn = write_row_fn;\n}\n\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\nvoid PNGAPI\npng_set_write_user_transform_fn(png_structrp png_ptr, png_user_transform_ptr\n    write_user_transform_fn)\n{\n   png_debug(1, \"in png_set_write_user_transform_fn\");\n\n   if (png_ptr == NULL)\n      return;\n\n   png_ptr->transformations |= PNG_USER_TRANSFORM;\n   png_ptr->write_user_transform_fn = write_user_transform_fn;\n}\n#endif\n\n\n#ifdef PNG_INFO_IMAGE_SUPPORTED\nvoid PNGAPI\npng_write_png(png_structrp png_ptr, png_inforp info_ptr,\n    int transforms, voidp params)\n{\n   if (png_ptr == NULL || info_ptr == NULL)\n      return;\n\n   if ((info_ptr->valid & PNG_INFO_IDAT) == 0)\n   {\n      png_app_error(png_ptr, \"no rows for png_write_image to write\");\n      return;\n   }\n\n   /* Write the file header information. */\n   png_write_info(png_ptr, info_ptr);\n\n   /* ------ these transformations don't touch the info structure ------- */\n\n   /* Invert monochrome pixels */\n   if ((transforms & PNG_TRANSFORM_INVERT_MONO) != 0)\n#ifdef PNG_WRITE_INVERT_SUPPORTED\n      png_set_invert_mono(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_INVERT_MONO not supported\");\n#endif\n\n   /* Shift the pixels up to a legal bit depth and fill in\n    * as appropriate to correctly scale the image.\n    */\n   if ((transforms & PNG_TRANSFORM_SHIFT) != 0)\n#ifdef PNG_WRITE_SHIFT_SUPPORTED\n      if ((info_ptr->valid & PNG_INFO_sBIT) != 0)\n         png_set_shift(png_ptr, &info_ptr->sig_bit);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SHIFT not supported\");\n#endif\n\n   /* Pack pixels into bytes */\n   if ((transforms & PNG_TRANSFORM_PACKING) != 0)\n#ifdef PNG_WRITE_PACK_SUPPORTED\n      png_set_packing(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_PACKING not supported\");\n#endif\n\n   /* Swap location of alpha bytes from ARGB to RGBA */\n   if ((transforms & PNG_TRANSFORM_SWAP_ALPHA) != 0)\n#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED\n      png_set_swap_alpha(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SWAP_ALPHA not supported\");\n#endif\n\n   /* Remove a filler (X) from XRGB/RGBX/AG/GA into to convert it into\n    * RGB, note that the code expects the input color type to be G or RGB; no\n    * alpha channel.\n    */\n   if ((transforms & (PNG_TRANSFORM_STRIP_FILLER_AFTER|\n       PNG_TRANSFORM_STRIP_FILLER_BEFORE)) != 0)\n   {\n#ifdef PNG_WRITE_FILLER_SUPPORTED\n      if ((transforms & PNG_TRANSFORM_STRIP_FILLER_AFTER) != 0)\n      {\n         if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)\n            png_app_error(png_ptr,\n                \"PNG_TRANSFORM_STRIP_FILLER: BEFORE+AFTER not supported\");\n\n         /* Continue if ignored - this is the pre-1.6.10 behavior */\n         png_set_filler(png_ptr, 0, PNG_FILLER_AFTER);\n      }\n\n      else if ((transforms & PNG_TRANSFORM_STRIP_FILLER_BEFORE) != 0)\n         png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_STRIP_FILLER not supported\");\n#endif\n   }\n\n   /* Flip BGR pixels to RGB */\n   if ((transforms & PNG_TRANSFORM_BGR) != 0)\n#ifdef PNG_WRITE_BGR_SUPPORTED\n      png_set_bgr(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_BGR not supported\");\n#endif\n\n   /* Swap bytes of 16-bit files to most significant byte first */\n   if ((transforms & PNG_TRANSFORM_SWAP_ENDIAN) != 0)\n#ifdef PNG_WRITE_SWAP_SUPPORTED\n      png_set_swap(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_SWAP_ENDIAN not supported\");\n#endif\n\n   /* Swap bits of 1-bit, 2-bit, 4-bit packed pixel formats */\n   if ((transforms & PNG_TRANSFORM_PACKSWAP) != 0)\n#ifdef PNG_WRITE_PACKSWAP_SUPPORTED\n      png_set_packswap(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_PACKSWAP not supported\");\n#endif\n\n   /* Invert the alpha channel from opacity to transparency */\n   if ((transforms & PNG_TRANSFORM_INVERT_ALPHA) != 0)\n#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED\n      png_set_invert_alpha(png_ptr);\n#else\n      png_app_error(png_ptr, \"PNG_TRANSFORM_INVERT_ALPHA not supported\");\n#endif\n\n   /* ----------------------- end of transformations ------------------- */\n\n   /* Write the bits */\n   png_write_image(png_ptr, info_ptr->row_pointers);\n\n   /* It is REQUIRED to call this to finish writing the rest of the file */\n   png_write_end(png_ptr, info_ptr);\n\n   PNG_UNUSED(params)\n}\n#endif\n\n\n#ifdef PNG_SIMPLIFIED_WRITE_SUPPORTED\n/* Initialize the write structure - general purpose utility. */\nstatic int\npng_image_write_init(png_imagep image)\n{\n   png_structp png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, image,\n       png_safe_error, png_safe_warning);\n\n   if (png_ptr != NULL)\n   {\n      png_infop info_ptr = png_create_info_struct(png_ptr);\n\n      if (info_ptr != NULL)\n      {\n         png_controlp control = png_voidcast(png_controlp,\n             png_malloc_warn(png_ptr, (sizeof *control)));\n\n         if (control != NULL)\n         {\n            memset(control, 0, (sizeof *control));\n\n            control->png_ptr = png_ptr;\n            control->info_ptr = info_ptr;\n            control->for_write = 1;\n\n            image->opaque = control;\n            return 1;\n         }\n\n         /* Error clean up */\n         png_destroy_info_struct(png_ptr, &info_ptr);\n      }\n\n      png_destroy_write_struct(&png_ptr, NULL);\n   }\n\n   return png_image_error(image, \"png_image_write_: out of memory\");\n}\n\n/* Arguments to png_image_write_main: */\ntypedef struct\n{\n   /* Arguments: */\n   png_imagep      image;\n   png_const_voidp buffer;\n   png_int_32      row_stride;\n   png_const_voidp colormap;\n   int             convert_to_8bit;\n   /* Local variables: */\n   png_const_voidp first_row;\n   ptrdiff_t       row_bytes;\n   png_voidp       local_row;\n   /* Byte count for memory writing */\n   png_bytep        memory;\n   png_alloc_size_t memory_bytes; /* not used for STDIO */\n   png_alloc_size_t output_bytes; /* running total */\n} png_image_write_control;\n\n/* Write png_uint_16 input to a 16-bit PNG; the png_ptr has already been set to\n * do any necessary byte swapping.  The component order is defined by the\n * png_image format value.\n */\nstatic int\npng_write_image_16bit(png_voidp argument)\n{\n   png_image_write_control *display = png_voidcast(png_image_write_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n\n   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,\n       display->first_row);\n   png_uint_16p output_row = png_voidcast(png_uint_16p, display->local_row);\n   png_uint_16p row_end;\n   const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;\n   int aindex = 0;\n   png_uint_32 y = image->height;\n\n   if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)\n   {\n#   ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED\n      if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)\n      {\n         aindex = -1;\n         ++input_row; /* To point to the first component */\n         ++output_row;\n      }\n         else\n            aindex = channels;\n#     else\n         aindex = channels;\n#     endif\n   }\n\n   else\n      png_error(png_ptr, \"png_write_image: internal call error\");\n\n   /* Work out the output row end and count over this, note that the increment\n    * above to 'row' means that row_end can actually be beyond the end of the\n    * row; this is correct.\n    */\n   row_end = output_row + image->width * (channels+1);\n\n   while (y-- > 0)\n   {\n      png_const_uint_16p in_ptr = input_row;\n      png_uint_16p out_ptr = output_row;\n\n      while (out_ptr < row_end)\n      {\n         const png_uint_16 alpha = in_ptr[aindex];\n         png_uint_32 reciprocal = 0;\n         int c;\n\n         out_ptr[aindex] = alpha;\n\n         /* Calculate a reciprocal.  The correct calculation is simply\n          * component/alpha*65535 << 15. (I.e. 15 bits of precision); this\n          * allows correct rounding by adding .5 before the shift.  'reciprocal'\n          * is only initialized when required.\n          */\n         if (alpha > 0 && alpha < 65535)\n            reciprocal = ((0xffff<<15)+(alpha>>1))/alpha;\n\n         c = channels;\n         do /* always at least one channel */\n         {\n            png_uint_16 component = *in_ptr++;\n\n            /* The following gives 65535 for an alpha of 0, which is fine,\n             * otherwise if 0/0 is represented as some other value there is more\n             * likely to be a discontinuity which will probably damage\n             * compression when moving from a fully transparent area to a\n             * nearly transparent one.  (The assumption here is that opaque\n             * areas tend not to be 0 intensity.)\n             */\n            if (component >= alpha)\n               component = 65535;\n\n            /* component<alpha, so component/alpha is less than one and\n             * component*reciprocal is less than 2^31.\n             */\n            else if (component > 0 && alpha < 65535)\n            {\n               png_uint_32 calc = component * reciprocal;\n               calc += 16384; /* round to nearest */\n               component = (png_uint_16)(calc >> 15);\n            }\n\n            *out_ptr++ = component;\n         }\n         while (--c > 0);\n\n         /* Skip to next component (skip the intervening alpha channel) */\n         ++in_ptr;\n         ++out_ptr;\n      }\n\n      png_write_row(png_ptr, png_voidcast(png_const_bytep, display->local_row));\n      input_row += display->row_bytes/(sizeof (png_uint_16));\n   }\n\n   return 1;\n}\n\n/* Given 16-bit input (1 to 4 channels) write 8-bit output.  If an alpha channel\n * is present it must be removed from the components, the components are then\n * written in sRGB encoding.  No components are added or removed.\n *\n * Calculate an alpha reciprocal to reverse pre-multiplication.  As above the\n * calculation can be done to 15 bits of accuracy; however, the output needs to\n * be scaled in the range 0..255*65535, so include that scaling here.\n */\n#   define UNP_RECIPROCAL(alpha) ((((0xffff*0xff)<<7)+(alpha>>1))/alpha)\n\nstatic png_byte\npng_unpremultiply(png_uint_32 component, png_uint_32 alpha,\n    png_uint_32 reciprocal/*from the above macro*/)\n{\n   /* The following gives 1.0 for an alpha of 0, which is fine, otherwise if 0/0\n    * is represented as some other value there is more likely to be a\n    * discontinuity which will probably damage compression when moving from a\n    * fully transparent area to a nearly transparent one.  (The assumption here\n    * is that opaque areas tend not to be 0 intensity.)\n    *\n    * There is a rounding problem here; if alpha is less than 128 it will end up\n    * as 0 when scaled to 8 bits.  To avoid introducing spurious colors into the\n    * output change for this too.\n    */\n   if (component >= alpha || alpha < 128)\n      return 255;\n\n   /* component<alpha, so component/alpha is less than one and\n    * component*reciprocal is less than 2^31.\n    */\n   else if (component > 0)\n   {\n      /* The test is that alpha/257 (rounded) is less than 255, the first value\n       * that becomes 255 is 65407.\n       * NOTE: this must agree with the PNG_DIV257 macro (which must, therefore,\n       * be exact!)  [Could also test reciprocal != 0]\n       */\n      if (alpha < 65407)\n      {\n         component *= reciprocal;\n         component += 64; /* round to nearest */\n         component >>= 7;\n      }\n\n      else\n         component *= 255;\n\n      /* Convert the component to sRGB. */\n      return (png_byte)PNG_sRGB_FROM_LINEAR(component);\n   }\n\n   else\n      return 0;\n}\n\nstatic int\npng_write_image_8bit(png_voidp argument)\n{\n   png_image_write_control *display = png_voidcast(png_image_write_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n\n   png_const_uint_16p input_row = png_voidcast(png_const_uint_16p,\n       display->first_row);\n   png_bytep output_row = png_voidcast(png_bytep, display->local_row);\n   png_uint_32 y = image->height;\n   const int channels = (image->format & PNG_FORMAT_FLAG_COLOR) != 0 ? 3 : 1;\n\n   if ((image->format & PNG_FORMAT_FLAG_ALPHA) != 0)\n   {\n      png_bytep row_end;\n      int aindex;\n\n#   ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED\n      if ((image->format & PNG_FORMAT_FLAG_AFIRST) != 0)\n      {\n         aindex = -1;\n         ++input_row; /* To point to the first component */\n         ++output_row;\n      }\n\n      else\n#   endif\n      aindex = channels;\n\n      /* Use row_end in place of a loop counter: */\n      row_end = output_row + image->width * (channels+1);\n\n      while (y-- > 0)\n      {\n         png_const_uint_16p in_ptr = input_row;\n         png_bytep out_ptr = output_row;\n\n         while (out_ptr < row_end)\n         {\n            png_uint_16 alpha = in_ptr[aindex];\n            png_byte alphabyte = (png_byte)PNG_DIV257(alpha);\n            png_uint_32 reciprocal = 0;\n            int c;\n\n            /* Scale and write the alpha channel. */\n            out_ptr[aindex] = alphabyte;\n\n            if (alphabyte > 0 && alphabyte < 255)\n               reciprocal = UNP_RECIPROCAL(alpha);\n\n            c = channels;\n            do /* always at least one channel */\n               *out_ptr++ = png_unpremultiply(*in_ptr++, alpha, reciprocal);\n            while (--c > 0);\n\n            /* Skip to next component (skip the intervening alpha channel) */\n            ++in_ptr;\n            ++out_ptr;\n         } /* while out_ptr < row_end */\n\n         png_write_row(png_ptr, png_voidcast(png_const_bytep,\n             display->local_row));\n         input_row += display->row_bytes/(sizeof (png_uint_16));\n      } /* while y */\n   }\n\n   else\n   {\n      /* No alpha channel, so the row_end really is the end of the row and it\n       * is sufficient to loop over the components one by one.\n       */\n      png_bytep row_end = output_row + image->width * channels;\n\n      while (y-- > 0)\n      {\n         png_const_uint_16p in_ptr = input_row;\n         png_bytep out_ptr = output_row;\n\n         while (out_ptr < row_end)\n         {\n            png_uint_32 component = *in_ptr++;\n\n            component *= 255;\n            *out_ptr++ = (png_byte)PNG_sRGB_FROM_LINEAR(component);\n         }\n\n         png_write_row(png_ptr, output_row);\n         input_row += display->row_bytes/(sizeof (png_uint_16));\n      }\n   }\n\n   return 1;\n}\n\nstatic void\npng_image_set_PLTE(png_image_write_control *display)\n{\n   const png_imagep image = display->image;\n   const void *cmap = display->colormap;\n   const int entries = image->colormap_entries > 256 ? 256 :\n       (int)image->colormap_entries;\n\n   /* NOTE: the caller must check for cmap != NULL and entries != 0 */\n   const png_uint_32 format = image->format;\n   const int channels = PNG_IMAGE_SAMPLE_CHANNELS(format);\n\n#   if defined(PNG_FORMAT_BGR_SUPPORTED) &&\\\n      defined(PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED)\n      const int afirst = (format & PNG_FORMAT_FLAG_AFIRST) != 0 &&\n          (format & PNG_FORMAT_FLAG_ALPHA) != 0;\n#   else\n#     define afirst 0\n#   endif\n\n#   ifdef PNG_FORMAT_BGR_SUPPORTED\n      const int bgr = (format & PNG_FORMAT_FLAG_BGR) != 0 ? 2 : 0;\n#   else\n#     define bgr 0\n#   endif\n\n   int i, num_trans;\n   png_color palette[256];\n   png_byte tRNS[256];\n\n   memset(tRNS, 255, (sizeof tRNS));\n   memset(palette, 0, (sizeof palette));\n\n   for (i=num_trans=0; i<entries; ++i)\n   {\n      /* This gets automatically converted to sRGB with reversal of the\n       * pre-multiplication if the color-map has an alpha channel.\n       */\n      if ((format & PNG_FORMAT_FLAG_LINEAR) != 0)\n      {\n         png_const_uint_16p entry = png_voidcast(png_const_uint_16p, cmap);\n\n         entry += i * channels;\n\n         if ((channels & 1) != 0) /* no alpha */\n         {\n            if (channels >= 3) /* RGB */\n            {\n               palette[i].blue = (png_byte)PNG_sRGB_FROM_LINEAR(255 *\n                   entry[(2 ^ bgr)]);\n               palette[i].green = (png_byte)PNG_sRGB_FROM_LINEAR(255 *\n                   entry[1]);\n               palette[i].red = (png_byte)PNG_sRGB_FROM_LINEAR(255 *\n                   entry[bgr]);\n            }\n\n            else /* Gray */\n               palette[i].blue = palette[i].red = palette[i].green =\n                  (png_byte)PNG_sRGB_FROM_LINEAR(255 * *entry);\n         }\n\n         else /* alpha */\n         {\n            png_uint_16 alpha = entry[afirst ? 0 : channels-1];\n            png_byte alphabyte = (png_byte)PNG_DIV257(alpha);\n            png_uint_32 reciprocal = 0;\n\n            /* Calculate a reciprocal, as in the png_write_image_8bit code above\n             * this is designed to produce a value scaled to 255*65535 when\n             * divided by 128 (i.e. asr 7).\n             */\n            if (alphabyte > 0 && alphabyte < 255)\n               reciprocal = (((0xffff*0xff)<<7)+(alpha>>1))/alpha;\n\n            tRNS[i] = alphabyte;\n            if (alphabyte < 255)\n               num_trans = i+1;\n\n            if (channels >= 3) /* RGB */\n            {\n               palette[i].blue = png_unpremultiply(entry[afirst + (2 ^ bgr)],\n                   alpha, reciprocal);\n               palette[i].green = png_unpremultiply(entry[afirst + 1], alpha,\n                   reciprocal);\n               palette[i].red = png_unpremultiply(entry[afirst + bgr], alpha,\n                   reciprocal);\n            }\n\n            else /* gray */\n               palette[i].blue = palette[i].red = palette[i].green =\n                   png_unpremultiply(entry[afirst], alpha, reciprocal);\n         }\n      }\n\n      else /* Color-map has sRGB values */\n      {\n         png_const_bytep entry = png_voidcast(png_const_bytep, cmap);\n\n         entry += i * channels;\n\n         switch (channels)\n         {\n            case 4:\n               tRNS[i] = entry[afirst ? 0 : 3];\n               if (tRNS[i] < 255)\n                  num_trans = i+1;\n               /* FALL THROUGH */\n            case 3:\n               palette[i].blue = entry[afirst + (2 ^ bgr)];\n               palette[i].green = entry[afirst + 1];\n               palette[i].red = entry[afirst + bgr];\n               break;\n\n            case 2:\n               tRNS[i] = entry[1 ^ afirst];\n               if (tRNS[i] < 255)\n                  num_trans = i+1;\n               /* FALL THROUGH */\n            case 1:\n               palette[i].blue = palette[i].red = palette[i].green =\n                  entry[afirst];\n               break;\n\n            default:\n               break;\n         }\n      }\n   }\n\n#   ifdef afirst\n#     undef afirst\n#   endif\n#   ifdef bgr\n#     undef bgr\n#   endif\n\n   png_set_PLTE(image->opaque->png_ptr, image->opaque->info_ptr, palette,\n       entries);\n\n   if (num_trans > 0)\n      png_set_tRNS(image->opaque->png_ptr, image->opaque->info_ptr, tRNS,\n          num_trans, NULL);\n\n   image->colormap_entries = entries;\n}\n\nstatic int\npng_image_write_main(png_voidp argument)\n{\n   png_image_write_control *display = png_voidcast(png_image_write_control*,\n       argument);\n   png_imagep image = display->image;\n   png_structrp png_ptr = image->opaque->png_ptr;\n   png_inforp info_ptr = image->opaque->info_ptr;\n   png_uint_32 format = image->format;\n\n   /* The following four ints are actually booleans */\n   int colormap = (format & PNG_FORMAT_FLAG_COLORMAP);\n   int linear = !colormap && (format & PNG_FORMAT_FLAG_LINEAR); /* input */\n   int alpha = !colormap && (format & PNG_FORMAT_FLAG_ALPHA);\n   int write_16bit = linear && !colormap && (display->convert_to_8bit == 0);\n\n#   ifdef PNG_BENIGN_ERRORS_SUPPORTED\n      /* Make sure we error out on any bad situation */\n      png_set_benign_errors(png_ptr, 0/*error*/);\n#   endif\n\n   /* Default the 'row_stride' parameter if required, also check the row stride\n    * and total image size to ensure that they are within the system limits.\n    */\n   {\n      const unsigned int channels = PNG_IMAGE_PIXEL_CHANNELS(image->format);\n\n      if (image->width <= 0x7FFFFFFFU/channels) /* no overflow */\n      {\n         png_uint_32 check;\n         const png_uint_32 png_row_stride = image->width * channels;\n\n         if (display->row_stride == 0)\n            display->row_stride = (png_int_32)/*SAFE*/png_row_stride;\n\n         if (display->row_stride < 0)\n            check = -display->row_stride;\n\n         else\n            check = display->row_stride;\n\n         if (check >= png_row_stride)\n         {\n            /* Now check for overflow of the image buffer calculation; this\n             * limits the whole image size to 32 bits for API compatibility with\n             * the current, 32-bit, PNG_IMAGE_BUFFER_SIZE macro.\n             */\n            if (image->height > 0xFFFFFFFF/png_row_stride)\n               png_error(image->opaque->png_ptr, \"memory image too large\");\n         }\n\n         else\n            png_error(image->opaque->png_ptr, \"supplied row stride too small\");\n      }\n\n      else\n         png_error(image->opaque->png_ptr, \"image row stride too large\");\n   }\n\n   /* Set the required transforms then write the rows in the correct order. */\n   if ((format & PNG_FORMAT_FLAG_COLORMAP) != 0)\n   {\n      if (display->colormap != NULL && image->colormap_entries > 0)\n      {\n         png_uint_32 entries = image->colormap_entries;\n\n         png_set_IHDR(png_ptr, info_ptr, image->width, image->height,\n             entries > 16 ? 8 : (entries > 4 ? 4 : (entries > 2 ? 2 : 1)),\n             PNG_COLOR_TYPE_PALETTE, PNG_INTERLACE_NONE,\n             PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n         png_image_set_PLTE(display);\n      }\n\n      else\n         png_error(image->opaque->png_ptr,\n             \"no color-map for color-mapped image\");\n   }\n\n   else\n      png_set_IHDR(png_ptr, info_ptr, image->width, image->height,\n          write_16bit ? 16 : 8,\n          ((format & PNG_FORMAT_FLAG_COLOR) ? PNG_COLOR_MASK_COLOR : 0) +\n          ((format & PNG_FORMAT_FLAG_ALPHA) ? PNG_COLOR_MASK_ALPHA : 0),\n          PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);\n\n   /* Counter-intuitively the data transformations must be called *after*\n    * png_write_info, not before as in the read code, but the 'set' functions\n    * must still be called before.  Just set the color space information, never\n    * write an interlaced image.\n    */\n\n   if (write_16bit != 0)\n   {\n      /* The gamma here is 1.0 (linear) and the cHRM chunk matches sRGB. */\n      png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_LINEAR);\n\n      if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)\n         png_set_cHRM_fixed(png_ptr, info_ptr,\n             /* color      x       y */\n             /* white */ 31270, 32900,\n             /* red   */ 64000, 33000,\n             /* green */ 30000, 60000,\n             /* blue  */ 15000,  6000\n         );\n   }\n\n   else if ((image->flags & PNG_IMAGE_FLAG_COLORSPACE_NOT_sRGB) == 0)\n      png_set_sRGB(png_ptr, info_ptr, PNG_sRGB_INTENT_PERCEPTUAL);\n\n   /* Else writing an 8-bit file and the *colors* aren't sRGB, but the 8-bit\n    * space must still be gamma encoded.\n    */\n   else\n      png_set_gAMA_fixed(png_ptr, info_ptr, PNG_GAMMA_sRGB_INVERSE);\n\n   /* Write the file header. */\n   png_write_info(png_ptr, info_ptr);\n\n   /* Now set up the data transformations (*after* the header is written),\n    * remove the handled transformations from the 'format' flags for checking.\n    *\n    * First check for a little endian system if writing 16-bit files.\n    */\n   if (write_16bit != 0)\n   {\n      PNG_CONST png_uint_16 le = 0x0001;\n\n      if ((*(png_const_bytep) & le) != 0)\n         png_set_swap(png_ptr);\n   }\n\n#   ifdef PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED\n      if ((format & PNG_FORMAT_FLAG_BGR) != 0)\n      {\n         if (colormap == 0 && (format & PNG_FORMAT_FLAG_COLOR) != 0)\n            png_set_bgr(png_ptr);\n         format &= ~PNG_FORMAT_FLAG_BGR;\n      }\n#   endif\n\n#   ifdef PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED\n      if ((format & PNG_FORMAT_FLAG_AFIRST) != 0)\n      {\n         if (colormap == 0 && (format & PNG_FORMAT_FLAG_ALPHA) != 0)\n            png_set_swap_alpha(png_ptr);\n         format &= ~PNG_FORMAT_FLAG_AFIRST;\n      }\n#   endif\n\n   /* If there are 16 or fewer color-map entries we wrote a lower bit depth\n    * above, but the application data is still byte packed.\n    */\n   if (colormap != 0 && image->colormap_entries <= 16)\n      png_set_packing(png_ptr);\n\n   /* That should have handled all (both) the transforms. */\n   if ((format & ~(png_uint_32)(PNG_FORMAT_FLAG_COLOR | PNG_FORMAT_FLAG_LINEAR |\n         PNG_FORMAT_FLAG_ALPHA | PNG_FORMAT_FLAG_COLORMAP)) != 0)\n      png_error(png_ptr, \"png_write_image: unsupported transformation\");\n\n   {\n      png_const_bytep row = png_voidcast(png_const_bytep, display->buffer);\n      ptrdiff_t row_bytes = display->row_stride;\n\n      if (linear != 0)\n         row_bytes *= (sizeof (png_uint_16));\n\n      if (row_bytes < 0)\n         row += (image->height-1) * (-row_bytes);\n\n      display->first_row = row;\n      display->row_bytes = row_bytes;\n   }\n\n   /* Apply 'fast' options if the flag is set. */\n   if ((image->flags & PNG_IMAGE_FLAG_FAST) != 0)\n   {\n      png_set_filter(png_ptr, PNG_FILTER_TYPE_BASE, PNG_NO_FILTERS);\n      /* NOTE: determined by experiment using pngstest, this reflects some\n       * balance between the time to write the image once and the time to read\n       * it about 50 times.  The speed-up in pngstest was about 10-20% of the\n       * total (user) time on a heavily loaded system.\n       */\n#   ifdef PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\n      png_set_compression_level(png_ptr, 3);\n#   endif\n   }\n\n   /* Check for the cases that currently require a pre-transform on the row\n    * before it is written.  This only applies when the input is 16-bit and\n    * either there is an alpha channel or it is converted to 8-bit.\n    */\n   if ((linear != 0 && alpha != 0 ) ||\n       (colormap == 0 && display->convert_to_8bit != 0))\n   {\n      png_bytep row = png_voidcast(png_bytep, png_malloc(png_ptr,\n          png_get_rowbytes(png_ptr, info_ptr)));\n      int result;\n\n      display->local_row = row;\n      if (write_16bit != 0)\n         result = png_safe_execute(image, png_write_image_16bit, display);\n      else\n         result = png_safe_execute(image, png_write_image_8bit, display);\n      display->local_row = NULL;\n\n      png_free(png_ptr, row);\n\n      /* Skip the 'write_end' on error: */\n      if (result == 0)\n         return 0;\n   }\n\n   /* Otherwise this is the case where the input is in a format currently\n    * supported by the rest of the libpng write code; call it directly.\n    */\n   else\n   {\n      png_const_bytep row = png_voidcast(png_const_bytep, display->first_row);\n      ptrdiff_t row_bytes = display->row_bytes;\n      png_uint_32 y = image->height;\n\n      while (y-- > 0)\n      {\n         png_write_row(png_ptr, row);\n         row += row_bytes;\n      }\n   }\n\n   png_write_end(png_ptr, info_ptr);\n   return 1;\n}\n\n\nstatic void (PNGCBAPI\nimage_memory_write)(png_structp png_ptr, png_bytep/*const*/ data,\n    png_size_t size)\n{\n   png_image_write_control *display = png_voidcast(png_image_write_control*,\n       png_ptr->io_ptr/*backdoor: png_get_io_ptr(png_ptr)*/);\n   const png_alloc_size_t ob = display->output_bytes;\n\n   /* Check for overflow; this should never happen: */\n   if (size <= ((png_alloc_size_t)-1) - ob)\n   {\n      /* I don't think libpng ever does this, but just in case: */\n      if (size > 0)\n      {\n         if (display->memory_bytes >= ob+size) /* writing */\n            memcpy(display->memory+ob, data, size);\n\n         /* Always update the size: */\n         display->output_bytes = ob+size;\n      }\n   }\n\n   else\n      png_error(png_ptr, \"png_image_write_to_memory: PNG too big\");\n}\n\nstatic void (PNGCBAPI\nimage_memory_flush)(png_structp png_ptr)\n{\n   PNG_UNUSED(png_ptr)\n}\n\nstatic int\npng_image_write_memory(png_voidp argument)\n{\n   png_image_write_control *display = png_voidcast(png_image_write_control*,\n       argument);\n\n   /* The rest of the memory-specific init and write_main in an error protected\n    * environment.  This case needs to use callbacks for the write operations\n    * since libpng has no built in support for writing to memory.\n    */\n   png_set_write_fn(display->image->opaque->png_ptr, display/*io_ptr*/,\n       image_memory_write, image_memory_flush);\n\n   return png_image_write_main(display);\n}\n\nint PNGAPI\npng_image_write_to_memory(png_imagep image, void *memory,\n    png_alloc_size_t * PNG_RESTRICT memory_bytes, int convert_to_8bit,\n    const void *buffer, png_int_32 row_stride, const void *colormap)\n{\n   /* Write the image to the given buffer, or count the bytes if it is NULL */\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (memory_bytes != NULL && buffer != NULL)\n      {\n         /* This is to give the caller an easier error detection in the NULL\n          * case and guard against uninitialized variable problems:\n          */\n         if (memory == NULL)\n            *memory_bytes = 0;\n\n         if (png_image_write_init(image) != 0)\n         {\n            png_image_write_control display;\n            int result;\n\n            memset(&display, 0, (sizeof display));\n            display.image = image;\n            display.buffer = buffer;\n            display.row_stride = row_stride;\n            display.colormap = colormap;\n            display.convert_to_8bit = convert_to_8bit;\n            display.memory = png_voidcast(png_bytep, memory);\n            display.memory_bytes = *memory_bytes;\n            display.output_bytes = 0;\n\n            result = png_safe_execute(image, png_image_write_memory, &display);\n            png_image_free(image);\n\n            /* write_memory returns true even if we ran out of buffer. */\n            if (result)\n            {\n               /* On out-of-buffer this function returns '0' but still updates\n                * memory_bytes:\n                */\n               if (memory != NULL && display.output_bytes > *memory_bytes)\n                  result = 0;\n\n               *memory_bytes = display.output_bytes;\n            }\n\n            return result;\n         }\n\n         else\n            return 0;\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_write_to_memory: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_write_to_memory: incorrect PNG_IMAGE_VERSION\");\n\n   else\n      return 0;\n}\n\n#ifdef PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\nint PNGAPI\npng_image_write_to_stdio(png_imagep image, FILE *file, int convert_to_8bit,\n    const void *buffer, png_int_32 row_stride, const void *colormap)\n{\n   /* Write the image to the given (FILE*). */\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (file != NULL && buffer != NULL)\n      {\n         if (png_image_write_init(image) != 0)\n         {\n            png_image_write_control display;\n            int result;\n\n            /* This is slightly evil, but png_init_io doesn't do anything other\n             * than this and we haven't changed the standard IO functions so\n             * this saves a 'safe' function.\n             */\n            image->opaque->png_ptr->io_ptr = file;\n\n            memset(&display, 0, (sizeof display));\n            display.image = image;\n            display.buffer = buffer;\n            display.row_stride = row_stride;\n            display.colormap = colormap;\n            display.convert_to_8bit = convert_to_8bit;\n\n            result = png_safe_execute(image, png_image_write_main, &display);\n            png_image_free(image);\n            return result;\n         }\n\n         else\n            return 0;\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_write_to_stdio: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_write_to_stdio: incorrect PNG_IMAGE_VERSION\");\n\n   else\n      return 0;\n}\n\nint PNGAPI\npng_image_write_to_file(png_imagep image, const char *file_name,\n    int convert_to_8bit, const void *buffer, png_int_32 row_stride,\n    const void *colormap)\n{\n   /* Write the image to the named file. */\n   if (image != NULL && image->version == PNG_IMAGE_VERSION)\n   {\n      if (file_name != NULL && buffer != NULL)\n      {\n         FILE *fp = fopen(file_name, \"wb\");\n\n         if (fp != NULL)\n         {\n            if (png_image_write_to_stdio(image, fp, convert_to_8bit, buffer,\n                row_stride, colormap) != 0)\n            {\n               int error; /* from fflush/fclose */\n\n               /* Make sure the file is flushed correctly. */\n               if (fflush(fp) == 0 && ferror(fp) == 0)\n               {\n                  if (fclose(fp) == 0)\n                     return 1;\n\n                  error = errno; /* from fclose */\n               }\n\n               else\n               {\n                  error = errno; /* from fflush or ferror */\n                  (void)fclose(fp);\n               }\n\n               (void)remove(file_name);\n               /* The image has already been cleaned up; this is just used to\n                * set the error (because the original write succeeded).\n                */\n               return png_image_error(image, strerror(error));\n            }\n\n            else\n            {\n               /* Clean up: just the opened file. */\n               (void)fclose(fp);\n               (void)remove(file_name);\n               return 0;\n            }\n         }\n\n         else\n            return png_image_error(image, strerror(errno));\n      }\n\n      else\n         return png_image_error(image,\n             \"png_image_write_to_file: invalid argument\");\n   }\n\n   else if (image != NULL)\n      return png_image_error(image,\n          \"png_image_write_to_file: incorrect PNG_IMAGE_VERSION\");\n\n   else\n      return 0;\n}\n#endif /* SIMPLIFIED_WRITE_STDIO */\n#endif /* SIMPLIFIED_WRITE */\n#endif /* WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngwtran.c",
    "content": "\n/* pngwtran.c - transforms the data in a row for PNG writers\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_WRITE_SUPPORTED\n#ifdef PNG_WRITE_TRANSFORMS_SUPPORTED\n\n#ifdef PNG_WRITE_PACK_SUPPORTED\n/* Pack pixels into bytes.  Pass the true bit depth in bit_depth.  The\n * row_info bit depth should be 8 (one pixel per byte).  The channels\n * should be 1 (this only happens on grayscale and paletted images).\n */\nstatic void\npng_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)\n{\n   png_debug(1, \"in png_do_pack\");\n\n   if (row_info->bit_depth == 8 &&\n      row_info->channels == 1)\n   {\n      switch ((int)bit_depth)\n      {\n         case 1:\n         {\n            png_bytep sp, dp;\n            int mask, v;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            sp = row;\n            dp = row;\n            mask = 0x80;\n            v = 0;\n\n            for (i = 0; i < row_width; i++)\n            {\n               if (*sp != 0)\n                  v |= mask;\n\n               sp++;\n\n               if (mask > 1)\n                  mask >>= 1;\n\n               else\n               {\n                  mask = 0x80;\n                  *dp = (png_byte)v;\n                  dp++;\n                  v = 0;\n               }\n            }\n\n            if (mask != 0x80)\n               *dp = (png_byte)v;\n\n            break;\n         }\n\n         case 2:\n         {\n            png_bytep sp, dp;\n            unsigned int shift;\n            int v;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            sp = row;\n            dp = row;\n            shift = 6;\n            v = 0;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_byte value;\n\n               value = (png_byte)(*sp & 0x03);\n               v |= (value << shift);\n\n               if (shift == 0)\n               {\n                  shift = 6;\n                  *dp = (png_byte)v;\n                  dp++;\n                  v = 0;\n               }\n\n               else\n                  shift -= 2;\n\n               sp++;\n            }\n\n            if (shift != 6)\n               *dp = (png_byte)v;\n\n            break;\n         }\n\n         case 4:\n         {\n            png_bytep sp, dp;\n            unsigned int shift;\n            int v;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            sp = row;\n            dp = row;\n            shift = 4;\n            v = 0;\n\n            for (i = 0; i < row_width; i++)\n            {\n               png_byte value;\n\n               value = (png_byte)(*sp & 0x0f);\n               v |= (value << shift);\n\n               if (shift == 0)\n               {\n                  shift = 4;\n                  *dp = (png_byte)v;\n                  dp++;\n                  v = 0;\n               }\n\n               else\n                  shift -= 4;\n\n               sp++;\n            }\n\n            if (shift != 4)\n               *dp = (png_byte)v;\n\n            break;\n         }\n\n         default:\n            break;\n      }\n\n      row_info->bit_depth = (png_byte)bit_depth;\n      row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,\n          row_info->width);\n   }\n}\n#endif\n\n#ifdef PNG_WRITE_SHIFT_SUPPORTED\n/* Shift pixel values to take advantage of whole range.  Pass the\n * true number of bits in bit_depth.  The row should be packed\n * according to row_info->bit_depth.  Thus, if you had a row of\n * bit depth 4, but the pixels only had values from 0 to 7, you\n * would pass 3 as bit_depth, and this routine would translate the\n * data to 0 to 15.\n */\nstatic void\npng_do_shift(png_row_infop row_info, png_bytep row,\n    png_const_color_8p bit_depth)\n{\n   png_debug(1, \"in png_do_shift\");\n\n   if (row_info->color_type != PNG_COLOR_TYPE_PALETTE)\n   {\n      int shift_start[4], shift_dec[4];\n      int channels = 0;\n\n      if ((row_info->color_type & PNG_COLOR_MASK_COLOR) != 0)\n      {\n         shift_start[channels] = row_info->bit_depth - bit_depth->red;\n         shift_dec[channels] = bit_depth->red;\n         channels++;\n\n         shift_start[channels] = row_info->bit_depth - bit_depth->green;\n         shift_dec[channels] = bit_depth->green;\n         channels++;\n\n         shift_start[channels] = row_info->bit_depth - bit_depth->blue;\n         shift_dec[channels] = bit_depth->blue;\n         channels++;\n      }\n\n      else\n      {\n         shift_start[channels] = row_info->bit_depth - bit_depth->gray;\n         shift_dec[channels] = bit_depth->gray;\n         channels++;\n      }\n\n      if ((row_info->color_type & PNG_COLOR_MASK_ALPHA) != 0)\n      {\n         shift_start[channels] = row_info->bit_depth - bit_depth->alpha;\n         shift_dec[channels] = bit_depth->alpha;\n         channels++;\n      }\n\n      /* With low row depths, could only be grayscale, so one channel */\n      if (row_info->bit_depth < 8)\n      {\n         png_bytep bp = row;\n         png_size_t i;\n         unsigned int mask;\n         png_size_t row_bytes = row_info->rowbytes;\n\n         if (bit_depth->gray == 1 && row_info->bit_depth == 2)\n            mask = 0x55;\n\n         else if (row_info->bit_depth == 4 && bit_depth->gray == 3)\n            mask = 0x11;\n\n         else\n            mask = 0xff;\n\n         for (i = 0; i < row_bytes; i++, bp++)\n         {\n            int j;\n            unsigned int v, out;\n\n            v = *bp;\n            out = 0;\n\n            for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])\n            {\n               if (j > 0)\n                  out |= v << j;\n\n               else\n                  out |= (v >> (-j)) & mask;\n            }\n\n            *bp = (png_byte)(out & 0xff);\n         }\n      }\n\n      else if (row_info->bit_depth == 8)\n      {\n         png_bytep bp = row;\n         png_uint_32 i;\n         png_uint_32 istop = channels * row_info->width;\n\n         for (i = 0; i < istop; i++, bp++)\n         {\n\n            const unsigned int c = i%channels;\n            int j;\n            unsigned int v, out;\n\n            v = *bp;\n            out = 0;\n\n            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])\n            {\n               if (j > 0)\n                  out |= v << j;\n\n               else\n                  out |= v >> (-j);\n            }\n\n            *bp = (png_byte)(out & 0xff);\n         }\n      }\n\n      else\n      {\n         png_bytep bp;\n         png_uint_32 i;\n         png_uint_32 istop = channels * row_info->width;\n\n         for (bp = row, i = 0; i < istop; i++)\n         {\n            const unsigned int c = i%channels;\n            int j;\n            unsigned int value, v;\n\n            v = png_get_uint_16(bp);\n            value = 0;\n\n            for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])\n            {\n               if (j > 0)\n                  value |= v << j;\n\n               else\n                  value |= v >> (-j);\n            }\n            *bp++ = (png_byte)((value >> 8) & 0xff);\n            *bp++ = (png_byte)(value & 0xff);\n         }\n      }\n   }\n}\n#endif\n\n#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED\nstatic void\npng_do_write_swap_alpha(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_write_swap_alpha\");\n\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This converts from ARGB to RGBA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               png_byte save = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = save;\n            }\n         }\n\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         else\n         {\n            /* This converts from AARRGGBB to RRGGBBAA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               png_byte save[2];\n               save[0] = *(sp++);\n               save[1] = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = save[0];\n               *(dp++) = save[1];\n            }\n         }\n#endif /* WRITE_16BIT */\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This converts from AG to GA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               png_byte save = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = save;\n            }\n         }\n\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         else\n         {\n            /* This converts from AAGG to GGAA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               png_byte save[2];\n               save[0] = *(sp++);\n               save[1] = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = save[0];\n               *(dp++) = save[1];\n            }\n         }\n#endif /* WRITE_16BIT */\n      }\n   }\n}\n#endif\n\n#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED\nstatic void\npng_do_write_invert_alpha(png_row_infop row_info, png_bytep row)\n{\n   png_debug(1, \"in png_do_write_invert_alpha\");\n\n   {\n      if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This inverts the alpha channel in RGBA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               /* Does nothing\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               */\n               sp+=3; dp = sp;\n               *dp = (png_byte)(255 - *(sp++));\n            }\n         }\n\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         else\n         {\n            /* This inverts the alpha channel in RRGGBBAA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               /* Does nothing\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               */\n               sp+=6; dp = sp;\n               *(dp++) = (png_byte)(255 - *(sp++));\n               *dp     = (png_byte)(255 - *(sp++));\n            }\n         }\n#endif /* WRITE_16BIT */\n      }\n\n      else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)\n      {\n         if (row_info->bit_depth == 8)\n         {\n            /* This inverts the alpha channel in GA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               *(dp++) = *(sp++);\n               *(dp++) = (png_byte)(255 - *(sp++));\n            }\n         }\n\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         else\n         {\n            /* This inverts the alpha channel in GGAA */\n            png_bytep sp, dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            for (i = 0, sp = dp = row; i < row_width; i++)\n            {\n               /* Does nothing\n               *(dp++) = *(sp++);\n               *(dp++) = *(sp++);\n               */\n               sp+=2; dp = sp;\n               *(dp++) = (png_byte)(255 - *(sp++));\n               *dp     = (png_byte)(255 - *(sp++));\n            }\n         }\n#endif /* WRITE_16BIT */\n      }\n   }\n}\n#endif\n\n/* Transform the data according to the user's wishes.  The order of\n * transformations is significant.\n */\nvoid /* PRIVATE */\npng_do_write_transformations(png_structrp png_ptr, png_row_infop row_info)\n{\n   png_debug(1, \"in png_do_write_transformations\");\n\n   if (png_ptr == NULL)\n      return;\n\n#ifdef PNG_WRITE_USER_TRANSFORM_SUPPORTED\n   if ((png_ptr->transformations & PNG_USER_TRANSFORM) != 0)\n      if (png_ptr->write_user_transform_fn != NULL)\n         (*(png_ptr->write_user_transform_fn)) /* User write transform\n                                                 function */\n             (png_ptr,  /* png_ptr */\n             row_info,  /* row_info: */\n                /*  png_uint_32 width;       width of row */\n                /*  png_size_t rowbytes;     number of bytes in row */\n                /*  png_byte color_type;     color type of pixels */\n                /*  png_byte bit_depth;      bit depth of samples */\n                /*  png_byte channels;       number of channels (1-4) */\n                /*  png_byte pixel_depth;    bits per pixel (depth*channels) */\n             png_ptr->row_buf + 1);      /* start of pixel data for row */\n#endif\n\n#ifdef PNG_WRITE_FILLER_SUPPORTED\n   if ((png_ptr->transformations & PNG_FILLER) != 0)\n      png_do_strip_channel(row_info, png_ptr->row_buf + 1,\n          !(png_ptr->flags & PNG_FLAG_FILLER_AFTER));\n#endif\n\n#ifdef PNG_WRITE_PACKSWAP_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACKSWAP) != 0)\n      png_do_packswap(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_WRITE_PACK_SUPPORTED\n   if ((png_ptr->transformations & PNG_PACK) != 0)\n      png_do_pack(row_info, png_ptr->row_buf + 1,\n          (png_uint_32)png_ptr->bit_depth);\n#endif\n\n#ifdef PNG_WRITE_SWAP_SUPPORTED\n#  ifdef PNG_16BIT_SUPPORTED\n   if ((png_ptr->transformations & PNG_SWAP_BYTES) != 0)\n      png_do_swap(row_info, png_ptr->row_buf + 1);\n#  endif\n#endif\n\n#ifdef PNG_WRITE_SHIFT_SUPPORTED\n   if ((png_ptr->transformations & PNG_SHIFT) != 0)\n      png_do_shift(row_info, png_ptr->row_buf + 1,\n           &(png_ptr->shift));\n#endif\n\n#ifdef PNG_WRITE_SWAP_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_SWAP_ALPHA) != 0)\n      png_do_write_swap_alpha(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_WRITE_INVERT_ALPHA_SUPPORTED\n   if ((png_ptr->transformations & PNG_INVERT_ALPHA) != 0)\n      png_do_write_invert_alpha(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_WRITE_BGR_SUPPORTED\n   if ((png_ptr->transformations & PNG_BGR) != 0)\n      png_do_bgr(row_info, png_ptr->row_buf + 1);\n#endif\n\n#ifdef PNG_WRITE_INVERT_SUPPORTED\n   if ((png_ptr->transformations & PNG_INVERT_MONO) != 0)\n      png_do_invert(row_info, png_ptr->row_buf + 1);\n#endif\n}\n#endif /* WRITE_TRANSFORMS */\n#endif /* WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/pngwutil.c",
    "content": "\n/* pngwutil.c - utilities to write a PNG file\n *\n * Last changed in libpng 1.6.24 [August 4, 2016]\n * Copyright (c) 1998-2002,2004,2006-2016 Glenn Randers-Pehrson\n * (Version 0.96 Copyright (c) 1996, 1997 Andreas Dilger)\n * (Version 0.88 Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.)\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#include \"pngpriv.h\"\n\n#ifdef PNG_WRITE_SUPPORTED\n\n#ifdef PNG_WRITE_INT_FUNCTIONS_SUPPORTED\n/* Place a 32-bit number into a buffer in PNG byte order.  We work\n * with unsigned numbers for convenience, although one supported\n * ancillary chunk uses signed (two's complement) numbers.\n */\nvoid PNGAPI\npng_save_uint_32(png_bytep buf, png_uint_32 i)\n{\n   buf[0] = (png_byte)((i >> 24) & 0xffU);\n   buf[1] = (png_byte)((i >> 16) & 0xffU);\n   buf[2] = (png_byte)((i >>  8) & 0xffU);\n   buf[3] = (png_byte)( i        & 0xffU);\n}\n\n/* Place a 16-bit number into a buffer in PNG byte order.\n * The parameter is declared unsigned int, not png_uint_16,\n * just to avoid potential problems on pre-ANSI C compilers.\n */\nvoid PNGAPI\npng_save_uint_16(png_bytep buf, unsigned int i)\n{\n   buf[0] = (png_byte)((i >> 8) & 0xffU);\n   buf[1] = (png_byte)( i       & 0xffU);\n}\n#endif\n\n/* Simple function to write the signature.  If we have already written\n * the magic bytes of the signature, or more likely, the PNG stream is\n * being embedded into another stream and doesn't need its own signature,\n * we should call png_set_sig_bytes() to tell libpng how many of the\n * bytes have already been written.\n */\nvoid PNGAPI\npng_write_sig(png_structrp png_ptr)\n{\n   png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   /* Inform the I/O callback that the signature is being written */\n   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_SIGNATURE;\n#endif\n\n   /* Write the rest of the 8 byte signature */\n   png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],\n       (png_size_t)(8 - png_ptr->sig_bytes));\n\n   if (png_ptr->sig_bytes < 3)\n      png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;\n}\n\n/* Write the start of a PNG chunk.  The type is the chunk type.\n * The total_length is the sum of the lengths of all the data you will be\n * passing in png_write_chunk_data().\n */\nstatic void\npng_write_chunk_header(png_structrp png_ptr, png_uint_32 chunk_name,\n    png_uint_32 length)\n{\n   png_byte buf[8];\n\n#if defined(PNG_DEBUG) && (PNG_DEBUG > 0)\n   PNG_CSTRING_FROM_CHUNK(buf, chunk_name);\n   png_debug2(0, \"Writing %s chunk, length = %lu\", buf, (unsigned long)length);\n#endif\n\n   if (png_ptr == NULL)\n      return;\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   /* Inform the I/O callback that the chunk header is being written.\n    * PNG_IO_CHUNK_HDR requires a single I/O call.\n    */\n   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_HDR;\n#endif\n\n   /* Write the length and the chunk name */\n   png_save_uint_32(buf, length);\n   png_save_uint_32(buf + 4, chunk_name);\n   png_write_data(png_ptr, buf, 8);\n\n   /* Put the chunk name into png_ptr->chunk_name */\n   png_ptr->chunk_name = chunk_name;\n\n   /* Reset the crc and run it over the chunk name */\n   png_reset_crc(png_ptr);\n\n   png_calculate_crc(png_ptr, buf + 4, 4);\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   /* Inform the I/O callback that chunk data will (possibly) be written.\n    * PNG_IO_CHUNK_DATA does NOT require a specific number of I/O calls.\n    */\n   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_DATA;\n#endif\n}\n\nvoid PNGAPI\npng_write_chunk_start(png_structrp png_ptr, png_const_bytep chunk_string,\n    png_uint_32 length)\n{\n   png_write_chunk_header(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), length);\n}\n\n/* Write the data of a PNG chunk started with png_write_chunk_header().\n * Note that multiple calls to this function are allowed, and that the\n * sum of the lengths from these calls *must* add up to the total_length\n * given to png_write_chunk_header().\n */\nvoid PNGAPI\npng_write_chunk_data(png_structrp png_ptr, png_const_bytep data,\n    png_size_t length)\n{\n   /* Write the data, and run the CRC over it */\n   if (png_ptr == NULL)\n      return;\n\n   if (data != NULL && length > 0)\n   {\n      png_write_data(png_ptr, data, length);\n\n      /* Update the CRC after writing the data,\n       * in case the user I/O routine alters it.\n       */\n      png_calculate_crc(png_ptr, data, length);\n   }\n}\n\n/* Finish a chunk started with png_write_chunk_header(). */\nvoid PNGAPI\npng_write_chunk_end(png_structrp png_ptr)\n{\n   png_byte buf[4];\n\n   if (png_ptr == NULL) return;\n\n#ifdef PNG_IO_STATE_SUPPORTED\n   /* Inform the I/O callback that the chunk CRC is being written.\n    * PNG_IO_CHUNK_CRC requires a single I/O function call.\n    */\n   png_ptr->io_state = PNG_IO_WRITING | PNG_IO_CHUNK_CRC;\n#endif\n\n   /* Write the crc in a single operation */\n   png_save_uint_32(buf, png_ptr->crc);\n\n   png_write_data(png_ptr, buf, (png_size_t)4);\n}\n\n/* Write a PNG chunk all at once.  The type is an array of ASCII characters\n * representing the chunk name.  The array must be at least 4 bytes in\n * length, and does not need to be null terminated.  To be safe, pass the\n * pre-defined chunk names here, and if you need a new one, define it\n * where the others are defined.  The length is the length of the data.\n * All the data must be present.  If that is not possible, use the\n * png_write_chunk_start(), png_write_chunk_data(), and png_write_chunk_end()\n * functions instead.\n */\nstatic void\npng_write_complete_chunk(png_structrp png_ptr, png_uint_32 chunk_name,\n    png_const_bytep data, png_size_t length)\n{\n   if (png_ptr == NULL)\n      return;\n\n   /* On 64-bit architectures 'length' may not fit in a png_uint_32. */\n   if (length > PNG_UINT_31_MAX)\n      png_error(png_ptr, \"length exceeds PNG maximum\");\n\n   png_write_chunk_header(png_ptr, chunk_name, (png_uint_32)length);\n   png_write_chunk_data(png_ptr, data, length);\n   png_write_chunk_end(png_ptr);\n}\n\n/* This is the API that calls the internal function above. */\nvoid PNGAPI\npng_write_chunk(png_structrp png_ptr, png_const_bytep chunk_string,\n    png_const_bytep data, png_size_t length)\n{\n   png_write_complete_chunk(png_ptr, PNG_CHUNK_FROM_STRING(chunk_string), data,\n       length);\n}\n\n/* This is used below to find the size of an image to pass to png_deflate_claim,\n * so it only needs to be accurate if the size is less than 16384 bytes (the\n * point at which a lower LZ window size can be used.)\n */\nstatic png_alloc_size_t\npng_image_size(png_structrp png_ptr)\n{\n   /* Only return sizes up to the maximum of a png_uint_32; do this by limiting\n    * the width and height used to 15 bits.\n    */\n   png_uint_32 h = png_ptr->height;\n\n   if (png_ptr->rowbytes < 32768 && h < 32768)\n   {\n      if (png_ptr->interlaced != 0)\n      {\n         /* Interlacing makes the image larger because of the replication of\n          * both the filter byte and the padding to a byte boundary.\n          */\n         png_uint_32 w = png_ptr->width;\n         unsigned int pd = png_ptr->pixel_depth;\n         png_alloc_size_t cb_base;\n         int pass;\n\n         for (cb_base=0, pass=0; pass<=6; ++pass)\n         {\n            png_uint_32 pw = PNG_PASS_COLS(w, pass);\n\n            if (pw > 0)\n               cb_base += (PNG_ROWBYTES(pd, pw)+1) * PNG_PASS_ROWS(h, pass);\n         }\n\n         return cb_base;\n      }\n\n      else\n         return (png_ptr->rowbytes+1) * h;\n   }\n\n   else\n      return 0xffffffffU;\n}\n\n#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n   /* This is the code to hack the first two bytes of the deflate stream (the\n    * deflate header) to correct the windowBits value to match the actual data\n    * size.  Note that the second argument is the *uncompressed* size but the\n    * first argument is the *compressed* data (and it must be deflate\n    * compressed.)\n    */\nstatic void\noptimize_cmf(png_bytep data, png_alloc_size_t data_size)\n{\n   /* Optimize the CMF field in the zlib stream.  The resultant zlib stream is\n    * still compliant to the stream specification.\n    */\n   if (data_size <= 16384) /* else windowBits must be 15 */\n   {\n      unsigned int z_cmf = data[0];  /* zlib compression method and flags */\n\n      if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)\n      {\n         unsigned int z_cinfo;\n         unsigned int half_z_window_size;\n\n         z_cinfo = z_cmf >> 4;\n         half_z_window_size = 1U << (z_cinfo + 7);\n\n         if (data_size <= half_z_window_size) /* else no change */\n         {\n            unsigned int tmp;\n\n            do\n            {\n               half_z_window_size >>= 1;\n               --z_cinfo;\n            }\n            while (z_cinfo > 0 && data_size <= half_z_window_size);\n\n            z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);\n\n            data[0] = (png_byte)z_cmf;\n            tmp = data[1] & 0xe0;\n            tmp += 0x1f - ((z_cmf << 8) + tmp) % 0x1f;\n            data[1] = (png_byte)tmp;\n         }\n      }\n   }\n}\n#endif /* WRITE_OPTIMIZE_CMF */\n\n/* Initialize the compressor for the appropriate type of compression. */\nstatic int\npng_deflate_claim(png_structrp png_ptr, png_uint_32 owner,\n    png_alloc_size_t data_size)\n{\n   if (png_ptr->zowner != 0)\n   {\n#if defined(PNG_WARNINGS_SUPPORTED) || defined(PNG_ERROR_TEXT_SUPPORTED)\n      char msg[64];\n\n      PNG_STRING_FROM_CHUNK(msg, owner);\n      msg[4] = ':';\n      msg[5] = ' ';\n      PNG_STRING_FROM_CHUNK(msg+6, png_ptr->zowner);\n      /* So the message that results is \"<chunk> using zstream\"; this is an\n       * internal error, but is very useful for debugging.  i18n requirements\n       * are minimal.\n       */\n      (void)png_safecat(msg, (sizeof msg), 10, \" using zstream\");\n#endif\n#if PNG_RELEASE_BUILD\n         png_warning(png_ptr, msg);\n\n         /* Attempt sane error recovery */\n         if (png_ptr->zowner == png_IDAT) /* don't steal from IDAT */\n         {\n            png_ptr->zstream.msg = PNGZ_MSG_CAST(\"in use by IDAT\");\n            return Z_STREAM_ERROR;\n         }\n\n         png_ptr->zowner = 0;\n#else\n         png_error(png_ptr, msg);\n#endif\n   }\n\n   {\n      int level = png_ptr->zlib_level;\n      int method = png_ptr->zlib_method;\n      int windowBits = png_ptr->zlib_window_bits;\n      int memLevel = png_ptr->zlib_mem_level;\n      int strategy; /* set below */\n      int ret; /* zlib return code */\n\n      if (owner == png_IDAT)\n      {\n         if ((png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY) != 0)\n            strategy = png_ptr->zlib_strategy;\n\n         else if (png_ptr->do_filter != PNG_FILTER_NONE)\n            strategy = PNG_Z_DEFAULT_STRATEGY;\n\n         else\n            strategy = PNG_Z_DEFAULT_NOFILTER_STRATEGY;\n      }\n\n      else\n      {\n#ifdef PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n            level = png_ptr->zlib_text_level;\n            method = png_ptr->zlib_text_method;\n            windowBits = png_ptr->zlib_text_window_bits;\n            memLevel = png_ptr->zlib_text_mem_level;\n            strategy = png_ptr->zlib_text_strategy;\n#else\n            /* If customization is not supported the values all come from the\n             * IDAT values except for the strategy, which is fixed to the\n             * default.  (This is the pre-1.6.0 behavior too, although it was\n             * implemented in a very different way.)\n             */\n            strategy = Z_DEFAULT_STRATEGY;\n#endif\n      }\n\n      /* Adjust 'windowBits' down if larger than 'data_size'; to stop this\n       * happening just pass 32768 as the data_size parameter.  Notice that zlib\n       * requires an extra 262 bytes in the window in addition to the data to be\n       * able to see the whole of the data, so if data_size+262 takes us to the\n       * next windowBits size we need to fix up the value later.  (Because even\n       * though deflate needs the extra window, inflate does not!)\n       */\n      if (data_size <= 16384)\n      {\n         /* IMPLEMENTATION NOTE: this 'half_window_size' stuff is only here to\n          * work round a Microsoft Visual C misbehavior which, contrary to C-90,\n          * widens the result of the following shift to 64-bits if (and,\n          * apparently, only if) it is used in a test.\n          */\n         unsigned int half_window_size = 1U << (windowBits-1);\n\n         while (data_size + 262 <= half_window_size)\n         {\n            half_window_size >>= 1;\n            --windowBits;\n         }\n      }\n\n      /* Check against the previous initialized values, if any. */\n      if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0 &&\n         (png_ptr->zlib_set_level != level ||\n         png_ptr->zlib_set_method != method ||\n         png_ptr->zlib_set_window_bits != windowBits ||\n         png_ptr->zlib_set_mem_level != memLevel ||\n         png_ptr->zlib_set_strategy != strategy))\n      {\n         if (deflateEnd(&png_ptr->zstream) != Z_OK)\n            png_warning(png_ptr, \"deflateEnd failed (ignored)\");\n\n         png_ptr->flags &= ~PNG_FLAG_ZSTREAM_INITIALIZED;\n      }\n\n      /* For safety clear out the input and output pointers (currently zlib\n       * doesn't use them on Init, but it might in the future).\n       */\n      png_ptr->zstream.next_in = NULL;\n      png_ptr->zstream.avail_in = 0;\n      png_ptr->zstream.next_out = NULL;\n      png_ptr->zstream.avail_out = 0;\n\n      /* Now initialize if required, setting the new parameters, otherwise just\n       * to a simple reset to the previous parameters.\n       */\n      if ((png_ptr->flags & PNG_FLAG_ZSTREAM_INITIALIZED) != 0)\n         ret = deflateReset(&png_ptr->zstream);\n\n      else\n      {\n         ret = deflateInit2(&png_ptr->zstream, level, method, windowBits,\n             memLevel, strategy);\n\n         if (ret == Z_OK)\n            png_ptr->flags |= PNG_FLAG_ZSTREAM_INITIALIZED;\n      }\n\n      /* The return code is from either deflateReset or deflateInit2; they have\n       * pretty much the same set of error codes.\n       */\n      if (ret == Z_OK)\n         png_ptr->zowner = owner;\n\n      else\n         png_zstream_error(png_ptr, ret);\n\n      return ret;\n   }\n}\n\n/* Clean up (or trim) a linked list of compression buffers. */\nvoid /* PRIVATE */\npng_free_buffer_list(png_structrp png_ptr, png_compression_bufferp *listp)\n{\n   png_compression_bufferp list = *listp;\n\n   if (list != NULL)\n   {\n      *listp = NULL;\n\n      do\n      {\n         png_compression_bufferp next = list->next;\n\n         png_free(png_ptr, list);\n         list = next;\n      }\n      while (list != NULL);\n   }\n}\n\n#ifdef PNG_WRITE_COMPRESSED_TEXT_SUPPORTED\n/* This pair of functions encapsulates the operation of (a) compressing a\n * text string, and (b) issuing it later as a series of chunk data writes.\n * The compression_state structure is shared context for these functions\n * set up by the caller to allow access to the relevant local variables.\n *\n * compression_buffer (new in 1.6.0) is just a linked list of zbuffer_size\n * temporary buffers.  From 1.6.0 it is retained in png_struct so that it will\n * be correctly freed in the event of a write error (previous implementations\n * just leaked memory.)\n */\ntypedef struct\n{\n   png_const_bytep      input;        /* The uncompressed input data */\n   png_alloc_size_t     input_len;    /* Its length */\n   png_uint_32          output_len;   /* Final compressed length */\n   png_byte             output[1024]; /* First block of output */\n} compression_state;\n\nstatic void\npng_text_compress_init(compression_state *comp, png_const_bytep input,\n    png_alloc_size_t input_len)\n{\n   comp->input = input;\n   comp->input_len = input_len;\n   comp->output_len = 0;\n}\n\n/* Compress the data in the compression state input */\nstatic int\npng_text_compress(png_structrp png_ptr, png_uint_32 chunk_name,\n    compression_state *comp, png_uint_32 prefix_len)\n{\n   int ret;\n\n   /* To find the length of the output it is necessary to first compress the\n    * input. The result is buffered rather than using the two-pass algorithm\n    * that is used on the inflate side; deflate is assumed to be slower and a\n    * PNG writer is assumed to have more memory available than a PNG reader.\n    *\n    * IMPLEMENTATION NOTE: the zlib API deflateBound() can be used to find an\n    * upper limit on the output size, but it is always bigger than the input\n    * size so it is likely to be more efficient to use this linked-list\n    * approach.\n    */\n   ret = png_deflate_claim(png_ptr, chunk_name, comp->input_len);\n\n   if (ret != Z_OK)\n      return ret;\n\n   /* Set up the compression buffers, we need a loop here to avoid overflowing a\n    * uInt.  Use ZLIB_IO_MAX to limit the input.  The output is always limited\n    * by the output buffer size, so there is no need to check that.  Since this\n    * is ANSI-C we know that an 'int', hence a uInt, is always at least 16 bits\n    * in size.\n    */\n   {\n      png_compression_bufferp *end = &png_ptr->zbuffer_list;\n      png_alloc_size_t input_len = comp->input_len; /* may be zero! */\n      png_uint_32 output_len;\n\n      /* zlib updates these for us: */\n      png_ptr->zstream.next_in = PNGZ_INPUT_CAST(comp->input);\n      png_ptr->zstream.avail_in = 0; /* Set below */\n      png_ptr->zstream.next_out = comp->output;\n      png_ptr->zstream.avail_out = (sizeof comp->output);\n\n      output_len = png_ptr->zstream.avail_out;\n\n      do\n      {\n         uInt avail_in = ZLIB_IO_MAX;\n\n         if (avail_in > input_len)\n            avail_in = (uInt)input_len;\n\n         input_len -= avail_in;\n\n         png_ptr->zstream.avail_in = avail_in;\n\n         if (png_ptr->zstream.avail_out == 0)\n         {\n            png_compression_buffer *next;\n\n            /* Chunk data is limited to 2^31 bytes in length, so the prefix\n             * length must be counted here.\n             */\n            if (output_len + prefix_len > PNG_UINT_31_MAX)\n            {\n               ret = Z_MEM_ERROR;\n               break;\n            }\n\n            /* Need a new (malloc'ed) buffer, but there may be one present\n             * already.\n             */\n            next = *end;\n            if (next == NULL)\n            {\n               next = png_voidcast(png_compression_bufferp, png_malloc_base\n                  (png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr)));\n\n               if (next == NULL)\n               {\n                  ret = Z_MEM_ERROR;\n                  break;\n               }\n\n               /* Link in this buffer (so that it will be freed later) */\n               next->next = NULL;\n               *end = next;\n            }\n\n            png_ptr->zstream.next_out = next->output;\n            png_ptr->zstream.avail_out = png_ptr->zbuffer_size;\n            output_len += png_ptr->zstream.avail_out;\n\n            /* Move 'end' to the next buffer pointer. */\n            end = &next->next;\n         }\n\n         /* Compress the data */\n         ret = deflate(&png_ptr->zstream,\n             input_len > 0 ? Z_NO_FLUSH : Z_FINISH);\n\n         /* Claw back input data that was not consumed (because avail_in is\n          * reset above every time round the loop).\n          */\n         input_len += png_ptr->zstream.avail_in;\n         png_ptr->zstream.avail_in = 0; /* safety */\n      }\n      while (ret == Z_OK);\n\n      /* There may be some space left in the last output buffer. This needs to\n       * be subtracted from output_len.\n       */\n      output_len -= png_ptr->zstream.avail_out;\n      png_ptr->zstream.avail_out = 0; /* safety */\n      comp->output_len = output_len;\n\n      /* Now double check the output length, put in a custom message if it is\n       * too long.  Otherwise ensure the z_stream::msg pointer is set to\n       * something.\n       */\n      if (output_len + prefix_len >= PNG_UINT_31_MAX)\n      {\n         png_ptr->zstream.msg = PNGZ_MSG_CAST(\"compressed data too long\");\n         ret = Z_MEM_ERROR;\n      }\n\n      else\n         png_zstream_error(png_ptr, ret);\n\n      /* Reset zlib for another zTXt/iTXt or image data */\n      png_ptr->zowner = 0;\n\n      /* The only success case is Z_STREAM_END, input_len must be 0; if not this\n       * is an internal error.\n       */\n      if (ret == Z_STREAM_END && input_len == 0)\n      {\n#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n         /* Fix up the deflate header, if required */\n         optimize_cmf(comp->output, comp->input_len);\n#endif\n         /* But Z_OK is returned, not Z_STREAM_END; this allows the claim\n          * function above to return Z_STREAM_END on an error (though it never\n          * does in the current versions of zlib.)\n          */\n         return Z_OK;\n      }\n\n      else\n         return ret;\n   }\n}\n\n/* Ship the compressed text out via chunk writes */\nstatic void\npng_write_compressed_data_out(png_structrp png_ptr, compression_state *comp)\n{\n   png_uint_32 output_len = comp->output_len;\n   png_const_bytep output = comp->output;\n   png_uint_32 avail = (sizeof comp->output);\n   png_compression_buffer *next = png_ptr->zbuffer_list;\n\n   for (;;)\n   {\n      if (avail > output_len)\n         avail = output_len;\n\n      png_write_chunk_data(png_ptr, output, avail);\n\n      output_len -= avail;\n\n      if (output_len == 0 || next == NULL)\n         break;\n\n      avail = png_ptr->zbuffer_size;\n      output = next->output;\n      next = next->next;\n   }\n\n   /* This is an internal error; 'next' must have been NULL! */\n   if (output_len > 0)\n      png_error(png_ptr, \"error writing ancillary chunked compressed data\");\n}\n#endif /* WRITE_COMPRESSED_TEXT */\n\n/* Write the IHDR chunk, and update the png_struct with the necessary\n * information.  Note that the rest of this code depends upon this\n * information being correct.\n */\nvoid /* PRIVATE */\npng_write_IHDR(png_structrp png_ptr, png_uint_32 width, png_uint_32 height,\n    int bit_depth, int color_type, int compression_type, int filter_type,\n    int interlace_type)\n{\n   png_byte buf[13]; /* Buffer to store the IHDR info */\n\n   png_debug(1, \"in png_write_IHDR\");\n\n   /* Check that we have valid input data from the application info */\n   switch (color_type)\n   {\n      case PNG_COLOR_TYPE_GRAY:\n         switch (bit_depth)\n         {\n            case 1:\n            case 2:\n            case 4:\n            case 8:\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n            case 16:\n#endif\n               png_ptr->channels = 1; break;\n\n            default:\n               png_error(png_ptr,\n                   \"Invalid bit depth for grayscale image\");\n         }\n         break;\n\n      case PNG_COLOR_TYPE_RGB:\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         if (bit_depth != 8 && bit_depth != 16)\n#else\n         if (bit_depth != 8)\n#endif\n            png_error(png_ptr, \"Invalid bit depth for RGB image\");\n\n         png_ptr->channels = 3;\n         break;\n\n      case PNG_COLOR_TYPE_PALETTE:\n         switch (bit_depth)\n         {\n            case 1:\n            case 2:\n            case 4:\n            case 8:\n               png_ptr->channels = 1;\n               break;\n\n            default:\n               png_error(png_ptr, \"Invalid bit depth for paletted image\");\n         }\n         break;\n\n      case PNG_COLOR_TYPE_GRAY_ALPHA:\n         if (bit_depth != 8 && bit_depth != 16)\n            png_error(png_ptr, \"Invalid bit depth for grayscale+alpha image\");\n\n         png_ptr->channels = 2;\n         break;\n\n      case PNG_COLOR_TYPE_RGB_ALPHA:\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n         if (bit_depth != 8 && bit_depth != 16)\n#else\n         if (bit_depth != 8)\n#endif\n            png_error(png_ptr, \"Invalid bit depth for RGBA image\");\n\n         png_ptr->channels = 4;\n         break;\n\n      default:\n         png_error(png_ptr, \"Invalid image color type specified\");\n   }\n\n   if (compression_type != PNG_COMPRESSION_TYPE_BASE)\n   {\n      png_warning(png_ptr, \"Invalid compression type specified\");\n      compression_type = PNG_COMPRESSION_TYPE_BASE;\n   }\n\n   /* Write filter_method 64 (intrapixel differencing) only if\n    * 1. Libpng was compiled with PNG_MNG_FEATURES_SUPPORTED and\n    * 2. Libpng did not write a PNG signature (this filter_method is only\n    *    used in PNG datastreams that are embedded in MNG datastreams) and\n    * 3. The application called png_permit_mng_features with a mask that\n    *    included PNG_FLAG_MNG_FILTER_64 and\n    * 4. The filter_method is 64 and\n    * 5. The color_type is RGB or RGBA\n    */\n   if (\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n       !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) != 0 &&\n       ((png_ptr->mode & PNG_HAVE_PNG_SIGNATURE) == 0) &&\n       (color_type == PNG_COLOR_TYPE_RGB ||\n        color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&\n       (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&\n#endif\n       filter_type != PNG_FILTER_TYPE_BASE)\n   {\n      png_warning(png_ptr, \"Invalid filter type specified\");\n      filter_type = PNG_FILTER_TYPE_BASE;\n   }\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   if (interlace_type != PNG_INTERLACE_NONE &&\n       interlace_type != PNG_INTERLACE_ADAM7)\n   {\n      png_warning(png_ptr, \"Invalid interlace type specified\");\n      interlace_type = PNG_INTERLACE_ADAM7;\n   }\n#else\n   interlace_type=PNG_INTERLACE_NONE;\n#endif\n\n   /* Save the relevant information */\n   png_ptr->bit_depth = (png_byte)bit_depth;\n   png_ptr->color_type = (png_byte)color_type;\n   png_ptr->interlaced = (png_byte)interlace_type;\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n   png_ptr->filter_type = (png_byte)filter_type;\n#endif\n   png_ptr->compression_type = (png_byte)compression_type;\n   png_ptr->width = width;\n   png_ptr->height = height;\n\n   png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);\n   png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);\n   /* Set the usr info, so any transformations can modify it */\n   png_ptr->usr_width = png_ptr->width;\n   png_ptr->usr_bit_depth = png_ptr->bit_depth;\n   png_ptr->usr_channels = png_ptr->channels;\n\n   /* Pack the header information into the buffer */\n   png_save_uint_32(buf, width);\n   png_save_uint_32(buf + 4, height);\n   buf[8] = (png_byte)bit_depth;\n   buf[9] = (png_byte)color_type;\n   buf[10] = (png_byte)compression_type;\n   buf[11] = (png_byte)filter_type;\n   buf[12] = (png_byte)interlace_type;\n\n   /* Write the chunk */\n   png_write_complete_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);\n\n   if ((png_ptr->do_filter) == PNG_NO_FILTERS)\n   {\n      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||\n          png_ptr->bit_depth < 8)\n         png_ptr->do_filter = PNG_FILTER_NONE;\n\n      else\n         png_ptr->do_filter = PNG_ALL_FILTERS;\n   }\n\n   png_ptr->mode = PNG_HAVE_IHDR; /* not READY_FOR_ZTXT */\n}\n\n/* Write the palette.  We are careful not to trust png_color to be in the\n * correct order for PNG, so people can redefine it to any convenient\n * structure.\n */\nvoid /* PRIVATE */\npng_write_PLTE(png_structrp png_ptr, png_const_colorp palette,\n    png_uint_32 num_pal)\n{\n   png_uint_32 max_palette_length, i;\n   png_const_colorp pal_ptr;\n   png_byte buf[3];\n\n   png_debug(1, \"in png_write_PLTE\");\n\n   max_palette_length = (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ?\n      (1 << png_ptr->bit_depth) : PNG_MAX_PALETTE_LENGTH;\n\n   if ((\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n       (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0 &&\n#endif\n       num_pal == 0) || num_pal > max_palette_length)\n   {\n      if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)\n      {\n         png_error(png_ptr, \"Invalid number of colors in palette\");\n      }\n\n      else\n      {\n         png_warning(png_ptr, \"Invalid number of colors in palette\");\n         return;\n      }\n   }\n\n   if ((png_ptr->color_type & PNG_COLOR_MASK_COLOR) == 0)\n   {\n      png_warning(png_ptr,\n          \"Ignoring request to write a PLTE chunk in grayscale PNG\");\n\n      return;\n   }\n\n   png_ptr->num_palette = (png_uint_16)num_pal;\n   png_debug1(3, \"num_palette = %d\", png_ptr->num_palette);\n\n   png_write_chunk_header(png_ptr, png_PLTE, (png_uint_32)(num_pal * 3));\n#ifdef PNG_POINTER_INDEXING_SUPPORTED\n\n   for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)\n   {\n      buf[0] = pal_ptr->red;\n      buf[1] = pal_ptr->green;\n      buf[2] = pal_ptr->blue;\n      png_write_chunk_data(png_ptr, buf, (png_size_t)3);\n   }\n\n#else\n   /* This is a little slower but some buggy compilers need to do this\n    * instead\n    */\n   pal_ptr=palette;\n\n   for (i = 0; i < num_pal; i++)\n   {\n      buf[0] = pal_ptr[i].red;\n      buf[1] = pal_ptr[i].green;\n      buf[2] = pal_ptr[i].blue;\n      png_write_chunk_data(png_ptr, buf, (png_size_t)3);\n   }\n\n#endif\n   png_write_chunk_end(png_ptr);\n   png_ptr->mode |= PNG_HAVE_PLTE;\n}\n\n/* This is similar to png_text_compress, above, except that it does not require\n * all of the data at once and, instead of buffering the compressed result,\n * writes it as IDAT chunks.  Unlike png_text_compress it *can* png_error out\n * because it calls the write interface.  As a result it does its own error\n * reporting and does not return an error code.  In the event of error it will\n * just call png_error.  The input data length may exceed 32-bits.  The 'flush'\n * parameter is exactly the same as that to deflate, with the following\n * meanings:\n *\n * Z_NO_FLUSH: normal incremental output of compressed data\n * Z_SYNC_FLUSH: do a SYNC_FLUSH, used by png_write_flush\n * Z_FINISH: this is the end of the input, do a Z_FINISH and clean up\n *\n * The routine manages the acquire and release of the png_ptr->zstream by\n * checking and (at the end) clearing png_ptr->zowner; it does some sanity\n * checks on the 'mode' flags while doing this.\n */\nvoid /* PRIVATE */\npng_compress_IDAT(png_structrp png_ptr, png_const_bytep input,\n    png_alloc_size_t input_len, int flush)\n{\n   if (png_ptr->zowner != png_IDAT)\n   {\n      /* First time.   Ensure we have a temporary buffer for compression and\n       * trim the buffer list if it has more than one entry to free memory.\n       * If 'WRITE_COMPRESSED_TEXT' is not set the list will never have been\n       * created at this point, but the check here is quick and safe.\n       */\n      if (png_ptr->zbuffer_list == NULL)\n      {\n         png_ptr->zbuffer_list = png_voidcast(png_compression_bufferp,\n             png_malloc(png_ptr, PNG_COMPRESSION_BUFFER_SIZE(png_ptr)));\n         png_ptr->zbuffer_list->next = NULL;\n      }\n\n      else\n         png_free_buffer_list(png_ptr, &png_ptr->zbuffer_list->next);\n\n      /* It is a terminal error if we can't claim the zstream. */\n      if (png_deflate_claim(png_ptr, png_IDAT, png_image_size(png_ptr)) != Z_OK)\n         png_error(png_ptr, png_ptr->zstream.msg);\n\n      /* The output state is maintained in png_ptr->zstream, so it must be\n       * initialized here after the claim.\n       */\n      png_ptr->zstream.next_out = png_ptr->zbuffer_list->output;\n      png_ptr->zstream.avail_out = png_ptr->zbuffer_size;\n   }\n\n   /* Now loop reading and writing until all the input is consumed or an error\n    * terminates the operation.  The _out values are maintained across calls to\n    * this function, but the input must be reset each time.\n    */\n   png_ptr->zstream.next_in = PNGZ_INPUT_CAST(input);\n   png_ptr->zstream.avail_in = 0; /* set below */\n   for (;;)\n   {\n      int ret;\n\n      /* INPUT: from the row data */\n      uInt avail = ZLIB_IO_MAX;\n\n      if (avail > input_len)\n         avail = (uInt)input_len; /* safe because of the check */\n\n      png_ptr->zstream.avail_in = avail;\n      input_len -= avail;\n\n      ret = deflate(&png_ptr->zstream, input_len > 0 ? Z_NO_FLUSH : flush);\n\n      /* Include as-yet unconsumed input */\n      input_len += png_ptr->zstream.avail_in;\n      png_ptr->zstream.avail_in = 0;\n\n      /* OUTPUT: write complete IDAT chunks when avail_out drops to zero. Note\n       * that these two zstream fields are preserved across the calls, therefore\n       * there is no need to set these up on entry to the loop.\n       */\n      if (png_ptr->zstream.avail_out == 0)\n      {\n         png_bytep data = png_ptr->zbuffer_list->output;\n         uInt size = png_ptr->zbuffer_size;\n\n         /* Write an IDAT containing the data then reset the buffer.  The\n          * first IDAT may need deflate header optimization.\n          */\n#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n            if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 &&\n                png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)\n               optimize_cmf(data, png_image_size(png_ptr));\n#endif\n\n         png_write_complete_chunk(png_ptr, png_IDAT, data, size);\n         png_ptr->mode |= PNG_HAVE_IDAT;\n\n         png_ptr->zstream.next_out = data;\n         png_ptr->zstream.avail_out = size;\n\n         /* For SYNC_FLUSH or FINISH it is essential to keep calling zlib with\n          * the same flush parameter until it has finished output, for NO_FLUSH\n          * it doesn't matter.\n          */\n         if (ret == Z_OK && flush != Z_NO_FLUSH)\n            continue;\n      }\n\n      /* The order of these checks doesn't matter much; it just affects which\n       * possible error might be detected if multiple things go wrong at once.\n       */\n      if (ret == Z_OK) /* most likely return code! */\n      {\n         /* If all the input has been consumed then just return.  If Z_FINISH\n          * was used as the flush parameter something has gone wrong if we get\n          * here.\n          */\n         if (input_len == 0)\n         {\n            if (flush == Z_FINISH)\n               png_error(png_ptr, \"Z_OK on Z_FINISH with output space\");\n\n            return;\n         }\n      }\n\n      else if (ret == Z_STREAM_END && flush == Z_FINISH)\n      {\n         /* This is the end of the IDAT data; any pending output must be\n          * flushed.  For small PNG files we may still be at the beginning.\n          */\n         png_bytep data = png_ptr->zbuffer_list->output;\n         uInt size = png_ptr->zbuffer_size - png_ptr->zstream.avail_out;\n\n#ifdef PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n         if ((png_ptr->mode & PNG_HAVE_IDAT) == 0 &&\n             png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)\n            optimize_cmf(data, png_image_size(png_ptr));\n#endif\n\n         png_write_complete_chunk(png_ptr, png_IDAT, data, size);\n         png_ptr->zstream.avail_out = 0;\n         png_ptr->zstream.next_out = NULL;\n         png_ptr->mode |= PNG_HAVE_IDAT | PNG_AFTER_IDAT;\n\n         png_ptr->zowner = 0; /* Release the stream */\n         return;\n      }\n\n      else\n      {\n         /* This is an error condition. */\n         png_zstream_error(png_ptr, ret);\n         png_error(png_ptr, png_ptr->zstream.msg);\n      }\n   }\n}\n\n/* Write an IEND chunk */\nvoid /* PRIVATE */\npng_write_IEND(png_structrp png_ptr)\n{\n   png_debug(1, \"in png_write_IEND\");\n\n   png_write_complete_chunk(png_ptr, png_IEND, NULL, (png_size_t)0);\n   png_ptr->mode |= PNG_HAVE_IEND;\n}\n\n#ifdef PNG_WRITE_gAMA_SUPPORTED\n/* Write a gAMA chunk */\nvoid /* PRIVATE */\npng_write_gAMA_fixed(png_structrp png_ptr, png_fixed_point file_gamma)\n{\n   png_byte buf[4];\n\n   png_debug(1, \"in png_write_gAMA\");\n\n   /* file_gamma is saved in 1/100,000ths */\n   png_save_uint_32(buf, (png_uint_32)file_gamma);\n   png_write_complete_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);\n}\n#endif\n\n#ifdef PNG_WRITE_sRGB_SUPPORTED\n/* Write a sRGB chunk */\nvoid /* PRIVATE */\npng_write_sRGB(png_structrp png_ptr, int srgb_intent)\n{\n   png_byte buf[1];\n\n   png_debug(1, \"in png_write_sRGB\");\n\n   if (srgb_intent >= PNG_sRGB_INTENT_LAST)\n      png_warning(png_ptr,\n          \"Invalid sRGB rendering intent specified\");\n\n   buf[0]=(png_byte)srgb_intent;\n   png_write_complete_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);\n}\n#endif\n\n#ifdef PNG_WRITE_iCCP_SUPPORTED\n/* Write an iCCP chunk */\nvoid /* PRIVATE */\npng_write_iCCP(png_structrp png_ptr, png_const_charp name,\n    png_const_bytep profile)\n{\n   png_uint_32 name_len;\n   png_uint_32 profile_len;\n   png_byte new_name[81]; /* 1 byte for the compression byte */\n   compression_state comp;\n   png_uint_32 temp;\n\n   png_debug(1, \"in png_write_iCCP\");\n\n   /* These are all internal problems: the profile should have been checked\n    * before when it was stored.\n    */\n   if (profile == NULL)\n      png_error(png_ptr, \"No profile for iCCP chunk\"); /* internal error */\n\n   profile_len = png_get_uint_32(profile);\n\n   if (profile_len < 132)\n      png_error(png_ptr, \"ICC profile too short\");\n\n   temp = (png_uint_32) (*(profile+8));\n   if (temp > 3 && (profile_len & 0x03))\n      png_error(png_ptr, \"ICC profile length invalid (not a multiple of 4)\");\n\n   {\n      png_uint_32 embedded_profile_len = png_get_uint_32(profile);\n\n      if (profile_len != embedded_profile_len)\n         png_error(png_ptr, \"Profile length does not match profile\");\n   }\n\n   name_len = png_check_keyword(png_ptr, name, new_name);\n\n   if (name_len == 0)\n      png_error(png_ptr, \"iCCP: invalid keyword\");\n\n   new_name[++name_len] = PNG_COMPRESSION_TYPE_BASE;\n\n   /* Make sure we include the NULL after the name and the compression type */\n   ++name_len;\n\n   png_text_compress_init(&comp, profile, profile_len);\n\n   /* Allow for keyword terminator and compression byte */\n   if (png_text_compress(png_ptr, png_iCCP, &comp, name_len) != Z_OK)\n      png_error(png_ptr, png_ptr->zstream.msg);\n\n   png_write_chunk_header(png_ptr, png_iCCP, name_len + comp.output_len);\n\n   png_write_chunk_data(png_ptr, new_name, name_len);\n\n   png_write_compressed_data_out(png_ptr, &comp);\n\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_sPLT_SUPPORTED\n/* Write a sPLT chunk */\nvoid /* PRIVATE */\npng_write_sPLT(png_structrp png_ptr, png_const_sPLT_tp spalette)\n{\n   png_uint_32 name_len;\n   png_byte new_name[80];\n   png_byte entrybuf[10];\n   png_size_t entry_size = (spalette->depth == 8 ? 6 : 10);\n   png_size_t palette_size = entry_size * spalette->nentries;\n   png_sPLT_entryp ep;\n#ifndef PNG_POINTER_INDEXING_SUPPORTED\n   int i;\n#endif\n\n   png_debug(1, \"in png_write_sPLT\");\n\n   name_len = png_check_keyword(png_ptr, spalette->name, new_name);\n\n   if (name_len == 0)\n      png_error(png_ptr, \"sPLT: invalid keyword\");\n\n   /* Make sure we include the NULL after the name */\n   png_write_chunk_header(png_ptr, png_sPLT,\n       (png_uint_32)(name_len + 2 + palette_size));\n\n   png_write_chunk_data(png_ptr, (png_bytep)new_name,\n       (png_size_t)(name_len + 1));\n\n   png_write_chunk_data(png_ptr, &spalette->depth, (png_size_t)1);\n\n   /* Loop through each palette entry, writing appropriately */\n#ifdef PNG_POINTER_INDEXING_SUPPORTED\n   for (ep = spalette->entries; ep<spalette->entries + spalette->nentries; ep++)\n   {\n      if (spalette->depth == 8)\n      {\n         entrybuf[0] = (png_byte)ep->red;\n         entrybuf[1] = (png_byte)ep->green;\n         entrybuf[2] = (png_byte)ep->blue;\n         entrybuf[3] = (png_byte)ep->alpha;\n         png_save_uint_16(entrybuf + 4, ep->frequency);\n      }\n\n      else\n      {\n         png_save_uint_16(entrybuf + 0, ep->red);\n         png_save_uint_16(entrybuf + 2, ep->green);\n         png_save_uint_16(entrybuf + 4, ep->blue);\n         png_save_uint_16(entrybuf + 6, ep->alpha);\n         png_save_uint_16(entrybuf + 8, ep->frequency);\n      }\n\n      png_write_chunk_data(png_ptr, entrybuf, entry_size);\n   }\n#else\n   ep=spalette->entries;\n   for (i = 0; i>spalette->nentries; i++)\n   {\n      if (spalette->depth == 8)\n      {\n         entrybuf[0] = (png_byte)ep[i].red;\n         entrybuf[1] = (png_byte)ep[i].green;\n         entrybuf[2] = (png_byte)ep[i].blue;\n         entrybuf[3] = (png_byte)ep[i].alpha;\n         png_save_uint_16(entrybuf + 4, ep[i].frequency);\n      }\n\n      else\n      {\n         png_save_uint_16(entrybuf + 0, ep[i].red);\n         png_save_uint_16(entrybuf + 2, ep[i].green);\n         png_save_uint_16(entrybuf + 4, ep[i].blue);\n         png_save_uint_16(entrybuf + 6, ep[i].alpha);\n         png_save_uint_16(entrybuf + 8, ep[i].frequency);\n      }\n\n      png_write_chunk_data(png_ptr, entrybuf, entry_size);\n   }\n#endif\n\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_sBIT_SUPPORTED\n/* Write the sBIT chunk */\nvoid /* PRIVATE */\npng_write_sBIT(png_structrp png_ptr, png_const_color_8p sbit, int color_type)\n{\n   png_byte buf[4];\n   png_size_t size;\n\n   png_debug(1, \"in png_write_sBIT\");\n\n   /* Make sure we don't depend upon the order of PNG_COLOR_8 */\n   if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      png_byte maxbits;\n\n      maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :\n          png_ptr->usr_bit_depth);\n\n      if (sbit->red == 0 || sbit->red > maxbits ||\n          sbit->green == 0 || sbit->green > maxbits ||\n          sbit->blue == 0 || sbit->blue > maxbits)\n      {\n         png_warning(png_ptr, \"Invalid sBIT depth specified\");\n         return;\n      }\n\n      buf[0] = sbit->red;\n      buf[1] = sbit->green;\n      buf[2] = sbit->blue;\n      size = 3;\n   }\n\n   else\n   {\n      if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)\n      {\n         png_warning(png_ptr, \"Invalid sBIT depth specified\");\n         return;\n      }\n\n      buf[0] = sbit->gray;\n      size = 1;\n   }\n\n   if ((color_type & PNG_COLOR_MASK_ALPHA) != 0)\n   {\n      if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)\n      {\n         png_warning(png_ptr, \"Invalid sBIT depth specified\");\n         return;\n      }\n\n      buf[size++] = sbit->alpha;\n   }\n\n   png_write_complete_chunk(png_ptr, png_sBIT, buf, size);\n}\n#endif\n\n#ifdef PNG_WRITE_cHRM_SUPPORTED\n/* Write the cHRM chunk */\nvoid /* PRIVATE */\npng_write_cHRM_fixed(png_structrp png_ptr, const png_xy *xy)\n{\n   png_byte buf[32];\n\n   png_debug(1, \"in png_write_cHRM\");\n\n   /* Each value is saved in 1/100,000ths */\n   png_save_int_32(buf,      xy->whitex);\n   png_save_int_32(buf +  4, xy->whitey);\n\n   png_save_int_32(buf +  8, xy->redx);\n   png_save_int_32(buf + 12, xy->redy);\n\n   png_save_int_32(buf + 16, xy->greenx);\n   png_save_int_32(buf + 20, xy->greeny);\n\n   png_save_int_32(buf + 24, xy->bluex);\n   png_save_int_32(buf + 28, xy->bluey);\n\n   png_write_complete_chunk(png_ptr, png_cHRM, buf, 32);\n}\n#endif\n\n#ifdef PNG_WRITE_tRNS_SUPPORTED\n/* Write the tRNS chunk */\nvoid /* PRIVATE */\npng_write_tRNS(png_structrp png_ptr, png_const_bytep trans_alpha,\n    png_const_color_16p tran, int num_trans, int color_type)\n{\n   png_byte buf[6];\n\n   png_debug(1, \"in png_write_tRNS\");\n\n   if (color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)\n      {\n         png_app_warning(png_ptr,\n             \"Invalid number of transparent colors specified\");\n         return;\n      }\n\n      /* Write the chunk out as it is */\n      png_write_complete_chunk(png_ptr, png_tRNS, trans_alpha,\n          (png_size_t)num_trans);\n   }\n\n   else if (color_type == PNG_COLOR_TYPE_GRAY)\n   {\n      /* One 16-bit value */\n      if (tran->gray >= (1 << png_ptr->bit_depth))\n      {\n         png_app_warning(png_ptr,\n             \"Ignoring attempt to write tRNS chunk out-of-range for bit_depth\");\n\n         return;\n      }\n\n      png_save_uint_16(buf, tran->gray);\n      png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);\n   }\n\n   else if (color_type == PNG_COLOR_TYPE_RGB)\n   {\n      /* Three 16-bit values */\n      png_save_uint_16(buf, tran->red);\n      png_save_uint_16(buf + 2, tran->green);\n      png_save_uint_16(buf + 4, tran->blue);\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0)\n#else\n      if ((buf[0] | buf[2] | buf[4]) != 0)\n#endif\n      {\n         png_app_warning(png_ptr,\n             \"Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8\");\n         return;\n      }\n\n      png_write_complete_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);\n   }\n\n   else\n   {\n      png_app_warning(png_ptr, \"Can't write tRNS with an alpha channel\");\n   }\n}\n#endif\n\n#ifdef PNG_WRITE_bKGD_SUPPORTED\n/* Write the background chunk */\nvoid /* PRIVATE */\npng_write_bKGD(png_structrp png_ptr, png_const_color_16p back, int color_type)\n{\n   png_byte buf[6];\n\n   png_debug(1, \"in png_write_bKGD\");\n\n   if (color_type == PNG_COLOR_TYPE_PALETTE)\n   {\n      if (\n#ifdef PNG_MNG_FEATURES_SUPPORTED\n          (png_ptr->num_palette != 0 ||\n          (png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) == 0) &&\n#endif\n         back->index >= png_ptr->num_palette)\n      {\n         png_warning(png_ptr, \"Invalid background palette index\");\n         return;\n      }\n\n      buf[0] = back->index;\n      png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);\n   }\n\n   else if ((color_type & PNG_COLOR_MASK_COLOR) != 0)\n   {\n      png_save_uint_16(buf, back->red);\n      png_save_uint_16(buf + 2, back->green);\n      png_save_uint_16(buf + 4, back->blue);\n#ifdef PNG_WRITE_16BIT_SUPPORTED\n      if (png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]) != 0)\n#else\n      if ((buf[0] | buf[2] | buf[4]) != 0)\n#endif\n      {\n         png_warning(png_ptr,\n             \"Ignoring attempt to write 16-bit bKGD chunk \"\n             \"when bit_depth is 8\");\n\n         return;\n      }\n\n      png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);\n   }\n\n   else\n   {\n      if (back->gray >= (1 << png_ptr->bit_depth))\n      {\n         png_warning(png_ptr,\n             \"Ignoring attempt to write bKGD chunk out-of-range for bit_depth\");\n\n         return;\n      }\n\n      png_save_uint_16(buf, back->gray);\n      png_write_complete_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);\n   }\n}\n#endif\n\n#ifdef PNG_WRITE_hIST_SUPPORTED\n/* Write the histogram */\nvoid /* PRIVATE */\npng_write_hIST(png_structrp png_ptr, png_const_uint_16p hist, int num_hist)\n{\n   int i;\n   png_byte buf[3];\n\n   png_debug(1, \"in png_write_hIST\");\n\n   if (num_hist > (int)png_ptr->num_palette)\n   {\n      png_debug2(3, \"num_hist = %d, num_palette = %d\", num_hist,\n          png_ptr->num_palette);\n\n      png_warning(png_ptr, \"Invalid number of histogram entries specified\");\n      return;\n   }\n\n   png_write_chunk_header(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));\n\n   for (i = 0; i < num_hist; i++)\n   {\n      png_save_uint_16(buf, hist[i]);\n      png_write_chunk_data(png_ptr, buf, (png_size_t)2);\n   }\n\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_tEXt_SUPPORTED\n/* Write a tEXt chunk */\nvoid /* PRIVATE */\npng_write_tEXt(png_structrp png_ptr, png_const_charp key, png_const_charp text,\n    png_size_t text_len)\n{\n   png_uint_32 key_len;\n   png_byte new_key[80];\n\n   png_debug(1, \"in png_write_tEXt\");\n\n   key_len = png_check_keyword(png_ptr, key, new_key);\n\n   if (key_len == 0)\n      png_error(png_ptr, \"tEXt: invalid keyword\");\n\n   if (text == NULL || *text == '\\0')\n      text_len = 0;\n\n   else\n      text_len = strlen(text);\n\n   if (text_len > PNG_UINT_31_MAX - (key_len+1))\n      png_error(png_ptr, \"tEXt: text too long\");\n\n   /* Make sure we include the 0 after the key */\n   png_write_chunk_header(png_ptr, png_tEXt,\n       (png_uint_32)/*checked above*/(key_len + text_len + 1));\n   /*\n    * We leave it to the application to meet PNG-1.0 requirements on the\n    * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of\n    * any non-Latin-1 characters except for NEWLINE.  ISO PNG will forbid them.\n    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.\n    */\n   png_write_chunk_data(png_ptr, new_key, key_len + 1);\n\n   if (text_len != 0)\n      png_write_chunk_data(png_ptr, (png_const_bytep)text, text_len);\n\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_zTXt_SUPPORTED\n/* Write a compressed text chunk */\nvoid /* PRIVATE */\npng_write_zTXt(png_structrp png_ptr, png_const_charp key, png_const_charp text,\n    int compression)\n{\n   png_uint_32 key_len;\n   png_byte new_key[81];\n   compression_state comp;\n\n   png_debug(1, \"in png_write_zTXt\");\n\n   if (compression == PNG_TEXT_COMPRESSION_NONE)\n   {\n      png_write_tEXt(png_ptr, key, text, 0);\n      return;\n   }\n\n   if (compression != PNG_TEXT_COMPRESSION_zTXt)\n      png_error(png_ptr, \"zTXt: invalid compression type\");\n\n   key_len = png_check_keyword(png_ptr, key, new_key);\n\n   if (key_len == 0)\n      png_error(png_ptr, \"zTXt: invalid keyword\");\n\n   /* Add the compression method and 1 for the keyword separator. */\n   new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE;\n   ++key_len;\n\n   /* Compute the compressed data; do it now for the length */\n   png_text_compress_init(&comp, (png_const_bytep)text,\n       text == NULL ? 0 : strlen(text));\n\n   if (png_text_compress(png_ptr, png_zTXt, &comp, key_len) != Z_OK)\n      png_error(png_ptr, png_ptr->zstream.msg);\n\n   /* Write start of chunk */\n   png_write_chunk_header(png_ptr, png_zTXt, key_len + comp.output_len);\n\n   /* Write key */\n   png_write_chunk_data(png_ptr, new_key, key_len);\n\n   /* Write the compressed data */\n   png_write_compressed_data_out(png_ptr, &comp);\n\n   /* Close the chunk */\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_iTXt_SUPPORTED\n/* Write an iTXt chunk */\nvoid /* PRIVATE */\npng_write_iTXt(png_structrp png_ptr, int compression, png_const_charp key,\n    png_const_charp lang, png_const_charp lang_key, png_const_charp text)\n{\n   png_uint_32 key_len, prefix_len;\n   png_size_t lang_len, lang_key_len;\n   png_byte new_key[82];\n   compression_state comp;\n\n   png_debug(1, \"in png_write_iTXt\");\n\n   key_len = png_check_keyword(png_ptr, key, new_key);\n\n   if (key_len == 0)\n      png_error(png_ptr, \"iTXt: invalid keyword\");\n\n   /* Set the compression flag */\n   switch (compression)\n   {\n      case PNG_ITXT_COMPRESSION_NONE:\n      case PNG_TEXT_COMPRESSION_NONE:\n         compression = new_key[++key_len] = 0; /* no compression */\n         break;\n\n      case PNG_TEXT_COMPRESSION_zTXt:\n      case PNG_ITXT_COMPRESSION_zTXt:\n         compression = new_key[++key_len] = 1; /* compressed */\n         break;\n\n      default:\n         png_error(png_ptr, \"iTXt: invalid compression\");\n   }\n\n   new_key[++key_len] = PNG_COMPRESSION_TYPE_BASE;\n   ++key_len; /* for the keywod separator */\n\n   /* We leave it to the application to meet PNG-1.0 requirements on the\n    * contents of the text.  PNG-1.0 through PNG-1.2 discourage the use of\n    * any non-Latin-1 characters except for NEWLINE.  ISO PNG, however,\n    * specifies that the text is UTF-8 and this really doesn't require any\n    * checking.\n    *\n    * The NUL character is forbidden by PNG-1.0 through PNG-1.2 and ISO PNG.\n    *\n    * TODO: validate the language tag correctly (see the spec.)\n    */\n   if (lang == NULL) lang = \"\"; /* empty language is valid */\n   lang_len = strlen(lang)+1;\n   if (lang_key == NULL) lang_key = \"\"; /* may be empty */\n   lang_key_len = strlen(lang_key)+1;\n   if (text == NULL) text = \"\"; /* may be empty */\n\n   prefix_len = key_len;\n   if (lang_len > PNG_UINT_31_MAX-prefix_len)\n      prefix_len = PNG_UINT_31_MAX;\n   else\n      prefix_len = (png_uint_32)(prefix_len + lang_len);\n\n   if (lang_key_len > PNG_UINT_31_MAX-prefix_len)\n      prefix_len = PNG_UINT_31_MAX;\n   else\n      prefix_len = (png_uint_32)(prefix_len + lang_key_len);\n\n   png_text_compress_init(&comp, (png_const_bytep)text, strlen(text));\n\n   if (compression != 0)\n   {\n      if (png_text_compress(png_ptr, png_iTXt, &comp, prefix_len) != Z_OK)\n         png_error(png_ptr, png_ptr->zstream.msg);\n   }\n\n   else\n   {\n      if (comp.input_len > PNG_UINT_31_MAX-prefix_len)\n         png_error(png_ptr, \"iTXt: uncompressed text too long\");\n\n      /* So the string will fit in a chunk: */\n      comp.output_len = (png_uint_32)/*SAFE*/comp.input_len;\n   }\n\n   png_write_chunk_header(png_ptr, png_iTXt, comp.output_len + prefix_len);\n\n   png_write_chunk_data(png_ptr, new_key, key_len);\n\n   png_write_chunk_data(png_ptr, (png_const_bytep)lang, lang_len);\n\n   png_write_chunk_data(png_ptr, (png_const_bytep)lang_key, lang_key_len);\n\n   if (compression != 0)\n      png_write_compressed_data_out(png_ptr, &comp);\n\n   else\n      png_write_chunk_data(png_ptr, (png_const_bytep)text, comp.output_len);\n\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_oFFs_SUPPORTED\n/* Write the oFFs chunk */\nvoid /* PRIVATE */\npng_write_oFFs(png_structrp png_ptr, png_int_32 x_offset, png_int_32 y_offset,\n    int unit_type)\n{\n   png_byte buf[9];\n\n   png_debug(1, \"in png_write_oFFs\");\n\n   if (unit_type >= PNG_OFFSET_LAST)\n      png_warning(png_ptr, \"Unrecognized unit type for oFFs chunk\");\n\n   png_save_int_32(buf, x_offset);\n   png_save_int_32(buf + 4, y_offset);\n   buf[8] = (png_byte)unit_type;\n\n   png_write_complete_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);\n}\n#endif\n#ifdef PNG_WRITE_pCAL_SUPPORTED\n/* Write the pCAL chunk (described in the PNG extensions document) */\nvoid /* PRIVATE */\npng_write_pCAL(png_structrp png_ptr, png_charp purpose, png_int_32 X0,\n    png_int_32 X1, int type, int nparams, png_const_charp units,\n    png_charpp params)\n{\n   png_uint_32 purpose_len;\n   png_size_t units_len, total_len;\n   png_size_tp params_len;\n   png_byte buf[10];\n   png_byte new_purpose[80];\n   int i;\n\n   png_debug1(1, \"in png_write_pCAL (%d parameters)\", nparams);\n\n   if (type >= PNG_EQUATION_LAST)\n      png_error(png_ptr, \"Unrecognized equation type for pCAL chunk\");\n\n   purpose_len = png_check_keyword(png_ptr, purpose, new_purpose);\n\n   if (purpose_len == 0)\n      png_error(png_ptr, \"pCAL: invalid keyword\");\n\n   ++purpose_len; /* terminator */\n\n   png_debug1(3, \"pCAL purpose length = %d\", (int)purpose_len);\n   units_len = strlen(units) + (nparams == 0 ? 0 : 1);\n   png_debug1(3, \"pCAL units length = %d\", (int)units_len);\n   total_len = purpose_len + units_len + 10;\n\n   params_len = (png_size_tp)png_malloc(png_ptr,\n       (png_alloc_size_t)(nparams * (sizeof (png_size_t))));\n\n   /* Find the length of each parameter, making sure we don't count the\n    * null terminator for the last parameter.\n    */\n   for (i = 0; i < nparams; i++)\n   {\n      params_len[i] = strlen(params[i]) + (i == nparams - 1 ? 0 : 1);\n      png_debug2(3, \"pCAL parameter %d length = %lu\", i,\n          (unsigned long)params_len[i]);\n      total_len += params_len[i];\n   }\n\n   png_debug1(3, \"pCAL total length = %d\", (int)total_len);\n   png_write_chunk_header(png_ptr, png_pCAL, (png_uint_32)total_len);\n   png_write_chunk_data(png_ptr, new_purpose, purpose_len);\n   png_save_int_32(buf, X0);\n   png_save_int_32(buf + 4, X1);\n   buf[8] = (png_byte)type;\n   buf[9] = (png_byte)nparams;\n   png_write_chunk_data(png_ptr, buf, (png_size_t)10);\n   png_write_chunk_data(png_ptr, (png_const_bytep)units, (png_size_t)units_len);\n\n   for (i = 0; i < nparams; i++)\n   {\n      png_write_chunk_data(png_ptr, (png_const_bytep)params[i], params_len[i]);\n   }\n\n   png_free(png_ptr, params_len);\n   png_write_chunk_end(png_ptr);\n}\n#endif\n\n#ifdef PNG_WRITE_sCAL_SUPPORTED\n/* Write the sCAL chunk */\nvoid /* PRIVATE */\npng_write_sCAL_s(png_structrp png_ptr, int unit, png_const_charp width,\n    png_const_charp height)\n{\n   png_byte buf[64];\n   png_size_t wlen, hlen, total_len;\n\n   png_debug(1, \"in png_write_sCAL_s\");\n\n   wlen = strlen(width);\n   hlen = strlen(height);\n   total_len = wlen + hlen + 2;\n\n   if (total_len > 64)\n   {\n      png_warning(png_ptr, \"Can't write sCAL (buffer too small)\");\n      return;\n   }\n\n   buf[0] = (png_byte)unit;\n   memcpy(buf + 1, width, wlen + 1);      /* Append the '\\0' here */\n   memcpy(buf + wlen + 2, height, hlen);  /* Do NOT append the '\\0' here */\n\n   png_debug1(3, \"sCAL total length = %u\", (unsigned int)total_len);\n   png_write_complete_chunk(png_ptr, png_sCAL, buf, total_len);\n}\n#endif\n\n#ifdef PNG_WRITE_pHYs_SUPPORTED\n/* Write the pHYs chunk */\nvoid /* PRIVATE */\npng_write_pHYs(png_structrp png_ptr, png_uint_32 x_pixels_per_unit,\n    png_uint_32 y_pixels_per_unit,\n    int unit_type)\n{\n   png_byte buf[9];\n\n   png_debug(1, \"in png_write_pHYs\");\n\n   if (unit_type >= PNG_RESOLUTION_LAST)\n      png_warning(png_ptr, \"Unrecognized unit type for pHYs chunk\");\n\n   png_save_uint_32(buf, x_pixels_per_unit);\n   png_save_uint_32(buf + 4, y_pixels_per_unit);\n   buf[8] = (png_byte)unit_type;\n\n   png_write_complete_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);\n}\n#endif\n\n#ifdef PNG_WRITE_tIME_SUPPORTED\n/* Write the tIME chunk.  Use either png_convert_from_struct_tm()\n * or png_convert_from_time_t(), or fill in the structure yourself.\n */\nvoid /* PRIVATE */\npng_write_tIME(png_structrp png_ptr, png_const_timep mod_time)\n{\n   png_byte buf[7];\n\n   png_debug(1, \"in png_write_tIME\");\n\n   if (mod_time->month  > 12 || mod_time->month  < 1 ||\n       mod_time->day    > 31 || mod_time->day    < 1 ||\n       mod_time->hour   > 23 || mod_time->second > 60)\n   {\n      png_warning(png_ptr, \"Invalid time specified for tIME chunk\");\n      return;\n   }\n\n   png_save_uint_16(buf, mod_time->year);\n   buf[2] = mod_time->month;\n   buf[3] = mod_time->day;\n   buf[4] = mod_time->hour;\n   buf[5] = mod_time->minute;\n   buf[6] = mod_time->second;\n\n   png_write_complete_chunk(png_ptr, png_tIME, buf, (png_size_t)7);\n}\n#endif\n\n/* Initializes the row writing capability of libpng */\nvoid /* PRIVATE */\npng_write_start_row(png_structrp png_ptr)\n{\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   /* Start of interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\n\n   /* Offset to next interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\n#endif\n\n   png_alloc_size_t buf_size;\n   int usr_pixel_depth;\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   png_byte filters;\n#endif\n\n   png_debug(1, \"in png_write_start_row\");\n\n   usr_pixel_depth = png_ptr->usr_channels * png_ptr->usr_bit_depth;\n   buf_size = PNG_ROWBYTES(usr_pixel_depth, png_ptr->width) + 1;\n\n   /* 1.5.6: added to allow checking in the row write code. */\n   png_ptr->transformed_pixel_depth = png_ptr->pixel_depth;\n   png_ptr->maximum_pixel_depth = (png_byte)usr_pixel_depth;\n\n   /* Set up row buffer */\n   png_ptr->row_buf = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));\n\n   png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   filters = png_ptr->do_filter;\n\n   if (png_ptr->height == 1)\n      filters &= 0xff & ~(PNG_FILTER_UP|PNG_FILTER_AVG|PNG_FILTER_PAETH);\n\n   if (png_ptr->width == 1)\n      filters &= 0xff & ~(PNG_FILTER_SUB|PNG_FILTER_AVG|PNG_FILTER_PAETH);\n\n   if (filters == 0)\n      filters = PNG_FILTER_NONE;\n\n   png_ptr->do_filter = filters;\n\n   if (((filters & (PNG_FILTER_SUB | PNG_FILTER_UP | PNG_FILTER_AVG |\n       PNG_FILTER_PAETH)) != 0) && png_ptr->try_row == NULL)\n   {\n      int num_filters = 0;\n\n      png_ptr->try_row = png_voidcast(png_bytep, png_malloc(png_ptr, buf_size));\n\n      if (filters & PNG_FILTER_SUB)\n         num_filters++;\n\n      if (filters & PNG_FILTER_UP)\n         num_filters++;\n\n      if (filters & PNG_FILTER_AVG)\n         num_filters++;\n\n      if (filters & PNG_FILTER_PAETH)\n         num_filters++;\n\n      if (num_filters > 1)\n         png_ptr->tst_row = png_voidcast(png_bytep, png_malloc(png_ptr,\n             buf_size));\n   }\n\n   /* We only need to keep the previous row if we are using one of the following\n    * filters.\n    */\n   if ((filters & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH)) != 0)\n      png_ptr->prev_row = png_voidcast(png_bytep,\n          png_calloc(png_ptr, buf_size));\n#endif /* WRITE_FILTER */\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* If interlaced, we need to set up width and height of pass */\n   if (png_ptr->interlaced != 0)\n   {\n      if ((png_ptr->transformations & PNG_INTERLACE) == 0)\n      {\n         png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -\n             png_pass_ystart[0]) / png_pass_yinc[0];\n\n         png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -\n             png_pass_start[0]) / png_pass_inc[0];\n      }\n\n      else\n      {\n         png_ptr->num_rows = png_ptr->height;\n         png_ptr->usr_width = png_ptr->width;\n      }\n   }\n\n   else\n#endif\n   {\n      png_ptr->num_rows = png_ptr->height;\n      png_ptr->usr_width = png_ptr->width;\n   }\n}\n\n/* Internal use only.  Called when finished processing a row of data. */\nvoid /* PRIVATE */\npng_write_finish_row(png_structrp png_ptr)\n{\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   /* Start of interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};\n\n   /* Offset to next interlace block in the y direction */\n   static PNG_CONST png_byte png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};\n#endif\n\n   png_debug(1, \"in png_write_finish_row\");\n\n   /* Next row */\n   png_ptr->row_number++;\n\n   /* See if we are done */\n   if (png_ptr->row_number < png_ptr->num_rows)\n      return;\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n   /* If interlaced, go to next pass */\n   if (png_ptr->interlaced != 0)\n   {\n      png_ptr->row_number = 0;\n      if ((png_ptr->transformations & PNG_INTERLACE) != 0)\n      {\n         png_ptr->pass++;\n      }\n\n      else\n      {\n         /* Loop until we find a non-zero width or height pass */\n         do\n         {\n            png_ptr->pass++;\n\n            if (png_ptr->pass >= 7)\n               break;\n\n            png_ptr->usr_width = (png_ptr->width +\n                png_pass_inc[png_ptr->pass] - 1 -\n                png_pass_start[png_ptr->pass]) /\n                png_pass_inc[png_ptr->pass];\n\n            png_ptr->num_rows = (png_ptr->height +\n                png_pass_yinc[png_ptr->pass] - 1 -\n                png_pass_ystart[png_ptr->pass]) /\n                png_pass_yinc[png_ptr->pass];\n\n            if ((png_ptr->transformations & PNG_INTERLACE) != 0)\n               break;\n\n         } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);\n\n      }\n\n      /* Reset the row above the image for the next pass */\n      if (png_ptr->pass < 7)\n      {\n         if (png_ptr->prev_row != NULL)\n            memset(png_ptr->prev_row, 0,\n                (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*\n                png_ptr->usr_bit_depth, png_ptr->width)) + 1);\n\n         return;\n      }\n   }\n#endif\n\n   /* If we get here, we've just written the last row, so we need\n      to flush the compressor */\n   png_compress_IDAT(png_ptr, NULL, 0, Z_FINISH);\n}\n\n#ifdef PNG_WRITE_INTERLACING_SUPPORTED\n/* Pick out the correct pixels for the interlace pass.\n * The basic idea here is to go through the row with a source\n * pointer and a destination pointer (sp and dp), and copy the\n * correct pixels for the pass.  As the row gets compacted,\n * sp will always be >= dp, so we should never overwrite anything.\n * See the default: case for the easiest code to understand.\n */\nvoid /* PRIVATE */\npng_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)\n{\n   /* Arrays to facilitate easy interlacing - use pass (0 - 6) as index */\n\n   /* Start of interlace block */\n   static PNG_CONST png_byte png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};\n\n   /* Offset to next interlace block */\n   static PNG_CONST png_byte  png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};\n\n   png_debug(1, \"in png_do_write_interlace\");\n\n   /* We don't have to do anything on the last pass (6) */\n   if (pass < 6)\n   {\n      /* Each pixel depth is handled separately */\n      switch (row_info->pixel_depth)\n      {\n         case 1:\n         {\n            png_bytep sp;\n            png_bytep dp;\n            unsigned int shift;\n            int d;\n            int value;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            dp = row;\n            d = 0;\n            shift = 7;\n\n            for (i = png_pass_start[pass]; i < row_width;\n               i += png_pass_inc[pass])\n            {\n               sp = row + (png_size_t)(i >> 3);\n               value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;\n               d |= (value << shift);\n\n               if (shift == 0)\n               {\n                  shift = 7;\n                  *dp++ = (png_byte)d;\n                  d = 0;\n               }\n\n               else\n                  shift--;\n\n            }\n            if (shift != 7)\n               *dp = (png_byte)d;\n\n            break;\n         }\n\n         case 2:\n         {\n            png_bytep sp;\n            png_bytep dp;\n            unsigned int shift;\n            int d;\n            int value;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            dp = row;\n            shift = 6;\n            d = 0;\n\n            for (i = png_pass_start[pass]; i < row_width;\n               i += png_pass_inc[pass])\n            {\n               sp = row + (png_size_t)(i >> 2);\n               value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;\n               d |= (value << shift);\n\n               if (shift == 0)\n               {\n                  shift = 6;\n                  *dp++ = (png_byte)d;\n                  d = 0;\n               }\n\n               else\n                  shift -= 2;\n            }\n            if (shift != 6)\n               *dp = (png_byte)d;\n\n            break;\n         }\n\n         case 4:\n         {\n            png_bytep sp;\n            png_bytep dp;\n            unsigned int shift;\n            int d;\n            int value;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n\n            dp = row;\n            shift = 4;\n            d = 0;\n            for (i = png_pass_start[pass]; i < row_width;\n                i += png_pass_inc[pass])\n            {\n               sp = row + (png_size_t)(i >> 1);\n               value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;\n               d |= (value << shift);\n\n               if (shift == 0)\n               {\n                  shift = 4;\n                  *dp++ = (png_byte)d;\n                  d = 0;\n               }\n\n               else\n                  shift -= 4;\n            }\n            if (shift != 4)\n               *dp = (png_byte)d;\n\n            break;\n         }\n\n         default:\n         {\n            png_bytep sp;\n            png_bytep dp;\n            png_uint_32 i;\n            png_uint_32 row_width = row_info->width;\n            png_size_t pixel_bytes;\n\n            /* Start at the beginning */\n            dp = row;\n\n            /* Find out how many bytes each pixel takes up */\n            pixel_bytes = (row_info->pixel_depth >> 3);\n\n            /* Loop through the row, only looking at the pixels that matter */\n            for (i = png_pass_start[pass]; i < row_width;\n               i += png_pass_inc[pass])\n            {\n               /* Find out where the original pixel is */\n               sp = row + (png_size_t)i * pixel_bytes;\n\n               /* Move the pixel */\n               if (dp != sp)\n                  memcpy(dp, sp, pixel_bytes);\n\n               /* Next pixel */\n               dp += pixel_bytes;\n            }\n            break;\n         }\n      }\n      /* Set new row width */\n      row_info->width = (row_info->width +\n          png_pass_inc[pass] - 1 -\n          png_pass_start[pass]) /\n          png_pass_inc[pass];\n\n      row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,\n          row_info->width);\n   }\n}\n#endif\n\n\n/* This filters the row, chooses which filter to use, if it has not already\n * been specified by the application, and then writes the row out with the\n * chosen filter.\n */\nstatic void /* PRIVATE */\npng_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,\n    png_size_t row_bytes);\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\nstatic png_size_t /* PRIVATE */\npng_setup_sub_row(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes, const png_size_t lmins)\n{\n   png_bytep rp, dp, lp;\n   png_size_t i;\n   png_size_t sum = 0;\n   int v;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp;\n        i++, rp++, dp++)\n   {\n      v = *dp = *rp;\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n   }\n\n   for (lp = png_ptr->row_buf + 1; i < row_bytes;\n      i++, rp++, lp++, dp++)\n   {\n      v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n\n      if (sum > lmins)  /* We are already worse, don't continue. */\n        break;\n   }\n\n   return (sum);\n}\n\nstatic void /* PRIVATE */\npng_setup_sub_row_only(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes)\n{\n   png_bytep rp, dp, lp;\n   png_size_t i;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_SUB;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1; i < bpp;\n        i++, rp++, dp++)\n   {\n      *dp = *rp;\n   }\n\n   for (lp = png_ptr->row_buf + 1; i < row_bytes;\n      i++, rp++, lp++, dp++)\n   {\n      *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);\n   }\n}\n\nstatic png_size_t /* PRIVATE */\npng_setup_up_row(png_structrp png_ptr, const png_size_t row_bytes,\n    const png_size_t lmins)\n{\n   png_bytep rp, dp, pp;\n   png_size_t i;\n   png_size_t sum = 0;\n   int v;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < row_bytes;\n       i++, rp++, pp++, dp++)\n   {\n      v = *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n\n      if (sum > lmins)  /* We are already worse, don't continue. */\n        break;\n   }\n\n   return (sum);\n}\nstatic void /* PRIVATE */\npng_setup_up_row_only(png_structrp png_ptr, const png_size_t row_bytes)\n{\n   png_bytep rp, dp, pp;\n   png_size_t i;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_UP;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < row_bytes;\n       i++, rp++, pp++, dp++)\n   {\n      *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);\n   }\n}\n\nstatic png_size_t /* PRIVATE */\npng_setup_avg_row(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes, const png_size_t lmins)\n{\n   png_bytep rp, dp, pp, lp;\n   png_uint_32 i;\n   png_size_t sum = 0;\n   int v;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < bpp; i++)\n   {\n      v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);\n\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n   }\n\n   for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)\n   {\n      v = *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))\n          & 0xff);\n\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n\n      if (sum > lmins)  /* We are already worse, don't continue. */\n        break;\n   }\n\n   return (sum);\n}\nstatic void /* PRIVATE */\npng_setup_avg_row_only(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes)\n{\n   png_bytep rp, dp, pp, lp;\n   png_uint_32 i;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_AVG;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < bpp; i++)\n   {\n      *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);\n   }\n\n   for (lp = png_ptr->row_buf + 1; i < row_bytes; i++)\n   {\n      *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))\n          & 0xff);\n   }\n}\n\nstatic png_size_t /* PRIVATE */\npng_setup_paeth_row(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes, const png_size_t lmins)\n{\n   png_bytep rp, dp, pp, cp, lp;\n   png_size_t i;\n   png_size_t sum = 0;\n   int v;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < bpp; i++)\n   {\n      v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);\n\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n   }\n\n   for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;\n        i++)\n   {\n      int a, b, c, pa, pb, pc, p;\n\n      b = *pp++;\n      c = *cp++;\n      a = *lp++;\n\n      p = b - c;\n      pc = a - c;\n\n#ifdef PNG_USE_ABS\n      pa = abs(p);\n      pb = abs(pc);\n      pc = abs(p + pc);\n#else\n      pa = p < 0 ? -p : p;\n      pb = pc < 0 ? -pc : pc;\n      pc = (p + pc) < 0 ? -(p + pc) : p + pc;\n#endif\n\n      p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;\n\n      v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);\n\n#ifdef PNG_USE_ABS\n      sum += 128 - abs(v - 128);\n#else\n      sum += (v < 128) ? v : 256 - v;\n#endif\n\n      if (sum > lmins)  /* We are already worse, don't continue. */\n        break;\n   }\n\n   return (sum);\n}\nstatic void /* PRIVATE */\npng_setup_paeth_row_only(png_structrp png_ptr, const png_uint_32 bpp,\n    const png_size_t row_bytes)\n{\n   png_bytep rp, dp, pp, cp, lp;\n   png_size_t i;\n\n   png_ptr->try_row[0] = PNG_FILTER_VALUE_PAETH;\n\n   for (i = 0, rp = png_ptr->row_buf + 1, dp = png_ptr->try_row + 1,\n       pp = png_ptr->prev_row + 1; i < bpp; i++)\n   {\n      *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);\n   }\n\n   for (lp = png_ptr->row_buf + 1, cp = png_ptr->prev_row + 1; i < row_bytes;\n        i++)\n   {\n      int a, b, c, pa, pb, pc, p;\n\n      b = *pp++;\n      c = *cp++;\n      a = *lp++;\n\n      p = b - c;\n      pc = a - c;\n\n#ifdef PNG_USE_ABS\n      pa = abs(p);\n      pb = abs(pc);\n      pc = abs(p + pc);\n#else\n      pa = p < 0 ? -p : p;\n      pb = pc < 0 ? -pc : pc;\n      pc = (p + pc) < 0 ? -(p + pc) : p + pc;\n#endif\n\n      p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;\n\n      *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);\n   }\n}\n#endif /* WRITE_FILTER */\n\nvoid /* PRIVATE */\npng_write_find_filter(png_structrp png_ptr, png_row_infop row_info)\n{\n#ifndef PNG_WRITE_FILTER_SUPPORTED\n   png_write_filtered_row(png_ptr, png_ptr->row_buf, row_info->rowbytes+1);\n#else\n   unsigned int filter_to_do = png_ptr->do_filter;\n   png_bytep row_buf;\n   png_bytep best_row;\n   png_uint_32 bpp;\n   png_size_t mins;\n   png_size_t row_bytes = row_info->rowbytes;\n\n   png_debug(1, \"in png_write_find_filter\");\n\n   /* Find out how many bytes offset each pixel is */\n   bpp = (row_info->pixel_depth + 7) >> 3;\n\n   row_buf = png_ptr->row_buf;\n   mins = PNG_SIZE_MAX - 256/* so we can detect potential overflow of the\n                               running sum */;\n\n   /* The prediction method we use is to find which method provides the\n    * smallest value when summing the absolute values of the distances\n    * from zero, using anything >= 128 as negative numbers.  This is known\n    * as the \"minimum sum of absolute differences\" heuristic.  Other\n    * heuristics are the \"weighted minimum sum of absolute differences\"\n    * (experimental and can in theory improve compression), and the \"zlib\n    * predictive\" method (not implemented yet), which does test compressions\n    * of lines using different filter methods, and then chooses the\n    * (series of) filter(s) that give minimum compressed data size (VERY\n    * computationally expensive).\n    *\n    * GRR 980525:  consider also\n    *\n    *   (1) minimum sum of absolute differences from running average (i.e.,\n    *       keep running sum of non-absolute differences & count of bytes)\n    *       [track dispersion, too?  restart average if dispersion too large?]\n    *\n    *  (1b) minimum sum of absolute differences from sliding average, probably\n    *       with window size <= deflate window (usually 32K)\n    *\n    *   (2) minimum sum of squared differences from zero or running average\n    *       (i.e., ~ root-mean-square approach)\n    */\n\n\n   /* We don't need to test the 'no filter' case if this is the only filter\n    * that has been chosen, as it doesn't actually do anything to the data.\n    */\n   best_row = png_ptr->row_buf;\n\n   if (PNG_SIZE_MAX/128 <= row_bytes)\n   {\n      /* Overflow can occur in the calculation, just select the lowest set\n       * filter.\n       */\n      filter_to_do &= 0U-filter_to_do;\n   }\n   else if ((filter_to_do & PNG_FILTER_NONE) != 0 &&\n         filter_to_do != PNG_FILTER_NONE)\n   {\n      /* Overflow not possible and multiple filters in the list, including the\n       * 'none' filter.\n       */\n      png_bytep rp;\n      png_size_t sum = 0;\n      png_size_t i;\n      int v;\n\n      {\n         for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)\n         {\n            v = *rp;\n#ifdef PNG_USE_ABS\n            sum += 128 - abs(v - 128);\n#else\n            sum += (v < 128) ? v : 256 - v;\n#endif\n         }\n      }\n\n      mins = sum;\n   }\n\n   /* Sub filter */\n   if (filter_to_do == PNG_FILTER_SUB)\n   /* It's the only filter so no testing is needed */\n   {\n      png_setup_sub_row_only(png_ptr, bpp, row_bytes);\n      best_row = png_ptr->try_row;\n   }\n\n   else if ((filter_to_do & PNG_FILTER_SUB) != 0)\n   {\n      png_size_t sum;\n      png_size_t lmins = mins;\n\n      sum = png_setup_sub_row(png_ptr, bpp, row_bytes, lmins);\n\n      if (sum < mins)\n      {\n         mins = sum;\n         best_row = png_ptr->try_row;\n         if (png_ptr->tst_row != NULL)\n         {\n            png_ptr->try_row = png_ptr->tst_row;\n            png_ptr->tst_row = best_row;\n         }\n      }\n   }\n\n   /* Up filter */\n   if (filter_to_do == PNG_FILTER_UP)\n   {\n      png_setup_up_row_only(png_ptr, row_bytes);\n      best_row = png_ptr->try_row;\n   }\n\n   else if ((filter_to_do & PNG_FILTER_UP) != 0)\n   {\n      png_size_t sum;\n      png_size_t lmins = mins;\n\n      sum = png_setup_up_row(png_ptr, row_bytes, lmins);\n\n      if (sum < mins)\n      {\n         mins = sum;\n         best_row = png_ptr->try_row;\n         if (png_ptr->tst_row != NULL)\n         {\n            png_ptr->try_row = png_ptr->tst_row;\n            png_ptr->tst_row = best_row;\n         }\n      }\n   }\n\n   /* Avg filter */\n   if (filter_to_do == PNG_FILTER_AVG)\n   {\n      png_setup_avg_row_only(png_ptr, bpp, row_bytes);\n      best_row = png_ptr->try_row;\n   }\n\n   else if ((filter_to_do & PNG_FILTER_AVG) != 0)\n   {\n      png_size_t sum;\n      png_size_t lmins = mins;\n\n      sum= png_setup_avg_row(png_ptr, bpp, row_bytes, lmins);\n\n      if (sum < mins)\n      {\n         mins = sum;\n         best_row = png_ptr->try_row;\n         if (png_ptr->tst_row != NULL)\n         {\n            png_ptr->try_row = png_ptr->tst_row;\n            png_ptr->tst_row = best_row;\n         }\n      }\n   }\n\n   /* Paeth filter */\n   if (filter_to_do == PNG_FILTER_PAETH)\n   {\n      png_setup_paeth_row_only(png_ptr, bpp, row_bytes);\n      best_row = png_ptr->try_row;\n   }\n\n   else if ((filter_to_do & PNG_FILTER_PAETH) != 0)\n   {\n      png_size_t sum;\n      png_size_t lmins = mins;\n\n      sum = png_setup_paeth_row(png_ptr, bpp, row_bytes, lmins);\n\n      if (sum < mins)\n      {\n         best_row = png_ptr->try_row;\n         if (png_ptr->tst_row != NULL)\n         {\n            png_ptr->try_row = png_ptr->tst_row;\n            png_ptr->tst_row = best_row;\n         }\n      }\n   }\n\n   /* Do the actual writing of the filtered row data from the chosen filter. */\n   png_write_filtered_row(png_ptr, best_row, row_info->rowbytes+1);\n\n#endif /* WRITE_FILTER */\n}\n\n\n/* Do the actual writing of a previously filtered row. */\nstatic void\npng_write_filtered_row(png_structrp png_ptr, png_bytep filtered_row,\n    png_size_t full_row_length/*includes filter byte*/)\n{\n   png_debug(1, \"in png_write_filtered_row\");\n\n   png_debug1(2, \"filter = %d\", filtered_row[0]);\n\n   png_compress_IDAT(png_ptr, filtered_row, full_row_length, Z_NO_FLUSH);\n\n#ifdef PNG_WRITE_FILTER_SUPPORTED\n   /* Swap the current and previous rows */\n   if (png_ptr->prev_row != NULL)\n   {\n      png_bytep tptr;\n\n      tptr = png_ptr->prev_row;\n      png_ptr->prev_row = png_ptr->row_buf;\n      png_ptr->row_buf = tptr;\n   }\n#endif /* WRITE_FILTER */\n\n   /* Finish row - updates counters and flushes zlib if last row */\n   png_write_finish_row(png_ptr);\n\n#ifdef PNG_WRITE_FLUSH_SUPPORTED\n   png_ptr->flush_rows++;\n\n   if (png_ptr->flush_dist > 0 &&\n       png_ptr->flush_rows >= png_ptr->flush_dist)\n   {\n      png_write_flush(png_ptr);\n   }\n#endif /* WRITE_FLUSH */\n}\n#endif /* WRITE */\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/libpng.tgt",
    "content": "40\r\ntargetIdent\r\n0\r\nMProject\r\n1\r\nMComponent\r\n0\r\n2\r\nWString\r\n3\r\nLIB\r\n3\r\nWString\r\n5\r\nn_2sn\r\n1\r\n0\r\n0\r\n4\r\nMCommand\r\n0\r\n5\r\nMCommand\r\n0\r\n6\r\nMItem\r\n10\r\nlibpng.lib\r\n7\r\nWString\r\n3\r\nLIB\r\n8\r\nWVList\r\n0\r\n9\r\nWVList\r\n1\r\n10\r\nActionStates\r\n11\r\nWString\r\n5\r\n&Make\r\n12\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n13\r\nWPickList\r\n16\r\n14\r\nMItem\r\n3\r\n*.c\r\n15\r\nWString\r\n4\r\nCOBJ\r\n16\r\nWVList\r\n2\r\n17\r\nMVState\r\n18\r\nWString\r\n3\r\nWCC\r\n19\r\nWString\r\n25\r\nn????Include directories:\r\n1\r\n20\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n21\r\nMVState\r\n22\r\nWString\r\n3\r\nWCC\r\n23\r\nWString\r\n25\r\nn????Include directories:\r\n0\r\n24\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n25\r\nWVList\r\n1\r\n26\r\nActionStates\r\n27\r\nWString\r\n5\r\n&Make\r\n28\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n29\r\nMItem\r\n11\r\n..\\..\\png.c\r\n30\r\nWString\r\n4\r\nCOBJ\r\n31\r\nWVList\r\n0\r\n32\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n33\r\nMItem\r\n16\r\n..\\..\\pngerror.c\r\n34\r\nWString\r\n4\r\nCOBJ\r\n35\r\nWVList\r\n0\r\n36\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n37\r\nMItem\r\n14\r\n..\\..\\pngget.c\r\n38\r\nWString\r\n4\r\nCOBJ\r\n39\r\nWVList\r\n0\r\n40\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n41\r\nMItem\r\n14\r\n..\\..\\pngmem.c\r\n42\r\nWString\r\n4\r\nCOBJ\r\n43\r\nWVList\r\n0\r\n44\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n45\r\nMItem\r\n16\r\n..\\..\\pngpread.c\r\n46\r\nWString\r\n4\r\nCOBJ\r\n47\r\nWVList\r\n0\r\n48\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n49\r\nMItem\r\n15\r\n..\\..\\pngread.c\r\n50\r\nWString\r\n4\r\nCOBJ\r\n51\r\nWVList\r\n0\r\n52\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n53\r\nMItem\r\n14\r\n..\\..\\pngrio.c\r\n54\r\nWString\r\n4\r\nCOBJ\r\n55\r\nWVList\r\n0\r\n56\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n57\r\nMItem\r\n16\r\n..\\..\\pngrtran.c\r\n58\r\nWString\r\n4\r\nCOBJ\r\n59\r\nWVList\r\n0\r\n60\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n61\r\nMItem\r\n16\r\n..\\..\\pngrutil.c\r\n62\r\nWString\r\n4\r\nCOBJ\r\n63\r\nWVList\r\n0\r\n64\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n65\r\nMItem\r\n14\r\n..\\..\\pngset.c\r\n66\r\nWString\r\n4\r\nCOBJ\r\n67\r\nWVList\r\n0\r\n68\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n69\r\nMItem\r\n16\r\n..\\..\\pngtrans.c\r\n70\r\nWString\r\n4\r\nCOBJ\r\n71\r\nWVList\r\n0\r\n72\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n73\r\nMItem\r\n14\r\n..\\..\\pngwio.c\r\n74\r\nWString\r\n4\r\nCOBJ\r\n75\r\nWVList\r\n0\r\n76\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n77\r\nMItem\r\n16\r\n..\\..\\pngwrite.c\r\n78\r\nWString\r\n4\r\nCOBJ\r\n79\r\nWVList\r\n0\r\n80\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n81\r\nMItem\r\n16\r\n..\\..\\pngwtran.c\r\n82\r\nWString\r\n4\r\nCOBJ\r\n83\r\nWVList\r\n0\r\n84\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n85\r\nMItem\r\n16\r\n..\\..\\pngwutil.c\r\n86\r\nWString\r\n4\r\nCOBJ\r\n87\r\nWVList\r\n0\r\n88\r\nWVList\r\n0\r\n14\r\n1\r\n1\r\n0\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/libpng.wpj",
    "content": "40\r\nprojectIdent\r\n0\r\nVpeMain\r\n1\r\nWRect\r\n256\r\n0\r\n8960\r\n9294\r\n2\r\nMProject\r\n3\r\nMCommand\r\n322\r\n# Locations of zlib and (if required) awk (change as required:)\r\nset zlib=..\\..\\..\\zlib\r\nset awk=\r\n#\r\n@if not exist pngconfig.dfa $(MAKE) $(__MAKEOPTS__) -f pngconfig.mak defaults\r\n@if exist config.inf type config.inf\r\n@echo Checking for the libpng configuration file pnglibconf.h\r\n$(MAKE) $(__MAKEOPTS__) -f pngconfig.mak\r\n4\r\nMCommand\r\n19\r\n@type pngconfig.inf\r\n4\r\n5\r\nWFileName\r\n10\r\nlibpng.tgt\r\n6\r\nWFileName\r\n11\r\npngtest.tgt\r\n7\r\nWFileName\r\n12\r\npngvalid.tgt\r\n8\r\nWFileName\r\n12\r\npngstest.tgt\r\n9\r\nWVList\r\n4\r\n10\r\nVComponent\r\n11\r\nWRect\r\n0\r\n0\r\n5638\r\n4174\r\n0\r\n0\r\n12\r\nWFileName\r\n10\r\nlibpng.tgt\r\n0\r\n0\r\n13\r\nVComponent\r\n14\r\nWRect\r\n1280\r\n1550\r\n5638\r\n4174\r\n0\r\n0\r\n15\r\nWFileName\r\n11\r\npngtest.tgt\r\n0\r\n1\r\n16\r\nVComponent\r\n17\r\nWRect\r\n524\r\n497\r\n5638\r\n4174\r\n0\r\n0\r\n18\r\nWFileName\r\n12\r\npngvalid.tgt\r\n0\r\n1\r\n19\r\nVComponent\r\n20\r\nWRect\r\n2054\r\n2701\r\n5674\r\n4232\r\n0\r\n0\r\n21\r\nWFileName\r\n12\r\npngstest.tgt\r\n0\r\n1\r\n19\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/pngconfig.mak",
    "content": "# This is an OpenWatcom make file which builds pnglibconf.h - the libpng\r\n# configuration header.  You can ignore this file if you don't need to\r\n# configure libpng; a default configuration will be built.\r\n#\r\n# For more information build libpng.wpj under the IDE and then read the\r\n# generated files:\r\n#\r\n#    config.inf: Basic configuration information for a standard build.\r\n#    pngconfig.dfa: Advanced configuration for non-standard libpng builds.\r\n#\r\nDELETE=rm -f\r\nECHO=echo\r\nCOPY=copy\r\n#\r\n# If your configuration needs to test compiler flags when building\r\n# pnglibconf.h you may need to override the following on the wmake command\r\n# line:\r\nCFLAGS=\r\nCC=wcl386\r\nCPP=$(CC) -pw0\r\n#\r\n# Read awk from the environment if set, else it can be set on the command\r\n# line (the default approach is to set the %awk% environment variable in the\r\n# IDE libpng.wpj 'before' rule - this setting is local.)\r\n!ifdef %awk\r\nAWK=$(%awk)\r\n!endif\r\n#\r\n# pnglibconf.h must exist in the source directory, this is the final rule\r\n# which copies the local built version (and this is the default target for\r\n# this makefile.)\r\n..\\..\\pnglibconf.h: pnglibconf.h\r\n $(COPY) pnglibconf.h $@\r\n\r\n!ifdef AWK\r\n# CPPFLAGS should contain the options to control the result,\r\n# but DEFS and CFLAGS are also supported here, override\r\n# as appropriate\r\nDFNFLAGS = $(DEFS) $(CPPFLAGS) $(CFLAGS)\r\n\r\npnglibconf.h: pnglibconf.dfn\r\n $(DELETE) $@ dfn.c dfn1.out dfn2.out\r\n $(ECHO) $#include \"pnglibconf.dfn\" >dfn.c\r\n $(CPP) $(DFNFLAGS) dfn.c >dfn1.out\r\n $(AWK) -f << dfn1.out >dfn2.out\r\n/^.*PNG_DEFN_MAGIC-.*-PNG_DEFN_END.*$$/{\r\n sub(/^.*PNG_DEFN_MAGIC-/, \"\")\r\n sub(/ *-PNG_DEFN_END.*$$/, \"\")\r\n gsub(/ *@@@ */, \"\")\r\n print\r\n}\r\n<<\r\n $(COPY) dfn2.out $@\r\n @type << >pngconfig.inf\r\nThis is a locally configurable build of libpng.lib; for configuration\r\ninstructions consult and edit projects/openwatcom/pngconfig.dfa\r\n<<\r\n $(DELETE) dfn.c dfn1.out dfn2.out\r\n\r\npnglibconf.dfn: ..\\..\\scripts\\pnglibconf.dfa ..\\..\\scripts\\options.awk pngconfig.dfa ..\\..\\pngconf.h\r\n $(DELETE) $@ dfn1.out dfn2.out\r\n $(AWK) -f ..\\..\\scripts\\options.awk out=dfn1.out version=search ..\\..\\pngconf.h ..\\..\\scripts\\pnglibconf.dfa pngconfig.dfa $(DFA_XTRA) 1>&2\r\n $(AWK) -f ..\\..\\scripts\\options.awk out=dfn2.out dfn1.out 1>&2\r\n $(COPY) dfn2.out $@\r\n $(DELETE) dfn1.out dfn2.out\r\n\r\n!else\r\n# The following lines are used to copy scripts\\pnglibconf.h.prebuilt and make\r\n# the required change to the calling convention.\r\n#\r\n# By default libpng is built to use the __cdecl calling convention on\r\n# Windows.  This gives compatibility with MSVC and GCC.  Unfortunately it\r\n# does not work with OpenWatcom because OpenWatcom implements longjmp using\r\n# the __watcall convention (compared with both MSVC and GCC which use __cdecl\r\n# for library functions.)\r\n#\r\n# Thus the default must be changed to build on OpenWatcom and, once changed,\r\n# the result will not be compatible with applications built using other\r\n# compilers (in fact attempts to build will fail at compile time.)\r\n#\r\npnglibconf.h: ..\\..\\scripts\\pnglibconf.h.prebuilt .existsonly\r\n @$(ECHO) .\r\n @$(ECHO) .\r\n @$(ECHO) $$(AWK) NOT AVAILABLE: COPYING scripts\\pnglibconf.h.prebuilt\r\n @$(ECHO) .\r\n @$(ECHO) .\r\n vi -q -k \":1,$$s/PNG_API_RULE 0$$/PNG_API_RULE 2/\\n:w! $@\\n:q!\\n\" ..\\..\\scripts\\pnglibconf.h.prebuilt\r\n @$(ECHO) .\r\n @$(ECHO) .\r\n @$(ECHO) YOU HAVE A DEFAULT CONFIGURATION BECAUSE YOU DO NOT HAVE AWK!\r\n @$(ECHO) .\r\n @$(ECHO) .\r\n @type << >pngconfig.inf\r\nThis is the default configuration of libpng.lib, if you wish to\r\nchange the configuration please consult the instructions in\r\nprojects/owatcom/pngconfig.dfa.\r\n<<\r\n\r\n!endif\r\n\r\n# Make the default files\r\ndefaults: .symbolic\r\n @$(COPY) << config.inf\r\n$# The libpng project is incompletely configured.  To complete configuration\r\n$# please complete the following steps:\r\n$#\r\n$#   1) Edit the 'before' rule of libpng.wpj (from the IDE) to define the\r\n$#      locations of the zlib include file zlib.h and the built zlib library,\r\n$#      zlib.lib.\r\n$#\r\n$#   2) If you want to change libpng to a non-standard configuration also\r\n$#      change the definition of 'awk' in the before rule to the name of your\r\n$#      awk command.  For more instructions on configuration read\r\n$#      pngconfig.dfa.\r\n$#\r\n$#   3) Delete this file (config.inf).\r\n<<\r\n @$(COPY) << pngconfig.dfa\r\n$# pngconfig.dfa: this file contains configuration options for libpng.\r\n$# If emtpy the standard configuration will be built.  For this file to be\r\n$# used a working version of the program 'awk' is required and the program\r\n$# must be identified in the 'before' rule of the project.\r\n$#\r\n$# If you don't already have 'awk', or the version of awk you have seems not\r\n$# to work, download Brian Kernighan's awk (Brian Kernighan is the author of\r\n$# awk.)  You can find source code and a built executable (called awk95.exe)\r\n$# here:\r\n$#\r\n$#     http://www.cs.princeton.edu/~bwk/btl.mirror/\r\n$#\r\n$# The executable works just fine.\r\n$#\r\n$# If build issues errors after a change to pngconfig.dfa you have entered\r\n$# inconsistent feature requests, or even malformed requests, in\r\n$# pngconfig.dfa.  The error messages from awk should be comprehensible, but\r\n$# if not simply go back to the start (nothing but comments in this file) and\r\n$# enter configuration lines one by one until one produces an error.  (Or, of\r\n$# course, do the standard binary chop.)\r\n$#\r\n$# You need to rebuild everything after a change to pnglibconf.dfa - i.e. you\r\n$# must do Actions/Mark All Targets for Remake.  This is because the compiler\r\n$# generated dependency information (as of OpenWatcom 1.9) does not record the\r\n$# dependency on pnglibconf.h correctly.\r\n$#\r\n$# If awk isn't set then this file is bypassed.  If you just want the standard\r\n$# configuration it is automatically produced from the distributed version\r\n$# (scripts\\pnglibconf.h.prebuilt) by editting PNG_API_RULE to 2 (to force use\r\n$# of the OpenWatcom library calling convention.)\r\n$#\r\n<<\r\n\r\nclean:: .symbolic\r\n $(DELETE) ..\\..\\pnglibconf.h pnglibconf.* dfn.c *.out pngconfig.inf\r\n $(DELETE) *.obj *.mbr *.sym *.err *.pch libpng.mk\r\n $(DELETE) libpng.lib libpng.lbr libpng.lb1 libpng.cbr libpng.mk1\r\n $(DELETE) pngtest.exe pngtest.map pngtest.lk1 pngtest.mk1\r\n $(DELETE) pngvalid.exe pngvalid.map pngvalid.lk1 pngvalid.mk1\r\n\r\ndistclean:: clean .symbolic\r\n $(DELETE) zlib.inf awk.inf config.inf pngconfig.dfa\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/pngstest.tgt",
    "content": "40\r\ntargetIdent\r\n0\r\nMProject\r\n1\r\nMComponent\r\n0\r\n2\r\nWString\r\n4\r\nNEXE\r\n3\r\nWString\r\n5\r\nnc2en\r\n1\r\n0\r\n0\r\n4\r\nMCommand\r\n0\r\n5\r\nMCommand\r\n1118\r\npngstest --strict --log ../../contrib/pngsuite/basn0g01.png ../../contrib/pngsuite/basn0g02.png ../../contrib/pngsuite/basn0g04.png ../../contrib/pngsuite/basn0g08.png ../../contrib/pngsuite/basn0g16.png ../../contrib/pngsuite/basn2c08.png ../../contrib/pngsuite/basn2c16.png ../../contrib/pngsuite/basn3p01.png ../../contrib/pngsuite/basn3p02.png ../../contrib/pngsuite/basn3p04.png ../../contrib/pngsuite/basn3p08.png ../../contrib/pngsuite/basn4a08.png ../../contrib/pngsuite/basn4a16.png ../../contrib/pngsuite/basn6a08.png ../../contrib/pngsuite/basn6a16.png ../../contrib/pngsuite/ftbbn0g04.png ../../contrib/pngsuite/ftbbn0g01.png ../../contrib/pngsuite/ftbbn0g02.png ../../contrib/pngsuite/ftbbn2c16.png ../../contrib/pngsuite/ftbbn3p08.png ../../contrib/pngsuite/ftbgn2c16.png ../../contrib/pngsuite/ftbgn3p08.png ../../contrib/pngsuite/ftbrn2c08.png ../../contrib/pngsuite/ftbwn0g16.png ../../contrib/pngsuite/ftbwn3p08.png ../../contrib/pngsuite/ftbyn3p08.png ../../contrib/pngsuite/ftp0n0g08.png ../../contrib/pngsuite/ftp0n2c08.png ../../contrib/pngsuite/ftp0n3p08.png ../../contrib/pngsuite/ftp1n3p08.png\r\n6\r\nMItem\r\n12\r\npngstest.exe\r\n7\r\nWString\r\n4\r\nNEXE\r\n8\r\nWVList\r\n6\r\n9\r\nMVState\r\n10\r\nWString\r\n7\r\nWINLINK\r\n11\r\nWString\r\n11\r\n?????Stack:\r\n1\r\n12\r\nWString\r\n4\r\n768k\r\n0\r\n13\r\nMVState\r\n14\r\nWString\r\n7\r\nWINLINK\r\n15\r\nWString\r\n28\r\n?????Library directories(;):\r\n1\r\n16\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n17\r\nMVState\r\n18\r\nWString\r\n7\r\nWINLINK\r\n19\r\nWString\r\n18\r\n?????Libraries(,):\r\n1\r\n20\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n21\r\nMVState\r\n22\r\nWString\r\n7\r\nWINLINK\r\n23\r\nWString\r\n11\r\n?????Stack:\r\n0\r\n24\r\nWString\r\n4\r\n768k\r\n0\r\n25\r\nMVState\r\n26\r\nWString\r\n7\r\nWINLINK\r\n27\r\nWString\r\n28\r\n?????Library directories(;):\r\n0\r\n28\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n29\r\nMVState\r\n30\r\nWString\r\n7\r\nWINLINK\r\n31\r\nWString\r\n18\r\n?????Libraries(,):\r\n0\r\n32\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n33\r\nWVList\r\n1\r\n34\r\nActionStates\r\n35\r\nWString\r\n4\r\n&Run\r\n36\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n37\r\nWPickList\r\n2\r\n38\r\nMItem\r\n3\r\n*.c\r\n39\r\nWString\r\n4\r\nCOBJ\r\n40\r\nWVList\r\n2\r\n41\r\nMVState\r\n42\r\nWString\r\n3\r\nWCC\r\n43\r\nWString\r\n25\r\nn????Include directories:\r\n1\r\n44\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n45\r\nMVState\r\n46\r\nWString\r\n3\r\nWCC\r\n47\r\nWString\r\n25\r\nn????Include directories:\r\n0\r\n48\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n49\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n50\r\nMItem\r\n33\r\n..\\..\\contrib\\libtests\\pngstest.c\r\n51\r\nWString\r\n4\r\nCOBJ\r\n52\r\nWVList\r\n0\r\n53\r\nWVList\r\n0\r\n38\r\n1\r\n1\r\n0\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/pngtest.tgt",
    "content": "40\r\ntargetIdent\r\n0\r\nMProject\r\n1\r\nMComponent\r\n0\r\n2\r\nWString\r\n4\r\nNEXE\r\n3\r\nWString\r\n5\r\nnc2en\r\n1\r\n0\r\n0\r\n4\r\nMCommand\r\n0\r\n5\r\nMCommand\r\n34\r\ncd ..\\..\r\nprojects\\owatcom\\pngtest\r\n6\r\nMItem\r\n11\r\npngtest.exe\r\n7\r\nWString\r\n4\r\nNEXE\r\n8\r\nWVList\r\n4\r\n9\r\nMVState\r\n10\r\nWString\r\n7\r\nWINLINK\r\n11\r\nWString\r\n28\r\n?????Library directories(;):\r\n1\r\n12\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n13\r\nMVState\r\n14\r\nWString\r\n7\r\nWINLINK\r\n15\r\nWString\r\n18\r\n?????Libraries(,):\r\n1\r\n16\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n17\r\nMVState\r\n18\r\nWString\r\n7\r\nWINLINK\r\n19\r\nWString\r\n28\r\n?????Library directories(;):\r\n0\r\n20\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n21\r\nMVState\r\n22\r\nWString\r\n7\r\nWINLINK\r\n23\r\nWString\r\n18\r\n?????Libraries(,):\r\n0\r\n24\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n25\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n26\r\nWPickList\r\n2\r\n27\r\nMItem\r\n3\r\n*.c\r\n28\r\nWString\r\n4\r\nCOBJ\r\n29\r\nWVList\r\n2\r\n30\r\nMVState\r\n31\r\nWString\r\n3\r\nWCC\r\n32\r\nWString\r\n25\r\nn????Include directories:\r\n1\r\n33\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n34\r\nMVState\r\n35\r\nWString\r\n3\r\nWCC\r\n36\r\nWString\r\n25\r\nn????Include directories:\r\n0\r\n37\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n38\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n39\r\nMItem\r\n15\r\n..\\..\\pngtest.c\r\n40\r\nWString\r\n4\r\nCOBJ\r\n41\r\nWVList\r\n0\r\n42\r\nWVList\r\n0\r\n27\r\n1\r\n1\r\n0\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/owatcom/pngvalid.tgt",
    "content": "40\r\ntargetIdent\r\n0\r\nMProject\r\n1\r\nMComponent\r\n0\r\n2\r\nWString\r\n4\r\nNEXE\r\n3\r\nWString\r\n5\r\nnc2en\r\n1\r\n0\r\n0\r\n4\r\nMCommand\r\n0\r\n5\r\nMCommand\r\n8\r\npngvalid\r\n6\r\nMItem\r\n12\r\npngvalid.exe\r\n7\r\nWString\r\n4\r\nNEXE\r\n8\r\nWVList\r\n6\r\n9\r\nMVState\r\n10\r\nWString\r\n7\r\nWINLINK\r\n11\r\nWString\r\n11\r\n?????Stack:\r\n1\r\n12\r\nWString\r\n4\r\n768k\r\n0\r\n13\r\nMVState\r\n14\r\nWString\r\n7\r\nWINLINK\r\n15\r\nWString\r\n28\r\n?????Library directories(;):\r\n1\r\n16\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n17\r\nMVState\r\n18\r\nWString\r\n7\r\nWINLINK\r\n19\r\nWString\r\n18\r\n?????Libraries(,):\r\n1\r\n20\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n21\r\nMVState\r\n22\r\nWString\r\n7\r\nWINLINK\r\n23\r\nWString\r\n11\r\n?????Stack:\r\n0\r\n24\r\nWString\r\n4\r\n768k\r\n0\r\n25\r\nMVState\r\n26\r\nWString\r\n7\r\nWINLINK\r\n27\r\nWString\r\n28\r\n?????Library directories(;):\r\n0\r\n28\r\nWString\r\n8\r\n$(%zlib)\r\n0\r\n29\r\nMVState\r\n30\r\nWString\r\n7\r\nWINLINK\r\n31\r\nWString\r\n18\r\n?????Libraries(,):\r\n0\r\n32\r\nWString\r\n19\r\nlibpng.lib zlib.lib\r\n0\r\n33\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n34\r\nWPickList\r\n2\r\n35\r\nMItem\r\n3\r\n*.c\r\n36\r\nWString\r\n4\r\nCOBJ\r\n37\r\nWVList\r\n2\r\n38\r\nMVState\r\n39\r\nWString\r\n3\r\nWCC\r\n40\r\nWString\r\n25\r\nn????Include directories:\r\n1\r\n41\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n42\r\nMVState\r\n43\r\nWString\r\n3\r\nWCC\r\n44\r\nWString\r\n25\r\nn????Include directories:\r\n0\r\n45\r\nWString\r\n39\r\n\"$(%zlib);$(%watcom)/h;$(%watcom)/h/nt\"\r\n0\r\n46\r\nWVList\r\n0\r\n-1\r\n1\r\n1\r\n0\r\n47\r\nMItem\r\n33\r\n..\\..\\contrib\\libtests\\pngvalid.c\r\n48\r\nWString\r\n4\r\nCOBJ\r\n49\r\nWVList\r\n0\r\n50\r\nWVList\r\n0\r\n35\r\n1\r\n1\r\n0\r\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/PRJ0041.mak",
    "content": "# Prevent \"Cannot find missing dependency...\" warnings while compiling\n# pngwin.rc (PRJ0041).\n\nall: $(IntDir)\\alloc.h \\\n\t $(IntDir)\\fp.h \\\n\t $(IntDir)\\m68881.h \\\n\t $(IntDir)\\mem.h \\\n\t $(IntDir)\\pngusr.h \\\n\t $(IntDir)\\strings.h \\\n\t $(IntDir)\\unistd.h \\\n\t $(IntDir)\\unixio.h\n\n$(IntDir)\\alloc.h \\\n$(IntDir)\\fp.h \\\n$(IntDir)\\m68881.h \\\n$(IntDir)\\mem.h \\\n$(IntDir)\\pngusr.h \\\n$(IntDir)\\strings.h \\\n$(IntDir)\\unistd.h \\\n$(IntDir)\\unixio.h:\n\t@!echo.>$@\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/README.txt",
    "content": "Microsoft Developer Studio Project File, Format Version 7.10 for libpng.\n\nCopyright (C) 2004 Simon-Pierre Cadieux.\n\nThis code is released under the libpng license.\nFor conditions of distribution and use, see copyright notice in png.h\n\nNOTE: This project will be removed from libpng-1.5.0.  It has\nbeen replaced with the \"vstudio\" project.\n\nAssumptions:\n* The libpng source files are in ..\\..\n* The zlib source files are in ..\\..\\..\\zlib\n* The zlib project file is in . /* Warning: This is until the zlib project\n  files get intergrated into the next zlib release. The final zlib project\n  directory will then be ..\\..\\..\\zlib\\projects\\visualc71. */\n\nTo use:\n\n1) On the main menu, select \"File | Open Solution\".\n   Open \"libpng.sln\".\n\n2) Display the Solution Explorer view (Ctrl+Alt+L)\n\n3) Set one of the project as the StartUp project. If you just want to build the\n   binaries set \"libpng\" as the startup project (Select \"libpng\" tree view\n   item + Project | Set as StartUp project). If you want to build and test the\n   binaries set it to \"pngtest\" (Select \"pngtest\" tree view item +\n   Project | Set as StartUp project)\n\n4) Select \"Build | Configuration Manager...\".\n   Choose the configuration you wish to build.\n\n5) Select \"Build | Clean Solution\".\n\n6) Select \"Build | Build Solution (Ctrl-Shift-B)\"\n\nThis project builds the libpng binaries as follows:\n\n* Win32_DLL_Release\\libpng16.dll      DLL build\n* Win32_DLL_Debug\\libpng16d.dll       DLL build (debug version)\n* Win32_DLL_VB\\libpng16vb.dll         DLL build for Visual Basic, using stdcall\n* Win32_LIB_Release\\libpng.lib        static build\n* Win32_LIB_Debug\\libpngd.lib         static build (debug version)\n\nNotes:\n\nIf you change anything in the source files, or select different compiler\nsettings, please change the DLL name to something different than any of\nthe above names. Also, make sure that in your \"pngusr.h\" you define\nPNG_USER_PRIVATEBUILD and PNG_USER_DLLFNAME_POSTFIX according to the\ninstructions provided in \"pngconf.h\".\n\nAll DLLs built by this project use the Microsoft dynamic C runtime library\nMSVCR71.DLL (MSVCR71D.DLL for debug versions).  If you distribute any of the\nabove mentioned libraries you may have to include this DLL in your package.\nFor a list of files that are redistributable in Visual Studio see\n$(VCINSTALLDIR)\\redist.txt.\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/README_zlib.txt",
    "content": "/* WARNING: This file was put in the LibPNG distribution for convenience only.\n            It is expected to be part of the next zlib release under\n            \"projects\\visualc71\\README.txt.\" */\n\nMicrosoft Developer Studio Project File, Format Version 7.10 for zlib.\n\nCopyright (C) 2004 Simon-Pierre Cadieux.\nCopyright (C) 2004 Cosmin Truta.\n\nThis code is released under the libpng license.\nFor conditions of distribution and use, see copyright notice in zlib.h.\n\nNOTE: This project will be removed from libpng-1.5.0.  It has\nbeen replaced with the \"vstudio\" project.\n\nTo use:\n\n1) On the main menu, select \"File | Open Solution\".\n   Open \"zlib.sln\".\n\n2) Display the Solution Explorer view (Ctrl+Alt+L)\n\n3) Set one of the project as the StartUp project. If you just want to build the\n   binaries set \"zlib\" as the startup project (Select \"zlib\" tree view item +\n   Project | Set as StartUp project). If you want to build and test the\n   binaries set it to \"example\" (Select \"example\" tree view item + Project |\n   Set as StartUp project), If you want to build the minigzip utility set it to\n   \"minigzip\" (Select \"minigzip\" tree view item + Project | Set as StartUp\n   project\n\n4) Select \"Build | Configuration Manager...\".\n   Choose the configuration you wish to build.\n\n5) Select \"Build | Clean Solution\".\n\n6) Select \"Build | Build Solution (Ctrl-Shift-B)\"\n\nThis project builds the zlib binaries as follows:\n\n* Win32_DLL_Release\\zlib1.dll       DLL build\n* Win32_DLL_Debug\\zlib1d.dll        DLL build (debug version)\n* Win32_LIB_Release\\zlib.lib        static build\n* Win32_LIB_Debug\\zlibd.lib         static build (debug version)\n\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/libpng.sln",
    "content": "Microsoft Visual Studio Solution File, Format Version 8.00\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"libpng\", \"libpng.vcproj\", \"{0008960E-E0DD-41A6-8265-00B31DDB4C21}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0} = {2D4F8105-7D21-454C-9932-B47CAB71A5C0}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pngtest\", \"pngtest.vcproj\", \"{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21} = {0008960E-E0DD-41A6-8265-00B31DDB4C21}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"zlib\", \"zlib.vcproj\", \"{2D4F8105-7D21-454C-9932-B47CAB71A5C0}\"\n\tProjectSection(ProjectDependencies) = postProject\n\tEndProjectSection\nEndProject\nGlobal\n\tGlobalSection(SolutionConfiguration) = preSolution\n\t\tDLL Debug = DLL Debug\n\t\tDLL Release = DLL Release\n\t\tDLL VB = DLL VB\n\t\tLIB Debug = LIB Debug\n\t\tLIB Release = LIB Release\n\tEndGlobalSection\n\tGlobalSection(ProjectConfiguration) = postSolution\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.ActiveCfg = DLL Debug|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Debug.Build.0 = DLL Debug|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.ActiveCfg = DLL Release|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL Release.Build.0 = DLL Release|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.ActiveCfg = DLL VB|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.DLL VB.Build.0 = DLL VB|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.ActiveCfg = LIB Debug|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Debug.Build.0 = LIB Debug|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.ActiveCfg = LIB Release|Win32\n\t\t{0008960E-E0DD-41A6-8265-00B31DDB4C21}.LIB Release.Build.0 = LIB Release|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.ActiveCfg = DLL Debug|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Debug.Build.0 = DLL Debug|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.ActiveCfg = DLL Release|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL Release.Build.0 = DLL Release|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.ActiveCfg = DLL VB|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.DLL VB.Build.0 = DLL VB|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.ActiveCfg = LIB Debug|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Debug.Build.0 = LIB Debug|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.ActiveCfg = LIB Release|Win32\n\t\t{FD1C2F86-9EEF-47BD-95A4-530917E17FDA}.LIB Release.Build.0 = LIB Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.ActiveCfg = DLL Debug|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Debug.Build.0 = DLL Debug|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.ActiveCfg = DLL Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL Release.Build.0 = DLL Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.ActiveCfg = DLL Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.DLL VB.Build.0 = DLL Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.ActiveCfg = LIB Debug|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Debug.Build.0 = LIB Debug|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.ActiveCfg = LIB Release|Win32\n\t\t{2D4F8105-7D21-454C-9932-B47CAB71A5C0}.LIB Release.Build.0 = LIB Release|Win32\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityGlobals) = postSolution\n\tEndGlobalSection\n\tGlobalSection(ExtensibilityAddIns) = postSolution\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/libpng.vcproj",
    "content": "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n<VisualStudioProject\n\tProjectType=\"Visual C++\"\n\tVersion=\"7.10\"\n\tName=\"libpng\"\n\tRootNamespace=\"libpng\">\n\t<Platforms>\n\t\t<Platform\n\t\t\tName=\"Win32\"/>\n\t</Platforms>\n\t<Configurations>\n\t\t<Configuration\n\t\t\tName=\"DLL Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Release\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Release\"\n\t\t\tConfigurationType=\"2\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;PNG_BUILD_DLL;ZLIB_DLL;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"2\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tUsePrecompiledHeader=\"3\"\n\t\t\t\tPrecompiledHeaderThrough=\"pngpriv.h\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/libpng16.dll\"\n\t\t\t\tLinkIncremental=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"\n\t\t\t\tCommandLine=\"copy ..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\pnglibconf.h\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n\t\t\t\tPreprocessorDefinitions=\"NDEBUG\"\n\t\t\t\tCulture=\"1033\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib;$(IntDir)\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"DLL Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Debug\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Debug\"\n\t\t\tConfigurationType=\"2\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;PNG_BUILD_DLL;ZLIB_DLL;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"3\"\n\t\t\t\tUsePrecompiledHeader=\"3\"\n\t\t\t\tPrecompiledHeaderThrough=\"pngpriv.h\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/libpng16d.dll\"\n\t\t\t\tGenerateDebugInformation=\"TRUE\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"\n\t\t\t\tCommandLine=\"copy ..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\pnglibconf.h\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n\t\t\t\tPreprocessorDefinitions=\"_DEBUG,PNG_DEBUG=1\"\n\t\t\t\tCulture=\"1033\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib;$(IntDir)\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"DLL VB|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_VB\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_VB\"\n\t\t\tConfigurationType=\"2\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;PNG_BUILD_DLL;ZLIB_DLL;PNGAPI=__stdcall;PNG_NO_MODULEDEF;PNG_LIBPNG_SPECIALBUILD;PNG_USER_PRIVATEBUILD;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"2\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tUsePrecompiledHeader=\"3\"\n\t\t\t\tPrecompiledHeaderThrough=\"pngpriv.h\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/libpng16vb.dll\"\n\t\t\t\tLinkIncremental=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"\n\t\t\t\tCommandLine=\"copy ..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\pnglibconf.h\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n\t\t\t\tAdditionalOptions=\"/d PNG_NO_PEDANTIC_WARNINGS /d PNG_LIBPNG_DLLFNAME_POSTFIX=&quot;&quot;&quot;&quot;VB&quot;&quot;&quot;&quot; /d PNG_LIBPNG_SPECIALBUILD=&quot;&quot;&quot;&quot;__stdcall calling convention used for exported functions&quot;&quot;&quot;&quot;\"\n\t\t\t\tPreprocessorDefinitions=\"NDEBUG\"\n\t\t\t\tCulture=\"1033\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib;$(IntDir)\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Release\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Release\"\n\t\t\tConfigurationType=\"4\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"0\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tUsePrecompiledHeader=\"3\"\n\t\t\t\tPrecompiledHeaderThrough=\"pngpriv.h\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLibrarianTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/libpng.lib\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"\n\t\t\t\tCommandLine=\"copy ..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\pnglibconf.h\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Debug\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Debug\"\n\t\t\tConfigurationType=\"4\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;DEBUG;PNG_DEBUG=1;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"1\"\n\t\t\t\tUsePrecompiledHeader=\"3\"\n\t\t\t\tPrecompiledHeaderThrough=\"pngpriv.h\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLibrarianTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/libpngd.lib\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"\n\t\t\t\tCommandLine=\"copy ..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\pnglibconf.h\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t</Configurations>\n\t<References>\n\t</References>\n\t<Files>\n\t\t<Filter\n\t\t\tName=\"Source Files\"\n\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\png.c\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Release|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"0\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Debug|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"0\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL VB|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"0\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"0\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"0\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngerror.c\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Release|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Debug|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL VB|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\t\t\tUsePrecompiledHeader=\"1\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngget.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngmem.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngpread.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngread.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngrio.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngrtran.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngrutil.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngset.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngtrans.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngwio.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngwrite.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngwtran.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngwutil.c\">\n\t\t\t</File>\n\t\t</Filter>\n\t\t<Filter\n\t\t\tName=\"Header Files\"\n\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\png.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngconf.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngpriv.h\">\n\t\t\t</File>\n\t\t</Filter>\n\t\t<Filter\n\t\t\tName=\"Resource Files\"\n\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\scripts\\pngwin.rc\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t</Filter>\n\t\t<File\n\t\t\tRelativePath=\".\\PRJ0041.mak\">\n\t\t\t<FileConfiguration\n\t\t\t\tName=\"DLL Release|Win32\">\n\t\t\t\t<Tool\n\t\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\t\tDescription=\"Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings.\"\n\t\t\t\t\tCommandLine=\"nmake -f PRJ0041.mak IntDir=$(IntDir)\"\n\t\t\t\t\tOutputs=\"$(IntDir)\\alloc.h;$(IntDir)\\fp.h;$(IntDir)\\m68881.h;$(IntDir)\\mem.h;$(IntDir)\\pngusr.h;$(IntDir)\\strings.h;$(IntDir)\\unistd.h;$(IntDir)\\unixio.h\"/>\n\t\t\t</FileConfiguration>\n\t\t\t<FileConfiguration\n\t\t\t\tName=\"DLL Debug|Win32\">\n\t\t\t\t<Tool\n\t\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\t\tDescription=\"Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings.\"\n\t\t\t\t\tCommandLine=\"nmake -f PRJ0041.mak IntDir=$(IntDir)\"\n\t\t\t\t\tOutputs=\"$(IntDir)\\alloc.h;$(IntDir)\\fp.h;$(IntDir)\\m68881.h;$(IntDir)\\mem.h;$(IntDir)\\pngusr.h;$(IntDir)\\strings.h;$(IntDir)\\unistd.h;$(IntDir)\\unixio.h\"/>\n\t\t\t</FileConfiguration>\n\t\t\t<FileConfiguration\n\t\t\t\tName=\"DLL VB|Win32\">\n\t\t\t\t<Tool\n\t\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\t\tDescription=\"Create dummy include files to prevent &quot;Cannot find missing dependency...&quot; warnings.\"\n\t\t\t\t\tCommandLine=\"nmake -f PRJ0041.mak IntDir=$(IntDir)\"\n\t\t\t\t\tOutputs=\"$(IntDir)\\alloc.h;$(IntDir)\\fp.h;$(IntDir)\\m68881.h;$(IntDir)\\mem.h;$(IntDir)\\pngusr.h;$(IntDir)\\strings.h;$(IntDir)\\unistd.h;$(IntDir)\\unixio.h\"/>\n\t\t\t</FileConfiguration>\n\t\t</File>\n\t\t<File\n\t\t\tRelativePath=\"README.txt\">\n\t\t</File>\n\t</Files>\n\t<Globals>\n\t</Globals>\n</VisualStudioProject>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/pngtest.vcproj",
    "content": "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n<VisualStudioProject\n\tProjectType=\"Visual C++\"\n\tVersion=\"7.10\"\n\tName=\"pngtest\"\n\tRootNamespace=\"pngtest\">\n\t<Platforms>\n\t\t<Platform\n\t\t\tName=\"Win32\"/>\n\t</Platforms>\n\t<Configurations>\n\t\t<Configuration\n\t\t\tName=\"DLL Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Release\\Test\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Release\\Test\"\n\t\t\tConfigurationType=\"1\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\scripts;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;PNG_DLL;PNG_NO_STDIO;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"2\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\tDescription=\"Testing...\"\n\t\t\t\tCommandLine=\"set path=$(OutDir)\\..;$(OutDir)\\..\\ZLib\n$(TargetPath) ..\\..\\pngtest.png $(IntDir)\\pngout.png\"\n\t\t\t\tOutputs=\"$(IntDir)\\pngout.png\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/pngtest.exe\"\n\t\t\t\tLinkIncremental=\"1\"\n\t\t\t\tSubSystem=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"DLL Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Debug\\Test\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Debug\\Test\"\n\t\t\tConfigurationType=\"1\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\scripts;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;PNG_DLL;PNG_NO_STDIO;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"3\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\tDescription=\"Testing...\"\n\t\t\t\tCommandLine=\"set path=$(OutDir)\\..;$(OutDir)\\..\\ZLib\n$(TargetPath) ..\\..\\pngtest.png $(IntDir)\\pngout.png\"\n\t\t\t\tOutputs=\"$(IntDir)\\pngout.png\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/pngtest.exe\"\n\t\t\t\tGenerateDebugInformation=\"TRUE\"\n\t\t\t\tSubSystem=\"1\"\n\t\t\t\tTargetMachine=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"DLL VB|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_VB\\Test\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_VB\\Test\"\n\t\t\tConfigurationType=\"1\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\scripts;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;PNG_DLL;PNG_NO_STDIO;PNGAPI=__stdcall;PNG_USER_PRIVATEBUILD;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"2\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tWarningLevel=\"2\"\n\t\t\t\tCallingConvention=\"2\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\tDescription=\"Testing...\"\n\t\t\t\tCommandLine=\"set path=$(OutDir)\\..;$(OutDir)\\..\\..\\Win32_DLL_Release\\ZLib\n$(TargetPath) ..\\..\\pngtest.png $(IntDir)\\pngout.png\"\n\t\t\t\tOutputs=\"$(IntDir)\\pngout.png\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/pngtest.exe\"\n\t\t\t\tLinkIncremental=\"1\"\n\t\t\t\tIgnoreDefaultLibraryNames=\"$(IntDir)\\libpng16b.lib\"\n\t\t\t\tSubSystem=\"1\"\n\t\t\t\tTargetMachine=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Release\\Test\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Release\\Test\"\n\t\t\tConfigurationType=\"1\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\scripts;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"0\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\tDescription=\"Testing...\"\n\t\t\t\tCommandLine=\"set path=$(OutDir)\\..;$(OutDir)\\..\\ZLib\n$(TargetPath) ..\\..\\pngtest.png $(IntDir)\\pngout.png\"\n\t\t\t\tOutputs=\"$(IntDir)\\pngout.png\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/pngtest.exe\"\n\t\t\t\tLinkIncremental=\"1\"\n\t\t\t\tSubSystem=\"1\"\n\t\t\t\tTargetMachine=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Debug\\Test\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Debug\\Test\"\n\t\t\tConfigurationType=\"1\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\scripts;..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"1\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"0\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"\n\t\t\t\tDescription=\"Testing...\"\n\t\t\t\tCommandLine=\"set path=$(OutDir)\\..;$(OutDir)\\..\\ZLib\n$(TargetPath) ..\\..\\pngtest.png $(IntDir)\\pngout.png\"\n\t\t\t\tOutputs=\"$(IntDir)\\pngout.png\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)/pngtest.exe\"\n\t\t\t\tGenerateDebugInformation=\"TRUE\"\n\t\t\t\tSubSystem=\"1\"\n\t\t\t\tTargetMachine=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t</Configurations>\n\t<References>\n\t</References>\n\t<Files>\n\t\t<Filter\n\t\t\tName=\"Source Files\"\n\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\pngtest.c\">\n\t\t\t</File>\n\t\t</Filter>\n\t</Files>\n\t<Globals>\n\t</Globals>\n</VisualStudioProject>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/visualc71/zlib.vcproj",
    "content": "<?xml version=\"1.0\" encoding=\"Windows-1252\"?>\n<VisualStudioProject\n\tProjectType=\"Visual C++\"\n\tVersion=\"7.10\"\n\tName=\"zlib\">\n\t<Platforms>\n\t\t<Platform\n\t\t\tName=\"Win32\"/>\n\t</Platforms>\n\t<Configurations>\n\t\t<Configuration\n\t\t\tName=\"DLL Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Release\\ZLib\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Release\\ZLib\"\n\t\t\tConfigurationType=\"2\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"2\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)\\zlib1.dll\"\n\t\t\t\tLinkIncremental=\"1\"\n\t\t\t\tModuleDefinitionFile=\"..\\..\\..\\zlib\\win32\\zlib.def\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n\t\t\t\tPreprocessorDefinitions=\"NDEBUG\"\n\t\t\t\tCulture=\"1033\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"DLL Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_DLL_Debug\\ZLib\"\n\t\t\tIntermediateDirectory=\".\\Win32_DLL_Debug\\ZLib\"\n\t\t\tConfigurationType=\"2\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"3\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLinkerTool\"\n\t\t\t\tOutputFile=\"$(OutDir)\\zlib1d.dll\"\n\t\t\t\tModuleDefinitionFile=\"..\\..\\..\\zlib\\win32\\zlib.def\"\n\t\t\t\tGenerateDebugInformation=\"TRUE\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"\n\t\t\t\tPreprocessorDefinitions=\"_DEBUG\"\n\t\t\t\tCulture=\"1033\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebDeploymentTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Release|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Release\\ZLib\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Release\\ZLib\"\n\t\t\tConfigurationType=\"4\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tInlineFunctionExpansion=\"1\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;NDEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS\"\n\t\t\t\tStringPooling=\"TRUE\"\n\t\t\t\tRuntimeLibrary=\"0\"\n\t\t\t\tEnableFunctionLevelLinking=\"TRUE\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tCompileAs=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLibrarianTool\"\n\t\t\t\tOutputFile=\"$(OutDir)\\zlib.lib\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t\t<Configuration\n\t\t\tName=\"LIB Debug|Win32\"\n\t\t\tOutputDirectory=\".\\Win32_LIB_Debug\\ZLib\"\n\t\t\tIntermediateDirectory=\".\\Win32_LIB_Debug\\ZLib\"\n\t\t\tConfigurationType=\"4\">\n\t\t\t<Tool\n\t\t\t\tName=\"VCCLCompilerTool\"\n\t\t\t\tOptimization=\"0\"\n\t\t\t\tAdditionalIncludeDirectories=\"..\\..\\..\\zlib\"\n\t\t\t\tPreprocessorDefinitions=\"WIN32;_DEBUG;_CRT_SECURE_NO_WARNINGS;_CRT_NONSTDC_NO_WARNINGS\"\n\t\t\t\tBasicRuntimeChecks=\"3\"\n\t\t\t\tRuntimeLibrary=\"1\"\n\t\t\t\tWarningLevel=\"3\"\n\t\t\t\tDebugInformationFormat=\"4\"\n\t\t\t\tCompileAs=\"1\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCLibrarianTool\"\n\t\t\t\tOutputFile=\"$(OutDir)\\zlibd.lib\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCMIDLTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPostBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreBuildEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCPreLinkEventTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCWebServiceProxyGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCXMLDataGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCManagedWrapperGeneratorTool\"/>\n\t\t\t<Tool\n\t\t\t\tName=\"VCAuxiliaryManagedWrapperGeneratorTool\"/>\n\t\t</Configuration>\n\t</Configurations>\n\t<References>\n\t</References>\n\t<Files>\n\t\t<Filter\n\t\t\tName=\"Source Files\"\n\t\t\tFilter=\"cpp;c;cxx;rc;def;r;odl;idl;hpj;bat\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\adler32.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\compress.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\crc32.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\deflate.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\gzlib.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\gzclose.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\gzread.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\gzwrite.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\infback.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inffast.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inflate.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inftrees.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\trees.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\uncompr.c\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\win32\\zlib.def\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\zutil.c\">\n\t\t\t</File>\n\t\t</Filter>\n\t\t<Filter\n\t\t\tName=\"Header Files\"\n\t\t\tFilter=\"h;hpp;hxx;hm;inl\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\crc32.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\deflate.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inffast.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inffixed.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inflate.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\inftrees.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\trees.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\zconf.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\zlib.h\">\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\zutil.h\">\n\t\t\t</File>\n\t\t</Filter>\n\t\t<Filter\n\t\t\tName=\"Resource Files\"\n\t\t\tFilter=\"ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\win32\\zlib1.rc\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCResourceCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t</Filter>\n\t\t<Filter\n\t\t\tName=\"Assembler Files (Unsupported)\"\n\t\t\tFilter=\"asm;obj;c;cpp;cxx;h;hpp;hxx\">\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\contrib\\masmx86\\gvmat32.asm\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\contrib\\masmx86\\gvmat32c.c\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCLCompilerTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t\t<File\n\t\t\t\tRelativePath=\"..\\..\\..\\zlib\\contrib\\masmx86\\inffas32.asm\">\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"DLL Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Release|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t\t<FileConfiguration\n\t\t\t\t\tName=\"LIB Debug|Win32\"\n\t\t\t\t\tExcludedFromBuild=\"TRUE\">\n\t\t\t\t\t<Tool\n\t\t\t\t\t\tName=\"VCCustomBuildTool\"/>\n\t\t\t\t</FileConfiguration>\n\t\t\t</File>\n\t\t</Filter>\n\t\t<File\n\t\t\tRelativePath=\"README.txt\">\n\t\t</File>\n\t</Files>\n\t<Globals>\n\t</Globals>\n</VisualStudioProject>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/libpng/libpng.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{D6973076-9317-4EF2-A0B8-B7A18AC0713E}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>libpng</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <CharacterSet>MultiByte</CharacterSet>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n    <CharacterSet>MultiByte</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>DynamicLibrary</ConfigurationType>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>MultiByte</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n    <CharacterSet>MultiByte</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildBeforeTargets>\n    </CustomBuildBeforeTargets>\n    <TargetName>$(ProjectName)16</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildBeforeTargets />\n    <TargetName>$(ProjectName)16</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildBeforeTargets>\n    </CustomBuildBeforeTargets>\n    <TargetName>$(ProjectName)16</TargetName>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildBeforeTargets />\n    <TargetName>$(ProjectName)16</TargetName>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>\n      <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>\n      <BrowseInformation>true</BrowseInformation>\n      <CompileAs>CompileAsC</CompileAs>\n      <StringPooling>true</StringPooling>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <Optimization>Disabled</Optimization>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>zlib.lib</AdditionalDependencies>\n      <Version>16</Version>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>\n      <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>\n      <BrowseInformation>true</BrowseInformation>\n      <CompileAs>CompileAsC</CompileAs>\n      <StringPooling>true</StringPooling>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>\n      <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>\n      <BrowseInformation>true</BrowseInformation>\n      <CompileAs>CompileAsC</CompileAs>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <Optimization>Full</Optimization>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>zlib.lib</AdditionalDependencies>\n      <Version>16</Version>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>Use</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <TreatWChar_tAsBuiltInType>false</TreatWChar_tAsBuiltInType>\n      <PrecompiledHeaderFile>pngpriv.h</PrecompiledHeaderFile>\n      <BrowseInformation>true</BrowseInformation>\n      <CompileAs>CompileAsC</CompileAs>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <Optimization>Full</Optimization>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n    </ClCompile>\n    <Link>\n      <SubSystem>Windows</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n    <Lib>\n      <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>\n    </Lib>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\..\\..\\png.c\">\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">Create</PrecompiledHeader>\n      <PrecompiledHeader Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">Create</PrecompiledHeader>\n    </ClCompile>\n    <ClCompile Include=\"..\\..\\..\\pngerror.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngget.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngmem.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngpread.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngread.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngrio.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngrtran.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngrutil.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngset.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngtrans.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngwio.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngwrite.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngwtran.c\" />\n    <ClCompile Include=\"..\\..\\..\\pngwutil.c\" />\n  </ItemGroup>\n  <ItemGroup>\n    <ResourceCompile Include=\"..\\..\\..\\scripts\\pngwin.rc\">\n      <ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">true</ExcludedFromBuild>\n      <ExcludedFromBuild Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">true</ExcludedFromBuild>\n    </ResourceCompile>\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/pnglibconf/pnglibconf.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{EB33566E-DA7F-4D28-9077-88C0B7C77E35}</ProjectGuid>\n    <RootNamespace>pnglibconf</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <UseDebugLibraries>false</UseDebugLibraries>\n    <WholeProgramOptimization>true</WholeProgramOptimization>\n    <CharacterSet>MultiByte</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <CustomBuildBeforeTargets>Build</CustomBuildBeforeTargets>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <Optimization>MaxSpeed</Optimization>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n    </ClCompile>\n    <Link>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n    <CustomBuildStep>\n      <Command>copy ..\\..\\..\\scripts\\pnglibconf.h.prebuilt ..\\..\\..\\pnglibconf.h</Command>\n    </CustomBuildStep>\n    <CustomBuildStep>\n      <Message>Generating pnglibconf.h</Message>\n    </CustomBuildStep>\n    <CustomBuildStep>\n      <Outputs>..\\..\\..\\pnglibconf.h</Outputs>\n    </CustomBuildStep>\n    <CustomBuildStep>\n      <Inputs>..\\..\\..\\scripts\\pnglibconf.h.prebuilt</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/pngstest/pngstest.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{277AC57F-313B-4D06-B119-A3CDB672D2FF}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>pngstest</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing libpng simplified API test program</Message>\n      <Command>\"$(OutDir)pngstest.exe\" --strict --log --touch \"$(IntDir)pngstest.out\" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn0g01.png ../../../contrib/pngsuite/ftbbn0g02.png ../../../contrib/pngsuite/ftbbn0g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn0g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n0g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>\n      <Outputs>$(IntDir)pngstest.out</Outputs>\n      <Inputs>$(OutDir)pngstest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing libpng simplified API test program</Message>\n      <Command>\"$(OutDir)pngstest.exe\" --strict --log --touch \"$(IntDir)pngstest.out\" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn0g01.png ../../../contrib/pngsuite/ftbbn0g02.png ../../../contrib/pngsuite/ftbbn0g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn0g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n0g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>\n      <Outputs>$(IntDir)pngstest.out</Outputs>\n      <Inputs>$(OutDir)pngstest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing libpng simplified API test program</Message>\n      <Command>\"$(OutDir)pngstest.exe\" --strict --log --touch \"$(IntDir)pngstest.out\" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn0g01.png ../../../contrib/pngsuite/ftbbn0g02.png ../../../contrib/pngsuite/ftbbn0g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn0g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n0g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>\n      <Outputs>$(IntDir)pngstest.out</Outputs>\n      <Inputs>$(OutDir)pngstest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing libpng simplified API test program</Message>\n      <Command>\"$(OutDir)pngstest.exe\" --strict --log --touch \"$(IntDir)pngstest.out\" ../../../contrib/pngsuite/basn0g01.png ../../../contrib/pngsuite/basn0g02.png ../../../contrib/pngsuite/basn0g04.png ../../../contrib/pngsuite/basn0g08.png ../../../contrib/pngsuite/basn0g16.png ../../../contrib/pngsuite/basn2c08.png ../../../contrib/pngsuite/basn2c16.png ../../../contrib/pngsuite/basn3p01.png ../../../contrib/pngsuite/basn3p02.png ../../../contrib/pngsuite/basn3p04.png ../../../contrib/pngsuite/basn3p08.png ../../../contrib/pngsuite/basn4a08.png ../../../contrib/pngsuite/basn4a16.png ../../../contrib/pngsuite/basn6a08.png ../../../contrib/pngsuite/basn6a16.png ../../../contrib/pngsuite/ftbbn0g01.png ../../../contrib/pngsuite/ftbbn0g02.png ../../../contrib/pngsuite/ftbbn0g04.png ../../../contrib/pngsuite/ftbbn2c16.png ../../../contrib/pngsuite/ftbbn3p08.png ../../../contrib/pngsuite/ftbgn2c16.png ../../../contrib/pngsuite/ftbgn3p08.png ../../../contrib/pngsuite/ftbrn2c08.png ../../../contrib/pngsuite/ftbwn0g16.png ../../../contrib/pngsuite/ftbwn3p08.png ../../../contrib/pngsuite/ftbyn3p08.png ../../../contrib/pngsuite/ftp0n0g08.png ../../../contrib/pngsuite/ftp0n2c08.png ../../../contrib/pngsuite/ftp0n3p08.png ../../../contrib/pngsuite/ftp1n3p08.png</Command>\n      <Outputs>$(IntDir)pngstest.out</Outputs>\n      <Inputs>$(OutDir)pngstest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\..\\..\\contrib\\libtests\\pngstest.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/pngtest/pngtest.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>pngtest</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG test program</Message>\n      <Command>\"$(OutDir)pngtest.exe\" ..\\..\\..\\pngtest.png \"$(IntDir)pngout.png\"</Command>\n      <Outputs>$(IntDir)pngout.png</Outputs>\n      <Inputs>..\\..\\..\\pngtest.png;$(OutDir)pngtest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG test program</Message>\n      <Command>\"$(OutDir)pngtest.exe\" ..\\..\\..\\pngtest.png \"$(IntDir)pngout.png\"</Command>\n      <Outputs>$(IntDir)pngout.png</Outputs>\n      <Inputs>..\\..\\..\\pngtest.png;$(OutDir)pngtest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG test program</Message>\n      <Command>\"$(OutDir)pngtest.exe\" ..\\..\\..\\pngtest.png \"$(IntDir)pngout.png\"</Command>\n      <Outputs>$(IntDir)pngout.png</Outputs>\n      <Inputs>..\\..\\..\\pngtest.png;$(OutDir)pngtest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG test program</Message>\n      <Command>$(OutDir)pngtest.exe ..\\..\\..\\pngtest.png $(IntDir)pngout.png</Command>\n      <Command>\"$(OutDir)pngtest.exe\" ..\\..\\..\\pngtest.png \"$(IntDir)pngout.png\"</Command>\n      <Outputs>$(IntDir)pngout.png</Outputs>\n      <Inputs>..\\..\\..\\pngtest.png;$(OutDir)pngtest.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\..\\..\\pngtest.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/pngunknown/pngunknown.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>pngunknown</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngunknown.exe\" --strict --default --touch \"$(IntDir)pngunknown.out\" ../../../pngtest.png</Command>\n      <Outputs>$(IntDir)pngunknown.out</Outputs>\n      <Inputs>$(OutDir)pngunknown.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngunknown.exe\" --strict --default --touch \"$(IntDir)pngunknown.out\" ../../../pngtest.png</Command>\n      <Outputs>$(IntDir)pngunknown.out</Outputs>\n      <Inputs>$(OutDir)pngunknown.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngunknown.exe\" --strict --default --touch \"$(IntDir)pngunknown.out\" ../../../pngtest.png</Command>\n      <Outputs>$(IntDir)pngunknown.out</Outputs>\n      <Inputs>$(OutDir)pngunknown.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngunknown.exe\" --strict --default --touch \"$(IntDir)pngunknown.out\" ../../../pngtest.png</Command>\n      <Outputs>$(IntDir)pngunknown.out</Outputs>\n      <Inputs>$(OutDir)pngunknown.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\..\\..\\contrib\\libtests\\pngunknown.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/pngvalid/pngvalid.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>pngvalid</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>Application</ConfigurationType>\n    <CharacterSet>Unicode</CharacterSet>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Label=\"PropertySheets\" Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>false</LinkIncremental>\n    <CustomBuildAfterTargets />\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngvalid.exe\" --touch \"$(IntDir)pngvalid.out\"</Command>\n      <Outputs>$(IntDir)pngvalid.out</Outputs>\n      <Inputs>$(OutDir)pngvalid.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <MinimalRebuild>false</MinimalRebuild>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <StringPooling>true</StringPooling>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <BrowseInformation>true</BrowseInformation>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngvalid.exe\" --touch \"$(IntDir)pngvalid.out\"</Command>\n      <Outputs>$(IntDir)pngvalid.out</Outputs>\n      <Inputs>$(OutDir)pngvalid.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;PNG_USE_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngvalid.exe\" --touch \"$(IntDir)pngvalid.out\"</Command>\n      <Outputs>$(IntDir)pngvalid.out</Outputs>\n      <Inputs>$(OutDir)pngvalid.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <PrecompiledHeader>NotUsing</PrecompiledHeader>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <FunctionLevelLinking>false</FunctionLevelLinking>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <AdditionalIncludeDirectories>$(ZLibSrcDir);..\\..\\..\\scripts;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings)</DisableSpecificWarnings>\n      <CompileAsManaged>false</CompileAsManaged>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <StringPooling>true</StringPooling>\n      <MinimalRebuild>false</MinimalRebuild>\n      <BrowseInformation>true</BrowseInformation>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <FloatingPointExceptions>false</FloatingPointExceptions>\n    </ClCompile>\n    <Link>\n      <SubSystem>Console</SubSystem>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n      <AdditionalDependencies>libpng16.lib;zlib.lib</AdditionalDependencies>\n      <AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>\n      <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>\n    </Link>\n    <CustomBuildStep>\n      <Message>Executing PNG validation program</Message>\n      <Command>\"$(OutDir)pngvalid.exe\" --touch \"$(IntDir)pngvalid.out\"</Command>\n      <Outputs>$(IntDir)pngvalid.out</Outputs>\n      <Inputs>$(OutDir)pngvalid.exe</Inputs>\n    </CustomBuildStep>\n  </ItemDefinitionGroup>\n  <ItemGroup>\n    <ClCompile Include=\"..\\..\\..\\contrib\\libtests\\pngvalid.c\" />\n  </ItemGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/readme.txt",
    "content": "\nVisualStudio instructions\n\nlibpng version 1.6.25 - September 1, 2016\n\nCopyright (c) 2010,2013,2015 Glenn Randers-Pehrson\n\nThis code is released under the libpng license.\nFor conditions of distribution and use, see the disclaimer\nand license in png.h\n\nThis directory  contains support for building libpng under MicroSoft\nVisualStudio 2010.  It may also work under later versions of VisualStudio.\nYou should be familiar with VisualStudio before using this directory.\n\nInitial preparations\n====================\nYou must enter some information in zlib.props before attempting to build\nwith this 'solution'.  Please read and edit zlib.props first.  You will\nprobably not be familiar with the contents of zlib.props - do not worry,\nit is mostly harmless.\n\nThis is all you need to do to build the 'release' and 'release library'\nconfigurations.\n\nDebugging\n=========\nThe release configurations default to /Ox optimization.  Full debugging\ninformation is produced (in the .pdb), but if you encounter a problem the\noptimization may make it difficult to debug.  Simply rebuild with a lower\noptimization level (e.g. /Od.)\n\nLinking your application\n========================\nNormally you should link against the 'release' configuration.  This builds a\nDLL for libpng with the default runtime options used by Visual Studio 2010.\nIn particular the runtime library is the \"MultiThreaded DLL\" version.\nIf you use Visual Studio defaults to build your application you will have no\nproblems.\n\nIf you don't use the Visual Studio defaults your application must still be\nbuilt with the default runtime option (/MD).  If, for some reason, it is not\nthen your application will crash inside libpng16.dll as soon as libpng\ntries to read from a file handle you pass in.\n\nIf you do not want to use the DLL, for example for a very small application,\nthe 'release library' configuration may be more appropriate.  This is built\nwith a non-standard runtime library - the \"MultiThreaded\" version.  When you\nbuild your application it must be compiled with this option (/MT), otherwise\nit will not build (if you are lucky) or crash (if you are not.) See the\nWARNING file that is distributed along with this readme.txt.\n\nStop reading here\n=================\nYou have enough information to build a working application.\n\nDebug versions have limited support\n===================================\nThis solution includes limited support for debug versions of libpng.  You\ndo not need these unless your own solution itself uses debug builds (it is\nfar more effective to debug on the release builds, there is no point building\na special debug build unless you have heap corruption problems that you can't\ntrack down.)\n\nThe debug build of libpng is minimally supported.  Support for debug builds of\nzlib is also minimal.  You really don't want to do this.\n\nWARNING\n=======\nLibpng 1.6.x does not use the default run-time library when building static\nlibrary builds of libpng; instead of the shared DLL runtime it uses a static\nruntime.  If you need to change this make sure to change the setting on all the\nrelevant projects:\n\n    libpng\n    zlib\n    all the test programs\n\nThe runtime library settings for each build are as follows:\n\n               Release        Debug\n    DLL         /MD            /MDd\n    Library     /MT            /MTd\n\nNOTICE that libpng 1.5.x erroneously used /MD for Debug DLL builds; if you used\nthe debug builds in your app and you changed your app to use /MD you will need\nto change it back to /MDd for libpng 1.6.0 and later.\n\nThe Visual Studio 2010 defaults for a Win32 DLL or Static Library project are\nas follows:\n\n                     Release     Debug\n    DLL               /MD         /MDd\n    Static Library    /MD         /MDd\n\nAlso, be sure to build libpng, zlib, and your project all for the same\nplatform (e.g., 32-bit or 64-bit).\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/vstudio.sln",
    "content": "Microsoft Visual Studio Solution File, Format Version 11.00\n# Visual Studio 2010\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"zlib\", \"zlib\\zlib.vcxproj\", \"{60F89955-91C6-3A36-8000-13C592FEC2DF}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pnglibconf\", \"pnglibconf\\pnglibconf.vcxproj\", \"{EB33566E-DA7F-4D28-9077-88C0B7C77E35}\"\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"libpng\", \"libpng\\libpng.vcxproj\", \"{D6973076-9317-4EF2-A0B8-B7A18AC0713E}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pngtest\", \"pngtest\\pngtest.vcxproj\", \"{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pngvalid\", \"pngvalid\\pngvalid.vcxproj\", \"{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pngstest\", \"pngstest\\pngstest.vcxproj\", \"{277AC57F-313B-4D06-B119-A3CDB672D2FF}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}\n\tEndProjectSection\nEndProject\nProject(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"pngunknown\", \"pngunknown\\pngunknown.vcxproj\", \"{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}\"\n\tProjectSection(ProjectDependencies) = postProject\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF} = {60F89955-91C6-3A36-8000-13C592FEC2DF}\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35} = {EB33566E-DA7F-4D28-9077-88C0B7C77E35}\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E} = {D6973076-9317-4EF2-A0B8-B7A18AC0713E}\n\tEndProjectSection\nEndProject\nGlobal\n\tGlobalSection(SolutionConfigurationPlatforms) = preSolution\n\t\tDebug Library|Win32 = Debug Library|Win32\n\t\tDebug|Win32 = Debug|Win32\n\t\tRelease Library|Win32 = Release Library|Win32\n\t\tRelease|Win32 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(ProjectConfigurationPlatforms) = postSolution\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{D6973076-9317-4EF2-A0B8-B7A18AC0713E}.Release|Win32.Build.0 = Release|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{228BA965-50D5-42B2-8BCF-AFCC227E3C1D}.Release|Win32.Build.0 = Release|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{60F89955-91C6-3A36-8000-13C592FEC2DF}.Release|Win32.Build.0 = Release|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{9B36B6FE-7FC0-434F-A71F-BBEF8099F1D8}.Release|Win32.Build.0 = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug Library|Win32.ActiveCfg = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug Library|Win32.Build.0 = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug|Win32.ActiveCfg = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Debug|Win32.Build.0 = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release Library|Win32.ActiveCfg = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release Library|Win32.Build.0 = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{EB33566E-DA7F-4D28-9077-88C0B7C77E35}.Release|Win32.Build.0 = Release|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{277AC57F-313B-4D06-B119-A3CDB672D2FF}.Release|Win32.Build.0 = Release|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug Library|Win32.ActiveCfg = Debug Library|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug Library|Win32.Build.0 = Debug Library|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug|Win32.ActiveCfg = Debug|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Debug|Win32.Build.0 = Debug|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release Library|Win32.ActiveCfg = Release Library|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release Library|Win32.Build.0 = Release Library|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release|Win32.ActiveCfg = Release|Win32\n\t\t{C5D3156C-8C8C-4936-B35F-2B829BA36FEC}.Release|Win32.Build.0 = Release|Win32\n\tEndGlobalSection\n\tGlobalSection(SolutionProperties) = preSolution\n\t\tHideSolutionNode = FALSE\n\tEndGlobalSection\nEndGlobal\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/zlib/zlib.vcxproj",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<Project DefaultTargets=\"Build\" ToolsVersion=\"4.0\" xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <ItemGroup Label=\"ProjectConfigurations\">\n    <ProjectConfiguration Include=\"Debug Library|Win32\">\n      <Configuration>Debug Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Debug|Win32\">\n      <Configuration>Debug</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release Library|Win32\">\n      <Configuration>Release Library</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n    <ProjectConfiguration Include=\"Release|Win32\">\n      <Configuration>Release</Configuration>\n      <Platform>Win32</Platform>\n    </ProjectConfiguration>\n  </ItemGroup>\n  <ItemGroup>\n    <ClCompile Include=\"$(ZLibSrcDir)\\adler32.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\compress.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\crc32.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\deflate.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\infback.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\inffast.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\inflate.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\inftrees.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\trees.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\uncompr.c\" />\n    <ClCompile Include=\"$(ZLibSrcDir)\\zutil.c\" />\n  </ItemGroup>\n  <PropertyGroup Label=\"Globals\">\n    <ProjectGuid>{60F89955-91C6-3A36-8000-13C592FEC2DF}</ProjectGuid>\n    <Keyword>Win32Proj</Keyword>\n    <RootNamespace>zlib</RootNamespace>\n  </PropertyGroup>\n  <Import Project=\"$(SolutionDir)\\zlib.props\" />\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.Default.props\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"Configuration\">\n    <ConfigurationType>StaticLibrary</ConfigurationType>\n  </PropertyGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.props\" />\n  <ImportGroup Label=\"ExtensionSettings\">\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" />\n  </ImportGroup>\n  <ImportGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\" Label=\"PropertySheets\">\n    <Import Project=\"$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props\" Condition=\"exists('$(UserRootDir)\\Microsoft.Cpp.$(Platform).user.props')\" Label=\"LocalAppDataPlatform\" />\n  </ImportGroup>\n  <PropertyGroup Label=\"UserMacros\" />\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <PropertyGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <LinkIncremental>true</LinkIncremental>\n  </PropertyGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug Library|Win32'\">\n    <ClCompile>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;Z_SOLO;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BrowseInformation>true</BrowseInformation>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings);4127;4131;4242;4244</DisableSpecificWarnings>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n    </ClCompile>\n    <Link>\n      <TargetMachine>MachineX86</TargetMachine>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <SubSystem>Windows</SubSystem>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Debug|Win32'\">\n    <ClCompile>\n      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;Z_SOLO;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Disabled</Optimization>\n      <BrowseInformation>true</BrowseInformation>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings);4127;4131;4242;4244</DisableSpecificWarnings>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>\n    </ClCompile>\n    <Link>\n      <TargetMachine>MachineX86</TargetMachine>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <SubSystem>Windows</SubSystem>\n    </Link>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release Library|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <BufferSecurityCheck>false</BufferSecurityCheck>\n      <BrowseInformation>true</BrowseInformation>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings);4127;4131;4242;4244</DisableSpecificWarnings>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;Z_SOLO;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n    </ClCompile>\n    <Link>\n      <TargetMachine>MachineX86</TargetMachine>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <SubSystem>Windows</SubSystem>\n    </Link>\n    <Lib>\n      <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>\n    </Lib>\n  </ItemDefinitionGroup>\n  <ItemDefinitionGroup Condition=\"'$(Configuration)|$(Platform)'=='Release|Win32'\">\n    <ClCompile>\n      <WarningLevel>$(WarningLevel)</WarningLevel>\n      <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\n      <Optimization>Full</Optimization>\n      <IntrinsicFunctions>true</IntrinsicFunctions>\n      <WholeProgramOptimization>true</WholeProgramOptimization>\n      <BufferSecurityCheck>false</BufferSecurityCheck>\n      <BrowseInformation>true</BrowseInformation>\n      <FunctionLevelLinking>true</FunctionLevelLinking>\n      <DisableSpecificWarnings>$(DisableSpecificWarnings);4127;4131;4242;4244</DisableSpecificWarnings>\n      <TreatWarningAsError>$(TreatWarningAsError)</TreatWarningAsError>\n      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;Z_SOLO;%(PreprocessorDefinitions)</PreprocessorDefinitions>\n    </ClCompile>\n    <Link>\n      <TargetMachine>MachineX86</TargetMachine>\n      <GenerateDebugInformation>true</GenerateDebugInformation>\n      <SubSystem>Windows</SubSystem>\n      <EnableCOMDATFolding>true</EnableCOMDATFolding>\n      <OptimizeReferences>true</OptimizeReferences>\n    </Link>\n    <Lib>\n      <LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>\n    </Lib>\n  </ItemDefinitionGroup>\n  <Import Project=\"$(VCTargetsPath)\\Microsoft.Cpp.targets\" />\n  <ImportGroup Label=\"ExtensionTargets\">\n  </ImportGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/projects/vstudio/zlib.props",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<!--\n * zlib.props - location of zlib source\n *\n * libpng version 1.6.25 - September 1, 2016\n *\n * Copyright (c) 1998-2011 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n\n * You must edit this file to record the location of the zlib\n * source code.\n -->\n\n<Project ToolsVersion=\"4.0\"\n   xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\">\n  <PropertyGroup Label=\"Globals\">\n    <!-- Place the name of the directory containing the source of zlib used for\n\t debugging in this property.\n\n         The directory need only contain the '.c' and '.h' files from the\n\t source.\n\n\t If you use a relative directory name (as below) then it must be\n\t relative to the project directories; these are one level deeper than\n\t the directories containing this file.\n\n\t If the version of zlib you use does not match that used when the\n\t distribution was built you will get warnings from pngtest that the zlib\n\t versions do not match.  The zlib version used in this build is recorded\n\t below:\n     -->\n    <ZLibSrcDir>..\\..\\..\\..\\zlib-1.2.8</ZLibSrcDir>\n\n    <!-- The following line allows compilation for an ARM target with Visual\n         Studio 2012.  Notice that this is not supported by the Visual Studio\n         2012 IDE and that the programs that result cannot be run unless they\n         signed by Microsoft.  This is therefore untested; only Microsoft can\n         test it:\n     -->\n    <WindowsSDKDesktopARMSupport>true</WindowsSDKDesktopARMSupport>\n\n    <!-- The following lines provide a global (solution level) control of the\n         warnings issued by the compiler, these are used in the individual\n         project files (*/*.vcxproj) with, for zlib, some extra disables.\n\n         Different versions of Visual Studio may require different settings,\n         these settings work with Visual Studio 2013.  Just set\n         TreatWarningAsError to false to check the build without failing on\n         errors.\n     -->\n   <WarningLevel>EnableAllWarnings</WarningLevel>\n   <TreatWarningAsError>true</TreatWarningAsError>\n   <DisableSpecificWarnings>4255;4668;4710;4711;4746;4820;4996</DisableSpecificWarnings>\n  </PropertyGroup>\n</Project>\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/README.txt",
    "content": "\nMakefiles for  libpng version 1.6.25 - September 1, 2016\n\npnglibconf.h.prebuilt       =>  Stores configuration settings\n makefile.linux    =>  Linux/ELF makefile\n                       (gcc, creates libpng16.so.16.1.6.25)\n makefile.gcc      =>  Generic makefile (gcc, creates static libpng.a)\n makefile.knr      =>  Archaic UNIX Makefile that converts files with\n                       ansi2knr (Requires ansi2knr.c from\n                       ftp://ftp.cs.wisc.edu/ghost)\n makefile.acorn    =>  Acorn makefile\n makefile.aix      =>  AIX/gcc makefile\n makefile.amiga    =>  Amiga makefile\n makefile.atari    =>  Atari makefile\n makefile.bc32     =>  32-bit Borland C++ (all modules compiled in C mode)\n makefile.beos     =>  beos makefile\n makefile.bor      =>  Borland makefile (uses bcc)\n makefile.cegcc    =>  minge32ce for Windows CE makefile\n makefile.darwin   =>  Darwin makefile, can use on MacosX\n makefile.dec      =>  DEC Alpha UNIX makefile\n makefile.dj2      =>  DJGPP 2 makefile\n makefile.freebsd  =>  FreeBSD makefile\n makefile.gcc      =>  Generic gcc makefile\n makefile.hpgcc    =>  HPUX makefile using gcc\n makefile.hpux     =>  HPUX (10.20 and 11.00) makefile\n makefile.hp64     =>  HPUX (10.20 and 11.00) makefile, 64-bit\n makefile.ibmc     =>  IBM C/C++ version 3.x for Win32 and OS/2 (static)\n makefile.intel    =>  Intel C/C++ version 4.0 and later\n makefile.mips     =>  MIPS makefile\n makefile.msc      =>  Microsoft C makefile\n makefile.netbsd   =>  NetBSD/cc makefile, makes libpng.so.\n makefile.openbsd  =>  OpenBSD makefile\n makefile.os2      =>  OS/2 Makefile (gcc and emx, requires libpng.def)\n makefile.sco      =>  For SCO OSr5  ELF and Unixware 7 with Native cc\n makefile.sggcc    =>  Silicon Graphics (gcc,\n                       creates libpng16.so.16.1.6.25)\n makefile.sgi      =>  Silicon Graphics IRIX makefile (cc, creates static lib)\n makefile.solaris  =>  Solaris 2.X makefile (gcc,\n                       creates libpng16.so.16.1.6.25)\n makefile.so9      =>  Solaris 9 makefile (gcc,\n                       creates libpng16.so.16.1.6.25)\n makefile.std      =>  Generic UNIX makefile (cc, creates static libpng.a)\n makefile.sunos    =>  Sun makefile\n makefile.32sunu   =>  Sun Ultra 32-bit makefile\n makefile.64sunu   =>  Sun Ultra 64-bit makefile\n makefile.tc3      =>  Turbo C 3.0 makefile\n makefile.vcwin32  =>  makefile for Microsoft Visual C++ 4.0 and later\n makevms.com       =>  VMS build script\n smakefile.ppc     =>  AMIGA smakefile for SAS C V6.58/7.00 PPC compiler\n                       (Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)\n\nOther supporting scripts:\n README.txt        =>  This file\n descrip.mms       =>  VMS makefile for MMS or MMK\n libpng-config-body.in => used by several makefiles to create libpng-config\n libpng-config-head.in => used by several makefiles to create libpng-config\n libpng.pc.in      =>  Used by several makefiles to create libpng.pc\n pngwin.rc         =>  Used by the visualc71 project.\n pngwin.def        =>  Used by makefile.os2\n pngwin.dfn        =>  Used to maintain pngwin.def\n SCOPTIONS.ppc     =>  Used with smakefile.ppc\n\n checksym.awk       =>  Used for maintaining pnglibconf.h\n def.dfn            =>  Used for maintaining pnglibconf.h\n options.awk        =>  Used for maintaining pnglibconf.h\n pnglibconf.dfa     =>  Used for maintaining pnglibconf.h\n pnglibconf.mak     =>  Used for maintaining pnglibconf.h\n sym.dfn            =>  Used for symbol versioning\n symbols.def        =>  Used for symbol versioning\n symbols.dfn        =>  Used for symbol versioning\n vers.dfn           =>  Used for symbol versioning\n\n libtool.m4        =>  Used by autoconf tools\n ltoptions.m4      =>  Used by autoconf tools\n ltsugar.m4        =>  Used by autoconf tools\n ltversion.m4      =>  Used by autoconf tools\n lt~obsolete.m4    =>  Used by autoconf tools\n\n intprefix.dfn     =>  Used by autoconf tools\n macro.lst         =>  Used by autoconf tools\n prefix.dfn        =>  Used by autoconf tools\n\n\nFurther information can be found in comments in the individual makefiles.\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/SCOPTIONS.ppc",
    "content": "OPTIMIZE\nOPTPEEP\nOPTTIME\nOPTSCHED\nAUTOREGISTER\nPARMS=REGISTERS\nINCLUDEDIR=hlp:ppc/include\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/checksym.awk",
    "content": "#!/bin/awk -f\n# Check a list of symbols against the master definition\n# (official) list.  Arguments:\n#\n# awk -f checksym.awk official-def list-to-check\n#\n# Output is a file in the current directory called 'symbols.new',\n# the value of the awk variable \"of\" (which can be changed on the\n# command line if required.)  stdout holds error messages.  Error\n# code indicates success or failure.\n#\n# NOTE: this is a pure, old fashioned, awk script.  It will\n# work with any awk\n\nBEGIN{\n   err=0\n   master=\"\"        # master file\n   official[1] = \"\" # defined symbols from master file\n   symbol[1] = \"\"   # defined symbols from png.h\n   removed[1] = \"\"  # removed symbols from png.h\n   lasto = 0        # last ordinal value from png.h\n   mastero = 0      # highest ordinal in master file\n   symbolo = 0      # highest ordinal in png.h\n   missing = \"error\"# log an error on missing symbols\n   of=\"symbols.new\" # default to a fixed name\n}\n\n# Read existing definitions from the master file (the first\n# file on the command line.)  This must be a def file and it\n# has definition lines (others are ignored) of the form:\n#\n#   symbol @ordinal\n#\nmaster == \"\" {\n   master = FILENAME\n}\nFILENAME==master && NF==2 && $2~/^@/ && $1!~/^;/ {\n   o=0+substr($2,2)\n   if (o > 0) {\n      if (official[o] == \"\") {\n         official[o] = $1\n         if (o > mastero) mastero = o\n         next\n      } else\n         print master \": duplicated symbol:\", official[o] \":\", $0\n   } else\n      print master \": bad export line format:\", $0\n   err = 1\n}\nFILENAME==master && $1==\";missing\" && NF==2{\n   # This allows the master file to control how missing symbols\n   # are handled; symbols that aren't in either the master or\n   # the new file.  Valid values are 'ignore', 'warning' and\n   # 'error'\n   missing = $2\n}\nFILENAME==master {\n   next\n}\n\n# Read new definitions, these are free form but the lines must\n# just be symbol definitions.  Lines will be commented out for\n# 'removed' symbols, introduced in png.h using PNG_REMOVED rather\n# than PNG_EXPORT.  Use symbols.dfn or pngwin.dfn to generate the\n# input file.\n#\n#  symbol @ordinal   # two fields, exported symbol\n#  ; symbol @ordinal # three fields, removed symbol\n#  ; @ordinal        # two fields, the last ordinal\nNF==2 && $1 == \";\" && $2 ~ /^@[1-9][0-9]*$/ { # last ordinal\n   o=0+substr($2,2)\n   if (lasto == 0 || lasto == o)\n      lasto=o\n   else {\n      print \"png.h: duplicated last ordinal:\", lasto, o\n      err = 1\n   }\n   next\n}\nNF==3 && $1 == \";\" && $3 ~ /^@[1-9][0-9]*$/ { # removed symbol\n   o=0+substr($3,2)\n   if (removed[o] == \"\" || removed[o] == $2) {\n      removed[o] = $2\n      if (o > symbolo) symbolo = o\n   } else {\n      print \"png.h: duplicated removed symbol\", o \": '\" removed[o] \"' != '\" $2 \"'\"\n      err = 1\n   }\n   next\n}\nNF==2 && $2 ~ /^@[1-9][0-9]*$/ { # exported symbol\n   o=0+substr($2,2)\n   if (symbol[o] == \"\" || symbol[o] == $1) {\n      symbol[o] = $1\n      if (o > symbolo) symbolo = o\n   } else {\n      print \"png.h: duplicated symbol\", o \": '\" symbol[o] \"' != '\" $1 \"'\"\n      err = 1\n   }\n}\n{\n   next # skip all other lines\n}\n\n# At the end check for symbols marked as both duplicated and removed\nEND{\n   if (symbolo > lasto) {\n      print \"highest symbol ordinal in png.h,\", symbolo \", exceeds last ordinal from png.h\", lasto\n      err = 1\n   }\n   if (mastero > lasto) {\n      print \"highest symbol ordinal in\", master \",\", mastero \", exceeds last ordinal from png.h\", lasto\n      err = 1\n   }\n   unexported=0\n   # Add a standard header to symbols.new:\n   print \";Version INSERT-VERSION-HERE\" >of\n   print \";--------------------------------------------------------------\" >of\n   print \"; LIBPNG symbol list as a Win32 DEF file\" >of\n   print \"; Contains all the symbols that can be exported from libpng\" >of\n   print \";--------------------------------------------------------------\" >of\n   print \"LIBRARY\" >of\n   print \"\" >of\n   print \"EXPORTS\" >of\n\n   for (o=1; o<=lasto; ++o) {\n      if (symbol[o] == \"\" && removed[o] == \"\") {\n         if (unexported == 0) unexported = o\n         if (official[o] == \"\") {\n            # missing in export list too, so ok\n            if (o < lasto) continue\n         }\n      }\n      if (unexported != 0) {\n         # Symbols in the .def but not in the new file are errors, but\n         # the 'unexported' symbols aren't in either.  By default this\n         # is an error too (see the setting of 'missing' at the start),\n         # but this can be reset on the command line or by stuff in the\n         # file - see the comments above.\n         if (missing != \"ignore\") {\n            if (o-1 > unexported)\n               print \"png.h:\", missing \": missing symbols:\", unexported \"-\" o-1\n            else\n               print \"png.h:\", missing \": missing symbol:\", unexported\n            if (missing != \"warning\")\n               err = 1\n         }\n         unexported = 0\n      }\n      if (symbol[o] != \"\" && removed[o] != \"\") {\n         print \"png.h: symbol\", o, \"both exported as '\" symbol[o] \"' and removed as '\" removed[o] \"'\"\n         err = 1\n      } else if (symbol[o] != official[o]) {\n         # either the symbol is missing somewhere or it changed\n         err = 1\n         if (symbol[o] == \"\")\n            print \"png.h: symbol\", o, \"is exported as '\" official[o] \"' in\", master\n         else if (official[o] == \"\")\n            print \"png.h: exported symbol\", o, \"'\" symbol[o] \"' not present in\", master\n         else\n            print \"png.h: exported symbol\", o, \"'\" symbol[o] \"' exists as '\" official[o] \"' in\", master\n      }\n\n      # Finally generate symbols.new\n      if (symbol[o] != \"\")\n         print \" \" symbol[o], \"@\" o > of\n   }\n\n   if (err != 0) {\n      print \"*** A new list is in\", of, \"***\"\n      exit 1\n   }\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/def.c",
    "content": "/* def.c - define format of libpng.def\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2011-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* Write the export file header: */\nPNG_DFN \";--------------------------------------------------------------\"\nPNG_DFN \"; LIBPNG module definition file for OS/2\"\nPNG_DFN \";--------------------------------------------------------------\"\nPNG_DFN \"\"\nPNG_DFN \"; If you give the library an explicit name one or other files\"\nPNG_DFN \"; may need modifying to support the new name on one or more\"\nPNG_DFN \"; systems.\"\nPNG_DFN \"LIBRARY\"\nPNG_DFN \"OS2 DESCRIPTION \"PNG image compression library\"\"\nPNG_DFN \"OS2 CODE PRELOAD MOVEABLE DISCARDABLE\"\nPNG_DFN \"\"\nPNG_DFN \"EXPORTS\"\nPNG_DFN \";Version 1.6.25\"\n\n#define PNG_EXPORTA(ordinal, type, name, args, attributes)\\\n        PNG_DFN \"@\" SYMBOL_PREFIX \"@@\" name \"@\"\n\n#include \"../png.h\"\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/descrip.mms",
    "content": "\ncc_defs = /inc=$(ZLIBSRC)\nc_deb =\n\n.ifdef __DECC__\npref = /prefix=all\n.endif\n\n\n\nOBJS = png.obj, pngset.obj, pngget.obj, pngrutil.obj, pngtrans.obj,\\\n\tpngwutil.obj, pngread.obj, pngmem.obj, pngwrite.obj, pngrtran.obj,\\\n\tpngwtran.obj, pngrio.obj, pngwio.obj, pngerror.obj, pngpread.obj\n\n\nCFLAGS= $(C_DEB) $(CC_DEFS) $(PREF)\n\nall : pngtest.exe libpng.olb\n\t\t@ write sys$output \" pngtest available\"\n\nlibpng.olb : libpng.olb($(OBJS))\n\t@ write sys$output \" Libpng available\"\n\n\npngtest.exe : pngtest.obj libpng.olb\n              link pngtest,libpng.olb/lib,$(ZLIBSRC)libz.olb/lib\n\ntest : pngtest.exe\n   run pngtest\n\nclean :\n\tdelete *.obj;*,*.exe;\n\n\n# Other dependencies.\npng.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngpread.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngset.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngget.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngread.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngrtran.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngrutil.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngerror.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngmem.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngrio.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngwio.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngtrans.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngwrite.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngwtran.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\npngwutil.obj : png.h, pngconf.h, pnglibconf.h, pngpriv.h, pngstruct.h,pnginfo.h, pngdebug.h\n\npngtest.obj : png.h, pngconf.h, pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/dfn.awk",
    "content": "#!/bin/awk -f\n# scripts/dfn.awk - process a .dfn file\n#\n# last changed in libpng version 1.5.19 - August 21, 2014\n#\n# Copyright (c) 2013-2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# The output of this script is written to the file given by\n# the variable 'out', which should be set on the command line.\n# Error messages are printed to stdout and if any are printed\n# the script will exit with error code 1.\n\nBEGIN{\n   out=\"/dev/null\"       # as a flag\n   out_count=0           # count of output lines\n   err=0                 # set if an error occurred\n   sort=0                # sort the output\n   array[\"\"]=\"\"\n}\n\n# The output file must be specified before any input:\nNR==1 && out == \"/dev/null\" {\n   print \"out=output.file must be given on the command line\"\n   # but continue without setting the error code; this allows the\n   # script to be checked easily\n}\n\n# Output can be sorted; two lines are recognized\n$1 == \"PNG_DFN_START_SORT\"{\n   sort=0+$2\n   next\n}\n\n$1 ~ /^PNG_DFN_END_SORT/{\n   # Do a very simple, slow, sort; notice that blank lines won't be\n   # output by this\n   for (entry in array) {\n      while (array[entry] != \"\") {\n         key = entry\n         value = array[key]\n         array[key] = \"\"\n\n         for (alt in array) {\n            if (array[alt] != \"\" && alt < key) {\n               array[key] = value\n               value = array[alt]\n               key = alt\n               array[alt] = \"\"\n            }\n         }\n\n         print value >out\n      }\n   }\n   sort=0\n   next\n}\n\n/^[^\"]*PNG_DFN *\".*\"[^\"]*$/{\n   # A definition line, apparently correctly formatted; extract the\n   # definition then replace any doubled \"\" that remain with a single\n   # double quote.  Notice that the original doubled double quotes\n   # may have been split by tokenization\n   #\n   # Sometimes GCC splits the PNG_DFN lines; we know this has happened\n   # if the quotes aren't closed and must read another line.  In this\n   # case it is essential to reject lines that start with '#' because those\n   # are introduced #line directives.\n   orig=$0\n   line=$0\n   lineno=FNR\n   if (lineno == \"\") lineno=NR\n\n   if (sub(/^[^\"]*PNG_DFN *\"/,\"\",line) != 1) {\n\tprint \"line\", lineno \": processing failed:\"\n\tprint orig\n\terr=1\n       next\n   } else {\n\t++out_count\n   }\n\n   # Now examine quotes within the value:\n   #\n   #   @\" - delete this and any following spaces\n   #   \"@ - delete this and any preceding spaces\n   #   @' - replace this by a double quote\n   #\n   # This allows macro substitution by the C compiler thus:\n   #\n   #   #define first_name John\n   #   #define last_name Smith\n   #\n   #\tPNG_DFN\"#define name @'@\" first_name \"@ @\" last_name \"@@'\"\n   #\n   # Might get C preprocessed to:\n   #\n   #   PNG_DFN \"#define foo @'@\" John \"@ @\" Smith \"@@'\"\n   #\n   # Which this script reduces to:\n   #\n   #\t#define name \"John Smith\"\n   #\n   while (1) {\n      # While there is an @\" remove it and the next \"@\n      if (line ~ /@\"/) {\n         if (line ~ /@\".*\"@/) {\n            # Do this special case first to avoid swallowing extra spaces\n            # before or after the @ stuff:\n            if (!sub(/@\" *\"@/, \"\", line)) {\n               # Ok, do it in pieces - there has to be a non-space between the\n               # two.  NOTE: really weird things happen if a leading @\" is\n               # lost - the code will error out below (I believe).\n               if (!sub(/@\" */, \"\", line) || !sub(/ *\"@/, \"\", line)) {\n                  print \"line\", lineno, \": internal error:\", orig\n                  exit 1\n               }\n            }\n         }\n\n         # There is no matching \"@.  Assume a split line\n         else while (1) {\n            if (getline nextline) {\n               # If the line starts with '#' it is a preprocesor line directive\n               # from cc -E; skip it:\n               if (nextline !~ /^#/) {\n                  line = line \" \" nextline\n                  break\n               }\n            } else {\n               # This is end-of-input - probably a missing \"@ on the first line:\n               print \"line\", lineno \": unbalanced @\\\" ... \\\"@ pair\"\n               err=1\n               next\n            }\n         }\n\n         # Keep going until all the @\" have gone\n         continue\n      }\n\n      # Attempt to remove a trailing \" (not preceded by '@') - if this can\n      # be done, stop now; if not assume a split line again\n      if (sub(/\"[^\"]*$/, \"\", line))\n         break\n\n      # Read another line\n      while (1) {\n         if (getline nextline) {\n            if (nextline !~ /^#/) {\n               line = line \" \" nextline\n               # Go back to stripping @\" \"@ pairs\n               break\n            }\n         } else {\n            print \"line\", lineno \": unterminated PNG_DFN string\"\n            err=1\n            next\n         }\n      }\n   }\n\n   # Put any needed double quotes in (at the end, because these would otherwise\n   # interfere with the processing above.)\n   gsub(/@'/,\"\\\"\", line)\n\n   # Remove any trailing spaces (not really required, but for\n   # editorial consistency\n   sub(/ *$/, \"\", line)\n\n   # Remove trailing CR\n   sub(/\r$/, \"\", line)\n\n   if (sort) {\n      if (split(line, parts) < sort) {\n         print \"line\", lineno \": missing sort field:\", line\n         err=1\n      } else\n         array[parts[sort]] = line\n   }\n\n   else\n      print line >out\n   next\n}\n\n/PNG_DFN/{\n   print \"line\", NR, \"incorrectly formatted PNG_DFN line:\"\n   print $0\n   err = 1\n}\n\nEND{\n   if (out_count > 0 || err > 0)\n\texit err\n\n   print \"no definition lines found\"\n   exit 1\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/genchk.cmake.in",
    "content": "# genchk.cmake.in\n# Generate .chk from .out with awk (generic), based upon the automake logic.\n\n# Copyright (C) 2016 Glenn Randers-Pehrson\n# Written by Roger Leigh, 2016\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Variables substituted from CMakeLists.txt\nset(SRCDIR \"@CMAKE_CURRENT_SOURCE_DIR@\")\n\nset(AWK \"@AWK@\")\n\nget_filename_component(INPUTEXT \"${INPUT}\" EXT)\nget_filename_component(OUTPUTEXT \"${OUTPUT}\" EXT)\nget_filename_component(INPUTBASE \"${INPUT}\" NAME_WE)\nget_filename_component(OUTPUTBASE \"${OUTPUT}\" NAME_WE)\nget_filename_component(INPUTDIR \"${INPUT}\" PATH)\nget_filename_component(OUTPUTDIR \"${OUTPUT}\" PATH)\n\nif(\"${INPUTEXT}\" STREQUAL \".out\" AND \"${OUTPUTEXT}\" STREQUAL \".chk\")\n  # Generate .chk from .out with awk (generic)\n  file(REMOVE \"${OUTPUT}\" \"${OUTPUTDIR}/${OUTPUTBASE}.new\")\n  execute_process(COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/checksym.awk\"\n                          \"${SRCDIR}/scripts/${INPUTBASE}.def\"\n                          \"of=${OUTPUTDIR}/${OUTPUTBASE}.new\"\n                          \"${INPUT}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate ${OUTPUTDIR}/${OUTPUTBASE}.new\")\n  endif()\n  file(RENAME \"${OUTPUTDIR}/${OUTPUTBASE}.new\" \"${OUTPUT}\")\nelse()\n  message(FATAL_ERROR \"Unsupported conversion: ${INPUTEXT} to ${OUTPUTEXT}\")\nendif()\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/genout.cmake.in",
    "content": "# genout.cmake.in\n# Generate .out from .c with awk (generic), based upon the automake logic.\n\n# Copyright (C) 2016 Glenn Randers-Pehrson\n# Written by Roger Leigh, 2016\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Variables substituted from CMakeLists.txt\nset(SRCDIR \"@CMAKE_CURRENT_SOURCE_DIR@\")\nset(BINDIR \"@CMAKE_CURRENT_BINARY_DIR@\")\n\nset(AWK \"@AWK@\")\nset(CMAKE_C_COMPILER \"@CMAKE_C_COMPILER@\")\nset(CMAKE_C_FLAGS @CMAKE_C_FLAGS@)\nset(INCDIR \"@CMAKE_CURRENT_BINARY_DIR@\")\nset(PNG_PREFIX \"@PNG_PREFIX@\")\nset(PNGLIB_MAJOR \"@PNGLIB_MAJOR@\")\nset(PNGLIB_MINOR \"@PNGLIB_MINOR@\")\nset(PNGLIB_VERSION \"@PNGLIB_VERSION@\")\nset(ZLIBINCDIR \"@ZLIB_INCLUDE_DIR@\")\n\nset(PLATFORM_C_FLAGS)\nif(APPLE)\n  set(CMAKE_OSX_ARCHITECTURES \"@CMAKE_OSX_ARCHITECTURES@\")\n  set(CMAKE_OSX_SYSROOT \"@CMAKE_OSX_SYSROOT@\")\n  if(CMAKE_OSX_ARCHITECTURES)\n    set(PLATFORM_C_FLAGS ${PLATFORM_C_FLAGS} -arch ${CMAKE_OSX_ARCHITECTURES})\n  endif()\n  if(CMAKE_OSX_SYSROOT)\n    set(PLATFORM_C_FLAGS ${PLATFORM_C_FLAGS} -isysroot ${CMAKE_OSX_SYSROOT})\n  endif()\nendif()\n\nget_filename_component(INPUTEXT \"${INPUT}\" EXT)\nget_filename_component(OUTPUTEXT \"${OUTPUT}\" EXT)\nget_filename_component(INPUTBASE \"${INPUT}\" NAME_WE)\nget_filename_component(OUTPUTBASE \"${OUTPUT}\" NAME_WE)\nget_filename_component(INPUTDIR \"${INPUT}\" PATH)\nget_filename_component(OUTPUTDIR \"${OUTPUT}\" PATH)\n\nif (\"${INPUTEXT}\" STREQUAL \".c\" AND \"${OUTPUTEXT}\" STREQUAL \".out\")\n  get_filename_component(GENDIR \"${OUTPUT}\" PATH)\n  file(MAKE_DIRECTORY \"${GENDIR}\")\n\n  file(REMOVE \"${OUTPUT}.tf1\" \"${OUTPUT}.tf2\")\n\n  set(INCLUDES \"-I${INCDIR}\")\n  if(ZLIBINCDIR)\n    foreach(dir ${ZLIBINCDIR})\n      list(APPEND INCLUDES \"-I${dir}\")\n    endforeach()\n  endif()\n\n  if(PNG_PREFIX)\n    set(PNG_PREFIX_DEF \"-DPNG_PREFIX=${PNG_PREFIX}\")\n  endif()\n\n  execute_process(COMMAND \"${CMAKE_C_COMPILER}\" \"-E\"\n                          ${CMAKE_C_FLAGS}\n                          ${PLATFORM_C_FLAGS}\n                          \"-I${SRCDIR}\"\n                          \"-I${BINDIR}\"\n                          ${INCLUDES}\n                          \"-DPNGLIB_LIBNAME=PNG${PNGLIB_MAJOR}${PNGLIB_MINOR}_0\"\n                          \"-DPNGLIB_VERSION=${PNGLIB_VERSION}\"\n                          \"-DSYMBOL_PREFIX=${SYMBOL_PREFIX}\"\n                          \"-DPNG_NO_USE_READ_MACROS\"\n                          \"-DPNG_BUILDING_SYMBOL_TABLE\"\n                          ${PNG_PREFIX_DEF}\n                          \"${INPUT}\"\n                  OUTPUT_FILE \"${OUTPUT}.tf1\"\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE CPP_FAIL)\n  if(CPP_FAIL)\n    message(FATAL_ERROR \"Failed to generate ${OUTPUT}.tf1\")\n  endif()\n\n  execute_process(COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/dfn.awk\"\n                          \"out=${OUTPUT}.tf2\" \"${OUTPUT}.tf1\"\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate ${OUTPUT}.tf2\")\n  endif()\n\n  file(REMOVE \"${OUTPUT}.tf1\")\n  file(RENAME \"${OUTPUT}.tf2\" \"${OUTPUT}\")\nelse()\n  message(FATAL_ERROR \"Unsupported conversion: ${INPUTEXT} to ${OUTPUTEXT}\")\nendif()\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/gensrc.cmake.in",
    "content": "# gensrc.cmake.in\n# Generate source files with awk, based upon the automake logic.\n\n# Copyright (C) 2016 Glenn Randers-Pehrson\n# Written by Roger Leigh, 2016\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Variables substituted from CMakeLists.txt\nset(SRCDIR \"@CMAKE_CURRENT_SOURCE_DIR@\")\nset(BINDIR \"@CMAKE_CURRENT_BINARY_DIR@\")\n\nset(AWK \"@AWK@\")\nset(DFA_XTRA \"@DFA_XTRA@\")\nset(PNG_PREFIX \"@PNG_PREFIX@\")\nset(PNGLIB_VERSION \"@PNGLIB_VERSION@\")\n\nif(\"${OUTPUT}\" STREQUAL \"scripts/pnglibconf.c\")\n  # Generate scripts/pnglibconf.c\n\n  file(REMOVE \"${BINDIR}/pnglibconf.tf6\" \"${BINDIR}/pnglibconf.tf7\")\n\n  execute_process(COMMAND \"${CMAKE_COMMAND}\" -E echo \"com ${PNGLIB_VERSION} STANDARD API DEFINITION\"\n                  COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/options.awk\"\n                          \"out=pnglibconf.tf6\" \"logunsupported=1\" \"version=search\"\n                          \"${SRCDIR}/pngconf.h\" \"-\"\n                          \"${SRCDIR}/scripts/pnglibconf.dfa\"\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate pnglibconf.tf6\")\n  endif()\n\n  execute_process(COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/options.awk\"\n                  \"out=pnglibconf.tf7\" \"pnglibconf.tf6\"\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate pnglibconf.tf7\")\n  endif()\n\n  file(REMOVE \"pnglibconf.tf6\")\n  file(MAKE_DIRECTORY \"${BINDIR}/scripts\")\n  file(RENAME \"pnglibconf.tf7\" \"${BINDIR}/scripts/pnglibconf.c\")\n\nelseif (\"${OUTPUT}\" STREQUAL \"pnglibconf.c\")\n  # Generate pnglibconf.c\n\n  file(REMOVE \"${BINDIR}/pnglibconf.tf4\" \"${BINDIR}/pnglibconf.tf5\")\n\n  execute_process(COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/options.awk\"\n                  out=pnglibconf.tf4 version=search\n                  ${SRCDIR}/pngconf.h ${SRCDIR}/scripts/pnglibconf.dfa\n                  ${SRCDIR}/pngusr.dfa ${DFA_XTRA}\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate pnglibconf.tf4\")\n  endif()\n\n  execute_process(COMMAND \"${AWK}\" -f \"${SRCDIR}/scripts/options.awk\"\n                  out=pnglibconf.tf5 pnglibconf.tf4\n                  WORKING_DIRECTORY \"${BINDIR}\"\n                  RESULT_VARIABLE AWK_FAIL)\n  if(AWK_FAIL)\n    message(FATAL_ERROR \"Failed to generate pnglibconf.tf5\")\n  endif()\n\n  file(REMOVE \"pnglibconf.tf4\")\n  file(MAKE_DIRECTORY \"${BINDIR}/scripts\")\n  file(RENAME \"pnglibconf.tf5\" \"${BINDIR}/pnglibconf.c\")\n\nelseif (\"${OUTPUT}\" STREQUAL \"pnglibconf.h\")\n  # Generate pnglibconf.h\n\n  file(REMOVE \"${BINDIR}/${OUTPUT}\")\n  if(PNG_PREFIX)\n    file(REMOVE \"pnglibconf.tf8\")\n\n    execute_process(COMMAND \"${AWK}\" \"s==0 && NR>1{print prev}\n                             s==0{prev=\\$0}\n                             s==1{print \\\"#define\\\", \\$1, \\\"${PNG_PREFIX}\\\" \\$1}\n                             s==2{print \\\"#define ${PNG_PREFIX}png_\\\" \\$1, \\\"PNG_\\\" \\$1}\n                             END{print prev}\" s=0 pnglibconf.out s=1 \"${BINDIR}/scripts/prefix.out\"\n                             s=2 \"${SRCDIR}/scripts/macro.lst\"\n                    OUTPUT_FILE pnglibconf.tf8\n                    RESULT_VARIABLE AWK_FAIL)\n    if(AWK_FAIL)\n      message(FATAL_ERROR \"Failed to generate pnglibconf.tf8\")\n    endif()\n\n    file(RENAME \"pnglibconf.tf8\" \"${BINDIR}/${OUTPUT}\")\n  else()\n    execute_process(COMMAND \"${CMAKE_COMMAND}\" -E copy \"${BINDIR}/pnglibconf.out\"\n                                                       \"${BINDIR}/${OUTPUT}\"\n                    RESULT_VARIABLE COPY_FAIL)\n    if(COPY_FAIL)\n      message(FATAL_ERROR \"Failed to create pnglibconf.h\")\n    endif()\n  endif()\n\nelseif (\"${OUTPUT}\" STREQUAL \"pngprefix.h\")\n  # Generate pngprefix.h\n\n  file(REMOVE \"${BINDIR}/${OUTPUT}\")\n\n  if(PNG_PREFIX)\n    file(REMOVE \"pngprefix.tf1\")\n\n    execute_process(COMMAND \"${AWK}\"\n                            \"{print \\\"#define\\\", \\$1, \\\"${PNG_PREFIX}\\\" \\$1}\"\n                            \"${BINDIR}/scripts/intprefix.out\"\n                    OUTPUT_FILE \"pngprefix.tf1\"\n                    RESULT_VARIABLE AWK_FAIL)\n    if(AWK_FAIL)\n      message(FATAL_ERROR \"Failed to generate pngprefix.tf1\")\n    endif()\n\n    file(RENAME \"pngprefix.tf1\" \"${BINDIR}/${OUTPUT}\")\n  else()\n    file(WRITE \"${BINDIR}/${OUTPUT}\" \"/* No libpng symbol prefix configured. */\")\n  endif()\n\nelseif(\"${OUTPUT}\" STREQUAL \"scripts/pnglibconf.h.prebuilt\")\n  # Generate scripts/pnglibconf.h.prebuilt (fails build)\n\n  message(STATUS \"Attempting to build scripts/pnglibconf.h.prebuilt\")\n  message(STATUS \"This is a machine generated file, but if you want to make\")\n  message(STATUS \"a new one simply build the 'genfiles' target, and copy\")\n  message(STATUS \"scripts/pnglibconf.out to scripts/pnglibconf.h.prebuilt\")\n  message(STATUS \"AND set PNG_ZLIB_VERNUM to 0 (you MUST do this)\")\n  message(FATAL_ERROR \"Stopping build\")\n\nelse()\n  message(FATAL_ERROR \"Unsupported output: ${OUTPUT}\")\nendif()\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/intprefix.c",
    "content": "\n/* intprefix.c - generate an unprefixed internal symbol list\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2013-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#define PNG_INTERNAL_DATA(type, name, array)\\\n        PNG_DFN \"@\" name \"@\"\n\n#define PNG_INTERNAL_FUNCTION(type, name, args, attributes)\\\n        PNG_DFN \"@\" name \"@\"\n\n#define PNG_INTERNAL_CALLBACK(type, name, args, attributes)\\\n        PNG_DFN \"@\" name \"@\"\n\n#define PNGPREFIX_H /* self generation */\n#include \"../pngpriv.h\"\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/libpng-config-body.in",
    "content": "\nusage()\n{\n    cat <<EOF\nUsage: libpng-config [OPTION] ...\n\nKnown values for OPTION are:\n\n  --prefix        print libpng prefix\n  --libdir        print path to directory containing library\n  --libs          print library linking information\n  --ccopts        print compiler options\n  --cppflags      print pre-processor flags\n  --cflags        print preprocessor flags, I_opts, and compiler options\n  --I_opts        print \"-I\" include options\n  --L_opts        print linker \"-L\" flags for dynamic linking\n  --R_opts        print dynamic linker \"-R\" or \"-rpath\" flags\n  --ldopts        print linker options\n  --ldflags       print linker flags (ldopts, L_opts, R_opts, and libs)\n  --static        revise subsequent outputs for static linking\n  --help          print this help and exit\n  --version       print version information\nEOF\n\n    exit $1\n}\n\nif test $# -eq 0; then\n    usage 1\nfi\n\nwhile test $# -gt 0; do\n    case \"$1\" in\n\n    --prefix)\n        echo ${prefix}\n        ;;\n\n    --version)\n        echo ${version}\n        exit 0\n        ;;\n\n    --help)\n        usage 0\n        ;;\n\n    --ccopts)\n        echo ${ccopts}\n        ;;\n\n    --cppflags)\n        echo ${cppflags}\n        ;;\n\n    --cflags)\n        echo ${I_opts} ${cppflags} ${ccopts}\n        ;;\n\n    --libdir)\n        echo ${libdir}\n        ;;\n\n    --libs)\n        echo ${libs}\n        ;;\n\n    --I_opts)\n        echo ${I_opts}\n        ;;\n\n    --L_opts)\n        echo ${L_opts}\n        ;;\n\n    --R_opts)\n        echo ${R_opts}\n        ;;\n\n    --ldflags)\n        echo ${ldflags} ${L_opts} ${R_opts} ${libs}\n        ;;\n\n    --static)\n        R_opts=\"\"\n        ;;\n\n    *)\n        usage\n        exit 1\n        ;;\n    esac\n    shift\ndone\n\nexit 0\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/libpng-config-head.in",
    "content": "#! /bin/sh\n\n# libpng-config\n# provides configuration info for libpng.\n\n# Copyright (C) 2002 Glenn Randers-Pehrson\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Modeled after libxml-config.\n\nversion=1.6.25\nprefix=\"\"\nlibdir=\"\"\nlibs=\"\"\nI_opts=\"\"\nL_opts=\"\"\nR_opts=\"\"\ncppflags=\"\"\nccopts=\"\"\nldopts=\"\"\n\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/libpng.pc.in",
    "content": "prefix=@prefix@\nexec_prefix=@exec_prefix@\nlibdir=@libdir@\nincludedir=@includedir@/libpng16\n\nName: libpng\nDescription: Loads and saves PNG files\nVersion: 1.6.25\nLibs: -L${libdir} -lpng16\nCflags: -I${includedir}\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/macro.lst",
    "content": "get_uint_32(buf)\nget_uint_16(buf)\nget_int_32(buf)\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.32sunu",
    "content": "# makefile for libpng on Solaris 2.x with cc\n# Contributed by William L. Sebok, based on makefile.linux\n# Copyright (C) 2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1998 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME=libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nCC=cc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=echo\nRM_F=/bin/rm -f\n\nSUN_CC_FLAGS=-fast -xtarget=ultra\nSUN_LD_FLAGS=-fast -xtarget=ultra\n\n# where make install puts libpng.a, libpng16.so and libpng16/png.h\nprefix=/a\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n# Changing these to ../zlib poses a security risk.  If you want\n# to have zlib in an adjacent directory, specify the full path instead of \"..\".\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\n\nZLIBLIB=/usr/lib\nZLIBINC=/usr/include\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=$(SUN_CC_FLAGS) # $(WARNMORE) -g\nLDFLAGS=$(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) libpng.a -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -KPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\ninclude scripts/pnglibconf.mak\nDELETE = $(RM_F)\nDFNFLAGS = $(DEFS) $(CPPFLAGS)\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo libdir=\\\"$(LIBPATH)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-R$(LIBPATH)\\\"; \\\n\techo ccopts=\\\"-fast -xtarget=ultra\\\"; \\\n\techo ldopts=\\\"-fast -xtarget=ultra\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t@case \"`type ld`\" in *ucb*) \\\n\techo; \\\n\techo '## WARNING:'; \\\n\techo '## The commands \"CC\" and \"LD\" must NOT refer to /usr/ucb/cc'; \\\n\techo '## and /usr/ucb/ld.  If they do, you need to adjust your PATH'; \\\n\techo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \\\n\techo '## The environment variable LD_LIBRARY_PATH should not be set'; \\\n\techo '## at all.  If it is, things are likely to break because of'; \\\n\techo '## the libucb dependency that is created.'; \\\n\techo; \\\n\t;; \\\n\tesac\n\t$(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \\\n\t -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) $(SUN_CC_FLAGS) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(SUN_CC_FLAGS) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.64sunu",
    "content": "# makefile for libpng on Solaris 2.x with cc\n# Contributed by William L. Sebok, based on makefile.linux\n# Copyright (C) 2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1998 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME=libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nCC=cc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=echo\nRM_F=/bin/rm -f\n\nSUN_CC_FLAGS=-fast -xtarget=ultra -xarch=v9\nSUN_LD_FLAGS=-fast -xtarget=ultra -xarch=v9\n\n# where make install puts libpng.a, libpng16.so and libpng16/png.h\nprefix=/a\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n# Changing these to ../zlib poses a security risk.  If you want\n# to have zlib in an adjacent directory, specify the full path instead of \"..\".\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\n\nZLIBLIB=/usr/lib\nZLIBINC=/usr/include\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS= $(SUN_CC_FLAGS) # $(WARNMORE) -g\nLDFLAGS=-L. -R. $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -KPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\ninclude scripts/pnglibconf.mak\nDELETE = $(RM_F)\nDFNFLAGS = $(DEFS) $(CPPFLAGS)\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo libdir=\\\"$(LIBPATH)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-R$(LIBPATH)\\\"; \\\n\techo ccopts=\\\"-fast -xtarget=ultra -xarch=v9\\\"; \\\n\techo ldopts=\\\"-fast -xtarget=ultra -xarch=v9\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t@case \"`type ld`\" in *ucb*) \\\n\techo; \\\n\techo '## WARNING:'; \\\n\techo '## The commands \"CC\" and \"LD\" must NOT refer to /usr/ucb/cc'; \\\n\techo '## and /usr/ucb/ld.  If they do, you need to adjust your PATH'; \\\n\techo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \\\n\techo '## The environment variable LD_LIBRARY_PATH should not be set'; \\\n\techo '## at all.  If it is, things are likely to break because of'; \\\n\techo '## the libucb dependency that is created.'; \\\n\techo; \\\n\t;; \\\n\tesac\n\t$(LD) -G -L$(ZLIBLIB) -R$(ZLIBLIB) -h $(LIBSOMAJ) \\\n\t -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) $(SUN_CC_FLAGS) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtestd -L$(DL) -R$(DL) `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(SUN_CC_FLAGS) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   $(SUN_LD_FLAGS) -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.acorn",
    "content": "# Project:   libpng\n\n\n# Toolflags:\nCCflags = -c -depend !Depend -IC:,Zlib: -g -throwback  -DRISCOS  -fnah\nC++flags = -c -depend !Depend -IC: -throwback\nLinkflags = -aif -c++ -o $@\nObjAsmflags = -throwback -NoCache -depend !Depend\nCMHGflags =\nLibFileflags = -c -l -o $@\nSqueezeflags = -o $@\n\n# Final targets:\n@.libpng-lib:   @.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \\\n\t@.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \\\n\t@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil\n\tLibFile $(LibFileflags) @.o.png @.o.pngerror @.o.pngrio @.o.pngrtran \\\n\t@.o.pngmem @.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngwio \\\n\t@.o.pngrutil @.o.pngtrans  @.o.pngwrite @.o.pngwtran @.o.pngwutil\n@.mm-libpng-lib:   @.mm.png @.mm.pngerror @.mm.pngrio @.mm.pngwio @.mm.pngmem \\\n\t@.mm.pngpread @.mm.pngset @.mm.pngget @.mm.pngread @.mm.pngrtran \\\n\t@.mm.pngrutil @.mm.pngtrans @.mm.pngwrite @.mm.pngwtran @.mm.pngwutil\n\tLibFile $(LibFileflags) @.mm.png @.mm.pngerror @.mm.pngrio \\\n\t@.mm.pngwio @.mm.pngmem @.mm.pngpread @.mm.pngset @.mm.pngget \\\n\t@.mm.pngread @.mm.pngrtran @.mm.pngrutil @.mm.pngtrans @.mm.pngwrite \\\n\t@.mm.pngwtran @.mm.pngwutil\n\n\n# User-editable dependencies:\n# (C) Copyright 1997 Tom Tanner\nTest: @.pngtest\n\t<Prefix$Dir>.pngtest\n\t@remove <Prefix$Dir>.pngtest\n\n#It would be nice if you could stop \"make\" listing from here on!\n@.pngtest:   @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib\n\tLink $(Linkflags) @.o.pngtest @.libpng-lib C:o.Stubs Zlib:zlib_lib\n\n.SUFFIXES: .o .mm .c\n\n.c.mm:\n\tMemCheck.CC cc $(ccflags) -o $@ LibPng:$<\n.c.o:\n\tcc $(ccflags) -o $@ $<\n\n# See scripts.mak.libpngconf for how to generate this:\n@.h.libpngconf: @.scripts.h.libpngconf\n\tcopy @.scripts.h.libpngconf $@\n\n# Static dependencies:\n@.o.png @.o.pngerror @.o.pngrio @.o.pngwio @.o.pngmem \\\n@.o.pngpread @.o.pngset @.o.pngget @.o.pngread @.o.pngrtran \\\n@.o.pngrutil @.o.pngtrans @.o.pngwrite @.o.pngwtran @.o.pngwutil \\\n@.o.pngtest: @.h.libpngconf\n\n\n# Dynamic dependencies:\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.aix",
    "content": "# makefile for libpng using gcc (generic, static library)\n# Copyright (C) 2002, 2006-2009, 2014 Glenn Randers-Pehrson\n# Copyright (C) 2000 Cosmin Truta\n# Copyright (C) 2000 Marc O. Gloor (AIX support added, from makefile.gcc)\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Location of the zlib library and include files\nZLIBINC = ../zlib\nZLIBLIB = ../zlib\n\n# Compiler, linker, lib and other tools\nCC = gcc\nLD = $(CC)\nAR_RC = ar rcs\nMKDIR_P = mkdir -p\nRANLIB = ranlib\nRM_F = rm -f\nLN_SF = ln -f -s\n\nLIBNAME = libpng16\nPNGMAJ = 16\n\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\n\nWARNMORE =\nCPPFLAGS = -I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS = -W -Wall -O2 # $(WARNMORE) -g\nLDFLAGS = -L. -L$(ZLIBLIB) -lpng16 -lz -lm\n\n# Variables\nOBJS =  png.o pngerror.o pngget.o pngmem.o pngpread.o \\\n\tpngread.o pngrio.o pngrtran.o pngrutil.o pngset.o \\\n\tpngtrans.o pngwio.o pngwrite.o pngwtran.o pngwutil.o\n\n# Targets\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: $(LIBNAME).a pngtest$(E)\n\ninclude scripts/pnglibconf.mak\nREMOVE = $(RM_F)\nDFNFLAGS = $(DEFS) $(CPPFLAGS)\n\n$(LIBNAME).a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\ntest: pngtest$(E)\n\t./pngtest$(E)\n\npngtest$(E): pngtest.o $(LIBNAME).a\n\t$(LD) -o $@ pngtest.o $(LDFLAGS)\n\ninstall: $(LIBNAME).a\n\t-@if [ ! -d $(DI)  ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME)  ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DI)/$(LIBNAME)/png.h\n\t-@$(RM_F) $(DI)/$(LIBNAME)/pngconf.h\n\t-@$(RM_F) $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h\n\t-@$(RM_F) $(DI)/pngconf.h\n\t-@$(RM_F) $(DI)/pnglibconf.h\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h \\\n\t$(DI)/$(LIBNAME)/pngconf.h \\\n\t$(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) -r $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\t-@$(RM_F) $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\tcp $(LIBNAME).a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\t(cd $(DI); $(LN_SF) libpng/* .;)\n\nclean:\n\t$(RM_F) *.o $(LIBNAME).a pngtest pngout.png pnglibconf.h\n\npng.o:      png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o:  png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o:  png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.amiga",
    "content": "# Commodore Amiga Makefile\n# makefile for libpng and SAS C V6.5x compiler\n# Copyright (C) 1995-2000 Wolf Faust\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Location/path of zlib include files\nZLIB=/zlib\n#compiler\nCC=sc\n#compiler flags\n# WARNING: a bug in V6.51 causes bad code with OPTGO\n#          So use V6.55 or set NOOPTGO!!!!!!!!!\nCFLAGS= NOSTKCHK PARMS=REG OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL\\\n\tOPTLOOP OPTRDEP=4 OPTDEP=4 OPTCOMP=4 INCLUDEDIR=$(ZLIB) \\\n\tDEFINE=PNG_INTERNAL\n#linker flags\nLDFLAGS= SD ND BATCH\n#link libs\nLDLIBS= libpng.lib libgz.lib LIB:scm.lib LIB:sc.lib Lib:amiga.lib\n# linker\nLN= slink\n# file deletion command\nRM= delete quiet\n# library (.lib) file creation command\nAR= oml\n# make directory command\nMKDIR= makedir\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nall: libpng.lib pngtest\n\nlibpng.lib: $(OBJS)\n-$(RM) libpng.lib\n$(AR) libpng.lib r $(OBJS)\n\n$(OBJS): pngpriv.h png.h pngconf.h pnglibconf.h pnginfo.h pngstruct.h pngdebug.h\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\nCOPY $(PNGLIBCONF_H_PREBUILT) TO pnglibconf.h\n\npngtest: pngtest.o libpng.lib\n$(LN) <WITH <\n$(LDFLAGS)\nTO pngtest\nFROM LIB:c.o pngtest.o\nLIB $(LDLIBS)\n<\n\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.atari",
    "content": "# makefile for libpng\n# Copyright (C) 2002, 2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Modified for LC56/ATARI assumes libz.lib is in same dir and uses default\n# rules for library management\n#\nCPPFLAGS = -I..\\zlib\nCFLAGS = -O\nLBR = png.lib\nLDFLAGS = -L. -L..\\zlib -lpng -lz -lm\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = $(LBR)(png.o) $(LBR)(pngset.o) $(LBR)(pngget.o) $(LBR)(pngrutil.o)\\\n\t$(LBR)(pngtrans.o) $(LBR)(pngwutil.o)\\\n\t$(LBR)(pngread.o) $(LBR)(pngerror.o) $(LBR)(pngwrite.o)\\\n\t$(LBR)(pngrtran.o) $(LBR)(pngwtran.o)\\\n\t$(LBR)(pngmem.o) $(LBR)(pngrio.o) $(LBR)(pngwio.o) $(LBR)(pngpread.o)\n\nall: $(LBR) pngtest.ttp\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\n$(LBR): $(OBJS)\n\n$(OBJS): pngpriv.h png.h pngconf.h pnglibconf.h pnginfo.h pngstruct.h pngdebug.h\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\tcp $(PNGLIBCONF_H_PREBUILT) $@\n\npngtest.ttp: pngtest.o $(LBR)\n\t$(CC) $(CFLAGS) $(LDFLAGS) -o$@ pngtest.o\n\ninstall: libpng.a\n\t-@mkdir $(DESTDIR)$(INCPATH)\n\t-@mkdir $(DESTDIR)$(INCPATH)/libpng\n\t-@mkdir $(DESTDIR)$(LIBPATH)\n\t-@rm -f $(DESTDIR)$(INCPATH)/png.h\n\t-@rm -f $(DESTDIR)$(INCPATH)/pngconf.h\n\t-@rm -f $(DESTDIR)$(INCPATH)/pnglibconf.h\n\tcp png.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pngconf.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h\n\t(cd $(DESTDIR)$(INCPATH); ln -f -s $(LIBNAME) libpng; \\\n\tln -f -s $(LIBNAME)/* .)\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.bc32",
    "content": "# Makefile for libpng\n# 32-bit Borland C++ (Note: All modules are compiled in C mode)\n# To build the library, do:\n#       \"make -fmakefile.bc32\"\n#\n# -------------------- 32-bit Borland C++ --------------------\n\n### Absolutely necessary for this makefile to work\n.AUTODEPEND\n\n## Where zlib.h, zconf.h and zlib.lib are\nZLIB_DIR=..\\zlib\n\n## Compiler, linker, librarian and other tools\nCC=bcc32\nLD=bcc32\nLIB=tlib\nCP=copy\n\n# -3 = 386, -4 = 486, -5 = Pentium etc.\n!ifndef TARGET_CPU\n#TARGET_CPU=-6\n!endif\n\n# Use this if you don't want Borland's fancy exception handling\n# (Caution: doesn't work with CBuilderX)\n#NOEHLIB=noeh32.lib\n\n!ifdef DEBUG\nCDEBUG=-v\nLDEBUG=-v\n!else\nCDEBUG=\nLDEBUG=\n!endif\n\n# STACKOFLOW=1\n!ifdef STACKOFLOW\nCDEBUG=$(CDEBUG) -N\nLDEBUG=$(LDEBUG) -N\n!endif\n\n# -O2 optimize for speed\n# -d  merge duplicate strings\n# -k- turn off standard stack frame\n# -w  display all warnings\nCPPFLAGS=-I$(ZLIB_DIR)\nCFLAGS=-O2 -d -k- -w $(TARGET_CPU) $(CDEBUG)\n\n# -M  generate map file\nLDFLAGS=-L$(ZLIB_DIR) -M $(LDEBUG)\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\n!ifndef PNGLIBCONF_H_PREBUILT\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n!endif\n\n## Variables\nOBJS = \\\n\tpng.obj \\\n\tpngerror.obj \\\n\tpngget.obj \\\n\tpngmem.obj \\\n\tpngpread.obj \\\n\tpngread.obj \\\n\tpngrio.obj \\\n\tpngrtran.obj \\\n\tpngrutil.obj \\\n\tpngset.obj \\\n\tpngtrans.obj \\\n\tpngwio.obj \\\n\tpngwrite.obj \\\n\tpngwtran.obj \\\n\tpngwutil.obj\n\nLIBOBJS = \\\n\t+png.obj \\\n\t+pngerror.obj \\\n\t+pngget.obj \\\n\t+pngmem.obj \\\n\t+pngpread.obj \\\n\t+pngread.obj \\\n\t+pngrio.obj \\\n\t+pngrtran.obj \\\n\t+pngrutil.obj \\\n\t+pngset.obj \\\n\t+pngtrans.obj \\\n\t+pngwio.obj \\\n\t+pngwrite.obj \\\n\t+pngwtran.obj \\\n\t+pngwutil.obj\n\nLIBNAME=libpng.lib\n\n## Implicit rules\n# Braces let make \"batch\" calls to the compiler,\n# 2 calls instead of 12; space is important.\n.c.obj:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) -c {$*.c }\n\n.c.exe:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $*.c \\\n\t  $(LIBNAME) zlib.lib $(NOEHLIB)\n\n.obj.exe:\n\t$(LD) $(LDFLAGS) $*.obj $(LIBNAME) zlib.lib $(NOEHLIB)\n\n## Major targets\nall: libpng pngtest\n\nlibpng: $(LIBNAME)\n\npngtest: pngtest.exe\n\ntest: pngtest.exe\n\tpngtest\n\n## Minor Targets\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\npng.obj: png.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.obj: pngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.obj: pngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.obj: pngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.obj: pngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.obj: pngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.obj: pngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.obj: pngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.obj: pngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.obj: pngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.obj: pngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.obj: pngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.obj: pngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.obj: pngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.obj: pngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtest.obj: pngtest.c png.h pngconf.h pnglibconf.h\n\n$(LIBNAME): $(OBJS)\n\t-del $(LIBNAME)\n\t$(LIB) $(LIBNAME) @&&|\n$(LIBOBJS), libpng\n|\n\n# Cleanup\nclean:\n\t-del pnglibconf.h\n\t-del *.obj\n\t-del $(LIBNAME)\n\t-del pngtest.exe\n\t-del *.lst\n\t-del *.map\n\t-del *.tds\n\t-del pngout.png\n\n# End of makefile for libpng\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.beos",
    "content": "# makefile for libpng on BeOS x86 ELF with gcc\n# modified from makefile.linux by Sander Stoks\n# Copyright (C) 2002, 2006, 2008, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1999 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME=libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nCC=gcc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\n# Where the zlib library and include files are located\nZLIBLIB=/usr/local/lib\nZLIBINC=/usr/local/include\n\nALIGN=\n# For i386:\n# ALIGN=-malign-loops=2 -malign-functions=2\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\n\n# On BeOS, -O1 is actually better than -O3.  This is a known bug but it's\n# still here in R4.5\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=-W -Wall -O1 -funroll-loops $(ALIGN) # $(WARNMORE) -g\n# LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng -lz\nLDFLAGS=-L. -Wl,-soname=$(LIBSOMAJ) -L$(ZLIBLIB) -lz\n\n# where make install puts libpng.a, libpng16.so*, and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS)\n\n.SUFFIXES:      .c .o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo libs=\\\"-lpng16 -lz \\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\tcp $(LIBSO)* /boot/home/config/lib\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(CC) -nostart -Wl,-soname,$(LIBSOMAJ) -o \\\n\t$(LIBSOMAJ) $(OBJSDLL) $(LDFLAGS)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -L$(ZLIBLIB) -L. -lz -lpng16 -o pngtest pngtest.o\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) $(CFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) -Wl,-rpath $(ZLIBLIB):$(DL) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png libpng-config \\\n\t$(LIBSO) $(LIBSOMAJ)* pngtesti \\\n\tpnglibconf.h libpng.pc\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.bor",
    "content": "# Makefile for libpng\n# 16-bit Borland C++ (Note: All modules are compiled in C mode)\n# To build the library, do:\n#       \"make -fmakefile.bor -DMODEL=c\"\n# or:   \"make -fmakefile.bor -DMODEL=l\"\n#\n# ------------ Borland C++ ------------\n\n### Absolutely necessary for this makefile to work\n.AUTODEPEND\n\n## Where zlib.h, zconf.h and zlib_MODEL.lib are\nZLIB_DIR=..\\zlib\n\n## Compiler, linker, librarian and other tools\nCC=bcc\nLD=bcc\nLIB=tlib\nCP=copy\n\n!ifndef MODEL\nMODEL=l\n!endif\n\nMODEL_ARG=-m$(MODEL)\n\n#TARGET_CPU=3\n# 2 = 286, 3 = 386, etc.\n!ifndef TARGET_CPU\nTARGET_CPU=2\n!endif\n\n# Use this if you don't want Borland's fancy exception handling\n# (for Borland C++ 4.0 or later)\n#NOEHLIB=noeh$(MODEL).lib\n\n!ifdef DEBUG\nCDEBUG=-v\nLDEBUG=-v\n!else\nCDEBUG=\nLDEBUG=\n!endif\n\n# STACKOFLOW=1\n!ifdef STACKOFLOW\nCDEBUG=$(CDEBUG) -N\nLDEBUG=$(LDEBUG) -N\n!endif\n\n# -X- turn on dependency generation in the object file\n# -w  set all warnings on\n# -O2 optimize for speed\n# -Z  global optimization\nCPPFLAGS=-I$(ZLIB_DIR)\nCFLAGS=-O2 -Z -X- -w -$(TARGET_CPU) $(MODEL_ARG) $(CDEBUG)\n\n# -M  generate map file\nLDFLAGS=-M -L$(ZLIB_DIR) $(MODEL_ARG) $(LDEBUG)\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\n!ifndef PNGLIBCONF_H_PREBUILT\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n!endif\n\n## Variables\n\nOBJS = \\\n\tpng.obj \\\n\tpngerror.obj \\\n\tpngget.obj \\\n\tpngmem.obj \\\n\tpngpread.obj \\\n\tpngread.obj \\\n\tpngrio.obj \\\n\tpngrtran.obj \\\n\tpngrutil.obj \\\n\tpngset.obj \\\n\tpngtrans.obj \\\n\tpngwio.obj \\\n\tpngwrite.obj \\\n\tpngwtran.obj \\\n\tpngwutil.obj\n\nLIBOBJS = \\\n\t+png.obj \\\n\t+pngerror.obj \\\n\t+pngget.obj \\\n\t+pngmem.obj \\\n\t+pngpread.obj \\\n\t+pngread.obj \\\n\t+pngrio.obj \\\n\t+pngrtran.obj \\\n\t+pngrutil.obj \\\n\t+pngset.obj \\\n\t+pngtrans.obj \\\n\t+pngwio.obj \\\n\t+pngwrite.obj \\\n\t+pngwtran.obj \\\n\t+pngwutil.obj\n\nLIBNAME=libpng$(MODEL).lib\n\n## Implicit rules\n\n# Braces let make \"batch\" calls to the compiler,\n# 2 calls instead of 12; space is important.\n.c.obj:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) -c {$*.c }\n\n.c.exe:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $*.c \\\n\t  $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)\n\n## Major targets\n\nall: libpng pngtest\n\n# try !include scripts\\pnglibconf.mak for more options\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng: $(LIBNAME)\n\npngtest: pngtest$(MODEL).exe\n\ntest: pngtest$(MODEL).exe\n\tpngtest$(MODEL)\n\n## Minor Targets\n\npng.obj: png.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.obj: pngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.obj: pngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.obj: pngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.obj: pngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.obj: pngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.obj: pngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.obj: pngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.obj: pngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.obj: pngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.obj: pngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.obj: pngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.obj: pngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.obj: pngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.obj: pngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\n$(LIBNAME): $(OBJS)\n\t-del $(LIBNAME)\n\t$(LIB) $(LIBNAME) @&&|\n$(LIBOBJS), libpng$(MODEL)\n|\n\npngtest$(MODEL).obj: pngtest.c png.h pngconf.h pnglibconf.h\n\t$(CC) $(CFLAGS) -opngtest$(MODEL) -c pngtest.c\n\npngtest$(MODEL).exe: pngtest$(MODEL).obj\n\t$(LD) $(LDFLAGS) pngtest$(MODEL).obj $(LIBNAME) zlib_$(MODEL).lib $(NOEHLIB)\n\n# Clean up anything else you want\nclean:\n\t-del pnglibconf.h\n\t-del *.obj\n\t-del *.exe\n\t-del *.lib\n\t-del *.lst\n\t-del *.map\n\n# End of makefile for libpng\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.cegcc",
    "content": "# Makefile for creating Windows CE release archives, with the\n# mingw32ce compiler.\n\n# Last updated: 22-Jul-2008\n\n# Copyright (C) 2008 Vincent Torri\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# To get some help, type\n#\n# make help\n#\n# To create the archives\n#\n# make\n#\n# To remove everything, type:\n#\n# make clean\n\nVERMAJ = 1\nVERMIN = 6\nVERMIC = 25\nVER = $(VERMAJ).$(VERMIN).$(VERMIC)\nNAME = libpng\nPACKAGE = $(NAME)-$(VER)\n\nBIN = libpng16-0.dll\nLIB = libpng16.a libpng16.dll.a libpng.a libpng.dll.a\nINCLUDE = png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\nPC = libpng16.pc libpng.pc\n\nMANIFESTVERBIN = \"Libpng-$(VER): Binary files\"\nMANIFESTVERDEV = \"Libpng-$(VER): Developer files\"\nMANIFESTVERDESC = \"Libpng: the official PNG reference library\"\n\nall: $(NAME)\n\n$(NAME): remove-old copy-src compilation copy manifest archive\n\t@echo \" * Removal of the directories\"\n\t@rm -rf $(PACKAGE)/ $(PACKAGE)-bin/ $(PACKAGE)-dev/\n\nremove-old:\n\t@echo \" * Removal of the old files\"\n\t@rm -rf $(PACKAGE)-bin*\n\t@rm -rf $(PACKAGE)-dev*\n\ncopy-src:\n\t@echo \" * Copy of source files\"\n\t@cp -R ../src/$(PACKAGE) .\n\t@echo \" * Creation of directories and files\"\n\t@mkdir -p $(PACKAGE)-bin/bin\n\t@mkdir -p $(PACKAGE)-bin/manifest\n\t@mkdir -p $(PACKAGE)-dev/lib/pkgconfig\n\t@mkdir -p $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN)\n\t@mkdir -p $(PACKAGE)-dev/manifest\n\t@touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.mft\n\t@touch $(PACKAGE)-bin/manifest/$(PACKAGE)-bin.ver\n\t@touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.mft\n\t@touch $(PACKAGE)-dev/manifest/$(PACKAGE)-dev.ver\n\ncompilation:\n\t@echo \" * Compilation of $(PACKAGE)\"\n\tcd $(PACKAGE) && CPPFLAGS=\"$(CPPFLAGS) -DPNG_CONSOLE_IO_SUPPORTED -D_WIN32_WCE=0x0420\" \\\n\t\tCFLAGS=\"$(CFLAGS) -mms-bitfields -O3 -pipe -fomit-frame-pointer\" \\\n\t\tLDFLAGS=\"$(LDFLAGS) -Wl,--enable-auto-import -Wl,-s\" \\\n\t\t./configure --prefix=/opt/wince --host=arm-mingw32ce && make\n\ncopy:\n\t@echo \" * Copy of binary and development files\"\n\t@for i in $(BIN); do \\\n\t  cp $(PACKAGE)/.libs/$$i $(PACKAGE)-bin/bin; \\\n\tdone\n\t@for i in $(LIB); do \\\n\t  cp $(PACKAGE)/.libs/$$i $(PACKAGE)-dev/lib; \\\n\tdone\n\t@for i in $(INCLUDE); do \\\n\t  cp $(PACKAGE)/$$i $(PACKAGE)-dev/include/$(NAME)$(VERMAJ)$(VERMIN); \\\n\tdone\n\t@for i in $(PC); do \\\n\t  cp $(PACKAGE)/$$i $(PACKAGE)-dev/lib/pkgconfig; \\\n\tdone\n\nmanifest:\n\t@echo \" * Creation of the manifest\"\n\t@cd $(PACKAGE)-bin && find * >> manifest/$(PACKAGE)-bin.mft\n\t@cd $(PACKAGE)-bin && \\\n\t  echo $(MANIFESTVERBIN) >> manifest/$(PACKAGE)-bin.ver && \\\n\t  echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-bin.ver\n\t@cd $(PACKAGE)-dev && find * >> manifest/$(PACKAGE)-dev.mft\n\t@cd $(PACKAGE)-dev && \\\n\t  echo $(MANIFESTVERDEV) >> manifest/$(PACKAGE)-dev.ver && \\\n\t  echo $(MANIFESTVERDESC) >> manifest/$(PACKAGE)-dev.ver\n\narchive:\n\t@echo \" * Creation of the archives\"\n\t@tar cf $(PACKAGE)-bin.tar $(PACKAGE)-bin\n\t@bzip2 -9 $(PACKAGE)-bin.tar\n\t@tar cf $(PACKAGE)-dev.tar $(PACKAGE)-dev\n\t@bzip2 -9 $(PACKAGE)-dev.tar\n\nclean:\n\t@echo \" * Cleaning\"\n\t@rm -rf $(PACKAGE)*\n\nhelp:\n\t@echo\n\t@echo \"To create the archives, type:\"\n\t@echo \" make\"\n\t@echo\n\t@echo \"To remove everything, type:\"\n\t@echo \" make clean\"\n\t@echo\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.darwin",
    "content": "# makefile for libpng on Darwin / Mac OS X\n# Copyright (C) 2002, 2004, 2006, 2008, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 2001 Christoph Pfisterer\n# derived from makefile.linux:\n#  Copyright (C) 1998, 1999 Greg Roelofs\n#  Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# where \"make install\" puts libpng.a, libpng16.dylib, png.h, pngconf.h,\n# and pnglibconf.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\nZLIBLIB=/usr/lib\nZLIBINC=/usr/include\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).dylib\nLIBSOMAJ=$(LIBNAME).$(PNGMAJ).dylib\nLIBSOREL=$(LIBNAME).$(PNGMAJ).$(RELEASE).dylib\nOLDSO=libpng.dylib\n\n# Utilities:\nCC=cc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\nCPPFLAGS=-I$(ZLIBINC)\n# CFLAGS=-W -Wall -O3 -funroll-loops\nCFLAGS=-W -Wall -O -funroll-loops\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng16 -lz\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -fno-common -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(CC) -dynamiclib \\\n\t -install_name $(LIBPATH)/$(LIBSOMAJ) \\\n\t -current_version 16 -compatibility_version 16 \\\n\t -o $(LIBSOMAJ) \\\n\t $(OBJSDLL) -L$(ZLIBLIB) -lz\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t$(RANLIB) $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOMAJ)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)\n\tchmod 755 $(DL)/$(LIBSOMAJ)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png libpng-config \\\n\tlibpng.pc $(LIBNAME).*dylib pngtesti pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.dec",
    "content": "# makefile for libpng on DEC Alpha Unix\n# Copyright (C) 2000-2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nPNGMAJ = 16\nLIBNAME = libpng16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=cc\nMKDIR_P=mkdir\nLN_SF=ln -f -s\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=-std -w1 -O # -g\nLDFLAGS=-L$(ZLIBLIB) -rpath $(ZLIBLIB) libpng.a -lz -lm\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: $(LIBSO) libpng.a pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@  $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"-std\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJS)\n\t$(CC) -shared -o $@ $(OBJS) -L$(ZLIBLIB) \\\n\t-soname $(LIBSOMAJ)\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@/bin/rm -f $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@/bin/rm -f $(DI)/libpng\n\t(cd $(DI); $(LN_SF)(LIBNAME) libpng; $(LN_SF)(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@/bin/rm -f $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF)(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@/bin/rm -f $(DM)/man3/libpng.3\n\t-@/bin/rm -f $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@/bin/rm -f $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@/bin/rm -f $(DB)/libpng-config\n\t-@/bin/rm -f $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF)(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -w1 -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB)  -R$(ZLIBLIB) -R$(DL) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) -w1 $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) -R$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.dj2",
    "content": "# DJGPP (DOS gcc) makefile for libpng\n# Copyright (C) 2002, 2006, 2009-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# where make install will put libpng.a and png.h\n#prefix=/usr/local\nprefix=.\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\nCC=gcc\nCPPFLAGS=-I../zlib -DPNG_NO_SNPRINTF\nCFLAGS=-O\nLDFLAGS=-L. -L../zlib/ -lpng -lz -lm\n\nRANLIB=ranlib\n\nCP=cp\nRM_F=rm -f\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o pngwtran.o \\\n\tpngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\tar rc $@  $(OBJS)\n\t$(RANLIB) $@\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\tcoff2exe pngtest\n\ntest: pngtest\n\t./pngtest\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.h\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.freebsd",
    "content": "# makefile for libpng under FreeBSD\n# Copyright (C) 2014 Glenn Randers-Pehrson and Andrey A. Chernov\n# Copyright (C) 2002, 2007, 2009 Glenn Randers-Pehrson and Andrey A. Chernov\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\nPREFIX?=        /usr/local\nSHLIB_VER?=     16\n\nLIB=\t\tpng\nSHLIB_MAJOR=\t${SHLIB_VER}\nSHLIB_MINOR=\t0\nNO_PROFILE=\tYES\nNO_OBJ=\t\tYES\n\n# where make install puts libpng.a and png.h\nDESTDIR=\t${PREFIX}\nLIBDIR=\t\t/lib\nINCS=\t\tpng.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\nINCSDIR=\t/include/libpng\nINCDIR=\t\t${INCSDIR}\t\t# for 4.x bsd.lib.mk\nMAN=\t\tlibpng.3 libpngpf.3 png.5\nMANDIR=\t\t/man/man\nSYMLINKS=       libpng/png.h ${INCSDIR}/../png.h \\\n\t\tlibpng/pngconf.h ${INCSDIR}/../pngconf.h \\\n\t\tlibpng/pnglibconf.h ${INCSDIR}/../pnglibconf.h\n\n# where make install finds libz.a and zlib.h\nZLIBLIB=\t/usr/lib\nZLIBINC=\t/usr/include\n\nLDADD+=\t\t-lm -lz\n#LDADD+=\t-lm -lz -lssp_nonshared   # for OSVERSION < 800000 ?\n\nDPADD+=\t\t${LIBM} ${LIBZ}\n\nCPPFLAGS+=\t-I. -I${ZLIBINC}\nCFLAGS+=\t-W -Wall\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT= scripts/pnglibconf.h.prebuilt\n\nSRCS=\tpng.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \\\n\tpngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \\\n\tpngwtran.c pngmem.c pngerror.c pngpread.c\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\npngtest: pngtest.o libpng.a\n\t${CC} ${CFLAGS} -L. -static -o pngtest pngtest.o -L${ZLIBLIB} \\\n\t-lpng ${LDADD}\n\nCLEANFILES= pngtest pngtest.o pngout.png\n\ntest: pngtest\n\t./pngtest\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\tcp $(PNGLIBCONF_H_PREBUILT) $@\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n.include <bsd.lib.mk>\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.gcc",
    "content": "# makefile for libpng using gcc (generic, static library)\n# Copyright (C) 2008, 2014 Glenn Randers-Pehrson\n# Copyright (C) 2000 Cosmin Truta\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Location of the zlib library and include files\nZLIBINC = ../zlib\nZLIBLIB = ../zlib\n\n# Compiler, linker, lib and other tools\nCC = gcc\nLD = $(CC)\nAR_RC = ar rcs\nRANLIB = ranlib\nCP = cp\nRM_F = rm -f\n\nWARNMORE = -Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes # -Wconversion\nCPPFLAGS = -I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS = -W -Wall -O2 # $(WARNMORE) -g\nLDFLAGS =\nLIBS = -lz -lm\n\n# File extensions\nEXEEXT =\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\n# Variables\nOBJS =  png.o pngerror.o pngget.o pngmem.o pngpread.o \\\n\tpngread.o pngrio.o pngrtran.o pngrutil.o pngset.o \\\n\tpngtrans.o pngwio.o pngwrite.o pngwtran.o pngwutil.o\n\n# Targets\nall: static\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nstatic: libpng.a pngtest$(EXEEXT)\n\nshared:\n\t@echo This is a generic makefile that cannot create shared libraries.\n\t@echo Please use a configuration that is specific to your platform.\n\t@false\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\ntest: pngtest$(EXEEXT)\n\t./pngtest$(EXEEXT)\n\npngtest$(EXEEXT): pngtest.o libpng.a\n\t$(LD) $(LDFLAGS) -L$(ZLIBLIB) -o $@ pngtest.o libpng.a $(LIBS)\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest$(EXEEXT) pngout.png pnglibconf.h\n\npng.o:      png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o:  png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o:  png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.hp64",
    "content": "# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product.\n# Copyright (C) 1999-2002, 2006, 2009, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42\n# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Where the zlib library and include files are located\nZLIBLIB=/opt/zlib/lib\nZLIBINC=/opt/zlib/include\n\n# Note that if you plan to build a libpng shared library, zlib must also\n# be a shared library, which zlib's configure does not do.  After running\n# zlib's configure, edit the appropriate lines of makefile to read:\n#   CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \\\n#   LDSHARED=ld -b\n#   SHAREDLIB=libz.sl\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).sl\nLIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.sl\n\n# Utilities:\nAR_RC=ar rc\nCC=cc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\nCPPFLAGS=-I$(ZLIBINC) \\\n        -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DHAVE_UNISTD_H -DUSE_MMAP\nCFLAGS=-O -Ae -Wl,+vnocompatwarnings +DD64 +Z\n# Caution: be sure you have built zlib with the same CFLAGS.\nCCFLAGS=-O -Ae -Wl,+vnocompatwarnings +DD64 +Z\n\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm\n\n# where make install puts libpng.a, libpng16.sl, and png.h\nprefix=/opt/libpng\nexec_prefix=$(prefix)\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:\t.c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) +z -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"-O -Ae -Wl,+vnocompatwarnings +DD64 +Z\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(LD) -b +s \\\n\t+h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) $(CCFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) $(CCFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.hpgcc",
    "content": "# makefile for libpng on HP-UX using GCC with the HP ANSI/C linker.\n# Copyright (C) 2002, 2006-2008, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 2001, Laurent faillie\n# Copyright (C) 1998, 1999 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).sl\nLIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.sl\n\n# Utilities:\nCC=gcc\nLD=ld\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\n# where \"make install\" puts libpng.a, $(OLDSO)*, png.h, pngconf.h\n# and pnglibconf.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\nZLIBLIB=/opt/zlib/lib\nZLIBINC=/opt/zlib/include\n\n# Note that if you plan to build a libpng shared library, zlib must also\n# be a shared library, which zlib's configure does not do.  After running\n# zlib's configure, edit the appropriate lines of makefile to read:\n#   CFLAGS=-O1 -DHAVE_UNISTD -DUSE_MAP -fPIC \\\n#   LDSHARED=ld -b\n#   SHAREDLIB=libz.sl\n\nALIGN=\n# for i386:\n#ALIGN=-malign-loops=2 -malign-functions=2\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\n\n# for pgcc version 2.95.1, -O3 is buggy; don't use it.\n\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=-W -Wall -O3 -funroll-loops $(ALIGN) # $(WARNMORE) -g\n#LDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng16 -lz -lm\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(LD) -b +s \\\n\t+h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) -Wl,-rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.hpux",
    "content": "# makefile for libpng, HPUX (10.20 and 11.00) using the ANSI/C product.\n# Copyright (C) 1999-2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42\n# contributed by Jim Rice and updated by Chris Schleicher, Hewlett Packard\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Where the zlib library and include files are located\nZLIBLIB=/opt/zlib/lib\nZLIBINC=/opt/zlib/include\n\n# Note that if you plan to build a libpng shared library, zlib must also\n# be a shared library, which zlib's configure does not do.  After running\n# zlib's configure, edit the appropriate lines of makefile to read:\n#   CPPFLAGS=-DHAVE_UNISTD -DUSE_MAP\n#   CFLAGS=-O1 -fPIC\n#   LDSHARED=ld -b\n#   SHAREDLIB=libz.sl\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).sl\nLIBSOMAJ=$(LIBNAME).sl.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.sl\n\n# Utilities:\nAR_RC=ar rc\nCC=cc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nRM_F=/bin/rm -f\n\n# where make install puts libpng.a, libpng16.sl, and png.h\nprefix=/opt/libpng\nexec_prefix=$(prefix)\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\nCPPFLAGS=-I$(ZLIBINC)\nCFLAGS=-O -Ae +DA1.1 +DS2.0\n# Caution: be sure you have built zlib with the same CFLAGS.\nCCFLAGS=-O -Ae +DA1.1 +DS2.0\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:\t.c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) +z -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"-O -Ae +DA1.1 +DS2.0\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(LD) -b +s \\\n\t+h $(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CCFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) $(CCFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) $(CCFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.ibmc",
    "content": "# Makefile for libpng (static)\n# IBM C version 3.x for Win32 and OS/2\n# Copyright (C) 2006, 2014 Glenn Randers-Pehrson\n# Copyright (C) 2000 Cosmin Truta\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Notes:\n#   Derived from makefile.std\n#   All modules are compiled in C mode\n#   Tested under Win32, expected to work under OS/2\n#   Can be easily adapted for IBM VisualAge/C++ for AIX\n\n# Location of the zlib library and include files\nZLIBINC = ../zlib\nZLIBLIB = ../zlib\n\n# Compiler, linker, lib and other tools\nCC = icc\nLD = ilink\nAR = ilib\nCP = copy\nRM = del\n\nCPPFLAGS = -I$(ZLIBINC)\nCFLAGS = -Mc -O2 -W3\nLDFLAGS =\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\n# File extensions\nO=.obj\nA=.lib\nE=.exe\n\n# Variables\nOBJS = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O) \\\n\tpngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O) \\\n\tpngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)\n\nLIBS = libpng$(A) $(ZLIBLIB)/zlib$(A)\n\n# Targets\n.c$(O):\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\nall: libpng$(A) pngtest$(E)\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng$(A): $(OBJS)\n\t$(AR) -out:$@ $(OBJS)\n\ntest: pngtest$(E)\n\tpngtest$(E)\n\npngtest: pngtest$(E)\n\npngtest$(E): pngtest$(O) libpng$(A)\n\t$(LD) $(LDFLAGS) pngtest$(O) $(LIBS)\n\nclean:\n\t$(RM) *$(O)\n\t$(RM) libpng$(A)\n\t$(RM) pnglibconf.h\n\t$(RM) pngtest$(E)\n\t$(RM) pngout.png\n\npng$(O):      png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget$(O):   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem$(O):   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread$(O):  png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio$(O):   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset$(O):   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio$(O):   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest$(O):  png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.intel",
    "content": "# Makefile for libpng\n# Microsoft Visual C++ with Intel C/C++ Compiler 4.0 and later\n\n# Copyright (C) 2006, 2014 Glenn Randers-Pehrson\n# Copyright (C) 2000, Pawel Mrochen, based on makefile.msc which is\n# copyright 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# To use, do \"nmake /f scripts\\makefile.intel\"\n#\n# ------------------- Intel C/C++ Compiler 4.0 and later -------------------\n\n# Where the zlib library and include files are located\nZLIBLIB=..\\zlib\nZLIBINC=..\\zlib\n\n# Target CPU\nCPU=6\t\t# Pentium II\n#CPU=5\t\t# Pentium\n\n# Calling convention\nCALLING=r\t# __fastcall\n#CALLING=z\t# __stdcall\n#CALLING=d\t# __cdecl\n\n# Uncomment next to put error messages in a file\n#ERRFILE=>>pngerrs\n\n# --------------------------------------------------------------------------\n\nCC=icl -c\nCPPFLAGS=-I$(ZLIBINC)\nCFLAGS=-O2 -G$(CPU)$(CALLING) -Qip -Qunroll4 -nologo\nLD=link\nLDFLAGS=/SUBSYSTEM:CONSOLE /NOLOGO\nCP=cp\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n\nO=.obj\n\nOBJS=png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O) \\\npngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O) \\\npngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)\n\nall: test\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\npng$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\nlibpng.lib: $(OBJS)\n\tif exist libpng.lib del libpng.lib\n\tlib /NOLOGO /OUT:libpng.lib $(OBJS)\n\npngtest.exe: pngtest.obj libpng.lib\n\t$(LD) $(LDFLAGS) /OUT:pngtest.exe pngtest.obj libpng.lib $(ZLIBLIB)\\zlib.lib\n\npngtest$(O): png.h pngconf.h pnglibconf.h\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\ntest: pngtest.exe\n\tpngtest.exe\n\n\n# End of makefile for libpng\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.knr",
    "content": "# makefile for libpng\n# Copyright (C) 2002, 2006, 2009, 2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# This makefile requires the file ansi2knr.c, which you can get\n# from the Ghostscript ftp site at ftp://ftp.cs.wisc.edu/ghost/\n# If you have libjpeg, you probably already have ansi2knr.c in the jpeg\n# source distribution.\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nCC = cc\nCPPFLAGS = -I../zlib\nCFLAGS = -O\nLDFLAGS = -L. -L../zlib/ -lpng -lz -lm\n# flags for ansi2knr\nANSI2KNRFLAGS=\n\nRANLIB = ranlib\n#RANLIB = echo\n\nCP = cp\nRM_F = rm -f\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nall: ansi2knr libpng.a pngtest\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\n# general rule to allow ansi2knr to work\n.c.o:\n\t./ansi2knr $*.c T$*.c\n\t$(CC) $(CPPFLAGS) $(CFLAGS) -c T$*.c\n\trm -f T$*.c $*.o\n\tmv T$*.o $*.o\n\nansi2knr: ansi2knr.c\n\t$(CC) $(CPPFLAGS) $(CFLAGS) $(ANSI2KNRFLAGS) -o ansi2knr ansi2knr.c\n\nlibpng.a: ansi2knr $(OBJS)\n\tar rc $@  $(OBJS)\n\t$(RANLIB) $@\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall: libpng.a png.h pngconf.h pnglibconf.h\n\t-@mkdir $(DESTDIR)$(INCPATH)\n\t-@mkdir $(DESTDIR)$(INCPATH)/libpng\n\t-@mkdir $(DESTDIR)$(LIBPATH)\n\t-@rm -f $(DESTDIR)$(INCPATH)/png.h\n\t-@rm -f $(DESTDIR)$(INCPATH)/pngconf.h\n\tcp png.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pngconf.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h\n\t(cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)\n\tcp libpng.a $(DESTDIR)$(LIBPATH)\n\tchmod 644 $(DESTDIR)$(LIBPATH)/libpng.a\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png ansi2knr pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.linux",
    "content": "# makefile for libpng.a and libpng16.so on Linux ELF with gcc\n# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2014 Greg Roelofs and\n# Glenn Randers-Pehrson\n# Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\nRELEASE = 25\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=gcc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\n# where \"make install\" puts libpng16.a, libpng16.so*,\n# libpng16/png.h, libpng16/pngconf.h, and libpng16/pnglibconf.h\n# Prefix must be a full pathname.\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located.\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\nALIGN=\n# for i386:\n#ALIGN=-malign-loops=2 -malign-functions=2\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\n\n# for pgcc version 2.95.1, -O3 is buggy; don't use it.\n\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS= -W -Wall -O3 -funroll-loops \\\n\t$(ALIGN) # $(WARNMORE) -g -DPNG_DEBUG=5\n\nLDFLAGS=-L. -Wl,-rpath,. -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) -lpng16 -lz -lm\nLDFLAGS_A=-L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) libpng.a -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS =  png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest pngtest-static libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-Wl,-rpath,$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\npngtest-static: pngtest.o libpng.a\n\t$(CC) -o pngtest-static $(CFLAGS) pngtest.o $(LDFLAGS_A)\n\ntest: pngtest pngtest-static\n\t@echo \"\"\n\t@echo \"   Running pngtest dynamically linked with $(LIBSO):\"\n\t@echo \"\"\n\t./pngtest\n\t@echo \"\"\n\t@echo \"   Running pngtest statically linked with libpng.a:\"\n\t@echo \"\"\n\t./pngtest-static\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) -Wl, -rpath,$(DL) -Wl,-rpath,$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) -Wl,-rpath,$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png libpng-config \\\n\t$(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.mips",
    "content": "# makefile for libpng\n# Copyright (C) 1998-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nCC=cc\nCPPFLAGS=-I../zlib -DSYSV -Dmips\nCFLAGS=-O -systype sysv -w\n#CFLAGS=-O\nLDFLAGS=-L. -L../zlib/ -lpng -lz -lm\n\n#RANLIB=ranlib\nRANLIB=echo\n\nCP=cp\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\tar rc $@  $(OBJS)\n\t$(RANLIB) $@\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall: libpng.a\n\t-@mkdir $(DESTDIR)$(INCPATH)\n\t-@mkdir $(DESTDIR)$(INCPATH)/libpng\n\t-@mkdir $(DESTDIR)$(LIBPATH)\n\t-@rm -f $(DESTDIR)$(INCPATH)/png.h\n\t-@rm -f $(DESTDIR)$(INCPATH)/pngconf.h\n\t-@rm -f $(DESTDIR)$(INCPATH)/pnglibconf.h\n\tcp png.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pngconf.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h\n\t(cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)\n\tcp libpng.a $(DESTDIR)$(LIBPATH)\n\tchmod 644 $(DESTDIR)$(LIBPATH)/libpng.a\n\nclean:\n\trm -f *.o libpng.a pngtest pngout.png pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.msc",
    "content": "# makefile for libpng\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n# Copyright (C) 2006, 2009, 2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\\zlib\n\n# -------- Microsoft C 5.1 and later, does not use assembler code --------\nMODEL=L\nCPPFLAGS=-I..\\zlib\nCFLAGS=-Oait -Gs -nologo -W3 -A$(MODEL)\n#-Ox generates bad code with MSC 5.1\nCC=cl\nLD=link\nLDFLAGS=/e/st:0x1500/noe\nCP=copy\nO=.obj\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n\n#uncomment next to put error messages in a file\nERRFILE= >> pngerrs\n\n# variables\nOBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)\nOBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)\nOBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)\n\nall: libpng.lib\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\npng$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\nlibpng.lib: $(OBJS1) $(OBJS2) $(OBJS3)\n\tdel libpng.lib\n\tlib libpng $(OBJS1);\n\tlib libpng $(OBJS2);\n\tlib libpng $(OBJS3);\n\npngtest$(O): png.h pngconf.h pnglibconf.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngtest.exe: pngtest.obj libpng.lib\n\t$(LD) $(LDFLAGS) pngtest.obj,,,libpng.lib ..\\zlib\\zlib.lib ;\n\ntest: pngtest.exe\n\tpngtest\n\n# End of makefile for libpng\n\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.msys",
    "content": "# makefile for libpng using MSYS/gcc (shared, static library)\n# Copyright (C) 2012 Glenn Randers-Pehrson and Christopher M. Wheeler\n#\n# Portions taken from makefile.linux:\n# Copyright (C) 1998, 1999, 2002, 2006, 2008, 2010-2014 Greg Roelofs and\n# Glenn Randers-Pehrson\n# Copyright (C) 2000 Cosmin Truta\n# Copyright (C) 1996, 1997 Andreas Dilger\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n# # # # # # # # # # # # # # # # #\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\nRELEASE = 25\n\n# Shared library names:\nLIBSO=$(LIBNAME).dll\nLIBSOMAJ=$(LIBNAME).dll.$(PNGMAJ)\nLIBSOREL=$(PNGMAJ).$(RELEASE)\nOLDSO=libpng.dll\n\n# Where the zlib library and include files are located.\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\nZLIBLIB=/usr/local/lib\nZLIBINC=/usr/local/include\n\n# Compiler, linker, lib and other tools\nCC = gcc\nLD = $(CC)\nAR_RC = ar rcs\nRANLIB = ranlib\nCP = cp\nRM_F = rm -rf\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\n\n#ARCH = -march=pentium3\n#ARCH = -march=i686\nARCH =\nCPPFLAGS = # -DPNG_DEBUG=5\nCFLAGS = -W -Wall -O2 $(ARCH) # -g\nLDFLAGS =\nLIBS = -lz -lm\n\n# File extensions\nEXEEXT=.exe\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\n\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\n# Variables\nOBJS =  png.o pngerror.o pngget.o pngmem.o pngpread.o \\\n\tpngread.o pngrio.o pngrtran.o pngrutil.o pngset.o \\\n\tpngtrans.o pngwio.o pngwrite.o pngwtran.o pngwutil.o\n\n# Targets\nall: static shared\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $<\n\nstatic: libpng.a pngtest$(EXEEXT)\n\nshared: $(LIBSOMAJ)\n\t$(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSO)\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ):\n\t$(CC) -shared -Wl,-soname,$(LIBSOMAJ) -o $(LIBSOMAJ)\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-Wl,-rpath,$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSO) $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\ntest: pngtest$(EXEEXT)\n\t./pngtest$(EXEEXT)\n\npngtest$(EXEEXT): pngtest.o libpng.a\n\t$(LD) $(LDFLAGS) -L$(ZLIBLIB) -o $@ pngtest.o libpng.a $(LIBS)\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest$(EXEEXT) pngout.png pnglibconf.h $(LIBSO) \\\n\t$(LIBSOMAJ) libpng-config\n\npng.o:      png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o:  png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o:   png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o:  png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.ne12bsd",
    "content": "# makefile for libpng for NetBSD for the standard\n# make obj && make depend && make && make test\n# make includes && make install\n# Copyright (C) 2002 Patrick R.L. Welche\n# Copyright (C) 2007, 2009, 2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# You should also run makefile.netbsd\n\nLOCALBASE?=/usr/local\nLIBDIR=\t${LOCALBASE}/lib\nMANDIR= ${LOCALBASE}/man\nINCSDIR=${LOCALBASE}/include/libpng16\n\nLIB=\tpng16\nSHLIB_MAJOR=\t0\nSHLIB_MINOR=\t1.6.25\nSRCS=\tpng.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \\\n\tpngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \\\n\tpngwtran.c pngmem.c pngerror.c pngpread.c\nINCS=\tpng.h pngconf.h pnglibconf.h\nMAN=\tlibpng.3 libpngpf.3 png.5\n\nCPPFLAGS+=-I${.CURDIR}\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT= scripts/pnglibconf.h.prebuilt\n\n# We should be able to do something like this instead of the manual\n# uncommenting, but it core dumps for me at the moment:\n# .if ${MACHINE_ARCH} == \"i386\"\n#   MKLINT= no\n# .endif\n\nCLEANFILES+=pngtest.o pngtest pnglibconf.h\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\tcp $(PNGLIBCONF_H_PREBUILT) $@\n\npngtest.o:\tpngtest.c\n\t${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET}\n\npngtest:\tpngtest.o libpng.a\n\t${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm\n\ntest:\tpngtest\n\tcd ${.CURDIR} && ${.OBJDIR}/pngtest\n\n.include <bsd.lib.mk>\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.netbsd",
    "content": "# makefile for libpng for NetBSD for the standard\n# make obj && make depend && make && make test\n# make includes && make install\n# Copyright (C) 2002 Patrick R.L. Welche\n# Copyright (C) 2007-2009, 2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# You should also run makefile.ne16bsd\n\nLOCALBASE?=/usr/local\nLIBDIR=\t${LOCALBASE}/lib\nMANDIR= ${LOCALBASE}/man\nINCSDIR=${LOCALBASE}/include\n\nLIB=\tpng\nSHLIB_MAJOR=\t16\nSHLIB_MINOR=\t1.6.25\nSRCS=\tpng.c pngset.c pngget.c pngrutil.c pngtrans.c pngwutil.c \\\n\tpngread.c pngrio.c pngwio.c pngwrite.c pngrtran.c \\\n\tpngwtran.c pngmem.c pngerror.c pngpread.c\nINCS=\tpng.h pngconf.h pnglibconf.h\nMAN=\tlibpng.3 libpngpf.3 png.5\n\nCPPFLAGS+=-I${.CURDIR}\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT= scripts/pnglibconf.h.prebuilt\n\n# We should be able to do something like this instead of the manual\n# uncommenting, but it core dumps for me at the moment:\n# .if ${MACHINE_ARCH} == \"i386\"\n#   MKLINT= no\n# .endif\n\nCLEANFILES+=pngtest.o pngtest pnglibconf.h\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\tcp $(PNGLIBCONF_H_PREBUILT) $@\n\npngtest.o:\tpngtest.c\n\t${CC} -c ${CPPFLAGS} ${CFLAGS} ${.ALLSRC} -o ${.TARGET}\n\npngtest:\tpngtest.o libpng.a\n\t${CC} ${LDFLAGS} ${.ALLSRC} -o${.TARGET} -lz -lm\n\ntest:\tpngtest\n\tcd ${.CURDIR} && ${.OBJDIR}/pngtest\n\n.include <bsd.lib.mk>\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.openbsd",
    "content": "# makefile for libpng\n# Copyright (C) 2007-2009, 2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\nPREFIX?= /usr/local\nLIBDIR=\t${PREFIX}/lib\nMANDIR= ${PREFIX}/man/cat\n\nSHLIB_MAJOR=\t16\nSHLIB_MINOR=\t1.6.25\n\nLIB=\tpng\nSRCS=\tpng.c pngerror.c pngget.c pngmem.c pngpread.c \\\n\tpngread.c pngrio.c pngrtran.c pngrutil.c pngset.c pngtrans.c \\\n\tpngwio.c pngwrite.c pngwtran.c pngwutil.c\n\nHDRS=\tpng.h pngconf.h pnglibconf.h\n\nCFLAGS+= -W -Wall\nCPPFLAGS+= -I${.CURDIR}\n\nNOPROFILE= Yes\n\nCLEANFILES+= pngtest.o pngtest pnglibconf.h\n\nMAN=\tlibpng.3 libpngpf.3 png.5\nDOCS=\tANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO \\\n\tlibpng-manual.txt\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT= scripts/pnglibconf.h.prebuilt\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\tcp $(PNGLIBCONF_H_PREBUILT) $@\n\npngtest.o:\tpngtest.c\n\t${CC} ${CPPFLAGS} ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET}\n\npngtest:\tpngtest.o\n\t${CC} ${LDFLAGS} ${.ALLSRC} -o ${.TARGET} -L${.OBJDIR} -lpng -lz -lm\n\ntest:\tpngtest\n\tcd ${.OBJDIR} && env \\\n\t\tLD_LIBRARY_PATH=\"${.OBJDIR}\" ${.OBJDIR}/pngtest\n\nbeforeinstall:\n\tif [ ! -d ${DESTDIR}${PREFIX}/include/libpng ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/include; \\\n\tfi\n\tif [ ! -d ${DESTDIR}${LIBDIR} ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}; \\\n\tfi\n\tif [ ! -d ${DESTDIR}${LIBDIR}/debug ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${LIBDIR}/debug; \\\n\tfi\n\tif [ ! -d ${DESTDIR}${MANDIR}3 ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}3; \\\n\tfi\n\tif [ ! -d ${DESTDIR}${MANDIR}5 ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${MANDIR}5; \\\n\tfi\n\tif [ ! -d ${DESTDIR}${PREFIX}/share/doc/png ]; then \\\n\t  ${INSTALL} -d -o root -g wheel ${DESTDIR}${PREFIX}/share/doc/png; \\\n\tfi\n\nafterinstall:\n\t@rm -f ${DESTDIR}${LIBDIR}/libpng_pic.a\n\t@rm -f ${DESTDIR}${LIBDIR}/debug/libpng.a\n\t@rm -f ${DESTDIR}${PREFIX}/include/png.h\n\t@rm -f ${DESTDIR}${PREFIX}/include/pngconf.h\n\t@rm -f ${DESTDIR}${PREFIX}/include/pnglibconf.h\n\t@rmdir ${DESTDIR}${LIBDIR}/debug 2>/dev/null || true\n\t${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \\\n\t\t-m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include\n\t${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \\\n\t\t-m ${NONBINMODE} ${HDRS} ${DESTDIR}${PREFIX}/include\n\t${INSTALL} ${INSTALL_COPY} -o ${SHAREOWN} -g ${SHAREGRP} \\\n\t\t-m ${NONBINMODE} ${DOCS} ${DESTDIR}${PREFIX}/share/doc/png\n\n.include <bsd.lib.mk>\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.sco",
    "content": "# makefile for SCO OSr5  ELF and Unixware 7 with Native cc\n# Contributed by Mike Hopkirk (hops@sco.com) modified from Makefile.lnx\n#   force ELF build dynamic linking, SONAME setting in lib and RPATH in app\n# Copyright (C) 2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1998 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nCC=cc\nAR_RC=ar rc\nMKDIR_P=mkdir\nLN_SF=ln -f -s\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# where make install puts libpng.a, $(OLDSO)*, and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\nCPPFLAGS=-I$(ZLIBINC)\nCFLAGS= -dy -belf -O3\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -KPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"-belf\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t$(CC) -G  -Wl,-h,$(LIBSOMAJ) -o $(LIBSOMAJ) \\\n\t $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\tLD_RUN_PATH=.:$(ZLIBLIB) $(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\t-@$(RM_F) $(DI)/png.h\n\t-@$(RM_F) $(DI)/pngconf.h\n\t-@$(RM_F) $(DI)/pnglibconf.h\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\t$(CC) $(CPPFLAGS) $(CFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png libpng-config \\\n\t$(LIBSO) $(LIBSOMAJ)* pngtest-static pngtesti \\\n\tpnglibconf.h libpng.pc\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.sggcc",
    "content": "# makefile for libpng.a and libpng16.so, SGI IRIX with 'cc'\n# Copyright (C) 2001-2002, 2006, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME=libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=gcc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# Where make install puts libpng.a, libpng16.so, and libpng16/png.h\n# Prefix must be a full pathname.\n\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib32\n#ZLIBINC=/usr/local/include\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\n# ABI can be blank to use default for your system, -32, -o32, -n32, or -64\n# See \"man abi\".  zlib must be built with the same ABI.\nABI=\n\nWARNMORE=\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=$(ABI) -O $(WARNMORE) -fPIC -mabi=n32 # -g\nLDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm\nLDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \\\n\t-set_version sgi$(PNGMAJ).0\n# See \"man dso\" for info about shared objects\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\n#LIBPATH=$(exec_prefix)/lib32\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS =  png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest shared libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nshared: $(LIBSOMAJ)\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"$(ABI)\\\"; \\\n\techo cppflags=\\\"\\\"; \\\n\techo ldopts=\\\"$(ABI)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libdir=\\\"$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJS)\n\t$(LDSHARED) -o $@ $(OBJS)\n\t$(RM_F) $(LIBSO) $(LIBSOMAJ)\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\techo\n\techo Testing local static library.\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -rpath $(ZLIBLIB):$(DL) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) libpng.a pngtest pngtesti pngout.png libpng.pc \\\n\tso_locations libpng-config $(LIBSO) $(LIBSOMAJ)* pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.sgi",
    "content": "# makefile for libpng.a and libpng16.so, SGI IRIX with 'cc'\n# Copyright (C) 2001-2002, 2006, 2007, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME=libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=cc\nMKDIR_P=mkdir -p\nLN_SF=ln -sf\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# Where make install puts libpng.a, libpng16.so, and libpng16/png.h\n# Prefix must be a full pathname.\n\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib32\n#ZLIBINC=/usr/local/include\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\n# ABI can be blank to use default for your system, -32, -o32, -n32, or -64\n# See \"man abi\".  zlib must be built with the same ABI.\nABI=\n\nWARNMORE=-fullwarn\n# Note: -KPIC is the default anyhow\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\n#CFLAGS= $(ABI) -O $(WARNMORE) -KPIC # -g\nCFLAGS=$(ABI) -O $(WARNMORE)\nLDFLAGS_A=$(ABI) -L. -L$(ZLIBLIB) -lpng16 -lz -lm\nLDFLAGS=$(ABI) -L. -L$(ZLIBLIB) -lpng -lz -lm\nLDSHARED=cc $(ABI) -shared -soname $(LIBSOMAJ) \\\n\t-set_version sgi$(PNGMAJ).0\n# See \"man dso\" for info about shared objects\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\n#LIBPATH=$(exec_prefix)/lib32\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS =  png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest shared libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo ccopts=\\\"$(ABI)\\\"; \\\n\techo ldopts=\\\"$(ABI)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo libdir=\\\"$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJS)\n\t$(LDSHARED) -o $@ $(OBJS)\n\t$(RM_F) $(LIBSO) $(LIBSOMAJ)\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\techo\n\techo Testing local static library.\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(DL) -L$(ZLIBLIB) \\\n\t   -rpath $(ZLIBLIB):$(DL) \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -L$(ZLIBLIB) \\\n\t   -rpath $(ZLIBLIB):`$(BINPATH)/$(LIBNAME)-config --libdir` \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags`\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png libpng.pc libpng-config \\\n\t$(LIBSO) $(LIBSOMAJ)* \\\n\tso_locations pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.so9",
    "content": "# makefile for libpng on Solaris 9 (beta) with Forte cc\n# Updated by Chad Schrock for Solaris 9\n# Contributed by William L. Sebok, based on makefile.linux\n# Copyright (C) 2002, 2006, 2008, 2010-2014 Glenn Randers-Pehrson\n# Copyright (C) 1998-2001 Greg Roelofs\n# Copyright (C) 1996-1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nPNGMAJ = 16\nLIBNAME = libpng16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\n# gcc 2.95 doesn't work.\nCC=cc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# Where make install puts libpng.a, $(OLDSO)*, and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n# Changing these to ../zlib poses a security risk.  If you want\n# to have zlib in an adjacent directory, specify the full path instead of \"..\".\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\n#Use the preinstalled zlib that comes with Solaris 9:\nZLIBLIB=/usr/lib\nZLIBINC=/usr/include\n\n#WARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\n#CFLAGS=-W -Wall -O3 $(WARNMORE) -g\nCFLAGS=-O3\nLDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -KPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-R$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t@case \"`type ld`\" in *ucb*) \\\n\techo; \\\n\techo '## WARNING:'; \\\n\techo '## The commands \"CC\" and \"LD\" must NOT refer to /usr/ucb/cc'; \\\n\techo '## and /usr/ucb/ld.  If they do, you need to adjust your PATH'; \\\n\techo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \\\n\techo '## The environment variable LD_LIBRARY_PATH should not be set'; \\\n\techo '## at all.  If it is, things are likely to break because of'; \\\n\techo '## the libucb dependency that is created.'; \\\n\techo; \\\n\t;; \\\n\tesac\n\t$(LD) -G -h $(LIBSOMAJ) \\\n\t -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(DL) -L$(ZLIBLIB)  -R$(ZLIBLIB) -R$(DL)\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.solaris",
    "content": "# makefile for libpng on Solaris 2.x with gcc\n# Copyright (C) 2004, 2006-2008, 2010-2014 Glenn Randers-Pehrson\n# Contributed by William L. Sebok, based on makefile.linux\n# Copyright (C) 1998 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=gcc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# Where make install puts libpng.a, libpng16.so*, and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n# Changing these to ../zlib poses a security risk.  If you want\n# to have zlib in an adjacent directory, specify the full path instead of \"..\".\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\n\nZLIBLIB=/usr/local/lib\nZLIBINC=/usr/local/include\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS= -W -Wall -O \\\n\t# $(WARNMORE) -g -DPNG_DEBUG=5\nLDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -fPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo cppflags=\\\"\\\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-R$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t@case \"`type ld`\" in *ucb*) \\\n\techo; \\\n\techo '## WARNING:'; \\\n\techo '## The commands \"CC\" and \"LD\" must NOT refer to /usr/ucb/cc'; \\\n\techo '## and /usr/ucb/ld.  If they do, you need to adjust your PATH'; \\\n\techo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \\\n\techo '## The environment variable LD_LIBRARY_PATH should not be set'; \\\n\techo '## at all.  If it is, things are likely to break because of'; \\\n\techo '## the libucb dependency that is created.'; \\\n\techo; \\\n\t;; \\\n\tesac\n\t$(LD) -G -h $(LIBSOMAJ) \\\n\t -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL)\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.solaris-x86",
    "content": "# makefile for libpng on Solaris 2.x with gcc\n# Copyright (C) 2004, 2006-2008, 2010-2014 Glenn Randers-Pehrson\n# Contributed by William L. Sebok, based on makefile.linux\n# Copyright (C) 1998 Greg Roelofs\n# Copyright (C) 1996, 1997 Andreas Dilger\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# Library name:\nLIBNAME = libpng16\nPNGMAJ = 16\n\n# Shared library names:\nLIBSO=$(LIBNAME).so\nLIBSOMAJ=$(LIBNAME).so.$(PNGMAJ)\nLIBSOREL=$(LIBSOMAJ).$(RELEASE)\nOLDSO=libpng.so\n\n# Utilities:\nAR_RC=ar rc\nCC=gcc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=echo\nCP=cp\nRM_F=/bin/rm -f\n\n# Where make install puts libpng.a, libpng16.so*, and png.h\nprefix=/usr/local\nexec_prefix=$(prefix)\n\n# Where the zlib library and include files are located\n# Changing these to ../zlib poses a security risk.  If you want\n# to have zlib in an adjacent directory, specify the full path instead of \"..\".\n#ZLIBLIB=../zlib\n#ZLIBINC=../zlib\n\nZLIBLIB=/usr/local/lib\nZLIBINC=/usr/local/include\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes #-Wconversion\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=-W -Wall -O # $(WARNMORE) -g\nLDFLAGS=-L. -R. -L$(ZLIBLIB) -R$(ZLIBLIB) -lpng16 -lz -lm\n\nINCPATH=$(prefix)/include\nLIBPATH=$(exec_prefix)/lib\nMANPATH=$(prefix)/man\nBINPATH=$(exec_prefix)/bin\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\nDB=$(DESTDIR)$(BINPATH)\nDI=$(DESTDIR)$(INCPATH)\nDL=$(DESTDIR)$(LIBPATH)\nDM=$(DESTDIR)$(MANPATH)\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\nOBJSDLL = $(OBJS:.o=.pic.o)\n\n.SUFFIXES:      .c .o .pic.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\n.c.pic.o:\n\t$(CC) -c $(CFLAGS) -fPIC -o $@ $*.c\n\nall: libpng.a $(LIBSO) pngtest libpng.pc libpng-config\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@ $(OBJS)\n\t$(RANLIB) $@\n\nlibpng.pc:\n\tcat scripts/libpng.pc.in | sed -e s!@prefix@!$(prefix)! \\\n\t-e s!@exec_prefix@!$(exec_prefix)! \\\n\t-e s!@libdir@!$(LIBPATH)! \\\n\t-e s!@includedir@!$(INCPATH)! \\\n\t-e s!-lpng16!-lpng16\\ -lz\\ -lm! > libpng.pc\n\nlibpng-config:\n\t( cat scripts/libpng-config-head.in; \\\n\techo prefix=\\\"$(prefix)\\\"; \\\n\techo I_opts=\\\"-I$(INCPATH)/$(LIBNAME)\\\"; \\\n\techo cppflags=\\\"\"; \\\n\techo L_opts=\\\"-L$(LIBPATH)\\\"; \\\n\techo R_opts=\\\"-R$(LIBPATH)\\\"; \\\n\techo libs=\\\"-lpng16 -lz -lm\\\"; \\\n\tcat scripts/libpng-config-body.in ) > libpng-config\n\tchmod +x libpng-config\n\n$(LIBSO): $(LIBSOMAJ)\n\t$(LN_SF) $(LIBSOMAJ) $(LIBSO)\n\n$(LIBSOMAJ): $(OBJSDLL)\n\t@case \"`type ld`\" in *ucb*) \\\n\techo; \\\n\techo '## WARNING:'; \\\n\techo '## The commands \"CC\" and \"LD\" must NOT refer to /usr/ucb/cc'; \\\n\techo '## and /usr/ucb/ld.  If they do, you need to adjust your PATH'; \\\n\techo '## environment variable to put /usr/ccs/bin ahead of /usr/ucb.'; \\\n\techo '## The environment variable LD_LIBRARY_PATH should not be set'; \\\n\techo '## at all.  If it is, things are likely to break because of'; \\\n\techo '## the libucb dependency that is created.'; \\\n\techo; \\\n\t;; \\\n\tesac\n\t$(LD) -G -h $(LIBSOMAJ) \\\n\t -o $(LIBSOMAJ) $(OBJSDLL)\n\npngtest: pngtest.o $(LIBSO)\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall-headers: png.h pngconf.h pnglibconf.h\n\t-@if [ ! -d $(DI) ]; then $(MKDIR_P) $(DI); fi\n\t-@if [ ! -d $(DI)/$(LIBNAME) ]; then $(MKDIR_P) $(DI)/$(LIBNAME); fi\n\tcp png.h pngconf.h pnglibconf.h $(DI)/$(LIBNAME)\n\tchmod 644 $(DI)/$(LIBNAME)/png.h $(DI)/$(LIBNAME)/pngconf.h $(DI)/$(LIBNAME)/pnglibconf.h\n\t-@$(RM_F) $(DI)/png.h $(DI)/pngconf.h $(DI)/pnglibconf.h\n\t-@$(RM_F) $(DI)/libpng\n\t(cd $(DI); $(LN_SF) $(LIBNAME) libpng; $(LN_SF) $(LIBNAME)/* .)\n\ninstall-static: install-headers libpng.a\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\tcp libpng.a $(DL)/$(LIBNAME).a\n\tchmod 644 $(DL)/$(LIBNAME).a\n\t-@$(RM_F) $(DL)/libpng.a\n\t(cd $(DL); $(LN_SF) $(LIBNAME).a libpng.a)\n\ninstall-shared: install-headers $(LIBSOMAJ) libpng.pc\n\t-@if [ ! -d $(DL) ]; then $(MKDIR_P) $(DL); fi\n\t-@$(RM_F) $(DL)/$(LIBSO)\n\t-@$(RM_F) $(DL)/$(LIBSOREL)\n\t-@$(RM_F) $(DL)/$(OLDSO)\n\tcp $(LIBSOMAJ) $(DL)/$(LIBSOREL)\n\tchmod 755 $(DL)/$(LIBSOREL)\n\t(cd $(DL); \\\n\t$(LN_SF) $(LIBSOREL) $(LIBSO); \\\n\t$(LN_SF) $(LIBSO) $(OLDSO))\n\t-@if [ ! -d $(DL)/pkgconfig ]; then $(MKDIR_P) $(DL)/pkgconfig; fi\n\t-@$(RM_F) $(DL)/pkgconfig/$(LIBNAME).pc\n\t-@$(RM_F) $(DL)/pkgconfig/libpng.pc\n\tcp libpng.pc $(DL)/pkgconfig/$(LIBNAME).pc\n\tchmod 644 $(DL)/pkgconfig/$(LIBNAME).pc\n\t(cd $(DL)/pkgconfig; $(LN_SF) $(LIBNAME).pc libpng.pc)\n\ninstall-man: libpng.3 libpngpf.3 png.5\n\t-@if [ ! -d $(DM) ]; then $(MKDIR_P) $(DM); fi\n\t-@if [ ! -d $(DM)/man3 ]; then $(MKDIR_P) $(DM)/man3; fi\n\t-@$(RM_F) $(DM)/man3/libpng.3\n\t-@$(RM_F) $(DM)/man3/libpngpf.3\n\tcp libpng.3 $(DM)/man3\n\tcp libpngpf.3 $(DM)/man3\n\t-@if [ ! -d $(DM)/man5 ]; then $(MKDIR_P) $(DM)/man5; fi\n\t-@$(RM_F) $(DM)/man5/png.5\n\tcp png.5 $(DM)/man5\n\ninstall-config: libpng-config\n\t-@if [ ! -d $(DB) ]; then $(MKDIR_P) $(DB); fi\n\t-@$(RM_F) $(DB)/libpng-config\n\t-@$(RM_F) $(DB)/$(LIBNAME)-config\n\tcp libpng-config $(DB)/$(LIBNAME)-config\n\tchmod 755 $(DB)/$(LIBNAME)-config\n\t(cd $(DB); $(LN_SF) $(LIBNAME)-config libpng-config)\n\ninstall: install-static install-shared install-man install-config\n\n# If you installed in $(DESTDIR), test-installed won't work until you\n# move the library to its final location.  Use test-dd to test it\n# before then.\n\ntest-dd:\n\techo\n\techo Testing installed dynamic shared library in $(DL).\n\t$(CC) -I$(DI) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtestd `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(DL) -L$(ZLIBLIB) -R$(ZLIBLIB) -R$(DL)\n\t./pngtestd pngtest.png\n\ntest-installed:\n\techo\n\techo Testing installed dynamic shared library.\n\t$(CC) $(CPPFLAGS) \\\n\t   `$(BINPATH)/$(LIBNAME)-config --cflags` pngtest.c \\\n\t   -o pngtesti `$(BINPATH)/$(LIBNAME)-config --ldflags` \\\n\t   -L$(ZLIBLIB) -R$(ZLIBLIB)\n\t./pngtesti pngtest.png\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngtesti pngout.png \\\n\tlibpng-config $(LIBSO) $(LIBSOMAJ)* \\\n\tlibpng.pc pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o png.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o pngerror.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o pngrio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o pngwio.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o pngmem.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o pngset.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o pngget.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o pngread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o pngrtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o pngrutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o pngtrans.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o pngwrite.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o pngwtran.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o pngwutil.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o pngpread.pic.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.std",
    "content": "# makefile for libpng\n# Copyright (C) 2002, 2006, 2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\nCC = cc\nAR_RC = ar rc\nMKDIR_P = mkdir\nLN_SF = ln -sf\nRANLIB = ranlib\nCP = cp\nRM_F = rm -f\nAWK = awk\nSED = sed\nCPP = $(CC) -E\nECHO = echo\n\nDFNFLAGS = # DFNFLAGS contains -D options to use in the libpng build\nDFA_EXTRA = # extra files that can be used to control configuration\nCPPFLAGS = -I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS = -O # -g\nLDFLAGS = -L. -L$(ZLIBLIB) -lpng -lz -lm\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest\n\n# The standard pnglibconf.h exists as scripts/pnglibconf.h.prebuilt,\n# copy this if the following doesn't work.\npnglibconf.h: pnglibconf.dfn\n\t$(RM_F) $@ pnglibconf.c pnglibconf.out pnglibconf.tmp\n\t$(ECHO) '#include \"pnglibconf.dfn\"' >pnglibconf.c\n\t$(ECHO) \"If '$(CC) -E' crashes try /lib/cpp (e.g. CPP='/lib/cpp')\" >&2\n\t$(CPP) $(DFNFLAGS) pnglibconf.c >pnglibconf.out\n\t$(AWK) -f \"scripts/dfn.awk\" out=\"pnglibconf.tmp\" pnglibconf.out 1>&2\n\tmv pnglibconf.tmp $@\n\npnglibconf.dfn: scripts/pnglibconf.dfa scripts/options.awk pngconf.h pngusr.dfa $(DFA_XTRA)\n\t$(RM_F) $@ pnglibconf.pre pnglibconf.tmp\n\t$(ECHO) \"Calling $(AWK) from scripts/pnglibconf.mak\" >&2\n\t$(ECHO) \"If 'awk' crashes try a better awk (e.g. AWK='nawk')\" >&2\n\t$(AWK) -f scripts/options.awk out=\"pnglibconf.pre\"\\\n\t    version=search pngconf.h scripts/pnglibconf.dfa\\\n\t    pngusr.dfa $(DFA_XTRA) 1>&2\n\t$(AWK) -f scripts/options.awk out=\"pnglibconf.tmp\" pnglibconf.pre 1>&2\n\tmv pnglibconf.tmp $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@  $(OBJS)\n\t$(RANLIB) $@\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall: libpng.a pnglibconf.h\n\t-@$(MKDIR_P) $(DESTDIR)$(INCPATH)\n\t-@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng\n\t-@$(MKDIR_P) $(DESTDIR)$(LIBPATH)\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/png.h\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/pnglibconf.h\n\tcp png.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pngconf.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h\n\t(cd $(DESTDIR)$(INCPATH); ln -f -s libpng/* .)\n\tcp libpng.a $(DESTDIR)$(LIBPATH)\n\tchmod 644 $(DESTDIR)$(LIBPATH)/libpng.a\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.h pnglibconf.c \\\n\tpnglibconf.out\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.sunos",
    "content": "# makefile for libpng\n# Copyright (C) 2002, 2006, 2014 Glenn Randers-Pehrson\n# Copyright (C) 1995 Guy Eric Schalnat, Group 42, Inc.\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# where make install puts libpng.a and png.h\nprefix=/usr/local\nINCPATH=$(prefix)/include\nLIBPATH=$(prefix)/lib\n\n# override DESTDIR= on the make install command line to easily support\n# installing into a temporary location.  Example:\n#\n#    make install DESTDIR=/tmp/build/libpng\n#\n# If you're going to install into a temporary location\n# via DESTDIR, $(DESTDIR)$(prefix) must already exist before\n# you execute make install.\nDESTDIR=\n\n# Where the zlib library and include files are located\n#ZLIBLIB=/usr/local/lib\n#ZLIBINC=/usr/local/include\nZLIBLIB=../zlib\nZLIBINC=../zlib\n\n\nWARNMORE=-Wwrite-strings -Wpointer-arith -Wshadow -Wconversion \\\n\t-Wmissing-declarations -Wtraditional -Wcast-align \\\n\t-Wstrict-prototypes -Wmissing-prototypes\n\nCC=gcc\nAR_RC=ar rc\nMKDIR_P=mkdir -p\nLN_SF=ln -f -s\nRANLIB=ranlib\nCP=cp\nRM_F=/bin/rm -f\n\nCPPFLAGS=-I$(ZLIBINC) # -DPNG_DEBUG=5\nCFLAGS=-O # $(WARNMORE)\nLDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -lm\n\n# Pre-built configuration\n# See scripts/pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts/pnglibconf.h.prebuilt\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o \\\n\tpngread.o pngrio.o pngwio.o pngwrite.o pngrtran.o \\\n\tpngwtran.o pngmem.o pngerror.o pngpread.o\n\n.c.o:\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<\n\nall: libpng.a pngtest\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\nlibpng.a: $(OBJS)\n\t$(AR_RC) $@  $(OBJS)\n\t$(RANLIB) $@\n\npngtest: pngtest.o libpng.a\n\t$(CC) -o pngtest $(CFLAGS) pngtest.o $(LDFLAGS)\n\ntest: pngtest\n\t./pngtest\n\ninstall: libpng.a\n\t-@$(MKDIR_P) $(DESTDIR)$(INCPATH)\n\t-@$(MKDIR_P) $(DESTDIR)$(INCPATH)/libpng\n\t-@$(MKDIR_P) $(DESTDIR)$(LIBPATH)\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/png.h\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/pngconf.h\n\t-@$(RM_F) $(DESTDIR)$(INCPATH)/pnglibconf.h\n\tcp png.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pngconf.h $(DESTDIR)$(INCPATH)/libpng\n\tcp pnglibconf.h $(DESTDIR)$(INCPATH)/libpng\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/png.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pngconf.h\n\tchmod 644 $(DESTDIR)$(INCPATH)/libpng/pnglibconf.h\n\t(cd $(DESTDIR)$(INCPATH); $(LN_SF) libpng/* .)\n\tcp libpng.a $(DESTDIR)$(LIBPATH)\n\tchmod 644 $(DESTDIR)$(LIBPATH)/libpng.a\n\nclean:\n\t$(RM_F) *.o libpng.a pngtest pngout.png pnglibconf.h\n\nDOCS = ANNOUNCE CHANGES INSTALL KNOWNBUG LICENSE README TODO Y2KINFO\nwritelock:\n\tchmod a-w *.[ch35] $(DOCS) scripts/*\n\n# DO NOT DELETE THIS LINE -- make depend depends on it.\n\npng.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngerror.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwio.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngmem.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngset.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngget.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngrutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngtrans.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwrite.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwtran.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngwutil.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\npngpread.o: png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\npngtest.o: png.h pngconf.h pnglibconf.h\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.tc3",
    "content": "# Makefile for libpng\n# TurboC/C++ (Note: All modules are compiled in C mode)\n\n# To use, do \"make -fmakefile.tc3\"\n\n# ----- Turbo C++ 3.0 -----\n\nMODEL=l\nCPPFLAGS=-I..\\zlib\nCFLAGS=-O2 -Z -m$(MODEL)\nCC=tcc\nLD=tcc\nLIB=tlib\nLDFLAGS=-m$(MODEL) -L..\\zlib\nCP=copy\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\n!ifndef PNGLIBCONF_H_PREBUILT\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n!endif\n\nO=.obj\nE=.exe\n\n# variables\nOBJS1 = png$(O) pngset$(O) pngget$(O) pngrutil$(O) pngtrans$(O) pngwutil$(O)\nOBJS2 = pngmem$(O) pngpread$(O) pngread$(O) pngerror$(O) pngwrite$(O)\nOBJS3 = pngrtran$(O) pngwtran$(O) pngrio$(O) pngwio$(O)\nOBJSL1 = +png$(O) +pngset$(O) +pngget$(O) +pngrutil$(O) +pngtrans$(O)\nOBJSL2 = +pngwutil$(O) +pngmem$(O) +pngpread$(O) +pngread$(O) +pngerror$(O)\nOBJSL3 = +pngwrite$(O) +pngrtran$(O) +pngwtran$(O) +pngrio$(O) +pngwio$(O)\n\nall: libpng$(MODEL).lib pngtest$(E)\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\npngtest: pngtest$(E)\n\ntest: pngtest$(E)\n\tpngtest$(E)\n\npng$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t\t  $(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngtest$(O): png.h pngconf.h pnglibconf.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\npngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c\n\nlibpng$(MODEL).lib: $(OBJS1) $(OBJS2) $(OBJS3)\n\t$(LIB) libpng$(MODEL) +$(OBJSL1)\n\t$(LIB) libpng$(MODEL) +$(OBJSL2)\n\t$(LIB) libpng$(MODEL) +$(OBJSL3)\n\npngtest$(E): pngtest$(O) libpng$(MODEL).lib\n\t$(LD) $(LDFLAGS) pngtest.obj libpng$(MODEL).lib zlib_$(MODEL).lib\n\n# End of makefile for libpng\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makefile.vcwin32",
    "content": "# makefile for libpng\n# Copyright (C) 1998 Tim Wegner\n# Copyright (C) 2006,2009,2011,2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n#\n# Assumes that zlib.lib, zconf.h, and zlib.h have been copied to ..\\zlib\n# To use, do \"nmake /f scripts\\makefile.vcwin32\"\n\n# -------- Microsoft Visual C++ 2.0 and later --------\n\n# Compiler, linker, librarian and other tools\nCC = cl\nLD = link\nAR = lib\nCPPFLAGS = -I..\\zlib\nCFLAGS  = -nologo -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -MD -O2 -W3\nLDFLAGS = -nologo\nARFLAGS = -nologo\nCP = copy\nRM = del\n\n# Pre-built configuration\n# See scripts\\pnglibconf.mak for more options\nPNGLIBCONF_H_PREBUILT = scripts\\pnglibconf.h.prebuilt\n\n# File extensions\nO=.obj\n\n#uncomment next to put error messages in a file\n#ERRFILE= >> pngerrs.log\n\n# Variables\nOBJS1 = png$(O) pngerror$(O) pngget$(O) pngmem$(O) pngpread$(O)\nOBJS2 = pngread$(O) pngrio$(O) pngrtran$(O) pngrutil$(O) pngset$(O)\nOBJS3 = pngtrans$(O) pngwio$(O) pngwrite$(O) pngwtran$(O) pngwutil$(O)\nOBJS  = $(OBJS1) $(OBJS2) $(OBJS3)\n\n# Targets\nall: libpng.lib\n\npnglibconf.h: $(PNGLIBCONF_H_PREBUILT)\n\t$(CP) $(PNGLIBCONF_H_PREBUILT) $@\n\npng$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngset$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngget$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngpread$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngerror$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngmem$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngrio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwio$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngtrans$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwrite$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwtran$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngwutil$(O): png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\nlibpng.lib: $(OBJS)\n\t-$(RM) $@\n\t$(AR) $(ARFLAGS) -out:$@ $(OBJS) $(ERRFILE)\n\npngtest$(O): png.h pngconf.h pnglibconf.h\n\t$(CC) -c $(CPPFLAGS) $(CFLAGS) $*.c $(ERRFILE)\n\npngtest.exe: pngtest$(O) libpng.lib\n\t$(LD) $(LDFLAGS) -out:$@ pngtest$(O) libpng.lib ..\\zlib\\zlib.lib $(ERRFILE)\n\ntest: pngtest.exe\n\tpngtest\n\nclean:\n\t-$(RM) *$(O)\n\t-$(RM) libpng.lib\n\t-$(RM) pnglibconf.h\n\t-$(RM) pngtest.exe\n\t-$(RM) pngout.png\n\n# End of makefile for libpng\n\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/makevms.com",
    "content": "$! make libpng under VMS\n$!\n$!\n$! Check for MMK/MMS\n$!\n$! This procedure accepts one parameter (contrib), which causes it to build\n$! the programs from the contrib directory instead of libpng.\n$!\n$ p1 = f$edit(p1,\"UPCASE\")\n$ if p1 .eqs. \"CONTRIB\"\n$ then\n$   set def [.contrib.gregbook]\n$   @makevms\n$   set def [-.pngminus]\n$   @makevms\n$   set def [--]\n$   exit\n$ endif\n$ Make = \"\"\n$ If F$Search (\"Sys$System:MMS.EXE\") .nes. \"\" Then Make = \"MMS\"\n$ If F$Type (MMK) .eqs. \"STRING\" Then Make = \"MMK\"\n$!\n$! Look for the compiler used\n$!\n$ zlibsrc = \"[-.zlib]\"\n$ ccopt=\"/include=''zlibsrc'\"\n$ if f$getsyi(\"HW_MODEL\").ge.1024\n$ then\n$  ccopt = \"/prefix=all\"+ccopt\n$  comp  = \"__decc__=1\"\n$  if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$ else\n$  if f$search(\"SYS$SYSTEM:DECC$COMPILER.EXE\").eqs.\"\"\n$   then\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys sys$library:\n$    if f$search(\"SYS$SYSTEM:VAXC.EXE\").eqs.\"\"\n$     then\n$      comp  = \"__gcc__=1\"\n$      CC :== GCC\n$     else\n$      comp = \"__vaxc__=1\"\n$     endif\n$   else\n$    if f$trnlnm(\"SYS\").eqs.\"\" then define sys decc$library_include:\n$    ccopt = \"/decc/prefix=all\"+ccopt\n$    comp  = \"__decc__=1\"\n$  endif\n$ endif\n$!\n$! Build the thing plain or with mms/mmk\n$!\n$ write sys$output \"Compiling Libpng sources ...\"\n$ if make.eqs.\"\"\n$  then\n$   dele pngtest.obj;*\n$   CALL MAKE png.OBJ \"cc ''CCOPT' png\" -\n\tpng.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngset.OBJ \"cc ''CCOPT' pngset\" -\n\tpngset.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngget.OBJ \"cc ''CCOPT' pngget\" -\n\tpngget.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngread.OBJ \"cc ''CCOPT' pngread\" -\n\tpngread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngpread.OBJ \"cc ''CCOPT' pngpread\" -\n\tpngpread.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngrtran.OBJ \"cc ''CCOPT' pngrtran\" -\n\tpngrtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngrutil.OBJ \"cc ''CCOPT' pngrutil\" -\n\tpngrutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngerror.OBJ \"cc ''CCOPT' pngerror\" -\n\tpngerror.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngmem.OBJ \"cc ''CCOPT' pngmem\" -\n\tpngmem.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngrio.OBJ \"cc ''CCOPT' pngrio\" -\n\tpngrio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngwio.OBJ \"cc ''CCOPT' pngwio\" -\n\tpngwio.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngtrans.OBJ \"cc ''CCOPT' pngtrans\" -\n\tpngtrans.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngwrite.OBJ \"cc ''CCOPT' pngwrite\" -\n\tpngwrite.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngwtran.OBJ \"cc ''CCOPT' pngwtran\" -\n\tpngwtran.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   CALL MAKE pngwutil.OBJ \"cc ''CCOPT' pngwutil\" -\n\tpngwutil.c png.h pngconf.h pnglibconf.h pngpriv.h pngstruct.h pnginfo.h pngdebug.h\n$   write sys$output \"Building Libpng ...\"\n$   CALL MAKE libpng.OLB \"lib/crea libpng.olb *.obj\" *.OBJ\n$   write sys$output \"Building pngtest...\"\n$   CALL MAKE pngtest.OBJ \"cc ''CCOPT' pngtest\" -\n\tpngtest.c png.h pngconf.h pnglibconf.h\n$   call make pngtest.exe -\n\t\"LINK pngtest,libpng.olb/lib,''zlibsrc'libz.olb/lib\" -\n\tpngtest.obj libpng.olb\n$   write sys$output \"Testing Libpng...\"\n$   run pngtest\n$  else\n$   if f$search(\"DESCRIP.MMS\") .eqs. \"\" then copy/nolog [.SCRIPTS]DESCRIP.MMS []\n$   'make'/macro=('comp',zlibsrc='zlibsrc')\n$  endif\n$ write sys$output \"Libpng build completed\"\n$ exit\n$!\n$!\n$MAKE: SUBROUTINE   !SUBROUTINE TO CHECK DEPENDENCIES\n$ V = 'F$Verify(0)\n$! P1 = What we are trying to make\n$! P2 = Command to make it\n$! P3 - P8  What it depends on\n$\n$ If F$Search(P1) .Eqs. \"\" Then Goto Makeit\n$ Time = F$CvTime(F$File(P1,\"RDT\"))\n$arg=3\n$Loop:\n$       Argument = P'arg\n$       If Argument .Eqs. \"\" Then Goto Exit\n$       El=0\n$Loop2:\n$       File = F$Element(El,\" \",Argument)\n$       If File .Eqs. \" \" Then Goto Endl\n$       AFile = \"\"\n$Loop3:\n$       OFile = AFile\n$       AFile = F$Search(File)\n$       If AFile .Eqs. \"\" .Or. AFile .Eqs. OFile Then Goto NextEl\n$       If F$CvTime(F$File(AFile,\"RDT\")) .Ges. Time Then Goto Makeit\n$       Goto Loop3\n$NextEL:\n$       El = El + 1\n$       Goto Loop2\n$EndL:\n$ arg=arg+1\n$ If arg .Le. 8 Then Goto Loop\n$ Goto Exit\n$\n$Makeit:\n$ VV=F$VERIFY(0)\n$ write sys$output P2\n$ 'P2\n$ VV='F$Verify(VV)\n$Exit:\n$ If V Then Set Verify\n$ENDSUBROUTINE\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/options.awk",
    "content": "#!/bin/awk -f\n# scripts/options.awk - library build configuration control\n#\n# last changed in libpng version 1.6.11 - June 5, 2014\n#\n# Copyright (c) 1998-2014 Glenn Randers-Pehrson\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\n# The output of this script is written to the file given by\n# the variable 'out'.  The script is run twice, once with\n# an intermediate output file, 'options.tmp' then again on\n# that file to produce the final output:\n#\n#  awk -f scripts/options.awk out=options.tmp scripts/options.dfa 1>&2\n#  awk -f scripts/options.awk out=options.dfn options.tmp 1>&2\n#\n# Some options may be specified on the command line:\n#\n#  deb=1            Causes debugging to be output\n#  logunsupported=1 Causes all options to be recorded in the output\n#  everything=off   Causes all options to be disabled by default\n#  everything=on    Causes all options to be enabled by default\n#\n# If awk fails on your platform, try nawk instead.\n#\n# These options may also be specified in the original input file (and\n# are copied to the preprocessed file).\n\nBEGIN{\n   out=\"\"                       # intermediate, preprocessed, file\n   pre=-1                       # preprocess (first line)\n   version=\"libpng version unknown\" # version information\n   version_file=\"\"              # where to find the version\n   err=0                        # in-line exit sets this\n   # The following definitions prevent the C preprocessor noticing the lines\n   # that will be in the final output file.  Some C preprocessors tokenise\n   # the lines, for example by inserting spaces around operators, and all\n   # C preprocessors notice lines that start with '#', most remove comments.\n   # The technique adopted here is to make the final output lines into\n   # C strings (enclosed in double quotes), preceeded by PNG_DFN.  As a\n   # consequence the output cannot contain a 'raw' double quote - instead put\n   # @' in, this will be replaced by a single \" afterward.  See the parser\n   # script dfn.awk for more capabilities (not required here).  Note that if\n   # you need a \" in a 'setting' in pnglibconf.dfa it must also be @'!\n   dq=\"@'\"                      # For a single double quote\n   start=\" PNG_DFN \\\"\"          # Start stuff to output (can't contain a \"!)\n   end=\"\\\" \"                    # End stuff to output\n   subs=\"@\\\" \"                  # Substitute start (substitute a C macro)\n   sube=\" \\\"@\"                  # Substitute end\n   comment=start \"/*\"           # Comment start\n   cend=\"*/\" end                # Comment end\n   def=start \"#define PNG_\"     # Arbitrary define\n   sup=\"_SUPPORTED\" end         # end supported option\n   und=comment \"#undef PNG_\"    # Unsupported option\n   une=\"_SUPPORTED\" cend        # end unsupported option\n   error=start \"ERROR:\"         # error message, terminate with 'end'\n\n   # Variables\n   deb=0                        # debug - set on command line\n   everything=\"\"                # do not override defaults\n   logunsupported=0             # write unsupported options too\n\n   # Precreate arrays\n   # for each option:\n   option[\"\"] = \"\"    # list of all options: default enabled/disabled\n   done[\"\"] = 1       # marks option as having been output\n   requires[\"\"] = \"\"  # requires by option\n   iffs[\"\"] = \"\"      # if by option\n   enabledby[\"\"] = \"\" # options that enable it by option\n   sets[\"\"] = \"\"      # settings set by each option\n   setval[\"\"] = \"\"    # value to set (indexed: 'option sets[option]')\n   # for each setting:\n   setting[\"\"] = \"\"   # requires by setting\n   defaults[\"\"] = \"\"  # used for a defaulted value\n   doneset[\"\"] = 1    # marks setting as having been output\n   r[\"\"] = \"\"         # Temporary array\n\n   # For decorating the output file\n   protect = \"\"\n}\n\n# The output file must be specified before any input:\nout == \"\" {\n   print \"out=output.file must be given on the command line\"\n   err = 1\n   exit 1\n}\n\n# The very first line indicates whether we are reading pre-processed\n# input or not, this must come *first* because 'PREPROCESSED' needs\n# to be the very first line in the temporary file.\npre == -1{\n   if ($0 == \"PREPROCESSED\") {\n      pre = 0\n      next\n   } else {\n      pre = 1\n      print \"PREPROCESSED\" >out\n      # And fall through to continue processing\n   }\n}\n\n# While pre-processing if version is set to \"search\" look for a version string\n# in the following file.\npre && version == \"search\" && version_file == \"\"{\n   version_file = FILENAME\n}\n\npre && version == \"search\" && version_file != FILENAME{\n   print \"version string not found in\", version_file\n   err = 1\n   exit 1\n}\n\npre && version == \"search\" && $0 ~ /^ \\* libpng version/{\n   version = substr($0, 4)\n   print \"version =\", version >out\n   next\n}\n\npre && FILENAME == version_file{\n   next\n}\n\n# variable=value\n#   Sets the given variable to the given value (the syntax is fairly\n#   free form, except for deb (you are expected to understand how to\n#   set the debug variable...)\n#\n#   This happens before the check on 'pre' below skips most of the\n#   rest of the actions, so the variable settings happen during\n#   preprocessing but are recorded in the END action too.  This\n#   allows them to be set on the command line too.\n$0 ~ /^[ \t]*version[ \t]*=/{\n   sub(/^[  ]*version[  ]*=[  ]*/, \"\")\n   version = $0\n   next\n}\n$0 ~ /^[ \t]*everything[ \t=]*off[ \t]*$/{\n   everything = \"off\"\n   next\n}\n$0 ~ /^[ \t]*everything[ \t=]*on[ \t]*$/{\n   everything = \"on\"\n   next\n}\n$0 ~ /^[ \t]*logunsupported[ \t=]*0[ \t]*$/{\n   logunsupported = 0\n   next\n}\n$0 ~ /^[ \t]*logunsupported[ \t=]*1[ \t]*$/{\n   logunsupported = 1\n   next\n}\n$1 == \"deb\" && $2 == \"=\" && NF == 3{\n   deb = $3\n   next\n}\n\n# Preprocessing - this just copies the input file with lines\n# that need preprocessing (just chunk at present) expanded\n# The bare \"pre\" instead of \"pre != 0\" crashes under Sunos awk\npre && $1 != \"chunk\"{\n   print >out\n   next\n}\n\n# The first characters of the line determine how it is processed,\n# leading spaces are ignored.  In general tokens that are not\n# keywords are the names of options.  An option 'name' is\n# controlled by the definition of the corresponding macros:\n#\n#   PNG_name_SUPPORTED    The option is turned on\n#   PNG_NO_name\n#   PNG_NO_name_SUPPORTED If the first macro is not defined\n#                         either of these will turn the option off\n#\n# If none of these macros are defined the option is turned on, unless\n# the keyword 'off' is given in a line relating to the option.  The\n# keyword 'on' can also be given, but it will be ignored (since it is\n# the default.)\n#\n# In the syntax below a 'name' is indicated by \"NAME\", other macro\n# values are indicated by \"MACRO\", as with \"NAME\" the leading \"PNG_\"\n# is omitted, but in this case the \"NO_\" prefix and the \"_SUPPORTED\"\n# suffix are never used.\n#\n# Each line is introduced by a keyword - the first non-space characters\n# on the line.  A line starting with a '#' is a comment - it is totally\n# ignored.  Keywords are as follows, a NAME, is simply a macro name\n# without the leading PNG_, PNG_NO_ or the trailing _SUPPORTED.\n\n$1 ~ /^#/ || $0 ~ /^[ \t]*$/{\n   next\n}\n\n# com <comment>\n#   The whole line is placed in the output file as a comment with\n#   the preceding 'com' removed\n$1 == \"com\"{\n   if (NF > 1) {\n      # sub(/^[ \t]*com[ \t]*/, \"\")\n      $1 = \"\"\n      print comment $0, cend >out\n   } else\n      print start end >out\n   next\n}\n\n# version\n#   Inserts a version comment\n$1 == \"version\" && NF == 1{\n   if (version == \"\") {\n      print \"ERROR: no version string set\"\n      err = 1 # prevent END{} running\n      exit 1\n   }\n\n   print comment, version, cend >out\n   next\n}\n\n# file output input protect\n#   Informational: the official name of the input file (without\n#   make generated local directories), the official name of the\n#   output file and, if required, a name to use in a protection\n#   macro for the contents.\n$1 == \"file\" && NF >= 2{\n   print comment, $2, cend >out\n   print comment, \"Machine generated file: DO NOT EDIT\", cend >out\n   if (NF >= 3)\n      print comment, \"Derived from:\", $3, cend >out\n   protect = $4\n   if (protect != \"\") {\n      print start \"#ifndef\", protect end >out\n      print start \"#define\", protect end >out\n   }\n   next\n}\n\n# option NAME ( (requires|enables|if) NAME* | on | off | disabled |\n#                sets SETTING VALUE+ )*\n#     \n#   Declares an option 'NAME' and describes its default setting (disabled)\n#   and its relationship to other options.  The option is disabled\n#   unless *all* the options listed after 'requires' are set and at\n#   least one of the options listed after 'if' is set.  If the\n#   option is set then it turns on all the options listed after 'enables'.\n#\n#   Note that \"enables\" takes priority over the required/if/disabled/off\n#   setting of the target option.\n#\n#   The definition file may list an option as 'disabled': off by default,\n#   otherwise the option is enabled: on by default.  A later (and it must\n#   be later) entry may turn an option on or off explicitly.\n\n$1 == \"option\" && NF >= 2{\n   opt = $2\n   sub(/,$/,\"\",opt)\n   onoff = option[opt]  # records current (and the default is \"\", enabled)\n   key = \"\"\n   istart = 3\n   do {\n      if (istart == 1) {     # continuation line\n         val = getline\n\n         if (val != 1) { # error reading it\n            if (val == 0)\n               print \"option\", opt \": ERROR: missing continuation line\"\n            else\n               print \"option\", opt \": ERROR: error reading continuation line\"\n\n            # This is a hard error\n            err = 1 # prevent END{} running\n            exit 1\n         }\n      }\n\n      for (i=istart; i<=NF; ++i) {\n         val=$(i)\n         sub(/,$/,\"\",val)\n         if (val == \"on\" || val == \"off\" || val == \"disabled\" || val ==\"enabled\") {\n            key = \"\"\n            if (onoff != val) {\n               # on or off can zap disabled or enabled:\n               if (onoff == \"\" || (onoff == \"disabled\" || onoff == \"enabled\") &&\n                   (val == \"on\" || val == \"off\")) {\n                  # It's easy to mis-spell the option when turning it\n                  # on or off, so warn about it here:\n                  if (onoff == \"\" && (val == \"on\" || val == \"off\")) {\n                     print \"option\", opt \": ERROR: turning unrecognized option\", val\n                     # For the moment error out - it is safer\n                     err = 1 # prevent END{} running\n                     exit 1\n                  }\n                  onoff = val\n               } else {\n                  # Print a message, otherwise the error\n                  # below is incomprehensible\n                  print \"option\", opt \": currently\", onoff \": attempt to turn\", val\n                  break\n               }\n            }\n         } else if (val == \"requires\" || val == \"if\" || val == \"enables\" || val ==\"sets\") {\n            key = val\n         } else if (key == \"requires\") {\n            requires[opt] = requires[opt] \" \" val\n         } else if (key == \"if\") {\n            iffs[opt] = iffs[opt] \" \" val\n         } else if (key == \"enables\") {\n            enabledby[val] = enabledby[val] \" \" opt\n         } else if (key == \"sets\") {\n            sets[opt] = sets[opt] \" \" val\n            key = \"setval\"\n            set = val\n         } else if (key == \"setval\") {\n            setval[opt \" \" set] = setval[opt \" \" set] \" \" val\n         } else\n            break # bad line format\n      }\n\n      istart = 1\n   } while (i > NF && $0 ~ /,$/)\n\n   if (i > NF) {\n      # Set the option, defaulting to 'enabled'\n      if (onoff == \"\") onoff = \"enabled\"\n      option[opt] = onoff\n      next\n   }\n   # Else fall through to the error handler\n}\n\n# chunk NAME [requires OPT] [enables LIST] [on|off|disabled]\n#   Expands to the 'option' settings appropriate to the reading and\n#   writing of an ancilliary PNG chunk 'NAME':\n#\n#   option READ_NAME requires READ_ANCILLARY_CHUNKS [READ_OPT]\n#   option READ_NAME enables NAME LIST\n#   [option READ_NAME off]\n#   option WRITE_NAME requires WRITE_ANCILLARY_CHUNKS [WRITE_OPT]\n#   option WRITE_NAME enables NAME LIST\n#   [option WRITE_NAME off]\n\npre != 0 && $1 == \"chunk\" && NF >= 2{\n   # 'chunk' is handled on the first pass by writing appropriate\n   # 'option' lines into the intermediate file.\n   opt = $2\n   sub(/,$/,\"\",opt)\n   onoff = \"\"\n   reqread = \"\"\n   reqwrite = \"\"\n   enables = \"\"\n   req = 0\n   istart = 3\n   do {\n      if (istart == 1) {     # continuation line\n         val = getline\n\n         if (val != 1) { # error reading it\n            if (val == 0)\n               print \"chunk\", opt \": ERROR: missing continuation line\"\n            else\n               print \"chunk\", opt \": ERROR: error reading continuation line\"\n\n            # This is a hard error\n            err = 1 # prevent END{} running\n            exit 1\n         }\n      }\n\n      # read the keywords/additional OPTS\n      for (i=istart; i<=NF; ++i) {\n         val = $(i)\n         sub(/,$/,\"\",val)\n         if (val == \"on\" || val == \"off\" || val == \"disabled\") {\n            if (onoff != val) {\n               if (onoff == \"\")\n                  onoff = val\n               else\n                  break # on/off conflict\n            }\n            req = 0\n         } else if (val == \"requires\")\n            req = 1\n         else if (val == \"enables\")\n            req = 2\n         else if (req == 1){\n            reqread = reqread \" READ_\" val\n            reqwrite = reqwrite \" WRITE_\" val\n         } else if (req == 2)\n            enables = enables \" \" val\n         else\n            break # bad line: handled below\n      }\n\n      istart = 1\n   } while (i > NF && $0 ~ /,$/)\n\n   if (i > NF) {\n      # Output new 'option' lines to the intermediate file (out)\n      print \"option READ_\" opt, \"requires READ_ANCILLARY_CHUNKS\" reqread, \"enables\", opt enables , onoff >out\n      print \"option WRITE_\" opt, \"requires WRITE_ANCILLARY_CHUNKS\" reqwrite, \"enables\", opt enables, onoff >out\n      next\n   }\n   # Else hit the error handler below - bad line format!\n}\n\n# setting MACRO ( requires MACRO* )* [ default VALUE ]\n#   Behaves in a similar way to 'option' without looking for NO_ or\n#   _SUPPORTED; the macro is enabled if it is defined so long as all\n#   the 'requires' macros are also defined.  The definitions may be\n#   empty, an error will be issued if the 'requires' macros are\n#   *not* defined.  If given the 'default' value is used if the\n#   macro is not defined.  The default value will be re-tokenised.\n#   (BTW: this is somewhat restrictive, it mainly exists for the\n#   support of non-standard configurations and numeric parameters,\n#   see the uses in scripts/options.dat\n\n$1 == \"setting\" && (NF == 2 || NF >= 3 && ($3 == \"requires\" || $3 == \"default\")){\n   reqs = \"\"\n   deflt = \"\"\n   isdef = 0\n   key = \"\"\n   for (i=3; i<=NF; ++i)\n      if ($(i) == \"requires\" || $(i) == \"default\") {\n         key = $(i)\n         if (key == \"default\") isdef = 1\n      } else if (key == \"requires\")\n         reqs = reqs \" \" $(i)\n      else if (key == \"default\")\n         deflt = deflt \" \" $(i)\n      else\n         break # Format error, handled below\n\n   setting[$2] = reqs\n   # NOTE: this overwrites a previous value silently\n   if (isdef && deflt == \"\")\n      deflt = \" \" # as a flag to force output\n   defaults[$2] = deflt\n   next\n}\n\n# The order of the dependency lines (option, chunk, setting) is irrelevant\n# - the 'enables', 'requires' and 'if' settings will be used to determine\n# the correct order in the output and the final values in pnglibconf.h are\n# not order dependent.  'requires' and 'if' entries take precedence over\n# 'enables' from other options; if an option requires another option it\n# won't be set regardless of any options that enable it unless the other\n# option is also enabled.\n#\n# Similarly 'enables' trumps a NO_ definition in CFLAGS or pngusr.h\n#\n# For simplicity cycles in the definitions are regarded as errors,\n# even if they are not ambiguous.\n# A given NAME can be specified in as many 'option' lines as required, the\n# definitions are additive.\n\n# For backwards compatibility equivalent macros may be listed thus:\n#\n# = [NO_]NAME MACRO\n#   Makes -DMACRO equivalent to -DPNG_NO_NAME or -DPNG_NAME_SUPPORTED\n#   as appropriate.\n#\n# The definition is injected into the C compiler input when encountered\n# in the second pass (so all these definitions appear *after* the @\n# lines!)\n#\n# 'NAME' is as above, but 'MACRO' is the full text of the equivalent\n# old, deprecated, macro.\n\n$1 == \"=\" && NF == 3{\n   print \"#ifdef PNG_\" $3 >out\n   if ($2 ~ /^NO_/)\n      print \"#   define PNG_\" $2 >out\n   else\n      print \"#   define PNG_\" $2 \"_SUPPORTED\" >out\n   print \"#endif\" >out\n   next\n}\n\n# Lines may be injected into the C compiler input by preceding them\n# with an \"@\" character.  The line is copied with just the leading\n# @ removed.\n\n$1 ~ /^@/{\n   # sub(/^[ \t]*@/, \"\")\n   $1 = substr($1, 2)\n   print >out\n   next\n}\n\n# Check for unrecognized lines, because of the preprocessing chunk\n# format errors will be detected on the first pass independent of\n# any other format errors.\n{\n   print \"options.awk: bad line (\" NR \"):\", $0\n   err = 1 # prevent END{} running\n   exit 1\n}\n\n# For checking purposes names that start with \"ok_\" or \"fail_\" are\n# not output to pnglibconf.h and must be either enabled or disabled\n# respectively for the build to succeed.  This allows interdependencies\n# between options of the form \"at least one of\" or \"at most one of\"\n# to be checked.  For example:\n#\n# option FLOATING_POINT enables ok_math\n# option FIXED_POINT enables ok_math\n#   This ensures that at least one of FLOATING_POINT and FIXED_POINT\n#   must be set for the build to succeed.\n#\n# option fail_math requires FLOATING_POINT FIXED_POINT\n#   This means the build will fail if *both* FLOATING_POINT and\n#   FIXED_POINT are set (this is an example; in fact both are allowed.)\n#\n# If all these options were given the build would require exactly one\n# of the names to be enabled.\n\nEND{\n   # END{} gets run on an exit (a traditional awk feature)\n   if (err) exit 1\n\n   if (pre) {\n      # Record the final value of the variables\n      print \"deb =\", deb >out\n      if (everything != \"\") {\n         print \"everything =\", everything >out\n      }\n      print \"logunsupported =\", logunsupported >out\n      exit 0\n   }\n\n   # Do the options first (allowing options to set settings).  The dependency\n   # tree is thus:\n   #\n   #   name     >     name\n   #   name requires  name\n   #   name if        name\n   #   name enabledby name\n   #\n   # First build a list 'tree' by option of all the things on which\n   # it depends.\n   print \"\" >out\n   print \"/* OPTIONS */\" >out\n   print comment, \"options\", cend >out\n   for (opt in enabledby) tree[opt] = 1  # may not be explicit options\n   for (opt in option) if (opt != \"\") {\n      o = option[opt]\n      # option should always be one of the following values\n      if (o != \"on\" && o != \"off\" && o != \"disabled\" && o != \"enabled\") {\n         print \"internal option error (\" o \")\"\n         exit 1\n      }\n      tree[opt] = \"\"   # so unlisted options marked\n   }\n   for (opt in tree) if (opt != \"\") {\n      if (tree[opt] == 1) {\n         tree[opt] = \"\"\n         if (option[opt] != \"\") {\n            print \"internal error (1)\"\n            exit 1\n         }\n         # Macros only listed in 'enables' remain off unless\n         # one of the enabling macros is on.\n         option[opt] = \"disabled\"\n      }\n\n      split(\"\", list) # clear 'list'\n      # Now add every requires, iffs or enabledby entry to 'list'\n      # so that we can add a unique list of requirements to tree[i]\n      split(requires[opt] iffs[opt] enabledby[opt], r)\n      for (i in r) list[r[i]] = 1\n      for (i in list) tree[opt] = tree[opt] \" \" i\n   }\n\n   # print the tree for extreme debugging\n   if (deb > 2) for (i in tree) if (i != \"\") print i, \"depends-on\" tree[i]\n\n   # Ok, now check all options marked explicitly 'on' or 'off':\n   #\n   # If an option[opt] is 'on' then turn on all requires[opt]\n   # If an option[opt] is 'off' then turn off all enabledby[opt]\n   #\n   # Error out if we have to turn 'on' to an 'off' option or vice versa.\n   npending = 0\n   for (opt in option) if (opt != \"\") {\n      if (option[opt] == \"on\" || option[opt] == \"off\") {\n         pending[++npending] = opt\n      }\n   }\n\n   err = 0 # set on error\n   while (npending > 0) {\n      opt = pending[npending--]\n      if (option[opt] == \"on\") {\n         nreqs = split(requires[opt], r)\n         for (j=1; j<=nreqs; ++j) {\n            if (option[r[j]] == \"off\") {\n               print \"option\", opt, \"turned on, but requirement\", r[j], \"is turned off\"\n               err = 1\n            } else if (option[r[j]] != \"on\") {\n               option[r[j]] = \"on\"\n               pending[++npending] = r[j]\n            }\n         }\n      } else {\n         if (option[opt] != \"off\") {\n            print \"internal error (2)\"\n            exit 1\n         }\n         nreqs = split(enabledby[opt], r)\n         for (j=1; j<=nreqs; ++j) {\n            if (option[r[j]] == \"on\") {\n               print \"option\", opt, \"turned off, but enabled by\", r[j], \"which is turned on\"\n               err = 1\n            } else if (option[r[j]] != \"off\") {\n               option[r[j]] = \"off\"\n               pending[++npending] = r[j]\n            }\n         }\n      }\n   }\n   if (err) exit 1\n\n   # Sort options:\n   print \"PNG_DFN_START_SORT 2\" >out\n\n   # option[i] is now the complete list of all the tokens we may\n   # need to output, go through it as above, depth first.\n   finished = 0\n   while (!finished) {\n      finished = 1\n      movement = 0 # done nothing\n      for (i in option) if (!done[i]) {\n         nreqs = split(tree[i], r)\n         if (nreqs > 0) {\n            for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {\n               break\n            }\n            if (j<=nreqs) {\n               finished = 0\n               continue  # next option\n            }\n         }\n\n         # All the requirements have been processed, output\n         # this option.  An option is _SUPPORTED if:\n         #\n         # all 'requires' are _SUPPORTED AND\n         # at least one of the 'if' options are _SUPPORTED AND\n         # EITHER:\n         #   The name is _SUPPORTED (on the command line)\n         # OR:\n         #   an 'enabledby' is _SUPPORTED\n         # OR:\n         #   NO_name is not defined AND\n         #   the option is not disabled; an option is disabled if:\n         #    option == off\n         #    option == disabled && everything != on\n         #    option == \"\" && everything == off\n         if (deb) print \"option\", i\n         print \"\" >out\n         print \"/* option:\", i, option[i] >out\n         print \" *   requires:  \" requires[i] >out\n         print \" *   if:        \" iffs[i] >out\n         print \" *   enabled-by:\" enabledby[i] >out\n         print \" *   sets:      \" sets[i], \"*/\" >out\n         print \"#undef PNG_on\" >out\n         print \"#define PNG_on 1\" >out\n\n         # requires\n         nreqs = split(requires[i], r)\n         for (j=1; j<=nreqs; ++j) {\n            print \"#ifndef PNG_\" r[j] \"_SUPPORTED\" >out\n            print \"#   undef PNG_on /*!\" r[j] \"*/\" >out\n            # This error appears in the final output if something\n            # was switched 'on' but the processing above to force\n            # the requires did not work\n            if (option[i] == \"on\") {\n               print error, i, \"requires\", r[j] end >out\n            }\n            print \"#endif\" >out\n         }\n\n         # if\n         have_ifs = 0\n         nreqs = split(iffs[i], r)\n         print \"#undef PNG_no_if\" >out\n         if (nreqs > 0) {\n            have_ifs = 1\n            print \"/* if\" iffs[i], \"*/\" >out\n            print \"#define PNG_no_if 1\" >out\n            for (j=1; j<=nreqs; ++j) {\n               print \"#ifdef PNG_\" r[j] \"_SUPPORTED\" >out\n               print \"#   undef PNG_no_if /*\" r[j] \"*/\" >out\n               print \"#endif\" >out\n            }\n            print \"#ifdef PNG_no_if /*missing if*/\" >out\n            print \"#   undef PNG_on\" >out\n            # There is no checking above for this, because we\n            # don't know which 'if' to choose, so whine about\n            # it here:\n            if (option[i] == \"on\") {\n               print error, i, \"needs one of:\", iffs[i] end >out\n            }\n            print \"#endif\" >out\n         }\n\n         print \"#ifdef PNG_on /*requires, if*/\" >out\n         # enables\n         print \"#   undef PNG_not_enabled\" >out\n         print \"#   define PNG_not_enabled 1\" >out\n         print \"   /* enabled by\" enabledby[i], \"*/\" >out\n         nreqs = split(enabledby[i], r)\n         for (j=1; j<=nreqs; ++j) {\n            print \"#ifdef PNG_\" r[j] \"_SUPPORTED\" >out\n            print \"#   undef PNG_not_enabled /*\" r[j] \"*/\" >out\n            # Oops, probably not intended (should be factored\n            # out by the checks above).\n            if (option[i] == \"off\") {\n               print error, i, \"enabled by:\", r[j] end >out\n            }\n            print \"#endif\" >out\n         }\n\n         print \"#   ifndef PNG_\" i \"_SUPPORTED /*!command line*/\" >out\n         print \"#    ifdef PNG_not_enabled /*!enabled*/\" >out\n         # 'have_ifs' here means that everything = \"off\" still allows an 'if' on\n         # an otherwise enabled option to turn it on; otherwise the 'if'\n         # handling is effectively disabled by 'everything = off'\n         if (option[i] == \"off\" || option[i] == \"disabled\" && everything != \"on\" || option[i] == \"enabled\" && everything == \"off\" && !have_ifs) {\n            print \"#      undef PNG_on /*default off*/\" >out\n         } else {\n            print \"#      ifdef PNG_NO_\" i >out\n            print \"#       undef PNG_on /*turned off*/\" >out\n            print \"#      endif\" >out\n            print \"#      ifdef PNG_NO_\" i \"_SUPPORTED\" >out\n            print \"#       undef PNG_on /*turned off*/\" >out\n            print \"#      endif\" >out\n         }\n         print \"#    endif /*!enabled*/\" >out\n         print \"#    ifdef PNG_on\" >out\n         # The _SUPPORTED macro must be defined so that dependent\n         # options output later work.\n         print \"#      define PNG_\" i \"_SUPPORTED\" >out\n         print \"#    endif\" >out\n         print \"#   endif /*!command line*/\" >out\n         # If PNG_on is still set the option should be defined in\n         # pnglibconf.h\n         print \"#   ifdef PNG_on\" >out\n         if (i ~ /^fail_/) {\n            print error, i, \"is on: enabled by:\" iffs[i] enabledby[i] \", requires\" requires[i] end >out\n         } else if (i !~ /^ok_/) {\n            print def i sup >out\n            # Supported option, set required settings\n            nreqs = split(sets[i], r)\n            for (j=1; j<=nreqs; ++j) {\n               print \"#    ifdef PNG_set_\" r[j] >out\n               # Some other option has already set a value:\n               print error, i, \"sets\", r[j] \": duplicate setting\" end >out\n               print error, \"   previous value: \" end \"PNG_set_\" r[j] >out\n               print \"#    else\" >out\n               # Else set the default: note that this won't accept arbitrary\n               # values, the setval string must be acceptable to all the C\n               # compilers we use.  That means it must be VERY simple; a number,\n               # a name or a string.\n               print \"#     define PNG_set_\" r[j], setval[i \" \" r[j]] >out\n               print \"#    endif\" >out\n            }\n         }\n         print \"#   endif /* definition */\" >out\n         print \"#endif /*requires, if*/\" >out\n         if (logunsupported || i ~ /^ok_/) {\n            print \"#ifndef  PNG_on\" >out\n            if (logunsupported) {\n               print und i une >out\n            }\n            if (i ~ /^ok_/) {\n               print error, i, \"not enabled: requires:\" requires[i] \", enabled by:\" iffs[i] enabledby[i] end >out\n            }\n            print \"#endif\" >out\n         }\n\n         done[i] = 1\n         ++movement\n      }\n\n      if (!finished && !movement) {\n         print \"option: loop or missing option in dependency tree, cannot process:\"\n         for (i in option) if (!done[i]) {\n            print \"  option\", i, \"depends on\" tree[i], \"needs:\"\n            nreqs = split(tree[i], r)\n            if (nreqs > 0) for (j=1; j<=nreqs; ++j) if (!done[r[j]]) {\n               print \"   \" r[j]\n            }\n         }\n         exit 1\n      }\n   }\n   print \"PNG_DFN_END_SORT\" >out\n   print comment, \"end of options\", cend >out\n\n   # Do the 'setting' values second, the algorithm the standard\n   # tree walk (O(1)) done in an O(2) while/for loop; interations\n   # settings x depth, outputing the deepest required macros\n   # first.\n   print \"\" >out\n   print \"/* SETTINGS */\" >out\n   print comment, \"settings\", cend >out\n   # Sort (in dfn.awk) on field 2, the setting name\n   print \"PNG_DFN_START_SORT 2\" >out\n   finished = 0\n   while (!finished) {\n      finished = 1\n      movement = 0 # done nothing\n      for (i in setting) if (!doneset[i]) {\n         nreqs = split(setting[i], r)\n         if (nreqs > 0) {\n            # By default assume the requires values are options, but if there\n            # is no option with that name check for a setting\n            for (j=1; j<=nreqs; ++j) if (option[r[j]] == \"\" && !doneset[r[j]]) {\n               break\n            }\n            if (j<=nreqs) {\n               finished = 0\n               continue # try a different setting\n            }\n         }\n\n         # All the requirements have been processed, output\n         # this setting.\n         if (deb) print \"setting\", i\n         deflt = defaults[i]\n         # Remove any spurious trailing spaces\n         sub(/ *$/,\"\",deflt)\n         # A leading @ means leave it unquoted so the preprocessor\n         # can substitute the build time value\n         if (deflt ~ /^ @/)\n            deflt = \" \" subs substr(deflt, 3) sube\n         print \"\" >out\n         print \"/* setting: \", i >out\n         print \" *   requires:\" setting[i] >out\n         print \" *   default: \", defaults[i] deflt, \"*/\" >out\n         for (j=1; j<=nreqs; ++j) {\n            if (option[r[j]] != \"\")\n               print \"#ifndef PNG_\" r[j] \"_SUPPORTED\" >out\n            else\n               print \"#ifndef PNG_\" r[j] >out\n            print error, i, \"requires\", r[j] end >out\n            print \"# endif\" >out\n         }\n         # The precedence is:\n         #\n         #  1) External definition; trumps:\n         #  2) Option 'sets' value; trumps:\n         #  3) Setting 'default'\n         #\n         print \"#ifdef PNG_\" i >out\n         # PNG_<i> is defined, so substitute the value:\n         print def i, subs \"PNG_\" i sube end >out\n         print \"#else /* use default */\" >out\n         print \"# ifdef PNG_set_\" i >out\n         # Value from an option 'sets' argument\n         print def i, subs \"PNG_set_\" i sube end >out\n         # This is so that subsequent tests on the setting work:\n         print \"#  define PNG_\" i, \"1\" >out\n         if (defaults[i] != \"\") {\n            print \"# else /*default*/\" >out\n            print def i deflt end >out\n            print \"#  define PNG_\" i, \"1\" >out\n         }\n         print \"# endif /* defaults */\" >out\n         print \"#endif /* setting\", i, \"*/\" >out\n\n         doneset[i] = 1\n         ++movement\n      }\n\n      if (!finished && !movement) {\n         print \"setting: loop or missing setting in 'requires', cannot process:\"\n         for (i in setting) if (!doneset[i]) {\n            print \"  setting\", i, \"requires\" setting[i]\n         }\n         exit 1\n      }\n   }\n   print \"PNG_DFN_END_SORT\" >out\n   print comment, \"end of settings\", cend >out\n\n   # Regular end - everything looks ok\n   if (protect != \"\") {\n      print start \"#endif\", \"/*\", protect, \"*/\" end >out\n   }\n}\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/pnglibconf.dfa",
    "content": "# scripts/pnglibconf.dfa - library build configuration control\n#\n@/*- pnglibconf.dfn intermediate file\n@ *  generated from scripts/pnglibconf.dfa\n@ */\n#\ncom pnglibconf.h - library build configuration\ncom\nversion\ncom\ncom Copyright (c) 1998-2016 Glenn Randers-Pehrson\ncom\ncom This code is released under the libpng license.\ncom For conditions of distribution and use, see the disclaimer\ncom and license in png.h\ncom\n\nfile pnglibconf.h scripts/pnglibconf.dfa PNGLCONF_H\n\n# This file is preprocessed by scripts/options.awk and the\n# C compiler to generate 'pnglibconf.h' - a list of all the\n# configuration options.  The file lists the various options\n# that can *only* be specified during the libpng build;\n# pnglibconf.h freezes the definitions selected for the specific\n# build.\n#\n# The syntax is detailed in scripts/options.awk; this is a summary\n# only:\n#\n# setting <name> [requires ...] [default]\n#    #define PNG_<name> <value>  /* value comes from current setting */\n# option <name> [requires ...] [if ...] [enables ...] [disabled]\n#    #define PNG_<name>_SUPPORTED if the requirements are met and\n#    enable the other options listed\n# chunk <name> [requires ...] [enables ...] [disabled]\n#    Enable chunk processing for the given ancillary chunk; any\n#    'requires something' expands to READ_something for read and\n#    WRITE_something for write, but the enables list members are\n#    used as given (e.g. enables GAMMA just expands to that on the\n#    correspond READ_name and WRITE_name lines.)\n#\n# \",\" may be used to separate options on an 'option' line and is ignored; it\n# doesn't change the meaning of the line.  (NOT setting, where \",\" becomes\n# part of the setting!)  A comma at the end of an option line causes a\n# continuation (the next line is included in the option too.)\n#\n# Note that the 'on' and 'off' keywords, while valid on both option\n# and chunk, should not be used in this file because they force the\n# relevant options on or off.\n\n#----------------------------------------------------------------------\n\n# The following setting, option and chunk values can all be changed\n# while building libpng:\n#\n# setting: change 'setting' lines to fine tune library performance;\n#   changes to the settings don't affect the libpng API functionally\n#\n# option: change 'option' lines to remove or add capabilities from\n#   or to the library; options change the library API\n#\n# chunk: change 'chunk' lines to remove capabilities to process\n#   optional ('ancillary') chunks.  This does not prevent PNG\n#   decoding but does change the libpng API because some chunks\n#   will be ignored.\n#\n# There are three ways of disabling features, in no particular order:\n#\n# 1) Create 'pngusr.h', enter the required private build information\n# detailed below and #define PNG_NO_<option> for each option you\n# don't want in that file in that file.  You can also turn on options\n# using PNG_<option>_SUPPORTED.  When you have finished rerun\n# configure and rebuild pnglibconf.h file with -DPNG_USER_CONFIG:\n#\n#  make clean\n#  CPPFLAGS='-DPNG_USER_CONFIG' ./configure\n#  make pnglibconf.h\n#\n# pngusr.h is only used during the creation of pnglibconf.h, but it\n# is safer to ensure that -DPNG_USER_CONFIG is specified throughout\n# the build by changing the CPPFLAGS passed to the initial ./configure\n#\n# 2) Add definitions of the settings you want to change to\n# CPPFLAGS; for example:\n#\n#   -DPNG_DEFAULT_READ_MACROS=0\n#\n# (This would change the default to *not* use read macros.)  Be\n# very careful to change only settings that don't alter the API\n# because this approach bypasses the private build checking.  You\n# can also change settings from pngpriv.h (read pngpriv.h) safely\n# without API changes.  Do that in the same way.\n#\n# 3) Write a new '.dfa' file (say 'pngusr.dfa') and in this file\n# provide override values for setting entries and turn option or\n# chunk values explicitly 'on' or 'off':\n#\n#    setting FOO default VALUE\n#    option BAR [on|off]\n#\n# Then add this file to the options.awk command line (the *first*\n# one) after this file.  The make macro DFA_XTRA is provided to make\n# this easier (set it like CPPFLAGS prior to running ./configure).\n# Look at the builds below contrib/pngminim for some extreme examples\n# of how this can be used.\n#\n# Don't edit this file unless you are contributing a patch to\n# libpng and need new or modified options/settings.\n#----------------------------------------------------------------------\n\n# The following causes commented out #undef lines to be written to\n# pnglibconf.h; this can be stopped by logunsupported=0 in a later\n# file or on the command line (after pnglibconf.dfa)\n\nlogunsupported = 1\n\n# The following allows the output from configure to modify the contents of\n# pnglibconf.h\n\n@#ifdef HAVE_CONFIG_H\n@#  include \"config.h\"\n@#endif\n\n# PNG_USER_CONFIG has to be defined on the compiler command line\n# to cause pngusr.h to be read while constructing pnglibconf.h\n#\n# If you create a private DLL you need to define the following\n# macros in the file 'pngusr.h' and set -DPNG_USER_CONFIG for\n# compilation (i.e. in CPPFLAGS.)\n# #define PNG_USER_PRIVATEBUILD \\\n#     <Describes by whom and why this version of the DLL was built>\n#  e.g. #define PNG_USER_PRIVATEBUILD \"Build by MyCompany for xyz reasons.\"\n# #define PNG_USER_DLLFNAME_POSTFIX <two-letter postfix that serve to\n#        distinguish your DLL from those of the official release. These\n#        correspond to the trailing letters that come after the version\n#        number and must match your private DLL name>\n#  e.g. // private DLL \"libpng13gx.dll\"\n#       #define PNG_USER_DLLFNAME_POSTFIX \"gx\"\n#\n# The following macros are also at your disposal if you want to complete the\n# DLL VERSIONINFO structure.\n# - PNG_USER_VERSIONINFO_COMMENTS\n# - PNG_USER_VERSIONINFO_COMPANYNAME\n# - PNG_USER_VERSIONINFO_LEGALTRADEMARKS\n\n# It is necessary to include configures definitions here so that AC_DEFINE\n# in configure.ac works in a comprehensible way\n@#if defined(HAVE_CONFIG_H) && !defined(PNG_NO_CONFIG_H)\n@#  include \"config.h\"\n@#endif\n\n@#ifdef PNG_USER_CONFIG\n@#  include \"pngusr.h\"\n@#endif\n\n# This is a special fixup for the Watcom C compiler on Windows, which has\n# multiple procedure call standards.  Unless PNG_API_RULE is set explicitly\n# (i.e. if it is not defined at this point) it will be forced to '2' here when\n# using Watcom.  This indicates to the other header files that Watcom behaviour\n# is required where appropriate.\n\n@#ifdef __WATCOMC__\n@#  ifndef PNG_API_RULE\n@#     define PNG_API_RULE 2 /* Use Watcom calling conventions */\n@#  endif\n@#endif\n\n# IN DEVELOPMENT\n# These are currently experimental features; define them if you want (NOTE:\n# experimental options must be disabled before they are defined in this file!)\n\n# NONE\n\n# Note that PNG_USER_CONFIG only has an effect when building\n# pnglibconf.h\n\nsetting USER_CONFIG\nsetting USER_PRIVATEBUILD\nsetting USER_DLLFNAME_POSTFIX\nsetting USER_VERSIONINFO_COMMENTS\nsetting USER_VERSIONINFO_COMPANYNAME\nsetting USER_VERSIONINFO_LEGALTRADEMARKS\n\n# Record the 'API rule' used to select calling conventions on\n# those systems that support such things (see all the comments in\n# pngconf.h)\n# Changing this setting has a fundamental affect on the PNG ABI,\n# do not release shared libraries with this changed.\n\nsetting API_RULE default 0\n\n# This allows a prefix to be added to the front of every API functon name (and\n# therefore every symbol) by redefining all the function names with the prefix\n# at the end of pnglibconf.h.  It also turns on similar internal symbol renaming\n# by causing a similar build-time only file, pngprefix.h, to be generated.\n\nsetting PREFIX\n\n# Implementation specific control of the optimizations, enabled by those\n# hardware or software options that need it (typically when run-time choices\n# must be made by the user)\noption SET_OPTION disabled\n\n# These options are specific to the ARM NEON hardware optimizations.  At present\n# these optimizations depend on GCC specific pre-processing of an assembler (.S)\n# file so they probably won't work with other compilers.\n#\n# ARM_NEON_OPT: unset: check at compile time (__ARM_NEON__ must be defined by\n#                      the compiler, typically as a result of specifying\n#                      CC=\"gcc -mfpu=neon\".)\n#                   0: disable (even if the CPU has a NEON FPU.)\n#                   1: check at run time (via ARM_NEON_{API,CHECK})\n#                   2: switch on unconditionally (inadvisable - instead pass\n#                      -mfpu=neon to GCC in CC)\n#           When building libpng avoid using any setting other than '0'; '1' is\n#           set automatically when either 'API' or 'CHECK' are configured in,\n#           '2' should not be necessary as -mfpu=neon will achieve the same\n#           effect as well as applying NEON optimizations to the rest of the\n#           libpng code.\n#           NOTE: any setting other than '0' requires ALIGNED_MEMORY\n# ARM_NEON_API:   (PNG_ARM_NEON == 1) allow the optimization to be switched on\n#                 with png_set_option\n# ARM_NEON_CHECK: (PNG_ARM_NEON == 1) compile a run-time check to see if Neon\n#                 extensions are supported. This is poorly supported and\n#                 deprecated - use the png_set_option API.\nsetting ARM_NEON_OPT\noption ARM_NEON_API disabled requires ALIGNED_MEMORY enables SET_OPTION,\n   sets ARM_NEON_OPT 1\noption ARM_NEON_CHECK disabled requires ALIGNED_MEMORY,\n   sets ARM_NEON_OPT 1\n\n# These settings configure the default compression level (0-9) and 'strategy';\n# strategy is as defined by the implementors of zlib. It describes the input\n# data and modifies the zlib parameters in an attempt to optimize the balance\n# between search and huffman encoding in the zlib algorithms.  The defaults are\n# the zlib.h defaults - the apparently recursive definition does not arise\n# because the name of the setting is prefixed by PNG_\n#\n# The TEXT values are the defaults when writing compressed text (all forms)\n\n# Include the zlib header so that the defaults below are known\n@#  include <zlib.h>\n\n# The '@' here means to substitute the value when pnglibconf.h is built\nsetting Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION\n# TODO: why aren't these Z_RLE; zlib.h says that Z_RLE, specifically, is\n# appropriate for PNG images, maybe it doesn't exist in all versions?\nsetting Z_DEFAULT_STRATEGY default @Z_FILTERED\nsetting Z_DEFAULT_NOFILTER_STRATEGY default @Z_DEFAULT_STRATEGY\nsetting ZLIB_VERNUM default @ZLIB_VERNUM\n\n# Linkage of:\n#\n#  API:      libpng API functions\n#  CALLBACK: internal non-file-local callbacks\n#  FUNCTION: internal non-file-local functions\n#  DATA:     internal non-file-local (const) data\nsetting LINKAGE_API default extern\nsetting LINKAGE_CALLBACK default extern\nsetting LINKAGE_FUNCTION default extern\nsetting LINKAGE_DATA default extern\n\nsetting TEXT_Z_DEFAULT_COMPRESSION default @Z_DEFAULT_COMPRESSION\nsetting TEXT_Z_DEFAULT_STRATEGY default @Z_DEFAULT_STRATEGY\n\n# Default to using the read macros\n\nsetting DEFAULT_READ_MACROS default 1\n\n# The alternative is to call functions to read PNG values, if\n# the functions are turned *off* the read macros must always\n# be enabled, so turning this off will actually force the\n# USE_READ_MACROS option on (see pngconf.h)\n\noption READ_INT_FUNCTIONS requires READ\n\n# The same for write  but these can only be switched off if no writing\n# is required at all - hence the use of a 'disabled', not a 'requires'.\n# If these are needed, they are enabled in the 'WRITE options' section\n# below.\n\noption WRITE_INT_FUNCTIONS disabled\n\n# Error controls\n#\n# WARNINGS: normally on, if off no warnings are generated\n# ERROR_TEXT: normally on, if off errors happen but there is no message\n# ERROR_NUMBERS: unimplemented feature, therefore disabled\n# BENIGN_ERRORS: support for just issuing warnings for recoverable errors\n#\n# BENIGN_READ_ERRORS:\n#     By default recoverable errors on read should just generate warnings,\n#     generally safe but PNG files that don't conform to the specification will\n#     be accepted if a meaningful result can be produced.\n#\n# BENIGN_WRITE_ERRORS:\n#     By default recoverable errors on write should just generate warnings,\n#     not generally safe because this allows the application to write invalid\n#     PNG files.  Applications should enable this themselves; it's useful\n#     because it means that a failure to write an ancilliary chunk can often be\n#     ignored.\n\noption WARNINGS\noption ERROR_TEXT\noption ERROR_NUMBERS disabled\n\noption BENIGN_ERRORS\noption BENIGN_WRITE_ERRORS requires BENIGN_ERRORS disabled\noption BENIGN_READ_ERRORS requires BENIGN_ERRORS\n\n\n# Generic options - affect both read and write.\n\noption MNG_FEATURES\n\n# Arithmetic options, the first is the big switch that chooses between internal\n# floating and fixed point arithmetic implementations - it does not affect any\n# APIs.  The second two (the _POINT settings) switch off individual APIs.\n#\n# Prior to libpng 1.6.8 one of the API (_POINT) variants had to be selected.  At\n# 1.6.8 this restriction has been removed; the simplified API can be used\n# without enabling any of the low level fixed/floating APIs.\n\noption FLOATING_ARITHMETIC\noption FLOATING_POINT\noption FIXED_POINT\n\n# This protects us against compilers that run on a windowing system\n# and thus don't have or would rather us not use the stdio types:\n# stdin, stdout, and stderr.  The only one currently used is stderr\n# in png_error() and png_warning().  #defining PNG_NO_CONSOLE_IO will\n# prevent these from being compiled and used. #defining PNG_NO_STDIO\n# will also prevent these, plus will prevent the entire set of stdio\n# macros and functions (FILE *, printf, etc.) from being compiled and used,\n# unless (PNG_DEBUG > 0) has been #defined.\n\noption STDIO\noption CONSOLE_IO requires STDIO\n\n# Note: prior to 1.5.0 this option could not be disabled if STDIO\n# was enabled.  Prior to 1.5.3 this option required STDIO\n\noption TIME_RFC1123\n\n# PNG_SETJMP_NOT_SUPPORTED is an old equivalent for NO_SETJMP\n\noption SETJMP\n= NO_SETJMP SETJMP_NOT_SUPPORTED\n\n# If this is disabled it is not possible for apps to get the\n# values from the 'info' structure, this effectively removes\n# quite a lot of the READ API.\n\noption EASY_ACCESS\n\n# Added at libpng-1.2.0\n\noption USER_MEM\n\n# Added at libpng-1.4.0\n\noption IO_STATE\n\n# Libpng limits: limit the size of images and data on read.\n#\n# If this option is disabled all the limit checking code will be disabled:\n\noption USER_LIMITS requires READ\n\n# The default settings given below for the limits mean that libpng will\n# limit the size of images or the size of data in ancilliary chunks to less\n# than the specification or implementation limits. Settings have the\n# following interpretations:\n#\n# USER_WIDTH_MAX: maximum width of an image that will be read\n# USER_HEIGHT_MAX: maximum height\n# USER_CHUNK_MALLOC_MAX: maximum in-memory (decompressed) size of a single chunk\n# USER_CHUNK_CACHE_MAX: maximum number of chunks to be cached\n#\n# Only chunks that are variable in number are counted towards the\n\n# Use 0x7fffffff for unlimited\nsetting USER_WIDTH_MAX default        1000000\nsetting USER_HEIGHT_MAX default       1000000\n\n# Use 0 for unlimited\nsetting USER_CHUNK_CACHE_MAX default     1000\nsetting USER_CHUNK_MALLOC_MAX default 8000000\n\n# If this option is enabled APIs to set the above limits at run time are added;\n# without this the hardwired (compile time) limits will be used.\noption SET_USER_LIMITS requires USER_LIMITS\n\n# All of the following options relate to code capabilities for\n# processing image data before creating a PNG or after reading one.\n# You can remove these capabilities safely and still be PNG\n# conformant, however the library that results is still non-standard.\n# See the comments above about how to change options and settings.\n\n# READ options\n#\n# WARNING: in libpng 1.5 maintained configuration compatibility with earlier\n# versions.  In some cases turning off an option turned off other options, in\n# others it was ineffective unless dependent options were also turned off.\n# Libpng 1.6 changes this: in general if you turn off an option that affects\n# APIs it stays off and simply disables APIs that depend on it.\n#\n# As a result if you simply port the libpng 1.5 configuration to libpng 1.6 you\n# will probably see build failures due to missing APIs.  Fixing these failures\n# requires some, perhaps considerable, knowledge of what your libpng using\n# applications are doing, fortunately there is no great reason for you to move\n# to libpng 1.6; the new interfaces in 1.6 will take several years to become\n# popular.\n\noption READ enables READ_INTERLACING SET_OPTION\n\n# Disabling READ_16BIT does not disable reading 16-bit PNG files, but it\n# forces them to be chopped down to 8-bit, and disables any 16-bit\n# processing after that has happened.  You need to be sure to enable\n# READ_SCALE_16_TO_8 or READ_STRIP_16_TO_8 when you disable READ_16BIT for\n# this to work properly.  You should disable the other option if you need to\n# ensure a particular conversion (otherwise the app can chose.)\n\noption READ_16BIT requires READ enables 16BIT\n\noption READ_QUANTIZE requires READ\n\noption READ_TRANSFORMS requires READ\n= NO_READ_TRANSFORMS READ_TRANSFORMS_NOT_SUPPORTED\n\n# Read gamma handling.  Gamma processing is a core part of libpng and many of\n# the capabilities are dependent on libpng performing gamma correction.\n#\n# In libpng 1.6 disabling gamma processing (setting PNG_NO_READ_GAMMA)\n# consistently disables those parts of the API that depend on it.  Prior to\n# 1.6.0 this was not true; the results were unpredictable and varied between\n# releases.\n#\n# If you disable gamma processing and your program no longer compiles you need\n# to ask whether you really need the APIs that are missing.  If you do then you\n# almost certainly need the gamma processing.\n#\n# If you handle gamma issues outside libpng then you do not need the libpng\n# gamma processing; and it is an enormous waste of space.  You just need to\n# remove the use of libpng APIs that depend on it.\noption READ_GAMMA requires READ_TRANSFORMS, READ_gAMA, READ_sRGB\n\noption READ_ALPHA_MODE requires READ_TRANSFORMS, READ_GAMMA\noption READ_BACKGROUND requires READ_TRANSFORMS, READ_STRIP_ALPHA, READ_GAMMA\noption READ_BGR requires READ_TRANSFORMS\noption READ_EXPAND_16 requires READ_TRANSFORMS, READ_16BIT, READ_EXPAND\noption READ_EXPAND requires READ_TRANSFORMS\noption READ_FILLER requires READ_TRANSFORMS\noption READ_GRAY_TO_RGB requires READ_TRANSFORMS\noption READ_INVERT_ALPHA requires READ_TRANSFORMS\noption READ_INVERT requires READ_TRANSFORMS\noption READ_PACK requires READ_TRANSFORMS\noption READ_PACKSWAP requires READ_TRANSFORMS\noption READ_RGB_TO_GRAY requires READ_TRANSFORMS, READ_GAMMA enables COLORSPACE\noption READ_SCALE_16_TO_8 requires READ_TRANSFORMS\noption READ_SHIFT requires READ_TRANSFORMS\noption READ_STRIP_16_TO_8 requires READ_TRANSFORMS\noption READ_STRIP_ALPHA requires READ_TRANSFORMS\noption READ_SWAP_ALPHA requires READ_TRANSFORMS\noption READ_SWAP requires READ_TRANSFORMS, READ_16BIT\noption READ_USER_TRANSFORM requires READ_TRANSFORMS\n\noption PROGRESSIVE_READ requires READ\noption SEQUENTIAL_READ requires READ\n\n# You can define PNG_NO_PROGRESSIVE_READ if you don't do progressive reading.\n# This is not talking about interlacing capability!  You'll still have\n# interlacing unless you turn off the following which is required\n# for PNG-compliant decoders.  (In other words, do not do this - in\n# fact it can't be disabled from the command line!)\n#option READ_INTERLACING requires READ\n\noption READ_COMPOSITE_NODIV requires READ\n= NO_READ_COMPOSITE_NODIV NO_READ_COMPOSITED_NODIV\n\n# Inch conversions\n\noption INCH_CONVERSIONS\n= INCH_CONVERSIONS INCH_CONVERSIONS\n\n# API to build a grayscale palette\n# NOTE: this is not used internally by libpng at present.\n\noption BUILD_GRAYSCALE_PALETTE\n\n# WRITE options\n\noption WRITE enables WRITE_INT_FUNCTIONS\n\n# Disabling WRITE_16BIT prevents 16-bit PNG files from being\n# generated.\noption WRITE_16BIT requires WRITE enables 16BIT\n\noption WRITE_TRANSFORMS requires WRITE\n= NO_WRITE_TRANSFORMS WRITE_TRANSFORMS_NOT_SUPPORTED\n\noption WRITE_SHIFT requires WRITE_TRANSFORMS\noption WRITE_PACK requires WRITE_TRANSFORMS\noption WRITE_BGR requires WRITE_TRANSFORMS\noption WRITE_SWAP requires WRITE_TRANSFORMS, WRITE_16BIT\noption WRITE_PACKSWAP requires WRITE_TRANSFORMS\noption WRITE_INVERT requires WRITE_TRANSFORMS\noption WRITE_FILLER requires WRITE_TRANSFORMS\noption WRITE_SWAP_ALPHA requires WRITE_TRANSFORMS\noption WRITE_INVERT_ALPHA requires WRITE_TRANSFORMS\noption WRITE_USER_TRANSFORM requires WRITE_TRANSFORMS\n\n# This is not required for PNG-compliant encoders, but can cause\n# trouble if left undefined\n\noption WRITE_INTERLACING requires WRITE\n\n# Deprecated, will be removed.\noption WRITE_WEIGHTED_FILTER requires WRITE\n\noption WRITE_FLUSH requires WRITE\n\n# Note: these can be turned off explicitly if not required by the\n# apps implementing the user transforms\noption USER_TRANSFORM_PTR if READ_USER_TRANSFORM, WRITE_USER_TRANSFORM\noption USER_TRANSFORM_INFO if READ_USER_TRANSFORM, WRITE_USER_TRANSFORM\n\n# This enables API to set compression parameters for compressing\n# non-IDAT chunks (zTXt, iTXt, iCCP, and unknown chunks).  This feature\n# was added at libpng-1.5.3.\noption WRITE_CUSTOMIZE_ZTXT_COMPRESSION requires WRITE\noption WRITE_CUSTOMIZE_COMPRESSION requires WRITE\n\n# Any chunks you are not interested in, you can undef here.  The\n# ones that allocate memory may be expecially important (hIST,\n# tEXt, zTXt, tRNS, pCAL).  Others will just save time and make png_info\n# a bit smaller.\n\n# The size of the png_text structure changed in libpng-1.0.6 when\n# iTXt support was added.  iTXt support was turned off by default through\n# libpng-1.2.x, to support old apps that malloc the png_text structure\n# instead of calling png_set_text() and letting libpng malloc it.  It\n# was turned on by default in libpng-1.4.0.\n\noption READ_ANCILLARY_CHUNKS requires READ\n# PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated.\n= NO_READ_ANCILLARY_CHUNKS READ_ANCILLARY_CHUNKS_NOT_SUPPORTED\n\noption WRITE_ANCILLARY_CHUNKS requires WRITE\n# PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED is deprecated.\n= NO_WRITE_ANCILLARY_CHUNKS WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED\n\n# These options disable *all* the text chunks if turned off\n\noption TEXT disabled\noption READ_TEXT requires READ_ANCILLARY_CHUNKS enables TEXT\noption WRITE_TEXT requires WRITE_ANCILLARY_CHUNKS enables TEXT\n\n# Moved to pnglibconf.h at libpng-1.5.0\n# Feature support: in 1.4 this was in pngconf.h, but the following\n# features have no affect on the libpng API.  Add library\n# only features to the end of this list.  Add features that\n# affect the API above.  (Note: the list of chunks follows\n# the library-only settings.)\n#\n# BUILD TIME ONLY OPTIONS\n#   These options do not affect the API but rather alter how the\n#   API is implemented, they get recorded in pnglibconf.h, but\n#   can't be changed by the application.\n\n# Colorspace support (enabled as required); just the support for colorant\n# information.  Gamma support, likewise, is just support for the gamma\n# information, READ_GAMMA is required for gamma transformations (so it\n# is possible to read PNG gamma without enabling all the libpng transform\n# code - do this for applications that do their own gamma processing)\n#\n# As of 1.6.0 COLORSPACE is only useful if the application processes the\n# information; this is because the library does not do any colorspace\n# processing, it just validates the data in the PNG file.\n\noption GAMMA disabled\noption COLORSPACE enables GAMMA disabled\n\n# When an ICC profile is read, or png_set, it will be checked for a match\n# against known sRGB profiles if the sRGB handling is enabled.  The\n# PNG_sRGB_PROFILE_CHECKS setting controls how much work is done during the\n# check:\n#\n# -1: Don't do any sRGB profile checking.\n#\n#  0: Just validate the profile MD5 signature if present, otherwise use\n#     the checks in option 1.\n#\n#  1: Additionally check the length, intent and adler32 checksum of the\n#     actual data.   If enabled this will reject known profiles that have\n#     had the rendering intent in the header changed as well as other edits\n#     done without updating the checksum.  See the discussion below.\n#\n#  2: Additionally checksum all the data using the ethernet CRC32 algorithm.\n#     This makes it more difficult to fake profiles and makes it less likely\n#     to get a false positive on profiles with no signature, but is probably\n#     just a waste of time since all currently approved ICC sRGB profiles have\n#     a secure MD5 signature.\n#\n# The rendering intent.  An ICC profile stores an intended rendering intent,\n# but does not include the value in the signature.  The intent is documented\n# as the intent that should be used when combining two profiles.  The sRGB\n# profile is intended, however, to be used with any of the four defined intents.\n# For this reason the sRGB chunk includes an 'intent' to be used when displaying\n# the image (intent is really a property of the image not the profile.)\n#\n# Unfortunately the iCCP chunk does not.  It may therefore be that some\n# applications modify the intent in profiles (including sRGB profiles) to work\n# round this problem.  Selecting an option other than option '0' will cause such\n# modified profiles to be rejected.\n#\n# Security.  The use of Adler32 and CRC32 checksums does not help significantly\n# with any security issues.  It is relatively easy to produce arbitrary profiles\n# with the required checksums on current computer systems.  Nevertheless\n# security does not seem to be an issue because the only consequence of a false\n# positive is a false assertion that the profile is an sRGB profile.  This might\n# be used to hide data from libpng using applications, but it doesn't seem\n# possible to damage them.\n\nsetting sRGB_PROFILE_CHECKS default 2\n\n# Artificially align memory - the code typically aligns to 8 byte\n# boundaries if this is switched on, it's a small waste of space\n# but can help (in theory) on some architectures.  Only affects\n# internal structures.  Added at libpng 1.4.0\n\noption ALIGNED_MEMORY\n\n# Buggy compilers (e.g., gcc 2.7.2.2) need PNG_NO_POINTER_INDEXING\n# See png[wr]util.c, normally this should always be *on*\n\noption POINTER_INDEXING\n\n# Other defines for things like memory and the like can go here.\n\n# BUILD TIME SETTINGS\n# Like build time options these do not affect the API, but they\n# may be useful to applications because they record details of\n# how the API will behave particularly with regard to overall\n# accuracy.\n\n# This controls how fine the quantizing gets.  As this allocates\n# a largish chunk of memory (32K), those who are not as concerned\n# with quantizing quality can decrease some or all of these.\n\nsetting QUANTIZE_RED_BITS default 5\nsetting QUANTIZE_GREEN_BITS default 5\nsetting QUANTIZE_BLUE_BITS default 5\n\n# This controls how fine the gamma correction becomes when you\n# are only interested in 8 bits anyway.  Increasing this value\n# results in more memory being used, and more pow() functions\n# being called to fill in the gamma tables.  Don't set this value\n# less than 8, and even that may not work (I haven't tested it).\n\nsetting MAX_GAMMA_8 default 11\n\n# This controls how much a difference in gamma we can tolerate before\n# we actually start doing gamma conversion, it's a fixed point value,\n# so the default below is 0.05, meaning libpng ignores corrections in\n# the range 0.95 to 1.05\n\nsetting GAMMA_THRESHOLD_FIXED default 5000\n\n# Precision to use when converting a floating point value to a PNG\n# extension format string in an sCAL chunk (only relevant if the\n# floating point API is enabled)\n\nsetting sCAL_PRECISION default 5\n\n# This is the size of the compression buffer, and thus the size of\n# an IDAT chunk.  Make this whatever size you feel is best for your\n# machine.  One of these will be allocated per png_struct.  When this\n# is full, it writes the data to the disk, and does some other\n# calculations.  Making this an extremely small size may slow\n# the library down, but you may want to experiment to determine\n# where it becomes significant, if you are concerned with memory\n# usage.  Note that zlib allocates at least 32Kb also.  For readers,\n# this describes the size of the buffer available to read the data in.\n# Unless this gets smaller than the size of a row (compressed),\n# it should not make much difference how big this is.\n\nsetting ZBUF_SIZE default 8192\n\n# This is the size of the decompression buffer used when counting or checking\n# the decompressed size of an LZ stream from a compressed ancilliary chunk; the\n# decompressed data is never used so a different size may be optimal.  This size\n# was determined using contrib/libtests/timepng.c with compressed zTXt data\n# around 11MByte in size.  Slight speed improvements (up to about 14% in\n# timepng) can be achieved by very large increases (to 32kbyte) on regular data,\n# but highly compressible data shows only around 2% improvement.   The size is\n# chosen to minimize the effects of DoS attacks based on using very large\n# amounts of highly compressible data.\n\nsetting INFLATE_BUF_SIZE default 1024\n\n# This is the maximum amount of IDAT data that the sequential reader will\n# process at one time.  The setting does not affect the size of IDAT chunks\n# read, just the amount read at once.  Neither does it affect the progressive\n# reader, which processes just the amount of data the application gives it.\n# The sequential reader is currently unable to process more than one IDAT at\n# once - it has to read and process each one in turn.  There is no point setting\n# this to a value larger than the IDAT chunks typically encountered (it would\n# just waste memory) but there may be some point in reducing it below the value\n# of ZBUF_SIZE (the size of IDAT chunks written by libpng.)\n\nsetting IDAT_READ_SIZE default PNG_ZBUF_SIZE\n\n# Ancillary chunks\nchunk bKGD\nchunk cHRM enables COLORSPACE\nchunk gAMA enables GAMMA\nchunk hIST\nchunk iCCP enables COLORSPACE, GAMMA\nchunk iTXt enables TEXT\nchunk oFFs\nchunk pCAL\nchunk pHYs\nchunk sBIT\nchunk sCAL\nchunk sPLT\nchunk sRGB enables COLORSPACE, GAMMA, SET_OPTION\nchunk tEXt requires TEXT\nchunk tIME\nchunk tRNS\nchunk zTXt enables TEXT\n\n# This only affects support of the optional PLTE chunk in RGB and RGBA\n# images.  Notice that READ_ANCILLARY_CHUNKS therefore disables part\n# of the regular chunk reading too.\n\noption READ_OPT_PLTE requires READ_ANCILLARY_CHUNKS\n\n# Unknown chunk handling\n#\n# 'UNKNOWN_CHUNKS' is a global option to disable all unknown chunk handling on\n# read or write; everything else below requires it (directly or indirectly).\noption UNKNOWN_CHUNKS\n\n# There are three main options to control the ability to read and write unknown\n# chunks.  If either read option is turned on then unknown chunks will be read,\n# otherwise they are skipped.  If the write option is turned on unknown chunks\n# set by png_set_unknown_chunks will be written otherwise it is an error to call\n# that API on a write struct.\noption WRITE_UNKNOWN_CHUNKS requires WRITE requires UNKNOWN_CHUNKS\noption WRITE_UNKNOWN_CHUNKS enables STORE_UNKNOWN_CHUNKS\n\n# The first way to read user chunks is to have libpng save them for a later call\n# to png_get_unknown_chunks, the application must call\n# png_set_keep_unknown_chunks to cause this to actually happen (see png.h)\noption SAVE_UNKNOWN_CHUNKS requires READ requires SET_UNKNOWN_CHUNKS\noption SAVE_UNKNOWN_CHUNKS enables READ_UNKNOWN_CHUNKS, STORE_UNKNOWN_CHUNKS\n\n# The second approach is to use an application provided callback to process the\n# chunks, the callback can either handle the chunk entirely itself or request\n# that libpng store the chunk for later retrieval via png_get_unknown_chunks.\n#\n# NOTE: If STORE_UNKNOWN_CHUNKS is not enabled (which is the default if\n# both SAVE_UNKNOWN_CHUNKS and WRITE_UNKNOWN_CHUNKS are disabled) then a\n# 0 result from the callback will be ignored because no support for saving\n# unknown chunks has been compiled in.  The normal symptom is that your app\n# fails to compile because png_get_unknown_chunks is no longer defined in png.h.\n# If you encounter this issue simply enable STORE_UNKNOWN_CHUNKS in your build.\n#\n# Note that there is no 'WRITE_USER_CHUNKS' so the USER_CHUNKS option is always\n# the same as READ_USER_CHUNKS at present\noption READ_USER_CHUNKS requires READ, UNKNOWN_CHUNKS\noption READ_USER_CHUNKS enables READ_UNKNOWN_CHUNKS, USER_CHUNKS\n\n# Two further options are provided to allow detailed control of the handling.\n# The first enables png_set_keep_unknown_chunks; this allows the default to be\n# changed from discarding unknown chunks and allows per-chunk control.  This is\n# required to use the SAVE_UNKNOWN_CHUNKS option.  If enabled this option also\n# applies to write (see png.h), otherwise the write API simply writes all the\n# chunks it is given.\n#\n# The second option extends the unknown handling to allow known chunks to be\n# handled as though they were unknown.  This option doesn't change any APIs, it\n# merely turns on the code to check known as well as unknown chunks.\n#\n# This option no longer affects the write code.  It can be safely disabled and\n# will prevent applications stopping libpng reading known chunks.\noption SET_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS\noption HANDLE_AS_UNKNOWN requires SET_UNKNOWN_CHUNKS\n\n# The following options are derived from the above and should not be turned on\n# explicitly.\noption READ_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS disabled\noption STORE_UNKNOWN_CHUNKS requires UNKNOWN_CHUNKS disabled\n\noption CONVERT_tIME requires WRITE_ANCILLARY_CHUNKS\n# The \"tm\" structure is not supported on WindowsCE\n\n@#ifdef _WIN32_WCE\n@#   define PNG_NO_CONVERT_tIME\n@#endif\n\noption WRITE_FILTER requires WRITE\n\noption SAVE_INT_32 disabled\n# png_save_int_32 is required internally for writing the ancillary chunks oFFs\n# and pCAL and for both reading and writing iCCP (for the generation/checking of\n# the corresponding cHRM/gAMA chunks) if full ICC is supported.\n\n# added at libpng-1.5.4\n\noption WRITE_OPTIMIZE_CMF requires WRITE\n\noption READ_COMPRESSED_TEXT disabled\noption READ_iCCP enables READ_COMPRESSED_TEXT\noption READ_iTXt enables READ_COMPRESSED_TEXT\noption READ_zTXt enables READ_COMPRESSED_TEXT\n\noption WRITE_oFFs enables SAVE_INT_32\noption WRITE_pCAL enables SAVE_INT_32\noption WRITE_cHRM enables SAVE_INT_32\n\noption WRITE_COMPRESSED_TEXT disabled\noption WRITE_iCCP enables WRITE_COMPRESSED_TEXT\noption WRITE_iTXt enables WRITE_COMPRESSED_TEXT\noption WRITE_zTXt enables WRITE_COMPRESSED_TEXT\n\n# Turn this off to disable png_read_png() and png_write_png() and\n# leave the row_pointers member out of the info structure.\n\noption INFO_IMAGE\n\n# added at libpng-1.5.10\n# Turn this off to disable warning about invalid palette index and\n# leave the num_palette_max member out of the png structure.\n\noption CHECK_FOR_INVALID_INDEX enables READ_CHECK_FOR_INVALID_INDEX\noption CHECK_FOR_INVALID_INDEX enables WRITE_CHECK_FOR_INVALID_INDEX\noption READ_CHECK_FOR_INVALID_INDEX requires READ, CHECK_FOR_INVALID_INDEX\noption WRITE_CHECK_FOR_INVALID_INDEX requires WRITE, CHECK_FOR_INVALID_INDEX\n\n# added at libpng-1.5.15\noption GET_PALETTE_MAX enables READ_GET_PALETTE_MAX WRITE_GET_PALETTE_MAX\noption READ_GET_PALETTE_MAX requires READ_CHECK_FOR_INVALID_INDEX disabled\noption WRITE_GET_PALETTE_MAX requires WRITE_CHECK_FOR_INVALID_INDEX disabled\n\n# Simplified API options (added at libpng-1.6.0)\n#  In libpng 1.6.8 the handling of these options was changed to used 'requires'\n#  throughout, so that disabling some of the low level support always disables\n#  the base simplified read/write API.  This much simplifies the handling and\n#  makes 'everything = off' work in a more intuitive way.  It eliminates a\n#  previously reported feature that APIs previously enabled by the simplified\n#  API couldn't be turned off without explicitly turning off the simplified\n#  APIs.\n#\n# Read:\noption SIMPLIFIED_READ,\n   requires SEQUENTIAL_READ, READ_TRANSFORMS, SETJMP, BENIGN_ERRORS,\n      READ_EXPAND, READ_16BIT, READ_EXPAND_16, READ_SCALE_16_TO_8,\n      READ_RGB_TO_GRAY, READ_ALPHA_MODE, READ_BACKGROUND, READ_STRIP_ALPHA,\n      READ_FILLER, READ_SWAP, READ_PACK, READ_GRAY_TO_RGB, READ_GAMMA,\n      READ_tRNS, READ_bKGD, READ_gAMA, READ_cHRM, READ_sRGB, READ_sBIT\n\n# AFIRST and BGR read options:\n#  Prior to libpng 1.6.8 these were disabled but switched on if the low level\n#  libpng routines that do the swaps were enabled.  This worked but was\n#  confusing.  In libpng 1.6.8 the options were changed to simple 'requires'\n#  and are enabled by default.  This should work the same way in practice.\noption SIMPLIFIED_READ_AFIRST enables FORMAT_AFIRST,\n   requires SIMPLIFIED_READ READ_SWAP_ALPHA\n\noption SIMPLIFIED_READ_BGR enables FORMAT_BGR,\n   requires SIMPLIFIED_READ READ_BGR\n\n# Write:\noption SIMPLIFIED_WRITE,\n   requires WRITE, SETJMP, WRITE_SWAP, WRITE_PACK,\n      WRITE_tRNS, WRITE_gAMA, WRITE_sRGB, WRITE_cHRM\n\n# 1.6.22: allow simplified write without stdio support:\noption SIMPLIFIED_WRITE_STDIO requires SIMPLIFIED_WRITE STDIO\n\noption SIMPLIFIED_WRITE_AFIRST enables FORMAT_AFIRST,\n   requires SIMPLIFIED_WRITE WRITE_SWAP_ALPHA\n\noption SIMPLIFIED_WRITE_BGR enables FORMAT_BGR,\n   requires SIMPLIFIED_WRITE WRITE_BGR\n\n# Formats:\noption FORMAT_AFIRST disabled\noption FORMAT_BGR disabled\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/pnglibconf.h.prebuilt",
    "content": "/* libpng 1.6.25 STANDARD API DEFINITION */\n\n/* pnglibconf.h - library build configuration */\n\n/* Libpng version 1.6.25 - September 1, 2016 */\n\n/* Copyright (c) 1998-2015 Glenn Randers-Pehrson */\n\n/* This code is released under the libpng license. */\n/* For conditions of distribution and use, see the disclaimer */\n/* and license in png.h */\n\n/* pnglibconf.h */\n/* Machine generated file: DO NOT EDIT */\n/* Derived from: scripts/pnglibconf.dfa */\n#ifndef PNGLCONF_H\n#define PNGLCONF_H\n/* options */\n#define PNG_16BIT_SUPPORTED\n#define PNG_ALIGNED_MEMORY_SUPPORTED\n/*#undef PNG_ARM_NEON_API_SUPPORTED*/\n/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/\n#define PNG_BENIGN_ERRORS_SUPPORTED\n#define PNG_BENIGN_READ_ERRORS_SUPPORTED\n/*#undef PNG_BENIGN_WRITE_ERRORS_SUPPORTED*/\n#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED\n#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_COLORSPACE_SUPPORTED\n#define PNG_CONSOLE_IO_SUPPORTED\n#define PNG_CONVERT_tIME_SUPPORTED\n#define PNG_EASY_ACCESS_SUPPORTED\n/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/\n#define PNG_ERROR_TEXT_SUPPORTED\n#define PNG_FIXED_POINT_SUPPORTED\n#define PNG_FLOATING_ARITHMETIC_SUPPORTED\n#define PNG_FLOATING_POINT_SUPPORTED\n#define PNG_FORMAT_AFIRST_SUPPORTED\n#define PNG_FORMAT_BGR_SUPPORTED\n#define PNG_GAMMA_SUPPORTED\n#define PNG_GET_PALETTE_MAX_SUPPORTED\n#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED\n#define PNG_INCH_CONVERSIONS_SUPPORTED\n#define PNG_INFO_IMAGE_SUPPORTED\n#define PNG_IO_STATE_SUPPORTED\n#define PNG_MNG_FEATURES_SUPPORTED\n#define PNG_POINTER_INDEXING_SUPPORTED\n#define PNG_PROGRESSIVE_READ_SUPPORTED\n#define PNG_READ_16BIT_SUPPORTED\n#define PNG_READ_ALPHA_MODE_SUPPORTED\n#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED\n#define PNG_READ_BACKGROUND_SUPPORTED\n#define PNG_READ_BGR_SUPPORTED\n#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_READ_COMPOSITE_NODIV_SUPPORTED\n#define PNG_READ_COMPRESSED_TEXT_SUPPORTED\n#define PNG_READ_EXPAND_16_SUPPORTED\n#define PNG_READ_EXPAND_SUPPORTED\n#define PNG_READ_FILLER_SUPPORTED\n#define PNG_READ_GAMMA_SUPPORTED\n#define PNG_READ_GET_PALETTE_MAX_SUPPORTED\n#define PNG_READ_GRAY_TO_RGB_SUPPORTED\n#define PNG_READ_INTERLACING_SUPPORTED\n#define PNG_READ_INT_FUNCTIONS_SUPPORTED\n#define PNG_READ_INVERT_ALPHA_SUPPORTED\n#define PNG_READ_INVERT_SUPPORTED\n#define PNG_READ_OPT_PLTE_SUPPORTED\n#define PNG_READ_PACKSWAP_SUPPORTED\n#define PNG_READ_PACK_SUPPORTED\n#define PNG_READ_QUANTIZE_SUPPORTED\n#define PNG_READ_RGB_TO_GRAY_SUPPORTED\n#define PNG_READ_SCALE_16_TO_8_SUPPORTED\n#define PNG_READ_SHIFT_SUPPORTED\n#define PNG_READ_STRIP_16_TO_8_SUPPORTED\n#define PNG_READ_STRIP_ALPHA_SUPPORTED\n#define PNG_READ_SUPPORTED\n#define PNG_READ_SWAP_ALPHA_SUPPORTED\n#define PNG_READ_SWAP_SUPPORTED\n#define PNG_READ_TEXT_SUPPORTED\n#define PNG_READ_TRANSFORMS_SUPPORTED\n#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_READ_USER_CHUNKS_SUPPORTED\n#define PNG_READ_USER_TRANSFORM_SUPPORTED\n#define PNG_READ_bKGD_SUPPORTED\n#define PNG_READ_cHRM_SUPPORTED\n#define PNG_READ_gAMA_SUPPORTED\n#define PNG_READ_hIST_SUPPORTED\n#define PNG_READ_iCCP_SUPPORTED\n#define PNG_READ_iTXt_SUPPORTED\n#define PNG_READ_oFFs_SUPPORTED\n#define PNG_READ_pCAL_SUPPORTED\n#define PNG_READ_pHYs_SUPPORTED\n#define PNG_READ_sBIT_SUPPORTED\n#define PNG_READ_sCAL_SUPPORTED\n#define PNG_READ_sPLT_SUPPORTED\n#define PNG_READ_sRGB_SUPPORTED\n#define PNG_READ_tEXt_SUPPORTED\n#define PNG_READ_tIME_SUPPORTED\n#define PNG_READ_tRNS_SUPPORTED\n#define PNG_READ_zTXt_SUPPORTED\n#define PNG_SAVE_INT_32_SUPPORTED\n#define PNG_SAVE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_SEQUENTIAL_READ_SUPPORTED\n#define PNG_SETJMP_SUPPORTED\n#define PNG_SET_OPTION_SUPPORTED\n#define PNG_SET_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_SET_USER_LIMITS_SUPPORTED\n#define PNG_SIMPLIFIED_READ_AFIRST_SUPPORTED\n#define PNG_SIMPLIFIED_READ_BGR_SUPPORTED\n#define PNG_SIMPLIFIED_READ_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_AFIRST_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_BGR_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_STDIO_SUPPORTED\n#define PNG_SIMPLIFIED_WRITE_SUPPORTED\n#define PNG_STDIO_SUPPORTED\n#define PNG_STORE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_TEXT_SUPPORTED\n#define PNG_TIME_RFC1123_SUPPORTED\n#define PNG_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_USER_CHUNKS_SUPPORTED\n#define PNG_USER_LIMITS_SUPPORTED\n#define PNG_USER_MEM_SUPPORTED\n#define PNG_USER_TRANSFORM_INFO_SUPPORTED\n#define PNG_USER_TRANSFORM_PTR_SUPPORTED\n#define PNG_WARNINGS_SUPPORTED\n#define PNG_WRITE_16BIT_SUPPORTED\n#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED\n#define PNG_WRITE_BGR_SUPPORTED\n#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED\n#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED\n#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED\n#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED\n#define PNG_WRITE_FILLER_SUPPORTED\n#define PNG_WRITE_FILTER_SUPPORTED\n#define PNG_WRITE_FLUSH_SUPPORTED\n#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED\n#define PNG_WRITE_INTERLACING_SUPPORTED\n#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED\n#define PNG_WRITE_INVERT_ALPHA_SUPPORTED\n#define PNG_WRITE_INVERT_SUPPORTED\n#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED\n#define PNG_WRITE_PACKSWAP_SUPPORTED\n#define PNG_WRITE_PACK_SUPPORTED\n#define PNG_WRITE_SHIFT_SUPPORTED\n#define PNG_WRITE_SUPPORTED\n#define PNG_WRITE_SWAP_ALPHA_SUPPORTED\n#define PNG_WRITE_SWAP_SUPPORTED\n#define PNG_WRITE_TEXT_SUPPORTED\n#define PNG_WRITE_TRANSFORMS_SUPPORTED\n#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED\n#define PNG_WRITE_USER_TRANSFORM_SUPPORTED\n#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED\n#define PNG_WRITE_bKGD_SUPPORTED\n#define PNG_WRITE_cHRM_SUPPORTED\n#define PNG_WRITE_gAMA_SUPPORTED\n#define PNG_WRITE_hIST_SUPPORTED\n#define PNG_WRITE_iCCP_SUPPORTED\n#define PNG_WRITE_iTXt_SUPPORTED\n#define PNG_WRITE_oFFs_SUPPORTED\n#define PNG_WRITE_pCAL_SUPPORTED\n#define PNG_WRITE_pHYs_SUPPORTED\n#define PNG_WRITE_sBIT_SUPPORTED\n#define PNG_WRITE_sCAL_SUPPORTED\n#define PNG_WRITE_sPLT_SUPPORTED\n#define PNG_WRITE_sRGB_SUPPORTED\n#define PNG_WRITE_tEXt_SUPPORTED\n#define PNG_WRITE_tIME_SUPPORTED\n#define PNG_WRITE_tRNS_SUPPORTED\n#define PNG_WRITE_zTXt_SUPPORTED\n#define PNG_bKGD_SUPPORTED\n#define PNG_cHRM_SUPPORTED\n#define PNG_gAMA_SUPPORTED\n#define PNG_hIST_SUPPORTED\n#define PNG_iCCP_SUPPORTED\n#define PNG_iTXt_SUPPORTED\n#define PNG_oFFs_SUPPORTED\n#define PNG_pCAL_SUPPORTED\n#define PNG_pHYs_SUPPORTED\n#define PNG_sBIT_SUPPORTED\n#define PNG_sCAL_SUPPORTED\n#define PNG_sPLT_SUPPORTED\n#define PNG_sRGB_SUPPORTED\n#define PNG_tEXt_SUPPORTED\n#define PNG_tIME_SUPPORTED\n#define PNG_tRNS_SUPPORTED\n#define PNG_zTXt_SUPPORTED\n/* end of options */\n/* settings */\n#define PNG_API_RULE 0\n#define PNG_DEFAULT_READ_MACROS 1\n#define PNG_GAMMA_THRESHOLD_FIXED 5000\n#define PNG_IDAT_READ_SIZE PNG_ZBUF_SIZE\n#define PNG_INFLATE_BUF_SIZE 1024\n#define PNG_LINKAGE_API extern\n#define PNG_LINKAGE_CALLBACK extern\n#define PNG_LINKAGE_DATA extern\n#define PNG_LINKAGE_FUNCTION extern\n#define PNG_MAX_GAMMA_8 11\n#define PNG_QUANTIZE_BLUE_BITS 5\n#define PNG_QUANTIZE_GREEN_BITS 5\n#define PNG_QUANTIZE_RED_BITS 5\n#define PNG_TEXT_Z_DEFAULT_COMPRESSION (-1)\n#define PNG_TEXT_Z_DEFAULT_STRATEGY 0\n#define PNG_USER_CHUNK_CACHE_MAX 1000\n#define PNG_USER_CHUNK_MALLOC_MAX 8000000\n#define PNG_USER_HEIGHT_MAX 1000000\n#define PNG_USER_WIDTH_MAX 1000000\n#define PNG_ZBUF_SIZE 8192\n#define PNG_ZLIB_VERNUM 0 /* unknown */\n#define PNG_Z_DEFAULT_COMPRESSION (-1)\n#define PNG_Z_DEFAULT_NOFILTER_STRATEGY 0\n#define PNG_Z_DEFAULT_STRATEGY 1\n#define PNG_sCAL_PRECISION 5\n#define PNG_sRGB_PROFILE_CHECKS 2\n/* end of settings */\n#endif /* PNGLCONF_H */\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/pnglibconf.mak",
    "content": "#!/usr/bin/make -f\n# pnglibconf.mak - standard make lines for pnglibconf.h\n#\n# These lines are copied from Makefile.am, they illustrate\n# how to automate the build of pnglibconf.h from scripts/pnglibconf.dfa\n# given just 'awk', a C preprocessor and standard command line utilities\n\n# Override as appropriate, these definitions can be overridden on\n# the make command line (AWK='nawk' for example).\nAWK = gawk\nAWK = mawk\nAWK = nawk\nAWK = one-true-awk\nAWK = awk  # Crashes on SunOS 5.10 - use 'nawk'\nCPP = $(CC) -E # On SUN OS 5.10 if this causes problems use /lib/cpp\n\nMOVE = mv\nDELETE = rm -f\nECHO = echo\nDFA_XTRA = # Put your configuration file here, see scripts/pnglibconf.dfa.  Eg:\n# DFA_XTRA = pngusr.dfa\n\n# CPPFLAGS should contain the options to control the result,\n# but DEFS and CFLAGS are also supported here, override\n# as appropriate\nDFNFLAGS = $(DEFS) $(CPPFLAGS) $(CFLAGS)\n\n# srcdir is a defacto standard for the location of the source\nsrcdir = .\n\n# The standard pnglibconf.h exists as scripts/pnglibconf.h.prebuilt,\n# copy this if the following doesn't work.\npnglibconf.h: pnglibconf.dfn\n\t$(DELETE) $@ pnglibconf.c pnglibconf.out pnglibconf.tmp\n\t$(ECHO) '#include \"pnglibconf.dfn\"' >pnglibconf.c\n\t$(ECHO) \"If '$(CC) -E' crashes try /lib/cpp (e.g. CPP='/lib/cpp')\" >&2\n\t$(CPP) $(DFNFLAGS) pnglibconf.c >pnglibconf.out\n\t$(AWK) -f \"$(srcdir)/scripts/dfn.awk\" out=\"pnglibconf.tmp\" pnglibconf.out 1>&2\n\t$(MOVE) pnglibconf.tmp $@\n\npnglibconf.dfn: $(srcdir)/scripts/pnglibconf.dfa $(srcdir)/scripts/options.awk $(srcdir)/pngconf.h $(srcdir)/pngusr.dfa $(DFA_XTRA)\n\t$(DELETE) $@ pnglibconf.pre pnglibconf.tmp\n\t$(ECHO) \"Calling $(AWK) from scripts/pnglibconf.mak\" >&2\n\t$(ECHO) \"If 'awk' crashes try a better awk (e.g. AWK='nawk')\" >&2\n\t$(AWK) -f $(srcdir)/scripts/options.awk out=\"pnglibconf.pre\"\\\n\t    version=search $(srcdir)/pngconf.h $(srcdir)/scripts/pnglibconf.dfa\\\n\t    $(srcdir)/pngusr.dfa $(DFA_XTRA) 1>&2\n\t$(AWK) -f $(srcdir)/scripts/options.awk out=\"pnglibconf.tmp\" pnglibconf.pre 1>&2\n\t$(MOVE) pnglibconf.tmp $@\n\nclean-pnglibconf:\n\t$(DELETE) pnglibconf.h pnglibconf.c pnglibconf.out pnglibconf.pre \\\n\tpnglibconf.dfn\n\nclean: clean-pnglibconf\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/pngwin.rc",
    "content": "#define PNG_VERSION_INFO_ONLY\n\n#include <windows.h>\n#include \"../png.h\"\n\n#define _QUOTE(x) # x\n#define QUOTE(x) _QUOTE(x)\n\n#define PNG_LIBPNG_DLLFNAME \"LIBPNG\"\n\n/* Support deprecated PRIVATEBUILD macro */\n#if defined(PRIVATEBUILD) && !defined(PNG_USER_PRIVATEBUILD)\n#  define PNG_USER_PRIVATEBUILD PRIVATEBUILD\n#endif\n\n#if defined(PNG_USER_DLLFNAME_POSTFIX) && !defined(PNG_USER_PRIVATEBUILD)\n#  error \"PNG_USER_PRIVATEBUILD must be defined as a string describing the\\\n custom changes made to the library.\"\n#endif\n\n/* Prioritize PNG_USER_x over PNG_LIBPNG_x */\n#ifdef PNG_USER_DLLFNAME_POSTFIX\n#  undef PNG_LIBPNG_DLLFNAME_POSTFIX\n#  define PNG_LIBPNG_DLLFNAME_POSTFIX PNG_USER_DLLFNAME_POSTFIX\n#endif\n\n#ifdef PNG_USER_VERSIONINFO_COMMENTS\n#  undef PNG_LIBPNG_VERSIONINFO_COMMENTS\n#  define PNG_LIBPNG_VERSIONINFO_COMMENTS PNG_USER_VERSIONINFO_COMMENTS\n#endif\n\n#if defined(PNG_DEBUG) && (PNG_DEBUG > 0)\n#  define VS_DEBUG VS_FF_DEBUG\n#  ifndef PNG_LIBPNG_DLLFNAME_POSTFIX\n#    define PNG_LIBPNG_DLLFNAME_POSTFIX \"D\"\n#  endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */\n#  ifndef PNG_LIBPNG_VERSIONINFO_COMMENTS\n#    define PNG_LIBPNG_VERSIONINFO_COMMENTS \"PNG_DEBUG=\" QUOTE(PNG_DEBUG)\n#  endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */\n#else\n#  define VS_DEBUG 0\n#  ifndef PNG_LIBPNG_DLLFNAME_POSTFIX\n#     define PNG_LIBPNG_DLLFNAME_POSTFIX\n#  endif /* PNG_LIBPNG_DLLFNAME_POSTFIX */\n#endif /* defined(DEBUG)... */\n\n#ifdef PNG_USER_PRIVATEBUILD\n#  define VS_PRIVATEBUILD VS_FF_PRIVATEBUILD\n#else\n#  define VS_PRIVATEBUILD 0\n#endif /* PNG_USER_PRIVATEBUILD */\n\n#ifdef PNG_LIBPNG_SPECIALBUILD\n#  define VS_SPECIALBUILD VS_FF_SPECIALBUILD\n#else\n#  define VS_SPECIALBUILD 0\n#endif /* PNG_LIBPNG_BUILD_SPECIAL */\n\n#if ((PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_RELEASE_STATUS_MASK) !=\\\n      PNG_LIBPNG_BUILD_STABLE)\n#  define VS_PRERELEASE VS_FF_PRERELEASE\n#  define VS_PATCHED 0\n#else\n#  define VS_PRERELEASE 0\n#  if (PNG_LIBPNG_BUILD_BASE_TYPE & PNG_LIBPNG_BUILD_PATCHED)\n#    define VS_PATCHED VS_FF_PATCHED\n#  else\n#    define VS_PATCHED 0\n#  endif\n#endif\n\nVS_VERSION_INFO VERSIONINFO\nFILEVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD\nPRODUCTVERSION PNG_LIBPNG_VER_MAJOR, PNG_LIBPNG_VER_MINOR, PNG_LIBPNG_VER_RELEASE, PNG_LIBPNG_VER_BUILD\nFILEFLAGSMASK VS_FFI_FILEFLAGSMASK\nFILEFLAGS VS_DEBUG | VS_PRIVATEBUILD | VS_SPECIALBUILD | VS_PRERELEASE | VS_PATCHED\nFILEOS VOS__WINDOWS32\nFILETYPE VFT_DLL\nFILESUBTYPE VFT2_UNKNOWN\nBEGIN\n  BLOCK \"StringFileInfo\"\n  BEGIN BLOCK \"040904E4\" /* Language type = U.S English(0x0409) and Character Set = Windows, Multilingual(0x04E4) */\n    BEGIN\n#ifdef PNG_LIBPNG_VERSIONINFO_COMMENTS\n      VALUE \"Comments\", PNG_LIBPNG_VERSIONINFO_COMMENTS \"\\000\"\n#endif /* PNG_LIBPNG_VERSIONINFO_COMMENTS */\n#ifdef PNG_USER_VERSIONINFO_COMPANYNAME\n      VALUE \"CompanyName\", PNG_USER_VERSIONINFO_COMPANYNAME \"\\000\"\n#endif /* PNG_USER_VERSIONINFO_COMPANYNAME */\n      VALUE \"FileDescription\", \"PNG image compression library\\000\"\n      VALUE \"FileVersion\", PNG_LIBPNG_VER_STRING \"\\000\"\n      VALUE \"InternalName\", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX \" (Windows 32 bit)\\000\"\n      VALUE \"LegalCopyright\", \"\\251 1998-2009 Glenn Randers-Pehrson et al.\\000\"\n#ifdef PNG_USER_VERSIONINFO_LEGALTRADEMARKS\n      VALUE \"LegalTrademarks\", PNG_USER_VERSIONINFO_LEGALTRADEMARKS \"\\000\"\n#endif /* PNG_USER_VERSIONINFO_LEGALTRADEMARKS */\n      VALUE \"OriginalFilename\", PNG_LIBPNG_DLLFNAME QUOTE(PNG_LIBPNG_VER_DLLNUM) PNG_LIBPNG_DLLFNAME_POSTFIX \".DLL\\000\"\n#ifdef PNG_USER_PRIVATEBUILD\n      VALUE \"PrivateBuild\", PNG_USER_PRIVATEBUILD \"\\000\"\n#endif /* PNG_USER_PRIVATEBUILD */\n      VALUE \"ProductName\", \"LibPNG\\000\"\n      VALUE \"ProductVersion\", \"1\\000\"\n#ifdef PNG_LIBPNG_SPECIALBUILD\n      VALUE \"SpecialBuild\", PNG_LIBPNG_SPECIALBUILD \"\\000\"\n#endif /* PNG_LIBPNG_SPECIALBUILD */\n    END\n  END\n  BLOCK \"VarFileInfo\"\n  BEGIN\n    VALUE \"Translation\", 0x0409, 0x04E4\n  END\nEND\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/prefix.c",
    "content": "\n/* prefix.c - generate an unprefixed symbol list\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2013-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#define PNG_EXPORTA(ordinal, type, name, args, attributes)\\\n        PNG_DFN \"@\" name \"@\"\n\n/* The configuration information *before* the additional of symbol renames,\n * the list is the C name list; no symbol prefix.\n */\n#include \"pnglibconf.out\"\n\nPNG_DFN_START_SORT 1\n\n#include \"../png.h\"\n\nPNG_DFN_END_SORT\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/smakefile.ppc",
    "content": "# Amiga powerUP (TM) Makefile\n# makefile for libpng and SAS C V6.58/7.00 PPC compiler\n# Copyright (C) 1998 by Andreas R. Kleinert\n#\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\nCC       = scppc\nCFLAGS   = NOSTKCHK NOSINT OPTIMIZE OPTGO OPTPEEP OPTINLOCAL OPTINL IDIR /zlib \\\n           OPTLOOP OPTRDEP=8 OPTDEP=8 OPTCOMP=8\nLIBNAME  = libpng.a\nAR       = ppc-amigaos-ar\nAR_FLAGS = cr\nRANLIB   = ppc-amigaos-ranlib\nLDFLAGS  = -r -o\nLDLIBS   =  ../zlib/libzip.a LIB:scppc.a\nLN       = ppc-amigaos-ld\nRM       = delete quiet\nMKDIR    = makedir\n\nOBJS = png.o pngset.o pngget.o pngrutil.o pngtrans.o pngwutil.o pngread.o \\\n       pngerror.o pngpread.o pngwrite.o pngrtran.o pngwtran.o pngrio.o \\\n       pngwio.o pngmem.o\n\nall: $(LIBNAME) pngtest\n\n$(LIBNAME): $(OBJS)\n            $(AR) $(AR_FLAGS) $@ $(OBJS)\n            $(RANLIB) $@\n\npngtest: pngtest.o $(LIBNAME)\n        $(LN) $(LDFLAGS) pngtest LIB:c_ppc.o pngtest.o $(LIBNAME) $(LDLIBS) \\\nLIB:end.o\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/sym.c",
    "content": "\n/* sym.c - define format of libpng.sym\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2011-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#define PNG_EXPORTA(ordinal, type, name, args, attributes)\\\n        PNG_DFN \"@\" SYMBOL_PREFIX \"@@\" name \"@\"\n\n#include \"../png.h\"\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/symbols.c",
    "content": "\n/* symbols.c - find all exported symbols\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2011-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n/* NOTE: making 'symbols.chk' checks both that the exported\n * symbols in the library don't change and (implicitly) that\n * scripts/pnglibconf.h.prebuilt is as expected.\n * If scripts/pnglibconf.h.prebuilt is remade using\n * scripts/pnglibconf.dfa then this checks the .dfa file too.\n */\n\n#define PNG_EXPORTA(ordinal, type, name, args, attributes)\\\n        PNG_DFN \"@\" name \"@ @@\" ordinal \"@\"\n#define PNG_REMOVED(ordinal, type, name, args, attributes)\\\n        PNG_DFN \"; @\" name \"@ @@\" ordinal \"@\"\n#define PNG_EXPORT_LAST_ORDINAL(ordinal)\\\n        PNG_DFN \"; @@\" ordinal \"@\"\n\n/* Read the defaults, but use scripts/pnglibconf.h.prebuilt; the 'standard'\n * header file.\n */\n#include \"pnglibconf.h.prebuilt\"\n#include \"../png.h\"\n\n/* Some things are turned off by default.  Turn these things\n * on here (by hand) to get the APIs they expose and validate\n * that no harm is done.  This list is the set of options\n * defaulted to 'off' in scripts/pnglibconf.dfa\n *\n * Maintenance: if scripts/pnglibconf.dfa options are changed\n * from, or to, 'disabled' this needs updating!\n */\n#define PNG_BENIGN_ERRORS_SUPPORTED\n#define PNG_ERROR_NUMBERS_SUPPORTED\n#define PNG_READ_BIG_ENDIAN_SUPPORTED  /* should do nothing! */\n#define PNG_INCH_CONVERSIONS_SUPPORTED\n#define PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED\n#define PNG_SET_OPTION_SUPPORTED\n\n#undef PNG_H\n#include \"../png.h\"\n\n/* Finally there are a couple of places where option support\n * actually changes the APIs revealed using a #if/#else/#endif\n * test in png.h, test these here.\n */\n#undef  PNG_FLOATING_POINT_SUPPORTED /* Exposes 'fixed' APIs */\n#undef  PNG_ERROR_TEXT_SUPPORTED     /* Exposes unsupported APIs */\n\n#undef PNG_H\n#include \"../png.h\"\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/symbols.def",
    "content": ";Version 1.6.25\n;--------------------------------------------------------------\n; LIBPNG symbol list as a Win32 DEF file\n; Contains all the symbols that can be exported from libpng\n;--------------------------------------------------------------\nLIBRARY\n\nEXPORTS\n png_access_version_number @1\n png_set_sig_bytes @2\n png_sig_cmp @3\n png_create_read_struct @4\n png_create_write_struct @5\n png_get_compression_buffer_size @6\n png_set_compression_buffer_size @7\n png_set_longjmp_fn @8\n png_longjmp @9\n png_reset_zstream @10\n png_create_read_struct_2 @11\n png_create_write_struct_2 @12\n png_write_sig @13\n png_write_chunk @14\n png_write_chunk_start @15\n png_write_chunk_data @16\n png_write_chunk_end @17\n png_create_info_struct @18\n png_info_init_3 @19\n png_write_info_before_PLTE @20\n png_write_info @21\n png_read_info @22\n png_convert_to_rfc1123 @23\n png_convert_from_struct_tm @24\n png_convert_from_time_t @25\n png_set_expand @26\n png_set_expand_gray_1_2_4_to_8 @27\n png_set_palette_to_rgb @28\n png_set_tRNS_to_alpha @29\n png_set_bgr @30\n png_set_gray_to_rgb @31\n png_set_rgb_to_gray @32\n png_set_rgb_to_gray_fixed @33\n png_get_rgb_to_gray_status @34\n png_build_grayscale_palette @35\n png_set_strip_alpha @36\n png_set_swap_alpha @37\n png_set_invert_alpha @38\n png_set_filler @39\n png_set_add_alpha @40\n png_set_swap @41\n png_set_packing @42\n png_set_packswap @43\n png_set_shift @44\n png_set_interlace_handling @45\n png_set_invert_mono @46\n png_set_background @47\n png_set_strip_16 @48\n png_set_quantize @49\n png_set_gamma @50\n png_set_flush @51\n png_write_flush @52\n png_start_read_image @53\n png_read_update_info @54\n png_read_rows @55\n png_read_row @56\n png_read_image @57\n png_write_row @58\n png_write_rows @59\n png_write_image @60\n png_write_end @61\n png_read_end @62\n png_destroy_info_struct @63\n png_destroy_read_struct @64\n png_destroy_write_struct @65\n png_set_crc_action @66\n png_set_filter @67\n png_set_filter_heuristics @68\n png_set_compression_level @69\n png_set_compression_mem_level @70\n png_set_compression_strategy @71\n png_set_compression_window_bits @72\n png_set_compression_method @73\n png_init_io @74\n png_set_error_fn @75\n png_get_error_ptr @76\n png_set_write_fn @77\n png_set_read_fn @78\n png_get_io_ptr @79\n png_set_read_status_fn @80\n png_set_write_status_fn @81\n png_set_mem_fn @82\n png_get_mem_ptr @83\n png_set_read_user_transform_fn @84\n png_set_write_user_transform_fn @85\n png_set_user_transform_info @86\n png_get_user_transform_ptr @87\n png_set_read_user_chunk_fn @88\n png_get_user_chunk_ptr @89\n png_set_progressive_read_fn @90\n png_get_progressive_ptr @91\n png_process_data @92\n png_progressive_combine_row @93\n png_malloc @94\n png_calloc @95\n png_malloc_warn @96\n png_free @97\n png_free_data @98\n png_data_freer @99\n png_malloc_default @100\n png_free_default @101\n png_error @102\n png_chunk_error @103\n png_err @104\n png_warning @105\n png_chunk_warning @106\n png_benign_error @107\n png_chunk_benign_error @108\n png_set_benign_errors @109\n png_get_valid @110\n png_get_rowbytes @111\n png_get_rows @112\n png_set_rows @113\n png_get_channels @114\n png_get_image_width @115\n png_get_image_height @116\n png_get_bit_depth @117\n png_get_color_type @118\n png_get_filter_type @119\n png_get_interlace_type @120\n png_get_compression_type @121\n png_get_pixels_per_meter @122\n png_get_x_pixels_per_meter @123\n png_get_y_pixels_per_meter @124\n png_get_pixel_aspect_ratio @125\n png_get_x_offset_pixels @126\n png_get_y_offset_pixels @127\n png_get_x_offset_microns @128\n png_get_y_offset_microns @129\n png_get_signature @130\n png_get_bKGD @131\n png_set_bKGD @132\n png_get_cHRM @133\n png_get_cHRM_fixed @134\n png_set_cHRM @135\n png_set_cHRM_fixed @136\n png_get_gAMA @137\n png_get_gAMA_fixed @138\n png_set_gAMA @139\n png_set_gAMA_fixed @140\n png_get_hIST @141\n png_set_hIST @142\n png_get_IHDR @143\n png_set_IHDR @144\n png_get_oFFs @145\n png_set_oFFs @146\n png_get_pCAL @147\n png_set_pCAL @148\n png_get_pHYs @149\n png_set_pHYs @150\n png_get_PLTE @151\n png_set_PLTE @152\n png_get_sBIT @153\n png_set_sBIT @154\n png_get_sRGB @155\n png_set_sRGB @156\n png_set_sRGB_gAMA_and_cHRM @157\n png_get_iCCP @158\n png_set_iCCP @159\n png_get_sPLT @160\n png_set_sPLT @161\n png_get_text @162\n png_set_text @163\n png_get_tIME @164\n png_set_tIME @165\n png_get_tRNS @166\n png_set_tRNS @167\n png_get_sCAL @168\n png_get_sCAL_s @169\n png_set_sCAL @170\n png_set_sCAL_s @171\n png_set_keep_unknown_chunks @172\n png_handle_as_unknown @173\n png_set_unknown_chunks @174\n png_set_unknown_chunk_location @175\n png_get_unknown_chunks @176\n png_set_invalid @177\n png_read_png @178\n png_write_png @179\n png_get_copyright @180\n png_get_header_ver @181\n png_get_header_version @182\n png_get_libpng_ver @183\n png_permit_mng_features @184\n png_set_strip_error_numbers @185\n png_set_user_limits @186\n png_get_user_width_max @187\n png_get_user_height_max @188\n png_set_chunk_cache_max @189\n png_get_chunk_cache_max @190\n png_set_chunk_malloc_max @191\n png_get_chunk_malloc_max @192\n png_get_pixels_per_inch @193\n png_get_x_pixels_per_inch @194\n png_get_y_pixels_per_inch @195\n png_get_x_offset_inches @196\n png_get_y_offset_inches @197\n png_get_pHYs_dpi @198\n png_get_io_state @199\n png_get_uint_32 @201\n png_get_uint_16 @202\n png_get_int_32 @203\n png_get_uint_31 @204\n png_save_uint_32 @205\n png_save_int_32 @206\n png_save_uint_16 @207\n png_set_gamma_fixed @208\n png_set_filter_heuristics_fixed @209\n png_get_pixel_aspect_ratio_fixed @210\n png_get_x_offset_inches_fixed @211\n png_get_y_offset_inches_fixed @212\n png_set_sCAL_fixed @213\n png_get_sCAL_fixed @214\n png_set_background_fixed @215\n png_get_io_chunk_type @216\n png_get_current_row_number @217\n png_get_current_pass_number @218\n png_process_data_pause @219\n png_process_data_skip @220\n png_set_expand_16 @221\n png_set_text_compression_level @222\n png_set_text_compression_mem_level @223\n png_set_text_compression_strategy @224\n png_set_text_compression_window_bits @225\n png_set_text_compression_method @226\n png_set_alpha_mode @227\n png_set_alpha_mode_fixed @228\n png_set_scale_16 @229\n png_get_cHRM_XYZ @230\n png_get_cHRM_XYZ_fixed @231\n png_set_cHRM_XYZ @232\n png_set_cHRM_XYZ_fixed @233\n png_image_begin_read_from_file @234\n png_image_begin_read_from_stdio @235\n png_image_begin_read_from_memory @236\n png_image_finish_read @237\n png_image_free @238\n png_image_write_to_file @239\n png_image_write_to_stdio @240\n png_convert_to_rfc1123_buffer @241\n png_set_check_for_invalid_index @242\n png_get_palette_max @243\n png_set_option @244\n png_image_write_to_memory @245\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/test.cmake.in",
    "content": "# test.cmake.in\n\n# Copyright (C) 2016 Glenn Randers-Pehrson\n# Written by Roger Leigh, 2016\n\n# This code is released under the libpng license.\n# For conditions of distribution and use, see the disclaimer\n# and license in png.h\n\nset(TEST_OPTIONS \"@TEST_OPTIONS@\")\nset(TEST_FILES \"@TEST_FILES@\")\n\nforeach(file ${TEST_FILES})\n  file(TO_NATIVE_PATH \"${file}\" native_file)\n  list(APPEND NATIVE_TEST_FILES \"${native_file}\")\nendforeach()\n\n# Add the directory containing libpng to the PATH (Windows only)\nif(WIN32)\n  get_filename_component(LIBPNG_DIR \"${LIBPNG}\" PATH)\n  file(TO_NATIVE_PATH \"${LIBPNG_DIR}\" LIBPNG_DIR)\n  set(ENV{PATH} \"${LIBPNG_DIR};$ENV{PATH}\")\nendif()\n\nexecute_process(COMMAND \"${CMAKE_COMMAND}\" -E echo \"Running ${TEST_COMMAND}\" ${TEST_OPTIONS} ${NATIVE_TEST_FILES})\n\nexecute_process(COMMAND \"${TEST_COMMAND}\" ${TEST_OPTIONS} ${NATIVE_TEST_FILES}\n                RESULT_VARIABLE TEST_STATUS)\nif(TEST_STATUS)\n  message(FATAL_ERROR \"Returned failed status ${TEST_STATUS}!\")\nendif()\n"
  },
  {
    "path": "tess-two/jni/libpng/scripts/vers.c",
    "content": "\n/* vers.c - define format of libpng.vers\n *\n * Last changed in libpng version 1.6.16 [December 22, 2014]\n * Copyright (c) 2011-2014 Glenn Randers-Pehrson\n *\n * This code is released under the libpng license.\n * For conditions of distribution and use, see the disclaimer\n * and license in png.h\n */\n\n#define PNG_EXPORTA(ordinal, type, name, args, attributes)\\\n        PNG_DFN \" @\" SYMBOL_PREFIX \"@@\" name \"@;\"\n\nPNG_DFN \"@\" PNGLIB_LIBNAME \"@ {global:\"\n\n#include \"../png.h\"\n\nPNG_DFN \"local: *; };\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngimage-full",
    "content": "#!/bin/sh\nexec ./pngimage --exhaustive --list-combos --log \"${srcdir}/contrib/pngsuite/\"*.png\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngimage-quick",
    "content": "#!/bin/sh\nexec ./pngimage --list-combos --log \"${srcdir}/contrib/pngsuite/\"*.png\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest",
    "content": "#!/bin/sh\n#\n# Usage:\n#\n#  tests/pngstest gamma alpha\n#\n# Run ./pngstest on the PNG files in $srcdir/contrib/testpngs which have the\n# given gamma and opacity:\n#\n#  gamma: one of; linear, 1.8, sRGB, none.\n#  alpha: one of; opaque, tRNS, alpha, none.  'none' is equivalent to !alpha\n#\n# NOTE: the temporary files pngstest generates have the base name gamma-alpha to\n# avoid issues with make -j\n#\ngamma=\"$1\"\nshift\nalpha=\"$1\"\nshift\nargs=\nLC_ALL=\"C\" # fix glob sort order to ASCII:\nfor f in \"${srcdir}/contrib/testpngs/\"*.png\ndo\n   g=\n   case \"$f\" in\n      *-linear[.-]*)\n         test \"$gamma\" = \"linear\" && g=\"$f\";;\n\n      *-sRGB[.-]*)\n         test \"$gamma\" = \"sRGB\" && g=\"$f\";;\n\n      *-1.8[.-]*)\n         test \"$gamma\" = \"1.8\" && g=\"$f\";;\n\n      *)\n         test \"$gamma\" = \"none\" && g=\"$f\";;\n   esac\n\n   case \"$g\" in\n      \"\")\n         :;;\n\n      *-alpha[-.]*)\n         test \"$alpha\" = \"alpha\" && args=\"$args $g\";;\n\n      *-tRNS[-.]*)\n         test \"$alpha\" = \"tRNS\" -o \"$alpha\" = \"none\" && args=\"$args $g\";;\n\n      *)\n         test \"$alpha\" = \"opaque\" -o \"$alpha\" = \"none\" && args=\"$args $g\";;\n   esac\ndone\n# This only works if the arguments don't contain spaces; they don't.\nexec ./pngstest --tmpfile \"${gamma}-${alpha}-\" --log ${1+\"$@\"} $args\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-1.8",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" 1.8 none\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-1.8-alpha",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" 1.8 alpha\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-linear",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" linear none\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-linear-alpha",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" linear alpha\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-none",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" none none\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-none-alpha",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" none alpha\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-sRGB",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" sRGB none\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngstest-sRGB-alpha",
    "content": "#!/bin/sh\nexec \"${srcdir}/tests/pngstest\" sRGB alpha\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngtest",
    "content": "#!/bin/sh\nexec ./pngtest --strict ${srcdir}/pngtest.png\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-IDAT",
    "content": "#!/bin/sh\nexec ./pngunknown --strict default=discard IDAT=save \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-discard",
    "content": "#!/bin/sh\nexec ./pngunknown --strict default=discard \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-if-safe",
    "content": "#!/bin/sh\nexec ./pngunknown --strict default=if-safe \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-sAPI",
    "content": "#!/bin/sh\nexec ./pngunknown --strict bKGD=save cHRM=save gAMA=save all=discard iCCP=save sBIT=save sRGB=save \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-sTER",
    "content": "#!/bin/sh\nexec ./pngunknown --strict sTER=if-safe \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-save",
    "content": "#!/bin/sh\nexec ./pngunknown --strict default=save \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngunknown-vpAg",
    "content": "#!/bin/sh\nexec ./pngunknown --strict vpAg=if-safe \"${srcdir}/pngtest.png\"\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-16-to-8",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-16-to-8\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-alpha-mode",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-alpha-mode\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-background",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-background\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-expand16-alpha-mode",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-alpha-mode --expand16\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-expand16-background",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-background --expand16\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-expand16-transform",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-transform --expand16\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-sbit",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-sbit\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-threshold",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-threshold\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-gamma-transform",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --gamma-transform\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-progressive-interlace-standard",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --standard --progressive-read --interlace\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-progressive-size",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --size --progressive-read\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-progressive-standard",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --standard --progressive-read\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-standard",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --standard\n"
  },
  {
    "path": "tess-two/jni/libpng/tests/pngvalid-transform",
    "content": "#!/bin/sh\nexec ./pngvalid --strict --transform\n"
  },
  {
    "path": "tess-two/proguard-rules.pro",
    "content": "# Preserve a method that is called from native code.\n\n-keep class com.googlecode.tesseract.android.TessBaseAPI {\n    protected void onProgressValues(int, int, int, int, int, int, int, int, int);\n}\n"
  },
  {
    "path": "tess-two/project.properties",
    "content": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# This file must be checked in Version Control Systems.\n#\n# To customize properties used by the Ant build system use,\n# \"ant.properties\", and override values to adapt the script to your\n# project structure.\n\nandroid.library=true\n# Project target.\ntarget=android-16\n"
  },
  {
    "path": "tess-two/res/.gitkeep",
    "content": ""
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/AdaptiveMap.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\n/**\n * Image adaptive mapping methods.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class AdaptiveMap {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Background normalization constants\n\n    /** Image reduction value; possible values are 1, 2, 4, 8 */\n    private final static int NORM_REDUCTION = 16;\n\n    /** Desired tile size; actual size may vary */\n    private final static int NORM_SIZE = 3;\n\n    /** Background brightness value; values over 200 may result in clipping */\n    private final static int NORM_BG_VALUE = 200;\n\n    // Adaptive contrast normalization constants\n\n    public final static int DEFAULT_TILE_WIDTH = 10;\n\n    public final static int DEFAULT_TILE_HEIGHT = 15;\n\n    public final static int DEFAULT_MIN_COUNT = 40;\n\n    public final static int DEFAULT_X_SMOOTH_SIZE = 2;\n\n    public final static int DEFAULT_Y_SMOOTH_SIZE = 1;\n\n    /**\n     * Normalizes an image's background using default parameters.\n     *\n     * @param pixs A source pix image.\n     * @return the source pix image with a normalized background\n     */\n    public static Pix backgroundNormMorph(Pix pixs) {\n        return backgroundNormMorph(pixs, NORM_REDUCTION, NORM_SIZE, NORM_BG_VALUE);\n    }\n\n    /**\n     * Normalizes an image's background to a specified value.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>This is a top-level interface for normalizing the image intensity by\n     * mapping the image so that the background is near the input value 'bgval'.\n     * <li>The input image is either grayscale or rgb.\n     * <li>For each component in the input image, the background value is\n     * estimated using a grayscale closing; hence the 'Morph' in the function\n     * name.\n     * <li>An optional binary mask can be specified, with the foreground pixels\n     * typically over image regions. The resulting background map values will be\n     * determined by surrounding pixels that are not under the mask foreground.\n     * The origin (0,0) of this mask is assumed to be aligned with the origin of\n     * the input image. This binary mask must not fully cover pixs, because then\n     * there will be no pixels in the input image available to compute the\n     * background.\n     * <li>The map is computed at reduced size (given by 'reduction') from the\n     * input pixs and optional pixim. At this scale, pixs is closed to remove\n     * the background, using a square Sel of odd dimension. The product of\n     * reduction * size should be large enough to remove most of the text\n     * foreground.\n     * <li>No convolutional smoothing needs to be done on the map before\n     * inverting it.\n     * <li>A 'bgval' target background value for the normalized image. This\n     * should be at least 128. If set too close to 255, some clipping will occur\n     * in the result.\n     * </ol>\n     *\n     * @param pixs A source pix image.\n     * @param normReduction Reduction at which morphological closings are done.\n     * @param normSize Size of square Sel for the closing.\n     * @param normBgValue Target background value.\n     * @return the source pix image with a normalized background\n     */\n    public static Pix backgroundNormMorph(\n            Pix pixs, int normReduction, int normSize, int normBgValue) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        long nativePix = nativeBackgroundNormMorph(\n                pixs.getNativePix(), normReduction, normSize, normBgValue);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to normalize image background\");\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Adaptively attempts to expand the contrast to the full dynamic range in \n     * each tile using default parameters.\n     *\n     * @see #pixContrastNorm(Pix, int, int, int, int, int)\n     * \n     * @param pixs A source pix image\n     * @return a new image with expanded contrast range\n     */\n    public static Pix pixContrastNorm(Pix pixs) {\n        return pixContrastNorm(pixs, DEFAULT_TILE_WIDTH, DEFAULT_TILE_HEIGHT,\n                DEFAULT_MIN_COUNT, DEFAULT_X_SMOOTH_SIZE, DEFAULT_Y_SMOOTH_SIZE);\n    }\n\n    /**\n     * Adaptively attempts to expand the contrast to the full dynamic range in \n     * each tile.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>If the contrast in a tile is smaller than minDiff, it uses the min \n     * and max pixel values from neighboring tiles.  It also can use\n     * convolution to smooth the min and max values from neighboring tiles.  \n     * After all that processing, it is possible that the actual pixel values \n     * in the tile are outside the computed [min ... max] range for local \n     * contrast normalization. Such pixels are taken to be at either 0 (if \n     * below the min) or 255 (if above the max).\n     * <li>sizeX and sizeY give the tile size; they are typically at least 20.\n     * <li>minDiff is used to eliminate results for tiles where it is likely \n     * that either fg or bg is missing.  A value around 50 or more is \n     * reasonable.\n     * <li>The full width and height of the convolution kernel are (2 * smoothx\n     * + 1) and (2 * smoothy + 1).  Some smoothing is typically useful, and we \n     * limit the smoothing half-widths to the range from 0 to 8. Use 0 for no \n     * smoothing.\n     * <li>A linear TRC (gamma = 1.0) is applied to increase the contrast in \n     * each tile. The result can subsequently be globally corrected, by \n     * applying pixGammaTRC() with arbitrary values of gamma and the 0 and 255 \n     * points of the mapping.\n     * </ol>\n     *\n     * @param pixs A source pix image\n     * @param sizeX Tile width\n     * @param sizeY Tile height\n     * @param minDiff Minimum difference to accept as valid\n     * @param smoothX Half-width of convolution kernel applied to min and max\n     * arrays\n     * @param smoothY Half-height of convolution kernel applied to min and max\n     * arrays\n     * @return a new image with expanded contrast range\n     */\n    public static Pix pixContrastNorm(\n            Pix pixs, int sizeX, int sizeY, int minDiff, int smoothX, int smoothY) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        long nativePix = nativePixContrastNorm(\n                pixs.getNativePix(), sizeX, sizeY, minDiff, smoothX, smoothY);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to normalize image contrast\");\n\n        return new Pix(nativePix);\n    }    \n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeBackgroundNormMorph(\n            long nativePix, int reduction, int size, int bgval);\n\n    private static native long nativePixContrastNorm(\n            long nativePix, int sizeX, int sizeY, int minDiff, int smoothX, int smoothY);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Binarize.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport androidx.annotation.FloatRange;\n\n/**\n * Image binarization methods.\n * \n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Binarize {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Otsu thresholding constants\n\n    /** Desired tile X dimension; actual size may vary */\n    public final static int OTSU_SIZE_X = 32;\n\n    /** Desired tile Y dimension; actual size may vary */\n    public final static int OTSU_SIZE_Y = 32;\n\n    /** Desired X smoothing value */\n    public final static int OTSU_SMOOTH_X = 2;\n\n    /** Desired Y smoothing value */\n    public final static int OTSU_SMOOTH_Y = 2;\n\n    /** Fraction of the max Otsu score, typically 0.1 */\n    public final static float OTSU_SCORE_FRACTION = 0.1f;\n\n    // Sauvola thresholding constants\n\n    public final static int SAUVOLA_DEFAULT_WINDOW_HALFWIDTH = 8;\n\n    public final static float SAUVOLA_DEFAULT_REDUCTION_FACTOR = 0.35f;\n\n    public final static int SAUVOLA_DEFAULT_NUM_TILES_X = 1;\n\n    public final static int SAUVOLA_DEFAULT_NUM_TILES_Y = 1;\n\n\n    /**\n     * Performs locally-adaptive Otsu threshold binarization with default\n     * parameters.\n     *\n     * @param pixs An 8 bpp PIX source image.\n     * @return A 1 bpp thresholded PIX image.\n     */\n    public static Pix otsuAdaptiveThreshold(Pix pixs) {\n        return otsuAdaptiveThreshold(\n                pixs, OTSU_SIZE_X, OTSU_SIZE_Y, OTSU_SMOOTH_X, OTSU_SMOOTH_Y, OTSU_SCORE_FRACTION);\n    }\n\n    /**\n     * Performs locally-adaptive Otsu threshold binarization.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>The Otsu method finds a single global threshold for an image. This\n     * function allows a locally adapted threshold to be found for each tile\n     * into which the image is broken up.\n     * <li>The array of threshold values, one for each tile, constitutes a\n     * highly downscaled image. This array is optionally smoothed using a\n     * convolution. The full width and height of the convolution kernel are (2 *\n     * smoothX + 1) and (2 * smoothY + 1).\n     * <li>The minimum tile dimension allowed is 16. If such small tiles are\n     * used, it is recommended to use smoothing, because without smoothing, each\n     * small tile determines the splitting threshold independently. A tile that\n     * is entirely in the image bg will then hallucinate fg, resulting in a very\n     * noisy binarization. The smoothing should be large enough that no tile is\n     * only influenced by one type (fg or bg) of pixels, because it will force a\n     * split of its pixels.\n     * <li>To get a single global threshold for the entire image, use input\n     * values of sizeX and sizeY that are larger than the image. For this\n     * situation, the smoothing parameters are ignored.\n     * <li>The threshold values partition the image pixels into two classes: one\n     * whose values are less than the threshold and another whose values are\n     * greater than or equal to the threshold. This is the same use of\n     * 'threshold' as in pixThresholdToBinary().\n     * <li>The scorefract is the fraction of the maximum Otsu score, which is\n     * used to determine the range over which the histogram minimum is searched.\n     * See numaSplitDistribution() for details on the underlying method of\n     * choosing a threshold.\n     * <li>This uses enables a modified version of the Otsu criterion for\n     * splitting the distribution of pixels in each tile into a fg and bg part.\n     * The modification consists of searching for a minimum in the histogram\n     * over a range of pixel values where the Otsu score is within a defined\n     * fraction, scoreFraction, of the max score. To get the original Otsu\n     * algorithm, set scoreFraction == 0.\n     * </ol>\n     *\n     * @param pixs An 8 bpp PIX source image.\n     * @param sizeX Desired tile X dimension; actual size may vary.\n     * @param sizeY Desired tile Y dimension; actual size may vary.\n     * @param smoothX Half-width of convolution kernel applied to threshold\n     *            array: use 0 for no smoothing.\n     * @param smoothY Half-height of convolution kernel applied to threshold\n     *            array: use 0 for no smoothing.\n     * @param scoreFraction Fraction of the max Otsu score; typ. 0.1 (use 0.0\n     *            for standard Otsu).\n     * @return A 1 bpp thresholded PIX image.\n     */\n    public static Pix otsuAdaptiveThreshold(Pix pixs, int sizeX, int sizeY, int smoothX, int smoothY,\n                                            @FloatRange(from=0.0, to=1.0) float scoreFraction) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n\n        long nativePix = nativeOtsuAdaptiveThreshold(pixs.getNativePix(), \n                sizeX, sizeY, smoothX, smoothY, scoreFraction);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform Otsu adaptive threshold on image\");\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Performs Sauvola binarization using default values.\n     * \n     * @see #sauvolaBinarizeTiled(Pix, int, float, int, int)\n     * \n     * @param pixs An 8 bpp PIX source image.\n     * @return A 1 bpp thresholded PIX image.\n     */\n    public static Pix sauvolaBinarizeTiled(Pix pixs) {\n        return sauvolaBinarizeTiled(pixs, SAUVOLA_DEFAULT_WINDOW_HALFWIDTH, \n                SAUVOLA_DEFAULT_REDUCTION_FACTOR, SAUVOLA_DEFAULT_NUM_TILES_X, \n                SAUVOLA_DEFAULT_NUM_TILES_Y);\n    }\n\n    /**\n     * Performs Sauvola binarization.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li> The window width and height are 2 * whsize + 1.  The minimum\n     * value for whsize is 2; typically it is &gt;= 7.\n     * <li> For nx == ny == 1, this defaults to pixSauvolaBinarize().\n     * <li> Why a tiled version?\n     * (a) Because the mean value accumulator is a uint32, overflow\n     * can occur for an image with more than 16M pixels.\n     * (b) The mean value accumulator array for 16M pixels is 64 MB.\n     * The mean square accumulator array for 16M pixels is 128 MB.\n     * Using tiles reduces the size of these arrays.\n     * (c) Each tile can be processed independently, in parallel,\n     * on a multicore processor.\n     * <li> The Sauvola threshold is determined from the formula:\n     *   t = m * (1 - k * (1 - s / 128))\n     * where:\n     *   t = local threshold\n     *   m = local mean\n     *   k = @factor (&gt;= 0)   [ typ. 0.35 ]\n     *   s = local standard deviation, which is maximized at\n     *       127.5 when half the samples are 0 and half are 255.\n     * <li> The basic idea of Niblack and Sauvola binarization is that\n     * the local threshold should be less than the median value, and the larger\n     * the variance, the closer to the median it should be chosen.  Typical \n     * values for k are between 0.2 and 0.5.\n     * </ol>\n     *   \n     * @param pixs An 8 bpp PIX source image.\n     * @param whsize Window half-width for measuring local statistics\n     * @param factor Factor for reducing threshold due to variance; &gt;= 0\n     * @param nx Subdivision into tiles; &gt;= 1\n     * @param ny Subdivision into tiles; &gt;= 1\n     * @return A 1 bpp thresholded PIX image.\n     */\n    public static Pix sauvolaBinarizeTiled(Pix pixs, int whsize, @FloatRange(from=0.0) float factor,\n                                           int nx, int ny) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n\n        long nativePix = nativeSauvolaBinarizeTiled(pixs.getNativePix(), \n                whsize, factor, nx, ny);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform Sauvola binarization on image\");\n\n        return new Pix(nativePix);        \n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeOtsuAdaptiveThreshold(\n            long nativePix, int sizeX, int sizeY, int smoothX, int smoothY, float scoreFract);\n\n    private static native long nativeSauvolaBinarizeTiled(\n            long nativePix, int whsize, float factor, int nx, int ny);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Box.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Rect;\nimport androidx.annotation.Size;\nimport android.util.Log;\n\n/**\n * Wrapper for Leptonica's native BOX.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Box {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    private static final String TAG = Box.class.getSimpleName();\n\n    /** The index of the X coordinate within the geometry array. */\n    public static final int INDEX_X = 0;\n\n    /** The index of the Y coordinate within the geometry array. */\n    public static final int INDEX_Y = 1;\n\n    /** The index of the width within the geometry array. */\n    public static final int INDEX_W = 2;\n\n    /** The index of the height within the geometry array. */\n    public static final int INDEX_H = 3;\n\n    /**\n     * A pointer to the native Box object. This is used internally by native\n     * code.\n     */\n    private final long mNativeBox;\n\n    private boolean mRecycled = false;\n\n    /**\n     * Creates a new Box wrapper for the specified native BOX.\n     *\n     * @param nativeBox A pointer to the native BOX.\n     */\n    Box(long nativeBox) {\n        mNativeBox = nativeBox;\n        mRecycled = false;\n    }\n\n    /**\n     * Creates a box with the specified geometry. All dimensions should be\n     * non-negative and specified in pixels.\n     *\n     * @param x X-coordinate of the top-left corner of the box.\n     * @param y Y-coordinate of the top-left corner of the box.\n     * @param w Width of the box.\n     * @param h Height of the box.\n     */\n    public Box(int x, int y, int w, int h) {\n        if (x < 0 || y < 0 || w < 0 || h < 0) {\n            throw new IllegalArgumentException(\"All box dimensions must be non-negative\");\n        }\n\n        long nativeBox = nativeCreate(x, y, w, h);\n\n        if (nativeBox == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        mNativeBox = nativeBox;\n        mRecycled = false;\n    }\n\n    /**\n     * Returns a pointer to the native Box object.\n     *\n     * @return a pointer to the native Box object\n     */\n    public long getNativeBox() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mNativeBox;\n    }\n\n    /**\n     * Returns the box's x-coordinate in pixels.\n     * \n     * @return The box's x-coordinate in pixels.\n     */\n    public int getX() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetX(mNativeBox);\n    }\n\n    /**\n     * Returns the box's y-coordinate in pixels.\n     * \n     * @return The box's y-coordinate in pixels.\n     */\n    public int getY() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetY(mNativeBox);\n    }\n\n    /**\n     * Returns the box's width in pixels.\n     * \n     * @return The box's width in pixels.\n     */\n    public int getWidth() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetWidth(mNativeBox);\n    }\n\n    /**\n     * Returns the box's height in pixels.\n     * \n     * @return The box's height in pixels.\n     */\n    public int getHeight() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetHeight(mNativeBox);\n    }\n\n    /**\n     * Returns an {@link android.graphics.Rect} containing the coordinates\n     * of this box.\n     *\n     * @return a rect representing the box\n     */\n    public Rect getRect() {\n        int[] geometry = getGeometry();\n        int left = geometry[Box.INDEX_X];\n        int top = geometry[Box.INDEX_Y];\n        int right = left + geometry[Box.INDEX_W];\n        int bottom = top + geometry[Box.INDEX_H];\n        return new Rect(left, top, right, bottom);\n    }\n\n    /**\n     * Returns an array containing the coordinates of this box. See INDEX_*\n     * constants for indices.\n     *\n     * @return an array of box coordinates\n     */\n    public int[] getGeometry() {\n        int[] geometry = new int[4];\n\n        if (getGeometry(geometry)) {\n            return geometry;\n        }\n\n        return null;\n    }\n\n    /**\n     * Fills an array containing the coordinates of this box. See INDEX_*\n     * constants for indices.\n     *\n     * @param geometry A 4+ element integer array to fill with coordinates.\n     * @return <code>true</code> on success\n     */\n    public boolean getGeometry(@Size(min=4) int[] geometry) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        if (geometry.length < 4) {\n            throw new IllegalArgumentException(\"Geometry array must be at least 4 elements long\");\n        }\n\n        return nativeGetGeometry(mNativeBox, geometry);\n    }\n\n    /**\n     * Releases resources and frees any memory associated with this Box.\n     */\n    public void recycle() {\n        if (!mRecycled) {\n            nativeDestroy(mNativeBox);\n\n            mRecycled = true;\n        }\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        try {\n            if (!mRecycled) {\n                Log.w(TAG, \"Box was not terminated using recycle()\");\n                recycle();\n            }\n        } finally {\n            super.finalize();\n        }\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeCreate(int x, int y, int w, int h);\n    private static native int nativeGetX(long nativeBox);\n    private static native int nativeGetY(long nativeBox);\n    private static native int nativeGetWidth(long nativeBox);\n    private static native int nativeGetHeight(long nativeBox);\n    private static native void nativeDestroy(long nativeBox);\n    private static native boolean nativeGetGeometry(long nativeBox, int[] geometry);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Boxa.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Rect;\nimport androidx.annotation.Size;\nimport android.util.Log;\n\n/**\n * Wrapper for Leptonica's native BOXA.\n *\n * @author renard\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Boxa {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    private static final String TAG = Boxa.class.getSimpleName();\n\n    /**\n     * A pointer to the native Boxa object. This is used internally by native\n     * code.\n     */\n    private final long mNativeBoxa;\n\n    private boolean mRecycled = false;\n\n    /**\n     * Creates a new Box wrapper for the specified native BOX.\n     *\n     * @param nativeBoxa A pointer to the native Boxa object.\n     */\n    public Boxa(long nativeBoxa) {\n        mNativeBoxa = nativeBoxa;\n        mRecycled = false;\n    }\n\n    // TODO Add constructors.\n\n    /**\n     * Returns a pointer to the native Boxa object.\n     *\n     * @return a pointer to the native Boxa object\n     */\n    public long getNativeBoxa() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mNativeBoxa;\n    }\n\n    public int getCount() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetCount(mNativeBoxa);\n    }\n\n    /**\n     * Returns an {@link android.graphics.Rect} containing the coordinates\n     * of this box.\n     *\n     * @param index which box element to refer to\n     * @return a rect representing the box\n     */\n    public Rect getRect(int index) {\n        int[] geometry = getGeometry(index);\n        int left = geometry[Box.INDEX_X];\n        int top = geometry[Box.INDEX_Y];\n        int right = left + geometry[Box.INDEX_W];\n        int bottom = top + geometry[Box.INDEX_H];\n        return new Rect(left, top, right, bottom);\n    }\n\n    /**\n     * Returns an array containing the coordinates of this box. See INDEX_*\n     * constants for indices.\n     *\n     * @param index which box element to refer to\n     * @return an array of box coordinates\n     */\n    public int[] getGeometry(int index) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        int[] geometry = new int[4];\n\n        if (getGeometry(index, geometry)) {\n            return geometry;\n        }\n\n        return null;\n    }\n\n    /**\n     * Fills an array containing the coordinates of this box. See INDEX_*\n     * constants for indices.\n     *\n     * @param index which box element to refer to\n     * @param geometry A 4+ element integer array to fill with coordinates.\n     * @return <code>true</code> on success\n     */\n    public boolean getGeometry(int index, @Size(min=4) int[] geometry) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        if (geometry.length < 4) {\n            throw new IllegalArgumentException(\"Geometry array must be at least 4 elements long\");\n        }\n\n        return nativeGetGeometry(mNativeBoxa, index, geometry);\n    }\n\n    /**\n     * Releases resources and frees any memory associated with this Box.\n     */\n    public synchronized void recycle() {\n        if (!mRecycled) {\n            nativeDestroy(mNativeBoxa);\n\n            mRecycled = true;\n        }\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        try {\n            if (!mRecycled) {\n                Log.w(TAG, \"Boxa was not terminated using recycle()\");\n                recycle();\n            }\n        } finally {\n            super.finalize();\n        }\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native void nativeDestroy(long nativeBox);\n    private static native boolean nativeGetGeometry(long nativeBoxa, int index,  int[] geometry);\n    private static native int nativeGetCount(long nativeBoxa);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Clip.java",
    "content": "/*\r\n * Copyright 2014 Robert Theis\r\n * \r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n * \r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n * \r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\npackage com.googlecode.leptonica.android;\r\n\r\n/**\r\n * Extract rectangular regions.\r\n */\r\npublic class Clip {\r\n    static {\r\n        System.loadLibrary(\"lept\");\r\n    }\r\n\r\n    /**\r\n     * Extract a region from a Pix.\r\n     * <p>\r\n     * Notes:\r\n     * <p>\r\n     * This should be simple, but there are choices to be made. The box is\r\n     * defined relative to the pix coordinates.  However, if the box is not\r\n     * contained within the pix, we have two choices:\r\n     * <p>     (1) clip the box to the pix\r\n     * <p>     (2) make a new pix equal to the full box dimensions,\r\n     *             but let rasterop do the clipping and positioning\r\n     *             of the src with respect to the dest\r\n     * <p>\r\n     * Choice (2) immediately brings up the problem of what pixel values\r\n     * to use that were not taken from the src.  For example, on a grayscale\r\n     * image, do you want the pixels not taken from the src to be black\r\n     * or white or something else?  To implement choice 2, one needs to\r\n     * specify the color of these extra pixels.\r\n     * <p>\r\n     * So we adopt (1), and clip the box first, if necessary,\r\n     * before making the dest pix and doing the rasterop.  But there\r\n     * is another issue to consider.  If you want to paste the\r\n     * clipped pix back into pixs, it must be properly aligned, and\r\n     * it is necessary to use the clipped box for alignment.\r\n     *\r\n     * @param source Source pix\r\n     * @param box Requested clipping region\r\n     * @return clipped pix, or null if rectangle doesn't intersect source pix\r\n     */\r\n    public static Pix clipRectangle(Pix source, Box box) {\r\n        long result = nativeClipRectangle(source.getNativePix(),\r\n                box.getNativeBox());\r\n        if (result != 0) {\r\n            return new Pix(result);\r\n        }\r\n        return null;\r\n    }\r\n\r\n    // ***************\r\n    // * NATIVE CODE *\r\n    // ***************\r\n\r\n    private static native long nativeClipRectangle(long nativePix, long nativeBox);\r\n}"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Constants.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport androidx.annotation.IntDef;\n\nimport java.lang.annotation.Retention;\n\nimport static java.lang.annotation.RetentionPolicy.SOURCE;\n\n/**\n * Leptonica constants.\n *\n * @author alanv@google.com (Alan Viverette)\n */\npublic class Constants {\n    /*-------------------------------------------------------------------------*\n     *                         Access and storage flags                        *\n     *-------------------------------------------------------------------------*/\n    /*\n     * For Pix, Box, Pta and Numa, there are 3 standard methods for handling the\n     * retrieval or insertion of a struct: (1) direct insertion (Don't do this\n     * if there is another handle somewhere to this same struct!) (2) copy\n     * (Always safe, sets up a refcount of 1 on the new object. Can be\n     * undesirable if very large, such as an image or an array of images.) (3)\n     * clone (Makes another handle to the same struct, and bumps the refcount up\n     * by 1. Safe to do unless you're changing data through one of the handles\n     * but don't want those changes to be seen by the other handle.) For Pixa\n     * and Boxa, which are structs that hold an array of clonable structs, there\n     * is an additional method: (4) copy-clone (Makes a new higher-level struct\n     * with a refcount of 1, but clones all the structs in the array.) Unlike\n     * the other structs, when retrieving a string from an Sarray, you are\n     * allowed to get a handle without a copy or clone (i.e., that you don't\n     * own!). You must not free or insert such a string! Specifically, for an\n     * Sarray, the copyflag for retrieval is either: TRUE (or 1 or L_COPY) or\n     * FALSE (or 0 or L_NOCOPY) For insertion, the copyflag is either: TRUE (or\n     * 1 or L_COPY) or FALSE (or 0 or L_INSERT) Note that L_COPY is always 1,\n     * and L_INSERT and L_NOCOPY are always 0.\n     */\n\n    @Retention(SOURCE)\n    @IntDef({L_INSERT, L_COPY, L_CLONE})\n    public @interface StorageFlag {}\n\n    /* Stuff it in; no copy, clone or copy-clone */\n    public static final int L_INSERT = 0;\n\n    /* Make/use a copy of the object */\n    public static final int L_COPY = 1;\n\n    /* Make/use clone (ref count) of the object */\n    public static final int L_CLONE = 2;\n\n    /*\n     * Make a new object and fill with with clones of each object in the\n     * array(s)\n     */\n    public static final int L_COPY_CLONE = 3;\n\n    /*--------------------------------------------------------------------------*\n     *                              Sort flags                                  *\n     *--------------------------------------------------------------------------*/\n\n    @Retention(SOURCE)\n    @IntDef({L_SORT_INCREASING, L_SORT_DECREASING})\n    public @interface SortOrder {}\n\n    /* Sort in increasing order */\n    public static final int L_SORT_INCREASING = 1;\n\n    /* Sort in decreasing order */\n    public static final int L_SORT_DECREASING = 2;\n\n    @Retention(SOURCE)\n    @IntDef({L_SORT_BY_X, L_SORT_BY_Y, L_SORT_BY_WIDTH, L_SORT_BY_HEIGHT, L_SORT_BY_MIN_DIMENSION,\n            L_SORT_BY_MAX_DIMENSION, L_SORT_BY_PERIMETER, L_SORT_BY_ASPECT_RATIO})\n    public @interface SortBy {}\n\n    /* Sort box or c.c. by horiz location */\n    public static final int L_SORT_BY_X = 3;\n\n    /* Sort box or c.c. by vert location */\n    public static final int L_SORT_BY_Y = 4;\n\n    /* Sort box or c.c. by width */\n    public static final int L_SORT_BY_WIDTH = 5;\n\n    /* Sort box or c.c. by height */\n    public static final int L_SORT_BY_HEIGHT = 6;\n\n    /* Sort box or c.c. by min dimension */\n    public static final int L_SORT_BY_MIN_DIMENSION = 7;\n\n    /* Sort box or c.c. by max dimension */\n    public static final int L_SORT_BY_MAX_DIMENSION = 8;\n\n    /* Sort box or c.c. by perimeter */\n    public static final int L_SORT_BY_PERIMETER = 9;\n\n    /* Sort box or c.c. by area */\n    public static final int L_SORT_BY_AREA = 10;\n\n    /* Sort box or c.c. by width/height ratio */\n    public static final int L_SORT_BY_ASPECT_RATIO = 11;\n\n    /* ------------------ Image file format types -------------- */\n    /*\n     * The IFF_DEFAULT flag is used to write the file out in the same (input)\n     * file format that the pix was read from. If the pix was not read from\n     * file, the input format field will be IFF_UNKNOWN and the output file\n     * format will be chosen to be compressed and lossless; namely, IFF_TIFF_G4\n     * for d = 1 and IFF_PNG for everything else. IFF_JP2 is for jpeg2000.\n     */\n\n    public static final int IFF_UNKNOWN = 0;\n\n    public static final int IFF_BMP = 1;\n\n    public static final int IFF_JFIF_JPEG = 2;\n\n    public static final int IFF_PNG = 3;\n\n    public static final int IFF_TIFF = 4;\n\n    public static final int IFF_TIFF_PACKBITS = 5;\n\n    public static final int IFF_TIFF_RLE = 6;\n\n    public static final int IFF_TIFF_G3 = 7;\n\n    public static final int IFF_TIFF_G4 = 8;\n\n    public static final int IFF_TIFF_LZW = 9;\n\n    public static final int IFF_TIFF_ZIP = 10;\n\n    public static final int IFF_PNM = 11;\n\n    public static final int IFF_PS = 12;\n\n    public static final int IFF_GIF = 13;\n\n    public static final int IFF_JP2 = 14;\n\n    public static final int IFF_DEFAULT = 15;\n\n    public static final int IFF_SPIX = 16;\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Convert.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\n/**\n * Image bit-depth conversion methods.\n * \n * @author alanv@google.com (Alan Viverette)\n */\npublic class Convert {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n    \n    /**\n     * Converts an image of any bit depth to 8-bit grayscale.\n     *\n     * @param pixs Source pix of any bit-depth.\n     * @return a new Pix image or <code>null</code> on error\n     */\n    public static Pix convertTo8(Pix pixs) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        long nativePix = nativeConvertTo8(pixs.getNativePix());\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to natively convert pix\");\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeConvertTo8(long nativePix);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Edge.java",
    "content": "/*\n * Copyright (C) 2014 Robert Theis\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport androidx.annotation.IntDef;\n\nimport java.lang.annotation.Retention;\n\nimport static java.lang.annotation.RetentionPolicy.SOURCE;\n\n/**\n * Edge detection.\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Edge {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Edge orientation flags\n    @Retention(SOURCE)\n    @IntDef({L_HORIZONTAL_EDGES, L_VERTICAL_EDGES, L_ALL_EDGES})\n    public @interface EdgeOrientationFlag {}\n\n    /** Filters for horizontal edges */\n    public static final int L_HORIZONTAL_EDGES = 0;\n\n    /** Filters for vertical edges */\n    public static final int L_VERTICAL_EDGES = 1;\n\n    /** Filters for all edges */\n    public static final int L_ALL_EDGES = 2;\n\n    /**\n     * Performs a Sobel edge detecting filter.\n     * <p>\n     * To use both the vertical and horizontal filters, set the orientation\n     * flag to L_ALL_EDGES; this sums the abs. value of their outputs,\n     * clipped to 255.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li> Invert pixd to see larger gradients as darker (grayscale).\n     * <li> To generate a binary image of the edges, threshold the result\n     * using pixThresholdToBinary().  If the high edge values are to be fg (1),\n     * invert after running pixThresholdToBinary().\n     * <li> Label the pixels as follows:\n     * <p>         1    4    7\n     * <p>         2    5    8\n     * <p>         3    6    9\n     * <p>\n     * Read the data incrementally across the image and unroll the loop.\n     * <li> This runs at about 45 Mpix/sec on a 3 GHz processor.\n     * </ol>\n     * \n     * @param pixs Source pix (8 bpp; no colormap)\n     * @param orientFlag Edge orientation flag (L_HORIZONTAL_EDGES, \n     *        L_VERTICAL_EDGES, L_ALL_EDGES)\n     * @return a new Pix image (8bpp, edges are brighter), or null on error\n     */\n    public static Pix pixSobelEdgeFilter(Pix pixs, @EdgeOrientationFlag int orientFlag) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (orientFlag < 0 || orientFlag > 2)\n            throw new IllegalArgumentException(\"Invalid orientation flag\");\n\n        long nativePix = nativePixSobelEdgeFilter(pixs.getNativePix(), \n                orientFlag);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform Sobel edge filter on image\");\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativePixSobelEdgeFilter(long nativePix, int orientFlag);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Enhance.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\n/**\n * Image sharpening methods.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Enhance {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Unsharp masking constants\n    \n    public final static int DEFAULT_UNSHARP_HALFWIDTH = 1;\n    \n    public final static float DEFAULT_UNSHARP_FRACTION = 0.3f;\n    \n    /**\n     * Performs unsharp masking (edge enhancement) using default values.\n     * \n     * @see #unsharpMasking(Pix, int, float)\n     * \n     * @param pixs Source image\n     * @return an edge-enhanced Pix image or copy if no enhancement requested\n     */\n    public static Pix unsharpMasking(Pix pixs) {\n        return unsharpMasking(pixs, DEFAULT_UNSHARP_HALFWIDTH, \n                DEFAULT_UNSHARP_FRACTION);\n    }\n    \n    /**\n     * Performs unsharp masking (edge enhancement).\n     * <p>\n     * Notes:\n     * <ul>\n     * <li>We use symmetric smoothing filters of odd dimension, typically use\n     * sizes of 3, 5, 7, etc. The <code>halfwidth</code> parameter for these is\n     * (size - 1)/2; i.e., 1, 2, 3, etc.</li>\n     * <li>The <code>fract</code> parameter is typically taken in the range: 0.2\n     * &lt; <code>fract</code> &lt; 0.7</li>\n     * </ul>\n     *\n     * @param pixs The source image\n     * @param halfwidth The half-width of the smoothing filter.\n     * @param fraction The fraction of edge to be added back into the source\n     *            image.\n     * @return an edge-enhanced Pix image or copy if no enhancement requested\n     */\n    public static Pix unsharpMasking(Pix pixs, int halfwidth, float fraction) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        long nativePix = nativeUnsharpMasking(pixs.getNativePix(), halfwidth, \n                fraction);\n\n        if (nativePix == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeUnsharpMasking(long nativePix, int halfwidth, float fract);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/GrayQuant.java",
    "content": "/*\n * Copyright (C) 2014 Robert Theis\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\npublic class GrayQuant {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    /**\n     * Perform simple (pixelwise) binarization with fixed threshold\n     * <p>\n     * Notes:\n     * <ol>\n     * <li> If the source pixel is less than the threshold value, the dest will \n     * be 1; otherwise, it will be 0\n     * </ol>\n     *\n     * @param pixs Source pix (4 or 8 bpp)\n     * @param thresh Threshold value\n     * @return a new Pix image, 1 bpp\n     */\n    public static Pix pixThresholdToBinary(Pix pixs, int thresh) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        int depth = pixs.getDepth();\n        if (depth != 4 && depth != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 4 or 8 bpp\");\n        if (depth == 4 && thresh > 16)\n            throw new IllegalArgumentException(\"4 bpp thresh not in {0-16}\");\n        if (depth == 8 && thresh > 256)\n            throw new IllegalArgumentException(\"8 bpp thresh not in {0-256}\");\n\n        long nativePix = nativePixThresholdToBinary(pixs.getNativePix(), \n                thresh);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform binarization\");\n\n        return new Pix(nativePix);         \n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativePixThresholdToBinary(long nativePix, int thresh);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/JpegIO.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Bitmap;\nimport android.graphics.Bitmap.CompressFormat;\nimport androidx.annotation.IntRange;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.IOException;\n\n/**\n * JPEG input and output methods.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class JpegIO {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    /** Default quality is 85%, which is reasonably good. */\n    public static final int DEFAULT_QUALITY = 85;\n\n    /** Progressive encoding is disabled by default to increase compatibility. */\n    public static final boolean DEFAULT_PROGRESSIVE = false;\n\n    /**\n     * Returns a compressed JPEG byte representation of this Pix using default\n     * parameters.\n     *\n     * @param pixs A source Pix image.\n     * @return a compressed JPEG byte array representation of the Pix\n     */\n    public static byte[] compressToJpeg(Pix pixs) {\n        return compressToJpeg(pixs, DEFAULT_QUALITY, DEFAULT_PROGRESSIVE);\n    }\n\n    /**\n     * Returns a compressed JPEG byte representation of this Pix.\n     *\n     * @param pixs A source pix image.\n     * @param quality The quality of the compressed image. Valid range is 0-100.\n     * @param progressive Whether to use progressive compression.\n     * @return a compressed JPEG byte array representation of the Pix\n     */\n    public static byte[] compressToJpeg(Pix pixs, @IntRange(from=0, to=100) int quality,\n                                        boolean progressive) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (quality < 0 || quality > 100)\n            throw new IllegalArgumentException(\"Quality must be between 0 and 100 (inclusive)\");\n\n        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();\n        final Bitmap bmp = WriteFile.writeBitmap(pixs);\n        bmp.compress(CompressFormat.JPEG, quality, byteStream);\n        bmp.recycle();\n\n        final byte[] encodedData = byteStream.toByteArray();\n\n        try {\n            byteStream.close();\n        } catch (IOException e) {\n            e.printStackTrace();\n        }\n\n        return encodedData;\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native byte[] nativeCompressToJpeg(\n            long nativePix, int quality, boolean progressive);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/MorphApp.java",
    "content": "/*\n * Copyright (C) 2014 Robert Theis\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport androidx.annotation.IntDef;\n\nimport java.lang.annotation.Retention;\n\nimport static java.lang.annotation.RetentionPolicy.SOURCE;\n\n/**\n * Composite image processing operations.\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class MorphApp {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Morphological tophat flags\n    @Retention(SOURCE)\n    @IntDef({L_TOPHAT_BLACK, L_TOPHAT_WHITE})\n    public @interface TophatType {}\n    public static final int L_TOPHAT_WHITE = 0;\n    public static final int L_TOPHAT_BLACK = 1;\n\n    public static final int DEFAULT_WIDTH = 7;\n\n    public static final int DEFAULT_HEIGHT = 7;\n\n    /**\n     * Performs a tophat transform.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li> Sel is a brick with all elements being hits\n     * <li> If hsize = vsize = 1, returns an image with all 0 data.\n     * <li> The L_TOPHAT_WHITE flag emphasizes small bright regions, whereas\n     * the L_TOPHAT_BLACK flag emphasizes small dark regions. The L_TOPHAT_WHITE\n     * tophat can be accomplished by doing a L_TOPHAT_BLACK tophat on the \n     * inverse, or v.v.\n     * </ol>\n     *     \n     * @param pixs Source pix (8bpp)\n     * @param hsize (of Sel; must be odd; origin implicitly in center)\n     * @param vsize (ditto)\n     * @param type L_TOPHAT_WHITE: image - opening or L_TOPHAT_BLACK: closing - image\n     * @return a new Pix image\n     */\n    public static Pix pixTophat(Pix pixs, int hsize, int vsize, @TophatType int type) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (hsize < 1 || vsize < 1)\n            throw new IllegalArgumentException(\"hsize or vsize < 1\");\n        if (type < 0 || type > 1)\n            throw new IllegalArgumentException(\"Type must be L_TOPHAT_BLACK or L_TOPHAT_WHITE\");\n\n        long nativePix = nativePixTophat(pixs.getNativePix(), hsize, vsize, \n                type);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform Tophat on image\");\n\n        return new Pix(nativePix); \n    }\n\n    /**\n     * Performs a tophat-like operation emphasizing small dark regions using\n     * default values.\n     * \n     * @see #pixFastTophat(Pix, int, int, int)\n     * \n     * @param pixs Source pix (8bpp)\n     * @return a new Pix image\n     */\n    public static Pix pixFastTophatBlack(Pix pixs) {\n        return pixFastTophat(pixs, DEFAULT_WIDTH, DEFAULT_HEIGHT, L_TOPHAT_BLACK);\n    }\n\n    /**\n     * Performs a tophat-like operation emphasizing small bright regions using\n     * default values.\n     * \n     * @see #pixFastTophat(Pix, int, int, int)\n     * \n     * @param pixs Source pix (8bpp)\n     * @return a new Pix image\n     */\n    public static Pix pixFastTophatWhite(Pix pixs) {\n        return pixFastTophat(pixs, DEFAULT_WIDTH, DEFAULT_HEIGHT, L_TOPHAT_WHITE);\n    }\n\n    /**\n     * Performs a tophat-like operation.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li> Don't be fooled. This is NOT a tophat.  It is a tophat-like\n     * operation, where the result is similar to what you'd get if you used an \n     * erosion instead of an opening, or a dilation instead of a closing.\n     * \n     * <li> Instead of opening or closing at full resolution, it does a fast\n     * downscale/minmax operation, then a quick small smoothing at low res, a \n     * replicative expansion of the \"background\" to full res, and finally a \n     * removal of the background level from the input image.  The smoothing \n     * step may not be important.\n     * \n     * <li> It does not remove noise as well as a tophat, but it is 5 to 10 \n     * times faster. If you need the preciseness of the tophat, don't use this.\n     * <li> The L_TOPHAT_WHITE flag emphasizes small bright regions, whereas \n     * the L_TOPHAT_BLACK flag emphasizes small dark regions.\n     * </ol>\n     *\n     * @param pixs Source pix (8bpp)\n     * @param xsize width of max/min op, smoothing; any integer &gt;= 1\n     * @param ysize height of max/min op, smoothing; any integer &gt;= 1\n     * @param type L_TOPHAT_WHITE: image - min, or L_TOPHAT_BLACK: max - image\n     * @return a new Pix image\n     */\n    public static Pix pixFastTophat(Pix pixs, int xsize, int ysize, @TophatType int type) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixs.getDepth() != 8)\n            throw new IllegalArgumentException(\"Source pix depth must be 8bpp\");\n        if (xsize < 1 || ysize < 1)\n            throw new IllegalArgumentException(\"size < 1\");\n        if (type < 0 || type > 1)\n            throw new IllegalArgumentException(\"Type must be L_TOPHAT_BLACK or L_TOPHAT_WHITE\");\n\n        long nativePix = nativePixFastTophat(pixs.getNativePix(), xsize, ysize, \n                type);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to perform pixFastTophat on image\");\n\n        return new Pix(nativePix); \n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativePixTophat(long nativePix, int hsize, int vsize, int type);\n\n    private static native long nativePixFastTophat(long nativePix, int xsize, int ysize, int type);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Pix.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Rect;\nimport androidx.annotation.ColorInt;\nimport androidx.annotation.Size;\n\n/**\n * Java representation of a native Leptonica PIX object.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Pix {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    /** Index of the image width within the dimensions array. */\n    public static final int INDEX_W = 0;\n\n    /** Index of the image height within the dimensions array. */\n    public static final int INDEX_H = 1;\n\n    /** Index of the image bit-depth within the dimensions array. */\n    public static final int INDEX_D = 2;\n\n    /** Package-accessible pointer to native pix */\n    private final long mNativePix;\n\n    private boolean mRecycled;\n\n    /**\n     * Creates a new Pix wrapper for the specified native PIX object.\n     *\n     * @param nativePix A pointer to the native PIX object.\n     */\n    public Pix(long nativePix) {\n        mNativePix = nativePix;\n        mRecycled = false;\n    }\n\n    public Pix(int width, int height, int depth) {\n        if (width <= 0 || height <= 0) {\n            throw new IllegalArgumentException(\"Pix width and height must be > 0\");\n        } else if (depth != 1 && depth != 2 && depth != 4 && depth != 8 && depth != 16\n                && depth != 24 && depth != 32) {\n            throw new IllegalArgumentException(\"Depth must be one of 1, 2, 4, 8, 16, or 32\");\n        }\n\n        mNativePix = nativeCreatePix(width, height, depth);\n        mRecycled = false;\n    }\n\n    /**\n     * Returns a pointer to the native Pix object. This is used by native code\n     * and is only valid within the same process in which the Pix was created.\n     *\n     * @return a native pointer to the Pix object\n     */\n    public long getNativePix() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mNativePix;\n    }\n\n    /**\n     * Return the raw bytes of the native PIX object. You can reconstruct the\n     * Pix from this data using createFromPix().\n     *\n     * @return a copy of this PIX object's raw data\n     */\n    public byte[] getData() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        byte[] buffer = nativeGetData(mNativePix);\n\n        if (buffer == null) {\n            throw new RuntimeException(\"native getData failed\");\n        }\n\n        return buffer;\n    }\n\n    /**\n     * Returns an array of this image's dimensions. See Pix.INDEX_* for indices.\n     *\n     * @return an array of this image's dimensions or <code>null</code> on\n     *         failure\n     */\n    public int[] getDimensions() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        int[] dimensions = new int[3];\n\n        if (getDimensions(dimensions)) {\n            return dimensions;\n        }\n\n        return null;\n    }\n\n    /**\n     * Fills an array with this image's dimensions. The array must be at least 3\n     * elements long.\n     *\n     * @param dimensions An integer array with at least three elements.\n     * @return <code>true</code> on success\n     */\n    public boolean getDimensions(@Size(min=3) int[] dimensions) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetDimensions(mNativePix, dimensions);\n    }\n\n    /**\n     * Returns a clone of this Pix. This does NOT create a separate copy, just a\n     * new pointer that can be recycled without affecting other clones.\n     *\n     * @return a clone (shallow copy) of the Pix\n     */\n    @Override\n    public Pix clone() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativePix = nativeClone(mNativePix);\n\n        if (nativePix == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Returns a deep copy of this Pix that can be modified without affecting\n     * the original Pix.\n     *\n     * @return a copy of the Pix\n     */\n    public Pix copy() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativePix = nativeCopy(mNativePix);\n\n        if (nativePix == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Inverts this Pix in-place.\n     *\n     * @return <code>true</code> on success\n     */\n    public boolean invert() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeInvert(mNativePix);\n    }\n\n    /**\n     * Releases resources and frees any memory associated with this Pix. You may\n     * not modify or access the pix after calling this method.\n     */\n    public void recycle() {\n        if (!mRecycled) {\n            nativeDestroy(mNativePix);\n\n            mRecycled = true;\n        }\n    }\n\n    /**\n     * Creates a new Pix from raw Pix data obtained from getData().\n     *\n     * @param pixData Raw pix data obtained from getData().\n     * @param width The width of the original Pix.\n     * @param height The height of the original Pix.\n     * @param depth The bit-depth of the original Pix.\n     * @return a new Pix or <code>null</code> on error\n     */\n    public static Pix createFromPix(byte[] pixData, int width, int height, int depth) {\n        long nativePix = nativeCreateFromData(pixData, width, height, depth);\n\n        if (nativePix == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Returns a Rect with the width and height of this Pix.\n     *\n     * @return a Rect with the width and height of this Pix\n     */\n    public Rect getRect() {\n        int w = getWidth();\n        int h = getHeight();\n\n        return new Rect(0, 0, w, h);\n    }\n\n    /**\n     * Returns the width of this Pix.\n     *\n     * @return the width of this Pix\n     */\n    public int getWidth() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetWidth(mNativePix);\n    }\n\n    /**\n     * Returns the height of this Pix.\n     *\n     * @return the height of this Pix\n     */\n    public int getHeight() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetHeight(mNativePix);\n    }\n\n    /**\n     * Returns the depth of this Pix.\n     *\n     * @return the depth of this Pix\n     */\n    public int getDepth() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetDepth(mNativePix);\n    }\n\n    /**\n     * Returns the spp of this Pix.\n     *\n     * @return the spp of this Pix\n     */\n    public int getSpp() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetSpp(mNativePix);\n    }\n\n    /**\n     * Returns the imageFormat of this Pix.\n     *\n     * @return the imageFormat of this Pix\n     */\n    public int getImageFormat() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetInputFormat(mNativePix);\n    }\n\n    public int getRefCount() {\n        return nativeGetRefCount(mNativePix);\n    }\n\n    /**\n     * Returns the {@link android.graphics.Color} at the specified location.\n     *\n     * @param x The x coordinate (0...width-1) of the pixel to return.\n     * @param y The y coordinate (0...height-1) of the pixel to return.\n     * @return The argb {@link android.graphics.Color} at the specified\n     *         coordinate.\n     * @throws IllegalArgumentException If x, y exceeds the image bounds.\n     */\n    public int getPixel(int x, int y) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        if (x < 0 || x >= getWidth()) {\n            throw new IllegalArgumentException(\"Supplied x coordinate exceeds image bounds\");\n        } else if (y < 0 || y >= getHeight()) {\n            throw new IllegalArgumentException(\"Supplied y coordinate exceeds image bounds\");\n        }\n\n        return nativeGetPixel(mNativePix, x, y);\n    }\n\n    /**\n     * Sets the {@link android.graphics.Color} at the specified location.\n     * \n     * @param x The x coordinate (0...width-1) of the pixel to set.\n     * @param y The y coordinate (0...height-1) of the pixel to set.\n     * @param color The argb {@link android.graphics.Color} to set at the\n     *            specified coordinate.\n     * @throws IllegalArgumentException If x, y exceeds the image bounds.\n     */\n    public void setPixel(int x, int y, @ColorInt int color) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        if (x < 0 || x >= getWidth()) {\n            throw new IllegalArgumentException(\"Supplied x coordinate exceeds image bounds\");\n        } else if (y < 0 || y >= getHeight()) {\n            throw new IllegalArgumentException(\"Supplied y coordinate exceeds image bounds\");\n        }\n\n        nativeSetPixel(mNativePix, x, y, color);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native int nativeGetRefCount(long nativePix);\n    private static native long nativeCreatePix(int w, int h, int d);\n    private static native long nativeCreateFromData(byte[] data, int w, int h, int d);\n    private static native byte[] nativeGetData(long nativePix);\n    private static native long nativeClone(long nativePix);\n    private static native long nativeCopy(long nativePix);\n    private static native boolean nativeInvert(long nativePix);\n    private static native void nativeDestroy(long nativePix);\n    private static native boolean nativeGetDimensions(long nativePix, int[] dimensions);\n    private static native int nativeGetWidth(long nativePix);\n    private static native int nativeGetHeight(long nativePix);\n    private static native int nativeGetDepth(long nativePix);\n    private static native int nativeGetPixel(long nativePix, int x, int y);\n    private static native void nativeSetPixel(long nativePix, int x, int y, int color);\n\n    private static native int nativeGetSpp(long nativePix);\n\n    /*! Image Formats */\n    public static final int IFF_UNKNOWN        = 0;\n    public static final int IFF_BMP            = 1;\n    public static final int IFF_JFIF_JPEG      = 2;\n    public static final int IFF_PNG            = 3;\n    public static final int IFF_TIFF           = 4;\n    public static final int IFF_TIFF_PACKBITS  = 5;\n    public static final int IFF_TIFF_RLE       = 6;\n    public static final int IFF_TIFF_G3        = 7;\n    public static final int IFF_TIFF_G4        = 8;\n    public static final int IFF_TIFF_LZW       = 9;\n    public static final int IFF_TIFF_ZIP       = 10;\n    public static final int IFF_PNM            = 11;\n    public static final int IFF_PS             = 12;\n    public static final int IFF_GIF            = 13;\n    public static final int IFF_JP2            = 14;\n    public static final int IFF_WEBP           = 15;\n    public static final int IFF_LPDF           = 16;\n    public static final int IFF_TIFF_JPEG      = 17;\n    public static final int IFF_DEFAULT        = 18;\n    public static final int IFF_SPIX           = 19;\n\n    private static native int nativeGetInputFormat(long nativePix);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Pixa.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Rect;\nimport androidx.annotation.Size;\nimport android.util.Log;\n\nimport java.io.File;\nimport java.util.ArrayList;\nimport java.util.Iterator;\n\n/**\n * Java representation of a native PIXA object. This object contains multiple\n * PIX objects and their associated bounding BOX objects.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Pixa implements Iterable<Pix> {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    private static final String TAG = Pixa.class.getSimpleName();\n\n    /** A pointer to the native PIXA object. This is used internally by native code. */\n    private final long mNativePixa;\n\n    /** The specified width of this Pixa. */\n    final int mWidth;\n\n    /** The specified height of this Pixa. */\n    final int mHeight;\n\n    private boolean mRecycled;\n\n    /**\n     * Creates a new Pixa with the specified minimum capacity. The Pixa will\n     * expand automatically as new Pix are added.\n     *\n     * @param size The minimum capacity of this Pixa.\n     * @return a new Pixa or <code>null</code> on error\n     */\n    public static Pixa createPixa(int size) {\n        return createPixa(size, 0, 0);\n    }\n\n    /**\n     * Creates a new Pixa with the specified minimum capacity. The Pixa will\n     * expand automatically as new Pix are added.\n     * <p>\n     * If non-zero, the specified width and height will be used to specify the\n     * bounds of output images. *\n     *\n     * @param size The minimum capacity of this Pixa.\n     * @param width (Optional) The width of this Pixa, use 0 for default.\n     * @param height (Optional) The height of this Pixa, use 0 for default.\n     * @return a new Pixa or <code>null</code> on error\n     */\n    public static Pixa createPixa(int size, int width, int height) {\n        long nativePixa = nativeCreate(size);\n\n        if (nativePixa == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pixa(nativePixa, width, height);\n    }\n\n    /**\n     * Creates a wrapper for the specified native Pixa pointer.\n     *\n     * @param nativePixa Native pointer to a PIXA object.\n     * @param width The width of the PIXA.\n     * @param height The height of the PIXA.\n     */\n    public Pixa(long nativePixa, int width, int height) {\n        mNativePixa = nativePixa;\n        mWidth = width;\n        mHeight = height;\n        mRecycled = false;\n    }\n\n    /**\n     * Returns a pointer to the native PIXA object. This is used by native code.\n     *\n     * @return a pointer to the native PIXA object\n     */\n    public long getNativePixa() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mNativePixa;\n    }\n\n    /**\n     * Creates a shallow copy of this Pixa. Contained Pix are cloned, and the\n     * resulting Pixa may be recycled separately from the original.\n     *\n     * @return a shallow copy of this Pixa\n     */\n    public Pixa copy() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativePixa = nativeCopy(mNativePixa);\n\n        if (nativePixa == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pixa(nativePixa, mWidth, mHeight);\n    }\n\n    /**\n     * Sorts this Pixa using the specified field and order. See\n     * Constants.L_SORT_BY_* and Constants.L_SORT_INCREASING or\n     * Constants.L_SORT_DECREASING.\n     *\n     * @param field The field to sort by. See Constants.L_SORT_BY_*.\n     * @param order The order in which to sort. Must be either\n     *            Constants.L_SORT_INCREASING or Constants.L_SORT_DECREASING.\n     * @return a sorted copy of this Pixa\n     */\n    public Pixa sort(@Constants.SortBy int field, @Constants.SortOrder int order) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativePixa = nativeSort(mNativePixa, field, order);\n\n        if (nativePixa == 0) {\n            throw new OutOfMemoryError();\n        }\n\n        return new Pixa(nativePixa, mWidth, mHeight);\n    }\n\n    /**\n     * Returns the number of elements in this Pixa.\n     *\n     * @return the number of elements in this Pixa\n     */\n    public int size() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetCount(mNativePixa);\n    }\n\n    /**\n     * Recycles this Pixa and frees natively allocated memory. You may not\n     * access or modify the Pixa after calling this method.\n     * <p>\n     * Any Pix obtained from this Pixa or copies of this Pixa will still be\n     * accessible until they are explicitly recycled or finalized by the garbage\n     * collector.\n     */\n    public synchronized void recycle() {\n        if (!mRecycled) {\n            nativeDestroy(mNativePixa);\n\n            mRecycled = true;\n        }\n    }\n\n    @Override\n    protected void finalize() throws Throwable {\n        try {\n            if (!mRecycled) {\n                Log.w(TAG, \"Pixa was not terminated using recycle()\");\n                recycle();\n            }\n        } finally {\n            super.finalize();\n        }\n    }\n\n    /**\n     * Merges the contents of another Pixa into this one.\n     *\n     * @param otherPixa The Pix to merge.\n     * @return <code>true</code> on success\n     */\n    public boolean join(Pixa otherPixa) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeJoin(mNativePixa, otherPixa.mNativePixa);\n    }\n\n    /**\n     * Adds a Pix to this Pixa.\n     *\n     * @param pix The Pix to add.\n     * @param mode The mode in which to add this Pix, typically\n     *            Constants.L_CLONE.\n     */\n    public void addPix(Pix pix, @Constants.StorageFlag int mode) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeAddPix(mNativePixa, pix.getNativePix(), mode);\n    }\n\n    /**\n     * Adds a Box to this Pixa.\n     *\n     * @param box The Box to add.\n     * @param mode The mode in which to add this Box, typically\n     *            Constants.L_CLONE.\n     */\n    public void addBox(Box box, @Constants.StorageFlag int mode) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeAddBox(mNativePixa, box.getNativeBox(), mode);\n    }\n\n    /**\n     * Adds a Pix and associated Box to this Pixa.\n     *\n     * @param pix The Pix to add.\n     * @param box The Box to add.\n     * @param mode The mode in which to add this Pix and Box, typically\n     *            Constants.L_CLONE.\n     */\n    public void add(Pix pix, Box box, @Constants.StorageFlag int mode) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeAdd(mNativePixa, pix.getNativePix(), box.getNativeBox(), mode);\n    }\n\n    /**\n     * Returns the Box at the specified index, or <code>null</code> on error.\n     *\n     * @param index The index of the Box to return.\n     * @return the Box at the specified index, or <code>null</code> on error\n     */\n    public Box getBox(int index) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativeBox = nativeGetBox(mNativePixa, index);\n\n        if (nativeBox == 0) {\n            return null;\n        }\n\n        return new Box(nativeBox);\n    }\n\n    /**\n     * Returns the Pix at the specified index, or <code>null</code> on error.\n     *\n     * @param index The index of the Pix to return.\n     * @return the Pix at the specified index, or <code>null</code> on error\n     */\n    public Pix getPix(int index) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativePix = nativeGetPix(mNativePixa, index);\n\n        if (nativePix == 0) {\n            return null;\n        }\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Returns the width of this Pixa, or 0 if one was not set when it was\n     * created.\n     *\n     * @return the width of this Pixa, or 0 if one was not set when it was\n     *         created\n     */\n    public int getWidth() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mWidth;\n    }\n\n    /**\n     * Returns the height of this Pixa, or 0 if one was not set when it was\n     * created.\n     *\n     * @return the height of this Pixa, or 0 if one was not set when it was\n     *         created\n     */\n    public int getHeight() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return mHeight;\n    }\n\n    /**\n     * Returns a bounding Rect for this Pixa, which may be (0,0,0,0) if width\n     * and height were not specified on creation.\n     *\n     * @return a bounding Rect for this Pixa\n     */\n    public Rect getRect() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Rect(0, 0, mWidth, mHeight);\n    }\n\n    /**\n     * Returns a geometry array for the Box at the specified index. See\n     * Box.INDEX_* for indices.\n     *\n     * @param index The index of the Box to get the geometry of.\n     * @return a bounding Rect for the Box at the specified index\n     */\n    public int[] getBoxGeometry(int index) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        int[] dimensions = new int[4];\n\n        if (getBoxGeometry(index, dimensions)) {\n            return dimensions;\n        }\n\n        return null;\n    }\n\n    /**\n     * Fills an array with the geometry of the Box at the specified index. See\n     * Box.INDEX_* for indices.\n     *\n     * @param index The index of the Box to get the geometry of.\n     * @param dimensions The array to fill with Box geometry. Must be at least 4\n     *            elements.\n     * @return <code>true</code> on success\n     */\n    public boolean getBoxGeometry(int index, @Size(min=4) int[] dimensions) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetBoxGeometry(mNativePixa, index, dimensions);\n    }\n\n    /**\n     * Returns a bounding Rect for the Box at the specified index.\n     *\n     * @param index The index of the Box to get the bounding Rect of.\n     * @return a bounding Rect for the Box at the specified index\n     */\n    public Rect getBoxRect(int index) {        \n        int[] dimensions = getBoxGeometry(index);\n\n        if (dimensions == null) {\n            return null;\n        }\n\n        int x = dimensions[Box.INDEX_X];\n        int y = dimensions[Box.INDEX_Y];\n        int w = dimensions[Box.INDEX_W];\n        int h = dimensions[Box.INDEX_H];\n\n        return new Rect(x, y, x + w, y + h);\n    }\n\n    /**\n     * Returns an ArrayList of Box bounding Rects.\n     *\n     * @return an ArrayList of Box bounding Rects\n     */\n    public ArrayList<Rect> getBoxRects() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        final int pixaCount = nativeGetCount(mNativePixa);\n        final int[] buffer = new int[4];\n        final ArrayList<Rect> rects = new ArrayList<Rect>(pixaCount);\n\n        for (int i = 0; i < pixaCount; i++) {\n            getBoxGeometry(i, buffer);\n\n            final int x = buffer[Box.INDEX_X];\n            final int y = buffer[Box.INDEX_Y];\n            final Rect bound = new Rect(x, y, x + buffer[Box.INDEX_W], y + buffer[Box.INDEX_H]);\n\n            rects.add(bound);\n        }\n\n        return rects;\n    }\n\n    /**\n     * Replaces the Pix and Box at the specified index with the specified Pix\n     * and Box, both of which should not be recycled after calling this method.\n     *\n     * @param index The index of the Pix to replace.\n     * @param pix The Pix to replace the existing Pix; it becomes an alias of the one stored in Pixa.\n     * @param box The Box to replace the existing Box; it becomes an alias of the one stored in Pixa.\n     */\n    public void replacePix(int index, Pix pix, Box box) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeReplacePix(mNativePixa, index, pix.getNativePix(), \n                box.getNativeBox());\n    }\n\n    /**\n     * Merges the Pix at the specified indices and removes the Pix at the second\n     * index.\n     *\n     * @param indexA The index of the first Pix.\n     * @param indexB The index of the second Pix, which will be removed after\n     *            merging.\n     */\n    public void mergeAndReplacePix(int indexA, int indexB) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeMergeAndReplacePix(mNativePixa, indexA, indexB);\n    }\n\n    /**\n     * Writes the components of this Pix to a bitmap-formatted file using a\n     * random color map.\n     *\n     * @param file The file to write to.\n     * @return <code>true</code> on success\n     */\n    public boolean writeToFileRandomCmap(File file) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeWriteToFileRandomCmap(mNativePixa, file.getAbsolutePath(), mWidth, mHeight);\n    }\n\n    public Iterator<Pix> iterator() {\n        return new PixIterator();\n    }\n\n    private class PixIterator implements Iterator<Pix> {\n        private int mIndex;\n\n        private PixIterator() {\n            mIndex = 0;\n        }\n\n        public boolean hasNext() {\n            final int size = size();\n            return (size > 0 && mIndex < size);\n        }\n\n        public Pix next() {\n            return getPix(mIndex++);\n        }\n\n        public void remove() {\n            throw new UnsupportedOperationException();\n        }\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeCreate(int size);\n\n    private static native long nativeCopy(long nativePixa);\n\n    private static native long nativeSort(long nativePixa, int field, int order);\n\n    private static native boolean nativeJoin(long nativePixa, long otherPixa);\n\n    private static native int nativeGetCount(long nativePixa);\n\n    private static native void nativeDestroy(long nativePixa);\n\n    private static native void nativeAddPix(long nativePixa, long nativePix, int mode);\n\n    private static native void nativeAddBox(long nativePixa, long nativeBox, int mode);\n\n    private static native void nativeAdd(long nativePixa, long nativePix, long nativeBox, int mode);\n\n    private static native boolean nativeWriteToFileRandomCmap(\n            long nativePixa, String fileName, int width, int height);\n\n    private static native void nativeReplacePix(\n            long nativePixa, int index, long nativePix, long nativeBox);\n\n    private static native void nativeMergeAndReplacePix(long nativePixa, int indexA, int indexB);\n\n    private static native long nativeGetBox(long nativePix, int index);\n\n    private static native long nativeGetPix(long nativePix, int index);\n\n    private static native boolean nativeGetBoxGeometry(long nativePixa, int index, int[] dimensions);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/ReadFile.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Bitmap;\nimport android.graphics.BitmapFactory;\nimport android.util.Log;\n\nimport java.io.File;\n\n/**\n * Image input and output methods.\n *\n * @author alanv@google.com (Alan Viverette)\n */\npublic class ReadFile {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    private static final String LOG_TAG = ReadFile.class.getSimpleName();\n\n    /**\n     * Creates a 32bpp Pix object from encoded data. Supported formats are BMP,\n     * JPEG, and PNG.\n     *\n     * @param encodedData BMP, JPEG, or PNG encoded byte data.\n     * @return a 32bpp Pix object\n     */\n    public static Pix readMem(byte[] encodedData) {\n        if (encodedData == null) {\n            Log.e(LOG_TAG, \"Image data byte array must be non-null\");\n            return null;\n        }\n\n        final BitmapFactory.Options opts = new BitmapFactory.Options();\n        opts.inPreferredConfig = Bitmap.Config.ARGB_8888;\n\n        final Bitmap bmp = BitmapFactory.decodeByteArray(encodedData, 0, encodedData.length,\n                opts);\n        final Pix pix = readBitmap(bmp);\n\n        bmp.recycle();\n\n        return pix;\n    }\n\n    /**\n     * Creates an 8bpp Pix object from raw 8bpp grayscale pixels.\n     *\n     * @param pixelData 8bpp grayscale pixel data.\n     * @param width The width of the input image.\n     * @param height The height of the input image.\n     * @return an 8bpp Pix object\n     */\n    public static Pix readBytes8(byte[] pixelData, int width, int height) {\n        if (pixelData == null)\n            throw new IllegalArgumentException(\"Byte array must be non-null\");\n        if (width <= 0)\n            throw new IllegalArgumentException(\"Image width must be greater than 0\");\n        if (height <= 0)\n            throw new IllegalArgumentException(\"Image height must be greater than 0\");\n        if (pixelData.length < width * height)\n            throw new IllegalArgumentException(\"Array length does not match dimensions\");\n\n        long nativePix = nativeReadBytes8(pixelData, width, height);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to read pix from memory\");\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Replaces the bytes in an 8bpp Pix object with raw grayscale 8bpp pixels.\n     * Width and height be identical to the input Pix.\n     *\n     * @param pixs The Pix whose bytes will be replaced.\n     * @param pixelData 8bpp grayscale pixel data.\n     * @param width The width of the input image.\n     * @param height The height of the input image.\n     * @return an 8bpp Pix object\n     */\n    public static boolean replaceBytes8(Pix pixs, byte[] pixelData, int width, int height) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (pixelData == null)\n            throw new IllegalArgumentException(\"Byte array must be non-null\");\n        if (width <= 0)\n            throw new IllegalArgumentException(\"Image width must be greater than 0\");\n        if (height <= 0)\n            throw new IllegalArgumentException(\"Image height must be greater than 0\");\n        if (pixelData.length < width * height)\n            throw new IllegalArgumentException(\"Array length does not match dimensions\");\n        if (pixs.getWidth() != width)\n            throw new IllegalArgumentException(\"Source pix width does not match image width\");\n        if (pixs.getHeight() != height)\n            throw new IllegalArgumentException(\"Source pix height does not match image height\");\n\n        return nativeReplaceBytes8(pixs.getNativePix(), pixelData, width, \n                height);\n    }\n\n    /**\n     * Creates a Pix object from encoded file data. Supported formats are BMP,\n     * JPEG, and PNG.\n     *\n     * @param file The BMP, JPEG, or PNG-encoded file to read in as a Pix.\n     * @return a Pix object\n     */\n    public static Pix readFile(File file) {\n        if (file == null) {\n            Log.e(LOG_TAG, \"File must be non-null\");\n            return null;\n        }\n        if (!file.exists()) {\n            Log.e(LOG_TAG, \"File does not exist\");\n            return null;\n        }\n        if (!file.canRead()) {\n            Log.e(LOG_TAG, \"Cannot read file\");\n            return null;\n        }\n\n        final long nativePix = nativeReadFile(file.getAbsolutePath());\n\n        if (nativePix != 0) {\n            return new Pix(nativePix);\n        }\n\n        final BitmapFactory.Options opts = new BitmapFactory.Options();\n        opts.inPreferredConfig = Bitmap.Config.ARGB_8888;\n\n        final Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath(), opts);\n        if (bmp == null) {\n            Log.e(LOG_TAG, \"Cannot decode bitmap\");\n            return null;\n        }\n        final Pix pix = readBitmap(bmp);\n\n        bmp.recycle();\n\n        return pix;\n    }\n\n    /**\n     * Creates a Pix object from Bitmap data. Currently supports only\n     * ARGB_8888-formatted bitmaps.\n     *\n     * @param bmp The Bitmap object to convert to a Pix.\n     * @return a Pix object\n     */\n    public static Pix readBitmap(Bitmap bmp) {\n        if (bmp == null) {\n            Log.e(LOG_TAG, \"Bitmap must be non-null\");\n            return null;\n        }\n        if (bmp.getConfig() != Bitmap.Config.ARGB_8888) {\n            Log.e(LOG_TAG, \"Bitmap config must be ARGB_8888\");\n            return null;\n        }\n\n        long nativePix = nativeReadBitmap(bmp);\n\n        if (nativePix == 0) {\n            Log.e(LOG_TAG, \"Failed to read pix from bitmap\");\n            return null;\n        }\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeReadMem(byte[] data, int size);\n\n    private static native long nativeReadBytes8(byte[] data, int w, int h);\n\n    private static native boolean nativeReplaceBytes8(long nativePix, byte[] data, int w, int h);\n\n    private static native long nativeReadFile(String filename);\n\n    private static native long nativeReadBitmap(Bitmap bitmap);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Rotate.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport androidx.annotation.IntRange;\n\n/**\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Rotate {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Rotation default\n\n    /** Default rotation quality is high. */\n    public static final boolean ROTATE_QUALITY = true;\n\n    /**\n     * Performs rotation using the default parameters.\n     *\n     * @param pixs The source pix.\n     * @param degrees The number of degrees to rotate; clockwise is positive.\n     * @return the rotated source image\n     */\n    public static Pix rotate(Pix pixs, float degrees) {\n        return rotate(pixs, degrees, false);\n    }\n\n    /**\n     * Performs rotation with resizing using the default parameters.\n     *\n     * @param pixs The source pix.\n     * @param degrees The number of degrees to rotate; clockwise is positive.\n     * @param quality Whether to use high-quality rotation.\n     * @return the rotated source image\n     */\n    public static Pix rotate(Pix pixs, float degrees, boolean quality) {\n        return rotate(pixs, degrees, quality, true);\n    }\n\n    /**\n     * Performs basic image rotation about the center.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>Rotation is about the center of the image.\n     * <li>For very small rotations, just return a clone.\n     * <li>Rotation brings either white or black pixels in from outside the\n     * image.\n     * <li>Above 20 degrees, if rotation by shear is requested, we rotate by\n     * sampling.\n     * <li>Colormaps are removed for rotation by area map and shear.\n     * <li>The dest can be expanded so that no image pixels are lost. To invoke\n     * expansion, input the original width and height. For repeated rotation,\n     * use of the original width and height allows the expansion to stop at the\n     * maximum required size, which is a square with side = sqrt(w*w + h*h).\n     * </ol>\n     *\n     * @param pixs The source pix.\n     * @param degrees The number of degrees to rotate; clockwise is positive.\n     * @param quality Whether to use high-quality rotation.\n     * @param resize Whether to expand the output so that no pixels are lost.\n     *         <strong>Note:</strong> 1bpp images are always resized when\n     *         quality is {@code true}.\n     * @return the rotated source image\n     */\n    public static Pix rotate(Pix pixs, float degrees, boolean quality, boolean resize) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        long nativePix = nativeRotate(pixs.getNativePix(), degrees, quality, \n                resize);\n\n        if (nativePix == 0)\n            return null;\n\n        return new Pix(nativePix);\n    }\n\n    /**\n     * Performs top-level rotation by multiples of 90 degrees.\n     *\n     * @param pixs The source pix (all depths)\n     * @param quads 0-3; number of 90 degree cw rotations\n     * @return the rotated source image\n     */\n    public static Pix rotateOrth(Pix pixs, @IntRange(from=0, to=3) int quads) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (quads < 0 || quads > 3)\n            throw new IllegalArgumentException(\"quads not in {0,1,2,3}\");\n\n        long nativePix = nativeRotateOrth(pixs.getNativePix(), quads);\n\n        if (nativePix == 0)\n            return null;\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeRotateOrth(long nativePix, int quads);\n\n    private static native long nativeRotate(long nativePix, float degrees, boolean quality,\n            boolean resize);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Scale.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\n/**\n * Image scaling methods.\n * \n * @author alanv@google.com (Alan Viverette)\n */\npublic class Scale {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    public enum ScaleType {\n        /* Scale in X and Y independently, so that src matches dst exactly. */\n        FILL,\n\n        /*\n         * Compute a scale that will maintain the original src aspect ratio, but\n         * will also ensure that src fits entirely inside dst. May shrink or\n         * expand src to fit dst.\n         */\n        FIT,\n\n        /*\n         * Compute a scale that will maintain the original src aspect ratio, but\n         * will also ensure that src fits entirely inside dst. May shrink src to\n         * fit dst, but will not expand it.\n         */\n        FIT_SHRINK,\n    }\n\n    /**\n     * Scales the Pix to a specified width and height using a specified scaling\n     * type (fill, stretch, etc.). Returns a scaled image or a clone of the Pix\n     * if no scaling is required.\n     *\n     * @param pixs Source pix image\n     * @param width The desired width to scale to\n     * @param height The desired height to scale to\n     * @param type The desired scaling type\n     * @return a scaled image or a clone of the Pix if no scaling is required\n     */\n    public static Pix scaleToSize(Pix pixs, int width, int height, ScaleType type) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        int pixWidth = pixs.getWidth();\n        int pixHeight = pixs.getHeight();\n\n        float scaleX = width / (float) pixWidth;\n        float scaleY = height / (float) pixHeight;\n\n        switch (type) {\n            case FILL:\n                // Retains default scaleX and scaleY values\n                break;\n            case FIT:\n                scaleX = Math.min(scaleX, scaleY);\n                //noinspection SuspiciousNameCombination\n                scaleY = scaleX;\n                break;\n            case FIT_SHRINK:\n                scaleX = Math.min(1.0f, Math.min(scaleX, scaleY));\n                //noinspection SuspiciousNameCombination\n                scaleY = scaleX;\n                break;\n        }\n\n        return scale(pixs, scaleX, scaleY);\n    }\n\n    /**\n     * Scales the Pix to specified scale. If no scaling is required, returns a\n     * clone of the source Pix.\n     *\n     * @param pixs the source Pix\n     * @param scale dimension scaling factor\n     * @return a Pix scaled according to the supplied factors\n     */\n    public static Pix scale(Pix pixs, float scale) {\n        return scale(pixs, scale, scale);\n    }\n\n    /**\n     * Scales the Pix to the specified scale without sharpening.\n     *\n     * @param pixs the source Pix (1, 2, 4, 8, 16 and 32 bpp)\n     * @param scale scaling factor for both X and Y\n     * @return a Pix scaled while maintaining its aspect ratio\n     */\n    public static Pix scaleWithoutSharpening(Pix pixs, float scale) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (scale <= 0.0f)\n            throw new IllegalArgumentException(\"Scaling factor must be positive\");\n\n        return new Pix(nativeScaleGeneral(pixs.getNativePix(), scale, scale,\n                0f, 0));\n    }\n\n    /**\n     * Scales the Pix to specified x and y scale. If no scaling is required,\n     * returns a clone of the source Pix.\n     *\n     * @param pixs the source Pix\n     * @param scaleX x-dimension (width) scaling factor\n     * @param scaleY y-dimension (height) scaling factor\n     * @return a Pix scaled according to the supplied factors\n     */\n    public static Pix scale(Pix pixs, float scaleX, float scaleY) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (scaleX <= 0.0f)\n            throw new IllegalArgumentException(\"X scaling factor must be positive\");\n        if (scaleY <= 0.0f)\n            throw new IllegalArgumentException(\"Y scaling factor must be positive\");\n\n        long nativePix = nativeScale(pixs.getNativePix(), scaleX, scaleY);\n\n        if (nativePix == 0)\n            throw new RuntimeException(\"Failed to natively scale pix\");\n\n        return new Pix(nativePix);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native long nativeScale(long nativePix, float scaleX, float scaleY);\n    private static native long nativeScaleGeneral(long nativePix, float scaleX, float scaleY, float sharpfract, int sharpwidth);\n\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/Skew.java",
    "content": "/*\n * Copyright (C) 2010 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\n/**\n * Image rotation and skew detection methods.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class Skew {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    // Text alignment defaults\n\n    /** Default range for sweep, will detect rotation of + or - 30 degrees. */\n    public final static float SWEEP_RANGE = 30.0f;\n\n    /** Default sweep delta, reasonably accurate within 0.05 degrees. */\n    public final static float SWEEP_DELTA = 5.0f;\n\n    /** Default sweep reduction, one-eighth the size of the original image. */\n    public final static int SWEEP_REDUCTION = 8;\n\n    /** Default sweep reduction, one-fourth the size of the original image. */\n    public final static int SEARCH_REDUCTION = 4;\n\n    /** Default search minimum delta, reasonably accurate within 0.05 degrees. */\n    public final static float SEARCH_MIN_DELTA = 0.01f;\n\n    /** \n     * Finds and returns the skew angle using default parameters.\n     * \n     * @param pixs Input pix (1 bpp).\n     * @return the detected skew angle, or 0.0 on failure\n     */\n    public static float findSkew(Pix pixs) {\n        return findSkew(pixs, SWEEP_RANGE, SWEEP_DELTA, SWEEP_REDUCTION, SEARCH_REDUCTION,\n                SEARCH_MIN_DELTA);\n    }\n\n    /**\n     * Finds and returns the skew angle, doing first a sweep through a set of\n     * equal angles, and then doing a binary search until convergence.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>In computing the differential line sum variance score, we sum the\n     * result over scanlines, but we always skip:\n     * <ul>\n     * <li>at least one scanline\n     * <li>not more than 10% of the image height\n     * <li>not more than 5% of the image width\n     * </ul>\n     * </ol>\n     *\n     * @param pixs Input pix (1 bpp).\n     * @param sweepRange Half the full search range, assumed about 0; in\n     *            degrees.\n     * @param sweepDelta Angle increment of sweep; in degrees.\n     * @param sweepReduction Sweep reduction factor = 1, 2, 4 or 8.\n     * @param searchReduction Binary search reduction factor = 1, 2, 4 or 8; and\n     *            must not exceed sweepReduction.\n     * @param searchMinDelta Minimum binary search increment angle; in degrees.\n     * @return the detected skew angle, or 0.0 on failure\n     */\n    public static float findSkew(Pix pixs, float sweepRange, float sweepDelta, int sweepReduction,\n            int searchReduction, float searchMinDelta) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        return nativeFindSkew(pixs.getNativePix(), sweepRange, sweepDelta,\n                sweepReduction, searchReduction, searchMinDelta);\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native float nativeFindSkew(long nativePix, float sweepRange, float sweepDelta,\n            int sweepReduction, int searchReduction, float searchMinDelta);\n\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/leptonica/android/WriteFile.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android;\n\nimport android.graphics.Bitmap;\n\nimport java.io.File;\n\n/**\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class WriteFile {\n    static {\n        System.loadLibrary(\"lept\");\n    }\n\n    /**\n     * Write an 8bpp Pix to a flat byte array.\n     *\n     * @param pixs The 8bpp source image.\n     * @return a byte array where each byte represents a single 8-bit pixel\n     */\n    public static byte[] writeBytes8(Pix pixs) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        int size = pixs.getWidth() * pixs.getHeight();\n\n        byte[] data = new byte[size];\n\n        if (pixs.getDepth() != 8) {\n            Pix pix8 = Convert.convertTo8(pixs);\n            writeBytes8(pix8, data);\n            pix8.recycle();\n        } else {\n            writeBytes8(pixs, data);\n        }\n\n        return data;\n    }\n\n    /**\n     * Write an 8bpp Pix to a flat byte array.\n     *\n     * @param pixs The 8bpp source image.\n     * @param data A byte array large enough to hold the pixels of pixs.\n     * @return the number of bytes written to data\n     */\n    @SuppressWarnings(\"UnusedReturnValue\")\n    public static int writeBytes8(Pix pixs, byte[] data) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        int size = pixs.getWidth() * pixs.getHeight();\n\n        if (data.length < size)\n            throw new IllegalArgumentException(\"Data array must be large enough to hold image bytes\");\n\n        return nativeWriteBytes8(pixs.getNativePix(), data);\n    }\n\n    /**\n     * Writes a Pix to file using the file extension as the output format;\n     * supported formats are .bmp, .jpg, and .png.\n     * <p>\n     * Notes:\n     * <ol>\n     * <li>This determines the output format from the filename extension.\n     * </ol>\n     *\n     * @param pixs Source image.\n     * @param file The file to write.\n     * @return <code>true</code> on success\n     */\n    public static boolean writeImpliedFormat(Pix pixs, File file) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n        if (file == null)\n            throw new IllegalArgumentException(\"File must be non-null\");\n\n        return nativeWriteImpliedFormat(pixs.getNativePix(),\n                file.getAbsolutePath());\n    }\n\n    /**\n     * Writes a Pix to an Android Bitmap object. The output Bitmap will always\n     * be in ARGB_8888 format, but the input Pixs may be any bit-depth.\n     *\n     * Warning: This method alters the original source image! Using the source\n     * image after calling this method is not recommended.\n     *\n     * @param pixs The source image.\n     * @return a Bitmap containing a copy of the source image, or <code>null\n     *         </code> on failure\n     */\n    public static Bitmap writeBitmap(Pix pixs) {\n        if (pixs == null)\n            throw new IllegalArgumentException(\"Source pix must be non-null\");\n\n        final int[] dimensions = pixs.getDimensions();\n        if (dimensions != null) {\n            final int width = dimensions[Pix.INDEX_W];\n            final int height = dimensions[Pix.INDEX_H];\n\n            final Bitmap.Config config = Bitmap.Config.ARGB_8888;\n            final Bitmap bitmap = Bitmap.createBitmap(width, height, config);\n\n            if (nativeWriteBitmap(pixs.getNativePix(), bitmap)) {\n                return bitmap;\n            }\n\n            bitmap.recycle();\n        }\n        return null;\n    }\n\n    // ***************\n    // * NATIVE CODE *\n    // ***************\n\n    private static native int nativeWriteBytes8(long nativePix, byte[] data);\n\n    private static native boolean nativeWriteImpliedFormat(long nativePix, String fileName);\n\n    private static native boolean nativeWriteBitmap(long nativePix, Bitmap bitmap);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/tesseract/android/PageIterator.java",
    "content": "/*\n * Copyright (C) 2012 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.tesseract.android;\n\nimport android.graphics.Rect;\n\nimport com.googlecode.tesseract.android.TessBaseAPI.PageIteratorLevel;\n\npublic class PageIterator {\n    static {\n        System.loadLibrary(\"lept\");\n        System.loadLibrary(\"tess\");\n    }\n\n    /** Pointer to native page iterator. */\n    private final long mNativePageIterator;\n\n    /* package */PageIterator(long nativePageIterator) {\n        mNativePageIterator = nativePageIterator;\n    }\n\n    /**\n     * Resets the iterator to point to the start of the page.\n     */\n    public void begin() {\n        nativeBegin(mNativePageIterator);\n    }\n\n    /**\n     * Moves to the start of the next object at the given level in the page\n     * hierarchy, and returns false if the end of the page was reached.\n     * <p>\n     * NOTE that {@link PageIteratorLevel#RIL_SYMBOL} will skip non-text blocks,\n     * but all other {@link PageIteratorLevel} level values will visit each\n     * non-text block once. Think of non text blocks as containing a single\n     * para, with a single line, with a single imaginary word.\n     * <p>\n     * Calls to this method with different levels may be freely intermixed.\n     * <p>\n     * This function iterates words in right-to-left scripts correctly, if the\n     * appropriate language has been loaded into Tesseract.\n     *\n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return {@code false} if the end of the page was reached, {@code true}\n     *         otherwise.\n     */\n    public boolean next(@PageIteratorLevel.Level int level) {\n        return nativeNext(mNativePageIterator, level);\n    }\n\n    /**\n     * Get bounding box: x, y, w, h\n     * <p>\n     * ============= Accessing data ==============.\n     * <p>\n     * Coordinate system:\n     * <ul>\n     * <li> Integer coordinates are at the cracks between the pixels.\n     * <li> The top-left corner of the top-left pixel in the image is at (0,0).\n     * <li> The bottom-right corner of the bottom-right pixel in the image is at\n     * (width, height).\n     * <li> Every bounding box goes from the top-left of the top-left contained\n     * pixel to the bottom-right of the bottom-right contained pixel, so\n     * the bounding box of the single top-left pixel in the image is:\n     * (0,0)-&gt;(1,1).\n     * <li> If an image rectangle has been set in the API, then returned coordinates\n     * relate to the original (full) image, rather than the rectangle.\n     * </ul><p>\n     * Returns the bounding rectangle of the current object at the given level.\n     * See comment on coordinate system above.\n     * <p>\n     * The returned bounding box may clip foreground pixels from a grey image.\n     * \n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return the bounding rectangle of the current object at the given level\n     */\n    public int[] getBoundingBox(@PageIteratorLevel.Level int level) {\n    \treturn nativeBoundingBox(mNativePageIterator, level);\n    }\n    \n    /**\n     * Get a bounding box as an Android Rect.\n     * \n     * @see #getBoundingBox(int)\n     * \n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return the bounding rectangle of the current object at the given level\n     */\n    public Rect getBoundingRect(@PageIteratorLevel.Level int level) {\n        int[] box = getBoundingBox(level);\n        return new Rect(box[0], box[1], box[2], box[3]);\n    }\n    \n    private static native void nativeBegin(long nativeIterator);\n    private static native boolean nativeNext(long nativeIterator, int level);\n    private static native int[] nativeBoundingBox(long nativeIterator, int level);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/tesseract/android/ResultIterator.java",
    "content": "/*\n * Copyright (C) 2012 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.tesseract.android;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\nimport android.util.Log;\nimport android.util.Pair;\n\nimport com.googlecode.tesseract.android.TessBaseAPI.PageIteratorLevel;\n\n/**\n * Java interface for the ResultIterator. Does not implement all available JNI\n * methods, but does implement enough to be useful. Comments are adapted from\n * original Tesseract source.\n *\n * @author alanv@google.com (Alan Viverette)\n */\npublic class ResultIterator extends PageIterator {\n    static {\n        System.loadLibrary(\"lept\");\n        System.loadLibrary(\"tess\");\n    }\n\n    /** Pointer to native result iterator. */\n    private final long mNativeResultIterator;\n\n    /* package */ResultIterator(long nativeResultIterator) {\n        super(nativeResultIterator);\n\n        mNativeResultIterator = nativeResultIterator;\n    }\n\n    /**\n     * Returns the text string for the current object at the given level.\n     *\n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return the text string for the current object at the given level.\n     */\n    public String getUTF8Text(@PageIteratorLevel.Level int level) {\n        return nativeGetUTF8Text(mNativeResultIterator, level);\n    }\n\n    /**\n     * Returns the mean confidence of the current object at the given level. The\n     * number should be interpreted as a percent probability (0-100).\n     *\n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return the mean confidence of the current object at the given level.\n     */\n    public float confidence(@PageIteratorLevel.Level int level) {\n        return nativeConfidence(mNativeResultIterator, level);\n    }\n\n    /**\n     * Returns true if the iterator is at the start of an object at the given\n     * level. Possible uses include determining if a call to Next(RIL_WORD)\n     * moved to the start of a RIL_PARA.\n     *\n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @return {@code true} if iterator points to the start of an object at the given level.\n     */\n    public boolean isAtBeginningOf(@PageIteratorLevel.Level int level) {\n        return nativeIsAtBeginningOf(mNativeResultIterator, level);\n    }\n\n    /**\n     * Returns whether the iterator is positioned at the last element in a\n     * given level. (e.g. the last word in a line, the last line in a block)\n     *\n     * @param level the page iterator level. See {@link PageIteratorLevel}.\n     * @param element the page iterator level. See {@link PageIteratorLevel}.\n     * @return {@code true} if iterator points to the last element in a given level.\n     */\n    public boolean isAtFinalElement(@PageIteratorLevel.Level int level,\n                                    @PageIteratorLevel.Level int element) {\n        return nativeIsAtFinalElement(mNativeResultIterator, level, element);\n    }\n\n    /**\n     * Returns all possible matching text strings and their confidence level \n     * for the current object.\n     * <p>\n     * The default matching text is blank (\"\"). \n     * The default confidence level is zero (0.0) \n     *\n     * @return A list of pairs with the UTF symbol and the confidence\n     */\n    public List<Pair<String, Double>> getSymbolChoicesAndConfidence() {\n        // Get the native choices\n        String[] nativeChoices = nativeGetSymbolChoices(mNativeResultIterator);\n\n        // Create the output list\n        ArrayList<Pair<String, Double>> pairedResults = new ArrayList<Pair<String, Double>>();\n\n        for (String nativeChoice : nativeChoices) {\n            // The string and the confidence level are separated by a '|'\n            int separatorPosition = nativeChoice.lastIndexOf('|');\n\n            // Create a pair with the choices\n            String utfString;\n            Double confidenceLevel = (double) 0;\n            if (separatorPosition > 0) {\n\n                // If the string contains a '|' separate the UTF string and the confidence level\n                utfString = nativeChoice.substring(0, separatorPosition);\n                try {\n                    confidenceLevel = Double.parseDouble(nativeChoice.substring(separatorPosition + 1));\n                } catch (NumberFormatException e) {\n                    Log.e(\"ResultIterator\",\"Invalid confidence level for \" + nativeChoice);\n                }\n            } else {\n                // If the string contains no '|' then save the full native result as the utfString\n                utfString = nativeChoice;\n            }\n\n            // Add the UTF string to the results\n            pairedResults.add(new Pair<String, Double> (utfString, confidenceLevel));\n        }\n\n        return pairedResults;\n    }\n\n    /**\n     * Deletes the iterator after use\n     */\n    public void delete() {\n        nativeDelete(mNativeResultIterator);\n    }\n    \n    private static native String[] nativeGetSymbolChoices(long nativeResultIterator);\n\n    private static native String nativeGetUTF8Text(long nativeResultIterator, int level);\n    private static native float nativeConfidence(long nativeResultIterator, int level);\n    private static native boolean nativeIsAtBeginningOf(long nativeResultIterator, int level);\n    private static native boolean nativeIsAtFinalElement(long nativeResultIterator, int level, int element);\n    private static native void nativeDelete(long nativeResultIterator);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/tesseract/android/TessBaseAPI.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * Copyright (C) 2011 Robert Theis\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.tesseract.android;\n\nimport android.graphics.Bitmap;\nimport android.graphics.Rect;\nimport androidx.annotation.IntDef;\nimport androidx.annotation.WorkerThread;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.Pixa;\nimport com.googlecode.leptonica.android.ReadFile;\n\nimport java.io.File;\nimport java.lang.annotation.Retention;\n\nimport static java.lang.annotation.RetentionPolicy.SOURCE;\n\n/**\n * Java interface for the Tesseract OCR engine. Does not implement all available\n * JNI methods, but does implement enough to be useful. Comments are adapted\n * from original Tesseract source.\n * \n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings({\"unused\", \"WeakerAccess\"})\npublic class TessBaseAPI {\n    /**\n     * Used by the native implementation of the class.\n     */\n    private long mNativeData;\n\n    static {\n        System.loadLibrary(\"lept\");\n        System.loadLibrary(\"tess\");\n\n        nativeClassInit();\n    }\n\n    /** Page segmentation mode. */\n    public static final class PageSegMode {\n        @Retention(SOURCE)\n        @IntDef({PSM_OSD_ONLY, PSM_AUTO_OSD, PSM_AUTO_ONLY, PSM_AUTO, PSM_SINGLE_COLUMN,\n                PSM_SINGLE_BLOCK_VERT_TEXT, PSM_SINGLE_BLOCK, PSM_SINGLE_LINE, PSM_SINGLE_WORD,\n        PSM_CIRCLE_WORD, PSM_SINGLE_CHAR, PSM_SPARSE_TEXT, PSM_SPARSE_TEXT_OSD, PSM_RAW_LINE})\n        public @interface Mode {}\n\n        /** Orientation and script detection only. */\n        public static final int PSM_OSD_ONLY = 0;\n\n        /** Automatic page segmentation with orientation and script detection. (OSD) */\n        public static final int PSM_AUTO_OSD = 1;\n\n        /** Fully automatic page segmentation, but no OSD, or OCR. */\n        public static final int PSM_AUTO_ONLY = 2;\n\n        /** Fully automatic page segmentation, but no OSD. */\n        public static final int PSM_AUTO = 3;\n\n        /** Assume a single column of text of variable sizes. */\n        public static final int PSM_SINGLE_COLUMN = 4;\n\n        /** Assume a single uniform block of vertically aligned text. */\n        public static final int PSM_SINGLE_BLOCK_VERT_TEXT = 5;\n\n        /** Assume a single uniform block of text. (Default.) */\n        public static final int PSM_SINGLE_BLOCK = 6;\n\n        /** Treat the image as a single text line. */\n        public static final int PSM_SINGLE_LINE = 7;\n\n        /** Treat the image as a single word. */\n        public static final int PSM_SINGLE_WORD = 8;\n\n        /** Treat the image as a single word in a circle. */\n        public static final int PSM_CIRCLE_WORD = 9;\n\n        /** Treat the image as a single character. */\n        public static final int PSM_SINGLE_CHAR = 10;\n\n        /** Find as much text as possible in no particular order. */\n        public static final int PSM_SPARSE_TEXT = 11;\n\n        /** Sparse text with orientation and script detection. */\n        public static final int PSM_SPARSE_TEXT_OSD = 12;\n\n        /** Treat the image as a single text line, bypassing hacks that are Tesseract-specific. */\n        public static final int PSM_RAW_LINE = 13;\n    }\n\n    /** Whitelist of characters to recognize. */\n    public static final String VAR_CHAR_WHITELIST = \"tessedit_char_whitelist\";\n\n    /** Blacklist of characters to not recognize. */\n    public static final String VAR_CHAR_BLACKLIST = \"tessedit_char_blacklist\";\n\n    /** Save blob choices allowing us to get alternative results. */\n    public static final String VAR_SAVE_BLOB_CHOICES = \"save_blob_choices\";\n\n    /** String value used to assign a boolean variable to true. */\n    public static final String VAR_TRUE = \"T\";\n\n    /** String value used to assign a boolean variable to false. */\n    public static final String VAR_FALSE = \"F\";\n\n    @Retention(SOURCE)\n    @IntDef({OEM_TESSERACT_ONLY, OEM_CUBE_ONLY, OEM_TESSERACT_CUBE_COMBINED, OEM_DEFAULT})\n    public @interface OcrEngineMode {}\n\n    /** Run Tesseract only - fastest */\n    public static final int OEM_TESSERACT_ONLY = 0;\n\n    /** Run Cube only - better accuracy, but slower */\n    @Deprecated\n    public static final int OEM_CUBE_ONLY = 1;\n\n    /** Run both and combine results - best accuracy */\n    @Deprecated\n    public static final int OEM_TESSERACT_CUBE_COMBINED = 2;\n\n    /** Default OCR engine mode. */\n    public static final int OEM_DEFAULT = 3;\n\n    /**\n     * Elements of the page hierarchy, used in {@link ResultIterator} to provide\n     * functions that operate on each level without having to have 5x as many\n     * functions.\n     * <p>\n     * NOTE: At present {@link #RIL_PARA} and {@link #RIL_BLOCK} are equivalent\n     * as there is no paragraph internally yet.\n     */\n    public static final class PageIteratorLevel {\n        @Retention(SOURCE)\n        @IntDef({RIL_BLOCK, RIL_PARA, RIL_TEXTLINE, RIL_WORD, RIL_SYMBOL})\n        public @interface Level {}\n\n        /** Block of text/image/separator line. */\n        public static final int RIL_BLOCK = 0;\n\n        /** Paragraph within a block. */\n        public static final int RIL_PARA = 1;\n\n        /** Line within a paragraph. */\n        public static final int RIL_TEXTLINE = 2;\n\n        /** Word within a text line. */\n        public static final int RIL_WORD = 3;\n\n        /** Symbol/character within a word. */\n        public static final int RIL_SYMBOL = 4;\n    }\n\n    private ProgressNotifier progressNotifier;\n\n    private boolean mRecycled;\n\n    /**\n     * Interface that may be implemented by calling object in order to receive \n     * progress callbacks during OCR.\n     *\n     * Progress callbacks are available when {@link #getHOCRText(int)} is used.\n     */\n    public interface ProgressNotifier {\n        void onProgressValues(ProgressValues progressValues);\n    }\n\n    /**\n     * Represents values indicating recognition progress and status.\n     */\n    public class ProgressValues {\n        private final int percent;\n        private final Rect wordRect;\n        private final Rect textRect;\n\n        public ProgressValues(int percent, Rect wordRect, Rect textRect) {\n            this.percent = percent;\n            this.wordRect = wordRect;\n            this.textRect = textRect;\n        }\n\n        /**\n         * Return word recognition progress.\n         * \n         * @return a value between 0 and 100\n         */\n        public int getPercent() {\n            return percent;\n        }\n\n        /**\n         * Return the bounds of the word currently being recognized.\n         * \n         * The returned bounding box is in the Android coordinate system,\n         * which has the origin in the top left.\n         * \n         * @return an {@link android.graphics.Rect} bounding box\n         */\n        public Rect getCurrentWordRect() {\n            return wordRect;\n        }\n\n        /**\n         * Return the bounds of the current recognition region. May match the \n         * bounds of the entire image or a sub-rectangle of the entire image.\n         * \n         * The returned bounding box is in the Android coordinate system,\n         * which has the origin in the top left.\n         * \n         * @return an {@link android.graphics.Rect} bounding box\n         */\n        public Rect getCurrentRect() {\n            return textRect;\n        }\n    }\n\n    /**\n     * Constructs an instance of TessBaseAPI.\n     * <p>\n     * When the instance of TessBaseAPI is no longer needed, its {@link #end}\n     * method must be invoked to dispose of it.\n     */\n    public TessBaseAPI() {\n        mNativeData = nativeConstruct();\n        if (mNativeData == 0) {\n            throw new RuntimeException(\"Can't create TessBaseApi object\");\n        }\n        mRecycled = false;\n    }\n\n    /**\n     * Constructs an instance of TessBaseAPI with a callback method for\n     * receiving progress updates during OCR.\n     * <p>\n     * When the instance of TessBaseAPI is no longer needed, its {@link #end}\n     * method must be invoked to dispose of it.\n     * \n     * @param progressNotifier Callback to receive progress notifications\n     */\n    public TessBaseAPI(ProgressNotifier progressNotifier) {\n        this();\n        this.progressNotifier = progressNotifier;\n    }\n\n    /**\n     * Initializes the Tesseract engine with a specified language model. Returns\n     * <code>true</code> on success.\n     * <p>\n     * Instances are now mostly thread-safe and totally independent, but some\n     * global parameters remain. Basically it is safe to use multiple\n     * TessBaseAPIs in different threads in parallel, UNLESS you use SetVariable\n     * on some of the Params in classify and textord. If you do, then the effect\n     * will be to change it for all your instances.\n     * <p>\n     * The datapath must be the name of the parent directory of tessdata and\n     * must end in / . Any name after the last / will be stripped. The language\n     * is (usually) an ISO 639-3 string or <code>null</code> will default to eng.\n     * It is entirely safe (and eventually will be efficient too) to call Init\n     * multiple times on the same instance to change language, or just to reset\n     * the classifier.\n     * <p>\n     * The language may be a string of the form {@code [~]<lang>[+[~]<lang>]*} indicating\n     * that multiple languages are to be loaded. Eg hin+eng will load Hindi and\n     * English. Languages may specify internally that they want to be loaded\n     * with one or more other languages, so the ~ sign is available to override\n     * that. Eg if hin were set to load eng by default, then hin+~eng would force\n     * loading only hin. The number of loaded languages is limited only by\n     * memory, with the caveat that loading additional languages will impact\n     * both speed and accuracy, as there is more work to do to decide on the\n     * applicable language, and there is more chance of hallucinating incorrect\n     * words.\n     * <p>\n     * <b>WARNING:</b> On changing languages, all Tesseract parameters are reset\n     * back to their default values. (Which may vary between languages.)\n     * <p>\n     * If you have a rare need to set a Variable that controls initialization\n     * for a second call to Init you should explicitly call End() and then use\n     * SetVariable before Init. This is only a very rare use case, since there\n     * are very few uses that require any parameters to be set before Init.\n     *\n     * @param datapath the parent directory of tessdata ending in a forward\n     *            slash\n     * @param language an ISO 639-3 string representing the language(s)\n     * @return <code>true</code> on success\n     */\n    public boolean init(String datapath, String language) {\n        return init(datapath, language, OEM_DEFAULT);\n    }\n\n    /**\n     * Initializes the Tesseract engine with the specified language model(s). Returns\n     * <code>true</code> on success.\n     *\n     * @see #init(String, String)\n     *\n     * @param datapath the parent directory of tessdata ending in a forward\n     *            slash\n     * @param language an ISO 639-3 string representing the language(s)\n     * @param ocrEngineMode the OCR engine mode to be set\n     * @return <code>true</code> on success\n     */\n    public boolean init(String datapath, String language, @OcrEngineMode int ocrEngineMode) {\n        if (datapath == null)\n            throw new IllegalArgumentException(\"Data path must not be null!\");\n        if (!datapath.endsWith(File.separator))\n            datapath += File.separator;\n\n        File datapathFile = new File(datapath);\n        if (!datapathFile.exists())\n            throw new IllegalArgumentException(\"Data path does not exist!\");\n\n        File tessdata = new File(datapath + \"tessdata\");\n        if (!tessdata.exists() || !tessdata.isDirectory())\n            throw new IllegalArgumentException(\"Data path must contain subfolder tessdata!\");\n\n        //noinspection deprecation\n        if (ocrEngineMode != OEM_CUBE_ONLY) {\n            for (String languageCode : language.split(\"\\\\+\")) {\n                if (!languageCode.startsWith(\"~\")) {\n                    File datafile = new File(tessdata + File.separator + \n                            languageCode + \".traineddata\");\n                    if (!datafile.exists())\n                        throw new IllegalArgumentException(\"Data file not found at \" + datafile);\n\n                    // Catch some common problematic initialization cases.\n                    if (languageCode.equals(\"ara\") || (languageCode.equals(\"hin\") &&\n                            ocrEngineMode == OEM_DEFAULT)) {\n                        boolean sampleCubeFileExists = new File(tessdata +\n                                File.separator + languageCode + \".cube.params\").exists();\n                        if (!sampleCubeFileExists) {\n                            throw new IllegalArgumentException(\"Cube data files not found.\" +\n                                    \" See https://github.com/rmtheis/tess-two/issues/239\");\n                        }\n                    }\n                }\n            }\n        }\n\n        boolean success = nativeInitOem(mNativeData, datapath, language, ocrEngineMode);\n\n        if (success) {\n            mRecycled = false;\n        }\n\n        return success;\n    }\n\n    /**\n     * Returns the languages string used in the last valid initialization.\n     * If the last initialization specified \"deu+hin\" then that will be\n     * returned. If hin loaded eng automatically as well, then that will\n     * not be included in this list.\n     * \n     * @return the last-used language code\n     */\n    public String getInitLanguagesAsString() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetInitLanguagesAsString(mNativeData);\n    }\n\n    /**\n     * Frees up recognition results and any stored image data, without actually\n     * freeing any recognition data that would be time-consuming to reload.\n     * Afterwards, you must call SetImage or SetRectangle before doing any\n     * Recognize or Get* operation.\n     */\n    public void clear() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeClear(mNativeData);\n    }\n\n    /**\n     * Closes down tesseract and free up all memory. End() is equivalent to\n     * destructing and reconstructing your TessBaseAPI.\n     * <p>\n     * Once End() has been used, none of the other API functions may be used\n     * other than Init and anything declared above it in the class definition.\n     */\n    public void end() {\n        if (!mRecycled) {\n            nativeEnd(mNativeData);\n\n            mRecycled = true;\n        }\n    }\n\n    /**\n     * Set the value of an internal \"parameter.\"\n     * <p>\n     * Supply the name of the parameter and the value as a string, just as\n     * you would in a config file.\n     * <p>\n     * Returns false if the name lookup failed.\n     * <p>\n     * Eg <code>setVariable(\"tessedit_char_blacklist\", \"xyz\");</code> to \n     * ignore x, y and z.\n     * \n     * Or <code>setVariable(\"classify_bln_numeric_mode\", \"1\");</code> to set\n     * numeric-only mode.\n     * <p>\n     * setVariable may be used before init, but settings will revert to\n     * defaults on end().\n     * <p>\n     * Note: Must be called after init(). Only works for non-init variables.\n     * \n     * @param var name of the variable\n     * @param value value to set\n     * @return false if the name lookup failed\n     */\n    public boolean setVariable(String var, String value) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeSetVariable(mNativeData, var, value);\n    }\n\n    /**\n     * Return the current page segmentation mode.\n     *\n     * @return value of the current page segmentation mode\n     */\n    public @PageSegMode.Mode int getPageSegMode() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetPageSegMode(mNativeData);\n    }\n\n    /**\n     * Sets the page segmentation mode. Defaults to \n     * {@link PageSegMode#PSM_SINGLE_BLOCK}. This controls how much processing\n     * the OCR engine will perform before recognizing text.\n     * <p>\n     * The mode can also be modified by readConfigFile or \n     * setVariable(\"tessedit_pageseg_mode\", mode as string).\n     *\n     * @param mode the {@link PageSegMode} to set\n     */\n    public void setPageSegMode(@PageSegMode.Mode int mode) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetPageSegMode(mNativeData, mode);\n    }\n\n    /**\n     * Sets debug mode. This controls how much information is displayed in the\n     * log during recognition.\n     *\n     * @param enabled <code>true</code> to enable debugging mode\n     */\n    public void setDebug(boolean enabled) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetDebug(mNativeData, enabled);\n    }\n\n    /**\n     * Restricts recognition to a sub-rectangle of the image. Call after\n     * SetImage. Each SetRectangle clears the recognition results so multiple\n     * rectangles can be recognized with the same image.\n     *\n     * @param rect the bounding rectangle\n     */\n    public void setRectangle(Rect rect) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        setRectangle(rect.left, rect.top, rect.width(), rect.height());\n    }\n\n    /**\n     * Restricts recognition to a sub-rectangle of the image. Call after\n     * SetImage. Each SetRectangle clears the recognition results so multiple\n     * rectangles can be recognized with the same image.\n     *\n     * @param left the left bound\n     * @param top the right bound\n     * @param width the width of the bounding box\n     * @param height the height of the bounding box\n     */\n    public void setRectangle(int left, int top, int width, int height) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetRectangle(mNativeData, left, top, width, height);\n    }\n\n    /**\n     * Provides an image for Tesseract to recognize. Copies the image buffer.\n     * The source image may be destroyed immediately after SetImage is called.\n     * SetImage clears all recognition results, and sets the rectangle to the\n     * full image, so it may be followed immediately by a GetUTF8Text, and it\n     * will automatically perform recognition.\n     *\n     * @param file absolute path to the image file\n     */\n    @WorkerThread\n    public void setImage(File file) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        Pix image = ReadFile.readFile(file);\n\n        if (image == null) {\n            throw new RuntimeException(\"Failed to read image file\");\n        }\n\n        nativeSetImagePix(mNativeData, image.getNativePix());\n\n        image.recycle();\n    }\n\n    /**\n     * Provides an image for Tesseract to recognize. Copies the image buffer.\n     * The source image may be destroyed immediately after SetImage is called.\n     * SetImage clears all recognition results, and sets the rectangle to the\n     * full image, so it may be followed immediately by a GetUTF8Text, and it\n     * will automatically perform recognition.\n     *\n     * @param bmp bitmap representation of the image\n     */\n    @WorkerThread\n    public void setImage(Bitmap bmp) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        Pix image = ReadFile.readBitmap(bmp);\n\n        if (image == null) {\n            throw new RuntimeException(\"Failed to read bitmap\");\n        }\n\n        nativeSetImagePix(mNativeData, image.getNativePix());\n        \n        image.recycle();\n    }\n\n    /**\n     * Provides a Leptonica pix format image for Tesseract to recognize. Clones\n     * the pix object. The source image may be destroyed immediately after\n     * SetImage is called, but its contents may not be modified.\n     *\n     * @param image Leptonica pix representation of the image\n     */\n    @WorkerThread\n    public void setImage(Pix image) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetImagePix(mNativeData, image.getNativePix());\n    }\n\n    /**\n     * Provides an image for Tesseract to recognize. Copies the image buffer.\n     * The source image may be destroyed immediately after SetImage is called.\n     * SetImage clears all recognition results, and sets the rectangle to the\n     * full image, so it may be followed immediately by a GetUTF8Text, and it\n     * will automatically perform recognition.\n     *\n     * @param imagedata byte representation of the image\n     * @param width image width\n     * @param height image height\n     * @param bpp bytes per pixel\n     * @param bpl bytes per line\n     */\n    @WorkerThread\n    public void setImage(byte[] imagedata, int width, int height, int bpp, int bpl) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetImageBytes(mNativeData, imagedata, width, height, bpp, bpl);\n    }\n\n    /**\n     * The recognized text is returned as a String which is coded as UTF8.\n     * This is a blocking operation that will not work with {@link #stop()}.\n     * Call {@link #getHOCRText(int)} before calling this function to\n     * interrupt a recognition task with {@link #stop()}\n     *\n     * @return the recognized text\n     */\n    @WorkerThread\n    public String getUTF8Text() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        // Trim because the text will have extra line breaks at the end\n        String text = nativeGetUTF8Text(mNativeData);\n\n        return text != null ? text.trim() : null;\n    }\n\n    /**\n     * Returns the (average) confidence value between 0 and 100.\n     *\n     * @return confidence value\n     */\n    public int meanConfidence() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeMeanConfidence(mNativeData);\n    }\n\n    /**\n     * Returns all word confidences (between 0 and 100) in an array.\n     * <p>\n     * The number of confidences should correspond to the number of \n     * space-delimited words in GetUTF8Text().\n     *\n     * @return an array of word confidences\n     */\n    public int[] wordConfidences() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        int[] conf = nativeWordConfidences(mNativeData);\n\n        // We shouldn't return null confidences\n        if (conf == null)\n            conf = new int[0];\n\n        return conf;\n    }\n\n    /**\n     * Get a copy of the internal thresholded image from Tesseract.\n     * <p>\n     * Caller takes ownership of the Pix and must recycle() it.\n     * May be called any time after setImage.\n     * \n     * @return Pix containing the thresholded image\n     */\n    public Pix getThresholdedImage() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pix(nativeGetThresholdedImage(mNativeData));\n    }\n\n    /**\n     * Returns the result of page layout analysis as a Pixa, in reading order.\n     * <p>\n     * Can be called before or after Recognize.\n     * \n     * @return Pixa contaning page layout bounding boxes\n     */\n    public Pixa getRegions() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pixa(nativeGetRegions(mNativeData), 0, 0);\n    }\n\n    /**\n     * Returns the textlines as a Pixa. Textlines are extracted from the \n     * thresholded image.\n     * <p>\n     * Can be called before or after Recognize. Block IDs are not returned.\n     * Paragraph IDs are not returned.\n     * \n     * @return Pixa containing textlines\n     */\n    public Pixa getTextlines() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pixa(nativeGetTextlines(mNativeData), 0, 0);\n    }\n\n    /**\n     * Get textlines and strips of image regions as a Pixa, in reading order.\n     * <p>\n     * Enables downstream handling of non-rectangular regions. Can be called\n     * before or after Recognize. Block IDs are not returned.\n     * \n     * @return Pixa containing strips\n     */\n    public Pixa getStrips() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pixa(nativeGetStrips(mNativeData), 0, 0);\n    }    \n\n    /**\n     * Get the words as a Pixa, in reading order.\n     * <p>\n     * Can be called before or after Recognize.\n     * \n     * @return Pixa containing word bounding boxes \n     */\n    public Pixa getWords() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pixa(nativeGetWords(mNativeData), 0, 0);\n    }\n\n    /**\n     * Gets the individual connected (text) components (created after pages \n     * segmentation step, but before recognition) as a Pixa, in reading order.\n     * <p>\n     * Can be called before or after Recognize. Note: the caller is \n     * responsible for calling recycle() on the returned Pixa.\n     * \n     * @return Pixa containing connected components bounding boxes \n     */\n    public Pixa getConnectedComponents() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return new Pixa(nativeGetConnectedComponents(mNativeData), 0, 0);\n    }\n\n    /**\n     * Get a reading-order iterator to the results of LayoutAnalysis and/or\n     * Recognize. The returned iterator must be deleted after use.\n     * \n     * @return iterator to the results of LayoutAnalysis and/or Recognize\n     */\n    public ResultIterator getResultIterator() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        long nativeResultIterator = nativeGetResultIterator(mNativeData);\n\n        if (nativeResultIterator == 0) {\n            return null;\n        }\n\n        return new ResultIterator(nativeResultIterator);\n    }\n\n    /**\n     * Make a HTML-formatted string with hOCR markup from the internal data\n     * structures. Interruptible by {@link #stop()}.\n     * \n     * @param page is 0-based but will appear in the output as 1-based. \n     * @return HTML-formatted string with hOCR markup\n     */\n    @WorkerThread\n    public String getHOCRText(int page){\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetHOCRText(mNativeData, page);\n    }\n\n    /**\n     * Set the name of the input file. Needed for training and reading a UNLV\n     * zone file.\n     * \n     * @param name input file name\n     */\n    public void setInputName(String name){\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetInputName(mNativeData, name);\n    } \n\n    /**\n     * Set the name of the bonus output files. Needed only for debugging.\n     * \n     * @param name output file name\n     */\n    public void setOutputName(String name){\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeSetOutputName(mNativeData, name);\n    } \n\n    /**\n     * Read a \"config\" file containing a set of variable, value pairs.\n     * <p>\n     * Searches the standard places: <i>tessdata/configs, tessdata/tessconfigs</i>.\n     * Note: only non-init params will be set.\n     * \n     * @param filename the configuration filename, without the path\n     */\n    public void readConfigFile(String filename) {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeReadConfigFile(mNativeData, filename);\n    }\n\n    /**\n     * The recognized text is returned as coded in the same format as a UTF8 \n     * box file used in training.\n     * <p>\n     * Constructs coordinates in the original image - not just the rectangle.\n     * \n     * @param page a 0-based page index that will appear in the box file.\n     * @return the recognized text\n     */\n    public String getBoxText(int page){\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        return nativeGetBoxText(mNativeData, page);\n    }\n\n    /**\n     * Returns the version identifier as a string.\n     *\n     * @return the version identifier\n     */\n    public String getVersion() {\n        return nativeGetVersion(mNativeData);\n    }\n\n    /**\n     * Cancel recognition started by {@link #getHOCRText(int)}.\n     */\n    public void stop() {\n        if (mRecycled)\n            throw new IllegalStateException();\n\n        nativeStop(mNativeData);\n    }\n\n    /**\n     * Called from native code to update progress of ongoing recognition passes.\n     *\n     * @param percent Percent complete\n     * @param left Left bound of word bounding box\n     * @param right Right bound of word bounding box\n     * @param top Top bound of word bounding box\n     * @param bottom Bottom bound of word bounding box\n     * @param textLeft Left bound of text bounding box\n     * @param textRight Right bound of text bounding box\n     * @param textTop Top bound of text bounding box\n     * @param textBottom Bottom bound of text bounding box\n     */\n    protected void onProgressValues(final int percent, final int left,\n            final int right, final int top, final int bottom,\n            final int textLeft, final int textRight, final int textTop, final int textBottom) {\n\n        if (progressNotifier != null) {\n            Rect wordRect = new Rect(left, textTop - top, right, textTop - bottom);\n            Rect textRect = new Rect(textLeft, textBottom, textRight, textTop);\n\n            ProgressValues pv = new ProgressValues(percent, wordRect, textRect);\n            progressNotifier.onProgressValues(pv);\n        }\n    }\n\n    /**\n     * Starts a new document. This clears the contents of the output data.\n     * \n     * Caller is responsible for escaping the provided title.\n     *\n     * @param tessPdfRenderer the renderer instance to use\n     * @param title a title to be used in the document metadata\n     * @return {@code true} on success. {@code false} on failure\n     */\n    public boolean beginDocument(TessPdfRenderer tessPdfRenderer, String title) {\n        return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(),\n                title);\n    }\n\n    /**\n     * Starts a new document with no title.\n     * \n     * @param tessPdfRenderer the renderer instance to use\n     * @return {@code true} on success. {@code false} on failure\n     * @see #beginDocument(TessPdfRenderer, String)\n     */\n    public boolean beginDocument(TessPdfRenderer tessPdfRenderer) {\n        return nativeBeginDocument(tessPdfRenderer.getNativePdfRenderer(), \"\");\n    }\n\n    /**\n     * Finishes the document and finalizes the output data.\n     * Invalid if beginDocument not yet called.\n     *\n     * @param tessPdfRenderer the renderer instance to use\n     * @return {@code true} on success. {@code false} on failure\n     */\n    public boolean endDocument(TessPdfRenderer tessPdfRenderer) {\n        return nativeEndDocument(tessPdfRenderer.getNativePdfRenderer());\n    }\n\n    /**\n     * Adds the given data to the opened document (if any).\n     * \n     * @param imageToProcess image to be used for OCR\n     * @param imageToWrite path to image to be written into resulting document\n     * @param tessPdfRenderer the renderer instance to use\n     *\n     * @return {@code true} on success. {@code false} on failure\n     */\n    public boolean addPageToDocument(Pix imageToProcess, String imageToWrite,\n            TessPdfRenderer tessPdfRenderer) {\n        return nativeAddPageToDocument(mNativeData, imageToProcess.getNativePix(),\n                imageToWrite, tessPdfRenderer.getNativePdfRenderer());\n    }\n\n    /*package*/ long getNativeData() {\n        return mNativeData;\n    }\n\n    // ******************\n    // * Native methods *\n    // ******************\n\n    /**\n     * Initializes static native data. Must be called on object load.\n     */\n    private static native void nativeClassInit();\n\n    /**\n     * Initializes native data. Must be called on object construction.\n     */\n    private native long nativeConstruct();\n\n    /**\n     * Calls End() and finalizes native data. Must be called on object \n     * destruction.\n     */\n    private native void nativeEnd(long mNativeData);\n\n    private native boolean nativeInit(long mNativeData, String datapath, String language);\n\n    private native boolean nativeInitOem(long mNativeData, String datapath, String language, int mode);\n\n    private native String nativeGetInitLanguagesAsString(long mNativeData);\n\n    private native void nativeClear(long mNativeData);\n\n    private native void nativeSetImageBytes(\n            long mNativeData,   byte[] imagedata, int width, int height, int bpp, int bpl);\n\n    private native void nativeSetImagePix(long mNativeData, long nativePix);\n\n    private native void nativeSetRectangle(long mNativeData, int left, int top, int width, int height);\n\n    private native String nativeGetUTF8Text(long mNativeData);\n\n    private native int nativeMeanConfidence(long mNativeData);\n\n    private native int[] nativeWordConfidences(long mNativeData);\n\n    private native boolean nativeSetVariable(long mNativeData, String var, String value);\n\n    private native void nativeSetDebug(long mNativeData, boolean debug);\n\n    @PageSegMode.Mode\n    private native int nativeGetPageSegMode(long mNativeData);\n\n    private native void nativeSetPageSegMode(long mNativeData, int mode);\n\n    private native long nativeGetThresholdedImage(long mNativeData);\n\n    private native long nativeGetRegions(long mNativeData);\n\n    private native long nativeGetTextlines(long mNativeData);\n\n    private native long nativeGetStrips(long mNativeData);\n\n    private native long nativeGetWords(long mNativeData);\n\n    private native long nativeGetConnectedComponents(long mNativeData);\n\n    private native long nativeGetResultIterator(long mNativeData);\n\n    private native String nativeGetBoxText(long mNativeData, int page_number);\n\n    private native String nativeGetHOCRText(long mNativeData, int page_number);\n\n    private native void nativeSetInputName(long mNativeData, String name);\n\n    private native void nativeSetOutputName(long mNativeData, String name);\n\n    private native void nativeReadConfigFile(long mNativeData, String fileName);\n\n    private native String nativeGetVersion(long mNativeData);\n\n    private native void nativeStop(long mNativeData);\n\n    private native boolean nativeBeginDocument(long rendererPointer, String title);\n\n    private native boolean nativeEndDocument(long rendererPointer);\n\n    private native boolean nativeAddPageToDocument(long mNativeData, long nativePix, String imagePath, long rendererPointer);\n}\n"
  },
  {
    "path": "tess-two/src/com/googlecode/tesseract/android/TessPdfRenderer.java",
    "content": "/*\r\n * Copyright 2015 Robert Theis\r\n * \r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n * \r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n * \r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\n\r\npackage com.googlecode.tesseract.android;\r\n\r\n/**\r\n * Java representation of a native Tesseract PDF renderer\r\n */\r\npublic class TessPdfRenderer {\r\n\r\n    /**\r\n     * Used by the native implementation of the class.\r\n     */\r\n    private final long mNativePdfRenderer;\r\n\r\n    static {\r\n        System.loadLibrary(\"lept\");\r\n        System.loadLibrary(\"tess\");\r\n    }\r\n\r\n    private boolean mRecycled;\r\n\r\n    /**\r\n     * Constructs an instance of a Tesseract PDF renderer.\r\n     * \r\n     * When the instance of TessPdfRenderer is no longer needed, its \r\n     * {@link #recycle} method must be invoked to dispose of it.\r\n     * \r\n     * @param baseApi API instance to use for performing OCR \r\n     * @param outputPath Full path to write the resulting PDF to, not\r\n     *         including the \".pdf\" extension \r\n     */\r\n    public TessPdfRenderer(TessBaseAPI baseApi, String outputPath) {        \r\n        this.mNativePdfRenderer = nativeCreate(baseApi.getNativeData(), outputPath);\r\n        mRecycled = false;\r\n    }\r\n\r\n    /**\r\n     * @return A pointer to the native TessPdfRenderer object.\r\n     */\r\n    public long getNativePdfRenderer() {\r\n        if (mRecycled)\r\n            throw new IllegalStateException();\r\n\r\n        return mNativePdfRenderer;\r\n    }\r\n\r\n    /**\r\n     * Releases resources and frees any memory associated with this \r\n     * TessPdfRenderer object. Must be called on object destruction.\r\n     */\r\n    public void recycle() {\r\n        nativeRecycle(mNativePdfRenderer);\r\n        mRecycled = true;\r\n    }\r\n\r\n    private static native long nativeCreate(long tessBaseAPINativeData, String outputPath);\r\n\r\n    private static native void nativeRecycle(long nativePointer);\r\n\r\n}"
  },
  {
    "path": "tess-two-test/.classpath",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<classpath>\n\t<classpathentry combineaccessrules=\"false\" kind=\"src\" path=\"/tess-two\"/>\n\t<classpathentry kind=\"con\" path=\"com.android.ide.eclipse.adt.ANDROID_FRAMEWORK\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.LIBRARIES\"/>\n\t<classpathentry exported=\"true\" kind=\"con\" path=\"com.android.ide.eclipse.adt.DEPENDENCIES\"/>\n\t<classpathentry kind=\"src\" path=\"src\"/>\n\t<classpathentry kind=\"src\" path=\"gen\"/>\n\t<classpathentry kind=\"output\" path=\"bin/classes\"/>\n</classpath>\n"
  },
  {
    "path": "tess-two-test/.project",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<projectDescription>\n\t<name>tess-two-test</name>\n\t<comment></comment>\n\t<projects>\n\t\t<project>tess-two</project>\n\t</projects>\n\t<buildSpec>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>org.eclipse.jdt.core.javabuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t\t<buildCommand>\n\t\t\t<name>com.android.ide.eclipse.adt.ApkBuilder</name>\n\t\t\t<arguments>\n\t\t\t</arguments>\n\t\t</buildCommand>\n\t</buildSpec>\n\t<natures>\n\t\t<nature>com.android.ide.eclipse.adt.AndroidNature</nature>\n\t\t<nature>org.eclipse.jdt.core.javanature</nature>\n\t</natures>\n</projectDescription>\n"
  },
  {
    "path": "tess-two-test/AndroidManifest.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n    package=\"com.googlecode.tesseract.android.test\">\n\n    <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />\n    <uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" />\n\n    <application\n        android:icon=\"@drawable/icon\"\n        android:label=\"@string/app_name\">\n    </application>\n\n</manifest>\n"
  },
  {
    "path": "tess-two-test/build.gradle",
    "content": "apply plugin: 'com.android.application'\n\nandroid {\n    compileSdkVersion 30\n\n    defaultConfig {\n        minSdkVersion 16\n        targetSdkVersion 30\n        versionCode 1\n        versionName '1.0'\n\n        testInstrumentationRunner \"androidx.test.runner.AndroidJUnitRunner\"\n    }\n\n    sourceSets {\n        main {\n            manifest.srcFile 'AndroidManifest.xml'\n            res.srcDirs = ['res']\n        }\n\n        androidTest {\n            manifest.srcFile 'AndroidManifest.xml'\n            aidl.srcDirs = ['src']\n            java.srcDirs = ['src']\n            res.srcDirs = ['res']\n        }\n    }\n\n    useLibrary 'android.test.runner'\n    useLibrary 'android.test.base'\n}\n\ndependencies {\n    implementation project(':tess-two')\n\n    // Core library\n    androidTestImplementation 'androidx.test:core:1.3.0'\n\n    // AndroidJUnitRunner and JUnit Rules\n    androidTestImplementation 'androidx.test:runner:1.3.0'\n    androidTestImplementation 'androidx.test:rules:1.3.0'\n}"
  },
  {
    "path": "tess-two-test/project.properties",
    "content": "# This file is automatically generated by Android Tools.\n# Do not modify this file -- YOUR CHANGES WILL BE ERASED!\n#\n# This file must be checked in Version Control Systems.\n#\n# To customize properties used by the Ant build system use,\n# \"ant.properties\", and override values to adapt the script to your\n# project structure.\n\nandroid.library.reference.1=../tess-two\n# Project target.\ntarget=android-16\n"
  },
  {
    "path": "tess-two-test/res/values/strings.xml",
    "content": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<resources>\n    <string name=\"app_name\">tesseract-android-tools-test</string>\n</resources>\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/AdaptiveMapTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\n\npublic class AdaptiveMapTest extends TestCase {\n\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/BinarizeTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\n\npublic class BinarizeTest extends TestCase {\n\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/BoxTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Box;\n\npublic class BoxTest extends TestCase {\n    @SmallTest\n    public void testBoxCreate() {\n        testBoxCreate(10, 10, 10, 10);\n        testBoxCreate(0, 0, 1, 1);\n    }\n    \n    private void testBoxCreate(int x, int y, int w, int h) {\n        Box box = new Box(x, y, w, h);\n        \n        assertEquals(x, box.getX());\n        assertEquals(y, box.getY());\n        assertEquals(w, box.getWidth());\n        assertEquals(h, box.getHeight());\n        \n        box.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/BoxaTest.java",
    "content": "/*\r\n * Copyright 2015 Robert Theis\r\n * \r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n * \r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n * \r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\n\r\npackage com.googlecode.leptonica.android.test;\r\n\r\nimport junit.framework.TestCase;\r\n\r\npublic class BoxaTest extends TestCase {\r\n\r\n}\r\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/ClipTest.java",
    "content": "/*\n * Copyright 2014 Robert Theis\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Box;\nimport com.googlecode.leptonica.android.Clip;\nimport com.googlecode.leptonica.android.Pix;\n\npublic class ClipTest extends TestCase {\n    @SmallTest\n    public void testClipRectangle() {\n        final int newWidth = 100;\n        final int newHeight = 75;\n\n        Pix pix = new Pix(640, 480, 8);\n        Box clippingBox = new Box(50, 50, newWidth, newHeight);\n        Pix clippedPix = Clip.clipRectangle(pix, clippingBox);\n        clippingBox.recycle();\n\n        assertNotNull(clippedPix);\n\n        // The clipped pix should not have the same native pointer.\n        assertNotSame(pix.getNativePix(), clippedPix.getNativePix());\n\n        // The clipped pix should have the correct size.\n        assertTrue(\"Clipped pix has incorrect width.\", clippedPix.getWidth() == newWidth);\n        assertTrue(\"Clipped pix has incorrect height.\", clippedPix.getHeight() == newHeight);\n\n        // We should be able to recycle both Pix.\n        pix.recycle();\n        clippedPix.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/ConvertTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport android.graphics.Color;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Convert;\nimport com.googlecode.leptonica.android.Pix;\n\nimport junit.framework.TestCase;\n\npublic class ConvertTest extends TestCase {\n    @SmallTest\n    public void testConvertTo8() {\n        Pix pixs = new Pix(640, 480, 32);\n        pixs.setPixel(0, 0, Color.RED);\n        pixs.setPixel(1, 0, Color.GREEN);\n        pixs.setPixel(2, 0, Color.BLUE);\n        pixs.setPixel(3, 0, Color.WHITE);\n        pixs.setPixel(4, 0, Color.BLACK);\n        \n        Pix pixd = Convert.convertTo8(pixs);\n        \n        assertNotSame(Color.RED, pixd.getPixel(0, 0));\n        assertNotSame(Color.GREEN, pixd.getPixel(1, 0));\n        assertNotSame(Color.BLUE, pixd.getPixel(2, 0));\n        assertEquals(Color.WHITE, pixd.getPixel(3, 0));\n        assertEquals(Color.BLACK, pixd.getPixel(4, 0));\n        \n        pixs.recycle();\n        pixd.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/EdgeTest.java",
    "content": "/*\r\n * Copyright 2015 Robert Theis\r\n * \r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n * \r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n * \r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\n\r\npackage com.googlecode.leptonica.android.test;\r\n\r\nimport junit.framework.TestCase;\r\n\r\npublic class EdgeTest extends TestCase {\r\n\r\n}\r\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/EnhanceTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\n\npublic class EnhanceTest extends TestCase {\n\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/GrayQuantTest.java",
    "content": "/*\r\n * Copyright 2015 Robert Theis\r\n * \r\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\r\n * use this file except in compliance with the License. You may obtain a copy of\r\n * the License at\r\n * \r\n * http://www.apache.org/licenses/LICENSE-2.0\r\n * \r\n * Unless required by applicable law or agreed to in writing, software\r\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\r\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r\n * License for the specific language governing permissions and limitations under\r\n * the License.\r\n */\r\n\r\npackage com.googlecode.leptonica.android.test;\r\n\r\nimport junit.framework.TestCase;\r\n\r\npublic class GrayQuantTest extends TestCase {\r\n\r\n}\r\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/JpegIOTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport android.graphics.Bitmap;\nimport android.graphics.BitmapFactory;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.JpegIO;\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\n\nimport junit.framework.TestCase;\n\npublic class JpegIOTest extends TestCase {\n    @SmallTest\n    public void testCompressToJpeg() {\n        testCompressToJpeg(640, 480, 85, true);\n        testCompressToJpeg(640, 480, 85, false);\n    }\n    \n    private void testCompressToJpeg(int width, int height, int quality, boolean progressive) {\n        Bitmap bmps = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\n        Pix pixs = ReadFile.readBitmap(bmps);\n        byte[] encodedBytes = JpegIO.compressToJpeg(pixs, quality, progressive);\n        Bitmap bmpd = BitmapFactory.decodeByteArray(encodedBytes, 0, encodedBytes.length);\n        \n        assertEquals(bmps.getWidth(), bmpd.getWidth());\n        assertEquals(bmps.getHeight(), bmpd.getHeight());\n        \n        bmps.recycle();\n        pixs.recycle();\n        //noinspection UnusedAssignment\n        encodedBytes = null;\n        bmpd.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/PixTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\n\nimport junit.framework.TestCase;\nimport android.graphics.Bitmap;\nimport android.graphics.Bitmap.CompressFormat;\nimport android.graphics.Color;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\n\npublic class PixTest extends TestCase {\n    @SmallTest\n    public void testGetData() throws IOException {\n        File file = File.createTempFile(\"testGetData\", \".jpg\");\n        FileOutputStream fileStream = new FileOutputStream(file);\n        Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.RGB_565);\n        bmp.compress(CompressFormat.JPEG, 85, fileStream);\n        Pix pix = ReadFile.readFile(file);\n        assertNotNull(pix);\n        byte[] pixData = pix.getData();\n        assertNotNull(pixData);\n\n        bmp.recycle();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testGetDimensions() {\n        int width = 640;\n        int height = 480;\n        int depth = 32;\n        Pix pix = new Pix(width, height, depth);\n\n        int[] dimens = pix.getDimensions();\n\n        assertEquals(\"Incorrect width value found.\", width,\n                dimens[Pix.INDEX_W]);\n        assertEquals(\"Incorrect height value found.\", height,\n                dimens[Pix.INDEX_H]);\n        assertEquals(\"Incorrect bit-depth value found.\", depth,\n                dimens[Pix.INDEX_D]);\n    }\n\n    @SmallTest\n    public void testPixClone() {\n        Pix pix = new Pix(640, 480, 32);\n        Pix pixCopy = pix.clone();\n\n        // The clone should not have the same native pointer.\n        assertNotSame(pix.getNativePix(), pixCopy.getNativePix());\n\n        // The clone should share the same backing data.\n        pix.setPixel(0, 0, Color.RED);\n        assertEquals(Color.RED, pixCopy.getPixel(0, 0));\n\n        // Finally, we should be able to recycle both Pix.\n        pix.recycle();\n        pixCopy.recycle();\n    }\n\n    @SmallTest\n    public void testPixCreate() {\n        testPixCreate(1, 1, 1);\n        testPixCreate(640, 480, 32);\n    }\n\n    private void testPixCreate(int w, int h, int d) {\n        Pix pix = new Pix(w, h, d);\n\n        // Make sure the dimensions were set correctly.\n        assertEquals(w, pix.getWidth());\n        assertEquals(h, pix.getHeight());\n        assertEquals(d, pix.getDepth());\n\n        // Make sure we can recycle the Pix.\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testPixPixelOps() {\n        Pix pix = new Pix(640, 480, 32);\n\n        // Set various pixel colors.\n        pix.setPixel(0, 0, Color.RED);\n        pix.setPixel(1, 0, Color.BLUE);\n        pix.setPixel(2, 0, Color.GREEN);\n        pix.setPixel(3, 0, Color.BLACK);\n        pix.setPixel(4, 0, Color.WHITE);\n\n        // Make sure the pixel was set and retrieved correctly.\n        assertEquals(Color.RED, pix.getPixel(0, 0));\n        assertEquals(Color.BLUE, pix.getPixel(1, 0));\n        assertEquals(Color.GREEN, pix.getPixel(2, 0));\n        assertEquals(Color.BLACK, pix.getPixel(3, 0));\n        assertEquals(Color.WHITE, pix.getPixel(4, 0));\n\n        pix.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/PixaTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Box;\nimport com.googlecode.leptonica.android.Constants;\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.Pixa;\n\nimport junit.framework.TestCase;\n\npublic class PixaTest extends TestCase {\n    @SmallTest\n    public void testPixaCreate() {\n        internalTestPixaCreate(0, 0, 0);\n        internalTestPixaCreate(1, 0, 0);\n        internalTestPixaCreate(0, 640, 480);\n        internalTestPixaCreate(5, 640, 480);\n    }\n\n    private void internalTestPixaCreate(int initialCapacity, int width, int height) {\n        Pixa pixa = Pixa.createPixa(initialCapacity, width, height);\n\n        // Make sure the dimensions were set correctly.\n        assertEquals(0, pixa.size());\n        assertEquals(width, pixa.getWidth());\n        assertEquals(height, pixa.getHeight());\n\n        // Fill the Pixa to capacity.\n        for (int i = 0; i < initialCapacity; i++) {\n            addBlockToPixa(pixa, 0, 0, 640, 480, 8);\n        }\n\n        // Make sure the size is reflected correctly.\n        assertEquals(initialCapacity, pixa.size());\n\n        // Make sure we can recycle the Pixa.\n        pixa.recycle();\n    }\n\n    @SmallTest\n    public void testPixaCopy() {\n        internalTestPixaCopy(0, 0, 0);\n        internalTestPixaCopy(5, 0, 0);\n        internalTestPixaCopy(0, 640, 480);\n        internalTestPixaCopy(5, 640, 480);\n    }\n\n    private void internalTestPixaCopy(int initialCapacity, int width, int height) {\n        Pixa pixa = Pixa.createPixa(initialCapacity, width, height);\n\n        // Fill the Pixa to capacity.\n        for (int i = 0; i < initialCapacity; i++) {\n            addBlockToPixa(pixa, 0, 0, 640, 640, 8);\n        }\n\n        // Create a shallow copy of the Pixa.\n        Pixa pixaCopy = pixa.copy();\n\n        // Add a new Pix to the copy.\n        addBlockToPixa(pixaCopy, 0, 0, 640, 640, 8);\n\n        // Ensure that both copies changed size.\n        assertEquals(initialCapacity + 1, pixaCopy.size());\n        assertEquals(pixaCopy.size(), pixa.size());\n\n        // Finally, we should be able to recycle both Pixa.\n        pixa.recycle();\n        pixaCopy.recycle();\n    }\n\n    @SmallTest\n    public void testPixaSort() {\n        Pixa pixa = Pixa.createPixa(0);\n\n        // Add contained Pix in arbitrary order.\n        addBlockToPixa(pixa, 0, 0, 640, 640, 8);\n        addBlockToPixa(pixa, 160, 160, 64, 64, 8);\n        addBlockToPixa(pixa, 32, 32, 320, 320, 8);\n        addBlockToPixa(pixa, 64, 64, 160, 160, 8);\n        addBlockToPixa(pixa, 320, 320, 32, 32, 8);\n\n        // Sort by increasing height.\n        Pixa pixaSorted = pixa.sort(Constants.L_SORT_BY_HEIGHT, Constants.L_SORT_INCREASING);\n\n        // Ensure sort was successful.\n        int[] currentDimensions = new int[4];\n        int previousHeight = -1;\n\n        for (int i = 0; i < pixa.size(); i++) {\n            assertTrue(pixaSorted.getBoxGeometry(i, currentDimensions));\n            int currentHeight = currentDimensions[Box.INDEX_H];\n            assertTrue(currentHeight > previousHeight);\n            previousHeight = currentHeight;\n        }\n\n        pixa.recycle();\n        pixaSorted.recycle();\n    }\n\n    @SmallTest\n    public void testPixaJoin() {\n        internalTestPixaJoin(0, 0);\n        internalTestPixaJoin(1, 0);\n        internalTestPixaJoin(0, 1);\n        internalTestPixaJoin(1, 1);\n    }\n\n    private void internalTestPixaJoin(int sizeA, int sizeB) {\n        Pixa pixaA = Pixa.createPixa(0);\n        Pixa pixaB = Pixa.createPixa(0);\n\n        // Populate both Pixa.\n        for (int i = 0; i < sizeA; i++) {\n            addBlockToPixa(pixaA, 0, 0, 640, 640, 8);\n        }\n\n        for (int i = 0; i < sizeB; i++) {\n            addBlockToPixa(pixaB, 0, 0, 640, 640, 8);\n        }\n\n        // Join pixaB into pixaA.\n        pixaA.join(pixaB);\n\n        // Ensure the join was successful.\n        assertEquals(pixaA.size(), sizeA + sizeB);\n        assertEquals(pixaB.size(), sizeB);\n\n        pixaA.recycle();\n        pixaB.recycle();\n    }\n\n    @SmallTest\n    public void testPixaReplacePix() {\n        Pixa pixa = Pixa.createPixa(0, 640, 480);\n\n        // Populate the Pixa.\n        addBlockToPixa(pixa, 0, 0, 640, 480, 8);\n\n        Pix pix = new Pix(320, 240, 8);\n        Box box = new Box(320, 240, 320, 240);\n\n        // Replace the existing Pix.\n        pixa.replacePix(0, pix, box);\n\n        // Ensure the replacement was successful.\n        Pix returnedPix = pixa.getPix(0);\n        Box returnedBox = pixa.getBox(0);\n\n        assertEquals(pix.getWidth(), returnedPix.getWidth());\n        assertEquals(pix.getHeight(), returnedPix.getHeight());\n        assertEquals(pix.getDepth(), returnedPix.getDepth());\n\n        assertEquals(box.getX(), returnedBox.getX());\n        assertEquals(box.getY(), returnedBox.getY());\n        assertEquals(box.getWidth(), returnedBox.getWidth());\n        assertEquals(box.getHeight(), returnedBox.getHeight());\n\n        returnedPix.recycle();\n        returnedBox.recycle();\n        pixa.recycle();\n    }\n\n    @SmallTest\n    public void testPixaMergeAndReplacePix() {\n        Pixa pixa = Pixa.createPixa(0, 640, 480);\n\n        // Populate the Pixa.\n        addBlockToPixa(pixa, 0, 0, 320, 240, 8);\n        addBlockToPixa(pixa, 320, 240, 320, 240, 8);\n\n        // Merge both Pix, removing the second Pix.\n        pixa.mergeAndReplacePix(0, 1);\n\n        // Ensure the merge was successful.\n        Pix pix = pixa.getPix(0);\n        Box box = pixa.getBox(0);\n\n        assertEquals(pixa.size(), 1);\n\n        assertEquals(pix.getWidth(), 640);\n        assertEquals(pix.getHeight(), 480);\n        assertEquals(pix.getDepth(), 8);\n\n        assertEquals(box.getX(), 0);\n        assertEquals(box.getY(), 0);\n        assertEquals(box.getWidth(), 640);\n        assertEquals(box.getHeight(), 480);\n\n        pix.recycle();\n        box.recycle();\n        pixa.recycle();\n    }\n\n    /**\n     * Adds a block to the specified Pixa.\n     *\n     * @param pixa The existing Pixa.\n     * @param x X-coordinate of the top-left corner of the block.\n     * @param y Y-coordinate of the top-left corner of the block.\n     * @param width Width of the block.\n     * @param height Height of the block.\n     * @param depth Bit-depth of the block.\n     */\n    private static void addBlockToPixa(Pixa pixa, int x, int y, int width, int height, int depth) {\n        final Pix pix = new Pix(width, height, depth);\n        final Box box = new Box(x, y, width, height);\n\n        pixa.add(pix, box, Constants.L_COPY);\n\n        pix.recycle();\n        box.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/ReadFileTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport java.io.ByteArrayOutputStream;\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\n\nimport junit.framework.TestCase;\nimport android.graphics.Bitmap;\nimport android.graphics.Bitmap.CompressFormat;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\n\n/**\n * @author alanv@google.com (Alan Viverette)\n */\npublic class ReadFileTest extends TestCase {\n\n    private static final String TAG = ReadFileTest.class.getSimpleName();\n\n    @SmallTest\n    public void testReadBitmap_1x1() {\n        testReadBitmap(1, 1, Bitmap.Config.ARGB_8888);\n    }\n\n    @SmallTest\n    public void testReadBitmap_100x100() {\n        testReadBitmap(100, 100, Bitmap.Config.ARGB_8888);\n    }\n\n    @SmallTest\n    public void testReadBitmap_640x480() {\n        testReadBitmap(640, 480, Bitmap.Config.ARGB_8888);\n    }\n\n    private void testReadBitmap(int width, int height, Bitmap.Config format) {\n        Bitmap bmp = TestUtils.createTestBitmap(width, height, format);\n        Pix pix = ReadFile.readBitmap(bmp);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n\n        bmp.recycle();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testReadFile_bmp() throws IOException {\n        File file = File.createTempFile(\"testReadFile\", \".bmp\");\n        FileOutputStream fileStream = new FileOutputStream(file);\n        Bitmap bmp = TestUtils.createTestBitmap(100, 100, Bitmap.Config.RGB_565);\n        boolean compressed = bmp.compress(CompressFormat.PNG, 100, fileStream);\n\n        assertTrue(compressed);\n\n        Pix pix = ReadFile.readFile(file);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n\n        fileStream.close();\n        bmp.recycle();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testReadFile_jpg() throws IOException {        \n        File file = File.createTempFile(\"testReadFile\", \".jpg\");\n        FileOutputStream fileStream = new FileOutputStream(file);\n        Bitmap bmp = TestUtils.createTestBitmap(100, 100, Bitmap.Config.RGB_565);\n        boolean compressed = bmp.compress(CompressFormat.JPEG, 85, fileStream);\n\n        assertTrue(compressed);\n\n        Pix pix = ReadFile.readFile(file);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n\n        fileStream.close();\n        bmp.recycle();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testReadFile_png() throws IOException {\n        File file = File.createTempFile(\"testReadFile\", \".png\");\n        FileOutputStream fileStream = new FileOutputStream(file);\n        Bitmap bmp = TestUtils.createTestBitmap(100, 100, Bitmap.Config.RGB_565);\n        boolean compressed = bmp.compress(CompressFormat.PNG, 100, fileStream);\n\n        assertTrue(compressed);\n\n        Pix pix = ReadFile.readFile(file);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n\n        fileStream.close();\n        bmp.recycle();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testReadMem_jpg() throws IOException {\n        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();\n        Bitmap bmp = TestUtils.createTestBitmap(100, 100, Bitmap.Config.RGB_565);\n        boolean compressed = bmp.compress(CompressFormat.JPEG, 85, byteStream);\n\n        assertTrue(compressed);\n\n        byte[] encodedData = byteStream.toByteArray();\n        Pix pix = ReadFile.readMem(encodedData);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.99f));\n\n        byteStream.close();\n        bmp.recycle();\n        //noinspection UnusedAssignment\n        encodedData = null;\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testReadMem_png() throws IOException {\n        ByteArrayOutputStream byteStream = new ByteArrayOutputStream();\n        Bitmap bmp = TestUtils.createTestBitmap(100, 100, Bitmap.Config.RGB_565);\n        boolean compressed = bmp.compress(CompressFormat.PNG, 100, byteStream);\n\n        assertTrue(compressed);\n\n        byte[] encodedData = byteStream.toByteArray();\n        Pix pix = ReadFile.readMem(encodedData);\n        assertNotNull(pix);\n        assertEquals(bmp.getWidth(), pix.getWidth());\n        assertEquals(bmp.getHeight(), pix.getHeight());\n\n        float match = TestUtils.compareImages(pix, bmp);\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n\n        byteStream.close();\n        bmp.recycle();\n        //noinspection UnusedAssignment\n        encodedData = null;\n        pix.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/RotateTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\nimport com.googlecode.leptonica.android.Rotate;\nimport com.googlecode.leptonica.android.WriteFile;\n\nimport android.graphics.Bitmap;\nimport android.graphics.Canvas;\nimport android.graphics.Color;\nimport android.graphics.Paint;\nimport android.graphics.Paint.Style;\nimport androidx.test.filters.SmallTest;\n\nimport junit.framework.TestCase;\n\npublic class RotateTest extends TestCase {\n    @SmallTest\n    public void testRotate() {\n        Bitmap bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);\n        Canvas canvas = new Canvas(bmp);\n        Paint paint = new Paint();\n\n        // Paint the background white\n        canvas.drawColor(Color.WHITE);\n\n        // Paint a black circle in the center\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        canvas.drawCircle(50, 50, 10, paint);\n\n        Pix pixs = ReadFile.readBitmap(bmp);\n        Pix pixd = Rotate.rotate(pixs, 180);\n        pixs.recycle();\n\n        Bitmap rotated = WriteFile.writeBitmap(pixd);\n        pixd.recycle();\n\n        assertNotNull(rotated);\n\n        float match = TestUtils.compareBitmaps(bmp, rotated);\n        bmp.recycle();\n        rotated.recycle();\n\n        assertTrue(\"Bitmaps do not match.\", (match > 0.99f));\n    }\n\n    @SmallTest\n    public void testRotateOrth() {\n        Bitmap bmp = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);\n        Canvas canvas = new Canvas(bmp);\n        Paint paint = new Paint();\n\n        // Paint the background white\n        canvas.drawColor(Color.WHITE);\n\n        // Paint a black circle in the center\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        canvas.drawCircle(50, 50, 10, paint);\n\n        Pix pixs = ReadFile.readBitmap(bmp);\n        Pix pixd = Rotate.rotateOrth(pixs, 1);\n        pixs.recycle();\n\n        Bitmap rotated = WriteFile.writeBitmap(pixd);\n        pixd.recycle();\n\n        assertNotNull(rotated);\n\n        float match = TestUtils.compareBitmaps(bmp, rotated);\n        bmp.recycle();\n        rotated.recycle();\n\n        assertTrue(\"Bitmaps do not match.\", (match > 0.99f));\n    }\n\n    @SmallTest\n    public void testRotateResize() {\n        Bitmap bmp = Bitmap.createBitmap(100, 10, Bitmap.Config.ARGB_8888);\n        Canvas canvas = new Canvas(bmp);\n        Paint paint = new Paint();\n\n        // Paint the background white\n        canvas.drawColor(Color.BLACK);\n\n        // Paint a black circle in the center\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        canvas.drawCircle(50, 50, 10, paint);\n\n        Pix pixs = ReadFile.readBitmap(bmp);\n        Pix pixd = Rotate.rotate(pixs, 180);\n        pixs.recycle();\n        bmp.recycle();\n\n        assertTrue(\"Rotated width is not 100.\", (pixd.getWidth() == 100));\n        pixd.recycle();\n    }\n}"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/ScaleTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport android.graphics.Bitmap;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\nimport com.googlecode.leptonica.android.Scale;\n\nimport junit.framework.TestCase;\n\npublic class ScaleTest extends TestCase {\n    @SmallTest\n    public void testScale() {\n        testScale(640, 480, 1.0f, 1.0f);\n        testScale(640, 480, 0.5f, 0.25f);\n    }\n\n    @SmallTest\n    public void testScaleGeneral() {\n        testScaleGeneral(640, 480, 1.0f);\n        testScaleGeneral(640, 480, 0.5f);\n    }\n\n    private void testScale(int inputWidth, int inputHeight, float scaleX, float scaleY) {\n        Bitmap bmp = Bitmap.createBitmap(inputWidth, inputHeight, Bitmap.Config.ARGB_8888);\n        Pix pixs = ReadFile.readBitmap(bmp);\n        Pix pixd = Scale.scale(pixs, scaleX, scaleY);\n\n        assertEquals((int) (inputWidth * scaleX), pixd.getWidth());\n        assertEquals((int) (inputHeight * scaleY), pixd.getHeight());\n\n        bmp.recycle();\n        pixs.recycle();\n        pixd.recycle();\n    }\n\n    private void testScaleGeneral(int inputWidth, int inputHeight, float scale) {\n        Bitmap bmp = Bitmap.createBitmap(inputWidth, inputHeight, Bitmap.Config.ARGB_8888);\n        Pix pixs = ReadFile.readBitmap(bmp);\n        Pix pixd = Scale.scaleWithoutSharpening(pixs, scale);\n\n        assertEquals((int) (inputWidth * scale), pixd.getWidth());\n        assertEquals((int) (inputHeight * scale), pixd.getHeight());\n\n        bmp.recycle();\n        pixs.recycle();\n        pixd.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/SkewTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport junit.framework.TestCase;\nimport android.graphics.Bitmap;\nimport android.graphics.Canvas;\nimport android.graphics.Color;\nimport android.graphics.Paint;\nimport android.graphics.Paint.Align;\nimport android.graphics.Paint.Style;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport com.googlecode.leptonica.android.Convert;\nimport com.googlecode.leptonica.android.GrayQuant;\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\nimport com.googlecode.leptonica.android.Skew;\n\npublic class SkewTest extends TestCase {\n\n    private static final String SENTENCE = \"The quick brown fox jumps over the lazy dog.\";\n\n    @SmallTest\n    public void testFindSkew() {\n        testFindSkew(SENTENCE, 640, 480, -15.0f);\n        testFindSkew(SENTENCE, 640, 480, 0.0f);\n        testFindSkew(SENTENCE, 640, 480, 15.0f);\n    }\n\n    private void testFindSkew(String text, int width, int height, float skew) {\n        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\n        Paint paint = new Paint();\n        Canvas canvas = new Canvas(bmp);\n\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        paint.setAntiAlias(true);\n        paint.setTextAlign(Align.CENTER);\n        paint.setTextSize(32.0f);\n\n        canvas.drawColor(Color.WHITE);\n        canvas.rotate(skew, width / 2, height / 2);\n        canvas.drawText(text, width / 2, height / 2 , paint);\n\n        Pix pixs = ReadFile.readBitmap(bmp);\n\n        assertNotNull(pixs);\n\n        Pix pixd;\n        //noinspection ConstantConditions\n        if (pixs.getDepth() != 4 || pixs.getDepth() != 8) {\n            Pix pix8 = Convert.convertTo8(pixs);\n            pixd = GrayQuant.pixThresholdToBinary(pix8, 1);\n            pix8.recycle();\n        } else {\n            pixd = GrayQuant.pixThresholdToBinary(pixs, 1);\n        }\n\n        float measuredSkew = -Skew.findSkew(pixd);\n        float tol = 1f;\n        boolean isInRange = skew - tol < measuredSkew && measuredSkew < skew + tol;\n        assertTrue(\"Skew has incorrect value.\", isInRange);\n\n        pixs.recycle();\n        pixd.recycle();\n        bmp.recycle();\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/TestUtils.java",
    "content": "/*\n * Copyright (C) 2012 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport android.graphics.Bitmap;\nimport android.graphics.Canvas;\nimport android.graphics.Color;\nimport android.graphics.Paint;\nimport android.graphics.Paint.Style;\nimport android.graphics.Rect;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\n\n/**\n * Utility methods for running Leptonica unit tests.\n *\n * @author alanv@google.com (Alan Viverette)\n */\n@SuppressWarnings(\"WeakerAccess\")\npublic class TestUtils {\n    public static float compareBitmaps(Bitmap a, Bitmap b) {\n        int found = 0;\n\n        for (int y = 0; y < a.getHeight(); y++) {\n            for (int x = 0; x < a.getWidth(); x++) {\n                if (a.getPixel(x, y) == b.getPixel(x, y)) {\n                    found++;\n                }\n            }\n        }\n\n        return found / (float)(a.getWidth() * a.getHeight());\n    }\n\n    public static float compareImages(Pix a, Bitmap b) {\n        int found = 0;\n\n        for (int y = 0; y < a.getHeight(); y++) {\n            for (int x = 0; x < a.getWidth(); x++) {\n                if (a.getPixel(x, y) == b.getPixel(x, y)) {\n                    found++;\n                }\n                // Jpeg compression does not support alpha channel, introduces some noise in the low bit\n                else if (a.getImageFormat() == Pix.IFF_JFIF_JPEG) {\n                    if ( (a.getPixel(x, y) & 0xfefefe) == (b.getPixel(x, y) & 0xfefefe) ) {\n                        found++;\n                    }\n                }\n                else if (a.getSpp() < 4) {\n                    if ( (a.getPixel(x, y) & 0xffffff) == (b.getPixel(x, y) & 0xffffff) ) {\n                        found++;\n                    }\n                }\n            }\n        }\n\n        return found / (float)(a.getWidth() * a.getHeight());\n    }\n\n    public static float comparePix(Pix a, Pix b) {\n        int found = 0;\n\n        for (int y = 0; y < a.getHeight(); y++) {\n            for (int x = 0; x < a.getWidth(); x++) {\n                if (a.getPixel(x, y) == b.getPixel(x, y)) {\n                    found++;\n                }\n                // Jpeg compression does not support alpha channel, introduces some noise in the low bit\n                else if (a.getImageFormat() == Pix.IFF_JFIF_JPEG || b.getImageFormat() == Pix.IFF_JFIF_JPEG) {\n                    if ( (a.getPixel(x, y) & 0xfefefe) == (b.getPixel(x, y) & 0xfefefe) ) {\n                        found++;\n                    }\n                }\n                else if (a.getSpp() < 4 || b.getSpp() < 4) {\n                    if ( (a.getPixel(x, y) & 0xffffff) == (b.getPixel(x, y) & 0xffffff) ) {\n                        found++;\n                    }\n                }\n            }\n        }\n\n        return found / (float)(a.getWidth() * a.getHeight());\n    }\n\n    public static Bitmap createTestBitmap(int width, int height, Bitmap.Config format) {\n        Bitmap bmp = Bitmap.createBitmap(width, height, format);\n        Canvas canvas = new Canvas(bmp);\n        Paint paint = new Paint();\n\n        if (width > 1 && height > 1) {\n            // Paint the left half white\n            paint.setColor(Color.WHITE);\n            paint.setStyle(Style.FILL);\n            canvas.drawRect(new Rect(0, 0, width / 2, height), paint);\n\n            // Paint the right half black\n            paint.setColor(Color.BLACK);\n            paint.setStyle(Style.FILL);\n            canvas.drawRect(new Rect(width / 2, 0, width, height), paint);\n        }\n        return bmp;\n    }\n\n    public static Pix createTestPix(int width, int height) {\n        Bitmap bmp = TestUtils.createTestBitmap(width, height, Bitmap.Config.ARGB_8888);\n        return ReadFile.readBitmap(bmp);\n    }\n}"
  },
  {
    "path": "tess-two-test/src/com/googlecode/leptonica/android/test/WriteFileTest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.leptonica.android.test;\n\nimport java.io.File;\nimport java.io.IOException;\n\nimport junit.framework.TestCase;\nimport android.graphics.Bitmap;\nimport androidx.test.filters.SmallTest;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\nimport com.googlecode.leptonica.android.WriteFile;\n\npublic class WriteFileTest extends TestCase {\n    @SmallTest\n    public void testWriteBitmap_1x1() {\n        testWriteBitmap(1, 1);\n    }\n\n    @SmallTest\n    public void testWriteBitmap_100x100() {\n        testWriteBitmap(100, 100);\n    }\n\n    @SmallTest\n    public void testWriteBitmap_640x480() {\n        testWriteBitmap(640, 480);\n    }\n\n    private void testWriteBitmap(int width, int height) {\n        Pix pix = TestUtils.createTestPix(width, height);\n        Pix pcopy = pix.copy();                      // keep unchanged copy\n        Bitmap bmp = WriteFile.writeBitmap(pix);     // pix changed\n\n        assertNotNull(bmp);\n        assertEquals(pix.getWidth(), bmp.getWidth());\n        assertEquals(pix.getHeight(), bmp.getHeight());\n\n        float match = TestUtils.compareImages(pcopy, bmp); // compare against the unchanged copy\n        pix.recycle();\n        bmp.recycle();\n\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n    }\n\n    @SmallTest\n    public void testWriteBytes8_1x1() {\n        testWriteBytes8(1, 1);\n    }\n\n    @SmallTest\n    public void testWriteBytes8_100x100() {\n        testWriteBytes8(100, 100);\n    }\n\n    @SmallTest\n    public void testWriteBytes8_640x480() {\n        testWriteBytes8(640, 480);\n    }\n\n    private static void testWriteBytes8(int width, int height) {\n        Pix pixs = TestUtils.createTestPix(width, height);\n        byte[] data = WriteFile.writeBytes8(pixs);\n        Pix pixd = ReadFile.readBytes8(data, width, height);\n\n        assertEquals(pixs.getWidth(), pixd.getWidth());\n        assertEquals(pixs.getHeight(), pixd.getHeight());\n\n        float match = TestUtils.comparePix(pixs, pixd);\n        pixs.recycle();\n        pixd.recycle();\n\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n    }\n\n    @SmallTest\n    public void testWriteImpliedFormat_bmp() throws IOException {\n        Pix pixs = TestUtils.createTestPix(100, 100);\n        File file = File.createTempFile(\"testWriteImpliedFormat\", \".bmp\");\n        testWriteImpliedFormat(pixs, file);\n        pixs.recycle();\n    }\n\n    @SmallTest\n    public void testWriteImpliedFormat_jpg() throws IOException {\n        Pix pixs = TestUtils.createTestPix(100, 100);\n        File file = File.createTempFile(\"testWriteImpliedFormat\", \".jpg\");\n        testWriteImpliedFormat(pixs, file);\n        pixs.recycle();\n    }\n\n    @SmallTest\n    public void testWriteImpliedFormat_png() throws IOException {\n        Pix pixs = TestUtils.createTestPix(100, 100);\n        File file = File.createTempFile(\"testWriteImpliedFormat\", \".png\");\n        testWriteImpliedFormat(pixs, file);\n        pixs.recycle();\n    }\n\n    private void testWriteImpliedFormat(Pix pixs, File file) {\n        boolean success = WriteFile.writeImpliedFormat(pixs, file);\n\n        assertTrue(\"Writing to file failed.\", success);\n        assertTrue(\"File does not exist.\", file.exists());\n        assertTrue(\"File does not contain data.\", file.length() > 0);\n\n        Pix pixd = ReadFile.readFile(file);\n\n        assertNotNull(\"Pix is null\", pixd);\n\n        float match = TestUtils.comparePix(pixs, pixd);\n        pixd.recycle();\n\n        assertTrue(\"Images do not match. match=\" + match, (match >= 0.9999f));\n    }\n}\n"
  },
  {
    "path": "tess-two-test/src/com/googlecode/tesseract/android/test/TessBaseAPITest.java",
    "content": "/*\n * Copyright (C) 2011 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.tesseract.android.test;\n\nimport android.Manifest;\nimport android.graphics.Bitmap;\nimport android.graphics.Bitmap.CompressFormat;\nimport android.graphics.Canvas;\nimport android.graphics.Color;\nimport android.graphics.Paint;\nimport android.graphics.Paint.Align;\nimport android.graphics.Paint.Style;\nimport android.graphics.Rect;\nimport android.os.AsyncTask;\nimport android.os.Environment;\n\nimport android.text.Html;\nimport android.util.Pair;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.Pixa;\nimport com.googlecode.tesseract.android.ResultIterator;\nimport com.googlecode.tesseract.android.TessBaseAPI;\nimport com.googlecode.tesseract.android.TessBaseAPI.PageIteratorLevel;\nimport com.googlecode.tesseract.android.TessBaseAPI.ProgressNotifier;\nimport com.googlecode.tesseract.android.TessBaseAPI.ProgressValues;\n\nimport junit.framework.TestCase;\n\nimport androidx.test.filters.SmallTest;\nimport androidx.test.rule.GrantPermissionRule;\n\nimport org.junit.Rule;\n\nimport java.io.File;\nimport java.io.FileOutputStream;\nimport java.io.IOException;\nimport java.util.List;\nimport java.util.concurrent.Semaphore;\n\npublic class TessBaseAPITest extends TestCase {\n    static final String TESSBASE_PATH = Environment.getExternalStorageDirectory().toString();\n    static final String DEFAULT_LANGUAGE = \"eng\";\n    private static final String TESSDATA_PATH = TESSBASE_PATH + \"/tessdata/\";\n    private static final String[] EXPECTED_CUBE_DATA_FILES_ENG = {\n        \"eng.cube.bigrams\",\n        \"eng.cube.fold\",\n        \"eng.cube.lm\",\n        \"eng.cube.nn\",\n        \"eng.cube.params\",\n        \"eng.cube.size\",\n        \"eng.cube.word-freq\",\n        \"eng.tesseract_cube.nn\"\n    };\n\n    private static final int DEFAULT_PAGE_SEG_MODE =\n            TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK;\n\n    // Grant permission to use external storage\n    @Rule\n    public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);\n\n    protected void setUp() throws Exception {\n        super.setUp();\n\n        // Check that the data file(s) exist.\n        for (String languageCode : DEFAULT_LANGUAGE.split(\"\\\\+\")) {\n            if (!languageCode.startsWith(\"~\")) {\n                File expectedFile = new File(TESSDATA_PATH + File.separator +\n                        languageCode + \".traineddata\");\n                assertTrue(\"Make sure that you've copied \" + languageCode +\n                        \".traineddata to \" + TESSDATA_PATH, expectedFile.exists());\n            }\n        }\n    }\n\n    private void checkCubeData() {\n        // Make sure the cube data files exist.\n        for (String expectedFilename : EXPECTED_CUBE_DATA_FILES_ENG) {\n            String expectedFilePath = TESSDATA_PATH + expectedFilename;\n            File expectedFile = new File(expectedFilePath);\n            assertTrue(\"Make sure that you've copied \" + expectedFilename +\n                    \" to \" + expectedFilePath, expectedFile.exists());\n        }\n    }\n\n    @SmallTest\n    public void testChoiceIterator() {\n        final String inputText = \"hello\";\n        final Bitmap bmp = TessBaseAPITest.getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setVariable(TessBaseAPI.VAR_SAVE_BLOB_CHOICES, TessBaseAPI.VAR_TRUE);\n\n        // Ensure that text is recognized.\n        baseApi.setImage(bmp);\n        String recognizedText = baseApi.getUTF8Text();\n        assertTrue(\"No recognized text found.\", recognizedText != null && !recognizedText.equals(\"\"));\n\n        // Iterate through the results.\n        ResultIterator iterator = baseApi.getResultIterator();\n        List<Pair<String, Double>> choicesAndConfidences;\n        iterator.begin();\n        do {\n            choicesAndConfidences = iterator.getSymbolChoicesAndConfidence();\n            assertNotNull(\"Invalid result.\", choicesAndConfidences);\n\n            for (Pair<String, Double> choiceAndConfidence : choicesAndConfidences) {\n                String choice = choiceAndConfidence.first;\n                Double conf = choiceAndConfidence.second;\n                assertTrue(\"No choice value found.\", choice != null && !choice.equals(\"\"));\n                assertTrue(\"Found an incorrect confidence value.\", conf >= 0 && conf <= 100);\n            }\n        } while (iterator.next(PageIteratorLevel.RIL_SYMBOL));\n        iterator.delete();\n\n        assertNotNull(\"No ChoiceIterator values found.\", choicesAndConfidences);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    private static Bitmap getTextImage(String text, int width, int height) {\n        final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\n\n        final Canvas canvas = new Canvas(bmp);\n        canvas.drawColor(Color.WHITE);\n        drawTextNewLines(text, canvas);\n\n        return bmp;\n    }\n\n    /**\n     * Draws text (with newlines) centered onto the canvas. If the text does not fit horizontally,\n     * it will be cut off. If the text does not fit vertically, the start of the text will be at\n     * the top of the image and whatever not fitting onto the image being cut off. If the text\n     * fits vertically it will be centered vertically.\n     *\n     * @param text String to draw onto the canvas\n     * @param canvas Canvas to draw text onto\n     */\n    private static void drawTextNewLines(String text,  Canvas canvas){\n        final Paint paint = new Paint();\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        paint.setAntiAlias(true);\n        paint.setTextAlign(Align.CENTER);\n        paint.setTextSize(24.0f);\n\n        String[] textArray = text.split(\"\\n\");\n        int width = canvas.getWidth();\n        int height = canvas.getHeight();\n        int count = textArray.length;\n        int lineSize = (int) (paint.descent() - paint.ascent());\n        int maxLinesToPushUp = height / lineSize;\n        maxLinesToPushUp = count < maxLinesToPushUp ? count : maxLinesToPushUp;\n        int pixelsToPushUp = (maxLinesToPushUp - 1) / 2 * lineSize;\n\n        int x = width / 2;\n        int y = (height / 2) - pixelsToPushUp;\n\n        for (String line : textArray){\n            canvas.drawText(line, x, y, paint);\n            y += lineSize;\n        }\n    }\n\n    @SmallTest\n    public void testClear() {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setImage(bmp);\n\n        // Ensure that the getUTF8Text() operation fails after clear() is called.\n        baseApi.clear();\n        String text = baseApi.getUTF8Text();\n\n        assertNull(\"Received non-null result after clear().\", text);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testEnd() {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setImage(bmp);\n\n        // Ensure that getUTF8Text() fails after end() is called.\n        baseApi.end();\n        try {\n            baseApi.getUTF8Text();\n            fail(\"IllegalStateException not thrown\");\n        } catch (IllegalStateException e) {\n            // Continue\n        } finally {\n            bmp.recycle();\n        }\n\n        // Ensure that reinitializing the API is successful.\n        success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(\"API failed to initialize after end()\", success);\n\n        // Ensure setImage() does not throw an exception.\n        final Bitmap bmp2 = getTextImage(inputText, 640, 480);\n        baseApi.setImage(bmp2);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp2.recycle();\n    }\n\n    //    @SmallTest\n    //    public void testGetHOCRText_combined() {\n    //        checkCubeData();\n    //\n    //        testGetHOCRText(\"eng\", TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED);\n    //    }\n    //\n    //    @SmallTest\n    //    public void testGetHOCRText_cube() {\n    //        checkCubeData();\n    //\n    //        testGetHOCRText(\"eng\", TessBaseAPI.OEM_CUBE_ONLY);\n    //    }\n\n    @SmallTest\n    public void testGetHOCRText_tesseract() {\n        testGetHOCRText(DEFAULT_LANGUAGE, TessBaseAPI.OEM_TESSERACT_ONLY);\n    }\n\n    private void testGetHOCRText(String language, int ocrEngineMode) {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, language, ocrEngineMode);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setImage(bmp);\n\n        // Ensure that getHOCRText() produces a result.\n        final String hOcr = baseApi.getHOCRText(0);\n        assertNotNull(\"HOCR result not found.\", hOcr);\n        assertTrue(hOcr.length() > 0);\n\n        final String outputText = Html.fromHtml(hOcr).toString().trim();\n        assertEquals(inputText, outputText);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testGetInitLanguagesAsString() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Check the last-used language code.\n        String lang = baseApi.getInitLanguagesAsString();\n        assertEquals(\"Got incorrect init languages value.\", lang, DEFAULT_LANGUAGE);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n    }\n\n    @SmallTest\n    public void testGetThresholdedImage() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Set the image to a Bitmap.\n        final Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);\n        baseApi.setImage(bmp);\n\n        // Check the size of the thresholded image.\n        Pix pixd = baseApi.getThresholdedImage();\n        assertNotNull(\"Thresholded image is null.\", pixd);\n        assertEquals(bmp.getWidth(), pixd.getWidth());\n        assertEquals(bmp.getHeight(), pixd.getHeight());\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n        pixd.recycle();\n    }\n\n    //    @SmallTest\n    //    public void testGetUTF8Text_combined() {\n    //        checkCubeData();\n    //\n    //        testGetUTF8Text(\"eng\", TessBaseAPI.OEM_TESSERACT_CUBE_COMBINED);\n    //    }\n    //\n    //    @SmallTest\n    //    public void testGetUTF8Text_cube() {\n    //        checkCubeData();\n    //\n    //        testGetUTF8Text(\"eng\", TessBaseAPI.OEM_CUBE_ONLY);\n    //    }\n\n    @SmallTest\n    public void testGetUTF8Text_tesseract() {\n        testGetUTF8Text(DEFAULT_LANGUAGE, TessBaseAPI.OEM_TESSERACT_ONLY);\n    }\n\n    private void testGetUTF8Text(String language, int ocrEngineMode) {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, language, ocrEngineMode);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setImage(bmp);\n\n        // Ensure that the result is correct.\n        final String outputText = baseApi.getUTF8Text();\n        assertEquals(\"\\\"\" + outputText + \"\\\" != \\\"\" + inputText + \"\\\"\", inputText, outputText);\n\n        // Ensure getRegions() works.\n        final Pixa regions = baseApi.getRegions();\n        assertEquals(\"Found incorrect number of regions.\", regions.size(), 1);\n        regions.recycle();\n\n        // Ensure getTextlines() works.\n        final Pixa textlines = baseApi.getTextlines();\n        assertEquals(\"Found incorrect number of textlines.\", textlines.size(), 1);\n        textlines.recycle();\n\n        // Ensure getStrips() works.\n        final Pixa strips = baseApi.getStrips();\n        assertEquals(\"Found incorrect number of strips.\", strips.size(), 1);\n        strips.recycle();\n\n        // Ensure getWords() works.\n        final Pixa words = baseApi.getWords();\n        assertEquals(\"Found incorrect number of words.\", words.size(), 1);\n        words.recycle();\n\n        // Ensure getConnectedComponents() works.\n        final Pixa connectedComponents = baseApi.getConnectedComponents();\n        assertTrue(\"Connected components not found.\", connectedComponents.size() > 0);\n        connectedComponents.recycle();\n\n        // Iterate through the results.\n        final ResultIterator iterator = baseApi.getResultIterator();\n        String lastUTF8Text;\n        float lastConfidence;\n        int[] lastBoundingBox;\n        Rect lastBoundingRect;\n        int count = 0;\n        iterator.begin();\n        do {\n            lastUTF8Text = iterator.getUTF8Text(PageIteratorLevel.RIL_WORD);\n            lastConfidence = iterator.confidence(PageIteratorLevel.RIL_WORD);\n            lastBoundingBox = iterator.getBoundingBox(PageIteratorLevel.RIL_WORD);\n            lastBoundingRect = iterator.getBoundingRect(PageIteratorLevel.RIL_WORD);\n            count++;\n        } while (iterator.next(PageIteratorLevel.RIL_WORD));\n        iterator.delete();\n\n        assertEquals(\"Found incorrect number of results.\", count, 1);\n        assertEquals(\"Found an incorrect result.\", lastUTF8Text, outputText);\n        assertTrue(\"Result was not high-confidence.\", lastConfidence > 80);\n        assertTrue(\"Result bounding box not found.\", lastBoundingBox[2] > 0 && lastBoundingBox[3] > 0);\n\n        boolean validBoundingRect =  lastBoundingRect.left < lastBoundingRect.right\n                && lastBoundingRect.top < lastBoundingRect.bottom;\n        assertTrue(\"Result bounding box Rect is incorrect.\", validBoundingRect);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testInit() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n    }\n\n    @SmallTest\n    public void testInit_ocrEngineMode() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean result = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE,\n                TessBaseAPI.OEM_TESSERACT_ONLY);\n\n        assertTrue(\"Init was unsuccessful.\", result);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n    }\n\n    @SmallTest\n    public void testProgressValues() {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n        final Rect imageBounds = new Rect(0, 0, bmp.getWidth(), bmp.getHeight());\n\n        class Notifier implements ProgressNotifier {\n            public boolean receivedProgress = false;\n\n            @Override\n            public void onProgressValues(ProgressValues progressValues) {\n                receivedProgress = true;\n                testProgressValues(progressValues, imageBounds);\n            }\n        }\n\n        final Notifier notifier = new Notifier();\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI(notifier);\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setImage(bmp);\n\n        // Ensure that we receive a progress callback.\n        baseApi.getHOCRText(0);\n        assertTrue(notifier.receivedProgress);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testProgressValues_setRectangle() {\n        class Notifier implements ProgressNotifier {\n            public boolean receivedProgress = false;\n            private Rect bounds;\n\n            public void reset(Rect bounds) {\n                this.bounds = bounds;\n                receivedProgress = false;\n            }\n\n            @Override\n            public void onProgressValues(ProgressValues progressValues) {\n                receivedProgress = true;\n                testProgressValues(progressValues, bounds);\n            }\n        }\n\n        final Notifier notifier = new Notifier();\n\n        final int width = 640;\n        final int height = 480;\n        final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\n\n        final Paint paint = new Paint();\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        paint.setAntiAlias(true);\n        paint.setTextAlign(Align.CENTER);\n        paint.setTextSize(32.0f);\n\n        // Draw separate text on the left and right halves of the image.\n        final Canvas canvas = new Canvas(bmp);\n        canvas.drawColor(Color.WHITE);\n        final String leftInput = \"A\";\n        final String rightInput  = \"B\";\n        canvas.drawText(leftInput, width / 4, height / 2, paint);\n        canvas.drawText(rightInput, width * 3 / 4, height / 2, paint);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI(notifier);\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n        baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST,\n                leftInput + rightInput);\n        baseApi.setImage(bmp);\n\n        // Attempt to restrict recognition to a sub-rectangle of the image.\n        final Rect left = new Rect(0, 0, width / 2, height);\n        baseApi.setRectangle(left);\n        notifier.reset(left);\n\n        // Ensure a progress callback is received.\n        baseApi.getHOCRText(0);\n        assertTrue(notifier.receivedProgress);\n\n        // Attempt to restrict recognition to a sub-rectangle of the image.\n        final Rect right = new Rect(width / 2 + 5, 7, width - 5, height - 7);\n        baseApi.setRectangle(right);\n        notifier.reset(right);\n\n        // Ensure a progress callback is received.\n        baseApi.getHOCRText(0);\n        assertTrue(notifier.receivedProgress);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    private static void testProgressValues(ProgressValues progress, Rect bounds) {\n        // Ensure that the percent progress is valid.\n        assertTrue(progress.getPercent() >= 0);\n        assertTrue(progress.getPercent() <= 100);\n\n        // Ensure that the text rect is valid.\n        final Rect textRect = progress.getCurrentRect();\n        assertTrue(textRect.left <= textRect.right);\n        assertTrue(textRect.top <= textRect.bottom);\n\n        // Text rect must match the bounds of the image or sub-rectangle used.\n        assertEquals(textRect.height(), bounds.height());\n        assertEquals(textRect.width(), bounds.width());\n\n        // Ensure that the word rect is valid.\n        final Rect wordRect = progress.getCurrentWordRect();\n        assertTrue(textRect.left <= textRect.right);\n        assertTrue(textRect.top <= textRect.bottom);\n\n        // Ensure the word rect falls within the text rect.\n        final Rect absoluteWordRect = new Rect(\n                textRect.left + wordRect.left,\n                textRect.top + wordRect.top,\n                textRect.left + wordRect.right,\n                textRect.top + wordRect.bottom);\n        assertTrue(textRect.contains(absoluteWordRect));\n    }\n\n    @SmallTest\n    public void testSetImage_bitmap() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Set the image to a Bitmap.\n        final Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);\n        baseApi.setImage(bmp);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testSetImage_file() throws IOException {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Create an image file.\n        File file = File.createTempFile(\"testSetImage\", \".bmp\");\n        FileOutputStream fileStream = new FileOutputStream(file);\n\n        Bitmap bmp = Bitmap.createBitmap(640, 480, Bitmap.Config.ARGB_8888);\n        bmp.compress(CompressFormat.JPEG, 85, fileStream);\n\n        // Set the image to a File.\n        baseApi.setImage(file);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testSetImage_pix() throws IOException {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Set the image to a Pix.\n        Pix pix = new Pix(640, 480, 32);\n        baseApi.setImage(pix);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        pix.recycle();\n    }\n\n    @SmallTest\n    public void testSetPageSegMode() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        // Check the default page segmentation mode.\n        assertEquals(\"Found unexpected default page segmentation mode.\",\n                baseApi.getPageSegMode(), DEFAULT_PAGE_SEG_MODE);\n\n        // Ensure that the page segmentation mode can be changed.\n        final int newPageSegMode = TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR;\n        baseApi.setPageSegMode(newPageSegMode);\n        assertEquals(\"Found unexpected page segmentation mode.\",\n                baseApi.getPageSegMode(), newPageSegMode);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n    }\n\n    @SmallTest\n    public void testSetRectangle() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_CHAR);\n\n        final int width = 640;\n        final int height = 480;\n        final Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);\n        final Paint paint = new Paint();\n        final Canvas canvas = new Canvas(bmp);\n\n        canvas.drawColor(Color.WHITE);\n\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        paint.setAntiAlias(true);\n        paint.setTextAlign(Align.CENTER);\n        paint.setTextSize(32.0f);\n\n        // Draw separate text on the left and right halves of the image.\n        final String leftInput = \"A\";\n        final String rightInput  = \"B\";\n        canvas.drawText(leftInput, width / 4, height / 2, paint);\n        canvas.drawText(rightInput, width * 3 / 4, height / 2, paint);\n\n        baseApi.setVariable(TessBaseAPI.VAR_CHAR_WHITELIST, leftInput + rightInput);\n        baseApi.setImage(bmp);\n\n        // Ensure the result is correct for a rectangle on the left half of the image.\n        Rect left = new Rect(0, 0, width / 2, height);\n        baseApi.setRectangle(left);\n        String leftResult = baseApi.getUTF8Text();\n        assertEquals(\"Found incorrect text.\", leftInput, leftResult);\n\n        // Ensure the result is correct for a rectangle on the right half of the image.\n        Rect right = new Rect(width / 2, 0, width, height);\n        baseApi.setRectangle(right);\n        String rightResult = baseApi.getUTF8Text();\n        assertEquals(\"Found incorrect text.\", rightInput, rightResult);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testSetVariable() {\n        final String inputText = \"hello\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_LINE);\n\n        // Ensure that setting the blacklist variable works.\n        final String blacklistedCharacter = inputText.substring(1, 2);\n        baseApi.setVariable(TessBaseAPI.VAR_CHAR_BLACKLIST, blacklistedCharacter);\n        baseApi.setImage(bmp);\n        final String outputText = baseApi.getUTF8Text();\n        assertFalse(\"Found a blacklisted character.\", outputText.contains(blacklistedCharacter));\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testStop() throws InterruptedException {\n\n        StringBuilder inputTextBuilder = new StringBuilder();\n        for (int i = 0; i < 200; i++){\n            inputTextBuilder.append(\"The quick brown fox jumps over the lazy dog.\\n\");\n        }\n        final Bitmap bmp = getTextImage(inputTextBuilder.toString(), 640, 4000);\n\n        final Semaphore progressSem = new Semaphore(0);\n        final TessBaseAPI baseApi = new TessBaseAPI(new ProgressNotifier() {\n            @Override\n            public void onProgressValues(ProgressValues progressValues) {\n                if (progressValues.getPercent() > 50){\n                    fail(\"OCR recognition was too fast, try to increase the image size and amount of text?\");\n                }\n                if (progressValues.getPercent() > 1){\n                    progressSem.release();\n                }\n            }\n        });\n\n        class LongRecognitionTask extends AsyncTask<Void, Void, Void> {\n            @Override\n            protected Void doInBackground(Void... params) {\n                baseApi.getHOCRText(0);\n                progressSem.release();\n                return null;\n            }\n        }\n\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n        baseApi.setImage(bmp);\n\n        LongRecognitionTask task = new LongRecognitionTask();\n        task.execute();\n\n        // Wait for recognition to start\n        progressSem.acquire();\n\n        baseApi.stop();\n\n        // Wait for getHOCRText() to complete, otherwise we may end() and recycle baseApi before\n        // getHOCRText() finishes execution on the AsyncTask thread and cause an exception\n        progressSem.acquire();\n\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testWordConfidences() {\n        final String inputText = \"one two three\";\n        final Bitmap bmp = getTextImage(inputText, 640, 480);\n\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TESSBASE_PATH, DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        baseApi.setPageSegMode(TessBaseAPI.PageSegMode.PSM_SINGLE_BLOCK);\n\n        baseApi.setImage(bmp);\n        String text = baseApi.getUTF8Text();\n\n        assertNotNull(\"Recognized text is null.\", text);\n\n        // Ensure that a mean confidence value is returned.\n        int conf = baseApi.meanConfidence();\n        boolean validConf = conf > 0 && conf <= 100;\n        assertTrue(\"Mean confidence value is incorrect.\", validConf);\n\n        // Ensure that word confidence values are returned.\n        int numWords = text.split(\"\\\\s+\").length;\n        int[] wordConf = baseApi.wordConfidences();\n        assertEquals(\"Found the wrong number of word confidence values.\", numWords, wordConf.length);\n        for (int confidence : wordConf) {\n            boolean valid = 0 <= confidence && confidence <= 100;\n            assertTrue(\"Found an invalid word confidence value.\", valid);\n        }\n\n        // Attempt to shut down the API.\n        baseApi.end();\n        bmp.recycle();\n    }\n\n    @SmallTest\n    public void testGetVersion() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n\n        String version = baseApi.getVersion();\n        assertNotNull(\"Version returned null\", version);\n\n        // Attempt to shut down the API.\n        baseApi.end();\n    }\n}"
  },
  {
    "path": "tess-two-test/src/com/googlecode/tesseract/android/test/TessPdfRendererTest.java",
    "content": "/*\n * Copyright 2015 Robert Theis\n * \n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n * \n * http://www.apache.org/licenses/LICENSE-2.0\n * \n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n */\n\npackage com.googlecode.tesseract.android.test;\n\nimport java.io.File;\nimport java.io.IOException;\n\nimport junit.framework.TestCase;\n\nimport android.Manifest;\nimport android.annotation.SuppressLint;\nimport android.graphics.Bitmap;\nimport android.graphics.Canvas;\nimport android.graphics.Color;\nimport android.graphics.Paint;\nimport android.graphics.Paint.Align;\nimport android.graphics.Paint.Style;\nimport android.test.suitebuilder.annotation.SmallTest;\n\nimport androidx.test.rule.GrantPermissionRule;\n\nimport com.googlecode.leptonica.android.Pix;\nimport com.googlecode.leptonica.android.ReadFile;\nimport com.googlecode.leptonica.android.WriteFile;\nimport com.googlecode.tesseract.android.TessBaseAPI;\nimport com.googlecode.tesseract.android.TessPdfRenderer;\n\nimport org.junit.Rule;\n\npublic class TessPdfRendererTest extends TestCase {\n\n    @SuppressLint(\"SdCardPath\")\n    private final static String OUTPUT_PATH = \"/sdcard/\";\n\n    // Grant permission to use external storage\n    @Rule\n    public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE);\n\n    @SmallTest\n    public void testCreate() {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TessBaseAPITest.TESSBASE_PATH,\n                TessBaseAPITest.DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        String pdfBasename = \"testCreate\";\n        \n        // Attempt to create a TessPdfRenderer instance.\n        TessPdfRenderer pdfRenderer = new TessPdfRenderer(baseApi, OUTPUT_PATH\n                + pdfBasename);\n\n        pdfRenderer.recycle();\n        baseApi.end();\n    }\n\n    @SmallTest\n    public void testAddPageToDocument() throws IOException {\n        // Attempt to initialize the API.\n        final TessBaseAPI baseApi = new TessBaseAPI();\n        boolean success = baseApi.init(TessBaseAPITest.TESSBASE_PATH,\n                TessBaseAPITest.DEFAULT_LANGUAGE);\n        assertTrue(success);\n\n        String pdfBasename = \"testAddPageToDocument\";\n\n        // Attempt to create a TessPdfRenderer instance.\n        TessPdfRenderer pdfRenderer = new TessPdfRenderer(baseApi, OUTPUT_PATH\n                + pdfBasename);\n\n        // Start the PDF writing process.\n        boolean beginSuccess = baseApi.beginDocument(pdfRenderer, \"title\");\n        assertTrue(beginSuccess);\n\n        // Add a page to the PDF.\n        final Pix pixOne = getTextImage(\"page one\", 640, 480);\n        final File fileOne = File.createTempFile(\"testPageOne\", \".png\");\n        WriteFile.writeImpliedFormat(pixOne, fileOne);\n        boolean addedPageOne = baseApi.addPageToDocument(pixOne,\n                fileOne.getAbsolutePath(), pdfRenderer);\n        assertTrue(addedPageOne);\n\n        // Add a second page.\n        final Pix pixTwo = getTextImage(\"page two\", 640, 480);\n        final File fileTwo = File.createTempFile(\"testPageTwo\", \".png\");\n        WriteFile.writeImpliedFormat(pixTwo, fileTwo);\n        boolean addedPageTwo = baseApi.addPageToDocument(pixTwo,\n                fileTwo.getAbsolutePath(), pdfRenderer);\n        assertTrue(addedPageTwo);\n\n        // Finish writing to the PDF document.\n        boolean endSuccess = baseApi.endDocument(pdfRenderer);\n        assertTrue(endSuccess);\n\n        // Ensure that a PDF file was created.\n        File pdf = new File(OUTPUT_PATH + pdfBasename + \".pdf\");\n        assertTrue(pdf.isFile());\n        assertTrue(pdf.length() > 0);\n\n        pdfRenderer.recycle();\n        baseApi.end();\n        pixOne.recycle();\n        pixTwo.recycle();\n    }\n\n    private static Pix getTextImage(String text, int width, int height) {\n        final Bitmap bmp = Bitmap.createBitmap(width, height, \n                Bitmap.Config.ARGB_8888);\n        final Paint paint = new Paint();\n        final Canvas canvas = new Canvas(bmp);\n\n        canvas.drawColor(Color.WHITE);\n\n        paint.setColor(Color.BLACK);\n        paint.setStyle(Style.FILL);\n        paint.setAntiAlias(true);\n        paint.setTextAlign(Align.CENTER);\n        paint.setTextSize(24.0f);\n        canvas.drawText(text, width / 2, height / 2, paint);\n\n        return ReadFile.readBitmap(bmp);\n    }\n\n}"
  }
]